validate xpubkeys
This commit is contained in:
parent
031e47ad5e
commit
23b183714a
|
@ -821,11 +821,15 @@ WalletService.prototype.joinWallet = function(opts, cb) {
|
||||||
if (!Utils.checkValueInCollection(opts.coin, Constants.COINS))
|
if (!Utils.checkValueInCollection(opts.coin, Constants.COINS))
|
||||||
return cb(new ClientError('Invalid coin'));
|
return cb(new ClientError('Invalid coin'));
|
||||||
|
|
||||||
|
var xPubKey;
|
||||||
try {
|
try {
|
||||||
Bitcore.HDPublicKey(opts.xPubKey);
|
xPubKey = Bitcore.HDPublicKey(opts.xPubKey);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return cb(new ClientError('Invalid extended public key'));
|
return cb(new ClientError('Invalid extended public key'));
|
||||||
}
|
}
|
||||||
|
if (_.isUndefined(xPubKey.network)) {
|
||||||
|
return cb(new ClientError('Invalid extended public key'));
|
||||||
|
}
|
||||||
|
|
||||||
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
|
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
|
||||||
|
|
||||||
|
@ -835,10 +839,15 @@ WalletService.prototype.joinWallet = function(opts, cb) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
|
if (!wallet) return cb(Errors.WALLET_NOT_FOUND);
|
||||||
|
|
||||||
|
|
||||||
if (opts.coin != wallet.coin) {
|
if (opts.coin != wallet.coin) {
|
||||||
return cb(new ClientError('The wallet you are trying to join was created for a different coin'));
|
return cb(new ClientError('The wallet you are trying to join was created for a different coin'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wallet.network != xPubKey.network.name) {
|
||||||
|
return cb(new ClientError('The wallet you are trying to join was created for a different network'));
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.supportBIP44AndP2PKH) {
|
if (opts.supportBIP44AndP2PKH) {
|
||||||
// New client trying to join legacy wallet
|
// New client trying to join legacy wallet
|
||||||
if (wallet.derivationStrategy == Constants.DERIVATION_STRATEGIES.BIP45) {
|
if (wallet.derivationStrategy == Constants.DERIVATION_STRATEGIES.BIP45) {
|
||||||
|
@ -991,7 +1000,15 @@ WalletService.prototype.createAddress = function(opts, cb) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
function createNewAddress(wallet, cb) {
|
function createNewAddress(wallet, cb) {
|
||||||
var address = wallet.createAddress(false);
|
|
||||||
|
var address;
|
||||||
|
try{
|
||||||
|
address = wallet.createAddress(false);
|
||||||
|
} catch(e){
|
||||||
|
log.warn("Error creating address for " + self.walletId, e);
|
||||||
|
return cb("Bad xPub");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
self.storage.storeAddressAndWallet(wallet, address, function(err) {
|
self.storage.storeAddressAndWallet(wallet, address, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
|
@ -596,6 +596,34 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail join existing wallet with bad xpub', function(done) {
|
||||||
|
var copayerOpts = helpers.getSignedCopayerOpts({
|
||||||
|
walletId: walletId,
|
||||||
|
name: 'me',
|
||||||
|
xPubKey: 'Ttub4pHUfyVU2mpjaM6YDGDJXWP6j5SL5AJzbViBuTaJEsybcrWZZoGkW7RSUSH9VRQKJtjqY2LfC2bF3FM4UqC1Ba9EP5M64SdTsv9575VAUwh',
|
||||||
|
requestPubKey: TestData.copayers[0].pubKey_1H_0,
|
||||||
|
customData: 'dummy custom data',
|
||||||
|
});
|
||||||
|
server.joinWallet(copayerOpts, function(err, result) {
|
||||||
|
err.message.should.match(/Invalid extended public key/);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail join existing wallet with wrong network xpub', function(done) {
|
||||||
|
var copayerOpts = helpers.getSignedCopayerOpts({
|
||||||
|
walletId: walletId,
|
||||||
|
name: 'me',
|
||||||
|
xPubKey: 'tpubD6NzVbkrYhZ4Wbwwqah5kj1RGPK9BYeGbowB1jegxMoAkKbNhYUAcRTZ5fyxDcpjNXxziiy2ZkUQ3kR1ycPNycTD7Q2Dr6UfLcNTYHrzS3U',
|
||||||
|
requestPubKey: TestData.copayers[0].pubKey_1H_0,
|
||||||
|
customData: 'dummy custom data',
|
||||||
|
});
|
||||||
|
server.joinWallet(copayerOpts, function(err, result) {
|
||||||
|
err.message.should.match(/different network/);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail to join with no name', function(done) {
|
it('should fail to join with no name', function(done) {
|
||||||
var copayerOpts = helpers.getSignedCopayerOpts({
|
var copayerOpts = helpers.getSignedCopayerOpts({
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
|
|
Loading…
Reference in New Issue