@piprail/sdk 3.0.0 → 3.1.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Caip2, X as X402AcceptEntry, y as X402AnyAccept, B as X402ExactAcceptEntry, e as ExactPaymentPayloadAny, q as SignedReceipt, x as VerifyResult, J as X402UptoAcceptEntry, o as Permit2UptoPaymentPayload, w as SpendSummary, z as X402Challenge, G as X402Receipt, S as SettleOutcome, v as SpendStore, t as SpendLedger, u as SpendRecord, p as PipRailReceipt, V as VerifyErrorCode, a as AssetId, A as AddressId, P as PaidReceipt } from './ledger-Crc1bZox.cjs';
2
- export { D as DEFAULT_EXACT_TRANSFER_METHOD, E as EXT_OFFER_RECEIPT, b as EXT_PAYMENT_IDENTIFIER, c as ExactAuthorizationWire, d as ExactPaymentPayload, H as HEADER_REQUIRED, f as HEADER_RESPONSE, g as HEADER_RESPONSE_V1, h as HEADER_SIGNATURE, i as HEADER_SIGNATURE_V1, K as KNOWN_EXACT_TRANSFER_METHODS, j as ParsedExactPayment, k as ParsedUptoPayment, l as Permit2Authorization, m as Permit2PaymentPayload, n as Permit2UptoAuthorization, r as SpendAssetTotal, s as SpendDenomTotal, F as X402PaymentSignature, I as X402ResourceObject, L as buildChallengeHeader, M as buildExactSignatureHeader, N as buildPaymentIdentifierAdvertisement, O as buildReceiptExtension, Q as buildReceiptHeader, R as buildSignatureHeader, T as buildUptoSignatureHeader, U as buildV1PaymentHeader, W as decodeBase64Json, Y as exactTransferMethod, Z as isSettleableExactMethod, _ as memorySpendStore, $ as normalizeV1Challenge, a0 as parseChallenge, a1 as parseExactObject, a2 as parseExactPaymentHeader, a3 as parseReceipt, a4 as parseReceiptExtension, a5 as parseSettleResponse, a6 as parseSignatureHeader, a7 as parseSignatureObject, a8 as parseUptoObject, a9 as parseUptoPaymentHeader, aa as pickAccept, ab as readPaymentIdentifier } from './ledger-Crc1bZox.cjs';
1
+ import { C as Caip2, X as X402AcceptEntry, y as X402AnyAccept, B as X402ExactAcceptEntry, e as ExactPaymentPayloadAny, q as SignedReceipt, x as VerifyResult, J as X402UptoAcceptEntry, o as Permit2UptoPaymentPayload, w as SpendSummary, z as X402Challenge, G as X402Receipt, S as SettleOutcome, v as SpendStore, t as SpendLedger, u as SpendRecord, p as PipRailReceipt, V as VerifyErrorCode, a as AssetId, A as AddressId, P as PaidReceipt } from './ledger-DkHUORUe.cjs';
2
+ export { D as DEFAULT_EXACT_TRANSFER_METHOD, E as EXT_OFFER_RECEIPT, b as EXT_PAYMENT_IDENTIFIER, c as ExactAuthorizationWire, d as ExactPaymentPayload, H as HEADER_REQUIRED, f as HEADER_RESPONSE, g as HEADER_RESPONSE_V1, h as HEADER_SIGNATURE, i as HEADER_SIGNATURE_V1, K as KNOWN_EXACT_TRANSFER_METHODS, j as ParsedExactPayment, k as ParsedUptoPayment, l as Permit2Authorization, m as Permit2PaymentPayload, n as Permit2UptoAuthorization, r as SpendAssetTotal, s as SpendDenomTotal, F as X402PaymentSignature, I as X402ResourceObject, L as buildChallengeHeader, M as buildExactSignatureHeader, N as buildPaymentIdentifierAdvertisement, O as buildReceiptExtension, Q as buildReceiptHeader, R as buildSignatureHeader, T as buildUptoSignatureHeader, U as buildV1PaymentHeader, W as decodeBase64Json, Y as exactTransferMethod, Z as isSettleableExactMethod, _ as memorySpendStore, $ as normalizeV1Challenge, a0 as parseChallenge, a1 as parseExactObject, a2 as parseExactPaymentHeader, a3 as parseReceipt, a4 as parseReceiptExtension, a5 as parseSettleResponse, a6 as parseSignatureHeader, a7 as parseSignatureObject, a8 as parseUptoObject, a9 as parseUptoPaymentHeader, aa as pickAccept, ab as readPaymentIdentifier } from './ledger-DkHUORUe.cjs';
3
3
  import * as viem_zksync from 'viem/zksync';
