@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,325 @@
|
|
|
1
|
+
import { type Account, type Address, type Chain, type Hex, type LocalAccount, type PublicClient, type Transport, type WalletClient } from 'viem';
|
|
2
|
+
import { type AllowanceAction, type DebitVoucherWire, type PaymentIntentWire } from '../committee/payment.js';
|
|
3
|
+
import type { DiscoveredPaymentFields, PaidOperationContext, PrepaidDeployment } from '../chain/prepaid.js';
|
|
4
|
+
import { TasraError } from '../errors.js';
|
|
5
|
+
import type { ApplicationStore } from './ready-slot.js';
|
|
6
|
+
/** Explicit, default-off allowance funding for paid operations. */
|
|
7
|
+
export interface PaidAllowanceOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Explicit opt-in. Set it only when every reader on the deployment (agent, verifiers, keepers,
|
|
10
|
+
* accountants) supports prepaid allowances: the network advertises no capability for it.
|
|
11
|
+
*/
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
/** Escrow locked per allowance, TASRA base units. Allowances are fixed-amount; a top-up is a new one. */
|
|
14
|
+
amount: bigint;
|
|
15
|
+
/** Per-operation cap of each allowance (default the operation limit `limits.maxCost`); at most `amount`. */
|
|
16
|
+
maxOpCost?: bigint;
|
|
17
|
+
/** Funded actions (default every action an allowance can fund). */
|
|
18
|
+
actions?: readonly AllowanceAction[];
|
|
19
|
+
/** Allowance lifetime, 900..3600 s (default 3600, the protocol maximum). */
|
|
20
|
+
lifetimeSecs?: number;
|
|
21
|
+
/** Expected concurrent operations; lanes default to min(streams, 8). Default 1. */
|
|
22
|
+
streams?: number;
|
|
23
|
+
/** Lane count override, 1..8. */
|
|
24
|
+
lanes?: number;
|
|
25
|
+
/** Reserve replacements in the background (default true). */
|
|
26
|
+
reserveAhead?: boolean;
|
|
27
|
+
/** Per-accountant debit request timeout, ms (default 15000). */
|
|
28
|
+
debitTimeoutMs?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Session grants: escrow locked per DRAW-lane allowance (default `amount`). A session grant's
|
|
31
|
+
* messages must pay its exact verifier draw, which moves every beacon epoch; draw lanes hold
|
|
32
|
+
* allowances reserved on one draw each (see {@link selectAllowanceLane}). At least the
|
|
33
|
+
* per-operation cap.
|
|
34
|
+
*/
|
|
35
|
+
drawAmount?: bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Most draw-lane allowances per slot whose escrow may still be locked (reserved, not yet past
|
|
38
|
+
* `expiresAt` plus the accountants' close grace), 1..1024 (default 4 x lanes, i.e. at most
|
|
39
|
+
* `4 x lanes x drawAmount` locked beside the regular lanes' `2 x lanes x amount`). At the
|
|
40
|
+
* bound a session message pays per operation instead of reserving another allowance. On a
|
|
41
|
+
* beacon faster than (lifetime + close grace) / 2 per epoch, size `drawAmount` down and this up.
|
|
42
|
+
*/
|
|
43
|
+
maxDrawAllowances?: number;
|
|
44
|
+
}
|
|
45
|
+
/** What paid-operation.ts needs from the pool. */
|
|
46
|
+
export interface AllowanceEnv {
|
|
47
|
+
client: PublicClient;
|
|
48
|
+
deployment: PrepaidDeployment & {
|
|
49
|
+
beacon: Address;
|
|
50
|
+
};
|
|
51
|
+
creator: Pick<LocalAccount, 'address' | 'signTypedData'>;
|
|
52
|
+
gasPayer: WalletClient<Transport, Chain, Account>;
|
|
53
|
+
store: ApplicationStore;
|
|
54
|
+
accountantUrls: readonly string[];
|
|
55
|
+
allowLocalHttp?: boolean;
|
|
56
|
+
limits: {
|
|
57
|
+
maxCost: bigint;
|
|
58
|
+
maxGas: bigint;
|
|
59
|
+
maxGasPrice: bigint;
|
|
60
|
+
};
|
|
61
|
+
options: PaidAllowanceOptions;
|
|
62
|
+
/**
|
|
63
|
+
* Session-grant reserve-ahead: a fresh payment discovery pinned to `epoch`
|
|
64
|
+
* (`discoverPaidOperationContext({verificationEpoch})`, which verifies the draw at a canonical
|
|
65
|
+
* head and refuses one that is not the beacon's latest or previous). Without it a new draw's
|
|
66
|
+
* lane is reserved only once a message needs it.
|
|
67
|
+
*/
|
|
68
|
+
discover?: (slot: Hex, epoch: bigint) => Promise<PaidOperationContext>;
|
|
69
|
+
}
|
|
70
|
+
/** The lane an operation was assigned: its allowance and the payment fields it must sign. */
|
|
71
|
+
export interface AllowanceTicket {
|
|
72
|
+
/** Lane index. */
|
|
73
|
+
lane: number;
|
|
74
|
+
/** Allowance the payment names. */
|
|
75
|
+
allowanceId: Hex;
|
|
76
|
+
/** Verification and keeper fields copied from the allowance (coordinator from current discovery). */
|
|
77
|
+
fields: DiscoveredPaymentFields;
|
|
78
|
+
}
|
|
79
|
+
/** The allowance path cannot fund this operation; nothing more will be requested for it. Fall back to a per-operation reservation. */
|
|
80
|
+
export declare class AllowanceRefusedError extends TasraError {
|
|
81
|
+
/** Stable reason. */
|
|
82
|
+
readonly code: "allowance-refused";
|
|
83
|
+
constructor(message: string, cause?: unknown);
|
|
84
|
+
}
|
|
85
|
+
/** Accountants were unreachable: the debit stays pending for the same seq and request; resume retries it. */
|
|
86
|
+
export declare class AllowanceUnavailableError extends TasraError {
|
|
87
|
+
/** Stable reason. */
|
|
88
|
+
readonly code: "allowance-unavailable";
|
|
89
|
+
constructor(message: string, cause?: unknown);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validate the allowance options against the operation limits.
|
|
93
|
+
* @param options - Allowance options.
|
|
94
|
+
* @param limits - Operation limits.
|
|
95
|
+
*/
|
|
96
|
+
export declare function validateAllowanceOptions(options: PaidAllowanceOptions, limits: {
|
|
97
|
+
maxCost: bigint;
|
|
98
|
+
}): void;
|
|
99
|
+
/**
|
|
100
|
+
* Lane count: `lanes`, else min(streams, 8).
|
|
101
|
+
* @param options - Allowance options.
|
|
102
|
+
*/
|
|
103
|
+
export declare function allowanceLaneCount(options: PaidAllowanceOptions): number;
|
|
104
|
+
/**
|
|
105
|
+
* The aggregated voucher journaled for a request, if any.
|
|
106
|
+
* @param store - Application store.
|
|
107
|
+
* @param requestId - Operation request ID.
|
|
108
|
+
*/
|
|
109
|
+
export declare function journaledAllowanceVoucher(store: ApplicationStore, requestId: Hex): Promise<DebitVoucherWire | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* The operation a lane must fund. `drawPinned`: only an allowance drawn on exactly the discovered
|
|
112
|
+
* verifier draw, and no reserved-ahead promotion (a session grant's opening, which
|
|
113
|
+
* verifiers judge at the LIVE beacon, and its messages, whose keeper refuses any draw but the grant's).
|
|
114
|
+
*/
|
|
115
|
+
export interface AllowanceOperation {
|
|
116
|
+
action: AllowanceAction;
|
|
117
|
+
expires: number;
|
|
118
|
+
drawPinned?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Pick a lane whose current allowance can fund this operation, or undefined (fall back to a
|
|
122
|
+
* per-operation reservation). Starts background reservations for missing or low lanes. When no
|
|
123
|
+
* lane can fund it but one of this slot's lanes is being reserved in this process, waits for that
|
|
124
|
+
* reservation (at most {@link LANE_WAIT_MS}) and selects once more: a per-operation reservation
|
|
125
|
+
* would queue behind it on the same gas payer, so the fallback costs a second transaction and at
|
|
126
|
+
* least twice the wait (long enough, under contention, to outlive the verifier epoch it signed).
|
|
127
|
+
* @param env - Allowance environment.
|
|
128
|
+
* @param context - Fresh discovery for this operation.
|
|
129
|
+
* @param operation - The paid action and the payment expiry.
|
|
130
|
+
*/
|
|
131
|
+
export declare function selectAllowanceLane(env: AllowanceEnv, context: PaidOperationContext, operation: AllowanceOperation): Promise<AllowanceTicket | undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Reserve (or reconcile) one lane's next allowance now. Exposed for applications that want lanes
|
|
134
|
+
* ready before the first operation; operations otherwise trigger it in the background.
|
|
135
|
+
* @param env - Allowance environment.
|
|
136
|
+
* @param context - Fresh discovery for the slot (verification epoch and keeper sharing of the allowance).
|
|
137
|
+
* @param lane - Lane index.
|
|
138
|
+
* @param signal - Cancellation (honoured until the reservation is prepared).
|
|
139
|
+
* @param ready - What the lane must be ready for (see {@link LaneReadiness}); unset, the plain `low()` rule.
|
|
140
|
+
*/
|
|
141
|
+
export declare function reserveForLane(env: AllowanceEnv, context: PaidOperationContext, lane: number, signal?: AbortSignal, ready?: LaneReadiness): Promise<'reserved' | 'pending' | 'not-needed'>;
|
|
142
|
+
/**
|
|
143
|
+
* Open one regular lane ahead of its first operation (see `prepareAllowances` in paid-operation.ts).
|
|
144
|
+
* The reservation is {@link reserveForLane}'s, journaled phase by phase exactly as a background
|
|
145
|
+
* refill: no other path. Before anything is discovered or signed:
|
|
146
|
+
* - a reservation of this lane already running in this process (an operation's refill) is awaited,
|
|
147
|
+
* never doubled, and the lane judged again after it;
|
|
148
|
+
* - a lane that needs nothing (a usable confirmed allowance, or a confirmed one reserved ahead)
|
|
149
|
+
* reports `not-needed` without a discovery, a signature or a send.
|
|
150
|
+
* With `ready` ({@link LaneReadiness}) "needs nothing" means ready for the coming work: when the
|
|
151
|
+
* current allowance is not confirmed, low, expires within `minLifetimeSecs`, or the lane cannot
|
|
152
|
+
* fund `minOperations`, the NEXT allowance is reserved ahead (and the lane judged again). A lane
|
|
153
|
+
* whose current allowance is spent takes its confirmed next over first, exactly as an operation
|
|
154
|
+
* would; one still short while holding both throws {@link AllowanceCapacityError}, never a third.
|
|
155
|
+
* Otherwise `discover` is called for a FRESH context (never one cached across lanes) and the lane is
|
|
156
|
+
* reserved; the reservation is registered as this lane's refill, so an operation selecting meanwhile
|
|
157
|
+
* waits for it (bounded) instead of starting its own.
|
|
158
|
+
* @param env - Allowance environment.
|
|
159
|
+
* @param slot - Slot.
|
|
160
|
+
* @param lane - Regular lane index, 0..lanes-1.
|
|
161
|
+
* @param discover - Fresh discovery for the slot (`fundedByAllowance`), called at most once per reservation.
|
|
162
|
+
* @param signal - Cancellation (honoured until the reservation is prepared; afterwards it is reconciled).
|
|
163
|
+
* @param ready - What the lane must be ready for (default: the plain `low()` rule).
|
|
164
|
+
*/
|
|
165
|
+
export declare function prepareAllowanceLane(env: AllowanceEnv, slot: Hex, lane: number, discover: () => Promise<PaidOperationContext>, signal?: AbortSignal, ready?: LaneReadiness): Promise<'reserved' | 'pending' | 'not-needed'>;
|
|
166
|
+
/**
|
|
167
|
+
* What a lane must be ready for, beyond today's `low()` rule ({@link prepareAllowanceLane}).
|
|
168
|
+
* Unset (or 0) keeps the plain rule: a confirmed, not-low current allowance, or a confirmed one
|
|
169
|
+
* reserved ahead, is enough.
|
|
170
|
+
*/
|
|
171
|
+
export interface LaneReadiness {
|
|
172
|
+
/**
|
|
173
|
+
* The lane must fund at least this many more operations at the per-operation cap
|
|
174
|
+
* (`limits.maxCost`) from its current allowance and its reserved-ahead one together; only an
|
|
175
|
+
* allowance that outlives `minLifetimeSecs` counts. At most 2 x floor(amount / maxCost).
|
|
176
|
+
*/
|
|
177
|
+
minOperations?: number;
|
|
178
|
+
/**
|
|
179
|
+
* The current allowance must outlive this many seconds, else the next one is reserved ahead (and
|
|
180
|
+
* must outlive it). At most the allowance lifetime minus 120 s (minus `work.ttlSecs` with `work`).
|
|
181
|
+
*/
|
|
182
|
+
minLifetimeSecs?: number;
|
|
183
|
+
/**
|
|
184
|
+
* The operations the coming work runs ({@link LaneWork}). With it an allowance counts only when
|
|
185
|
+
* lane selection would accept it for EVERY one of them, for an operation started at any moment
|
|
186
|
+
* of `minLifetimeSecs`: the same predicate, never a looser one.
|
|
187
|
+
*/
|
|
188
|
+
work?: LaneWork;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* What the coming work's operations need of an allowance, judged by the predicate lane selection
|
|
192
|
+
* applies ({@link selectAllowanceLane}): each action funded, the keeper sharing (key epoch,
|
|
193
|
+
* committee version, threshold, contributors) of the fresh discovery `context`, and an expiry at
|
|
194
|
+
* least `ttlSecs` (the operations' payment lifetime) plus the clock margin beyond the moment the
|
|
195
|
+
* operation starts. A regular lane is never judged on its verifier draw (selection pins a draw only
|
|
196
|
+
* for session grants, whose draw lanes are not prepared).
|
|
197
|
+
*/
|
|
198
|
+
export interface LaneWork {
|
|
199
|
+
/** Fresh discovery of the slot (`fundedByAllowance`): the keeper sharing an operation would be paid under now. */
|
|
200
|
+
context: PaidOperationContext;
|
|
201
|
+
/** The paid actions as payments carry them (`eoa-sign` on a threshold-ECDSA slot), 1..5 distinct. */
|
|
202
|
+
actions: readonly AllowanceAction[];
|
|
203
|
+
/** The operations' payment lifetime, 1..3600 s (`PaidOperationRequest.operation.ttlSecs`, default 600). */
|
|
204
|
+
ttlSecs: number;
|
|
205
|
+
}
|
|
206
|
+
/** The lane cannot hold what the coming work needs: it already holds a current and a reserved-ahead allowance. */
|
|
207
|
+
export declare class AllowanceCapacityError extends TasraError {
|
|
208
|
+
/** The allowance lane that is full. */
|
|
209
|
+
readonly lane: number;
|
|
210
|
+
/** Operations the lane can still fund within the required lifetime. */
|
|
211
|
+
readonly operations: number;
|
|
212
|
+
/** Stable reason. */
|
|
213
|
+
readonly code: "allowance-capacity";
|
|
214
|
+
constructor(
|
|
215
|
+
/** The allowance lane that is full. */
|
|
216
|
+
lane: number,
|
|
217
|
+
/** Operations the lane can still fund within the required lifetime. */
|
|
218
|
+
operations: number, ready: LaneReadiness);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Validate a lane readiness request against the allowance options.
|
|
222
|
+
* @param env - Allowance environment.
|
|
223
|
+
* @param ready - Readiness request.
|
|
224
|
+
*/
|
|
225
|
+
export declare function validateLaneReadiness(env: AllowanceEnv, ready: LaneReadiness): void;
|
|
226
|
+
/**
|
|
227
|
+
* Validate that an operation of lifetime `ttlSecs` started at the end of a `minLifetimeSecs` horizon
|
|
228
|
+
* can be funded by a fresh allowance at all ({@link LaneWork}).
|
|
229
|
+
* @param env - Allowance environment.
|
|
230
|
+
* @param minLifetimeSecs - Readiness horizon, seconds.
|
|
231
|
+
* @param ttlSecs - The operations' payment lifetime, seconds.
|
|
232
|
+
*/
|
|
233
|
+
export declare function validateReadinessHorizon(env: AllowanceEnv, minLifetimeSecs: number, ttlSecs: number): void;
|
|
234
|
+
/**
|
|
235
|
+
* Obtain (or re-read) the debit voucher of one allowance-backed payment on its lane. Journals the
|
|
236
|
+
* debit before any request; resumes the same seq, request and quote block. Throws
|
|
237
|
+
* {@link AllowanceRefusedError} (lane retired, fall back) or {@link AllowanceUnavailableError} (retry later).
|
|
238
|
+
* @param env - Allowance environment.
|
|
239
|
+
* @param ticket - The lane the payment was signed for.
|
|
240
|
+
* @param payment - Creator-signed allowance payment without a voucher.
|
|
241
|
+
* @param signal - Cancellation of the network round (an aborted round stays pending).
|
|
242
|
+
*/
|
|
243
|
+
export declare function obtainAllowanceVoucher(env: AllowanceEnv, ticket: {
|
|
244
|
+
lane: number;
|
|
245
|
+
}, payment: PaymentIntentWire, signal?: AbortSignal, options?: ObtainVoucherOptions): Promise<DebitVoucherWire>;
|
|
246
|
+
/** Options of {@link obtainAllowanceVoucher}. */
|
|
247
|
+
export interface ObtainVoucherOptions {
|
|
248
|
+
/**
|
|
249
|
+
* Further entries to journal with THIS request's voucher, in the same commit as `pav-<request>`
|
|
250
|
+
* and before the lane advances past its seq (the operation journal's `reserved` phase). A crash
|
|
251
|
+
* may keep any subset of that commit; the lane completes an interrupted advance from either.
|
|
252
|
+
*/
|
|
253
|
+
journal?: (voucher: DebitVoucherWire) => readonly (readonly [string, unknown])[];
|
|
254
|
+
/** Further locks held for the whole round, taken with the lane's (all in sorted order), e.g. the operation journal's. */
|
|
255
|
+
lock?: readonly string[];
|
|
256
|
+
/** Runs first under every lock, before anything is read or sent; a throw sends nothing. */
|
|
257
|
+
check?: () => Promise<void>;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The voucher push journal of an allowance: its last voucher, the members that acknowledged it and
|
|
261
|
+
* whether the one re-push was spent (diagnostics).
|
|
262
|
+
* @param store - Application store.
|
|
263
|
+
* @param allowance - Allowance ID.
|
|
264
|
+
*/
|
|
265
|
+
export declare function inspectAllowanceVoucherPush(store: ApplicationStore, allowance: Hex): Promise<{
|
|
266
|
+
seq: number;
|
|
267
|
+
acked: string[];
|
|
268
|
+
repushed: boolean;
|
|
269
|
+
} | undefined>;
|
|
270
|
+
/** Test hook: wait for every background voucher push started in this process. */
|
|
271
|
+
export declare function settleAllowanceVoucherPushes(): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* Inspect the lanes of a slot: allowance, seq, cumulative and any pending debit (diagnostics).
|
|
274
|
+
* @param store - Application store.
|
|
275
|
+
* @param deployment - Approved deployment.
|
|
276
|
+
* @param slot - Slot.
|
|
277
|
+
* @param lanes - Lane count.
|
|
278
|
+
*/
|
|
279
|
+
export declare function inspectAllowanceLanes(store: ApplicationStore, deployment: PrepaidDeployment, slot: Hex, lanes: number): Promise<{
|
|
280
|
+
lane: number;
|
|
281
|
+
allowanceId?: Hex;
|
|
282
|
+
phase?: string;
|
|
283
|
+
seq?: number;
|
|
284
|
+
cumulative?: string;
|
|
285
|
+
amount?: string;
|
|
286
|
+
expiresAt?: number;
|
|
287
|
+
pending?: {
|
|
288
|
+
seq: number;
|
|
289
|
+
requestId: Hex;
|
|
290
|
+
partials: number;
|
|
291
|
+
};
|
|
292
|
+
next?: {
|
|
293
|
+
allowanceId: Hex;
|
|
294
|
+
phase: string;
|
|
295
|
+
};
|
|
296
|
+
retired: number;
|
|
297
|
+
}[]>;
|
|
298
|
+
/**
|
|
299
|
+
* Inspect the session-grant draw lanes of a slot for one epoch's parity: as {@link inspectAllowanceLanes},
|
|
300
|
+
* with each allowance's verifier epoch and how many allowances the lane holds (escrow possibly still locked).
|
|
301
|
+
* @param store - Application store.
|
|
302
|
+
* @param deployment - Approved deployment.
|
|
303
|
+
* @param slot - Slot.
|
|
304
|
+
* @param lanes - Lane count.
|
|
305
|
+
* @param epoch - A verifier epoch of the parity to inspect.
|
|
306
|
+
*/
|
|
307
|
+
export declare function inspectAllowanceDrawLanes(store: ApplicationStore, deployment: PrepaidDeployment, slot: Hex, lanes: number, epoch: number): Promise<{
|
|
308
|
+
lane: number;
|
|
309
|
+
allowanceId?: Hex;
|
|
310
|
+
epoch?: number;
|
|
311
|
+
phase?: string;
|
|
312
|
+
seq?: number;
|
|
313
|
+
amount?: string;
|
|
314
|
+
next?: {
|
|
315
|
+
allowanceId: Hex;
|
|
316
|
+
phase: string;
|
|
317
|
+
epoch: number;
|
|
318
|
+
};
|
|
319
|
+
retired: number;
|
|
320
|
+
held: number;
|
|
321
|
+
}[]>;
|
|
322
|
+
/** Test hook: wait for every background reservation (and draw reserve-ahead) started in this process. */
|
|
323
|
+
export declare function settleAllowanceRefills(): Promise<void>;
|
|
324
|
+
/** Test hook: forget this process's reserve-ahead retry times (a new process starts without them). */
|
|
325
|
+
export declare function resetAllowanceDrawAheads(): void;
|