Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
/ sol-ecverify Public archive

A solidity library for verifying elliptic curve signatures in Ethereum (ecrecover)

License

Notifications You must be signed in to change notification settings

miguelmota/sol-ecverify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


logo


sol-ecverify

A solidity library for verifying elliptic curve signatures in Ethereum (wrapper around ecrecover).

API

  • ecrecovery(hash, sig) -> address

    • {bytes32} hash - 32 byte sha3 (keccak256) hash of original message data

    • {bytes} sig - 65 byte signature string

  • ecverify(hash, sig, account) -> bool

    • {bytes32} hash - 32 byte sha3 (keccak256) hash of original message data

    • {bytes} sig - 65 byte signature string

    • {address} signer - 20 byte address of proposed signer

Getting started

const {sha3} = require('ethereumjs-util')
const account = '0xa462d983B4b8C855e1876e8c24889CBa466A67EB'

const msg = Buffer.from('some data')
const sig = web3.eth.sign(account, `0x${msg.toString('hex')}`)

// https://github.com/ethereum/go-ethereum/issues/3731
const prefix = Buffer.from('\x19Ethereum Signed Message:\n');
const pmsg = `0x${sha3(Buffer.concat([prefix, Buffer.from(String(msg.length)), msg])).toString('hex')}`

var signer = await ECVerify.ecrecovery(pmsg, sig)
console.log(signer) // "0xa462d983B4b8C855e1876e8c24889CBa466A67EB"

var verified = await ECVerify.ecverify(pmsg, sig, account)
console.log(verified) // true

Test

truffle test

Credit

Thanks to @axic for providing this gist (#79)

License

MIT