@kumiai/mls 0.13.2 → 0.13.4

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.
@@ -1,5 +1,6 @@
1
1
  import { type CapabilityPayload } from '@kokuin/capability';
2
2
  import { type SignedToken, type SigningIdentity } from '@kokuin/token';
3
+ import type { Now } from '@sozai/runtime';
3
4
  /** The action a device capability must grant for a leaf to authenticate as a kumiai MLS leaf. */
4
5
  export declare const MLS_LEAF_ACT = "authenticate";
5
6
  /** The resource half of that grant — kumiai-namespaced, group-independent. */
@@ -24,6 +25,7 @@ export declare function assertCapabilityLifetime(payload: CapabilityTimeClaims,
24
25
  export declare function capabilityKey(payload: CapabilityPayload): import("@kokuin/controller").TaggedKey;
25
26
  export declare function assertControllerGrant(payload: CapabilityPayload, controllerID: string): void;
26
27
  export type MintLeafCapabilityParams = {
28
+ now: Now;
27
29
  signer: SigningIdentity;
28
30
  controllerID: string;
29
31
  audience: string;
package/lib/capability.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { audienceConfirmation, hasPermission } from '@kokuin/capability';
2
2
  import { tryDecodeKey } from '@kokuin/controller';
3
- import { isSignedToken, normalizeDID, now, stringifyToken } from '@kokuin/token';
3
+ import { isSignedToken, normalizeDID, stringifyToken } from '@kokuin/token';
4
4
  import { b64uToJSON } from '@sozai/codec';
5
5
  import { LeafBindingError } from './errors.js';
6
6
  /** The action a device capability must grant for a leaf to authenticate as a kumiai MLS leaf. */ export const MLS_LEAF_ACT = 'authenticate';
@@ -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 iat = Math.floor(params.now() / 1000);
70
70
  assertCapabilityLifetime({
71
71
  iat,
72
72
  exp: params.exp
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
  };
@@ -1,5 +1,6 @@
1
1
  import type { ControllerLog } from '@kokuin/controller';
2
2
  import { type SigningIdentity } from '@kokuin/token';
3
+ import type { Now } from '@sozai/runtime';
3
4
  import { type ClientState, createCommit, type DefaultProposal, type KeyPackage, type ProposalWithSender, type UnappliedProposals } from 'ts-mls';
4
5
  import { type GroupHandle } from './group-handle.js';
5
6
  import { type GroupPermission } from './roster.js';
@@ -117,6 +118,8 @@ export type CommitInviteResult = {
117
118
  epoch: bigint;
118
119
  };
119
120
  export type CommitInviteParams = YieldOptions & {
121
+ /** Clock for the author-time check of the invitee's binding, read once. */
122
+ now: Now;
120
123
  group: GroupHandle;
121
124
  keyPackage: KeyPackage;
122
125
  invite: Invite;
@@ -143,4 +146,4 @@ export type CommitInviteParams = YieldOptions & {
143
146
  * The mutex only serializes concurrent calls against one handle; it does not make a
144
147
  * second commit from a superseded handle safe.
145
148
  */
146
- export declare function commitInvite({ group, keyPackage, invite, ...options }: CommitInviteParams): Promise<CommitInviteResult>;
149
+ export declare function commitInvite({ now, group, keyPackage, invite, ...options }: CommitInviteParams): Promise<CommitInviteResult>;
@@ -341,9 +341,6 @@ export function proposedTree(state, proposals) {
341
341
  for (const proposal of proposals){
342
342
  if (proposal.proposalType === defaultProposalTypes.add) {
343
343
  const leaf = proposal.add.keyPackage.leafNode;
344
- if (isDefaultCredential(leaf.credential) && leaf.credential.credentialType === defaultCredentialTypes.basic) {
345
- assertBindingAuthorTime(parseMLSCredentialIdentity(leaf.credential.identity).controller);
346
- }
347
344
  await validateEntry(group, leaf, undefined, {
348
345
  registry: fold.registry,
349
346
  stage: 'full',
@@ -475,7 +472,7 @@ export function proposedTree(state, proposals) {
475
472
  * commit: two commits from the same source handle both frame at its epoch and diverge.
476
473
  * The mutex only serializes concurrent calls against one handle; it does not make a
477
474
  * second commit from a superseded handle safe.
478
- */ export async function commitInvite({ group, keyPackage, invite, ...options }) {
475
+ */ export async function commitInvite({ now, group, keyPackage, invite, ...options }) {
479
476
  return mutexFor(group).run(async ()=>{
480
477
  if (invite.groupID !== group.groupID) {
481
478
  throw new Error(`commitInvite: invite is for group ${invite.groupID}, not ${group.groupID}`);
@@ -531,6 +528,10 @@ export function proposedTree(state, proposals) {
531
528
  keyPackage
532
529
  }
533
530
  };
531
+ assertBindingAuthorTime({
532
+ controller: parseMLSCredentialIdentity(credential.identity).controller,
533
+ nowSeconds: Math.floor(now() / 1000)
534
+ });
534
535
  // A lifecycle group re-admitting a device replaces the leaf it still holds for that DID.
535
536
  const stale = group.anchor.controller == null ? undefined : staleLeafIndex(group.state.ratchetTree, keyPackage.leafNode);
536
537
  const result = await commitWithEntries({
@@ -1,4 +1,5 @@
1
1
  import { type OwnIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import { type ClientState } from 'ts-mls';
3
4
  import type { MemberCredential } from './credential.js';
4
5
  import { GroupHandle } from './group-handle.js';
@@ -10,9 +11,11 @@ export type CreateGroupResult = {
10
11
  export type CreateGroupParams = {
11
12
  identity: OwnIdentity;
12
13
  groupID: string;
14
+ /** Clock for the author-time check of the creator's binding, read once. */
15
+ now: Now;
13
16
  } & GroupOptions & YieldOptions;
14
17
  /** Create a new MLS group. The identity becomes the sole member and admin. */
15
- export declare function createGroup({ identity, groupID, ...options }: CreateGroupParams): Promise<CreateGroupResult>;
18
+ export declare function createGroup({ identity, groupID, now, ...options }: CreateGroupParams): Promise<CreateGroupResult>;
16
19
  export type RestoreGroupParams = YieldOptions & {
17
20
  state: ClientState;
18
21
  credential: MemberCredential;
@@ -10,8 +10,11 @@ import { GroupHandle } from './group-handle.js';
10
10
  import { buildLedgerHeadExtension, extendHead, genesisHead } from './head.js';
11
11
  import { ledgerEntryDigest, signLedgerEntry } from './ledger.js';
12
12
  import { DEVICE_ENTRY_TYPE, registryForLog } from './registry.js';
13
- /** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup({ identity, groupID, ...options }) {
14
- assertBindingAuthorTime(options?.controller);
13
+ /** Create a new MLS group. The identity becomes the sole member and admin. */ export async function createGroup({ identity, groupID, now, ...options }) {
14
+ assertBindingAuthorTime({
15
+ controller: options?.controller,
16
+ nowSeconds: Math.floor(now() / 1000)
17
+ });
15
18
  // A binding enriches a supplied anchor before genesis; standard anchor bytes stay untouched.
16
19
  // Existing lifecycle fields must agree with the authored policy before the tree is validated.
17
20
  const extensions = [
@@ -1,4 +1,5 @@
1
1
  import { type OwnIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import { type Credential } from 'ts-mls';
3
4
  import type { ControllerBinding } from './credential.js';
4
5
  import type { GroupOptions, KeyPackageBundle } from './types.js';
@@ -7,7 +8,11 @@ export type MakeMLSCredentialParams = {
7
8
  controller?: ControllerBinding;
8
9
  };
9
10
  export declare function makeMLSCredential({ identity, controller }: MakeMLSCredentialParams): Credential;
10
- export declare function assertBindingAuthorTime(controller?: ControllerBinding): void;
11
+ export type AssertBindingAuthorTimeParams = {
12
+ controller?: ControllerBinding;
13
+ nowSeconds: number;
14
+ };
15
+ export declare function assertBindingAuthorTime({ controller, nowSeconds, }: AssertBindingAuthorTimeParams): void;
11
16
  /**
12
17
  * How long an ordinary, single-use key package stays valid, in days.
13
18
  *
@@ -19,9 +24,10 @@ export declare function assertBindingAuthorTime(controller?: ControllerBinding):
19
24
  export declare const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
20
25
  export type CreateKeyPackageBundleParams = {
21
26
  identity: OwnIdentity;
27
+ now: Now;
22
28
  } & GroupOptions;
23
29
  /** Generate a key package for joining groups. */
24
- export declare function createKeyPackageBundle({ identity, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
30
+ export declare function createKeyPackageBundle({ identity, now, ...options }: CreateKeyPackageBundleParams): Promise<KeyPackageBundle>;
25
31
  /**
26
32
  * The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
27
33
  * no such extension). Its presence marks a key package as reusable by design; its data is empty.
@@ -53,6 +59,7 @@ export declare const LAST_RESORT_EXTENSION_TYPE = 10;
53
59
  export declare const LAST_RESORT_LIFETIME_DAYS = 90;
54
60
  export type CreateLastResortKeyPackageBundleParams = {
55
61
  identity: OwnIdentity;
62
+ now: Now;
56
63
  } & GroupOptions;
57
64
  /**
58
65
  * Generate a reusable last-resort key package for joining groups.
@@ -71,4 +78,4 @@ export type CreateLastResortKeyPackageBundleParams = {
71
78
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
72
79
  * obligations fail the same way: silently, and precisely when the floor is needed.
73
80
  */
74
- export declare function createLastResortKeyPackageBundle({ identity, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
81
+ export declare function createLastResortKeyPackageBundle({ identity, now, ...options }: CreateLastResortKeyPackageBundleParams): Promise<KeyPackageBundle>;
@@ -1,4 +1,4 @@
1
- import { isPeer4, now } from '@kokuin/token';
1
+ import { isPeer4 } from '@kokuin/token';
2
2
  import { defaultCredentialTypes, generateKeyPackageWithKey, greaseExtensions, makeCustomExtension } from 'ts-mls';
3
3
  import { controlCapabilities } from './anchor.js';
4
4
  import { verifyLeafCredential } from './authentication.js';
@@ -26,17 +26,17 @@ export function makeMLSCredential({ identity, controller }) {
26
26
  identity: new TextEncoder().encode(JSON.stringify(payload))
27
27
  };
28
28
  }
29
- export function assertBindingAuthorTime(controller) {
29
+ export function assertBindingAuthorTime({ controller, nowSeconds }) {
30
30
  if (controller == null) return;
31
31
  if (controller.member != null) {
32
- if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat > now()) {
32
+ if (controller.iat == null || !Number.isFinite(controller.iat) || controller.iat > nowSeconds) {
33
33
  throw new Error('Membership binding is not valid at authoring time');
34
34
  }
35
35
  return;
36
36
  }
37
37
  if (controller.capability == null) throw new LeafBindingError('controller-mismatch');
38
38
  const { iat, exp } = readCapability(controller.capability).payload;
39
- const timestamp = now();
39
+ const timestamp = nowSeconds;
40
40
  if (exp <= timestamp || iat > timestamp) {
41
41
  throw new Error('Leaf capability is not valid at authoring time');
42
42
  }
@@ -49,8 +49,11 @@ export function assertBindingAuthorTime(controller) {
49
49
  * `extensions` is left genuinely absent (not passed as `undefined`) when the caller supplies none,
50
50
  * so `generateKeyPackageWithKey`'s own `params.extensions ?? greaseExtensions(...)` default still
51
51
  * applies for the ordinary path.
52
- */ async function buildBundle(identity, options, overrides = {}) {
53
- assertBindingAuthorTime(options?.controller);
52
+ */ async function buildBundle(identity, options, overrides, nowSeconds) {
53
+ assertBindingAuthorTime({
54
+ controller: options?.controller,
55
+ nowSeconds
56
+ });
54
57
  const credential = makeMLSCredential({
55
58
  identity,
56
59
  controller: options?.controller
@@ -105,17 +108,17 @@ export function assertBindingAuthorTime(controller) {
105
108
  * default can move under a patch bump. 30 sits well under the 4-month `maximumTotalLifetime` ts-mls
106
109
  * declares, and makes a weekly top-up comfortable rather than marginal.
107
110
  */ export const ORDINARY_KEY_PACKAGE_LIFETIME_DAYS = 30;
108
- /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime() {
109
- const nowSeconds = Math.floor(Date.now() / 1000);
111
+ /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function ordinaryLifetime(nowSeconds) {
110
112
  return {
111
113
  notBefore: BigInt(nowSeconds - 86_400),
112
114
  notAfter: BigInt(nowSeconds + ORDINARY_KEY_PACKAGE_LIFETIME_DAYS * 86_400)
113
115
  };
114
116
  }
115
- /** Generate a key package for joining groups. */ export async function createKeyPackageBundle({ identity, ...options }) {
117
+ /** Generate a key package for joining groups. */ export async function createKeyPackageBundle({ identity, now, ...options }) {
118
+ const nowSeconds = Math.floor(now() / 1000);
116
119
  return buildBundle(identity, options, {
117
- lifetime: ordinaryLifetime()
118
- });
120
+ lifetime: ordinaryLifetime(nowSeconds)
121
+ }, nowSeconds);
119
122
  }
120
123
  /**
121
124
  * The `last_resort` KeyPackage extension from draft-ietf-mls-extensions (NOT RFC 9420, which has
@@ -144,8 +147,7 @@ export function assertBindingAuthorTime(controller) {
144
147
  * **This is a rotation deadline, not a solution.** A host must re-upload before it elapses, or the
145
148
  * floor disappears exactly when it is needed.
146
149
  */ export const LAST_RESORT_LIFETIME_DAYS = 90;
147
- /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime() {
148
- const nowSeconds = Math.floor(Date.now() / 1000);
150
+ /** Back-dated a day, as ts-mls's own default is, so peer clock skew cannot invalidate a fresh package. */ function lastResortLifetime(nowSeconds) {
149
151
  return {
150
152
  notBefore: BigInt(nowSeconds - 86_400),
151
153
  notAfter: BigInt(nowSeconds + LAST_RESORT_LIFETIME_DAYS * 86_400)
@@ -167,7 +169,8 @@ export function assertBindingAuthorTime(controller) {
167
169
  * carries an MLS lifetime, and an inviter validates it when building the Add — so an unrotated
168
170
  * package stops working while the hub still reports the slot as full and keeps serving it. Both
169
171
  * obligations fail the same way: silently, and precisely when the floor is needed.
170
- */ export async function createLastResortKeyPackageBundle({ identity, ...options }) {
172
+ */ export async function createLastResortKeyPackageBundle({ identity, now, ...options }) {
173
+ const nowSeconds = Math.floor(now() / 1000);
171
174
  return buildBundle(identity, options, {
172
175
  // Supplying `extensions` at all suppresses ts-mls's own default of
173
176
  // `greaseExtensions(defaultGreaseConfig)`. `defaultGreaseConfig` is not exported, so its 0.1
@@ -181,6 +184,6 @@ export function assertBindingAuthorTime(controller) {
181
184
  extensionData: new Uint8Array(0)
182
185
  })
183
186
  ],
184
- lifetime: lastResortLifetime()
185
- });
187
+ lifetime: lastResortLifetime(nowSeconds)
188
+ }, nowSeconds);
186
189
  }
@@ -1,4 +1,5 @@
1
1
  import { type SigningIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import { type KeyPackage } from 'ts-mls';
3
4
  import { type GroupHandle } from './group-handle.js';
4
5
  import type { YieldOptions } from './types.js';
@@ -36,6 +37,8 @@ export type LabelDeviceParams = GroupSigner & {
36
37
  */
37
38
  export declare function labelDevice({ group, identity, ...params }: LabelDeviceParams): Promise<DeviceWriteResult>;
38
39
  export type AddDeviceParams = GroupSigner & {
40
+ /** Clock for the author-time check of the added leaf's binding, read once. */
41
+ now: Now;
39
42
  keyPackage: KeyPackage;
40
43
  device: string;
41
44
  controller: string;
@@ -47,7 +50,7 @@ export type AddDeviceParams = GroupSigner & {
47
50
  * capability. Binds the added leaf to `device`/`controller` (the key package must present `device`).
48
51
  * Returns the Commit + Welcome bytes.
49
52
  */
50
- export declare function addDevice({ group, identity, ...params }: AddDeviceParams): Promise<DeviceWriteResult & {
53
+ export declare function addDevice({ now, group, identity, ...params }: AddDeviceParams): Promise<DeviceWriteResult & {
51
54
  welcomeMessage: Uint8Array;
52
55
  }>;
53
56
  export type RevokeDeviceParams = GroupSigner & {
@@ -2,6 +2,7 @@ import { normalizeDID } from '@kokuin/token';
2
2
  import { defaultCredentialTypes, defaultProposalTypes, encode, isDefaultCredential, mlsMessageEncoder } from 'ts-mls';
3
3
  import { parseMLSCredentialIdentity } from './credential.js';
4
4
  import { commitWithEntries } from './group-commit.js';
5
+ import { assertBindingAuthorTime } from './group-credential.js';
5
6
  import { deriveGroup, mutexFor } from './group-handle.js';
6
7
  import { signLedgerEntry } from './ledger.js';
7
8
  import { DEVICE_ENTRY_TYPE } from './registry.js';
@@ -88,7 +89,7 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
88
89
  * package plus a `kumiai.device` `add` entry, both authorized by the profile's management
89
90
  * capability. Binds the added leaf to `device`/`controller` (the key package must present `device`).
90
91
  * Returns the Commit + Welcome bytes.
91
- */ export async function addDevice({ group, identity, ...params }) {
92
+ */ export async function addDevice({ now, group, identity, ...params }) {
92
93
  return mutexFor(group).run(async ()=>{
93
94
  // Bind the added leaf to the entry's subject — the key package must present `device`.
94
95
  const credential = params.keyPackage.leafNode.credential;
@@ -113,6 +114,10 @@ import { DEVICE_ENTRY_TYPE } from './registry.js';
113
114
  }
114
115
  }
115
116
  });
117
+ assertBindingAuthorTime({
118
+ controller: parseMLSCredentialIdentity(credential.identity).controller,
119
+ nowSeconds: Math.floor(now() / 1000)
120
+ });
116
121
  const addProposal = {
117
122
  proposalType: defaultProposalTypes.add,
118
123
  add: {
@@ -1,5 +1,6 @@
1
1
  import { type ControllerLog } from '@kokuin/controller';
2
2
  import { type CryptoOptions } from '@kokuin/token';
3
+ import type { Now } from '@sozai/runtime';
3
4
  import { type ClientState } from 'ts-mls';
4
5
  import { type ControllerBinding } from './credential.js';
5
6
  import { type RevokeProofReason } from './errors.js';
@@ -56,15 +57,17 @@ export type PreservationClockParams = YieldOptions & {
56
57
  export declare function preservationClock({ group, candidateTree, candidateRegistry, ...options }: PreservationClockParams): Promise<Array<string>>;
57
58
  export type AttestTreeTimeParams = YieldOptions & {
58
59
  group: GroupHandle;
59
- time?: number;
60
+ now: Now;
60
61
  };
61
- export declare function attestTreeTime({ group, time, ...options }: AttestTreeTimeParams): Promise<DeviceWriteResult | null>;
62
+ export declare function attestTreeTime({ group, now, ...options }: AttestTreeTimeParams): Promise<DeviceWriteResult | null>;
62
63
  export type RenewLeafParams = YieldOptions & {
64
+ /** Clock for the author-time check of the new binding, read once. */
65
+ now: Now;
63
66
  group: GroupHandle;
64
67
  binding: ControllerBinding;
65
68
  controllerLog?: ControllerLog;
66
69
  };
67
- export declare function renewLeaf({ group, binding, ...options }: RenewLeafParams): Promise<DeviceWriteResult>;
70
+ export declare function renewLeaf({ now, group, binding, ...options }: RenewLeafParams): Promise<DeviceWriteResult>;
68
71
  export type RemoveLapsedLeavesResult = {
69
72
  removed: Array<string>;
70
73
  /** Absent when no leaf had lapsed. */
@@ -193,7 +193,8 @@ export async function preservationClock({ group, candidateTree, candidateRegistr
193
193
  })
194
194
  ];
195
195
  }
196
- export async function attestTreeTime({ group, time = Date.now() / 1000, ...options }) {
196
+ export async function attestTreeTime({ group, now, ...options }) {
197
+ const time = now() / 1000;
197
198
  return mutexFor(group).run(async ()=>{
198
199
  const controller = group.anchor.controller;
199
200
  if (controller == null) return null;
@@ -252,9 +253,12 @@ async function buildResult(params) {
252
253
  epoch: newGroup.epoch
253
254
  };
254
255
  }
255
- export async function renewLeaf({ group, binding, ...options }) {
256
+ export async function renewLeaf({ now, group, binding, ...options }) {
256
257
  return mutexFor(group).run(async ()=>{
257
- assertBindingAuthorTime(binding);
258
+ assertBindingAuthorTime({
259
+ controller: binding,
260
+ nowSeconds: Math.floor(now() / 1000)
261
+ });
258
262
  const index = group.state.privatePath.leafIndex * 2;
259
263
  const tree = group.state.ratchetTree.slice();
260
264
  const original = tree[index];
@@ -1,4 +1,5 @@
1
1
  import { type OwnIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import { type ClientState, type Welcome } from 'ts-mls';
3
4
  import { type ControllerBinding, type MemberCredential } from './credential.js';
4
5
  import { GroupHandle } from './group-handle.js';
@@ -49,6 +50,8 @@ export type JoinGroupExternalParamsBeforeBindingParams = {
49
50
  source: GroupHandle;
50
51
  };
51
52
  export type JoinGroupExternalParams = YieldOptions & {
53
+ /** Clock for the author-time check of the replacement binding, read once. */
54
+ now: Now;
52
55
  identity: OwnIdentity;
53
56
  /** Framed MLSMessage(GroupInfo) bytes from exportGroupInfo. */
54
57
  groupInfo: Uint8Array;
@@ -290,7 +290,10 @@ export async function processWelcome(params) {
290
290
  source: before
291
291
  });
292
292
  if (anchor.controller != null && controller == null) throw new LeafBindingError('floating-refused');
293
- assertBindingAuthorTime(controller);
293
+ assertBindingAuthorTime({
294
+ controller: controller,
295
+ nowSeconds: Math.floor(params.now() / 1000)
296
+ });
294
297
  const gate = await prepareLifecycleGate({
295
298
  yield: params.yield,
296
299
  group: before,
@@ -1,4 +1,5 @@
1
1
  import { type CryptoOptions, type OwnIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import { type ClientState, type GroupContextExtension, type IncomingMessageCallback, type LeafNode } from 'ts-mls';
3
4
  import { type JudgingContext } from './authentication.js';
4
5
  import { type ControllerBinding } from './credential.js';
@@ -51,6 +52,8 @@ export type AssertSenderNotLapsedParams = YieldOptions & {
51
52
  /** Historical messages use the tree and registry authenticated in their own epoch. */
52
53
  export declare function assertSenderNotLapsed(params: AssertSenderNotLapsedParams): Promise<void>;
53
54
  export type AssertRecoveryBindingParams = YieldOptions & {
55
+ /** Clock for the author-time check of the replacement binding, read once. */
56
+ now: Now;
54
57
  group: GroupHandle;
55
58
  identity: OwnIdentity;
56
59
  controller: ControllerBinding;
package/lib/lifecycle.js CHANGED
@@ -613,7 +613,10 @@ export async function validateWelcomeTree(group, judging = {
613
613
  }
614
614
  /** @internal Check a replacement against the complete external admission predicates. */ export async function assertRecoveryBinding(params) {
615
615
  const { group, identity: ownIdentity, controller } = params;
616
- assertBindingAuthorTime(controller);
616
+ assertBindingAuthorTime({
617
+ controller: controller,
618
+ nowSeconds: Math.floor(params.now() / 1000)
619
+ });
617
620
  const index = group.findMemberLeafIndex(normalizeDID(ownIdentity.id));
618
621
  const old = index == null ? undefined : leafAt(group.state.ratchetTree, index);
619
622
  if (old == null || index == null) throw new LeafBindingError('identity-change');
@@ -1,4 +1,5 @@
1
1
  import { type SigningIdentity } from '@kokuin/token';
2
+ import type { Now } from '@sozai/runtime';
2
3
  import type { GroupHandle } from './group-handle.js';
3
4
  import { type OpenSealedGroupInfoParams } from './recovery.js';
4
5
  import type { DeviceRegistry } from './registry.js';
@@ -46,7 +47,7 @@ export type RecoverySignerEligibleParams = {
46
47
  group: GroupHandle;
47
48
  registry: DeviceRegistry;
48
49
  signer: string;
49
- /** Seconds since epoch; defaults to the current time. */
50
- now?: number;
50
+ /** Clock read once for the current time, epoch milliseconds. */
51
+ now: Now;
51
52
  };
52
53
  export declare function recoverySignerEligible(params: RecoverySignerEligibleParams): Promise<boolean>;
@@ -122,7 +122,8 @@ export async function openRecoveryVerdict(params) {
122
122
  };
123
123
  }
124
124
  export async function recoverySignerEligible(params) {
125
- const { group, registry, signer, now = Date.now() / 1000 } = params;
125
+ const { group, registry, signer } = params;
126
+ const nowSeconds = params.now() / 1000;
126
127
  const controller = group.anchor.controller;
127
128
  if (controller == null) return false;
128
129
  const options = {
@@ -179,7 +180,7 @@ export async function recoverySignerEligible(params) {
179
180
  controllerID: controller,
180
181
  ...options
181
182
  });
182
- return expiry >= Math.max(time, now - 300);
183
+ return expiry >= Math.max(time, nowSeconds - 300);
183
184
  } catch {
184
185
  return false;
185
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/mls",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "description": "E2EE group identity and membership for Enkaku using MLS",
5
5
  "keywords": [
6
6
  "mls",
@@ -25,17 +25,17 @@
25
25
  "lib/*"
26
26
  ],
27
27
  "dependencies": {
28
- "@kokuin/capability": "^0.7.1",
28
+ "@kokuin/capability": "^0.7.2",
29
29
  "@kokuin/controller": "^0.7.1",
30
30
  "@kokuin/crypto": "^0.7.1",
31
31
  "@kokuin/token": "^0.7.1",
32
32
  "@noble/ciphers": "^2.4.0",
33
33
  "@noble/curves": "^2.4.0",
34
34
  "@noble/hashes": "^2.4.0",
35
- "@sozai/async": "^0.4.3",
35
+ "@sozai/async": "^0.4.4",
36
36
  "@sozai/codec": "^0.4.4",
37
37
  "@sozai/event": "^0.1.6",
38
- "@sozai/runtime": "^0.1.0",
38
+ "@sozai/runtime": "^0.1.1",
39
39
  "ts-mls": "2.0.0-rc.13"
40
40
  },
41
41
  "devDependencies": {