Constructs a new Did
instance from individual components.
An object containing the parameters to be included in the DID URI.
Optional
fragment?: stringOptional. The fragment component of the DID URI.
The DID method identifier.
The name of the DID method.
Optional
params?: Record<string, string>Optional. The query parameters in the DID URI.
Optional
path?: stringOptional. The path component of the DID URI.
Optional
query?: stringOptional. The query component of the DID URI.
Optional
fragmentOptional fragment component of the DID URI.
did:web:tbd.website#key-1
The DID method identifier.
h4d3ixkwt6q5a455tucw7j14jmqyghdtbr6cpiz6on5oxj5bpr3o
The name of the DID method.
Examples of DID method names are dht
, jwk
, and web
, among others.
Optional
paramsOptional query parameters in the DID URI.
did:web:tbd.website?service=files&relativeRef=/whitepaper.pdf
Optional
pathOptional path component of the DID URI.
did:web:tbd.website/path
Optional
queryOptional query component of the DID URI.
did:web:tbd.website?versionId=1
A string representation of the DID.
A DID is a URI composed of three parts: the scheme did:
, a method identifier, and a unique,
method-specific identifier specified by the DID method.
did:dht:h4d3ixkwt6q5a455tucw7j14jmqyghdtbr6cpiz6on5oxj5bpr3o
Static
Readonly
DID_Regular expression pattern for matching all of the components of a DID URI.
Static
Readonly
FRAGMENT_Regular expression pattern for matching the fragment component of a DID URI.
Static
Readonly
ID_Regular expression pattern for matching the characters allowed in a method identifier.
Static
Readonly
METHOD_Regular expression pattern for matching the method identifier component of a DID URI.
Static
Readonly
METHOD_Regular expression pattern for matching the method component of a DID URI.
Static
Readonly
PATH_Regular expression pattern for matching the path component of a DID URI.
Static
Readonly
PCT_Regular expression pattern for matching percent-encoded characters in a method identifier.
Static
Readonly
QUERY_Regular expression pattern for matching the query component of a DID URI.
Static
parseParses a DID URI string into its individual components.
A Did
object representing the parsed DID URI, or null
if the input string is not a valid DID URI.
const did = Did.parse('did:example:123?service=agent&relativeRef=/credentials#degree');
console.log(did.uri) // Output: 'did:example:123'
console.log(did.method) // Output: 'example'
console.log(did.id) // Output: '123'
console.log(did.query) // Output: 'service=agent&relativeRef=/credentials'
console.log(did.fragment) // Output: 'degree'
console.log(did.params) // Output: { service: 'agent', relativeRef: '/credentials' }
didUri - The DID URI string to be parsed.
The
Did
class represents a Decentralized Identifier (DID) Uniform Resource Identifier (URI).This class provides a method for parsing a DID URI string into its component parts, as well as a method for serializing a DID URI object into a string.
A DID URI is composed of the following components:
See
DID Core Specification, § DID Syntax