@t3foundry/tasra-sdk 0.3.1-next.1 → 0.4.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 (255) hide show
  1. package/CHANGELOG.md +1067 -28
  2. package/README.md +15 -0
  3. package/dist/app/approvals.d.ts +66 -4
  4. package/dist/app/approvals.js +153 -16
  5. package/dist/app/authorization.d.ts +1 -1
  6. package/dist/app/authorization.js +1 -1
  7. package/dist/app/browser.d.ts +63 -0
  8. package/dist/app/browser.js +242 -0
  9. package/dist/app/client.d.ts +114 -13
  10. package/dist/app/client.js +302 -76
  11. package/dist/app/identity.js +21 -9
  12. package/dist/app/index.d.ts +28 -3
  13. package/dist/app/index.js +16 -1
  14. package/dist/app/memory-store.d.ts +7 -0
  15. package/dist/app/memory-store.js +55 -0
  16. package/dist/app/node.d.ts +34 -6
  17. package/dist/app/node.js +387 -64
  18. package/dist/app/paid-allowance.d.ts +325 -0
  19. package/dist/app/paid-allowance.js +1290 -0
  20. package/dist/app/paid-approval.d.ts +122 -0
  21. package/dist/app/paid-approval.js +379 -0
  22. package/dist/app/paid-journal.d.ts +51 -0
  23. package/dist/app/paid-journal.js +117 -0
  24. package/dist/app/paid-keys.d.ts +12 -0
  25. package/dist/app/paid-keys.js +20 -0
  26. package/dist/app/paid-operation.d.ts +821 -0
  27. package/dist/app/paid-operation.js +1720 -0
  28. package/dist/app/paid-reservation.d.ts +157 -0
  29. package/dist/app/paid-reservation.js +323 -0
  30. package/dist/app/paid-session.d.ts +147 -0
  31. package/dist/app/paid-session.js +578 -0
  32. package/dist/app/payer-queue.d.ts +11 -0
  33. package/dist/app/payer-queue.js +27 -0
  34. package/dist/app/policy-bootstrap.d.ts +342 -0
  35. package/dist/app/policy-bootstrap.js +365 -0
  36. package/dist/app/policy-operation.d.ts +47 -0
  37. package/dist/app/policy-operation.js +101 -0
  38. package/dist/app/ready-slot.d.ts +12 -0
  39. package/dist/app/ready-slot.js +5 -2
  40. package/dist/app/rotation-lock.d.ts +38 -0
  41. package/dist/app/rotation-lock.js +42 -0
  42. package/dist/app/session-decrypt.d.ts +135 -0
  43. package/dist/app/session-decrypt.js +335 -0
  44. package/dist/app/session-grants.d.ts +349 -0
  45. package/dist/app/session-grants.js +811 -0
  46. package/dist/app/signing-intents.d.ts +78 -0
  47. package/dist/app/signing-intents.js +95 -0
  48. package/dist/app/store-commit.d.ts +63 -0
  49. package/dist/app/store-commit.js +126 -0
  50. package/dist/app/store-errors.d.ts +8 -0
  51. package/dist/app/store-errors.js +11 -0
  52. package/dist/app/tasra-client.d.ts +2 -0
  53. package/dist/app/tasra-client.js +1 -1
  54. package/dist/app/wallet.js +4 -1
  55. package/dist/auth/holderProof.d.ts +3 -0
  56. package/dist/auth/holderProof.js +8 -7
  57. package/dist/auth/verifier.d.ts +4 -2
  58. package/dist/auth/verifier.js +5 -2
  59. package/dist/chain/abis/index.d.ts +6178 -4101
  60. package/dist/chain/abis/index.js +3 -0
  61. package/dist/chain/abis/keyRegistry.d.ts +256 -0
  62. package/dist/chain/abis/keyRegistry.js +333 -0
  63. package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
  64. package/dist/chain/abis/prepaidFaultOracle.js +413 -0
  65. package/dist/chain/abis/settlement.d.ts +2203 -703
  66. package/dist/chain/abis/settlement.js +2685 -764
  67. package/dist/chain/allowance.d.ts +358 -0
  68. package/dist/chain/allowance.js +800 -0
  69. package/dist/chain/billing.d.ts +85 -0
  70. package/dist/chain/billing.js +197 -0
  71. package/dist/chain/chainId.d.ts +13 -0
  72. package/dist/chain/chainId.js +26 -0
  73. package/dist/chain/client.d.ts +15 -1
  74. package/dist/chain/client.js +57 -1
  75. package/dist/chain/commitmentRecovery.d.ts +51 -0
  76. package/dist/chain/commitmentRecovery.js +38 -0
  77. package/dist/chain/committeeClient.d.ts +17 -10
  78. package/dist/chain/committeeClient.js +64 -16
  79. package/dist/chain/committeeDraw.d.ts +12 -0
  80. package/dist/chain/committeeDraw.js +56 -0
  81. package/dist/chain/custodyHealth.d.ts +212 -0
  82. package/dist/chain/custodyHealth.js +365 -0
  83. package/dist/chain/deployments.js +2 -0
  84. package/dist/chain/events.js +2 -0
  85. package/dist/chain/headFollower.d.ts +77 -0
  86. package/dist/chain/headFollower.js +219 -0
  87. package/dist/chain/headPrefetch.d.ts +23 -0
  88. package/dist/chain/headPrefetch.js +67 -0
  89. package/dist/chain/index.d.ts +50 -8
  90. package/dist/chain/index.js +28 -3
  91. package/dist/chain/keeperExecution.d.ts +44 -0
  92. package/dist/chain/keeperExecution.js +127 -0
  93. package/dist/chain/keeperRecovery.d.ts +78 -0
  94. package/dist/chain/keeperRecovery.js +91 -0
  95. package/dist/chain/node.d.ts +24 -1
  96. package/dist/chain/node.js +88 -43
  97. package/dist/chain/offchain.d.ts +2 -0
  98. package/dist/chain/paidAgentTransport.d.ts +38 -0
  99. package/dist/chain/paidAgentTransport.js +1 -0
  100. package/dist/chain/paidEpoch.d.ts +66 -0
  101. package/dist/chain/paidEpoch.js +139 -0
  102. package/dist/chain/paidPacing.d.ts +81 -0
  103. package/dist/chain/paidPacing.js +136 -0
  104. package/dist/chain/pinnedReads.d.ts +49 -0
  105. package/dist/chain/pinnedReads.js +218 -0
  106. package/dist/chain/prepaid.d.ts +383 -0
  107. package/dist/chain/prepaid.js +1046 -0
  108. package/dist/chain/prepaidEscape.d.ts +274 -0
  109. package/dist/chain/prepaidEscape.js +432 -0
  110. package/dist/chain/prepaidFault.d.ts +94 -0
  111. package/dist/chain/prepaidFault.js +148 -0
  112. package/dist/chain/receipt.d.ts +24 -0
  113. package/dist/chain/receipt.js +82 -0
  114. package/dist/chain/registeredAgent.d.ts +68 -3
  115. package/dist/chain/registeredAgent.js +143 -42
  116. package/dist/chain/registeredOperation.d.ts +10 -1
  117. package/dist/chain/registeredOperation.js +18 -3
  118. package/dist/chain/registeredPaidAgent.d.ts +254 -0
  119. package/dist/chain/registeredPaidAgent.js +889 -0
  120. package/dist/chain/registeredRelay.d.ts +31 -1
  121. package/dist/chain/registeredRelay.js +164 -43
  122. package/dist/chain/relayVoucher.d.ts +64 -0
  123. package/dist/chain/relayVoucher.js +69 -0
  124. package/dist/chain/reservation.d.ts +239 -0
  125. package/dist/chain/reservation.js +746 -0
  126. package/dist/chain/reshareRoster.d.ts +64 -0
  127. package/dist/chain/reshareRoster.js +85 -0
  128. package/dist/chain/revertReason.d.ts +8 -0
  129. package/dist/chain/revertReason.js +2 -1
  130. package/dist/chain/rotationLock.d.ts +130 -0
  131. package/dist/chain/rotationLock.js +168 -0
  132. package/dist/chain/serviceRequestPolicy.d.ts +47 -0
  133. package/dist/chain/serviceRequestPolicy.js +86 -0
  134. package/dist/chain/services.d.ts +7 -0
  135. package/dist/chain/services.js +44 -4
  136. package/dist/chain/slotClient.js +11 -2
  137. package/dist/chain/slotHandoff.d.ts +81 -0
  138. package/dist/chain/slotHandoff.js +166 -0
  139. package/dist/chain/slotSeed.d.ts +47 -5
  140. package/dist/chain/slotSeed.js +173 -42
  141. package/dist/chain/verifierSnapshot.d.ts +36 -0
  142. package/dist/chain/verifierSnapshot.js +197 -0
  143. package/dist/chain/write.d.ts +111 -21
  144. package/dist/chain/write.js +378 -146
  145. package/dist/committee/blsSharing.d.ts +53 -0
  146. package/dist/committee/blsSharing.js +90 -0
  147. package/dist/committee/client.d.ts +62 -23
  148. package/dist/committee/client.js +288 -72
  149. package/dist/committee/dual-operation.d.ts +165 -0
  150. package/dist/committee/dual-operation.js +229 -0
  151. package/dist/committee/dual-sign.d.ts +26 -1
  152. package/dist/committee/dual-sign.js +85 -7
  153. package/dist/committee/ecdsa.d.ts +38 -0
  154. package/dist/committee/ecdsa.js +87 -15
  155. package/dist/committee/evidence.d.ts +30 -0
  156. package/dist/committee/evidence.js +65 -0
  157. package/dist/committee/execution.d.ts +414 -0
  158. package/dist/committee/execution.js +446 -0
  159. package/dist/committee/extraction.js +33 -26
  160. package/dist/committee/index.d.ts +30 -7
  161. package/dist/committee/index.js +18 -6
  162. package/dist/committee/keeperExecution.d.ts +37 -0
  163. package/dist/committee/keeperExecution.js +141 -0
  164. package/dist/committee/oauth.d.ts +14 -4
  165. package/dist/committee/oauth.js +17 -5
  166. package/dist/committee/payment.d.ts +369 -0
  167. package/dist/committee/payment.js +339 -0
  168. package/dist/committee/recovery.d.ts +136 -0
  169. package/dist/committee/recovery.js +204 -0
  170. package/dist/committee/recoveryJson.d.ts +2 -0
  171. package/dist/committee/recoveryJson.js +87 -0
  172. package/dist/committee/request.d.ts +63 -27
  173. package/dist/committee/request.js +77 -66
  174. package/dist/committee/session-grant.d.ts +320 -0
  175. package/dist/committee/session-grant.js +397 -0
  176. package/dist/committee/status-refresh.d.ts +257 -0
  177. package/dist/committee/status-refresh.js +619 -0
  178. package/dist/committee/token.d.ts +163 -15
  179. package/dist/committee/token.js +247 -10
  180. package/dist/crypto/bn254.d.ts +70 -0
  181. package/dist/crypto/bn254.js +222 -0
  182. package/dist/crypto/ibe.d.ts +32 -0
  183. package/dist/crypto/ibe.js +56 -8
  184. package/dist/crypto/index.d.ts +1 -1
  185. package/dist/crypto/index.js +1 -1
  186. package/dist/crypto/kem.d.ts +31 -0
  187. package/dist/crypto/kem.js +113 -7
  188. package/dist/crypto/recipient.d.ts +75 -0
  189. package/dist/crypto/recipient.js +107 -0
  190. package/dist/decryption/client.d.ts +10 -16
  191. package/dist/decryption/client.js +8 -76
  192. package/dist/decryption/index.d.ts +2 -0
  193. package/dist/decryption/index.js +2 -0
  194. package/dist/decryption/sealed.d.ts +72 -0
  195. package/dist/decryption/sealed.js +147 -0
  196. package/dist/decryption/session.d.ts +115 -0
  197. package/dist/decryption/session.js +358 -0
  198. package/dist/errors.d.ts +406 -1
  199. package/dist/errors.js +400 -5
  200. package/dist/index.d.ts +9 -2
  201. package/dist/index.js +6 -1
  202. package/dist/internal/bounded.d.ts +66 -0
  203. package/dist/internal/bounded.js +126 -0
  204. package/dist/internal/network.d.ts +4 -0
  205. package/dist/internal/network.js +40 -0
  206. package/dist/internal/retryAfter.d.ts +8 -0
  207. package/dist/internal/retryAfter.js +28 -0
  208. package/dist/internal/sleep.d.ts +6 -0
  209. package/dist/internal/sleep.js +15 -0
  210. package/dist/internal/typedData.d.ts +13 -0
  211. package/dist/internal/typedData.js +77 -0
  212. package/dist/internal/viemErrors.d.ts +26 -0
  213. package/dist/internal/viemErrors.js +49 -0
  214. package/dist/oid4vp/binding.d.ts +27 -1
  215. package/dist/oid4vp/binding.js +36 -1
  216. package/dist/oid4vp/jose.d.ts +4 -2
  217. package/dist/oid4vp/jose.js +39 -7
  218. package/dist/oid4vp/request-object.d.ts +61 -4
  219. package/dist/oid4vp/request-object.js +140 -5
  220. package/dist/oid4vp/verifier-agent.d.ts +18 -8
  221. package/dist/oid4vp/verifier-agent.js +48 -6
  222. package/dist/oid4vp/wallet.d.ts +2 -4
  223. package/dist/oid4vp/wallet.js +1 -0
  224. package/dist/retry.d.ts +78 -0
  225. package/dist/retry.js +137 -0
  226. package/dist/signing/frost.d.ts +1 -1
  227. package/dist/verifier-agent/index.d.ts +41 -5
  228. package/dist/verifier-agent/index.js +124 -9
  229. package/dist/verifier-agent/payment.d.ts +7 -0
  230. package/dist/verifier-agent/payment.js +17 -0
  231. package/docs/api.md +8 -2
  232. package/docs/application-api.md +25 -2
  233. package/docs/chain.md +155 -9
  234. package/docs/consumer-migrations.md +61 -0
  235. package/docs/encrypted-notes.md +3 -2
  236. package/docs/encryption.md +4 -2
  237. package/docs/errors.md +14 -1
  238. package/docs/flows.md +2 -2
  239. package/docs/funding.md +902 -0
  240. package/docs/native-approvals.md +63 -0
  241. package/docs/reference/README.md +9 -8
  242. package/docs/reference/app-browser.md +232 -0
  243. package/docs/reference/app-node.md +38 -8
  244. package/docs/reference/app.md +4621 -805
  245. package/docs/reference/chain-node.md +74 -16
  246. package/docs/reference/chain.md +6740 -1592
  247. package/docs/reference/committee.md +5630 -987
  248. package/docs/reference/main.md +1439 -140
  249. package/docs/reference/oid4vp.md +297 -144
  250. package/docs/reference/verifier-agent.md +77 -35
  251. package/docs/signing.md +6 -0
  252. package/examples/encrypted-notes.ts +21 -6
  253. package/examples/getting-started.ts +2 -7
  254. package/examples/live-config.ts +24 -17
  255. package/package.json +17 -5
