@serfab/cadre-core 1.15.0 → 1.17.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.
Files changed (199) hide show
  1. package/README.md +1 -1
  2. package/dist/bootstrap-peer-store-file.js +1 -1
  3. package/dist/bootstrap-peer-store.d.ts +1 -1
  4. package/dist/bootstrap-peer-store.js +4 -4
  5. package/dist/cadre-invite-protocol.d.ts +55 -138
  6. package/dist/cadre-invite-protocol.js +94 -449
  7. package/dist/cadre-invite-protocol.js.map +1 -1
  8. package/dist/cadre-join-request.d.ts +15 -2
  9. package/dist/cadre-join-request.js +22 -3
  10. package/dist/cadre-join-request.js.map +1 -1
  11. package/dist/cadre-node.d.ts +530 -247
  12. package/dist/cadre-node.js +1046 -525
  13. package/dist/cadre-node.js.map +1 -1
  14. package/dist/control-authorization.d.ts +36 -14
  15. package/dist/control-authorization.js +20 -3
  16. package/dist/control-authorization.js.map +1 -1
  17. package/dist/control-cohort.d.ts +22 -23
  18. package/dist/control-cohort.js +24 -24
  19. package/dist/control-cohort.js.map +1 -1
  20. package/dist/control-database.d.ts +416 -136
  21. package/dist/control-database.js +757 -378
  22. package/dist/control-database.js.map +1 -1
  23. package/dist/control-protocol-guard.d.ts +5 -4
  24. package/dist/control-protocol-guard.js +6 -3
  25. package/dist/control-protocol-guard.js.map +1 -1
  26. package/dist/control-schema-version.d.ts +80 -0
  27. package/dist/control-schema-version.js +203 -0
  28. package/dist/control-schema-version.js.map +1 -0
  29. package/dist/control-schema.d.ts +45 -5
  30. package/dist/control-schema.js +254 -70
  31. package/dist/control-schema.js.map +1 -1
  32. package/dist/control-write-retry.d.ts +5 -5
  33. package/dist/control-write-retry.js +10 -8
  34. package/dist/control-write-retry.js.map +1 -1
  35. package/dist/delegate-admission.d.ts +13 -0
  36. package/dist/delegate-admission.js +27 -0
  37. package/dist/delegate-admission.js.map +1 -1
  38. package/dist/ed25519-key.d.ts +10 -7
  39. package/dist/ed25519-key.js +23 -20
  40. package/dist/ed25519-key.js.map +1 -1
  41. package/dist/edge-node/config.d.ts +122 -0
  42. package/dist/edge-node/config.js +199 -0
  43. package/dist/edge-node/config.js.map +1 -0
  44. package/dist/edge-node/dissolve.d.ts +95 -0
  45. package/dist/edge-node/dissolve.js +184 -0
  46. package/dist/edge-node/dissolve.js.map +1 -0
  47. package/dist/edge-node/edge-join.d.ts +44 -0
  48. package/dist/edge-node/edge-join.js +227 -0
  49. package/dist/edge-node/edge-join.js.map +1 -0
  50. package/dist/edge-node/edge-node.d.ts +295 -0
  51. package/dist/edge-node/edge-node.js +704 -0
  52. package/dist/edge-node/edge-node.js.map +1 -0
  53. package/dist/edge-node/index.d.ts +18 -0
  54. package/dist/edge-node/index.js +18 -0
  55. package/dist/edge-node/index.js.map +1 -0
  56. package/dist/edge-node/join-credential.d.ts +11 -0
  57. package/dist/edge-node/join-credential.js +11 -0
  58. package/dist/edge-node/join-credential.js.map +1 -0
  59. package/dist/edge-node/lazy-raw-storage.d.ts +40 -0
  60. package/dist/edge-node/lazy-raw-storage.js +134 -0
  61. package/dist/edge-node/lazy-raw-storage.js.map +1 -0
  62. package/dist/edge-node/node-local.d.ts +60 -0
  63. package/dist/edge-node/node-local.js +58 -0
  64. package/dist/edge-node/node-local.js.map +1 -0
  65. package/dist/edge-node/options.d.ts +83 -0
  66. package/dist/edge-node/options.js +110 -0
  67. package/dist/edge-node/options.js.map +1 -0
  68. package/dist/edge-node/owner-grant.d.ts +41 -0
  69. package/dist/edge-node/owner-grant.js +38 -0
  70. package/dist/edge-node/owner-grant.js.map +1 -0
  71. package/dist/edge-node/platform.d.ts +140 -0
  72. package/dist/edge-node/platform.js +12 -0
  73. package/dist/edge-node/platform.js.map +1 -0
  74. package/dist/edge-node/strand-move.d.ts +115 -0
  75. package/dist/edge-node/strand-move.js +223 -0
  76. package/dist/edge-node/strand-move.js.map +1 -0
  77. package/dist/edge-node/strands.d.ts +28 -0
  78. package/dist/edge-node/strands.js +60 -0
  79. package/dist/edge-node/strands.js.map +1 -0
  80. package/dist/index.d.ts +16 -7
  81. package/dist/index.js +26 -7
  82. package/dist/index.js.map +1 -1
  83. package/dist/joined-strand-store.d.ts +3 -3
  84. package/dist/joined-strand-store.js +3 -3
  85. package/dist/joined-strand-store.js.map +1 -1
  86. package/dist/key-store.d.ts +9 -4
  87. package/dist/key-store.js +9 -4
  88. package/dist/key-store.js.map +1 -1
  89. package/dist/machine-removal.d.ts +19 -39
  90. package/dist/machine-removal.js +24 -98
  91. package/dist/machine-removal.js.map +1 -1
  92. package/dist/member-redemption.d.ts +250 -0
  93. package/dist/member-redemption.js +485 -0
  94. package/dist/member-redemption.js.map +1 -0
  95. package/dist/owner-anchor-sync.d.ts +4 -4
  96. package/dist/owner-anchor-sync.js +16 -15
  97. package/dist/owner-anchor-sync.js.map +1 -1
  98. package/dist/owner-grant-protocol.d.ts +247 -0
  99. package/dist/owner-grant-protocol.js +330 -0
  100. package/dist/owner-grant-protocol.js.map +1 -0
  101. package/dist/owner-key-export.d.ts +70 -0
  102. package/dist/owner-key-export.js +279 -0
  103. package/dist/owner-key-export.js.map +1 -0
  104. package/dist/owner-key-flows.d.ts +55 -0
  105. package/dist/owner-key-flows.js +60 -0
  106. package/dist/owner-key-flows.js.map +1 -0
  107. package/dist/owner-key-store.d.ts +31 -0
  108. package/dist/owner-key-store.js +81 -0
  109. package/dist/owner-key-store.js.map +1 -0
  110. package/dist/owner-keys.d.ts +78 -0
  111. package/dist/owner-keys.js +133 -0
  112. package/dist/owner-keys.js.map +1 -0
  113. package/dist/owner-signer.d.ts +54 -0
  114. package/dist/owner-signer.js +51 -0
  115. package/dist/owner-signer.js.map +1 -0
  116. package/dist/peer-authorization.d.ts +83 -18
  117. package/dist/peer-authorization.js +123 -53
  118. package/dist/peer-authorization.js.map +1 -1
  119. package/dist/provider/rent-node.js +1 -1
  120. package/dist/provider/rent-node.js.map +1 -1
  121. package/dist/seed-bootstrap.d.ts +131 -109
  122. package/dist/seed-bootstrap.js +260 -248
  123. package/dist/seed-bootstrap.js.map +1 -1
  124. package/dist/seed-trust-policy.js +4 -4
  125. package/dist/strand-addr-protocol.d.ts +4 -1
  126. package/dist/strand-addr-protocol.js +8 -2
  127. package/dist/strand-addr-protocol.js.map +1 -1
  128. package/dist/strand-cohort.d.ts +3 -0
  129. package/dist/strand-cohort.js.map +1 -1
  130. package/dist/strand-database.d.ts +1 -0
  131. package/dist/strand-database.js +3 -0
  132. package/dist/strand-database.js.map +1 -1
  133. package/dist/strand-first-sync-gate.d.ts +4 -3
  134. package/dist/strand-first-sync-gate.js +4 -3
  135. package/dist/strand-first-sync-gate.js.map +1 -1
  136. package/dist/strand-instance-manager.d.ts +1 -1
  137. package/dist/strand-membership-writer.d.ts +13 -2
  138. package/dist/strand-membership-writer.js +52 -16
  139. package/dist/strand-membership-writer.js.map +1 -1
  140. package/dist/strand-move.d.ts +6 -5
  141. package/dist/strand-move.js +31 -30
  142. package/dist/strand-move.js.map +1 -1
  143. package/dist/strand-peer-redial.js +2 -3
  144. package/dist/strand-peer-redial.js.map +1 -1
  145. package/dist/types.d.ts +286 -103
  146. package/dist/types.js.map +1 -1
  147. package/package.json +16 -7
  148. package/src/bootstrap-peer-store-file.ts +44 -44
  149. package/src/bootstrap-peer-store.ts +214 -214
  150. package/src/cadre-invite-protocol.ts +131 -531
  151. package/src/cadre-join-request.ts +188 -167
  152. package/src/cadre-node.ts +1166 -541
  153. package/src/control-authorization.ts +47 -14
  154. package/src/control-cohort.ts +127 -128
  155. package/src/control-database.ts +940 -456
  156. package/src/control-protocol-guard.ts +7 -4
  157. package/src/control-schema-version.ts +251 -0
  158. package/src/control-schema.ts +265 -70
  159. package/src/control-write-retry.ts +569 -567
  160. package/src/delegate-admission.ts +37 -0
  161. package/src/ed25519-key.ts +174 -171
  162. package/src/edge-node/config.ts +277 -0
  163. package/src/edge-node/dissolve.ts +251 -0
  164. package/src/edge-node/edge-join.ts +319 -0
  165. package/src/edge-node/edge-node.ts +1045 -0
  166. package/src/edge-node/index.ts +59 -0
  167. package/src/edge-node/join-credential.ts +16 -0
  168. package/src/edge-node/lazy-raw-storage.ts +178 -0
  169. package/src/edge-node/node-local.ts +84 -0
  170. package/src/edge-node/options.ts +179 -0
  171. package/src/edge-node/owner-grant.ts +63 -0
  172. package/src/edge-node/platform.ts +151 -0
  173. package/src/edge-node/strand-move.ts +270 -0
  174. package/src/edge-node/strands.ts +72 -0
  175. package/src/index.ts +102 -5
  176. package/src/joined-strand-store.ts +4 -4
  177. package/src/key-store.ts +10 -4
  178. package/src/machine-removal.ts +26 -111
  179. package/src/member-redemption.ts +642 -0
  180. package/src/owner-anchor-sync.ts +19 -18
  181. package/src/owner-grant-protocol.ts +532 -0
  182. package/src/owner-key-export.ts +348 -0
  183. package/src/owner-key-flows.ts +109 -0
  184. package/src/owner-key-store.ts +85 -0
  185. package/src/owner-keys.ts +178 -0
  186. package/src/owner-signer.ts +94 -0
  187. package/src/peer-authorization.ts +558 -488
  188. package/src/provider/rent-node.ts +1 -1
  189. package/src/seed-bootstrap.ts +301 -312
  190. package/src/seed-trust-policy.ts +4 -4
  191. package/src/strand-addr-protocol.ts +547 -538
  192. package/src/strand-cohort.ts +4 -0
  193. package/src/strand-database.ts +3 -0
  194. package/src/strand-first-sync-gate.ts +4 -3
  195. package/src/strand-instance-manager.ts +1 -1
  196. package/src/strand-membership-writer.ts +61 -16
  197. package/src/strand-move.ts +45 -36
  198. package/src/strand-peer-redial.ts +2 -3
  199. package/src/types.ts +304 -103
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * How the node-local trusted-owner anchor follows the replicated `OwnerKey` table along
3
3
  * VERIFIABLE chains — the pure rule, with no I/O, so it can be tested without a database.
