hd
This commit is contained in:
parent
e80785654c
commit
ba6d4821cc
@ -317,6 +317,7 @@ Mnemonic.prototype.fromPhrase = function fromPhrase(phrase) {
|
|||||||
assert(bits >= constants.hd.MIN_ENTROPY);
|
assert(bits >= constants.hd.MIN_ENTROPY);
|
||||||
assert(bits <= constants.hd.MAX_ENTROPY);
|
assert(bits <= constants.hd.MAX_ENTROPY);
|
||||||
assert(bits % 32 === 0);
|
assert(bits % 32 === 0);
|
||||||
|
assert(cbits !== 0, 'Invalid checksum.');
|
||||||
|
|
||||||
ent = new Buffer(Math.ceil((bits + cbits) / 8));
|
ent = new Buffer(Math.ceil((bits + cbits) / 8));
|
||||||
ent.fill(0);
|
ent.fill(0);
|
||||||
@ -1247,50 +1248,46 @@ HDPrivateKey.fromMnemonic = function fromMnemonic(mnemonic, network) {
|
|||||||
/**
|
/**
|
||||||
* Inject properties from privateKey and entropy.
|
* Inject properties from privateKey and entropy.
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} options
|
* @param {Buffer} key
|
||||||
|
* @param {Buffer} entropy
|
||||||
* @param {(Network|NetworkType)?} network
|
* @param {(Network|NetworkType)?} network
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HDPrivateKey.prototype.generate = function _generate(options, network) {
|
HDPrivateKey.prototype.fromKey = function fromKey(key, entropy, network) {
|
||||||
var privateKey, entropy;
|
assert(Buffer.isBuffer(key) && key.length === 32);
|
||||||
|
assert(Buffer.isBuffer(entropy) && entropy.length === 32);
|
||||||
if (!options)
|
|
||||||
options = {};
|
|
||||||
|
|
||||||
if (Buffer.isBuffer(options))
|
|
||||||
options = { privateKey: options };
|
|
||||||
|
|
||||||
privateKey = options.privateKey;
|
|
||||||
entropy = options.entropy;
|
|
||||||
|
|
||||||
if (!privateKey)
|
|
||||||
privateKey = ec.generatePrivateKey();
|
|
||||||
|
|
||||||
if (!entropy)
|
|
||||||
entropy = ec.random(32);
|
|
||||||
|
|
||||||
this.network = bcoin.network.get(network);
|
this.network = bcoin.network.get(network);
|
||||||
this.depth = 0;
|
this.depth = 0;
|
||||||
this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
|
this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
|
||||||
this.childIndex = 0;
|
this.childIndex = 0;
|
||||||
this.chainCode = entropy;
|
this.chainCode = entropy;
|
||||||
this.privateKey = privateKey;
|
this.privateKey = key;
|
||||||
this.publicKey = ec.publicKeyCreate(this.privateKey, true);
|
this.publicKey = ec.publicKeyCreate(this.privateKey, true);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an hd private key from a key and/or entropy bytes.
|
* Create an hd private key from a key and entropy bytes.
|
||||||
* @param {Object?} options
|
* @param {Buffer} key
|
||||||
* @param {Buffer?} options.privateKey
|
* @param {Buffer} entropy
|
||||||
* @param {Buffer?} options.entropy
|
|
||||||
* @param {(Network|NetworkType)?} network
|
* @param {(Network|NetworkType)?} network
|
||||||
* @returns {HDPrivateKey}
|
* @returns {HDPrivateKey}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HDPrivateKey.generate = function generate(options, network) {
|
HDPrivateKey.fromKey = function fromKey(key, entropy, network) {
|
||||||
return new HDPrivateKey().generate(options, network);
|
return new HDPrivateKey().fromKey(key, entropy, network);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an hd private key.
|
||||||
|
* @param {(Network|NetworkType)?} network
|
||||||
|
* @returns {HDPrivateKey}
|
||||||
|
*/
|
||||||
|
|
||||||
|
HDPrivateKey.generate = function generate(network) {
|
||||||
|
var key = ec.generatePrivateKey();
|
||||||
|
var entropy = ec.random(32);
|
||||||
|
return HDPrivateKey.fromKey(key, entropy, network);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -21,6 +21,7 @@ var PolicyEstimator = require('./fees');
|
|||||||
* @property {Number} height
|
* @property {Number} height
|
||||||
* @property {Rate} feeRate
|
* @property {Rate} feeRate
|
||||||
* @property {Rate} minRelay
|
* @property {Rate} minRelay
|
||||||
|
* @property {PolicyEstimator} fees
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Network(options) {
|
function Network(options) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user