thirdweb 5.107.1 → 5.108.0-nightly-a94f22928a662a5aff7a203fc2d383d9fa0907ec-20250923000340

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 (78) hide show
  1. package/dist/cjs/exports/x402.js +6 -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/version.js.map +1 -1
  11. package/dist/cjs/x402/encode.js +71 -0
  12. package/dist/cjs/x402/encode.js.map +1 -0
  13. package/dist/cjs/x402/facilitator.js +83 -2
  14. package/dist/cjs/x402/facilitator.js.map +1 -1
  15. package/dist/cjs/x402/fetchWithPayment.js +7 -15
  16. package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
  17. package/dist/cjs/x402/schemas.js +50 -0
  18. package/dist/cjs/x402/schemas.js.map +1 -0
  19. package/dist/cjs/x402/sign.js +148 -0
  20. package/dist/cjs/x402/sign.js.map +1 -0
  21. package/dist/cjs/x402/verify-payment.js +341 -0
  22. package/dist/cjs/x402/verify-payment.js.map +1 -0
  23. package/dist/esm/exports/x402.js +2 -0
  24. package/dist/esm/exports/x402.js.map +1 -1
  25. package/dist/esm/react/core/utils/defaultTokens.js +2 -8
  26. package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
  27. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
  28. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  29. package/dist/esm/react/web/ui/Bridge/BuyWidget.js +15 -6
  30. package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  31. package/dist/esm/version.js +1 -1
  32. package/dist/esm/version.js.map +1 -1
  33. package/dist/esm/x402/encode.js +66 -0
  34. package/dist/esm/x402/encode.js.map +1 -0
  35. package/dist/esm/x402/facilitator.js +83 -2
  36. package/dist/esm/x402/facilitator.js.map +1 -1
  37. package/dist/esm/x402/fetchWithPayment.js +8 -16
  38. package/dist/esm/x402/fetchWithPayment.js.map +1 -1
  39. package/dist/esm/x402/schemas.js +46 -0
  40. package/dist/esm/x402/schemas.js.map +1 -0
  41. package/dist/esm/x402/sign.js +145 -0
  42. package/dist/esm/x402/sign.js.map +1 -0
  43. package/dist/esm/x402/verify-payment.js +338 -0
  44. package/dist/esm/x402/verify-payment.js.map +1 -0
  45. package/dist/types/exports/x402.d.ts +2 -0
  46. package/dist/types/exports/x402.d.ts.map +1 -1
  47. package/dist/types/react/core/utils/defaultTokens.d.ts +2 -7
  48. package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
  49. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +4 -3
  50. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  51. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +7 -3
  52. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
  53. package/dist/types/version.d.ts +1 -1
  54. package/dist/types/version.d.ts.map +1 -1
  55. package/dist/types/x402/encode.d.ts +23 -0
  56. package/dist/types/x402/encode.d.ts.map +1 -0
  57. package/dist/types/x402/facilitator.d.ts +44 -3
  58. package/dist/types/x402/facilitator.d.ts.map +1 -1
  59. package/dist/types/x402/fetchWithPayment.d.ts +1 -1
  60. package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
  61. package/dist/types/x402/schemas.d.ts +164 -0
  62. package/dist/types/x402/schemas.d.ts.map +1 -0
  63. package/dist/types/x402/sign.d.ts +12 -0
  64. package/dist/types/x402/sign.d.ts.map +1 -0
  65. package/dist/types/x402/verify-payment.d.ts +158 -0
  66. package/dist/types/x402/verify-payment.d.ts.map +1 -0
  67. package/package.json +3 -3
  68. package/src/exports/x402.ts +6 -0
  69. package/src/react/core/utils/defaultTokens.ts +2 -8
  70. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +42 -31
  71. package/src/react/web/ui/Bridge/BuyWidget.tsx +24 -9
  72. package/src/version.ts +1 -1
  73. package/src/x402/encode.ts +81 -0
  74. package/src/x402/facilitator.ts +114 -6
  75. package/src/x402/fetchWithPayment.ts +13 -27
  76. package/src/x402/schemas.ts +76 -0
  77. package/src/x402/sign.ts +206 -0
  78. package/src/x402/verify-payment.ts +469 -0
