|
|
@ -24,31 +24,22 @@ var derived_0_1_200000 = 'xpub6BqyndF6rkBNTV6LXwiY8Pco8aqctqq7tGEUdA8fmGDTnDJphn |
|
|
|
describe('HDPublicKey interface', function() { |
|
|
|
|
|
|
|
var expectFail = function(func, errorType) { |
|
|
|
var got = null; |
|
|
|
var error = null; |
|
|
|
try { |
|
|
|
(function() { |
|
|
|
func(); |
|
|
|
} catch (e) { |
|
|
|
error = e; |
|
|
|
got = e instanceof errorType; |
|
|
|
} |
|
|
|
if (!error instanceof errorType) { |
|
|
|
console.log('Error', typeof error); |
|
|
|
} |
|
|
|
// expect(got).to.equal(true);
|
|
|
|
}).should.throw(errorType); |
|
|
|
}; |
|
|
|
|
|
|
|
var expectDerivationFail = function(argument, error) { |
|
|
|
return expectFail(function() { |
|
|
|
(function() { |
|
|
|
var pubkey = new HDPublicKey(xpubkey); |
|
|
|
xpubkey.derive(argument); |
|
|
|
}, error); |
|
|
|
pubkey.derive(argument); |
|
|
|
}).should.throw(error); |
|
|
|
}; |
|
|
|
|
|
|
|
var expectFailBuilding = function(argument, error) { |
|
|
|
return expectFail(function() { |
|
|
|
(function() { |
|
|
|
return new HDPublicKey(argument); |
|
|
|
}, error); |
|
|
|
}).should.throw(error); |
|
|
|
}; |
|
|
|
|
|
|
|
describe('creation formats', function() { |
|
|
@ -225,16 +216,22 @@ describe('HDPublicKey interface', function() { |
|
|
|
|
|
|
|
it('doesn\'t allow other parameters like m\' or M\' or "s"', function() { |
|
|
|
/* jshint quotmark: double */ |
|
|
|
expectDerivationFail("m'", hdErrors.InvalidDerivationArgument); |
|
|
|
expectDerivationFail("M'", hdErrors.InvalidDerivationArgument); |
|
|
|
expectDerivationFail("1", hdErrors.InvalidDerivationArgument); |
|
|
|
expectDerivationFail("S", hdErrors.InvalidDerivationArgument); |
|
|
|
expectDerivationFail("m'", hdErrors.InvalidIndexCantDeriveHardened); |
|
|
|
expectDerivationFail("M'", hdErrors.InvalidIndexCantDeriveHardened); |
|
|
|
expectDerivationFail("1", hdErrors.InvalidPath); |
|
|
|
expectDerivationFail("S", hdErrors.InvalidPath); |
|
|
|
}); |
|
|
|
|
|
|
|
it('can\'t derive hardened keys', function() { |
|
|
|
expectFail(function() { |
|
|
|
return new HDPublicKey(xpubkey).derive(HDPublicKey.Hardened); |
|
|
|
}, hdErrors.InvalidDerivationArgument); |
|
|
|
}, hdErrors.InvalidIndexCantDeriveHardened); |
|
|
|
}); |
|
|
|
|
|
|
|
it('can\'t derive hardened keys via second argument', function() { |
|
|
|
expectFail(function() { |
|
|
|
return new HDPublicKey(xpubkey).derive(5, true); |
|
|
|
}, hdErrors.InvalidIndexCantDeriveHardened); |
|
|
|
}); |
|
|
|
|
|
|
|
it('validates correct paths', function() { |
|
|
|