|
@ -62,7 +62,6 @@ CopayServer.prototype.createWallet = function (opts, cb) { |
|
|
* Retrieves a wallet from storage. |
|
|
* Retrieves a wallet from storage. |
|
|
* @param {Object} opts |
|
|
* @param {Object} opts |
|
|
* @param {string} opts.id - The wallet id. |
|
|
* @param {string} opts.id - The wallet id. |
|
|
* @param {truthy} opts.includeCopayers - Fetch wallet along with list of copayers. |
|
|
|
|
|
* @returns {Object} wallet |
|
|
* @returns {Object} wallet |
|
|
*/ |
|
|
*/ |
|
|
CopayServer.prototype.getWallet = function (opts, cb) { |
|
|
CopayServer.prototype.getWallet = function (opts, cb) { |
|
@ -72,15 +71,7 @@ CopayServer.prototype.createWallet = function (opts, cb) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
if (!wallet) return cb('Wallet not found'); |
|
|
if (!wallet) return cb('Wallet not found'); |
|
|
|
|
|
|
|
|
if (opts.includeCopayers) { |
|
|
return cb(null, wallet); |
|
|
self.storage.fetchCopayers(wallet.id, function (err, copayers) { |
|
|
|
|
|
if (err) return cb(err); |
|
|
|
|
|
wallet.copayers = copayers || []; |
|
|
|
|
|
return cb(null, wallet); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
return cb(null, wallet); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -110,7 +101,7 @@ CopayServer.prototype._runLocked = function (walletId, cb, task) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self._runLocked(opts.walletId, cb, function (cb) { |
|
|
self.getWallet({ id: opts.walletId, includeCopayers: true }, function (err, wallet) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err || !wallet) return cb(err); |
|
|
if (err || !wallet) return cb(err); |
|
|
if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb('Copayer already in wallet'); |
|
|
if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb('Copayer already in wallet'); |
|
|
if (wallet.copayers.length == wallet.n) return cb('Wallet full'); |
|
|
if (wallet.copayers.length == wallet.n) return cb('Wallet full'); |
|
@ -124,14 +115,12 @@ CopayServer.prototype._runLocked = function (walletId, cb, task) { |
|
|
xPubKeySignature: opts.xPubKeySignature, |
|
|
xPubKeySignature: opts.xPubKeySignature, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
self.storage.storeCopayer(wallet.id, copayer, function (err) { |
|
|
wallet.addCopayer(copayer); |
|
|
|
|
|
|
|
|
|
|
|
self.storage.storeWallet(wallet, function (err) { |
|
|
if (err) return cb(err); |
|
|
if (err) return cb(err); |
|
|
if ((wallet.copayers.length + 1) < wallet.n) return cb(); |
|
|
|
|
|
|
|
|
|
|
|
wallet.status = 'complete'; |
|
|
return cb(); |
|
|
wallet.publicKeyRing = _.pluck(wallet.copayers, 'xPubKey'); |
|
|
|
|
|
wallet.publicKeyRing.push(copayer.xPubKey); |
|
|
|
|
|
self.storage.storeWallet(wallet, cb); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
@ -182,8 +171,10 @@ CopayServer.prototype._doCreateAddress = function (pkr, index, isChange) { |
|
|
CopayServer.prototype.verifyMessageSignature = function (opts, cb) { |
|
|
CopayServer.prototype.verifyMessageSignature = function (opts, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
self.storage.fetchCopayer(opts.walletId, opts.copayerId, function (err, copayer) { |
|
|
self.getWallet({ id: opts.walletId }, function (err, wallet) { |
|
|
if (err) return cb(err); |
|
|
if (err || !wallet) return cb(err); |
|
|
|
|
|
|
|
|
|
|
|
var copayer = wallet.getCopayer(opts.copayerId); |
|
|
if (!copayer) return cb('Copayer not found'); |
|
|
if (!copayer) return cb('Copayer not found'); |
|
|
|
|
|
|
|
|
var isValid = self._doVerifyMessageSignature(copayer.xPubKey, opts.message, opts.signature); |
|
|
var isValid = self._doVerifyMessageSignature(copayer.xPubKey, opts.message, opts.signature); |
|
|