improve bip32 interface slightly
This commit is contained in:
parent
8228d8204f
commit
be37f5e37f
|
@ -17,7 +17,10 @@ var BIP32 = function(str) {
|
||||||
this.fromString(str);
|
this.fromString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
BIP32.prototype.fromRandom = function() {
|
BIP32.prototype.fromRandom = function(network) {
|
||||||
|
if (!network)
|
||||||
|
network = 'mainnet';
|
||||||
|
this.version = constants[network].bip32privkey;
|
||||||
this.depth = 0x00;
|
this.depth = 0x00;
|
||||||
this.parentFingerprint = new Buffer([0, 0, 0, 0]);
|
this.parentFingerprint = new Buffer([0, 0, 0, 0]);
|
||||||
this.childIndex = new Buffer([0, 0, 0, 0]);
|
this.childIndex = new Buffer([0, 0, 0, 0]);
|
||||||
|
|
|
@ -36,13 +36,8 @@ describe('BIP32', function() {
|
||||||
should.exist(BIP32);
|
should.exist(BIP32);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a mainnet bip32', function() {
|
it('should create a bip32', function() {
|
||||||
var bip32 = new BIP32('mainnet');
|
var bip32 = new BIP32();
|
||||||
should.exist(bip32);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create a testnet bip32', function() {
|
|
||||||
var bip32 = new BIP32('testnet');
|
|
||||||
should.exist(bip32);
|
should.exist(bip32);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -291,13 +286,15 @@ describe('BIP32', function() {
|
||||||
|
|
||||||
describe('testnet', function() {
|
describe('testnet', function() {
|
||||||
it('should initialize a new BIP32 correctly from a random BIP32', function() {
|
it('should initialize a new BIP32 correctly from a random BIP32', function() {
|
||||||
var b1 = new BIP32('testnet');
|
var b1 = new BIP32();
|
||||||
|
b1.fromRandom('testnet');
|
||||||
var b2 = new BIP32(b1.extendedPublicKeyString());
|
var b2 = new BIP32(b1.extendedPublicKeyString());
|
||||||
b2.extendedPublicKeyString().should.equal(b1.extendedPublicKeyString());
|
b2.extendedPublicKeyString().should.equal(b1.extendedPublicKeyString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate valid ext pub key for testnet', function() {
|
it('should generate valid ext pub key for testnet', function() {
|
||||||
var b = new BIP32('testnet');
|
var b = new BIP32();
|
||||||
|
b.fromRandom('testnet');
|
||||||
b.extendedPublicKeyString().substring(0,4).should.equal('tpub');
|
b.extendedPublicKeyString().substring(0,4).should.equal('tpub');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue