@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.
Files changed (49) hide show
  1. package/dist/index.d.ts +47 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +790 -325
  4. package/dist/index.js.map +1 -1
  5. package/dist/protected.d.ts.map +1 -1
  6. package/dist/protected.js.map +1 -1
  7. package/dist/types/index.d.ts +48 -2
  8. package/dist/types/index.d.ts.map +1 -1
  9. package/dist/x402/builders.d.ts +60 -0
  10. package/dist/x402/builders.d.ts.map +1 -0
  11. package/dist/x402/builders.js +210 -0
  12. package/dist/x402/builders.js.map +1 -0
  13. package/dist/x402/common.d.ts +23 -0
  14. package/dist/x402/common.d.ts.map +1 -0
  15. package/dist/x402/common.js +108 -0
  16. package/dist/x402/common.js.map +1 -0
  17. package/dist/x402/encode.d.ts +23 -0
  18. package/dist/x402/encode.d.ts.map +1 -0
  19. package/dist/x402/encode.js +71 -0
  20. package/dist/x402/encode.js.map +1 -0
  21. package/dist/x402/facilitator.d.ts +88 -0
  22. package/dist/x402/facilitator.d.ts.map +1 -0
  23. package/dist/x402/facilitator.js +214 -0
  24. package/dist/x402/facilitator.js.map +1 -0
  25. package/dist/x402/fetchWithPayment.d.ts +43 -0
  26. package/dist/x402/fetchWithPayment.d.ts.map +1 -0
  27. package/dist/x402/fetchWithPayment.js +117 -0
  28. package/dist/x402/fetchWithPayment.js.map +1 -0
  29. package/dist/x402/schemas.d.ts +34 -0
  30. package/dist/x402/schemas.d.ts.map +1 -0
  31. package/dist/x402/schemas.js +126 -0
  32. package/dist/x402/schemas.js.map +1 -0
  33. package/dist/x402/settle-payment.d.ts +120 -0
  34. package/dist/x402/settle-payment.d.ts.map +1 -0
  35. package/dist/x402/settle-payment.js +177 -0
  36. package/dist/x402/settle-payment.js.map +1 -0
  37. package/dist/x402/sign.d.ts +13 -0
  38. package/dist/x402/sign.d.ts.map +1 -0
  39. package/dist/x402/sign.js +221 -0
  40. package/dist/x402/sign.js.map +1 -0
  41. package/dist/x402/types.d.ts +58 -0
  42. package/dist/x402/types.d.ts.map +1 -0
  43. package/dist/x402/types.js +3 -0
  44. package/dist/x402/types.js.map +1 -0
  45. package/dist/x402/verify-payment.d.ts +70 -0
  46. package/dist/x402/verify-payment.d.ts.map +1 -0
  47. package/dist/x402/verify-payment.js +123 -0
  48. package/dist/x402/verify-payment.js.map +1 -0
  49. package/package.json +9 -9
