|
|
@ -55,104 +55,104 @@ describe('BIP32', function() { |
|
|
|
|
|
|
|
it('should get the extended public key from the extended private key for test vector 1', function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
bip32.extendedPublicKeyString().should.equal(vector1_m_public); |
|
|
|
bip32.xpubkeyString().should.equal(vector1_m_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0' ext. private key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector1_m0h_private); |
|
|
|
child.xprivkeyString().should.equal(vector1_m0h_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0' ext. public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector1_m0h_public); |
|
|
|
child.xpubkeyString().should.equal(vector1_m0h_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1 ext. private key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector1_m0h1_private); |
|
|
|
child.xprivkeyString().should.equal(vector1_m0h1_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1 ext. public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector1_m0h1_public); |
|
|
|
child.xpubkeyString().should.equal(vector1_m0h1_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/1"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector1_m0h1_public); |
|
|
|
child2.xpubkeyString().should.equal(vector1_m0h1_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h ext. private key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector1_m0h12h_private); |
|
|
|
child.xprivkeyString().should.equal(vector1_m0h12h_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h ext. public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector1_m0h12h_public); |
|
|
|
child.xpubkeyString().should.equal(vector1_m0h12h_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h/2 ext. private key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'/2"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector1_m0h12h2_private); |
|
|
|
child.xprivkeyString().should.equal(vector1_m0h12h2_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/2"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector1_m0h12h2_public); |
|
|
|
child2.xpubkeyString().should.equal(vector1_m0h12h2_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h/2 ext. public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'/2"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector1_m0h12h2_public); |
|
|
|
child.xpubkeyString().should.equal(vector1_m0h12h2_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'/2/1000000000"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector1_m0h12h21000000000_private); |
|
|
|
child.xprivkeyString().should.equal(vector1_m0h12h21000000000_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'/2/1000000000"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector1_m0h12h21000000000_public); |
|
|
|
child.xpubkeyString().should.equal(vector1_m0h12h21000000000_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0'/1/2'/2/1000000000 ext. public key from m/0'/1/2'/2 public key from test vector 1", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector1_m_private); |
|
|
|
var child = bip32.derive("m/0'/1/2'/2"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/1000000000"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector1_m0h12h21000000000_public); |
|
|
|
child2.xpubkeyString().should.equal(vector1_m0h12h21000000000_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should initialize test vector 2 from the extended public key', function() { |
|
|
@ -167,118 +167,118 @@ describe('BIP32', function() { |
|
|
|
|
|
|
|
it('should get the extended public key from the extended private key for test vector 2', function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
bip32.extendedPublicKeyString().should.equal(vector2_m_public); |
|
|
|
bip32.xpubkeyString().should.equal(vector2_m_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0 ext. private key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector2_m0_private); |
|
|
|
child.xprivkeyString().should.equal(vector2_m0_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0 ext. public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector2_m0_public); |
|
|
|
child.xpubkeyString().should.equal(vector2_m0_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0 ext. public key from m public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/0"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector2_m0_public); |
|
|
|
child2.xpubkeyString().should.equal(vector2_m0_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h ext. private key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector2_m02147483647h_private); |
|
|
|
child.xprivkeyString().should.equal(vector2_m02147483647h_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h ext. public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector2_m02147483647h_public); |
|
|
|
child.xpubkeyString().should.equal(vector2_m02147483647h_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1 ext. private key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector2_m02147483647h1_private); |
|
|
|
child.xprivkeyString().should.equal(vector2_m02147483647h1_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1 ext. public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector2_m02147483647h1_public); |
|
|
|
child.xpubkeyString().should.equal(vector2_m02147483647h1_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/1"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector2_m02147483647h1_public); |
|
|
|
child2.xpubkeyString().should.equal(vector2_m02147483647h1_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1/2147483646'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector2_m02147483647h12147483646h_private); |
|
|
|
child.xprivkeyString().should.equal(vector2_m02147483647h12147483646h_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1/2147483646'"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector2_m02147483647h12147483646h_public); |
|
|
|
child.xpubkeyString().should.equal(vector2_m02147483647h12147483646h_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1/2147483646'/2"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPrivateKeyString().should.equal(vector2_m02147483647h12147483646h2_private); |
|
|
|
child.xprivkeyString().should.equal(vector2_m02147483647h12147483646h2_private); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1/2147483646'/2"); |
|
|
|
should.exist(child); |
|
|
|
child.extendedPublicKeyString().should.equal(vector2_m02147483647h12147483646h2_public); |
|
|
|
child.xpubkeyString().should.equal(vector2_m02147483647h12147483646h2_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2", function() { |
|
|
|
var bip32 = new BIP32().fromString(vector2_m_private); |
|
|
|
var child = bip32.derive("m/0/2147483647'/1/2147483646'"); |
|
|
|
var child_pub = new BIP32().fromString(child.extendedPublicKeyString()); |
|
|
|
var child_pub = new BIP32().fromString(child.xpubkeyString()); |
|
|
|
var child2 = child_pub.derive("m/2"); |
|
|
|
should.exist(child2); |
|
|
|
child2.extendedPublicKeyString().should.equal(vector2_m02147483647h12147483646h2_public); |
|
|
|
child2.xpubkeyString().should.equal(vector2_m02147483647h12147483646h2_public); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('testnet', function() { |
|
|
|
it('should initialize a new BIP32 correctly from a random BIP32', function() { |
|
|
|
var b1 = new BIP32(); |
|
|
|
b1.fromRandom('testnet'); |
|
|
|
var b2 = new BIP32().fromString(b1.extendedPublicKeyString()); |
|
|
|
b2.extendedPublicKeyString().should.equal(b1.extendedPublicKeyString()); |
|
|
|
var b2 = new BIP32().fromString(b1.xpubkeyString()); |
|
|
|
b2.xpubkeyString().should.equal(b1.xpubkeyString()); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should generate valid ext pub key for testnet', function() { |
|
|
|
var b = new BIP32(); |
|
|
|
b.fromRandom('testnet'); |
|
|
|
b.extendedPublicKeyString().substring(0,4).should.equal('tpub'); |
|
|
|
b.xpubkeyString().substring(0,4).should.equal('tpub'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -293,8 +293,8 @@ describe('BIP32', function() { |
|
|
|
key: bip32.key, |
|
|
|
hasPrivateKey: bip32.hasPrivateKey, |
|
|
|
pubKeyHash: bip32.pubKeyhash, |
|
|
|
extendedPublicKey: bip32.extendedPublicKey, |
|
|
|
extendedPrivateKey: bip32.extendedPrivateKey |
|
|
|
xpubkey: bip32.xpubkey, |
|
|
|
xprivkey: bip32.xprivkey |
|
|
|
}); |
|
|
|
bip322.toString().should.equal(bip32.toString()); |
|
|
|
bip322.set({}).toString().should.equal(bip32.toString()); |
|
|
@ -306,16 +306,16 @@ describe('BIP32', function() { |
|
|
|
var hex = vector1_master; |
|
|
|
var bip32 = (new BIP32()).fromSeed(new Buffer(hex, 'hex'), 'mainnet'); |
|
|
|
should.exist(bip32); |
|
|
|
bip32.extendedPrivateKeyString().should.equal(vector1_m_private); |
|
|
|
bip32.extendedPublicKeyString().should.equal(vector1_m_public); |
|
|
|
bip32.xprivkeyString().should.equal(vector1_m_private); |
|
|
|
bip32.xpubkeyString().should.equal(vector1_m_public); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should initialize a new BIP32 correctly from test vector 2 seed', function() { |
|
|
|
var hex = vector2_master; |
|
|
|
var bip32 = (new BIP32()).fromSeed(new Buffer(hex, 'hex'), 'mainnet'); |
|
|
|
should.exist(bip32); |
|
|
|
bip32.extendedPrivateKeyString().should.equal(vector2_m_private); |
|
|
|
bip32.extendedPublicKeyString().should.equal(vector2_m_public); |
|
|
|
bip32.xprivkeyString().should.equal(vector2_m_private); |
|
|
|
bip32.xpubkeyString().should.equal(vector2_m_public); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@ -330,7 +330,7 @@ describe('BIP32', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should return an xpub string', function() { |
|
|
|
var bip32b = new BIP32().fromString(bip32.extendedPublicKeyString()); |
|
|
|
var bip32b = new BIP32().fromString(bip32.xpubkeyString()); |
|
|
|
bip32b.toString().slice(0, 4).should.equal('xpub'); |
|
|
|
}); |
|
|
|
|
|
|
@ -339,7 +339,7 @@ describe('BIP32', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should return a tpub string', function() { |
|
|
|
var tip32b = new BIP32().fromString(tip32.extendedPublicKeyString()); |
|
|
|
var tip32b = new BIP32().fromString(tip32.xpubkeyString()); |
|
|
|
tip32b.toString().slice(0, 4).should.equal('tpub'); |
|
|
|
}); |
|
|
|
|
|
|
|