diff --git a/src/hdnode.js b/src/hdnode.js index fbf0577..bf84c45 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -124,6 +124,10 @@ HDNode.fromBase58 = function (string, networks) { return hd } +HDNode.prototype.getAddress = function () { + return this.keyPair.getAddress() +} + HDNode.prototype.getIdentifier = function () { return bcrypto.hash160(this.keyPair.getPublicKeyBuffer()) } @@ -132,10 +136,6 @@ HDNode.prototype.getFingerprint = function () { return this.getIdentifier().slice(0, 4) } -HDNode.prototype.getAddress = function () { - return this.keyPair.getAddress() -} - HDNode.prototype.neutered = function () { var neuteredKeyPair = new ECPair(null, this.keyPair.Q, { network: this.keyPair.network diff --git a/test/hdnode.js b/test/hdnode.js index 3bfed8d..c7ab317 100644 --- a/test/hdnode.js +++ b/test/hdnode.js @@ -2,6 +2,7 @@ /* eslint-disable no-new */ var assert = require('assert') +var ecdsa = require('../src/ecdsa') var sinon = require('sinon') var BigInteger = require('bigi') @@ -9,6 +10,7 @@ var ECPair = require('../src/ecpair') var HDNode = require('../src/hdnode') var fixtures = require('./fixtures/hdnode.json') +var curve = ecdsa.__curve var NETWORKS = require('../src/networks') var NETWORKS_LIST = [] // Object.values(NETWORKS) @@ -68,6 +70,24 @@ describe('HDNode', function () { }) }) + it('throws if IL is not within interval [1, n - 1] | IL === 0', sinon.test(function () { + this.mock(BigInteger).expects('fromBuffer') + .once().returns(BigInteger.ZERO) + + assert.throws(function () { + HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') + }, /Private key must be greater than 0/) + })) + + it('throws if IL is not within interval [1, n - 1] | IL === n', sinon.test(function () { + this.mock(BigInteger).expects('fromBuffer') + .once().returns(curve.n) + + assert.throws(function () { + HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') + }, /Private key must be less than the curve order/) + })) + it('throws on low entropy seed', function () { assert.throws(function () { HDNode.fromSeedHex('ffffffffff')