← backapr 18 2024
how to sign an already hashed message with ethers
how to sign an already hashed message with ethers, when you cant use wallet.signMessage, wallet.signTransaction, or wallet._signTypedData
ethers has 3 main sign methods:
wallet.signMessage- this hashes the given message, then signs it
wallat.signTransaction- serializes, hashes, then signs it
wallet._signTypedData- eip-712 hashes it, then signs it
but, if you have your own already hashed message you want to sign, you cant use either of these three.
you can, instead:
import { joinSignature, keccak256 } from 'ethers/lib/utils';
// assuming you already have a wallet instantiated
const signature = joinSignature(
wallet._signingKey().signDigest(ethers.utils.arrayify(msgHash))
);
deor.app/posts/how-to-sign-an-already-hashed-msg-ethers