@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
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { type Account, type Address, type Chain, type Hex, type PublicClient, type Transport, type WalletClient } from 'viem';
|
|
2
|
+
import { type DebitVoucherWire, type PaymentIntentWire, type PrepaidAllowanceIntentWire } from '../committee/payment.js';
|
|
3
|
+
import type { PrepaidDeployment } from './prepaid.js';
|
|
4
|
+
/** An allowance's on-chain record (`Settlement.prepaidAllowance`) at one canonical block. */
|
|
5
|
+
export interface PrepaidAllowanceState {
|
|
6
|
+
/** Allowance id. */
|
|
7
|
+
allowanceId: Hex;
|
|
8
|
+
/** Slot it belongs to (zero when never reserved). */
|
|
9
|
+
slotId: Hex;
|
|
10
|
+
/** Immutable roster/epoch pin; zero means "not reserved". */
|
|
11
|
+
assignmentBlock: Hex;
|
|
12
|
+
/** Escrow. */
|
|
13
|
+
amount: bigint;
|
|
14
|
+
/** Settled debits so far (settle path only; not the off-chain cumulative). */
|
|
15
|
+
spent: bigint;
|
|
16
|
+
/** Per-operation cap. */
|
|
17
|
+
maxOpCost: bigint;
|
|
18
|
+
/** Expiry, Unix seconds. */
|
|
19
|
+
expiresAt: bigint;
|
|
20
|
+
/** Reservation time, Unix seconds. */
|
|
21
|
+
reservedAt: bigint;
|
|
22
|
+
/** Funded actions bitmap. */
|
|
23
|
+
actions: number;
|
|
24
|
+
/** Closed or escaped. */
|
|
25
|
+
closed: boolean;
|
|
26
|
+
/** Canonical block of the read. */
|
|
27
|
+
blockNumber: bigint;
|
|
28
|
+
/** Its hash. */
|
|
29
|
+
blockHash: Hex;
|
|
30
|
+
/** Its timestamp. */
|
|
31
|
+
blockTimestamp: bigint;
|
|
32
|
+
}
|
|
33
|
+
/** Accountant authorization of one allowance (`AllowanceResponse`); a signature is not a mined allowance. */
|
|
34
|
+
export interface PrepaidAllowanceQuote {
|
|
35
|
+
/** Slot. */
|
|
36
|
+
slot: Hex;
|
|
37
|
+
/** Derived allowance id. */
|
|
38
|
+
allowance_id: Hex;
|
|
39
|
+
/** The creator intent's EIP-712 hash (`intentHash` argument). */
|
|
40
|
+
intent_hash: Hex;
|
|
41
|
+
/** Quote block; also the allowance's assignment block. */
|
|
42
|
+
quote_block: Hex;
|
|
43
|
+
/** Reconciled legacy settlement cursor. */
|
|
44
|
+
legacy_nonce: number;
|
|
45
|
+
/** Escrow, decimal. */
|
|
46
|
+
amount: string;
|
|
47
|
+
/** Per-operation cap, decimal. */
|
|
48
|
+
max_op_cost: string;
|
|
49
|
+
/** Funded actions bitmap. */
|
|
50
|
+
actions: number;
|
|
51
|
+
/** Expiry, Unix seconds. */
|
|
52
|
+
expires_at: number;
|
|
53
|
+
/** Authorization deadline, Unix seconds. */
|
|
54
|
+
deadline: number;
|
|
55
|
+
/** Reserve digest. */
|
|
56
|
+
digest: Hex;
|
|
57
|
+
/** Threshold BN254 signature after `authorize`, null after `prepare`. */
|
|
58
|
+
signature: Hex | null;
|
|
59
|
+
/** Always false. */
|
|
60
|
+
mined: false;
|
|
61
|
+
}
|
|
62
|
+
/** Immutable identity of one allowance reservation transaction, retained before broadcast. */
|
|
63
|
+
export interface PrepaidAllowanceReservationRecord {
|
|
64
|
+
/** Record format. */
|
|
65
|
+
schema: 1;
|
|
66
|
+
/** Derived allowance id; the durable key. */
|
|
67
|
+
allowanceId: Hex;
|
|
68
|
+
/** Creator-signed intent. */
|
|
69
|
+
intent: PrepaidAllowanceIntentWire;
|
|
70
|
+
/** Signed accountant quote. */
|
|
71
|
+
quote: PrepaidAllowanceQuote;
|
|
72
|
+
/** Exact bounded legacy transaction. */
|
|
73
|
+
transaction: {
|
|
74
|
+
chainId: number;
|
|
75
|
+
from: Address;
|
|
76
|
+
to: Address;
|
|
77
|
+
data: Hex;
|
|
78
|
+
value: '0';
|
|
79
|
+
nonce: number;
|
|
80
|
+
gas: string;
|
|
81
|
+
gasPrice: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Durable checkpoints, as for a per-operation reservation. A timeout after `prepared` needs observation, never a new attempt. */
|
|
85
|
+
export type PrepaidAllowanceCheckpoint = {
|
|
86
|
+
/** Persisted before submission. */
|
|
87
|
+
phase: 'prepared';
|
|
88
|
+
/** Exact identity. */
|
|
89
|
+
record: PrepaidAllowanceReservationRecord;
|
|
90
|
+
/** Local signer's hash, journaled before broadcast. */
|
|
91
|
+
transactionHash?: Hex;
|
|
92
|
+
} | {
|
|
93
|
+
/** A hash was returned; mining unproven. */
|
|
94
|
+
phase: 'submitted';
|
|
95
|
+
/** Allowance id. */
|
|
96
|
+
allowanceId: Hex;
|
|
97
|
+
/** Hash. */
|
|
98
|
+
transactionHash: Hex;
|
|
99
|
+
} | {
|
|
100
|
+
/** Mined and canonical. */
|
|
101
|
+
phase: 'confirmed';
|
|
102
|
+
/** Allowance id. */
|
|
103
|
+
allowanceId: Hex;
|
|
104
|
+
/** Hash. */
|
|
105
|
+
transactionHash: Hex;
|
|
106
|
+
/** Inclusion block. */
|
|
107
|
+
blockHash: Hex;
|
|
108
|
+
};
|
|
109
|
+
/** Limits and mandatory durable storage for one allowance reservation. */
|
|
110
|
+
export interface ReservePrepaidAllowanceOptions {
|
|
111
|
+
/** Independently selected accountant endpoints. */
|
|
112
|
+
accountantUrls: readonly string[];
|
|
113
|
+
/** HTTP only on local chain 43112. */
|
|
114
|
+
allowLocalHttp?: boolean;
|
|
115
|
+
/** Maximum gas units. */
|
|
116
|
+
maxGas: bigint;
|
|
117
|
+
/** Maximum legacy gas price, wei. */
|
|
118
|
+
maxGasPrice: bigint;
|
|
119
|
+
/** Per-accountant timeout, 1..85000 ms (default 85000). */
|
|
120
|
+
requestTimeoutMs?: number;
|
|
121
|
+
/** Receipt timeout, 1..120000 ms (default 60000). */
|
|
122
|
+
receiptTimeoutMs?: number;
|
|
123
|
+
/** Confirmations, 1..64 (default 1). */
|
|
124
|
+
confirmations?: number;
|
|
125
|
+
/** Cancellation: honoured until the `prepared` checkpoint; afterwards it only ends the receipt wait (uncertain). */
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
/**
|
|
128
|
+
* Canonical block the intent's verifier epoch was observed at. The first prepare names it (else
|
|
129
|
+
* the client's fresh latest block), so every member judges the same chain state; when every
|
|
130
|
+
* member refuses before writing there, the round is repeated once at the client's latest block.
|
|
131
|
+
* No prepare is ever sent without a block.
|
|
132
|
+
*/
|
|
133
|
+
quoteBlock?: Hex;
|
|
134
|
+
/** Await durable storage. `prepared` must create a unique record keyed by allowance id and survive process loss. */
|
|
135
|
+
persist: (checkpoint: PrepaidAllowanceCheckpoint) => Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
/** Quote freshness the accountants enforce (`MAX_QUOTE_AGE`). */
|
|
138
|
+
export declare const ALLOWANCE_QUOTE_MAX_AGE_SECS = 30;
|
|
139
|
+
/** `PAYMENT_INTENT_MAX_LIFETIME_SECS`: an allowance lives at most one hour. */
|
|
140
|
+
export declare const ALLOWANCE_MAX_LIFETIME_SECS = 3600;
|
|
141
|
+
/**
|
|
142
|
+
* The allowance id every reader derives from a creator intent.
|
|
143
|
+
* @param intent - Creator intent (signature not part of the preimage).
|
|
144
|
+
*/
|
|
145
|
+
export declare function prepaidAllowanceId(intent: Omit<PrepaidAllowanceIntentWire, 'signature'>): Hex;
|
|
146
|
+
/**
|
|
147
|
+
* Read `Settlement.prepaidAllowance(id)` at a canonical block (`blockHash`), or at a fresh head.
|
|
148
|
+
* @param client - Trusted RPC client.
|
|
149
|
+
* @param deployment - Approved deployment.
|
|
150
|
+
* @param id - Allowance id.
|
|
151
|
+
* @param blockHash - Canonical block to read at; a fresh latest head (<= 30 s) when absent.
|
|
152
|
+
*/
|
|
153
|
+
export declare function readPrepaidAllowance(client: PublicClient, deployment: PrepaidDeployment, id: Hex, blockHash?: Hex): Promise<PrepaidAllowanceState>;
|
|
154
|
+
/**
|
|
155
|
+
* Reserve one allowance for a creator-signed intent: quorum quote, one bounded legacy transaction,
|
|
156
|
+
* the durable checkpoints, the receipt and the mined record. Never resubmits or replaces; an
|
|
157
|
+
* outcome unknown after `prepared` is {@link PaidReservationUncertainError} (its `requestId` is the
|
|
158
|
+
* allowance id).
|
|
159
|
+
* @param client - Trusted RPC client; submission retries disabled.
|
|
160
|
+
* @param wallet - Dedicated account-bound gas payer.
|
|
161
|
+
* @param deployment - Approved deployment.
|
|
162
|
+
* @param original - Creator-signed allowance intent.
|
|
163
|
+
* @param options - Endpoints, gas limits and mandatory durable persistence.
|
|
164
|
+
*/
|
|
165
|
+
export declare function reservePrepaidAllowance(client: PublicClient, wallet: WalletClient<Transport, Chain, Account>, deployment: PrepaidDeployment, original: PrepaidAllowanceIntentWire, options: ReservePrepaidAllowanceOptions): Promise<{
|
|
166
|
+
transactionHash: Hex;
|
|
167
|
+
allowance: PrepaidAllowanceState;
|
|
168
|
+
quote: PrepaidAllowanceQuote;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Whether a prepared allowance reservation is mined as signed, read at a fresh head. `reserved`
|
|
172
|
+
* proves it; `not-reserved` is final only once a canonical block is past the quote deadline
|
|
173
|
+
* (the contract refuses the signed quote from then on); otherwise `uncertain`.
|
|
174
|
+
* @param client - Trusted RPC client.
|
|
175
|
+
* @param deployment - Approved deployment.
|
|
176
|
+
* @param record - The durable `prepared` record.
|
|
177
|
+
*/
|
|
178
|
+
export declare function reconcilePrepaidAllowance(client: PublicClient, deployment: PrepaidDeployment, record: PrepaidAllowanceReservationRecord): Promise<{
|
|
179
|
+
state: 'reserved' | 'not-reserved' | 'uncertain';
|
|
180
|
+
allowance: PrepaidAllowanceState;
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* `beacon.mpk()` at a canonical block, via `Settlement.beacon()` read at the same block.
|
|
184
|
+
* @param client - Trusted RPC client.
|
|
185
|
+
* @param deployment - Approved deployment (with the approved beacon, when known).
|
|
186
|
+
* @param blockHash - Quote block.
|
|
187
|
+
*/
|
|
188
|
+
export declare function readAccountantGroupKey(client: PublicClient, deployment: PrepaidDeployment & {
|
|
189
|
+
beacon?: Address;
|
|
190
|
+
}, blockHash: Hex): Promise<Uint8Array>;
|
|
191
|
+
/**
|
|
192
|
+
* Verify a debit voucher's shape and its threshold signature against `beacon.mpk()` at its quote block.
|
|
193
|
+
* @param client - Trusted RPC client.
|
|
194
|
+
* @param deployment - Approved deployment.
|
|
195
|
+
* @param voucher - Untrusted voucher.
|
|
196
|
+
*/
|
|
197
|
+
export declare function verifyDebitVoucher(client: PublicClient, deployment: PrepaidDeployment & {
|
|
198
|
+
beacon?: Address;
|
|
199
|
+
}, voucher: DebitVoucherWire): Promise<void>;
|
|
200
|
+
/** One member's answer to `POST /v1/prepaid/allowances/{id}/debits` (`DebitPartialResponse`). */
|
|
201
|
+
export interface DebitPartialWire {
|
|
202
|
+
/** Allowance. */
|
|
203
|
+
allowance_id: Hex;
|
|
204
|
+
/** Sequence. */
|
|
205
|
+
seq: number;
|
|
206
|
+
/** Request. */
|
|
207
|
+
request_id: Hex;
|
|
208
|
+
/** Cost at the quote block, decimal. */
|
|
209
|
+
cost: string;
|
|
210
|
+
/** Total through seq, decimal. */
|
|
211
|
+
cumulative: string;
|
|
212
|
+
/** Quote block. */
|
|
213
|
+
quote_block: Hex;
|
|
214
|
+
/** Digest the partial is over. */
|
|
215
|
+
digest: Hex;
|
|
216
|
+
/** Member identifier. */
|
|
217
|
+
identifier: number;
|
|
218
|
+
/** 64-byte partial. */
|
|
219
|
+
partial: Hex;
|
|
220
|
+
/** 128-byte verifying share. */
|
|
221
|
+
verifying_share: Hex;
|
|
222
|
+
/** The sharing the partial belongs to. */
|
|
223
|
+
sharing: Hex;
|
|
224
|
+
/** k. */
|
|
225
|
+
threshold: number;
|
|
226
|
+
/** n. */
|
|
227
|
+
members: number;
|
|
228
|
+
}
|
|
229
|
+
/** One debit request: the same body is sent to every member. */
|
|
230
|
+
export interface DebitRequest {
|
|
231
|
+
/** Creator-signed allowance payment WITHOUT a voucher. */
|
|
232
|
+
payment: PaymentIntentWire;
|
|
233
|
+
/** Sequence (1 without a previous voucher). */
|
|
234
|
+
seq: number;
|
|
235
|
+
/** Quorum voucher of `seq - 1`. */
|
|
236
|
+
previous?: DebitVoucherWire;
|
|
237
|
+
/** The quote block every member reads at (fixed by the caller and journaled before the round). */
|
|
238
|
+
quoteBlock: Hex;
|
|
239
|
+
/** The allowance's per-operation cap, from its mined record. */
|
|
240
|
+
maxOpCost: bigint;
|
|
241
|
+
}
|
|
242
|
+
/** How one member answered a debit round. */
|
|
243
|
+
export type DebitMemberOutcome = {
|
|
244
|
+
/** Endpoint. */
|
|
245
|
+
url: string;
|
|
246
|
+
/** A verified partial. */
|
|
247
|
+
kind: 'partial';
|
|
248
|
+
/** The partial. */
|
|
249
|
+
partial: DebitPartialWire;
|
|
250
|
+
} | {
|
|
251
|
+
/** Endpoint. */
|
|
252
|
+
url: string;
|
|
253
|
+
/** Transport loss, 5xx, 408 or 429: the member may have journaled the debit. */
|
|
254
|
+
kind: 'unavailable';
|
|
255
|
+
/** Safe reason. */
|
|
256
|
+
reason: string;
|
|
257
|
+
} | {
|
|
258
|
+
/** Endpoint. */
|
|
259
|
+
url: string;
|
|
260
|
+
/** A definite refusal (another 4xx) or an invalid answer. */
|
|
261
|
+
kind: 'refused';
|
|
262
|
+
/** HTTP status (0 = invalid answer). */
|
|
263
|
+
status: number;
|
|
264
|
+
/** Safe reason. */
|
|
265
|
+
reason: string;
|
|
266
|
+
};
|
|
267
|
+
/** A voucher round ended without `k` verified partials. */
|
|
268
|
+
export declare class DebitVoucherError extends Error {
|
|
269
|
+
readonly outcomes: DebitMemberOutcome[];
|
|
270
|
+
readonly partials: number;
|
|
271
|
+
/** Threshold, when any member named it. */ readonly threshold: number | undefined;
|
|
272
|
+
/** Stable reason. */
|
|
273
|
+
readonly code: "debit-voucher-unavailable";
|
|
274
|
+
constructor(/** Every member's outcome. */ outcomes: DebitMemberOutcome[], /** Partials obtained. */ partials: number,
|
|
275
|
+
/** Threshold, when any member named it. */ threshold: number | undefined);
|
|
276
|
+
/** True when no member is unavailable: every member that did not sign definitely refused. */
|
|
277
|
+
get definite(): boolean;
|
|
278
|
+
/** True when any member signed this seq for this request (it is then bound to it at those members). */
|
|
279
|
+
get claimed(): boolean;
|
|
280
|
+
}
|
|
281
|
+
/** Options for {@link collectDebitVoucher}. */
|
|
282
|
+
export interface CollectDebitVoucherOptions {
|
|
283
|
+
/** Approved accountant endpoints (all are asked). */
|
|
284
|
+
accountantUrls: readonly string[];
|
|
285
|
+
/** HTTP only on local chain 43112. */
|
|
286
|
+
allowLocalHttp?: boolean;
|
|
287
|
+
/** Per-member timeout, 1..60000 ms (default 15000). */
|
|
288
|
+
requestTimeoutMs?: number;
|
|
289
|
+
/** Cancellation. An abort after the round started may leave partials journaled at members. */
|
|
290
|
+
signal?: AbortSignal;
|
|
291
|
+
/** Partials already obtained for this exact request (from an earlier attempt of the round). */
|
|
292
|
+
known?: readonly DebitPartialWire[];
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Obtain one debit voucher: the same request to every accountant in parallel, each answer checked
|
|
296
|
+
* against the request, `k` partials of one sharing combined and the aggregate verified against
|
|
297
|
+
* `beacon.mpk()` at the quote block (read while the members answer).
|
|
298
|
+
*
|
|
299
|
+
* The voucher is returned as soon as `k` answers combine into an aggregate the group key verifies:
|
|
300
|
+
* that check alone makes the voucher valid, so the round neither waits for the remaining members
|
|
301
|
+
* (their requests run on in the background; the voucher reaches them by the push) nor checks each
|
|
302
|
+
* partial against its share first. Only when an aggregate fails are the partials checked one by
|
|
303
|
+
* one, which names the member whose partial does not verify and drops it from the next subsets.
|
|
304
|
+
* Without `k` the round waits for every member, checks every partial and throws
|
|
305
|
+
* {@link DebitVoucherError} with each member's outcome.
|
|
306
|
+
* @param client - Trusted RPC client (group key read).
|
|
307
|
+
* @param deployment - Approved deployment (with the approved beacon, when known).
|
|
308
|
+
* @param request - Payment, sequence, previous voucher, journaled quote block and the allowance cap.
|
|
309
|
+
* @param options - Endpoints, timeout, cancellation and already-known partials.
|
|
310
|
+
* @returns The voucher, the `k` partials combined into it and the outcomes of the members that had answered.
|
|
311
|
+
*/
|
|
312
|
+
export declare function collectDebitVoucher(client: PublicClient, deployment: PrepaidDeployment & {
|
|
313
|
+
beacon?: Address;
|
|
314
|
+
}, request: DebitRequest, options: CollectDebitVoucherOptions): Promise<{
|
|
315
|
+
voucher: DebitVoucherWire;
|
|
316
|
+
partials: DebitPartialWire[];
|
|
317
|
+
outcomes: DebitMemberOutcome[];
|
|
318
|
+
}>;
|
|
319
|
+
/** One member's answer to `POST /v1/prepaid/allowances/{id}/vouchers`. */
|
|
320
|
+
export type VoucherPushOutcome = {
|
|
321
|
+
/** Endpoint. */
|
|
322
|
+
url: string;
|
|
323
|
+
/** The member verified the voucher against the group key and journaled it (`recorded`: unchanged, attached or observed). */
|
|
324
|
+
kind: 'accepted';
|
|
325
|
+
/** The member's decision. */
|
|
326
|
+
recorded: string;
|
|
327
|
+
} | {
|
|
328
|
+
/** Endpoint. */
|
|
329
|
+
url: string;
|
|
330
|
+
/** Transport loss, timeout, a non-2xx answer or an invalid answer. */
|
|
331
|
+
kind: 'failed';
|
|
332
|
+
/** HTTP status (0 = transport or invalid answer). */
|
|
333
|
+
status: number;
|
|
334
|
+
/** Safe reason. */
|
|
335
|
+
reason: string;
|
|
336
|
+
};
|
|
337
|
+
/** Options for {@link pushDebitVoucher}. */
|
|
338
|
+
export interface PushDebitVoucherOptions {
|
|
339
|
+
/** Accountant endpoints to push to. */
|
|
340
|
+
accountantUrls: readonly string[];
|
|
341
|
+
/** HTTP only on local chain 43112. */
|
|
342
|
+
allowLocalHttp?: boolean;
|
|
343
|
+
/** Per-member timeout, 1..60000 ms (default 10000). */
|
|
344
|
+
requestTimeoutMs?: number;
|
|
345
|
+
/** Members pushed at once, 1..32 (default 4). */
|
|
346
|
+
concurrency?: number;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Push an aggregated debit voucher to accountant members (`POST /v1/prepaid/allowances/{id}/vouchers`).
|
|
350
|
+
* A member learns a seq's aggregate from the next debit's `previous`; the last seq of a lane is
|
|
351
|
+
* never anyone's `previous`, so this is how members that will never see it as `previous` learn it.
|
|
352
|
+
* Each member verifies it against the group key at its quote block; the push is idempotent.
|
|
353
|
+
* Never rejects for a member failure: every member's answer is returned as an outcome.
|
|
354
|
+
* @param chainId - Deployment chain (endpoint transport policy).
|
|
355
|
+
* @param voucher - A verified aggregated voucher.
|
|
356
|
+
* @param options - Endpoints, timeout and concurrency.
|
|
357
|
+
*/
|
|
358
|
+
export declare function pushDebitVoucher(chainId: number, voucher: DebitVoucherWire, options: PushDebitVoucherOptions): Promise<VoucherPushOutcome[]>;
|