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.
Files changed (96) hide show
  1. package/dist/cjs/exports/x402.js +8 -1
  2. package/dist/cjs/exports/x402.js.map +1 -1
  3. package/dist/cjs/react/core/utils/defaultTokens.js +2 -8
  4. package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
  5. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
  6. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  7. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +15 -6
  8. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  9. package/dist/cjs/version.js +1 -1
  10. package/dist/cjs/x402/common.js +173 -0
  11. package/dist/cjs/x402/common.js.map +1 -0
  12. package/dist/cjs/x402/encode.js +71 -0
  13. package/dist/cjs/x402/encode.js.map +1 -0
  14. package/dist/cjs/x402/facilitator.js +83 -2
  15. package/dist/cjs/x402/facilitator.js.map +1 -1
  16. package/dist/cjs/x402/fetchWithPayment.js +7 -15
  17. package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
  18. package/dist/cjs/x402/schemas.js +50 -0
  19. package/dist/cjs/x402/schemas.js.map +1 -0
  20. package/dist/cjs/x402/settle-payment.js +174 -0
  21. package/dist/cjs/x402/settle-payment.js.map +1 -0
  22. package/dist/cjs/x402/sign.js +148 -0
  23. package/dist/cjs/x402/sign.js.map +1 -0
  24. package/dist/cjs/x402/types.js +5 -0
  25. package/dist/cjs/x402/types.js.map +1 -0
  26. package/dist/cjs/x402/verify-payment.js +121 -0
  27. package/dist/cjs/x402/verify-payment.js.map +1 -0
  28. package/dist/esm/exports/x402.js +3 -0
  29. package/dist/esm/exports/x402.js.map +1 -1
  30. package/dist/esm/react/core/utils/defaultTokens.js +2 -8
  31. package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
  32. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
  33. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  34. package/dist/esm/react/web/ui/Bridge/BuyWidget.js +15 -6
  35. package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  36. package/dist/esm/version.js +1 -1
  37. package/dist/esm/x402/common.js +170 -0
  38. package/dist/esm/x402/common.js.map +1 -0
  39. package/dist/esm/x402/encode.js +66 -0
  40. package/dist/esm/x402/encode.js.map +1 -0
  41. package/dist/esm/x402/facilitator.js +83 -2
  42. package/dist/esm/x402/facilitator.js.map +1 -1
  43. package/dist/esm/x402/fetchWithPayment.js +8 -16
  44. package/dist/esm/x402/fetchWithPayment.js.map +1 -1
  45. package/dist/esm/x402/schemas.js +46 -0
  46. package/dist/esm/x402/schemas.js.map +1 -0
  47. package/dist/esm/x402/settle-payment.js +171 -0
  48. package/dist/esm/x402/settle-payment.js.map +1 -0
  49. package/dist/esm/x402/sign.js +145 -0
  50. package/dist/esm/x402/sign.js.map +1 -0
  51. package/dist/esm/x402/types.js +2 -0
  52. package/dist/esm/x402/types.js.map +1 -0
  53. package/dist/esm/x402/verify-payment.js +118 -0
  54. package/dist/esm/x402/verify-payment.js.map +1 -0
  55. package/dist/types/exports/x402.d.ts +4 -0
  56. package/dist/types/exports/x402.d.ts.map +1 -1
  57. package/dist/types/react/core/utils/defaultTokens.d.ts +2 -7
  58. package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
  59. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +4 -3
  60. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  61. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +7 -3
  62. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
  63. package/dist/types/version.d.ts +1 -1
  64. package/dist/types/x402/common.d.ts +16 -0
  65. package/dist/types/x402/common.d.ts.map +1 -0
  66. package/dist/types/x402/encode.d.ts +23 -0
  67. package/dist/types/x402/encode.d.ts.map +1 -0
  68. package/dist/types/x402/facilitator.d.ts +44 -3
  69. package/dist/types/x402/facilitator.d.ts.map +1 -1
  70. package/dist/types/x402/fetchWithPayment.d.ts +1 -1
  71. package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
  72. package/dist/types/x402/schemas.d.ts +164 -0
  73. package/dist/types/x402/schemas.d.ts.map +1 -0
  74. package/dist/types/x402/settle-payment.d.ts +117 -0
  75. package/dist/types/x402/settle-payment.d.ts.map +1 -0
  76. package/dist/types/x402/sign.d.ts +12 -0
  77. package/dist/types/x402/sign.d.ts.map +1 -0
  78. package/dist/types/x402/types.d.ts +71 -0
  79. package/dist/types/x402/types.d.ts.map +1 -0
  80. package/dist/types/x402/verify-payment.d.ts +69 -0
  81. package/dist/types/x402/verify-payment.d.ts.map +1 -0
  82. package/package.json +1 -1
  83. package/src/exports/x402.ts +8 -0
  84. package/src/react/core/utils/defaultTokens.ts +2 -8
  85. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +42 -31
  86. package/src/react/web/ui/Bridge/BuyWidget.tsx +24 -9
  87. package/src/version.ts +1 -1
  88. package/src/x402/common.ts +242 -0
  89. package/src/x402/encode.ts +81 -0
  90. package/src/x402/facilitator.ts +114 -6
  91. package/src/x402/fetchWithPayment.ts +13 -27
  92. package/src/x402/schemas.ts +76 -0
  93. package/src/x402/settle-payment.ts +186 -0
  94. package/src/x402/sign.ts +206 -0
  95. package/src/x402/types.ts +90 -0
  96. package/src/x402/verify-payment.ts +133 -0
