Private
Static
JWK_A mapping from JSON Web Key (JWK) property descriptors to multicodec names.
This mapping is used to convert keys in JWK (JSON Web Key) format to multicodec format.
The keys of this object are strings that describe the JOSE key type and usage, such as 'Ed25519:public', 'Ed25519:private', etc. The values are the corresponding multicodec names used to represent these key types.
const multicodecName = JWK_TO_MULTICODEC['Ed25519:public'];
// Returns 'ed25519-pub', the multicodec name for an Ed25519 public key
Static
MULTICODEC_Defines the expected byte lengths for public keys associated with different cryptographic algorithms, indexed by their multicodec code values.
Private
Static
MULTICODEC_A mapping from multicodec names to their corresponding JOSE (JSON Object Signing and Encryption) representations. This mapping facilitates the conversion of multicodec key formats to JWK (JSON Web Key) formats.
The keys of this object are multicodec names, such as 'ed25519-pub', 'ed25519-priv', etc. The values are objects representing the corresponding JWK properties for that key type.
const joseKey = MULTICODEC_TO_JWK['ed25519-pub'];
// Returns a partial JWK for an Ed25519 public key
Static
jwkConverts a JWK (JSON Web Key) to a Multicodec code and name.
A promise that resolves to a Multicodec definition.
const jwk: Jwk = { crv: 'Ed25519', kty: 'OKP', x: '...' };
const { code, name } = await DidKeyUtils.jwkToMulticodec({ jwk });
Static
keyReturns the appropriate public key compressor for the specified cryptographic curve.
The cryptographic curve to use for the key conversion.
A public key compressor for the specified curve.
Converts a public key to its compressed form.
The parameters for the public key compression.
The public key as a Uint8Array.
A Promise that resolves to the compressed public key as a Uint8Array.
Static
keyReturns the appropriate key converter for the specified cryptographic curve.
The cryptographic curve to use for the key conversion.
An AsymmetricKeyConverter
for the specified curve.
Static
multicodecConverts a Multicodec code or name to parial JWK (JSON Web Key).
The parameters for the conversion.
Optional
code?: numberOptional Multicodec code to convert.
Optional
name?: stringOptional Multicodec name to convert.
A promise that resolves to a JOSE format key.
const partialJwk = await DidKeyUtils.multicodecToJwk({ name: 'ed25519-pub' });
Static
publicConverts a public key in JWK (JSON Web Key) format to a multibase identifier.
A promise that resolves to the multibase identifier.
Note: All secp public keys are converted to compressed point encoding before the multibase identifier is computed.
Per Multicodec table: Public keys for Elliptic Curve cryptography algorithms (e.g., secp256k1, secp256k1r1, secp384r1, etc.) are always represented with compressed point encoding (e.g., secp256k1-pub, p256-pub, p384-pub, etc.).
Per RFC 8812: "As a compressed point encoding representation is not defined for JWK elliptic curve points, the uncompressed point encoding defined there MUST be used. The x and y values represented MUST both be exactly 256 bits, with any leading zeros preserved."
const publicKey = { crv: 'Ed25519', kty: 'OKP', x: '...' };
const multibaseId = await DidKeyUtils.publicKeyToMultibaseId({ publicKey });
The
DidKeyUtils
class provides utility functions to support operations in the DID Key method.