DidKeyGenerator

Generates W3C did:key identifiers from P-256 public keys.

The DID is derived from the root passkey's P-256 public key — one DID per user, stable across all Midnight dApps. This is the sigil's identity facet.

Format: did:key:z<base58btc(varint(0x1200) || compressed_P256_pubkey)>

Where:

  • 0x1200 is the multicodec identifier for P-256 public keys

  • varint encoding of 0x1200 = [0x80, 0x24]

  • compressed P-256 public key = 33 bytes (0x02/0x03 prefix + 32-byte x coordinate)

  • 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

Link copied to clipboard

Compresses a P-256 public key from x/y coordinates.

Link copied to clipboard
fun fromCompressedP256(compressedPublicKey: ByteArray): String

Generates a did:key from a compressed P-256 public key.

Link copied to clipboard

Generates a did:key from a Java ECPublicKey (P-256).

Link copied to clipboard
fun fromEd25519(publicKey: ByteArray): String

Generates a did:key from a 32-byte Ed25519 public key.

Link copied to clipboard

Generates a did:key from uncompressed P-256 x/y coordinates.

Link copied to clipboard

True when did uses the legacy P-256 multicodec encoding.

Link copied to clipboard

Extracts the compressed P-256 public key from a did:key string.