@@ -0,0 +1,821 @@
1
+ import { type ClientRecipient, type DecryptionBindingWire } from '../crypto/recipient.js';
2
+ import { type Account, type Address, type Chain, type Hex, type LocalAccount, type Transport, type WalletClient } from 'viem';
3
+ import type { TasraChainClient } from '../chain/client.js';
4
+ import type { BillingModeDetector } from '../chain/billing.js';
5
+ import { type PaidContextDeployment, type PaidKeeperEndpoint } from '../chain/prepaid.js';
6
+ import type { PaidAgentTransport } from '../chain/paidAgentTransport.js';
7
+ import type { ApprovedAgentProfile } from '../chain/registeredAgent.js';
8
+ import { type KeeperRecoveryTransport, type RecoveredKeeperExecution } from '../chain/keeperRecovery.js';
9
+ import { type ApplicationReservationState } from './paid-reservation.js';
10
+ import type { SessionGrantCreateFragment } from './session-grants.js';
11
+ import type { SessionGrantWire } from '../committee/session-grant.js';
12
+ import { type PaidSessionHolder } from './paid-session.js';
13
+ import type { ApplicationStore } from './ready-slot.js';
14
+ import { type ExecutionStage } from '../committee/execution.js';
15
+ import type { KeeperExecutionApprover } from '../committee/keeperExecution.js';
16
+ import { type AllowanceAction, type PaymentIntentWire } from '../committee/payment.js';
17
+ import { type CompoundTokenWire } from '../committee/token.js';
18
+ import { type StatusRefreshHolderSigner } from '../committee/status-refresh.js';
19
+ import { type CommitteeAction } from '../oid4vp/binding.js';
20
+ import type { VerifiedRequestObject } from '../oid4vp/request-object.js';
21
+ import type { VerifierProof } from '../committee/client.js';
22
+ import { TasraError, type StatusRefreshFailure } from '../errors.js';
23
+ import type { IbeExtractionPartial } from '../committee/client.js';
24
+ import { type PaidAllowanceOptions } from './paid-allowance.js';
25
+ import { type SlotPolicyBootstrap } from './policy-bootstrap.js';
26
+ /** Approved deployment, signers, services and spending limits shared by paid operations. */
27
+ export interface PaidOperationConfig {
28
+ /** Trusted chain client; its ServiceRegistry address must match the approved agent profile. */
29
+ chain: TasraChainClient;
30
+ /** Independently approved contracts, with the deployment default verifier policy. */
31
+ deployment: PaidContextDeployment & {
32
+ defaultVerificationPolicy?: {
33
+ committee: number;
34
+ quorum: number;
35
+ };
36
+ };
37
+ /** Slot creator: signs the operation, the payment intent and the execution certificate. */
38
+ creator: Pick<LocalAccount, 'address' | 'signTypedData'>;
39
+ /** Dedicated reservation gas payer (account- and chain-bound). Never shared with unrelated sends. */
40
+ gasPayer: WalletClient<Transport, Chain, Account>;
41
+ /** Private durable store with exclusive locks shared by every process or tab using this payer. */
42
+ store: ApplicationStore;
43
+ /** Independently approved verifier-agent and its guarded transport. */
44
+ agent: {
45
+ profile: ApprovedAgentProfile;
46
+ transport: PaidAgentTransport;
47
+ };
48
+ /** Approved accountant origins: reservation quotes and verifier snapshot artifacts. */
49
+ accountantUrls: readonly string[];
50
+ /** Finite spending limits: TASRA per operation, gas units and gas price for the reservation. */
51
+ limits: {
52
+ maxCost: bigint;
53
+ maxGas: bigint;
54
+ maxGasPrice: bigint;
55
+ };
56
+ /** Permit HTTP on the local development chain (43112) only. */
57
+ allowLocalHttp?: boolean;
58
+ /** Caller-approved keeper route map (registered URL to reachable URL). */
59
+ keeperUrl?: (registeredUrl: string) => string;
60
+ /** Cached billing detector for this deployment; a fresh read is used when absent. */
61
+ billing?: BillingModeDetector;
62
+ /** Fetch used for verifier snapshot artifacts (defaults to global fetch). */
63
+ fetch?: typeof fetch;
64
+ /** Longest wait for the current epoch's snapshots to be anchored, ms (default 180000, max 300000). */
65
+ snapshotWaitMs?: number;
66
+ /**
67
+ * Poll interval while waiting on the agent with nothing else to go on, ms (default 1000): a wallet
68
+ * callback, or proposals not yet listed. Agent Retry-After hints take precedence. Approved
69
+ * proposals and sent continuations are read back at once, and while the committee works the
70
+ * session status is long-polled (`?wait=1`) instead.
71
+ */
72
+ pollIntervalMs?: number;
73
+ /**
74
+ * Accept a grant WITHOUT revocation-status attestations (with a warning), only for a deployment
75
+ * still inside the keepers' documented status-freshness migration window. Default false: the
76
+ * grant is refused with `revocation_status_missing` before execution. Stale or invalid
77
+ * attestations are always refused.
78
+ */
79
+ allowMissingStatusAttestations?: boolean;
80
+ /**
81
+ * Prepaid allowances, DEFAULT OFF. With `enabled: true` an operation whose slot has a
82
+ * lane with room is paid by an accountant-quorum debit voucher against a reserved allowance
83
+ * instead of its own on-chain reservation; otherwise (no usable lane, exhausted, expired or
84
+ * refused) it falls back to the per-operation reservation. Enable only when every reader on the
85
+ * deployment supports prepaid allowances: the network advertises no capability for it.
86
+ */
87
+ allowances?: PaidAllowanceOptions;
88
+ }
89
+ /** The one operation to authorize and how its holder presents. */
90
+ export interface PaidOperationRequest {
91
+ /** Slot to operate on. */
92
+ slot: Hex;
93
+ /** Committee action and payload: `message` for sign, `identity` for ibe-extract, `payloadDigest` for decrypt/dual-approve. */
94
+ operation: {
95
+ action: CommitteeAction;
96
+ message?: Uint8Array;
97
+ identity?: string;
98
+ payloadDigest?: Uint8Array;
99
+ decryption?: DecryptionBindingWire;
100
+ ttlSecs?: number;
101
+ description?: string;
102
+ };
103
+ /**
104
+ * The slot's rule, in one of two forms. `{rule, salt}`: the exact provisioned DCQL rule bytes and
105
+ * salt; the chain commitment uses canonical JSON, the verifier token hash binds these original
106
+ * bytes unchanged. `{policy, audience}`: a creator-signed slot policy bootstrap issued to this
107
+ * holder application (`audience`), for a holder that never holds the salt. Its signature, scope,
108
+ * lifetime and rule hash are checked offline, then its creator, commitment and rule version
109
+ * against the same canonical slot read discovery makes, and its sequence against the store's
110
+ * high-water mark; all before anything is signed or spent. The bootstrap is journaled with the
111
+ * operation; the salt never is.
112
+ */
113
+ rule: {
114
+ rule: string;
115
+ salt: Hex;
116
+ } | {
117
+ policy: SlotPolicyBootstrap;
118
+ audience: Address;
119
+ };
120
+ /**
121
+ * Holder strategy: the SDK wallet presents itself, an external wallet scans the request, or
122
+ * (`kind: 'oauth'`) the client presents a DPoP-bound OAuth access token for an OAuth slot rule.
123
+ * The choice is journaled with the operation: a resume must use the same kind.
124
+ */
125
+ holder: PaidSessionHolder;
126
+ /** Pin the coordinator keeper (operator address); otherwise the first eligible keeper. */
127
+ coordinator?: Address;
128
+ /** Cancellation for the authorization (reservation, session, grant). */
129
+ signal?: AbortSignal;
130
+ /** Inspect the verified request object before any credential is disclosed. */
131
+ observeRequest?(request: VerifiedRequestObject): void | Promise<void>;
132
+ /**
133
+ * Session grants: also open a session grant with this presentation (KEM `decrypt` only), for the
134
+ * fresh session key in the fragment ({@link sessionGrantCreateFragment}). The fragment is public
135
+ * and journaled; the presentation nonce binds its key. The verified grant comes back as
136
+ * {@link PaidOperation.sessionGrant}; accept it with `acceptSessionGrant` and the same key.
137
+ */
138
+ sessionGrant?: SessionGrantCreateFragment;
139
+ /**
140
+ * Receive the reservation identity as soon as it is derived, before witnesses are fetched or
141
+ * anything is reserved, to link this run to its payment. A throw stops the operation before any
142
+ * spending. Until the journal is written (just before reservation) `paidOperationPhase` returns
143
+ * undefined for it.
144
+ */
145
+ onRequestId?(requestId: Hex): void | Promise<void>;
146
+ }
147
+ /** A verified, paid committee authorization for exactly one keeper execution. */
148
+ export interface PaidOperation {
149
+ /** Exact sealed presentation ciphertext persisted with the original grant. */
150
+ readonly evidenceCt?: string;
151
+ /**
152
+ * Session grants, when the request asked for a session grant: the verified opening grant
153
+ * (`{session_grant, refresh_seq: 0}`, the input of `acceptSessionGrant`), or why none came. The
154
+ * compound token authorizes this one operation either way.
155
+ */
156
+ readonly sessionGrant?: {
157
+ grant?: {
158
+ session_grant: SessionGrantWire;
159
+ refresh_seq: 0;
160
+ };
161
+ error?: string;
162
+ };
163
+ /** Reservation identity (`prepaid-request/v1`), the key for resume and recovery. */
164
+ readonly requestId: Hex;
165
+ /** Original creator-signed payment intent. */
166
+ readonly payment: PaymentIntentWire;
167
+ /** The assigned coordinator keeper's reachable URL (after the approved route map). */
168
+ readonly coordinatorUrl: string;
169
+ /** Verified compound token carrying the payment. */
170
+ readonly compound_token: CompoundTokenWire;
171
+ /** Anchored verifier witnesses, for keeper calls. */
172
+ readonly verifierProofs: VerifierProof[];
173
+ /** The same witnesses in wire form. */
174
+ readonly verifier_proofs: {
175
+ verifier_index: number;
176
+ operator: string;
177
+ pubkey: string;
178
+ proof: string[];
179
+ }[];
180
+ /** Client approver for keeper stage signatures; pass as `approveExecution` to committee clients. */
181
+ readonly approveExecution: KeeperExecutionApprover;
182
+ /** Run the keeper operation exactly once. A failure is journaled and never retried; use `recover`. */
183
+ execute<R>(work: (operation: PaidOperation) => Promise<R>): Promise<R>;
184
+ /**
185
+ * Explicitly refresh the grant's revocation-status attestations
186
+ * (`keykeeper/committee-status-refresh/v1`) for the SAME token and payment, before `execute`.
187
+ * Allowed only while the journal is `authorized` (nothing was sent). A new `seq` is journaled
188
+ * BEFORE the proof is signed or sent and is never reused, even after a crash. On success the
189
+ * grant's `status_attestations` are replaced in the journal (the original list is kept in its
190
+ * refresh history) and later `execute` calls and `compound_token` reads use them. Never automatic,
191
+ * never retried; no new session, payment or keeper work. Throws {@link StatusRefreshError}.
192
+ */
193
+ refreshStatus(options?: RefreshPaidStatusOptions): Promise<PaidStatusRefresh>;
194
+ /** Read the keeper's retained result after an uncertain execution. Performs no new work. */
195
+ recover(options: {
196
+ transport: KeeperRecoveryTransport;
197
+ stage?: Extract<ExecutionStage, 'coordinator' | 'contributor'>;
198
+ /** Original assigned contributor public key; reads sealed result bytes without opening them. */
199
+ contributorKey?: Hex;
200
+ signal?: AbortSignal;
201
+ }): Promise<RecoveredKeeperExecution>;
202
+ /**
203
+ * After an uncertain `ibe-extract` fan-out, read each assigned contributor's retained,
204
+ * commitment-verified partial (stage `contributor`) until the payment's keeper threshold is
205
+ * met. Performs no new work and never re-sends an extraction. Combine the partials with the
206
+ * pairing-verifying IBE combine helpers. Throws when fewer than the threshold are recoverable.
207
+ */
208
+ recoverIbePartials(options: RecoverIbePartialsOptions): Promise<RecoveredIbePartials>;
209
+ /** Erase the local execution signer. */
210
+ dispose(): void;
211
+ }
212
+ /** Options for {@link PaidOperation.recoverIbePartials}. */
213
+ export interface RecoverIbePartialsOptions {
214
+ /** Original client-held recipient. Its private key is never written to the operation journal. */
215
+ recipient?: ClientRecipient;
216
+ /** Original identity and authenticated 144-byte G2 || G1 public shares. */
217
+ identity?: string;
218
+ /** Original authenticated 144-byte G2 || G1 public shares used to validate recovered contributions. */
219
+ verifyingShares?: ReadonlyMap<number, Uint8Array>;
220
+ /** Caller-approved guarded keeper recovery transport. */
221
+ transport: KeeperRecoveryTransport;
222
+ /** Cancellation for the whole recovery; each keeper read also has its own 60-second deadline. */
223
+ signal?: AbortSignal;
224
+ /** Contributors read at once, 1..16 (default 4). No new read starts after the threshold is met. */
225
+ concurrency?: number;
226
+ }
227
+ /** Options for {@link PaidOperation.refreshStatus} and {@link PaidOperationRecovery.refreshStatus}. */
228
+ export interface RefreshPaidStatusOptions {
229
+ /**
230
+ * Route: `'agent'` (default) relays through the original session of the approved verifier-agent
231
+ * (journals written before the SDK recorded the session id cannot use it); `{verifiers}` calls
232
+ * the original signers' verifiers directly. Either way every answer is verified here under the
233
+ * anchored roster keys of the signers that verified the original token.
234
+ */
235
+ via?: 'agent' | {
236
+ verifiers: readonly {
237
+ index: number;
238
+ url: string;
239
+ }[];
240
+ fetch?: typeof fetch;
241
+ };
242
+ /**
243
+ * Prove with the holder key recorded at issuance (`holder_key`) instead of the creator-certified
244
+ * client execution key (`client_execution`, the default).
245
+ */
246
+ holder?: StatusRefreshHolderSigner;
247
+ /** Cancellation. An abort after the `seq` was journaled still consumes it. */
248
+ signal?: AbortSignal;
249
+ }
250
+ /** A successful paid status refresh. */
251
+ export interface PaidStatusRefresh {
252
+ /** Reservation identity. */
253
+ requestId: Hex;
254
+ /** Journaled sequence number the proof used. */
255
+ seq: number;
256
+ /** Effective status deadline (quorum-th largest), Unix seconds; keepers accept until `+ 5 s`. */
257
+ statusUntil: number;
258
+ /** The journaled grant with its merged attestations (signatures and token hash unchanged). */
259
+ compound_token: CompoundTokenWire;
260
+ /** Verifier indexes whose new attestation was accepted. */
261
+ refreshed: number[];
262
+ /** Original signers that contributed nothing, and why. */
263
+ failures: StatusRefreshFailure[];
264
+ }
265
+ /** One contributor's recovered extraction partial. */
266
+ export interface RecoveredIbePartial {
267
+ /** Assigned contributor, with its approved (routed) URL. */
268
+ keeper: PaidKeeperEndpoint;
269
+ /** Decoded partial, in the shape the IBE combine helpers accept. */
270
+ partial: IbeExtractionPartial;
271
+ /** Signed execution evidence and exact retained bytes. */
272
+ recovered: RecoveredKeeperExecution;
273
+ }
274
+ /** Result of {@link PaidOperation.recoverIbePartials}. */
275
+ export interface RecoveredIbePartials {
276
+ /** Keeper threshold from the payment's assignment. */
277
+ threshold: number;
278
+ /** At least `threshold` recovered partials, from distinct contributors. */
279
+ partials: RecoveredIbePartial[];
280
+ /** Contributors whose retained result could not be read (operator and a safe message). */
281
+ failures: {
282
+ operator: Address;
283
+ message: string;
284
+ }[];
285
+ }
286
+ /** Where a paid operation stopped with an uncertain or unfinished outcome. */
287
+ export type PaidOperationPhase = 'reservation' | 'session' | 'execution';
288
+ /**
289
+ * Stable reason a paid operation stopped. `resumable` on the error says whether
290
+ * {@link resumePaidOperation} can still make progress.
291
+ * - `reservation-refused`: nothing was prepared or sent (e.g. accountant refusal, underfunded
292
+ * slot, RPC failure before preparation). Resumable unless the payment expired.
293
+ * - `reservation-uncertain`: a reservation may have been sent; resume reconciles it, never resends.
294
+ * - `reservation-failed`: the original reservation provably never happened. Final.
295
+ * - `session-interrupted`: transport loss, timeout or an unavailable agent; resume continues.
296
+ * - `session-refused`: the committee, a verifier, the wallet or the agent refused (a failed
297
+ * session, HTTP 4xx such as 403/410). Final.
298
+ * - `session-write-uncertain`: a journaled session write has an unknown outcome; resume refuses
299
+ * it until reconciled out of band. Not resumable.
300
+ * - `payment-expired`: the creator-signed payment expired; nothing more can run under it. Final.
301
+ * - `execution-uncertain`: the keeper may have run; use the handle's `recover`, never execute again.
302
+ * - `aborted`: the caller's signal stopped a journaled operation before anything uncertain was
303
+ * sent in this step; resumable unless the payment expired. When the abort left a step uncertain
304
+ * (a reservation or session write may have been sent, or an execution), that step's uncertain
305
+ * code is reported instead. An abort before the journal is written rethrows the signal's reason:
306
+ * nothing was journaled or sent.
307
+ */
308
+ export type PaidOperationErrorCode = 'reservation-refused' | 'reservation-uncertain' | 'reservation-failed' | 'session-interrupted' | 'session-refused' | 'session-write-uncertain' | 'payment-expired' | 'execution-uncertain' | 'aborted';
309
+ /** The operation stopped where repeating a step could pay or execute twice; resume or recover it. */
310
+ export declare class PaidOperationRecoveryError extends TasraError {
311
+ /** Reservation identity to resume with. */ readonly requestId: Hex;
312
+ /** Step whose outcome is uncertain. */ readonly phase: PaidOperationPhase;
313
+ /** Stable machine-readable reason. */
314
+ readonly code: PaidOperationErrorCode;
315
+ /** Whether {@link resumePaidOperation} can still make progress; false for a final refusal or a step only `recover` can read. */
316
+ readonly resumable: boolean;
317
+ constructor(
318
+ /** Reservation identity to resume with. */ requestId: Hex,
319
+ /** Step whose outcome is uncertain. */ phase: PaidOperationPhase, cause: unknown,
320
+ /** Classification; defaults to the uncertain outcome of the phase. */
321
+ detail?: {
322
+ code?: PaidOperationErrorCode;
323
+ resumable?: boolean;
324
+ });
325
+ }
326
+ /**
327
+ * Journaled progress of one paid operation. `failed` is terminal: the original reservation
328
+ * provably never happened and the operation must not be reserved again. `abandoned` is terminal
329
+ * too: the application closed it with {@link abandonPaidOperation} once nothing could still land.
330
+ */
331
+ export type PaidOperationJournalPhase = 'reserving' | 'reserved' | 'certified' | 'authorized' | 'executing' | 'executed' | 'failed' | 'abandoned';
332
+ /** Which lanes of a slot {@link prepareAllowances} opens, and how. */
333
+ export interface PrepareAllowancesRequest {
334
+ /** Slot whose allowance lanes to open. */
335
+ slot: Hex;
336
+ /** Regular lane indices to open, each 0..lanes-1 and distinct (default every lane, see `allowanceLaneCount`). */
337
+ lanes?: readonly number[];
338
+ /**
339
+ * Lanes opened at once, 1..8 (default 4). Every reservation goes through the one dedicated gas
340
+ * payer queue, and each pins its own fresh discovery as its quote block, which the accountants
341
+ * accept for only 30 s: a lane that waits behind too many others in the queue is refused.
342
+ */
343
+ concurrency?: number;
344
+ /** Coordinator to discover with (as {@link PaidOperationRequest.coordinator}). */
345
+ coordinator?: Address;
346
+ /**
347
+ * Each lane must fund at least this many more operations at the per-operation cap
348
+ * (`limits.maxCost`) from its current allowance and its reserved-ahead one together (only an
349
+ * allowance outliving `minLifetimeSecs` counts); otherwise the next allowance is reserved ahead
350
+ * now. 0..2 x floor(amount / maxCost); default 0 (today's rule: a confirmed, not-low current
351
+ * allowance is enough). Set it, with `minLifetimeSecs`, when preparing for sustained work: a
352
+ * lane that is confirmed but close to exhaustion or expiry otherwise reports `not-needed` and the
353
+ * work reserves its replacement inside an operation.
354
+ */
355
+ minOperations?: number;
356
+ /**
357
+ * The current allowance must outlive this many seconds, else the next one is reserved ahead (and
358
+ * must outlive it). 0..lifetime - 120 s; default 0. A bound on how long the coming work runs.
359
+ */
360
+ minLifetimeSecs?: number;
361
+ /**
362
+ * The paid actions the coming work runs (as `PaidOperationRequest.operation.action`: `sign` is
363
+ * paid as `eoa-sign` on a threshold-ECDSA slot, exactly as {@link paidOperation} pays it). Given,
364
+ * a lane is ready only when its current or confirmed reserved-ahead allowance passes the very
365
+ * check lane selection applies to each of these operations, started at any moment of
366
+ * `minLifetimeSecs`: the action funded, the keeper sharing (key epoch, committee version,
367
+ * threshold, contributors) of a FRESH discovery made for this judgement, and an expiry beyond the
368
+ * operation's own payment lifetime (`operationTtlSecs`) plus the clock margin. A lane that fails it
369
+ * gets a fitting next allowance reserved ahead; a current one that cannot fund the next operation
370
+ * at all gives way to it, and a reserved-ahead one that never can (a stale sharing) is replaced.
371
+ * Without it readiness looks at balance and expiry alone, so a lane can report `not-needed` and
372
+ * still be refused by every operation (one discovery more per call when given).
373
+ */
374
+ actions?: readonly AllowanceAction[];
375
+ /** The coming operations' payment lifetime, 1..3600 s (default 600, {@link paidOperation}'s default); only with `actions`. */
376
+ operationTtlSecs?: number;
377
+ /** Cancellation: lanes not yet started are reported `cancelled`; a started one is cancelled until its reservation is prepared. */
378
+ signal?: AbortSignal;
379
+ }
380
+ /**
381
+ * What {@link prepareAllowances} did for one lane:
382
+ * - `reserved`: an allowance was reserved (confirmed) on the lane now: the lane's current one, or its next reserved ahead for `minOperations` / `minLifetimeSecs`;
383
+ * - `not-needed`: the lane already had a usable confirmed allowance (or one reserved ahead); nothing was discovered, signed or sent;
384
+ * - `pending`: a reservation of the lane is uncertain (broadcast, outcome unknown); a later call or operation reconciles it, never re-signs beside it;
385
+ * - `failed`: the reservation failed (`error`), or (`AllowanceCapacityError`) the lane holds its current and a reserved-ahead allowance and still cannot fund `minOperations` (never a third: at most 2 x lanes x amount locked); nothing of it is left on the lane unless it was broadcast (then `pending` next time);
386
+ * - `cancelled`: the signal ended it before its reservation was prepared, or before it started.
387
+ */
388
+ export type PreparedAllowanceOutcome = 'reserved' | 'pending' | 'not-needed' | 'failed' | 'cancelled';
389
+ /** One lane's result of {@link prepareAllowances}. */
390
+ export interface PreparedAllowanceLane {
391
+ /** Lane index. */
392
+ lane: number;
393
+ /** What happened on the lane. */
394
+ outcome: PreparedAllowanceOutcome;
395
+ /** The failure, for `failed` (and the abort reason for a `cancelled` lane that had started). */
396
+ error?: unknown;
397
+ }
398
+ /** The result of {@link prepareAllowances}, one entry per requested lane, in request order. */
399
+ export interface PreparedAllowances {
400
+ /** Slot. */
401
+ slot: Hex;
402
+ /** Per-lane outcomes. */
403
+ lanes: PreparedAllowanceLane[];
404
+ }
405
+ /**
406
+ * Prepaid allowances: open (reserve) a slot's allowance lanes BEFORE its first paid operation, like loading
407
+ * a card, so no user operation waits for an allowance reservation (approve + reserve transactions
408
+ * and their receipts) inside it. Operations otherwise open a cold lane themselves: the first one on
409
+ * each lane then falls back to a per-operation reservation or waits for the lane.
410
+ *
411
+ * Each lane is reserved through the same journaled reservation as an operation's background refill
412
+ * (intent signed by the creator, `signing`, then `prepared`, `submitted` and `confirmed` under the
413
+ * durable payer claim and the dedicated payer queue), with its own FRESH discovery (never a context
414
+ * cached across lanes); a lane that needs nothing is reported `not-needed` without any read or
415
+ * send, so the call is idempotent. A lane failure is reported on that lane only; the other lanes
416
+ * are unaffected. Never throws for a lane's outcome; throws only for invalid input or
417
+ * configuration, and when the signal was aborted before anything started.
418
+ *
419
+ * Draw lanes (session grants) are not opened here: their draw is known only once a
420
+ * grant exists.
421
+ * @param config Approved deployment, creator, gas payer, store, accountants, limits and `allowances` (enabled).
422
+ * @param request Slot, lanes, concurrency, readiness for the coming work and cancellation.
423
+ */
424
+ export declare function prepareAllowances(config: PaidOperationConfig, request: PrepareAllowancesRequest): Promise<PreparedAllowances>;
425
+ /**
426
+ * Authorize one paid committee operation. Returns a handle whose `execute` runs the keeper
427
+ * operation once. Throws PaidOperationRecoveryError when a reservation, session write or the
428
+ * execution outcome is uncertain; continue with {@link resumePaidOperation}, never by calling
429
+ * this again (that would be a second payment).
430
+ * @param config Approved deployment, creator, gas payer, store, agent, accountants and limits.
431
+ * @param request Slot, operation, original rule, holder strategy and cancellation.
432
+ */
433
+ export declare function paidOperation(config: PaidOperationConfig, request: PaidOperationRequest): Promise<PaidOperation>;
434
+ /**
435
+ * One per-operation payment. A refused reservation is never replaced by a re-signed intent here:
436
+ * an intent that reached an accountant can still be reserved by anyone holding it (the accountant
437
+ * accepts a client-pinned quote block up to MAX_QUOTE_AGE old, and `reservePrepaid*` is
438
+ * permissionless) until its payment expires, so a second intent could be charged as well. The
439
+ * journal stays `reserving`, reconcilable (`reconcilePaidOperation`, `resumePaidOperation`) and
440
+ * not abandonable until that window has passed; a reservation that lands meanwhile is found by
441
+ * reconciliation, and one left unused is refunded by the accountants' unused-reservation close.
442
+ */
443
+ /**
444
+ * A per-operation reservation that waited for its payer past its verifier epoch, refused BEFORE the
445
+ * first prepare (see {@link reserve}): the signed intent never left this process, so it is
446
+ * journaled `failed` and the operation is signed once more at a current epoch. A
447
+ * {@link paidOperation} does that itself (once); a {@link paidSessionDecrypt} pays the GRANT's
448
+ * draw, so it throws this and its caller pays again on a refreshed grant (`decryptInSession`).
449
+ * `beaconEpoch` is this process's own chain read that refused it.
450
+ */
451
+ export declare class NewerVerifierEpoch extends Error {
452
+ /** The refused reservation's payment request id. */
453
+ readonly requestId: Hex;
454
+ /** The beacon epoch this process read when it refused. */
455
+ readonly beaconEpoch: bigint;
456
+ /** Stable reason. */
457
+ readonly code: "newer-verifier-epoch";
458
+ constructor(
459
+ /** The refused reservation's payment request id. */
460
+ requestId: Hex,
461
+ /** The beacon epoch this process read when it refused. */
462
+ beaconEpoch: bigint);
463
+ }
464
+ /** Read-only recovery for a paid operation whose keeper work was sent; see {@link recoverPaidOperation}. */
465
+ export interface PaidOperationRecovery {
466
+ /** Reservation identity. */
467
+ readonly requestId: Hex;
468
+ /** Original creator-signed payment intent. */
469
+ readonly payment: PaymentIntentWire;
470
+ /** Journaled phase (`executing` or `executed`, or `abandoned` from one of them). */
471
+ readonly phase: PaidOperationJournalPhase;
472
+ /** Read the keeper's retained result (coordinator stage by default). Performs no new work. */
473
+ recover: PaidOperation['recover'];
474
+ /** For `ibe-extract`: read contributors' retained partials up to the threshold. Performs no new work. */
475
+ recoverIbePartials: PaidOperation['recoverIbePartials'];
476
+ /**
477
+ * EXPLICIT RECOVERY ONLY: refresh the grant's revocation-status attestations while the execution
478
+ * is uncertain (`executing`), for an application that has independently decided to continue the
479
+ * SAME request (for example after `recover` found no coordinator record). It changes no keeper
480
+ * state and NOT the journal phase: the execution stays uncertain, `execute` stays refused, and
481
+ * neither a keeper 403 nor a recovery 404 becomes evidence that no work ran. Same journaled,
482
+ * never-reused `seq` as {@link PaidOperation.refreshStatus}; requires `explicitRecovery: true`.
483
+ */
484
+ refreshStatus(options: RefreshPaidStatusOptions & {
485
+ explicitRecovery: true;
486
+ }): Promise<PaidStatusRefresh>;
487
+ /** Erase the local execution signer. */
488
+ dispose(): void;
489
+ }
490
+ /**
491
+ * Open the read-only recovery reads of a paid operation whose keeper work was sent, straight
492
+ * from its journal: after {@link reconcilePaidOperation} reports `next: 'recover'` (phase
493
+ * `executing`), or to re-read an `executed` result. No reservation, session or execution
494
+ * happens, and no holder is needed. Refused for any other phase. Journals written before the
495
+ * SDK recorded assigned contributors (before dfafff3) support `recover` but not
496
+ * `recoverIbePartials`.
497
+ * @param config The configuration the operation started with.
498
+ * @param requestId Reservation identity.
499
+ */
500
+ export declare function recoverPaidOperation(config: PaidOperationConfig, requestId: Hex): Promise<PaidOperationRecovery>;
501
+ /** What the application should do next with a reconciled paid operation. */
502
+ export type PaidOperationNextStep =
503
+ /** Nothing was ever reserved; `resumePaidOperation` makes the first reservation. */
504
+ 'reserve'
505
+ /** Reserved or further; `resumePaidOperation` continues (session needs its holder). */
506
+ | 'resume'
507
+ /** The reservation outcome is not provable yet; reconcile again later. Never reserve again. */
508
+ | 'wait'
509
+ /** Keeper execution outcome is uncertain; read it with the handle's `recover`. */
510
+ | 'recover'
511
+ /** The keeper operation completed. */
512
+ | 'done'
513
+ /** The original reservation provably never happened; this operation is finished unpaid. */
514
+ | 'abandon'
515
+ /** The application closed this operation with {@link abandonPaidOperation}; nothing more to do. */
516
+ | 'closed';
517
+ /** Read-only reconciliation result of {@link reconcilePaidOperation}. */
518
+ export interface PaidOperationStatus {
519
+ /** Reservation identity. */
520
+ requestId: Hex;
521
+ /** Journaled phase after reconciliation. */
522
+ phase: PaidOperationJournalPhase;
523
+ /** Gas payer the journal recorded (absent from journals written before payers were recorded). */
524
+ payer?: Address;
525
+ /** Reservation state: proven from the chain while `reserving`, implied by the phase afterwards. */
526
+ reservation: ApplicationReservationState;
527
+ /** Whether this operation still holds its gas payer's durable claim. */
528
+ payerLocked: boolean;
529
+ /** Next safe step. */
530
+ next: PaidOperationNextStep;
531
+ /** Why the reservation is `uncertain` or `not-reserved`; safe to log. */
532
+ reason?: string;
533
+ /** Journaled or reported reservation transaction hash, when known. */
534
+ transactionHash?: Hex;
535
+ }
536
+ /** Options shared by {@link resumePaidOperation} and {@link reconcilePaidOperation}. */
537
+ export interface ResumePaidOperationOptions {
538
+ /** Holder strategy, needed while the session is unfinished. */
539
+ holder?: PaidSessionHolder;
540
+ /** A located original reservation transaction hash, when none was journaled; speeds a proof before the quote deadline. */
541
+ transactionHash?: Hex;
542
+ /** Cancellation. */
543
+ signal?: AbortSignal;
544
+ /** Inspect the verified request object before any credential is disclosed. */
545
+ observeRequest?(request: VerifiedRequestObject): void | Promise<void>;
546
+ /** Chain observation depth for reservation reconciliation, 1..64 (default 1). */
547
+ confirmations?: number;
548
+ /**
549
+ * Only reconcile: never reserve, never drive the session, never execute. Returns the
550
+ * {@link PaidOperationStatus} instead of a handle. Same as {@link reconcilePaidOperation}.
551
+ */
552
+ reconcileOnly?: boolean;
553
+ }
554
+ /**
555
+ * Reconcile a paid operation without any billable or keeper work: no reservation, no session
556
+ * write, no execution. A `reserving` operation is checked on chain by its request ID and payer
557
+ * nonce (no transaction hash needed) and advanced only on proof: `reserved` when the chain holds
558
+ * it, `failed` when its quote deadline passed without one. Anything else stays `reserving`
559
+ * with `next: 'wait'` and the payer locked.
560
+ * @param config The configuration the operation started with.
561
+ * @param requestId Reservation identity.
562
+ * @param options Located transaction hash and observation depth.
563
+ */
564
+ export declare function reconcilePaidOperation(config: PaidOperationConfig, requestId: Hex, options?: Pick<ResumePaidOperationOptions, 'transactionHash' | 'confirmations'>): Promise<PaidOperationStatus>;
565
+ /**
566
+ * Continue a paid operation from its journal after a PaidOperationRecoveryError or a restart.
567
+ * A `reserving` operation is first reconciled on chain (see {@link reconcilePaidOperation}); it
568
+ * is reserved only when nothing was ever prepared for it (no journal, no payer claim, nothing on
569
+ * chain), and never again after any preparation. An unprovable reservation throws
570
+ * PaidOperationRecoveryError and keeps the gas payer locked. A session is re-read, skipping
571
+ * confirmed writes; an authorized or executing operation returns its handle (use `recover` for
572
+ * an uncertain execution). With `reconcileOnly` it returns the status instead and does no work.
573
+ * @param config The same configuration the operation started with.
574
+ * @param requestId Reservation identity from the error or the journal.
575
+ * @param options Holder strategy, located transaction hash, cancellation, request observation, reconcile-only.
576
+ */
577
+ export declare function resumePaidOperation(config: PaidOperationConfig, requestId: Hex, options: ResumePaidOperationOptions & {
578
+ reconcileOnly: true;
579
+ }): Promise<PaidOperationStatus>;
580
+ /**
581
+ * Continue a paid operation from its journal after a PaidOperationRecoveryError or a restart.
582
+ * A `reserving` operation is first reconciled on chain (see {@link reconcilePaidOperation}); it
583
+ * is reserved only when nothing was ever prepared for it (no journal, no payer claim, nothing on
584
+ * chain), and never again after any preparation. An unprovable reservation throws
585
+ * PaidOperationRecoveryError and keeps the gas payer locked. A session is re-read, skipping
586
+ * confirmed writes; an authorized or executing operation returns its handle (use `recover` for
587
+ * an uncertain execution). With `reconcileOnly` it returns the status instead and does no work.
588
+ * @param config The same configuration the operation started with.
589
+ * @param requestId Reservation identity from the error or the journal.
590
+ * @param options Holder strategy, located transaction hash, cancellation, request observation, reconcile-only.
591
+ */
592
+ export declare function resumePaidOperation(config: PaidOperationConfig, requestId: Hex, options?: ResumePaidOperationOptions & {
593
+ reconcileOnly?: false;
594
+ }): Promise<PaidOperation>;
595
+ /**
596
+ * Read the journaled phase of a paid operation, for deciding between resume and recovery.
597
+ * @param store Store the operation was journaled in.
598
+ * @param requestId Reservation identity.
599
+ */
600
+ /** A final dual-control Sign: the message whose SHA-256 the payment binds, and its lifetime. */
601
+ export interface PaidFinalSignRequest {
602
+ /** FROST slot under a dual-control policy. */
603
+ slot: Hex;
604
+ /** Exact message the dual-control request will sign. */
605
+ message: Uint8Array;
606
+ /** Payment lifetime, 1..3600 seconds (default 600). */
607
+ ttlSecs?: number;
608
+ /** Pin the coordinator keeper (operator address); otherwise the drawn one. */
609
+ coordinator?: Address;
610
+ /** Cancellation (discovery, debit or reservation). */
611
+ signal?: AbortSignal;
612
+ /** Receive the request identity before anything is debited or reserved; a throw stops it. */
613
+ onRequestId?(requestId: Hex): void | Promise<void>;
614
+ }
615
+ /** A paid final Sign ready for `createDualSignClient`: its payment, keeper and execution approvals. */
616
+ export interface PaidFinalSign {
617
+ /** Request identity (the dual-sign request id without `0x`). */
618
+ requestId: Hex;
619
+ /** The backed final Sign payment (with its debit voucher when allowance-backed). */
620
+ payment: PaymentIntentWire;
621
+ /** The payment's coordinator keeper URL (after `keeperUrl` routing). */
622
+ coordinatorUrl: string;
623
+ /** Approves the keeper's final work for exactly this payment (the dual-sign `approveExecution`). */
624
+ approveExecution: KeeperExecutionApprover;
625
+ /** Erase the execution key from memory. */
626
+ dispose(): void;
627
+ }
628
+ /**
629
+ * Pay a final dual-control Sign without any presentation: no verifier-agent session and no
630
+ * credential grant follows, because a static-key dual-control quorum authorizes the work at the
631
+ * keeper. With `config.allowances` it is debited from an allowance lane and falls back
632
+ * to a per-operation reservation exactly as {@link paidOperation} does; the journal, the execution
633
+ * certificate and the keeper approvals are the ones paidOperation uses. Resume an interrupted one
634
+ * with {@link resumePaidFinalSign}.
635
+ * @param config - Paid operation configuration (its agent settings are not used).
636
+ * @param request - Slot, message, lifetime and cancellation.
637
+ */
638
+ export declare function paidFinalSign(config: PaidOperationConfig, request: PaidFinalSignRequest): Promise<PaidFinalSign>;
639
+ /**
640
+ * Resume a journaled final Sign ({@link paidFinalSign}) after an interruption: a `reserving` one is
641
+ * reconciled through the same debit or reservation path (never a second payment), then certified.
642
+ * @param config - The original configuration.
643
+ * @param requestId - The final Sign's request identity.
644
+ * @param signal - Cancellation.
645
+ */
646
+ export declare function resumePaidFinalSign(config: PaidOperationConfig, requestId: Hex, signal?: AbortSignal): Promise<PaidFinalSign>;
647
+ /** One session-grant KEM decrypt to pay: the slot and the exact recipient binding. */
648
+ export interface PaidSessionDecryptRequest {
649
+ /** KEM (BLS) slot named by the session grant. */
650
+ slot: Hex;
651
+ /** Recipient binding of this ciphertext ({@link decryptionBinding}); fixes the payload digest. */
652
+ decryption: DecryptionBindingWire;
653
+ /** Payment lifetime, 1..3600 seconds (default 600). */
654
+ ttlSecs?: number;
655
+ /** Cancellation (discovery, debit or reservation). */
656
+ signal?: AbortSignal;
657
+ /** Receive the request identity before anything is debited or reserved; a throw stops it. */
658
+ onRequestId?(requestId: Hex): void | Promise<void>;
659
+ /**
660
+ * The session grant this decrypt is served under (`GrantedSession.current()`). The payment then
661
+ * names THE GRANT'S verifier draw, as the keeper requires of every session item (any other draw
662
+ * is refused: "payment names another verifier draw than the session grant"). While the grant's
663
+ * epoch is the beacon's latest or previous it is paid there; past that a `PaidDrawMovedError`
664
+ * (`code: 'draw-moved'`) is thrown before anything is signed: refresh the grant first. Without
665
+ * it the payment takes the freshly discovered draw, which is the grant's only by chance.
666
+ */
667
+ grant?: {
668
+ epoch: number;
669
+ seed: string;
670
+ };
671
+ /**
672
+ * Sees the beacon's latest epoch the moment discovery reads it, before anything is signed
673
+ * (`GrantedSession.observeBeacon`: the grant's background refresh then starts while this
674
+ * payment is still being reserved). A throw is ignored.
675
+ */
676
+ onBeaconEpoch?(epoch: bigint): void;
677
+ }
678
+ /** A paid session-grant decrypt ready for the session partials client. */
679
+ export interface PaidSessionDecrypt {
680
+ /** Request identity. */
681
+ requestId: Hex;
682
+ /** The backed decrypt payment (with its debit voucher when allowance-backed). */
683
+ payment: PaymentIntentWire;
684
+ /** Approves each keeper's contribution for exactly this payment (kind `session-decrypt`). */
685
+ approveExecution: KeeperExecutionApprover;
686
+ /**
687
+ * Read ONE assigned contributor's retained partial for this decrypt after it answered that the item
688
+ * already ran (`409 recoverable` / `already claimed`): the paid-execution recovery route, which
689
+ * performs no new work and spends nothing. `nodeUrl` is the keeper URL the request went to (after
690
+ * `keeperUrl` routing). Returns the retained partial JSON for `decryptWithSessionGrant`'s `recover`.
691
+ */
692
+ recoverPartial(options: {
693
+ nodeUrl: string;
694
+ transport: KeeperRecoveryTransport;
695
+ signal?: AbortSignal;
696
+ }): Promise<unknown>;
697
+ /** Erase the execution key from memory. */
698
+ dispose(): void;
699
+ /**
700
+ * The beacon's latest epoch the payment's discovery observed (absent on a resume). Once it is past
701
+ * the grant's epoch, refresh the grant before the beacon moves again: a refresh continues ONE
702
+ * epoch; a skipped epoch needs a new presentation.
703
+ */
704
+ beaconEpoch?: bigint;
705
+ }
706
+ /**
707
+ * Pay one KEM decrypt that a session grant authorizes: no presentation and no
708
+ * verifier round, because the grant and the session-key proof authorize the keeper work. With
709
+ * `config.allowances` it is debited from an allowance lane and falls back to a per-operation
710
+ * reservation exactly as {@link paidOperation}; journal, certificate and keeper approvals are the
711
+ * ones every paid operation uses. Resume an interrupted one with {@link resumePaidSessionDecrypt}.
712
+ * @param config - Paid operation configuration (its agent settings are not used).
713
+ * @param request - Slot, recipient binding, lifetime and cancellation.
714
+ */
715
+ export declare function paidSessionDecrypt(config: PaidOperationConfig, request: PaidSessionDecryptRequest): Promise<PaidSessionDecrypt>;
716
+ /**
717
+ * Resume a journaled session-grant decrypt payment ({@link paidSessionDecrypt}): a `reserving`
718
+ * one is reconciled through the same debit or reservation path (never a second payment).
719
+ * @param config - The original configuration.
720
+ * @param requestId - The decrypt's request identity.
721
+ * @param signal - Cancellation.
722
+ */
723
+ export declare function resumePaidSessionDecrypt(config: PaidOperationConfig, requestId: Hex, signal?: AbortSignal): Promise<PaidSessionDecrypt>;
724
+ /**
725
+ * The journaled phase of a paid operation, or `undefined` when the store holds no record of it.
726
+ * @param store - Application store holding the operation journal.
727
+ * @param requestId - Payment request id of the operation.
728
+ */
729
+ export declare function paidOperationPhase(store: ApplicationStore, requestId: Hex): Promise<PaidOperationJournalPhase | undefined>;
730
+ /** One journaled paid operation, as listed by {@link listPaidOperations}. */
731
+ export interface PaidOperationSummary {
732
+ /** Reservation identity (lowercase). */
733
+ requestId: Hex;
734
+ /** Journaled phase. */
735
+ phase: PaidOperationJournalPhase;
736
+ /** Slot the operation runs on. */
737
+ slot: Hex;
738
+ /** Paid action (`eoa-sign` for a FROST sign on an EOA slot). */
739
+ action: PaymentIntentWire['action'];
740
+ /** Payment expiry, Unix seconds. */
741
+ expires: number;
742
+ /** Gas payer the journal recorded (absent from journals written before payers were recorded). */
743
+ payer?: Address;
744
+ /** Set for an abandoned operation: why and the phase it was abandoned from. */
745
+ abandoned?: {
746
+ reason: string;
747
+ at: number;
748
+ phase: Exclude<PaidOperationJournalPhase, 'abandoned'>;
749
+ };
750
+ }
751
+ /** Options for {@link listPaidOperations}. */
752
+ export interface ListPaidOperationsOptions {
753
+ /** Phase or phases to keep, e.g. `['reserving', 'executing']` for work needing attention. Naming `abandoned` includes abandoned operations. */
754
+ phase?: PaidOperationJournalPhase | readonly PaidOperationJournalPhase[];
755
+ /** Include abandoned operations (default false: they are closed and never need attention). */
756
+ includeAbandoned?: boolean;
757
+ /**
758
+ * Once per store, index journals written before the index existed. Needs a store that can
759
+ * list its keys (`list`); the built-in memory, file and IndexedDB stores can.
760
+ */
761
+ backfill?: boolean;
762
+ }
763
+ /**
764
+ * List the paid operations journaled in a store, oldest first, without relying on its key scheme.
765
+ * Abandoned operations are left out unless asked for. Operations journaled before this index
766
+ * existed are listed only after a one-time `backfill`; otherwise read them with `paidOperationPhase`.
767
+ * @param store Store the operations were journaled in.
768
+ * @param filter Phases to keep, whether to include abandoned operations, and the one-time backfill.
769
+ */
770
+ export declare function listPaidOperations(store: ApplicationStore, filter?: ListPaidOperationsOptions): Promise<PaidOperationSummary[]>;
771
+ /** {@link abandonPaidOperation} refused: something could still land under this operation. */
772
+ export declare class PaidOperationAbandonRefusedError extends TasraError {
773
+ /** Reservation identity. */ readonly requestId: Hex;
774
+ /** Journaled phase that blocks abandoning. */ readonly phase: PaidOperationJournalPhase;
775
+ /** Unix seconds from which abandoning succeeds (payment expiry plus a skew margin), when time alone unblocks it. */ readonly notBefore?: number | undefined;
776
+ constructor(
777
+ /** Reservation identity. */ requestId: Hex,
778
+ /** Journaled phase that blocks abandoning. */ phase: PaidOperationJournalPhase,
779
+ /** Why it cannot be abandoned yet; safe to log. */ reason: string,
780
+ /** Unix seconds from which abandoning succeeds (payment expiry plus a skew margin), when time alone unblocks it. */ notBefore?: number | undefined);
781
+ }
782
+ /** Options for {@link abandonPaidOperation}. */
783
+ export interface AbandonPaidOperationOptions {
784
+ /** Why the application closes the operation (1..512 characters); journaled and listed. */
785
+ reason: string;
786
+ }
787
+ /** Result of {@link abandonPaidOperation}. */
788
+ export interface AbandonedPaidOperation {
789
+ /** Reservation identity (lowercase). */
790
+ requestId: Hex;
791
+ /** Phase the operation was abandoned from. */
792
+ from: Exclude<PaidOperationJournalPhase, 'abandoned'>;
793
+ /** Journaled reason. */
794
+ reason: string;
795
+ /** When it was abandoned, Unix seconds. */
796
+ at: number;
797
+ }
798
+ /**
799
+ * Close a paid operation for good, only when nothing can still land under it: no reservation,
800
+ * session write or keeper work can still be accepted. The journal is kept (phase `abandoned`),
801
+ * left out of {@link listPaidOperations} by default and refused by {@link resumePaidOperation}.
802
+ * Abandoning an already abandoned operation returns its original record.
803
+ *
804
+ * Allowed when the journal proves it:
805
+ * - `reserving` with no reservation ever prepared, once the payment has expired plus the quote
806
+ * window (MAX_QUOTE_AGE, 30 s) and the skew margin: until then the signed intent the accountants
807
+ * saw could still be reserved by whoever holds it;
808
+ * - `failed` (the reservation provably never happened);
809
+ * - `executed` (completed and recorded);
810
+ * - `reserved`, `certified`, `authorized` or `executing` once the creator-signed payment has
811
+ * expired (plus a skew margin): keepers, verifiers and the agent refuse it from then on.
812
+ * Retained results of an `executing` operation stay readable with {@link recoverPaidOperation}.
813
+ *
814
+ * Refused (PaidOperationAbandonRefusedError) otherwise. A `reserving` operation whose
815
+ * reservation was prepared must first be settled by {@link reconcilePaidOperation} (it becomes
816
+ * `failed` or `reserved`), which also releases the gas payer.
817
+ * @param store Store the operation was journaled in.
818
+ * @param requestId Reservation identity.
819
+ * @param options Reason to journal.
820
+ */
821
+ export declare function abandonPaidOperation(store: ApplicationStore, requestId: Hex, options: AbandonPaidOperationOptions): Promise<AbandonedPaidOperation>;