4
- * `CadreNode.syncOwnerAnchor` reads the table, the tombstones and the invitation chain,
4
+ * `CadreNode.syncOwnerAnchor` reads the table, the tombstones and the owner-grant chain,
5
5
  * calls {@link deriveOwnerAnchor}, and applies the difference to the store.
6
6
  *
7
7
  * Why not simply trust the table: an empty local copy can seat any key through the
@@ -19,9 +19,10 @@
19
19
  * retired, although nothing could re-derive it from the remaining base.
20
20
  * - **derivable from S**: a live row whose stored proof verifies against S — owner-signed
21
21
  * (`vouchSig` set): `vouchOwner` is in S and `verifyOwnerKeyVoucher` holds;
22
- * invitation-admitted (`vouchSig` null, `vouchUsage` set): `verifyInvitationOwnerAdmission`
23
- * holds with S as the anchor. The founding row (all three null) is never derivable:
24
- * founders enter anchors only out of band.
22
+ * grant-seated (`vouchSig` null, `vouchUsage` naming an `OwnerGrantUsage` row):
23
+ * `verifyOwnerGrantAdmission` holds with S as the anchor. The founding row (all three null)
24
+ * is never derivable: founders enter anchors only out of band. A machine invitation admits a
25
+ * machine and never seats an owner row, so no `CadreInviteUsage` row is read here.
25
26
  * - **derived**: the least fixpoint from base ∪ kept — add every key whose live row is
