tests: add API consistency and tests for #366
This commit is contained in:
parent
49050f9d26
commit
9daf937e93
2 changed files with 36 additions and 0 deletions
|
@ -43,7 +43,11 @@ function HDNode(K, chainCode, network) {
|
|||
if (K instanceof BigInteger) {
|
||||
this.privKey = new ECKey(K, true)
|
||||
this.pubKey = this.privKey.pub
|
||||
} else if (K instanceof ECKey) {
|
||||
assert(K.pub.compressed, 'ECKey must be compressed')
|
||||
this.privKey = K
|
||||
} else if (K instanceof ECPubKey) {
|
||||
assert(K.compressed, 'ECPubKey must be compressed')
|
||||
this.pubKey = K
|
||||
} else {
|
||||
this.pubKey = new ECPubKey(K, true)
|
||||
|
|
|
@ -2,6 +2,8 @@ var assert = require('assert')
|
|||
var networks = require('../src/networks')
|
||||
|
||||
var BigInteger = require('bigi')
|
||||
var ECKey = require('../src/eckey')
|
||||
var ECPubKey = require('../src/ecpubkey')
|
||||
var HDNode = require('../src/hdnode')
|
||||
|
||||
var ecurve = require('ecurve')
|
||||
|
@ -22,6 +24,36 @@ describe('HDNode', function() {
|
|||
assert(hd.pubKey.Q.equals(Q))
|
||||
})
|
||||
|
||||
it('allows initialization directly from an ECKey', function() {
|
||||
var ek = new ECKey(d)
|
||||
var hd = new HDNode(ek, chainCode)
|
||||
|
||||
assert.equal(hd.privKey, ek)
|
||||
})
|
||||
|
||||
it('allows initialization directly from an ECPubKey', function() {
|
||||
var ek = new ECPubKey(Q)
|
||||
var hd = new HDNode(ek, chainCode)
|
||||
|
||||
assert.equal(hd.pubKey, ek)
|
||||
})
|
||||
|
||||
it('throws if ECKey is not compressed', function() {
|
||||
var ek = new ECKey(d, false)
|
||||
|
||||
assert.throws(function() {
|
||||
new HDNode(ek, chainCode)
|
||||
}, /ECKey must be compressed/)
|
||||
})
|
||||
|
||||
it('throws if ECPubKey is not compressed', function() {
|
||||
var ek = new ECPubKey(Q, false)
|
||||
|
||||
assert.throws(function() {
|
||||
new HDNode(ek, chainCode)
|
||||
}, /ECPubKey must be compressed/)
|
||||
})
|
||||
|
||||
it('only uses compressed points', function() {
|
||||
var hd = new HDNode(Q, chainCode)
|
||||
var hdP = new HDNode(d, chainCode)
|
||||
|
|
Loading…
Reference in a new issue