Comparing version 0.5.0 to 0.6.0
@@ -0,1 +1,6 @@ | ||
0.6.0 / 2014-06-03 | ||
------------------ | ||
* added field `pubKeyHash` and alias `publicHash` | ||
* removed semicolons (CryptoCoinJS should no longer use them) | ||
0.5.0 / 2014-06-03 | ||
@@ -2,0 +7,0 @@ ------------------ |
@@ -0,1 +1,3 @@ | ||
var crypto = require('crypto') | ||
var ecurve = require('ecurve') | ||
@@ -10,3 +12,3 @@ var ECPointFp = ecurve.ECPointFp | ||
function ECKey (bytes, compressed) { | ||
if (!(this instanceof ECKey)) return new ECKey(bytes, compressed); | ||
if (!(this instanceof ECKey)) return new ECKey(bytes, compressed) | ||
@@ -19,3 +21,3 @@ if (typeof compressed == 'boolean') | ||
if (bytes) | ||
this.privateKey = bytes; | ||
this.privateKey = bytes | ||
} | ||
@@ -30,33 +32,33 @@ | ||
get: function() { | ||
return this.key; | ||
return this.key | ||
}, | ||
set: function(bytes) { | ||
var byteArr; | ||
var byteArr | ||
if (Buffer.isBuffer(bytes)) { | ||
this.key = bytes; | ||
byteArr = [].slice.call(bytes); | ||
this.key = bytes | ||
byteArr = [].slice.call(bytes) | ||
} else if (bytes instanceof Uint8Array) { | ||
byteArr = [].slice.call(bytes); | ||
this.key = new Buffer(byteArr); | ||
byteArr = [].slice.call(bytes) | ||
this.key = new Buffer(byteArr) | ||
} else if (Array.isArray(bytes)) { | ||
byteArr = bytes; | ||
this.key = new Buffer(byteArr); | ||
byteArr = bytes | ||
this.key = new Buffer(byteArr) | ||
} else { | ||
throw new Error('Invalid type. 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.') | ||
} | ||
if (bytes.length != 32) | ||
throw new Error("private key bytes must have a length of 32"); | ||
throw new Error("private key bytes must have a length of 32") | ||
//_exportKey => privateKey + (0x01 if compressed) | ||
if (this._compressed) | ||
this._exportKey = Buffer.concat([ this.key, new Buffer([0x01]) ]); | ||
this._exportKey = Buffer.concat([ this.key, new Buffer([0x01]) ]) | ||
else | ||
this._exportKey = Buffer.concat([ this.key ]); //clone key as opposed to passing a reference (relevant to Node.js only) | ||
this._exportKey = Buffer.concat([ this.key ]) //clone key as opposed to passing a reference (relevant to Node.js only) | ||
this.keyBigInteger = BigInteger.fromByteArrayUnsigned(byteArr); | ||
this.keyBigInteger = BigInteger.fromByteArrayUnsigned(byteArr) | ||
//reset | ||
this._publicPoint = null; | ||
this._pubKeyHash = null; | ||
this._publicPoint = null | ||
this._pubKeyHash = null | ||
} | ||
@@ -67,9 +69,24 @@ }) | ||
get: function() { | ||
return this._exportKey; | ||
return this._exportKey | ||
} | ||
}) | ||
Object.defineProperty(ECKey.prototype, 'publicHash', { | ||
get: function() { | ||
return this.pubKeyHash | ||
} | ||
}) | ||
Object.defineProperty(ECKey.prototype, 'pubKeyHash', { | ||
get: function() { | ||
if (this._pubKeyHash) return this._pubKeyHash | ||
var sha = crypto.createHash('sha256').update(this.publicKey).digest() | ||
this._pubKeyHash = crypto.createHash('rmd160').update(sha).digest() | ||
return this._pubKeyHash | ||
} | ||
}) | ||
Object.defineProperty(ECKey.prototype, 'publicKey', { | ||
get: function() { | ||
return new Buffer(this.publicPoint.getEncoded(this.compressed)); | ||
return new Buffer(this.publicPoint.getEncoded(this.compressed)) | ||
} | ||
@@ -81,5 +98,5 @@ }) | ||
if (!this._publicPoint) { | ||
this._publicPoint = ecparams.g.multiply(this.keyBigInteger); | ||
this._publicPoint = ecparams.g.multiply(this.keyBigInteger) | ||
} | ||
return this._publicPoint; | ||
return this._publicPoint | ||
} | ||
@@ -90,12 +107,12 @@ }) | ||
get: function() { | ||
return this._compressed; | ||
return this._compressed | ||
}, | ||
set: function(val) { | ||
var c = !!val; | ||
if (c === this._compressed) return; | ||
var c = !!val | ||
if (c === this._compressed) return | ||
//reset key stuff | ||
var pk = this.privateKey; | ||
this._compressed = c; | ||
this.privateKey = pk; | ||
var pk = this.privateKey | ||
this._compressed = c | ||
this.privateKey = pk | ||
} | ||
@@ -110,3 +127,3 @@ }) | ||
ECKey.prototype.toString = function (format) { | ||
return this.privateKey.toString('hex'); | ||
return this.privateKey.toString('hex') | ||
} | ||
@@ -113,0 +130,0 @@ |
{ | ||
"name": "eckey", | ||
"version": "0.5.0", | ||
"description": "Elliptical curve cryptography for crypto currencies such as Litecoin and Bitcoin", | ||
"version": "0.6.0", | ||
"description": "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.", | ||
"keywords": [ | ||
@@ -20,7 +20,8 @@ "cryptography", | ||
"secure-random": "^1.0.0", | ||
"mochify": "~0.4.2", | ||
"mochify": "^0.9.3", | ||
"coveralls": "^2.10.0", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"istanbul": "^0.2.10", | ||
"string": "^1.8.1" | ||
"string": "^1.8.1", | ||
"crypto-browserify": "^2.1.8" | ||
}, | ||
@@ -36,2 +37,5 @@ "repository": { | ||
}, | ||
"browser": { | ||
"crypto": "crypto-browserify" | ||
}, | ||
"scripts": { | ||
@@ -38,0 +42,0 @@ "test": "mocha --ui bdd", |
@@ -12,4 +12,5 @@ eckey | ||
Official documenation: | ||
http://cryptocoinjs.com/modules/currency/eckey/ |
8482
100
15
9