@kumiai/rpc 0.10.7 → 0.10.8

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 CHANGED
@@ -16,7 +16,6 @@ already aborted resolves `[]` without sending, including while the peer waits fo
16
16
 
17
17
  group-rpc never imports MLS. It owns transport and orchestration; the consumer supplies the crypto
18
18
  half through two ports:
19
-
20
19
  - **`GroupCrypto`** — a synchronous epoch hint, `exportSecret(label, length?)` for as many epoch-bound,
21
20
  domain-separated exported secrets as there are labels, `wrap`/`unwrap` for app traffic,
22
21
  `frameEpoch` and `frameAAD` to read a sealed frame's cleartext metadata, optional `pending`
@@ -39,7 +38,6 @@ hand-rolled seal keyed off anything but the epoch secret round-trips, throws not
39
38
  removed member open the ledger-entry blobs of commits enacted after its removal.
40
39
 
41
40
  Four constraints a port implementation is most likely to get wrong, all of which the suite pins:
42
-
43
41
  - **`epoch()` is a hint; decisions use the epoch a result reports.** A host's published epoch can
44
42
  lag its handle or, after a rolled-back transaction, run ahead of it. So every port result that
45
43
  acted on the handle carries the epoch it acted at, read under the host's handle lock:
@@ -140,7 +138,7 @@ type rejects it too, so an erased type cannot slip one past. Correlation traffic
140
138
  request re-fires its responder, and the rid/timeout/quorum machinery has no meaning outside its
141
139
  original round.
142
140
 
143
- Retention is the *protocol's* word, never the frame's. A retained frame naming an ephemeral
141
+ Retention is the _protocol's_ word, never the frame's. A retained frame naming an ephemeral
144
142
  procedure was published `retain: 'log'` by a member whose dispatch would not do that, and the drain
145
143
  drops it.
146
144
 
@@ -159,7 +157,7 @@ member's effective join is its rejoin epoch, and nothing a roster diff can see m
159
157
 
160
158
  ### The returning-member drain
161
159
 
162
- A peer that was away pulls each app topic's retained segment and delivers it through the *same*
160
+ A peer that was away pulls each app topic's retained segment and delivers it through the _same_
163
161
  handlers the live bus server is built from, so a drained frame and a pushed one reach the host by the
164
162
  same door. Its own frames are not delivered — the live fan-out never echoes a publisher its own
165
163
  broadcast, and a drain that did would make a returning member the only one to see its own messages
@@ -168,7 +166,7 @@ arrive.
168
166
  The rule that makes the durable cursor safe: **a cursor may only pass a frame that is DELIVERED or
169
167
  DEAD.** A frame sealed below the handle's epoch is dead (MLS ratchets forward — those bytes are
170
168
  ciphertext forever), as is one that claims this epoch and will not open, as are bytes that are not a
171
- sealed frame at all. A frame sealed *ahead* of the walk is neither: it opens once the walk gets
169
+ sealed frame at all. A frame sealed _ahead_ of the walk is neither: it opens once the walk gets
172
170
  there, so the cursor stops behind it and the frame stays buffered. That distinction is what
173
171
  `GroupCrypto.frameEpoch` exists for — `unwrap` throwing says "not my epoch" and cannot say which.
174
172
 
@@ -184,11 +182,11 @@ real gap.
184
182
  all** — the params type is a union, so a host cannot wire a subset. Each missing piece is a silent
185
183
  failure:
186
184
 
187
- | | Without it |
188
- | --- | --- |
189
- | `journal` — durable single slot, written before every publish, cleared on both outcomes | every commit whose process died in the acceptance window is silently lost |
190
- | `anchorStore` — one slot, overwritten on every rotation, read once at construction | the peer re-seeds the anchor at its live epoch on the next restart and silently partitions from its own group, deriving topics no member that stayed up is on |
191
- | `appCursorStore` — a read position per topic, written as each drain finishes | the peer re-reads its app history from the hub's oldest retained frame every restart, re-delivers what it already delivered, and has nowhere to notice the retention floor passing it |
185
+ | | Without it |
186
+ | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
187
+ | `journal` — durable single slot, written before every publish, cleared on both outcomes | every commit whose process died in the acceptance window is silently lost |
188
+ | `anchorStore` — one slot, overwritten on every rotation, read once at construction | the peer re-seeds the anchor at its live epoch on the next restart and silently partitions from its own group, deriving topics no member that stayed up is on |
189
+ | `appCursorStore` — a read position per topic, written as each drain finishes | the peer re-reads its app history from the hub's oldest retained frame every restart, re-delivers what it already delivered, and has nowhere to notice the retention floor passing it |
192
190
 
