@kumiai/mls-rpc 0.13.1 → 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/lib/mls.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { OwnIdentity } from '@kokuin/token';
2
2
  import { type GroupHandle } from '@kumiai/mls';
3
3
  import type { GroupMLS } from '@kumiai/rpc';
4
+ import { type Now, type Runtime } from '@sozai/runtime';
4
5
  import { type HandleAccess } from './access.js';
5
6
  import { type RecoveryBinding } from './recovery.js';
6
7
  export declare const groupHandleAccess: WeakMap<GroupMLS, HandleAccess>;
@@ -36,6 +37,7 @@ export type LedgerEntrySlot = {
36
37
  };
37
38
  export declare function createLedgerEntrySlot(): LedgerEntrySlot;
38
39
  export type GroupMLSParams = {
40
+ runtime?: Runtime;
39
41
  access: HandleAccess;
40
42
  /** This member's signing identity: recovery requests and attestations are signed with it. */
41
43
  identity: OwnIdentity;
@@ -62,6 +64,7 @@ export type RecoveryPending = {
62
64
  };
63
65
  export declare function createRecoveryPending(options?: {
64
66
  ttlMS?: number;
67
+ monotonicNow?: Now;
65
68
  }): RecoveryPending;
66
69
  export declare function deriveRecoverySecret(handle: GroupHandle): Promise<Uint8Array>;
67
70
  /**
package/lib/mls.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { confirmationKey, createRecoveryRequest, encodeGroupAnchor, ledgerEntryDigest, MissingLedgerEntriesError, openRecoveryGroupInfo, openRecoveryVerdict, openSealedLedger, readCommitEntryIDs, readMessageEpoch, recoverySignerEligible, sealGroupInfo, sealLedger, sealRecoveryVerdict, verifyRecoveryRequest } from '@kumiai/mls';
2
+ import { createRuntime } from '@sozai/runtime';
2
3
  import { guardedReplace } from './access.js';
3
4
  import { applyCommit } from './apply-commit.js';
4
5
  import { createRecoveryBindingState, createVerdictJudge } from './recovery.js';
@@ -37,6 +38,7 @@ export function createLedgerEntrySlot() {
37
38
  * timeout without saying so — so this bounds it off the mint time.
38
39
  */ const REQUEST_TTL_MS = 120_000;
39
40
  export function createRecoveryPending(options) {
41
+ const monotonicNow = options?.monotonicNow ?? createRuntime().monotonicNow;
40
42
  const ttlMS = options?.ttlMS ?? REQUEST_TTL_MS;
41
43
  const requests = new Map();
42
44
  const remove = (requestID, request)=>{
@@ -45,7 +47,7 @@ export function createRecoveryPending(options) {
45
47
  requests.delete(requestID);
46
48
  };
47
49
  const sweep = ()=>{
48
- const now = Date.now();
50
+ const now = monotonicNow();
49
51
  for (const [id, request] of requests){
50
52
  if (request.expiresAt <= now) remove(id, request);
51
53
  }
@@ -68,7 +70,7 @@ export function createRecoveryPending(options) {
68
70
  nodeTimer.unref?.();
69
71
  requests.set(requestID, {
70
72
  ephemeralPrivateKey,
71
- expiresAt: Date.now() + retentionMs,
73
+ expiresAt: monotonicNow() + retentionMs,
72
74
  timer
73
75
  });
74
76
  },
@@ -109,8 +111,11 @@ export async function deriveRecoverySecret(handle) {
109
111
  * host must not put anything on it that confidentiality depends on.
110
112
  */ export function createGroupMLS(params) {
111
113
  const { access, identity, entrySlot } = params;
112
- const pending = createRecoveryPending();
113
- const recovery = createRecoveryBindingState(identity, params.recoveryBinding);
114
+ const runtime = createRuntime(params.runtime);
115
+ const pending = createRecoveryPending({
116
+ monotonicNow: runtime.monotonicNow
117
+ });
118
+ const recovery = createRecoveryBindingState(identity, params.recoveryBinding, runtime.now);
114
119
  const port = {
115
120
  async verifyRecoveryRequest (request) {
116
121
  try {
@@ -315,9 +320,11 @@ export async function deriveRecoverySecret(handle) {
315
320
  if (rejoined.group.anchor.controller != null && !await recoverySignerEligible({
316
321
  group: rejoined.group,
317
322
  registry: rejoined.knownRegistry,
318
- signer: reply.signer
323
+ signer: reply.signer,
324
+ now: runtime.now() / 1000
319
325
  })) return null;
320
326
  const judge = createVerdictJudge({
327
+ now: runtime.now,
321
328
  group: rejoined.group,
322
329
  sourceTree: rejoined.sourceTree,
323
330
  known: rejoined.knownRegistry,
package/lib/recovery.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type OwnIdentity } from '@kokuin/token';
2
2
  import { type ClientState, type ControllerBinding, type DeviceRegistry, type GroupHandle } from '@kumiai/mls';
3
3
  import type { OpenedRecoveryVerdict, PendingRecovery, PendingRecoveryConfirmationKeyParams } from '@kumiai/rpc';
4
+ import { type Now } from '@sozai/runtime';
4
5
  export type RecoveryBindingRequest = {
5
6
  groupID: string;
6
7
  controllerID: string;
@@ -13,6 +14,7 @@ export type RecoveryReply = {
13
14
  signer: string;
14
15
  };
15
16
  export type VerdictJudgeParams = {
17
+ now?: Now;
16
18
  group: GroupHandle;
17
19
  sourceTree: ClientState['ratchetTree'];
18
20
  known: DeviceRegistry;
@@ -27,7 +29,7 @@ export type RecoveryCandidate = PendingRecovery & {
27
29
  replyLedger: Array<string>;
28
30
  signer: string;
29
31
  };
30
- export declare function createRecoveryBindingState(identity: OwnIdentity, host?: RecoveryBinding): {
32
+ export declare function createRecoveryBindingState(identity: OwnIdentity, host?: RecoveryBinding, now?: Now): {
31
33
  prepare(group: GroupHandle): Promise<"ready" | "renewal-required">;
32
34
  join(group: GroupHandle, reply: RecoveryReply): Promise<{
33
35
  markBindingUnusable: () => void;
package/lib/recovery.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { normalizeDID } from '@kokuin/token';
2
2
  import { assertRecoveryBinding, assertRetainsKnownEffects, confirmationKey, confirmationTag, joinGroupExternal, LeafBindingError, LeafLapsedError, parseMLSCredentialIdentity, RevokeProofError, recoverySignerEligible } from '@kumiai/mls';
3
- export function createRecoveryBindingState(identity, host) {
3
+ import { createRuntime } from '@sozai/runtime';
4
+ export function createRecoveryBindingState(identity, host, now = createRuntime().now) {
4
5
  let binding;
5
6
  let asked = false;
6
7
  let prepared = false;
@@ -98,7 +99,8 @@ export function createRecoveryBindingState(identity, host) {
98
99
  if (!await recoverySignerEligible({
99
100
  group: pending,
100
101
  registry: source.registry,
101
- signer: reply.signer
102
+ signer: reply.signer,
103
+ now: now() / 1000
102
104
  })) throw new Error('Ineligible recovery attestation signer');
103
105
  signerEligible = true;
104
106
  candidateSource = source;
@@ -145,7 +147,7 @@ export function createRecoveryBindingState(identity, host) {
145
147
  };
146
148
  }
147
149
  export function createVerdictJudge(params) {
148
- const { group, sourceTree, known, requestID } = params;
150
+ const { group, sourceTree, known, requestID, now = createRuntime().now } = params;
149
151
  let tuple;
150
152
  return {
151
153
  async confirmationKey ({ position, commitDigest }) {
@@ -172,7 +174,8 @@ export function createVerdictJudge(params) {
172
174
  if (group.anchor.controller != null) return await recoverySignerEligible({
173
175
  group,
174
176
  registry: known,
175
- signer
177
+ signer,
178
+ now: now() / 1000
176
179
  }) ? 'authoritative' : 'advisory';
177
180
  if (verdict.verdict === 'confirmed') return 'authoritative';
178
181
  for (const node of sourceTree){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/mls-rpc",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "The @kumiai/rpc consumer ports (GroupCrypto, GroupMLS) implemented over @kumiai/mls",
5
5
  "keywords": [
6
6
  "mls",
@@ -26,10 +26,10 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@kokuin/token": "^0.7.1",
29
- "@kumiai/mls": "^0.13.2",
30
- "@kumiai/rpc": "^0.13.1",
29
+ "@kumiai/mls": "^0.13.3",
30
+ "@kumiai/rpc": "^0.13.2",
31
31
  "@noble/ciphers": "^2.4.0",
32
- "@sozai/runtime": "^0.1.0"
32
+ "@sozai/runtime": "^0.1.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@kumiai/rpc-conformance": "^0.13.0",