@@ -0,0 +1,70 @@
1
+ import { type PaymentArgs, type VerifyPaymentResult } from "./types.js";
2
+ /**
3
+ * Verifies X402 payments for protected resources. This function only verifies the payment,
4
+ * you should use `settlePayment` to settle the payment.
5
+ *
6
+ * @param args - Configuration object containing payment verification parameters
7
+ * @returns A promise that resolves to either a successful verification result (200) or payment required error (402)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Usage in a Next.js API route
12
+ * import { verifyPayment, facilitator } from "thirdweb/x402";
13
+ * import { createThirdwebClient } from "thirdweb";
14
+ * import { arbitrumSepolia } from "thirdweb/chains";
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: arbitrumSepolia, // or any other chain
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 declare function verifyPayment(args: PaymentArgs): Promise<VerifyPaymentResult>;
70
+ //# sourceMappingURL=verify-payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-payment.d.ts","sourceRoot":"","sources":["../../src/x402/verify-payment.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CA0D9B"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyPayment = verifyPayment;
4
+ const common_js_1 = require("./common.js");
5
+ const types_js_1 = require("./types.js");
6
+ /**
7
+ * Verifies X402 payments for protected resources. This function only verifies the payment,
8
+ * you should use `settlePayment` to settle the payment.
9
+ *
10
+ * @param args - Configuration object containing payment verification parameters
11
+ * @returns A promise that resolves to either a successful verification result (200) or payment required error (402)
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Usage in a Next.js API route
16
+ * import { verifyPayment, facilitator } from "thirdweb/x402";
17
+ * import { createThirdwebClient } from "thirdweb";
18
+ * import { arbitrumSepolia } from "thirdweb/chains";
19
+ *
20
+ * const client = createThirdwebClient({
21
+ * secretKey: process.env.THIRDWEB_SECRET_KEY,
22
+ * });
23
+ *
24
+ * const thirdwebFacilitator = facilitator({
25
+ * client,
26
+ * serverWalletAddress: "0x1234567890123456789012345678901234567890",
27
+ * });
28
+ *
29
+ * export async function GET(request: Request) {
30
+ * const paymentData = request.headers.get("x-payment");
31
+ *
32
+ * const paymentArgs = {
33
+ * resourceUrl: "https://api.example.com/premium-content",
34
+ * method: "GET",
35
+ * paymentData,
36
+ * payTo: "0x1234567890123456789012345678901234567890",
37
+ * network: arbitrumSepolia, // or any other chain
38
+ * price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
39
+ * facilitator: thirdwebFacilitator,
40
+ * routeConfig: {
41
+ * description: "Access to premium API content",
42
+ * mimeType: "application/json",
43
+ * maxTimeoutSeconds: 300,
44
+ * },
45
+ * };
46
+ *
47
+ * // verify the payment
48
+ * const result = await verifyPayment(paymentArgs);
49
+ *
50
+ * if (result.status === 200) {
51
+ * // Payment verified, but not settled yet
52
+ * // you can do the work that requires payment first
53
+ * const result = await doSomething();
54
+ * // then settle the payment
55
+ * const settleResult = await settlePayment(paymentArgs);
56
+ *
57
+ * // then return the result
58
+ * return Response.json(result);
59
+ * } else {
60
+ * // verification failed, return payment required
61
+ * return Response.json(result.responseBody, {
62
+ * status: result.status,
63
+ * headers: result.responseHeaders,
64
+ * });
65
+ * }
66
+ * }
67
+ * ```
68
+ *
69
+ * @public
70
+ * @beta
71
+ * @bridge x402
72
+ */
73
+ async function verifyPayment(args) {
74
+ const { routeConfig = {}, facilitator } = args;
75
+ const { errorMessages } = routeConfig;
76
+ const decodePaymentResult = await (0, common_js_1.decodePaymentRequest)(args);
77
+ if (decodePaymentResult.status !== 200) {
78
+ return decodePaymentResult;
79
+ }
80
+ const { selectedPaymentRequirements, decodedPayment, paymentRequirements } = decodePaymentResult;
81
+ // Verify payment
82
+ try {
83
+ const verification = await facilitator.verify(decodedPayment, selectedPaymentRequirements);
84
+ if (verification.isValid) {
85
+ return {
86
+ status: 200,
87
+ decodedPayment,
88
+ selectedPaymentRequirements,
89
+ };
90
+ }
91
+ else {
92
+ const error = verification.invalidReason || "Verification failed";
93
+ return {
94
+ status: 402,
95
+ responseHeaders: {
96
+ "Content-Type": "application/json",
97
+ },
98
+ responseBody: {
99
+ x402Version: types_js_1.x402Version,
100
+ error: error,
101
+ errorMessage: errorMessages?.verificationFailed || verification.errorMessage,
102
+ accepts: paymentRequirements,
103
+ },
104
+ };
105
+ }
106
+ }
107
+ catch (error) {
108
+ return {
109
+ status: 402,
110
+ responseHeaders: {
111
+ "Content-Type": "application/json",
112
+ },
113
+ responseBody: {
114
+ x402Version: types_js_1.x402Version,
115
+ error: "Verification error",
116
+ errorMessage: errorMessages?.verificationFailed ||
117
+ (error instanceof Error ? error.message : undefined),
118
+ accepts: paymentRequirements,
119
+ },
120
+ };
121
+ }
122
+ }
123
+ //# sourceMappingURL=verify-payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-payment.js","sourceRoot":"","sources":["../../src/x402/verify-payment.ts"],"names":[],"mappings":";;AA0EA,sCA4DC;AAtID,2CAAmD;AACnD,yCAIoB;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACI,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,IAAA,gCAAoB,EAAC,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,MAAM,KAAK,GAAG,YAAY,CAAC,aAAa,IAAI,qBAAqB,CAAC;YAClE,OAAO;gBACL,MAAM,EAAE,GAAG;gBACX,eAAe,EAAE;oBACf,cAAc,EAAE,kBAAkB;iBACnC;gBACD,YAAY,EAAE;oBACZ,WAAW,EAAX,sBAAW;oBACX,KAAK,EAAE,KAAK;oBACZ,YAAY,EACV,aAAa,EAAE,kBAAkB,IAAI,YAAY,CAAC,YAAY;oBAChE,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,oBAAoB;gBAC3B,YAAY,EACV,aAAa,EAAE,kBAAkB;oBACjC,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-pay/icpay-sdk",
3
- "version": "1.3.96",
3
+ "version": "1.4.13",
4
4
  "description": "Official icpay SDK for Internet Computer payments",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,16 +25,16 @@
25
25
  "author": "icpay",
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@dfinity/agent": "^3.4.1",
29
- "@dfinity/auth-client": "^3.4.1",
30
- "@dfinity/candid": "^3.4.1",
31
- "@dfinity/principal": "^3.4.1"
28
+ "@dfinity/agent": "^3.4.2",
29
+ "@dfinity/auth-client": "^3.4.2",
30
+ "@dfinity/candid": "^3.4.2",
31
+ "@dfinity/principal": "^3.4.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "^24.9.2",
35
- "@typescript-eslint/eslint-plugin": "^8.46.2",
36
- "@typescript-eslint/parser": "^8.46.2",
37
- "eslint": "^9.38.0",
34
+ "@types/node": "^24.10.1",
35
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
36
+ "@typescript-eslint/parser": "^8.47.0",
37
+ "eslint": "^9.39.1",
38
38
  "prettier": "^3.6.2",
39
39
  "typescript": "^5.9.3"
40
40
  },