@toon-protocol/client 0.26.1 → 0.27.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.ts CHANGED
@@ -2237,6 +2237,22 @@ declare function httpEndpointToBtpUrl(httpEndpoint: string): string;
2237
2237
  * payment-claim validation lives ONLY in the connector.
2238
2238
  */
2239
2239
 
2240
+ /**
2241
+ * The `extra` bag of an `accepts` entry — an open set of terms from the peer,
2242
+ * not a fixed contract. `session_lease_ttl_ms` (connector#722,
2243
+ * `session_registry::SESSION_LEASE_BACKSTOP_TTL`) is the one member this
2244
+ * client currently reads by name; everything else is preserved untouched
2245
+ * (issue #506) rather than stripped by a narrower type, so a future field
2246
+ * survives the round trip even before this package knows its name.
2247
+ */
2248
+ interface X402ChannelExtra {
2249
+ /**
2250
+ * The connector's session lease TTL in milliseconds. Absent on a connector
2251
+ * predating #722 — `undefined`, never a substituted default.
2252
+ */
2253
+ session_lease_ttl_ms?: number;
2254
+ [key: string]: unknown;
2255
+ }
2240
2256
  /** A single parsed `accepts` entry that offers the `toon-channel` scheme. */
2241
2257
  interface ToonChannelAccept {
2242
2258
  /** Always `'toon-channel'` for a matched entry. */
@@ -2251,6 +2267,12 @@ interface ToonChannelAccept {
2251
2267
  httpEndpoint: string;
2252
2268
  /** Whether the host accepts the BTP upgrade over the HTTP endpoint. */
2253
2269
  supportsUpgrade: boolean;
2270
+ /**
2271
+ * The entry's raw `extra` bag, preserved as-is. `undefined` when the entry
2272
+ * carried no `extra` at all — distinct from an `extra` that merely omits a
2273
+ * given key (issue #506).
2274
+ */
2275
+ extra?: X402ChannelExtra;
2254
2276
  }
2255
2277
  /** The parsed x402 402 body, with the selected `toon-channel` entry (if any). */
2256
2278
  interface ParsedX402Challenge {
@@ -2281,6 +2303,8 @@ interface H402FetchOptions {
2281
2303
  type ClaimResolver = (destination: string, amount: bigint) => Promise<unknown>;
2282
2304
  /** Factory for an {@link HttpIlpClient} given a resolved `POST /ilp` endpoint. */
2283
2305
  type HttpIlpClientFactory = (httpEndpoint: string) => HttpIlpClient;
2306
+ /** Caller-supplied hook invoked with every parsed x402 challenge. */
2307
+ type ChallengeHandler = (challenge: ParsedX402Challenge) => void;
2284
2308
  interface Http402ClientConfig {
2285
2309
  /**
2286
2310
  * Underlying HTTP fetch for the INITIAL (un-paid) request that probes for a
@@ -2319,6 +2343,16 @@ interface Http402ClientConfig {
2319
2343
  * re-fetching a key per paid request.
2320
2344
  */
2321
2345
  connectorEdge?: ConnectorEdgeClient;
2346
+ /**
2347
+ * Called with the parsed challenge whenever a `402` body is parsed —
2348
+ * before the pay/pass-through decision, so it fires whether or not a
2349
+ * `toon-channel` entry is offered or a claim resolver is configured. The
2350
+ * one-shot `fetch()` return is a plain `Response`; this is how a caller
2351
+ * (e.g. `ToonClient.getLastX402Terms`) reaches the negotiated terms —
2352
+ * including the `extra` bag (issue #506) — without re-issuing the probe
2353
+ * itself.
2354
+ */
2355
+ onChallenge?: ChallengeHandler;
2322
2356
  }
2323
2357
  /**
2324
2358
  * Reusable h402 fetch engine. `ToonClient.h402Fetch` is a thin wrapper that
@@ -2330,6 +2364,7 @@ declare class Http402Client {
2330
2364
  private readonly createIlpClient;
2331
2365
  private readonly needsDuplex;
2332
2366
  private readonly connectorEdge;
2367
+ private readonly onChallenge?;
2333
2368
  constructor(config?: Http402ClientConfig);
2334
2369
  /**
2335
2370
  * `fetch()`-like entry point. Issues the request; on `402` parses the x402
@@ -2600,6 +2635,14 @@ declare function submitEvmSettlement(bundle: SettlementBundle, params: SubmitEvm
2600
2635
  declare class ToonClient {
2601
2636
  private readonly config;
2602
2637
  private state;
2638
+ /**
2639
+ * The most recently parsed `toon-channel` x402 accepts entry, from the last
2640
+ * `h402Fetch` call that saw a `402` (issue #506) — including its `extra`
2641
+ * bag (e.g. `session_lease_ttl_ms`). Captured whether or not that fetch
2642
+ * went on to pay, so a caller can read the negotiated terms via
2643
+ * {@link getLastX402Terms} without re-issuing the probe by hand.
2644
+ */
2645
+ private lastX402Terms?;
2603
2646
  private readonly evmSigner?;
2604
2647
  private solanaSigner?;
2605
2648
  /**
@@ -2859,6 +2902,16 @@ declare class ToonClient {
2859
2902
  * HTTP payload.
2860
2903
  */
2861
2904
  h402Fetch(url: string, opts?: H402FetchOptions): Promise<Response>;
2905
+ /**
2906
+ * The `toon-channel` accepts entry from the most recent `h402Fetch` 402
2907
+ * probe — including its `extra` bag (issue #506, e.g.
2908
+ * `extra.session_lease_ttl_ms`, connector#722) — or `undefined` if
2909
+ * `h402Fetch` has not yet been called or its last probe offered no
2910
+ * `toon-channel` entry. Captured whether or not that fetch went on to pay,
2911
+ * so a caller (e.g. buzz#84's mesh refresh cadence) can read the
2912
+ * negotiated terms without re-issuing a probe by hand.
2913
+ */
2914
+ getLastX402Terms(): ToonChannelAccept | undefined;
2862
2915
  /**
2863
2916
  * Sends a raw swap ILP packet (Story 12.5) to a swap peer with an attached
2864
2917
  * balance-proof claim. This is a lower-level surface than `publishEvent`:
@@ -6710,4 +6763,4 @@ declare function readExchangeOutcome(result: {
6710
6763
  /** Read a response header, case-insensitively; the first match wins. */
6711
6764
  declare function envelopeHeader(response: EnvelopeResponse, name: string): string | undefined;
6712
6765
 
6713
- export { type BackupPayload, type BalanceProofParams, BtpPaidWriteTransport, type BtpPaidWriteTransportConfig, BtpRuntimeClient, type BtpRuntimeClientConfig, type BuildSwapSettlementsParams, CLAIM_TYPEHASH, CONDITION_LENGTH, COOP_CLOSE_TYPEHASH, type ChainMetadata, type ChainSigner, type ChannelBinding, type ChannelBindingContext, ChannelFundingError, ChannelManager, ChannelResumeError, type ChannelStore, type ChannelStoreEntry, type ClaimMessage, type ClaimResolver, type ClaimSendingTransport, type ClaimSignature, type ClaimStateFailed, type ClaimStateOk, type ClaimStateRequestEntry, type ClaimStateResult, ConnectorEdgeClient, type ConnectorEdgeClientConfig, ConnectorEdgeError, type ConnectorEdgeErrorCode, ConnectorError, type ConnectorIdentity, type ConnectorRoutePrice, type Decoded, type DeployMinaZkAppParams, type DiscoveredIlpPeer, type EVMClaimMessage, type EncryptedArtifact, type EncryptedKeystore, type EnsureOwnedMinaZkAppParams, type EnsureOwnedMinaZkAppResult, type Envelope, EnvelopeError, EnvelopeErrorKind, type EnvelopeHeader, type EnvelopeRequest, type EnvelopeResponse, type EvmClaimDomainContext, type EvmClaimMessage, type EvmClaimVerifyResult, type EvmCooperativeCloseMessage, type EvmReadConsistencyConfig, EvmSigner, type EvmTransferConfig, type ExchangeOutcome, type ExecutionConditionPair, FULFILLMENT_MISMATCH_CODE, FULFILLMENT_MISMATCH_MESSAGE, type FaucetChain, type FundWalletOptions, type FundWalletResult, GIFTWRAP_NONCE_LENGTH, GIFTWRAP_PUBLIC_KEY_LENGTH, GIFTWRAP_SECRET_LENGTH, GIFTWRAP_TYPE_REQUEST, GIFTWRAP_TYPE_RESPONSE, GIFT_WRAP_KIND, GiftWrapAddressError, GiftWrapDecryptError, type GiftWrapEcdh, GiftWrapError, GiftWrapErrorKind, type H402FetchOptions, HashlockConditionMismatchError, HashlockDecryptError, Http402Client, type Http402ClientConfig, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpIlpClient, type HttpIlpClientConfig, type HttpIlpClientFactory, HttpRuntimeClient, type HttpRuntimeClientConfig, ILP_CLAIM_HEADER, ILP_PEER_ID_HEADER, type IlpSendParams, type IlpSendResultWithFulfillment, type IlpTransportChoice, InMemoryChannelStore, InMemoryPreimageRetentionStore, InMemoryReceivedClaimStore, type IncrementOfferTags, type IncrementPrepare, type IngestAndRevealParams, type IngestAndRevealResult, type IngestReceivedClaimsParams, type IngestReceivedClaimsResult, InsufficientBalanceError, InvalidAddressError, type JobAnswer, type JobHandler, type JobRequest, JsonFileChannelStore, JsonFileReceivedClaimStore, KeyManager, type KeyManagerConfig, MINA_CHANNEL_STATE, type MinaChannelStateReader, type MinaClaimMessage, type MinaClaimSubmitArgs, type MinaClaimSubmitter, type MinaCoSignInputs, type MinaCoSignedClaim, type MinaDepositReader, type MinaOnChainChannelState, type MinaSettlementContext, MinaSettlementError, type MinaSettlementErrorCode, type MinaSettlementResult, type MinaSignaturePair, MinaSigner, type MinaSignerOptions, type MinaTransferConfig, type MinaZkAppDeployRecord, NetworkError, OerError, OerErrorKind, OnChainChannelClient, type OnChainChannelClientConfig, type OpenedRequest, type OrderedBtpSession, type ParsedX402Challenge, type PasskeyInfo, type PreimageRetentionStore, type PublishEventResult, ROLLING_SWAP_DOMAIN_NAME, ROLLING_SWAP_DOMAIN_VERSION, type ReceivedClaimEntry, type ReceivedClaimRejection, type ReceivedClaimRejectionCode, type ReceivedClaimStore, type RequestBlobStorageParams, type RequestBlobStorageResult, type RetainedPreimage, type RetryOptions, type RevealDecision, type RevealFn, type RevealResult, type RevealedClaim, type RolledBackClaim, SEAL_KIND, type SealedExchange, type SealedRequest, SealedResponseError, type SealedResponseErrorKind, type SelectIlpTransportOptions, type SendTransferParams, type SendTransferResult, type SignedBalanceProof, type SolanaChannelClientOptions, type SolanaClaimMessage, SolanaSigner, type SolanaTransferConfig, StaleRpcReadError, type SubmitEvmSettlementParams, type SubmitEvmSettlementResult, type SwapSettlementBuild, type ToonChannelAccept, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type TransferAssetKind, type TransferChain, type TransferConfig, TransferNotDeliveredError, TransferUnsupportedError, UnknownChainError, type UnwrappedGiftWrap, ValidationError, type VaultData, type VerifiedReceivedClaim, type WalletBalance, type WalletBalanceSources, type WalletChainBalances, type WalletTokenAmount, applyDefaults, applyNetworkPresets, assertValidCondition, buildBackupEvent, buildBackupFilter, buildIncrementPrepare, buildMinaCoSignedClaim, buildSettlementInfo, buildSwapSettlements, connectorEdgeBaseUrl, createJobMessageHandler, createO1jsMinaClaimSubmitter, decodeConnectorPublicKey, decodeEnvelope, decodeEnvelopeRequest, decodeEnvelopeResponse, decodeEvmSettlementTx, decodeVarOctetString, decodeVarUint, decryptArtifact, decryptMnemonic, defaultFaucetTimeout, deployMinaChannelZkApp, deriveCondition, deriveFromNsec, deriveFulfillment, deriveFullIdentity, deriveNostrKeyFromMnemonic, encodeEnvelope, encodeEnvelopeRequest, encodeEnvelopeResponse, encodeVarOctetString, encodeVarUint, encryptArtifact, encryptMnemonic, ensureOwnedMinaZkApp, entryToAccumulatedClaim, envelopeHeader, evmClaimDigest, evmCooperativeCloseDigest, extractArweaveTxId, fulfillIncrement, fulfillmentMatchesCondition, fundWallet, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, hasSettlementMetadata, httpEndpointToBtpUrl, importKeystore, ingestAndReveal, ingestReceivedClaims, isInsufficientGasError, isPrfSupported, isZeroCondition, loadKeystore, localGiftWrapEcdh, looksLikeSealedResponse, mintExecutionCondition, openRequest, openResponse, parseBackupPayload, parseClaimStateResponse, parseConnectorIdentity, parseConnectorRoutePrice, parseEvmChainId, parseX402Body, parseX402Challenge, proxyIlpEndpoint, readDiscoveredIlpPeer, readEvmNativeBalance, readEvmTokenBalance, readExchangeOutcome, readMinaBalance, readMinaChannelState, readMinaDepositTotal, readSolanaNativeBalance, readSolanaTokenBalance, readWalletBalances, recoverEvmClaimSigner, requestBlobStorage, sealExchange, sealRequest, sealRequestWithRandomness, sealResponse, sealResponseWithRandomness, selectIlpTransport, sendTransfer, submitEvmSettlement, submitMinaSettlement, unwrapGiftWrapWithKey, validateConfig, validateMnemonic, verifyEvmClaimSignature, withRetry, writeKeystoreFile };
6766
+ export { type BackupPayload, type BalanceProofParams, BtpPaidWriteTransport, type BtpPaidWriteTransportConfig, BtpRuntimeClient, type BtpRuntimeClientConfig, type BuildSwapSettlementsParams, CLAIM_TYPEHASH, CONDITION_LENGTH, COOP_CLOSE_TYPEHASH, type ChainMetadata, type ChainSigner, type ChallengeHandler, type ChannelBinding, type ChannelBindingContext, ChannelFundingError, ChannelManager, ChannelResumeError, type ChannelStore, type ChannelStoreEntry, type ClaimMessage, type ClaimResolver, type ClaimSendingTransport, type ClaimSignature, type ClaimStateFailed, type ClaimStateOk, type ClaimStateRequestEntry, type ClaimStateResult, ConnectorEdgeClient, type ConnectorEdgeClientConfig, ConnectorEdgeError, type ConnectorEdgeErrorCode, ConnectorError, type ConnectorIdentity, type ConnectorRoutePrice, type Decoded, type DeployMinaZkAppParams, type DiscoveredIlpPeer, type EVMClaimMessage, type EncryptedArtifact, type EncryptedKeystore, type EnsureOwnedMinaZkAppParams, type EnsureOwnedMinaZkAppResult, type Envelope, EnvelopeError, EnvelopeErrorKind, type EnvelopeHeader, type EnvelopeRequest, type EnvelopeResponse, type EvmClaimDomainContext, type EvmClaimMessage, type EvmClaimVerifyResult, type EvmCooperativeCloseMessage, type EvmReadConsistencyConfig, EvmSigner, type EvmTransferConfig, type ExchangeOutcome, type ExecutionConditionPair, FULFILLMENT_MISMATCH_CODE, FULFILLMENT_MISMATCH_MESSAGE, type FaucetChain, type FundWalletOptions, type FundWalletResult, GIFTWRAP_NONCE_LENGTH, GIFTWRAP_PUBLIC_KEY_LENGTH, GIFTWRAP_SECRET_LENGTH, GIFTWRAP_TYPE_REQUEST, GIFTWRAP_TYPE_RESPONSE, GIFT_WRAP_KIND, GiftWrapAddressError, GiftWrapDecryptError, type GiftWrapEcdh, GiftWrapError, GiftWrapErrorKind, type H402FetchOptions, HashlockConditionMismatchError, HashlockDecryptError, Http402Client, type Http402ClientConfig, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpIlpClient, type HttpIlpClientConfig, type HttpIlpClientFactory, HttpRuntimeClient, type HttpRuntimeClientConfig, ILP_CLAIM_HEADER, ILP_PEER_ID_HEADER, type IlpSendParams, type IlpSendResultWithFulfillment, type IlpTransportChoice, InMemoryChannelStore, InMemoryPreimageRetentionStore, InMemoryReceivedClaimStore, type IncrementOfferTags, type IncrementPrepare, type IngestAndRevealParams, type IngestAndRevealResult, type IngestReceivedClaimsParams, type IngestReceivedClaimsResult, InsufficientBalanceError, InvalidAddressError, type JobAnswer, type JobHandler, type JobRequest, JsonFileChannelStore, JsonFileReceivedClaimStore, KeyManager, type KeyManagerConfig, MINA_CHANNEL_STATE, type MinaChannelStateReader, type MinaClaimMessage, type MinaClaimSubmitArgs, type MinaClaimSubmitter, type MinaCoSignInputs, type MinaCoSignedClaim, type MinaDepositReader, type MinaOnChainChannelState, type MinaSettlementContext, MinaSettlementError, type MinaSettlementErrorCode, type MinaSettlementResult, type MinaSignaturePair, MinaSigner, type MinaSignerOptions, type MinaTransferConfig, type MinaZkAppDeployRecord, NetworkError, OerError, OerErrorKind, OnChainChannelClient, type OnChainChannelClientConfig, type OpenedRequest, type OrderedBtpSession, type ParsedX402Challenge, type PasskeyInfo, type PreimageRetentionStore, type PublishEventResult, ROLLING_SWAP_DOMAIN_NAME, ROLLING_SWAP_DOMAIN_VERSION, type ReceivedClaimEntry, type ReceivedClaimRejection, type ReceivedClaimRejectionCode, type ReceivedClaimStore, type RequestBlobStorageParams, type RequestBlobStorageResult, type RetainedPreimage, type RetryOptions, type RevealDecision, type RevealFn, type RevealResult, type RevealedClaim, type RolledBackClaim, SEAL_KIND, type SealedExchange, type SealedRequest, SealedResponseError, type SealedResponseErrorKind, type SelectIlpTransportOptions, type SendTransferParams, type SendTransferResult, type SignedBalanceProof, type SolanaChannelClientOptions, type SolanaClaimMessage, SolanaSigner, type SolanaTransferConfig, StaleRpcReadError, type SubmitEvmSettlementParams, type SubmitEvmSettlementResult, type SwapSettlementBuild, type ToonChannelAccept, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type TransferAssetKind, type TransferChain, type TransferConfig, TransferNotDeliveredError, TransferUnsupportedError, UnknownChainError, type UnwrappedGiftWrap, ValidationError, type VaultData, type VerifiedReceivedClaim, type WalletBalance, type WalletBalanceSources, type WalletChainBalances, type WalletTokenAmount, type X402ChannelExtra, applyDefaults, applyNetworkPresets, assertValidCondition, buildBackupEvent, buildBackupFilter, buildIncrementPrepare, buildMinaCoSignedClaim, buildSettlementInfo, buildSwapSettlements, connectorEdgeBaseUrl, createJobMessageHandler, createO1jsMinaClaimSubmitter, decodeConnectorPublicKey, decodeEnvelope, decodeEnvelopeRequest, decodeEnvelopeResponse, decodeEvmSettlementTx, decodeVarOctetString, decodeVarUint, decryptArtifact, decryptMnemonic, defaultFaucetTimeout, deployMinaChannelZkApp, deriveCondition, deriveFromNsec, deriveFulfillment, deriveFullIdentity, deriveNostrKeyFromMnemonic, encodeEnvelope, encodeEnvelopeRequest, encodeEnvelopeResponse, encodeVarOctetString, encodeVarUint, encryptArtifact, encryptMnemonic, ensureOwnedMinaZkApp, entryToAccumulatedClaim, envelopeHeader, evmClaimDigest, evmCooperativeCloseDigest, extractArweaveTxId, fulfillIncrement, fulfillmentMatchesCondition, fundWallet, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, hasSettlementMetadata, httpEndpointToBtpUrl, importKeystore, ingestAndReveal, ingestReceivedClaims, isInsufficientGasError, isPrfSupported, isZeroCondition, loadKeystore, localGiftWrapEcdh, looksLikeSealedResponse, mintExecutionCondition, openRequest, openResponse, parseBackupPayload, parseClaimStateResponse, parseConnectorIdentity, parseConnectorRoutePrice, parseEvmChainId, parseX402Body, parseX402Challenge, proxyIlpEndpoint, readDiscoveredIlpPeer, readEvmNativeBalance, readEvmTokenBalance, readExchangeOutcome, readMinaBalance, readMinaChannelState, readMinaDepositTotal, readSolanaNativeBalance, readSolanaTokenBalance, readWalletBalances, recoverEvmClaimSigner, requestBlobStorage, sealExchange, sealRequest, sealRequestWithRandomness, sealResponse, sealResponseWithRandomness, selectIlpTransport, sendTransfer, submitEvmSettlement, submitMinaSettlement, unwrapGiftWrapWithKey, validateConfig, validateMnemonic, verifyEvmClaimSignature, withRetry, writeKeystoreFile };
package/dist/index.js CHANGED
@@ -5031,11 +5031,12 @@ async function initializeHttpMode(config) {
5031
5031
  supportsUpgrade: config.connectorSupportsUpgrade
5032
5032
  });
5033
5033
  const transportChoice = discoveredPeer.httpEndpoint || discoveredPeer.btpEndpoint ? selectIlpTransport(discoveredPeer, { needsDuplex: false }) : null;
5034
+ const btpPeerId = config.btpPeerId ?? config.ilpInfo.ilpAddress;
5034
5035
  let btpClient = null;
5035
5036
  if (effectiveBtpUrl) {
5036
5037
  btpClient = new BtpRuntimeClient({
5037
5038
  btpUrl: effectiveBtpUrl,
5038
- peerId: config.btpPeerId ?? `client`,
5039
+ peerId: btpPeerId,
5039
5040
  authToken: config.btpAuthToken ?? "",
5040
5041
  // Serve-side job registration (toon-client#494): a connector-originated
5041
5042
  // MESSAGE carrying a PREPARE is answered by the configured handler.
@@ -5049,7 +5050,7 @@ async function initializeHttpMode(config) {
5049
5050
  if (transportChoice && (transportChoice.kind === "http" || transportChoice.kind === "http-upgradable")) {
5050
5051
  httpIlpClient = new HttpIlpClient({
5051
5052
  httpEndpoint: transportChoice.httpEndpoint,
5052
- ...config.btpPeerId !== void 0 ? { peerId: config.btpPeerId } : {},
5053
+ peerId: btpPeerId,
5053
5054
  ...config.btpAuthToken !== void 0 ? { authToken: config.btpAuthToken } : {},
5054
5055
  timeout: config.queryTimeout,
5055
5056
  maxRetries: config.maxRetries,
@@ -7071,9 +7072,11 @@ var Http402Client = class {
7071
7072
  createIlpClient;
7072
7073
  needsDuplex;
7073
7074
  connectorEdge;
7075
+ onChallenge;
7074
7076
  constructor(config = {}) {
7075
7077
  this.fetchImpl = config.fetch ?? fetch;
7076
7078
  this.resolveClaim = config.resolveClaim;
7079
+ this.onChallenge = config.onChallenge;
7077
7080
  this.createIlpClient = config.createIlpClient ?? ((httpEndpoint) => new HttpIlpClient({ httpEndpoint }));
7078
7081
  this.needsDuplex = config.needsDuplex ?? false;
7079
7082
  this.connectorEdge = config.connectorEdge ?? new ConnectorEdgeClient({
@@ -7098,6 +7101,7 @@ var Http402Client = class {
7098
7101
  });
7099
7102
  if (probe.status !== 402) return probe;
7100
7103
  const challenge = await parseX402Challenge(probe.clone());
7104
+ this.onChallenge?.(challenge);
7101
7105
  const accept = challenge.toonChannel;
7102
7106
  if (!accept || !this.resolveClaim) return probe;
7103
7107
  return this.payOverToon(url, method, opts, accept, this.resolveClaim);
@@ -7234,11 +7238,13 @@ function parseX402Body(body, baseUrl) {
7234
7238
  const entry = raw;
7235
7239
  const scheme = readString(entry, ["scheme"]);
7236
7240
  if (scheme !== "toon-channel") continue;
7237
- const extra = typeof entry["extra"] === "object" && entry["extra"] !== null ? entry["extra"] : {};
7238
- const destination = readString(extra, ["ilpAddress", "destination"]) ?? readString(entry, ["destination", "ilpAddress", "payTo"]);
7239
- const rawEndpoint = readString(entry, ["httpEndpoint", "ilpEndpoint"]) ?? readString(extra, ["httpEndpoint", "endpoint"]) ?? readString(entry, ["endpoint"]);
7241
+ const rawExtra = entry["extra"];
7242
+ const extra = typeof rawExtra === "object" && rawExtra !== null ? rawExtra : void 0;
7243
+ const extraForReads = extra ?? {};
7244
+ const destination = readString(extraForReads, ["ilpAddress", "destination"]) ?? readString(entry, ["destination", "ilpAddress", "payTo"]);
7245
+ const rawEndpoint = readString(entry, ["httpEndpoint", "ilpEndpoint"]) ?? readString(extraForReads, ["httpEndpoint", "endpoint"]) ?? readString(entry, ["endpoint"]);
7240
7246
  const httpEndpoint = resolveEndpoint(rawEndpoint, baseUrl);
7241
- const amount = readAmount(extra, ["price", "amount"]) ?? readAmount(entry, ["amount", "price", "maxAmountRequired"]);
7247
+ const amount = readAmount(extraForReads, ["price", "amount"]) ?? readAmount(entry, ["amount", "price", "maxAmountRequired"]);
7242
7248
  if (!destination || !httpEndpoint || amount === void 0) continue;
7243
7249
  const network = readString(entry, ["network", "chain"]);
7244
7250
  const supportsUpgrade = entry["supportsUpgrade"] === true || entry["upgradable"] === true;
@@ -7250,7 +7256,8 @@ function parseX402Body(body, baseUrl) {
7250
7256
  destination,
7251
7257
  amount,
7252
7258
  httpEndpoint,
7253
- supportsUpgrade
7259
+ supportsUpgrade,
7260
+ ...extra !== void 0 ? { extra } : {}
7254
7261
  }
7255
7262
  };
7256
7263
  }
@@ -7735,6 +7742,14 @@ function lookupByCanonicalChain(map, chain) {
7735
7742
  var ToonClient = class {
7736
7743
  config;
7737
7744
  state = null;
7745
+ /**
7746
+ * The most recently parsed `toon-channel` x402 accepts entry, from the last
7747
+ * `h402Fetch` call that saw a `402` (issue #506) — including its `extra`
7748
+ * bag (e.g. `session_lease_ttl_ms`). Captured whether or not that fetch
7749
+ * went on to pay, so a caller can read the negotiated terms via
7750
+ * {@link getLastX402Terms} without re-issuing the probe by hand.
7751
+ */
7752
+ lastX402Terms;
7738
7753
  evmSigner;
7739
7754
  solanaSigner;
7740
7755
  /**
@@ -8286,12 +8301,29 @@ var ToonClient = class {
8286
8301
  // fresh Http402Client per call (below), and a paid request now needs a
8287
8302
  // terminating key.
8288
8303
  connectorEdge: this.connectorEdge,
8304
+ // Capture the negotiated terms (issue #506) regardless of the
8305
+ // pay/pass-through outcome — see `lastX402Terms`'s own doc comment.
8306
+ onChallenge: (challenge) => {
8307
+ this.lastX402Terms = challenge.toonChannel;
8308
+ },
8289
8309
  ...this.channelManager ? {
8290
8310
  resolveClaim: (destination, amount) => this.resolveClaimForDestination(destination, amount)
8291
8311
  } : {}
8292
8312
  });
8293
8313
  return client.fetch(url, opts);
8294
8314
  }
8315
+ /**
8316
+ * The `toon-channel` accepts entry from the most recent `h402Fetch` 402
8317
+ * probe — including its `extra` bag (issue #506, e.g.
8318
+ * `extra.session_lease_ttl_ms`, connector#722) — or `undefined` if
8319
+ * `h402Fetch` has not yet been called or its last probe offered no
8320
+ * `toon-channel` entry. Captured whether or not that fetch went on to pay,
8321
+ * so a caller (e.g. buzz#84's mesh refresh cadence) can read the
8322
+ * negotiated terms without re-issuing a probe by hand.
8323
+ */
8324
+ getLastX402Terms() {
8325
+ return this.lastX402Terms;
8326
+ }
8295
8327
  /**
8296
8328
  * Sends a raw swap ILP packet (Story 12.5) to a swap peer with an attached
8297
8329
  * balance-proof claim. This is a lower-level surface than `publishEvent`: