Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eckey

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eckey - npm Package Compare versions

Comparing version 0.8.0 to 1.0.0

39

CHANGELOG.md

@@ -0,1 +1,5 @@

1.0.0 / 2016-03-26
------------------
- upgraded to `secp256k1`. [#15][#15]
0.8.0 / 2014-09-29

@@ -47,3 +51,3 @@ ------------------

* removed `sign()` and `verify()`, methods can be accessed from [ecdsa](https://github.com/cryptocoinjs/ecdsa)
* added `privateExportKey`
* added `privateExportKey`
* removed `getExportedPrivateKey`, note that `getExportedPrivateKey` was essentially just a way to get WIF

@@ -80,3 +84,3 @@ * removed `decodeString()`, use package [coinstring][coinstring] in its place

------------------
* changed package name
* changed package name
* removed AMD support

@@ -88,2 +92,31 @@

[coinstring]: https://github.com/cryptocoinjs/coinstring
[coinstring]: https://github.com/cryptocoinjs/coinstring
<!--- secp256k1 instead ecurve -->
[#14]: https://github.com/cryptocoinjs/eckey/pull/14
<!--- Private key [1, n - 1] range -->
[#13]: https://github.com/cryptocoinjs/eckey/issues/13
<!--- Pass the `compressed` flag when used without `new` -->
[#12]: https://github.com/cryptocoinjs/eckey/pull/12
<!--- Fixed variable name -->
[#11]: https://github.com/cryptocoinjs/eckey/pull/11
<!--- Repository description -->
[#10]: https://github.com/cryptocoinjs/eckey/issues/10
<!--- Input is undefined -->
[#9]: https://github.com/cryptocoinjs/eckey/issues/9
<!--- Retarget for just NodeJS and Browserify -->
[#8]: https://github.com/cryptocoinjs/eckey/issues/8
<!--- Transition from convert-hex to binstring -->
[#7]: https://github.com/cryptocoinjs/eckey/issues/7
<!--- More explicit setting of testnet / prod net -->
[#6]: https://github.com/cryptocoinjs/eckey/issues/6
<!--- Adding checksum checks in ECkey decode strings -->
[#5]: https://github.com/cryptocoinjs/eckey/pull/5
<!--- update deps - makes eckey npm installable -->
[#4]: https://github.com/cryptocoinjs/eckey/pull/4
<!--- doesn't install: npm ERR! 404 'cryptocoin-base58' is not in the npm registry -->
[#3]: https://github.com/cryptocoinjs/eckey/issues/3
<!--- Fixed getExportedPrivateKey() returning uncompressed private key -->
[#2]: https://github.com/cryptocoinjs/eckey/pull/2
<!--- fix code typo [bug] -->
[#1]: https://github.com/cryptocoinjs/eckey/issues/1

75

lib/eckey.js
var crypto = require('crypto')
var secp256k1 = require('secp256k1')
var ecurve = require('ecurve')
var ecparams = ecurve.getCurveByName('secp256k1')
var BigInteger = require('bigi')
function ECKey (bytes, compressed) {
if (!(this instanceof ECKey)) return new ECKey(bytes, compressed)
if (typeof compressed == 'boolean')
this._compressed = compressed
else
this._compressed = true
if (bytes)
this.privateKey = bytes
this._compressed = typeof compressed === 'boolean' ? compressed : true
if (bytes) this.privateKey = bytes
}
/********************
* GET/SET PROPERTIES
********************/
Object.defineProperty(ECKey.prototype, 'privateKey', {
enumerable: true, configurable: true,
get: function() {
get: function () {
return this.key
},
set: function(bytes) {
set: function (bytes) {
var byteArr

@@ -43,15 +31,13 @@ if (Buffer.isBuffer(bytes)) {

if (bytes.length != 32)
throw new Error("private key bytes must have a length of 32")
if (bytes.length !== 32) throw new Error('private key bytes must have a length of 32')
//_exportKey => privateKey + (0x01 if compressed)
if (this._compressed)
// _exportKey => privateKey + (0x01 if compressed)
if (this._compressed) {
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)
} else {
this._exportKey = Buffer.concat([ this.key ]) // clone key as opposed to passing a reference (relevant to Node.js only)
}
this.keyBigInteger = BigInteger.fromByteArrayUnsigned(byteArr)
//reset
this._publicPoint = null
// reset
this._publicKey = null
this._pubKeyHash = null

@@ -62,3 +48,3 @@ }

Object.defineProperty(ECKey.prototype, 'privateExportKey', {
get: function() {
get: function () {
return this._exportKey

@@ -69,3 +55,3 @@ }

Object.defineProperty(ECKey.prototype, 'publicHash', {
get: function() {
get: function () {
return this.pubKeyHash

@@ -76,3 +62,3 @@ }

Object.defineProperty(ECKey.prototype, 'pubKeyHash', {
get: function() {
get: function () {
if (this._pubKeyHash) return this._pubKeyHash

@@ -86,25 +72,17 @@ var sha = crypto.createHash('sha256').update(this.publicKey).digest()

Object.defineProperty(ECKey.prototype, 'publicKey', {
get: function() {
return new Buffer(this.publicPoint.getEncoded(this.compressed))
get: function () {
if (!this._publicKey) this._publicKey = secp256k1.publicKeyCreate(this.key, this.compressed)
return new Buffer(this._publicKey)
}
})
Object.defineProperty(ECKey.prototype, 'publicPoint', {
get: function() {
if (!this._publicPoint) {
this._publicPoint = ecparams.G.multiply(this.keyBigInteger)
}
return this._publicPoint
}
})
Object.defineProperty(ECKey.prototype, 'compressed', {
get: function() {
get: function () {
return this._compressed
},
set: function(val) {
},
set: function (val) {
var c = !!val
if (c === this._compressed) return
//reset key stuff
// reset key stuff
var pk = this.privateKey

@@ -116,6 +94,2 @@ this._compressed = c

/************
* METHODS
************/
ECKey.prototype.toString = function (format) {

@@ -126,2 +100,1 @@ return this.privateKey.toString('hex')

module.exports = ECKey
{
"name": "eckey",
"version": "0.8.0",
"version": "1.0.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.",

@@ -17,10 +17,6 @@ "keywords": [

"devDependencies": {
"mocha": "^1.20.0",
"crypto-browserify": "^3.2.5",
"mocha": "2.x",
"secure-random": "^1.0.0",
"mochify": "^1.1.3",
"coveralls": "^2.10.0",
"mocha-lcov-reporter": "0.0.1",
"istanbul": "^0.2.10",
"string": "^1.8.1",
"crypto-browserify": "^3.2.5"
"standard": "6.x"
},

@@ -33,23 +29,9 @@ "repository": {

"dependencies": {
"ecurve": "^1.0.0",
"bigi": "^1.1.0"
"secp256k1": "^3.0.1"
},
"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",
"harness": "mocha",
"browsers": [
"firefox/latest",
"chrome/latest",
"ie/9..latest",
"safari/6..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
"lint": "standard",
"test": "standard && mocha --ui bdd",
"unit": "mocha --ui bdd"
}
}

@@ -5,7 +5,4 @@ eckey

[![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)
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.

@@ -16,2 +13,2 @@

http://cryptocoinjs.com/modules/currency/eckey/
http://cryptocoinjs.com/modules/currency/eckey/
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc