@piprail/sdk 1.4.0 → 1.5.1
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/CHAINS.md +2 -2
- package/CHANGELOG.md +65 -0
- package/ERRORS.md +15 -3
- package/README.md +38 -4
- package/dist/{algorand-XJ5OVWQB.js → algorand-B67G4335.js} +34 -0
- package/dist/{algorand-IDFUG5CI.cjs → algorand-IJJKE35X.cjs} +38 -4
- package/dist/{aptos-TPSOQ2VL.cjs → aptos-X3G2UBYW.cjs} +28 -0
- package/dist/{aptos-AWWSCPDH.js → aptos-YQWTGFRZ.js} +28 -0
- package/dist/index.cjs +307 -29
- package/dist/index.d.cts +174 -15
- package/dist/index.d.ts +174 -15
- package/dist/index.js +295 -17
- package/dist/{near-NOJTO4GX.js → near-7MBBCDUE.js} +50 -0
- package/dist/{near-KDA5DPTX.cjs → near-GGUHLXAF.cjs} +57 -7
- package/dist/{solana-HNRTS4KM.js → solana-7WJVZGDW.js} +22 -0
- package/dist/{solana-DVA6I55L.cjs → solana-W24TCJV4.cjs} +25 -3
- package/dist/{stellar-4TDVVJYO.js → stellar-HV6VGZX3.js} +50 -0
- package/dist/{stellar-4D5EWT3V.cjs → stellar-YMY3K2YB.cjs} +50 -0
- package/dist/{sui-ALUTM5GX.js → sui-2WFWVFJX.js} +23 -0
- package/dist/{sui-5HMIHOZK.cjs → sui-32KVESR5.cjs} +23 -0
- package/dist/{ton-3XMIM2FU.js → ton-DGZB7W4U.js} +23 -0
- package/dist/{ton-TVK4TEDX.cjs → ton-FIQGV2LC.cjs} +23 -0
- package/dist/{tron-6D65YJEU.js → tron-RLIL2FDI.js} +28 -0
- package/dist/{tron-Y5RZJZRT.cjs → tron-ZSXAPZ2C.cjs} +28 -0
- package/dist/{xrpl-ICO6G7UK.cjs → xrpl-2PKP7HOI.cjs} +61 -1
- package/dist/{xrpl-ISFG3SSN.js → xrpl-UEC2GYVV.js} +60 -0
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -3845,7 +3845,7 @@ interface AlgorandToken {
|
|
|
3845
3845
|
}
|
|
3846
3846
|
/**
|
|
3847
3847
|
* What to be paid in. Each driver validates the forms it accepts:
|
|
3848
|
-
* - 'native' the chain's native coin (ETH, BNB, SOL, TON, XLM, XRP)
|
|
3848
|
+
* - 'native' the chain's native coin (ETH, BNB, SOL, TON, XLM, XRP, TRX, NEAR, SUI, APT, ALGO)
|
|
3849
3849
|
* - 'USDC' (string) a symbol resolved against the chosen chain
|
|
3850
3850
|
* - EvmToken any ERC-20 (EVM chains)
|
|
3851
3851
|
* - SolanaToken any SPL token (Solana)
|
|
@@ -3892,6 +3892,22 @@ interface CostEstimate {
|
|
|
3892
3892
|
interface WalletHandle {
|
|
3893
3893
|
readonly _native: unknown;
|
|
3894
3894
|
}
|
|
3895
|
+
/**
|
|
3896
|
+
* Why a recipient can't receive an asset yet — the chain's one-time receive
|
|
3897
|
+
* prerequisite, when it has one. Surfaced by {@link ResolvedNetwork.recipientReady}
|
|
3898
|
+
* and relayed by the client's planner so an agent fixes the RECIPIENT (not its own
|
|
3899
|
+
* balance). Families with no prerequisite report `ready: 'n/a'` and no reason.
|
|
3900
|
+
*/
|
|
3901
|
+
type RecipientReason = 'NO_TRUSTLINE' | 'NOT_REGISTERED' | 'NOT_OPTED_IN' | 'INACTIVE';
|
|
3902
|
+
/** What {@link ResolvedNetwork.balanceOf} returns — base-unit balances, or null per
|
|
3903
|
+
* field when that read was unavailable (transient/RPC), never a false 0. */
|
|
3904
|
+
interface WalletBalance {
|
|
3905
|
+
/** The payment token's balance in base units, or null if the read was unavailable. */
|
|
3906
|
+
token: bigint | null;
|
|
3907
|
+
/** The native gas coin's balance in base units, or null if unavailable. For
|
|
3908
|
+
* `asset === 'native'`, this equals `token`. */
|
|
3909
|
+
native: bigint | null;
|
|
3910
|
+
}
|
|
3895
3911
|
interface ConfirmInfo {
|
|
3896
3912
|
/** Block number (EVM) or slot (Solana) as a string — numeric-agnostic. */
|
|
3897
3913
|
height: string;
|
|
@@ -3946,6 +3962,31 @@ interface ResolvedNetwork {
|
|
|
3946
3962
|
estimateCost(accept: X402AcceptEntry, opts?: {
|
|
3947
3963
|
from?: string;
|
|
3948
3964
|
}): Promise<CostEstimate>;
|
|
3965
|
+
/**
|
|
3966
|
+
* Read the BOUND WALLET's own balance of the payment `asset` AND of the native
|
|
3967
|
+
* gas coin, in base units — what the client's `planPayment` checks affordability
|
|
3968
|
+
* against. RPC-read-only and NEVER throws: a field whose read was unavailable
|
|
3969
|
+
* (rate-limited / transient) comes back `null` (unknown), never `0` (which would
|
|
3970
|
+
* falsely read "broke"). For `asset === 'native'`, `token === native`.
|
|
3971
|
+
* Payer-side + informational — the gate never calls this. See {@link WalletBalance}.
|
|
3972
|
+
*/
|
|
3973
|
+
balanceOf(wallet: WalletHandle, asset: string): Promise<WalletBalance>;
|
|
3974
|
+
/**
|
|
3975
|
+
* Can `payTo` RECEIVE `asset` on this network right now? Reports the chain's
|
|
3976
|
+
* one-time receive prerequisite (trustline / storage_deposit / ASA opt-in /
|
|
3977
|
+
* activation):
|
|
3978
|
+
* - `{ ready: 'n/a' }` the family has NO prerequisite (EVM, Solana, TON,
|
|
3979
|
+
* Tron, Sui, Aptos — and every native coin)
|
|
3980
|
+
* - `{ ready: true }` the prerequisite is satisfied
|
|
3981
|
+
* - `{ ready: false, reason }` it's missing (see {@link RecipientReason}) — fix the recipient
|
|
3982
|
+
* - `{ ready: 'unknown' }` the probe read failed (transient) — NEVER throws
|
|
3983
|
+
* Re-derives nothing from a client ref; reads only the given `payTo`. Payer-side
|
|
3984
|
+
* pre-flight — the gate never calls this.
|
|
3985
|
+
*/
|
|
3986
|
+
recipientReady(payTo: string, asset: string): Promise<{
|
|
3987
|
+
ready: boolean | 'n/a' | 'unknown';
|
|
3988
|
+
reason?: RecipientReason;
|
|
3989
|
+
}>;
|
|
3949
3990
|
/** Verify `ref` satisfies `accept`, RPC-only, in-process. */
|
|
3950
3991
|
verify(ref: string, accept: X402AcceptEntry): Promise<VerifyResult>;
|
|
3951
3992
|
}
|
|
@@ -4089,6 +4130,8 @@ type PipRailEvent = {
|
|
|
4089
4130
|
* - Stellar → `{ secret }` (S… seed) or a ready `{ keypair }`
|
|
4090
4131
|
* - XRPL → `{ seed }` (s… seed) or a ready `{ wallet }`
|
|
4091
4132
|
* - NEAR → `{ accountId, privateKey }` (privateKey = ed25519:… secret)
|
|
4133
|
+
* - Aptos → `{ privateKey }` (AIP-80 `ed25519-priv-0x…` / raw `0x…` hex) or `{ account }`
|
|
4134
|
+
* - Algorand→ `{ mnemonic }` (25 words) or a ready `{ account }`
|
|
4092
4135
|
*/
|
|
4093
4136
|
type WalletInput = {
|
|
4094
4137
|
privateKey: string;
|
|
@@ -4162,11 +4205,67 @@ interface PipRailCostQuote {
|
|
|
4162
4205
|
/** Estimated network fee (gas) in the chain's native coin. */
|
|
4163
4206
|
cost: CostEstimate;
|
|
4164
4207
|
}
|
|
4208
|
+
/** A hard reason a rail can't be settled right now — each maps to a concrete fix. */
|
|
4209
|
+
type PayBlocker = 'INSUFFICIENT_TOKEN' | 'INSUFFICIENT_GAS' | 'RECIPIENT_NOT_READY' | 'OUTSIDE_POLICY';
|
|
4210
|
+
/** A soft flag — never blocks, always worth surfacing to the agent. */
|
|
4211
|
+
type PayWarning = 'SYMBOL_MISMATCH' | 'BALANCE_UNREADABLE' | 'RECIPIENT_READINESS_UNKNOWN' | 'GAS_HEURISTIC' | 'THIN_GAS_MARGIN';
|
|
4212
|
+
/** One offered rail, fully analysed against the bound wallet's own holdings. */
|
|
4213
|
+
interface PayOption {
|
|
4214
|
+
/** The rail this analyses (one entry from the 402's accepts[]). */
|
|
4215
|
+
accept: X402AcceptEntry;
|
|
4216
|
+
/** The priced requirement — TRUE decimals/symbol + the policy verdict. */
|
|
4217
|
+
quote: PipRailQuote;
|
|
4218
|
+
/** Estimated native-coin gas to send it (cost.basis surfaced). */
|
|
4219
|
+
cost: CostEstimate;
|
|
4220
|
+
/** The verdict for THIS rail. 'unknown' = a read failed, so payability can't be confirmed. */
|
|
4221
|
+
state: 'payable' | 'blocked' | 'unknown';
|
|
4222
|
+
/** Hard reasons it's blocked (empty when payable). */
|
|
4223
|
+
blockers: PayBlocker[];
|
|
4224
|
+
/** Soft flags (may be present even when payable). */
|
|
4225
|
+
warnings: PayWarning[];
|
|
4226
|
+
/** Live wallet holdings, human units; null = the read was unavailable (NOT zero). */
|
|
4227
|
+
balance: {
|
|
4228
|
+
token: string | null;
|
|
4229
|
+
native: string | null;
|
|
4230
|
+
};
|
|
4231
|
+
/** What this rail needs: the payment amount + the estimated gas, human units. */
|
|
4232
|
+
need: {
|
|
4233
|
+
token: string;
|
|
4234
|
+
native: string;
|
|
4235
|
+
};
|
|
4236
|
+
/** How much MORE is needed to clear a funds blocker, human units (omitted when funded). */
|
|
4237
|
+
shortfall?: {
|
|
4238
|
+
token?: string;
|
|
4239
|
+
native?: string;
|
|
4240
|
+
};
|
|
4241
|
+
/** Can payTo receive this asset right now, and if not, what fixes it. */
|
|
4242
|
+
recipient: {
|
|
4243
|
+
ready: boolean | 'n/a' | 'unknown';
|
|
4244
|
+
reason?: RecipientReason;
|
|
4245
|
+
fix?: string;
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
/** The plan for ONE 402 across every rail this client can pay (its bound network). */
|
|
4249
|
+
interface PaymentPlan {
|
|
4250
|
+
url: string;
|
|
4251
|
+
/** The network this client is bound to (the rails it can settle). */
|
|
4252
|
+
network: Caip2;
|
|
4253
|
+
/** Top-level verdict for instant branching. */
|
|
4254
|
+
status: 'ready' | 'blocked' | 'unknown';
|
|
4255
|
+
/** True iff at least one rail is payable now (best !== null). */
|
|
4256
|
+
payable: boolean;
|
|
4257
|
+
/** The rail to use: the cheapest (within native coin) payable option, or null. */
|
|
4258
|
+
best: PayOption | null;
|
|
4259
|
+
/** Every offered+supported rail, ranked: payable → unknown → blocked. */
|
|
4260
|
+
options: PayOption[];
|
|
4261
|
+
/** When NOT payable: one human, actionable sentence on exactly what to do. */
|
|
4262
|
+
fundingHint: string | null;
|
|
4263
|
+
}
|
|
4165
4264
|
interface PipRailClientOptions {
|
|
4166
4265
|
/** Wallet for the chosen chain family. */
|
|
4167
4266
|
wallet: WalletInput;
|
|
4168
4267
|
/** Which chain to pay on. EVM ('bnb'|'base'|…), 'solana', 'ton', 'stellar',
|
|
4169
|
-
* 'xrpl', 'tron', 'sui', or '
|
|
4268
|
+
* 'xrpl', 'tron', 'sui', 'near', 'aptos', or 'algorand'. */
|
|
4170
4269
|
chain: ChainSelector;
|
|
4171
4270
|
/** Override the chain's default RPC URL (recommended in production). */
|
|
4172
4271
|
rpcUrl?: string;
|
|
@@ -4200,6 +4299,16 @@ interface PipRailClientOptions {
|
|
|
4200
4299
|
maxPaymentRetries?: number;
|
|
4201
4300
|
/** Timeout (ms) for the retry leg after broadcast. Default 30_000. */
|
|
4202
4301
|
retryTimeoutMs?: number;
|
|
4302
|
+
/**
|
|
4303
|
+
* Balance-aware routing: when true, `fetch()` runs `planPayment` on a 402 and
|
|
4304
|
+
* pays the cheapest rail the wallet can ACTUALLY settle (token + native gas +
|
|
4305
|
+
* recipient-ready), instead of the first policy-passing accept. If none is
|
|
4306
|
+
* settleable it throws {@link PaymentDeclinedError} carrying the funding hint —
|
|
4307
|
+
* before any send. Default **false** (defaults never change): the zero-config
|
|
4308
|
+
* path keeps its existing selection. Recommended for multi-rail 402s. Override
|
|
4309
|
+
* per call with `fetch(url, { autoRoute: true })`.
|
|
4310
|
+
*/
|
|
4311
|
+
autoRoute?: boolean;
|
|
4203
4312
|
/** Logger hook. Default no-op. */
|
|
4204
4313
|
onEvent?: (event: PipRailEvent) => void;
|
|
4205
4314
|
}
|
|
@@ -4252,6 +4361,32 @@ declare class PipRailClient {
|
|
|
4252
4361
|
/** Aggregated snapshot of every payment this client has settled — total
|
|
4253
4362
|
* count, cumulative spend per token, and the individual records. */
|
|
4254
4363
|
spent(): SpendSummary;
|
|
4364
|
+
/**
|
|
4365
|
+
* Plan a payment for a gated URL — WITHOUT paying. The read-only completion of
|
|
4366
|
+
* the `quote()` → `estimateCost()` → **`planPayment()`** trio: it surveys every
|
|
4367
|
+
* rail the 402 offers on this client's chain against the wallet's OWN holdings —
|
|
4368
|
+
* token balance, native-coin gas, and recipient-readiness (trustline / ATA /
|
|
4369
|
+
* storage_deposit / ASA opt-in) — and returns, crystal-clear:
|
|
4370
|
+
* - `payable` + `best` — the cheapest rail the wallet can actually settle
|
|
4371
|
+
* - `options[]` — every rail with typed `blockers` + soft `warnings`
|
|
4372
|
+
* - `fundingHint` — one human sentence on exactly what to top up
|
|
4373
|
+
*
|
|
4374
|
+
* NEVER throws for a read problem (a transient/RPC failure surfaces as a rail in
|
|
4375
|
+
* `state: 'unknown'` + a warning, never a false "unaffordable"); returns `null`
|
|
4376
|
+
* when the URL isn't payment-gated (no 402); and when the 402 offers no rail on
|
|
4377
|
+
* this client's chain it EXPLAINS that (status `blocked` + a hint), rather than
|
|
4378
|
+
* throwing. Throws `InvalidEnvelopeError` only on an unparseable challenge.
|
|
4379
|
+
*
|
|
4380
|
+
* Then pay the chosen rail with `fetch(url, { autoRoute: true })`, or branch on
|
|
4381
|
+
* the plan yourself. No funds move.
|
|
4382
|
+
*/
|
|
4383
|
+
planPayment(url: string, init?: RequestInit): Promise<PaymentPlan | null>;
|
|
4384
|
+
/**
|
|
4385
|
+
* Convenience over {@link planPayment}: can the wallet settle this URL right now?
|
|
4386
|
+
* `true` when at least one rail is payable — or when the URL isn't gated (a free
|
|
4387
|
+
* resource is trivially "affordable"). No funds move.
|
|
4388
|
+
*/
|
|
4389
|
+
canAfford(url: string, init?: RequestInit): Promise<boolean>;
|
|
4255
4390
|
/**
|
|
4256
4391
|
* Lower-level: drive any HTTP method through the 402 flow.
|
|
4257
4392
|
*
|
|
@@ -4266,6 +4401,14 @@ declare class PipRailClient {
|
|
|
4266
4401
|
* `quote()` (read-only) and `fetch()` (which then authorises + pays).
|
|
4267
4402
|
*/
|
|
4268
4403
|
private resolveChallenge;
|
|
4404
|
+
/** The candidate accepts this client could pay: our scheme, on the bound network. */
|
|
4405
|
+
private gatherCandidates;
|
|
4406
|
+
/** Build the full {@link PaymentPlan} from an already-parsed challenge + bound
|
|
4407
|
+
* net/wallet. Shared by `planPayment` (read-only) and `fetch`'s autoRoute. */
|
|
4408
|
+
private planFromChallenge;
|
|
4409
|
+
/** Analyse ONE rail against the wallet's holdings — quote (existing) + gas
|
|
4410
|
+
* (estimateCost, existing) + balanceOf + recipientReady → a {@link PayOption}. */
|
|
4411
|
+
private analyzeRail;
|
|
4269
4412
|
/** Build the agent-facing quote for an accept: TRUE decimals/symbol (via the
|
|
4270
4413
|
* driver's describeAsset) + the policy verdict + a symbol-mismatch flag. */
|
|
4271
4414
|
private buildQuote;
|
|
@@ -4277,6 +4420,16 @@ declare class PipRailClient {
|
|
|
4277
4420
|
private payAndConfirm;
|
|
4278
4421
|
private retryWithProof;
|
|
4279
4422
|
}
|
|
4423
|
+
/**
|
|
4424
|
+
* Plan a payment ACROSS several single-chain clients — the cross-chain brain.
|
|
4425
|
+
* A {@link PipRailClient} is bound to one chain (its wallet); give this one client
|
|
4426
|
+
* per chain the agent funds and it runs each client's {@link PipRailClient.planPayment}
|
|
4427
|
+
* in parallel and merges the rails into one plan, ranked payable-first. `best` is a
|
|
4428
|
+
* payable rail; across different native coins there's no oracle to pick the
|
|
4429
|
+
* fiat-cheapest, so the tiebreak is the order `clients` were given (the agent's own
|
|
4430
|
+
* chain preference). Returns `null` only if the URL isn't gated for any client.
|
|
4431
|
+
*/
|
|
4432
|
+
declare function planAcross(clients: PipRailClient[], url: string, init?: RequestInit): Promise<PaymentPlan | null>;
|
|
4280
4433
|
|
|
4281
4434
|
/** A framework-agnostic tool definition an agent runtime can register. */
|
|
4282
4435
|
interface AgentTool {
|
|
@@ -4290,8 +4443,10 @@ interface AgentTool {
|
|
|
4290
4443
|
invoke: (args: Record<string, unknown>) => Promise<unknown>;
|
|
4291
4444
|
}
|
|
4292
4445
|
/**
|
|
4293
|
-
*
|
|
4446
|
+
* Three tools wrapping a configured {@link PipRailClient}:
|
|
4294
4447
|
* - `piprail_quote_payment(url)` — price a gated URL WITHOUT paying.
|
|
4448
|
+
* - `piprail_plan_payment(url)` — check you CAN pay (balance + gas + recipient
|
|
4449
|
+
* readiness) across every rail the URL offers, WITHOUT paying.
|
|
4295
4450
|
* - `piprail_pay_request(url, method?, body?)` — pay if needed and return the result.
|
|
4296
4451
|
*
|
|
4297
4452
|
* A policy/approval refusal comes back as a structured `{ declined: true, reason }`
|
|
@@ -4327,7 +4482,7 @@ declare function paymentTools(client: PipRailClient): AgentTool[];
|
|
|
4327
4482
|
*/
|
|
4328
4483
|
interface AcceptOption {
|
|
4329
4484
|
/** Which chain. EVM ('bnb'|'base'|…), 'solana', 'ton', 'stellar', 'xrpl',
|
|
4330
|
-
* 'tron', 'near', or '
|
|
4485
|
+
* 'tron', 'near', 'sui', 'aptos', or 'algorand'. */
|
|
4331
4486
|
chain: ChainSelector;
|
|
4332
4487
|
/** Token to be paid in (symbol / 'native' / custom descriptor). */
|
|
4333
4488
|
token: TokenInput;
|
|
@@ -4341,8 +4496,9 @@ interface AcceptOption {
|
|
|
4341
4496
|
interface RequirePaymentOptions {
|
|
4342
4497
|
/**
|
|
4343
4498
|
* Single-chain form: which chain to accept payment on. EVM ('bnb'|'base'|…),
|
|
4344
|
-
* 'solana', 'ton', 'stellar', 'xrpl', 'tron', 'near',
|
|
4345
|
-
* `chain` + `token` + `amount`, OR use the multi-chain
|
|
4499
|
+
* 'solana', 'ton', 'stellar', 'xrpl', 'tron', 'near', 'sui', 'aptos', or
|
|
4500
|
+
* 'algorand'. Provide `chain` + `token` + `amount`, OR use the multi-chain
|
|
4501
|
+
* `accept` array below.
|
|
4346
4502
|
*/
|
|
4347
4503
|
chain?: ChainSelector;
|
|
4348
4504
|
/** Override the chain's default RPC URL (recommended in production). */
|
|
@@ -4353,9 +4509,10 @@ interface RequirePaymentOptions {
|
|
|
4353
4509
|
* `{ address, decimals }` on EVM/Tron, `{ mint, decimals }` on Solana,
|
|
4354
4510
|
* `{ master, decimals }` on TON, `{ issuer, code, decimals }` on Stellar,
|
|
4355
4511
|
* `{ issuer, currencyHex, decimals }` on XRPL, `{ contractId, decimals }` on
|
|
4356
|
-
* NEAR, `{ coinType, decimals }` on Sui
|
|
4512
|
+
* NEAR, `{ coinType, decimals }` on Sui, `{ metadata, decimals }` on Aptos, or
|
|
4513
|
+
* `{ assetId, decimals }` on Algorand. You name the token; the SDK fills in
|
|
4357
4514
|
* the contract + decimals for built-in symbols. (Note: native USDC doesn't
|
|
4358
|
-
* exist on TON/Tron — USDT does; NEAR is
|
|
4515
|
+
* exist on TON/Tron — USDT does; native NEAR is supported via `'native'`.)
|
|
4359
4516
|
*/
|
|
4360
4517
|
token?: TokenInput;
|
|
4361
4518
|
/** Human-readable amount, e.g. "0.05" (single-chain form). */
|
|
@@ -4367,8 +4524,8 @@ interface RequirePaymentOptions {
|
|
|
4367
4524
|
*/
|
|
4368
4525
|
accept?: AcceptOption[];
|
|
4369
4526
|
/** Address that receives the payment (0x… EVM/Sui, base58 Solana, EQ…/UQ… TON,
|
|
4370
|
-
* G… Stellar, r… XRPL, T… Tron, account id on NEAR
|
|
4371
|
-
* form; the per-option fallback for the multi form. */
|
|
4527
|
+
* G… Stellar, r… XRPL, T… Tron, account id on NEAR, 0x… Aptos, base32 Algorand).
|
|
4528
|
+
* Required for the single form; the per-option fallback for the multi form. */
|
|
4372
4529
|
payTo?: AddressId;
|
|
4373
4530
|
/** Shown to the agent in the challenge. */
|
|
4374
4531
|
description?: string;
|
|
@@ -4518,7 +4675,7 @@ declare class InsufficientFundsError extends PipRailError {
|
|
|
4518
4675
|
* The message states the requirement and the fix in plain language **and echoes
|
|
4519
4676
|
* the raw chain code** (e.g. `(XRPL: tecNO_DST_INSUF_XRP)`), while the untouched
|
|
4520
4677
|
* chain error is preserved on `.cause` for deeper debugging. Chains with no
|
|
4521
|
-
* receive prerequisite (EVM, Solana, Sui, Tron, and native TON/NEAR) never throw it.
|
|
4678
|
+
* receive prerequisite (EVM, Solana, Sui, Aptos, Tron, and native TON/NEAR) never throw it.
|
|
4522
4679
|
*/
|
|
4523
4680
|
declare class RecipientNotReadyError extends PipRailError {
|
|
4524
4681
|
readonly code = "RECIPIENT_NOT_READY";
|
|
@@ -4615,7 +4772,7 @@ declare class NonReplayableBodyError extends PipRailError {
|
|
|
4615
4772
|
}
|
|
4616
4773
|
/**
|
|
4617
4774
|
* The chosen chain belongs to one family (EVM, Solana, TON, Stellar, XRPL, Tron,
|
|
4618
|
-
* Sui, NEAR) but the wallet, payTo, or token was given in another family's form
|
|
4775
|
+
* Sui, NEAR, Aptos, Algorand) but the wallet, payTo, or token was given in another family's form
|
|
4619
4776
|
* (e.g. an `0x…` payTo on Solana, or a `{ mint }` token on a Stellar chain).
|
|
4620
4777
|
*/
|
|
4621
4778
|
declare class WrongFamilyError extends PipRailError {
|
|
@@ -4627,7 +4784,8 @@ declare class WrongFamilyError extends PipRailError {
|
|
|
4627
4784
|
* token by full descriptor ({ address, decimals } EVM/Tron · { mint, decimals }
|
|
4628
4785
|
* Solana · { master, decimals } TON · { issuer, code, decimals } Stellar ·
|
|
4629
4786
|
* { issuer, currencyHex, decimals } XRPL · { coinType, decimals } Sui ·
|
|
4630
|
-
* { contractId, decimals } NEAR
|
|
4787
|
+
* { contractId, decimals } NEAR · { metadata, decimals } Aptos ·
|
|
4788
|
+
* { assetId, decimals } Algorand).
|
|
4631
4789
|
*/
|
|
4632
4790
|
declare class UnknownTokenError extends PipRailError {
|
|
4633
4791
|
readonly code = "UNKNOWN_TOKEN";
|
|
@@ -4639,7 +4797,8 @@ declare class UnknownTokenError extends PipRailError {
|
|
|
4639
4797
|
* `npm install @ton/ton @ton/core @ton/crypto`; Stellar:
|
|
4640
4798
|
* `npm install @stellar/stellar-sdk`; XRPL: `npm install xrpl`; Tron:
|
|
4641
4799
|
* `npm install tronweb`; Sui: `npm install @mysten/sui`; NEAR:
|
|
4642
|
-
* `npm install near-api-js
|
|
4800
|
+
* `npm install near-api-js`; Aptos: `npm install @aptos-labs/ts-sdk`;
|
|
4801
|
+
* Algorand: `npm install algosdk`.
|
|
4643
4802
|
*/
|
|
4644
4803
|
declare class MissingDriverError extends PipRailError {
|
|
4645
4804
|
readonly code = "MISSING_DRIVER";
|
|
@@ -4765,4 +4924,4 @@ declare function encodeXPaymentHeader(input: {
|
|
|
4765
4924
|
x402Version?: number;
|
|
4766
4925
|
}): string;
|
|
4767
4926
|
|
|
4768
|
-
export { type AcceptOption, type AddressId, type AgentTool, type AssetId, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, InsufficientFundsError, InvalidEnvelopeError, MaxRetriesExceededError, MissingDriverError, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPolicy, PaymentTimeoutError, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, RecipientNotReadyError, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type TronToken, UnknownTokenError, UnsupportedNetworkError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletHandle, type WalletInput, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402Challenge, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, type XrplToken, buildChallengeHeader, buildExactAuthorization, buildReceiptHeader, buildSignatureHeader, chainIdForExactNetwork, createPaymentGate, encodeXPaymentHeader, evaluatePolicy, parseChallenge, parseExactRequirements, parseReceipt, parseSignatureHeader, paymentTools, pickAccept, registerDriver, requirePayment, resolveChain, toInsufficientFundsError, toInvalidBody };
|
|
4927
|
+
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, InsufficientFundsError, InvalidEnvelopeError, MaxRetriesExceededError, MissingDriverError, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type PayBlocker, type PayOption, type PayWarning, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, PaymentTimeoutError, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, RecipientNotReadyError, type RecipientReason, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type TronToken, UnknownTokenError, UnsupportedNetworkError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402Challenge, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, type XrplToken, buildChallengeHeader, buildExactAuthorization, buildReceiptHeader, buildSignatureHeader, chainIdForExactNetwork, createPaymentGate, encodeXPaymentHeader, evaluatePolicy, parseChallenge, parseExactRequirements, parseReceipt, parseSignatureHeader, paymentTools, pickAccept, planAcross, registerDriver, requirePayment, resolveChain, toInsufficientFundsError, toInvalidBody };
|
package/dist/index.d.ts
CHANGED
|
@@ -3845,7 +3845,7 @@ interface AlgorandToken {
|
|
|
3845
3845
|
}
|
|
3846
3846
|
/**
|
|
3847
3847
|
* What to be paid in. Each driver validates the forms it accepts:
|
|
3848
|
-
* - 'native' the chain's native coin (ETH, BNB, SOL, TON, XLM, XRP)
|
|
3848
|
+
* - 'native' the chain's native coin (ETH, BNB, SOL, TON, XLM, XRP, TRX, NEAR, SUI, APT, ALGO)
|
|
3849
3849
|
* - 'USDC' (string) a symbol resolved against the chosen chain
|
|
3850
3850
|
* - EvmToken any ERC-20 (EVM chains)
|
|
3851
3851
|
* - SolanaToken any SPL token (Solana)
|
|
@@ -3892,6 +3892,22 @@ interface CostEstimate {
|
|
|
3892
3892
|
interface WalletHandle {
|
|
3893
3893
|
readonly _native: unknown;
|
|
3894
3894
|
}
|
|
3895
|
+
/**
|
|
3896
|
+
* Why a recipient can't receive an asset yet — the chain's one-time receive
|
|
3897
|
+
* prerequisite, when it has one. Surfaced by {@link ResolvedNetwork.recipientReady}
|
|
3898
|
+
* and relayed by the client's planner so an agent fixes the RECIPIENT (not its own
|
|
3899
|
+
* balance). Families with no prerequisite report `ready: 'n/a'` and no reason.
|
|
3900
|
+
*/
|
|
3901
|
+
type RecipientReason = 'NO_TRUSTLINE' | 'NOT_REGISTERED' | 'NOT_OPTED_IN' | 'INACTIVE';
|
|
3902
|
+
/** What {@link ResolvedNetwork.balanceOf} returns — base-unit balances, or null per
|
|
3903
|
+
* field when that read was unavailable (transient/RPC), never a false 0. */
|
|
3904
|
+
interface WalletBalance {
|
|
3905
|
+
/** The payment token's balance in base units, or null if the read was unavailable. */
|
|
3906
|
+
token: bigint | null;
|
|
3907
|
+
/** The native gas coin's balance in base units, or null if unavailable. For
|
|
3908
|
+
* `asset === 'native'`, this equals `token`. */
|
|
3909
|
+
native: bigint | null;
|
|
3910
|
+
}
|
|
3895
3911
|
interface ConfirmInfo {
|
|
3896
3912
|
/** Block number (EVM) or slot (Solana) as a string — numeric-agnostic. */
|
|
3897
3913
|
height: string;
|
|
@@ -3946,6 +3962,31 @@ interface ResolvedNetwork {
|
|
|
3946
3962
|
estimateCost(accept: X402AcceptEntry, opts?: {
|
|
3947
3963
|
from?: string;
|
|
3948
3964
|
}): Promise<CostEstimate>;
|
|
3965
|
+
/**
|
|
3966
|
+
* Read the BOUND WALLET's own balance of the payment `asset` AND of the native
|
|
3967
|
+
* gas coin, in base units — what the client's `planPayment` checks affordability
|
|
3968
|
+
* against. RPC-read-only and NEVER throws: a field whose read was unavailable
|
|
3969
|
+
* (rate-limited / transient) comes back `null` (unknown), never `0` (which would
|
|
3970
|
+
* falsely read "broke"). For `asset === 'native'`, `token === native`.
|
|
3971
|
+
* Payer-side + informational — the gate never calls this. See {@link WalletBalance}.
|
|
3972
|
+
*/
|
|
3973
|
+
balanceOf(wallet: WalletHandle, asset: string): Promise<WalletBalance>;
|
|
3974
|
+
/**
|
|
3975
|
+
* Can `payTo` RECEIVE `asset` on this network right now? Reports the chain's
|
|
3976
|
+
* one-time receive prerequisite (trustline / storage_deposit / ASA opt-in /
|
|
3977
|
+
* activation):
|
|
3978
|
+
* - `{ ready: 'n/a' }` the family has NO prerequisite (EVM, Solana, TON,
|
|
3979
|
+
* Tron, Sui, Aptos — and every native coin)
|
|
3980
|
+
* - `{ ready: true }` the prerequisite is satisfied
|
|
3981
|
+
* - `{ ready: false, reason }` it's missing (see {@link RecipientReason}) — fix the recipient
|
|
3982
|
+
* - `{ ready: 'unknown' }` the probe read failed (transient) — NEVER throws
|
|
3983
|
+
* Re-derives nothing from a client ref; reads only the given `payTo`. Payer-side
|
|
3984
|
+
* pre-flight — the gate never calls this.
|
|
3985
|
+
*/
|
|
3986
|
+
recipientReady(payTo: string, asset: string): Promise<{
|
|
3987
|
+
ready: boolean | 'n/a' | 'unknown';
|
|
3988
|
+
reason?: RecipientReason;
|
|
3989
|
+
}>;
|
|
3949
3990
|
/** Verify `ref` satisfies `accept`, RPC-only, in-process. */
|
|
3950
3991
|
verify(ref: string, accept: X402AcceptEntry): Promise<VerifyResult>;
|
|
3951
3992
|
}
|
|
@@ -4089,6 +4130,8 @@ type PipRailEvent = {
|
|
|
4089
4130
|
* - Stellar → `{ secret }` (S… seed) or a ready `{ keypair }`
|
|
4090
4131
|
* - XRPL → `{ seed }` (s… seed) or a ready `{ wallet }`
|
|
4091
4132
|
* - NEAR → `{ accountId, privateKey }` (privateKey = ed25519:… secret)
|
|
4133
|
+
* - Aptos → `{ privateKey }` (AIP-80 `ed25519-priv-0x…` / raw `0x…` hex) or `{ account }`
|
|
4134
|
+
* - Algorand→ `{ mnemonic }` (25 words) or a ready `{ account }`
|
|
4092
4135
|
*/
|
|
4093
4136
|
type WalletInput = {
|
|
4094
4137
|
privateKey: string;
|
|
@@ -4162,11 +4205,67 @@ interface PipRailCostQuote {
|
|
|
4162
4205
|
/** Estimated network fee (gas) in the chain's native coin. */
|
|
4163
4206
|
cost: CostEstimate;
|
|
4164
4207
|
}
|
|
4208
|
+
/** A hard reason a rail can't be settled right now — each maps to a concrete fix. */
|
|
4209
|
+
type PayBlocker = 'INSUFFICIENT_TOKEN' | 'INSUFFICIENT_GAS' | 'RECIPIENT_NOT_READY' | 'OUTSIDE_POLICY';
|
|
4210
|
+
/** A soft flag — never blocks, always worth surfacing to the agent. */
|
|
4211
|
+
type PayWarning = 'SYMBOL_MISMATCH' | 'BALANCE_UNREADABLE' | 'RECIPIENT_READINESS_UNKNOWN' | 'GAS_HEURISTIC' | 'THIN_GAS_MARGIN';
|
|
4212
|
+
/** One offered rail, fully analysed against the bound wallet's own holdings. */
|
|
4213
|
+
interface PayOption {
|
|
4214
|
+
/** The rail this analyses (one entry from the 402's accepts[]). */
|
|
4215
|
+
accept: X402AcceptEntry;
|
|
4216
|
+
/** The priced requirement — TRUE decimals/symbol + the policy verdict. */
|
|
4217
|
+
quote: PipRailQuote;
|
|
4218
|
+
/** Estimated native-coin gas to send it (cost.basis surfaced). */
|
|
4219
|
+
cost: CostEstimate;
|
|
4220
|
+
/** The verdict for THIS rail. 'unknown' = a read failed, so payability can't be confirmed. */
|
|
4221
|
+
state: 'payable' | 'blocked' | 'unknown';
|
|
4222
|
+
/** Hard reasons it's blocked (empty when payable). */
|
|
4223
|
+
blockers: PayBlocker[];
|
|
4224
|
+
/** Soft flags (may be present even when payable). */
|
|
4225
|
+
warnings: PayWarning[];
|
|
4226
|
+
/** Live wallet holdings, human units; null = the read was unavailable (NOT zero). */
|
|
4227
|
+
balance: {
|
|
4228
|
+
token: string | null;
|
|
4229
|
+
native: string | null;
|
|
4230
|
+
};
|
|
4231
|
+
/** What this rail needs: the payment amount + the estimated gas, human units. */
|
|
4232
|
+
need: {
|
|
4233
|
+
token: string;
|
|
4234
|
+
native: string;
|
|
4235
|
+
};
|
|
4236
|
+
/** How much MORE is needed to clear a funds blocker, human units (omitted when funded). */
|
|
4237
|
+
shortfall?: {
|
|
4238
|
+
token?: string;
|
|
4239
|
+
native?: string;
|
|
4240
|
+
};
|
|
4241
|
+
/** Can payTo receive this asset right now, and if not, what fixes it. */
|
|
4242
|
+
recipient: {
|
|
4243
|
+
ready: boolean | 'n/a' | 'unknown';
|
|
4244
|
+
reason?: RecipientReason;
|
|
4245
|
+
fix?: string;
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
/** The plan for ONE 402 across every rail this client can pay (its bound network). */
|
|
4249
|
+
interface PaymentPlan {
|
|
4250
|
+
url: string;
|
|
4251
|
+
/** The network this client is bound to (the rails it can settle). */
|
|
4252
|
+
network: Caip2;
|
|
4253
|
+
/** Top-level verdict for instant branching. */
|
|
4254
|
+
status: 'ready' | 'blocked' | 'unknown';
|
|
4255
|
+
/** True iff at least one rail is payable now (best !== null). */
|
|
4256
|
+
payable: boolean;
|
|
4257
|
+
/** The rail to use: the cheapest (within native coin) payable option, or null. */
|
|
4258
|
+
best: PayOption | null;
|
|
4259
|
+
/** Every offered+supported rail, ranked: payable → unknown → blocked. */
|
|
4260
|
+
options: PayOption[];
|
|
4261
|
+
/** When NOT payable: one human, actionable sentence on exactly what to do. */
|
|
4262
|
+
fundingHint: string | null;
|
|
4263
|
+
}
|
|
4165
4264
|
interface PipRailClientOptions {
|
|
4166
4265
|
/** Wallet for the chosen chain family. */
|
|
4167
4266
|
wallet: WalletInput;
|
|
4168
4267
|
/** Which chain to pay on. EVM ('bnb'|'base'|…), 'solana', 'ton', 'stellar',
|
|
4169
|
-
* 'xrpl', 'tron', 'sui', or '
|
|
4268
|
+
* 'xrpl', 'tron', 'sui', 'near', 'aptos', or 'algorand'. */
|
|
4170
4269
|
chain: ChainSelector;
|
|
4171
4270
|
/** Override the chain's default RPC URL (recommended in production). */
|
|
4172
4271
|
rpcUrl?: string;
|
|
@@ -4200,6 +4299,16 @@ interface PipRailClientOptions {
|
|
|
4200
4299
|
maxPaymentRetries?: number;
|
|
4201
4300
|
/** Timeout (ms) for the retry leg after broadcast. Default 30_000. */
|
|
4202
4301
|
retryTimeoutMs?: number;
|
|
4302
|
+
/**
|
|
4303
|
+
* Balance-aware routing: when true, `fetch()` runs `planPayment` on a 402 and
|
|
4304
|
+
* pays the cheapest rail the wallet can ACTUALLY settle (token + native gas +
|
|
4305
|
+
* recipient-ready), instead of the first policy-passing accept. If none is
|
|
4306
|
+
* settleable it throws {@link PaymentDeclinedError} carrying the funding hint —
|
|
4307
|
+
* before any send. Default **false** (defaults never change): the zero-config
|
|
4308
|
+
* path keeps its existing selection. Recommended for multi-rail 402s. Override
|
|
4309
|
+
* per call with `fetch(url, { autoRoute: true })`.
|
|
4310
|
+
*/
|
|
4311
|
+
autoRoute?: boolean;
|
|
4203
4312
|
/** Logger hook. Default no-op. */
|
|
4204
4313
|
onEvent?: (event: PipRailEvent) => void;
|
|
4205
4314
|
}
|
|
@@ -4252,6 +4361,32 @@ declare class PipRailClient {
|
|
|
4252
4361
|
/** Aggregated snapshot of every payment this client has settled — total
|
|
4253
4362
|
* count, cumulative spend per token, and the individual records. */
|
|
4254
4363
|
spent(): SpendSummary;
|
|
4364
|
+
/**
|
|
4365
|
+
* Plan a payment for a gated URL — WITHOUT paying. The read-only completion of
|
|
4366
|
+
* the `quote()` → `estimateCost()` → **`planPayment()`** trio: it surveys every
|
|
4367
|
+
* rail the 402 offers on this client's chain against the wallet's OWN holdings —
|
|
4368
|
+
* token balance, native-coin gas, and recipient-readiness (trustline / ATA /
|
|
4369
|
+
* storage_deposit / ASA opt-in) — and returns, crystal-clear:
|
|
4370
|
+
* - `payable` + `best` — the cheapest rail the wallet can actually settle
|
|
4371
|
+
* - `options[]` — every rail with typed `blockers` + soft `warnings`
|
|
4372
|
+
* - `fundingHint` — one human sentence on exactly what to top up
|
|
4373
|
+
*
|
|
4374
|
+
* NEVER throws for a read problem (a transient/RPC failure surfaces as a rail in
|
|
4375
|
+
* `state: 'unknown'` + a warning, never a false "unaffordable"); returns `null`
|
|
4376
|
+
* when the URL isn't payment-gated (no 402); and when the 402 offers no rail on
|
|
4377
|
+
* this client's chain it EXPLAINS that (status `blocked` + a hint), rather than
|
|
4378
|
+
* throwing. Throws `InvalidEnvelopeError` only on an unparseable challenge.
|
|
4379
|
+
*
|
|
4380
|
+
* Then pay the chosen rail with `fetch(url, { autoRoute: true })`, or branch on
|
|
4381
|
+
* the plan yourself. No funds move.
|
|
4382
|
+
*/
|
|
4383
|
+
planPayment(url: string, init?: RequestInit): Promise<PaymentPlan | null>;
|
|
4384
|
+
/**
|
|
4385
|
+
* Convenience over {@link planPayment}: can the wallet settle this URL right now?
|
|
4386
|
+
* `true` when at least one rail is payable — or when the URL isn't gated (a free
|
|
4387
|
+
* resource is trivially "affordable"). No funds move.
|
|
4388
|
+
*/
|
|
4389
|
+
canAfford(url: string, init?: RequestInit): Promise<boolean>;
|
|
4255
4390
|
/**
|
|
4256
4391
|
* Lower-level: drive any HTTP method through the 402 flow.
|
|
4257
4392
|
*
|
|
@@ -4266,6 +4401,14 @@ declare class PipRailClient {
|
|
|
4266
4401
|
* `quote()` (read-only) and `fetch()` (which then authorises + pays).
|
|
4267
4402
|
*/
|
|
4268
4403
|
private resolveChallenge;
|
|
4404
|
+
/** The candidate accepts this client could pay: our scheme, on the bound network. */
|
|
4405
|
+
private gatherCandidates;
|
|
4406
|
+
/** Build the full {@link PaymentPlan} from an already-parsed challenge + bound
|
|
4407
|
+
* net/wallet. Shared by `planPayment` (read-only) and `fetch`'s autoRoute. */
|
|
4408
|
+
private planFromChallenge;
|
|
4409
|
+
/** Analyse ONE rail against the wallet's holdings — quote (existing) + gas
|
|
4410
|
+
* (estimateCost, existing) + balanceOf + recipientReady → a {@link PayOption}. */
|
|
4411
|
+
private analyzeRail;
|
|
4269
4412
|
/** Build the agent-facing quote for an accept: TRUE decimals/symbol (via the
|
|
4270
4413
|
* driver's describeAsset) + the policy verdict + a symbol-mismatch flag. */
|
|
4271
4414
|
private buildQuote;
|
|
@@ -4277,6 +4420,16 @@ declare class PipRailClient {
|
|
|
4277
4420
|
private payAndConfirm;
|
|
4278
4421
|
private retryWithProof;
|
|
4279
4422
|
}
|
|
4423
|
+
/**
|
|
4424
|
+
* Plan a payment ACROSS several single-chain clients — the cross-chain brain.
|
|
4425
|
+
* A {@link PipRailClient} is bound to one chain (its wallet); give this one client
|
|
4426
|
+
* per chain the agent funds and it runs each client's {@link PipRailClient.planPayment}
|
|
4427
|
+
* in parallel and merges the rails into one plan, ranked payable-first. `best` is a
|
|
4428
|
+
* payable rail; across different native coins there's no oracle to pick the
|
|
4429
|
+
* fiat-cheapest, so the tiebreak is the order `clients` were given (the agent's own
|
|
4430
|
+
* chain preference). Returns `null` only if the URL isn't gated for any client.
|
|
4431
|
+
*/
|
|
4432
|
+
declare function planAcross(clients: PipRailClient[], url: string, init?: RequestInit): Promise<PaymentPlan | null>;
|
|
4280
4433
|
|
|
4281
4434
|
/** A framework-agnostic tool definition an agent runtime can register. */
|
|
4282
4435
|
interface AgentTool {
|
|
@@ -4290,8 +4443,10 @@ interface AgentTool {
|
|
|
4290
4443
|
invoke: (args: Record<string, unknown>) => Promise<unknown>;
|
|
4291
4444
|
}
|
|
4292
4445
|
/**
|
|
4293
|
-
*
|
|
4446
|
+
* Three tools wrapping a configured {@link PipRailClient}:
|
|
4294
4447
|
* - `piprail_quote_payment(url)` — price a gated URL WITHOUT paying.
|
|
4448
|
+
* - `piprail_plan_payment(url)` — check you CAN pay (balance + gas + recipient
|
|
4449
|
+
* readiness) across every rail the URL offers, WITHOUT paying.
|
|
4295
4450
|
* - `piprail_pay_request(url, method?, body?)` — pay if needed and return the result.
|
|
4296
4451
|
*
|
|
4297
4452
|
* A policy/approval refusal comes back as a structured `{ declined: true, reason }`
|
|
@@ -4327,7 +4482,7 @@ declare function paymentTools(client: PipRailClient): AgentTool[];
|
|
|
4327
4482
|
*/
|
|
4328
4483
|
interface AcceptOption {
|
|
4329
4484
|
/** Which chain. EVM ('bnb'|'base'|…), 'solana', 'ton', 'stellar', 'xrpl',
|
|
4330
|
-
* 'tron', 'near', or '
|
|
4485
|
+
* 'tron', 'near', 'sui', 'aptos', or 'algorand'. */
|
|
4331
4486
|
chain: ChainSelector;
|
|
4332
4487
|
/** Token to be paid in (symbol / 'native' / custom descriptor). */
|
|
4333
4488
|
token: TokenInput;
|
|
@@ -4341,8 +4496,9 @@ interface AcceptOption {
|
|
|
4341
4496
|
interface RequirePaymentOptions {
|
|
4342
4497
|
/**
|
|
4343
4498
|
* Single-chain form: which chain to accept payment on. EVM ('bnb'|'base'|…),
|
|
4344
|
-
* 'solana', 'ton', 'stellar', 'xrpl', 'tron', 'near',
|
|
4345
|
-
* `chain` + `token` + `amount`, OR use the multi-chain
|
|
4499
|
+
* 'solana', 'ton', 'stellar', 'xrpl', 'tron', 'near', 'sui', 'aptos', or
|
|
4500
|
+
* 'algorand'. Provide `chain` + `token` + `amount`, OR use the multi-chain
|
|
4501
|
+
* `accept` array below.
|
|
4346
4502
|
*/
|
|
4347
4503
|
chain?: ChainSelector;
|
|
4348
4504
|
/** Override the chain's default RPC URL (recommended in production). */
|
|
@@ -4353,9 +4509,10 @@ interface RequirePaymentOptions {
|
|
|
4353
4509
|
* `{ address, decimals }` on EVM/Tron, `{ mint, decimals }` on Solana,
|
|
4354
4510
|
* `{ master, decimals }` on TON, `{ issuer, code, decimals }` on Stellar,
|
|
4355
4511
|
* `{ issuer, currencyHex, decimals }` on XRPL, `{ contractId, decimals }` on
|
|
4356
|
-
* NEAR, `{ coinType, decimals }` on Sui
|
|
4512
|
+
* NEAR, `{ coinType, decimals }` on Sui, `{ metadata, decimals }` on Aptos, or
|
|
4513
|
+
* `{ assetId, decimals }` on Algorand. You name the token; the SDK fills in
|
|
4357
4514
|
* the contract + decimals for built-in symbols. (Note: native USDC doesn't
|
|
4358
|
-
* exist on TON/Tron — USDT does; NEAR is
|
|
4515
|
+
* exist on TON/Tron — USDT does; native NEAR is supported via `'native'`.)
|
|
4359
4516
|
*/
|
|
4360
4517
|
token?: TokenInput;
|
|
4361
4518
|
/** Human-readable amount, e.g. "0.05" (single-chain form). */
|
|
@@ -4367,8 +4524,8 @@ interface RequirePaymentOptions {
|
|
|
4367
4524
|
*/
|
|
4368
4525
|
accept?: AcceptOption[];
|
|
4369
4526
|
/** Address that receives the payment (0x… EVM/Sui, base58 Solana, EQ…/UQ… TON,
|
|
4370
|
-
* G… Stellar, r… XRPL, T… Tron, account id on NEAR
|
|
4371
|
-
* form; the per-option fallback for the multi form. */
|
|
4527
|
+
* G… Stellar, r… XRPL, T… Tron, account id on NEAR, 0x… Aptos, base32 Algorand).
|
|
4528
|
+
* Required for the single form; the per-option fallback for the multi form. */
|
|
4372
4529
|
payTo?: AddressId;
|
|
4373
4530
|
/** Shown to the agent in the challenge. */
|
|
4374
4531
|
description?: string;
|
|
@@ -4518,7 +4675,7 @@ declare class InsufficientFundsError extends PipRailError {
|
|
|
4518
4675
|
* The message states the requirement and the fix in plain language **and echoes
|
|
4519
4676
|
* the raw chain code** (e.g. `(XRPL: tecNO_DST_INSUF_XRP)`), while the untouched
|
|
4520
4677
|
* chain error is preserved on `.cause` for deeper debugging. Chains with no
|
|
4521
|
-
* receive prerequisite (EVM, Solana, Sui, Tron, and native TON/NEAR) never throw it.
|
|
4678
|
+
* receive prerequisite (EVM, Solana, Sui, Aptos, Tron, and native TON/NEAR) never throw it.
|
|
4522
4679
|
*/
|
|
4523
4680
|
declare class RecipientNotReadyError extends PipRailError {
|
|
4524
4681
|
readonly code = "RECIPIENT_NOT_READY";
|
|
@@ -4615,7 +4772,7 @@ declare class NonReplayableBodyError extends PipRailError {
|
|
|
4615
4772
|
}
|
|
4616
4773
|
/**
|
|
4617
4774
|
* The chosen chain belongs to one family (EVM, Solana, TON, Stellar, XRPL, Tron,
|
|
4618
|
-
* Sui, NEAR) but the wallet, payTo, or token was given in another family's form
|
|
4775
|
+
* Sui, NEAR, Aptos, Algorand) but the wallet, payTo, or token was given in another family's form
|
|
4619
4776
|
* (e.g. an `0x…` payTo on Solana, or a `{ mint }` token on a Stellar chain).
|
|
4620
4777
|
*/
|
|
4621
4778
|
declare class WrongFamilyError extends PipRailError {
|
|
@@ -4627,7 +4784,8 @@ declare class WrongFamilyError extends PipRailError {
|
|
|
4627
4784
|
* token by full descriptor ({ address, decimals } EVM/Tron · { mint, decimals }
|
|
4628
4785
|
* Solana · { master, decimals } TON · { issuer, code, decimals } Stellar ·
|
|
4629
4786
|
* { issuer, currencyHex, decimals } XRPL · { coinType, decimals } Sui ·
|
|
4630
|
-
* { contractId, decimals } NEAR
|
|
4787
|
+
* { contractId, decimals } NEAR · { metadata, decimals } Aptos ·
|
|
4788
|
+
* { assetId, decimals } Algorand).
|
|
4631
4789
|
*/
|
|
4632
4790
|
declare class UnknownTokenError extends PipRailError {
|
|
4633
4791
|
readonly code = "UNKNOWN_TOKEN";
|
|
@@ -4639,7 +4797,8 @@ declare class UnknownTokenError extends PipRailError {
|
|
|
4639
4797
|
* `npm install @ton/ton @ton/core @ton/crypto`; Stellar:
|
|
4640
4798
|
* `npm install @stellar/stellar-sdk`; XRPL: `npm install xrpl`; Tron:
|
|
4641
4799
|
* `npm install tronweb`; Sui: `npm install @mysten/sui`; NEAR:
|
|
4642
|
-
* `npm install near-api-js
|
|
4800
|
+
* `npm install near-api-js`; Aptos: `npm install @aptos-labs/ts-sdk`;
|
|
4801
|
+
* Algorand: `npm install algosdk`.
|
|
4643
4802
|
*/
|
|
4644
4803
|
declare class MissingDriverError extends PipRailError {
|
|
4645
4804
|
readonly code = "MISSING_DRIVER";
|
|
@@ -4765,4 +4924,4 @@ declare function encodeXPaymentHeader(input: {
|
|
|
4765
4924
|
x402Version?: number;
|
|
4766
4925
|
}): string;
|
|
4767
4926
|
|
|
4768
|
-
export { type AcceptOption, type AddressId, type AgentTool, type AssetId, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, InsufficientFundsError, InvalidEnvelopeError, MaxRetriesExceededError, MissingDriverError, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPolicy, PaymentTimeoutError, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, RecipientNotReadyError, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type TronToken, UnknownTokenError, UnsupportedNetworkError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletHandle, type WalletInput, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402Challenge, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, type XrplToken, buildChallengeHeader, buildExactAuthorization, buildReceiptHeader, buildSignatureHeader, chainIdForExactNetwork, createPaymentGate, encodeXPaymentHeader, evaluatePolicy, parseChallenge, parseExactRequirements, parseReceipt, parseSignatureHeader, paymentTools, pickAccept, registerDriver, requirePayment, resolveChain, toInsufficientFundsError, toInvalidBody };
|
|
4927
|
+
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, InsufficientFundsError, InvalidEnvelopeError, MaxRetriesExceededError, MissingDriverError, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type PayBlocker, type PayOption, type PayWarning, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, PaymentTimeoutError, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, RecipientNotReadyError, type RecipientReason, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type TronToken, UnknownTokenError, UnsupportedNetworkError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402Challenge, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, type XrplToken, buildChallengeHeader, buildExactAuthorization, buildReceiptHeader, buildSignatureHeader, chainIdForExactNetwork, createPaymentGate, encodeXPaymentHeader, evaluatePolicy, parseChallenge, parseExactRequirements, parseReceipt, parseSignatureHeader, paymentTools, pickAccept, planAcross, registerDriver, requirePayment, resolveChain, toInsufficientFundsError, toInvalidBody };
|