@kumiai/mls 0.13.1 → 0.13.3

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.
Files changed (42) hide show
  1. package/README.md +19 -0
  2. package/lib/authentication.d.ts +4 -3
  3. package/lib/authentication.js +10 -0
  4. package/lib/capability.d.ts +1 -0
  5. package/lib/capability.js +1 -1
  6. package/lib/controller-ingest.d.ts +2 -1
  7. package/lib/controller-log.d.ts +7 -6
  8. package/lib/crypto.js +15 -7
  9. package/lib/device-proof.d.ts +2 -1
  10. package/lib/embedded-resolver.d.ts +2 -1
  11. package/lib/envelope-fold.d.ts +2 -1
  12. package/lib/envelope-fold.js +2 -1
  13. package/lib/group-commit.d.ts +7 -7
  14. package/lib/group-commit.js +31 -15
  15. package/lib/group-context.d.ts +2 -2
  16. package/lib/group-context.js +4 -0
  17. package/lib/group-create.d.ts +3 -3
  18. package/lib/group-create.js +12 -5
  19. package/lib/group-credential.d.ts +5 -3
  20. package/lib/group-credential.js +15 -16
  21. package/lib/group-device.d.ts +2 -1
  22. package/lib/group-device.js +20 -10
  23. package/lib/group-handle.d.ts +9 -8
  24. package/lib/group-handle.js +48 -25
  25. package/lib/group-lifecycle.d.ts +16 -15
  26. package/lib/group-lifecycle.js +55 -29
  27. package/lib/group-membership.d.ts +3 -2
  28. package/lib/group-membership.js +4 -3
  29. package/lib/group-welcome.d.ts +3 -3
  30. package/lib/group-welcome.js +25 -6
  31. package/lib/history.d.ts +3 -2
  32. package/lib/index.d.ts +1 -1
  33. package/lib/ledger.d.ts +4 -3
  34. package/lib/ledger.js +3 -2
  35. package/lib/lifecycle-proof.d.ts +6 -5
  36. package/lib/lifecycle-proof.js +8 -6
  37. package/lib/lifecycle.d.ts +8 -7
  38. package/lib/lifecycle.js +46 -29
  39. package/lib/member-root.d.ts +8 -7
  40. package/lib/registry.d.ts +6 -5
  41. package/lib/types.d.ts +1 -0
  42. package/package.json +8 -8
@@ -71,11 +71,13 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
71
71
  const registry = anchor.controller == null || options?.controllerLog == null ? undefined : await registryForLog({
72
72
  controller: anchor.controller,
73
73
  log: options.controllerLog,
74
- crypto: options.crypto
74
+ crypto: options.crypto,
75
+ yield: options.yield
75
76
  });
76
77
  const tokens = [];
