Signing with EIP191
Use EIP191 eth_personal_sign
to sign a message instead of a transaction or raw signature.
This can be done with
LitActions.ethPersonalSignMessageEcdsa({ message, publicKey , sigName });
It will prepend "\x19Ethereum Signed Message:\n"
to the message and then hash and sign it according to https://eips.ethereum.org/EIPS/eip-191.
Lit Action code:
export const litActionCode = `
(async () => {
const sigShare = await LitActions.signEcdsa({
toSign: dataToSign,
publicKey,
sigName,
});
})();
`;
Lit SDK code:
const litActionSignatures = await litNodeClient.executeJs({
sessionSigs,
code: litActionCode,
jsParams: {
dataToSign: ethersUtils.arrayify(
ethersUtils.keccak256([1, 2, 3, 4, 5])
),
publicKey: pkpPublicKey,
sigName: "sig",
},
});
const dataSigned = `0x${signature.dataSigned}`;
const encodedSig = ethersUtils.joinSignature({
v: signature.recid,
r: `0x${signature.r}`,
s: `0x${signature.s}`,
});
const recoveredPubkey = ethersUtils.recoverPublicKey(dataSigned, encodedSig);
console.log("Recovered uncompressed public key: ", recoveredPubkey);
const recoveredAddress = ethersUtils.recoverAddress(dataSigned, encodedSig);
console.log("Recovered address from signature: ", recoveredAddress);
info
Not finding the answer you're looking for? Share your feedback on these docs by creating an issue in our GitHub Issues and Reports repository or get support by visiting our Support page.