@t3foundry/tasra-sdk 0.3.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,383 @@
1
+ import { type Address, type Hex, type PublicClient } from 'viem';
2
+ import { type PaymentIntentWire } from '../committee/payment.js';
3
+ import type { ExecutionConsentPolicy } from '../committee/execution.js';
4
+ import { type ExecutionRecoveryTarget, type SignedPaidExecutionReport } from '../committee/recovery.js';
5
+ import { type PaidPacingClock } from './paidPacing.js';
6
+ /** Deployment independently selected by the application, not taken from a received intent. */
7
+ export interface PrepaidDeployment {
8
+ /** Expected EVM chain ID. */
9
+ chainId: number;
10
+ /** Expected Settlement proxy. */
11
+ settlement: Address;
12
+ /** Expected KeyRegistry proxy. */
13
+ keyRegistry: Address;
14
+ }
15
+ /** Fresh canonical observation shared by every field in a funding or reservation result. */
16
+ export interface PrepaidObservation {
17
+ /** Canonical block number. */
18
+ blockNumber: bigint;
19
+ /** Exact canonical block used for EIP-1898 calls. */
20
+ blockHash: Hex;
21
+ /** Block timestamp in Unix seconds. */
22
+ blockTimestamp: bigint;
23
+ }
24
+ /** Slot TASRA balances at a single canonical block; this does not grant paid admission. */
25
+ export interface SlotFunding extends PrepaidObservation {
26
+ /** Slot identifier. */
27
+ slot: Hex;
28
+ /** Whether the slot has prepaid mode enabled. */
29
+ enabled: boolean;
30
+ /** Unreserved TASRA base units. */
31
+ available: bigint;
32
+ /** TASRA base units held by unsettled reservations. */
33
+ reserved: bigint;
34
+ /** Available plus reserved TASRA base units. */
35
+ total: bigint;
36
+ /** `'1'` when read from a legacy Settlement (no prepaid getters: `enabled` false, `reserved` 0). Absent on a prepaid deployment. */
37
+ settlementVersion?: '1';
38
+ }
39
+ /** Chain backing for one operation; holder authorization and execution journals remain separate. */
40
+ export interface PaidOperationReceipt extends PrepaidObservation {
41
+ /** Reservation identity derived locally from the payment intent. */
42
+ requestId: Hex;
43
+ /** Original quoted assignment block committed by the reservation quorum. */
44
+ assignmentBlock: Hex;
45
+ /** Original reserved TASRA base units, retained after settlement. */
46
+ cost: bigint;
47
+ /** Whether final settlement has completed. This is not permission to execute again. */
48
+ settled: boolean;
49
+ /** TASRA base units refunded to this slot during reconciliation. */
50
+ refunded: bigint;
51
+ }
52
+ /** Explicit expected operation, independent of the supplied payment. */
53
+ export interface ExpectedPaidOperation {
54
+ /** Intended slot identifier. */
55
+ slot: Hex;
56
+ /** Intended final key operation. */
57
+ action: PaymentIntentWire['action'];
58
+ /** Independently derived exact operation payload digest. */
59
+ payloadDigest: Hex;
60
+ }
61
+ /** Approved contracts and default verifier policy for client-side execution consent. */
62
+ export interface ClientExecutionDeployment extends PrepaidDeployment {
63
+ /** Independently approved anchored verifier registry. */
64
+ verifierSet: Address;
65
+ /** Independently approved randomness beacon. */
66
+ beacon: Address;
67
+ /** Explicit deployment default, used only when the slot's on-chain policy is zero. */
68
+ defaultVerificationPolicy?: {
69
+ committee: number;
70
+ quorum: number;
71
+ };
72
+ }
73
+ /** An anchored drawn verifier identity, supplied with its inclusion proof. */
74
+ export interface PaidVerifierWitness {
75
+ /** Snapshot index; the SDK independently recomputes the draw. */
76
+ index: number;
77
+ /** Registered operator account. */
78
+ operator: Address;
79
+ /** Ed25519 key anchored at the payment's verification epoch. */
80
+ publicKey: Hex;
81
+ /** Sorted-pair Merkle inclusion path. */
82
+ proof: Hex[];
83
+ }
84
+ /** Fresh canonical payment and verifier-policy observation before a client signature. */
85
+ export interface ClientExecutionObservation extends PrepaidObservation {
86
+ /** Exact independently read creator, deployment, reserved cost and current time. */
87
+ policy: ExecutionConsentPolicy;
88
+ }
89
+ /**
90
+ * Read canonical mined credit, creator, beacon and verifier policy before approving work.
91
+ * All registry calls use the receipt's EIP-1898 block hash; no latest/number fallback.
92
+ * The paid verification epoch alone is judged at the reservation's stored quote block
93
+ * (`prepaidAssignmentBlock`, EIP-1898 `requireCanonical` plus a by-number recheck): it must be
94
+ * that block's `{epoch, epoch - 1}`. An unreadable quote block or state rejects with a retryable
95
+ * `PaidEpochError` (`paid_epoch_unavailable`), never an admission or a live-head fallback; a
96
+ * reorganised quote block or out-of-window epoch is a definite `paid_epoch_refused`.
97
+ * A target additionally proves drawn membership and current registered verifier standing.
98
+ * @param client Trusted RPC client for the independently selected deployment.
99
+ * @param deployment Approved contracts and explicit default verification policy.
100
+ * @param payment Original locally retained creator intent, never copied from a proposal.
101
+ * @param expected Application-selected slot, action and payload digest.
102
+ * @param target Optional drawn verifier whose work is about to be approved.
103
+ */
104
+ export declare function readClientExecutionPolicy(client: PublicClient, deployment: ClientExecutionDeployment, payment: PaymentIntentWire, expected: ExpectedPaidOperation, target?: PaidVerifierWitness): Promise<ClientExecutionObservation>;
105
+ /** Currently eligible registered keeper selected in the creator's paid assignment. */
106
+ export interface PaidKeeperEndpoint {
107
+ /** Registered payout/operator address. */
108
+ operator: Address;
109
+ /** Registered Ed25519 key. */
110
+ publicKey: Hex;
111
+ /** Exact registered HTTP(S) base URL, checked against the selected transport policy. */
112
+ url: string;
113
+ }
114
+ /** The single coordinator and contributor set selected by the creator's paid assignment. */
115
+ export interface PaidKeeperTarget extends PaidKeeperEndpoint {
116
+ /** Chain-backed reservation observation; never substitutes for holder authorization. */
117
+ receipt: PaidOperationReceipt;
118
+ /** Exact signed contributor set, for operations that request individual shares. */
119
+ contributors: PaidKeeperEndpoint[];
120
+ /** Published slot group key for independently checking the operation result. */
121
+ groupPublicKey: Hex;
122
+ /** Solidity KeyRegistry mode ordinal for selecting the matching key-operation client. */
123
+ mode: number;
124
+ }
125
+ /** Explicit transport allowance for a development chain. HTTPS is otherwise required. */
126
+ export interface PaidKeeperTransportOptions {
127
+ /** Allow an HTTP coordinator only on local chain43112. Never enables HTTP on Fuji. */
128
+ allowLocalHttp?: boolean;
129
+ }
130
+ /** Original canonical keeper admission authenticated for a completed-result read. */
131
+ export interface KeeperExecutionRecoveryObservation extends PrepaidObservation {
132
+ /** Financial policy evaluated at the original accepted time, never used to admit fresh work. */
133
+ policy: ExecutionConsentPolicy;
134
+ /** Eligible assigned keeper and endpoint read at the original canonical block. */
135
+ keeper: PaidKeeperEndpoint;
136
+ /** Original slot group key, for checking the recovered cryptographic result independently. */
137
+ groupPublicKey: Hex;
138
+ /** Original slot mode. */
139
+ mode: number;
140
+ }
141
+ /**
142
+ * Authenticate completed keeper evidence using canonical original creator, fee and roster reads.
143
+ * Every contract call uses the report's original EIP-1898 hash with requireCanonical; missing
144
+ * history fails closed. Current expiry, ownership or payout never replaces the original state.
145
+ * This performs no transaction, keeper request or fresh work admission.
146
+ * @param client Trusted bounded RPC client for the independently approved deployment.
147
+ * @param deployment Approved chain and contracts, never taken from a received report.
148
+ * @param payment Original creator payment retained before the operation.
149
+ * @param expected Independently intended slot, action and digest.
150
+ * @param target Original client key and independently selected assigned keeper stage/key.
151
+ * @param execution Untrusted public completed evidence, authenticated against the same history.
152
+ * @param transport Explicit local HTTP allowance for the historical registered endpoint.
153
+ */
154
+ export declare function readKeeperExecutionRecoveryPolicy(client: PublicClient, deployment: PrepaidDeployment, payment: PaymentIntentWire, expected: ExpectedPaidOperation, target: ExecutionRecoveryTarget, execution: SignedPaidExecutionReport, transport?: PaidKeeperTransportOptions): Promise<KeeperExecutionRecoveryObservation>;
155
+ /** Independently approved deployment used to discover a payment before creator signing. */
156
+ export interface PaidContextDeployment extends PrepaidDeployment {
157
+ /** Expected anchored verifier-set registry. */
158
+ verifierSet: Address;
159
+ /** Expected accountant snapshot registry used by reservation approval. */
160
+ accountantSet: Address;
161
+ /** Expected threshold beacon, also checked through registry pointers. */
162
+ beacon: Address;
163
+ }
164
+ /** Explicit application policy for selecting currently eligible paid workers. */
165
+ /**
166
+ * How long discovery waits for an admissible complete epoch. The accountants anchor a new epoch's
167
+ * verifier and accountant snapshots seconds after they push its seed (6-8 s in the local fleet,
168
+ * where epochs are 8-10 s apart), and keepers accept only the latest or the previous epoch: until
169
+ * both anchors land, no epoch is both admissible and complete. That is the protocol's timing, not a
170
+ * refusal, so discovery observes again instead of failing (2026-10-31: a one-shot discovery lost a
171
+ * certification row to that two-second window).
172
+ */
173
+ export interface PaidAnchorWait {
174
+ /** Longest total wait in ms; 0 keeps the single observation. Default 20 000, at most 120 000. */
175
+ timeoutMs?: number;
176
+ /** Pause between observations in ms. Default 1 000, within 100..10 000. */
177
+ pollMs?: number;
178
+ /** Time source; the system clock by default. Inject one in tests. */
179
+ clock?: PaidPacingClock;
180
+ }
181
+ /** Options for opening a paid operation context: the keeper transport, an optional requested coordinator and the bounded anchor wait. */
182
+ export interface PaidContextOptions extends PaidKeeperTransportOptions {
183
+ /** Requested registered coordinator; otherwise a uniform draw among eligible keepers. Retain the returned context for reservation and recovery. */
184
+ coordinator?: Address;
185
+ /** Bounded wait for an admissible complete epoch; see {@link PaidAnchorWait}. */
186
+ anchorWait?: PaidAnchorWait;
187
+ /** Independently approved deployed verifier defaults; required only for a zero slot override. */
188
+ defaultVerificationPolicy?: {
189
+ committee: number;
190
+ quorum: number;
191
+ };
192
+ /**
193
+ * Prepaid allowances: the operation may be funded by an already reserved allowance, so an activated slot
194
+ * whose whole balance is escrowed (`balanceOf` 0) is not refused here. Activation is still required;
195
+ * a per-operation reservation from such a slot is refused by the accountants (402).
196
+ */
197
+ fundedByAllowance?: boolean;
198
+ /**
199
+ * Session grants: draw on THIS verifier epoch (a session grant's), never a newer one. Every message
200
+ * of a session pays the grant's draw (the keeper refuses any other), and a grant is admitted only
201
+ * while its epoch is the beacon's latest or the one before; past that a typed
202
+ * {@link PaidDrawMovedError} is thrown before anything is signed (refresh the grant first).
203
+ */
204
+ verificationEpoch?: bigint;
205
+ /**
206
+ * Prepaid allowances: while a new epoch's anchors land (no admissible complete verifier draw at the
207
+ * observed head, see {@link PaidAnchorWait}), return at once a context marked
208
+ * {@link PaidOperationContext.undrawn} instead of waiting. Only for a caller that will fund the
209
+ * operation from an EXISTING allowance, whose payment names the allowance's own draw (judged at
210
+ * the allowance's quote block, not at this head): its keeper sharing, creator, mode and rule
211
+ * commitment are read as usual. Requires `fundedByAllowance`; ignored with `verificationEpoch`.
212
+ */
213
+ undrawnDuringAnchorGap?: boolean;
214
+ }
215
+ /**
216
+ * The pinned verifier epoch ({@link PaidContextOptions.verificationEpoch}) is no longer the beacon's
217
+ * latest or previous epoch. Nothing was signed or reserved: refresh the session grant (or present
218
+ * again) and discover anew.
219
+ */
220
+ export declare class PaidDrawMovedError extends Error {
221
+ /** The pinned verifier epoch. */
222
+ readonly pinnedEpoch: bigint;
223
+ /** The beacon's latest epoch as read. */
224
+ readonly beaconEpoch: bigint;
225
+ /** Stable reason. */
226
+ readonly code: "draw-moved";
227
+ constructor(
228
+ /** The pinned verifier epoch. */
229
+ pinnedEpoch: bigint,
230
+ /** The beacon's latest epoch as read. */
231
+ beaconEpoch: bigint);
232
+ }
233
+ /** Chain-derived fields safe to copy into the creator's independently bounded payment intent. */
234
+ export type DiscoveredPaymentFields = Pick<PaymentIntentWire, 'chain_id' | 'settlement' | 'key_registry' | 'slot' | 'verification_epoch' | 'verification_seed' | 'verification_root' | 'verification_registry_size' | 'verification_committee' | 'verification_quorum' | 'keeper_assignment'>;
235
+ /** The verifier-draw fields of {@link DiscoveredPaymentFields}: present only on a drawn context. */
236
+ export type PaymentDrawFieldName = 'verification_epoch' | 'verification_seed' | 'verification_root' | 'verification_registry_size' | 'verification_committee' | 'verification_quorum';
237
+ /**
238
+ * The chain and keeper-sharing fields of an UNDRAWN context: no verifier draw at all, so they can
239
+ * never complete a payment intent (a per-operation intent or an allowance needs the draw fields).
240
+ */
241
+ export type UndrawnPaymentFields = Omit<DiscoveredPaymentFields, PaymentDrawFieldName>;
242
+ interface PaidOperationContextBase extends PrepaidObservation {
243
+ /** On-chain slot creator whose EIP-712 signature authorizes spending. */
244
+ creator: Address;
245
+ /** Slot mode ordinal for selecting the operation client. */
246
+ mode: number;
247
+ /** Published group key, independently verified again during execution. */
248
+ groupPublicKey: Hex;
249
+ /** Selected eligible keeper coordinator. */
250
+ coordinator: PaidKeeperEndpoint;
251
+ /** All currently eligible assigned contributors in canonical public-key order. */
252
+ contributors: PaidKeeperEndpoint[];
253
+ /** Unreserved slot TASRA at this block; it is not a reservation or an operation quote. */
254
+ available: bigint;
255
+ /** The slot's salted rule commitment at this block, from the same canonical slot read. */
256
+ ruleCommitment?: Hex;
257
+ /** The slot's rule version at this block, from the same canonical slot read. */
258
+ ruleVersion?: number;
259
+ /** The beacon's latest epoch at this block (the draw is it or, while its anchors land, the one before). */
260
+ beaconEpoch?: bigint;
261
+ }
262
+ /** A context on an admissible complete verifier draw: the only kind a payment intent is built from. */
263
+ export interface DrawnPaidOperationContext extends PaidOperationContextBase {
264
+ /** Chain and assignment fields; add the exact action/digest, cap, nonce, expiry and session commitment before signing. */
265
+ intentFields: DiscoveredPaymentFields;
266
+ /** Never set on a drawn context. */
267
+ undrawn?: undefined;
268
+ }
269
+ /**
270
+ * Returned only with {@link PaidContextOptions.undrawnDuringAnchorGap}: this block has no admissible
271
+ * complete verifier draw, so `intentFields` carries NO verification fields. Such a context may
272
+ * select an existing allowance (which carries its own draw); it never signs a per-operation payment
273
+ * and never reserves an allowance. Discover again (with the bounded anchor wait) for anything else.
274
+ */
275
+ export interface UndrawnPaidOperationContext extends PaidOperationContextBase {
276
+ /** Chain and keeper-sharing fields only; no verifier draw. */
277
+ intentFields: UndrawnPaymentFields;
278
+ /** Always set: this context has no verifier draw. */
279
+ undrawn: true;
280
+ }
281
+ /** One canonical pre-signing observation; later reservation and execution must revalidate it. Narrow on `undrawn` before reading draw fields. */
282
+ export type PaidOperationContext = DrawnPaidOperationContext | UndrawnPaidOperationContext;
283
+ /**
284
+ * The context's intent fields, refused for an undrawn context: the one path from a context to a
285
+ * payment intent. Throws rather than ever returning zero or missing draw fields.
286
+ */
287
+ export declare function drawnIntentFields(context: PaidOperationContext): DiscoveredPaymentFields;
288
+ /**
289
+ * The beacon's current epoch at a fresh observed head (the followed tip when live, else `latest`),
290
+ * through the same block-pinned read discovery uses. Performs no transaction.
291
+ * @param client - Trusted bounded Viem RPC client for the selected deployment.
292
+ * @param deployment - Independently approved chain and contract addresses, the beacon included.
293
+ * @param options - `fresh`: read at an RPC `latest` head of its own, never a followed tip. For a
294
+ * decision a tip lagging the chain would get wrong (confirming that a grant left the window: a
295
+ * keeper judged it at a newer head; C21, two beacon pushes in a second).
296
+ */
297
+ export declare function readCurrentBeaconEpoch(client: PublicClient, deployment: PaidContextDeployment, options?: {
298
+ fresh?: boolean;
299
+ }): Promise<bigint>;
300
+ /** The beacon's latest epoch and the newest epoch a session grant can be drawn on now. */
301
+ export interface BeaconDrawState {
302
+ /** The beacon's latest epoch. */
303
+ latest: bigint;
304
+ /**
305
+ * `latest` once its verifier-set snapshot is anchored, else `latest - 1` when that one is, else
306
+ * absent: the epoch the verifier-agent draws a new grant (or a session continuation) on, as the
307
+ * agent picks it (`pick_draw_epoch`). A refresh before it moves past a grant's epoch can only
308
+ * re-sign the grant on its own epoch.
309
+ */
310
+ draw?: bigint;
311
+ }
312
+ /**
313
+ * The beacon's latest epoch and its draw epoch ({@link BeaconDrawState}) at ONE fresh observed head
314
+ * (the followed tip when live, else `latest`), through the block-pinned reads discovery uses. The
315
+ * previous epoch's snapshot is read only while the latest one is not anchored. Performs no transaction.
316
+ * @param client - Trusted bounded Viem RPC client for the selected deployment.
317
+ * @param deployment - Independently approved chain and contract addresses, the beacon and verifier set included.
318
+ */
319
+ export declare function readBeaconDrawState(client: PublicClient, deployment: PaidContextDeployment): Promise<BeaconDrawState>;
320
+ /**
321
+ * Read available, reserved and total slot TASRA at one fresh canonical block. Performs no transaction.
322
+ * @param client - Trusted bounded Viem RPC client for the selected deployment.
323
+ * @param deployment - Independently approved chain and contract addresses.
324
+ * @param slot - Slot whose TASRA balances are required.
325
+ */
326
+ export declare function readSlotFunding(client: PublicClient, deployment: PrepaidDeployment, slot: Hex): Promise<SlotFunding>;
327
+ /**
328
+ * Require mined backing for an independently selected operation, without spending or performing it.
329
+ * A completed reservation remains inspectable. This result never authorizes another execution;
330
+ * the keeper must independently verify the holder, current assignment and durable operation journal.
331
+ * @param client - Trusted bounded Viem RPC client for the selected deployment.
332
+ * @param deployment - Independently approved chain and contract addresses.
333
+ * @param payment - Fixed creator-signed intent for the existing reservation.
334
+ * @param expected - Slot, action and digest derived from the operation the application intends.
335
+ * @param options - `atLeastBlock`: a block the caller saw its own transaction mined in; an older
336
+ * followed tip is not used (it cannot show that transaction), the RPC head is read instead.
337
+ */
338
+ export declare function readPaidOperationReceipt(client: PublicClient, deployment: PrepaidDeployment, payment: PaymentIntentWire, expected: ExpectedPaidOperation, options?: {
339
+ atLeastBlock?: bigint;
340
+ }): Promise<PaidOperationReceipt>;
341
+ /**
342
+ * Pre-read one in-flight paid operation's own settlement state (its request's cost, settlement,
343
+ * refund and assignment block; for an allowance-backed one also the allowance record) at every
344
+ * new followed head until the payment expires, so the receipt, client policy and keeper target
345
+ * checks at that head find it cached. Without a head follower this does nothing.
346
+ * @param client Trusted client with a head follower attached.
347
+ * @param deployment Approved deployment.
348
+ * @param payment The operation's creator-signed intent.
349
+ */
350
+ export declare function followPaidRequest(client: PublicClient, deployment: PrepaidDeployment & Partial<Pick<ClientExecutionDeployment, 'beacon' | 'verifierSet'>>, payment: PaymentIntentWire): void;
351
+ /**
352
+ * Resolve only the signed coordinator after checking mined backing, creator consent and current sharing.
353
+ * Does not contact any keeper, submit a transaction, mint a credential grant or execute work.
354
+ * @param client - Trusted bounded Viem RPC client for the selected deployment.
355
+ * @param deployment - Independently approved chain and contract addresses.
356
+ * @param payment - Creator-signed intent for the existing reservation.
357
+ * @param expected - Independently derived slot, action and exact payload digest.
358
+ * @param transport - Explicit local HTTP allowance; defaults to HTTPS only.
359
+ */
360
+ export declare function resolvePaidKeeperTarget(client: PublicClient, deployment: PrepaidDeployment, payment: PaymentIntentWire, expected: ExpectedPaidOperation, transport?: PaidKeeperTransportOptions): Promise<PaidKeeperTarget>;
361
+ /**
362
+ * Discover keeper sharing and verifier policy from one fresh canonical block before creating an intent.
363
+ * Selects the current epoch with both verifier and accountant snapshots, otherwise its immediate predecessor.
364
+ * Performs no signing, reservation, service contact or gas/TASRA mutation.
365
+ * @param client - Trusted bounded Viem client supporting EIP-1898 canonical reads.
366
+ * @param deployment - Independently approved contract and beacon addresses.
367
+ * @param slotId - Independently selected slot to fund and operate.
368
+ * @param options - Approved default verifier policy, optional coordinator and transport policy.
369
+ * @returns A {@link DrawnPaidOperationContext}, unless `undrawnDuringAnchorGap` is set: then possibly an {@link UndrawnPaidOperationContext}.
370
+ */
371
+ export declare function discoverPaidOperationContext(client: PublicClient, deployment: PaidContextDeployment, slotId: Hex, options?: PaidContextOptions & {
372
+ undrawnDuringAnchorGap?: false;
373
+ }): Promise<DrawnPaidOperationContext>;
374
+ /**
375
+ * As above, with {@link PaidContextOptions.undrawnDuringAnchorGap} possibly set: the result may be an
376
+ * {@link UndrawnPaidOperationContext} (narrow on `undrawn` before building any payment intent).
377
+ * @param client - Trusted bounded Viem client supporting EIP-1898 canonical reads.
378
+ * @param deployment - Independently approved contract and beacon addresses.
379
+ * @param slotId - Independently selected slot to fund and operate.
380
+ * @param options - Approved default verifier policy, optional coordinator, transport policy and the anchor-gap opt-in.
381
+ */
382
+ export declare function discoverPaidOperationContext(client: PublicClient, deployment: PaidContextDeployment, slotId: Hex, options?: PaidContextOptions): Promise<PaidOperationContext>;
383
+ export {};