@kumiai/mls 0.9.0 → 0.10.1
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 +23 -0
- package/lib/anchor.d.ts +10 -4
- package/lib/anchor.js +26 -2
- package/lib/authentication.d.ts +11 -14
- package/lib/authentication.js +127 -86
- package/lib/capability.d.ts +37 -0
- package/lib/capability.js +141 -0
- package/lib/codec.js +2 -1
- package/lib/device-proof.d.ts +1 -0
- package/lib/device-proof.js +8 -12
- package/lib/envelope-fold.d.ts +16 -1
- package/lib/envelope-fold.js +49 -9
- package/lib/errors.d.ts +18 -0
- package/lib/errors.js +33 -0
- package/lib/group-commit.d.ts +22 -35
- package/lib/group-commit.js +122 -103
- package/lib/group-context.d.ts +6 -2
- package/lib/group-context.js +11 -4
- package/lib/group-create.js +56 -11
- package/lib/group-credential.d.ts +3 -1
- package/lib/group-credential.js +17 -3
- package/lib/group-device.js +34 -21
- package/lib/group-handle.d.ts +60 -24
- package/lib/group-handle.js +331 -77
- package/lib/group-info.d.ts +8 -0
- package/lib/group-info.js +29 -1
- package/lib/group-lifecycle.d.ts +32 -0
- package/lib/group-lifecycle.js +300 -0
- package/lib/group-membership.js +7 -3
- package/lib/group-welcome.d.ts +13 -4
- package/lib/group-welcome.js +113 -21
- package/lib/group.d.ts +3 -2
- package/lib/group.js +2 -1
- package/lib/history.d.ts +6 -0
- package/lib/history.js +26 -0
- package/lib/index.d.ts +10 -4
- package/lib/index.js +9 -3
- package/lib/lifecycle-proof.d.ts +24 -0
- package/lib/lifecycle-proof.js +193 -0
- package/lib/lifecycle.d.ts +44 -0
- package/lib/lifecycle.js +385 -0
- package/lib/policy.d.ts +20 -0
- package/lib/policy.js +8 -4
- package/lib/recovery-verdict.d.ts +43 -0
- package/lib/recovery-verdict.js +135 -0
- package/lib/recovery.d.ts +70 -0
- package/lib/recovery.js +110 -36
- package/lib/registry.d.ts +34 -7
- package/lib/registry.js +113 -15
- package/lib/roster.d.ts +1 -1
- package/lib/roster.js +2 -2
- package/lib/types.d.ts +13 -8
- package/lib/welcome-refs.d.ts +2 -1
- package/package.json +6 -6
package/lib/group-create.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
2
|
import { generateKeyPackageWithKey, createGroup as mlsCreateGroup } from 'ts-mls';
|
|
3
|
-
import { buildCurrentGroupAnchorExtension, decodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
|
|
3
|
+
import { buildCurrentGroupAnchorExtension, buildGroupAnchorExtension, decodeGroupAnchor, GROUP_ANCHOR_EXTENSION_TYPE, LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
|
|
4
|
+
import { verifyLeafCredential } from './authentication.js';
|
|
5
|
+
import { LeafBindingError } from './errors.js';
|
|
4
6
|
import { buildLeafCapabilities, resolveMlsContext } from './group-context.js';
|
|
5
|
-
import { makeMLSCredential } from './group-credential.js';
|
|
7
|
+
import { assertBindingAuthorTime, makeMLSCredential } from './group-credential.js';
|
|
6
8
|
import { GroupHandle } from './group-handle.js';
|
|
7
9
|
import { buildLedgerHeadExtension, genesisHead } from './head.js';
|
|
8
10
|
/** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup(identity, groupID, options) {
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// its contents); its `creatorDID` coupling to the creating identity is validated
|
|
13
|
-
// below. A decode failure here is left to the fail-closed decode in the constructor.
|
|
11
|
+
assertBindingAuthorTime(options?.controller);
|
|
12
|
+
// A binding enriches a supplied anchor before genesis; standard anchor bytes stay untouched.
|
|
13
|
+
// Existing lifecycle fields must agree with the authored policy before the tree is validated.
|
|
14
14
|
const extensions = [
|
|
15
15
|
...options?.extensions ?? []
|
|
16
16
|
];
|
|
@@ -21,15 +21,60 @@ import { buildLedgerHeadExtension, genesisHead } from './head.js';
|
|
|
21
21
|
if (suppliedAnchor != null && normalizeDID(suppliedAnchor.creatorDID) !== normalizeDID(identity.id)) {
|
|
22
22
|
throw new Error(`createGroup: the anchor's creatorDID (${suppliedAnchor.creatorDID}) must be the creating identity (${identity.id})`);
|
|
23
23
|
}
|
|
24
|
+
if (suppliedAnchor != null && suppliedAnchorData instanceof Uint8Array && options?.controller != null) {
|
|
25
|
+
const leafLifetime = options.leafLifetime ?? 86_400;
|
|
26
|
+
const trustedGrantLifetime = options.trustedGrantLifetime ?? 2_592_000;
|
|
27
|
+
if (suppliedAnchor.controller !== undefined && suppliedAnchor.controller !== options.controller.id) {
|
|
28
|
+
throw new LeafBindingError('controller-mismatch');
|
|
29
|
+
}
|
|
30
|
+
if (suppliedAnchor.leafLifetime !== undefined && suppliedAnchor.leafLifetime !== leafLifetime || suppliedAnchor.trustedGrantLifetime !== undefined && suppliedAnchor.trustedGrantLifetime !== trustedGrantLifetime) {
|
|
31
|
+
throw new Error('Lifecycle lifetime options must match the supplied anchor');
|
|
32
|
+
}
|
|
33
|
+
// Reading normally withholds future-version app payloads; authoring must preserve them.
|
|
34
|
+
const original = JSON.parse(new TextDecoder().decode(suppliedAnchorData));
|
|
35
|
+
extensions[extensions.indexOf(suppliedAnchorExtension)] = buildGroupAnchorExtension({
|
|
36
|
+
...suppliedAnchor,
|
|
37
|
+
app: original.app,
|
|
38
|
+
controller: options.controller.id,
|
|
39
|
+
leafLifetime,
|
|
40
|
+
trustedGrantLifetime
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (suppliedAnchorExtension == null) {
|
|
45
|
+
extensions.push(options?.controller == null ? buildCurrentGroupAnchorExtension(identity.id) : buildGroupAnchorExtension({
|
|
46
|
+
creatorDID: identity.id,
|
|
47
|
+
version: 1,
|
|
48
|
+
controller: options.controller.id,
|
|
49
|
+
leafLifetime: options.leafLifetime ?? 86_400,
|
|
50
|
+
trustedGrantLifetime: options.trustedGrantLifetime ?? 2_592_000
|
|
51
|
+
}));
|
|
24
52
|
}
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
const anchorExtension = extensions.find((ext)=>ext.extensionType === GROUP_ANCHOR_EXTENSION_TYPE);
|
|
54
|
+
const anchorData = anchorExtension?.extensionData;
|
|
55
|
+
const anchor = anchorData instanceof Uint8Array ? decodeGroupAnchor(anchorData) : null;
|
|
56
|
+
if (anchor == null) throw new Error('group anchor extension present but could not be decoded');
|
|
57
|
+
if (anchor.controller != null) {
|
|
58
|
+
if (options?.controller == null) throw new LeafBindingError('floating-refused');
|
|
59
|
+
if (normalizeDID(anchor.controller) !== normalizeDID(options.controller.id)) {
|
|
60
|
+
throw new LeafBindingError('controller-mismatch');
|
|
61
|
+
}
|
|
62
|
+
} else if (options?.controller != null) {
|
|
63
|
+
throw new LeafBindingError('controller-mismatch');
|
|
64
|
+
}
|
|
65
|
+
const context = await resolveMlsContext(options, anchor);
|
|
66
|
+
const mlsCredential = makeMLSCredential(identity, options?.controller);
|
|
67
|
+
if (options?.controller != null) {
|
|
68
|
+
await verifyLeafCredential(mlsCredential, identity.publicKey, {
|
|
69
|
+
leafLifetime: ()=>anchor.leafLifetime ?? 86_400,
|
|
70
|
+
trustedGrantLifetime: ()=>anchor.trustedGrantLifetime ?? 2_592_000
|
|
71
|
+
});
|
|
27
72
|
}
|
|
28
73
|
if (!extensions.some((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE)) {
|
|
29
74
|
extensions.push(buildLedgerHeadExtension(genesisHead(groupID)));
|
|
30
75
|
}
|
|
31
76
|
const statePromise = generateKeyPackageWithKey({
|
|
32
|
-
credential:
|
|
77
|
+
credential: mlsCredential,
|
|
33
78
|
signatureKeyPair: {
|
|
34
79
|
signKey: identity.privateKey,
|
|
35
80
|
publicKey: identity.publicKey
|
|
@@ -64,7 +109,7 @@ import { buildLedgerHeadExtension, genesisHead } from './head.js';
|
|
|
64
109
|
};
|
|
65
110
|
}
|
|
66
111
|
export async function restoreGroup(params) {
|
|
67
|
-
// Construction reseeds
|
|
112
|
+
// Construction reseeds control authority from the anchor in the restored state;
|
|
68
113
|
// an anchorless state throws (the same fail-closed guard).
|
|
69
114
|
const group = new GroupHandle({
|
|
70
115
|
state: params.state,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type OwnIdentity } from '@kokuin/token';
|
|
2
2
|
import { type Credential } from 'ts-mls';
|
|
3
|
+
import type { ControllerBinding } from './credential.js';
|
|
3
4
|
import type { GroupOptions, KeyPackageBundle } from './types.js';
|
|
4
|
-
export declare function makeMLSCredential(identity: OwnIdentity): Credential;
|
|
5
|
+
export declare function makeMLSCredential(identity: OwnIdentity, controller?: ControllerBinding): Credential;
|
|
6
|
+
export declare function assertBindingAuthorTime(controller?: ControllerBinding): void;
|
|
5
7
|
/**
|
|
6
8
|
* How long an ordinary, single-use key package stays valid, in days.
|
|
7
9
|
*
|
package/lib/group-credential.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { isPeer4 } from '@kokuin/token';
|
|
1
|
+
import { isPeer4, now } from '@kokuin/token';
|
|
2
2
|
import { defaultCredentialTypes, generateKeyPackageWithKey, greaseExtensions, makeCustomExtension } from 'ts-mls';
|
|
3
3
|
import { controlCapabilities } from './anchor.js';
|
|
4
|
+
import { verifyLeafCredential } from './authentication.js';
|
|
5
|
+
import { readCapability } from './capability.js';
|
|
4
6
|
import { resolveMlsContext } from './group-context.js';
|
|
5
|
-
export function makeMLSCredential(identity) {
|
|
7
|
+
export function makeMLSCredential(identity, controller) {
|
|
6
8
|
const id = identity.id;
|
|
7
9
|
const isPeer = isPeer4(id);
|
|
8
10
|
if (isPeer && !('longForm' in identity && typeof identity.longForm === 'string')) {
|
|
@@ -12,6 +14,7 @@ export function makeMLSCredential(identity) {
|
|
|
12
14
|
v: 1,
|
|
13
15
|
id
|
|
14
16
|
};
|
|
17
|
+
if (controller != null) payload.controller = controller;
|
|
15
18
|
if (isPeer) {
|
|
16
19
|
payload.longForm = identity.longForm;
|
|
17
20
|
}
|
|
@@ -20,6 +23,14 @@ export function makeMLSCredential(identity) {
|
|
|
20
23
|
identity: new TextEncoder().encode(JSON.stringify(payload))
|
|
21
24
|
};
|
|
22
25
|
}
|
|
26
|
+
export function assertBindingAuthorTime(controller) {
|
|
27
|
+
if (controller == null) return;
|
|
28
|
+
const { iat, exp } = readCapability(controller.capability).payload;
|
|
29
|
+
const timestamp = now();
|
|
30
|
+
if (exp <= timestamp || iat > timestamp) {
|
|
31
|
+
throw new Error('Leaf capability is not valid at authoring time');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
23
34
|
/**
|
|
24
35
|
* Shared key-package construction. An invitee leaf must advertise the control extension types or
|
|
25
36
|
* ts-mls refuses to add it to an anchored group. An explicit `options.capabilities` override still
|
|
@@ -29,9 +40,12 @@ export function makeMLSCredential(identity) {
|
|
|
29
40
|
* so `generateKeyPackageWithKey`'s own `params.extensions ?? greaseExtensions(...)` default still
|
|
30
41
|
* applies for the ordinary path.
|
|
31
42
|
*/ async function buildBundle(identity, options, overrides = {}) {
|
|
43
|
+
assertBindingAuthorTime(options?.controller);
|
|
44
|
+
const credential = makeMLSCredential(identity, options?.controller);
|
|
45
|
+
if (options?.controller != null) await verifyLeafCredential(credential, identity.publicKey);
|
|
32
46
|
const { cipherSuite } = await resolveMlsContext(options);
|
|
33
47
|
const result = await generateKeyPackageWithKey({
|
|
34
|
-
credential
|
|
48
|
+
credential,
|
|
35
49
|
signatureKeyPair: {
|
|
36
50
|
signKey: identity.privateKey,
|
|
37
51
|
publicKey: identity.publicKey
|
package/lib/group-device.js
CHANGED
|
@@ -24,9 +24,12 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
24
24
|
} : {}
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
-
const result = await commitWithEntries(
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const result = await commitWithEntries({
|
|
28
|
+
group,
|
|
29
|
+
extraProposals: [],
|
|
30
|
+
enacted: [
|
|
31
|
+
token
|
|
32
|
+
],
|
|
30
33
|
requireAdmin: false
|
|
31
34
|
});
|
|
32
35
|
const newGroup = deriveGroup(group, result.newState);
|
|
@@ -55,9 +58,12 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
55
58
|
capability: params.capability
|
|
56
59
|
}
|
|
57
60
|
});
|
|
58
|
-
const result = await commitWithEntries(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const result = await commitWithEntries({
|
|
62
|
+
group,
|
|
63
|
+
extraProposals: [],
|
|
64
|
+
enacted: [
|
|
65
|
+
token
|
|
66
|
+
],
|
|
61
67
|
requireAdmin: false
|
|
62
68
|
});
|
|
63
69
|
const newGroup = deriveGroup(group, result.newState);
|
|
@@ -103,11 +109,14 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
103
109
|
keyPackage: params.keyPackage
|
|
104
110
|
}
|
|
105
111
|
};
|
|
106
|
-
const result = await commitWithEntries(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
const result = await commitWithEntries({
|
|
113
|
+
group,
|
|
114
|
+
extraProposals: [
|
|
115
|
+
addProposal
|
|
116
|
+
],
|
|
117
|
+
enacted: [
|
|
118
|
+
token
|
|
119
|
+
],
|
|
111
120
|
ratchetTreeExtension: true,
|
|
112
121
|
requireAdmin: false
|
|
113
122
|
});
|
|
@@ -153,16 +162,18 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
164
|
];
|
|
156
|
-
const result = await commitWithEntries(
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
const result = await commitWithEntries({
|
|
166
|
+
group,
|
|
167
|
+
extraProposals: proposals,
|
|
168
|
+
enacted: [
|
|
169
|
+
token
|
|
170
|
+
],
|
|
159
171
|
requireAdmin: false
|
|
160
172
|
});
|
|
161
173
|
const newGroup = deriveGroup(group, result.newState);
|
|
162
|
-
|
|
174
|
+
await newGroup.applyLedgerEntries([
|
|
163
175
|
token
|
|
164
176
|
]);
|
|
165
|
-
newGroup.emitControlEvents(enacted);
|
|
166
177
|
return {
|
|
167
178
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
168
179
|
newGroup,
|
|
@@ -187,16 +198,18 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
187
198
|
headDigest: params.headDigest
|
|
188
199
|
}
|
|
189
200
|
});
|
|
190
|
-
const result = await commitWithEntries(
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
const result = await commitWithEntries({
|
|
202
|
+
group,
|
|
203
|
+
extraProposals: [],
|
|
204
|
+
enacted: [
|
|
205
|
+
token
|
|
206
|
+
],
|
|
193
207
|
requireAdmin: false
|
|
194
208
|
});
|
|
195
209
|
const newGroup = deriveGroup(group, result.newState);
|
|
196
|
-
|
|
210
|
+
await newGroup.applyLedgerEntries([
|
|
197
211
|
token
|
|
198
212
|
]);
|
|
199
|
-
newGroup.emitControlEvents(enacted);
|
|
200
213
|
return {
|
|
201
214
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
202
215
|
newGroup,
|
package/lib/group-handle.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { EventEmitter, type EventsSource } from '@sozai/event';
|
|
2
|
-
import { type ClientState, type IncomingMessageCallback, type MlsContext, type ProposalWithSender } from 'ts-mls';
|
|
2
|
+
import { type ClientState, type IncomingMessageCallback, type MlsContext, type MlsFramedMessage, type ProposalWithSender } from 'ts-mls';
|
|
3
3
|
import { type GroupAnchor } from './anchor.js';
|
|
4
4
|
import { type GroupMember, type MemberCredential } from './credential.js';
|
|
5
5
|
import { type LeafBinding } from './device-proof.js';
|
|
6
6
|
import { type VerifiedLedgerEntry } from './ledger.js';
|
|
7
|
+
import { type CommitRejectionReason } from './lifecycle.js';
|
|
7
8
|
import { type Mutex } from './mutex.js';
|
|
8
9
|
import { type CommitPolicyContext } from './policy.js';
|
|
9
10
|
import { type DeviceOp, type DeviceRegistry } from './registry.js';
|
|
@@ -15,6 +16,9 @@ export type GroupHandleEvents = {
|
|
|
15
16
|
deviceRevoked: Array<{
|
|
16
17
|
device: string;
|
|
17
18
|
controller: string;
|
|
19
|
+
logPosition?: number;
|
|
20
|
+
reason?: 'reset';
|
|
21
|
+
cascadedFrom?: string;
|
|
18
22
|
}>;
|
|
19
23
|
controllerBeaconChanged: {
|
|
20
24
|
controller: string;
|
|
@@ -22,13 +26,22 @@ export type GroupHandleEvents = {
|
|
|
22
26
|
headDigest: string;
|
|
23
27
|
};
|
|
24
28
|
};
|
|
29
|
+
export type SendAdmission = {
|
|
30
|
+
epoch: number;
|
|
31
|
+
admissible: true;
|
|
32
|
+
} | {
|
|
33
|
+
epoch: number;
|
|
34
|
+
admissible: false;
|
|
35
|
+
reason: 'lapsed';
|
|
36
|
+
};
|
|
25
37
|
/** The full emitter for a handle — module-internal, for deriveGroup to share it onward. */
|
|
26
38
|
export declare function emitterOf(group: GroupHandle): EventEmitter<GroupHandleEvents>;
|
|
27
39
|
/** Thrown by GroupHandle.processMessage when the commit policy rejects an incoming
|
|
28
40
|
* commit. The handle is left at its pre-commit epoch. */
|
|
29
41
|
export declare class CommitRejectedError extends Error {
|
|
30
42
|
#private;
|
|
31
|
-
constructor(proposals: Array<ProposalWithSender>, senderLeafIndex?: number);
|
|
43
|
+
constructor(proposals: Array<ProposalWithSender>, senderLeafIndex?: number, reason?: CommitRejectionReason);
|
|
44
|
+
get reason(): CommitRejectionReason;
|
|
32
45
|
get proposals(): Array<ProposalWithSender>;
|
|
33
46
|
get senderLeafIndex(): number | undefined;
|
|
34
47
|
}
|
|
@@ -62,11 +75,15 @@ export type GroupHandleParams = {
|
|
|
62
75
|
onLedgerEntries?: (entries: Array<VerifiedLedgerEntry>) => void;
|
|
63
76
|
/** Shared event emitter; a derived handle inherits its parent's so subscriptions persist. */
|
|
64
77
|
events?: EventEmitter<GroupHandleEvents>;
|
|
78
|
+
/** Defer authored control notifications until adoption. */
|
|
79
|
+
speculative?: boolean;
|
|
65
80
|
};
|
|
66
81
|
/** Mutable wrapper around MLS group state + Enkaku credential. */
|
|
67
82
|
export declare class GroupHandle {
|
|
68
83
|
#private;
|
|
69
84
|
constructor(params: GroupHandleParams);
|
|
85
|
+
sendAdmission(): SendAdmission;
|
|
86
|
+
confirmAdopted(): void;
|
|
70
87
|
get groupID(): string;
|
|
71
88
|
get epoch(): bigint;
|
|
72
89
|
get treeHash(): Uint8Array;
|
|
@@ -115,11 +132,10 @@ export declare class GroupHandle {
|
|
|
115
132
|
}>;
|
|
116
133
|
/**
|
|
117
134
|
* @internal Fire notification events for the device entries just enacted in one operation.
|
|
118
|
-
* Called
|
|
135
|
+
* Called after acceptance or adoption — NEVER from
|
|
119
136
|
* the constructor or a fresh-join applyLedgerEntries, so a joiner is not replayed the whole
|
|
120
137
|
* history as live events (it reads revokedDevices()/beaconOf for current state instead). Uses
|
|
121
|
-
* `fire`: a throwing listener is swallowed and cannot break the fold. Reads
|
|
122
|
-
* POST-fold registry.
|
|
138
|
+
* `fire`: a throwing listener is swallowed and cannot break the fold. Reads the post-fold registry.
|
|
123
139
|
*/
|
|
124
140
|
emitControlEvents(enacted: ReadonlyArray<VerifiedLedgerEntry>): void;
|
|
125
141
|
/**
|
|
@@ -177,9 +193,13 @@ export declare class GroupHandle {
|
|
|
177
193
|
* signatures do not. The bound: **a lying responder can withhold, never rewrite.**
|
|
178
194
|
*
|
|
179
195
|
* Throws {@link LedgerIncompleteError} on a head mismatch; the caller drops that
|
|
180
|
-
* responder and tries the next.
|
|
196
|
+
* responder and tries the next. `persist` runs under this handle's mutex and must not
|
|
197
|
+
* call back into it. It must write atomically: rejection means nothing was stored.
|
|
198
|
+
* Host callbacks run after successful persist; a callback throw does not undo bootstrap.
|
|
181
199
|
*/
|
|
182
|
-
bootstrapLedger(tokens: Array<string
|
|
200
|
+
bootstrapLedger(tokens: Array<string>, opts?: {
|
|
201
|
+
persist?: (handle: GroupHandle) => Promise<void> | void;
|
|
202
|
+
}): Promise<void>;
|
|
183
203
|
get memberCount(): number;
|
|
184
204
|
findMemberLeafIndex(id: string): number | undefined;
|
|
185
205
|
/**
|
|
@@ -200,10 +220,10 @@ export declare class GroupHandle {
|
|
|
200
220
|
* The diff sees MEMBERSHIP, and only membership: an Add, a Remove, or both in
|
|
201
221
|
* one commit (compare as a set — a count misses that last case). It does NOT
|
|
202
222
|
* see an external-commit REJOIN by a member the group still holds. That member
|
|
203
|
-
* keeps its id, so the id set is unchanged;
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
223
|
+
* keeps its id, so the id set is unchanged; the new leaf takes the leftmost blank, which is the
|
|
224
|
+
* just-vacated slot only when no earlier blank exists — otherwise the rejoiner's `leafIndex`
|
|
225
|
+
* moves. Only the id-set projection of this result is guaranteed unchanged across a rejoin;
|
|
226
|
+
* `leafIndex` is not, so a before/after diff on `leafIndex` cannot be relied on either.
|
|
207
227
|
* A caller that must detect a rejoin reads the COMMIT instead — an external
|
|
208
228
|
* commit is structurally one: a public message from a non-member carrying a
|
|
209
229
|
* commit, recognizable from its own bytes before it is applied, and carrying
|
|
@@ -254,12 +274,10 @@ export declare class GroupHandle {
|
|
|
254
274
|
* Open an application message sealed for the group and recover WHO SENT IT — the
|
|
255
275
|
* counterpart to {@link encrypt}, and the read half of the group's application lane.
|
|
256
276
|
*
|
|
257
|
-
* Throws for bytes this handle cannot open
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* — it is how a frame says "not mine" — and such a caller must not read the throw as
|
|
262
|
-
* corruption. Use {@link readMessageEpoch} to tell those two cases apart before trying.
|
|
277
|
+
* Throws for bytes this handle cannot open. A future-epoch frame cannot open yet;
|
|
278
|
+
* ts-mls can open some past-epoch frames while their retained key material lasts.
|
|
279
|
+
* That window is bounded by epoch transitions. Use {@link readMessageEpoch} to
|
|
280
|
+
* distinguish an epoch mismatch from malformed bytes before trying.
|
|
263
281
|
*
|
|
264
282
|
* WHY THE SENDER IS AUTHENTICATED and not merely claimed: the leaf index comes from the
|
|
265
283
|
* message's sender-data, encrypted under this epoch's sender-data secret, and the
|
|
@@ -286,6 +304,23 @@ export declare class GroupHandle {
|
|
|
286
304
|
senderDID?: string;
|
|
287
305
|
aad: Uint8Array;
|
|
288
306
|
}>;
|
|
307
|
+
/**
|
|
308
|
+
* Open an application frame, but make its post-open state durable before adopting it.
|
|
309
|
+
* The callback runs under this handle's mutex and must store `stagedState` as the
|
|
310
|
+
* group's handle state. It must not call this handle or the peer. If opening or
|
|
311
|
+
* persistence fails, the live state and its ratchet secrets remain untouched.
|
|
312
|
+
*/
|
|
313
|
+
decryptStaged(message: Uint8Array, opts: {
|
|
314
|
+
expectedAAD?: Uint8Array;
|
|
315
|
+
}, persist: (stagedState: Uint8Array, opened: {
|
|
316
|
+
payload: Uint8Array;
|
|
317
|
+
senderDID: string;
|
|
318
|
+
aad: Uint8Array;
|
|
319
|
+
}) => Promise<void>): Promise<{
|
|
320
|
+
payload: Uint8Array;
|
|
321
|
+
senderDID: string;
|
|
322
|
+
aad: Uint8Array;
|
|
323
|
+
}>;
|
|
289
324
|
/**
|
|
290
325
|
* The device-proof binding at the leaf naming `did`: its bound controller (if any), the embedded
|
|
291
326
|
* controller-log prefix (if bound), and the leaf signature key. Reads the CURRENT ratchet tree —
|
|
@@ -335,17 +370,18 @@ export declare class GroupHandle {
|
|
|
335
370
|
/**
|
|
336
371
|
* Process a received MLS message (Commit, Proposal, or application). Accepts
|
|
337
372
|
* wire-form bytes (preferred, e.g. from commitInvite/removeMember) or a pre-decoded
|
|
338
|
-
* ts-mls
|
|
339
|
-
*
|
|
373
|
+
* ts-mls framed message (legacy). The runtime `instanceof` selects the decode path.
|
|
374
|
+
* `persist` covers accepted commits and proposals, not application messages or their
|
|
375
|
+
* receive ratchet. It runs under this handle's mutex and must not call back into it.
|
|
376
|
+
* It must write atomically: rejection means nothing was stored. Host callbacks run
|
|
377
|
+
* after successful persist; a callback throw does not undo an advance.
|
|
340
378
|
*/
|
|
341
|
-
processMessage(message: Uint8Array |
|
|
379
|
+
processMessage(message: Uint8Array | MlsFramedMessage, opts?: {
|
|
342
380
|
commitPolicy?: IncomingMessageCallback;
|
|
381
|
+
persist?: (handle: GroupHandle) => Promise<void> | void;
|
|
343
382
|
}): Promise<Uint8Array | null>;
|
|
344
383
|
}
|
|
345
|
-
/** Build
|
|
346
|
-
* filter judge against, so the two always agree. `entryIDs` are the ledger entry
|
|
347
|
-
* ids this commit enacts (drives the expected head); `candidateRoster` is the
|
|
348
|
-
* post-fold roster receivers install. */
|
|
384
|
+
/** Build policy inputs shared by author and receiver gates. Entry ids drive the expected head. */
|
|
349
385
|
export declare function buildCommitPolicyContext(handle: GroupHandle, args: {
|
|
350
386
|
baseRoster: RosterState;
|
|
351
387
|
candidateRoster: RosterState;
|