|
|
@ -17,12 +17,12 @@ var BASE_URL = 'http://localhost:3001/copay/api'; |
|
|
|
|
|
|
|
var WALLET_CRITICAL_DATA = ['xPrivKey', 'm', 'publicKeyRing', 'sharedEncryptingKey']; |
|
|
|
|
|
|
|
function _encryptProposalMessage(message, encryptingKey) { |
|
|
|
function _encryptMessage(message, encryptingKey) { |
|
|
|
if (!message) return null; |
|
|
|
return WalletUtils.encryptMessage(message, encryptingKey); |
|
|
|
}; |
|
|
|
|
|
|
|
function _decryptProposalMessage(message, encryptingKey) { |
|
|
|
function _decryptMessage(message, encryptingKey) { |
|
|
|
if (!message) return ''; |
|
|
|
try { |
|
|
|
return WalletUtils.decryptMessage(message, encryptingKey); |
|
|
@ -31,6 +31,15 @@ function _decryptProposalMessage(message, encryptingKey) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
function _processTxps(txps, encryptingKey) { |
|
|
|
_.each([].concat(txps), function(txp) { |
|
|
|
txp.decryptedMessage = _decryptMessage(txp.message, encryptingKey); |
|
|
|
_.each(txp.actions, function(action) { |
|
|
|
action.comment = _decryptMessage(action.comment, encryptingKey); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
function _parseError(body) { |
|
|
|
if (_.isString(body)) { |
|
|
|
try { |
|
|
@ -305,12 +314,9 @@ API.prototype.getStatus = function(cb) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
var url = '/v1/wallets/'; |
|
|
|
self._doGetRequest(url, data, function(err, body) { |
|
|
|
_.each(body.pendingTxps, function(txp) { |
|
|
|
txp.decryptedMessage = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); |
|
|
|
}); |
|
|
|
|
|
|
|
return cb(err, body, data.copayerId); |
|
|
|
self._doGetRequest(url, data, function(err, result) { |
|
|
|
_processTxps(result.pendingTxps, data.sharedEncryptingKey); |
|
|
|
return cb(err, result, data.copayerId); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
@ -335,7 +341,7 @@ API.prototype.sendTxProposal = function(opts, cb) { |
|
|
|
var args = { |
|
|
|
toAddress: opts.toAddress, |
|
|
|
amount: opts.amount, |
|
|
|
message: _encryptProposalMessage(opts.message, data.sharedEncryptingKey), |
|
|
|
message: _encryptMessage(opts.message, data.sharedEncryptingKey), |
|
|
|
}; |
|
|
|
var hash = WalletUtils.getProposalHash(args.toAddress, args.amount, args.message); |
|
|
|
args.proposalSignature = WalletUtils.signMessage(hash, data.signingPrivKey); |
|
|
@ -431,7 +437,7 @@ API.prototype.import = function(str, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* opts.doNotVerify |
|
|
|
* @return {undefined} |
|
|
|
*/ |
|
|
@ -444,14 +450,11 @@ API.prototype.getTxProposals = function(opts, cb) { |
|
|
|
var url = '/v1/txproposals/'; |
|
|
|
self._doGetRequest(url, data, function(err, txps) { |
|
|
|
if (err) return cb(err); |
|
|
|
var fake = false; |
|
|
|
|
|
|
|
_.each(txps, function(txp) { |
|
|
|
txp.decryptedMessage = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); |
|
|
|
_processTxps(txps, data.sharedEncryptingKey); |
|
|
|
|
|
|
|
if (!opts.doNotVerify |
|
|
|
&& !Verifier.checkTxProposal(data, txp)) |
|
|
|
fake = true; |
|
|
|
var fake = _.any(txps, function(txp) { |
|
|
|
return (!opts.doNotVerify && !Verifier.checkTxProposal(data, txp)); |
|
|
|
}); |
|
|
|
|
|
|
|
if (fake) |
|
|
@ -523,7 +526,7 @@ API.prototype.rejectTxProposal = function(txp, reason, cb) { |
|
|
|
|
|
|
|
var url = '/v1/txproposals/' + txp.id + '/rejections/'; |
|
|
|
var args = { |
|
|
|
reason: reason || '', |
|
|
|
reason: _encryptMessage(reason, data.sharedEncryptingKey) || '', |
|
|
|
}; |
|
|
|
self._doPostRequest(url, args, data, cb); |
|
|
|
}); |
|
|
|