Skip to content

Instantly share code, notes, and snippets.

@nizhunt
Created January 20, 2024 19:00
Show Gist options
  • Save nizhunt/0befadff766dbb8667f95559cd80db02 to your computer and use it in GitHub Desktop.
Save nizhunt/0befadff766dbb8667f95559cd80db02 to your computer and use it in GitHub Desktop.
Calyptus Solidity Challenge #271 🕵️‍♂️
const { ethers } = require("ethers");
// Replace with your private key
const privateKey = "YOUR_PRIVATE_KEY"; // NEVER commit your private key!
const yourAnswer = 144;
const yourTwitterHandle = "Abc"; //case-sensitive
// Connect to the wallet
const wallet = new ethers.Wallet(privateKey);
// Function to sign the message
async function signMessage() {
const message = ethers.utils.solidityKeccak256(
["uint256", "string"],
[yourAnswer, yourTwitterHandle]
);
const arrayifyMessage = ethers.utils.arrayify(message);
const signature = await wallet.signMessage(arrayifyMessage);
console.log("Message:", arrayifyMessage);
console.log("Signature:", signature);
console.log("address:", wallet.address);
}
signMessage().catch(console.error);
const { ethers } = require("ethers");
// The message that was signed - replace these with the actual values
const yourAnswer = 144;
const yourTwitterHandle = "Abc"; //case-sensitive
// The signature - replace this with the actual signature string
const signature = "YOUR_SIGNATURE";
// Function to retrieve the signer's address
async function getSignerAddress() {
// Recreate the message that was originally signed
const message = ethers.utils.solidityKeccak256(
["uint256", "string"],
[yourAnswer, yourTwitterHandle]
);
const arrayifyMessage = ethers.utils.arrayify(message);
// Recover the address of the signer
const signerAddress = ethers.utils.verifyMessage(arrayifyMessage, signature);
console.log("Signer Address:", signerAddress);
}
getSignerAddress().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment