1- import type { ThirdwebClient } from "thirdweb" ;
21import { stringify } from "thirdweb/utils" ;
32import type { VerifyResponse } from "x402/types" ;
43import type {
@@ -12,10 +11,9 @@ import type {
1211export type WaitUntil = "simulated" | "submitted" | "confirmed" ;
1312
1413export type ThirdwebX402FacilitatorConfig = {
15- client : ThirdwebClient ;
16- serverWalletAddress : string ;
14+ walletSecret : string ;
15+ walletAddress : string ;
1716 waitUntil ?: WaitUntil ;
18- vaultAccessToken ?: string ;
1917 baseUrl ?: string ;
2018} ;
2119
@@ -47,7 +45,7 @@ export type ThirdwebX402Facilitator = {
4745 } ) => Promise < FacilitatorSupportedResponse > ;
4846} ;
4947
50- const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402 " ;
48+ const DEFAULT_BASE_URL = "https://nexus- api.thirdweb.com" ;
5149
5250/**
5351 * Creates a facilitator for the x402 payment protocol.
@@ -58,21 +56,17 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
5856 *
5957 * @example
6058 * ```ts
61- * import { facilitator } from "thirdweb/x402";
62- * import { createThirdwebClient } from "thirdweb";
59+ * import { createFacilitator } from "@thirdweb-dev/nexus";
6360 * import { paymentMiddleware } from 'x402-hono'
6461 *
65- * const client = createThirdwebClient({
66- * secretKey: "your-secret-key",
67- * });
68- * const thirdwebX402Facilitator = facilitator({
69- * client: client,
70- * serverWalletAddress: "0x1234567890123456789012345678901234567890",
62+ * const facilitator = createFacilitator({
63+ * walletSecret: <your-wallet-secret>,
64+ * walletAddress: <your-wallet-address>,
7165 * });
7266 *
7367 * // add the facilitator to any x402 payment middleware
7468 * const middleware = paymentMiddleware(
75- * "0x1234567890123456789012345678901234567890" ,
69+ * facilitator.address ,
7670 * {
7771 * "/api/paywall": {
7872 * price: "$0.01",
@@ -82,16 +76,16 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
8276 * },
8377 * },
8478 * },
85- * thirdwebX402Facilitator ,
79+ * facilitator ,
8680 * );
8781 * ```
8882 *
8983 * #### Configuration Options
9084 *
9185 * ```ts
92- * const thirdwebX402Facilitator = facilitator ({
93- * client: client ,
94- * serverWalletAddress: "0x1234567890123456789012345678901234567890" ,
86+ * const thirdwebX402Facilitator = createFacilitator ({
87+ * walletSecret: <your-wallet-secret> ,
88+ * walletAddress: <your-wallet-address> ,
9589 * // Optional: Wait behavior for settlements
9690 * // - "simulated": Only simulate the transaction (fastest)
9791 * // - "submitted": Wait until transaction is submitted
@@ -103,38 +97,32 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
10397 *
10498 * @bridge x402
10599 */
106- export function facilitator (
100+ export function createFacilitator (
107101 config : ThirdwebX402FacilitatorConfig ,
108102) : ThirdwebX402Facilitator {
109- const secretKey = config . client . secretKey ;
110- if ( ! secretKey ) {
111- throw new Error ( "Client secret key is required for the x402 facilitator" ) ;
103+ if ( ! config . walletSecret ) {
104+ throw new Error ( "Wallet secret is required for the x402 facilitator" ) ;
112105 }
113- const serverWalletAddress = config . serverWalletAddress ;
114- if ( ! serverWalletAddress ) {
115- throw new Error (
116- "Server wallet address is required for the x402 facilitator" ,
117- ) ;
106+
107+ if ( ! config . walletAddress ) {
108+ throw new Error ( "Wallet address is required for the x402 facilitator" ) ;
118109 }
119110 const facilitator = {
120111 url : ( config . baseUrl ?? DEFAULT_BASE_URL ) as `${string } ://${string } `,
121- address : serverWalletAddress ,
112+ address : config . walletAddress ,
122113 createAuthHeaders : async ( ) => {
123114 return {
124115 verify : {
125- "x-secret-key" : secretKey ,
116+ authorization : `Bearer ${ config . walletSecret } ` ,
126117 } ,
127118 settle : {
128- "x-secret-key" : secretKey ,
129- ...( config . vaultAccessToken
130- ? { "x-vault-access-token" : config . vaultAccessToken }
131- : { } ) ,
119+ authorization : `Bearer ${ config . walletSecret } ` ,
132120 } ,
133121 supported : {
134- "x-secret-key" : secretKey ,
122+ authorization : `Bearer ${ config . walletSecret } ` ,
135123 } ,
136124 list : {
137- "x-secret-key" : secretKey ,
125+ authorization : `Bearer ${ config . walletSecret } ` ,
138126 } ,
139127 } ;
140128 } ,
0 commit comments