Wallet: deprecates newMasterKey
This commit is contained in:
parent
09455a6ad8
commit
d618aa9822
1 changed files with 27 additions and 23 deletions
|
@ -7,14 +7,18 @@ var HDNode = require('./hdnode')
|
||||||
var Transaction = require('./transaction')
|
var Transaction = require('./transaction')
|
||||||
|
|
||||||
function Wallet(seed, network) {
|
function Wallet(seed, network) {
|
||||||
|
seed = seed || crypto.randomBytes(32)
|
||||||
network = network || networks.bitcoin
|
network = network || networks.bitcoin
|
||||||
|
|
||||||
// Stored in a closure to make accidental serialization less likely
|
// Stored in a closure to make accidental serialization less likely
|
||||||
var masterkey = null
|
var masterkey = HDNode.fromSeedBuffer(seed, network)
|
||||||
var me = this
|
var me = this
|
||||||
var accountZero = null
|
|
||||||
var internalAccount = null
|
// HD first-level child derivation method should be hardened
|
||||||
var externalAccount = null
|
// 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
|
// Addresses
|
||||||
this.addresses = []
|
this.addresses = []
|
||||||
|
@ -23,25 +27,6 @@ function Wallet(seed, network) {
|
||||||
// Transaction output data
|
// Transaction output data
|
||||||
this.outputs = {}
|
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() {
|
this.generateAddress = function() {
|
||||||
var key = externalAccount.derive(this.addresses.length)
|
var key = externalAccount.derive(this.addresses.length)
|
||||||
this.addresses.push(key.getAddress().toString())
|
this.addresses.push(key.getAddress().toString())
|
||||||
|
@ -71,6 +56,25 @@ function Wallet(seed, network) {
|
||||||
return utxo
|
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) {
|
this.setUnspentOutputs = function(utxo) {
|
||||||
var outputs = {}
|
var outputs = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue