Skip to content

Commit

Permalink
Merge pull request #1989 from Web3Auth/fix/strip0x
Browse files Browse the repository at this point in the history
fix: strip 0x from the unsignned data
  • Loading branch information
chaitanyapotti authored Oct 21, 2024
2 parents 7288c0c + d0a37f2 commit 7f1fa72
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TypedMessageParams,
validateTypedSignMessageDataV4,
} from "@web3auth/ethereum-provider";
import { hashMessage, TypedDataEncoder } from "ethers";
import { hashMessage, Signature, TypedDataEncoder } from "ethers";

async function signTx(
txParams: TransactionParams & { gas?: string },
Expand All @@ -25,8 +25,8 @@ async function signTx(
...finalTxParams,
from: undefined, // from is already calculated inside Transaction.from and is not allowed to be passed in
});

const vrs = await sign(Buffer.from(ethTx.unsignedHash));
const msgHash = stripHexPrefix(ethTx.unsignedHash);
const vrs = await sign(Buffer.from(msgHash, "hex"));
let { v } = vrs;
const { r, s } = vrs;

Expand All @@ -37,9 +37,7 @@ async function signTx(

// addSignature will handle the v value
const tx = ethTx;
tx.signature.v = BigInt(v);
tx.signature.r = r;
tx.signature.s = s;
tx.signature = Signature.from({ v, r: `0x${r.toString("hex")}`, s: `0x${s.toString("hex")}` });

return tx.serialized as PrefixedHexString;
}
Expand Down

0 comments on commit 7f1fa72

Please sign in to comment.