@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/group-lifecycle.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ControllerLog } from '@kokuin/controller';
|
|
2
|
+
import { type CryptoOptions } from '@kokuin/token';
|
|
2
3
|
import { type ClientState } from 'ts-mls';
|
|
3
4
|
import { type ControllerBinding } from './credential.js';
|
|
4
5
|
import { type RevokeProofReason } from './errors.js';
|
|
@@ -7,8 +8,16 @@ import { type GroupHandle } from './group-handle.js';
|
|
|
7
8
|
import { type EffectClaim } from './member-root.js';
|
|
8
9
|
import { type DeviceRegistry } from './registry.js';
|
|
9
10
|
export type CommitResult = DeviceWriteResult;
|
|
10
|
-
export
|
|
11
|
-
|
|
11
|
+
export type ControllerLogDeltaParams = {
|
|
12
|
+
group: GroupHandle;
|
|
13
|
+
log: ControllerLog;
|
|
14
|
+
};
|
|
15
|
+
export declare function controllerLogDelta({ group, log, }: ControllerLogDeltaParams): Promise<ControllerLog | null>;
|
|
16
|
+
export type PublishControllerLogParams = {
|
|
17
|
+
group: GroupHandle;
|
|
18
|
+
log: ControllerLog;
|
|
19
|
+
};
|
|
20
|
+
export declare function publishControllerLog({ group, log, }: PublishControllerLogParams): Promise<DeviceWriteResult | null>;
|
|
12
21
|
/**
|
|
13
22
|
* Author a by-reference Remove for this handle's own leaf at its current epoch.
|
|
14
23
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
@@ -38,11 +47,23 @@ export type RevokeBuildResult = {
|
|
|
38
47
|
status: 'not-provable';
|
|
39
48
|
reason: RevokeProofReason;
|
|
40
49
|
};
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
export type PreservationClockParams = {
|
|
51
|
+
group: GroupHandle;
|
|
52
|
+
candidateTree: ClientState['ratchetTree'];
|
|
53
|
+
candidateRegistry: DeviceRegistry;
|
|
54
|
+
};
|
|
55
|
+
export declare function preservationClock({ group, candidateTree, candidateRegistry, }: PreservationClockParams): Promise<Array<string>>;
|
|
56
|
+
export type AttestTreeTimeParams = {
|
|
57
|
+
group: GroupHandle;
|
|
58
|
+
time?: number;
|
|
59
|
+
};
|
|
60
|
+
export declare function attestTreeTime({ group, time, }: AttestTreeTimeParams): Promise<DeviceWriteResult | null>;
|
|
61
|
+
export type RenewLeafParams = {
|
|
62
|
+
group: GroupHandle;
|
|
63
|
+
binding: ControllerBinding;
|
|
44
64
|
controllerLog?: ControllerLog;
|
|
45
|
-
}
|
|
65
|
+
};
|
|
66
|
+
export declare function renewLeaf({ group, binding, ...options }: RenewLeafParams): Promise<DeviceWriteResult>;
|
|
46
67
|
export type RemoveLapsedLeavesResult = {
|
|
47
68
|
removed: Array<string>;
|
|
48
69
|
/** Absent when no leaf had lapsed. */
|
|
@@ -54,12 +75,21 @@ export type RemovalEvidence = {
|
|
|
54
75
|
epoch: string;
|
|
55
76
|
closure: ControllerLog;
|
|
56
77
|
};
|
|
57
|
-
export
|
|
58
|
-
|
|
78
|
+
export type RemovalEvidenceParams = {
|
|
79
|
+
controller: string;
|
|
80
|
+
log: ControllerLog;
|
|
81
|
+
rmv: string;
|
|
82
|
+
} & CryptoOptions;
|
|
83
|
+
export declare function removalEvidence({ controller, log, rmv, ...options }: RemovalEvidenceParams): Promise<RemovalEvidence | undefined>;
|
|
84
|
+
export type SurvivorTargetsParams = {
|
|
85
|
+
group: GroupHandle;
|
|
86
|
+
add: string;
|
|
87
|
+
};
|
|
88
|
+
export declare function survivorTargets({ group, add, }: SurvivorTargetsParams): Promise<Array<{
|
|
59
89
|
did: string;
|
|
60
90
|
leafKey: Uint8Array;
|
|
61
|
-
}
|
|
62
|
-
export type
|
|
91
|
+
}>>;
|
|
92
|
+
export type RevokeProofInput = {
|
|
63
93
|
log: ControllerLog;
|
|
64
94
|
deny?: Array<string>;
|
|
65
95
|
remove?: Array<{
|
|
@@ -72,4 +102,7 @@ export type RevokeWithProofParams = {
|
|
|
72
102
|
reset: true;
|
|
73
103
|
log: ControllerLog;
|
|
74
104
|
};
|
|
75
|
-
export
|
|
105
|
+
export type RevokeWithProofParams = {
|
|
106
|
+
group: GroupHandle;
|
|
107
|
+
} & RevokeProofInput;
|
|
108
|
+
export declare function revokeWithProof({ group, ...params }: RevokeWithProofParams): Promise<RevokeBuildResult>;
|
package/lib/group-lifecycle.js
CHANGED
|
@@ -15,19 +15,39 @@ 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 function controllerLogDelta(group, log) {
|
|
18
|
+
export async function controllerLogDelta({ group, log }) {
|
|
19
19
|
const controller = group.anchor.controller;
|
|
20
20
|
if (controller == null) throw new RevokeProofError('wrong-controller');
|
|
21
|
-
const
|
|
21
|
+
const options = {
|
|
22
|
+
crypto: group.crypto
|
|
23
|
+
};
|
|
24
|
+
const recorded = recordedLogOf({
|
|
25
|
+
registry: group.registry,
|
|
26
|
+
controller
|
|
27
|
+
});
|
|
22
28
|
if (recorded == null) throw new RevokeProofError('detached');
|
|
23
29
|
const first = log.chain[0]?.event;
|
|
24
30
|
if (first == null) throw new RevokeProofError('no-rev');
|
|
25
31
|
if (first.t === 'icp' && normalizeDID(didFromInception(first)) !== normalizeDID(controller) || log.chain.some(({ event })=>event.t !== 'icp' && (event.i == null || normalizeDID(event.i) !== normalizeDID(controller)))) throw new RevokeProofError('wrong-controller');
|
|
26
|
-
const folded = foldControllerLog(controller, log);
|
|
32
|
+
const folded = await foldControllerLog(controller, log, options);
|
|
27
33
|
if (!folded.ok) throw new RevokeProofError(isDetachedFoldReason(folded.reason) ? 'detached' : 'not-authority-signed');
|
|
28
|
-
const pruned = pruneLog(
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
const pruned = await pruneLog({
|
|
35
|
+
...options,
|
|
36
|
+
did: controller,
|
|
37
|
+
input: log
|
|
38
|
+
});
|
|
39
|
+
const incoming = await ingestControllerLog({
|
|
40
|
+
controller,
|
|
41
|
+
recorded: undefined,
|
|
42
|
+
proof: pruned,
|
|
43
|
+
...options
|
|
44
|
+
});
|
|
45
|
+
const previous = await ingestControllerLog({
|
|
46
|
+
controller,
|
|
47
|
+
recorded: undefined,
|
|
48
|
+
proof: recorded,
|
|
49
|
+
...options
|
|
50
|
+
});
|
|
31
51
|
const reset = incoming.after.head.gen > previous.after.head.gen;
|
|
32
52
|
const merged = incoming.log;
|
|
33
53
|
const common = reset ? 1 : Math.min(recorded.chain.length, merged.chain.length);
|
|
@@ -42,25 +62,48 @@ export function controllerLogDelta(group, log) {
|
|
|
42
62
|
events: merged.events.filter(({ event })=>!seen.has(digestOf(event)))
|
|
43
63
|
};
|
|
44
64
|
if (delta.chain.length === 0 && delta.events.length === 0) return null;
|
|
45
|
-
ingestControllerLog(
|
|
65
|
+
await ingestControllerLog({
|
|
66
|
+
controller,
|
|
67
|
+
recorded,
|
|
68
|
+
proof: delta,
|
|
69
|
+
...options
|
|
70
|
+
});
|
|
46
71
|
return delta;
|
|
47
72
|
}
|
|
48
|
-
export async function publishControllerLog(group, log) {
|
|
73
|
+
export async function publishControllerLog({ group, log }) {
|
|
49
74
|
return mutexFor(group).run(async ()=>{
|
|
50
|
-
const delta = controllerLogDelta(
|
|
75
|
+
const delta = await controllerLogDelta({
|
|
76
|
+
group,
|
|
77
|
+
log
|
|
78
|
+
});
|
|
51
79
|
if (delta == null) return null;
|
|
52
80
|
const controller = group.anchor.controller;
|
|
53
81
|
if (controller == null) throw new RevokeProofError('wrong-controller');
|
|
54
|
-
const ingested = ingestControllerLog(
|
|
55
|
-
|
|
82
|
+
const ingested = await ingestControllerLog({
|
|
83
|
+
controller,
|
|
84
|
+
recorded: recordedLogOf({
|
|
85
|
+
registry: group.registry,
|
|
86
|
+
controller
|
|
87
|
+
}),
|
|
88
|
+
proof: delta,
|
|
89
|
+
previous: group.registry.controllers.get(normalizeDID(controller)),
|
|
90
|
+
crypto: group.crypto
|
|
91
|
+
});
|
|
92
|
+
const effects = effectDelta({
|
|
93
|
+
before: ingested.before?.head,
|
|
94
|
+
after: ingested.after.head
|
|
95
|
+
});
|
|
56
96
|
if (effects.generation || effects.denied.length > 0 || effects.removed.length > 0) throw new RevokeProofError('effects-mismatch');
|
|
57
|
-
const token = await signLedgerEntry(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
97
|
+
const token = await signLedgerEntry({
|
|
98
|
+
identity: ownIdentity(group),
|
|
99
|
+
entry: {
|
|
100
|
+
type: DEVICE_ENTRY_TYPE,
|
|
101
|
+
groupID: group.groupID,
|
|
102
|
+
subject: controller,
|
|
103
|
+
value: {
|
|
104
|
+
op: 'log',
|
|
105
|
+
proof: delta
|
|
106
|
+
}
|
|
64
107
|
}
|
|
65
108
|
});
|
|
66
109
|
return buildResult({
|
|
@@ -96,7 +139,7 @@ export async function publishControllerLog(group, log) {
|
|
|
96
139
|
enacted: tokens,
|
|
97
140
|
requireAdmin: false
|
|
98
141
|
});
|
|
99
|
-
const newGroup = deriveGroup(group, result.newState);
|
|
142
|
+
const newGroup = await deriveGroup(group, result.newState);
|
|
100
143
|
await newGroup.applyLedgerEntries(result.enacted);
|
|
101
144
|
return {
|
|
102
145
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
@@ -109,44 +152,61 @@ function ownIdentity(group) {
|
|
|
109
152
|
const leaf = leafAt(group.state.ratchetTree, group.state.privatePath.leafIndex);
|
|
110
153
|
if (leaf == null || !('identity' in leaf.credential)) throw new LeafBindingError('identity-change');
|
|
111
154
|
const parsed = parseMLSCredentialIdentity(leaf.credential.identity);
|
|
112
|
-
return createSigningIdentityForDID(
|
|
155
|
+
return createSigningIdentityForDID({
|
|
156
|
+
id: parsed.longForm ?? parsed.id,
|
|
157
|
+
privateKey: group.state.signaturePrivateKey,
|
|
158
|
+
crypto: group.crypto
|
|
159
|
+
});
|
|
113
160
|
}
|
|
114
|
-
export async function preservationClock(group, candidateTree, candidateRegistry) {
|
|
161
|
+
export async function preservationClock({ group, candidateTree, candidateRegistry }) {
|
|
115
162
|
const controller = group.anchor.controller;
|
|
116
163
|
if (controller == null) return [];
|
|
117
|
-
const before = treeTime(group, controller);
|
|
118
|
-
if (attestedTreeTime(
|
|
164
|
+
const before = await treeTime(group, controller);
|
|
165
|
+
if (await attestedTreeTime({
|
|
166
|
+
tree: candidateTree,
|
|
167
|
+
registry: candidateRegistry,
|
|
168
|
+
controllerID: controller,
|
|
169
|
+
crypto: group.crypto
|
|
170
|
+
}) >= before) return [];
|
|
119
171
|
return [
|
|
120
|
-
await signLedgerEntry(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
172
|
+
await signLedgerEntry({
|
|
173
|
+
identity: ownIdentity(group),
|
|
174
|
+
entry: {
|
|
175
|
+
type: DEVICE_ENTRY_TYPE,
|
|
176
|
+
groupID: group.groupID,
|
|
177
|
+
subject: controller,
|
|
178
|
+
value: {
|
|
179
|
+
op: 'clock',
|
|
180
|
+
time: before
|
|
181
|
+
}
|
|
127
182
|
}
|
|
128
183
|
})
|
|
129
184
|
];
|
|
130
185
|
}
|
|
131
|
-
export async function attestTreeTime(group, time = Date.now() / 1000) {
|
|
186
|
+
export async function attestTreeTime({ group, time = Date.now() / 1000 }) {
|
|
132
187
|
return mutexFor(group).run(async ()=>{
|
|
133
188
|
const controller = group.anchor.controller;
|
|
134
189
|
if (controller == null) return null;
|
|
135
190
|
const projection = group.registry.controllers.get(normalizeDID(controller));
|
|
136
191
|
if (projection?.recordedLog == null) return null;
|
|
137
|
-
const folded = foldControllerLog(controller, projection.recordedLog
|
|
192
|
+
const folded = await foldControllerLog(controller, projection.recordedLog, {
|
|
193
|
+
crypto: group.crypto
|
|
194
|
+
});
|
|
138
195
|
if (!folded.ok || folded.head.saturated) return null;
|
|
139
196
|
const members = effectiveAttestingMembers(folded.head, projection, time).filter(([, member])=>normalizeDID(member.did) === normalizeDID(group.credential.id));
|
|
140
197
|
if (members.length === 0) return null;
|
|
141
198
|
if (members.every(([, member])=>time <= (projection.attestations.get(member.key) ?? 0))) return null;
|
|
142
|
-
const token = await signLedgerEntry(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
199
|
+
const token = await signLedgerEntry({
|
|
200
|
+
identity: ownIdentity(group),
|
|
201
|
+
entry: {
|
|
202
|
+
type: DEVICE_ENTRY_TYPE,
|
|
203
|
+
groupID: group.groupID,
|
|
204
|
+
subject: controller,
|
|
205
|
+
value: {
|
|
206
|
+
op: 'clock',
|
|
207
|
+
time,
|
|
208
|
+
attest: true
|
|
209
|
+
}
|
|
150
210
|
}
|
|
151
211
|
});
|
|
152
212
|
return buildResult({
|
|
@@ -170,7 +230,7 @@ async function buildResult(params) {
|
|
|
170
230
|
// MLS captured the replacement tree as historical data when building a renewal.
|
|
171
231
|
const historical = result.newState.historicalReceiverData.get(group.epoch);
|
|
172
232
|
if (historical != null && commitState != null) historical.ratchetTree = group.state.ratchetTree;
|
|
173
|
-
const newGroup = deriveGroup(group, result.newState);
|
|
233
|
+
const newGroup = await deriveGroup(group, result.newState);
|
|
174
234
|
await newGroup.applyLedgerEntries(result.enacted);
|
|
175
235
|
return {
|
|
176
236
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
@@ -178,7 +238,7 @@ async function buildResult(params) {
|
|
|
178
238
|
epoch: newGroup.epoch
|
|
179
239
|
};
|
|
180
240
|
}
|
|
181
|
-
export async function renewLeaf(group, binding, options) {
|
|
241
|
+
export async function renewLeaf({ group, binding, ...options }) {
|
|
182
242
|
return mutexFor(group).run(async ()=>{
|
|
183
243
|
assertBindingAuthorTime(binding);
|
|
184
244
|
const index = group.state.privatePath.leafIndex * 2;
|
|
@@ -197,20 +257,30 @@ export async function renewLeaf(group, binding, options) {
|
|
|
197
257
|
const tokens = [];
|
|
198
258
|
let candidate = group.registry;
|
|
199
259
|
if (options?.controllerLog != null) {
|
|
200
|
-
const delta = controllerLogDelta(
|
|
260
|
+
const delta = await controllerLogDelta({
|
|
261
|
+
group,
|
|
262
|
+
log: options.controllerLog
|
|
263
|
+
});
|
|
201
264
|
if (delta != null) {
|
|
202
|
-
const token = await signLedgerEntry(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
265
|
+
const token = await signLedgerEntry({
|
|
266
|
+
identity: ownIdentity(group),
|
|
267
|
+
entry: {
|
|
268
|
+
type: DEVICE_ENTRY_TYPE,
|
|
269
|
+
groupID: group.groupID,
|
|
270
|
+
subject: binding.id,
|
|
271
|
+
value: {
|
|
272
|
+
op: 'log',
|
|
273
|
+
proof: delta
|
|
274
|
+
}
|
|
209
275
|
}
|
|
210
276
|
});
|
|
211
|
-
const verified = await verifyLedgerEntry(
|
|
277
|
+
const verified = await verifyLedgerEntry({
|
|
278
|
+
token,
|
|
279
|
+
crypto: group.crypto
|
|
280
|
+
});
|
|
212
281
|
if (verified == null) throw new Error('Invalid authored log entry');
|
|
213
|
-
const folded = foldEnvelope({
|
|
282
|
+
const folded = await foldEnvelope({
|
|
283
|
+
crypto: group.crypto,
|
|
214
284
|
baseRoster: group.roster,
|
|
215
285
|
baseRegistry: group.registry,
|
|
216
286
|
entries: [
|
|
@@ -237,8 +307,14 @@ export async function renewLeaf(group, binding, options) {
|
|
|
237
307
|
});
|
|
238
308
|
if (group.anchor.controller != null) {
|
|
239
309
|
const entries = group.ledger.map(({ verified })=>verified);
|
|
240
|
-
const before = historySize(
|
|
241
|
-
|
|
310
|
+
const before = historySize({
|
|
311
|
+
tree: group.state.ratchetTree,
|
|
312
|
+
entries
|
|
313
|
+
});
|
|
314
|
+
const after = historySize({
|
|
315
|
+
tree,
|
|
316
|
+
entries
|
|
317
|
+
});
|
|
242
318
|
if (after > HISTORY_HORIZON && after > before) throw new LeafBindingError('history-horizon');
|
|
243
319
|
}
|
|
244
320
|
return buildResult({
|
|
@@ -258,7 +334,7 @@ export async function removeLapsedLeaves(group) {
|
|
|
258
334
|
const proposals = [];
|
|
259
335
|
for (const member of group.listMembers()){
|
|
260
336
|
const leaf = leafAt(group.state.ratchetTree, member.leafIndex);
|
|
261
|
-
if (leaf == null || !isLapsed(group, leaf)) continue;
|
|
337
|
+
if (leaf == null || !await isLapsed(group, leaf)) continue;
|
|
262
338
|
removed.push(member.id);
|
|
263
339
|
proposals.push({
|
|
264
340
|
proposalType: defaultProposalTypes.remove,
|
|
@@ -289,12 +365,12 @@ function alreadyApplied(group, claims) {
|
|
|
289
365
|
return record?.status === 'revoked' && !isResetOnly(record) && group.findMemberLeafIndex(did) == null;
|
|
290
366
|
});
|
|
291
367
|
}
|
|
292
|
-
export function removalEvidence(controller, log, rmv) {
|
|
368
|
+
export async function removalEvidence({ controller, log, rmv, ...options }) {
|
|
293
369
|
const signed = log.events.find(({ event })=>digestOf(event) === rmv);
|
|
294
370
|
if (signed?.event.t !== 'rmv') return undefined;
|
|
295
|
-
const closure = closureOf(controller, log, [
|
|
371
|
+
const closure = await closureOf(controller, log, [
|
|
296
372
|
rmv
|
|
297
|
-
]);
|
|
373
|
+
], options);
|
|
298
374
|
if (closure == null) return undefined;
|
|
299
375
|
return {
|
|
300
376
|
controller: normalizeDID(controller),
|
|
@@ -302,34 +378,42 @@ export function removalEvidence(controller, log, rmv) {
|
|
|
302
378
|
closure
|
|
303
379
|
};
|
|
304
380
|
}
|
|
305
|
-
export function survivorTargets(group, add) {
|
|
381
|
+
export async function survivorTargets({ group, add }) {
|
|
306
382
|
const controller = group.anchor.controller;
|
|
307
383
|
if (controller == null) return [];
|
|
308
|
-
|
|
384
|
+
const descendants = [];
|
|
385
|
+
for (const { id } of group.listMembers()){
|
|
309
386
|
const binding = group.bindingOfDID(id);
|
|
310
|
-
if (binding?.controller !== normalizeDID(controller) || binding.prefix == null)
|
|
311
|
-
const authority = effectiveAuthorityOf({
|
|
312
|
-
|
|
313
|
-
binding: {
|
|
314
|
-
...binding,
|
|
315
|
-
id: binding.controller,
|
|
316
|
-
prefix: binding.prefix
|
|
317
|
-
},
|
|
318
|
-
leafKey: binding.leafKey
|
|
319
|
-
}, group.registry, controller);
|
|
320
|
-
return 'root' in authority && authority.root.kind === 'member' && authority.root.add === add ? [
|
|
321
|
-
{
|
|
387
|
+
if (binding?.controller !== normalizeDID(controller) || binding.prefix == null) continue;
|
|
388
|
+
const authority = await effectiveAuthorityOf({
|
|
389
|
+
leaf: {
|
|
322
390
|
did: id,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
391
|
+
binding: {
|
|
392
|
+
...binding,
|
|
393
|
+
id: binding.controller,
|
|
394
|
+
prefix: binding.prefix
|
|
395
|
+
},
|
|
396
|
+
leafKey: binding.leafKey
|
|
397
|
+
},
|
|
398
|
+
registry: group.registry,
|
|
399
|
+
controller,
|
|
400
|
+
crypto: group.crypto
|
|
401
|
+
});
|
|
402
|
+
if ('root' in authority && authority.root.kind === 'member' && authority.root.add === add) descendants.push({
|
|
403
|
+
did: id,
|
|
404
|
+
leafKey: binding.leafKey.slice()
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return descendants;
|
|
327
408
|
}
|
|
328
|
-
export async function revokeWithProof(group, params) {
|
|
409
|
+
export async function revokeWithProof({ group, ...params }) {
|
|
329
410
|
return mutexFor(group).run(async ()=>{
|
|
330
411
|
try {
|
|
331
412
|
const controller = group.anchor.controller;
|
|
332
413
|
if (controller == null) throw new RevokeProofError('wrong-controller');
|
|
414
|
+
const options = {
|
|
415
|
+
crypto: group.crypto
|
|
416
|
+
};
|
|
333
417
|
const reset = 'reset' in params;
|
|
334
418
|
const requested = reset ? [] : (params.deny ?? []).map(normalizeDID);
|
|
335
419
|
const removals = reset ? [] : (params.remove ?? []).map(({ did, add })=>({
|
|
@@ -340,26 +424,41 @@ export async function revokeWithProof(group, params) {
|
|
|
340
424
|
if (params.log.chain.length === 0) throw new RevokeProofError('no-rev');
|
|
341
425
|
const projection = group.registry.controllers.get(normalizeDID(controller));
|
|
342
426
|
if (params.log.chain.every(({ event })=>event.g < (projection?.genFloor ?? 0))) throw new RevokeProofError('generation-floor');
|
|
343
|
-
let proof = controllerLogDelta(
|
|
427
|
+
let proof = await controllerLogDelta({
|
|
428
|
+
group,
|
|
429
|
+
log: params.log
|
|
430
|
+
});
|
|
344
431
|
if (!reset && params.evidence != null && proof != null) {
|
|
345
432
|
const evidence = params.evidence.filter((held)=>normalizeDID(held.controller) === normalizeDID(controller) && held.closure.events.some(({ event })=>event.t === 'rmv' && event.e === held.epoch && removals.some(({ add })=>event.add === add)));
|
|
346
|
-
const supplied = mergeLifecycleProofLogs(controller, {
|
|
433
|
+
const supplied = await mergeLifecycleProofLogs(controller, {
|
|
347
434
|
chain: params.log.chain,
|
|
348
435
|
events: proof.events
|
|
349
436
|
}, {
|
|
350
437
|
chain: params.log.chain,
|
|
351
438
|
events: evidence.flatMap(({ closure })=>closure.events)
|
|
352
|
-
});
|
|
439
|
+
}, options);
|
|
353
440
|
proof = {
|
|
354
441
|
...proof,
|
|
355
442
|
events: supplied.events
|
|
356
443
|
};
|
|
357
444
|
}
|
|
358
|
-
const ingested = proof == null ? null : ingestControllerLog(
|
|
445
|
+
const ingested = proof == null ? null : await ingestControllerLog({
|
|
446
|
+
controller,
|
|
447
|
+
recorded: projection?.recordedLog,
|
|
448
|
+
proof,
|
|
449
|
+
previous: projection,
|
|
450
|
+
...options
|
|
451
|
+
});
|
|
359
452
|
if (!reset && ingested != null && ingested.after.head.gen !== ingested.before?.head.gen) throw new RevokeProofError('needs-reset');
|
|
360
453
|
if (!reset) {
|
|
361
454
|
const requestedClaims = [
|
|
362
|
-
...requested.length === 0 || projection?.recordedLog == null ? [] :
|
|
455
|
+
...requested.length === 0 || projection?.recordedLog == null ? [] : (await claimsFor({
|
|
456
|
+
controller,
|
|
457
|
+
recorded: undefined,
|
|
458
|
+
merged: projection.recordedLog,
|
|
459
|
+
genFloor: projection.genFloor,
|
|
460
|
+
...options
|
|
461
|
+
})).filter((claim)=>claim.kind === 'deny' && requested.includes(normalizeDID(claim.did))),
|
|
363
462
|
...removals.flatMap((member)=>{
|
|
364
463
|
const removed = projection?.removedMembers.get(member.add);
|
|
365
464
|
return removed?.did === member.did ? [
|
|
@@ -376,7 +475,13 @@ export async function revokeWithProof(group, params) {
|
|
|
376
475
|
};
|
|
377
476
|
}
|
|
378
477
|
if (proof == null || ingested == null) throw new RevokeProofError('no-rev');
|
|
379
|
-
const effects = claimsFor(
|
|
478
|
+
const effects = await claimsFor({
|
|
479
|
+
controller,
|
|
480
|
+
recorded: projection?.recordedLog,
|
|
481
|
+
merged: await lifecycleProofLog(controller, ingested, proof, options),
|
|
482
|
+
genFloor: projection?.genFloor ?? 0,
|
|
483
|
+
...options
|
|
484
|
+
});
|
|
380
485
|
if (!reset && (requested.some((did)=>!effects.some((claim)=>claim.kind === 'deny' && normalizeDID(claim.did) === did)) || removals.some((member)=>!effects.some((claim)=>claim.kind === 'remove' && claim.member.add === member.add && normalizeDID(claim.member.did) === member.did)))) throw new RevokeProofError('no-rev');
|
|
381
486
|
const value = {
|
|
382
487
|
op: reset ? 'reset' : 'revoke',
|
|
@@ -399,7 +504,7 @@ export async function revokeWithProof(group, params) {
|
|
|
399
504
|
value
|
|
400
505
|
}
|
|
401
506
|
};
|
|
402
|
-
authenticateLifecycleProof(controller, verified, group.registry);
|
|
507
|
+
await authenticateLifecycleProof(controller, verified, group.registry, options);
|
|
403
508
|
const derived = await lifecycleProofEffects(group, verified);
|
|
404
509
|
value.revoked = derived.revoked;
|
|
405
510
|
value.removed = derived.removed;
|
|
@@ -415,7 +520,10 @@ export async function revokeWithProof(group, params) {
|
|
|
415
520
|
}
|
|
416
521
|
}));
|
|
417
522
|
const tokens = [
|
|
418
|
-
await signLedgerEntry(
|
|
523
|
+
await signLedgerEntry({
|
|
524
|
+
identity: ownIdentity(group),
|
|
525
|
+
entry: verified.entry
|
|
526
|
+
})
|
|
419
527
|
];
|
|
420
528
|
return {
|
|
421
529
|
status: 'built',
|
|
@@ -9,6 +9,11 @@ export type RemoveMemberResult = {
|
|
|
9
9
|
* readMessageEpoch). */
|
|
10
10
|
epoch: bigint;
|
|
11
11
|
};
|
|
12
|
+
export type RemoveMemberParams = {
|
|
13
|
+
group: GroupHandle;
|
|
14
|
+
leafIndex: number;
|
|
15
|
+
ledgerEntries?: Array<string>;
|
|
16
|
+
};
|
|
12
17
|
/**
|
|
13
18
|
* Remove a member. Advances the epoch and rotates keys.
|
|
14
19
|
*
|
|
@@ -22,4 +27,4 @@ export type RemoveMemberResult = {
|
|
|
22
27
|
* The mutex only serializes concurrent calls against one handle; it does not make a
|
|
23
28
|
* second commit from a superseded handle safe.
|
|
24
29
|
*/
|
|
25
|
-
export declare function removeMember(group
|
|
30
|
+
export declare function removeMember({ group, leafIndex, ledgerEntries, }: 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 }) {
|
|
17
17
|
return mutexFor(group).run(async ()=>{
|
|
18
18
|
const removeProposal = {
|
|
19
19
|
proposalType: defaultProposalTypes.remove,
|
|
@@ -29,7 +29,7 @@ import { deriveGroup, mutexFor } from './group-handle.js';
|
|
|
29
29
|
],
|
|
30
30
|
enacted
|
|
31
31
|
});
|
|
32
|
-
const newGroup = deriveGroup(group, result.newState);
|
|
32
|
+
const newGroup = await deriveGroup(group, result.newState);
|
|
33
33
|
await newGroup.applyLedgerEntries(result.enacted);
|
|
34
34
|
return {
|
|
35
35
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
package/lib/group-welcome.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export type ProcessWelcomeOnceParams = ProcessWelcomeParams & {
|
|
|
44
44
|
* `joined` is an ordinary first join.
|
|
45
45
|
*/
|
|
46
46
|
export declare function processWelcomeOnce(params: ProcessWelcomeOnceParams): Promise<ProcessWelcomeResult | null>;
|
|
47
|
+
export type JoinGroupExternalParamsBeforeBindingParams = {
|
|
48
|
+
pending: GroupHandle;
|
|
49
|
+
source: GroupHandle;
|
|
50
|
+
};
|
|
47
51
|
export type JoinGroupExternalParams = {
|
|
48
52
|
identity: OwnIdentity;
|
|
49
53
|
/** Framed MLSMessage(GroupInfo) bytes from exportGroupInfo. */
|
|
@@ -59,7 +63,7 @@ export type JoinGroupExternalParams = {
|
|
|
59
63
|
options?: GroupOptions;
|
|
60
64
|
authenticatedData?: Uint8Array;
|
|
61
65
|
/** @internal Judge the attestation before any replacement-binding checks. */
|
|
62
|
-
beforeBinding?: (
|
|
66
|
+
beforeBinding?: (params: JoinGroupExternalParamsBeforeBindingParams) => Promise<void>;
|
|
63
67
|
};
|
|
64
68
|
export type JoinGroupExternalResult = {
|
|
65
69
|
/** Framed MLSMessage(PublicMessage) bytes. Broadcast to existing members. */
|