Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Move this to paritytech/js-libs? #4

Open
amaury1093 opened this issue Oct 31, 2018 · 1 comment
Open

Move this to paritytech/js-libs? #4

amaury1093 opened this issue Oct 31, 2018 · 1 comment

Comments

@amaury1093
Copy link

I deliberately didn't include this one into the maintained-by-parity repos: https://github.com/paritytech/js-libs.

If we decide to take care of it, it would be nice to include it too.

@mikeygbooth99
Copy link

// Change accountToSignWith to the address of your account.

var Web3 = require('web3');
var web3 = new Web3();

web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

var accountToSignWith = '0xbedcf417ff2752d996d2ade98b97a6f0bef4beb9';
var message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tubulum fuisse, qua illum, cuius is condemnatus est rogatione, P. Eaedem res maneant alio modo.'

var contractSource = contract SignAndVerifyExample { function RecoverAddress(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) constant returns (address) { return ecrecover(msgHash, v, r, s); } };

var contractABI = [{"constant":true,"inputs":[{"name":"msgHash","type":"bytes32"},{"name":"v","type":"uint8"},{"name":"r","type":"bytes32"},{"name":"s","type":"bytes32"}],"name":"RecoverAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"}];
var contractAddress = '0x5481c0fe170641bd2e0ff7f04161871829c1902d'; // on Ropsten and Rinkeby

var signAndVerifyContract = web3.eth.contract(contractABI).at(contractAddress);

// eth_sign calculated the signature over keccak256("\x19Ethereum Signed Message:\n" + len(givenMessage) + givenMessage)))
// this gives context to a signature and prevents signing of transactions.
function messageHash(msg) {
return web3.sha3('\x19Ethereum Signed Message:\n' + msg.length + msg);
}

function verifyHandler(err, address) {
if (!err) {
console.log('Recovered address:', address);
console.log(' Address matched:', accountToSignWith === address);
} else {
console.err('Could not recover address:', err);
}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants