From 32a2e119e1de9b0c9a090b1d829029ae6bd5da58 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 3 Oct 2016 03:43:16 -0700 Subject: [PATCH] walletkey: comments and fixes. --- lib/primitives/keyring.js | 6 +---- lib/wallet/account.js | 2 +- lib/wallet/walletkey.js | 50 +++++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/primitives/keyring.js b/lib/primitives/keyring.js index 00a547b3..aac6f3b2 100644 --- a/lib/primitives/keyring.js +++ b/lib/primitives/keyring.js @@ -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) { diff --git a/lib/wallet/account.js b/lib/wallet/account.js index 5be77405..888404a2 100644 --- a/lib/wallet/account.js +++ b/lib/wallet/account.js @@ -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: diff --git a/lib/wallet/walletkey.js b/lib/wallet/walletkey.js index 07e881ae..599681e5 100644 --- a/lib/wallet/walletkey.js +++ b/lib/wallet/walletkey.js @@ -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} */