@piprail/sdk 2.6.0 → 2.8.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 +67 -0
- package/README.md +1 -1
- package/dist/{algorand-TMA62DN2.cjs → algorand-EKD34T4Q.cjs} +32 -32
- package/dist/{algorand-WB6PBJU4.js → algorand-WJL6VRXW.js} +1 -1
- package/dist/{aptos-JQMZNTMD.cjs → aptos-CVHLVMAF.cjs} +31 -31
- package/dist/{aptos-QAAXIUY3.js → aptos-WMPFEASY.js} +1 -1
- package/dist/{chunk-JG6KRAW6.cjs → chunk-VPENSVOI.cjs} +8 -0
- package/dist/{chunk-7XK22JSQ.js → chunk-W3HOMXOF.js} +8 -0
- package/dist/index.cjs +158 -119
- package/dist/index.d.cts +64 -10
- package/dist/index.d.ts +64 -10
- package/dist/index.js +66 -27
- package/dist/{near-H5AQ253I.cjs → near-NYFMX2KA.cjs} +26 -26
- package/dist/{near-OTPQD6BI.js → near-QV4IOZNX.js} +1 -1
- package/dist/{solana-M3VOHCMO.cjs → solana-L342QCSV.cjs} +64 -33
- package/dist/{solana-3FMCWSEE.js → solana-Z34OWXMO.js} +33 -2
- package/dist/{stellar-U5NCRIOJ.js → stellar-PWC4LETJ.js} +1 -1
- package/dist/{stellar-FW6C6FBE.cjs → stellar-YEXRVR3W.cjs} +20 -20
- package/dist/{sui-47C2KEZI.cjs → sui-EFRSCDWN.cjs} +16 -16
- package/dist/{sui-Y53M4GUM.js → sui-VEOGHBYE.js} +1 -1
- package/dist/{ton-MMPKWT6N.cjs → ton-LZKJWYHV.cjs} +25 -21
- package/dist/{ton-5ZPT5PSP.js → ton-N7KSPSAR.js} +11 -7
- package/dist/{tron-JOT4STIG.cjs → tron-DQU4WTGQ.cjs} +24 -24
- package/dist/{tron-WYS4X2I5.js → tron-WKDUQVZR.js} +1 -1
- package/dist/{xrpl-2MZEOIFY.js → xrpl-6B4IYRWI.js} +1 -1
- package/dist/{xrpl-PECT4IMX.cjs → xrpl-K3U3SBF4.cjs} +20 -20
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -4741,6 +4741,8 @@ declare function getDirectoryInfo(source: DiscoverySource): DirectoryInfo;
|
|
|
4741
4741
|
declare function decorateOutcome(o: RegisterOutcome): RegisterOutcome;
|
|
4742
4742
|
/** Normalize an index's network field to CAIP-2 when we recognise the slug;
|
|
4743
4743
|
* pass a value that's already CAIP-2 (`namespace:reference`) through unchanged.
|
|
4744
|
+
* A legacy/superseded CAIP-2 id is mapped to its canonical replacement first
|
|
4745
|
+
* (so a colon-bearing legacy id like `ton:-239` still canonicalizes).
|
|
4744
4746
|
* An unknown slug returns unchanged (no `:`), which the client treats as
|
|
4745
4747
|
* "unresolved — don't hide it" rather than a confident mismatch. */
|
|
4746
4748
|
declare function normalizeNetwork(network: string): string;
|
|
@@ -5044,6 +5046,14 @@ type PipRailEvent = {
|
|
|
5044
5046
|
} | {
|
|
5045
5047
|
kind: 'payment-failed';
|
|
5046
5048
|
reason: string;
|
|
5049
|
+
/** A machine-readable failure code when one is known. For a SERVER rejection it's the SAME
|
|
5050
|
+
* code the merchant's `onFailed` hook receives (a canonical {@link VerifyErrorCode} from a
|
|
5051
|
+
* PipRail gate, or a foreign facilitator's reason string); for a pre-send client DECLINE
|
|
5052
|
+
* (policy / budget / approval) it's that decline reason (e.g. `'BUDGET'`, `'APPROVAL'`).
|
|
5053
|
+
* Absent when no structured code was given. */
|
|
5054
|
+
code?: string;
|
|
5055
|
+
/** Human-readable detail, when present (e.g. `"Paid 40000, required 500000."`). */
|
|
5056
|
+
detail?: string;
|
|
5047
5057
|
};
|
|
5048
5058
|
/**
|
|
5049
5059
|
* Wallet for the chosen chain family. **One field, every chain: `{ key }`** — the
|
|
@@ -6463,6 +6473,28 @@ interface ExactRailOption {
|
|
|
6463
6473
|
* "just works". Force `'eip3009'` or `'permit2'` to pin one. Ignored on Solana (always SVM). */
|
|
6464
6474
|
method?: 'eip3009' | 'permit2' | 'auto';
|
|
6465
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* The merchant-side mirror of {@link PaidReceipt}: what an {@link RequirePaymentOptions.onFailed}
|
|
6478
|
+
* hook receives when a SUBMITTED payment proof is REJECTED. It carries the SAME machine-readable
|
|
6479
|
+
* `code` the buyer's client is given for that rejection, so both sides are notified of one
|
|
6480
|
+
* consistent reason. (A rejection has no settlement, so — unlike a receipt — there is no tx hash
|
|
6481
|
+
* or settled amount to report.)
|
|
6482
|
+
*/
|
|
6483
|
+
interface FailedPayment {
|
|
6484
|
+
/** The canonical rejection reason — the same {@link VerifyErrorCode} surfaced to the buyer
|
|
6485
|
+
* (e.g. `amount_too_low`, `payment_expired`, `tx_already_used`, `transfer_not_found`). */
|
|
6486
|
+
code: VerifyErrorCode;
|
|
6487
|
+
/** Human-readable detail, e.g. `"Paid 40000, required 500000."`. */
|
|
6488
|
+
detail: string;
|
|
6489
|
+
/**
|
|
6490
|
+
* `true` for a **transient** rejection (`tx_not_found` / `insufficient_confirmations`): the proof
|
|
6491
|
+
* may still be settling and the buyer's client **retries automatically** — you'll get `onPaid` if
|
|
6492
|
+
* it then succeeds. `false` for a **definitive** rejection the buyer must fix (wrong amount,
|
|
6493
|
+
* expired, replayed, bad signature, wrong recipient). Alert on `!transient` to avoid false alarms
|
|
6494
|
+
* on normal RPC lag; nothing is hidden — every rejected attempt still fires `onFailed`.
|
|
6495
|
+
*/
|
|
6496
|
+
transient: boolean;
|
|
6497
|
+
}
|
|
6466
6498
|
interface RequirePaymentOptions {
|
|
6467
6499
|
/**
|
|
6468
6500
|
* Single-chain form: which chain to accept payment on. EVM ('bnb'|'base'|…),
|
|
@@ -6535,6 +6567,37 @@ interface RequirePaymentOptions {
|
|
|
6535
6567
|
* via `onPaidError`; it never turns a settled payment into a 402.
|
|
6536
6568
|
*/
|
|
6537
6569
|
awaitOnPaid?: boolean;
|
|
6570
|
+
/**
|
|
6571
|
+
* The merchant-side mirror of `onPaid`: fired when a SUBMITTED payment proof is REJECTED — a
|
|
6572
|
+
* `kind:'invalid'` verdict (wrong amount, expired, replayed, unknown asset, …). Receives a
|
|
6573
|
+
* {@link FailedPayment} carrying the SAME machine `code` the buyer's client is given, so the
|
|
6574
|
+
* merchant and the buyer are notified of the same failure with the same reason.
|
|
6575
|
+
*
|
|
6576
|
+
* Fires ONLY on a rejected attempt — NOT on a normal first-request 402 `challenge` (no proof
|
|
6577
|
+
* yet), and NOT on a transient/settlement error that throws (an RPC blip, or a 5xx
|
|
6578
|
+
* `SettlementError`): those aren't payment verdicts. Like `onPaid`, it may be **sync or async**
|
|
6579
|
+
* and is fully isolated — a throw OR a rejected promise is caught and routed to `onFailedError`,
|
|
6580
|
+
* so it can never break the request or crash the process. Fire-and-forget by default; set
|
|
6581
|
+
* `awaitOnFailed` to run it before the 402 is returned.
|
|
6582
|
+
*
|
|
6583
|
+
* NOTE: a failure the merchant never receives a request for — the buyer can't afford it, an
|
|
6584
|
+
* `onBeforePay`/`policy` declines it, or the buyer abandons before paying — cannot reach a
|
|
6585
|
+
* backendless gate (only the buyer's client sees it). `onFailed` covers every rejection that
|
|
6586
|
+
* DOES reach the gate.
|
|
6587
|
+
*/
|
|
6588
|
+
onFailed?: (failure: FailedPayment) => void | Promise<void>;
|
|
6589
|
+
/**
|
|
6590
|
+
* Observe a failure inside `onFailed` (sync throw or async rejection) — the mirror of
|
|
6591
|
+
* `onPaidError`. Without it, a throwing `onFailed` is swallowed silently. Its own throws are
|
|
6592
|
+
* also swallowed (it can never break a request).
|
|
6593
|
+
*/
|
|
6594
|
+
onFailedError?: (error: unknown, failure: FailedPayment) => void;
|
|
6595
|
+
/**
|
|
6596
|
+
* Await `onFailed` before the 402 rejection is returned (mirror of `awaitOnPaid`), so
|
|
6597
|
+
* "failure recorded" is guaranteed before the caller is told. Default `false` (fire-and-forget).
|
|
6598
|
+
* A rejection inside the hook is still isolated via `onFailedError`.
|
|
6599
|
+
*/
|
|
6600
|
+
awaitOnFailed?: boolean;
|
|
6538
6601
|
/**
|
|
6539
6602
|
* ALSO advertise a standard x402 `exact` rail so any standard x402 client can pay this
|
|
6540
6603
|
* gate — opt-in, EVM (EIP-3009/Permit2) + Solana (SVM). See {@link ExactRailOption}.
|
|
@@ -6639,15 +6702,6 @@ interface PaymentGate {
|
|
|
6639
6702
|
*/
|
|
6640
6703
|
landingPage(challenge: X402Challenge): string;
|
|
6641
6704
|
}
|
|
6642
|
-
/**
|
|
6643
|
-
* Framework-agnostic core. Build one gate per gated resource and reuse it
|
|
6644
|
-
* — its in-memory used-tx set is what stops the same proof being redeemed
|
|
6645
|
-
* twice. Wrap it for Express with `requirePayment`, or call it directly
|
|
6646
|
-
* from Hono / Fastify / Adonis / Workers / etc.
|
|
6647
|
-
*
|
|
6648
|
-
* The chain's driver is resolved lazily on first `challenge()`/`verify()`,
|
|
6649
|
-
* which is what lets Solana (and future families) auto-mount with no setup.
|
|
6650
|
-
*/
|
|
6651
6705
|
declare function createPaymentGate(options: RequirePaymentOptions): PaymentGate;
|
|
6652
6706
|
interface ExpressLikeRequest {
|
|
6653
6707
|
headers: Record<string, string | string[] | undefined>;
|
|
@@ -7527,4 +7581,4 @@ declare const PERMIT2_WITNESS_TYPES: {
|
|
|
7527
7581
|
*/
|
|
7528
7582
|
declare function renderLandingPage(sd: SelfDescription): string;
|
|
7529
7583
|
|
|
7530
|
-
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, BRAND, type BazaarExtension, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ChallengeTriage, type ChallengeVerdict, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, DIRECTORY_INFO, type DeclineReasonCode, type DeliverAttempt, type DeliverReceiptOptions, type DeliverResult, type DirectoryInfo, type DiscoverOptions, type DiscoveredRail, type DiscoveredResource, type DiscoveryDescriptor, type DiscoverySigner, type DiscoverySort, type DiscoverySource, type DomainClaim, type DomainVerification, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExactAuthorizationWire, type ExactPaymentPayload, type ExactPaymentPayloadAny, type ExactRailOption, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, type FacilitatorConfig, type FacilitatorPaymentRequirements, type FacilitatorSupportedKind, GENERATOR, HEADER_REQUIRED, HEADER_RESPONSE, HEADER_RESPONSE_V1, HEADER_SIGNATURE, HEADER_SIGNATURE_V1, InsufficientFundsError, InvalidEnvelopeError, KNOWN_FACILITATORS, type KnownFacilitator, type ListingVisibility, type ManifestInput, MaxRetriesExceededError, MissingDriverError, MultiChainPayer, type MultiChainPayerOptions, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type OpenApiDocument, type OpenApiOperation, PERMIT2_ADDRESS, PERMIT2_PROXY_CHAIN_IDS, PERMIT2_WITNESS_TYPES, PIPRAIL_AGENT_GUIDE, POWERED_BY, type PaidReceipt, type ParsedExactPayment, type PayBlocker, type PayOption, type PayWarning, type PayingClient, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, type PaymentRail, type PaymentScheme, PaymentTimeoutError, type Permit2Authorization, type Permit2PaymentPayload, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, type PolicyDenyCode, REGISTER_ATTRIBUTION, RecipientNotReadyError, type RecipientReason, type RegisterInput, type RegisterOptions, type RegisterOutcome, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type ResourceDescription, type SearchOpenIndexesOptions, type SelfDescribeEndpoint, type SelfDescribeRail, type SelfDescription, type SessionBudget, type SettleOutcome, type SettleViaFacilitatorInput, SettlementError, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendRemaining, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type ToolAnnotations, type TronToken, UnknownTokenError, UnsupportedNetworkError, UnsupportedSchemeError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WalletRequiredError, type WellKnownX402, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402AnyAccept, type X402Challenge, type X402DnsRecord, type X402ExactAcceptEntry, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, X402_EXACT_PERMIT2_PROXY, type XrplToken, agentGuide, appendAttribution, appendKeywords, buildBazaarExtension, buildChallengeHeader, buildEndpointInfo, buildExactAuthorization, buildExactSignatureHeader, buildOpenApi, buildReceiptHeader, buildSelfDescription, buildSignatureHeader, buildWellKnownX402, buildX402DnsTxt, chainIdForExactNetwork, claim402IndexDomain, classifyChallenge, createPaymentGate, decorateOutcome, deliverReceipt, describeChallenge, discoveryHeaders, eip3009Abi, encodeXPaymentHeader, evaluatePolicy, explainDecline, facilitatorCoverage, fetchAcross, firstKeylessFacilitator, formatSpendReport, getDirectoryInfo, isPermit2ProxyChain, knownFacilitatorsFor, normalizeNetwork, parseChallenge, parseExactPaymentHeader, parseExactRequirements, parseFacilitatorSupported, parseReceipt, parseSettleResponse, parseSignatureHeader, paymentTools, pickAccept, planAcross, rankResources, readExactDomain, register402Index, registerDriver, registerX402Scan, renderLandingPage, requirePayment, resolveChain, scoreResource, searchOpenIndexes, settleViaFacilitator, summarizePlan, toInsufficientFundsError, toInvalidBody, verify402IndexDomain };
|
|
7584
|
+
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, BRAND, type BazaarExtension, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ChallengeTriage, type ChallengeVerdict, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, DIRECTORY_INFO, type DeclineReasonCode, type DeliverAttempt, type DeliverReceiptOptions, type DeliverResult, type DirectoryInfo, type DiscoverOptions, type DiscoveredRail, type DiscoveredResource, type DiscoveryDescriptor, type DiscoverySigner, type DiscoverySort, type DiscoverySource, type DomainClaim, type DomainVerification, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExactAuthorizationWire, type ExactPaymentPayload, type ExactPaymentPayloadAny, type ExactRailOption, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, type FacilitatorConfig, type FacilitatorPaymentRequirements, type FacilitatorSupportedKind, type FailedPayment, GENERATOR, HEADER_REQUIRED, HEADER_RESPONSE, HEADER_RESPONSE_V1, HEADER_SIGNATURE, HEADER_SIGNATURE_V1, InsufficientFundsError, InvalidEnvelopeError, KNOWN_FACILITATORS, type KnownFacilitator, type ListingVisibility, type ManifestInput, MaxRetriesExceededError, MissingDriverError, MultiChainPayer, type MultiChainPayerOptions, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type OpenApiDocument, type OpenApiOperation, PERMIT2_ADDRESS, PERMIT2_PROXY_CHAIN_IDS, PERMIT2_WITNESS_TYPES, PIPRAIL_AGENT_GUIDE, POWERED_BY, type PaidReceipt, type ParsedExactPayment, type PayBlocker, type PayOption, type PayWarning, type PayingClient, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, type PaymentRail, type PaymentScheme, PaymentTimeoutError, type Permit2Authorization, type Permit2PaymentPayload, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, type PolicyDenyCode, REGISTER_ATTRIBUTION, RecipientNotReadyError, type RecipientReason, type RegisterInput, type RegisterOptions, type RegisterOutcome, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type ResourceDescription, type SearchOpenIndexesOptions, type SelfDescribeEndpoint, type SelfDescribeRail, type SelfDescription, type SessionBudget, type SettleOutcome, type SettleViaFacilitatorInput, SettlementError, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendRemaining, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type ToolAnnotations, type TronToken, UnknownTokenError, UnsupportedNetworkError, UnsupportedSchemeError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WalletRequiredError, type WellKnownX402, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402AnyAccept, type X402Challenge, type X402DnsRecord, type X402ExactAcceptEntry, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, X402_EXACT_PERMIT2_PROXY, type XrplToken, agentGuide, appendAttribution, appendKeywords, buildBazaarExtension, buildChallengeHeader, buildEndpointInfo, buildExactAuthorization, buildExactSignatureHeader, buildOpenApi, buildReceiptHeader, buildSelfDescription, buildSignatureHeader, buildWellKnownX402, buildX402DnsTxt, chainIdForExactNetwork, claim402IndexDomain, classifyChallenge, createPaymentGate, decorateOutcome, deliverReceipt, describeChallenge, discoveryHeaders, eip3009Abi, encodeXPaymentHeader, evaluatePolicy, explainDecline, facilitatorCoverage, fetchAcross, firstKeylessFacilitator, formatSpendReport, getDirectoryInfo, isPermit2ProxyChain, knownFacilitatorsFor, normalizeNetwork, parseChallenge, parseExactPaymentHeader, parseExactRequirements, parseFacilitatorSupported, parseReceipt, parseSettleResponse, parseSignatureHeader, paymentTools, pickAccept, planAcross, rankResources, readExactDomain, register402Index, registerDriver, registerX402Scan, renderLandingPage, requirePayment, resolveChain, scoreResource, searchOpenIndexes, settleViaFacilitator, summarizePlan, toInsufficientFundsError, toInvalidBody, verify402IndexDomain };
|
package/dist/index.d.ts
CHANGED
|
@@ -4741,6 +4741,8 @@ declare function getDirectoryInfo(source: DiscoverySource): DirectoryInfo;
|
|
|
4741
4741
|
declare function decorateOutcome(o: RegisterOutcome): RegisterOutcome;
|
|
4742
4742
|
/** Normalize an index's network field to CAIP-2 when we recognise the slug;
|
|
4743
4743
|
* pass a value that's already CAIP-2 (`namespace:reference`) through unchanged.
|
|
4744
|
+
* A legacy/superseded CAIP-2 id is mapped to its canonical replacement first
|
|
4745
|
+
* (so a colon-bearing legacy id like `ton:-239` still canonicalizes).
|
|
4744
4746
|
* An unknown slug returns unchanged (no `:`), which the client treats as
|
|
4745
4747
|
* "unresolved — don't hide it" rather than a confident mismatch. */
|
|
4746
4748
|
declare function normalizeNetwork(network: string): string;
|
|
@@ -5044,6 +5046,14 @@ type PipRailEvent = {
|
|
|
5044
5046
|
} | {
|
|
5045
5047
|
kind: 'payment-failed';
|
|
5046
5048
|
reason: string;
|
|
5049
|
+
/** A machine-readable failure code when one is known. For a SERVER rejection it's the SAME
|
|
5050
|
+
* code the merchant's `onFailed` hook receives (a canonical {@link VerifyErrorCode} from a
|
|
5051
|
+
* PipRail gate, or a foreign facilitator's reason string); for a pre-send client DECLINE
|
|
5052
|
+
* (policy / budget / approval) it's that decline reason (e.g. `'BUDGET'`, `'APPROVAL'`).
|
|
5053
|
+
* Absent when no structured code was given. */
|
|
5054
|
+
code?: string;
|
|
5055
|
+
/** Human-readable detail, when present (e.g. `"Paid 40000, required 500000."`). */
|
|
5056
|
+
detail?: string;
|
|
5047
5057
|
};
|
|
5048
5058
|
/**
|
|
5049
5059
|
* Wallet for the chosen chain family. **One field, every chain: `{ key }`** — the
|
|
@@ -6463,6 +6473,28 @@ interface ExactRailOption {
|
|
|
6463
6473
|
* "just works". Force `'eip3009'` or `'permit2'` to pin one. Ignored on Solana (always SVM). */
|
|
6464
6474
|
method?: 'eip3009' | 'permit2' | 'auto';
|
|
6465
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* The merchant-side mirror of {@link PaidReceipt}: what an {@link RequirePaymentOptions.onFailed}
|
|
6478
|
+
* hook receives when a SUBMITTED payment proof is REJECTED. It carries the SAME machine-readable
|
|
6479
|
+
* `code` the buyer's client is given for that rejection, so both sides are notified of one
|
|
6480
|
+
* consistent reason. (A rejection has no settlement, so — unlike a receipt — there is no tx hash
|
|
6481
|
+
* or settled amount to report.)
|
|
6482
|
+
*/
|
|
6483
|
+
interface FailedPayment {
|
|
6484
|
+
/** The canonical rejection reason — the same {@link VerifyErrorCode} surfaced to the buyer
|
|
6485
|
+
* (e.g. `amount_too_low`, `payment_expired`, `tx_already_used`, `transfer_not_found`). */
|
|
6486
|
+
code: VerifyErrorCode;
|
|
6487
|
+
/** Human-readable detail, e.g. `"Paid 40000, required 500000."`. */
|
|
6488
|
+
detail: string;
|
|
6489
|
+
/**
|
|
6490
|
+
* `true` for a **transient** rejection (`tx_not_found` / `insufficient_confirmations`): the proof
|
|
6491
|
+
* may still be settling and the buyer's client **retries automatically** — you'll get `onPaid` if
|
|
6492
|
+
* it then succeeds. `false` for a **definitive** rejection the buyer must fix (wrong amount,
|
|
6493
|
+
* expired, replayed, bad signature, wrong recipient). Alert on `!transient` to avoid false alarms
|
|
6494
|
+
* on normal RPC lag; nothing is hidden — every rejected attempt still fires `onFailed`.
|
|
6495
|
+
*/
|
|
6496
|
+
transient: boolean;
|
|
6497
|
+
}
|
|
6466
6498
|
interface RequirePaymentOptions {
|
|
6467
6499
|
/**
|
|
6468
6500
|
* Single-chain form: which chain to accept payment on. EVM ('bnb'|'base'|…),
|
|
@@ -6535,6 +6567,37 @@ interface RequirePaymentOptions {
|
|
|
6535
6567
|
* via `onPaidError`; it never turns a settled payment into a 402.
|
|
6536
6568
|
*/
|
|
6537
6569
|
awaitOnPaid?: boolean;
|
|
6570
|
+
/**
|
|
6571
|
+
* The merchant-side mirror of `onPaid`: fired when a SUBMITTED payment proof is REJECTED — a
|
|
6572
|
+
* `kind:'invalid'` verdict (wrong amount, expired, replayed, unknown asset, …). Receives a
|
|
6573
|
+
* {@link FailedPayment} carrying the SAME machine `code` the buyer's client is given, so the
|
|
6574
|
+
* merchant and the buyer are notified of the same failure with the same reason.
|
|
6575
|
+
*
|
|
6576
|
+
* Fires ONLY on a rejected attempt — NOT on a normal first-request 402 `challenge` (no proof
|
|
6577
|
+
* yet), and NOT on a transient/settlement error that throws (an RPC blip, or a 5xx
|
|
6578
|
+
* `SettlementError`): those aren't payment verdicts. Like `onPaid`, it may be **sync or async**
|
|
6579
|
+
* and is fully isolated — a throw OR a rejected promise is caught and routed to `onFailedError`,
|
|
6580
|
+
* so it can never break the request or crash the process. Fire-and-forget by default; set
|
|
6581
|
+
* `awaitOnFailed` to run it before the 402 is returned.
|
|
6582
|
+
*
|
|
6583
|
+
* NOTE: a failure the merchant never receives a request for — the buyer can't afford it, an
|
|
6584
|
+
* `onBeforePay`/`policy` declines it, or the buyer abandons before paying — cannot reach a
|
|
6585
|
+
* backendless gate (only the buyer's client sees it). `onFailed` covers every rejection that
|
|
6586
|
+
* DOES reach the gate.
|
|
6587
|
+
*/
|
|
6588
|
+
onFailed?: (failure: FailedPayment) => void | Promise<void>;
|
|
6589
|
+
/**
|
|
6590
|
+
* Observe a failure inside `onFailed` (sync throw or async rejection) — the mirror of
|
|
6591
|
+
* `onPaidError`. Without it, a throwing `onFailed` is swallowed silently. Its own throws are
|
|
6592
|
+
* also swallowed (it can never break a request).
|
|
6593
|
+
*/
|
|
6594
|
+
onFailedError?: (error: unknown, failure: FailedPayment) => void;
|
|
6595
|
+
/**
|
|
6596
|
+
* Await `onFailed` before the 402 rejection is returned (mirror of `awaitOnPaid`), so
|
|
6597
|
+
* "failure recorded" is guaranteed before the caller is told. Default `false` (fire-and-forget).
|
|
6598
|
+
* A rejection inside the hook is still isolated via `onFailedError`.
|
|
6599
|
+
*/
|
|
6600
|
+
awaitOnFailed?: boolean;
|
|
6538
6601
|
/**
|
|
6539
6602
|
* ALSO advertise a standard x402 `exact` rail so any standard x402 client can pay this
|
|
6540
6603
|
* gate — opt-in, EVM (EIP-3009/Permit2) + Solana (SVM). See {@link ExactRailOption}.
|
|
@@ -6639,15 +6702,6 @@ interface PaymentGate {
|
|
|
6639
6702
|
*/
|
|
6640
6703
|
landingPage(challenge: X402Challenge): string;
|
|
6641
6704
|
}
|
|
6642
|
-
/**
|
|
6643
|
-
* Framework-agnostic core. Build one gate per gated resource and reuse it
|
|
6644
|
-
* — its in-memory used-tx set is what stops the same proof being redeemed
|
|
6645
|
-
* twice. Wrap it for Express with `requirePayment`, or call it directly
|
|
6646
|
-
* from Hono / Fastify / Adonis / Workers / etc.
|
|
6647
|
-
*
|
|
6648
|
-
* The chain's driver is resolved lazily on first `challenge()`/`verify()`,
|
|
6649
|
-
* which is what lets Solana (and future families) auto-mount with no setup.
|
|
6650
|
-
*/
|
|
6651
6705
|
declare function createPaymentGate(options: RequirePaymentOptions): PaymentGate;
|
|
6652
6706
|
interface ExpressLikeRequest {
|
|
6653
6707
|
headers: Record<string, string | string[] | undefined>;
|
|
@@ -7527,4 +7581,4 @@ declare const PERMIT2_WITNESS_TYPES: {
|
|
|
7527
7581
|
*/
|
|
7528
7582
|
declare function renderLandingPage(sd: SelfDescription): string;
|
|
7529
7583
|
|
|
7530
|
-
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, BRAND, type BazaarExtension, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ChallengeTriage, type ChallengeVerdict, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, DIRECTORY_INFO, type DeclineReasonCode, type DeliverAttempt, type DeliverReceiptOptions, type DeliverResult, type DirectoryInfo, type DiscoverOptions, type DiscoveredRail, type DiscoveredResource, type DiscoveryDescriptor, type DiscoverySigner, type DiscoverySort, type DiscoverySource, type DomainClaim, type DomainVerification, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExactAuthorizationWire, type ExactPaymentPayload, type ExactPaymentPayloadAny, type ExactRailOption, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, type FacilitatorConfig, type FacilitatorPaymentRequirements, type FacilitatorSupportedKind, GENERATOR, HEADER_REQUIRED, HEADER_RESPONSE, HEADER_RESPONSE_V1, HEADER_SIGNATURE, HEADER_SIGNATURE_V1, InsufficientFundsError, InvalidEnvelopeError, KNOWN_FACILITATORS, type KnownFacilitator, type ListingVisibility, type ManifestInput, MaxRetriesExceededError, MissingDriverError, MultiChainPayer, type MultiChainPayerOptions, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type OpenApiDocument, type OpenApiOperation, PERMIT2_ADDRESS, PERMIT2_PROXY_CHAIN_IDS, PERMIT2_WITNESS_TYPES, PIPRAIL_AGENT_GUIDE, POWERED_BY, type PaidReceipt, type ParsedExactPayment, type PayBlocker, type PayOption, type PayWarning, type PayingClient, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, type PaymentRail, type PaymentScheme, PaymentTimeoutError, type Permit2Authorization, type Permit2PaymentPayload, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, type PolicyDenyCode, REGISTER_ATTRIBUTION, RecipientNotReadyError, type RecipientReason, type RegisterInput, type RegisterOptions, type RegisterOutcome, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type ResourceDescription, type SearchOpenIndexesOptions, type SelfDescribeEndpoint, type SelfDescribeRail, type SelfDescription, type SessionBudget, type SettleOutcome, type SettleViaFacilitatorInput, SettlementError, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendRemaining, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type ToolAnnotations, type TronToken, UnknownTokenError, UnsupportedNetworkError, UnsupportedSchemeError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WalletRequiredError, type WellKnownX402, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402AnyAccept, type X402Challenge, type X402DnsRecord, type X402ExactAcceptEntry, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, X402_EXACT_PERMIT2_PROXY, type XrplToken, agentGuide, appendAttribution, appendKeywords, buildBazaarExtension, buildChallengeHeader, buildEndpointInfo, buildExactAuthorization, buildExactSignatureHeader, buildOpenApi, buildReceiptHeader, buildSelfDescription, buildSignatureHeader, buildWellKnownX402, buildX402DnsTxt, chainIdForExactNetwork, claim402IndexDomain, classifyChallenge, createPaymentGate, decorateOutcome, deliverReceipt, describeChallenge, discoveryHeaders, eip3009Abi, encodeXPaymentHeader, evaluatePolicy, explainDecline, facilitatorCoverage, fetchAcross, firstKeylessFacilitator, formatSpendReport, getDirectoryInfo, isPermit2ProxyChain, knownFacilitatorsFor, normalizeNetwork, parseChallenge, parseExactPaymentHeader, parseExactRequirements, parseFacilitatorSupported, parseReceipt, parseSettleResponse, parseSignatureHeader, paymentTools, pickAccept, planAcross, rankResources, readExactDomain, register402Index, registerDriver, registerX402Scan, renderLandingPage, requirePayment, resolveChain, scoreResource, searchOpenIndexes, settleViaFacilitator, summarizePlan, toInsufficientFundsError, toInvalidBody, verify402IndexDomain };
|
|
7584
|
+
export { type AcceptOption, type AddressId, type AgentTool, type AlgorandToken, type AptosToken, type AssetId, BRAND, type BazaarExtension, type BuildExactParams, CHAINS, type Caip2, type ChainFamily, type ChainInput, type ChainName, type ChainPreset, type ChainSelector, type ChallengeTriage, type ChallengeVerdict, type ConfirmInfo, ConfirmationTimeoutError, type CostEstimate, DIRECTORY_INFO, type DeclineReasonCode, type DeliverAttempt, type DeliverReceiptOptions, type DeliverResult, type DirectoryInfo, type DiscoverOptions, type DiscoveredRail, type DiscoveredResource, type DiscoveryDescriptor, type DiscoverySigner, type DiscoverySort, type DiscoverySource, type DomainClaim, type DomainVerification, EIP3009_TYPES, EXACT_NETWORK_SLUGS, type EvmToken, type ExactAccept, type ExactAuthorization, type ExactAuthorizationWire, type ExactPaymentPayload, type ExactPaymentPayloadAny, type ExactRailOption, type ExpressLikeMiddleware, type ExpressLikeNext, type ExpressLikeRequest, type ExpressLikeResponse, type FacilitatorConfig, type FacilitatorPaymentRequirements, type FacilitatorSupportedKind, type FailedPayment, GENERATOR, HEADER_REQUIRED, HEADER_RESPONSE, HEADER_RESPONSE_V1, HEADER_SIGNATURE, HEADER_SIGNATURE_V1, InsufficientFundsError, InvalidEnvelopeError, KNOWN_FACILITATORS, type KnownFacilitator, type ListingVisibility, type ManifestInput, MaxRetriesExceededError, MissingDriverError, MultiChainPayer, type MultiChainPayerOptions, type NearToken, NoCompatibleAcceptError, NonReplayableBodyError, type OpenApiDocument, type OpenApiOperation, PERMIT2_ADDRESS, PERMIT2_PROXY_CHAIN_IDS, PERMIT2_WITNESS_TYPES, PIPRAIL_AGENT_GUIDE, POWERED_BY, type PaidReceipt, type ParsedExactPayment, type PayBlocker, type PayOption, type PayWarning, type PayingClient, PaymentDeclinedError, type PaymentDriver, type PaymentGate, type PaymentIntent, type PaymentPlan, type PaymentPolicy, type PaymentRail, type PaymentScheme, PaymentTimeoutError, type Permit2Authorization, type Permit2PaymentPayload, PipRailClient, type PipRailClientOptions, type PipRailCostQuote, PipRailError, type PipRailEvent, type PipRailQuote, type PolicyDecision, type PolicyDenyCode, REGISTER_ATTRIBUTION, RecipientNotReadyError, type RecipientReason, type RegisterInput, type RegisterOptions, type RegisterOutcome, type RequirePaymentOptions, type ResolveOptions, type ResolvedChain, type ResolvedNetwork, type ResolvedToken, type ResourceDescription, type SearchOpenIndexesOptions, type SelfDescribeEndpoint, type SelfDescribeRail, type SelfDescription, type SessionBudget, type SettleOutcome, type SettleViaFacilitatorInput, SettlementError, type SolanaToken, type SpendAssetTotal, type SpendRecord, type SpendRemaining, type SpendSummary, type StellarToken, type SuiToken, type TokenInfo, type TokenInput, type TonToken, type ToolAnnotations, type TronToken, UnknownTokenError, UnsupportedNetworkError, UnsupportedSchemeError, type VerifyErrorCode, type VerifyPaymentResult, type VerifyResult, type WalletBalance, type WalletHandle, type WalletInput, WalletRequiredError, type WellKnownX402, WrongChainError, WrongFamilyError, type X402AcceptEntry, type X402AnyAccept, type X402Challenge, type X402DnsRecord, type X402ExactAcceptEntry, type X402InvalidBody, type X402PaymentSignature, type X402Receipt, type X402ResourceObject, X402_EXACT_PERMIT2_PROXY, type XrplToken, agentGuide, appendAttribution, appendKeywords, buildBazaarExtension, buildChallengeHeader, buildEndpointInfo, buildExactAuthorization, buildExactSignatureHeader, buildOpenApi, buildReceiptHeader, buildSelfDescription, buildSignatureHeader, buildWellKnownX402, buildX402DnsTxt, chainIdForExactNetwork, claim402IndexDomain, classifyChallenge, createPaymentGate, decorateOutcome, deliverReceipt, describeChallenge, discoveryHeaders, eip3009Abi, encodeXPaymentHeader, evaluatePolicy, explainDecline, facilitatorCoverage, fetchAcross, firstKeylessFacilitator, formatSpendReport, getDirectoryInfo, isPermit2ProxyChain, knownFacilitatorsFor, normalizeNetwork, parseChallenge, parseExactPaymentHeader, parseExactRequirements, parseFacilitatorSupported, parseReceipt, parseSettleResponse, parseSignatureHeader, paymentTools, pickAccept, planAcross, rankResources, readExactDomain, register402Index, registerDriver, registerX402Scan, renderLandingPage, requirePayment, resolveChain, scoreResource, searchOpenIndexes, settleViaFacilitator, summarizePlan, toInsufficientFundsError, toInvalidBody, verify402IndexDomain };
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
parseUnits,
|
|
25
25
|
rejectForeignToken,
|
|
26
26
|
toInsufficientFundsError
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-W3HOMXOF.js";
|
|
28
28
|
|
|
29
29
|
// src/drivers/registry.ts
|
|
30
30
|
var byFamily = /* @__PURE__ */ new Map();
|
|
@@ -1840,7 +1840,7 @@ var loaders = {
|
|
|
1840
1840
|
solana: async () => {
|
|
1841
1841
|
let mod;
|
|
1842
1842
|
try {
|
|
1843
|
-
mod = await import("./solana-
|
|
1843
|
+
mod = await import("./solana-Z34OWXMO.js");
|
|
1844
1844
|
} catch (cause) {
|
|
1845
1845
|
throw new MissingDriverError(
|
|
1846
1846
|
`Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
|
|
@@ -1852,7 +1852,7 @@ var loaders = {
|
|
|
1852
1852
|
ton: async () => {
|
|
1853
1853
|
let mod;
|
|
1854
1854
|
try {
|
|
1855
|
-
mod = await import("./ton-
|
|
1855
|
+
mod = await import("./ton-N7KSPSAR.js");
|
|
1856
1856
|
} catch (cause) {
|
|
1857
1857
|
throw new MissingDriverError(
|
|
1858
1858
|
`TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
|
|
@@ -1864,7 +1864,7 @@ var loaders = {
|
|
|
1864
1864
|
stellar: async () => {
|
|
1865
1865
|
let mod;
|
|
1866
1866
|
try {
|
|
1867
|
-
mod = await import("./stellar-
|
|
1867
|
+
mod = await import("./stellar-PWC4LETJ.js");
|
|
1868
1868
|
} catch (cause) {
|
|
1869
1869
|
throw new MissingDriverError(
|
|
1870
1870
|
`Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
|
|
@@ -1876,7 +1876,7 @@ var loaders = {
|
|
|
1876
1876
|
xrpl: async () => {
|
|
1877
1877
|
let mod;
|
|
1878
1878
|
try {
|
|
1879
|
-
mod = await import("./xrpl-
|
|
1879
|
+
mod = await import("./xrpl-6B4IYRWI.js");
|
|
1880
1880
|
} catch (cause) {
|
|
1881
1881
|
throw new MissingDriverError(
|
|
1882
1882
|
`XRPL selected, but its package isn't installed. Run: npm install xrpl`,
|
|
@@ -1888,7 +1888,7 @@ var loaders = {
|
|
|
1888
1888
|
tron: async () => {
|
|
1889
1889
|
let mod;
|
|
1890
1890
|
try {
|
|
1891
|
-
mod = await import("./tron-
|
|
1891
|
+
mod = await import("./tron-WKDUQVZR.js");
|
|
1892
1892
|
} catch (cause) {
|
|
1893
1893
|
throw new MissingDriverError(
|
|
1894
1894
|
`Tron selected, but its package isn't installed. Run: npm install tronweb`,
|
|
@@ -1900,7 +1900,7 @@ var loaders = {
|
|
|
1900
1900
|
sui: async () => {
|
|
1901
1901
|
let mod;
|
|
1902
1902
|
try {
|
|
1903
|
-
mod = await import("./sui-
|
|
1903
|
+
mod = await import("./sui-VEOGHBYE.js");
|
|
1904
1904
|
} catch (cause) {
|
|
1905
1905
|
throw new MissingDriverError(
|
|
1906
1906
|
`Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
|
|
@@ -1912,7 +1912,7 @@ var loaders = {
|
|
|
1912
1912
|
near: async () => {
|
|
1913
1913
|
let mod;
|
|
1914
1914
|
try {
|
|
1915
|
-
mod = await import("./near-
|
|
1915
|
+
mod = await import("./near-QV4IOZNX.js");
|
|
1916
1916
|
} catch (cause) {
|
|
1917
1917
|
throw new MissingDriverError(
|
|
1918
1918
|
`NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
|
|
@@ -1924,7 +1924,7 @@ var loaders = {
|
|
|
1924
1924
|
aptos: async () => {
|
|
1925
1925
|
let mod;
|
|
1926
1926
|
try {
|
|
1927
|
-
mod = await import("./aptos-
|
|
1927
|
+
mod = await import("./aptos-WMPFEASY.js");
|
|
1928
1928
|
} catch (cause) {
|
|
1929
1929
|
throw new MissingDriverError(
|
|
1930
1930
|
`Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
|
|
@@ -1936,7 +1936,7 @@ var loaders = {
|
|
|
1936
1936
|
algorand: async () => {
|
|
1937
1937
|
let mod;
|
|
1938
1938
|
try {
|
|
1939
|
-
mod = await import("./algorand-
|
|
1939
|
+
mod = await import("./algorand-WJL6VRXW.js");
|
|
1940
1940
|
} catch (cause) {
|
|
1941
1941
|
throw new MissingDriverError(
|
|
1942
1942
|
`Algorand selected, but its package isn't installed. Run: npm install algosdk`,
|
|
@@ -2027,7 +2027,7 @@ var SLUG_TO_CAIP2 = {
|
|
|
2027
2027
|
bsc: "eip155:56",
|
|
2028
2028
|
// non-EVM families — values mirror each driver's bound caip2 exactly
|
|
2029
2029
|
solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
2030
|
-
ton: "
|
|
2030
|
+
ton: "tvm:-239",
|
|
2031
2031
|
tron: "tron:mainnet",
|
|
2032
2032
|
near: "near:mainnet",
|
|
2033
2033
|
sui: "sui:mainnet",
|
|
@@ -2036,7 +2036,12 @@ var SLUG_TO_CAIP2 = {
|
|
|
2036
2036
|
stellar: "stellar:pubnet",
|
|
2037
2037
|
xrpl: "xrpl:0"
|
|
2038
2038
|
};
|
|
2039
|
+
var LEGACY_CAIP2_ALIAS = {
|
|
2040
|
+
"ton:-239": "tvm:-239"
|
|
2041
|
+
};
|
|
2039
2042
|
function normalizeNetwork(network) {
|
|
2043
|
+
const legacy = LEGACY_CAIP2_ALIAS[network];
|
|
2044
|
+
if (legacy) return legacy;
|
|
2040
2045
|
if (network.includes(":")) return network;
|
|
2041
2046
|
return SLUG_TO_CAIP2[network.toLowerCase()] ?? network;
|
|
2042
2047
|
}
|
|
@@ -3212,7 +3217,9 @@ var PipRailClient = class {
|
|
|
3212
3217
|
if (autoRoute) {
|
|
3213
3218
|
const plan = await this.planFromChallenge(net, wallet, challenge, url, schemes);
|
|
3214
3219
|
if (!plan.best) {
|
|
3215
|
-
|
|
3220
|
+
const reason = plan.fundingHint ?? "No rail is settleable for this payment.";
|
|
3221
|
+
this.safeEmit({ kind: "payment-failed", reason });
|
|
3222
|
+
throw new PaymentDeclinedError(reason);
|
|
3216
3223
|
}
|
|
3217
3224
|
accept = plan.best.accept;
|
|
3218
3225
|
quote = plan.best.quote;
|
|
@@ -3502,10 +3509,10 @@ var PipRailClient = class {
|
|
|
3502
3509
|
* TERMINAL expiry/approval decline it must not retry) without parsing prose. */
|
|
3503
3510
|
async authorize(quote) {
|
|
3504
3511
|
if (!quote.withinPolicy) {
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
);
|
|
3512
|
+
const reason = `Payment refused by policy: ${quote.policyReason ?? "not allowed"}`;
|
|
3513
|
+
const reasonCode = reasonCodeForPolicy(quote.policyCode);
|
|
3514
|
+
this.safeEmit({ kind: "payment-failed", reason, code: reasonCode });
|
|
3515
|
+
throw new PaymentDeclinedError(reason, { reasonCode });
|
|
3509
3516
|
}
|
|
3510
3517
|
const hook = this.opts.onBeforePay;
|
|
3511
3518
|
if (!hook) return;
|
|
@@ -3513,16 +3520,14 @@ var PipRailClient = class {
|
|
|
3513
3520
|
try {
|
|
3514
3521
|
approved = await hook(quote);
|
|
3515
3522
|
} catch (err) {
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
});
|
|
3523
|
+
const reason = "onBeforePay threw \u2014 refusing to pay.";
|
|
3524
|
+
this.safeEmit({ kind: "payment-failed", reason, code: "APPROVAL" });
|
|
3525
|
+
throw new PaymentDeclinedError(reason, { cause: err, reasonCode: "APPROVAL" });
|
|
3520
3526
|
}
|
|
3521
3527
|
if (!approved) {
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
);
|
|
3528
|
+
const reason = `onBeforePay declined ${quote.amountFormatted} ${quote.symbol ?? ""}`.trimEnd() + ` on ${quote.network}.`;
|
|
3529
|
+
this.safeEmit({ kind: "payment-failed", reason, code: "APPROVAL" });
|
|
3530
|
+
throw new PaymentDeclinedError(reason, { reasonCode: "APPROVAL" });
|
|
3526
3531
|
}
|
|
3527
3532
|
}
|
|
3528
3533
|
/** Record a settled payment in the ledger (true decimals for the running total). */
|
|
@@ -3617,7 +3622,8 @@ var PipRailClient = class {
|
|
|
3617
3622
|
const unconfirmedNote = confirmed ? "" : " (broadcast but NOT locally confirmed \u2014 it may still have settled on-chain)";
|
|
3618
3623
|
this.safeEmit({
|
|
3619
3624
|
kind: "payment-failed",
|
|
3620
|
-
reason: `server returned 402 after broadcasting payment ${ref}${unconfirmedNote} (${why})
|
|
3625
|
+
reason: `server returned 402 after broadcasting payment ${ref}${unconfirmedNote} (${why})`,
|
|
3626
|
+
...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
|
|
3621
3627
|
});
|
|
3622
3628
|
throw new MaxRetriesExceededError(
|
|
3623
3629
|
`Server still returned 402 after ${attempts} attempt(s) with on-chain proof ref=${ref}${unconfirmedNote}. Last server rejection: ${why}. Re-verify or re-submit ref=${ref} before retrying \u2014 never re-pay (it would double-spend).`,
|
|
@@ -3652,7 +3658,7 @@ var PipRailClient = class {
|
|
|
3652
3658
|
const headers = new Headers(init?.headers);
|
|
3653
3659
|
headers.set(HEADER_SIGNATURE, buildExactSignatureHeader({ accepted, payload }));
|
|
3654
3660
|
const rejectDefinitive = (why2) => {
|
|
3655
|
-
this.safeEmit({ kind: "payment-failed", reason: `exact: facilitator rejected nonce=${nonce} (${why2})
|
|
3661
|
+
this.safeEmit({ kind: "payment-failed", reason: `exact: facilitator rejected nonce=${nonce} (${why2})`, code: why2 });
|
|
3656
3662
|
throw new MaxRetriesExceededError(
|
|
3657
3663
|
`exact: the facilitator rejected the payment (${why2}). Fix the cause, then re-present the SAME signed authorization (nonce=${nonce}) \u2014 do NOT re-sign a fresh nonce. ref=${nonce}.`,
|
|
3658
3664
|
{ ref: nonce }
|
|
@@ -3707,7 +3713,8 @@ var PipRailClient = class {
|
|
|
3707
3713
|
const why = lastReason ? `${lastReason.error}${lastReason.detail ? ` \u2014 ${lastReason.detail}` : ""}` : "server gave no reason";
|
|
3708
3714
|
this.safeEmit({
|
|
3709
3715
|
kind: "payment-failed",
|
|
3710
|
-
reason: `exact: 402 after submitting authorization nonce=${nonce} (${why})
|
|
3716
|
+
reason: `exact: 402 after submitting authorization nonce=${nonce} (${why})`,
|
|
3717
|
+
...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
|
|
3711
3718
|
});
|
|
3712
3719
|
throw new MaxRetriesExceededError(
|
|
3713
3720
|
`exact: server still returned 402 after submitting the signed authorization (nonce=${nonce}). Last rejection: ${why}. Re-present the SAME authorization \u2014 do NOT re-sign a fresh nonce; verify authorizationState(${payerFrom}, ${nonce}) first. ref=${nonce}.`,
|
|
@@ -5260,6 +5267,7 @@ function normaliseExactOption(exact) {
|
|
|
5260
5267
|
if (exact === true) return { settle: "keyless" };
|
|
5261
5268
|
return exact;
|
|
5262
5269
|
}
|
|
5270
|
+
var TRANSIENT_VERIFY_CODES = /* @__PURE__ */ new Set(["tx_not_found", "insufficient_confirmations"]);
|
|
5263
5271
|
function createPaymentGate(options) {
|
|
5264
5272
|
const minConfirmations = options.minConfirmations ?? 1;
|
|
5265
5273
|
const maxTimeoutSeconds = options.maxTimeoutSeconds ?? 600;
|
|
@@ -5544,6 +5552,32 @@ function createPaymentGate(options) {
|
|
|
5544
5552
|
if (options.awaitOnPaid) await fireOnPaid(paid);
|
|
5545
5553
|
else void fireOnPaid(paid);
|
|
5546
5554
|
}
|
|
5555
|
+
function reportOnFailedError(error, failure) {
|
|
5556
|
+
if (!options.onFailedError) return;
|
|
5557
|
+
try {
|
|
5558
|
+
options.onFailedError(error, failure);
|
|
5559
|
+
} catch {
|
|
5560
|
+
}
|
|
5561
|
+
}
|
|
5562
|
+
function fireOnFailed(failure) {
|
|
5563
|
+
if (!options.onFailed) return;
|
|
5564
|
+
let outcome;
|
|
5565
|
+
try {
|
|
5566
|
+
outcome = options.onFailed(failure);
|
|
5567
|
+
} catch (err) {
|
|
5568
|
+
reportOnFailedError(err, failure);
|
|
5569
|
+
return;
|
|
5570
|
+
}
|
|
5571
|
+
if (outcome != null && typeof outcome.then === "function") {
|
|
5572
|
+
return Promise.resolve(outcome).catch((err) => reportOnFailedError(err, failure));
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
async function deliverOnFailed(result) {
|
|
5576
|
+
const code = result.error;
|
|
5577
|
+
const failure = { code, detail: result.detail, transient: TRANSIENT_VERIFY_CODES.has(code) };
|
|
5578
|
+
if (options.awaitOnFailed) await fireOnFailed(failure);
|
|
5579
|
+
else void fireOnFailed(failure);
|
|
5580
|
+
}
|
|
5547
5581
|
async function describe(resourceUrl = "") {
|
|
5548
5582
|
const specs = await ready();
|
|
5549
5583
|
const accepts = [];
|
|
@@ -5707,6 +5741,11 @@ function createPaymentGate(options) {
|
|
|
5707
5741
|
return { kind: "paid", receipt: result.receipt, receiptHeader: buildReceiptHeader(result.receipt) };
|
|
5708
5742
|
}
|
|
5709
5743
|
async function verify(paymentSignature) {
|
|
5744
|
+
const result = await resolveVerdict(paymentSignature);
|
|
5745
|
+
if (result.kind === "invalid") await deliverOnFailed(result);
|
|
5746
|
+
return result;
|
|
5747
|
+
}
|
|
5748
|
+
async function resolveVerdict(paymentSignature) {
|
|
5710
5749
|
const raw = normaliseHeader(paymentSignature);
|
|
5711
5750
|
if (!raw) return asChallenge();
|
|
5712
5751
|
const sig = parseSignatureHeader(raw);
|