@kumiai/mls 0.10.9 → 0.12.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/README.md +29 -1
- package/lib/authentication.d.ts +8 -4
- package/lib/authentication.js +210 -54
- 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 +10 -0
- package/lib/controller-log.js +71 -0
- 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 -15
- package/lib/embedded-resolver.js +53 -16
- 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 +102 -16
- package/lib/group-lifecycle.d.ts +31 -5
- package/lib/group-lifecycle.js +253 -154
- 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 +196 -132
- package/lib/lifecycle.d.ts +9 -6
- package/lib/lifecycle.js +196 -86
- package/lib/member-root.d.ts +88 -0
- package/lib/member-root.js +469 -0
- package/lib/recovery-verdict.d.ts +1 -1
- package/lib/recovery-verdict.js +32 -15
- package/lib/registry.d.ts +17 -6
- package/lib/registry.js +205 -21
- 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/registry.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { digestOf, isControllerLog, resolveBranches } from '@kokuin/controller';
|
|
2
2
|
import { normalizeDID } from '@kokuin/token';
|
|
3
|
+
import { readCapability } from './capability.js';
|
|
4
|
+
import { ingestControllerLog } from './controller-ingest.js';
|
|
5
|
+
import { foldChain, foldControllerLog, memberDropIndices, revokeIndices } from './controller-log.js';
|
|
6
|
+
import { RecoveryKnowledgeError, RevokeProofError } from './errors.js';
|
|
3
7
|
import { authenticateLifecycleProof } from './lifecycle-proof.js';
|
|
8
|
+
import { claimsFor } from './member-root.js';
|
|
4
9
|
import { adminCount, ROLE_ENTRY_TYPE, roleReducer } from './roster.js';
|
|
5
10
|
/** The reserved control type carrying a device-registry mutation. One branch, one namespace slot. */ export const DEVICE_ENTRY_TYPE = 'kumiai.device';
|
|
6
11
|
export function controllerProjection() {
|
|
7
12
|
return {
|
|
8
|
-
recordedLog: [],
|
|
9
13
|
genFloor: 0,
|
|
10
|
-
timeFloor: 0
|
|
14
|
+
timeFloor: 0,
|
|
15
|
+
attestations: new Map(),
|
|
16
|
+
removedMembers: new Map(),
|
|
17
|
+
survivorGrants: new Map()
|
|
11
18
|
};
|
|
12
19
|
}
|
|
13
20
|
export function registrySeed() {
|
|
@@ -19,11 +26,13 @@ export function registrySeed() {
|
|
|
19
26
|
/** Structural guard: a value carrying a known `op` (and, for register/add, a string controller). */ export function isDeviceValue(value) {
|
|
20
27
|
if (value == null || typeof value !== 'object') return false;
|
|
21
28
|
const v = value;
|
|
22
|
-
if (v.op !== 'register' && v.op !== 'add' && v.op !== 'revoke' && v.op !== 'label' && v.op !== 'beacon' && v.op !== 'reset' && v.op !== 'clock') {
|
|
29
|
+
if (v.op !== 'register' && v.op !== 'add' && v.op !== 'revoke' && v.op !== 'label' && v.op !== 'beacon' && v.op !== 'reset' && v.op !== 'clock' && v.op !== 'log' && v.op !== 'seed') {
|
|
23
30
|
return false;
|
|
24
31
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
32
|
+
const logBearing = v.op === 'log' || v.op === 'seed';
|
|
33
|
+
const proofBearing = logBearing || v.op === 'reset' || v.op === 'revoke' && v.proof !== undefined;
|
|
34
|
+
if (!proofBearing && ('proof' in v || 'revoked' in v || 'effects' in v || 'removed' in v || 'survivors' in v)) return false;
|
|
35
|
+
if (logBearing && (!isControllerLog(v.proof) || 'revoked' in v || 'effects' in v || 'removed' in v || 'survivors' in v || 'capability' in v)) return false;
|
|
27
36
|
if ((v.op === 'register' || v.op === 'add') && typeof v.controller !== 'string') return false;
|
|
28
37
|
if (v.op === 'beacon' && (typeof v.logLength !== 'number' || typeof v.headDigest !== 'string')) {
|
|
29
38
|
return false;
|
|
@@ -34,19 +43,31 @@ export function registrySeed() {
|
|
|
34
43
|
if (v.logLength !== undefined && typeof v.logLength !== 'number') return false;
|
|
35
44
|
if (v.headDigest !== undefined && typeof v.headDigest !== 'string') return false;
|
|
36
45
|
if (v.time !== undefined && (typeof v.time !== 'number' || !Number.isFinite(v.time))) return false;
|
|
37
|
-
if (v.proof !== undefined && !
|
|
46
|
+
if (v.proof !== undefined && !isControllerLog(v.proof)) return false;
|
|
38
47
|
if (v.revoked !== undefined && (!Array.isArray(v.revoked) || v.revoked.some((effect)=>{
|
|
39
48
|
if (effect == null || typeof effect !== 'object') return true;
|
|
40
49
|
const record = effect;
|
|
41
50
|
return typeof record.did !== 'string' || record.cascadedFrom !== undefined && typeof record.cascadedFrom !== 'string';
|
|
42
51
|
}))) return false;
|
|
43
52
|
if (v.op === 'clock' && typeof v.time !== 'number') return false;
|
|
44
|
-
if (
|
|
53
|
+
if (v.attest !== undefined && (v.op !== 'clock' || v.attest !== true)) return false;
|
|
54
|
+
if (!logBearing && (v.op === 'reset' || v.proof !== undefined) && (!isControllerLog(v.proof) || !Array.isArray(v.revoked) || !Array.isArray(v.effects) || !Array.isArray(v.removed))) return false;
|
|
55
|
+
if (v.effects !== undefined && (!Array.isArray(v.effects) || v.effects.some((claim)=>{
|
|
56
|
+
if (claim == null || typeof claim !== 'object') return true;
|
|
57
|
+
const c = claim;
|
|
58
|
+
if (c.kind === 'deny' ? typeof c.did !== 'string' : c.kind !== 'remove' || c.member == null || typeof c.member !== 'object' || typeof c.member.did !== 'string' || typeof c.member.add !== 'string') return true;
|
|
59
|
+
if (c.ref == null || typeof c.ref !== 'object') return true;
|
|
60
|
+
const ref = c.ref;
|
|
61
|
+
const keys = Object.keys(ref);
|
|
62
|
+
return !(keys.length === 1 && (Number.isInteger(ref.chainIndex) && ref.chainIndex >= 0 || Number.isInteger(ref.snapshot) && ref.snapshot >= 0) || typeof ref.event === 'string' && keys.every((key)=>key === 'event' || key === 'epoch') && (ref.epoch === undefined || typeof ref.epoch === 'string'));
|
|
63
|
+
}))) return false;
|
|
64
|
+
if (v.removed !== undefined && (!Array.isArray(v.removed) || v.removed.some((effect)=>effect == null || typeof effect !== 'object' || typeof effect.did !== 'string' || typeof effect.cascadedFrom !== 'string'))) return false;
|
|
65
|
+
if (v.survivors !== undefined && (!Array.isArray(v.survivors) || v.survivors.some((raw)=>typeof raw !== 'string'))) return false;
|
|
45
66
|
return true;
|
|
46
67
|
}
|
|
47
68
|
export function isLifecycleDeviceValue(value) {
|
|
48
69
|
if (!isDeviceValue(value)) return false;
|
|
49
|
-
return value.op === 'beacon' || value.op === 'clock' || (value.op === 'revoke' || value.op === 'reset') && value.proof !== undefined && value.revoked !== undefined && value.capability === undefined;
|
|
70
|
+
return value.op === 'beacon' || value.op === 'clock' || value.op === 'log' || value.op === 'seed' || (value.op === 'revoke' || value.op === 'reset') && value.proof !== undefined && value.revoked !== undefined && value.capability === undefined;
|
|
50
71
|
}
|
|
51
72
|
/**
|
|
52
73
|
* The registry fold step. Pure, order-dependent, authorization-free — a device entry's authority
|
|
@@ -58,29 +79,54 @@ export function isLifecycleDeviceValue(value) {
|
|
|
58
79
|
const devices = new Map(state.devices);
|
|
59
80
|
const controllers = new Map(state.controllers);
|
|
60
81
|
const existing = devices.get(subject);
|
|
61
|
-
if (controllerID != null && (value.op === 'reset' || value.op === 'revoke' || value.op === 'clock')) {
|
|
82
|
+
if (controllerID != null && (value.op === 'reset' || value.op === 'revoke' || value.op === 'clock' || value.op === 'log' || value.op === 'seed')) {
|
|
62
83
|
const controller = normalizeDID(controllerID);
|
|
63
84
|
const previous = controllers.get(controller) ?? controllerProjection();
|
|
64
85
|
if (value.op === 'clock') {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
if (value.attest === true) {
|
|
87
|
+
const folded = previous.recordedLog == null ? undefined : foldControllerLog(controller, previous.recordedLog);
|
|
88
|
+
const member = folded?.ok ? [
|
|
89
|
+
...folded.head.members.values()
|
|
90
|
+
].find((member)=>normalizeDID(member.did) === normalizeDID(verified.issuer)) : undefined;
|
|
91
|
+
if (member == null) throw new RevokeProofError('effects-mismatch');
|
|
92
|
+
const attestations = new Map(previous.attestations);
|
|
93
|
+
attestations.set(member.key, Math.max(attestations.get(member.key) ?? 0, value.time));
|
|
94
|
+
controllers.set(controller, {
|
|
95
|
+
...previous,
|
|
96
|
+
attestations
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
controllers.set(controller, {
|
|
100
|
+
...previous,
|
|
101
|
+
timeFloor: Math.max(previous.timeFloor, value.time)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
69
104
|
} else {
|
|
70
105
|
const effect = authenticateLifecycleProof(controller, verified, state);
|
|
71
|
-
|
|
106
|
+
let projection = {
|
|
72
107
|
...previous,
|
|
73
108
|
recordedLog: effect.recordedLog,
|
|
74
109
|
genFloor: effect.genFloor
|
|
75
|
-
}
|
|
110
|
+
};
|
|
111
|
+
if (value.op === 'seed') projection = seedEffects(controller, devices, projection);
|
|
112
|
+
controllers.set(controller, projection);
|
|
113
|
+
const resetRef = effect.resetRef;
|
|
114
|
+
const denials = new Map((value.effects ?? []).flatMap((claim)=>claim.kind === 'deny' ? [
|
|
115
|
+
[
|
|
116
|
+
normalizeDID(claim.did),
|
|
117
|
+
claim.ref
|
|
118
|
+
]
|
|
119
|
+
] : []));
|
|
76
120
|
for (const revoked of value.revoked ?? []){
|
|
77
121
|
const did = normalizeDID(revoked.did);
|
|
78
122
|
const held = devices.get(did);
|
|
79
123
|
if (held?.status === 'revoked' && (value.op === 'reset' || !isResetOnly(held))) continue;
|
|
124
|
+
const proofRef = denials.get(normalizeDID(revoked.cascadedFrom ?? did)) ?? resetRef;
|
|
125
|
+
if (proofRef == null) throw new RevokeProofError('effects-mismatch');
|
|
80
126
|
devices.set(did, {
|
|
81
127
|
controller,
|
|
82
128
|
status: 'revoked',
|
|
83
|
-
|
|
129
|
+
proofRef,
|
|
84
130
|
...value.op === 'reset' ? {
|
|
85
131
|
reason: 'reset'
|
|
86
132
|
} : {},
|
|
@@ -89,6 +135,53 @@ export function isLifecycleDeviceValue(value) {
|
|
|
89
135
|
}
|
|
90
136
|
});
|
|
91
137
|
}
|
|
138
|
+
for (const [did, proofRef] of denials){
|
|
139
|
+
const held = devices.get(did);
|
|
140
|
+
if (held?.status === 'revoked' && !isResetOnly(held)) continue;
|
|
141
|
+
devices.set(did, {
|
|
142
|
+
controller,
|
|
143
|
+
status: 'revoked',
|
|
144
|
+
proofRef
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const removedMembers = new Map(projection.removedMembers);
|
|
148
|
+
for (const claim of value.effects ?? []){
|
|
149
|
+
if (claim.kind !== 'remove') continue;
|
|
150
|
+
removedMembers.set(claim.member.add, {
|
|
151
|
+
did: normalizeDID(claim.member.did),
|
|
152
|
+
gen: effect.genFloor,
|
|
153
|
+
proofRef: claim.ref
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
for (const [add, member] of removedMembers){
|
|
157
|
+
if (!('event' in member.proofRef)) continue;
|
|
158
|
+
const index = memberDropIndices(controller, effect.recordedLog.chain, add).at(-1);
|
|
159
|
+
if (index != null) removedMembers.set(add, {
|
|
160
|
+
...member,
|
|
161
|
+
proofRef: {
|
|
162
|
+
chainIndex: index
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const survivorGrants = new Map(projection.survivorGrants);
|
|
167
|
+
for (const raw of value.survivors ?? []){
|
|
168
|
+
survivorGrants.set(normalizeDID(readCapability(raw).payload.aud), raw);
|
|
169
|
+
}
|
|
170
|
+
controllers.set(controller, {
|
|
171
|
+
...projection,
|
|
172
|
+
removedMembers,
|
|
173
|
+
survivorGrants
|
|
174
|
+
});
|
|
175
|
+
for (const [did, held] of devices){
|
|
176
|
+
if (held.controller !== controller || held.proofRef == null || !('event' in held.proofRef)) continue;
|
|
177
|
+
const index = revokeIndices(controller, effect.recordedLog.chain, held.cascadedFrom ?? did).at(-1);
|
|
178
|
+
if (index != null) devices.set(did, {
|
|
179
|
+
...held,
|
|
180
|
+
proofRef: {
|
|
181
|
+
chainIndex: index
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
92
185
|
}
|
|
93
186
|
return {
|
|
94
187
|
devices,
|
|
@@ -140,6 +233,8 @@ export function isLifecycleDeviceValue(value) {
|
|
|
140
233
|
}
|
|
141
234
|
case 'reset':
|
|
142
235
|
case 'clock':
|
|
236
|
+
case 'log':
|
|
237
|
+
case 'seed':
|
|
143
238
|
return {
|
|
144
239
|
devices,
|
|
145
240
|
controllers
|
|
@@ -187,7 +282,7 @@ export function isLifecycleDeviceValue(value) {
|
|
|
187
282
|
const record = registry.devices.get(normalizeDID(parsed.id));
|
|
188
283
|
const binding = parsed.controller;
|
|
189
284
|
if (record == null || !isResetOnly(record) || binding == null || normalizeDID(binding.id) !== record.controller) return false;
|
|
190
|
-
const folded =
|
|
285
|
+
const folded = foldChain(binding.id, binding.prefix);
|
|
191
286
|
return folded.ok && (folded.states.at(-1)?.gen ?? 0) >= (registry.controllers.get(record.controller)?.genFloor ?? 0);
|
|
192
287
|
}
|
|
193
288
|
/** The profile a device is bound to in the folded registry, or undefined — the authority input. */ export function controllerOf(registry, deviceDID) {
|
|
@@ -196,6 +291,94 @@ export function isLifecycleDeviceValue(value) {
|
|
|
196
291
|
/** The advisory beacon a controller last announced, or undefined. Never a validation input. */ export function beaconOf(registry, controllerDID) {
|
|
197
292
|
return registry.controllers.get(normalizeDID(controllerDID))?.beacon;
|
|
198
293
|
}
|
|
294
|
+
export function recordedLogOf(registry, controller) {
|
|
295
|
+
return registry.controllers.get(normalizeDID(controller))?.recordedLog;
|
|
296
|
+
}
|
|
297
|
+
export function assertRetainsKnownEffects(controller, known, candidate) {
|
|
298
|
+
const did = normalizeDID(controller);
|
|
299
|
+
const held = known.controllers.get(did);
|
|
300
|
+
const offered = candidate.controllers.get(did);
|
|
301
|
+
const before = held?.recordedLog == null ? undefined : foldControllerLog(did, held.recordedLog);
|
|
302
|
+
const after = offered?.recordedLog == null ? undefined : foldControllerLog(did, offered.recordedLog);
|
|
303
|
+
if (before?.ok && (!after?.ok || after.head.saturated)) throw new RecoveryKnowledgeError('epoch-event');
|
|
304
|
+
if (held?.recordedLog != null && offered?.recordedLog != null) {
|
|
305
|
+
const branches = resolveBranches(did, [
|
|
306
|
+
held.recordedLog.chain,
|
|
307
|
+
offered.recordedLog.chain
|
|
308
|
+
]);
|
|
309
|
+
const winner = branches.ok ? foldChain(did, branches.winner) : undefined;
|
|
310
|
+
if (!winner?.ok || after?.ok && after.head.epoch !== winner.head.epoch) throw new RecoveryKnowledgeError('forked');
|
|
311
|
+
}
|
|
312
|
+
if ((offered?.timeFloor ?? 0) < (held?.timeFloor ?? 0) || (offered?.genFloor ?? 0) < (held?.genFloor ?? 0)) throw new RecoveryKnowledgeError('floor');
|
|
313
|
+
for (const [device, record] of known.devices){
|
|
314
|
+
if (record.controller !== did || record.status !== 'revoked' || isResetOnly(record)) continue;
|
|
315
|
+
const retained = candidate.devices.get(device);
|
|
316
|
+
if (retained?.controller !== did || retained.status !== 'revoked' || isResetOnly(retained)) throw new RecoveryKnowledgeError('revocation');
|
|
317
|
+
}
|
|
318
|
+
const resetPast = (generation)=>after?.ok === true && after.head.gen > generation && (offered?.genFloor ?? 0) > generation;
|
|
319
|
+
for (const [add, member] of held?.removedMembers ?? []){
|
|
320
|
+
if (!offered?.removedMembers.has(add) && !resetPast(member.gen)) throw new RecoveryKnowledgeError('removal');
|
|
321
|
+
}
|
|
322
|
+
if (before?.ok) {
|
|
323
|
+
const retained = new Set(after?.ok ? after.applied : []);
|
|
324
|
+
const settledAt = after?.ok ? after.states.findIndex((state)=>state.digest === before.head.epoch) : -1;
|
|
325
|
+
const settled = after?.ok === true && settledAt >= 0 && settledAt < after.states.length - 1;
|
|
326
|
+
for (const event of before.applied){
|
|
327
|
+
if (!retained.has(event) && !settled && !resetPast(before.head.gen)) throw new RecoveryKnowledgeError('epoch-event');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (after?.ok) {
|
|
331
|
+
for (const member of after.head.members.values()){
|
|
332
|
+
if (member.effective && (offered?.attestations.get(member.key) ?? 0) < (held?.attestations.get(member.key) ?? 0)) throw new RecoveryKnowledgeError('attestation');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
export function registryForLog(controller, log) {
|
|
337
|
+
const { log: recordedLog, after } = ingestControllerLog(controller, undefined, log);
|
|
338
|
+
const devices = new Map();
|
|
339
|
+
const projection = seedEffects(normalizeDID(controller), devices, {
|
|
340
|
+
...controllerProjection(),
|
|
341
|
+
recordedLog,
|
|
342
|
+
genFloor: after.head.gen
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
devices,
|
|
346
|
+
controllers: new Map([
|
|
347
|
+
[
|
|
348
|
+
normalizeDID(controller),
|
|
349
|
+
projection
|
|
350
|
+
]
|
|
351
|
+
])
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function seedEffects(controller, devices, projection) {
|
|
355
|
+
const log = projection.recordedLog;
|
|
356
|
+
const folded = foldControllerLog(controller, log);
|
|
357
|
+
if (!folded.ok) throw new RevokeProofError('effects-mismatch');
|
|
358
|
+
const removedMembers = new Map(projection.removedMembers);
|
|
359
|
+
for (const claim of claimsFor(controller, undefined, log, 0)){
|
|
360
|
+
if (claim.kind === 'deny') {
|
|
361
|
+
devices.set(normalizeDID(claim.did), {
|
|
362
|
+
controller,
|
|
363
|
+
status: 'revoked',
|
|
364
|
+
proofRef: claim.ref
|
|
365
|
+
});
|
|
366
|
+
} else {
|
|
367
|
+
const ref = claim.ref;
|
|
368
|
+
const gen = 'event' in ref ? log.events.find(({ event })=>digestOf(event) === ref.event)?.event.g : folded.states['chainIndex' in ref ? ref.chainIndex : ref.snapshot]?.gen;
|
|
369
|
+
if (gen == null) throw new RevokeProofError('no-rev');
|
|
370
|
+
removedMembers.set(claim.member.add, {
|
|
371
|
+
did: normalizeDID(claim.member.did),
|
|
372
|
+
gen,
|
|
373
|
+
proofRef: ref
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
...projection,
|
|
379
|
+
removedMembers
|
|
380
|
+
};
|
|
381
|
+
}
|
|
199
382
|
/**
|
|
200
383
|
* The deny set Slice 1's seam consumes: the device DIDs at `status: 'revoked'` NOW. Matched, never
|
|
201
384
|
* enumerated by consumers (`has`), holding device DIDs only, per the kokuin deny-set rule.
|
|
@@ -233,7 +416,7 @@ export function isLifecycleDeviceValue(value) {
|
|
|
233
416
|
*/ export function foldControl(entries, anchor, groupID, onDrop) {
|
|
234
417
|
let roster = roleReducer.seed(anchor);
|
|
235
418
|
let registry = registrySeed();
|
|
236
|
-
for (const { verified, entryID } of entries){
|
|
419
|
+
for (const [position, { verified, entryID }] of entries.entries()){
|
|
237
420
|
const { entry, issuer } = verified;
|
|
238
421
|
if (entry.groupID !== groupID) {
|
|
239
422
|
onDrop?.({
|
|
@@ -261,6 +444,7 @@ export function isLifecycleDeviceValue(value) {
|
|
|
261
444
|
continue;
|
|
262
445
|
}
|
|
263
446
|
try {
|
|
447
|
+
if (entry.value.op === 'seed' && position !== 0) throw new RevokeProofError('detached');
|
|
264
448
|
registry = registryApply({
|
|
265
449
|
issuer,
|
|
266
450
|
entry: {
|
|
@@ -326,10 +510,10 @@ export function isLifecycleDeviceValue(value) {
|
|
|
326
510
|
}
|
|
327
511
|
/** A ledger revocation, independent of the controller's current log deny set. */ export function revocationOf(group, did) {
|
|
328
512
|
const record = group.registry.devices.get(normalizeDID(did));
|
|
329
|
-
if (record?.status !== 'revoked' || record.
|
|
513
|
+
if (record?.status !== 'revoked' || record.proofRef === undefined) return null;
|
|
330
514
|
return {
|
|
331
515
|
controller: record.controller,
|
|
332
|
-
|
|
516
|
+
proofRef: record.proofRef,
|
|
333
517
|
...record.reason === undefined ? {} : {
|
|
334
518
|
reason: record.reason
|
|
335
519
|
},
|
package/lib/stale-leaf.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type ClientState, type LeafNode, type ProposalWithSender } from 'ts-mls';
|
|
2
|
+
import { type ControllerBinding } from './credential.js';
|
|
2
3
|
/** More than one leaf of a lifecycle group names the DID an admission would replace. */
|
|
3
4
|
export declare class DuplicateMemberLeafError extends Error {
|
|
4
5
|
#private;
|
|
5
6
|
constructor(did: string);
|
|
6
7
|
get did(): string;
|
|
7
8
|
}
|
|
9
|
+
export declare function bindingIssuedAt(binding: ControllerBinding): number;
|
|
8
10
|
/**
|
|
9
11
|
* A replacement carries a controller grant issued strictly after the replaced leaf's, so a key
|
|
10
12
|
* package published under the leaf's current grant cannot evict that leaf.
|
package/lib/stale-leaf.js
CHANGED
|
@@ -23,17 +23,22 @@ function leafDID(leaf) {
|
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
export function bindingIssuedAt(binding) {
|
|
27
|
+
if (binding.member != null && binding.iat != null) return binding.iat;
|
|
28
|
+
if (binding.capability == null) throw new LeafBindingError('controller-mismatch');
|
|
29
|
+
return readCapability(binding.capability).payload.iat;
|
|
30
|
+
}
|
|
31
|
+
function leafBindingIssuedAt(leaf) {
|
|
27
32
|
if (!isDefaultCredential(leaf.credential) || leaf.credential.credentialType !== defaultCredentialTypes.basic) return undefined;
|
|
28
33
|
const binding = parseMLSCredentialIdentity(leaf.credential.identity).controller;
|
|
29
|
-
return binding == null ? undefined :
|
|
34
|
+
return binding == null ? undefined : bindingIssuedAt(binding);
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
37
|
* A replacement carries a controller grant issued strictly after the replaced leaf's, so a key
|
|
33
38
|
* package published under the leaf's current grant cannot evict that leaf.
|
|
34
39
|
*/ export function assertNewerBinding(leaf, replaced) {
|
|
35
|
-
const next =
|
|
36
|
-
const previous =
|
|
40
|
+
const next = leafBindingIssuedAt(leaf);
|
|
41
|
+
const previous = leafBindingIssuedAt(replaced);
|
|
37
42
|
if (next == null || previous == null || next <= previous) throw new LeafBindingError('renewal-order');
|
|
38
43
|
}
|
|
39
44
|
function leafIndicesOf(tree, did) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { ControllerLog } from '@kokuin/controller';
|
|
1
2
|
import type { Capabilities, CryptoProvider, GroupContextExtension, IncomingMessageCallback, KeyPackage, PrivateKeyPackage } from 'ts-mls';
|
|
2
3
|
import type { ControllerBinding } from './credential.js';
|
|
3
4
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
4
5
|
export type GroupOptions = {
|
|
5
6
|
/** Creator or key-package leaf binding. Creates a lifecycle group when passed to createGroup. */
|
|
6
7
|
controller?: ControllerBinding;
|
|
8
|
+
/** Authoritative creator log. Required when creating a lifecycle group. */
|
|
9
|
+
controllerLog?: ControllerLog;
|
|
7
10
|
/** Lifecycle leaf lifetime in seconds. Defaults to 86,400; maximum 604,800. */
|
|
8
11
|
leafLifetime?: number;
|
|
9
12
|
/** Lifecycle trusted grant lifetime in seconds. Defaults to 2,592,000; maximum 31,536,000. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "E2EE group identity and membership for Enkaku using MLS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kokuin/capability": "^0.
|
|
29
|
-
"@kokuin/controller": "^0.
|
|
30
|
-
"@kokuin/token": "^0.
|
|
28
|
+
"@kokuin/capability": "^0.5.2",
|
|
29
|
+
"@kokuin/controller": "^0.2.4",
|
|
30
|
+
"@kokuin/token": "^0.6.2",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
32
|
"@noble/curves": "^2.4.0",
|
|
33
33
|
"@noble/hashes": "^2.4.0",
|