From 74ee2f90d0c6c59842e2846a3390a62bdf6ab9d0 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 22 Mar 2014 16:26:44 +1100 Subject: [PATCH 1/2] Adds failing test for #78 --- test/eckey.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/eckey.js b/test/eckey.js index c0caa41..fb3f3af 100644 --- a/test/eckey.js +++ b/test/eckey.js @@ -110,5 +110,17 @@ describe('ECKey', function() { assert.equal(key.version, testnet); assert.equal(key.toBase58(), priv); }) + + it('initiation via alternative constructor syntax', function() { + var priv = 'ca48ec9783cf3ad0dfeff1fc254395a2e403cbbc666477b61b45e31d3b8ab458'; + var pub = '044b12d9d7c77db68388b6ff7c89046174c871546436806bcd80d07c28ea81199' + + '283fbec990dad6fb98f93f712d50cb874dd717de6a184158d63886dda3090f566'; + var key = ECKey(priv, false, testnet); + + assert.equal(key.getPub().toHex(), pub); + assert.equal(key.compressed, false); + assert.equal(key.version, testnet); + assert.equal(key.toHex(), priv); + }) }) }) From a1be488d1b7de536de811cbfa7fa3a8d8a0d6b23 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 22 Mar 2014 16:27:10 +1100 Subject: [PATCH 2/2] Fixes #78 --- src/eckey.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eckey.js b/src/eckey.js index 62b8f87..72321e3 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -14,7 +14,7 @@ var ecparams = sec("secp256k1"); // input can be nothing, array of bytes, hex string, or base58 string var ECKey = function (input,compressed,version) { - if (!(this instanceof ECKey)) { return new ECKey(input,compressed); } + if (!(this instanceof ECKey)) { return new ECKey(input,compressed,version); } if (!input) { // Generate new key var n = ecparams.getN(); @@ -56,7 +56,7 @@ ECKey.prototype.import = function (input,compressed,version) { : input.length == 65 ? true : null - this.version = + this.version = version !== undefined ? version : input instanceof ECKey ? input.version : input instanceof BigInteger ? mainnet