Created
January 20, 2024 19:00
-
-
Save nizhunt/0befadff766dbb8667f95559cd80db02 to your computer and use it in GitHub Desktop.
Calyptus Solidity Challenge #271 🕵️♂️
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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