thirdweb 5.107.1 → 5.108.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 -1
- package/dist/cjs/exports/x402.js.map +1 -1
- package/dist/cjs/react/core/utils/defaultTokens.js +2 -8
- package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
- package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +15 -6
- package/dist/cjs/react/web/ui/Bridge/BuyWidget.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/x402/common.js +173 -0
- package/dist/cjs/x402/common.js.map +1 -0
- package/dist/cjs/x402/encode.js +71 -0
- package/dist/cjs/x402/encode.js.map +1 -0
- package/dist/cjs/x402/facilitator.js +83 -2
- package/dist/cjs/x402/facilitator.js.map +1 -1
- package/dist/cjs/x402/fetchWithPayment.js +7 -15
- package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
- package/dist/cjs/x402/schemas.js +50 -0
- package/dist/cjs/x402/schemas.js.map +1 -0
- package/dist/cjs/x402/settle-payment.js +174 -0
- package/dist/cjs/x402/settle-payment.js.map +1 -0
- package/dist/cjs/x402/sign.js +148 -0
- package/dist/cjs/x402/sign.js.map +1 -0
- package/dist/cjs/x402/types.js +5 -0
- package/dist/cjs/x402/types.js.map +1 -0
- package/dist/cjs/x402/verify-payment.js +121 -0
- package/dist/cjs/x402/verify-payment.js.map +1 -0
- package/dist/esm/exports/x402.js +3 -0
- package/dist/esm/exports/x402.js.map +1 -1
- package/dist/esm/react/core/utils/defaultTokens.js +2 -8
- package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
- package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/BuyWidget.js +15 -6
- package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/x402/common.js +170 -0
- package/dist/esm/x402/common.js.map +1 -0
- package/dist/esm/x402/encode.js +66 -0
- package/dist/esm/x402/encode.js.map +1 -0
- package/dist/esm/x402/facilitator.js +83 -2
- package/dist/esm/x402/facilitator.js.map +1 -1
- package/dist/esm/x402/fetchWithPayment.js +8 -16
- package/dist/esm/x402/fetchWithPayment.js.map +1 -1
- package/dist/esm/x402/schemas.js +46 -0
- package/dist/esm/x402/schemas.js.map +1 -0
- package/dist/esm/x402/settle-payment.js +171 -0
- package/dist/esm/x402/settle-payment.js.map +1 -0
- package/dist/esm/x402/sign.js +145 -0
- package/dist/esm/x402/sign.js.map +1 -0
- package/dist/esm/x402/types.js +2 -0
- package/dist/esm/x402/types.js.map +1 -0
- package/dist/esm/x402/verify-payment.js +118 -0
- package/dist/esm/x402/verify-payment.js.map +1 -0
- package/dist/types/exports/x402.d.ts +4 -0
- package/dist/types/exports/x402.d.ts.map +1 -1
- package/dist/types/react/core/utils/defaultTokens.d.ts +2 -7
- package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +4 -3
- package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +7 -3
- package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/x402/common.d.ts +16 -0
- package/dist/types/x402/common.d.ts.map +1 -0
- package/dist/types/x402/encode.d.ts +23 -0
- package/dist/types/x402/encode.d.ts.map +1 -0
- package/dist/types/x402/facilitator.d.ts +44 -3
- package/dist/types/x402/facilitator.d.ts.map +1 -1
- package/dist/types/x402/fetchWithPayment.d.ts +1 -1
- package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
- package/dist/types/x402/schemas.d.ts +164 -0
- package/dist/types/x402/schemas.d.ts.map +1 -0
- package/dist/types/x402/settle-payment.d.ts +117 -0
- package/dist/types/x402/settle-payment.d.ts.map +1 -0
- package/dist/types/x402/sign.d.ts +12 -0
- package/dist/types/x402/sign.d.ts.map +1 -0
- package/dist/types/x402/types.d.ts +71 -0
- package/dist/types/x402/types.d.ts.map +1 -0
- package/dist/types/x402/verify-payment.d.ts +69 -0
- package/dist/types/x402/verify-payment.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/exports/x402.ts +8 -0
- package/src/react/core/utils/defaultTokens.ts +2 -8
- package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +42 -31
- package/src/react/web/ui/Bridge/BuyWidget.tsx +24 -9
- package/src/version.ts +1 -1
- package/src/x402/common.ts +242 -0
- package/src/x402/encode.ts +81 -0
- package/src/x402/facilitator.ts +114 -6
- package/src/x402/fetchWithPayment.ts +13 -27
- package/src/x402/schemas.ts +76 -0
- package/src/x402/settle-payment.ts +186 -0
- package/src/x402/sign.ts +206 -0
- package/src/x402/types.ts +90 -0
- package/src/x402/verify-payment.ts +133 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchWithPayment.js","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fetchWithPayment.js","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EACL,gBAAgB,EAEhB,kCAAkC,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MA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AO,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,46 @@
|
|
|
1
|
+
import { EvmNetworkToChainId, PaymentPayloadSchema, PaymentRequirementsSchema, SettleResponseSchema, } from "x402/types";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const FacilitatorNetworkSchema = z.union([
|
|
4
|
+
z.literal("base-sepolia"),
|
|
5
|
+
z.literal("base"),
|
|
6
|
+
z.literal("avalanche-fuji"),
|
|
7
|
+
z.literal("avalanche"),
|
|
8
|
+
z.literal("iotex"),
|
|
9
|
+
z.literal("solana-devnet"),
|
|
10
|
+
z.literal("solana"),
|
|
11
|
+
z.literal("sei"),
|
|
12
|
+
z.literal("sei-testnet"),
|
|
13
|
+
z.string().refine((value) => value.startsWith("eip155:"), {
|
|
14
|
+
message: "Invalid network",
|
|
15
|
+
}),
|
|
16
|
+
]);
|
|
17
|
+
export const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({
|
|
18
|
+
network: FacilitatorNetworkSchema,
|
|
19
|
+
});
|
|
20
|
+
export const RequestedPaymentRequirementsSchema = PaymentRequirementsSchema.extend({
|
|
21
|
+
network: FacilitatorNetworkSchema,
|
|
22
|
+
});
|
|
23
|
+
const FacilitatorSettleResponseSchema = SettleResponseSchema.extend({
|
|
24
|
+
network: FacilitatorNetworkSchema,
|
|
25
|
+
});
|
|
26
|
+
export function networkToChainId(network) {
|
|
27
|
+
if (network.startsWith("eip155:")) {
|
|
28
|
+
const chainId = parseInt(network.split(":")[1] ?? "0");
|
|
29
|
+
if (!Number.isNaN(chainId) && chainId > 0) {
|
|
30
|
+
return chainId;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error(`Invalid network: ${network}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const mappedChainId = EvmNetworkToChainId.get(network);
|
|
37
|
+
if (!mappedChainId) {
|
|
38
|
+
throw new Error(`Invalid network: ${network}`);
|
|
39
|
+
}
|
|
40
|
+
// TODO (402): support solana networks
|
|
41
|
+
if (mappedChainId === 101 || mappedChainId === 103) {
|
|
42
|
+
throw new Error("Solana networks not supported yet.");
|
|
43
|
+
}
|
|
44
|
+
return mappedChainId;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/x402/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAGnB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC;IACvC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IACzB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IAC3B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IACtB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;IAC1B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,CAAC,CAAC,OAAO,CAAC,KAAK,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E,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { stringify } from "../utils/json.js";
|
|
2
|
+
import { decodePaymentRequest } from "./common.js";
|
|
3
|
+
import { safeBase64Encode } from "./encode.js";
|
|
4
|
+
import { x402Version, } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Verifies and processes X402 payments for protected resources.
|
|
7
|
+
*
|
|
8
|
+
* This function implements the X402 payment protocol, verifying payment proofs
|
|
9
|
+
* and settling payments through a facilitator service. It handles the complete
|
|
10
|
+
* payment flow from validation to settlement.
|
|
11
|
+
*
|
|
12
|
+
* @param args - Configuration object containing payment verification parameters
|
|
13
|
+
* @returns A promise that resolves to either a successful payment result (200) or payment required error (402)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ### Next.js API route example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Usage in a Next.js API route
|
|
21
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
22
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
23
|
+
*
|
|
24
|
+
* const client = createThirdwebClient({
|
|
25
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const thirdwebFacilitator = facilitator({
|
|
29
|
+
* client,
|
|
30
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* export async function GET(request: Request) {
|
|
34
|
+
* const paymentData = request.headers.get("x-payment");
|
|
35
|
+
*
|
|
36
|
+
* // verify and process the payment
|
|
37
|
+
* const result = await settlePayment({
|
|
38
|
+
* resourceUrl: "https://api.example.com/premium-content",
|
|
39
|
+
* method: "GET",
|
|
40
|
+
* paymentData,
|
|
41
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
42
|
+
* network: "eip155:84532", // CAIP2 format: "eip155:<chain_id>"
|
|
43
|
+
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
44
|
+
* facilitator: thirdwebFacilitator,
|
|
45
|
+
* routeConfig: {
|
|
46
|
+
* description: "Access to premium API content",
|
|
47
|
+
* mimeType: "application/json",
|
|
48
|
+
* maxTimeoutSeconds: 300,
|
|
49
|
+
* },
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* if (result.status === 200) {
|
|
53
|
+
* // Payment verified and settled successfully
|
|
54
|
+
* return Response.json({ data: "premium content" });
|
|
55
|
+
* } else {
|
|
56
|
+
* // Payment required
|
|
57
|
+
* return Response.json(result.responseBody, {
|
|
58
|
+
* status: result.status,
|
|
59
|
+
* headers: result.responseHeaders,
|
|
60
|
+
* });
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ### Express middleware example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Usage in Express middleware
|
|
69
|
+
* import express from "express";
|
|
70
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
71
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
72
|
+
*
|
|
73
|
+
* const client = createThirdwebClient({
|
|
74
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const thirdwebFacilitator = facilitator({
|
|
78
|
+
* client,
|
|
79
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const app = express();
|
|
83
|
+
*
|
|
84
|
+
* async function paymentMiddleware(req, res, next) {
|
|
85
|
+
* // verify and process the payment
|
|
86
|
+
* const result = await settlePayment({
|
|
87
|
+
* resourceUrl: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
|
|
88
|
+
* method: req.method,
|
|
89
|
+
* paymentData: req.headers["x-payment"],
|
|
90
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
91
|
+
* network: "eip155:8453", // CAIP2 format: "eip155:<chain_id>"
|
|
92
|
+
* price: "$0.05",
|
|
93
|
+
* facilitator: thirdwebFacilitator,
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* if (result.status === 200) {
|
|
97
|
+
* // Set payment receipt headers and continue
|
|
98
|
+
* Object.entries(result.responseHeaders).forEach(([key, value]) => {
|
|
99
|
+
* res.setHeader(key, value);
|
|
100
|
+
* });
|
|
101
|
+
* next();
|
|
102
|
+
* } else {
|
|
103
|
+
* // Return payment required response
|
|
104
|
+
* res.status(result.status)
|
|
105
|
+
* .set(result.responseHeaders)
|
|
106
|
+
* .json(result.responseBody);
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* app.get("/api/premium", paymentMiddleware, (req, res) => {
|
|
111
|
+
* res.json({ message: "This is premium content!" });
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
* @beta
|
|
117
|
+
* @bridge x402
|
|
118
|
+
*/
|
|
119
|
+
export async function settlePayment(args) {
|
|
120
|
+
const { routeConfig = {}, facilitator } = args;
|
|
121
|
+
const { errorMessages } = routeConfig;
|
|
122
|
+
const decodePaymentResult = await decodePaymentRequest(args);
|
|
123
|
+
if (decodePaymentResult.status !== 200) {
|
|
124
|
+
return decodePaymentResult;
|
|
125
|
+
}
|
|
126
|
+
const { selectedPaymentRequirements, decodedPayment, paymentRequirements } = decodePaymentResult;
|
|
127
|
+
// Settle payment
|
|
128
|
+
try {
|
|
129
|
+
const settlement = await facilitator.settle(decodedPayment, selectedPaymentRequirements);
|
|
130
|
+
if (settlement.success) {
|
|
131
|
+
return {
|
|
132
|
+
status: 200,
|
|
133
|
+
paymentReceipt: settlement,
|
|
134
|
+
responseHeaders: {
|
|
135
|
+
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE",
|
|
136
|
+
"X-PAYMENT-RESPONSE": safeBase64Encode(stringify(settlement)),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return {
|
|
142
|
+
status: 402,
|
|
143
|
+
responseHeaders: {
|
|
144
|
+
"Content-Type": "application/json",
|
|
145
|
+
},
|
|
146
|
+
responseBody: {
|
|
147
|
+
x402Version,
|
|
148
|
+
error: errorMessages?.settlementFailed ||
|
|
149
|
+
settlement.errorReason ||
|
|
150
|
+
"Settlement failed",
|
|
151
|
+
accepts: paymentRequirements,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
return {
|
|
158
|
+
status: 402,
|
|
159
|
+
responseHeaders: {
|
|
160
|
+
"Content-Type": "application/json",
|
|
161
|
+
},
|
|
162
|
+
responseBody: {
|
|
163
|
+
x402Version,
|
|
164
|
+
error: errorMessages?.settlementFailed ||
|
|
165
|
+
(error instanceof Error ? error.message : "Settlement error"),
|
|
166
|
+
accepts: paymentRequirements,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=settle-payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settle-payment.js","sourceRoot":"","sources":["../../../src/x402/settle-payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAGL,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AY,EAAE;gBACZ,WAAW;gBACX,KAAK,EACH,aAAa,EAAE,gBAAgB;oBAC/B,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC;gBAC/D,OAAO,EAAE,mBAAmB;aAC7B;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { getAddress } from "../utils/address.js";
|
|
2
|
+
import { toHex } from "../utils/encoding/hex.js";
|
|
3
|
+
import { encodePayment } from "./encode.js";
|
|
4
|
+
import { networkToChainId, } from "./schemas.js";
|
|
5
|
+
/**
|
|
6
|
+
* Prepares an unsigned payment header with the given sender address and payment requirements.
|
|
7
|
+
*
|
|
8
|
+
* @param from - The sender's address from which the payment will be made
|
|
9
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
10
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
11
|
+
* @returns An unsigned payment payload containing authorization details
|
|
12
|
+
*/
|
|
13
|
+
function preparePaymentHeader(from, x402Version, paymentRequirements) {
|
|
14
|
+
const nonce = createNonce();
|
|
15
|
+
const validAfter = BigInt(Math.floor(Date.now() / 1000) - 600).toString();
|
|
16
|
+
const validBefore = BigInt(Math.floor(Date.now() / 1000 + paymentRequirements.maxTimeoutSeconds)).toString();
|
|
17
|
+
return {
|
|
18
|
+
x402Version,
|
|
19
|
+
scheme: paymentRequirements.scheme,
|
|
20
|
+
network: paymentRequirements.network,
|
|
21
|
+
payload: {
|
|
22
|
+
signature: undefined,
|
|
23
|
+
authorization: {
|
|
24
|
+
from,
|
|
25
|
+
to: paymentRequirements.payTo,
|
|
26
|
+
value: paymentRequirements.maxAmountRequired,
|
|
27
|
+
validAfter: validAfter.toString(),
|
|
28
|
+
validBefore: validBefore.toString(),
|
|
29
|
+
nonce,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Signs a payment header using the provided client and payment requirements.
|
|
36
|
+
*
|
|
37
|
+
* @param client - The signer wallet instance used to sign the payment header
|
|
38
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
39
|
+
* @param unsignedPaymentHeader - The unsigned payment payload to be signed
|
|
40
|
+
* @returns A promise that resolves to the signed payment payload
|
|
41
|
+
*/
|
|
42
|
+
async function signPaymentHeader(account, paymentRequirements, unsignedPaymentHeader) {
|
|
43
|
+
const { signature } = await signAuthorization(account, unsignedPaymentHeader.payload.authorization, paymentRequirements);
|
|
44
|
+
return {
|
|
45
|
+
...unsignedPaymentHeader,
|
|
46
|
+
payload: {
|
|
47
|
+
...unsignedPaymentHeader.payload,
|
|
48
|
+
signature,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a complete payment payload by preparing and signing a payment header.
|
|
54
|
+
*
|
|
55
|
+
* @param client - The signer wallet instance used to create and sign the payment
|
|
56
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
57
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
58
|
+
* @returns A promise that resolves to the complete signed payment payload
|
|
59
|
+
*/
|
|
60
|
+
async function createPayment(account, x402Version, paymentRequirements) {
|
|
61
|
+
const from = getAddress(account.address);
|
|
62
|
+
const unsignedPaymentHeader = preparePaymentHeader(from, x402Version, paymentRequirements);
|
|
63
|
+
return signPaymentHeader(account, paymentRequirements, unsignedPaymentHeader);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates and encodes a payment header for the given client and payment requirements.
|
|
67
|
+
*
|
|
68
|
+
* @param client - The signer wallet instance used to create the payment header
|
|
69
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
70
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
71
|
+
* @returns A promise that resolves to the encoded payment header string
|
|
72
|
+
*/
|
|
73
|
+
export async function createPaymentHeader(account, x402Version, paymentRequirements) {
|
|
74
|
+
const payment = await createPayment(account, x402Version, paymentRequirements);
|
|
75
|
+
return encodePayment(payment);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Signs an EIP-3009 authorization for USDC transfer
|
|
79
|
+
*
|
|
80
|
+
* @param walletClient - The wallet client that will sign the authorization
|
|
81
|
+
* @param params - The authorization parameters containing transfer details
|
|
82
|
+
* @param params.from - The address tokens will be transferred from
|
|
83
|
+
* @param params.to - The address tokens will be transferred to
|
|
84
|
+
* @param params.value - The amount of USDC tokens to transfer (in base units)
|
|
85
|
+
* @param params.validAfter - Unix timestamp after which the authorization becomes valid
|
|
86
|
+
* @param params.validBefore - Unix timestamp before which the authorization is valid
|
|
87
|
+
* @param params.nonce - Random 32-byte nonce to prevent replay attacks
|
|
88
|
+
* @param paymentRequirements - The payment requirements containing asset and network information
|
|
89
|
+
* @param paymentRequirements.asset - The address of the USDC contract
|
|
90
|
+
* @param paymentRequirements.network - The network where the USDC contract exists
|
|
91
|
+
* @param paymentRequirements.extra - The extra information containing the name and version of the ERC20 contract
|
|
92
|
+
* @returns The signature for the authorization
|
|
93
|
+
*/
|
|
94
|
+
async function signAuthorization(account, { from, to, value, validAfter, validBefore, nonce, }, { asset, network, extra }) {
|
|
95
|
+
const chainId = networkToChainId(network);
|
|
96
|
+
const name = extra?.name;
|
|
97
|
+
const version = extra?.version;
|
|
98
|
+
// TODO (402): detect permit vs transfer on asset contract
|
|
99
|
+
const data = {
|
|
100
|
+
types: {
|
|
101
|
+
TransferWithAuthorization: [
|
|
102
|
+
{ name: "from", type: "address" },
|
|
103
|
+
{ name: "to", type: "address" },
|
|
104
|
+
{ name: "value", type: "uint256" },
|
|
105
|
+
{ name: "validAfter", type: "uint256" },
|
|
106
|
+
{ name: "validBefore", type: "uint256" },
|
|
107
|
+
{ name: "nonce", type: "bytes32" },
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
domain: {
|
|
111
|
+
name,
|
|
112
|
+
version,
|
|
113
|
+
chainId,
|
|
114
|
+
verifyingContract: getAddress(asset),
|
|
115
|
+
},
|
|
116
|
+
primaryType: "TransferWithAuthorization",
|
|
117
|
+
message: {
|
|
118
|
+
from: getAddress(from),
|
|
119
|
+
to: getAddress(to),
|
|
120
|
+
value,
|
|
121
|
+
validAfter,
|
|
122
|
+
validBefore,
|
|
123
|
+
nonce: nonce,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const signature = await account.signTypedData(data);
|
|
127
|
+
return {
|
|
128
|
+
signature,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Generates a random 32-byte nonce for use in authorization signatures
|
|
133
|
+
*
|
|
134
|
+
* @returns A random 32-byte nonce as a hex string
|
|
135
|
+
*/
|
|
136
|
+
function createNonce() {
|
|
137
|
+
const cryptoObj = typeof globalThis.crypto !== "undefined" &&
|
|
138
|
+
typeof globalThis.crypto.getRandomValues === "function"
|
|
139
|
+
? globalThis.crypto
|
|
140
|
+
: // Dynamic require is needed to support node.js
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
142
|
+
require("crypto").webcrypto;
|
|
143
|
+
return toHex(cryptoObj.getRandomValues(new Uint8Array(32)));
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=sign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../../src/x402/sign.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAY,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,gBAAgB,GAIjB,MAAM,cAAc,CAAC;AAEtB;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,IAAa,EACb,WAAmB,EACnB,mBAAiD;IAEjD,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC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AAE,UAAU,CAAC,KAAK,CAAC;SACrC;QACD,WAAW,EAAE,2BAAoC;QACjD,OAAO,EAAE;YACP,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;YACtB,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC;YAClB,KAAK;YACL,UAAU;YACV,WAAW;YACX,KAAK,EAAE,KAAK;SACb;KACF,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,SAAS,GACb,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW;QACxC,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,KAAK,UAAU;QACrD,CAAC,CAAC,UAAU,CAAC,MAAM;QACnB,CAAC,CAAC,+CAA+C;YAC/C,iEAAiE;YACjE,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC;IAClC,OAAO,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/x402/types.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { decodePaymentRequest } from "./common.js";
|
|
2
|
+
import { x402Version, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verifies X402 payments for protected resources. This function only verifies the payment,
|
|
5
|
+
* you should use `settlePayment` to settle the payment.
|
|
6
|
+
*
|
|
7
|
+
* @param args - Configuration object containing payment verification parameters
|
|
8
|
+
* @returns A promise that resolves to either a successful verification result (200) or payment required error (402)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Usage in a Next.js API route
|
|
13
|
+
* import { verifyPayment, facilitator } from "thirdweb/x402";
|
|
14
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
15
|
+
*
|
|
16
|
+
* const client = createThirdwebClient({
|
|
17
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const thirdwebFacilitator = facilitator({
|
|
21
|
+
* client,
|
|
22
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* export async function GET(request: Request) {
|
|
26
|
+
* const paymentData = request.headers.get("x-payment");
|
|
27
|
+
*
|
|
28
|
+
* const paymentArgs = {
|
|
29
|
+
* resourceUrl: "https://api.example.com/premium-content",
|
|
30
|
+
* method: "GET",
|
|
31
|
+
* paymentData,
|
|
32
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
33
|
+
* network: "eip155:84532", // CAIP2 format: "eip155:<chain_id>"
|
|
34
|
+
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
35
|
+
* facilitator: thirdwebFacilitator,
|
|
36
|
+
* routeConfig: {
|
|
37
|
+
* description: "Access to premium API content",
|
|
38
|
+
* mimeType: "application/json",
|
|
39
|
+
* maxTimeoutSeconds: 300,
|
|
40
|
+
* },
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* // verify the payment
|
|
44
|
+
* const result = await verifyPayment(paymentArgs);
|
|
45
|
+
*
|
|
46
|
+
* if (result.status === 200) {
|
|
47
|
+
* // Payment verified, but not settled yet
|
|
48
|
+
* // you can do the work that requires payment first
|
|
49
|
+
* const result = await doSomething();
|
|
50
|
+
* // then settle the payment
|
|
51
|
+
* const settleResult = await settlePayment(paymentArgs);
|
|
52
|
+
*
|
|
53
|
+
* // then return the result
|
|
54
|
+
* return Response.json(result);
|
|
55
|
+
* } else {
|
|
56
|
+
* // verification failed, return payment required
|
|
57
|
+
* return Response.json(result.responseBody, {
|
|
58
|
+
* status: result.status,
|
|
59
|
+
* headers: result.responseHeaders,
|
|
60
|
+
* });
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @beta
|
|
67
|
+
* @bridge x402
|
|
68
|
+
*/
|
|
69
|
+
export async function verifyPayment(args) {
|
|
70
|
+
const { routeConfig = {}, facilitator } = args;
|
|
71
|
+
const { errorMessages } = routeConfig;
|
|
72
|
+
const decodePaymentResult = await decodePaymentRequest(args);
|
|
73
|
+
if (decodePaymentResult.status !== 200) {
|
|
74
|
+
return decodePaymentResult;
|
|
75
|
+
}
|
|
76
|
+
const { selectedPaymentRequirements, decodedPayment, paymentRequirements } = decodePaymentResult;
|
|
77
|
+
// Verify payment
|
|
78
|
+
try {
|
|
79
|
+
const verification = await facilitator.verify(decodedPayment, selectedPaymentRequirements);
|
|
80
|
+
if (verification.isValid) {
|
|
81
|
+
return {
|
|
82
|
+
status: 200,
|
|
83
|
+
decodedPayment,
|
|
84
|
+
selectedPaymentRequirements,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return {
|
|
89
|
+
status: 402,
|
|
90
|
+
responseHeaders: {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
},
|
|
93
|
+
responseBody: {
|
|
94
|
+
x402Version,
|
|
95
|
+
error: errorMessages?.verificationFailed ||
|
|
96
|
+
verification.invalidReason ||
|
|
97
|
+
"Verification failed",
|
|
98
|
+
accepts: paymentRequirements,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return {
|
|
105
|
+
status: 402,
|
|
106
|
+
responseHeaders: {
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
},
|
|
109
|
+
responseBody: {
|
|
110
|
+
x402Version,
|
|
111
|
+
error: errorMessages?.verificationFailed ||
|
|
112
|
+
(error instanceof Error ? error.message : "Verification error"),
|
|
113
|
+
accepts: paymentRequirements,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=verify-payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-payment.js","sourceRoot":"","sources":["../../../src/x402/verify-payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAGL,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAiB;IAEjB,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC/C,MAAM,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAEtC,MAAM,mBAAmB,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAE7D,IAAI,mBAAmB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACvC,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,MAAM,EAAE,2BAA2B,EAAE,cAAc,EAAE,mBAAmB,EAAE,GACxE,mBAAmB,CAAC;IAEtB,iBAAiB;IACjB,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,MAAM,CAC3C,cAAc,EACd,2BAA2B,CAC5B,CAAC;QAEF,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,cAAc;gBACd,2BAA2B;aAC5B,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,eAAe,EAAE;oBACf,cAAc,EAAE,kBAAkB;iBACnC;gBACD,YAAY,EAAE;oBACZ,WAAW;oBACX,KAAK,EACH,aAAa,EAAE,kBAAkB;wBACjC,YAAY,CAAC,aAAa;wBAC1B,qBAAqB;oBACvB,OAAO,EAAE,mBAAmB;iBAC7B;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,GAAG;YACX,eAAe,EAAE;gBACf,cAAc,EAAE,kBAAkB;aACnC;YACD,YAAY,EAAE;gBACZ,WAAW;gBACX,KAAK,EACH,aAAa,EAAE,kBAAkB;oBACjC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC;gBACjE,OAAO,EAAE,mBAAmB;aAC7B;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { decodePayment, encodePayment } from "../x402/encode.js";
|
|
1
2
|
export { facilitator, type ThirdwebX402FacilitatorConfig, } from "../x402/facilitator.js";
|
|
2
3
|
export { wrapFetchWithPayment } from "../x402/fetchWithPayment.js";
|
|
4
|
+
export { settlePayment } from "../x402/settle-payment.js";
|
|
5
|
+
export type { PaymentArgs, SettlePaymentResult, VerifyPaymentResult, } from "../x402/types.js";
|
|
6
|
+
export { verifyPayment } from "../x402/verify-payment.js";
|
|
3
7
|
//# sourceMappingURL=x402.d.ts.map
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../../src/exports/x402.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,WAAW,EACX,KAAK,6BAA6B,GACnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -208,13 +208,8 @@ declare const DEFAULT_TOKENS: {
|
|
|
208
208
|
readonly name: "USD Coin";
|
|
209
209
|
readonly symbol: "USDC";
|
|
210
210
|
}];
|
|
211
|
-
readonly "
|
|
212
|
-
readonly address: "
|
|
213
|
-
readonly icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNTAwIiBoZWlnaHQ9IjI1MDAiIHZpZXdCb3g9IjAgMCAzMiAzMiI+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48Y2lyY2xlIGN4PSIxNiIgY3k9IjE2IiByPSIxNiIgZmlsbD0iIzYyN0VFQSIvPjxnIGZpbGw9IiNGRkYiIGZpbGwtcnVsZT0ibm9uemVybyI+PHBhdGggZmlsbC1vcGFjaXR5PSIuNjAyIiBkPSJNMTYuNDk4IDR2OC44N2w3LjQ5NyAzLjM1eiIvPjxwYXRoIGQ9Ik0xNi40OTggNEw5IDE2LjIybDcuNDk4LTMuMzV6Ii8+PHBhdGggZmlsbC1vcGFjaXR5PSIuNjAyIiBkPSJNMTYuNDk4IDIxLjk2OHY2LjAyN0wyNCAxNy42MTZ6Ii8+PHBhdGggZD0iTTE2LjQ5OCAyNy45OTV2LTYuMDI4TDkgMTcuNjE2eiIvPjxwYXRoIGZpbGwtb3BhY2l0eT0iLjIiIGQ9Ik0xNi40OTggMjAuNTczbDcuNDk3LTQuMzUzLTcuNDk3LTMuMzQ4eiIvPjxwYXRoIGZpbGwtb3BhY2l0eT0iLjYwMiIgZD0iTTkgMTYuMjJsNy40OTggNC4zNTN2LTcuNzAxeiIvPjwvZz48L2c+PC9zdmc+";
|
|
214
|
-
readonly name: "Wrapped Ether";
|
|
215
|
-
readonly symbol: "WETH";
|
|
216
|
-
}, {
|
|
217
|
-
readonly address: "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63";
|
|
211
|
+
readonly "421614": readonly [{
|
|
212
|
+
readonly address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d";
|
|
218
213
|
readonly icon: "data:image/svg+xml;base64,PHN2ZyBkYXRhLW5hbWU9Ijg2OTc3Njg0LTEyZGItNDg1MC04ZjMwLTIzM2E3YzI2N2QxMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgMjAwMCAyMDAwIj4KICA8cGF0aCBkPSJNMTAwMCAyMDAwYzU1NC4xNyAwIDEwMDAtNDQ1LjgzIDEwMDAtMTAwMFMxNTU0LjE3IDAgMTAwMCAwIDAgNDQ1LjgzIDAgMTAwMHM0NDUuODMgMTAwMCAxMDAwIDEwMDB6IiBmaWxsPSIjMjc3NWNhIi8+CiAgPHBhdGggZD0iTTEyNzUgMTE1OC4zM2MwLTE0NS44My04Ny41LTE5NS44My0yNjIuNS0yMTYuNjYtMTI1LTE2LjY3LTE1MC01MC0xNTAtMTA4LjM0czQxLjY3LTk1LjgzIDEyNS05NS44M2M3NSAwIDExNi42NyAyNSAxMzcuNSA4Ny41IDQuMTcgMTIuNSAxNi42NyAyMC44MyAyOS4xNyAyMC44M2g2Ni42NmMxNi42NyAwIDI5LjE3LTEyLjUgMjkuMTctMjkuMTZ2LTQuMTdjLTE2LjY3LTkxLjY3LTkxLjY3LTE2Mi41LTE4Ny41LTE3MC44M3YtMTAwYzAtMTYuNjctMTIuNS0yOS4xNy0zM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0xMi41LTEyLjUtMjkuMTYtMjUtMzcuNXpNMTIyOS4xNyAyOTUuODNjLTE2LjY3LTguMzMtMzMuMzQgMC0zNy41IDE2LjY3LTQuMTcgNC4xNy00LjE3IDguMzMtNC4xNyAxNi42N3Y1OC4zM2MwIDE2LjY3IDEyLjUgMzMuMzMgMjUgNDEuNjcgMzI1IDExNi42NiA0OTEuNjcgNDc5LjE2IDM3MC44MyA4MDAtNjIuNSAxNzUtMjAwIDMwOC4zMy0zNzAuODMgMzcwLjgzLTE2LjY3IDguMzMtMjUgMjAuODMtMjUgNDEuNjdWMTcwMGMwIDE2LjY3IDguMzMgMjkuMTcgMjUgMzMuMzMgNC4xNyAwIDEyLjUgMCAxNi42Ny00LjE2IDM5NS44My0xMjUgNjEyLjUtNTQ1Ljg0IDQ4Ny41LTk0MS42Ny03NS0yMzcuNS0yNTguMzQtNDE2LjY3LTQ4Ny41LTQ5MS42N3oiIGZpbGw9IiNmZmYiLz4KPC9zdmc+Cg==";
|
|
219
214
|
readonly name: "USD Coin";
|
|
220
215
|
readonly symbol: "USDC";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultTokens.d.ts","sourceRoot":"","sources":["../../../../../src/react/core/utils/defaultTokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA0BF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAGtD,QAAA,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"defaultTokens.d.ts","sourceRoot":"","sources":["../../../../../src/react/core/utils/defaultTokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA0BF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAGtD,QAAA,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6QV,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,EAAgC,eAAe,CAAC;AAE1E,KAAK,eAAe,GAClB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,yBAGpE"}
|
|
@@ -5,6 +5,7 @@ import type { PurchaseData } from "../../../../pay/types.js";
|
|
|
5
5
|
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
|
|
6
6
|
import type { Address } from "../../../../utils/address.js";
|
|
7
7
|
import type { Prettify } from "../../../../utils/type-utils.js";
|
|
8
|
+
import type { BridgePrepareResult } from "../../../core/hooks/useBridgePrepare.js";
|
|
8
9
|
import type { SupportedTokens } from "../../../core/utils/defaultTokens.js";
|
|
9
10
|
import type { ConnectLocale } from "../ConnectWallet/locale/types.js";
|
|
10
11
|
import type { PayEmbedConnectOptions } from "../PayEmbed.js";
|
|
@@ -49,15 +50,15 @@ export interface BridgeOrchestratorProps {
|
|
|
49
50
|
/**
|
|
50
51
|
* Called when the flow is completed successfully
|
|
51
52
|
*/
|
|
52
|
-
onComplete: () => void;
|
|
53
|
+
onComplete: (quote: BridgePrepareResult) => void;
|
|
53
54
|
/**
|
|
54
55
|
* Called when the flow encounters an error
|
|
55
56
|
*/
|
|
56
|
-
onError: (error: Error) => void;
|
|
57
|
+
onError: (error: Error, quote: BridgePrepareResult | undefined) => void;
|
|
57
58
|
/**
|
|
58
59
|
* Called when the user cancels the flow
|
|
59
60
|
*/
|
|
60
|
-
onCancel: () => void;
|
|
61
|
+
onCancel: (quote: BridgePrepareResult | undefined) => void;
|
|
61
62
|
/**
|
|
62
63
|
* Connect options for wallet connection
|
|
63
64
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BridgeOrchestrator.d.ts","sourceRoot":"","sources":["../../../../../../src/react/web/ui/Bridge/BridgeOrchestrator.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC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;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,SAAS,EACT,eAAe,EACf,UAAU,EACV,OAAO,EACP,QAAQ,EACR,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAmC,EACnC,oBAA2B,EAC3B,eAAe,EACf,OAAc,GACf,EAAE,uBAAuB,2CA+QzB"}
|
|
@@ -10,8 +10,12 @@ import type { WalletId } from "../../../../wallets/wallet-types.js";
|
|
|
10
10
|
import type { Theme } from "../../../core/design-system/index.js";
|
|
11
11
|
import type { SiweAuthOptions } from "../../../core/hooks/auth/useSiweAuth.js";
|
|
12
12
|
import type { ConnectButton_connectModalOptions } from "../../../core/hooks/connection/ConnectButtonProps.js";
|
|
13
|
+
import type { BridgePrepareResult } from "../../../core/hooks/useBridgePrepare.js";
|
|
13
14
|
import type { SupportedTokens } from "../../../core/utils/defaultTokens.js";
|
|
14
15
|
import type { LocaleId } from "../types.js";
|
|
16
|
+
type BuyOrOnrampPrepareResult = Extract<BridgePrepareResult, {
|
|
17
|
+
type: "buy" | "onramp";
|
|
18
|
+
}>;
|
|
15
19
|
export type BuyWidgetProps = {
|
|
16
20
|
/**
|
|
17
21
|
* Customize the supported tokens that users can pay with.
|
|
@@ -120,15 +124,15 @@ export type BuyWidgetProps = {
|
|
|
120
124
|
/**
|
|
121
125
|
* Callback triggered when the purchase is successful.
|
|
122
126
|
*/
|
|
123
|
-
onSuccess?: () => void;
|
|
127
|
+
onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
|
|
124
128
|
/**
|
|
125
129
|
* Callback triggered when the purchase encounters an error.
|
|
126
130
|
*/
|
|
127
|
-
onError?: (error: Error) => void;
|
|
131
|
+
onError?: (error: Error, quote: BuyOrOnrampPrepareResult | undefined) => void;
|
|
128
132
|
/**
|
|
129
133
|
* Callback triggered when the user cancels the purchase.
|
|
130
134
|
*/
|
|
131
|
-
onCancel?: () => void;
|
|
135
|
+
onCancel?: (quote: BuyOrOnrampPrepareResult | undefined) => void;
|
|
132
136
|
/**
|
|
133
137
|
* @hidden
|
|
134
138
|
*/
|