@kumiai/mls 0.12.3 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,40 @@
1
- import { type Capabilities, type GroupContextExtension, type MlsContext } from 'ts-mls';
1
+ import { type Capabilities, type ClientConfig, type GroupContextExtension, type KeyRetentionConfig, type MlsContext } from 'ts-mls';
2
2
  import type { GroupAnchor } from './anchor.js';
3
3
  import { type JudgingContext } from './authentication.js';
4
4
  import type { GroupOptions } from './types.js';
5
+ /**
6
+ * The receive-side key retention every kumiai context carries, in place of ts-mls's
7
+ * defaults (10 skipped keys, a 200-generation forward window).
8
+ *
9
+ * A member has ONE application sender ratchet per epoch, and a host can spend it across
10
+ * several lanes a receiver drains independently (tunnel topics, a service lane, an app
11
+ * log). After a reconnect one lane can hold a backlog of hundreds of frames while a single
12
+ * newer frame on another lane opens first and moves the receiver's ratchet past them. Every
13
+ * backlog frame whose skipped key was not retained can then never be opened: ts-mls throws
14
+ * `Desired gen in the past`.
15
+ *
16
+ * - `retainKeysForGenerations: 256` — a sender that restores a persisted state advances
17
+ * past a lease of up to 64 generations it may have spent, which leaves that many skipped
18
+ * keys no frame will ever claim; the remaining 192 generations cover a cross-lane backlog.
19
+ * The window counts generations, not frames: in a group of three or more, a sender's
20
+ * frames to the other peers are generations this receiver skips and never claims, so they
21
+ * both fill the window and shorten the backlog it covers (one frame in `members - 1` is
22
+ * this receiver's). Each retained key is one 32-byte secret, about 37 bytes encoded.
23
+ * - `retainKeysForEpochs: 1` — the current epoch's tree and one past epoch's. A backlog
24
+ * sealed before the last commit is rare, and in a group of three or more every retained
25
+ * tree holds a full window per sender at steady state. Measured persisted receiver state
26
+ * at steady state: 2 members 2.6 KB, 3 members 42 KB, 5 members 82 KB, 10 members 181 KB
27
+ * (with ts-mls's four past epochs: 5.8, 103, 202 and 449 KB). That state is persisted on
28
+ * each receive advance, and ts-mls re-sorts a full window on every ratchet step.
29
+ * - `maximumForwardRatchetSteps: 512` — at least the retention, so the single newer frame
30
+ * that jumps past a full backlog still opens rather than being refused as too far ahead.
31
+ * A step is one KDF expansion, so the bound on a forged generation stays cheap.
32
+ */
33
+ export declare const KUMIAI_KEY_RETENTION_CONFIG: Readonly<KeyRetentionConfig>;
34
+ /** A context's client config, with kumiai's key retention when none is given. */
35
+ export declare function kumiaiClientConfig(): ClientConfig;
36
+ /** Copy a client config without sharing its mutable parts with the source context. */
37
+ export declare function copyClientConfig(config: ClientConfig): ClientConfig;
5
38
  /** Late-bound provider of a context's device deny set, pointed at the live handle after construction. */