4
4
  import * as abitype from 'abitype';
5
5
  import * as viem_chains from 'viem/chains';
@@ -4140,10 +4140,21 @@ type RecipientReason = 'NO_TRUSTLINE' | 'NOT_REGISTERED' | 'NOT_OPTED_IN' | 'INA
4140
4140
  /** What {@link ResolvedNetwork.balanceOf} returns — base-unit balances, or null per
4141
4141
  * field when that read was unavailable (transient/RPC), never a false 0. */
4142
4142
  interface WalletBalance {
4143
- /** The payment token's balance in base units, or null if the read was unavailable. */
4143
+ /**
4144
+ * The payment token's SPENDABLE balance in base units, or null if the read was unavailable.
4145
+ *
4146
+ * For `asset === 'native'` this is what the holder may actually send, which is not always
4147
+ * what it holds: a chain may require an account to retain a minimum it can never spend
4148
+ * (Solana's rent exemption, XRPL's base reserve). Report the reserve DEDUCTED here, and the
4149
+ * true balance in {@link WalletBalance.native}. `planPayment` measures affordability against
4150
+ * this field, so a driver that reports the raw balance instead will call a payment affordable
4151
+ * that the chain then refuses after signing — the one thing the pre-flight check exists to
4152
+ * prevent. Where a family has no such reserve the two fields are simply equal.
4153
+ */
4144
4154
  token: bigint | null;
4145
- /** The native gas coin's balance in base units, or null if unavailable. For
4146
- * `asset === 'native'`, this equals `token`. */
4155
+ /** The native gas coin's TRUE balance in base units, or null if unavailable — what gas is
4156
+ * judged against. For `asset === 'native'` this is the raw balance, which may exceed
4157
+ * {@link WalletBalance.token} by the chain's retained reserve. */
4147
4158
  native: bigint | null;
4148
4159
  }
