Skip to content

Commit

Permalink
Merge pull request bitpay#2902 from matiu/feat/schnoor-livenet
Browse files Browse the repository at this point in the history
activate schnoor for BCH livenet
matiu authored Jul 22, 2020
2 parents c2b3535 + fc66c71 commit d81b166
Showing 5 changed files with 53 additions and 18 deletions.
8 changes: 2 additions & 6 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1277,7 +1277,7 @@ export class API extends EventEmitter {
$.checkArgument(opts);

// BCH schnorr deployment
if (!opts.signingMethod && this.credentials.coin == 'bch' && this.credentials.network == 'testnet') {
if (!opts.signingMethod && this.credentials.coin == 'bch') {
opts.signingMethod = 'schnorr';
}

@@ -1547,11 +1547,7 @@ export class API extends EventEmitter {

if (!isLegit) return cb(new Errors.SERVER_COMPROMISED());

let defaultBase = '/v1/txproposals/';
if (txp.coin === 'bch' && txp.network === 'testnet') {
defaultBase = '/v2/txproposals/';
}

let defaultBase = '/v2/txproposals/';
base = base || defaultBase;
// base = base || '/v2/txproposals/'; // DISABLED 2020-04-07

38 changes: 36 additions & 2 deletions packages/bitcore-wallet-client/test/api.test.js
Original file line number Diff line number Diff line change
@@ -3795,6 +3795,40 @@ describe('client API', function() { // DONT USE LAMBAS HERE!!! https://stackover
});
});


it('Should fail with "upgrade needed" trying to sign schnorr on old clients', (done) => {
var toAddress = 'qran0w2c8x2n4wdr60s4nrle65s745wt4sakf9xa8e';
var opts = {
outputs: [{
amount: 1e8,
toAddress: toAddress,
}, {
amount: 2e8,
toAddress: toAddress,
}],
feePerKb: 100e2,
message: 'just some message',
txpVersion: 3,
coin: 'bch',
};
clients[0].createTxProposal(opts, (err, txp) => {
should.not.exist(err);
should.exist(txp);
clients[0].publishTxProposal({
txp: txp,
}, (err, publishedTxp) => {
should.not.exist(err);
should.exist(publishedTxp);
publishedTxp.status.should.equal('pending');
let signatures = keys[0].sign(clients[0].getRootPath(), txp);
clients[0].pushSignatures(publishedTxp, signatures, (err, txp) => {
err.message.should.contain('upgrade');
done();
}, '/v1/txproposals/');
});
}, '/v3/txproposals');
});

it('Should sign proposal v3', (done) => {
var toAddress = 'qran0w2c8x2n4wdr60s4nrle65s745wt4sakf9xa8e';
var opts = {
@@ -3808,7 +3842,7 @@ describe('client API', function() { // DONT USE LAMBAS HERE!!! https://stackover
feePerKb: 100e2,
message: 'just some message',
txpVersion: 3,
coin: 'bch'
coin: 'bch',
};
clients[0].createTxProposal(opts, (err, txp) => {
should.not.exist(err);
@@ -3824,7 +3858,7 @@ describe('client API', function() { // DONT USE LAMBAS HERE!!! https://stackover
should.not.exist(err);
txp.status.should.equal('accepted');
done();
}, '/v1/txproposals/');
}, '/v2/txproposals/');
});
}, '/v3/txproposals');
});
11 changes: 8 additions & 3 deletions packages/bitcore-wallet-service/src/lib/expressapp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import _ from 'lodash';
import 'source-map-support/register';
import logger from './logger';
import { logger, transport } from './logger';

import { ClientError } from './errors/clienterror';
import { LogMiddleware } from './middleware';
@@ -85,7 +85,7 @@ export class ExpressApp {
});

if (opts.disableLogs) {
logger.warn('Logs disabled');
transport.level= 'error';
} else {
this.app.use(LogMiddleware());
// morgan.token('walletId', function getId(req) {
@@ -861,6 +861,7 @@ export class ExpressApp {
});
});