193
191
  Neither the anchor nor the cursor can be re-derived. The anchor sits at an epoch the live handle then
194
192
  runs past, and MLS ratchets forward, so a rebooted handle can never re-export it.
@@ -216,12 +214,12 @@ Each `StrandObservation` names the stable commit-topic `groupID`, the frame's lo
216
214
  peer's `localEpoch`, a `kind`, and a `confidence`. `claimedEpoch` comes from the cleartext header;
217
215
  `commitDigest` identifies the commit bytes. Both are `null` for an unreadable future version.
218
216
 
219
- | Kind | Confidence | What the evidence establishes |
220
- | --- | --- | --- |
221
- | `own-unmerged` | `authenticated` | Sender data proves this device sealed a commit at this epoch that the hub now places in the log. Commit content is unverified; a hub can tamper beyond the ciphertext sample or fake acceptance. Heal. |
222
- | `fork-losing` | `observed` | This peer enacted different commit bytes at that epoch and is on the branch that loses the log-position tiebreak. The other commit is not authenticated. |
223
- | `ahead` | `claimed` | A frame's cleartext epoch is ahead of this peer. A commit-topic publisher can forge that claim. |
224
- | `unknown-version` | `claimed` | A frame's handshake or commit-frame version cannot be read by this build. Its epoch and commit bytes are unavailable. |
217
+ | Kind | Confidence | What the evidence establishes |
218
+ | ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
219
+ | `own-unmerged` | `authenticated` | Sender data proves this device sealed a commit at this epoch that the hub now places in the log. Commit content is unverified; a hub can tamper beyond the ciphertext sample or fake acceptance. Heal. |
220
+ | `fork-losing` | `observed` | This peer enacted different commit bytes at that epoch and is on the branch that loses the log-position tiebreak. The other commit is not authenticated. |
221
+ | `ahead` | `claimed` | A frame's cleartext epoch is ahead of this peer. A commit-topic publisher can forge that claim. |
222
+ | `unknown-version` | `claimed` | A frame's handshake or commit-frame version cannot be read by this build. Its epoch and commit bytes are unavailable. |
225
223
 
226
224
  `GroupPeerParams.onRecovery` reports `started` and exactly one terminal event (`succeeded` or
227
225
  `failed`) for each attempt. The event's `attemptID`, `groupID` and `trigger` (`automatic` or
package/lib/commit.d.ts CHANGED
@@ -10,6 +10,12 @@ export type CommitKind = 'ledger' | 'invite' | 'remove';
10
10
  * derived handle and never advance the source — so the host's live handle is still the
11
11
  * pre-commit one, which is what lets the peer seal the bodies under the epoch every receiver of
12
12
  * this commit is at.
13
+ *
14
+ * GroupMLS.prepareCommitBuild and commitBuildFramed must be supplied together or both omitted.
15
+ * Without hooks, the host builder must durably reserve a handshake generation before every build.
16
+ * It must durably consume that reservation after building, before returning this PendingCommit for journalling or publication.
17
+ * With @kumiai/mls, call group.consumeHandshakeReservation(persist) on the source handle.
18
+ * Only durable proof that no frame could have left the device permits reservation reuse.
13
19
  */
