Interface Keystore

interface Keystore {
    get(kind: KeyKind): Promise<null | StoredKey>;
    getOrCreate(
        kind: KeyKind,
        factory: () => StoredKey | Promise<StoredKey>,
    ): Promise<StoredKey>;
    put(kind: KeyKind, key: StoredKey): Promise<void>;
}

Implemented by

Methods

  • Atomically return the existing key or create-and-store one — the WHOLE get→create→put cycle under the keystore's lock (issue #8). Two concurrent callers must end up with the SAME key: a lost generated key means every field sealed to it is unrecoverable (the server holds no copy; that is the design), so the factory must run at most once per stored key.

    Parameters

    Returns Promise<StoredKey>