@kumiai/mls 0.10.1 → 0.10.3
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 +18 -0
- package/lib/authentication.js +84 -5
- package/lib/credential.d.ts +7 -7
- package/lib/credential.js +15 -10
- package/lib/device-proof.d.ts +1 -0
- package/lib/errors.d.ts +1 -1
- package/lib/group-commit.d.ts +3 -1
- package/lib/group-commit.js +24 -14
- package/lib/group-context.d.ts +2 -0
- package/lib/group-context.js +1 -0
- package/lib/group-handle.d.ts +10 -0
- package/lib/group-handle.js +108 -12
- package/lib/group-lifecycle.d.ts +17 -0
- package/lib/group-lifecycle.js +50 -8
- package/lib/group-welcome.js +9 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -2
- package/lib/lifecycle-proof.d.ts +10 -1
- package/lib/lifecycle-proof.js +28 -2
- package/lib/lifecycle.d.ts +2 -0
- package/lib/lifecycle.js +43 -17
- package/lib/policy.js +1 -1
- package/lib/registry.d.ts +11 -6
- package/lib/registry.js +21 -11
- package/lib/secret-tree.d.ts +3 -0
- package/lib/secret-tree.js +60 -0
- package/package.json +3 -3
package/lib/authentication.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type SignedEvent } from '@kokuin/controller';
|
|
2
2
|
import type { AuthenticationService, Credential } from 'ts-mls';
|
|
3
|
+
import { type MLSCredentialIdentity } from './credential.js';
|
|
4
|
+
import { type DeviceRegistry } from './registry.js';
|
|
3
5
|
export { MLS_LEAF_ACT, MLS_LEAF_RES } from './capability.js';
|
|
4
6
|
/** The action a management capability must grant to mutate a profile's device registry. */
|
|
5
7
|
export declare const MLS_DEVICES_ACT = "manage";
|
|
@@ -7,9 +9,25 @@ export declare const MLS_DEVICES_ACT = "manage";
|
|
|
7
9
|
export declare const MLS_DEVICES_RES = "kumiai/devices";
|
|
8
10
|
export type DIDAuthenticationDependencies = {
|
|
9
11
|
deviceDenySet?: () => ReadonlySet<string>;
|
|
12
|
+
/** Registry context permits authenticated post-reset subject admission. */
|
|
13
|
+
deviceRegistry?: () => DeviceRegistry | undefined;
|
|
10
14
|
leafLifetime?: () => number | undefined;
|
|
11
15
|
trustedGrantLifetime?: () => number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this leaf may keep an issuer the deny set names, on its holder evidence. The caller
|
|
18
|
+
* answers for the group (its anchor names a controller) and for the leaf (it is the credential
|
|
19
|
+
* already in the tree at that index, or it arrives in a Welcome tree). Absent: never.
|
|
20
|
+
*/
|
|
21
|
+
mayKeepDeniedIssuer?: (credential: Credential, signaturePublicKey: Uint8Array) => boolean;
|
|
12
22
|
};
|
|
23
|
+
/** Structural evidence gate also used before MLS invokes its boolean authentication adapter. */
|
|
24
|
+
export declare function checkHolderEvidence(parsed: MLSCredentialIdentity, signaturePublicKey: Uint8Array, trustedGrantLifetime?: number): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* A chained leaf carrying its holder's own valid controller grant, for a holder the deny set does
|
|
27
|
+
* not name. Such a leaf names a device the controller bound itself, so denying the device that
|
|
28
|
+
* issued its capability does not take that binding away.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasHolderEvidence(parsed: MLSCredentialIdentity, signaturePublicKey: Uint8Array, denied: ReadonlySet<string>, trustedGrantLifetime?: number): boolean;
|
|
13
31
|
/** Internal throwing boundary for entry gates; ts-mls consumes the boolean adapter below. */
|
|
14
32
|
export declare function verifyLeafCredential(credential: Credential, signaturePublicKey: Uint8Array, deps?: DIDAuthenticationDependencies): Promise<void>;
|
|
15
33
|
/** Management grants are direct controller grants, verified at their issuance time. */
|
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';
|
|
@@ -76,8 +77,9 @@ function isDenied(denied, did) {
|
|
|
76
77
|
}
|
|
77
78
|
const token = readCapability(params.capability);
|
|
78
79
|
const payload = token.payload;
|
|
79
|
-
const
|
|
80
|
-
|
|
80
|
+
const ceiling = params.trustedGrant ? MAX_TRUSTED_GRANT_LIFETIME : MAX_LEAF_LIFETIME;
|
|
81
|
+
const lifetime = params.trustedGrant ? params.trustedGrantLifetime : params.leafLifetime;
|
|
82
|
+
assertCapabilityLifetime(payload, Math.min(lifetime ?? ceiling, ceiling));
|
|
81
83
|
if (normalizeDID(payload.sub) !== normalizeDID(params.controllerID)) {
|
|
82
84
|
throw new LeafBindingError('subject-mismatch');
|
|
83
85
|
}
|
|
@@ -152,16 +154,69 @@ function isDenied(denied, did) {
|
|
|
152
154
|
maxDepth: 1
|
|
153
155
|
});
|
|
154
156
|
}
|
|
157
|
+
function withoutIssuer(denied, capability) {
|
|
158
|
+
const issuer = normalizeDID(readCapability(capability).payload.iss);
|
|
159
|
+
return new Set([
|
|
160
|
+
...denied
|
|
161
|
+
].filter((did)=>normalizeDID(did) !== issuer));
|
|
162
|
+
}
|
|
163
|
+
/** Structural evidence gate also used before MLS invokes its boolean authentication adapter. */ export function checkHolderEvidence(parsed, signaturePublicKey, trustedGrantLifetime = MAX_TRUSTED_GRANT_LIFETIME) {
|
|
164
|
+
const binding = parsed.controller;
|
|
165
|
+
if (binding == null) return;
|
|
166
|
+
const leafPayload = readCapability(binding.capability).payload;
|
|
167
|
+
if (leafPayload.cap === undefined) return;
|
|
168
|
+
if (binding.holderGrant == null) throw new LeafBindingError('missing-holder-evidence');
|
|
169
|
+
try {
|
|
170
|
+
const grant = readCapability(binding.holderGrant).payload;
|
|
171
|
+
assertControllerGrant(grant, binding.id);
|
|
172
|
+
assertCapabilityLifetime(grant, Math.min(trustedGrantLifetime, MAX_TRUSTED_GRANT_LIFETIME));
|
|
173
|
+
if (grant.cap !== undefined || grant.iat > leafPayload.iat || grant.exp <= leafPayload.iat || grant.nbf != null && grant.nbf > leafPayload.iat || normalizeDID(grant.aud) !== normalizeDID(parsed.id) || !constantTimeEqual(capabilityKey(grant).publicKey, signaturePublicKey) || !hasPermission({
|
|
174
|
+
act: MLS_LEAF_ACT,
|
|
175
|
+
res: MLS_LEAF_RES
|
|
176
|
+
}, grant)) throw new LeafBindingError('holder-evidence-mismatch');
|
|
177
|
+
} catch (cause) {
|
|
178
|
+
const error = new LeafBindingError('holder-evidence-mismatch');
|
|
179
|
+
error.cause = cause;
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
return binding.holderGrant;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A chained leaf carrying its holder's own valid controller grant, for a holder the deny set does
|
|
186
|
+
* not name. Such a leaf names a device the controller bound itself, so denying the device that
|
|
187
|
+
* issued its capability does not take that binding away.
|
|
188
|
+
*/ export function hasHolderEvidence(parsed, signaturePublicKey, denied, trustedGrantLifetime) {
|
|
189
|
+
const binding = parsed.controller;
|
|
190
|
+
if (binding == null || isDenied(denied, parsed.id)) return false;
|
|
191
|
+
try {
|
|
192
|
+
if (readCapability(binding.capability).payload.cap === undefined) return false;
|
|
193
|
+
return checkHolderEvidence(parsed, signaturePublicKey, trustedGrantLifetime) != null;
|
|
194
|
+
} catch {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
155
198
|
/** Internal throwing boundary for entry gates; ts-mls consumes the boolean adapter below. */ export async function verifyLeafCredential(credential, signaturePublicKey, deps = {}) {
|
|
156
199
|
if (credential.credentialType !== defaultCredentialTypes.basic) {
|
|
157
200
|
throw new Error('Unsupported MLS credential type');
|
|
158
201
|
}
|
|
159
202
|
const parsed = parseMLSCredentialIdentity(credential.identity);
|
|
160
203
|
if (!matchesLeafKey(parsed, signaturePublicKey)) throw new LeafBindingError('identity-change');
|
|
161
|
-
const
|
|
162
|
-
|
|
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;
|
|
163
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
|
+
}
|
|
164
217
|
try {
|
|
218
|
+
// The holder grant does not inherit the leaf capability's issuer exception.
|
|
219
|
+
const leafDenySet = deps.mayKeepDeniedIssuer?.(credential, signaturePublicKey) && hasHolderEvidence(parsed, signaturePublicKey, denySet, deps.trustedGrantLifetime?.()) ? withoutIssuer(denySet, parsed.controller.capability) : denySet;
|
|
165
220
|
await verifyPinnedCapability({
|
|
166
221
|
capability: parsed.controller.capability,
|
|
167
222
|
prefix: parsed.controller.prefix,
|
|
@@ -172,10 +227,34 @@ function isDenied(denied, did) {
|
|
|
172
227
|
res: MLS_LEAF_RES
|
|
173
228
|
},
|
|
174
229
|
leafKey: signaturePublicKey,
|
|
175
|
-
denySet,
|
|
230
|
+
denySet: leafDenySet,
|
|
176
231
|
leafLifetime: deps.leafLifetime?.(),
|
|
177
232
|
trustedGrantLifetime: deps.trustedGrantLifetime?.()
|
|
178
233
|
});
|
|
234
|
+
const holderGrant = checkHolderEvidence(parsed, signaturePublicKey, deps.trustedGrantLifetime?.());
|
|
235
|
+
if (holderGrant != null) {
|
|
236
|
+
try {
|
|
237
|
+
await verifyPinnedCapability({
|
|
238
|
+
capability: holderGrant,
|
|
239
|
+
prefix: parsed.controller.prefix,
|
|
240
|
+
controllerID: parsed.controller.id,
|
|
241
|
+
audience: parsed.id,
|
|
242
|
+
permission: {
|
|
243
|
+
act: MLS_LEAF_ACT,
|
|
244
|
+
res: MLS_LEAF_RES
|
|
245
|
+
},
|
|
246
|
+
leafKey: signaturePublicKey,
|
|
247
|
+
denySet,
|
|
248
|
+
trustedGrantLifetime: deps.trustedGrantLifetime?.(),
|
|
249
|
+
directOnly: true,
|
|
250
|
+
trustedGrant: true
|
|
251
|
+
});
|
|
252
|
+
} catch (cause) {
|
|
253
|
+
const error = new LeafBindingError('holder-evidence-mismatch');
|
|
254
|
+
error.cause = cause;
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
179
258
|
} catch (error) {
|
|
180
259
|
if (error instanceof LeafBindingError) throw error;
|
|
181
260
|
const rejection = new LeafBindingError('signature-invalid');
|
package/lib/credential.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export type ControllerBinding = {
|
|
|
33
33
|
id: string;
|
|
34
34
|
prefix: Array<SignedEvent>;
|
|
35
35
|
capability: string;
|
|
36
|
+
/** The leaf holder's direct controller grant, required for chained capabilities. */
|
|
37
|
+
holderGrant?: string;
|
|
36
38
|
};
|
|
37
39
|
export type MLSCredentialIdentity = {
|
|
38
40
|
v?: 1;
|
|
@@ -63,21 +65,19 @@ export type GroupMember = {
|
|
|
63
65
|
};
|
|
64
66
|
export declare function parseMLSCredentialIdentity(identity: Uint8Array): MLSCredentialIdentity;
|
|
65
67
|
/**
|
|
66
|
-
* The normalized DID an MLS leaf credential names, or `
|
|
68
|
+
* The normalized DID an MLS leaf credential names, or `null` when it names none.
|
|
67
69
|
*
|
|
68
70
|
* Total by contract. The receive-side commit policy calls this on a leaf inside an untrusted
|
|
69
71
|
* commit, and `defaultCommitPolicy` is pure and total — a malformed credential must read as
|
|
70
72
|
* "no DID", never throw past the policy boundary. Every rejection `parseMLSCredentialIdentity`
|
|
71
|
-
* raises collapses to `
|
|
73
|
+
* raises collapses to `null` here: non-JSON bytes, a non-object value, an unsupported `v`, a
|
|
72
74
|
* non-string `id`, a non-string `longForm`.
|
|
73
75
|
*
|
|
74
76
|
* `credentialType !== basic` does not narrow on its own: `CredentialCustom.credentialType` is a
|
|
75
77
|
* bare `number`, so the compiler cannot rule it out. ts-mls's own guard can.
|
|
76
78
|
*
|
|
77
|
-
*
|
|
79
|
+
* An empty `id` names no DID and returns `null`.
|
|
80
|
+
* Syntax is not validated. An identity naming an arbitrary non-empty string returns that string, which no
|
|
78
81
|
* roster grants — a lookup miss, and deliberately distinct from a credential that names nothing.
|
|
79
|
-
*
|
|
80
|
-
* Not re-exported from the package index: `policy.ts` is the only consumer today, and widening the
|
|
81
|
-
* surface is cheap to do later and impossible to undo.
|
|
82
82
|
*/
|
|
83
|
-
export declare function didFromCredential(credential: Credential): string |
|
|
83
|
+
export declare function didFromCredential(credential: Credential): string | null;
|
package/lib/credential.js
CHANGED
|
@@ -50,40 +50,45 @@ export function parseMLSCredentialIdentity(identity) {
|
|
|
50
50
|
if (!Array.isArray(cc.prefix)) {
|
|
51
51
|
throw new Error('Invalid MLS credential: controller.prefix must be an array');
|
|
52
52
|
}
|
|
53
|
+
if ('holderGrant' in cc && typeof cc.holderGrant !== 'string') {
|
|
54
|
+
throw new Error('Invalid MLS credential: controller.holderGrant must be a string');
|
|
55
|
+
}
|
|
53
56
|
// Structural only — the prefix events are validated cryptographically by the fold in
|
|
54
57
|
// validateCredential, never here (parse stays pure/structural, like longForm).
|
|
55
58
|
result.controller = {
|
|
56
59
|
id: cc.id,
|
|
57
60
|
prefix: cc.prefix,
|
|
58
|
-
capability: cc.capability
|
|
61
|
+
capability: cc.capability,
|
|
62
|
+
...typeof cc.holderGrant === 'string' ? {
|
|
63
|
+
holderGrant: cc.holderGrant
|
|
64
|
+
} : {}
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
return result;
|
|
62
68
|
}
|
|
63
69
|
/**
|
|
64
|
-
* The normalized DID an MLS leaf credential names, or `
|
|
70
|
+
* The normalized DID an MLS leaf credential names, or `null` when it names none.
|
|
65
71
|
*
|
|
66
72
|
* Total by contract. The receive-side commit policy calls this on a leaf inside an untrusted
|
|
67
73
|
* commit, and `defaultCommitPolicy` is pure and total — a malformed credential must read as
|
|
68
74
|
* "no DID", never throw past the policy boundary. Every rejection `parseMLSCredentialIdentity`
|
|
69
|
-
* raises collapses to `
|
|
75
|
+
* raises collapses to `null` here: non-JSON bytes, a non-object value, an unsupported `v`, a
|
|
70
76
|
* non-string `id`, a non-string `longForm`.
|
|
71
77
|
*
|
|
72
78
|
* `credentialType !== basic` does not narrow on its own: `CredentialCustom.credentialType` is a
|
|
73
79
|
* bare `number`, so the compiler cannot rule it out. ts-mls's own guard can.
|
|
74
80
|
*
|
|
75
|
-
*
|
|
81
|
+
* An empty `id` names no DID and returns `null`.
|
|
82
|
+
* Syntax is not validated. An identity naming an arbitrary non-empty string returns that string, which no
|
|
76
83
|
* roster grants — a lookup miss, and deliberately distinct from a credential that names nothing.
|
|
77
|
-
*
|
|
78
|
-
* Not re-exported from the package index: `policy.ts` is the only consumer today, and widening the
|
|
79
|
-
* surface is cheap to do later and impossible to undo.
|
|
80
84
|
*/ export function didFromCredential(credential) {
|
|
81
85
|
if (!isDefaultCredential(credential) || credential.credentialType !== defaultCredentialTypes.basic) {
|
|
82
|
-
return
|
|
86
|
+
return null;
|
|
83
87
|
}
|
|
84
88
|
try {
|
|
85
|
-
|
|
89
|
+
const id = parseMLSCredentialIdentity(credential.identity).id;
|
|
90
|
+
return id === '' ? null : normalizeDID(id);
|
|
86
91
|
} catch {
|
|
87
|
-
return
|
|
92
|
+
return null;
|
|
88
93
|
}
|
|
89
94
|
}
|
package/lib/device-proof.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type LeafBinding = {
|
|
|
8
8
|
/** The embedded controller log prefix (present iff bound), for resolving a capability signature. */
|
|
9
9
|
prefix?: Array<SignedEvent>;
|
|
10
10
|
capability?: string;
|
|
11
|
+
holderGrant?: string;
|
|
11
12
|
/** The leaf's MLS signature public key. */
|
|
12
13
|
leafKey: Uint8Array;
|
|
13
14
|
};
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type LeafBindingReason = 'issuer-mismatch' | 'audience-mismatch' | 'permission-denied' | 'signature-invalid' | 'confirmation-invalid' | 'subject-mismatch' | 'chain-depth' | 'self-issued' | 'child-outlives-parent' | 'denied-issuer' | 'denied-id' | 'renewal-order' | 'lifetime-cap' | 'generation-floor' | 'identity-change' | 'controller-mismatch' | 'floating-refused' | 'history-horizon';
|
|
1
|
+
export type LeafBindingReason = 'missing-holder-evidence' | 'holder-evidence-mismatch' | 'issuer-mismatch' | 'audience-mismatch' | 'permission-denied' | 'signature-invalid' | 'confirmation-invalid' | 'subject-mismatch' | 'chain-depth' | 'self-issued' | 'child-outlives-parent' | 'denied-issuer' | 'denied-id' | 'renewal-order' | 'lifetime-cap' | 'generation-floor' | 'identity-change' | 'controller-mismatch' | 'floating-refused' | 'history-horizon';
|
|
2
2
|
export declare class LeafBindingError extends Error {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(reason: LeafBindingReason);
|
package/lib/group-commit.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SigningIdentity } from '@kokuin/token';
|
|
2
|
-
import { type ClientState, createCommit, type DefaultProposal, type KeyPackage } from 'ts-mls';
|
|
2
|
+
import { type ClientState, createCommit, type DefaultProposal, type KeyPackage, type UnappliedProposals } from 'ts-mls';
|
|
3
3
|
import { type GroupHandle } from './group-handle.js';
|
|
4
4
|
import { type GroupPermission } from './roster.js';
|
|
5
5
|
import type { Invite } from './types.js';
|
|
@@ -37,6 +37,8 @@ export declare function createInvite(params: CreateInviteParams): Promise<Create
|
|
|
37
37
|
export type CommitWithEntriesParams = {
|
|
38
38
|
group: GroupHandle;
|
|
39
39
|
extraProposals: Array<DefaultProposal>;
|
|
40
|
+
/** Pending proposals to commit by reference, retaining their authenticated senders. */
|
|
41
|
+
pendingProposals?: UnappliedProposals;
|
|
40
42
|
enacted: Array<string>;
|
|
41
43
|
ratchetTreeExtension?: boolean;
|
|
42
44
|
/** Defaults to true; device and lifecycle entries carry their own authority. */
|
package/lib/group-commit.js
CHANGED
|
@@ -6,10 +6,10 @@ import { verifyDeviceEntry } from './device-proof.js';
|
|
|
6
6
|
import { encodeControlEnvelope } from './envelope.js';
|
|
7
7
|
import { foldEnvelope } from './envelope-fold.js';
|
|
8
8
|
import { assertBindingAuthorTime } from './group-credential.js';
|
|
9
|
-
import { buildCommitPolicyContext, deriveGroup, mutexFor } from './group-handle.js';
|
|
9
|
+
import { buildCommitPolicyContext, CommitRejectedError, deriveGroup, mutexFor } from './group-handle.js';
|
|
10
10
|
import { buildLedgerHeadExtension, extendHead, readLedgerHead } from './head.js';
|
|
11
11
|
import { ledgerEntryDigest, signLedgerEntry, verifyLedgerEntry } from './ledger.js';
|
|
12
|
-
import { prepareLifecycleGate, validateEntry } from './lifecycle.js';
|
|
12
|
+
import { prepareLifecycleGate, rejectionReason, validateEntry } from './lifecycle.js';
|
|
13
13
|
import { authority, controllerOf, DEVICE_ENTRY_TYPE } from './registry.js';
|
|
14
14
|
import { ROLE_ENTRY_TYPE } from './roster.js';
|
|
15
15
|
/** The supplied key package names a different identity from the invite's recipient. */ export class InviteRecipientMismatchError extends Error {
|
|
@@ -178,7 +178,7 @@ import { ROLE_ENTRY_TYPE } from './roster.js';
|
|
|
178
178
|
});
|
|
179
179
|
const commitState = {
|
|
180
180
|
...params.commitState ?? group.state,
|
|
181
|
-
unappliedProposals: {}
|
|
181
|
+
unappliedProposals: params.pendingProposals ?? {}
|
|
182
182
|
};
|
|
183
183
|
const proposals = [
|
|
184
184
|
...extraProposals
|
|
@@ -200,12 +200,22 @@ import { ROLE_ENTRY_TYPE } from './roster.js';
|
|
|
200
200
|
const incoming = {
|
|
201
201
|
kind: 'commit',
|
|
202
202
|
senderLeafIndex: group.state.privatePath.leafIndex,
|
|
203
|
-
proposals:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
proposals: [
|
|
204
|
+
...Object.values(commitState.unappliedProposals),
|
|
205
|
+
...proposals.map((proposal)=>({
|
|
206
|
+
proposal,
|
|
207
|
+
senderLeafIndex: group.state.privatePath.leafIndex
|
|
208
|
+
}))
|
|
209
|
+
]
|
|
207
210
|
};
|
|
208
|
-
|
|
211
|
+
try {
|
|
212
|
+
gate.check(incoming);
|
|
213
|
+
} catch (cause) {
|
|
214
|
+
if (params.pendingProposals == null) throw cause;
|
|
215
|
+
const error = new CommitRejectedError(incoming.proposals, incoming.senderLeafIndex, rejectionReason(cause));
|
|
216
|
+
error.cause = cause;
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
209
219
|
for (const proposal of proposals){
|
|
210
220
|
if (proposal.proposalType === defaultProposalTypes.add) {
|
|
211
221
|
const leaf = proposal.add.keyPackage.leafNode;
|
|
@@ -331,16 +341,16 @@ import { ROLE_ENTRY_TYPE } from './roster.js';
|
|
|
331
341
|
// `credentialType !== basic` does not narrow on its own: CredentialCustom.credentialType is a
|
|
332
342
|
// bare `number`, so the compiler cannot rule it out. ts-mls's own guard can.
|
|
333
343
|
//
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
//
|
|
337
|
-
// is deliberately unexported. The two must stay in agreement — if they diverge, the committer
|
|
338
|
-
// authors a commit every receiver rejects, a liveness failure rather than a security one.
|
|
344
|
+
// The exported `didFromCredential` collapses absent identities to null. This inlined variant
|
|
345
|
+
// distinguishes non-basic credentials from malformed JSON for its error messages.
|
|
346
|
+
// DID normalisation must agree with the helper, or receivers reject the authored commit.
|
|
339
347
|
const credential = keyPackage.leafNode.credential;
|
|
340
348
|
if (!isDefaultCredential(credential) || credential.credentialType !== defaultCredentialTypes.basic) {
|
|
341
349
|
throw new Error('commitInvite: the key package carries a non-basic credential, which names no DID to bind');
|
|
342
350
|
}
|
|
343
|
-
const
|
|
351
|
+
const recipientID = parseMLSCredentialIdentity(credential.identity).id;
|
|
352
|
+
if (recipientID === '') throw new Error('commitInvite: the recipient credential names no DID');
|
|
353
|
+
const actualDID = normalizeDID(recipientID);
|
|
344
354
|
if (actualDID !== expectedDID) {
|
|
345
355
|
throw new InviteRecipientMismatchError({
|
|
346
356
|
groupID: group.groupID,
|
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.d.ts
CHANGED
|
@@ -256,6 +256,15 @@ export declare class GroupHandle {
|
|
|
256
256
|
* consequences of this method's plainness; wrapping it "for consistency" breaks both.
|
|
257
257
|
*/
|
|
258
258
|
exportSecret(label: string, context: Uint8Array, length?: number): Promise<Uint8Array>;
|
|
259
|
+
/**
|
|
260
|
+
* Author and retain an authenticated self-removal proposal under the handle mutex.
|
|
261
|
+
* Once a member processes a pending self-removal, application encrypt throws until
|
|
262
|
+
* a commit lands. Callers should commit pending self-removals promptly.
|
|
263
|
+
*/
|
|
264
|
+
proposeSelfRemoval(): Promise<{
|
|
265
|
+
frame: Uint8Array;
|
|
266
|
+
epoch: bigint;
|
|
267
|
+
}>;
|
|
259
268
|
/**
|
|
260
269
|
* Encrypt an application message for the group at this handle's current epoch,
|
|
261
270
|
* returning framed wire bytes. A handle a commit has already superseded (see
|
|
@@ -371,6 +380,7 @@ export declare class GroupHandle {
|
|
|
371
380
|
* Process a received MLS message (Commit, Proposal, or application). Accepts
|
|
372
381
|
* wire-form bytes (preferred, e.g. from commitInvite/removeMember) or a pre-decoded
|
|
373
382
|
* ts-mls framed message (legacy). The runtime `instanceof` selects the decode path.
|
|
383
|
+
* A proposal from a past epoch is ignored (returns null, nothing persisted).
|
|
374
384
|
* `persist` covers accepted commits and proposals, not application messages or their
|
|
375
385
|
* receive ratchet. It runs under this handle's mutex and must not call back into it.
|
|
376
386
|
* It must write atomically: rejection means nothing was stored. Host callbacks run
|