Comparing version 0.4.2 to 0.5.0
@@ -0,1 +1,14 @@ | ||
0.5.0 / 2014-06-03 | ||
------------------ | ||
* add TravisCI | ||
* add Coveralls | ||
* upgraded `secure-random@~0.2.1` to `secure-random@^1.0.0` dev dep | ||
* removed `ecurve-names` dep, functionality is now present in `ecurve` | ||
* upgraded from `ecurve@~0.3.x` to `ecurve@^0.6.0` | ||
* removed static field `compressByDefault` | ||
* field `compressed` is now set to `true` by default | ||
* upgraded `terst` dev dep to `0.2.0` | ||
* upgraded `bigi@~0.2.0` to `bigi@^1.1.0` | ||
* add testling | ||
0.4.2 / 2014-04-17 | ||
@@ -2,0 +15,0 @@ ------------------ |
@@ -1,4 +0,5 @@ | ||
var ECPointFp = require('ecurve').ECPointFp; | ||
var ecparams = require('ecurve-names')('secp256k1'); | ||
var BigInteger = require('bigi'); | ||
var ecurve = require('ecurve') | ||
var ECPointFp = ecurve.ECPointFp | ||
var ecparams = ecurve.getECParams('secp256k1') | ||
var BigInteger = require('bigi') | ||
@@ -11,3 +12,6 @@ module.exports = ECKey | ||
this._compressed = compressed || !!ECKey.compressByDefault; | ||
if (typeof compressed == 'boolean') | ||
this._compressed = compressed | ||
else | ||
this._compressed = true | ||
@@ -19,8 +23,2 @@ if (bytes) | ||
/******************** | ||
* STATIC PROPERTIES | ||
********************/ | ||
ECKey.compressByDefault = false; | ||
/******************** | ||
* GET/SET PROPERTIES | ||
@@ -46,3 +44,3 @@ ********************/ | ||
} else { | ||
throw new Error('private key bytes must be either a Buffer, Array, or Uint8Array.'); | ||
throw new Error('Invalid type. private key bytes must be either a Buffer, Array, or Uint8Array.'); | ||
} | ||
@@ -81,4 +79,5 @@ | ||
get: function() { | ||
if (!this._publicPoint) | ||
this._publicPoint = ecparams.getG().multiply(this.keyBigInteger); | ||
if (!this._publicPoint) { | ||
this._publicPoint = ecparams.g.multiply(this.keyBigInteger); | ||
} | ||
return this._publicPoint; | ||
@@ -108,6 +107,2 @@ } | ||
/*ECKey.prototype.setPub = function (pub) { | ||
this.pub = ECPointFp.decodeFrom(ecparams.getCurve(), pub); | ||
};*/ | ||
ECKey.prototype.toString = function (format) { | ||
@@ -114,0 +109,0 @@ return this.privateKey.toString('hex'); |
{ | ||
"name": "eckey", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Elliptical curve cryptography for crypto currencies such as Litecoin and Bitcoin", | ||
@@ -17,7 +17,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"mocha": "1.*", | ||
"terst": "~0.1.0", | ||
"binstring": "~0.2.0", | ||
"secure-random": "~0.2.0", | ||
"mochify": "~0.4.2" | ||
"mocha": "^1.20.0", | ||
"terst": "^0.2.0", | ||
"secure-random": "^1.0.0", | ||
"mochify": "~0.4.2", | ||
"coveralls": "^2.10.0", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"istanbul": "^0.2.10", | ||
"string": "^1.8.1" | ||
}, | ||
@@ -30,6 +33,22 @@ "repository": { | ||
"dependencies": { | ||
"ecurve": "~0.3.0", | ||
"ecurve-names": "~0.3.0", | ||
"bigi": "0.2.x" | ||
"ecurve": "^0.6.0", | ||
"bigi": "^1.1.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha --ui bdd", | ||
"unit": "./node_modules/.bin/mocha", | ||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js", | ||
"coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"firefox/latest", | ||
"chrome/latest", | ||
"ie/9..latest", | ||
"safari/6..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2..latest" | ||
] | ||
} | ||
} |
151
README.md
eckey | ||
===== | ||
JavaScript component for Elliptical curve cryptography for crypto currencies such as Bitcoin, Litecoin, Dogecoin, etc. | ||
[![build status](https://secure.travis-ci.org/cryptocoinjs/eckey.png)](http://travis-ci.org/cryptocoinjs/eckey) | ||
[![Coverage Status](https://img.shields.io/coveralls/cryptocoinjs/eckey.svg)](https://coveralls.io/r/cryptocoinjs/eckey) | ||
[![Version](http://img.shields.io/npm/v/eckey.svg)](https://www.npmjs.org/package/eckey) | ||
[![browser support](https://ci.testling.com/cryptocoinjs/eckey.png)](https://ci.testling.com/cryptocoinjs/eckey) | ||
Why? | ||
---- | ||
JavaScript component to handle private key and public keys associated with elliptic curve cryptography. Used with crypto currencies such as Bitcoin, Litecoin, Dogecoin, etc. Works in both Node.js and the browser. | ||
This module provides a convenient way to compute relevant crypto currency operations that adhere to elliptical curve cryptography. To | ||
really understand how private keys, public keys, addresses, and how elliptical curve cryptography works with JavaScript, read this: http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript | ||
Official documenation: | ||
Installation | ||
------------ | ||
npm install --save eckey | ||
Usage | ||
----- | ||
### API | ||
#### ECKey([bytes], [compressed]) | ||
Constructor function. | ||
- **bytes**: The private key bytes. Must be 32 bytes in length. Should be an `Array`, `Uint8Array`, or a `Buffer`. | ||
- **compressed**: Specify whether the key should be compressed or not. | ||
```js | ||
var ECKey = require('eckey'); | ||
var secureRandom = require('secure-random'); | ||
var bytes = secureRandom(32); //https://github.com/jprichardson/secure-random | ||
var key1 = new ECKey(bytes); | ||
var key2 = ECKey(bytes); //<--- can also use without "new" | ||
var compressedKey = new ECKey(bytes, true); | ||
``` | ||
Note: Previous versions of this module would generate a random array of bytes for you if you didn't pass as input any to the constructor. This behavior has been removed to remove complexity and to ensure that the random generation is done securely. In the past, it wasn't. | ||
#### compressed | ||
Get/set whether the point on the curve is compressed. Affects the output of the WIF (wallet import format) and the address. | ||
#### privateKey | ||
Get/set the private key. When setting, the type can be either an `Array`, `Buffer`, or `Uint8Array`. When getting, the type is always `Buffer`. Setting would be useful if you don't pass a private key to the constructor. | ||
```js | ||
var ECKey = require('eckey'); | ||
var conv = require('binstring'); | ||
var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"; | ||
var key = new ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), false); | ||
console.log(key.privatekey.toString('hex')); // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd | ||
var keyCompressed = ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), true); | ||
//nothing changes when compressed | ||
console.log(key.privatekey.toString('hex')); // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd | ||
``` | ||
#### privateExportKey | ||
Get the private key along with a byte for compression if `compressed` is true. i.e. | ||
if compressed | ||
privateExportKey = privateKey + 0x01 | ||
else | ||
privateExportKey = privateKey | ||
This is useful inconjunction with the package [coinstring](https://github.com/cryptocoinjs/coinstring) to generate | ||
[Wallet Import Format](https://en.bitcoin.it/wiki/Wallet_import_format) keys. | ||
```js | ||
var ECKey = require('eckey'); | ||
var conv = require('binstring'); | ||
var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"; | ||
var key = new ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), false); | ||
console.log(key.privateExportKey.toString('hex')); // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd | ||
var keyCompressed = new ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), true); | ||
//notice the extra "01" at the end? | ||
console.log(key.privateExportKey.toString('hex')); // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd01 | ||
``` | ||
#### publicKey | ||
Get the public key. The type is `Buffer`. | ||
```js | ||
var ECKey = require('eckey'); | ||
var conv = require('binstring'); | ||
var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"; | ||
var key = new ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), false); | ||
console.log(key.publickey.toString('hex')); | ||
// => 04d0988bfa799f7d7ef9ab3de97ef481cd0f75d2367ad456607647edde665d6f6fbdd594388756a7beaf73b4822bc22d36e9bda7db82df2b8b623673eefc0b7495 | ||
var keyCompressed = ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), true); | ||
console.log(key.publickey.toString('hex')); | ||
// => 03d0988bfa799f7d7ef9ab3de97ef481cd0f75d2367ad456607647edde665d6f6f | ||
``` | ||
#### publicPoint | ||
Get the [Public Key Point](https://github.com/cryptocoinjs/ecurve/blob/master/lib/ecurve.js) on the Ellipitical Curve. | ||
#### toString() | ||
Returns the string representation of the private key. | ||
```js | ||
var ECKey = require('eckey'); | ||
var conv = require('binstring'); | ||
var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"; | ||
var key = new ECKey(conv(privateKeyHex, {in: 'hex', out: 'buffer'}), true); | ||
console.log(key.toString()) // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd | ||
``` | ||
References | ||
---------- | ||
- http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript | ||
- https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/eckey.js | ||
- https://github.com/vbuterin/bitcoinjs-lib/blob/master/src/eckey.js | ||
http://cryptocoinjs.com/modules/currency/eckey/ |
Sorry, the diff of this file is not supported yet
2
7712
8
86
14
+ Addedbigi@1.4.2(transitive)
+ Addedecurve@0.6.0(transitive)
- Removedecurve-names@~0.3.0
- Removedbigi@0.2.0(transitive)
- Removedecurve@0.3.2(transitive)
- Removedecurve-names@0.3.0(transitive)
Updatedbigi@^1.1.0
Updatedecurve@^0.6.0