@@ -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,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,158 @@
1
+ import { type ERC20TokenAmount, type Money, type PaymentMiddlewareConfig } from "x402/types";
2
+ import { type Address } from "../utils/address.js";
3
+ import type { facilitator as facilitatorType } from "./facilitator.js";
4
+ import { type FacilitatorNetwork, type FacilitatorSettleResponse, type RequestedPaymentRequirements } from "./schemas.js";
5
+ /**
6
+ * Configuration object for verifying X402 payments.
7
+ *
8
+ * @public
9
+ */
10
+ export type VerifyPaymentArgs = {
11
+ /** The URL of the resource being protected by the payment */
12
+ resourceUrl: string;
13
+ /** The HTTP method used to access the resource */
14
+ method: "GET" | "POST" | ({} & string);
15
+ /** The payment data/proof provided by the client, typically from the X-PAYMENT header */
16
+ paymentData?: string | null;
17
+ /** The wallet address that should receive the payment */
18
+ payTo: Address;
19
+ /** The blockchain network where the payment should be processed */
20
+ network: FacilitatorNetwork;
21
+ /** The price for accessing the resource - either a USD amount (e.g., "$0.10") or a specific token amount */
22
+ price: Money | ERC20TokenAmount;
23
+ /** The payment facilitator instance used to verify and settle payments */
24
+ facilitator: ReturnType<typeof facilitatorType>;
25
+ /** Optional configuration for the payment middleware route */
26
+ routeConfig?: PaymentMiddlewareConfig;
27
+ };
28
+ /**
29
+ * The result of a payment verification operation.
30
+ *
31
+ * @public
32
+ */
33
+ export type VerifyPaymentResult = {
34
+ /** HTTP 200 - Payment was successfully verified and settled */
35
+ status: 200;
36
+ /** Response headers including payment receipt information */
37
+ responseHeaders: Record<string, string>;
38
+ /** The settlement receipt from the payment facilitator */
39
+ paymentReceipt: FacilitatorSettleResponse;
40
+ } | {
41
+ /** HTTP 402 - Payment Required, verification failed or payment missing */
42
+ status: 402;
43
+ /** The error response body containing payment requirements */
44
+ responseBody: {
45
+ /** The X402 protocol version */
46
+ x402Version: number;
47
+ /** Human-readable error message */
48
+ error: string;
49
+ /** Array of acceptable payment methods and requirements */
50
+ accepts: RequestedPaymentRequirements[];
51
+ /** Optional payer address if verification partially succeeded */
52
+ payer?: string;
53
+ };
54
+ /** Response headers for the error response */
55
+ responseHeaders: Record<string, string>;
56
+ };
57
+ /**
58
+ * Verifies and processes X402 payments for protected resources.
59
+ *
60
+ * This function implements the X402 payment protocol, verifying payment proofs
61
+ * and settling payments through a facilitator service. It handles the complete
62
+ * payment flow from validation to settlement.
63
+ *
64
+ * @param args - Configuration object containing payment verification parameters
65
+ * @returns A promise that resolves to either a successful payment result (200) or payment required error (402)
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * // Usage in a Next.js API route
70
+ * import { verifyPayment, 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
+ * export async function GET(request: Request) {
83
+ * const paymentData = request.headers.get("x-payment");
84
+ *
85
+ * const result = await verifyPayment({
86
+ * resourceUrl: "https://api.example.com/premium-content",
87
+ * method: "GET",
88
+ * paymentData,
89
+ * payTo: "0x1234567890123456789012345678901234567890",
90
+ * network: "eip155:84532", // CAIP2 format: "eip155:<chain_id>"
91
+ * price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
92
+ * facilitator: thirdwebFacilitator,
93
+ * routeConfig: {
94
+ * description: "Access to premium API content",
95
+ * mimeType: "application/json",
96
+ * maxTimeoutSeconds: 300,
97
+ * },
98
+ * });
99
+ *
100
+ * if (result.status === 200) {
101
+ * // Payment verified and settled successfully
102
+ * return Response.json({ data: "premium content" }, {
103
+ * headers: result.responseHeaders,
104
+ * });
105
+ * } else {
106
+ * // Payment required
107
+ * return Response.json(result.responseBody, {
108
+ * status: result.status,
109
+ * headers: result.responseHeaders,
110
+ * });
111
+ * }
112
+ * }
113
+ * ```
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * // Usage in Express middleware
118
+ * import express from "express";
119
+ * import { verifyPayment, facilitator } from "thirdweb/x402";
120
+ *
121
+ * const app = express();
122
+ *
123
+ * async function paymentMiddleware(req, res, next) {
124
+ * const result = await verifyPayment({
125
+ * resourceUrl: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
126
+ * method: req.method,
127
+ * paymentData: req.headers["x-payment"],
128
+ * payTo: "0x1234567890123456789012345678901234567890",
129
+ * network: "eip155:8453", // CAIP2 format: "eip155:<chain_id>"
130
+ * price: "$0.05",
131
+ * facilitator: thirdwebFacilitator,
132
+ * });
133
+ *
134
+ * if (result.status === 200) {
135
+ * // Set payment receipt headers and continue
136
+ * Object.entries(result.responseHeaders).forEach(([key, value]) => {
137
+ * res.setHeader(key, value);
138
+ * });
139
+ * next();
140
+ * } else {
141
+ * // Return payment required response
142
+ * res.status(result.status)
143
+ * .set(result.responseHeaders)
144
+ * .json(result.responseBody);
145
+ * }
146
+ * }
147
+ *
148
+ * app.get("/api/premium", paymentMiddleware, (req, res) => {
149
+ * res.json({ message: "This is premium content!" });
150
+ * });
151
+ * ```
152
+ *
153
+ * @public
154
+ * @beta
155
+ * @bridge x402
156
+ */
157
+ export declare function verifyPayment(args: VerifyPaymentArgs): Promise<VerifyPaymentResult>;
158
+ //# 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":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,KAAK,EAGV,KAAK,uBAAuB,EAE7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,qBAAqB,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAG9B,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,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;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,+DAA+D;IAC/D,MAAM,EAAE,GAAG,CAAC;IACZ,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,0DAA0D;IAC1D,cAAc,EAAE,yBAAyB,CAAC;CAC3C,GACD;IACE,0EAA0E;IAC1E,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;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAkO9B"}
package/package.json CHANGED
@@ -40,8 +40,8 @@
40
40
  "viem": "2.33.2",
