@kumiai/mls 0.13.1 → 0.13.2
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.
- package/README.md +19 -0
- package/lib/authentication.d.ts +4 -3
- package/lib/authentication.js +10 -0
- package/lib/controller-ingest.d.ts +2 -1
- package/lib/controller-log.d.ts +7 -6
- package/lib/device-proof.d.ts +2 -1
- package/lib/embedded-resolver.d.ts +2 -1
- package/lib/envelope-fold.d.ts +2 -1
- package/lib/envelope-fold.js +2 -1
- package/lib/group-commit.d.ts +7 -7
- package/lib/group-commit.js +31 -15
- package/lib/group-context.d.ts +2 -2
- package/lib/group-context.js +4 -0
- package/lib/group-create.d.ts +3 -3
- package/lib/group-create.js +12 -5
- package/lib/group-device.d.ts +2 -1
- package/lib/group-device.js +20 -10
- package/lib/group-handle.d.ts +9 -8
- package/lib/group-handle.js +48 -25
- package/lib/group-lifecycle.d.ts +16 -15
- package/lib/group-lifecycle.js +55 -29
- package/lib/group-membership.d.ts +3 -2
- package/lib/group-membership.js +4 -3
- package/lib/group-welcome.d.ts +3 -3
- package/lib/group-welcome.js +25 -6
- package/lib/history.d.ts +3 -2
- package/lib/index.d.ts +1 -1
- package/lib/ledger.d.ts +4 -3
- package/lib/ledger.js +3 -2
- package/lib/lifecycle-proof.d.ts +6 -5
- package/lib/lifecycle-proof.js +8 -6
- package/lib/lifecycle.d.ts +8 -7
- package/lib/lifecycle.js +46 -29
- package/lib/member-root.d.ts +8 -7
- package/lib/registry.d.ts +6 -5
- package/lib/types.d.ts +1 -0
- package/package.json +6 -6
package/lib/group-lifecycle.js
CHANGED
|
@@ -15,11 +15,12 @@ import { attestedTreeTime, isLapsed, leafAt, treeTime, validateEntry } from './l
|
|
|
15
15
|
import { authenticateLifecycleProof, lifecycleProofEffects, lifecycleProofLog, mergeLifecycleProofLogs, verifyLifecycleProof } from './lifecycle-proof.js';
|
|
16
16
|
import { claimsFor, effectiveAttestingMembers, effectiveAuthorityOf } from './member-root.js';
|
|
17
17
|
import { DEVICE_ENTRY_TYPE, isResetOnly, recordedLogOf } from './registry.js';
|
|
18
|
-
export async function controllerLogDelta({ group, log }) {
|
|
18
|
+
export async function controllerLogDelta({ group, log, ...policy }) {
|
|
19
19
|
const controller = group.anchor.controller;
|
|
20
20
|
if (controller == null) throw new RevokeProofError('wrong-controller');
|
|
21
21
|
const options = {
|
|
22
|
-
crypto: group.crypto
|
|
22
|
+
crypto: group.crypto,
|
|
23
|
+
yield: policy.yield
|
|
23
24
|
};
|
|
24
25
|
const recorded = recordedLogOf({
|
|
25
26
|
registry: group.registry,
|
|
@@ -70,9 +71,10 @@ export async function controllerLogDelta({ group, log }) {
|
|
|
70
71
|
});
|
|
71
72
|
return delta;
|
|
72
73
|
}
|
|
73
|
-
export async function publishControllerLog({ group, log }) {
|
|
74
|
+
export async function publishControllerLog({ group, log, ...options }) {
|
|
74
75
|
return mutexFor(group).run(async ()=>{
|
|
75
76
|
const delta = await controllerLogDelta({
|
|
77
|
+
yield: options.yield,
|
|
76
78
|
group,
|
|
77
79
|
log
|
|
78
80
|
});
|
|
@@ -87,7 +89,8 @@ export async function publishControllerLog({ group, log }) {
|
|
|
87
89
|
}),
|
|
88
90
|
proof: delta,
|
|
89
91
|
previous: group.registry.controllers.get(normalizeDID(controller)),
|
|
90
|
-
crypto: group.crypto
|
|
92
|
+
crypto: group.crypto,
|
|
93
|
+
yield: options.yield
|
|
91
94
|
});
|
|
92
95
|
const effects = effectDelta({
|
|
93
96
|
before: ingested.before?.head,
|
|
@@ -95,6 +98,7 @@ export async function publishControllerLog({ group, log }) {
|
|
|
95
98
|
});
|
|
96
99
|
if (effects.generation || effects.denied.length > 0 || effects.removed.length > 0) throw new RevokeProofError('effects-mismatch');
|
|
97
100
|
const token = await signLedgerEntry({
|
|
101
|
+
yield: options.yield,
|
|
98
102
|
identity: ownIdentity(group),
|
|
99
103
|
entry: {
|
|
100
104
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -111,7 +115,8 @@ export async function publishControllerLog({ group, log }) {
|
|
|
111
115
|
proposals: [],
|
|
112
116
|
tokens: [
|
|
113
117
|
token
|
|
114
|
-
]
|
|
118
|
+
],
|
|
119
|
+
...options
|
|
115
120
|
});
|
|
116
121
|
});
|
|
117
122
|
}
|
|
@@ -119,28 +124,29 @@ export async function publishControllerLog({ group, log }) {
|
|
|
119
124
|
* Author a by-reference Remove for this handle's own leaf at its current epoch.
|
|
120
125
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
121
126
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
122
|
-
*/ export async function proposeSelfRemoval(group) {
|
|
123
|
-
return group.proposeSelfRemoval();
|
|
127
|
+
*/ export async function proposeSelfRemoval(group, options) {
|
|
128
|
+
return group.proposeSelfRemoval(options);
|
|
124
129
|
}
|
|
125
130
|
/**
|
|
126
131
|
* Commit other members' pending self-removals without absorbing other pending proposals.
|
|
127
132
|
* Returns null when only the committer's own self-removal (or none) is pending.
|
|
128
133
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
129
134
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
130
|
-
*/ export async function commitSelfRemovals(group) {
|
|
135
|
+
*/ export async function commitSelfRemovals(group, options) {
|
|
131
136
|
return mutexFor(group).run(async ()=>{
|
|
132
137
|
const pendingProposals = Object.fromEntries(Object.entries(group.state.unappliedProposals).filter(([, { proposal, senderLeafIndex }])=>isDefaultProposal(proposal) && proposal.proposalType === defaultProposalTypes.remove && proposal.remove.removed === senderLeafIndex && senderLeafIndex !== group.state.privatePath.leafIndex));
|
|
133
138
|
if (Object.keys(pendingProposals).length === 0) return null;
|
|
134
139
|
const tokens = [];
|
|
135
140
|
const result = await commitWithEntries({
|
|
141
|
+
yield: options?.yield,
|
|
136
142
|
group,
|
|
137
143
|
extraProposals: [],
|
|
138
144
|
pendingProposals,
|
|
139
145
|
enacted: tokens,
|
|
140
146
|
requireAdmin: false
|
|
141
147
|
});
|
|
142
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
143
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
148
|
+
const newGroup = await deriveGroup(group, result.newState, options);
|
|
149
|
+
await newGroup.applyLedgerEntries(result.enacted, options);
|
|
144
150
|
return {
|
|
145
151
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
146
152
|
newGroup,
|
|
@@ -158,18 +164,22 @@ function ownIdentity(group) {
|
|
|
158
164
|
crypto: group.crypto
|
|
159
165
|
});
|
|
160
166
|
}
|
|
161
|
-
export async function preservationClock({ group, candidateTree, candidateRegistry }) {
|
|
167
|
+
export async function preservationClock({ group, candidateTree, candidateRegistry, ...options }) {
|
|
162
168
|
const controller = group.anchor.controller;
|
|
163
169
|
if (controller == null) return [];
|
|
164
|
-
const before = await treeTime(group, controller
|
|
170
|
+
const before = await treeTime(group, controller, group.registry, {
|
|
171
|
+
yield: options.yield
|
|
172
|
+
});
|
|
165
173
|
if (await attestedTreeTime({
|
|
166
174
|
tree: candidateTree,
|
|
167
175
|
registry: candidateRegistry,
|
|
168
176
|
controllerID: controller,
|
|
169
|
-
crypto: group.crypto
|
|
177
|
+
crypto: group.crypto,
|
|
178
|
+
yield: options.yield
|
|
170
179
|
}) >= before) return [];
|
|
171
180
|
return [
|
|
172
181
|
await signLedgerEntry({
|
|
182
|
+
yield: options.yield,
|
|
173
183
|
identity: ownIdentity(group),
|
|
174
184
|
entry: {
|
|
175
185
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -183,20 +193,22 @@ export async function preservationClock({ group, candidateTree, candidateRegistr
|
|
|
183
193
|
})
|
|
184
194
|
];
|
|
185
195
|
}
|
|
186
|
-
export async function attestTreeTime({ group, time = Date.now() / 1000 }) {
|
|
196
|
+
export async function attestTreeTime({ group, time = Date.now() / 1000, ...options }) {
|
|
187
197
|
return mutexFor(group).run(async ()=>{
|
|
188
198
|
const controller = group.anchor.controller;
|
|
189
199
|
if (controller == null) return null;
|
|
190
200
|
const projection = group.registry.controllers.get(normalizeDID(controller));
|
|
191
201
|
if (projection?.recordedLog == null) return null;
|
|
192
202
|
const folded = await foldControllerLog(controller, projection.recordedLog, {
|
|
193
|
-
crypto: group.crypto
|
|
203
|
+
crypto: group.crypto,
|
|
204
|
+
yield: options.yield
|
|
194
205
|
});
|
|
195
206
|
if (!folded.ok || folded.head.saturated) return null;
|
|
196
207
|
const members = effectiveAttestingMembers(folded.head, projection, time).filter(([, member])=>normalizeDID(member.did) === normalizeDID(group.credential.id));
|
|
197
208
|
if (members.length === 0) return null;
|
|
198
209
|
if (members.every(([, member])=>time <= (projection.attestations.get(member.key) ?? 0))) return null;
|
|
199
210
|
const token = await signLedgerEntry({
|
|
211
|
+
yield: options.yield,
|
|
200
212
|
identity: ownIdentity(group),
|
|
201
213
|
entry: {
|
|
202
214
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -214,13 +226,15 @@ export async function attestTreeTime({ group, time = Date.now() / 1000 }) {
|
|
|
214
226
|
proposals: [],
|
|
215
227
|
tokens: [
|
|
216
228
|
token
|
|
217
|
-
]
|
|
229
|
+
],
|
|
230
|
+
...options
|
|
218
231
|
});
|
|
219
232
|
});
|
|
220
233
|
}
|
|
221
234
|
async function buildResult(params) {
|
|
222
235
|
const { group, proposals, tokens, commitState } = params;
|
|
223
236
|
const result = await commitWithEntries({
|
|
237
|
+
yield: params.yield,
|
|
224
238
|
group,
|
|
225
239
|
extraProposals: proposals,
|
|
226
240
|
enacted: tokens,
|
|
@@ -230,8 +244,8 @@ async function buildResult(params) {
|
|
|
230
244
|
// MLS captured the replacement tree as historical data when building a renewal.
|
|
231
245
|
const historical = result.newState.historicalReceiverData.get(group.epoch);
|
|
232
246
|
if (historical != null && commitState != null) historical.ratchetTree = group.state.ratchetTree;
|
|
233
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
234
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
247
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
248
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
235
249
|
return {
|
|
236
250
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
237
251
|
newGroup,
|
|
@@ -258,11 +272,13 @@ export async function renewLeaf({ group, binding, ...options }) {
|
|
|
258
272
|
let candidate = group.registry;
|
|
259
273
|
if (options?.controllerLog != null) {
|
|
260
274
|
const delta = await controllerLogDelta({
|
|
275
|
+
yield: options.yield,
|
|
261
276
|
group,
|
|
262
277
|
log: options.controllerLog
|
|
263
278
|
});
|
|
264
279
|
if (delta != null) {
|
|
265
280
|
const token = await signLedgerEntry({
|
|
281
|
+
yield: options.yield,
|
|
266
282
|
identity: ownIdentity(group),
|
|
267
283
|
entry: {
|
|
268
284
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -276,11 +292,13 @@ export async function renewLeaf({ group, binding, ...options }) {
|
|
|
276
292
|
});
|
|
277
293
|
const verified = await verifyLedgerEntry({
|
|
278
294
|
token,
|
|
279
|
-
crypto: group.crypto
|
|
295
|
+
crypto: group.crypto,
|
|
296
|
+
yield: options.yield
|
|
280
297
|
});
|
|
281
298
|
if (verified == null) throw new Error('Invalid authored log entry');
|
|
282
299
|
const folded = await foldEnvelope({
|
|
283
300
|
crypto: group.crypto,
|
|
301
|
+
yield: options.yield,
|
|
284
302
|
baseRoster: group.roster,
|
|
285
303
|
baseRegistry: group.registry,
|
|
286
304
|
entries: [
|
|
@@ -301,6 +319,7 @@ export async function renewLeaf({ group, binding, ...options }) {
|
|
|
301
319
|
}
|
|
302
320
|
}
|
|
303
321
|
await validateEntry(group, own.leaf, original.leaf, {
|
|
322
|
+
yield: options.yield,
|
|
304
323
|
registry: candidate,
|
|
305
324
|
stage: 'full',
|
|
306
325
|
mode: 'admit'
|
|
@@ -324,17 +343,18 @@ export async function renewLeaf({ group, binding, ...options }) {
|
|
|
324
343
|
commitState: {
|
|
325
344
|
...group.state,
|
|
326
345
|
ratchetTree: tree
|
|
327
|
-
}
|
|
346
|
+
},
|
|
347
|
+
yield: options.yield
|
|
328
348
|
});
|
|
329
349
|
});
|
|
330
350
|
}
|
|
331
|
-
export async function removeLapsedLeaves(group) {
|
|
351
|
+
export async function removeLapsedLeaves(group, options) {
|
|
332
352
|
return mutexFor(group).run(async ()=>{
|
|
333
353
|
const removed = [];
|
|
334
354
|
const proposals = [];
|
|
335
355
|
for (const member of group.listMembers()){
|
|
336
356
|
const leaf = leafAt(group.state.ratchetTree, member.leafIndex);
|
|
337
|
-
if (leaf == null || !await isLapsed(group, leaf)) continue;
|
|
357
|
+
if (leaf == null || !await isLapsed(group, leaf, group.registry, options)) continue;
|
|
338
358
|
removed.push(member.id);
|
|
339
359
|
proposals.push({
|
|
340
360
|
proposalType: defaultProposalTypes.remove,
|
|
@@ -352,7 +372,8 @@ export async function removeLapsedLeaves(group) {
|
|
|
352
372
|
result: await buildResult({
|
|
353
373
|
group,
|
|
354
374
|
proposals,
|
|
355
|
-
tokens
|
|
375
|
+
tokens,
|
|
376
|
+
...options
|
|
356
377
|
})
|
|
357
378
|
};
|
|
358
379
|
});
|
|
@@ -378,7 +399,7 @@ export async function removalEvidence({ controller, log, rmv, ...options }) {
|
|
|
378
399
|
closure
|
|
379
400
|
};
|
|
380
401
|
}
|
|
381
|
-
export async function survivorTargets({ group, add }) {
|
|
402
|
+
export async function survivorTargets({ group, add, ...options }) {
|
|
382
403
|
const controller = group.anchor.controller;
|
|
383
404
|
if (controller == null) return [];
|
|
384
405
|
const descendants = [];
|
|
@@ -397,7 +418,8 @@ export async function survivorTargets({ group, add }) {
|
|
|
397
418
|
},
|
|
398
419
|
registry: group.registry,
|
|
399
420
|
controller,
|
|
400
|
-
crypto: group.crypto
|
|
421
|
+
crypto: group.crypto,
|
|
422
|
+
yield: options.yield
|
|
401
423
|
});
|
|
402
424
|
if ('root' in authority && authority.root.kind === 'member' && authority.root.add === add) descendants.push({
|
|
403
425
|
did: id,
|
|
@@ -412,7 +434,8 @@ export async function revokeWithProof({ group, ...params }) {
|
|
|
412
434
|
const controller = group.anchor.controller;
|
|
413
435
|
if (controller == null) throw new RevokeProofError('wrong-controller');
|
|
414
436
|
const options = {
|
|
415
|
-
crypto: group.crypto
|
|
437
|
+
crypto: group.crypto,
|
|
438
|
+
yield: params.yield
|
|
416
439
|
};
|
|
417
440
|
const reset = 'reset' in params;
|
|
418
441
|
const requested = reset ? [] : (params.deny ?? []).map(normalizeDID);
|
|
@@ -425,6 +448,7 @@ export async function revokeWithProof({ group, ...params }) {
|
|
|
425
448
|
const projection = group.registry.controllers.get(normalizeDID(controller));
|
|
426
449
|
if (params.log.chain.every(({ event })=>event.g < (projection?.genFloor ?? 0))) throw new RevokeProofError('generation-floor');
|
|
427
450
|
let proof = await controllerLogDelta({
|
|
451
|
+
yield: params.yield,
|
|
428
452
|
group,
|
|
429
453
|
log: params.log
|
|
430
454
|
});
|
|
@@ -505,14 +529,14 @@ export async function revokeWithProof({ group, ...params }) {
|
|
|
505
529
|
}
|
|
506
530
|
};
|
|
507
531
|
await authenticateLifecycleProof(controller, verified, group.registry, options);
|
|
508
|
-
const derived = await lifecycleProofEffects(group, verified);
|
|
532
|
+
const derived = await lifecycleProofEffects(group, verified, group.registry, params);
|
|
509
533
|
value.revoked = derived.revoked;
|
|
510
534
|
value.removed = derived.removed;
|
|
511
535
|
if (derived.removeLeafIndices.includes(group.state.privatePath.leafIndex)) return {
|
|
512
536
|
status: 'self-affected',
|
|
513
537
|
subject: group.credential.id
|
|
514
538
|
};
|
|
515
|
-
await verifyLifecycleProof(group, verified);
|
|
539
|
+
await verifyLifecycleProof(group, verified, group.registry, params);
|
|
516
540
|
const proposals = derived.removeLeafIndices.map((removed)=>({
|
|
517
541
|
proposalType: defaultProposalTypes.remove,
|
|
518
542
|
remove: {
|
|
@@ -521,6 +545,7 @@ export async function revokeWithProof({ group, ...params }) {
|
|
|
521
545
|
}));
|
|
522
546
|
const tokens = [
|
|
523
547
|
await signLedgerEntry({
|
|
548
|
+
yield: params.yield,
|
|
524
549
|
identity: ownIdentity(group),
|
|
525
550
|
entry: verified.entry
|
|
526
551
|
})
|
|
@@ -531,7 +556,8 @@ export async function revokeWithProof({ group, ...params }) {
|
|
|
531
556
|
result: await buildResult({
|
|
532
557
|
group,
|
|
533
558
|
proposals,
|
|
534
|
-
tokens
|
|
559
|
+
tokens,
|
|
560
|
+
yield: params.yield
|
|
535
561
|
})
|
|
536
562
|
};
|
|
537
563
|
} catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type GroupHandle } from './group-handle.js';
|
|
2
|
+
import type { YieldOptions } from './types.js';
|
|
2
3
|
export type RemoveMemberResult = {
|
|
3
4
|
/** Framed MLSMessage bytes. Broadcast to existing members via the DS. */
|
|
4
5
|
commitMessage: Uint8Array;
|
|
@@ -9,7 +10,7 @@ export type RemoveMemberResult = {
|
|
|
9
10
|
* readMessageEpoch). */
|
|
10
11
|
epoch: bigint;
|
|
11
12
|
};
|
|
12
|
-
export type RemoveMemberParams = {
|
|
13
|
+
export type RemoveMemberParams = YieldOptions & {
|
|
13
14
|
group: GroupHandle;
|
|
14
15
|
leafIndex: number;
|
|
15
16
|
ledgerEntries?: Array<string>;
|
|
@@ -27,4 +28,4 @@ export type RemoveMemberParams = {
|
|
|
27
28
|
* The mutex only serializes concurrent calls against one handle; it does not make a
|
|
28
29
|
* second commit from a superseded handle safe.
|
|
29
30
|
*/
|
|
30
|
-
export declare function removeMember({ group, leafIndex, ledgerEntries, }: RemoveMemberParams): Promise<RemoveMemberResult>;
|
|
31
|
+
export declare function removeMember({ group, leafIndex, ledgerEntries, ...options }: RemoveMemberParams): Promise<RemoveMemberResult>;
|
package/lib/group-membership.js
CHANGED
|
@@ -13,7 +13,7 @@ import { deriveGroup, mutexFor } from './group-handle.js';
|
|
|
13
13
|
* commit: two commits from the same source handle both frame at its epoch and diverge.
|
|
14
14
|
* The mutex only serializes concurrent calls against one handle; it does not make a
|
|
15
15
|
* second commit from a superseded handle safe.
|
|
16
|
-
*/ export async function removeMember({ group, leafIndex, ledgerEntries }) {
|
|
16
|
+
*/ export async function removeMember({ group, leafIndex, ledgerEntries, ...options }) {
|
|
17
17
|
return mutexFor(group).run(async ()=>{
|
|
18
18
|
const removeProposal = {
|
|
19
19
|
proposalType: defaultProposalTypes.remove,
|
|
@@ -23,14 +23,15 @@ import { deriveGroup, mutexFor } from './group-handle.js';
|
|
|
23
23
|
};
|
|
24
24
|
const enacted = ledgerEntries ?? [];
|
|
25
25
|
const result = await commitWithEntries({
|
|
26
|
+
yield: options.yield,
|
|
26
27
|
group,
|
|
27
28
|
extraProposals: [
|
|
28
29
|
removeProposal
|
|
29
30
|
],
|
|
30
31
|
enacted
|
|
31
32
|
});
|
|
32
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
33
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
33
|
+
const newGroup = await deriveGroup(group, result.newState, options);
|
|
34
|
+
await newGroup.applyLedgerEntries(result.enacted, options);
|
|
34
35
|
return {
|
|
35
36
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
36
37
|
newGroup,
|
package/lib/group-welcome.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { type ClientState, type Welcome } from 'ts-mls';
|
|
|
3
3
|
import { type ControllerBinding, type MemberCredential } from './credential.js';
|
|
4
4
|
import { GroupHandle } from './group-handle.js';
|
|
5
5
|
import type { DeviceRegistry } from './registry.js';
|
|
6
|
-
import type { GroupOptions, Invite, KeyPackageBundle } from './types.js';
|
|
6
|
+
import type { GroupOptions, Invite, KeyPackageBundle, YieldOptions } from './types.js';
|
|
7
7
|
export type ProcessWelcomeResult = {
|
|
8
8
|
group: GroupHandle;
|
|
9
9
|
credential: MemberCredential;
|
|
10
10
|
};
|
|
11
|
-
export type ProcessWelcomeParams = {
|
|
11
|
+
export type ProcessWelcomeParams = YieldOptions & {
|
|
12
12
|
identity: OwnIdentity;
|
|
13
13
|
invite: Invite;
|
|
14
14
|
/** Wire-form framed MLSMessage(Welcome) bytes (preferred), or a pre-decoded
|
|
@@ -48,7 +48,7 @@ export type JoinGroupExternalParamsBeforeBindingParams = {
|
|
|
48
48
|
pending: GroupHandle;
|
|
49
49
|
source: GroupHandle;
|
|
50
50
|
};
|
|
51
|
-
export type JoinGroupExternalParams = {
|
|
51
|
+
export type JoinGroupExternalParams = YieldOptions & {
|
|
52
52
|
identity: OwnIdentity;
|
|
53
53
|
/** Framed MLSMessage(GroupInfo) bytes from exportGroupInfo. */
|
|
54
54
|
groupInfo: Uint8Array;
|
package/lib/group-welcome.js
CHANGED
|
@@ -34,6 +34,7 @@ export async function processWelcome(params) {
|
|
|
34
34
|
async validateCredential (credential, signaturePublicKey) {
|
|
35
35
|
await verifyLeafCredential(credential, signaturePublicKey, {
|
|
36
36
|
crypto: options?.crypto,
|
|
37
|
+
yield: params.yield,
|
|
37
38
|
judging: ()=>({
|
|
38
39
|
stage: 'structural',
|
|
39
40
|
mode: 'rejudge'
|
|
@@ -60,6 +61,7 @@ export async function processWelcome(params) {
|
|
|
60
61
|
};
|
|
61
62
|
const group = await GroupHandle.create({
|
|
62
63
|
crypto: options?.crypto,
|
|
64
|
+
yield: params.yield,
|
|
63
65
|
state,
|
|
64
66
|
credential,
|
|
65
67
|
context,
|
|
@@ -90,14 +92,20 @@ export async function processWelcome(params) {
|
|
|
90
92
|
for (const token of invite.ledgerEntries){
|
|
91
93
|
const verified = await verifyLedgerEntry({
|
|
92
94
|
token,
|
|
93
|
-
crypto: options?.crypto
|
|
95
|
+
crypto: options?.crypto,
|
|
96
|
+
yield: params.yield
|
|
94
97
|
});
|
|
95
98
|
if (verified?.entry.type === ROLE_ENTRY_TYPE && verified.entry.groupID === invite.groupID && normalizeDID(verified.entry.subject) === normalizeDID(identity.id)) namesSelf = true;
|
|
96
99
|
}
|
|
97
100
|
if (!namesSelf) throw new Error('processWelcome: the invite carries no role entry naming this identity');
|
|
98
101
|
}
|
|
99
|
-
await group.applyLedgerEntries(invite.ledgerEntries);
|
|
100
|
-
await validateWelcomeTree(group
|
|
102
|
+
await group.applyLedgerEntries(invite.ledgerEntries, params);
|
|
103
|
+
await validateWelcomeTree(group, {
|
|
104
|
+
registry: group.registry,
|
|
105
|
+
stage: 'full',
|
|
106
|
+
mode: 'rejudge',
|
|
107
|
+
yield: params.yield
|
|
108
|
+
});
|
|
101
109
|
return {
|
|
102
110
|
group,
|
|
103
111
|
credential
|
|
@@ -175,6 +183,7 @@ export async function processWelcome(params) {
|
|
|
175
183
|
if (anchor.controller != null && parsed.controller != null && normalizeDID(parsed.controller.id) !== normalizeDID(anchor.controller)) throw new LeafBindingError('controller-mismatch');
|
|
176
184
|
await verifyLeafCredential(leafCredential, signaturePublicKey, {
|
|
177
185
|
crypto: options?.crypto,
|
|
186
|
+
yield: params.yield,
|
|
178
187
|
judging: ()=>({
|
|
179
188
|
stage: 'structural',
|
|
180
189
|
mode: 'rejudge'
|
|
@@ -223,6 +232,7 @@ export async function processWelcome(params) {
|
|
|
223
232
|
const commitMessage = encode(mlsMessageEncoder, framedCommit);
|
|
224
233
|
const group = await GroupHandle.create({
|
|
225
234
|
crypto: options?.crypto,
|
|
235
|
+
yield: params.yield,
|
|
226
236
|
state: newState,
|
|
227
237
|
credential,
|
|
228
238
|
context,
|
|
@@ -256,6 +266,7 @@ export async function processWelcome(params) {
|
|
|
256
266
|
};
|
|
257
267
|
const before = await GroupHandle.create({
|
|
258
268
|
crypto: options?.crypto,
|
|
269
|
+
yield: params.yield,
|
|
259
270
|
state: {
|
|
260
271
|
...newState,
|
|
261
272
|
ratchetTree: beforeTree,
|
|
@@ -266,10 +277,12 @@ export async function processWelcome(params) {
|
|
|
266
277
|
});
|
|
267
278
|
if (ledgerEntries != null) {
|
|
268
279
|
await before.bootstrapLedger({
|
|
269
|
-
tokens: ledgerEntries
|
|
280
|
+
tokens: ledgerEntries,
|
|
281
|
+
yield: params.yield
|
|
270
282
|
});
|
|
271
283
|
await group.bootstrapLedger({
|
|
272
|
-
tokens: ledgerEntries
|
|
284
|
+
tokens: ledgerEntries,
|
|
285
|
+
yield: params.yield
|
|
273
286
|
});
|
|
274
287
|
}
|
|
275
288
|
await params.beforeBinding?.({
|
|
@@ -279,6 +292,7 @@ export async function processWelcome(params) {
|
|
|
279
292
|
if (anchor.controller != null && controller == null) throw new LeafBindingError('floating-refused');
|
|
280
293
|
assertBindingAuthorTime(controller);
|
|
281
294
|
const gate = await prepareLifecycleGate({
|
|
295
|
+
yield: params.yield,
|
|
282
296
|
group: before,
|
|
283
297
|
entries: [],
|
|
284
298
|
candidateRegistry: before.registry,
|
|
@@ -296,7 +310,12 @@ export async function processWelcome(params) {
|
|
|
296
310
|
proposals
|
|
297
311
|
});
|
|
298
312
|
await gate.postApply(newState);
|
|
299
|
-
await validateWelcomeTree(group
|
|
313
|
+
await validateWelcomeTree(group, {
|
|
314
|
+
registry: group.registry,
|
|
315
|
+
stage: 'full',
|
|
316
|
+
mode: 'rejudge',
|
|
317
|
+
yield: params.yield
|
|
318
|
+
});
|
|
300
319
|
return {
|
|
301
320
|
commitMessage,
|
|
302
321
|
group,
|
package/lib/history.d.ts
CHANGED
|
@@ -2,16 +2,17 @@ import { type ControllerLog } from '@kokuin/controller';
|
|
|
2
2
|
import type { CryptoOptions } from '@kokuin/token';
|
|
3
3
|
import { type ClientState } from 'ts-mls';
|
|
4
4
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
5
|
+
import type { YieldOptions } from './types.js';
|
|
5
6
|
export declare const HISTORY_HORIZON = 393216;
|
|
6
7
|
export declare const MAX_EPOCH_EVENTS_FOR_LEAVES = 32;
|
|
7
8
|
export declare const SETTLE_PROMPT_EPOCH_EVENTS = 24;
|
|
8
9
|
export type EpochEventCountParams = {
|
|
9
10
|
log: ControllerLog;
|
|
10
|
-
} & CryptoOptions;
|
|
11
|
+
} & CryptoOptions & YieldOptions;
|
|
11
12
|
export declare function epochEventCount({ log, ...options }: EpochEventCountParams): Promise<number>;
|
|
12
13
|
export type SettleAdvisoryParams = {
|
|
13
14
|
log: ControllerLog;
|
|
14
|
-
} & CryptoOptions;
|
|
15
|
+
} & CryptoOptions & YieldOptions;
|
|
15
16
|
export declare function settleAdvisory({ log, ...options }: SettleAdvisoryParams): Promise<'ok' | 'prompt' | 'blocked'>;
|
|
16
17
|
export declare function controllerLogSize(events: ReadonlyArray<unknown>): number;
|
|
17
18
|
export declare function proofSize(value: unknown): number;
|
package/lib/index.d.ts
CHANGED
|
@@ -58,5 +58,5 @@ export { adminCount, foldRoster, type GroupPermission, ROLE_ENTRY_TYPE, type Rol
|
|
|
58
58
|
export type { MergeReceiveSecretTreeParams } from './secret-tree.js';
|
|
59
59
|
export { mergeReceiveSecretTree } from './secret-tree.js';
|
|
60
60
|
export { bindingIssuedAt, DuplicateMemberLeafError } from './stale-leaf.js';
|
|
61
|
-
export type { GroupOptions, Invite, KeyPackageBundle } from './types.js';
|
|
61
|
+
export type { GroupOptions, Invite, KeyPackageBundle, YieldOptions } from './types.js';
|
|
62
62
|
export { welcomeKeyPackageRefs } from './welcome-refs.js';
|
package/lib/ledger.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type CryptoOptions, type SigningIdentity } from '@kokuin/token';
|
|
2
|
+
import type { YieldOptions } from './types.js';
|
|
2
3
|
export declare const LEDGER_ENTRY_DIGEST_CACHE_SIZE = 4096;
|
|
3
4
|
/** @internal */
|
|
4
5
|
export declare function ledgerEntryDigestCacheSize(): number;
|
|
@@ -27,7 +28,7 @@ export type VerifiedLedgerEntry<TValue = unknown> = {
|
|
|
27
28
|
issuer: string;
|
|
28
29
|
entry: LedgerEntry<TValue>;
|
|
29
30
|
};
|
|
30
|
-
export type SignLedgerEntryParams = {
|
|
31
|
+
export type SignLedgerEntryParams = YieldOptions & {
|
|
31
32
|
identity: SigningIdentity;
|
|
32
33
|
entry: LedgerEntry;
|
|
33
34
|
};
|
|
@@ -37,10 +38,10 @@ export type SignLedgerEntryParams = {
|
|
|
37
38
|
* author. `ord` is signed only when present, so a claim without it never signs
|
|
38
39
|
* an `ord: undefined` key. Returns the stringified token.
|
|
39
40
|
*/
|
|
40
|
-
export declare function signLedgerEntry({ identity, entry }: SignLedgerEntryParams): Promise<string>;
|
|
41
|
+
export declare function signLedgerEntry({ identity, entry, ...options }: SignLedgerEntryParams): Promise<string>;
|
|
41
42
|
export type VerifyLedgerEntryParams = {
|
|
42
43
|
token: string;
|
|
43
|
-
} & CryptoOptions;
|
|
44
|
+
} & CryptoOptions & YieldOptions;
|
|
44
45
|
/**
|
|
45
46
|
* Verify a signed ledger token and extract its claim. Returns `null` when the
|
|
46
47
|
* token is unparseable, unsigned (`alg: 'none'` — `verifyToken`
|
package/lib/ledger.js
CHANGED
|
@@ -11,7 +11,7 @@ const LEDGER_ENTRY_DIGEST_CACHE = new Map();
|
|
|
11
11
|
* covers every claim field — including `groupID` and `ord` — and binds the
|
|
12
12
|
* author. `ord` is signed only when present, so a claim without it never signs
|
|
13
13
|
* an `ord: undefined` key. Returns the stringified token.
|
|
14
|
-
*/ export async function signLedgerEntry({ identity, entry }) {
|
|
14
|
+
*/ export async function signLedgerEntry({ identity, entry, ...options }) {
|
|
15
15
|
const signed = await identity.signToken({
|
|
16
16
|
payload: {
|
|
17
17
|
type: entry.type,
|
|
@@ -22,7 +22,8 @@ const LEDGER_ENTRY_DIGEST_CACHE = new Map();
|
|
|
22
22
|
ord: entry.ord
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
embedLongForm: true
|
|
25
|
+
embedLongForm: true,
|
|
26
|
+
yield: options.yield
|
|
26
27
|
});
|
|
27
28
|
return stringifyToken(signed);
|
|
28
29
|
}
|
package/lib/lifecycle-proof.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { GroupHandle } from './group-handle.js';
|
|
|
6
6
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
7
7
|
import { type RemovedEffect } from './member-root.js';
|
|
8
8
|
import { type DeviceRegistry, type DeviceValue, type RevokedEffect } from './registry.js';
|
|
9
|
+
import type { YieldOptions } from './types.js';
|
|
9
10
|
export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
10
11
|
/** Derived from a proof and the pre-commit tree; proposal comparison belongs to the commit gate. */
|
|
11
12
|
export type LifecycleProofEffects = {
|
|
@@ -25,11 +26,11 @@ type AuthenticatedProof = {
|
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
/** Keep controller merge limits inside the lifecycle proof error boundary. */
|
|
28
|
-
export declare function mergeLifecycleProofLogs(controller: string, first: ControllerLog, second: ControllerLog, options?: CryptoOptions): Promise<ControllerLog>;
|
|
29
|
+
export declare function mergeLifecycleProofLogs(controller: string, first: ControllerLog, second: ControllerLog, options?: CryptoOptions & YieldOptions): Promise<ControllerLog>;
|
|
29
30
|
/** Reattach historical closures without reviving unapplied current-epoch events. */
|
|
30
|
-
export declare function lifecycleProofLog(controller: string, ingested: IngestedControllerLog, proof: ControllerLog, options?: CryptoOptions): Promise<ControllerLog>;
|
|
31
|
+
export declare function lifecycleProofLog(controller: string, ingested: IngestedControllerLog, proof: ControllerLog, options?: CryptoOptions & YieldOptions): Promise<ControllerLog>;
|
|
31
32
|
/** Authenticate replayable log data without reading any membership state. */
|
|
32
|
-
export declare function authenticateLifecycleProof(controllerID: string, verified: VerifiedLedgerEntry<DeviceValue>, registry: DeviceRegistry, options?: CryptoOptions): Promise<AuthenticatedProof>;
|
|
33
|
+
export declare function authenticateLifecycleProof(controllerID: string, verified: VerifiedLedgerEntry<DeviceValue>, registry: DeviceRegistry, options?: CryptoOptions & YieldOptions): Promise<AuthenticatedProof>;
|
|
33
34
|
/**
|
|
34
35
|
* A leaf that stays when its issuer is denied: in a group whose anchor names a controller, a
|
|
35
36
|
* chained leaf of that controller carrying its holder's own valid grant from it, for a holder that
|
|
@@ -39,5 +40,5 @@ export declare function isEvidencedChild(group: GroupHandle, leaf: LeafNode, den
|
|
|
39
40
|
/** Whether the member at `leafIndex` is an evidenced child that a cascade leaves in place. */
|
|
40
41
|
export declare function isExemptMember(group: GroupHandle, leafIndex: number): boolean;
|
|
41
42
|
/** Verify live effects while all leaves still describe the epoch before the commit. */
|
|
42
|
-
export declare function lifecycleProofEffects(group: GroupHandle, verified: VerifiedLedgerEntry<DeviceValue>, registry?: DeviceRegistry): Promise<LifecycleProofEffects>;
|
|
43
|
-
export declare function verifyLifecycleProof(group: GroupHandle, verified: VerifiedLedgerEntry<DeviceValue>, registry?: DeviceRegistry): Promise<LifecycleProofEffects>;
|
|
43
|
+
export declare function lifecycleProofEffects(group: GroupHandle, verified: VerifiedLedgerEntry<DeviceValue>, registry?: DeviceRegistry, policy?: YieldOptions): Promise<LifecycleProofEffects>;
|
|
44
|
+
export declare function verifyLifecycleProof(group: GroupHandle, verified: VerifiedLedgerEntry<DeviceValue>, registry?: DeviceRegistry, policy?: YieldOptions): Promise<LifecycleProofEffects>;
|
package/lib/lifecycle-proof.js
CHANGED
|
@@ -139,12 +139,13 @@ export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
|
139
139
|
return cascadedFrom === effect.cascadedFrom;
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
/** Verify live effects while all leaves still describe the epoch before the commit. */ export async function lifecycleProofEffects(group, verified, registry = group.registry) {
|
|
142
|
+
/** Verify live effects while all leaves still describe the epoch before the commit. */ export async function lifecycleProofEffects(group, verified, registry = group.registry, policy) {
|
|
143
143
|
const controllerID = group.anchor.controller;
|
|
144
144
|
if (controllerID == null) throw new RevokeProofError('wrong-controller');
|
|
145
145
|
const controller = normalizeDID(controllerID);
|
|
146
146
|
const options = {
|
|
147
|
-
crypto: group.crypto
|
|
147
|
+
crypto: group.crypto,
|
|
148
|
+
yield: policy?.yield
|
|
148
149
|
};
|
|
149
150
|
const subject = normalizeDID(verified.entry.subject);
|
|
150
151
|
const value = verified.entry.value;
|
|
@@ -203,7 +204,7 @@ export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
|
203
204
|
const leaf = index == null ? undefined : leafAt(group.state.ratchetTree, index);
|
|
204
205
|
if (leaf == null) throw new RevokeProofError('wrong-controller');
|
|
205
206
|
if (denySetOf(registry).has(normalizeDID(verified.issuer))) throw new LeafBindingError('denied-id');
|
|
206
|
-
if (await isLapsed(group, leaf, registry)) throw new LeafLapsedError('lapsed');
|
|
207
|
+
if (await isLapsed(group, leaf, registry, options)) throw new LeafLapsedError('lapsed');
|
|
207
208
|
const before = historySize({
|
|
208
209
|
tree: group.state.ratchetTree,
|
|
209
210
|
entries: group.ledger.map(({ verified })=>verified)
|
|
@@ -253,7 +254,8 @@ export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
|
253
254
|
controllerID: controller,
|
|
254
255
|
prefix: candidate.controllers.get(controller)?.recordedLog?.chain ?? [],
|
|
255
256
|
registry: candidate,
|
|
256
|
-
crypto: group.crypto
|
|
257
|
+
crypto: group.crypto,
|
|
258
|
+
yield: options.yield
|
|
257
259
|
}).frozen();
|
|
258
260
|
const token = await verifyToken({
|
|
259
261
|
...options,
|
|
@@ -335,8 +337,8 @@ export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
|
335
337
|
...cascade
|
|
336
338
|
};
|
|
337
339
|
}
|
|
338
|
-
export async function verifyLifecycleProof(group, verified, registry = group.registry) {
|
|
339
|
-
const effects = await lifecycleProofEffects(group, verified, registry);
|
|
340
|
+
export async function verifyLifecycleProof(group, verified, registry = group.registry, policy) {
|
|
341
|
+
const effects = await lifecycleProofEffects(group, verified, registry, policy);
|
|
340
342
|
const value = verified.entry.value;
|
|
341
343
|
if ((value.op === 'revoke' || value.op === 'reset') && (!effectsMatch(value.revoked, effects.revoked) || !effectsMatch(value.removed, effects.removed))) throw new RevokeProofError('effects-mismatch');
|
|
342
344
|
return effects;
|