26
27
  * derivable from what is already in the set, until nothing changes. **chainDerived** is the
27
28
  * keys whose live row was derivable in this pass, base keys included.
@@ -45,9 +46,9 @@
45
46
  * two cannot be told apart from replicated state; keeping is the only rule under which a
46
47
  * sole owner can rotate at all.
47
48
  */
48
- import { verifyInvitationOwnerAdmission, verifyOwnerKeyVoucher, verifyRevocationSigner } from './peer-authorization.js';
49
+ import { verifyOwnerGrantAdmission, verifyOwnerKeyVoucher, verifyRevocationSigner } from './peer-authorization.js';
49
50
  import type { TrustSource } from './trusted-owner-store.js';
50
- import type { InvitationChain, OwnerKeyRow, RevocationRow } from './types.js';
51
+ import type { OwnerGrantChain, OwnerKeyRow, RevocationRow } from './types.js';
51
52
 
52
53
  export interface OwnerAnchorInputs {
53
54
  /** The party whose table is being read; every stored proof is judged for it, so a voucher or tombstone signed for another party neither seats nor removes a key. */
@@ -58,8 +59,8 @@ export interface OwnerAnchorInputs {
58
59
  rows: readonly OwnerKeyRow[];
59
60
  /** `Revocation` rows; only those with `tableName === 'OwnerKey'` are consulted. */
60
61
  tombstones: readonly RevocationRow[];
61
- /** The usage and invitation rows, when some owner row is invitation-admitted; null skips those rows. */
62
- chain: InvitationChain | null;
62
+ /** The usage and grant rows, when some owner row is grant-seated; null when none is, which skips every consent-seated row. */
63
+ grantChain: OwnerGrantChain | null;
63
64
  }
64
65
 
65
66
  export interface OwnerAnchorDerivation {
@@ -70,7 +71,7 @@ export interface OwnerAnchorDerivation {
70
71
  }
71
72
 
72
73
  /** The rule above, as one pure function. */
73
- export function deriveOwnerAnchor({ partyId, anchor, rows, tombstones, chain }: OwnerAnchorInputs): OwnerAnchorDerivation {
74
+ export function deriveOwnerAnchor({ partyId, anchor, rows, tombstones, grantChain }: OwnerAnchorInputs): OwnerAnchorDerivation {
74
75
  const ownerTombstones = tombstones.filter(tombstone => tombstone.tableName === 'OwnerKey');
75
76
  // NOTE: a stamp is retired by any tombstone that names it, verified or not — the same
76
77
  // reading `queryCadrePeers` and `getOwnerKeys` give the table. A forged tombstone can
@@ -80,7 +81,7 @@ export function deriveOwnerAnchor({ partyId, anchor, rows, tombstones, chain }:
80
81
  const liveRows = rows.filter(row => !retired.has(row.stampId));
81
82
 
82
83
  const derived = passStartSet(anchor, liveRows);
83
- const chainDerived = deriveFixpoint(partyId, derived, liveRows, chain);
84
+ const chainDerived = deriveFixpoint(partyId, derived, liveRows, grantChain);
84
85
 
85
86
  const removed = removedKeys(partyId, derived, chainDerived, ownerTombstones);
86
87
  if (removed.size > 0 && removed.size === derived.size) {
@@ -108,7 +109,7 @@ function passStartSet(anchor: ReadonlyMap<string, TrustSource>, liveRows: readon
108
109
  * trust only grows within a pass, and a proof that failed against a trusted voucher cannot
109
110
  * pass later, so no row is verified twice.
110
111
  */
111
- function deriveFixpoint(partyId: string, derived: Set<string>, liveRows: readonly OwnerKeyRow[], chain: InvitationChain | null): Set<string> {
112
+ function deriveFixpoint(partyId: string, derived: Set<string>, liveRows: readonly OwnerKeyRow[], grantChain: OwnerGrantChain | null): Set<string> {
112
113
  const chainDerived = new Set<string>();
113
114
  const pending = new Set(liveRows);
114
115
  let progress = true;
@@ -119,7 +120,7 @@ function deriveFixpoint(partyId: string, derived: Set<string>, liveRows: readonl
119
120
  continue;
120
121
  }
121
122
  pending.delete(row);
122
- if (proofVerifies(partyId, row, derived, chain)) {
123
+ if (proofVerifies(partyId, row, derived, grantChain)) {
123
124
  chainDerived.add(row.key);
124
125
  derived.add(row.key);
125
126
  progress = true;
@@ -130,22 +131,22 @@ function deriveFixpoint(partyId: string, derived: Set<string>, liveRows: readonl
130
131
  }
131
132
 
132
133
  /** Does `row`'s stored proof verify against `trusted`, for `partyId`, by the kind of proof it carries (see the module doc)? */
133
- function proofVerifies(partyId: string, row: OwnerKeyRow, trusted: ReadonlySet<string>, chain: InvitationChain | null): boolean {
134
+ function proofVerifies(partyId: string, row: OwnerKeyRow, trusted: ReadonlySet<string>, grantChain: OwnerGrantChain | null): boolean {
134
135
  if (row.vouchOwner === null) {
135
136
  return false;
136
137
  }
137
138
  if (row.vouchSig !== null) {
138
- return verifyOwnerKeyVoucher(partyId, row.key, row.stampId, row.vouchOwner, row.vouchSig);
139
+ return verifyOwnerKeyVoucher(partyId, row.key, row.label, row.stampId, row.vouchOwner, row.vouchSig);
139
140
  }
140
141
  if (row.vouchUsage === null) {
141
142
  return false;
142
143
  }
143
- const usage = chain?.usages.get(row.vouchUsage);
144
- const invite = usage === undefined ? undefined : chain?.invites.get(usage.inviteKey);
145
- if (usage === undefined || invite === undefined) {
144
+ const grantUsage = grantChain?.usages.get(row.vouchUsage);
145
+ const grant = grantUsage === undefined ? undefined : grantChain?.grants.get(grantUsage.grantKey);
146
+ if (grantUsage === undefined || grant === undefined) {
146
147
  return false;
147
148
  }
148
- return verifyInvitationOwnerAdmission(partyId, row, usage, invite, key => trusted.has(key));
149
+ return verifyOwnerGrantAdmission(partyId, row, grantUsage, grant, (key) => trusted.has(key));
149
150
  }
150
151
 
151
152
  /**
@@ -0,0 +1,532 @@
1
+ /**
2
+ * Owner grant redemption transport: `/sereus/owner-grant/1.0.0`.
3
+ *
4
+ * A holder of an owner grant (an owner-signed `OwnerGrant` row plus the private half of the
5
+ * grant keypair, see {@link OwnerGrantBundle}) dials ANY member machine the grant names and
6
+ * proves possession of the grant and of the key it wants seated; the member seats the row if
7
+ * it does not hold it yet and writes the holder's `OwnerKey` row through
8
+ * `ControlDatabase.redeemOwnerGrant`. No machine is admitted and no peer id is named: the
9
+ * holder's network identity has nothing to do with the key it seats, so unlike the invitation
10
+ * protocol there is no connecting-identity check — both signatures already bind the grant, the
11
+ * nonce and the key. The owner that minted the grant need not be online.
12
+ *
13
+ * The exchange shape — one frame each way, the member's hardening and admission of the
14
+ * holder, the holder's address-by-address dialing in passes — is `member-redemption.ts`'s,
15
+ * shared with the invitation protocol; this module supplies the grant's bundle, request,
16
+ * checks, writes and refusal codes. Stranger-facing by design, classed `stranger-open` in
17
+ * `control-protocol-guard.ts`; the handler's own trust decision is the two signatures.
18
+ */
19
+
20
+ import debug from 'debug';
21
+ import type { Libp2p } from '@libp2p/interface';
22
+ import { toString as uint8ArrayToString, fromString as uint8ArrayFromString } from 'uint8arrays';
23
+ import { sign } from '@optimystic/quereus-plugin-crypto';
24
+ import {
25
+ ownerGrantRedeemMessage,
26
+ ownerGrantConsentMessage,
27
+ OwnerGrantIssuerUnknownError,
28
+ InvitationExhaustedError,
29
+ type ControlDatabase
30
+ } from './control-database.js';
31
+ import { verifyOwnerGrantRow, verifyOwnerGrantRedemption } from './peer-authorization.js';
32
+ import { OWNER_KEY_MAX_LABEL } from './owner-key-export.js';
33
+ import { CADRE_INVITATION_PREFIX, CADRE_JOIN_REQUEST_PREFIX, OWNER_GRANT_PREFIX, OWNER_KEY_EXPORT_STEM } from './cadre-join-request.js';
34
+ import {
35
+ MemberRedemptionHandler,
36
+ constraintRefusal,
37
+ dialRedemption,
38
+ dialRedemptionInPasses,
39
+ isBoundedString,
40
+ isEd25519KeyB64,
41
+ isNullableBoundedString,
42
+ isNullableUseCap,
43
+ rejection,
44
+ writeFailureRefusal,
45
+ type ConstraintRefusalRow,
46
+ type MemberRedemption,
47
+ type MemberRedemptionHandlerOptions,
48
+ type MemberRedemptionOptions,
49
+ type MemberRedemptionPassOptions,
50
+ type RedemptionAddressOutcome,
51
+ type RedemptionRejection
52
+ } from './member-redemption.js';
53
+ import type { OwnerSign } from './owner-signer.js';
54
+ import type { CadreJoinProgress, OwnerGrantRow } from './types.js';
55
+
56
+ const log = debug('sereus:cadre:owner-grant-proto');
57
+
58
+ /** Protocol id for owner grant redemption (parallel to `/sereus/cadre-invite/1.0.0`). */
59
+ export const OWNER_GRANT_PROTOCOL = '/sereus/owner-grant/1.0.0';
60
+
61
+ /** What the dialer calls the credential in log lines, deadline labels and error text. */
62
+ const LABEL = 'Owner grant';
63
+
64
+ /** Most machines a grant bundle may name; the issuer caps its own list far below this. */
65
+ const MAX_BUNDLE_MEMBERS = 64;
66
+
67
+ // ── The grant bundle ─────────────────────────────────────────────────────────
68
+
69
+ /**
70
+ * What an owner hands out (QR, paste, file) and a holder redeems. A grant is an ed25519
71
+ * keypair: the row holds the public half, `grantPrivateKey` is the proof of possession, and
72
+ * whoever holds this bundle can become an owner of the party — a bearer credential for admin
73
+ * rights for the row's lifetime (15 minutes by default; a backup grant has no expiry and is
74
+ * kept as carefully as an owner key).
75
+ *
76
+ * Carrying the signed row is what makes redemption work at a member that has not received
77
+ * the row by replication: the member seats it from the bundle under its stored issuer
78
+ * signature. The row's own signature covers every column, so a bundle whose row was altered
79
+ * cannot be seated anywhere. `members` are the party's addresses at mint time, so a backup
80
+ * grant can go stale if every member's address changes.
81
+ */
82
+ export interface OwnerGrantBundle {
83
+ v: 1;
84
+ /** The cadre the grant makes an owner of; a holder refuses one for another party. */
85
+ partyId: string;
86
+ /** The grant's ed25519 seed, base64url: the proof of possession. */
87
+ grantPrivateKey: string;
88
+ /** The owner-signed row exactly as issued (`ControlDatabase.insertOwnerGrant`). */
89
+ grant: OwnerGrantRow;
90
+ /**
91
+ * The issuer's anchored owner keys. The holder pins them before it dials
92
+ * (`CadreNode.trustOwnerKeys`) and checks the member's reply against them. Sourced from the
93
+ * issuer's node-local anchor only, never the replicated `OwnerKey` table, for the reason the
94
+ * invitation gives: the holder anchors whatever arrives here.
95
+ */
96
+ ownerKeys: string[];
97
+ /** As `CadreInvitation.members`: multiaddrs ending in `/p2p/<peerId>`, the issuer's first, at most six in all. */
98
+ members: string[];
99
+ }
100
+
101
+ /**
102
+ * Encode a bundle for out-of-band delivery: {@link OWNER_GRANT_PREFIX}, then base64url over
103
+ * JSON. The prefix lets an app tell a grant from an invitation, a join request or an owner key
104
+ * and name the mistake when one is pasted for the other.
105
+ */
106
+ export function encodeOwnerGrant(bundle: OwnerGrantBundle): string {
107
+ return `${OWNER_GRANT_PREFIX}${uint8ArrayToString(new TextEncoder().encode(JSON.stringify(bundle)), 'base64url')}`;
108
+ }
109
+
110
+ /**
111
+ * Decode a bundle, refusing anything that is not a well-formed version-1
112
+ * {@link OwnerGrantBundle} behind {@link OWNER_GRANT_PREFIX}. Standalone, like
113
+ * `decodeCadreInvitation`, so a client without a node can decode one.
114
+ *
115
+ * @throws on an owner key, a cadre invitation or a join request, a string without the prefix
116
+ * or that is not base64url JSON after it, or one that decodes to another shape or version.
117
+ */
118
+ export function decodeOwnerGrant(encoded: string): OwnerGrantBundle {
119
+ const trimmed = encoded.trim();
120
+ if (trimmed.startsWith(OWNER_KEY_EXPORT_STEM)) {
121
+ throw new Error('This is an owner key, not an owner grant; it is private, so import it only where the app asks for an owner key');
122
+ }
123
+ if (trimmed.startsWith(CADRE_INVITATION_PREFIX)) {
124
+ throw new Error('This is a cadre invitation, not an owner grant; paste it where the app asks for an invitation');
125
+ }
126
+ if (trimmed.startsWith(CADRE_JOIN_REQUEST_PREFIX)) {
127
+ throw new Error('This is a join request, not an owner grant; paste it into the app that manages your cadre');
128
+ }
129
+ if (!trimmed.startsWith(OWNER_GRANT_PREFIX)) {
130
+ throw new Error(`Owner grant must start with "${OWNER_GRANT_PREFIX}" (this one starts with "${trimmed.slice(0, OWNER_GRANT_PREFIX.length)}")`);
131
+ }
132
+ let parsed: unknown;
133
+ try {
134
+ parsed = JSON.parse(new TextDecoder().decode(uint8ArrayFromString(trimmed.slice(OWNER_GRANT_PREFIX.length), 'base64url')));
135
+ } catch (error) {
136
+ throw new Error('Owner grant does not decode as base64url JSON', { cause: error });
137
+ }
138
+ if (!isWellFormedOwnerGrantBundle(parsed)) {
139
+ throw new Error('Owner grant is malformed or of an unsupported version');
140
+ }
141
+ return parsed;
142
+ }
143
+
144
+ function isWellFormedOwnerGrantBundle(value: unknown): value is OwnerGrantBundle {
145
+ if (typeof value !== 'object' || value === null) return false;
146
+ const { v, partyId, grantPrivateKey, grant, ownerKeys, members } = value as Record<string, unknown>;
147
+ return v === 1
148
+ && isBoundedString(partyId)
149
+ && isEd25519KeyB64(grantPrivateKey)
150
+ && isWellFormedOwnerGrantRow(grant)
151
+ && Array.isArray(ownerKeys) && ownerKeys.length > 0 && ownerKeys.every((key) => isEd25519KeyB64(key))
152
+ && Array.isArray(members) && members.length <= MAX_BUNDLE_MEMBERS && members.every((addr) => isBoundedString(addr));
153
+ }
154
+
155
+ /** Is `value` an {@link OwnerGrantRow} with every column in its stored form and bounded? */
156
+ export function isWellFormedOwnerGrantRow(value: unknown): value is OwnerGrantRow {
157
+ if (typeof value !== 'object' || value === null) return false;
158
+ const row = value as Record<string, unknown>;
159
+ return isEd25519KeyB64(row.key)
160
+ && isNullableBoundedString(row.label, OWNER_KEY_MAX_LABEL)
161
+ && isNullableBoundedString(row.expiresAt)
162
+ && isNullableUseCap(row.totalUses)
163
+ && isBoundedString(row.stampId)
164
+ && isEd25519KeyB64(row.issuerKey)
165
+ && isBoundedString(row.issuerSig);
166
+ }
167
+
168
+ // ── Wire messages ────────────────────────────────────────────────────────────
169
+
170
+ /** Holder → member: one frame, the whole redemption. */
171
+ export interface OwnerGrantRedeemRequest {
172
+ v: 1;
173
+ /** The cadre the holder believes it is becoming an owner of; a machine serving another party refuses by name. */
174
+ partyId: string;
175
+ /** The owner-signed row from the bundle. */
176
+ grant: OwnerGrantRow;
177
+ /** The ed25519 public key to seat as an owner, base64url: the holder's, fresh or already held. */
178
+ ownerKey: string;
179
+ /** Single-use nonce the holder minted (`generateStampId`); both signatures cover it. */
180
+ usageStampId: string;
181
+ /** By `grantPrivateKey` over the `'redeem'` digest. */
182
+ grantSig: string;
183
+ /** By `ownerKey` over the `'consent'` digest. */
184
+ ownerSig: string;
185
+ }
186
+
187
+ /**
188
+ * Why a member refused a redemption: the invitation's codes with grant wording. Retryability
189
+ * is {@link OWNER_GRANT_REJECTION_RETRYABLE}'s; a retryable code moves the holder to the next
190
+ * address the bundle names.
191
+ */
192
+ export type OwnerGrantRejectionCode =
193
+ /** The issuer's `OwnerKey` row is not on this member (not replicated yet), or the issuer was removed; the member cannot tell which. */
194
+ | 'issuer-unknown'
195
+ /** A signature does not verify, or the request or the row is malformed. */
196
+ | 'grant-invalid'
197
+ /** Expired, withdrawn, exhausted, or issued by a key that is no longer an owner here. */
198
+ | 'grant-spent'
199
+ /** This machine serves another cadre than the one the grant names. */
200
+ | 'party-mismatch'
201
+ /** The member is at its cap on concurrent redemptions. */
202
+ | 'busy'
203
+ /** The write failed transiently (the write retry gave up), or the member has not synced the grant row the cadre holds; nothing was recorded. */
204
+ | 'conflict'
205
+ /** An unexpected member-side failure, or a request frame the member could not read: nothing was proved either way. */
206
+ | 'internal';
207
+
208
+ /** Which refusals are worth repeating at the next address — the one place that says so. */
209
+ export const OWNER_GRANT_REJECTION_RETRYABLE: Readonly<Record<OwnerGrantRejectionCode, boolean>> = {
210
+ 'issuer-unknown': true,
211
+ 'grant-invalid': false,
212
+ 'grant-spent': false,
213
+ 'party-mismatch': false,
214
+ 'busy': true,
215
+ 'conflict': true,
216
+ 'internal': true
217
+ };
218
+
219
+ /** Is `value` a code this build knows? Own keys only, so a peer's `'constructor'` does not pass. */
220
+ export function isOwnerGrantRejectionCode(value: unknown): value is OwnerGrantRejectionCode {
221
+ return typeof value === 'string' && Object.prototype.hasOwnProperty.call(OWNER_GRANT_REJECTION_RETRYABLE, value);
222
+ }
223
+
224
+ /** Member → holder. No dial hints: the holder is not joining the cadre's network, only seating a key. */
225
+ export interface OwnerGrantRedeemReply {
226
+ accepted: boolean;
227
+ /** Present iff `!accepted`. */
228
+ code?: OwnerGrantRejectionCode;
229
+ /** Human-facing text; present iff `!accepted`. */
230
+ reason?: string;
231
+ /** The member's party id; present iff `accepted`. */
232
+ partyId?: string;
233
+ /** The grant row as this member holds it; present iff `accepted`. */
234
+ grant?: OwnerGrantRow;
235
+ /** The key was already a live owner here, so nothing was written and no use was spent; present iff `accepted`. */
236
+ alreadyOwner?: boolean;
237
+ }
238
+
239
+ /** An accepting reply, every optional field present. */
240
+ export interface OwnerGrantAccepted extends OwnerGrantRedeemReply {
241
+ accepted: true;
242
+ partyId: string;
243
+ grant: OwnerGrantRow;
244
+ alreadyOwner: boolean;
245
+ }
246
+
247
+ type OwnerGrantRejection = RedemptionRejection<OwnerGrantRejectionCode>;
248
+
249
+ // ── Errors the holder sees ───────────────────────────────────────────────────
250
+
251
+ /**
252
+ * A member answered and refused (on `CadreNode.redeemOwnerGrant`'s local path, the member is
253
+ * this node). `code` is `'unrecognized'` when the frame carried none this build knows, and such
254
+ * a refusal counts as retryable, as the invitation's does.
255
+ */
256
+ export class OwnerGrantRejectedError extends Error {
257
+ readonly code: OwnerGrantRejectionCode | 'unrecognized';
258
+ readonly reason: string;
259
+ readonly retryable: boolean;
260
+
261
+ /** Both arguments come straight off the wire, so neither is trusted to have its declared type. */
262
+ constructor(code: unknown, reason: unknown) {
263
+ const text = typeof reason === 'string' ? reason : 'no reason provided';
264
+ super(`Owner grant refused: ${text}`);
265
+ this.name = 'OwnerGrantRejectedError';
266
+ this.code = isOwnerGrantRejectionCode(code) ? code : 'unrecognized';
267
+ this.reason = text;
268
+ this.retryable = this.code === 'unrecognized' || OWNER_GRANT_REJECTION_RETRYABLE[this.code];
269
+ }
270
+ }
271
+
272
+ /** Every address the bundle names was tried and none accepted. Always retryable; `outcomes` says what each address did. */
273
+ export class OwnerGrantUnreachableError extends Error {
274
+ readonly retryable = true;
275
+
276
+ constructor(readonly outcomes: readonly RedemptionAddressOutcome[]) {
277
+ super(outcomes.length === 0
278
+ ? 'Owner grant names no dialable member'
279
+ : `Owner grant could not be redeemed at any of its ${outcomes.length} address(es): `
280
+ + outcomes.map((outcome) => `${outcome.addr}: ${outcome.error.message}`).join('; '));
281
+ this.name = 'OwnerGrantUnreachableError';
282
+ }
283
+ }
284
+
285
+ /**
286
+ * A member accepted but its reply does not check out: another party id, another grant key, or
287
+ * a row not signed by one of the pinned owner keys. Final, for the invitation's reason: such a
288
+ * machine is not a member of the cadre the grant names.
289
+ */
290
+ export class OwnerGrantReplyInvalidError extends Error {
291
+ readonly retryable = false;
292
+
293
+ constructor(message: string) {
294
+ super(`Owner grant reply refused: ${message}`);
295
+ this.name = 'OwnerGrantReplyInvalidError';
296
+ }
297
+ }
298
+
299
+ // ── Shape checks ─────────────────────────────────────────────────────────────
300
+
301
+ function isWellFormedRedeemRequest(value: unknown): value is OwnerGrantRedeemRequest {
302
+ if (typeof value !== 'object' || value === null) return false;
303
+ const { v, partyId, grant, ownerKey, usageStampId, grantSig, ownerSig } = value as Record<string, unknown>;
304
+ return v === 1
305
+ && isBoundedString(partyId)
306
+ && isWellFormedOwnerGrantRow(grant)
307
+ && isEd25519KeyB64(ownerKey)
308
+ && isBoundedString(usageStampId)
309
+ && isBoundedString(grantSig)
310
+ && isBoundedString(ownerSig);
311
+ }
312
+
313
+ /** An acceptance frame's fields. Throws on a malformed one. */
314
+ function decodeAccepted(reply: Record<string, unknown>): OwnerGrantAccepted {
315
+ if (!isBoundedString(reply.partyId) || !isWellFormedOwnerGrantRow(reply.grant)) {
316
+ throw new Error('Owner grant acceptance is missing its party id or a well-formed row');
317
+ }
318
+ return { accepted: true, partyId: reply.partyId, grant: reply.grant, alreadyOwner: reply.alreadyOwner === true };
319
+ }
320
+
321
+ // ── Request construction (holder side) ───────────────────────────────────────
322
+
323
+ /**
324
+ * Build and sign the request for `bundle`: the holder's `'redeem'` signature with the grant's
325
+ * private key (held in memory for the length of this call) and the seated key's `'consent'`
326
+ * signature through `signConsent`, the `sign` of an open owner approval on the signer that
327
+ * holds `ownerKey`; both over (grant key, `usageStampId`, `ownerKey`) for the grant's party. The
328
+ * same bytes the schema verifies at the member (`ownerGrantRedeemMessage` /
329
+ * `ownerGrantConsentMessage`), and the same request goes to every member and every pass.
330
+ */
331
+ export async function signOwnerGrantRequest(
332
+ bundle: OwnerGrantBundle,
333
+ ownerKey: string,
334
+ signConsent: OwnerSign,
335
+ usageStampId: string
336
+ ): Promise<OwnerGrantRedeemRequest> {
337
+ const fields = { grantKey: bundle.grant.key, usageStampId, seatedKey: ownerKey };
338
+ const grantSig = sign(ownerGrantRedeemMessage(bundle.partyId, fields), bundle.grantPrivateKey, 'ed25519', 'bytes', 'base64url', 'base64url') as string;
339
+ const ownerSig = await signConsent(ownerGrantConsentMessage(bundle.partyId, fields));
340
+ return { v: 1, partyId: bundle.partyId, grant: bundle.grant, ownerKey, usageStampId, grantSig, ownerSig };
341
+ }
342
+
343
+ /**
344
+ * The holder's check on an acceptance: the same party, the same grant key, and a row signed by
345
+ * an issuer the holder pinned from the bundle. Throws {@link OwnerGrantReplyInvalidError} naming
346
+ * the first failure. Bounded as `verifyRedeemReply` is: it catches a wrong-party or wrong-row
347
+ * answer, not a forged member, which the holder's anchor settles once its store syncs.
348
+ */
349
+ export function verifyOwnerGrantReply(
350
+ reply: OwnerGrantAccepted,
351
+ bundle: OwnerGrantBundle,
352
+ isTrustedIssuer: (ownerKey: string) => boolean
353
+ ): void {
354
+ if (reply.partyId !== bundle.partyId) {
355
+ throw new OwnerGrantReplyInvalidError(`the member serves party ${reply.partyId}, the grant names ${bundle.partyId}`);
356
+ }
357
+ if (reply.grant.key !== bundle.grant.key) {
358
+ throw new OwnerGrantReplyInvalidError('the member answered for a different grant');
359
+ }
360
+ if (!isTrustedIssuer(reply.grant.issuerKey)) {
361
+ throw new OwnerGrantReplyInvalidError('the row the member holds is not issued by one of the grant\'s owner keys');
362
+ }
363
+ if (!verifyOwnerGrantRow(bundle.partyId, reply.grant)) {
364
+ throw new OwnerGrantReplyInvalidError('the row the member holds is not signed by its issuer');
365
+ }
366
+ }
367
+
368
+ // ── Member side (handler) ────────────────────────────────────────────────────
369
+
370
+ /** The control-database surface a redemption needs; a `ControlDatabase` satisfies it. */
371
+ export type OwnerGrantStore = Pick<ControlDatabase, 'seatOwnerGrant' | 'isOwnerGrantLive' | 'redeemOwnerGrant'>;
372
+
373
+ export interface OwnerGrantHandlerOptions extends MemberRedemptionHandlerOptions {
374
+ store: OwnerGrantStore;
375
+ }
376
+
377
+ /** Constraint names the schema refuses a redemption with, and the code each maps to. */
378
+ const REDEEM_CONSTRAINT_CODES: ReadonlyArray<ConstraintRefusalRow<OwnerGrantRejectionCode>> = [
379
+ [/CHECK constraint failed: Authorized\b/, 'grant-spent', 'The grant is expired, withdrawn, exhausted, or its issuer is no longer an owner'],
380
+ [/CHECK constraint failed: (GrantPossessed|OwnerConsented|SeatedExists)\b/, 'grant-invalid', 'The redemption does not satisfy the grant'],
381
+ [/CHECK constraint failed: NotRevoked\b/, 'grant-spent', 'The grant was withdrawn'],
382
+ ];
383
+
384
+ /**
385
+ * Member side of the grant protocol (`MemberRedemptionHandler` has the shape): after the
386
+ * request's shape, it checks the party and both signatures — nothing about the connecting
387
+ * peer, whose identity is unrelated to the key it seats — then seats the row from the bundle
388
+ * and redeems. An issuer this member does not know as an owner is the one retryable refusal
389
+ * left: the holder tries the next address, which may hold the issuer's row.
390
+ */
391
+ export class OwnerGrantHandler extends MemberRedemptionHandler<OwnerGrantRedeemRequest, OwnerGrantRedeemReply> {
392
+ private readonly store: OwnerGrantStore;
393
+ protected readonly busyRefusal = rejection('busy', 'Too many concurrent redemptions');
394
+ protected readonly internalRefusal = rejection('internal', 'Internal redemption error');
395
+ protected readonly malformedRefusal = rejection('grant-invalid', 'Malformed redemption request');
396
+
397
+ constructor(options: OwnerGrantHandlerOptions) {
398
+ super('Owner grant', OWNER_GRANT_PROTOCOL, options);
399
+ this.store = options.store;
400
+ }
401
+
402
+ protected isWellFormedRequest(value: unknown): value is OwnerGrantRedeemRequest {
403
+ return isWellFormedRedeemRequest(value);
404
+ }
405
+
406
+ protected checkRequest(request: OwnerGrantRedeemRequest): OwnerGrantRejection | null {
407
+ if (request.partyId !== this.partyId) {
408
+ return rejection('party-mismatch', 'This machine serves another cadre');
409
+ }
410
+ const fields = { grantKey: request.grant.key, usageStampId: request.usageStampId, seatedKey: request.ownerKey };
411
+ if (!verifyOwnerGrantRedemption(this.partyId, fields, request.grantSig, request.ownerSig)) {
412
+ return rejection('grant-invalid', 'The redemption signatures do not verify');
413
+ }
414
+ return null;
415
+ }
416
+
417
+ protected isLive(request: OwnerGrantRedeemRequest): Promise<boolean> {
418
+ return this.store.isOwnerGrantLive(request.grant);
419
+ }
420
+
421
+ /** The two writes — the seat (its own transaction; a no-op when held) and the redemption — each answered by name when it fails. */
422
+ protected async redeemAdmitted(request: OwnerGrantRedeemRequest, remotePeerId: string): Promise<OwnerGrantRedeemReply> {
423
+ try {
424
+ await this.store.seatOwnerGrant(request.grant);
425
+ } catch (error) {
426
+ if (error instanceof OwnerGrantIssuerUnknownError) {
427
+ return rejection('issuer-unknown', 'The grant\'s issuer is not known as an owner here');
428
+ }
429
+ log('seating grant %s from %s failed: %o', request.grant.key, remotePeerId, error);
430
+ return constraintRefusal(error, REDEEM_CONSTRAINT_CODES) ?? writeFailureRefusal(error);
431
+ }
432
+ let alreadyOwner: boolean;
433
+ try {
434
+ const result = await this.store.redeemOwnerGrant({
435
+ grantKey: request.grant.key,
436
+ seatedKey: request.ownerKey,
437
+ usageStampId: request.usageStampId,
438
+ grantSig: request.grantSig,
439
+ ownerSig: request.ownerSig
440
+ });
441
+ alreadyOwner = result.alreadyOwner;
442
+ log('grant %s redeemed for %s by %s (alreadyOwner=%s)', request.grant.key, request.ownerKey, remotePeerId, alreadyOwner);
443
+ } catch (error) {
444
+ if (error instanceof InvitationExhaustedError) {
445
+ return rejection('grant-spent', 'The grant has no uses left');
446
+ }
447
+ log('redeeming grant %s for %s failed: %o', request.grant.key, request.ownerKey, error);
448
+ return constraintRefusal(error, REDEEM_CONSTRAINT_CODES) ?? writeFailureRefusal(error);
449
+ }
450
+ // The row as held: the seat inserted this copy verbatim, or found the same row.
451
+ return { accepted: true, partyId: this.partyId, grant: request.grant, alreadyOwner };
452
+ }
453
+ }
454
+
455
+ // ── Holder side (dialer) ─────────────────────────────────────────────────────
456
+
457
+ export interface RedeemOwnerGrantAtMembersOptions {
458
+ /** The bundle: its `members` are dialed in order. */
459
+ bundle: OwnerGrantBundle;
460
+ /** The signed request ({@link signOwnerGrantRequest}); the same one goes to every address. */
461
+ request: OwnerGrantRedeemRequest;
462
+ /** Is this owner key one the holder pinned from the bundle? The reply check's input. */
463
+ isTrustedIssuer: (ownerKey: string) => boolean;
464
+ /** See `MemberRedemptionOptions.linkRoundTripMs`. */
465
+ linkRoundTripMs?: number;
466
+ /** Per-address deadline override; default derived from `linkRoundTripMs`. */
467
+ addressBudgetMs?: number;
468
+ protocolId?: string;
469
+ /** Cancels the dial or stream in flight and ends the pass; the call throws the signal's reason. */
470
+ signal?: AbortSignal;
471
+ }
472
+
473
+ /** What a successful redemption yields the holder. */
474
+ export type OwnerGrantRedemption = MemberRedemption<OwnerGrantAccepted>;
475
+
476
+ /** The grant's half of the shared dial loop: its label, protocol, bundle, codec, checks and errors. */
477
+ function grantRedemption(options: RedeemOwnerGrantAtMembersOptions): MemberRedemptionOptions<OwnerGrantAccepted> {
478
+ return {
479
+ label: LABEL,
480
+ protocolId: options.protocolId ?? OWNER_GRANT_PROTOCOL,
481
+ members: options.bundle.members,
482
+ request: options.request,
483
+ decodeAccepted,
484
+ refusal: (code, reason) => new OwnerGrantRejectedError(code, reason),
485
+ verifyAccepted: (reply) => verifyOwnerGrantReply(reply, options.bundle, options.isTrustedIssuer),
486
+ unreachable: (outcomes) => new OwnerGrantUnreachableError(outcomes),
487
+ ...(options.linkRoundTripMs !== undefined ? { linkRoundTripMs: options.linkRoundTripMs } : {}),
488
+ ...(options.addressBudgetMs !== undefined ? { addressBudgetMs: options.addressBudgetMs } : {}),
489
+ ...(options.signal ? { signal: options.signal } : {}),
490
+ };
491
+ }
492
+
493
+ /**
494
+ * Holder side: try the bundle's addresses one at a time and stop at the first acceptance or
495
+ * the first final refusal (`dialRedemption` in `member-redemption.ts`). Every address gets the
496
+ * SAME request, with one `usageStampId`: `OwnerGrantUsage` is keyed by it, so a member the
497
+ * holder gave up on that was still committing cannot spend a second use, and a retry after a
498
+ * dropped reply is answered `alreadyOwner`.
499
+ *
500
+ * @throws {OwnerGrantRejectedError} on a final refusal (its `retryable` is false).
501
+ * @throws {OwnerGrantReplyInvalidError} on an acceptance that fails {@link verifyOwnerGrantReply}.
502
+ * @throws {OwnerGrantUnreachableError} when every address was tried and none accepted.
503
+ * @throws the reason of `options.signal` once it aborts.
504
+ */
505
+ export function redeemOwnerGrantAtMembers(node: Libp2p, options: RedeemOwnerGrantAtMembersOptions): Promise<OwnerGrantRedemption> {
506
+ return dialRedemption(node, grantRedemption(options));
507
+ }
508
+
509
+ export interface RedeemOwnerGrantInPassesOptions extends RedeemOwnerGrantAtMembersOptions {
510
+ /** Keep making passes while every answer is retryable; false makes exactly one. */
511
+ waitForMember: boolean;
512
+ /** Called at each pass and each pause; an exception it throws is logged and ignored. */
513
+ onProgress?: (progress: CadreJoinProgress) => void;
514
+ }
515
+
516
+ /**
517
+ * Holder side, in passes (`dialRedemptionInPasses` in `member-redemption.ts`): one
518
+ * {@link redeemOwnerGrantAtMembers} pass, or, with `waitForMember`, as many as it takes,
519
+ * pausing between them and never past the grant's expiry, which by this holder's clock is
520
+ * thrown as the `grant-spent` refusal a member would give. A backup grant has no expiry, so a
521
+ * wait on one ends only by acceptance, a final refusal, the signal or the node stopping.
522
+ */
523
+ export function redeemOwnerGrantInPasses(node: Libp2p, options: RedeemOwnerGrantInPassesOptions): Promise<OwnerGrantRedemption> {
524
+ const passes: MemberRedemptionPassOptions<OwnerGrantAccepted> = {
525
+ ...grantRedemption(options),
526
+ waitForMember: options.waitForMember,
527
+ expiresAt: options.bundle.grant.expiresAt,
528
+ expired: () => new OwnerGrantRejectedError('grant-spent', 'the grant expired before a member accepted it'),
529
+ ...(options.onProgress ? { onProgress: options.onProgress } : {}),
530
+ };
531
+ return dialRedemptionInPasses(node, passes);
532
+ }