Skip to content

Commit daafb97

Browse files
committed
ECPair/HDNode: adds getNetwork
1 parent 57d0ea8 commit daafb97

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/ecpair.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ ECPair.prototype.getAddress = function () {
105105
return bs58check.encode(payload)
106106
}
107107

108+
ECPair.prototype.getNetwork = function () {
109+
return this.network
110+
}
111+
108112
ECPair.prototype.getPublicKeyBuffer = function () {
109113
return this.Q.getEncoded(this.compressed)
110114
}

src/hdnode.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ HDNode.prototype.getFingerprint = function () {
136136
return this.getIdentifier().slice(0, 4)
137137
}
138138

139+
HDNode.prototype.getNetwork = function () {
140+
return this.keyPair.getNetwork()
141+
}
142+
139143
HDNode.prototype.getPublicKeyBuffer = function () {
140144
return this.keyPair.getPublicKeyBuffer()
141145
}

test/ecpair.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ describe('ECPair', function () {
167167
})
168168
})
169169

170+
describe('getNetwork', function () {
171+
fixtures.valid.forEach(function (f) {
172+
it('returns ' + f.network + ' for ' + f.WIF, function () {
173+
var network = NETWORKS[f.network]
174+
var keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST)
175+
176+
assert.strictEqual(keyPair.getNetwork(), network)
177+
})
178+
})
179+
})
180+
170181
describe('ecdsa wrappers', function () {
171182
var keyPair, hash
172183

test/hdnode.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ describe('HDNode', function () {
121121
}))
122122
})
123123

124+
describe('getNetwork', function () {
125+
it('wraps keyPair.getNetwork', sinon.test(function () {
126+
this.mock(keyPair).expects('getNetwork')
127+
.once().withArgs().returns('network')
128+
129+
assert.strictEqual(hd.getNetwork(), 'network')
130+
}))
131+
})
132+
124133
describe('getPublicKeyBuffer', function () {
125134
it('wraps keyPair.getPublicKeyBuffer', sinon.test(function () {
126135
this.mock(keyPair).expects('getPublicKeyBuffer')

0 commit comments

Comments
 (0)