thirdweb 5.107.1-nightly-51177fbe17153b711d80ec87b43aadc8ca12fb9e-20250922000346 → 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 (81) 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/gas/fee-data.js +1 -0
  4. package/dist/cjs/gas/fee-data.js.map +1 -1
  5. package/dist/cjs/react/core/utils/defaultTokens.js +2 -8
  6. package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
  7. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
  8. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  9. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +15 -6
  10. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  11. package/dist/cjs/version.js +1 -1
  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/sign.js +148 -0
  21. package/dist/cjs/x402/sign.js.map +1 -0
  22. package/dist/cjs/x402/verify-payment.js +341 -0
  23. package/dist/cjs/x402/verify-payment.js.map +1 -0
  24. package/dist/esm/exports/x402.js +2 -0
  25. package/dist/esm/exports/x402.js.map +1 -1
  26. package/dist/esm/gas/fee-data.js +1 -0
  27. package/dist/esm/gas/fee-data.js.map +1 -1
  28. package/dist/esm/react/core/utils/defaultTokens.js +2 -8
  29. package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
  30. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +18 -14
  31. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  32. package/dist/esm/react/web/ui/Bridge/BuyWidget.js +15 -6
  33. package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  34. package/dist/esm/version.js +1 -1
  35. package/dist/esm/x402/encode.js +66 -0
  36. package/dist/esm/x402/encode.js.map +1 -0
  37. package/dist/esm/x402/facilitator.js +83 -2
  38. package/dist/esm/x402/facilitator.js.map +1 -1
  39. package/dist/esm/x402/fetchWithPayment.js +8 -16
  40. package/dist/esm/x402/fetchWithPayment.js.map +1 -1
  41. package/dist/esm/x402/schemas.js +46 -0
  42. package/dist/esm/x402/schemas.js.map +1 -0
  43. package/dist/esm/x402/sign.js +145 -0
  44. package/dist/esm/x402/sign.js.map +1 -0
  45. package/dist/esm/x402/verify-payment.js +338 -0
  46. package/dist/esm/x402/verify-payment.js.map +1 -0
  47. package/dist/types/exports/x402.d.ts +2 -0
  48. package/dist/types/exports/x402.d.ts.map +1 -1
  49. package/dist/types/gas/fee-data.d.ts.map +1 -1
  50. package/dist/types/react/core/utils/defaultTokens.d.ts +2 -7
  51. package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
  52. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +4 -3
  53. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  54. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +7 -3
  55. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
  56. package/dist/types/version.d.ts +1 -1
  57. package/dist/types/x402/encode.d.ts +23 -0
  58. package/dist/types/x402/encode.d.ts.map +1 -0
  59. package/dist/types/x402/facilitator.d.ts +44 -3
  60. package/dist/types/x402/facilitator.d.ts.map +1 -1
  61. package/dist/types/x402/fetchWithPayment.d.ts +1 -1
  62. package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
  63. package/dist/types/x402/schemas.d.ts +164 -0
  64. package/dist/types/x402/schemas.d.ts.map +1 -0
  65. package/dist/types/x402/sign.d.ts +12 -0
  66. package/dist/types/x402/sign.d.ts.map +1 -0
  67. package/dist/types/x402/verify-payment.d.ts +158 -0
  68. package/dist/types/x402/verify-payment.d.ts.map +1 -0
  69. package/package.json +3 -3
  70. package/src/exports/x402.ts +6 -0
  71. package/src/gas/fee-data.ts +1 -0
  72. package/src/react/core/utils/defaultTokens.ts +2 -8
  73. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +42 -31
  74. package/src/react/web/ui/Bridge/BuyWidget.tsx +24 -9
  75. package/src/version.ts +1 -1
  76. package/src/x402/encode.ts +81 -0
  77. package/src/x402/facilitator.ts +114 -6
  78. package/src/x402/fetchWithPayment.ts +13 -27
  79. package/src/x402/schemas.ts +76 -0
  80. package/src/x402/sign.ts +206 -0
  81. package/src/x402/verify-payment.ts +469 -0
@@ -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 `verifyPayment` 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,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-nightly-51177fbe17153b711d80ec87b43aadc8ca12fb9e-20250922000346",
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";
@@ -47,6 +47,7 @@ const FORCE_GAS_PRICE_CHAIN_IDS = [
47
47
  2020, // Ronin Mainnet
48
48
  2021, // Ronin Testnet (Saigon)
49
49
  98866, // Plume mainnet
50
+ 1417429182, // Wilderworld Zephyr Testnet
50
51
  ];
51
52
 
52
53
  /**
@@ -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",