From d76cd8ec5a894b8fd3846075353be1ed98a7c38a Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 29 Jun 2015 12:20:24 -0300 Subject: [PATCH 1/2] add client-version to expressapp --- lib/expressapp.js | 14 +++++++++++--- lib/server.js | 13 +++++++++++-- test/integration/server.js | 8 ++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/expressapp.js b/lib/expressapp.js index cc6bcc2..eddfc8f 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -33,7 +33,7 @@ ExpressApp.prototype.start = function(opts, cb) { this.app.use(function(req, res, next) { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE'); - res.setHeader('Access-Control-Allow-Headers', 'x-signature,x-identity,X-Requested-With,Content-Type,Authorization'); + res.setHeader('Access-Control-Allow-Headers', 'x-signature,x-identity,x-client-version,X-Requested-With,Content-Type,Authorization'); next(); }); var allowCORS = function(req, res, next) { @@ -104,6 +104,13 @@ ExpressApp.prototype.start = function(opts, cb) { }; }; + function getServer(req, res, cb) { + var opts = { + clientVersion: req.header('x-client-version'), + }; + return WalletService.getInstance(opts); + }; + function getServerWithAuth(req, res, cb) { var credentials = getCredentials(req); if (!credentials) @@ -115,6 +122,7 @@ ExpressApp.prototype.start = function(opts, cb) { copayerId: credentials.copayerId, message: req.method.toLowerCase() + '|' + req.url + '|' + JSON.stringify(req.body), signature: credentials.signature, + clientVersion: req.header('x-client-version'), }; WalletService.getInstanceWithAuth(auth, function(err, server) { if (err) return returnError(err, res, req); @@ -123,7 +131,7 @@ ExpressApp.prototype.start = function(opts, cb) { }; router.post('/v1/wallets/', function(req, res) { - var server = WalletService.getInstance(); + var server = getServer(req, res); server.createWallet(req.body, function(err, walletId) { if (err) return returnError(err, res, req); res.json({ @@ -134,7 +142,7 @@ ExpressApp.prototype.start = function(opts, cb) { router.post('/v1/wallets/:id/copayers/', function(req, res) { req.body.walletId = req.params['id']; - var server = WalletService.getInstance(); + var server = getServer(req, res); server.joinWallet(req.body, function(err, result) { if (err) return returnError(err, res, req); diff --git a/lib/server.js b/lib/server.js index b1e6c40..4d5f296 100644 --- a/lib/server.js +++ b/lib/server.js @@ -131,8 +131,16 @@ WalletService.shutDown = function(cb) { }); }; -WalletService.getInstance = function() { - return new WalletService(); +/** + * Gets an instance of the server without authentication. + * @param {Object} opts + * @param {string} opts.clientVersion - A string that identifies the client issuing the request + */ +WalletService.getInstance = function(opts) { + opts = opts || {}; + var server = new WalletService(); + server.clientVersion = opts.clientVersion; + return server; }; /** @@ -141,6 +149,7 @@ WalletService.getInstance = function() { * @param {string} opts.copayerId - The copayer id making the request. * @param {string} opts.message - The contents of the request to be signed. * @param {string} opts.signature - Signature of message to be verified using the copayer's requestPubKey + * @param {string} opts.clientVersion - A string that identifies the client issuing the request */ WalletService.getInstanceWithAuth = function(opts, cb) { diff --git a/test/integration/server.js b/test/integration/server.js index 0197b37..08c54a0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -574,6 +574,14 @@ describe('Wallet service', function() { }); }); + describe('#getInstance', function() { + it('should get server instance', function() { + var server = WalletService.getInstance({ + clientVersion: 'bwc-0.0.1', + }); + server.clientVersion.should.equal('bwc-0.0.1'); + }); + }); describe('#getInstanceWithAuth', function() { it('should get server instance for existing copayer', function(done) { From 7ff9ceceb7576ce47bbb52da3f9517f06597acbf Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 29 Jun 2015 12:20:39 -0300 Subject: [PATCH 2/2] v0.0.38 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 777f859..bbbc00f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-wallet-service", "description": "A service for Mutisig HD Bitcoin Wallets", "author": "BitPay Inc", - "version": "0.0.37", + "version": "0.0.38", "keywords": [ "bitcoin", "copay",