4149
4160
  interface ConfirmInfo {
@@ -6026,6 +6037,21 @@ declare class PipRailClient {
6026
6037
  private bound?;
6027
6038
  private lastReceiptValue;
6028
6039
  constructor(opts: PipRailClientOptions);
6040
+ /**
6041
+ * Pin the three authority accessors to THIS instance, non-writable and non-configurable.
6042
+ *
6043
+ * `paymentTools()` decides which tools a model is handed by calling `canAgentSell()` /
6044
+ * `canAgentSwap()`, which read `mode()`. Those were plain prototype methods, so any code
6045
+ * holding the client could reassign one — `client.mode = () => 'sovereign'` turned a
6046
+ * budgeted client's eight tools into sovereign's fourteen.
6047
+ *
6048
+ * A MODEL could never do that (it sends JSON tool arguments; it does not hold the object),
6049
+ * so this is not a path a model can walk. It is defence in depth for the case where a
6050
+ * client passes through code that is not the operator's own: an agent framework, a plugin,
6051
+ * some middleware that wraps or proxies objects. Authority is set once, by whoever
6052
+ * provisioned the key, and nothing downstream gets to revise it.
6053
+ */
6054
+ private sealAuthority;
6029
6055
  /**
6030
6056
  * Fail LOUDLY at construction on a malformed amount cap — a security boundary
6031
6057
  * must never silently half-arm, and a misconfigured cap is a programmer error
@@ -7506,10 +7532,28 @@ interface RequirePaymentOptions {
7506
7532
  maxTimeoutSeconds?: number;
7507
7533
  /** Nonce generator. Default `crypto.randomUUID()`. */
7508
7534
  generateNonce?: () => string;
7509
- /** Replay hook — return true if this proof was already redeemed. */
7535
+ /**
7536
+ * Replay hook — return true if this proof was already redeemed.
7537
+ *
7538
+ * For a MULTI-PROCESS deployment make this an atomic **check-and-reserve** (Redis
7539
+ * `SET NX`, which returns null when the key already exists) rather than a plain read:
7540
+ * the gate consults this before an `await`ed verification and records after it, so a
7541
+ * separate `exists()` then `set()` lets two instances redeem one proof. A reserving
7542
+ * `isUsed` should be paired with {@link RequirePaymentOptions.releaseUsed}, or a
7543
+ * transient verify failure will permanently burn an otherwise-valid payment.
7544
+ */
7510
7545
  isUsed?: (ref: string) => boolean | Promise<boolean>;
7511
- /** Replay hook — record a redeemed proof. */
7546
+ /** Replay hook — record a redeemed proof. Fires only on a SETTLED payment. */
7512
7547
  markUsed?: (ref: string) => void | Promise<void>;
7548
+ /**
7549
+ * Replay hook — release a reservation this gate made but could not settle (a transient
7550
+ * RPC failure, a rejected proof). Optional, and only meaningful when `isUsed` RESERVES
7551
+ * (the `SET NX` shape above): without it that reservation outlives the failed attempt and
7552
+ * the buyer's still-valid proof can never be redeemed — they paid and get nothing. The
7553
+ * built-in store has always released on failure; this is how a custom store does the same.
7554
+ * Never throws into the request: a failure here is swallowed (a stale key expires on its own).
7555
+ */
7556
+ releaseUsed?: (ref: string) => void | Promise<void>;
7513
7557
  /**
7514
7558
  * Fired when a payment verifies successfully, with the enriched {@link PaidReceipt}.
7515
7559
  * May be **sync or async** — a throw OR a rejected promise is isolated (routed to
@@ -8054,7 +8098,9 @@ declare function parseFacilitatorSupported(body: unknown): FacilitatorSupportedK
8054
8098
  * {@link fetchFacilitatorFeePayer}). Lets an operator/agent ask "does this facilitator
8055
8099
  * cover my network?" before wiring a gate. Pure `fetch`, no chain libraries (STANDARDS §1).
8056
8100
  */
8057
- declare function facilitatorCoverage(url: string, timeoutMs?: number): Promise<FacilitatorSupportedKind[]>;
8101
+ declare function facilitatorCoverage(url: string,
8102
+ /** Cold-start sized, for the same reason as {@link fetchFacilitatorFeePayer}. */
8103
+ timeoutMs?: number): Promise<FacilitatorSupportedKind[]>;
8058
8104
  /** A merchant-chosen facilitator: its base URL + optional per-request auth headers. */
8059
8105
  interface FacilitatorConfig {
8060
8106
  /** Base URL, e.g. 'https://x402.org/facilitator' (trailing slash stripped). */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Caip2, X as X402AcceptEntry, y as X402AnyAccept, B as X402ExactAcceptEntry, e as ExactPaymentPayloadAny, q as SignedReceipt, x as VerifyResult, J as X402UptoAcceptEntry, o as Permit2UptoPaymentPayload, w as SpendSummary, z as X402Challenge, G as X402Receipt, S as SettleOutcome, v as SpendStore, t as SpendLedger, u as SpendRecord, p as PipRailReceipt, V as VerifyErrorCode, a as AssetId, A as AddressId, P as PaidReceipt } from './ledger-Crc1bZox.js';
2
- export { D as DEFAULT_EXACT_TRANSFER_METHOD, E as EXT_OFFER_RECEIPT, b as EXT_PAYMENT_IDENTIFIER, c as ExactAuthorizationWire, d as ExactPaymentPayload, H as HEADER_REQUIRED, f as HEADER_RESPONSE, g as HEADER_RESPONSE_V1, h as HEADER_SIGNATURE, i as HEADER_SIGNATURE_V1, K as KNOWN_EXACT_TRANSFER_METHODS, j as ParsedExactPayment, k as ParsedUptoPayment, l as Permit2Authorization, m as Permit2PaymentPayload, n as Permit2UptoAuthorization, r as SpendAssetTotal, s as SpendDenomTotal, F as X402PaymentSignature, I as X402ResourceObject, L as buildChallengeHeader, M as buildExactSignatureHeader, N as buildPaymentIdentifierAdvertisement, O as buildReceiptExtension, Q as buildReceiptHeader, R as buildSignatureHeader, T as buildUptoSignatureHeader, U as buildV1PaymentHeader, W as decodeBase64Json, Y as exactTransferMethod, Z as isSettleableExactMethod, _ as memorySpendStore, $ as normalizeV1Challenge, a0 as parseChallenge, a1 as parseExactObject, a2 as parseExactPaymentHeader, a3 as parseReceipt, a4 as parseReceiptExtension, a5 as parseSettleResponse, a6 as parseSignatureHeader, a7 as parseSignatureObject, a8 as parseUptoObject, a9 as parseUptoPaymentHeader, aa as pickAccept, ab as readPaymentIdentifier } from './ledger-Crc1bZox.js';
1
+ import { C as Caip2, X as X402AcceptEntry, y as X402AnyAccept, B as X402ExactAcceptEntry, e as ExactPaymentPayloadAny, q as SignedReceipt, x as VerifyResult, J as X402UptoAcceptEntry, o as Permit2UptoPaymentPayload, w as SpendSummary, z as X402Challenge, G as X402Receipt, S as SettleOutcome, v as SpendStore, t as SpendLedger, u as SpendRecord, p as PipRailReceipt, V as VerifyErrorCode, a as AssetId, A as AddressId, P as PaidReceipt } from './ledger-DkHUORUe.js';
2
+ export { D as DEFAULT_EXACT_TRANSFER_METHOD, E as EXT_OFFER_RECEIPT, b as EXT_PAYMENT_IDENTIFIER, c as ExactAuthorizationWire, d as ExactPaymentPayload, H as HEADER_REQUIRED, f as HEADER_RESPONSE, g as HEADER_RESPONSE_V1, h as HEADER_SIGNATURE, i as HEADER_SIGNATURE_V1, K as KNOWN_EXACT_TRANSFER_METHODS, j as ParsedExactPayment, k as ParsedUptoPayment, l as Permit2Authorization, m as Permit2PaymentPayload, n as Permit2UptoAuthorization, r as SpendAssetTotal, s as SpendDenomTotal, F as X402PaymentSignature, I as X402ResourceObject, L as buildChallengeHeader, M as buildExactSignatureHeader, N as buildPaymentIdentifierAdvertisement, O as buildReceiptExtension, Q as buildReceiptHeader, R as buildSignatureHeader, T as buildUptoSignatureHeader, U as buildV1PaymentHeader, W as decodeBase64Json, Y as exactTransferMethod, Z as isSettleableExactMethod, _ as memorySpendStore, $ as normalizeV1Challenge, a0 as parseChallenge, a1 as parseExactObject, a2 as parseExactPaymentHeader, a3 as parseReceipt, a4 as parseReceiptExtension, a5 as parseSettleResponse, a6 as parseSignatureHeader, a7 as parseSignatureObject, a8 as parseUptoObject, a9 as parseUptoPaymentHeader, aa as pickAccept, ab as readPaymentIdentifier } from './ledger-DkHUORUe.js';
3
3
  import * as viem_zksync from 'viem/zksync';
4
4
  import * as abitype from 'abitype';
5
5
  import * as viem_chains from 'viem/chains';
@@ -4140,10 +4140,21 @@ type RecipientReason = 'NO_TRUSTLINE' | 'NOT_REGISTERED' | 'NOT_OPTED_IN' | 'INA
4140
4140
  /** What {@link ResolvedNetwork.balanceOf} returns — base-unit balances, or null per
4141
4141
  * field when that read was unavailable (transient/RPC), never a false 0. */
4142
4142
  interface WalletBalance {
4143
- /** The payment token's balance in base units, or null if the read was unavailable. */
4143
+ /**
4144
+ * The payment token's SPENDABLE balance in base units, or null if the read was unavailable.
4145
+ *
4146
+ * For `asset === 'native'` this is what the holder may actually send, which is not always
4147
+ * what it holds: a chain may require an account to retain a minimum it can never spend
4148
+ * (Solana's rent exemption, XRPL's base reserve). Report the reserve DEDUCTED here, and the
4149
+ * true balance in {@link WalletBalance.native}. `planPayment` measures affordability against
4150
+ * this field, so a driver that reports the raw balance instead will call a payment affordable
4151
+ * that the chain then refuses after signing — the one thing the pre-flight check exists to
4152
+ * prevent. Where a family has no such reserve the two fields are simply equal.
4153
+ */
4144
4154
  token: bigint | null;
4145
- /** The native gas coin's balance in base units, or null if unavailable. For
4146
- * `asset === 'native'`, this equals `token`. */
4155
+ /** The native gas coin's TRUE balance in base units, or null if unavailable — what gas is
4156
+ * judged against. For `asset === 'native'` this is the raw balance, which may exceed
4157
+ * {@link WalletBalance.token} by the chain's retained reserve. */
4147
4158
  native: bigint | null;
4148
4159
  }
4149
4160
  interface ConfirmInfo {
@@ -6026,6 +6037,21 @@ declare class PipRailClient {
6026
6037
  private bound?;
6027
6038
  private lastReceiptValue;
6028
6039
  constructor(opts: PipRailClientOptions);
6040
+ /**
6041
+ * Pin the three authority accessors to THIS instance, non-writable and non-configurable.
6042
+ *
6043
+ * `paymentTools()` decides which tools a model is handed by calling `canAgentSell()` /
6044
+ * `canAgentSwap()`, which read `mode()`. Those were plain prototype methods, so any code
6045
+ * holding the client could reassign one — `client.mode = () => 'sovereign'` turned a
6046
+ * budgeted client's eight tools into sovereign's fourteen.
6047
+ *
6048
+ * A MODEL could never do that (it sends JSON tool arguments; it does not hold the object),
6049
+ * so this is not a path a model can walk. It is defence in depth for the case where a
6050
+ * client passes through code that is not the operator's own: an agent framework, a plugin,
6051
+ * some middleware that wraps or proxies objects. Authority is set once, by whoever
6052
+ * provisioned the key, and nothing downstream gets to revise it.
6053
+ */
6054
+ private sealAuthority;
6029
6055
  /**
6030
6056
  * Fail LOUDLY at construction on a malformed amount cap — a security boundary
6031
6057
  * must never silently half-arm, and a misconfigured cap is a programmer error
@@ -7506,10 +7532,28 @@ interface RequirePaymentOptions {
7506
7532
  maxTimeoutSeconds?: number;
7507
7533
  /** Nonce generator. Default `crypto.randomUUID()`. */
7508
7534
  generateNonce?: () => string;
7509
- /** Replay hook — return true if this proof was already redeemed. */
7535
+ /**
7536
+ * Replay hook — return true if this proof was already redeemed.
7537
+ *
7538
+ * For a MULTI-PROCESS deployment make this an atomic **check-and-reserve** (Redis
7539
+ * `SET NX`, which returns null when the key already exists) rather than a plain read:
7540
+ * the gate consults this before an `await`ed verification and records after it, so a
7541
+ * separate `exists()` then `set()` lets two instances redeem one proof. A reserving
7542
+ * `isUsed` should be paired with {@link RequirePaymentOptions.releaseUsed}, or a
7543
+ * transient verify failure will permanently burn an otherwise-valid payment.
7544
+ */
7510
7545
  isUsed?: (ref: string) => boolean | Promise<boolean>;
7511
- /** Replay hook — record a redeemed proof. */
7546
+ /** Replay hook — record a redeemed proof. Fires only on a SETTLED payment. */
7512
7547
  markUsed?: (ref: string) => void | Promise<void>;
7548
+ /**
7549
+ * Replay hook — release a reservation this gate made but could not settle (a transient
7550
+ * RPC failure, a rejected proof). Optional, and only meaningful when `isUsed` RESERVES
7551
+ * (the `SET NX` shape above): without it that reservation outlives the failed attempt and
7552
+ * the buyer's still-valid proof can never be redeemed — they paid and get nothing. The
7553
+ * built-in store has always released on failure; this is how a custom store does the same.
7554
+ * Never throws into the request: a failure here is swallowed (a stale key expires on its own).
7555
+ */
7556
+ releaseUsed?: (ref: string) => void | Promise<void>;
7513
7557
  /**
7514
7558
  * Fired when a payment verifies successfully, with the enriched {@link PaidReceipt}.
7515
7559
  * May be **sync or async** — a throw OR a rejected promise is isolated (routed to
@@ -8054,7 +8098,9 @@ declare function parseFacilitatorSupported(body: unknown): FacilitatorSupportedK
8054
8098
  * {@link fetchFacilitatorFeePayer}). Lets an operator/agent ask "does this facilitator
8055
8099
  * cover my network?" before wiring a gate. Pure `fetch`, no chain libraries (STANDARDS §1).
8056
8100
  */
8057
- declare function facilitatorCoverage(url: string, timeoutMs?: number): Promise<FacilitatorSupportedKind[]>;
8101
+ declare function facilitatorCoverage(url: string,
8102
+ /** Cold-start sized, for the same reason as {@link fetchFacilitatorFeePayer}. */
8103
+ timeoutMs?: number): Promise<FacilitatorSupportedKind[]>;
8058
8104
  /** A merchant-chosen facilitator: its base URL + optional per-request auth headers. */
8059
8105
  interface FacilitatorConfig {
8060
8106
  /** Base URL, e.g. 'https://x402.org/facilitator' (trailing slash stripped). */