11import * as ox__Authorization from "ox/Authorization" ;
2- import type { EIP1193Provider } from "viem " ;
2+ import * as ox__Signature from "ox/Signature " ;
33import {
4+ type EIP1193Provider ,
45 getTypesForEIP712Domain ,
56 type SignTypedDataParameters ,
67 serializeTypedData ,
@@ -188,7 +189,7 @@ function createAccount({
188189 async sendTransaction ( tx : SendTransactionOption ) {
189190 const gasFees = tx . gasPrice
190191 ? {
191- gasPrice : tx . gasPrice ? numberToHex ( tx . gasPrice ) : undefined ,
192+ gasPrice : numberToHex ( tx . gasPrice ) ,
192193 }
193194 : {
194195 maxFeePerGas : tx . maxFeePerGas
@@ -201,6 +202,9 @@ function createAccount({
201202 const params = [
202203 {
203204 ...tx ,
205+ authorizationList : tx . authorizationList
206+ ? ox__Authorization . toRpcList ( tx . authorizationList )
207+ : undefined ,
204208 ...gasFees ,
205209 from : this . address ,
206210 gas : tx . gas ? numberToHex ( tx . gas ) : undefined ,
@@ -269,10 +273,25 @@ function createAccount({
269273 } ,
270274 async signAuthorization ( authorization : AuthorizationRequest ) {
271275 const payload = ox__Authorization . getSignPayload ( authorization ) ;
272- return await provider . request ( {
273- method : "eth_sign" ,
274- params : [ getAddress ( account . address ) , payload ] ,
275- } ) ;
276+ let signature : Hex | undefined ;
277+ try {
278+ signature = await provider . request ( {
279+ method : "eth_sign" ,
280+ params : [ getAddress ( account . address ) , payload ] ,
281+ } ) ;
282+ } catch {
283+ // fallback to secp256k1_sign, some providers don't support eth_sign
284+ signature = await provider . request ( {
285+ // @ts -expect-error - overriding types here
286+ method : "secp256k1_sign" ,
287+ params : [ payload ] ,
288+ } ) ;
289+ }
290+ if ( ! signature ) {
291+ throw new Error ( "Failed to sign authorization" ) ;
292+ }
293+ const parsedSignature = ox__Signature . fromHex ( signature as Hex ) ;
294+ return { ...authorization , ...parsedSignature } ;
276295 } ,
277296 async signTypedData ( typedData ) {
278297 if ( ! provider || ! account . address ) {
0 commit comments