@kumiai/mls 0.13.1 → 0.13.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.
Files changed (42) hide show
  1. package/README.md +19 -0
  2. package/lib/authentication.d.ts +4 -3
  3. package/lib/authentication.js +10 -0
  4. package/lib/capability.d.ts +1 -0
  5. package/lib/capability.js +1 -1
  6. package/lib/controller-ingest.d.ts +2 -1
  7. package/lib/controller-log.d.ts +7 -6
  8. package/lib/crypto.js +15 -7
  9. package/lib/device-proof.d.ts +2 -1
  10. package/lib/embedded-resolver.d.ts +2 -1
  11. package/lib/envelope-fold.d.ts +2 -1
  12. package/lib/envelope-fold.js +2 -1
  13. package/lib/group-commit.d.ts +7 -7
  14. package/lib/group-commit.js +31 -15
  15. package/lib/group-context.d.ts +2 -2
  16. package/lib/group-context.js +4 -0
  17. package/lib/group-create.d.ts +3 -3
  18. package/lib/group-create.js +12 -5
  19. package/lib/group-credential.d.ts +5 -3
  20. package/lib/group-credential.js +15 -16
  21. package/lib/group-device.d.ts +2 -1
  22. package/lib/group-device.js +20 -10
  23. package/lib/group-handle.d.ts +9 -8
  24. package/lib/group-handle.js +48 -25
  25. package/lib/group-lifecycle.d.ts +16 -15
  26. package/lib/group-lifecycle.js +55 -29
  27. package/lib/group-membership.d.ts +3 -2
  28. package/lib/group-membership.js +4 -3
  29. package/lib/group-welcome.d.ts +3 -3
  30. package/lib/group-welcome.js +25 -6
  31. package/lib/history.d.ts +3 -2
  32. package/lib/index.d.ts +1 -1
  33. package/lib/ledger.d.ts +4 -3
  34. package/lib/ledger.js +3 -2
  35. package/lib/lifecycle-proof.d.ts +6 -5
  36. package/lib/lifecycle-proof.js +8 -6
  37. package/lib/lifecycle.d.ts +8 -7
  38. package/lib/lifecycle.js +46 -29
  39. package/lib/member-root.d.ts +8 -7
  40. package/lib/registry.d.ts +6 -5
  41. package/lib/types.d.ts +1 -0
  42. package/package.json +8 -8
package/README.md CHANGED
@@ -163,3 +163,22 @@ The follow-up revocation work will introduce a ledger entry that removes a DID's
163
163
  A last-resort key package carries an MLS lifetime of `LAST_RESORT_LIFETIME_DAYS` (90). The inviter validates that lifetime when building the Add, so an expired package is refused at the far end with `Current time not within Lifetime` — and refused _no matter what the hub does_, because the hub stores opaque bytes and cannot see the expiry.
164
164
 
165
165
  That makes the failure worse than an empty slot: the hub goes on reporting the slot as full and serving the dead package, so the availability floor looks healthy while every join through it fails. A host must generate and upload a fresh last-resort bundle before the window elapses, and keep the new private half. Uploading once at enrolment buys 90 days, not forever.
166
+
167
+ ### Cooperative yielding
168
+
169
+ Pass `yield: false` for calls inside a host write transaction to skip cooperative timer pauses.
170
+ Omitting `yield`, or passing `true`, preserves the existing behaviour. The option applies only to that call.
171
+ Crypto, ledger validation, commit policy, head checks and persist ordering are unchanged.
172
+
173
+ The option is a top-level field on the parameter object for `processMessage`, `bootstrapLedger`,
174
+ `createGroup`, `restoreGroup`, `processWelcome`, `processWelcomeOnce`, `joinGroupExternal`,
175
+ `createInvite`, `commitInvite`, `commitLedgerEntries`, `removeMember`, `registerDevice`, `labelDevice`, `addDevice`,
176
+ `revokeDevice`, `announceControllerBeacon`, `publishControllerLog`, `attestTreeTime`, `renewLeaf`
177
+ and `revokeWithProof`.
178
+ Positional APIs accept a second options argument: `handle.applyLedgerEntries(tokens, { yield: false })`,
179
+ `handle.proposeSelfRemoval({ yield: false })`, `proposeSelfRemoval(group, { yield: false })`,
180
+ `commitSelfRemovals(group, { yield: false })` and `removeLapsedLeaves(group, { yield: false })`.
181
+ `YieldOptions` is exported for callers. The option does not become a default on the returned handle.
182
+
183
+ The policy also reaches token signing, verification and lifecycle authentication, including cold caches.
184
+ `signLedgerEntry` and `verifyLedgerEntry` accept the same top-level option.
@@ -3,12 +3,13 @@ import { type CryptoOptions } from '@kokuin/token';
3
3
  import type { AuthenticationService, Credential } from 'ts-mls';
