|
|
@ -211,12 +211,15 @@ API.prototype._joinWallet = function(secret, copayerName, cb) { |
|
|
|
var wallet = body.wallet; |
|
|
|
var data = { |
|
|
|
copayerId: body.copayerId, |
|
|
|
walletPrivKey: walletPrivKey.toWIF(), |
|
|
|
signingPrivKey: signingPrivKey.toWIF(), |
|
|
|
m: wallet.m, |
|
|
|
n: wallet.n, |
|
|
|
|
|
|
|
publicKeyRing: wallet.publicKeyRing, |
|
|
|
network: wallet.network, |
|
|
|
m: wallet.m, |
|
|
|
n: wallet.n, |
|
|
|
|
|
|
|
xPrivKey: xPrivKey, |
|
|
|
walletPrivKey: walletPrivKey.toWIF(), |
|
|
|
signingPrivKey: signingPrivKey.toWIF(), |
|
|
|
}; |
|
|
|
self.storage.save(data, cb); |
|
|
|
}); |
|
|
@ -304,8 +307,11 @@ API.prototype.export = function(cb) { |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var x = _.pick(data, WALLET_CRITICAL_DATA) |
|
|
|
return cb(null, JSON.stringify(_.values(x))); |
|
|
|
var v = []; |
|
|
|
_.each(WALLET_CRITICAL_DATA, function(k) { |
|
|
|
v.push(data[k]); |
|
|
|
}); |
|
|
|
return cb(null, JSON.stringify(v)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -313,16 +319,27 @@ API.prototype.export = function(cb) { |
|
|
|
API.prototype.import = function(str, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var inData = JSON.parse(str); |
|
|
|
var data = {}, |
|
|
|
i = 0; |
|
|
|
this.storage.load(function(err, data) { |
|
|
|
if (data) |
|
|
|
return cb('Storage already contains a wallet'); |
|
|
|
|
|
|
|
_.each(WALLET_CRITICAL_DATA, function(k) { |
|
|
|
data[k] = inData[i++]; |
|
|
|
}); |
|
|
|
data = {}; |
|
|
|
|
|
|
|
if (err) return cb(err); |
|
|
|
} |
|
|
|
var inData = JSON.parse(str); |
|
|
|
var i = 0; |
|
|
|
|
|
|
|
_.each(WALLET_CRITICAL_DATA, function(k) { |
|
|
|
data[k] = inData[i++]; |
|
|
|
if (!data[k]) |
|
|
|
return cb('Invalid wallet data'); |
|
|
|
}); |
|
|
|
|
|
|
|
data.m = data.publicKeyRing.length; |
|
|
|
data.signingPrivKey = (new Bitcore.HDPrivateKey(data.xPrivKey)).derive('m/1/0').privateKey.toWIF(); |
|
|
|
data.network = data.xPrivKey.substr(0,4) === 'tprv' ? 'testnet' : 'livenet'; |
|
|
|
self.storage.save(data, cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype.getTxProposals = function(opts, cb) { |
|
|
|