Browse Source

fix signatures

activeAddress
Ivan Socolsky 10 years ago
parent
commit
efa706e68c
  1. 14
      lib/client/api.js
  2. 27
      test/integration/server.js

14
lib/client/api.js

@ -488,23 +488,25 @@ API.prototype.signTxProposal = function(txp, cb) {
_.each(txp.inputs, function(i) { _.each(txp.inputs, function(i) {
if (!derived[i.path]) { if (!derived[i.path]) {
derived[i.path] = xpriv.derive(i.path).privateKey; derived[i.path] = xpriv.derive(i.path).privateKey;
}
privs.push(derived[i.path]); privs.push(derived[i.path]);
}
}); });
var t = new Bitcore.Transaction(); var t = new Bitcore.Transaction();
_.each(txp.inputs, function(i) { _.each(txp.inputs, function(i) {
t.from(i, i.publicKeys, txp.requiredSignatures); t.from(i, i.publicKeys, txp.requiredSignatures);
}); });
t.to(txp.toAddress, txp.amount) t.to(txp.toAddress, txp.amount)
.change(txp.changeAddress.address) .change(txp.changeAddress.address);
.sign(privs);
var signatures = _.map(privs, function(priv, i) { var signatures = _.map(privs, function(priv, i) {
return _.find(t.getSignatures(priv), { return t.getSignatures(priv);
inputIndex: i });
}).signature.toDER().toString('hex');
signatures = _.map(_.sortBy(_.flatten(signatures), 'inputIndex'), function(s) {
return s.signature.toDER().toString('hex');
}); });
var url = '/v1/txproposals/' + txp.id + '/signatures/'; var url = '/v1/txproposals/' + txp.id + '/signatures/';

27
test/integration/server.js

@ -125,33 +125,34 @@ helpers.stubBroadcastFail = function() {
}; };
helpers.clientSign = function(tx, xprivHex) { helpers.clientSign = function(txp, xprivHex) {
//Derive proper key to sign, for each input //Derive proper key to sign, for each input
var privs = [], var privs = [],
derived = {}; derived = {};
var xpriv = new Bitcore.HDPrivateKey(xprivHex); var xpriv = new Bitcore.HDPrivateKey(xprivHex);
_.each(tx.inputs, function(i) { _.each(txp.inputs, function(i) {
if (!derived[i.path]) { if (!derived[i.path]) {
derived[i.path] = xpriv.derive(i.path).privateKey; derived[i.path] = xpriv.derive(i.path).privateKey;
}
privs.push(derived[i.path]); privs.push(derived[i.path]);
}
}); });
var t = new Bitcore.Transaction(); var t = new Bitcore.Transaction();
_.each(tx.inputs, function(i) { _.each(txp.inputs, function(i) {
t.from(i, i.publicKeys, tx.requiredSignatures); t.from(i, i.publicKeys, txp.requiredSignatures);
}); });
t.to(tx.toAddress, tx.amount) t.to(txp.toAddress, txp.amount)
.change(tx.changeAddress.address) .change(txp.changeAddress.address);
.sign(privs);
var signatures = _.map(privs, function(priv, i) { var signatures = _.map(privs, function(priv, i) {
return _.find(t.getSignatures(priv), { return t.getSignatures(priv);
inputIndex: i });
}).signature.toDER().toString('hex');
signatures = _.map(_.sortBy(_.flatten(signatures), 'inputIndex'), function(s) {
return s.signature.toDER().toString('hex');
}); });
return signatures; return signatures;
@ -1080,7 +1081,7 @@ describe('Copay server', function() {
}); });
}); });
it.only('should sign and broadcast a tx', function(done) { it('should sign and broadcast a tx', function(done) {
helpers.stubBroadcast('1122334455'); helpers.stubBroadcast('1122334455');
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey); var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 10, null, TestData.copayers[0].privKey);
server.createTx(txOpts, function(err, txp) { server.createTx(txOpts, function(err, txp) {
@ -1486,7 +1487,7 @@ describe('Copay server', function() {
}, function(err, notifications) { }, function(err, notifications) {
should.not.exist(err); should.not.exist(err);
var types = _.pluck(notifications, 'type'); var types = _.pluck(notifications, 'type');
types.should.deep.equal(['NewCopayer', 'NewAddress', 'NewAddress', 'NewAddress', 'NewAddress']); types.should.deep.equal(['NewCopayer', 'NewAddress', 'NewAddress', 'NewAddress', 'NewTxProposal']);
done(); done();
}); });
}); });

Loading…
Cancel
Save