pub fn validate_did(did: &str) -> Result<(), SyntaxError>Expand description
Checks a string against the generic atproto DID syntax rules.
§This is not AccountDid::parse, and the difference is deliberate
AccountDid is much stricter: did:web only, hostname-level only, ports
only on loopback, lowercase only. That strictness is this project’s
security posture rather than atproto’s grammar — see Zone. Running the
protocol’s generic DID vectors against AccountDid would report failures
that are the entire point of the type, so they are run against this
function instead.
The two are still connected: every DID AccountDid::mint produces is also
valid here, and the conformance suite asserts it.
use didbot_identity::did::validate_did;
assert!(validate_did("did:plc:7iza6de2dwap2sbkpav7c6c6").is_ok());
assert!(validate_did("did:web:localhost%3A1234").is_ok());
assert!(validate_did("did:m123:val").is_err()); // method is letters only
assert!(validate_did("did:method:val:").is_err());