@kumiai/rpc 0.10.8 → 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 CHANGED
@@ -151,7 +151,10 @@ move it too, because MLS ratchets forward and a member added at epoch E cannot e
151
151
  epoch's secret. `max(last add, last remove)` is the only epoch that is both after every removal and
152
152
  holdable by every current member, and every member reaches it by applying the same commit, so they
153
153
  agree natively. A rejoin rotates it as well, on the applied commit's own external flag — a rejoining
154
- 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.
155
158
 
156
159
  `GroupPeer.anchorEpoch()` exposes where it sits.
157
160
 
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/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
@@ -402,7 +418,9 @@ export type GroupMLS = {
402
418
  * matter to that diff (see {@link "roster".detectRosterChange}).
403
419
  *
404
420
  * Membership only: a rejoin by a member the roster still holds changes no `did` and is invisible
405
- * 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.
406
424
  */
407
425
  rosterEntries(): Promise<Array<RosterEntry>>;
408
426
  /**
package/lib/index.d.ts CHANGED
@@ -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
@@ -16,5 +16,5 @@ export { createLedgerEntryResolver, decodeLedgerEntries, encodeLedgerEntries, LE
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 roster = (await port.rosterEntries()).map((entry)=>normalizeDID(entry.did));
280
- if (record.forced || detectRosterChange(record.rosterBefore, roster)) {
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
- const rosterBefore = retry && pending != null ? pending.rosterBefore : (await port.rosterEntries()).map((entry)=>normalizeDID(entry.did));
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
  };
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.8",
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,10 +26,10 @@
26
26
  "lib/*"
27
27
  ],
28
28
  "dependencies": {
29
- "@enkaku/client": "^0.21.5",
30
- "@enkaku/protocol": "^0.21.5",
31
- "@enkaku/server": "^0.21.5",
32
- "@enkaku/transport": "^0.21.5",
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
35
  "@kumiai/hub-protocol": "^0.10.2",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@kumiai/hub-conformance": "^0.10.1",
46
- "@kumiai/rpc-conformance": "^0.10.2",
46
+ "@kumiai/rpc-conformance": "^0.10.3",
47
47
  "@noble/curves": "^2.4.0",
48
48
  "vitest": "^5.0.5"
49
49
  },