remove derivationStrategy field from txp

This commit is contained in:
Ivan Socolsky 2015-11-06 11:48:28 -03:00
parent c629b02419
commit 714b95b32c
5 changed files with 28 additions and 43 deletions

View File

@ -78,7 +78,6 @@ TxProposal.create = function(opts) {
x.excludeUnconfirmedUtxos = opts.excludeUnconfirmedUtxos;
x.proposalSignaturePubKey = opts.proposalSignaturePubKey;
x.proposalSignaturePubKeySig = opts.proposalSignaturePubKeySig;
x.derivationStrategy = opts.derivationStrategy || Constants.DERIVATION_STRATEGIES.BIP45;
x.addressType = opts.addressType || Constants.SCRIPT_TYPES.P2SH;
x.customData = opts.customData;
@ -127,7 +126,6 @@ TxProposal.fromObj = function(obj) {
x.excludeUnconfirmedUtxos = obj.excludeUnconfirmedUtxos;
x.proposalSignaturePubKey = obj.proposalSignaturePubKey;
x.proposalSignaturePubKeySig = obj.proposalSignaturePubKeySig;
x.derivationStrategy = obj.derivationStrategy || Constants.DERIVATION_STRATEGIES.BIP45;
x.addressType = obj.addressType || Constants.SCRIPT_TYPES.P2SH;
x.customData = obj.customData;

View File

@ -1285,7 +1285,6 @@ WalletService.prototype.createTx = function(opts, cb) {
requiredRejections: Math.min(wallet.m, wallet.n - wallet.m + 1),
walletN: wallet.n,
excludeUnconfirmedUtxos: !!opts.excludeUnconfirmedUtxos,
derivationStrategy: wallet.derivationStrategy,
addressType: wallet.addressType,
customData: opts.customData,
};

View File

@ -161,7 +161,7 @@ describe('Email notifications', function() {
async.eachSeries(_.range(2), function(i, next) {
var copayer = TestData.copayers[i];
helpers.getAuthServer(copayer.id44, function(server) {
var signatures = helpers.clientSign(txp, copayer.xPrivKey);
var signatures = helpers.clientSign(txp, copayer.xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txp.id,
signatures: signatures,

View File

@ -301,25 +301,14 @@ helpers.stubAddressActivity = function(activeAddresses) {
};
};
helpers.clientSign = function(txp, xPrivKey) {
helpers.clientSign = function(txp, derivedXPrivKey) {
var self = this;
function getBaseAddressDerivationPath(derivationStrategy, network, account) {
if (derivationStrategy == Constants.DERIVATION_STRATEGIES.BIP45) return "m/45'";
return "m/44'/" + (network == 'livenet' ? "0'" : "1'") + "/" + account + "'";
};
function deriveXPrivFromMaster(masterXPriv, derivationStrategy, network, account) {
var path = getBaseAddressDerivationPath(derivationStrategy, network, account || 0);
return new Bitcore.HDPrivateKey(masterXPriv, network).derive(path);
};
//Derive proper key to sign, for each input
var privs = [];
var derived = {};
var network = new Bitcore.Address(txp.changeAddress.address).network.name;
var xpriv = deriveXPrivFromMaster(xPrivKey, txp.derivationStrategy, network);
var xpriv = new Bitcore.HDPrivateKey(derivedXPrivKey, txp.network);
_.each(txp.inputs, function(i) {
if (!derived[i.path]) {

View File

@ -1929,7 +1929,7 @@ describe('Wallet service', function() {
tx.fee.should.be.within(0.9 * estimatedFee, 1.1 * estimatedFee);
// Sign it to make sure Bitcore doesn't complain about the fees
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -2432,7 +2432,6 @@ describe('Wallet service', function() {
server.createTx(txOpts, function(err, tx) {
should.not.exist(err);
should.exist(tx);
tx.derivationStrategy.should.equal('BIP44');
tx.addressType.should.equal('P2PKH');
txid = tx.id;
done();
@ -2446,7 +2445,7 @@ describe('Wallet service', function() {
server.getPendingTxs({}, function(err, txs) {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
should.not.exist(tx.raw);
server.signTx({
txProposalId: txid,
@ -2494,7 +2493,7 @@ describe('Wallet service', function() {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2521,7 +2520,7 @@ describe('Wallet service', function() {
server.getPendingTxs({}, function(err, txs) {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = helpers.clientSign(tx, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[1].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2537,7 +2536,7 @@ describe('Wallet service', function() {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
signatures[0] = 1;
server.signTx({
@ -2572,7 +2571,7 @@ describe('Wallet service', function() {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = _.take(helpers.clientSign(tx, TestData.copayers[0].xPrivKey), tx.inputs.length - 1);
var signatures = _.take(helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H), tx.inputs.length - 1);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2589,7 +2588,7 @@ describe('Wallet service', function() {
var tx = txs[0];
tx.id.should.equal(txid);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2612,7 +2611,7 @@ describe('Wallet service', function() {
server.rejectTx({
txProposalId: txid,
}, function(err) {
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2660,7 +2659,7 @@ describe('Wallet service', function() {
txProposalId: txid
}, function(err, tx) {
should.not.exist(err);
var signatures = helpers.clientSign(tx, TestData.copayers[2].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[2].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txid,
signatures: signatures,
@ -2690,7 +2689,7 @@ describe('Wallet service', function() {
server.createTx(txOpts, function(err, txp) {
should.not.exist(err);
should.exist(txp);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -2940,7 +2939,7 @@ describe('Wallet service', function() {
});
},
function(txp, next) {
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txpId,
signatures: signatures,
@ -2971,7 +2970,7 @@ describe('Wallet service', function() {
},
function(txp, next) {
helpers.getAuthServer(wallet.copayers[1].id, function(server, wallet) {
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txpId,
signatures: signatures,
@ -3373,7 +3372,7 @@ describe('Wallet service', function() {
server.getPendingTxs({}, function(err, txs) {
blockchainExplorer.broadcast = sinon.stub().callsArgWith(1, 'broadcast error');
var tx = txs[0];
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -3415,7 +3414,7 @@ describe('Wallet service', function() {
it('should notify sign, acceptance, and broadcast, and emit', function(done) {
server.getPendingTxs({}, function(err, txs) {
var tx = txs[2];
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -3444,7 +3443,7 @@ describe('Wallet service', function() {
it('should notify sign, acceptance, and broadcast, and emit (with 3rd party broadcast', function(done) {
server.getPendingTxs({}, function(err, txs) {
var tx = txs[2];
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -3638,7 +3637,7 @@ describe('Wallet service', function() {
});
it('should allow creator to remove a signed TX by himself', function(done) {
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -3660,7 +3659,7 @@ describe('Wallet service', function() {
async.waterfall([
function(next) {
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -3725,7 +3724,7 @@ describe('Wallet service', function() {
it('should not allow creator copayer to remove a TX signed by other copayer, in less than 24hrs', function(done) {
helpers.getAuthServer(wallet.copayers[1].id, function(server2) {
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey_44H_0H_0H);
server2.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -3744,7 +3743,7 @@ describe('Wallet service', function() {
it('should allow creator copayer to remove a TX rejected by other copayer, in less than 24hrs', function(done) {
helpers.getAuthServer(wallet.copayers[1].id, function(server2) {
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey_44H_0H_0H);
server2.rejectTx({
txProposalId: txp.id,
signatures: signatures,
@ -3764,7 +3763,7 @@ describe('Wallet service', function() {
it('should allow creator copayer to remove a TX signed by other copayer, after 24hrs', function(done) {
helpers.getAuthServer(wallet.copayers[1].id, function(server2) {
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey_44H_0H_0H);
server2.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -3791,7 +3790,7 @@ describe('Wallet service', function() {
it('should allow other copayer to remove a TX signed, after 24hrs', function(done) {
helpers.getAuthServer(wallet.copayers[1].id, function(server2) {
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey);
var signatures = helpers.clientSign(txp, TestData.copayers[1].xPrivKey_44H_0H_0H);
server2.signTx({
txProposalId: txp.id,
signatures: signatures,
@ -3951,7 +3950,7 @@ describe('Wallet service', function() {
should.not.exist(err);
should.exist(tx);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -4594,7 +4593,7 @@ describe('Wallet service', function() {
signature: 'dummy',
clientVersion: 'bwc-0.0.40',
}, function(err, server) {
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -4632,7 +4631,7 @@ describe('Wallet service', function() {
tx.amount.should.equal(helpers.toSatoshi(80));
tx.fee.should.equal(Defaults.DEFAULT_FEE_PER_KB);
helpers.getAuthServer(wallet.copayers[0].id, function(server) {
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,
@ -4671,7 +4670,7 @@ describe('Wallet service', function() {
tx.fee.should.equal(5000);
// Sign it to make sure Bitcore doesn't complain about the fees
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey);
var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: tx.id,
signatures: signatures,