DidKeyGenerator
Generates and parses W3C did:key identifiers for the sigil's identity facet: one DID per user, stable across all Midnight dApps.
The production path derives the DID from the user's Ed25519 sigil key (the PRF-derived identity key; multicodec 0xed), producing the well-known did:key:z6Mk... form (see fromEd25519). Earlier installations rooted the DID directly in the passkey's P-256 public key (multicodec 0x1200, did:key:zDn...); that encoding is still recognized for migration (see isLegacyP256 and fromCompressedP256).
Format: did:key:z<base58btc(varint(multicodec) || pubkey)>
Where:
multicodec varint: Ed25519 =
0xed->[0xed, 0x01]; legacy P-256 =0x1200->[0x80, 0x24]pubkey: 32-byte Ed25519 key, or 33-byte compressed P-256 key (0x02/0x03 prefix + 32-byte x)
base58btc = Bitcoin-style base58 encoding (multibase prefix
z)
References:
did:key spec: https://w3c-ccg.github.io/did-method-key/
Multicodec table: https://github.com/multiformats/multicodec
Multibase: https://github.com/multiformats/multibase
Functions
Compresses a P-256 public key from x/y coordinates.
Generates a did:key from a compressed P-256 public key.
Generates a did:key from a Java ECPublicKey (P-256).
Generates a did:key from a 32-byte Ed25519 public key.
Generates a did:key from uncompressed P-256 x/y coordinates.
True when did uses the legacy P-256 multicodec encoding.
Extracts the compressed P-256 public key from a did:key string.