@kumiai/mls 0.13.0 → 0.13.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.
- package/README.md +19 -0
- package/lib/authentication.d.ts +4 -3
- package/lib/authentication.js +10 -0
- package/lib/controller-ingest.d.ts +2 -1
- package/lib/controller-log.d.ts +7 -6
- package/lib/crypto.d.ts +8 -1
- package/lib/crypto.js +23 -11
- package/lib/device-proof.d.ts +2 -1
- package/lib/embedded-resolver.d.ts +2 -1
- package/lib/envelope-fold.d.ts +2 -1
- package/lib/envelope-fold.js +2 -1
- package/lib/group-commit.d.ts +7 -7
- package/lib/group-commit.js +31 -15
- package/lib/group-context.d.ts +2 -2
- package/lib/group-context.js +8 -2
- package/lib/group-create.d.ts +3 -3
- package/lib/group-create.js +12 -5
- package/lib/group-device.d.ts +2 -1
- package/lib/group-device.js +20 -10
- package/lib/group-handle.d.ts +9 -8
- package/lib/group-handle.js +48 -25
- package/lib/group-lifecycle.d.ts +16 -15
- package/lib/group-lifecycle.js +55 -29
- package/lib/group-membership.d.ts +3 -2
- package/lib/group-membership.js +4 -3
- package/lib/group-welcome.d.ts +3 -3
- package/lib/group-welcome.js +25 -6
- package/lib/history.d.ts +3 -2
- package/lib/index.d.ts +1 -1
- package/lib/ledger.d.ts +4 -3
- package/lib/ledger.js +3 -2
- package/lib/lifecycle-proof.d.ts +6 -5
- package/lib/lifecycle-proof.js +8 -6
- package/lib/lifecycle.d.ts +8 -7
- package/lib/lifecycle.js +46 -29
- package/lib/member-root.d.ts +8 -7
- package/lib/registry.d.ts +6 -5
- package/lib/types.d.ts +3 -2
- package/package.json +6 -6
package/lib/group-create.js
CHANGED
|
@@ -71,11 +71,13 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
|
|
|
71
71
|
const registry = anchor.controller == null || options?.controllerLog == null ? undefined : await registryForLog({
|
|
72
72
|
controller: anchor.controller,
|
|
73
73
|
log: options.controllerLog,
|
|
74
|
-
crypto: options.crypto
|
|
74
|
+
crypto: options.crypto,
|
|
75
|
+
yield: options.yield
|
|
75
76
|
});
|
|
76
77
|
const tokens = [];
|
|
77
78
|
if (anchor.controller != null && options?.controllerLog != null) {
|
|
78
79
|
tokens.push(await signLedgerEntry({
|
|
80
|
+
yield: options.yield,
|
|
79
81
|
identity,
|
|
80
82
|
entry: {
|
|
81
83
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -100,10 +102,12 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
|
|
|
100
102
|
if (options?.controller != null) {
|
|
101
103
|
await verifyLeafCredential(mlsCredential, identity.publicKey, {
|
|
102
104
|
crypto: options.crypto,
|
|
105
|
+
yield: options.yield,
|
|
103
106
|
judging: ()=>({
|
|
104
107
|
registry,
|
|
105
108
|
stage: 'full',
|
|
106
|
-
mode: 'admit'
|
|
109
|
+
mode: 'admit',
|
|
110
|
+
yield: options.yield
|
|
107
111
|
}),
|
|
108
112
|
leafLifetime: ()=>anchor.leafLifetime ?? 86_400,
|
|
109
113
|
trustedGrantLifetime: ()=>anchor.trustedGrantLifetime ?? 2_592_000
|
|
@@ -119,7 +123,8 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
|
|
|
119
123
|
const state = await withJudging(context, {
|
|
120
124
|
registry,
|
|
121
125
|
stage: 'full',
|
|
122
|
-
mode: 'admit'
|
|
126
|
+
mode: 'admit',
|
|
127
|
+
yield: options.yield
|
|
123
128
|
}, async (judgedContext)=>{
|
|
124
129
|
const keyPackage = await generateKeyPackageWithKey({
|
|
125
130
|
credential: mlsCredential,
|
|
@@ -144,6 +149,7 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
|
|
|
144
149
|
};
|
|
145
150
|
const group = await GroupHandle.create({
|
|
146
151
|
crypto: options?.crypto,
|
|
152
|
+
yield: options.yield,
|
|
147
153
|
state,
|
|
148
154
|
credential,
|
|
149
155
|
context,
|
|
@@ -151,7 +157,7 @@ import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
|
|
|
151
157
|
resolveLedgerEntries: options?.resolveLedgerEntries,
|
|
152
158
|
onLedgerEntries: options?.onLedgerEntries
|
|
153
159
|
});
|
|
154
|
-
await group.applyLedgerEntries(tokens);
|
|
160
|
+
await group.applyLedgerEntries(tokens, options);
|
|
155
161
|
return {
|
|
156
162
|
group,
|
|
157
163
|
credential
|
|
@@ -162,6 +168,7 @@ export async function restoreGroup(params) {
|
|
|
162
168
|
// an anchorless state throws (the same fail-closed guard).
|
|
163
169
|
const group = await GroupHandle.create({
|
|
164
170
|
crypto: params.options?.crypto,
|
|
171
|
+
yield: params.yield,
|
|
165
172
|
state: params.state,
|
|
166
173
|
credential: params.credential,
|
|
167
174
|
context: await resolveMlsContext(params.options),
|
|
@@ -169,6 +176,6 @@ export async function restoreGroup(params) {
|
|
|
169
176
|
resolveLedgerEntries: params.options?.resolveLedgerEntries,
|
|
170
177
|
onLedgerEntries: params.options?.onLedgerEntries
|
|
171
178
|
});
|
|
172
|
-
await group.applyLedgerEntries(params.ledgerEntries ?? []);
|
|
179
|
+
await group.applyLedgerEntries(params.ledgerEntries ?? [], params);
|
|
173
180
|
return group;
|
|
174
181
|
}
|
package/lib/group-device.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SigningIdentity } from '@kokuin/token';
|
|
2
2
|
import { type KeyPackage } from 'ts-mls';
|
|
3
3
|
import { type GroupHandle } from './group-handle.js';
|
|
4
|
+
import type { YieldOptions } from './types.js';
|
|
4
5
|
export type DeviceWriteResult = {
|
|
5
6
|
/** Framed MLSMessage bytes. The caller (kubun) broadcasts to existing members via its DS. */
|
|
6
7
|
commitMessage: Uint8Array;
|
|
@@ -8,7 +9,7 @@ export type DeviceWriteResult = {
|
|
|
8
9
|
/** Post-commit epoch (== newGroup.epoch). */
|
|
9
10
|
epoch: bigint;
|
|
10
11
|
};
|
|
11
|
-
type GroupSigner = {
|
|
12
|
+
type GroupSigner = YieldOptions & {
|
|
12
13
|
group: GroupHandle;
|
|
13
14
|
identity: SigningIdentity;
|
|
14
15
|
};
|
package/lib/group-device.js
CHANGED
|
@@ -13,6 +13,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
13
13
|
*/ export async function registerDevice({ group, identity, ...params }) {
|
|
14
14
|
return mutexFor(group).run(async ()=>{
|
|
15
15
|
const token = await signLedgerEntry({
|
|
16
|
+
yield: params.yield,
|
|
16
17
|
identity,
|
|
17
18
|
entry: {
|
|
18
19
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -28,6 +29,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
31
|
const result = await commitWithEntries({
|
|
32
|
+
yield: params.yield,
|
|
31
33
|
group,
|
|
32
34
|
extraProposals: [],
|
|
33
35
|
enacted: [
|
|
@@ -35,8 +37,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
35
37
|
],
|
|
36
38
|
requireAdmin: false
|
|
37
39
|
});
|
|
38
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
39
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
40
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
41
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
40
42
|
return {
|
|
41
43
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
42
44
|
newGroup,
|
|
@@ -50,6 +52,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
50
52
|
*/ export async function labelDevice({ group, identity, ...params }) {
|
|
51
53
|
return mutexFor(group).run(async ()=>{
|
|
52
54
|
const token = await signLedgerEntry({
|
|
55
|
+
yield: params.yield,
|
|
53
56
|
identity,
|
|
54
57
|
entry: {
|
|
55
58
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -63,6 +66,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
63
66
|
}
|
|
64
67
|
});
|
|
65
68
|
const result = await commitWithEntries({
|
|
69
|
+
yield: params.yield,
|
|
66
70
|
group,
|
|
67
71
|
extraProposals: [],
|
|
68
72
|
enacted: [
|
|
@@ -70,8 +74,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
70
74
|
],
|
|
71
75
|
requireAdmin: false
|
|
72
76
|
});
|
|
73
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
74
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
77
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
78
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
75
79
|
return {
|
|
76
80
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
77
81
|
newGroup,
|
|
@@ -96,6 +100,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
96
100
|
throw new Error(`addDevice: the key package presents ${presentedDID}, not the device ${normalizeDID(params.device)}`);
|
|
97
101
|
}
|
|
98
102
|
const token = await signLedgerEntry({
|
|
103
|
+
yield: params.yield,
|
|
99
104
|
identity,
|
|
100
105
|
entry: {
|
|
101
106
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -115,6 +120,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
115
120
|
}
|
|
116
121
|
};
|
|
117
122
|
const result = await commitWithEntries({
|
|
123
|
+
yield: params.yield,
|
|
118
124
|
group,
|
|
119
125
|
extraProposals: [
|
|
120
126
|
addProposal
|
|
@@ -128,8 +134,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
128
134
|
if (result.welcome == null) {
|
|
129
135
|
throw new Error('addDevice: expected a Welcome message for the add proposal');
|
|
130
136
|
}
|
|
131
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
132
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
137
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
138
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
133
139
|
return {
|
|
134
140
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
135
141
|
welcomeMessage: encode(mlsMessageEncoder, result.welcome),
|
|
@@ -148,6 +154,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
148
154
|
*/ export async function revokeDevice({ group, identity, ...params }) {
|
|
149
155
|
return mutexFor(group).run(async ()=>{
|
|
150
156
|
const token = await signLedgerEntry({
|
|
157
|
+
yield: params.yield,
|
|
151
158
|
identity,
|
|
152
159
|
entry: {
|
|
153
160
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -169,6 +176,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
169
176
|
}
|
|
170
177
|
];
|
|
171
178
|
const result = await commitWithEntries({
|
|
179
|
+
yield: params.yield,
|
|
172
180
|
group,
|
|
173
181
|
extraProposals: proposals,
|
|
174
182
|
enacted: [
|
|
@@ -176,8 +184,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
176
184
|
],
|
|
177
185
|
requireAdmin: false
|
|
178
186
|
});
|
|
179
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
180
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
187
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
188
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
181
189
|
return {
|
|
182
190
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
183
191
|
newGroup,
|
|
@@ -193,6 +201,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
193
201
|
*/ export async function announceControllerBeacon({ group, identity, ...params }) {
|
|
194
202
|
return mutexFor(group).run(async ()=>{
|
|
195
203
|
const token = await signLedgerEntry({
|
|
204
|
+
yield: params.yield,
|
|
196
205
|
identity,
|
|
197
206
|
entry: {
|
|
198
207
|
type: DEVICE_ENTRY_TYPE,
|
|
@@ -206,6 +215,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
206
215
|
}
|
|
207
216
|
});
|
|
208
217
|
const result = await commitWithEntries({
|
|
218
|
+
yield: params.yield,
|
|
209
219
|
group,
|
|
210
220
|
extraProposals: [],
|
|
211
221
|
enacted: [
|
|
@@ -213,8 +223,8 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
|
|
|
213
223
|
],
|
|
214
224
|
requireAdmin: false
|
|
215
225
|
});
|
|
216
|
-
const newGroup = await deriveGroup(group, result.newState);
|
|
217
|
-
await newGroup.applyLedgerEntries(result.enacted);
|
|
226
|
+
const newGroup = await deriveGroup(group, result.newState, params);
|
|
227
|
+
await newGroup.applyLedgerEntries(result.enacted, params);
|
|
218
228
|
return {
|
|
219
229
|
commitMessage: encode(mlsMessageEncoder, result.commit),
|
|
220
230
|
newGroup,
|
package/lib/group-handle.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { type Mutex } from './mutex.js';
|
|
|
13
13
|
import { type CommitPolicyContext } from './policy.js';
|
|
14
14
|
import { type DeviceOp, type DeviceRegistry } from './registry.js';
|
|
15
15
|
import type { RosterState } from './roster.js';
|
|
16
|
+
import type { YieldOptions } from './types.js';
|
|
16
17
|
declare const CLONE_SOURCE: unique symbol;
|
|
17
18
|
type CloneGroupHandleParams = GroupHandleParams & {
|
|
18
19
|
[CLONE_SOURCE]: GroupHandle;
|
|
@@ -27,11 +28,11 @@ type FoldedControl = {
|
|
|
27
28
|
type FoldedGroupHandleParams = GroupHandleParams & {
|
|
28
29
|
[FOLDED_CONTROL]: FoldedControl;
|
|
29
30
|
};
|
|
30
|
-
export type RegistryAtParams = {
|
|
31
|
+
export type RegistryAtParams = YieldOptions & {
|
|
31
32
|
group: GroupHandle;
|
|
32
33
|
head: Uint8Array;
|
|
33
34
|
};
|
|
34
|
-
export declare function registryAt({ group, head }: RegistryAtParams): Promise<DeviceRegistry>;
|
|
35
|
+
export declare function registryAt({ group, head, ...options }: RegistryAtParams): Promise<DeviceRegistry>;
|
|
35
36
|
export declare function mutexFor(handle: GroupHandle): Mutex;
|
|
36
37
|
/** Events a GroupHandle emits. Advisory notifications derived from the folded ledger; never
|
|
37
38
|
* a protocol input. Delivered via `fire` (a throwing listener never breaks a fold). */
|
|
@@ -96,7 +97,7 @@ export type LedgerLogEntry = HeldLedgerEntry & {
|
|
|
96
97
|
entryID: string;
|
|
97
98
|
};
|
|
98
99
|
export declare const VERIFIED_LEDGER_TOKEN_CACHE_SIZE = 4096;
|
|
99
|
-
export type GroupHandleParams = CryptoOptions & {
|
|
100
|
+
export type GroupHandleParams = CryptoOptions & YieldOptions & {
|
|
100
101
|
state: ClientState;
|
|
101
102
|
credential: MemberCredential;
|
|
102
103
|
context: MlsContext;
|
|
@@ -115,7 +116,7 @@ export type GroupHandleParams = CryptoOptions & {
|
|
|
115
116
|
/** Defer authored control notifications until adoption. */
|
|
116
117
|
speculative?: boolean;
|
|
117
118
|
};
|
|
118
|
-
export type GroupHandleBootstrapLedgerParams = {
|
|
119
|
+
export type GroupHandleBootstrapLedgerParams = YieldOptions & {
|
|
119
120
|
tokens: Array<string>;
|
|
120
121
|
persist?: (handle: GroupHandle) => Promise<void> | void;
|
|
121
122
|
};
|
|
@@ -147,7 +148,7 @@ export type GroupHandleDecryptStagedParams = {
|
|
|
147
148
|
aad: Uint8Array;
|
|
148
149
|
}) => Promise<void>;
|
|
149
150
|
};
|
|
150
|
-
export type GroupHandleProcessMessageParams = {
|
|
151
|
+
export type GroupHandleProcessMessageParams = YieldOptions & {
|
|
151
152
|
message: Uint8Array | MlsFramedMessage;
|
|
152
153
|
commitPolicy?: IncomingMessageCallback;
|
|
153
154
|
persist?: (handle: GroupHandle) => Promise<void> | void;
|
|
@@ -239,7 +240,7 @@ export declare class GroupHandle {
|
|
|
239
240
|
* it (MLS applies each once, restoreGroup replays a token list once, processWelcome
|
|
240
241
|
* folds an invite once). Serialized on the handle's mutex.
|
|
241
242
|
*/
|
|
242
|
-
applyLedgerEntries(tokens: Array<string
|
|
243
|
+
applyLedgerEntries(tokens: Array<string>, options?: YieldOptions): Promise<Array<VerifiedLedgerEntry>>;
|
|
243
244
|
/**
|
|
244
245
|
* Whether the ledger this handle holds is the whole ledger its GroupContext
|
|
245
246
|
* attests to: the head folded from the ids it holds, in order, against the
|
|
@@ -347,7 +348,7 @@ export declare class GroupHandle {
|
|
|
347
348
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
348
349
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
349
350
|
*/
|
|
350
|
-
proposeSelfRemoval(): Promise<{
|
|
351
|
+
proposeSelfRemoval(options?: YieldOptions): Promise<{
|
|
351
352
|
frame: Uint8Array;
|
|
352
353
|
epoch: bigint;
|
|
353
354
|
}>;
|
|
@@ -513,5 +514,5 @@ export declare function buildCommitPolicyContext(handle: GroupHandle, args: {
|
|
|
513
514
|
externalCommitDID?: string;
|
|
514
515
|
}): CommitPolicyContext;
|
|
515
516
|
/** Build the handle a commit hands back: the post-commit state, everything else inherited. */
|
|
516
|
-
export declare function deriveGroup(group: GroupHandle, state: ClientState): Promise<GroupHandle>;
|
|
517
|
+
export declare function deriveGroup(group: GroupHandle, state: ClientState, options?: YieldOptions): Promise<GroupHandle>;
|
|
517
518
|
export {};
|
package/lib/group-handle.js
CHANGED
|
@@ -31,7 +31,7 @@ const FOLDED_CONTROL = Symbol('foldedControl');
|
|
|
31
31
|
async function computeAdmission(view) {
|
|
32
32
|
const leaf = leafAt(view.state.ratchetTree, view.state.privatePath.leafIndex);
|
|
33
33
|
const epoch = Number(view.state.groupContext.epoch);
|
|
34
|
-
return Object.freeze(leaf != null && await isLapsed(view, leaf) ? {
|
|
34
|
+
return Object.freeze(leaf != null && await isLapsed(view, leaf, view.registry, view) ? {
|
|
35
35
|
epoch,
|
|
36
36
|
admissible: false,
|
|
37
37
|
reason: 'lapsed'
|
|
@@ -41,7 +41,7 @@ async function computeAdmission(view) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
const HISTORICAL_REGISTRIES = new WeakMap();
|
|
44
|
-
export async function registryAt({ group, head }) {
|
|
44
|
+
export async function registryAt({ group, head, ...options }) {
|
|
45
45
|
let cache = HISTORICAL_REGISTRIES.get(group);
|
|
46
46
|
if (cache == null) {
|
|
47
47
|
cache = new Map();
|
|
@@ -70,7 +70,8 @@ export async function registryAt({ group, head }) {
|
|
|
70
70
|
actual: head
|
|
71
71
|
})) throw new Error('Unknown epoch ledger head');
|
|
72
72
|
const registry = (await foldLedgerControl(group.ledger.slice(0, length), group.anchor, group.groupID, {
|
|
73
|
-
crypto: group.crypto
|
|
73
|
+
crypto: group.crypto,
|
|
74
|
+
yield: options?.yield
|
|
74
75
|
})).registry;
|
|
75
76
|
cache.set(key, registry);
|
|
76
77
|
if (cache.size > 8) {
|
|
@@ -403,16 +404,19 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
403
404
|
const folded = await foldLedgerControl([
|
|
404
405
|
...params.ledger ?? []
|
|
405
406
|
], anchor, params.credential.groupID, {
|
|
406
|
-
crypto
|
|
407
|
+
crypto,
|
|
408
|
+
yield: params.yield
|
|
407
409
|
});
|
|
408
410
|
const registry = await registryWithTreeBindings(folded.registry, params.state.ratchetTree, anchor, {
|
|
409
|
-
crypto
|
|
411
|
+
crypto,
|
|
412
|
+
yield: params.yield
|
|
410
413
|
});
|
|
411
414
|
const admission = await computeAdmission({
|
|
412
415
|
state: params.state,
|
|
413
416
|
anchor,
|
|
414
417
|
registry,
|
|
415
|
-
crypto
|
|
418
|
+
crypto,
|
|
419
|
+
yield: params.yield
|
|
416
420
|
});
|
|
417
421
|
const seeded = {
|
|
418
422
|
...params,
|
|
@@ -719,7 +723,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
719
723
|
* express a demotion back to a previously-held role. Nothing replays a commit into
|
|
720
724
|
* it (MLS applies each once, restoreGroup replays a token list once, processWelcome
|
|
721
725
|
* folds an invite once). Serialized on the handle's mutex.
|
|
722
|
-
*/ async applyLedgerEntries(tokens) {
|
|
726
|
+
*/ async applyLedgerEntries(tokens, options) {
|
|
723
727
|
return mutexFor(this).run(async ()=>{
|
|
724
728
|
const appended = [];
|
|
725
729
|
const candidates = [];
|
|
@@ -727,7 +731,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
727
731
|
const memo = remembered != null && remembered.crypto === this.#crypto ? remembered.held : undefined;
|
|
728
732
|
const nextMemo = [];
|
|
729
733
|
for (const [index, token] of tokens.entries()){
|
|
730
|
-
await maybeYield();
|
|
734
|
+
if (options?.yield !== false) await maybeYield();
|
|
731
735
|
const held = memo?.[index];
|
|
732
736
|
let verified;
|
|
733
737
|
if (held?.token === token) {
|
|
@@ -741,7 +745,8 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
741
745
|
verified = structuredClone(held.verified);
|
|
742
746
|
} else {
|
|
743
747
|
verified = await verifyCachedLedgerEntry(token, {
|
|
744
|
-
crypto: this.#crypto
|
|
748
|
+
crypto: this.#crypto,
|
|
749
|
+
yield: options?.yield
|
|
745
750
|
});
|
|
746
751
|
}
|
|
747
752
|
if (verified == null || verified.entry.groupID !== this.groupID) continue;
|
|
@@ -756,16 +761,19 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
756
761
|
...candidates
|
|
757
762
|
];
|
|
758
763
|
const folded = await foldLedgerControl(ledger, this.#anchor, this.groupID, {
|
|
759
|
-
crypto: this.#crypto
|
|
764
|
+
crypto: this.#crypto,
|
|
765
|
+
yield: options?.yield
|
|
760
766
|
});
|
|
761
767
|
const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
|
|
762
|
-
crypto: this.#crypto
|
|
768
|
+
crypto: this.#crypto,
|
|
769
|
+
yield: options?.yield
|
|
763
770
|
});
|
|
764
771
|
const admission = await computeAdmission({
|
|
765
772
|
state: this.#state,
|
|
766
773
|
anchor: this.#anchor,
|
|
767
774
|
registry,
|
|
768
|
-
crypto: this.#crypto
|
|
775
|
+
crypto: this.#crypto,
|
|
776
|
+
yield: options?.yield
|
|
769
777
|
});
|
|
770
778
|
this.#ledger = ledger;
|
|
771
779
|
for (const { entryID, token, verified } of candidates){
|
|
@@ -865,10 +873,11 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
865
873
|
});
|
|
866
874
|
const log = [];
|
|
867
875
|
for(let index = 0; index < tokens.length; index++){
|
|
868
|
-
await maybeYield();
|
|
876
|
+
if (opts?.yield !== false) await maybeYield();
|
|
869
877
|
const token = tokens[index];
|
|
870
878
|
const verified = await verifyCachedLedgerEntry(token, {
|
|
871
|
-
crypto: this.#crypto
|
|
879
|
+
crypto: this.#crypto,
|
|
880
|
+
yield: opts?.yield
|
|
872
881
|
});
|
|
873
882
|
if (verified == null || verified.entry.groupID !== this.groupID) {
|
|
874
883
|
// Unreachable past the gate — the chain digests the token bytes, so an
|
|
@@ -893,16 +902,19 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
893
902
|
admission: this.#admission
|
|
894
903
|
};
|
|
895
904
|
const folded = await foldLedgerControl(log, this.#anchor, this.groupID, {
|
|
896
|
-
crypto: this.#crypto
|
|
905
|
+
crypto: this.#crypto,
|
|
906
|
+
yield: opts?.yield
|
|
897
907
|
});
|
|
898
908
|
const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
|
|
899
|
-
crypto: this.#crypto
|
|
909
|
+
crypto: this.#crypto,
|
|
910
|
+
yield: opts?.yield
|
|
900
911
|
});
|
|
901
912
|
const admission = await computeAdmission({
|
|
902
913
|
state: this.#state,
|
|
903
914
|
anchor: this.#anchor,
|
|
904
915
|
registry,
|
|
905
|
-
crypto: this.#crypto
|
|
916
|
+
crypto: this.#crypto,
|
|
917
|
+
yield: opts?.yield
|
|
906
918
|
});
|
|
907
919
|
this.#ledger = log;
|
|
908
920
|
this.#entryBodies = new Map(log.map(({ entryID, token, verified })=>[
|
|
@@ -1058,7 +1070,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1058
1070
|
* Author and retain an authenticated self-removal proposal under the handle mutex.
|
|
1059
1071
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
1060
1072
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
1061
|
-
*/ async proposeSelfRemoval() {
|
|
1073
|
+
*/ async proposeSelfRemoval(options) {
|
|
1062
1074
|
return mutexFor(this).run(async ()=>{
|
|
1063
1075
|
const senderLeafIndex = this.#state.privatePath.leafIndex;
|
|
1064
1076
|
const proposal = {
|
|
@@ -1069,6 +1081,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1069
1081
|
};
|
|
1070
1082
|
const gate = await prepareLifecycleGate({
|
|
1071
1083
|
group: this,
|
|
1084
|
+
yield: options?.yield,
|
|
1072
1085
|
entries: [],
|
|
1073
1086
|
candidateRegistry: this.#registry,
|
|
1074
1087
|
context: buildCommitPolicyContext(this, {
|
|
@@ -1485,12 +1498,13 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1485
1498
|
}
|
|
1486
1499
|
const tokens = await this.#resolveLedgerEntries(missing);
|
|
1487
1500
|
for (const token of tokens){
|
|
1488
|
-
await maybeYield();
|
|
1501
|
+
if (opts?.yield !== false) await maybeYield();
|
|
1489
1502
|
const id = ledgerEntryDigest(token);
|
|
1490
1503
|
// Content-addressing binds the untrusted body to the requested id.
|
|
1491
1504
|
if (resolved.has(id) || !missing.includes(id)) continue;
|
|
1492
1505
|
const verified = await verifyCachedLedgerEntry(token, {
|
|
1493
|
-
crypto: this.#crypto
|
|
1506
|
+
crypto: this.#crypto,
|
|
1507
|
+
yield: opts?.yield
|
|
1494
1508
|
});
|
|
1495
1509
|
if (verified == null) continue;
|
|
1496
1510
|
resolved.set(id, ledgerLogEntry(id, token, verified));
|
|
@@ -1509,6 +1523,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1509
1523
|
});
|
|
1510
1524
|
const foldResult = await foldEnvelope({
|
|
1511
1525
|
crypto: this.#crypto,
|
|
1526
|
+
yield: opts?.yield,
|
|
1512
1527
|
baseRoster: this.#roster,
|
|
1513
1528
|
baseRegistry: this.#registry,
|
|
1514
1529
|
entries: ordered,
|
|
@@ -1539,7 +1554,8 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1539
1554
|
continue;
|
|
1540
1555
|
}
|
|
1541
1556
|
const ok = await verifyDeviceEntry(verified, proofCtx, {
|
|
1542
|
-
crypto: this.#crypto
|
|
1557
|
+
crypto: this.#crypto,
|
|
1558
|
+
yield: opts?.yield
|
|
1543
1559
|
});
|
|
1544
1560
|
if (!ok) {
|
|
1545
1561
|
precomputedReject = true;
|
|
@@ -1569,6 +1585,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1569
1585
|
const externalLeaf = frame.wireformat === wireformats.mls_public_message && frame.publicMessage.content.contentType === contentTypes.commit && frame.publicMessage.senderType === senderTypes.new_member_commit ? frame.publicMessage.content.commit.path?.leafNode : undefined;
|
|
1570
1586
|
gate = await prepareLifecycleGate({
|
|
1571
1587
|
group: this,
|
|
1588
|
+
yield: opts?.yield,
|
|
1572
1589
|
entries: acceptedEntries.map(({ verified })=>verified),
|
|
1573
1590
|
candidateRegistry,
|
|
1574
1591
|
context,
|
|
@@ -1633,16 +1650,19 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1633
1650
|
});
|
|
1634
1651
|
}
|
|
1635
1652
|
const folded = await foldLedgerControl(ledger, this.#anchor, this.groupID, {
|
|
1636
|
-
crypto: this.#crypto
|
|
1653
|
+
crypto: this.#crypto,
|
|
1654
|
+
yield: opts?.yield
|
|
1637
1655
|
});
|
|
1638
1656
|
const registry = await registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor, {
|
|
1639
|
-
crypto: this.#crypto
|
|
1657
|
+
crypto: this.#crypto,
|
|
1658
|
+
yield: opts?.yield
|
|
1640
1659
|
});
|
|
1641
1660
|
const admission = await computeAdmission({
|
|
1642
1661
|
state: this.#state,
|
|
1643
1662
|
anchor: this.#anchor,
|
|
1644
1663
|
registry,
|
|
1645
|
-
crypto: this.#crypto
|
|
1664
|
+
crypto: this.#crypto,
|
|
1665
|
+
yield: opts?.yield
|
|
1646
1666
|
});
|
|
1647
1667
|
// Published together: readers between the folds still see the previous epoch's control state.
|
|
1648
1668
|
this.#ledger = ledger;
|
|
@@ -1893,6 +1913,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1893
1913
|
const index = await readSenderLeafIndex(this.#context, historical?.senderDataSecret ?? this.#state.keySchedule.senderDataSecret, application);
|
|
1894
1914
|
await assertSenderNotLapsed({
|
|
1895
1915
|
group: this,
|
|
1916
|
+
yield: opts.yield,
|
|
1896
1917
|
tree: historical?.ratchetTree ?? this.#state.ratchetTree,
|
|
1897
1918
|
leafIndex: index,
|
|
1898
1919
|
extensions: (historical?.groupContext ?? this.#state.groupContext).extensions
|
|
@@ -1921,6 +1942,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
1921
1942
|
});
|
|
1922
1943
|
await verifyLeafCredential(credential, key, {
|
|
1923
1944
|
crypto: this.#crypto,
|
|
1945
|
+
yield: opts?.yield,
|
|
1924
1946
|
deviceDenySet: ()=>denySetOf(candidateRegistry),
|
|
1925
1947
|
judging: ()=>({
|
|
1926
1948
|
registry: this.#anchor.controller == null ? undefined : candidateRegistry,
|
|
@@ -2064,7 +2086,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
2064
2086
|
}
|
|
2065
2087
|
};
|
|
2066
2088
|
}
|
|
2067
|
-
/** Build the handle a commit hands back: the post-commit state, everything else inherited. */ export async function deriveGroup(group, state) {
|
|
2089
|
+
/** Build the handle a commit hands back: the post-commit state, everything else inherited. */ export async function deriveGroup(group, state, options) {
|
|
2068
2090
|
return await GroupHandle.create({
|
|
2069
2091
|
state,
|
|
2070
2092
|
credential: group.credential,
|
|
@@ -2073,6 +2095,7 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
2073
2095
|
crypto: group.crypto
|
|
2074
2096
|
}),
|
|
2075
2097
|
crypto: group.crypto,
|
|
2098
|
+
yield: options?.yield,
|
|
2076
2099
|
ledger: group.ledger,
|
|
2077
2100
|
commitPolicy: group.commitPolicy,
|
|
2078
2101
|
resolveLedgerEntries: group.resolveLedgerEntries,
|
package/lib/group-lifecycle.d.ts
CHANGED
|
@@ -7,23 +7,24 @@ import type { DeviceWriteResult } from './group-device.js';
|
|
|
7
7
|
import { type GroupHandle } from './group-handle.js';
|
|
8
8
|
import { type EffectClaim } from './member-root.js';
|
|
9
9
|
import { type DeviceRegistry } from './registry.js';
|
|
10
|
+
import type { YieldOptions } from './types.js';
|
|
10
11
|
export type CommitResult = DeviceWriteResult;
|
|
11
|
-
export type ControllerLogDeltaParams = {
|
|
12
|
+
export type ControllerLogDeltaParams = YieldOptions & {
|
|
12
13
|
group: GroupHandle;
|
|
13
14
|
log: ControllerLog;
|
|
14
15
|
};
|
|
15
|
-
export declare function controllerLogDelta({ group, log, }: ControllerLogDeltaParams): Promise<ControllerLog | null>;
|
|
16
|
-
export type PublishControllerLogParams = {
|
|
16
|
+
export declare function controllerLogDelta({ group, log, ...policy }: ControllerLogDeltaParams): Promise<ControllerLog | null>;
|
|
17
|
+
export type PublishControllerLogParams = YieldOptions & {
|
|
17
18
|
group: GroupHandle;
|
|
18
19
|
log: ControllerLog;
|
|
19
20
|
};
|
|
20
|
-
export declare function publishControllerLog({ group, log, }: PublishControllerLogParams): Promise<DeviceWriteResult | null>;
|
|
21
|
+
export declare function publishControllerLog({ group, log, ...options }: PublishControllerLogParams): Promise<DeviceWriteResult | null>;
|
|
21
22
|
/**
|
|
22
23
|
* Author a by-reference Remove for this handle's own leaf at its current epoch.
|
|
23
24
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
24
25
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
25
26
|
*/
|
|
26
|
-
export declare function proposeSelfRemoval(group: GroupHandle): Promise<{
|
|
27
|
+
export declare function proposeSelfRemoval(group: GroupHandle, options?: YieldOptions): Promise<{
|
|
27
28
|
frame: Uint8Array;
|
|
28
29
|
epoch: bigint;
|
|
29
30
|
}>;
|
|
@@ -33,7 +34,7 @@ export declare function proposeSelfRemoval(group: GroupHandle): Promise<{
|
|
|
33
34
|
* Once a member processes a pending self-removal, application encrypt throws until
|
|
34
35
|
* a commit lands. Callers should commit pending self-removals promptly.
|
|
35
36
|
*/
|
|
36
|
-
export declare function commitSelfRemovals(group: GroupHandle): Promise<CommitResult | null>;
|
|
37
|
+
export declare function commitSelfRemovals(group: GroupHandle, options?: YieldOptions): Promise<CommitResult | null>;
|
|
37
38
|
export type RevokeBuildResult = {
|
|
38
39
|
status: 'built';
|
|
39
40
|
effects: Array<EffectClaim>;
|
|
@@ -47,18 +48,18 @@ export type RevokeBuildResult = {
|
|
|
47
48
|
status: 'not-provable';
|
|
48
49
|
reason: RevokeProofReason;
|
|
49
50
|
};
|
|
50
|
-
export type PreservationClockParams = {
|
|
51
|
+
export type PreservationClockParams = YieldOptions & {
|
|
51
52
|
group: GroupHandle;
|
|
52
53
|
candidateTree: ClientState['ratchetTree'];
|
|
53
54
|
candidateRegistry: DeviceRegistry;
|
|
54
55
|
};
|
|
55
|
-
export declare function preservationClock({ group, candidateTree, candidateRegistry, }: PreservationClockParams): Promise<Array<string>>;
|
|
56
|
-
export type AttestTreeTimeParams = {
|
|
56
|
+
export declare function preservationClock({ group, candidateTree, candidateRegistry, ...options }: PreservationClockParams): Promise<Array<string>>;
|
|
57
|
+
export type AttestTreeTimeParams = YieldOptions & {
|
|
57
58
|
group: GroupHandle;
|
|
58
59
|
time?: number;
|
|
59
60
|
};
|
|
60
|
-
export declare function attestTreeTime({ group, time, }: AttestTreeTimeParams): Promise<DeviceWriteResult | null>;
|
|
61
|
-
export type RenewLeafParams = {
|
|
61
|
+
export declare function attestTreeTime({ group, time, ...options }: AttestTreeTimeParams): Promise<DeviceWriteResult | null>;
|
|
62
|
+
export type RenewLeafParams = YieldOptions & {
|
|
62
63
|
group: GroupHandle;
|
|
63
64
|
binding: ControllerBinding;
|
|
64
65
|
controllerLog?: ControllerLog;
|
|
@@ -69,7 +70,7 @@ export type RemoveLapsedLeavesResult = {
|
|
|
69
70
|
/** Absent when no leaf had lapsed. */
|
|
70
71
|
result?: DeviceWriteResult;
|
|
71
72
|
};
|
|
72
|
-
export declare function removeLapsedLeaves(group: GroupHandle): Promise<RemoveLapsedLeavesResult>;
|
|
73
|
+
export declare function removeLapsedLeaves(group: GroupHandle, options?: YieldOptions): Promise<RemoveLapsedLeavesResult>;
|
|
73
74
|
export type RemovalEvidence = {
|
|
74
75
|
controller: string;
|
|
75
76
|
epoch: string;
|
|
@@ -81,11 +82,11 @@ export type RemovalEvidenceParams = {
|
|
|
81
82
|
rmv: string;
|
|
82
83
|
} & CryptoOptions;
|
|
83
84
|
export declare function removalEvidence({ controller, log, rmv, ...options }: RemovalEvidenceParams): Promise<RemovalEvidence | undefined>;
|
|
84
|
-
export type SurvivorTargetsParams = {
|
|
85
|
+
export type SurvivorTargetsParams = YieldOptions & {
|
|
85
86
|
group: GroupHandle;
|
|
86
87
|
add: string;
|
|
87
88
|
};
|
|
88
|
-
export declare function survivorTargets({ group, add, }: SurvivorTargetsParams): Promise<Array<{
|
|
89
|
+
export declare function survivorTargets({ group, add, ...options }: SurvivorTargetsParams): Promise<Array<{
|
|
89
90
|
did: string;
|
|
90
91
|
leafKey: Uint8Array;
|
|
91
92
|
}>>;
|
|
@@ -102,7 +103,7 @@ export type RevokeProofInput = {
|
|
|
102
103
|
reset: true;
|
|
103
104
|
log: ControllerLog;
|
|
104
105
|
};
|
|
105
|
-
export type RevokeWithProofParams = {
|
|
106
|
+
export type RevokeWithProofParams = YieldOptions & {
|
|
106
107
|
group: GroupHandle;
|
|
107
108
|
} & RevokeProofInput;
|
|
108
109
|
export declare function revokeWithProof({ group, ...params }: RevokeWithProofParams): Promise<RevokeBuildResult>;
|