Code Duplication    Length = 1-33 lines in 4 locations

lib/wallet.js 1 location

@@ 416-448 (lines=33) @@
413
                        self.encryptedPrimarySeed = options.encryptedPrimarySeed;
414
                        self.encryptedSecret = options.encryptedSecret;
415
                        self.walletVersion = Wallet.WALLET_VERSION_V3;
416
417
                        return self;
418
                    });
419
                });
420
        });
421
422
};
423
424
Wallet.prototype._upgradeV1ToV3 = function(passphrase, notify) {
425
    var self = this;
426
427
    return q.when(true)
428
        .then(function() {
429
            var options = {
430
                storeDataOnServer: true,
431
                passphrase: passphrase,
432
                primarySeed: self.primarySeed
433
            };
434
435
            return self.sdk.produceEncryptedDataV3(options, notify || function noop() {})
436
                .then(function(options) {
437
                    // store recoveryEncryptedSecret for printing on backup sheet
438
                    self.recoveryEncryptedSecret = options.recoveryEncryptedSecret;
439
440
                    return self.sdk.updateWallet(self.identifier, {
441
                        primary_mnemonic: '',
442
                        encrypted_primary_seed: options.encryptedPrimarySeed.toString('base64'),
443
                        encrypted_secret: options.encryptedSecret.toString('base64'),
444
                        recovery_secret: options.recoverySecret.toString('hex'),
445
                        wallet_version: Wallet.WALLET_VERSION_V3
446
                    }).then(function() {
447
                        self.secret = options.secret;
448
                        self.encryptedPrimarySeed = options.encryptedPrimarySeed;
449
                        self.encryptedSecret = options.encryptedSecret;
450
                        self.walletVersion = Wallet.WALLET_VERSION_V3;
451

build/blocktrail-sdk.min.js 3 locations

@@ 2-2 (lines=1) @@
1
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.blocktrailSDK=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c,Buffer){function d(a,b){var c=h.HDNode.fromBase58(a[0],b);if("undefined"!=typeof c.keyPair.d)throw new Error("BIP32Key contained private key material - abort");if("M"!==a[1].slice(0,1))throw new Error("BIP32Key contained non-public path - abort")}function e(a,b){d(a.primary_public_key,b),d(a.backup_public_key,b)}var f=a("lodash"),g=a("q"),h=a("bitcoinjs-lib"),i=a("bitcoinjs-message"),j=a("bip39"),k=a("./wallet"),l=a("./rest_client"),m=a("./encryption"),n=a("./keyderivation"),o=a("./encryption_mnemonic"),p=a("./blocktrail"),q=a("randombytes"),r=a("crypto-js"),s=a("./webworkifier"),t=a("./use-webworker")(),u=function(a){var b=this;return this instanceof u?(b.testnet=a.testnet=a.testnet||!1,b.testnet?b.network=h.networks.testnet:b.network=h.networks.bitcoin,b.bitcoinCash=a.network&&"BCC"===a.network,b.feeSanityCheck="undefined"==typeof a.feeSanityCheck||a.feeSanityCheck,b.feeSanityCheckBaseFeeMultiplier=a.feeSanityCheckBaseFeeMultiplier||200,a.apiNetwork=a.apiNetwork||(b.testnet?"t":"")+(a.network||"BTC").toUpperCase(),void(b.client=u.initRestClient(a))):new u(a)};u.initRestClient=function(a){return c.env.BLOCKTRAIL_SDK_API_ENDPOINT&&(a.host=c.env.BLOCKTRAIL_SDK_API_ENDPOINT),a.host&&0===a.host.indexOf("https://")?(a.https=!0,a.host=a.host.substr(8)):a.host&&0===a.host.indexOf("http://")&&(a.https=!1,a.host=a.host.substr(7)),"undefined"==typeof a.https&&(a.https=!0),a.host||(a.host="api.blocktrail.com"),a.port||(a.port=a.https?443:80),a.endpoint||(a.endpoint="/"+(a.apiVersion||"v1")+(a.apiNetwork?"/"+a.apiNetwork:"")),new l(a)};var v=function(a){return g.when(a).then(function(a){return a.storePrimaryMnemonic&&(a.storeDataOnServer=a.storePrimaryMnemonic),"undefined"==typeof a.storeDataOnServer&&(a.storeDataOnServer=!a.primarySeed),a})},w=function(a,b){return g.when(a).then(function(a){if(a.storeDataOnServer){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),a.encryptedSecret=r.AES.encrypt(a.secret,a.passphrase).toString(r.format.OpenSSL)}b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),a.encryptedPrimarySeed=r.AES.encrypt(a.primarySeed.toString("base64"),a.secret).toString(r.format.OpenSSL),a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoveryEncryptedSecret=r.AES.encrypt(a.secret,a.recoverySecret).toString(r.format.OpenSSL)}return a})};u.prototype.promisedEncrypt=function(b,c,d){if(t){var e=m.generateSalt(),f=m.generateIV();return s.workify(u.prototype.promisedEncrypt,function(){return a("./webworker")},{method:"Encryption.encryptWithSaltAndIV",pt:b,pw:c,saltBuf:e,iv:f,iterations:d}).then(function(a){return Buffer.from(a.cipherText.buffer)})}try{return g.when(m.encrypt(b,c,d))}catch(a){return g.reject(a)}},u.prototype.promisedDecrypt=function(b,c){if(t)return s.workify(u.prototype.promisedDecrypt,function(){return a("./webworker")},{method:"Encryption.decrypt",ct:b,pw:c}).then(function(a){return Buffer.from(a.plainText.buffer)});try{return g.when(m.decrypt(b,c))}catch(a){return g.reject(a)}},u.prototype.produceEncryptedDataV3=function(a,b){var c=this;return g.when(a).then(function(a){return a.storeDataOnServer?g.when().then(function(){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8),c.promisedEncrypt(a.secret,new Buffer(a.passphrase),n.defaultIterations).then(function(b){a.encryptedSecret=b})}if(!(a.secret instanceof Buffer))throw new Error("Secret must be a buffer")}).then(function(){return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),c.promisedEncrypt(a.primarySeed,a.secret,n.subkeyIterations).then(function(b){a.encryptedPrimarySeed=b})}).then(function(){if(a.recoverySecret!==!1)return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoverySecret||(a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8)),c.promisedEncrypt(a.secret,a.recoverySecret,n.defaultIterations).then(function(b){a.recoveryEncryptedSecret=b})}).then(function(){return a}):a})};var x=function(a,b,c){return g.when(a).then(function(a){return a.backupPublicKey||(a.backupSeed=a.backupSeed||q(k.WALLET_ENTROPY_BITS/8)),c(u.CREATE_WALLET_PROGRESS_PRIMARY),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,b),c(u.CREATE_WALLET_PROGRESS_BACKUP),a.backupPublicKey||(a.backupPrivateKey=h.HDNode.fromSeedBuffer(a.backupSeed,b),a.backupPublicKey=a.backupPrivateKey.neutered()),a.primaryPublicKey=a.primaryPrivateKey.deriveHardened(a.keyIndex).neutered(),c(u.CREATE_WALLET_PROGRESS_SUBMIT),a})};u.prototype.mnemonicToPrivateKey=function(a,b,c){var d=this,e=g.defer();e.promise.spreadNodeify(c);var f=d.testnet?h.networks.testnet:h.networks.bitcoin;return e.resolve(g.fcall(function(){return d.mnemonicToSeedHex(a,b).then(function(a){return h.HDNode.fromSeedHex(a,f)})})),e.promise},u.prototype.mnemonicToSeedHex=function(b,c){var d=this;if(t)return s.workify(d.mnemonicToSeedHex,function(){return a("./webworker")},{method:"mnemonicToSeedHex",mnemonic:b,passphrase:c}).then(function(a){return a.seed});try{return g.when(j.mnemonicToSeedHex(b,c))}catch(a){return g.reject(a)}},u.prototype.resolvePrimaryPrivateKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.passphrase&&a.password)throw new p.WalletCreateError("Can't specify passphrase and password");if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryMnemonic&&a.primarySeed)throw new p.WalletInitError("Can only specify one of; Primary Mnemonic or Primary Seed");if(a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");if(!a.primaryMnemonic&&!a.primarySeed)throw new p.WalletInitError("Need to specify at least one of; Primary Mnemonic or Primary Seed");if(a.primarySeed)c.primarySeed=a.primarySeed,a.primaryPrivateKey=h.HDNode.fromSeedBuffer(c.primarySeed,e),d.resolve(a);else{if(!a.passphrase)throw new p.WalletInitError("Can't init wallet with Primary Mnemonic without a passphrase");c.mnemonicToSeedHex(a.primaryMnemonic,a.passphrase).then(function(b){try{a.primarySeed=new Buffer(b,"hex"),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,e),d.resolve(a)}catch(a){d.reject(a)}},function(a){d.reject(a)})}}catch(a){d.reject(a)}return d.promise},u.prototype.resolveBackupPublicKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.backupMnemonic&&a.backupPublicKey)throw new p.WalletInitError("Can only specify one of; Backup Mnemonic or Backup PublicKey");if(!a.backupMnemonic&&!a.backupPublicKey)throw new p.WalletInitError("Need to specify at least one of; Backup Mnemonic or Backup PublicKey");a.backupPublicKey?a.backupPublicKey instanceof h.HDNode?d.resolve(a):(a.backupPublicKey=h.HDNode.fromBase58(a.backupPublicKey,e),d.resolve(a)):c.mnemonicToPrivateKey(a.backupMnemonic,"").then(function(b){a.backupPublicKey=b.neutered(),d.resolve(a)},function(a){d.reject(a)})}catch(a){d.reject(a)}return d.promise},u.prototype.debugAuth=function(a){var b=this;return b.client.get("/debug/http-signature",null,!0,a)},u.prototype.address=function(a,b){var c=this;return c.client.get("/address/"+a,null,b)},u.prototype.addresses=function(a,b){var c=this;return c.client.post("/address",null,{addresses:a},b)},u.prototype.addressTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/transactions",b,c)},u.prototype.batchAddressHasTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/has-transactions",b,{addresses:a},c)},u.prototype.addressUnconfirmedTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unconfirmed-transactions",b,c)},u.prototype.addressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unspent-outputs",b,c)},u.prototype.batchAddressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/unspent-outputs",b,{addresses:a},c)},u.prototype.verifyAddress=function(a,b,c){var d=this;return d.client.post("/address/"+a+"/verify",null,{signature:b},c)},u.prototype.allBlocks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/all-blocks",a,b)},u.prototype.block=function(a,b){var c=this;return c.client.get("/block/"+a,null,b)},u.prototype.blockLatest=function(a){var b=this;return b.client.get("/block/latest",null,a)},u.prototype.blockTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/block/"+a+"/transactions",b,c)},u.prototype.transaction=function(a,b){var c=this;return c.client.get("/transaction/"+a,null,b)},u.prototype.transactions=function(a,b){var c=this;return c.client.post("/transactions",null,a,b,!1)},u.prototype.allWebhooks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/webhooks",a,b)},u.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/webhook",null,{url:a,identifier:b},c)},u.prototype.getWebhook=function(a,b){var c=this;return c.client.get("/webhook/"+a,null,b)},u.prototype.updateWebhook=function(a,b,c){var d=this;return d.client.put("/webhook/"+a,null,b,c)},u.prototype.deleteWebhook=function(a,b){var c=this;return c.client.delete("/webhook/"+a,null,null,b)},u.prototype.getWebhookEvents=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/webhook/"+a+"/events",b,c)},u.prototype.subscribeTransaction=function(a,b,c,d){var e=this,f={event_type:"transaction",transaction:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.subscribeAddressTransactions=function(a,b,c,d){var e=this,f={event_type:"address-transactions",address:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.batchSubscribeAddressTransactions=function(a,b,c){var d=this;return b.forEach(function(a){a.event_type="address-transactions"}),d.client.post("/webhook/"+a+"/events/batch",null,b,c)},u.prototype.subscribeNewBlocks=function(a,b){var c=this,d={event_type:"block"};return c.client.post("/webhook/"+a+"/events",null,d,b)},u.prototype.unsubscribeAddressTransactions=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/address-transactions/"+b,null,null,c)},u.prototype.unsubscribeTransaction=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/transaction/"+b,null,null,c)},u.prototype.unsubscribeNewBlocks=function(a,b){var c=this;return c.client.delete("/webhook/"+a+"/block",null,null,b)},u.prototype.initWallet=function(a,b){var c=this;if("object"!=typeof a&&(a={identifier:arguments[0],passphrase:arguments[1]},b=arguments[2]),a.check_backup_key&&"string"!=typeof a.check_backup_key)throw new Error("Invalid input, must provide the backup key as a string (the xpub)");var d=g.defer();d.promise.spreadNodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin,i=a.identifier;return i?(d.resolve(c.client.get("/wallet/"+i,null,!0).then(function(b){var d=a.keyIndex||b.key_index;if(a.walletVersion=b.wallet_version,a.check_backup_key&&a.check_backup_key!==b.backup_public_key[0])throw new Error("Backup key returned from server didn't match our own copy");var g=h.HDNode.fromBase58(b.backup_public_key[0],e),j=f.mapValues(b.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),l=f.mapValues(b.primary_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),m=new k(c,i,a.walletVersion,b.primary_mnemonic,b.encrypted_primary_seed,b.encrypted_secret,l,g,j,d,b.chain||0,b.segwit||0,c.testnet,b.checksum,b.upgrade_key_index,a.bypassNewAddressCheck);return m.recoverySecret=b.recovery_secret,a.readOnly?m:m.unlock(a).then(function(){return m})})),d.promise):(d.reject(new p.WalletInitError("Identifier is required")),d.promise)},u.CREATE_WALLET_PROGRESS_START=0,u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET=4,u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY=5,u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY=6,u.CREATE_WALLET_PROGRESS_PRIMARY=10,u.CREATE_WALLET_PROGRESS_BACKUP=20,u.CREATE_WALLET_PROGRESS_SUBMIT=30,u.CREATE_WALLET_PROGRESS_INIT=40,u.CREATE_WALLET_PROGRESS_DONE=100,u.prototype.createNewWallet=function(a,b){var c=this;if("object"!=typeof a){var d=arguments[0],e=arguments[1],f=arguments[2];b=arguments[3],"function"==typeof f&&(b=f,f=null),a={identifier:d,passphrase:e,keyIndex:f}}a.walletVersion=a.walletVersion||k.WALLET_VERSION_V3;var h=g.defer();return h.promise.spreadNodeify(b),g.nextTick(function(){return h.notify(u.CREATE_WALLET_PROGRESS_START),a.keyIndex=a.keyIndex||0,a.passphrase=a.passphrase||a.password,delete a.password,a.identifier?void(a.walletVersion===k.WALLET_VERSION_V1?c._createNewWalletV1(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V2?c._createNewWalletV2(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V3?c._createNewWalletV3(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):h.reject(new p.WalletCreateError("Invalid wallet version!"))):(h.reject(new p.WalletCreateError("Identifier is required")),h.promise)}),h.promise},u.prototype._createNewWalletV1=function(a){var b=this,c=g.defer();return g.nextTick(function(){if(!a.primaryMnemonic&&!a.primarySeed){if(!a.passphrase&&!a.password)return c.reject(new p.WalletCreateError("Can't generate Primary Mnemonic without a passphrase")),c.promise;a.primaryMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS),a.storePrimaryMnemonic!==!1&&(a.storePrimaryMnemonic=!0)}a.backupMnemonic||a.backupPublicKey||(a.backupMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS)),c.notify(u.CREATE_WALLET_PROGRESS_PRIMARY),b.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return c.notify(u.CREATE_WALLET_PROGRESS_BACKUP),b.resolveBackupPublicKeyFromOptions(a).then(function(a){c.notify(u.CREATE_WALLET_PROGRESS_SUBMIT);var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex,g=a.primaryPrivateKey.deriveHardened(e).neutered();return b.storeNewWalletV1(a.identifier,[g.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storePrimaryMnemonic&&a.primaryMnemonic,d,e,a.segwit||null).then(function(i){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var j=f.mapValues(i.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V1,a.primaryMnemonic,null,null,{keyIndex:g},a.backupPublicKey,j,e,i.chain||0,i.segwit||0,b.testnet,d,i.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V1,passphrase:a.passphrase,primarySeed:a.primarySeed,primaryMnemonic:null}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,primaryMnemonic:a.primaryMnemonic,backupMnemonic:a.backupMnemonic,blocktrailPublicKeys:j}]})})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)})}),c.promise},u.prototype._createNewWalletV2=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return w(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV2(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V2,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V2,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?j.entropyToMnemonic(p.convert(a.encryptedPrimarySeed,"base64","hex")):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed.toString("hex")):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?j.entropyToMnemonic(p.convert(a.recoveryEncryptedSecret,"base64","hex")):null,encryptedSecret:a.encryptedSecret?j.entropyToMnemonic(p.convert(a.encryptedSecret,"base64","hex")):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype._createNewWalletV3=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return b.produceEncryptedDataV3(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV3(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V3,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V3,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?o.encode(a.encryptedPrimarySeed):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?o.encode(a.recoveryEncryptedSecret):null,encryptedSecret:a.encryptedSecret?o.encode(a.encryptedSecret):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype.storeNewWalletV1=function(a,b,c,d,f,g,h){var i=this,j={identifier:a,wallet_version:k.WALLET_VERSION_V1,primary_public_key:b,backup_public_key:c,primary_mnemonic:d,checksum:f,key_index:g,segwit:h};return e(j,i.network),i.client.post("/wallet",null,j)},u.prototype.storeNewWalletV2=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V2,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d,encrypted_secret:f,recovery_secret:g,checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.storeNewWalletV3=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V3,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d.toString("base64"),encrypted_secret:f.toString("base64"),recovery_secret:g.toString("hex"),checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.updateWallet=function(a,b,c){var d=this;return d.client.post("/wallet/"+a,null,b,c)},u.prototype.upgradeKeyIndex=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/upgrade",null,{key_index:b,primary_public_key:c},d)},u.prototype.getWalletBalance=function(a,b){var c=this;return c.client.get("/wallet/"+a+"/balance",null,!0,b)},u.prototype.doWalletDiscovery=function(a,b,c){var d=this;return d.client.get("/wallet/"+a+"/discovery",{gap:b},!0,c)},u.prototype.getNewDerivation=function(a,b,c){var d=this;return d.client.post("/wallet/"+a+"/path",null,{path:b},c)},u.prototype.deleteWallet=function(a,b,c,d,e){var f=this;return"function"==typeof d&&(e=d,d=!1),f.client.delete("/wallet/"+a,{force:d},{checksum:b,signature:c},e)},u.prototype.coinSelection=function(a,b,c,d,e,f,h){var i=this;"function"==typeof e?(h=e,e=null,f={}):"function"==typeof f&&(h=f,f={}),e=e||k.FEE_STRATEGY_OPTIMAL,f=f||{};var j=g.defer();j.promise.spreadNodeify(h);var l={lock:c,zeroconf:d?1:0,zeroconfself:"undefined"==typeof f.allowZeroConfSelf||f.allowZeroConfSelf?1:0,fee_strategy:e};return f.forcefee&&(l.forcefee=f.forcefee),j.resolve(i.client.post("/wallet/"+a+"/coin-selection",l,b).then(function(a){return[a.utxos,a.fee,a.change,a]},function(a){if(a.message.match(/too low to pay the fee/))throw p.WalletFeeError(a);throw a})),j.promise},u.prototype.feePerKB=function(a){var b=this,c=g.defer();return c.promise.spreadNodeify(a),c.resolve(b.client.get("/fee-per-kb")),c.promise},u.prototype.sendTransaction=function(a,b,c,d,e,f,g){var h=this;"function"==typeof e?(g=e,e=null,f=!1):"function"==typeof f&&(g=f,f=!1);var i={paths:c,two_factor_token:e};return"string"==typeof b?i.raw_transaction=b:"object"==typeof b&&Object.keys(b).map(function(a){i[a]=b[a]}),h.client.post("/wallet/"+a+"/send",{check_fee:d?1:0,prioboost:f?1:0},i,g)},u.prototype.setupWalletWebhook=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/webhook",null,{url:c,identifier:b},d)},u.prototype.deleteWalletWebhook=function(a,b,c){var d=this;return d.client.delete("/wallet/"+a+"/webhook/"+b,null,null,c)},u.prototype.walletTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/transactions",b,!0,c)},u.prototype.walletAddresses=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/addresses",b,!0,c)},u.prototype.labelWalletAddress=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/address/"+b+"/label",null,{label:c},d)},u.prototype.walletMaxSpendable=function(a,b,c,d,e){var f=this;"function"==typeof c?(e=c,c=null):"function"==typeof d&&(e=d,d={}),c=c||k.FEE_STRATEGY_OPTIMAL,d=d||{};var g={outputs:d.outputs?d.outputs:1,zeroconf:b?1:0,zeroconfself:"undefined"==typeof d.allowZeroConfSelf||d.allowZeroConfSelf?1:0,fee_strategy:c};return d.forcefee&&(g.forcefee=d.forcefee),f.client.get("/wallet/"+a+"/max-spendable",g,!0,e)},u.prototype.walletUTXOs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/utxos",b,!0,c)},u.prototype.allWallets=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/wallets",a,!0,b)},u.prototype.verifyMessage=function(a,b,c,d){var e=this,f=g.defer();f.promise.nodeify(d);try{var h=i.verify(b,e.network.messagePrefix,a,new Buffer(c,"base64"));f.resolve(h)}catch(a){f.reject(a)}return f.promise},u.prototype.faucetWithdrawl=function(a,b,c){var d=this;return d.client.post("/faucet/withdrawl",null,{address:a,amount:b},c)},u.prototype.sendRawTransaction=function(a,b){var c=this;return c.client.post("/send-raw-tx",null,a,b)},u.prototype.price=function(a){var b=this;return b.client.get("/price",null,!1,a)},b.exports=u}).call(this,a("_process"),a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,"./rest_client":9,"./use-webworker":14,"./wallet":15,"./webworker":17,"./webworkifier":18,_process:263,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293,randombytes:297}],2:[function(a,b,c){(function(Buffer){var c=a("util"),d=a("assert"),e=a("crypto-js"),f=a("bip39"),g={COIN:1e8,PRECISION:8,DUST:2730,BASE_FEE:1e4},h=function(a,b,c){return new Buffer(a,b).toString(c)},i=function(a,b){var c=f.mnemonicToEntropy(a),d=h(c,"hex","base64"),i=e.AES.decrypt(d,b).toString(e.enc.Utf8);if(!i.length)throw new g.WalletDecryptError;return i},j=function(a,b){return i(a,b).toString(e.enc.Utf8)},k=function(a,b){return h(j(a,b),"base64","hex")},l=function(a,b){return new Buffer(k(a,b),"hex")},m=function(a,b){var c=e.AES.encrypt(a,b).toString(e.format.OpenSSL),d=h(c,"base64","hex"),g=f.entropyToMnemonic(d);return g},n=function(a,b){return m(h(a,"hex","base64"),b)},o=function(a,b){return m(a.toString("base64"),b)};g.convert=h,g.aesDecryptMnemonicToSeed=j,g.aesDecryptMnemonicToSeedBuffer=l,g.aesDecryptMnemonicToSeedHex=k,g.aesEncryptSeedToMnemonic=m,g.aesEncryptSeedHexToMnemonic=n,g.aesEncryptSeedBufferToMnemonic=o,g.V3Crypt={KeyDerivation:a("./keyderivation"),Encryption:a("./encryption"),EncryptionMnemonic:a("./encryption_mnemonic")},g.toSatoshi=function(a){return parseInt((a*g.COIN).toFixed(0),10)},g.toBTC=function(a){return(a/g.COIN).toFixed(g.PRECISION)},g.patchQ=function(a){function b(b,c,d){return a(b).spreadDone(c,d)}function c(b,c){return a(b).spreadNodeify(c)}a.spreadNodeify&&a.spreadDone||(a.spreadDone=b,a.makePromise.prototype.spreadDone=function(a,b){return this.all().done(function(b){return a.apply(void 0,b)},b)},a.spreadNodeify=c,a.makePromise.prototype.spreadNodeify=function(b){return b?void this.then(function(c){a.nextTick(function(){b.apply(void 0,[null].concat(c))})},function(c){a.nextTick(function(){b(c)})}):this})},Error.extend=function(a,b){d(a,"subTypeName is required");var e=function(c){return this instanceof e?(this.name=a,this.code=b,this.message=c?c.message||c||"":"",void(Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor))):new e(c)};return c.inherits(e,this),e.prototype.toString=function(){return this.name+": "+c.inspect(this.message)},e.extend=this.extend,e},"function"!=typeof Uint8Array.prototype.reverse&&(Buffer.prototype.reverse=function(){for(var a,b=0,c=this.length-1;b<=c;++b,--c)a=this[b],this[b]=this[c],this[c]=a;return this}),g.WalletInitError=Error.extend("WalletInitError",400),g.WalletCreateError=Error.extend("WalletCreateError",400),g.WalletUpgradeError=Error.extend("WalletUpgradeError",400),g.WalletChecksumError=Error.extend("WalletChecksumError",400),g.WalletDeleteError=Error.extend("WalletDeleteError",400),g.WalletDecryptError=Error.extend("WalletDecryptError",400),g.WalletAddressError=Error.extend("WalletAddressError",500),g.WalletSendError=Error.extend("WalletSendError",400),g.WalletLockedError=Error.extend("WalletLockedError",500),g.WalletFeeError=Error.extend("WalletFeeError",500),g.WalletInvalid2FAError=Error.extend("WalletInvalid2FAError",401),g.WalletMissing2FAError=Error.extend("WalletMissing2FAError",401),g.TransactionSignError=Error.extend("TransactionSignError",500),g.TransactionInputError=Error.extend("TransactionInputError",400),g.TransactionOutputError=Error.extend("TransactionOutputError",400),g.KeyPathError=Error.extend("KeyPathError",400),g.InvalidAddressError=Error.extend("InvalidAddressError",400),g.Error=Error.extend("Error",500),g.FEE_STRATEGY_FORCE_FEE="force_fee",g.FEE_STRATEGY_BASE_FEE="base_fee",g.FEE_STRATEGY_OPTIMAL="optimal",g.FEE_STRATEGY_LOW_PRIORITY="low_priority",g.FEE_STRATEGY_MIN_RELAY_FEE="min_relay_fee",g.patchQ(a("q")),b.exports=g}).call(this,a("buffer").Buffer)},{"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,assert:20,bip39:28,buffer:105,"crypto-js":185,q:293,util:360}],3:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("sjcl"),e=a("./keyderivation"),f=a("randombytes"),g={defaultSaltLen:10,tagLenBits:128,ivLenBits:128,ivLenWords:4};g.generateSalt=function(){return f(this.defaultSaltLen)},g.generateIV=function(){return f(this.ivLenBits/8)},g.encrypt=function(a,b,c){var d=this.generateSalt(),f=this.generateIV();return c="undefined"==typeof c?e.defaultIterations:c,this.encryptWithSaltAndIV(a,b,d,f,c)},g.encryptWithSaltAndIV=function(a,b,f,g,h){c(a instanceof Buffer,"pt must be provided as a buffer"),c(b instanceof Buffer,"pw must be provided as a buffer"),c(g instanceof Buffer,"IV must be provided as a buffer"),c(f instanceof Buffer,"saltBuff must be provided as a buffer"),c(16===g.length,"IV must be exactly 16 bytes");var i=new Buffer(1),j=f,k=new Buffer(4);i.writeUInt8(f.length),k.writeUInt32LE(h);var l=i.toString("hex")+j.toString("hex")+k.toString("hex"),m=d.codec.hex.toBits(e.compute(b,f,h).toString("hex")),n=d.mode.gcm.encrypt(new d.cipher.aes(m),d.codec.hex.toBits(a.toString("hex")),d.codec.hex.toBits(g.toString("hex")),d.codec.hex.toBits(l),this.tagLenBits);return new Buffer([l,g.toString("hex"),d.codec.hex.fromBits(n)].join(""),"hex")},g.decrypt=function(a,b){c(a instanceof Buffer,"cipherText must be provided as a Buffer"),c(b instanceof Buffer,"password must be provided as a Buffer");var f=new Buffer(a,"hex"),g=0,h=f.readUInt8(g);g+=1;var i=f.slice(1,g+h);g+=h;var j=f.readUInt32LE(g);g+=4;var k=f.slice(0,g),l=f.slice(g,16+g);g+=16;var m=f.slice(g),n=e.compute(b,i,j),o=d.mode.gcm.decrypt(new d.cipher.aes(d.codec.hex.toBits(n.toString("hex"))),d.codec.hex.toBits(m.toString("hex")),d.codec.hex.toBits(l.toString("hex")),d.codec.hex.toBits(k.toString("hex")),this.tagLenBits);return new Buffer(d.codec.hex.fromBits(o),"hex")},b.exports=g}).call(this,a("buffer").Buffer)},{"./keyderivation":5,assert:20,buffer:105,randombytes:297,sjcl:343}],4:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bip39");String.prototype.repeat||(String.prototype.repeat=function(a){"use strict";if(null===this)throw new TypeError("can't convert "+this+" to object");var b=""+this;if(a=+a,a!==a&&(a=0),a<0)throw new RangeError("repeat count must be non-negative");if(a===1/0)throw new RangeError("repeat count must be less than infinity");if(a=Math.floor(a),0===b.length||0===a)return"";if(b.length*a>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");for(var c="";1===(1&a)&&(c+=b),a>>>=1,0!==a;)b+=b;return c});var e={chunkSize:4,paddingDummy:129},f=function(a){if(a[0]>128)throw new Error("Mnemonic sanity check - first byte can never be above 0x80");return e.paddingDummy.toString(16).repeat(e.chunkSize-a.length%e.chunkSize)};e.encode=function(a){c(a instanceof Buffer,"Data must be provided as a Buffer");var b=f(a),e=d.entropyToMnemonic(b+a.toString("hex"));try{d.mnemonicToEntropy(e)}catch(a){throw new Error("BIP39 library produced an invalid mnemonic")}return e},e.decode=function(a){c("string"==typeof a,"Mnemonic must be provided as a string");for(var b=new Buffer(d.mnemonicToEntropy(a),"hex"),e=0;b[e]===this.paddingDummy;)e++;var g=b.slice(e,b.length);if(f(g)!==b.slice(0,e).toString("hex"))throw new Error("There is only one way to pad a string");return g},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,
2
bip39:28,buffer:105}],5:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("./pbkdf2_sha512"),e={defaultIterations:35e3,subkeyIterations:1,keySizeBits:256};e.compute=function(a,b,e){if(e=e||this.defaultIterations,c(a instanceof Buffer,"Password must be provided as a Buffer"),c(b instanceof Buffer,"Salt must be provided as a Buffer"),c(b.length>0,"Salt must not be empty"),c("number"==typeof e,"Iterations must be a number"),c(e>0,"Iteration count should be at least 1"),b.length>128)throw new Error("Sanity check: Invalid salt, length can never be greater than 128");return d.digest(a,b,e,this.keySizeBits/8)},b.exports=e}).call(this,a("buffer").Buffer)},{"./pbkdf2_sha512":6,assert:20,buffer:105}],6:[function(a,b,c){(function(Buffer){var c=a("../vendor/asmcrypto.js/asmcrypto.js"),d=function(a,b,d,e){return new Buffer(new c.PBKDF2_HMAC_SHA512.bytes(a,b,d,e).buffer)};b.exports={digest:d}}).call(this,a("buffer").Buffer)},{"../vendor/asmcrypto.js/asmcrypto.js":365,buffer:105}],7:[function(a,b,c){b.exports=c={VERSION:"3.5.3"}},{}],8:[function(a,b,c){(function(c){function d(a){var b=this;b.https=a.https,b.host=a.host,b.endpoint=a.endpoint,b.auth=a.auth,b.port=a.port,b.apiKey=a.apiKey,b.apiSecret=a.apiSecret,b.contentMd5="undefined"==typeof a.contentMd5||a.contentMd5,b.params=f.defaults({},a.params),b.headers=f.defaults({},a.headers)}var e=a("./blocktrail"),f=a("lodash"),g=a("url"),h=a("querystring"),i=a("q"),j=a("create-hash"),k=a("superagent"),l=a("superagent-http-signature/index-hmac-only"),m=a("debug")("blocktrail-sdk:request"),n=!c.browser,o=function(){};d.qs=function(a){var b=[],c=Object.keys(a);return c.sort(),c.forEach(function(c){var d={};d[c]=a[c],b.push(h.stringify(d))}),b.join("&")},d.prototype.request=function(a,b,c,e,h){var k=this;k.deferred=i.defer(),k.callback=h||o;var l=g.parse(b,!0),p=d.qs(f.defaults({},c||{},l.query||{},k.params||{}));k.path="".concat(k.endpoint,l.pathname),p&&(k.path=k.path.concat("?",p)),e?(k.payload=JSON.stringify(e),k.headers["Content-Type"]="application/json"):k.payload="",n&&(k.headers["Content-Length"]=k.payload?k.payload.length:0),k.contentMd5===!0&&("GET"===a||"DELETE"===a?k.headers["Content-MD5"]=j("md5").update(k.path).digest().toString("hex"):k.headers["Content-MD5"]=j("md5").update(k.payload).digest().toString("hex")),m("%s %s %s",a,k.host,k.path);var q={hostname:k.host,path:k.path,port:k.port,method:a,headers:k.headers,auth:k.auth,agent:!1,withCredentials:!1};return k.performRequest(q),k.deferred.promise},d.prototype.performRequest=function(a){var b=this,c=a.method,e=!1;"http-signature"===a.auth&&(e=!0,delete a.auth);var g=(b.https?"https://":"http://")+a.hostname+a.path,h=k(c,g);if(!b.payload||"DELETE"!==c&&"POST"!==c&&"PUT"!==c&&"PATCH"!==c||h.send(b.payload),f.forEach(a.headers,function(a,b){h.set(b,a)}),e){if(!b.apiSecret){var i=new Error("Missing apiSecret! required to sign POST requests!");return b.deferred.reject(i),b.callback(i)}h.use(l({headers:["(request-target)","content-md5"],algorithm:"hmac-sha256",key:b.apiSecret,keyId:b.apiKey}))}return h.end(function(a,c){var e;if(a)return b.deferred.reject(a),b.callback(a);if(m("response status code: %s content type: %s",c.status,c.headers["content-type"]),!a&&c.headers["content-type"].indexOf("application/json")>=0)try{e=JSON.parse(c.text)}catch(b){a=b}return a||200===c.status||(a=d.handleFailure(c.text,c.statusCode)),a?b.deferred.reject(a):b.deferred.resolve(e),b.callback(a,e)}),b.deferred},d.handleFailure=function(a,b){var c,e;if("object"==typeof a)c=a;else try{c=JSON.parse(a)}catch(a){}return c?(e=new Error(c.msg?c.msg:null),Object.keys(c).forEach(function(a){"msg"!==a&&(e[a]=c[a])})):e=a?new Error(a):new Error("Unknown Server Error"),b&&(e.statusCode=b),d.convertError(e)},d.convertError=function(a){return a.requires_2fa?new e.WalletMissing2FAError:a.message.match(/Invalid two_factor_token/)?new e.WalletInvalid2FAError:a},b.exports=d}).call(this,a("_process"))},{"./blocktrail":2,_process:263,"create-hash":128,debug:211,lodash:249,q:293,querystring:296,superagent:349,"superagent-http-signature/index-hmac-only":346,url:355}],9:[function(a,b,c){var d=a("lodash"),e=a("./request"),f=function(b){var c=this;c.apiKey=b.apiKey,c.apiSecret=b.apiSecret,c.https=b.https,c.host=b.host,c.port=b.port,c.endpoint=b.endpoint,c.defaultParams={},c.apiKey&&(c.defaultParams.api_key=c.apiKey),c.defaultHeaders=d.defaults({},{"X-SDK-Version":"blocktrail-sdk-nodejs/"+a("./pkginfo").VERSION},b.defaultHeaders)};f.prototype.create_request=function(a){var b=this;return a=d.defaults({},a,{https:b.https,host:b.host,port:b.port,endpoint:b.endpoint,apiKey:b.apiKey,apiSecret:b.apiSecret,params:d.defaults({},b.defaultParams),headers:d.defaults({},b.defaultHeaders)}),new e(a)},f.prototype.post=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("POST",a,b,c,d)},f.prototype.put=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("PUT",a,b,c,d)},f.prototype.get=function(a,b,c,d){"function"==typeof c&&(d=c,c=!1);var e={};return c&&(e.auth="http-signature"),this.create_request(e).request("GET",a,b,null,d)},f.prototype.delete=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("DELETE",a,b,c,d)},b.exports=function(a){return new f(a)}},{"./pkginfo":7,"./request":8,lodash:249}],10:[function(a,b,c){var d=a("../api_client"),e=a("lodash"),f=a("q"),g=a("async"),h=function(a){this.defaultSettings={apiKey:null,apiSecret:null,network:"BTC",testnet:!1,apiVersion:"v1",apiEndpoint:null,retryLimit:5,retryDelay:20,paginationLimit:200},this.settings=e.merge({},this.defaultSettings,a);var b=this.normaliseNetwork(this.settings.network,this.settings.testnet);this.settings.network=b.network,this.settings.testnet=b.testnet,this.client=new d(this.settings)};h.prototype.normaliseNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?{network:"BTC",testnet:!0}:{network:"BTC",testnet:!1};case"tbtc":case"bitcoin-testnet":return{network:"BTC",testnet:!0};case"bcc":return b?{network:"BCC",testnet:!0}:{network:"BCC",testnet:!1};case"tbcc":return{network:"BCC",testnet:!0};default:throw new Error("Unknown network "+a)}},h.prototype.setPaginationLimit=function(a){this.settings.paginationLimit=a},h.prototype.estimateFee=function(){var a=this;return a.client.feePerKB().then(function(a){return Math.max(a.optimal,a.min_relay_fee)})},h.prototype.getBatchUnspentOutputs=function(a){var b=this,c=f.defer(),d=1,e=null,h=[];return g.doWhilst(function(c){var e={page:d,limit:b.settings.paginationLimit};b.client.batchAddressUnspentOutputs(a,e).then(function(a){h=h.concat(a.data),d++,c()},function(a){console.log("error happened:",a),c(a)})},function(){return e&&e.data.length>0},function(a){a&&console.log("complete, but with errors",a.message);var b={};h.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.hash,index:a.index,value:a.value,script_hex:a.script_hex})}),c.resolve(b)}),c.promise},h.prototype.batchAddressHasTransactions=function(a){var b=this;return b.client.batchAddressHasTransactions(a).then(function(a){return a.has_transactions})},b.exports=h},{"../api_client":1,async:21,lodash:249,q:293}],11:[function(a,b,c){var d=a("../blocktrail"),e=a("superagent"),f=a("lodash"),g=a("q"),h="https://insight.bitpay.com/api",i="https://test-insight.bitpay.com/api",j=function(a){this.defaultSettings={host:h,testnet:!1,retryLimit:5,retryDelay:20},"undefined"==typeof a.host&&a.testnet&&(this.defaultSettings.host=i),this.settings=f.merge({},this.defaultSettings,a),this.DEFAULT_ENDPOINT_MAINNET=h,this.DEFAULT_ENDPOINT_TESTNET=i};j.prototype.getBatchUnspentOutputs=function(a){var b=this,c=g.defer(),e={addrs:a.join(",")};return b.postEndpoint("addrs/utxo",e).then(function(a){var b={};a.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.txid,index:a.vout,value:d.toSatoshi(a.amount),script_hex:a.scriptPubKey})}),c.resolve(b)},function(a){c.reject(a)}),c.promise},j.prototype.batchAddressHasTransactions=function(a){var b=this,c={addrs:a.join(",")};return b.postEndpoint("addrs/txs",c).then(function(a){return a.items.length>0})},j.prototype.estimateFee=function(){var a=this,b="4";return a.getEndpoint("utils/estimatefee?nbBlocks="+b).then(function(a){return a[b]===-1?1e5:parseInt(1e8*a[b],10)})},j.prototype.sendTx=function(a){return this.postEndpoint("tx/send",{rawtx:a})},j.prototype.getEndpoint=function(a){return this.getRequest(this.settings.host+"/"+a)},j.prototype.postEndpoint=function(a,b){return this.postRequest(this.settings.host+"/"+a,b)},j.prototype.getRequest=function(a){var b=g.defer();return e.get(a).end(function(a,c){if(a)return void b.reject(a);if(!c.ok)return b.reject(c.text);if(!(c.headers["content-type"].indexOf("application/json")>=0))return b.resolve(c.body);try{var d=JSON.parse(c.text);return b.resolve(d)}catch(c){return b.reject(a)}}),b.promise},j.prototype.postRequest=function(a,b){var c=g.defer();return e.post(a).send(b).set("Content-Type","application/json").end(function(a,b){if(a)return void c.reject(a);if(!b.ok)return c.reject(b.text);if(!(b.headers["content-type"].indexOf("application/json")>=0))return c.resolve(b.body);try{var d=JSON.parse(b.text);return c.resolve(d)}catch(b){return c.reject(a)}}),c.promise},b.exports=j},{"../blocktrail":2,lodash:249,q:293,superagent:349}],12:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bitcoinjs-lib"),e={SIZE_DER_SIGNATURE:72,SIZE_V0_P2WSH:36};e.getPublicKeySize=function(a){return a?33:65},e.getLengthForScriptPush=function(a){if(a<75)return 1;if(a<=255)return 2;if(a<=65535)return 3;if(a<=4294967295)return 5;throw new Error("Size of pushdata too large")},e.getLengthForVarInt=function(a){if(a<253)return 1;var b;if(a<65535)b=2;else if(a<4294967295)b=4;else{if(!(a<0x10000000000000000))throw new Error("Size of varint too large");b=8}return 1+b},e.estimateMultisigStackSize=function(a,b){var c,d=[0];for(c=0;c<a;c++)d.push(e.SIZE_DER_SIGNATURE);var f=1;for(c=0;c<b.length;c++)f+=this.getLengthForScriptPush(b[c].length)+b[c].length;return f+=2,[d,f]},e.estimateP2PKStackSize=function(a){var b=[e.SIZE_DER_SIGNATURE],c=this.getLengthForScriptPush(a.length)+a.length+1;return[b,c]},e.estimateP2PKHStackSize=function(a){"undefined"==typeof a&&(a=!0);var b=[this.SIZE_DER_SIGNATURE,this.getPublicKeySize(a)],c=2+this.getLengthForScriptPush(20)+20+2;return[b,c]},e.estimateStackSignatureSize=function(a,b,d,e){c(null===e||b);var f=[],g=[];b?(g=a,e instanceof Buffer&&g.push(e.length)):f=a,d instanceof Buffer&&f.push(d.length);var h=this,i=0;f.map(function(a){i+=h.getLengthForScriptPush(a)+a}),i+=h.getLengthForVarInt(i);var j=0;return g.length>0&&(g.map(function(a){j+=h.getLengthForVarInt(a)+a}),j+=h.getLengthForVarInt(g.length)),[i,j]},e.estimateInputFromScripts=function(a,b,e,f,g){c(null===e||f);var h;if(d.script.multisig.output.check(a)){var i=d.script.multisig.output.decode(a);h=this.estimateMultisigStackSize(i.m,i.pubKeys)[0]}else if(d.script.pubKey.output.check(a)){var j=d.script.pubKey.output.decode(a);h=this.estimateP2PKStackSize(j)[0]}else{if(!d.script.pubKeyHash.output.check(a))throw new Error("Unsupported script type");h=this.estimateP2PKHStackSize(g)[0]}return this.estimateStackSignatureSize(h,f,b,e)},e.estimateUtxo=function(a,b){var c=Buffer.from(a.scriptpubkey_hex,"hex"),e="string"==typeof a.redeem_script?Buffer.from(a.redeem_script,"hex"):null,f="string"==typeof a.witness_script?Buffer.from(a.witness_script,"hex"):null,g=!1,h=c;if(d.script.scriptHash.output.check(h)){if(null===e)throw new Error("Cant estimate, missing redeem script");h=e}if(d.script.witnessPubKeyHash.output.check(h)){var i=d.script.witnessPubKeyHash.output.decode(h);h=d.script.pubKeyHash.output.encode(i),g=!0}else if(d.script.witnessScriptHash.output.check(h)){if(null===f)throw new Error("Can't estimate, missing witness script");h=f,g=!0}var j=d.script.types,k=[j.MULTISIG,j.P2PKH,j.P2PK],l=d.script.classifyOutput(h);if(k.indexOf(l)===-1)throw new Error("Unsupported script type");var m=this.estimateInputFromScripts(h,e,f,g,b);return{scriptSig:m[0],witness:m[1]}},e.estimateInputsSize=function(a,b){var c=0,d=0;return a.map(function(a){var f=e.estimateUtxo(a);c+=40+f.scriptSig,b&&(d+=f.witness)}),b&&d>0&&(c+=2+d),c},e.calculateOutputsSize=function(a){var b=0;return a.map(function(a){var c=e.getLengthForVarInt(a.script.length);b+=8+c+a.script.length}),b},e.estimateTxWeight=function(a,b){var c=e.calculateOutputsSize(a.outs),d=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!1)+e.getLengthForVarInt(a.outs.length)+c+4,f=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!0)+e.getLengthForVarInt(a.outs.length)+c+4;return 3*d+f},e.estimateTxVsize=function(a,b){return parseInt(Math.ceil(e.estimateTxWeight(a,b)/4),10)},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,"bitcoinjs-lib":43,buffer:105}],13:[function(a,b,c){var d=a("lodash"),e=a("q"),f=a("async"),g=function(a,b){this.defaultSettings={logging:!1,batchChunkSize:200},this.settings=d.merge({},this.defaultSettings,b),this.client=a};g.prototype.getUTXOs=function(a){var b=this,c={},g=e.defer();return f.eachSeries(d.chunk(a,b.settings.batchChunkSize),function(a,e){b.settings.logging&&console.log("checking batch of "+a.length+" addresses for UTXOs",a.join(",")),b.client.getBatchUnspentOutputs(a).done(function(a){d.each(a,function(a,b){a.length>0&&(c[b]=a)}),e()},function(a){e(a)})},function(a){a&&console.log("error encountered",a),g.resolve(c)}),g.promise},b.exports=g},{async:21,lodash:249,q:293}],14:[function(a,b,c){(function(a){var d=!a.browser,e=!d&&"undefined"!=typeof window&&"undefined"!=typeof window.Worker,f=("undefined"!=typeof navigator&&navigator.userAgent||"").match(/Android (\d)\.(\d)(\.(\d))/);f&&f[1]<=4&&(e=!1),b.exports=c=function(){return e}}).call(this,a("_process"))},{_process:263}],15:[function(a,b,c){(function(Buffer){var c=a("lodash"),d=a("assert"),e=a("q"),f=a("async"),g=a("bitcoinjs-lib"),h=a("bitcoinjs-message"),i=a("./blocktrail"),j=a("crypto-js"),k=a("./encryption"),l=a("./encryption_mnemonic"),m=a("./size_estimation"),n=a("bip39"),o={SIGN:"sign",DONT_SIGN:"dont_sign"},p=function(a,b,e,f,h,i,j,k,l,m,n,o,q,r,s,t){var u=this;u.sdk=a,u.identifier=b,u.walletVersion=e,u.locked=!0,u.bypassNewAddressCheck=!!t,u.bitcoinCash=u.sdk.bitcoinCash,d(0===o||!u.bitcoinCash),u.testnet=q,u.bitcoinCash?u.testnet?u.network=g.networks.bitcoincashtestnet:u.network=g.networks.bitcoincash:u.testnet?u.network=g.networks.testnet:u.network=g.networks.bitcoin,d(k instanceof g.HDNode),d(c.every(j,function(a){return a instanceof g.HDNode})),d(c.every(l,function(a){return a instanceof g.HDNode})),u.primaryMnemonic=f,u.encryptedPrimarySeed=h,u.encryptedSecret=i,u.primaryPrivateKey=null,u.backupPrivateKey=null,u.backupPublicKey=k,u.blocktrailPublicKeys=l,u.primaryPublicKeys=j,u.keyIndex=m;var v;v=u.bitcoinCash?p.CHAIN_BCC_DEFAULT:o?p.CHAIN_BTC_SEGWIT:p.CHAIN_BTC_DEFAULT,u.chain=v,u.checksum=r,u.upgradeToKeyIndex=s,u.secret=null,u.seedHex=null};p.WALLET_VERSION_V1="v1",p.WALLET_VERSION_V2="v2",p.WALLET_VERSION_V3="v3",p.WALLET_ENTROPY_BITS=256,p.OP_RETURN="opreturn",p.DATA=p.OP_RETURN,p.PAY_PROGRESS_START=0,p.PAY_PROGRESS_COIN_SELECTION=10,p.PAY_PROGRESS_CHANGE_ADDRESS=20,p.PAY_PROGRESS_SIGN=30,p.PAY_PROGRESS_SEND=40,p.PAY_PROGRESS_DONE=100,p.CHAIN_BTC_DEFAULT=0,p.CHAIN_BTC_SEGWIT=2,p.CHAIN_BCC_DEFAULT=1,p.FEE_STRATEGY_FORCE_FEE=i.FEE_STRATEGY_FORCE_FEE,p.FEE_STRATEGY_BASE_FEE=i.FEE_STRATEGY_BASE_FEE,p.FEE_STRATEGY_OPTIMAL=i.FEE_STRATEGY_OPTIMAL,p.FEE_STRATEGY_LOW_PRIORITY=i.FEE_STRATEGY_LOW_PRIORITY,p.FEE_STRATEGY_MIN_RELAY_FEE=i.FEE_STRATEGY_MIN_RELAY_FEE,p.prototype.isSegwit=function(){return p.CHAIN_BTC_SEGWIT===this.chain},p.prototype.unlock=function(a,b){var d=this,f=e.defer();return f.promise.nodeify(b),a=c.merge({},a),e.fcall(function(){switch(d.walletVersion){case p.WALLET_VERSION_V1:return d.unlockV1(a);case p.WALLET_VERSION_V2:return d.unlockV2(a);case p.WALLET_VERSION_V3:return d.unlockV3(a);default:return e.reject(new i.WalletInitError("Invalid wallet version"))}}).then(function(a){d.primaryPrivateKey=a;var b=d.primaryPrivateKey.getAddress();if(b!==d.checksum)throw new i.WalletChecksumError("Generated checksum ["+b+"] does not match ["+d.checksum+"], most likely due to incorrect password");if(d.locked=!1,"undefined"!=typeof d.upgradeToKeyIndex&&null!==d.upgradeToKeyIndex)return d.upgradeKeyIndex(d.upgradeToKeyIndex)}).then(function(a){f.resolve(a)},function(a){f.reject(a)}),f.promise},p.prototype.unlockV1=function(a){var b=this;return a.primaryMnemonic="undefined"!=typeof a.primaryMnemonic?a.primaryMnemonic:b.primaryMnemonic,a.secretMnemonic="undefined"!=typeof a.secretMnemonic?a.secretMnemonic:b.secretMnemonic,b.sdk.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return b.primarySeed=a.primarySeed,a.primaryPrivateKey})},p.prototype.unlockV2=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletDecryptError("specifying primaryPrivateKey has been deprecated");if(a.primarySeed)c.primarySeed=a.primarySeed;else if(a.secret)try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}else{if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");a.passphrase=a.passphrase||a.password;try{if(c.secret=j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedSecret),a.passphrase).toString(j.enc.Utf8),!c.secret.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt secret")}try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}}return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})),d.promise},p.prototype.unlockV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){return e.when().then(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletInitError("specifying primaryPrivateKey has been deprecated");if(!a.primarySeed){if(a.secret)return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")});if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");return a.passphrase=a.passphrase||a.password,delete a.password,c.sdk.promisedDecrypt(new Buffer(a.encryptedSecret,"base64"),new Buffer(a.passphrase)).then(function(a){c.secret=a},function(){throw new i.WalletDecryptError("Failed to decrypt secret")}).then(function(){return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")})})}c.primarySeed=a.primarySeed}).then(function(){return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})})),d.promise},p.prototype.lock=function(){var a=this;a.secret=null,a.primarySeed=null,a.primaryPrivateKey=null,a.backupPrivateKey=null,a.locked=!0},p.prototype.upgradeToV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.when(!0).then(function(){if(c.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to upgrade");if(c.walletVersion===p.WALLET_VERSION_V3)throw new i.WalletUpgradeError("Wallet is already V3");return c.walletVersion===p.WALLET_VERSION_V2?c._upgradeV2ToV3(a,d.notify.bind(d)):c.walletVersion===p.WALLET_VERSION_V1?c._upgradeV1ToV3(a,d.notify.bind(d)):void 0}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},p.prototype._upgradeV2ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed,recoverySecret:!1};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.sdk.updateWallet(c.identifier,{encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype._upgradeV1ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.recoveryEncryptedSecret=a.recoveryEncryptedSecret,c.sdk.updateWallet(c.identifier,{primary_mnemonic:"",encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),recovery_secret:a.recoverySecret.toString("hex"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype.doPasswordChange=function(a){var b=this;return e.when(null).then(function(){if(b.walletVersion===p.WALLET_VERSION_V1)throw new i.WalletLockedError("Wallet version does not support password change!");if(b.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to change password");if(!b.secret)throw new i.WalletLockedError("No secret");var c,d;if(b.walletVersion===p.WALLET_VERSION_V2)c=j.AES.encrypt(b.secret,a).toString(j.format.OpenSSL),d=n.entropyToMnemonic(i.convert(c,"base64","hex"));else{if("string"==typeof a)a=new Buffer(a);else if(!(a instanceof Buffer))throw new Error("New password must be provided as a string or a Buffer");c=k.encrypt(b.secret,a),d=l.encode(c),c=c.toString("base64")}return[c,d]})},p.prototype.passwordChange=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.fcall(function(){return c.doPasswordChange(a).then(function(a){var b=a[0],d=a[1];return c.sdk.updateWallet(c.identifier,{encrypted_secret:b}).then(function(){return c.encryptedSecret=b,{encryptedSecret:d}})}).then(function(a){d.resolve(a)},function(a){d.reject(a)})}),d.promise},p.prototype.getAddressByPath=function(a){return this.getWalletScriptByPath(a).address},p.prototype.getRedeemScriptByPath=function(a){return this.getWalletScriptByPath(a).redeemScript},p.prototype.getWalletScriptByPath=function(a){var b,c,d=this,e=d.getPrimaryPublicKey(a),f=d.getBlocktrailPublicKey(a),h=p.deriveByPath(d.backupPublicKey,a.replace("'",""),"M"),i=p.sortMultiSigKeys([e.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),f.keyPair.getPublicKeyBuffer()]),j=g.script.multisig.output.encode(2,i),k=parseInt(a.split("/")[2]);"bitcoincash"!==this.network&&k===p.CHAIN_BTC_SEGWIT?(b=j,c=g.script.witnessScriptHash.output.encode(g.crypto.sha256(b))):(b=null,c=j);var l=g.script.scriptHash.output.encode(g.crypto.hash160(c)),m=g.address.fromOutputScript(l,this.network);return{witnessScript:b,redeemScript:c,scriptPubKey:l,address:m}},p.prototype.getPrimaryPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.primaryPublicKeys[c]){if(!b.primaryPrivateKey)throw new i.KeyPathError("Wallet.getPrimaryPublicKey keyIndex ("+c+") is unknown to us");b.primaryPublicKeys[c]=p.deriveByPath(b.primaryPrivateKey,"M/"+c+"'","m")}var d=b.primaryPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.getBlocktrailPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.blocktrailPublicKeys[c])throw new i.KeyPathError("Wallet.getBlocktrailPublicKey keyIndex ("+c+") is unknown to us");var d=b.blocktrailPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.upgradeKeyIndex=function(a,b){var d=this,f=e.defer();if(f.promise.nodeify(b),d.locked)return f.reject(new i.WalletLockedError("Wallet needs to be unlocked to upgrade key index")),f.promise;var h=d.primaryPrivateKey.deriveHardened(a).neutered();return f.resolve(d.sdk.upgradeKeyIndex(d.identifier,a,[h.toBase58(),"M/"+a+"'"]).then(function(b){return d.keyIndex=a,c.forEach(b.blocktrail_public_keys,function(a,b){d.blocktrailPublicKeys[b]=g.HDNode.fromBase58(a[0],d.network)}),d.primaryPublicKeys[a]=h,!0})),f.promise},p.prototype.getNewAddress=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getNewDerivation(b.identifier,"M/"+b.keyIndex+"'/"+b.chain).then(function(a){var c=a.path,d=a.address;if(!b.bypassNewAddressCheck&&(d=b.getAddressByPath(a.path),d!==a.address))throw new i.WalletAddressError("Failed to verify address ["+a.address+"] !== ["+d+"]");return[d,c]})),c.promise},p.prototype.getBalance=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier).then(function(a){return[a.confirmed,a.unconfirmed]})),c.promise},p.prototype.getInfo=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier)),c.promise},p.prototype.doDiscovery=function(a,b){var c=this;"function"==typeof a&&(b=a,a=null);var d=e.defer();return d.promise.spreadNodeify(b),d.resolve(c.sdk.doWalletDiscovery(c.identifier,a).then(function(a){return[a.confirmed,a.unconfirmed]})),d.promise},p.prototype.deleteWallet=function(a,b){var c=this;"function"==typeof a&&(b=a,a=!1);var d=e.defer();if(d.promise.nodeify(b),c.locked)return d.reject(new i.WalletDeleteError("Wallet needs to be unlocked to delete wallet")),d.promise;var f=c.primaryPrivateKey.getAddress(),g=c.primaryPrivateKey.keyPair.d.toBuffer(32),j=h.sign(f,c.network.messagePrefix,g,!0).toString("base64");return d.resolve(c.sdk.deleteWallet(c.identifier,f,j,a).then(function(a){return a.deleted})),d.promise},p.prototype.pay=function(a,b,c,d,f,g,h,j){var k=this;"function"==typeof b?(j=b,b=null):"function"==typeof c?(j=c,c=!1):"function"==typeof d?(j=d,d=!0):"function"==typeof f?(j=f,f=null):"function"==typeof g?(j=g,g=null):"function"==typeof h&&(j=h,h={}),d="undefined"==typeof d||d,f=f||p.FEE_STRATEGY_OPTIMAL,h=h||{};var l="undefined"==typeof h.checkFee||h.checkFee,m=e.defer();return m.promise.nodeify(j),k.locked?(m.reject(new i.WalletLockedError("Wallet needs to be unlocked to send coins")),m.promise):(e.nextTick(function(){m.notify(p.PAY_PROGRESS_START),k.buildTransaction(a,b,c,d,f,h).then(function(a){return a},function(a){m.reject(a)},function(a){m.notify(a)}).spread(function(a,b){m.notify(p.PAY_PROGRESS_SEND);var c={signed_transaction:a.toHex(),base_transaction:a.__toBuffer(null,null,!1).toString("hex")};return k.sendTransaction(c,b.map(function(a){return a.path}),l,g,h.prioboost).then(function(a){return m.notify(p.PAY_PROGRESS_DONE),a&&a.complete&&"false"!==a.complete?a.txid:void m.reject(new i.TransactionSignError("Failed to completely sign transaction"))})},function(a){throw a}).then(function(a){m.resolve(a)},function(a){m.reject(a)})}),m.promise)},p.prototype.decodeAddress=function(a){return p.getAddressAndType(a,this.network)},p.getAddressAndType=function(a,b){var c,d,e;if(b===g.networks.bitcoin||b===g.networks.testnet){try{c=g.address.fromBech32(a,b),e=null,d="bech32"}catch(a){e=a}if(!e&&c.prefix!==b.bech32)throw new i.InvalidAddressError("Address invalid on this network")}if(!c){try{c=g.address.fromBase58Check(a),e=null,d="base58"}catch(a){e=a}if(!e&&c.version!==b.pubKeyHash&&c.version!==b.scriptHash)throw new i.InvalidAddressError("Address invalid on this network")}if(e)throw new i.InvalidAddressError(e.message);return{address:a,decoded:c,type:d}},p.convertPayToOutputs=function(a,b){var c,d=[];if(Array.isArray(a))c=function(a,b,c){if("object"!=typeof b)throw new Error("Invalid transaction output for numerically indexed list [1]");var d=Object.keys(b);if(d.indexOf("scriptPubKey")!==-1&&d.indexOf("value")!==-1)c.scriptPubKey=b.scriptPubKey,c.value=b.value;else if(d.indexOf("address")!==-1&&d.indexOf("value")!==-1)c.address=b.address,c.value=b.value;else{if(2===d.length||2===b.length||0===d[0]||1===d[1])throw new Error("Invalid transaction output for numerically indexed list [2]");c.address=b[0],c.value=b[1]}};else{if("object"!=typeof a)throw new Error("Invalid input");c=function(a,b,c){if(c.address=a.trim(),c.value=b,c.address===p.OP_RETURN){var d=Buffer.isBuffer(b)?b:new Buffer(b,"utf-8");c.scriptPubKey=g.script.nullData.output.encode(d).toString("hex"),c.value=0,c.address=null}}}return Object.keys(a).forEach(function(e){var f={};if(c(e,a[e],f),parseInt(f.value,10).toString()!==f.value.toString())throw new i.WalletSendError("Values should be in Satoshis");if("string"==typeof f.address)try{var h=p.getAddressAndType(f.address,b);f.scriptPubKey=g.address.toOutputScript(h.address,b).toString("hex"),delete f.address}catch(a){throw new i.InvalidAddressError("Invalid address ["+f.address+"] ("+a.message+")")}if("6a"!==f.scriptPubKey.slice(0,2)){if(!(f.value=parseInt(f.value,10)))throw new i.WalletSendError("Values should be non zero");if(f.value<=i.DUST)throw new i.WalletSendError("Values should be more than dust ("+i.DUST+")")}f.value=parseInt(f.value,10),d.push(f)}),d},p.prototype.buildTransaction=function(a,b,d,h,j,k,l){var m=this;"function"==typeof b?(l=b,b=null):"function"==typeof d?(l=d,d=!1):"function"==typeof h?(l=h,h=!0):"function"==typeof j?(l=j,j=null):"function"==typeof k&&(l=k,k={}),h="undefined"==typeof h||h,j=j||p.FEE_STRATEGY_OPTIMAL,k=k||{};var n=e.defer();return n.promise.spreadNodeify(l),e.nextTick(function(){var l;try{l=p.convertPayToOutputs(a,m.network)}catch(a){return n.reject(a),n.promise}return l.length?(n.notify(p.PAY_PROGRESS_COIN_SELECTION),void n.resolve(m.coinSelection(l,!0,d,j,k).spread(function(a,d,k){var n,q,r=[],s=e.defer();return f.waterfall([function(b){var c=a.map(function(a){return a.value}).reduce(function(a,b){return a+b}),e=l.map(function(a){return a.value}).reduce(function(a,b){return a+b}),f=c-e-d;return f>2*i.DUST&&f!==k?b(new i.WalletFeeError("the amount of change ("+k+") suggested by the coin selection seems incorrect ("+f+")")):void b()},function(a){q=new g.TransactionBuilder(m.network),m.bitcoinCash&&q.enableBitcoinCash(),a()},function(b){var c;for(c=0;c<a.length;c++)q.addInput(a[c].hash,a[c].idx);b()},function(a){l.forEach(function(a){if(a.address)r.push({address:a.address,value:a.value});else{if(!a.scriptPubKey)throw new Error("Invalid send");r.push({scriptPubKey:new Buffer(a.scriptPubKey,"hex"),value:a.value})}}),a()},function(a){if(k>0)if(k<=i.DUST)k=0;else if(!b)return s.notify(p.PAY_PROGRESS_CHANGE_ADDRESS),m.getNewAddress(function(c,d){return c?a(c):(b=d,void a())});a()},function(a){k>0&&(h?r.splice(c.random(0,r.length),0,{address:b,value:k}):r.push({address:b,value:k})),a()},function(a){r.forEach(function(a){q.addOutput(a.scriptPubKey||a.address,a.value)}),a()},function(b){var c,d,e,f,h;for(s.notify(p.PAY_PROGRESS_SIGN),c=0;c<a.length;c++){var i=o.SIGN;if(a[c].sign_mode&&(i=a[c].sign_mode),f=null,h=null,i===o.SIGN){if(e=a[c].path.replace("M","m"),m.primaryPrivateKey)d=p.deriveByPath(m.primaryPrivateKey,e,"m").keyPair;else{if(!m.backupPrivateKey)throw new Error("No master privateKey present");d=p.deriveByPath(m.backupPrivateKey,e.replace(/^m\/(\d+)\'/,"m/$1"),"m").keyPair}f=new Buffer(a[c].redeem_script,"hex"),"string"==typeof a[c].witness_script&&(h=new Buffer(a[c].witness_script,"hex"));var j=g.Transaction.SIGHASH_ALL;
3
m.bitcoinCash&&(j|=g.Transaction.SIGHASH_BITCOINCASHBIP143),q.sign(c,d,f,j,a[c].value,h)}}n=q.buildIncomplete(),b()},function(b){var c=p.estimateVsizeFee(n,a);if(m.sdk.feeSanityCheck)switch(j){case p.FEE_STRATEGY_BASE_FEE:if(Math.abs(c-d)>i.BASE_FEE)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems incorrect ("+c+") for FEE_STRATEGY_BASE_FEE"));break;case p.FEE_STRATEGY_OPTIMAL:if(d>c*m.feeSanityCheckBaseFeeMultiplier)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems awefully high ("+c+") for FEE_STRATEGY_OPTIMAL"))}b()}],function(b){return b?void s.reject(new i.WalletSendError(b)):void s.resolve([n,a])}),s.promise}))):(n.reject(new i.WalletSendError("Need at least one recipient")),n.promise)}),n.promise},p.prototype.coinSelection=function(a,b,c,d,f,g){var h=this;"function"==typeof b?(g=b,b=!0):"function"==typeof c?(g=c,c=!1):"function"==typeof d?(g=d,d=null):"function"==typeof f&&(g=f,f={}),b="undefined"==typeof b||b,d=d||p.FEE_STRATEGY_OPTIMAL,f=f||{};var i;try{i=p.convertPayToOutputs(a,h.network)}catch(a){var j=e.defer();return j.promise.nodeify(g),j.reject(a),j.promise}return h.sdk.coinSelection(h.identifier,i,b,c,d,f,g)},p.prototype.sendTransaction=function(a,b,c,d,f,g){var h=this;"function"==typeof d?(g=d,d=null,f=!1):"function"==typeof f&&(g=d,f=!1);var j=e.defer();return j.promise.nodeify(g),h.sdk.sendTransaction(h.identifier,a,b,c,d,f).then(function(a){j.resolve(a)},function(a){a.requires_2fa?j.reject(new i.WalletMissing2FAError):a.message.match(/Invalid two_factor_token/)?j.reject(new i.WalletInvalid2FAError):j.reject(a)}),j.promise},p.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),b=b||"WALLET-"+d.identifier,d.sdk.setupWalletWebhook(d.identifier,b,a,c)},p.prototype.deleteWebhook=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),a=a||"WALLET-"+c.identifier,c.sdk.deleteWalletWebhook(c.identifier,a,b)},p.prototype.transactions=function(a,b){var c=this;return c.sdk.walletTransactions(c.identifier,a,b)},p.prototype.maxSpendable=function(a,b,c,d){var e=this;return"function"==typeof a?(d=a,a=!1):"function"==typeof b?(d=b,b=null):"function"==typeof c&&(d=c,c={}),"object"==typeof a?(c=a,a=!1):"object"==typeof b&&(c=b,b=null),c=c||{},"undefined"!=typeof c.allowZeroConf&&(a=c.allowZeroConf),"undefined"!=typeof c.feeStrategy&&(b=c.feeStrategy),b=b||p.FEE_STRATEGY_OPTIMAL,e.sdk.walletMaxSpendable(e.identifier,a,b,c,d)},p.prototype.addresses=function(a,b){var c=this;return c.sdk.walletAddresses(c.identifier,a,b)},p.prototype.labelAddress=function(a,b,c){var d=this;return d.sdk.labelWalletAddress(d.identifier,a,b,c)},p.prototype.utxos=function(a,b){var c=this;return c.sdk.walletUTXOs(c.identifier,a,b)},p.prototype.unspentOutputs=p.prototype.utxos,p.sortMultiSigKeys=function(a){return a.sort(function(a,b){return a.toString("hex").localeCompare(b.toString("hex"))}),a},p.estimateIncompleteTxFee=function(a,b){var c=p.estimateIncompleteTxSize(a),d=c/1e3,e=Math.ceil(c/1e3);return b?parseInt(d*b,10):parseInt(e*i.BASE_FEE,10)},p.estimateVsizeFee=function(a,b,c){var d=m.estimateTxVsize(a,b),e=d/1e3,f=Math.ceil(d/1e3);return c?parseInt(e*c,10):parseInt(f*i.BASE_FEE,10)},p.estimateIncompleteTxSize=function(a){var b=16;return b+=34*a.outs.length,a.ins.forEach(function(a){var c=a.script,d=g.script.classifyInput(c),e=[2,3];if(!e&&"scripthash"===d){var f=g.script.decompile(c),h=f.slice(-1)[0];if(c=g.script.compile(f.slice(0,-1)),d=g.script.classifyInput(c),g.script.classifyOutput(h)!==d)throw new i.TransactionInputError("Non-matching scriptSig and scriptPubKey in input");if("multisig"===d){var j=g.script.decompile(h),k=j[0];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var l=j[h.chunks.length-2];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var m=k-(g.opcodes.OP_1-1),n=l-(g.opcodes.OP_1-1);if(n<m)throw new i.TransactionInputError("Invalid multisig redeemScript");e=[m,n]}}b+=e?40+73*e[0]+107+4:147}),b},p.estimateFee=function(a,b){var c=16;c+=34*b,c+=297*a;var d=Math.ceil(c/1e3);return d*i.BASE_FEE},p.deriveByPath=function(a,b,c){if(c=c||(a.keyPair.d?"m":"M"),"m"!==b[0].toLowerCase()||"m"!==c[0].toLowerCase())throw new i.KeyPathError("Wallet.deriveByPath only works with absolute paths. ("+b+", "+c+")");if("m"===b[0]&&"M"===c[0])throw new i.KeyPathError("Wallet.deriveByPath can't derive private path from public parent. ("+b+", "+c+")");var d="M"===b[0]&&"m"===c[0];if(d&&(b[0]="m"),0!==b.toLowerCase().indexOf(c.toLowerCase()))throw new i.KeyPathError("Wallet.derivePath requires path ("+b+") to be a child of keyPath ("+c+")");b=b.substr(c.length);var e=a;return b.replace(/^\//,"").split("/").forEach(function(a){a&&(a.indexOf("'")!==-1&&(a=parseInt(a.replace("'",""),10)+g.HDNode.HIGHEST_BIT),e=e.derive(parseInt(a,10)))}),d?e.neutered():e},b.exports=p}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./size_estimation":12,assert:20,async:21,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293}],16:[function(a,b,c){(function(Buffer){var c=a("./unspent_output_finder"),d=a("bitcoinjs-lib"),e=a("bip39"),f=a("crypto-js"),g=a("./blocktrail"),h=a("./encryption_mnemonic"),i=a("./encryption"),j=a("./wallet"),k=a("lodash"),l=a("q"),m=a("async"),n=function(a,b,j){var l=this;this.defaultSettings={network:"btc",testnet:!1,logging:!1,bitcoinCash:!1,sweepBatchSize:200},this.settings=k.merge({},this.defaultSettings,j),this.bitcoinDataClient=b,this.utxoFinder=new c(b,this.settings),this.sweepData=null,"object"==typeof j.network?this.network=j.network:this.network=this.getBitcoinNetwork(this.settings.network,this.settings.testnet),a.walletVersion=a.walletVersion||2;var m=!1;if(!Array.isArray(a.blocktrailKeys))throw new Error("blocktrail pub keys are required (must be type Array)");switch(a.walletVersion){case 1:if("undefined"==typeof a.primaryMnemonic||!a.primaryMnemonic)throw new Error("missing primary mnemonic for version 1 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic)throw new Error("missing backup mnemonic for version 1 wallet");if("undefined"==typeof a.primaryPassphrase)throw new Error("missing primary passphrase for version 1 wallet");a.primaryMnemonic=a.primaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=a.backupMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;case 2:case 3:if("undefined"==typeof a.encryptedPrimaryMnemonic||!a.encryptedPrimaryMnemonic)throw new Error("missing encrypted primary seed for version 2 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic&&a.backupMnemonic!==!1)throw new Error("missing backup seed for version 2 wallet");if(m="undefined"!=typeof a.password&&null!==a.password){if("undefined"==typeof a.passwordEncryptedSecretMnemonic||!a.passwordEncryptedSecretMnemonic)throw new Error("missing password encrypted secret for version 2 wallet");if("undefined"==typeof a.password)throw new Error("missing primary passphrase for version 2 wallet")}else{if("undefined"==typeof a.encryptedRecoverySecretMnemonic||!a.encryptedRecoverySecretMnemonic)throw new Error("missing encrypted recovery secret for version 2 wallet (recovery without password)");if(!a.recoverySecretDecryptionKey)throw new Error("missing recovery secret decryption key for version 2 wallet (recovery without password)")}a.encryptedPrimaryMnemonic=a.encryptedPrimaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=(a.backupMnemonic||"").trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.recoverySecretDecryptionKey&&(a.recoverySecretDecryptionKey=a.recoverySecretDecryptionKey.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ")),m?a.passwordEncryptedSecretMnemonic=a.passwordEncryptedSecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "):a.encryptedRecoverySecretMnemonic=a.encryptedRecoverySecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.blocktrailPublicKeys={},k.each(a.blocktrailKeys,function(a){l.blocktrailPublicKeys[a.keyIndex]=d.HDNode.fromBase58(a.pubkey,l.network)});var n,o,p;switch(a.walletVersion){case 1:n=e.mnemonicToSeed(a.primaryMnemonic,a.primaryPassphrase),o=e.mnemonicToSeed(a.backupMnemonic,"");break;case 2:if(a.encryptedPrimaryMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedPrimaryMnemonic),"hex","base64"),m?a.passwordEncryptedSecretMnemonic=g.convert(e.mnemonicToEntropy(a.passwordEncryptedSecretMnemonic),"hex","base64"):a.encryptedRecoverySecretMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedRecoverySecretMnemonic),"hex","base64"),p=m?f.AES.decrypt(a.passwordEncryptedSecretMnemonic,a.password).toString(f.enc.Utf8):f.AES.decrypt(a.encryptedRecoverySecretMnemonic,a.recoverySecretDecryptionKey).toString(f.enc.Utf8),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=new Buffer(f.AES.decrypt(a.encryptedPrimaryMnemonic,p).toString(f.enc.Utf8),"base64"),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;case 3:if(a.encryptedPrimaryMnemonic=h.decode(a.encryptedPrimaryMnemonic),m?a.passwordEncryptedSecretMnemonic=h.decode(a.passwordEncryptedSecretMnemonic):a.encryptedRecoverySecretMnemonic=h.decode(a.encryptedRecoverySecretMnemonic),p=m?i.decrypt(a.passwordEncryptedSecretMnemonic,new Buffer(a.password)):i.decrypt(a.encryptedRecoverySecretMnemonic,new Buffer(a.recoverySecretDecryptionKey,"hex")),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=i.decrypt(a.encryptedPrimaryMnemonic,p),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.primaryPrivateKey=d.HDNode.fromSeedBuffer(n,this.network),o?(this.backupPrivateKey=d.HDNode.fromSeedBuffer(o,this.network),this.backupPublicKey=this.backupPrivateKey.neutered()):(this.backupPrivateKey=!1,this.backupPublicKey=d.HDNode.fromBase58(a.backupPublicKey,this.network)),this.settings.logging&&(console.log("using password method: "+m),console.log("Primary Prv Key: "+this.primaryPrivateKey.toBase58()),console.log("Primary Pub Key: "+this.primaryPrivateKey.neutered().toBase58()),console.log("Backup Prv Key: "+(this.backupPrivateKey?this.backupPrivateKey.toBase58():null)),console.log("Backup Pub Key: "+this.backupPublicKey.toBase58()))};n.prototype.getBitcoinNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?d.networks.testnet:d.networks.bitcoin;case"tbtc":case"bitcoin-testnet":return d.networks.testnet;default:throw new Error("Unknown network "+a)}},n.prototype.getBlocktrailPublicKey=function(a){a=a.replace("m","M");var b=a.split("/")[1].replace("'","");if(!this.blocktrailPublicKeys[b])throw new Error("Wallet.getBlocktrailPublicKey keyIndex ("+b+") is unknown to us");return this.blocktrailPublicKeys[b]},n.prototype.createAddress=function(a){a=a.replace("m","M");var b,c,e=a.split("/")[1].replace("'",""),f=parseInt(a.split("/")[2]),g=j.deriveByPath(this.primaryPrivateKey,a,"m"),h=j.deriveByPath(this.backupPublicKey,a.replace("'",""),"M"),i=j.deriveByPath(this.getBlocktrailPublicKey(a),a,"M/"+e+"'"),k=j.sortMultiSigKeys([g.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),i.keyPair.getPublicKeyBuffer()]),l=d.script.multisig.output.encode(2,k);"bitcoincash"!==this.network&&f===j.CHAIN_BTC_SEGWIT?(c=l,b=d.script.witnessScriptHash.output.encode(d.crypto.sha256(c))):(c=null,b=l);var m=d.crypto.hash160(b),n=d.script.scriptHash.output.encode(m),o=this.network;"undefined"!=typeof this.network&&(o=this.network);var p=d.address.fromOutputScript(n,o);return{address:p.toString(),redeem:b,witness:c}},n.prototype.createBatchAddresses=function(a,b,c,d){var e=this,f={};return l.all(k.range(0,b).map(function(b){var g="M/"+c+"'/"+d+"/"+(a+b),h=e.createAddress(g);f[h.address]={redeem:h.redeem,witness:h.witness,path:g}})).then(function(){return f})},n.prototype.discoverWalletFunds=function(a,b){var c=this,d=0,e=0,f=0,g={};"undefined"==typeof a&&(a=this.settings.sweepBatchSize);var h=l.defer();h.promise.nodeify(b);var i;return i="bitcoincash"===this.network?[0,1]:[0,1,2],m.nextTick(function(){m.eachSeries(Object.keys(c.blocktrailPublicKeys),function(b,j){m.eachSeries(i,function(i,j){var n=0,o=!1;m.doWhilst(function(j){c.settings.logging&&console.log("generating addresses "+n+" -> "+(n+a)+" using blocktrail key index: "+b+", chain: "+i),h.notify({message:"generating addresses "+n+" -> "+(n+a),increment:a,btPubKeyIndex:b,chain:i,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),m.nextTick(function(){c.createBatchAddresses(n,a,b,i).then(function(i){return f+=Object.keys(i).length,c.settings.logging&&console.log("starting fund discovery for "+a+" addresses..."),h.notify({message:"starting fund discovery for "+a+" addresses",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),c.bitcoinDataClient.batchAddressHasTransactions(k.keys(i)).then(function(j){return o=j,c.settings.logging&&console.log("batch "+(o?"has":"does not have")+" transactions..."),l.when(o).then(function(j){if(j)return c.utxoFinder.getUTXOs(k.keys(i)).then(function(j){k.each(j,function(a,b){var f=null;"undefined"!=typeof i[b].witness&&(f=i[b].witness),g[b]={path:i[b].path,redeem:i[b].redeem,witness:f,utxos:a},e+=a.length,d=k.reduce(a,function(a,b){return a+b.value},d),c.settings.logging&&console.log("found "+a.length+" unspent outputs for address: "+b)}),h.notify({message:"discovering funds",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})})})})}).then(function(){n+=a,m.nextTick(j)},function(a){j(a)})})},function(){return o},function(c){c&&(console.log("batch complete, but with errors",c.message),h.notify({message:"batch complete, but with errors: "+c.message,error:c,increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})),m.nextTick(j)})},function(a){j(a)})},function(a){a&&c.settings.logging&&console.log("error encountered when discovering funds",a),c.settings.logging&&console.log("finished fund discovery: "+d+" Satoshi (in "+e+" outputs) found when searching "+f+" addresses"),c.sweepData={utxos:g,count:e,balance:d,addressesSearched:f},h.resolve(c.sweepData)})}),h.promise},n.prototype.sweepWallet=function(a,b){var c=this,d=l.defer();return d.promise.nodeify(b),c.settings.logging&&console.log("starting wallet sweeping to address "+a),l.when(!0).then(function(){if(!c.sweepData)return c.discoverWalletFunds().progress(function(a){d.notify(a)})}).then(function(){return c.bitcoinDataClient.estimateFee()}).then(function(b){return 0===c.sweepData.balance?(d.reject("No funds found after searching through "+c.sweepData.addressesSearched+" addresses"),d.promise):c.createTransaction(a,null,b,d)}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},n.prototype.createTransaction=function(a,b,c,e){var f=this;this.settings.logging&&console.log("Creating transaction to address destinationAddress"),e&&e.notify({message:"creating raw transaction to "+a});var h=new d.TransactionBuilder(this.network);this.settings.bitcoinCash&&h.enableBitcoinCash();var i=[];if(k.each(this.sweepData.utxos,function(a,b){k.each(a.utxos,function(c){h.addInput(c.hash,c.index),i.push({txid:c.hash,vout:c.index,scriptPubKey:c.script_hex,value:c.value,address:b,path:a.path,redeemScript:a.redeem,witnessScript:a.witness})})}),!h)throw new Error("Failed to create raw transaction");var l=f.sweepData.balance,m=h.addOutput(a,l);if("undefined"==typeof b||null===b){e&&e.notify({message:"estimating transaction fee, based on "+g.toBTC(c)+" BTC/kb"});var n=i.map(function(a){return{txid:a.txid,vout:a.vout,address:a.vout,scriptpubkey_hex:a.vout,redeem_script:a.redeemScript,witness_script:a.witnessScript,path:a.path,value:a.value}});b=j.estimateVsizeFee(h.tx,n,c)}return h.tx.outs[m].value-=b,e&&e.notify({message:"signing transaction"}),this.signTransaction(h,i)},n.prototype.signTransaction=function(a,b){var c=this;this.settings.logging&&console.log("Signing transaction");var e=d.Transaction.SIGHASH_ALL;return this.settings.bitcoinCash&&(e|=d.Transaction.SIGHASH_BITCOINCASHBIP143),k.each(b,function(b,d){var f=j.deriveByPath(c.primaryPrivateKey,b.path.replace("M","m"),"m").keyPair;if(a.sign(d,f,b.redeemScript,e,b.value,b.witnessScript),c.backupPrivateKey){var g=j.deriveByPath(c.backupPrivateKey,b.path.replace("'","").replace("M","m"),"m").keyPair;a.sign(d,g,b.redeemScript,e,b.value,b.witnessScript)}}),c.backupPrivateKey?a.build().toHex():a.buildIncomplete().toHex()},b.exports=n}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./unspent_output_finder":13,"./wallet":15,async:21,bip39:28,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,lodash:249,q:293}],17:[function(a,b,c){(function(Buffer){var c=a("bip39"),d=a("./encryption");b.exports=function(a){a.addEventListener("message",function(b){var e=b.data||{};switch(e.method){case"mnemonicToSeedHex":!function(){try{var d=e.mnemonic,f=e.passphrase;if(!c.validateMnemonic(d))throw b=new Error("Invalid passphrase"),b.id=e.id,b;var g=c.mnemonicToSeedHex(d,f);a.postMessage({id:e.id,seed:g,mnemonic:d})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.encryptWithSaltAndIV":!function(){try{if(!(e.pt&&e.pw&&e.saltBuf&&e.iv&&e.iterations))throw new Error("Invalid input");var b=Buffer.from(e.pt.buffer),c=Buffer.from(e.pw.buffer),f=Buffer.from(e.saltBuf.buffer),g=Buffer.from(e.iv.buffer),h=e.iterations,i=d.encryptWithSaltAndIV(b,c,f,g,h);a.postMessage({id:e.id,cipherText:i})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.decrypt":!function(){try{if(!e.ct||!e.pw)throw new Error("Invalid input");var b=Buffer.from(e.ct.buffer),c=Buffer.from(e.pw.buffer),f=d.decrypt(b,c);a.postMessage({id:e.id,plainText:f})}catch(a){throw a.id=e.id,a}}();break;default:throw b=new Error("Invalid method ["+b.method+"]"),b.id=e.id,b}},!1)}}).call(this,a("buffer").Buffer)},{"./encryption":3,bip39:28,buffer:105}],18:[function(a,b,c){var d=a("q"),e=a("webworkify");b.exports=c={workify:function(a,b,c){var f=d.defer();try{"undefined"==typeof a.worker&&(a.worker=e(b()),a.first=!0,a.id=0);var g=a.worker,h=a.id++,i=function(b){a.first&&(a.first=!1,URL.revokeObjectURL(g.objectURL)),b.data.id===h&&f.resolve(b.data)},j=function(a){f.reject(new Error(a.message.replace("Uncaught Error: ","")))},k=function(){g.removeEventListener("message",i),g.removeEventListener("error",j)};return g.addEventListener("message",i,!1),g.addEventListener("error",j,!1),c.id=h,g.postMessage(c),f.promise.then(function(a){return k(),a},function(a){throw k(),a})}catch(a){return f.reject(a),f.promise}}}},{q:293,webworkify:363}],19:[function(a,b,c){(function(Buffer){var d=a("./lib/api_client"),e=a("./lib/blocktrail");Object.keys(e).forEach(function(a){d[a]=e[a]}),d.q=a("q"),d.BlocktrailSDK=d,d.Wallet=a("./lib/wallet"),d.Request=a("./lib/request"),d.Encryption=a("./lib/encryption"),d.KeyDerivation=a("./lib/keyderivation"),d.EncryptionMnemonic=a("./lib/encryption_mnemonic"),d.useWebworker=a("./lib/use-webworker"),d.WalletSweeper=a("./lib/wallet_sweeper"),d.UnspentOutputFinder=a("./lib/unspent_output_finder"),d.BlocktrailBitcoinService=a("./lib/services/blocktrail_bitcoin_service"),d.InsightBitcoinService=a("./lib/services/insight_bitcoin_service"),d.randomBytes=a("randombytes"),d.lodash=a("lodash"),d.CryptoJS=a("crypto-js"),d.debug=a("debug"),d.bip39=a("bip39"),d.bip39wordlist=a("bip39/wordlists/en.json"),d.bitcoin=a("bitcoinjs-lib"),d.superagent=a("superagent"),d.Buffer=Buffer,d.VERSION=a("./lib/pkginfo").VERSION,c=b.exports=d}).call(this,a("buffer").Buffer)},{"./lib/api_client":1,"./lib/blocktrail":2,"./lib/encryption":3,"./lib/encryption_mnemonic":4,"./lib/keyderivation":5,"./lib/pkginfo":7,"./lib/request":8,"./lib/services/blocktrail_bitcoin_service":10,"./lib/services/insight_bitcoin_service":11,"./lib/unspent_output_finder":13,"./lib/use-webworker":14,"./lib/wallet":15,"./lib/wallet_sweeper":16,bip39:28,"bip39/wordlists/en.json":31,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,debug:211,lodash:249,q:293,randombytes:297,superagent:349}],20:[function(a,b,c){(function(c){"use strict";function d(a,b){if(a===b)return 0;for(var c=a.length,d=b.length,e=0,f=Math.min(c,d);e<f;++e)if(a[e]!==b[e]){c=a[e],d=b[e];break}return c<d?-1:d<c?1:0}function e(a){return c.Buffer&&"function"==typeof c.Buffer.isBuffer?c.Buffer.isBuffer(a):!(null==a||!a._isBuffer)}function f(a){return Object.prototype.toString.call(a)}function g(a){return!e(a)&&("function"==typeof c.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(a):!!a&&(a instanceof DataView||!!(a.buffer&&a.buffer instanceof ArrayBuffer))))}function h(a){if(u.isFunction(a)){if(x)return a.name;var b=a.toString(),c=b.match(z);return c&&c[1]}}function i(a,b){return"string"==typeof a?a.length<b?a:a.slice(0,b):a}function j(a){if(x||!u.isFunction(a))return u.inspect(a);var b=h(a),c=b?": "+b:"";return"[Function"+c+"]"}function k(a){return i(j(a.actual),128)+" "+a.operator+" "+i(j(a.expected),128)}function l(a,b,c,d,e){throw new y.AssertionError({message:c,actual:a,expected:b,operator:d,stackStartFunction:e})}function m(a,b){a||l(a,!0,b,"==",y.ok)}function n(a,b,c,h){if(a===b)return!0;if(e(a)&&e(b))return 0===d(a,b);if(u.isDate(a)&&u.isDate(b))return a.getTime()===b.getTime();if(u.isRegExp(a)&&u.isRegExp(b))return a.source===b.source&&a.global===b.global&&a.multiline===b.multiline&&a.lastIndex===b.lastIndex&&a.ignoreCase===b.ignoreCase;if(null!==a&&"object"==typeof a||null!==b&&"object"==typeof b){if(g(a)&&g(b)&&f(a)===f(b)&&!(a instanceof Float32Array||a instanceof Float64Array))return 0===d(new Uint8Array(a.buffer),new Uint8Array(b.buffer));if(e(a)!==e(b))return!1;h=h||{actual:[],expected:[]};var i=h.actual.indexOf(a);return i!==-1&&i===h.expected.indexOf(b)||(h.actual.push(a),h.expected.push(b),p(a,b,c,h))}return c?a===b:a==b}function o(a){return"[object Arguments]"==Object.prototype.toString.call(a)}function p(a,b,c,d){if(null===a||void 0===a||null===b||void 0===b)return!1;if(u.isPrimitive(a)||u.isPrimitive(b))return a===b;if(c&&Object.getPrototypeOf(a)!==Object.getPrototypeOf(b))return!1;var e=o(a),f=o(b);if(e&&!f||!e&&f)return!1;if(e)return a=w.call(a),b=w.call(b),n(a,b,c);var g,h,i=A(a),j=A(b);if(i.length!==j.length)return!1;for(i.sort(),j.sort(),h=i.length-1;h>=0;h--)if(i[h]!==j[h])return!1;for(h=i.length-1;h>=0;h--)if(g=i[h],!n(a[g],b[g],c,d))return!1;return!0}function q(a,b,c){n(a,b,!0)&&l(a,b,c,"notDeepStrictEqual",q)}function r(a,b){if(!a||!b)return!1;if("[object RegExp]"==Object.prototype.toString.call(b))return b.test(a);try{if(a instanceof b)return!0}catch(a){}return!Error.isPrototypeOf(b)&&b.call({},a)===!0}function s(a){var b;try{a()}catch(a){b=a}return b}function t(a,b,c,d){var e;if("function"!=typeof b)throw new TypeError('"block" argument must be a function');"string"==typeof c&&(d=c,c=null),e=s(b),d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&l(e,c,"Missing expected exception"+d);var f="string"==typeof d,g=!a&&u.isError(e),h=!a&&e&&!c;if((g&&f&&r(e,c)||h)&&l(e,c,"Got unwanted exception"+d),a&&e&&c&&!r(e,c)||!a&&e)throw e}var u=a("util/"),v=Object.prototype.hasOwnProperty,w=Array.prototype.slice,x=function(){return"foo"===function(){}.name}(),y=b.exports=m,z=/\s*function\s+([^\(\s]*)\s*/;y.AssertionError=function(a){this.name="AssertionError",this.actual=a.actual,this.expected=a.expected,this.operator=a.operator,a.message?(this.message=a.message,this.generatedMessage=!1):(this.message=k(this),this.generatedMessage=!0);var b=a.stackStartFunction||l;if(Error.captureStackTrace)Error.captureStackTrace(this,b);else{var c=new Error;if(c.stack){var d=c.stack,e=h(b),f=d.indexOf("\n"+e);if(f>=0){var g=d.indexOf("\n",f+1);d=d.substring(g+1)}this.stack=d}}},u.inherits(y.AssertionError,Error),y.fail=l,y.ok=m,y.equal=function(a,b,c){a!=b&&l(a,b,c,"==",y.equal)},y.notEqual=function(a,b,c){a==b&&l(a,b,c,"!=",y.notEqual)},y.deepEqual=function(a,b,c){n(a,b,!1)||l(a,b,c,"deepEqual",y.deepEqual)},y.deepStrictEqual=function(a,b,c){n(a,b,!0)||l(a,b,c,"deepStrictEqual",y.deepStrictEqual)},y.notDeepEqual=function(a,b,c){n(a,b,!1)&&l(a,b,c,"notDeepEqual",y.notDeepEqual)},y.notDeepStrictEqual=q,y.strictEqual=function(a,b,c){a!==b&&l(a,b,c,"===",y.strictEqual)},y.notStrictEqual=function(a,b,c){a===b&&l(a,b,c,"!==",y.notStrictEqual)},y.throws=function(a,b,c){t(!0,a,b,c)},y.doesNotThrow=function(a,b,c){t(!1,a,b,c)},y.ifError=function(a){if(a)throw a};var A=Object.keys||function(a){var b=[];for(var c in a)v.call(a,c)&&b.push(c);return b}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"util/":360}],21:[function(a,b,c){(function(a){!function(){function c(a){var b=!1;return function(){if(b)throw new Error("Callback was already called.");b=!0,a.apply(d,arguments)}}var d,e,f={};d=this,null!=d&&(e=d.async),f.noConflict=function(){return d.async=e,f};var g=Object.prototype.toString,h=Array.isArray||function(a){return"[object Array]"===g.call(a)},i=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)},j=function(a,b){if(a.map)return a.map(b);var c=[];return i(a,function(a,d,e){c.push(b(a,d,e))}),c},k=function(a,b,c){return a.reduce?a.reduce(b,c):(i(a,function(a,d,e){c=b(c,a,d,e)}),c)},l=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};"undefined"!=typeof a&&a.nextTick?(f.nextTick=a.nextTick,"undefined"!=typeof setImmediate?f.setImmediate=function(a){setImmediate(a)}:f.setImmediate=f.nextTick):"function"==typeof setImmediate?(f.nextTick=function(a){setImmediate(a)},f.setImmediate=f.nextTick):(f.nextTick=function(a){setTimeout(a,0)},f.setImmediate=f.nextTick),f.each=function(a,b,d){function e(b){b?(d(b),d=function(){}):(f+=1,f>=a.length&&d())}if(d=d||function(){},!a.length)return d();var f=0;i(a,function(a){b(a,c(e))})},f.forEach=f.each,f.eachSeries=function(a,b,c){if(c=c||function(){},!a.length)return c();var d=0,e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d>=a.length?c():e())})};e()},f.forEachSeries=f.eachSeries,f.eachLimit=function(a,b,c,d){var e=m(b);e.apply(null,[a,c,d])},f.forEachLimit=f.eachLimit;var m=function(a){return function(b,c,d){if(d=d||function(){},!b.length||a<=0)return d();var e=0,f=0,g=0;!function h(){if(e>=b.length)return d();for(;g<a&&f<b.length;)f+=1,g+=1,c(b[f-1],function(a){a?(d(a),d=function(){}):(e+=1,g-=1,e>=b.length?d():h())})}()}},n=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.each].concat(b))}},o=function(a,b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[m(a)].concat(c))}},p=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.eachSeries].concat(b))}},q=function(a,b,c,d){if(b=j(b,function(a,b){return{index:b,value:a}}),d){var e=[];a(b,function(a,b){c(a.value,function(c,d){e[a.index]=d,b(c)})},function(a){d(a,e)})}else a(b,function(a,b){c(a.value,function(a){b(a)})})};f.map=n(q),f.mapSeries=p(q),f.mapLimit=function(a,b,c,d){return r(b)(a,c,d)};var r=function(a){return o(a,q)};f.reduce=function(a,b,c,d){f.eachSeries(a,function(a,d){c(b,a,function(a,c){b=c,d(a)})},function(a){d(a,b)})},f.inject=f.reduce,f.foldl=f.reduce,f.reduceRight=function(a,b,c,d){var e=j(a,function(a){return a}).reverse();f.reduce(e,b,c,d)},f.foldr=f.reduceRight;var s=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.filter=n(s),f.filterSeries=p(s),f.select=f.filter,f.selectSeries=f.filterSeries;var t=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.reject=n(t),f.rejectSeries=p(t);var u=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?(d(a),d=function(){}):b()})},function(a){d()})};f.detect=n(u),f.detectSeries=p(u),f.some=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a&&(c(!0),c=function(){}),d()})},function(a){c(!1)})},f.any=f.some,f.every=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a||(c(!1),c=function(){}),d()})},function(a){c(!0)})},f.all=f.every,f.sortBy=function(a,b,c){f.map(a,function(a,c){b(a,function(b,d){b?c(b):c(null,{value:a,criteria:d})})},function(a,b){if(a)return c(a);var d=function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0};c(null,j(b.sort(d),function(a){return a.value}))})},f.auto=function(a,b){b=b||function(){};var c=l(a),d=c.length;if(!d)return b();var e={},g=[],j=function(a){g.unshift(a)},m=function(a){for(var b=0;b<g.length;b+=1)if(g[b]===a)return void g.splice(b,1)},n=function(){d--,i(g.slice(0),function(a){a()})};j(function(){if(!d){var a=b;b=function(){},a(null,e)}}),i(c,function(c){var d=h(a[c])?a[c]:[a[c]],g=function(a){var d=Array.prototype.slice.call(arguments,1);if(d.length<=1&&(d=d[0]),a){var g={};i(l(e),function(a){g[a]=e[a]}),g[c]=d,b(a,g),b=function(){}}else e[c]=d,f.setImmediate(n)},o=d.slice(0,Math.abs(d.length-1))||[],p=function(){return k(o,function(a,b){return a&&e.hasOwnProperty(b)},!0)&&!e.hasOwnProperty(c)};if(p())d[d.length-1](g,e);else{var q=function(){p()&&(m(q),d[d.length-1](g,e))};j(q)}})},f.retry=function(a,b,c){var d=5,e=[];"function"==typeof a&&(c=b,b=a,a=d),a=parseInt(a,10)||d;var g=function(d,g){for(var h=function(a,b){return function(c){a(function(a,d){c(!a||b,{err:a,result:d})},g)}};a;)e.push(h(b,!(a-=1)));f.series(e,function(a,b){b=b[b.length-1],(d||c)(b.err,b.result)})};return c?g():g},f.waterfall=function(a,b){if(b=b||function(){},!h(a)){var c=new Error("First argument to waterfall must be an array of functions");return b(c)}if(!a.length)return b();var d=function(a){return function(c){if(c)b.apply(null,arguments),b=function(){};else{var e=Array.prototype.slice.call(arguments,1),g=a.next();g?e.push(d(g)):e.push(b),f.setImmediate(function(){a.apply(null,e)})}}};d(f.iterator(a))()};var v=function(a,b,c){if(c=c||function(){},h(b))a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},c);else{var d={};a.each(l(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}};f.parallel=function(a,b){v({map:f.map,each:f.each},a,b)},f.parallelLimit=function(a,b,c){v({map:r(b),each:m(b)},a,c)},f.series=function(a,b){if(b=b||function(){},h(a))f.mapSeries(a,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},b);else{var c={};f.eachSeries(l(a),function(b,d){a[b](function(a){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),c[b]=e,d(a)})},function(a){b(a,c)})}},f.iterator=function(a){var b=function(c){var d=function(){return a.length&&a[c].apply(null,arguments),d.next()};return d.next=function(){return c<a.length-1?b(c+1):null},d};return b(0)},f.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var w=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};f.concat=n(w),
4
f.concatSeries=p(w),f.whilst=function(a,b,c){a()?b(function(d){return d?c(d):void f.whilst(a,b,c)}):c()},f.doWhilst=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?f.doWhilst(a,b,c):c()})},f.until=function(a,b,c){a()?c():b(function(d){return d?c(d):void f.until(a,b,c)})},f.doUntil=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?c():f.doUntil(a,b,c)})},f.queue=function(a,b){function d(a,b,c,d){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var e={data:b,callback:"function"==typeof d?d:null};c?a.tasks.unshift(e):a.tasks.push(e),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}void 0===b&&(b=1);var e=0,g={tasks:[],concurrency:b,saturated:null,empty:null,drain:null,started:!1,paused:!1,push:function(a,b){d(g,a,!1,b)},kill:function(){g.drain=null,g.tasks=[]},unshift:function(a,b){d(g,a,!0,b)},process:function(){if(!g.paused&&e<g.concurrency&&g.tasks.length){var b=g.tasks.shift();g.empty&&0===g.tasks.length&&g.empty(),e+=1;var d=function(){e-=1,b.callback&&b.callback.apply(b,arguments),g.drain&&g.tasks.length+e===0&&g.drain(),g.process()},f=c(d);a(b.data,f)}},length:function(){return g.tasks.length},running:function(){return e},idle:function(){return g.tasks.length+e===0},pause:function(){g.paused!==!0&&(g.paused=!0,g.process())},resume:function(){g.paused!==!1&&(g.paused=!1,g.process())}};return g},f.priorityQueue=function(a,b){function c(a,b){return a.priority-b.priority}function d(a,b,c){for(var d=-1,e=a.length-1;d<e;){var f=d+(e-d+1>>>1);c(b,a[f])>=0?d=f:e=f-1}return d}function e(a,b,e,g){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var h={data:b,priority:e,callback:"function"==typeof g?g:null};a.tasks.splice(d(a.tasks,h,c)+1,0,h),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}var g=f.queue(a,b);return g.push=function(a,b,c){e(g,a,b,c)},delete g.unshift,g},f.cargo=function(a,b){var c=!1,d=[],e={tasks:d,payload:b,saturated:null,empty:null,drain:null,drained:!0,push:function(a,c){h(a)||(a=[a]),i(a,function(a){d.push({data:a,callback:"function"==typeof c?c:null}),e.drained=!1,e.saturated&&d.length===b&&e.saturated()}),f.setImmediate(e.process)},process:function f(){if(!c){if(0===d.length)return e.drain&&!e.drained&&e.drain(),void(e.drained=!0);var g="number"==typeof b?d.splice(0,b):d.splice(0,d.length),h=j(g,function(a){return a.data});e.empty&&e.empty(),c=!0,a(h,function(){c=!1;var a=arguments;i(g,function(b){b.callback&&b.callback.apply(null,a)}),f()})}},length:function(){return d.length},running:function(){return c}};return e};var x=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(b?console.error&&console.error(b):console[a]&&i(c,function(b){console[a](b)}))}]))}};f.log=x("log"),f.dir=x("dir"),f.memoize=function(a,b){var c={},d={};b=b||function(a){return a};var e=function(){var e=Array.prototype.slice.call(arguments),g=e.pop(),h=b.apply(null,e);h in c?f.nextTick(function(){g.apply(null,c[h])}):h in d?d[h].push(g):(d[h]=[g],a.apply(null,e.concat([function(){c[h]=arguments;var a=d[h];delete d[h];for(var b=0,e=a.length;b<e;b++)a[b].apply(null,arguments)}])))};return e.memo=c,e.unmemoized=a,e},f.unmemoize=function(a){return function(){return(a.unmemoized||a).apply(null,arguments)}},f.times=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.map(d,b,c)},f.timesSeries=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.mapSeries(d,b,c)},f.seq=function(){var a=arguments;return function(){var b=this,c=Array.prototype.slice.call(arguments),d=c.pop();f.reduce(a,c,function(a,c,d){c.apply(b,a.concat([function(){var a=arguments[0],b=Array.prototype.slice.call(arguments,1);d(a,b)}]))},function(a,c){d.apply(b,[a].concat(c))})}},f.compose=function(){return f.seq.apply(null,Array.prototype.reverse.call(arguments))};var y=function(a,b){var c=function(){var c=this,d=Array.prototype.slice.call(arguments),e=d.pop();return a(b,function(a,b){a.apply(c,d.concat([b]))},e)};if(arguments.length>2){var d=Array.prototype.slice.call(arguments,2);return c.apply(this,d)}return c};f.applyEach=n(y),f.applyEachSeries=p(y),f.forever=function(a,b){function c(d){if(d){if(b)return b(d);throw d}a(c)}c()},"undefined"!=typeof b&&b.exports?b.exports=f:"undefined"!=typeof define&&define.amd?define([],function(){return f}):d.async=f}()}).call(this,a("_process"))},{_process:263}],22:[function(a,b,c){var Buffer=a("safe-buffer").Buffer;b.exports=function(a){function b(b){if(0===b.length)return"";for(var c=[0],d=0;d<b.length;++d){for(var e=0,g=b[d];e<c.length;++e)g+=c[e]<<8,c[e]=g%f,g=g/f|0;for(;g>0;)c.push(g%f),g=g/f|0}for(var h="",i=0;0===b[i]&&i<b.length-1;++i)h+=a[0];for(var j=c.length-1;j>=0;--j)h+=a[c[j]];return h}function c(a){if(0===a.length)return Buffer.allocUnsafe(0);for(var b=[0],c=0;c<a.length;c++){var d=e[a[c]];if(void 0===d)return;for(var h=0,i=d;h<b.length;++h)i+=b[h]*f,b[h]=255&i,i>>=8;for(;i>0;)b.push(255&i),i>>=8}for(var j=0;a[j]===g&&j<a.length-1;++j)b.push(0);return Buffer.from(b.reverse())}function d(a){var b=c(a);if(b)return b;throw new Error("Non-base"+f+" character")}for(var e={},f=a.length,g=a.charAt(0),h=0;h<a.length;h++){var i=a.charAt(h);if(void 0!==e[i])throw new TypeError(i+" is ambiguous");e[i]=h}return{encode:b,decodeUnsafe:c,decode:d}}},{"safe-buffer":311}],23:[function(a,b,c){"use strict";function d(a){var b=a>>25;return(33554431&a)<<5^996825010&-(b>>0&1)^642813549&-(b>>1&1)^513874426&-(b>>2&1)^1027748829&-(b>>3&1)^705979059&-(b>>4&1)}function e(a){for(var b=1,c=0;c<a.length;++c){var e=a.charCodeAt(c);if(e<33||e>126)throw new Error("Invalid prefix ("+a+")");b=d(b)^e>>5}b=d(b);for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);b=d(b)^31&g}return b}function f(a,b){if(a.length+7+b.length>90)throw new TypeError("Exceeds Bech32 maximum length");a=a.toLowerCase();for(var c=e(a),f=a+"1",g=0;g<b.length;++g){var h=b[g];if(h>>5!==0)throw new Error("Non 5-bit word");c=d(c)^h,f+=k.charAt(h)}for(var i=0;i<6;++i)c=d(c);c^=1;for(var j=0;j<6;++j){var l=c>>5*(5-j)&31;f+=k.charAt(l)}return f}function g(a){if(a.length<8)throw new TypeError(a+" too short");if(a.length>90)throw new TypeError(a+" too long");var b=a.toLowerCase(),c=a.toUpperCase();if(a!==b&&a!==c)throw new Error("Mixed-case string "+a);a=b;var f=a.lastIndexOf("1");if(0===f)throw new Error("Missing prefix for "+a);var g=a.slice(0,f),h=a.slice(f+1);if(h.length<6)throw new Error("Data too short");for(var i=e(g),j=[],k=0;k<h.length;++k){var m=h.charAt(k),n=l[m];if(void 0===n)throw new Error("Unknown character "+m);i=d(i)^n,k+6>=h.length||j.push(n)}if(1!==i)throw new Error("Invalid checksum for "+a);return{prefix:g,words:j}}function h(a,b,c,d){for(var e=0,f=0,g=(1<<c)-1,h=[],i=0;i<a.length;++i)for(e=e<<b|a[i],f+=b;f>=c;)f-=c,h.push(e>>f&g);if(d)f>0&&h.push(e<<c-f&g);else{if(f>=b)throw new Error("Excess padding");if(e<<c-f&g)throw new Error("Non-zero padding")}return h}function i(a){return h(a,8,5,!0)}function j(a){return h(a,5,8,!1)}for(var k="qpzry9x8gf2tvdw0s3jn54khce6mua7l",l={},m=0;m<k.length;m++){var n=k.charAt(m);if(void 0!==l[n])throw new TypeError(n+" is ambiguous");l[n]=m}b.exports={decode:g,encode:f,toWords:i,fromWords:j}},{}],24:[function(a,b,c){function BigInteger(a,b,c){return this instanceof BigInteger?void(null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))):new BigInteger(a,b,c)}function d(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function e(a){return eb.charAt(a)}function f(a,b){var c=fb[a.charCodeAt(b)];return null==c?-1:c}function g(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function h(a){this.t=1,this.s=a<0?-1:0,a>0?this[0]=a:a<-1?this[0]=a+ab:this.t=0}function i(a){var b=new BigInteger;return b.fromInt(a),b}function j(a,b){var c,d=this;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void d.fromRadix(a,b);c=2}d.t=0,d.s=0;for(var e=a.length,g=!1,h=0;--e>=0;){var i=8==c?255&a[e]:f(a,e);i<0?"-"==a.charAt(e)&&(g=!0):(g=!1,0==h?d[d.t++]=i:h+c>d.DB?(d[d.t-1]|=(i&(1<<d.DB-h)-1)<<h,d[d.t++]=i>>d.DB-h):d[d.t-1]|=i<<h,h+=c,h>=d.DB&&(h-=d.DB))}8==c&&0!=(128&a[0])&&(d.s=-1,h>0&&(d[d.t-1]|=(1<<d.DB-h)-1<<h)),d.clamp(),g&&BigInteger.ZERO.subTo(d,d)}function k(){for(var a=this.s&this.DM;this.t>0&&this[this.t-1]==a;)--this.t}function l(a){var b=this;if(b.s<0)return"-"+b.negate().toString(a);var c;if(16==a)c=4;else if(8==a)c=3;else if(2==a)c=1;else if(32==a)c=5;else{if(4!=a)return b.toRadix(a);c=2}var d,f=(1<<c)-1,g=!1,h="",i=b.t,j=b.DB-i*b.DB%c;if(i-- >0)for(j<b.DB&&(d=b[i]>>j)>0&&(g=!0,h=e(d));i>=0;)j<c?(d=(b[i]&(1<<j)-1)<<c-j,d|=b[--i]>>(j+=b.DB-c)):(d=b[i]>>(j-=c)&f,j<=0&&(j+=b.DB,--i)),d>0&&(g=!0),g&&(h+=e(d));return g?h:"0"}function m(){var a=new BigInteger;return BigInteger.ZERO.subTo(this,a),a}function n(){return this.s<0?this.negate():this}function o(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function p(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function q(){return this.t<=0?0:this.DB*(this.t-1)+p(this[this.t-1]^this.s&this.DM)}function r(){return this.bitLength()>>3}function s(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function t(a,b){for(var c=a;c<this.t;++c)b[c-a]=this[c];b.t=Math.max(this.t-a,0),b.s=this.s}function u(a,b){var c,d=this,e=a%d.DB,f=d.DB-e,g=(1<<f)-1,h=Math.floor(a/d.DB),i=d.s<<e&d.DM;for(c=d.t-1;c>=0;--c)b[c+h+1]=d[c]>>f|i,i=(d[c]&g)<<e;for(c=h-1;c>=0;--c)b[c]=0;b[h]=i,b.t=d.t+h+1,b.s=d.s,b.clamp()}function v(a,b){var c=this;b.s=c.s;var d=Math.floor(a/c.DB);if(d>=c.t)return void(b.t=0);var e=a%c.DB,f=c.DB-e,g=(1<<e)-1;b[0]=c[d]>>e;for(var h=d+1;h<c.t;++h)b[h-d-1]|=(c[h]&g)<<f,b[h-d]=c[h]>>e;e>0&&(b[c.t-d-1]|=(c.s&g)<<f),b.t=c.t-d,b.clamp()}function w(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]-a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e-=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e-=a[d],b[d++]=e&c.DM,e>>=c.DB;e-=a.s}b.s=e<0?-1:0,e<-1?b[d++]=c.DV+e:e>0&&(b[d++]=e),b.t=d,b.clamp()}function x(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e<d.t;++e)b[e+c.t]=c.am(0,d[e],b,e,0,c.t);b.s=0,b.clamp(),this.s!=a.s&&BigInteger.ZERO.subTo(b,b)}function y(a){for(var b=this.abs(),c=a.t=2*b.t;--c>=0;)a[c]=0;for(c=0;c<b.t-1;++c){var d=b.am(c,b[c],a,2*c,0,1);(a[c+b.t]+=b.am(c+1,2*b[c],a,2*c+1,d,b.t-c-1))>=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function z(a,b,c){var d=this,e=a.abs();if(!(e.t<=0)){var f=d.abs();if(f.t<e.t)return null!=b&&b.fromInt(0),void(null!=c&&d.copyTo(c));null==c&&(c=new BigInteger);var g=new BigInteger,h=d.s,i=a.s,j=d.DB-p(e[e.t-1]);j>0?(e.lShiftTo(j,g),f.lShiftTo(j,c)):(e.copyTo(g),f.copyTo(c));var k=g.t,l=g[k-1];if(0!=l){var m=l*(1<<d.F1)+(k>1?g[k-2]>>d.F2:0),n=d.FV/m,o=(1<<d.F1)/m,q=1<<d.F2,r=c.t,s=r-k,t=null==b?new BigInteger:b;for(g.dlShiftTo(s,t),c.compareTo(t)>=0&&(c[c.t++]=1,c.subTo(t,c)),BigInteger.ONE.dlShiftTo(k,t),t.subTo(g,g);g.t<k;)g[g.t++]=0;for(;--s>=0;){var u=c[--r]==l?d.DM:Math.floor(c[r]*n+(c[r-1]+q)*o);if((c[r]+=g.am(0,u,c,s,0,k))<u)for(g.dlShiftTo(s,t),c.subTo(t,c);c[r]<--u;)c.subTo(t,c)}null!=b&&(c.drShiftTo(k,b),h!=i&&BigInteger.ZERO.subTo(b,b)),c.t=k,c.clamp(),j>0&&c.rShiftTo(j,c),h<0&&BigInteger.ZERO.subTo(c,c)}}}function A(a){var b=new BigInteger;return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b),b}function B(a){this.m=a}function C(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function D(a){return a}function E(a){a.divRemTo(this.m,null,a)}function F(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function G(a,b){a.squareTo(b),this.reduce(b)}function H(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function I(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<a.DB-15)-1,this.mt2=2*a.t}function J(a){var b=new BigInteger;return a.abs().dlShiftTo(this.m.t,b),b.divRemTo(this.m,null,b),a.s<0&&b.compareTo(BigInteger.ZERO)>0&&this.m.subTo(b,b),b}function K(a){var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function L(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b<this.m.t;++b){var c=32767&a[b],d=c*this.mpl+((c*this.mph+(a[b]>>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function M(a,b){a.squareTo(b),this.reduce(b)}function N(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function O(){return 0==(this.t>0?1&this[0]:this.s)}function P(a,b){if(a>4294967295||a<1)return BigInteger.ONE;var c=new BigInteger,d=new BigInteger,e=b.convert(this),f=p(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<<f)>0)b.mulTo(d,e,c);else{var g=c;c=d,d=g}return b.revert(c)}function Q(a,b){var c;return c=a<256||b.isEven()?new B(b):new I(b),this.exp(a,c)}function R(){var a=new BigInteger;return this.copyTo(a),a}function S(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function T(){return 0==this.t?this.s:this[0]<<24>>24}function U(){return 0==this.t?this.s:this[0]<<16>>16}function V(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function W(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function X(a){if(null==a&&(a=10),0==this.signum()||a<2||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=i(c),e=new BigInteger,f=new BigInteger,g="";for(this.divRemTo(d,e,f);e.signum()>0;)g=(c+f.intValue()).toString(a).substr(1)+g,e.divRemTo(d,e,f);return f.intValue().toString(a)+g}function Y(a,b){var c=this;c.fromInt(0),null==b&&(b=10);for(var d=c.chunkSize(b),e=Math.pow(b,d),g=!1,h=0,i=0,j=0;j<a.length;++j){var k=f(a,j);k<0?"-"==a.charAt(j)&&0==c.signum()&&(g=!0):(i=b*i+k,++h>=d&&(c.dMultiply(e),c.dAddOffset(i,0),h=0,i=0))}h>0&&(c.dMultiply(Math.pow(b,h)),c.dAddOffset(i,0)),g&&BigInteger.ZERO.subTo(c,c)}function Z(a,b,c){var d=this;if("number"==typeof b)if(a<2)d.fromInt(1);else for(d.fromNumber(a,c),d.testBit(a-1)||d.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),fa,d),d.isEven()&&d.dAddOffset(1,0);!d.isProbablePrime(b);)d.dAddOffset(2,0),d.bitLength()>a&&d.subTo(BigInteger.ONE.shiftLeft(a-1),d);else{var e=new Array,f=7&a;e.length=(a>>3)+1,b.nextBytes(e),f>0?e[0]&=(1<<f)-1:e[0]=0,d.fromString(e,256)}}function $(){var a=this,b=a.t,c=new Array;c[0]=a.s;var d,e=a.DB-b*a.DB%8,f=0;if(b-- >0)for(e<a.DB&&(d=a[b]>>e)!=(a.s&a.DM)>>e&&(c[f++]=d|a.s<<a.DB-e);b>=0;)e<8?(d=(a[b]&(1<<e)-1)<<8-e,d|=a[--b]>>(e+=a.DB-8)):(d=a[b]>>(e-=8)&255,e<=0&&(e+=a.DB,--b)),0!=(128&d)&&(d|=-256),0===f&&(128&a.s)!=(128&d)&&++f,(f>0||d!=a.s)&&(c[f++]=d);return c}function _(a){return 0==this.compareTo(a)}function aa(a){return this.compareTo(a)<0?this:a}function ba(a){return this.compareTo(a)>0?this:a}function ca(a,b,c){var d,e,f=this,g=Math.min(a.t,f.t);for(d=0;d<g;++d)c[d]=b(f[d],a[d]);if(a.t<f.t){for(e=a.s&f.DM,d=g;d<f.t;++d)c[d]=b(f[d],e);c.t=f.t}else{for(e=f.s&f.DM,d=g;d<a.t;++d)c[d]=b(e,a[d]);c.t=a.t}c.s=b(f.s,a.s),c.clamp()}function da(a,b){return a&b}function ea(a){var b=new BigInteger;return this.bitwiseTo(a,da,b),b}function fa(a,b){return a|b}function ga(a){var b=new BigInteger;return this.bitwiseTo(a,fa,b),b}function ha(a,b){return a^b}function ia(a){var b=new BigInteger;return this.bitwiseTo(a,ha,b),b}function ja(a,b){return a&~b}function ka(a){var b=new BigInteger;return this.bitwiseTo(a,ja,b),b}function la(){for(var a=new BigInteger,b=0;b<this.t;++b)a[b]=this.DM&~this[b];return a.t=this.t,a.s=~this.s,a}function ma(a){var b=new BigInteger;return a<0?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function na(a){var b=new BigInteger;return a<0?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function oa(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function pa(){for(var a=0;a<this.t;++a)if(0!=this[a])return a*this.DB+oa(this[a]);return this.s<0?this.t*this.DB:-1}function qa(a){for(var b=0;0!=a;)a&=a-1,++b;return b}function ra(){for(var a=0,b=this.s&this.DM,c=0;c<this.t;++c)a+=qa(this[c]^b);return a}function sa(a){var b=Math.floor(a/this.DB);return b>=this.t?0!=this.s:0!=(this[b]&1<<a%this.DB)}function ta(a,b){var c=BigInteger.ONE.shiftLeft(a);return this.bitwiseTo(c,b,c),c}function ua(a){return this.changeBit(a,fa)}function va(a){return this.changeBit(a,ja)}function wa(a){return this.changeBit(a,ha)}function xa(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]+a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e+=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e+=a[d],b[d++]=e&c.DM,e>>=c.DB;e+=a.s}b.s=e<0?-1:0,e>0?b[d++]=e:e<-1&&(b[d++]=c.DV+e),b.t=d,b.clamp()}function ya(a){var b=new BigInteger;return this.addTo(a,b),b}function za(a){var b=new BigInteger;return this.subTo(a,b),b}function Aa(a){var b=new BigInteger;return this.multiplyTo(a,b),b}function Ba(){var a=new BigInteger;return this.squareTo(a),a}function Ca(a){var b=new BigInteger;return this.divRemTo(a,b,null),b}function Da(a){var b=new BigInteger;return this.divRemTo(a,null,b),b}function Ea(a){var b=new BigInteger,c=new BigInteger;return this.divRemTo(a,b,c),new Array(b,c)}function Fa(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function Ga(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function Ha(){}function Ia(a){return a}function Ja(a,b,c){a.multiplyTo(b,c)}function Ka(a,b){a.squareTo(b)}function La(a){return this.exp(a,new Ha)}function Ma(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;d<e;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);d<e;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function Na(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d<a.t;++d)c[this.t+d-b]=this.am(b-d,a[d],c,0,0,this.t+d-b);c.clamp(),c.drShiftTo(1,c)}function Oa(a){this.r2=new BigInteger,this.q3=new BigInteger,BigInteger.ONE.dlShiftTo(2*a.t,this.r2),this.mu=this.r2.divide(a),this.m=a}function Pa(a){if(a.s<0||a.t>2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function Qa(a){return a}function Ra(a){var b=this;for(a.drShiftTo(b.m.t-1,b.r2),a.t>b.m.t+1&&(a.t=b.m.t+1,a.clamp()),b.mu.multiplyUpperTo(b.r2,b.m.t+1,b.q3),b.m.multiplyLowerTo(b.q3,b.m.t+1,b.r2);a.compareTo(b.r2)<0;)a.dAddOffset(1,b.m.t+1);for(a.subTo(b.r2,a);a.compareTo(b.m)>=0;)a.subTo(b.m,a)}function Sa(a,b){a.squareTo(b),this.reduce(b)}function Ta(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function Ua(a,b){var c,d,e=a.bitLength(),f=i(1);if(e<=0)return f;c=e<18?1:e<48?3:e<144?4:e<768?5:6,d=e<8?new B(b):b.isEven()?new Oa(b):new I(b);var g=new Array,h=3,j=c-1,k=(1<<c)-1;if(g[1]=d.convert(this),c>1){var l=new BigInteger;for(d.sqrTo(g[1],l);h<=k;)g[h]=new BigInteger,d.mulTo(l,g[h-2],g[h]),h+=2}var m,n,o=a.t-1,q=!0,r=new BigInteger;for(e=p(a[o])-1;o>=0;){for(e>=j?m=a[o]>>e-j&k:(m=(a[o]&(1<<e+1)-1)<<j-e,o>0&&(m|=a[o-1]>>this.DB+e-j)),h=c;0==(1&m);)m>>=1,--h;if((e-=h)<0&&(e+=this.DB,--o),q)g[m].copyTo(f),q=!1;else{for(;h>1;)d.sqrTo(f,r),d.sqrTo(r,f),h-=2;h>0?d.sqrTo(f,r):(n=f,f=r,r=n),d.mulTo(r,g[m],f)}for(;o>=0&&0==(a[o]&1<<e);)d.sqrTo(f,r),n=f,f=r,r=n,--e<0&&(e=this.DB-1,--o)}return d.revert(f)}function Va(a){var b=this.s<0?this.negate():this.clone(),c=a.s<0?a.negate():a.clone();if(b.compareTo(c)<0){var d=b;b=c,c=d}var e=b.getLowestSetBit(),f=c.getLowestSetBit();if(f<0)return b;for(e<f&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function Wa(a){if(a<=0)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function Xa(a){var b=a.isEven();if(0===this.signum())throw new Error("division by zero");if(this.isEven()&&b||0==a.signum())return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=i(1),f=i(0),g=i(0),h=i(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(e.isEven()&&f.isEven()||(e.addTo(this,e),f.subTo(a,f)),e.rShiftTo(1,e)):f.isEven()||f.subTo(a,f),f.rShiftTo(1,f);for(;d.isEven();)d.rShiftTo(1,d),b?(g.isEven()&&h.isEven()||(g.addTo(this,g),h.subTo(a,h)),g.rShiftTo(1,g)):h.isEven()||h.subTo(a,h),h.rShiftTo(1,h);c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(g,e),f.subTo(h,f)):(d.subTo(c,d),b&&g.subTo(e,g),h.subTo(f,h))}if(0!=d.compareTo(BigInteger.ONE))return BigInteger.ZERO;for(;h.compareTo(a)>=0;)h.subTo(a,h);for(;h.signum()<0;)h.addTo(a,h);return h}function Ya(a){var b,c=this.abs();if(1==c.t&&c[0]<=gb[gb.length-1]){for(b=0;b<gb.length;++b)if(c[0]==gb[b])return!0;return!1}if(c.isEven())return!1;for(b=1;b<gb.length;){for(var d=gb[b],e=b+1;e<gb.length&&d<hb;)d*=gb[e++];for(d=c.modInt(d);b<e;)if(d%gb[b++]==0)return!1}return c.millerRabin(a)}function Za(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(c<=0)return!1;var d=b.shiftRight(c);a=a+1>>1,a>gb.length&&(a=gb.length);for(var e,f=new BigInteger(null),g=[],h=0;h<a;++h){for(;e=gb[Math.floor(Math.random()*gb.length)],g.indexOf(e)!=-1;);g.push(e),f.fromInt(e);var i=f.modPow(d,this);if(0!=i.compareTo(BigInteger.ONE)&&0!=i.compareTo(b)){for(var e=1;e++<c&&0!=i.compareTo(b);)if(i=i.modPowInt(2,this),0==i.compareTo(BigInteger.ONE))return!1;if(0!=i.compareTo(b))return!1}}return!0}var $a=BigInteger.prototype;$a.__bigi=a("../package.json").version,BigInteger.isBigInteger=function(a,b){return a&&a.__bigi&&(!b||a.__bigi===$a.__bigi)};var _a;BigInteger.prototype.am=d,_a=26,BigInteger.prototype.DB=_a,BigInteger.prototype.DM=(1<<_a)-1;var ab=BigInteger.prototype.DV=1<<_a,bb=52;BigInteger.prototype.FV=Math.pow(2,bb),BigInteger.prototype.F1=bb-_a,BigInteger.prototype.F2=2*_a-bb;var cb,db,eb="0123456789abcdefghijklmnopqrstuvwxyz",fb=new Array;for(cb="0".charCodeAt(0),db=0;db<=9;++db)fb[cb++]=db;for(cb="a".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;for(cb="A".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;B.prototype.convert=C,B.prototype.revert=D,B.prototype.reduce=E,B.prototype.mulTo=F,B.prototype.sqrTo=G,I.prototype.convert=J,I.prototype.revert=K,I.prototype.reduce=L,I.prototype.mulTo=N,I.prototype.sqrTo=M,$a.copyTo=g,$a.fromInt=h,$a.fromString=j,$a.clamp=k,$a.dlShiftTo=s,$a.drShiftTo=t,$a.lShiftTo=u,$a.rShiftTo=v,$a.subTo=w,$a.multiplyTo=x,$a.squareTo=y,$a.divRemTo=z,$a.invDigit=H,$a.isEven=O,$a.exp=P,$a.toString=l,$a.negate=m,$a.abs=n,$a.compareTo=o,$a.bitLength=q,$a.byteLength=r,$a.mod=A,$a.modPowInt=Q,Ha.prototype.convert=Ia,Ha.prototype.revert=Ia,Ha.prototype.mulTo=Ja,Ha.prototype.sqrTo=Ka,Oa.prototype.convert=Pa,Oa.prototype.revert=Qa,Oa.prototype.reduce=Ra,Oa.prototype.mulTo=Ta,Oa.prototype.sqrTo=Sa;var gb=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],hb=(1<<26)/gb[gb.length-1];$a.chunkSize=V,$a.toRadix=X,$a.fromRadix=Y,$a.fromNumber=Z,$a.bitwiseTo=ca,$a.changeBit=ta,$a.addTo=xa,$a.dMultiply=Fa,$a.dAddOffset=Ga,$a.multiplyLowerTo=Ma,$a.multiplyUpperTo=Na,$a.modInt=Wa,$a.millerRabin=Za,$a.clone=R,$a.intValue=S,$a.byteValue=T,$a.shortValue=U,$a.signum=W,$a.toByteArray=$,$a.equals=_,$a.min=aa,$a.max=ba,$a.and=ea,$a.or=ga,$a.xor=ia,$a.andNot=ka,$a.not=la,$a.shiftLeft=ma,$a.shiftRight=na,$a.getLowestSetBit=pa,$a.bitCount=ra,$a.testBit=sa,$a.setBit=ua,$a.clearBit=va,$a.flipBit=wa,$a.add=ya,$a.subtract=za,$a.multiply=Aa,$a.divide=Ca,$a.remainder=Da,$a.divideAndRemainder=Ea,$a.modPow=Ua,$a.modInverse=Xa,$a.pow=La,$a.gcd=Va,$a.isProbablePrime=Ya,$a.square=Ba,BigInteger.ZERO=i(0),BigInteger.ONE=i(1),BigInteger.valueOf=i,b.exports=BigInteger},{"../package.json":27}],25:[function(a,b,c){(function(Buffer){var b=a("assert"),BigInteger=a("./bigi");BigInteger.fromByteArrayUnsigned=function(a){return new BigInteger(128&a[0]?[0].concat(a):a)},BigInteger.prototype.toByteArrayUnsigned=function(){var a=this.toByteArray();return 0===a[0]?a.slice(1):a},BigInteger.fromDERInteger=function(a){return new BigInteger(a)},BigInteger.prototype.toDERInteger=BigInteger.prototype.toByteArray,BigInteger.fromBuffer=function(a){if(128&a[0]){var b=Array.prototype.slice.call(a);return new BigInteger([0].concat(b))}return new BigInteger(a)},BigInteger.fromHex=function(a){return""===a?BigInteger.ZERO:(b.equal(a,a.match(/^[A-Fa-f0-9]+/),"Invalid hex string"),b.equal(a.length%2,0,"Incomplete hex"),new BigInteger(a,16))},BigInteger.prototype.toBuffer=function(a){for(var b=this.toByteArrayUnsigned(),c=[],d=a-b.length;c.length<d;)c.push(0);return new Buffer(c.concat(b))},BigInteger.prototype.toHex=function(a){return this.toBuffer(a).toString("hex")}}).call(this,a("buffer").Buffer)},{"./bigi":24,assert:20,buffer:105}],26:[function(a,b,c){var BigInteger=a("./bigi");a("./convert"),b.exports=BigInteger},{"./bigi":24,"./convert":25}],27:[function(a,b,c){b.exports={_args:[[{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib"]],_from:"bigi@>=1.4.0 <2.0.0",_id:"[email protected]",_inCache:!0,_location:"/bigi",_nodeVersion:"6.1.0",_npmOperationalInternal:{host:"packages-12-west.internal.npmjs.com",tmp:"tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"},_npmUser:{name:"jprichardson",email:"[email protected]"},_npmVersion:"3.8.6",_phantomChildren:{},_requested:{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},_requiredBy:["/bitcoinjs-lib","/ecurve"],_resolved:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",_shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",_shrinkwrap:null,_spec:"bigi@^1.4.0",_where:"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib",bugs:{url:"https://github.com/cryptocoinjs/bigi/issues"},dependencies:{},description:"Big integers.",devDependencies:{coveralls:"^2.11.2",istanbul:"^0.3.5",jshint:"^2.5.1",mocha:"^2.1.0",mochify:"^2.1.0"},directories:{},dist:{shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",tarball:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"},gitHead:"c25308081c896ff84702303722bf5ecd8b3f78e3",homepage:"https://github.com/cryptocoinjs/bigi#readme",keywords:["cryptography","math","bitcoin","arbitrary","precision","arithmetic","big","integer","int","number","biginteger","bigint","bignumber","decimal","float"],main:"./lib/index.js",maintainers:[{name:"midnightlightning",email:"[email protected]"},{name:"sidazhang",email:"[email protected]"},{name:"nadav",email:"[email protected]"},{name:"jprichardson",email:"[email protected]"}],name:"bigi",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{url:"git+https://github.com/cryptocoinjs/bigi.git",type:"git"},scripts:{"browser-test":"mochify --wd -R spec",coverage:"istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",coveralls:"npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",jshint:"jshint --config jshint.json lib/*.js ; true",test:"_mocha -- test/*.js",unit:"mocha"},testling:{files:"test/*.js",harness:"mocha",browsers:["ie/9..latest","firefox/latest","chrome/latest","safari/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},version:"1.4.2"}},{}],28:[function(a,b,c){(function(Buffer){var c=a("./lib/index"),d=a("./sjcl"),e=a("assert");e("function"==typeof d.hash.sha512);var f=function(a){var b=new d.misc.hmac(a,d.hash.sha512);this.encrypt=function(){return b.encrypt.apply(b,arguments)}};c.setPbkdf2(function(a,b,c,e,g){var h;switch(g){case"sha512":h=f;break;default:throw new Error("Digest ["+g+"] not implemented")}var i=d.misc.pbkdf2(d.codec.utf8String.toBits(a),d.codec.utf8String.toBits(b),c,8*e,h);return new Buffer(d.codec.hex.fromBits(i),"hex")}),b.exports={salt:c.salt,mnemonicToSeed:c.mnemonicToSeed,mnemonicToSeedHex:c.mnemonicToSeedHex,mnemonicToEntropy:c.mnemonicToEntropy,entropyToMnemonic:c.entropyToMnemonic,generateMnemonic:c.generateMnemonic,validateMnemonic:c.validateMnemonic}}).call(this,a("buffer").Buffer)},{"./lib/index":29,"./sjcl":30,assert:20,buffer:105}],29:[function(a,b,c){(function(Buffer){function c(a){n=a}function d(a,b){return n(a,k(b),2048,64,"sha512")}function e(a,b){return d(a,b).toString("hex")}function f(a,b){b=b||s;var c=a.split(" ");o(c.length%3===0,"Invalid mnemonic");var d=c.every(function(a){return b.indexOf(a)>-1});o(d,"Invalid mnemonic");var e=c.map(function(a){var c=b.indexOf(a);return m(c.toString(2),"0",11)}).join(""),f=32*Math.floor(e.length/33),g=e.slice(0,f),h=e.slice(f),i=g.match(/(.{1,8})/g).map(function(a){return parseInt(a,2)}),k=new Buffer(i),l=j(k);return o(l===h,"Invalid mnemonic checksum"),k.toString("hex")}function g(a,b){b=b||s;var c=new Buffer(a,"hex"),d=l([].slice.call(c)),e=j(c),f=d+e,g=f.match(/(.{1,11})/g),h=g.map(function(a){var c=parseInt(a,2);return b[c]});return h.join(" ")}function h(a,b,c){a=a||128,b=b||q;var d=b(a/8).toString("hex");return g(d,c)}function i(a,b){try{f(a,b)}catch(a){return!1}return!0}function j(a){var b=p("sha256").update(a).digest(),c=8*a.length,d=c/32;return l([].slice.call(b)).slice(0,d)}function k(a){return"mnemonic"+(r.nfkd(a)||"")}function l(a){return a.map(function(a){return m(a.toString(2),"0",8)}).join("")}function m(a,b,c){for(;a.length<c;)a=b+a;return a}var n,o=a("assert"),p=a("create-hash"),q=a("randombytes"),r=a("unorm"),s=a("../wordlists/en.json");b.exports={setPbkdf2:c,salt:k,mnemonicToSeed:d,mnemonicToSeedHex:e,mnemonicToEntropy:f,entropyToMnemonic:g,generateMnemonic:h,validateMnemonic:i}}).call(this,a("buffer").Buffer)},{"../wordlists/en.json":31,assert:20,buffer:105,"create-hash":128,randombytes:297,unorm:354}],30:[function(a,b,c){"use strict";function d(a){throw a}function e(a,b,c){4!==b.length&&d(new m.exception.invalid("invalid aes block size"));var e=a.b[c],f=b[0]^e[0],g=b[c?3:1]^e[1],h=b[2]^e[2];b=b[c?1:3]^e[3];var i,j,k,l,n=e.length/4-2,o=4,p=[0,0,0,0];i=a.o[c],a=i[0];var q=i[1],r=i[2],s=i[3],t=i[4];for(l=0;l<n;l++)i=a[f>>>24]^q[g>>16&255]^r[h>>8&255]^s[255&b]^e[o],j=a[g>>>24]^q[h>>16&255]^r[b>>8&255]^s[255&f]^e[o+1],k=a[h>>>24]^q[b>>16&255]^r[f>>8&255]^s[255&g]^e[o+2],b=a[b>>>24]^q[f>>16&255]^r[g>>8&255]^s[255&h]^e[o+3],o+=4,f=i,g=j,h=k;for(l=0;4>l;l++)p[c?3&-l:l]=t[f>>>24]<<24^t[g>>16&255]<<16^t[h>>8&255]<<8^t[255&b]^e[o++],i=f,f=g,g=h,h=b,b=i;return p}function f(a,b){var c,d=m.random.D[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}function g(a){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?m.random.addEntropy(window.performance.now(),a,"loadtime"):m.random.addEntropy((new Date).valueOf(),a,"loadtime");
5
}function h(a){a.b=i(a).concat(i(a)),a.F=new m.cipher.aes(a.b)}function i(a){for(var b=0;4>b&&(a.i[b]=a.i[b]+1|0,!a.i[b]);b++);return a.F.encrypt(a.i)}function j(a,b){return function(){b.apply(a,arguments)}}var k=void 0,l=!1,m={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message},this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message},this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message},this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message},this.message=a}}};"undefined"!=typeof b&&b.exports&&(b.exports=m),"function"==typeof define&&define([],function(){return m}),m.cipher.aes=function(a){this.o[0][0][0]||this.t();var b,c,e,f,g=this.o[0][4],h=this.o[1];b=a.length;var i=1;for(4!==b&&6!==b&&8!==b&&d(new m.exception.invalid("invalid aes key size")),this.b=[e=a.slice(0),f=[]],a=b;a<4*b+28;a++)c=e[a-1],(0===a%b||8===b&&4===a%b)&&(c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[255&c],0===a%b&&(c=c<<8^c>>>24^i<<24,i=i<<1^283*(i>>7))),e[a]=e[a-b]^c;for(b=0;a;b++,a--)c=e[3&b?a:a-4],f[b]=4>=a||4>b?c:h[0][g[c>>>24]]^h[1][g[c>>16&255]]^h[2][g[c>>8&255]]^h[3][g[255&c]]},m.cipher.aes.prototype={encrypt:function(a){return e(this,a,0)},decrypt:function(a){return e(this,a,1)},o:[[[],[],[],[],[]],[[],[],[],[],[]]],t:function(){var a,b,c,d,e,f,g,h=this.o[0],i=this.o[1],j=h[4],k=i[4],l=[],m=[];for(a=0;256>a;a++)m[(l[a]=a<<1^283*(a>>7))^a]=a;for(b=c=0;!j[b];b^=d||1,c=m[c]||1)for(f=c^c<<1^c<<2^c<<3^c<<4,f=f>>8^255&f^99,j[b]=f,k[f]=b,e=l[a=l[d=l[b]]],g=16843009*e^65537*a^257*d^16843008*b,e=257*l[f]^16843008*f,a=0;4>a;a++)h[a][b]=e=e<<24^e>>>8,i[a][f]=g=g<<24^g>>>8;for(a=0;5>a;a++)h[a]=h[a].slice(0),i[a]=i[a].slice(0)}},m.bitArray={bitSlice:function(a,b,c){return a=m.bitArray.R(a.slice(b/32),32-(31&b)).slice(1),c===k?a:m.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=m.bitArray.getPartial(c);return 32===d?a.concat(b):m.bitArray.R(b,d,0|c,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0===b?0:32*(b-1)+m.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;return b&=31,0<c&&b&&(a[c-1]=m.bitArray.partial(b,a[c-1]&2147483648>>b-1,1)),a},partial:function(a,b,c){return 32===a?b:(c?0|b:b<<32-a)+1099511627776*a},getPartial:function(a){return Math.round(a/1099511627776)||32},equal:function(a,b){if(m.bitArray.bitLength(a)!==m.bitArray.bitLength(b))return l;var c,d=0;for(c=0;c<a.length;c++)d|=a[c]^b[c];return 0===d},R:function(a,b,c,d){var e;for(e=0,d===k&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;return e=a.length?a[a.length-1]:0,a=m.bitArray.getPartial(e),d.push(m.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1)),d},j:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&65280|(65280&c)<<8|c<<24;return a}},m.codec.utf8String={fromBits:function(a){var b,c,d="",e=m.bitArray.bitLength(a);for(b=0;b<e/8;b++)0===(3&b)&&(c=a[b/4]),d+=String.fromCharCode(c>>>24),c<<=8;return decodeURIComponent(escape(d))},toBits:function(a){a=unescape(encodeURIComponent(a));var b,c=[],d=0;for(b=0;b<a.length;b++)d=d<<8|a.charCodeAt(b),3===(3&b)&&(c.push(d),d=0);return 3&b&&c.push(m.bitArray.partial(8*(3&b),d)),c}},m.codec.hex={fromBits:function(a){var b,c="";for(b=0;b<a.length;b++)c+=((0|a[b])+0xf00000000000).toString(16).substr(4);return c.substr(0,m.bitArray.bitLength(a)/4)},toBits:function(a){var b,c,d=[];for(a=a.replace(/\s|0x/g,""),c=a.length,a+="00000000",b=0;b<a.length;b+=8)d.push(0^parseInt(a.substr(b,8),16));return m.bitArray.clamp(d,4*c)}},m.codec.base64={M:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,f=m.codec.base64.M,g=0,h=m.bitArray.bitLength(a);for(c&&(f=f.substr(0,62)+"-_"),c=0;6*d.length<h;)d+=f.charAt((g^a[c]>>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;3&d.length&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c,e,f=[],g=0,h=m.codec.base64.M,i=0;for(b&&(h=h.substr(0,62)+"-_"),c=0;c<a.length;c++)e=h.indexOf(a.charAt(c)),0>e&&d(new m.exception.invalid("this isn't base64!")),26<g?(g-=26,f.push(i^e>>>g),i=e<<32-g):(g+=6,i^=e<<32-g);return 56&g&&f.push(m.bitArray.partial(56&g,i,1)),f}},m.codec.base64url={fromBits:function(a){return m.codec.base64.fromBits(a,1,1)},toBits:function(a){return m.codec.base64.toBits(a,1)}},m.hash.sha256=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha256.hash=function(a){return(new m.hash.sha256).update(a).finalize()},m.hash.sha256.prototype={blockSize:512,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=512+b&-512;b<=a;b+=512)this.r(c.splice(0,16));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+2;15&a;a++)b.push(0);for(b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,16));return this.reset(),c},l:[],b:[],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}var b,c=0,d=2;a:for(;64>c;d++){for(b=2;b*b<=d;b++)if(0===d%b)continue a;8>c&&(this.l[c]=a(Math.pow(d,.5))),this.b[c]=a(Math.pow(d,1/3)),c++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7];for(a=0;64>a;a++)16>a?b=d[a]:(b=d[a+1&15],c=d[a+14&15],b=d[15&a]=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[15&a]+d[a+9&15]|0),b=b+n+(k>>>6^k>>>11^k>>>25^k<<26^k<<21^k<<7)+(m^k&(l^m))+f[a],n=m,m=l,l=k,k=j+b|0,j=i,i=h,h=g,g=b+(h&i^j&(h^i))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+g|0,e[1]=e[1]+h|0,e[2]=e[2]+i|0,e[3]=e[3]+j|0,e[4]=e[4]+k|0,e[5]=e[5]+l|0,e[6]=e[6]+m|0,e[7]=e[7]+n|0}},m.hash.sha512=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha512.hash=function(a){return(new m.hash.sha512).update(a).finalize()},m.hash.sha512.prototype={blockSize:1024,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=1024+b&-1024;b<=a;b+=1024)this.r(c.splice(0,32));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+4;31&a;a++)b.push(0);for(b.push(0),b.push(0),b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,32));return this.reset(),c},l:[],ca:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],ea:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}function b(a){return 1099511627776*(a-Math.floor(a))&255}var c,d=0,e=2;a:for(;80>d;e++){for(c=2;c*c<=e;c++)if(0===e%c)continue a;8>d&&(this.l[2*d]=a(Math.pow(e,.5)),this.l[2*d+1]=b(Math.pow(e,.5))<<24|this.ca[d]),this.b[2*d]=a(Math.pow(e,1/3)),this.b[2*d+1]=b(Math.pow(e,1/3))<<24|this.ea[d],d++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7],o=e[8],p=e[9],q=e[10],r=e[11],s=e[12],t=e[13],u=e[14],v=e[15],w=g,x=h,y=i,z=j,A=k,B=l,C=m,D=n,E=o,F=p,G=q,H=r,I=s,J=t,K=u,L=v;for(a=0;80>a;a++){if(16>a)b=d[2*a],c=d[2*a+1];else{c=d[2*(a-15)];var M=d[2*(a-15)+1];b=(M<<31|c>>>1)^(M<<24|c>>>8)^c>>>7;var N=(c<<31|M>>>1)^(c<<24|M>>>8)^(c<<25|M>>>7);c=d[2*(a-2)];var O=d[2*(a-2)+1],M=(O<<13|c>>>19)^(c<<3|O>>>29)^c>>>6,O=(c<<13|O>>>19)^(O<<3|c>>>29)^(c<<26|O>>>6),P=d[2*(a-7)],Q=d[2*(a-16)],R=d[2*(a-16)+1];c=N+d[2*(a-7)+1],b=b+P+(c>>>0<N>>>0?1:0),c+=O,b+=M+(c>>>0<O>>>0?1:0),c+=R,b+=Q+(c>>>0<R>>>0?1:0)}d[2*a]=b|=0,d[2*a+1]=c|=0;var P=E&G^~E&I,S=F&H^~F&J,O=w&y^w&A^y&A,T=x&z^x&B^z&B,Q=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),R=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),U=f[2*a],V=f[2*a+1],M=L+((E<<18|F>>>14)^(E<<14|F>>>18)^(F<<23|E>>>9)),N=K+((F<<18|E>>>14)^(F<<14|E>>>18)^(E<<23|F>>>9))+(M>>>0<L>>>0?1:0),M=M+S,N=N+(P+(M>>>0<S>>>0?1:0)),M=M+V,N=N+(U+(M>>>0<V>>>0?1:0)),M=M+c|0,N=N+(b+(M>>>0<c>>>0?1:0));c=R+T,b=Q+O+(c>>>0<R>>>0?1:0),K=I,L=J,I=G,J=H,G=E,H=F,F=D+M|0,E=C+N+(F>>>0<D>>>0?1:0)|0,C=A,D=B,A=y,B=z,y=w,z=x,x=M+c|0,w=N+b+(x>>>0<M>>>0?1:0)|0}h=e[1]=h+x|0,e[0]=g+w+(h>>>0<x>>>0?1:0)|0,j=e[3]=j+z|0,e[2]=i+y+(j>>>0<z>>>0?1:0)|0,l=e[5]=l+B|0,e[4]=k+A+(l>>>0<B>>>0?1:0)|0,n=e[7]=n+D|0,e[6]=m+C+(n>>>0<D>>>0?1:0)|0,p=e[9]=p+F|0,e[8]=o+E+(p>>>0<F>>>0?1:0)|0,r=e[11]=r+H|0,e[10]=q+G+(r>>>0<H>>>0?1:0)|0,t=e[13]=t+J|0,e[12]=s+I+(t>>>0<J>>>0?1:0)|0,v=e[15]=v+L|0,e[14]=u+K+(v>>>0<L>>>0?1:0)|0}},m.mode.ccm={name:"ccm",w:[],listenProgress:function(a){m.mode.ccm.w.push(a)},unListenProgress:function(a){a=m.mode.ccm.w.indexOf(a),-1<a&&m.mode.ccm.w.splice(a,1)},X:function(a){var b,c=m.mode.ccm.w.slice();for(b=0;b<c.length;b+=1)c[b](a)},encrypt:function(a,b,c,e,f){var g,h=b.slice(0),i=m.bitArray,j=i.bitLength(c)/8,k=i.bitLength(h)/8;for(f=f||64,e=e||[],7>j&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),g=2;4>g&&k>>>8*g;g++);return g<15-j&&(g=15-j),c=i.clamp(c,8*(15-g)),b=m.mode.ccm.O(a,b,c,e,f,g),h=m.mode.ccm.s(a,h,c,b,f,g),i.concat(h.data,h.tag)},decrypt:function(a,b,c,e,f){f=f||64,e=e||[];var g=m.bitArray,h=g.bitLength(c)/8,i=g.bitLength(b),j=g.clamp(b,i-f),k=g.bitSlice(b,i-f),i=(i-f)/8;for(7>h&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),b=2;4>b&&i>>>8*b;b++);return b<15-h&&(b=15-h),c=g.clamp(c,8*(15-b)),j=m.mode.ccm.s(a,j,c,k,f,b),a=m.mode.ccm.O(a,j.data,c,e,f,b),g.equal(j.tag,a)||d(new m.exception.corrupt("ccm: tag doesn't match")),j.data},ga:function(a,b,c,d,e,f){var g=[],h=m.bitArray,i=h.j;if(d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)],d=h.concat(d,c),d[3]|=e,d=a.encrypt(d),b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:4294967295>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;b<g.length;b+=4)d=a.encrypt(i(d,g.slice(b,b+4).concat([0,0,0])));return d},O:function(a,b,c,e,f,g){var h=m.bitArray,i=h.j;for(f/=8,(f%2||4>f||16<f)&&d(new m.exception.invalid("ccm: invalid tag length")),(4294967295<e.length||4294967295<b.length)&&d(new m.exception.bug("ccm: can't deal with 4GiB or more data")),c=m.mode.ccm.ga(a,e,c,f,h.bitLength(b)/8,g),e=0;e<b.length;e+=4)c=a.encrypt(i(c,b.slice(e,e+4).concat([0,0,0])));return h.clamp(c,8*f)},s:function(a,b,c,d,e,f){var g,h=m.bitArray;g=h.j;var i=b.length,j=h.bitLength(b),k=i/50,l=k;if(c=h.concat([h.partial(8,f-1)],c).concat([0,0,0]).slice(0,4),d=h.bitSlice(g(d,a.encrypt(c)),0,e),!i)return{tag:d,data:[]};for(g=0;g<i;g+=4)g>k&&(m.mode.ccm.X(g/i),k+=l),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,j)}}},m.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits"));var h,i=m.mode.ocb2.K,j=m.bitArray,k=j.j,l=[0,0,0,0];c=i(a.encrypt(c));var n,o=[];for(e=e||[],f=f||64,h=0;h+4<b.length;h+=4)n=b.slice(h,h+4),l=k(l,n),o=o.concat(k(c,a.encrypt(k(c,n)))),c=i(c);return n=b.slice(h),b=j.bitLength(n),h=a.encrypt(k(c,[0,0,0,b])),n=j.clamp(k(n.concat([0,0,0]),h),b),l=k(l,k(n.concat([0,0,0]),h)),l=a.encrypt(k(l,k(c,i(c)))),e.length&&(l=k(l,g?e:m.mode.ocb2.pmac(a,e))),o.concat(j.concat(n,j.clamp(l,f)))},decrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits")),f=f||64;var h,i,j=m.mode.ocb2.K,k=m.bitArray,l=k.j,n=[0,0,0,0],o=j(a.encrypt(c)),p=m.bitArray.bitLength(b)-f,q=[];for(e=e||[],c=0;c+4<p/32;c+=4)h=l(o,a.decrypt(l(o,b.slice(c,c+4)))),n=l(n,h),q=q.concat(h),o=j(o);return i=p-32*c,h=a.encrypt(l(o,[0,0,0,i])),h=l(h,k.clamp(b.slice(c),i).concat([0,0,0])),n=l(n,h),n=a.encrypt(l(n,l(o,j(o)))),e.length&&(n=l(n,g?e:m.mode.ocb2.pmac(a,e))),k.equal(k.clamp(n,f),k.bitSlice(b,p))||d(new m.exception.corrupt("ocb: tag doesn't match")),q.concat(k.clamp(h,i))},pmac:function(a,b){var c,d=m.mode.ocb2.K,e=m.bitArray,f=e.j,g=[0,0,0,0],h=a.encrypt([0,0,0,0]),h=f(h,d(d(h)));for(c=0;c+4<b.length;c+=4)h=d(h),g=f(g,a.encrypt(f(h,b.slice(c,c+4))));return c=b.slice(c),128>e.bitLength(c)&&(h=f(h,d(h)),c=e.concat(c,[-2147483648,0,0,0])),g=f(g,c),a.encrypt(f(d(f(h,d(h))),g))},K:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}},m.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var f=b.slice(0);return b=m.bitArray,d=d||[],a=m.mode.gcm.s(!0,a,f,d,c,e||128),b.concat(a.data,a.tag)},decrypt:function(a,b,c,e,f){var g=b.slice(0),h=m.bitArray,i=h.bitLength(g);return f=f||128,e=e||[],f<=i?(b=h.bitSlice(g,i-f),g=h.bitSlice(g,0,i-f)):(b=g,g=[]),a=m.mode.gcm.s(l,a,g,e,c,f),h.equal(a.tag,b)||d(new m.exception.corrupt("gcm: tag doesn't match")),a.data},ba:function(a,b){var c,d,e,f,g,h=m.bitArray.j;for(e=[0,0,0,0],f=b.slice(0),c=0;128>c;c++){for((d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,f)),g=0!==(1&f[3]),d=3;0<d;d--)f[d]=f[d]>>>1|(1&f[d-1])<<31;f[0]>>>=1,g&&(f[0]^=-520093696)}return e},k:function(a,b,c){var d,e=c.length;for(b=b.slice(0),d=0;d<e;d+=4)b[0]^=4294967295&c[d],b[1]^=4294967295&c[d+1],b[2]^=4294967295&c[d+2],b[3]^=4294967295&c[d+3],b=m.mode.gcm.ba(b,a);return b},s:function(a,b,c,d,e,f){var g,h,i,j,k,l,n,o,p=m.bitArray;for(l=c.length,n=p.bitLength(c),o=p.bitLength(d),h=p.bitLength(e),g=b.encrypt([0,0,0,0]),96===h?(e=e.slice(0),e=p.concat(e,[1])):(e=m.mode.gcm.k(g,[0,0,0,0],e),e=m.mode.gcm.k(g,e,[0,0,Math.floor(h/4294967296),4294967295&h])),h=m.mode.gcm.k(g,[0,0,0,0],d),k=e.slice(0),d=h.slice(0),a||(d=m.mode.gcm.k(g,h,c)),j=0;j<l;j+=4)k[3]++,i=b.encrypt(k),c[j]^=i[0],c[j+1]^=i[1],c[j+2]^=i[2],c[j+3]^=i[3];return c=p.clamp(c,n),a&&(d=m.mode.gcm.k(g,h,c)),a=[Math.floor(o/4294967296),4294967295&o,Math.floor(n/4294967296),4294967295&n],d=m.mode.gcm.k(g,d,a),i=b.encrypt(e),d[0]^=i[0],d[1]^=i[1],d[2]^=i[2],d[3]^=i[3],{tag:p.bitSlice(d,0,f),data:c}}},m.misc.hmac=function(a,b){this.P=b=b||m.hash.sha256;var c,d=[[],[]],e=b.prototype.blockSize/32;for(this.q=[new b,new b],a.length>e&&(a=b.hash(a)),c=0;c<e;c++)d[0][c]=909522486^a[c],d[1][c]=1549556828^a[c];this.q[0].update(d[0]),this.q[1].update(d[1]),this.J=new b(this.q[0])},m.misc.hmac.prototype.encrypt=m.misc.hmac.prototype.mac=function(a){return this.S&&d(new m.exception.invalid("encrypt on already updated hmac called!")),this.update(a),this.digest(a)},m.misc.hmac.prototype.reset=function(){this.J=new this.P(this.q[0]),this.S=l},m.misc.hmac.prototype.update=function(a){this.S=!0,this.J.update(a)},m.misc.hmac.prototype.digest=function(){var a=this.J.finalize(),a=new this.P(this.q[1]).update(a).finalize();return this.reset(),a},m.misc.pbkdf2=function(a,b,c,e,f){c=c||1e3,(0>e||0>c)&&d(m.exception.invalid("invalid params to pbkdf2")),"string"==typeof a&&(a=m.codec.utf8String.toBits(a)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),f=f||m.misc.hmac,a=new f(a);var g,h,i,j,k=[],l=m.bitArray;for(j=1;32*k.length<(e||1);j++){for(f=g=a.encrypt(l.concat(b,[j])),h=1;h<c;h++)for(g=a.encrypt(g),i=0;i<g.length;i++)f[i]^=g[i];k=k.concat(f)}return e&&(k=l.clamp(k,e)),k},m.prng=function(a){this.f=[new m.hash.sha256],this.m=[0],this.I=0,this.A={},this.H=0,this.N={},this.Q=this.g=this.n=this.Z=0,this.b=[0,0,0,0,0,0,0,0],this.i=[0,0,0,0],this.F=k,this.G=a,this.u=l,this.D={progress:{},seeded:{}},this.p=this.Y=0,this.B=1,this.C=2,this.U=65536,this.L=[0,48,64,96,128,192,256,384,512,768,1024],this.V=3e4,this.T=80},m.prng.prototype={randomWords:function(a,b){var c,e=[];c=this.isReady(b);var f;if(c===this.p&&d(new m.exception.notReady("generator isn't seeded")),c&this.C){c=!(c&this.B),f=[];var g,j=0;for(this.Q=f[0]=(new Date).valueOf()+this.V,g=0;16>g;g++)f.push(4294967296*Math.random()|0);for(g=0;g<this.f.length&&(f=f.concat(this.f[g].finalize()),j+=this.m[g],this.m[g]=0,!(!c&&this.I&1<<g));g++);for(this.I>=1<<this.f.length&&(this.f.push(new m.hash.sha256),this.m.push(0)),this.g-=j,j>this.n&&(this.n=j),this.I++,this.b=m.hash.sha256.hash(this.b.concat(f)),this.F=new m.cipher.aes(this.b),c=0;4>c&&(this.i[c]=this.i[c]+1|0,!this.i[c]);c++);}for(c=0;c<a;c+=4)0===(c+1)%this.U&&h(this),f=i(this),e.push(f[0],f[1],f[2],f[3]);return h(this),e.slice(0,a)},setDefaultParanoia:function(a,b){0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b&&d("Setting paranoia=0 will ruin your security; use it only for testing"),this.G=a},addEntropy:function(a,b,c){c=c||"user";var e,g,h=(new Date).valueOf(),i=this.A[c],j=this.isReady(),l=0;switch(e=this.N[c],e===k&&(e=this.N[c]=this.Z++),i===k&&(i=this.A[c]=0),this.A[c]=(this.A[c]+1)%this.f.length,typeof a){case"number":b===k&&(b=1),this.f[i].update([e,this.H++,1,b,h,1,0|a]);break;case"object":if(c=Object.prototype.toString.call(a),"[object Uint32Array]"===c){for(g=[],c=0;c<a.length;c++)g.push(a[c]);a=g}else for("[object Array]"!==c&&(l=1),c=0;c<a.length&&!l;c++)"number"!=typeof a[c]&&(l=1);if(!l){if(b===k)for(c=b=0;c<a.length;c++)for(g=a[c];0<g;)b++,g>>>=1;this.f[i].update([e,this.H++,2,b,h,a.length].concat(a))}break;case"string":b===k&&(b=a.length),this.f[i].update([e,this.H++,3,b,h,a.length]),this.f[i].update(a);break;default:l=1}l&&d(new m.exception.bug("random: addEntropy only supports number, array of numbers or string")),this.m[i]+=b,this.g+=b,j===this.p&&(this.isReady()!==this.p&&f("seeded",Math.max(this.n,this.g)),f("progress",this.getProgress()))},isReady:function(a){return a=this.L[a!==k?a:this.G],this.n&&this.n>=a?this.m[0]>this.T&&(new Date).valueOf()>this.Q?this.C|this.B:this.B:this.g>=a?this.C|this.p:this.p},getProgress:function(a){return a=this.L[a?a:this.G],this.n>=a?1:this.g>a?1:this.g/a},startCollectors:function(){this.u||(this.a={loadTimeCollector:j(this,this.fa),mouseCollector:j(this,this.ha),keyboardCollector:j(this,this.da),accelerometerCollector:j(this,this.W),touchCollector:j(this,this.ja)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,l),window.addEventListener("mousemove",this.a.mouseCollector,l),window.addEventListener("keypress",this.a.keyboardCollector,l),window.addEventListener("devicemotion",this.a.accelerometerCollector,l),window.addEventListener("touchmove",this.a.touchCollector,l)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):d(new m.exception.bug("can't attach event")),this.u=!0)},stopCollectors:function(){this.u&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,l),window.removeEventListener("mousemove",this.a.mouseCollector,l),window.removeEventListener("keypress",this.a.keyboardCollector,l),window.removeEventListener("devicemotion",this.a.accelerometerCollector,l),window.removeEventListener("touchmove",this.a.touchCollector,l)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.u=l)},addEventListener:function(a,b){this.D[a][this.Y++]=b},removeEventListener:function(a,b){var c,d,e=this.D[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;c<f.length;c++)d=f[c],delete e[d]},da:function(){g(1)},ha:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(a){c=b=0}0!=b&&0!=c&&m.random.addEntropy([b,c],2,"mouse"),g(0)},ja:function(a){a=a.touches[0]||a.changedTouches[0],m.random.addEntropy([a.pageX||a.clientX,a.pageY||a.clientY],1,"touch"),g(0)},fa:function(){g(2)},W:function(a){if(a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z,window.orientation){var b=window.orientation;"number"==typeof b&&m.random.addEntropy(b,1,"accelerometer")}a&&m.random.addEntropy(a,2,"accelerometer"),g(0)}},m.random=new m.prng(6);a:try{var n,o,p,q;if(q="undefined"!=typeof b){var r;if(r=b.exports){var s;try{s=a("crypto")}catch(a){s=null}r=(o=s)&&o.randomBytes}q=r}if(q)n=o.randomBytes(128),n=new Uint32Array(new Uint8Array(n).buffer),m.random.addEntropy(n,1024,"crypto['randomBytes']");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(p=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(p);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break a;window.msCrypto.getRandomValues(p)}m.random.addEntropy(p,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))}m.json={defaults:{v:1,iter:1e3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},aa:function(a,b,c,e){c=c||{},e=e||{};var f,g=m.json,h=g.h({iv:m.random.randomWords(4,0)},g.defaults);return g.h(h,c),c=h.adata,"string"==typeof h.salt&&(h.salt=m.codec.base64.toBits(h.salt)),"string"==typeof h.iv&&(h.iv=m.codec.base64.toBits(h.iv)),(!m.mode[h.mode]||!m.cipher[h.cipher]||"string"==typeof a&&100>=h.iter||64!==h.ts&&96!==h.ts&&128!==h.ts||128!==h.ks&&192!==h.ks&&256!==h.ks||2>h.iv.length||4<h.iv.length)&&d(new m.exception.invalid("json encrypt: invalid parameters")),"string"==typeof a?(f=m.misc.cachedPbkdf2(a,h),a=f.key.slice(0,h.ks/32),h.salt=f.salt):m.ecc&&a instanceof m.ecc.elGamal.publicKey&&(f=a.kem(),h.kemtag=f.tag,a=f.key.slice(0,h.ks/32)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),"string"==typeof c&&(h.adata=c=m.codec.utf8String.toBits(c)),f=new m.cipher[h.cipher](a),g.h(e,h),e.key=a,h.ct="ccm"===h.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b instanceof ArrayBuffer?m.arrayBuffer.ccm.encrypt(f,b,h.iv,c,h.ts):m.mode[h.mode].encrypt(f,b,h.iv,c,h.ts),h},encrypt:function(a,b,c,d){var e=m.json,f=e.aa.apply(e,arguments);return e.encode(f)},$:function(a,b,c,e){c=c||{},e=e||{};var f=m.json;b=f.h(f.h(f.h({},f.defaults),b),c,!0);var g,h;return g=b.adata,"string"==typeof b.salt&&(b.salt=m.codec.base64.toBits(b.salt)),"string"==typeof b.iv&&(b.iv=m.codec.base64.toBits(b.iv)),(!m.mode[b.mode]||!m.cipher[b.cipher]||"string"==typeof a&&100>=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&256!==b.ks||!b.iv||2>b.iv.length||4<b.iv.length)&&d(new m.exception.invalid("json decrypt: invalid parameters")),"string"==typeof a?(h=m.misc.cachedPbkdf2(a,b),a=h.key.slice(0,b.ks/32),b.salt=h.salt):m.ecc&&a instanceof m.ecc.elGamal.secretKey&&(a=a.unkem(m.codec.base64.toBits(b.kemtag)).slice(0,b.ks/32)),"string"==typeof g&&(g=m.codec.utf8String.toBits(g)),h=new m.cipher[b.cipher](a),g="ccm"===b.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b.ct instanceof ArrayBuffer?m.arrayBuffer.ccm.decrypt(h,b.ct,b.iv,b.tag,g,b.ts):m.mode[b.mode].decrypt(h,b.ct,b.iv,g,b.ts),f.h(e,b),e.key=a,1===c.raw?g:m.codec.utf8String.fromBits(g)},decrypt:function(a,b,c,d){var e=m.json;return e.$(a,e.decode(b),c,d)},encode:function(a){var b,c="{",e="";for(b in a)if(a.hasOwnProperty(b))switch(b.match(/^[a-z0-9]+$/i)||d(new m.exception.invalid("json encode: invalid property name")),c+=e+'"'+b+'":',e=",",typeof a[b]){case"number":case"boolean":c+=a[b];break;case"string":c+='"'+escape(a[b])+'"';break;case"object":c+='"'+m.codec.base64.fromBits(a[b],0)+'"';break;default:d(new m.exception.bug("json encode: unsupported type"))}return c+"}"},decode:function(a){a=a.replace(/\s/g,""),a.match(/^\{.*\}$/)||d(new m.exception.invalid("json decode: this isn't json!")),a=a.replace(/^\{|\}$/g,"").split(/,/);var b,c,e={};for(b=0;b<a.length;b++)(c=a[b].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))||d(new m.exception.invalid("json decode: this isn't json!")),null!=c[3]?e[c[2]]=parseInt(c[3],10):null!=c[4]?e[c[2]]=c[2].match(/^(ct|adata|salt|iv)$/)?m.codec.base64.toBits(c[4]):unescape(c[4]):null!=c[5]&&(e[c[2]]="true"===c[5]);return e},h:function(a,b,c){if(a===k&&(a={}),b===k)return a;for(var e in b)b.hasOwnProperty(e)&&(c&&a[e]!==k&&a[e]!==b[e]&&d(new m.exception.invalid("required parameter overridden")),a[e]=b[e]);return a},la:function(a,b){var c,d={};for(c in a)a.hasOwnProperty(c)&&a[c]!==b[c]&&(d[c]=a[c]);return d},ka:function(a,b){var c,d={};for(c=0;c<b.length;c++)a[b[c]]!==k&&(d[b[c]]=a[b[c]]);return d}},m.encrypt=m.json.encrypt,m.decrypt=m.json.decrypt,m.misc.ia={},m.misc.cachedPbkdf2=function(a,b){var c,d=m.misc.ia;return b=b||{},c=b.iter||1e3,d=d[a]=d[a]||{},c=d[c]=d[c]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):m.random.randomWords(2,0)},d=b.salt===k?c.firstSalt:b.salt,c[d]=c[d]||m.misc.pbkdf2(a,d,b.iter),{key:c[d].slice(0),salt:d.slice(0)}}},{crypto:133}],31:[function(a,b,c){b.exports=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","affair","afford","afraid","again","age","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert","alien","all","alley","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","among","amount","amused","analyst","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","approve","april","arch","arctic","area","arena","argue","arm","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artefact","artist","artwork","ask","aspect","assault","asset","assist","assume","asthma","athlete","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","can","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","car","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","category","cattle","caught","cause","caution","cave","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","cupboard","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"];
@@ 2-2 (lines=1) @@
1
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.blocktrailSDK=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c,Buffer){function d(a,b){var c=h.HDNode.fromBase58(a[0],b);if("undefined"!=typeof c.keyPair.d)throw new Error("BIP32Key contained private key material - abort");if("M"!==a[1].slice(0,1))throw new Error("BIP32Key contained non-public path - abort")}function e(a,b){d(a.primary_public_key,b),d(a.backup_public_key,b)}var f=a("lodash"),g=a("q"),h=a("bitcoinjs-lib"),i=a("bitcoinjs-message"),j=a("bip39"),k=a("./wallet"),l=a("./rest_client"),m=a("./encryption"),n=a("./keyderivation"),o=a("./encryption_mnemonic"),p=a("./blocktrail"),q=a("randombytes"),r=a("crypto-js"),s=a("./webworkifier"),t=a("./use-webworker")(),u=function(a){var b=this;return this instanceof u?(b.testnet=a.testnet=a.testnet||!1,b.testnet?b.network=h.networks.testnet:b.network=h.networks.bitcoin,b.bitcoinCash=a.network&&"BCC"===a.network,b.feeSanityCheck="undefined"==typeof a.feeSanityCheck||a.feeSanityCheck,b.feeSanityCheckBaseFeeMultiplier=a.feeSanityCheckBaseFeeMultiplier||200,a.apiNetwork=a.apiNetwork||(b.testnet?"t":"")+(a.network||"BTC").toUpperCase(),void(b.client=u.initRestClient(a))):new u(a)};u.initRestClient=function(a){return c.env.BLOCKTRAIL_SDK_API_ENDPOINT&&(a.host=c.env.BLOCKTRAIL_SDK_API_ENDPOINT),a.host&&0===a.host.indexOf("https://")?(a.https=!0,a.host=a.host.substr(8)):a.host&&0===a.host.indexOf("http://")&&(a.https=!1,a.host=a.host.substr(7)),"undefined"==typeof a.https&&(a.https=!0),a.host||(a.host="api.blocktrail.com"),a.port||(a.port=a.https?443:80),a.endpoint||(a.endpoint="/"+(a.apiVersion||"v1")+(a.apiNetwork?"/"+a.apiNetwork:"")),new l(a)};var v=function(a){return g.when(a).then(function(a){return a.storePrimaryMnemonic&&(a.storeDataOnServer=a.storePrimaryMnemonic),"undefined"==typeof a.storeDataOnServer&&(a.storeDataOnServer=!a.primarySeed),a})},w=function(a,b){return g.when(a).then(function(a){if(a.storeDataOnServer){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),a.encryptedSecret=r.AES.encrypt(a.secret,a.passphrase).toString(r.format.OpenSSL)}b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),a.encryptedPrimarySeed=r.AES.encrypt(a.primarySeed.toString("base64"),a.secret).toString(r.format.OpenSSL),a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoveryEncryptedSecret=r.AES.encrypt(a.secret,a.recoverySecret).toString(r.format.OpenSSL)}return a})};u.prototype.promisedEncrypt=function(b,c,d){if(t){var e=m.generateSalt(),f=m.generateIV();return s.workify(u.prototype.promisedEncrypt,function(){return a("./webworker")},{method:"Encryption.encryptWithSaltAndIV",pt:b,pw:c,saltBuf:e,iv:f,iterations:d}).then(function(a){return Buffer.from(a.cipherText.buffer)})}try{return g.when(m.encrypt(b,c,d))}catch(a){return g.reject(a)}},u.prototype.promisedDecrypt=function(b,c){if(t)return s.workify(u.prototype.promisedDecrypt,function(){return a("./webworker")},{method:"Encryption.decrypt",ct:b,pw:c}).then(function(a){return Buffer.from(a.plainText.buffer)});try{return g.when(m.decrypt(b,c))}catch(a){return g.reject(a)}},u.prototype.produceEncryptedDataV3=function(a,b){var c=this;return g.when(a).then(function(a){return a.storeDataOnServer?g.when().then(function(){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8),c.promisedEncrypt(a.secret,new Buffer(a.passphrase),n.defaultIterations).then(function(b){a.encryptedSecret=b})}if(!(a.secret instanceof Buffer))throw new Error("Secret must be a buffer")}).then(function(){return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),c.promisedEncrypt(a.primarySeed,a.secret,n.subkeyIterations).then(function(b){a.encryptedPrimarySeed=b})}).then(function(){if(a.recoverySecret!==!1)return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoverySecret||(a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8)),c.promisedEncrypt(a.secret,a.recoverySecret,n.defaultIterations).then(function(b){a.recoveryEncryptedSecret=b})}).then(function(){return a}):a})};var x=function(a,b,c){return g.when(a).then(function(a){return a.backupPublicKey||(a.backupSeed=a.backupSeed||q(k.WALLET_ENTROPY_BITS/8)),c(u.CREATE_WALLET_PROGRESS_PRIMARY),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,b),c(u.CREATE_WALLET_PROGRESS_BACKUP),a.backupPublicKey||(a.backupPrivateKey=h.HDNode.fromSeedBuffer(a.backupSeed,b),a.backupPublicKey=a.backupPrivateKey.neutered()),a.primaryPublicKey=a.primaryPrivateKey.deriveHardened(a.keyIndex).neutered(),c(u.CREATE_WALLET_PROGRESS_SUBMIT),a})};u.prototype.mnemonicToPrivateKey=function(a,b,c){var d=this,e=g.defer();e.promise.spreadNodeify(c);var f=d.testnet?h.networks.testnet:h.networks.bitcoin;return e.resolve(g.fcall(function(){return d.mnemonicToSeedHex(a,b).then(function(a){return h.HDNode.fromSeedHex(a,f)})})),e.promise},u.prototype.mnemonicToSeedHex=function(b,c){var d=this;if(t)return s.workify(d.mnemonicToSeedHex,function(){return a("./webworker")},{method:"mnemonicToSeedHex",mnemonic:b,passphrase:c}).then(function(a){return a.seed});try{return g.when(j.mnemonicToSeedHex(b,c))}catch(a){return g.reject(a)}},u.prototype.resolvePrimaryPrivateKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.passphrase&&a.password)throw new p.WalletCreateError("Can't specify passphrase and password");if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryMnemonic&&a.primarySeed)throw new p.WalletInitError("Can only specify one of; Primary Mnemonic or Primary Seed");if(a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");if(!a.primaryMnemonic&&!a.primarySeed)throw new p.WalletInitError("Need to specify at least one of; Primary Mnemonic or Primary Seed");if(a.primarySeed)c.primarySeed=a.primarySeed,a.primaryPrivateKey=h.HDNode.fromSeedBuffer(c.primarySeed,e),d.resolve(a);else{if(!a.passphrase)throw new p.WalletInitError("Can't init wallet with Primary Mnemonic without a passphrase");c.mnemonicToSeedHex(a.primaryMnemonic,a.passphrase).then(function(b){try{a.primarySeed=new Buffer(b,"hex"),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,e),d.resolve(a)}catch(a){d.reject(a)}},function(a){d.reject(a)})}}catch(a){d.reject(a)}return d.promise},u.prototype.resolveBackupPublicKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.backupMnemonic&&a.backupPublicKey)throw new p.WalletInitError("Can only specify one of; Backup Mnemonic or Backup PublicKey");if(!a.backupMnemonic&&!a.backupPublicKey)throw new p.WalletInitError("Need to specify at least one of; Backup Mnemonic or Backup PublicKey");a.backupPublicKey?a.backupPublicKey instanceof h.HDNode?d.resolve(a):(a.backupPublicKey=h.HDNode.fromBase58(a.backupPublicKey,e),d.resolve(a)):c.mnemonicToPrivateKey(a.backupMnemonic,"").then(function(b){a.backupPublicKey=b.neutered(),d.resolve(a)},function(a){d.reject(a)})}catch(a){d.reject(a)}return d.promise},u.prototype.debugAuth=function(a){var b=this;return b.client.get("/debug/http-signature",null,!0,a)},u.prototype.address=function(a,b){var c=this;return c.client.get("/address/"+a,null,b)},u.prototype.addresses=function(a,b){var c=this;return c.client.post("/address",null,{addresses:a},b)},u.prototype.addressTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/transactions",b,c)},u.prototype.batchAddressHasTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/has-transactions",b,{addresses:a},c)},u.prototype.addressUnconfirmedTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unconfirmed-transactions",b,c)},u.prototype.addressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unspent-outputs",b,c)},u.prototype.batchAddressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/unspent-outputs",b,{addresses:a},c)},u.prototype.verifyAddress=function(a,b,c){var d=this;return d.client.post("/address/"+a+"/verify",null,{signature:b},c)},u.prototype.allBlocks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/all-blocks",a,b)},u.prototype.block=function(a,b){var c=this;return c.client.get("/block/"+a,null,b)},u.prototype.blockLatest=function(a){var b=this;return b.client.get("/block/latest",null,a)},u.prototype.blockTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/block/"+a+"/transactions",b,c)},u.prototype.transaction=function(a,b){var c=this;return c.client.get("/transaction/"+a,null,b)},u.prototype.transactions=function(a,b){var c=this;return c.client.post("/transactions",null,a,b,!1)},u.prototype.allWebhooks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/webhooks",a,b)},u.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/webhook",null,{url:a,identifier:b},c)},u.prototype.getWebhook=function(a,b){var c=this;return c.client.get("/webhook/"+a,null,b)},u.prototype.updateWebhook=function(a,b,c){var d=this;return d.client.put("/webhook/"+a,null,b,c)},u.prototype.deleteWebhook=function(a,b){var c=this;return c.client.delete("/webhook/"+a,null,null,b)},u.prototype.getWebhookEvents=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/webhook/"+a+"/events",b,c)},u.prototype.subscribeTransaction=function(a,b,c,d){var e=this,f={event_type:"transaction",transaction:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.subscribeAddressTransactions=function(a,b,c,d){var e=this,f={event_type:"address-transactions",address:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.batchSubscribeAddressTransactions=function(a,b,c){var d=this;return b.forEach(function(a){a.event_type="address-transactions"}),d.client.post("/webhook/"+a+"/events/batch",null,b,c)},u.prototype.subscribeNewBlocks=function(a,b){var c=this,d={event_type:"block"};return c.client.post("/webhook/"+a+"/events",null,d,b)},u.prototype.unsubscribeAddressTransactions=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/address-transactions/"+b,null,null,c)},u.prototype.unsubscribeTransaction=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/transaction/"+b,null,null,c)},u.prototype.unsubscribeNewBlocks=function(a,b){var c=this;return c.client.delete("/webhook/"+a+"/block",null,null,b)},u.prototype.initWallet=function(a,b){var c=this;if("object"!=typeof a&&(a={identifier:arguments[0],passphrase:arguments[1]},b=arguments[2]),a.check_backup_key&&"string"!=typeof a.check_backup_key)throw new Error("Invalid input, must provide the backup key as a string (the xpub)");var d=g.defer();d.promise.spreadNodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin,i=a.identifier;return i?(d.resolve(c.client.get("/wallet/"+i,null,!0).then(function(b){var d=a.keyIndex||b.key_index;if(a.walletVersion=b.wallet_version,a.check_backup_key&&a.check_backup_key!==b.backup_public_key[0])throw new Error("Backup key returned from server didn't match our own copy");var g=h.HDNode.fromBase58(b.backup_public_key[0],e),j=f.mapValues(b.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),l=f.mapValues(b.primary_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),m=new k(c,i,a.walletVersion,b.primary_mnemonic,b.encrypted_primary_seed,b.encrypted_secret,l,g,j,d,b.chain||0,b.segwit||0,c.testnet,b.checksum,b.upgrade_key_index,a.bypassNewAddressCheck);return m.recoverySecret=b.recovery_secret,a.readOnly?m:m.unlock(a).then(function(){return m})})),d.promise):(d.reject(new p.WalletInitError("Identifier is required")),d.promise)},u.CREATE_WALLET_PROGRESS_START=0,u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET=4,u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY=5,u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY=6,u.CREATE_WALLET_PROGRESS_PRIMARY=10,u.CREATE_WALLET_PROGRESS_BACKUP=20,u.CREATE_WALLET_PROGRESS_SUBMIT=30,u.CREATE_WALLET_PROGRESS_INIT=40,u.CREATE_WALLET_PROGRESS_DONE=100,u.prototype.createNewWallet=function(a,b){var c=this;if("object"!=typeof a){var d=arguments[0],e=arguments[1],f=arguments[2];b=arguments[3],"function"==typeof f&&(b=f,f=null),a={identifier:d,passphrase:e,keyIndex:f}}a.walletVersion=a.walletVersion||k.WALLET_VERSION_V3;var h=g.defer();return h.promise.spreadNodeify(b),g.nextTick(function(){return h.notify(u.CREATE_WALLET_PROGRESS_START),a.keyIndex=a.keyIndex||0,a.passphrase=a.passphrase||a.password,delete a.password,a.identifier?void(a.walletVersion===k.WALLET_VERSION_V1?c._createNewWalletV1(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V2?c._createNewWalletV2(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V3?c._createNewWalletV3(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):h.reject(new p.WalletCreateError("Invalid wallet version!"))):(h.reject(new p.WalletCreateError("Identifier is required")),h.promise)}),h.promise},u.prototype._createNewWalletV1=function(a){var b=this,c=g.defer();return g.nextTick(function(){if(!a.primaryMnemonic&&!a.primarySeed){if(!a.passphrase&&!a.password)return c.reject(new p.WalletCreateError("Can't generate Primary Mnemonic without a passphrase")),c.promise;a.primaryMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS),a.storePrimaryMnemonic!==!1&&(a.storePrimaryMnemonic=!0)}a.backupMnemonic||a.backupPublicKey||(a.backupMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS)),c.notify(u.CREATE_WALLET_PROGRESS_PRIMARY),b.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return c.notify(u.CREATE_WALLET_PROGRESS_BACKUP),b.resolveBackupPublicKeyFromOptions(a).then(function(a){c.notify(u.CREATE_WALLET_PROGRESS_SUBMIT);var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex,g=a.primaryPrivateKey.deriveHardened(e).neutered();return b.storeNewWalletV1(a.identifier,[g.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storePrimaryMnemonic&&a.primaryMnemonic,d,e,a.segwit||null).then(function(i){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var j=f.mapValues(i.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V1,a.primaryMnemonic,null,null,{keyIndex:g},a.backupPublicKey,j,e,i.chain||0,i.segwit||0,b.testnet,d,i.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V1,passphrase:a.passphrase,primarySeed:a.primarySeed,primaryMnemonic:null}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,primaryMnemonic:a.primaryMnemonic,backupMnemonic:a.backupMnemonic,blocktrailPublicKeys:j}]})})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)})}),c.promise},u.prototype._createNewWalletV2=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return w(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV2(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V2,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V2,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?j.entropyToMnemonic(p.convert(a.encryptedPrimarySeed,"base64","hex")):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed.toString("hex")):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?j.entropyToMnemonic(p.convert(a.recoveryEncryptedSecret,"base64","hex")):null,encryptedSecret:a.encryptedSecret?j.entropyToMnemonic(p.convert(a.encryptedSecret,"base64","hex")):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype._createNewWalletV3=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return b.produceEncryptedDataV3(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV3(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V3,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V3,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?o.encode(a.encryptedPrimarySeed):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?o.encode(a.recoveryEncryptedSecret):null,encryptedSecret:a.encryptedSecret?o.encode(a.encryptedSecret):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype.storeNewWalletV1=function(a,b,c,d,f,g,h){var i=this,j={identifier:a,wallet_version:k.WALLET_VERSION_V1,primary_public_key:b,backup_public_key:c,primary_mnemonic:d,checksum:f,key_index:g,segwit:h};return e(j,i.network),i.client.post("/wallet",null,j)},u.prototype.storeNewWalletV2=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V2,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d,encrypted_secret:f,recovery_secret:g,checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.storeNewWalletV3=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V3,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d.toString("base64"),encrypted_secret:f.toString("base64"),recovery_secret:g.toString("hex"),checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.updateWallet=function(a,b,c){var d=this;return d.client.post("/wallet/"+a,null,b,c)},u.prototype.upgradeKeyIndex=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/upgrade",null,{key_index:b,primary_public_key:c},d)},u.prototype.getWalletBalance=function(a,b){var c=this;return c.client.get("/wallet/"+a+"/balance",null,!0,b)},u.prototype.doWalletDiscovery=function(a,b,c){var d=this;return d.client.get("/wallet/"+a+"/discovery",{gap:b},!0,c)},u.prototype.getNewDerivation=function(a,b,c){var d=this;return d.client.post("/wallet/"+a+"/path",null,{path:b},c)},u.prototype.deleteWallet=function(a,b,c,d,e){var f=this;return"function"==typeof d&&(e=d,d=!1),f.client.delete("/wallet/"+a,{force:d},{checksum:b,signature:c},e)},u.prototype.coinSelection=function(a,b,c,d,e,f,h){var i=this;"function"==typeof e?(h=e,e=null,f={}):"function"==typeof f&&(h=f,f={}),e=e||k.FEE_STRATEGY_OPTIMAL,f=f||{};var j=g.defer();j.promise.spreadNodeify(h);var l={lock:c,zeroconf:d?1:0,zeroconfself:"undefined"==typeof f.allowZeroConfSelf||f.allowZeroConfSelf?1:0,fee_strategy:e};return f.forcefee&&(l.forcefee=f.forcefee),j.resolve(i.client.post("/wallet/"+a+"/coin-selection",l,b).then(function(a){return[a.utxos,a.fee,a.change,a]},function(a){if(a.message.match(/too low to pay the fee/))throw p.WalletFeeError(a);throw a})),j.promise},u.prototype.feePerKB=function(a){var b=this,c=g.defer();return c.promise.spreadNodeify(a),c.resolve(b.client.get("/fee-per-kb")),c.promise},u.prototype.sendTransaction=function(a,b,c,d,e,f,g){var h=this;"function"==typeof e?(g=e,e=null,f=!1):"function"==typeof f&&(g=f,f=!1);var i={paths:c,two_factor_token:e};return"string"==typeof b?i.raw_transaction=b:"object"==typeof b&&Object.keys(b).map(function(a){i[a]=b[a]}),h.client.post("/wallet/"+a+"/send",{check_fee:d?1:0,prioboost:f?1:0},i,g)},u.prototype.setupWalletWebhook=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/webhook",null,{url:c,identifier:b},d)},u.prototype.deleteWalletWebhook=function(a,b,c){var d=this;return d.client.delete("/wallet/"+a+"/webhook/"+b,null,null,c)},u.prototype.walletTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/transactions",b,!0,c)},u.prototype.walletAddresses=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/addresses",b,!0,c)},u.prototype.labelWalletAddress=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/address/"+b+"/label",null,{label:c},d)},u.prototype.walletMaxSpendable=function(a,b,c,d,e){var f=this;"function"==typeof c?(e=c,c=null):"function"==typeof d&&(e=d,d={}),c=c||k.FEE_STRATEGY_OPTIMAL,d=d||{};var g={outputs:d.outputs?d.outputs:1,zeroconf:b?1:0,zeroconfself:"undefined"==typeof d.allowZeroConfSelf||d.allowZeroConfSelf?1:0,fee_strategy:c};return d.forcefee&&(g.forcefee=d.forcefee),f.client.get("/wallet/"+a+"/max-spendable",g,!0,e)},u.prototype.walletUTXOs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/utxos",b,!0,c)},u.prototype.allWallets=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/wallets",a,!0,b)},u.prototype.verifyMessage=function(a,b,c,d){var e=this,f=g.defer();f.promise.nodeify(d);try{var h=i.verify(b,e.network.messagePrefix,a,new Buffer(c,"base64"));f.resolve(h)}catch(a){f.reject(a)}return f.promise},u.prototype.faucetWithdrawl=function(a,b,c){var d=this;return d.client.post("/faucet/withdrawl",null,{address:a,amount:b},c)},u.prototype.sendRawTransaction=function(a,b){var c=this;return c.client.post("/send-raw-tx",null,a,b)},u.prototype.price=function(a){var b=this;return b.client.get("/price",null,!1,a)},b.exports=u}).call(this,a("_process"),a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,"./rest_client":9,"./use-webworker":14,"./wallet":15,"./webworker":17,"./webworkifier":18,_process:263,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293,randombytes:297}],2:[function(a,b,c){(function(Buffer){var c=a("util"),d=a("assert"),e=a("crypto-js"),f=a("bip39"),g={COIN:1e8,PRECISION:8,DUST:2730,BASE_FEE:1e4},h=function(a,b,c){return new Buffer(a,b).toString(c)},i=function(a,b){var c=f.mnemonicToEntropy(a),d=h(c,"hex","base64"),i=e.AES.decrypt(d,b).toString(e.enc.Utf8);if(!i.length)throw new g.WalletDecryptError;return i},j=function(a,b){return i(a,b).toString(e.enc.Utf8)},k=function(a,b){return h(j(a,b),"base64","hex")},l=function(a,b){return new Buffer(k(a,b),"hex")},m=function(a,b){var c=e.AES.encrypt(a,b).toString(e.format.OpenSSL),d=h(c,"base64","hex"),g=f.entropyToMnemonic(d);return g},n=function(a,b){return m(h(a,"hex","base64"),b)},o=function(a,b){return m(a.toString("base64"),b)};g.convert=h,g.aesDecryptMnemonicToSeed=j,g.aesDecryptMnemonicToSeedBuffer=l,g.aesDecryptMnemonicToSeedHex=k,g.aesEncryptSeedToMnemonic=m,g.aesEncryptSeedHexToMnemonic=n,g.aesEncryptSeedBufferToMnemonic=o,g.V3Crypt={KeyDerivation:a("./keyderivation"),Encryption:a("./encryption"),EncryptionMnemonic:a("./encryption_mnemonic")},g.toSatoshi=function(a){return parseInt((a*g.COIN).toFixed(0),10)},g.toBTC=function(a){return(a/g.COIN).toFixed(g.PRECISION)},g.patchQ=function(a){function b(b,c,d){return a(b).spreadDone(c,d)}function c(b,c){return a(b).spreadNodeify(c)}a.spreadNodeify&&a.spreadDone||(a.spreadDone=b,a.makePromise.prototype.spreadDone=function(a,b){return this.all().done(function(b){return a.apply(void 0,b)},b)},a.spreadNodeify=c,a.makePromise.prototype.spreadNodeify=function(b){return b?void this.then(function(c){a.nextTick(function(){b.apply(void 0,[null].concat(c))})},function(c){a.nextTick(function(){b(c)})}):this})},Error.extend=function(a,b){d(a,"subTypeName is required");var e=function(c){return this instanceof e?(this.name=a,this.code=b,this.message=c?c.message||c||"":"",void(Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor))):new e(c)};return c.inherits(e,this),e.prototype.toString=function(){return this.name+": "+c.inspect(this.message)},e.extend=this.extend,e},"function"!=typeof Uint8Array.prototype.reverse&&(Buffer.prototype.reverse=function(){for(var a,b=0,c=this.length-1;b<=c;++b,--c)a=this[b],this[b]=this[c],this[c]=a;return this}),g.WalletInitError=Error.extend("WalletInitError",400),g.WalletCreateError=Error.extend("WalletCreateError",400),g.WalletUpgradeError=Error.extend("WalletUpgradeError",400),g.WalletChecksumError=Error.extend("WalletChecksumError",400),g.WalletDeleteError=Error.extend("WalletDeleteError",400),g.WalletDecryptError=Error.extend("WalletDecryptError",400),g.WalletAddressError=Error.extend("WalletAddressError",500),g.WalletSendError=Error.extend("WalletSendError",400),g.WalletLockedError=Error.extend("WalletLockedError",500),g.WalletFeeError=Error.extend("WalletFeeError",500),g.WalletInvalid2FAError=Error.extend("WalletInvalid2FAError",401),g.WalletMissing2FAError=Error.extend("WalletMissing2FAError",401),g.TransactionSignError=Error.extend("TransactionSignError",500),g.TransactionInputError=Error.extend("TransactionInputError",400),g.TransactionOutputError=Error.extend("TransactionOutputError",400),g.KeyPathError=Error.extend("KeyPathError",400),g.InvalidAddressError=Error.extend("InvalidAddressError",400),g.Error=Error.extend("Error",500),g.FEE_STRATEGY_FORCE_FEE="force_fee",g.FEE_STRATEGY_BASE_FEE="base_fee",g.FEE_STRATEGY_OPTIMAL="optimal",g.FEE_STRATEGY_LOW_PRIORITY="low_priority",g.FEE_STRATEGY_MIN_RELAY_FEE="min_relay_fee",g.patchQ(a("q")),b.exports=g}).call(this,a("buffer").Buffer)},{"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,assert:20,bip39:28,buffer:105,"crypto-js":185,q:293,util:360}],3:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("sjcl"),e=a("./keyderivation"),f=a("randombytes"),g={defaultSaltLen:10,tagLenBits:128,ivLenBits:128,ivLenWords:4};g.generateSalt=function(){return f(this.defaultSaltLen)},g.generateIV=function(){return f(this.ivLenBits/8)},g.encrypt=function(a,b,c){var d=this.generateSalt(),f=this.generateIV();return c="undefined"==typeof c?e.defaultIterations:c,this.encryptWithSaltAndIV(a,b,d,f,c)},g.encryptWithSaltAndIV=function(a,b,f,g,h){c(a instanceof Buffer,"pt must be provided as a buffer"),c(b instanceof Buffer,"pw must be provided as a buffer"),c(g instanceof Buffer,"IV must be provided as a buffer"),c(f instanceof Buffer,"saltBuff must be provided as a buffer"),c(16===g.length,"IV must be exactly 16 bytes");var i=new Buffer(1),j=f,k=new Buffer(4);i.writeUInt8(f.length),k.writeUInt32LE(h);var l=i.toString("hex")+j.toString("hex")+k.toString("hex"),m=d.codec.hex.toBits(e.compute(b,f,h).toString("hex")),n=d.mode.gcm.encrypt(new d.cipher.aes(m),d.codec.hex.toBits(a.toString("hex")),d.codec.hex.toBits(g.toString("hex")),d.codec.hex.toBits(l),this.tagLenBits);return new Buffer([l,g.toString("hex"),d.codec.hex.fromBits(n)].join(""),"hex")},g.decrypt=function(a,b){c(a instanceof Buffer,"cipherText must be provided as a Buffer"),c(b instanceof Buffer,"password must be provided as a Buffer");var f=new Buffer(a,"hex"),g=0,h=f.readUInt8(g);g+=1;var i=f.slice(1,g+h);g+=h;var j=f.readUInt32LE(g);g+=4;var k=f.slice(0,g),l=f.slice(g,16+g);g+=16;var m=f.slice(g),n=e.compute(b,i,j),o=d.mode.gcm.decrypt(new d.cipher.aes(d.codec.hex.toBits(n.toString("hex"))),d.codec.hex.toBits(m.toString("hex")),d.codec.hex.toBits(l.toString("hex")),d.codec.hex.toBits(k.toString("hex")),this.tagLenBits);return new Buffer(d.codec.hex.fromBits(o),"hex")},b.exports=g}).call(this,a("buffer").Buffer)},{"./keyderivation":5,assert:20,buffer:105,randombytes:297,sjcl:343}],4:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bip39");String.prototype.repeat||(String.prototype.repeat=function(a){"use strict";if(null===this)throw new TypeError("can't convert "+this+" to object");var b=""+this;if(a=+a,a!==a&&(a=0),a<0)throw new RangeError("repeat count must be non-negative");if(a===1/0)throw new RangeError("repeat count must be less than infinity");if(a=Math.floor(a),0===b.length||0===a)return"";if(b.length*a>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");for(var c="";1===(1&a)&&(c+=b),a>>>=1,0!==a;)b+=b;return c});var e={chunkSize:4,paddingDummy:129},f=function(a){if(a[0]>128)throw new Error("Mnemonic sanity check - first byte can never be above 0x80");return e.paddingDummy.toString(16).repeat(e.chunkSize-a.length%e.chunkSize)};e.encode=function(a){c(a instanceof Buffer,"Data must be provided as a Buffer");var b=f(a),e=d.entropyToMnemonic(b+a.toString("hex"));try{d.mnemonicToEntropy(e)}catch(a){throw new Error("BIP39 library produced an invalid mnemonic")}return e},e.decode=function(a){c("string"==typeof a,"Mnemonic must be provided as a string");for(var b=new Buffer(d.mnemonicToEntropy(a),"hex"),e=0;b[e]===this.paddingDummy;)e++;var g=b.slice(e,b.length);if(f(g)!==b.slice(0,e).toString("hex"))throw new Error("There is only one way to pad a string");return g},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,
2
bip39:28,buffer:105}],5:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("./pbkdf2_sha512"),e={defaultIterations:35e3,subkeyIterations:1,keySizeBits:256};e.compute=function(a,b,e){if(e=e||this.defaultIterations,c(a instanceof Buffer,"Password must be provided as a Buffer"),c(b instanceof Buffer,"Salt must be provided as a Buffer"),c(b.length>0,"Salt must not be empty"),c("number"==typeof e,"Iterations must be a number"),c(e>0,"Iteration count should be at least 1"),b.length>128)throw new Error("Sanity check: Invalid salt, length can never be greater than 128");return d.digest(a,b,e,this.keySizeBits/8)},b.exports=e}).call(this,a("buffer").Buffer)},{"./pbkdf2_sha512":6,assert:20,buffer:105}],6:[function(a,b,c){(function(Buffer){var c=a("../vendor/asmcrypto.js/asmcrypto.js"),d=function(a,b,d,e){return new Buffer(new c.PBKDF2_HMAC_SHA512.bytes(a,b,d,e).buffer)};b.exports={digest:d}}).call(this,a("buffer").Buffer)},{"../vendor/asmcrypto.js/asmcrypto.js":365,buffer:105}],7:[function(a,b,c){b.exports=c={VERSION:"3.5.3"}},{}],8:[function(a,b,c){(function(c){function d(a){var b=this;b.https=a.https,b.host=a.host,b.endpoint=a.endpoint,b.auth=a.auth,b.port=a.port,b.apiKey=a.apiKey,b.apiSecret=a.apiSecret,b.contentMd5="undefined"==typeof a.contentMd5||a.contentMd5,b.params=f.defaults({},a.params),b.headers=f.defaults({},a.headers)}var e=a("./blocktrail"),f=a("lodash"),g=a("url"),h=a("querystring"),i=a("q"),j=a("create-hash"),k=a("superagent"),l=a("superagent-http-signature/index-hmac-only"),m=a("debug")("blocktrail-sdk:request"),n=!c.browser,o=function(){};d.qs=function(a){var b=[],c=Object.keys(a);return c.sort(),c.forEach(function(c){var d={};d[c]=a[c],b.push(h.stringify(d))}),b.join("&")},d.prototype.request=function(a,b,c,e,h){var k=this;k.deferred=i.defer(),k.callback=h||o;var l=g.parse(b,!0),p=d.qs(f.defaults({},c||{},l.query||{},k.params||{}));k.path="".concat(k.endpoint,l.pathname),p&&(k.path=k.path.concat("?",p)),e?(k.payload=JSON.stringify(e),k.headers["Content-Type"]="application/json"):k.payload="",n&&(k.headers["Content-Length"]=k.payload?k.payload.length:0),k.contentMd5===!0&&("GET"===a||"DELETE"===a?k.headers["Content-MD5"]=j("md5").update(k.path).digest().toString("hex"):k.headers["Content-MD5"]=j("md5").update(k.payload).digest().toString("hex")),m("%s %s %s",a,k.host,k.path);var q={hostname:k.host,path:k.path,port:k.port,method:a,headers:k.headers,auth:k.auth,agent:!1,withCredentials:!1};return k.performRequest(q),k.deferred.promise},d.prototype.performRequest=function(a){var b=this,c=a.method,e=!1;"http-signature"===a.auth&&(e=!0,delete a.auth);var g=(b.https?"https://":"http://")+a.hostname+a.path,h=k(c,g);if(!b.payload||"DELETE"!==c&&"POST"!==c&&"PUT"!==c&&"PATCH"!==c||h.send(b.payload),f.forEach(a.headers,function(a,b){h.set(b,a)}),e){if(!b.apiSecret){var i=new Error("Missing apiSecret! required to sign POST requests!");return b.deferred.reject(i),b.callback(i)}h.use(l({headers:["(request-target)","content-md5"],algorithm:"hmac-sha256",key:b.apiSecret,keyId:b.apiKey}))}return h.end(function(a,c){var e;if(a)return b.deferred.reject(a),b.callback(a);if(m("response status code: %s content type: %s",c.status,c.headers["content-type"]),!a&&c.headers["content-type"].indexOf("application/json")>=0)try{e=JSON.parse(c.text)}catch(b){a=b}return a||200===c.status||(a=d.handleFailure(c.text,c.statusCode)),a?b.deferred.reject(a):b.deferred.resolve(e),b.callback(a,e)}),b.deferred},d.handleFailure=function(a,b){var c,e;if("object"==typeof a)c=a;else try{c=JSON.parse(a)}catch(a){}return c?(e=new Error(c.msg?c.msg:null),Object.keys(c).forEach(function(a){"msg"!==a&&(e[a]=c[a])})):e=a?new Error(a):new Error("Unknown Server Error"),b&&(e.statusCode=b),d.convertError(e)},d.convertError=function(a){return a.requires_2fa?new e.WalletMissing2FAError:a.message.match(/Invalid two_factor_token/)?new e.WalletInvalid2FAError:a},b.exports=d}).call(this,a("_process"))},{"./blocktrail":2,_process:263,"create-hash":128,debug:211,lodash:249,q:293,querystring:296,superagent:349,"superagent-http-signature/index-hmac-only":346,url:355}],9:[function(a,b,c){var d=a("lodash"),e=a("./request"),f=function(b){var c=this;c.apiKey=b.apiKey,c.apiSecret=b.apiSecret,c.https=b.https,c.host=b.host,c.port=b.port,c.endpoint=b.endpoint,c.defaultParams={},c.apiKey&&(c.defaultParams.api_key=c.apiKey),c.defaultHeaders=d.defaults({},{"X-SDK-Version":"blocktrail-sdk-nodejs/"+a("./pkginfo").VERSION},b.defaultHeaders)};f.prototype.create_request=function(a){var b=this;return a=d.defaults({},a,{https:b.https,host:b.host,port:b.port,endpoint:b.endpoint,apiKey:b.apiKey,apiSecret:b.apiSecret,params:d.defaults({},b.defaultParams),headers:d.defaults({},b.defaultHeaders)}),new e(a)},f.prototype.post=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("POST",a,b,c,d)},f.prototype.put=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("PUT",a,b,c,d)},f.prototype.get=function(a,b,c,d){"function"==typeof c&&(d=c,c=!1);var e={};return c&&(e.auth="http-signature"),this.create_request(e).request("GET",a,b,null,d)},f.prototype.delete=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("DELETE",a,b,c,d)},b.exports=function(a){return new f(a)}},{"./pkginfo":7,"./request":8,lodash:249}],10:[function(a,b,c){var d=a("../api_client"),e=a("lodash"),f=a("q"),g=a("async"),h=function(a){this.defaultSettings={apiKey:null,apiSecret:null,network:"BTC",testnet:!1,apiVersion:"v1",apiEndpoint:null,retryLimit:5,retryDelay:20,paginationLimit:200},this.settings=e.merge({},this.defaultSettings,a);var b=this.normaliseNetwork(this.settings.network,this.settings.testnet);this.settings.network=b.network,this.settings.testnet=b.testnet,this.client=new d(this.settings)};h.prototype.normaliseNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?{network:"BTC",testnet:!0}:{network:"BTC",testnet:!1};case"tbtc":case"bitcoin-testnet":return{network:"BTC",testnet:!0};case"bcc":return b?{network:"BCC",testnet:!0}:{network:"BCC",testnet:!1};case"tbcc":return{network:"BCC",testnet:!0};default:throw new Error("Unknown network "+a)}},h.prototype.setPaginationLimit=function(a){this.settings.paginationLimit=a},h.prototype.estimateFee=function(){var a=this;return a.client.feePerKB().then(function(a){return Math.max(a.optimal,a.min_relay_fee)})},h.prototype.getBatchUnspentOutputs=function(a){var b=this,c=f.defer(),d=1,e=null,h=[];return g.doWhilst(function(c){var e={page:d,limit:b.settings.paginationLimit};b.client.batchAddressUnspentOutputs(a,e).then(function(a){h=h.concat(a.data),d++,c()},function(a){console.log("error happened:",a),c(a)})},function(){return e&&e.data.length>0},function(a){a&&console.log("complete, but with errors",a.message);var b={};h.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.hash,index:a.index,value:a.value,script_hex:a.script_hex})}),c.resolve(b)}),c.promise},h.prototype.batchAddressHasTransactions=function(a){var b=this;return b.client.batchAddressHasTransactions(a).then(function(a){return a.has_transactions})},b.exports=h},{"../api_client":1,async:21,lodash:249,q:293}],11:[function(a,b,c){var d=a("../blocktrail"),e=a("superagent"),f=a("lodash"),g=a("q"),h="https://insight.bitpay.com/api",i="https://test-insight.bitpay.com/api",j=function(a){this.defaultSettings={host:h,testnet:!1,retryLimit:5,retryDelay:20},"undefined"==typeof a.host&&a.testnet&&(this.defaultSettings.host=i),this.settings=f.merge({},this.defaultSettings,a),this.DEFAULT_ENDPOINT_MAINNET=h,this.DEFAULT_ENDPOINT_TESTNET=i};j.prototype.getBatchUnspentOutputs=function(a){var b=this,c=g.defer(),e={addrs:a.join(",")};return b.postEndpoint("addrs/utxo",e).then(function(a){var b={};a.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.txid,index:a.vout,value:d.toSatoshi(a.amount),script_hex:a.scriptPubKey})}),c.resolve(b)},function(a){c.reject(a)}),c.promise},j.prototype.batchAddressHasTransactions=function(a){var b=this,c={addrs:a.join(",")};return b.postEndpoint("addrs/txs",c).then(function(a){return a.items.length>0})},j.prototype.estimateFee=function(){var a=this,b="4";return a.getEndpoint("utils/estimatefee?nbBlocks="+b).then(function(a){return a[b]===-1?1e5:parseInt(1e8*a[b],10)})},j.prototype.sendTx=function(a){return this.postEndpoint("tx/send",{rawtx:a})},j.prototype.getEndpoint=function(a){return this.getRequest(this.settings.host+"/"+a)},j.prototype.postEndpoint=function(a,b){return this.postRequest(this.settings.host+"/"+a,b)},j.prototype.getRequest=function(a){var b=g.defer();return e.get(a).end(function(a,c){if(a)return void b.reject(a);if(!c.ok)return b.reject(c.text);if(!(c.headers["content-type"].indexOf("application/json")>=0))return b.resolve(c.body);try{var d=JSON.parse(c.text);return b.resolve(d)}catch(c){return b.reject(a)}}),b.promise},j.prototype.postRequest=function(a,b){var c=g.defer();return e.post(a).send(b).set("Content-Type","application/json").end(function(a,b){if(a)return void c.reject(a);if(!b.ok)return c.reject(b.text);if(!(b.headers["content-type"].indexOf("application/json")>=0))return c.resolve(b.body);try{var d=JSON.parse(b.text);return c.resolve(d)}catch(b){return c.reject(a)}}),c.promise},b.exports=j},{"../blocktrail":2,lodash:249,q:293,superagent:349}],12:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bitcoinjs-lib"),e={SIZE_DER_SIGNATURE:72,SIZE_V0_P2WSH:36};e.getPublicKeySize=function(a){return a?33:65},e.getLengthForScriptPush=function(a){if(a<75)return 1;if(a<=255)return 2;if(a<=65535)return 3;if(a<=4294967295)return 5;throw new Error("Size of pushdata too large")},e.getLengthForVarInt=function(a){if(a<253)return 1;var b;if(a<65535)b=2;else if(a<4294967295)b=4;else{if(!(a<0x10000000000000000))throw new Error("Size of varint too large");b=8}return 1+b},e.estimateMultisigStackSize=function(a,b){var c,d=[0];for(c=0;c<a;c++)d.push(e.SIZE_DER_SIGNATURE);var f=1;for(c=0;c<b.length;c++)f+=this.getLengthForScriptPush(b[c].length)+b[c].length;return f+=2,[d,f]},e.estimateP2PKStackSize=function(a){var b=[e.SIZE_DER_SIGNATURE],c=this.getLengthForScriptPush(a.length)+a.length+1;return[b,c]},e.estimateP2PKHStackSize=function(a){"undefined"==typeof a&&(a=!0);var b=[this.SIZE_DER_SIGNATURE,this.getPublicKeySize(a)],c=2+this.getLengthForScriptPush(20)+20+2;return[b,c]},e.estimateStackSignatureSize=function(a,b,d,e){c(null===e||b);var f=[],g=[];b?(g=a,e instanceof Buffer&&g.push(e.length)):f=a,d instanceof Buffer&&f.push(d.length);var h=this,i=0;f.map(function(a){i+=h.getLengthForScriptPush(a)+a}),i+=h.getLengthForVarInt(i);var j=0;return g.length>0&&(g.map(function(a){j+=h.getLengthForVarInt(a)+a}),j+=h.getLengthForVarInt(g.length)),[i,j]},e.estimateInputFromScripts=function(a,b,e,f,g){c(null===e||f);var h;if(d.script.multisig.output.check(a)){var i=d.script.multisig.output.decode(a);h=this.estimateMultisigStackSize(i.m,i.pubKeys)[0]}else if(d.script.pubKey.output.check(a)){var j=d.script.pubKey.output.decode(a);h=this.estimateP2PKStackSize(j)[0]}else{if(!d.script.pubKeyHash.output.check(a))throw new Error("Unsupported script type");h=this.estimateP2PKHStackSize(g)[0]}return this.estimateStackSignatureSize(h,f,b,e)},e.estimateUtxo=function(a,b){var c=Buffer.from(a.scriptpubkey_hex,"hex"),e="string"==typeof a.redeem_script?Buffer.from(a.redeem_script,"hex"):null,f="string"==typeof a.witness_script?Buffer.from(a.witness_script,"hex"):null,g=!1,h=c;if(d.script.scriptHash.output.check(h)){if(null===e)throw new Error("Cant estimate, missing redeem script");h=e}if(d.script.witnessPubKeyHash.output.check(h)){var i=d.script.witnessPubKeyHash.output.decode(h);h=d.script.pubKeyHash.output.encode(i),g=!0}else if(d.script.witnessScriptHash.output.check(h)){if(null===f)throw new Error("Can't estimate, missing witness script");h=f,g=!0}var j=d.script.types,k=[j.MULTISIG,j.P2PKH,j.P2PK],l=d.script.classifyOutput(h);if(k.indexOf(l)===-1)throw new Error("Unsupported script type");var m=this.estimateInputFromScripts(h,e,f,g,b);return{scriptSig:m[0],witness:m[1]}},e.estimateInputsSize=function(a,b){var c=0,d=0;return a.map(function(a){var f=e.estimateUtxo(a);c+=40+f.scriptSig,b&&(d+=f.witness)}),b&&d>0&&(c+=2+d),c},e.calculateOutputsSize=function(a){var b=0;return a.map(function(a){var c=e.getLengthForVarInt(a.script.length);b+=8+c+a.script.length}),b},e.estimateTxWeight=function(a,b){var c=e.calculateOutputsSize(a.outs),d=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!1)+e.getLengthForVarInt(a.outs.length)+c+4,f=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!0)+e.getLengthForVarInt(a.outs.length)+c+4;return 3*d+f},e.estimateTxVsize=function(a,b){return parseInt(Math.ceil(e.estimateTxWeight(a,b)/4),10)},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,"bitcoinjs-lib":43,buffer:105}],13:[function(a,b,c){var d=a("lodash"),e=a("q"),f=a("async"),g=function(a,b){this.defaultSettings={logging:!1,batchChunkSize:200},this.settings=d.merge({},this.defaultSettings,b),this.client=a};g.prototype.getUTXOs=function(a){var b=this,c={},g=e.defer();return f.eachSeries(d.chunk(a,b.settings.batchChunkSize),function(a,e){b.settings.logging&&console.log("checking batch of "+a.length+" addresses for UTXOs",a.join(",")),b.client.getBatchUnspentOutputs(a).done(function(a){d.each(a,function(a,b){a.length>0&&(c[b]=a)}),e()},function(a){e(a)})},function(a){a&&console.log("error encountered",a),g.resolve(c)}),g.promise},b.exports=g},{async:21,lodash:249,q:293}],14:[function(a,b,c){(function(a){var d=!a.browser,e=!d&&"undefined"!=typeof window&&"undefined"!=typeof window.Worker,f=("undefined"!=typeof navigator&&navigator.userAgent||"").match(/Android (\d)\.(\d)(\.(\d))/);f&&f[1]<=4&&(e=!1),b.exports=c=function(){return e}}).call(this,a("_process"))},{_process:263}],15:[function(a,b,c){(function(Buffer){var c=a("lodash"),d=a("assert"),e=a("q"),f=a("async"),g=a("bitcoinjs-lib"),h=a("bitcoinjs-message"),i=a("./blocktrail"),j=a("crypto-js"),k=a("./encryption"),l=a("./encryption_mnemonic"),m=a("./size_estimation"),n=a("bip39"),o={SIGN:"sign",DONT_SIGN:"dont_sign"},p=function(a,b,e,f,h,i,j,k,l,m,n,o,q,r,s,t){var u=this;u.sdk=a,u.identifier=b,u.walletVersion=e,u.locked=!0,u.bypassNewAddressCheck=!!t,u.bitcoinCash=u.sdk.bitcoinCash,d(0===o||!u.bitcoinCash),u.testnet=q,u.bitcoinCash?u.testnet?u.network=g.networks.bitcoincashtestnet:u.network=g.networks.bitcoincash:u.testnet?u.network=g.networks.testnet:u.network=g.networks.bitcoin,d(k instanceof g.HDNode),d(c.every(j,function(a){return a instanceof g.HDNode})),d(c.every(l,function(a){return a instanceof g.HDNode})),u.primaryMnemonic=f,u.encryptedPrimarySeed=h,u.encryptedSecret=i,u.primaryPrivateKey=null,u.backupPrivateKey=null,u.backupPublicKey=k,u.blocktrailPublicKeys=l,u.primaryPublicKeys=j,u.keyIndex=m;var v;v=u.bitcoinCash?p.CHAIN_BCC_DEFAULT:o?p.CHAIN_BTC_SEGWIT:p.CHAIN_BTC_DEFAULT,u.chain=v,u.checksum=r,u.upgradeToKeyIndex=s,u.secret=null,u.seedHex=null};p.WALLET_VERSION_V1="v1",p.WALLET_VERSION_V2="v2",p.WALLET_VERSION_V3="v3",p.WALLET_ENTROPY_BITS=256,p.OP_RETURN="opreturn",p.DATA=p.OP_RETURN,p.PAY_PROGRESS_START=0,p.PAY_PROGRESS_COIN_SELECTION=10,p.PAY_PROGRESS_CHANGE_ADDRESS=20,p.PAY_PROGRESS_SIGN=30,p.PAY_PROGRESS_SEND=40,p.PAY_PROGRESS_DONE=100,p.CHAIN_BTC_DEFAULT=0,p.CHAIN_BTC_SEGWIT=2,p.CHAIN_BCC_DEFAULT=1,p.FEE_STRATEGY_FORCE_FEE=i.FEE_STRATEGY_FORCE_FEE,p.FEE_STRATEGY_BASE_FEE=i.FEE_STRATEGY_BASE_FEE,p.FEE_STRATEGY_OPTIMAL=i.FEE_STRATEGY_OPTIMAL,p.FEE_STRATEGY_LOW_PRIORITY=i.FEE_STRATEGY_LOW_PRIORITY,p.FEE_STRATEGY_MIN_RELAY_FEE=i.FEE_STRATEGY_MIN_RELAY_FEE,p.prototype.isSegwit=function(){return p.CHAIN_BTC_SEGWIT===this.chain},p.prototype.unlock=function(a,b){var d=this,f=e.defer();return f.promise.nodeify(b),a=c.merge({},a),e.fcall(function(){switch(d.walletVersion){case p.WALLET_VERSION_V1:return d.unlockV1(a);case p.WALLET_VERSION_V2:return d.unlockV2(a);case p.WALLET_VERSION_V3:return d.unlockV3(a);default:return e.reject(new i.WalletInitError("Invalid wallet version"))}}).then(function(a){d.primaryPrivateKey=a;var b=d.primaryPrivateKey.getAddress();if(b!==d.checksum)throw new i.WalletChecksumError("Generated checksum ["+b+"] does not match ["+d.checksum+"], most likely due to incorrect password");if(d.locked=!1,"undefined"!=typeof d.upgradeToKeyIndex&&null!==d.upgradeToKeyIndex)return d.upgradeKeyIndex(d.upgradeToKeyIndex)}).then(function(a){f.resolve(a)},function(a){f.reject(a)}),f.promise},p.prototype.unlockV1=function(a){var b=this;return a.primaryMnemonic="undefined"!=typeof a.primaryMnemonic?a.primaryMnemonic:b.primaryMnemonic,a.secretMnemonic="undefined"!=typeof a.secretMnemonic?a.secretMnemonic:b.secretMnemonic,b.sdk.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return b.primarySeed=a.primarySeed,a.primaryPrivateKey})},p.prototype.unlockV2=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletDecryptError("specifying primaryPrivateKey has been deprecated");if(a.primarySeed)c.primarySeed=a.primarySeed;else if(a.secret)try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}else{if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");a.passphrase=a.passphrase||a.password;try{if(c.secret=j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedSecret),a.passphrase).toString(j.enc.Utf8),!c.secret.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt secret")}try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}}return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})),d.promise},p.prototype.unlockV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){return e.when().then(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletInitError("specifying primaryPrivateKey has been deprecated");if(!a.primarySeed){if(a.secret)return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")});if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");return a.passphrase=a.passphrase||a.password,delete a.password,c.sdk.promisedDecrypt(new Buffer(a.encryptedSecret,"base64"),new Buffer(a.passphrase)).then(function(a){c.secret=a},function(){throw new i.WalletDecryptError("Failed to decrypt secret")}).then(function(){return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")})})}c.primarySeed=a.primarySeed}).then(function(){return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})})),d.promise},p.prototype.lock=function(){var a=this;a.secret=null,a.primarySeed=null,a.primaryPrivateKey=null,a.backupPrivateKey=null,a.locked=!0},p.prototype.upgradeToV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.when(!0).then(function(){if(c.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to upgrade");if(c.walletVersion===p.WALLET_VERSION_V3)throw new i.WalletUpgradeError("Wallet is already V3");return c.walletVersion===p.WALLET_VERSION_V2?c._upgradeV2ToV3(a,d.notify.bind(d)):c.walletVersion===p.WALLET_VERSION_V1?c._upgradeV1ToV3(a,d.notify.bind(d)):void 0}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},p.prototype._upgradeV2ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed,recoverySecret:!1};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.sdk.updateWallet(c.identifier,{encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype._upgradeV1ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.recoveryEncryptedSecret=a.recoveryEncryptedSecret,c.sdk.updateWallet(c.identifier,{primary_mnemonic:"",encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),recovery_secret:a.recoverySecret.toString("hex"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype.doPasswordChange=function(a){var b=this;return e.when(null).then(function(){if(b.walletVersion===p.WALLET_VERSION_V1)throw new i.WalletLockedError("Wallet version does not support password change!");if(b.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to change password");if(!b.secret)throw new i.WalletLockedError("No secret");var c,d;if(b.walletVersion===p.WALLET_VERSION_V2)c=j.AES.encrypt(b.secret,a).toString(j.format.OpenSSL),d=n.entropyToMnemonic(i.convert(c,"base64","hex"));else{if("string"==typeof a)a=new Buffer(a);else if(!(a instanceof Buffer))throw new Error("New password must be provided as a string or a Buffer");c=k.encrypt(b.secret,a),d=l.encode(c),c=c.toString("base64")}return[c,d]})},p.prototype.passwordChange=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.fcall(function(){return c.doPasswordChange(a).then(function(a){var b=a[0],d=a[1];return c.sdk.updateWallet(c.identifier,{encrypted_secret:b}).then(function(){return c.encryptedSecret=b,{encryptedSecret:d}})}).then(function(a){d.resolve(a)},function(a){d.reject(a)})}),d.promise},p.prototype.getAddressByPath=function(a){return this.getWalletScriptByPath(a).address},p.prototype.getRedeemScriptByPath=function(a){return this.getWalletScriptByPath(a).redeemScript},p.prototype.getWalletScriptByPath=function(a){var b,c,d=this,e=d.getPrimaryPublicKey(a),f=d.getBlocktrailPublicKey(a),h=p.deriveByPath(d.backupPublicKey,a.replace("'",""),"M"),i=p.sortMultiSigKeys([e.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),f.keyPair.getPublicKeyBuffer()]),j=g.script.multisig.output.encode(2,i),k=parseInt(a.split("/")[2]);"bitcoincash"!==this.network&&k===p.CHAIN_BTC_SEGWIT?(b=j,c=g.script.witnessScriptHash.output.encode(g.crypto.sha256(b))):(b=null,c=j);var l=g.script.scriptHash.output.encode(g.crypto.hash160(c)),m=g.address.fromOutputScript(l,this.network);return{witnessScript:b,redeemScript:c,scriptPubKey:l,address:m}},p.prototype.getPrimaryPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.primaryPublicKeys[c]){if(!b.primaryPrivateKey)throw new i.KeyPathError("Wallet.getPrimaryPublicKey keyIndex ("+c+") is unknown to us");b.primaryPublicKeys[c]=p.deriveByPath(b.primaryPrivateKey,"M/"+c+"'","m")}var d=b.primaryPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.getBlocktrailPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.blocktrailPublicKeys[c])throw new i.KeyPathError("Wallet.getBlocktrailPublicKey keyIndex ("+c+") is unknown to us");var d=b.blocktrailPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.upgradeKeyIndex=function(a,b){var d=this,f=e.defer();if(f.promise.nodeify(b),d.locked)return f.reject(new i.WalletLockedError("Wallet needs to be unlocked to upgrade key index")),f.promise;var h=d.primaryPrivateKey.deriveHardened(a).neutered();return f.resolve(d.sdk.upgradeKeyIndex(d.identifier,a,[h.toBase58(),"M/"+a+"'"]).then(function(b){return d.keyIndex=a,c.forEach(b.blocktrail_public_keys,function(a,b){d.blocktrailPublicKeys[b]=g.HDNode.fromBase58(a[0],d.network)}),d.primaryPublicKeys[a]=h,!0})),f.promise},p.prototype.getNewAddress=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getNewDerivation(b.identifier,"M/"+b.keyIndex+"'/"+b.chain).then(function(a){var c=a.path,d=a.address;if(!b.bypassNewAddressCheck&&(d=b.getAddressByPath(a.path),d!==a.address))throw new i.WalletAddressError("Failed to verify address ["+a.address+"] !== ["+d+"]");return[d,c]})),c.promise},p.prototype.getBalance=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier).then(function(a){return[a.confirmed,a.unconfirmed]})),c.promise},p.prototype.getInfo=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier)),c.promise},p.prototype.doDiscovery=function(a,b){var c=this;"function"==typeof a&&(b=a,a=null);var d=e.defer();return d.promise.spreadNodeify(b),d.resolve(c.sdk.doWalletDiscovery(c.identifier,a).then(function(a){return[a.confirmed,a.unconfirmed]})),d.promise},p.prototype.deleteWallet=function(a,b){var c=this;"function"==typeof a&&(b=a,a=!1);var d=e.defer();if(d.promise.nodeify(b),c.locked)return d.reject(new i.WalletDeleteError("Wallet needs to be unlocked to delete wallet")),d.promise;var f=c.primaryPrivateKey.getAddress(),g=c.primaryPrivateKey.keyPair.d.toBuffer(32),j=h.sign(f,c.network.messagePrefix,g,!0).toString("base64");return d.resolve(c.sdk.deleteWallet(c.identifier,f,j,a).then(function(a){return a.deleted})),d.promise},p.prototype.pay=function(a,b,c,d,f,g,h,j){var k=this;"function"==typeof b?(j=b,b=null):"function"==typeof c?(j=c,c=!1):"function"==typeof d?(j=d,d=!0):"function"==typeof f?(j=f,f=null):"function"==typeof g?(j=g,g=null):"function"==typeof h&&(j=h,h={}),d="undefined"==typeof d||d,f=f||p.FEE_STRATEGY_OPTIMAL,h=h||{};var l="undefined"==typeof h.checkFee||h.checkFee,m=e.defer();return m.promise.nodeify(j),k.locked?(m.reject(new i.WalletLockedError("Wallet needs to be unlocked to send coins")),m.promise):(e.nextTick(function(){m.notify(p.PAY_PROGRESS_START),k.buildTransaction(a,b,c,d,f,h).then(function(a){return a},function(a){m.reject(a)},function(a){m.notify(a)}).spread(function(a,b){m.notify(p.PAY_PROGRESS_SEND);var c={signed_transaction:a.toHex(),base_transaction:a.__toBuffer(null,null,!1).toString("hex")};return k.sendTransaction(c,b.map(function(a){return a.path}),l,g,h.prioboost).then(function(a){return m.notify(p.PAY_PROGRESS_DONE),a&&a.complete&&"false"!==a.complete?a.txid:void m.reject(new i.TransactionSignError("Failed to completely sign transaction"))})},function(a){throw a}).then(function(a){m.resolve(a)},function(a){m.reject(a)})}),m.promise)},p.prototype.decodeAddress=function(a){return p.getAddressAndType(a,this.network)},p.getAddressAndType=function(a,b){var c,d,e;if(b===g.networks.bitcoin||b===g.networks.testnet){try{c=g.address.fromBech32(a,b),e=null,d="bech32"}catch(a){e=a}if(!e&&c.prefix!==b.bech32)throw new i.InvalidAddressError("Address invalid on this network")}if(!c){try{c=g.address.fromBase58Check(a),e=null,d="base58"}catch(a){e=a}if(!e&&c.version!==b.pubKeyHash&&c.version!==b.scriptHash)throw new i.InvalidAddressError("Address invalid on this network")}if(e)throw new i.InvalidAddressError(e.message);return{address:a,decoded:c,type:d}},p.convertPayToOutputs=function(a,b){var c,d=[];if(Array.isArray(a))c=function(a,b,c){if("object"!=typeof b)throw new Error("Invalid transaction output for numerically indexed list [1]");var d=Object.keys(b);if(d.indexOf("scriptPubKey")!==-1&&d.indexOf("value")!==-1)c.scriptPubKey=b.scriptPubKey,c.value=b.value;else if(d.indexOf("address")!==-1&&d.indexOf("value")!==-1)c.address=b.address,c.value=b.value;else{if(2===d.length||2===b.length||0===d[0]||1===d[1])throw new Error("Invalid transaction output for numerically indexed list [2]");c.address=b[0],c.value=b[1]}};else{if("object"!=typeof a)throw new Error("Invalid input");c=function(a,b,c){if(c.address=a.trim(),c.value=b,c.address===p.OP_RETURN){var d=Buffer.isBuffer(b)?b:new Buffer(b,"utf-8");c.scriptPubKey=g.script.nullData.output.encode(d).toString("hex"),c.value=0,c.address=null}}}return Object.keys(a).forEach(function(e){var f={};if(c(e,a[e],f),parseInt(f.value,10).toString()!==f.value.toString())throw new i.WalletSendError("Values should be in Satoshis");if("string"==typeof f.address)try{var h=p.getAddressAndType(f.address,b);f.scriptPubKey=g.address.toOutputScript(h.address,b).toString("hex"),delete f.address}catch(a){throw new i.InvalidAddressError("Invalid address ["+f.address+"] ("+a.message+")")}if("6a"!==f.scriptPubKey.slice(0,2)){if(!(f.value=parseInt(f.value,10)))throw new i.WalletSendError("Values should be non zero");if(f.value<=i.DUST)throw new i.WalletSendError("Values should be more than dust ("+i.DUST+")")}f.value=parseInt(f.value,10),d.push(f)}),d},p.prototype.buildTransaction=function(a,b,d,h,j,k,l){var m=this;"function"==typeof b?(l=b,b=null):"function"==typeof d?(l=d,d=!1):"function"==typeof h?(l=h,h=!0):"function"==typeof j?(l=j,j=null):"function"==typeof k&&(l=k,k={}),h="undefined"==typeof h||h,j=j||p.FEE_STRATEGY_OPTIMAL,k=k||{};var n=e.defer();return n.promise.spreadNodeify(l),e.nextTick(function(){var l;try{l=p.convertPayToOutputs(a,m.network)}catch(a){return n.reject(a),n.promise}return l.length?(n.notify(p.PAY_PROGRESS_COIN_SELECTION),void n.resolve(m.coinSelection(l,!0,d,j,k).spread(function(a,d,k){var n,q,r=[],s=e.defer();return f.waterfall([function(b){var c=a.map(function(a){return a.value}).reduce(function(a,b){return a+b}),e=l.map(function(a){return a.value}).reduce(function(a,b){return a+b}),f=c-e-d;return f>2*i.DUST&&f!==k?b(new i.WalletFeeError("the amount of change ("+k+") suggested by the coin selection seems incorrect ("+f+")")):void b()},function(a){q=new g.TransactionBuilder(m.network),m.bitcoinCash&&q.enableBitcoinCash(),a()},function(b){var c;for(c=0;c<a.length;c++)q.addInput(a[c].hash,a[c].idx);b()},function(a){l.forEach(function(a){if(a.address)r.push({address:a.address,value:a.value});else{if(!a.scriptPubKey)throw new Error("Invalid send");r.push({scriptPubKey:new Buffer(a.scriptPubKey,"hex"),value:a.value})}}),a()},function(a){if(k>0)if(k<=i.DUST)k=0;else if(!b)return s.notify(p.PAY_PROGRESS_CHANGE_ADDRESS),m.getNewAddress(function(c,d){return c?a(c):(b=d,void a())});a()},function(a){k>0&&(h?r.splice(c.random(0,r.length),0,{address:b,value:k}):r.push({address:b,value:k})),a()},function(a){r.forEach(function(a){q.addOutput(a.scriptPubKey||a.address,a.value)}),a()},function(b){var c,d,e,f,h;for(s.notify(p.PAY_PROGRESS_SIGN),c=0;c<a.length;c++){var i=o.SIGN;if(a[c].sign_mode&&(i=a[c].sign_mode),f=null,h=null,i===o.SIGN){if(e=a[c].path.replace("M","m"),m.primaryPrivateKey)d=p.deriveByPath(m.primaryPrivateKey,e,"m").keyPair;else{if(!m.backupPrivateKey)throw new Error("No master privateKey present");d=p.deriveByPath(m.backupPrivateKey,e.replace(/^m\/(\d+)\'/,"m/$1"),"m").keyPair}f=new Buffer(a[c].redeem_script,"hex"),"string"==typeof a[c].witness_script&&(h=new Buffer(a[c].witness_script,"hex"));var j=g.Transaction.SIGHASH_ALL;
3
m.bitcoinCash&&(j|=g.Transaction.SIGHASH_BITCOINCASHBIP143),q.sign(c,d,f,j,a[c].value,h)}}n=q.buildIncomplete(),b()},function(b){var c=p.estimateVsizeFee(n,a);if(m.sdk.feeSanityCheck)switch(j){case p.FEE_STRATEGY_BASE_FEE:if(Math.abs(c-d)>i.BASE_FEE)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems incorrect ("+c+") for FEE_STRATEGY_BASE_FEE"));break;case p.FEE_STRATEGY_OPTIMAL:if(d>c*m.feeSanityCheckBaseFeeMultiplier)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems awefully high ("+c+") for FEE_STRATEGY_OPTIMAL"))}b()}],function(b){return b?void s.reject(new i.WalletSendError(b)):void s.resolve([n,a])}),s.promise}))):(n.reject(new i.WalletSendError("Need at least one recipient")),n.promise)}),n.promise},p.prototype.coinSelection=function(a,b,c,d,f,g){var h=this;"function"==typeof b?(g=b,b=!0):"function"==typeof c?(g=c,c=!1):"function"==typeof d?(g=d,d=null):"function"==typeof f&&(g=f,f={}),b="undefined"==typeof b||b,d=d||p.FEE_STRATEGY_OPTIMAL,f=f||{};var i;try{i=p.convertPayToOutputs(a,h.network)}catch(a){var j=e.defer();return j.promise.nodeify(g),j.reject(a),j.promise}return h.sdk.coinSelection(h.identifier,i,b,c,d,f,g)},p.prototype.sendTransaction=function(a,b,c,d,f,g){var h=this;"function"==typeof d?(g=d,d=null,f=!1):"function"==typeof f&&(g=d,f=!1);var j=e.defer();return j.promise.nodeify(g),h.sdk.sendTransaction(h.identifier,a,b,c,d,f).then(function(a){j.resolve(a)},function(a){a.requires_2fa?j.reject(new i.WalletMissing2FAError):a.message.match(/Invalid two_factor_token/)?j.reject(new i.WalletInvalid2FAError):j.reject(a)}),j.promise},p.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),b=b||"WALLET-"+d.identifier,d.sdk.setupWalletWebhook(d.identifier,b,a,c)},p.prototype.deleteWebhook=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),a=a||"WALLET-"+c.identifier,c.sdk.deleteWalletWebhook(c.identifier,a,b)},p.prototype.transactions=function(a,b){var c=this;return c.sdk.walletTransactions(c.identifier,a,b)},p.prototype.maxSpendable=function(a,b,c,d){var e=this;return"function"==typeof a?(d=a,a=!1):"function"==typeof b?(d=b,b=null):"function"==typeof c&&(d=c,c={}),"object"==typeof a?(c=a,a=!1):"object"==typeof b&&(c=b,b=null),c=c||{},"undefined"!=typeof c.allowZeroConf&&(a=c.allowZeroConf),"undefined"!=typeof c.feeStrategy&&(b=c.feeStrategy),b=b||p.FEE_STRATEGY_OPTIMAL,e.sdk.walletMaxSpendable(e.identifier,a,b,c,d)},p.prototype.addresses=function(a,b){var c=this;return c.sdk.walletAddresses(c.identifier,a,b)},p.prototype.labelAddress=function(a,b,c){var d=this;return d.sdk.labelWalletAddress(d.identifier,a,b,c)},p.prototype.utxos=function(a,b){var c=this;return c.sdk.walletUTXOs(c.identifier,a,b)},p.prototype.unspentOutputs=p.prototype.utxos,p.sortMultiSigKeys=function(a){return a.sort(function(a,b){return a.toString("hex").localeCompare(b.toString("hex"))}),a},p.estimateIncompleteTxFee=function(a,b){var c=p.estimateIncompleteTxSize(a),d=c/1e3,e=Math.ceil(c/1e3);return b?parseInt(d*b,10):parseInt(e*i.BASE_FEE,10)},p.estimateVsizeFee=function(a,b,c){var d=m.estimateTxVsize(a,b),e=d/1e3,f=Math.ceil(d/1e3);return c?parseInt(e*c,10):parseInt(f*i.BASE_FEE,10)},p.estimateIncompleteTxSize=function(a){var b=16;return b+=34*a.outs.length,a.ins.forEach(function(a){var c=a.script,d=g.script.classifyInput(c),e=[2,3];if(!e&&"scripthash"===d){var f=g.script.decompile(c),h=f.slice(-1)[0];if(c=g.script.compile(f.slice(0,-1)),d=g.script.classifyInput(c),g.script.classifyOutput(h)!==d)throw new i.TransactionInputError("Non-matching scriptSig and scriptPubKey in input");if("multisig"===d){var j=g.script.decompile(h),k=j[0];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var l=j[h.chunks.length-2];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var m=k-(g.opcodes.OP_1-1),n=l-(g.opcodes.OP_1-1);if(n<m)throw new i.TransactionInputError("Invalid multisig redeemScript");e=[m,n]}}b+=e?40+73*e[0]+107+4:147}),b},p.estimateFee=function(a,b){var c=16;c+=34*b,c+=297*a;var d=Math.ceil(c/1e3);return d*i.BASE_FEE},p.deriveByPath=function(a,b,c){if(c=c||(a.keyPair.d?"m":"M"),"m"!==b[0].toLowerCase()||"m"!==c[0].toLowerCase())throw new i.KeyPathError("Wallet.deriveByPath only works with absolute paths. ("+b+", "+c+")");if("m"===b[0]&&"M"===c[0])throw new i.KeyPathError("Wallet.deriveByPath can't derive private path from public parent. ("+b+", "+c+")");var d="M"===b[0]&&"m"===c[0];if(d&&(b[0]="m"),0!==b.toLowerCase().indexOf(c.toLowerCase()))throw new i.KeyPathError("Wallet.derivePath requires path ("+b+") to be a child of keyPath ("+c+")");b=b.substr(c.length);var e=a;return b.replace(/^\//,"").split("/").forEach(function(a){a&&(a.indexOf("'")!==-1&&(a=parseInt(a.replace("'",""),10)+g.HDNode.HIGHEST_BIT),e=e.derive(parseInt(a,10)))}),d?e.neutered():e},b.exports=p}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./size_estimation":12,assert:20,async:21,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293}],16:[function(a,b,c){(function(Buffer){var c=a("./unspent_output_finder"),d=a("bitcoinjs-lib"),e=a("bip39"),f=a("crypto-js"),g=a("./blocktrail"),h=a("./encryption_mnemonic"),i=a("./encryption"),j=a("./wallet"),k=a("lodash"),l=a("q"),m=a("async"),n=function(a,b,j){var l=this;this.defaultSettings={network:"btc",testnet:!1,logging:!1,bitcoinCash:!1,sweepBatchSize:200},this.settings=k.merge({},this.defaultSettings,j),this.bitcoinDataClient=b,this.utxoFinder=new c(b,this.settings),this.sweepData=null,"object"==typeof j.network?this.network=j.network:this.network=this.getBitcoinNetwork(this.settings.network,this.settings.testnet),a.walletVersion=a.walletVersion||2;var m=!1;if(!Array.isArray(a.blocktrailKeys))throw new Error("blocktrail pub keys are required (must be type Array)");switch(a.walletVersion){case 1:if("undefined"==typeof a.primaryMnemonic||!a.primaryMnemonic)throw new Error("missing primary mnemonic for version 1 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic)throw new Error("missing backup mnemonic for version 1 wallet");if("undefined"==typeof a.primaryPassphrase)throw new Error("missing primary passphrase for version 1 wallet");a.primaryMnemonic=a.primaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=a.backupMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;case 2:case 3:if("undefined"==typeof a.encryptedPrimaryMnemonic||!a.encryptedPrimaryMnemonic)throw new Error("missing encrypted primary seed for version 2 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic&&a.backupMnemonic!==!1)throw new Error("missing backup seed for version 2 wallet");if(m="undefined"!=typeof a.password&&null!==a.password){if("undefined"==typeof a.passwordEncryptedSecretMnemonic||!a.passwordEncryptedSecretMnemonic)throw new Error("missing password encrypted secret for version 2 wallet");if("undefined"==typeof a.password)throw new Error("missing primary passphrase for version 2 wallet")}else{if("undefined"==typeof a.encryptedRecoverySecretMnemonic||!a.encryptedRecoverySecretMnemonic)throw new Error("missing encrypted recovery secret for version 2 wallet (recovery without password)");if(!a.recoverySecretDecryptionKey)throw new Error("missing recovery secret decryption key for version 2 wallet (recovery without password)")}a.encryptedPrimaryMnemonic=a.encryptedPrimaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=(a.backupMnemonic||"").trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.recoverySecretDecryptionKey&&(a.recoverySecretDecryptionKey=a.recoverySecretDecryptionKey.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ")),m?a.passwordEncryptedSecretMnemonic=a.passwordEncryptedSecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "):a.encryptedRecoverySecretMnemonic=a.encryptedRecoverySecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.blocktrailPublicKeys={},k.each(a.blocktrailKeys,function(a){l.blocktrailPublicKeys[a.keyIndex]=d.HDNode.fromBase58(a.pubkey,l.network)});var n,o,p;switch(a.walletVersion){case 1:n=e.mnemonicToSeed(a.primaryMnemonic,a.primaryPassphrase),o=e.mnemonicToSeed(a.backupMnemonic,"");break;case 2:if(a.encryptedPrimaryMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedPrimaryMnemonic),"hex","base64"),m?a.passwordEncryptedSecretMnemonic=g.convert(e.mnemonicToEntropy(a.passwordEncryptedSecretMnemonic),"hex","base64"):a.encryptedRecoverySecretMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedRecoverySecretMnemonic),"hex","base64"),p=m?f.AES.decrypt(a.passwordEncryptedSecretMnemonic,a.password).toString(f.enc.Utf8):f.AES.decrypt(a.encryptedRecoverySecretMnemonic,a.recoverySecretDecryptionKey).toString(f.enc.Utf8),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=new Buffer(f.AES.decrypt(a.encryptedPrimaryMnemonic,p).toString(f.enc.Utf8),"base64"),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;case 3:if(a.encryptedPrimaryMnemonic=h.decode(a.encryptedPrimaryMnemonic),m?a.passwordEncryptedSecretMnemonic=h.decode(a.passwordEncryptedSecretMnemonic):a.encryptedRecoverySecretMnemonic=h.decode(a.encryptedRecoverySecretMnemonic),p=m?i.decrypt(a.passwordEncryptedSecretMnemonic,new Buffer(a.password)):i.decrypt(a.encryptedRecoverySecretMnemonic,new Buffer(a.recoverySecretDecryptionKey,"hex")),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=i.decrypt(a.encryptedPrimaryMnemonic,p),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.primaryPrivateKey=d.HDNode.fromSeedBuffer(n,this.network),o?(this.backupPrivateKey=d.HDNode.fromSeedBuffer(o,this.network),this.backupPublicKey=this.backupPrivateKey.neutered()):(this.backupPrivateKey=!1,this.backupPublicKey=d.HDNode.fromBase58(a.backupPublicKey,this.network)),this.settings.logging&&(console.log("using password method: "+m),console.log("Primary Prv Key: "+this.primaryPrivateKey.toBase58()),console.log("Primary Pub Key: "+this.primaryPrivateKey.neutered().toBase58()),console.log("Backup Prv Key: "+(this.backupPrivateKey?this.backupPrivateKey.toBase58():null)),console.log("Backup Pub Key: "+this.backupPublicKey.toBase58()))};n.prototype.getBitcoinNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?d.networks.testnet:d.networks.bitcoin;case"tbtc":case"bitcoin-testnet":return d.networks.testnet;default:throw new Error("Unknown network "+a)}},n.prototype.getBlocktrailPublicKey=function(a){a=a.replace("m","M");var b=a.split("/")[1].replace("'","");if(!this.blocktrailPublicKeys[b])throw new Error("Wallet.getBlocktrailPublicKey keyIndex ("+b+") is unknown to us");return this.blocktrailPublicKeys[b]},n.prototype.createAddress=function(a){a=a.replace("m","M");var b,c,e=a.split("/")[1].replace("'",""),f=parseInt(a.split("/")[2]),g=j.deriveByPath(this.primaryPrivateKey,a,"m"),h=j.deriveByPath(this.backupPublicKey,a.replace("'",""),"M"),i=j.deriveByPath(this.getBlocktrailPublicKey(a),a,"M/"+e+"'"),k=j.sortMultiSigKeys([g.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),i.keyPair.getPublicKeyBuffer()]),l=d.script.multisig.output.encode(2,k);"bitcoincash"!==this.network&&f===j.CHAIN_BTC_SEGWIT?(c=l,b=d.script.witnessScriptHash.output.encode(d.crypto.sha256(c))):(c=null,b=l);var m=d.crypto.hash160(b),n=d.script.scriptHash.output.encode(m),o=this.network;"undefined"!=typeof this.network&&(o=this.network);var p=d.address.fromOutputScript(n,o);return{address:p.toString(),redeem:b,witness:c}},n.prototype.createBatchAddresses=function(a,b,c,d){var e=this,f={};return l.all(k.range(0,b).map(function(b){var g="M/"+c+"'/"+d+"/"+(a+b),h=e.createAddress(g);f[h.address]={redeem:h.redeem,witness:h.witness,path:g}})).then(function(){return f})},n.prototype.discoverWalletFunds=function(a,b){var c=this,d=0,e=0,f=0,g={};"undefined"==typeof a&&(a=this.settings.sweepBatchSize);var h=l.defer();h.promise.nodeify(b);var i;return i="bitcoincash"===this.network?[0,1]:[0,1,2],m.nextTick(function(){m.eachSeries(Object.keys(c.blocktrailPublicKeys),function(b,j){m.eachSeries(i,function(i,j){var n=0,o=!1;m.doWhilst(function(j){c.settings.logging&&console.log("generating addresses "+n+" -> "+(n+a)+" using blocktrail key index: "+b+", chain: "+i),h.notify({message:"generating addresses "+n+" -> "+(n+a),increment:a,btPubKeyIndex:b,chain:i,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),m.nextTick(function(){c.createBatchAddresses(n,a,b,i).then(function(i){return f+=Object.keys(i).length,c.settings.logging&&console.log("starting fund discovery for "+a+" addresses..."),h.notify({message:"starting fund discovery for "+a+" addresses",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),c.bitcoinDataClient.batchAddressHasTransactions(k.keys(i)).then(function(j){return o=j,c.settings.logging&&console.log("batch "+(o?"has":"does not have")+" transactions..."),l.when(o).then(function(j){if(j)return c.utxoFinder.getUTXOs(k.keys(i)).then(function(j){k.each(j,function(a,b){var f=null;"undefined"!=typeof i[b].witness&&(f=i[b].witness),g[b]={path:i[b].path,redeem:i[b].redeem,witness:f,utxos:a},e+=a.length,d=k.reduce(a,function(a,b){return a+b.value},d),c.settings.logging&&console.log("found "+a.length+" unspent outputs for address: "+b)}),h.notify({message:"discovering funds",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})})})})}).then(function(){n+=a,m.nextTick(j)},function(a){j(a)})})},function(){return o},function(c){c&&(console.log("batch complete, but with errors",c.message),h.notify({message:"batch complete, but with errors: "+c.message,error:c,increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})),m.nextTick(j)})},function(a){j(a)})},function(a){a&&c.settings.logging&&console.log("error encountered when discovering funds",a),c.settings.logging&&console.log("finished fund discovery: "+d+" Satoshi (in "+e+" outputs) found when searching "+f+" addresses"),c.sweepData={utxos:g,count:e,balance:d,addressesSearched:f},h.resolve(c.sweepData)})}),h.promise},n.prototype.sweepWallet=function(a,b){var c=this,d=l.defer();return d.promise.nodeify(b),c.settings.logging&&console.log("starting wallet sweeping to address "+a),l.when(!0).then(function(){if(!c.sweepData)return c.discoverWalletFunds().progress(function(a){d.notify(a)})}).then(function(){return c.bitcoinDataClient.estimateFee()}).then(function(b){return 0===c.sweepData.balance?(d.reject("No funds found after searching through "+c.sweepData.addressesSearched+" addresses"),d.promise):c.createTransaction(a,null,b,d)}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},n.prototype.createTransaction=function(a,b,c,e){var f=this;this.settings.logging&&console.log("Creating transaction to address destinationAddress"),e&&e.notify({message:"creating raw transaction to "+a});var h=new d.TransactionBuilder(this.network);this.settings.bitcoinCash&&h.enableBitcoinCash();var i=[];if(k.each(this.sweepData.utxos,function(a,b){k.each(a.utxos,function(c){h.addInput(c.hash,c.index),i.push({txid:c.hash,vout:c.index,scriptPubKey:c.script_hex,value:c.value,address:b,path:a.path,redeemScript:a.redeem,witnessScript:a.witness})})}),!h)throw new Error("Failed to create raw transaction");var l=f.sweepData.balance,m=h.addOutput(a,l);if("undefined"==typeof b||null===b){e&&e.notify({message:"estimating transaction fee, based on "+g.toBTC(c)+" BTC/kb"});var n=i.map(function(a){return{txid:a.txid,vout:a.vout,address:a.vout,scriptpubkey_hex:a.vout,redeem_script:a.redeemScript,witness_script:a.witnessScript,path:a.path,value:a.value}});b=j.estimateVsizeFee(h.tx,n,c)}return h.tx.outs[m].value-=b,e&&e.notify({message:"signing transaction"}),this.signTransaction(h,i)},n.prototype.signTransaction=function(a,b){var c=this;this.settings.logging&&console.log("Signing transaction");var e=d.Transaction.SIGHASH_ALL;return this.settings.bitcoinCash&&(e|=d.Transaction.SIGHASH_BITCOINCASHBIP143),k.each(b,function(b,d){var f=j.deriveByPath(c.primaryPrivateKey,b.path.replace("M","m"),"m").keyPair;if(a.sign(d,f,b.redeemScript,e,b.value,b.witnessScript),c.backupPrivateKey){var g=j.deriveByPath(c.backupPrivateKey,b.path.replace("'","").replace("M","m"),"m").keyPair;a.sign(d,g,b.redeemScript,e,b.value,b.witnessScript)}}),c.backupPrivateKey?a.build().toHex():a.buildIncomplete().toHex()},b.exports=n}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./unspent_output_finder":13,"./wallet":15,async:21,bip39:28,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,lodash:249,q:293}],17:[function(a,b,c){(function(Buffer){var c=a("bip39"),d=a("./encryption");b.exports=function(a){a.addEventListener("message",function(b){var e=b.data||{};switch(e.method){case"mnemonicToSeedHex":!function(){try{var d=e.mnemonic,f=e.passphrase;if(!c.validateMnemonic(d))throw b=new Error("Invalid passphrase"),b.id=e.id,b;var g=c.mnemonicToSeedHex(d,f);a.postMessage({id:e.id,seed:g,mnemonic:d})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.encryptWithSaltAndIV":!function(){try{if(!(e.pt&&e.pw&&e.saltBuf&&e.iv&&e.iterations))throw new Error("Invalid input");var b=Buffer.from(e.pt.buffer),c=Buffer.from(e.pw.buffer),f=Buffer.from(e.saltBuf.buffer),g=Buffer.from(e.iv.buffer),h=e.iterations,i=d.encryptWithSaltAndIV(b,c,f,g,h);a.postMessage({id:e.id,cipherText:i})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.decrypt":!function(){try{if(!e.ct||!e.pw)throw new Error("Invalid input");var b=Buffer.from(e.ct.buffer),c=Buffer.from(e.pw.buffer),f=d.decrypt(b,c);a.postMessage({id:e.id,plainText:f})}catch(a){throw a.id=e.id,a}}();break;default:throw b=new Error("Invalid method ["+b.method+"]"),b.id=e.id,b}},!1)}}).call(this,a("buffer").Buffer)},{"./encryption":3,bip39:28,buffer:105}],18:[function(a,b,c){var d=a("q"),e=a("webworkify");b.exports=c={workify:function(a,b,c){var f=d.defer();try{"undefined"==typeof a.worker&&(a.worker=e(b()),a.first=!0,a.id=0);var g=a.worker,h=a.id++,i=function(b){a.first&&(a.first=!1,URL.revokeObjectURL(g.objectURL)),b.data.id===h&&f.resolve(b.data)},j=function(a){f.reject(new Error(a.message.replace("Uncaught Error: ","")))},k=function(){g.removeEventListener("message",i),g.removeEventListener("error",j)};return g.addEventListener("message",i,!1),g.addEventListener("error",j,!1),c.id=h,g.postMessage(c),f.promise.then(function(a){return k(),a},function(a){throw k(),a})}catch(a){return f.reject(a),f.promise}}}},{q:293,webworkify:363}],19:[function(a,b,c){(function(Buffer){var d=a("./lib/api_client"),e=a("./lib/blocktrail");Object.keys(e).forEach(function(a){d[a]=e[a]}),d.q=a("q"),d.BlocktrailSDK=d,d.Wallet=a("./lib/wallet"),d.Request=a("./lib/request"),d.Encryption=a("./lib/encryption"),d.KeyDerivation=a("./lib/keyderivation"),d.EncryptionMnemonic=a("./lib/encryption_mnemonic"),d.useWebworker=a("./lib/use-webworker"),d.WalletSweeper=a("./lib/wallet_sweeper"),d.UnspentOutputFinder=a("./lib/unspent_output_finder"),d.BlocktrailBitcoinService=a("./lib/services/blocktrail_bitcoin_service"),d.InsightBitcoinService=a("./lib/services/insight_bitcoin_service"),d.randomBytes=a("randombytes"),d.lodash=a("lodash"),d.CryptoJS=a("crypto-js"),d.debug=a("debug"),d.bip39=a("bip39"),d.bip39wordlist=a("bip39/wordlists/en.json"),d.bitcoin=a("bitcoinjs-lib"),d.superagent=a("superagent"),d.Buffer=Buffer,d.VERSION=a("./lib/pkginfo").VERSION,c=b.exports=d}).call(this,a("buffer").Buffer)},{"./lib/api_client":1,"./lib/blocktrail":2,"./lib/encryption":3,"./lib/encryption_mnemonic":4,"./lib/keyderivation":5,"./lib/pkginfo":7,"./lib/request":8,"./lib/services/blocktrail_bitcoin_service":10,"./lib/services/insight_bitcoin_service":11,"./lib/unspent_output_finder":13,"./lib/use-webworker":14,"./lib/wallet":15,"./lib/wallet_sweeper":16,bip39:28,"bip39/wordlists/en.json":31,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,debug:211,lodash:249,q:293,randombytes:297,superagent:349}],20:[function(a,b,c){(function(c){"use strict";function d(a,b){if(a===b)return 0;for(var c=a.length,d=b.length,e=0,f=Math.min(c,d);e<f;++e)if(a[e]!==b[e]){c=a[e],d=b[e];break}return c<d?-1:d<c?1:0}function e(a){return c.Buffer&&"function"==typeof c.Buffer.isBuffer?c.Buffer.isBuffer(a):!(null==a||!a._isBuffer)}function f(a){return Object.prototype.toString.call(a)}function g(a){return!e(a)&&("function"==typeof c.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(a):!!a&&(a instanceof DataView||!!(a.buffer&&a.buffer instanceof ArrayBuffer))))}function h(a){if(u.isFunction(a)){if(x)return a.name;var b=a.toString(),c=b.match(z);return c&&c[1]}}function i(a,b){return"string"==typeof a?a.length<b?a:a.slice(0,b):a}function j(a){if(x||!u.isFunction(a))return u.inspect(a);var b=h(a),c=b?": "+b:"";return"[Function"+c+"]"}function k(a){return i(j(a.actual),128)+" "+a.operator+" "+i(j(a.expected),128)}function l(a,b,c,d,e){throw new y.AssertionError({message:c,actual:a,expected:b,operator:d,stackStartFunction:e})}function m(a,b){a||l(a,!0,b,"==",y.ok)}function n(a,b,c,h){if(a===b)return!0;if(e(a)&&e(b))return 0===d(a,b);if(u.isDate(a)&&u.isDate(b))return a.getTime()===b.getTime();if(u.isRegExp(a)&&u.isRegExp(b))return a.source===b.source&&a.global===b.global&&a.multiline===b.multiline&&a.lastIndex===b.lastIndex&&a.ignoreCase===b.ignoreCase;if(null!==a&&"object"==typeof a||null!==b&&"object"==typeof b){if(g(a)&&g(b)&&f(a)===f(b)&&!(a instanceof Float32Array||a instanceof Float64Array))return 0===d(new Uint8Array(a.buffer),new Uint8Array(b.buffer));if(e(a)!==e(b))return!1;h=h||{actual:[],expected:[]};var i=h.actual.indexOf(a);return i!==-1&&i===h.expected.indexOf(b)||(h.actual.push(a),h.expected.push(b),p(a,b,c,h))}return c?a===b:a==b}function o(a){return"[object Arguments]"==Object.prototype.toString.call(a)}function p(a,b,c,d){if(null===a||void 0===a||null===b||void 0===b)return!1;if(u.isPrimitive(a)||u.isPrimitive(b))return a===b;if(c&&Object.getPrototypeOf(a)!==Object.getPrototypeOf(b))return!1;var e=o(a),f=o(b);if(e&&!f||!e&&f)return!1;if(e)return a=w.call(a),b=w.call(b),n(a,b,c);var g,h,i=A(a),j=A(b);if(i.length!==j.length)return!1;for(i.sort(),j.sort(),h=i.length-1;h>=0;h--)if(i[h]!==j[h])return!1;for(h=i.length-1;h>=0;h--)if(g=i[h],!n(a[g],b[g],c,d))return!1;return!0}function q(a,b,c){n(a,b,!0)&&l(a,b,c,"notDeepStrictEqual",q)}function r(a,b){if(!a||!b)return!1;if("[object RegExp]"==Object.prototype.toString.call(b))return b.test(a);try{if(a instanceof b)return!0}catch(a){}return!Error.isPrototypeOf(b)&&b.call({},a)===!0}function s(a){var b;try{a()}catch(a){b=a}return b}function t(a,b,c,d){var e;if("function"!=typeof b)throw new TypeError('"block" argument must be a function');"string"==typeof c&&(d=c,c=null),e=s(b),d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&l(e,c,"Missing expected exception"+d);var f="string"==typeof d,g=!a&&u.isError(e),h=!a&&e&&!c;if((g&&f&&r(e,c)||h)&&l(e,c,"Got unwanted exception"+d),a&&e&&c&&!r(e,c)||!a&&e)throw e}var u=a("util/"),v=Object.prototype.hasOwnProperty,w=Array.prototype.slice,x=function(){return"foo"===function(){}.name}(),y=b.exports=m,z=/\s*function\s+([^\(\s]*)\s*/;y.AssertionError=function(a){this.name="AssertionError",this.actual=a.actual,this.expected=a.expected,this.operator=a.operator,a.message?(this.message=a.message,this.generatedMessage=!1):(this.message=k(this),this.generatedMessage=!0);var b=a.stackStartFunction||l;if(Error.captureStackTrace)Error.captureStackTrace(this,b);else{var c=new Error;if(c.stack){var d=c.stack,e=h(b),f=d.indexOf("\n"+e);if(f>=0){var g=d.indexOf("\n",f+1);d=d.substring(g+1)}this.stack=d}}},u.inherits(y.AssertionError,Error),y.fail=l,y.ok=m,y.equal=function(a,b,c){a!=b&&l(a,b,c,"==",y.equal)},y.notEqual=function(a,b,c){a==b&&l(a,b,c,"!=",y.notEqual)},y.deepEqual=function(a,b,c){n(a,b,!1)||l(a,b,c,"deepEqual",y.deepEqual)},y.deepStrictEqual=function(a,b,c){n(a,b,!0)||l(a,b,c,"deepStrictEqual",y.deepStrictEqual)},y.notDeepEqual=function(a,b,c){n(a,b,!1)&&l(a,b,c,"notDeepEqual",y.notDeepEqual)},y.notDeepStrictEqual=q,y.strictEqual=function(a,b,c){a!==b&&l(a,b,c,"===",y.strictEqual)},y.notStrictEqual=function(a,b,c){a===b&&l(a,b,c,"!==",y.notStrictEqual)},y.throws=function(a,b,c){t(!0,a,b,c)},y.doesNotThrow=function(a,b,c){t(!1,a,b,c)},y.ifError=function(a){if(a)throw a};var A=Object.keys||function(a){var b=[];for(var c in a)v.call(a,c)&&b.push(c);return b}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"util/":360}],21:[function(a,b,c){(function(a){!function(){function c(a){var b=!1;return function(){if(b)throw new Error("Callback was already called.");b=!0,a.apply(d,arguments)}}var d,e,f={};d=this,null!=d&&(e=d.async),f.noConflict=function(){return d.async=e,f};var g=Object.prototype.toString,h=Array.isArray||function(a){return"[object Array]"===g.call(a)},i=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)},j=function(a,b){if(a.map)return a.map(b);var c=[];return i(a,function(a,d,e){c.push(b(a,d,e))}),c},k=function(a,b,c){return a.reduce?a.reduce(b,c):(i(a,function(a,d,e){c=b(c,a,d,e)}),c)},l=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};"undefined"!=typeof a&&a.nextTick?(f.nextTick=a.nextTick,"undefined"!=typeof setImmediate?f.setImmediate=function(a){setImmediate(a)}:f.setImmediate=f.nextTick):"function"==typeof setImmediate?(f.nextTick=function(a){setImmediate(a)},f.setImmediate=f.nextTick):(f.nextTick=function(a){setTimeout(a,0)},f.setImmediate=f.nextTick),f.each=function(a,b,d){function e(b){b?(d(b),d=function(){}):(f+=1,f>=a.length&&d())}if(d=d||function(){},!a.length)return d();var f=0;i(a,function(a){b(a,c(e))})},f.forEach=f.each,f.eachSeries=function(a,b,c){if(c=c||function(){},!a.length)return c();var d=0,e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d>=a.length?c():e())})};e()},f.forEachSeries=f.eachSeries,f.eachLimit=function(a,b,c,d){var e=m(b);e.apply(null,[a,c,d])},f.forEachLimit=f.eachLimit;var m=function(a){return function(b,c,d){if(d=d||function(){},!b.length||a<=0)return d();var e=0,f=0,g=0;!function h(){if(e>=b.length)return d();for(;g<a&&f<b.length;)f+=1,g+=1,c(b[f-1],function(a){a?(d(a),d=function(){}):(e+=1,g-=1,e>=b.length?d():h())})}()}},n=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.each].concat(b))}},o=function(a,b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[m(a)].concat(c))}},p=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.eachSeries].concat(b))}},q=function(a,b,c,d){if(b=j(b,function(a,b){return{index:b,value:a}}),d){var e=[];a(b,function(a,b){c(a.value,function(c,d){e[a.index]=d,b(c)})},function(a){d(a,e)})}else a(b,function(a,b){c(a.value,function(a){b(a)})})};f.map=n(q),f.mapSeries=p(q),f.mapLimit=function(a,b,c,d){return r(b)(a,c,d)};var r=function(a){return o(a,q)};f.reduce=function(a,b,c,d){f.eachSeries(a,function(a,d){c(b,a,function(a,c){b=c,d(a)})},function(a){d(a,b)})},f.inject=f.reduce,f.foldl=f.reduce,f.reduceRight=function(a,b,c,d){var e=j(a,function(a){return a}).reverse();f.reduce(e,b,c,d)},f.foldr=f.reduceRight;var s=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.filter=n(s),f.filterSeries=p(s),f.select=f.filter,f.selectSeries=f.filterSeries;var t=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.reject=n(t),f.rejectSeries=p(t);var u=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?(d(a),d=function(){}):b()})},function(a){d()})};f.detect=n(u),f.detectSeries=p(u),f.some=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a&&(c(!0),c=function(){}),d()})},function(a){c(!1)})},f.any=f.some,f.every=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a||(c(!1),c=function(){}),d()})},function(a){c(!0)})},f.all=f.every,f.sortBy=function(a,b,c){f.map(a,function(a,c){b(a,function(b,d){b?c(b):c(null,{value:a,criteria:d})})},function(a,b){if(a)return c(a);var d=function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0};c(null,j(b.sort(d),function(a){return a.value}))})},f.auto=function(a,b){b=b||function(){};var c=l(a),d=c.length;if(!d)return b();var e={},g=[],j=function(a){g.unshift(a)},m=function(a){for(var b=0;b<g.length;b+=1)if(g[b]===a)return void g.splice(b,1)},n=function(){d--,i(g.slice(0),function(a){a()})};j(function(){if(!d){var a=b;b=function(){},a(null,e)}}),i(c,function(c){var d=h(a[c])?a[c]:[a[c]],g=function(a){var d=Array.prototype.slice.call(arguments,1);if(d.length<=1&&(d=d[0]),a){var g={};i(l(e),function(a){g[a]=e[a]}),g[c]=d,b(a,g),b=function(){}}else e[c]=d,f.setImmediate(n)},o=d.slice(0,Math.abs(d.length-1))||[],p=function(){return k(o,function(a,b){return a&&e.hasOwnProperty(b)},!0)&&!e.hasOwnProperty(c)};if(p())d[d.length-1](g,e);else{var q=function(){p()&&(m(q),d[d.length-1](g,e))};j(q)}})},f.retry=function(a,b,c){var d=5,e=[];"function"==typeof a&&(c=b,b=a,a=d),a=parseInt(a,10)||d;var g=function(d,g){for(var h=function(a,b){return function(c){a(function(a,d){c(!a||b,{err:a,result:d})},g)}};a;)e.push(h(b,!(a-=1)));f.series(e,function(a,b){b=b[b.length-1],(d||c)(b.err,b.result)})};return c?g():g},f.waterfall=function(a,b){if(b=b||function(){},!h(a)){var c=new Error("First argument to waterfall must be an array of functions");return b(c)}if(!a.length)return b();var d=function(a){return function(c){if(c)b.apply(null,arguments),b=function(){};else{var e=Array.prototype.slice.call(arguments,1),g=a.next();g?e.push(d(g)):e.push(b),f.setImmediate(function(){a.apply(null,e)})}}};d(f.iterator(a))()};var v=function(a,b,c){if(c=c||function(){},h(b))a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},c);else{var d={};a.each(l(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}};f.parallel=function(a,b){v({map:f.map,each:f.each},a,b)},f.parallelLimit=function(a,b,c){v({map:r(b),each:m(b)},a,c)},f.series=function(a,b){if(b=b||function(){},h(a))f.mapSeries(a,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},b);else{var c={};f.eachSeries(l(a),function(b,d){a[b](function(a){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),c[b]=e,d(a)})},function(a){b(a,c)})}},f.iterator=function(a){var b=function(c){var d=function(){return a.length&&a[c].apply(null,arguments),d.next()};return d.next=function(){return c<a.length-1?b(c+1):null},d};return b(0)},f.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var w=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};f.concat=n(w),
4
f.concatSeries=p(w),f.whilst=function(a,b,c){a()?b(function(d){return d?c(d):void f.whilst(a,b,c)}):c()},f.doWhilst=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?f.doWhilst(a,b,c):c()})},f.until=function(a,b,c){a()?c():b(function(d){return d?c(d):void f.until(a,b,c)})},f.doUntil=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?c():f.doUntil(a,b,c)})},f.queue=function(a,b){function d(a,b,c,d){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var e={data:b,callback:"function"==typeof d?d:null};c?a.tasks.unshift(e):a.tasks.push(e),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}void 0===b&&(b=1);var e=0,g={tasks:[],concurrency:b,saturated:null,empty:null,drain:null,started:!1,paused:!1,push:function(a,b){d(g,a,!1,b)},kill:function(){g.drain=null,g.tasks=[]},unshift:function(a,b){d(g,a,!0,b)},process:function(){if(!g.paused&&e<g.concurrency&&g.tasks.length){var b=g.tasks.shift();g.empty&&0===g.tasks.length&&g.empty(),e+=1;var d=function(){e-=1,b.callback&&b.callback.apply(b,arguments),g.drain&&g.tasks.length+e===0&&g.drain(),g.process()},f=c(d);a(b.data,f)}},length:function(){return g.tasks.length},running:function(){return e},idle:function(){return g.tasks.length+e===0},pause:function(){g.paused!==!0&&(g.paused=!0,g.process())},resume:function(){g.paused!==!1&&(g.paused=!1,g.process())}};return g},f.priorityQueue=function(a,b){function c(a,b){return a.priority-b.priority}function d(a,b,c){for(var d=-1,e=a.length-1;d<e;){var f=d+(e-d+1>>>1);c(b,a[f])>=0?d=f:e=f-1}return d}function e(a,b,e,g){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var h={data:b,priority:e,callback:"function"==typeof g?g:null};a.tasks.splice(d(a.tasks,h,c)+1,0,h),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}var g=f.queue(a,b);return g.push=function(a,b,c){e(g,a,b,c)},delete g.unshift,g},f.cargo=function(a,b){var c=!1,d=[],e={tasks:d,payload:b,saturated:null,empty:null,drain:null,drained:!0,push:function(a,c){h(a)||(a=[a]),i(a,function(a){d.push({data:a,callback:"function"==typeof c?c:null}),e.drained=!1,e.saturated&&d.length===b&&e.saturated()}),f.setImmediate(e.process)},process:function f(){if(!c){if(0===d.length)return e.drain&&!e.drained&&e.drain(),void(e.drained=!0);var g="number"==typeof b?d.splice(0,b):d.splice(0,d.length),h=j(g,function(a){return a.data});e.empty&&e.empty(),c=!0,a(h,function(){c=!1;var a=arguments;i(g,function(b){b.callback&&b.callback.apply(null,a)}),f()})}},length:function(){return d.length},running:function(){return c}};return e};var x=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(b?console.error&&console.error(b):console[a]&&i(c,function(b){console[a](b)}))}]))}};f.log=x("log"),f.dir=x("dir"),f.memoize=function(a,b){var c={},d={};b=b||function(a){return a};var e=function(){var e=Array.prototype.slice.call(arguments),g=e.pop(),h=b.apply(null,e);h in c?f.nextTick(function(){g.apply(null,c[h])}):h in d?d[h].push(g):(d[h]=[g],a.apply(null,e.concat([function(){c[h]=arguments;var a=d[h];delete d[h];for(var b=0,e=a.length;b<e;b++)a[b].apply(null,arguments)}])))};return e.memo=c,e.unmemoized=a,e},f.unmemoize=function(a){return function(){return(a.unmemoized||a).apply(null,arguments)}},f.times=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.map(d,b,c)},f.timesSeries=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.mapSeries(d,b,c)},f.seq=function(){var a=arguments;return function(){var b=this,c=Array.prototype.slice.call(arguments),d=c.pop();f.reduce(a,c,function(a,c,d){c.apply(b,a.concat([function(){var a=arguments[0],b=Array.prototype.slice.call(arguments,1);d(a,b)}]))},function(a,c){d.apply(b,[a].concat(c))})}},f.compose=function(){return f.seq.apply(null,Array.prototype.reverse.call(arguments))};var y=function(a,b){var c=function(){var c=this,d=Array.prototype.slice.call(arguments),e=d.pop();return a(b,function(a,b){a.apply(c,d.concat([b]))},e)};if(arguments.length>2){var d=Array.prototype.slice.call(arguments,2);return c.apply(this,d)}return c};f.applyEach=n(y),f.applyEachSeries=p(y),f.forever=function(a,b){function c(d){if(d){if(b)return b(d);throw d}a(c)}c()},"undefined"!=typeof b&&b.exports?b.exports=f:"undefined"!=typeof define&&define.amd?define([],function(){return f}):d.async=f}()}).call(this,a("_process"))},{_process:263}],22:[function(a,b,c){var Buffer=a("safe-buffer").Buffer;b.exports=function(a){function b(b){if(0===b.length)return"";for(var c=[0],d=0;d<b.length;++d){for(var e=0,g=b[d];e<c.length;++e)g+=c[e]<<8,c[e]=g%f,g=g/f|0;for(;g>0;)c.push(g%f),g=g/f|0}for(var h="",i=0;0===b[i]&&i<b.length-1;++i)h+=a[0];for(var j=c.length-1;j>=0;--j)h+=a[c[j]];return h}function c(a){if(0===a.length)return Buffer.allocUnsafe(0);for(var b=[0],c=0;c<a.length;c++){var d=e[a[c]];if(void 0===d)return;for(var h=0,i=d;h<b.length;++h)i+=b[h]*f,b[h]=255&i,i>>=8;for(;i>0;)b.push(255&i),i>>=8}for(var j=0;a[j]===g&&j<a.length-1;++j)b.push(0);return Buffer.from(b.reverse())}function d(a){var b=c(a);if(b)return b;throw new Error("Non-base"+f+" character")}for(var e={},f=a.length,g=a.charAt(0),h=0;h<a.length;h++){var i=a.charAt(h);if(void 0!==e[i])throw new TypeError(i+" is ambiguous");e[i]=h}return{encode:b,decodeUnsafe:c,decode:d}}},{"safe-buffer":311}],23:[function(a,b,c){"use strict";function d(a){var b=a>>25;return(33554431&a)<<5^996825010&-(b>>0&1)^642813549&-(b>>1&1)^513874426&-(b>>2&1)^1027748829&-(b>>3&1)^705979059&-(b>>4&1)}function e(a){for(var b=1,c=0;c<a.length;++c){var e=a.charCodeAt(c);if(e<33||e>126)throw new Error("Invalid prefix ("+a+")");b=d(b)^e>>5}b=d(b);for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);b=d(b)^31&g}return b}function f(a,b){if(a.length+7+b.length>90)throw new TypeError("Exceeds Bech32 maximum length");a=a.toLowerCase();for(var c=e(a),f=a+"1",g=0;g<b.length;++g){var h=b[g];if(h>>5!==0)throw new Error("Non 5-bit word");c=d(c)^h,f+=k.charAt(h)}for(var i=0;i<6;++i)c=d(c);c^=1;for(var j=0;j<6;++j){var l=c>>5*(5-j)&31;f+=k.charAt(l)}return f}function g(a){if(a.length<8)throw new TypeError(a+" too short");if(a.length>90)throw new TypeError(a+" too long");var b=a.toLowerCase(),c=a.toUpperCase();if(a!==b&&a!==c)throw new Error("Mixed-case string "+a);a=b;var f=a.lastIndexOf("1");if(0===f)throw new Error("Missing prefix for "+a);var g=a.slice(0,f),h=a.slice(f+1);if(h.length<6)throw new Error("Data too short");for(var i=e(g),j=[],k=0;k<h.length;++k){var m=h.charAt(k),n=l[m];if(void 0===n)throw new Error("Unknown character "+m);i=d(i)^n,k+6>=h.length||j.push(n)}if(1!==i)throw new Error("Invalid checksum for "+a);return{prefix:g,words:j}}function h(a,b,c,d){for(var e=0,f=0,g=(1<<c)-1,h=[],i=0;i<a.length;++i)for(e=e<<b|a[i],f+=b;f>=c;)f-=c,h.push(e>>f&g);if(d)f>0&&h.push(e<<c-f&g);else{if(f>=b)throw new Error("Excess padding");if(e<<c-f&g)throw new Error("Non-zero padding")}return h}function i(a){return h(a,8,5,!0)}function j(a){return h(a,5,8,!1)}for(var k="qpzry9x8gf2tvdw0s3jn54khce6mua7l",l={},m=0;m<k.length;m++){var n=k.charAt(m);if(void 0!==l[n])throw new TypeError(n+" is ambiguous");l[n]=m}b.exports={decode:g,encode:f,toWords:i,fromWords:j}},{}],24:[function(a,b,c){function BigInteger(a,b,c){return this instanceof BigInteger?void(null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))):new BigInteger(a,b,c)}function d(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function e(a){return eb.charAt(a)}function f(a,b){var c=fb[a.charCodeAt(b)];return null==c?-1:c}function g(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function h(a){this.t=1,this.s=a<0?-1:0,a>0?this[0]=a:a<-1?this[0]=a+ab:this.t=0}function i(a){var b=new BigInteger;return b.fromInt(a),b}function j(a,b){var c,d=this;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void d.fromRadix(a,b);c=2}d.t=0,d.s=0;for(var e=a.length,g=!1,h=0;--e>=0;){var i=8==c?255&a[e]:f(a,e);i<0?"-"==a.charAt(e)&&(g=!0):(g=!1,0==h?d[d.t++]=i:h+c>d.DB?(d[d.t-1]|=(i&(1<<d.DB-h)-1)<<h,d[d.t++]=i>>d.DB-h):d[d.t-1]|=i<<h,h+=c,h>=d.DB&&(h-=d.DB))}8==c&&0!=(128&a[0])&&(d.s=-1,h>0&&(d[d.t-1]|=(1<<d.DB-h)-1<<h)),d.clamp(),g&&BigInteger.ZERO.subTo(d,d)}function k(){for(var a=this.s&this.DM;this.t>0&&this[this.t-1]==a;)--this.t}function l(a){var b=this;if(b.s<0)return"-"+b.negate().toString(a);var c;if(16==a)c=4;else if(8==a)c=3;else if(2==a)c=1;else if(32==a)c=5;else{if(4!=a)return b.toRadix(a);c=2}var d,f=(1<<c)-1,g=!1,h="",i=b.t,j=b.DB-i*b.DB%c;if(i-- >0)for(j<b.DB&&(d=b[i]>>j)>0&&(g=!0,h=e(d));i>=0;)j<c?(d=(b[i]&(1<<j)-1)<<c-j,d|=b[--i]>>(j+=b.DB-c)):(d=b[i]>>(j-=c)&f,j<=0&&(j+=b.DB,--i)),d>0&&(g=!0),g&&(h+=e(d));return g?h:"0"}function m(){var a=new BigInteger;return BigInteger.ZERO.subTo(this,a),a}function n(){return this.s<0?this.negate():this}function o(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function p(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function q(){return this.t<=0?0:this.DB*(this.t-1)+p(this[this.t-1]^this.s&this.DM)}function r(){return this.bitLength()>>3}function s(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function t(a,b){for(var c=a;c<this.t;++c)b[c-a]=this[c];b.t=Math.max(this.t-a,0),b.s=this.s}function u(a,b){var c,d=this,e=a%d.DB,f=d.DB-e,g=(1<<f)-1,h=Math.floor(a/d.DB),i=d.s<<e&d.DM;for(c=d.t-1;c>=0;--c)b[c+h+1]=d[c]>>f|i,i=(d[c]&g)<<e;for(c=h-1;c>=0;--c)b[c]=0;b[h]=i,b.t=d.t+h+1,b.s=d.s,b.clamp()}function v(a,b){var c=this;b.s=c.s;var d=Math.floor(a/c.DB);if(d>=c.t)return void(b.t=0);var e=a%c.DB,f=c.DB-e,g=(1<<e)-1;b[0]=c[d]>>e;for(var h=d+1;h<c.t;++h)b[h-d-1]|=(c[h]&g)<<f,b[h-d]=c[h]>>e;e>0&&(b[c.t-d-1]|=(c.s&g)<<f),b.t=c.t-d,b.clamp()}function w(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]-a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e-=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e-=a[d],b[d++]=e&c.DM,e>>=c.DB;e-=a.s}b.s=e<0?-1:0,e<-1?b[d++]=c.DV+e:e>0&&(b[d++]=e),b.t=d,b.clamp()}function x(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e<d.t;++e)b[e+c.t]=c.am(0,d[e],b,e,0,c.t);b.s=0,b.clamp(),this.s!=a.s&&BigInteger.ZERO.subTo(b,b)}function y(a){for(var b=this.abs(),c=a.t=2*b.t;--c>=0;)a[c]=0;for(c=0;c<b.t-1;++c){var d=b.am(c,b[c],a,2*c,0,1);(a[c+b.t]+=b.am(c+1,2*b[c],a,2*c+1,d,b.t-c-1))>=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function z(a,b,c){var d=this,e=a.abs();if(!(e.t<=0)){var f=d.abs();if(f.t<e.t)return null!=b&&b.fromInt(0),void(null!=c&&d.copyTo(c));null==c&&(c=new BigInteger);var g=new BigInteger,h=d.s,i=a.s,j=d.DB-p(e[e.t-1]);j>0?(e.lShiftTo(j,g),f.lShiftTo(j,c)):(e.copyTo(g),f.copyTo(c));var k=g.t,l=g[k-1];if(0!=l){var m=l*(1<<d.F1)+(k>1?g[k-2]>>d.F2:0),n=d.FV/m,o=(1<<d.F1)/m,q=1<<d.F2,r=c.t,s=r-k,t=null==b?new BigInteger:b;for(g.dlShiftTo(s,t),c.compareTo(t)>=0&&(c[c.t++]=1,c.subTo(t,c)),BigInteger.ONE.dlShiftTo(k,t),t.subTo(g,g);g.t<k;)g[g.t++]=0;for(;--s>=0;){var u=c[--r]==l?d.DM:Math.floor(c[r]*n+(c[r-1]+q)*o);if((c[r]+=g.am(0,u,c,s,0,k))<u)for(g.dlShiftTo(s,t),c.subTo(t,c);c[r]<--u;)c.subTo(t,c)}null!=b&&(c.drShiftTo(k,b),h!=i&&BigInteger.ZERO.subTo(b,b)),c.t=k,c.clamp(),j>0&&c.rShiftTo(j,c),h<0&&BigInteger.ZERO.subTo(c,c)}}}function A(a){var b=new BigInteger;return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b),b}function B(a){this.m=a}function C(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function D(a){return a}function E(a){a.divRemTo(this.m,null,a)}function F(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function G(a,b){a.squareTo(b),this.reduce(b)}function H(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function I(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<a.DB-15)-1,this.mt2=2*a.t}function J(a){var b=new BigInteger;return a.abs().dlShiftTo(this.m.t,b),b.divRemTo(this.m,null,b),a.s<0&&b.compareTo(BigInteger.ZERO)>0&&this.m.subTo(b,b),b}function K(a){var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function L(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b<this.m.t;++b){var c=32767&a[b],d=c*this.mpl+((c*this.mph+(a[b]>>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function M(a,b){a.squareTo(b),this.reduce(b)}function N(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function O(){return 0==(this.t>0?1&this[0]:this.s)}function P(a,b){if(a>4294967295||a<1)return BigInteger.ONE;var c=new BigInteger,d=new BigInteger,e=b.convert(this),f=p(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<<f)>0)b.mulTo(d,e,c);else{var g=c;c=d,d=g}return b.revert(c)}function Q(a,b){var c;return c=a<256||b.isEven()?new B(b):new I(b),this.exp(a,c)}function R(){var a=new BigInteger;return this.copyTo(a),a}function S(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function T(){return 0==this.t?this.s:this[0]<<24>>24}function U(){return 0==this.t?this.s:this[0]<<16>>16}function V(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function W(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function X(a){if(null==a&&(a=10),0==this.signum()||a<2||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=i(c),e=new BigInteger,f=new BigInteger,g="";for(this.divRemTo(d,e,f);e.signum()>0;)g=(c+f.intValue()).toString(a).substr(1)+g,e.divRemTo(d,e,f);return f.intValue().toString(a)+g}function Y(a,b){var c=this;c.fromInt(0),null==b&&(b=10);for(var d=c.chunkSize(b),e=Math.pow(b,d),g=!1,h=0,i=0,j=0;j<a.length;++j){var k=f(a,j);k<0?"-"==a.charAt(j)&&0==c.signum()&&(g=!0):(i=b*i+k,++h>=d&&(c.dMultiply(e),c.dAddOffset(i,0),h=0,i=0))}h>0&&(c.dMultiply(Math.pow(b,h)),c.dAddOffset(i,0)),g&&BigInteger.ZERO.subTo(c,c)}function Z(a,b,c){var d=this;if("number"==typeof b)if(a<2)d.fromInt(1);else for(d.fromNumber(a,c),d.testBit(a-1)||d.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),fa,d),d.isEven()&&d.dAddOffset(1,0);!d.isProbablePrime(b);)d.dAddOffset(2,0),d.bitLength()>a&&d.subTo(BigInteger.ONE.shiftLeft(a-1),d);else{var e=new Array,f=7&a;e.length=(a>>3)+1,b.nextBytes(e),f>0?e[0]&=(1<<f)-1:e[0]=0,d.fromString(e,256)}}function $(){var a=this,b=a.t,c=new Array;c[0]=a.s;var d,e=a.DB-b*a.DB%8,f=0;if(b-- >0)for(e<a.DB&&(d=a[b]>>e)!=(a.s&a.DM)>>e&&(c[f++]=d|a.s<<a.DB-e);b>=0;)e<8?(d=(a[b]&(1<<e)-1)<<8-e,d|=a[--b]>>(e+=a.DB-8)):(d=a[b]>>(e-=8)&255,e<=0&&(e+=a.DB,--b)),0!=(128&d)&&(d|=-256),0===f&&(128&a.s)!=(128&d)&&++f,(f>0||d!=a.s)&&(c[f++]=d);return c}function _(a){return 0==this.compareTo(a)}function aa(a){return this.compareTo(a)<0?this:a}function ba(a){return this.compareTo(a)>0?this:a}function ca(a,b,c){var d,e,f=this,g=Math.min(a.t,f.t);for(d=0;d<g;++d)c[d]=b(f[d],a[d]);if(a.t<f.t){for(e=a.s&f.DM,d=g;d<f.t;++d)c[d]=b(f[d],e);c.t=f.t}else{for(e=f.s&f.DM,d=g;d<a.t;++d)c[d]=b(e,a[d]);c.t=a.t}c.s=b(f.s,a.s),c.clamp()}function da(a,b){return a&b}function ea(a){var b=new BigInteger;return this.bitwiseTo(a,da,b),b}function fa(a,b){return a|b}function ga(a){var b=new BigInteger;return this.bitwiseTo(a,fa,b),b}function ha(a,b){return a^b}function ia(a){var b=new BigInteger;return this.bitwiseTo(a,ha,b),b}function ja(a,b){return a&~b}function ka(a){var b=new BigInteger;return this.bitwiseTo(a,ja,b),b}function la(){for(var a=new BigInteger,b=0;b<this.t;++b)a[b]=this.DM&~this[b];return a.t=this.t,a.s=~this.s,a}function ma(a){var b=new BigInteger;return a<0?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function na(a){var b=new BigInteger;return a<0?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function oa(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function pa(){for(var a=0;a<this.t;++a)if(0!=this[a])return a*this.DB+oa(this[a]);return this.s<0?this.t*this.DB:-1}function qa(a){for(var b=0;0!=a;)a&=a-1,++b;return b}function ra(){for(var a=0,b=this.s&this.DM,c=0;c<this.t;++c)a+=qa(this[c]^b);return a}function sa(a){var b=Math.floor(a/this.DB);return b>=this.t?0!=this.s:0!=(this[b]&1<<a%this.DB)}function ta(a,b){var c=BigInteger.ONE.shiftLeft(a);return this.bitwiseTo(c,b,c),c}function ua(a){return this.changeBit(a,fa)}function va(a){return this.changeBit(a,ja)}function wa(a){return this.changeBit(a,ha)}function xa(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]+a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e+=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e+=a[d],b[d++]=e&c.DM,e>>=c.DB;e+=a.s}b.s=e<0?-1:0,e>0?b[d++]=e:e<-1&&(b[d++]=c.DV+e),b.t=d,b.clamp()}function ya(a){var b=new BigInteger;return this.addTo(a,b),b}function za(a){var b=new BigInteger;return this.subTo(a,b),b}function Aa(a){var b=new BigInteger;return this.multiplyTo(a,b),b}function Ba(){var a=new BigInteger;return this.squareTo(a),a}function Ca(a){var b=new BigInteger;return this.divRemTo(a,b,null),b}function Da(a){var b=new BigInteger;return this.divRemTo(a,null,b),b}function Ea(a){var b=new BigInteger,c=new BigInteger;return this.divRemTo(a,b,c),new Array(b,c)}function Fa(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function Ga(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function Ha(){}function Ia(a){return a}function Ja(a,b,c){a.multiplyTo(b,c)}function Ka(a,b){a.squareTo(b)}function La(a){return this.exp(a,new Ha)}function Ma(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;d<e;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);d<e;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function Na(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d<a.t;++d)c[this.t+d-b]=this.am(b-d,a[d],c,0,0,this.t+d-b);c.clamp(),c.drShiftTo(1,c)}function Oa(a){this.r2=new BigInteger,this.q3=new BigInteger,BigInteger.ONE.dlShiftTo(2*a.t,this.r2),this.mu=this.r2.divide(a),this.m=a}function Pa(a){if(a.s<0||a.t>2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function Qa(a){return a}function Ra(a){var b=this;for(a.drShiftTo(b.m.t-1,b.r2),a.t>b.m.t+1&&(a.t=b.m.t+1,a.clamp()),b.mu.multiplyUpperTo(b.r2,b.m.t+1,b.q3),b.m.multiplyLowerTo(b.q3,b.m.t+1,b.r2);a.compareTo(b.r2)<0;)a.dAddOffset(1,b.m.t+1);for(a.subTo(b.r2,a);a.compareTo(b.m)>=0;)a.subTo(b.m,a)}function Sa(a,b){a.squareTo(b),this.reduce(b)}function Ta(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function Ua(a,b){var c,d,e=a.bitLength(),f=i(1);if(e<=0)return f;c=e<18?1:e<48?3:e<144?4:e<768?5:6,d=e<8?new B(b):b.isEven()?new Oa(b):new I(b);var g=new Array,h=3,j=c-1,k=(1<<c)-1;if(g[1]=d.convert(this),c>1){var l=new BigInteger;for(d.sqrTo(g[1],l);h<=k;)g[h]=new BigInteger,d.mulTo(l,g[h-2],g[h]),h+=2}var m,n,o=a.t-1,q=!0,r=new BigInteger;for(e=p(a[o])-1;o>=0;){for(e>=j?m=a[o]>>e-j&k:(m=(a[o]&(1<<e+1)-1)<<j-e,o>0&&(m|=a[o-1]>>this.DB+e-j)),h=c;0==(1&m);)m>>=1,--h;if((e-=h)<0&&(e+=this.DB,--o),q)g[m].copyTo(f),q=!1;else{for(;h>1;)d.sqrTo(f,r),d.sqrTo(r,f),h-=2;h>0?d.sqrTo(f,r):(n=f,f=r,r=n),d.mulTo(r,g[m],f)}for(;o>=0&&0==(a[o]&1<<e);)d.sqrTo(f,r),n=f,f=r,r=n,--e<0&&(e=this.DB-1,--o)}return d.revert(f)}function Va(a){var b=this.s<0?this.negate():this.clone(),c=a.s<0?a.negate():a.clone();if(b.compareTo(c)<0){var d=b;b=c,c=d}var e=b.getLowestSetBit(),f=c.getLowestSetBit();if(f<0)return b;for(e<f&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function Wa(a){if(a<=0)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function Xa(a){var b=a.isEven();if(0===this.signum())throw new Error("division by zero");if(this.isEven()&&b||0==a.signum())return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=i(1),f=i(0),g=i(0),h=i(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(e.isEven()&&f.isEven()||(e.addTo(this,e),f.subTo(a,f)),e.rShiftTo(1,e)):f.isEven()||f.subTo(a,f),f.rShiftTo(1,f);for(;d.isEven();)d.rShiftTo(1,d),b?(g.isEven()&&h.isEven()||(g.addTo(this,g),h.subTo(a,h)),g.rShiftTo(1,g)):h.isEven()||h.subTo(a,h),h.rShiftTo(1,h);c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(g,e),f.subTo(h,f)):(d.subTo(c,d),b&&g.subTo(e,g),h.subTo(f,h))}if(0!=d.compareTo(BigInteger.ONE))return BigInteger.ZERO;for(;h.compareTo(a)>=0;)h.subTo(a,h);for(;h.signum()<0;)h.addTo(a,h);return h}function Ya(a){var b,c=this.abs();if(1==c.t&&c[0]<=gb[gb.length-1]){for(b=0;b<gb.length;++b)if(c[0]==gb[b])return!0;return!1}if(c.isEven())return!1;for(b=1;b<gb.length;){for(var d=gb[b],e=b+1;e<gb.length&&d<hb;)d*=gb[e++];for(d=c.modInt(d);b<e;)if(d%gb[b++]==0)return!1}return c.millerRabin(a)}function Za(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(c<=0)return!1;var d=b.shiftRight(c);a=a+1>>1,a>gb.length&&(a=gb.length);for(var e,f=new BigInteger(null),g=[],h=0;h<a;++h){for(;e=gb[Math.floor(Math.random()*gb.length)],g.indexOf(e)!=-1;);g.push(e),f.fromInt(e);var i=f.modPow(d,this);if(0!=i.compareTo(BigInteger.ONE)&&0!=i.compareTo(b)){for(var e=1;e++<c&&0!=i.compareTo(b);)if(i=i.modPowInt(2,this),0==i.compareTo(BigInteger.ONE))return!1;if(0!=i.compareTo(b))return!1}}return!0}var $a=BigInteger.prototype;$a.__bigi=a("../package.json").version,BigInteger.isBigInteger=function(a,b){return a&&a.__bigi&&(!b||a.__bigi===$a.__bigi)};var _a;BigInteger.prototype.am=d,_a=26,BigInteger.prototype.DB=_a,BigInteger.prototype.DM=(1<<_a)-1;var ab=BigInteger.prototype.DV=1<<_a,bb=52;BigInteger.prototype.FV=Math.pow(2,bb),BigInteger.prototype.F1=bb-_a,BigInteger.prototype.F2=2*_a-bb;var cb,db,eb="0123456789abcdefghijklmnopqrstuvwxyz",fb=new Array;for(cb="0".charCodeAt(0),db=0;db<=9;++db)fb[cb++]=db;for(cb="a".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;for(cb="A".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;B.prototype.convert=C,B.prototype.revert=D,B.prototype.reduce=E,B.prototype.mulTo=F,B.prototype.sqrTo=G,I.prototype.convert=J,I.prototype.revert=K,I.prototype.reduce=L,I.prototype.mulTo=N,I.prototype.sqrTo=M,$a.copyTo=g,$a.fromInt=h,$a.fromString=j,$a.clamp=k,$a.dlShiftTo=s,$a.drShiftTo=t,$a.lShiftTo=u,$a.rShiftTo=v,$a.subTo=w,$a.multiplyTo=x,$a.squareTo=y,$a.divRemTo=z,$a.invDigit=H,$a.isEven=O,$a.exp=P,$a.toString=l,$a.negate=m,$a.abs=n,$a.compareTo=o,$a.bitLength=q,$a.byteLength=r,$a.mod=A,$a.modPowInt=Q,Ha.prototype.convert=Ia,Ha.prototype.revert=Ia,Ha.prototype.mulTo=Ja,Ha.prototype.sqrTo=Ka,Oa.prototype.convert=Pa,Oa.prototype.revert=Qa,Oa.prototype.reduce=Ra,Oa.prototype.mulTo=Ta,Oa.prototype.sqrTo=Sa;var gb=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],hb=(1<<26)/gb[gb.length-1];$a.chunkSize=V,$a.toRadix=X,$a.fromRadix=Y,$a.fromNumber=Z,$a.bitwiseTo=ca,$a.changeBit=ta,$a.addTo=xa,$a.dMultiply=Fa,$a.dAddOffset=Ga,$a.multiplyLowerTo=Ma,$a.multiplyUpperTo=Na,$a.modInt=Wa,$a.millerRabin=Za,$a.clone=R,$a.intValue=S,$a.byteValue=T,$a.shortValue=U,$a.signum=W,$a.toByteArray=$,$a.equals=_,$a.min=aa,$a.max=ba,$a.and=ea,$a.or=ga,$a.xor=ia,$a.andNot=ka,$a.not=la,$a.shiftLeft=ma,$a.shiftRight=na,$a.getLowestSetBit=pa,$a.bitCount=ra,$a.testBit=sa,$a.setBit=ua,$a.clearBit=va,$a.flipBit=wa,$a.add=ya,$a.subtract=za,$a.multiply=Aa,$a.divide=Ca,$a.remainder=Da,$a.divideAndRemainder=Ea,$a.modPow=Ua,$a.modInverse=Xa,$a.pow=La,$a.gcd=Va,$a.isProbablePrime=Ya,$a.square=Ba,BigInteger.ZERO=i(0),BigInteger.ONE=i(1),BigInteger.valueOf=i,b.exports=BigInteger},{"../package.json":27}],25:[function(a,b,c){(function(Buffer){var b=a("assert"),BigInteger=a("./bigi");BigInteger.fromByteArrayUnsigned=function(a){return new BigInteger(128&a[0]?[0].concat(a):a)},BigInteger.prototype.toByteArrayUnsigned=function(){var a=this.toByteArray();return 0===a[0]?a.slice(1):a},BigInteger.fromDERInteger=function(a){return new BigInteger(a)},BigInteger.prototype.toDERInteger=BigInteger.prototype.toByteArray,BigInteger.fromBuffer=function(a){if(128&a[0]){var b=Array.prototype.slice.call(a);return new BigInteger([0].concat(b))}return new BigInteger(a)},BigInteger.fromHex=function(a){return""===a?BigInteger.ZERO:(b.equal(a,a.match(/^[A-Fa-f0-9]+/),"Invalid hex string"),b.equal(a.length%2,0,"Incomplete hex"),new BigInteger(a,16))},BigInteger.prototype.toBuffer=function(a){for(var b=this.toByteArrayUnsigned(),c=[],d=a-b.length;c.length<d;)c.push(0);return new Buffer(c.concat(b))},BigInteger.prototype.toHex=function(a){return this.toBuffer(a).toString("hex")}}).call(this,a("buffer").Buffer)},{"./bigi":24,assert:20,buffer:105}],26:[function(a,b,c){var BigInteger=a("./bigi");a("./convert"),b.exports=BigInteger},{"./bigi":24,"./convert":25}],27:[function(a,b,c){b.exports={_args:[[{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib"]],_from:"bigi@>=1.4.0 <2.0.0",_id:"[email protected]",_inCache:!0,_location:"/bigi",_nodeVersion:"6.1.0",_npmOperationalInternal:{host:"packages-12-west.internal.npmjs.com",tmp:"tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"},_npmUser:{name:"jprichardson",email:"[email protected]"},_npmVersion:"3.8.6",_phantomChildren:{},_requested:{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},_requiredBy:["/bitcoinjs-lib","/ecurve"],_resolved:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",_shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",_shrinkwrap:null,_spec:"bigi@^1.4.0",_where:"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib",bugs:{url:"https://github.com/cryptocoinjs/bigi/issues"},dependencies:{},description:"Big integers.",devDependencies:{coveralls:"^2.11.2",istanbul:"^0.3.5",jshint:"^2.5.1",mocha:"^2.1.0",mochify:"^2.1.0"},directories:{},dist:{shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",tarball:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"},gitHead:"c25308081c896ff84702303722bf5ecd8b3f78e3",homepage:"https://github.com/cryptocoinjs/bigi#readme",keywords:["cryptography","math","bitcoin","arbitrary","precision","arithmetic","big","integer","int","number","biginteger","bigint","bignumber","decimal","float"],main:"./lib/index.js",maintainers:[{name:"midnightlightning",email:"[email protected]"},{name:"sidazhang",email:"[email protected]"},{name:"nadav",email:"[email protected]"},{name:"jprichardson",email:"[email protected]"}],name:"bigi",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{url:"git+https://github.com/cryptocoinjs/bigi.git",type:"git"},scripts:{"browser-test":"mochify --wd -R spec",coverage:"istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",coveralls:"npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",jshint:"jshint --config jshint.json lib/*.js ; true",test:"_mocha -- test/*.js",unit:"mocha"},testling:{files:"test/*.js",harness:"mocha",browsers:["ie/9..latest","firefox/latest","chrome/latest","safari/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},version:"1.4.2"}},{}],28:[function(a,b,c){(function(Buffer){var c=a("./lib/index"),d=a("./sjcl"),e=a("assert");e("function"==typeof d.hash.sha512);var f=function(a){var b=new d.misc.hmac(a,d.hash.sha512);this.encrypt=function(){return b.encrypt.apply(b,arguments)}};c.setPbkdf2(function(a,b,c,e,g){var h;switch(g){case"sha512":h=f;break;default:throw new Error("Digest ["+g+"] not implemented")}var i=d.misc.pbkdf2(d.codec.utf8String.toBits(a),d.codec.utf8String.toBits(b),c,8*e,h);return new Buffer(d.codec.hex.fromBits(i),"hex")}),b.exports={salt:c.salt,mnemonicToSeed:c.mnemonicToSeed,mnemonicToSeedHex:c.mnemonicToSeedHex,mnemonicToEntropy:c.mnemonicToEntropy,entropyToMnemonic:c.entropyToMnemonic,generateMnemonic:c.generateMnemonic,validateMnemonic:c.validateMnemonic}}).call(this,a("buffer").Buffer)},{"./lib/index":29,"./sjcl":30,assert:20,buffer:105}],29:[function(a,b,c){(function(Buffer){function c(a){n=a}function d(a,b){return n(a,k(b),2048,64,"sha512")}function e(a,b){return d(a,b).toString("hex")}function f(a,b){b=b||s;var c=a.split(" ");o(c.length%3===0,"Invalid mnemonic");var d=c.every(function(a){return b.indexOf(a)>-1});o(d,"Invalid mnemonic");var e=c.map(function(a){var c=b.indexOf(a);return m(c.toString(2),"0",11)}).join(""),f=32*Math.floor(e.length/33),g=e.slice(0,f),h=e.slice(f),i=g.match(/(.{1,8})/g).map(function(a){return parseInt(a,2)}),k=new Buffer(i),l=j(k);return o(l===h,"Invalid mnemonic checksum"),k.toString("hex")}function g(a,b){b=b||s;var c=new Buffer(a,"hex"),d=l([].slice.call(c)),e=j(c),f=d+e,g=f.match(/(.{1,11})/g),h=g.map(function(a){var c=parseInt(a,2);return b[c]});return h.join(" ")}function h(a,b,c){a=a||128,b=b||q;var d=b(a/8).toString("hex");return g(d,c)}function i(a,b){try{f(a,b)}catch(a){return!1}return!0}function j(a){var b=p("sha256").update(a).digest(),c=8*a.length,d=c/32;return l([].slice.call(b)).slice(0,d)}function k(a){return"mnemonic"+(r.nfkd(a)||"")}function l(a){return a.map(function(a){return m(a.toString(2),"0",8)}).join("")}function m(a,b,c){for(;a.length<c;)a=b+a;return a}var n,o=a("assert"),p=a("create-hash"),q=a("randombytes"),r=a("unorm"),s=a("../wordlists/en.json");b.exports={setPbkdf2:c,salt:k,mnemonicToSeed:d,mnemonicToSeedHex:e,mnemonicToEntropy:f,entropyToMnemonic:g,generateMnemonic:h,validateMnemonic:i}}).call(this,a("buffer").Buffer)},{"../wordlists/en.json":31,assert:20,buffer:105,"create-hash":128,randombytes:297,unorm:354}],30:[function(a,b,c){"use strict";function d(a){throw a}function e(a,b,c){4!==b.length&&d(new m.exception.invalid("invalid aes block size"));var e=a.b[c],f=b[0]^e[0],g=b[c?3:1]^e[1],h=b[2]^e[2];b=b[c?1:3]^e[3];var i,j,k,l,n=e.length/4-2,o=4,p=[0,0,0,0];i=a.o[c],a=i[0];var q=i[1],r=i[2],s=i[3],t=i[4];for(l=0;l<n;l++)i=a[f>>>24]^q[g>>16&255]^r[h>>8&255]^s[255&b]^e[o],j=a[g>>>24]^q[h>>16&255]^r[b>>8&255]^s[255&f]^e[o+1],k=a[h>>>24]^q[b>>16&255]^r[f>>8&255]^s[255&g]^e[o+2],b=a[b>>>24]^q[f>>16&255]^r[g>>8&255]^s[255&h]^e[o+3],o+=4,f=i,g=j,h=k;for(l=0;4>l;l++)p[c?3&-l:l]=t[f>>>24]<<24^t[g>>16&255]<<16^t[h>>8&255]<<8^t[255&b]^e[o++],i=f,f=g,g=h,h=b,b=i;return p}function f(a,b){var c,d=m.random.D[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}function g(a){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?m.random.addEntropy(window.performance.now(),a,"loadtime"):m.random.addEntropy((new Date).valueOf(),a,"loadtime");
5
}function h(a){a.b=i(a).concat(i(a)),a.F=new m.cipher.aes(a.b)}function i(a){for(var b=0;4>b&&(a.i[b]=a.i[b]+1|0,!a.i[b]);b++);return a.F.encrypt(a.i)}function j(a,b){return function(){b.apply(a,arguments)}}var k=void 0,l=!1,m={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message},this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message},this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message},this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message},this.message=a}}};"undefined"!=typeof b&&b.exports&&(b.exports=m),"function"==typeof define&&define([],function(){return m}),m.cipher.aes=function(a){this.o[0][0][0]||this.t();var b,c,e,f,g=this.o[0][4],h=this.o[1];b=a.length;var i=1;for(4!==b&&6!==b&&8!==b&&d(new m.exception.invalid("invalid aes key size")),this.b=[e=a.slice(0),f=[]],a=b;a<4*b+28;a++)c=e[a-1],(0===a%b||8===b&&4===a%b)&&(c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[255&c],0===a%b&&(c=c<<8^c>>>24^i<<24,i=i<<1^283*(i>>7))),e[a]=e[a-b]^c;for(b=0;a;b++,a--)c=e[3&b?a:a-4],f[b]=4>=a||4>b?c:h[0][g[c>>>24]]^h[1][g[c>>16&255]]^h[2][g[c>>8&255]]^h[3][g[255&c]]},m.cipher.aes.prototype={encrypt:function(a){return e(this,a,0)},decrypt:function(a){return e(this,a,1)},o:[[[],[],[],[],[]],[[],[],[],[],[]]],t:function(){var a,b,c,d,e,f,g,h=this.o[0],i=this.o[1],j=h[4],k=i[4],l=[],m=[];for(a=0;256>a;a++)m[(l[a]=a<<1^283*(a>>7))^a]=a;for(b=c=0;!j[b];b^=d||1,c=m[c]||1)for(f=c^c<<1^c<<2^c<<3^c<<4,f=f>>8^255&f^99,j[b]=f,k[f]=b,e=l[a=l[d=l[b]]],g=16843009*e^65537*a^257*d^16843008*b,e=257*l[f]^16843008*f,a=0;4>a;a++)h[a][b]=e=e<<24^e>>>8,i[a][f]=g=g<<24^g>>>8;for(a=0;5>a;a++)h[a]=h[a].slice(0),i[a]=i[a].slice(0)}},m.bitArray={bitSlice:function(a,b,c){return a=m.bitArray.R(a.slice(b/32),32-(31&b)).slice(1),c===k?a:m.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=m.bitArray.getPartial(c);return 32===d?a.concat(b):m.bitArray.R(b,d,0|c,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0===b?0:32*(b-1)+m.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;return b&=31,0<c&&b&&(a[c-1]=m.bitArray.partial(b,a[c-1]&2147483648>>b-1,1)),a},partial:function(a,b,c){return 32===a?b:(c?0|b:b<<32-a)+1099511627776*a},getPartial:function(a){return Math.round(a/1099511627776)||32},equal:function(a,b){if(m.bitArray.bitLength(a)!==m.bitArray.bitLength(b))return l;var c,d=0;for(c=0;c<a.length;c++)d|=a[c]^b[c];return 0===d},R:function(a,b,c,d){var e;for(e=0,d===k&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;return e=a.length?a[a.length-1]:0,a=m.bitArray.getPartial(e),d.push(m.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1)),d},j:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&65280|(65280&c)<<8|c<<24;return a}},m.codec.utf8String={fromBits:function(a){var b,c,d="",e=m.bitArray.bitLength(a);for(b=0;b<e/8;b++)0===(3&b)&&(c=a[b/4]),d+=String.fromCharCode(c>>>24),c<<=8;return decodeURIComponent(escape(d))},toBits:function(a){a=unescape(encodeURIComponent(a));var b,c=[],d=0;for(b=0;b<a.length;b++)d=d<<8|a.charCodeAt(b),3===(3&b)&&(c.push(d),d=0);return 3&b&&c.push(m.bitArray.partial(8*(3&b),d)),c}},m.codec.hex={fromBits:function(a){var b,c="";for(b=0;b<a.length;b++)c+=((0|a[b])+0xf00000000000).toString(16).substr(4);return c.substr(0,m.bitArray.bitLength(a)/4)},toBits:function(a){var b,c,d=[];for(a=a.replace(/\s|0x/g,""),c=a.length,a+="00000000",b=0;b<a.length;b+=8)d.push(0^parseInt(a.substr(b,8),16));return m.bitArray.clamp(d,4*c)}},m.codec.base64={M:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,f=m.codec.base64.M,g=0,h=m.bitArray.bitLength(a);for(c&&(f=f.substr(0,62)+"-_"),c=0;6*d.length<h;)d+=f.charAt((g^a[c]>>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;3&d.length&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c,e,f=[],g=0,h=m.codec.base64.M,i=0;for(b&&(h=h.substr(0,62)+"-_"),c=0;c<a.length;c++)e=h.indexOf(a.charAt(c)),0>e&&d(new m.exception.invalid("this isn't base64!")),26<g?(g-=26,f.push(i^e>>>g),i=e<<32-g):(g+=6,i^=e<<32-g);return 56&g&&f.push(m.bitArray.partial(56&g,i,1)),f}},m.codec.base64url={fromBits:function(a){return m.codec.base64.fromBits(a,1,1)},toBits:function(a){return m.codec.base64.toBits(a,1)}},m.hash.sha256=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha256.hash=function(a){return(new m.hash.sha256).update(a).finalize()},m.hash.sha256.prototype={blockSize:512,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=512+b&-512;b<=a;b+=512)this.r(c.splice(0,16));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+2;15&a;a++)b.push(0);for(b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,16));return this.reset(),c},l:[],b:[],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}var b,c=0,d=2;a:for(;64>c;d++){for(b=2;b*b<=d;b++)if(0===d%b)continue a;8>c&&(this.l[c]=a(Math.pow(d,.5))),this.b[c]=a(Math.pow(d,1/3)),c++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7];for(a=0;64>a;a++)16>a?b=d[a]:(b=d[a+1&15],c=d[a+14&15],b=d[15&a]=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[15&a]+d[a+9&15]|0),b=b+n+(k>>>6^k>>>11^k>>>25^k<<26^k<<21^k<<7)+(m^k&(l^m))+f[a],n=m,m=l,l=k,k=j+b|0,j=i,i=h,h=g,g=b+(h&i^j&(h^i))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+g|0,e[1]=e[1]+h|0,e[2]=e[2]+i|0,e[3]=e[3]+j|0,e[4]=e[4]+k|0,e[5]=e[5]+l|0,e[6]=e[6]+m|0,e[7]=e[7]+n|0}},m.hash.sha512=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha512.hash=function(a){return(new m.hash.sha512).update(a).finalize()},m.hash.sha512.prototype={blockSize:1024,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=1024+b&-1024;b<=a;b+=1024)this.r(c.splice(0,32));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+4;31&a;a++)b.push(0);for(b.push(0),b.push(0),b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,32));return this.reset(),c},l:[],ca:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],ea:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}function b(a){return 1099511627776*(a-Math.floor(a))&255}var c,d=0,e=2;a:for(;80>d;e++){for(c=2;c*c<=e;c++)if(0===e%c)continue a;8>d&&(this.l[2*d]=a(Math.pow(e,.5)),this.l[2*d+1]=b(Math.pow(e,.5))<<24|this.ca[d]),this.b[2*d]=a(Math.pow(e,1/3)),this.b[2*d+1]=b(Math.pow(e,1/3))<<24|this.ea[d],d++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7],o=e[8],p=e[9],q=e[10],r=e[11],s=e[12],t=e[13],u=e[14],v=e[15],w=g,x=h,y=i,z=j,A=k,B=l,C=m,D=n,E=o,F=p,G=q,H=r,I=s,J=t,K=u,L=v;for(a=0;80>a;a++){if(16>a)b=d[2*a],c=d[2*a+1];else{c=d[2*(a-15)];var M=d[2*(a-15)+1];b=(M<<31|c>>>1)^(M<<24|c>>>8)^c>>>7;var N=(c<<31|M>>>1)^(c<<24|M>>>8)^(c<<25|M>>>7);c=d[2*(a-2)];var O=d[2*(a-2)+1],M=(O<<13|c>>>19)^(c<<3|O>>>29)^c>>>6,O=(c<<13|O>>>19)^(O<<3|c>>>29)^(c<<26|O>>>6),P=d[2*(a-7)],Q=d[2*(a-16)],R=d[2*(a-16)+1];c=N+d[2*(a-7)+1],b=b+P+(c>>>0<N>>>0?1:0),c+=O,b+=M+(c>>>0<O>>>0?1:0),c+=R,b+=Q+(c>>>0<R>>>0?1:0)}d[2*a]=b|=0,d[2*a+1]=c|=0;var P=E&G^~E&I,S=F&H^~F&J,O=w&y^w&A^y&A,T=x&z^x&B^z&B,Q=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),R=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),U=f[2*a],V=f[2*a+1],M=L+((E<<18|F>>>14)^(E<<14|F>>>18)^(F<<23|E>>>9)),N=K+((F<<18|E>>>14)^(F<<14|E>>>18)^(E<<23|F>>>9))+(M>>>0<L>>>0?1:0),M=M+S,N=N+(P+(M>>>0<S>>>0?1:0)),M=M+V,N=N+(U+(M>>>0<V>>>0?1:0)),M=M+c|0,N=N+(b+(M>>>0<c>>>0?1:0));c=R+T,b=Q+O+(c>>>0<R>>>0?1:0),K=I,L=J,I=G,J=H,G=E,H=F,F=D+M|0,E=C+N+(F>>>0<D>>>0?1:0)|0,C=A,D=B,A=y,B=z,y=w,z=x,x=M+c|0,w=N+b+(x>>>0<M>>>0?1:0)|0}h=e[1]=h+x|0,e[0]=g+w+(h>>>0<x>>>0?1:0)|0,j=e[3]=j+z|0,e[2]=i+y+(j>>>0<z>>>0?1:0)|0,l=e[5]=l+B|0,e[4]=k+A+(l>>>0<B>>>0?1:0)|0,n=e[7]=n+D|0,e[6]=m+C+(n>>>0<D>>>0?1:0)|0,p=e[9]=p+F|0,e[8]=o+E+(p>>>0<F>>>0?1:0)|0,r=e[11]=r+H|0,e[10]=q+G+(r>>>0<H>>>0?1:0)|0,t=e[13]=t+J|0,e[12]=s+I+(t>>>0<J>>>0?1:0)|0,v=e[15]=v+L|0,e[14]=u+K+(v>>>0<L>>>0?1:0)|0}},m.mode.ccm={name:"ccm",w:[],listenProgress:function(a){m.mode.ccm.w.push(a)},unListenProgress:function(a){a=m.mode.ccm.w.indexOf(a),-1<a&&m.mode.ccm.w.splice(a,1)},X:function(a){var b,c=m.mode.ccm.w.slice();for(b=0;b<c.length;b+=1)c[b](a)},encrypt:function(a,b,c,e,f){var g,h=b.slice(0),i=m.bitArray,j=i.bitLength(c)/8,k=i.bitLength(h)/8;for(f=f||64,e=e||[],7>j&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),g=2;4>g&&k>>>8*g;g++);return g<15-j&&(g=15-j),c=i.clamp(c,8*(15-g)),b=m.mode.ccm.O(a,b,c,e,f,g),h=m.mode.ccm.s(a,h,c,b,f,g),i.concat(h.data,h.tag)},decrypt:function(a,b,c,e,f){f=f||64,e=e||[];var g=m.bitArray,h=g.bitLength(c)/8,i=g.bitLength(b),j=g.clamp(b,i-f),k=g.bitSlice(b,i-f),i=(i-f)/8;for(7>h&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),b=2;4>b&&i>>>8*b;b++);return b<15-h&&(b=15-h),c=g.clamp(c,8*(15-b)),j=m.mode.ccm.s(a,j,c,k,f,b),a=m.mode.ccm.O(a,j.data,c,e,f,b),g.equal(j.tag,a)||d(new m.exception.corrupt("ccm: tag doesn't match")),j.data},ga:function(a,b,c,d,e,f){var g=[],h=m.bitArray,i=h.j;if(d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)],d=h.concat(d,c),d[3]|=e,d=a.encrypt(d),b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:4294967295>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;b<g.length;b+=4)d=a.encrypt(i(d,g.slice(b,b+4).concat([0,0,0])));return d},O:function(a,b,c,e,f,g){var h=m.bitArray,i=h.j;for(f/=8,(f%2||4>f||16<f)&&d(new m.exception.invalid("ccm: invalid tag length")),(4294967295<e.length||4294967295<b.length)&&d(new m.exception.bug("ccm: can't deal with 4GiB or more data")),c=m.mode.ccm.ga(a,e,c,f,h.bitLength(b)/8,g),e=0;e<b.length;e+=4)c=a.encrypt(i(c,b.slice(e,e+4).concat([0,0,0])));return h.clamp(c,8*f)},s:function(a,b,c,d,e,f){var g,h=m.bitArray;g=h.j;var i=b.length,j=h.bitLength(b),k=i/50,l=k;if(c=h.concat([h.partial(8,f-1)],c).concat([0,0,0]).slice(0,4),d=h.bitSlice(g(d,a.encrypt(c)),0,e),!i)return{tag:d,data:[]};for(g=0;g<i;g+=4)g>k&&(m.mode.ccm.X(g/i),k+=l),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,j)}}},m.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits"));var h,i=m.mode.ocb2.K,j=m.bitArray,k=j.j,l=[0,0,0,0];c=i(a.encrypt(c));var n,o=[];for(e=e||[],f=f||64,h=0;h+4<b.length;h+=4)n=b.slice(h,h+4),l=k(l,n),o=o.concat(k(c,a.encrypt(k(c,n)))),c=i(c);return n=b.slice(h),b=j.bitLength(n),h=a.encrypt(k(c,[0,0,0,b])),n=j.clamp(k(n.concat([0,0,0]),h),b),l=k(l,k(n.concat([0,0,0]),h)),l=a.encrypt(k(l,k(c,i(c)))),e.length&&(l=k(l,g?e:m.mode.ocb2.pmac(a,e))),o.concat(j.concat(n,j.clamp(l,f)))},decrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits")),f=f||64;var h,i,j=m.mode.ocb2.K,k=m.bitArray,l=k.j,n=[0,0,0,0],o=j(a.encrypt(c)),p=m.bitArray.bitLength(b)-f,q=[];for(e=e||[],c=0;c+4<p/32;c+=4)h=l(o,a.decrypt(l(o,b.slice(c,c+4)))),n=l(n,h),q=q.concat(h),o=j(o);return i=p-32*c,h=a.encrypt(l(o,[0,0,0,i])),h=l(h,k.clamp(b.slice(c),i).concat([0,0,0])),n=l(n,h),n=a.encrypt(l(n,l(o,j(o)))),e.length&&(n=l(n,g?e:m.mode.ocb2.pmac(a,e))),k.equal(k.clamp(n,f),k.bitSlice(b,p))||d(new m.exception.corrupt("ocb: tag doesn't match")),q.concat(k.clamp(h,i))},pmac:function(a,b){var c,d=m.mode.ocb2.K,e=m.bitArray,f=e.j,g=[0,0,0,0],h=a.encrypt([0,0,0,0]),h=f(h,d(d(h)));for(c=0;c+4<b.length;c+=4)h=d(h),g=f(g,a.encrypt(f(h,b.slice(c,c+4))));return c=b.slice(c),128>e.bitLength(c)&&(h=f(h,d(h)),c=e.concat(c,[-2147483648,0,0,0])),g=f(g,c),a.encrypt(f(d(f(h,d(h))),g))},K:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}},m.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var f=b.slice(0);return b=m.bitArray,d=d||[],a=m.mode.gcm.s(!0,a,f,d,c,e||128),b.concat(a.data,a.tag)},decrypt:function(a,b,c,e,f){var g=b.slice(0),h=m.bitArray,i=h.bitLength(g);return f=f||128,e=e||[],f<=i?(b=h.bitSlice(g,i-f),g=h.bitSlice(g,0,i-f)):(b=g,g=[]),a=m.mode.gcm.s(l,a,g,e,c,f),h.equal(a.tag,b)||d(new m.exception.corrupt("gcm: tag doesn't match")),a.data},ba:function(a,b){var c,d,e,f,g,h=m.bitArray.j;for(e=[0,0,0,0],f=b.slice(0),c=0;128>c;c++){for((d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,f)),g=0!==(1&f[3]),d=3;0<d;d--)f[d]=f[d]>>>1|(1&f[d-1])<<31;f[0]>>>=1,g&&(f[0]^=-520093696)}return e},k:function(a,b,c){var d,e=c.length;for(b=b.slice(0),d=0;d<e;d+=4)b[0]^=4294967295&c[d],b[1]^=4294967295&c[d+1],b[2]^=4294967295&c[d+2],b[3]^=4294967295&c[d+3],b=m.mode.gcm.ba(b,a);return b},s:function(a,b,c,d,e,f){var g,h,i,j,k,l,n,o,p=m.bitArray;for(l=c.length,n=p.bitLength(c),o=p.bitLength(d),h=p.bitLength(e),g=b.encrypt([0,0,0,0]),96===h?(e=e.slice(0),e=p.concat(e,[1])):(e=m.mode.gcm.k(g,[0,0,0,0],e),e=m.mode.gcm.k(g,e,[0,0,Math.floor(h/4294967296),4294967295&h])),h=m.mode.gcm.k(g,[0,0,0,0],d),k=e.slice(0),d=h.slice(0),a||(d=m.mode.gcm.k(g,h,c)),j=0;j<l;j+=4)k[3]++,i=b.encrypt(k),c[j]^=i[0],c[j+1]^=i[1],c[j+2]^=i[2],c[j+3]^=i[3];return c=p.clamp(c,n),a&&(d=m.mode.gcm.k(g,h,c)),a=[Math.floor(o/4294967296),4294967295&o,Math.floor(n/4294967296),4294967295&n],d=m.mode.gcm.k(g,d,a),i=b.encrypt(e),d[0]^=i[0],d[1]^=i[1],d[2]^=i[2],d[3]^=i[3],{tag:p.bitSlice(d,0,f),data:c}}},m.misc.hmac=function(a,b){this.P=b=b||m.hash.sha256;var c,d=[[],[]],e=b.prototype.blockSize/32;for(this.q=[new b,new b],a.length>e&&(a=b.hash(a)),c=0;c<e;c++)d[0][c]=909522486^a[c],d[1][c]=1549556828^a[c];this.q[0].update(d[0]),this.q[1].update(d[1]),this.J=new b(this.q[0])},m.misc.hmac.prototype.encrypt=m.misc.hmac.prototype.mac=function(a){return this.S&&d(new m.exception.invalid("encrypt on already updated hmac called!")),this.update(a),this.digest(a)},m.misc.hmac.prototype.reset=function(){this.J=new this.P(this.q[0]),this.S=l},m.misc.hmac.prototype.update=function(a){this.S=!0,this.J.update(a)},m.misc.hmac.prototype.digest=function(){var a=this.J.finalize(),a=new this.P(this.q[1]).update(a).finalize();return this.reset(),a},m.misc.pbkdf2=function(a,b,c,e,f){c=c||1e3,(0>e||0>c)&&d(m.exception.invalid("invalid params to pbkdf2")),"string"==typeof a&&(a=m.codec.utf8String.toBits(a)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),f=f||m.misc.hmac,a=new f(a);var g,h,i,j,k=[],l=m.bitArray;for(j=1;32*k.length<(e||1);j++){for(f=g=a.encrypt(l.concat(b,[j])),h=1;h<c;h++)for(g=a.encrypt(g),i=0;i<g.length;i++)f[i]^=g[i];k=k.concat(f)}return e&&(k=l.clamp(k,e)),k},m.prng=function(a){this.f=[new m.hash.sha256],this.m=[0],this.I=0,this.A={},this.H=0,this.N={},this.Q=this.g=this.n=this.Z=0,this.b=[0,0,0,0,0,0,0,0],this.i=[0,0,0,0],this.F=k,this.G=a,this.u=l,this.D={progress:{},seeded:{}},this.p=this.Y=0,this.B=1,this.C=2,this.U=65536,this.L=[0,48,64,96,128,192,256,384,512,768,1024],this.V=3e4,this.T=80},m.prng.prototype={randomWords:function(a,b){var c,e=[];c=this.isReady(b);var f;if(c===this.p&&d(new m.exception.notReady("generator isn't seeded")),c&this.C){c=!(c&this.B),f=[];var g,j=0;for(this.Q=f[0]=(new Date).valueOf()+this.V,g=0;16>g;g++)f.push(4294967296*Math.random()|0);for(g=0;g<this.f.length&&(f=f.concat(this.f[g].finalize()),j+=this.m[g],this.m[g]=0,!(!c&&this.I&1<<g));g++);for(this.I>=1<<this.f.length&&(this.f.push(new m.hash.sha256),this.m.push(0)),this.g-=j,j>this.n&&(this.n=j),this.I++,this.b=m.hash.sha256.hash(this.b.concat(f)),this.F=new m.cipher.aes(this.b),c=0;4>c&&(this.i[c]=this.i[c]+1|0,!this.i[c]);c++);}for(c=0;c<a;c+=4)0===(c+1)%this.U&&h(this),f=i(this),e.push(f[0],f[1],f[2],f[3]);return h(this),e.slice(0,a)},setDefaultParanoia:function(a,b){0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b&&d("Setting paranoia=0 will ruin your security; use it only for testing"),this.G=a},addEntropy:function(a,b,c){c=c||"user";var e,g,h=(new Date).valueOf(),i=this.A[c],j=this.isReady(),l=0;switch(e=this.N[c],e===k&&(e=this.N[c]=this.Z++),i===k&&(i=this.A[c]=0),this.A[c]=(this.A[c]+1)%this.f.length,typeof a){case"number":b===k&&(b=1),this.f[i].update([e,this.H++,1,b,h,1,0|a]);break;case"object":if(c=Object.prototype.toString.call(a),"[object Uint32Array]"===c){for(g=[],c=0;c<a.length;c++)g.push(a[c]);a=g}else for("[object Array]"!==c&&(l=1),c=0;c<a.length&&!l;c++)"number"!=typeof a[c]&&(l=1);if(!l){if(b===k)for(c=b=0;c<a.length;c++)for(g=a[c];0<g;)b++,g>>>=1;this.f[i].update([e,this.H++,2,b,h,a.length].concat(a))}break;case"string":b===k&&(b=a.length),this.f[i].update([e,this.H++,3,b,h,a.length]),this.f[i].update(a);break;default:l=1}l&&d(new m.exception.bug("random: addEntropy only supports number, array of numbers or string")),this.m[i]+=b,this.g+=b,j===this.p&&(this.isReady()!==this.p&&f("seeded",Math.max(this.n,this.g)),f("progress",this.getProgress()))},isReady:function(a){return a=this.L[a!==k?a:this.G],this.n&&this.n>=a?this.m[0]>this.T&&(new Date).valueOf()>this.Q?this.C|this.B:this.B:this.g>=a?this.C|this.p:this.p},getProgress:function(a){return a=this.L[a?a:this.G],this.n>=a?1:this.g>a?1:this.g/a},startCollectors:function(){this.u||(this.a={loadTimeCollector:j(this,this.fa),mouseCollector:j(this,this.ha),keyboardCollector:j(this,this.da),accelerometerCollector:j(this,this.W),touchCollector:j(this,this.ja)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,l),window.addEventListener("mousemove",this.a.mouseCollector,l),window.addEventListener("keypress",this.a.keyboardCollector,l),window.addEventListener("devicemotion",this.a.accelerometerCollector,l),window.addEventListener("touchmove",this.a.touchCollector,l)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):d(new m.exception.bug("can't attach event")),this.u=!0)},stopCollectors:function(){this.u&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,l),window.removeEventListener("mousemove",this.a.mouseCollector,l),window.removeEventListener("keypress",this.a.keyboardCollector,l),window.removeEventListener("devicemotion",this.a.accelerometerCollector,l),window.removeEventListener("touchmove",this.a.touchCollector,l)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.u=l)},addEventListener:function(a,b){this.D[a][this.Y++]=b},removeEventListener:function(a,b){var c,d,e=this.D[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;c<f.length;c++)d=f[c],delete e[d]},da:function(){g(1)},ha:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(a){c=b=0}0!=b&&0!=c&&m.random.addEntropy([b,c],2,"mouse"),g(0)},ja:function(a){a=a.touches[0]||a.changedTouches[0],m.random.addEntropy([a.pageX||a.clientX,a.pageY||a.clientY],1,"touch"),g(0)},fa:function(){g(2)},W:function(a){if(a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z,window.orientation){var b=window.orientation;"number"==typeof b&&m.random.addEntropy(b,1,"accelerometer")}a&&m.random.addEntropy(a,2,"accelerometer"),g(0)}},m.random=new m.prng(6);a:try{var n,o,p,q;if(q="undefined"!=typeof b){var r;if(r=b.exports){var s;try{s=a("crypto")}catch(a){s=null}r=(o=s)&&o.randomBytes}q=r}if(q)n=o.randomBytes(128),n=new Uint32Array(new Uint8Array(n).buffer),m.random.addEntropy(n,1024,"crypto['randomBytes']");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(p=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(p);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break a;window.msCrypto.getRandomValues(p)}m.random.addEntropy(p,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))}m.json={defaults:{v:1,iter:1e3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},aa:function(a,b,c,e){c=c||{},e=e||{};var f,g=m.json,h=g.h({iv:m.random.randomWords(4,0)},g.defaults);return g.h(h,c),c=h.adata,"string"==typeof h.salt&&(h.salt=m.codec.base64.toBits(h.salt)),"string"==typeof h.iv&&(h.iv=m.codec.base64.toBits(h.iv)),(!m.mode[h.mode]||!m.cipher[h.cipher]||"string"==typeof a&&100>=h.iter||64!==h.ts&&96!==h.ts&&128!==h.ts||128!==h.ks&&192!==h.ks&&256!==h.ks||2>h.iv.length||4<h.iv.length)&&d(new m.exception.invalid("json encrypt: invalid parameters")),"string"==typeof a?(f=m.misc.cachedPbkdf2(a,h),a=f.key.slice(0,h.ks/32),h.salt=f.salt):m.ecc&&a instanceof m.ecc.elGamal.publicKey&&(f=a.kem(),h.kemtag=f.tag,a=f.key.slice(0,h.ks/32)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),"string"==typeof c&&(h.adata=c=m.codec.utf8String.toBits(c)),f=new m.cipher[h.cipher](a),g.h(e,h),e.key=a,h.ct="ccm"===h.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b instanceof ArrayBuffer?m.arrayBuffer.ccm.encrypt(f,b,h.iv,c,h.ts):m.mode[h.mode].encrypt(f,b,h.iv,c,h.ts),h},encrypt:function(a,b,c,d){var e=m.json,f=e.aa.apply(e,arguments);return e.encode(f)},$:function(a,b,c,e){c=c||{},e=e||{};var f=m.json;b=f.h(f.h(f.h({},f.defaults),b),c,!0);var g,h;return g=b.adata,"string"==typeof b.salt&&(b.salt=m.codec.base64.toBits(b.salt)),"string"==typeof b.iv&&(b.iv=m.codec.base64.toBits(b.iv)),(!m.mode[b.mode]||!m.cipher[b.cipher]||"string"==typeof a&&100>=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&256!==b.ks||!b.iv||2>b.iv.length||4<b.iv.length)&&d(new m.exception.invalid("json decrypt: invalid parameters")),"string"==typeof a?(h=m.misc.cachedPbkdf2(a,b),a=h.key.slice(0,b.ks/32),b.salt=h.salt):m.ecc&&a instanceof m.ecc.elGamal.secretKey&&(a=a.unkem(m.codec.base64.toBits(b.kemtag)).slice(0,b.ks/32)),"string"==typeof g&&(g=m.codec.utf8String.toBits(g)),h=new m.cipher[b.cipher](a),g="ccm"===b.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b.ct instanceof ArrayBuffer?m.arrayBuffer.ccm.decrypt(h,b.ct,b.iv,b.tag,g,b.ts):m.mode[b.mode].decrypt(h,b.ct,b.iv,g,b.ts),f.h(e,b),e.key=a,1===c.raw?g:m.codec.utf8String.fromBits(g)},decrypt:function(a,b,c,d){var e=m.json;return e.$(a,e.decode(b),c,d)},encode:function(a){var b,c="{",e="";for(b in a)if(a.hasOwnProperty(b))switch(b.match(/^[a-z0-9]+$/i)||d(new m.exception.invalid("json encode: invalid property name")),c+=e+'"'+b+'":',e=",",typeof a[b]){case"number":case"boolean":c+=a[b];break;case"string":c+='"'+escape(a[b])+'"';break;case"object":c+='"'+m.codec.base64.fromBits(a[b],0)+'"';break;default:d(new m.exception.bug("json encode: unsupported type"))}return c+"}"},decode:function(a){a=a.replace(/\s/g,""),a.match(/^\{.*\}$/)||d(new m.exception.invalid("json decode: this isn't json!")),a=a.replace(/^\{|\}$/g,"").split(/,/);var b,c,e={};for(b=0;b<a.length;b++)(c=a[b].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))||d(new m.exception.invalid("json decode: this isn't json!")),null!=c[3]?e[c[2]]=parseInt(c[3],10):null!=c[4]?e[c[2]]=c[2].match(/^(ct|adata|salt|iv)$/)?m.codec.base64.toBits(c[4]):unescape(c[4]):null!=c[5]&&(e[c[2]]="true"===c[5]);return e},h:function(a,b,c){if(a===k&&(a={}),b===k)return a;for(var e in b)b.hasOwnProperty(e)&&(c&&a[e]!==k&&a[e]!==b[e]&&d(new m.exception.invalid("required parameter overridden")),a[e]=b[e]);return a},la:function(a,b){var c,d={};for(c in a)a.hasOwnProperty(c)&&a[c]!==b[c]&&(d[c]=a[c]);return d},ka:function(a,b){var c,d={};for(c=0;c<b.length;c++)a[b[c]]!==k&&(d[b[c]]=a[b[c]]);return d}},m.encrypt=m.json.encrypt,m.decrypt=m.json.decrypt,m.misc.ia={},m.misc.cachedPbkdf2=function(a,b){var c,d=m.misc.ia;return b=b||{},c=b.iter||1e3,d=d[a]=d[a]||{},c=d[c]=d[c]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):m.random.randomWords(2,0)},d=b.salt===k?c.firstSalt:b.salt,c[d]=c[d]||m.misc.pbkdf2(a,d,b.iter),{key:c[d].slice(0),salt:d.slice(0)}}},{crypto:133}],31:[function(a,b,c){b.exports=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","affair","afford","afraid","again","age","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert","alien","all","alley","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","among","amount","amused","analyst","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","approve","april","arch","arctic","area","arena","argue","arm","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artefact","artist","artwork","ask","aspect","assault","asset","assist","assume","asthma","athlete","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","can","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","car","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","category","cattle","caught","cause","caution","cave","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","cupboard","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"];
@@ 2-2 (lines=1) @@
1
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.blocktrailSDK=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c,Buffer){function d(a,b){var c=h.HDNode.fromBase58(a[0],b);if("undefined"!=typeof c.keyPair.d)throw new Error("BIP32Key contained private key material - abort");if("M"!==a[1].slice(0,1))throw new Error("BIP32Key contained non-public path - abort")}function e(a,b){d(a.primary_public_key,b),d(a.backup_public_key,b)}var f=a("lodash"),g=a("q"),h=a("bitcoinjs-lib"),i=a("bitcoinjs-message"),j=a("bip39"),k=a("./wallet"),l=a("./rest_client"),m=a("./encryption"),n=a("./keyderivation"),o=a("./encryption_mnemonic"),p=a("./blocktrail"),q=a("randombytes"),r=a("crypto-js"),s=a("./webworkifier"),t=a("./use-webworker")(),u=function(a){var b=this;return this instanceof u?(b.testnet=a.testnet=a.testnet||!1,b.testnet?b.network=h.networks.testnet:b.network=h.networks.bitcoin,b.bitcoinCash=a.network&&"BCC"===a.network,b.feeSanityCheck="undefined"==typeof a.feeSanityCheck||a.feeSanityCheck,b.feeSanityCheckBaseFeeMultiplier=a.feeSanityCheckBaseFeeMultiplier||200,a.apiNetwork=a.apiNetwork||(b.testnet?"t":"")+(a.network||"BTC").toUpperCase(),void(b.client=u.initRestClient(a))):new u(a)};u.initRestClient=function(a){return c.env.BLOCKTRAIL_SDK_API_ENDPOINT&&(a.host=c.env.BLOCKTRAIL_SDK_API_ENDPOINT),a.host&&0===a.host.indexOf("https://")?(a.https=!0,a.host=a.host.substr(8)):a.host&&0===a.host.indexOf("http://")&&(a.https=!1,a.host=a.host.substr(7)),"undefined"==typeof a.https&&(a.https=!0),a.host||(a.host="api.blocktrail.com"),a.port||(a.port=a.https?443:80),a.endpoint||(a.endpoint="/"+(a.apiVersion||"v1")+(a.apiNetwork?"/"+a.apiNetwork:"")),new l(a)};var v=function(a){return g.when(a).then(function(a){return a.storePrimaryMnemonic&&(a.storeDataOnServer=a.storePrimaryMnemonic),"undefined"==typeof a.storeDataOnServer&&(a.storeDataOnServer=!a.primarySeed),a})},w=function(a,b){return g.when(a).then(function(a){if(a.storeDataOnServer){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),a.encryptedSecret=r.AES.encrypt(a.secret,a.passphrase).toString(r.format.OpenSSL)}b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),a.encryptedPrimarySeed=r.AES.encrypt(a.primarySeed.toString("base64"),a.secret).toString(r.format.OpenSSL),a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8).toString("hex"),b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoveryEncryptedSecret=r.AES.encrypt(a.secret,a.recoverySecret).toString(r.format.OpenSSL)}return a})};u.prototype.promisedEncrypt=function(b,c,d){if(t){var e=m.generateSalt(),f=m.generateIV();return s.workify(u.prototype.promisedEncrypt,function(){return a("./webworker")},{method:"Encryption.encryptWithSaltAndIV",pt:b,pw:c,saltBuf:e,iv:f,iterations:d}).then(function(a){return Buffer.from(a.cipherText.buffer)})}try{return g.when(m.encrypt(b,c,d))}catch(a){return g.reject(a)}},u.prototype.promisedDecrypt=function(b,c){if(t)return s.workify(u.prototype.promisedDecrypt,function(){return a("./webworker")},{method:"Encryption.decrypt",ct:b,pw:c}).then(function(a){return Buffer.from(a.plainText.buffer)});try{return g.when(m.decrypt(b,c))}catch(a){return g.reject(a)}},u.prototype.produceEncryptedDataV3=function(a,b){var c=this;return g.when(a).then(function(a){return a.storeDataOnServer?g.when().then(function(){if(!a.secret){if(!a.passphrase)throw new p.WalletCreateError("Can't encrypt data without a passphrase");return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET),a.secret=q(k.WALLET_ENTROPY_BITS/8),c.promisedEncrypt(a.secret,new Buffer(a.passphrase),n.defaultIterations).then(function(b){a.encryptedSecret=b})}if(!(a.secret instanceof Buffer))throw new Error("Secret must be a buffer")}).then(function(){return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY),c.promisedEncrypt(a.primarySeed,a.secret,n.subkeyIterations).then(function(b){a.encryptedPrimarySeed=b})}).then(function(){if(a.recoverySecret!==!1)return b(u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY),a.recoverySecret||(a.recoverySecret=q(k.WALLET_ENTROPY_BITS/8)),c.promisedEncrypt(a.secret,a.recoverySecret,n.defaultIterations).then(function(b){a.recoveryEncryptedSecret=b})}).then(function(){return a}):a})};var x=function(a,b,c){return g.when(a).then(function(a){return a.backupPublicKey||(a.backupSeed=a.backupSeed||q(k.WALLET_ENTROPY_BITS/8)),c(u.CREATE_WALLET_PROGRESS_PRIMARY),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,b),c(u.CREATE_WALLET_PROGRESS_BACKUP),a.backupPublicKey||(a.backupPrivateKey=h.HDNode.fromSeedBuffer(a.backupSeed,b),a.backupPublicKey=a.backupPrivateKey.neutered()),a.primaryPublicKey=a.primaryPrivateKey.deriveHardened(a.keyIndex).neutered(),c(u.CREATE_WALLET_PROGRESS_SUBMIT),a})};u.prototype.mnemonicToPrivateKey=function(a,b,c){var d=this,e=g.defer();e.promise.spreadNodeify(c);var f=d.testnet?h.networks.testnet:h.networks.bitcoin;return e.resolve(g.fcall(function(){return d.mnemonicToSeedHex(a,b).then(function(a){return h.HDNode.fromSeedHex(a,f)})})),e.promise},u.prototype.mnemonicToSeedHex=function(b,c){var d=this;if(t)return s.workify(d.mnemonicToSeedHex,function(){return a("./webworker")},{method:"mnemonicToSeedHex",mnemonic:b,passphrase:c}).then(function(a){return a.seed});try{return g.when(j.mnemonicToSeedHex(b,c))}catch(a){return g.reject(a)}},u.prototype.resolvePrimaryPrivateKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.passphrase&&a.password)throw new p.WalletCreateError("Can't specify passphrase and password");if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryMnemonic&&a.primarySeed)throw new p.WalletInitError("Can only specify one of; Primary Mnemonic or Primary Seed");if(a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");if(!a.primaryMnemonic&&!a.primarySeed)throw new p.WalletInitError("Need to specify at least one of; Primary Mnemonic or Primary Seed");if(a.primarySeed)c.primarySeed=a.primarySeed,a.primaryPrivateKey=h.HDNode.fromSeedBuffer(c.primarySeed,e),d.resolve(a);else{if(!a.passphrase)throw new p.WalletInitError("Can't init wallet with Primary Mnemonic without a passphrase");c.mnemonicToSeedHex(a.primaryMnemonic,a.passphrase).then(function(b){try{a.primarySeed=new Buffer(b,"hex"),a.primaryPrivateKey=h.HDNode.fromSeedBuffer(a.primarySeed,e),d.resolve(a)}catch(a){d.reject(a)}},function(a){d.reject(a)})}}catch(a){d.reject(a)}return d.promise},u.prototype.resolveBackupPublicKeyFromOptions=function(a,b){var c=this,d=g.defer();d.promise.nodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin;try{if(a.backupMnemonic&&a.backupPublicKey)throw new p.WalletInitError("Can only specify one of; Backup Mnemonic or Backup PublicKey");if(!a.backupMnemonic&&!a.backupPublicKey)throw new p.WalletInitError("Need to specify at least one of; Backup Mnemonic or Backup PublicKey");a.backupPublicKey?a.backupPublicKey instanceof h.HDNode?d.resolve(a):(a.backupPublicKey=h.HDNode.fromBase58(a.backupPublicKey,e),d.resolve(a)):c.mnemonicToPrivateKey(a.backupMnemonic,"").then(function(b){a.backupPublicKey=b.neutered(),d.resolve(a)},function(a){d.reject(a)})}catch(a){d.reject(a)}return d.promise},u.prototype.debugAuth=function(a){var b=this;return b.client.get("/debug/http-signature",null,!0,a)},u.prototype.address=function(a,b){var c=this;return c.client.get("/address/"+a,null,b)},u.prototype.addresses=function(a,b){var c=this;return c.client.post("/address",null,{addresses:a},b)},u.prototype.addressTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/transactions",b,c)},u.prototype.batchAddressHasTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/has-transactions",b,{addresses:a},c)},u.prototype.addressUnconfirmedTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unconfirmed-transactions",b,c)},u.prototype.addressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/address/"+a+"/unspent-outputs",b,c)},u.prototype.batchAddressUnspentOutputs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/address/unspent-outputs",b,{addresses:a},c)},u.prototype.verifyAddress=function(a,b,c){var d=this;return d.client.post("/address/"+a+"/verify",null,{signature:b},c)},u.prototype.allBlocks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/all-blocks",a,b)},u.prototype.block=function(a,b){var c=this;return c.client.get("/block/"+a,null,b)},u.prototype.blockLatest=function(a){var b=this;return b.client.get("/block/latest",null,a)},u.prototype.blockTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/block/"+a+"/transactions",b,c)},u.prototype.transaction=function(a,b){var c=this;return c.client.get("/transaction/"+a,null,b)},u.prototype.transactions=function(a,b){var c=this;return c.client.post("/transactions",null,a,b,!1)},u.prototype.allWebhooks=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/webhooks",a,b)},u.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.post("/webhook",null,{url:a,identifier:b},c)},u.prototype.getWebhook=function(a,b){var c=this;return c.client.get("/webhook/"+a,null,b)},u.prototype.updateWebhook=function(a,b,c){var d=this;return d.client.put("/webhook/"+a,null,b,c)},u.prototype.deleteWebhook=function(a,b){var c=this;return c.client.delete("/webhook/"+a,null,null,b)},u.prototype.getWebhookEvents=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/webhook/"+a+"/events",b,c)},u.prototype.subscribeTransaction=function(a,b,c,d){var e=this,f={event_type:"transaction",transaction:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.subscribeAddressTransactions=function(a,b,c,d){var e=this,f={event_type:"address-transactions",address:b,confirmations:c};return e.client.post("/webhook/"+a+"/events",null,f,d)},u.prototype.batchSubscribeAddressTransactions=function(a,b,c){var d=this;return b.forEach(function(a){a.event_type="address-transactions"}),d.client.post("/webhook/"+a+"/events/batch",null,b,c)},u.prototype.subscribeNewBlocks=function(a,b){var c=this,d={event_type:"block"};return c.client.post("/webhook/"+a+"/events",null,d,b)},u.prototype.unsubscribeAddressTransactions=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/address-transactions/"+b,null,null,c)},u.prototype.unsubscribeTransaction=function(a,b,c){var d=this;return d.client.delete("/webhook/"+a+"/transaction/"+b,null,null,c)},u.prototype.unsubscribeNewBlocks=function(a,b){var c=this;return c.client.delete("/webhook/"+a+"/block",null,null,b)},u.prototype.initWallet=function(a,b){var c=this;if("object"!=typeof a&&(a={identifier:arguments[0],passphrase:arguments[1]},b=arguments[2]),a.check_backup_key&&"string"!=typeof a.check_backup_key)throw new Error("Invalid input, must provide the backup key as a string (the xpub)");var d=g.defer();d.promise.spreadNodeify(b);var e=c.testnet?h.networks.testnet:h.networks.bitcoin,i=a.identifier;return i?(d.resolve(c.client.get("/wallet/"+i,null,!0).then(function(b){var d=a.keyIndex||b.key_index;if(a.walletVersion=b.wallet_version,a.check_backup_key&&a.check_backup_key!==b.backup_public_key[0])throw new Error("Backup key returned from server didn't match our own copy");var g=h.HDNode.fromBase58(b.backup_public_key[0],e),j=f.mapValues(b.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),l=f.mapValues(b.primary_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),m=new k(c,i,a.walletVersion,b.primary_mnemonic,b.encrypted_primary_seed,b.encrypted_secret,l,g,j,d,b.chain||0,b.segwit||0,c.testnet,b.checksum,b.upgrade_key_index,a.bypassNewAddressCheck);return m.recoverySecret=b.recovery_secret,a.readOnly?m:m.unlock(a).then(function(){return m})})),d.promise):(d.reject(new p.WalletInitError("Identifier is required")),d.promise)},u.CREATE_WALLET_PROGRESS_START=0,u.CREATE_WALLET_PROGRESS_ENCRYPT_SECRET=4,u.CREATE_WALLET_PROGRESS_ENCRYPT_PRIMARY=5,u.CREATE_WALLET_PROGRESS_ENCRYPT_RECOVERY=6,u.CREATE_WALLET_PROGRESS_PRIMARY=10,u.CREATE_WALLET_PROGRESS_BACKUP=20,u.CREATE_WALLET_PROGRESS_SUBMIT=30,u.CREATE_WALLET_PROGRESS_INIT=40,u.CREATE_WALLET_PROGRESS_DONE=100,u.prototype.createNewWallet=function(a,b){var c=this;if("object"!=typeof a){var d=arguments[0],e=arguments[1],f=arguments[2];b=arguments[3],"function"==typeof f&&(b=f,f=null),a={identifier:d,passphrase:e,keyIndex:f}}a.walletVersion=a.walletVersion||k.WALLET_VERSION_V3;var h=g.defer();return h.promise.spreadNodeify(b),g.nextTick(function(){return h.notify(u.CREATE_WALLET_PROGRESS_START),a.keyIndex=a.keyIndex||0,a.passphrase=a.passphrase||a.password,delete a.password,a.identifier?void(a.walletVersion===k.WALLET_VERSION_V1?c._createNewWalletV1(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V2?c._createNewWalletV2(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):a.walletVersion===k.WALLET_VERSION_V3?c._createNewWalletV3(a).progress(function(a){h.notify(a)}).then(function(a){h.resolve(a)},function(a){h.reject(a)}):h.reject(new p.WalletCreateError("Invalid wallet version!"))):(h.reject(new p.WalletCreateError("Identifier is required")),h.promise)}),h.promise},u.prototype._createNewWalletV1=function(a){var b=this,c=g.defer();return g.nextTick(function(){if(!a.primaryMnemonic&&!a.primarySeed){if(!a.passphrase&&!a.password)return c.reject(new p.WalletCreateError("Can't generate Primary Mnemonic without a passphrase")),c.promise;a.primaryMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS),a.storePrimaryMnemonic!==!1&&(a.storePrimaryMnemonic=!0)}a.backupMnemonic||a.backupPublicKey||(a.backupMnemonic=j.generateMnemonic(k.WALLET_ENTROPY_BITS)),c.notify(u.CREATE_WALLET_PROGRESS_PRIMARY),b.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return c.notify(u.CREATE_WALLET_PROGRESS_BACKUP),b.resolveBackupPublicKeyFromOptions(a).then(function(a){c.notify(u.CREATE_WALLET_PROGRESS_SUBMIT);var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex,g=a.primaryPrivateKey.deriveHardened(e).neutered();return b.storeNewWalletV1(a.identifier,[g.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storePrimaryMnemonic&&a.primaryMnemonic,d,e,a.segwit||null).then(function(i){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var j=f.mapValues(i.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V1,a.primaryMnemonic,null,null,{keyIndex:g},a.backupPublicKey,j,e,i.chain||0,i.segwit||0,b.testnet,d,i.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V1,passphrase:a.passphrase,primarySeed:a.primarySeed,primaryMnemonic:null}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,primaryMnemonic:a.primaryMnemonic,backupMnemonic:a.backupMnemonic,blocktrailPublicKeys:j}]})})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)})}),c.promise},u.prototype._createNewWalletV2=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return w(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV2(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V2,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V2,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?j.entropyToMnemonic(p.convert(a.encryptedPrimarySeed,"base64","hex")):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed.toString("hex")):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?j.entropyToMnemonic(p.convert(a.recoveryEncryptedSecret,"base64","hex")):null,encryptedSecret:a.encryptedSecret?j.entropyToMnemonic(p.convert(a.encryptedSecret,"base64","hex")):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype._createNewWalletV3=function(a){var b=this,c=g.defer();a=f.merge({},a);var d=b.testnet?h.networks.testnet:h.networks.bitcoin;return v(a).then(function(a){if(a.passphrase=a.passphrase||a.password,delete a.password,a.primaryPrivateKey)throw new p.WalletInitError("Can't specify; Primary PrivateKey");return a.primarySeed=a.primarySeed||q(k.WALLET_ENTROPY_BITS/8),a}).then(function(a){return b.produceEncryptedDataV3(a,c.notify.bind(c))}).then(function(a){return x(a,d,c.notify.bind(c))}).then(function(a){var d=a.primaryPrivateKey.getAddress(),e=a.keyIndex;return b.storeNewWalletV3(a.identifier,[a.primaryPublicKey.toBase58(),"M/"+e+"'"],[a.backupPublicKey.toBase58(),"M"],!!a.storeDataOnServer&&a.encryptedPrimarySeed,!!a.storeDataOnServer&&a.encryptedSecret,!!a.storeDataOnServer&&a.recoverySecret,d,e,a.support_secret||null,a.segwit||null).then(function(g){c.notify(u.CREATE_WALLET_PROGRESS_INIT);var i=f.mapValues(g.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],b.network)}),l=new k(b,a.identifier,k.WALLET_VERSION_V3,null,a.storeDataOnServer?a.encryptedPrimarySeed:null,a.storeDataOnServer?a.encryptedSecret:null,{keyIndex:a.primaryPublicKey},a.backupPublicKey,i,e,g.chain||0,g.segwit||0,b.testnet,d,g.upgrade_key_index,a.bypassNewAddressCheck);return l.unlock({walletVersion:k.WALLET_VERSION_V3,passphrase:a.passphrase,primarySeed:a.primarySeed,secret:a.secret}).then(function(){return c.notify(u.CREATE_WALLET_PROGRESS_DONE),[l,{walletVersion:l.walletVersion,encryptedPrimarySeed:a.encryptedPrimarySeed?o.encode(a.encryptedPrimarySeed):null,backupSeed:a.backupSeed?j.entropyToMnemonic(a.backupSeed):null,recoveryEncryptedSecret:a.recoveryEncryptedSecret?o.encode(a.recoveryEncryptedSecret):null,encryptedSecret:a.encryptedSecret?o.encode(a.encryptedSecret):null,blocktrailPublicKeys:i}]})})}).then(function(a){c.resolve(a)},function(a){c.reject(a)}),c.promise},u.prototype.storeNewWalletV1=function(a,b,c,d,f,g,h){var i=this,j={identifier:a,wallet_version:k.WALLET_VERSION_V1,primary_public_key:b,backup_public_key:c,primary_mnemonic:d,checksum:f,key_index:g,segwit:h};return e(j,i.network),i.client.post("/wallet",null,j)},u.prototype.storeNewWalletV2=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V2,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d,encrypted_secret:f,recovery_secret:g,checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.storeNewWalletV3=function(a,b,c,d,f,g,h,i,j,l){var m=this,n={identifier:a,wallet_version:k.WALLET_VERSION_V3,primary_public_key:b,backup_public_key:c,encrypted_primary_seed:d.toString("base64"),encrypted_secret:f.toString("base64"),recovery_secret:g.toString("hex"),checksum:h,key_index:i,support_secret:j||null,segwit:l};return e(n,m.network),m.client.post("/wallet",null,n)},u.prototype.updateWallet=function(a,b,c){var d=this;return d.client.post("/wallet/"+a,null,b,c)},u.prototype.upgradeKeyIndex=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/upgrade",null,{key_index:b,primary_public_key:c},d)},u.prototype.getWalletBalance=function(a,b){var c=this;return c.client.get("/wallet/"+a+"/balance",null,!0,b)},u.prototype.doWalletDiscovery=function(a,b,c){var d=this;return d.client.get("/wallet/"+a+"/discovery",{gap:b},!0,c)},u.prototype.getNewDerivation=function(a,b,c){var d=this;return d.client.post("/wallet/"+a+"/path",null,{path:b},c)},u.prototype.deleteWallet=function(a,b,c,d,e){var f=this;return"function"==typeof d&&(e=d,d=!1),f.client.delete("/wallet/"+a,{force:d},{checksum:b,signature:c},e)},u.prototype.coinSelection=function(a,b,c,d,e,f,h){var i=this;"function"==typeof e?(h=e,e=null,f={}):"function"==typeof f&&(h=f,f={}),e=e||k.FEE_STRATEGY_OPTIMAL,f=f||{};var j=g.defer();j.promise.spreadNodeify(h);var l={lock:c,zeroconf:d?1:0,zeroconfself:"undefined"==typeof f.allowZeroConfSelf||f.allowZeroConfSelf?1:0,fee_strategy:e};return f.forcefee&&(l.forcefee=f.forcefee),j.resolve(i.client.post("/wallet/"+a+"/coin-selection",l,b).then(function(a){return[a.utxos,a.fee,a.change,a]},function(a){if(a.message.match(/too low to pay the fee/))throw p.WalletFeeError(a);throw a})),j.promise},u.prototype.feePerKB=function(a){var b=this,c=g.defer();return c.promise.spreadNodeify(a),c.resolve(b.client.get("/fee-per-kb")),c.promise},u.prototype.sendTransaction=function(a,b,c,d,e,f,g){var h=this;"function"==typeof e?(g=e,e=null,f=!1):"function"==typeof f&&(g=f,f=!1);var i={paths:c,two_factor_token:e};return"string"==typeof b?i.raw_transaction=b:"object"==typeof b&&Object.keys(b).map(function(a){i[a]=b[a]}),h.client.post("/wallet/"+a+"/send",{check_fee:d?1:0,prioboost:f?1:0},i,g)},u.prototype.setupWalletWebhook=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/webhook",null,{url:c,identifier:b},d)},u.prototype.deleteWalletWebhook=function(a,b,c){var d=this;return d.client.delete("/wallet/"+a+"/webhook/"+b,null,null,c)},u.prototype.walletTransactions=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/transactions",b,!0,c)},u.prototype.walletAddresses=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/addresses",b,!0,c)},u.prototype.labelWalletAddress=function(a,b,c,d){var e=this;return e.client.post("/wallet/"+a+"/address/"+b+"/label",null,{label:c},d)},u.prototype.walletMaxSpendable=function(a,b,c,d,e){var f=this;"function"==typeof c?(e=c,c=null):"function"==typeof d&&(e=d,d={}),c=c||k.FEE_STRATEGY_OPTIMAL,d=d||{};var g={outputs:d.outputs?d.outputs:1,zeroconf:b?1:0,zeroconfself:"undefined"==typeof d.allowZeroConfSelf||d.allowZeroConfSelf?1:0,fee_strategy:c};return d.forcefee&&(g.forcefee=d.forcefee),f.client.get("/wallet/"+a+"/max-spendable",g,!0,e)},u.prototype.walletUTXOs=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),d.client.get("/wallet/"+a+"/utxos",b,!0,c)},u.prototype.allWallets=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),c.client.get("/wallets",a,!0,b)},u.prototype.verifyMessage=function(a,b,c,d){var e=this,f=g.defer();f.promise.nodeify(d);try{var h=i.verify(b,e.network.messagePrefix,a,new Buffer(c,"base64"));f.resolve(h)}catch(a){f.reject(a)}return f.promise},u.prototype.faucetWithdrawl=function(a,b,c){var d=this;return d.client.post("/faucet/withdrawl",null,{address:a,amount:b},c)},u.prototype.sendRawTransaction=function(a,b){var c=this;return c.client.post("/send-raw-tx",null,a,b)},u.prototype.price=function(a){var b=this;return b.client.get("/price",null,!1,a)},b.exports=u}).call(this,a("_process"),a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,"./rest_client":9,"./use-webworker":14,"./wallet":15,"./webworker":17,"./webworkifier":18,_process:263,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293,randombytes:297}],2:[function(a,b,c){(function(Buffer){var c=a("util"),d=a("assert"),e=a("crypto-js"),f=a("bip39"),g={COIN:1e8,PRECISION:8,DUST:2730,BASE_FEE:1e4},h=function(a,b,c){return new Buffer(a,b).toString(c)},i=function(a,b){var c=f.mnemonicToEntropy(a),d=h(c,"hex","base64"),i=e.AES.decrypt(d,b).toString(e.enc.Utf8);if(!i.length)throw new g.WalletDecryptError;return i},j=function(a,b){return i(a,b).toString(e.enc.Utf8)},k=function(a,b){return h(j(a,b),"base64","hex")},l=function(a,b){return new Buffer(k(a,b),"hex")},m=function(a,b){var c=e.AES.encrypt(a,b).toString(e.format.OpenSSL),d=h(c,"base64","hex"),g=f.entropyToMnemonic(d);return g},n=function(a,b){return m(h(a,"hex","base64"),b)},o=function(a,b){return m(a.toString("base64"),b)};g.convert=h,g.aesDecryptMnemonicToSeed=j,g.aesDecryptMnemonicToSeedBuffer=l,g.aesDecryptMnemonicToSeedHex=k,g.aesEncryptSeedToMnemonic=m,g.aesEncryptSeedHexToMnemonic=n,g.aesEncryptSeedBufferToMnemonic=o,g.V3Crypt={KeyDerivation:a("./keyderivation"),Encryption:a("./encryption"),EncryptionMnemonic:a("./encryption_mnemonic")},g.toSatoshi=function(a){return parseInt((a*g.COIN).toFixed(0),10)},g.toBTC=function(a){return(a/g.COIN).toFixed(g.PRECISION)},g.patchQ=function(a){function b(b,c,d){return a(b).spreadDone(c,d)}function c(b,c){return a(b).spreadNodeify(c)}a.spreadNodeify&&a.spreadDone||(a.spreadDone=b,a.makePromise.prototype.spreadDone=function(a,b){return this.all().done(function(b){return a.apply(void 0,b)},b)},a.spreadNodeify=c,a.makePromise.prototype.spreadNodeify=function(b){return b?void this.then(function(c){a.nextTick(function(){b.apply(void 0,[null].concat(c))})},function(c){a.nextTick(function(){b(c)})}):this})},Error.extend=function(a,b){d(a,"subTypeName is required");var e=function(c){return this instanceof e?(this.name=a,this.code=b,this.message=c?c.message||c||"":"",void(Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor))):new e(c)};return c.inherits(e,this),e.prototype.toString=function(){return this.name+": "+c.inspect(this.message)},e.extend=this.extend,e},"function"!=typeof Uint8Array.prototype.reverse&&(Buffer.prototype.reverse=function(){for(var a,b=0,c=this.length-1;b<=c;++b,--c)a=this[b],this[b]=this[c],this[c]=a;return this}),g.WalletInitError=Error.extend("WalletInitError",400),g.WalletCreateError=Error.extend("WalletCreateError",400),g.WalletUpgradeError=Error.extend("WalletUpgradeError",400),g.WalletChecksumError=Error.extend("WalletChecksumError",400),g.WalletDeleteError=Error.extend("WalletDeleteError",400),g.WalletDecryptError=Error.extend("WalletDecryptError",400),g.WalletAddressError=Error.extend("WalletAddressError",500),g.WalletSendError=Error.extend("WalletSendError",400),g.WalletLockedError=Error.extend("WalletLockedError",500),g.WalletFeeError=Error.extend("WalletFeeError",500),g.WalletInvalid2FAError=Error.extend("WalletInvalid2FAError",401),g.WalletMissing2FAError=Error.extend("WalletMissing2FAError",401),g.TransactionSignError=Error.extend("TransactionSignError",500),g.TransactionInputError=Error.extend("TransactionInputError",400),g.TransactionOutputError=Error.extend("TransactionOutputError",400),g.KeyPathError=Error.extend("KeyPathError",400),g.InvalidAddressError=Error.extend("InvalidAddressError",400),g.Error=Error.extend("Error",500),g.FEE_STRATEGY_FORCE_FEE="force_fee",g.FEE_STRATEGY_BASE_FEE="base_fee",g.FEE_STRATEGY_OPTIMAL="optimal",g.FEE_STRATEGY_LOW_PRIORITY="low_priority",g.FEE_STRATEGY_MIN_RELAY_FEE="min_relay_fee",g.patchQ(a("q")),b.exports=g}).call(this,a("buffer").Buffer)},{"./encryption":3,"./encryption_mnemonic":4,"./keyderivation":5,assert:20,bip39:28,buffer:105,"crypto-js":185,q:293,util:360}],3:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("sjcl"),e=a("./keyderivation"),f=a("randombytes"),g={defaultSaltLen:10,tagLenBits:128,ivLenBits:128,ivLenWords:4};g.generateSalt=function(){return f(this.defaultSaltLen)},g.generateIV=function(){return f(this.ivLenBits/8)},g.encrypt=function(a,b,c){var d=this.generateSalt(),f=this.generateIV();return c="undefined"==typeof c?e.defaultIterations:c,this.encryptWithSaltAndIV(a,b,d,f,c)},g.encryptWithSaltAndIV=function(a,b,f,g,h){c(a instanceof Buffer,"pt must be provided as a buffer"),c(b instanceof Buffer,"pw must be provided as a buffer"),c(g instanceof Buffer,"IV must be provided as a buffer"),c(f instanceof Buffer,"saltBuff must be provided as a buffer"),c(16===g.length,"IV must be exactly 16 bytes");var i=new Buffer(1),j=f,k=new Buffer(4);i.writeUInt8(f.length),k.writeUInt32LE(h);var l=i.toString("hex")+j.toString("hex")+k.toString("hex"),m=d.codec.hex.toBits(e.compute(b,f,h).toString("hex")),n=d.mode.gcm.encrypt(new d.cipher.aes(m),d.codec.hex.toBits(a.toString("hex")),d.codec.hex.toBits(g.toString("hex")),d.codec.hex.toBits(l),this.tagLenBits);return new Buffer([l,g.toString("hex"),d.codec.hex.fromBits(n)].join(""),"hex")},g.decrypt=function(a,b){c(a instanceof Buffer,"cipherText must be provided as a Buffer"),c(b instanceof Buffer,"password must be provided as a Buffer");var f=new Buffer(a,"hex"),g=0,h=f.readUInt8(g);g+=1;var i=f.slice(1,g+h);g+=h;var j=f.readUInt32LE(g);g+=4;var k=f.slice(0,g),l=f.slice(g,16+g);g+=16;var m=f.slice(g),n=e.compute(b,i,j),o=d.mode.gcm.decrypt(new d.cipher.aes(d.codec.hex.toBits(n.toString("hex"))),d.codec.hex.toBits(m.toString("hex")),d.codec.hex.toBits(l.toString("hex")),d.codec.hex.toBits(k.toString("hex")),this.tagLenBits);return new Buffer(d.codec.hex.fromBits(o),"hex")},b.exports=g}).call(this,a("buffer").Buffer)},{"./keyderivation":5,assert:20,buffer:105,randombytes:297,sjcl:343}],4:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bip39");String.prototype.repeat||(String.prototype.repeat=function(a){"use strict";if(null===this)throw new TypeError("can't convert "+this+" to object");var b=""+this;if(a=+a,a!==a&&(a=0),a<0)throw new RangeError("repeat count must be non-negative");if(a===1/0)throw new RangeError("repeat count must be less than infinity");if(a=Math.floor(a),0===b.length||0===a)return"";if(b.length*a>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");for(var c="";1===(1&a)&&(c+=b),a>>>=1,0!==a;)b+=b;return c});var e={chunkSize:4,paddingDummy:129},f=function(a){if(a[0]>128)throw new Error("Mnemonic sanity check - first byte can never be above 0x80");return e.paddingDummy.toString(16).repeat(e.chunkSize-a.length%e.chunkSize)};e.encode=function(a){c(a instanceof Buffer,"Data must be provided as a Buffer");var b=f(a),e=d.entropyToMnemonic(b+a.toString("hex"));try{d.mnemonicToEntropy(e)}catch(a){throw new Error("BIP39 library produced an invalid mnemonic")}return e},e.decode=function(a){c("string"==typeof a,"Mnemonic must be provided as a string");for(var b=new Buffer(d.mnemonicToEntropy(a),"hex"),e=0;b[e]===this.paddingDummy;)e++;var g=b.slice(e,b.length);if(f(g)!==b.slice(0,e).toString("hex"))throw new Error("There is only one way to pad a string");return g},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,
2
bip39:28,buffer:105}],5:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("./pbkdf2_sha512"),e={defaultIterations:35e3,subkeyIterations:1,keySizeBits:256};e.compute=function(a,b,e){if(e=e||this.defaultIterations,c(a instanceof Buffer,"Password must be provided as a Buffer"),c(b instanceof Buffer,"Salt must be provided as a Buffer"),c(b.length>0,"Salt must not be empty"),c("number"==typeof e,"Iterations must be a number"),c(e>0,"Iteration count should be at least 1"),b.length>128)throw new Error("Sanity check: Invalid salt, length can never be greater than 128");return d.digest(a,b,e,this.keySizeBits/8)},b.exports=e}).call(this,a("buffer").Buffer)},{"./pbkdf2_sha512":6,assert:20,buffer:105}],6:[function(a,b,c){(function(Buffer){var c=a("../vendor/asmcrypto.js/asmcrypto.js"),d=function(a,b,d,e){return new Buffer(new c.PBKDF2_HMAC_SHA512.bytes(a,b,d,e).buffer)};b.exports={digest:d}}).call(this,a("buffer").Buffer)},{"../vendor/asmcrypto.js/asmcrypto.js":365,buffer:105}],7:[function(a,b,c){b.exports=c={VERSION:"3.5.3"}},{}],8:[function(a,b,c){(function(c){function d(a){var b=this;b.https=a.https,b.host=a.host,b.endpoint=a.endpoint,b.auth=a.auth,b.port=a.port,b.apiKey=a.apiKey,b.apiSecret=a.apiSecret,b.contentMd5="undefined"==typeof a.contentMd5||a.contentMd5,b.params=f.defaults({},a.params),b.headers=f.defaults({},a.headers)}var e=a("./blocktrail"),f=a("lodash"),g=a("url"),h=a("querystring"),i=a("q"),j=a("create-hash"),k=a("superagent"),l=a("superagent-http-signature/index-hmac-only"),m=a("debug")("blocktrail-sdk:request"),n=!c.browser,o=function(){};d.qs=function(a){var b=[],c=Object.keys(a);return c.sort(),c.forEach(function(c){var d={};d[c]=a[c],b.push(h.stringify(d))}),b.join("&")},d.prototype.request=function(a,b,c,e,h){var k=this;k.deferred=i.defer(),k.callback=h||o;var l=g.parse(b,!0),p=d.qs(f.defaults({},c||{},l.query||{},k.params||{}));k.path="".concat(k.endpoint,l.pathname),p&&(k.path=k.path.concat("?",p)),e?(k.payload=JSON.stringify(e),k.headers["Content-Type"]="application/json"):k.payload="",n&&(k.headers["Content-Length"]=k.payload?k.payload.length:0),k.contentMd5===!0&&("GET"===a||"DELETE"===a?k.headers["Content-MD5"]=j("md5").update(k.path).digest().toString("hex"):k.headers["Content-MD5"]=j("md5").update(k.payload).digest().toString("hex")),m("%s %s %s",a,k.host,k.path);var q={hostname:k.host,path:k.path,port:k.port,method:a,headers:k.headers,auth:k.auth,agent:!1,withCredentials:!1};return k.performRequest(q),k.deferred.promise},d.prototype.performRequest=function(a){var b=this,c=a.method,e=!1;"http-signature"===a.auth&&(e=!0,delete a.auth);var g=(b.https?"https://":"http://")+a.hostname+a.path,h=k(c,g);if(!b.payload||"DELETE"!==c&&"POST"!==c&&"PUT"!==c&&"PATCH"!==c||h.send(b.payload),f.forEach(a.headers,function(a,b){h.set(b,a)}),e){if(!b.apiSecret){var i=new Error("Missing apiSecret! required to sign POST requests!");return b.deferred.reject(i),b.callback(i)}h.use(l({headers:["(request-target)","content-md5"],algorithm:"hmac-sha256",key:b.apiSecret,keyId:b.apiKey}))}return h.end(function(a,c){var e;if(a)return b.deferred.reject(a),b.callback(a);if(m("response status code: %s content type: %s",c.status,c.headers["content-type"]),!a&&c.headers["content-type"].indexOf("application/json")>=0)try{e=JSON.parse(c.text)}catch(b){a=b}return a||200===c.status||(a=d.handleFailure(c.text,c.statusCode)),a?b.deferred.reject(a):b.deferred.resolve(e),b.callback(a,e)}),b.deferred},d.handleFailure=function(a,b){var c,e;if("object"==typeof a)c=a;else try{c=JSON.parse(a)}catch(a){}return c?(e=new Error(c.msg?c.msg:null),Object.keys(c).forEach(function(a){"msg"!==a&&(e[a]=c[a])})):e=a?new Error(a):new Error("Unknown Server Error"),b&&(e.statusCode=b),d.convertError(e)},d.convertError=function(a){return a.requires_2fa?new e.WalletMissing2FAError:a.message.match(/Invalid two_factor_token/)?new e.WalletInvalid2FAError:a},b.exports=d}).call(this,a("_process"))},{"./blocktrail":2,_process:263,"create-hash":128,debug:211,lodash:249,q:293,querystring:296,superagent:349,"superagent-http-signature/index-hmac-only":346,url:355}],9:[function(a,b,c){var d=a("lodash"),e=a("./request"),f=function(b){var c=this;c.apiKey=b.apiKey,c.apiSecret=b.apiSecret,c.https=b.https,c.host=b.host,c.port=b.port,c.endpoint=b.endpoint,c.defaultParams={},c.apiKey&&(c.defaultParams.api_key=c.apiKey),c.defaultHeaders=d.defaults({},{"X-SDK-Version":"blocktrail-sdk-nodejs/"+a("./pkginfo").VERSION},b.defaultHeaders)};f.prototype.create_request=function(a){var b=this;return a=d.defaults({},a,{https:b.https,host:b.host,port:b.port,endpoint:b.endpoint,apiKey:b.apiKey,apiSecret:b.apiSecret,params:d.defaults({},b.defaultParams),headers:d.defaults({},b.defaultHeaders)}),new e(a)},f.prototype.post=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("POST",a,b,c,d)},f.prototype.put=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("PUT",a,b,c,d)},f.prototype.get=function(a,b,c,d){"function"==typeof c&&(d=c,c=!1);var e={};return c&&(e.auth="http-signature"),this.create_request(e).request("GET",a,b,null,d)},f.prototype.delete=function(a,b,c,d,e){e="undefined"==typeof e||e;var f={};return e&&(f.auth="http-signature"),this.create_request(f).request("DELETE",a,b,c,d)},b.exports=function(a){return new f(a)}},{"./pkginfo":7,"./request":8,lodash:249}],10:[function(a,b,c){var d=a("../api_client"),e=a("lodash"),f=a("q"),g=a("async"),h=function(a){this.defaultSettings={apiKey:null,apiSecret:null,network:"BTC",testnet:!1,apiVersion:"v1",apiEndpoint:null,retryLimit:5,retryDelay:20,paginationLimit:200},this.settings=e.merge({},this.defaultSettings,a);var b=this.normaliseNetwork(this.settings.network,this.settings.testnet);this.settings.network=b.network,this.settings.testnet=b.testnet,this.client=new d(this.settings)};h.prototype.normaliseNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?{network:"BTC",testnet:!0}:{network:"BTC",testnet:!1};case"tbtc":case"bitcoin-testnet":return{network:"BTC",testnet:!0};case"bcc":return b?{network:"BCC",testnet:!0}:{network:"BCC",testnet:!1};case"tbcc":return{network:"BCC",testnet:!0};default:throw new Error("Unknown network "+a)}},h.prototype.setPaginationLimit=function(a){this.settings.paginationLimit=a},h.prototype.estimateFee=function(){var a=this;return a.client.feePerKB().then(function(a){return Math.max(a.optimal,a.min_relay_fee)})},h.prototype.getBatchUnspentOutputs=function(a){var b=this,c=f.defer(),d=1,e=null,h=[];return g.doWhilst(function(c){var e={page:d,limit:b.settings.paginationLimit};b.client.batchAddressUnspentOutputs(a,e).then(function(a){h=h.concat(a.data),d++,c()},function(a){console.log("error happened:",a),c(a)})},function(){return e&&e.data.length>0},function(a){a&&console.log("complete, but with errors",a.message);var b={};h.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.hash,index:a.index,value:a.value,script_hex:a.script_hex})}),c.resolve(b)}),c.promise},h.prototype.batchAddressHasTransactions=function(a){var b=this;return b.client.batchAddressHasTransactions(a).then(function(a){return a.has_transactions})},b.exports=h},{"../api_client":1,async:21,lodash:249,q:293}],11:[function(a,b,c){var d=a("../blocktrail"),e=a("superagent"),f=a("lodash"),g=a("q"),h="https://insight.bitpay.com/api",i="https://test-insight.bitpay.com/api",j=function(a){this.defaultSettings={host:h,testnet:!1,retryLimit:5,retryDelay:20},"undefined"==typeof a.host&&a.testnet&&(this.defaultSettings.host=i),this.settings=f.merge({},this.defaultSettings,a),this.DEFAULT_ENDPOINT_MAINNET=h,this.DEFAULT_ENDPOINT_TESTNET=i};j.prototype.getBatchUnspentOutputs=function(a){var b=this,c=g.defer(),e={addrs:a.join(",")};return b.postEndpoint("addrs/utxo",e).then(function(a){var b={};a.forEach(function(a){var c=a.address;"undefined"==typeof b[c]&&(b[c]=[]),b[c].push({hash:a.txid,index:a.vout,value:d.toSatoshi(a.amount),script_hex:a.scriptPubKey})}),c.resolve(b)},function(a){c.reject(a)}),c.promise},j.prototype.batchAddressHasTransactions=function(a){var b=this,c={addrs:a.join(",")};return b.postEndpoint("addrs/txs",c).then(function(a){return a.items.length>0})},j.prototype.estimateFee=function(){var a=this,b="4";return a.getEndpoint("utils/estimatefee?nbBlocks="+b).then(function(a){return a[b]===-1?1e5:parseInt(1e8*a[b],10)})},j.prototype.sendTx=function(a){return this.postEndpoint("tx/send",{rawtx:a})},j.prototype.getEndpoint=function(a){return this.getRequest(this.settings.host+"/"+a)},j.prototype.postEndpoint=function(a,b){return this.postRequest(this.settings.host+"/"+a,b)},j.prototype.getRequest=function(a){var b=g.defer();return e.get(a).end(function(a,c){if(a)return void b.reject(a);if(!c.ok)return b.reject(c.text);if(!(c.headers["content-type"].indexOf("application/json")>=0))return b.resolve(c.body);try{var d=JSON.parse(c.text);return b.resolve(d)}catch(c){return b.reject(a)}}),b.promise},j.prototype.postRequest=function(a,b){var c=g.defer();return e.post(a).send(b).set("Content-Type","application/json").end(function(a,b){if(a)return void c.reject(a);if(!b.ok)return c.reject(b.text);if(!(b.headers["content-type"].indexOf("application/json")>=0))return c.resolve(b.body);try{var d=JSON.parse(b.text);return c.resolve(d)}catch(b){return c.reject(a)}}),c.promise},b.exports=j},{"../blocktrail":2,lodash:249,q:293,superagent:349}],12:[function(a,b,c){(function(Buffer){var c=a("assert"),d=a("bitcoinjs-lib"),e={SIZE_DER_SIGNATURE:72,SIZE_V0_P2WSH:36};e.getPublicKeySize=function(a){return a?33:65},e.getLengthForScriptPush=function(a){if(a<75)return 1;if(a<=255)return 2;if(a<=65535)return 3;if(a<=4294967295)return 5;throw new Error("Size of pushdata too large")},e.getLengthForVarInt=function(a){if(a<253)return 1;var b;if(a<65535)b=2;else if(a<4294967295)b=4;else{if(!(a<0x10000000000000000))throw new Error("Size of varint too large");b=8}return 1+b},e.estimateMultisigStackSize=function(a,b){var c,d=[0];for(c=0;c<a;c++)d.push(e.SIZE_DER_SIGNATURE);var f=1;for(c=0;c<b.length;c++)f+=this.getLengthForScriptPush(b[c].length)+b[c].length;return f+=2,[d,f]},e.estimateP2PKStackSize=function(a){var b=[e.SIZE_DER_SIGNATURE],c=this.getLengthForScriptPush(a.length)+a.length+1;return[b,c]},e.estimateP2PKHStackSize=function(a){"undefined"==typeof a&&(a=!0);var b=[this.SIZE_DER_SIGNATURE,this.getPublicKeySize(a)],c=2+this.getLengthForScriptPush(20)+20+2;return[b,c]},e.estimateStackSignatureSize=function(a,b,d,e){c(null===e||b);var f=[],g=[];b?(g=a,e instanceof Buffer&&g.push(e.length)):f=a,d instanceof Buffer&&f.push(d.length);var h=this,i=0;f.map(function(a){i+=h.getLengthForScriptPush(a)+a}),i+=h.getLengthForVarInt(i);var j=0;return g.length>0&&(g.map(function(a){j+=h.getLengthForVarInt(a)+a}),j+=h.getLengthForVarInt(g.length)),[i,j]},e.estimateInputFromScripts=function(a,b,e,f,g){c(null===e||f);var h;if(d.script.multisig.output.check(a)){var i=d.script.multisig.output.decode(a);h=this.estimateMultisigStackSize(i.m,i.pubKeys)[0]}else if(d.script.pubKey.output.check(a)){var j=d.script.pubKey.output.decode(a);h=this.estimateP2PKStackSize(j)[0]}else{if(!d.script.pubKeyHash.output.check(a))throw new Error("Unsupported script type");h=this.estimateP2PKHStackSize(g)[0]}return this.estimateStackSignatureSize(h,f,b,e)},e.estimateUtxo=function(a,b){var c=Buffer.from(a.scriptpubkey_hex,"hex"),e="string"==typeof a.redeem_script?Buffer.from(a.redeem_script,"hex"):null,f="string"==typeof a.witness_script?Buffer.from(a.witness_script,"hex"):null,g=!1,h=c;if(d.script.scriptHash.output.check(h)){if(null===e)throw new Error("Cant estimate, missing redeem script");h=e}if(d.script.witnessPubKeyHash.output.check(h)){var i=d.script.witnessPubKeyHash.output.decode(h);h=d.script.pubKeyHash.output.encode(i),g=!0}else if(d.script.witnessScriptHash.output.check(h)){if(null===f)throw new Error("Can't estimate, missing witness script");h=f,g=!0}var j=d.script.types,k=[j.MULTISIG,j.P2PKH,j.P2PK],l=d.script.classifyOutput(h);if(k.indexOf(l)===-1)throw new Error("Unsupported script type");var m=this.estimateInputFromScripts(h,e,f,g,b);return{scriptSig:m[0],witness:m[1]}},e.estimateInputsSize=function(a,b){var c=0,d=0;return a.map(function(a){var f=e.estimateUtxo(a);c+=40+f.scriptSig,b&&(d+=f.witness)}),b&&d>0&&(c+=2+d),c},e.calculateOutputsSize=function(a){var b=0;return a.map(function(a){var c=e.getLengthForVarInt(a.script.length);b+=8+c+a.script.length}),b},e.estimateTxWeight=function(a,b){var c=e.calculateOutputsSize(a.outs),d=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!1)+e.getLengthForVarInt(a.outs.length)+c+4,f=4+e.getLengthForVarInt(b.length)+this.estimateInputsSize(b,!0)+e.getLengthForVarInt(a.outs.length)+c+4;return 3*d+f},e.estimateTxVsize=function(a,b){return parseInt(Math.ceil(e.estimateTxWeight(a,b)/4),10)},b.exports=e}).call(this,a("buffer").Buffer)},{assert:20,"bitcoinjs-lib":43,buffer:105}],13:[function(a,b,c){var d=a("lodash"),e=a("q"),f=a("async"),g=function(a,b){this.defaultSettings={logging:!1,batchChunkSize:200},this.settings=d.merge({},this.defaultSettings,b),this.client=a};g.prototype.getUTXOs=function(a){var b=this,c={},g=e.defer();return f.eachSeries(d.chunk(a,b.settings.batchChunkSize),function(a,e){b.settings.logging&&console.log("checking batch of "+a.length+" addresses for UTXOs",a.join(",")),b.client.getBatchUnspentOutputs(a).done(function(a){d.each(a,function(a,b){a.length>0&&(c[b]=a)}),e()},function(a){e(a)})},function(a){a&&console.log("error encountered",a),g.resolve(c)}),g.promise},b.exports=g},{async:21,lodash:249,q:293}],14:[function(a,b,c){(function(a){var d=!a.browser,e=!d&&"undefined"!=typeof window&&"undefined"!=typeof window.Worker,f=("undefined"!=typeof navigator&&navigator.userAgent||"").match(/Android (\d)\.(\d)(\.(\d))/);f&&f[1]<=4&&(e=!1),b.exports=c=function(){return e}}).call(this,a("_process"))},{_process:263}],15:[function(a,b,c){(function(Buffer){var c=a("lodash"),d=a("assert"),e=a("q"),f=a("async"),g=a("bitcoinjs-lib"),h=a("bitcoinjs-message"),i=a("./blocktrail"),j=a("crypto-js"),k=a("./encryption"),l=a("./encryption_mnemonic"),m=a("./size_estimation"),n=a("bip39"),o={SIGN:"sign",DONT_SIGN:"dont_sign"},p=function(a,b,e,f,h,i,j,k,l,m,n,o,q,r,s,t){var u=this;u.sdk=a,u.identifier=b,u.walletVersion=e,u.locked=!0,u.bypassNewAddressCheck=!!t,u.bitcoinCash=u.sdk.bitcoinCash,d(0===o||!u.bitcoinCash),u.testnet=q,u.bitcoinCash?u.testnet?u.network=g.networks.bitcoincashtestnet:u.network=g.networks.bitcoincash:u.testnet?u.network=g.networks.testnet:u.network=g.networks.bitcoin,d(k instanceof g.HDNode),d(c.every(j,function(a){return a instanceof g.HDNode})),d(c.every(l,function(a){return a instanceof g.HDNode})),u.primaryMnemonic=f,u.encryptedPrimarySeed=h,u.encryptedSecret=i,u.primaryPrivateKey=null,u.backupPrivateKey=null,u.backupPublicKey=k,u.blocktrailPublicKeys=l,u.primaryPublicKeys=j,u.keyIndex=m;var v;v=u.bitcoinCash?p.CHAIN_BCC_DEFAULT:o?p.CHAIN_BTC_SEGWIT:p.CHAIN_BTC_DEFAULT,u.chain=v,u.checksum=r,u.upgradeToKeyIndex=s,u.secret=null,u.seedHex=null};p.WALLET_VERSION_V1="v1",p.WALLET_VERSION_V2="v2",p.WALLET_VERSION_V3="v3",p.WALLET_ENTROPY_BITS=256,p.OP_RETURN="opreturn",p.DATA=p.OP_RETURN,p.PAY_PROGRESS_START=0,p.PAY_PROGRESS_COIN_SELECTION=10,p.PAY_PROGRESS_CHANGE_ADDRESS=20,p.PAY_PROGRESS_SIGN=30,p.PAY_PROGRESS_SEND=40,p.PAY_PROGRESS_DONE=100,p.CHAIN_BTC_DEFAULT=0,p.CHAIN_BTC_SEGWIT=2,p.CHAIN_BCC_DEFAULT=1,p.FEE_STRATEGY_FORCE_FEE=i.FEE_STRATEGY_FORCE_FEE,p.FEE_STRATEGY_BASE_FEE=i.FEE_STRATEGY_BASE_FEE,p.FEE_STRATEGY_OPTIMAL=i.FEE_STRATEGY_OPTIMAL,p.FEE_STRATEGY_LOW_PRIORITY=i.FEE_STRATEGY_LOW_PRIORITY,p.FEE_STRATEGY_MIN_RELAY_FEE=i.FEE_STRATEGY_MIN_RELAY_FEE,p.prototype.isSegwit=function(){return p.CHAIN_BTC_SEGWIT===this.chain},p.prototype.unlock=function(a,b){var d=this,f=e.defer();return f.promise.nodeify(b),a=c.merge({},a),e.fcall(function(){switch(d.walletVersion){case p.WALLET_VERSION_V1:return d.unlockV1(a);case p.WALLET_VERSION_V2:return d.unlockV2(a);case p.WALLET_VERSION_V3:return d.unlockV3(a);default:return e.reject(new i.WalletInitError("Invalid wallet version"))}}).then(function(a){d.primaryPrivateKey=a;var b=d.primaryPrivateKey.getAddress();if(b!==d.checksum)throw new i.WalletChecksumError("Generated checksum ["+b+"] does not match ["+d.checksum+"], most likely due to incorrect password");if(d.locked=!1,"undefined"!=typeof d.upgradeToKeyIndex&&null!==d.upgradeToKeyIndex)return d.upgradeKeyIndex(d.upgradeToKeyIndex)}).then(function(a){f.resolve(a)},function(a){f.reject(a)}),f.promise},p.prototype.unlockV1=function(a){var b=this;return a.primaryMnemonic="undefined"!=typeof a.primaryMnemonic?a.primaryMnemonic:b.primaryMnemonic,a.secretMnemonic="undefined"!=typeof a.secretMnemonic?a.secretMnemonic:b.secretMnemonic,b.sdk.resolvePrimaryPrivateKeyFromOptions(a).then(function(a){return b.primarySeed=a.primarySeed,a.primaryPrivateKey})},p.prototype.unlockV2=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletDecryptError("specifying primaryPrivateKey has been deprecated");if(a.primarySeed)c.primarySeed=a.primarySeed;else if(a.secret)try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}else{if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");a.passphrase=a.passphrase||a.password;try{if(c.secret=j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedSecret),a.passphrase).toString(j.enc.Utf8),!c.secret.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt secret")}try{if(c.primarySeed=new Buffer(j.AES.decrypt(j.format.OpenSSL.parse(a.encryptedPrimarySeed),c.secret).toString(j.enc.Utf8),"base64"),!c.primarySeed.length)throw new Error}catch(a){throw new i.WalletDecryptError("Failed to decrypt primarySeed")}}return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})),d.promise},p.prototype.unlockV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),d.resolve(e.fcall(function(){return e.when().then(function(){if(a.encryptedPrimarySeed="undefined"!=typeof a.encryptedPrimarySeed?a.encryptedPrimarySeed:c.encryptedPrimarySeed,a.encryptedSecret="undefined"!=typeof a.encryptedSecret?a.encryptedSecret:c.encryptedSecret,a.secret&&(c.secret=a.secret),a.primaryPrivateKey)throw new i.WalletInitError("specifying primaryPrivateKey has been deprecated");if(!a.primarySeed){if(a.secret)return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")});if(a.passphrase&&a.password)throw new i.WalletCreateError("Can't specify passphrase and password");return a.passphrase=a.passphrase||a.password,delete a.password,c.sdk.promisedDecrypt(new Buffer(a.encryptedSecret,"base64"),new Buffer(a.passphrase)).then(function(a){c.secret=a},function(){throw new i.WalletDecryptError("Failed to decrypt secret")}).then(function(){return c.sdk.promisedDecrypt(new Buffer(a.encryptedPrimarySeed,"base64"),c.secret).then(function(a){c.primarySeed=a},function(){throw new i.WalletDecryptError("Failed to decrypt primarySeed")})})}c.primarySeed=a.primarySeed}).then(function(){return g.HDNode.fromSeedBuffer(c.primarySeed,c.network)})})),d.promise},p.prototype.lock=function(){var a=this;a.secret=null,a.primarySeed=null,a.primaryPrivateKey=null,a.backupPrivateKey=null,a.locked=!0},p.prototype.upgradeToV3=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.when(!0).then(function(){if(c.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to upgrade");if(c.walletVersion===p.WALLET_VERSION_V3)throw new i.WalletUpgradeError("Wallet is already V3");return c.walletVersion===p.WALLET_VERSION_V2?c._upgradeV2ToV3(a,d.notify.bind(d)):c.walletVersion===p.WALLET_VERSION_V1?c._upgradeV1ToV3(a,d.notify.bind(d)):void 0}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},p.prototype._upgradeV2ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed,recoverySecret:!1};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.sdk.updateWallet(c.identifier,{encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype._upgradeV1ToV3=function(a,b){var c=this;return e.when(!0).then(function(){var d={storeDataOnServer:!0,passphrase:a,primarySeed:c.primarySeed};return c.sdk.produceEncryptedDataV3(d,b||function(){}).then(function(a){return c.recoveryEncryptedSecret=a.recoveryEncryptedSecret,c.sdk.updateWallet(c.identifier,{primary_mnemonic:"",encrypted_primary_seed:a.encryptedPrimarySeed.toString("base64"),encrypted_secret:a.encryptedSecret.toString("base64"),recovery_secret:a.recoverySecret.toString("hex"),wallet_version:p.WALLET_VERSION_V3}).then(function(){return c.secret=a.secret,c.encryptedPrimarySeed=a.encryptedPrimarySeed,c.encryptedSecret=a.encryptedSecret,c.walletVersion=p.WALLET_VERSION_V3,c})})})},p.prototype.doPasswordChange=function(a){var b=this;return e.when(null).then(function(){if(b.walletVersion===p.WALLET_VERSION_V1)throw new i.WalletLockedError("Wallet version does not support password change!");if(b.locked)throw new i.WalletLockedError("Wallet needs to be unlocked to change password");if(!b.secret)throw new i.WalletLockedError("No secret");var c,d;if(b.walletVersion===p.WALLET_VERSION_V2)c=j.AES.encrypt(b.secret,a).toString(j.format.OpenSSL),d=n.entropyToMnemonic(i.convert(c,"base64","hex"));else{if("string"==typeof a)a=new Buffer(a);else if(!(a instanceof Buffer))throw new Error("New password must be provided as a string or a Buffer");c=k.encrypt(b.secret,a),d=l.encode(c),c=c.toString("base64")}return[c,d]})},p.prototype.passwordChange=function(a,b){var c=this,d=e.defer();return d.promise.nodeify(b),e.fcall(function(){return c.doPasswordChange(a).then(function(a){var b=a[0],d=a[1];return c.sdk.updateWallet(c.identifier,{encrypted_secret:b}).then(function(){return c.encryptedSecret=b,{encryptedSecret:d}})}).then(function(a){d.resolve(a)},function(a){d.reject(a)})}),d.promise},p.prototype.getAddressByPath=function(a){return this.getWalletScriptByPath(a).address},p.prototype.getRedeemScriptByPath=function(a){return this.getWalletScriptByPath(a).redeemScript},p.prototype.getWalletScriptByPath=function(a){var b,c,d=this,e=d.getPrimaryPublicKey(a),f=d.getBlocktrailPublicKey(a),h=p.deriveByPath(d.backupPublicKey,a.replace("'",""),"M"),i=p.sortMultiSigKeys([e.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),f.keyPair.getPublicKeyBuffer()]),j=g.script.multisig.output.encode(2,i),k=parseInt(a.split("/")[2]);"bitcoincash"!==this.network&&k===p.CHAIN_BTC_SEGWIT?(b=j,c=g.script.witnessScriptHash.output.encode(g.crypto.sha256(b))):(b=null,c=j);var l=g.script.scriptHash.output.encode(g.crypto.hash160(c)),m=g.address.fromOutputScript(l,this.network);return{witnessScript:b,redeemScript:c,scriptPubKey:l,address:m}},p.prototype.getPrimaryPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.primaryPublicKeys[c]){if(!b.primaryPrivateKey)throw new i.KeyPathError("Wallet.getPrimaryPublicKey keyIndex ("+c+") is unknown to us");b.primaryPublicKeys[c]=p.deriveByPath(b.primaryPrivateKey,"M/"+c+"'","m")}var d=b.primaryPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.getBlocktrailPublicKey=function(a){var b=this;a=a.replace("m","M");var c=a.split("/")[1].replace("'","");if(!b.blocktrailPublicKeys[c])throw new i.KeyPathError("Wallet.getBlocktrailPublicKey keyIndex ("+c+") is unknown to us");var d=b.blocktrailPublicKeys[c];return p.deriveByPath(d,a,"M/"+c+"'")},p.prototype.upgradeKeyIndex=function(a,b){var d=this,f=e.defer();if(f.promise.nodeify(b),d.locked)return f.reject(new i.WalletLockedError("Wallet needs to be unlocked to upgrade key index")),f.promise;var h=d.primaryPrivateKey.deriveHardened(a).neutered();return f.resolve(d.sdk.upgradeKeyIndex(d.identifier,a,[h.toBase58(),"M/"+a+"'"]).then(function(b){return d.keyIndex=a,c.forEach(b.blocktrail_public_keys,function(a,b){d.blocktrailPublicKeys[b]=g.HDNode.fromBase58(a[0],d.network)}),d.primaryPublicKeys[a]=h,!0})),f.promise},p.prototype.getNewAddress=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getNewDerivation(b.identifier,"M/"+b.keyIndex+"'/"+b.chain).then(function(a){var c=a.path,d=a.address;if(!b.bypassNewAddressCheck&&(d=b.getAddressByPath(a.path),d!==a.address))throw new i.WalletAddressError("Failed to verify address ["+a.address+"] !== ["+d+"]");return[d,c]})),c.promise},p.prototype.getBalance=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier).then(function(a){return[a.confirmed,a.unconfirmed]})),c.promise},p.prototype.getInfo=function(a){var b=this,c=e.defer();return c.promise.spreadNodeify(a),c.resolve(b.sdk.getWalletBalance(b.identifier)),c.promise},p.prototype.doDiscovery=function(a,b){var c=this;"function"==typeof a&&(b=a,a=null);var d=e.defer();return d.promise.spreadNodeify(b),d.resolve(c.sdk.doWalletDiscovery(c.identifier,a).then(function(a){return[a.confirmed,a.unconfirmed]})),d.promise},p.prototype.deleteWallet=function(a,b){var c=this;"function"==typeof a&&(b=a,a=!1);var d=e.defer();if(d.promise.nodeify(b),c.locked)return d.reject(new i.WalletDeleteError("Wallet needs to be unlocked to delete wallet")),d.promise;var f=c.primaryPrivateKey.getAddress(),g=c.primaryPrivateKey.keyPair.d.toBuffer(32),j=h.sign(f,c.network.messagePrefix,g,!0).toString("base64");return d.resolve(c.sdk.deleteWallet(c.identifier,f,j,a).then(function(a){return a.deleted})),d.promise},p.prototype.pay=function(a,b,c,d,f,g,h,j){var k=this;"function"==typeof b?(j=b,b=null):"function"==typeof c?(j=c,c=!1):"function"==typeof d?(j=d,d=!0):"function"==typeof f?(j=f,f=null):"function"==typeof g?(j=g,g=null):"function"==typeof h&&(j=h,h={}),d="undefined"==typeof d||d,f=f||p.FEE_STRATEGY_OPTIMAL,h=h||{};var l="undefined"==typeof h.checkFee||h.checkFee,m=e.defer();return m.promise.nodeify(j),k.locked?(m.reject(new i.WalletLockedError("Wallet needs to be unlocked to send coins")),m.promise):(e.nextTick(function(){m.notify(p.PAY_PROGRESS_START),k.buildTransaction(a,b,c,d,f,h).then(function(a){return a},function(a){m.reject(a)},function(a){m.notify(a)}).spread(function(a,b){m.notify(p.PAY_PROGRESS_SEND);var c={signed_transaction:a.toHex(),base_transaction:a.__toBuffer(null,null,!1).toString("hex")};return k.sendTransaction(c,b.map(function(a){return a.path}),l,g,h.prioboost).then(function(a){return m.notify(p.PAY_PROGRESS_DONE),a&&a.complete&&"false"!==a.complete?a.txid:void m.reject(new i.TransactionSignError("Failed to completely sign transaction"))})},function(a){throw a}).then(function(a){m.resolve(a)},function(a){m.reject(a)})}),m.promise)},p.prototype.decodeAddress=function(a){return p.getAddressAndType(a,this.network)},p.getAddressAndType=function(a,b){var c,d,e;if(b===g.networks.bitcoin||b===g.networks.testnet){try{c=g.address.fromBech32(a,b),e=null,d="bech32"}catch(a){e=a}if(!e&&c.prefix!==b.bech32)throw new i.InvalidAddressError("Address invalid on this network")}if(!c){try{c=g.address.fromBase58Check(a),e=null,d="base58"}catch(a){e=a}if(!e&&c.version!==b.pubKeyHash&&c.version!==b.scriptHash)throw new i.InvalidAddressError("Address invalid on this network")}if(e)throw new i.InvalidAddressError(e.message);return{address:a,decoded:c,type:d}},p.convertPayToOutputs=function(a,b){var c,d=[];if(Array.isArray(a))c=function(a,b,c){if("object"!=typeof b)throw new Error("Invalid transaction output for numerically indexed list [1]");var d=Object.keys(b);if(d.indexOf("scriptPubKey")!==-1&&d.indexOf("value")!==-1)c.scriptPubKey=b.scriptPubKey,c.value=b.value;else if(d.indexOf("address")!==-1&&d.indexOf("value")!==-1)c.address=b.address,c.value=b.value;else{if(2===d.length||2===b.length||0===d[0]||1===d[1])throw new Error("Invalid transaction output for numerically indexed list [2]");c.address=b[0],c.value=b[1]}};else{if("object"!=typeof a)throw new Error("Invalid input");c=function(a,b,c){if(c.address=a.trim(),c.value=b,c.address===p.OP_RETURN){var d=Buffer.isBuffer(b)?b:new Buffer(b,"utf-8");c.scriptPubKey=g.script.nullData.output.encode(d).toString("hex"),c.value=0,c.address=null}}}return Object.keys(a).forEach(function(e){var f={};if(c(e,a[e],f),parseInt(f.value,10).toString()!==f.value.toString())throw new i.WalletSendError("Values should be in Satoshis");if("string"==typeof f.address)try{var h=p.getAddressAndType(f.address,b);f.scriptPubKey=g.address.toOutputScript(h.address,b).toString("hex"),delete f.address}catch(a){throw new i.InvalidAddressError("Invalid address ["+f.address+"] ("+a.message+")")}if("6a"!==f.scriptPubKey.slice(0,2)){if(!(f.value=parseInt(f.value,10)))throw new i.WalletSendError("Values should be non zero");if(f.value<=i.DUST)throw new i.WalletSendError("Values should be more than dust ("+i.DUST+")")}f.value=parseInt(f.value,10),d.push(f)}),d},p.prototype.buildTransaction=function(a,b,d,h,j,k,l){var m=this;"function"==typeof b?(l=b,b=null):"function"==typeof d?(l=d,d=!1):"function"==typeof h?(l=h,h=!0):"function"==typeof j?(l=j,j=null):"function"==typeof k&&(l=k,k={}),h="undefined"==typeof h||h,j=j||p.FEE_STRATEGY_OPTIMAL,k=k||{};var n=e.defer();return n.promise.spreadNodeify(l),e.nextTick(function(){var l;try{l=p.convertPayToOutputs(a,m.network)}catch(a){return n.reject(a),n.promise}return l.length?(n.notify(p.PAY_PROGRESS_COIN_SELECTION),void n.resolve(m.coinSelection(l,!0,d,j,k).spread(function(a,d,k){var n,q,r=[],s=e.defer();return f.waterfall([function(b){var c=a.map(function(a){return a.value}).reduce(function(a,b){return a+b}),e=l.map(function(a){return a.value}).reduce(function(a,b){return a+b}),f=c-e-d;return f>2*i.DUST&&f!==k?b(new i.WalletFeeError("the amount of change ("+k+") suggested by the coin selection seems incorrect ("+f+")")):void b()},function(a){q=new g.TransactionBuilder(m.network),m.bitcoinCash&&q.enableBitcoinCash(),a()},function(b){var c;for(c=0;c<a.length;c++)q.addInput(a[c].hash,a[c].idx);b()},function(a){l.forEach(function(a){if(a.address)r.push({address:a.address,value:a.value});else{if(!a.scriptPubKey)throw new Error("Invalid send");r.push({scriptPubKey:new Buffer(a.scriptPubKey,"hex"),value:a.value})}}),a()},function(a){if(k>0)if(k<=i.DUST)k=0;else if(!b)return s.notify(p.PAY_PROGRESS_CHANGE_ADDRESS),m.getNewAddress(function(c,d){return c?a(c):(b=d,void a())});a()},function(a){k>0&&(h?r.splice(c.random(0,r.length),0,{address:b,value:k}):r.push({address:b,value:k})),a()},function(a){r.forEach(function(a){q.addOutput(a.scriptPubKey||a.address,a.value)}),a()},function(b){var c,d,e,f,h;for(s.notify(p.PAY_PROGRESS_SIGN),c=0;c<a.length;c++){var i=o.SIGN;if(a[c].sign_mode&&(i=a[c].sign_mode),f=null,h=null,i===o.SIGN){if(e=a[c].path.replace("M","m"),m.primaryPrivateKey)d=p.deriveByPath(m.primaryPrivateKey,e,"m").keyPair;else{if(!m.backupPrivateKey)throw new Error("No master privateKey present");d=p.deriveByPath(m.backupPrivateKey,e.replace(/^m\/(\d+)\'/,"m/$1"),"m").keyPair}f=new Buffer(a[c].redeem_script,"hex"),"string"==typeof a[c].witness_script&&(h=new Buffer(a[c].witness_script,"hex"));var j=g.Transaction.SIGHASH_ALL;
3
m.bitcoinCash&&(j|=g.Transaction.SIGHASH_BITCOINCASHBIP143),q.sign(c,d,f,j,a[c].value,h)}}n=q.buildIncomplete(),b()},function(b){var c=p.estimateVsizeFee(n,a);if(m.sdk.feeSanityCheck)switch(j){case p.FEE_STRATEGY_BASE_FEE:if(Math.abs(c-d)>i.BASE_FEE)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems incorrect ("+c+") for FEE_STRATEGY_BASE_FEE"));break;case p.FEE_STRATEGY_OPTIMAL:if(d>c*m.feeSanityCheckBaseFeeMultiplier)return b(new i.WalletFeeError("the fee suggested by the coin selection ("+d+") seems awefully high ("+c+") for FEE_STRATEGY_OPTIMAL"))}b()}],function(b){return b?void s.reject(new i.WalletSendError(b)):void s.resolve([n,a])}),s.promise}))):(n.reject(new i.WalletSendError("Need at least one recipient")),n.promise)}),n.promise},p.prototype.coinSelection=function(a,b,c,d,f,g){var h=this;"function"==typeof b?(g=b,b=!0):"function"==typeof c?(g=c,c=!1):"function"==typeof d?(g=d,d=null):"function"==typeof f&&(g=f,f={}),b="undefined"==typeof b||b,d=d||p.FEE_STRATEGY_OPTIMAL,f=f||{};var i;try{i=p.convertPayToOutputs(a,h.network)}catch(a){var j=e.defer();return j.promise.nodeify(g),j.reject(a),j.promise}return h.sdk.coinSelection(h.identifier,i,b,c,d,f,g)},p.prototype.sendTransaction=function(a,b,c,d,f,g){var h=this;"function"==typeof d?(g=d,d=null,f=!1):"function"==typeof f&&(g=d,f=!1);var j=e.defer();return j.promise.nodeify(g),h.sdk.sendTransaction(h.identifier,a,b,c,d,f).then(function(a){j.resolve(a)},function(a){a.requires_2fa?j.reject(new i.WalletMissing2FAError):a.message.match(/Invalid two_factor_token/)?j.reject(new i.WalletInvalid2FAError):j.reject(a)}),j.promise},p.prototype.setupWebhook=function(a,b,c){var d=this;return"function"==typeof b&&(c=b,b=null),b=b||"WALLET-"+d.identifier,d.sdk.setupWalletWebhook(d.identifier,b,a,c)},p.prototype.deleteWebhook=function(a,b){var c=this;return"function"==typeof a&&(b=a,a=null),a=a||"WALLET-"+c.identifier,c.sdk.deleteWalletWebhook(c.identifier,a,b)},p.prototype.transactions=function(a,b){var c=this;return c.sdk.walletTransactions(c.identifier,a,b)},p.prototype.maxSpendable=function(a,b,c,d){var e=this;return"function"==typeof a?(d=a,a=!1):"function"==typeof b?(d=b,b=null):"function"==typeof c&&(d=c,c={}),"object"==typeof a?(c=a,a=!1):"object"==typeof b&&(c=b,b=null),c=c||{},"undefined"!=typeof c.allowZeroConf&&(a=c.allowZeroConf),"undefined"!=typeof c.feeStrategy&&(b=c.feeStrategy),b=b||p.FEE_STRATEGY_OPTIMAL,e.sdk.walletMaxSpendable(e.identifier,a,b,c,d)},p.prototype.addresses=function(a,b){var c=this;return c.sdk.walletAddresses(c.identifier,a,b)},p.prototype.labelAddress=function(a,b,c){var d=this;return d.sdk.labelWalletAddress(d.identifier,a,b,c)},p.prototype.utxos=function(a,b){var c=this;return c.sdk.walletUTXOs(c.identifier,a,b)},p.prototype.unspentOutputs=p.prototype.utxos,p.sortMultiSigKeys=function(a){return a.sort(function(a,b){return a.toString("hex").localeCompare(b.toString("hex"))}),a},p.estimateIncompleteTxFee=function(a,b){var c=p.estimateIncompleteTxSize(a),d=c/1e3,e=Math.ceil(c/1e3);return b?parseInt(d*b,10):parseInt(e*i.BASE_FEE,10)},p.estimateVsizeFee=function(a,b,c){var d=m.estimateTxVsize(a,b),e=d/1e3,f=Math.ceil(d/1e3);return c?parseInt(e*c,10):parseInt(f*i.BASE_FEE,10)},p.estimateIncompleteTxSize=function(a){var b=16;return b+=34*a.outs.length,a.ins.forEach(function(a){var c=a.script,d=g.script.classifyInput(c),e=[2,3];if(!e&&"scripthash"===d){var f=g.script.decompile(c),h=f.slice(-1)[0];if(c=g.script.compile(f.slice(0,-1)),d=g.script.classifyInput(c),g.script.classifyOutput(h)!==d)throw new i.TransactionInputError("Non-matching scriptSig and scriptPubKey in input");if("multisig"===d){var j=g.script.decompile(h),k=j[0];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var l=j[h.chunks.length-2];if(k===g.opcodes.OP_0||k<g.opcodes.OP_1||k>g.opcodes.OP_16)throw new i.TransactionInputError("Invalid multisig redeemScript");var m=k-(g.opcodes.OP_1-1),n=l-(g.opcodes.OP_1-1);if(n<m)throw new i.TransactionInputError("Invalid multisig redeemScript");e=[m,n]}}b+=e?40+73*e[0]+107+4:147}),b},p.estimateFee=function(a,b){var c=16;c+=34*b,c+=297*a;var d=Math.ceil(c/1e3);return d*i.BASE_FEE},p.deriveByPath=function(a,b,c){if(c=c||(a.keyPair.d?"m":"M"),"m"!==b[0].toLowerCase()||"m"!==c[0].toLowerCase())throw new i.KeyPathError("Wallet.deriveByPath only works with absolute paths. ("+b+", "+c+")");if("m"===b[0]&&"M"===c[0])throw new i.KeyPathError("Wallet.deriveByPath can't derive private path from public parent. ("+b+", "+c+")");var d="M"===b[0]&&"m"===c[0];if(d&&(b[0]="m"),0!==b.toLowerCase().indexOf(c.toLowerCase()))throw new i.KeyPathError("Wallet.derivePath requires path ("+b+") to be a child of keyPath ("+c+")");b=b.substr(c.length);var e=a;return b.replace(/^\//,"").split("/").forEach(function(a){a&&(a.indexOf("'")!==-1&&(a=parseInt(a.replace("'",""),10)+g.HDNode.HIGHEST_BIT),e=e.derive(parseInt(a,10)))}),d?e.neutered():e},b.exports=p}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./size_estimation":12,assert:20,async:21,bip39:28,"bitcoinjs-lib":43,"bitcoinjs-message":72,buffer:105,"crypto-js":185,lodash:249,q:293}],16:[function(a,b,c){(function(Buffer){var c=a("./unspent_output_finder"),d=a("bitcoinjs-lib"),e=a("bip39"),f=a("crypto-js"),g=a("./blocktrail"),h=a("./encryption_mnemonic"),i=a("./encryption"),j=a("./wallet"),k=a("lodash"),l=a("q"),m=a("async"),n=function(a,b,j){var l=this;this.defaultSettings={network:"btc",testnet:!1,logging:!1,bitcoinCash:!1,sweepBatchSize:200},this.settings=k.merge({},this.defaultSettings,j),this.bitcoinDataClient=b,this.utxoFinder=new c(b,this.settings),this.sweepData=null,"object"==typeof j.network?this.network=j.network:this.network=this.getBitcoinNetwork(this.settings.network,this.settings.testnet),a.walletVersion=a.walletVersion||2;var m=!1;if(!Array.isArray(a.blocktrailKeys))throw new Error("blocktrail pub keys are required (must be type Array)");switch(a.walletVersion){case 1:if("undefined"==typeof a.primaryMnemonic||!a.primaryMnemonic)throw new Error("missing primary mnemonic for version 1 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic)throw new Error("missing backup mnemonic for version 1 wallet");if("undefined"==typeof a.primaryPassphrase)throw new Error("missing primary passphrase for version 1 wallet");a.primaryMnemonic=a.primaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=a.backupMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;case 2:case 3:if("undefined"==typeof a.encryptedPrimaryMnemonic||!a.encryptedPrimaryMnemonic)throw new Error("missing encrypted primary seed for version 2 wallet");if("undefined"==typeof a.backupMnemonic||!a.backupMnemonic&&a.backupMnemonic!==!1)throw new Error("missing backup seed for version 2 wallet");if(m="undefined"!=typeof a.password&&null!==a.password){if("undefined"==typeof a.passwordEncryptedSecretMnemonic||!a.passwordEncryptedSecretMnemonic)throw new Error("missing password encrypted secret for version 2 wallet");if("undefined"==typeof a.password)throw new Error("missing primary passphrase for version 2 wallet")}else{if("undefined"==typeof a.encryptedRecoverySecretMnemonic||!a.encryptedRecoverySecretMnemonic)throw new Error("missing encrypted recovery secret for version 2 wallet (recovery without password)");if(!a.recoverySecretDecryptionKey)throw new Error("missing recovery secret decryption key for version 2 wallet (recovery without password)")}a.encryptedPrimaryMnemonic=a.encryptedPrimaryMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.backupMnemonic=(a.backupMnemonic||"").trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "),a.recoverySecretDecryptionKey&&(a.recoverySecretDecryptionKey=a.recoverySecretDecryptionKey.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ")),m?a.passwordEncryptedSecretMnemonic=a.passwordEncryptedSecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," "):a.encryptedRecoverySecretMnemonic=a.encryptedRecoverySecretMnemonic.trim().replace(new RegExp("\r\n","g")," ").replace(new RegExp("\n","g")," ").replace(/\s+/g," ");break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.blocktrailPublicKeys={},k.each(a.blocktrailKeys,function(a){l.blocktrailPublicKeys[a.keyIndex]=d.HDNode.fromBase58(a.pubkey,l.network)});var n,o,p;switch(a.walletVersion){case 1:n=e.mnemonicToSeed(a.primaryMnemonic,a.primaryPassphrase),o=e.mnemonicToSeed(a.backupMnemonic,"");break;case 2:if(a.encryptedPrimaryMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedPrimaryMnemonic),"hex","base64"),m?a.passwordEncryptedSecretMnemonic=g.convert(e.mnemonicToEntropy(a.passwordEncryptedSecretMnemonic),"hex","base64"):a.encryptedRecoverySecretMnemonic=g.convert(e.mnemonicToEntropy(a.encryptedRecoverySecretMnemonic),"hex","base64"),p=m?f.AES.decrypt(a.passwordEncryptedSecretMnemonic,a.password).toString(f.enc.Utf8):f.AES.decrypt(a.encryptedRecoverySecretMnemonic,a.recoverySecretDecryptionKey).toString(f.enc.Utf8),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=new Buffer(f.AES.decrypt(a.encryptedPrimaryMnemonic,p).toString(f.enc.Utf8),"base64"),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;case 3:if(a.encryptedPrimaryMnemonic=h.decode(a.encryptedPrimaryMnemonic),m?a.passwordEncryptedSecretMnemonic=h.decode(a.passwordEncryptedSecretMnemonic):a.encryptedRecoverySecretMnemonic=h.decode(a.encryptedRecoverySecretMnemonic),p=m?i.decrypt(a.passwordEncryptedSecretMnemonic,new Buffer(a.password)):i.decrypt(a.encryptedRecoverySecretMnemonic,new Buffer(a.recoverySecretDecryptionKey,"hex")),!p)throw new Error("Could not decrypt secret with "+(m?"password":"decryption key"));n=i.decrypt(a.encryptedPrimaryMnemonic,p),a.backupMnemonic&&(o=new Buffer(e.mnemonicToEntropy(a.backupMnemonic),"hex"));break;default:throw new Error("Wrong version ["+a.walletVersion+"]")}this.primaryPrivateKey=d.HDNode.fromSeedBuffer(n,this.network),o?(this.backupPrivateKey=d.HDNode.fromSeedBuffer(o,this.network),this.backupPublicKey=this.backupPrivateKey.neutered()):(this.backupPrivateKey=!1,this.backupPublicKey=d.HDNode.fromBase58(a.backupPublicKey,this.network)),this.settings.logging&&(console.log("using password method: "+m),console.log("Primary Prv Key: "+this.primaryPrivateKey.toBase58()),console.log("Primary Pub Key: "+this.primaryPrivateKey.neutered().toBase58()),console.log("Backup Prv Key: "+(this.backupPrivateKey?this.backupPrivateKey.toBase58():null)),console.log("Backup Pub Key: "+this.backupPublicKey.toBase58()))};n.prototype.getBitcoinNetwork=function(a,b){switch(a.toLowerCase()){case"btc":case"bitcoin":return b?d.networks.testnet:d.networks.bitcoin;case"tbtc":case"bitcoin-testnet":return d.networks.testnet;default:throw new Error("Unknown network "+a)}},n.prototype.getBlocktrailPublicKey=function(a){a=a.replace("m","M");var b=a.split("/")[1].replace("'","");if(!this.blocktrailPublicKeys[b])throw new Error("Wallet.getBlocktrailPublicKey keyIndex ("+b+") is unknown to us");return this.blocktrailPublicKeys[b]},n.prototype.createAddress=function(a){a=a.replace("m","M");var b,c,e=a.split("/")[1].replace("'",""),f=parseInt(a.split("/")[2]),g=j.deriveByPath(this.primaryPrivateKey,a,"m"),h=j.deriveByPath(this.backupPublicKey,a.replace("'",""),"M"),i=j.deriveByPath(this.getBlocktrailPublicKey(a),a,"M/"+e+"'"),k=j.sortMultiSigKeys([g.keyPair.getPublicKeyBuffer(),h.keyPair.getPublicKeyBuffer(),i.keyPair.getPublicKeyBuffer()]),l=d.script.multisig.output.encode(2,k);"bitcoincash"!==this.network&&f===j.CHAIN_BTC_SEGWIT?(c=l,b=d.script.witnessScriptHash.output.encode(d.crypto.sha256(c))):(c=null,b=l);var m=d.crypto.hash160(b),n=d.script.scriptHash.output.encode(m),o=this.network;"undefined"!=typeof this.network&&(o=this.network);var p=d.address.fromOutputScript(n,o);return{address:p.toString(),redeem:b,witness:c}},n.prototype.createBatchAddresses=function(a,b,c,d){var e=this,f={};return l.all(k.range(0,b).map(function(b){var g="M/"+c+"'/"+d+"/"+(a+b),h=e.createAddress(g);f[h.address]={redeem:h.redeem,witness:h.witness,path:g}})).then(function(){return f})},n.prototype.discoverWalletFunds=function(a,b){var c=this,d=0,e=0,f=0,g={};"undefined"==typeof a&&(a=this.settings.sweepBatchSize);var h=l.defer();h.promise.nodeify(b);var i;return i="bitcoincash"===this.network?[0,1]:[0,1,2],m.nextTick(function(){m.eachSeries(Object.keys(c.blocktrailPublicKeys),function(b,j){m.eachSeries(i,function(i,j){var n=0,o=!1;m.doWhilst(function(j){c.settings.logging&&console.log("generating addresses "+n+" -> "+(n+a)+" using blocktrail key index: "+b+", chain: "+i),h.notify({message:"generating addresses "+n+" -> "+(n+a),increment:a,btPubKeyIndex:b,chain:i,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),m.nextTick(function(){c.createBatchAddresses(n,a,b,i).then(function(i){return f+=Object.keys(i).length,c.settings.logging&&console.log("starting fund discovery for "+a+" addresses..."),h.notify({message:"starting fund discovery for "+a+" addresses",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d}),c.bitcoinDataClient.batchAddressHasTransactions(k.keys(i)).then(function(j){return o=j,c.settings.logging&&console.log("batch "+(o?"has":"does not have")+" transactions..."),l.when(o).then(function(j){if(j)return c.utxoFinder.getUTXOs(k.keys(i)).then(function(j){k.each(j,function(a,b){var f=null;"undefined"!=typeof i[b].witness&&(f=i[b].witness),g[b]={path:i[b].path,redeem:i[b].redeem,witness:f,utxos:a},e+=a.length,d=k.reduce(a,function(a,b){return a+b.value},d),c.settings.logging&&console.log("found "+a.length+" unspent outputs for address: "+b)}),h.notify({message:"discovering funds",increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})})})})}).then(function(){n+=a,m.nextTick(j)},function(a){j(a)})})},function(){return o},function(c){c&&(console.log("batch complete, but with errors",c.message),h.notify({message:"batch complete, but with errors: "+c.message,error:c,increment:a,btPubKeyIndex:b,totalAddresses:f,addressUTXOs:g,totalUTXOs:e,totalBalance:d})),m.nextTick(j)})},function(a){j(a)})},function(a){a&&c.settings.logging&&console.log("error encountered when discovering funds",a),c.settings.logging&&console.log("finished fund discovery: "+d+" Satoshi (in "+e+" outputs) found when searching "+f+" addresses"),c.sweepData={utxos:g,count:e,balance:d,addressesSearched:f},h.resolve(c.sweepData)})}),h.promise},n.prototype.sweepWallet=function(a,b){var c=this,d=l.defer();return d.promise.nodeify(b),c.settings.logging&&console.log("starting wallet sweeping to address "+a),l.when(!0).then(function(){if(!c.sweepData)return c.discoverWalletFunds().progress(function(a){d.notify(a)})}).then(function(){return c.bitcoinDataClient.estimateFee()}).then(function(b){return 0===c.sweepData.balance?(d.reject("No funds found after searching through "+c.sweepData.addressesSearched+" addresses"),d.promise):c.createTransaction(a,null,b,d)}).then(function(a){d.resolve(a)},function(a){d.reject(a)}),d.promise},n.prototype.createTransaction=function(a,b,c,e){var f=this;this.settings.logging&&console.log("Creating transaction to address destinationAddress"),e&&e.notify({message:"creating raw transaction to "+a});var h=new d.TransactionBuilder(this.network);this.settings.bitcoinCash&&h.enableBitcoinCash();var i=[];if(k.each(this.sweepData.utxos,function(a,b){k.each(a.utxos,function(c){h.addInput(c.hash,c.index),i.push({txid:c.hash,vout:c.index,scriptPubKey:c.script_hex,value:c.value,address:b,path:a.path,redeemScript:a.redeem,witnessScript:a.witness})})}),!h)throw new Error("Failed to create raw transaction");var l=f.sweepData.balance,m=h.addOutput(a,l);if("undefined"==typeof b||null===b){e&&e.notify({message:"estimating transaction fee, based on "+g.toBTC(c)+" BTC/kb"});var n=i.map(function(a){return{txid:a.txid,vout:a.vout,address:a.vout,scriptpubkey_hex:a.vout,redeem_script:a.redeemScript,witness_script:a.witnessScript,path:a.path,value:a.value}});b=j.estimateVsizeFee(h.tx,n,c)}return h.tx.outs[m].value-=b,e&&e.notify({message:"signing transaction"}),this.signTransaction(h,i)},n.prototype.signTransaction=function(a,b){var c=this;this.settings.logging&&console.log("Signing transaction");var e=d.Transaction.SIGHASH_ALL;return this.settings.bitcoinCash&&(e|=d.Transaction.SIGHASH_BITCOINCASHBIP143),k.each(b,function(b,d){var f=j.deriveByPath(c.primaryPrivateKey,b.path.replace("M","m"),"m").keyPair;if(a.sign(d,f,b.redeemScript,e,b.value,b.witnessScript),c.backupPrivateKey){var g=j.deriveByPath(c.backupPrivateKey,b.path.replace("'","").replace("M","m"),"m").keyPair;a.sign(d,g,b.redeemScript,e,b.value,b.witnessScript)}}),c.backupPrivateKey?a.build().toHex():a.buildIncomplete().toHex()},b.exports=n}).call(this,a("buffer").Buffer)},{"./blocktrail":2,"./encryption":3,"./encryption_mnemonic":4,"./unspent_output_finder":13,"./wallet":15,async:21,bip39:28,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,lodash:249,q:293}],17:[function(a,b,c){(function(Buffer){var c=a("bip39"),d=a("./encryption");b.exports=function(a){a.addEventListener("message",function(b){var e=b.data||{};switch(e.method){case"mnemonicToSeedHex":!function(){try{var d=e.mnemonic,f=e.passphrase;if(!c.validateMnemonic(d))throw b=new Error("Invalid passphrase"),b.id=e.id,b;var g=c.mnemonicToSeedHex(d,f);a.postMessage({id:e.id,seed:g,mnemonic:d})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.encryptWithSaltAndIV":!function(){try{if(!(e.pt&&e.pw&&e.saltBuf&&e.iv&&e.iterations))throw new Error("Invalid input");var b=Buffer.from(e.pt.buffer),c=Buffer.from(e.pw.buffer),f=Buffer.from(e.saltBuf.buffer),g=Buffer.from(e.iv.buffer),h=e.iterations,i=d.encryptWithSaltAndIV(b,c,f,g,h);a.postMessage({id:e.id,cipherText:i})}catch(a){throw a.id=e.id,a}}();break;case"Encryption.decrypt":!function(){try{if(!e.ct||!e.pw)throw new Error("Invalid input");var b=Buffer.from(e.ct.buffer),c=Buffer.from(e.pw.buffer),f=d.decrypt(b,c);a.postMessage({id:e.id,plainText:f})}catch(a){throw a.id=e.id,a}}();break;default:throw b=new Error("Invalid method ["+b.method+"]"),b.id=e.id,b}},!1)}}).call(this,a("buffer").Buffer)},{"./encryption":3,bip39:28,buffer:105}],18:[function(a,b,c){var d=a("q"),e=a("webworkify");b.exports=c={workify:function(a,b,c){var f=d.defer();try{"undefined"==typeof a.worker&&(a.worker=e(b()),a.first=!0,a.id=0);var g=a.worker,h=a.id++,i=function(b){a.first&&(a.first=!1,URL.revokeObjectURL(g.objectURL)),b.data.id===h&&f.resolve(b.data)},j=function(a){f.reject(new Error(a.message.replace("Uncaught Error: ","")))},k=function(){g.removeEventListener("message",i),g.removeEventListener("error",j)};return g.addEventListener("message",i,!1),g.addEventListener("error",j,!1),c.id=h,g.postMessage(c),f.promise.then(function(a){return k(),a},function(a){throw k(),a})}catch(a){return f.reject(a),f.promise}}}},{q:293,webworkify:363}],19:[function(a,b,c){(function(Buffer){var d=a("./lib/api_client"),e=a("./lib/blocktrail");Object.keys(e).forEach(function(a){d[a]=e[a]}),d.q=a("q"),d.BlocktrailSDK=d,d.Wallet=a("./lib/wallet"),d.Request=a("./lib/request"),d.Encryption=a("./lib/encryption"),d.KeyDerivation=a("./lib/keyderivation"),d.EncryptionMnemonic=a("./lib/encryption_mnemonic"),d.useWebworker=a("./lib/use-webworker"),d.WalletSweeper=a("./lib/wallet_sweeper"),d.UnspentOutputFinder=a("./lib/unspent_output_finder"),d.BlocktrailBitcoinService=a("./lib/services/blocktrail_bitcoin_service"),d.InsightBitcoinService=a("./lib/services/insight_bitcoin_service"),d.randomBytes=a("randombytes"),d.lodash=a("lodash"),d.CryptoJS=a("crypto-js"),d.debug=a("debug"),d.bip39=a("bip39"),d.bip39wordlist=a("bip39/wordlists/en.json"),d.bitcoin=a("bitcoinjs-lib"),d.superagent=a("superagent"),d.Buffer=Buffer,d.VERSION=a("./lib/pkginfo").VERSION,c=b.exports=d}).call(this,a("buffer").Buffer)},{"./lib/api_client":1,"./lib/blocktrail":2,"./lib/encryption":3,"./lib/encryption_mnemonic":4,"./lib/keyderivation":5,"./lib/pkginfo":7,"./lib/request":8,"./lib/services/blocktrail_bitcoin_service":10,"./lib/services/insight_bitcoin_service":11,"./lib/unspent_output_finder":13,"./lib/use-webworker":14,"./lib/wallet":15,"./lib/wallet_sweeper":16,bip39:28,"bip39/wordlists/en.json":31,"bitcoinjs-lib":43,buffer:105,"crypto-js":185,debug:211,lodash:249,q:293,randombytes:297,superagent:349}],20:[function(a,b,c){(function(c){"use strict";function d(a,b){if(a===b)return 0;for(var c=a.length,d=b.length,e=0,f=Math.min(c,d);e<f;++e)if(a[e]!==b[e]){c=a[e],d=b[e];break}return c<d?-1:d<c?1:0}function e(a){return c.Buffer&&"function"==typeof c.Buffer.isBuffer?c.Buffer.isBuffer(a):!(null==a||!a._isBuffer)}function f(a){return Object.prototype.toString.call(a)}function g(a){return!e(a)&&("function"==typeof c.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(a):!!a&&(a instanceof DataView||!!(a.buffer&&a.buffer instanceof ArrayBuffer))))}function h(a){if(u.isFunction(a)){if(x)return a.name;var b=a.toString(),c=b.match(z);return c&&c[1]}}function i(a,b){return"string"==typeof a?a.length<b?a:a.slice(0,b):a}function j(a){if(x||!u.isFunction(a))return u.inspect(a);var b=h(a),c=b?": "+b:"";return"[Function"+c+"]"}function k(a){return i(j(a.actual),128)+" "+a.operator+" "+i(j(a.expected),128)}function l(a,b,c,d,e){throw new y.AssertionError({message:c,actual:a,expected:b,operator:d,stackStartFunction:e})}function m(a,b){a||l(a,!0,b,"==",y.ok)}function n(a,b,c,h){if(a===b)return!0;if(e(a)&&e(b))return 0===d(a,b);if(u.isDate(a)&&u.isDate(b))return a.getTime()===b.getTime();if(u.isRegExp(a)&&u.isRegExp(b))return a.source===b.source&&a.global===b.global&&a.multiline===b.multiline&&a.lastIndex===b.lastIndex&&a.ignoreCase===b.ignoreCase;if(null!==a&&"object"==typeof a||null!==b&&"object"==typeof b){if(g(a)&&g(b)&&f(a)===f(b)&&!(a instanceof Float32Array||a instanceof Float64Array))return 0===d(new Uint8Array(a.buffer),new Uint8Array(b.buffer));if(e(a)!==e(b))return!1;h=h||{actual:[],expected:[]};var i=h.actual.indexOf(a);return i!==-1&&i===h.expected.indexOf(b)||(h.actual.push(a),h.expected.push(b),p(a,b,c,h))}return c?a===b:a==b}function o(a){return"[object Arguments]"==Object.prototype.toString.call(a)}function p(a,b,c,d){if(null===a||void 0===a||null===b||void 0===b)return!1;if(u.isPrimitive(a)||u.isPrimitive(b))return a===b;if(c&&Object.getPrototypeOf(a)!==Object.getPrototypeOf(b))return!1;var e=o(a),f=o(b);if(e&&!f||!e&&f)return!1;if(e)return a=w.call(a),b=w.call(b),n(a,b,c);var g,h,i=A(a),j=A(b);if(i.length!==j.length)return!1;for(i.sort(),j.sort(),h=i.length-1;h>=0;h--)if(i[h]!==j[h])return!1;for(h=i.length-1;h>=0;h--)if(g=i[h],!n(a[g],b[g],c,d))return!1;return!0}function q(a,b,c){n(a,b,!0)&&l(a,b,c,"notDeepStrictEqual",q)}function r(a,b){if(!a||!b)return!1;if("[object RegExp]"==Object.prototype.toString.call(b))return b.test(a);try{if(a instanceof b)return!0}catch(a){}return!Error.isPrototypeOf(b)&&b.call({},a)===!0}function s(a){var b;try{a()}catch(a){b=a}return b}function t(a,b,c,d){var e;if("function"!=typeof b)throw new TypeError('"block" argument must be a function');"string"==typeof c&&(d=c,c=null),e=s(b),d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&l(e,c,"Missing expected exception"+d);var f="string"==typeof d,g=!a&&u.isError(e),h=!a&&e&&!c;if((g&&f&&r(e,c)||h)&&l(e,c,"Got unwanted exception"+d),a&&e&&c&&!r(e,c)||!a&&e)throw e}var u=a("util/"),v=Object.prototype.hasOwnProperty,w=Array.prototype.slice,x=function(){return"foo"===function(){}.name}(),y=b.exports=m,z=/\s*function\s+([^\(\s]*)\s*/;y.AssertionError=function(a){this.name="AssertionError",this.actual=a.actual,this.expected=a.expected,this.operator=a.operator,a.message?(this.message=a.message,this.generatedMessage=!1):(this.message=k(this),this.generatedMessage=!0);var b=a.stackStartFunction||l;if(Error.captureStackTrace)Error.captureStackTrace(this,b);else{var c=new Error;if(c.stack){var d=c.stack,e=h(b),f=d.indexOf("\n"+e);if(f>=0){var g=d.indexOf("\n",f+1);d=d.substring(g+1)}this.stack=d}}},u.inherits(y.AssertionError,Error),y.fail=l,y.ok=m,y.equal=function(a,b,c){a!=b&&l(a,b,c,"==",y.equal)},y.notEqual=function(a,b,c){a==b&&l(a,b,c,"!=",y.notEqual)},y.deepEqual=function(a,b,c){n(a,b,!1)||l(a,b,c,"deepEqual",y.deepEqual)},y.deepStrictEqual=function(a,b,c){n(a,b,!0)||l(a,b,c,"deepStrictEqual",y.deepStrictEqual)},y.notDeepEqual=function(a,b,c){n(a,b,!1)&&l(a,b,c,"notDeepEqual",y.notDeepEqual)},y.notDeepStrictEqual=q,y.strictEqual=function(a,b,c){a!==b&&l(a,b,c,"===",y.strictEqual)},y.notStrictEqual=function(a,b,c){a===b&&l(a,b,c,"!==",y.notStrictEqual)},y.throws=function(a,b,c){t(!0,a,b,c)},y.doesNotThrow=function(a,b,c){t(!1,a,b,c)},y.ifError=function(a){if(a)throw a};var A=Object.keys||function(a){var b=[];for(var c in a)v.call(a,c)&&b.push(c);return b}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"util/":360}],21:[function(a,b,c){(function(a){!function(){function c(a){var b=!1;return function(){if(b)throw new Error("Callback was already called.");b=!0,a.apply(d,arguments)}}var d,e,f={};d=this,null!=d&&(e=d.async),f.noConflict=function(){return d.async=e,f};var g=Object.prototype.toString,h=Array.isArray||function(a){return"[object Array]"===g.call(a)},i=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c+=1)b(a[c],c,a)},j=function(a,b){if(a.map)return a.map(b);var c=[];return i(a,function(a,d,e){c.push(b(a,d,e))}),c},k=function(a,b,c){return a.reduce?a.reduce(b,c):(i(a,function(a,d,e){c=b(c,a,d,e)}),c)},l=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};"undefined"!=typeof a&&a.nextTick?(f.nextTick=a.nextTick,"undefined"!=typeof setImmediate?f.setImmediate=function(a){setImmediate(a)}:f.setImmediate=f.nextTick):"function"==typeof setImmediate?(f.nextTick=function(a){setImmediate(a)},f.setImmediate=f.nextTick):(f.nextTick=function(a){setTimeout(a,0)},f.setImmediate=f.nextTick),f.each=function(a,b,d){function e(b){b?(d(b),d=function(){}):(f+=1,f>=a.length&&d())}if(d=d||function(){},!a.length)return d();var f=0;i(a,function(a){b(a,c(e))})},f.forEach=f.each,f.eachSeries=function(a,b,c){if(c=c||function(){},!a.length)return c();var d=0,e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d>=a.length?c():e())})};e()},f.forEachSeries=f.eachSeries,f.eachLimit=function(a,b,c,d){var e=m(b);e.apply(null,[a,c,d])},f.forEachLimit=f.eachLimit;var m=function(a){return function(b,c,d){if(d=d||function(){},!b.length||a<=0)return d();var e=0,f=0,g=0;!function h(){if(e>=b.length)return d();for(;g<a&&f<b.length;)f+=1,g+=1,c(b[f-1],function(a){a?(d(a),d=function(){}):(e+=1,g-=1,e>=b.length?d():h())})}()}},n=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.each].concat(b))}},o=function(a,b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[m(a)].concat(c))}},p=function(a){return function(){var b=Array.prototype.slice.call(arguments);return a.apply(null,[f.eachSeries].concat(b))}},q=function(a,b,c,d){if(b=j(b,function(a,b){return{index:b,value:a}}),d){var e=[];a(b,function(a,b){c(a.value,function(c,d){e[a.index]=d,b(c)})},function(a){d(a,e)})}else a(b,function(a,b){c(a.value,function(a){b(a)})})};f.map=n(q),f.mapSeries=p(q),f.mapLimit=function(a,b,c,d){return r(b)(a,c,d)};var r=function(a){return o(a,q)};f.reduce=function(a,b,c,d){f.eachSeries(a,function(a,d){c(b,a,function(a,c){b=c,d(a)})},function(a){d(a,b)})},f.inject=f.reduce,f.foldl=f.reduce,f.reduceRight=function(a,b,c,d){var e=j(a,function(a){return a}).reverse();f.reduce(e,b,c,d)},f.foldr=f.reduceRight;var s=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.filter=n(s),f.filterSeries=p(s),f.select=f.filter,f.selectSeries=f.filterSeries;var t=function(a,b,c,d){var e=[];b=j(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||e.push(a),b()})},function(a){d(j(e.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};f.reject=n(t),f.rejectSeries=p(t);var u=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?(d(a),d=function(){}):b()})},function(a){d()})};f.detect=n(u),f.detectSeries=p(u),f.some=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a&&(c(!0),c=function(){}),d()})},function(a){c(!1)})},f.any=f.some,f.every=function(a,b,c){f.each(a,function(a,d){b(a,function(a){a||(c(!1),c=function(){}),d()})},function(a){c(!0)})},f.all=f.every,f.sortBy=function(a,b,c){f.map(a,function(a,c){b(a,function(b,d){b?c(b):c(null,{value:a,criteria:d})})},function(a,b){if(a)return c(a);var d=function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0};c(null,j(b.sort(d),function(a){return a.value}))})},f.auto=function(a,b){b=b||function(){};var c=l(a),d=c.length;if(!d)return b();var e={},g=[],j=function(a){g.unshift(a)},m=function(a){for(var b=0;b<g.length;b+=1)if(g[b]===a)return void g.splice(b,1)},n=function(){d--,i(g.slice(0),function(a){a()})};j(function(){if(!d){var a=b;b=function(){},a(null,e)}}),i(c,function(c){var d=h(a[c])?a[c]:[a[c]],g=function(a){var d=Array.prototype.slice.call(arguments,1);if(d.length<=1&&(d=d[0]),a){var g={};i(l(e),function(a){g[a]=e[a]}),g[c]=d,b(a,g),b=function(){}}else e[c]=d,f.setImmediate(n)},o=d.slice(0,Math.abs(d.length-1))||[],p=function(){return k(o,function(a,b){return a&&e.hasOwnProperty(b)},!0)&&!e.hasOwnProperty(c)};if(p())d[d.length-1](g,e);else{var q=function(){p()&&(m(q),d[d.length-1](g,e))};j(q)}})},f.retry=function(a,b,c){var d=5,e=[];"function"==typeof a&&(c=b,b=a,a=d),a=parseInt(a,10)||d;var g=function(d,g){for(var h=function(a,b){return function(c){a(function(a,d){c(!a||b,{err:a,result:d})},g)}};a;)e.push(h(b,!(a-=1)));f.series(e,function(a,b){b=b[b.length-1],(d||c)(b.err,b.result)})};return c?g():g},f.waterfall=function(a,b){if(b=b||function(){},!h(a)){var c=new Error("First argument to waterfall must be an array of functions");return b(c)}if(!a.length)return b();var d=function(a){return function(c){if(c)b.apply(null,arguments),b=function(){};else{var e=Array.prototype.slice.call(arguments,1),g=a.next();g?e.push(d(g)):e.push(b),f.setImmediate(function(){a.apply(null,e)})}}};d(f.iterator(a))()};var v=function(a,b,c){if(c=c||function(){},h(b))a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},c);else{var d={};a.each(l(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}};f.parallel=function(a,b){v({map:f.map,each:f.each},a,b)},f.parallelLimit=function(a,b,c){v({map:r(b),each:m(b)},a,c)},f.series=function(a,b){if(b=b||function(){},h(a))f.mapSeries(a,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c)})},b);else{var c={};f.eachSeries(l(a),function(b,d){a[b](function(a){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),c[b]=e,d(a)})},function(a){b(a,c)})}},f.iterator=function(a){var b=function(c){var d=function(){return a.length&&a[c].apply(null,arguments),d.next()};return d.next=function(){return c<a.length-1?b(c+1):null},d};return b(0)},f.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var w=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};f.concat=n(w),
4
f.concatSeries=p(w),f.whilst=function(a,b,c){a()?b(function(d){return d?c(d):void f.whilst(a,b,c)}):c()},f.doWhilst=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?f.doWhilst(a,b,c):c()})},f.until=function(a,b,c){a()?c():b(function(d){return d?c(d):void f.until(a,b,c)})},f.doUntil=function(a,b,c){a(function(d){if(d)return c(d);var e=Array.prototype.slice.call(arguments,1);b.apply(null,e)?c():f.doUntil(a,b,c)})},f.queue=function(a,b){function d(a,b,c,d){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var e={data:b,callback:"function"==typeof d?d:null};c?a.tasks.unshift(e):a.tasks.push(e),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}void 0===b&&(b=1);var e=0,g={tasks:[],concurrency:b,saturated:null,empty:null,drain:null,started:!1,paused:!1,push:function(a,b){d(g,a,!1,b)},kill:function(){g.drain=null,g.tasks=[]},unshift:function(a,b){d(g,a,!0,b)},process:function(){if(!g.paused&&e<g.concurrency&&g.tasks.length){var b=g.tasks.shift();g.empty&&0===g.tasks.length&&g.empty(),e+=1;var d=function(){e-=1,b.callback&&b.callback.apply(b,arguments),g.drain&&g.tasks.length+e===0&&g.drain(),g.process()},f=c(d);a(b.data,f)}},length:function(){return g.tasks.length},running:function(){return e},idle:function(){return g.tasks.length+e===0},pause:function(){g.paused!==!0&&(g.paused=!0,g.process())},resume:function(){g.paused!==!1&&(g.paused=!1,g.process())}};return g},f.priorityQueue=function(a,b){function c(a,b){return a.priority-b.priority}function d(a,b,c){for(var d=-1,e=a.length-1;d<e;){var f=d+(e-d+1>>>1);c(b,a[f])>=0?d=f:e=f-1}return d}function e(a,b,e,g){return a.started||(a.started=!0),h(b)||(b=[b]),0==b.length?f.setImmediate(function(){a.drain&&a.drain()}):void i(b,function(b){var h={data:b,priority:e,callback:"function"==typeof g?g:null};a.tasks.splice(d(a.tasks,h,c)+1,0,h),a.saturated&&a.tasks.length===a.concurrency&&a.saturated(),f.setImmediate(a.process)})}var g=f.queue(a,b);return g.push=function(a,b,c){e(g,a,b,c)},delete g.unshift,g},f.cargo=function(a,b){var c=!1,d=[],e={tasks:d,payload:b,saturated:null,empty:null,drain:null,drained:!0,push:function(a,c){h(a)||(a=[a]),i(a,function(a){d.push({data:a,callback:"function"==typeof c?c:null}),e.drained=!1,e.saturated&&d.length===b&&e.saturated()}),f.setImmediate(e.process)},process:function f(){if(!c){if(0===d.length)return e.drain&&!e.drained&&e.drain(),void(e.drained=!0);var g="number"==typeof b?d.splice(0,b):d.splice(0,d.length),h=j(g,function(a){return a.data});e.empty&&e.empty(),c=!0,a(h,function(){c=!1;var a=arguments;i(g,function(b){b.callback&&b.callback.apply(null,a)}),f()})}},length:function(){return d.length},running:function(){return c}};return e};var x=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(b?console.error&&console.error(b):console[a]&&i(c,function(b){console[a](b)}))}]))}};f.log=x("log"),f.dir=x("dir"),f.memoize=function(a,b){var c={},d={};b=b||function(a){return a};var e=function(){var e=Array.prototype.slice.call(arguments),g=e.pop(),h=b.apply(null,e);h in c?f.nextTick(function(){g.apply(null,c[h])}):h in d?d[h].push(g):(d[h]=[g],a.apply(null,e.concat([function(){c[h]=arguments;var a=d[h];delete d[h];for(var b=0,e=a.length;b<e;b++)a[b].apply(null,arguments)}])))};return e.memo=c,e.unmemoized=a,e},f.unmemoize=function(a){return function(){return(a.unmemoized||a).apply(null,arguments)}},f.times=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.map(d,b,c)},f.timesSeries=function(a,b,c){for(var d=[],e=0;e<a;e++)d.push(e);return f.mapSeries(d,b,c)},f.seq=function(){var a=arguments;return function(){var b=this,c=Array.prototype.slice.call(arguments),d=c.pop();f.reduce(a,c,function(a,c,d){c.apply(b,a.concat([function(){var a=arguments[0],b=Array.prototype.slice.call(arguments,1);d(a,b)}]))},function(a,c){d.apply(b,[a].concat(c))})}},f.compose=function(){return f.seq.apply(null,Array.prototype.reverse.call(arguments))};var y=function(a,b){var c=function(){var c=this,d=Array.prototype.slice.call(arguments),e=d.pop();return a(b,function(a,b){a.apply(c,d.concat([b]))},e)};if(arguments.length>2){var d=Array.prototype.slice.call(arguments,2);return c.apply(this,d)}return c};f.applyEach=n(y),f.applyEachSeries=p(y),f.forever=function(a,b){function c(d){if(d){if(b)return b(d);throw d}a(c)}c()},"undefined"!=typeof b&&b.exports?b.exports=f:"undefined"!=typeof define&&define.amd?define([],function(){return f}):d.async=f}()}).call(this,a("_process"))},{_process:263}],22:[function(a,b,c){var Buffer=a("safe-buffer").Buffer;b.exports=function(a){function b(b){if(0===b.length)return"";for(var c=[0],d=0;d<b.length;++d){for(var e=0,g=b[d];e<c.length;++e)g+=c[e]<<8,c[e]=g%f,g=g/f|0;for(;g>0;)c.push(g%f),g=g/f|0}for(var h="",i=0;0===b[i]&&i<b.length-1;++i)h+=a[0];for(var j=c.length-1;j>=0;--j)h+=a[c[j]];return h}function c(a){if(0===a.length)return Buffer.allocUnsafe(0);for(var b=[0],c=0;c<a.length;c++){var d=e[a[c]];if(void 0===d)return;for(var h=0,i=d;h<b.length;++h)i+=b[h]*f,b[h]=255&i,i>>=8;for(;i>0;)b.push(255&i),i>>=8}for(var j=0;a[j]===g&&j<a.length-1;++j)b.push(0);return Buffer.from(b.reverse())}function d(a){var b=c(a);if(b)return b;throw new Error("Non-base"+f+" character")}for(var e={},f=a.length,g=a.charAt(0),h=0;h<a.length;h++){var i=a.charAt(h);if(void 0!==e[i])throw new TypeError(i+" is ambiguous");e[i]=h}return{encode:b,decodeUnsafe:c,decode:d}}},{"safe-buffer":311}],23:[function(a,b,c){"use strict";function d(a){var b=a>>25;return(33554431&a)<<5^996825010&-(b>>0&1)^642813549&-(b>>1&1)^513874426&-(b>>2&1)^1027748829&-(b>>3&1)^705979059&-(b>>4&1)}function e(a){for(var b=1,c=0;c<a.length;++c){var e=a.charCodeAt(c);if(e<33||e>126)throw new Error("Invalid prefix ("+a+")");b=d(b)^e>>5}b=d(b);for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);b=d(b)^31&g}return b}function f(a,b){if(a.length+7+b.length>90)throw new TypeError("Exceeds Bech32 maximum length");a=a.toLowerCase();for(var c=e(a),f=a+"1",g=0;g<b.length;++g){var h=b[g];if(h>>5!==0)throw new Error("Non 5-bit word");c=d(c)^h,f+=k.charAt(h)}for(var i=0;i<6;++i)c=d(c);c^=1;for(var j=0;j<6;++j){var l=c>>5*(5-j)&31;f+=k.charAt(l)}return f}function g(a){if(a.length<8)throw new TypeError(a+" too short");if(a.length>90)throw new TypeError(a+" too long");var b=a.toLowerCase(),c=a.toUpperCase();if(a!==b&&a!==c)throw new Error("Mixed-case string "+a);a=b;var f=a.lastIndexOf("1");if(0===f)throw new Error("Missing prefix for "+a);var g=a.slice(0,f),h=a.slice(f+1);if(h.length<6)throw new Error("Data too short");for(var i=e(g),j=[],k=0;k<h.length;++k){var m=h.charAt(k),n=l[m];if(void 0===n)throw new Error("Unknown character "+m);i=d(i)^n,k+6>=h.length||j.push(n)}if(1!==i)throw new Error("Invalid checksum for "+a);return{prefix:g,words:j}}function h(a,b,c,d){for(var e=0,f=0,g=(1<<c)-1,h=[],i=0;i<a.length;++i)for(e=e<<b|a[i],f+=b;f>=c;)f-=c,h.push(e>>f&g);if(d)f>0&&h.push(e<<c-f&g);else{if(f>=b)throw new Error("Excess padding");if(e<<c-f&g)throw new Error("Non-zero padding")}return h}function i(a){return h(a,8,5,!0)}function j(a){return h(a,5,8,!1)}for(var k="qpzry9x8gf2tvdw0s3jn54khce6mua7l",l={},m=0;m<k.length;m++){var n=k.charAt(m);if(void 0!==l[n])throw new TypeError(n+" is ambiguous");l[n]=m}b.exports={decode:g,encode:f,toWords:i,fromWords:j}},{}],24:[function(a,b,c){function BigInteger(a,b,c){return this instanceof BigInteger?void(null!=a&&("number"==typeof a?this.fromNumber(a,b,c):null==b&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))):new BigInteger(a,b,c)}function d(a,b,c,d,e,f){for(;--f>=0;){var g=b*this[a++]+c[d]+e;e=Math.floor(g/67108864),c[d++]=67108863&g}return e}function e(a){return eb.charAt(a)}function f(a,b){var c=fb[a.charCodeAt(b)];return null==c?-1:c}function g(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t,a.s=this.s}function h(a){this.t=1,this.s=a<0?-1:0,a>0?this[0]=a:a<-1?this[0]=a+ab:this.t=0}function i(a){var b=new BigInteger;return b.fromInt(a),b}function j(a,b){var c,d=this;if(16==b)c=4;else if(8==b)c=3;else if(256==b)c=8;else if(2==b)c=1;else if(32==b)c=5;else{if(4!=b)return void d.fromRadix(a,b);c=2}d.t=0,d.s=0;for(var e=a.length,g=!1,h=0;--e>=0;){var i=8==c?255&a[e]:f(a,e);i<0?"-"==a.charAt(e)&&(g=!0):(g=!1,0==h?d[d.t++]=i:h+c>d.DB?(d[d.t-1]|=(i&(1<<d.DB-h)-1)<<h,d[d.t++]=i>>d.DB-h):d[d.t-1]|=i<<h,h+=c,h>=d.DB&&(h-=d.DB))}8==c&&0!=(128&a[0])&&(d.s=-1,h>0&&(d[d.t-1]|=(1<<d.DB-h)-1<<h)),d.clamp(),g&&BigInteger.ZERO.subTo(d,d)}function k(){for(var a=this.s&this.DM;this.t>0&&this[this.t-1]==a;)--this.t}function l(a){var b=this;if(b.s<0)return"-"+b.negate().toString(a);var c;if(16==a)c=4;else if(8==a)c=3;else if(2==a)c=1;else if(32==a)c=5;else{if(4!=a)return b.toRadix(a);c=2}var d,f=(1<<c)-1,g=!1,h="",i=b.t,j=b.DB-i*b.DB%c;if(i-- >0)for(j<b.DB&&(d=b[i]>>j)>0&&(g=!0,h=e(d));i>=0;)j<c?(d=(b[i]&(1<<j)-1)<<c-j,d|=b[--i]>>(j+=b.DB-c)):(d=b[i]>>(j-=c)&f,j<=0&&(j+=b.DB,--i)),d>0&&(g=!0),g&&(h+=e(d));return g?h:"0"}function m(){var a=new BigInteger;return BigInteger.ZERO.subTo(this,a),a}function n(){return this.s<0?this.negate():this}function o(a){var b=this.s-a.s;if(0!=b)return b;var c=this.t;if(b=c-a.t,0!=b)return this.s<0?-b:b;for(;--c>=0;)if(0!=(b=this[c]-a[c]))return b;return 0}function p(a){var b,c=1;return 0!=(b=a>>>16)&&(a=b,c+=16),0!=(b=a>>8)&&(a=b,c+=8),0!=(b=a>>4)&&(a=b,c+=4),0!=(b=a>>2)&&(a=b,c+=2),0!=(b=a>>1)&&(a=b,c+=1),c}function q(){return this.t<=0?0:this.DB*(this.t-1)+p(this[this.t-1]^this.s&this.DM)}function r(){return this.bitLength()>>3}function s(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a,b.s=this.s}function t(a,b){for(var c=a;c<this.t;++c)b[c-a]=this[c];b.t=Math.max(this.t-a,0),b.s=this.s}function u(a,b){var c,d=this,e=a%d.DB,f=d.DB-e,g=(1<<f)-1,h=Math.floor(a/d.DB),i=d.s<<e&d.DM;for(c=d.t-1;c>=0;--c)b[c+h+1]=d[c]>>f|i,i=(d[c]&g)<<e;for(c=h-1;c>=0;--c)b[c]=0;b[h]=i,b.t=d.t+h+1,b.s=d.s,b.clamp()}function v(a,b){var c=this;b.s=c.s;var d=Math.floor(a/c.DB);if(d>=c.t)return void(b.t=0);var e=a%c.DB,f=c.DB-e,g=(1<<e)-1;b[0]=c[d]>>e;for(var h=d+1;h<c.t;++h)b[h-d-1]|=(c[h]&g)<<f,b[h-d]=c[h]>>e;e>0&&(b[c.t-d-1]|=(c.s&g)<<f),b.t=c.t-d,b.clamp()}function w(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]-a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e-=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e-=a[d],b[d++]=e&c.DM,e>>=c.DB;e-=a.s}b.s=e<0?-1:0,e<-1?b[d++]=c.DV+e:e>0&&(b[d++]=e),b.t=d,b.clamp()}function x(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e<d.t;++e)b[e+c.t]=c.am(0,d[e],b,e,0,c.t);b.s=0,b.clamp(),this.s!=a.s&&BigInteger.ZERO.subTo(b,b)}function y(a){for(var b=this.abs(),c=a.t=2*b.t;--c>=0;)a[c]=0;for(c=0;c<b.t-1;++c){var d=b.am(c,b[c],a,2*c,0,1);(a[c+b.t]+=b.am(c+1,2*b[c],a,2*c+1,d,b.t-c-1))>=b.DV&&(a[c+b.t]-=b.DV,a[c+b.t+1]=1)}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1)),a.s=0,a.clamp()}function z(a,b,c){var d=this,e=a.abs();if(!(e.t<=0)){var f=d.abs();if(f.t<e.t)return null!=b&&b.fromInt(0),void(null!=c&&d.copyTo(c));null==c&&(c=new BigInteger);var g=new BigInteger,h=d.s,i=a.s,j=d.DB-p(e[e.t-1]);j>0?(e.lShiftTo(j,g),f.lShiftTo(j,c)):(e.copyTo(g),f.copyTo(c));var k=g.t,l=g[k-1];if(0!=l){var m=l*(1<<d.F1)+(k>1?g[k-2]>>d.F2:0),n=d.FV/m,o=(1<<d.F1)/m,q=1<<d.F2,r=c.t,s=r-k,t=null==b?new BigInteger:b;for(g.dlShiftTo(s,t),c.compareTo(t)>=0&&(c[c.t++]=1,c.subTo(t,c)),BigInteger.ONE.dlShiftTo(k,t),t.subTo(g,g);g.t<k;)g[g.t++]=0;for(;--s>=0;){var u=c[--r]==l?d.DM:Math.floor(c[r]*n+(c[r-1]+q)*o);if((c[r]+=g.am(0,u,c,s,0,k))<u)for(g.dlShiftTo(s,t),c.subTo(t,c);c[r]<--u;)c.subTo(t,c)}null!=b&&(c.drShiftTo(k,b),h!=i&&BigInteger.ZERO.subTo(b,b)),c.t=k,c.clamp(),j>0&&c.rShiftTo(j,c),h<0&&BigInteger.ZERO.subTo(c,c)}}}function A(a){var b=new BigInteger;return this.abs().divRemTo(a,null,b),this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b),b}function B(a){this.m=a}function C(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function D(a){return a}function E(a){a.divRemTo(this.m,null,a)}function F(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function G(a,b){a.squareTo(b),this.reduce(b)}function H(){if(this.t<1)return 0;var a=this[0];if(0==(1&a))return 0;var b=3&a;return b=b*(2-(15&a)*b)&15,b=b*(2-(255&a)*b)&255,b=b*(2-((65535&a)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV,b>0?this.DV-b:-b}function I(a){this.m=a,this.mp=a.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<a.DB-15)-1,this.mt2=2*a.t}function J(a){var b=new BigInteger;return a.abs().dlShiftTo(this.m.t,b),b.divRemTo(this.m,null,b),a.s<0&&b.compareTo(BigInteger.ZERO)>0&&this.m.subTo(b,b),b}function K(a){var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function L(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b<this.m.t;++b){var c=32767&a[b],d=c*this.mpl+((c*this.mph+(a[b]>>15)*this.mpl&this.um)<<15)&a.DM;for(c=b+this.m.t,a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp(),a.drShiftTo(this.m.t,a),a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function M(a,b){a.squareTo(b),this.reduce(b)}function N(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function O(){return 0==(this.t>0?1&this[0]:this.s)}function P(a,b){if(a>4294967295||a<1)return BigInteger.ONE;var c=new BigInteger,d=new BigInteger,e=b.convert(this),f=p(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<<f)>0)b.mulTo(d,e,c);else{var g=c;c=d,d=g}return b.revert(c)}function Q(a,b){var c;return c=a<256||b.isEven()?new B(b):new I(b),this.exp(a,c)}function R(){var a=new BigInteger;return this.copyTo(a),a}function S(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function T(){return 0==this.t?this.s:this[0]<<24>>24}function U(){return 0==this.t?this.s:this[0]<<16>>16}function V(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function W(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}function X(a){if(null==a&&(a=10),0==this.signum()||a<2||a>36)return"0";var b=this.chunkSize(a),c=Math.pow(a,b),d=i(c),e=new BigInteger,f=new BigInteger,g="";for(this.divRemTo(d,e,f);e.signum()>0;)g=(c+f.intValue()).toString(a).substr(1)+g,e.divRemTo(d,e,f);return f.intValue().toString(a)+g}function Y(a,b){var c=this;c.fromInt(0),null==b&&(b=10);for(var d=c.chunkSize(b),e=Math.pow(b,d),g=!1,h=0,i=0,j=0;j<a.length;++j){var k=f(a,j);k<0?"-"==a.charAt(j)&&0==c.signum()&&(g=!0):(i=b*i+k,++h>=d&&(c.dMultiply(e),c.dAddOffset(i,0),h=0,i=0))}h>0&&(c.dMultiply(Math.pow(b,h)),c.dAddOffset(i,0)),g&&BigInteger.ZERO.subTo(c,c)}function Z(a,b,c){var d=this;if("number"==typeof b)if(a<2)d.fromInt(1);else for(d.fromNumber(a,c),d.testBit(a-1)||d.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),fa,d),d.isEven()&&d.dAddOffset(1,0);!d.isProbablePrime(b);)d.dAddOffset(2,0),d.bitLength()>a&&d.subTo(BigInteger.ONE.shiftLeft(a-1),d);else{var e=new Array,f=7&a;e.length=(a>>3)+1,b.nextBytes(e),f>0?e[0]&=(1<<f)-1:e[0]=0,d.fromString(e,256)}}function $(){var a=this,b=a.t,c=new Array;c[0]=a.s;var d,e=a.DB-b*a.DB%8,f=0;if(b-- >0)for(e<a.DB&&(d=a[b]>>e)!=(a.s&a.DM)>>e&&(c[f++]=d|a.s<<a.DB-e);b>=0;)e<8?(d=(a[b]&(1<<e)-1)<<8-e,d|=a[--b]>>(e+=a.DB-8)):(d=a[b]>>(e-=8)&255,e<=0&&(e+=a.DB,--b)),0!=(128&d)&&(d|=-256),0===f&&(128&a.s)!=(128&d)&&++f,(f>0||d!=a.s)&&(c[f++]=d);return c}function _(a){return 0==this.compareTo(a)}function aa(a){return this.compareTo(a)<0?this:a}function ba(a){return this.compareTo(a)>0?this:a}function ca(a,b,c){var d,e,f=this,g=Math.min(a.t,f.t);for(d=0;d<g;++d)c[d]=b(f[d],a[d]);if(a.t<f.t){for(e=a.s&f.DM,d=g;d<f.t;++d)c[d]=b(f[d],e);c.t=f.t}else{for(e=f.s&f.DM,d=g;d<a.t;++d)c[d]=b(e,a[d]);c.t=a.t}c.s=b(f.s,a.s),c.clamp()}function da(a,b){return a&b}function ea(a){var b=new BigInteger;return this.bitwiseTo(a,da,b),b}function fa(a,b){return a|b}function ga(a){var b=new BigInteger;return this.bitwiseTo(a,fa,b),b}function ha(a,b){return a^b}function ia(a){var b=new BigInteger;return this.bitwiseTo(a,ha,b),b}function ja(a,b){return a&~b}function ka(a){var b=new BigInteger;return this.bitwiseTo(a,ja,b),b}function la(){for(var a=new BigInteger,b=0;b<this.t;++b)a[b]=this.DM&~this[b];return a.t=this.t,a.s=~this.s,a}function ma(a){var b=new BigInteger;return a<0?this.rShiftTo(-a,b):this.lShiftTo(a,b),b}function na(a){var b=new BigInteger;return a<0?this.lShiftTo(-a,b):this.rShiftTo(a,b),b}function oa(a){if(0==a)return-1;var b=0;return 0==(65535&a)&&(a>>=16,b+=16),0==(255&a)&&(a>>=8,b+=8),0==(15&a)&&(a>>=4,b+=4),0==(3&a)&&(a>>=2,b+=2),0==(1&a)&&++b,b}function pa(){for(var a=0;a<this.t;++a)if(0!=this[a])return a*this.DB+oa(this[a]);return this.s<0?this.t*this.DB:-1}function qa(a){for(var b=0;0!=a;)a&=a-1,++b;return b}function ra(){for(var a=0,b=this.s&this.DM,c=0;c<this.t;++c)a+=qa(this[c]^b);return a}function sa(a){var b=Math.floor(a/this.DB);return b>=this.t?0!=this.s:0!=(this[b]&1<<a%this.DB)}function ta(a,b){var c=BigInteger.ONE.shiftLeft(a);return this.bitwiseTo(c,b,c),c}function ua(a){return this.changeBit(a,fa)}function va(a){return this.changeBit(a,ja)}function wa(a){return this.changeBit(a,ha)}function xa(a,b){for(var c=this,d=0,e=0,f=Math.min(a.t,c.t);d<f;)e+=c[d]+a[d],b[d++]=e&c.DM,e>>=c.DB;if(a.t<c.t){for(e+=a.s;d<c.t;)e+=c[d],b[d++]=e&c.DM,e>>=c.DB;e+=c.s}else{for(e+=c.s;d<a.t;)e+=a[d],b[d++]=e&c.DM,e>>=c.DB;e+=a.s}b.s=e<0?-1:0,e>0?b[d++]=e:e<-1&&(b[d++]=c.DV+e),b.t=d,b.clamp()}function ya(a){var b=new BigInteger;return this.addTo(a,b),b}function za(a){var b=new BigInteger;return this.subTo(a,b),b}function Aa(a){var b=new BigInteger;return this.multiplyTo(a,b),b}function Ba(){var a=new BigInteger;return this.squareTo(a),a}function Ca(a){var b=new BigInteger;return this.divRemTo(a,b,null),b}function Da(a){var b=new BigInteger;return this.divRemTo(a,null,b),b}function Ea(a){var b=new BigInteger,c=new BigInteger;return this.divRemTo(a,b,c),new Array(b,c)}function Fa(a){this[this.t]=this.am(0,a-1,this,0,0,this.t),++this.t,this.clamp()}function Ga(a,b){if(0!=a){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function Ha(){}function Ia(a){return a}function Ja(a,b,c){a.multiplyTo(b,c)}function Ka(a,b){a.squareTo(b)}function La(a){return this.exp(a,new Ha)}function Ma(a,b,c){var d=Math.min(this.t+a.t,b);for(c.s=0,c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;d<e;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);d<e;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function Na(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d<a.t;++d)c[this.t+d-b]=this.am(b-d,a[d],c,0,0,this.t+d-b);c.clamp(),c.drShiftTo(1,c)}function Oa(a){this.r2=new BigInteger,this.q3=new BigInteger,BigInteger.ONE.dlShiftTo(2*a.t,this.r2),this.mu=this.r2.divide(a),this.m=a}function Pa(a){if(a.s<0||a.t>2*this.m.t)return a.mod(this.m);if(a.compareTo(this.m)<0)return a;var b=new BigInteger;return a.copyTo(b),this.reduce(b),b}function Qa(a){return a}function Ra(a){var b=this;for(a.drShiftTo(b.m.t-1,b.r2),a.t>b.m.t+1&&(a.t=b.m.t+1,a.clamp()),b.mu.multiplyUpperTo(b.r2,b.m.t+1,b.q3),b.m.multiplyLowerTo(b.q3,b.m.t+1,b.r2);a.compareTo(b.r2)<0;)a.dAddOffset(1,b.m.t+1);for(a.subTo(b.r2,a);a.compareTo(b.m)>=0;)a.subTo(b.m,a)}function Sa(a,b){a.squareTo(b),this.reduce(b)}function Ta(a,b,c){a.multiplyTo(b,c),this.reduce(c)}function Ua(a,b){var c,d,e=a.bitLength(),f=i(1);if(e<=0)return f;c=e<18?1:e<48?3:e<144?4:e<768?5:6,d=e<8?new B(b):b.isEven()?new Oa(b):new I(b);var g=new Array,h=3,j=c-1,k=(1<<c)-1;if(g[1]=d.convert(this),c>1){var l=new BigInteger;for(d.sqrTo(g[1],l);h<=k;)g[h]=new BigInteger,d.mulTo(l,g[h-2],g[h]),h+=2}var m,n,o=a.t-1,q=!0,r=new BigInteger;for(e=p(a[o])-1;o>=0;){for(e>=j?m=a[o]>>e-j&k:(m=(a[o]&(1<<e+1)-1)<<j-e,o>0&&(m|=a[o-1]>>this.DB+e-j)),h=c;0==(1&m);)m>>=1,--h;if((e-=h)<0&&(e+=this.DB,--o),q)g[m].copyTo(f),q=!1;else{for(;h>1;)d.sqrTo(f,r),d.sqrTo(r,f),h-=2;h>0?d.sqrTo(f,r):(n=f,f=r,r=n),d.mulTo(r,g[m],f)}for(;o>=0&&0==(a[o]&1<<e);)d.sqrTo(f,r),n=f,f=r,r=n,--e<0&&(e=this.DB-1,--o)}return d.revert(f)}function Va(a){var b=this.s<0?this.negate():this.clone(),c=a.s<0?a.negate():a.clone();if(b.compareTo(c)<0){var d=b;b=c,c=d}var e=b.getLowestSetBit(),f=c.getLowestSetBit();if(f<0)return b;for(e<f&&(f=e),f>0&&(b.rShiftTo(f,b),c.rShiftTo(f,c));b.signum()>0;)(e=b.getLowestSetBit())>0&&b.rShiftTo(e,b),(e=c.getLowestSetBit())>0&&c.rShiftTo(e,c),b.compareTo(c)>=0?(b.subTo(c,b),b.rShiftTo(1,b)):(c.subTo(b,c),c.rShiftTo(1,c));return f>0&&c.lShiftTo(f,c),c}function Wa(a){if(a<=0)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(0==b)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}function Xa(a){var b=a.isEven();if(0===this.signum())throw new Error("division by zero");if(this.isEven()&&b||0==a.signum())return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=i(1),f=i(0),g=i(0),h=i(1);0!=c.signum();){for(;c.isEven();)c.rShiftTo(1,c),b?(e.isEven()&&f.isEven()||(e.addTo(this,e),f.subTo(a,f)),e.rShiftTo(1,e)):f.isEven()||f.subTo(a,f),f.rShiftTo(1,f);for(;d.isEven();)d.rShiftTo(1,d),b?(g.isEven()&&h.isEven()||(g.addTo(this,g),h.subTo(a,h)),g.rShiftTo(1,g)):h.isEven()||h.subTo(a,h),h.rShiftTo(1,h);c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(g,e),f.subTo(h,f)):(d.subTo(c,d),b&&g.subTo(e,g),h.subTo(f,h))}if(0!=d.compareTo(BigInteger.ONE))return BigInteger.ZERO;for(;h.compareTo(a)>=0;)h.subTo(a,h);for(;h.signum()<0;)h.addTo(a,h);return h}function Ya(a){var b,c=this.abs();if(1==c.t&&c[0]<=gb[gb.length-1]){for(b=0;b<gb.length;++b)if(c[0]==gb[b])return!0;return!1}if(c.isEven())return!1;for(b=1;b<gb.length;){for(var d=gb[b],e=b+1;e<gb.length&&d<hb;)d*=gb[e++];for(d=c.modInt(d);b<e;)if(d%gb[b++]==0)return!1}return c.millerRabin(a)}function Za(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(c<=0)return!1;var d=b.shiftRight(c);a=a+1>>1,a>gb.length&&(a=gb.length);for(var e,f=new BigInteger(null),g=[],h=0;h<a;++h){for(;e=gb[Math.floor(Math.random()*gb.length)],g.indexOf(e)!=-1;);g.push(e),f.fromInt(e);var i=f.modPow(d,this);if(0!=i.compareTo(BigInteger.ONE)&&0!=i.compareTo(b)){for(var e=1;e++<c&&0!=i.compareTo(b);)if(i=i.modPowInt(2,this),0==i.compareTo(BigInteger.ONE))return!1;if(0!=i.compareTo(b))return!1}}return!0}var $a=BigInteger.prototype;$a.__bigi=a("../package.json").version,BigInteger.isBigInteger=function(a,b){return a&&a.__bigi&&(!b||a.__bigi===$a.__bigi)};var _a;BigInteger.prototype.am=d,_a=26,BigInteger.prototype.DB=_a,BigInteger.prototype.DM=(1<<_a)-1;var ab=BigInteger.prototype.DV=1<<_a,bb=52;BigInteger.prototype.FV=Math.pow(2,bb),BigInteger.prototype.F1=bb-_a,BigInteger.prototype.F2=2*_a-bb;var cb,db,eb="0123456789abcdefghijklmnopqrstuvwxyz",fb=new Array;for(cb="0".charCodeAt(0),db=0;db<=9;++db)fb[cb++]=db;for(cb="a".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;for(cb="A".charCodeAt(0),db=10;db<36;++db)fb[cb++]=db;B.prototype.convert=C,B.prototype.revert=D,B.prototype.reduce=E,B.prototype.mulTo=F,B.prototype.sqrTo=G,I.prototype.convert=J,I.prototype.revert=K,I.prototype.reduce=L,I.prototype.mulTo=N,I.prototype.sqrTo=M,$a.copyTo=g,$a.fromInt=h,$a.fromString=j,$a.clamp=k,$a.dlShiftTo=s,$a.drShiftTo=t,$a.lShiftTo=u,$a.rShiftTo=v,$a.subTo=w,$a.multiplyTo=x,$a.squareTo=y,$a.divRemTo=z,$a.invDigit=H,$a.isEven=O,$a.exp=P,$a.toString=l,$a.negate=m,$a.abs=n,$a.compareTo=o,$a.bitLength=q,$a.byteLength=r,$a.mod=A,$a.modPowInt=Q,Ha.prototype.convert=Ia,Ha.prototype.revert=Ia,Ha.prototype.mulTo=Ja,Ha.prototype.sqrTo=Ka,Oa.prototype.convert=Pa,Oa.prototype.revert=Qa,Oa.prototype.reduce=Ra,Oa.prototype.mulTo=Ta,Oa.prototype.sqrTo=Sa;var gb=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],hb=(1<<26)/gb[gb.length-1];$a.chunkSize=V,$a.toRadix=X,$a.fromRadix=Y,$a.fromNumber=Z,$a.bitwiseTo=ca,$a.changeBit=ta,$a.addTo=xa,$a.dMultiply=Fa,$a.dAddOffset=Ga,$a.multiplyLowerTo=Ma,$a.multiplyUpperTo=Na,$a.modInt=Wa,$a.millerRabin=Za,$a.clone=R,$a.intValue=S,$a.byteValue=T,$a.shortValue=U,$a.signum=W,$a.toByteArray=$,$a.equals=_,$a.min=aa,$a.max=ba,$a.and=ea,$a.or=ga,$a.xor=ia,$a.andNot=ka,$a.not=la,$a.shiftLeft=ma,$a.shiftRight=na,$a.getLowestSetBit=pa,$a.bitCount=ra,$a.testBit=sa,$a.setBit=ua,$a.clearBit=va,$a.flipBit=wa,$a.add=ya,$a.subtract=za,$a.multiply=Aa,$a.divide=Ca,$a.remainder=Da,$a.divideAndRemainder=Ea,$a.modPow=Ua,$a.modInverse=Xa,$a.pow=La,$a.gcd=Va,$a.isProbablePrime=Ya,$a.square=Ba,BigInteger.ZERO=i(0),BigInteger.ONE=i(1),BigInteger.valueOf=i,b.exports=BigInteger},{"../package.json":27}],25:[function(a,b,c){(function(Buffer){var b=a("assert"),BigInteger=a("./bigi");BigInteger.fromByteArrayUnsigned=function(a){return new BigInteger(128&a[0]?[0].concat(a):a)},BigInteger.prototype.toByteArrayUnsigned=function(){var a=this.toByteArray();return 0===a[0]?a.slice(1):a},BigInteger.fromDERInteger=function(a){return new BigInteger(a)},BigInteger.prototype.toDERInteger=BigInteger.prototype.toByteArray,BigInteger.fromBuffer=function(a){if(128&a[0]){var b=Array.prototype.slice.call(a);return new BigInteger([0].concat(b))}return new BigInteger(a)},BigInteger.fromHex=function(a){return""===a?BigInteger.ZERO:(b.equal(a,a.match(/^[A-Fa-f0-9]+/),"Invalid hex string"),b.equal(a.length%2,0,"Incomplete hex"),new BigInteger(a,16))},BigInteger.prototype.toBuffer=function(a){for(var b=this.toByteArrayUnsigned(),c=[],d=a-b.length;c.length<d;)c.push(0);return new Buffer(c.concat(b))},BigInteger.prototype.toHex=function(a){return this.toBuffer(a).toString("hex")}}).call(this,a("buffer").Buffer)},{"./bigi":24,assert:20,buffer:105}],26:[function(a,b,c){var BigInteger=a("./bigi");a("./convert"),b.exports=BigInteger},{"./bigi":24,"./convert":25}],27:[function(a,b,c){b.exports={_args:[[{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib"]],_from:"bigi@>=1.4.0 <2.0.0",_id:"[email protected]",_inCache:!0,_location:"/bigi",_nodeVersion:"6.1.0",_npmOperationalInternal:{host:"packages-12-west.internal.npmjs.com",tmp:"tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"},_npmUser:{name:"jprichardson",email:"[email protected]"},_npmVersion:"3.8.6",_phantomChildren:{},_requested:{raw:"bigi@^1.4.0",scope:null,escapedName:"bigi",name:"bigi",rawSpec:"^1.4.0",spec:">=1.4.0 <2.0.0",type:"range"},_requiredBy:["/bitcoinjs-lib","/ecurve"],_resolved:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",_shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",_shrinkwrap:null,_spec:"bigi@^1.4.0",_where:"/work/blocktrail-sdk-nodejs/node_modules/bitcoinjs-lib",bugs:{url:"https://github.com/cryptocoinjs/bigi/issues"},dependencies:{},description:"Big integers.",devDependencies:{coveralls:"^2.11.2",istanbul:"^0.3.5",jshint:"^2.5.1",mocha:"^2.1.0",mochify:"^2.1.0"},directories:{},dist:{shasum:"9c665a95f88b8b08fc05cfd731f561859d725825",tarball:"https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"},gitHead:"c25308081c896ff84702303722bf5ecd8b3f78e3",homepage:"https://github.com/cryptocoinjs/bigi#readme",keywords:["cryptography","math","bitcoin","arbitrary","precision","arithmetic","big","integer","int","number","biginteger","bigint","bignumber","decimal","float"],main:"./lib/index.js",maintainers:[{name:"midnightlightning",email:"[email protected]"},{name:"sidazhang",email:"[email protected]"},{name:"nadav",email:"[email protected]"},{name:"jprichardson",email:"[email protected]"}],name:"bigi",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{url:"git+https://github.com/cryptocoinjs/bigi.git",type:"git"},scripts:{"browser-test":"mochify --wd -R spec",coverage:"istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",coveralls:"npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",jshint:"jshint --config jshint.json lib/*.js ; true",test:"_mocha -- test/*.js",unit:"mocha"},testling:{files:"test/*.js",harness:"mocha",browsers:["ie/9..latest","firefox/latest","chrome/latest","safari/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},version:"1.4.2"}},{}],28:[function(a,b,c){(function(Buffer){var c=a("./lib/index"),d=a("./sjcl"),e=a("assert");e("function"==typeof d.hash.sha512);var f=function(a){var b=new d.misc.hmac(a,d.hash.sha512);this.encrypt=function(){return b.encrypt.apply(b,arguments)}};c.setPbkdf2(function(a,b,c,e,g){var h;switch(g){case"sha512":h=f;break;default:throw new Error("Digest ["+g+"] not implemented")}var i=d.misc.pbkdf2(d.codec.utf8String.toBits(a),d.codec.utf8String.toBits(b),c,8*e,h);return new Buffer(d.codec.hex.fromBits(i),"hex")}),b.exports={salt:c.salt,mnemonicToSeed:c.mnemonicToSeed,mnemonicToSeedHex:c.mnemonicToSeedHex,mnemonicToEntropy:c.mnemonicToEntropy,entropyToMnemonic:c.entropyToMnemonic,generateMnemonic:c.generateMnemonic,validateMnemonic:c.validateMnemonic}}).call(this,a("buffer").Buffer)},{"./lib/index":29,"./sjcl":30,assert:20,buffer:105}],29:[function(a,b,c){(function(Buffer){function c(a){n=a}function d(a,b){return n(a,k(b),2048,64,"sha512")}function e(a,b){return d(a,b).toString("hex")}function f(a,b){b=b||s;var c=a.split(" ");o(c.length%3===0,"Invalid mnemonic");var d=c.every(function(a){return b.indexOf(a)>-1});o(d,"Invalid mnemonic");var e=c.map(function(a){var c=b.indexOf(a);return m(c.toString(2),"0",11)}).join(""),f=32*Math.floor(e.length/33),g=e.slice(0,f),h=e.slice(f),i=g.match(/(.{1,8})/g).map(function(a){return parseInt(a,2)}),k=new Buffer(i),l=j(k);return o(l===h,"Invalid mnemonic checksum"),k.toString("hex")}function g(a,b){b=b||s;var c=new Buffer(a,"hex"),d=l([].slice.call(c)),e=j(c),f=d+e,g=f.match(/(.{1,11})/g),h=g.map(function(a){var c=parseInt(a,2);return b[c]});return h.join(" ")}function h(a,b,c){a=a||128,b=b||q;var d=b(a/8).toString("hex");return g(d,c)}function i(a,b){try{f(a,b)}catch(a){return!1}return!0}function j(a){var b=p("sha256").update(a).digest(),c=8*a.length,d=c/32;return l([].slice.call(b)).slice(0,d)}function k(a){return"mnemonic"+(r.nfkd(a)||"")}function l(a){return a.map(function(a){return m(a.toString(2),"0",8)}).join("")}function m(a,b,c){for(;a.length<c;)a=b+a;return a}var n,o=a("assert"),p=a("create-hash"),q=a("randombytes"),r=a("unorm"),s=a("../wordlists/en.json");b.exports={setPbkdf2:c,salt:k,mnemonicToSeed:d,mnemonicToSeedHex:e,mnemonicToEntropy:f,entropyToMnemonic:g,generateMnemonic:h,validateMnemonic:i}}).call(this,a("buffer").Buffer)},{"../wordlists/en.json":31,assert:20,buffer:105,"create-hash":128,randombytes:297,unorm:354}],30:[function(a,b,c){"use strict";function d(a){throw a}function e(a,b,c){4!==b.length&&d(new m.exception.invalid("invalid aes block size"));var e=a.b[c],f=b[0]^e[0],g=b[c?3:1]^e[1],h=b[2]^e[2];b=b[c?1:3]^e[3];var i,j,k,l,n=e.length/4-2,o=4,p=[0,0,0,0];i=a.o[c],a=i[0];var q=i[1],r=i[2],s=i[3],t=i[4];for(l=0;l<n;l++)i=a[f>>>24]^q[g>>16&255]^r[h>>8&255]^s[255&b]^e[o],j=a[g>>>24]^q[h>>16&255]^r[b>>8&255]^s[255&f]^e[o+1],k=a[h>>>24]^q[b>>16&255]^r[f>>8&255]^s[255&g]^e[o+2],b=a[b>>>24]^q[f>>16&255]^r[g>>8&255]^s[255&h]^e[o+3],o+=4,f=i,g=j,h=k;for(l=0;4>l;l++)p[c?3&-l:l]=t[f>>>24]<<24^t[g>>16&255]<<16^t[h>>8&255]<<8^t[255&b]^e[o++],i=f,f=g,g=h,h=b,b=i;return p}function f(a,b){var c,d=m.random.D[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}function g(a){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?m.random.addEntropy(window.performance.now(),a,"loadtime"):m.random.addEntropy((new Date).valueOf(),a,"loadtime");
5
}function h(a){a.b=i(a).concat(i(a)),a.F=new m.cipher.aes(a.b)}function i(a){for(var b=0;4>b&&(a.i[b]=a.i[b]+1|0,!a.i[b]);b++);return a.F.encrypt(a.i)}function j(a,b){return function(){b.apply(a,arguments)}}var k=void 0,l=!1,m={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message},this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message},this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message},this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message},this.message=a}}};"undefined"!=typeof b&&b.exports&&(b.exports=m),"function"==typeof define&&define([],function(){return m}),m.cipher.aes=function(a){this.o[0][0][0]||this.t();var b,c,e,f,g=this.o[0][4],h=this.o[1];b=a.length;var i=1;for(4!==b&&6!==b&&8!==b&&d(new m.exception.invalid("invalid aes key size")),this.b=[e=a.slice(0),f=[]],a=b;a<4*b+28;a++)c=e[a-1],(0===a%b||8===b&&4===a%b)&&(c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[255&c],0===a%b&&(c=c<<8^c>>>24^i<<24,i=i<<1^283*(i>>7))),e[a]=e[a-b]^c;for(b=0;a;b++,a--)c=e[3&b?a:a-4],f[b]=4>=a||4>b?c:h[0][g[c>>>24]]^h[1][g[c>>16&255]]^h[2][g[c>>8&255]]^h[3][g[255&c]]},m.cipher.aes.prototype={encrypt:function(a){return e(this,a,0)},decrypt:function(a){return e(this,a,1)},o:[[[],[],[],[],[]],[[],[],[],[],[]]],t:function(){var a,b,c,d,e,f,g,h=this.o[0],i=this.o[1],j=h[4],k=i[4],l=[],m=[];for(a=0;256>a;a++)m[(l[a]=a<<1^283*(a>>7))^a]=a;for(b=c=0;!j[b];b^=d||1,c=m[c]||1)for(f=c^c<<1^c<<2^c<<3^c<<4,f=f>>8^255&f^99,j[b]=f,k[f]=b,e=l[a=l[d=l[b]]],g=16843009*e^65537*a^257*d^16843008*b,e=257*l[f]^16843008*f,a=0;4>a;a++)h[a][b]=e=e<<24^e>>>8,i[a][f]=g=g<<24^g>>>8;for(a=0;5>a;a++)h[a]=h[a].slice(0),i[a]=i[a].slice(0)}},m.bitArray={bitSlice:function(a,b,c){return a=m.bitArray.R(a.slice(b/32),32-(31&b)).slice(1),c===k?a:m.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=m.bitArray.getPartial(c);return 32===d?a.concat(b):m.bitArray.R(b,d,0|c,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0===b?0:32*(b-1)+m.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;return b&=31,0<c&&b&&(a[c-1]=m.bitArray.partial(b,a[c-1]&2147483648>>b-1,1)),a},partial:function(a,b,c){return 32===a?b:(c?0|b:b<<32-a)+1099511627776*a},getPartial:function(a){return Math.round(a/1099511627776)||32},equal:function(a,b){if(m.bitArray.bitLength(a)!==m.bitArray.bitLength(b))return l;var c,d=0;for(c=0;c<a.length;c++)d|=a[c]^b[c];return 0===d},R:function(a,b,c,d){var e;for(e=0,d===k&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;return e=a.length?a[a.length-1]:0,a=m.bitArray.getPartial(e),d.push(m.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1)),d},j:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&65280|(65280&c)<<8|c<<24;return a}},m.codec.utf8String={fromBits:function(a){var b,c,d="",e=m.bitArray.bitLength(a);for(b=0;b<e/8;b++)0===(3&b)&&(c=a[b/4]),d+=String.fromCharCode(c>>>24),c<<=8;return decodeURIComponent(escape(d))},toBits:function(a){a=unescape(encodeURIComponent(a));var b,c=[],d=0;for(b=0;b<a.length;b++)d=d<<8|a.charCodeAt(b),3===(3&b)&&(c.push(d),d=0);return 3&b&&c.push(m.bitArray.partial(8*(3&b),d)),c}},m.codec.hex={fromBits:function(a){var b,c="";for(b=0;b<a.length;b++)c+=((0|a[b])+0xf00000000000).toString(16).substr(4);return c.substr(0,m.bitArray.bitLength(a)/4)},toBits:function(a){var b,c,d=[];for(a=a.replace(/\s|0x/g,""),c=a.length,a+="00000000",b=0;b<a.length;b+=8)d.push(0^parseInt(a.substr(b,8),16));return m.bitArray.clamp(d,4*c)}},m.codec.base64={M:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,f=m.codec.base64.M,g=0,h=m.bitArray.bitLength(a);for(c&&(f=f.substr(0,62)+"-_"),c=0;6*d.length<h;)d+=f.charAt((g^a[c]>>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;3&d.length&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c,e,f=[],g=0,h=m.codec.base64.M,i=0;for(b&&(h=h.substr(0,62)+"-_"),c=0;c<a.length;c++)e=h.indexOf(a.charAt(c)),0>e&&d(new m.exception.invalid("this isn't base64!")),26<g?(g-=26,f.push(i^e>>>g),i=e<<32-g):(g+=6,i^=e<<32-g);return 56&g&&f.push(m.bitArray.partial(56&g,i,1)),f}},m.codec.base64url={fromBits:function(a){return m.codec.base64.fromBits(a,1,1)},toBits:function(a){return m.codec.base64.toBits(a,1)}},m.hash.sha256=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha256.hash=function(a){return(new m.hash.sha256).update(a).finalize()},m.hash.sha256.prototype={blockSize:512,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=512+b&-512;b<=a;b+=512)this.r(c.splice(0,16));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+2;15&a;a++)b.push(0);for(b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,16));return this.reset(),c},l:[],b:[],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}var b,c=0,d=2;a:for(;64>c;d++){for(b=2;b*b<=d;b++)if(0===d%b)continue a;8>c&&(this.l[c]=a(Math.pow(d,.5))),this.b[c]=a(Math.pow(d,1/3)),c++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7];for(a=0;64>a;a++)16>a?b=d[a]:(b=d[a+1&15],c=d[a+14&15],b=d[15&a]=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[15&a]+d[a+9&15]|0),b=b+n+(k>>>6^k>>>11^k>>>25^k<<26^k<<21^k<<7)+(m^k&(l^m))+f[a],n=m,m=l,l=k,k=j+b|0,j=i,i=h,h=g,g=b+(h&i^j&(h^i))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+g|0,e[1]=e[1]+h|0,e[2]=e[2]+i|0,e[3]=e[3]+j|0,e[4]=e[4]+k|0,e[5]=e[5]+l|0,e[6]=e[6]+m|0,e[7]=e[7]+n|0}},m.hash.sha512=function(a){this.b[0]||this.t(),a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()},m.hash.sha512.hash=function(a){return(new m.hash.sha512).update(a).finalize()},m.hash.sha512.prototype={blockSize:1024,reset:function(){return this.e=this.l.slice(0),this.d=[],this.c=0,this},update:function(a){"string"==typeof a&&(a=m.codec.utf8String.toBits(a));var b,c=this.d=m.bitArray.concat(this.d,a);for(b=this.c,a=this.c=b+m.bitArray.bitLength(a),b=1024+b&-1024;b<=a;b+=1024)this.r(c.splice(0,32));return this},finalize:function(){var a,b=this.d,c=this.e,b=m.bitArray.concat(b,[m.bitArray.partial(1,1)]);for(a=b.length+4;31&a;a++)b.push(0);for(b.push(0),b.push(0),b.push(Math.floor(this.c/4294967296)),b.push(0|this.c);b.length;)this.r(b.splice(0,32));return this.reset(),c},l:[],ca:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],ea:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366,7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],t:function(){function a(a){return 4294967296*(a-Math.floor(a))|0}function b(a){return 1099511627776*(a-Math.floor(a))&255}var c,d=0,e=2;a:for(;80>d;e++){for(c=2;c*c<=e;c++)if(0===e%c)continue a;8>d&&(this.l[2*d]=a(Math.pow(e,.5)),this.l[2*d+1]=b(Math.pow(e,.5))<<24|this.ca[d]),this.b[2*d]=a(Math.pow(e,1/3)),this.b[2*d+1]=b(Math.pow(e,1/3))<<24|this.ea[d],d++}},r:function(a){var b,c,d=a.slice(0),e=this.e,f=this.b,g=e[0],h=e[1],i=e[2],j=e[3],k=e[4],l=e[5],m=e[6],n=e[7],o=e[8],p=e[9],q=e[10],r=e[11],s=e[12],t=e[13],u=e[14],v=e[15],w=g,x=h,y=i,z=j,A=k,B=l,C=m,D=n,E=o,F=p,G=q,H=r,I=s,J=t,K=u,L=v;for(a=0;80>a;a++){if(16>a)b=d[2*a],c=d[2*a+1];else{c=d[2*(a-15)];var M=d[2*(a-15)+1];b=(M<<31|c>>>1)^(M<<24|c>>>8)^c>>>7;var N=(c<<31|M>>>1)^(c<<24|M>>>8)^(c<<25|M>>>7);c=d[2*(a-2)];var O=d[2*(a-2)+1],M=(O<<13|c>>>19)^(c<<3|O>>>29)^c>>>6,O=(c<<13|O>>>19)^(O<<3|c>>>29)^(c<<26|O>>>6),P=d[2*(a-7)],Q=d[2*(a-16)],R=d[2*(a-16)+1];c=N+d[2*(a-7)+1],b=b+P+(c>>>0<N>>>0?1:0),c+=O,b+=M+(c>>>0<O>>>0?1:0),c+=R,b+=Q+(c>>>0<R>>>0?1:0)}d[2*a]=b|=0,d[2*a+1]=c|=0;var P=E&G^~E&I,S=F&H^~F&J,O=w&y^w&A^y&A,T=x&z^x&B^z&B,Q=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),R=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),U=f[2*a],V=f[2*a+1],M=L+((E<<18|F>>>14)^(E<<14|F>>>18)^(F<<23|E>>>9)),N=K+((F<<18|E>>>14)^(F<<14|E>>>18)^(E<<23|F>>>9))+(M>>>0<L>>>0?1:0),M=M+S,N=N+(P+(M>>>0<S>>>0?1:0)),M=M+V,N=N+(U+(M>>>0<V>>>0?1:0)),M=M+c|0,N=N+(b+(M>>>0<c>>>0?1:0));c=R+T,b=Q+O+(c>>>0<R>>>0?1:0),K=I,L=J,I=G,J=H,G=E,H=F,F=D+M|0,E=C+N+(F>>>0<D>>>0?1:0)|0,C=A,D=B,A=y,B=z,y=w,z=x,x=M+c|0,w=N+b+(x>>>0<M>>>0?1:0)|0}h=e[1]=h+x|0,e[0]=g+w+(h>>>0<x>>>0?1:0)|0,j=e[3]=j+z|0,e[2]=i+y+(j>>>0<z>>>0?1:0)|0,l=e[5]=l+B|0,e[4]=k+A+(l>>>0<B>>>0?1:0)|0,n=e[7]=n+D|0,e[6]=m+C+(n>>>0<D>>>0?1:0)|0,p=e[9]=p+F|0,e[8]=o+E+(p>>>0<F>>>0?1:0)|0,r=e[11]=r+H|0,e[10]=q+G+(r>>>0<H>>>0?1:0)|0,t=e[13]=t+J|0,e[12]=s+I+(t>>>0<J>>>0?1:0)|0,v=e[15]=v+L|0,e[14]=u+K+(v>>>0<L>>>0?1:0)|0}},m.mode.ccm={name:"ccm",w:[],listenProgress:function(a){m.mode.ccm.w.push(a)},unListenProgress:function(a){a=m.mode.ccm.w.indexOf(a),-1<a&&m.mode.ccm.w.splice(a,1)},X:function(a){var b,c=m.mode.ccm.w.slice();for(b=0;b<c.length;b+=1)c[b](a)},encrypt:function(a,b,c,e,f){var g,h=b.slice(0),i=m.bitArray,j=i.bitLength(c)/8,k=i.bitLength(h)/8;for(f=f||64,e=e||[],7>j&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),g=2;4>g&&k>>>8*g;g++);return g<15-j&&(g=15-j),c=i.clamp(c,8*(15-g)),b=m.mode.ccm.O(a,b,c,e,f,g),h=m.mode.ccm.s(a,h,c,b,f,g),i.concat(h.data,h.tag)},decrypt:function(a,b,c,e,f){f=f||64,e=e||[];var g=m.bitArray,h=g.bitLength(c)/8,i=g.bitLength(b),j=g.clamp(b,i-f),k=g.bitSlice(b,i-f),i=(i-f)/8;for(7>h&&d(new m.exception.invalid("ccm: iv must be at least 7 bytes")),b=2;4>b&&i>>>8*b;b++);return b<15-h&&(b=15-h),c=g.clamp(c,8*(15-b)),j=m.mode.ccm.s(a,j,c,k,f,b),a=m.mode.ccm.O(a,j.data,c,e,f,b),g.equal(j.tag,a)||d(new m.exception.corrupt("ccm: tag doesn't match")),j.data},ga:function(a,b,c,d,e,f){var g=[],h=m.bitArray,i=h.j;if(d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)],d=h.concat(d,c),d[3]|=e,d=a.encrypt(d),b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:4294967295>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;b<g.length;b+=4)d=a.encrypt(i(d,g.slice(b,b+4).concat([0,0,0])));return d},O:function(a,b,c,e,f,g){var h=m.bitArray,i=h.j;for(f/=8,(f%2||4>f||16<f)&&d(new m.exception.invalid("ccm: invalid tag length")),(4294967295<e.length||4294967295<b.length)&&d(new m.exception.bug("ccm: can't deal with 4GiB or more data")),c=m.mode.ccm.ga(a,e,c,f,h.bitLength(b)/8,g),e=0;e<b.length;e+=4)c=a.encrypt(i(c,b.slice(e,e+4).concat([0,0,0])));return h.clamp(c,8*f)},s:function(a,b,c,d,e,f){var g,h=m.bitArray;g=h.j;var i=b.length,j=h.bitLength(b),k=i/50,l=k;if(c=h.concat([h.partial(8,f-1)],c).concat([0,0,0]).slice(0,4),d=h.bitSlice(g(d,a.encrypt(c)),0,e),!i)return{tag:d,data:[]};for(g=0;g<i;g+=4)g>k&&(m.mode.ccm.X(g/i),k+=l),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,j)}}},m.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits"));var h,i=m.mode.ocb2.K,j=m.bitArray,k=j.j,l=[0,0,0,0];c=i(a.encrypt(c));var n,o=[];for(e=e||[],f=f||64,h=0;h+4<b.length;h+=4)n=b.slice(h,h+4),l=k(l,n),o=o.concat(k(c,a.encrypt(k(c,n)))),c=i(c);return n=b.slice(h),b=j.bitLength(n),h=a.encrypt(k(c,[0,0,0,b])),n=j.clamp(k(n.concat([0,0,0]),h),b),l=k(l,k(n.concat([0,0,0]),h)),l=a.encrypt(k(l,k(c,i(c)))),e.length&&(l=k(l,g?e:m.mode.ocb2.pmac(a,e))),o.concat(j.concat(n,j.clamp(l,f)))},decrypt:function(a,b,c,e,f,g){128!==m.bitArray.bitLength(c)&&d(new m.exception.invalid("ocb iv must be 128 bits")),f=f||64;var h,i,j=m.mode.ocb2.K,k=m.bitArray,l=k.j,n=[0,0,0,0],o=j(a.encrypt(c)),p=m.bitArray.bitLength(b)-f,q=[];for(e=e||[],c=0;c+4<p/32;c+=4)h=l(o,a.decrypt(l(o,b.slice(c,c+4)))),n=l(n,h),q=q.concat(h),o=j(o);return i=p-32*c,h=a.encrypt(l(o,[0,0,0,i])),h=l(h,k.clamp(b.slice(c),i).concat([0,0,0])),n=l(n,h),n=a.encrypt(l(n,l(o,j(o)))),e.length&&(n=l(n,g?e:m.mode.ocb2.pmac(a,e))),k.equal(k.clamp(n,f),k.bitSlice(b,p))||d(new m.exception.corrupt("ocb: tag doesn't match")),q.concat(k.clamp(h,i))},pmac:function(a,b){var c,d=m.mode.ocb2.K,e=m.bitArray,f=e.j,g=[0,0,0,0],h=a.encrypt([0,0,0,0]),h=f(h,d(d(h)));for(c=0;c+4<b.length;c+=4)h=d(h),g=f(g,a.encrypt(f(h,b.slice(c,c+4))));return c=b.slice(c),128>e.bitLength(c)&&(h=f(h,d(h)),c=e.concat(c,[-2147483648,0,0,0])),g=f(g,c),a.encrypt(f(d(f(h,d(h))),g))},K:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^135*(a[0]>>>31)]}},m.mode.gcm={name:"gcm",encrypt:function(a,b,c,d,e){var f=b.slice(0);return b=m.bitArray,d=d||[],a=m.mode.gcm.s(!0,a,f,d,c,e||128),b.concat(a.data,a.tag)},decrypt:function(a,b,c,e,f){var g=b.slice(0),h=m.bitArray,i=h.bitLength(g);return f=f||128,e=e||[],f<=i?(b=h.bitSlice(g,i-f),g=h.bitSlice(g,0,i-f)):(b=g,g=[]),a=m.mode.gcm.s(l,a,g,e,c,f),h.equal(a.tag,b)||d(new m.exception.corrupt("gcm: tag doesn't match")),a.data},ba:function(a,b){var c,d,e,f,g,h=m.bitArray.j;for(e=[0,0,0,0],f=b.slice(0),c=0;128>c;c++){for((d=0!==(a[Math.floor(c/32)]&1<<31-c%32))&&(e=h(e,f)),g=0!==(1&f[3]),d=3;0<d;d--)f[d]=f[d]>>>1|(1&f[d-1])<<31;f[0]>>>=1,g&&(f[0]^=-520093696)}return e},k:function(a,b,c){var d,e=c.length;for(b=b.slice(0),d=0;d<e;d+=4)b[0]^=4294967295&c[d],b[1]^=4294967295&c[d+1],b[2]^=4294967295&c[d+2],b[3]^=4294967295&c[d+3],b=m.mode.gcm.ba(b,a);return b},s:function(a,b,c,d,e,f){var g,h,i,j,k,l,n,o,p=m.bitArray;for(l=c.length,n=p.bitLength(c),o=p.bitLength(d),h=p.bitLength(e),g=b.encrypt([0,0,0,0]),96===h?(e=e.slice(0),e=p.concat(e,[1])):(e=m.mode.gcm.k(g,[0,0,0,0],e),e=m.mode.gcm.k(g,e,[0,0,Math.floor(h/4294967296),4294967295&h])),h=m.mode.gcm.k(g,[0,0,0,0],d),k=e.slice(0),d=h.slice(0),a||(d=m.mode.gcm.k(g,h,c)),j=0;j<l;j+=4)k[3]++,i=b.encrypt(k),c[j]^=i[0],c[j+1]^=i[1],c[j+2]^=i[2],c[j+3]^=i[3];return c=p.clamp(c,n),a&&(d=m.mode.gcm.k(g,h,c)),a=[Math.floor(o/4294967296),4294967295&o,Math.floor(n/4294967296),4294967295&n],d=m.mode.gcm.k(g,d,a),i=b.encrypt(e),d[0]^=i[0],d[1]^=i[1],d[2]^=i[2],d[3]^=i[3],{tag:p.bitSlice(d,0,f),data:c}}},m.misc.hmac=function(a,b){this.P=b=b||m.hash.sha256;var c,d=[[],[]],e=b.prototype.blockSize/32;for(this.q=[new b,new b],a.length>e&&(a=b.hash(a)),c=0;c<e;c++)d[0][c]=909522486^a[c],d[1][c]=1549556828^a[c];this.q[0].update(d[0]),this.q[1].update(d[1]),this.J=new b(this.q[0])},m.misc.hmac.prototype.encrypt=m.misc.hmac.prototype.mac=function(a){return this.S&&d(new m.exception.invalid("encrypt on already updated hmac called!")),this.update(a),this.digest(a)},m.misc.hmac.prototype.reset=function(){this.J=new this.P(this.q[0]),this.S=l},m.misc.hmac.prototype.update=function(a){this.S=!0,this.J.update(a)},m.misc.hmac.prototype.digest=function(){var a=this.J.finalize(),a=new this.P(this.q[1]).update(a).finalize();return this.reset(),a},m.misc.pbkdf2=function(a,b,c,e,f){c=c||1e3,(0>e||0>c)&&d(m.exception.invalid("invalid params to pbkdf2")),"string"==typeof a&&(a=m.codec.utf8String.toBits(a)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),f=f||m.misc.hmac,a=new f(a);var g,h,i,j,k=[],l=m.bitArray;for(j=1;32*k.length<(e||1);j++){for(f=g=a.encrypt(l.concat(b,[j])),h=1;h<c;h++)for(g=a.encrypt(g),i=0;i<g.length;i++)f[i]^=g[i];k=k.concat(f)}return e&&(k=l.clamp(k,e)),k},m.prng=function(a){this.f=[new m.hash.sha256],this.m=[0],this.I=0,this.A={},this.H=0,this.N={},this.Q=this.g=this.n=this.Z=0,this.b=[0,0,0,0,0,0,0,0],this.i=[0,0,0,0],this.F=k,this.G=a,this.u=l,this.D={progress:{},seeded:{}},this.p=this.Y=0,this.B=1,this.C=2,this.U=65536,this.L=[0,48,64,96,128,192,256,384,512,768,1024],this.V=3e4,this.T=80},m.prng.prototype={randomWords:function(a,b){var c,e=[];c=this.isReady(b);var f;if(c===this.p&&d(new m.exception.notReady("generator isn't seeded")),c&this.C){c=!(c&this.B),f=[];var g,j=0;for(this.Q=f[0]=(new Date).valueOf()+this.V,g=0;16>g;g++)f.push(4294967296*Math.random()|0);for(g=0;g<this.f.length&&(f=f.concat(this.f[g].finalize()),j+=this.m[g],this.m[g]=0,!(!c&&this.I&1<<g));g++);for(this.I>=1<<this.f.length&&(this.f.push(new m.hash.sha256),this.m.push(0)),this.g-=j,j>this.n&&(this.n=j),this.I++,this.b=m.hash.sha256.hash(this.b.concat(f)),this.F=new m.cipher.aes(this.b),c=0;4>c&&(this.i[c]=this.i[c]+1|0,!this.i[c]);c++);}for(c=0;c<a;c+=4)0===(c+1)%this.U&&h(this),f=i(this),e.push(f[0],f[1],f[2],f[3]);return h(this),e.slice(0,a)},setDefaultParanoia:function(a,b){0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b&&d("Setting paranoia=0 will ruin your security; use it only for testing"),this.G=a},addEntropy:function(a,b,c){c=c||"user";var e,g,h=(new Date).valueOf(),i=this.A[c],j=this.isReady(),l=0;switch(e=this.N[c],e===k&&(e=this.N[c]=this.Z++),i===k&&(i=this.A[c]=0),this.A[c]=(this.A[c]+1)%this.f.length,typeof a){case"number":b===k&&(b=1),this.f[i].update([e,this.H++,1,b,h,1,0|a]);break;case"object":if(c=Object.prototype.toString.call(a),"[object Uint32Array]"===c){for(g=[],c=0;c<a.length;c++)g.push(a[c]);a=g}else for("[object Array]"!==c&&(l=1),c=0;c<a.length&&!l;c++)"number"!=typeof a[c]&&(l=1);if(!l){if(b===k)for(c=b=0;c<a.length;c++)for(g=a[c];0<g;)b++,g>>>=1;this.f[i].update([e,this.H++,2,b,h,a.length].concat(a))}break;case"string":b===k&&(b=a.length),this.f[i].update([e,this.H++,3,b,h,a.length]),this.f[i].update(a);break;default:l=1}l&&d(new m.exception.bug("random: addEntropy only supports number, array of numbers or string")),this.m[i]+=b,this.g+=b,j===this.p&&(this.isReady()!==this.p&&f("seeded",Math.max(this.n,this.g)),f("progress",this.getProgress()))},isReady:function(a){return a=this.L[a!==k?a:this.G],this.n&&this.n>=a?this.m[0]>this.T&&(new Date).valueOf()>this.Q?this.C|this.B:this.B:this.g>=a?this.C|this.p:this.p},getProgress:function(a){return a=this.L[a?a:this.G],this.n>=a?1:this.g>a?1:this.g/a},startCollectors:function(){this.u||(this.a={loadTimeCollector:j(this,this.fa),mouseCollector:j(this,this.ha),keyboardCollector:j(this,this.da),accelerometerCollector:j(this,this.W),touchCollector:j(this,this.ja)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,l),window.addEventListener("mousemove",this.a.mouseCollector,l),window.addEventListener("keypress",this.a.keyboardCollector,l),window.addEventListener("devicemotion",this.a.accelerometerCollector,l),window.addEventListener("touchmove",this.a.touchCollector,l)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):d(new m.exception.bug("can't attach event")),this.u=!0)},stopCollectors:function(){this.u&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,l),window.removeEventListener("mousemove",this.a.mouseCollector,l),window.removeEventListener("keypress",this.a.keyboardCollector,l),window.removeEventListener("devicemotion",this.a.accelerometerCollector,l),window.removeEventListener("touchmove",this.a.touchCollector,l)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.u=l)},addEventListener:function(a,b){this.D[a][this.Y++]=b},removeEventListener:function(a,b){var c,d,e=this.D[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;c<f.length;c++)d=f[c],delete e[d]},da:function(){g(1)},ha:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(a){c=b=0}0!=b&&0!=c&&m.random.addEntropy([b,c],2,"mouse"),g(0)},ja:function(a){a=a.touches[0]||a.changedTouches[0],m.random.addEntropy([a.pageX||a.clientX,a.pageY||a.clientY],1,"touch"),g(0)},fa:function(){g(2)},W:function(a){if(a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z,window.orientation){var b=window.orientation;"number"==typeof b&&m.random.addEntropy(b,1,"accelerometer")}a&&m.random.addEntropy(a,2,"accelerometer"),g(0)}},m.random=new m.prng(6);a:try{var n,o,p,q;if(q="undefined"!=typeof b){var r;if(r=b.exports){var s;try{s=a("crypto")}catch(a){s=null}r=(o=s)&&o.randomBytes}q=r}if(q)n=o.randomBytes(128),n=new Uint32Array(new Uint8Array(n).buffer),m.random.addEntropy(n,1024,"crypto['randomBytes']");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(p=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(p);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break a;window.msCrypto.getRandomValues(p)}m.random.addEntropy(p,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))}m.json={defaults:{v:1,iter:1e3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},aa:function(a,b,c,e){c=c||{},e=e||{};var f,g=m.json,h=g.h({iv:m.random.randomWords(4,0)},g.defaults);return g.h(h,c),c=h.adata,"string"==typeof h.salt&&(h.salt=m.codec.base64.toBits(h.salt)),"string"==typeof h.iv&&(h.iv=m.codec.base64.toBits(h.iv)),(!m.mode[h.mode]||!m.cipher[h.cipher]||"string"==typeof a&&100>=h.iter||64!==h.ts&&96!==h.ts&&128!==h.ts||128!==h.ks&&192!==h.ks&&256!==h.ks||2>h.iv.length||4<h.iv.length)&&d(new m.exception.invalid("json encrypt: invalid parameters")),"string"==typeof a?(f=m.misc.cachedPbkdf2(a,h),a=f.key.slice(0,h.ks/32),h.salt=f.salt):m.ecc&&a instanceof m.ecc.elGamal.publicKey&&(f=a.kem(),h.kemtag=f.tag,a=f.key.slice(0,h.ks/32)),"string"==typeof b&&(b=m.codec.utf8String.toBits(b)),"string"==typeof c&&(h.adata=c=m.codec.utf8String.toBits(c)),f=new m.cipher[h.cipher](a),g.h(e,h),e.key=a,h.ct="ccm"===h.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b instanceof ArrayBuffer?m.arrayBuffer.ccm.encrypt(f,b,h.iv,c,h.ts):m.mode[h.mode].encrypt(f,b,h.iv,c,h.ts),h},encrypt:function(a,b,c,d){var e=m.json,f=e.aa.apply(e,arguments);return e.encode(f)},$:function(a,b,c,e){c=c||{},e=e||{};var f=m.json;b=f.h(f.h(f.h({},f.defaults),b),c,!0);var g,h;return g=b.adata,"string"==typeof b.salt&&(b.salt=m.codec.base64.toBits(b.salt)),"string"==typeof b.iv&&(b.iv=m.codec.base64.toBits(b.iv)),(!m.mode[b.mode]||!m.cipher[b.cipher]||"string"==typeof a&&100>=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&256!==b.ks||!b.iv||2>b.iv.length||4<b.iv.length)&&d(new m.exception.invalid("json decrypt: invalid parameters")),"string"==typeof a?(h=m.misc.cachedPbkdf2(a,b),a=h.key.slice(0,b.ks/32),b.salt=h.salt):m.ecc&&a instanceof m.ecc.elGamal.secretKey&&(a=a.unkem(m.codec.base64.toBits(b.kemtag)).slice(0,b.ks/32)),"string"==typeof g&&(g=m.codec.utf8String.toBits(g)),h=new m.cipher[b.cipher](a),g="ccm"===b.mode&&m.arrayBuffer&&m.arrayBuffer.ccm&&b.ct instanceof ArrayBuffer?m.arrayBuffer.ccm.decrypt(h,b.ct,b.iv,b.tag,g,b.ts):m.mode[b.mode].decrypt(h,b.ct,b.iv,g,b.ts),f.h(e,b),e.key=a,1===c.raw?g:m.codec.utf8String.fromBits(g)},decrypt:function(a,b,c,d){var e=m.json;return e.$(a,e.decode(b),c,d)},encode:function(a){var b,c="{",e="";for(b in a)if(a.hasOwnProperty(b))switch(b.match(/^[a-z0-9]+$/i)||d(new m.exception.invalid("json encode: invalid property name")),c+=e+'"'+b+'":',e=",",typeof a[b]){case"number":case"boolean":c+=a[b];break;case"string":c+='"'+escape(a[b])+'"';break;case"object":c+='"'+m.codec.base64.fromBits(a[b],0)+'"';break;default:d(new m.exception.bug("json encode: unsupported type"))}return c+"}"},decode:function(a){a=a.replace(/\s/g,""),a.match(/^\{.*\}$/)||d(new m.exception.invalid("json decode: this isn't json!")),a=a.replace(/^\{|\}$/g,"").split(/,/);var b,c,e={};for(b=0;b<a.length;b++)(c=a[b].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))||d(new m.exception.invalid("json decode: this isn't json!")),null!=c[3]?e[c[2]]=parseInt(c[3],10):null!=c[4]?e[c[2]]=c[2].match(/^(ct|adata|salt|iv)$/)?m.codec.base64.toBits(c[4]):unescape(c[4]):null!=c[5]&&(e[c[2]]="true"===c[5]);return e},h:function(a,b,c){if(a===k&&(a={}),b===k)return a;for(var e in b)b.hasOwnProperty(e)&&(c&&a[e]!==k&&a[e]!==b[e]&&d(new m.exception.invalid("required parameter overridden")),a[e]=b[e]);return a},la:function(a,b){var c,d={};for(c in a)a.hasOwnProperty(c)&&a[c]!==b[c]&&(d[c]=a[c]);return d},ka:function(a,b){var c,d={};for(c=0;c<b.length;c++)a[b[c]]!==k&&(d[b[c]]=a[b[c]]);return d}},m.encrypt=m.json.encrypt,m.decrypt=m.json.decrypt,m.misc.ia={},m.misc.cachedPbkdf2=function(a,b){var c,d=m.misc.ia;return b=b||{},c=b.iter||1e3,d=d[a]=d[a]||{},c=d[c]=d[c]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):m.random.randomWords(2,0)},d=b.salt===k?c.firstSalt:b.salt,c[d]=c[d]||m.misc.pbkdf2(a,d,b.iter),{key:c[d].slice(0),salt:d.slice(0)}}},{crypto:133}],31:[function(a,b,c){b.exports=["abandon","ability","able","about","above","absent","absorb","abstract","absurd","abuse","access","accident","account","accuse","achieve","acid","acoustic","acquire","across","act","action","actor","actress","actual","adapt","add","addict","address","adjust","admit","adult","advance","advice","aerobic","affair","afford","afraid","again","age","agent","agree","ahead","aim","air","airport","aisle","alarm","album","alcohol","alert","alien","all","alley","allow","almost","alone","alpha","already","also","alter","always","amateur","amazing","among","amount","amused","analyst","anchor","ancient","anger","angle","angry","animal","ankle","announce","annual","another","answer","antenna","antique","anxiety","any","apart","apology","appear","apple","approve","april","arch","arctic","area","arena","argue","arm","armed","armor","army","around","arrange","arrest","arrive","arrow","art","artefact","artist","artwork","ask","aspect","assault","asset","assist","assume","asthma","athlete","atom","attack","attend","attitude","attract","auction","audit","august","aunt","author","auto","autumn","average","avocado","avoid","awake","aware","away","awesome","awful","awkward","axis","baby","bachelor","bacon","badge","bag","balance","balcony","ball","bamboo","banana","banner","bar","barely","bargain","barrel","base","basic","basket","battle","beach","bean","beauty","because","become","beef","before","begin","behave","behind","believe","below","belt","bench","benefit","best","betray","better","between","beyond","bicycle","bid","bike","bind","biology","bird","birth","bitter","black","blade","blame","blanket","blast","bleak","bless","blind","blood","blossom","blouse","blue","blur","blush","board","boat","body","boil","bomb","bone","bonus","book","boost","border","boring","borrow","boss","bottom","bounce","box","boy","bracket","brain","brand","brass","brave","bread","breeze","brick","bridge","brief","bright","bring","brisk","broccoli","broken","bronze","broom","brother","brown","brush","bubble","buddy","budget","buffalo","build","bulb","bulk","bullet","bundle","bunker","burden","burger","burst","bus","business","busy","butter","buyer","buzz","cabbage","cabin","cable","cactus","cage","cake","call","calm","camera","camp","can","canal","cancel","candy","cannon","canoe","canvas","canyon","capable","capital","captain","car","carbon","card","cargo","carpet","carry","cart","case","cash","casino","castle","casual","cat","catalog","catch","category","cattle","caught","cause","caution","cave","ceiling","celery","cement","census","century","cereal","certain","chair","chalk","champion","change","chaos","chapter","charge","chase","chat","cheap","check","cheese","chef","cherry","chest","chicken","chief","child","chimney","choice","choose","chronic","chuckle","chunk","churn","cigar","cinnamon","circle","citizen","city","civil","claim","clap","clarify","claw","clay","clean","clerk","clever","click","client","cliff","climb","clinic","clip","clock","clog","close","cloth","cloud","clown","club","clump","cluster","clutch","coach","coast","coconut","code","coffee","coil","coin","collect","color","column","combine","come","comfort","comic","common","company","concert","conduct","confirm","congress","connect","consider","control","convince","cook","cool","copper","copy","coral","core","corn","correct","cost","cotton","couch","country","couple","course","cousin","cover","coyote","crack","cradle","craft","cram","crane","crash","crater","crawl","crazy","cream","credit","creek","crew","cricket","crime","crisp","critic","crop","cross","crouch","crowd","crucial","cruel","cruise","crumble","crunch","crush","cry","crystal","cube","culture","cup","cupboard","curious","current","curtain","curve","cushion","custom","cute","cycle","dad","damage","damp","dance","danger","daring","dash","daughter","dawn","day","deal","debate","debris","decade","december","decide","decline","decorate","decrease","deer","defense","define","defy","degree","delay","deliver","demand","demise","denial","dentist","deny","depart","depend","deposit","depth","deputy","derive","describe","desert","design","desk","despair","destroy","detail","detect","develop","device","devote","diagram","dial","diamond","diary","dice","diesel","diet","differ","digital","dignity","dilemma","dinner","dinosaur","direct","dirt","disagree","discover","disease","dish","dismiss","disorder","display","distance","divert","divide","divorce","dizzy","doctor","document","dog","doll","dolphin","domain","donate","donkey","donor","door","dose","double","dove","draft","dragon","drama","drastic","draw","dream","dress","drift","drill","drink","drip","drive","drop","drum","dry","duck","dumb","dune","during","dust","dutch","duty","dwarf","dynamic","eager","eagle","early","earn","earth","easily","east","easy","echo","ecology","economy","edge","edit","educate","effort","egg","eight","either","elbow","elder","electric","elegant","element","elephant","elevator","elite","else","embark","embody","embrace","emerge","emotion","employ","empower","empty","enable","enact","end","endless","endorse","enemy","energy","enforce","engage","engine","enhance","enjoy","enlist","enough","enrich","enroll","ensure","enter","entire","entry","envelope","episode","equal","equip","era","erase","erode","erosion","error","erupt","escape","essay","essence","estate","eternal","ethics","evidence","evil","evoke","evolve","exact","example","excess","exchange","excite","exclude","excuse","execute","exercise","exhaust","exhibit","exile","exist","exit","exotic","expand","expect","expire","explain","expose","express","extend","extra","eye","eyebrow","fabric","face","faculty","fade","faint","faith","fall","false","fame","family","famous","fan","fancy","fantasy","farm","fashion","fat","fatal","father","fatigue","fault","favorite","feature","february","federal","fee","feed","feel","female","fence","festival","fetch","fever","few","fiber","fiction","field","figure","file","film","filter","final","find","fine","finger","finish","fire","firm","first","fiscal","fish","fit","fitness","fix","flag","flame","flash","flat","flavor","flee","flight","flip","float","flock","floor","flower","fluid","flush","fly","foam","focus","fog","foil","fold","follow","food","foot","force","forest","forget","fork","fortune","forum","forward","fossil","foster","found","fox","fragile","frame","frequent","fresh","friend","fringe","frog","front","frost","frown","frozen","fruit","fuel","fun","funny","furnace","fury","future","gadget","gain","galaxy","gallery","game","gap","garage","garbage","garden","garlic","garment","gas","gasp","gate","gather","gauge","gaze","general","genius","genre","gentle","genuine","gesture","ghost","giant","gift","giggle","ginger","giraffe","girl","give","glad","glance","glare","glass","glide","glimpse","globe","gloom","glory","glove","glow","glue","goat","goddess","gold","good","goose","gorilla","gospel","gossip","govern","gown","grab","grace","grain","grant","grape","grass","gravity","great","green","grid","grief","grit","grocery","group","grow","grunt","guard","guess","guide","guilt","guitar","gun","gym","habit","hair","half","hammer","hamster","hand","happy","harbor","hard","harsh","harvest","hat","have","hawk","hazard","head","health","heart","heavy","hedgehog","height","hello","helmet","help","hen","hero","hidden","high","hill","hint","hip","hire","history","hobby","hockey","hold","hole","holiday","hollow","home","honey","hood","hope","horn","horror","horse","hospital","host","hotel","hour","hover","hub","huge","human","humble","humor","hundred","hungry","hunt","hurdle","hurry","hurt","husband","hybrid","ice","icon","idea","identify","idle","ignore","ill","illegal","illness","image","imitate","immense","immune","impact","impose","improve","impulse","inch","include","income","increase","index","indicate","indoor","industry","infant","inflict","inform","inhale","inherit","initial","inject","injury","inmate","inner","innocent","input","inquiry","insane","insect","inside","inspire","install","intact","interest","into","invest","invite","involve","iron","island","isolate","issue","item","ivory","jacket","jaguar","jar","jazz","jealous","jeans","jelly","jewel","job","join","joke","journey","joy","judge","juice","jump","jungle","junior","junk","just","kangaroo","keen","keep","ketchup","key","kick","kid","kidney","kind","kingdom","kiss","kit","kitchen","kite","kitten","kiwi","knee","knife","knock","know","lab","label","labor","ladder","lady","lake","lamp","language","laptop","large","later","latin","laugh","laundry","lava","law","lawn","lawsuit","layer","lazy","leader","leaf","learn","leave","lecture","left","leg","legal","legend","leisure","lemon","lend","length","lens","leopard","lesson","letter","level","liar","liberty","library","license","life","lift","light","like","limb","limit","link","lion","liquid","list","little","live","lizard","load","loan","lobster","local","lock","logic","lonely","long","loop","lottery","loud","lounge","love","loyal","lucky","luggage","lumber","lunar","lunch","luxury","lyrics","machine","mad","magic","magnet","maid","mail","main","major","make","mammal","man","manage","mandate","mango","mansion","manual","maple","marble","march","margin","marine","market","marriage","mask","mass","master","match","material","math","matrix","matter","maximum","maze","meadow","mean","measure","meat","mechanic","medal","media","melody","melt","member","memory","mention","menu","mercy","merge","merit","merry","mesh","message","metal","method","middle","midnight","milk","million","mimic","mind","minimum","minor","minute","miracle","mirror","misery","miss","mistake","mix","mixed","mixture","mobile","model","modify","mom","moment","monitor","monkey","monster","month","moon","moral","more","morning","mosquito","mother","motion","motor","mountain","mouse","move","movie","much","muffin","mule","multiply","muscle","museum","mushroom","music","must","mutual","myself","mystery","myth","naive","name","napkin","narrow","nasty","nation","nature","near","neck","need","negative","neglect","neither","nephew","nerve","nest","net","network","neutral","never","news","next","nice","night","noble","noise","nominee","noodle","normal","north","nose","notable","note","nothing","notice","novel","now","nuclear","number","nurse","nut","oak","obey","object","oblige","obscure","observe","obtain","obvious","occur","ocean","october","odor","off","offer","office","often","oil","okay","old","olive","olympic","omit","once","one","onion","online","only","open","opera","opinion","oppose","option","orange","orbit","orchard","order","ordinary","organ","orient","original","orphan","ostrich","other","outdoor","outer","output","outside","oval","oven","over","own","owner","oxygen","oyster","ozone","pact","paddle","page","pair","palace","palm","panda","panel","panic","panther","paper","parade","parent","park","parrot","party","pass","patch","path","patient","patrol","pattern","pause","pave","payment","peace","peanut","pear","peasant","pelican","pen","penalty","pencil","people","pepper","perfect","permit","person","pet","phone","photo","phrase","physical","piano","picnic","picture","piece","pig","pigeon","pill","pilot","pink","pioneer","pipe","pistol","pitch","pizza","place","planet","plastic","plate","play","please","pledge","pluck","plug","plunge","poem","poet","point","polar","pole","police","pond","pony","pool","popular","portion","position","possible","post","potato","pottery","poverty","powder","power","practice","praise","predict","prefer","prepare","present","pretty","prevent","price","pride","primary","print","priority","prison","private","prize","problem","process","produce","profit","program","project","promote","proof","property","prosper","protect","proud","provide","public","pudding","pull","pulp","pulse","pumpkin","punch","pupil","puppy","purchase","purity","purpose","purse","push","put","puzzle","pyramid","quality","quantum","quarter","question","quick","quit","quiz","quote","rabbit","raccoon","race","rack","radar","radio","rail","rain","raise","rally","ramp","ranch","random","range","rapid","rare","rate","rather","raven","raw","razor","ready","real","reason","rebel","rebuild","recall","receive","recipe","record","recycle","reduce","reflect","reform","refuse","region","regret","regular","reject","relax","release","relief","rely","remain","remember","remind","remove","render","renew","rent","reopen","repair","repeat","replace","report","require","rescue","resemble","resist","resource","response","result","retire","retreat","return","reunion","reveal","review","reward","rhythm","rib","ribbon","rice","rich","ride","ridge","rifle","right","rigid","ring","riot","ripple","risk","ritual","rival","river","road","roast","robot","robust","rocket","romance","roof","rookie","room","rose","rotate","rough","round","route","royal","rubber","rude","rug","rule","run","runway","rural","sad","saddle","sadness","safe","sail","salad","salmon","salon","salt","salute","same","sample","sand","satisfy","satoshi","sauce","sausage","save","say","scale","scan","scare","scatter","scene","scheme","school","science","scissors","scorpion","scout","scrap","screen","script","scrub","sea","search","season","seat","second","secret","section","security","seed","seek","segment","select","sell","seminar","senior","sense","sentence","series","service","session","settle","setup","seven","shadow","shaft","shallow","share","shed","shell","sheriff","shield","shift","shine","ship","shiver","shock","shoe","shoot","shop","short","shoulder","shove","shrimp","shrug","shuffle","shy","sibling","sick","side","siege","sight","sign","silent","silk","silly","silver","similar","simple","since","sing","siren","sister","situate","six","size","skate","sketch","ski","skill","skin","skirt","skull","slab","slam","sleep","slender","slice","slide","slight","slim","slogan","slot","slow","slush","small","smart","smile","smoke","smooth","snack","snake","snap","sniff","snow","soap","soccer","social","sock","soda","soft","solar","soldier","solid","solution","solve","someone","song","soon","sorry","sort","soul","sound","soup","source","south","space","spare","spatial","spawn","speak","special","speed","spell","spend","sphere","spice","spider","spike","spin","spirit","split","spoil","sponsor","spoon","sport","spot","spray","spread","spring","spy","square","squeeze","squirrel","stable","stadium","staff","stage","stairs","stamp","stand","start","state","stay","steak","steel","stem","step","stereo","stick","still","sting","stock","stomach","stone","stool","story","stove","strategy","street","strike","strong","struggle","student","stuff","stumble","style","subject","submit","subway","success","such","sudden","suffer","sugar","suggest","suit","summer","sun","sunny","sunset","super","supply","supreme","sure","surface","surge","surprise","surround","survey","suspect","sustain","swallow","swamp","swap","swarm","swear","sweet","swift","swim","swing","switch","sword","symbol","symptom","syrup","system","table","tackle","tag","tail","talent","talk","tank","tape","target","task","taste","tattoo","taxi","teach","team","tell","ten","tenant","tennis","tent","term","test","text","thank","that","theme","then","theory","there","they","thing","this","thought","three","thrive","throw","thumb","thunder","ticket","tide","tiger","tilt","timber","time","tiny","tip","tired","tissue","title","toast","tobacco","today","toddler","toe","together","toilet","token","tomato","tomorrow","tone","tongue","tonight","tool","tooth","top","topic","topple","torch","tornado","tortoise","toss","total","tourist","toward","tower","town","toy","track","trade","traffic","tragic","train","transfer","trap","trash","travel","tray","treat","tree","trend","trial","tribe","trick","trigger","trim","trip","trophy","trouble","truck","true","truly","trumpet","trust","truth","try","tube","tuition","tumble","tuna","tunnel","turkey","turn","turtle","twelve","twenty","twice","twin","twist","two","type","typical","ugly","umbrella","unable","unaware","uncle","uncover","under","undo","unfair","unfold","unhappy","uniform","unique","unit","universe","unknown","unlock","until","unusual","unveil","update","upgrade","uphold","upon","upper","upset","urban","urge","usage","use","used","useful","useless","usual","utility","vacant","vacuum","vague","valid","valley","valve","van","vanish","vapor","various","vast","vault","vehicle","velvet","vendor","venture","venue","verb","verify","version","very","vessel","veteran","viable","vibrant","vicious","victory","video","view","village","vintage","violin","virtual","virus","visa","visit","visual","vital","vivid","vocal","voice","void","volcano","volume","vote","voyage","wage","wagon","wait","walk","wall","walnut","want","warfare","warm","warrior","wash","wasp","waste","water","wave","way","wealth","weapon","wear","weasel","weather","web","wedding","weekend","weird","welcome","west","wet","whale","what","wheat","wheel","when","where","whip","whisper","wide","width","wife","wild","will","win","window","wine","wing","wink","winner","winter","wire","wisdom","wise","wish","witness","wolf","woman","wonder","wood","wool","word","work","world","worry","worth","wrap","wreck","wrestle","wrist","write","wrong","yard","year","yellow","you","young","youth","zebra","zero","zone","zoo"];