Static
methodName of the DID method, as defined in the DID Key specification.
Static
createCreates a new DID using the did:key
method formed from a newly generated key.
The parameters for the create operation.
Optional
keyKey Management System (KMS) used to generate keys and sign data.
Optional
options?: DidKeyCreateOptions<TKms>Optional parameters that can be specified when creating a new DID.
A Promise resolving to a BearerDid object representing the new DID.
The DID URI is formed by
Multibase base58-btc
encoding the
Multicodec-encoded
public key and prefixing with did:key:
.
This method can optionally derive an encryption key from the public key used to create the DID
if and only if the public key algorithm is Ed25519
. This feature enables the same DID to be
used for encrypted communication, in addition to signature verification. To enable this
feature, specify an algorithm
of Ed25519
as either a top-level option or in a
verificationMethod
and set the enableEncryptionKeyDerivation
option to true
.
Notes:
options
are given, by default a new Ed25519 key will be generated.algorithm
and verificationMethods
options are mutually exclusive. If both are given,
an error will be thrown.// DID Creation
const did = await DidKey.create();
// DID Creation with a KMS
const keyManager = new LocalKeyManager();
const did = await DidKey.create({ keyManager });
Private
Static
createExpands a did:key identifier to a DID Document.
Reference: https://w3c-ccg.github.io/did-method-key/#document-creation-algorithm
Optional
options?: DidResolutionOptions | DidKeyCreateOptions<CryptoApi<KmsGenerateKeyParams, string, KmsGetPublicKeyParams, KmsDigestParams, KmsSignParams, KmsVerifyParams>>Private
Static
createDecoding a multibase-encoded multicodec value into a verification method that is suitable for verifying that encrypted information will be received by the intended recipient.
Private
Static
createDecodes a multibase-encoded multicodec value into a verification method that is suitable for verifying digital signatures.
Signature method creation algorithm inputs.
Private
Static
deriveTransform a multibase-encoded multicodec value to public encryption key components that are suitable for encrypting messages to a receiver. A mathematical proof elaborating on the safety of performing this operation is available in: On using the same key pair for Ed25519 and an X25519 based KEM
Static
getGiven the W3C DID Document of a did:key
DID, return the verification method that will be used
for signing messages and credentials. With DID Key, the first verification method in the
authentication property in the DID Document is used.
Note that for DID Key, only one verification method intended for signing can exist so
specifying methodId
could be considered redundant or unnecessary. The option is provided for
consistency with other DID method implementations.
The parameters for the getSigningMethod
operation.
DID Document to get the verification method from.
Optional
methodID of the verification method to use for signing.
Verification method to use for signing.
Static
importInstantiates a BearerDid object for the DID Key method from a given PortableDid.
This method allows for the creation of a BearerDid
object using a previously created DID's
key material, DID document, and metadata.
The parameters for the import operation.
Optional
keyOptionally specify an external Key Management System (KMS) used to generate keys and sign data. If not given, a new LocalKeyManager instance will be created and used.
The PortableDid object to import.
A Promise resolving to a BearerDid
object representing the DID formed from the provided keys.
The verificationMethod
array of the DID document must contain exactly one key since the
did:key
method only supports a single verification method.
// Export an existing BearerDid to PortableDid format.
const portableDid = await did.export();
// Reconstruct a BearerDid object from the PortableDid.
const did = await DidKey.import({ portableDid });
An error if the DID document does not contain exactly one verification method.
Static
resolveResolves a did:key
identifier to a DID Document.
The DID to be resolved.
Optional
options: DidResolutionOptionsOptional parameters for resolving the DID.
A Promise resolving to a DidResolutionResult object representing the result of the resolution.
Private
Static
validateValidates the structure and components of a DID URI against the did:key
method specification.
An object representing the parsed components of a DID URI, including the scheme, method, and method-specific identifier.
true
if the DID URI meets the did:key
method's structural requirements, false
otherwise.
The
DidKey
class provides an implementation of the 'did:key' DID method.Features:
did:key
DIDs.did:key
to its corresponding DID Document.Remarks
The
did:key
DID method uses a single public key to generate a DID and does not rely on any external system such as a blockchain or centralized database. This characteristic makes it suitable for use cases where a assertions about a DID Subject can be self-verifiable by third parties.The method-specific identifier is formed by Multibase base58-btc encoding the concatenation of the Multicodec identifier for the public key type and the raw public key bytes. To form the DID URI, the method-specific identifier is prefixed with the string 'did:key:'.
This method can optionally derive an encryption key from the public key used to create the DID if and only if the public key algorithm is
Ed25519
. This feature enables the same DID to be used for encrypted communication, in addition to signature verification. To enable this feature when callingDidKey.create()
, first specify analgorithm
ofEd25519
or provide akeySet
referencing anEd25519
key and then set theenableEncryptionKeyDerivation
option totrue
.Note:
See
DID Key Specification
Example