6
39
  export type DeviceDenyHolder = {
7
40
  provider: () => ReadonlySet<string>;
@@ -14,7 +47,7 @@ export declare function deviceDenyHolderFor(context: MlsContext): DeviceDenyHold
14
47
  /** Run with an isolated authentication service without changing the source context. */
15
48
  export declare function withJudging<T>(context: MlsContext, judging: JudgingContext, fn: (context: MlsContext) => Promise<T>): Promise<T>;
16
49
  export declare function resolveMlsContext(options?: GroupOptions, anchor?: GroupAnchor): Promise<MlsContext>;
17
- export declare function createMlsContext(cipherSuite: MlsContext['cipherSuite'], anchor?: GroupAnchor): MlsContext;
50
+ export declare function createMlsContext(cipherSuite: MlsContext['cipherSuite'], anchor?: GroupAnchor, clientConfig?: ClientConfig): MlsContext;
18
51
  /**
19
52
  * Build the leaf-node capabilities for a member joining or creating a group. RFC
20
53
  * 9420 requires a leaf to advertise every non-default GroupContext extension type
@@ -1,9 +1,65 @@
1
- import { defaultCapabilities, getCiphersuiteImpl } from 'ts-mls';
1
+ import { defaultCapabilities, defaultKeyPackageEqualityConfig, defaultLifetimeConfig, defaultPaddingConfig, getCiphersuiteImpl } from 'ts-mls';
2
2
  import { createDIDAuthenticationService } from './authentication.js';
3
3
  import { nobleCryptoProvider } from './crypto.js';
4
4
  import { denySetOf } from './registry.js';
5
5
  const DEFAULT_CIPHERSUITE = 'MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519';
6
6
  const EMPTY_DENY = new Set();
7
+ /**
8
+ * The receive-side key retention every kumiai context carries, in place of ts-mls's
9
+ * defaults (10 skipped keys, a 200-generation forward window).
10
+ *
11
+ * A member has ONE application sender ratchet per epoch, and a host can spend it across
12
+ * several lanes a receiver drains independently (tunnel topics, a service lane, an app
13
+ * log). After a reconnect one lane can hold a backlog of hundreds of frames while a single
14
+ * newer frame on another lane opens first and moves the receiver's ratchet past them. Every
15
+ * backlog frame whose skipped key was not retained can then never be opened: ts-mls throws
16
+ * `Desired gen in the past`.
17
+ *
18
+ * - `retainKeysForGenerations: 256` — a sender that restores a persisted state advances
19
+ * past a lease of up to 64 generations it may have spent, which leaves that many skipped
20
+ * keys no frame will ever claim; the remaining 192 generations cover a cross-lane backlog.
21
+ * The window counts generations, not frames: in a group of three or more, a sender's
22
+ * frames to the other peers are generations this receiver skips and never claims, so they
23
+ * both fill the window and shorten the backlog it covers (one frame in `members - 1` is
24
+ * this receiver's). Each retained key is one 32-byte secret, about 37 bytes encoded.
25
+ * - `retainKeysForEpochs: 1` — the current epoch's tree and one past epoch's. A backlog
26
+ * sealed before the last commit is rare, and in a group of three or more every retained
27
+ * tree holds a full window per sender at steady state. Measured persisted receiver state
28
+ * at steady state: 2 members 2.6 KB, 3 members 42 KB, 5 members 82 KB, 10 members 181 KB
29
+ * (with ts-mls's four past epochs: 5.8, 103, 202 and 449 KB). That state is persisted on
30
+ * each receive advance, and ts-mls re-sorts a full window on every ratchet step.
31
+ * - `maximumForwardRatchetSteps: 512` — at least the retention, so the single newer frame
32
+ * that jumps past a full backlog still opens rather than being refused as too far ahead.
33
+ * A step is one KDF expansion, so the bound on a forged generation stays cheap.
34
+ */ export const KUMIAI_KEY_RETENTION_CONFIG = Object.freeze({
35
+ retainKeysForGenerations: 256,
36
+ retainKeysForEpochs: 1,
37
+ maximumForwardRatchetSteps: 512
38
+ });
39
+ /** A context's client config, with kumiai's key retention when none is given. */ export function kumiaiClientConfig() {
40
+ return {
41
+ keyRetentionConfig: {
42
+ ...KUMIAI_KEY_RETENTION_CONFIG
43
+ },
44
+ lifetimeConfig: {
45
+ ...defaultLifetimeConfig
46
+ },
47
+ paddingConfig: structuredClone(defaultPaddingConfig),
48
+ keyPackageEqualityConfig: defaultKeyPackageEqualityConfig
49
+ };
50
+ }
51
+ /** Copy a client config without sharing its mutable parts with the source context. */ export function copyClientConfig(config) {
52
+ const equality = config.keyPackageEqualityConfig;
53
+ return {
54
+ keyRetentionConfig: structuredClone(config.keyRetentionConfig),
55
+ lifetimeConfig: structuredClone(config.lifetimeConfig),
56
+ paddingConfig: structuredClone(config.paddingConfig),
57
+ keyPackageEqualityConfig: {
58
+ compareKeyPackages: equality.compareKeyPackages.bind(equality),
59
+ compareKeyPackageToLeafNode: equality.compareKeyPackageToLeafNode.bind(equality)
60
+ }
61
+ };
62
+ }
7
63
  const DENY_HOLDERS = new WeakMap();
8
64
  /** The deny holder for an internally built context, or undefined for others. */ export function deviceDenyHolderFor(context) {
9
65
  return DENY_HOLDERS.get(context);
@@ -41,7 +97,7 @@ export async function resolveMlsContext(options, anchor) {
41
97
  const cipherSuite = await getCiphersuiteImpl(name, options?.cryptoProvider ?? nobleCryptoProvider);
42
98
  return createMlsContext(cipherSuite, anchor);
43
99
  }
44
- export function createMlsContext(cipherSuite, anchor) {
100
+ export function createMlsContext(cipherSuite, anchor, clientConfig) {
45
101
  // The deny set cannot be known here — the handle that folds it does not exist yet. Bind a mutable
46
102
  // holder the auth service reads; the GroupHandle constructor points it at its own currentDenySet().
47
103
  const holder = {
@@ -52,7 +108,8 @@ export function createMlsContext(cipherSuite, anchor) {
52
108
  const authService = authenticationFor(holder);
53
109
  const context = {
54
110
  cipherSuite,
55
- authService
111
+ authService,
112
+ clientConfig: clientConfig == null ? kumiaiClientConfig() : copyClientConfig(clientConfig)
56
113
  };
57
114
  DENY_HOLDERS.set(context, holder);
58
115
  return context;
@@ -309,7 +309,9 @@ export declare class GroupHandle {
309
309
  * For a host that restores a persisted state and must not reuse a generation it may have
310
310
  * sent from before a crash. Each skipped generation costs one KDF step, not an encrypt.
311
311
  * Receivers must still cross the gap: ts-mls refuses a jump beyond its forward-ratchet
312
- * window (`maximumForwardRatchetSteps`, 200 by default).
312
+ * window (`maximumForwardRatchetSteps`: 512 for a kumiai context, see
313
+ * `KUMIAI_KEY_RETENTION_CONFIG`; 200 in ts-mls's default, which a peer on an older
314
+ * release still applies).
313
315
  *
314
316
  * No cap by default: a host catching up a stored high-water mark may legitimately step
315
317
  * far past any receiver's position (a receiver's window counts from the last generation
@@ -11,7 +11,7 @@ import { verifyDeviceEntry } from './device-proof.js';
11
11
  import { decodeControlEnvelope } from './envelope.js';
12
12
  import { foldEnvelope, GROUP_TYPE_PREFIX } from './envelope-fold.js';
13
13
  import { HandshakeReservationError, HandshakeWindowConfigError, HandshakeWindowError, LeafBindingError, LeafLapsedError, RevokeProofError } from './errors.js';
14
- import { createMlsContext, deviceDenyHolderFor } from './group-context.js';
14
+ import { copyClientConfig, createMlsContext, deviceDenyHolderFor, kumiaiClientConfig } from './group-context.js';
15
15
  import { readMessageEpoch } from './group-info.js';
16
16
  import { assertHeadMatches, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, readLedgerHead, readLedgerHeadExtension } from './head.js';
17
17
  import { settleAdvisory } from './history.js';
@@ -345,6 +345,9 @@ function ledgerLogEntry(entryID, token, verified) {
345
345
  this.#state = params.state;
346
346
  this.#credential = params.credential;
347
347
  this.#context = params.context;
348
+ // A caller-built context without a client config gets kumiai's, as the context a commit
349
+ // rebuilds would: in place, since the context is the key of its deny holder.
350
+ this.#context.clientConfig ??= kumiaiClientConfig();
348
351
  this.#commitPolicy = params.commitPolicy;
349
352
  this.#resolveLedgerEntries = params.resolveLedgerEntries;
350
353
  this.#onLedgerEntries = params.onLedgerEntries;
@@ -423,18 +426,7 @@ function ledgerLogEntry(entryID, token, verified) {
423
426
  }
424
427
  } : createMlsContext(this.#context.cipherSuite, this.#anchor);
425
428
  const config = this.#context.clientConfig;
426
- if (config != null) {
427
- const equality = config.keyPackageEqualityConfig;
428
- context.clientConfig = {
429
- keyRetentionConfig: structuredClone(config.keyRetentionConfig),
430
- lifetimeConfig: structuredClone(config.lifetimeConfig),
431
- paddingConfig: structuredClone(config.paddingConfig),
432
- keyPackageEqualityConfig: {
433
- compareKeyPackages: equality.compareKeyPackages.bind(equality),
434
- compareKeyPackageToLeafNode: equality.compareKeyPackageToLeafNode.bind(equality)
435
- }
436
- };
437
- }
429
+ if (config != null) context.clientConfig = copyClientConfig(config);
438
430
  context.externalPsks = structuredClone(this.#context.externalPsks);
439
431
  const params = {
440
432
  [CLONE_SOURCE]: this,
@@ -1009,7 +1001,9 @@ function ledgerLogEntry(entryID, token, verified) {
1009
1001
  * For a host that restores a persisted state and must not reuse a generation it may have
1010
1002
  * sent from before a crash. Each skipped generation costs one KDF step, not an encrypt.
1011
1003
  * Receivers must still cross the gap: ts-mls refuses a jump beyond its forward-ratchet
1012
- * window (`maximumForwardRatchetSteps`, 200 by default).
1004
+ * window (`maximumForwardRatchetSteps`: 512 for a kumiai context, see
1005
+ * `KUMIAI_KEY_RETENTION_CONFIG`; 200 in ts-mls's default, which a peer on an older
1006
+ * release still applies).
1013
1007
  *
1014
1008
  * No cap by default: a host catching up a stored high-water mark may legitimately step
1015
1009
  * far past any receiver's position (a receiver's window counts from the last generation
@@ -1863,7 +1857,8 @@ function ledgerLogEntry(entryID, token, verified) {
1863
1857
  return new GroupHandle({
1864
1858
  state,
1865
1859
  credential: group.credential,
1866
- context: createMlsContext(group.context.cipherSuite, group.anchor),
1860
+ // The post-commit handle keeps the source's receive retention, not ts-mls's defaults.
1861
+ context: createMlsContext(group.context.cipherSuite, group.anchor, group.context.clientConfig),
1867
1862
  ledger: group.ledger,
1868
1863
  commitPolicy: group.commitPolicy,
1869
1864
  resolveLedgerEntries: group.resolveLedgerEntries,
package/lib/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export { type EnvelopeFoldResult, type FoldEnvelopeContext, type FoldEnvelopePar
16
16
  export { ClientStateReservationError, HandshakeReservationError, HandshakeWindowConfigError, HandshakeWindowError, LeafBindingError, type LeafBindingReason, LeafLapsedError, type LeafLapsedReason, RecoveryKnowledgeError, type RecoveryKnowledgeReason, RevokeProofError, type RevokeProofReason, } from './errors.js';
17
17
  export { type FoldDrop, type FoldInput, foldLedger, type LedgerReducer, } from './fold.js';
18
18
  export { addDevice, announceControllerBeacon, type CommitInviteResult, type CommitLedgerEntriesResult, CommitRejectedError, type CreateGroupResult, type CreateInviteParams, type CreateInviteResult, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, createLastResortKeyPackageBundle, type DeviceWriteResult, type ExportGroupInfoParams, type ExportGroupInfoResult, exportGroupInfo, GroupHandle, type GroupHandleEvents, type GroupHandleParams, type HeldLedgerEntry, type InspectGroupInfoResult, InviteRecipientMismatchError, type InviteRecipientMismatchErrorParams, inspectGroupInfo, type JoinGroupExternalParams, type JoinGroupExternalResult, joinGroupExternal, LAST_RESORT_EXTENSION_TYPE, LAST_RESORT_LIFETIME_DAYS, type LedgerLogEntry, labelDevice, makeMLSCredential, ORDINARY_KEY_PACKAGE_LIFETIME_DAYS, type ProcessWelcomeOnceParams, type ProcessWelcomeParams, type ProcessWelcomeResult, processWelcome, processWelcomeOnce, type RemoveMemberResult, type RestoreGroupParams, readCommitEntryIDs, readMessageAAD, readMessageEpoch, registerDevice, removeMember, restoreGroup, revokeDevice, type SendAdmission, } from './group.js';
19
+ export { KUMIAI_KEY_RETENTION_CONFIG } from './group-context.js';
19
20
  export { registryAt } from './group-handle.js';
20
21
  export { attestTreeTime, type CommitResult, commitSelfRemovals, controllerLogDelta, preservationClock, proposeSelfRemoval, publishControllerLog, type RemovalEvidence, type RemoveLapsedLeavesResult, type RevokeBuildResult, type RevokeWithProofParams, removalEvidence, removeLapsedLeaves, renewLeaf, revokeWithProof, survivorTargets, } from './group-lifecycle.js';
21
22
  export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, LEDGER_HEAD_VERSION, type LedgerHead, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension, } from './head.js';
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ export { foldEnvelope } from './envelope-fold.js';
13
13
  export { ClientStateReservationError, HandshakeReservationError, HandshakeWindowConfigError, HandshakeWindowError, LeafBindingError, LeafLapsedError, RecoveryKnowledgeError, RevokeProofError } from './errors.js';
14
14
  export { foldLedger } from './fold.js';
15
15
  export { addDevice, announceControllerBeacon, CommitRejectedError, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, createLastResortKeyPackageBundle, exportGroupInfo, GroupHandle, InviteRecipientMismatchError, inspectGroupInfo, joinGroupExternal, LAST_RESORT_EXTENSION_TYPE, LAST_RESORT_LIFETIME_DAYS, labelDevice, makeMLSCredential, ORDINARY_KEY_PACKAGE_LIFETIME_DAYS, processWelcome, processWelcomeOnce, readCommitEntryIDs, readMessageAAD, readMessageEpoch, registerDevice, removeMember, restoreGroup, revokeDevice } from './group.js';
16
+ export { KUMIAI_KEY_RETENTION_CONFIG } from './group-context.js';
16
17
  export { registryAt } from './group-handle.js';
17
18
  export { attestTreeTime, commitSelfRemovals, controllerLogDelta, preservationClock, proposeSelfRemoval, publishControllerLog, removalEvidence, removeLapsedLeaves, renewLeaf, revokeWithProof, survivorTargets } from './group-lifecycle.js';
18
19
  export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, LEDGER_HEAD_VERSION, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension } from './head.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/mls",
3
- "version": "0.12.3",
3
+ "version": "0.12.4",
4
4
  "description": "E2EE group identity and membership for Enkaku using MLS",
5
5
  "keywords": [
6
6
  "mls",