walletkey: comments and fixes.

This commit is contained in:
Christopher Jeffrey 2016-10-03 03:43:16 -07:00
parent 44b5a8725e
commit 32a2e119e1
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 31 additions and 27 deletions

View File

@ -28,11 +28,7 @@ var ec = require('../crypto/ec');
* @exports KeyRing
* @constructor
* @param {Object} options
* @param {HDPrivateKey|HDPublicKey|Buffer} options.key
* @param {Buffer[]} options.keys - Shared multisig keys.
* @param {Number?} options.m - Multisig `m` value.
* @param {Number?} options.n - Multisig `n` value.
* @param {Boolean?} options.witness - Whether witness programs are enabled.
* @param {Network} network
*/
function KeyRing(options, network) {

View File

@ -516,7 +516,7 @@ Account.prototype.derivePath = function derivePath(path, master) {
return;
}
ring = WalletKey.fromImport(this, data, this.network);
ring = WalletKey.fromImport(this, data);
return ring;
case Path.types.ADDRESS:

View File

@ -17,11 +17,6 @@ var Path = require('./path');
* @exports WalletKey
* @constructor
* @param {Object} options
* @param {HDPrivateKey|HDPublicKey|Buffer} options.key
* @param {Buffer[]} options.keys - Shared multisig keys.
* @param {Number?} options.m - Multisig `m` value.
* @param {Number?} options.n - Multisig `n` value.
* @param {Boolean?} options.witness - Whether witness programs are enabled.
*/
function WalletKey(options, network) {
@ -163,8 +158,12 @@ WalletKey.fromRaw = function fromRaw(data) {
};
/**
* Instantiate a wallet key from serialized data.
* @param {Buffer} data
* Inject properties from hd key.
* @private
* @param {Account} account
* @param {HDPrivateKey|HDPublicKey} key
* @param {Number} branch
* @param {Number} index
* @returns {WalletKey}
*/
@ -180,14 +179,17 @@ WalletKey.prototype.fromHD = function fromHD(account, key, branch, index) {
this.nested = branch === 2;
if (key.privateKey)
return this.fromPrivate(key.privateKey, key.network);
return this.fromPrivate(key.privateKey, account.network);
return this.fromPublic(key.publicKey, key.network);
return this.fromPublic(key.publicKey, account.network);
};
/**
* Instantiate a wallet key from serialized data.
* @param {Buffer} data
* Instantiate a wallet key from hd key.
* @param {Account} account
* @param {HDPrivateKey|HDPublicKey} key
* @param {Number} branch
* @param {Number} index
* @returns {WalletKey}
*/
@ -196,34 +198,39 @@ WalletKey.fromHD = function fromHD(account, key, branch, index) {
};
/**
* Instantiate a wallet key from serialized data.
* Inject properties from imported data.
* @private
* @param {Account} account
* @param {Buffer} data
* @returns {WalletKey}
*/
WalletKey.prototype.fromImport = function fromImport(account, data, network) {
WalletKey.prototype.fromImport = function fromImport(account, data) {
this.keyType = Path.types.KEY;
this.id = account.id;
this.wid = account.wid;
this.name = account.name;
this.account = account.accountIndex;
this.witness = account.witness;
return this.fromRaw(data, network);
return this.fromRaw(data, account.network);
};
/**
* Instantiate a wallet key from serialized data.
* Instantiate a wallet key from imported data.
* @param {Account} account
* @param {Buffer} data
* @returns {WalletKey}
*/
WalletKey.fromImport = function fromImport(account, data, network) {
return new WalletKey().fromImport(account, data, network);
WalletKey.fromImport = function fromImport(account, data) {
return new WalletKey().fromImport(account, data);
};
/**
* Instantiate a wallet key from serialized data.
* @param {Buffer} data
* Inject properties from key.
* @private
* @param {Account} account
* @param {KeyRing} ring
* @returns {WalletKey}
*/
@ -238,8 +245,9 @@ WalletKey.prototype.fromRing = function fromRing(account, ring) {
};
/**
* Instantiate a wallet key from serialized data.
* @param {Buffer} data
* Instantiate a wallet key from regular key.
* @param {Account} account
* @param {KeyRing} ring
* @returns {WalletKey}
*/