From d618aa9822fbdb1bb887e6f62d44e383518fd5be Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 14 Aug 2014 11:00:18 +1000 Subject: [PATCH] Wallet: deprecates newMasterKey --- src/wallet.js | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index c056c95..dd492ba 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -7,14 +7,18 @@ var HDNode = require('./hdnode') var Transaction = require('./transaction') function Wallet(seed, network) { + seed = seed || crypto.randomBytes(32) network = network || networks.bitcoin // Stored in a closure to make accidental serialization less likely - var masterkey = null + var masterkey = HDNode.fromSeedBuffer(seed, network) var me = this - var accountZero = null - var internalAccount = null - var externalAccount = null + + // HD first-level child derivation method should be hardened + // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254 + var accountZero = masterkey.deriveHardened(0) + var externalAccount = accountZero.derive(0) + var internalAccount = accountZero.derive(1) // Addresses this.addresses = [] @@ -23,25 +27,6 @@ function Wallet(seed, network) { // Transaction output data this.outputs = {} - // Make a new master key - this.newMasterKey = function(seed) { - seed = seed || crypto.randomBytes(32) - masterkey = HDNode.fromSeedBuffer(seed, network) - - // HD first-level child derivation method should be hardened - // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254 - accountZero = masterkey.deriveHardened(0) - externalAccount = accountZero.derive(0) - internalAccount = accountZero.derive(1) - - me.addresses = [] - me.changeAddresses = [] - - me.outputs = {} - } - - this.newMasterKey(seed) - this.generateAddress = function() { var key = externalAccount.derive(this.addresses.length) this.addresses.push(key.getAddress().toString()) @@ -71,6 +56,25 @@ function Wallet(seed, network) { return utxo } + // FIXME: remove in 2.x.y + this.newMasterKey = function(seed) { + console.warn('newMasterKey is deprecated, please make a new Wallet instance instead') + + seed = seed || crypto.randomBytes(32) + masterkey = HDNode.fromSeedBuffer(seed, network) + + // HD first-level child derivation method should be hardened + // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254 + accountZero = masterkey.deriveHardened(0) + externalAccount = accountZero.derive(0) + internalAccount = accountZero.derive(1) + + me.addresses = [] + me.changeAddresses = [] + + me.outputs = {} + } + this.setUnspentOutputs = function(utxo) { var outputs = {}