4
4
  import { type MLSCredentialIdentity } from './credential.js';
5
5
  import { type DeviceRegistry } from './registry.js';
6
+ import type { YieldOptions } from './types.js';
6
7
  export { MLS_LEAF_ACT, MLS_LEAF_RES } from './capability.js';
7
8
  /** The action a management capability must grant to mutate a profile's device registry. */
8
9
  export declare const MLS_DEVICES_ACT = "manage";
9
10
  /** The resource half — kumiai-namespaced and group-independent. */
10
11
  export declare const MLS_DEVICES_RES = "kumiai/devices";
11
- export type JudgingContext = {
12
+ export type JudgingContext = YieldOptions & {
12
13
  registry?: DeviceRegistry;
13
14
  stage: 'structural' | 'full';
14
15
  mode: 'admit' | 'retain' | 'rejudge';
@@ -17,7 +18,7 @@ export type DIDAuthenticationDependenciesMayKeepDeniedIssuerParams = {
17
18
  credential: Credential;
18
19
  signaturePublicKey: Uint8Array;
19
20
  };
20
- export type DIDAuthenticationDependencies = CryptoOptions & {
21
+ export type DIDAuthenticationDependencies = CryptoOptions & YieldOptions & {
21
22
  deviceDenySet?: () => ReadonlySet<string>;
22
23
  judging?: () => JudgingContext;
23
24
  leafLifetime?: () => number | undefined;
@@ -40,7 +41,7 @@ export declare function hasHolderEvidence(parsed: MLSCredentialIdentity, signatu
40
41
  /** Internal throwing boundary for entry gates; ts-mls consumes the boolean adapter below. */
41
42
  export declare function verifyLeafCredential(credential: Credential, signaturePublicKey: Uint8Array, deps?: DIDAuthenticationDependencies): Promise<void>;
42
43
  /** Management grants are direct controller grants, verified at their issuance time. */
43
- export declare function verifyManagementCapability(params: CryptoOptions & {
44
+ export declare function verifyManagementCapability(params: CryptoOptions & YieldOptions & {
44
45
  capability?: string;
45
46
  prefix: Array<SignedEvent>;
46
47
  controllerID: string;
@@ -77,6 +77,7 @@ function isDenied(denied, did) {
77
77
  }
78
78
  /** Authenticate only embedded proof, using the token's issuance as its reference time. */ async function verifyPinnedCapability(params) {
79
79
  if (!params.controllerID.startsWith('did:kokuin:') || !(await foldChain(params.controllerID, params.prefix, {
80
+ yield: params.yield,
80
81
  crypto: params.crypto
81
82
  })).ok) {
82
83
  throw new LeafBindingError('controller-mismatch');
@@ -104,6 +105,7 @@ function isDenied(denied, did) {
104
105
  const base = params.resolver ?? createRegistryControllerResolver({
105
106
  controllerID: params.controllerID,
106
107
  prefix: params.prefix,
108
+ yield: params.yield,
107
109
  crypto: params.crypto
108
110
  }).frozen();
109
111
  const resolver = {
@@ -116,6 +118,7 @@ function isDenied(denied, did) {
116
118
  const check = async (claims)=>{
117
119
  if (params.stage === 'structural') return;
118
120
  await checkCapability({
121
+ yield: params.yield,
119
122
  crypto: params.crypto,
120
123
  permission: params.permission,
121
124
  payload: claims,
@@ -131,6 +134,7 @@ function isDenied(denied, did) {
131
134
  if (payload.cap === undefined) {
132
135
  assertControllerGrant(payload, params.controllerID);
133
136
  const verified = await verifyToken({
137
+ yield: params.yield,
134
138
  crypto: params.crypto,
135
139
  token: params.capability,
136
140
  methods: [
@@ -166,6 +170,7 @@ function isDenied(denied, did) {
166
170
  if (token.header.alg !== issuerKey.alg) throw new LeafBindingError('signature-invalid');
167
171
  if (!await getVerifier({
168
172
  algorithm: token.header.alg,
173
+ yield: params.yield,
169
174
  crypto: params.crypto
170
175
  })({
171
176
  signature: fromB64U(token.signature),
@@ -187,6 +192,7 @@ function isDenied(denied, did) {
187
192
  atTime: payload.iat
188
193
  });
189
194
  const verifiedParent = await verifyToken({
195
+ yield: params.yield,
190
196
  crypto: params.crypto,
191
197
  token: parentRaw,
192
198
  atTime: payload.iat,
@@ -270,6 +276,7 @@ function withoutIssuer(denied, capability) {
270
276
  const registry = judging.registry;
271
277
  const structural = judging.stage === 'structural';
272
278
  const options = {
279
+ yield: deps.yield,
273
280
  crypto: deps.crypto
274
281
  };
275
282
  const denied = structural ? EMPTY_DENY : deps.deviceDenySet?.() ?? (registry == null ? EMPTY_DENY : denySetOf(registry));
@@ -307,6 +314,7 @@ function withoutIssuer(denied, capability) {
307
314
  controllerID: binding.id,
308
315
  prefix: binding.prefix,
309
316
  registry: structural ? undefined : registry,
317
+ yield: deps.yield,
310
318
  crypto: deps.crypto
311
319
  }).frozen();
312
320
  if (binding.member != null) {
@@ -337,6 +345,7 @@ function withoutIssuer(denied, capability) {
337
345
  const substitute = authority.slot === 'holder' ? binding.holderGrant : registry.controllers.get(normalizeDID(binding.id))?.survivorGrants.get(normalizeDID(parsed.id));
338
346
  if (substitute == null) throw new LeafBindingError('member-removed');
339
347
  await verifyPinnedCapability({
348
+ yield: deps.yield,
340
349
  crypto: deps.crypto,
341
350
  capability: substitute,
342
351
  resolver: frozen,
@@ -390,6 +399,7 @@ function withoutIssuer(denied, capability) {
390
399
  }
391
400
  if (binding.capability == null) throw new LeafBindingError('controller-mismatch');
392
401
  const common = {
402
+ yield: deps.yield,
393
403
  crypto: deps.crypto,
394
404
  prefix: binding.prefix,
395
405
  controllerID: binding.id,
@@ -24,6 +24,7 @@ export declare function assertCapabilityLifetime(payload: CapabilityTimeClaims,
24
24
  export declare function capabilityKey(payload: CapabilityPayload): import("@kokuin/controller").TaggedKey;
25
25
  export declare function assertControllerGrant(payload: CapabilityPayload, controllerID: string): void;
26
26
  export type MintLeafCapabilityParams = {
27
+ nowSeconds?: number;
27
28
  signer: SigningIdentity;
28
29
  controllerID: string;
29
30
  audience: string;
package/lib/capability.js CHANGED
@@ -66,7 +66,7 @@ function issuingPayload(params, maximum) {
66
66
  if (!params.controllerID.startsWith('did:kokuin:')) {
67
67
  throw new LeafBindingError('controller-mismatch');
68
68
  }
69
- const iat = now();
69
+ const { nowSeconds: iat = now() } = params;
70
70
  assertCapabilityLifetime({
71
71
  iat,
72
72
  exp: params.exp
@@ -1,6 +1,7 @@
1
1
  import { type ControllerLog, type FoldResult, type KeyState } from '@kokuin/controller';
2
2
  import { type CryptoOptions } from '@kokuin/token';
3
3
  import type { ControllerProjection } from './registry.js';
4
+ import type { YieldOptions } from './types.js';
4
5
  export type FoldOk = Extract<FoldResult, {
5
6
  ok: true;
6
7
  }>;
@@ -15,7 +16,7 @@ export type IngestControllerLogParams = {
15
16
  recorded: ControllerLog | undefined;
16
17
  proof: ControllerLog;
17
18
  previous?: ControllerProjection;
18
- } & CryptoOptions;
19
+ } & CryptoOptions & YieldOptions;
19
20
  export declare function ingestControllerLog({ controller, recorded, proof, previous, ...options }: IngestControllerLogParams): Promise<IngestedControllerLog>;
20
21
  export type EffectDeltaParams = {
21
22
  before: KeyState | undefined;
@@ -1,18 +1,19 @@
1
1
  import { type ControllerLog, type FoldResult, type SignedEvent } from '@kokuin/controller';
2
2
  import { type CryptoOptions } from '@kokuin/token';
3
+ import type { YieldOptions } from './types.js';
3
4
  export declare const CHAIN_REVOKE_REFUSED = "chain revoke refused";
4
5
  export declare function asControllerLog(chain: ReadonlyArray<SignedEvent>): ControllerLog;
5
6
  export declare function hasChainRevoke(chain: ReadonlyArray<unknown>): boolean;
6
- export declare function foldChain(did: string, chain: ReadonlyArray<SignedEvent>, options?: CryptoOptions): Promise<FoldResult>;
7
- export declare function foldControllerLog(did: string, log: ControllerLog, options?: CryptoOptions): Promise<FoldResult>;
8
- export declare function revokeIndices(did: string, chain: ReadonlyArray<SignedEvent>, subject: string, options?: CryptoOptions): Promise<Array<number>>;
7
+ export declare function foldChain(did: string, chain: ReadonlyArray<SignedEvent>, options?: CryptoOptions & YieldOptions): Promise<FoldResult>;
8
+ export declare function foldControllerLog(did: string, log: ControllerLog, options?: CryptoOptions & YieldOptions): Promise<FoldResult>;
9
+ export declare function revokeIndices(did: string, chain: ReadonlyArray<SignedEvent>, subject: string, options?: CryptoOptions & YieldOptions): Promise<Array<number>>;
9
10
  export type MemberDropIndicesParams = {
10
11
  did: string;
11
12
  chain: ReadonlyArray<SignedEvent>;
12
13
  add: string;
13
- } & CryptoOptions;
14
+ } & CryptoOptions & YieldOptions;
14
15
  export declare function memberDropIndices({ did, chain, add, ...options }: MemberDropIndicesParams): Promise<Array<number>>;
15
16
  /** Same-generation `rot` indices whose snapshot newly carries `add` as `member`'s removed incarnation. */
16
- export declare function memberTombstoneIndices(did: string, chain: ReadonlyArray<SignedEvent>, add: string, member: string, options?: CryptoOptions): Promise<Array<number>>;
17
- export declare function closureOf(did: string, log: ControllerLog, targets: ReadonlyArray<string>, options?: CryptoOptions): Promise<ControllerLog | undefined>;
17
+ export declare function memberTombstoneIndices(did: string, chain: ReadonlyArray<SignedEvent>, add: string, member: string, options?: CryptoOptions & YieldOptions): Promise<Array<number>>;
18
+ export declare function closureOf(did: string, log: ControllerLog, targets: ReadonlyArray<string>, options?: CryptoOptions & YieldOptions): Promise<ControllerLog | undefined>;
18
19
  export declare function isDetachedFoldReason(reason: string): boolean;
package/lib/crypto.js CHANGED
@@ -94,7 +94,14 @@ function makeKdf(kdfName) {
94
94
  size
95
95
  };
96
96
  }
97
- function makeSignature({ name, crypto }) {
97
+ // ---------------------------------------------------------------------------
98
+ // Signature (Ed25519)
99
+ // ---------------------------------------------------------------------------
100
+ // Ed25519 and X25519 secret keys are 32 random bytes, drawn from the suite RNG so an injected source
101
+ // controls every key and encapsulation. X25519 takes them verbatim (noble clamps on use), and its
102
+ // typed randomSecretKey() accepts no seed.
103
+ const SECRET_KEY_SEED_LENGTH = 32;
104
+ function makeSignature({ name, crypto, rng }) {
98
105
  if (name !== 'Ed25519') {
99
106
  throw new Error(`Unsupported signature algorithm: ${name}. Only Ed25519 is supported.`);
100
107
  }
@@ -115,7 +122,7 @@ function makeSignature({ name, crypto }) {
115
122
  });
116
123
  },
117
124
  async keygen () {
118
- const signKey = ed25519.utils.randomSecretKey();
125
+ const signKey = ed25519.utils.randomSecretKey(rng.randomBytes(SECRET_KEY_SEED_LENGTH));
119
126
  return {
120
127
  signKey,
121
128
  publicKey: ed25519.getPublicKey(signKey)
@@ -173,7 +180,7 @@ const KEM_SUITE_ID = concatBytes(new TextEncoder().encode('KEM'), i2osp(KEM_ID_X
173
180
  publicKey: pk
174
181
  };
175
182
  }
176
- function makeHpke(hpkeAlg) {
183
+ function makeHpke(hpkeAlg, rng) {
177
184
  if (!hpkeAlg.kem.includes('X25519')) {
178
185
  throw new Error(`Unsupported KEM: ${hpkeAlg.kem}. Only DHKEM-X25519-HKDF-SHA256 is supported.`);
179
186
  }
@@ -227,7 +234,7 @@ function makeHpke(hpkeAlg) {
227
234
  /**
228
235
  * Encap (RFC 9180 §4.1) — generate ephemeral keypair and shared secret
229
236
  */ function encap(recipientPublicKey) {
230
- const ek = x25519.utils.randomSecretKey();
237
+ const ek = rng.randomBytes(SECRET_KEY_SEED_LENGTH);
231
238
  const enc = x25519.getPublicKey(ek);
232
239
  const dh = x25519.getSharedSecret(ek, recipientPublicKey);
233
240
  const kemContext = concatBytes(enc, recipientPublicKey);
@@ -328,7 +335,7 @@ function makeHpke(hpkeAlg) {
328
335
  };
329
336
  },
330
337
  async generateKeyPair () {
331
- const privateKey = x25519.utils.randomSecretKey();
338
+ const privateKey = rng.randomBytes(SECRET_KEY_SEED_LENGTH);
332
339
  const publicKey = x25519.getPublicKey(privateKey);
333
340
  return {
334
341
  privateKey: wrapPrivateKey(privateKey),
@@ -378,9 +385,10 @@ export function createNobleCryptoProvider(options) {
378
385
  kdf: makeKdf(config.hpke.kdf),
379
386
  signature: makeSignature({
380
387
  name: config.signature,
381
- crypto
388
+ crypto,
389
+ rng
382
390
  }),
383
- hpke: makeHpke(config.hpke),
391
+ hpke: makeHpke(config.hpke, rng),
384
392
  rng,
385
393
  id
386
394
  };
@@ -2,6 +2,7 @@ import type { SignedEvent } from '@kokuin/controller';
2
2
  import { type CryptoOptions } from '@kokuin/token';
3
3
  import type { VerifiedLedgerEntry } from './ledger.js';
4
4
  import type { DeviceValue } from './registry.js';
5
+ import type { YieldOptions } from './types.js';
5
6
  /** What the tree yields about a leaf for the device-proof gate: its binding, prefix, and leaf key. */
6
7
  export type LeafBinding = {
7
8
  /** The bound profile DID, or undefined for a floating leaf. */
@@ -38,4 +39,4 @@ export type DeviceProofContext = {
38
39
  *
39
40
  * Pure of the fold — runs only where the tree is present (never on a bootstrap re-fold).
40
41
  */
41
- export declare function verifyDeviceEntry(verified: VerifiedLedgerEntry<DeviceValue>, ctx: DeviceProofContext, options?: CryptoOptions): Promise<boolean>;
42
+ export declare function verifyDeviceEntry(verified: VerifiedLedgerEntry<DeviceValue>, ctx: DeviceProofContext, options?: CryptoOptions & YieldOptions): Promise<boolean>;
@@ -1,13 +1,14 @@
1
1
  import { type ControllerLog, type ControllerResolver, type SignedEvent } from '@kokuin/controller';
2
2
  import { type CryptoOptions } from '@kokuin/token';
3
3
  import { type DeviceRegistry } from './registry.js';
4
+ import type { YieldOptions } from './types.js';
4
5
  export type PrefixRelationParams = {
5
6
  recorded: ControllerLog | undefined;
6
7
  prefix: ReadonlyArray<SignedEvent>;
7
8
  };
8
9
  export declare function prefixRelation({ recorded, prefix, }: PrefixRelationParams): 'contained' | 'ahead' | 'forked' | 'none';
9
10
  /** Root keys come from the leaf prefix; member authority comes from the recorded epoch. */
10
- export declare function createRegistryControllerResolver(params: CryptoOptions & {
11
+ export declare function createRegistryControllerResolver(params: CryptoOptions & YieldOptions & {
11
12
  controllerID: string;
12
13
  prefix: ReadonlyArray<SignedEvent>;
13
14
  registry?: DeviceRegistry;
@@ -4,6 +4,7 @@ import type { FoldInput } from './fold.js';
4
4
  import type { VerifiedLedgerEntry } from './ledger.js';
5
5
  import { type DeviceRegistry } from './registry.js';
6
6
  import { type RosterState } from './roster.js';
7
+ import type { YieldOptions } from './types.js';
7
8
  /**
8
9
  * The outcome of folding an envelope's control entries. On accept: the candidate
9
10
  * roster (base ∪ this envelope's kumiai.role entries), the candidate registry (base ∪
@@ -29,7 +30,7 @@ export type FoldEnvelopeContext = {
29
30
  /** The controller bound to the issuer's pre-commit leaf, if any. */
30
31
  memberController: (did: string) => string | undefined;
31
32
  };
32
- export type FoldEnvelopeParams = CryptoOptions & {
33
+ export type FoldEnvelopeParams = CryptoOptions & YieldOptions & {
33
34
  baseRoster: RosterState;
34
35
  baseRegistry: DeviceRegistry;
35
36
  entries: Array<FoldInput>;
@@ -68,7 +68,8 @@ function isRoleValue(value) {
68
68
  value
69
69
  }
70
70
  }, workingRegistry, context?.controllerID, {
71
- crypto
71
+ crypto,
72
+ yield: params.yield
72
73
  });
73
74
  } catch (error) {
74
75
  return {
@@ -3,7 +3,7 @@ import { type SigningIdentity } from '@kokuin/token';
3
3
  import { type ClientState, createCommit, type DefaultProposal, type KeyPackage, type ProposalWithSender, type UnappliedProposals } from 'ts-mls';
4
4
  import { type GroupHandle } from './group-handle.js';
5
5
  import { type GroupPermission } from './roster.js';
6
- import type { Invite } from './types.js';
6
+ import type { Invite, YieldOptions } from './types.js';
7
7
  export type InviteRecipientMismatchErrorParams = {
8
8
  groupID: string;
9
9
  expectedDID: string;
@@ -19,7 +19,7 @@ export declare class InviteRecipientMismatchError extends Error {
19
19
  /** DID the supplied key package presents. */
20
20
  get actualDID(): string;
21
21
  }
22
- export type CreateInviteParams = {
22
+ export type CreateInviteParams = YieldOptions & {
23
23
  group: GroupHandle;
24
24
  identity: SigningIdentity;
25
25
  recipientDID: string;
@@ -37,7 +37,7 @@ export type CreateInviteResult = {
37
37
  /** Create an invite without adding its recipient; commitInvite enacts the admission. */
38
38
  export declare function createInvite(params: CreateInviteParams): Promise<CreateInviteResult>;
39
39
  export declare function proposedTree(state: ClientState, proposals: Array<ProposalWithSender>): ClientState['ratchetTree'];
40
- export type CommitWithEntriesParams = {
40
+ export type CommitWithEntriesParams = YieldOptions & {
41
41
  group: GroupHandle;
42
42
  extraProposals: Array<DefaultProposal>;
43
43
  /** Pending proposals to commit by reference, retaining their authenticated senders. */
@@ -78,7 +78,7 @@ export type CommitLedgerEntriesResult = {
78
78
  /** Post-commit epoch the group is now at (== newGroup.epoch). */
79
79
  epoch: bigint;
80
80
  };
81
- export type CommitLedgerEntriesParams = {
81
+ export type CommitLedgerEntriesParams = YieldOptions & {
82
82
  group: GroupHandle;
83
83
  tokens: Array<string>;
84
84
  };
@@ -101,7 +101,7 @@ export type CommitLedgerEntriesParams = {
101
101
  * The mutex only serializes concurrent calls against one handle. A source whose commit
102
102
  * was accepted is superseded and must never be reused.
103
103
  */
104
- export declare function commitLedgerEntries({ group, tokens, }: CommitLedgerEntriesParams): Promise<CommitLedgerEntriesResult>;
104
+ export declare function commitLedgerEntries({ group, tokens, ...options }: CommitLedgerEntriesParams): Promise<CommitLedgerEntriesResult>;
105
105
  export type CommitInviteResult = {
106
106
  /** The input invite, updated with the complete ledger, including any preservation clock. */
107
107
  invite: Invite;
@@ -116,7 +116,7 @@ export type CommitInviteResult = {
116
116
  * readMessageEpoch). */
117
117
  epoch: bigint;
118
118
  };
119
- export type CommitInviteParams = {
119
+ export type CommitInviteParams = YieldOptions & {
120
120
  group: GroupHandle;
121
121
  keyPackage: KeyPackage;
122
122
  invite: Invite;
@@ -143,4 +143,4 @@ export type CommitInviteParams = {
143
143
  * The mutex only serializes concurrent calls against one handle; it does not make a
144
144
  * second commit from a superseded handle safe.
145
145
  */
146
- export declare function commitInvite({ group, keyPackage, invite, }: CommitInviteParams): Promise<CommitInviteResult>;
146
+ export declare function commitInvite({ group, keyPackage, invite, ...options }: CommitInviteParams): Promise<CommitInviteResult>;
@@ -52,16 +52,19 @@ const INVITE_ENTRIES = new WeakMap();
52
52
  for (const token of appended){
53
53
  const verified = await verifyLedgerEntry({
54
54
  token,
55
- crypto: group.crypto
55
+ crypto: group.crypto,
56
+ yield: params.yield
56
57
  });
57
58
  if (verified == null || verified.entry.groupID !== group.groupID || verified.entry.type.startsWith('kumiai.') || normalizeDID(verified.issuer) !== normalizeDID(identity.id)) throw new Error('createInvite: entries must be consumer entries signed by the inviter');
58
59
  }
59
60
  if (params.controllerLog != null) {
60
61
  const delta = await controllerLogDelta({
61
62
  group,
62
- log: params.controllerLog
63
+ log: params.controllerLog,
64
+ yield: params.yield
63
65
  });
64
66
  if (delta != null) appended.unshift(await signLedgerEntry({
67
+ yield: params.yield,
65
68
  identity,
66
69
  entry: {
67
70
  type: DEVICE_ENTRY_TYPE,
@@ -84,6 +87,7 @@ const INVITE_ENTRIES = new WeakMap();
84
87
  }
85
88
  appended = [
86
89
  await signLedgerEntry({
90
+ yield: params.yield,
87
91
  identity,
88
92
  entry: {
89
93
  type: ROLE_ENTRY_TYPE,
@@ -199,7 +203,8 @@ export function proposedTree(state, proposals) {
199
203
  for (const token of enacted){
200
204
  const verified = await verifyLedgerEntry({
201
205
  token,
202
- crypto: group.crypto
206
+ crypto: group.crypto,
207
+ yield: params.yield
203
208
  });
204
209
  if (verified == null) {
205
210
  throw new Error('cannot enact a ledger entry whose signature does not verify');
@@ -211,6 +216,7 @@ export function proposedTree(state, proposals) {
211
216
  }
212
217
  const foldEntries = async ()=>await foldEnvelope({
213
218
  crypto: group.crypto,
219
+ yield: params.yield,
214
220
  baseRoster: group.roster,
215
221
  baseRegistry: group.registry,
216
222
  entries: inputs,
@@ -234,6 +240,7 @@ export function proposedTree(state, proposals) {
234
240
  }))
235
241
  ]);
236
242
  const clocks = await preservationClock({
243
+ yield: params.yield,
237
244
  group,
238
245
  candidateTree: tree,
239
246
  candidateRegistry: fold.registry
@@ -241,7 +248,8 @@ export function proposedTree(state, proposals) {
241
248
  for (const clock of clocks){
242
249
  const verified = await verifyLedgerEntry({
243
250
  token: clock,
244
- crypto: group.crypto
251
+ crypto: group.crypto,
252
+ yield: params.yield
245
253
  });
246
254
  if (verified == null) throw new Error('Invalid preservation clock');
247
255
  enacted.push(clock);
@@ -267,7 +275,8 @@ export function proposedTree(state, proposals) {
267
275
  continue;
268
276
  }
269
277
  const ok = await verifyDeviceEntry(input.verified, proofCtx, {
270
- crypto: group.crypto
278
+ crypto: group.crypto,
279
+ yield: params.yield
271
280
  });
272
281
  if (!ok) {
273
282
  throw new Error(`cannot enact device entry ${input.entryID}: proof verification failed`);
@@ -300,6 +309,7 @@ export function proposedTree(state, proposals) {
300
309
  });
301
310
  }
302
311
  const gate = await prepareLifecycleGate({
312
+ yield: params.yield,
303
313
  group,
304
314
  entries: inputs.map(({ verified })=>verified),
305
315
  candidateRegistry: fold.registry,
@@ -337,7 +347,8 @@ export function proposedTree(state, proposals) {
337
347
  await validateEntry(group, leaf, undefined, {
338
348
  registry: fold.registry,
339
349
  stage: 'full',
340
- mode: 'admit'
350
+ mode: 'admit',
351
+ yield: params.yield
341
352
  });
342
353
  }
343
354
  }
@@ -345,7 +356,8 @@ export function proposedTree(state, proposals) {
345
356
  const result = await withJudging(group.context, {
346
357
  registry: group.anchor.controller == null ? undefined : candidateRegistry,
347
358
  stage: 'full',
348
- mode: 'admit'
359
+ mode: 'admit',
360
+ yield: params.yield
349
361
  }, (context)=>createCommit({
350
362
  context: {
351
363
  ...context,
@@ -359,7 +371,8 @@ export function proposedTree(state, proposals) {
359
371
  mode: index != null && isUnchangedLeaf(group.state.ratchetTree, index, {
360
372
  credential,
361
373
  signaturePublicKey: key
362
- }) ? 'retain' : 'admit'
374
+ }) ? 'retain' : 'admit',
375
+ yield: params.yield
363
376
  }, (judgedContext)=>judgedContext.authService.validateCredential(credential, key));
364
377
  }
365
378
  }
@@ -421,18 +434,19 @@ export function proposedTree(state, proposals) {
421
434
  * Serialise reserve, build and consume against the source handle.
422
435
  * The mutex only serializes concurrent calls against one handle. A source whose commit
423
436
  * was accepted is superseded and must never be reused.
424
- */ export async function commitLedgerEntries({ group, tokens }) {
437
+ */ export async function commitLedgerEntries({ group, tokens, ...options }) {
425
438
  return mutexFor(group).run(async ()=>{
426
439
  if (tokens.length === 0) {
427
440
  throw new Error('commitLedgerEntries: no ledger entries to commit');
428
441
  }
429
442
  const result = await commitWithEntries({
443
+ yield: options.yield,
430
444
  group,
431
445
  extraProposals: [],
432
446
  enacted: tokens
433
447
  });
434
- const newGroup = await deriveGroup(group, result.newState);
435
- await newGroup.applyLedgerEntries(result.enacted);
448
+ const newGroup = await deriveGroup(group, result.newState, options);
449
+ await newGroup.applyLedgerEntries(result.enacted, options);
436
450
  return {
437
451
  commitMessage: encode(mlsMessageEncoder, result.commit),
438
452
  newGroup,
@@ -461,7 +475,7 @@ export function proposedTree(state, proposals) {
461
475
  * commit: two commits from the same source handle both frame at its epoch and diverge.
462
476
  * The mutex only serializes concurrent calls against one handle; it does not make a
463
477
  * second commit from a superseded handle safe.
464
- */ export async function commitInvite({ group, keyPackage, invite }) {
478
+ */ export async function commitInvite({ group, keyPackage, invite, ...options }) {
465
479
  return mutexFor(group).run(async ()=>{
466
480
  if (invite.groupID !== group.groupID) {
467
481
  throw new Error(`commitInvite: invite is for group ${invite.groupID}, not ${group.groupID}`);
@@ -473,7 +487,8 @@ export function proposedTree(state, proposals) {
473
487
  for (const token of enacted){
474
488
  const verified = await verifyLedgerEntry({
475
489
  token,
476
- crypto: group.crypto
490
+ crypto: group.crypto,
491
+ yield: options.yield
477
492
  });
478
493
  if (verified?.entry.type === ROLE_ENTRY_TYPE && verified.entry.groupID === group.groupID) {
479
494
  grantedTo = verified.entry.subject;
@@ -519,6 +534,7 @@ export function proposedTree(state, proposals) {
519
534
  // A lifecycle group re-admitting a device replaces the leaf it still holds for that DID.
520
535
  const stale = group.anchor.controller == null ? undefined : staleLeafIndex(group.state.ratchetTree, keyPackage.leafNode);
521
536
  const result = await commitWithEntries({
537
+ yield: options.yield,
522
538
  group,
523
539
  extraProposals: stale == null ? [
524
540
  addProposal
@@ -534,12 +550,12 @@ export function proposedTree(state, proposals) {
534
550
  enacted,
535
551
  ratchetTreeExtension: true
536
552
  });
537
- const newGroup = await deriveGroup(group, result.newState);
553
+ const newGroup = await deriveGroup(group, result.newState, options);
538
554
  if (result.welcome == null) {
539
555
  throw new Error('commitInvite: expected a Welcome message for the add proposal');
540
556
  }
541
557
  // Preservation may append a clock after the invite was prepared.
542
- await newGroup.applyLedgerEntries(result.enacted);
558
+ await newGroup.applyLedgerEntries(result.enacted, options);
543
559
  const commitMessage = encode(mlsMessageEncoder, result.commit);
544
560
  const welcomeMessage = encode(mlsMessageEncoder, result.welcome);
545
561
  invite.ledgerEntries = newGroup.ledgerTokens;
@@ -2,7 +2,7 @@ import type { CryptoOptions } from '@kokuin/token';
2
2
  import { type Capabilities, type ClientConfig, type GroupContextExtension, type KeyRetentionConfig, type MlsContext } from 'ts-mls';
3
3
  import type { GroupAnchor } from './anchor.js';
4
4
  import { type JudgingContext } from './authentication.js';
5
- import type { GroupOptions } from './types.js';
5
+ import type { GroupOptions, YieldOptions } from './types.js';
6
6
  /**
7
7
  * The receive-side key retention every kumiai context carries, in place of ts-mls's
8
8
  * defaults (10 skipped keys, a 200-generation forward window).
@@ -37,7 +37,7 @@ export declare function kumiaiClientConfig(): ClientConfig;
37
37
  /** Copy a client config without sharing its mutable parts with the source context. */
38
38
  export declare function copyClientConfig(config: ClientConfig): ClientConfig;
39
39
  /** Late-bound provider of a context's device deny set, pointed at the live handle after construction. */
40
- export type DeviceDenyHolder = CryptoOptions & {
40
+ export type DeviceDenyHolder = CryptoOptions & YieldOptions & {
41
41
  provider: () => ReadonlySet<string>;
42
42
  judging?: () => JudgingContext;
43
43
  leafLifetime?: number;
@@ -70,6 +70,7 @@ const DENY_HOLDERS = new WeakMap();
70
70
  const registry = judging.registry;
71
71
  const scopedHolder = {
72
72
  ...holder,
73
+ yield: judging.yield,
73
74
  provider: registry == null ? holder.provider : ()=>denySetOf(registry),
74
75
  judging: ()=>judging
75
76
  };
@@ -85,6 +86,9 @@ function authenticationFor(holder) {
85
86
  get crypto () {
86
87
  return holder.crypto;
87
88
  },
89
+ get yield () {
90
+ return holder.yield;
91
+ },
88
92
  deviceDenySet: ()=>holder.provider(),
89
93
  judging: ()=>holder.judging?.() ?? {
90
94
  stage: 'full',
@@ -2,7 +2,7 @@ import { type OwnIdentity } from '@kokuin/token';
2
2
  import { type ClientState } from 'ts-mls';
3
3
  import type { MemberCredential } from './credential.js';
4
4
  import { GroupHandle } from './group-handle.js';
5
- import type { GroupOptions } from './types.js';
5
+ import type { GroupOptions, YieldOptions } from './types.js';
6
6
  export type CreateGroupResult = {
7
7
  group: GroupHandle;
8
8
  credential: MemberCredential;
@@ -10,10 +10,10 @@ export type CreateGroupResult = {
10
10
  export type CreateGroupParams = {
11
11
  identity: OwnIdentity;
12
12
  groupID: string;
13
- } & GroupOptions;
13
+ } & GroupOptions & YieldOptions;
14
14
  /** Create a new MLS group. The identity becomes the sole member and admin. */
15
15
  export declare function createGroup({ identity, groupID, ...options }: CreateGroupParams): Promise<CreateGroupResult>;
16
- export type RestoreGroupParams = {
16
+ export type RestoreGroupParams = YieldOptions & {
17
17
  state: ClientState;
18
18
  credential: MemberCredential;
19
19
  /** Signed ledger tokens the host persisted, replayed to rebuild the roster. */