|
|
@ -15,7 +15,7 @@ var ServerCompromisedError = require('./servercompromisederror') |
|
|
|
|
|
|
|
var BASE_URL = 'http://localhost:3001/copay/api'; |
|
|
|
|
|
|
|
var WALLET_CRITICAL_DATA = ['xPrivKey', 'm', 'publicKeyRing']; |
|
|
|
var WALLET_CRITICAL_DATA = ['xPrivKey', 'm', 'publicKeyRing', 'sharedEncryptingKey']; |
|
|
|
|
|
|
|
function _encryptProposalMessage(message, encryptingKey) { |
|
|
|
if (!message) return null; |
|
|
@ -24,7 +24,11 @@ function _encryptProposalMessage(message, encryptingKey) { |
|
|
|
|
|
|
|
function _decryptProposalMessage(message, encryptingKey) { |
|
|
|
if (!message) return ''; |
|
|
|
return WalletUtils.decryptMessage(message, encryptingKey); |
|
|
|
try { |
|
|
|
return WalletUtils.decryptMessage(message, encryptingKey); |
|
|
|
} catch (ex) { |
|
|
|
return '<ECANNOTDECRYPT>'; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
function _parseError(body) { |
|
|
@ -150,8 +154,9 @@ API.prototype._doGetRequest = function(url, data, cb) { |
|
|
|
|
|
|
|
API.prototype._initData = function(network, walletPrivKey, m, n) { |
|
|
|
var xPrivKey = new Bitcore.HDPrivateKey(network); |
|
|
|
var signingPrivKey = (new Bitcore.HDPrivateKey(xPrivKey)).derive('m/1/0').privateKey.toWIF(); |
|
|
|
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString(); |
|
|
|
var signingPrivKey = (new Bitcore.HDPrivateKey(xPrivKey)).derive('m/1/0').privateKey; |
|
|
|
var sharedEncryptingKey = Bitcore.crypto.Hash.sha256(signingPrivKey.toBuffer()).slice(0, 16).toString('base64'); |
|
|
|
var copayerId = WalletUtils.xPubToCopayerId(xPubKey); |
|
|
|
|
|
|
|
var data = { |
|
|
@ -161,8 +166,9 @@ API.prototype._initData = function(network, walletPrivKey, m, n) { |
|
|
|
network: network, |
|
|
|
m: m, |
|
|
|
n: n, |
|
|
|
signingPrivKey: signingPrivKey, |
|
|
|
signingPrivKey: signingPrivKey.toWIF(), |
|
|
|
walletPrivKey: walletPrivKey.toWIF(), |
|
|
|
sharedEncryptingKey: sharedEncryptingKey, |
|
|
|
}; |
|
|
|
return data; |
|
|
|
}; |
|
|
@ -280,8 +286,8 @@ API.prototype.getStatus = function(cb) { |
|
|
|
var url = '/v1/wallets/'; |
|
|
|
self._doGetRequest(url, data, function(err, body) { |
|
|
|
_.each(body.pendingTxps, function(txp) { |
|
|
|
txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey); |
|
|
|
}); |
|
|
|
txp.message = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); |
|
|
|
}); |
|
|
|
|
|
|
|
return cb(err, body, data.copayerId); |
|
|
|
}); |
|
|
@ -312,7 +318,7 @@ API.prototype.sendTxProposal = function(opts, cb) { |
|
|
|
var args = { |
|
|
|
toAddress: opts.toAddress, |
|
|
|
amount: amount, |
|
|
|
message: _encryptProposalMessage(opts.message, data.signingPrivKey), |
|
|
|
message: _encryptProposalMessage(opts.message, data.sharedEncryptingKey), |
|
|
|
}; |
|
|
|
var hash = WalletUtils.getProposalHash(args.toAddress, args.amount, args.message); |
|
|
|
args.proposalSignature = WalletUtils.signMessage(hash, data.signingPrivKey); |
|
|
@ -417,7 +423,7 @@ API.prototype.getTxProposals = function(opts, cb) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
_.each(txps, function(txp) { |
|
|
|
txp.message = _decryptProposalMessage(txp.message, data.signingPrivKey); |
|
|
|
txp.message = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); |
|
|
|
}); |
|
|
|
return cb(null, txps); |
|
|
|
}); |
|
|
|