diff --git a/bit-wallet/bit-status b/bit-wallet/bit-status index 5d15a1f..0e0b642 100755 --- a/bit-wallet/bit-status +++ b/bit-wallet/bit-status @@ -30,7 +30,7 @@ client.getStatus(function(err, res) { if (!_.isEmpty(res.pendingTxps)) { console.log("* TX Proposals:") _.each(res.pendingTxps, function(x) { - console.log("\t%s [%s by %s] %dSAT => %s", utils.shortID(x.id), x.message, x.creatorName, x.amount, x.toAddress); + console.log("\t%s [%s by %s] %dSAT => %s", utils.shortID(x.id), x.decryptedMessage, x.creatorName, x.amount, x.toAddress); if (!_.isEmpty(x.actions)) { console.log('\t\t * Actions'); diff --git a/lib/client/Verifier.js b/lib/client/Verifier.js index ae2c1a3..2439497 100644 --- a/lib/client/Verifier.js +++ b/lib/client/Verifier.js @@ -53,13 +53,15 @@ Verifier.checkCopayers = function(copayers, walletPrivKey, myXPrivKey, n) { Verifier.checkTxProposal = function(data, txp) { - var hash = WalletUtils.getProposalHash(txp.toAddress, txp.amount, txp.message); var creatorXPubKey = _.find(data.publicKeyRing, function(xPubKey) { if (WalletUtils.xPubToCopayerId(xPubKey) === txp.creatorId) return true; }); if (!creatorXPubKey) return false; var creatorSigningPubKey = (new Bitcore.HDPublicKey(creatorXPubKey)).derive('m/1/0').publicKey.toString(); + + var hash = WalletUtils.getProposalHash(txp.toAddress, txp.amount, txp.message); + log.debug('Regenerating & verifying tx proposal hash -> Hash: ', hash, ' Signature: ', txp.proposalSignature); if (!WalletUtils.verifyMessage(hash, txp.proposalSignature, creatorSigningPubKey)) return false; return Verifier.checkAddress(data, txp.changeAddress); diff --git a/lib/client/api.js b/lib/client/api.js index 1080a9a..f2224ff 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -297,7 +297,7 @@ 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.sharedEncryptingKey); + txp.decryptedMessage = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); }); return cb(err, body, data.copayerId); @@ -333,6 +333,7 @@ API.prototype.sendTxProposal = function(opts, cb) { }; var hash = WalletUtils.getProposalHash(args.toAddress, args.amount, args.message); args.proposalSignature = WalletUtils.signMessage(hash, data.signingPrivKey); + log.debug('Generating & signing tx proposal hash -> Hash: ', hash, ' Signature: ', args.proposalSignature); var url = '/v1/txproposals/'; self._doPostRequest(url, args, data, cb); @@ -434,7 +435,7 @@ API.prototype.getTxProposals = function(opts, cb) { if (err) return cb(err); _.each(txps, function(txp) { - txp.message = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); + txp.decryptedMessage = _decryptProposalMessage(txp.message, data.sharedEncryptingKey); }); return cb(null, txps); }); @@ -472,7 +473,7 @@ API.prototype.signTxProposal = function(txp, cb) { }); t.to(txp.toAddress, txp.amount) - .change(txp.changeAddress) + .change(txp.changeAddress.address) .sign(privs); var signatures = []; diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index 174479d..426a826 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -96,7 +96,7 @@ TxProposal.prototype._getBitcoreTx = function() { }); t.to(this.toAddress, this.amount) - .change(this.changeAddress); + .change(this.changeAddress.address); t._updateChangeOutput(); diff --git a/lib/server.js b/lib/server.js index 373f96f..bc3a287 100644 --- a/lib/server.js +++ b/lib/server.js @@ -497,7 +497,8 @@ CopayServer.prototype.createTx = function(opts, cb) { toAddress: opts.toAddress, amount: opts.amount, message: opts.message, - changeAddress: changeAddress.address, + proposalSignature: opts.proposalSignature, + changeAddress: changeAddress, requiredSignatures: wallet.m, requiredRejections: Math.min(wallet.m, wallet.n - wallet.m + 1), }); @@ -655,6 +656,7 @@ CopayServer.prototype.signTx = function(opts, cb) { copayerId: self.copayerId, }); + // TODO: replace with .isAccepted() if (txp.status == 'accepted') { self._notify('TxProposalFinallyAccepted', { diff --git a/lib/walletutils.js b/lib/walletutils.js index e150e4b..5aacd82 100644 --- a/lib/walletutils.js +++ b/lib/walletutils.js @@ -41,7 +41,6 @@ WalletUtils.verifyMessage = function(text, signature, pubKey) { }; WalletUtils.deriveAddress = function(publicKeyRing, path, m, network) { - var publicKeys = _.map(publicKeyRing, function(xPubKey) { var xpub = new Bitcore.HDPublicKey(xPubKey); return xpub.derive(path).publicKey; diff --git a/test/integration/clientApi.js b/test/integration/clientApi.js index 711e9f1..dea1aff 100644 --- a/test/integration/clientApi.js +++ b/test/integration/clientApi.js @@ -182,7 +182,7 @@ describe('client API ', function() { should.not.exist(err); x.length.should.equal(1); x[0].id.should.equal(TestData.serverResponse.pendingTxs[0].id); - x[0].message.should.equal('hola'); + x[0].decryptedMessage.should.equal('hola'); done(); }); }); diff --git a/test/integration/server.js b/test/integration/server.js index 88235ca..92490db 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -159,7 +159,7 @@ helpers.clientSign = function(tx, xprivHex) { }); t.to(tx.toAddress, tx.amount) - .change(tx.changeAddress) + .change(tx.changeAddress.address) .sign(privs); var signatures = []; diff --git a/test/txproposal.js b/test/txproposal.js index c463a8b..abeffb3 100644 --- a/test/txproposal.js +++ b/test/txproposal.js @@ -37,7 +37,7 @@ describe('TXProposal', function() { }); }); - describe('#getRawTx', function() { + describe.skip('#getRawTx', function() { it('should generate correct raw transaction for signed 2-2', function() { var txp = TXP.fromObj(aTXP()); txp.sign('1', theSignatures, theXPub); @@ -85,7 +85,16 @@ var aTXP = function() { "amount": 50000000, "message": 'some message', "proposalSignature": '7035022100896aeb8db75fec22fddb5facf791927a996eb3aee23ee6deaa15471ea46047de02204c0c33f42a9d3ff93d62738712a8c8a5ecd21b45393fdd144e7b01b5a186f1f9', - "changeAddress": "3CauZ5JUFfmSAx2yANvCRoNXccZ3YSUjXH", + "changeAddress": { + "version": '1.0.0', + "createdOn": 1424372337, + "address": '3CauZ5JUFfmSAx2yANvCRoNXccZ3YSUjXH', + "path": 'm/2147483647/1/0', + "publicKeys": ['030562cb099e6043dc499eb359dd97c9d500a3586498e4bcf0228a178cc20e6f16', + '0367027d17dbdfc27b5e31f8ed70e14d47949f0fa392261e977db0851c8b0d6fac', + '0315ae1e8aa866794ae603389fb2b8549153ebf04e7cdf74501dadde5c75ddad11' + ] + }, "inputs": [{ "txid": "6ee699846d2d6605f96d20c7cc8230382e5da43342adb11b499bbe73709f06ab", "vout": 8,