@@ -3,20 +3,18 @@ import type { ExactEvmPayloadAuthorization } from "x402/types";
33import  {  getCachedChain  }  from  "../chains/utils.js" ; 
44import  type  {  ThirdwebClient  }  from  "../client/client.js" ; 
55import  {  getContract  }  from  "../contract/contract.js" ; 
6+ import  {  nonces  }  from  "../extensions/erc20/__generated__/IERC20Permit/read/nonces.js" ; 
67import  {  type  Address ,  getAddress  }  from  "../utils/address.js" ; 
78import  {  type  Hex ,  toHex  }  from  "../utils/encoding/hex.js" ; 
89import  type  {  Account  }  from  "../wallets/interfaces/wallet.js" ; 
10+ import  {  detectSupportedAuthorizationMethods  }  from  "./common.js" ; 
911import  {  encodePayment  }  from  "./encode.js" ; 
1012import  { 
1113  networkToChainId , 
1214  type  RequestedPaymentPayload , 
1315  type  RequestedPaymentRequirements , 
1416  type  UnsignedPaymentPayload , 
1517}  from  "./schemas.js" ; 
16- import  { 
17-   detectSupportedAuthorizationMethods , 
18- }  from  "./common.js" ; 
19- import  {  nonces  }  from  "../extensions/erc20/__generated__/IERC20Permit/read/nonces.js" ; 
2018import  {  x402Version  }  from  "./types.js" ; 
2119
2220/** 
@@ -31,13 +29,13 @@ function preparePaymentHeader(
3129  from : Address , 
3230  x402Version : number , 
3331  paymentRequirements : RequestedPaymentRequirements , 
34-   nonce : Hex 
32+   nonce : Hex , 
3533) : UnsignedPaymentPayload  { 
3634  const  validAfter  =  BigInt ( 
37-     Math . floor ( Date . now ( )  /  1000 )  -  600  // 10 minutes before 
35+     Math . floor ( Date . now ( )  /  1000 )  -  600 ,  // 10 minutes before 
3836  ) . toString ( ) ; 
3937  const  validBefore  =  BigInt ( 
40-     Math . floor ( Date . now ( )  /  1000  +  paymentRequirements . maxTimeoutSeconds ) 
38+     Math . floor ( Date . now ( )  /  1000  +  paymentRequirements . maxTimeoutSeconds ) , 
4139  ) . toString ( ) ; 
4240
4341  return  { 
@@ -69,7 +67,7 @@ function preparePaymentHeader(
6967async  function  signPaymentHeader ( 
7068  client : ThirdwebClient , 
7169  account : Account , 
72-   paymentRequirements : RequestedPaymentRequirements 
70+   paymentRequirements : RequestedPaymentRequirements , 
7371) : Promise < RequestedPaymentPayload >  { 
7472  const  from  =  getAddress ( account . address ) ; 
7573  const  chainId  =  networkToChainId ( paymentRequirements . network ) ; 
@@ -94,12 +92,12 @@ async function signPaymentHeader(
9492      from , 
9593      x402Version , 
9694      paymentRequirements , 
97-       toHex ( nonce ,  {  size : 32  } )  // permit nonce 
95+       toHex ( nonce ,  {  size : 32  } ) ,  // permit nonce 
9896    ) ; 
9997    const  {  signature }  =  await  signERC2612Permit ( 
10098      account , 
10199      unsignedPaymentHeader . payload . authorization , 
102-       paymentRequirements 
100+       paymentRequirements , 
103101    ) ; 
104102    return  { 
105103      ...unsignedPaymentHeader , 
@@ -115,12 +113,12 @@ async function signPaymentHeader(
115113      from , 
116114      x402Version , 
117115      paymentRequirements , 
118-       nonce  // random nonce 
116+       nonce ,  // random nonce 
119117    ) ; 
120118    const  {  signature }  =  await  signERC3009Authorization ( 
121119      account , 
122120      unsignedPaymentHeader . payload . authorization , 
123-       paymentRequirements 
121+       paymentRequirements , 
124122    ) ; 
125123    return  { 
126124      ...unsignedPaymentHeader , 
@@ -143,7 +141,7 @@ async function signPaymentHeader(
143141export  async  function  createPaymentHeader ( 
144142  client : ThirdwebClient , 
145143  account : Account , 
146-   paymentRequirements : RequestedPaymentRequirements 
144+   paymentRequirements : RequestedPaymentRequirements , 
147145) : Promise < string >  { 
148146  const  payment  =  await  signPaymentHeader ( client ,  account ,  paymentRequirements ) ; 
149147  return  encodePayment ( payment ) ; 
@@ -176,7 +174,7 @@ async function signERC3009Authorization(
176174    validBefore, 
177175    nonce, 
178176  } : ExactEvmPayloadAuthorization , 
179-   {  asset,  network,  extra } : RequestedPaymentRequirements 
177+   {  asset,  network,  extra } : RequestedPaymentRequirements , 
180178) : Promise < {  signature : Hex  } >  { 
181179  const  chainId  =  networkToChainId ( network ) ; 
182180  const  name  =  extra ?. name ; 
@@ -218,7 +216,7 @@ async function signERC3009Authorization(
218216async  function  signERC2612Permit ( 
219217  account : Account , 
220218  {  from,  value,  validBefore,  nonce } : ExactEvmPayloadAuthorization , 
221-   {  asset,  network,  extra } : RequestedPaymentRequirements 
219+   {  asset,  network,  extra } : RequestedPaymentRequirements , 
222220) : Promise < {  signature : Hex  } >  { 
223221  const  chainId  =  networkToChainId ( network ) ; 
224222  const  name  =  extra ?. name ; 
@@ -227,7 +225,7 @@ async function signERC2612Permit(
227225  const  facilitatorAddress  =  extra ?. facilitatorAddress ; 
228226  if  ( ! facilitatorAddress )  { 
229227    throw  new  Error ( 
230-       "facilitatorAddress is required in PaymentRequirements extra to pay with permit-based assets" 
228+       "facilitatorAddress is required in PaymentRequirements extra to pay with permit-based assets" , 
231229    ) ; 
232230  } 
233231
0 commit comments