// DEPRECATEED
router.post('/v1/txproposals/:id/signatures/', (req, res) => {
getServerWithAuth(req, res, server => {
req.body.maxTxpVersion = 3;
@@ -873,11 +874,15 @@ export class ExpressApp {
});
});

// We created a new endpoint that support BCH schnorr signatues
// so we can safely throw the error "UPGRADE NEEDED" if an old
// client tries to post ECDSA signatures to a Schnorr TXP.
// (using the old /v1/txproposal method): if (txp.signingMethod === 'schnorr' && !opts.supportBchSchnorr) return cb(Errors.UPGRADE_NEEDED);
router.post('/v2/txproposals/:id/signatures/', (req, res) => {
getServerWithAuth(req, res, server => {
req.body.txProposalId = req.params['id'];
req.body.maxTxpVersion = 3;
req.body.useBchSchnorr = true;
req.body.supportBchSchnorr = true;
server.signTx(req.body, (err, txp) => {
if (err) return returnError(err, res, req);
res.json(txp);
10 changes: 5 additions & 5 deletions packages/bitcore-wallet-service/src/lib/middleware.ts
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ type TimedRequest = {

function LogObj(logOut: { [key: string]: string }) {
logger.info(
`${logOut.support}${logOut.time} | ${logOut.ip} | ${logOut.userAgent || 'na'} | ${logOut.walletId || '-'} | ${logOut.phase} | ${
logOut.took
} | ${logOut.method} | ${logOut.status} | ${logOut.url} | ${logOut.openConnections} open`
`${logOut.support}${logOut.time} | ${logOut.ip} | ${logOut.userAgent || 'na'} | ${logOut.walletId || '-'} | ${
logOut.phase
} | ${logOut.took} | ${logOut.method} | ${logOut.status} | ${logOut.url} | ${logOut.openConnections} open`
);
}

@@ -22,9 +22,9 @@ function LogPhase(req: TimedRequest, res: express.Response, phase: string) {
const time = req.startTime ? req.startTime : new Date();
const ua = req.headers['user-agent'] || '-';
const ver = req.headers['x-client-version'] || '-';
const support = req.isSupportStaff ? 'SUPPORT:' : '';
const support = req.isSupportStaff ? 'SUPPORT:' : '';
const logOut = {
support: support,
support,
time: formatTimestamp(time),
walletId: req.walletId,
userAgent: ua + ':' + ver,
4 changes: 2 additions & 2 deletions packages/bitcore-wallet-service/src/lib/server.ts
Original file line number Diff line number Diff line change
@@ -2567,7 +2567,7 @@ export class WalletService {
* @param {string} opts.txProposalId - The identifier of the transaction.
* @param {string} opts.signatures - The signatures of the inputs of this tx for this copayer (in appearance order)
* @param {string} opts.maxTxpVersion - Client's maximum supported txp version
* @param {boolean} opts.useBchSchnorr - indication whether to use schnorr for signing tx
* @param {boolean} opts.supportBchSchnorr - indication whether to use schnorr for signing tx
*/
signTx(opts, cb) {
if (!checkRequired(opts, ['txProposalId', 'signatures'], cb)) return;
@@ -2598,7 +2598,7 @@ export class WalletService {
if (action) return cb(Errors.COPAYER_VOTED);
if (!txp.isPending()) return cb(Errors.TX_NOT_PENDING);

if (txp.signingMethod === 'schnorr' && !opts.useBchSchnorr) return cb(Errors.UPGRADE_NEEDED);
if (txp.signingMethod === 'schnorr' && !opts.supportBchSchnorr) return cb(Errors.UPGRADE_NEEDED);

const copayer = wallet.getCopayer(this.copayerId);

0 comments on commit d81b166

Please sign in to comment.