diff --git a/src/index.js b/src/index.js index b56c329..a5c9b7e 100644 --- a/src/index.js +++ b/src/index.js @@ -39,6 +39,10 @@ class Vain extends Emitter { }); 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() { diff --git a/test/errors.js b/test/errors.js index c51084c..471ceb2 100644 --- a/test/errors.js +++ b/test/errors.js @@ -28,3 +28,9 @@ test('Vain throws when `options.prefix` is `undefined`', t => { const error = t.throws(() => new Vain(options)); 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'); +});