Last active
December 26, 2023 22:52
-
-
Save sogoiii/5846ea3a581d1825bd745308895e8455 to your computer and use it in GitHub Desktop.
Validate a signature in javascript using solidity
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 SignVerifyArtifact = require('./contracts/SignAndVerifyExample') | |
const SignVerify = contract(SignVerifyArtifact) | |
SignVerify.setProvider(provider) | |
//... | |
SignVerify | |
.deployed() | |
.then(instance => { | |
let fixed_msg = `\x19Ethereum Signed Message:\n${msg.length}${msg}` | |
let fixed_msg_sha = web3.sha3(fixed_msg) | |
return instance.verify.call( | |
fixed_msg_sha, | |
v_decimal, | |
r, | |
s | |
) | |
}) | |
.then(data => { | |
console.log('-----data------') | |
console.log(`input addr ==> ${addr}`) | |
console.log(`output addr => ${data}`) | |
}) | |
.catch(e => { | |
console.error(e) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment