eth-sig-util
Advanced tools
Comparing version 1.0.0 to 1.1.0
20
index.js
@@ -20,2 +20,22 @@ const ethUtil = require('ethereumjs-util') | ||
personalSign: function (privateKey, msgParams) { | ||
var message = ethUtil.toBuffer(msgParams.data) | ||
var msgHash = ethUtil.hashPersonalMessage(message) | ||
var sig = ethUtil.ecsign(msgHash, privateKey) | ||
var serialized = ethUtil.bufferToHex(this.concatSig(sig.v, sig.r, sig.s)) | ||
return serialized | ||
}, | ||
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 sender = ethUtil.publicToAddress(publicKey) | ||
senderHex = ethUtil.bufferToHex(sender) | ||
return senderHex | ||
}, | ||
} | ||
@@ -22,0 +42,0 @@ |
{ | ||
"name": "eth-sig-util", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A few useful functions for signing ethereum data", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/index.js" | ||
}, | ||
@@ -25,3 +25,7 @@ "repository": { | ||
"ethereumjs-util": "^5.1.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.2.0", | ||
"tape": "^4.6.3" | ||
} | ||
} |
@@ -16,1 +16,14 @@ # Eth-Sig-Util | ||
Takes an address of either upper or lower case, with or without a hex prefix, and returns an all-lowercase, hex-prefixed address, suitable for submitting to an ethereum provider. | ||
### personalSign (privateKeyBuffer, msgParams) | ||
msgParams should have a `data` key that is hex-encoded data to sign. | ||
Returns the prefixed signature expected for calls to `eth.personalSign`. | ||
### recoverPersonalSignature (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 sender address. | ||
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5890
6
101
0
29
2