41
41
  "x402": "0.6.1",
42
42
  "zod": "3.25.75",
43
- "@thirdweb-dev/engine": "3.2.1",
44
- "@thirdweb-dev/insight": "1.1.1"
43
+ "@thirdweb-dev/insight": "1.1.1",
44
+ "@thirdweb-dev/engine": "3.2.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@aws-sdk/client-kms": "3.592.0",
@@ -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-nightly-a94f22928a662a5aff7a203fc2d383d9fa0907ec-20250923000340",
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,11 @@
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 {
8
+ type VerifyPaymentArgs,
9
+ type VerifyPaymentResult,
10
+ verifyPayment,
11
+ } from "../x402/verify-payment.js";
@@ -289,15 +289,9 @@ const DEFAULT_TOKENS = {
289
289
  symbol: "USDC",
290
290
  },
291
291
  ],
292
- "421613": [
292
+ "421614": [
293
293
  {
294
- address: "0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3",
295
- icon: wrappedEthIcon,
296
- name: "Wrapped Ether",
297
- symbol: "WETH",
298
- },
299
- {
300
- address: "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63",
294
+ address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
301
295
  icon: usdcIcon,
302
296
  name: "USD Coin",
303
297
  symbol: "USDC",
@@ -82,17 +82,17 @@ export interface BridgeOrchestratorProps {
82
82
  /**
83
83
  * Called when the flow is completed successfully
84
84
  */
85
- onComplete: () => void;
85
+ onComplete: (quote: BridgePrepareResult) => void;
86
86
 
87
87
  /**
88
88
  * Called when the flow encounters an error
89
89
  */
90
- onError: (error: Error) => void;
90
+ onError: (error: Error, quote: BridgePrepareResult | undefined) => void;
91
91
 
92
92
  /**
93
93
  * Called when the user cancels the flow
94
94
  */
95
- onCancel: () => void;
95
+ onCancel: (quote: BridgePrepareResult | undefined) => void;
96
96
 
97
97
  /**
98
98
  * Connect options for wallet connection
@@ -189,19 +189,22 @@ export function BridgeOrchestrator({
189
189
  }, [send, uiOptions.mode]);
190
190
 
191
191
  // Handle post-buy transaction completion
192
- const handlePostBuyTransactionComplete = useCallback(() => {
193
- onComplete?.();
194
- send({ type: "RESET" });
195
- }, [onComplete, send]);
192
+ const handlePostBuyTransactionComplete = useCallback(
193
+ (quote: BridgePrepareResult) => {
194
+ onComplete?.(quote);
195
+ send({ type: "RESET" });
196
+ },
197
+ [onComplete, send],
198
+ );
196
199
 
197
200
  // Handle errors
198
201
  const handleError = useCallback(
199
202
  (error: Error) => {
200
203
  console.error(error);
201
- onError?.(error);
204
+ onError?.(error, state.context.quote);
202
205
  send({ error, type: "ERROR_OCCURRED" });
203
206
  },
204
- [onError, send],
207
+ [onError, send, state.context.quote],
205
208
  );
206
209
 
207
210
  // Handle payment method selection
@@ -227,10 +230,13 @@ export function BridgeOrchestrator({
227
230
 
228
231
  // Handle execution complete
229
232
  const handleExecutionComplete = useCallback(
230
- (completedStatuses: CompletedStatusResult[]) => {
233
+ (
234
+ completedStatuses: CompletedStatusResult[],
235
+ quote: BridgePrepareResult,
236
+ ) => {
231
237
  send({ completedStatuses, type: "EXECUTION_COMPLETE" });
232
238
  if (uiOptions.mode !== "transaction") {
233
- onComplete?.();
239
+ onComplete?.(quote);
234
240
  }
235
241
  },
236
242
  [send, onComplete, uiOptions.mode],
@@ -241,6 +247,8 @@ export function BridgeOrchestrator({
241
247
  send({ type: "RETRY" });
242
248
  }, [send]);
243
249
 
250
+ const quote = state.context.quote;
251
+
244
252
  // Handle requirements resolved from FundWallet and DirectPayment
245
253
  const handleRequirementsResolved = useCallback(
246
254
  (amount: string, token: TokenWithPrices, receiverAddress: Address) => {
@@ -263,7 +271,7 @@ export function BridgeOrchestrator({
263
271
  error={state.context.currentError}
264
272
  onCancel={() => {
265
273
  send({ type: "RESET" });
266
- onCancel?.();
274
+ onCancel?.(quote);
267
275
  }}
268
276
  onRetry={handleRetry}
269
277
  />
@@ -369,31 +377,33 @@ export function BridgeOrchestrator({
369
377
  />
370
378
  )}
371
379
 
372
- {state.value === "execute" &&
373
- state.context.quote &&
374
- state.context.request && (
375
- <StepRunner
376
- autoStart={true}
377
- client={client}
378
- onBack={() => {
379
- send({ type: "BACK" });
380
- }}
381
- onCancel={onCancel}
382
- onComplete={handleExecutionComplete}
383
- request={state.context.request}
384
- wallet={state.context.selectedPaymentMethod?.payerWallet}
385
- windowAdapter={webWindowAdapter}
386
- />
387
- )}
380
+ {state.value === "execute" && quote && state.context.request && (
381
+ <StepRunner
382
+ autoStart={true}
383
+ client={client}
384
+ onBack={() => {
385
+ send({ type: "BACK" });
386
+ }}
387
+ onCancel={() => {
388
+ onCancel(quote);
389
+ }}
390
+ onComplete={(completedStatuses) => {
391
+ handleExecutionComplete(completedStatuses, quote);
392
+ }}
393
+ request={state.context.request}
394
+ wallet={state.context.selectedPaymentMethod?.payerWallet}
395
+ windowAdapter={webWindowAdapter}
396
+ />
397
+ )}
388
398
 
389
399
  {state.value === "success" &&
390
- state.context.quote &&
400
+ quote &&
391
401
  state.context.completedStatuses && (
392
402
  <SuccessScreen
393
403
  client={client}
394
404
  completedStatuses={state.context.completedStatuses}
395
405
  onDone={handleDoneOrContinueClick}
396
- preparedQuote={state.context.quote}
406
+ preparedQuote={quote}
397
407
  uiOptions={uiOptions}
398
408
  windowAdapter={webWindowAdapter}
399
409
  hasPaymentId={!!paymentLinkId}
@@ -402,9 +412,10 @@ export function BridgeOrchestrator({
402
412
 
403
413
  {state.value === "post-buy-transaction" &&
404
414
  uiOptions.mode === "transaction" &&
415
+ quote &&
405
416
  uiOptions.transaction && (
406
417
  <ExecutingTxScreen
407
- closeModal={handlePostBuyTransactionComplete}
418
+ closeModal={() => handlePostBuyTransactionComplete(quote)}
408
419
  onTxSent={() => {
409
420
  // Do nothing
410
421
  }}
@@ -23,6 +23,7 @@ import { CustomThemeProvider } from "../../../core/design-system/CustomThemeProv
23
23
  import type { Theme } from "../../../core/design-system/index.js";
24
24
  import type { SiweAuthOptions } from "../../../core/hooks/auth/useSiweAuth.js";
25
25
  import type { ConnectButton_connectModalOptions } from "../../../core/hooks/connection/ConnectButtonProps.js";
26
+ import type { BridgePrepareResult } from "../../../core/hooks/useBridgePrepare.js";
26
27
  import type { SupportedTokens } from "../../../core/utils/defaultTokens.js";
27
28
  import { useConnectLocale } from "../ConnectWallet/locale/getConnectLocale.js";
28
29
  import { EmbedContainer } from "../ConnectWallet/Modal/ConnectEmbed.js";
@@ -32,6 +33,11 @@ import type { LocaleId } from "../types.js";
32
33
  import { BridgeOrchestrator, type UIOptions } from "./BridgeOrchestrator.js";
33
34
  import { UnsupportedTokenScreen } from "./UnsupportedTokenScreen.js";
34
35
 
36
+ type BuyOrOnrampPrepareResult = Extract<
37
+ BridgePrepareResult,
38
+ { type: "buy" | "onramp" }
39
+ >;
40
+
35
41
  export type BuyWidgetProps = {
36
42
  /**
37
43
  * Customize the supported tokens that users can pay with.
@@ -155,17 +161,17 @@ export type BuyWidgetProps = {
155
161
  /**
156
162
  * Callback triggered when the purchase is successful.
157
163
  */
158
- onSuccess?: () => void;
164
+ onSuccess?: (quote: BuyOrOnrampPrepareResult) => void;
159
165
 
160
166
  /**
161
167
  * Callback triggered when the purchase encounters an error.
162
168
  */
163
- onError?: (error: Error) => void;
169
+ onError?: (error: Error, quote: BuyOrOnrampPrepareResult | undefined) => void;
164
170
 
165
171
  /**
166
172
  * Callback triggered when the user cancels the purchase.
167
173
  */
168
- onCancel?: () => void;
174
+ onCancel?: (quote: BuyOrOnrampPrepareResult | undefined) => void;
169
175
 
170
176
  /**
171
177
  * @hidden
@@ -447,14 +453,23 @@ export function BuyWidget(props: BuyWidgetProps) {
447
453
  client={props.client}
448
454
  connectLocale={localeQuery.data}
449
455
  connectOptions={props.connectOptions}
450
- onCancel={() => {
451
- props.onCancel?.();
456
+ onCancel={(quote) => {
457
+ // type guard
458
+ if (quote?.type === "buy" || quote?.type === "onramp") {
459
+ props.onCancel?.(quote);
460
+ }
452
461
  }}
453
- onComplete={() => {
454
- props.onSuccess?.();
462
+ onComplete={(quote) => {
463
+ // type guard
464
+ if (quote?.type === "buy" || quote?.type === "onramp") {
465
+ props.onSuccess?.(quote);
466
+ }
455
467
  }}
456
- onError={(err: Error) => {
457
- props.onError?.(err);
468
+ onError={(err: Error, quote) => {
469
+ // type guard
470
+ if (quote?.type === "buy" || quote?.type === "onramp") {
471
+ props.onError?.(err, quote);
472
+ }
458
473
  }}
459
474
  paymentLinkId={props.paymentLinkId}
460
475
  paymentMethods={props.paymentMethods}
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.107.1";
1
+ export const version = "5.108.0-nightly-a94f22928a662a5aff7a203fc2d383d9fa0907ec-20250923000340";