Skip to main content
Version: v3.x.x

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.

const go = async () => {
const message = "Hello World";
const litNodeClient = new LitJsSdk.LitNodeClient({
litNetwork: "cayenne",
});
await litNodeClient.connect();

const signatures = await litNodeClient.executeJs({
code: litActionCode,
jsParams: {
// this is the string "Hello World" for testing
message,
publicKey:
"0x02e5896d70c1bc4b4844458748fe0f936c7919d7968341e391fb6d82c258192e64",
sigName: "sig1",
},
authSig,
});
console.log("signatures: ", signatures);
const sig = signatures.sig1;
const dataSigned = "0x" + sig.dataSigned;
const encodedSig = joinSignature({
r: "0x" + sig.r,
s: "0x" + sig.s,
v: sig.recid,
});

console.log("encodedSig", encodedSig);
console.log("sig length in bytes: ", encodedSig.substring(2).length / 2);
console.log("dataSigned", dataSigned);
const splitSig = splitSignature(encodedSig);
console.log("splitSig", splitSig);

const recoveredPubkey = recoverPublicKey(dataSigned, encodedSig);
console.log("uncompressed recoveredPubkey", recoveredPubkey);
const compressedRecoveredPubkey = computePublicKey(recoveredPubkey, true);
console.log("compressed recoveredPubkey", compressedRecoveredPubkey);
const recoveredAddress = recoverAddress(dataSigned, encodedSig);
console.log("recoveredAddress", recoveredAddress);

const recoveredAddressViaMessage = verifyMessage(message, encodedSig);
console.log("recoveredAddressViaMessage", recoveredAddressViaMessage);
};

go();