@kumiai/mls 0.10.0 → 0.10.2

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.
Files changed (53) hide show
  1. package/lib/anchor.d.ts +10 -4
  2. package/lib/anchor.js +26 -2
  3. package/lib/authentication.d.ts +24 -12
  4. package/lib/authentication.js +192 -83
  5. package/lib/capability.d.ts +37 -0
  6. package/lib/capability.js +141 -0
  7. package/lib/credential.d.ts +7 -7
  8. package/lib/credential.js +15 -10
  9. package/lib/device-proof.d.ts +2 -0
  10. package/lib/device-proof.js +8 -12
  11. package/lib/envelope-fold.d.ts +16 -1
  12. package/lib/envelope-fold.js +49 -9
  13. package/lib/errors.d.ts +18 -0
  14. package/lib/errors.js +33 -0
  15. package/lib/group-commit.d.ts +24 -35
  16. package/lib/group-commit.js +139 -110
  17. package/lib/group-context.d.ts +6 -2
  18. package/lib/group-context.js +11 -4
  19. package/lib/group-create.js +56 -11
  20. package/lib/group-credential.d.ts +3 -1
  21. package/lib/group-credential.js +17 -3
  22. package/lib/group-device.js +34 -21
  23. package/lib/group-handle.d.ts +31 -8
  24. package/lib/group-handle.js +275 -58
  25. package/lib/group-lifecycle.d.ts +49 -0
  26. package/lib/group-lifecycle.js +341 -0
  27. package/lib/group-membership.js +7 -3
  28. package/lib/group-welcome.d.ts +11 -2
  29. package/lib/group-welcome.js +122 -22
  30. package/lib/group.d.ts +2 -1
  31. package/lib/group.js +1 -0
  32. package/lib/history.d.ts +6 -0
  33. package/lib/history.js +26 -0
  34. package/lib/index.d.ts +12 -5
  35. package/lib/index.js +10 -3
  36. package/lib/lifecycle-proof.d.ts +33 -0
  37. package/lib/lifecycle-proof.js +218 -0
  38. package/lib/lifecycle.d.ts +46 -0
  39. package/lib/lifecycle.js +410 -0
  40. package/lib/policy.d.ts +20 -0
  41. package/lib/policy.js +8 -5
  42. package/lib/recovery-verdict.d.ts +43 -0
  43. package/lib/recovery-verdict.js +135 -0
  44. package/lib/recovery.d.ts +70 -0
  45. package/lib/recovery.js +110 -36
  46. package/lib/registry.d.ts +34 -7
  47. package/lib/registry.js +113 -15
  48. package/lib/roster.d.ts +1 -1
  49. package/lib/roster.js +2 -2
  50. package/lib/secret-tree.d.ts +3 -0
  51. package/lib/secret-tree.js +60 -0
  52. package/lib/types.d.ts +13 -8
  53. package/package.json +5 -5
@@ -24,9 +24,12 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
24
24
  } : {}
25
25
  }
26
26
  });
27
- const result = await commitWithEntries(group, [], [
28
- token
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(group, [], [
59
- token
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(group, [
107
- addProposal
108
- ], [
109
- token
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(group, proposals, [
157
- token
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
- const enacted = await newGroup.applyLedgerEntries([
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(group, [], [
191
- token
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
- const enacted = await newGroup.applyLedgerEntries([
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,
@@ -4,6 +4,7 @@ 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 from the commit path, from bootstrapLedger, and from the local write APIs — NEVER from
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 controllerOf on the
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
  /**
@@ -240,6 +256,15 @@ export declare class GroupHandle {
240
256
  * consequences of this method's plainness; wrapping it "for consistency" breaks both.
241
257
  */
242
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
+ }>;
243
268
  /**
244
269
  * Encrypt an application message for the group at this handle's current epoch,
245
270
  * returning framed wire bytes. A handle a commit has already superseded (see
@@ -355,6 +380,7 @@ export declare class GroupHandle {
355
380
  * Process a received MLS message (Commit, Proposal, or application). Accepts
356
381
  * wire-form bytes (preferred, e.g. from commitInvite/removeMember) or a pre-decoded
357
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).
358
384
  * `persist` covers accepted commits and proposals, not application messages or their
359
385
  * receive ratchet. It runs under this handle's mutex and must not call back into it.
360
386
  * It must write atomically: rejection means nothing was stored. Host callbacks run
@@ -365,10 +391,7 @@ export declare class GroupHandle {
365
391
  persist?: (handle: GroupHandle) => Promise<void> | void;
366
392
  }): Promise<Uint8Array | null>;
367
393
  }
368
- /** Build the CommitPolicyContext both the receive gate and the send-side pending
369
- * filter judge against, so the two always agree. `entryIDs` are the ledger entry
370
- * ids this commit enacts (drives the expected head); `candidateRoster` is the
371
- * post-fold roster receivers install. */
394
+ /** Build policy inputs shared by author and receiver gates. Entry ids drive the expected head. */
372
395
  export declare function buildCommitPolicyContext(handle: GroupHandle, args: {
373
396
  baseRoster: RosterState;
374
397
  candidateRoster: RosterState;