@haven_ai/sdk 0.0.0-dev.202609190647.18526db → 0.0.0-dev.202609190936.6937e31

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.cjs CHANGED
@@ -865,6 +865,13 @@ function selectPaymentOption(accepts) {
865
865
  return null;
866
866
  }
867
867
  var ERC7710_ASSET_TRANSFER_METHOD = "erc7710";
868
+ function isEip3009ConstructibleOption(option) {
869
+ const rawMethod = option.extra?.assetTransferMethod;
870
+ if (rawMethod !== void 0 && rawMethod !== "eip3009") return false;
871
+ const rawFlow = option.extra?.paymentFlow;
872
+ if (rawFlow !== void 0 && rawFlow !== "authorization") return false;
873
+ return true;
874
+ }
868
875
  function x402AssetTransferMethod(option) {
869
876
  const raw = option.extra?.assetTransferMethod;
870
877
  return typeof raw === "string" ? raw : null;
@@ -885,7 +892,8 @@ function selectStandardPaymentOption(accepts) {
885
892
  if (!accepts || accepts.length === 0) return null;
886
893
  for (const opt of accepts) {
887
894
  if (opt === null || typeof opt !== "object") continue;
888
- if (!isErc7710Option(opt) && isPayableStandardOption(opt)) return opt;
895
+ if (!isEip3009ConstructibleOption(opt)) continue;
896
+ if (isPayableStandardOption(opt)) return opt;
889
897
  }
890
898
  return null;
891
899
  }
@@ -894,6 +902,7 @@ function selectErc7710PaymentOption(accepts) {
894
902
  for (const opt of accepts) {
895
903
  if (opt === null || typeof opt !== "object") continue;
896
904
  if (isErc7710Option(opt) && isPayableStandardOption(opt)) return opt;
905
+ if (!isEip3009ConstructibleOption(opt)) continue;
897
906
  }
898
907
  return null;
899
908
  }
@@ -955,6 +964,11 @@ function toStandardPaymentRequirements(paymentRequired, option) {
955
964
  if (option.scheme !== "exact") {
956
965
  throw new Error(`Unsupported x402 scheme: ${option.scheme}`);
957
966
  }
967
+ if (!isEip3009ConstructibleOption(option)) {
968
+ throw new Error(
969
+ "Unsupported x402 payment requirements: this SDK constructs EIP-3009 authorization payments only. The merchant advertised a different extra.assetTransferMethod or an unrecognized extra.paymentFlow."
970
+ );
971
+ }
958
972
  return {
959
973
  scheme: "exact",
960
974
  network,
@@ -2079,8 +2093,11 @@ function requestInitFromSnapshot(request) {
2079
2093
  }
2080
2094
  function noCompatiblePaymentOptionError(accepts) {
2081
2095
  const erc7710Only = selectErc7710PaymentOption(accepts) !== null;
2096
+ const unsupportedOnly = !erc7710Only && accepts.some(
2097
+ (opt) => opt !== null && typeof opt === "object" && !isErc7710Option(opt) && (x402AssetTransferMethod(opt) !== null || opt.extra?.paymentFlow !== void 0)
2098
+ );
2082
2099
  return new HavenApiError(
2083
- "No compatible payment option found in x402 requirements. Haven supports standard x402 exact payments on Base USDC." + (erc7710Only ? " The only Haven-compatible option this merchant advertises is tagged extra.assetTransferMethod: 'erc7710' (direct settlement), which this EIP-3009 payment path cannot settle \u2014 the limitation is the settlement scheme, not the asset. Paying this merchant requires a delegation-rail erc7710 flow (settleX402Erc7710, or the hosted MCP purchase tools)." : ""),
2100
+ "No compatible payment option found in x402 requirements. Haven supports standard x402 exact payments on Base USDC." + (erc7710Only ? " The only Haven-compatible option this merchant advertises is tagged extra.assetTransferMethod: 'erc7710' (direct settlement), which this EIP-3009 payment path cannot settle \u2014 the limitation is the settlement scheme, not the asset. Paying this merchant requires a delegation-rail erc7710 flow (settleX402Erc7710, or the hosted MCP purchase tools)." : unsupportedOnly ? " Every option this merchant advertises asks for a transfer method or payment flow Haven cannot construct (for example extra.assetTransferMethod: 'permit2', or an unrecognized extra.paymentFlow). No payment intent was created and no funds moved." : ""),
2084
2101
  400
2085
2102
  );
2086
2103
  }