@@ -1 +1 @@
1
- {"version":3,"file":"BuyWidget.d.ts","sourceRoot":"","sources":["../../../../../../src/react/web/ui/Bridge/BuyWidget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,KAAK,EAAE,qBAAqB,EAA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AE,iCAAiC,CAAC;IAEjD;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;;OASG;IACH,WAAW,CAAC,EACR;QACE,OAAO,EAAE,MAAM,CAAC;KACjB,GACD,OAAO,CAAC;IAEZ;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAEjB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.107.1";
1
+ export declare const version = "5.108.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { type RequestedPaymentPayload, type RequestedPaymentRequirements } from "./schemas.js";
2
+ import { type PaymentArgs, type PaymentRequiredResult } from "./types.js";
3
+ type GetPaymentRequirementsResult = {
4
+ status: 200;
5
+ paymentRequirements: RequestedPaymentRequirements[];
6
+ selectedPaymentRequirements: RequestedPaymentRequirements;
7
+ decodedPayment: RequestedPaymentPayload;
8
+ };
9
+ /**
10
+ * Decodes a payment request and returns the payment requirements, selected payment requirements, and decoded payment
11
+ * @param args
12
+ * @returns The payment requirements, selected payment requirements, and decoded payment
13
+ */
14
+ export declare function decodePaymentRequest(args: PaymentArgs): Promise<GetPaymentRequirementsResult | PaymentRequiredResult>;
15
+ export {};
16
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/x402/common.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAE3B,MAAM,YAAY,CAAC;AAEpB,KAAK,4BAA4B,GAAG;IAClC,MAAM,EAAE,GAAG,CAAC;IACZ,mBAAmB,EAAE,4BAA4B,EAAE,CAAC;IACpD,2BAA2B,EAAE,4BAA4B,CAAC;IAC1D,cAAc,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,4BAA4B,GAAG,qBAAqB,CAAC,CA+I/D"}
@@ -0,0 +1,23 @@
1
+ import { type RequestedPaymentPayload } from "./schemas.js";
2
+ /**
3
+ * Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified
4
+ *
5
+ * @param payment - The payment payload to encode
6
+ * @returns A base64 encoded string representation of the payment payload
7
+ */
8
+ export declare function encodePayment(payment: RequestedPaymentPayload): string;
9
+ /**
10
+ * Decodes a base64 encoded payment string back into a PaymentPayload object
11
+ *
12
+ * @param payment - The base64 encoded payment string to decode
13
+ * @returns The decoded and validated PaymentPayload object
14
+ */
15
+ export declare function decodePayment(payment: string): RequestedPaymentPayload;
16
+ /**
17
+ * Encodes a string to base64 format
18
+ *
19
+ * @param data - The string to be encoded to base64
20
+ * @returns The base64 encoded string
21
+ */
22
+ export declare function safeBase64Encode(data: string): string;
23
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/x402/encode.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAkBtE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAUtE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQrD"}
@@ -1,5 +1,6 @@
1
- import type { FacilitatorConfig } from "x402/types";
1
+ import type { SupportedPaymentKindsResponse, VerifyResponse } from "x402/types";
2
2
  import type { ThirdwebClient } from "../client/client.js";
3
+ import type { FacilitatorSettleResponse, RequestedPaymentPayload, RequestedPaymentRequirements } from "./schemas.js";
3
4
  export type ThirdwebX402FacilitatorConfig = {
4
5
  client: ThirdwebClient;
5
6
  serverWalletAddress: string;
@@ -8,7 +9,7 @@ export type ThirdwebX402FacilitatorConfig = {
8
9
  };
9
10
  /**
10
11
  * 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
+ * You can use this with `settlePayment` or with any x402 middleware to enable settling transactions with your thirdweb server wallet.
12
13
  *
13
14
  * @param config - The configuration for the facilitator
14
15
  * @returns a x402 compatible FacilitatorConfig
@@ -44,5 +45,45 @@ export type ThirdwebX402FacilitatorConfig = {
44
45
  *
45
46
  * @bridge x402
46
47
  */
47
- export declare function facilitator(config: ThirdwebX402FacilitatorConfig): FacilitatorConfig;
48
+ export declare function facilitator(config: ThirdwebX402FacilitatorConfig): {
49
+ url: `${string}://${string}`;
50
+ createAuthHeaders: () => Promise<{
51
+ verify: {
52
+ "x-secret-key": string;
53
+ };
54
+ settle: {
55
+ "x-vault-access-token"?: string | undefined;
56
+ "x-secret-key": string;
57
+ "x-settlement-wallet-address": string;
58
+ };
59
+ supported: {
60
+ "x-secret-key": string;
61
+ };
62
+ list: {
63
+ "x-secret-key": string;
64
+ };
65
+ }>;
66
+ /**
67
+ * Verifies a payment payload with the facilitator service
68
+ *
69
+ * @param payload - The payment payload to verify
70
+ * @param paymentRequirements - The payment requirements to verify against
71
+ * @returns A promise that resolves to the verification response
72
+ */
73
+ verify(payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements): Promise<VerifyResponse>;
74
+ /**
75
+ * Settles a payment with the facilitator service
76
+ *
77
+ * @param payload - The payment payload to settle
78
+ * @param paymentRequirements - The payment requirements for the settlement
79
+ * @returns A promise that resolves to the settlement response
80
+ */
81
+ settle(payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements): Promise<FacilitatorSettleResponse>;
82
+ /**
83
+ * Gets the supported payment kinds from the facilitator service.
84
+ *
85
+ * @returns A promise that resolves to the supported payment kinds
86
+ */
87
+ supported(): Promise<SupportedPaymentKindsResponse>;
88
+ };
48
89
  //# sourceMappingURL=facilitator.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,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,CAAC,MAAM,EAAE,6BAA6B;SAYhB,GAAG,MAAM,MAAM,MAAM,EAAE;;;;;;;;;;;;;;;;;IAqBpE;;;;;;OAMG;oBAEQ,uBAAuB,uBACX,4BAA4B,GAChD,OAAO,CAAC,cAAc,CAAC;IA0B1B;;;;;;OAMG;oBAEQ,uBAAuB,uBACX,4BAA4B,GAChD,OAAO,CAAC,yBAAyB,CAAC;IA0BrC;;;;OAIG;iBACgB,OAAO,CAAC,6BAA6B,CAAC;EA2B5D"}
@@ -39,5 +39,5 @@ import type { Wallet } from "../wallets/interfaces/wallet.js";
39
39
  *
40
40
  * @bridge x402
41
41
  */
42
- export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, maxValue?: bigint): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
42
+ export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, _client: ThirdwebClient, wallet: Wallet, maxValue?: bigint): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
43
43
  //# sourceMappingURL=fetchWithPayment.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAQ9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAA4B,IAExB,OAAO,WAAW,EAAE,OAAO,WAAW,uBAuErD"}
@@ -0,0 +1,164 @@
1
+ import { type ExactEvmPayload } from "x402/types";
2
+ import { z } from "zod";
3
+ declare const FacilitatorNetworkSchema: z.ZodUnion<[z.ZodLiteral<"base-sepolia">, z.ZodLiteral<"base">, z.ZodLiteral<"avalanche-fuji">, z.ZodLiteral<"avalanche">, z.ZodLiteral<"iotex">, z.ZodLiteral<"solana-devnet">, z.ZodLiteral<"solana">, z.ZodLiteral<"sei">, z.ZodLiteral<"sei-testnet">, z.ZodEffects<z.ZodString, string, string>]>;
4
+ export type FacilitatorNetwork = z.infer<typeof FacilitatorNetworkSchema>;
5
+ export declare const RequestedPaymentPayloadSchema: z.ZodObject<{
6
+ x402Version: z.ZodEffects<z.ZodNumber, number, number>;
7
+ scheme: z.ZodEnum<["exact"]>;
8
+ payload: z.ZodUnion<[z.ZodObject<{
9
+ signature: z.ZodString;
10
+ authorization: z.ZodObject<{
11
+ from: z.ZodString;
12
+ to: z.ZodString;
13
+ value: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
14
+ validAfter: z.ZodEffects<z.ZodString, string, string>;
15
+ validBefore: z.ZodEffects<z.ZodString, string, string>;
16
+ nonce: z.ZodString;
17
+ }, "strip", z.ZodTypeAny, {
18
+ from: string;
19
+ to: string;
20
+ value: string;
21
+ validAfter: string;
22
+ validBefore: string;
23
+ nonce: string;
24
+ }, {
25
+ from: string;
26
+ to: string;
27
+ value: string;
28
+ validAfter: string;
29
+ validBefore: string;
30
+ nonce: string;
31
+ }>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ signature: string;
34
+ authorization: {
35
+ from: string;
36
+ to: string;
37
+ value: string;
38
+ validAfter: string;
39
+ validBefore: string;
40
+ nonce: string;
41
+ };
42
+ }, {
43
+ signature: string;
44
+ authorization: {
45
+ from: string;
46
+ to: string;
47
+ value: string;
48
+ validAfter: string;
49
+ validBefore: string;
50
+ nonce: string;
51
+ };
52
+ }>, z.ZodObject<{
53
+ transaction: z.ZodString;
54
+ }, "strip", z.ZodTypeAny, {
55
+ transaction: string;
56
+ }, {
57
+ transaction: string;
58
+ }>]>;
59
+ } & {
60
+ network: z.ZodUnion<[z.ZodLiteral<"base-sepolia">, z.ZodLiteral<"base">, z.ZodLiteral<"avalanche-fuji">, z.ZodLiteral<"avalanche">, z.ZodLiteral<"iotex">, z.ZodLiteral<"solana-devnet">, z.ZodLiteral<"solana">, z.ZodLiteral<"sei">, z.ZodLiteral<"sei-testnet">, z.ZodEffects<z.ZodString, string, string>]>;
61
+ }, "strip", z.ZodTypeAny, {
62
+ payload: {
63
+ signature: string;
64
+ authorization: {
65
+ from: string;
66
+ to: string;
67
+ value: string;
68
+ validAfter: string;
69
+ validBefore: string;
70
+ nonce: string;
71
+ };
72
+ } | {
73
+ transaction: string;
74
+ };
75
+ scheme: "exact";
76
+ network: string;
77
+ x402Version: number;
78
+ }, {
79
+ payload: {
80
+ signature: string;
81
+ authorization: {
82
+ from: string;
83
+ to: string;
84
+ value: string;
85
+ validAfter: string;
86
+ validBefore: string;
87
+ nonce: string;
88
+ };
89
+ } | {
90
+ transaction: string;
91
+ };
92
+ scheme: "exact";
93
+ network: string;
94
+ x402Version: number;
95
+ }>;
96
+ export type RequestedPaymentPayload = z.infer<typeof RequestedPaymentPayloadSchema>;
97
+ export type UnsignedPaymentPayload = Omit<RequestedPaymentPayload, "payload"> & {
98
+ payload: Omit<ExactEvmPayload, "signature"> & {
99
+ signature: undefined;
100
+ };
101
+ };
102
+ export declare const RequestedPaymentRequirementsSchema: z.ZodObject<{
103
+ scheme: z.ZodEnum<["exact"]>;
104
+ maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
105
+ resource: z.ZodString;
106
+ description: z.ZodString;
107
+ mimeType: z.ZodString;
108
+ outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
109
+ payTo: z.ZodUnion<[z.ZodString, z.ZodString]>;
110
+ maxTimeoutSeconds: z.ZodNumber;
111
+ asset: z.ZodUnion<[z.ZodString, z.ZodString]>;
112
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
113
+ } & {
114
+ network: z.ZodUnion<[z.ZodLiteral<"base-sepolia">, z.ZodLiteral<"base">, z.ZodLiteral<"avalanche-fuji">, z.ZodLiteral<"avalanche">, z.ZodLiteral<"iotex">, z.ZodLiteral<"solana-devnet">, z.ZodLiteral<"solana">, z.ZodLiteral<"sei">, z.ZodLiteral<"sei-testnet">, z.ZodEffects<z.ZodString, string, string>]>;
115
+ }, "strip", z.ZodTypeAny, {
116
+ description: string;
117
+ scheme: "exact";
118
+ resource: string;
119
+ mimeType: string;
120
+ asset: string;
121
+ network: string;
122
+ maxAmountRequired: string;
123
+ payTo: string;
124
+ maxTimeoutSeconds: number;
125
+ outputSchema?: Record<string, any> | undefined;
126
+ extra?: Record<string, any> | undefined;
127
+ }, {
128
+ description: string;
129
+ scheme: "exact";
130
+ resource: string;
131
+ mimeType: string;
132
+ asset: string;
133
+ network: string;
134
+ maxAmountRequired: string;
135
+ payTo: string;
136
+ maxTimeoutSeconds: number;
137
+ outputSchema?: Record<string, any> | undefined;
138
+ extra?: Record<string, any> | undefined;
139
+ }>;
140
+ export type RequestedPaymentRequirements = z.infer<typeof RequestedPaymentRequirementsSchema>;
141
+ declare const FacilitatorSettleResponseSchema: z.ZodObject<{
142
+ success: z.ZodBoolean;
143
+ errorReason: z.ZodOptional<z.ZodEnum<["insufficient_funds", "invalid_exact_evm_payload_authorization_valid_after", "invalid_exact_evm_payload_authorization_valid_before", "invalid_exact_evm_payload_authorization_value", "invalid_exact_evm_payload_signature", "invalid_exact_evm_payload_recipient_mismatch", "invalid_exact_svm_payload_transaction", "invalid_exact_svm_payload_transaction_amount_mismatch", "invalid_exact_svm_payload_transaction_create_ata_instruction", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset", "invalid_exact_svm_payload_transaction_instructions", "invalid_exact_svm_payload_transaction_instructions_length", "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high", "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked", "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked", "invalid_exact_svm_payload_transaction_not_a_transfer_instruction", "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata", "invalid_exact_svm_payload_transaction_receiver_ata_not_found", "invalid_exact_svm_payload_transaction_sender_ata_not_found", "invalid_exact_svm_payload_transaction_simulation_failed", "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata", "invalid_network", "invalid_payload", "invalid_payment_requirements", "invalid_scheme", "invalid_payment", "payment_expired", "unsupported_scheme", "invalid_x402_version", "invalid_transaction_state", "invalid_x402_version", "settle_exact_svm_block_height_exceeded", "settle_exact_svm_transaction_confirmation_timed_out", "unsupported_scheme", "unexpected_settle_error", "unexpected_verify_error"]>>;
144
+ payer: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodString]>>;
145
+ transaction: z.ZodString;
146
+ } & {
147
+ network: z.ZodUnion<[z.ZodLiteral<"base-sepolia">, z.ZodLiteral<"base">, z.ZodLiteral<"avalanche-fuji">, z.ZodLiteral<"avalanche">, z.ZodLiteral<"iotex">, z.ZodLiteral<"solana-devnet">, z.ZodLiteral<"solana">, z.ZodLiteral<"sei">, z.ZodLiteral<"sei-testnet">, z.ZodEffects<z.ZodString, string, string>]>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ transaction: string;
150
+ success: boolean;
151
+ network: string;
152
+ errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
153
+ payer?: string | undefined;
154
+ }, {
155
+ transaction: string;
156
+ success: boolean;
157
+ network: string;
158
+ errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
159
+ payer?: string | undefined;
160
+ }>;
161
+ export type FacilitatorSettleResponse = z.infer<typeof FacilitatorSettleResponseSchema>;
162
+ export declare function networkToChainId(network: string): number;
163
+ export {};
164
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/x402/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAKrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,wBAAwB,wSAa5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAExC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,uBAAuB,EACvB,SAAS,CACV,GAAG;IACF,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG;QAAE,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC;CACxE,CAAC;AAEF,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG3C,CAAC;AAEL,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,kCAAkC,CAC1C,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;EAEnC,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAkBxD"}
@@ -0,0 +1,117 @@
1
+ import { type PaymentArgs, 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
+ *
21
+ * const client = createThirdwebClient({
22
+ * secretKey: process.env.THIRDWEB_SECRET_KEY,
23
+ * });
24
+ *
25
+ * const thirdwebFacilitator = facilitator({
26
+ * client,
27
+ * serverWalletAddress: "0x1234567890123456789012345678901234567890",
28
+ * });
29
+ *
30
+ * export async function GET(request: Request) {
31
+ * const paymentData = request.headers.get("x-payment");
32
+ *
33
+ * // verify and process the payment
34
+ * const result = await settlePayment({
35
+ * resourceUrl: "https://api.example.com/premium-content",
36
+ * method: "GET",
37
+ * paymentData,
38
+ * payTo: "0x1234567890123456789012345678901234567890",
39
+ * network: "eip155:84532", // CAIP2 format: "eip155:<chain_id>"
40
+ * price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
41
+ * facilitator: thirdwebFacilitator,
42
+ * routeConfig: {
43
+ * description: "Access to premium API content",
44
+ * mimeType: "application/json",
45
+ * maxTimeoutSeconds: 300,
46
+ * },
47
+ * });
48
+ *
49
+ * if (result.status === 200) {
50
+ * // Payment verified and settled successfully
51
+ * return Response.json({ data: "premium content" });
52
+ * } else {
53
+ * // Payment required
54
+ * return Response.json(result.responseBody, {
55
+ * status: result.status,
56
+ * headers: result.responseHeaders,
57
+ * });
58
+ * }
59
+ * }
60
+ * ```
61
+ *
62
+ * ### Express middleware example
63
+ *
64
+ * ```ts
65
+ * // Usage in Express middleware
66
+ * import express from "express";
67
+ * import { settlePayment, facilitator } from "thirdweb/x402";
68
+ * import { createThirdwebClient } from "thirdweb";
69
+ *
70
+ * const client = createThirdwebClient({
71
+ * secretKey: process.env.THIRDWEB_SECRET_KEY,
72
+ * });
73
+ *
74
+ * const thirdwebFacilitator = facilitator({
75
+ * client,
76
+ * serverWalletAddress: "0x1234567890123456789012345678901234567890",
77
+ * });
78
+ *
79
+ * const app = express();
80
+ *
81
+ * async function paymentMiddleware(req, res, next) {
82
+ * // verify and process the payment
83
+ * const result = await settlePayment({
84
+ * resourceUrl: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
85
+ * method: req.method,
86
+ * paymentData: req.headers["x-payment"],
87
+ * payTo: "0x1234567890123456789012345678901234567890",
88
+ * network: "eip155:8453", // CAIP2 format: "eip155:<chain_id>"
89
+ * price: "$0.05",
90
+ * facilitator: thirdwebFacilitator,
91
+ * });
92
+ *
93
+ * if (result.status === 200) {
94
+ * // Set payment receipt headers and continue
95
+ * Object.entries(result.responseHeaders).forEach(([key, value]) => {
96
+ * res.setHeader(key, value);
97
+ * });
98
+ * next();
99
+ * } else {
100
+ * // Return payment required response
101
+ * res.status(result.status)
102
+ * .set(result.responseHeaders)
103
+ * .json(result.responseBody);
104
+ * }
105
+ * }
106
+ *
107
+ * app.get("/api/premium", paymentMiddleware, (req, res) => {
108
+ * res.json({ message: "This is premium content!" });
109
+ * });
110
+ * ```
111
+ *
112
+ * @public
113
+ * @beta
114
+ * @bridge x402
115
+ */
116
+ export declare function settlePayment(args: PaymentArgs): Promise<SettlePaymentResult>;
117
+ //# 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,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CA4D9B"}
@@ -0,0 +1,12 @@
1
+ import type { Account } from "../wallets/interfaces/wallet.js";
2
+ import { type RequestedPaymentRequirements } from "./schemas.js";
3
+ /**
4
+ * Creates and encodes a payment header for the given client and payment requirements.
5
+ *
6
+ * @param client - The signer wallet instance used to create the payment header
7
+ * @param x402Version - The version of the X402 protocol to use
8
+ * @param paymentRequirements - The payment requirements containing scheme and network information
9
+ * @returns A promise that resolves to the encoded payment header string
10
+ */
11
+ export declare function createPaymentHeader(account: Account, x402Version: number, paymentRequirements: RequestedPaymentRequirements): Promise<string>;
12
+ //# 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,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAGL,KAAK,4BAA4B,EAElC,MAAM,cAAc,CAAC;AA4FtB;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,mBAAmB,EAAE,4BAA4B,GAChD,OAAO,CAAC,MAAM,CAAC,CAOjB"}
@@ -0,0 +1,71 @@
1
+ import type { ERC20TokenAmount, Money, PaymentMiddlewareConfig } from "x402/types";
2
+ import type { Address } from "../utils/address.js";
3
+ import type { Prettify } from "../utils/type-utils.js";
4
+ import type { facilitator as facilitatorType } from "./facilitator.js";
5
+ import type { FacilitatorNetwork, FacilitatorSettleResponse, RequestedPaymentPayload, RequestedPaymentRequirements } from "./schemas.js";
6
+ export declare const x402Version = 1;
7
+ /**
8
+ * Configuration object for verifying or processing X402 payments.
9
+ *
10
+ * @public
11
+ */
12
+ export type PaymentArgs = {
13
+ /** The URL of the resource being protected by the payment */
14
+ resourceUrl: string;
15
+ /** The HTTP method used to access the resource */
16
+ method: "GET" | "POST" | ({} & string);
17
+ /** The payment data/proof provided by the client, typically from the X-PAYMENT header */
18
+ paymentData?: string | null;
19
+ /** The wallet address that should receive the payment */
20
+ payTo: Address;
21
+ /** The blockchain network where the payment should be processed */
22
+ network: FacilitatorNetwork;
23
+ /** The price for accessing the resource - either a USD amount (e.g., "$0.10") or a specific token amount */
24
+ price: Money | ERC20TokenAmount;
25
+ /** The payment facilitator instance used to verify and settle payments */
26
+ facilitator: ReturnType<typeof facilitatorType>;
27
+ /** Optional configuration for the payment middleware route */
28
+ routeConfig?: PaymentMiddlewareConfig;
29
+ };
30
+ export type PaymentRequiredResult = {
31
+ /** HTTP 402 - Payment Required, verification or processing failed or payment missing */
32
+ status: 402;
33
+ /** The error response body containing payment requirements */
34
+ responseBody: {
35
+ /** The X402 protocol version */
36
+ x402Version: number;
37
+ /** Human-readable error message */
38
+ error: string;
39
+ /** Array of acceptable payment methods and requirements */
40
+ accepts: RequestedPaymentRequirements[];
41
+ /** Optional payer address if verification partially succeeded */
42
+ payer?: string;
43
+ };
44
+ /** Response headers for the error response */
45
+ responseHeaders: Record<string, string>;
46
+ };
47
+ /**
48
+ * The result of a payment settlement operation.
49
+ *
50
+ * @public
51
+ */
52
+ export type SettlePaymentResult = Prettify<{
53
+ /** HTTP 200 - Payment was successfully processed */
54
+ status: 200;
55
+ /** Response headers including payment receipt information */
56
+ responseHeaders: Record<string, string>;
57
+ /** The payment receipt from the payment facilitator */
58
+ paymentReceipt: FacilitatorSettleResponse;
59
+ } | PaymentRequiredResult>;
60
+ /**
61
+ * The result of a payment verification operation.
62
+ *
63
+ * @public
64
+ */
65
+ export type VerifyPaymentResult = Prettify<{
66
+ /** HTTP 200 - Payment was successfully verified */
67
+ status: 200;
68
+ decodedPayment: RequestedPaymentPayload;
69
+ selectedPaymentRequirements: RequestedPaymentRequirements;
70
+ } | PaymentRequiredResult>;
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/x402/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,uBAAuB,EACxB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACvC,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,mEAAmE;IACnE,OAAO,EAAE,kBAAkB,CAAC;IAC5B,4GAA4G;IAC5G,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC;IAChC,0EAA0E;IAC1E,WAAW,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;IAChD,8DAA8D;IAC9D,WAAW,CAAC,EAAE,uBAAuB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,wFAAwF;IACxF,MAAM,EAAE,GAAG,CAAC;IACZ,8DAA8D;IAC9D,YAAY,EAAE;QACZ,gCAAgC;QAChC,WAAW,EAAE,MAAM,CAAC;QACpB,mCAAmC;QACnC,KAAK,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,OAAO,EAAE,4BAA4B,EAAE,CAAC;QACxC,iEAAiE;QACjE,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,8CAA8C;IAC9C,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACtC;IACE,oDAAoD;IACpD,MAAM,EAAE,GAAG,CAAC;IACZ,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,uDAAuD;IACvD,cAAc,EAAE,yBAAyB,CAAC;CAC3C,GACD,qBAAqB,CACxB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACtC;IACE,mDAAmD;IACnD,MAAM,EAAE,GAAG,CAAC;IACZ,cAAc,EAAE,uBAAuB,CAAC;IACxC,2BAA2B,EAAE,4BAA4B,CAAC;CAC3D,GACD,qBAAqB,CACxB,CAAC"}
@@ -0,0 +1,69 @@
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
+ *
15
+ * const client = createThirdwebClient({
16
+ * secretKey: process.env.THIRDWEB_SECRET_KEY,
17
+ * });
18
+ *
19
+ * const thirdwebFacilitator = facilitator({
20
+ * client,
21
+ * serverWalletAddress: "0x1234567890123456789012345678901234567890",
22
+ * });
23
+ *
24
+ * export async function GET(request: Request) {
25
+ * const paymentData = request.headers.get("x-payment");
26
+ *
27
+ * const paymentArgs = {
28
+ * resourceUrl: "https://api.example.com/premium-content",
29
+ * method: "GET",
30
+ * paymentData,
31
+ * payTo: "0x1234567890123456789012345678901234567890",
32
+ * network: "eip155:84532", // CAIP2 format: "eip155:<chain_id>"
33
+ * price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
34
+ * facilitator: thirdwebFacilitator,
35
+ * routeConfig: {
36
+ * description: "Access to premium API content",
37
+ * mimeType: "application/json",
38
+ * maxTimeoutSeconds: 300,
39
+ * },
40
+ * };
41
+ *
42
+ * // verify the payment
43
+ * const result = await verifyPayment(paymentArgs);
44
+ *
45
+ * if (result.status === 200) {
46
+ * // Payment verified, but not settled yet
47
+ * // you can do the work that requires payment first
48
+ * const result = await doSomething();
49
+ * // then settle the payment
50
+ * const settleResult = await settlePayment(paymentArgs);
51
+ *
52
+ * // then return the result
53
+ * return Response.json(result);
54
+ * } else {
55
+ * // verification failed, return payment required
56
+ * return Response.json(result.responseBody, {
57
+ * status: result.status,
58
+ * headers: result.responseHeaders,
59
+ * });
60
+ * }
61
+ * }
62
+ * ```
63
+ *
64
+ * @public
65
+ * @beta
66
+ * @bridge x402
67
+ */
68
+ export declare function verifyPayment(args: PaymentArgs): Promise<VerifyPaymentResult>;
69
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAyD9B"}
package/package.json CHANGED
@@ -397,7 +397,7 @@
397
397
  }
398
398
  },
399
399
  "typings": "./dist/types/exports/thirdweb.d.ts",
400
- "version": "5.107.1",
400
+ "version": "5.108.0",
401
401
  "scripts": {
402
402
  "bench": "vitest -c ./test/vitest.config.ts bench",
403
403
  "bench:compare": "bun run ./benchmarks/run.ts",
@@ -1,5 +1,13 @@
1
+ export { decodePayment, encodePayment } from "../x402/encode.js";
1
2
  export {
2
3
  facilitator,
3
4
  type ThirdwebX402FacilitatorConfig,
4
5
  } from "../x402/facilitator.js";
5
6
  export { wrapFetchWithPayment } from "../x402/fetchWithPayment.js";
7
+ export { settlePayment } from "../x402/settle-payment.js";
8
+ export type {
9
+ PaymentArgs,
10
+ SettlePaymentResult,
11
+ VerifyPaymentResult,
12
+ } from "../x402/types.js";
13
+ export { verifyPayment } from "../x402/verify-payment.js";