Allow creating a new random testnet HDPrivate key
This commit is contained in:
parent
9f32c1b7ba
commit
98cfd646e7
|
@ -41,25 +41,25 @@ function HDPrivateKey(arg) {
|
|||
if (!(this instanceof HDPrivateKey)) {
|
||||
return new HDPrivateKey(arg);
|
||||
}
|
||||
if (arg) {
|
||||
if (_.isString(arg) || BufferUtil.isBuffer(arg)) {
|
||||
if (HDPrivateKey.isValidSerialized(arg)) {
|
||||
this._buildFromSerialized(arg);
|
||||
} else if (JSUtil.isValidJSON(arg)) {
|
||||
this._buildFromJSON(arg);
|
||||
} else {
|
||||
throw HDPrivateKey.getSerializedError(arg);
|
||||
}
|
||||
} else {
|
||||
if (_.isObject(arg)) {
|
||||
this._buildFromObject(arg);
|
||||
} else {
|
||||
throw new hdErrors.UnrecognizedArgument(arg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!arg) {
|
||||
return this._generateRandomly();
|
||||
}
|
||||
|
||||
if (Network.get(arg)) {
|
||||
return this._generateRandomly(arg);
|
||||
} else if (_.isString(arg) || BufferUtil.isBuffer(arg)) {
|
||||
if (HDPrivateKey.isValidSerialized(arg)) {
|
||||
this._buildFromSerialized(arg);
|
||||
} else if (JSUtil.isValidJSON(arg)) {
|
||||
this._buildFromJSON(arg);
|
||||
} else {
|
||||
throw HDPrivateKey.getSerializedError(arg);
|
||||
}
|
||||
} else if (_.isObject(arg)) {
|
||||
this._buildFromObject(arg);
|
||||
} else {
|
||||
throw new hdErrors.UnrecognizedArgument(arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,7 +266,6 @@ HDPrivateKey.prototype._generateRandomly = function(network) {
|
|||
*/
|
||||
HDPrivateKey.fromSeed = function(hexa, network) {
|
||||
/* jshint maxcomplexity: 8 */
|
||||
|
||||
if (JSUtil.isHexaString(hexa)) {
|
||||
hexa = BufferUtil.hexToBuffer(hexa);
|
||||
}
|
||||
|
@ -282,7 +281,7 @@ HDPrivateKey.fromSeed = function(hexa, network) {
|
|||
var hash = Hash.sha512hmac(hexa, new buffer.Buffer('Bitcoin seed'));
|
||||
|
||||
return new HDPrivateKey({
|
||||
network: Network.get(network) || Network.livenet,
|
||||
network: Network.get(network) || Network.defaultNetwork,
|
||||
depth: 0,
|
||||
parentFingerPrint: 0,
|
||||
childIndex: 0,
|
||||
|
@ -441,7 +440,6 @@ HDPrivateKey.prototype.toJSON = function toJSON() {
|
|||
HDPrivateKey.DefaultDepth = 0;
|
||||
HDPrivateKey.DefaultFingerprint = 0;
|
||||
HDPrivateKey.DefaultChildIndex = 0;
|
||||
HDPrivateKey.DefaultNetwork = Network.livenet;
|
||||
HDPrivateKey.Hardened = 0x80000000;
|
||||
HDPrivateKey.RootElementAlias = ['m', 'M', 'm\'', 'M\''];
|
||||
|
||||
|
|
|
@ -50,6 +50,12 @@ describe('HDPrivate key interface', function() {
|
|||
should.exist(new HDPrivateKey().xprivkey);
|
||||
});
|
||||
|
||||
it('should make a new private key from random for testnet', function() {
|
||||
var key = new HDPrivateKey('testnet');
|
||||
should.exist(key.xprivkey);
|
||||
key.network.name.should.equal('testnet');
|
||||
});
|
||||
|
||||
it('should not be able to change read-only properties', function() {
|
||||
var hdkey = new HDPrivateKey();
|
||||
expect(function() {
|
||||
|
|
Loading…
Reference in New Issue