@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
@@ -3,6 +3,8 @@ import { presentationOperationTypedData, verifierAgentResult } from '../oid4vp/v
3
3
  import { decodeJson } from '../oid4vp/jose.js';
4
4
  import { derivedNonce, requestHash } from '../oid4vp/binding.js';
5
5
  import { VerifierAgentSessionError, nextPollDelay } from '../verifier-agent/index.js';
6
+ import { assertPaymentIntentWire, paymentIntentHash } from '../committee/payment.js';
7
+ import { sessionPaymentFields } from '../verifier-agent/payment.js';
6
8
  /**
7
9
  * Sign once, authenticate an explicitly approved provider, and retain its pinned poll closure.
8
10
  * @param client Registered agent client with independently approved providers.
@@ -11,12 +13,14 @@ import { VerifierAgentSessionError, nextPollDelay } from '../verifier-agent/inde
11
13
  export async function openRegisteredVerifierAgentSession(client, opts) {
12
14
  opts.signal?.throwIfAborted();
13
15
  const { typedData, operation, messageHex, payloadDigest } = presentationOperationTypedData(opts);
16
+ const payment = opts.payment && structuredClone(opts.payment), random = opts.random;
17
+ sessionPaymentFields({ operation, operationSig: '', messageHex, payment, random });
18
+ const expectedHash = requestHash(operation.chain_id, hexToBytes(operation.slot_id), opts.action, payloadDigest);
14
19
  const operationSig = await opts.signer.signTypedData(typedData);
15
20
  opts.signal?.throwIfAborted();
16
- const session = await client.createSession({ operation, operationSig, messageHex, delegation: opts.delegation }, { profileIndex: opts.profileIndex, signal: opts.signal });
17
- const slot = typeof opts.slotId === 'string' ? hexToBytes(opts.slotId) : opts.slotId;
18
- const expectedHash = requestHash(opts.chainId, slot, opts.action, payloadDigest);
21
+ const session = await client.createSession({ operation, operationSig, messageHex, delegation: opts.delegation, payment, random }, { profileIndex: opts.profileIndex, signal: opts.signal });
19
22
  return Object.freeze({ ...session, operation: Object.freeze(operation), verifierAgentUrl: session.profile.endpoint,
23
+ get payment() { return session.payment; },
20
24
  get requestHash() { return expectedHash.slice(); },
21
25
  });
22
26
  }
@@ -103,6 +107,17 @@ export function assertRegisteredWalletRequest(session, ro, status) {
103
107
  registrySize: integer('registry_size'), committee: integer('committee_count'), quorum: integer('quorum'), operationExp: op.exp });
104
108
  if (claims.nonce !== expected || binding.nonce !== expected)
105
109
  throw new Error('Wallet nonce does not bind the opened operation');
110
+ const payment = session.payment;
111
+ if (payment) {
112
+ assertPaymentIntentWire(binding.payment);
113
+ if (paymentIntentHash(binding.payment).toLowerCase() !== session.paymentHash?.toLowerCase()
114
+ || String(binding.random).toLowerCase() !== session.random?.toLowerCase() || integer('epoch') !== payment.verification_epoch
115
+ || String(binding.seed).toLowerCase() !== payment.verification_seed.toLowerCase()
116
+ || String(binding.snapshot_root).toLowerCase() !== payment.verification_root.toLowerCase()
117
+ || integer('registry_size') !== payment.verification_registry_size || integer('committee_count') !== payment.verification_committee
118
+ || integer('quorum') !== payment.verification_quorum || op.exp !== payment.expires)
119
+ throw new Error('Wallet nonce context differs from the reserved payment');
120
+ }
106
121
  if (!Number.isSafeInteger(claims.exp) || Number(claims.exp) > op.exp || Number(claims.exp) < Math.floor(Date.now() / 1000))
107
122
  throw new Error('Wallet request expiry exceeds its authorization');
108
123
  // VERIFY WHEN PRESENT - DO not REQUIRE. Requiring it made this wallet the only one that
@@ -0,0 +1,254 @@
1
+ import { type DpopSigner } from '../auth/dpop.js';
2
+ import { type Hex } from 'viem';
3
+ import { type ClientExecutionSigner, type ExecutionCertificate, type ExecutionProposal, type SessionInitialization } from '../committee/execution.js';
4
+ import { type PaymentIntentWire } from '../committee/payment.js';
5
+ import { type SessionGrantRequestWire, type SessionGrantWire } from '../committee/session-grant.js';
6
+ import { type VerifiedRequestObject } from '../oid4vp/request-object.js';
7
+ import { type CreateSessionParams, type SessionStatusResult } from '../verifier-agent/index.js';
8
+ import type { TasraChainClient } from './client.js';
9
+ import type { ApprovedAgentProfile } from './registeredAgent.js';
10
+ import { type ClientExecutionDeployment, type PaidVerifierWitness } from './prepaid.js';
11
+ import type { PaidAgentTransport } from './paidAgentTransport.js';
12
+ import { type PaidPacingClock } from './paidPacing.js';
13
+ /**
14
+ * Pacing of a paid session's definite 429/503 refusals. Repeatable reads (proposals, Request
15
+ * Object, presentations, session poll, approval state) and the continuation POST (429 only) are
16
+ * repeated inside the session's signed expiry; the creation POST (429/503, the agent refuses
17
+ * both before any session exists) inside the payment's own remaining window, with the identical
18
+ * body; nothing else is.
19
+ */
20
+ export interface PaidPacingOptions {
21
+ /** Time source; wall-clock ms. Default: the system clock. */
22
+ clock?: PaidPacingClock;
23
+ /**
24
+ * Longest one attempt may take (provider check plus HTTP), 1000..60000 ms (default 60000). Each
25
+ * attempt is cut off at this bound, and a repeated attempt starts only with this much time left.
26
+ */
27
+ attemptBudgetMs?: number;
28
+ }
29
+ /** A signed approval retained BEFORE its first send; every send uses exactly `body`. */
30
+ export interface RetainedPaidApproval {
31
+ /** Agent delivery (proposal) identity. */
32
+ proposalId: string;
33
+ /** Exact JSON request body `{"authorization":…}`; never re-serialized or re-signed. */
34
+ body: string;
35
+ /** Unix seconds after which the approval may not be sent (proposal and session expiry). */
36
+ expires: number;
37
+ }
38
+ /**
39
+ * Answer to one batch of retained approvals (`POST /v1/sessions/{id}/execution/approve`):
40
+ * `busy` when the whole request was refused before processing (HTTP 429/503), otherwise the
41
+ * per-delivery HTTP status the agent decided (204 accepted; 404, 409, 410 or 422 refused).
42
+ */
43
+ export type PaidApprovalBatchReply = {
44
+ /** The whole batch was refused before processing. */
45
+ kind: 'busy';
46
+ /** Observed status. */
47
+ httpStatus: 429 | 503;
48
+ /** Strict server hint, in ms. */
49
+ hintMs?: number;
50
+ } | {
51
+ /** The agent decided each delivery. */
52
+ kind: 'results';
53
+ /** HTTP status per delivery. */
54
+ results: ReadonlyMap<string, 204 | 404 | 409 | 410 | 422>;
55
+ };
56
+ /** Manifest capability of an agent that accepts a batch of approvals in one request. */
57
+ export declare const BATCH_APPROVAL_CAPABILITY = "execution-approve-batch";
58
+ /** Manifest capability of an agent that holds a proposal listing until one is pending (`?wait_ms=`). */
59
+ export declare const PROPOSAL_WAIT_CAPABILITY = "execution-wait";
60
+ /** Longest proposal hold the client asks for (the agent's own cap). */
61
+ export declare const MAX_PROPOSAL_WAIT_MS = 25000;
62
+ /** Outcome of one send of a retained approval. Any other answer throws {@link PaidAgentControlError}. */
63
+ export interface PaidApprovalDelivery {
64
+ /** `accepted`: HTTP 204, the agent accepted the approval. `busy`: HTTP 429/503, definitely refused before processing. */
65
+ status: 'accepted' | 'busy';
66
+ /** Observed status of a `busy` answer. */
67
+ httpStatus?: 429 | 503;
68
+ /** Strict server hint of a `busy` answer, in ms. */
69
+ hintMs?: number;
70
+ }
71
+ /** Client-built original operation and reserved intent. No provider fallback is permitted. */
72
+ export interface PaidAgentSessionParams extends CreateSessionParams {
73
+ /** Original creator-signed reserved TASRA intent. */
74
+ payment: PaymentIntentWire;
75
+ /** Original presentation random committed before reservation. */
76
+ random: string;
77
+ /** Credential adapter; omitted means wallet. */
78
+ kind?: 'wallet' | 'oauth';
79
+ /**
80
+ * Session mode (KEM `decrypt` only): also open a session grant for this FRESH public
81
+ * session key. The presentation nonce then binds the key's RFC 7638 thumbprint
82
+ * (`vp-session-nonce/v1`), and every nonce this session checks is that one.
83
+ */
84
+ sessionGrant?: SessionGrantRequestWire;
85
+ }
86
+ /** What a completed session-mode presentation returned beside its compound token. */
87
+ export interface PaidSessionGrantOutcome {
88
+ /** The quorum-signed grant, already verified against the anchored draw; `refresh_seq` 0. */
89
+ grant?: {
90
+ session_grant: SessionGrantWire;
91
+ refresh_seq: 0;
92
+ };
93
+ /** Why no grant came with the token (an agent `session_*` code, or `sdk_grant_invalid`). */
94
+ error?: string;
95
+ }
96
+ /** Complete presentation explicitly accepted by the client before verifier work. */
97
+ export interface ClientApprovedPresentation {
98
+ /** Holder hint; the committee still authenticates it. */
99
+ holder: string;
100
+ /** Every compact wallet credential, or an empty array for OAuth. */
101
+ credentials: string[];
102
+ /** Original holder proof, if applicable. */
103
+ holder_proof: string | null;
104
+ /** Original OAuth artifacts, if this session uses OAuth. */
105
+ oauth: {
106
+ access_token: string;
107
+ dpop_proof: string;
108
+ session_id: string;
109
+ } | null;
110
+ /** Original holder-selected integer issuance time; never change it on a retry. */
111
+ iat: number;
112
+ }
113
+ /** Retained callback is untrusted until the application accepts its complete presentation. */
114
+ export interface PaidRetainedPresentation {
115
+ /** Locally checked callback identity; safe for correlation. */
116
+ id: string;
117
+ /** Complete owner-only proposal. Do not log credential contents. */
118
+ presentation: ClientApprovedPresentation;
119
+ /** Immutable parent expiry. */
120
+ expires: number;
121
+ /** Whether this callback has already been selected. */
122
+ selected: boolean;
123
+ }
124
+ /** Owner proposal, including its transport correlation identity. */
125
+ export interface PaidAgentProposal extends ExecutionProposal {
126
+ /** Transport identity; it never replaces the complete-body comparison. */
127
+ id: string;
128
+ }
129
+ /** HTTP refusal or consent/recovery wait, with no credential-bearing response text. */
130
+ export declare class PaidAgentControlError extends Error {
131
+ /** Original locally derived session identity. */ readonly sessionId: string;
132
+ /** Observed status; this never authorizes an automatic resend. */ readonly httpStatus: number;
133
+ /** Agent-requested wait in ms (`Retry-After`), when sent; a polling hint for reads and consent waits. */ readonly retryAfterMs?: number | undefined;
134
+ constructor(
135
+ /** Original locally derived session identity. */ sessionId: string,
136
+ /** Observed status; this never authorizes an automatic resend. */ httpStatus: number,
137
+ /** Agent-requested wait in ms (`Retry-After`), when sent; a polling hint for reads and consent waits. */ retryAfterMs?: number | undefined);
138
+ }
139
+ /** Prepared client-owned session; creation sends once, reconciliation only reads. */
140
+ export interface RegisteredPaidAgentSession {
141
+ /** Locally derived deterministic initialization identity. */
142
+ readonly sessionId: string;
143
+ /** Original approved provider, immutable and independently authenticated. */
144
+ readonly profile: Readonly<ApprovedAgentProfile>;
145
+ /** Original spending commitment. */
146
+ readonly paymentHash: Hex;
147
+ /** Public initialization proof; the execution private key remains with the caller. */
148
+ readonly initialization: SessionInitialization;
149
+ /** Locally derived OAuth audience and nonce; available after public-context recovery. */
150
+ readonly oauthContext: Readonly<{
151
+ nonce: string;
152
+ dpopHtu: string;
153
+ platformAudience: string;
154
+ }>;
155
+ /** Build and verify the original OAuth presentation locally. Retain it before submission. */
156
+ prepareOAuthPresentation(accessToken: string, signer: DpopSigner, signal?: AbortSignal): Promise<ClientApprovedPresentation>;
157
+ /** Submit the retained original OAuth artifacts once; HTTP202 means client consent is still needed. */
158
+ submitOAuthPresentation(approved: ClientApprovedPresentation, signal?: AbortSignal): Promise<void>;
159
+ /** Send the exact initialized creation POST once. Retain this object if its result is unknown. */
160
+ create(signal?: AbortSignal): Promise<void>;
161
+ /** Recover the original public context via authenticated GET after a lost creation reply. */
162
+ reconcile(signal?: AbortSignal): Promise<SessionStatusResult>;
163
+ /**
164
+ * Read owner-only complete-body proposals, without approving or sending operator work. With
165
+ * `waitMs` and an agent advertising {@link PROPOSAL_WAIT_CAPABILITY}, the agent holds the
166
+ * answer until one is pending (at most `waitMs`, capped at {@link MAX_PROPOSAL_WAIT_MS}).
167
+ */
168
+ proposals(signal?: AbortSignal, options?: {
169
+ waitMs?: number;
170
+ }): Promise<PaidAgentProposal[]>;
171
+ /** Whether the authenticated agent's manifest advertises {@link BATCH_APPROVAL_CAPABILITY}. */
172
+ readonly batchApprovals?: boolean;
173
+ /** Whether the authenticated agent's manifest advertises {@link PROPOSAL_WAIT_CAPABILITY}. */
174
+ readonly proposalWait?: boolean;
175
+ /**
176
+ * Send several retained approvals' authorizations in ONE request (agents advertising
177
+ * {@link BATCH_APPROVAL_CAPABILITY}); each authorization is the one its retained body carries,
178
+ * never re-signed. Distinct deliveries, at most 256.
179
+ */
180
+ sendRetainedApprovals?(approvals: readonly RetainedPaidApproval[], signal?: AbortSignal): Promise<PaidApprovalBatchReply>;
181
+ /** Approve one JAR signer or distinct attester after canonical member/policy checks and local body reconstruction. */
182
+ approveRequest(proposal: PaidAgentProposal, stage: 'presentation_sign' | 'presentation_attest', member: PaidVerifierWitness, signal?: AbortSignal): Promise<void>;
183
+ /** Read retained callback candidates; application acceptance must precede selection or signing. */
184
+ presentations(signal?: AbortSignal): Promise<PaidRetainedPresentation[]>;
185
+ /** Select/resume the exact client-accepted callback. HTTP425 requires separate operator approvals. */
186
+ resumePresentation(id: string, approved: ClientApprovedPresentation, signal?: AbortSignal): Promise<void>;
187
+ /** Approve one drawn verifier's complete credential body, built from the separately accepted presentation. */
188
+ approveCredentials(proposal: PaidAgentProposal, member: PaidVerifierWitness, approved: ClientApprovedPresentation, signal?: AbortSignal): Promise<void>;
189
+ /** Record a refusal; never reopens a dispatched operator stage. */
190
+ rejectProposal(id: string, signal?: AbortSignal): Promise<void>;
191
+ /** Fetch and independently verify the drawn signer's JAR and every bound session claim before exposing a QR. */
192
+ requestObject(signal?: AbortSignal): Promise<{
193
+ request: VerifiedRequestObject;
194
+ requestUri: string;
195
+ qrPayload: string;
196
+ }>;
197
+ /**
198
+ * Poll the original provider and verify a completed token against the anchored draw and application's rule hash.
199
+ * With `wait`, ask the agent to hold the reply until the session's status or phase changes
200
+ * (`?wait=1`, at most 20 s); an agent without long-poll support answers at once. A session whose
201
+ * attempt budget is under 25 s never asks for a hold.
202
+ */
203
+ poll(signal?: AbortSignal, options?: {
204
+ wait?: boolean;
205
+ }): Promise<SessionStatusResult>;
206
+ /** Pacing this session applies to definite 429/503 refusals (present on sessions from {@link prepareRegisteredPaidSession}). */
207
+ readonly pacing?: Readonly<{
208
+ clock: PaidPacingClock;
209
+ attemptBudgetMs: number;
210
+ }>;
211
+ /** Sign (once) the approval {@link RegisteredPaidAgentSession.approveRequest} would send, without sending it. Retain it durably before the first send. */
212
+ prepareRequestApproval?(proposal: PaidAgentProposal, stage: 'presentation_sign' | 'presentation_attest', member: PaidVerifierWitness, signal?: AbortSignal): Promise<RetainedPaidApproval>;
213
+ /** Sign (once) the approval {@link RegisteredPaidAgentSession.approveCredentials} would send, without sending it. Retain it durably before the first send. */
214
+ prepareCredentialApproval?(proposal: PaidAgentProposal, member: PaidVerifierWitness, approved: ClientApprovedPresentation, signal?: AbortSignal): Promise<RetainedPaidApproval>;
215
+ /**
216
+ * Send a retained approval's exact bytes ONCE. 204 is `accepted`, 429/503 `busy` (not processed);
217
+ * any other status throws {@link PaidAgentControlError}. Never re-signs; never repeats by itself:
218
+ * the caller decides a resend under its durable permit.
219
+ */
220
+ sendRetainedApproval?(approval: RetainedPaidApproval, signal?: AbortSignal): Promise<PaidApprovalDelivery>;
221
+ /** Read one delivery's state (`pending`, `approved`, `dispatched`, `finished`, …); repeated on 429/503 inside the session expiry. */
222
+ approvalState?(proposalId: string, signal?: AbortSignal): Promise<string>;
223
+ }
224
+ /**
225
+ * Authenticate one approved provider and prepare complete client-signed initialization before HTTP.
226
+ * This function reserves nothing, sends no session POST and keeps the execution signer local.
227
+ * The caller must retain the returned object through uncertain creation/delivery outcomes.
228
+ * @param chain Independently configured trusted RPC/registry client.
229
+ * @param config Approved provider, deployment, drawn Merkle witnesses and client-verified rule/query.
230
+ * @param params Original operation and fixed mined payment, built before contacting the agent.
231
+ * @param consent Creator-certified client key, optional locally retained bearer and consent deadline.
232
+ */
233
+ export declare function prepareRegisteredPaidSession(chain: TasraChainClient, config: {
234
+ profile: ApprovedAgentProfile;
235
+ deployment: ClientExecutionDeployment;
236
+ transport: PaidAgentTransport;
237
+ members: readonly PaidVerifierWitness[];
238
+ ruleHash: Hex;
239
+ dcqlQuery: Record<string, unknown>;
240
+ /**
241
+ * Accept a completed grant WITHOUT revocation-status attestations (with a warning), only for a
242
+ * deployment still inside the keepers' documented migration window. Default false: a missing
243
+ * list is `revocation_status_missing`. Stale or invalid attestations are always refused.
244
+ */
245
+ allowMissingStatusAttestations?: boolean;
246
+ /** Pacing of definite 429/503 refusals on repeatable requests; defaults to the system clock and a 60 s attempt. */
247
+ pacing?: PaidPacingOptions;
248
+ }, params: PaidAgentSessionParams, consent: {
249
+ certificate: ExecutionCertificate;
250
+ signer: ClientExecutionSigner;
251
+ pollSecret?: string;
252
+ expires?: number;
253
+ signal?: AbortSignal;
254
+ }): Promise<RegisteredPaidAgentSession>;