Browse Source

Merge pull request #409 from isocolsky/validate-xpub

Handle invalid xpub on wallet join
activeAddress
Matias Alejo Garcia 9 years ago
parent
commit
15082f6d1b
  1. 6
      lib/server.js
  2. 15
      test/integration/server.js

6
lib/server.js

@ -567,6 +567,12 @@ WalletService.prototype.joinWallet = function(opts, cb) {
if (_.isEmpty(opts.name)) if (_.isEmpty(opts.name))
return cb(new ClientError('Invalid copayer name')); return cb(new ClientError('Invalid copayer name'));
try {
Bitcore.HDPublicKey(opts.xPubKey);
} catch (ex) {
return cb(new ClientError('Invalid extended public key'));
}
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true; opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
self.walletId = opts.walletId; self.walletId = opts.walletId;

15
test/integration/server.js

@ -450,6 +450,21 @@ describe('Wallet service', function() {
}); });
}); });
it('should fail to join with invalid xPubKey', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'copayer 1',
xPubKey: 'invalid',
requestPubKey: TestData.copayers[0].pubKey_1H_0,
});
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(result);
should.exist(err);
err.message.should.contain('extended public key');
done();
});
});
it('should fail to join with null signature', function(done) { it('should fail to join with null signature', function(done) {
var copayerOpts = { var copayerOpts = {
walletId: walletId, walletId: walletId,

Loading…
Cancel
Save