|
|
@ -309,66 +309,73 @@ API.prototype.getBalance = function(cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
API.prototype.getTxProposals = function(opts, cb) { |
|
|
|
API.prototype.export = function(cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck( |
|
|
|
function(err, data) { |
|
|
|
this._loadAndCheck( function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var url = '/v1/txproposals/'; |
|
|
|
self._doGetRequest(url, data, cb); |
|
|
|
var x = _.pick(data,['publicKeyRing','xPrivKey', 'copayerId', 'signingPrivKey']) |
|
|
|
return cb(null, JSON.stringify(x)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
API.prototype.getTxProposals = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var url = '/v1/txproposals/'; |
|
|
|
self._doGetRequest(url, data, cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
API.prototype.signTxProposal = function(txp, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
this._loadAndCheck( |
|
|
|
function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
this._loadAndCheck(function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
if (!Verifier.checkTxProposal(data, txp)) { |
|
|
|
return cb(new ServerCompromisedError('Server sent fake transaction proposal')); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Derive proper key to sign, for each input
|
|
|
|
var privs = [], |
|
|
|
derived = {}; |
|
|
|
//Derive proper key to sign, for each input
|
|
|
|
var privs = [], |
|
|
|
derived = {}; |
|
|
|
|
|
|
|
var network = new Bitcore.Address(txp.toAddress).network.name; |
|
|
|
var xpriv = new Bitcore.HDPrivateKey(data.xPrivKey, network); |
|
|
|
var network = new Bitcore.Address(txp.toAddress).network.name; |
|
|
|
var xpriv = new Bitcore.HDPrivateKey(data.xPrivKey, network); |
|
|
|
|
|
|
|
_.each(txp.inputs, function(i) { |
|
|
|
if (!derived[i.path]) { |
|
|
|
derived[i.path] = xpriv.derive(i.path).privateKey; |
|
|
|
} |
|
|
|
privs.push(derived[i.path]); |
|
|
|
}); |
|
|
|
_.each(txp.inputs, function(i) { |
|
|
|
if (!derived[i.path]) { |
|
|
|
derived[i.path] = xpriv.derive(i.path).privateKey; |
|
|
|
} |
|
|
|
privs.push(derived[i.path]); |
|
|
|
}); |
|
|
|
|
|
|
|
var t = new Bitcore.Transaction(); |
|
|
|
_.each(txp.inputs, function(i) { |
|
|
|
t.from(i, i.publicKeys, txp.requiredSignatures); |
|
|
|
}); |
|
|
|
var t = new Bitcore.Transaction(); |
|
|
|
_.each(txp.inputs, function(i) { |
|
|
|
t.from(i, i.publicKeys, txp.requiredSignatures); |
|
|
|
}); |
|
|
|
|
|
|
|
t.to(txp.toAddress, txp.amount) |
|
|
|
.change(txp.changeAddress) |
|
|
|
.sign(privs); |
|
|
|
t.to(txp.toAddress, txp.amount) |
|
|
|
.change(txp.changeAddress) |
|
|
|
.sign(privs); |
|
|
|
|
|
|
|
var signatures = []; |
|
|
|
_.each(privs, function(p) { |
|
|
|
var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); |
|
|
|
signatures.push(s); |
|
|
|
}); |
|
|
|
var signatures = []; |
|
|
|
_.each(privs, function(p) { |
|
|
|
var s = t.getSignatures(p)[0].signature.toDER().toString('hex'); |
|
|
|
signatures.push(s); |
|
|
|
}); |
|
|
|
|
|
|
|
var url = '/v1/txproposals/' + txp.id + '/signatures/'; |
|
|
|
var args = { |
|
|
|
signatures: signatures |
|
|
|
}; |
|
|
|
var url = '/v1/txproposals/' + txp.id + '/signatures/'; |
|
|
|
var args = { |
|
|
|
signatures: signatures |
|
|
|
}; |
|
|
|
|
|
|
|
self._doPostRequest(url, args, data, cb); |
|
|
|
}); |
|
|
|
self._doPostRequest(url, args, data, cb); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
API.prototype.rejectTxProposal = function(txp, reason, cb) { |
|
|
|