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 * @exports KeyRing
* @constructor * @constructor
* @param {Object} options * @param {Object} options
* @param {HDPrivateKey|HDPublicKey|Buffer} options.key * @param {Network} network
* @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 KeyRing(options, network) { function KeyRing(options, network) {

View File

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

View File

@ -17,11 +17,6 @@ var Path = require('./path');
* @exports WalletKey * @exports WalletKey
* @constructor * @constructor
* @param {Object} options * @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) { function WalletKey(options, network) {
@ -163,8 +158,12 @@ WalletKey.fromRaw = function fromRaw(data) {
}; };
/** /**
* Instantiate a wallet key from serialized data. * Inject properties from hd key.
* @param {Buffer} data * @private
* @param {Account} account
* @param {HDPrivateKey|HDPublicKey} key
* @param {Number} branch
* @param {Number} index
* @returns {WalletKey} * @returns {WalletKey}
*/ */
@ -180,14 +179,17 @@ WalletKey.prototype.fromHD = function fromHD(account, key, branch, index) {
this.nested = branch === 2; this.nested = branch === 2;
if (key.privateKey) 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. * Instantiate a wallet key from hd key.
* @param {Buffer} data * @param {Account} account
* @param {HDPrivateKey|HDPublicKey} key
* @param {Number} branch
* @param {Number} index
* @returns {WalletKey} * @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 * @param {Buffer} data
* @returns {WalletKey} * @returns {WalletKey}
*/ */
WalletKey.prototype.fromImport = function fromImport(account, data, network) { WalletKey.prototype.fromImport = function fromImport(account, data) {
this.keyType = Path.types.KEY; this.keyType = Path.types.KEY;
this.id = account.id; this.id = account.id;
this.wid = account.wid; this.wid = account.wid;
this.name = account.name; this.name = account.name;
this.account = account.accountIndex; this.account = account.accountIndex;
this.witness = account.witness; 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 * @param {Buffer} data
* @returns {WalletKey} * @returns {WalletKey}
*/ */
WalletKey.fromImport = function fromImport(account, data, network) { WalletKey.fromImport = function fromImport(account, data) {
return new WalletKey().fromImport(account, data, network); return new WalletKey().fromImport(account, data);
}; };
/** /**
* Instantiate a wallet key from serialized data. * Inject properties from key.
* @param {Buffer} data * @private
* @param {Account} account
* @param {KeyRing} ring
* @returns {WalletKey} * @returns {WalletKey}
*/ */
@ -238,8 +245,9 @@ WalletKey.prototype.fromRing = function fromRing(account, ring) {
}; };
/** /**
* Instantiate a wallet key from serialized data. * Instantiate a wallet key from regular key.
* @param {Buffer} data * @param {Account} account
* @param {KeyRing} ring
* @returns {WalletKey} * @returns {WalletKey}
*/ */