thirdweb 5.106.0 → 5.107.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/cjs/exports/x402.js +8 -0
- package/dist/cjs/exports/x402.js.map +1 -0
- package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +1 -1
- package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js +1 -1
- package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js +1 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js +10 -3
- package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/smart/lib/bundler.js +3 -0
- package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/cjs/x402/facilitator.js +76 -0
- package/dist/cjs/x402/facilitator.js.map +1 -0
- package/dist/cjs/x402/fetchWithPayment.js +121 -0
- package/dist/cjs/x402/fetchWithPayment.js.map +1 -0
- package/dist/esm/exports/x402.js +3 -0
- package/dist/esm/exports/x402.js.map +1 -0
- package/dist/esm/react/web/ui/Bridge/BuyWidget.js +1 -1
- package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js +1 -1
- package/dist/esm/react/web/ui/Bridge/TransactionWidget.js +1 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js +10 -3
- package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/smart/lib/bundler.js +3 -0
- package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/esm/x402/facilitator.js +73 -0
- package/dist/esm/x402/facilitator.js.map +1 -0
- package/dist/esm/x402/fetchWithPayment.js +118 -0
- package/dist/esm/x402/fetchWithPayment.js.map +1 -0
- package/dist/types/exports/x402.d.ts +3 -0
- package/dist/types/exports/x402.d.ts.map +1 -0
- package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +1 -1
- package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts +1 -1
- package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts +1 -1
- package/dist/types/react/web/ui/Bridge/swap-widget/SwapWidget.d.ts +8 -0
- package/dist/types/react/web/ui/Bridge/swap-widget/SwapWidget.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
- package/dist/types/x402/facilitator.d.ts +48 -0
- package/dist/types/x402/facilitator.d.ts.map +1 -0
- package/dist/types/x402/fetchWithPayment.d.ts +43 -0
- package/dist/types/x402/fetchWithPayment.d.ts.map +1 -0
- package/package.json +12 -3
- package/src/exports/x402.ts +5 -0
- package/src/react/web/ui/Bridge/BuyWidget.tsx +1 -1
- package/src/react/web/ui/Bridge/CheckoutWidget.tsx +1 -1
- package/src/react/web/ui/Bridge/TransactionWidget.tsx +1 -1
- package/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx +24 -3
- package/src/version.ts +1 -1
- package/src/wallets/smart/lib/bundler.ts +4 -0
- package/src/x402/facilitator.ts +87 -0
- package/src/x402/fetchWithPayment.ts +173 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facilitator.js","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AAUA,MAAM,gBAAgB,GAAG,2CAA2C,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAqC;IAErC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;IAC1C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC;IACvD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAA4B;QACpE,iBAAiB,EAAE,KAAK,IAAI,EAAE;YAC5B,OAAO;gBACL,MAAM,EAAE;oBACN,cAAc,EAAE,SAAS;iBAC1B;gBACD,MAAM,EAAE;oBACN,cAAc,EAAE,SAAS;oBACzB,6BAA6B,EAAE,mBAAmB;oBAClD,GAAG,CAAC,MAAM,CAAC,gBAAgB;wBACzB,CAAC,CAAC,EAAE,sBAAsB,EAAE,MAAM,CAAC,gBAAgB,EAAE;wBACrD,CAAC,CAAC,EAAE,CAAC;iBACR;gBACD,SAAS,EAAE;oBACT,cAAc,EAAE,SAAS;iBAC1B;gBACD,IAAI,EAAE;oBACJ,cAAc,EAAE,SAAS;iBAC1B;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createPaymentHeader } from "x402/client";
|
|
2
|
+
import { ChainIdToNetwork, EvmNetworkToChainId, PaymentRequirementsSchema, } from "x402/types";
|
|
3
|
+
import { viemAdapter } from "../adapters/viem.js";
|
|
4
|
+
import { getCachedChain } from "../chains/utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Enables the payment of APIs using the x402 payment protocol.
|
|
7
|
+
*
|
|
8
|
+
* This function wraps the native fetch API to automatically handle 402 Payment Required responses
|
|
9
|
+
* by creating and sending a payment header. It will:
|
|
10
|
+
* 1. Make the initial request
|
|
11
|
+
* 2. If a 402 response is received, parse the payment requirements
|
|
12
|
+
* 3. Verify the payment amount is within the allowed maximum
|
|
13
|
+
* 4. Create a payment header using the provided wallet client
|
|
14
|
+
* 5. Retry the request with the payment header
|
|
15
|
+
*
|
|
16
|
+
* @param fetch - The fetch function to wrap (typically globalThis.fetch)
|
|
17
|
+
* @param client - The thirdweb client used to access RPC infrastructure
|
|
18
|
+
* @param wallet - The wallet used to sign payment messages
|
|
19
|
+
* @param maxValue - The maximum allowed payment amount in base units (defaults to 1 USDC)
|
|
20
|
+
* @returns A wrapped fetch function that handles 402 responses automatically
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { wrapFetchWithPayment } from "thirdweb/x402";
|
|
25
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
26
|
+
* import { createWallet } from "thirdweb/wallets";
|
|
27
|
+
*
|
|
28
|
+
* const client = createThirdwebClient({ clientId: "your-client-id" });
|
|
29
|
+
* const wallet = createWallet("io.metamask");
|
|
30
|
+
* await wallet.connect({ client })
|
|
31
|
+
*
|
|
32
|
+
* const fetchWithPay = wrapFetchWithPayment(fetch, client, wallet);
|
|
33
|
+
*
|
|
34
|
+
* // Make a request that may require payment
|
|
35
|
+
* const response = await fetchWithPay('https://api.example.com/paid-endpoint');
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} If the payment amount exceeds the maximum allowed value
|
|
39
|
+
* @throws {Error} If a payment has already been attempted for this request
|
|
40
|
+
* @throws {Error} If there's an error creating the payment header
|
|
41
|
+
*
|
|
42
|
+
* @bridge x402
|
|
43
|
+
*/
|
|
44
|
+
export function wrapFetchWithPayment(fetch, client, wallet, maxValue = BigInt(1 * 10 ** 6)) {
|
|
45
|
+
return async (input, init) => {
|
|
46
|
+
const response = await fetch(input, init);
|
|
47
|
+
if (response.status !== 402) {
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
const { x402Version, accepts } = (await response.json());
|
|
51
|
+
const parsedPaymentRequirements = accepts
|
|
52
|
+
.map((x) => PaymentRequirementsSchema.parse(x))
|
|
53
|
+
.filter((x) => x.scheme === "exact"); // TODO (402): accept other schemes
|
|
54
|
+
const account = wallet.getAccount();
|
|
55
|
+
let chain = wallet.getChain();
|
|
56
|
+
if (!account || !chain) {
|
|
57
|
+
throw new Error("Wallet not connected. Please connect your wallet to continue.");
|
|
58
|
+
}
|
|
59
|
+
const selectedPaymentRequirements = defaultPaymentRequirementsSelector(parsedPaymentRequirements, chain.id, "exact");
|
|
60
|
+
if (BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue) {
|
|
61
|
+
throw new Error("Payment amount exceeds maximum allowed");
|
|
62
|
+
}
|
|
63
|
+
const paymentChainId = EvmNetworkToChainId.get(selectedPaymentRequirements.network);
|
|
64
|
+
if (!paymentChainId) {
|
|
65
|
+
throw new Error(`No chain found for the selected payment requirement: ${selectedPaymentRequirements.network}`);
|
|
66
|
+
}
|
|
67
|
+
// switch to the payment chain if it's not the current chain
|
|
68
|
+
if (paymentChainId !== chain.id) {
|
|
69
|
+
await wallet.switchChain(getCachedChain(paymentChainId));
|
|
70
|
+
chain = wallet.getChain();
|
|
71
|
+
if (!chain) {
|
|
72
|
+
throw new Error(`Failed to switch chain (${paymentChainId})`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const walletClient = viemAdapter.wallet.toViem({
|
|
76
|
+
wallet: wallet,
|
|
77
|
+
chain,
|
|
78
|
+
client,
|
|
79
|
+
});
|
|
80
|
+
const paymentHeader = await createPaymentHeader(walletClient, x402Version, selectedPaymentRequirements);
|
|
81
|
+
const initParams = init || {};
|
|
82
|
+
if (initParams.__is402Retry) {
|
|
83
|
+
throw new Error("Payment already attempted");
|
|
84
|
+
}
|
|
85
|
+
const newInit = {
|
|
86
|
+
...initParams,
|
|
87
|
+
headers: {
|
|
88
|
+
...(initParams.headers || {}),
|
|
89
|
+
"X-PAYMENT": paymentHeader,
|
|
90
|
+
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE",
|
|
91
|
+
},
|
|
92
|
+
__is402Retry: true,
|
|
93
|
+
};
|
|
94
|
+
const secondResponse = await fetch(input, newInit);
|
|
95
|
+
return secondResponse;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function defaultPaymentRequirementsSelector(paymentRequirements, chainId, scheme) {
|
|
99
|
+
if (!paymentRequirements.length) {
|
|
100
|
+
throw new Error("No valid payment requirements found in server 402 response");
|
|
101
|
+
}
|
|
102
|
+
const currentWalletNetwork = ChainIdToNetwork[chainId];
|
|
103
|
+
// find the payment requirements matching the connected wallet chain
|
|
104
|
+
const matchingPaymentRequirements = paymentRequirements.find((x) => x.network === currentWalletNetwork && x.scheme === scheme);
|
|
105
|
+
if (matchingPaymentRequirements) {
|
|
106
|
+
return matchingPaymentRequirements;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// if no matching payment requirements, use the first payment requirement
|
|
110
|
+
// and switch the wallet to that chain
|
|
111
|
+
const firstPaymentRequirement = paymentRequirements.find((x) => x.scheme === scheme);
|
|
112
|
+
if (!firstPaymentRequirement) {
|
|
113
|
+
throw new Error("No suitable payment requirements found");
|
|
114
|
+
}
|
|
115
|
+
return firstPaymentRequirement;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=fetchWithPayment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchWithPayment.js","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEnB,yBAAyB,GAE1B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAA8B,EAC9B,MAAsB,EACtB,MAAc,EACd,WAAmB,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEtC,OAAO,KAAK,EAAE,KAAkB,EAAE,IAAkB,EAAE,EAAE;QACtD,MAAM,QAAQ,GAAG,MAAM,K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AAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,oBAAoB,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CACjE,CAAC;IAEF,IAAI,2BAA2B,EAAE,CAAC;QAChC,OAAO,2BAA2B,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,yEAAyE;QACzE,sCAAsC;QACtC,MAAM,uBAAuB,GAAG,mBAAmB,CAAC,IAAI,CACtD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAC3B,CAAC;QACF,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,uBAAuB,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../../src/exports/x402.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,6BAA6B,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -264,7 +264,7 @@ export type BuyWidgetProps = {
|
|
|
264
264
|
*
|
|
265
265
|
* Refer to the [`BuyWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/BuyWidgetConnectOptions) type for more details.
|
|
266
266
|
*
|
|
267
|
-
* @bridge
|
|
267
|
+
* @bridge
|
|
268
268
|
*/
|
|
269
269
|
export declare function BuyWidget(props: BuyWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
270
270
|
/**
|
|
@@ -260,7 +260,7 @@ export type CheckoutWidgetProps = {
|
|
|
260
260
|
*
|
|
261
261
|
* Refer to the [`CheckoutWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/CheckoutWidgetConnectOptions) type for more details.
|
|
262
262
|
*
|
|
263
|
-
* @bridge
|
|
263
|
+
* @bridge
|
|
264
264
|
*/
|
|
265
265
|
export declare function CheckoutWidget(props: CheckoutWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
266
266
|
/**
|
|
@@ -265,7 +265,7 @@ export type TransactionWidgetProps = {
|
|
|
265
265
|
*
|
|
266
266
|
* Refer to the [`TransactionWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/TransactionWidgetConnectOptions) type for more details.
|
|
267
267
|
*
|
|
268
|
-
* @bridge
|
|
268
|
+
* @bridge
|
|
269
269
|
*/
|
|
270
270
|
export declare function TransactionWidget(props: TransactionWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
271
271
|
/**
|
|
@@ -128,6 +128,13 @@ export type SwapWidgetProps = {
|
|
|
128
128
|
onCancel?: (quote: SwapPreparedQuote) => void;
|
|
129
129
|
style?: React.CSSProperties;
|
|
130
130
|
className?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to persist the token selections to localStorage so that if the user revisits the widget, the last used tokens are pre-selected.
|
|
133
|
+
* The last used tokens do not override the tokens specified in the `prefill` prop
|
|
134
|
+
*
|
|
135
|
+
* @default true
|
|
136
|
+
*/
|
|
137
|
+
persistTokenSelections?: boolean;
|
|
131
138
|
};
|
|
132
139
|
/**
|
|
133
140
|
* A widget for swapping tokens with cross-chain support
|
|
@@ -199,6 +206,7 @@ export type SwapWidgetProps = {
|
|
|
199
206
|
* }} />
|
|
200
207
|
* ```
|
|
201
208
|
*
|
|
209
|
+
* @bridge
|
|
202
210
|
*/
|
|
203
211
|
export declare function SwapWidget(props: SwapWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
204
212
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapWidget.d.ts","sourceRoot":"","sources":["../../../../../../../src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,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D;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC9C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CAUhD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,SAAS,CAAC;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAcA"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.107.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../../../../../src/wallets/smart/lib/bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAKhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kFAAkF,CAAC;AAC7H,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAC;AACjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAC7F,OAAO,KAAK,EAAE,kBAAkB,EAAE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epC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FacilitatorConfig } from "x402/types";
|
|
2
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
3
|
+
export type ThirdwebX402FacilitatorConfig = {
|
|
4
|
+
client: ThirdwebClient;
|
|
5
|
+
serverWalletAddress: string;
|
|
6
|
+
vaultAccessToken?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates a facilitator for the x402 payment protocol.
|
|
11
|
+
* Use this with any x402 middleware to enable settling transactions with your thirdweb server wallet.
|
|
12
|
+
*
|
|
13
|
+
* @param config - The configuration for the facilitator
|
|
14
|
+
* @returns a x402 compatible FacilitatorConfig
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { facilitator } from "thirdweb/x402";
|
|
19
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
20
|
+
*
|
|
21
|
+
* const client = createThirdwebClient({
|
|
22
|
+
* secretKey: "your-secret-key",
|
|
23
|
+
* });
|
|
24
|
+
* const thirdwebX402Facilitator = facilitator({
|
|
25
|
+
* client: client,
|
|
26
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // add the facilitator to any x402 payment middleware
|
|
30
|
+
* const middleware = paymentMiddleware(
|
|
31
|
+
* "0x1234567890123456789012345678901234567890",
|
|
32
|
+
* {
|
|
33
|
+
* "/api/paywall": {
|
|
34
|
+
* price: "$0.01",
|
|
35
|
+
* network: "base-sepolia",
|
|
36
|
+
* config: {
|
|
37
|
+
* description: "Access to paid content",
|
|
38
|
+
* },
|
|
39
|
+
* },
|
|
40
|
+
* },
|
|
41
|
+
* thirdwebX402Facilitator,
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @bridge x402
|
|
46
|
+
*/
|
|
47
|
+
export declare function facilitator(config: ThirdwebX402FacilitatorConfig): FacilitatorConfig;
|
|
48
|
+
//# sourceMappingURL=facilitator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,cAAc,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,6BAA6B,GACpC,iBAAiB,CAkCnB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
2
|
+
import type { Wallet } from "../wallets/interfaces/wallet.js";
|
|
3
|
+
/**
|
|
4
|
+
* Enables the payment of APIs using the x402 payment protocol.
|
|
5
|
+
*
|
|
6
|
+
* This function wraps the native fetch API to automatically handle 402 Payment Required responses
|
|
7
|
+
* by creating and sending a payment header. It will:
|
|
8
|
+
* 1. Make the initial request
|
|
9
|
+
* 2. If a 402 response is received, parse the payment requirements
|
|
10
|
+
* 3. Verify the payment amount is within the allowed maximum
|
|
11
|
+
* 4. Create a payment header using the provided wallet client
|
|
12
|
+
* 5. Retry the request with the payment header
|
|
13
|
+
*
|
|
14
|
+
* @param fetch - The fetch function to wrap (typically globalThis.fetch)
|
|
15
|
+
* @param client - The thirdweb client used to access RPC infrastructure
|
|
16
|
+
* @param wallet - The wallet used to sign payment messages
|
|
17
|
+
* @param maxValue - The maximum allowed payment amount in base units (defaults to 1 USDC)
|
|
18
|
+
* @returns A wrapped fetch function that handles 402 responses automatically
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { wrapFetchWithPayment } from "thirdweb/x402";
|
|
23
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
24
|
+
* import { createWallet } from "thirdweb/wallets";
|
|
25
|
+
*
|
|
26
|
+
* const client = createThirdwebClient({ clientId: "your-client-id" });
|
|
27
|
+
* const wallet = createWallet("io.metamask");
|
|
28
|
+
* await wallet.connect({ client })
|
|
29
|
+
*
|
|
30
|
+
* const fetchWithPay = wrapFetchWithPayment(fetch, client, wallet);
|
|
31
|
+
*
|
|
32
|
+
* // Make a request that may require payment
|
|
33
|
+
* const response = await fetchWithPay('https://api.example.com/paid-endpoint');
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @throws {Error} If the payment amount exceeds the maximum allowed value
|
|
37
|
+
* @throws {Error} If a payment has already been attempted for this request
|
|
38
|
+
* @throws {Error} If there's an error creating the payment header
|
|
39
|
+
*
|
|
40
|
+
* @bridge x402
|
|
41
|
+
*/
|
|
42
|
+
export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, maxValue?: bigint): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
43
|
+
//# sourceMappingURL=fetchWithPayment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAA4B,IAExB,OAAO,WAAW,EAAE,OAAO,WAAW,uBAmFrD"}
|
package/package.json
CHANGED
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
"toml": "3.0.0",
|
|
39
39
|
"uqr": "0.1.2",
|
|
40
40
|
"viem": "2.33.2",
|
|
41
|
+
"x402": "0.6.1",
|
|
41
42
|
"zod": "3.25.75",
|
|
42
|
-
"@thirdweb-dev/
|
|
43
|
-
"@thirdweb-dev/
|
|
43
|
+
"@thirdweb-dev/insight": "1.1.1",
|
|
44
|
+
"@thirdweb-dev/engine": "3.2.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@aws-sdk/client-kms": "3.592.0",
|
|
@@ -226,6 +227,11 @@
|
|
|
226
227
|
"react-native": "./dist/esm/exports/wallets/in-app.native.js",
|
|
227
228
|
"import": "./dist/esm/exports/wallets/in-app.js",
|
|
228
229
|
"default": "./dist/cjs/exports/wallets/in-app.js"
|
|
230
|
+
},
|
|
231
|
+
"./x402": {
|
|
232
|
+
"types": "./dist/types/exports/x402.d.ts",
|
|
233
|
+
"import": "./dist/esm/exports/x402.js",
|
|
234
|
+
"default": "./dist/cjs/exports/x402.js"
|
|
229
235
|
}
|
|
230
236
|
},
|
|
231
237
|
"files": [
|
|
@@ -384,11 +390,14 @@
|
|
|
384
390
|
],
|
|
385
391
|
"insight": [
|
|
386
392
|
"./dist/types/exports/insight.d.ts"
|
|
393
|
+
],
|
|
394
|
+
"x402": [
|
|
395
|
+
"./dist/types/exports/x402.d.ts"
|
|
387
396
|
]
|
|
388
397
|
}
|
|
389
398
|
},
|
|
390
399
|
"typings": "./dist/types/exports/thirdweb.d.ts",
|
|
391
|
-
"version": "5.
|
|
400
|
+
"version": "5.107.0",
|
|
392
401
|
"scripts": {
|
|
393
402
|
"bench": "vitest -c ./test/vitest.config.ts bench",
|
|
394
403
|
"bench:compare": "bun run ./benchmarks/run.ts",
|
|
@@ -322,7 +322,7 @@ type UIOptionsResult =
|
|
|
322
322
|
*
|
|
323
323
|
* Refer to the [`BuyWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/BuyWidgetConnectOptions) type for more details.
|
|
324
324
|
*
|
|
325
|
-
* @bridge
|
|
325
|
+
* @bridge
|
|
326
326
|
*/
|
|
327
327
|
export function BuyWidget(props: BuyWidgetProps) {
|
|
328
328
|
const localeQuery = useConnectLocale(props.locale || "en_US");
|
|
@@ -318,7 +318,7 @@ type UIOptionsResult =
|
|
|
318
318
|
*
|
|
319
319
|
* Refer to the [`CheckoutWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/CheckoutWidgetConnectOptions) type for more details.
|
|
320
320
|
*
|
|
321
|
-
* @bridge
|
|
321
|
+
* @bridge
|
|
322
322
|
*/
|
|
323
323
|
export function CheckoutWidget(props: CheckoutWidgetProps) {
|
|
324
324
|
const localeQuery = useConnectLocale(props.locale || "en_US");
|
|
@@ -326,7 +326,7 @@ type UIOptionsResult =
|
|
|
326
326
|
*
|
|
327
327
|
* Refer to the [`TransactionWidgetConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/TransactionWidgetConnectOptions) type for more details.
|
|
328
328
|
*
|
|
329
|
-
* @bridge
|
|
329
|
+
* @bridge
|
|
330
330
|
*/
|
|
331
331
|
export function TransactionWidget(props: TransactionWidgetProps) {
|
|
332
332
|
const localeQuery = useConnectLocale(props.locale || "en_US");
|
|
@@ -154,6 +154,14 @@ export type SwapWidgetProps = {
|
|
|
154
154
|
onCancel?: (quote: SwapPreparedQuote) => void;
|
|
155
155
|
style?: React.CSSProperties;
|
|
156
156
|
className?: string;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Whether to persist the token selections to localStorage so that if the user revisits the widget, the last used tokens are pre-selected.
|
|
160
|
+
* The last used tokens do not override the tokens specified in the `prefill` prop
|
|
161
|
+
*
|
|
162
|
+
* @default true
|
|
163
|
+
*/
|
|
164
|
+
persistTokenSelections?: boolean;
|
|
157
165
|
};
|
|
158
166
|
|
|
159
167
|
/**
|
|
@@ -226,6 +234,7 @@ export type SwapWidgetProps = {
|
|
|
226
234
|
* }} />
|
|
227
235
|
* ```
|
|
228
236
|
*
|
|
237
|
+
* @bridge
|
|
229
238
|
*/
|
|
230
239
|
export function SwapWidget(props: SwapWidgetProps) {
|
|
231
240
|
return (
|
|
@@ -291,6 +300,7 @@ type SwapWidgetScreen =
|
|
|
291
300
|
function SwapWidgetContent(props: SwapWidgetProps) {
|
|
292
301
|
const [screen, setScreen] = useState<SwapWidgetScreen>({ id: "1:swap-ui" });
|
|
293
302
|
const activeWalletInfo = useActiveWalletInfo();
|
|
303
|
+
const isPersistEnabled = props.persistTokenSelections !== false;
|
|
294
304
|
|
|
295
305
|
const [amountSelection, setAmountSelection] = useState<{
|
|
296
306
|
type: "buy" | "sell";
|
|
@@ -323,6 +333,11 @@ function SwapWidgetContent(props: SwapWidgetProps) {
|
|
|
323
333
|
chainId: props.prefill.buyToken.chainId,
|
|
324
334
|
};
|
|
325
335
|
}
|
|
336
|
+
|
|
337
|
+
if (!isPersistEnabled) {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
|
|
326
341
|
const lastUsedBuyToken = getLastUsedTokens()?.buyToken;
|
|
327
342
|
|
|
328
343
|
// the token that will be set as initial value of sell token
|
|
@@ -346,13 +361,18 @@ function SwapWidgetContent(props: SwapWidgetProps) {
|
|
|
346
361
|
});
|
|
347
362
|
|
|
348
363
|
const [sellToken, setSellToken] = useState<TokenSelection | undefined>(() => {
|
|
349
|
-
return getInitialSellToken(
|
|
364
|
+
return getInitialSellToken(
|
|
365
|
+
props.prefill,
|
|
366
|
+
isPersistEnabled ? getLastUsedTokens()?.sellToken : undefined,
|
|
367
|
+
);
|
|
350
368
|
});
|
|
351
369
|
|
|
352
370
|
// persist selections to localStorage whenever they change
|
|
353
371
|
useEffect(() => {
|
|
354
|
-
|
|
355
|
-
|
|
372
|
+
if (isPersistEnabled) {
|
|
373
|
+
setLastUsedTokens({ buyToken, sellToken });
|
|
374
|
+
}
|
|
375
|
+
}, [buyToken, sellToken, isPersistEnabled]);
|
|
356
376
|
|
|
357
377
|
// preload requests
|
|
358
378
|
useBridgeChains(props.client);
|
|
@@ -524,5 +544,6 @@ function getInitialSellToken(
|
|
|
524
544
|
chainId: prefill.sellToken.chainId,
|
|
525
545
|
};
|
|
526
546
|
}
|
|
547
|
+
|
|
527
548
|
return lastUsedSellToken;
|
|
528
549
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.
|
|
1
|
+
export const version = "5.107.0";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { FacilitatorConfig } from "x402/types";
|
|
2
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
3
|
+
|
|
4
|
+
export type ThirdwebX402FacilitatorConfig = {
|
|
5
|
+
client: ThirdwebClient;
|
|
6
|
+
serverWalletAddress: string;
|
|
7
|
+
vaultAccessToken?: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a facilitator for the x402 payment protocol.
|
|
15
|
+
* Use this with any x402 middleware to enable settling transactions with your thirdweb server wallet.
|
|
16
|
+
*
|
|
17
|
+
* @param config - The configuration for the facilitator
|
|
18
|
+
* @returns a x402 compatible FacilitatorConfig
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { facilitator } from "thirdweb/x402";
|
|
23
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
24
|
+
*
|
|
25
|
+
* const client = createThirdwebClient({
|
|
26
|
+
* secretKey: "your-secret-key",
|
|
27
|
+
* });
|
|
28
|
+
* const thirdwebX402Facilitator = facilitator({
|
|
29
|
+
* client: client,
|
|
30
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // add the facilitator to any x402 payment middleware
|
|
34
|
+
* const middleware = paymentMiddleware(
|
|
35
|
+
* "0x1234567890123456789012345678901234567890",
|
|
36
|
+
* {
|
|
37
|
+
* "/api/paywall": {
|
|
38
|
+
* price: "$0.01",
|
|
39
|
+
* network: "base-sepolia",
|
|
40
|
+
* config: {
|
|
41
|
+
* description: "Access to paid content",
|
|
42
|
+
* },
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* thirdwebX402Facilitator,
|
|
46
|
+
* );
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @bridge x402
|
|
50
|
+
*/
|
|
51
|
+
export function facilitator(
|
|
52
|
+
config: ThirdwebX402FacilitatorConfig,
|
|
53
|
+
): FacilitatorConfig {
|
|
54
|
+
const secretKey = config.client.secretKey;
|
|
55
|
+
if (!secretKey) {
|
|
56
|
+
throw new Error("Client secret key is required for the x402 facilitator");
|
|
57
|
+
}
|
|
58
|
+
const serverWalletAddress = config.serverWalletAddress;
|
|
59
|
+
if (!serverWalletAddress) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Server wallet address is required for the x402 facilitator",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
url: (config.baseUrl ?? DEFAULT_BASE_URL) as `${string}://${string}`,
|
|
66
|
+
createAuthHeaders: async () => {
|
|
67
|
+
return {
|
|
68
|
+
verify: {
|
|
69
|
+
"x-secret-key": secretKey,
|
|
70
|
+
},
|
|
71
|
+
settle: {
|
|
72
|
+
"x-secret-key": secretKey,
|
|
73
|
+
"x-settlement-wallet-address": serverWalletAddress,
|
|
74
|
+
...(config.vaultAccessToken
|
|
75
|
+
? { "x-vault-access-token": config.vaultAccessToken }
|
|
76
|
+
: {}),
|
|
77
|
+
},
|
|
78
|
+
supported: {
|
|
79
|
+
"x-secret-key": secretKey,
|
|
80
|
+
},
|
|
81
|
+
list: {
|
|
82
|
+
"x-secret-key": secretKey,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|