@kumiai/rpc 0.10.7 → 0.10.9
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 +18 -17
- package/lib/anchor.d.ts +5 -0
- package/lib/commit.d.ts +6 -0
- package/lib/crypto.d.ts +34 -1
- package/lib/errors.d.ts +3 -0
- package/lib/errors.js +6 -0
- package/lib/host-boundary.d.ts +2 -0
- package/lib/host-boundary.js +10 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/peer.js +21 -4
- package/lib/roster.d.ts +15 -1
- package/lib/roster.js +20 -1
- package/package.json +10 -10
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
|
|
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
|
|
|
@@ -153,13 +151,16 @@ move it too, because MLS ratchets forward and a member added at epoch E cannot e
|
|
|
153
151
|
epoch's secret. `max(last add, last remove)` is the only epoch that is both after every removal and
|
|
154
152
|
holdable by every current member, and every member reaches it by applying the same commit, so they
|
|
155
153
|
agree natively. A rejoin rotates it as well, on the applied commit's own external flag — a rejoining
|
|
156
|
-
member's effective join is its rejoin epoch, and nothing a roster diff can see moves.
|
|
154
|
+
member's effective join is its rejoin epoch, and nothing a roster diff can see moves. So does a
|
|
155
|
+
stale-leaf replacement (a Remove and an Add of the same DID in one commit): the DID set is unchanged,
|
|
156
|
+
so the peer reads it from `RosterEntry.admission` — an admission present after the commit and absent
|
|
157
|
+
before it is an Add.
|
|
157
158
|
|
|
158
159
|
`GroupPeer.anchorEpoch()` exposes where it sits.
|
|
159
160
|
|
|
160
161
|
### The returning-member drain
|
|
161
162
|
|
|
162
|
-
A peer that was away pulls each app topic's retained segment and delivers it through the
|
|
163
|
+
A peer that was away pulls each app topic's retained segment and delivers it through the _same_
|
|
163
164
|
handlers the live bus server is built from, so a drained frame and a pushed one reach the host by the
|
|
164
165
|
same door. Its own frames are not delivered — the live fan-out never echoes a publisher its own
|
|
165
166
|
broadcast, and a drain that did would make a returning member the only one to see its own messages
|
|
@@ -168,7 +169,7 @@ arrive.
|
|
|
168
169
|
The rule that makes the durable cursor safe: **a cursor may only pass a frame that is DELIVERED or
|
|
169
170
|
DEAD.** A frame sealed below the handle's epoch is dead (MLS ratchets forward — those bytes are
|
|
170
171
|
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
|
|
172
|
+
sealed frame at all. A frame sealed _ahead_ of the walk is neither: it opens once the walk gets
|
|
172
173
|
there, so the cursor stops behind it and the frame stays buffered. That distinction is what
|
|
173
174
|
`GroupCrypto.frameEpoch` exists for — `unwrap` throwing says "not my epoch" and cannot say which.
|
|
174
175
|
|
|
@@ -184,11 +185,11 @@ real gap.
|
|
|
184
185
|
all** — the params type is a union, so a host cannot wire a subset. Each missing piece is a silent
|
|
185
186
|
failure:
|
|
186
187
|
|
|
187
|
-
|
|
|
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
|
|
191
|
-
| `appCursorStore` — a read position per topic, written as each drain finishes
|
|
188
|
+
| | Without it |
|
|
189
|
+
| --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `journal` — durable single slot, written before every publish, cleared on both outcomes | every commit whose process died in the acceptance window is silently lost |
|
|
191
|
+
| `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 |
|
|
192
|
+
| `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
193
|
|
|
193
194
|
Neither the anchor nor the cursor can be re-derived. The anchor sits at an epoch the live handle then
|
|
194
195
|
runs past, and MLS ratchets forward, so a rebooted handle can never re-export it.
|
|
@@ -216,12 +217,12 @@ Each `StrandObservation` names the stable commit-topic `groupID`, the frame's lo
|
|
|
216
217
|
peer's `localEpoch`, a `kind`, and a `confidence`. `claimedEpoch` comes from the cleartext header;
|
|
217
218
|
`commitDigest` identifies the commit bytes. Both are `null` for an unreadable future version.
|
|
218
219
|
|
|
219
|
-
| Kind
|
|
220
|
-
|
|
|
221
|
-
| `own-unmerged`
|
|
222
|
-
| `fork-losing`
|
|
223
|
-
| `ahead`
|
|
224
|
-
| `unknown-version` | `claimed`
|
|
220
|
+
| Kind | Confidence | What the evidence establishes |
|
|
221
|
+
| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
222
|
+
| `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. |
|
|
223
|
+
| `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. |
|
|
224
|
+
| `ahead` | `claimed` | A frame's cleartext epoch is ahead of this peer. A commit-topic publisher can forge that claim. |
|
|
225
|
+
| `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
226
|
|
|
226
227
|
`GroupPeerParams.onRecovery` reports `started` and exactly one terminal event (`succeeded` or
|
|
227
228
|
`failed`) for each attempt. The event's `attemptID`, `groupID` and `trigger` (`automatic` or
|
package/lib/anchor.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ export type AnchorSlot = {
|
|
|
14
14
|
epochBefore: number;
|
|
15
15
|
epochAfter: number;
|
|
16
16
|
rosterBefore: Array<string>;
|
|
17
|
+
/**
|
|
18
|
+
* The leaf admissions held before the advance. Absent on a record written before admissions
|
|
19
|
+
* were tracked, which resolves on the roster diff and `forced` alone.
|
|
20
|
+
*/
|
|
21
|
+
admissionsBefore?: Array<string>;
|
|
17
22
|
forced: boolean;
|
|
18
23
|
advance: string;
|
|
19
24
|
};
|
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
|
@@ -241,6 +241,22 @@ export type RosterEntry = {
|
|
|
241
241
|
* guarantee: it is whatever the credential holds, and for an id with no long form it is the id.
|
|
242
242
|
*/
|
|
243
243
|
longForm: string;
|
|
244
|
+
/**
|
|
245
|
+
* Names the KeyPackage this leaf was Added from, for as long as the leaf still holds that
|
|
246
|
+
* KeyPackage's leaf node — until the member's own first path or Update replaces it. Absent once
|
|
247
|
+
* it has, and absent on a leaf that entered by external commit (its leaf node is path-made).
|
|
248
|
+
* Opaque, compared only for equality; unique per KeyPackage (real impl: the leaf's HPKE
|
|
249
|
+
* encryption key).
|
|
250
|
+
*
|
|
251
|
+
* Read around {@link GroupMLS.processCommit} it says whether the Commit ADDED a leaf: only an
|
|
252
|
+
* Add puts a KeyPackage leaf node into the tree, so a value present after and absent before is
|
|
253
|
+
* an Add — including one the `did` diff cannot see, a Remove and an Add of the SAME DID in one
|
|
254
|
+
* Commit (a stale-leaf replacement). An ordinary path or Update commit only ever drops a value,
|
|
255
|
+
* never brings one. See {@link "roster".detectLeafAdmission}.
|
|
256
|
+
*
|
|
257
|
+
* Optional for implementations that cannot read it; the lane then sees only `did` changes.
|
|
258
|
+
*/
|
|
259
|
+
admission?: string;
|
|
244
260
|
};
|
|
245
261
|
/**
|
|
246
262
|
* What a Commit says about itself, readable WITHOUT applying it and without decrypting: the
|
|
@@ -377,6 +393,21 @@ export type GroupMLS = {
|
|
|
377
393
|
sendAdmission(): SendAdmission;
|
|
378
394
|
/** Read the current handle epoch under the host's handle lock. */
|
|
379
395
|
readEpoch(): Promise<number>;
|
|
396
|
+
/**
|
|
397
|
+
* Durably reserve a handshake sender generation before EVERY host build.
|
|
398
|
+
* Reuse only durable evidence of a reservation that has never permitted publication.
|
|
399
|
+
* Keep the epoch, ledger and application ratchet unchanged.
|
|
400
|
+
* Resolve only after persistence. On failure the peer must not invoke the builder.
|
|
401
|
+
* Implement both build hooks or neither. An incomplete pair throws CommitBuildHooksError at construction.
|
|
402
|
+
* Without hooks, builders must reserve and consume durably before returning their frame.
|
|
403
|
+
*/
|
|
404
|
+
prepareCommitBuild?(): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Persist reservation consumption after build, before journalling or publishing its frame.
|
|
407
|
+
* Required whenever prepareCommitBuild is present, including when preparation always burns a generation.
|
|
408
|
+
* Builders must return their frame before publishing it.
|
|
409
|
+
*/
|
|
410
|
+
commitBuildFramed?(): Promise<void>;
|
|
380
411
|
/**
|
|
381
412
|
* The leaves this handle's ratchet tree currently holds, one {@link RosterEntry} per leaf, in
|
|
382
413
|
* ascending `leafIndex` order. Purely local: reads no secret, advances nothing.
|
|
@@ -387,7 +418,9 @@ export type GroupMLS = {
|
|
|
387
418
|
* matter to that diff (see {@link "roster".detectRosterChange}).
|
|
388
419
|
*
|
|
389
420
|
* Membership only: a rejoin by a member the roster still holds changes no `did` and is invisible
|
|
390
|
-
* to a `did` diff — {@link CommitHeader.external} is what the lane rotates on for that.
|
|
421
|
+
* to a `did` diff — {@link CommitHeader.external} is what the lane rotates on for that. A
|
|
422
|
+
* same-DID leaf replacement is invisible to it too, and {@link RosterEntry.admission} is what
|
|
423
|
+
* the lane rotates on for that.
|
|
391
424
|
*/
|
|
392
425
|
rosterEntries(): Promise<Array<RosterEntry>>;
|
|
393
426
|
/**
|
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
|
}
|
package/lib/host-boundary.d.ts
CHANGED
|
@@ -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";
|
package/lib/host-boundary.js
CHANGED
|
@@ -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')
|
|
234
|
-
|
|
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';
|
|
@@ -23,5 +23,5 @@ export type { AppOutboxCleared, EpochFloor } from './log-delivery.js';
|
|
|
23
23
|
export { createGroupPeer, type GroupPeer, type GroupPeerMLSParams, type GroupPeerParams, type ProtocolSurface, type RecoveryEvent, type RecoveryFailureDetails, type RecoveryFailureReason, type RecoveryTrigger, type StrandConfidence, type StrandKind, type StrandObservation, } from './peer.js';
|
|
24
24
|
export { defineGroupProtocol, type GroupProcedureDefinition, type GroupProtocolDefinition, type RetainableEventProcedureDefinition, type Retention, retentionOf, } from './protocol.js';
|
|
25
25
|
export { decodeLedgerReply, decodeLedgerRequest, decodeRecoveryConfirmRequest, decodeRecoveryReply, decodeRecoveryRequest, decodeRecoveryVerdict, encodeLedgerReply, encodeLedgerRequest, encodeRecoveryConfirmRequest, encodeRecoveryReply, encodeRecoveryRequest, encodeRecoveryVerdict, type RecoveryConfirmRequest, type RecoveryVerdictFrame, } from './recovery.js';
|
|
26
|
-
export { detectRosterChange } from './roster.js';
|
|
26
|
+
export { detectLeafAdmission, detectRosterChange } from './roster.js';
|
|
27
27
|
export { APP_TOPIC_LABEL, COMMIT_LABEL, commitTopic, discoveryTopic, INBOX_LABEL, inboxTopic, protocolTopic, RENDEZVOUS_LABEL, rendezvousTopic, } from './topic.js';
|
package/lib/index.js
CHANGED
|
@@ -9,12 +9,12 @@ 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';
|
|
16
16
|
export { createGroupPeer } from './peer.js';
|
|
17
17
|
export { defineGroupProtocol, retentionOf } from './protocol.js';
|
|
18
18
|
export { decodeLedgerReply, decodeLedgerRequest, decodeRecoveryConfirmRequest, decodeRecoveryReply, decodeRecoveryRequest, decodeRecoveryVerdict, encodeLedgerReply, encodeLedgerRequest, encodeRecoveryConfirmRequest, encodeRecoveryReply, encodeRecoveryRequest, encodeRecoveryVerdict } from './recovery.js';
|
|
19
|
-
export { detectRosterChange } from './roster.js';
|
|
19
|
+
export { detectLeafAdmission, detectRosterChange } from './roster.js';
|
|
20
20
|
export { APP_TOPIC_LABEL, COMMIT_LABEL, commitTopic, discoveryTopic, INBOX_LABEL, inboxTopic, protocolTopic, RENDEZVOUS_LABEL, rendezvousTopic } from './topic.js';
|
package/lib/peer.js
CHANGED
|
@@ -22,7 +22,7 @@ import { DEFAULT_APP_LOG_RETENTION_SECONDS, DEFAULT_COMMIT_DEADLINE_MS, DEFAULT_
|
|
|
22
22
|
import { retentionOf } from './protocol.js';
|
|
23
23
|
import { decodeLedgerReply, decodeLedgerRequest, decodeRecoveryConfirmRequest, decodeRecoveryReply, decodeRecoveryRequest, decodeRecoveryVerdict, encodeLedgerReply, encodeLedgerRequest, encodeRecoveryConfirmRequest, encodeRecoveryReply, encodeRecoveryRequest, encodeRecoveryVerdict } from './recovery.js';
|
|
24
24
|
import { confirmationTag, createRecoveryCache, waitForRecoveryConfirmation } from './recovery-confirmation.js';
|
|
25
|
-
import { detectRosterChange } from './roster.js';
|
|
25
|
+
import { detectLeafAdmission, detectRosterChange } from './roster.js';
|
|
26
26
|
import { APP_TOPIC_LABEL, commitTopic, inboxTopic, protocolTopic, rendezvousTopic } from './topic.js';
|
|
27
27
|
export { DEFAULT_APP_LOG_RETENTION_SECONDS, DEFAULT_COMMIT_LOG_RETENTION_SECONDS } from './peer-types.js';
|
|
28
28
|
/** How many commit frames a single pull asks for. Pull loops until the log is drained. */ const COMMIT_FETCH_LIMIT = 100;
|
|
@@ -43,6 +43,11 @@ const CONFIDENCE_RANK = {
|
|
|
43
43
|
observed: 1,
|
|
44
44
|
authenticated: 2
|
|
45
45
|
};
|
|
46
|
+
/** The leaf admissions a roster holds (see {@link RosterEntry.admission}). */ function admissionsOf(entries) {
|
|
47
|
+
return entries.flatMap((entry)=>entry.admission == null ? [] : [
|
|
48
|
+
entry.admission
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
46
51
|
function verdictForOutcome(binding, outcome) {
|
|
47
52
|
switch(outcome.kind){
|
|
48
53
|
case 'applied':
|
|
@@ -276,8 +281,12 @@ export function createGroupPeer(input) {
|
|
|
276
281
|
requireAnchorRecovery();
|
|
277
282
|
return;
|
|
278
283
|
}
|
|
279
|
-
const
|
|
280
|
-
|
|
284
|
+
const entries = await port.rosterEntries();
|
|
285
|
+
const roster = entries.map((entry)=>normalizeDID(entry.did));
|
|
286
|
+
// An Add of a DID the roster already held — a stale-leaf replacement — moves no DID, and its
|
|
287
|
+
// Welcome joiner seeds at this epoch all the same: the fresh leaf is what says so.
|
|
288
|
+
const admitted = record.admissionsBefore != null && detectLeafAdmission(record.admissionsBefore, admissionsOf(entries));
|
|
289
|
+
if (record.forced || admitted || detectRosterChange(record.rosterBefore, roster)) {
|
|
281
290
|
await captureAnchor(record.advance);
|
|
282
291
|
} else {
|
|
283
292
|
await keepAnchor();
|
|
@@ -922,13 +931,16 @@ export function createGroupPeer(input) {
|
|
|
922
931
|
}
|
|
923
932
|
if (!confirmedRecovery) await appLane.deliver();
|
|
924
933
|
assertLive();
|
|
925
|
-
|
|
934
|
+
// A retry keeps the record's pre-advance view: the live tree may already be past it.
|
|
935
|
+
const entriesBefore = retry && pending != null ? [] : await port.rosterEntries();
|
|
936
|
+
const rosterBefore = retry && pending != null ? pending.rosterBefore : entriesBefore.map((entry)=>normalizeDID(entry.did));
|
|
926
937
|
const epochBefore = await port.readEpoch();
|
|
927
938
|
assertLive();
|
|
928
939
|
const record = retry && pending != null ? pending : {
|
|
929
940
|
epochBefore,
|
|
930
941
|
epochAfter: identity.epochAfter,
|
|
931
942
|
rosterBefore,
|
|
943
|
+
admissionsBefore: admissionsOf(entriesBefore),
|
|
932
944
|
forced: identity.forced,
|
|
933
945
|
advance: identity.advance
|
|
934
946
|
};
|
|
@@ -1900,8 +1912,13 @@ export function createGroupPeer(input) {
|
|
|
1900
1912
|
}
|
|
1901
1913
|
// 2. Build against the host's CURRENT handle, adopting nothing. `build` closes over that
|
|
1902
1914
|
// handle, so a rebased retry frames at the rebased epoch.
|
|
1915
|
+
// Reserve durably before framing: the CAS winner may never advance our epoch.
|
|
1916
|
+
await mls.prepareCommitBuild?.();
|
|
1917
|
+
assertLive();
|
|
1903
1918
|
const pending = wrapPendingCommit(boundary, await build());
|
|
1904
1919
|
assertLive();
|
|
1920
|
+
await mls.commitBuildFramed?.();
|
|
1921
|
+
assertLive();
|
|
1905
1922
|
// 3. Journal BEFORE publishing, durably: from here to the hub's answer is the crash
|
|
1906
1923
|
// window, and the slot is the only thing that survives it.
|
|
1907
1924
|
//
|
package/lib/roster.d.ts
CHANGED
|
@@ -17,6 +17,20 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Pure: no state, no order dependence (the inputs are compared as sets), duplicates ignored.
|
|
19
19
|
* Because it compares DIDs and not leaves, a change that leaves the DID set intact is invisible
|
|
20
|
-
* to it — an external-commit rejoin by a member the roster still holds is exactly that
|
|
20
|
+
* to it — an external-commit rejoin by a member the roster still holds is exactly that, and so is
|
|
21
|
+
* a stale-leaf replacement (a Remove and an Add of the same DID in one Commit), which
|
|
22
|
+
* {@link detectLeafAdmission} sees.
|
|
21
23
|
*/
|
|
22
24
|
export declare function detectRosterChange(before: Array<string>, after: Array<string>): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Detect an ADD by diffing the leaf admissions around a Commit's application (see the rpc
|
|
27
|
+
* `RosterEntry.admission`): `true` iff a value is present after that was absent before.
|
|
28
|
+
*
|
|
29
|
+
* Only an Add puts a KeyPackage leaf node into the tree, so a new admission is an Add, and every
|
|
30
|
+
* Add brings one. It sees the Add a DID diff cannot: a Remove and an Add of the same DID in one
|
|
31
|
+
* Commit, whose re-added member joins by Welcome at the post-commit epoch and can never export the
|
|
32
|
+
* anchor the group would otherwise keep. A value that disappears is a member's own path or Update
|
|
33
|
+
* replacing the leaf node it was Added with, or a Remove — neither is an Add, and the first must
|
|
34
|
+
* not rotate.
|
|
35
|
+
*/
|
|
36
|
+
export declare function detectLeafAdmission(before: Array<string>, after: Array<string>): boolean;
|
package/lib/roster.js
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Pure: no state, no order dependence (the inputs are compared as sets), duplicates ignored.
|
|
19
19
|
* Because it compares DIDs and not leaves, a change that leaves the DID set intact is invisible
|
|
20
|
-
* to it — an external-commit rejoin by a member the roster still holds is exactly that
|
|
20
|
+
* to it — an external-commit rejoin by a member the roster still holds is exactly that, and so is
|
|
21
|
+
* a stale-leaf replacement (a Remove and an Add of the same DID in one Commit), which
|
|
22
|
+
* {@link detectLeafAdmission} sees.
|
|
21
23
|
*/ export function detectRosterChange(before, after) {
|
|
22
24
|
const held = new Set(before);
|
|
23
25
|
const present = new Set(after);
|
|
@@ -27,3 +29,20 @@
|
|
|
27
29
|
}
|
|
28
30
|
return false;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Detect an ADD by diffing the leaf admissions around a Commit's application (see the rpc
|
|
34
|
+
* `RosterEntry.admission`): `true` iff a value is present after that was absent before.
|
|
35
|
+
*
|
|
36
|
+
* Only an Add puts a KeyPackage leaf node into the tree, so a new admission is an Add, and every
|
|
37
|
+
* Add brings one. It sees the Add a DID diff cannot: a Remove and an Add of the same DID in one
|
|
38
|
+
* Commit, whose re-added member joins by Welcome at the post-commit epoch and can never export the
|
|
39
|
+
* anchor the group would otherwise keep. A value that disappears is a member's own path or Update
|
|
40
|
+
* replacing the leaf node it was Added with, or a Remove — neither is an Add, and the first must
|
|
41
|
+
* not rotate.
|
|
42
|
+
*/ export function detectLeafAdmission(before, after) {
|
|
43
|
+
const held = new Set(before);
|
|
44
|
+
for (const admission of after){
|
|
45
|
+
if (!held.has(admission)) return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/rpc",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.9",
|
|
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.
|
|
30
|
-
"@enkaku/protocol": "^0.21.
|
|
31
|
-
"@enkaku/server": "^0.21.
|
|
32
|
-
"@enkaku/transport": "^0.21.
|
|
29
|
+
"@enkaku/client": "^0.21.6",
|
|
30
|
+
"@enkaku/protocol": "^0.21.6",
|
|
31
|
+
"@enkaku/server": "^0.21.6",
|
|
32
|
+
"@enkaku/transport": "^0.21.6",
|
|
33
33
|
"@kokuin/token": "^0.5.1",
|
|
34
34
|
"@kumiai/broadcast": "^0.10.0",
|
|
35
|
-
"@kumiai/hub-protocol": "^0.10.
|
|
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.
|
|
39
|
-
"@sozai/event": "^0.1.
|
|
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.
|
|
46
|
+
"@kumiai/rpc-conformance": "^0.10.3",
|
|
47
47
|
"@noble/curves": "^2.4.0",
|
|
48
|
-
"vitest": "^5.0.
|
|
48
|
+
"vitest": "^5.0.5"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|