Skip to content

Instantly share code, notes, and snippets.

@sogoiii
Last active December 26, 2023 22:52
Show Gist options
  • Save sogoiii/5846ea3a581d1825bd745308895e8455 to your computer and use it in GitHub Desktop.
Save sogoiii/5846ea3a581d1825bd745308895e8455 to your computer and use it in GitHub Desktop.
Validate a signature in javascript using solidity
//...
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