14
20
  export type PendingCommit = {
15
21
  /** Framed MLSMessage(Commit) bytes. */
package/lib/crypto.d.ts CHANGED
@@ -377,6 +377,21 @@ export type GroupMLS = {
377
377
  sendAdmission(): SendAdmission;
378
378
  /** Read the current handle epoch under the host's handle lock. */
379
379
  readEpoch(): Promise<number>;
380
+ /**
381
+ * Durably reserve a handshake sender generation before EVERY host build.
382
+ * Reuse only durable evidence of a reservation that has never permitted publication.
383
+ * Keep the epoch, ledger and application ratchet unchanged.
384
+ * Resolve only after persistence. On failure the peer must not invoke the builder.
385
+ * Implement both build hooks or neither. An incomplete pair throws CommitBuildHooksError at construction.
386
+ * Without hooks, builders must reserve and consume durably before returning their frame.
387
+ */
388
+ prepareCommitBuild?(): Promise<void>;
389
+ /**
390
+ * Persist reservation consumption after build, before journalling or publishing its frame.
391
+ * Required whenever prepareCommitBuild is present, including when preparation always burns a generation.
392
+ * Builders must return their frame before publishing it.
393
+ */
394
+ commitBuildFramed?(): Promise<void>;
380
395
  /**
381
396
  * The leaves this handle's ratchet tree currently holds, one {@link RosterEntry} per leaf, in
382
397
  * ascending `leafIndex` order. Purely local: reads no secret, advances nothing.
package/lib/errors.d.ts CHANGED
@@ -9,6 +9,9 @@ export declare class PeerDisposedError extends Error {
9
9
  export declare class PeerRemovedError extends Error {
10
10
  name: string;
11
11
  }
12
+ export declare class CommitBuildHooksError extends Error {
13
+ constructor();
14
+ }
12
15
  export declare class AppOutboxFullError extends Error {
13
16
  name: string;
14
17
  }
package/lib/errors.js CHANGED
@@ -8,6 +8,12 @@
8
8
  export class PeerRemovedError extends Error {
9
9
  name = 'PeerRemovedError';
10
10
  }
11
+ export class CommitBuildHooksError extends Error {
12
+ constructor(){
13
+ super('GroupMLS must implement prepareCommitBuild and commitBuildFramed together');
14
+ this.name = 'CommitBuildHooksError';
15
+ }
16
+ }
11
17
  export class AppOutboxFullError extends Error {
12
18
  name = 'AppOutboxFullError';
13
19
  }
@@ -43,6 +43,8 @@ export declare const mlsHostMembers: {
43
43
  readonly openRecoveryVerdict: "host";
44
44
  readonly sendAdmission: "host";
45
45
  readonly readEpoch: "host";
46
+ readonly prepareCommitBuild: "host";
47
+ readonly commitBuildFramed: "host";
46
48
  readonly rosterEntries: "host";
47
49
  readonly readCommitHeader: "host";
48
50
  readonly processCommit: "host";
@@ -1,4 +1,4 @@
1
- import { PeerDisposedError } from './errors.js';
1
+ import { CommitBuildHooksError, PeerDisposedError } from './errors.js';
2
2
  // New recovery methods must be classified alongside the existing acceptance callback.
3
3
  export const pendingRecoveryHostMembers = {
4
4
  epoch: 'data',
@@ -37,6 +37,8 @@ export const mlsHostMembers = {
37
37
  openRecoveryVerdict: 'host',
38
38
  sendAdmission: 'host',
39
39
  readEpoch: 'host',
40
+ prepareCommitBuild: 'host',
41
+ commitBuildFramed: 'host',
40
42
  rosterEntries: 'host',
41
43
  readCommitHeader: 'host',
42
44
  processCommit: 'host',
@@ -230,8 +232,13 @@ export function wrapPeerHost(boundary, params) {
230
232
  value: crypto.pending == null ? undefined : selectHostMembers(boundary, crypto.pending, pendingFrameHostMembers)
231
233
  });
232
234
  } else if (key === 'anchorStore') selected = selectHostMembers(boundary, value, anchorStoreHostMembers);
233
- else if (kind === 'mls') selected = selectHostMembers(boundary, value, mlsHostMembers);
234
- else if (kind === 'handlers') {
235
+ else if (kind === 'mls') {
236
+ const mls = value;
237
+ if (typeof mls.prepareCommitBuild === 'function' !== (typeof mls.commitBuildFramed === 'function')) {
238
+ throw new CommitBuildHooksError();
239
+ }
240
+ selected = selectHostMembers(boundary, mls, mlsHostMembers);
241
+ } else if (kind === 'handlers') {
235
242
  selected = Object.fromEntries(Object.entries(value).map(([name, handlers])=>[
236
243
  name,
237
244
  boundary.wrap(handlers)
package/lib/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { CommitDeadlineError, type CommitJournal, type CommitKind, isHeadMismatc
13
13
  export { COMMIT_FRAME_VERSION, type CommitFrame, decodeCommitFrame, encodeCommitFrame, isUnsupportedCommitFrameVersion, UnsupportedCommitFrameVersionError, } from './commit-frame.js';
14
14
  export { type AppFrameRef, AppFrameStorageError, type AppliedRecovery, type CommitContext, type CommitHeader, type ExportSecretResult, FrameEpochError, type GroupCrypto, type GroupMLS, type GroupUnwrapResult, isAppFrameStorageError, isMissingLedgerEntries, type OpenedRecoveryVerdict, type PendingAppFrame, type PendingAppFrames, type PendingRecovery, type ProcessCommitResult, type RecoveryConfirmationKey, type RecoveryRefusalReason, type RecoveryVerdict, type RosterEntry, type SealEntriesResult, type SendAdmission, sortPendingAppFrames, type VerifiedRecoveryRequest, } from './crypto.js';
15
15
  export { asDeliveryPosition, asLogPosition, type DeliveryPosition, type LogPosition, } from './cursor.js';
16
- export { AppEntryTooLargeError, AppOutboxFullError, PeerDisposedError, PeerRemovedError, SendNotAdmissibleError, } from './errors.js';
16
+ export { AppEntryTooLargeError, AppOutboxFullError, CommitBuildHooksError, PeerDisposedError, PeerRemovedError, SendNotAdmissibleError, } from './errors.js';
17
17
  export { assertFrameFits, FrameTooLargeError } from './frame-size.js';
18
18
  export type { GroupProcedureHandlers } from './handlers.js';
19
19
  export { decodeHandshakeFrame, encodeHandshakeFrame, HANDSHAKE_KIND, HANDSHAKE_MAGIC, HANDSHAKE_VERSION, type HandshakeKind, } from './handshake.js';
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ export { CommitDeadlineError, isHeadMismatch, JournalEpochError, RecoveryRequire
9
9
  export { COMMIT_FRAME_VERSION, decodeCommitFrame, encodeCommitFrame, isUnsupportedCommitFrameVersion, UnsupportedCommitFrameVersionError } from './commit-frame.js';
10
10
  export { AppFrameStorageError, FrameEpochError, isAppFrameStorageError, isMissingLedgerEntries, sortPendingAppFrames } from './crypto.js';
11
11
  export { asDeliveryPosition, asLogPosition } from './cursor.js';
12
- export { AppEntryTooLargeError, AppOutboxFullError, PeerDisposedError, PeerRemovedError, SendNotAdmissibleError } from './errors.js';
12
+ export { AppEntryTooLargeError, AppOutboxFullError, CommitBuildHooksError, PeerDisposedError, PeerRemovedError, SendNotAdmissibleError } from './errors.js';
13
13
  export { assertFrameFits, FrameTooLargeError } from './frame-size.js';
14
14
  export { decodeHandshakeFrame, encodeHandshakeFrame, HANDSHAKE_KIND, HANDSHAKE_MAGIC, HANDSHAKE_VERSION } from './handshake.js';
15
15
  export { createLedgerEntryResolver, decodeLedgerEntries, encodeLedgerEntries, LEDGER_ENTRIES_VERSION } from './ledger-entries.js';
package/lib/peer.js CHANGED
@@ -1900,8 +1900,13 @@ export function createGroupPeer(input) {
1900
1900
  }
1901
1901
  // 2. Build against the host's CURRENT handle, adopting nothing. `build` closes over that
1902
1902
  // handle, so a rebased retry frames at the rebased epoch.
1903
+ // Reserve durably before framing: the CAS winner may never advance our epoch.
1904
+ await mls.prepareCommitBuild?.();
1905
+ assertLive();
1903
1906
  const pending = wrapPendingCommit(boundary, await build());
1904
1907
  assertLive();
1908
+ await mls.commitBuildFramed?.();
1909
+ assertLive();
1905
1910
  // 3. Journal BEFORE publishing, durably: from here to the hub's answer is the crash
1906
1911
  // window, and the slot is the only thing that survives it.
1907
1912
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/rpc",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "description": "High-level MLS-aware group RPC for Enkaku: bus broadcast/anycast/gather plus directed RPC over the pub/sub hub",
5
5
  "keywords": [
6
6
  "rpc",
@@ -26,26 +26,26 @@
26
26
  "lib/*"
27
27
  ],
28
28
  "dependencies": {
29
- "@enkaku/client": "^0.21.3",
30
- "@enkaku/protocol": "^0.21.4",
31
- "@enkaku/server": "^0.21.4",
32
- "@enkaku/transport": "^0.21.3",
29
+ "@enkaku/client": "^0.21.5",
30
+ "@enkaku/protocol": "^0.21.5",
31
+ "@enkaku/server": "^0.21.5",
32
+ "@enkaku/transport": "^0.21.5",
33
33
  "@kokuin/token": "^0.5.1",
34
34
  "@kumiai/broadcast": "^0.10.0",
35
- "@kumiai/hub-protocol": "^0.10.1",
35
+ "@kumiai/hub-protocol": "^0.10.2",
36
36
  "@kumiai/hub-tunnel": "^0.10.3",
37
37
  "@noble/hashes": "^2.4.0",
38
- "@sozai/codec": "^0.4.2",
39
- "@sozai/event": "^0.1.5",
38
+ "@sozai/codec": "^0.4.3",
39
+ "@sozai/event": "^0.1.6",
40
40
  "@sozai/log": "^0.4.0",
41
41
  "@sozai/runtime": "^0.1.0",
42
42
  "@sozai/schema": "^0.1.6"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@kumiai/hub-conformance": "^0.10.1",
46
- "@kumiai/rpc-conformance": "^0.10.1",
46
+ "@kumiai/rpc-conformance": "^0.10.2",
47
47
  "@noble/curves": "^2.4.0",
48
- "vitest": "^5.0.3"
48
+ "vitest": "^5.0.5"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"