ethereumjs-util
Advanced tools
Comparing version 1.0.2 to 1.0.3
42
index.js
@@ -182,10 +182,26 @@ const SHA3 = require('sha3'), | ||
exports.privateToAddress = function(privateKey){ | ||
/** | ||
* Returns the ethereum public key of a given private key | ||
* @method privateToPublic | ||
* @param {Buffer} privateKey | ||
* @return {Buffer} | ||
*/ | ||
var privateToPublic = exports.privateToPublic = 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); | ||
return key; | ||
} | ||
/** | ||
* Returns the ethereum address of a given private key | ||
* @method privateToAddress | ||
* @param {Buffer} privateKey | ||
* @return {Buffer} | ||
*/ | ||
exports.privateToAddress = function(privateKey){ | ||
return pubToAddress(privateToPublic(privateKey)); | ||
} | ||
/** | ||
* Generates a new address | ||
@@ -245,5 +261,3 @@ * @method generateAddress | ||
if (typeof v === 'string') { | ||
if (v.slice(0, 2) === '0x') { | ||
v = v.slice(2); | ||
} | ||
v= stripHex(v); | ||
v = new Buffer(v, 'hex'); | ||
@@ -423,1 +437,19 @@ } else if (typeof v === 'number') { | ||
}; | ||
const isHexPrefixed = exports.isHexPrefixed = function(str){ | ||
return str.slice(0, 2) === '0x'; | ||
} | ||
const stripHex = exports.stripHex = function(str){ | ||
if (typeof str !== 'string') | ||
return str | ||
return isHexPrefixed ? str.slice(2) : str | ||
} | ||
exports.addHex = function(str){ | ||
if (typeof str !== 'string') | ||
return str | ||
return isHexPrefixed(str) ? '0x' + str : str | ||
} |
{ | ||
"name": "ethereumjs-util", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "a collection of utility functions for Ethereum", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -51,2 +51,10 @@ # SYNOPSIS [![Build Status](https://travis-ci.org/ethereum/ethereumjs-util.svg)](https://travis-ci.org/ethereum/ethereumjs-util) | ||
### `privateToPublic(privateKey)` | ||
Returns the ethereum public key of a given private key | ||
- `privateKey` - the private key as a `buffer` | ||
### `privateToAddress(privateKey)` | ||
Returns the ethereum address of a given private key | ||
- `privateKey` - the private key as a `buffer` | ||
### `defineProperties(self, fields)` | ||
@@ -53,0 +61,0 @@ defines properties on a `Object` |
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
18716
503
82