(function(e){vari=function(e,i){Object.defineProperty(module.exports,e,{get:function(){returnrequire(i)}})};i("Bignum","bignum"),Object.defineProperty(module.exports,"bignum",{get:function(){returnconsole.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.'),require("bignum")}}),i("Base58","./lib/Base58"),Object.defineProperty(module.exports,"base58",{get:function(){returnconsole.log('base58 (with a lower-case "b") is deprecated. Use bitcore.Base58 (capital "B") instead.'),require("./lib/Base58")}}),i("bufferput","bufferput"),i("buffertools","buffertools"),i("Buffers.monkey","./patches/Buffers.monkey"),i("config","./config"),i("const","./const"),i("Deserialize","./lib/Deserialize"),i("ECIES","./lib/ECIES"),i("log","./util/log"),i("networks","./networks"),i("SecureRandom","./lib/SecureRandom"),i("sjcl","./lib/sjcl"),i("util","./util/util"),i("EncodedData","./util/EncodedData"),i("VersionedData","./util/VersionedData"),i("BinaryParser","./util/BinaryParser"),i("Address","./lib/Address"),i("HierarchicalKey","./lib/HierarchicalKey"),Object.defineProperty(module.exports,"BIP32",{get:function(){returnconsole.log("BIP32 is deprecated. Use bitcore.HierarchicalKey instead."),require("./lib/HierarchicalKey")}}),i("BIP39","./lib/BIP39"),i("BIP39WordlistEn","./lib/BIP39WordlistEn"),i("Point","./lib/Point"),i("Opcode","./lib/Opcode"),i("Script","./lib/Script"),i("Transaction","./lib/Transaction"),i("TransactionBuilder","./lib/TransactionBuilder"),i("Connection","./lib/Connection"),i("PayPro","./lib/PayPro"),i("Peer","./lib/Peer"),i("Block","./lib/Block"),i("ScriptInterpreter","./lib/ScriptInterpreter"),i("Bloom","./lib/Bloom"),i("Key","./lib/Key"),Object.defineProperty(module.exports,"KeyModule",{get:function(){returnconsole.log("KeyModule is deprecated."),require("bindings")("KeyModule")}}),i("SINKey","./lib/SINKey"),i("SIN","./lib/SIN"),i("PrivateKey","./lib/PrivateKey"),i("RpcClient","./lib/RpcClient"),i("Wallet","./lib/Wallet"),i("WalletKey","./lib/WalletKey"),i("PeerManager","./lib/PeerManager"),i("Message","./lib/Message"),i("Electrum","./lib/Electrum"),i("Armory","./lib/Armory"),i("NetworkMonitor","./lib/NetworkMonitor"),module.exports.Buffer=e}).call(this,require("buffer").Buffer);
(function(e){"use strict";functionr(t,i){if(i&&i.length&&(!e.isBuffer(i)||20!=i.length))thrownewError("Hash must be 20 bytes");r.super_.call(this,t,i)}vart=require("../util"),i=require("../util/VersionedData"),n=require("../util/EncodedData"),s=require("../networks"),o=require("./Script"),u=require("util");u.inherits(r,i),n.applyEncodingsTo(r),r.fromPubKey=function(e,i){if(i||(i="livenet"),33!==e.length&&65!==e.length)thrownewError("Invalid public key");varn=s[i].addressVersion,o=t.sha256ripe160(e);returnnewr(n,o)},r.fromKey=function(e,t){returnr.fromPubKey(e.public,t)},r.fromPubKeys=function(e,t,i,n){i||(i="livenet");for(varsint){varu=t[s];if(33!=u.length&&65!=u.length)thrownewError("Invalid public key")}vara=o.createMultisig(e,t,n);returnr.fromScript(a,i)},r.fromScript=function(i,n){n||(n="livenet"),"string"==typeofi&&(i=newo(newe(i,"hex")));varu=s[n].P2SHVersion,a=i.getBuffer(),f=t.sha256ripe160(a);returnnewr(u,f)},r.fromScriptPubKey=function(i,n){"string"==typeofi&&(i=newo(newe(i,"hex"))),n||(n="livenet");varu,a=[],f=i.capture();if(f){varc=i.classify();switch(c){caseo.TX_PUBKEY:f[0]=t.sha256ripe160(f[0]),u=s[n].addressVersion;break;caseo.TX_PUBKEYHASH:u=s[n].addressVersion;break;caseo.TX_MULTISIG:u=s[n].addressVersion;for(varlinf)f[l]=t.sha256ripe160(f[l]);break;caseo.TX_SCRIPTHASH:u=s[n].P2SHVersion}for(varlinf)a.push(newr(u,f[l]))}returna},r.prototype.validate=function(){if(this.doAsBinary(function(){if(r.super_.prototype.validate.apply(this),21!==this.data.length)thrownewError("invalid data length")}),"undefined"==typeofthis.network())thrownewError("invalid network")},r.prototype.network=function(){vare,r=this.version(),t=s.livenet,i=s.testnet;returnr===t.addressVersion||r===t.P2SHVersion?e=t:(r===i.addressVersion||r===i.P2SHVersion)&&(e=i),e},r.prototype.isScript=function(){returnthis.isValid()&&this.version()===this.network().P2SHVersion},r.prototype.getScriptPubKey=function(){vare,r=this.version(),t=s.livenet,i=s.testnet;if(r===t.addressVersion||r===i.addressVersion)e=o.createPubKeyHashOut(this.payload());else{if(r!==t.P2SHVersion&&r!==i.P2SHVersion)thrownewError("invalid address - unknown version");e=o.createP2SH(this.payload())}returne},r.fromPubkeyHashScriptSig=function(e,t){returnr.fromPubKey(e.chunks[1],t)},r.fromScriptSig=function(t,i){"string"==typeoft&&(t=newo(newe(t,"hex"))),i||(i="livenet");t.chunks;return2===t.chunks.length?r.fromPubkeyHashScriptSig(t,i):null},r.getScriptPubKeyFor=function(e){returnnewr(e).getScriptPubKey()},r.validate=function(e){returnnewr(e).isValid()},module.exports=r}).call(this,require("buffer").Buffer);
(function(e){varn=require("../util"),r=require("./sjcl"),t=require("./SecureRandom"),i=function(e){varn=newr.misc.hmac(e,r.hash.sha512);this.encrypt=function(){returnn.encrypt.apply(n,arguments)}},o=function(e,n,t){varo=r.misc.pbkdf2(e,n,t,512,i);returnr.codec.hex.fromBits(o)},l=function(){};l.mnemonic=function(e,n){if(n||(n=128),n%32!=0)thrownewError("bits must be multiple of 32");varr=t.getRandomBuffer(n/8);returnl.entropy2mnemonic(e,r)},l.entropy2mnemonic=function(e,r){for(vart=n.sha256(r),i="",o=8*r.length,l=0;l<r.length;l++)i+=("00000000"+r[l].toString(2)).slice(-8);varc=t[0].toString(2);if(c=("00000000"+c).slice(-8).slice(0,o/32),i+=c,i.length%11!=0)thrownewError("internal error - entropy not an even multiple of 11 bits - "+i.length);for(varu="",l=0;l<i.length/11;l++){""!=u&&(u+=" ");vars=parseInt(i.slice(11*l,11*(l+1)),2);u+=e[s]}returnu},l.check=function(r,t){for(vari=t.split(" "),o="",l=0;l<i.length;l++){varc=r.indexOf(i[l]);if(0>c)return!1;o+=("00000000000"+c.toString(2)).slice(-11)}if(o.length%11!=0)thrownewError("internal error - entropy not an even multiple of 11 bits - "+o.length);for(varu=o.length/33,s=o.slice(-u),a=o.slice(0,o.length-u),f=newe(a.length/8),l=0;l<a.length/8;l++)f.writeUInt8(parseInt(o.slice(8*l,8*(l+1)),2),l);varh=n.sha256(f),m=h[0].toString(2);returnm=("00000000"+m).slice(-8).slice(0,u),m==s},l.mnemonic2seed=function(n,r){r||(r="");vart=o(n,"mnemonic"+r,2048,64),i=newe(t,"hex");returni},module.exports=l}).call(this,require("buffer").Buffer);
(function(e){functionr(r){returnnewe(t.createHash("sha256").update(r).digest("binary"),"binary")}functionn(e){returnr(r(e))}for(vart=require("crypto"),o=require("bignum"),i=newe(1024),c=newe(0),f="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u=f[0],a=newe(f,"ascii"),h={},d=0;d<f.length;d++)h[f[d]]=d;varl={encode:function(r){varn,t,c=o.fromBuffer(r);n=r.length<512?i:newe(r.length<<1);for(varf=n.length-1;c.gt(0);)t=c.mod(58),c=c.div(58),n[f]=a[t.toNumber()],f--;for(varu=0;0==r[u];)n[f]=a[0],u++,f--;returnn.slice(f+1,n.length).toString("ascii")},decode:function(r){if(0==r.length)returnc;for(varn=o(0),t=0;t<r.length;t++)n=n.mul(58),n=n.add(h[r[t]]);for(vart=0;t<r.length&&r[t]==u;)t++;if(t>0){vari=newe(t);returni.fill(0),t==r.length?i:(n=n.toBuffer(),e.concat([i,n],t+n.length))}returnn.toBuffer()}},s={encode:function(r){vart=newe(r.length+4),o=n(r);returnr.copy(t),o.copy(t,r.length),l.encode(t)},decode:function(e){varr=l.decode(e);if(r.length<4)thrownewError("invalid input: too short");vart=r.slice(0,-4),o=r.slice(-4),i=n(t),c=i.slice(0,4);if(o.toString("hex")!==c.toString("hex"))thrownewError("checksum mismatch");returnt}};exports.setBuffer=function(e){i=e},exports.base58=l,exports.base58Check=s,exports.encode=l.encode,exports.decode=l.decode}).call(this,require("buffer").Buffer);
(function(t){functione(t){"object"!=typeoft&&(t={}),this.hash=t.hash||null,this.prev_hash=t.prev_hash||r.NULL_HASH,this.merkle_root=t.merkle_root||r.NULL_HASH,this.timestamp=t.timestamp||0,this.bits=t.bits||0,this.nonce=t.nonce||0,this.version=t.version||0,this.height=t.height||0,this.size=t.size||0,this.active=t.active||!1,this.chainWork=t.chainWork||r.EMPTY_BUFFER,this.txs=t.txs||[]}varr=require("../util"),i=require("./Script"),o=require("bignum"),s=(require("binary"),require("step"),require("buffertools")),h=require("./Transaction"),n=h.In,a=h.Out,c=h.COINBASE_OP,u=require("../util/error").VerificationError,l={maxTimeOffset:7200,largestHash:newo("10000000000000000000000000000000000000000000000000000000000000000",16)};e.prototype.getHeader=function(){vare=newt(80),r=0;returne.writeUInt32LE(this.version,r),r+=4,this.prev_hash.copy(e,r),r+=32,this.merkle_root.copy(e,r),r+=32,e.writeUInt32LE(this.timestamp,r),r+=4,e.writeUInt32LE(this.bits,r),r+=4,e.writeUInt32LE(this.nonce,r),r+=4,e},e.prototype.parse=function(t,e){if(this.version=t.word32le(),this.prev_hash=t.buffer(32),this.merkle_root=t.buffer(32),this.timestamp=t.word32le(),this.bits=t.word32le(),this.nonce=t.word32le(),this.txs=[],this.size=0,!e)for(varr=t.varInt(),i=0;r>i;i++){varo=newh;o.parse(t),this.txs.push(o)}},e.prototype.calcHash=function(){vart=this.getHeader();returnr.twoSha256(t)},e.prototype.checkHash=function(){returnthis.hash&&this.hash.length?0==s.compare(this.calcHash(),this.hash):!1},e.prototype.getHash=function(){returnthis.hash&&this.hash.length||(this.hash=this.calcHash()),this.hash},e.prototype.checkProofOfWork=function(){vart=r.decodeDiffBits(this.bits),e=s.reverse(this.hash);if(s.compare(e,t)>0)thrownewu("Difficulty target not met");return!0},e.prototype.getWork=function(){vart=r.decodeDiffBits(this.bits,!0);returnl.largestHash.div(t.add(1))},e.prototype.checkTimestamp=function(){vart=(newDate).getTime()/1e3;if(this.timestamp>t+l.maxTimeOffset)thrownewu("Timestamp too far into the future");return!0},e.prototype.checkTransactions=function(t){if(!Array.isArray(t)||t.length<=0)thrownewu("No transactions");if(!t[0].isCoinBase())thrownewu("First tx must be coinbase");for(vare=1;e<t.length;e++)if(t[e].isCoinBase())thrownewu("Tx index "+e+" must not be coinbase");return!0},e.prototype.getMerkleTree=function(e){if(0==e.length)return[r.NULL_HASH.slice(0)];for(vari=e.map(function(t){returntinstanceofh?t.getHash():t}),o=0,s=e.length;s>1;s=Math.floor((s+1)/2)){for(varn=0;s>n;n+=2){vara=Math.min(n+1,s-1),c=i[o+n],u=i[o+a];i.push(r.twoSha256(t.concat([c,u])))}o+=s}returni},e.prototype.calcMerkleRoot=function(t){vare=this.getMerkleTree(t);returne[e.length-1]},e.prototype.checkMerkleRoot=function(e){if(!this.merkle_root||!this.merkle_root.length)thrownewu("No merkle root");if(0!==s.compare(this.calcMerkleRoot(e),newt(this.merkle_root)))thrownewu("Merkle root incorrect");return!0},e.prototype.checkBlock=function(t){if(!this.checkHash())thrownewu("Block hash invalid");if(this.checkProofOfWork(),this.checkTimestamp(),t&&(this.checkTransactions(t),!this.checkMerkleRoot(t)))thrownewu("Merkle hash invalid");return!0},e.getBlockValue=function(t){vare=50*r.COIN;returne/=Math.pow(2,Math.floor(t/21e4)),e=Math.floor(e),e=newo(e)},e.prototype.getBlockValue=function(){returne.getBlockValue(this.height)},e.prototype.toString=function(){return"<Block "+r.formatHashAlt(this.hash)+" height="+this.height+">"},e.prototype.createCoinbaseTx=function(t){vare=newh;returne.ins.push(newn({s:r.EMPTY_BUFFER,q:4294967295,o:c})),e.outs.push(newa({v:r.bigIntToValue(this.getBlockValue()),s:i.createPubKeyOut(t).getBuffer()})),e},e.prototype.solve=function(t,e){vari=this.getHeader(),o=r.decodeDiffBits(this.bits);t.solve(i,o,e)},e.prototype.getStandardizedObject=function(t){vare={hash:r.formatHashFull(this.getHash()),version:this.version,prev_block:r.formatHashFull(this.prev_hash),mrkl_root:r.formatHashFull(this.merkle_root),time:this.timestamp,bits:this.bits,nonce:this.nonce,height:this.height};if(t){vari=this.getMerkleTree(t).map(
(function(e){functiont(e,t,r){if(this.config=r||a,this.network=h[this.config.network]||h.livenet,this.socket=e,this.peer=t,this.config.proxy){vars=require("socks5-client");this.socket=news(this.config.proxy.host,this.config.proxy.port)}this.active=!1,this.recvVer=0,this.sendVer=0,this.bestHeight=0,this.inbound=!!this.socket.server,this.getaddr=!1,this.buffers=newo,(newDate).getTime()>1329696e6&&(this.recvVer=209,this.sendVer=209),this.setupHandlers()}varr=require("../util/log"),s=1e7,n=7e4,i=require("bufferput"),o=require("buffers");require("../patches/Buffers.monkey").patch(o);vara=require("../config"),h=require("../networks"),c=require("./Block"),d=require("./Transaction"),f=require("../util"),u=require("../util/BinaryParser"),p=require("buffertools"),g=f.twoSha256,l=require("./SecureRandom"),v=l.getPseudoRandomBuffer(8),b=require("util"),k=require("events").EventEmitter,m=6e4;b.inherits(t,k),t.prototype.open=function(e){return"function"==typeofe&&this.once("connect",e),this.socket.connect(this.peer.port,this.peer.host),this},t.prototype.setupHandlers=function(){this.socket.addListener("connect",this.handleConnect.bind(this)),this.socket.addListener("error",this.handleError.bind(this)),this.socket.addListener("end",this.handleDisconnect.bind(this)),this.socket.addListener("data",function(e){vart=35;r.debug("["+this.peer+"] Recieved "+e.length+" bytes of data:"),r.debug("... "+p.toHex(e.slice(0,t>e.length?e.length:t))+(e.length>t?"...":""))}.bind(this)),this.socket.addListener("data",this.handleData.bind(this))},t.prototype.handleConnect=function(){this.inbound||this.sendVersion(),this.emit("connect",{conn:this,socket:this.socket,peer:this.peer})},t.prototype.handleError=function(e){110==e.errno||"ETIMEDOUT"==e.errno?r.info("connection timed out for "+this.peer):111==e.errno||"ECONNREFUSED"==e.errno?r.info("connection refused for "+this.peer):r.warn("connection with "+this.peer+" "+e.toString()),this.emit("error",{conn:this,socket:this.socket,peer:this.peer,err:e})},t.prototype.handleDisconnect=function(){this.emit("disconnect",{conn:this,socket:this.socket,peer:this.peer})},t.prototype.handleMessage=function(t){if(t){try{switch(t.command){case"version":if(0===p.compare(v,t.nonce))returnvoidthis.socket.end();this.inbound&&this.sendVersion(),t.version>=209&&this.sendMessage("verack",newe([])),this.sendVer=Math.min(t.version,n),t.version<209?this.recvVer=Math.min(t.version,n):this.once("verack",function(){this.recvVer=t.version}.bind(this)),this.bestHeight=t.start_height;break;case"verack":this.recvVer=Math.min(t.version,n),this.active=!0;break;case"ping":"object"==typeoft.nonce&&this.sendPong(t.nonce)}}catch(s){returnvoidr.err('Error while handling "'+t.command+'" message from '+this.peer+":\n"+(s.stack?s.stack:s.toString()))}this.emit(t.command,{conn:this,socket:this.socket,peer:this.peer,message:t})}},t.prototype.sendPong=function(e){this.sendMessage("pong",e)},t.prototype.sendVersion=function(){vart="/BitcoinX:0.1/",r=newi;r.word32le(n),r.word64le(1),r.word64le(Math.round((newDate).getTime()/1e3)),r.pad(26),r.pad(26),r.put(v),r.varint(t.length),r.put(newe(t,"ascii")),r.word32le(0),this.sendMessage("version",r.buffer())},t.prototype.sendGetBlocks=function(t,r,s){r=r||f.NULL_HASH;varn=newi;n.word32le(this.sendVer),n.varint(t.length);for(varo=0;o<t.length;o++){if(32!=t[o].length)thrownewError("Invalid hash length");n.put(t[o])}vara=newe(r,"binary");if(32!=a.length)thrownewError("Invalid hash length");n.put(a);varh="getblocks";s&&(h="getheaders"),this.sendMessage(h,n.buffer())},t.prototype.sendGetHeaders=function(e,t){this.sendGetBlocks(e,t,!0)},t.prototype.sendGetData=function(e){vart=newi;t.varint(e.length);for(varr=0;r<e.length;r++)t.word32le(e[r].type),t.put(e[r].hash);this.sendMessage("getdata",t.buffer())},t.prototype.sendGetAddr=function(){vare=newi;this.sendMessage("getaddr",e.buffer())},t.prototype.sendInv=function(e){Array.isArray(e)||(e=[e]);vart=newi;t.varint(e.length),e.forEach(function(e){t.word32le(einstanceofc?2:1),t.put(e.getHash())}),this.sendMessage("inv",t.buffer(
(function(e){"use strict";varn=require("../util"),i=require("./Key"),r=function(){};r.sign=function(e,n){vari=r.magicHash(e),t=n.signSync(i);returnt},r.verifyWithPubKey=function(e,n,t){varu=r.magicHash(n),a=newi;return65==e.length&&(a.compressed=!1),a.public=e,a.verifySignatureSync(u,t)},r.magicBytes=newe("Bitcoin Signed Message:\n"),r.magicHash=function(i){vart=r.magicBytes,u=n.varIntBuf(t.length),a=newe(i),c=n.varIntBuf(a.length),s=e.concat([u,t,c,a]),f=n.twoSha256(s);returnf},module.exports=r}).call(this,require("buffer").Buffer);
varlog=require("../util/log"),networks=require("../networks"),Address=require("./Address"),Peer=require("./Peer"),PeerManager=require("./PeerManager"),util=require("util"),EventEmitter=require("events").EventEmitter,preconditions=require("preconditions").singleton(),NetworkMonitor=function(e){preconditions.checkArgument(e),this.peerman=e,this.networkName=e.config.network,this.init()};util.inherits(NetworkMonitor,EventEmitter),NetworkMonitor.create=function(e){this.config=e;vart=newPeerManager({network:e.networkName});returnt.addPeer(newPeer(e.host,e.port)),newNetworkMonitor(t)},NetworkMonitor.prototype.init=function(){vare=this,t=function(e){vart=e.message.invs;e.conn.sendGetData(t)},n=function(t){e.emit("block",t.message)},o=function(t){varn=t.message.tx;e.emit("tx",n);for(varo=n.getSendingAddresses(e.config.networkName),r=0;r<o.length;r++){vari=o[r];e.emit("out:"+i,n)}for(vars=n.getReceivingAddresses(e.config.networkName),r=0;r<s.length;r++){vari=s[r];e.emit("in:"+i,n)}};this.peerman.on("connection",function(r){if(e.connection)thrownewError("Cant handle more than one connection");e.connection=r,r.on("inv",t),r.on("block",n),r.on("tx",o)})},NetworkMonitor.prototype.incoming=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("in:"+e,t)},NetworkMonitor.prototype.outgoing=function(e,t){preconditions.checkArgument(Address.validate(e)),this.on("out:"+e,t)},NetworkMonitor.prototype.start=function(){this.peerman.start()},NetworkMonitor.prototype.stop=function(){this.peerman.stop()},module.exports=NetworkMonitor;
functionPeerManager(e){this.config=e||{};for(varninbitcoreDefaults)bitcoreDefaults.hasOwnProperty(n)&&void0===this.config[n]&&(this.config[n]=bitcoreDefaults[n]);this.active=!1,this.timer=null,this.peers=[],this.pool=[],this.connections=[],this.isConnected=!1,this.peerDiscovery=!1,this.interval=5e3,this.minConnections=8,this.minKnownPeers=10,this.seeds={resolved:[],failed:[]}}varlog=require("../util/log"),bitcoreDefaults=require("../config"),Connection=require("./Connection"),Peer=require("./Peer"),async=require("async"),dns=require("dns"),networks=require("../networks"),util=require("util");GetAdjustedTime=function(){returnMath.floor((newDate).getTime()/1e3)};varEventEmitter=require("events").EventEmitter;util.inherits(PeerManager,EventEmitter),PeerManager.Connection=Connection,PeerManager.prototype.start=function(){this.active=!0,this.timer||(this.timer=setInterval(this.checkStatus.bind(this),this.interval))},PeerManager.prototype.stop=function(){this.active=!1,this.timer&&(clearInterval(this.timer),this.timer=null);for(vare=0;e<this.connections.length;e++)this.connections[e].socket.end()},PeerManager.prototype.addPeer=function(e,n){if(einstanceofPeer)this.peers.push(e);else{if("string"!=typeofe)throwlog.err("Node.addPeer(): Invalid value provided for peer",{val:e}),"Node.addPeer(): Invalid value provided for peer.";this.addPeer(newPeer(e,n))}},PeerManager.prototype.removePeer=function(e){varn=this.peers.indexOf(e),t=!!~n;returnt&&this.peers.splice(n,1),t},PeerManager.prototype.checkStatus=function(){if(this.peers.length){vare={};this.peers.forEach(function(n){e[n.toString()]=n}),this.connections.forEach(function(n){vart=n.peer.toString();"undefined"!==e[t]&&deletee[t]});varn=0;this.peers.forEach(function(e){e.connection&&!e.connection._connecting&&n++}),log.debug(n+" of "+this.peers.length+" peers connected"),Object.keys(e).forEach(function(n){this.connectTo(e[n])}.bind(this))}},PeerManager.prototype.connectTo=function(e){log.info("connecting to "+e);try{returnthis.addConnection(e.createConnection(),e)}catch(n){returnlog.err("creating connection",n),null}},PeerManager.prototype.addConnection=function(e,n){vart=newConnection(e,n,this.config);returnthis.connections.push(t),this.emit("connection",t),t.addListener("version",this.handleVersion.bind(this)),t.addListener("verack",this.handleReady.bind(this)),t.addListener("addr",this.handleAddr.bind(this)),t.addListener("getaddr",this.handleGetAddr.bind(this)),t.addListener("error",this.handleError.bind(this)),t.addListener("disconnect",this.handleDisconnect.bind(this)),t},PeerManager.prototype.handleVersion=function(e){e.peer.version=e.message.version,e.peer.start_height=e.message.start_height,!e.conn.inbound,this.peerDiscovery&&(e.message.version>=31402||this.peers.length<1e3)&&(e.conn.sendGetAddr(),e.conn.getaddr=!0)},PeerManager.prototype.handleReady=function(e){log.info("connected to "+e.conn.peer.host+":"+e.conn.peer.port),this.emit("connect",{pm:this,conn:e.conn,socket:e.socket,peer:e.peer}),0==this.isConnected&&(this.emit("netConnected",e),this.isConnected=!0)},PeerManager.prototype.handleAddr=function(e){if(this.peerDiscovery){varn=GetAdjustedTime();e.message.addrs.forEach(function(e){try{(e.time<=1e8||e.time>n+600)&&(e.time=n-432e3);vart=newPeer(e.ip,e.port,e.services);t.lastSeen=e.time,this.peers.push(t)}catch(r){log.warn("Invalid addr received: "+r.message)}}.bind(this)),e.message.addrs.length<1e3&&(e.conn.getaddr=!1)}},PeerManager.prototype.handleGetAddr=function(){},PeerManager.prototype.handleError=function(e){log.err("unkown error with peer "+e.peer+" (disconnecting): "+e.err),this.handleDisconnect.apply(this,[].slice.call(arguments))},PeerManager.prototype.handleDisconnect=function(e){log.info("disconnected from peer "+e.peer);varn=this.connections.indexOf(e.conn);-1!=n&&this.connections.splice(n,1),this.removePeer(e.peer),this.pool.length&&(log.info("replacing peer using the pool of "+this.pool.length+" seeds"),this.addPeer(this.pool.pop())),this.connections.length||(this.emit("netDisconnected"),this.isConnected=!1)},PeerManag
(function(t){"use strict";functioni(n,r){if("number"!=typeofn)returnvoidi.super_.call(this,n,r);if(!t.isBuffer(r)||20!=r.length)thrownewError("Payload must be 20 bytes");this.data=newt(2+r.length),this.converters=this.encodings.binary.converters,this._encoding=this.encodings.binary._encoding,this.encoding("binary"),this.prefix(15),this.type(n),this.payload(r)}varn=require("../util/VersionedData"),r=require("../util/EncodedData"),e=require("util"),o=require("../util");e.inherits(i,n),r.applyEncodingsTo(i),i.SIN_PERSIST_MAINNET=1,i.SIN_PERSIST_TESTNET=17,i.SIN_EPHEM=2,i.prototype.prefix=function(t){returnt||0===t?(this.doAsBinary(function(){this.data.writeUInt8(t,0)}),t):this.as("binary").readUInt8(0)},i.prototype.type=function(t){returnt||0===t?(this.doAsBinary(function(){this.data.writeUInt8(t,1)}),t):this.as("binary").readUInt8(1)},i.prototype.payload=function(t){returnt?(this.doAsBinary(function(){t.copy(this.data,2)}),t):this.as("binary").slice(1)},i.prototype.validate=function(){this.doAsBinary(function(){if(i.super_.prototype.validate.call(this),22!=this.data.length)thrownewError("invalid data length")})},i.fromPubKey=function(n,r){if(r||(r=i.SIN_EPHEM),!t.isBuffer(n)||33!==n.length&&65!=n.length)thrownewError("Invalid public key");vare=o.sha256ripe160(n);returnnewi(e,r)},module.exports=i}).call(this,require("buffer").Buffer);
(function(t){functione(t){this.buffer=t?t:f.EMPTY_BUFFER,this.chunks=[],this.parse()}functionr(t){returnt==h.map.OP_0||t>=h.map.OP_1&&t<=h.map.OP_16}functionn(t){returnt<h.map.OP_PUSHDATA1?1:255>=t?2:65535>=t?3:5}functions(e){varr=void0;returne<h.map.OP_PUSHDATA1?(r=newt(1),r.writeUInt8(e,0)):255>=e?(r=newt(2),r.writeUInt8(h.map.OP_PUSHDATA1,0),r.writeUInt8(e,1)):65535>=e?(r=newt(3),r.writeUInt8(h.map.OP_PUSHDATA2,0),r.writeUInt16LE(e,1)):(r=newt(5),r.writeUInt8(h.map.OP_PUSHDATA4,0),r.writeUInt32LE(e,1)),r}varu=(require("../config"),require("../util/log")),h=require("./Opcode"),o=require("buffertools"),f=require("../util/util"),c=require("../util/BinaryParser"),p=require("bufferput"),a=0,l=1,g=2,k=3,w=4,y=["unknown","pubkey","pubkeyhash","multisig","scripthash"];e.TX_UNKNOWN=a,e.TX_PUBKEY=l,e.TX_PUBKEYHASH=g,e.TX_MULTISIG=k,e.TX_SCRIPTHASH=w,e.prototype.parse=function(){this.chunks=[];for(vart=newc(this.buffer);!t.eof();){vare,r,n=t.word8();n>0&&n<h.map.OP_PUSHDATA1?this.chunks.push(t.buffer(n)):n===h.map.OP_PUSHDATA1?(e=t.word8(),r=t.buffer(e),this.chunks.push(r)):n===h.map.OP_PUSHDATA2?(e=t.word16le(),r=t.buffer(e),this.chunks.push(r)):n===h.map.OP_PUSHDATA4?(e=t.word32le(),r=t.buffer(e),this.chunks.push(r)):this.chunks.push(n)}},e.prototype.isPushOnly=function(){for(vare=0;e<this.chunks.length;e++){varr=this.chunks[e];if(!t.isBuffer(r)&&r>h.map.OP_16)return!1}return!0},e.prototype.isP2SH=function(){return3==this.chunks.length&&this.chunks[0]==h.map.OP_HASH160&&t.isBuffer(this.chunks[1])&&20==this.chunks[1].length&&this.chunks[2]==h.map.OP_EQUAL},e.prototype.isPubkey=function(){return2==this.chunks.length&&t.isBuffer(this.chunks[0])&&this.chunks[1]==h.map.OP_CHECKSIG},e.prototype.isPubkeyHash=function(){return5==this.chunks.length&&this.chunks[0]==h.map.OP_DUP&&this.chunks[1]==h.map.OP_HASH160&&t.isBuffer(this.chunks[2])&&20==this.chunks[2].length&&this.chunks[3]==h.map.OP_EQUALVERIFY&&this.chunks[4]==h.map.OP_CHECKSIG},e.prototype.isMultiSig=function(){returnthis.chunks.length>3&&r(this.chunks[0])&&this.chunks.slice(1,this.chunks.length-2).every(function(e){returnt.isBuffer(e)})&&r(this.chunks[this.chunks.length-2])&&this.chunks[this.chunks.length-1]==h.map.OP_CHECKMULTISIG},e.prototype.isP2shScriptSig=function(){if(!r(this.chunks[0])||0!==this.chunks[0])return!1;vart=newe(this.chunks[this.chunks.length-1]),n=t.classify();returnn!==a},e.prototype.isMultiSigScriptSig=function(){returnr(this.chunks[0])&&0===this.chunks[0]?!this.isP2shScriptSig():!1},e.prototype.countSignatures=function(){vart=0,e=this.chunks.length;returnt=this.isMultiSigScriptSig()?e-1:this.isP2shScriptSig()?e-2:0===o.compare(this.getBuffer(),f.EMPTY_BUFFER)?0:1},e.prototype.countMissingSignatures=function(){if(this.isMultiSig())returnu.debug("Can not count missing signatures on normal Multisig script"),null;vart=0,n=this.chunks.length;if(r(this.chunks[0])&&0===this.chunks[0]){vari=newe(this.chunks[n-1]);if(r(i.chunks[0])){vars=i.chunks[0]-80;t=s-(n-2)}elseu.debug("Unrecognized script type")}else0===o.compare(this.getBuffer(),f.EMPTY_BUFFER)&&(t=1);returnt},e.prototype.finishedMultiSig=function(){vart=this.countMissingSignatures();returnnull===t?null:0===t},e.prototype.getMultiSigInfo=function(){if(!this.isMultiSig())thrownewError("Script.getMultiSigInfo(): Not a multiSig script.");for(vart=this.chunks[0]-80,e=this.chunks[this.chunks.length-2]-80,r=[],n=1;n<this.chunks.length-2;n++)r.push(this.chunks[n]);if(r.length!=e)thrownewError("Script.getMultiSigInfo(): Amount of PKs does not match what the script specifies.");return{nsigs:t,npubkeys:e,pubkeys:r}},e.prototype.prependOp0=function(){vart=[0];for(iinthis.chunks)this.chunks.hasOwnProperty(i)&&t.push(this.chunks[i]);returnthis.chunks=t,this.updateBuffer(),this},e.prototype.classify=function(){returnthis.isPubkeyHash()?g:this.isP2SH()?w:this.isMultiSig()?k:this.isPubkey()?l:a},e.prototype.capture=function(){vart=this.classify(),e=[];switch(t){casel:e.push(this.chunks[0]);break;caseg:e.push(this.chunks[2]);break;casek:for(varr=1;r<this.chunks.leng
(function(t){"use strict";functione(t){returnt=t||{},this.lockTime=t.lockTime||0,this.spendUnconfirmed=t.spendUnconfirmed||!1,(t.fee||t.feeSat)&&(this.givenFeeSat=t.fee?t.fee*n.COIN:t.feeSat),this.remainderOut=t.remainderOut,this.signhash=t.signhash||f.SIGHASH_ALL,this.tx={},this.inputsSigned=0,this.signaturesAdded=0,this}varr=require("./Address"),i=require("./Script"),n=require("../util"),s=require("bignum"),a=require("buffertools"),u=require("../networks"),o=require("./WalletKey"),h=require("./PrivateKey"),p=require("./Key"),c=require("../util/log"),f=require("./Transaction"),d=parseInt(1e-4*n.COIN);e.FEE_PER_1000B_SAT=d,e._scriptForPubkeys=function(e){for(varr=e.pubkeys.length,n=[],s=0;r>s;s++)n.push(newt(e.pubkeys[s],"hex"));returni.createMultisig(e.nreq,n)},e._scriptForOut=function(t){vare;if(t.address)e=newr(t.address).getScriptPubKey();else{if(!(t.pubkeys||t.nreq||t.nreq>1))thrownewError("unknown out type");e=this._scriptForPubkeys(t)}returne},e.infoForP2sh=function(t,e){vari=this._scriptForOut(t),s=n.sha256ripe160(i.getBuffer()),a="testnet"===e?u.testnet.P2SHVersion:u.livenet.P2SHVersion,o=newr(a,s),h=o.as("base58");return{script:i,scriptBufHex:i.getBuffer().toString("hex"),hash:s,address:h}},e.prototype.setUnspent=function(t){returnthis.utxos=t,this},e.prototype._setInputMap=function(){for(vare=[],r=this.selectedUtxos.length,n=0;r>n;n++){vars=this.selectedUtxos[n],a=newt(s.scriptPubKey,"hex"),u=newi(a),o=u.classify();if(o===i.TX_UNKNOWN)thrownewError("unkown output type at:"+n+" Type:"+u.getRawOutType());e.push({address:s.address,scriptPubKey:u,scriptType:o,i:n})}returnthis.inputMap=e,this},e.prototype.getSelectedUnspent=function(){returnthis.selectedUtxos},e.prototype._selectUnspent=function(t){if(!this.utxos||!this.utxos.length)thrownewError("unspent not set");vare=[6,1];this.spendUnconfirmed&&e.push(0);varr=[],i=s(0),a=!1,u=null,o=this.utxos.length;do{for(varh=e.shift(),p=0;o>p;p++){varc=this.utxos[p],f=c.confirmations||0;if(!(h>f||u&&f>=u)){vard=c.amountSat||n.parseValue(c.amount);if(i=i.add(d),r.push(c),i.cmp(t)>=0){a=!0;break}}}u=h}while(!a&&e.length);if(!a)thrownewError("not enough unspent tx outputs to fulfill totalNeededAmount [SAT]:"+t);returnthis.selectedUtxos=r,this._setInputMap(),this},e.prototype._setInputs=function(e){varr=this.selectedUtxos,i=r.length,u=s(0);e.ins=[];for(varo=0;i>o;o++){u=u.add(n.parseValue(r[o].amount));varh={};h.s=n.EMPTY_BUFFER,h.q=4294967295;varp=newt(r[o].txid,"hex"),c=a.reverse(p),f=parseInt(r[o].vout),d=newt(4);d.writeUInt32LE(f,0),h.o=t.concat([c,d]),e.ins.push(h)}returnthis.valueInSat=u,this},e.prototype._setFee=function(t){if("undefined"==typeofthis.valueOutSat)thrownewError("valueOutSat undefined");vare=this.valueOutSat.add(t);if(this.valueInSat.cmp(e)<0){varr=this.valueInSat.toString(),i=e.toString();thrownewError("transaction input amount is less than outputs: "+r+" < "+i+" [SAT]")}returnthis.feeSat=t,this},e.prototype._setRemainder=function(t,r){if("undefined"==typeofthis.valueInSat||"undefined"==typeofthis.valueOutSat)thrownewError("valueInSat / valueOutSat undefined");vari=this.valueInSat.sub(this.valueOutSat).sub(this.feeSat),a=t.outs.length;if(this.remainderSat=s(0),a>r&&t.outs.pop(),i.cmp(0)>0){varu=this.remainderOut||this.selectedUtxos[0],o=n.bigIntToValue(i),h=e._scriptForOut(u),p={v:o,s:h.getBuffer()};t.outs.push(p),this.remainderSat=i}returnthis},e.prototype._setFeeAndRemainder=function(t){vare,r=500,i=t.outs.length;do{e=parseInt(r/1e3)+1;varn=this.givenFeeSat?this.givenFeeSat:e*d,s=this.valueOutSat.add(n);this._selectUnspent(s)._setInputs(t)._setFee(n)._setRemainder(t,i),r=newf(t).getSize()}while(r>1e3*(e+1));returnthis},e.prototype.setOutputs=function(t){varr=s(0),i={};i.version=1,i.lock_time=this.lockTime||0,i.ins=[],i.outs=[];for(vara=t.length,u=0;a>u;u++){varo=t[u].amountSat||n.parseValue(t[u].amount),h=n.bigIntToValue(o),p=e._scriptForOut(t[u]),c={v:h,s:p.getBuffer()};i.outs.push(c);vard=t[u].amountSat||n.parseValue(t[u].amount);r=r.add(d)}returnthis.valueOutSat=r,this._setFeeAndRemainder
(function(e){functionr(e){if(e||(e={}),!e.network)thrownewError("network parameter is required");this.network=e.network,this.created=e.created,this.privKey=e.privKey}vari=require("../util"),t=require("../util/time"),s=require("./Key"),p=require("./PrivateKey"),n=require("./Address");r.prototype.generate=function(){this.privKey=s.generateSync(),this.created=t.curtime()},r.prototype.storeObj=function(){vare=this.privKey.public.toString("hex"),r=i.sha256ripe160(this.privKey.public),t=newn(this.network.addressVersion,r),s=newp(this.network.privKeyVersion,this.privKey.private,this.privKey.compressed),o={created:this.created,priv:s.toString(),pub:e,addr:t.toString()};returno},r.prototype.fromObj=function(r){if(this.created=r.created,this.privKey=news,64==r.priv.length)this.privKey.private=newe(r.priv,"hex"),this.privKey.compressed="undefined"==typeofr.compressed?!0:r.compressed;else{vari=newp(r.priv);i.validate(),this.privKey.private=newe(i.payload()),this.privKey.compressed=i.compressed()}this.privKey.regenerateSync()},module.exports=r}).call(this,require("buffer").Buffer);
(function(e){"use strict";vart=require("../sjcl"),c=require("../common/ECIES");c.symmetricEncrypt=function(c,r,o){vari=t.codec.hex.toBits(c.toString("hex")),s=t.codec.hex.toBits(r.toString("hex")),n=t.codec.hex.toBits(o.toString("hex"));t.beware["CBC mode is dangerous because it doesn't protect message integrity."]();varh=newt.cipher.aes(i),d=t.mode.cbc.encrypt(h,n,s),a=newe(t.codec.hex.fromBits(d),"hex"),x=e.concat([r,a]);returnx},c.symmetricDecrypt=function(c,r){varo=t.codec.hex.toBits(c.toString("hex")),i=r.slice(0,16),s=r.slice(16,r.length);t.beware["CBC mode is dangerous because it doesn't protect message integrity."]();varn=t.codec.hex.toBits(s.toString("hex")),h=t.codec.hex.toBits(i.toString("hex")),d=newt.cipher.aes(o),a=t.mode.cbc.decrypt(d,n,h),x=newe(t.codec.hex.fromBits(a),"hex");returnx},module.exports=c}).call(this,require("buffer").Buffer);
(function(e){varr=require("../SecureRandom"),t=require("bignum"),i=require("elliptic"),s=require("./Point"),n=require("../common/Key"),o=(require("util"),function(){this._pub=null,this._compressed=!0});for(varuinn)n.hasOwnProperty(u)&&(o[u]=n[u]);o.bufferToArray=function(e){for(varr=[],t=e.length,i=0;t>i;i++)r.push(e.readUInt8(i));returnr};Object.defineProperty(o.prototype,"public",{set:function(r){if(!e.isBuffer(r))thrownewError("Arg should be a buffer");vart=r[0];this._compressed=4!==t,this._pub=r},get:function(){returnthis._pub}}),Object.defineProperty(o.prototype,"compressed",{set:function(r){varn=this._compressed;if(this._compressed=!!r,n!=this._compressed){{this._pub}if(this._pub)if(this._compressed){varo=this._pub.slice(1,33),u=this._pub.slice(33,65),p=newt(o),c=newt(u),f=news(p,c);this._pub=f.toCompressedPubKey()}else{varh=i.curves.secp256k1,o=this._pub.slice(1,33),a=3==this._pub[0]?!0:!1,f=h.curve.pointFromX(a,o),u=newe(f.y.toArray()),y=newt(o),v=newt(u),b=news(y,v);this._pub=b.toUncompressedPubKey()}!this._compressed}},get:function(){returnthis._compressed}}),o.generateSync=function(){for(vare,s=i.curves.secp256k1;;)if(e=r.getRandomBuffer(32),t.fromBuffer(e,{size:32}).cmp(s.n)<0)break;varn=newo;returnn.private=e,n.regenerateSync(),n},o.prototype.regenerateSync=function(){if(!this.private)thrownewError("Key does not have a private key set");vare=i.curves.secp256k1,r=(e.g,e.g.mul(this.private)),n=newt(r.x.toArray()),o=newt(r.y.toArray()),u=news(n,o);returnthis._pub=this.compressed?u.toCompressedPubKey():u.toUncompressedPubKey(),this},o.prototype.signSync=function(r){i.curves.secp256k1;if(!this.private)thrownewError("Key does not have a private key set");if(!e.isBuffer(r)||32!==r.length)thrownewError("Arg should be a 32 bytes hash buffer");vars=newt(this.private),n=o.sign(r,s),u=o.rs2DER(n.r,n.s);returnu},o.prototype.verifySignature=function(e,r,t){try{vari=this.verifySignatureSync(e,r);t(null,i)}catch(s){t(s)}},o.prototype.verifySignatureSync=function(e,r){vart=newi.ec(i.curves.secp256k1),s=e.toString("hex"),n=this._pub.toString("hex"),r=r.toString("hex"),o=t.verify(s,r,n);returno},module.exports=o}).call(this,require("buffer").Buffer);
(function(e){"use strict";varr=(require("./Key"),require("bignum")),u=(require("assert"),require("elliptic")),i=require("../common/Point");i.add=function(e,r){vart=u.curves.secp256k1,n=t.curve.point(e.x,e.y),s=t.curve.point(r.x,r.y),c=n.add(s),f=newi(c.x,c.y);returnf},i.multiply=function(t,n){if(e.isBuffer(n)&&32!==n.length)thrownewError("if x is a buffer, it must be 32 bytes");vars=u.curves.secp256k1,c=s.curve.point(t.x,t.y);"string"==typeofn&&(n=newr(n));varf=c.mul(n),o=newi(f.x,f.y);returno},module.exports=i}).call(this,require("buffer").Buffer);
(function(o){varr=require("../common/SecureRandom");r.getRandomBuffer=function(r){if(!window.crypto&&!window.msCrypto)thrownewError("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)vare=window.crypto;else{if(!window.msCrypto||!window.msCrypto.getRandomValues)thrownewError("window.crypto.getRandomValues not available");vare=window.msCrypto}varn=newUint8Array(r);e.getRandomValues(n);varw=newo(n);returnw},module.exports=r}).call(this,require("buffer").Buffer);
(function(e){"use strict";varr=require("../../util"),t=require("../Point"),i=require("../SecureRandom"),n=require("../Key"),c=function(){};c.encryptObj=function(e,r,t,n){vars=newc;s.KB=e,s.message=r,t=s.getRandomSeed(t);varo=(s.R,s.S=s.getSfromPubkey()),u=c.kdf(o),a=s.kE=u.slice(0,32),p=s.kM=u.slice(32,64);n=n||i.getRandomBuffer(16);{varf=s.c=c.symmetricEncrypt(a,n,r);s.d=c.mac(p,f)}returns},c.encrypt=function(r,t,i,s){varo=c.encryptObj(r,t,i,s),u=newn;u.compressed=!1,u.public=o.R.toUncompressedPubKey(),u.compressed=!0;vara=u.public,p=e.concat([a,o.c,o.d]);returnp},c.decryptObj=function(e){varr=e.kB,i=e.R,n=e.c,s=e.d,o=t.multiply(i,r),u=o.x.toBuffer({size:32}),a=c.kdf(u),p=e.kE=a.slice(0,32),f=e.kM=a.slice(32,64),y=c.mac(f,n);if(s.toString("hex")!==y.toString("hex"))thrownewError("MAC check incorrect. Data is invalid.");varh=c.symmetricDecrypt(p,n);returnh},c.decrypt=function(e,r){if(r.length<97)thrownewError("invalid length of encrypted data");vari=newc;i.kB=e;vars=r.slice(0,33),o=newn;returno.public=s,o.compressed=!1,i.R=t.fromUncompressedPubKey(o.public),i.c=r.slice(33,r.length-64),i.d=r.slice(r.length-64,r.length),c.decryptObj(i)},c.kdf=function(e){vart=r.sha512(e);returnt},c.mac=function(e,t){vari=r.sha512hmac(e,t);returni},c.prototype.getRandomSeed=function(e){returne?(this.key=newn,this.key.private=e,this.key.regenerateSync()):this.key=n.generateSync(),this.r=this.key.private,this.key.compressed=!1,this.R=t.fromUncompressedPubKey(this.key.public),this.r},c.prototype.getSfromPubkey=function(){vare=newn;e.public=this.KB,e.compressed=!1;varr=t.fromUncompressedPubKey(e.public);returnthis.P=t.multiply(r,this.r),this.S=this.P.x.toBuffer({size:32}),this.S},c.prototype.getSfromPrivkey=function(){vare=this.R,r=this.kB,i=t.multiply(e,r),n=i.x.toBuffer({size:32});returnn},module.exports=c}).call(this,require("buffer").Buffer);
(function(r){vare=require("bignum"),n=require("./Point"),t=require("./SecureRandom"),o=function(){};o.parseDERsig=function(n){if(!r.isBuffer(n))thrownewError("DER formatted signature should be a buffer");vart=n[0];if(48!==t)thrownewError("Header byte should be 0x30");varo=n[1];if(o!==n.slice(2).length)thrownewError("Length byte should length of what follows");varf=n[2];if(2!==f)thrownewError("Integer byte for r should be 0x02");varu=n[3],i=n.slice(4,4+u),h=e.fromBuffer(i),a=0===n[4]?!0:!1;if(u!==i.length)thrownewError("Length of r incorrect");varg=n[4+u+0];if(2!==g)thrownewError("Integer byte for s should be 0x02");varl=n[4+u+1],w=n.slice(4+u+2,4+u+2+l),s=e.fromBuffer(w),c=0===n[4+u+2+2]?!0:!1;if(l!==w.length)thrownewError("Length of s incorrect");vard=4+u+2+l;if(o!==d-2)thrownewError("Length of signature incorrect");varm={header:t,length:o,rheader:f,rlength:u,rneg:a,rbuf:i,r:h,sheader:g,slength:l,sneg:c,sbuf:w,s:s};returnm},o.rs2DER=function(e,n){vart=e.toBuffer(),o=n.toBuffer(),f=128&t[0]?!0:!1,u=128&o[0]?!0:!1,i=f?r.concat([newr([0]),t]):t,h=u?r.concat([newr([0]),o]):o,a=2+i.length+2+h.length,g=i.length,l=h.length,w=2,s=2,c=48,d=r.concat([newr([c,a,w,g]),i,newr([s,l]),h]);returnd},o.sign=function(r,t,f){varu=t,i=n.getN(),h=newe(r);dovarf=f||o.genk(),a=n.getG(),g=n.multiply(a,f),l=g.x.mod(i),w=f.invm(i).mul(h.add(u.mul(l))).mod(i);while(l.cmp(newe(0))<=0||w.cmp(newe(0))<=0);return{r:l,s:w}},o.genk=function(){returnnewe(t.getRandomBuffer(8))},module.exports=o}).call(this,require("buffer").Buffer);
(function(n){!function(){functiont(n){vart=!1;returnfunction(){if(t)thrownewError("Callback was already called.");t=!0,n.apply(e,arguments)}}vare,r,u={};e=this,null!=e&&(r=e.async),u.noConflict=function(){returne.async=r,u};vari=function(n,t){if(n.forEach)returnn.forEach(t);for(vare=0;e<n.length;e+=1)t(n[e],e,n)},c=function(n,t){if(n.map)returnn.map(t);vare=[];returni(n,function(n,r,u){e.push(t(n,r,u))}),e},o=function(n,t,e){returnn.reduce?n.reduce(t,e):(i(n,function(n,r,u){e=t(e,n,r,u)}),e)},a=function(n){if(Object.keys)returnObject.keys(n);vart=[];for(vareinn)n.hasOwnProperty(e)&&t.push(e);returnt};"undefined"!=typeofn&&n.nextTick?(u.nextTick=n.nextTick,u.setImmediate="undefined"!=typeofsetImmediate?function(n){setImmediate(n)}:u.nextTick):"function"==typeofsetImmediate?(u.nextTick=function(n){setImmediate(n)},u.setImmediate=u.nextTick):(u.nextTick=function(n){setTimeout(n,0)},u.setImmediate=u.nextTick),u.each=function(n,e,r){if(r=r||function(){},!n.length)returnr();varu=0;i(n,function(i){e(i,t(function(t){t?(r(t),r=function(){}):(u+=1,u>=n.length&&r(null))}))})},u.forEach=u.each,u.eachSeries=function(n,t,e){if(e=e||function(){},!n.length)returne();varr=0,u=function(){t(n[r],function(t){t?(e(t),e=function(){}):(r+=1,r>=n.length?e(null):u())})};u()},u.forEachSeries=u.eachSeries,u.eachLimit=function(n,t,e,r){varu=l(t);u.apply(null,[n,e,r])},u.forEachLimit=u.eachLimit;varl=function(n){returnfunction(t,e,r){if(r=r||function(){},!t.length||0>=n)returnr();varu=0,i=0,c=0;!functiono(){if(u>=t.length)returnr();for(;n>c&&i<t.length;)i+=1,c+=1,e(t[i-1],function(n){n?(r(n),r=function(){}):(u+=1,c-=1,u>=t.length?r():o())})}()}},f=function(n){returnfunction(){vart=Array.prototype.slice.call(arguments);returnn.apply(null,[u.each].concat(t))}},s=function(n,t){returnfunction(){vare=Array.prototype.slice.call(arguments);returnt.apply(null,[l(n)].concat(e))}},p=function(n){returnfunction(){vart=Array.prototype.slice.call(arguments);returnn.apply(null,[u.eachSeries].concat(t))}},m=function(n,t,e,r){varu=[];t=c(t,function(n,t){return{index:t,value:n}}),n(t,function(n,t){e(n.value,function(e,r){u[n.index]=r,t(e)})},function(n){r(n,u)})};u.map=f(m),u.mapSeries=p(m),u.mapLimit=function(n,t,e,r){returny(t)(n,e,r)};vary=function(n){returns(n,m)};u.reduce=function(n,t,e,r){u.eachSeries(n,function(n,r){e(t,n,function(n,e){t=e,r(n)})},function(n){r(n,t)})},u.inject=u.reduce,u.foldl=u.reduce,u.reduceRight=function(n,t,e,r){vari=c(n,function(n){returnn}).reverse();u.reduce(i,t,e,r)},u.foldr=u.reduceRight;varh=function(n,t,e,r){varu=[];t=c(t,function(n,t){return{index:t,value:n}}),n(t,function(n,t){e(n.value,function(e){e&&u.push(n),t()})},function(){r(c(u.sort(function(n,t){returnn.index-t.index}),function(n){returnn.value}))})};u.filter=f(h),u.filterSeries=p(h),u.select=u.filter,u.selectSeries=u.filterSeries;varv=function(n,t,e,r){varu=[];t=c(t,function(n,t){return{index:t,value:n}}),n(t,function(n,t){e(n.value,function(e){e||u.push(n),t()})},function(){r(c(u.sort(function(n,t){returnn.index-t.index}),function(n){returnn.value}))})};u.reject=f(v),u.rejectSeries=p(v);vard=function(n,t,e,r){n(t,function(n,t){e(n,function(e){e?(r(n),r=function(){}):t()})},function(){r()})};u.detect=f(d),u.detectSeries=p(d),u.some=function(n,t,e){u.each(n,function(n,r){t(n,function(n){n&&(e(!0),e=function(){}),r()})},function(){e(!1)})},u.any=u.some,u.every=function(n,t,e){u.each(n,function(n,r){t(n,function(n){n||(e(!1),e=function(){}),r()})},function(){e(!0)})},u.all=u.every,u.sortBy=function(n,t,e){u.map(n,function(n,e){t(n,function(t,r){t?e(t):e(null,{value:n,criteria:r})})},function(n,t){if(n)returne(n);varr=function(n,t){vare=n.criteria,r=t.criteria;returnr>e?-1:e>r?1:0};e(null,c(t.sort(r),function(n){returnn.value}))})},u.auto=function(n,t){t=t||function(){};vare=a(n);if(!e.length)returnt(null);varr={},c=[],l=function(n){c.unshift(n)},f=function(n){for(vart=0;t<c.length;t+=1)if(c[t]===n)returnvoidc.splice(t,1)},s=function(){i(c.slice(0),function(n){n()})};l(function(){a(r).length===e.length&&(
(function(t){functionn(t){for(varn=0,e=0;e<t.length;e++)n+=Math.pow(256,e)*t[e];returnn}functione(t){for(varn=0,e=0;e<t.length;e++)n+=Math.pow(256,t.length-e-1)*t[e];returnn}functionr(t){varn=e(t);return128==(128&t[0])&&(n-=Math.pow(256,t.length)),n}functiono(t){vare=n(t);return128==(128&t[t.length-1])&&(e-=Math.pow(256,t.length)),e}functioni(t){vari={};return[1,2,4,8].forEach(function(u){vars=8*u;i["word"+s+"le"]=i["word"+s+"lu"]=t(u,n),i["word"+s+"ls"]=t(u,o),i["word"+s+"be"]=i["word"+s+"bu"]=t(u,e),i["word"+s+"bs"]=t(u,r)}),i.word8=i.word8u=i.word8be,i.word8s=i.word8bs,i}varu=require("chainsaw"),s=require("events").EventEmitter,f=require("buffers"),c=require("./lib/vars.js"),l=require("stream").Stream;exports=module.exports=function(n,e){if(t.isBuffer(n))returnexports.parse(n);varr=exports.stream();returnn&&n.pipe?n.pipe(r):n&&(n.on(e||"data",function(t){r.write(t)}),n.on("end",function(){r.end()})),r},exports.stream=function(n){functione(t,n,e){a={bytes:t,skip:e,cb:function(t){a=null,n(t)}},r()}functionr(){if(!a)returnvoid(b&&(w=!0));if("function"==typeofa)a();else{vart=p+a.bytes;if(g.length>=t){varn;null==p?(n=g.splice(0,t),a.skip||(n=n.slice())):(a.skip||(n=g.slice(p,t)),p=t),a.skip?a.cb():a.cb(n)}}}functiono(n){functiono(){w||n.next()}varu=i(function(t,n){returnfunction(r){e(t,function(t){v.set(r,n(t)),o()})}});returnu.tap=function(t){n.nest(t,v.store)},u.into=function(t,e){v.get(t)||v.set(t,{});varr=v;v=c(r.get(t)),n.nest(function(){e.apply(this,arguments),this.tap(function(){v=r})},v.store)},u.flush=function(){v.store={},o()},u.loop=function(t){vare=!1;n.nest(!1,functionr(){this.vars=v.store,t.call(this,function(){e=!0,o()},v.store),this.tap(function(){e?n.next():r.call(this)}.bind(this))},v.store)},u.buffer=function(t,n){"string"==typeofn&&(n=v.get(n)),e(n,function(n){v.set(t,n),o()})},u.skip=function(t){"string"==typeoft&&(t=v.get(t)),e(t,function(){o()})},u.scan=function(n,e){if("string"==typeofe)e=newt(e);elseif(!t.isBuffer(e))thrownewError("search must be a Buffer or a string");vari=0;a=function(){vart=g.indexOf(e,p+i),u=t-p-i;-1!==t?(a=null,null!=p?(v.set(n,g.slice(p,p+i+u)),p+=i+u+e.length):(v.set(n,g.slice(0,i+u)),g.splice(0,i+u+e.length)),o(),r()):u=Math.max(g.length-e.length-p-i,0),i+=u},r()},u.peek=function(t){p=0,n.nest(function(){t.call(this,v.store),this.tap(function(){p=null})})},u}if(n)returnexports.apply(null,arguments);vara=null,p=null,h=u.light(o);h.writable=!0;varg=f();h.write=function(t){g.push(t),r()};varv=c(),w=!1,b=!1;returnh.end=function(){b=!0},h.pipe=l.prototype.pipe,Object.getOwnPropertyNames(s.prototype).forEach(function(t){h[t]=s.prototype[t]}),h},exports.parse=function(n){vare=i(function(t,i){returnfunction(u){if(r+t<=n.length){vars=n.slice(r,r+t);r+=t,o.set(u,i(s))}elseo.set(u,null);returne}}),r=0,o=c();returne.vars=o.store,e.tap=function(t){returnt.call(e,o.store),e},e.into=function(t,n){o.get(t)||o.set(t,{});varr=o;returno=c(r.get(t)),n.call(e,o.store),o=r,e},e.loop=function(t){for(varn=!1,r=function(){n=!0};n===!1;)t.call(e,r,o.store);returne},e.buffer=function(t,i){"string"==typeofi&&(i=o.get(i));varu=n.slice(r,Math.min(n.length,r+i));returnr+=i,o.set(t,u),e},e.skip=function(t){return"string"==typeoft&&(t=o.get(t)),r+=t,e},e.scan=function(i,u){if("string"==typeofu)u=newt(u);elseif(!t.isBuffer(u))thrownewError("search must be a Buffer or a string");o.set(i,null);for(vars=0;s+r<=n.length-u.length+1;s++){for(varf=0;f<u.length&&n[r+s+f]===u[f];f++);if(f===u.length)break}returno.set(i,n.slice(r,r+s)),r+=s+u.length,e},e.peek=function(t){varn=r;returnt.call(e,o.store),r=n,e},e.flush=function(){returno.store={},e},e.eof=function(){returnr>=n.length},e}}).call(this,require("buffer").Buffer);
(function(n){functiont(n){vare=t.saw(n,{}),r=n.call(e.handlers,e);returnvoid0!==r&&(e.handlers=r),e.record(),e.chain()}functione(n){n.step=0,n.pop=function(){returnn.actions[n.step++]},n.trap=function(t,e){varr=Array.isArray(t)?t:[t];n.actions.push({path:r,step:n.step,cb:e,trap:!0})},n.down=function(t){vare=(Array.isArray(t)?t:[t]).join("/"),r=n.actions.slice(n.step).map(function(t){returnt.trap&&t.step<=n.step?!1:t.path.join("/")==e}).indexOf(!0);r>=0?n.step+=r:n.step=n.actions.length;vara=n.actions[n.step-1];a&&a.trap?(n.step=a.step,a.cb()):n.next()},n.jump=function(t){n.step=t,n.next()}}varr=require("traverse"),a=require("events").EventEmitter;module.exports=t,t.light=function(n){vare=t.saw(n,{}),r=n.call(e.handlers,e);returnvoid0!==r&&(e.handlers=r),e.chain()},t.saw=function(o,s){vari=newa;returni.handlers=s,i.actions=[],i.chain=function(){vart=r(i.handlers).map(function(n){if(this.isRoot)returnn;vare=this.path;"function"==typeofn&&this.update(function(){returni.actions.push({path:e,args:[].slice.call(arguments)}),t})});returnn.nextTick(function(){i.emit("begin"),i.next()}),t},i.pop=function(){returni.actions.shift()},i.next=function(){varn=i.pop();if(n){if(!n.trap){vart=i.handlers;n.path.forEach(function(n){t=t[n]}),t.apply(i.handlers,n.args)}}elsei.emit("end")},i.nest=function(n){vare=[].slice.call(arguments,1),r=!0;if("boolean"==typeofn){varr=n;n=e.shift()}vara=t.saw(o,{}),s=o.call(a.handlers,a);void0!==s&&(a.handlers=s),"undefined"!=typeofi.step&&a.record(),n.apply(a.chain(),e),r!==!1&&a.on("end",i.next)},i.record=function(){e(i)},["trap","down","jump"].forEach(function(n){i[n]=function(){thrownewError("To use the trap, down and jump features, please call record() first to start recording actions.")}}),i}}).call(this,require("/home/maraoz/git/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"));
functionTraverse(e){returnthisinstanceofTraverse?void(this.value=e):newTraverse(e)}functionwalk(e,t,r){varn=[],o=[],a=!0;returnfunctioni(e){varc=r?copy(e):e,s={},f={node:c,node_:e,path:[].concat(n),parent:o.slice(-1)[0],key:n.slice(-1)[0],isRoot:0===n.length,level:n.length,circular:null,update:function(e){f.isRoot||(f.parent.node[f.key]=e),f.node=e},"delete":function(){deletef.parent.node[f.key]},remove:function(){Array.isArray(f.parent.node)?f.parent.node.splice(f.key,1):deletef.parent.node[f.key]},before:function(e){s.before=e},after:function(e){s.after=e},pre:function(e){s.pre=e},post:function(e){s.post=e},stop:function(){a=!1}};if(!a)returnf;if("object"==typeofc&&null!==c){f.isLeaf=0==Object.keys(c).length;for(varu=0;u<o.length;u++)if(o[u].node_===e){f.circular=o[u];break}}elsef.isLeaf=!0;f.notLeaf=!f.isLeaf,f.notRoot=!f.isRoot;varl=t.call(f,f.node);if(void0!==l&&f.update&&f.update(l),s.before&&s.before.call(f,f.node),"object"==typeoff.node&&null!==f.node&&!f.circular){o.push(f);varp=Object.keys(f.node);p.forEach(function(e,t){n.push(e),s.pre&&s.pre.call(f,f.node[e],e);varo=i(f.node[e]);r&&Object.hasOwnProperty.call(f.node,e)&&(f.node[e]=o.node),o.isLast=t==p.length-1,o.isFirst=0==t,s.post&&s.post.call(f,o),n.pop()}),o.pop()}returns.after&&s.after.call(f,f.node),f}(e).node}functioncopy(e){if("object"==typeofe&&null!==e){vart;returnt=Array.isArray(e)?[]:einstanceofDate?newDate(e):einstanceofBoolean?newBoolean(e):einstanceofNumber?newNumber(e):einstanceofString?newString(e):Object.create(Object.getPrototypeOf(e)),Object.keys(e).forEach(function(r){t[r]=e[r]}),t}returne}module.exports=Traverse,Traverse.prototype.get=function(e){for(vart=this.value,r=0;r<e.length;r++){varn=e[r];if(!Object.hasOwnProperty.call(t,n)){t=void0;break}t=t[n]}returnt},Traverse.prototype.set=function(e,t){for(varr=this.value,n=0;n<e.length-1;n++){varo=e[n];Object.hasOwnProperty.call(r,o)||(r[o]={}),r=r[o]}returnr[e[n]]=t,t},Traverse.prototype.map=function(e){returnwalk(this.value,e,!0)},Traverse.prototype.forEach=function(e){returnthis.value=walk(this.value,e,!1),this.value},Traverse.prototype.reduce=function(e,t){varr=1===arguments.length,n=r?this.value:t;returnthis.forEach(function(t){this.isRoot&&r||(n=e.call(this,n,t))}),n},Traverse.prototype.deepEqual=function(e){if(1!==arguments.length)thrownewError("deepEqual requires exactly one object to compare against");vart=!0,r=e;returnthis.forEach(function(n){varo=function(){returnvoid(t=!1)}.bind(this);if(!this.isRoot){if("object"!=typeofr)returno();r=r[this.key]}vara=r;this.post(function(){r=a});vari=function(e){returnObject.prototype.toString.call(e)};if(this.circular)Traverse(e).get(this.circular.path)!==a&&o();elseif(typeofa!=typeofn)o();elseif(null===a||null===n||void0===a||void0===n)a!==n&&o();elseif(a.__proto__!==n.__proto__)o();elseif(a===n);elseif("function"==typeofa)ainstanceofRegExp?a.toString()!=n.toString()&&o():a!==n&&o();elseif("object"==typeofa)if("[object Arguments]"===i(n)||"[object Arguments]"===i(a))i(a)!==i(n)&&o();elseif(ainstanceofDate||ninstanceofDate)ainstanceofDate&&ninstanceofDate&&a.getTime()===n.getTime()||o();else{varc=Object.keys(a),s=Object.keys(n);if(c.length!==s.length)returno();for(varf=0;f<c.length;f++){varu=c[f];Object.hasOwnProperty.call(n,u)||o()}}}),t},Traverse.prototype.paths=function(){vare=[];returnthis.forEach(function(){e.push(this.path)}),e},Traverse.prototype.nodes=function(){vare=[];returnthis.forEach(function(){e.push(this.node)}),e},Traverse.prototype.clone=function(){vare=[],t=[];returnfunctionr(n){for(varo=0;o<e.length;o++)if(e[o]===n)returnt[o];if("object"==typeofn&&null!==n){vara=copy(n);returne.push(n),t.push(a),Object.keys(n).forEach(function(e){a[e]=r(n[e])}),e.pop(),t.pop(),a}returnn}(this.value)},Object.keys(Traverse.prototype).forEach(function(e){Traverse[e]=function(t){varr=[].slice.call(arguments,1),n=Traverse(t);returnn[e].apply(n,r)}});
(function(e,r){functiono(e){"string"==typeofe?e={bindings:e}:e||(e={}),e.__proto__=d,e.module_root||(e.module_root=exports.getRoot(exports.getFileName())),".node"!=i.extname(e.bindings)&&(e.bindings+=".node");for(varr,o,n,s=[],a=0,u=e.try.length;u>a;a++){r=t.apply(null,e.try[a].map(function(r){returne[r]||r})),s.push(r);try{returno=e.path?require.resolve(r):require(r),e.path||(o.path=r),o}catch(l){if(!/not find/i.test(l.message))throwl}}thrown=newError("Could not locate the bindings file. Tried:\n"+s.map(function(r){returne.arrow+r}).join("\n")),n.tries=s,n}varn=require("fs"),i=require("path"),t=i.join,s=i.dirname,a=n.existsSync||i.existsSync,d={arrow:e.env.NODE_BINDINGS_ARROW||" → ",compiled:e.env.NODE_BINDINGS_COMPILED_DIR||"compiled",platform:e.platform,arch:e.arch,version:e.versions.node,bindings:"bindings.node","try":[["module_root","build","bindings"],["module_root","build","Debug","bindings"],["module_root","build","Release","bindings"],["module_root","out","Debug","bindings"],["module_root","Debug","bindings"],["module_root","out","Release","bindings"],["module_root","Release","bindings"],["module_root","build","default","bindings"],["module_root","compiled","version","platform","arch","bindings"]]};module.exports=exports=o,exports.getFileName=function(){vare,o=Error.prepareStackTrace,n=Error.stackTraceLimit,i={};returnError.stackTraceLimit=10,Error.prepareStackTrace=function(o,n){for(vari=0,t=n.length;t>i;i++)if(e=n[i].getFileName(),e!==r)return},Error.captureStackTrace(i),i.stack,Error.prepareStackTrace=o,Error.stackTraceLimit=n,e},exports.getRoot=function(r){for(varo,n=s(r);;){if("."===n&&(n=e.cwd()),a(t(n,"package.json"))||a(t(n,"node_modules")))returnn;if(o===n)thrownewError('Could not find module root given file: "'+r+'". Do you have a `package.json` file? ');o=n,n=t(n,"..")}}}).call(this,require("/home/maraoz/git/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"/node_modules/bindings/bindings.js");
(function(t){"use strict";functionr(){this.writable=!0,this.buffer=null}vare=require("events"),n=require("util"),i={};module.exports.Buffer=t;varo=function(r){returnrinstanceoft||rinstanceofUint8Array},f=function(t){returnfunction(){varr=this;if(o(r));else{if(!o(arguments[0]))thrownewError("Argument should be a buffer object.");r=arguments[0],Array.prototype.shift.apply(arguments)}returnt.apply(r,arguments)}},u=function(t){returnfunction(){varr=this;if(o(r));else{if(!o(arguments[0]))throwError("Argument should be a buffer object.");r=arguments[0],Array.prototype.shift.apply(arguments)}vare=arguments[0];if("string"==typeofe||einstanceofString||o(e))returnt.apply(r,arguments);thrownewError("Second argument must be a string or a buffer.")}};i.clear=f(function(){for(vart=0;t<this.length;t++)this[t]=0;returnthis}),i.fill=f(function(t){for(varr="undefined"==typeoft.length?1:t.length,e=0;e<this.length;e+=r)for(varn=0;r>n;n++)this[e+n]="undefined"==typeoft.length?t:"string"==typeoft[n]?t[n].charCodeAt(0):t[n];returnthis}),i.indexOf=f(function(t,r){if(r=r||0,0===t.length)return-1;for(vare=r;e<this.length-t.length+1;e+=1){for(varn=!0,i=0;i<t.length;i++){varo=this[e+i],f=t[i];if("string"==typeoff&&(f=f.charCodeAt(0)),o!==f){n=!1;break}}if(n)returne}return-1}),i.equals=u(function(t){return0===i.compare(this,t)}),i.compare=u(function(t){varr=this,e=r.length,n=t.length;if(e!==n)returne>n?1:-1;for(vari=0;e>i;i++){varo=r[i],f=t[i];if("string"==typeoff&&(f=f.charCodeAt(0)),o!==f)returno>f?1:-1}return0}),i.concat=function(){for(varr=0,e=0;e<arguments.length;e++){if(void0===arguments[e].length)throwError("all arguments must be strings or Buffers");r+=arguments[e].length}for(varn=newt(r),i=0,e=0;e<arguments.length;e++)for(varo=0;o<arguments[e].length;o++)n[i++]="string"==typeofarguments[e][o]?arguments[e][o].charCodeAt(0):arguments[e][o];returnn},i.reverse=f(function(){for(varr=newt(this.length),e=0;e<this.length;e++)r[e]=this[this.length-e-1];returnr}),i.toHex=f(function(){for(vart="",r=0;r<this.length;r++){vare=this[r].toString(16);1==e.length&&(e="0"+e),e.length>2&&(e=e.substring(1,3)),t+=e}returnt}),i.fromHex=f(function(){varr=this.length;if(r%2!==0)thrownewError("Invalid hex string length");for(vare=newt(r/2),n=0;n<e.length;n++){vari=String.fromCharCode(this[2*n]),o=String.fromCharCode(this[2*n+1]);e[n]=parseInt(i+o,16)}returne}),exports.extend=function(){varr;r=arguments.length>0?Array.prototype.slice.call(arguments):"function"==typeofUint8Array?[t.prototype,Uint8Array.prototype]:[t.prototype];for(vare=0,n=r.length;n>e;e+=1){varo=r[e];for(varfini)o[f]=i[f];o!==exports&&(o.concat=function(){vart=[this].concat(Array.prototype.slice.call(arguments));returni.concat.apply(i,t)})}},exports.extend(exports),n.inherits(r,e.EventEmitter),r.prototype._append=function(r,e){if(!this.writable)thrownewError("Stream is not writable.");if(t.isBuffer(r));else{if("string"!=typeofr)thrownewError("Argument should be either a buffer or a string.");r=newt(r,e||"utf8")}this.buffer?this.buffer=i.concat(this.buffer,r):(this.buffer=newt(r.length),r.copy(this.buffer))},r.prototype.write=function(t,r){returnthis._append(t,r),!0},r.prototype.end=function(t,r){t&&this._append(t,r),this.emit("close"),this.writable=!1},r.prototype.getBuffer=function(){returnthis.buffer?this.buffer:newt(0)},r.prototype.toString=function(){returnthis.getBuffer().toString()},exports.WritableBufferStream=r}).call(this,require("buffer").Buffer);
functionBuffer(e,t,r){if(!(thisinstanceofBuffer))returnnewBuffer(e,t,r);varn=typeofe;if("base64"===t&&"string"===n)for(e=stringtrim(e);e.length%4!==0;)e+="=";vari;if("number"===n)i=coerce(e);elseif("string"===n)i=Buffer.byteLength(e,t);else{if("object"!==n)thrownewError("First argument needs to be a number, array or string.");i=coerce(e.length)}vars;Buffer._useTypedArrays?s=Buffer._augment(newUint8Array(i)):(s=this,s.length=i,s._isBuffer=!0);vara;if(Buffer._useTypedArrays&&"number"==typeofe.byteLength)s._set(e);elseif(isArrayish(e))for(a=0;i>a;a++)s[a]=Buffer.isBuffer(e)?e.readUInt8(a):e[a];elseif("string"===n)s.write(e,0,t);elseif("number"===n&&!Buffer._useTypedArrays&&!r)for(a=0;i>a;a++)s[a]=0;returns}function_hexWrite(e,t,r,n){r=Number(r)||0;vari=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;vars=t.length;assert(s%2===0,"Invalid hex string"),n>s/2&&(n=s/2);for(vara=0;n>a;a++){varo=parseInt(t.substr(2*a,2),16);assert(!isNaN(o),"Invalid hex string"),e[r+a]=o}returnBuffer._charsWritten=2*a,a}function_utf8Write(e,t,r,n){vari=Buffer._charsWritten=blitBuffer(utf8ToBytes(t),e,r,n);returni}function_asciiWrite(e,t,r,n){vari=Buffer._charsWritten=blitBuffer(asciiToBytes(t),e,r,n);returni}function_binaryWrite(e,t,r,n){return_asciiWrite(e,t,r,n)}function_base64Write(e,t,r,n){vari=Buffer._charsWritten=blitBuffer(base64ToBytes(t),e,r,n);returni}function_utf16leWrite(e,t,r,n){vari=Buffer._charsWritten=blitBuffer(utf16leToBytes(t),e,r,n);returni}function_base64Slice(e,t,r){returnbase64.fromByteArray(0===t&&r===e.length?e:e.slice(t,r))}function_utf8Slice(e,t,r){varn="",i="";r=Math.min(e.length,r);for(vars=t;r>s;s++)e[s]<=127?(n+=decodeUtf8Char(i)+String.fromCharCode(e[s]),i=""):i+="%"+e[s].toString(16);returnn+decodeUtf8Char(i)}function_asciiSlice(e,t,r){varn="";r=Math.min(e.length,r);for(vari=t;r>i;i++)n+=String.fromCharCode(e[i]);returnn}function_binarySlice(e,t,r){return_asciiSlice(e,t,r)}function_hexSlice(e,t,r){varn=e.length;(!t||0>t)&&(t=0),(!r||0>r||r>n)&&(r=n);for(vari="",s=t;r>s;s++)i+=toHex(e[s]);returni}function_utf16leSlice(e,t,r){for(varn=e.slice(t,r),i="",s=0;s<n.length;s+=2)i+=String.fromCharCode(n[s]+256*n[s+1]);returni}function_readUInt16(e,t,r,n){n||(assert("boolean"==typeofr,"missing or invalid endian"),assert(void0!==t&&null!==t,"missing offset"),assert(t+1<e.length,"Trying to read beyond buffer length"));vari=e.length;if(!(t>=i)){vars;returnr?(s=e[t],i>t+1&&(s|=e[t+1]<<8)):(s=e[t]<<8,i>t+1&&(s|=e[t+1])),s}}function_readUInt32(e,t,r,n){n||(assert("boolean"==typeofr,"missing or invalid endian"),assert(void0!==t&&null!==t,"missing offset"),assert(t+3<e.length,"Trying to read beyond buffer length"));vari=e.length;if(!(t>=i)){vars;returnr?(i>t+2&&(s=e[t+2]<<16),i>t+1&&(s|=e[t+1]<<8),s|=e[t],i>t+3&&(s+=e[t+3]<<24>>>0)):(i>t+1&&(s=e[t+1]<<16),i>t+2&&(s|=e[t+2]<<8),i>t+3&&(s|=e[t+3]),s+=e[t]<<24>>>0),s}}function_readInt16(e,t,r,n){n||(assert("boolean"==typeofr,"missing or invalid endian"),assert(void0!==t&&null!==t,"missing offset"),assert(t+1<e.length,"Trying to read beyond buffer length"));vari=e.length;if(!(t>=i)){vars=_readUInt16(e,t,r,!0),a=32768&s;returna?-1*(65535-s+1):s}}function_readInt32(e,t,r,n){n||(assert("boolean"==typeofr,"missing or invalid endian"),assert(void0!==t&&null!==t,"missing offset"),assert(t+3<e.length,"Trying to read beyond buffer length"));vari=e.length;if(!(t>=i)){vars=_readUInt32(e,t,r,!0),a=2147483648&s;returna?-1*(4294967295-s+1):s}}function_readFloat(e,t,r,n){returnn||(assert("boolean"==typeofr,"missing or invalid endian"),assert(t+3<e.length,"Trying to read beyond buffer length")),ieee754.read(e,t,r,23,4)}function_readDouble(e,t,r,n){returnn||(assert("boolean"==typeofr,"missing or invalid endian"),assert(t+7<e.length,"Trying to read beyond buffer length")),ieee754.read(e,t,r,52,8)}function_writeUInt16(e,t,r,n,i){i||(assert(void0!==t&&null!==t,"missing value"),assert("boolean"==typeofn,"missing or invalid endian"),assert(void0!==r&&null!==r,"missing offset"),assert(r+1<e.length,"tryingtowritebeyondb
varlookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";functionr(t){varr=t.charCodeAt(0);returnr===h?62:r===c?63:o>r?-1:o+10>r?r-o+26+26:i+26>r?r-i:A+26>r?r-A+26:void0}functione(t){functione(t){i[f++]=t}varn,h,c,o,A,i;if(t.length%4>0)thrownewError("Invalid string. Length must be a multiple of 4");varu=t.length;A="="===t.charAt(u-2)?2:"="===t.charAt(u-1)?1:0,i=newa(3*t.length/4-A),c=A>0?t.length-4:t.length;varf=0;for(n=0,h=0;c>n;n+=4,h+=3)o=r(t.charAt(n))<<18|r(t.charAt(n+1))<<12|r(t.charAt(n+2))<<6|r(t.charAt(n+3)),e((16711680&o)>>16),e((65280&o)>>8),e(255&o);return2===A?(o=r(t.charAt(n))<<2|r(t.charAt(n+1))>>4,e(255&o)):1===A&&(o=r(t.charAt(n))<<10|r(t.charAt(n+1))<<4|r(t.charAt(n+2))>>2,e(o>>8&255),e(255&o)),i}functionn(t){functionr(t){returnlookup.charAt(t)}functione(t){returnr(t>>18&63)+r(t>>12&63)+r(t>>6&63)+r(63&t)}varn,a,h,c=t.length%3,o="";for(n=0,h=t.length-c;h>n;n+=3)a=(t[n]<<16)+(t[n+1]<<8)+t[n+2],o+=e(a);switch(c){case1:a=t[t.length-1],o+=r(a>>2),o+=r(a<<4&63),o+="==";break;case2:a=(t[t.length-2]<<8)+t[t.length-1],o+=r(a>>10),o+=r(a>>4&63),o+=r(a<<2&63),o+="="}returno}vara="undefined"!=typeofUint8Array?Uint8Array:Array,h="+".charCodeAt(0),c="/".charCodeAt(0),o="0".charCodeAt(0),A="a".charCodeAt(0),i="A".charCodeAt(0);t.toByteArray=e,t.fromByteArray=n}("undefined"==typeofexports?this.base64js={}:exports);
functionEventEmitter(){this._events=this._events||{},this._maxListeners=this._maxListeners||void0}functionisFunction(e){return"function"==typeofe}functionisNumber(e){return"number"==typeofe}functionisObject(e){return"object"==typeofe&&null!==e}functionisUndefined(e){returnvoid0===e}module.exports=EventEmitter,EventEmitter.EventEmitter=EventEmitter,EventEmitter.prototype._events=void0,EventEmitter.prototype._maxListeners=void0,EventEmitter.defaultMaxListeners=10,EventEmitter.prototype.setMaxListeners=function(e){if(!isNumber(e)||0>e||isNaN(e))throwTypeError("n must be a positive number");returnthis._maxListeners=e,this},EventEmitter.prototype.emit=function(e){vart,n,s,i,r,o;if(this._events||(this._events={}),"error"===e&&(!this._events.error||isObject(this._events.error)&&!this._events.error.length))throwt=arguments[1],tinstanceofError?t:TypeError('Uncaught, unspecified "error" event.');if(n=this._events[e],isUndefined(n))return!1;if(isFunction(n))switch(arguments.length){case1:n.call(this);break;case2:n.call(this,arguments[1]);break;case3:n.call(this,arguments[1],arguments[2]);break;default:for(s=arguments.length,i=newArray(s-1),r=1;s>r;r++)i[r-1]=arguments[r];n.apply(this,i)}elseif(isObject(n)){for(s=arguments.length,i=newArray(s-1),r=1;s>r;r++)i[r-1]=arguments[r];for(o=n.slice(),s=o.length,r=0;s>r;r++)o[r].apply(this,i)}return!0},EventEmitter.prototype.addListener=function(e,t){varn;if(!isFunction(t))throwTypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,isFunction(t.listener)?t.listener:t),this._events[e]?isObject(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,isObject(this._events[e])&&!this._events[e].warned){varn;n=isUndefined(this._maxListeners)?EventEmitter.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeofconsole.trace&&console.trace())}returnthis},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.once=function(e,t){functionn(){this.removeListener(e,n),s||(s=!0,t.apply(this,arguments))}if(!isFunction(t))throwTypeError("listener must be a function");vars=!1;returnn.listener=t,this.on(e,n),this},EventEmitter.prototype.removeListener=function(e,t){varn,s,i,r;if(!isFunction(t))throwTypeError("listener must be a function");if(!this._events||!this._events[e])returnthis;if(n=this._events[e],i=n.length,s=-1,n===t||isFunction(n.listener)&&n.listener===t)deletethis._events[e],this._events.removeListener&&this.emit("removeListener",e,t);elseif(isObject(n)){for(r=i;r-->0;)if(n[r]===t||n[r].listener&&n[r].listener===t){s=r;break}if(0>s)returnthis;1===n.length?(n.length=0,deletethis._events[e]):n.splice(s,1),this._events.removeListener&&this.emit("removeListener",e,t)}returnthis},EventEmitter.prototype.removeAllListeners=function(e){vart,n;if(!this._events)returnthis;if(!this._events.removeListener)return0===arguments.length?this._events={}:this._events[e]&&deletethis._events[e],this;if(0===arguments.length){for(tinthis._events)"removeListener"!==t&&this.removeAllListeners(t);returnthis.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],isFunction(n))this.removeListener(e,n);elsefor(;n.length;)this.removeListener(e,n[n.length-1]);returndeletethis._events[e],this},EventEmitter.prototype.listeners=function(e){vart;returnt=this._events&&this._events[e]?isFunction(this._events[e])?[this._events[e]]:this._events[e].slice():[]},EventEmitter.listenerCount=function(e,t){varn;returnn=e._events&&e._events[t]?isFunction(e._events[t])?1:e._events[t].length:0};
varhttp=module.exports,EventEmitter=require("events").EventEmitter,Request=require("./lib/request"),url=require("url");http.request=function(e,t){"string"==typeofe&&(e=url.parse(e)),e||(e={}),e.host||e.port||(e.port=parseInt(window.location.port,10)),!e.host&&e.hostname&&(e.host=e.hostname),e.scheme||(e.scheme=window.location.protocol.split(":")[0]),e.host||(e.host=window.location.hostname||window.location.host),/:/.test(e.host)&&(e.port||(e.port=e.host.split(":")[1]),e.host=e.host.split(":")[0]),e.port||(e.port="https"==e.scheme?443:80);varo=newRequest(newxhrHttp,e);returnt&&o.on("response",t),o},http.get=function(e,t){e.method="GET";varo=http.request(e,t);returno.end(),o},http.Agent=function(){},http.Agent.defaultMaxSockets=4;varxhrHttp=function(){if("undefined"==typeofwindow)thrownewError("no window object present");if(window.XMLHttpRequest)returnwindow.XMLHttpRequest;if(window.ActiveXObject){for(vare=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"],t=0;t<e.length;t++)try{varo=newwindow.ActiveXObject(e[t]);returnfunction(){if(o){varr=o;returno=null,r}returnnewwindow.ActiveXObject(e[t])}}catch(r){}thrownewError("ajax not supported in this browser")}thrownewError("ajax not supported in this browser")}();http.STATUS_CODES={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Time-out",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Large",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"};
!function(){functiont(t){this.message=t}vare="undefined"!=typeofexports?exports:this,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.prototype=newError,t.prototype.name="InvalidCharacterError",e.btoa||(e.btoa=function(e){for(varo,n,a=0,i=r,c="";e.charAt(0|a)||(i="=",a%1);c+=i.charAt(63&o>>8-a%1*8)){if(n=e.charCodeAt(a+=.75),n>255)thrownewt("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|n}returnc}),e.atob||(e.atob=function(e){if(e=e.replace(/=+$/,""),e.length%4==1)thrownewt("'atob' failed: The string to be decoded is not correctly encoded.");for(varo,n,a=0,i=0,c="";n=e.charAt(i++);~n&&(o=a%4?64*o+n:n,a++%4)?c+=String.fromCharCode(255&o>>(-2*a&6)):0)n=r.indexOf(n);returnc})}();
functionnoop(){}varprocess=module.exports={};process.nextTick=function(){varo="undefined"!=typeofwindow&&window.setImmediate,e="undefined"!=typeofwindow&&window.postMessage&&window.addEventListener;if(o)returnfunction(o){returnwindow.setImmediate(o)};if(e){varn=[];returnwindow.addEventListener("message",function(o){vare=o.source;if((e===window||null===e)&&"process-tick"===o.data&&(o.stopPropagation(),n.length>0)){vars=n.shift();s()}},!0),function(o){n.push(o),window.postMessage("process-tick","*")}}returnfunction(o){setTimeout(o,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.once=noop,process.off=noop,process.emit=noop,process.binding=function(){thrownewError("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){thrownewError("process.chdir is not supported")};
(function(r){functiont(r,t){for(vare=0,n=r.length-1;n>=0;n--){varo=r[n];"."===o?r.splice(n,1):".."===o?(r.splice(n,1),e++):e&&(r.splice(n,1),e--)}if(t)for(;e--;e)r.unshift("..");returnr}functione(r,t){if(r.filter)returnr.filter(t);for(vare=[],n=0;n<r.length;n++)t(r[n],n,r)&&e.push(r[n]);returne}varn=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,o=function(r){returnn.exec(r).slice(1)};exports.resolve=function(){for(varn="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){vari=s>=0?arguments[s]:r.cwd();if("string"!=typeofi)thrownewTypeError("Arguments to path.resolve must be strings");i&&(n=i+"/"+n,o="/"===i.charAt(0))}returnn=t(e(n.split("/"),function(r){return!!r}),!o).join("/"),(o?"/":"")+n||"."},exports.normalize=function(r){varn=exports.isAbsolute(r),o="/"===s(r,-1);returnr=t(e(r.split("/"),function(r){return!!r}),!n).join("/"),r||n||(r="."),r&&o&&(r+="/"),(n?"/":"")+r},exports.isAbsolute=function(r){return"/"===r.charAt(0)},exports.join=function(){varr=Array.prototype.slice.call(arguments,0);returnexports.normalize(e(r,function(r){if("string"!=typeofr)thrownewTypeError("Arguments to path.join must be strings");returnr}).join("/"))},exports.relative=function(r,t){functione(r){for(vart=0;t<r.length&&""===r[t];t++);for(vare=r.length-1;e>=0&&""===r[e];e--);returnt>e?[]:r.slice(t,e-t+1)}r=exports.resolve(r).substr(1),t=exports.resolve(t).substr(1);for(varn=e(r.split("/")),o=e(t.split("/")),s=Math.min(n.length,o.length),i=s,u=0;s>u;u++)if(n[u]!==o[u]){i=u;break}for(varl=[],u=i;u<n.length;u++)l.push("..");returnl=l.concat(o.slice(i)),l.join("/")},exports.sep="/",exports.delimiter=":",exports.dirname=function(r){vart=o(r),e=t[0],n=t[1];returne||n?(n&&(n=n.substr(0,n.length-1)),e+n):"."},exports.basename=function(r,t){vare=o(r)[2];returnt&&e.substr(-1*t.length)===t&&(e=e.substr(0,e.length-t.length)),e},exports.extname=function(r){returno(r)[3]};vars="b"==="ab".substr(-1)?function(r,t,e){returnr.substr(t,e)}:function(r,t,e){return0>t&&(t=r.length+t),r.substr(t,e)}}).call(this,require("/home/maraoz/git/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"));
varprocess=module.exports={};process.nextTick=function(){vare="undefined"!=typeofwindow&&window.setImmediate,n="undefined"!=typeofwindow&&window.postMessage&&window.addEventListener;if(e)returnfunction(e){returnwindow.setImmediate(e)};if(n){varo=[];returnwindow.addEventListener("message",function(e){varn=e.source;if((n===window||null===n)&&"process-tick"===e.data&&(e.stopPropagation(),o.length>0)){varr=o.shift();r()}},!0),function(e){o.push(e),window.postMessage("process-tick","*")}}returnfunction(e){setTimeout(e,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.binding=function(){thrownewError("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){thrownewError("process.chdir is not supported")};
(function(e){functiont(e){e=e||{};vart=e.highWaterMark;this.highWaterMark=t||0===t?t:16384,this.highWaterMark=~~this.highWaterMark,this.buffer=[],this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=!1,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.calledRead=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.objectMode=!!e.objectMode,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(_||(_=require("string_decoder").StringDecoder),this.decoder=new_(e.encoding),this.encoding=e.encoding)}functionn(e){returnthisinstanceofn?(this._readableState=newt(e,this),this.readable=!0,voidS.call(this)):newn(e)}functionr(e,t,n,r,a){varo=d(t,n);if(o)e.emit("error",o);elseif(null===n||void0===n)t.reading=!1,t.ended||s(e,t);elseif(t.objectMode||n&&n.length>0)if(t.ended&&!a){varu=newError("stream.push() after EOF");e.emit("error",u)}elseif(t.endEmitted&&a){varu=newError("stream.unshift() after end event");e.emit("error",u)}else!t.decoder||a||r||(n=t.decoder.write(n)),t.length+=t.objectMode?1:n.length,a?t.buffer.unshift(n):(t.reading=!1,t.buffer.push(n)),t.needReadable&&l(e),h(e,t);elsea||(t.reading=!1);returni(t)}functioni(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||0===e.length)}functiona(e){if(e>=L)e=L;else{e--;for(vart=1;32>t;t<<=1)e|=e>>t;e++}returne}functiono(e,t){return0===t.length&&t.ended?0:t.objectMode?0===e?0:1:isNaN(e)||null===e?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:0>=e?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}functiond(e,t){varn=null;returnR.isBuffer(t)||"string"==typeoft||null===t||void0===t||e.objectMode||n||(n=newTypeError("Invalid non-string/buffer chunk")),n}functions(e,t){if(t.decoder&&!t.ended){varn=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.length>0?l(e):v(e)}functionl(e){vart=e._readableState;t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,t.sync?E(function(){u(e)}):u(e))}functionu(e){e.emit("readable")}functionh(e,t){t.readingMore||(t.readingMore=!0,E(function(){f(e,t)}))}functionf(e,t){for(varn=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(e.read(0),n!==t.length);)n=t.length;t.readingMore=!1}functionp(e){returnfunction(){vart=e._readableState;t.awaitDrain--,0===t.awaitDrain&&c(e)}}functionc(e){functiont(e){vart=e.write(n);!1===t&&r.awaitDrain++}varn,r=e._readableState;for(r.awaitDrain=0;r.pipesCount&&null!==(n=e.read());)if(1===r.pipesCount?t(r.pipes,0,null):w(r.pipes,t),e.emit("data",n),r.awaitDrain>0)return;return0===r.pipesCount?(r.flowing=!1,void(M.listenerCount(e,"data")>0&&b(e))):void(r.ranOut=!0)}functiong(){this._readableState.ranOut&&(this._readableState.ranOut=!1,c(this))}functionb(e,t){varn=e._readableState;if(n.flowing)thrownewError("Cannot switch to old mode now.");varr=t||!1,i=!1;e.readable=!0,e.pipe=S.prototype.pipe,e.on=e.addListener=S.prototype.on,e.on("readable",function(){i=!0;for(vart;!r&&null!==(t=e.read());)e.emit("data",t);null===t&&(i=!1,e._readableState.needReadable=!0)}),e.pause=function(){r=!0,this.emit("pause")},e.resume=function(){r=!1,i?E(function(){e.emit("readable")}):this.read(0),this.emit("resume")},e.emit("readable")}functionm(e,t){varn,r=t.buffer,i=t.length,a=!!t.decoder,o=!!t.objectMode;if(0===r.length)returnnull;if(0===i)n=null;elseif(o)n=r.shift();elseif(!e||e>=i)n=a?r.join(""):R.concat(r,i),r.length=0;elseif(e<r[0].length){vard=r[0];n=d.slice(0,e),r[0]=d.slice(e)}elseif(e===r[0].length)n=r.shift();else{n=a?"":newR(e);for(vars=0,l=0,u=r.length;u>l&&e>s;l++){vard=r[0],h=Math.min(e-s,d.length);a?n+=d.slice(0,h):d.copy(n,s,0,h),h<d.length?r[0]=d.slice(h):r.shift(),s+=h}}returnn}functionv(e){vart=e._readableState;if(t.length>0)thrownewError("endReadable called on non-empty stream");!t.endEmitted&&t.calledRead&&(t.ended=!0,E(function(){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.r
functionTransformState(r,t){this.afterTransform=function(r,n){returnafterTransform(t,r,n)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}functionafterTransform(r,t,n){vare=r._transformState;e.transforming=!1;vara=e.writecb;if(!a)returnr.emit("error",newError("no writecb in Transform class"));e.writechunk=null,e.writecb=null,null!==n&&void0!==n&&r.push(n),a&&a(t);vari=r._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&r._read(i.highWaterMark)}functionTransform(r){if(!(thisinstanceofTransform))returnnewTransform(r);Duplex.call(this,r);vart=(this._transformState=newTransformState(r,this),this);this._readableState.needReadable=!0,this._readableState.sync=!1,this.once("finish",function(){"function"==typeofthis._flush?this._flush(function(r){done(t,r)}):done(t)})}functiondone(r,t){if(t)returnr.emit("error",t);varn=r._writableState,e=(r._readableState,r._transformState);if(n.length)thrownewError("calling transform done when ws.length != 0");if(e.transforming)thrownewError("calling transform done when still transforming");returnr.push(null)}module.exports=Transform;varDuplex=require("./duplex.js"),inherits=require("inherits");inherits(Transform,Duplex),Transform.prototype.push=function(r,t){returnthis._transformState.needTransform=!1,Duplex.prototype.push.call(this,r,t)},Transform.prototype._transform=function(){thrownewError("not implemented")},Transform.prototype._write=function(r,t,n){vare=this._transformState;if(e.writecb=n,e.writechunk=r,e.writeencoding=t,!e.transforming){vara=this._readableState;(e.needTransform||a.needReadable||a.length<a.highWaterMark)&&this._read(a.highWaterMark)}},Transform.prototype._read=function(){varr=this._transformState;r.writechunk&&r.writecb&&!r.transforming?(r.transforming=!0,this._transform(r.writechunk,r.writeencoding,r.afterTransform)):r.needTransform=!0};
functionWriteReq(e,t,r){this.chunk=e,this.encoding=t,this.callback=r}functionWritableState(e,t){e=e||{};varr=e.highWaterMark;this.highWaterMark=r||0===r?r:16384,this.objectMode=!!e.objectMode,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;vari=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){onwrite(t,e)},this.writecb=null,this.writelen=0,this.buffer=[]}functionWritable(e){returnthisinstanceofWritable||thisinstanceofStream.Duplex?(this._writableState=newWritableState(e,this),this.writable=!0,voidStream.call(this)):newWritable(e)}functionwriteAfterEnd(e,t,r){vari=newError("write after end");e.emit("error",i),setImmediate(function(){r(i)})}functionvalidChunk(e,t,r,i){varn=!0;if(!Buffer.isBuffer(r)&&"string"!=typeofr&&null!==r&&void0!==r&&!t.objectMode){varf=newTypeError("Invalid non-string/buffer chunk");e.emit("error",f),setImmediate(function(){i(f)}),n=!1}returnn}functiondecodeChunk(e,t,r){returne.objectMode||e.decodeStrings===!1||"string"!=typeoft||(t=newBuffer(t,r)),t}functionwriteOrBuffer(e,t,r,i,n){r=decodeChunk(t,r,i);varf=t.objectMode?1:r.length;t.length+=f;varo=t.length<t.highWaterMark;returnt.needDrain=!o,t.writing?t.buffer.push(newWriteReq(r,i,n)):doWrite(e,t,f,r,i,n),o}functiondoWrite(e,t,r,i,n,f){t.writelen=r,t.writecb=f,t.writing=!0,t.sync=!0,e._write(i,n,t.onwrite),t.sync=!1}functiononwriteError(e,t,r,i,n){r?setImmediate(function(){n(i)}):n(i),e.emit("error",i)}functiononwriteStateUpdate(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}functiononwrite(e,t){varr=e._writableState,i=r.sync,n=r.writecb;if(onwriteStateUpdate(r),t)onwriteError(e,r,i,t,n);else{varf=needFinish(e,r);f||r.bufferProcessing||!r.buffer.length||clearBuffer(e,r),i?setImmediate(function(){afterWrite(e,r,f,n)}):afterWrite(e,r,f,n)}}functionafterWrite(e,t,r,i){r||onwriteDrain(e,t),i(),r&&finishMaybe(e,t)}functiononwriteDrain(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}functionclearBuffer(e,t){t.bufferProcessing=!0;for(varr=0;r<t.buffer.length;r++){vari=t.buffer[r],n=i.chunk,f=i.encoding,o=i.callback,a=t.objectMode?1:n.length;if(doWrite(e,t,a,n,f,o),t.writing){r++;break}}t.bufferProcessing=!1,r<t.buffer.length?t.buffer=t.buffer.slice(r):t.buffer.length=0}functionneedFinish(e,t){returnt.ending&&0===t.length&&!t.finished&&!t.writing}functionfinishMaybe(e,t){varr=needFinish(e,t);returnr&&(t.finished=!0,e.emit("finish")),r}functionendWritable(e,t,r){t.ending=!0,finishMaybe(e,t),r&&(t.finished?setImmediate(r):e.once("finish",r)),t.ended=!0}module.exports=Writable,Writable.WritableState=WritableState;varisUint8Array="undefined"!=typeofUint8Array?function(e){returneinstanceofUint8Array}:function(e){returne&&e.constructor&&"Uint8Array"===e.constructor.name},isArrayBuffer="undefined"!=typeofArrayBuffer?function(e){returneinstanceofArrayBuffer}:function(e){returne&&e.constructor&&"ArrayBuffer"===e.constructor.name},inherits=require("inherits"),Stream=require("./index.js"),setImmediate=require("process/browser.js").nextTick,Buffer=require("buffer").Buffer;inherits(Writable,Stream),Writable.prototype.pipe=function(){this.emit("error",newError("Cannot pipe. Not readable."))},Writable.prototype.write=function(e,t,r){vari=this._writableState,n=!1;return"function"==typeoft&&(r=t,t=null),!Buffer.isBuffer(e)&&isUint8Array(e)&&(e=newBuffer(e)),isArrayBuffer(e)&&"undefined"!=typeofUint8Array&&(e=newBuffer(newUint8Array(e))),Buffer.isBuffer(e)?t="buffer":t||(t=i.defaultEncoding),"function"!=typeofr&&(r=function(){}),i.ended?writeAfterEnd(this,i,r):validChunk(this,i,e,r)&&(n=writeOrBuffer(this,i,e,t,r)),n},Writable.prototype._write=function(e,t,r){r(newError("not implemented"))},Writable.prototype.end=function(e,t,r){vari=this._writableState;"function"==typeofe?(r=e,e=null,t=null):"function"==typeoft&&(r=t,t=null),"undefined"!=typeofe&&null!==e&&this.write(e,t),i.endin
!function(){"use strict";functiont(t,h,a){if(t&&"object"==typeoft&&t.href)returnt;if("string"!=typeoft)thrownewTypeError("Parameter 'url' must be a string, not "+typeoft);varn={},p=t;p=p.trim();vari=r.exec(p);if(i){i=i[0];varq=i.toLowerCase();n.protocol=q,p=p.substr(i.length)}if(a||i||p.match(/^\/\/[^@\/]+@[^@\/]+/)){varj="//"===p.substr(0,2);!j||i&&g[i]||(p=p.substr(2),n.slashes=!0)}if(!g[i]&&(j||i&&!y[i])){varx=p.indexOf("@");if(-1!==x){for(varA=p.slice(0,x),O=!0,z=0,C=m.length;C>z;z++)if(-1!==A.indexOf(m[z])){O=!1;break}O&&(n.auth=decodeURIComponent(A),p=p.substr(x+1))}for(varZ=-1,z=0,C=f.length;C>z;z++){vark=p.indexOf(f[z]);-1!==k&&(0>Z||Z>k)&&(Z=k)}-1!==Z?(n.host=p.substr(0,Z),p=p.substr(Z)):(n.host=p,p="");for(varw=s(n.host),I=Object.keys(w),z=0,C=I.length;C>z;z++){varR=I[z];n[R]=w[R]}n.hostname=n.hostname||"";varU="["===n.hostname[0]&&"]"===n.hostname[n.hostname.length-1];if(n.hostname.length>l)n.hostname="";elseif(!U)for(var$=n.hostname.split(/\./),z=0,C=$.length;C>z;z++){var_=$[z];if(_&&!_.match(u)){for(varL="",E=0,P=_.length;P>E;E++)L+=_.charCodeAt(E)>127?"x":_[E];if(!L.match(u)){varT=$.slice(0,z),B=$.slice(z+1),D=_.match(v);D&&(T.push(D[1]),B.unshift(D[2])),B.length&&(p="/"+B.join(".")+p),n.hostname=T.join(".");break}}}if(n.hostname=n.hostname.toLowerCase(),!U){for(varF=n.hostname.split("."),G=[],z=0;z<F.length;++z){varH=F[z];G.push(H.match(/[^A-Za-z0-9_-]/)?"xn--"+o.encode(H):H)}n.hostname=G.join(".")}n.host=(n.hostname||"")+(n.port?":"+n.port:""),n.href+=n.host,U&&(n.hostname=n.hostname.substr(1,n.hostname.length-2),"/"!==p[0]&&(p="/"+p))}if(!d[q])for(varz=0,C=c.length;C>z;z++){varJ=c[z],K=encodeURIComponent(J);K===J&&(K=escape(J)),p=p.split(J).join(K)}varM=p.indexOf("#");-1!==M&&(n.hash=p.substr(M),p=p.slice(0,M));varN=p.indexOf("?");return-1!==N?(n.search=p.substr(N),n.query=p.substr(N+1),h&&(n.query=b.parse(n.query)),p=p.slice(0,N)):h&&(n.search="",n.query={}),p&&(n.pathname=p),y[i]&&n.hostname&&!n.pathname&&(n.pathname="/"),(n.pathname||n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=e(n),n}functione(e){"string"==typeofe&&(e=t(e));varh=e.auth||"";h&&(h=encodeURIComponent(h),h=h.replace(/%3A/i,":"),h+="@");vara=e.protocol||"",s=e.pathname||"",o=e.hash||"",r=!1,n="";void0!==e.host?r=h+e.host:void0!==e.hostname&&(r=h+(-1===e.hostname.indexOf(":")?e.hostname:"["+e.hostname+"]"),e.port&&(r+=":"+e.port)),e.query&&"object"==typeofe.query&&Object.keys(e.query).length&&(n=b.stringify(e.query));varp=e.search||n&&"?"+n||"";returna&&":"!==a.substr(-1)&&(a+=":"),e.slashes||(!a||y[a])&&r!==!1?(r="//"+(r||""),s&&"/"!==s.charAt(0)&&(s="/"+s)):r||(r=""),o&&"#"!==o.charAt(0)&&(o="#"+o),p&&"?"!==p.charAt(0)&&(p="?"+p),a+r+s+p+o}functionh(t,h){returne(a(t,h))}functiona(h,a){if(!h)returna;if(h=t(e(h),!1,!0),a=t(e(a),!1,!0),h.hash=a.hash,""===a.href)returnh.href=e(h),h;if(a.slashes&&!a.protocol)returna.protocol=h.protocol,y[a.protocol]&&a.hostname&&!a.pathname&&(a.path=a.pathname="/"),a.href=e(a),a;if(a.protocol&&a.protocol!==h.protocol){if(!y[a.protocol])returna.href=e(a),a;if(h.protocol=a.protocol,!a.host&&!g[a.protocol]){for(vars=(a.pathname||"").split("/");s.length&&!(a.host=s.shift()););a.host||(a.host=""),a.hostname||(a.hostname=""),""!==s[0]&&s.unshift(""),s.length<2&&s.unshift(""),a.pathname=s.join("/")}returnh.pathname=a.pathname,h.search=a.search,h.query=a.query,h.host=a.host||"",h.auth=a.auth,h.hostname=a.hostname||a.host,h.port=a.port,(void0!==h.pathname||void0!==h.search)&&(h.path=(h.pathname?h.pathname:"")+(h.search?h.search:"")),h.slashes=h.slashes||a.slashes,h.href=e(h),h}varo=h.pathname&&"/"===h.pathname.charAt(0),r=void0!==a.host||a.pathname&&"/"===a.pathname.charAt(0),n=r||o||h.host&&a.pathname,p=n,i=h.pathname&&h.pathname.split("/")||[],s=a.pathname&&a.pathname.split("/")||[],c=h.protocol&&!y[h.protocol];if(c&&(deleteh.hostname,deleteh.port,h.host&&(""===i[0]?i[0]=h.host:i.unshift(h.host)),deleteh.host,a.protocol&&(deletea.hostname,deletea.port,a.host&&(""===s[0]?s[0]=a.host:s.unshift(a.host)),deletea.host),n=n&&(""===s[
(function(t){functione(t){returnthisinstanceofe?(this.buffers=t||[],void(this.length=this.buffers.reduce(function(t,e){returnt+e.length},0))):newe(t)}module.exports=e,e.prototype.push=function(){for(vare=0;e<arguments.length;e++)if(!t.isBuffer(arguments[e]))thrownewTypeError("Tried to push a non-buffer");for(vare=0;e<arguments.length;e++){varr=arguments[e];this.buffers.push(r),this.length+=r.length}returnthis.length},e.prototype.unshift=function(){for(vare=0;e<arguments.length;e++)if(!t.isBuffer(arguments[e]))thrownewTypeError("Tried to unshift a non-buffer");for(vare=0;e<arguments.length;e++){varr=arguments[e];this.buffers.unshift(r),this.length+=r.length}returnthis.length},e.prototype.copy=function(t,e,r,n){returnthis.slice(r,n).copy(t,e,0,n-r)},e.prototype.splice=function(r,n){vars=this.buffers,i=r>=0?r:this.length-r,h=[].slice.call(arguments,2);void0===n?n=this.length-i:n>this.length-i&&(n=this.length-i);for(varr=0;r<h.length;r++)this.length+=h[r].length;for(varf=newe,o=0,l=0;l<s.length&&o+s[l].length<i;l++)o+=s[l].length;if(i-o>0){varu=i-o;if(u+n<s[l].length){f.push(s[l].slice(u,u+n));for(varg=s[l],p=newt(u),r=0;u>r;r++)p[r]=g[r];for(vara=newt(g.length-u-n),r=u+n;r<g.length;r++)a[r-n-u]=g[r];if(h.length>0){varc=h.slice();c.unshift(p),c.push(a),s.splice.apply(s,[l,1].concat(c)),l+=c.length,h=[]}elses.splice(l,1,p,a),l+=2}elsef.push(s[l].slice(u)),s[l]=s[l].slice(0,u),l++}for(h.length>0&&(s.splice.apply(s,[l,0].concat(h)),l+=h.length);f.length<n;){varv=s[l],b=v.length,y=Math.min(b,n-f.length);y===b?(f.push(v),s.splice(l,1)):(f.push(v.slice(0,y)),s[l]=s[l].slice(y))}returnthis.length-=f.length,f},e.prototype.slice=function(e,r){varn=this.buffers;void0===r&&(r=this.length),void0===e&&(e=0),r>this.length&&(r=this.length);for(vars=0,i=0;i<n.length&&s+n[i].length<=e;i++)s+=n[i].length;for(varh=newt(r-e),f=0,o=i;r-e>f&&o<n.length;o++){varl=n[o].length,u=0===f?e-s:0,g=f+l>=r-e?Math.min(u+(r-e)-f,l):l;n[o].copy(h,f,u,g),f+=g-u}returnh},e.prototype.pos=function(t){if(0>t||t>=this.length)thrownewError("oob");for(vare=t,r=0,n=null;;){if(n=this.buffers[r],e<n.length)return{buf:r,offset:e};e-=n.length,r++}},e.prototype.get=function(t){vare=this.pos(t);returnthis.buffers[e.buf].get(e.offset)},e.prototype.set=function(t,e){varr=this.pos(t);returnthis.buffers[r.buf].set(r.offset,e)},e.prototype.indexOf=function(e,r){if("string"==typeofe)e=newt(e);elseif(!(einstanceoft))thrownewError("Invalid type for a search string");if(!e.length)return0;if(!this.length)return-1;varn,s=0,i=0,h=0,f=0;if(r){varo=this.pos(r);s=o.buf,i=o.offset,f=r}for(;;){for(;i>=this.buffers[s].length;)if(i=0,s++,s>=this.buffers.length)return-1;varl=this.buffers[s][i];if(l==e[h]){if(0==h&&(n={i:s,j:i,pos:f}),h++,h==e.length)returnn.pos}else0!=h&&(s=n.i,i=n.j,f=n.pos,h=0);i++,f++}},e.prototype.toBuffer=function(){returnthis.slice()},e.prototype.toString=function(t,e,r){returnthis.slice(e,r).toString(t)}}).call(this,require("buffer").Buffer);
functionEdwardsCurve(t){this.twisted=1!=t.a,this.mOneA=this.twisted&&-1==t.a,this.extended=this.mOneA,Base.call(this,"mont",t),this.a=newbn(t.a,16).mod(this.red.m).toRed(this.red),this.c=newbn(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=newbn(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),assert(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==t.c}functionPoint(t,e,r,i,d){Base.BasePoint.call(this,t,"projective"),null===e&&null===r&&null===i?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=newbn(e,16),this.y=newbn(r,16),this.z=i?newbn(i,16):this.curve.one,this.t=d&&newbn(d,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}varassert=require("assert"),curve=require("../curve"),elliptic=require("../../elliptic"),bn=require("bn.js"),inherits=require("inherits"),Base=curve.base,getNAF=elliptic.utils.getNAF;inherits(EdwardsCurve,Base),module.exports=EdwardsCurve,EdwardsCurve.prototype._mulA=function(t){returnthis.mOneA?t.redNeg():this.a.redMul(t)},EdwardsCurve.prototype._mulC=function(t){returnthis.oneC?t:this.c.redMul(t)},EdwardsCurve.prototype.point=function(t,e,r,i){returnnewPoint(this,t,e,r,i)},EdwardsCurve.prototype.jpoint=function(t,e,r,i){returnthis.point(t,e,r,i)},EdwardsCurve.prototype.pointFromJSON=function(t){returnPoint.fromJSON(this,t)},EdwardsCurve.prototype.pointFromX=function(t,e){e=newbn(e,16),e.red||(e=e.toRed(this.red));varr=e.redSqr(),i=this.c2.redSub(this.a.redMul(r)),d=this.one.redSub(this.c2.redMul(this.d).redMul(r)),s=i.redMul(d.redInvm()).redSqrt(),u=s.fromRed().isOdd();return(t&&!u||!t&&u)&&(s=s.redNeg()),this.point(e,s,curve.one)},EdwardsCurve.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();vare=t.x.redSqr(),r=t.y.redSqr(),i=e.redMul(this.a).redAdd(r),d=this.c2.redMul(this.one.redAdd(this.d.redMul(e).redMul(r)));return0===i.cmp(d)},inherits(Point,Base.BasePoint),Point.fromJSON=function(t,e){returnnewPoint(t,e[0],e[1],e[2])},Point.prototype.inspect=function(){returnthis.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16)+" y: "+this.y.fromRed().toString(16)+" z: "+this.z.fromRed().toString(16)+">"},Point.prototype.isInfinity=function(){return0===this.x.cmpn(0)&&0===this.y.cmp(this.z)},Point.prototype._extDbl=function(){vart=this.x.redSqr(),e=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);vari=this.curve._mulA(t),d=this.x.redAdd(this.y).redSqr().redISub(t).redISub(e),s=i.redAdd(e),u=s.redSub(r),n=i.redSub(e),h=d.redMul(u),o=s.redMul(n),l=d.redMul(n),c=u.redMul(s);returnthis.curve.point(h,o,c,l)},Point.prototype._projDbl=function(){vart=this.x.redAdd(this.y).redSqr(),e=this.x.redSqr(),r=this.y.redSqr();if(this.curve.twisted){vari=this.curve._mulA(e),d=i.redAdd(r);if(this.zOne)vars=t.redSub(e).redSub(r).redMul(d.redSub(this.curve.two)),u=d.redMul(i.redSub(r)),n=d.redSqr().redSub(d).redSub(d);elsevarh=this.z.redSqr(),o=d.redSub(h).redISub(h),s=t.redSub(e).redISub(r).redMul(o),u=d.redMul(i.redSub(r)),n=d.redMul(o)}elsevari=e.redAdd(r),h=this.curve._mulC(redMul(this.z)).redSqr(),o=i.redSub(h).redSub(h),s=this.curve._mulC(t.redISub(i)).redMul(o),u=this.curve._mulC(i).redMul(e.redISub(r)),n=i.redMul(o);returnthis.curve.point(s,u,n)},Point.prototype.dbl=function(){returnthis.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},Point.prototype._extAdd=function(t){vare=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),r=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),i=this.t.redMul(this.curve.dd).redMul(t.t),d=this.z.redMul(t.z.redAdd(t.z)),s=r.redSub(e),u=d.redSub(i),n=d.redAdd(i),h=r.redAdd(e),o=s.redMul(u),l=n.redMul(h),c=s.redMul(h),p=u.redMul(n);returnthis.curve.point(o,l,p,c)},Point.prototype._projAdd=functio
functionMontCurve(t){Base.call(this,"mont",t),this.a=newbn(t.a,16).toRed(this.red),this.b=newbn(t.b,16).toRed(this.red),this.i4=newbn(4).toRed(this.red).redInvm(),this.two=newbn(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}functionPoint(t,e,r){Base.BasePoint.call(this,t,"projective"),null===e&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=newbn(e,16),this.z=newbn(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}varassert=require("assert"),curve=require("../curve"),elliptic=require("../../elliptic"),bn=require("bn.js"),inherits=require("inherits"),Base=curve.base,getNAF=elliptic.utils.getNAF;inherits(MontCurve,Base),module.exports=MontCurve,MontCurve.prototype.point=function(t,e){returnnewPoint(this,t,e)},MontCurve.prototype.pointFromJSON=function(t){returnPoint.fromJSON(this,t)},MontCurve.prototype.validate=function(t){vare=t.normalize().x,r=e.redSqr(),i=r.redMul(e).redAdd(r.redMul(this.a)).redAdd(e),n=i.redSqrt();return0===n.redSqr().cmp(i)},inherits(Point,Base.BasePoint),Point.prototype.precompute=function(){},Point.fromJSON=function(t,e){returnnewPoint(t,e[0],e[1]||t.one)},Point.prototype.inspect=function(){returnthis.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16)+" z: "+this.z.fromRed().toString(16)+">"},Point.prototype.isInfinity=function(){return0===this.z.cmpn(0)},Point.prototype.dbl=function(){vart=this.x.redAdd(this.z),e=t.redSqr(),r=this.x.redSub(this.z),i=r.redSqr(),n=e.redSub(i),o=e.redMul(i),d=n.redMul(i.redAdd(this.curve.a24.redMul(n)));returnthis.curve.point(o,d)},Point.prototype.add=function(){thrownewError("Not supported on Montgomery curve")},Point.prototype.diffAdd=function(t,e){varr=this.x.redAdd(this.z),i=this.x.redSub(this.z),n=t.x.redAdd(t.z),o=t.x.redSub(t.z),d=o.redMul(r),s=n.redMul(i),u=e.z.redMul(d.redAdd(s).redSqr()),h=e.x.redMul(d.redISub(s).redSqr());returnthis.curve.point(u,h)},Point.prototype.mul=function(t){for(vare=t.clone(),r=this,i=this.curve.point(null,null),n=this,o=[];0!==e.cmpn(0);e.ishrn(1))o.push(e.andln(1));for(vard=o.length-1;d>=0;d--)0===o[d]?(r=r.diffAdd(i,n),i=i.dbl()):(i=r.diffAdd(i,n),r=r.dbl());returni},Point.prototype.mulAdd=function(){thrownewError("Not supported on Montgomery curve")},Point.prototype.normalize=function(){returnthis.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},Point.prototype.getX=function(){returnthis.normalize(),this.x.fromRed()};
functionKeyPair(t,i,e){returniinstanceofKeyPair?i:einstanceofKeyPair?e:(i||(i=e,e=null),null!==i&&"object"==typeofi&&(i.x?(e=i,i=null):(i.priv||i.pub)&&(e=i.pub,i=i.priv)),this.ec=t,this.priv=null,this.pub=null,void(this._importPublicHex(i,e)||("hex"===e&&(e=null),i&&this._importPrivate(i),e&&this._importPublic(e))))}varassert=require("assert"),bn=require("bn.js"),elliptic=require("../../elliptic"),utils=elliptic.utils;module.exports=KeyPair,KeyPair.prototype.validate=function(){vart=this.getPublic();returnt.isInfinity()?{result:!1,reason:"Invalid public key"}:t.validate()?t.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},KeyPair.prototype.getPublic=function(t,i){if(this.pub||(this.pub=this.ec.g.mul(this.priv)),"string"==typeoft&&(i=t,t=null),!i)returnthis.pub;for(vare=this.ec.curve.p.byteLength(),r=this.pub.getX().toArray(),n=r.length;e>n;n++)r.unshift(0);if(t)varu=[this.pub.getY().isEven()?2:3].concat(r);else{for(vars=this.pub.getY().toArray(),n=s.length;e>n;n++)s.unshift(0);varu=[4].concat(r,s)}returnutils.encode(u,i)},KeyPair.prototype.getPrivate=function(t){return"hex"===t?this.priv.toString(16):this.priv},KeyPair.prototype._importPrivate=function(t){this.priv=newbn(t,16),this.priv=this.priv.mod(this.ec.curve.n)},KeyPair.prototype._importPublic=function(t){this.pub=this.ec.curve.point(t.x,t.y)},KeyPair.prototype._importPublicHex=function(t,i){t=utils.toArray(t,i);vare=this.ec.curve.p.byteLength();if(4===t[0]&&t.length-1===2*e)this.pub=this.ec.curve.point(t.slice(1,1+e),t.slice(1+e,1+2*e));else{if(2!==t[0]&&3!==t[0]||t.length-1!==e)return!1;this.pub=this.ec.curve.pointFromX(3===t[0],t.slice(1,1+e))}return!0},KeyPair.prototype.derive=function(t){returnt.mul(this.priv).getX()},KeyPair.prototype.sign=function(t){returnthis.ec.sign(t,this)},KeyPair.prototype.verify=function(t,i){returnthis.ec.verify(t,i,this)},KeyPair.prototype.inspect=function(){return"<Key priv: "+(this.priv&&this.priv.toString(16))+" pub: "+(this.pub&&this.pub.inspect())+" >"};
functionSignature(t,r){returntinstanceofSignature?t:void(this._importDER(t,r)||(assert(t&&r,"Signature without r or s"),this.r=newbn(t,16),this.s=newbn(r,16)))}varassert=require("assert"),bn=require("bn.js"),elliptic=require("../../elliptic"),utils=elliptic.utils;module.exports=Signature,Signature.prototype._importDER=function(t,r){if(t=utils.toArray(t,r),t.length<6||48!==t[0]||2!==t[2])return!1;vare=t[1];if(1+e>t.length)return!1;varn=t[3];if(n>=128)return!1;if(4+n+2>=t.length)return!1;if(2!==t[4+n])return!1;vari=t[5+n];returni>=128?!1:4+n+2+i>t.length?!1:(this.r=newbn(t.slice(4,4+n)),this.s=newbn(t.slice(4+n+2,4+n+2+i)),!0)},Signature.prototype.toDER=function(t){varr=this.r.toArray(),e=this.s.toArray();128&r[0]&&(r=[0].concat(r)),128&e[0]&&(e=[0].concat(e));varn=r.length+e.length+4,i=[48,n,2,r.length];returni=i.concat(r,[2,e.length],e),utils.encode(i,t)};
functionHmacDRBG(t){if(!(thisinstanceofHmacDRBG))returnnewHmacDRBG(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this.reseed=null,this.reseedInterval=null,this.K=null,this.V=null;vare=utils.toArray(t.entropy,t.entropyEnc),i=utils.toArray(t.nonce,t.nonceEnc),s=utils.toArray(t.pers,t.persEnc);assert(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,i,s)}varassert=require("assert"),hash=require("hash.js"),elliptic=require("../elliptic"),utils=elliptic.utils;module.exports=HmacDRBG,HmacDRBG.prototype._init=function(t,e,i){vars=t.concat(e).concat(i);this.K=newArray(this.outLen/8),this.V=newArray(this.outLen/8);for(varh=0;h<this.V.length;h++)this.K[h]=0,this.V[h]=1;this._update(s),this.reseed=1,this.reseedInterval=281474976710656},HmacDRBG.prototype._hmac=function(){returnnewhash.hmac(this.hash,this.K)},HmacDRBG.prototype._update=function(t){vare=this._hmac().update(this.V).update([0]);t&&(e=e.update(t)),this.K=e.digest(),this.V=this._hmac().update(this.V).digest(),t&&(this.K=this._hmac().update(this.V).update([1]).update(t).digest(),this.V=this._hmac().update(this.V).digest())},HmacDRBG.prototype.reseed=function(t,e,i,s){"string"!=typeofe&&(s=i,i=e,e=null),t=utils.toBuffer(t,e),i=utils.toBuffer(i,s),assert(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(i||[])),this.reseed=1},HmacDRBG.prototype.generate=function(t,e,i,s){if(this.reseed>this.reseedInterval)thrownewError("Reseed is required");"string"!=typeofe&&(s=i,i=e,e=null),i&&(i=utils.toArray(i,s),this._update(i));for(varh=[];h.length<t;)this.V=this._hmac().update(this.V).digest(),h=h.concat(this.V);varr=h.slice(0,t);returnthis._update(i),this.reseed++,utils.encode(r,e)};
"readme":"# Elliptic [![Build Status](https://secure.travis-ci.org/indutny/elliptic.png)](http://travis-ci.org/indutny/elliptic)\n\nFast elliptic-curve cryptography in a plain javascript implementation.\n\nNOTE: Please take a look at http://safecurves.cr.yp.to/ before choosing a curve\nfor your cryptography operations.\n\n## Incentive\n\nECC is much slower than regular RSA cryptography, the JS implementations are\neven more slower.\n\n## Benchmarks\n\n```bash\n$ node benchmarks/index.js\nBenchmarking: sign\nelliptic#sign x 262 ops/sec ±0.51% (177 runs sampled)\neccjs#sign x 55.91 ops/sec ±0.90% (144 runs sampled)\n------------------------\nFastest is elliptic#sign\n========================\nBenchmarking: verify\nelliptic#verify x 113 ops/sec ±0.50% (166 runs sampled)\neccjs#verify x 48.56 ops/sec ±0.36% (125 runs sampled)\n------------------------\nFastest is elliptic#verify\n========================\nBenchmarking: gen\nelliptic#gen x 294 ops/sec ±0.43% (176 runs sampled)\neccjs#gen x 62.25 ops/sec ±0.63% (129 runs sampled)\n------------------------\nFastest is elliptic#gen\n========================\nBenchmarking: ecdh\nelliptic#ecdh x 136 ops/sec ±0.85% (156 runs sampled)\n------------------------\nFastest is elliptic#ecdh\n========================\n```\n\n## API\n\n### ECDSA\n\n```javascript\nvar EC = require('elliptic').ec;\n\n// Create and initialize EC context\n// (better do it once and reuse it)\nvar ec = new EC('secp256k1');\n\n// Generate keys\nvar key = ec.genKeyPair();\n\n// Sign message (must be an array, or it'll be treated as a hex sequence)\nvar msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];\nvar signature = key.sign(msg);\n\n// Export DER encoded signature in Array\nvar derSign = signature.toDER();\n\n// Verify signature\nconsole.log(key.verify(msg, derSign));\n```\n\n### ECDH\n\n```javascript\n// Generate keys\nvar key1 = ec.genKeyPair();\nvar key2 = ec.genKeyPair();\n\nvar shared1 = key1.derive(key2.getPublic());\nvar shared2 = key2.derive(key1.getPublic());\n\nconsole.log('Both shared secrets are BN instances');\nconsole.log(shared1.toString(16));\nconsole.log(shared2.toString(16));\n```\n\nNOTE: `.derive()` returns a [BN][1] instance.\n\n## Supported curves\n\nElliptic.js support following curve types:\n\n* Short Weierstrass\n* Montgomery\n* Edwards\n* Twisted Edwards\n\nFollowing curve 'presets' are embedded into the library:\n\n* `secp256k1`\n* `p192`\n* `p224`\n* `p256`\n* `curve25519`\n* `ed25519`\n\nNOTE: That `curve25519` could not be used for ECDSA, use `ed25519` instead.\n\n### Implementation details\n\nECDSA is using deterministic `k` value generation as per [RFC6979][0]. Most of\nthe curve operations are performed on non-affine coordinates (either projective\nor extended), various windowing techniques are used for different cases.\n\nAll operations are performed in reduction context using [bn.js][1], hashing is\nprovided by [hash.js][2]\n\n#### LICENSE\n\nThis software is licensed under the MIT License.\n\nCopyright Fedor Indutny, 2014.\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the\nfollowing conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\",WITHOUTWARRANTYOFANYKIND,EXPRESS\nORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF\nMERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.IN\nNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,\nDAMAGESOROTHERLIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOR\nOTHERWISE,ARISINGFROM,OUTOFORINCONNECTIONWITHTHESOFTWAREORTHE\nUSEOROTHERDEALINGSINTHESOFTWARE.\n\n[0]:http://tools.
}function_rsasign_signWithMessageHash(t,e){varr=KJUR.crypto.Util.getPaddedDigestInfoHex(t,e,this.n.bitLength()),i=parseBigInt(r,16),n=this.doPrivate(i),s=n.toString(16);return_zeroPaddingOfSignature(s,this.n.bitLength())}function_rsasign_signStringWithSHA1(t){return_rsasign_signString.call(this,t,"sha1")}function_rsasign_signStringWithSHA256(t){return_rsasign_signString.call(this,t,"sha256")}functionpss_mgf1_str(t,e,r){for(vari="",n=0;i.length<e;)i+=hextorstr(r(rstrtohex(t+String.fromCharCode.apply(String,[(4278190080&n)>>24,(16711680&n)>>16,(65280&n)>>8,255&n])))),n+=1;returni}function_rsasign_signStringPSS(t,e,r){vari=function(t){returnKJUR.crypto.Util.hashHex(t,e)},n=i(rstrtohex(t));returnvoid0===r&&(r=-1),this.signWithMessageHashPSS(n,e,r)}function_rsasign_signWithMessageHashPSS(t,e,r){vari,n=hextorstr(t),s=n.length,o=this.n.bitLength()-1,a=Math.ceil(o/8),h=function(t){returnKJUR.crypto.Util.hashHex(t,e)};if(-1===r||void0===r)r=s;elseif(-2===r)r=a-s-2;elseif(-2>r)throw"invalid salt length";if(s+r+2>a)throw"data too long";varu="";r>0&&(u=newArray(r),(newSecureRandom).nextBytes(u),u=String.fromCharCode.apply(String,u));varc=hextorstr(h(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+n+u))),g=[];for(i=0;a-r-s-2>i;i+=1)g[i]=0;varf=String.fromCharCode.apply(String,g)+""+u,p=pss_mgf1_str(c,f.length,h),l=[];for(i=0;i<f.length;i+=1)l[i]=f.charCodeAt(i)^p.charCodeAt(i);vard=65280>>8*a-o&255;for(l[0]&=~d,i=0;s>i;i++)l.push(c.charCodeAt(i));returnl.push(188),_zeroPaddingOfSignature(this.doPrivate(newBigInteger(l)).toString(16),this.n.bitLength())}function_rsasign_getDecryptSignatureBI(t,e,r){vari=newRSAKey;i.setPublic(e,r);varn=i.doPublic(t);returnn}function_rsasign_getHexDigestInfoFromSig(t,e,r){vari=_rsasign_getDecryptSignatureBI(t,e,r),n=i.toString(16).replace(/^1f+00/,"");returnn}function_rsasign_getAlgNameAndHashFromHexDisgestInfo(t){for(vareinKJUR.crypto.Util.DIGESTINFOHEAD){varr=KJUR.crypto.Util.DIGESTINFOHEAD[e],i=r.length;if(t.substring(0,i)==r){varn=[e,t.substring(i)];returnn}}return[]}function_rsasign_verifySignatureWithArgs(t,e,r,i){varn=_rsasign_getHexDigestInfoFromSig(e,r,i),s=_rsasign_getAlgNameAndHashFromHexDisgestInfo(n);if(0==s.length)return!1;varo=s[0],a=s[1],h=function(t){returnKJUR.crypto.Util.hashString(t,o)},u=h(t);returna==u}function_rsasign_verifyHexSignatureForMessage(t,e){varr=parseBigInt(t,16),i=_rsasign_verifySignatureWithArgs(e,r,this.n.toString(16),this.e.toString(16));returni}function_rsasign_verifyString(t,e){e=e.replace(_RE_HEXDECONLY,""),e=e.replace(/[ \n]+/g,"");varr=parseBigInt(e,16);if(r.bitLength()>this.n.bitLength())return0;vari=this.doPublic(r),n=i.toString(16).replace(/^1f+00/,""),s=_rsasign_getAlgNameAndHashFromHexDisgestInfo(n);if(0==s.length)return!1;varo=s[0],a=s[1],h=function(t){returnKJUR.crypto.Util.hashString(t,o)},u=h(t);returna==u}function_rsasign_verifyWithMessageHash(t,e){e=e.replace(_RE_HEXDECONLY,""),e=e.replace(/[ \n]+/g,"");varr=parseBigInt(e,16);if(r.bitLength()>this.n.bitLength())return0;vari=this.doPublic(r),n=i.toString(16).replace(/^1f+00/,""),s=_rsasign_getAlgNameAndHashFromHexDisgestInfo(n);if(0==s.length)return!1;varo=(s[0],s[1]);returno==t}function_rsasign_verifyStringPSS(t,e,r,i){varn=function(t){returnKJUR.crypto.Util.hashHex(t,r)},s=n(rstrtohex(t));returnvoid0===i&&(i=-1),this.verifyWithMessageHashPSS(s,e,r,i)}function_rsasign_verifyWithMessageHashPSS(t,e,r,i){varn=newBigInteger(e,16);if(n.bitLength()>this.n.bitLength())return!1;vars,o=function(t){returnKJUR.crypto.Util.hashHex(t,r)},a=hextorstr(t),h=a.length,u=this.n.bitLength()-1,c=Math.ceil(u/8);if(-1===i||void0===i)i=h;elseif(-2===i)i=c-h-2;elseif(-2>i)throw"invalid salt length";if(h+i+2>c)throw"data too long";varg=this.doPublic(n).toByteArray();for(s=0;s<g.length;s+=1)g[s]&=255;for(;g.length<c;)g.unshift(0);if(188!==g[c-1])throw"encoded message does not end in 0xbc";g=String.fromCharCode.apply(String,g);varf=g.substr(0,c-h-1),p=g.substr(f.length,h),l=65280>>8*c-u&255;if(0!==(f.charCodeAt(0)&l))throw"bitsbeyondkeysizenotzer
},"undefined"!=typeoft&&("string"==typeoft&&t.toLowerCase().match(/^[0-9a-f]+$/)?this.setHexValueIncludingUnusedBits(t):"undefined"!=typeoft.hex?this.setHexValueIncludingUnusedBits(t.hex):"undefined"!=typeoft.bin?this.setByBinaryString(t.bin):"undefined"!=typeoft.array&&this.setByBooleanArray(t.array))},YAHOO.lang.extend(KJUR.asn1.DERBitString,KJUR.asn1.ASN1Object),KJUR.asn1.DEROctetString=function(t){KJUR.asn1.DEROctetString.superclass.constructor.call(this,t),this.hT="04"},YAHOO.lang.extend(KJUR.asn1.DEROctetString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNull=function(){KJUR.asn1.DERNull.superclass.constructor.call(this),this.hT="05",this.hTLV="0500"},YAHOO.lang.extend(KJUR.asn1.DERNull,KJUR.asn1.ASN1Object),KJUR.asn1.DERObjectIdentifier=function(t){vare=function(t){vare=t.toString(16);return1==e.length&&(e="0"+e),e},r=function(t){varr="",i=newBigInteger(t,10),n=i.toString(2),s=7-n.length%7;7==s&&(s=0);for(varo="",a=0;s>a;a++)o+="0";n=o+n;for(vara=0;a<n.length-1;a+=7){varh=n.substr(a,7);a!=n.length-7&&(h="1"+h),r+=e(parseInt(h,2))}returnr};KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this),this.hT="06",this.setValueHex=function(t){this.hTLV=null,this.isModified=!0,this.s=null,this.hV=t},this.setValueOidString=function(t){if(!t.match(/^[0-9.]+$/))throw"malformed oid string: "+t;vari="",n=t.split("."),s=40*parseInt(n[0])+parseInt(n[1]);i+=e(s),n.splice(0,2);for(varo=0;o<n.length;o++)i+=r(n[o]);this.hTLV=null,this.isModified=!0,this.s=null,this.hV=i},this.setValueName=function(t){if("undefined"==typeofKJUR.asn1.x509.OID.name2oidList[t])throw"DERObjectIdentifier oidName undefined: "+t;vare=KJUR.asn1.x509.OID.name2oidList[t];this.setValueOidString(e)},this.getFreshValueHex=function(){returnthis.hV},"undefined"!=typeoft&&("string"==typeoft&&t.match(/^[0-2].[0-9.]+$/)?this.setValueOidString(t):void0!==KJUR.asn1.x509.OID.name2oidList[t]?this.setValueOidString(KJUR.asn1.x509.OID.name2oidList[t]):"undefined"!=typeoft.oid?this.setValueOidString(t.oid):"undefined"!=typeoft.hex?this.setValueHex(t.hex):"undefined"!=typeoft.name&&this.setValueName(t.name))},YAHOO.lang.extend(KJUR.asn1.DERObjectIdentifier,KJUR.asn1.ASN1Object),KJUR.asn1.DERUTF8String=function(t){KJUR.asn1.DERUTF8String.superclass.constructor.call(this,t),this.hT="0c"},YAHOO.lang.extend(KJUR.asn1.DERUTF8String,KJUR.asn1.DERAbstractString),KJUR.asn1.DERNumericString=function(t){KJUR.asn1.DERNumericString.superclass.constructor.call(this,t),this.hT="12"},YAHOO.lang.extend(KJUR.asn1.DERNumericString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERPrintableString=function(t){KJUR.asn1.DERPrintableString.superclass.constructor.call(this,t),this.hT="13"},YAHOO.lang.extend(KJUR.asn1.DERPrintableString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERTeletexString=function(t){KJUR.asn1.DERTeletexString.superclass.constructor.call(this,t),this.hT="14"},YAHOO.lang.extend(KJUR.asn1.DERTeletexString,KJUR.asn1.DERAbstractString),KJUR.asn1.DERIA5String=function(t){KJUR.asn1.DERIA5String.superclass.constructor.call(this,t),this.hT="16"},YAHOO.lang.extend(KJUR.asn1.DERIA5String,KJUR.asn1.DERAbstractString),KJUR.asn1.DERUTCTime=function(t){KJUR.asn1.DERUTCTime.superclass.constructor.call(this,t),this.hT="17",this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"utc"),this.hV=stohex(this.s)},"undefined"!=typeoft&&("undefined"!=typeoft.str?this.setString(t.str):"string"==typeoft&&t.match(/^[0-9]{12}Z$/)?this.setString(t):"undefined"!=typeoft.hex?this.setStringHex(t.hex):"undefined"!=typeoft.date&&this.setByDate(t.date))},YAHOO.lang.extend(KJUR.asn1.DERUTCTime,KJUR.asn1.DERAbstractTime),KJUR.asn1.DERGeneralizedTime=function(t){KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this,t),this.hT="18",this.setByDate=function(t){this.hTLV=null,this.isModified=!0,this.date=t,this.s=this.formatDate(this.date,"gen"),this.hV=stohex(this.s)},"undefined"!=typeoft&&("undefined"!=typeoft.str?this.setString(t.str):"string"==typeoft&&t.match(/^[0-9]{14}Z$/)?this.setString(t):"undefined"!=typeoft.hex?this.setS
returnthis.DIGESTINFOHEAD[e]+t},this.getPaddedDigestInfoHex=function(t,e,r){vari=this.getDigestInfoHex(t,e),n=r/4;if(i.length+22>n)throw"key is too short for SigAlg: keylen="+r+","+e;for(vars="0001",o="00"+i,a="",h=n-s.length-o.length,u=0;h>u;u+=2)a+="ff";varc=s+a+o;returnc},this.hashString=function(t,e){varr=newKJUR.crypto.MessageDigest({alg:e});returnr.digestString(t)},this.hashHex=function(t,e){varr=newKJUR.crypto.MessageDigest({alg:e});returnr.digestHex(t)},this.sha1=function(t){vare=newKJUR.crypto.MessageDigest({alg:"sha1",prov:"cryptojs"});returne.digestString(t)},this.sha256=function(t){vare=newKJUR.crypto.MessageDigest({alg:"sha256",prov:"cryptojs"});returne.digestString(t)},this.sha256Hex=function(t){vare=newKJUR.crypto.MessageDigest({alg:"sha256",prov:"cryptojs"});returne.digestHex(t)},this.sha512=function(t){vare=newKJUR.crypto.MessageDigest({alg:"sha512",prov:"cryptojs"});returne.digestString(t)},this.sha512Hex=function(t){vare=newKJUR.crypto.MessageDigest({alg:"sha512",prov:"cryptojs"});returne.digestHex(t)},this.md5=function(t){vare=newKJUR.crypto.MessageDigest({alg:"md5",prov:"cryptojs"});returne.digestString(t)},this.ripemd160=function(t){vare=newKJUR.crypto.MessageDigest({alg:"ripemd160",prov:"cryptojs"});returne.digestString(t)},this.getCryptoJSMDByName=function(){}},KJUR.crypto.MessageDigest=function(params){varmd=null,algName=null,provName=null;this.setAlgAndProvider=function(alg,prov){if(null!=alg&&void0===prov&&(prov=KJUR.crypto.Util.DEFAULTPROVIDER[alg]),-1!=":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(alg)&&"cryptojs"==prov){try{this.md=eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[alg]).create()}catch(ex){throw"setAlgAndProvider hash alg set fail alg="+alg+"/"+ex}this.updateString=function(t){this.md.update(t)},this.updateHex=function(t){vare=CryptoJS.enc.Hex.parse(t);this.md.update(e)},this.digest=function(){vart=this.md.finalize();returnt.toString(CryptoJS.enc.Hex)},this.digestString=function(t){returnthis.updateString(t),this.digest()},this.digestHex=function(t){returnthis.updateHex(t),this.digest()}}if(-1!=":sha256:".indexOf(alg)&&"sjcl"==prov){try{this.md=newsjcl.hash.sha256}catch(ex){throw"setAlgAndProvider hash alg set fail alg="+alg+"/"+ex}this.updateString=function(t){this.md.update(t)},this.updateHex=function(t){vare=sjcl.codec.hex.toBits(t);this.md.update(e)},this.digest=function(){vart=this.md.finalize();returnsjcl.codec.hex.fromBits(t)},this.digestString=function(t){returnthis.updateString(t),this.digest()},this.digestHex=function(t){returnthis.updateHex(t),this.digest()}}},this.updateString=function(){throw"updateString(str) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.updateHex=function(){throw"updateHex(hex) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digest=function(){throw"digest() not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digestString=function(){throw"digestString(str) not supported for this alg/prov: "+this.algName+"/"+this.provName},this.digestHex=function(){throw"digestHex(hex) not supported for this alg/prov: "+this.algName+"/"+this.provName},void0!==params&&void0!==params.alg&&(this.algName=params.alg,void0===params.prov&&(this.provName=KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]),this.setAlgAndProvider(this.algName,this.provName))},KJUR.crypto.Mac=function(params){varmac=null,pass=null,algName=null,provName=null,algProv=null;this.setAlgAndProvider=function(alg,prov){if(null==alg&&(alg="hmacsha1"),alg=alg.toLowerCase(),"hmac"!=alg.substr(0,4))throw"setAlgAndProvider unsupported HMAC alg: "+alg;void0===prov&&(prov=KJUR.crypto.Util.DEFAULTPROVIDER[alg]),this.algProv=alg+"/"+prov;varhashAlg=alg.substr(4);if(-1!=":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(hashAlg)&&"cryptojs"==prov){try{varmdObj=eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[hashAlg]);this.mac=CryptoJS.algo.HMAC.create(mdObj,this.pass)}catch(ex){throw"setAlgAndProvider hash alg set fail hashAlg="+hashAlg+"/"+ex}this.updateString=function(t)
},getKeyFromPlainPrivatePKCS8PEM:function(t){vare=this.getHexFromPEM(t,"PRIVATE KEY"),r=this.getKeyFromPlainPrivatePKCS8Hex(e);returnr},getKeyFromPlainPrivatePKCS8Hex:function(t){vare=this.parsePlainPrivatePKCS8Hex(t);if("2a864886f70d010101"==e.algoid){this.parsePrivateRawRSAKeyHexAtObj(t,e);varr=e.key,i=newRSAKey;returni.setPrivateEx(r.n,r.e,r.d,r.p,r.q,r.dp,r.dq,r.co),i}if("2a8648ce3d0201"==e.algoid){if(this.parsePrivateRawECKeyHexAtObj(t,e),void0===KJUR.crypto.OID.oidhex2name[e.algparam])throw"KJUR.crypto.OID.oidhex2name undefined: "+e.algparam;varn=KJUR.crypto.OID.oidhex2name[e.algparam],i=newKJUR.crypto.ECDSA({curve:n,prv:e.key});returni}throw"unsupported private key algorithm"},getRSAKeyFromPublicPKCS8PEM:function(t){vare=this.getHexFromPEM(t,"PUBLIC KEY"),r=this.getRSAKeyFromPublicPKCS8Hex(e);returnr},getKeyFromPublicPKCS8PEM:function(t){vare=this.getHexFromPEM(t,"PUBLIC KEY"),r=this.getKeyFromPublicPKCS8Hex(e);returnr},getKeyFromPublicPKCS8Hex:function(t){vare=this.parsePublicPKCS8Hex(t);if("2a864886f70d010101"==e.algoid){varr=this.parsePublicRawRSAKeyHex(e.key),i=newRSAKey;returni.setPublic(r.n,r.e),i}if("2a8648ce3d0201"==e.algoid){if(void0===KJUR.crypto.OID.oidhex2name[e.algparam])throw"KJUR.crypto.OID.oidhex2name undefined: "+e.algparam;varn=KJUR.crypto.OID.oidhex2name[e.algparam],i=newKJUR.crypto.ECDSA({curve:n,pub:e.key});returni}throw"unsupported public key algorithm"},parsePublicRawRSAKeyHex:function(t){vare={};if("30"!=t.substr(0,2))throw"malformed RSA key(code:001)";varr=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(2!=r.length)throw"malformed RSA key(code:002)";if("02"!=t.substr(r[0],2))throw"malformed RSA key(code:003)";if(e.n=ASN1HEX.getHexOfV_AtObj(t,r[0]),"02"!=t.substr(r[1],2))throw"malformed RSA key(code:004)";returne.e=ASN1HEX.getHexOfV_AtObj(t,r[1]),e},parsePrivateRawRSAKeyHexAtObj:function(t,e){varr=e.keyidx;if("30"!=t.substr(r,2))throw"malformed RSA private key(code:001)";vari=ASN1HEX.getPosArrayOfChildren_AtObj(t,r);if(9!=i.length)throw"malformed RSA private key(code:002)";e.key={},e.key.n=ASN1HEX.getHexOfV_AtObj(t,i[1]),e.key.e=ASN1HEX.getHexOfV_AtObj(t,i[2]),e.key.d=ASN1HEX.getHexOfV_AtObj(t,i[3]),e.key.p=ASN1HEX.getHexOfV_AtObj(t,i[4]),e.key.q=ASN1HEX.getHexOfV_AtObj(t,i[5]),e.key.dp=ASN1HEX.getHexOfV_AtObj(t,i[6]),e.key.dq=ASN1HEX.getHexOfV_AtObj(t,i[7]),e.key.co=ASN1HEX.getHexOfV_AtObj(t,i[8])},parsePrivateRawECKeyHexAtObj:function(t,e){varr=e.keyidx;if("30"!=t.substr(r,2))throw"malformed ECC private key(code:001)";vari=ASN1HEX.getPosArrayOfChildren_AtObj(t,r);if(3!=i.length)throw"malformed ECC private key(code:002)";if("04"!=t.substr(i[1],2))throw"malformed ECC private key(code:003)";e.key=ASN1HEX.getHexOfV_AtObj(t,i[1])},parsePublicPKCS8Hex:function(t){vare={};e.algparam=null;varr=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(2!=r.length)throw"outer DERSequence shall have 2 elements: "+r.length;vari=r[0];if("30"!=t.substr(i,2))throw"malformed PKCS8 public key(code:001)";varn=ASN1HEX.getPosArrayOfChildren_AtObj(t,i);if(2!=n.length)throw"malformed PKCS8 public key(code:002)";if("06"!=t.substr(n[0],2))throw"malformed PKCS8 public key(code:003)";if(e.algoid=ASN1HEX.getHexOfV_AtObj(t,n[0]),"06"==t.substr(n[1],2)&&(e.algparam=ASN1HEX.getHexOfV_AtObj(t,n[1])),"03"!=t.substr(r[1],2))throw"malformed PKCS8 public key(code:004)";returne.key=ASN1HEX.getHexOfV_AtObj(t,r[1]).substr(2),e},getRSAKeyFromPublicPKCS8Hex:function(t){vare=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(2!=e.length)throw"outer DERSequence shall have 2 elements: "+e.length;varr=ASN1HEX.getHexOfTLV_AtObj(t,e[0]);if("300d06092a864886f70d0101010500"!=r)throw"PKCS8 AlgorithmId is not rsaEncryption";if("03"!=t.substr(e[1],2))throw"PKCS8 Public Key is not BITSTRING encapslated.";vari=ASN1HEX.getStartPosOfV_AtObj(t,e[1])+2;if("30"!=t.substr(i,2))throw"PKCS8 Public Key is not SEQUENCE.";varn=ASN1HEX.getPosArrayOfChildren_AtObj(t,i);if(2!=n.length)throw"inner DERSequence shall have 2 elements: "+n.length;if("02"!=t.substr(n[0],2))throw"N is not ASN.1 INTEGER";if("02"!=t.substr(n[1],2))throw"EisnotASN
}functione(t){vare=t.alg,r="";if("RS256"!=e&&"RS512"!=e&&"PS256"!=e&&"PS512"!=e)throw"JWS signature algorithm not supported: "+e;return"256"==e.substr(2)&&(r="sha256"),"512"==e.substr(2)&&(r="sha512"),r}functionr(t){returne(jsonParse(t))}functioni(t,e,i,n,s,o){vara=newRSAKey;a.setPrivate(n,s,o);varh=r(t),u=a.signString(i,h);returnu}functionn(t,i,n,s,o){vara=null;a="undefined"==typeofo?r(t):e(o);varh="PS"==o.alg.substr(0,2);returns.hashAndSign?b64tob64u(s.hashAndSign(a,n,"binary","base64",h)):hextob64u(h?s.signStringPSS(n,a):s.signString(n,a))}functions(t,e,i,n){vars=newRSAKey;s.readPrivateKeyFromPEMString(n);varo=r(t),a=s.signString(i,o);returna}this.parseJWS=function(t,e){if(void0===this.parsedJWS||!e&&void0===this.parsedJWS.sigvalH){if(null==t.match(/^([^.]+)\.([^.]+)\.([^.]+)$/))throw"JWS signature is not a form of 'Head.Payload.SigValue'.";varr=RegExp.$1,i=RegExp.$2,n=RegExp.$3,s=r+"."+i;if(this.parsedJWS={},this.parsedJWS.headB64U=r,this.parsedJWS.payloadB64U=i,this.parsedJWS.sigvalB64U=n,this.parsedJWS.si=s,!e){varo=b64utohex(n),a=parseBigInt(o,16);this.parsedJWS.sigvalH=o,this.parsedJWS.sigvalBI=a}varh=b64utoutf8(r),u=b64utoutf8(i);if(this.parsedJWS.headS=h,this.parsedJWS.payloadS=u,!this.isSafeJSONString(h,this.parsedJWS,"headP"))throw"malformed JSON string for JWS Head: "+h}},this.verifyJWSByNE=function(t,e,r){returnthis.parseJWS(t),_rsasign_verifySignatureWithArgs(this.parsedJWS.si,this.parsedJWS.sigvalBI,e,r)},this.verifyJWSByKey=function(t,r){this.parseJWS(t);vari=e(this.parsedJWS.headP),n="PS"==this.parsedJWS.headP.alg.substr(0,2);returnr.hashAndVerify?r.hashAndVerify(i,newBuffer(this.parsedJWS.si,"utf8").toString("base64"),b64utob64(this.parsedJWS.sigvalB64U),"base64",n):n?r.verifyStringPSS(this.parsedJWS.si,this.parsedJWS.sigvalH,i):r.verifyString(this.parsedJWS.si,this.parsedJWS.sigvalH)},this.verifyJWSByPemX509Cert=function(t,e){this.parseJWS(t);varr=newX509;returnr.readCertPEM(e),r.subjectPublicKeyRSA.verifyString(this.parsedJWS.si,this.parsedJWS.sigvalH)},this.generateJWSByNED=function(e,r,n,s,o){if(!this.isSafeJSONString(e))throw"JWS Head is not safe JSON string: "+e;vara=t(e,r),h=i(e,r,a,n,s,o),u=hextob64u(h);returnthis.parsedJWS={},this.parsedJWS.headB64U=a.split(".")[0],this.parsedJWS.payloadB64U=a.split(".")[1],this.parsedJWS.sigvalB64U=u,a+"."+u},this.generateJWSByKey=function(e,r,i){vars={};if(!this.isSafeJSONString(e,s,"headP"))throw"JWS Head is not safe JSON string: "+e;varo=t(e,r),a=n(e,r,o,i,s.headP);returnthis.parsedJWS={},this.parsedJWS.headB64U=o.split(".")[0],this.parsedJWS.payloadB64U=o.split(".")[1],this.parsedJWS.sigvalB64U=a,o+"."+a},this.generateJWSByP1PrvKey=function(e,r,i){if(!this.isSafeJSONString(e))throw"JWS Head is not safe JSON string: "+e;varn=t(e,r),o=s(e,r,n,i),a=hextob64u(o);returnthis.parsedJWS={},this.parsedJWS.headB64U=n.split(".")[0],this.parsedJWS.payloadB64U=n.split(".")[1],this.parsedJWS.sigvalB64U=a,n+"."+a}},KJUR.jws.JWS.sign=function(t,e,r,i,n){vars=KJUR.jws.JWS;if(!s.isSafeJSONString(e))throw"JWS Head is not safe JSON string: "+sHead;varo=s.readSafeJSONString(e);""!=t&&null!=t||void0===o.alg||(t=o.alg),""!=t&&null!=t&&void0===o.alg&&(o.alg=t,e=JSON.stringify(o));vara=null;if(void0===s.jwsalg2sigalg[t])throw"unsupported alg name: "+t;a=s.jwsalg2sigalg[t];varh=utf8tob64u(e),u=utf8tob64u(r),c=h+"."+u,g="";if("Hmac"==a.substr(0,4)){if(void0===i)throw"hexadecimal key shall be specified for HMAC";varf=newKJUR.crypto.Mac({alg:a,pass:hextorstr(i)});f.updateString(c),g=f.doFinal()}elseif(-1!=a.indexOf("withECDSA")){varp=newKJUR.crypto.Signature({alg:a});p.init(i,n),p.updateString(c),hASN1Sig=p.sign(),g=KJUR.crypto.ECDSA.asn1SigToConcatSig(hASN1Sig)}elseif("none"!=a){varp=newKJUR.crypto.Signature({alg:a});p.init(i,n),p.updateString(c),g=p.sign()}varl=hextob64u(g);returnc+"."+l},KJUR.jws.JWS.verify=function(t,e){varr=KJUR.jws.JWS,i=t.split("."),n=i[0],s=i[1],o=n+"."+s,a=b64utohex(i[2]),h=r.readSafeJSONString(b64utoutf8(i[0])),u=null;if(void0===h.alg)throw"algorithm not specified in header";u=h.alg;varc=null;if(vo
(function(){varn=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){returnninstanceofj?n:thisinstanceofj?void(this._wrapped=n):newj(n)};"undefined"!=typeofexports?("undefined"!=typeofmodule&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.6.0";varA=j.each=j.forEach=function(n,t,e){if(null==n)returnn;if(s&&n.forEach===s)n.forEach(t,e);elseif(n.length===+n.length){for(varu=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}elsefor(vara=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return;returnn};j.map=j.collect=function(n,t,r){vare=[];returnnull==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};varO="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){varu=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)returne&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)thrownewTypeError(O);returnr},j.reduceRight=j.foldr=function(n,t,r,e){varu=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)returne&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);vari=n.length;if(i!==+i){vara=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)thrownewTypeError(O);returnr},j.find=j.detect=function(n,t,r){vare;returnk(n,function(n,u,i){returnt.call(r,n,u,i)?(e=n,!0):void0}),e},j.filter=j.select=function(n,t,r){vare=[];returnnull==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){returnj.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);varu=!0;returnnull==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void0:r}),!!u)};vark=j.some=j.any=function(n,t,e){t||(t=j.identity);varu=!1;returnnull==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){returnu||(u=t.call(e,n,i,a))?r:void0}),!!u)};j.contains=j.include=function(n,t){returnnull==n?!1:y&&n.indexOf===y?-1!=n.indexOf(t):k(n,function(n){returnn===t})},j.invoke=function(n,t){varr=o.call(arguments,2),e=j.isFunction(t);returnj.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){returnj.map(n,j.property(t))},j.where=function(n,t){returnj.filter(n,j.matches(t))},j.findWhere=function(n,t){returnj.find(n,j.matches(t))},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)returnMath.max.apply(Math,n);vare=-1/0,u=-1/0;returnA(n,function(n,i,a){varo=t?t.call(r,n,i,a):n;o>u&&(e=n,u=o)}),e},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)returnMath.min.apply(Math,n);vare=1/0,u=1/0;returnA(n,function(n,i,a){varo=t?t.call(r,n,i,a):n;u>o&&(e=n,u=o)}),e},j.shuffle=function(n){vart,r=0,e=[];returnA(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){returnnull==t||r?(n.length!==+n.length&&(n=j.values(n)),n[j.random(n.length-1)]):j.shuffle(n).slice(0,Math.max(0,t))};varE=function(n){returnnull==n?j.identity:j.isFunction(n)?n:j.property(n)};j.sortBy=function(n,t,r){returnt=E(t),j.pluck(j.map(n,function(n,e,u){return{value:n,index:e,criteria:t.call(r,n,e,u)}}).sort(function(n,t){varr=n.criteria,e=t.criteria;if(r!==e){if(r>e||void0===r)return1;if(e>r||void0===e)return-1}returnn.index-t.index}),"value")};varF=function(n){returnfunction(t,r,e){varu={};returnr=E(r),A(t,function(i,a){varo=r.call(e,i,a,t);n(u,o,i)}),u}};j.groupBy=F(function(n,t,r){j.has(n,t)?n[t].push(r):n[t]=[r]}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=E(r);for(varu=r.call(e,t),i=0,a=n.length;a>i;){varo=i+a>>>1;r.call(e,n[o])<u?i=o+1:a=o}returni},j.toArray=function(n){returnn?j.isArray
},{}],163:[function(require,module,exports){
exports.ShouldBeDefined="Variable should be defined.",exports.ShouldBeUndefined="Variable should be undefined.",exports.ShouldBeArray="Variable should be of type Array.",exports.ShouldNotBeArray="Variable should NOT be of type Array.",exports.ShouldBeObject="Variable should be of type Object.",exports.ShouldNotBeObject="Variable should NOT be of type Object.",exports.ShouldBeEmpty="Array or object should be empty.",exports.ShouldNotBeEmpty="Array or object should NOT be empty.",exports.ShouldBeFunction="Variable should be a Function.",exports.ShouldNotBeFunction="Variable should NOT be a Function.",exports.ShouldBeString="Variable should be a String.",exports.ShouldNotBeString="Variable should NOT be a String.",exports.ShouldBeNumber="Variable should be a Number.",exports.ShouldNotBeNumber="Variable should NOT be a Number.",exports.ShouldBeFinite="Variable should be Finite (i.e. not infinity).",exports.ShouldBeInfinite="Variable should be Infinite.",exports.ShouldBeBoolean="Variable should be a Boolean.",exports.ShouldNotBeBoolean="Variable should NOT be a Boolean.",exports.ShouldBeDate="Variable should be a Date.",exports.ShouldNotBeDate="Variable should NOT be a Date.",exports.ShouldBeRegExp="Variable should be a RegExp.",exports.ShouldNotBeRegExp="Variable should NOT be a RegExp.",exports.ShouldBeFalsey="Variable should be falsey.",exports.ShouldNotBeFalsey="Variable should NOT be falsey.",exports.IllegalArgument="Illegal Argument.",exports.IllegalState="Illegal State.",exports.ShouldHaveValidIndex="Index should be between between 0 (inclusive) and size (exclusive).",exports.ShouldHaveValidPosition="Index should be between index between 0 (inclusive) and size (inclusive).",exports.ShouldHaveValidPositions="Start and End should be between valid sub range between 0 (inclusive) and size (inclusive).",exports.StartBeforeEnd="Start value should be less than the end value.";
!function(e){"use strict";functiont(e){if(!e||!e.VERSION||e.VERSION.split(".")[0]<3)throwError("ProtoBuf.js requires ByteBuffer.js >=3");vart={};returnt.VERSION="3.0.0",t.WIRE_TYPES={},t.WIRE_TYPES.VARINT=0,t.WIRE_TYPES.BITS64=1,t.WIRE_TYPES.LDELIM=2,t.WIRE_TYPES.STARTGROUP=3,t.WIRE_TYPES.ENDGROUP=4,t.WIRE_TYPES.BITS32=5,t.PACKABLE_WIRE_TYPES=[t.WIRE_TYPES.VARINT,t.WIRE_TYPES.BITS64,t.WIRE_TYPES.BITS32],t.TYPES={int32:{name:"int32",wireType:t.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:t.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:t.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:t.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:t.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:t.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:t.WIRE_TYPES.VARINT},"double":{name:"double",wireType:t.WIRE_TYPES.BITS64},string:{name:"string",wireType:t.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:t.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:t.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:t.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:t.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:t.WIRE_TYPES.BITS64},"float":{name:"float",wireType:t.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:t.WIRE_TYPES.VARINT},message:{name:"message",wireType:t.WIRE_TYPES.LDELIM},group:{name:"group",wireType:t.WIRE_TYPES.STARTGROUP}},t.ID_MIN=1,t.ID_MAX=536870911,t.ByteBuffer=e,t.Long=e.Long||null,t.convertFieldsToCamelCase=!1,t.Util=function(){Object.create||(Object.create=function(e){functiont(){}if(arguments.length>1)thrownewError("Object.create implementation only accepts the first parameter.");returnt.prototype=e,newt});vare={};e.IS_NODE=!1;try{e.IS_NODE="function"==typeofrequire&&"function"==typeofrequire("fs").readFileSync&&"function"==typeofrequire("path").resolve}catch(t){}returne.XHR=function(){for(vare=[function(){returnnewXMLHttpRequest},function(){returnnewActiveXObject("Msxml2.XMLHTTP")},function(){returnnewActiveXObject("Msxml3.XMLHTTP")},function(){returnnewActiveXObject("Microsoft.XMLHTTP")}],t=null,n=0;n<e.length;n++){try{t=e[n]()}catch(i){continue}break}if(!t)thrownewError("XMLHttpRequest is not supported");returnt},e.fetch=function(t,n){if(n&&"function"!=typeofn&&(n=null),e.IS_NODE)if(n)require("fs").readFile(t,function(e,t){n(e?null:""+t)});elsetry{returnrequire("fs").readFileSync(t)}catch(i){returnnull}else{varr=e.XHR();if(r.open("GET",t,n?!0:!1),r.setRequestHeader("Accept","text/plain"),"function"==typeofr.overrideMimeType&&r.overrideMimeType("text/plain"),!n)returnr.send(null),200==r.status||0==r.status&&"string"==typeofr.responseText?r.responseText:null;if(r.onreadystatechange=function(){4==r.readyState&&n(200==r.status||0==r.status&&"string"==typeofr.responseText?r.responseText:null)},4==r.readyState)return;r.send(null)}},e.isArray=function(e){returne?einstanceofArray?!0:Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e):!1},e}(),t.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",STRINGOPEN:'"',STRINGCLOSE:'"',STRINGOPEN_SQ:"'",STRINGCLOSE_SQ:"'",COPTOPEN:"(",COPTCLOSE:")",DELIM:/[\s\{\}=;\[\],'"\(\)]/g,RULE:/^(?:required|optional|repeated)$/,TYPE:/^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,NAME:/^[a-zA-Z_][a-zA-Z_0-9]*$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,FQTYPEREF:/^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|([0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?))$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0x[0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^[0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?$/,ID:/^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g,BOOL:/^(?:true|false)$/i},t.DotProto=function(e,t){varn={},i=function(e){this.source=""+e,this.index=0,this.line=1,this.stack=[],this.readingString=!1,this.stringEndsWith=t.STRINGCLOSE};i.prototype._readString=fu
break;caset.TYPES.sint64:i.writeVarint64ZigZag(n);break;caset.TYPES.fixed64:i.writeUint64(n);break;caset.TYPES.sfixed64:i.writeInt64(n);break;caset.TYPES.bool:i.writeVarint32("string"==typeofn?"false"===n.toLowerCase()?0:!!n:n?1:0);break;caset.TYPES["enum"]:i.writeVarint32(n);break;caset.TYPES["float"]:i.writeFloat32(n);break;caset.TYPES["double"]:i.writeFloat64(n);break;caset.TYPES.string:i.writeVString(n);break;caset.TYPES.bytes:n.offset>n.length&&(i=i.clone().flip());varr=n.offset;i.writeVarint32(n.remaining()),i.append(n),n.offset=r;break;caset.TYPES.message:vars=(newe).LE();this.resolvedType.encode(n,s),i.writeVarint32(s.offset),i.append(s.flip());break;caset.TYPES.group:this.resolvedType.encode(n,i),i.writeVarint32(this.id<<3|t.WIRE_TYPES.ENDGROUP);break;default:thrownewError("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+n+" (unknown type)")}returni}},l.prototype.decode=function(e,n,i){varr,s;if(e!=this.type.wireType&&(i||e!=t.WIRE_TYPES.LDELIM||!this.repeated))thrownewError("Illegal wire type for field "+this.toString(!0)+": "+e+" ("+this.type.wireType+" expected)");if(e==t.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&!i){s=n.readVarint32(),s=n.offset+s;for(varo=[];n.offset<s;)o.push(this.decode(this.type.wireType,n,!0));returno}switch(this.type){caset.TYPES.int32:return0|n.readVarint32();caset.TYPES.uint32:returnn.readVarint32()>>>0;caset.TYPES.sint32:return0|n.readVarint32ZigZag();caset.TYPES.fixed32:returnn.readUint32()>>>0;caset.TYPES.sfixed32:return0|n.readInt32();caset.TYPES.int64:returnn.readVarint64();caset.TYPES.uint64:returnn.readVarint64().toUnsigned();caset.TYPES.sint64:returnn.readVarint64ZigZag();caset.TYPES.fixed64:returnn.readUint64();caset.TYPES.sfixed64:returnn.readInt64();caset.TYPES.bool:return!!n.readVarint32();caset.TYPES["enum"]:returnn.readVarint32();caset.TYPES["float"]:returnn.readFloat();caset.TYPES["double"]:returnn.readDouble();caset.TYPES.string:returnn.readVString();caset.TYPES.bytes:if(s=n.readVarint32(),n.remaining()<s)thrownewError("Illegal number of bytes for "+this.toString(!0)+": "+s+" required but got only "+n.remaining());returnr=n.clone(),r.limit=r.offset+s,n.offset+=s,r;caset.TYPES.message:returns=n.readVarint32(),this.resolvedType.decode(n,s);caset.TYPES.group:returnthis.resolvedType.decode(n,-1,this.id)}thrownewError("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+e)},r.Message.Field=l;varf=function(e,t,n){o.call(this,e,t,n),this.className="Enum",this.object=null};f.prototype=Object.create(o.prototype),f.prototype.build=function(){for(vare={},t=this.getChildren(f.Value),n=0;n<t.length;n++)e[t[n].name]=t[n].id;returnObject.defineProperty&&Object.defineProperty(e,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1}),this.object=e},r.Enum=f;varp=function(e,t,n){s.call(this,e,t),this.className="Enum.Value",this.id=n};p.prototype=Object.create(s.prototype),r.Enum.Value=p;varh=function(e,t,n){o.call(this,e,t,n),this.className="Service",this.clazz=null};h.prototype=Object.create(o.prototype),h.prototype.build=function(e){returnthis.clazz&&!e?this.clazz:this.clazz=function(e,t){varn=function(t){e.Builder.Service.call(this),this.rpcImpl=t||function(e,t,n){setTimeout(n.bind(this,newError("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};n.prototype=Object.create(e.Builder.Service.prototype),Object.defineProperty&&(Object.defineProperty(n,"$options",{value:t.buildOpt(),enumerable:!1,configurable:!1,writable:!1}),Object.defineProperty(n.prototype,"$options",{value:n.$options,enumerable:!1,configurable:!1,writable:!1}));for(vari=t.getChildren(e.Reflect.Service.RPCMethod),r=0;r<i.length;r++)!function(e){n.prototype[e.name]=function(n,i){try{n&&ninstanceofe.resolvedRequestType.clazz||setTimeout(i.bind(this,newError("Illegal request type provided to service method "+t.name+"#"+e.name)),0),this.rpcImpl(e.fqn(),n,function(n,r){if(n)returnvoidi(n);try{r=e.resolvedResponseType.clazz.decode(r)}catch(s){}returnr&&rinstan
!function(e){functiont(e){functiont(e,n,i){if("undefined"==typeofe&&(e=t.DEFAULT_CAPACITY),"undefined"==typeofn&&(n=t.DEFAULT_ENDIAN),"undefined"==typeofi&&(i=t.DEFAULT_NOASSERT),!i){if(e|=0,0>e)thrownewRangeError("Illegal capacity: 0 <= "+e);if("boolean"!=typeofn)thrownewTypeError("Illegal littleEndian: Not a boolean");if("boolean"!=typeofi)thrownewTypeError("Illegal noAssert: Not a boolean")}this.buffer=0===e?r:newArrayBuffer(e),this.view=0===e?null:newDataView(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian="undefined"!=typeofn?!!n:!1,this.noAssert=!!i}t.VERSION="3.1.0",t.LITTLE_ENDIAN=!0,t.BIG_ENDIAN=!1,t.DEFAULT_CAPACITY=16,t.DEFAULT_ENDIAN=t.BIG_ENDIAN,t.DEFAULT_NOASSERT=!1,t.Long=e||null;varr=newArrayBuffer(0);t.allocate=function(e,r,n){returnnewt(e,r,n)},t.concat=function(e,r,n,i){("boolean"==typeofr||"string"!=typeofr)&&(i=n,n=r,r=void0);for(varf,o=0,s=0,h=e.length;h>s;++s)t.isByteBuffer(e[s])||(e[s]=t.wrap(e[s],r)),f=e[s].limit-e[s].offset,f>0&&(o+=f);if(0===o)returnnewt(0,n,i);for(r=newt(o,n,i),i=newUint8Array(r.buffer),s=0;h>s;)n=e[s++],f=n.limit-n.offset,0>=f||(i.set(newUint8Array(n.buffer).subarray(n.offset,n.limit),r.offset),r.offset+=f);returnr.limit=r.offset,r.offset=0,r},t.isByteBuffer=function(e){returne&&einstanceoft},t.type=function(){returnArrayBuffer},t.wrap=function(e,r,n,f){if("string"!=typeofr&&(f=n,n=r,r=void0),"string"==typeofe)switch("undefined"==typeofr&&(r="utf8"),r){case"base64":returnt.fromBase64(e,n);case"hex":returnt.fromHex(e,n);case"binary":returnt.fromBinary(e,n);case"utf8":returnt.fromUTF8(e,n);case"debug":returnt.fromDebug(e,n);default:thrownewTypeError("Unsupported encoding: "+r)}if(null===e||"object"!=typeofe)thrownewTypeError("Illegal buffer: null or non-object");if(t.isByteBuffer(e))returnr=t.prototype.clone.call(e),r.markedOffset=-1,r;if(einstanceofUint8Array)r=newt(0,n,f),0<e.length&&(r.buffer=e.buffer,r.offset=e.byteOffset,r.limit=e.byteOffset+e.length,r.view=0<e.length?newDataView(e.buffer):null);elseif(einstanceofArrayBuffer)r=newt(0,n,f),0<e.byteLength&&(r.buffer=e,r.offset=0,r.limit=e.byteLength,r.view=0<e.byteLength?newDataView(e):null);else{if("[object Array]"!==Object.prototype.toString.call(e))thrownewTypeError("Illegal buffer");for(r=newt(e.length,n,f),r.limit=e.length,i=0;i<e.length;++i)r.view.setUint8(i,e[i])}returnr},t.prototype.writeInt8=function(e,t){varr="undefined"==typeoft;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeoft||0!==t%1)thrownewTypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)thrownewRangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;varn=this.buffer.byteLength;returnt>n&&this.resize((n*=2)>t?n:t),this.view.setInt8(t-1,e),r&&(this.offset+=1),this},t.prototype.writeByte=t.prototype.writeInt8,t.prototype.readInt8=function(e){vart="undefined"==typeofe;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeError("Illegal offset: "+e+" (not an integer)");if(e>>>=0,0>e||e+1>this.buffer.byteLength)thrownewRangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}returne=this.view.getInt8(e),t&&(this.offset+=1),e},t.prototype.readByte=t.prototype.readInt8,t.prototype.writeUint8=function(e,t){varr="undefined"==typeoft;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeoft||0!==t%1)thrownewTypeError("Illegal offset: "+t+" (not an integer)");if(t>>>=0,0>t||t+0>this.buffer.byteLength)thrownewRangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;varn=this.buffer.byteLength;returnt>n&&this.resize((n*=2)>t?n:t),this.view.setUint8(t-1,e),r&&(this.offset+=1),this},t.prototype.readUint8=function(e){vart="undefined"==typeofe;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeE
},t.prototype.toBuffer=function(e){vart=this.offset,n=this.limit;if(t>n)vari=t,t=n,n=i;if(!this.noAssert){if("number"!=typeoft||0!==t%1)thrownewTypeError("Illegal offset: Not an integer");if(t>>>=0,"number"!=typeofn||0!==n%1)thrownewTypeError("Illegal limit: Not an integer");if(n>>>=0,0>t||t>n||n>this.buffer.byteLength)thrownewRangeError("Illegal range: 0 <= "+t+" <= "+n+" <= "+this.buffer.byteLength)}returne||0!==t||n!==this.buffer.byteLength?t===n?r:(e=newArrayBuffer(n-t),newUint8Array(e).set(newUint8Array(this.buffer).subarray(t,n),0),e):this.buffer},t.prototype.toArrayBuffer=t.prototype.toBuffer,t.prototype.toString=function(e){if("undefined"==typeofe)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";switch(e){case"utf8":returnthis.toUTF8();case"base64":returnthis.toBase64();case"hex":returnthis.toHex();case"binary":returnthis.toBinary();case"debug":returnthis.toDebug();case"columns":returnthis.o();default:throwError("Unsupported encoding: "+e)}};varn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",n=n+"";t.prototype.toBase64=function(e,t){if("undefined"==typeofe&&(e=this.offset),"undefined"==typeoft&&(t=this.limit),!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeoft||0!==t%1)thrownewTypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)thrownewRangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(e===t)return"";for(varr,i,f,o,s,h,a="";t>e;)r=this.view.getUint8(e++),i=(o=t>e)?this.view.getUint8(e++):0,f=(s=t>e)?this.view.getUint8(e++):0,h=r>>2,r=(3&r)<<4|i>>4,i=(15&i)<<2|f>>6,f&=63,s||(f=64,o||(i=64)),a+=n.charAt(h)+n.charAt(r)+n.charAt(i)+n.charAt(f);returna},t.fromBase64=function(e,r,i){if(!i){if("string"!=typeofe)thrownewTypeError("Illegal str: Not a string");if(0!==e.length%4)thrownewTypeError("Illegal str: Length not a multiple of 4")}varf,o=e.length,s=0;for(f=e.length-1;f>=0&&"="===e.charAt(f);--f)s++;if(s>2)thrownewTypeError("Illegal str: Suffix is too large");if(0===o)returnnewt(0,r,i);varh,a,l,u=newt(o/4*3-s,r,i);for(r=f=0;o>f;){if(s=n.indexOf(e.charAt(f++)),h=o>f?n.indexOf(e.charAt(f++)):0,a=o>f?n.indexOf(e.charAt(f++)):0,l=o>f?n.indexOf(e.charAt(f++)):0,!i&&(0>s||0>h||0>a||0>l))thrownewTypeError("Illegal str: Contains non-base64 characters");u.view.setUint8(r++,s<<2|h>>4),64!==a&&(u.view.setUint8(r++,h<<4&240|a>>2,r),64!==l&&u.view.setUint8(r++,a<<6&192|l))}returnu.limit=r,u},t.btoa=function(e){returnt.fromBinary(e).toBase64()},t.atob=function(e){returnt.fromBase64(e).toBinary()},t.prototype.toBinary=function(e,t){if(e="undefined"==typeofe?this.offset:e,t="undefined"==typeoft?this.limit:t,!this.noAssert){if("number"!=typeofe||0!==e%1)thrownewTypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeoft||0!==t%1)thrownewTypeError("Illegal end: Not an integer");if(t>>>=0,0>e||e>t||t>this.buffer.byteLength)thrownewRangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(e===t)return"";for(varr=[];t>e;)r.push(this.view.getUint8(e++));returnString.fromCharCode.apply(String,r)},t.fromBinary=function(e,r,n){if(!n&&"string"!=typeofe)thrownewTypeError("Illegal str: Not a string");for(vari=0,f=e.length,o=newt(f,r,n);f>i;){if(r=e.charCodeAt(i),!n&&r>255)thrownewTypeError("Illegal charCode at "+i+": 0 <= "+r+" <= 255");o.view.setUint8(i++,r)}returno.limit=f,o},t.prototype.toDebug=function(e){for(vart,r=-1,n=this.buffer.byteLength,i="",f="",o="";n>r;){if(-1!==r&&(t=this.view.getUint8(r),i=16>t?i+("0"+t.toString(16).toUpperCase()):i+t.toString(16).toUpperCase(),e&&(f+=t>32&&127>t?String.fromCharCode(t):".")),++r,e&&r>0&&0===r%16&&r!==n){for(;51>i.length;)i+=" ";o+=i+f+"\n",i=f=""}i=r===this.offset&&r===this.limit?i+(r===this.markedOffset?"!":"|"):r===this.offset?i+(r===this.markedOffset?"[":"<"):r===this.limit?i+(r===this.markedOffset?"]":">"):i+(r===this.markedOffset?"'":e||0!==r&&r!==n?" "
!function(t){"use strict";vari=function(t,i,r){t&&"object"==typeoft&&(i=t.high,r=t.unsigned,t=t.low),this.low=0|t,this.high=0|i,this.unsigned=!!r},r={},e={};i.fromInt=function(t,n){varo,s;returnn?(t>>>=0,t>=0&&256>t&&(s=e[t])?s:(o=newi(t,0>(0|t)?-1:0,!0),t>=0&&256>t&&(e[t]=o),o)):(t=0|t,t>=-128&&128>t&&(s=r[t])?s:(o=newi(t,0>t?-1:0,!1),t>=-128&&128>t&&(r[t]=o),o))},i.fromNumber=function(t,r){returnr=!!r,isNaN(t)||!isFinite(t)?i.ZERO:!r&&-h>=t?i.MIN_SIGNED_VALUE:r&&0>=t?i.MIN_UNSIGNED_VALUE:!r&&t+1>=h?i.MAX_SIGNED_VALUE:r&&t>=s?i.MAX_UNSIGNED_VALUE:0>t?i.fromNumber(-t,!1).negate():newi(t%o|0,t/o|0,r)},i.fromBits=function(t,r,e){returnnewi(t,r,e)},i.from28Bits=function(t,r,e,n){returni.fromBits(t|r<<28,r>>>4|e<<24,n)},i.fromString=function(t,r,e){if(0==t.length)thrownewError("number format error: empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)returni.ZERO;if("number"==typeofr&&(e=r,r=!1),e=e||10,2>e||e>36)thrownewError("radix out of range: "+e);if("-"==t.charAt(0))returni.fromString(t.substring(1),r,e).negate();if(t.indexOf("-")>=0)thrownewError('number format error: interior "-" character: '+t);for(varn=i.fromNumber(Math.pow(e,8)),o=i.ZERO,s=0;s<t.length;s+=8){varh=Math.min(8,t.length-s),u=parseInt(t.substring(s,s+h),e);if(8>h){varf=i.fromNumber(Math.pow(e,h));o=o.multiply(f).add(i.fromNumber(u))}elseo=o.multiply(n),o=o.add(i.fromNumber(u))}returno.unsigned=r,o};varn=65536,o=n*n,s=o*o,h=s/2,u=i.fromInt(1<<24);i.ZERO=i.fromInt(0),i.UZERO=i.fromInt(0,!0),i.ONE=i.fromInt(1),i.UONE=i.fromInt(1,!0),i.NEG_ONE=i.fromInt(-1),i.MAX_SIGNED_VALUE=i.fromBits(-1,2147483647,!1),i.MAX_UNSIGNED_VALUE=i.fromBits(-1,-1,!0),i.MAX_VALUE=i.MAX_SIGNED_VALUE,i.MIN_SIGNED_VALUE=i.fromBits(0,-2147483648,!1),i.MIN_UNSIGNED_VALUE=i.fromBits(0,0,!0),i.MIN_VALUE=i.MIN_SIGNED_VALUE,i.prototype.toInt=function(){returnthis.unsigned?this.low>>>0:this.low},i.prototype.toNumber=function(){returnthis.unsigned?(this.high>>>0)*o+(this.low>>>0):this.high*o+(this.low>>>0)},i.prototype.toString=function(t){if(t=t||10,2>t||t>36)thrownewError("radix out of range: "+t);if(this.isZero())return"0";varr;if(this.isNegative()){if(this.equals(i.MIN_SIGNED_VALUE)){vare=i.fromNumber(t),n=this.div(e);returnr=n.multiply(e).subtract(this),n.toString(t)+r.toInt().toString(t)}return"-"+this.negate().toString(t)}varo=i.fromNumber(Math.pow(t,6));r=this;for(vars="";;){varh=r.div(o),u=r.subtract(h.multiply(o)).toInt(),f=u.toString(t);if(r=h,r.isZero())returnf+s;for(;f.length<6;)f="0"+f;s=""+f+s}},i.prototype.getHighBits=function(){returnthis.high},i.prototype.getHighBitsUnsigned=function(){returnthis.high>>>0},i.prototype.getLowBits=function(){returnthis.low},i.prototype.getLowBitsUnsigned=function(){returnthis.low>>>0},i.prototype.getNumBitsAbs=function(){if(this.isNegative())returnthis.equals(i.MIN_SIGNED_VALUE)?64:this.negate().getNumBitsAbs();for(vart=0!=this.high?this.high:this.low,r=31;r>0&&0==(t&1<<r);r--);return0!=this.high?r+33:r+1},i.prototype.isZero=function(){return0==this.high&&0==this.low},i.prototype.isNegative=function(){return!this.unsigned&&this.high<0},i.prototype.isOdd=function(){return1==(1&this.low)},i.prototype.isEven=function(){return0==(1&this.low)},i.prototype.equals=function(t){returnthis.unsigned!=t.unsigned&&this.high>>>31!=t.high>>>31?!1:this.high==t.high&&this.low==t.low},i.prototype.notEquals=function(t){return!this.equals(t)},i.prototype.lessThan=function(t){returnthis.compare(t)<0},i.prototype.lessThanOrEqual=function(t){returnthis.compare(t)<=0},i.prototype.greaterThan=function(t){returnthis.compare(t)>0},i.prototype.greaterThanOrEqual=function(t){returnthis.compare(t)>=0},i.prototype.compare=function(t){if(this.equals(t))return0;vari=this.isNegative(),r=t.isNegative();returni&&!r?-1:!i&&r?1:this.unsigned?t.high>>>0>this.high>>>0||t.high==this.high&&t.low>>>0>this.low>>>0?-1:1:this.subtract(t).isNegative()?-1:1},i.prototype.negate=function(){return!this.unsigned&&this.equals(i.MIN_SIGNED_VALUE)?i.MIN_SIGNED_VALUE:this.not().add(i.ONE)},i.prototype.add=function(t
(function(e){"use strict";functiont(e,t){varo=this;u.call(o),o.socket=newi.Socket,o.socksHost=e,o.socksPort=t,o.socket.on("error",function(e){o.emit("error",e)}),o.on("error",function(){o.socket.destroyed||o.socket.destroy()})}functiono(e,t){varo,n,r=e.split(".");for(o=0;o<r.length;o++)n=parseInt(r[o],10),t.push(n)}functionn(e,t){varo,n,r,s,c,i,u;if(i=newd.Address(e).canonicalForm(),!i)return!1;for(u=i.split(":"),o=0;o<u.length;o++)s=u[o].substr(0,2),c=u[o].substr(2,2),n=parseInt(s,16),r=parseInt(c,16),t.push(n),t.push(r);return!0}functionr(e,t){varo,n;for(t.push(e.length),o=0;o<e.length;o++)n=e.charCodeAt(o),t.push(n)}functions(e,t){p(t,t.length,e)}functionc(e){switch(e){case1:return"General SOCKS server failure";case2:return"Connection not allowed by ruleset";case3:return"Network unreachable";case4:return"Host unreachable";case5:return"Connection refused";case6:return"TTL expired";case7:return"Command not supported";case8:return"Address type not supported";default:return"Unknown status code "+e}}vari=require("net"),u=require("events").EventEmitter,a=require("util").inherits,p=require("network-byte-order").htons,d=require("ipv6").v6;module.exports=exports=t,exports.createConnection=function(e){varo,n,r;returnn=e.socksHost||"localhost",r=e.socksPort||1080,o=newt(n,r),o.connect(e.port,e.host)},a(t,u),t.prototype.setTimeout=function(e,t){returnthis.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(){returnthis.socket.setNoDelay()},t.prototype.setKeepAlive=function(e,t){returnthis.socket.setKeepAlive(e,t)},t.prototype.address=function(){returnthis.socket.address()},t.prototype.pause=function(){returnthis.socket.pause()},t.prototype.resume=function(){returnthis.socket.resume()},t.prototype.end=function(e,t){returnthis.socket.end(e,t)},t.prototype.destroy=function(e){returnthis.socket.destroy(e)},t.prototype.destroySoon=function(){vare=this.socket.destroySoon();returnthis.writable=!1,e},t.prototype.setEncoding=function(e){returnthis.socket.setEncoding(e)},t.prototype.write=function(e,t,o){returnthis.socket.write(e,t,o)},t.prototype.connect=function(e,t){varo=this;returno.socket.connect(o.socksPort,o.socksHost,function(){o.establishSocksConnection(t,e)}),o},t.prototype.handleSocksConnectToHost=function(){vare=this;e.socket.on("close",function(t){e.emit("close",t)}),e.socket.on("end",function(){e.emit("end")}),e.socket.on("data",function(t){e.emit("data",t)}),e.socket._httpMessage=e._httpMessage,e.socket.parser=e.parser,e.socket.ondata=e.ondata,e.writable=!0,e.readable=!0,e.emit("connect")},t.prototype.establishSocksConnection=function(e,t){varo=this;o.authenticateWithSocks(function(){o.connectSocksToHost(e,t,function(){o.handleSocksConnectToHost()})})},t.prototype.authenticateWithSocks=function(t){varo,n=this;n.socket.ondata=function(e,o,r){vars;returnr-o!==2?s=newError("SOCKS authentication failed. Unexpected number of bytes received."):5!==e[o]?s=newError("SOCKS authentication failed. Unexpected SOCKS version number: "+e[o]+"."):0!==e[o+1]&&(s=newError("SOCKS authentication failed. Unexpected SOCKS authentication method: "+e[o+1]+".")),s?voidn.emit("error",s):void(t&&t())},o=newe(3),o[0]=5,o[1]=1,o[2]=0,n.socket.write(o)},t.prototype.connectSocksToHost=function(t,u,a){varp,d,h=this;switch(this.socket.ondata=function(e,t){varo,n,r,s;if(5!==e[t]?s=newError("SOCKS connection failed. Unexpected SOCKS version number: "+e[t]+"."):0!==e[t+1]?s=newError("SOCKS connection failed. "+c(e[t+1])+"."):0!==e[t+2]&&(s=newError("SOCKS connection failed. The reserved byte must be 0x00.")),s)returnvoidh.emit("error",s);switch(n="",r=0,e[t+3]){case1:n=e[t+4]+"."+e[t+5]+"."+e[t+6]+"."+e[t+7],r=4;break;case3:for(r=e[t+4]+1,o=t+5;t+r>o;o++)n+=String.fromCharCode(e[o]);break;case4:r=16;break;default:returnvoidh.emit("error",newError("SOCKS connection failed. Unknown addres type: "+e[t+3]+"."))}a&&a()},p=[],p.push(5),p.push(1),p.push(0),i.isIP(t)){case0:p.push(3),r(t,p);break;case4:p.push(1),o(t,p);break;case6:if(p.push(4),n(t,p)===!1)returnvoidh.emit("error",newError("IPv6ho
varutil=require("util"),sprintf=function(){functionr(r){returnObject.prototype.toString.call(r).slice(8,-1).toLowerCase()}functione(r,e){for(vart=[];e>0;t[--e]=r);returnt.join("")}vart=function(){returnt.cache.hasOwnProperty(arguments[0])||(t.cache[arguments[0]]=t.parse(arguments[0])),t.format.call(null,t.cache[arguments[0]],arguments)};returnt.object_stringify=function(r,e,n,i){vars="";if(null!=r)switch(typeofr){case"function":return"[Function"+(r.name?": "+r.name:"")+"]";case"object":if(rinstanceofError)return"["+r.toString()+"]";if(e>=n)return"[Object]";if(i&&(i=i.slice(0),i.push(r)),null!=r.length){s+="[";vara=[];for(varoinr)a.push(i&&i.indexOf(r[o])>=0?"[Circular]":t.object_stringify(r[o],e+1,n,i));s+=a.join(", ")+"]"}else{if("getMonth"inr)return"Date("+r+")";s+="{";vara=[];for(varfinr)r.hasOwnProperty(f)&&a.push(i&&i.indexOf(r[f])>=0?f+": [Circular]":f+": "+t.object_stringify(r[f],e+1,n,i));s+=a.join(", ")+"}"}returns;case"string":return'"'+r+'"'}return""+r},t.format=function(n,i){vars,a,o,f,u,c,p,l=1,h=n.length,g="",b=[];for(a=0;h>a;a++)if(g=r(n[a]),"string"===g)b.push(n[a]);elseif("array"===g){if(f=n[a],f[2])for(s=i[l],o=0;o<f[2].length;o++){if(!s.hasOwnProperty(f[2][o]))thrownewError(sprintf('[sprintf] property "%s" does not exist',f[2][o]));s=s[f[2][o]]}elses=f[1]?i[f[1]]:i[l++];if(/[^sO]/.test(f[8])&&"number"!=r(s))thrownewError(sprintf('[sprintf] expecting number but found %s "'+s+'"',r(s)));switch(f[8]){case"b":s=s.toString(2);break;case"c":s=String.fromCharCode(s);break;case"d":s=parseInt(s,10);break;case"e":s=f[7]?s.toExponential(f[7]):s.toExponential();break;case"f":s=f[7]?parseFloat(s).toFixed(f[7]):parseFloat(s);break;case"O":s=t.object_stringify(s,0,parseInt(f[7])||5);break;case"o":s=s.toString(8);break;case"s":s=(s=String(s))&&f[7]?s.substring(0,f[7]):s;break;case"u":s=Math.abs(s);break;case"x":s=s.toString(16);break;case"X":s=s.toString(16).toUpperCase()}s=/[def]/.test(f[8])&&f[3]&&s>=0?"+"+s:s,c=f[4]?"0"==f[4]?"0":f[4].charAt(1):" ",p=f[6]-String(s).length,u=f[6]?e(c,p):"",b.push(f[5]?s+u:u+s)}returnb.join("")},t.cache={},t.parse=function(r){for(vare=r,t=[],n=[],i=0;e;){if(null!==(t=/^[^\x25]+/.exec(e)))n.push(t[0]);elseif(null!==(t=/^\x25{2}/.exec(e)))n.push("%");else{if(null===(t=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosOuxX])/.exec(e)))thrownewError("[sprintf] "+e);if(t[2]){i|=1;vars=[],a=t[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(a)))thrownewError("[sprintf] "+a);for(s.push(o[1]);""!==(a=a.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(a)))s.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(a)))thrownewError("[sprintf] "+a);s.push(o[1])}t[2]=s}elsei|=2;if(3===i)thrownewError("[sprintf] mixing positional and named placeholders is not (yet) supported");n.push(t)}e=e.substring(t[0].length)}returnn},t}(),vsprintf=function(r,e){vart=e.slice();returnt.unshift(r),sprintf.apply(null,t)};module.exports=sprintf,sprintf.sprintf=sprintf,sprintf.vsprintf=vsprintf;
(function(e,r){functiont(e){for(e=e.substr(0,8);e.length<8;)e+="0";returne}functionn(e){returni(e[1]).mul("100000000").add(t(e[2]))}functiono(e){returni(t(e[1]))}functionf(e){returni(e[1]).mul("100000000")}varu=require("crypto"),i=require("bignum"),s=require("binary"),a=require("bufferput"),c=require("buffertools"),h=require("../lib/sjcl");if(e.browser)varl=require("hash.js");{varp=exports.sha256=function(e){returnnewr(u.createHash("sha256").update(e).digest("binary"),"binary")},v=(exports.sha512=function(t){if(e.browser){varn=t.toString("hex"),o=h.codec.hex.toBits(n),f=h.hash.sha512.hash(o),i=h.codec.hex.fromBits(f),s=newr(i,"hex");returns}returnnewr(u.createHash("sha512").update(t).digest("binary"),"binary")},exports.sha512hmac=function(t,n){if(e.browser){varo=h.codec.hex.toBits(n.toString("hex")),f=h.codec.hex.toBits(t.toString("hex")),i=newh.misc.hmac(o,h.hash.sha512),s=i.encrypt(f),a=h.codec.hex.fromBits(s),c=newr(a,"hex");returnc}vari=u.createHmac("sha512",n),l=i.update(t).digest();returnl},exports.ripe160=function(t){if(!r.isBuffer(t))thrownewError("arg should be a buffer");returne.browser?newr(l.ripemd160().update(t).digest()):newr(u.createHash("rmd160").update(t).digest("binary"),"binary")}),g=(exports.sha1=function(e){returnnewr(u.createHash("sha1").update(e).digest("binary"),"binary")},exports.twoSha256=function(e){returnp(p(e))},exports.sha256ripe160=function(e){returnv(p(e))},exports.formatHash=function(e){vart=newr(10);returne.copy(t,0,22,32),c.reverse(t).toString("hex")},exports.formatHashFull=function(e){vart=newr(e.length);e.copy(t);varn=c.toHex(c.reverse(t));returnn}),d=(exports.formatHashAlt=function(e){varr=g(e);returnr=r.replace(/^0*/,""),r.substr(0,10)},exports.formatBuffer=function(e,t){null===t&&(t=10),(t>e.length||0===t)&&(t=e.length);varn=newr(t);e.copy(n,0,0,t);varo=c.toHex(n);returnn.length<e.length&&(o+="..."),o},exports.valueToBigInt=function(e){returnr.isBuffer(e)?i.fromBuffer(e,{endian:"little",size:8}):e});exports.bigIntToValue=function(e){returnr.isBuffer(e)?e:e.toBuffer({endian:"little",size:8})}}exports.bytesNeededToStore=bytesNeededToStore=function(e){return0===e?0:Math.ceil((e.toString(2).replace("-","").length+1)/8)},exports.negativeBuffer=negativeBuffer=function(e){for(vart=newr(e.length),n=0;n<e.length;n++)t[n]=~e[n],t[n]<0&&(t[n]+=256);for(varn=e.length-1;n>=0&&(t[n]+=1,t[n]>=256&&(t[n]-=256),0===t[n]);n--);returnt},exports.intToBuffer2C=function(e){varr=bytesNeededToStore(e),t=newa,n=e.toString(16),o="-"===n[0];n=n.replace("-","");for(varf=0;r>f;f++){varu=n.substring(n.length-2*(f+1),n.length-2*f);1===u.length&&(u="0"+u);vari=parseInt(u,16);t.word8(i)}vars=t.buffer();returno&&(s=c.reverse(s),s=negativeBuffer(s),s=c.reverse(s)),s};varw=function(e){vart;return128&e[0]?(t=newr(e.length+1),e.copy(t,1),t[0]=0):t=e,t};exports.intToBufferSM=function(e){"number"==typeofe&&(e=i(e));vart,n,o=e.cmp(0);returno>0?(t=e.toBuffer(),n=w(t),n=c.reverse(n)):0==o?n=newr([]):(t=e.neg().toBuffer(),n=w(t),n[0]|=128,n=c.reverse(n)),n},exports.bufferSMToInt=function(e){if(!e.length)returni(0);if(e.length>4)thrownewError("Bigint cast overflow (> 4 bytes)");vart=newr(e.length);e.copy(t),t=c.reverse(t);varn=128&t[0];returnn?(t[0]&=127,i.fromBuffer(t).neg()):i.fromBuffer(t)};varx=(exports.formatValue=function(e){for(varr=d(e).toString(),t=r.length>8?r.substr(0,r.length-8):"0",n=r.length>8?r.substr(r.length-8):r;n.length<8;)n="0"+n;for(n=n.replace(/0*$/,"");n.length<2;)n+="0";returnt+"."+n},/^\s*(\d+)\.(\d+)/),b=/^\s*\.(\d+)/,m=/^\s*(\d+)/;exports.parseValue=function(e){"string"!=typeofe&&(e=e.toString());varr=e.match(x);returnr?n(r):(r=e.match(b))?o(r):(r=e.match(m),r?f(r):void0)};{varB=(exports.createSynchrotron=function(e){varr={};returnfunction(t){varn=Array.prototype.slice.call(arguments),o=function(){n[0]=function(){r[t]&&(r[t].length?r[t].shift()():deleter[t])},e.apply(null,n)};r[t]?r[t].push(o):(r[t]=[],o())}},exports.decodeDiffBits=function(e,t){e=+e;for(varn=i(16777215&e),o=8*((e>>>24)-3);o-->0;)n=n.mul(2);if(t