@piprail/sdk 2.12.0 → 2.13.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/dist/index.d.cts CHANGED
@@ -4622,10 +4622,12 @@ declare class MaxRetriesExceededError extends PipRailError {
4622
4622
  /**
4623
4623
  * The proof ref — recover with it, don't re-pay. Its meaning depends on the
4624
4624
  * scheme: for `onchain-proof` it's the already-broadcast transaction ref
4625
- * (re-verify or re-submit it). For a standard `exact` rail it's the EIP-3009
4626
- * authorization NONCE (a `0x…` 32-byte value, NOT a tx hash) — re-PRESENT the
4627
- * same signed authorization, never re-sign a fresh nonce; check the token's
4628
- * `authorizationState(from, nonce)` before assuming it didn't settle.
4625
+ * (re-verify or re-submit it). For a standard `exact` rail it's the authorization's
4626
+ * single-use marker (NOT a tx hash) — re-PRESENT the same signed authorization, never
4627
+ * re-sign a fresh nonce, and verify it on-chain before assuming it didn't settle. On
4628
+ * EVM that marker is the EIP-3009 NONCE (a `0x…` value), checked via the token's
4629
+ * `authorizationState(from, nonce)`; the non-EVM `exact` rails key off their own marker
4630
+ * (Solana tx signature, Algorand group id, Aptos account sequence number, NEAR access-key nonce).
4629
4631
  */
4630
4632
  readonly ref?: string;
4631
4633
  constructor(message: string, options?: ErrorOptions & {
@@ -7306,7 +7308,11 @@ interface DeliverReceiptOptions {
7306
7308
  url: string;
7307
7309
  /**
7308
7310
  * Shared secret. When set, the raw JSON body is signed HMAC-SHA256 and sent as
7309
- * `<signatureHeader>: sha256=<hex>` so the receiver can verify authenticity.
7311
+ * `<signatureHeader>: sha256=<hex>` so the receiver can verify authenticity. Signing uses Web
7312
+ * Crypto (`crypto.subtle`) — always present on the supported runtimes (Node ≥ 20, modern
7313
+ * browsers). On a runtime that lacks it the body is sent **unsigned, with no signature header**,
7314
+ * so a receiver must treat a *missing* signature as unauthenticated (reject it), never silently
7315
+ * accept an unsigned body.
7310
7316
  */
7311
7317
  secret?: string;
7312
7318
  /** Extra retry attempts after the first send (default 5 → up to 6 POSTs total). */
@@ -7834,11 +7840,11 @@ declare const PERMIT2_UPTO_WITNESS_TYPES: {
7834
7840
  declare function renderLandingPage(sd: SelfDescription): string;
7835
7841
 
7836
7842
  /**
7837
- * Minimal, DUCK-TYPED Google Agent2Agent (A2A) shapes — the structural surface the
7838
- * PipRail A2A transport reads/writes, and NOTHING more. Like `ExpressLikeRequest` in
7839
- * `server.ts`, these declare only the fields the adapter touches, so any A2A runtime's
7840
- * objects (the official `@a2a-js/sdk`, ADK, or a hand-rolled JSON-RPC handler) satisfy
7841
- * them structurally — **with ZERO `@a2a` dependency**.
7843
+ * Minimal, DUCK-TYPED Agent2Agent (A2A) shapes — the structural surface the PipRail A2A
7844
+ * transport reads/writes, and NOTHING more. Like `ExpressLikeRequest` in `server.ts`, these
7845
+ * declare only the fields the adapter touches, so any A2A runtime's objects (the official
7846
+ * `@a2a-js/sdk` — `a2aproject` org, the Linux Foundation A2A project — ADK, or a hand-rolled
7847
+ * JSON-RPC handler) satisfy them structurally — **with ZERO `@a2a` dependency**.
7842
7848
  *
7843
7849
  * x402-over-A2A carries PipRail's existing `PaymentRequired`/`PaymentPayload`/
7844
7850
  * `SettlementResponse` envelopes inside A2A `Task`/`Message` `metadata`, keyed off five
@@ -7948,9 +7954,11 @@ interface A2ATaskRecord {
7948
7954
  }
7949
7955
 
7950
7956
  /**
7951
- * x402-over-A2A — the SELLER-side transport adapter (Google Agent2Agent).
7957
+ * x402-over-A2A — the SELLER-side transport adapter for the Agent2Agent (A2A) protocol.
7952
7958
  *
7953
- * A2A is x402's third official transport (alongside HTTP and MCP). It carries PipRail's
7959
+ * A2A is an open protocol (created by Google, now a Linux Foundation project — a2a-protocol.org;
7960
+ * official JS runtime `@a2a-js/sdk` from the `a2aproject` org). It is x402's third official transport
7961
+ * (alongside HTTP and MCP). It carries PipRail's
7954
7962
  * BYTE-IDENTICAL `PaymentRequired`/`PaymentPayload`/`SettlementResponse` envelopes inside
7955
7963
  * A2A `Task`/`Message` JSON-RPC `metadata` (five namespaced `x402.payment.*` keys) keyed
7956
7964
  * off a coarse A2A Task state — instead of base64 HTTP headers. It is a thin codec + adapter
@@ -7979,9 +7987,15 @@ interface A2ATaskRecord {
7979
7987
  * PaymentPayload byte-identically, while the legacy v0.1 `x402_a2a` package (x402Version 1,
7980
7988
  * `maxAmountRequired`, chain slugs) is bitrotted. Inbound v1 object-cores are absorbed for the
7981
7989
  * standard `exact` scheme; PipRail-native `onchain-proof` is always v2 (never sent v1-flat).
7982
- * • Merchant statuses are spec-bounded: `payment-required` (incl. a retryable re-challenge of a
7983
- * rejected proof) / `payment-completed` / `payment-failed`. `payment-rejected` + `payment-submitted`
7984
- * are CLIENT→merchant statuses we never emit.
7990
+ * • Merchant statuses are spec-bounded: `payment-required` (a genuine first/no-proof challenge) /
7991
+ * `payment-completed` / `payment-failed`. A SUBMITTED proof that fails verification (expired /
7992
+ * wrong-amount / replayed) emits `payment-failed` — the a2a.md §9 rule ("If a payment fails, the
7993
+ * server MUST set x402.payment.status to payment-failed") and its EXPIRED-signature example, which
7994
+ * Google's reference executor matches verbatim (`is_valid == false → record_payment_failure →
7995
+ * PAYMENT_FAILED`). Retryability rides on the A2A Task `state` (`input-required`), NOT the status —
7996
+ * so a rejection is `payment-failed` + `input-required` (retry) while a terminal settlement error is
7997
+ * `payment-failed` + `failed`. `payment-rejected` + `payment-submitted` are CLIENT→merchant statuses
7998
+ * we never emit.
7985
7999
  *
7986
8000
  * ── DEFERRED (NOT built here — see the x402-parity/03-a2a-transport plan) ──────
7987
8001
  * • Phase 4 — the A2A BUYER (`A2APayer`): the HTTP buyer mints the payload that rides A2A today.
@@ -8017,6 +8031,12 @@ declare function toA2AErrorCode(code: string): string;
8017
8031
  * Build the `input-required` payment-request Task carrying the challenge as RAW JSON
8018
8032
  * (NOT base64) in `x402.payment.required` + `x402.payment.status = 'payment-required'`.
8019
8033
  * `parts` are any human-readable message parts the merchant wants alongside it.
8034
+ *
8035
+ * Returns a **transport-metadata** Task: it carries the x402 `payment` state, NOT the host-owned
8036
+ * ids the `@a2a-js/sdk` runtime requires (`Task.contextId`, `status.message.messageId`/`parts`,
8037
+ * `artifacts[].artifactId` are all REQUIRED in the SDK's types). The host adapter stamps those
8038
+ * before publishing — see the `@a2a-js/sdk` mount in the docs / `examples/a2a-server/lib.mjs`.
8039
+ * This keeps the protocol layer chain- and runtime-agnostic (zero `@a2a` dependency).
8020
8040
  */
8021
8041
  declare function toA2APaymentRequired(taskId: string, challenge: X402Challenge, parts?: A2APart[]): A2ATask;
8022
8042
  /** Build the `x402.payment.receipts` metadata block (an ARRAY, append-only, B7 union). */
@@ -8078,9 +8098,15 @@ interface A2APaymentHandler {
8078
8098
  * `gate.verify()`'s `VerifyPaymentResult` exactly:
8079
8099
  * - no payload yet → Task `input-required` + `x402.payment.required`
8080
8100
  * - payload, verified+settled → Task `completed` + `x402.payment.receipts` + artifacts
8081
- * - payload, rejected → Task `input-required` re-challenge (RETRYABLE)
8101
+ * - payload, rejected → Task `input-required` re-challenge, status `payment-failed` (RETRYABLE)
8082
8102
  * - settle threw (relayer) → Task `failed` + `x402.payment.error` (NOT retryable)
8083
8103
  * - settle OK but fulfill threw → Task `completed` + receipt + error annotation (B7)
8104
+ *
8105
+ * The returned Task is **transport metadata only** — it carries the x402 `payment.*` state but NOT
8106
+ * the host-owned ids the `@a2a-js/sdk` runtime requires (`Task.contextId`, `status.message.messageId`
8107
+ * /`parts`, `artifacts[].artifactId`). The host adapter (the `AgentExecutor`) stamps those before
8108
+ * `bus.publish` — see the mount in the docs / `examples/a2a-server/lib.mjs`. This keeps the protocol
8109
+ * layer free of any `@a2a` dependency.
8084
8110
  */
8085
8111
  handleMessage(message: A2AMessage, taskId?: string): Promise<A2ATask>;
8086
8112
  /** Stamp the x402 extension into an AgentCard's `capabilities.extensions` (§2.4). */
package/dist/index.d.ts CHANGED
@@ -4622,10 +4622,12 @@ declare class MaxRetriesExceededError extends PipRailError {
4622
4622
  /**
4623
4623
  * The proof ref — recover with it, don't re-pay. Its meaning depends on the
4624
4624
  * scheme: for `onchain-proof` it's the already-broadcast transaction ref
4625
- * (re-verify or re-submit it). For a standard `exact` rail it's the EIP-3009
4626
- * authorization NONCE (a `0x…` 32-byte value, NOT a tx hash) — re-PRESENT the
4627
- * same signed authorization, never re-sign a fresh nonce; check the token's
4628
- * `authorizationState(from, nonce)` before assuming it didn't settle.
4625
+ * (re-verify or re-submit it). For a standard `exact` rail it's the authorization's
4626
+ * single-use marker (NOT a tx hash) — re-PRESENT the same signed authorization, never
4627
+ * re-sign a fresh nonce, and verify it on-chain before assuming it didn't settle. On
4628
+ * EVM that marker is the EIP-3009 NONCE (a `0x…` value), checked via the token's
4629
+ * `authorizationState(from, nonce)`; the non-EVM `exact` rails key off their own marker
4630
+ * (Solana tx signature, Algorand group id, Aptos account sequence number, NEAR access-key nonce).
4629
4631
  */
4630
4632
  readonly ref?: string;
4631
4633
  constructor(message: string, options?: ErrorOptions & {
@@ -7306,7 +7308,11 @@ interface DeliverReceiptOptions {
7306
7308
  url: string;
7307
7309
  /**
7308
7310
  * Shared secret. When set, the raw JSON body is signed HMAC-SHA256 and sent as
7309
- * `<signatureHeader>: sha256=<hex>` so the receiver can verify authenticity.
7311
+ * `<signatureHeader>: sha256=<hex>` so the receiver can verify authenticity. Signing uses Web
7312
+ * Crypto (`crypto.subtle`) — always present on the supported runtimes (Node ≥ 20, modern
7313
+ * browsers). On a runtime that lacks it the body is sent **unsigned, with no signature header**,
7314
+ * so a receiver must treat a *missing* signature as unauthenticated (reject it), never silently
7315
+ * accept an unsigned body.
7310
7316
  */
7311
7317
  secret?: string;
7312
7318
  /** Extra retry attempts after the first send (default 5 → up to 6 POSTs total). */
@@ -7834,11 +7840,11 @@ declare const PERMIT2_UPTO_WITNESS_TYPES: {
7834
7840
  declare function renderLandingPage(sd: SelfDescription): string;
7835
7841
 
7836
7842
  /**
7837
- * Minimal, DUCK-TYPED Google Agent2Agent (A2A) shapes — the structural surface the
7838
- * PipRail A2A transport reads/writes, and NOTHING more. Like `ExpressLikeRequest` in
7839
- * `server.ts`, these declare only the fields the adapter touches, so any A2A runtime's
7840
- * objects (the official `@a2a-js/sdk`, ADK, or a hand-rolled JSON-RPC handler) satisfy
7841
- * them structurally — **with ZERO `@a2a` dependency**.
7843
+ * Minimal, DUCK-TYPED Agent2Agent (A2A) shapes — the structural surface the PipRail A2A
7844
+ * transport reads/writes, and NOTHING more. Like `ExpressLikeRequest` in `server.ts`, these
7845
+ * declare only the fields the adapter touches, so any A2A runtime's objects (the official
7846
+ * `@a2a-js/sdk` — `a2aproject` org, the Linux Foundation A2A project — ADK, or a hand-rolled
7847
+ * JSON-RPC handler) satisfy them structurally — **with ZERO `@a2a` dependency**.
7842
7848
  *
7843
7849
  * x402-over-A2A carries PipRail's existing `PaymentRequired`/`PaymentPayload`/
7844
7850
  * `SettlementResponse` envelopes inside A2A `Task`/`Message` `metadata`, keyed off five
@@ -7948,9 +7954,11 @@ interface A2ATaskRecord {
7948
7954
  }
7949
7955
 
7950
7956
  /**
7951
- * x402-over-A2A — the SELLER-side transport adapter (Google Agent2Agent).
7957
+ * x402-over-A2A — the SELLER-side transport adapter for the Agent2Agent (A2A) protocol.
7952
7958
  *
7953
- * A2A is x402's third official transport (alongside HTTP and MCP). It carries PipRail's
7959
+ * A2A is an open protocol (created by Google, now a Linux Foundation project — a2a-protocol.org;
7960
+ * official JS runtime `@a2a-js/sdk` from the `a2aproject` org). It is x402's third official transport
7961
+ * (alongside HTTP and MCP). It carries PipRail's
7954
7962
  * BYTE-IDENTICAL `PaymentRequired`/`PaymentPayload`/`SettlementResponse` envelopes inside
7955
7963
  * A2A `Task`/`Message` JSON-RPC `metadata` (five namespaced `x402.payment.*` keys) keyed
7956
7964
  * off a coarse A2A Task state — instead of base64 HTTP headers. It is a thin codec + adapter
@@ -7979,9 +7987,15 @@ interface A2ATaskRecord {
7979
7987
  * PaymentPayload byte-identically, while the legacy v0.1 `x402_a2a` package (x402Version 1,
7980
7988
  * `maxAmountRequired`, chain slugs) is bitrotted. Inbound v1 object-cores are absorbed for the
7981
7989
  * standard `exact` scheme; PipRail-native `onchain-proof` is always v2 (never sent v1-flat).
7982
- * • Merchant statuses are spec-bounded: `payment-required` (incl. a retryable re-challenge of a
7983
- * rejected proof) / `payment-completed` / `payment-failed`. `payment-rejected` + `payment-submitted`
7984
- * are CLIENT→merchant statuses we never emit.
7990
+ * • Merchant statuses are spec-bounded: `payment-required` (a genuine first/no-proof challenge) /
7991
+ * `payment-completed` / `payment-failed`. A SUBMITTED proof that fails verification (expired /
7992
+ * wrong-amount / replayed) emits `payment-failed` — the a2a.md §9 rule ("If a payment fails, the
7993
+ * server MUST set x402.payment.status to payment-failed") and its EXPIRED-signature example, which
7994
+ * Google's reference executor matches verbatim (`is_valid == false → record_payment_failure →
7995
+ * PAYMENT_FAILED`). Retryability rides on the A2A Task `state` (`input-required`), NOT the status —
7996
+ * so a rejection is `payment-failed` + `input-required` (retry) while a terminal settlement error is
7997
+ * `payment-failed` + `failed`. `payment-rejected` + `payment-submitted` are CLIENT→merchant statuses
7998
+ * we never emit.
7985
7999
  *
7986
8000
  * ── DEFERRED (NOT built here — see the x402-parity/03-a2a-transport plan) ──────
7987
8001
  * • Phase 4 — the A2A BUYER (`A2APayer`): the HTTP buyer mints the payload that rides A2A today.
@@ -8017,6 +8031,12 @@ declare function toA2AErrorCode(code: string): string;
8017
8031
  * Build the `input-required` payment-request Task carrying the challenge as RAW JSON
8018
8032
  * (NOT base64) in `x402.payment.required` + `x402.payment.status = 'payment-required'`.
8019
8033
  * `parts` are any human-readable message parts the merchant wants alongside it.
8034
+ *
8035
+ * Returns a **transport-metadata** Task: it carries the x402 `payment` state, NOT the host-owned
8036
+ * ids the `@a2a-js/sdk` runtime requires (`Task.contextId`, `status.message.messageId`/`parts`,
8037
+ * `artifacts[].artifactId` are all REQUIRED in the SDK's types). The host adapter stamps those
8038
+ * before publishing — see the `@a2a-js/sdk` mount in the docs / `examples/a2a-server/lib.mjs`.
8039
+ * This keeps the protocol layer chain- and runtime-agnostic (zero `@a2a` dependency).
8020
8040
  */
8021
8041
  declare function toA2APaymentRequired(taskId: string, challenge: X402Challenge, parts?: A2APart[]): A2ATask;
8022
8042
  /** Build the `x402.payment.receipts` metadata block (an ARRAY, append-only, B7 union). */
@@ -8078,9 +8098,15 @@ interface A2APaymentHandler {
8078
8098
  * `gate.verify()`'s `VerifyPaymentResult` exactly:
8079
8099
  * - no payload yet → Task `input-required` + `x402.payment.required`
8080
8100
  * - payload, verified+settled → Task `completed` + `x402.payment.receipts` + artifacts
8081
- * - payload, rejected → Task `input-required` re-challenge (RETRYABLE)
8101
+ * - payload, rejected → Task `input-required` re-challenge, status `payment-failed` (RETRYABLE)
8082
8102
  * - settle threw (relayer) → Task `failed` + `x402.payment.error` (NOT retryable)
8083
8103
  * - settle OK but fulfill threw → Task `completed` + receipt + error annotation (B7)
8104
+ *
8105
+ * The returned Task is **transport metadata only** — it carries the x402 `payment.*` state but NOT
8106
+ * the host-owned ids the `@a2a-js/sdk` runtime requires (`Task.contextId`, `status.message.messageId`
8107
+ * /`parts`, `artifacts[].artifactId`). The host adapter (the `AgentExecutor`) stamps those before
8108
+ * `bus.publish` — see the mount in the docs / `examples/a2a-server/lib.mjs`. This keeps the protocol
8109
+ * layer free of any `@a2a` dependency.
8084
8110
  */
8085
8111
  handleMessage(message: A2AMessage, taskId?: string): Promise<A2ATask>;
8086
8112
  /** Stamp the x402 extension into an AgentCard's `capabilities.extensions` (§2.4). */
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  parseUnits,
32
32
  rejectForeignToken,
33
33
  toInsufficientFundsError
34
- } from "./chunk-SC2ZYDHD.js";
34
+ } from "./chunk-O32N6MFN.js";
35
35
 
36
36
  // src/drivers/registry.ts
37
37
  var byFamily = /* @__PURE__ */ new Map();
@@ -2329,7 +2329,7 @@ var loaders = {
2329
2329
  solana: async () => {
2330
2330
  let mod;
2331
2331
  try {
2332
- mod = await import("./solana-ELUWO6N5.js");
2332
+ mod = await import("./solana-VYLWFNAH.js");
2333
2333
  } catch (cause) {
2334
2334
  throw new MissingDriverError(
2335
2335
  `Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
@@ -2341,7 +2341,7 @@ var loaders = {
2341
2341
  ton: async () => {
2342
2342
  let mod;
2343
2343
  try {
2344
- mod = await import("./ton-7GKCTC5H.js");
2344
+ mod = await import("./ton-NNKQFQ6U.js");
2345
2345
  } catch (cause) {
2346
2346
  throw new MissingDriverError(
2347
2347
  `TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
@@ -2353,7 +2353,7 @@ var loaders = {
2353
2353
  stellar: async () => {
2354
2354
  let mod;
2355
2355
  try {
2356
- mod = await import("./stellar-ASP2THL2.js");
2356
+ mod = await import("./stellar-KBR4V77T.js");
2357
2357
  } catch (cause) {
2358
2358
  throw new MissingDriverError(
2359
2359
  `Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
@@ -2365,7 +2365,7 @@ var loaders = {
2365
2365
  xrpl: async () => {
2366
2366
  let mod;
2367
2367
  try {
2368
- mod = await import("./xrpl-DD7TJL5L.js");
2368
+ mod = await import("./xrpl-37E23W53.js");
2369
2369
  } catch (cause) {
2370
2370
  throw new MissingDriverError(
2371
2371
  `XRPL selected, but its package isn't installed. Run: npm install xrpl`,
@@ -2377,7 +2377,7 @@ var loaders = {
2377
2377
  tron: async () => {
2378
2378
  let mod;
2379
2379
  try {
2380
- mod = await import("./tron-BMCWN5SS.js");
2380
+ mod = await import("./tron-W2D5PQXV.js");
2381
2381
  } catch (cause) {
2382
2382
  throw new MissingDriverError(
2383
2383
  `Tron selected, but its package isn't installed. Run: npm install tronweb`,
@@ -2389,7 +2389,7 @@ var loaders = {
2389
2389
  sui: async () => {
2390
2390
  let mod;
2391
2391
  try {
2392
- mod = await import("./sui-FZIKZNVI.js");
2392
+ mod = await import("./sui-BXHB6D3W.js");
2393
2393
  } catch (cause) {
2394
2394
  throw new MissingDriverError(
2395
2395
  `Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
@@ -2401,7 +2401,7 @@ var loaders = {
2401
2401
  near: async () => {
2402
2402
  let mod;
2403
2403
  try {
2404
- mod = await import("./near-FZBUICCS.js");
2404
+ mod = await import("./near-VDATC5AV.js");
2405
2405
  } catch (cause) {
2406
2406
  throw new MissingDriverError(
2407
2407
  `NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
@@ -2413,7 +2413,7 @@ var loaders = {
2413
2413
  aptos: async () => {
2414
2414
  let mod;
2415
2415
  try {
2416
- mod = await import("./aptos-LY67Q6QF.js");
2416
+ mod = await import("./aptos-RYQOSFBQ.js");
2417
2417
  } catch (cause) {
2418
2418
  throw new MissingDriverError(
2419
2419
  `Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
@@ -2425,7 +2425,7 @@ var loaders = {
2425
2425
  algorand: async () => {
2426
2426
  let mod;
2427
2427
  try {
2428
- mod = await import("./algorand-AA3WXKW4.js");
2428
+ mod = await import("./algorand-TQCYK2XT.js");
2429
2429
  } catch (cause) {
2430
2430
  throw new MissingDriverError(
2431
2431
  `Algorand selected, but its package isn't installed. Run: npm install algosdk`,
@@ -3449,6 +3449,24 @@ var SpendLedger = class {
3449
3449
  }
3450
3450
  };
3451
3451
 
3452
+ // src/util/exactRecovery.ts
3453
+ function exactSettleCheckHint(family, payerFrom, nonce) {
3454
+ switch (family) {
3455
+ case "evm":
3456
+ return `the EIP-3009 \`authorizationState(${payerFrom}, ${nonce})\` (or, on the Permit2 method, the Permit2 nonce bitmap)`;
3457
+ case "solana":
3458
+ return `the buyer's transaction signature (a duplicate signature is the chain's own replay guard; plus the SPL-Memo nonce when present)`;
3459
+ case "algorand":
3460
+ return `the atomic group / transaction id`;
3461
+ case "aptos":
3462
+ return `the sender's account sequence number`;
3463
+ case "near":
3464
+ return `the access-key nonce (\`${nonce}\`)`;
3465
+ default:
3466
+ return `the single-use marker (\`ref=${nonce}\`)`;
3467
+ }
3468
+ }
3469
+
3452
3470
  // src/client.ts
3453
3471
  var DEFAULT_SCHEMES = ["onchain-proof"];
3454
3472
  var RECIPIENT_FIX = {
@@ -4760,7 +4778,7 @@ var PipRailClient = class {
4760
4778
  async payExactRail(net, wallet, accept, url, init, quote) {
4761
4779
  if (!net.payExact) {
4762
4780
  throw new UnsupportedSchemeError(
4763
- `the ${net.family} family can't pay a standard 'exact' rail (supported on EVM, Solana, Algorand + NEAR today).`
4781
+ `the ${net.family} family can't pay a standard 'exact' rail (supported on EVM, Solana, Algorand, Aptos + NEAR today).`
4764
4782
  );
4765
4783
  }
4766
4784
  throwIfAborted(init?.signal);
@@ -4793,7 +4811,7 @@ var PipRailClient = class {
4793
4811
  response = await fetch(url, { ...init ?? {}, headers, signal });
4794
4812
  } catch (err) {
4795
4813
  throw new PaymentTimeoutError(
4796
- `exact: no response after submitting the authorization (nonce=${nonce}) to ${hostOf2(url)}. The facilitator may have already settled it \u2014 verify on-chain with authorizationState(${payerFrom}, ${nonce}) before re-presenting; do NOT re-pay.`,
4814
+ `exact: no response after submitting the authorization (nonce=${nonce}) to ${hostOf2(url)}. The facilitator may have already settled it \u2014 verify on-chain via ${exactSettleCheckHint(net.family, payerFrom, nonce)} before re-presenting the SAME signed authorization; do NOT re-pay.`,
4797
4815
  { cause: err, ref: nonce }
4798
4816
  );
4799
4817
  } finally {
@@ -4809,7 +4827,7 @@ var PipRailClient = class {
4809
4827
  const receipt = parseReceipt(response);
4810
4828
  this.captureReceipt(response, url);
4811
4829
  this.safeEmit({ kind: "payment-settled", receipt, ...settle ? { settle } : {} });
4812
- const ref = settle?.transaction || receipt?.transaction || `eip3009-nonce:${nonce}`;
4830
+ const ref = settle?.transaction || receipt?.transaction || `${net.family === "evm" ? "eip3009" : net.family}-nonce:${nonce}`;
4813
4831
  this.recordSpend(quote, ref);
4814
4832
  return response;
4815
4833
  }
@@ -4828,7 +4846,7 @@ var PipRailClient = class {
4828
4846
  ...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
4829
4847
  });
4830
4848
  throw new MaxRetriesExceededError(
4831
- `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}.`,
4849
+ `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 on-chain via ${exactSettleCheckHint(net.family, payerFrom, nonce)} first. ref=${nonce}.`,
4832
4850
  { ref: nonce }
4833
4851
  );
4834
4852
  }
@@ -7478,11 +7496,18 @@ var MAX_TASK_RECEIPTS = 64;
7478
7496
  var VERIFY_CODE_TO_A2A_ERROR = {
7479
7497
  payment_expired: "EXPIRED_PAYMENT",
7480
7498
  tx_already_used: "DUPLICATE_NONCE",
7499
+ // Genuine amount mismatches only — the spec defines INVALID_AMOUNT as "the payment amount does
7500
+ // not match the required amount" (a2a.md §9.1), so keep it strictly for amount errors.
7481
7501
  amount_too_low: "INVALID_AMOUNT",
7482
7502
  upto_settle_exceeds_max: "INVALID_AMOUNT",
7483
7503
  signature_invalid: "INVALID_SIGNATURE",
7484
- transfer_not_found: "INVALID_AMOUNT",
7485
- wrong_recipient: "INVALID_AMOUNT",
7504
+ // NOT amount mismatches — a proof for an unoffered asset/network, or paid to the wrong recipient.
7505
+ // The spec's 7-member enum (errors.py x402ErrorCode) has no WRONG_RECIPIENT/TRANSFER_NOT_FOUND, so
7506
+ // these map to SETTLEMENT_FAILED — its explicit catch-all "the transaction failed on-chain for a
7507
+ // reason other than the above" (a2a.md §9.1) — never INVALID_AMOUNT, which would mislead a buyer
7508
+ // into retrying with a corrected amount. The raw PipRail code still rides in extensions.piprail.
7509
+ transfer_not_found: "SETTLEMENT_FAILED",
7510
+ wrong_recipient: "SETTLEMENT_FAILED",
7486
7511
  tx_reverted: "SETTLEMENT_FAILED",
7487
7512
  tx_not_found: "EXPIRED_PAYMENT",
7488
7513
  insufficient_confirmations: "EXPIRED_PAYMENT",
@@ -7565,7 +7590,7 @@ function createA2APaymentHandler(options) {
7565
7590
  const store = options.taskStore ?? defaultTaskStore();
7566
7591
  function appendReceipt(taskId, entry) {
7567
7592
  const prior = store.get(taskId)?.receipts ?? [];
7568
- const isDup = "success" in entry && entry.success === true && prior.some((r) => "transaction" in r && r.transaction === entry.transaction);
7593
+ const isDup = "success" in entry && entry.success === true && entry.transaction !== "" && prior.some((r) => "transaction" in r && r.transaction === entry.transaction);
7569
7594
  const next = isDup ? prior : [...prior, entry];
7570
7595
  const receipts = next.length > MAX_TASK_RECEIPTS ? next.slice(-MAX_TASK_RECEIPTS) : next;
7571
7596
  store.set(taskId, { receipts }, ttlMs);
@@ -7595,7 +7620,7 @@ function createA2APaymentHandler(options) {
7595
7620
  const network = attempted ?? singleNetworkOf(result.challenge);
7596
7621
  const receipts = appendReceiptFailed(taskId, result.error, result.detail, network);
7597
7622
  const metadata = {
7598
- [A2A_STATUS_KEY]: "payment-required",
7623
+ [A2A_STATUS_KEY]: "payment-failed",
7599
7624
  [A2A_ERROR_KEY]: toA2AErrorCode(result.error),
7600
7625
  [A2A_REQUIRED_KEY]: result.challenge,
7601
7626
  ...toA2APaymentReceipts(receipts)
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
13
+ var _chunkDCOUJZPLcjs = require('./chunk-DCOUJZPL.cjs');
14
14
 
15
15
  // src/drivers/near/index.ts
16
16
  var _nearapijs = require('near-api-js');
@@ -61,18 +61,18 @@ async function payNear(params) {
61
61
  return res.hash;
62
62
  } catch (err) {
63
63
  if (isNearRegistrationError(err)) {
64
- throw new (0, _chunkMWBT7MCEcjs.RecipientNotReadyError)(
64
+ throw new (0, _chunkDCOUJZPLcjs.RecipientNotReadyError)(
65
65
  `NEAR recipient ${accept.payTo} isn't registered on token ${accept.asset} (NEP-145 storage_deposit) \u2014 register it once (\u22480.00125 NEAR) before it can receive. (NEAR: not registered)`,
66
66
  { cause: err }
67
67
  );
68
68
  }
69
69
  if (isNearAffordability(err)) {
70
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
70
+ throw new (0, _chunkDCOUJZPLcjs.InsufficientFundsError)(
71
71
  err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
72
72
  { cause: err }
73
73
  );
74
74
  }
75
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
75
+ throw _nullishCoalesce(_chunkDCOUJZPLcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
76
76
  }
77
77
  }
78
78
  async function payNearNative(params) {
@@ -82,12 +82,12 @@ async function payNearNative(params) {
82
82
  return res.hash;
83
83
  } catch (err) {
84
84
  if (isNearAffordability(err)) {
85
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
85
+ throw new (0, _chunkDCOUJZPLcjs.InsufficientFundsError)(
86
86
  err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
87
87
  { cause: err }
88
88
  );
89
89
  }
90
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
90
+ throw _nullishCoalesce(_chunkDCOUJZPLcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
91
91
  }
92
92
  }
93
93
  function isNearRegistrationError(err) {
@@ -109,28 +109,28 @@ var NONCE_BLOCK_MULTIPLIER = 1000000n;
109
109
  async function payExactNear(input) {
110
110
  const { signer, senderId, blockHeight, accessKeyNonce, accept } = input;
111
111
  if (accept.asset === "native") {
112
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
112
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)(
113
113
  "NEAR exact is NEP-141-only (an ft_transfer); native NEAR is not exact-payable. Pay via onchain-proof."
114
114
  );
115
115
  }
116
116
  if (!isValidNearAccountId(accept.asset)) {
117
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`NEAR exact: asset "${accept.asset}" must be a NEP-141 contract account id.`);
117
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)(`NEAR exact: asset "${accept.asset}" must be a NEP-141 contract account id.`);
118
118
  }
119
119
  if (!isValidNearAccountId(accept.payTo)) {
120
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`NEAR exact: payTo "${accept.payTo}" is not a valid NEAR account id.`);
120
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)(`NEAR exact: payTo "${accept.payTo}" is not a valid NEAR account id.`);
121
121
  }
122
122
  if (!isValidNearAccountId(senderId)) {
123
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`NEAR exact: sender "${senderId}" is not a valid NEAR account id.`);
123
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)(`NEAR exact: sender "${senderId}" is not a valid NEAR account id.`);
124
124
  }
125
125
  const t = accept.maxTimeoutSeconds;
126
126
  if (!Number.isInteger(t) || t <= 0) {
127
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)("NEAR exact: maxTimeoutSeconds must be a positive integer.");
127
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)("NEAR exact: maxTimeoutSeconds must be a positive integer.");
128
128
  }
129
129
  const timeoutBlocks = BigInt(Math.max(1, Math.ceil(t / ESTIMATED_BLOCK_SECONDS)));
130
130
  const maxBlockHeight = blockHeight + timeoutBlocks;
131
131
  const nonce = accessKeyNonce + 1n;
132
132
  if (nonce >= blockHeight * NONCE_BLOCK_MULTIPLIER) {
133
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
133
+ throw new (0, _chunkDCOUJZPLcjs.UnsupportedSchemeError)(
134
134
  "NEAR exact: the access-key nonce is at the protocol ceiling for this block height; cannot build a delegate action."
135
135
  );
136
136
  }
@@ -259,7 +259,7 @@ async function verifyAndSettleExactNear(input) {
259
259
  if (/not enough|insufficient|exceeded the prepaid gas|NotEnoughBalance|doesn't have enough|is not registered/i.test(m)) {
260
260
  return fail("tx_reverted", `the ft_transfer would fail on chain: ${shorten(m)}.`);
261
261
  }
262
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
262
+ throw new (0, _chunkDCOUJZPLcjs.SettlementError)(
263
263
  `NEAR exact settle: the relayer could not submit the delegate (${shorten(m)}). The buyer's signed delegate is still valid \u2014 fund/fix the relayer and the buyer can re-present it.`,
264
264
  { cause: err }
265
265
  );
@@ -408,13 +408,13 @@ function txNotFound(hash) {
408
408
 
409
409
  function assertNearWallet(wallet, network) {
410
410
  if (typeof wallet !== "object" || wallet === null) {
411
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
411
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
412
412
  `chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
413
413
  );
414
414
  }
415
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
415
+ _chunkDCOUJZPLcjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
416
416
  if (!("accountId" in wallet) || !("key" in wallet)) {
417
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
417
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
418
418
  `chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
419
419
  );
420
420
  }
@@ -422,13 +422,13 @@ function assertNearWallet(wallet, network) {
422
422
  }
423
423
  function resolveNearWallet(config) {
424
424
  if (!config.accountId || !config.key) {
425
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
425
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
426
426
  }
427
427
  let signer;
428
428
  try {
429
429
  signer = _nearapijs.KeyPairSigner.fromSecretKey(config.key);
430
430
  } catch (cause) {
431
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
431
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
432
432
  cause
433
433
  });
434
434
  }
@@ -490,16 +490,16 @@ function makeNearNetwork(preset, rpcUrl) {
490
490
  const info = preset.tokens[token.toUpperCase()];
491
491
  if (!info) {
492
492
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
493
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
493
+ throw new (0, _chunkDCOUJZPLcjs.UnknownTokenError)(
494
494
  `token "${token}" isn't built in for NEAR (known: ${known}). Pass { contractId, decimals } for a custom NEP-141.`
495
495
  );
496
496
  }
497
497
  return { asset: info.contractId, decimals: info.decimals, symbol: info.symbol };
498
498
  }
499
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "near", network);
499
+ _chunkDCOUJZPLcjs.rejectForeignToken.call(void 0, token, "near", network);
500
500
  const t = token;
501
501
  if (!t.contractId || typeof t.decimals !== "number") {
502
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
502
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
503
503
  `chain ${network} is NEAR; a custom token must be { contractId, decimals }.`
504
504
  );
505
505
  }
@@ -518,12 +518,12 @@ function makeNearNetwork(preset, rpcUrl) {
518
518
  },
519
519
  assertValidPayTo(payTo) {
520
520
  if (payTo.startsWith("0x")) {
521
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
521
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
522
522
  `chain ${network} is NEAR, but payTo "${payTo}" looks like an EVM/Sui 0x address.`
523
523
  );
524
524
  }
525
525
  if (!isValidNearAccountId(payTo)) {
526
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
526
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
527
527
  `chain ${network} is NEAR, but payTo "${payTo}" is not a valid NEAR account id.`
528
528
  );
529
529
  }
@@ -567,10 +567,10 @@ function makeNearNetwork(preset, rpcUrl) {
567
567
  if (tx && tx.success) return { height: "0" };
568
568
  } catch (e11) {
569
569
  }
570
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
570
+ throw new (0, _chunkDCOUJZPLcjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
571
571
  },
572
572
  async estimateCost() {
573
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
573
+ return _chunkDCOUJZPLcjs.nativeCost.call(void 0, {
574
574
  symbol: "NEAR",
575
575
  decimals: NEAR_DECIMALS,
576
576
  fee: 1500000000000000000000n,
@@ -692,7 +692,7 @@ function makeNearNetwork(preset, rpcUrl) {
692
692
  try {
693
693
  relayerWallet = resolveNearWallet(relayer._native);
694
694
  } catch (err) {
695
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
695
+ throw new (0, _chunkDCOUJZPLcjs.SettlementError)(
696
696
  `NEAR exact settle: the relayer wallet is invalid (${err instanceof Error ? err.message : String(err)}).`,
697
697
  { cause: err }
698
698
  );
@@ -10,7 +10,7 @@ import {
10
10
  nativeCost,
11
11
  rejectForeignToken,
12
12
  toInsufficientFundsError
13
- } from "./chunk-SC2ZYDHD.js";
13
+ } from "./chunk-O32N6MFN.js";
14
14
 
15
15
  // src/drivers/near/index.ts
16
16
  import { JsonRpcProvider, Account, actions as actions2 } from "near-api-js";