Function: toDID()
toDID(
did):null|DID
Defined in: src/types/atproto-validators.ts:89
Validates and brands a DID string.
Parameters
did
string
Potential DID string
Returns
null | DID
Branded DID if valid, null otherwise
Remarks
DID format: did:method:identifier
Validation rules:
- Must start with
did: - Method must be lowercase alphabetic
- Identifier must be non-empty, alphanumeric with periods, underscores, hyphens
Supported methods:
did:plc:*(Placeholder, AT Protocol default)did:web:*(Web-based)- Other methods allowed but may not be resolvable
Example
const valid = toDID('did:plc:z72i7hdynmk6r22z27h6tvur');
console.log(valid); // 'did:plc:z72i7hdynmk6r22z27h6tvur'
const invalid = toDID('not-a-did');
console.log(invalid); // null