@kumiai/rpc 0.12.3 → 0.13.0

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/protocol.js CHANGED
@@ -25,7 +25,7 @@
25
25
  /**
26
26
  * The retention a procedure was declared with in its group protocol definition. `'log'` only for
27
27
  * an `event` procedure carrying `retain: 'log'`; `'ephemeral'` for everything else (the default).
28
- */ export function retentionOf(protocol, procedureName) {
28
+ */ export function retentionOf({ protocol, procedureName }) {
29
29
  const procedure = protocol[procedureName];
30
30
  return procedure?.type === 'event' && procedure.retain === 'log' ? 'log' : 'ephemeral';
31
31
  }
@@ -86,13 +86,18 @@ export function waitForRecoveryConfirmation(params) {
86
86
  receive: (sealed)=>{
87
87
  opening = opening.then(async ()=>{
88
88
  if (finished) return;
89
- const opened = await port.openRecoveryVerdict(sealed, requestID);
89
+ const opened = await port.openRecoveryVerdict({
90
+ sealed,
91
+ requestID
92
+ });
90
93
  if (finished || opened == null) return;
91
94
  const verdict = opened.verdict;
92
95
  const boundToAttempt = verdict.groupID === groupID && verdict.requestID === requestID && verdict.position === position && verdict.commitDigest === commitDigest;
93
96
  if (!boundToAttempt) return;
94
97
  if (verdict.verdict === 'confirmed' && (verdict.epoch !== pending.epoch || verdict.tag !== confirmationTag(key, requestID))) return;
95
- if (pending.judgeVerdict(opened) === 'advisory') {
98
+ const standing = await pending.judgeVerdict(opened);
99
+ if (finished) return;
100
+ if (standing === 'advisory') {
96
101
  advisory.set(JSON.stringify(opened), opened);
97
102
  if (advisory.size > 1024) {
98
103
  const oldest = advisory.keys().next().value;
package/lib/recovery.d.ts CHANGED
@@ -1,23 +1,39 @@
1
- export declare function encodeRecoveryRequest(requestID: string, request: Uint8Array): Uint8Array;
1
+ export type EncodeRecoveryRequestParams = {
2
+ requestID: string;
3
+ request: Uint8Array;
4
+ };
5
+ export declare function encodeRecoveryRequest({ requestID, request, }: EncodeRecoveryRequestParams): Uint8Array;
2
6
  export declare function decodeRecoveryRequest(payload: Uint8Array): {
3
7
  requestID: string;
4
8
  request: Uint8Array;
5
9
  };
6
- export declare function encodeRecoveryReply(requestID: string, groupInfo: Uint8Array): Uint8Array;
10
+ export type EncodeRecoveryReplyParams = {
11
+ requestID: string;
12
+ groupInfo: Uint8Array;
13
+ };
14
+ export declare function encodeRecoveryReply({ requestID, groupInfo, }: EncodeRecoveryReplyParams): Uint8Array;
7
15
  export declare function decodeRecoveryReply(payload: Uint8Array): {
8
16
  requestID: string;
9
17
  groupInfo: Uint8Array;
10
18
  };
19
+ export type EncodeLedgerRequestParams = {
20
+ requestID: string;
21
+ request: Uint8Array;
22
+ };
11
23
  /**
12
24
  * A ledger gather carries the port's signed request blob, as a recovery request does: it is
13
25
  * what a responder authorizes against and the only key it will seal to. A request with no blob
14
26
  * is from nobody, and every responder refuses it.
15
27
  */
16
- export declare function encodeLedgerRequest(requestID: string, request: Uint8Array): Uint8Array;
28
+ export declare function encodeLedgerRequest({ requestID, request }: EncodeLedgerRequestParams): Uint8Array;
17
29
  export declare function decodeLedgerRequest(payload: Uint8Array): {
18
30
  requestID: string;
19
31
  request: Uint8Array;
20
32
  };
33
+ export type EncodeLedgerReplyParams = {
34
+ requestID: string;
35
+ sealed: Uint8Array;
36
+ };
21
37
  /**
22
38
  * A responder's whole ordered ledger, SEALED to the ephemeral key inside the request it
23
39
  * answers. The lane carries the bytes and reads none of them.
@@ -25,7 +41,7 @@ export declare function decodeLedgerRequest(payload: Uint8Array): {
25
41
  * Order is inside the seal and load-bearing: the head is a chain digest, so a permuted list of
26
42
  * the same tokens folds to a different head and the requester rejects it.
27
43
  */
28
- export declare function encodeLedgerReply(requestID: string, sealed: Uint8Array): Uint8Array;
44
+ export declare function encodeLedgerReply({ requestID, sealed }: EncodeLedgerReplyParams): Uint8Array;
29
45
  export declare function decodeLedgerReply(payload: Uint8Array): {
30
46
  requestID: string;
31
47
  sealed: Uint8Array;
@@ -38,7 +54,11 @@ export type RecoveryConfirmRequest = {
38
54
  };
39
55
  export declare function encodeRecoveryConfirmRequest(value: RecoveryConfirmRequest): Uint8Array;
40
56
  export declare function decodeRecoveryConfirmRequest(payload: Uint8Array): RecoveryConfirmRequest;
41
- export declare function encodeRecoveryVerdict(requestID: string, sealed: Uint8Array): Uint8Array;
57
+ export type EncodeRecoveryVerdictParams = {
58
+ requestID: string;
59
+ sealed: Uint8Array;
60
+ };
61
+ export declare function encodeRecoveryVerdict({ requestID, sealed, }: EncodeRecoveryVerdictParams): Uint8Array;
42
62
  export type RecoveryVerdictFrame = {
43
63
  requestID: string;
44
64
  sealed: Uint8Array;
package/lib/recovery.js CHANGED
@@ -40,7 +40,7 @@ function decodeWithRequestID(payload, label, maxBytes = MAX_REQUEST_ID_BYTES) {
40
40
  rest: payload.subarray(2 + ridLen)
41
41
  };
42
42
  }
43
- export function encodeRecoveryRequest(requestID, request) {
43
+ export function encodeRecoveryRequest({ requestID, request }) {
44
44
  return encodeWithRequestID({
45
45
  requestID,
46
46
  payload: request,
@@ -54,7 +54,7 @@ export function decodeRecoveryRequest(payload) {
54
54
  request: rest
55
55
  };
56
56
  }
57
- export function encodeRecoveryReply(requestID, groupInfo) {
57
+ export function encodeRecoveryReply({ requestID, groupInfo }) {
58
58
  return encodeWithRequestID({
59
59
  requestID,
60
60
  payload: groupInfo,
@@ -72,7 +72,7 @@ export function decodeRecoveryReply(payload) {
72
72
  * A ledger gather carries the port's signed request blob, as a recovery request does: it is
73
73
  * what a responder authorizes against and the only key it will seal to. A request with no blob
74
74
  * is from nobody, and every responder refuses it.
75
- */ export function encodeLedgerRequest(requestID, request) {
75
+ */ export function encodeLedgerRequest({ requestID, request }) {
76
76
  return encodeWithRequestID({
77
77
  requestID,
78
78
  payload: request,
@@ -92,7 +92,7 @@ export function decodeLedgerRequest(payload) {
92
92
  *
93
93
  * Order is inside the seal and load-bearing: the head is a chain digest, so a permuted list of
94
94
  * the same tokens folds to a different head and the requester rejects it.
95
- */ export function encodeLedgerReply(requestID, sealed) {
95
+ */ export function encodeLedgerReply({ requestID, sealed }) {
96
96
  return encodeWithRequestID({
97
97
  requestID,
98
98
  payload: sealed,
@@ -138,7 +138,7 @@ export function decodeRecoveryConfirmRequest(payload) {
138
138
  request: digest.rest
139
139
  };
140
140
  }
141
- export function encodeRecoveryVerdict(requestID, sealed) {
141
+ export function encodeRecoveryVerdict({ requestID, sealed }) {
142
142
  return encodeWithRequestID({
143
143
  requestID,
144
144
  payload: sealed,
package/lib/roster.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export type DetectRosterChangeParams = {
2
+ before: Array<string>;
3
+ after: Array<string>;
4
+ };
1
5
  /**
2
6
  * Detect a roster CHANGE by diffing the roster around a Commit's application: the DIDs a handle
3
7
  * held before applying against the DIDs it holds after. `true` iff the two sets differ at all —
@@ -21,7 +25,11 @@
21
25
  * a stale-leaf replacement (a Remove and an Add of the same DID in one Commit), which
22
26
  * {@link detectLeafAdmission} sees.
23
27
  */
24
- export declare function detectRosterChange(before: Array<string>, after: Array<string>): boolean;
28
+ export declare function detectRosterChange({ before, after }: DetectRosterChangeParams): boolean;
29
+ export type DetectLeafAdmissionParams = {
30
+ before: Array<string>;
31
+ after: Array<string>;
32
+ };
25
33
  /**
26
34
  * Detect an ADD by diffing the leaf admissions around a Commit's application (see the rpc
27
35
  * `RosterEntry.admission`): `true` iff a value is present after that was absent before.
@@ -33,4 +41,4 @@ export declare function detectRosterChange(before: Array<string>, after: Array<s
33
41
  * replacing the leaf node it was Added with, or a Remove — neither is an Add, and the first must
34
42
  * not rotate.
35
43
  */
36
- export declare function detectLeafAdmission(before: Array<string>, after: Array<string>): boolean;
44
+ export declare function detectLeafAdmission({ before, after }: DetectLeafAdmissionParams): boolean;
package/lib/roster.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * to it — an external-commit rejoin by a member the roster still holds is exactly that, and so is
21
21
  * a stale-leaf replacement (a Remove and an Add of the same DID in one Commit), which
22
22
  * {@link detectLeafAdmission} sees.
23
- */ export function detectRosterChange(before, after) {
23
+ */ export function detectRosterChange({ before, after }) {
24
24
  const held = new Set(before);
25
25
  const present = new Set(after);
26
26
  if (held.size !== present.size) return true;
@@ -39,7 +39,7 @@
39
39
  * anchor the group would otherwise keep. A value that disappears is a member's own path or Update
40
40
  * replacing the leaf node it was Added with, or a Remove — neither is an Add, and the first must
41
41
  * not rotate.
42
- */ export function detectLeafAdmission(before, after) {
42
+ */ export function detectLeafAdmission({ before, after }) {
43
43
  const held = new Set(before);
44
44
  for (const admission of after){
45
45
  if (!held.has(admission)) return true;
package/lib/topic.d.ts CHANGED
@@ -21,19 +21,30 @@ export declare const INBOX_LABEL = "kumiai/inbox/v1";
21
21
  export declare const COMMIT_LABEL = "kumiai/commit/v1";
22
22
  /** Reserved label for the non-rotating recovery-rendezvous topic. */
23
23
  export declare const RENDEZVOUS_LABEL = "kumiai/rendezvous/v1";
24
+ export type ProtocolTopicParams = {
25
+ secret: Uint8Array;
26
+ epoch: number;
27
+ protocol: string;
28
+ scope?: string;
29
+ };
24
30
  /**
25
31
  * Group-scoped broadcast/multicast topic for an application protocol. Opaque to
26
32
  * the hub; derivable only by members holding the epoch secret. `scope`
27
33
  * discriminates a subgroup (e.g. an ephemeral room) sharing the protocol.
28
34
  */
29
- export declare function protocolTopic(secret: Uint8Array, epoch: number, protocol: string, scope?: string): string;
35
+ export declare function protocolTopic({ secret, epoch, protocol, scope, }: ProtocolTopicParams): string;
36
+ export type InboxTopicParams = {
37
+ secret: Uint8Array;
38
+ epoch: number;
39
+ memberDID: string;
40
+ };
30
41
  /**
31
42
  * Group-scoped personal inbox topic for unicast/directed RPC to `memberDID`.
32
43
  * Opaque; derivable only by fellow members. Uses the reserved {@link INBOX_LABEL};
33
44
  * {@link protocolTopic} enforces the separation from application protocols by
34
45
  * rejecting the `kumiai/` namespace.
35
46
  */
36
- export declare function inboxTopic(secret: Uint8Array, epoch: number, memberDID: string): string;
47
+ export declare function inboxTopic({ secret, epoch, memberDID }: InboxTopicParams): string;
37
48
  /**
38
49
  * The non-rotating commit topic: MLS Commits only, retained as a log, read by pull. Derived
39
50
  * from the epoch-independent recovery secret (epoch fixed at `0`), so it is stable for the
package/lib/topic.js CHANGED
@@ -27,19 +27,29 @@ const SEP = '\0';
27
27
  * Group-scoped broadcast/multicast topic for an application protocol. Opaque to
28
28
  * the hub; derivable only by members holding the epoch secret. `scope`
29
29
  * discriminates a subgroup (e.g. an ephemeral room) sharing the protocol.
30
- */ export function protocolTopic(secret, epoch, protocol, scope = '') {
30
+ */ export function protocolTopic({ secret, epoch, protocol, scope = '' }) {
31
31
  if (protocol.startsWith(RESERVED_LABEL_PREFIX)) {
32
32
  throw new Error(`protocolTopic: protocol must not use the reserved "${RESERVED_LABEL_PREFIX}" namespace`);
33
33
  }
34
- return deriveTopicID(secret, epoch, protocol, scope);
34
+ return deriveTopicID({
35
+ secret,
36
+ epoch,
37
+ label: protocol,
38
+ scope
39
+ });
35
40
  }
36
41
  /**
37
42
  * Group-scoped personal inbox topic for unicast/directed RPC to `memberDID`.
38
43
  * Opaque; derivable only by fellow members. Uses the reserved {@link INBOX_LABEL};
39
44
  * {@link protocolTopic} enforces the separation from application protocols by
40
45
  * rejecting the `kumiai/` namespace.
41
- */ export function inboxTopic(secret, epoch, memberDID) {
42
- return deriveTopicID(secret, epoch, INBOX_LABEL, memberDID);
46
+ */ export function inboxTopic({ secret, epoch, memberDID }) {
47
+ return deriveTopicID({
48
+ secret,
49
+ epoch,
50
+ label: INBOX_LABEL,
51
+ scope: memberDID
52
+ });
43
53
  }
44
54
  /**
45
55
  * The non-rotating commit topic: MLS Commits only, retained as a log, read by pull. Derived
@@ -49,7 +59,11 @@ const SEP = '\0';
49
59
  * Separate from {@link rendezvousTopic}: the commit lane is a log whose head every commit
50
60
  * moves, the rendezvous lane is a mailbox whose frames must never move a head.
51
61
  */ export function commitTopic(recoverySecret) {
52
- return deriveTopicID(recoverySecret, 0, COMMIT_LABEL);
62
+ return deriveTopicID({
63
+ secret: recoverySecret,
64
+ epoch: 0,
65
+ label: COMMIT_LABEL
66
+ });
53
67
  }
54
68
  /**
55
69
  * The non-rotating recovery-rendezvous topic: recovery request/reply, published
@@ -57,7 +71,11 @@ const SEP = '\0';
57
71
  * stranded peer always shares it with the live group. Mailbox semantics: a requester
58
72
  * subscribes before it asks, so it cannot miss its own reply. Opaque to the hub.
59
73
  */ export function rendezvousTopic(recoverySecret) {
60
- return deriveTopicID(recoverySecret, 0, RENDEZVOUS_LABEL);
74
+ return deriveTopicID({
75
+ secret: recoverySecret,
76
+ epoch: 0,
77
+ label: RENDEZVOUS_LABEL
78
+ });
61
79
  }
62
80
  /**
63
81
  * Public, secretless pre-group rendezvous topic (invite / keypackage / Welcome).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/rpc",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
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.22.3",
30
- "@enkaku/protocol": "^0.22.3",
31
- "@enkaku/server": "^0.22.3",
32
- "@enkaku/transport": "^0.22.3",
33
- "@kokuin/token": "^0.6.4",
34
- "@kumiai/broadcast": "^0.12.0",
35
- "@kumiai/hub-protocol": "^0.12.0",
36
- "@kumiai/hub-tunnel": "^0.12.1",
29
+ "@enkaku/client": "^0.23.0",
30
+ "@enkaku/protocol": "^0.23.0",
31
+ "@enkaku/server": "^0.23.0",
32
+ "@enkaku/transport": "^0.23.0",
33
+ "@kokuin/token": "^0.7.0",
34
+ "@kumiai/broadcast": "^0.13.0",
35
+ "@kumiai/hub-protocol": "^0.13.0",
36
+ "@kumiai/hub-tunnel": "^0.13.0",
37
37
  "@noble/hashes": "^2.4.0",
38
- "@sozai/codec": "^0.4.3",
38
+ "@sozai/codec": "^0.4.4",
39
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
- "@kumiai/hub-conformance": "^0.12.0",
46
- "@kumiai/rpc-conformance": "^0.12.0",
45
+ "@kumiai/hub-conformance": "^0.13.0",
46
+ "@kumiai/rpc-conformance": "^0.13.0",
47
47
  "@noble/curves": "^2.4.0",
48
- "vitest": "^5.0.5"
48
+ "vitest": "^5.1.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"