SiweMessage.validateMessage


Express app

“dependencies”: {
@lit-protocol/lit-node-client”: “^2.2.54”,
@metamask/eth-sig-util”: “^6.0.0”,
@spheron/storage”: “^2.0.0”,
“axios”: “^1.4.0”,
“dotenv”: “^16.3.1”,
“ethers”: “^5.7.2”,
“express”: “^4.18.2”,
“jsonwebtoken”: “^9.0.1”,
“mongoose”: “^7.5.0”,
“multer”: “^1.4.5-lts.1”,
“siwe”: “^2.1.4”,
“uuid”: “^9.0.0”,
“validator”: “^13.9.0”
}

	const authSig = await signAuthMessage(walletPrivateKey);

const siwe = require(“siwe”);
const { Wallet, verifyMessage } = require(“ethers”);

const domain = “localhost”;
const origin = “https://localhost/login”;

const signAuthMessage = async (privKey) => {
const wallet = new Wallet(privKey);
const statement =
“This is a test statement. You can put anything you want here.”;

console.log("Signing message with address: ", wallet.address);
const siweMessage = new siwe.SiweMessage({
	domain,
	address: wallet.address,
	statement,
	uri: origin,
	version: "1",
	chainId: 1,
});

const messageToSign = siweMessage.prepareMessage();
const signature = await wallet.signMessage(messageToSign);
const recoveredAddress = verifyMessage(messageToSign, signature);

const authSig = {
	sig: signature,
	derivedVia: "web3.eth.personal.sign",
	signedMessage: messageToSign,
	address: recoveredAddress,
};

return authSig;

};

module.exports = { signAuthMessage };

What’s your questions here?