@kumiai/mls 0.11.0 → 0.12.1
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 +30 -1
- package/lib/authentication.d.ts +6 -2
- package/lib/authentication.js +207 -51
- package/lib/capability.d.ts +4 -0
- package/lib/capability.js +22 -10
- package/lib/controller-ingest.d.ts +19 -0
- package/lib/controller-ingest.js +117 -0
- package/lib/controller-log.d.ts +6 -3
- package/lib/controller-log.js +52 -13
- package/lib/credential.d.ts +8 -5
- package/lib/credential.js +32 -3
- package/lib/device-proof.d.ts +5 -0
- package/lib/embedded-resolver.d.ts +8 -18
- package/lib/embedded-resolver.js +52 -24
- package/lib/errors.d.ts +8 -2
- package/lib/errors.js +11 -0
- package/lib/group-commit.d.ts +11 -2
- package/lib/group-commit.js +154 -46
- package/lib/group-context.d.ts +4 -2
- package/lib/group-context.js +30 -6
- package/lib/group-create.js +44 -16
- package/lib/group-credential.js +22 -1
- package/lib/group-device.js +5 -15
- package/lib/group-handle.d.ts +12 -1
- package/lib/group-handle.js +89 -12
- package/lib/group-lifecycle.d.ts +31 -5
- package/lib/group-lifecycle.js +253 -155
- package/lib/group-membership.js +1 -1
- package/lib/group-welcome.d.ts +4 -0
- package/lib/group-welcome.js +14 -2
- package/lib/history.d.ts +6 -0
- package/lib/history.js +20 -1
- package/lib/index.d.ts +12 -7
- package/lib/index.js +11 -6
- package/lib/lifecycle-proof.d.ts +15 -6
- package/lib/lifecycle-proof.js +195 -126
- package/lib/lifecycle.d.ts +9 -6
- package/lib/lifecycle.js +194 -84
- package/lib/member-root.d.ts +88 -0
- package/lib/member-root.js +480 -0
- package/lib/recovery-verdict.d.ts +1 -1
- package/lib/recovery-verdict.js +30 -13
- package/lib/registry.d.ts +17 -6
- package/lib/registry.js +206 -20
- package/lib/stale-leaf.d.ts +2 -0
- package/lib/stale-leaf.js +9 -4
- package/lib/types.d.ts +3 -0
- package/package.json +4 -4
package/lib/group-handle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertTimeClaimsValid, decodeSignedToken, normalizeDID } from '@kokuin/token';
|
|
2
2
|
import { toB64 } from '@sozai/codec';
|
|
3
3
|
import { EventEmitter } from '@sozai/event';
|
|
4
|
-
import { contentTypes, createApplicationMessage, createProposal, decode, defaultCredentialTypes, defaultKeyRetentionConfig, defaultProposalTypes, encode, isDefaultCredential, leafNodeSources, mlsExporter, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, UsageError, wireformats } from 'ts-mls';
|
|
4
|
+
import { contentTypes, createApplicationMessage, createProposal, decode, defaultCredentialTypes, defaultKeyRetentionConfig, defaultProposalTypes, encode, isDefaultCredential, isDefaultProposal, leafNodeSources, mlsExporter, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, UsageError, wireformats } from 'ts-mls';
|
|
5
5
|
import { readGroupAnchor } from './anchor.js';
|
|
6
6
|
import { verifyLeafCredential } from './authentication.js';
|
|
7
7
|
import { encodeClientState } from './codec.js';
|
|
@@ -12,17 +12,46 @@ import { foldEnvelope, GROUP_TYPE_PREFIX } from './envelope-fold.js';
|
|
|
12
12
|
import { HandshakeReservationError, HandshakeWindowConfigError, HandshakeWindowError, LeafBindingError, LeafLapsedError, RevokeProofError } from './errors.js';
|
|
13
13
|
import { createMlsContext, deviceDenyHolderFor } from './group-context.js';
|
|
14
14
|
import { readMessageEpoch } from './group-info.js';
|
|
15
|
-
import { assertHeadMatches, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, headsMatch, readLedgerHead, readLedgerHeadExtension } from './head.js';
|
|
15
|
+
import { assertHeadMatches, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, readLedgerHead, readLedgerHeadExtension } from './head.js';
|
|
16
|
+
import { settleAdvisory } from './history.js';
|
|
16
17
|
import { ledgerEntryDigest, verifyLedgerEntry } from './ledger.js';
|
|
17
18
|
import { assertSenderNotLapsed, isLapsed, isUnchangedLeaf, leafAt, prepareLifecycleGate, rejectionReason } from './lifecycle.js';
|
|
18
19
|
import { createMutex } from './mutex.js';
|
|
19
20
|
import { defaultCommitPolicy, MissingLedgerEntriesError } from './policy.js';
|
|
20
|
-
import { beaconOf, controllerOf, DEVICE_ENTRY_TYPE, denySetOf, foldControl, isDeviceValue, mayReadmitResetDevice, revocationOf } from './registry.js';
|
|
21
|
+
import { beaconOf, controllerOf, DEVICE_ENTRY_TYPE, denySetOf, foldControl, isDeviceValue, mayReadmitResetDevice, recordedLogOf, revocationOf } from './registry.js';
|
|
21
22
|
import { advanceSendingRatchet } from './secret-tree.js';
|
|
22
23
|
import { readSenderLeafIndex } from './sender-data.js';
|
|
23
24
|
/** One serializer per live handle, so its state-mutating operations run one at a
|
|
24
25
|
* time in issue order. Keyed weakly: the entry is collected with the handle, and
|
|
25
26
|
* the handle carries no reference back to it. */ const MUTEXES = new WeakMap();
|
|
27
|
+
const HISTORICAL_REGISTRIES = new WeakMap();
|
|
28
|
+
export function registryAt(group, head) {
|
|
29
|
+
let cache = HISTORICAL_REGISTRIES.get(group);
|
|
30
|
+
if (cache == null) {
|
|
31
|
+
cache = new Map();
|
|
32
|
+
HISTORICAL_REGISTRIES.set(group, cache);
|
|
33
|
+
}
|
|
34
|
+
const key = toB64(head);
|
|
35
|
+
const cached = cache.get(key);
|
|
36
|
+
if (cached != null) return cached;
|
|
37
|
+
let held = genesisHead(group.groupID);
|
|
38
|
+
let length = 0;
|
|
39
|
+
for (const entry of group.ledger){
|
|
40
|
+
if (headsMatch(held, head)) break;
|
|
41
|
+
held = extendHead(held, [
|
|
42
|
+
entry.entryID
|
|
43
|
+
]);
|
|
44
|
+
length++;
|
|
45
|
+
}
|
|
46
|
+
if (!headsMatch(held, head)) throw new Error('Unknown epoch ledger head');
|
|
47
|
+
const registry = foldLedgerControl(group.ledger.slice(0, length), group.anchor, group.groupID).registry;
|
|
48
|
+
cache.set(key, registry);
|
|
49
|
+
if (cache.size > 8) {
|
|
50
|
+
const oldest = cache.keys().next().value;
|
|
51
|
+
if (oldest != null) cache.delete(oldest);
|
|
52
|
+
}
|
|
53
|
+
return registry;
|
|
54
|
+
}
|
|
26
55
|
/** Leave half the configured receiver window unused. */ const HANDSHAKE_WINDOW_DIVISOR = 2;
|
|
27
56
|
export function mutexFor(handle) {
|
|
28
57
|
let mutex = MUTEXES.get(handle);
|
|
@@ -312,7 +341,11 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
312
341
|
const denyHolder = deviceDenyHolderFor(this.#context);
|
|
313
342
|
if (denyHolder != null) {
|
|
314
343
|
denyHolder.provider = ()=>this.currentDenySet();
|
|
315
|
-
denyHolder.
|
|
344
|
+
denyHolder.judging = ()=>({
|
|
345
|
+
registry: anchor.controller == null ? undefined : this.registry,
|
|
346
|
+
stage: 'full',
|
|
347
|
+
mode: 'admit'
|
|
348
|
+
});
|
|
316
349
|
denyHolder.leafLifetime = anchor.controller == null ? undefined : anchor.leafLifetime ?? 86_400;
|
|
317
350
|
denyHolder.trustedGrantLifetime = anchor.controller == null ? undefined : anchor.trustedGrantLifetime ?? 2_592_000;
|
|
318
351
|
}
|
|
@@ -389,6 +422,11 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
389
422
|
/** The device registry folded from the anchor and every applied ledger entry. */ get registry() {
|
|
390
423
|
return this.#registry;
|
|
391
424
|
}
|
|
425
|
+
settleAdvisory() {
|
|
426
|
+
const controller = this.#anchor.controller;
|
|
427
|
+
const log = controller == null ? undefined : recordedLogOf(this.#registry, controller);
|
|
428
|
+
return log == null ? 'ok' : settleAdvisory(log);
|
|
429
|
+
}
|
|
392
430
|
/**
|
|
393
431
|
* The device deny set the auth service consumes: the DIDs revoked in the CURRENTLY folded
|
|
394
432
|
* registry (pre-commit). Matched, never enumerated by consumers. A revoke takes deny-effect from
|
|
@@ -431,12 +469,31 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
431
469
|
}
|
|
432
470
|
const emitter = emitterOf(this);
|
|
433
471
|
const revoked = [];
|
|
472
|
+
const removed = [];
|
|
434
473
|
for (const { entry } of enacted){
|
|
435
474
|
if (entry.type !== DEVICE_ENTRY_TYPE || !isDeviceValue(entry.value)) continue;
|
|
436
475
|
const value = entry.value;
|
|
437
476
|
const subject = normalizeDID(entry.subject);
|
|
438
477
|
if (this.#anchor.controller != null && (value.op === 'revoke' || value.op === 'reset')) {
|
|
439
|
-
for (const
|
|
478
|
+
for (const claim of value.effects ?? []){
|
|
479
|
+
if (claim.kind !== 'remove') continue;
|
|
480
|
+
removed.push({
|
|
481
|
+
controller: subject,
|
|
482
|
+
member: {
|
|
483
|
+
did: normalizeDID(claim.member.did),
|
|
484
|
+
add: claim.member.add
|
|
485
|
+
},
|
|
486
|
+
removedLeaves: (value.removed ?? []).filter(({ cascadedFrom })=>normalizeDID(cascadedFrom) === normalizeDID(claim.member.did)).map(({ did })=>normalizeDID(did))
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
for (const effect of [
|
|
490
|
+
...value.revoked ?? [],
|
|
491
|
+
...(value.effects ?? []).flatMap((claim)=>claim.kind === 'deny' && !value.revoked?.some(({ did })=>normalizeDID(did) === normalizeDID(claim.did)) ? [
|
|
492
|
+
{
|
|
493
|
+
did: claim.did
|
|
494
|
+
}
|
|
495
|
+
] : [])
|
|
496
|
+
]){
|
|
440
497
|
const device = normalizeDID(effect.did);
|
|
441
498
|
const record = revocationOf(this, device);
|
|
442
499
|
if (record != null) revoked.push({
|
|
@@ -459,6 +516,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
459
516
|
}
|
|
460
517
|
}
|
|
461
518
|
if (revoked.length > 0) emitter.fire('deviceRevoked', revoked);
|
|
519
|
+
if (removed.length > 0) emitter.fire('memberRemoved', removed);
|
|
462
520
|
}
|
|
463
521
|
/** Deliver independent host notifications after acceptance and any requested persist. */ #notifyAccepted(surfaced, enactedDevice) {
|
|
464
522
|
const errors = [];
|
|
@@ -1332,6 +1390,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1332
1390
|
return emit;
|
|
1333
1391
|
};
|
|
1334
1392
|
return {
|
|
1393
|
+
candidateRegistry,
|
|
1335
1394
|
callback: wrapCommitPolicy(combined, capture),
|
|
1336
1395
|
capture,
|
|
1337
1396
|
applyOnAccept,
|
|
@@ -1415,6 +1474,12 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1415
1474
|
controller: parsed.controller.id,
|
|
1416
1475
|
prefix: parsed.controller.prefix,
|
|
1417
1476
|
capability: parsed.controller.capability,
|
|
1477
|
+
...parsed.controller.member == null ? {} : {
|
|
1478
|
+
member: parsed.controller.member
|
|
1479
|
+
},
|
|
1480
|
+
...parsed.controller.iat == null ? {} : {
|
|
1481
|
+
iat: parsed.controller.iat
|
|
1482
|
+
},
|
|
1418
1483
|
...parsed.controller.holderGrant == null ? {} : {
|
|
1419
1484
|
holderGrant: parsed.controller.holderGrant
|
|
1420
1485
|
}
|
|
@@ -1546,7 +1611,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1546
1611
|
const proposalEpoch = privateProposal?.epoch ?? (frame.wireformat === wireformats.mls_public_message && frame.publicMessage.content.contentType === contentTypes.proposal ? frame.publicMessage.content.epoch : undefined);
|
|
1547
1612
|
// Past proposals cannot be enacted at this epoch and need no ratchet or ledger work.
|
|
1548
1613
|
if (proposalEpoch != null && proposalEpoch < this.epoch) return null;
|
|
1549
|
-
const { callback, capture, applyOnAccept, postApply } = await this.#prepareCommitPipeline(decoded, opts);
|
|
1614
|
+
const { callback, capture, applyOnAccept, postApply, candidateRegistry } = await this.#prepareCommitPipeline(decoded, opts);
|
|
1550
1615
|
const previousState = this.#state;
|
|
1551
1616
|
const previousAdmission = this.#admission;
|
|
1552
1617
|
const application = readPrivateFrame(decoded, contentTypes.application);
|
|
@@ -1568,16 +1633,28 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1568
1633
|
authService: {
|
|
1569
1634
|
validateCredential: async (credential, key)=>{
|
|
1570
1635
|
try {
|
|
1636
|
+
// Referenced Updates authenticate before the commit callback runs.
|
|
1637
|
+
const proposed = (capture.rejected?.proposals ?? Object.values(this.#state.unappliedProposals)).find(({ proposal })=>{
|
|
1638
|
+
if (!isDefaultProposal(proposal)) return false;
|
|
1639
|
+
if (proposal.proposalType === defaultProposalTypes.add) return proposal.add.keyPackage.leafNode.credential === credential;
|
|
1640
|
+
return proposal.proposalType === defaultProposalTypes.update && proposal.update.leafNode.credential === credential;
|
|
1641
|
+
});
|
|
1642
|
+
const index = proposed == null ? capture.committerLeafIndex : proposed.proposal.proposalType === defaultProposalTypes.update ? proposed.senderLeafIndex : undefined;
|
|
1643
|
+
const retained = index != null && isUnchangedLeaf(this.#state.ratchetTree, index, {
|
|
1644
|
+
credential,
|
|
1645
|
+
signaturePublicKey: key
|
|
1646
|
+
});
|
|
1571
1647
|
await verifyLeafCredential(credential, key, {
|
|
1572
|
-
deviceDenySet: ()=>
|
|
1573
|
-
|
|
1648
|
+
deviceDenySet: ()=>denySetOf(candidateRegistry),
|
|
1649
|
+
judging: ()=>({
|
|
1650
|
+
registry: this.#anchor.controller == null ? undefined : candidateRegistry,
|
|
1651
|
+
stage: 'full',
|
|
1652
|
+
mode: retained ? 'retain' : 'admit'
|
|
1653
|
+
}),
|
|
1574
1654
|
// MLS re-validates the committer's path leaf after its proposals are judged:
|
|
1575
1655
|
// an evidenced child keeps a denied issuer only with the credential it
|
|
1576
1656
|
// already holds at that leaf.
|
|
1577
|
-
mayKeepDeniedIssuer: (
|
|
1578
|
-
credential: leafCredential,
|
|
1579
|
-
signaturePublicKey: leafKey
|
|
1580
|
-
}),
|
|
1657
|
+
mayKeepDeniedIssuer: ()=>this.#anchor.controller != null && retained,
|
|
1581
1658
|
leafLifetime: ()=>this.#anchor.controller == null ? undefined : this.#anchor.leafLifetime ?? 86_400,
|
|
1582
1659
|
trustedGrantLifetime: ()=>this.#anchor.controller == null ? undefined : this.#anchor.trustedGrantLifetime ?? 2_592_000
|
|
1583
1660
|
});
|
package/lib/group-lifecycle.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ControllerLog } from '@kokuin/controller';
|
|
2
|
+
import { type ClientState } from 'ts-mls';
|
|
2
3
|
import { type ControllerBinding } from './credential.js';
|
|
3
4
|
import { type RevokeProofReason } from './errors.js';
|
|
4
5
|
import type { DeviceWriteResult } from './group-device.js';
|
|
5
6
|
import { type GroupHandle } from './group-handle.js';
|
|
7
|
+
import { type EffectClaim } from './member-root.js';
|
|
8
|
+
import { type DeviceRegistry } from './registry.js';
|
|
6
9
|
export type CommitResult = DeviceWriteResult;
|
|
10
|
+
export declare function controllerLogDelta(group: GroupHandle, log: ControllerLog): ControllerLog | null;
|
|
11
|
+
export declare function publishControllerLog(group: GroupHandle, log: ControllerLog): Promise<DeviceWriteResult | null>;
|
|
7
12
|
/**
|
|
8
13
|
* Author a by-reference Remove for this handle's own leaf at its current epoch.
|
|
9
14
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
@@ -22,6 +27,7 @@ export declare function proposeSelfRemoval(group: GroupHandle): Promise<{
|
|
|
22
27
|
export declare function commitSelfRemovals(group: GroupHandle): Promise<CommitResult | null>;
|
|
23
28
|
export type RevokeBuildResult = {
|
|
24
29
|
status: 'built';
|
|
30
|
+
effects: Array<EffectClaim>;
|
|
25
31
|
result: DeviceWriteResult;
|
|
26
32
|
} | {
|
|
27
33
|
status: 'already-revoked';
|
|
@@ -32,18 +38,38 @@ export type RevokeBuildResult = {
|
|
|
32
38
|
status: 'not-provable';
|
|
33
39
|
reason: RevokeProofReason;
|
|
34
40
|
};
|
|
35
|
-
export declare function
|
|
41
|
+
export declare function preservationClock(group: GroupHandle, candidateTree: ClientState['ratchetTree'], candidateRegistry: DeviceRegistry): Promise<Array<string>>;
|
|
42
|
+
export declare function attestTreeTime(group: GroupHandle, time?: number): Promise<DeviceWriteResult | null>;
|
|
43
|
+
export declare function renewLeaf(group: GroupHandle, binding: ControllerBinding, options?: {
|
|
44
|
+
controllerLog?: ControllerLog;
|
|
45
|
+
}): Promise<DeviceWriteResult>;
|
|
36
46
|
export type RemoveLapsedLeavesResult = {
|
|
37
47
|
removed: Array<string>;
|
|
38
48
|
/** Absent when no leaf had lapsed. */
|
|
39
49
|
result?: DeviceWriteResult;
|
|
40
50
|
};
|
|
41
51
|
export declare function removeLapsedLeaves(group: GroupHandle): Promise<RemoveLapsedLeavesResult>;
|
|
52
|
+
export type RemovalEvidence = {
|
|
53
|
+
controller: string;
|
|
54
|
+
epoch: string;
|
|
55
|
+
closure: ControllerLog;
|
|
56
|
+
};
|
|
57
|
+
export declare function removalEvidence(controller: string, log: ControllerLog, rmv: string): RemovalEvidence | undefined;
|
|
58
|
+
export declare function survivorTargets(group: GroupHandle, add: string): Array<{
|
|
59
|
+
did: string;
|
|
60
|
+
leafKey: Uint8Array;
|
|
61
|
+
}>;
|
|
42
62
|
export type RevokeWithProofParams = {
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
log: ControllerLog;
|
|
64
|
+
deny?: Array<string>;
|
|
65
|
+
remove?: Array<{
|
|
66
|
+
did: string;
|
|
67
|
+
add: string;
|
|
68
|
+
}>;
|
|
69
|
+
survivors?: Array<string>;
|
|
70
|
+
evidence?: Array<RemovalEvidence>;
|
|
45
71
|
} | {
|
|
46
72
|
reset: true;
|
|
47
|
-
log:
|
|
73
|
+
log: ControllerLog;
|
|
48
74
|
};
|
|
49
75
|
export declare function revokeWithProof(group: GroupHandle, params: RevokeWithProofParams): Promise<RevokeBuildResult>;
|