@kumiai/mls 0.12.4 → 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 +3 -2
- package/lib/group-context.js +6 -2
- 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 +84 -30
- package/lib/group-handle.js +368 -154
- 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 +27 -1
- 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/lifecycle.js
CHANGED
|
@@ -4,7 +4,7 @@ import { defaultCredentialTypes, defaultProposalTypes, isDefaultCredential, isDe
|
|
|
4
4
|
import { LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
|
|
5
5
|
import { checkHolderEvidence, verifyLeafCredential } from './authentication.js';
|
|
6
6
|
import { assertCapabilityLifetime, capabilityKey, MAX_LEAF_LIFETIME, MAX_TRUSTED_GRANT_LIFETIME, readCapability } from './capability.js';
|
|
7
|
-
import { foldChain
|
|
7
|
+
import { foldChain } from './controller-log.js';
|
|
8
8
|
import { parseMLSCredentialIdentity } from './credential.js';
|
|
9
9
|
import { prefixRelation } from './embedded-resolver.js';
|
|
10
10
|
import { LeafBindingError, LeafLapsedError, RevokeProofError } from './errors.js';
|
|
@@ -13,7 +13,7 @@ import { registryAt } from './group-handle.js';
|
|
|
13
13
|
import { decodeLedgerHead } from './head.js';
|
|
14
14
|
import { HISTORY_HORIZON, historySize } from './history.js';
|
|
15
15
|
import { isEvidencedChild, verifyLifecycleProof } from './lifecycle-proof.js';
|
|
16
|
-
import { effectiveAttestingMembers, effectiveAuthorityOf, memberRootStatus, memberRootsOf } from './member-root.js';
|
|
16
|
+
import { effectiveAttestingMembers, effectiveAuthorityOf, memberRootStatus, memberRootsOf, projectionFold } from './member-root.js';
|
|
17
17
|
import { evaluateGroupContextExtensions } from './policy.js';
|
|
18
18
|
import { DEVICE_ENTRY_TYPE, denySetOf, mayReadmitResetDevice, registryApply } from './registry.js';
|
|
19
19
|
import { assertNewerBinding, bindingIssuedAt, stalePairedAdd } from './stale-leaf.js';
|
|
@@ -42,10 +42,10 @@ export function leafAt(tree, index) {
|
|
|
42
42
|
const node = tree[index * 2];
|
|
43
43
|
return node?.nodeType === nodeTypes.leaf ? node.leaf : undefined;
|
|
44
44
|
}
|
|
45
|
-
export function attestedTreeTime(tree, registry, controllerID) {
|
|
45
|
+
export async function attestedTreeTime({ tree, registry, controllerID, ...options }) {
|
|
46
46
|
const controller = normalizeDID(controllerID);
|
|
47
47
|
const projection = registry.controllers.get(controller);
|
|
48
|
-
const folded =
|
|
48
|
+
const folded = await projectionFold(controller, projection, options);
|
|
49
49
|
const head = folded?.ok && !folded.head.saturated ? folded.head : undefined;
|
|
50
50
|
const effective = new Map(effectiveAttestingMembers(head, projection));
|
|
51
51
|
const attestations = new Map();
|
|
@@ -72,55 +72,83 @@ export function attestedTreeTime(tree, registry, controllerID) {
|
|
|
72
72
|
const quorum = times.length === 1 ? times[0] : times[1];
|
|
73
73
|
return Math.max(projection?.timeFloor ?? 0, rootTime, quorum ?? 0);
|
|
74
74
|
}
|
|
75
|
-
export function treeTime(group, controllerID, registry = group.registry) {
|
|
76
|
-
return attestedTreeTime(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
export async function treeTime(group, controllerID, registry = group.registry) {
|
|
76
|
+
return await attestedTreeTime({
|
|
77
|
+
tree: group.state.ratchetTree,
|
|
78
|
+
registry: group.anchor.controller == null ? {
|
|
79
|
+
...registry,
|
|
80
|
+
controllers: new Map()
|
|
81
|
+
} : registry,
|
|
82
|
+
controllerID,
|
|
83
|
+
crypto: group.crypto
|
|
84
|
+
});
|
|
80
85
|
}
|
|
81
|
-
export function isLapsed(group, leaf, registry = group.registry) {
|
|
86
|
+
export async function isLapsed(group, leaf, registry = group.registry) {
|
|
82
87
|
const controller = group.anchor.controller;
|
|
83
88
|
if (controller == null) return false;
|
|
84
89
|
const binding = identity(leaf).controller;
|
|
85
|
-
const expiry = binding == null ? undefined : leafExpiry(
|
|
86
|
-
|
|
90
|
+
const expiry = binding == null ? undefined : await leafExpiry({
|
|
91
|
+
binding,
|
|
92
|
+
registry,
|
|
93
|
+
controller,
|
|
94
|
+
crypto: group.crypto
|
|
95
|
+
});
|
|
96
|
+
return expiry != null && expiry < await treeTime(group, controller, registry);
|
|
87
97
|
}
|
|
88
|
-
export function leafExpiry(binding, registry, controller) {
|
|
98
|
+
export async function leafExpiry({ binding, registry, controller, ...options }) {
|
|
89
99
|
const did = normalizeDID(controller);
|
|
90
100
|
const projection = registry.controllers.get(did);
|
|
91
101
|
if (binding.member == null) {
|
|
92
102
|
if (binding.capability == null) throw new LeafBindingError('controller-mismatch');
|
|
93
103
|
const { payload } = readCapability(binding.capability);
|
|
94
|
-
const authority = effectiveAuthorityOf({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
const authority = await effectiveAuthorityOf({
|
|
105
|
+
leaf: {
|
|
106
|
+
did: payload.aud,
|
|
107
|
+
binding,
|
|
108
|
+
leafKey: capabilityKey(payload).publicKey
|
|
109
|
+
},
|
|
110
|
+
registry,
|
|
111
|
+
controller,
|
|
112
|
+
...options
|
|
113
|
+
});
|
|
99
114
|
return 'root' in authority && authority.expiry != null ? Math.min(payload.exp, authority.expiry) : payload.exp;
|
|
100
115
|
}
|
|
101
116
|
if (normalizeDID(binding.id) !== did) return undefined;
|
|
102
117
|
const log = projection?.recordedLog;
|
|
103
|
-
if (log == null || prefixRelation(
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
if (log == null || prefixRelation({
|
|
119
|
+
recorded: log,
|
|
120
|
+
prefix: binding.prefix
|
|
121
|
+
}) !== 'contained') return undefined;
|
|
122
|
+
const folded = await projectionFold(did, projection, options);
|
|
123
|
+
if (!folded?.ok) return undefined;
|
|
106
124
|
const member = folded.head.members.get(binding.member.add);
|
|
107
125
|
const memberDID = member?.did ?? projection?.removedMembers.get(binding.member.add)?.did;
|
|
108
126
|
if (memberDID == null) return undefined;
|
|
109
127
|
const survivor = projection?.survivorGrants.get(normalizeDID(memberDID));
|
|
110
128
|
const leafKey = member == null ? survivor == null ? undefined : capabilityKey(readCapability(survivor).payload).publicKey : decodeKey(member.key).publicKey;
|
|
111
129
|
if (leafKey != null) {
|
|
112
|
-
const authority = effectiveAuthorityOf({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
const authority = await effectiveAuthorityOf({
|
|
131
|
+
leaf: {
|
|
132
|
+
did: memberDID,
|
|
133
|
+
binding,
|
|
134
|
+
leafKey
|
|
135
|
+
},
|
|
136
|
+
registry,
|
|
137
|
+
controller,
|
|
138
|
+
...options
|
|
139
|
+
});
|
|
117
140
|
if ('root' in authority && authority.expiry != null) return authority.expiry;
|
|
118
141
|
}
|
|
119
|
-
const status = memberRootStatus(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
142
|
+
const status = await memberRootStatus({
|
|
143
|
+
registry,
|
|
144
|
+
controller: did,
|
|
145
|
+
root: {
|
|
146
|
+
kind: 'member',
|
|
147
|
+
did: memberDID,
|
|
148
|
+
add: binding.member.add,
|
|
149
|
+
gen: binding.member.g
|
|
150
|
+
},
|
|
151
|
+
...options
|
|
124
152
|
});
|
|
125
153
|
return status.status === 'effective' ? status.lease : undefined;
|
|
126
154
|
}
|
|
@@ -143,7 +171,7 @@ function credentialEqual(a, b) {
|
|
|
143
171
|
const current = readCapability(old.capability).payload;
|
|
144
172
|
return current.cap !== undefined && group.registry.devices.get(normalizeDID(current.iss))?.status === 'revoked';
|
|
145
173
|
}
|
|
146
|
-
function checkBinding(group, leaf, previous, /** The leaf arrives in a Welcome tree rather than as an entry. */ welcome = false, judging = {
|
|
174
|
+
async function checkBinding(group, leaf, previous, /** The leaf arrives in a Welcome tree rather than as an entry. */ welcome = false, judging = {
|
|
147
175
|
registry: group.registry,
|
|
148
176
|
stage: 'full',
|
|
149
177
|
mode: 'admit'
|
|
@@ -153,11 +181,16 @@ function checkBinding(group, leaf, previous, /** The leaf arrives in a Welcome t
|
|
|
153
181
|
const controller = group.anchor.controller;
|
|
154
182
|
if (controller != null && binding == null) throw new LeafBindingError('floating-refused');
|
|
155
183
|
if (controller != null && binding != null && normalizeDID(binding.id) !== normalizeDID(controller)) throw new LeafBindingError('controller-mismatch');
|
|
156
|
-
if (controller == null && binding != null && memberRootsOf(
|
|
184
|
+
if (controller == null && binding != null && memberRootsOf({
|
|
185
|
+
binding,
|
|
186
|
+
leafDID: parsed.id
|
|
187
|
+
}).some(({ root })=>root.kind === 'member')) throw new LeafBindingError('controller-mismatch');
|
|
157
188
|
const registry = judging.registry;
|
|
158
189
|
const full = judging.stage === 'full';
|
|
159
190
|
const denied = full && registry != null ? denySetOf(registry) : new Set();
|
|
160
|
-
if (denied.has(normalizeDID(parsed.id)) && !mayReadmitResetDevice(registry ?? group.registry, parsed
|
|
191
|
+
if (denied.has(normalizeDID(parsed.id)) && !await mayReadmitResetDevice(registry ?? group.registry, parsed, {
|
|
192
|
+
crypto: group.crypto
|
|
193
|
+
})) throw new LeafBindingError('denied-id');
|
|
161
194
|
const record = full ? registry?.devices.get(normalizeDID(parsed.id)) : undefined;
|
|
162
195
|
if (record != null && (binding == null || normalizeDID(binding.id) !== record.controller)) throw new LeafBindingError('controller-mismatch');
|
|
163
196
|
if (previous != null) {
|
|
@@ -175,32 +208,40 @@ function checkBinding(group, leaf, previous, /** The leaf arrives in a Welcome t
|
|
|
175
208
|
if (parent != null) assertCapabilityLifetime(readCapability(parent).payload, controller == null ? MAX_TRUSTED_GRANT_LIFETIME : group.anchor.trustedGrantLifetime ?? 2_592_000);
|
|
176
209
|
if (payload.cap != null && denied.has(normalizeDID(payload.iss)) && !((welcome || judging.mode === 'retain') && isEvidencedChild(group, leaf, denied))) throw new LeafBindingError('denied-issuer');
|
|
177
210
|
}
|
|
178
|
-
const folded = foldChain(binding.id, binding.prefix
|
|
211
|
+
const folded = await foldChain(binding.id, binding.prefix, {
|
|
212
|
+
crypto: group.crypto
|
|
213
|
+
});
|
|
179
214
|
if (!folded.ok) throw new LeafBindingError('controller-mismatch');
|
|
180
215
|
if (full && controller != null && (folded.states.at(-1)?.gen ?? 0) < (registry?.controllers.get(normalizeDID(controller))?.genFloor ?? 0)) throw new LeafBindingError('generation-floor');
|
|
181
216
|
}
|
|
182
|
-
function checkAdmissionExpiry(group, leaf, registry = group.registry) {
|
|
217
|
+
async function checkAdmissionExpiry(group, leaf, registry = group.registry) {
|
|
183
218
|
const binding = identity(leaf).controller;
|
|
184
219
|
if (binding == null) return;
|
|
185
|
-
const expiry = leafExpiry(
|
|
220
|
+
const expiry = await leafExpiry({
|
|
221
|
+
binding,
|
|
222
|
+
registry,
|
|
223
|
+
controller: binding.id,
|
|
224
|
+
crypto: group.crypto
|
|
225
|
+
});
|
|
186
226
|
if (expiry == null) throw new LeafBindingError('member-unavailable');
|
|
187
|
-
if (expiry <= treeTime(group, binding.id, registry)) throw new LeafLapsedError('lapsed');
|
|
227
|
+
if (expiry <= await treeTime(group, binding.id, registry)) throw new LeafLapsedError('lapsed');
|
|
188
228
|
}
|
|
189
|
-
function checkEntry(group, leaf, previous, judging = {
|
|
229
|
+
async function checkEntry(group, leaf, previous, judging = {
|
|
190
230
|
registry: group.registry,
|
|
191
231
|
stage: 'full',
|
|
192
232
|
mode: 'admit'
|
|
193
233
|
}) {
|
|
194
|
-
checkBinding(group, leaf, previous, false, judging);
|
|
195
|
-
if (judging.mode === 'admit') checkAdmissionExpiry(group, leaf, judging.registry);
|
|
234
|
+
await checkBinding(group, leaf, previous, false, judging);
|
|
235
|
+
if (judging.mode === 'admit') await checkAdmissionExpiry(group, leaf, judging.registry);
|
|
196
236
|
}
|
|
197
237
|
async function validateBoundLeaf(group, leaf, previous, welcome = false, judging = {
|
|
198
238
|
registry: group.registry,
|
|
199
239
|
stage: 'full',
|
|
200
240
|
mode: 'admit'
|
|
201
241
|
}) {
|
|
202
|
-
checkBinding(group, leaf, previous, welcome, judging);
|
|
242
|
+
await checkBinding(group, leaf, previous, welcome, judging);
|
|
203
243
|
await verifyLeafCredential(leaf.credential, leaf.signaturePublicKey, {
|
|
244
|
+
crypto: group.crypto,
|
|
204
245
|
judging: ()=>({
|
|
205
246
|
...judging,
|
|
206
247
|
registry: group.anchor.controller == null ? undefined : judging.registry
|
|
@@ -217,19 +258,22 @@ export async function validateEntry(group, leaf, previous, judging = {
|
|
|
217
258
|
mode: 'admit'
|
|
218
259
|
}) {
|
|
219
260
|
await validateBoundLeaf(group, leaf, previous, false, judging);
|
|
220
|
-
if (judging.mode === 'admit') checkAdmissionExpiry(group, leaf, judging.registry);
|
|
261
|
+
if (judging.mode === 'admit') await checkAdmissionExpiry(group, leaf, judging.registry);
|
|
221
262
|
}
|
|
222
263
|
/** The same credential and key a tree already holds at that leaf index. */ export function isUnchangedLeaf(tree, index, leaf) {
|
|
223
264
|
const held = leafAt(tree, index);
|
|
224
265
|
return held != null && credentialEqual(held, leaf) && bytesEqual(held.signaturePublicKey, leaf.signaturePublicKey);
|
|
225
266
|
}
|
|
226
|
-
function checkSurvivors(group, tree, registry, origin) {
|
|
267
|
+
async function checkSurvivors(group, tree, registry, origin) {
|
|
227
268
|
const denied = denySetOf(registry);
|
|
228
269
|
const controller = group.anchor.controller;
|
|
270
|
+
const options = {
|
|
271
|
+
crypto: group.crypto
|
|
272
|
+
};
|
|
229
273
|
for (const [position, node] of tree.entries()){
|
|
230
274
|
if (node?.nodeType !== nodeTypes.leaf) continue;
|
|
231
275
|
const parsed = identity(node.leaf);
|
|
232
|
-
if (denied.has(normalizeDID(parsed.id)) && !mayReadmitResetDevice(registry, parsed)) throw new LeafBindingError('denied-id');
|
|
276
|
+
if (denied.has(normalizeDID(parsed.id)) && !await mayReadmitResetDevice(registry, parsed, options)) throw new LeafBindingError('denied-id');
|
|
233
277
|
if (parsed.controller == null) {
|
|
234
278
|
if (controller != null) throw new LeafBindingError('floating-refused');
|
|
235
279
|
continue;
|
|
@@ -238,14 +282,19 @@ function checkSurvivors(group, tree, registry, origin) {
|
|
|
238
282
|
const payload = binding.member != null || binding.capability == null ? undefined : readCapability(binding.capability).payload;
|
|
239
283
|
if (payload?.cap != null && denied.has(normalizeDID(payload.iss)) && !((origin.kind === 'welcome' || position % 2 === 0 && isUnchangedLeaf(origin.before, position / 2, node.leaf)) && isEvidencedChild(group, node.leaf, denied))) throw new LeafBindingError('denied-issuer');
|
|
240
284
|
if (controller != null) {
|
|
241
|
-
const folded = foldChain(binding.id, binding.prefix);
|
|
285
|
+
const folded = await foldChain(binding.id, binding.prefix, options);
|
|
242
286
|
if (normalizeDID(binding.id) !== normalizeDID(controller) || !folded.ok) throw new LeafBindingError('controller-mismatch');
|
|
243
287
|
if ((folded.states.at(-1)?.gen ?? 0) < (registry.controllers.get(normalizeDID(controller))?.genFloor ?? 0)) throw new LeafBindingError('generation-floor');
|
|
244
|
-
const authority = effectiveAuthorityOf({
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
288
|
+
const authority = await effectiveAuthorityOf({
|
|
289
|
+
leaf: {
|
|
290
|
+
did: parsed.id,
|
|
291
|
+
binding,
|
|
292
|
+
leafKey: node.leaf.signaturePublicKey
|
|
293
|
+
},
|
|
294
|
+
registry,
|
|
295
|
+
controller,
|
|
296
|
+
...options
|
|
297
|
+
});
|
|
249
298
|
if ('status' in authority && authority.status === 'removed') throw new LeafBindingError('member-removed');
|
|
250
299
|
}
|
|
251
300
|
}
|
|
@@ -258,21 +307,24 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
258
307
|
for (const [index, node] of group.state.ratchetTree.entries()){
|
|
259
308
|
if (node?.nodeType !== nodeTypes.leaf) continue;
|
|
260
309
|
await validateBoundLeaf(group, node.leaf, undefined, true, judging);
|
|
261
|
-
if (judging.stage === 'full' && index === group.state.privatePath.leafIndex * 2) checkAdmissionExpiry(group, node.leaf, judging.registry);
|
|
310
|
+
if (judging.stage === 'full' && index === group.state.privatePath.leafIndex * 2) await checkAdmissionExpiry(group, node.leaf, judging.registry);
|
|
262
311
|
}
|
|
263
|
-
if (judging.stage === 'full') checkSurvivors(group, group.state.ratchetTree, judging.registry ?? group.registry, {
|
|
312
|
+
if (judging.stage === 'full') await checkSurvivors(group, group.state.ratchetTree, judging.registry ?? group.registry, {
|
|
264
313
|
kind: 'welcome'
|
|
265
314
|
});
|
|
266
315
|
}
|
|
267
316
|
/** The callback judges proposals; survivors check the path before any state is installed. */ export async function prepareLifecycleGate(params) {
|
|
268
317
|
const { group, entries, candidateRegistry, context, externalLeaf } = params;
|
|
269
318
|
const controller = group.anchor.controller;
|
|
319
|
+
const options = {
|
|
320
|
+
crypto: group.crypto
|
|
321
|
+
};
|
|
270
322
|
if (controller == null) {
|
|
271
323
|
for (const { entry, issuer } of entries){
|
|
272
324
|
if (entry.type !== DEVICE_ENTRY_TYPE) continue;
|
|
273
325
|
const capability = entry.value.capability;
|
|
274
326
|
const binding = group.bindingOfDID(issuer);
|
|
275
|
-
if (capability != null && binding?.controller != null && readCapability(capability).payload.exp < treeTime(group, binding.controller, candidateRegistry)) throw new LeafLapsedError('lapsed');
|
|
327
|
+
if (capability != null && binding?.controller != null && readCapability(capability).payload.exp < await treeTime(group, binding.controller, candidateRegistry)) throw new LeafLapsedError('lapsed');
|
|
276
328
|
}
|
|
277
329
|
}
|
|
278
330
|
const before = group.state.ratchetTree;
|
|
@@ -281,14 +333,22 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
281
333
|
...ledger,
|
|
282
334
|
...entries
|
|
283
335
|
];
|
|
284
|
-
const beforeSize = controller == null ? 0 : historySize(
|
|
285
|
-
|
|
336
|
+
const beforeSize = controller == null ? 0 : historySize({
|
|
337
|
+
tree: before,
|
|
338
|
+
entries: ledger
|
|
339
|
+
});
|
|
340
|
+
const beforeTime = controller == null ? 0 : await treeTime(group, controller);
|
|
286
341
|
const lapsed = new Set();
|
|
287
342
|
if (controller != null) {
|
|
288
343
|
for(let index = 0; index * 2 < before.length; index++){
|
|
289
344
|
const leaf = leafAt(before, index);
|
|
290
345
|
const binding = leaf == null ? undefined : identity(leaf).controller;
|
|
291
|
-
const expiry = binding == null ? undefined : leafExpiry(
|
|
346
|
+
const expiry = binding == null ? undefined : await leafExpiry({
|
|
347
|
+
binding,
|
|
348
|
+
registry: group.registry,
|
|
349
|
+
controller,
|
|
350
|
+
...options
|
|
351
|
+
});
|
|
292
352
|
if (expiry != null && expiry < beforeTime) lapsed.add(index);
|
|
293
353
|
}
|
|
294
354
|
}
|
|
@@ -316,7 +376,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
316
376
|
for (const entry of lifecycleEntries){
|
|
317
377
|
const verified = entry;
|
|
318
378
|
const effects = await verifyLifecycleProof(group, verified, registry);
|
|
319
|
-
registry = registryApply(verified, registry, controller);
|
|
379
|
+
registry = await registryApply(verified, registry, controller, options);
|
|
320
380
|
if ([
|
|
321
381
|
'revoke',
|
|
322
382
|
'reset'
|
|
@@ -332,12 +392,20 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
332
392
|
let incomingCommit;
|
|
333
393
|
function checkSize(tree) {
|
|
334
394
|
if (controller == null) return;
|
|
335
|
-
const size = historySize(
|
|
395
|
+
const size = historySize({
|
|
396
|
+
tree,
|
|
397
|
+
entries: afterLedger
|
|
398
|
+
});
|
|
336
399
|
if (size > HISTORY_HORIZON && size > beforeSize) throw new LeafBindingError('history-horizon');
|
|
337
400
|
}
|
|
338
|
-
function checkTime(tree) {
|
|
401
|
+
async function checkTime(tree) {
|
|
339
402
|
if (controller == null) return;
|
|
340
|
-
if (attestedTreeTime(
|
|
403
|
+
if (await attestedTreeTime({
|
|
404
|
+
tree,
|
|
405
|
+
registry: candidateRegistry,
|
|
406
|
+
controllerID: controller,
|
|
407
|
+
...options
|
|
408
|
+
}) < beforeTime) throw new RevokeProofError('time-regression');
|
|
341
409
|
}
|
|
342
410
|
function checkRegistryAdds(proposals) {
|
|
343
411
|
for (const { entry } of entries){
|
|
@@ -356,7 +424,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
356
424
|
}
|
|
357
425
|
}
|
|
358
426
|
}
|
|
359
|
-
const check = (incoming)=>{
|
|
427
|
+
const check = async (incoming)=>{
|
|
360
428
|
const proposals = incoming.kind === 'commit' ? incoming.proposals : [
|
|
361
429
|
incoming.proposal
|
|
362
430
|
];
|
|
@@ -370,13 +438,13 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
370
438
|
if (remove == null || !isDefaultProposal(remove) || remove.proposalType !== defaultProposalTypes.remove) throw new Error('Missing replacement target');
|
|
371
439
|
const old = leafAt(before, remove.remove.removed);
|
|
372
440
|
if (old == null) throw new LeafBindingError('identity-change');
|
|
373
|
-
checkEntry(group, externalLeaf, old, judging(remove.remove.removed, externalLeaf));
|
|
441
|
+
await checkEntry(group, externalLeaf, old, judging(remove.remove.removed, externalLeaf));
|
|
374
442
|
const tree = before.slice();
|
|
375
443
|
tree[remove.remove.removed * 2] = {
|
|
376
444
|
nodeType: nodeTypes.leaf,
|
|
377
445
|
leaf: externalLeaf
|
|
378
446
|
};
|
|
379
|
-
checkTime(tree);
|
|
447
|
+
await checkTime(tree);
|
|
380
448
|
checkSize(tree);
|
|
381
449
|
return;
|
|
382
450
|
}
|
|
@@ -396,7 +464,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
396
464
|
switch(proposal.proposalType){
|
|
397
465
|
case defaultProposalTypes.add:
|
|
398
466
|
{
|
|
399
|
-
checkEntry(group, proposal.add.keyPackage.leafNode, undefined, judging(undefined, proposal.add.keyPackage.leafNode));
|
|
467
|
+
await checkEntry(group, proposal.add.keyPackage.leafNode, undefined, judging(undefined, proposal.add.keyPackage.leafNode));
|
|
400
468
|
const parsed = identity(proposal.add.keyPackage.leafNode);
|
|
401
469
|
const record = candidateRegistry.devices.get(normalizeDID(parsed.id));
|
|
402
470
|
if (record != null && (parsed.controller == null || normalizeDID(parsed.controller.id) !== record.controller)) throw new LeafBindingError('controller-mismatch');
|
|
@@ -410,7 +478,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
410
478
|
{
|
|
411
479
|
const old = sender == null ? undefined : leafAt(before, sender);
|
|
412
480
|
if (old == null || sender == null) throw new LeafBindingError('identity-change');
|
|
413
|
-
checkEntry(group, proposal.update.leafNode, old, judging(sender, proposal.update.leafNode));
|
|
481
|
+
await checkEntry(group, proposal.update.leafNode, old, judging(sender, proposal.update.leafNode));
|
|
414
482
|
tree[sender * 2] = {
|
|
415
483
|
nodeType: nodeTypes.leaf,
|
|
416
484
|
leaf: proposal.update.leafNode
|
|
@@ -436,7 +504,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
436
504
|
]
|
|
437
505
|
});
|
|
438
506
|
if (replacement != null && old != null) {
|
|
439
|
-
checkEntry(group, replacement, old, judging(target, replacement));
|
|
507
|
+
await checkEntry(group, replacement, old, judging(target, replacement));
|
|
440
508
|
assertNewerBinding(replacement, old);
|
|
441
509
|
}
|
|
442
510
|
if (controller != null && (old == null || !(authorised || replacement != null))) throw new Error('Unauthorised Remove');
|
|
@@ -458,9 +526,9 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
458
526
|
const enactsNonClock = entries.some((verified)=>verified.entry.type !== DEVICE_ENTRY_TYPE || opOf(verified) !== 'clock');
|
|
459
527
|
if (sender != null && lapsed.has(incoming.senderLeafIndex) && (changesMoreThanHead || enactsNonClock)) throw new LeafLapsedError('lapsed');
|
|
460
528
|
}
|
|
461
|
-
if (incoming.kind === 'commit') checkTime(tree);
|
|
529
|
+
if (incoming.kind === 'commit') await checkTime(tree);
|
|
462
530
|
checkSize(tree);
|
|
463
|
-
checkSurvivors(group, tree, candidateRegistry, {
|
|
531
|
+
await checkSurvivors(group, tree, candidateRegistry, {
|
|
464
532
|
kind: 'commit',
|
|
465
533
|
before
|
|
466
534
|
});
|
|
@@ -482,12 +550,17 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
482
550
|
const old = leafAt(before, senderIndex);
|
|
483
551
|
const next = leafAt(state.ratchetTree, senderIndex);
|
|
484
552
|
const binding = next == null ? undefined : identity(next).controller;
|
|
485
|
-
const expiry = binding == null ? undefined : leafExpiry(
|
|
486
|
-
|
|
553
|
+
const expiry = binding == null ? undefined : await leafExpiry({
|
|
554
|
+
binding,
|
|
555
|
+
registry: candidateRegistry,
|
|
556
|
+
controller,
|
|
557
|
+
...options
|
|
558
|
+
});
|
|
559
|
+
if (old != null && lapsed.has(senderIndex) && (next == null || credentialEqual(old, next) || expiry == null || expiry < await treeTime(group, controller, candidateRegistry))) throw new LeafLapsedError('lapsed');
|
|
487
560
|
}
|
|
488
|
-
checkTime(state.ratchetTree);
|
|
561
|
+
await checkTime(state.ratchetTree);
|
|
489
562
|
checkSize(state.ratchetTree);
|
|
490
|
-
checkSurvivors(group, state.ratchetTree, candidateRegistry, {
|
|
563
|
+
await checkSurvivors(group, state.ratchetTree, candidateRegistry, {
|
|
491
564
|
kind: 'commit',
|
|
492
565
|
before
|
|
493
566
|
});
|
|
@@ -497,7 +570,7 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
497
570
|
postApply
|
|
498
571
|
};
|
|
499
572
|
}
|
|
500
|
-
/** Historical messages use the tree and registry authenticated in their own epoch. */ export function assertSenderNotLapsed(params) {
|
|
573
|
+
/** Historical messages use the tree and registry authenticated in their own epoch. */ export async function assertSenderNotLapsed(params) {
|
|
501
574
|
const { group, tree, leafIndex, extensions } = params;
|
|
502
575
|
const controller = group.anchor.controller;
|
|
503
576
|
if (controller == null || leafIndex == null) return;
|
|
@@ -506,10 +579,26 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
506
579
|
const data = extensions.find((extension)=>extension.extensionType === LEDGER_HEAD_EXTENSION_TYPE)?.extensionData;
|
|
507
580
|
const expected = data instanceof Uint8Array ? decodeLedgerHead(data) : null;
|
|
508
581
|
if (expected == null) throw new Error('Missing epoch ledger head');
|
|
509
|
-
const registry = registryAt(
|
|
582
|
+
const registry = await registryAt({
|
|
583
|
+
group,
|
|
584
|
+
head: expected.head
|
|
585
|
+
});
|
|
586
|
+
const options = {
|
|
587
|
+
crypto: group.crypto
|
|
588
|
+
};
|
|
510
589
|
const binding = identity(leaf).controller;
|
|
511
|
-
const expiry = binding == null ? undefined : leafExpiry(
|
|
512
|
-
|
|
590
|
+
const expiry = binding == null ? undefined : await leafExpiry({
|
|
591
|
+
binding,
|
|
592
|
+
registry,
|
|
593
|
+
controller,
|
|
594
|
+
...options
|
|
595
|
+
});
|
|
596
|
+
if (expiry != null && expiry < await attestedTreeTime({
|
|
597
|
+
tree,
|
|
598
|
+
registry,
|
|
599
|
+
controllerID: controller,
|
|
600
|
+
...options
|
|
601
|
+
})) throw new LeafLapsedError('lapsed');
|
|
513
602
|
}
|
|
514
603
|
/** @internal Check a replacement against the complete external admission predicates. */ export async function assertRecoveryBinding(params) {
|
|
515
604
|
const { group, identity: ownIdentity, controller } = params;
|
|
@@ -520,7 +609,10 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
520
609
|
const leaf = {
|
|
521
610
|
...old,
|
|
522
611
|
signaturePublicKey: ownIdentity.publicKey,
|
|
523
|
-
credential: makeMLSCredential(
|
|
612
|
+
credential: makeMLSCredential({
|
|
613
|
+
identity: ownIdentity,
|
|
614
|
+
controller
|
|
615
|
+
})
|
|
524
616
|
};
|
|
525
617
|
await validateEntry(group, leaf, old);
|
|
526
618
|
const tree = group.state.ratchetTree.slice();
|
|
@@ -530,8 +622,19 @@ export async function validateWelcomeTree(group, judging = {
|
|
|
530
622
|
};
|
|
531
623
|
const controllerID = group.anchor.controller;
|
|
532
624
|
if (controllerID == null) return;
|
|
533
|
-
if (attestedTreeTime(
|
|
625
|
+
if (await attestedTreeTime({
|
|
626
|
+
tree,
|
|
627
|
+
registry: group.registry,
|
|
628
|
+
controllerID,
|
|
629
|
+
crypto: group.crypto
|
|
630
|
+
}) < await treeTime(group, controllerID)) throw new RevokeProofError('effects-mismatch');
|
|
534
631
|
const ledger = group.ledger.map(({ verified })=>verified);
|
|
535
|
-
const size = historySize(
|
|
536
|
-
|
|
632
|
+
const size = historySize({
|
|
633
|
+
tree,
|
|
634
|
+
entries: ledger
|
|
635
|
+
});
|
|
636
|
+
if (size > HISTORY_HORIZON && size > historySize({
|
|
637
|
+
tree: group.state.ratchetTree,
|
|
638
|
+
entries: ledger
|
|
639
|
+
})) throw new LeafBindingError('history-horizon');
|
|
537
640
|
}
|
package/lib/member-root.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type ControllerLog, type KeyState, type MemberState } from '@kokuin/controller';
|
|
1
|
+
import { type ControllerLog, type FoldResult, type KeyState, type MemberState } from '@kokuin/controller';
|
|
2
|
+
import { type CryptoOptions } from '@kokuin/token';
|
|
2
3
|
import type { ControllerBinding } from './credential.js';
|
|
3
4
|
import type { ControllerProjection, DeviceRegistry, RevokedEffect } from './registry.js';
|
|
4
5
|
export type MemberRoot = {
|
|
@@ -40,17 +41,33 @@ export type RemovedEffect = {
|
|
|
40
41
|
did: string;
|
|
41
42
|
cascadedFrom: string;
|
|
42
43
|
};
|
|
44
|
+
export type MemberRootsOfParams = {
|
|
45
|
+
binding: ControllerBinding;
|
|
46
|
+
leafDID: string;
|
|
47
|
+
};
|
|
43
48
|
/** Decode only; callers authenticate the tokens and membership references. */
|
|
44
|
-
export declare function memberRootsOf(binding
|
|
49
|
+
export declare function memberRootsOf({ binding, leafDID, }: MemberRootsOfParams): Array<{
|
|
45
50
|
slot: EvidenceSlot;
|
|
46
51
|
root: MemberRoot;
|
|
47
52
|
}>;
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
export type EffectOfParams = {
|
|
54
|
+
controller: string;
|
|
55
|
+
log: ControllerLog;
|
|
56
|
+
claim: EffectClaim;
|
|
57
|
+
genFloor: number;
|
|
58
|
+
} & CryptoOptions;
|
|
59
|
+
export declare function effectOf({ controller, log, claim, genFloor, ...options }: EffectOfParams): Promise<void>;
|
|
60
|
+
export declare function effectProofContext(controller: string, log: ControllerLog, options?: CryptoOptions): Promise<{
|
|
61
|
+
effectOf: (claim: EffectClaim, genFloor: number) => Promise<void>;
|
|
62
|
+
claimsFor: (recorded: ControllerLog | undefined, genFloor: number) => Promise<EffectClaim[]>;
|
|
63
|
+
}>;
|
|
64
|
+
export type ClaimsForParams = {
|
|
65
|
+
controller: string;
|
|
66
|
+
recorded: ControllerLog | undefined;
|
|
67
|
+
merged: ControllerLog;
|
|
68
|
+
genFloor: number;
|
|
69
|
+
} & CryptoOptions;
|
|
70
|
+
export declare function claimsFor({ controller, recorded, merged, genFloor, ...options }: ClaimsForParams): Promise<Array<EffectClaim>>;
|
|
54
71
|
export type MemberRootStatus = {
|
|
55
72
|
status: 'root';
|
|
56
73
|
} | {
|
|
@@ -63,14 +80,29 @@ export type MemberRootStatus = {
|
|
|
63
80
|
status: 'unavailable';
|
|
64
81
|
why: 'no-log' | 'saturated' | 'unknown-incarnation' | 'prefix';
|
|
65
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* The fold of a projection's recorded log, once per log. Lifecycle checks run on every frame, and
|
|
85
|
+
* a fold verifies every signature in the log. Callers must only read the result.
|
|
86
|
+
*/
|
|
87
|
+
export declare function projectionFold(controller: string, projection: ControllerProjection | undefined, options?: CryptoOptions): Promise<FoldResult | undefined>;
|
|
66
88
|
export declare function effectiveAttestingMembers(head: KeyState | undefined, projection: ControllerProjection | undefined, time?: number): Array<[string, MemberState]>;
|
|
67
|
-
export
|
|
89
|
+
export type MemberRootStatusParams = {
|
|
90
|
+
registry: DeviceRegistry;
|
|
91
|
+
controller: string;
|
|
92
|
+
root: MemberRoot;
|
|
93
|
+
} & CryptoOptions;
|
|
94
|
+
export declare function memberRootStatus({ registry, controller, root, ...options }: MemberRootStatusParams): Promise<MemberRootStatus>;
|
|
68
95
|
export type LeafRef = {
|
|
69
96
|
did: string;
|
|
70
97
|
binding: ControllerBinding;
|
|
71
98
|
leafKey: Uint8Array;
|
|
72
99
|
};
|
|
73
|
-
export
|
|
100
|
+
export type EffectiveAuthorityOfParams = {
|
|
101
|
+
leaf: LeafRef;
|
|
102
|
+
registry: DeviceRegistry;
|
|
103
|
+
controller: string;
|
|
104
|
+
} & CryptoOptions;
|
|
105
|
+
export declare function effectiveAuthorityOf({ leaf, registry, controller, ...options }: EffectiveAuthorityOfParams): Promise<{
|
|
74
106
|
root: MemberRoot;
|
|
75
107
|
slot: EvidenceSlot;
|
|
76
108
|
expiry?: number;
|
|
@@ -78,11 +110,18 @@ export declare function effectiveAuthorityOf(leaf: LeafRef, registry: DeviceRegi
|
|
|
78
110
|
status: 'removed';
|
|
79
111
|
} | {
|
|
80
112
|
status: 'unavailable';
|
|
81
|
-
}
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
|
|
113
|
+
}>;
|
|
114
|
+
export type CascadeOfParams = {
|
|
115
|
+
leaves: ReadonlyArray<LeafRef & {
|
|
116
|
+
leafIndex: number;
|
|
117
|
+
}>;
|
|
118
|
+
claims: ReadonlyArray<EffectClaim>;
|
|
119
|
+
before: DeviceRegistry;
|
|
120
|
+
after: DeviceRegistry;
|
|
121
|
+
controller: string;
|
|
122
|
+
} & CryptoOptions;
|
|
123
|
+
export declare function cascadeOf({ leaves, claims, before, after, controller, ...options }: CascadeOfParams): Promise<{
|
|
85
124
|
revoked: Array<RevokedEffect>;
|
|
86
125
|
removed: Array<RemovedEffect>;
|
|
87
126
|
removeLeafIndices: Array<number>;
|
|
88
|
-
}
|
|
127
|
+
}>;
|