uvd-x402-sdk 2.46.0 → 2.47.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/README.md +65 -0
- package/dist/adapters/index.d.mts +3 -3
- package/dist/adapters/index.d.ts +3 -3
- package/dist/backend/index.d.mts +2 -2
- package/dist/backend/index.d.ts +2 -2
- package/dist/backend/index.js +7 -1
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +7 -1
- package/dist/backend/index.mjs.map +1 -1
- package/dist/{index-DgChnK_c.d.mts → index-CVW8AhRX.d.mts} +1 -1
- package/dist/{index-DgChnK_c.d.ts → index-CVW8AhRX.d.ts} +1 -1
- package/dist/{index-BidnFGw_.d.mts → index-Cic-RnwJ.d.mts} +1 -1
- package/dist/{index-H64xdjKh.d.ts → index-DVJ9S8lP.d.ts} +1 -1
- package/dist/index.d.mts +387 -5
- package/dist/index.d.ts +387 -5
- package/dist/index.js +375 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +364 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{ows-DTDixPzO.d.ts → ows-C-KmORG9.d.ts} +1 -1
- package/dist/{ows-CYIVd4xO.d.mts → ows-Z9v4GxOZ.d.mts} +1 -1
- package/dist/providers/algorand/index.d.mts +1 -1
- package/dist/providers/algorand/index.d.ts +1 -1
- package/dist/providers/evm/index.d.mts +1 -1
- package/dist/providers/evm/index.d.ts +1 -1
- package/dist/providers/near/index.d.mts +1 -1
- package/dist/providers/near/index.d.ts +1 -1
- package/dist/providers/solana/index.d.mts +1 -1
- package/dist/providers/solana/index.d.ts +1 -1
- package/dist/providers/stellar/index.d.mts +1 -1
- package/dist/providers/stellar/index.d.ts +1 -1
- package/dist/providers/sui/index.d.mts +1 -1
- package/dist/providers/sui/index.d.ts +1 -1
- package/dist/providers/xrpl/index.d.mts +1 -1
- package/dist/providers/xrpl/index.d.ts +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/{wallet-0cX9Pw2F.d.mts → wallet-w7BnImDG.d.mts} +1 -1
- package/dist/{wallet-0cX9Pw2F.d.ts → wallet-w7BnImDG.d.ts} +1 -1
- package/package.json +38 -13
- package/src/backend/index.ts +22 -1
- package/src/erc8128.ts +443 -0
- package/src/escrow-preauth.ts +416 -0
- package/src/index.ts +36 -0
package/dist/index.js
CHANGED
|
@@ -2548,6 +2548,362 @@ async function* streamTrafficEvents(options = {}) {
|
|
|
2548
2548
|
reader.releaseLock();
|
|
2549
2549
|
}
|
|
2550
2550
|
}
|
|
2551
|
+
var DEFAULT_LABEL = "eth";
|
|
2552
|
+
var ALG = "eip191";
|
|
2553
|
+
var DEFAULT_VALIDITY_SEC = 300;
|
|
2554
|
+
var DEFAULT_CHAIN_ID = 8453;
|
|
2555
|
+
async function signRequest(options) {
|
|
2556
|
+
const key = options.privateKey.startsWith("0x") ? options.privateKey : `0x${options.privateKey}`;
|
|
2557
|
+
const wallet = new ethers.ethers.Wallet(key);
|
|
2558
|
+
return signRequestWithSigner({
|
|
2559
|
+
address: wallet.address,
|
|
2560
|
+
signMessage: (signatureBase) => wallet.signMessage(signatureBase),
|
|
2561
|
+
method: options.method,
|
|
2562
|
+
url: options.url,
|
|
2563
|
+
body: options.body,
|
|
2564
|
+
nonce: options.nonce,
|
|
2565
|
+
chainId: options.chainId,
|
|
2566
|
+
label: options.label,
|
|
2567
|
+
validitySec: options.validitySec
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
async function signRequestWithWallet(wallet, options) {
|
|
2571
|
+
return signRequestWithSigner({
|
|
2572
|
+
...options,
|
|
2573
|
+
address: wallet.getAddress(),
|
|
2574
|
+
signMessage: (signatureBase) => wallet.signMessage(signatureBase)
|
|
2575
|
+
});
|
|
2576
|
+
}
|
|
2577
|
+
async function signRequestWithSigner(options) {
|
|
2578
|
+
const {
|
|
2579
|
+
address: rawAddress,
|
|
2580
|
+
signMessage,
|
|
2581
|
+
method,
|
|
2582
|
+
url,
|
|
2583
|
+
body,
|
|
2584
|
+
nonce,
|
|
2585
|
+
chainId = DEFAULT_CHAIN_ID,
|
|
2586
|
+
label = DEFAULT_LABEL,
|
|
2587
|
+
validitySec = DEFAULT_VALIDITY_SEC
|
|
2588
|
+
} = options;
|
|
2589
|
+
const address = rawAddress.toLowerCase();
|
|
2590
|
+
const parsed = new URL(url);
|
|
2591
|
+
const authority = parsed.host;
|
|
2592
|
+
const path = parsed.pathname || "/";
|
|
2593
|
+
const query = parsed.search || void 0;
|
|
2594
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
2595
|
+
const created = now;
|
|
2596
|
+
const expires = now + validitySec;
|
|
2597
|
+
const keyid = `erc8128:${chainId}:${address}`;
|
|
2598
|
+
const covered = ["@method", "@authority", "@path"];
|
|
2599
|
+
if (query) {
|
|
2600
|
+
covered.push("@query");
|
|
2601
|
+
}
|
|
2602
|
+
const headers = {
|
|
2603
|
+
Signature: "",
|
|
2604
|
+
"Signature-Input": ""
|
|
2605
|
+
};
|
|
2606
|
+
if (body !== void 0) {
|
|
2607
|
+
const digest = computeContentDigest(body);
|
|
2608
|
+
headers["Content-Digest"] = digest;
|
|
2609
|
+
covered.push("content-digest");
|
|
2610
|
+
}
|
|
2611
|
+
const sigBase = buildSignatureBase({
|
|
2612
|
+
method,
|
|
2613
|
+
authority,
|
|
2614
|
+
path,
|
|
2615
|
+
query,
|
|
2616
|
+
contentDigest: headers["Content-Digest"],
|
|
2617
|
+
covered,
|
|
2618
|
+
created,
|
|
2619
|
+
expires,
|
|
2620
|
+
nonce,
|
|
2621
|
+
keyid
|
|
2622
|
+
});
|
|
2623
|
+
const sigHex = await signMessage(sigBase);
|
|
2624
|
+
const sigBytes = ethers.ethers.getBytes(sigHex.startsWith("0x") ? sigHex : `0x${sigHex}`);
|
|
2625
|
+
const sigB64 = ethers.ethers.encodeBase64(sigBytes);
|
|
2626
|
+
const sigParams = buildSignatureParams({ covered, created, expires, nonce, keyid });
|
|
2627
|
+
headers.Signature = `${label}=:${sigB64}:`;
|
|
2628
|
+
headers["Signature-Input"] = `${label}=${sigParams}`;
|
|
2629
|
+
return headers;
|
|
2630
|
+
}
|
|
2631
|
+
async function fetchNonce(apiBase, timeoutMs = 1e4) {
|
|
2632
|
+
const url = `${apiBase.replace(/\/$/, "")}/api/v1/auth/erc8128/nonce`;
|
|
2633
|
+
const controller = new AbortController();
|
|
2634
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
2635
|
+
try {
|
|
2636
|
+
const resp = await fetch(url, { signal: controller.signal });
|
|
2637
|
+
if (!resp.ok) {
|
|
2638
|
+
throw new Error(`Failed to fetch nonce: ${resp.status} ${resp.statusText}`);
|
|
2639
|
+
}
|
|
2640
|
+
const data = await resp.json();
|
|
2641
|
+
return data.nonce;
|
|
2642
|
+
} finally {
|
|
2643
|
+
clearTimeout(timer);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
function createSignedFetch(config) {
|
|
2647
|
+
const { apiBase, chainId, privateKey, wallet } = config;
|
|
2648
|
+
if (!privateKey && !wallet) {
|
|
2649
|
+
throw new X402Error(
|
|
2650
|
+
"createSignedFetch requires a signer: pass privateKey or wallet.",
|
|
2651
|
+
"WALLET_NOT_CONNECTED"
|
|
2652
|
+
);
|
|
2653
|
+
}
|
|
2654
|
+
return async (path, init) => {
|
|
2655
|
+
const url = `${apiBase.replace(/\/$/, "")}${path}`;
|
|
2656
|
+
const method = (init?.method || "GET").toUpperCase();
|
|
2657
|
+
const body = init?.body ? String(init.body) : void 0;
|
|
2658
|
+
const nonce = await fetchNonce(apiBase);
|
|
2659
|
+
const requestOptions = { method, url, body, nonce, chainId };
|
|
2660
|
+
const sigHeaders = wallet ? await signRequestWithWallet(wallet, requestOptions) : await signRequest({ ...requestOptions, privateKey });
|
|
2661
|
+
const headers = new Headers(init?.headers);
|
|
2662
|
+
headers.set("Signature", sigHeaders.Signature);
|
|
2663
|
+
headers.set("Signature-Input", sigHeaders["Signature-Input"]);
|
|
2664
|
+
if (sigHeaders["Content-Digest"]) {
|
|
2665
|
+
headers.set("Content-Digest", sigHeaders["Content-Digest"]);
|
|
2666
|
+
}
|
|
2667
|
+
if (body) {
|
|
2668
|
+
headers.set("Content-Type", headers.get("Content-Type") || "application/json");
|
|
2669
|
+
}
|
|
2670
|
+
return fetch(url, { ...init, headers, method });
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
function computeContentDigest(body) {
|
|
2674
|
+
const hash = ethers.ethers.sha256(ethers.ethers.toUtf8Bytes(body));
|
|
2675
|
+
const b64 = ethers.ethers.encodeBase64(ethers.ethers.getBytes(hash));
|
|
2676
|
+
return `sha-256=:${b64}:`;
|
|
2677
|
+
}
|
|
2678
|
+
function buildSignatureBase(params) {
|
|
2679
|
+
const lines = [];
|
|
2680
|
+
for (const component of params.covered) {
|
|
2681
|
+
switch (component) {
|
|
2682
|
+
case "@method":
|
|
2683
|
+
lines.push(`"@method": ${params.method.toUpperCase()}`);
|
|
2684
|
+
break;
|
|
2685
|
+
case "@authority":
|
|
2686
|
+
lines.push(`"@authority": ${params.authority}`);
|
|
2687
|
+
break;
|
|
2688
|
+
case "@path":
|
|
2689
|
+
lines.push(`"@path": ${params.path}`);
|
|
2690
|
+
break;
|
|
2691
|
+
case "@query":
|
|
2692
|
+
lines.push(`"@query": ${params.query || "?"}`);
|
|
2693
|
+
break;
|
|
2694
|
+
case "content-digest":
|
|
2695
|
+
lines.push(`"content-digest": ${params.contentDigest || ""}`);
|
|
2696
|
+
break;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
const sigParams = buildSignatureParams({
|
|
2700
|
+
covered: params.covered,
|
|
2701
|
+
created: params.created,
|
|
2702
|
+
expires: params.expires,
|
|
2703
|
+
nonce: params.nonce,
|
|
2704
|
+
keyid: params.keyid
|
|
2705
|
+
});
|
|
2706
|
+
lines.push(`"@signature-params": ${sigParams}`);
|
|
2707
|
+
return lines.join("\n");
|
|
2708
|
+
}
|
|
2709
|
+
function buildSignatureParams(params) {
|
|
2710
|
+
const compStr = params.covered.map((c) => `"${c}"`).join(" ");
|
|
2711
|
+
const parts = [`(${compStr})`];
|
|
2712
|
+
parts.push(`created=${params.created}`);
|
|
2713
|
+
parts.push(`expires=${params.expires}`);
|
|
2714
|
+
if (params.nonce) {
|
|
2715
|
+
parts.push(`nonce="${params.nonce}"`);
|
|
2716
|
+
}
|
|
2717
|
+
parts.push(`keyid="${params.keyid}"`);
|
|
2718
|
+
parts.push(`alg="${ALG}"`);
|
|
2719
|
+
return parts.join(";");
|
|
2720
|
+
}
|
|
2721
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
2722
|
+
var USDC_DECIMALS = 6;
|
|
2723
|
+
var ESCROW_DEPOSIT_LIMIT_USD = 100;
|
|
2724
|
+
var OPERATOR_FEE_BPS = 1300;
|
|
2725
|
+
var DEFAULT_MIN_FEE_BPS = 0;
|
|
2726
|
+
var DEFAULT_MAX_FEE_BPS = 1800;
|
|
2727
|
+
var RECEIVE_WITH_AUTHORIZATION_TYPES = {
|
|
2728
|
+
ReceiveWithAuthorization: [
|
|
2729
|
+
{ name: "from", type: "address" },
|
|
2730
|
+
{ name: "to", type: "address" },
|
|
2731
|
+
{ name: "value", type: "uint256" },
|
|
2732
|
+
{ name: "validAfter", type: "uint256" },
|
|
2733
|
+
{ name: "validBefore", type: "uint256" },
|
|
2734
|
+
{ name: "nonce", type: "bytes32" }
|
|
2735
|
+
]
|
|
2736
|
+
};
|
|
2737
|
+
var PAYMENT_INFO_TUPLE = "tuple(address,address,address,address,uint120,uint48,uint48,uint48,uint16,uint16,address,uint256)";
|
|
2738
|
+
var ESCROW_TIER_WINDOWS = {
|
|
2739
|
+
micro: { pre: 3600, auth: 7200, refund: 86400 },
|
|
2740
|
+
standard: { pre: 7200, auth: 86400, refund: 604800 }
|
|
2741
|
+
};
|
|
2742
|
+
var REVIEW_WINDOW_SEC = 7 * 24 * 3600;
|
|
2743
|
+
var REFUND_WINDOW_SEC = 7 * 24 * 3600;
|
|
2744
|
+
var REQUIRED_NETWORK_KEYS = [
|
|
2745
|
+
"chain_id",
|
|
2746
|
+
"operator",
|
|
2747
|
+
"escrow",
|
|
2748
|
+
"token_collector",
|
|
2749
|
+
"usdc",
|
|
2750
|
+
"usdc_domain_name",
|
|
2751
|
+
"usdc_domain_version",
|
|
2752
|
+
"payment_info_typehash"
|
|
2753
|
+
];
|
|
2754
|
+
function hex32(value) {
|
|
2755
|
+
return value.startsWith("0x") ? value : `0x${value}`;
|
|
2756
|
+
}
|
|
2757
|
+
function randomSalt() {
|
|
2758
|
+
const webCrypto = globalThis.crypto;
|
|
2759
|
+
if (webCrypto?.getRandomValues) {
|
|
2760
|
+
const bytes = new Uint8Array(32);
|
|
2761
|
+
webCrypto.getRandomValues(bytes);
|
|
2762
|
+
return ethers.ethers.hexlify(bytes);
|
|
2763
|
+
}
|
|
2764
|
+
return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
2765
|
+
}
|
|
2766
|
+
function computeEscrowNonce(chainId, escrowAddress, paymentInfoTypehash, pi) {
|
|
2767
|
+
const coder = ethers.ethers.AbiCoder.defaultAbiCoder();
|
|
2768
|
+
const piTuple = [
|
|
2769
|
+
ethers.ethers.getAddress(pi.operator),
|
|
2770
|
+
ZERO_ADDRESS,
|
|
2771
|
+
// payer = 0 for the payer-agnostic hash
|
|
2772
|
+
ethers.ethers.getAddress(pi.receiver),
|
|
2773
|
+
ethers.ethers.getAddress(pi.token),
|
|
2774
|
+
BigInt(pi.maxAmount),
|
|
2775
|
+
// uint120
|
|
2776
|
+
pi.preApprovalExpiry,
|
|
2777
|
+
// uint48
|
|
2778
|
+
pi.authorizationExpiry,
|
|
2779
|
+
// uint48
|
|
2780
|
+
pi.refundExpiry,
|
|
2781
|
+
// uint48
|
|
2782
|
+
pi.minFeeBps,
|
|
2783
|
+
// uint16
|
|
2784
|
+
pi.maxFeeBps,
|
|
2785
|
+
// uint16
|
|
2786
|
+
ethers.ethers.getAddress(pi.feeReceiver),
|
|
2787
|
+
BigInt(hex32(pi.salt))
|
|
2788
|
+
// uint256
|
|
2789
|
+
];
|
|
2790
|
+
const piHash = ethers.ethers.keccak256(
|
|
2791
|
+
coder.encode(["bytes32", PAYMENT_INFO_TUPLE], [hex32(paymentInfoTypehash), piTuple])
|
|
2792
|
+
);
|
|
2793
|
+
return ethers.ethers.keccak256(
|
|
2794
|
+
coder.encode(
|
|
2795
|
+
["uint256", "address", "bytes32"],
|
|
2796
|
+
[chainId, ethers.ethers.getAddress(escrowAddress), piHash]
|
|
2797
|
+
)
|
|
2798
|
+
);
|
|
2799
|
+
}
|
|
2800
|
+
async function buildEscrowPreAuth(wallet, params) {
|
|
2801
|
+
const cfg = params.networkConfig;
|
|
2802
|
+
const missing = REQUIRED_NETWORK_KEYS.filter((key) => !cfg[key]);
|
|
2803
|
+
if (missing.length > 0) {
|
|
2804
|
+
throw new X402Error(
|
|
2805
|
+
`Incomplete escrow network config (missing ${missing.join(", ")}) \u2014 refusing to sign an EIP-3009 authorization with a mismatched domain.`,
|
|
2806
|
+
"INVALID_CONFIG"
|
|
2807
|
+
);
|
|
2808
|
+
}
|
|
2809
|
+
const maxAmount = BigInt(params.bountyAtomic);
|
|
2810
|
+
if (maxAmount <= 0n) {
|
|
2811
|
+
throw new X402Error(
|
|
2812
|
+
`Bounty must be positive, got ${maxAmount} atomic units`,
|
|
2813
|
+
"INVALID_AMOUNT"
|
|
2814
|
+
);
|
|
2815
|
+
}
|
|
2816
|
+
const depositLimitUsd = params.depositLimitUsd ?? ESCROW_DEPOSIT_LIMIT_USD;
|
|
2817
|
+
const depositLimitAtomic = BigInt(Math.round(depositLimitUsd * 10 ** USDC_DECIMALS));
|
|
2818
|
+
if (maxAmount > depositLimitAtomic) {
|
|
2819
|
+
throw new X402Error(
|
|
2820
|
+
`Bounty ${maxAmount} atomic units exceeds the on-chain escrow deposit limit ($${depositLimitUsd}).`,
|
|
2821
|
+
"INVALID_AMOUNT"
|
|
2822
|
+
);
|
|
2823
|
+
}
|
|
2824
|
+
const minFeeBps = cfg.min_fee_bps ?? DEFAULT_MIN_FEE_BPS;
|
|
2825
|
+
const maxFeeBps = cfg.max_fee_bps ?? DEFAULT_MAX_FEE_BPS;
|
|
2826
|
+
if (maxFeeBps < OPERATOR_FEE_BPS) {
|
|
2827
|
+
throw new X402Error(
|
|
2828
|
+
`maxFeeBps=${maxFeeBps} cannot cover the operator's ${OPERATOR_FEE_BPS} bps static fee \u2014 the on-chain release would revert.`,
|
|
2829
|
+
"INVALID_CONFIG"
|
|
2830
|
+
);
|
|
2831
|
+
}
|
|
2832
|
+
const tierKey = params.tier ?? "micro";
|
|
2833
|
+
const windows = cfg.tiers?.[tierKey] ?? ESCROW_TIER_WINDOWS[tierKey];
|
|
2834
|
+
if (!windows) {
|
|
2835
|
+
const known = [.../* @__PURE__ */ new Set([...Object.keys(cfg.tiers ?? {}), ...Object.keys(ESCROW_TIER_WINDOWS)])].sort();
|
|
2836
|
+
throw new X402Error(
|
|
2837
|
+
`Unknown escrow tier '${tierKey}' \u2014 known tiers: ${known.join(", ")}`,
|
|
2838
|
+
"INVALID_CONFIG"
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
2842
|
+
const reviewBase = Math.max(now, params.reviewDeadlineSec ?? now);
|
|
2843
|
+
const authExpiry = Math.max(now + windows.auth, reviewBase + REVIEW_WINDOW_SEC);
|
|
2844
|
+
const refundExpiry = Math.max(now + windows.refund, authExpiry + REFUND_WINDOW_SEC);
|
|
2845
|
+
const paymentInfo = {
|
|
2846
|
+
operator: ethers.ethers.getAddress(cfg.operator),
|
|
2847
|
+
receiver: ethers.ethers.getAddress(params.workerWallet),
|
|
2848
|
+
token: ethers.ethers.getAddress(cfg.usdc),
|
|
2849
|
+
maxAmount: maxAmount.toString(),
|
|
2850
|
+
preApprovalExpiry: now + windows.pre,
|
|
2851
|
+
authorizationExpiry: authExpiry,
|
|
2852
|
+
refundExpiry,
|
|
2853
|
+
minFeeBps,
|
|
2854
|
+
maxFeeBps,
|
|
2855
|
+
feeReceiver: ethers.ethers.getAddress(cfg.operator),
|
|
2856
|
+
salt: randomSalt()
|
|
2857
|
+
};
|
|
2858
|
+
const nonce = computeEscrowNonce(
|
|
2859
|
+
cfg.chain_id,
|
|
2860
|
+
cfg.escrow,
|
|
2861
|
+
cfg.payment_info_typehash,
|
|
2862
|
+
paymentInfo
|
|
2863
|
+
);
|
|
2864
|
+
const payer = ethers.ethers.getAddress(params.payerWallet);
|
|
2865
|
+
const tokenCollector = ethers.ethers.getAddress(cfg.token_collector);
|
|
2866
|
+
const { signature } = await wallet.signTypedData(
|
|
2867
|
+
JSON.stringify({
|
|
2868
|
+
domain: {
|
|
2869
|
+
name: cfg.usdc_domain_name,
|
|
2870
|
+
version: cfg.usdc_domain_version,
|
|
2871
|
+
chainId: cfg.chain_id,
|
|
2872
|
+
verifyingContract: ethers.ethers.getAddress(cfg.usdc)
|
|
2873
|
+
},
|
|
2874
|
+
types: RECEIVE_WITH_AUTHORIZATION_TYPES,
|
|
2875
|
+
primaryType: "ReceiveWithAuthorization",
|
|
2876
|
+
message: {
|
|
2877
|
+
from: payer,
|
|
2878
|
+
to: tokenCollector,
|
|
2879
|
+
value: maxAmount.toString(),
|
|
2880
|
+
validAfter: "0",
|
|
2881
|
+
validBefore: String(paymentInfo.preApprovalExpiry),
|
|
2882
|
+
nonce
|
|
2883
|
+
}
|
|
2884
|
+
})
|
|
2885
|
+
);
|
|
2886
|
+
return JSON.stringify({
|
|
2887
|
+
x402Version: 2,
|
|
2888
|
+
scheme: "escrow",
|
|
2889
|
+
payload: {
|
|
2890
|
+
authorization: {
|
|
2891
|
+
from: payer,
|
|
2892
|
+
to: tokenCollector,
|
|
2893
|
+
value: maxAmount.toString(),
|
|
2894
|
+
validAfter: "0",
|
|
2895
|
+
validBefore: String(paymentInfo.preApprovalExpiry),
|
|
2896
|
+
nonce
|
|
2897
|
+
},
|
|
2898
|
+
signature,
|
|
2899
|
+
paymentInfo
|
|
2900
|
+
},
|
|
2901
|
+
paymentRequirements: {
|
|
2902
|
+
scheme: "escrow",
|
|
2903
|
+
network: `eip155:${cfg.chain_id}`
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2551
2907
|
|
|
2552
2908
|
// src/backend/index.ts
|
|
2553
2909
|
function parsePaymentHeader(headerValue) {
|
|
@@ -2741,9 +3097,15 @@ var FacilitatorClient = class {
|
|
|
2741
3097
|
};
|
|
2742
3098
|
}
|
|
2743
3099
|
const result = await response.json();
|
|
3100
|
+
const transactionHash = result.transaction ?? result.transactionHash ?? result.transaction_hash;
|
|
3101
|
+
if (result.success && !transactionHash) {
|
|
3102
|
+
console.warn(
|
|
3103
|
+
"[x402] settle reported success but carried no transaction hash under transaction/transactionHash/transaction_hash \u2014 treat delivery as unconfirmed"
|
|
3104
|
+
);
|
|
3105
|
+
}
|
|
2744
3106
|
return {
|
|
2745
3107
|
success: true,
|
|
2746
|
-
transactionHash
|
|
3108
|
+
transactionHash,
|
|
2747
3109
|
network: result.network
|
|
2748
3110
|
};
|
|
2749
3111
|
} catch (error) {
|
|
@@ -3309,11 +3671,14 @@ exports.DEFAULT_CHAIN = DEFAULT_CHAIN;
|
|
|
3309
3671
|
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
3310
3672
|
exports.DEFAULT_FACILITATOR_URL = DEFAULT_FACILITATOR_URL;
|
|
3311
3673
|
exports.DEFAULT_PAYMENT_HEADER = DEFAULT_PAYMENT_HEADER;
|
|
3674
|
+
exports.ESCROW_DEPOSIT_LIMIT_USD = ESCROW_DEPOSIT_LIMIT_USD;
|
|
3675
|
+
exports.ESCROW_TIER_WINDOWS = ESCROW_TIER_WINDOWS;
|
|
3312
3676
|
exports.EVENT_KINDS = EVENT_KINDS;
|
|
3313
3677
|
exports.EnvKeyAdapter = EnvKeyAdapter;
|
|
3314
3678
|
exports.FACILITATOR_ADDRESSES = FACILITATOR_ADDRESSES;
|
|
3315
3679
|
exports.FacilitatorClient = FacilitatorClient;
|
|
3316
3680
|
exports.KEEPALIVE_INTERVAL_MS = KEEPALIVE_INTERVAL_MS;
|
|
3681
|
+
exports.OPERATOR_FEE_BPS = OPERATOR_FEE_BPS;
|
|
3317
3682
|
exports.OWSWalletAdapter = OWSWalletAdapter;
|
|
3318
3683
|
exports.PAYMENT_HEADER_NAMES = PAYMENT_HEADER_NAMES;
|
|
3319
3684
|
exports.SSEParser = SSEParser;
|
|
@@ -3323,18 +3688,23 @@ exports.X402Client = X402Client;
|
|
|
3323
3688
|
exports.X402Error = X402Error;
|
|
3324
3689
|
exports.X402_CORS_HEADERS = X402_CORS_HEADERS;
|
|
3325
3690
|
exports.X402_HEADER_NAMES = X402_HEADER_NAMES;
|
|
3691
|
+
exports.buildEscrowPreAuth = buildEscrowPreAuth;
|
|
3326
3692
|
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
3327
3693
|
exports.buildSettleRequest = buildSettleRequest;
|
|
3328
3694
|
exports.buildSettleRequestV2 = buildSettleRequestV2;
|
|
3695
|
+
exports.buildSignatureBase = buildSignatureBase;
|
|
3696
|
+
exports.buildSignatureParams = buildSignatureParams;
|
|
3329
3697
|
exports.buildVerifyRequest = buildVerifyRequest;
|
|
3330
3698
|
exports.buildVerifyRequestV2 = buildVerifyRequestV2;
|
|
3331
3699
|
exports.caip2ToChain = caip2ToChain;
|
|
3332
3700
|
exports.chainToCAIP2 = chainToCAIP2;
|
|
3701
|
+
exports.computeEscrowNonce = computeEscrowNonce;
|
|
3333
3702
|
exports.convertX402Header = convertX402Header;
|
|
3334
3703
|
exports.create402Response = create402Response;
|
|
3335
3704
|
exports.createHonoMiddleware = createHonoMiddleware;
|
|
3336
3705
|
exports.createPaymentHeaders = createPaymentHeaders;
|
|
3337
3706
|
exports.createPaymentMiddleware = createPaymentMiddleware;
|
|
3707
|
+
exports.createSignedFetch = createSignedFetch;
|
|
3338
3708
|
exports.createX402Header = createX402Header;
|
|
3339
3709
|
exports.createX402V1Header = createX402V1Header;
|
|
3340
3710
|
exports.createX402V2Header = createX402V2Header;
|
|
@@ -3342,6 +3712,7 @@ exports.decodeX402Header = decodeX402Header;
|
|
|
3342
3712
|
exports.detectX402Version = detectX402Version;
|
|
3343
3713
|
exports.encodeX402Header = encodeX402Header;
|
|
3344
3714
|
exports.extractPaymentFromHeaders = extractPaymentFromHeaders;
|
|
3715
|
+
exports.fetchNonce = fetchNonce;
|
|
3345
3716
|
exports.generatePaymentOptions = generatePaymentOptions;
|
|
3346
3717
|
exports.getAlgorandChains = getAlgorandChains;
|
|
3347
3718
|
exports.getChainById = getChainById;
|
|
@@ -3371,6 +3742,9 @@ exports.isXRPLChain = isXRPLChain;
|
|
|
3371
3742
|
exports.matchesFilters = matchesFilters;
|
|
3372
3743
|
exports.parseNetworkIdentifier = parseNetworkIdentifier;
|
|
3373
3744
|
exports.parseTrafficEvent = parseTrafficEvent;
|
|
3745
|
+
exports.signRequest = signRequest;
|
|
3746
|
+
exports.signRequestWithSigner = signRequestWithSigner;
|
|
3747
|
+
exports.signRequestWithWallet = signRequestWithWallet;
|
|
3374
3748
|
exports.streamTrafficEvents = streamTrafficEvents;
|
|
3375
3749
|
exports.validateAmount = validateAmount;
|
|
3376
3750
|
exports.validateRecipient = validateRecipient;
|