@kumiai/mls 0.12.3 → 0.13.0
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/lib/anchor.d.ts +6 -2
- package/lib/anchor.js +1 -1
- package/lib/authentication.d.ts +8 -3
- package/lib/authentication.js +139 -46
- package/lib/capability.js +16 -7
- package/lib/controller-ingest.d.ts +14 -2
- package/lib/controller-ingest.js +15 -8
- package/lib/controller-log.d.ts +12 -6
- package/lib/controller-log.js +29 -15
- package/lib/device-proof.d.ts +2 -1
- package/lib/device-proof.js +2 -1
- package/lib/embedded-resolver.d.ts +7 -2
- package/lib/embedded-resolver.js +16 -6
- package/lib/envelope-fold.d.ts +3 -2
- package/lib/envelope-fold.js +14 -6
- package/lib/fold.d.ts +17 -3
- package/lib/fold.js +9 -3
- package/lib/group-commit.d.ts +11 -2
- package/lib/group-commit.js +76 -32
- package/lib/group-context.d.ts +37 -3
- package/lib/group-context.js +65 -4
- package/lib/group-create.d.ts +5 -1
- package/lib/group-create.js +36 -14
- package/lib/group-credential.d.ts +13 -3
- package/lib/group-credential.js +17 -6
- package/lib/group-device.d.ts +32 -22
- package/lib/group-device.js +66 -51
- package/lib/group-handle.d.ts +87 -31
- package/lib/group-handle.js +377 -168
- package/lib/group-lifecycle.d.ts +44 -11
- package/lib/group-lifecycle.js +193 -85
- package/lib/group-membership.d.ts +6 -1
- package/lib/group-membership.js +2 -2
- package/lib/group-welcome.d.ts +5 -1
- package/lib/group-welcome.js +34 -10
- package/lib/head.d.ts +25 -5
- package/lib/head.js +17 -8
- package/lib/history.d.ts +14 -3
- package/lib/history.js +8 -5
- package/lib/index.d.ts +28 -1
- package/lib/index.js +1 -0
- package/lib/key-package-codec.d.ts +4 -1
- package/lib/key-package-codec.js +1 -1
- package/lib/ledger.d.ts +14 -6
- package/lib/ledger.js +56 -19
- package/lib/lifecycle-proof.d.ts +5 -4
- package/lib/lifecycle-proof.js +111 -51
- package/lib/lifecycle.d.ts +18 -9
- package/lib/lifecycle.js +184 -81
- package/lib/member-root.d.ts +54 -15
- package/lib/member-root.js +115 -53
- package/lib/policy.d.ts +5 -1
- package/lib/policy.js +1 -1
- package/lib/recovery-verdict.d.ts +12 -3
- package/lib/recovery-verdict.js +56 -22
- package/lib/recovery.d.ts +20 -5
- package/lib/recovery.js +117 -46
- package/lib/registry.d.ts +46 -10
- package/lib/registry.js +64 -38
- package/lib/roster.d.ts +7 -1
- package/lib/roster.js +18 -7
- package/lib/secret-tree.d.ts +5 -1
- package/lib/secret-tree.js +1 -1
- package/lib/types.d.ts +3 -0
- package/package.json +9 -5
package/lib/member-root.js
CHANGED
|
@@ -4,7 +4,7 @@ import { capabilityKey, readCapability } from './capability.js';
|
|
|
4
4
|
import { effectDelta } from './controller-ingest.js';
|
|
5
5
|
import { foldControllerLog } from './controller-log.js';
|
|
6
6
|
import { LeafBindingError, RevokeProofError } from './errors.js';
|
|
7
|
-
/** Decode only; callers authenticate the tokens and membership references. */ export function memberRootsOf(binding, leafDID) {
|
|
7
|
+
/** Decode only; callers authenticate the tokens and membership references. */ export function memberRootsOf({ binding, leafDID }) {
|
|
8
8
|
const tokenRoot = (raw)=>{
|
|
9
9
|
const { iss, mbr } = readCapability(raw).payload;
|
|
10
10
|
return mbr == null ? {
|
|
@@ -48,8 +48,8 @@ import { LeafBindingError, RevokeProofError } from './errors.js';
|
|
|
48
48
|
});
|
|
49
49
|
return roots;
|
|
50
50
|
}
|
|
51
|
-
function foldedLog(controller, log) {
|
|
52
|
-
const folded = foldControllerLog(controller, log);
|
|
51
|
+
async function foldedLog(controller, log, options) {
|
|
52
|
+
const folded = await foldControllerLog(controller, log, options);
|
|
53
53
|
if (!folded.ok) throw new RevokeProofError('effects-mismatch');
|
|
54
54
|
return folded;
|
|
55
55
|
}
|
|
@@ -58,8 +58,8 @@ function denies(state, did) {
|
|
|
58
58
|
...state.deny
|
|
59
59
|
].some((entry)=>normalizeDID(entry) === normalizeDID(did));
|
|
60
60
|
}
|
|
61
|
-
function effectProofs(did, log) {
|
|
62
|
-
const folded = foldedLog(did, log);
|
|
61
|
+
async function effectProofs(did, log, options) {
|
|
62
|
+
const folded = await foldedLog(did, log, options);
|
|
63
63
|
const events = new Map(log.events.map((signed)=>[
|
|
64
64
|
digestOf(signed.event),
|
|
65
65
|
signed
|
|
@@ -107,16 +107,16 @@ function effectProofs(did, log) {
|
|
|
107
107
|
if (!prior.tombstones?.has(add)) append(tombstones, add, index);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
const viewAt = (epoch)=>{
|
|
110
|
+
const viewAt = async (epoch)=>{
|
|
111
111
|
if (epoch == null) return views.get(folded.head.epoch);
|
|
112
112
|
const held = views.get(epoch);
|
|
113
113
|
if (held != null) return held;
|
|
114
114
|
const anchor = anchors.get(epoch);
|
|
115
115
|
if (anchor == null) return undefined;
|
|
116
|
-
const historical = foldControllerLog(did, {
|
|
116
|
+
const historical = await foldControllerLog(did, {
|
|
117
117
|
chain: log.chain.slice(0, anchor + 1),
|
|
118
118
|
events: log.events
|
|
119
|
-
});
|
|
119
|
+
}, options);
|
|
120
120
|
const view = {
|
|
121
121
|
folded: historical,
|
|
122
122
|
applied: new Set(historical.ok ? historical.applied : [])
|
|
@@ -134,11 +134,11 @@ function effectProofs(did, log) {
|
|
|
134
134
|
viewAt
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
function checkEffect(log, claim, genFloor, proofs) {
|
|
137
|
+
async function checkEffect(log, claim, genFloor, proofs) {
|
|
138
138
|
let folded = proofs.folded;
|
|
139
139
|
const ref = claim.ref;
|
|
140
140
|
if ('event' in ref) {
|
|
141
|
-
const view = proofs.viewAt(ref.epoch);
|
|
141
|
+
const view = await proofs.viewAt(ref.epoch);
|
|
142
142
|
if (view == null) throw new RevokeProofError('no-rev');
|
|
143
143
|
if (!view.folded.ok) throw new RevokeProofError('effects-mismatch');
|
|
144
144
|
folded = view.folded;
|
|
@@ -174,29 +174,32 @@ function checkEffect(log, claim, genFloor, proofs) {
|
|
|
174
174
|
}
|
|
175
175
|
if (state.gen < genFloor) throw new RevokeProofError('generation-floor');
|
|
176
176
|
}
|
|
177
|
-
export function effectOf(controller, log, claim, genFloor) {
|
|
178
|
-
checkEffect(log, claim, genFloor, effectProofs(normalizeDID(controller), log));
|
|
177
|
+
export async function effectOf({ controller, log, claim, genFloor, ...options }) {
|
|
178
|
+
await checkEffect(log, claim, genFloor, await effectProofs(normalizeDID(controller), log, options));
|
|
179
179
|
}
|
|
180
|
-
export function effectProofContext(controller, log) {
|
|
180
|
+
export async function effectProofContext(controller, log, options) {
|
|
181
181
|
const did = normalizeDID(controller);
|
|
182
|
-
const proofs = effectProofs(did, log);
|
|
182
|
+
const proofs = await effectProofs(did, log, options);
|
|
183
183
|
return {
|
|
184
|
-
effectOf: (claim, genFloor)=>checkEffect(log, claim, genFloor, proofs),
|
|
185
|
-
claimsFor: (recorded, genFloor)=>claimsWithProofs(did, recorded, log, genFloor, proofs)
|
|
184
|
+
effectOf: async (claim, genFloor)=>await checkEffect(log, claim, genFloor, proofs),
|
|
185
|
+
claimsFor: async (recorded, genFloor)=>await claimsWithProofs(did, recorded, log, genFloor, proofs, options)
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
-
export function claimsFor(controller, recorded, merged, genFloor) {
|
|
189
|
-
return effectProofContext(controller, merged).claimsFor(recorded, genFloor);
|
|
188
|
+
export async function claimsFor({ controller, recorded, merged, genFloor, ...options }) {
|
|
189
|
+
return (await effectProofContext(controller, merged, options)).claimsFor(recorded, genFloor);
|
|
190
190
|
}
|
|
191
|
-
function claimsWithProofs(did, recorded, merged, genFloor, proofs) {
|
|
192
|
-
const before = recorded == null ? undefined : foldedLog(did, recorded);
|
|
191
|
+
async function claimsWithProofs(did, recorded, merged, genFloor, proofs, options) {
|
|
192
|
+
const before = recorded == null ? undefined : await foldedLog(did, recorded, options);
|
|
193
193
|
const after = proofs.folded;
|
|
194
|
-
const delta = effectDelta(
|
|
194
|
+
const delta = effectDelta({
|
|
195
|
+
before: before?.head,
|
|
196
|
+
after: after.head
|
|
197
|
+
});
|
|
195
198
|
const eventClaims = new Map();
|
|
196
199
|
// Authenticate each supplied epoch once, including retained pre-settlement closures.
|
|
197
200
|
for (const [digest, { event }] of proofs.events){
|
|
198
201
|
if (event.t !== 'rev' && event.t !== 'rmv') continue;
|
|
199
|
-
const view = proofs.viewAt(event.e);
|
|
202
|
+
const view = await proofs.viewAt(event.e);
|
|
200
203
|
if (view == null || !view.folded.ok || !view.applied.has(digest)) continue;
|
|
201
204
|
const ref = {
|
|
202
205
|
event: digest,
|
|
@@ -263,17 +266,17 @@ function claimsWithProofs(did, recorded, merged, genFloor, proofs) {
|
|
|
263
266
|
member
|
|
264
267
|
}))
|
|
265
268
|
];
|
|
266
|
-
|
|
269
|
+
const effects = [];
|
|
270
|
+
for (const claim of claims){
|
|
267
271
|
const floor = claim.kind === 'deny' ? Math.max(genFloor, after.head.gen) : genFloor;
|
|
268
272
|
const target = claim.kind === 'deny' ? `deny:${claim.did}` : `remove:${claim.member.add}`;
|
|
269
273
|
const event = eventClaims.get(target)?.find(({ claim: candidate, gen })=>{
|
|
270
274
|
return gen >= floor && (claim.kind === 'deny' || candidate.kind === 'remove' && candidate.member.did === claim.member.did);
|
|
271
275
|
});
|
|
272
276
|
if (event != null) {
|
|
273
|
-
checkEffect(merged, event.claim, floor, proofs);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
];
|
|
277
|
+
await checkEffect(merged, event.claim, floor, proofs);
|
|
278
|
+
effects.push(event.claim);
|
|
279
|
+
continue;
|
|
277
280
|
}
|
|
278
281
|
const atFloor = (index)=>(after.states[index]?.gen ?? -1) >= floor;
|
|
279
282
|
// Drops before tombstones: a 0.12.0 receiver accepts only the drop.
|
|
@@ -292,24 +295,36 @@ function claimsWithProofs(did, recorded, merged, genFloor, proofs) {
|
|
|
292
295
|
...claim,
|
|
293
296
|
ref
|
|
294
297
|
};
|
|
295
|
-
checkEffect(merged, candidate, floor, proofs);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
];
|
|
298
|
+
await checkEffect(merged, candidate, floor, proofs);
|
|
299
|
+
effects.push(candidate);
|
|
300
|
+
continue;
|
|
299
301
|
}
|
|
300
302
|
// Generation changes and DID denials end authority without an explicit removal proof.
|
|
301
|
-
if (claim.kind === 'remove' && before != null && !after.head.members.get(claim.member.add)?.removed && !proofs.drops.has(claim.member.add) && !eventClaims.has(target) && (before.head.gen !== after.head.gen || denies(after.head, claim.member.did)))
|
|
303
|
+
if (claim.kind === 'remove' && before != null && !after.head.members.get(claim.member.add)?.removed && !proofs.drops.has(claim.member.add) && !eventClaims.has(target) && (before.head.gen !== after.head.gen || denies(after.head, claim.member.did))) continue;
|
|
302
304
|
throw new RevokeProofError('no-rev');
|
|
303
|
-
}
|
|
305
|
+
}
|
|
306
|
+
return effects;
|
|
304
307
|
}
|
|
305
308
|
const projectionFolds = new WeakMap();
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
309
|
+
/**
|
|
310
|
+
* The fold of a projection's recorded log, once per log. Lifecycle checks run on every frame, and
|
|
311
|
+
* a fold verifies every signature in the log. Callers must only read the result.
|
|
312
|
+
*/ export async function projectionFold(controller, projection, options) {
|
|
313
|
+
const log = projection?.recordedLog;
|
|
314
|
+
if (projection == null || log == null) return undefined;
|
|
315
|
+
const cached = projectionFolds.get(projection);
|
|
316
|
+
// `recordedLogOf` hands out the live log, so growth in place must miss too.
|
|
317
|
+
if (cached != null && cached.crypto === options?.crypto && cached.log === log && cached.chainLength === log.chain.length && cached.eventsLength === log.events.length) return cached.folded;
|
|
318
|
+
const chainLength = log.chain.length;
|
|
319
|
+
const eventsLength = log.events.length;
|
|
320
|
+
const folded = await foldControllerLog(controller, log, options);
|
|
321
|
+
projectionFolds.set(projection, {
|
|
322
|
+
folded,
|
|
323
|
+
crypto: options?.crypto,
|
|
324
|
+
log,
|
|
325
|
+
chainLength,
|
|
326
|
+
eventsLength
|
|
327
|
+
});
|
|
313
328
|
return folded;
|
|
314
329
|
}
|
|
315
330
|
export function effectiveAttestingMembers(head, projection, time) {
|
|
@@ -318,7 +333,7 @@ export function effectiveAttestingMembers(head, projection, time) {
|
|
|
318
333
|
...head.members
|
|
319
334
|
].filter(([add, member])=>member.effective && !member.removed && !projection?.removedMembers.has(add) && (time == null || time <= member.lease));
|
|
320
335
|
}
|
|
321
|
-
export function memberRootStatus(registry, controller, root) {
|
|
336
|
+
export async function memberRootStatus({ registry, controller, root, ...options }) {
|
|
322
337
|
if (root.kind === 'root') return {
|
|
323
338
|
status: 'root'
|
|
324
339
|
};
|
|
@@ -327,7 +342,7 @@ export function memberRootStatus(registry, controller, root) {
|
|
|
327
342
|
if (projection?.removedMembers.has(root.add)) return {
|
|
328
343
|
status: 'removed'
|
|
329
344
|
};
|
|
330
|
-
const folded = projectionFold(did, projection);
|
|
345
|
+
const folded = await projectionFold(did, projection, options);
|
|
331
346
|
if (folded == null) return {
|
|
332
347
|
status: 'unavailable',
|
|
333
348
|
why: 'no-log'
|
|
@@ -375,17 +390,25 @@ function substituteRoot(raw, leaf) {
|
|
|
375
390
|
return undefined;
|
|
376
391
|
}
|
|
377
392
|
}
|
|
378
|
-
export function effectiveAuthorityOf(leaf, registry, controller) {
|
|
393
|
+
export async function effectiveAuthorityOf({ leaf, registry, controller, ...options }) {
|
|
379
394
|
const did = normalizeDID(controller);
|
|
380
395
|
if (normalizeDID(leaf.binding.id) !== did) return {
|
|
381
396
|
status: 'unavailable'
|
|
382
397
|
};
|
|
383
|
-
const roots = memberRootsOf(
|
|
398
|
+
const roots = memberRootsOf({
|
|
399
|
+
binding: leaf.binding,
|
|
400
|
+
leafDID: leaf.did
|
|
401
|
+
});
|
|
384
402
|
const primary = roots[0];
|
|
385
403
|
if (primary == null) return {
|
|
386
404
|
status: 'unavailable'
|
|
387
405
|
};
|
|
388
|
-
const status = memberRootStatus(
|
|
406
|
+
const status = await memberRootStatus({
|
|
407
|
+
registry,
|
|
408
|
+
controller: did,
|
|
409
|
+
root: primary.root,
|
|
410
|
+
...options
|
|
411
|
+
});
|
|
389
412
|
const projection = registry.controllers.get(did);
|
|
390
413
|
const chain = projection?.recordedLog?.chain;
|
|
391
414
|
if (chain != null && leaf.binding.prefix.some((signed, index)=>{
|
|
@@ -397,7 +420,12 @@ export function effectiveAuthorityOf(leaf, registry, controller) {
|
|
|
397
420
|
if (status.status === 'root' || status.status === 'effective') {
|
|
398
421
|
const holder = roots.find(({ slot })=>slot === 'holder');
|
|
399
422
|
if (holder != null) {
|
|
400
|
-
const held = memberRootStatus(
|
|
423
|
+
const held = await memberRootStatus({
|
|
424
|
+
registry,
|
|
425
|
+
controller: did,
|
|
426
|
+
root: holder.root,
|
|
427
|
+
...options
|
|
428
|
+
});
|
|
401
429
|
if (held.status === 'removed' || held.status === 'unavailable') return {
|
|
402
430
|
status: held.status
|
|
403
431
|
};
|
|
@@ -421,7 +449,12 @@ export function effectiveAuthorityOf(leaf, registry, controller) {
|
|
|
421
449
|
if (raw == null) continue;
|
|
422
450
|
const root = substituteRoot(raw, leaf);
|
|
423
451
|
if (root == null) continue;
|
|
424
|
-
const status = memberRootStatus(
|
|
452
|
+
const status = await memberRootStatus({
|
|
453
|
+
registry,
|
|
454
|
+
controller: did,
|
|
455
|
+
root,
|
|
456
|
+
...options
|
|
457
|
+
});
|
|
425
458
|
if (status.status === 'root' || status.status === 'effective') return {
|
|
426
459
|
root,
|
|
427
460
|
slot,
|
|
@@ -432,7 +465,7 @@ export function effectiveAuthorityOf(leaf, registry, controller) {
|
|
|
432
465
|
status: 'removed'
|
|
433
466
|
};
|
|
434
467
|
}
|
|
435
|
-
export function cascadeOf(leaves, claims, before, after, controller) {
|
|
468
|
+
export async function cascadeOf({ leaves, claims, before, after, controller, ...options }) {
|
|
436
469
|
const revoked = claims.filter((claim)=>claim.kind === 'deny').map((claim)=>({
|
|
437
470
|
did: normalizeDID(claim.did)
|
|
438
471
|
}));
|
|
@@ -446,8 +479,18 @@ export function cascadeOf(leaves, claims, before, after, controller) {
|
|
|
446
479
|
const capability = leaf.binding.capability == null ? undefined : readCapability(leaf.binding.capability).payload;
|
|
447
480
|
const issuer = capability?.cap == null ? undefined : normalizeDID(capability.iss);
|
|
448
481
|
const holderRoot = leaf.binding.holderGrant == null ? undefined : substituteRoot(leaf.binding.holderGrant, leaf);
|
|
449
|
-
const holderStatus = holderRoot == null ? undefined : memberRootStatus(
|
|
450
|
-
|
|
482
|
+
const holderStatus = holderRoot == null ? undefined : await memberRootStatus({
|
|
483
|
+
registry: after,
|
|
484
|
+
controller,
|
|
485
|
+
root: holderRoot,
|
|
486
|
+
...options
|
|
487
|
+
});
|
|
488
|
+
const authority = await effectiveAuthorityOf({
|
|
489
|
+
leaf,
|
|
490
|
+
registry: after,
|
|
491
|
+
controller,
|
|
492
|
+
...options
|
|
493
|
+
});
|
|
451
494
|
const evidenced = !direct.has(did) && after.devices.get(did)?.status !== 'revoked' && (holderStatus?.status === 'root' || holderStatus?.status === 'effective' || 'root' in authority && authority.slot === 'survivor');
|
|
452
495
|
if (issuer != null && direct.has(issuer) && !direct.has(did) && !evidenced) {
|
|
453
496
|
if (!affected.has(did)) revoked.push({
|
|
@@ -461,10 +504,29 @@ export function cascadeOf(leaves, claims, before, after, controller) {
|
|
|
461
504
|
continue;
|
|
462
505
|
}
|
|
463
506
|
if (!('status' in authority) || authority.status !== 'removed') continue;
|
|
464
|
-
const prior = effectiveAuthorityOf(
|
|
465
|
-
|
|
507
|
+
const prior = await effectiveAuthorityOf({
|
|
508
|
+
leaf,
|
|
509
|
+
registry: before,
|
|
510
|
+
controller,
|
|
511
|
+
...options
|
|
512
|
+
});
|
|
513
|
+
const roots = memberRootsOf({
|
|
514
|
+
binding: leaf.binding,
|
|
515
|
+
leafDID: leaf.did
|
|
516
|
+
}).map(({ root })=>root);
|
|
466
517
|
if ('root' in prior) roots.unshift(prior.root);
|
|
467
|
-
|
|
518
|
+
let root;
|
|
519
|
+
for (const candidate of roots){
|
|
520
|
+
if (candidate.kind === 'member' && (await memberRootStatus({
|
|
521
|
+
registry: after,
|
|
522
|
+
controller,
|
|
523
|
+
root: candidate,
|
|
524
|
+
...options
|
|
525
|
+
})).status === 'removed') {
|
|
526
|
+
root = candidate;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
468
530
|
if (root?.kind !== 'member') continue;
|
|
469
531
|
removed.push({
|
|
470
532
|
did,
|
package/lib/policy.d.ts
CHANGED
|
@@ -75,6 +75,10 @@ export declare function evaluateGroupContextExtensions(extensions: Array<{
|
|
|
75
75
|
extensionType: number;
|
|
76
76
|
extensionData: unknown;
|
|
77
77
|
}>, context: CommitPolicyContext): IncomingMessageAction;
|
|
78
|
+
export type DefaultCommitPolicyParams = {
|
|
79
|
+
incoming: IncomingMessage;
|
|
80
|
+
context: CommitPolicyContext;
|
|
81
|
+
};
|
|
78
82
|
/**
|
|
79
83
|
* Pure receiving-side commit policy: given the resolved context, decides whether an incoming
|
|
80
84
|
* commit or standalone proposal is admissible. Never throws.
|
|
@@ -89,7 +93,7 @@ export declare function evaluateGroupContextExtensions(extensions: Array<{
|
|
|
89
93
|
* One rule isn't a proposal's own: a commit enacting ledger entries must carry a
|
|
90
94
|
* group-context-extensions proposal, or entries would be enacted without moving the head.
|
|
91
95
|
*/
|
|
92
|
-
export declare function defaultCommitPolicy(incoming
|
|
96
|
+
export declare function defaultCommitPolicy({ incoming, context, }: DefaultCommitPolicyParams): IncomingMessageAction;
|
|
93
97
|
/**
|
|
94
98
|
* Thrown by the caller's resolver when an envelope names entry ids the ledger can't resolve.
|
|
95
99
|
* Belongs to the commit-policy resolution boundary, but {@link defaultCommitPolicy} itself is
|
package/lib/policy.js
CHANGED
|
@@ -211,7 +211,7 @@ function bytesEqual(a, b) {
|
|
|
211
211
|
*
|
|
212
212
|
* One rule isn't a proposal's own: a commit enacting ledger entries must carry a
|
|
213
213
|
* group-context-extensions proposal, or entries would be enacted without moving the head.
|
|
214
|
-
*/ export function defaultCommitPolicy(incoming, context) {
|
|
214
|
+
*/ export function defaultCommitPolicy({ incoming, context }) {
|
|
215
215
|
if (incoming.kind === 'proposal') {
|
|
216
216
|
const { proposal, senderLeafIndex } = incoming.proposal;
|
|
217
217
|
return evaluateProposal(proposal, senderLeafIndex, context);
|
|
@@ -22,8 +22,17 @@ export type OpenedRecoveryVerdict = {
|
|
|
22
22
|
signer: string;
|
|
23
23
|
verdict: RecoveryVerdict;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
26
|
-
|
|
25
|
+
export type ConfirmationKeyParams = {
|
|
26
|
+
group: GroupHandle;
|
|
27
|
+
position: string;
|
|
28
|
+
commitDigest: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function confirmationKey({ group, position, commitDigest, }: ConfirmationKeyParams): Promise<Uint8Array>;
|
|
31
|
+
export type ConfirmationTagParams = {
|
|
32
|
+
key: Uint8Array;
|
|
33
|
+
requestID: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function confirmationTag({ key, requestID }: ConfirmationTagParams): string;
|
|
27
36
|
export type SealRecoveryVerdictParams = {
|
|
28
37
|
group: GroupHandle;
|
|
29
38
|
identity: SigningIdentity;
|
|
@@ -40,4 +49,4 @@ export type RecoverySignerEligibleParams = {
|
|
|
40
49
|
/** Seconds since epoch; defaults to the current time. */
|
|
41
50
|
now?: number;
|
|
42
51
|
};
|
|
43
|
-
export declare function recoverySignerEligible(params: RecoverySignerEligibleParams): boolean
|
|
52
|
+
export declare function recoverySignerEligible(params: RecoverySignerEligibleParams): Promise<boolean>;
|
package/lib/recovery-verdict.js
CHANGED
|
@@ -21,7 +21,7 @@ function frame(value) {
|
|
|
21
21
|
out.set(bytes, 4);
|
|
22
22
|
return out;
|
|
23
23
|
}
|
|
24
|
-
export async function confirmationKey(group, position, commitDigest) {
|
|
24
|
+
export async function confirmationKey({ group, position, commitDigest }) {
|
|
25
25
|
const fields = [
|
|
26
26
|
group.groupID,
|
|
27
27
|
position,
|
|
@@ -33,9 +33,13 @@ export async function confirmationKey(group, position, commitDigest) {
|
|
|
33
33
|
context.set(field, offset);
|
|
34
34
|
offset += field.length;
|
|
35
35
|
}
|
|
36
|
-
return await group.exportSecret(
|
|
36
|
+
return await group.exportSecret({
|
|
37
|
+
label: 'kumiai.rejoin-confirm',
|
|
38
|
+
context,
|
|
39
|
+
length: 32
|
|
40
|
+
});
|
|
37
41
|
}
|
|
38
|
-
export function confirmationTag(key, requestID) {
|
|
42
|
+
export function confirmationTag({ key, requestID }) {
|
|
39
43
|
return encodeMultibase(hmac(sha256, key, utf8.encode(requestID)));
|
|
40
44
|
}
|
|
41
45
|
function isRecoveryVerdict(value) {
|
|
@@ -57,12 +61,16 @@ function isRecoveryVerdict(value) {
|
|
|
57
61
|
}
|
|
58
62
|
export async function sealRecoveryVerdict(params) {
|
|
59
63
|
const { group, identity, request, verdict } = params;
|
|
60
|
-
const verified = await verifyRecoveryRequest(
|
|
64
|
+
const verified = await verifyRecoveryRequest({
|
|
65
|
+
token: request,
|
|
66
|
+
crypto: group.crypto
|
|
67
|
+
});
|
|
61
68
|
if (normalizeDID(identity.id) !== normalizeDID(group.credential.id) || !isRecoveryVerdict(verdict) || verdict.groupID !== group.groupID || verdict.groupID !== verified.groupID || verdict.requestID !== verified.requestID) throw new Error('Recovery verdict does not bind the signed request');
|
|
62
69
|
const token = await identity.signToken({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
payload: {
|
|
71
|
+
...verdict,
|
|
72
|
+
type: VERDICT_TYPE
|
|
73
|
+
},
|
|
66
74
|
embedLongForm: true
|
|
67
75
|
});
|
|
68
76
|
// A refusal can answer an agent whose leaf the responder no longer holds.
|
|
@@ -83,7 +91,10 @@ export async function openRecoveryVerdict(params) {
|
|
|
83
91
|
requestID,
|
|
84
92
|
ephemeralPrivateKey
|
|
85
93
|
});
|
|
86
|
-
const token = await verifyToken(
|
|
94
|
+
const token = await verifyToken({
|
|
95
|
+
crypto: group.crypto,
|
|
96
|
+
token: new TextDecoder().decode(plaintext)
|
|
97
|
+
});
|
|
87
98
|
if (!isVerifiedToken(token) || token.payload.type !== VERDICT_TYPE || !isRecoveryVerdict(token.payload) || token.payload.groupID !== group.groupID || token.payload.requestID !== requestID) throw new Error('Unauthenticated recovery verdict');
|
|
88
99
|
const { groupID, position, commitDigest } = token.payload;
|
|
89
100
|
const binding = {
|
|
@@ -110,16 +121,19 @@ export async function openRecoveryVerdict(params) {
|
|
|
110
121
|
verdict
|
|
111
122
|
};
|
|
112
123
|
}
|
|
113
|
-
export function recoverySignerEligible(params) {
|
|
124
|
+
export async function recoverySignerEligible(params) {
|
|
114
125
|
const { group, registry, signer, now = Date.now() / 1000 } = params;
|
|
115
126
|
const controller = group.anchor.controller;
|
|
116
127
|
if (controller == null) return false;
|
|
128
|
+
const options = {
|
|
129
|
+
crypto: group.crypto
|
|
130
|
+
};
|
|
117
131
|
try {
|
|
118
132
|
const binding = group.bindingOfDID(signer);
|
|
119
133
|
if (binding?.controller !== controller || binding.prefix == null) return false;
|
|
120
134
|
const payload = binding.member != null || binding.capability == null ? undefined : readCapability(binding.capability).payload;
|
|
121
135
|
if (registry.devices.get(normalizeDID(signer))?.status === 'revoked' || payload?.cap != null && registry.devices.get(normalizeDID(payload.iss))?.status === 'revoked') return false;
|
|
122
|
-
const folded = foldChain(controller, binding.prefix);
|
|
136
|
+
const folded = await foldChain(controller, binding.prefix, options);
|
|
123
137
|
const projection = registry.controllers.get(normalizeDID(controller));
|
|
124
138
|
if (!folded.ok || (folded.states.at(-1)?.gen ?? 0) < (projection?.genFloor ?? 0)) return false;
|
|
125
139
|
const bound = {
|
|
@@ -127,24 +141,44 @@ export function recoverySignerEligible(params) {
|
|
|
127
141
|
id: controller,
|
|
128
142
|
prefix: binding.prefix
|
|
129
143
|
};
|
|
130
|
-
const authority = effectiveAuthorityOf({
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
const authority = await effectiveAuthorityOf({
|
|
145
|
+
leaf: {
|
|
146
|
+
did: signer,
|
|
147
|
+
binding: bound,
|
|
148
|
+
leafKey: binding.leafKey
|
|
149
|
+
},
|
|
150
|
+
registry,
|
|
151
|
+
controller,
|
|
152
|
+
...options
|
|
153
|
+
});
|
|
135
154
|
if ('status' in authority) return false;
|
|
136
155
|
if (binding.member != null && authority.slot === 'membership') {
|
|
137
|
-
const status = memberRootStatus(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
const status = await memberRootStatus({
|
|
157
|
+
registry,
|
|
158
|
+
controller,
|
|
159
|
+
root: {
|
|
160
|
+
kind: 'member',
|
|
161
|
+
did: signer,
|
|
162
|
+
add: binding.member.add,
|
|
163
|
+
gen: binding.member.g
|
|
164
|
+
},
|
|
165
|
+
...options
|
|
142
166
|
});
|
|
143
167
|
if (status.status !== 'effective' || status.key.length !== binding.leafKey.length || status.key.some((byte, index)=>byte !== binding.leafKey[index])) return false;
|
|
144
168
|
}
|
|
145
|
-
const expiry = leafExpiry(
|
|
169
|
+
const expiry = await leafExpiry({
|
|
170
|
+
binding: bound,
|
|
171
|
+
registry,
|
|
172
|
+
controller,
|
|
173
|
+
...options
|
|
174
|
+
});
|
|
146
175
|
if (expiry == null) return false;
|
|
147
|
-
const time = attestedTreeTime(
|
|
176
|
+
const time = await attestedTreeTime({
|
|
177
|
+
tree: group.state.ratchetTree,
|
|
178
|
+
registry,
|
|
179
|
+
controllerID: controller,
|
|
180
|
+
...options
|
|
181
|
+
});
|
|
148
182
|
return expiry >= Math.max(time, now - 300);
|
|
149
183
|
} catch {
|
|
150
184
|
return false;
|
package/lib/recovery.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SigningIdentity } from '@kokuin/token';
|
|
1
|
+
import { type CryptoOptions, type SigningIdentity } from '@kokuin/token';
|
|
2
2
|
import { type GroupHandle } from './group.js';
|
|
3
3
|
/** `type` tag on every recovery-request token. Domain-separates it, so a token
|
|
4
4
|
* minted for another purpose can never pose as a request for group state. */
|
|
@@ -66,11 +66,15 @@ export type VerifiedRecoveryRequest = {
|
|
|
66
66
|
* ratchet tree. The authorization check; a removed member fails it.
|
|
67
67
|
*/
|
|
68
68
|
export type RecoveryRequestRejection = 'unverified' | 'malformed' | 'group-mismatch' | 'not-a-member';
|
|
69
|
+
export type RecoveryRequestErrorParams = {
|
|
70
|
+
reason: RecoveryRequestRejection;
|
|
71
|
+
message: string;
|
|
72
|
+
} & ErrorOptions;
|
|
69
73
|
/** Thrown by {@link sealGroupInfo}. The primitive refuses loudly rather than
|
|
70
74
|
* returning an empty reply; a responder that wants to stay silent catches this. */
|
|
71
75
|
export declare class RecoveryRequestError extends Error {
|
|
72
76
|
#private;
|
|
73
|
-
constructor(reason
|
|
77
|
+
constructor({ reason, message, ...options }: RecoveryRequestErrorParams);
|
|
74
78
|
get reason(): RecoveryRequestRejection;
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
@@ -101,21 +105,32 @@ export type SealedGroupInfoRejection = SealedReplyRejection | 'unauthenticated'
|
|
|
101
105
|
* GroupInfo presented as a ledger is `not-for-me`, not `malformed`: the domains
|
|
102
106
|
* differ, so the AEAD refuses before anything is parsed. */
|
|
103
107
|
export type SealedLedgerRejection = SealedReplyRejection;
|
|
108
|
+
export type SealedGroupInfoErrorParams = {
|
|
109
|
+
reason: SealedGroupInfoRejection;
|
|
110
|
+
message: string;
|
|
111
|
+
} & ErrorOptions;
|
|
104
112
|
/** Thrown by {@link openSealedGroupInfo}. Distinguishes "not addressed to me" from
|
|
105
113
|
* "corrupt", so a peer sifting a shared lane drops the former quietly. */
|
|
106
114
|
export declare class SealedGroupInfoError extends Error {
|
|
107
115
|
#private;
|
|
108
|
-
constructor(reason
|
|
116
|
+
constructor({ reason, message, ...options }: SealedGroupInfoErrorParams);
|
|
109
117
|
get reason(): SealedGroupInfoRejection;
|
|
110
118
|
}
|
|
119
|
+
export type SealedLedgerErrorParams = {
|
|
120
|
+
reason: SealedReplyRejection;
|
|
121
|
+
message: string;
|
|
122
|
+
} & ErrorOptions;
|
|
111
123
|
/** Thrown by {@link openSealedLedger}, read like its GroupInfo sibling: a requester
|
|
112
124
|
* sifting a shared lane drops `not-for-me` quietly (every other member's reply to
|
|
113
125
|
* every other request looks like this) and shouts about `malformed`. */
|
|
114
126
|
export declare class SealedLedgerError extends Error {
|
|
115
127
|
#private;
|
|
116
|
-
constructor(reason
|
|
128
|
+
constructor({ reason, message, ...options }: SealedLedgerErrorParams);
|
|
117
129
|
get reason(): SealedReplyRejection;
|
|
118
130
|
}
|
|
131
|
+
export type VerifyRecoveryRequestParams = {
|
|
132
|
+
token: string;
|
|
133
|
+
} & CryptoOptions;
|
|
119
134
|
/**
|
|
120
135
|
* Verify a request token's signature and parse its payload. The requester DID is
|
|
121
136
|
* the verified issuer, never a payload field. Unsigned (`alg: 'none'`) tokens are
|
|
@@ -123,7 +138,7 @@ export declare class SealedLedgerError extends Error {
|
|
|
123
138
|
* attacker-chosen. `embedLongForm` lets it verify offline — a responder needs no
|
|
124
139
|
* DID resolver to answer.
|
|
125
140
|
*/
|
|
126
|
-
export declare function verifyRecoveryRequest(token:
|
|
141
|
+
export declare function verifyRecoveryRequest({ token, ...options }: VerifyRecoveryRequestParams): Promise<VerifiedRecoveryRequest>;
|
|
127
142
|
export type CreateRecoveryRequestParams = {
|
|
128
143
|
/** The requester's own (possibly stale) handle: it names the group, and its
|
|
129
144
|
* ciphersuite is the HPKE the ephemeral keypair must be minted under. */
|