diff --git a/.changeset/famous-owls-lick.md b/.changeset/famous-owls-lick.md new file mode 100644 index 00000000000..d6d6c8c4cd4 --- /dev/null +++ b/.changeset/famous-owls-lick.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Make maxAmount optional in wrapFetchWithPayment and loosen schema validation for payment payloads diff --git a/packages/thirdweb/src/x402/encode.ts b/packages/thirdweb/src/x402/encode.ts index 17567c5af8b..9a89e5e60ca 100644 --- a/packages/thirdweb/src/x402/encode.ts +++ b/packages/thirdweb/src/x402/encode.ts @@ -1,8 +1,5 @@ import type { ExactEvmPayload } from "x402/types"; -import { - type RequestedPaymentPayload, - RequestedPaymentPayloadSchema, -} from "./schemas.js"; +import type { RequestedPaymentPayload } from "./schemas.js"; /** * Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified @@ -44,8 +41,7 @@ export function decodePayment(payment: string): RequestedPaymentPayload { ...parsed, payload: parsed.payload as ExactEvmPayload, }; - const validated = RequestedPaymentPayloadSchema.parse(obj); - return validated; + return obj; } /** diff --git a/packages/thirdweb/src/x402/fetchWithPayment.ts b/packages/thirdweb/src/x402/fetchWithPayment.ts index d9adeef3b59..20a4ec58f9e 100644 --- a/packages/thirdweb/src/x402/fetchWithPayment.ts +++ b/packages/thirdweb/src/x402/fetchWithPayment.ts @@ -52,7 +52,7 @@ export function wrapFetchWithPayment( fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, - maxValue: bigint = BigInt(1 * 10 ** 6), // Default to 1 USDC + maxValue?: bigint, ) { return async (input: RequestInfo, init?: RequestInit) => { const response = await fetch(input, init); @@ -91,7 +91,10 @@ export function wrapFetchWithPayment( ); } - if (BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue) { + if ( + maxValue && + BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue + ) { throw new Error( `Payment amount exceeds maximum allowed (currently set to ${maxValue} in base units)`, ); diff --git a/packages/thirdweb/src/x402/schemas.ts b/packages/thirdweb/src/x402/schemas.ts index 4953f1f890f..389e869590c 100644 --- a/packages/thirdweb/src/x402/schemas.ts +++ b/packages/thirdweb/src/x402/schemas.ts @@ -15,7 +15,7 @@ const FacilitatorNetworkSchema = z.string(); export type FacilitatorNetwork = z.infer; -export const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({ +const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({ network: FacilitatorNetworkSchema, });