FakeKeyScheme

class FakeKeyScheme(random: Random, before: suspend (FakeKeyOperation) -> Unit = {}) : KeyScheme

A KeyScheme for tests: it makes keys, reads keys, signs and checks without ever waiting on the platform's cryptographic provider, so a room test on wasmJs stays on virtual time. Anyone can forge its signatures: a signature is SHA-512 of a fixed tag, the key's compressed point and the message.

It still refuses everything a real scheme refuses for the reasons a room test checks: a signature under another key, over another message, or with any byte changed. So a test that asserts a room turns away a forged or replayed proof is not made vacuous by running on it.

  • generate makes a key whose 33-byte compressed point is 0x02 followed by 32 bytes from random. The point is not necessarily on P-256: nothing here does curve math.

  • key makes the fixed key numbered index, without suspending.

  • parse checks syntax only, as a frame's serializer does.

  • verify recomputes the signature and compares it.

Every operation first runs before, which by default does nothing and returns at once. A test that needs a gap — a Goodbye landing between a Challenge and its Proof, a re-Hello while a decision is in flight — passes a before that suspends on a gate it opens later. A test that needs the provider to fail passes one that throws: the throw escapes the operation unchanged, as an IllegalStateException from a real provider would. before runs outside every lock, and for a key's signatures too.

A room picks the scheme up through its DeviceKeyStore: build the store with fakeKeyStore, and the room reads DeviceKeyStore.keyScheme from it. A room on a real store checks every signature with ECDSA, so a fake signature sent to it is simply a bad one.

Every fake scheme checks every other fake scheme's signatures, and fakeDeviceKey's: the scheme holds no secret. A store's key does not come from generate but from the index the store was built with, so two stores with different indices are two devices with two different keys whichever schemes they share.

Parameters

random

where generate's points come from. There is no default: pass a seeded Random, so a red that depends on which key sorts first replays the same way. Two schemes on equal seeds draw the same keys. Draws are taken under a lock, so one scheme is safe to share across threads.

before

runs at the start of every operation, with the operation it is about to run.

Constructors

Link copied to clipboard
constructor(random: Random, before: suspend (FakeKeyOperation) -> Unit = {})

Functions

Link copied to clipboard
open suspend override fun generate(): DeviceKey
Link copied to clipboard
fun key(index: Int): DeviceKey

The fixed key numbered index, the same in every run and on every target, made without suspending. Its signatures run this scheme's before. Its DeviceKey.id is fakeDidKey(index).

Link copied to clipboard
open suspend override fun parse(value: String): DidKey
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open suspend override fun verify(key: DidKey, message: ByteArray, signature: ByteArray): Boolean