1
1
import * as ox__Authorization from "ox/Authorization" ;
2
- import type { EIP1193Provider } from "viem " ;
2
+ import * as ox__Signature from "ox/Signature " ;
3
3
import {
4
+ type EIP1193Provider ,
4
5
getTypesForEIP712Domain ,
5
6
type SignTypedDataParameters ,
6
7
serializeTypedData ,
@@ -188,7 +189,7 @@ function createAccount({
188
189
async sendTransaction ( tx : SendTransactionOption ) {
189
190
const gasFees = tx . gasPrice
190
191
? {
191
- gasPrice : tx . gasPrice ? numberToHex ( tx . gasPrice ) : undefined ,
192
+ gasPrice : numberToHex ( tx . gasPrice ) ,
192
193
}
193
194
: {
194
195
maxFeePerGas : tx . maxFeePerGas
@@ -201,6 +202,9 @@ function createAccount({
201
202
const params = [
202
203
{
203
204
...tx ,
205
+ authorizationList : tx . authorizationList
206
+ ? ox__Authorization . toRpcList ( tx . authorizationList )
207
+ : undefined ,
204
208
...gasFees ,
205
209
from : this . address ,
206
210
gas : tx . gas ? numberToHex ( tx . gas ) : undefined ,
@@ -269,10 +273,25 @@ function createAccount({
269
273
} ,
270
274
async signAuthorization ( authorization : AuthorizationRequest ) {
271
275
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 } ;
276
295
} ,
277
296
async signTypedData ( typedData ) {
278
297
if ( ! provider || ! account . address ) {
0 commit comments