|
|
@ -12,22 +12,50 @@ var WalletUtils = require('../walletutils'); |
|
|
|
|
|
|
|
var VERSION = '1.0.0'; |
|
|
|
|
|
|
|
function Wallet(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
function Wallet() { |
|
|
|
this.version = VERSION; |
|
|
|
this.createdOn = Math.floor(Date.now() / 1000); |
|
|
|
this.id = Uuid.v4(); |
|
|
|
this.name = opts.name; |
|
|
|
this.m = opts.m; |
|
|
|
this.n = opts.n; |
|
|
|
this.status = 'pending'; |
|
|
|
this.publicKeyRing = []; |
|
|
|
this.addressIndex = 0; |
|
|
|
this.copayers = []; |
|
|
|
this.pubKey = opts.pubKey; |
|
|
|
this.network = opts.network; |
|
|
|
this.addressManager = new AddressManager(); |
|
|
|
}; |
|
|
|
|
|
|
|
Wallet.create = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
var x = new Wallet(); |
|
|
|
|
|
|
|
x.createdOn = Math.floor(Date.now() / 1000); |
|
|
|
x.id = Uuid.v4(); |
|
|
|
x.name = opts.name; |
|
|
|
x.m = opts.m; |
|
|
|
x.n = opts.n; |
|
|
|
x.status = 'pending'; |
|
|
|
x.publicKeyRing = []; |
|
|
|
x.addressIndex = 0; |
|
|
|
x.copayers = []; |
|
|
|
x.pubKey = opts.pubKey; |
|
|
|
x.network = opts.network; |
|
|
|
x.addressManager = new AddressManager(); |
|
|
|
|
|
|
|
return x; |
|
|
|
}; |
|
|
|
|
|
|
|
Wallet.fromObj = function(obj) { |
|
|
|
var x = new Wallet(); |
|
|
|
|
|
|
|
x.createdOn = obj.createdOn; |
|
|
|
x.id = obj.id; |
|
|
|
x.name = obj.name; |
|
|
|
x.m = obj.m; |
|
|
|
x.n = obj.n; |
|
|
|
x.status = obj.status; |
|
|
|
x.publicKeyRing = obj.publicKeyRing; |
|
|
|
x.copayers = _.map(obj.copayers, function(copayer) { |
|
|
|
return Copayer.fromObj(copayer); |
|
|
|
}); |
|
|
|
x.pubKey = obj.pubKey; |
|
|
|
x.network = obj.network; |
|
|
|
x.addressManager = AddressManager.fromObj(obj.addressManager); |
|
|
|
|
|
|
|
return x; |
|
|
|
}; |
|
|
|
|
|
|
|
/* For compressed keys, m*73 + n*34 <= 496 */ |
|
|
@ -60,26 +88,6 @@ Wallet.verifyCopayerLimits = function(m, n) { |
|
|
|
return (n >= 1 && n <= 12) && (m >= 1 && m <= Wallet.COPAYER_PAIR_LIMITS[n]); |
|
|
|
}; |
|
|
|
|
|
|
|
Wallet.fromObj = function(obj) { |
|
|
|
var x = new Wallet(); |
|
|
|
|
|
|
|
x.createdOn = obj.createdOn; |
|
|
|
x.id = obj.id; |
|
|
|
x.name = obj.name; |
|
|
|
x.m = obj.m; |
|
|
|
x.n = obj.n; |
|
|
|
x.status = obj.status; |
|
|
|
x.publicKeyRing = obj.publicKeyRing; |
|
|
|
x.copayers = _.map(obj.copayers, function(copayer) { |
|
|
|
return Copayer.fromObj(copayer); |
|
|
|
}); |
|
|
|
x.pubKey = obj.pubKey; |
|
|
|
x.network = obj.network; |
|
|
|
x.addressManager = AddressManager.fromObj(obj.addressManager); |
|
|
|
|
|
|
|
return x; |
|
|
|
}; |
|
|
|
|
|
|
|
Wallet.prototype.isShared = function() { |
|
|
|
return this.n > 1; |
|
|
|
}; |
|
|
|