@ic-pay/icpay-sdk 1.3.96 → 1.4.13
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/index.d.ts +47 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +790 -325
- package/dist/index.js.map +1 -1
- package/dist/protected.d.ts.map +1 -1
- package/dist/protected.js.map +1 -1
- package/dist/types/index.d.ts +48 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/x402/builders.d.ts +60 -0
- package/dist/x402/builders.d.ts.map +1 -0
- package/dist/x402/builders.js +210 -0
- package/dist/x402/builders.js.map +1 -0
- package/dist/x402/common.d.ts +23 -0
- package/dist/x402/common.d.ts.map +1 -0
- package/dist/x402/common.js +108 -0
- package/dist/x402/common.js.map +1 -0
- package/dist/x402/encode.d.ts +23 -0
- package/dist/x402/encode.d.ts.map +1 -0
- package/dist/x402/encode.js +71 -0
- package/dist/x402/encode.js.map +1 -0
- package/dist/x402/facilitator.d.ts +88 -0
- package/dist/x402/facilitator.d.ts.map +1 -0
- package/dist/x402/facilitator.js +214 -0
- package/dist/x402/facilitator.js.map +1 -0
- package/dist/x402/fetchWithPayment.d.ts +43 -0
- package/dist/x402/fetchWithPayment.d.ts.map +1 -0
- package/dist/x402/fetchWithPayment.js +117 -0
- package/dist/x402/fetchWithPayment.js.map +1 -0
- package/dist/x402/schemas.d.ts +34 -0
- package/dist/x402/schemas.d.ts.map +1 -0
- package/dist/x402/schemas.js +126 -0
- package/dist/x402/schemas.js.map +1 -0
- package/dist/x402/settle-payment.d.ts +120 -0
- package/dist/x402/settle-payment.d.ts.map +1 -0
- package/dist/x402/settle-payment.js +177 -0
- package/dist/x402/settle-payment.js.map +1 -0
- package/dist/x402/sign.d.ts +13 -0
- package/dist/x402/sign.d.ts.map +1 -0
- package/dist/x402/sign.js +221 -0
- package/dist/x402/sign.js.map +1 -0
- package/dist/x402/types.d.ts +58 -0
- package/dist/x402/types.d.ts.map +1 -0
- package/dist/x402/types.js +3 -0
- package/dist/x402/types.js.map +1 -0
- package/dist/x402/verify-payment.d.ts +70 -0
- package/dist/x402/verify-payment.d.ts.map +1 -0
- package/dist/x402/verify-payment.js +123 -0
- package/dist/x402/verify-payment.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type SettlePaymentArgs, type SettlePaymentResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Verifies and processes X402 payments for protected resources.
|
|
4
|
+
*
|
|
5
|
+
* This function implements the X402 payment protocol, verifying payment proofs
|
|
6
|
+
* and settling payments through a facilitator service. It handles the complete
|
|
7
|
+
* payment flow from validation to settlement.
|
|
8
|
+
*
|
|
9
|
+
* @param args - Configuration object containing payment verification parameters
|
|
10
|
+
* @returns A promise that resolves to either a successful payment result (200) or payment required error (402)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ### Next.js API route example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Usage in a Next.js API route
|
|
18
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
19
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
20
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
21
|
+
*
|
|
22
|
+
* const client = createThirdwebClient({
|
|
23
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const thirdwebFacilitator = facilitator({
|
|
27
|
+
* client,
|
|
28
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* export async function GET(request: Request) {
|
|
32
|
+
* const paymentData = request.headers.get("x-payment");
|
|
33
|
+
*
|
|
34
|
+
* // verify and process the payment
|
|
35
|
+
* const result = await settlePayment({
|
|
36
|
+
* resourceUrl: "https://api.example.com/premium-content",
|
|
37
|
+
* method: "GET",
|
|
38
|
+
* paymentData,
|
|
39
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
40
|
+
* network: arbitrumSepolia, // or any other chain
|
|
41
|
+
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
42
|
+
* facilitator: thirdwebFacilitator,
|
|
43
|
+
* routeConfig: {
|
|
44
|
+
* description: "Access to premium API content",
|
|
45
|
+
* mimeType: "application/json",
|
|
46
|
+
* maxTimeoutSeconds: 300,
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* if (result.status === 200) {
|
|
51
|
+
* // Payment verified and settled successfully
|
|
52
|
+
* return Response.json({ data: "premium content" });
|
|
53
|
+
* } else {
|
|
54
|
+
* // Payment required
|
|
55
|
+
* return Response.json(result.responseBody, {
|
|
56
|
+
* status: result.status,
|
|
57
|
+
* headers: result.responseHeaders,
|
|
58
|
+
* });
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ### Express middleware example
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Usage in Express middleware
|
|
67
|
+
* import express from "express";
|
|
68
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
69
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
70
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
71
|
+
*
|
|
72
|
+
* const client = createThirdwebClient({
|
|
73
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* const thirdwebFacilitator = facilitator({
|
|
77
|
+
* client,
|
|
78
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* const app = express();
|
|
82
|
+
*
|
|
83
|
+
* async function paymentMiddleware(req, res, next) {
|
|
84
|
+
* // verify and process the payment
|
|
85
|
+
* const result = await settlePayment({
|
|
86
|
+
* resourceUrl: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
|
|
87
|
+
* method: req.method,
|
|
88
|
+
* paymentData: req.headers["x-payment"],
|
|
89
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
90
|
+
* network: arbitrumSepolia, // or any other chain
|
|
91
|
+
* price: "$0.05",
|
|
92
|
+
* waitUntil: "submitted",
|
|
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 declare function settlePayment(args: SettlePaymentArgs): Promise<SettlePaymentResult>;
|
|
120
|
+
//# sourceMappingURL=settle-payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settle-payment.d.ts","sourceRoot":"","sources":["../../src/x402/settle-payment.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CA6D9B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.settlePayment = settlePayment;
|
|
4
|
+
const json_js_1 = require("../utils/json.js");
|
|
5
|
+
const common_js_1 = require("./common.js");
|
|
6
|
+
const encode_js_1 = require("./encode.js");
|
|
7
|
+
const types_js_1 = require("./types.js");
|
|
8
|
+
/**
|
|
9
|
+
* Verifies and processes X402 payments for protected resources.
|
|
10
|
+
*
|
|
11
|
+
* This function implements the X402 payment protocol, verifying payment proofs
|
|
12
|
+
* and settling payments through a facilitator service. It handles the complete
|
|
13
|
+
* payment flow from validation to settlement.
|
|
14
|
+
*
|
|
15
|
+
* @param args - Configuration object containing payment verification parameters
|
|
16
|
+
* @returns A promise that resolves to either a successful payment result (200) or payment required error (402)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ### Next.js API route example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Usage in a Next.js API route
|
|
24
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
25
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
26
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
27
|
+
*
|
|
28
|
+
* const client = createThirdwebClient({
|
|
29
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const thirdwebFacilitator = facilitator({
|
|
33
|
+
* client,
|
|
34
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* export async function GET(request: Request) {
|
|
38
|
+
* const paymentData = request.headers.get("x-payment");
|
|
39
|
+
*
|
|
40
|
+
* // verify and process the payment
|
|
41
|
+
* const result = await settlePayment({
|
|
42
|
+
* resourceUrl: "https://api.example.com/premium-content",
|
|
43
|
+
* method: "GET",
|
|
44
|
+
* paymentData,
|
|
45
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
46
|
+
* network: arbitrumSepolia, // or any other chain
|
|
47
|
+
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
48
|
+
* facilitator: thirdwebFacilitator,
|
|
49
|
+
* routeConfig: {
|
|
50
|
+
* description: "Access to premium API content",
|
|
51
|
+
* mimeType: "application/json",
|
|
52
|
+
* maxTimeoutSeconds: 300,
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* if (result.status === 200) {
|
|
57
|
+
* // Payment verified and settled successfully
|
|
58
|
+
* return Response.json({ data: "premium content" });
|
|
59
|
+
* } else {
|
|
60
|
+
* // Payment required
|
|
61
|
+
* return Response.json(result.responseBody, {
|
|
62
|
+
* status: result.status,
|
|
63
|
+
* headers: result.responseHeaders,
|
|
64
|
+
* });
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* ### Express middleware example
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* // Usage in Express middleware
|
|
73
|
+
* import express from "express";
|
|
74
|
+
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
75
|
+
* import { createThirdwebClient } from "thirdweb";
|
|
76
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
77
|
+
*
|
|
78
|
+
* const client = createThirdwebClient({
|
|
79
|
+
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const thirdwebFacilitator = facilitator({
|
|
83
|
+
* client,
|
|
84
|
+
* serverWalletAddress: "0x1234567890123456789012345678901234567890",
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* const app = express();
|
|
88
|
+
*
|
|
89
|
+
* async function paymentMiddleware(req, res, next) {
|
|
90
|
+
* // verify and process the payment
|
|
91
|
+
* const result = await settlePayment({
|
|
92
|
+
* resourceUrl: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
|
|
93
|
+
* method: req.method,
|
|
94
|
+
* paymentData: req.headers["x-payment"],
|
|
95
|
+
* payTo: "0x1234567890123456789012345678901234567890",
|
|
96
|
+
* network: arbitrumSepolia, // or any other chain
|
|
97
|
+
* price: "$0.05",
|
|
98
|
+
* waitUntil: "submitted",
|
|
99
|
+
* facilitator: thirdwebFacilitator,
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* if (result.status === 200) {
|
|
103
|
+
* // Set payment receipt headers and continue
|
|
104
|
+
* Object.entries(result.responseHeaders).forEach(([key, value]) => {
|
|
105
|
+
* res.setHeader(key, value);
|
|
106
|
+
* });
|
|
107
|
+
* next();
|
|
108
|
+
* } else {
|
|
109
|
+
* // Return payment required response
|
|
110
|
+
* res.status(result.status)
|
|
111
|
+
* .set(result.responseHeaders)
|
|
112
|
+
* .json(result.responseBody);
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* app.get("/api/premium", paymentMiddleware, (req, res) => {
|
|
117
|
+
* res.json({ message: "This is premium content!" });
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
* @beta
|
|
123
|
+
* @bridge x402
|
|
124
|
+
*/
|
|
125
|
+
async function settlePayment(args) {
|
|
126
|
+
const { routeConfig = {}, facilitator } = args;
|
|
127
|
+
const { errorMessages } = routeConfig;
|
|
128
|
+
const decodePaymentResult = await (0, common_js_1.decodePaymentRequest)(args);
|
|
129
|
+
if (decodePaymentResult.status !== 200) {
|
|
130
|
+
return decodePaymentResult;
|
|
131
|
+
}
|
|
132
|
+
const { selectedPaymentRequirements, decodedPayment, paymentRequirements } = decodePaymentResult;
|
|
133
|
+
try {
|
|
134
|
+
const settlement = await facilitator.settle(decodedPayment, selectedPaymentRequirements, args.waitUntil);
|
|
135
|
+
if (settlement.success) {
|
|
136
|
+
return {
|
|
137
|
+
status: 200,
|
|
138
|
+
paymentReceipt: settlement,
|
|
139
|
+
responseHeaders: {
|
|
140
|
+
"Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE",
|
|
141
|
+
"X-PAYMENT-RESPONSE": (0, encode_js_1.safeBase64Encode)((0, json_js_1.stringify)(settlement)),
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const error = settlement.errorReason || "Settlement error";
|
|
147
|
+
return {
|
|
148
|
+
status: 402,
|
|
149
|
+
responseHeaders: {
|
|
150
|
+
"Content-Type": "application/json",
|
|
151
|
+
},
|
|
152
|
+
responseBody: {
|
|
153
|
+
x402Version: types_js_1.x402Version,
|
|
154
|
+
error,
|
|
155
|
+
errorMessage: errorMessages?.settlementFailed || settlement.errorMessage,
|
|
156
|
+
accepts: paymentRequirements,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
status: 402,
|
|
164
|
+
responseHeaders: {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
},
|
|
167
|
+
responseBody: {
|
|
168
|
+
x402Version: types_js_1.x402Version,
|
|
169
|
+
error: "Settlement error",
|
|
170
|
+
errorMessage: errorMessages?.settlementFailed ||
|
|
171
|
+
(error instanceof Error ? error.message : undefined),
|
|
172
|
+
accepts: paymentRequirements,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=settle-payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settle-payment.js","sourceRoot":"","sources":["../../src/x402/settle-payment.ts"],"names":[],"mappings":";;AA8HA,sCA+DC;AA7LD,8CA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ACV,aAAa,EAAE,gBAAgB,IAAI,UAAU,CAAC,YAAY;oBAC5D,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,EAAX,sBAAW;gBACX,KAAK,EAAE,kBAAkB;gBACzB,YAAY,EACV,aAAa,EAAE,gBAAgB;oBAC/B,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;gBACtD,OAAO,EAAE,mBAAmB;aAC7B;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ThirdwebClient } from "../client/client.js";
|
|
2
|
+
import type { Account } from "../wallets/interfaces/wallet.js";
|
|
3
|
+
import { type RequestedPaymentRequirements } from "./schemas.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates and encodes a payment header for the given client and payment requirements.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The signer wallet instance used to create the payment header
|
|
8
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
9
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
10
|
+
* @returns A promise that resolves to the encoded payment header string
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPaymentHeader(client: ThirdwebClient, account: Account, paymentRequirements: RequestedPaymentRequirements, x402Version: number): Promise<string>;
|
|
13
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/x402/sign.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG/D,OAAO,EAIL,KAAK,4BAA4B,EAElC,MAAM,cAAc,CAAC;AAoItB;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,EAChB,mBAAmB,EAAE,4BAA4B,EACjD,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaymentHeader = createPaymentHeader;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const utils_js_1 = require("../chains/utils.js");
|
|
6
|
+
const contract_js_1 = require("../contract/contract.js");
|
|
7
|
+
const nonces_js_1 = require("../extensions/erc20/__generated__/IERC20Permit/read/nonces.js");
|
|
8
|
+
const address_js_1 = require("../utils/address.js");
|
|
9
|
+
const hex_js_1 = require("../utils/encoding/hex.js");
|
|
10
|
+
const common_js_1 = require("./common.js");
|
|
11
|
+
const encode_js_1 = require("./encode.js");
|
|
12
|
+
const schemas_js_1 = require("./schemas.js");
|
|
13
|
+
/**
|
|
14
|
+
* Prepares an unsigned payment header with the given sender address and payment requirements.
|
|
15
|
+
*
|
|
16
|
+
* @param from - The sender's address from which the payment will be made
|
|
17
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
18
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
19
|
+
* @returns An unsigned payment payload containing authorization details
|
|
20
|
+
*/
|
|
21
|
+
function preparePaymentHeader(from, x402Version, paymentRequirements, nonce) {
|
|
22
|
+
const validAfter = BigInt(Math.floor(Date.now() / 1000) - 86400).toString();
|
|
23
|
+
const validBefore = BigInt(Math.floor(Date.now() / 1000 + paymentRequirements.maxTimeoutSeconds)).toString();
|
|
24
|
+
return {
|
|
25
|
+
x402Version,
|
|
26
|
+
scheme: paymentRequirements.scheme,
|
|
27
|
+
network: paymentRequirements.network,
|
|
28
|
+
payload: {
|
|
29
|
+
signature: undefined,
|
|
30
|
+
authorization: {
|
|
31
|
+
from,
|
|
32
|
+
to: paymentRequirements.payTo,
|
|
33
|
+
value: paymentRequirements.maxAmountRequired,
|
|
34
|
+
validAfter: validAfter.toString(),
|
|
35
|
+
validBefore: validBefore.toString(),
|
|
36
|
+
nonce: nonce,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Signs a payment header using the provided client and payment requirements.
|
|
43
|
+
*
|
|
44
|
+
* @param client - The signer wallet instance used to sign the payment header
|
|
45
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
46
|
+
* @param unsignedPaymentHeader - The unsigned payment payload to be signed
|
|
47
|
+
* @returns A promise that resolves to the signed payment payload
|
|
48
|
+
*/
|
|
49
|
+
async function signPaymentHeader(client, account, paymentRequirements, x402Version) {
|
|
50
|
+
const from = (0, address_js_1.getAddress)(account.address);
|
|
51
|
+
const caip2ChainId = (0, schemas_js_1.networkToCaip2ChainId)(paymentRequirements.network);
|
|
52
|
+
const chainId = (0, schemas_js_1.extractEvmChainId)(caip2ChainId);
|
|
53
|
+
// TODO (402): support solana
|
|
54
|
+
if (chainId === null) {
|
|
55
|
+
throw new Error(`Unsupported chain ID: ${paymentRequirements.network}`);
|
|
56
|
+
}
|
|
57
|
+
const supportedSignatureType = await (0, common_js_1.getSupportedSignatureType)({
|
|
58
|
+
client,
|
|
59
|
+
asset: paymentRequirements.asset,
|
|
60
|
+
chainId: chainId,
|
|
61
|
+
eip712Extras: paymentRequirements.extra,
|
|
62
|
+
});
|
|
63
|
+
switch (supportedSignatureType) {
|
|
64
|
+
case "Permit": {
|
|
65
|
+
const nonce = await (0, nonces_js_1.nonces)({
|
|
66
|
+
contract: (0, contract_js_1.getContract)({
|
|
67
|
+
address: paymentRequirements.asset,
|
|
68
|
+
chain: (0, utils_js_1.getCachedChain)(chainId),
|
|
69
|
+
client: client,
|
|
70
|
+
}),
|
|
71
|
+
owner: from,
|
|
72
|
+
});
|
|
73
|
+
const unsignedPaymentHeader = preparePaymentHeader(from, x402Version, paymentRequirements, (0, hex_js_1.toHex)(nonce, { size: 32 }));
|
|
74
|
+
const { signature } = await signERC2612Permit(account, unsignedPaymentHeader.payload.authorization, paymentRequirements);
|
|
75
|
+
return {
|
|
76
|
+
...unsignedPaymentHeader,
|
|
77
|
+
payload: {
|
|
78
|
+
...unsignedPaymentHeader.payload,
|
|
79
|
+
signature,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
case "TransferWithAuthorization": {
|
|
84
|
+
// default to transfer with authorization
|
|
85
|
+
const nonce = await createNonce();
|
|
86
|
+
const unsignedPaymentHeader = preparePaymentHeader(from, x402Version, paymentRequirements, nonce);
|
|
87
|
+
const { signature } = await signERC3009Authorization(account, unsignedPaymentHeader.payload.authorization, paymentRequirements);
|
|
88
|
+
return {
|
|
89
|
+
...unsignedPaymentHeader,
|
|
90
|
+
payload: {
|
|
91
|
+
...unsignedPaymentHeader.payload,
|
|
92
|
+
signature,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`No supported payment authorization methods found on ${paymentRequirements.asset} on chain ${paymentRequirements.network}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates and encodes a payment header for the given client and payment requirements.
|
|
102
|
+
*
|
|
103
|
+
* @param client - The signer wallet instance used to create the payment header
|
|
104
|
+
* @param x402Version - The version of the X402 protocol to use
|
|
105
|
+
* @param paymentRequirements - The payment requirements containing scheme and network information
|
|
106
|
+
* @returns A promise that resolves to the encoded payment header string
|
|
107
|
+
*/
|
|
108
|
+
async function createPaymentHeader(client, account, paymentRequirements, x402Version) {
|
|
109
|
+
const payment = await signPaymentHeader(client, account, paymentRequirements, x402Version);
|
|
110
|
+
return (0, encode_js_1.encodePayment)(payment);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Signs an EIP-3009 authorization for USDC transfer
|
|
114
|
+
*
|
|
115
|
+
* @param walletClient - The wallet client that will sign the authorization
|
|
116
|
+
* @param params - The authorization parameters containing transfer details
|
|
117
|
+
* @param params.from - The address tokens will be transferred from
|
|
118
|
+
* @param params.to - The address tokens will be transferred to
|
|
119
|
+
* @param params.value - The amount of USDC tokens to transfer (in base units)
|
|
120
|
+
* @param params.validAfter - Unix timestamp after which the authorization becomes valid
|
|
121
|
+
* @param params.validBefore - Unix timestamp before which the authorization is valid
|
|
122
|
+
* @param params.nonce - Random 32-byte nonce to prevent replay attacks
|
|
123
|
+
* @param paymentRequirements - The payment requirements containing asset and network information
|
|
124
|
+
* @param paymentRequirements.asset - The address of the USDC contract
|
|
125
|
+
* @param paymentRequirements.network - The network where the USDC contract exists
|
|
126
|
+
* @param paymentRequirements.extra - The extra information containing the name and version of the ERC20 contract
|
|
127
|
+
* @returns The signature for the authorization
|
|
128
|
+
*/
|
|
129
|
+
async function signERC3009Authorization(account, { from, to, value, validAfter, validBefore, nonce, }, { asset, network, extra }) {
|
|
130
|
+
const chainId = (0, schemas_js_1.extractEvmChainId)((0, schemas_js_1.networkToCaip2ChainId)(network));
|
|
131
|
+
if (chainId === null) {
|
|
132
|
+
throw new Error(`Unsupported chain ID: ${network}`);
|
|
133
|
+
}
|
|
134
|
+
const name = extra?.name;
|
|
135
|
+
const version = extra?.version;
|
|
136
|
+
const signature = await account.signTypedData({
|
|
137
|
+
types: {
|
|
138
|
+
TransferWithAuthorization: [
|
|
139
|
+
{ name: "from", type: "address" },
|
|
140
|
+
{ name: "to", type: "address" },
|
|
141
|
+
{ name: "value", type: "uint256" },
|
|
142
|
+
{ name: "validAfter", type: "uint256" },
|
|
143
|
+
{ name: "validBefore", type: "uint256" },
|
|
144
|
+
{ name: "nonce", type: "bytes32" },
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
domain: {
|
|
148
|
+
name,
|
|
149
|
+
version,
|
|
150
|
+
chainId,
|
|
151
|
+
verifyingContract: (0, address_js_1.getAddress)(asset),
|
|
152
|
+
},
|
|
153
|
+
primaryType: "TransferWithAuthorization",
|
|
154
|
+
message: {
|
|
155
|
+
from: (0, address_js_1.getAddress)(from),
|
|
156
|
+
to: (0, address_js_1.getAddress)(to),
|
|
157
|
+
value: BigInt(value),
|
|
158
|
+
validAfter: BigInt(validAfter),
|
|
159
|
+
validBefore: BigInt(validBefore),
|
|
160
|
+
nonce: nonce,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
signature,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async function signERC2612Permit(account, { from, to, value, validBefore, nonce }, { asset, network, extra }) {
|
|
168
|
+
const chainId = (0, schemas_js_1.extractEvmChainId)((0, schemas_js_1.networkToCaip2ChainId)(network));
|
|
169
|
+
if (chainId === null) {
|
|
170
|
+
throw new Error(`Unsupported chain ID: ${network}`);
|
|
171
|
+
}
|
|
172
|
+
const name = extra?.name;
|
|
173
|
+
const version = extra?.version;
|
|
174
|
+
if (!name || !version) {
|
|
175
|
+
throw new Error("name and version are required in PaymentRequirements extra to pay with permit-based assets");
|
|
176
|
+
}
|
|
177
|
+
//Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline
|
|
178
|
+
const signature = await account.signTypedData({
|
|
179
|
+
types: {
|
|
180
|
+
Permit: [
|
|
181
|
+
{ name: "owner", type: "address" },
|
|
182
|
+
{ name: "spender", type: "address" },
|
|
183
|
+
{ name: "value", type: "uint256" },
|
|
184
|
+
{ name: "nonce", type: "uint256" },
|
|
185
|
+
{ name: "deadline", type: "uint256" },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
domain: {
|
|
189
|
+
name,
|
|
190
|
+
version,
|
|
191
|
+
chainId,
|
|
192
|
+
verifyingContract: (0, address_js_1.getAddress)(asset),
|
|
193
|
+
},
|
|
194
|
+
primaryType: "Permit",
|
|
195
|
+
message: {
|
|
196
|
+
owner: (0, address_js_1.getAddress)(from),
|
|
197
|
+
spender: (0, address_js_1.getAddress)(to),
|
|
198
|
+
value: BigInt(value),
|
|
199
|
+
nonce: (0, viem_1.hexToBigInt)(nonce),
|
|
200
|
+
deadline: BigInt(validBefore),
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
signature,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Generates a random 32-byte nonce for use in authorization signatures
|
|
209
|
+
*
|
|
210
|
+
* @returns A random 32-byte nonce as a hex string
|
|
211
|
+
*/
|
|
212
|
+
async function createNonce() {
|
|
213
|
+
const cryptoObj = typeof globalThis.crypto !== "undefined" &&
|
|
214
|
+
typeof globalThis.crypto.getRandomValues === "function"
|
|
215
|
+
? globalThis.crypto
|
|
216
|
+
: // Dynamic require is needed to support node.js
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
218
|
+
require("crypto").webcrypto;
|
|
219
|
+
return (0, hex_js_1.toHex)(cryptoObj.getRandomValues(new Uint8Array(32)));
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=sign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/x402/sign.ts"],"names":[],"mappings":";;AA6JA,kDAaC;AA1KD,+BAAmC;AAEnC,iDAAoD;AAEpD,yDAAsD;AACtD,6FAAuF;AACvF,oDAA+D;AAC/D,qDAA2D;AAE3D,2CAAwD;AACxD,2CAA4C;AAC5C,6CAMsB;AAGtB;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,IAAa,EACb,WAAmB,EACnB,mBAAiD,EACjD,KAAU;IAEV,MAAM,UAAU,GAAG,MAAM,CACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CACtC,CAAC,Q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
|
3
|
+
version: string;
|
|
4
|
+
chainId?: number;
|
|
5
|
+
verifyingContract: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TransferWithAuthorizationMessage {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
value: string;
|
|
11
|
+
validAfter: string;
|
|
12
|
+
validBefore: string;
|
|
13
|
+
nonce: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PermitMessage {
|
|
16
|
+
owner: string;
|
|
17
|
+
spender: string;
|
|
18
|
+
value: string;
|
|
19
|
+
nonce: string;
|
|
20
|
+
deadline: string;
|
|
21
|
+
}
|
|
22
|
+
export interface X402AcceptExtra {
|
|
23
|
+
intentId?: string;
|
|
24
|
+
provider?: string;
|
|
25
|
+
ledgerId?: string;
|
|
26
|
+
facilitatorUrl?: string | null;
|
|
27
|
+
name?: string;
|
|
28
|
+
eip3009Version?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface X402Acceptance {
|
|
31
|
+
scheme: string;
|
|
32
|
+
network: string;
|
|
33
|
+
maxAmountRequired: string;
|
|
34
|
+
resource?: string | null;
|
|
35
|
+
description?: string | null;
|
|
36
|
+
mimeType?: string | null;
|
|
37
|
+
payTo: string;
|
|
38
|
+
maxTimeoutSeconds?: number;
|
|
39
|
+
asset?: string;
|
|
40
|
+
extra?: Partial<X402AcceptExtra>;
|
|
41
|
+
}
|
|
42
|
+
export interface X402Header {
|
|
43
|
+
x402Version: number;
|
|
44
|
+
scheme: string;
|
|
45
|
+
network: string;
|
|
46
|
+
payload: {
|
|
47
|
+
authorization: {
|
|
48
|
+
from: string;
|
|
49
|
+
to: string;
|
|
50
|
+
value: string;
|
|
51
|
+
validAfter: string;
|
|
52
|
+
validBefore: string;
|
|
53
|
+
nonce: string;
|
|
54
|
+
};
|
|
55
|
+
signature: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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