DidKey
The public name of one device's key: a short string another device can store, compare, and check a signature against. Two devices holding the same name are talking about the same key.
It is a W3C did:key for a P-256 public key: did:key:z, then base58btc of the p256-pub multicodec (0x80 0x24) and the key's 33-byte SEC 1 compressed point. So every value starts did:key:zDn. Each key has exactly one name, so comparing two DidKeys compares their keys.
Two levels of checking, because a constructor cannot suspend. Building a DidKey — including decoding one with its serializer, where it travels as a plain string — checks the syntax only: the prefix, the alphabet, the multicodec, the 33-byte length and the 0x02/0x03 lead byte. parse also checks that the point is on the curve and that this platform's provider decodes it, and verify checks the curve before it trusts the point. Use parse for a name from outside.
The on-curve check is not decoration. cryptography-kotlin's JDK decoder computes a square root without checking it, so on the JVM and Android a name whose x has no point on P-256 would otherwise decode into a key. The check runs in common code, so every platform agrees.
Samples
// A device's name, as it arrives from somewhere you do not control: a peer, a QR code, a saved file.
val received = "did:key:zDnaerDaTF5BXEavCrfRZEk316dpbLsfPDZ3WJ5hRTPFU2169"
val device = DidKey.parse(received) // syntax, and that the key really is a point on P-256
check(device.value == received)
check(device.compressedPoint().size == 33)
// Well-formed but naming no key at all: refused the same way on every platform.
val noSuchKey = "did:key:zDnaeQRy3dcKsKa1zmKtVKsTy3m2HYoQnFnfKuxD6HfSTQgYg"
val refused = try {
DidKey.parse(noSuchKey)
false
} catch (_: IllegalArgumentException) {
true
}
check(refused)