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.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-
|
|
2
|
-
export { d as WalletState } from '../index-
|
|
1
|
+
import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-DbauIMV2.mjs';
|
|
2
|
+
export { d as WalletState } from '../index-DbauIMV2.mjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
-
import { g as getChainByName, X as X402Client } from '../index-
|
|
5
|
+
import { g as getChainByName, X as X402Client } from '../index-DAC3DRdT.mjs';
|
|
6
6
|
export { FAMILY_LABEL, NetworkOption, NetworkPicker, NetworkPickerProps, SIGNABLE_IN_BROWSER, buildNetworkOptions, resolveChain } from './picker/index.mjs';
|
|
7
7
|
|
|
8
8
|
/** One entry of the `accepts` array of a 402 response. */
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-
|
|
2
|
-
export { d as WalletState } from '../index-
|
|
1
|
+
import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-DbauIMV2.js';
|
|
2
|
+
export { d as WalletState } from '../index-DbauIMV2.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
-
import { g as getChainByName, X as X402Client } from '../index-
|
|
5
|
+
import { g as getChainByName, X as X402Client } from '../index-DRSEcZ36.js';
|
|
6
6
|
export { FAMILY_LABEL, NetworkOption, NetworkPicker, NetworkPickerProps, SIGNABLE_IN_BROWSER, buildNetworkOptions, resolveChain } from './picker/index.js';
|
|
7
7
|
|
|
8
8
|
/** One entry of the `accepts` array of a 402 response. */
|
package/dist/react/index.js
CHANGED
|
@@ -1273,6 +1273,37 @@ var init_personal_sign = __esm({
|
|
|
1273
1273
|
}
|
|
1274
1274
|
});
|
|
1275
1275
|
|
|
1276
|
+
// src/utils/validity.ts
|
|
1277
|
+
function resolveValiditySeconds(perPayment, clientDefault) {
|
|
1278
|
+
const chosen = perPayment ?? clientDefault ?? DEFAULT_VALIDITY_SECONDS;
|
|
1279
|
+
if (!Number.isInteger(chosen) || chosen <= 0) {
|
|
1280
|
+
throw new X402Error(
|
|
1281
|
+
`validitySeconds must be a positive whole number of seconds, got ${String(chosen)}`,
|
|
1282
|
+
"INVALID_CONFIG",
|
|
1283
|
+
{ validitySeconds: chosen }
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
if (chosen > MAX_VALIDITY_SECONDS) {
|
|
1287
|
+
throw new X402Error(
|
|
1288
|
+
`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.`,
|
|
1289
|
+
"INVALID_CONFIG",
|
|
1290
|
+
{ validitySeconds: chosen, max: MAX_VALIDITY_SECONDS }
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
return chosen;
|
|
1294
|
+
}
|
|
1295
|
+
function clampValiditySeconds(maxTimeoutSeconds) {
|
|
1296
|
+
return Math.min(MAX_VALIDITY_SECONDS, Math.max(1, Math.floor(maxTimeoutSeconds)));
|
|
1297
|
+
}
|
|
1298
|
+
var DEFAULT_VALIDITY_SECONDS, MAX_VALIDITY_SECONDS;
|
|
1299
|
+
var init_validity = __esm({
|
|
1300
|
+
"src/utils/validity.ts"() {
|
|
1301
|
+
init_types();
|
|
1302
|
+
DEFAULT_VALIDITY_SECONDS = 300;
|
|
1303
|
+
MAX_VALIDITY_SECONDS = 3600;
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1276
1307
|
// src/utils/index.ts
|
|
1277
1308
|
var init_utils = __esm({
|
|
1278
1309
|
"src/utils/index.ts"() {
|
|
@@ -1281,6 +1312,7 @@ var init_utils = __esm({
|
|
|
1281
1312
|
init_base64();
|
|
1282
1313
|
init_validation();
|
|
1283
1314
|
init_personal_sign();
|
|
1315
|
+
init_validity();
|
|
1284
1316
|
}
|
|
1285
1317
|
});
|
|
1286
1318
|
|
|
@@ -2022,6 +2054,7 @@ var X402Client = class _X402Client {
|
|
|
2022
2054
|
*/
|
|
2023
2055
|
purchasePolicy;
|
|
2024
2056
|
constructor(config = {}) {
|
|
2057
|
+
resolveValiditySeconds(void 0, config.validitySeconds);
|
|
2025
2058
|
this.config = {
|
|
2026
2059
|
...DEFAULT_CONFIG,
|
|
2027
2060
|
...config
|
|
@@ -2349,7 +2382,8 @@ var X402Client = class _X402Client {
|
|
|
2349
2382
|
amount: ethers.ethers.formatUnits(chosen.amount, chosen.decimals),
|
|
2350
2383
|
tokenType,
|
|
2351
2384
|
network: chosen.chainName,
|
|
2352
|
-
x402Version: version
|
|
2385
|
+
x402Version: version,
|
|
2386
|
+
validitySeconds: chosen.maxTimeoutSeconds !== void 0 ? clampValiditySeconds(chosen.maxTimeoutSeconds) : void 0
|
|
2353
2387
|
});
|
|
2354
2388
|
const paidHeaders = {
|
|
2355
2389
|
..._X402Client.headersToRecord(options.init?.headers),
|
|
@@ -2423,6 +2457,7 @@ var X402Client = class _X402Client {
|
|
|
2423
2457
|
continue;
|
|
2424
2458
|
}
|
|
2425
2459
|
const chainName = getChainByName(network) ? network : caip2ToChain(network);
|
|
2460
|
+
const declaredTimeout = typeof accept.maxTimeoutSeconds === "number" && Number.isFinite(accept.maxTimeoutSeconds) ? accept.maxTimeoutSeconds : void 0;
|
|
2426
2461
|
offers.push({
|
|
2427
2462
|
network,
|
|
2428
2463
|
chainName,
|
|
@@ -2430,6 +2465,7 @@ var X402Client = class _X402Client {
|
|
|
2430
2465
|
amount: String(amount),
|
|
2431
2466
|
decimals: _X402Client.offerDecimals(chainName, tokenType),
|
|
2432
2467
|
payTo,
|
|
2468
|
+
...declaredTimeout !== void 0 ? { maxTimeoutSeconds: declaredTimeout } : {},
|
|
2433
2469
|
raw: accept
|
|
2434
2470
|
});
|
|
2435
2471
|
}
|
|
@@ -2729,7 +2765,10 @@ var X402Client = class _X402Client {
|
|
|
2729
2765
|
}
|
|
2730
2766
|
const nonce = ethers.ethers.hexlify(nonceBytes);
|
|
2731
2767
|
const validAfter = 0;
|
|
2732
|
-
const validityWindowSeconds =
|
|
2768
|
+
const validityWindowSeconds = resolveValiditySeconds(
|
|
2769
|
+
paymentInfo.validitySeconds,
|
|
2770
|
+
this.config.validitySeconds
|
|
2771
|
+
);
|
|
2733
2772
|
const validBefore = Math.floor(Date.now() / 1e3) + validityWindowSeconds;
|
|
2734
2773
|
const domain = {
|
|
2735
2774
|
name: token.name,
|
|
@@ -3251,13 +3290,13 @@ function useBalance() {
|
|
|
3251
3290
|
};
|
|
3252
3291
|
}
|
|
3253
3292
|
function usePayment() {
|
|
3254
|
-
const { client
|
|
3293
|
+
const { client } = useX402();
|
|
3255
3294
|
const [isPaying, setIsPaying] = react.useState(false);
|
|
3256
3295
|
const [error, setError] = react.useState(null);
|
|
3257
3296
|
const [lastResult, setLastResult] = react.useState(null);
|
|
3258
3297
|
const pay = react.useCallback(
|
|
3259
3298
|
async (paymentInfo) => {
|
|
3260
|
-
if (!
|
|
3299
|
+
if (!client.getState().connected) {
|
|
3261
3300
|
throw new Error("Wallet not connected");
|
|
3262
3301
|
}
|
|
3263
3302
|
setIsPaying(true);
|
|
@@ -3274,7 +3313,7 @@ function usePayment() {
|
|
|
3274
3313
|
setIsPaying(false);
|
|
3275
3314
|
}
|
|
3276
3315
|
},
|
|
3277
|
-
[client
|
|
3316
|
+
[client]
|
|
3278
3317
|
);
|
|
3279
3318
|
const reset = react.useCallback(() => {
|
|
3280
3319
|
setError(null);
|