Merge pull request #79 from Dcousens/master
Fixes #78 for alternative constructor syntax
This commit is contained in:
commit
807972bbaf
2 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue