Fix bug on hdprivate key generation
This commit is contained in:
parent
dff415e0df
commit
89d78019d8
@ -404,18 +404,19 @@ HDPrivateKey.prototype._buildFromBuffers = function(arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var network = Network.get(BufferUtil.integerFromBuffer(arg.version));
|
||||||
var xprivkey;
|
var xprivkey;
|
||||||
xprivkey = Base58Check.encode(buffer.Buffer.concat(sequence));
|
xprivkey = Base58Check.encode(buffer.Buffer.concat(sequence));
|
||||||
arg.xprivkey = new Buffer(xprivkey);
|
arg.xprivkey = new Buffer(xprivkey);
|
||||||
|
|
||||||
var privateKey = new PrivateKey(BN.fromBuffer(arg.privateKey));
|
var privateKey = new PrivateKey(BN.fromBuffer(arg.privateKey), network);
|
||||||
var publicKey = privateKey.toPublicKey();
|
var publicKey = privateKey.toPublicKey();
|
||||||
var size = HDPrivateKey.ParentFingerPrintSize;
|
var size = HDPrivateKey.ParentFingerPrintSize;
|
||||||
var fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).slice(0, size);
|
var fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).slice(0, size);
|
||||||
|
|
||||||
JSUtil.defineImmutable(this, {
|
JSUtil.defineImmutable(this, {
|
||||||
xprivkey: xprivkey,
|
xprivkey: xprivkey,
|
||||||
network: Network.get(BufferUtil.integerFromBuffer(arg.version)),
|
network: network,
|
||||||
depth: BufferUtil.integerFromSingleByteBuffer(arg.depth),
|
depth: BufferUtil.integerFromSingleByteBuffer(arg.depth),
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
publicKey: publicKey,
|
publicKey: publicKey,
|
||||||
|
|||||||
@ -8,6 +8,7 @@ var bitcore = require('..');
|
|||||||
var errors = bitcore.errors;
|
var errors = bitcore.errors;
|
||||||
var hdErrors = errors.HDPrivateKey;
|
var hdErrors = errors.HDPrivateKey;
|
||||||
var buffer = require('buffer');
|
var buffer = require('buffer');
|
||||||
|
var Networks = bitcore.Networks;
|
||||||
var BufferUtil = bitcore.util.buffer;
|
var BufferUtil = bitcore.util.buffer;
|
||||||
var HDPrivateKey = bitcore.HDPrivateKey;
|
var HDPrivateKey = bitcore.HDPrivateKey;
|
||||||
var Base58Check = bitcore.encoding.Base58Check;
|
var Base58Check = bitcore.encoding.Base58Check;
|
||||||
@ -85,17 +86,25 @@ describe('HDPrivate key interface', function() {
|
|||||||
it('allows no-new calling', function() {
|
it('allows no-new calling', function() {
|
||||||
HDPrivateKey(xprivkey).toString().should.equal(xprivkey);
|
HDPrivateKey(xprivkey).toString().should.equal(xprivkey);
|
||||||
});
|
});
|
||||||
|
it('allows the use of a copy constructor', function() {
|
||||||
|
HDPrivateKey(HDPrivateKey(xprivkey))
|
||||||
|
.xprivkey.should.equal(xprivkey);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('public key', function() {
|
||||||
|
var testnetKey = new HDPrivateKey('tprv8ZgxMBicQKsPdEeU2KiGFnUgRGriMnQxrwrg6FWCBg4jeiidHRyCCdA357kfkZiGaXEapWZsGDKikeeEbvgXo3UmEdbEKNdQH9VXESmGuUK');
|
||||||
|
var livenetKey = new HDPrivateKey('xprv9s21ZrQH143K3e39bnn1vyS7YFa1EAJAFGDoeHaSBsgBxgAkTEXeSx7xLvhNQNJxJwhzziWcK3znUFKRPRwWBPkKZ8ijUBa5YYpYPQmeBDX');
|
||||||
|
|
||||||
|
it('matches the network', function() {
|
||||||
|
testnetKey.publicKey.network.should.equal(Networks.testnet);
|
||||||
|
livenetKey.publicKey.network.should.equal(Networks.livenet);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('inspect() displays correctly', function() {
|
it('inspect() displays correctly', function() {
|
||||||
HDPrivateKey(xprivkey).inspect().should.equal('<HDPrivateKey: ' + xprivkey + '>');
|
HDPrivateKey(xprivkey).inspect().should.equal('<HDPrivateKey: ' + xprivkey + '>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows the use of a copy constructor', function() {
|
|
||||||
HDPrivateKey(HDPrivateKey(xprivkey))
|
|
||||||
.xprivkey.should.equal(xprivkey);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fails when trying to derive with an invalid argument', function() {
|
it('fails when trying to derive with an invalid argument', function() {
|
||||||
expectDerivationFail([], hdErrors.InvalidDerivationArgument);
|
expectDerivationFail([], hdErrors.InvalidDerivationArgument);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user