Created
March 3, 2017 03:28
-
-
Save AlwaysBCoding/e28637188cfeeb3db4695ca1c17c18d6 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 18 | Signing Arbitrary Messages
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
// Private Key | |
var pKey = "..." | |
var pKeyx = new Buffer(pKey, "hex") | |
// Shared Message | |
var message = "..." | |
var messageHash = web3.sha3(message) | |
var messageHashx = new Buffer(messageHash.replace("0x", ""), "hex") | |
// Signed Hash | |
var signedMessage = EthUtil.ecsign(messageHashx, pKeyx) | |
var signedHash = EthUtil.toRpcSig(signedMessage.v, signedMessage.r, signedMessage.s).toString("hex") | |
// Recover Address | |
var sigDecoded = EthUtil.fromRpcSig(signedHash) | |
var recoveredPub = EthUtil.ecrecover(messageHashx, sigDecoded.v, sigDecoded.r, sigDecoded.s) | |
var recoveredAddress = EthUtil.pubToAddress(recoveredPub).toString("hex") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment