uvd-x402-sdk 2.89.0 → 2.91.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 +32 -0
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/backend/index.d.mts +2 -2
- package/dist/backend/index.d.ts +2 -2
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs.map +1 -1
- package/dist/erc8128/index.js.map +1 -1
- package/dist/erc8128/index.mjs.map +1 -1
- package/dist/{index-13ZUDF7c.d.mts → index-DAC3DRdT.d.mts} +1 -1
- package/dist/{index-B5B9EK3x.d.ts → index-DRSEcZ36.d.ts} +1 -1
- package/dist/{index-CAJg-_cr.d.mts → index-DRk6i654.d.mts} +1 -1
- package/dist/{index-BWN0Haa0.d.mts → index-DbauIMV2.d.mts} +41 -0
- package/dist/{index-BWN0Haa0.d.ts → index-DbauIMV2.d.ts} +41 -0
- package/dist/{index-Cd1Mpznb.d.ts → index-s6ot_Mu-.d.ts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +43 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -3
- package/dist/index.mjs.map +1 -1
- package/dist/providers/algorand/index.d.mts +1 -1
- package/dist/providers/algorand/index.d.ts +1 -1
- package/dist/providers/algorand/index.js.map +1 -1
- package/dist/providers/algorand/index.mjs.map +1 -1
- package/dist/providers/evm/index.d.mts +1 -1
- package/dist/providers/evm/index.d.ts +1 -1
- package/dist/providers/evm/index.js +23 -1
- package/dist/providers/evm/index.js.map +1 -1
- package/dist/providers/evm/index.mjs +23 -1
- package/dist/providers/evm/index.mjs.map +1 -1
- package/dist/providers/near/index.d.mts +1 -1
- package/dist/providers/near/index.d.ts +1 -1
- package/dist/providers/near/index.js.map +1 -1
- package/dist/providers/near/index.mjs.map +1 -1
- package/dist/providers/solana/index.d.mts +1 -1
- package/dist/providers/solana/index.d.ts +1 -1
- package/dist/providers/solana/index.js.map +1 -1
- package/dist/providers/solana/index.mjs.map +1 -1
- package/dist/providers/stellar/index.d.mts +1 -1
- package/dist/providers/stellar/index.d.ts +1 -1
- package/dist/providers/stellar/index.js.map +1 -1
- package/dist/providers/stellar/index.mjs.map +1 -1
- package/dist/providers/sui/index.d.mts +1 -1
- package/dist/providers/sui/index.d.ts +1 -1
- package/dist/providers/sui/index.js.map +1 -1
- package/dist/providers/sui/index.mjs.map +1 -1
- package/dist/providers/xrpl/index.d.mts +1 -1
- package/dist/providers/xrpl/index.d.ts +1 -1
- package/dist/providers/xrpl/index.js.map +1 -1
- package/dist/providers/xrpl/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +44 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +44 -5
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/picker/index.d.mts +1 -1
- package/dist/react/picker/index.d.ts +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +29 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +26 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/{validation-B95g0MqC.d.mts → validity-BTMBMmuj.d.mts} +101 -2
- package/dist/{validation-_Tcjm2gu.d.ts → validity-C0z0GqH6.d.ts} +101 -2
- package/package.json +1 -1
- package/src/client/X402Client.ts +32 -2
- package/src/index.ts +5 -0
- package/src/providers/evm/index.ts +4 -2
- package/src/react/index.tsx +8 -3
- package/src/types/index.ts +41 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/validity.ts +135 -0
package/dist/react/index.mjs
CHANGED
|
@@ -1271,6 +1271,37 @@ var init_personal_sign = __esm({
|
|
|
1271
1271
|
}
|
|
1272
1272
|
});
|
|
1273
1273
|
|
|
1274
|
+
// src/utils/validity.ts
|
|
1275
|
+
function resolveValiditySeconds(perPayment, clientDefault) {
|
|
1276
|
+
const chosen = perPayment ?? clientDefault ?? DEFAULT_VALIDITY_SECONDS;
|
|
1277
|
+
if (!Number.isInteger(chosen) || chosen <= 0) {
|
|
1278
|
+
throw new X402Error(
|
|
1279
|
+
`validitySeconds must be a positive whole number of seconds, got ${String(chosen)}`,
|
|
1280
|
+
"INVALID_CONFIG",
|
|
1281
|
+
{ validitySeconds: chosen }
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
if (chosen > MAX_VALIDITY_SECONDS) {
|
|
1285
|
+
throw new X402Error(
|
|
1286
|
+
`validitySeconds must be at most ${MAX_VALIDITY_SECONDS} seconds, got ${String(chosen)}. A longer window is a standing claim on the payer: it can be settled long after the payer gave the payment up for expired.`,
|
|
1287
|
+
"INVALID_CONFIG",
|
|
1288
|
+
{ validitySeconds: chosen, max: MAX_VALIDITY_SECONDS }
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
return chosen;
|
|
1292
|
+
}
|
|
1293
|
+
function clampValiditySeconds(maxTimeoutSeconds) {
|
|
1294
|
+
return Math.min(MAX_VALIDITY_SECONDS, Math.max(1, Math.floor(maxTimeoutSeconds)));
|
|
1295
|
+
}
|
|
1296
|
+
var DEFAULT_VALIDITY_SECONDS, MAX_VALIDITY_SECONDS;
|
|
1297
|
+
var init_validity = __esm({
|
|
1298
|
+
"src/utils/validity.ts"() {
|
|
1299
|
+
init_types();
|
|
1300
|
+
DEFAULT_VALIDITY_SECONDS = 300;
|
|
1301
|
+
MAX_VALIDITY_SECONDS = 3600;
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1274
1305
|
// src/utils/index.ts
|
|
1275
1306
|
var init_utils = __esm({
|
|
1276
1307
|
"src/utils/index.ts"() {
|
|
@@ -1279,6 +1310,7 @@ var init_utils = __esm({
|
|
|
1279
1310
|
init_base64();
|
|
1280
1311
|
init_validation();
|
|
1281
1312
|
init_personal_sign();
|
|
1313
|
+
init_validity();
|
|
1282
1314
|
}
|
|
1283
1315
|
});
|
|
1284
1316
|
|
|
@@ -2020,6 +2052,7 @@ var X402Client = class _X402Client {
|
|
|
2020
2052
|
*/
|
|
2021
2053
|
purchasePolicy;
|
|
2022
2054
|
constructor(config = {}) {
|
|
2055
|
+
resolveValiditySeconds(void 0, config.validitySeconds);
|
|
2023
2056
|
this.config = {
|
|
2024
2057
|
...DEFAULT_CONFIG,
|
|
2025
2058
|
...config
|
|
@@ -2347,7 +2380,8 @@ var X402Client = class _X402Client {
|
|
|
2347
2380
|
amount: ethers.formatUnits(chosen.amount, chosen.decimals),
|
|
2348
2381
|
tokenType,
|
|
2349
2382
|
network: chosen.chainName,
|
|
2350
|
-
x402Version: version
|
|
2383
|
+
x402Version: version,
|
|
2384
|
+
validitySeconds: chosen.maxTimeoutSeconds !== void 0 ? clampValiditySeconds(chosen.maxTimeoutSeconds) : void 0
|
|
2351
2385
|
});
|
|
2352
2386
|
const paidHeaders = {
|
|
2353
2387
|
..._X402Client.headersToRecord(options.init?.headers),
|
|
@@ -2421,6 +2455,7 @@ var X402Client = class _X402Client {
|
|
|
2421
2455
|
continue;
|
|
2422
2456
|
}
|
|
2423
2457
|
const chainName = getChainByName(network) ? network : caip2ToChain(network);
|
|
2458
|
+
const declaredTimeout = typeof accept.maxTimeoutSeconds === "number" && Number.isFinite(accept.maxTimeoutSeconds) ? accept.maxTimeoutSeconds : void 0;
|
|
2424
2459
|
offers.push({
|
|
2425
2460
|
network,
|
|
2426
2461
|
chainName,
|
|
@@ -2428,6 +2463,7 @@ var X402Client = class _X402Client {
|
|
|
2428
2463
|
amount: String(amount),
|
|
2429
2464
|
decimals: _X402Client.offerDecimals(chainName, tokenType),
|
|
2430
2465
|
payTo,
|
|
2466
|
+
...declaredTimeout !== void 0 ? { maxTimeoutSeconds: declaredTimeout } : {},
|
|
2431
2467
|
raw: accept
|
|
2432
2468
|
});
|
|
2433
2469
|
}
|
|
@@ -2727,7 +2763,10 @@ var X402Client = class _X402Client {
|
|
|
2727
2763
|
}
|
|
2728
2764
|
const nonce = ethers.hexlify(nonceBytes);
|
|
2729
2765
|
const validAfter = 0;
|
|
2730
|
-
const validityWindowSeconds =
|
|
2766
|
+
const validityWindowSeconds = resolveValiditySeconds(
|
|
2767
|
+
paymentInfo.validitySeconds,
|
|
2768
|
+
this.config.validitySeconds
|
|
2769
|
+
);
|
|
2731
2770
|
const validBefore = Math.floor(Date.now() / 1e3) + validityWindowSeconds;
|
|
2732
2771
|
const domain = {
|
|
2733
2772
|
name: token.name,
|
|
@@ -3249,13 +3288,13 @@ function useBalance() {
|
|
|
3249
3288
|
};
|
|
3250
3289
|
}
|
|
3251
3290
|
function usePayment() {
|
|
3252
|
-
const { client
|
|
3291
|
+
const { client } = useX402();
|
|
3253
3292
|
const [isPaying, setIsPaying] = useState(false);
|
|
3254
3293
|
const [error, setError] = useState(null);
|
|
3255
3294
|
const [lastResult, setLastResult] = useState(null);
|
|
3256
3295
|
const pay = useCallback(
|
|
3257
3296
|
async (paymentInfo) => {
|
|
3258
|
-
if (!
|
|
3297
|
+
if (!client.getState().connected) {
|
|
3259
3298
|
throw new Error("Wallet not connected");
|
|
3260
3299
|
}
|
|
3261
3300
|
setIsPaying(true);
|
|
@@ -3272,7 +3311,7 @@ function usePayment() {
|
|
|
3272
3311
|
setIsPaying(false);
|
|
3273
3312
|
}
|
|
3274
3313
|
},
|
|
3275
|
-
[client
|
|
3314
|
+
[client]
|
|
3276
3315
|
);
|
|
3277
3316
|
const reset = useCallback(() => {
|
|
3278
3317
|
setError(null);
|