|
@@ 1-1 (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.bitcoinCash=a.network&&"BCC"===a.network,b.testnet=a.testnet=a.testnet||!1,b.bitcoinCash?b.testnet?b.network=h.networks.bitcoincashtestnet:b.network=h.networks.bitcoincash:b.testnet?b.network=h.networks.testnet:b.network=h.networks.bitcoin,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();return e.promise.spreadNodeify(c),e.resolve(g.fcall(function(){return d.mnemonicToSeedHex(a,b).then(function(a){return h.HDNode.fromSeedHex(a,d.network)})})),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);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,c.network),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,c.network),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);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,c.network),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=a.identifier;return e?(d.resolve(c.client.get("/wallet/"+e,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],c.network),i=f.mapValues(b.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),j=f.mapValues(b.primary_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),l=new k(c,e,a.walletVersion,b.primary_mnemonic,b.encrypted_primary_seed,b.encrypted_secret,j,g,i,d,b.segwit||0,c.testnet,b.checksum,b.upgrade_key_index,a.bypassNewAddressCheck);return l.recoverySecret=b.recovery_secret,a.readOnly?l:l.unlock(a).then(function(){return l})})),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.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();return a=f.merge({},a),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,b.network,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.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();return a=f.merge({},a),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,b.network,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.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,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, |
| 2 |
|
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.6"}},{}],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){var t=this;t.sdk=a,t.identifier=b,t.walletVersion=e,t.locked=!0,t.bypassNewAddressCheck=!!s,t.bitcoinCash=t.sdk.bitcoinCash,t.segwit=!!n,d(!t.segwit||!t.bitcoinCash),t.testnet=o,t.bitcoinCash?t.testnet?t.network=g.networks.bitcoincashtestnet:t.network=g.networks.bitcoincash:t.testnet?t.network=g.networks.testnet:t.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})),t.primaryMnemonic=f,t.encryptedPrimarySeed=h,t.encryptedSecret=i,t.primaryPrivateKey=null,t.backupPrivateKey=null,t.backupPublicKey=k,t.blocktrailPublicKeys=l,t.primaryPublicKeys=j,t.keyIndex=m,t.bitcoinCash?(t.chain=p.CHAIN_BCC_DEFAULT,t.changeChain=p.CHAIN_BCC_DEFAULT):t.segwit?(t.chain=p.CHAIN_BTC_DEFAULT,t.changeChain=p.CHAIN_BTC_SEGWIT):(t.chain=p.CHAIN_BTC_DEFAULT,t.changeChain=p.CHAIN_BTC_DEFAULT),t.checksum=q,t.upgradeToKeyIndex=r,t.secret=null,t.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!!this.segwit},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,b){var c=this;"function"==typeof a&&(b=a,a=null),"undefined"!=typeof a&&null!==a||(a=c.chain);var d=e.defer();return d.promise.spreadNodeify(b),d.resolve(c.sdk.getNewDerivation(c.identifier,"M/"+c.keyIndex+"'/"+a).then(function(a){var b=a.path,d=a.address;if(!c.bypassNewAddressCheck&&(d=c.getAddressByPath(a.path),d!==a.address))throw new i.WalletAddressError("Failed to verify address ["+a.address+"] !== ["+d+"]");return[d,b]})),d.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(m.changeChain,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"); |
|
@@ 1-1 (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.bitcoinCash=a.network&&"BCC"===a.network,b.testnet=a.testnet=a.testnet||!1,b.bitcoinCash?b.testnet?b.network=h.networks.bitcoincashtestnet:b.network=h.networks.bitcoincash:b.testnet?b.network=h.networks.testnet:b.network=h.networks.bitcoin,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();return e.promise.spreadNodeify(c),e.resolve(g.fcall(function(){return d.mnemonicToSeedHex(a,b).then(function(a){return h.HDNode.fromSeedHex(a,d.network)})})),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);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,c.network),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,c.network),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);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,c.network),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=a.identifier;return e?(d.resolve(c.client.get("/wallet/"+e,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],c.network),i=f.mapValues(b.blocktrail_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),j=f.mapValues(b.primary_public_keys,function(a){return h.HDNode.fromBase58(a[0],c.network)}),l=new k(c,e,a.walletVersion,b.primary_mnemonic,b.encrypted_primary_seed,b.encrypted_secret,j,g,i,d,b.segwit||0,c.testnet,b.checksum,b.upgrade_key_index,a.bypassNewAddressCheck);return l.recoverySecret=b.recovery_secret,a.readOnly?l:l.unlock(a).then(function(){return l})})),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.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();return a=f.merge({},a),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,b.network,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.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();return a=f.merge({},a),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,b.network,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.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,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, |
| 2 |
|
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.6"}},{}],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){var t=this;t.sdk=a,t.identifier=b,t.walletVersion=e,t.locked=!0,t.bypassNewAddressCheck=!!s,t.bitcoinCash=t.sdk.bitcoinCash,t.segwit=!!n,d(!t.segwit||!t.bitcoinCash),t.testnet=o,t.bitcoinCash?t.testnet?t.network=g.networks.bitcoincashtestnet:t.network=g.networks.bitcoincash:t.testnet?t.network=g.networks.testnet:t.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})),t.primaryMnemonic=f,t.encryptedPrimarySeed=h,t.encryptedSecret=i,t.primaryPrivateKey=null,t.backupPrivateKey=null,t.backupPublicKey=k,t.blocktrailPublicKeys=l,t.primaryPublicKeys=j,t.keyIndex=m,t.bitcoinCash?(t.chain=p.CHAIN_BCC_DEFAULT,t.changeChain=p.CHAIN_BCC_DEFAULT):t.segwit?(t.chain=p.CHAIN_BTC_DEFAULT,t.changeChain=p.CHAIN_BTC_SEGWIT):(t.chain=p.CHAIN_BTC_DEFAULT,t.changeChain=p.CHAIN_BTC_DEFAULT),t.checksum=q,t.upgradeToKeyIndex=r,t.secret=null,t.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!!this.segwit},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,b){var c=this;"function"==typeof a&&(b=a,a=null),"undefined"!=typeof a&&null!==a||(a=c.chain);var d=e.defer();return d.promise.spreadNodeify(b),d.resolve(c.sdk.getNewDerivation(c.identifier,"M/"+c.keyIndex+"'/"+a).then(function(a){var b=a.path,d=a.address;if(!c.bypassNewAddressCheck&&(d=c.getAddressByPath(a.path),d!==a.address))throw new i.WalletAddressError("Failed to verify address ["+a.address+"] !== ["+d+"]");return[d,b]})),d.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(m.changeChain,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"); |