KeyScheme

interface KeyScheme

How one device makes keys, reads a key named from outside, and checks a signature. A room uses one scheme for everything it signs and checks, and takes it from its DeviceKeyStore.keyScheme.

There is one scheme for real use, P256: ECDSA on P-256, through the platform's own provider. It is what every DeviceKeyStore answers unless it says otherwise. Any other scheme is reachable only through an opt-in: this type's own @IdentityInternalApi, which a store on an arbitrary scheme needs (InMemoryDeviceKeyStore(scheme), or an implementor overriding DeviceKeyStore.keyScheme), or :kuilt-identity-test's @TestOnlyKeyScheme for its fake. No default, no deserialisation path and no DidKey ever selects one.

Why the seam exists. On wasmJs every P256 operation is a WebCrypto promise. A room test running under runTest that waits on one stops being a virtual-time test, so the room and timer tests in other kuilt modules check signatures with a synchronous fake scheme instead. That fake lives in :kuilt-identity-test, behind its own tests-only opt-in, and never in this module. Real P-256 stays covered here, by this module's own tests and its signature vectors.

The scheme belongs to the room, never to the key. A DidKey carries no scheme: a key read off the wire is checked under whatever scheme the reading room was built with. So a room on P256 checks every signature with ECDSA, whatever a peer sends, and a fake signature is just a wrong one.

Every member may be called from many coroutines at once, on a multi-threaded dispatcher.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract suspend fun generate(): DeviceKey

A new key in this scheme, held in memory only.

Link copied to clipboard
abstract suspend fun parse(value: String): DidKey

The key value names, as far as this scheme can check it from outside. P256 is DidKey.parse.

Link copied to clipboard
abstract suspend fun verify(key: DidKey, message: ByteArray, signature: ByteArray): Boolean

Whether signature is key's signature over message in this scheme. Never throws on bad input: a malformed key or signature is false.