Browse Source

Enforce xpub is set when keyFormat is xpub

master
Luke Childs 5 years ago
parent
commit
6597703de1
  1. 4
      src/index.js
  2. 6
      test/errors.js

4
src/index.js

@ -39,6 +39,10 @@ class Vain extends Emitter {
}); });
this.prefix = `${this.addressFormat.prefix}${this.options.prefix}`; this.prefix = `${this.addressFormat.prefix}${this.options.prefix}`;
if (this.options.keyFormat === 'xpub' && typeof this.options.xpub !== 'string') {
throw new Error('An xpub string must be passed in');
}
} }
generate() { generate() {

6
test/errors.js

@ -28,3 +28,9 @@ test('Vain throws when `options.prefix` is `undefined`', t => {
const error = t.throws(() => new Vain(options)); const error = t.throws(() => new Vain(options));
t.is(error.message, 'Prefix must be set'); t.is(error.message, 'Prefix must be set');
}); });
test('Vain throws when `options.xpub` is `undefined` when `options.keyFormat` is `xpub`', t => {
const options = {keyFormat: 'xpub', prefix: 'BTC'};
const error = t.throws(() => new Vain(options));
t.is(error.message, 'An xpub string must be passed in');
});

Loading…
Cancel
Save