Skip to content

Commit ea80610

Browse files
[SDK] Fix signAuthorization for 1193 providers (#8042)
1 parent 3ad9f7d commit ea80610

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

.changeset/shaggy-fans-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix signAuthorization implementation for 1193 provider

packages/thirdweb/src/wallets/injected/index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as ox__Authorization from "ox/Authorization";
2-
import type { EIP1193Provider } from "viem";
2+
import * as ox__Signature from "ox/Signature";
33
import {
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

Comments
 (0)