ECPair/HDNode: adds getNetwork

This commit is contained in:
Daniel Cousens 2015-09-21 17:37:21 +10:00
parent 57d0ea84a2
commit daafb9794e
4 changed files with 28 additions and 0 deletions

View file

@ -105,6 +105,10 @@ ECPair.prototype.getAddress = function () {
return bs58check.encode(payload)
}
ECPair.prototype.getNetwork = function () {
return this.network
}
ECPair.prototype.getPublicKeyBuffer = function () {
return this.Q.getEncoded(this.compressed)
}

View file

@ -136,6 +136,10 @@ HDNode.prototype.getFingerprint = function () {
return this.getIdentifier().slice(0, 4)
}
HDNode.prototype.getNetwork = function () {
return this.keyPair.getNetwork()
}
HDNode.prototype.getPublicKeyBuffer = function () {
return this.keyPair.getPublicKeyBuffer()
}

View file

@ -167,6 +167,17 @@ describe('ECPair', function () {
})
})
describe('getNetwork', function () {
fixtures.valid.forEach(function (f) {
it('returns ' + f.network + ' for ' + f.WIF, function () {
var network = NETWORKS[f.network]
var keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
assert.strictEqual(keyPair.getNetwork(), network)
})
})
})
describe('ecdsa wrappers', function () {
var keyPair, hash

View file

@ -121,6 +121,15 @@ describe('HDNode', function () {
}))
})
describe('getNetwork', function () {
it('wraps keyPair.getNetwork', sinon.test(function () {
this.mock(keyPair).expects('getNetwork')
.once().withArgs().returns('network')
assert.strictEqual(hd.getNetwork(), 'network')
}))
})
describe('getPublicKeyBuffer', function () {
it('wraps keyPair.getPublicKeyBuffer', sinon.test(function () {
this.mock(keyPair).expects('getPublicKeyBuffer')