@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.
- package/CHANGELOG.md +1067 -28
- package/README.md +15 -0
- package/dist/app/approvals.d.ts +66 -4
- package/dist/app/approvals.js +153 -16
- package/dist/app/authorization.d.ts +1 -1
- package/dist/app/authorization.js +1 -1
- package/dist/app/browser.d.ts +63 -0
- package/dist/app/browser.js +242 -0
- package/dist/app/client.d.ts +114 -13
- package/dist/app/client.js +302 -76
- package/dist/app/identity.js +21 -9
- package/dist/app/index.d.ts +28 -3
- package/dist/app/index.js +16 -1
- package/dist/app/memory-store.d.ts +7 -0
- package/dist/app/memory-store.js +55 -0
- package/dist/app/node.d.ts +34 -6
- package/dist/app/node.js +387 -64
- package/dist/app/paid-allowance.d.ts +325 -0
- package/dist/app/paid-allowance.js +1290 -0
- package/dist/app/paid-approval.d.ts +122 -0
- package/dist/app/paid-approval.js +379 -0
- package/dist/app/paid-journal.d.ts +51 -0
- package/dist/app/paid-journal.js +117 -0
- package/dist/app/paid-keys.d.ts +12 -0
- package/dist/app/paid-keys.js +20 -0
- package/dist/app/paid-operation.d.ts +821 -0
- package/dist/app/paid-operation.js +1720 -0
- package/dist/app/paid-reservation.d.ts +157 -0
- package/dist/app/paid-reservation.js +323 -0
- package/dist/app/paid-session.d.ts +147 -0
- package/dist/app/paid-session.js +578 -0
- package/dist/app/payer-queue.d.ts +11 -0
- package/dist/app/payer-queue.js +27 -0
- package/dist/app/policy-bootstrap.d.ts +342 -0
- package/dist/app/policy-bootstrap.js +365 -0
- package/dist/app/policy-operation.d.ts +47 -0
- package/dist/app/policy-operation.js +101 -0
- package/dist/app/ready-slot.d.ts +12 -0
- package/dist/app/ready-slot.js +5 -2
- package/dist/app/rotation-lock.d.ts +38 -0
- package/dist/app/rotation-lock.js +42 -0
- package/dist/app/session-decrypt.d.ts +135 -0
- package/dist/app/session-decrypt.js +335 -0
- package/dist/app/session-grants.d.ts +349 -0
- package/dist/app/session-grants.js +811 -0
- package/dist/app/signing-intents.d.ts +78 -0
- package/dist/app/signing-intents.js +95 -0
- package/dist/app/store-commit.d.ts +63 -0
- package/dist/app/store-commit.js +126 -0
- package/dist/app/store-errors.d.ts +8 -0
- package/dist/app/store-errors.js +11 -0
- package/dist/app/tasra-client.d.ts +2 -0
- package/dist/app/tasra-client.js +1 -1
- package/dist/app/wallet.js +4 -1
- package/dist/auth/holderProof.d.ts +3 -0
- package/dist/auth/holderProof.js +8 -7
- package/dist/auth/verifier.d.ts +4 -2
- package/dist/auth/verifier.js +5 -2
- package/dist/chain/abis/index.d.ts +6178 -4101
- package/dist/chain/abis/index.js +3 -0
- package/dist/chain/abis/keyRegistry.d.ts +256 -0
- package/dist/chain/abis/keyRegistry.js +333 -0
- package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
- package/dist/chain/abis/prepaidFaultOracle.js +413 -0
- package/dist/chain/abis/settlement.d.ts +2203 -703
- package/dist/chain/abis/settlement.js +2685 -764
- package/dist/chain/allowance.d.ts +358 -0
- package/dist/chain/allowance.js +800 -0
- package/dist/chain/billing.d.ts +85 -0
- package/dist/chain/billing.js +197 -0
- package/dist/chain/chainId.d.ts +13 -0
- package/dist/chain/chainId.js +26 -0
- package/dist/chain/client.d.ts +15 -1
- package/dist/chain/client.js +57 -1
- package/dist/chain/commitmentRecovery.d.ts +51 -0
- package/dist/chain/commitmentRecovery.js +38 -0
- package/dist/chain/committeeClient.d.ts +17 -10
- package/dist/chain/committeeClient.js +64 -16
- package/dist/chain/committeeDraw.d.ts +12 -0
- package/dist/chain/committeeDraw.js +56 -0
- package/dist/chain/custodyHealth.d.ts +212 -0
- package/dist/chain/custodyHealth.js +365 -0
- package/dist/chain/deployments.js +2 -0
- package/dist/chain/events.js +2 -0
- package/dist/chain/headFollower.d.ts +77 -0
- package/dist/chain/headFollower.js +219 -0
- package/dist/chain/headPrefetch.d.ts +23 -0
- package/dist/chain/headPrefetch.js +67 -0
- package/dist/chain/index.d.ts +50 -8
- package/dist/chain/index.js +28 -3
- package/dist/chain/keeperExecution.d.ts +44 -0
- package/dist/chain/keeperExecution.js +127 -0
- package/dist/chain/keeperRecovery.d.ts +78 -0
- package/dist/chain/keeperRecovery.js +91 -0
- package/dist/chain/node.d.ts +24 -1
- package/dist/chain/node.js +88 -43
- package/dist/chain/offchain.d.ts +2 -0
- package/dist/chain/paidAgentTransport.d.ts +38 -0
- package/dist/chain/paidAgentTransport.js +1 -0
- package/dist/chain/paidEpoch.d.ts +66 -0
- package/dist/chain/paidEpoch.js +139 -0
- package/dist/chain/paidPacing.d.ts +81 -0
- package/dist/chain/paidPacing.js +136 -0
- package/dist/chain/pinnedReads.d.ts +49 -0
- package/dist/chain/pinnedReads.js +218 -0
- package/dist/chain/prepaid.d.ts +383 -0
- package/dist/chain/prepaid.js +1046 -0
- package/dist/chain/prepaidEscape.d.ts +274 -0
- package/dist/chain/prepaidEscape.js +432 -0
- package/dist/chain/prepaidFault.d.ts +94 -0
- package/dist/chain/prepaidFault.js +148 -0
- package/dist/chain/receipt.d.ts +24 -0
- package/dist/chain/receipt.js +82 -0
- package/dist/chain/registeredAgent.d.ts +68 -3
- package/dist/chain/registeredAgent.js +143 -42
- package/dist/chain/registeredOperation.d.ts +10 -1
- package/dist/chain/registeredOperation.js +18 -3
- package/dist/chain/registeredPaidAgent.d.ts +254 -0
- package/dist/chain/registeredPaidAgent.js +889 -0
- package/dist/chain/registeredRelay.d.ts +31 -1
- package/dist/chain/registeredRelay.js +164 -43
- package/dist/chain/relayVoucher.d.ts +64 -0
- package/dist/chain/relayVoucher.js +69 -0
- package/dist/chain/reservation.d.ts +239 -0
- package/dist/chain/reservation.js +746 -0
- package/dist/chain/reshareRoster.d.ts +64 -0
- package/dist/chain/reshareRoster.js +85 -0
- package/dist/chain/revertReason.d.ts +8 -0
- package/dist/chain/revertReason.js +2 -1
- package/dist/chain/rotationLock.d.ts +130 -0
- package/dist/chain/rotationLock.js +168 -0
- package/dist/chain/serviceRequestPolicy.d.ts +47 -0
- package/dist/chain/serviceRequestPolicy.js +86 -0
- package/dist/chain/services.d.ts +7 -0
- package/dist/chain/services.js +44 -4
- package/dist/chain/slotClient.js +11 -2
- package/dist/chain/slotHandoff.d.ts +81 -0
- package/dist/chain/slotHandoff.js +166 -0
- package/dist/chain/slotSeed.d.ts +47 -5
- package/dist/chain/slotSeed.js +173 -42
- package/dist/chain/verifierSnapshot.d.ts +36 -0
- package/dist/chain/verifierSnapshot.js +197 -0
- package/dist/chain/write.d.ts +111 -21
- package/dist/chain/write.js +378 -146
- package/dist/committee/blsSharing.d.ts +53 -0
- package/dist/committee/blsSharing.js +90 -0
- package/dist/committee/client.d.ts +62 -23
- package/dist/committee/client.js +288 -72
- package/dist/committee/dual-operation.d.ts +165 -0
- package/dist/committee/dual-operation.js +229 -0
- package/dist/committee/dual-sign.d.ts +26 -1
- package/dist/committee/dual-sign.js +85 -7
- package/dist/committee/ecdsa.d.ts +38 -0
- package/dist/committee/ecdsa.js +87 -15
- package/dist/committee/evidence.d.ts +30 -0
- package/dist/committee/evidence.js +65 -0
- package/dist/committee/execution.d.ts +414 -0
- package/dist/committee/execution.js +446 -0
- package/dist/committee/extraction.js +33 -26
- package/dist/committee/index.d.ts +30 -7
- package/dist/committee/index.js +18 -6
- package/dist/committee/keeperExecution.d.ts +37 -0
- package/dist/committee/keeperExecution.js +141 -0
- package/dist/committee/oauth.d.ts +14 -4
- package/dist/committee/oauth.js +17 -5
- package/dist/committee/payment.d.ts +369 -0
- package/dist/committee/payment.js +339 -0
- package/dist/committee/recovery.d.ts +136 -0
- package/dist/committee/recovery.js +204 -0
- package/dist/committee/recoveryJson.d.ts +2 -0
- package/dist/committee/recoveryJson.js +87 -0
- package/dist/committee/request.d.ts +63 -27
- package/dist/committee/request.js +77 -66
- package/dist/committee/session-grant.d.ts +320 -0
- package/dist/committee/session-grant.js +397 -0
- package/dist/committee/status-refresh.d.ts +257 -0
- package/dist/committee/status-refresh.js +619 -0
- package/dist/committee/token.d.ts +163 -15
- package/dist/committee/token.js +247 -10
- package/dist/crypto/bn254.d.ts +70 -0
- package/dist/crypto/bn254.js +222 -0
- package/dist/crypto/ibe.d.ts +32 -0
- package/dist/crypto/ibe.js +56 -8
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/crypto/kem.d.ts +31 -0
- package/dist/crypto/kem.js +113 -7
- package/dist/crypto/recipient.d.ts +75 -0
- package/dist/crypto/recipient.js +107 -0
- package/dist/decryption/client.d.ts +10 -16
- package/dist/decryption/client.js +8 -76
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/decryption/sealed.d.ts +72 -0
- package/dist/decryption/sealed.js +147 -0
- package/dist/decryption/session.d.ts +115 -0
- package/dist/decryption/session.js +358 -0
- package/dist/errors.d.ts +406 -1
- package/dist/errors.js +400 -5
- package/dist/index.d.ts +9 -2
- package/dist/index.js +6 -1
- package/dist/internal/bounded.d.ts +66 -0
- package/dist/internal/bounded.js +126 -0
- package/dist/internal/network.d.ts +4 -0
- package/dist/internal/network.js +40 -0
- package/dist/internal/retryAfter.d.ts +8 -0
- package/dist/internal/retryAfter.js +28 -0
- package/dist/internal/sleep.d.ts +6 -0
- package/dist/internal/sleep.js +15 -0
- package/dist/internal/typedData.d.ts +13 -0
- package/dist/internal/typedData.js +77 -0
- package/dist/internal/viemErrors.d.ts +26 -0
- package/dist/internal/viemErrors.js +49 -0
- package/dist/oid4vp/binding.d.ts +27 -1
- package/dist/oid4vp/binding.js +36 -1
- package/dist/oid4vp/jose.d.ts +4 -2
- package/dist/oid4vp/jose.js +39 -7
- package/dist/oid4vp/request-object.d.ts +61 -4
- package/dist/oid4vp/request-object.js +140 -5
- package/dist/oid4vp/verifier-agent.d.ts +18 -8
- package/dist/oid4vp/verifier-agent.js +48 -6
- package/dist/oid4vp/wallet.d.ts +2 -4
- package/dist/oid4vp/wallet.js +1 -0
- package/dist/retry.d.ts +78 -0
- package/dist/retry.js +137 -0
- package/dist/signing/frost.d.ts +1 -1
- package/dist/verifier-agent/index.d.ts +41 -5
- package/dist/verifier-agent/index.js +124 -9
- package/dist/verifier-agent/payment.d.ts +7 -0
- package/dist/verifier-agent/payment.js +17 -0
- package/docs/api.md +8 -2
- package/docs/application-api.md +25 -2
- package/docs/chain.md +155 -9
- package/docs/consumer-migrations.md +61 -0
- package/docs/encrypted-notes.md +3 -2
- package/docs/encryption.md +4 -2
- package/docs/errors.md +14 -1
- package/docs/flows.md +2 -2
- package/docs/funding.md +902 -0
- package/docs/native-approvals.md +63 -0
- package/docs/reference/README.md +9 -8
- package/docs/reference/app-browser.md +232 -0
- package/docs/reference/app-node.md +38 -8
- package/docs/reference/app.md +4621 -805
- package/docs/reference/chain-node.md +74 -16
- package/docs/reference/chain.md +6740 -1592
- package/docs/reference/committee.md +5630 -987
- package/docs/reference/main.md +1439 -140
- package/docs/reference/oid4vp.md +297 -144
- package/docs/reference/verifier-agent.md +77 -35
- package/docs/signing.md +6 -0
- package/examples/encrypted-notes.ts +21 -6
- package/examples/getting-started.ts +2 -7
- package/examples/live-config.ts +24 -17
- package/package.json +17 -5
package/docs/funding.md
CHANGED
|
@@ -12,6 +12,734 @@ There are three steps:
|
|
|
12
12
|
AVAX is not sent to a slot ID. An Ethereum slot's derived account separately needs
|
|
13
13
|
AVAX when it sends Ethereum transactions. Its account balance is not usage credit.
|
|
14
14
|
|
|
15
|
+
## Prepaid deployment protocol
|
|
16
|
+
|
|
17
|
+
### Detect the billing mode first
|
|
18
|
+
|
|
19
|
+
A deployment bills either by metering (legacy, `Settlement.version()` is `"1"`, for example
|
|
20
|
+
`tasra.fuji.v1`) or per operation from a prepaid reservation (`"2"`, or `"3"`, which adds only
|
|
21
|
+
the payer timeout escape). Nothing off-chain
|
|
22
|
+
reports which, so read it from the Settlement contract before choosing a flow:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import {createBillingModeDetector} from '@t3foundry/tasra-sdk/chain'
|
|
26
|
+
|
|
27
|
+
const billing = createBillingModeDetector(publicClient, {chainId, settlement})
|
|
28
|
+
const {mode} = await billing.mode(slotId) // 'legacy' | 'prepaid' | 'unknown'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Versions `"2"` and `"3"` are prepaid for a slot once `prepaidEnabled(slot)` is set, and for every slot of a
|
|
32
|
+
prepaid-from-genesis deployment (its first funding enables it). An upgraded deployment keeps
|
|
33
|
+
a slot on legacy billing until its cutover. Any other version, a failed read, a chain mismatch
|
|
34
|
+
or a reorganized block is `unknown`: start neither flow. The detector caches `prepaid`
|
|
35
|
+
(one-way per slot) until `invalidate`, `legacy` for `legacyTtlMs` (default 60 s), and
|
|
36
|
+
never `unknown`. Paid entry points such as `discoverPaidOperationContext` throw
|
|
37
|
+
`BillingModeError` (`mode`, `settlementVersion`) on a legacy or unreadable slot;
|
|
38
|
+
`requirePrepaidSlot` is the same guard on its own. `readSlotFunding` on a version `"1"`
|
|
39
|
+
Settlement reports the balance with `enabled: false`, `reserved: 0n` and
|
|
40
|
+
`settlementVersion: '1'`.
|
|
41
|
+
|
|
42
|
+
The certification deployment requires a mined TASRA reservation before verification or
|
|
43
|
+
keeper work. Depositing funds alone does not create that reservation. `paidOperation`
|
|
44
|
+
from `@t3foundry/tasra-sdk/app` runs the complete lifecycle for one operation; the primitives below
|
|
45
|
+
remain available for applications that compose it themselves.
|
|
46
|
+
|
|
47
|
+
### One paid operation
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {paidOperation, resumePaidOperation, PaidOperationRecoveryError} from '@t3foundry/tasra-sdk/app'
|
|
51
|
+
import {createFileStore} from '@t3foundry/tasra-sdk/app/node'
|
|
52
|
+
import {createNodePaidAgentTransport} from '@t3foundry/tasra-sdk/chain/node'
|
|
53
|
+
|
|
54
|
+
const config = {chain, deployment, creator, gasPayer, store: createFileStore(stateDir),
|
|
55
|
+
agent: {profile, transport: createNodePaidAgentTransport()}, accountantUrls,
|
|
56
|
+
limits: {maxCost, maxGas, maxGasPrice}}
|
|
57
|
+
const op = await paidOperation(config, {slot, operation: {action: 'sign', message},
|
|
58
|
+
rule: {rule, salt}, holder})
|
|
59
|
+
const signature = await op.execute(() => committeeSign({nodeUrl: op.coordinatorUrl,
|
|
60
|
+
committeeToken: op.compound_token, message, verifierProofs: op.verifierProofs,
|
|
61
|
+
approveExecution: op.approveExecution}))
|
|
62
|
+
op.dispose()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
It refuses a legacy or unreadable slot (`BillingModeError`), checks the creator and the
|
|
66
|
+
slot's salted rule commitment, signs the operation and payment intent, verifies the drawn
|
|
67
|
+
verifier witnesses from an approved accountant's snapshot, reserves through
|
|
68
|
+
`reserveApplicationPayment` with the caller's dedicated gas payer, certifies a local
|
|
69
|
+
execution key, drives the registered session (`drivePaidSession`) and verifies the grant.
|
|
70
|
+
`holder` is `{kind: 'local', makePresentation, submit}` when the SDK wallet presents
|
|
71
|
+
(`makePresentation(request, {requestUri, qrPayload})`, plus an optional `present` hook with
|
|
72
|
+
the same link, so applications never rebuild the request URI), or
|
|
73
|
+
`{kind: 'external', present, accept}` when a phone wallet scans `qrPayload` and the
|
|
74
|
+
application accepts the complete retained presentation, or `{kind: 'oauth', credential}` for an
|
|
75
|
+
OAuth slot rule (`oauth+access-token+dpop` or a `kk_oauth` envelope).
|
|
76
|
+
|
|
77
|
+
With `kind: 'oauth'` the client presents a DPoP-bound access token itself: no request
|
|
78
|
+
object is fetched and no wallet is involved. `credential({sessionId, nonce, dpopHtu,
|
|
79
|
+
platformAudience})` returns `{accessToken, signer}` (a `DpopSigner` over the key the token's
|
|
80
|
+
`cnf.jkt` names); the token's `aud` must include `platformAudience`. The SDK builds the proof
|
|
81
|
+
and verifies audience, lifetime, `cnf.jkt`, nonce, `htm`, `htu`, `ath` and the proof signature
|
|
82
|
+
locally, journals the exact presentation in the store BEFORE its one submission, then approves
|
|
83
|
+
the drawn verifiers' credential work on that retained presentation. `credential` runs at most
|
|
84
|
+
once per session: a resume reuses the journaled presentation and never asks for a refreshed
|
|
85
|
+
token (an expired one ends the operation; reconcile or abandon it). A submission whose reply was
|
|
86
|
+
lost is confirmed only by a read showing the agent holding exactly that presentation; otherwise
|
|
87
|
+
the resume refuses. Only a definite HTTP 429 is repeated, with the identical token and proof,
|
|
88
|
+
inside the proof's 60-second window; one that ran out is journaled `unsent` and a resume resends
|
|
89
|
+
those same bytes. The holder kind is journaled with the operation: `resumePaidOperation` refuses
|
|
90
|
+
a holder of the other family. A holder that does not match the slot rule's family is refused
|
|
91
|
+
before anything is signed or reserved. Tokens and proofs never appear in errors or
|
|
92
|
+
`listPaidOperations` summaries; they are kept in the private store, which must be protected
|
|
93
|
+
accordingly.
|
|
94
|
+
|
|
95
|
+
When every approved accountant returns 404 for the anchored verifier snapshot,
|
|
96
|
+
`paidOperation` waits for that exact original artifact before reserving. The wait
|
|
97
|
+
is capped by `snapshotWaitMs`, 150 seconds and the operation lifetime; cancellation
|
|
98
|
+
stops it. An invalid artifact or any other read failure is not retried. The lower
|
|
99
|
+
level `fetchDrawnVerifierWitnesses` keeps immediate failure by default; callers can
|
|
100
|
+
opt into this behavior with `waitForPublicationMs` (0–150000).
|
|
101
|
+
|
|
102
|
+
Each billable step is journaled in the store before it is sent. When an outcome is
|
|
103
|
+
uncertain the call throws `PaidOperationRecoveryError` (`requestId`, `phase`:
|
|
104
|
+
`reservation`, `session` or `execution`, a stable `code` and `resumable`). `resumable`
|
|
105
|
+
separates a final refusal (`session-refused`, `reservation-failed`, `payment-expired`) and
|
|
106
|
+
steps only reconciliation or `recover` can settle from an interruption worth resuming. Never call `paidOperation` again for that
|
|
107
|
+
work, which would pay twice. Call `resumePaidOperation(config, requestId, {holder})`: it
|
|
108
|
+
re-reads the session and skips confirmed writes. An unknown creation can be confirmed only
|
|
109
|
+
by an authenticated, verified read of that same original session; other unknown writes
|
|
110
|
+
remain refused. Cancelling through `signal` after the operation is journaled throws code
|
|
111
|
+
`aborted`, resumable unless the payment expired, when the step sent nothing uncertain; if
|
|
112
|
+
a reservation or session write may have been sent, that step's uncertain code is reported
|
|
113
|
+
instead. An abort before the journal is written rethrows the signal's reason: nothing was
|
|
114
|
+
sent.
|
|
115
|
+
|
|
116
|
+
A reservation still in flight is reconciled on chain first, by the deterministic request ID
|
|
117
|
+
and the gas payer's nonce, so no transaction hash is needed (a local signer's hash is
|
|
118
|
+
journaled before broadcast anyway; pass `transactionHash` to prove a mined original
|
|
119
|
+
sooner). The chain holding the reservation advances the operation. A quote deadline passed
|
|
120
|
+
without one marks it `failed`: it is never reserved again. Anything else stays
|
|
121
|
+
`reserving`, the call throws and the gas payer stays locked. Resume makes a first
|
|
122
|
+
reservation only when nothing was ever prepared for the request (no journal, no payer
|
|
123
|
+
claim, nothing on chain). To inspect without any billable or keeper work, use
|
|
124
|
+
`reconcilePaidOperation(config, requestId)` (or `resumePaidOperation` with
|
|
125
|
+
`reconcileOnly: true`); it returns `{phase, reservation, payerLocked, next}`, where
|
|
126
|
+
`next` is `reserve`, `resume`, `wait`, `recover`, `done`, `abandon` or `closed`.
|
|
127
|
+
For `recover`, `recoverPaidOperation(config, requestId)` opens the read-only `recover` and
|
|
128
|
+
`recoverIbePartials` straight from the journal, without a holder or a full resume.
|
|
129
|
+
Journals written before SDK commit dfafff3 did not record the assigned contributors: they
|
|
130
|
+
support `recover` but not `recoverIbePartials`.
|
|
131
|
+
`reconcileApplicationReservation` is the same proof for applications composing
|
|
132
|
+
`reserveApplicationPayment` themselves.
|
|
133
|
+
|
|
134
|
+
Pass `onRequestId` to `paidOperation` to receive the request ID as soon as it is derived,
|
|
135
|
+
before anything is reserved, to link an in-flight run to its payment.
|
|
136
|
+
`listPaidOperations(store, {phase})` lists journaled operations (`requestId`, `phase`,
|
|
137
|
+
`slot`, `action`, `expires`, the recorded gas `payer`), e.g. `{phase: ['reserving',
|
|
138
|
+
'certified', 'executing']}` at startup for work to reconcile, without reading the store's
|
|
139
|
+
key scheme. `{backfill: true}` once indexes journals written before the index existed
|
|
140
|
+
(the built-in stores can list their keys).
|
|
141
|
+
|
|
142
|
+
`abandonPaidOperation(store, requestId, {reason})` closes an operation for good, only when
|
|
143
|
+
nothing can still land under it: a reservation never prepared, a `failed` or `executed`
|
|
144
|
+
operation, or any other phase once its payment has expired (plus a two-minute skew margin).
|
|
145
|
+
Otherwise it throws `PaidOperationAbandonRefusedError` (`notBefore` says when expiry
|
|
146
|
+
unblocks it); a prepared reservation must be settled by `reconcilePaidOperation` first.
|
|
147
|
+
Abandoned operations are left out of `listPaidOperations` unless `includeAbandoned` (or
|
|
148
|
+
phase `abandoned`) is asked for, and `resumePaidOperation` refuses them.
|
|
149
|
+
|
|
150
|
+
One gas payer serializes reservations, and an uncertain one keeps it locked until
|
|
151
|
+
reconciled. To spread load, keep a few dedicated payers and pick one per operation with
|
|
152
|
+
`selectApplicationGasPayer(store, wallets)`: it skips payers holding an unresolved claim,
|
|
153
|
+
prefers payers idle in this process and rotates round-robin; `undefined` means every payer
|
|
154
|
+
needs reconciliation. Pass the chosen wallet as that operation's `gasPayer`. The journal
|
|
155
|
+
records it, and a reserving operation resumes only with that payer; pass `{resume:
|
|
156
|
+
requestId}` to `selectApplicationGasPayer` to get it back from the pool. `execute` runs once; after an
|
|
157
|
+
uncertain execution use `op.recover({transport: createNodeKeeperRecoveryTransport()})`
|
|
158
|
+
to read the keeper's retained result. An identity extraction fans out to every assigned
|
|
159
|
+
contributor; after a lost reply, `op.recoverIbePartials({transport})` reads each
|
|
160
|
+
contributor's retained, commitment-verified partial (bounded concurrency, stopping at the
|
|
161
|
+
payment's keeper threshold) and returns them in the shape the IBE combine helpers accept,
|
|
162
|
+
never re-sending an extraction. For local development keepers over HTTP, pass
|
|
163
|
+
`{allowLocalHttp: true}` to `createNodeKeeperRecoveryTransport` (Node) or
|
|
164
|
+
`createBrowserKeeperRecoveryTransport` (browser); both permit loopback and private hosts only
|
|
165
|
+
and are off by default.
|
|
166
|
+
`createMemoryStore` suits tests only.
|
|
167
|
+
|
|
168
|
+
For clients integrating with an independently verified reservation service,
|
|
169
|
+
`@t3foundry/tasra-sdk/committee` exports `PaymentIntentWire`, `paymentIntentTypedData`,
|
|
170
|
+
`paymentIntentHash`, `keeperAssignmentCommitment` and `paymentSessionCommitment`.
|
|
171
|
+
The payment intent binds the deployment, slot, exact operation, fee cap, presentation
|
|
172
|
+
session, verifier committee and keeper assignment. Amounts use decimal TASRA base-unit
|
|
173
|
+
strings. JSON integer inputs must be safe integers; unsafe numbers are refused.
|
|
174
|
+
|
|
175
|
+
The creator signs the typed data. A presentation delegate has no implicit spending
|
|
176
|
+
authority. Verify the deployment, current assignment, fee quote, creator signature and
|
|
177
|
+
mined reservation independently before opening a session. Hashing an intent does not
|
|
178
|
+
establish any of those facts.
|
|
179
|
+
|
|
180
|
+
Before constructing an intent, use `discoverPaidOperationContext` from `@t3foundry/tasra-sdk/chain`.
|
|
181
|
+
Supply independently approved Settlement, KeyRegistry, VerifierSetRegistry, AccountantSetRegistry and beacon
|
|
182
|
+
addresses. It checks the registry beacon pointers and reads the keeper sharing, eligible
|
|
183
|
+
workers and anchored verifier context at one fresh canonical block. The selected epoch must
|
|
184
|
+
have both verifier and accountant snapshots. If either current snapshot is missing, only
|
|
185
|
+
the immediately preceding epoch is eligible as a fallback.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import {discoverPaidOperationContext} from '@t3foundry/tasra-sdk/chain'
|
|
189
|
+
|
|
190
|
+
const context = await discoverPaidOperationContext(client, {
|
|
191
|
+
...deployment,
|
|
192
|
+
verifierSet,
|
|
193
|
+
accountantSet,
|
|
194
|
+
beacon,
|
|
195
|
+
}, slotId, {
|
|
196
|
+
defaultVerificationPolicy: {committee: 3, quorum: 2},
|
|
197
|
+
})
|
|
198
|
+
const unsignedPayment = {
|
|
199
|
+
...context.intentFields,
|
|
200
|
+
action,
|
|
201
|
+
payload_digest: payloadDigest,
|
|
202
|
+
nonce,
|
|
203
|
+
max_cost: maximumTasraCost,
|
|
204
|
+
expires,
|
|
205
|
+
session_commitment: paymentSessionCommitment(random, audience, expires),
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Use the verifier defaults approved for your deployment; the numbers above are examples.
|
|
210
|
+
A slot's nonzero policy overrides them. Missing defaults for a slot with no override are
|
|
211
|
+
refused. Discovery draws the coordinator uniformly from eligible assigned keepers, or
|
|
212
|
+
accepts an explicit `coordinator` address. Retain that context for signing and reservation;
|
|
213
|
+
recovery uses the original paid assignment and does not draw again. The intent includes all
|
|
214
|
+
currently eligible assigned contributors. It refuses fewer contributors than the threshold.
|
|
215
|
+
This gives eligible keepers equal chances over many fresh operations, not guaranteed turns.
|
|
216
|
+
Eligibility is verified on chain; discovery does not probe endpoint reachability.
|
|
217
|
+
|
|
218
|
+
The result includes the creator, published group key, endpoints, available TASRA and block
|
|
219
|
+
identity. Only `intentFields` belongs in the payment preimage. The application still chooses
|
|
220
|
+
the exact operation digest, fresh nonce and presentation random, audience, fee cap and expiry;
|
|
221
|
+
the creator must review and sign them. A positive balance is not a fee quote or reserved
|
|
222
|
+
credit. Discovery makes no service request or transaction, and later reservation and
|
|
223
|
+
execution checks must revalidate chain state. HTTPS is required except with the explicit
|
|
224
|
+
`allowLocalHttp` option on local chain43112; that option never enables HTTP on Fuji.
|
|
225
|
+
|
|
226
|
+
For direct reservation submission, call `reservePaidOperation` from `@t3foundry/tasra-sdk/chain`
|
|
227
|
+
with the signed intent, an independently selected deployment and expected operation,
|
|
228
|
+
a Viem public client, and an account-bound Viem gas-payer wallet. It gathers the same
|
|
229
|
+
quote from the supplied accountants, compares the deployment's digest, recovers the
|
|
230
|
+
creator signature and simulates the threshold-authorized contract call. All reads for
|
|
231
|
+
the quote use its fresh canonical block; unsupported canonical reads fail.
|
|
232
|
+
|
|
233
|
+
Credential approvals use `action: 'dual-approve'` and their exact approval payload digest.
|
|
234
|
+
Each holder's approval has its own intent, session and reservation. These payments do not
|
|
235
|
+
fund the final keeper signature, which requires a separate `sign` intent and reservation.
|
|
236
|
+
The final paid signature uses the separate native dual-control lifecycle described below.
|
|
237
|
+
|
|
238
|
+
Set `maxGas` and `maxGasPrice` explicitly. These limit native transaction gas; the
|
|
239
|
+
intent's `max_cost` separately limits TASRA. Supply trusted, bounded clients and
|
|
240
|
+
accountant HTTPS endpoints. `allowLocalHttp` permits HTTP only on chain43112.
|
|
241
|
+
The function does not mint tokens, fund a wallet, enable a slot or create a new intent.
|
|
242
|
+
Use the discovery helper above before creator signing.
|
|
243
|
+
|
|
244
|
+
Its required `persist` callback is part of the spending guarantee. On `prepared`,
|
|
245
|
+
atomically create a durable record keyed by `record.requestId` and reject an existing
|
|
246
|
+
record, including concurrent attempts. Resolve only after the record survives process
|
|
247
|
+
loss. On `submitted` and `confirmed`, durably update that same record. A process-local
|
|
248
|
+
map or a no-op callback is insufficient. Use the application's transactional database
|
|
249
|
+
or an equivalently durable exclusive file journal; never overwrite or delete an
|
|
250
|
+
uncertain preparation to enable a retry. Keep the presentation random and audience
|
|
251
|
+
alongside the intent in the application's session journal.
|
|
252
|
+
|
|
253
|
+
`createPaidReservationJournal` from `@t3foundry/tasra-sdk/app` supplies this callback for an
|
|
254
|
+
`ApplicationStore`. For Node.js, use `createFileStore` from `@t3foundry/tasra-sdk/app/node` in a
|
|
255
|
+
private directory. Browser applications must supply durable storage and exclusive locks
|
|
256
|
+
shared across tabs; an in-memory store does not meet this contract. `createIndexedDbStore`
|
|
257
|
+
from `@t3foundry/tasra-sdk/app/browser` does: each `save` resolves only after a strict-durability
|
|
258
|
+
IndexedDB commit, and `withLock` takes an exclusive Web Lock shared by every tab, worker
|
|
259
|
+
and extension service worker of the origin (`failIfLocked: true` refuses instead of
|
|
260
|
+
waiting). The same entry provides fetch transports for paid sessions, keeper result
|
|
261
|
+
recovery and relayers. They use the Node transports' route, method, bearer and bound
|
|
262
|
+
checks, require HTTPS, send no cookies, follow no redirects and refuse loopback names and
|
|
263
|
+
private IP literals unless approved. A browser cannot check where a name resolves, so rely
|
|
264
|
+
on its private-network protections; services must allow the origin through CORS and
|
|
265
|
+
expose `Retry-After` and `x-ratelimit-after`.
|
|
266
|
+
|
|
267
|
+
### Holder applications without the rule salt
|
|
268
|
+
|
|
269
|
+
A holder application can run paid operations on a slot whose rule salt only the creator keeps.
|
|
270
|
+
The creator issues a signed slot policy bootstrap to the application's own key; the application
|
|
271
|
+
passes it instead of `{rule, salt}` and never sees the salt.
|
|
272
|
+
|
|
273
|
+
On the creator side:
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
import {issueSlotPolicyBootstrap, verifySlotPolicyRequest} from '@t3foundry/tasra-sdk/app'
|
|
277
|
+
|
|
278
|
+
// The application asked with createSlotPolicyRequest(appKey, {chainId, keyRegistry, slot}).
|
|
279
|
+
const asked = await verifySlotPolicyRequest(request, {chainId, keyRegistry})
|
|
280
|
+
// Check here that asked.audience is an application enrolled for asked.slot and asked.nonce is new.
|
|
281
|
+
const bootstrap = await issueSlotPolicyBootstrap(chain, {signer: creatorSigner, slot: asked.slot,
|
|
282
|
+
rule, salt, audience: asked.audience, actions: ['sign'], sequence: nextSequence, ttlSecs: 900})
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
It refuses unless the signer is the slot's creator and the rule and salt reproduce the slot's
|
|
286
|
+
commitment. The statement binds the chain, KeyRegistry, slot, rule version, salted commitment,
|
|
287
|
+
`keccak256` of the raw rule, the application key, the allowed actions, a lifetime of at most one
|
|
288
|
+
day and a `sequence`; issue a higher sequence to supersede earlier statements.
|
|
289
|
+
|
|
290
|
+
In the holder application:
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
import {paidPolicyOperation} from '@t3foundry/tasra-sdk/app'
|
|
294
|
+
|
|
295
|
+
const op = await paidPolicyOperation({...config, creator: remoteCreatorSigner}, {slot,
|
|
296
|
+
operation: {action: 'sign', message}, policy: bootstrap, audience: appKey.address,
|
|
297
|
+
operationKey: 'invoice-2026-0042', holder})
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Before anything is signed or spent it checks the bootstrap's shape, deployment, slot,
|
|
301
|
+
application key, action, lifetime, that the rule is the one the statement hashes and that the
|
|
302
|
+
configured creator signed it; then, at the block discovery reads, that the slot's creator,
|
|
303
|
+
commitment and rule version are the statement's; then that the store never accepted a higher
|
|
304
|
+
`sequence` for this slot and application. Refusals are `SlotPolicyError` with a stable `code`.
|
|
305
|
+
The bootstrap and the raw rule are journaled with the operation; the salt never is.
|
|
306
|
+
|
|
307
|
+
`operationKey` names one intended operation. It is bound in the store before anything is
|
|
308
|
+
signed, and a later call with the same key, after a lost reply, an uncertain step or a restart,
|
|
309
|
+
resumes the original operation instead of starting another: an expired or newer bootstrap is not
|
|
310
|
+
needed and not used. A key bound to another operation, a closed original and an original that
|
|
311
|
+
never reached its journal are refused as `PolicyOperationError`; restart the last only with
|
|
312
|
+
`restartUnjournaled: true`, which still waits out a derived request's payment window. Keep a
|
|
313
|
+
decryption's recipient with the key: the operation it binds includes it.
|
|
314
|
+
|
|
315
|
+
### Prepaid allowances (opt-in)
|
|
316
|
+
|
|
317
|
+
By default every paid operation waits for its own reservation transaction. With
|
|
318
|
+
`PaidOperationConfig.allowances` (**off by default**) the SDK instead reserves an
|
|
319
|
+
allowance ahead of use (one transaction escrowing `amount`) and debits each operation with an
|
|
320
|
+
accountant-quorum voucher, so no block interval sits on the operation's path:
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
const config: PaidOperationConfig = {
|
|
324
|
+
...paid,
|
|
325
|
+
allowances: {enabled: true, amount: 50_000n, streams: 16}, // 8 lanes: min(streams, 8)
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Enable it only when every reader on the deployment (agent, verifiers, keepers, accountants)
|
|
330
|
+
supports prepaid allowances: the network advertises no capability for it, so the option is the switch.
|
|
331
|
+
|
|
332
|
+
- **Lanes.** Each of `lanes` (default `min(streams, 8)`) holds one allowance and a strictly
|
|
333
|
+
serial debit sequence; different lanes debit in parallel. An operation on a lane signs the
|
|
334
|
+
distinct `SlotAllowancePaymentIntent` (its request ID binds the allowance) with the
|
|
335
|
+
allowance's verification epoch and keeper sharing.
|
|
336
|
+
- **Vouchers.** The debit request goes to every accountant in parallel at one quote block. Each
|
|
337
|
+
member's BN254 partial is checked against its verifying share, `k` are combined and the
|
|
338
|
+
aggregate is verified against `beacon.mpk()` at the quote block before it is attached to the
|
|
339
|
+
payment.
|
|
340
|
+
- **Journal.** The lane journals the sequence, request and quote block before any request, then
|
|
341
|
+
the partials and the voucher. A resume asks for the same sequence and request, so a member
|
|
342
|
+
that already signed returns the same partial.
|
|
343
|
+
- **Open the lanes first.** Without it the first operation on each cold lane finds no allowance
|
|
344
|
+
and pays for the lane's opening inside itself (or falls back to a per-operation reservation).
|
|
345
|
+
Open them once, like loading a card, before user operations:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
const {lanes} = await prepareAllowances(config, {slot}) // every lane; or {slot, lanes: [0, 1]}
|
|
349
|
+
for (const l of lanes) if (l.outcome === 'failed') console.warn(`lane ${l.lane} not opened`, l.error)
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Each lane is reserved through the same journaled reservation as a background top-up, with its
|
|
353
|
+
own fresh discovery, at most `concurrency` (default 4) at once on the dedicated payer. A lane
|
|
354
|
+
reports `reserved`, `not-needed` (already open: nothing read or sent, so the call is
|
|
355
|
+
idempotent), `pending` (broadcast, outcome uncertain; reconciled later, never re-signed),
|
|
356
|
+
`failed` (that lane only) or `cancelled` (`signal`). Draw lanes are not opened here.
|
|
357
|
+
|
|
358
|
+
Preparing for sustained work, say how much is coming. Without it a lane whose confirmed
|
|
359
|
+
allowance is close to exhaustion or expiry (but not yet "low") reports `not-needed`, and an
|
|
360
|
+
operation of the work then reserves the replacement inside itself:
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
await prepareAllowances(config, {slot, minOperations: 120, minLifetimeSecs: 1800})
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Each lane must then fund `minOperations` more operations at the per-operation cap from its
|
|
367
|
+
current and reserved-ahead allowances (only one outliving `minLifetimeSecs` counts), and the
|
|
368
|
+
current one must outlive `minLifetimeSecs`; otherwise the next allowance is reserved ahead now
|
|
369
|
+
(`reserved`). A spent current allowance first hands over to its confirmed next. A lane holding
|
|
370
|
+
both that is still short reports `failed` (`AllowanceCapacityError`): it never locks a third
|
|
371
|
+
(at most 2 x lanes x `amount`). Bounds: `minOperations` 0..2 x floor(`amount` / per-operation
|
|
372
|
+
cap), `minLifetimeSecs` 0..lifetime - 120 s.
|
|
373
|
+
- **Top-up.** Allowances are fixed-amount and live at most an hour. A replacement is reserved in
|
|
374
|
+
the background once the remainder is below 25 % or less than 10 minutes remain, using the same
|
|
375
|
+
dedicated gas payer and durable payer claim as reservations.
|
|
376
|
+
- **Fallback.** Without a lane that can fund the operation (none yet, exhausted, expired, action
|
|
377
|
+
not funded, keeper sharing changed) the operation uses a per-operation reservation. A definite
|
|
378
|
+
accountant refusal journals the allowance attempt `failed`, retires the lane and falls back once
|
|
379
|
+
to a fresh payment with a new request ID (`onRequestId` then sees both). Unreachable accountants
|
|
380
|
+
leave the debit pending: `resumePaidOperation` retries the same voucher.
|
|
381
|
+
- **Session draws.** A session grant's messages must pay the grant's exact verifier draw, and
|
|
382
|
+
the grant follows the beacon every epoch. Regular lanes are never retired for that; separate
|
|
383
|
+
draw lanes (two sets, one per epoch parity) hold one allowance per draw. When a message on the
|
|
384
|
+
grant's epoch sees the beacon already at the next one, the next draw is discovered (pinned and
|
|
385
|
+
verified exactly as the message's own) and its lanes are reserved in the background, so the
|
|
386
|
+
messages after the grant's refresh pay by voucher. A message whose draw lane is still being
|
|
387
|
+
reserved waits for it (at most 20 s) rather than reserving per operation. The escrow they hold
|
|
388
|
+
is bounded: at most `maxDrawAllowances` (default `4 x lanes`) allowances of `drawAmount`
|
|
389
|
+
(default `amount`) per slot, counted until their expiry plus the accountants' 10-minute close
|
|
390
|
+
grace; at the bound a message pays per operation. On a beacon faster than about
|
|
391
|
+
(lifetime + 10 min) / 2 per epoch, lower `drawAmount` and `lifetimeSecs` and raise
|
|
392
|
+
`maxDrawAllowances`.
|
|
393
|
+
- Historical keeper-result recovery of allowance-backed work is not available yet and fails closed.
|
|
394
|
+
|
|
395
|
+
### Busy services during a paid operation
|
|
396
|
+
|
|
397
|
+
Paid clients behind one network address share the verifier-agent's per-client limiter, so a
|
|
398
|
+
burst can see HTTP 429 after the TASRA is already reserved. The SDK waits such a definite refusal
|
|
399
|
+
out instead of losing the paid request, and never extends a signed expiry to do so:
|
|
400
|
+
|
|
401
|
+
- The session's repeatable reads (proposals, Request Object, presentations, poll, delivery state)
|
|
402
|
+
repeat on 429/503 inside the session's signed expiry; the continuation repeats on 429 only.
|
|
403
|
+
- Each operator approval is signed once and its exact body is retained in the store, marked in
|
|
404
|
+
flight, before the first send. After a 429/503 it is resent byte-identically under a one-use,
|
|
405
|
+
generation-bound permit that the store's exclusive `claim` consumes before every resend. A send without a definite
|
|
406
|
+
answer (transport error, timeout, abort, crash) is never resent: a resume reads the delivery and
|
|
407
|
+
confirms it, or throws `PaidApprovalUnresolvedError`. Stores without `claim` send once.
|
|
408
|
+
- An accountant `prepare` answered 429 with a wait hint (its reservation quota) is repeated
|
|
409
|
+
identically within min(150 s, half the payment's remaining lifetime); otherwise
|
|
410
|
+
`PaidReservationQuotaError`. Nothing is reserved before the single reservation transaction.
|
|
411
|
+
- Before that transaction, an unavailable accountant (transport failure or HTTP 5xx) can
|
|
412
|
+
be skipped. Responsive members must agree on one quote, and another prepared coordinator
|
|
413
|
+
may return its quorum authorization for that same intent and quote. Collection shares
|
|
414
|
+
one budget of min(150 s, half the remaining payment lifetime). Credit or policy refusals,
|
|
415
|
+
malformed responses, disagreement and caller cancellation still stop the operation.
|
|
416
|
+
This does not retry a transaction or change an uncertain reservation's recovery rules.
|
|
417
|
+
|
|
418
|
+
Waits honour `Retry-After` and `x-ratelimit-after` as integer seconds (a hint is a floor, never
|
|
419
|
+
shortened). A wait that does not fit before the deadline, or a hint over 120 s, throws
|
|
420
|
+
`PaidBackoffError` without sleeping; resume the operation later rather than starting it again.
|
|
421
|
+
|
|
422
|
+
```ts
|
|
423
|
+
import {createPaidReservationJournal} from '@t3foundry/tasra-sdk/app'
|
|
424
|
+
import {createFileStore} from '@t3foundry/tasra-sdk/app/node'
|
|
425
|
+
|
|
426
|
+
const store = createFileStore('.tasra/payments')
|
|
427
|
+
const journal = createPaidReservationJournal(store, payment, {random, audience})
|
|
428
|
+
const result = await reservePaidOperation(client, wallet, deployment, payment, expected, {
|
|
429
|
+
...limits,
|
|
430
|
+
persist: journal.persist,
|
|
431
|
+
})
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
The adapter checks the session commitment, durably retains the original intent, quote,
|
|
435
|
+
transaction, random and audience before submission, and refuses any existing preparation.
|
|
436
|
+
It also refuses changed hashes and out-of-order checkpoint updates. After restart,
|
|
437
|
+
`loadPaidReservationJournal(store, requestId)` reads the saved evidence without network I/O.
|
|
438
|
+
A saved `confirmed` phase may have become orphaned: recheck canonical chain state before
|
|
439
|
+
using it. A `prepared` record without a hash may still have been broadcast. Reconcile that
|
|
440
|
+
original transaction using its saved payer and nonce; never delete the record to retry.
|
|
441
|
+
This adapter coordinates each reservation identity. For multiple operations sharing a gas
|
|
442
|
+
payer, use the application wrapper below.
|
|
443
|
+
|
|
444
|
+
### Coordinate the gas payer
|
|
445
|
+
|
|
446
|
+
`reserveApplicationPayment` takes the same clients, deployment, payment and expected
|
|
447
|
+
operation, plus a durable store and the original session:
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
import {reserveApplicationPayment, reconcileApplicationPayment} from '@t3foundry/tasra-sdk/app'
|
|
451
|
+
|
|
452
|
+
const result = await reserveApplicationPayment(client, wallet, deployment, payment, expected, {
|
|
453
|
+
...limits, store, session: {random, audience},
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
// After an uncertain submission, locate its original hash; this call never sends a transaction.
|
|
457
|
+
const resolution = await reconcileApplicationPayment(
|
|
458
|
+
client, store, deployment, requestId, expected, independentlyRecoveredHash, 2,
|
|
459
|
+
)
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
All reservation callers must share the same store and use a dedicated gas payer. The
|
|
463
|
+
lock spans nonce selection, durable preparation, submission and verification. It covers
|
|
464
|
+
different slots and deployments on the same chain. A concurrent call in the same process
|
|
465
|
+
waits its turn. One in another process waits or is refused, depending on the store: the
|
|
466
|
+
file store waits up to its `lockWaitMs` (default 10 s), then refuses with `StoreLockedError`.
|
|
467
|
+
Unrelated CLI, wallet and low-level `reservePaidOperation` writes are outside this lock.
|
|
468
|
+
|
|
469
|
+
Once preparation claims a payer, any uncertain outcome retains that claim across restart.
|
|
470
|
+
`ApplicationPayerRecoveryError.requestId` identifies the operation to inspect. Recovery
|
|
471
|
+
requires the original exact transaction to be canonically mined, including a revert; it
|
|
472
|
+
retains the recovered evidence before releasing the payer. The original journal is never
|
|
473
|
+
deleted or made reusable. A durable nonce floor refuses RPC responses older than the last
|
|
474
|
+
verified consumption. Neither expiry nor an absent transaction hash releases a claim.
|
|
475
|
+
If the transaction never lands, the payer remains held: this API does not broadcast a
|
|
476
|
+
cancellation or replacement. A process killed while holding a file-store lock also leaves
|
|
477
|
+
that lock for explicit reconciliation under the store's existing recovery policy.
|
|
478
|
+
|
|
479
|
+
The wrapper returns the same verified reservation receipt as the low-level helper. It
|
|
480
|
+
does not resume authorization or keeper work, and it cannot coordinate other applications
|
|
481
|
+
using another store or an externally shared wallet.
|
|
482
|
+
|
|
483
|
+
Only after durable preparation does the helper submit one transaction. It neither
|
|
484
|
+
retries through another wallet method nor replaces a transaction. It checks the mined
|
|
485
|
+
transaction against the saved nonce, sender, call data and gas bounds, then checks the
|
|
486
|
+
canonical reservation's exact cost and assignment block. A successful return includes
|
|
487
|
+
the transaction hash and reservation receipt. `PaidReservationUncertainError` carries
|
|
488
|
+
the request ID and any known hash; inspect the journal and `readPaidOperationReceipt`
|
|
489
|
+
before further spending. Absence of a hash or an HTTP response does not prove that
|
|
490
|
+
the transaction was never sent. Other uses of the gas-payer account must coordinate
|
|
491
|
+
nonces with this application.
|
|
492
|
+
|
|
493
|
+
Both helpers (and `paidOperation`'s reservation step) accept a `signal`. An abort before the
|
|
494
|
+
durable preparation refuses with `PaidReservationAbortedError` (`code: 'aborted'`): nothing
|
|
495
|
+
was journaled, claimed or sent, so reserving again is safe. From the preparation on, the one
|
|
496
|
+
broadcast proceeds and every journal checkpoint is written in full; a sent transaction cannot
|
|
497
|
+
be cancelled, so a later abort only ends the receipt wait as `PaidReservationUncertainError`
|
|
498
|
+
(`code: 'reservation-uncertain'`) and the payer stays claimed until reconciled.
|
|
499
|
+
|
|
500
|
+
For a local signer, it also decodes the returned signed bytes and recovers their sender before
|
|
501
|
+
broadcast, checking every saved transaction field and rechecking expiry after signing.
|
|
502
|
+
A lost or incorrect RPC reply leaves the locally computed hash in the uncertainty error;
|
|
503
|
+
retain that error's hash with your recovery evidence. The prepared journal still survives
|
|
504
|
+
if no subsequent checkpoint can be saved. The selected payer and chain are captured before
|
|
505
|
+
asynchronous work so callback changes cannot redirect the request.
|
|
506
|
+
|
|
507
|
+
After restart, `reconcilePaidReservation` checks the transaction against the original durable
|
|
508
|
+
record without requesting a quote, signing, broadcasting or changing the journal:
|
|
509
|
+
|
|
510
|
+
```ts
|
|
511
|
+
import {loadPaidReservationJournal} from '@t3foundry/tasra-sdk/app'
|
|
512
|
+
import {reconcilePaidReservation} from '@t3foundry/tasra-sdk/chain'
|
|
513
|
+
|
|
514
|
+
const saved = await loadPaidReservationJournal(store, requestId)
|
|
515
|
+
if (!saved) throw new Error('Original reservation journal is required')
|
|
516
|
+
const transactionHash = saved.transactionHash ?? independentlyRecoveredHash
|
|
517
|
+
const resolution = await reconcilePaidReservation(
|
|
518
|
+
client, deployment, saved.record, expected, transactionHash, 2,
|
|
519
|
+
)
|
|
520
|
+
console.log(resolution.status, resolution.gasCost)
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
The candidate hash may come from the journal or an independent search for the original
|
|
524
|
+
payer/nonce. A matching hash alone is insufficient: the SDK checks sender, destination,
|
|
525
|
+
nonce, call data, value, chain, transaction type and gas bounds against the saved record.
|
|
526
|
+
It verifies creator consent using the original canonical quote block and requires the
|
|
527
|
+
requested confirmation depth at a fresh head. The RPC must retain that historical state;
|
|
528
|
+
missing state, unknown transactions, reorgs or missing receipts never become evidence of
|
|
529
|
+
non-submission. Expired intents can still be inspected. A successful result includes current
|
|
530
|
+
reservation state, even after final settlement or a refund. A reverted result proves only
|
|
531
|
+
that this original transaction reverted; another transaction may have reserved the same intent.
|
|
532
|
+
`gasCost` is the original transaction's consumed native gas in wei, not TASRA usage charges.
|
|
533
|
+
Neither result authorizes another spend or keeper operation. Keep the original journal;
|
|
534
|
+
the helper does not clear a payer lock, retry a payment or resume an expired session.
|
|
535
|
+
|
|
536
|
+
Pass the same `payment` and committed `random` to `createOid4vpSession`,
|
|
537
|
+
`createOauthSession` or `openVerifierAgentSession`. For the high-level session helper,
|
|
538
|
+
keep the original operation expiry fixed with `nowSecs` and `ttlSecs`; it must match
|
|
539
|
+
the expiry committed before reservation. The verifier-agent checks the session random
|
|
540
|
+
and its configured audience against that commitment. `awaitVerifierAgentResult` checks
|
|
541
|
+
that the returned token preserves the expected payment hash and its preimage.
|
|
542
|
+
|
|
543
|
+
The registered-provider path supports the same `payment` and `random` through
|
|
544
|
+
`openRegisteredVerifierAgentSession`. Its operation expiry must equal the intent expiry.
|
|
545
|
+
It validates the random/audience commitment against the selected approved agent profile
|
|
546
|
+
before disclosure and never falls back to another paid provider. The returned session
|
|
547
|
+
retains an immutable payment commitment and defensive copies of the intent. The registered
|
|
548
|
+
wallet-request check compares the disclosed payment, seed, epoch, snapshot, policy and
|
|
549
|
+
random with that intent before presentation, even if a changed context produces a
|
|
550
|
+
self-consistent nonce. Registered result polling rejects a missing or substituted payment.
|
|
551
|
+
An uncertain paid creation error retains `paymentHash`; reconcile the original payment
|
|
552
|
+
before trying another session.
|
|
553
|
+
|
|
554
|
+
For direct verifier integration, `committeeAuthorize` and `gatherCommitteeToken` carry
|
|
555
|
+
the payment with the matching request binding and pinned verification epoch. The
|
|
556
|
+
assembled token includes both `payment_hash` and `payment`.
|
|
557
|
+
|
|
558
|
+
`@t3foundry/tasra-sdk/chain` provides `readSlotFunding` for available, reserved and total TASRA,
|
|
559
|
+
and `readPaidOperationReceipt` for the exact operation's existing reservation. Both pin
|
|
560
|
+
reads to one fresh canonical block using EIP-1898 and refuse unsupported canonical reads,
|
|
561
|
+
stale heads and reorgs. The receipt also retains original cost and refunded amount after
|
|
562
|
+
settlement; reading it never authorizes another execution.
|
|
563
|
+
|
|
564
|
+
Use `resolvePaidKeeperTarget` with an independently selected deployment, slot, action and
|
|
565
|
+
payload digest. It checks the reservation, recovers the creator signature, verifies the
|
|
566
|
+
current sharing against the signed keeper assignment, and returns the assigned
|
|
567
|
+
coordinator, signed contributor endpoints and the slot's group public key. It never contacts the
|
|
568
|
+
keeper and refuses a settled payment. Supply a bounded, trusted Viem public client. HTTPS is the default; development
|
|
569
|
+
HTTP requires `allowLocalHttp: true` and chain43112 together. Fuji always requires HTTPS.
|
|
570
|
+
Private endpoint access and custom CA trust remain the application's transport policy.
|
|
571
|
+
|
|
572
|
+
Send the grant to that coordinator using the matching key-operation client and verify
|
|
573
|
+
the result against the discovered group key. Do not fail over a paid request to another keeper,
|
|
574
|
+
create a replacement reservation automatically, or treat an HTTP timeout as proof that
|
|
575
|
+
no work occurred. Keep the payment and operation identity for reconciliation.
|
|
576
|
+
|
|
577
|
+
The application ECDSA `signDigest`, FROST `sign`, and BLS `extractIdentity` / `decrypt`
|
|
578
|
+
methods accept `{authorize, payment, random, execution}` for an already reserved operation. They
|
|
579
|
+
check canonical backing and current assignment before requesting credentials and again
|
|
580
|
+
after authorization. The authorization callback receives a defensive payment copy and
|
|
581
|
+
the original expiry through `nowSecs` / `ttlSecs`; registered wallet and credential
|
|
582
|
+
authorizers forward these to session creation. A changed or missing payment in the grant
|
|
583
|
+
is refused before contacting a keeper. Signatures use the paid coordinator; IBE extraction
|
|
584
|
+
uses only the signed contributors. Results are still cryptographically verified.
|
|
585
|
+
`execution` contains the original creator-certified client certificate and its local
|
|
586
|
+
Ed25519 signer. Paid work without this capability is refused before a keeper request.
|
|
587
|
+
Keep the signer in the client; a verifier-agent does not receive its private seed.
|
|
588
|
+
|
|
589
|
+
```ts
|
|
590
|
+
const signature = await frostSlot.sign(message, {
|
|
591
|
+
authorize,
|
|
592
|
+
payment,
|
|
593
|
+
random,
|
|
594
|
+
execution: {certificate: originalCertificate, signer: originalExecutionSigner},
|
|
595
|
+
})
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
For direct keeper clients, supply `approveExecution` from
|
|
599
|
+
`createKeeperExecutionApprover` in `@t3foundry/tasra-sdk/chain`. Retain the original signed payment
|
|
600
|
+
and independently computed operation digest, approved deployment and local execution
|
|
601
|
+
certificate. The approver re-reads canonical reserved TASRA, original creator and current
|
|
602
|
+
eligible sharing before each signing callback. It signs the complete client-built body
|
|
603
|
+
for the assigned coordinator and every signed contributor; IBE requests approve only
|
|
604
|
+
the contributor being contacted. A changed ciphertext nonce, participant selection,
|
|
605
|
+
credential token or optional field changes this body commitment.
|
|
606
|
+
|
|
607
|
+
```ts
|
|
608
|
+
const approveExecution = createKeeperExecutionApprover({
|
|
609
|
+
client,
|
|
610
|
+
deployment,
|
|
611
|
+
payment,
|
|
612
|
+
expected: {slot: slotId, action: 'sign', payloadDigest},
|
|
613
|
+
certificate: originalCertificate,
|
|
614
|
+
signer: originalExecutionSigner,
|
|
615
|
+
})
|
|
616
|
+
const result = await committeeSign({
|
|
617
|
+
nodeUrl: assignedCoordinator.url,
|
|
618
|
+
committeeToken: grant.token,
|
|
619
|
+
verifierProofs: grant.verifierProofs,
|
|
620
|
+
message,
|
|
621
|
+
approveExecution,
|
|
622
|
+
})
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
The same capability is accepted by `committeeSignEoaDigest`, `committeeDecrypt`,
|
|
626
|
+
`requestIbeExtractionPartials` and paid `createDualSignClient`. The transport verifies
|
|
627
|
+
returned client signatures against the exact body before dispatch, refuses missing or
|
|
628
|
+
duplicate assigned stage approvals, and rechecks expiry. These source changes and
|
|
629
|
+
their regression cases still require the complete SDK and native deployment gates.
|
|
630
|
+
Custom `keeperUrl` mappings must preserve HTTPS. Local HTTP additionally requires
|
|
631
|
+
`allowLocalPaidHttp: true` on the application client and chain43112. The application does
|
|
632
|
+
not fail over a paid attempt or submit a replacement reservation. Each operation needs
|
|
633
|
+
its own payment; do not reuse one fixed payment for multiple Viem account calls.
|
|
634
|
+
|
|
635
|
+
Paid token signatures use a separate domain; existing unpaid token bytes stay unchanged.
|
|
636
|
+
This encoding compatibility does not enable unpaid service on a prepaid deployment.
|
|
637
|
+
The helpers cover discovery, reservation journaling and execution separately. Application-wide
|
|
638
|
+
gas nonce coordination and automatic final settlement orchestration remain separate work;
|
|
639
|
+
the helpers above do not claim a complete prepaid client.
|
|
640
|
+
|
|
641
|
+
### Client consent for paid stages
|
|
642
|
+
|
|
643
|
+
`@t3foundry/tasra-sdk/committee` provides `createLocalExecutionSigner`,
|
|
644
|
+
`createExecutionCertificate`, `approveExecutionRequest`, and
|
|
645
|
+
`verifyExecutionAuthorization` for client-owned execution consent. The application
|
|
646
|
+
keeps the Ed25519 private execution key locally. The slot creator signs a separate
|
|
647
|
+
certificate binding its public key to the original payment, deployment, request ID,
|
|
648
|
+
session commitment and expiry. Payment hashes and reservation identities stay unchanged.
|
|
649
|
+
|
|
650
|
+
Before creating a paid session, call `initializeExecutionSession` with the original
|
|
651
|
+
payment, creator certificate, local signer and an `ExpectedInitialization` built
|
|
652
|
+
from your authenticated, approved agent profile and complete create body. Generate
|
|
653
|
+
`poll_secret` locally as a nonzero 32-byte lowercase hex string and include it in
|
|
654
|
+
that body. Add only the returned `execution_initialization` envelope to the POST.
|
|
655
|
+
The signature binds the bearer, profile, payment, exact field shape and expiry.
|
|
656
|
+
`verifySessionInitialization` rechecks that consent. The hash returned by
|
|
657
|
+
`hashTypedData(executionInitializationTypedData(payment, proof))`, without its
|
|
658
|
+
`0x` prefix, is the expected session ID. Keep the same complete body and proof
|
|
659
|
+
for reconciliation after a lost reply. One original payment request allocates one session; changing
|
|
660
|
+
the body or owner requires a new payment reservation, even with a fresh client
|
|
661
|
+
initialization signature.
|
|
662
|
+
Session initialization is not a paid operator stage. It performs no fee reservation,
|
|
663
|
+
HTTP dispatch or automatic approval. This helper alone does not implement the full
|
|
664
|
+
agent transport, JAR/attest, wallet or keeper orchestration.
|
|
665
|
+
|
|
666
|
+
For each stage, independently authenticate the destination operator and construct
|
|
667
|
+
the complete unsigned request body from your own operation intent and validated
|
|
668
|
+
presentation. Pass that body as `expected.body` and the agent's complete proposal as
|
|
669
|
+
`proposal.unsigned_body`. `approveExecutionRequest` compares their canonical hashes
|
|
670
|
+
before asking the local signer to authorize the stage. Operator, stage, payment,
|
|
671
|
+
action, payload and bounded expiry are part of the signed message. An opaque hash
|
|
672
|
+
from the agent is insufficient. Explicit `null` and absent fields are different;
|
|
673
|
+
the body must contain only safe JSON values and must exclude the
|
|
674
|
+
`execution_authorization` envelope.
|
|
675
|
+
|
|
676
|
+
`ExecutionConsentPolicy` must come from your approved deployment, independently read
|
|
677
|
+
slot creator, locally retained payment hash, canonical quote or mined reservation
|
|
678
|
+
cost, and a fresh clock. The helper checks signatures and commitments; the caller
|
|
679
|
+
still checks mined backing and verifier assignment. A valid signature alone does
|
|
680
|
+
not prove funds are reserved or that a verifier was drawn.
|
|
681
|
+
|
|
682
|
+
These consent helpers do not automatically approve wallet callbacks, poll an agent
|
|
683
|
+
approval queue, dispatch operations, or settle fees. Agent delivery and application
|
|
684
|
+
orchestration are separate integrations. Never copy an untrusted proposal into
|
|
685
|
+
`expected.body` without checking every field against your own intent. Never send the
|
|
686
|
+
private seed or signing capability to the agent. Call the local signer's `dispose()`
|
|
687
|
+
when its session finishes; persisted seed copies remain the application's responsibility.
|
|
688
|
+
|
|
689
|
+
### Read a completed keeper result
|
|
690
|
+
|
|
691
|
+
Keep the original payment, operation digest, assigned worker endpoint, creator
|
|
692
|
+
certificate and local execution signer privately until the result has been received
|
|
693
|
+
and verified. `recoverKeeperExecution` reads completed work from that original worker;
|
|
694
|
+
it does not reserve funds, prepare a nonce, repeat signing or close an unused stage.
|
|
695
|
+
It remains a read after the payment or original work approval expires.
|
|
696
|
+
|
|
697
|
+
```ts
|
|
698
|
+
import {recoverKeeperExecution} from '@t3foundry/tasra-sdk/chain'
|
|
699
|
+
import {createNodeKeeperRecoveryTransport} from '@t3foundry/tasra-sdk/chain/node'
|
|
700
|
+
|
|
701
|
+
const recovered = await recoverKeeperExecution({
|
|
702
|
+
client,
|
|
703
|
+
deployment,
|
|
704
|
+
payment,
|
|
705
|
+
expected: {slot: slotId, action, payloadDigest},
|
|
706
|
+
keeper: originalAssignedKeeper,
|
|
707
|
+
target: {stage: originalStage, executionKey: originalCertificate.execution_key},
|
|
708
|
+
signer: originalLocalExecutionSigner,
|
|
709
|
+
transport: createNodeKeeperRecoveryTransport(approvedTransportPolicy),
|
|
710
|
+
})
|
|
711
|
+
// Decode the operation's retained internal result, then verify its cryptographic
|
|
712
|
+
// signature/share using recovered.observation.groupPublicKey before using it.
|
|
713
|
+
const internalResult = JSON.parse(recovered.resultJson)
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
Use an independently approved RPC deployment and the worker/client identities retained
|
|
717
|
+
before submission. The helper authenticates the worker report, then reads creator,
|
|
718
|
+
reserved TASRA and eligible keeper assignment at its original canonical block hash.
|
|
719
|
+
Every contract call requires EIP-1898 canonicality. Missing or orphaned history is
|
|
720
|
+
refused; it never falls back to latest state. The reserved fee and the original client
|
|
721
|
+
approval must match before the helper asks the local signer for a fresh read signature.
|
|
722
|
+
The current slot owner, remaining balance or payout status does not replace that history.
|
|
723
|
+
|
|
724
|
+
The helper checks the returned signed evidence and the exact retained result commitment
|
|
725
|
+
before exposing `resultJson`. This authenticates retained bytes; applications still
|
|
726
|
+
verify the result's cryptographic meaning. The internal format may differ from the
|
|
727
|
+
original HTTP response and exclude later audit metadata. IBE results use their existing
|
|
728
|
+
share commitment; added audit metadata is not part of that commitment.
|
|
729
|
+
|
|
730
|
+
The Node transport allows only the public evidence and private recovery POSTs, with
|
|
731
|
+
verified TLS, connection-time destination checks, bounded responses and no redirects.
|
|
732
|
+
Set explicit private hosts and additional CA roots through `approvedTransportPolicy`.
|
|
733
|
+
Browser applications supply an equivalently guarded `KeeperRecoveryTransport`.
|
|
734
|
+
Recovery never automatically retries key work. Missing, failed or interrupted stages,
|
|
735
|
+
HTTP refusals and unavailable history remain errors to reconcile against the original
|
|
736
|
+
payment. `KeeperRecoveryError.httpStatus` preserves HTTP refusals without private body
|
|
737
|
+
text. A lost read reply can be read again with fresh client authentication; the original
|
|
738
|
+
payment cannot be reused to start another operation.
|
|
739
|
+
|
|
740
|
+
These new recovery sources and regression cases still require the full SDK and native
|
|
741
|
+
deployment validation gates. Complete final fee orchestration remains unfinished work.
|
|
742
|
+
|
|
15
743
|
## 1. Fund the creator with AVAX
|
|
16
744
|
|
|
17
745
|
Run the [creation lesson](create-slot.md) to print your saved creator address.
|
|
@@ -124,3 +852,177 @@ if its following purchase or deposit fails.
|
|
|
124
852
|
</details>
|
|
125
853
|
|
|
126
854
|
**Next: [Read your slot →](read-slot.md)**
|
|
855
|
+
|
|
856
|
+
### Paid dual-control signatures
|
|
857
|
+
|
|
858
|
+
Reserve a final `sign` payment for SHA-256 of the exact message. Pass it as
|
|
859
|
+
`payment` and the original `{certificate, signer}` as `execution` to
|
|
860
|
+
`frostSlot.approvals({quorum, credentialGated, payment, execution})`. This resolves
|
|
861
|
+
and pins the assigned coordinator from chain. Then call `create(message)` on the
|
|
862
|
+
returned client. The lower-level `createDualSignClient` also accepts a pinned
|
|
863
|
+
`payment`, or `create(message, {payment})` when you already verified its coordinator.
|
|
864
|
+
Paid creation also requires its local `approveExecution` capability. Its complete-body
|
|
865
|
+
client approvals remain bound to the final Sign payment while credentialed approvers
|
|
866
|
+
use their separate payments. A local client-signing refusal occurs before dispatch and
|
|
867
|
+
does not become an unknown network outcome.
|
|
868
|
+
|
|
869
|
+
The request ID is the reservation ID without its `0x` prefix. Every approval signs
|
|
870
|
+
`paidDualSignApprovalPayload(chainId, slotId, message, requestId, payment)`, binding
|
|
871
|
+
the chain, slot, message, request and final payment commitment. A static approver
|
|
872
|
+
needs no credential verification. A credential approver needs a **separate** reserved
|
|
873
|
+
`dual-approve` intent whose payload digest is SHA-256 of these approval bytes. Pass
|
|
874
|
+
that intent and its fixed presentation `random` to `approveWithCredential`.
|
|
875
|
+
The final Sign payment cannot pay for credential approval work.
|
|
876
|
+
|
|
877
|
+
Opening a request and collecting approvals does not start keeper key work. A keeper
|
|
878
|
+
starts only after independently verifying the distinct approval quorum, current
|
|
879
|
+
policy, final reservation and assigned sharing. Fee settlement uses actual signed
|
|
880
|
+
work reports; a role whose operators did no work receives no fee.
|
|
881
|
+
|
|
882
|
+
Persist the message and original payments before sending. If creation has an unknown
|
|
883
|
+
outcome, its error includes the stable request ID. Resume with
|
|
884
|
+
`client.resume(requestId, message, {payment})` and poll before resubmitting. A pinned
|
|
885
|
+
client retains that payment automatically. The prepaid keeper deployment stores
|
|
886
|
+
dual-control bindings, approvals and terminal results in its encrypted durable journal.
|
|
887
|
+
After a keeper restart, resume against the original coordinator and request ID. A
|
|
888
|
+
completed result remains retrievable after the approval window expires. An interrupted
|
|
889
|
+
signing attempt is uncertain and does not reopen the payment for another execution;
|
|
890
|
+
reconcile its original payment and execution evidence.
|
|
891
|
+
|
|
892
|
+
The SDK does not run the platform's payout supervisor. Operators must configure that
|
|
893
|
+
service separately. After canonical settlement, the platform CLI can retrieve a minimal
|
|
894
|
+
claim plan from an assigned accountant with `payment claim-plan`. Save a private backup;
|
|
895
|
+
the claim command independently checks its proofs against the canonical chain root.
|
|
896
|
+
Claiming credits an operator's reward balance, and withdrawing that balance is a separate
|
|
897
|
+
transaction. Neither operation resumes keeper work or changes the saved reservation.
|
|
898
|
+
|
|
899
|
+
## Report a prepaid payout fault
|
|
900
|
+
|
|
901
|
+
When signed evidence shows a settled batch paid the wrong workers, hand it to an
|
|
902
|
+
accountant's fault witness with `submitPrepaidFaultClaim(accountantUrl, bundle)` from
|
|
903
|
+
`@t3foundry/tasra-sdk/chain`. HTTP 202 means the claim was authenticated against the mined batch
|
|
904
|
+
and stored; 400, 403 and 413 are final, 408, 429 and 503 can be sent again later (the
|
|
905
|
+
error carries `retryAfterMs`). `readPrepaidFaultStatus` reports whether a witness can
|
|
906
|
+
adjudicate. The accountant set threshold-signs a verdict; anyone can relay it with
|
|
907
|
+
`contestPrepaidFault` (simulated first, so an oracle refusal such as `WrongEpoch()` or
|
|
908
|
+
`AlreadyResolved()` is named and nothing is sent). `readPrepaidFaultResolution` shows
|
|
909
|
+
whether the offender was already punished for that batch. None of these calls retries.
|
|
910
|
+
|
|
911
|
+
## Escape a reservation nobody reconciled
|
|
912
|
+
|
|
913
|
+
On a Settlement with the prepaid timeout escape (version `"3"`), a reservation that the
|
|
914
|
+
accountant set has not reconciled within the governed escape delay can be released by
|
|
915
|
+
anyone: its full reserved cost returns to the same slot's balance, no operator is paid,
|
|
916
|
+
and the request gets the same permanent settled mark a reconcile writes, so whichever is
|
|
917
|
+
mined first is final. The refund stays in the slot balance; it is not withdrawn to you.
|
|
918
|
+
The delay is set only by governance and is not part of the SDK.
|
|
919
|
+
|
|
920
|
+
```ts
|
|
921
|
+
import {createPrepaidEscapeClient, isPrepaidEscapeError} from '@t3foundry/tasra-sdk/chain'
|
|
922
|
+
|
|
923
|
+
const escape = createPrepaidEscapeClient(publicClient, {chainId, settlement})
|
|
924
|
+
const {requests} = await escape.escapableAt({slotId, requestIds})
|
|
925
|
+
// each: 'notReserved' | 'settled' (escapedAt when escaped) | 'disabled' | 'notOpen' (opensAt) | 'open'
|
|
926
|
+
const open = requests.filter(r => r.status === 'open').map(r => r.requestId)
|
|
927
|
+
const result = await escape.escapePrepaid({slotId, requestIds: open, signer: wallet,
|
|
928
|
+
maxGas: 6_000_000n, maxGasPrice, persist: checkpoint => journal.save(checkpoint)})
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
Take the request IDs from your own durable record of the intents you signed
|
|
932
|
+
(`prepaidRequestId(payment)`), never from a history scan. `escapePrepaid` reads every
|
|
933
|
+
status at one canonical block first and refuses with `PrepaidEscapeError` unless every
|
|
934
|
+
request is `open`: `escape_not_open` carries `opensAt` and is the only retryable code;
|
|
935
|
+
`escape_disabled`, `reservation_unavailable` and `escape_unsupported` (a Settlement before
|
|
936
|
+
version `"3"`) are final. It then sends sequential transactions of at most 64 requests,
|
|
937
|
+
simulating each (a contract refusal maps to the same codes with `local: false`),
|
|
938
|
+
journaling `prepared` before the single broadcast, then `submitted` and, once the
|
|
939
|
+
`PrepaidEscaped` and `PrepaidBatchEscaped` events match the call, `confirmed`. A failure
|
|
940
|
+
after `prepared` is `PrepaidEscapeUncertainError`: never resend; call
|
|
941
|
+
`escape.reconcileEscape({record, transactionHash})`, which reads `prepaidEscapedAt`,
|
|
942
|
+
`prepaidSettled`, the receipt and the payer nonce and answers `escaped`, `completed`,
|
|
943
|
+
`reverted`, `not-escaped` (the call can no longer mine; a fresh attempt is safe) or
|
|
944
|
+
`uncertain` (read again later). `decodePrepaidEscapeRevert` names an escape refusal from a
|
|
945
|
+
call you submit another way, and `decodePrepaidEscapeLogs` decodes the events.
|
|
946
|
+
|
|
947
|
+
## Handle depleted slot credit
|
|
948
|
+
|
|
949
|
+
Catch `UnderfundedSlotError` from `@t3foundry/tasra-sdk/chain` when discovering or reserving a new
|
|
950
|
+
payment. The error carries `slotId`; discovery of an activated zero-balance slot also
|
|
951
|
+
reports `availableTasraUnits: 0n`. An accountant refusal reports `status: 402` and its
|
|
952
|
+
endpoint. The API does not return a verified required/available amount with that refusal,
|
|
953
|
+
so the SDK leaves those amounts absent instead of estimating them.
|
|
954
|
+
|
|
955
|
+
Check fresh slot funding and top up TASRA before preparing new work. Available credit
|
|
956
|
+
excludes funds already reserved by other requests. A request can be underfunded with a
|
|
957
|
+
positive balance if its fee is larger, and concurrent requests can consume credit between
|
|
958
|
+
discovery and reservation; on-chain reservation remains atomic. AVAX in the slot creator's
|
|
959
|
+
wallet pays gas and does not fund service work. An already backed operation keeps its
|
|
960
|
+
reserved fee even when the slot's available balance reaches zero.
|
|
961
|
+
|
|
962
|
+
This error is not automatically retryable. After an uncertain broadcast, reconcile the
|
|
963
|
+
saved reservation rather than submitting it again in response to a balance change.
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
The paid session control transport is `createNodePaidAgentTransport` from
|
|
967
|
+
`@t3foundry/tasra-sdk/chain/node`. It preserves HTTP425 consent waits, HTTP503 recovery
|
|
968
|
+
failures, HTTP204 approval acknowledgments and HTTP200 identical-creation
|
|
969
|
+
responses. It permits the owner bearer only on session control routes and never
|
|
970
|
+
follows redirects or retries an unknown POST. A caller must still pin the selected
|
|
971
|
+
registered provider and independently compose/check every approval body; the
|
|
972
|
+
transport does not authenticate a proposal or authorize paid work. Private hosts
|
|
973
|
+
and additional local CA roots must be explicit, with TLS verification retained.
|
|
974
|
+
|
|
975
|
+
### Registered paid session driver
|
|
976
|
+
|
|
977
|
+
`prepareRegisteredPaidSession` from `@t3foundry/tasra-sdk/chain` takes the independently
|
|
978
|
+
approved agent profile, trusted deployment, every drawn verifier's anchored Merkle
|
|
979
|
+
witness, application-verified rule hash and intended DCQL query. Supply the original
|
|
980
|
+
operation, signed payment, fixed random, creator-certified local execution signer
|
|
981
|
+
and a locally retained owner bearer. Preparation authenticates the provider and
|
|
982
|
+
reads the mined reservation and effective verifier policy before producing the
|
|
983
|
+
initialization signature. It does not submit a reservation or creation request.
|
|
984
|
+
|
|
985
|
+
Retain the returned object, bearer and local signer before calling `create()`.
|
|
986
|
+
Creation is sent once. If the reply is lost, use `reconcile()` to read the locally
|
|
987
|
+
derived session ID from the same registered provider. The owner-authenticated
|
|
988
|
+
status includes the original public encryption key, state, expiry and complete
|
|
989
|
+
binding. The driver checks these against its own intent and refuses a changed
|
|
990
|
+
context. Provider changes are checked before any owner control request.
|
|
991
|
+
|
|
992
|
+
For wallet sessions, read `proposals()` and use `approveRequest()` for the assigned
|
|
993
|
+
`presentation_sign` operator and separate drawn `presentation_attest` operators.
|
|
994
|
+
The driver rebuilds each body from the original operation and recovered context;
|
|
995
|
+
it does not sign an agent-supplied digest. Once those stages have completed,
|
|
996
|
+
`requestObject()` verifies the anchored signer's signature, session claims,
|
|
997
|
+
encryption key, query and operation context before returning a QR payload.
|
|
998
|
+
|
|
999
|
+
Read `presentations()` after the wallet callback. Independently validate and accept
|
|
1000
|
+
the complete presentation before calling `resumePresentation()` or
|
|
1001
|
+
`approveCredentials()`. Every credential is retained and included in the expected
|
|
1002
|
+
verifier body. A changed, truncated or substituted list is refused before signing.
|
|
1003
|
+
Each selected verifier is checked against both the original anchored draw and its
|
|
1004
|
+
current registered standing. HTTP425 indicates that separate consent is required;
|
|
1005
|
+
HTTP503 indicates recovery is needed. Neither triggers an automatic resend.
|
|
1006
|
+
`poll()` verifies a completed compound token's signatures, quorum, rule, operation,
|
|
1007
|
+
payment, seed and expiry against the client-owned context.
|
|
1008
|
+
|
|
1009
|
+
For OAuth sessions, select `kind: 'oauth'`. After creation or reconciliation,
|
|
1010
|
+
`oauthContext` supplies the locally derived nonce, DPoP target and chain-specific
|
|
1011
|
+
audience. Use `prepareOAuthPresentation(accessToken, dpopSigner)` with the key bound
|
|
1012
|
+
by the access token. Retain the returned complete presentation before calling
|
|
1013
|
+
`submitOAuthPresentation()` once. The client checks the token's audience and
|
|
1014
|
+
issuance time and verifies the DPoP signature, bound key, target, nonce and token
|
|
1015
|
+
hash. This does not replace the committee's issuer, rule and holder verification.
|
|
1016
|
+
HTTP202 means the callback is retained and still needs client approval. Continue
|
|
1017
|
+
through presentation selection and drawn credential approvals. After an uncertain
|
|
1018
|
+
submission, inspect the original retained callback; do not mint or resend a proof
|
|
1019
|
+
automatically.
|
|
1020
|
+
|
|
1021
|
+
The Node paid transport sends OAuth artifacts only to the original session's
|
|
1022
|
+
OAuth-response POST, with `Authorization: DPoP`, `DPoP` and a separate
|
|
1023
|
+
`X-Poll-Secret`. It preserves HTTP202 and refuses header injection, redirects,
|
|
1024
|
+
wrong routes and oversized artifacts.
|
|
1025
|
+
|
|
1026
|
+
These new driver sources and regressions still await the complete SDK verification
|
|
1027
|
+
gate and native paid-session acceptance. Keeper operation delivery and final fee
|
|
1028
|
+
settlement are separate from this authorization flow.
|