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