eth-sig-util
Advanced tools
Comparing version 1.1.1 to 1.2.0
23
index.js
@@ -29,8 +29,3 @@ const ethUtil = require('ethereumjs-util') | ||
recoverPersonalSignature: function (msgParams) { | ||
let senderHex | ||
const message = ethUtil.toBuffer(msgParams.data) | ||
const msgHash = ethUtil.hashPersonalMessage(message) | ||
const signature = ethUtil.toBuffer(msgParams.sig) | ||
const sigParams = ethUtil.fromRpcSig(signature) | ||
const publicKey = ethUtil.ecrecover(msgHash, sigParams.v, sigParams.r, sigParams.s) | ||
const publicKey = getPublicKeyFor(msgParams) | ||
const sender = ethUtil.publicToAddress(publicKey) | ||
@@ -41,4 +36,20 @@ senderHex = ethUtil.bufferToHex(sender) | ||
extractPublicKey: function (msgParams) { | ||
const publicKey = getPublicKeyFor(msgParams) | ||
return '0x' + publicKey.toString('hex') | ||
}, | ||
} | ||
function getPublicKeyFor (msgParams) { | ||
let senderHex | ||
const message = ethUtil.toBuffer(msgParams.data) | ||
const msgHash = ethUtil.hashPersonalMessage(message) | ||
const signature = ethUtil.toBuffer(msgParams.sig) | ||
const sigParams = ethUtil.fromRpcSig(signature) | ||
const publicKey = ethUtil.ecrecover(msgHash, sigParams.v, sigParams.r, sigParams.s) | ||
return publicKey | ||
} | ||
function padWithZeroes (number, length) { | ||
@@ -45,0 +56,0 @@ var myString = '' + number |
{ | ||
"name": "eth-sig-util", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A few useful functions for signing ethereum data", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,1 +29,7 @@ # Eth-Sig-Util [![CircleCI](https://circleci.com/gh/flyswatter/eth-sig-util.svg?style=svg)](https://circleci.com/gh/flyswatter/eth-sig-util) | ||
### extractPublicKey (msgParams) | ||
msgParams should have a `data` key that is hex-encoded data unsigned, and a `sig` key that is hex-encoded and already signed. | ||
Returns a hex-encoded public key. | ||
@@ -22,2 +22,3 @@ const test = require('tape') | ||
const address = '0x29c76e6ad8f28bb1004902578fb108c507be341b' | ||
console.log('for address ' + address) | ||
const privKeyHex = '4af1bceebf7f3634ec3cff8a2c38e51178d5d4ce585c52d6043e5e2cc3418bb0' | ||
@@ -35,2 +36,22 @@ const privKey = new Buffer(privKeyHex, 'hex') | ||
test('personalSign and extractPublicKey', function (t) { | ||
t.plan(1) | ||
const address = '0x29c76e6ad8f28bb1004902578fb108c507be341b' | ||
const privKeyHex = '4af1bceebf7f3634ec3cff8a2c38e51178d5d4ce585c52d6043e5e2cc3418bb0' | ||
const pubKeyHex = '0x9e9e45b2ec5f070b4e26f57c7fedf647afa7a03e894789816fbd12fedc5acd79d0dfeea925688e177caccb8f5e09f0c289bbcfc7adb98d76f5f8c5259478903a' | ||
const privKey = new Buffer(privKeyHex, 'hex') | ||
const message = 'Hello, world!' | ||
const msgParams = { data: message } | ||
const signed = sigUtil.personalSign(privKey, msgParams) | ||
msgParams.sig = signed | ||
const publicKey = sigUtil.extractPublicKey(msgParams) | ||
t.equal(publicKey, pubKeyHex) | ||
}) | ||
signatureTest({ | ||
@@ -37,0 +58,0 @@ testLabel: 'geth kumavis manual I', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7167
123
35