|
@ -3,9 +3,7 @@ |
|
|
|
|
|
|
|
|
var assert = require('assert') |
|
|
var assert = require('assert') |
|
|
var ecdsa = require('../src/ecdsa') |
|
|
var ecdsa = require('../src/ecdsa') |
|
|
var sinon = require('sinon') |
|
|
var hoodwink = require('hoodwink') |
|
|
var sinonTest = require('sinon-test') |
|
|
|
|
|
var setupTest = sinonTest(sinon) |
|
|
|
|
|
|
|
|
|
|
|
var BigInteger = require('bigi') |
|
|
var BigInteger = require('bigi') |
|
|
var ECPair = require('../src/ecpair') |
|
|
var ECPair = require('../src/ecpair') |
|
@ -81,18 +79,20 @@ describe('HDNode', function () { |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it('throws if IL is not within interval [1, n - 1] | IL === 0', setupTest(function () { |
|
|
it('throws if IL is not within interval [1, n - 1] | IL === 0', hoodwink(function () { |
|
|
this.mock(BigInteger).expects('fromBuffer') |
|
|
this.mock(BigInteger, 'fromBuffer', function () { |
|
|
.once().returns(BigInteger.ZERO) |
|
|
return BigInteger.ZERO |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.throws(function () { |
|
|
assert.throws(function () { |
|
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') |
|
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') |
|
|
}, /Private key must be greater than 0/) |
|
|
}, /Private key must be greater than 0/) |
|
|
})) |
|
|
})) |
|
|
|
|
|
|
|
|
it('throws if IL is not within interval [1, n - 1] | IL === n', setupTest(function () { |
|
|
it('throws if IL is not within interval [1, n - 1] | IL === n', hoodwink(function () { |
|
|
this.mock(BigInteger).expects('fromBuffer') |
|
|
this.mock(BigInteger, 'fromBuffer', function () { |
|
|
.once().returns(curve.n) |
|
|
return curve.n |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.throws(function () { |
|
|
assert.throws(function () { |
|
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') |
|
|
HDNode.fromSeedHex('ffffffffffffffffffffffffffffffff') |
|
@ -124,38 +124,43 @@ describe('HDNode', function () { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('getAddress', function () { |
|
|
describe('getAddress', function () { |
|
|
it('wraps keyPair.getAddress', setupTest(function () { |
|
|
it('wraps keyPair.getAddress', hoodwink(function () { |
|
|
this.mock(keyPair).expects('getAddress') |
|
|
this.mock(hd.keyPair, 'getAddress', function () { |
|
|
.once().withArgs().returns('foobar') |
|
|
return 'foo' |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.strictEqual(hd.getAddress(), 'foobar') |
|
|
assert.strictEqual(hd.getAddress(), 'foo') |
|
|
})) |
|
|
})) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('getNetwork', function () { |
|
|
describe('getNetwork', function () { |
|
|
it('wraps keyPair.getNetwork', setupTest(function () { |
|
|
it('wraps keyPair.getNetwork', hoodwink(function () { |
|
|
this.mock(keyPair).expects('getNetwork') |
|
|
this.mock(hd.keyPair, 'getNetwork', function () { |
|
|
.once().withArgs().returns('network') |
|
|
return 'foo' |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.strictEqual(hd.getNetwork(), 'network') |
|
|
assert.strictEqual(hd.getNetwork(), 'foo') |
|
|
})) |
|
|
})) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('getPublicKeyBuffer', function () { |
|
|
describe('getPublicKeyBuffer', function () { |
|
|
it('wraps keyPair.getPublicKeyBuffer', setupTest(function () { |
|
|
it('wraps keyPair.getPublicKeyBuffer', hoodwink(function () { |
|
|
this.mock(keyPair).expects('getPublicKeyBuffer') |
|
|
this.mock(hd.keyPair, 'getPublicKeyBuffer', function () { |
|
|
.once().withArgs().returns('pubKeyBuffer') |
|
|
return 'foo' |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.strictEqual(hd.getPublicKeyBuffer(), 'pubKeyBuffer') |
|
|
assert.strictEqual(hd.getPublicKeyBuffer(), 'foo') |
|
|
})) |
|
|
})) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('sign', function () { |
|
|
describe('sign', function () { |
|
|
it('wraps keyPair.sign', setupTest(function () { |
|
|
it('wraps keyPair.sign', hoodwink(function () { |
|
|
this.mock(keyPair).expects('sign') |
|
|
this.mock(hd.keyPair, 'sign', function (h) { |
|
|
.once().withArgs(hash).returns('signed') |
|
|
assert.strictEqual(hash, h) |
|
|
|
|
|
return 'foo' |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.strictEqual(hd.sign(hash), 'signed') |
|
|
assert.strictEqual(hd.sign(hash), 'foo') |
|
|
})) |
|
|
})) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
@ -166,11 +171,14 @@ describe('HDNode', function () { |
|
|
signature = hd.sign(hash) |
|
|
signature = hd.sign(hash) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it('wraps keyPair.verify', setupTest(function () { |
|
|
it('wraps keyPair.verify', hoodwink(function () { |
|
|
this.mock(keyPair).expects('verify') |
|
|
this.mock(hd.keyPair, 'verify', function (h, s) { |
|
|
.once().withArgs(hash, signature).returns('verified') |
|
|
assert.strictEqual(hash, h) |
|
|
|
|
|
assert.strictEqual(signature, s) |
|
|
|
|
|
return 'foo' |
|
|
|
|
|
}, 1) |
|
|
|
|
|
|
|
|
assert.strictEqual(hd.verify(hash, signature), 'verified') |
|
|
assert.strictEqual(hd.verify(hash, signature), 'foo') |
|
|
})) |
|
|
})) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|