diff --git a/src/hdnode.js b/src/hdnode.js index bf84c45..33eb67c 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -149,6 +149,14 @@ HDNode.prototype.neutered = function () { return neutered } +HDNode.prototype.sign = function (hash) { + return this.keyPair.sign(hash) +} + +HDNode.prototype.verify = function (hash, signature) { + return this.keyPair.verify(hash, signature) +} + HDNode.prototype.toBase58 = function (__isPrivate) { if (__isPrivate !== undefined) throw new TypeError('Unsupported argument in 2.0.0') diff --git a/test/hdnode.js b/test/hdnode.js index c7ab317..a2e17d7 100644 --- a/test/hdnode.js +++ b/test/hdnode.js @@ -101,6 +101,51 @@ describe('HDNode', function () { }) }) + describe('ECPair wrappers', function () { + var keyPair, hd, hash + + beforeEach(function () { + keyPair = ECPair.makeRandom() + hash = new Buffer(32) + + var chainCode = new Buffer(32) + hd = new HDNode(keyPair, chainCode) + }) + + describe('getAddress', function () { + it('wraps keyPair.getAddress', sinon.test(function () { + this.mock(keyPair).expects('getAddress') + .once().withArgs().returns('foobar') + + assert.strictEqual(hd.getAddress(), 'foobar') + })) + }) + + describe('sign', function () { + it('wraps keyPair.sign', sinon.test(function () { + this.mock(keyPair).expects('sign') + .once().withArgs(hash).returns('signed') + + assert.strictEqual(hd.sign(hash), 'signed') + })) + }) + + describe('verify', function () { + var signature + + beforeEach(function () { + signature = hd.sign(hash) + }) + + it('wraps keyPair.verify', sinon.test(function () { + this.mock(keyPair).expects('verify') + .once().withArgs(hash, signature).returns('verified') + + assert.strictEqual(hd.verify(hash, signature), 'verified') + })) + }) + }) + describe('toBase58', function () { fixtures.valid.forEach(function (f) { it('exports ' + f.master.base58 + ' (public) correctly', function () { @@ -173,23 +218,6 @@ describe('HDNode', function () { }) }) - describe('getAddress', function () { - var hd - - beforeEach(function () { - var f = fixtures.valid[0] - - hd = HDNode.fromBase58(f.master.base58, NETWORKS_LIST) - }) - - it('wraps ECPair.getAddress', sinon.test(function () { - this.mock(hd.keyPair).expects('getAddress') - .once().returns('foobar') - - assert.strictEqual(hd.getAddress(), 'foobar') - })) - }) - describe('neutered', function () { var f = fixtures.valid[0]