@keplr-ewallet/ewallet-sdk-eth
Version:
20 lines • 760 B
JavaScript
import { pad, toHex } from "viem";
import { secp256k1 } from "@noble/curves/secp256k1";
export const encodeEthereumSignature = (signOutput, chainId) => {
const { sig, is_high } = signOutput;
const bigRHexWithout0x = sig.big_r.replace(/^0x/, "");
const point = secp256k1.Point.fromHex(bigRHexWithout0x);
const r = pad(toHex(point.x), { dir: "left", size: 32 });
const isYOdd = point.y % BigInt(2) === BigInt(1);
let v = isYOdd ? 28 : 27;
if (is_high) {
v = v === 27 ? 28 : 27;
}
if (chainId != null) {
v += chainId * 2 + 8;
}
const sHex = ("0x" + sig.s.replace(/^0x/, ""));
const s = pad(sHex, { dir: "left", size: 32 });
return { r, s, v: BigInt(v) };
};
//# sourceMappingURL=signature.js.map