ethereumjs-util
Advanced tools
Comparing version 1.0.1 to 1.0.2
21
index.js
const SHA3 = require('sha3'), | ||
ec = require('elliptic').ec('secp256k1'); | ||
assert = require('assert'), | ||
@@ -7,5 +8,5 @@ rlp = require('rlp'), | ||
//the max interger that this VM can handle | ||
var MAX_INTEGER = exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16); | ||
const MAX_INTEGER = exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16); | ||
var TWO_POW256 = exports.TWO_POW256 = new BN('115792089237316195423570985008687907853269984665640564039457584007913129639936'); | ||
const TWO_POW256 = exports.TWO_POW256 = new BN('115792089237316195423570985008687907853269984665640564039457584007913129639936'); | ||
@@ -22,3 +23,3 @@ //hex string of SHA3-256 hash of `null` | ||
var ETH_UNITS = exports.ETH_UNITS = [ | ||
const ETH_UNITS = exports.ETH_UNITS = [ | ||
'wei', | ||
@@ -177,10 +178,15 @@ 'Kwei', | ||
*/ | ||
exports.pubToAddress = function(pubKey) { | ||
var pubToAddress = exports.pubToAddress = exports.publicToAddress = function(pubKey) { | ||
var hash = new SHA3.SHA3Hash(256); | ||
hash.update(pubKey.slice(1)); | ||
hash.update(pubKey.slice(-64)); | ||
return new Buffer(hash.digest('hex').slice(-40), 'hex'); | ||
}; | ||
exports.privateToAddress = function(privateKey){ | ||
privateKey = new BN(privateKey); | ||
var key = ec.keyFromPrivate(privateKey).getPublic().toJSON(); | ||
key = new Buffer(key[0].toArray().concat(key[1].toArray())); | ||
return pubToAddress(key); | ||
} | ||
/** | ||
@@ -266,3 +272,2 @@ * Generates a new address | ||
if (!(field.empty && v.length === 0) && field.length) { | ||
@@ -269,0 +274,0 @@ assert(field.length === v.length, 'The field ' + field.name + 'must have byte length of ' + field.length); |
{ | ||
"name": "ethereumjs-util", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "a collection of utility functions for Ethereum", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"crypto-js": "^3.1.5", | ||
"elliptic": "^3.1.0", | ||
"rlp": "^1.0.0", | ||
@@ -29,0 +30,0 @@ "sha3": "^1.1.0" |
@@ -86,3 +86,3 @@ var assert = require('assert'); | ||
var pubKey = 'f049a20000000000f0b08900000000000841b30200000000200000000d000000'; | ||
var address = '47f4f63d925e6b35f604a203a7ee365c147500db'; | ||
var address = 'ef6a1274aa67f83eadf383016d584cd6185477ae'; | ||
pubKey = new Buffer(pubKey, 'hex'); | ||
@@ -89,0 +89,0 @@ var r = ethUtils.pubToAddress(pubKey); |
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
17729
8
477
5
+ Addedelliptic@^3.1.0
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@3.1.0(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)