|
|
@ -29,7 +29,7 @@ function CopayError(code, message, inner) { |
|
|
|
this.inner = inner; |
|
|
|
}; |
|
|
|
|
|
|
|
function BadRequestError(message) { |
|
|
|
function RequestError(message) { |
|
|
|
this.message = message || 'Bad request'; |
|
|
|
}; |
|
|
|
|
|
|
@ -67,9 +67,9 @@ CopayServer.prototype.createWallet = function(opts, cb) { |
|
|
|
pubKey; |
|
|
|
|
|
|
|
Utils.checkRequired(opts, ['id', 'name', 'm', 'n', 'pubKey']); |
|
|
|
if (!Wallet.verifyCopayerLimits(opts.m, opts.n)) return cb(new BadRequestError('Invalid combination of required copayers / total copayers')); |
|
|
|
if (!Wallet.verifyCopayerLimits(opts.m, opts.n)) return cb(new RequestError('Invalid combination of required copayers / total copayers')); |
|
|
|
var network = opts.network || 'livenet'; |
|
|
|
if (network != 'livenet' && network != 'testnet') return cb(new BadRequestError('Invalid network')); |
|
|
|
if (network != 'livenet' && network != 'testnet') return cb(new RequestError('Invalid network')); |
|
|
|
|
|
|
|
try { |
|
|
|
pubKey = new PublicKey.fromString(opts.pubKey); |
|
|
@ -105,7 +105,7 @@ CopayServer.prototype.getWallet = function(opts, cb) { |
|
|
|
|
|
|
|
self.storage.fetchWallet(opts.id, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet) return cb(new BadRequestError('Wallet not found')); |
|
|
|
if (!wallet) return cb(new RequestError('Wallet not found')); |
|
|
|
return cb(null, wallet); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -142,7 +142,7 @@ CopayServer.prototype.joinWallet = function(opts, cb) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!self._verifySignature(opts.xPubKey, opts.xPubKeySignature, wallet.pubKey)) { |
|
|
|
return cb(new BadRequestError()); |
|
|
|
return cb(new RequestError()); |
|
|
|
} |
|
|
|
|
|
|
|
if (_.find(wallet.copayers, { |
|
|
@ -244,7 +244,7 @@ CopayServer.prototype.verifyMessageSignature = function(opts, cb) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var copayer = wallet.getCopayer(opts.copayerId); |
|
|
|
if (!copayer) return cb(new BadRequestError('Copayer not found')); |
|
|
|
if (!copayer) return cb(new RequestError('Copayer not found')); |
|
|
|
|
|
|
|
var isValid = self._verifySignature(opts.message, opts.signature, copayer.signingPubKey); |
|
|
|
return cb(null, isValid); |
|
|
@ -278,7 +278,7 @@ CopayServer.prototype._getUtxos = function(opts, cb) { |
|
|
|
// Get addresses for this wallet
|
|
|
|
self.storage.fetchAddresses(opts.walletId, function(err, addresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (addresses.length == 0) return cb(new BadRequestError('The wallet has no addresses')); |
|
|
|
if (addresses.length == 0) return cb(new RequestError('The wallet has no addresses')); |
|
|
|
|
|
|
|
var addresses = _.pluck(addresses, 'address'); |
|
|
|
|
|
|
@ -464,7 +464,7 @@ CopayServer.prototype.signTx = function(opts, cb) { |
|
|
|
|
|
|
|
self.fetchTx(opts.walletId, opts.txProposalId, function(err, txp) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!txp) return cb(new BadRequestError('Transaction proposal not found')); |
|
|
|
if (!txp) return cb(new RequestError('Transaction proposal not found')); |
|
|
|
var action = _.find(txp.actions, { |
|
|
|
copayerId: opts.copayerId |
|
|
|
}); |
|
|
@ -506,7 +506,7 @@ CopayServer.prototype.rejectTx = function(opts, cb) { |
|
|
|
|
|
|
|
self.fetchTx(opts.walletId, opts.txProposalId, function(err, txp) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!txp) return cb(new BadRequestError('Transaction proposal not found')); |
|
|
|
if (!txp) return cb(new RequestError('Transaction proposal not found')); |
|
|
|
var action = _.find(txp.actions, { |
|
|
|
copayerId: opts.copayerId |
|
|
|
}); |
|
|
|