@kumiai/mls 0.10.2 → 0.10.4
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/authentication.d.ts +3 -0
- package/lib/authentication.js +14 -3
- package/lib/group-context.d.ts +2 -0
- package/lib/group-context.js +1 -0
- package/lib/group-handle.js +42 -6
- package/lib/group-lifecycle.js +3 -2
- package/lib/lifecycle-proof.js +3 -2
- package/lib/lifecycle.js +4 -3
- package/lib/registry.d.ts +11 -6
- package/lib/registry.js +21 -11
- package/package.json +1 -1
package/lib/authentication.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SignedEvent } from '@kokuin/controller';
|
|
2
2
|
import type { AuthenticationService, Credential } from 'ts-mls';
|
|
3
3
|
import { type MLSCredentialIdentity } from './credential.js';
|
|
4
|
+
import { type DeviceRegistry } from './registry.js';
|
|
4
5
|
export { MLS_LEAF_ACT, MLS_LEAF_RES } from './capability.js';
|
|
5
6
|
/** The action a management capability must grant to mutate a profile's device registry. */
|
|
6
7
|
export declare const MLS_DEVICES_ACT = "manage";
|
|
@@ -8,6 +9,8 @@ export declare const MLS_DEVICES_ACT = "manage";
|
|
|
8
9
|
export declare const MLS_DEVICES_RES = "kumiai/devices";
|
|
9
10
|
export type DIDAuthenticationDependencies = {
|
|
10
11
|
deviceDenySet?: () => ReadonlySet<string>;
|
|
12
|
+
/** Registry context permits authenticated post-reset subject admission. */
|
|
13
|
+
deviceRegistry?: () => DeviceRegistry | undefined;
|
|
11
14
|
leafLifetime?: () => number | undefined;
|
|
12
15
|
trustedGrantLifetime?: () => number | undefined;
|
|
13
16
|
/**
|
package/lib/authentication.js
CHANGED
|
@@ -7,6 +7,7 @@ import { assertCapabilityLifetime, assertControllerGrant, capabilityKey, MAX_LEA
|
|
|
7
7
|
import { parseMLSCredentialIdentity } from './credential.js';
|
|
8
8
|
import { createEmbeddedControllerResolver } from './embedded-resolver.js';
|
|
9
9
|
import { LeafBindingError } from './errors.js';
|
|
10
|
+
import { denySetOf, mayReadmitResetDevice } from './registry.js';
|
|
10
11
|
export { MLS_LEAF_ACT, MLS_LEAF_RES } from './capability.js';
|
|
11
12
|
/** The action a management capability must grant to mutate a profile's device registry. */ export const MLS_DEVICES_ACT = 'manage';
|
|
12
13
|
/** The resource half — kumiai-namespaced, group-independent, per the kokuin management tier. */ export const MLS_DEVICES_RES = 'kumiai/devices';
|
|
@@ -200,11 +201,21 @@ function withoutIssuer(denied, capability) {
|
|
|
200
201
|
}
|
|
201
202
|
const parsed = parseMLSCredentialIdentity(credential.identity);
|
|
202
203
|
if (!matchesLeafKey(parsed, signaturePublicKey)) throw new LeafBindingError('identity-change');
|
|
203
|
-
const
|
|
204
|
-
|
|
204
|
+
const registry = deps.deviceRegistry?.();
|
|
205
|
+
const denied = deps.deviceDenySet?.() ?? (registry == null ? EMPTY_DENY : denySetOf(registry));
|
|
206
|
+
if (isDenied(denied, parsed.id) && (registry == null || !mayReadmitResetDevice(registry, parsed))) throw new LeafBindingError('denied-id');
|
|
207
|
+
// Exempt only this holder; every issuer remains subject to the full deny set.
|
|
208
|
+
const denySet = isDenied(denied, parsed.id) ? new Set([
|
|
209
|
+
...denied
|
|
210
|
+
].filter((did)=>normalizeDID(did) !== normalizeDID(parsed.id))) : denied;
|
|
205
211
|
if (parsed.controller == null) return;
|
|
212
|
+
if (registry != null) {
|
|
213
|
+
const folded = foldLog(parsed.controller.id, parsed.controller.prefix);
|
|
214
|
+
if (!folded.ok) throw new LeafBindingError('controller-mismatch');
|
|
215
|
+
if ((folded.states.at(-1)?.gen ?? 0) < (registry.controllers.get(normalizeDID(parsed.controller.id))?.genFloor ?? 0)) throw new LeafBindingError('generation-floor');
|
|
216
|
+
}
|
|
206
217
|
try {
|
|
207
|
-
// The holder grant
|
|
218
|
+
// The holder grant does not inherit the leaf capability's issuer exception.
|
|
208
219
|
const leafDenySet = deps.mayKeepDeniedIssuer?.(credential, signaturePublicKey) && hasHolderEvidence(parsed, signaturePublicKey, denySet, deps.trustedGrantLifetime?.()) ? withoutIssuer(denySet, parsed.controller.capability) : denySet;
|
|
209
220
|
await verifyPinnedCapability({
|
|
210
221
|
capability: parsed.controller.capability,
|
package/lib/group-context.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Capabilities, type GroupContextExtension, type MlsContext } from 'ts-mls';
|
|
2
2
|
import type { GroupAnchor } from './anchor.js';
|
|
3
|
+
import type { DeviceRegistry } from './registry.js';
|
|
3
4
|
import type { GroupOptions } from './types.js';
|
|
4
5
|
/** Late-bound provider of a context's device deny set, pointed at the live handle after construction. */
|
|
5
6
|
export type DeviceDenyHolder = {
|
|
6
7
|
provider: () => ReadonlySet<string>;
|
|
8
|
+
registry?: () => DeviceRegistry | undefined;
|
|
7
9
|
leafLifetime?: number;
|
|
8
10
|
trustedGrantLifetime?: number;
|
|
9
11
|
};
|
package/lib/group-context.js
CHANGED
|
@@ -22,6 +22,7 @@ export function createMlsContext(cipherSuite, anchor) {
|
|
|
22
22
|
};
|
|
23
23
|
const authService = createDIDAuthenticationService({
|
|
24
24
|
deviceDenySet: ()=>holder.provider(),
|
|
25
|
+
deviceRegistry: ()=>holder.registry?.(),
|
|
25
26
|
leafLifetime: ()=>holder.leafLifetime,
|
|
26
27
|
trustedGrantLifetime: ()=>holder.trustedGrantLifetime
|
|
27
28
|
});
|
package/lib/group-handle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
2
|
import { EventEmitter } from '@sozai/event';
|
|
3
|
-
import { contentTypes, createApplicationMessage, createProposal, decode, defaultProposalTypes, encode, mlsExporter, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, wireformats } from 'ts-mls';
|
|
3
|
+
import { contentTypes, createApplicationMessage, createProposal, decode, defaultCredentialTypes, defaultProposalTypes, encode, isDefaultCredential, mlsExporter, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, wireformats } from 'ts-mls';
|
|
4
4
|
import { readGroupAnchor } from './anchor.js';
|
|
5
5
|
import { verifyLeafCredential } from './authentication.js';
|
|
6
6
|
import { encodeClientState } from './codec.js';
|
|
@@ -16,7 +16,7 @@ import { ledgerEntryDigest, verifyLedgerEntry } from './ledger.js';
|
|
|
16
16
|
import { assertSenderNotLapsed, isLapsed, isUnchangedLeaf, leafAt, prepareLifecycleGate, rejectionReason } from './lifecycle.js';
|
|
17
17
|
import { createMutex } from './mutex.js';
|
|
18
18
|
import { defaultCommitPolicy, MissingLedgerEntriesError } from './policy.js';
|
|
19
|
-
import { beaconOf, controllerOf, DEVICE_ENTRY_TYPE, denySetOf, foldControl, isDeviceValue, revocationOf } from './registry.js';
|
|
19
|
+
import { beaconOf, controllerOf, DEVICE_ENTRY_TYPE, denySetOf, foldControl, isDeviceValue, mayReadmitResetDevice, revocationOf } from './registry.js';
|
|
20
20
|
import { readSenderLeafIndex } from './sender-data.js';
|
|
21
21
|
/** One serializer per live handle, so its state-mutating operations run one at a
|
|
22
22
|
* time in issue order. Keyed weakly: the entry is collected with the handle, and
|
|
@@ -171,6 +171,39 @@ export function mutexFor(handle) {
|
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
/** Project lifecycle tree re-admissions from the full ledger fold, never a previous projection.
|
|
175
|
+
* A lapsed re-admitted leaf and a leaf inserted after expiry are indistinguishable here;
|
|
176
|
+
* a genuine expired post-reset package can activate a leaf for a Welcome joiner or an
|
|
177
|
+
* external rejoiner adopting a fork existing members reject. Ordinary commit admission
|
|
178
|
+
* still enforces expiry.
|
|
179
|
+
*/ function registryWithTreeBindings(registry, tree, anchor) {
|
|
180
|
+
if (anchor.controller == null) return registry;
|
|
181
|
+
const devices = new Map(registry.devices);
|
|
182
|
+
for (const node of tree){
|
|
183
|
+
if (node?.nodeType !== nodeTypes.leaf || !isDefaultCredential(node.leaf.credential) || node.leaf.credential.credentialType !== defaultCredentialTypes.basic) continue;
|
|
184
|
+
let parsed;
|
|
185
|
+
try {
|
|
186
|
+
parsed = parseMLSCredentialIdentity(node.leaf.credential.identity);
|
|
187
|
+
} catch {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!mayReadmitResetDevice(registry, parsed)) continue;
|
|
191
|
+
const did = normalizeDID(parsed.id);
|
|
192
|
+
const record = devices.get(did);
|
|
193
|
+
if (record == null) continue;
|
|
194
|
+
devices.set(did, {
|
|
195
|
+
controller: record.controller,
|
|
196
|
+
status: 'active',
|
|
197
|
+
...record.label == null ? {} : {
|
|
198
|
+
label: record.label
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
...registry,
|
|
204
|
+
devices
|
|
205
|
+
};
|
|
206
|
+
}
|
|
174
207
|
/**
|
|
175
208
|
* Project a held ledger into BOTH the roster and the device registry in one ordered pass
|
|
176
209
|
* (see {@link foldControl}), so a role entry's authority resolves against the registry-so-far.
|
|
@@ -226,11 +259,12 @@ export function mutexFor(handle) {
|
|
|
226
259
|
]));
|
|
227
260
|
const folded = foldLedgerControl(this.#ledger, anchor, this.groupID);
|
|
228
261
|
this.#roster = folded.roster;
|
|
229
|
-
this.#registry = folded.registry;
|
|
262
|
+
this.#registry = registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor);
|
|
230
263
|
// Authentication reads only this handle's registry and lifetime limits.
|
|
231
264
|
const denyHolder = deviceDenyHolderFor(this.#context);
|
|
232
265
|
if (denyHolder != null) {
|
|
233
266
|
denyHolder.provider = ()=>this.currentDenySet();
|
|
267
|
+
denyHolder.registry = ()=>anchor.controller == null ? undefined : this.registry;
|
|
234
268
|
denyHolder.leafLifetime = anchor.controller == null ? undefined : anchor.leafLifetime ?? 86_400;
|
|
235
269
|
denyHolder.trustedGrantLifetime = anchor.controller == null ? undefined : anchor.trustedGrantLifetime ?? 2_592_000;
|
|
236
270
|
}
|
|
@@ -424,7 +458,7 @@ export function mutexFor(handle) {
|
|
|
424
458
|
}
|
|
425
459
|
const folded = foldLedgerControl(this.#ledger, this.#anchor, this.groupID);
|
|
426
460
|
this.#roster = folded.roster;
|
|
427
|
-
this.#registry = folded.registry;
|
|
461
|
+
this.#registry = registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor);
|
|
428
462
|
this.#admission = this.#computeAdmission();
|
|
429
463
|
if (this.#pendingControlEvents != null) {
|
|
430
464
|
this.emitControlEvents(appended.filter(({ entry })=>entry.type === DEVICE_ENTRY_TYPE));
|
|
@@ -536,7 +570,7 @@ export function mutexFor(handle) {
|
|
|
536
570
|
}
|
|
537
571
|
]));
|
|
538
572
|
this.#roster = folded.roster;
|
|
539
|
-
this.#registry = folded.registry;
|
|
573
|
+
this.#registry = registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor);
|
|
540
574
|
this.#admission = this.#computeAdmission();
|
|
541
575
|
try {
|
|
542
576
|
await opts?.persist?.(this);
|
|
@@ -1032,7 +1066,8 @@ export function mutexFor(handle) {
|
|
|
1032
1066
|
});
|
|
1033
1067
|
}
|
|
1034
1068
|
this.#roster = candidateRoster;
|
|
1035
|
-
this.#
|
|
1069
|
+
const folded = foldLedgerControl(this.#ledger, this.#anchor, this.groupID);
|
|
1070
|
+
this.#registry = registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor);
|
|
1036
1071
|
this.#admission = this.#computeAdmission();
|
|
1037
1072
|
const emit = ()=>{
|
|
1038
1073
|
this.#notifyAccepted(surfaced, acceptedEntries.filter(({ verified })=>verified.entry.type === DEVICE_ENTRY_TYPE).map(({ verified })=>verified));
|
|
@@ -1279,6 +1314,7 @@ export function mutexFor(handle) {
|
|
|
1279
1314
|
try {
|
|
1280
1315
|
await verifyLeafCredential(credential, key, {
|
|
1281
1316
|
deviceDenySet: ()=>this.currentDenySet(),
|
|
1317
|
+
deviceRegistry: ()=>this.#anchor.controller == null ? undefined : this.registry,
|
|
1282
1318
|
// MLS re-validates the committer's path leaf after its proposals are judged:
|
|
1283
1319
|
// an evidenced child keeps a denied issuer only with the credential it
|
|
1284
1320
|
// already holds at that leaf.
|
package/lib/group-lifecycle.js
CHANGED
|
@@ -11,7 +11,7 @@ import { HISTORY_HORIZON, historySize } from './history.js';
|
|
|
11
11
|
import { signLedgerEntry } from './ledger.js';
|
|
12
12
|
import { isLapsed, leafAt, treeTime, validateEntry } from './lifecycle.js';
|
|
13
13
|
import { authenticateLifecycleProof, isExemptMember, verifyLifecycleProof } from './lifecycle-proof.js';
|
|
14
|
-
import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
14
|
+
import { DEVICE_ENTRY_TYPE, isResetOnly } from './registry.js';
|
|
15
15
|
/**
|
|
16
16
|
* Author a by-reference Remove for this handle's own leaf at its current epoch.
|
|
17
17
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
@@ -233,7 +233,8 @@ export async function removeLapsedLeaves(group) {
|
|
|
233
233
|
* Revoked in the registry, with no leaf of its own and no leaf it issued left in the tree, apart
|
|
234
234
|
* from evidenced children, which its revocation never removes.
|
|
235
235
|
*/ function isFullyRevoked(group, subject) {
|
|
236
|
-
|
|
236
|
+
const record = group.registry.devices.get(subject);
|
|
237
|
+
if (record?.status !== 'revoked' || isResetOnly(record)) return false;
|
|
237
238
|
if (group.findMemberLeafIndex(subject) != null) return false;
|
|
238
239
|
return !group.listMembers().some((member)=>{
|
|
239
240
|
const capability = group.bindingOfDID(member.id)?.capability;
|
package/lib/lifecycle-proof.js
CHANGED
|
@@ -6,7 +6,7 @@ import { readCapability } from './capability.js';
|
|
|
6
6
|
import { parseMLSCredentialIdentity } from './credential.js';
|
|
7
7
|
import { RevokeProofError } from './errors.js';
|
|
8
8
|
import { controllerLogSize, HISTORY_HORIZON, historySize } from './history.js';
|
|
9
|
-
import { denySetOf } from './registry.js';
|
|
9
|
+
import { denySetOf, isResetOnly } from './registry.js';
|
|
10
10
|
export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
11
11
|
/** Authenticate replayable log data without reading any membership state. */ export function authenticateLifecycleProof(controllerID, verified, registry) {
|
|
12
12
|
const controller = normalizeDID(controllerID);
|
|
@@ -180,7 +180,8 @@ export { controllerLogSize, HISTORY_HORIZON } from './history.js';
|
|
|
180
180
|
const authenticated = authenticateLifecycleProof(controller, verified, group.registry);
|
|
181
181
|
const revoked = [];
|
|
182
182
|
if (value.op === 'revoke') {
|
|
183
|
-
|
|
183
|
+
const record = group.registry.devices.get(subject);
|
|
184
|
+
if (record?.status === 'revoked' && !isResetOnly(record)) throw new RevokeProofError('effects-mismatch');
|
|
184
185
|
revoked.push({
|
|
185
186
|
did: subject
|
|
186
187
|
});
|
package/lib/lifecycle.js
CHANGED
|
@@ -11,7 +11,7 @@ import { decodeLedgerHead, extendHead, genesisHead, headsMatch } from './head.js
|
|
|
11
11
|
import { HISTORY_HORIZON, historySize } from './history.js';
|
|
12
12
|
import { isEvidencedChild, verifyLifecycleProof } from './lifecycle-proof.js';
|
|
13
13
|
import { evaluateGroupContextExtensions } from './policy.js';
|
|
14
|
-
import { DEVICE_ENTRY_TYPE, denySetOf } from './registry.js';
|
|
14
|
+
import { DEVICE_ENTRY_TYPE, denySetOf, mayReadmitResetDevice } from './registry.js';
|
|
15
15
|
export function rejectionReason(error) {
|
|
16
16
|
if (error instanceof LeafLapsedError) return 'lapse';
|
|
17
17
|
if (error instanceof LeafBindingError) {
|
|
@@ -85,7 +85,7 @@ function checkBinding(group, leaf, previous, /** The leaf arrives in a Welcome t
|
|
|
85
85
|
if (controller != null && binding == null) throw new LeafBindingError('floating-refused');
|
|
86
86
|
if (controller != null && binding != null && normalizeDID(binding.id) !== normalizeDID(controller)) throw new LeafBindingError('controller-mismatch');
|
|
87
87
|
const denied = denySetOf(group.registry);
|
|
88
|
-
if (denied.has(normalizeDID(parsed.id))) throw new LeafBindingError('denied-id');
|
|
88
|
+
if (denied.has(normalizeDID(parsed.id)) && !mayReadmitResetDevice(group.registry, parsed)) throw new LeafBindingError('denied-id');
|
|
89
89
|
const record = group.registry.devices.get(normalizeDID(parsed.id));
|
|
90
90
|
if (record != null && (binding == null || normalizeDID(binding.id) !== record.controller)) throw new LeafBindingError('controller-mismatch');
|
|
91
91
|
if (previous != null) {
|
|
@@ -116,6 +116,7 @@ async function validateBoundLeaf(group, leaf, previous, welcome = false) {
|
|
|
116
116
|
checkBinding(group, leaf, previous, welcome);
|
|
117
117
|
await verifyLeafCredential(leaf.credential, leaf.signaturePublicKey, {
|
|
118
118
|
deviceDenySet: ()=>denySetOf(group.registry),
|
|
119
|
+
deviceRegistry: ()=>group.anchor.controller == null ? undefined : group.registry,
|
|
119
120
|
mayKeepDeniedIssuer: ()=>welcome && group.anchor.controller != null,
|
|
120
121
|
leafLifetime: ()=>group.anchor.controller == null ? undefined : group.anchor.leafLifetime ?? 86_400,
|
|
121
122
|
trustedGrantLifetime: ()=>group.anchor.controller == null ? undefined : group.anchor.trustedGrantLifetime ?? 2_592_000
|
|
@@ -135,7 +136,7 @@ function checkSurvivors(group, tree, registry, origin) {
|
|
|
135
136
|
for (const [position, node] of tree.entries()){
|
|
136
137
|
if (node?.nodeType !== nodeTypes.leaf) continue;
|
|
137
138
|
const parsed = identity(node.leaf);
|
|
138
|
-
if (denied.has(normalizeDID(parsed.id))) throw new LeafBindingError('denied-id');
|
|
139
|
+
if (denied.has(normalizeDID(parsed.id)) && !mayReadmitResetDevice(registry, parsed)) throw new LeafBindingError('denied-id');
|
|
139
140
|
if (parsed.controller == null) {
|
|
140
141
|
if (controller != null) throw new LeafBindingError('floating-refused');
|
|
141
142
|
continue;
|
package/lib/registry.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SignedEvent } from '@kokuin/controller';
|
|
2
2
|
import type { GroupAnchor } from './anchor.js';
|
|
3
|
+
import type { MLSCredentialIdentity } from './credential.js';
|
|
3
4
|
import type { FoldDrop, FoldInput } from './fold.js';
|
|
4
5
|
import type { GroupHandle } from './group-handle.js';
|
|
5
6
|
import type { VerifiedLedgerEntry } from './ledger.js';
|
|
@@ -36,7 +37,7 @@ export type Revocation = {
|
|
|
36
37
|
reason?: 'reset';
|
|
37
38
|
cascadedFrom?: string;
|
|
38
39
|
};
|
|
39
|
-
/** A folded device binding or
|
|
40
|
+
/** A folded device binding or revocation. Reset-only removal permits fresh admission. */
|
|
40
41
|
export type DeviceRecord = {
|
|
41
42
|
controller: string;
|
|
42
43
|
status: 'active' | 'revoked';
|
|
@@ -77,6 +78,10 @@ export declare function isLifecycleDeviceValue(value: DeviceValue): boolean;
|
|
|
77
78
|
* never the fold's. Lifecycle effects replay recorded DIDs without consulting a later tree.
|
|
78
79
|
*/
|
|
79
80
|
export declare function registryApply(verified: VerifiedLedgerEntry<DeviceValue>, state: DeviceRegistry, controllerID?: string): DeviceRegistry;
|
|
81
|
+
/** Only reset removal without a cascade permits a later admission. */
|
|
82
|
+
export declare function isResetOnly(record: DeviceRecord): boolean;
|
|
83
|
+
/** Structural admission exception. Callers still authenticate the capability and holder grant. */
|
|
84
|
+
export declare function mayReadmitResetDevice(registry: DeviceRegistry, parsed: MLSCredentialIdentity): boolean;
|
|
80
85
|
/** The profile a device is bound to in the folded registry, or undefined — the authority input. */
|
|
81
86
|
export declare function controllerOf(registry: DeviceRegistry, deviceDID: string): string | undefined;
|
|
82
87
|
/** The advisory beacon a controller last announced, or undefined. Never a validation input. */
|
|
@@ -88,9 +93,9 @@ export declare function beaconOf(registry: DeviceRegistry, controllerDID: string
|
|
|
88
93
|
export declare function denySetOf(registry: DeviceRegistry): ReadonlySet<string>;
|
|
89
94
|
/**
|
|
90
95
|
* The universal rule: an ACTIVE binding resolves the issuer to its controller; anything else
|
|
91
|
-
* resolves to the issuer itself. A revoked binding confers no authority
|
|
92
|
-
*
|
|
93
|
-
*
|
|
96
|
+
* resolves to the issuer itself. A revoked binding confers no authority until accepted re-entry.
|
|
97
|
+
* Floating leaves and entries enacted while revoked cannot resolve to the former controller.
|
|
98
|
+
* (Note the split:
|
|
94
99
|
* {@link controllerOf} is the RAW lookup, deliberately status-blind, since the deviceRevoked event
|
|
95
100
|
* emission and the revoke/label gate read the surviving binding of a just-revoked device.)
|
|
96
101
|
*/
|
|
@@ -112,5 +117,5 @@ export declare function foldControl(entries: Array<FoldInput>, anchor: GroupAnch
|
|
|
112
117
|
roster: RosterState;
|
|
113
118
|
registry: DeviceRegistry;
|
|
114
119
|
};
|
|
115
|
-
/** A
|
|
120
|
+
/** A ledger revocation, independent of the controller's current log deny set. */
|
|
116
121
|
export declare function revocationOf(group: GroupHandle, did: string): Revocation | null;
|
package/lib/registry.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foldLog } from '@kokuin/controller';
|
|
1
2
|
import { normalizeDID } from '@kokuin/token';
|
|
2
3
|
import { authenticateLifecycleProof } from './lifecycle-proof.js';
|
|
3
4
|
import { adminCount, ROLE_ENTRY_TYPE, roleReducer } from './roster.js';
|
|
@@ -74,7 +75,8 @@ export function isLifecycleDeviceValue(value) {
|
|
|
74
75
|
});
|
|
75
76
|
for (const revoked of value.revoked ?? []){
|
|
76
77
|
const did = normalizeDID(revoked.did);
|
|
77
|
-
|
|
78
|
+
const held = devices.get(did);
|
|
79
|
+
if (held?.status === 'revoked' && (value.op === 'reset' || !isResetOnly(held))) continue;
|
|
78
80
|
devices.set(did, {
|
|
79
81
|
controller,
|
|
80
82
|
status: 'revoked',
|
|
@@ -97,11 +99,8 @@ export function isLifecycleDeviceValue(value) {
|
|
|
97
99
|
case 'register':
|
|
98
100
|
case 'add':
|
|
99
101
|
{
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
// The record is left frozen at 'revoked' (the acceptance gate still verified the entry, but the
|
|
103
|
-
// fold does not resurrect a revoked binding). Keeps determinism: every member applies this rule.
|
|
104
|
-
if (existing?.status === 'revoked') {
|
|
102
|
+
// Acceptance checks fresh evidence before reactivating a reset-only binding.
|
|
103
|
+
if (existing?.status === 'revoked' && !isResetOnly(existing)) {
|
|
105
104
|
return {
|
|
106
105
|
devices,
|
|
107
106
|
controllers
|
|
@@ -129,8 +128,9 @@ export function isLifecycleDeviceValue(value) {
|
|
|
129
128
|
devices,
|
|
130
129
|
controllers
|
|
131
130
|
};
|
|
131
|
+
const { reason: _reason, ...terminal } = existing;
|
|
132
132
|
devices.set(subject, {
|
|
133
|
-
...
|
|
133
|
+
...terminal,
|
|
134
134
|
status: 'revoked'
|
|
135
135
|
});
|
|
136
136
|
return {
|
|
@@ -180,6 +180,16 @@ export function isLifecycleDeviceValue(value) {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
+
/** Only reset removal without a cascade permits a later admission. */ export function isResetOnly(record) {
|
|
184
|
+
return record.status === 'revoked' && record.reason === 'reset' && record.cascadedFrom == null;
|
|
185
|
+
}
|
|
186
|
+
/** Structural admission exception. Callers still authenticate the capability and holder grant. */ export function mayReadmitResetDevice(registry, parsed) {
|
|
187
|
+
const record = registry.devices.get(normalizeDID(parsed.id));
|
|
188
|
+
const binding = parsed.controller;
|
|
189
|
+
if (record == null || !isResetOnly(record) || binding == null || normalizeDID(binding.id) !== record.controller) return false;
|
|
190
|
+
const folded = foldLog(binding.id, binding.prefix);
|
|
191
|
+
return folded.ok && (folded.states.at(-1)?.gen ?? 0) >= (registry.controllers.get(record.controller)?.genFloor ?? 0);
|
|
192
|
+
}
|
|
183
193
|
/** The profile a device is bound to in the folded registry, or undefined — the authority input. */ export function controllerOf(registry, deviceDID) {
|
|
184
194
|
return registry.devices.get(normalizeDID(deviceDID))?.controller;
|
|
185
195
|
}
|
|
@@ -198,9 +208,9 @@ export function isLifecycleDeviceValue(value) {
|
|
|
198
208
|
}
|
|
199
209
|
/**
|
|
200
210
|
* The universal rule: an ACTIVE binding resolves the issuer to its controller; anything else
|
|
201
|
-
* resolves to the issuer itself. A revoked binding confers no authority
|
|
202
|
-
*
|
|
203
|
-
*
|
|
211
|
+
* resolves to the issuer itself. A revoked binding confers no authority until accepted re-entry.
|
|
212
|
+
* Floating leaves and entries enacted while revoked cannot resolve to the former controller.
|
|
213
|
+
* (Note the split:
|
|
204
214
|
* {@link controllerOf} is the RAW lookup, deliberately status-blind, since the deviceRevoked event
|
|
205
215
|
* emission and the revoke/label gate read the surviving binding of a just-revoked device.)
|
|
206
216
|
*/ export function authority(registry, issuer) {
|
|
@@ -314,7 +324,7 @@ export function isLifecycleDeviceValue(value) {
|
|
|
314
324
|
registry
|
|
315
325
|
};
|
|
316
326
|
}
|
|
317
|
-
/** A
|
|
327
|
+
/** A ledger revocation, independent of the controller's current log deny set. */ export function revocationOf(group, did) {
|
|
318
328
|
const record = group.registry.devices.get(normalizeDID(did));
|
|
319
329
|
if (record?.status !== 'revoked' || record.logPosition === undefined) return null;
|
|
320
330
|
return {
|