@dexterai/x402 1.8.1 → 1.9.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/adapters/index.cjs +15 -3
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +5 -5
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/index.js +5 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/client/index.cjs +22 -9
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +6 -6
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +12 -9
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs +24 -11
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -4
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +14 -11
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +30 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +28 -18
- package/dist/server/index.js.map +1 -1
- package/dist/{solana-BeGAqPta.d.cts → solana-CfHuiW2H.d.cts} +2 -2
- package/dist/{solana-CQD9yMju.d.ts → solana-kZcwbUK9.d.ts} +2 -2
- package/dist/{types-DYLi7SuF.d.cts → types-BQvaF8lB.d.cts} +7 -5
- package/dist/{types-DYLi7SuF.d.ts → types-BQvaF8lB.d.ts} +7 -5
- package/dist/{types-B477nBpg.d.cts → types-DmqH9yD8.d.cts} +1 -1
- package/dist/{types-BWnUAPvD.d.ts → types-ENcnkof8.d.ts} +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/{x402-client-Dk9q2QQF.d.cts → x402-client-BDaOwfgE.d.cts} +2 -2
- package/dist/{x402-client-D9b3PHai.d.ts → x402-client-DIcp-PvX.d.ts} +2 -2
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/react/index.ts
|
|
@@ -139,7 +149,7 @@ var SolanaAdapter = class {
|
|
|
139
149
|
const connection = new import_web3.Connection(url, "confirmed");
|
|
140
150
|
const userPubkey = new import_web3.PublicKey(wallet.publicKey.toBase58());
|
|
141
151
|
const { payTo, asset, extra } = accept;
|
|
142
|
-
const amount = accept.amount
|
|
152
|
+
const amount = accept.amount ?? accept.maxAmountRequired;
|
|
143
153
|
if (!amount) {
|
|
144
154
|
throw new Error("Missing amount in payment requirements");
|
|
145
155
|
}
|
|
@@ -377,7 +387,7 @@ var EvmAdapter = class {
|
|
|
377
387
|
throw new Error("Wallet not connected");
|
|
378
388
|
}
|
|
379
389
|
const { payTo, asset, extra } = accept;
|
|
380
|
-
const amount = accept.amount
|
|
390
|
+
const amount = accept.amount ?? accept.maxAmountRequired;
|
|
381
391
|
if (!amount) {
|
|
382
392
|
throw new Error("Missing amount in payment requirements");
|
|
383
393
|
}
|
|
@@ -405,7 +415,9 @@ var EvmAdapter = class {
|
|
|
405
415
|
{ name: "nonce", type: "bytes32" }
|
|
406
416
|
]
|
|
407
417
|
};
|
|
408
|
-
const
|
|
418
|
+
const nonceBytes = new Uint8Array(32);
|
|
419
|
+
(globalThis.crypto ?? (await import("crypto")).webcrypto).getRandomValues(nonceBytes);
|
|
420
|
+
const nonce = "0x" + [...nonceBytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
409
421
|
const now = Math.floor(Date.now() / 1e3);
|
|
410
422
|
const authorization = {
|
|
411
423
|
from: wallet.address,
|
|
@@ -497,10 +509,11 @@ function createX402Client(config) {
|
|
|
497
509
|
const parts = jwt.split(".");
|
|
498
510
|
if (parts.length === 3) {
|
|
499
511
|
const payload = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
512
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
513
|
+
const maxExp = now + 86400;
|
|
514
|
+
const expiresAt = Math.min(typeof payload.exp === "number" ? payload.exp : now, maxExp);
|
|
515
|
+
passCache.set(host, { jwt, expiresAt });
|
|
516
|
+
log("Access pass cached for", host, "| expires:", new Date(expiresAt * 1e3).toISOString());
|
|
504
517
|
}
|
|
505
518
|
} catch {
|
|
506
519
|
log("Failed to cache access pass");
|
|
@@ -581,7 +594,7 @@ function createX402Client(config) {
|
|
|
581
594
|
if (adapter.name === "Solana" && !accept.extra?.feePayer) return null;
|
|
582
595
|
const decimals = accept.extra?.decimals ?? (isKnownUSDC(accept.asset) ? 6 : void 0);
|
|
583
596
|
if (typeof decimals !== "number") return null;
|
|
584
|
-
const paymentAmount = accept.amount
|
|
597
|
+
const paymentAmount = accept.amount ?? accept.maxAmountRequired;
|
|
585
598
|
if (!paymentAmount) return null;
|
|
586
599
|
const rpcUrl = getRpcUrl(accept.network, adapter);
|
|
587
600
|
const balance = await adapter.getBalance(accept, wallet, rpcUrl);
|
|
@@ -725,7 +738,7 @@ function createX402Client(config) {
|
|
|
725
738
|
"Payment option missing decimals - provide in extra or use a known stablecoin"
|
|
726
739
|
);
|
|
727
740
|
}
|
|
728
|
-
const paymentAmount = accept.amount
|
|
741
|
+
const paymentAmount = accept.amount ?? accept.maxAmountRequired;
|
|
729
742
|
if (!paymentAmount) {
|
|
730
743
|
throw new X402Error("missing_amount", "Payment option missing amount");
|
|
731
744
|
}
|
|
@@ -936,7 +949,7 @@ function useX402Payment(config) {
|
|
|
936
949
|
const accept = {
|
|
937
950
|
scheme: "exact",
|
|
938
951
|
network: SOLANA_MAINNET_NETWORK,
|
|
939
|
-
|
|
952
|
+
amount: "0",
|
|
940
953
|
asset: USDC_MINT,
|
|
941
954
|
payTo: "",
|
|
942
955
|
maxTimeoutSeconds: 60,
|
|
@@ -961,7 +974,7 @@ function useX402Payment(config) {
|
|
|
961
974
|
const accept = {
|
|
962
975
|
scheme: "exact",
|
|
963
976
|
network: BASE_MAINNET_NETWORK,
|
|
964
|
-
|
|
977
|
+
amount: "0",
|
|
965
978
|
asset: USDC_BASE,
|
|
966
979
|
payTo: "",
|
|
967
980
|
maxTimeoutSeconds: 60,
|