(function(f){if(typeofexports==="object"&&typeofmodule!=="undefined"){module.exports=f()}elseif(typeofdefine==="function"&&define.amd){define([],f)}else{varg;if(typeofwindow!=="undefined"){g=window}elseif(typeofglobal!=="undefined"){g=global}elseif(typeofself!=="undefined"){g=self}else{g=this}g.Syndicate=f()}})(function(){vardefine,module,exports;returnfunctione(t,n,r){functions(o,u){if(!n[o]){if(!t[o]){vara=typeofrequire=="function"&&require;if(!u&&a)returna(o,!0);if(i)returni(o,!0);varf=newError("Cannot find module '"+o+"'");throwf.code="MODULE_NOT_FOUND",f}varl=n[o]={exports:{}};t[o][0].call(l.exports,function(e){varn=t[o][1][e];returns(n?n:e)},l,l.exports,e,t,n,r)}returnn[o].exports}vari=typeofrequire=="function"&&require;for(varo=0;o<r.length;o++)s(r[o]);returns}({1:[function(require,module,exports){},{}],2:[function(require,module,exports){(function(global){"use strict";varbase64=require("base64-js");varieee754=require("ieee754");varisArray=require("isarray");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.TYPED_ARRAY_SUPPORT=global.TYPED_ARRAY_SUPPORT!==undefined?global.TYPED_ARRAY_SUPPORT:typedArraySupport();exports.kMaxLength=kMaxLength();functiontypedArraySupport(){try{vararr=newUint8Array(1);arr.__proto__={__proto__:Uint8Array.prototype,foo:function(){return42}};returnarr.foo()===42&&typeofarr.subarray==="function"&&arr.subarray(1,1).byteLength===0}catch(e){returnfalse}}functionkMaxLength(){returnBuffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}functioncreateBuffer(that,length){if(kMaxLength()<length){thrownewRangeError("Invalid typed array length")}if(Buffer.TYPED_ARRAY_SUPPORT){that=newUint8Array(length);that.__proto__=Buffer.prototype}else{if(that===null){that=newBuffer(length)}that.length=length}returnthat}functionBuffer(arg,encodingOrOffset,length){if(!Buffer.TYPED_ARRAY_SUPPORT&&!(thisinstanceofBuffer)){returnnewBuffer(arg,encodingOrOffset,length)}if(typeofarg==="number"){if(typeofencodingOrOffset==="string"){thrownewError("If encoding is specified then the first argument must be a string")}returnallocUnsafe(this,arg)}returnfrom(this,arg,encodingOrOffset,length)}Buffer.poolSize=8192;Buffer._augment=function(arr){arr.__proto__=Buffer.prototype;returnarr};functionfrom(that,value,encodingOrOffset,length){if(typeofvalue==="number"){thrownewTypeError('"value" argument must not be a number')}if(typeofArrayBuffer!=="undefined"&&valueinstanceofArrayBuffer){returnfromArrayBuffer(that,value,encodingOrOffset,length)}if(typeofvalue==="string"){returnfromString(that,value,encodingOrOffset)}returnfromObject(that,value)}Buffer.from=function(value,encodingOrOffset,length){returnfrom(null,value,encodingOrOffset,length)};if(Buffer.TYPED_ARRAY_SUPPORT){Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;if(typeofSymbol!=="undefined"&&Symbol.species&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true})}}functionassertSize(size){if(typeofsize!=="number"){thrownewTypeError('"size" argument must be a number')}elseif(size<0){thrownewRangeError('"size" argument must not be negative')}}functionalloc(that,size,fill,encoding){assertSize(size);if(size<=0){returncreateBuffer(that,size)}if(fill!==undefined){returntypeofencoding==="string"?createBuffer(that,size).fill(fill,encoding):createBuffer(that,size).fill(fill)}returncreateBuffer(that,size)}Buffer.alloc=function(size,fill,encoding){returnalloc(null,size,fill,encoding)};functionallocUnsafe(that,size){assertSize(size);that=createBuffer(that,size<0?0:checked(size)|0);if(!Buffer.TYPED_ARRAY_SUPPORT){for(vari=0;i<size;++i){that[i]=0}}returnthat}Buffer.allocUnsafe=function(size){returnallocUnsafe(null,size)};Buffer.allocUnsafeSlow=function(size){returnallocUnsafe(null,size)};functionfromString(that,string,encoding){if(typeofencoding!=="string"||encoding===""){encoding="utf8"}if(!Buffer.isEncoding(encoding)){thrownewTypeError('"encoding" must be a valid string encoding')}var
}elseif(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}elseif(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}elseif(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{thrownewError("Invalid code point")}}returnbytes}functionasciiToBytes(str){varbyteArray=[];for(vari=0;i<str.length;++i){byteArray.push(str.charCodeAt(i)&255)}returnbyteArray}functionutf16leToBytes(str,units){varc,hi,lo;varbyteArray=[];for(vari=0;i<str.length;++i){if((units-=2)<0)break;c=str.charCodeAt(i);hi=c>>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}returnbyteArray}functionbase64ToBytes(str){returnbase64.toByteArray(base64clean(str))}functionblitBuffer(src,dst,offset,length){for(vari=0;i<length;++i){if(i+offset>=dst.length||i>=src.length)break;dst[i+offset]=src[i]}returni}functionisnan(val){returnval!==val}}).call(this,typeofglobal!=="undefined"?global:typeofself!=="undefined"?self:typeofwindow!=="undefined"?window:{})},{"base64-js":3,ieee754:4,isarray:5}],3:[function(require,module,exports){"use strict";exports.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;varlookup=[];varrevLookup=[];varArr=typeofUint8Array!=="undefined"?Uint8Array:Array;varcode="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(vari=0,len=code.length;i<len;++i){lookup[i]=code[i];revLookup[code.charCodeAt(i)]=i}revLookup["-".charCodeAt(0)]=62;revLookup["_".charCodeAt(0)]=63;functionplaceHoldersCount(b64){varlen=b64.length;if(len%4>0){thrownewError("Invalid string. Length must be a multiple of 4")}returnb64[len-2]==="="?2:b64[len-1]==="="?1:0}functionbyteLength(b64){returnb64.length*3/4-placeHoldersCount(b64)}functiontoByteArray(b64){vari,j,l,tmp,placeHolders,arr;varlen=b64.length;placeHolders=placeHoldersCount(b64);arr=newArr(len*3/4-placeHolders);l=placeHolders>0?len-4:len;varL=0;for(i=0,j=0;i<l;i+=4,j+=3){tmp=revLookup[b64.charCodeAt(i)]<<18|revLookup[b64.charCodeAt(i+1)]<<12|revLookup[b64.charCodeAt(i+2)]<<6|revLookup[b64.charCodeAt(i+3)];arr[L++]=tmp>>16&255;arr[L++]=tmp>>8&255;arr[L++]=tmp&255}if(placeHolders===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[L++]=tmp&255}elseif(placeHolders===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[L++]=tmp>>8&255;arr[L++]=tmp&255}returnarr}functiontripletToBase64(num){returnlookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}functionencodeChunk(uint8,start,end){vartmp;varoutput=[];for(vari=start;i<end;i+=3){tmp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2];output.push(tripletToBase64(tmp))}returnoutput.join("")}functionfromByteArray(uint8){vartmp;varlen=uint8.length;varextraBytes=len%3;varoutput="";varparts=[];varmaxChunkLength=16383;for(vari=0,len2=len-extraBytes;i<len2;i+=maxChunkLength){parts.push(encodeChunk(uint8,i,i+maxChunkLength>len2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];output+=lookup[tmp>>2];output+=lookup[tmp<<4&63];output+="=="}elseif(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];output+=lookup[tmp>>10];output+=lookup[tmp>>4&63];output+=lookup[tmp<<2&63];output+="="}parts.push(output);returnparts.join("")}},{}],4:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){vare,m;vareLen=nBytes*8-mLen-1;vareMax=(1<<eLen)-1;vareBias=eMax>>1;varnBits=-7;vari=isLE?nBytes-1:0;vard=isLE?-1:1;vars=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}elseif(e===eMax){returnm?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){vare,m,c;vareLen=nBytes*8-mLen-1;vareMax=(1<<eLen)-1;
varTransform=require("cipher-base");varinherits=require("inherits");inherits(StreamCipher,Transform);module.exports=StreamCipher;functionStreamCipher(mode,key,iv,decrypt){if(!(thisinstanceofStreamCipher)){returnnewStreamCipher(mode,key,iv)}Transform.call(this);this._cipher=newaes.AES(key);this._prev=newBuffer(iv.length);this._cache=newBuffer("");this._secCache=newBuffer("");this._decrypt=decrypt;iv.copy(this._prev);this._mode=mode}StreamCipher.prototype._update=function(chunk){returnthis._mode.encrypt(this,chunk,this._decrypt)};StreamCipher.prototype._final=function(){this._cipher.scrub()}}).call(this,require("buffer").Buffer)},{"./aes":8,buffer:2,"cipher-base":23,inherits:200}],25:[function(require,module,exports){(function(Buffer){varCipherBase=require("cipher-base");vardes=require("des.js");varinherits=require("inherits");varmodes={"des-ede3-cbc":des.CBC.instantiate(des.EDE),"des-ede3":des.EDE,"des-ede-cbc":des.CBC.instantiate(des.EDE),"des-ede":des.EDE,"des-cbc":des.CBC.instantiate(des.DES),"des-ecb":des.DES};modes.des=modes["des-cbc"];modes.des3=modes["des-ede3-cbc"];module.exports=DES;inherits(DES,CipherBase);functionDES(opts){CipherBase.call(this);varmodeName=opts.mode.toLowerCase();varmode=modes[modeName];vartype;if(opts.decrypt){type="decrypt"}else{type="encrypt"}varkey=opts.key;if(modeName==="des-ede"||modeName==="des-ede-cbc"){key=Buffer.concat([key,key.slice(0,8)])}variv=opts.iv;this._des=mode.create({key:key,iv:iv,type:type})}DES.prototype._update=function(data){returnnewBuffer(this._des.update(data))};DES.prototype._final=function(){returnnewBuffer(this._des.final())}}).call(this,require("buffer").Buffer)},{buffer:2,"cipher-base":27,"des.js":28,inherits:200}],26:[function(require,module,exports){exports["des-ecb"]={key:8,iv:0};exports["des-cbc"]=exports.des={key:8,iv:8};exports["des-ede3-cbc"]=exports.des3={key:24,iv:8};exports["des-ede3"]={key:24,iv:0};exports["des-ede-cbc"]={key:16,iv:8};exports["des-ede"]={key:16,iv:0}},{}],27:[function(require,module,exports){arguments[4][23][0].apply(exports,arguments)},{buffer:2,dup:23,inherits:200,stream:219,string_decoder:220}],28:[function(require,module,exports){"use strict";exports.utils=require("./des/utils");exports.Cipher=require("./des/cipher");exports.DES=require("./des/des");exports.CBC=require("./des/cbc");exports.EDE=require("./des/ede")},{"./des/cbc":29,"./des/cipher":30,"./des/des":31,"./des/ede":32,"./des/utils":33}],29:[function(require,module,exports){"use strict";varassert=require("minimalistic-assert");varinherits=require("inherits");varproto={};functionCBCState(iv){assert.equal(iv.length,8,"Invalid IV length");this.iv=newArray(8);for(vari=0;i<this.iv.length;i++)this.iv[i]=iv[i]}functioninstantiate(Base){functionCBC(options){Base.call(this,options);this._cbcInit()}inherits(CBC,Base);varkeys=Object.keys(proto);for(vari=0;i<keys.length;i++){varkey=keys[i];CBC.prototype[key]=proto[key]}CBC.create=functioncreate(options){returnnewCBC(options)};returnCBC}exports.instantiate=instantiate;proto._cbcInit=function_cbcInit(){varstate=newCBCState(this.options.iv);this._cbcState=state};proto._update=function_update(inp,inOff,out,outOff){varstate=this._cbcState;varsuperProto=this.constructor.super_.prototype;variv=state.iv;if(this.type==="encrypt"){for(vari=0;i<this.blockSize;i++)iv[i]^=inp[inOff+i];superProto._update.call(this,iv,0,out,outOff);for(vari=0;i<this.blockSize;i++)iv[i]=out[outOff+i]}else{superProto._update.call(this,inp,inOff,out,outOff);for(vari=0;i<this.blockSize;i++)out[outOff+i]^=iv[i];for(vari=0;i<this.blockSize;i++)iv[i]=inp[inOff+i]}}},{inherits:200,"minimalistic-assert":34}],30:[function(require,module,exports){"use strict";varassert=require("minimalistic-assert");functionCipher(options){this.options=options;this.type=this.options.type;this.blockSize=8;this._init();this.buffer=newArray(this.blockSize);this.bufferOff=0}module.exports=Cipher;Cipher.prototype._init=function_init(){};Cipher.prototype.update=functionupdate(data){if(data.length===0)return[];if(this.type==="decrypt")returnt
this.red=ctx;returnthis};BN.prototype.forceRed=functionforceRed(ctx){assert(!this.red,"Already a number in reduction context");returnthis._forceRed(ctx)};BN.prototype.redAdd=functionredAdd(num){assert(this.red,"redAdd works only with red numbers");returnthis.red.add(this,num)};BN.prototype.redIAdd=functionredIAdd(num){assert(this.red,"redIAdd works only with red numbers");returnthis.red.iadd(this,num)};BN.prototype.redSub=functionredSub(num){assert(this.red,"redSub works only with red numbers");returnthis.red.sub(this,num)};BN.prototype.redISub=functionredISub(num){assert(this.red,"redISub works only with red numbers");returnthis.red.isub(this,num)};BN.prototype.redShl=functionredShl(num){assert(this.red,"redShl works only with red numbers");returnthis.red.shl(this,num)};BN.prototype.redMul=functionredMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);returnthis.red.mul(this,num)};BN.prototype.redIMul=functionredIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);returnthis.red.imul(this,num)};BN.prototype.redSqr=functionredSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);returnthis.red.sqr(this)};BN.prototype.redISqr=functionredISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);returnthis.red.isqr(this)};BN.prototype.redSqrt=functionredSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);returnthis.red.sqrt(this)};BN.prototype.redInvm=functionredInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);returnthis.red.invm(this)};BN.prototype.redNeg=functionredNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);returnthis.red.neg(this)};BN.prototype.redPow=functionredPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);returnthis.red.pow(this,num)};varprimes={k256:null,p224:null,p192:null,p25519:null};functionMPrime(name,p){this.name=name;this.p=newBN(p,16);this.n=this.p.bitLength();this.k=newBN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function_tmp(){vartmp=newBN(null);tmp.words=newArray(Math.ceil(this.n/13));returntmp};MPrime.prototype.ireduce=functionireduce(num){varr=num;varrlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);varcmp=rlen<this.n?-1:r.ucmp(this.p);if(cmp===0){r.words[0]=0;r.length=1}elseif(cmp>0){r.isub(this.p)}else{r.strip()}returnr};MPrime.prototype.split=functionsplit(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=functionimulK(num){returnnum.imul(this.k)};functionK256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=functionsplit(input,output){varmask=4194303;varoutLen=Math.min(input.length,9);for(vari=0;i<outLen;i++){output.words[i]=input.words[i]}output.length=outLen;if(input.length<=9){input.words[0]=0;input.length=1;return}varprev=input.words[9];output.words[output.length++]=prev&mask;for(i=10;i<input.length;i++){varnext=input.words[i]|0;input.words[i-10]=(next&mask)<<4|prev>>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=functionimulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;varlo=0;for(vari=0;i<num.length;i++){varw=num.words[i]|0;lo+=w*977;num.words[i]=lo&67108863;lo=w*64+(lo/67108864|0)}if(num.words[num.length-1]===0){num.length--;if(num.words[num.length-1]===0){num.length--}}returnnum};functionP224(){MPrime.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}inherits(P224,MPrime);functionP192(){MPrime.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}inherits(P192,MPrime);functionP25519(){MPrime.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}inherits(P25519,MPri
varnpoints=this._endoWnafT1;varncoeffs=this._endoWnafT2;for(vari=0;i<points.length;i++){varsplit=this._endoSplit(coeffs[i]);varp=points[i];varbeta=p._getBeta();if(split.k1.negative){split.k1.ineg();p=p.neg(true)}if(split.k2.negative){split.k2.ineg();beta=beta.neg(true)}npoints[i*2]=p;npoints[i*2+1]=beta;ncoeffs[i*2]=split.k1;ncoeffs[i*2+1]=split.k2}varres=this._wnafMulAdd(1,npoints,ncoeffs,i*2,jacobianResult);for(varj=0;j<i*2;j++){npoints[j]=null;ncoeffs[j]=null}returnres};functionPoint(curve,x,y,isRed){Base.BasePoint.call(this,curve,"affine");if(x===null&&y===null){this.x=null;this.y=null;this.inf=true}else{this.x=newBN(x,16);this.y=newBN(y,16);if(isRed){this.x.forceRed(this.curve.red);this.y.forceRed(this.curve.red)}if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);this.inf=false}}inherits(Point,Base.BasePoint);ShortCurve.prototype.point=functionpoint(x,y,isRed){returnnewPoint(this,x,y,isRed)};ShortCurve.prototype.pointFromJSON=functionpointFromJSON(obj,red){returnPoint.fromJSON(this,obj,red)};Point.prototype._getBeta=function_getBeta(){if(!this.curve.endo)return;varpre=this.precomputed;if(pre&&pre.beta)returnpre.beta;varbeta=this.curve.point(this.x.redMul(this.curve.endo.beta),this.y);if(pre){varcurve=this.curve;varendoMul=function(p){returncurve.point(p.x.redMul(curve.endo.beta),p.y)};pre.beta=beta;beta.precomputed={beta:null,naf:pre.naf&&{wnd:pre.naf.wnd,points:pre.naf.points.map(endoMul)},doubles:pre.doubles&&{step:pre.doubles.step,points:pre.doubles.points.map(endoMul)}}}returnbeta};Point.prototype.toJSON=functiontoJSON(){if(!this.precomputed)return[this.x,this.y];return[this.x,this.y,this.precomputed&&{doubles:this.precomputed.doubles&&{step:this.precomputed.doubles.step,points:this.precomputed.doubles.points.slice(1)},naf:this.precomputed.naf&&{wnd:this.precomputed.naf.wnd,points:this.precomputed.naf.points.slice(1)}}]};Point.fromJSON=functionfromJSON(curve,obj,red){if(typeofobj==="string")obj=JSON.parse(obj);varres=curve.point(obj[0],obj[1],red);if(!obj[2])returnres;functionobj2point(obj){returncurve.point(obj[0],obj[1],red)}varpre=obj[2];res.precomputed={beta:null,doubles:pre.doubles&&{step:pre.doubles.step,points:[res].concat(pre.doubles.points.map(obj2point))},naf:pre.naf&&{wnd:pre.naf.wnd,points:[res].concat(pre.naf.points.map(obj2point))}};returnres};Point.prototype.inspect=functioninspect(){if(this.isInfinity())return"<EC Point Infinity>";return"<EC Point x: "+this.x.fromRed().toString(16,2)+" y: "+this.y.fromRed().toString(16,2)+">"};Point.prototype.isInfinity=functionisInfinity(){returnthis.inf};Point.prototype.add=functionadd(p){if(this.inf)returnp;if(p.inf)returnthis;if(this.eq(p))returnthis.dbl();if(this.neg().eq(p))returnthis.curve.point(null,null);if(this.x.cmp(p.x)===0)returnthis.curve.point(null,null);varc=this.y.redSub(p.y);if(c.cmpn(0)!==0)c=c.redMul(this.x.redSub(p.x).redInvm());varnx=c.redSqr().redISub(this.x).redISub(p.x);varny=c.redMul(this.x.redSub(nx)).redISub(this.y);returnthis.curve.point(nx,ny)};Point.prototype.dbl=functiondbl(){if(this.inf)returnthis;varys1=this.y.redAdd(this.y);if(ys1.cmpn(0)===0)returnthis.curve.point(null,null);vara=this.curve.a;varx2=this.x.redSqr();vardyinv=ys1.redInvm();varc=x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);varnx=c.redSqr().redISub(this.x.redAdd(this.x));varny=c.redMul(this.x.redSub(nx)).redISub(this.y);returnthis.curve.point(nx,ny)};Point.prototype.getX=functiongetX(){returnthis.x.fromRed()};Point.prototype.getY=functiongetY(){returnthis.y.fromRed()};Point.prototype.mul=functionmul(k){k=newBN(k,16);if(this._hasDoubles(k))returnthis.curve._fixedNafMul(this,k);elseif(this.curve.endo)returnthis.curve._endoWnafMulAdd([this],[k]);elsereturnthis.curve._wnafMul(this,k)};Point.prototype.mulAdd=functionmulAdd(k1,p2,k2){varpoints=[this,p2];varcoeffs=[k1,k2];if(this.curve.endo)returnthis.curve._endoWnafMulAdd(points,coeffs);elsereturnthis.curve._wnafMulAdd(1,points,coeffs,2)};Point.prototype.jmulAdd=functionjmulAdd(k1,p2,k2){va
});cachedProperty(Signature,"Rencoded",functionRencoded(){returnthis.eddsa.encodePoint(this.R())});cachedProperty(Signature,"Sencoded",functionSencoded(){returnthis.eddsa.encodeInt(this.S())});Signature.prototype.toBytes=functiontoBytes(){returnthis.Rencoded().concat(this.Sencoded())};Signature.prototype.toHex=functiontoHex(){returnutils.encode(this.toBytes(),"hex").toUpperCase()};module.exports=Signature},{"../../elliptic":41,"bn.js":39}],54:[function(require,module,exports){"use strict";varhash=require("hash.js");varelliptic=require("../elliptic");varutils=elliptic.utils;varassert=utils.assert;functionHmacDRBG(options){if(!(thisinstanceofHmacDRBG))returnnewHmacDRBG(options);this.hash=options.hash;this.predResist=!!options.predResist;this.outLen=this.hash.outSize;this.minEntropy=options.minEntropy||this.hash.hmacStrength;this.reseed=null;this.reseedInterval=null;this.K=null;this.V=null;varentropy=utils.toArray(options.entropy,options.entropyEnc);varnonce=utils.toArray(options.nonce,options.nonceEnc);varpers=utils.toArray(options.pers,options.persEnc);assert(entropy.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._init(entropy,nonce,pers)}module.exports=HmacDRBG;HmacDRBG.prototype._init=functioninit(entropy,nonce,pers){varseed=entropy.concat(nonce).concat(pers);this.K=newArray(this.outLen/8);this.V=newArray(this.outLen/8);for(vari=0;i<this.V.length;i++){this.K[i]=0;this.V[i]=1}this._update(seed);this.reseed=1;this.reseedInterval=281474976710656};HmacDRBG.prototype._hmac=functionhmac(){returnnewhash.hmac(this.hash,this.K)};HmacDRBG.prototype._update=functionupdate(seed){varkmac=this._hmac().update(this.V).update([0]);if(seed)kmac=kmac.update(seed);this.K=kmac.digest();this.V=this._hmac().update(this.V).digest();if(!seed)return;this.K=this._hmac().update(this.V).update([1]).update(seed).digest();this.V=this._hmac().update(this.V).digest()};HmacDRBG.prototype.reseed=functionreseed(entropy,entropyEnc,add,addEnc){if(typeofentropyEnc!=="string"){addEnc=add;add=entropyEnc;entropyEnc=null}entropy=utils.toBuffer(entropy,entropyEnc);add=utils.toBuffer(add,addEnc);assert(entropy.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._update(entropy.concat(add||[]));this.reseed=1};HmacDRBG.prototype.generate=functiongenerate(len,enc,add,addEnc){if(this.reseed>this.reseedInterval)thrownewError("Reseed is required");if(typeofenc!=="string"){addEnc=add;add=enc;enc=null}if(add){add=utils.toArray(add,addEnc);this._update(add)}vartemp=[];while(temp.length<len){this.V=this._hmac().update(this.V).digest();temp=temp.concat(this.V)}varres=temp.slice(0,len);this._update(add);this.reseed++;returnutils.encode(res,enc)}},{"../elliptic":41,"hash.js":58}],55:[function(require,module,exports){module.exports={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],[
"./withPublic":196,"./xor":197,"bn.js":155,"browserify-rsa":156,buffer:2,"create-hash":130,"parse-asn1":160,randombytes:198}],196:[function(require,module,exports){(function(Buffer){varbn=require("bn.js");functionwithPublic(paddedMsg,key){returnnewBuffer(paddedMsg.toRed(bn.mont(key.modulus)).redPow(newbn(key.publicExponent)).fromRed().toArray())}module.exports=withPublic}).call(this,require("buffer").Buffer)},{"bn.js":155,buffer:2}],197:[function(require,module,exports){module.exports=functionxor(a,b){varlen=a.length;vari=-1;while(++i<len){a[i]^=b[i]}returna}},{}],198:[function(require,module,exports){(function(process,global,Buffer){"use strict";functionoldBrowser(){thrownewError("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11")}varcrypto=global.crypto||global.msCrypto;if(crypto&&crypto.getRandomValues){module.exports=randomBytes}else{module.exports=oldBrowser}functionrandomBytes(size,cb){if(size>65536)thrownewError("requested too many random bytes");varrawBytes=newglobal.Uint8Array(size);if(size>0){crypto.getRandomValues(rawBytes)}varbytes=newBuffer(rawBytes.buffer);if(typeofcb==="function"){returnprocess.nextTick(function(){cb(null,bytes)})}returnbytes}}).call(this,require("_process"),typeofglobal!=="undefined"?global:typeofself!=="undefined"?self:typeofwindow!=="undefined"?window:{},require("buffer").Buffer)},{_process:202,buffer:2}],199:[function(require,module,exports){functionEventEmitter(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}module.exports=EventEmitter;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._maxListeners=undefined;EventEmitter.defaultMaxListeners=10;EventEmitter.prototype.setMaxListeners=function(n){if(!isNumber(n)||n<0||isNaN(n))throwTypeError("n must be a positive number");this._maxListeners=n;returnthis};EventEmitter.prototype.emit=function(type){varer,handler,len,args,i,listeners;if(!this._events)this._events={};if(type==="error"){if(!this._events.error||isObject(this._events.error)&&!this._events.error.length){er=arguments[1];if(erinstanceofError){thrower}else{varerr=newError('Uncaught, unspecified "error" event. ('+er+")");err.context=er;throwerr}}}handler=this._events[type];if(isUndefined(handler))returnfalse;if(isFunction(handler)){switch(arguments.length){case1:handler.call(this);break;case2:handler.call(this,arguments[1]);break;case3:handler.call(this,arguments[1],arguments[2]);break;default:args=Array.prototype.slice.call(arguments,1);handler.apply(this,args)}}elseif(isObject(handler)){args=Array.prototype.slice.call(arguments,1);listeners=handler.slice();len=listeners.length;for(i=0;i<len;i++)listeners[i].apply(this,args)}returntrue};EventEmitter.prototype.addListener=function(type,listener){varm;if(!isFunction(listener))throwTypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",type,isFunction(listener.listener)?listener.listener:listener);if(!this._events[type])this._events[type]=listener;elseif(isObject(this._events[type]))this._events[type].push(listener);elsethis._events[type]=[this._events[type],listener];if(isObject(this._events[type])&&!this._events[type].warned){if(!isUndefined(this._maxListeners)){m=this._maxListeners}else{m=EventEmitter.defaultMaxListeners}if(m&&m>0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeofconsole.trace==="function"){console.trace()}}}returnthis};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throwTypeError("listener must be a function");varfired=false;functiong(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);returnthis};Eve
returnnewWritable(options)}this._writableState=newWritableState(options,this);this.writable=true;if(options){if(typeofoptions.write==="function")this._write=options.write;if(typeofoptions.writev==="function")this._writev=options.writev}Stream.call(this)}Writable.prototype.pipe=function(){this.emit("error",newError("Cannot pipe, not readable"))};functionwriteAfterEnd(stream,cb){varer=newError("write after end");stream.emit("error",er);processNextTick(cb,er)}functionvalidChunk(stream,state,chunk,cb){varvalid=true;varer=false;if(chunk===null){er=newTypeError("May not write null values to stream")}elseif(!Buffer.isBuffer(chunk)&&typeofchunk!=="string"&&chunk!==undefined&&!state.objectMode){er=newTypeError("Invalid non-string/buffer chunk")}if(er){stream.emit("error",er);processNextTick(cb,er);valid=false}returnvalid}Writable.prototype.write=function(chunk,encoding,cb){varstate=this._writableState;varret=false;if(typeofencoding==="function"){cb=encoding;encoding=null}if(Buffer.isBuffer(chunk))encoding="buffer";elseif(!encoding)encoding=state.defaultEncoding;if(typeofcb!=="function")cb=nop;if(state.ended)writeAfterEnd(this,cb);elseif(validChunk(this,state,chunk,cb)){state.pendingcb++;ret=writeOrBuffer(this,state,chunk,encoding,cb)}returnret};Writable.prototype.cork=function(){varstate=this._writableState;state.corked++};Writable.prototype.uncork=function(){varstate=this._writableState;if(state.corked){state.corked--;if(!state.writing&&!state.corked&&!state.finished&&!state.bufferProcessing&&state.bufferedRequest)clearBuffer(this,state)}};Writable.prototype.setDefaultEncoding=functionsetDefaultEncoding(encoding){if(typeofencoding==="string")encoding=encoding.toLowerCase();if(!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((encoding+"").toLowerCase())>-1))thrownewTypeError("Unknown encoding: "+encoding);this._writableState.defaultEncoding=encoding;returnthis};functiondecodeChunk(state,chunk,encoding){if(!state.objectMode&&state.decodeStrings!==false&&typeofchunk==="string"){chunk=bufferShim.from(chunk,encoding)}returnchunk}functionwriteOrBuffer(stream,state,chunk,encoding,cb){chunk=decodeChunk(state,chunk,encoding);if(Buffer.isBuffer(chunk))encoding="buffer";varlen=state.objectMode?1:chunk.length;state.length+=len;varret=state.length<state.highWaterMark;if(!ret)state.needDrain=true;if(state.writing||state.corked){varlast=state.lastBufferedRequest;state.lastBufferedRequest=newWriteReq(chunk,encoding,cb);if(last){last.next=state.lastBufferedRequest}else{state.bufferedRequest=state.lastBufferedRequest}state.bufferedRequestCount+=1}else{doWrite(stream,state,false,len,chunk,encoding,cb)}returnret}functiondoWrite(stream,state,writev,len,chunk,encoding,cb){state.writelen=len;state.writecb=cb;state.writing=true;state.sync=true;if(writev)stream._writev(chunk,state.onwrite);elsestream._write(chunk,encoding,state.onwrite);state.sync=false}functiononwriteError(stream,state,sync,er,cb){--state.pendingcb;if(sync)processNextTick(cb,er);elsecb(er);stream._writableState.errorEmitted=true;stream.emit("error",er)}functiononwriteStateUpdate(state){state.writing=false;state.writecb=null;state.length-=state.writelen;state.writelen=0}functiononwrite(stream,er){varstate=stream._writableState;varsync=state.sync;varcb=state.writecb;onwriteStateUpdate(state);if(er)onwriteError(stream,state,sync,er,cb);else{varfinished=needFinish(state);if(!finished&&!state.corked&&!state.bufferProcessing&&state.bufferedRequest){clearBuffer(stream,state)}if(sync){asyncWrite(afterWrite,stream,state,finished,cb)}else{afterWrite(stream,state,finished,cb)}}}functionafterWrite(stream,state,finished,cb){if(!finished)onwriteDrain(stream,state);state.pendingcb--;cb();finishMaybe(stream,state)}functiononwriteDrain(stream,state){if(state.length===0&&state.needDrain){state.needDrain=false;stream.emit("drain")}}functionclearBuffer(stream,state){state.bufferProcessing=true;varentry=state.bufferedRequest;if(stream._writev&&entry&&entry.next){varl=state.bufferedRequestCount;varbu
cache[iterations]=val;if(fn(val,iterations++,this)===false){break}}returniterations};IteratorSeq.prototype.__iteratorUncached=function(type,reverse){if(reverse){returnthis.cacheResult().__iterator(type,reverse)}variterator=this._iterator;varcache=this._iteratorCache;variterations=0;returnnewIterator(function(){if(iterations>=cache.length){varstep=iterator.next();if(step.done){returnstep}cache[iterations]=step.value}returniteratorValue(type,iterations,cache[iterations++])})};functionisSeq(maybeSeq){return!!(maybeSeq&&maybeSeq[IS_SEQ_SENTINEL])}varEMPTY_SEQ;functionemptySequence(){returnEMPTY_SEQ||(EMPTY_SEQ=newArraySeq([]))}functionkeyedSeqFromValue(value){varseq=Array.isArray(value)?newArraySeq(value).fromEntrySeq():isIterator(value)?newIteratorSeq(value).fromEntrySeq():hasIterator(value)?newIterableSeq(value).fromEntrySeq():typeofvalue==="object"?newObjectSeq(value):undefined;if(!seq){thrownewTypeError("Expected Array or iterable object of [k, v] entries, "+"or keyed object: "+value)}returnseq}functionindexedSeqFromValue(value){varseq=maybeIndexedSeqFromValue(value);if(!seq){thrownewTypeError("Expected Array or iterable object of values: "+value)}returnseq}functionseqFromValue(value){varseq=maybeIndexedSeqFromValue(value)||typeofvalue==="object"&&newObjectSeq(value);if(!seq){thrownewTypeError("Expected Array or iterable object of values, or keyed object: "+value)}returnseq}functionmaybeIndexedSeqFromValue(value){returnisArrayLike(value)?newArraySeq(value):isIterator(value)?newIteratorSeq(value):hasIterator(value)?newIterableSeq(value):undefined}functionseqIterate(seq,fn,reverse,useKeys){varcache=seq._cache;if(cache){varmaxIndex=cache.length-1;for(varii=0;ii<=maxIndex;ii++){varentry=cache[reverse?maxIndex-ii:ii];if(fn(entry[1],useKeys?entry[0]:ii,seq)===false){returnii+1}}returnii}returnseq.__iterateUncached(fn,reverse)}functionseqIterator(seq,type,reverse,useKeys){varcache=seq._cache;if(cache){varmaxIndex=cache.length-1;varii=0;returnnewIterator(function(){varentry=cache[reverse?maxIndex-ii:ii];returnii++>maxIndex?iteratorDone():iteratorValue(type,useKeys?entry[0]:ii-1,entry[1])})}returnseq.__iteratorUncached(type,reverse)}functionfromJS(json,converter){returnconverter?fromJSWith(converter,json,"",{"":json}):fromJSDefault(json)}functionfromJSWith(converter,json,key,parentJSON){if(Array.isArray(json)){returnconverter.call(parentJSON,key,IndexedSeq(json).map(function(v,k){returnfromJSWith(converter,v,k,json)}))}if(isPlainObj(json)){returnconverter.call(parentJSON,key,KeyedSeq(json).map(function(v,k){returnfromJSWith(converter,v,k,json)}))}returnjson}functionfromJSDefault(json){if(Array.isArray(json)){returnIndexedSeq(json).map(fromJSDefault).toList()}if(isPlainObj(json)){returnKeyedSeq(json).map(fromJSDefault).toMap()}returnjson}functionisPlainObj(value){returnvalue&&(value.constructor===Object||value.constructor===undefined)}functionis(valueA,valueB){if(valueA===valueB||valueA!==valueA&&valueB!==valueB){returntrue}if(!valueA||!valueB){returnfalse}if(typeofvalueA.valueOf==="function"&&typeofvalueB.valueOf==="function"){valueA=valueA.valueOf();valueB=valueB.valueOf();if(valueA===valueB||valueA!==valueA&&valueB!==valueB){returntrue}if(!valueA||!valueB){returnfalse}}if(typeofvalueA.equals==="function"&&typeofvalueB.equals==="function"&&valueA.equals(valueB)){returntrue}returnfalse}functiondeepEqual(a,b){if(a===b){returntrue}if(!isIterable(b)||a.size!==undefined&&b.size!==undefined&&a.size!==b.size||a.__hash!==undefined&&b.__hash!==undefined&&a.__hash!==b.__hash||isKeyed(a)!==isKeyed(b)||isIndexed(a)!==isIndexed(b)||isOrdered(a)!==isOrdered(b)){returnfalse}if(a.size===0&&b.size===0){returntrue}varnotAssociative=!isAssociative(a);if(isOrdered(a)){varentries=a.entries();returnb.every(function(v,k){varentry=entries.next().value;returnentry&&is(entry[1],v)&&(notAssociative||is(entry[0],k))})&&entries.next().done}varflipped=false;if(a.size===undefined){if(b.size===undefined){if(typeofa.cacheResult==="function"){a.cacheResult()}}else{fli
returnrecord}functionrecordName(record){returnrecord._name||record.constructor.name||"Record"}functionsetProps(prototype,names){try{names.forEach(setProp.bind(undefined,prototype))}catch(error){}}functionsetProp(prototype,name){Object.defineProperty(prototype,name,{get:function(){returnthis.get(name)},set:function(value){invariant(this.__ownerID,"Cannot set on an immutable record.");this.set(name,value)}})}createClass(Set,SetCollection);functionSet(value){returnvalue===null||value===undefined?emptySet():isSet(value)&&!isOrdered(value)?value:emptySet().withMutations(function(set){variter=SetIterable(value);assertNotInfinite(iter.size);iter.forEach(function(v){returnset.add(v)})})}Set.of=function(){returnthis(arguments)};Set.fromKeys=function(value){returnthis(KeyedIterable(value).keySeq())};Set.prototype.toString=function(){returnthis.__toString("Set {","}")};Set.prototype.has=function(value){returnthis._map.has(value)};Set.prototype.add=function(value){returnupdateSet(this,this._map.set(value,true))};Set.prototype.remove=function(value){returnupdateSet(this,this._map.remove(value))};Set.prototype.clear=function(){returnupdateSet(this,this._map.clear())};Set.prototype.union=function(){variters=SLICE$0.call(arguments,0);iters=iters.filter(function(x){returnx.size!==0});if(iters.length===0){returnthis}if(this.size===0&&!this.__ownerID&&iters.length===1){returnthis.constructor(iters[0])}returnthis.withMutations(function(set){for(varii=0;ii<iters.length;ii++){SetIterable(iters[ii]).forEach(function(value){returnset.add(value)})}})};Set.prototype.intersect=function(){variters=SLICE$0.call(arguments,0);if(iters.length===0){returnthis}iters=iters.map(function(iter){returnSetIterable(iter)});varoriginalSet=this;returnthis.withMutations(function(set){originalSet.forEach(function(value){if(!iters.every(function(iter){returniter.includes(value)})){set.remove(value)}})})};Set.prototype.subtract=function(){variters=SLICE$0.call(arguments,0);if(iters.length===0){returnthis}iters=iters.map(function(iter){returnSetIterable(iter)});varoriginalSet=this;returnthis.withMutations(function(set){originalSet.forEach(function(value){if(iters.some(function(iter){returniter.includes(value)})){set.remove(value)}})})};Set.prototype.merge=function(){returnthis.union.apply(this,arguments)};Set.prototype.mergeWith=function(merger){variters=SLICE$0.call(arguments,1);returnthis.union.apply(this,iters)};Set.prototype.sort=function(comparator){returnOrderedSet(sortFactory(this,comparator))};Set.prototype.sortBy=function(mapper,comparator){returnOrderedSet(sortFactory(this,comparator,mapper))};Set.prototype.wasAltered=function(){returnthis._map.wasAltered()};Set.prototype.__iterate=function(fn,reverse){varthis$0=this;returnthis._map.__iterate(function(_,k){returnfn(k,k,this$0)},reverse)};Set.prototype.__iterator=function(type,reverse){returnthis._map.map(function(_,k){returnk}).__iterator(type,reverse)};Set.prototype.__ensureOwner=function(ownerID){if(ownerID===this.__ownerID){returnthis}varnewMap=this._map.__ensureOwner(ownerID);if(!ownerID){this.__ownerID=ownerID;this._map=newMap;returnthis}returnthis.__make(newMap,ownerID)};functionisSet(maybeSet){return!!(maybeSet&&maybeSet[IS_SET_SENTINEL])}Set.isSet=isSet;varIS_SET_SENTINEL="@@__IMMUTABLE_SET__@@";varSetPrototype=Set.prototype;SetPrototype[IS_SET_SENTINEL]=true;SetPrototype[DELETE]=SetPrototype.remove;SetPrototype.mergeDeep=SetPrototype.merge;SetPrototype.mergeDeepWith=SetPrototype.mergeWith;SetPrototype.withMutations=MapPrototype.withMutations;SetPrototype.asMutable=MapPrototype.asMutable;SetPrototype.asImmutable=MapPrototype.asImmutable;SetPrototype.__empty=emptySet;SetPrototype.__make=makeSet;functionupdateSet(set,newMap){if(set.__ownerID){set.size=newMap.size;set._map=newMap;returnset}returnnewMap===set._map?set:newMap.size===0?set.__empty():set.__make(newMap)}functionmakeSet(map,ownerID){varset=Object.create(SetPrototype);set.size=map?map.size:0;set._map=map;set.__ownerID=ownerID;returnset}varEMPTY_SET;functionemptySet(){returnEMPTY_S
226:[function(require,module,exports){"use strict";varImmutable=require("immutable");varTrie=require("./trie.js");varPatch=require("./patch.js");varStruct=require("./struct.js");varDemandMatcher=require("./demand-matcher.js").DemandMatcher;varCodec=require("./codec");varDataspace_=require("./dataspace.js");varDataspace=Dataspace_.Dataspace;var__=Dataspace_.__;var_$=Dataspace_._$;varDEFAULT_RECONNECT_DELAY=100;varMAX_RECONNECT_DELAY=3e4;varDEFAULT_IDLE_TIMEOUT=3e5;varDEFAULT_PING_INTERVAL=DEFAULT_IDLE_TIMEOUT-1e4;vartoBroker=Struct.makeConstructor("toBroker",["url","assertion"]);varfromBroker=Struct.makeConstructor("fromBroker",["url","assertion"]);varbrokerConnection=Struct.makeConstructor("brokerConnection",["url"]);varbrokerConnected=Struct.makeConstructor("brokerConnected",["url"]);varforceBrokerDisconnect=Struct.makeConstructor("forceBrokerDisconnect",["url"]);functionspawnBrokerClientDriver(){varURL=_$("url");Dataspace.spawn(newDataspace(function(){Dataspace.spawn(newDemandMatcher([brokerConnection(URL)],[brokerConnection(URL)],function(c){Dataspace.spawn(newBrokerClientConnection(c.url))},{demandMetaLevel:1,supplyMetaLevel:0}))}))}functionBrokerClientConnection(wsurl){this.wsurl=wsurl;this.sock=null;this.sendsAttempted=0;this.sendsTransmitted=0;this.receiveCount=0;this.connectionCount=0;this.reconnectDelay=DEFAULT_RECONNECT_DELAY;this.idleTimeout=DEFAULT_IDLE_TIMEOUT;this.pingInterval=DEFAULT_PING_INTERVAL;this.localAssertions=Trie.emptyTrie;this.connectionInterrupted=false;this.activityTimestamp=0;this.idleTimer=null;this.pingTimer=null}BrokerClientConnection.prototype.clearHeartbeatTimers=function(){if(this.idleTimer){clearTimeout(this.idleTimer);this.idleTimer=null}if(this.pingTimer){clearTimeout(this.pingTimer);this.pingTimer=null}};BrokerClientConnection.prototype.recordActivity=function(){varself=this;this.activityTimestamp=+newDate;this.clearHeartbeatTimers();this.idleTimer=setTimeout(function(){self.forceclose()},this.idleTimeout);this.pingTimer=setTimeout(function(){self.safeSend(JSON.stringify("ping"))},this.pingInterval)};BrokerClientConnection.prototype.boot=function(){this.reconnect();varinitialAssertions=Patch.sub(toBroker(this.wsurl,__),1).andThen(Patch.sub(Patch.observe(fromBroker(this.wsurl,__)),1)).andThen(Patch.assert(brokerConnection(this.wsurl))).andThen(Patch.sub(brokerConnection(this.wsurl),1)).andThen(Patch.sub(forceBrokerDisconnect(this.wsurl),1));returninitialAssertions};BrokerClientConnection.prototype.trapexit=function(){this.forceclose()};BrokerClientConnection.prototype.isConnected=function(){returnthis.sock&&this.sock.readyState===this.sock.OPEN};BrokerClientConnection.prototype.safeSend=function(m){try{this.sendsAttempted++;if(this.isConnected()){this.sock.send(m);this.sendsTransmitted++}}catch(e){console.warn("Trapped exn while sending",e)}};BrokerClientConnection.prototype.sendPatch=function(p){varj=JSON.stringify(Codec.encodeEvent(Syndicate.stateChange(p)));this.safeSend(j)};BrokerClientConnection.prototype.handleEvent=function(e){switch(e.type){case"stateChange":if(e.patch.project(Patch.atMeta(brokerConnection(_$))).hasRemoved()){Dataspace.exit()}varpTo=e.patch.project(Patch.atMeta(toBroker(__,_$)));varpObsFrom=e.patch.project(Patch.atMeta(Patch.observe(fromBroker(__,_$))));pObsFrom=newPatch.Patch(Trie.compilePattern(true,Patch.observe(Trie.embeddedTrie(pObsFrom.added))),Trie.compilePattern(true,Patch.observe(Trie.embeddedTrie(pObsFrom.removed))));varnewLocalAssertions=this.localAssertions;newLocalAssertions=pTo.label(Immutable.Set.of("to")).applyTo(newLocalAssertions);newLocalAssertions=pObsFrom.label(Immutable.Set.of("obsFrom")).applyTo(newLocalAssertions);vartrueSet=Immutable.Set.of(true);varalwaysTrueSet=function(v){returntrueSet};varp=Patch.computePatch(Trie.relabel(this.localAssertions,alwaysTrueSet),Trie.relabel(newLocalAssertions,alwaysTrueSet));this.localAssertions=newLocalAssertions;this.sendPatch(p);break;case"message":varm=e.message;if(Patch.atMeta.isClassOf(m)){m=m[0];if(toBroker.isClassOf(m)){varj=JSON.stringify(Codec.encode
}}function_check(p){if(pinstanceofPatch){thrownewError("Cannot construct patch pattern using an embedded patch")}returnp}functionassert(p,metaLevel){returnnewPatch(Trie.compilePattern(true,prependAtMeta(_check(p),metaLevel||0)),Trie.emptyTrie)}functionretract(p,metaLevel){returnnewPatch(Trie.emptyTrie,Trie.compilePattern(true,prependAtMeta(_check(p),metaLevel||0)))}functionsub(p,metaLevel){returnnewPatch(observeAtMeta(_check(p),metaLevel||0),Trie.emptyTrie)}functionunsub(p,metaLevel){returnnewPatch(Trie.emptyTrie,observeAtMeta(_check(p),metaLevel||0))}functionpub(p,metaLevel){returnassert(advertise(_check(p)),metaLevel)}functionunpub(p,metaLevel){returnretract(advertise(_check(p)),metaLevel)}Patch.prototype.equals=function(other){if(!(otherinstanceofPatch))returnfalse;returnImmutable.is(this.added,other.added)&&Immutable.is(this.removed,other.removed)};Patch.prototype.isEmpty=function(){returnthis.added===Trie.emptyTrie&&this.removed===Trie.emptyTrie};Patch.prototype.isNonEmpty=function(){return!this.isEmpty()};Patch.prototype.hasAdded=function(){return!Trie.is_emptyTrie(this.added)};Patch.prototype.hasRemoved=function(){return!Trie.is_emptyTrie(this.removed)};Patch.prototype.lift=function(){returnnewPatch(Trie.compilePattern(true,atMeta(Trie.embeddedTrie(this.added))),Trie.compilePattern(true,atMeta(Trie.embeddedTrie(this.removed))))};varatMetaProj=atMeta(_$);Patch.prototype.drop=function(){returnnewPatch(Trie.project(this.added,atMetaProj),Trie.project(this.removed,atMetaProj))};Patch.prototype.strip=function(){returnnewPatch(Trie.relabel(this.added,function(v){returntrue}),Trie.relabel(this.removed,function(v){returntrue}))};Patch.prototype.label=function(labelValue){returnnewPatch(Trie.relabel(this.added,function(v){returnlabelValue}),Trie.relabel(this.removed,function(v){returnlabelValue}))};Patch.prototype.limit=function(bound){returnnewPatch(Trie.subtract(this.added,bound,function(v1,v2){returnTrie.emptyTrie}),Trie.intersect(this.removed,bound,function(v1,v2){returnTrie.trieSuccess(v1)}))};varmetaLabelSet=Immutable.Set(["meta"]);Patch.prototype.computeAggregate=function(label,base,removeMeta){returnnewPatch(Trie.subtract(this.added,base,addCombiner),Trie.subtract(this.removed,base,removeCombiner));functionaddCombiner(v1,v2){if(removeMeta&&Immutable.is(v2,metaLabelSet)){returnTrie.trieSuccess(v1)}else{returnTrie.emptyTrie}}functionremoveCombiner(v1,v2){if(v2.size===1){returnTrie.trieSuccess(v1)}else{if(removeMeta&&v2.size===2&&v2.has("meta")){returnTrie.trieSuccess(v1)}else{returnTrie.emptyTrie}}}};Patch.prototype.applyTo=function(base){returnTrie._union(Trie.subtract(base,this.removed),this.added)};Patch.prototype.updateInterests=function(base){returnTrie._union(Trie.subtract(base,this.removed,function(v1,v2){returnTrie.emptyTrie}),this.added,function(v1,v2){returntrueLabel})};Patch.prototype.unapplyTo=function(base){returnTrie._union(Trie.subtract(base,this.added),this.removed)};Patch.prototype.andThen=function(nextPatch){returnnewPatch(nextPatch.updateInterests(this.added),Trie._union(Trie.subtract(this.removed,nextPatch.added,function(v1,v2){returnTrie.emptyTrie}),nextPatch.removed,function(v1,v2){returntrueLabel}))};functionpatchSeq(){varp=emptyPatch;for(vari=0;i<arguments.length;i++){p=p.andThen(arguments[i])}returnp}functioncomputePatch(oldBase,newBase){returnnewPatch(Trie.subtract(newBase,oldBase),Trie.subtract(oldBase,newBase))}functionbiasedIntersection(object,subject){subject=Trie.trieStep(subject,observe.meta.arity,observe.meta);returnTrie.intersect(object,subject,function(v1,v2){returnTrie.trieSuccess(v1)})}Patch.prototype.viewFrom=function(interests){returnnewPatch(biasedIntersection(this.added,interests),biasedIntersection(this.removed,interests))};Patch.prototype.unsafeUnion=function(other){returnnewPatch(Trie._union(this.added,other.added),Trie._union(this.removed,other.removed))};Patch.prototype.project=function(compiledProjection){returnnewPatch(Trie.project(this.added,compiledProjection),Trie.project(this.removed,com