77
78
  if (anchor.controller != null && options?.controllerLog != null) {
78
79
  tokens.push(await signLedgerEntry({
80
+ yield: options.yield,
79
81
  identity,
80
82
  entry: {
81
83
  type: DEVICE_ENTRY_TYPE,
@@ -100,10 +102,12 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
100
102
  if (options?.controller != null) {
101
103
  await verifyLeafCredential(mlsCredential, identity.publicKey, {
102
104
  crypto: options.crypto,
105
+ yield: options.yield,
103
106
  judging: ()=>({
104
107
  registry,
105
108
  stage: 'full',
106
- mode: 'admit'
109
+ mode: 'admit',
110
+ yield: options.yield
107
111
  }),
108
112
  leafLifetime: ()=>anchor.leafLifetime ?? 86_400,
109
113
  trustedGrantLifetime: ()=>anchor.trustedGrantLifetime ?? 2_592_000
@@ -119,7 +123,8 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
119
123
  const state = await withJudging(context, {
120
124
  registry,
121
125
  stage: 'full',
122
- mode: 'admit'
126
+ mode: 'admit',
127
+ yield: options.yield
123
128
  }, async (judgedContext)=>{
124
129
  const keyPackage = await generateKeyPackageWithKey({
125
130
  credential: mlsCredential,
@@ -144,6 +149,7 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
144
149
  };
145
150
  const group = await GroupHandle.create({
146
151
  crypto: options?.crypto,
152
+ yield: options.yield,
147
153
  state,
148
154
  credential,
149
155
  context,
@@ -151,7 +157,7 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
151
157
  resolveLedgerEntries: options?.resolveLedgerEntries,
152
158
  onLedgerEntries: options?.onLedgerEntries
153
159
  });
154
- await group.applyLedgerEntries(tokens);
160
+ await group.applyLedgerEntries(tokens, options);
155
161
  return {
156
162
  group,
157
163
  credential
@@ -162,6 +168,7 @@ export async function restoreGroup(params) {
162
168
  // an anchorless state throws (the same fail-closed guard).
163
169
  const group = await GroupHandle.create({
164
170
  crypto: params.options?.crypto,
171
+ yield: params.yield,
165
172
  state: params.state,
166
173
  credential: params.credential,
167
174
  context: await resolveMlsContext(params.options),
@@ -169,6 +176,6 @@ export async function restoreGroup(params) {
169
176
  resolveLedgerEntries: params.options?.resolveLedgerEntries,
170
177
  onLedgerEntries: params.options?.onLedgerEntries
171
178
  });
172
- await group.applyLedgerEntries(params.ledgerEntries ?? []);
179
+ await group.applyLedgerEntries(params.ledgerEntries ?? [], params);
173
180
  return group;
174
181
  }
@@ -7,7 +7,7 @@ export type MakeMLSCredentialParams = {
7
7
  controller?: ControllerBinding;
8
8
  };
9
9
  export declare function makeMLSCredential({ identity, controller }: MakeMLSCredentialParams): Credential;
10
- export declare function assertBindingAuthorTime(controller?: ControllerBinding): void;
10
+ export declare function assertBindingAuthorTime(controller?: ControllerBinding, nowSeconds?: number): void;
11
11
  /**
12
12
  * How long an ordinary, single-use key package stays valid, in days.
13
13
  *
@@ -19,9 +19,10 @@ export declare function assertBindingAuthorTime(controller?: ControllerBinding):
19
19
  export declare const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
20
20
  export type CreateKeyPackageBundleParams = {
21
21
  identity: OwnIdentity;
22
+ nowSeconds?: number;
22
23
  } & GroupOptions;
23
24
  /** Generate a key package for joining groups. */
24
- export declare function createKeyPackageBundle({ identity, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
25
+ export declare function createKeyPackageBundle({ identity, nowSeconds, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
25
26
  /**
26
27
  * The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
27
28
  * no such extension). Its presence marks a key package as reusable by design; its data is empty.
@@ -53,6 +54,7 @@ export declare const LAST_RESORT_EXTENSION_TYPE = 10;
53
54
  export declare const LAST_RESORT_LIFETIME_DAYS = 90;
54
55
  export type CreateLastResortKeyPackageBundleParams = {
55
56
  identity: OwnIdentity;
57
+ nowSeconds?: number;
56
58
  } & GroupOptions;
57
59
  /**
58
60
  * Generate a reusable last-resort key package for joining groups.
@@ -71,4 +73,4 @@ export type CreateLastResortKeyPackageBundleParams = {
71
73
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
72
74
  * obligations fail the same way: silently, and precisely when the floor is needed.
73
75
  */
74
- export declare function createLastResortKeyPackageBundle({ identity, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
76
+ export declare function createLastResortKeyPackageBundle({ identity, nowSeconds, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
@@ -1,4 +1,4 @@
1
- import { isPeer4, now } from '@kokuin/token';
1
+ import { isPeer4 } from '@kokuin/token';
2
2
  import { defaultCredentialTypes, generateKeyPackageWithKey, greaseExtensions, makeCustomExtension } from 'ts-mls';
3
3
  import { controlCapabilities } from './anchor.js';
4
4
  import { verifyLeafCredential } from './authentication.js';
@@ -7,6 +7,7 @@ import { LeafBindingError } from './errors.js';
7
7
  import { resolveMlsContext } from './group-context.js';
8
8
  import { memberRootsOf } from './member-root.js';
9
9
  import { registryForLog } from './registry.js';
10
+ const currentSeconds = ()=>Math.floor(Date.now() / 1000);
10
11
  export function makeMLSCredential({ identity, controller }) {
11
12
  const id = identity.id;
12
13
  const isPeer = isPeer4(id);
@@ -26,17 +27,17 @@ export function makeMLSCredential({ identity, controller }) {
26
27
  identity: new TextEncoder().encode(JSON.stringify(payload))
27
28
  };
28
29
  }
29
- export function assertBindingAuthorTime(controller) {
30
+ export function assertBindingAuthorTime(controller, nowSeconds = currentSeconds()) {
30
31
  if (controller == null) return;
31
32
  if (controller.member != null) {
32
- if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat > now()) {
33
+ if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat > nowSeconds) {
33
34
  throw new Error('Membership binding is not valid at authoring time');
34
35
  }
35
36
  return;
36
37
  }
37
38
  if (controller.capability == null) throw new LeafBindingError('controller-mismatch');
38
39
  const { iat, exp } = readCapability(controller.capability).payload;
39
- const timestamp = now();
40
+ const timestamp = nowSeconds;
40
41
  if (exp <= timestamp || iat > timestamp) {
41
42
  throw new Error('Leaf capability is not valid at authoring time');
42
43
  }
@@ -49,8 +50,8 @@ export function assertBindingAuthorTime(controller) {
49
50
  * `extensions` is left genuinely absent (not passed as `undefined`) when the caller supplies none,
50
51
  * so `generateKeyPackageWithKey`'s own `params.extensions ?? greaseExtensions(...)` default still
51
52
  * applies for the ordinary path.
52
- */ async function buildBundle(identity, options, overrides = {}) {
53
- assertBindingAuthorTime(options?.controller);
53
+ */ async function buildBundle(identity, options, overrides = {}, nowSeconds) {
54
+ assertBindingAuthorTime(options?.controller, nowSeconds);
54
55
  const credential = makeMLSCredential({
55
56
  identity,
56
57
  controller: options?.controller
@@ -105,17 +106,16 @@ export function assertBindingAuthorTime(controller) {
105
106
  * default can move under a patch bump. 30 sits well under the 4-month `maximumTotalLifetime` ts-mls
106
107
  * declares, and makes a weekly top-up comfortable rather than marginal.
107
108
  */ export const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
108
- /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime() {
109
- const nowSeconds = Math.floor(Date.now() / 1000);
109
+ /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime(nowSeconds) {
110
110
  return {
111
111
  notBefore: BigInt(nowSeconds - 86_400),
112
112
  notAfter: BigInt(nowSeconds + ORDINARY_KEY_PACKAGE_LIFETIME_DAYS * 86_400)
113
113
  };
114
114
  }
115
- /** Generate a key package for joining groups. */ export async function createKeyPackageBundle({ identity, ...options }) {
115
+ /** Generate a key package for joining groups. */ export async function createKeyPackageBundle({ identity, nowSeconds = currentSeconds(), ...options }) {
116
116
  return buildBundle(identity, options, {
117
- lifetime: ordinaryLifetime()
118
- });
117
+ lifetime: ordinaryLifetime(nowSeconds)
118
+ }, nowSeconds);
119
119
  }
120
120
  /**
121
121
  * The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
@@ -144,8 +144,7 @@ export function assertBindingAuthorTime(controller) {
144
144
  * **This is a rotation deadline, not a solution.** A host must re-upload before it elapses, or the
145
145
  * floor disappears exactly when it is needed.
146
146
  */ export const LAST_RESORT_LIFETIME_DAYS = 90;
147
- /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime() {
148
- const nowSeconds = Math.floor(Date.now() / 1000);
147
+ /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime(nowSeconds) {
149
148
  return {
150
149
  notBefore: BigInt(nowSeconds - 86_400),
151
150
  notAfter: BigInt(nowSeconds + LAST_RESORT_LIFETIME_DAYS * 86_400)
@@ -167,7 +166,7 @@ export function assertBindingAuthorTime(controller) {
167
166
  * carries an MLS lifetime, and an inviter validates it when building the Add — so an unrotated
168
167
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
169
168
  * obligations fail the same way: silently, and precisely when the floor is needed.
170
- */ export async function createLastResortKeyPackageBundle({ identity, ...options }) {
169
+ */ export async function createLastResortKeyPackageBundle({ identity, nowSeconds = currentSeconds(), ...options }) {
171
170
  return buildBundle(identity, options, {
172
171
  // Supplying `extensions` at all suppresses ts-mls's own default of
173
172
  // `greaseExtensions(defaultGreaseConfig)`. `defaultGreaseConfig` is not exported, so its 0.1
@@ -181,6 +180,6 @@ export function assertBindingAuthorTime(controller) {
181
180
  extensionData: new Uint8Array(0)
182
181
  })
183
182
  ],
184
- lifetime: lastResortLifetime()
185
- });
183
+ lifetime: lastResortLifetime(nowSeconds)
184
+ }, nowSeconds);
186
185
  }
@@ -1,6 +1,7 @@
1
1
  import { type SigningIdentity } from '@kokuin/token';
2
2
  import { type KeyPackage } from 'ts-mls';
3
3
  import { type GroupHandle } from './group-handle.js';
4
+ import type { YieldOptions } from './types.js';
4
5
  export type DeviceWriteResult = {
5
6
  /** Framed MLSMessage bytes. The caller (kubun) broadcasts to existing members via its DS. */
6
7
  commitMessage: Uint8Array;
@@ -8,7 +9,7 @@ export type DeviceWriteResult = {
8
9
  /** Post-commit epoch (== newGroup.epoch). */
9
10
  epoch: bigint;
10
11
  };
11
- type GroupSigner = {
12
+ type GroupSigner = YieldOptions & {
12
13
  group: GroupHandle;
13
14
  identity: SigningIdentity;
14
15
  };
@@ -13,6 +13,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
13
13
  */ export async function registerDevice({ group, identity, ...params }) {
14
14
  return mutexFor(group).run(async ()=>{
15
15
  const token = await signLedgerEntry({
16
+ yield: params.yield,
16
17
  identity,
17
18
  entry: {
18
19
  type: DEVICE_ENTRY_TYPE,
@@ -28,6 +29,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
28
29
  }
29
30
  });
30
31
  const result = await commitWithEntries({
32
+ yield: params.yield,
31
33
  group,
32
34
  extraProposals: [],
33
35
  enacted: [
@@ -35,8 +37,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
35
37
  ],
36
38
  requireAdmin: false
37
39
  });
38
- const newGroup = await deriveGroup(group, result.newState);
39
- await newGroup.applyLedgerEntries(result.enacted);
40
+ const newGroup = await deriveGroup(group, result.newState, params);
41
+ await newGroup.applyLedgerEntries(result.enacted, params);
40
42
  return {
41
43
  commitMessage: encode(mlsMessageEncoder, result.commit),
42
44
  newGroup,
@@ -50,6 +52,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
50
52
  */ export async function labelDevice({ group, identity, ...params }) {
51
53
  return mutexFor(group).run(async ()=>{
52
54
  const token = await signLedgerEntry({
55
+ yield: params.yield,
53
56
  identity,
54
57
  entry: {
55
58
  type: DEVICE_ENTRY_TYPE,
@@ -63,6 +66,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
63
66
  }
64
67
  });
65
68
  const result = await commitWithEntries({
69
+ yield: params.yield,
66
70
  group,
67
71
  extraProposals: [],
68
72
  enacted: [
@@ -70,8 +74,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
70
74
  ],
71
75
  requireAdmin: false
72
76
  });
73
- const newGroup = await deriveGroup(group, result.newState);
74
- await newGroup.applyLedgerEntries(result.enacted);
77
+ const newGroup = await deriveGroup(group, result.newState, params);
78
+ await newGroup.applyLedgerEntries(result.enacted, params);
75
79
  return {
76
80
  commitMessage: encode(mlsMessageEncoder, result.commit),
77
81
  newGroup,
@@ -96,6 +100,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
96
100
  throw new Error(`addDevice: the key package presents ${presentedDID}, not the device ${normalizeDID(params.device)}`);
97
101
  }
98
102
  const token = await signLedgerEntry({
103
+ yield: params.yield,
99
104
  identity,
100
105
  entry: {
101
106
  type: DEVICE_ENTRY_TYPE,
@@ -115,6 +120,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
115
120
  }
116
121
  };
117
122
  const result = await commitWithEntries({
123
+ yield: params.yield,
118
124
  group,
119
125
  extraProposals: [
120
126
  addProposal
@@ -128,8 +134,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
128
134
  if (result.welcome == null) {
129
135
  throw new Error('addDevice: expected a Welcome message for the add proposal');
130
136
  }
131
- const newGroup = await deriveGroup(group, result.newState);
132
- await newGroup.applyLedgerEntries(result.enacted);
137
+ const newGroup = await deriveGroup(group, result.newState, params);
138
+ await newGroup.applyLedgerEntries(result.enacted, params);
133
139
  return {
134
140
  commitMessage: encode(mlsMessageEncoder, result.commit),
135
141
  welcomeMessage: encode(mlsMessageEncoder, result.welcome),
@@ -148,6 +154,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
148
154
  */ export async function revokeDevice({ group, identity, ...params }) {
149
155
  return mutexFor(group).run(async ()=>{
150
156
  const token = await signLedgerEntry({
157
+ yield: params.yield,
151
158
  identity,
152
159
  entry: {
153
160
  type: DEVICE_ENTRY_TYPE,
@@ -169,6 +176,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
169
176
  }
170
177
  ];
171
178
  const result = await commitWithEntries({
179
+ yield: params.yield,
172
180
  group,
173
181
  extraProposals: proposals,
174
182
  enacted: [
@@ -176,8 +184,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
176
184
  ],
177
185
  requireAdmin: false
178
186
  });
179
- const newGroup = await deriveGroup(group, result.newState);
180
- await newGroup.applyLedgerEntries(result.enacted);
187
+ const newGroup = await deriveGroup(group, result.newState, params);
188
+ await newGroup.applyLedgerEntries(result.enacted, params);
181
189
  return {
182
190
  commitMessage: encode(mlsMessageEncoder, result.commit),
183
191
  newGroup,
@@ -193,6 +201,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
193
201
  */ export async function announceControllerBeacon({ group, identity, ...params }) {
194
202
  return mutexFor(group).run(async ()=>{
195
203
  const token = await signLedgerEntry({
204
+ yield: params.yield,
196
205
  identity,
197
206
  entry: {
198
207
  type: DEVICE_ENTRY_TYPE,
@@ -206,6 +215,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
206
215
  }
207
216
  });
208
217
  const result = await commitWithEntries({
218
+ yield: params.yield,
209
219
  group,
210
220
  extraProposals: [],
211
221
  enacted: [
@@ -213,8 +223,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
213
223
  ],
214
224
  requireAdmin: false
215
225
  });
216
- const newGroup = await deriveGroup(group, result.newState);
217
- await newGroup.applyLedgerEntries(result.enacted);
226
+ const newGroup = await deriveGroup(group, result.newState, params);
227
+ await newGroup.applyLedgerEntries(result.enacted, params);
218
228
  return {
219
229
  commitMessage: encode(mlsMessageEncoder, result.commit),
220
230
  newGroup,
@@ -13,6 +13,7 @@ import { type Mutex } from './mutex.js';
13
13
  import { type CommitPolicyContext } from './policy.js';
14
14
  import { type DeviceOp, type DeviceRegistry } from './registry.js';
15
15
  import type { RosterState } from './roster.js';
16
+ import type { YieldOptions } from './types.js';
16
17
  declare const CLONE_SOURCE: unique symbol;
17
18
  type CloneGroupHandleParams = GroupHandleParams & {
18
19
  [CLONE_SOURCE]: GroupHandle;
@@ -27,11 +28,11 @@ type FoldedControl = {
27
28
  type FoldedGroupHandleParams = GroupHandleParams & {
28
29
  [FOLDED_CONTROL]: FoldedControl;
29
30
  };
30
- export type RegistryAtParams = {
31
+ export type RegistryAtParams = YieldOptions & {
31
32
  group: GroupHandle;
32
33
  head: Uint8Array;
33
34
  };
34
- export declare function registryAt({ group, head }: RegistryAtParams): Promise<DeviceRegistry>;
35
+ export declare function registryAt({ group, head, ...options }: RegistryAtParams): Promise<DeviceRegistry>;
35
36
  export declare function mutexFor(handle: GroupHandle): Mutex;
36
37
  /** Events a GroupHandle emits. Advisory notifications derived from the folded ledger; never
37
38
  * a protocol input. Delivered via `fire` (a throwing listener never breaks a fold). */
@@ -96,7 +97,7 @@ export type LedgerLogEntry = HeldLedgerEntry & {
96
97
  entryID: string;
97
98
  };
98
99
  export declare const VERIFIED_LEDGER_TOKEN_CACHE_SIZE = 4096;
99
- export type GroupHandleParams = CryptoOptions & {
100
+ export type GroupHandleParams = CryptoOptions & YieldOptions & {
100
101
  state: ClientState;
101
102
  credential: MemberCredential;
102
103
  context: MlsContext;
@@ -115,7 +116,7 @@ export type GroupHandleParams = CryptoOptions & {
115
116
  /** Defer authored control notifications until adoption. */
116
117
  speculative?: boolean;
117
118
  };
118
- export type GroupHandleBootstrapLedgerParams = {
119
+ export type GroupHandleBootstrapLedgerParams = YieldOptions & {
119
120
  tokens: Array<string>;
120
121
  persist?: (handle: GroupHandle) => Promise<void> | void;
121
122
  };
@@ -147,7 +148,7 @@ export type GroupHandleDecryptStagedParams = {
147
148
  aad: Uint8Array;
148
149
  }) => Promise<void>;
149
150
  };
150
- export type GroupHandleProcessMessageParams = {
151
+ export type GroupHandleProcessMessageParams = YieldOptions & {
151
152
  message: Uint8Array | MlsFramedMessage;
152
153
  commitPolicy?: IncomingMessageCallback;
153
154
  persist?: (handle: GroupHandle) => Promise<void> | void;
@@ -239,7 +240,7 @@ export declare class GroupHandle {
239
240
  * it (MLS applies each once, restoreGroup replays a token list once, processWelcome
240
241
  * folds an invite once). Serialized on the handle's mutex.
241
242
  */
242
- applyLedgerEntries(tokens: Array<string>): Promise<Array<VerifiedLedgerEntry>>;
243
+ applyLedgerEntries(tokens: Array<string>, options?: YieldOptions): Promise<Array<VerifiedLedgerEntry>>;
243
244
  /**
244
245
  * Whether the ledger this handle holds is the whole ledger its GroupContext
245
246
  * attests to: the head folded from the ids it holds, in order, against the
@@ -347,7 +348,7 @@ export declare class GroupHandle {
347
348
  * Once a member processes a pending self-removal, application encrypt throws until
348
349
  * a commit lands. Callers should commit pending self-removals promptly.
349
350
  */
350
- proposeSelfRemoval(): Promise<{
351
+ proposeSelfRemoval(options?: YieldOptions): Promise<{
351
352
  frame: Uint8Array;
352
353
  epoch: bigint;
353
354
  }>;
@@ -513,5 +514,5 @@ export declare function buildCommitPolicyContext(handle: GroupHandle, args: {
513
514
  externalCommitDID?: string;
514
515
  }): CommitPolicyContext;
515
516
  /** Build the handle a commit hands back: the post-commit state, everything else inherited. */
516
- export declare function deriveGroup(group: GroupHandle, state: ClientState): Promise<GroupHandle>;
517
+ export declare function deriveGroup(group: GroupHandle, state: ClientState, options?: YieldOptions): Promise<GroupHandle>;
517
518
  export {};
@@ -31,7 +31,7 @@ const FOLDED_CONTROL = Symbol('foldedControl');
31
31
  async function computeAdmission(view) {
32
32
  const leaf = leafAt(view.state.ratchetTree, view.state.privatePath.leafIndex);
33
33
  const epoch = Number(view.state.groupContext.epoch);
34
- return Object.freeze(leaf != null && await isLapsed(view, leaf) ? {
34
+ return Object.freeze(leaf != null && await isLapsed(view, leaf, view.registry, view) ? {
35
35
  epoch,
36
36
  admissible: false,
37
37
  reason: 'lapsed'
@@ -41,7 +41,7 @@ async function computeAdmission(view) {
41
41
  });
42
42
  }
43
43
  const HISTORICAL_REGISTRIES = new WeakMap();
44
- export async function registryAt({ group, head }) {
44
+ export async function registryAt({ group, head, ...options }) {
45
45
  let cache = HISTORICAL_REGISTRIES.get(group);
46
46
  if (cache == null) {
47
47
  cache = new Map();
@@ -70,7 +70,8 @@ export async function registryAt({ group, head }) {
70
70
  actual: head
71
71
  })) throw new Error('Unknown epoch ledger head');
72
72
  const registry = (await foldLedgerControl(group.ledger.slice(0, length), group.anchor, group.groupID, {
73
- crypto: group.crypto
73
+ crypto: group.crypto,
74
+ yield: options?.yield
74
75
  })).registry;
75
76
  cache.set(key, registry);
76
77
  if (cache.size > 8) {
@@ -403,16 +404,19 @@ function ledgerLogEntry(entryID, token, verified) {
403
404
  const folded = await foldLedgerControl([
404
405
  ...params.ledger ?? []
405
406
  ], anchor, params.credential.groupID, {
406
- crypto
407
+ crypto,
408
+ yield: params.yield
407
409
  });
408
410
  const registry = await registryWithTreeBindings(folded.registry, params.state.ratchetTree, anchor, {
409
- crypto
411
+ crypto,
412
+ yield: params.yield
410
413
  });
411
414
  const admission = await computeAdmission({
412
415
  state: params.state,
413
416
  anchor,
414
417
  registry,
415
- crypto
418
+ crypto,
419
+ yield: params.yield
416
420
  });
417
421
  const seeded = {
418
422
  ...params,
@@ -719,7 +723,7 @@ function ledgerLogEntry(entryID, token, verified) {
719
723
  * express a demotion back to a previously-held role. Nothing replays a commit into
720
724
  * it (MLS applies each once, restoreGroup replays a token list once, processWelcome
721
725
  * folds an invite once). Serialized on the handle's mutex.
722
- */ async applyLedgerEntries(tokens) {
726
+ */ async applyLedgerEntries(tokens, options) {
723
727
  return mutexFor(this).run(async ()=>{
724
728
  const appended = [];
725
729
  const candidates = [];
@@ -727,7 +731,7 @@ function ledgerLogEntry(entryID, token, verified) {
727
731
  const memo = remembered != null && remembered.crypto === this.#crypto ? remembered.held : undefined;
728
732
  const nextMemo = [];
729
733
  for (const [index, token] of tokens.entries()){
730
- await maybeYield();
734
+ if (options?.yield !== false) await maybeYield();
731
735
  const held = memo?.[index];
732
736
  let verified;
733
737
  if (held?.token === token) {
@@ -741,7 +745,8 @@ function ledgerLogEntry(entryID, token, verified) {
741
745
  verified = structuredClone(held.verified);
742
746
  } else {
743
747
  verified = await verifyCachedLedgerEntry(token, {
744
- crypto: this.#crypto
748
+ crypto: this.#crypto,
749
+ yield: options?.yield
745
750
  });
746
751
  }
747
752
  if (verified == null || verified.entry.groupID !== this.groupID) continue;
@@ -756,16 +761,19 @@ function ledgerLogEntry(entryID, token, verified) {
756
761
  ...candidates
757
762
  ];
758
763
  const folded = await foldLedgerControl(ledger, this.#anchor, this.groupID, {
759
- crypto: this.#crypto
764
+ crypto: this.#crypto,
765
+ yield: options?.yield
760
766
  });
761
767
  const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
762
- crypto: this.#crypto
768
+ crypto: this.#crypto,
769
+ yield: options?.yield
763
770
  });
764
771
  const admission = await computeAdmission({
765
772
  state: this.#state,
766
773
  anchor: this.#anchor,
767
774
  registry,
768
- crypto: this.#crypto
775
+ crypto: this.#crypto,
776
+ yield: options?.yield
769
777
  });
770
778
  this.#ledger = ledger;
771
779
  for (const { entryID, token, verified } of candidates){
@@ -865,10 +873,11 @@ function ledgerLogEntry(entryID, token, verified) {
865
873
  });
866
874
  const log = [];
867
875
  for(let index = 0; index < tokens.length; index++){
868
- await maybeYield();
876
+ if (opts?.yield !== false) await maybeYield();
869
877
  const token = tokens[index];
870
878
  const verified = await verifyCachedLedgerEntry(token, {
871
- crypto: this.#crypto
879
+ crypto: this.#crypto,
880
+ yield: opts?.yield
872
881
  });
873
882
  if (verified == null || verified.entry.groupID !== this.groupID) {
874
883
  // Unreachable past the gate — the chain digests the token bytes, so an
@@ -893,16 +902,19 @@ function ledgerLogEntry(entryID, token, verified) {
893
902
  admission: this.#admission
894
903
  };
895
904
  const folded = await foldLedgerControl(log, this.#anchor, this.groupID, {
896
- crypto: this.#crypto
905
+ crypto: this.#crypto,
906
+ yield: opts?.yield
897
907
  });
898
908
  const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
899
- crypto: this.#crypto
909
+ crypto: this.#crypto,
910
+ yield: opts?.yield
900
911
  });
901
912
  const admission = await computeAdmission({
902
913
  state: this.#state,
903
914
  anchor: this.#anchor,
904
915
  registry,
905
- crypto: this.#crypto
916
+ crypto: this.#crypto,
917
+ yield: opts?.yield
906
918
  });
907
919
  this.#ledger = log;
908
920
  this.#entryBodies = new Map(log.map(({ entryID, token, verified })=>[
@@ -1058,7 +1070,7 @@ function ledgerLogEntry(entryID, token, verified) {
1058
1070
  * Author and retain an authenticated self-removal proposal under the handle mutex.
1059
1071
  * Once a member processes a pending self-removal, application encrypt throws until
1060
1072
  * a commit lands. Callers should commit pending self-removals promptly.
1061
- */ async proposeSelfRemoval() {
1073
+ */ async proposeSelfRemoval(options) {
1062
1074
  return mutexFor(this).run(async ()=>{
1063
1075
  const senderLeafIndex = this.#state.privatePath.leafIndex;
1064
1076
  const proposal = {
@@ -1069,6 +1081,7 @@ function ledgerLogEntry(entryID, token, verified) {
1069
1081
  };
1070
1082
  const gate = await prepareLifecycleGate({
1071
1083
  group: this,
1084
+ yield: options?.yield,
1072
1085
  entries: [],
1073
1086
  candidateRegistry: this.#registry,
1074
1087
  context: buildCommitPolicyContext(this, {
@@ -1485,12 +1498,13 @@ function ledgerLogEntry(entryID, token, verified) {
1485
1498
  }
1486
1499
  const tokens = await this.#resolveLedgerEntries(missing);
1487
1500
  for (const token of tokens){
1488
- await maybeYield();
1501
+ if (opts?.yield !== false) await maybeYield();
1489
1502
  const id = ledgerEntryDigest(token);
1490
1503
  // Content-addressing binds the untrusted body to the requested id.
1491
1504
  if (resolved.has(id) || !missing.includes(id)) continue;
1492
1505
  const verified = await verifyCachedLedgerEntry(token, {
1493
- crypto: this.#crypto
1506
+ crypto: this.#crypto,
1507
+ yield: opts?.yield
1494
1508
  });
1495
1509
  if (verified == null) continue;
1496
1510
  resolved.set(id, ledgerLogEntry(id, token, verified));
@@ -1509,6 +1523,7 @@ function ledgerLogEntry(entryID, token, verified) {
1509
1523
  });
1510
1524
  const foldResult = await foldEnvelope({
1511
1525
  crypto: this.#crypto,
1526
+ yield: opts?.yield,
1512
1527
  baseRoster: this.#roster,
1513
1528
  baseRegistry: this.#registry,
1514
1529
  entries: ordered,
@@ -1539,7 +1554,8 @@ function ledgerLogEntry(entryID, token, verified) {
1539
1554
  continue;
1540
1555
  }
1541
1556
  const ok = await verifyDeviceEntry(verified, proofCtx, {
1542
- crypto: this.#crypto
1557
+ crypto: this.#crypto,
1558
+ yield: opts?.yield
1543
1559
  });
1544
1560
  if (!ok) {
1545
1561
  precomputedReject = true;
@@ -1569,6 +1585,7 @@ function ledgerLogEntry(entryID, token, verified) {
1569
1585
  const externalLeaf = frame.wireformat === wireformats.mls_public_message && frame.publicMessage.content.contentType === contentTypes.commit && frame.publicMessage.senderType === senderTypes.new_member_commit ? frame.publicMessage.content.commit.path?.leafNode : undefined;
1570
1586
  gate = await prepareLifecycleGate({
1571
1587
  group: this,
1588
+ yield: opts?.yield,
1572
1589
  entries: acceptedEntries.map(({ verified })=>verified),
1573
1590
  candidateRegistry,
1574
1591
  context,
@@ -1633,16 +1650,19 @@ function ledgerLogEntry(entryID, token, verified) {
1633
1650
  });
1634
1651
  }
1635
1652
  const folded = await foldLedgerControl(ledger, this.#anchor, this.groupID, {
1636
- crypto: this.#crypto
1653
+ crypto: this.#crypto,
1654
+ yield: opts?.yield
1637
1655
  });
1638
1656
  const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
1639
- crypto: this.#crypto
1657
+ crypto: this.#crypto,
1658
+ yield: opts?.yield
1640
1659
  });
1641
1660
  const admission = await computeAdmission({
1642
1661
  state: this.#state,
1643
1662
  anchor: this.#anchor,
1644
1663
  registry,
1645
- crypto: this.#crypto
1664
+ crypto: this.#crypto,
1665
+ yield: opts?.yield
1646
1666
  });
1647
1667
  // Published together: readers between the folds still see the previous epoch's control state.
1648
1668
  this.#ledger = ledger;
@@ -1893,6 +1913,7 @@ function ledgerLogEntry(entryID, token, verified) {
1893
1913
  const index = await readSenderLeafIndex(this.#context, historical?.senderDataSecret ?? this.#state.keySchedule.senderDataSecret, application);
1894
1914
  await assertSenderNotLapsed({
1895
1915
  group: this,
1916
+ yield: opts.yield,
1896
1917
  tree: historical?.ratchetTree ?? this.#state.ratchetTree,
1897
1918
  leafIndex: index,
1898
1919
  extensions: (historical?.groupContext ?? this.#state.groupContext).extensions
@@ -1921,6 +1942,7 @@ function ledgerLogEntry(entryID, token, verified) {
1921
1942
  });
1922
1943
  await verifyLeafCredential(credential, key, {
1923
1944
  crypto: this.#crypto,
1945
+ yield: opts?.yield,
1924
1946
  deviceDenySet: ()=>denySetOf(candidateRegistry),
1925
1947
  judging: ()=>({
1926
1948
  registry: this.#anchor.controller == null ? undefined : candidateRegistry,
@@ -2064,7 +2086,7 @@ function ledgerLogEntry(entryID, token, verified) {
2064
2086
  }
2065
2087
  };
2066
2088
  }
2067
- /** Build the handle a commit hands back: the post-commit state, everything else inherited. */ export async function deriveGroup(group, state) {
2089
+ /** Build the handle a commit hands back: the post-commit state, everything else inherited. */ export async function deriveGroup(group, state, options) {
2068
2090
  return await GroupHandle.create({
2069
2091
  state,
2070
2092
  credential: group.credential,
@@ -2073,6 +2095,7 @@ function ledgerLogEntry(entryID, token, verified) {
2073
2095
  crypto: group.crypto
2074
2096
  }),
2075
2097
  crypto: group.crypto,
2098
+ yield: options?.yield,
2076
2099
  ledger: group.ledger,
2077
2100
  commitPolicy: group.commitPolicy,
2078
2101
  resolveLedgerEntries: group.resolveLedgerEntries,