From fe46f95b322a3b52878a083ab06225c2f2ffc126 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 31 Aug 2015 11:59:54 -0300 Subject: [PATCH] test for legacy clients trying to join BIP44 wallet --- lib/server.js | 12 +++++- test/integration/server.js | 87 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/lib/server.js b/lib/server.js index a65f561..2e4bec1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -512,6 +512,10 @@ WalletService.prototype.addAccess = function(opts, cb) { }); }; +WalletService.prototype._clientSupportsBIP44 = function() { + return !!this.clientVersion && !(/^bw.-0\.[01]\./.test(this.clientVersion)); +}; + /** * Joins a wallet in creation. * @param {Object} opts @@ -541,8 +545,12 @@ WalletService.prototype.joinWallet = function(opts, cb) { self.storage.fetchWallet(opts.walletId, function(err, wallet) { if (err) return cb(err); if (!wallet) return cb(Errors.WALLET_NOT_FOUND); - if (wallet.addressManager.derivationStrategy != opts.derivationStrategy) - return cb(new ClientError(Errors.codes.UPGRADE_NEEDED, 'To join this wallet, you need to upgrade your client app.')); + if (wallet.addressManager.derivationStrategy != opts.derivationStrategy) { + if (!self._clientSupportsBIP44()) { + return cb(new ClientError(Errors.codes.UPGRADE_NEEDED, 'To join this wallet, you need to upgrade your client app.')); + } + return cb(new ClientError('Incompatible address derivation strategy')); + } var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey); if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { diff --git a/test/integration/server.js b/test/integration/server.js index 27dd623..a48baac 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1132,6 +1132,93 @@ describe('Wallet service', function() { }); }); + describe('Address derivation strategy', function() { + var server; + beforeEach(function() { + server = WalletService.getInstance({ + clientVersion: 'bwc-0.2.0', + }); + }); + it('should fail to join BIP45 wallet with BIP44 copayer opts', function(done) { + var walletOpts = { + name: 'my wallet', + m: 2, + n: 3, + pubKey: TestData.keyPair.pub, + derivationStrategy: 'BIP45', + }; + server.createWallet(walletOpts, function(err, wid) { + should.not.exist(err); + var copayerOpts = helpers.getSignedCopayerOpts({ + walletId: wid, + name: 'me', + xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H, + requestPubKey: TestData.copayers[0].pubKey_1H_0, + customData: 'dummy custom data', + derivationStrategy: 'BIP44', + }); + server.joinWallet(copayerOpts, function(err, result) { + should.exist(err); + err.message.toLowerCase().should.contain('address derivation strategy'); + done(); + }); + }); + }); + it('should fail to join BIP44 wallet with BIP45 copayer opts', function(done) { + var walletOpts = { + name: 'my wallet', + m: 2, + n: 3, + pubKey: TestData.keyPair.pub, + derivationStrategy: 'BIP44', + }; + server.createWallet(walletOpts, function(err, wid) { + should.not.exist(err); + var copayerOpts = helpers.getSignedCopayerOpts({ + walletId: wid, + name: 'me', + xPubKey: TestData.copayers[0].xPubKey_45H, + requestPubKey: TestData.copayers[0].pubKey_1H_0, + customData: 'dummy custom data', + derivationStrategy: 'BIP45', + }); + server.joinWallet(copayerOpts, function(err, result) { + should.exist(err); + err.message.toLowerCase().should.contain('address derivation strategy'); + done(); + }); + }); + }); + it('should require upgrade when joining BIP44 wallet with BIP45 copayer opts from old client app', function(done) { + var walletOpts = { + name: 'my wallet', + m: 2, + n: 3, + pubKey: TestData.keyPair.pub, + derivationStrategy: 'BIP44', + }; + server.createWallet(walletOpts, function(err, wid) { + should.not.exist(err); + var copayerOpts = helpers.getSignedCopayerOpts({ + walletId: wid, + name: 'me', + xPubKey: TestData.copayers[0].xPubKey_45H, + requestPubKey: TestData.copayers[0].pubKey_1H_0, + customData: 'dummy custom data', + derivationStrategy: 'BIP45', + }); + server = WalletService.getInstance({ + clientVersion: 'bwc-0.1.4', + }); + server.joinWallet(copayerOpts, function(err, result) { + should.exist(err); + err.code.should.equal('UPGRADE_NEEDED'); + done(); + }); + }); + }); + }); + describe('#getStatus', function() { var server, wallet; beforeEach(function(done) {