Skip to content

YjsKeychain

Defined in: yjs/src/peerborne-yjs.ts:1256

Append-only keychain with canonical 32-byte identifiers.

  • Keychain<Uint8Array, CryptoKey>

new YjsKeychain(): YjsKeychain

YjsKeychain

add(): Promise<[Uint8Array<ArrayBufferLike>, CryptoKey, Uint8Array<ArrayBufferLike>]>

Defined in: yjs/src/peerborne-yjs.ts:1263

Generates and adds a new document encryption key to the keychain.

Promise<[Uint8Array<ArrayBufferLike>, CryptoKey, Uint8Array<ArrayBufferLike>]>

The new document key ID, key, and a block of change(s) describing the keychain addition.

Keychain.add


addEpochKey(epochId, key): Promise<Uint8Array<ArrayBufferLike>>

Defined in: yjs/src/peerborne-yjs.ts:1311

Add an epoch-based encryption key to the keychain.

Epoch keys are used for key rotation: each epoch has a unique 32-byte ID and an associated AES-GCM symmetric key. The key is cached locally and appended to the CRDT keychain for synchronization with peers.

Uint8Array

The 32-byte epoch identifier.

CryptoKey

The AES-GCM CryptoKey for this epoch.

Promise<Uint8Array<ArrayBufferLike>>

The serialized keychain state as a Yjs update for broadcasting.

Keychain.addEpochKey


current(): Promise<[Uint8Array<ArrayBufferLike>, CryptoKey]>

Defined in: yjs/src/peerborne-yjs.ts:1590

Gets the current encryption key that should be used to encrypt new changes.

Promise<[Uint8Array<ArrayBufferLike>, CryptoKey]>

Keychain.current


currentKeyChange(): Promise<Uint8Array<ArrayBufferLike>>

Defined in: yjs/src/peerborne-yjs.ts:1610

Gets a block of change(s) describing only the current (most recent) key. Used for current_only key distribution where new members receive the current encryption key, not the full key history. This does not itself redact retained CRDT operations encrypted during that epoch.

The returned value MUST be safe to regenerate and replay without creating a second logical keychain entry, and byte-stable for the same logical key tuple across repeated calls, restored instances, and equivalent replicas. Implementations may synthesize a standalone projection only with stable, content-derived CRDT operation identity; otherwise they MUST reject. A one-key keychain MUST export its live history so receivers share the author’s lineage and can merge the author’s next add() delta. Receivers of a projected later key hold an independent lineage and cannot merge rotation deltas authored on the full history.

Promise<Uint8Array<ArrayBufferLike>>

A replay-safe block of change(s) containing only the current key.

Keychain.currentKeyChange


getKey(keyIDBytes): CryptoKey | undefined

Defined in: yjs/src/peerborne-yjs.ts:1666

Synchronous cache lookup for a key by its ID bytes.

This is intentionally a pure cache lookup. Use keys() or current() to ensure keys are imported and cached before calling getKey.

Uint8Array

CryptoKey | undefined

Keychain.getKey


history(): Uint8Array

Defined in: yjs/src/peerborne-yjs.ts:1389

Gets a block of change(s) describing the whole state of the keychain.

Uint8Array

A block of change(s) describing the keychain.

Keychain.history


historySince(keyID): Promise<Uint8Array<ArrayBufferLike>>

Defined in: yjs/src/peerborne-yjs.ts:1636

Return stable existing keychain operations when the requested boundary is the first retained key.

A later Yjs array suffix depends on preceding client clocks/structs. A fresh minimal Doc would merge once, but independently regenerated updates use new client IDs and duplicate entries. Reject boundaries that cannot be served from existing operation history without either that replay ambiguity or disclosure of pre-boundary keys.

Uint8Array

Promise<Uint8Array<ArrayBufferLike>>

Keychain.historySince


keys(): Promise<[Uint8Array<ArrayBufferLike>, CryptoKey][]>

Defined in: yjs/src/peerborne-yjs.ts:1566

Gets the all document encryption keys in the keychain.

Promise<[Uint8Array<ArrayBufferLike>, CryptoKey][]>

all document encryption keys.

Keychain.keys


merge(change): void

Defined in: yjs/src/peerborne-yjs.ts:1398

Merges in a block of change(s) to the keychain.

Uint8Array

A block of change(s) to apply.

void

Keychain.merge


prepareAppend(changes, intent): PreparedKeychainMerge<Uint8Array<ArrayBufferLike>, CryptoKey>

Defined in: yjs/src/peerborne-yjs.ts:1408

Stage an authenticated, predecessor-bound standalone key append. This is distinct from prepareMerge() because append authority must be validated explicitly. Implementations MUST require a canonical one-key projection matching expectedNewKeyId. They may append only when the live current key matches expectedPreviousKeyId, or return an unchanged exact replay when the live sequence already ends with the expected previous/new pair and material.

Uint8Array

KeychainAppendIntent

PreparedKeychainMerge<Uint8Array<ArrayBufferLike>, CryptoKey>

Keychain.prepareAppend


prepareEpochKey(epochId, key): Promise<PreparedKeychainEpoch<Uint8Array<ArrayBufferLike>>>

Defined in: yjs/src/peerborne-yjs.ts:1317

Stage an epoch-key insertion without mutating live keychain state. BeeKEM membership transitions finish all fallible signing, sealing, serialization, and block preparation before a synchronous keychain/tree commit.

commit() MUST either apply the staged state completely or throw before mutation. It is called at most once, after every asynchronous preparation step has succeeded.

Core transaction wrappers inspect both this capability and the returned claimCommit capability without invoking accessors. Implement them as ordinary prototype methods or own data-property functions.

The epochId width contract is identical to addEpochKey(): it must equal KeychainProvider.keyIDLength, exactly 32 bytes in the shipped providers, and a mismatch must be rejected before any state is staged or mutated. The current BeeKEM wire protocols derive and authenticate fixed 32-byte epoch IDs, so a custom provider with another key-ID width cannot implement those transitions.

Uint8Array

The full-width epoch identifier.

CryptoKey

The encryption key for this epoch.

Promise<PreparedKeychainEpoch<Uint8Array<ArrayBufferLike>>>

Keychain.prepareEpochKey


prepareKey(): Promise<PreparedKeychainAddition<Uint8Array<ArrayBufferLike>, CryptoKey>>

Defined in: yjs/src/peerborne-yjs.ts:1269

Stage generation and insertion of a random document key without mutating live state. Callers can finish fallible wire preparation before invoking the synchronous commit.

Promise<PreparedKeychainAddition<Uint8Array<ArrayBufferLike>, CryptoKey>>

Keychain.prepareKey


prepareMerge(changes): PreparedKeychainMerge<Uint8Array<ArrayBufferLike>, CryptoKey>

Defined in: yjs/src/peerborne-yjs.ts:1402

Stage a remote keychain merge for an atomic Welcome state commit. Core transaction wrappers inspect this capability and the prepared hydrateKeys, getKey, and claimCommit capabilities without invoking accessors. Implement them as ordinary prototype methods or own data-property functions.

Uint8Array

PreparedKeychainMerge<Uint8Array<ArrayBufferLike>, CryptoKey>

Keychain.prepareMerge


stateCommitment(): Promise<Uint8Array<ArrayBufferLike>>

Defined in: yjs/src/peerborne-yjs.ts:1393

Commit to the validated ordered logical key sequence independently of provider-specific CRDT operation identities. Implementations MUST use computeKeychainStateCommitment.

Promise<Uint8Array<ArrayBufferLike>>

Keychain.stateCommitment