|
|
@ -3,6 +3,10 @@ |
|
|
|
var _ = require('lodash'); |
|
|
|
var util = require('util'); |
|
|
|
|
|
|
|
var Bitcore = require('bitcore'); |
|
|
|
var BitcoreAddress = Bitcore.Address; |
|
|
|
|
|
|
|
var Address = require('./address'); |
|
|
|
var Copayer = require('./copayer'); |
|
|
|
var Addressable = require('./Addressable'); |
|
|
|
|
|
|
@ -23,6 +27,7 @@ function Wallet(opts) { |
|
|
|
this.addressIndex = 0; |
|
|
|
this.copayers = []; |
|
|
|
this.pubKey = opts.pubKey; |
|
|
|
this.isTestnet = false; |
|
|
|
}; |
|
|
|
|
|
|
|
/* For compressed keys, m*73 + n*34 <= 496 */ |
|
|
@ -70,6 +75,7 @@ Wallet.fromObj = function (obj) { |
|
|
|
return new Copayer(copayer); |
|
|
|
}); |
|
|
|
x.pubKey = obj.pubKey; |
|
|
|
x.isTestnet = obj.isTestnet; |
|
|
|
|
|
|
|
Wallet.super_.prototype.fromObj.apply(this, [obj]); |
|
|
|
return x; |
|
|
@ -88,4 +94,26 @@ Wallet.prototype.getCopayer = function (copayerId) { |
|
|
|
return _.find(this.copayers, { id: copayerId }); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Wallet.prototype._getBitcoreNetwork = function () { |
|
|
|
return this.isTestnet ? Bitcore.Networks.testnet : Bitcore.Networks.livenet; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Wallet.prototype.createAddress = function (path) { |
|
|
|
|
|
|
|
var publicKeys = _.map(this.copayers, function(copayer) { |
|
|
|
var xpub = new Bitcore.HDPublicKey(copayer.xPubKey); |
|
|
|
return xpub.derive(path).publicKey; |
|
|
|
}); |
|
|
|
|
|
|
|
var bitcoreAddress = BitcoreAddress.createMultisig(publicKeys, this.m, this._getBitcoreNetwork()); |
|
|
|
|
|
|
|
return new Address({ |
|
|
|
address: bitcoreAddress.toString(), |
|
|
|
path: path, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Wallet; |
|
|
|