@0xpolygonid/js-sdk 1.41.0 → 1.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/esm/index.js +11 -0
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.global.js +3 -3
- package/dist/browser/umd/index.global.js.map +1 -1
- package/dist/node/cjs/index.cjs +11 -0
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.js +11 -0
- package/dist/node/esm/index.js.map +1 -1
- package/dist/types/iden3comm/handlers/common.d.ts.map +1 -1
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts +7 -4
- package/dist/types/iden3comm/types/protocol/contract-request.d.ts.map +1 -1
- package/dist/types/storage/blockchain/onchain-zkp-verifier.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/iden3comm/handlers/common.ts +6 -0
- package/src/iden3comm/types/protocol/contract-request.ts +11 -4
- package/src/storage/blockchain/onchain-zkp-verifier.ts +4 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var PolygonIdSdk=(()=>{var wne=Object.create;var LI=Object.defineProperty;var bne=Object.getOwnPropertyDescriptor;var Ene=Object.getOwnPropertyNames;var Ine=Object.getPrototypeOf,Ane=Object.prototype.hasOwnProperty;var co=(n,e)=>()=>(n&&(e=n(n=0)),e);var oe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Rr=(n,e)=>{for(var t in e)LI(n,t,{get:e[t],enumerable:!0})},fN=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ene(e))!Ane.call(n,i)&&i!==t&&LI(n,i,{get:()=>e[i],enumerable:!(r=bne(e,i))||r.enumerable});return n};var En=(n,e,t)=>(t=n!=null?wne(Ine(n)):{},fN(e||!n||!n.__esModule?LI(t,"default",{value:n,enumerable:!0}):t,n)),$8=n=>fN(LI({},"__esModule",{value:!0}),n);var Y9=oe((Ym,db)=>{"use strict";(function(n,e){"use strict";var t={};n.PubSub?(t=n.PubSub,console.warn("PubSub already loaded, using existing version")):(n.PubSub=t,e(t)),typeof Ym=="object"?(db!==void 0&&db.exports&&(Ym=db.exports=t),Ym.PubSub=t,db.exports=Ym=t):typeof define=="function"&&define.amd&&define(function(){return t})})(typeof window=="object"&&window||Ym||global,function(n){"use strict";var e={},t=-1,r="*";function i(f){var m;for(m in f)if(Object.prototype.hasOwnProperty.call(f,m))return!0;return!1}function o(f){return function(){throw f}}function s(f,m,w){try{f(m,w)}catch(b){setTimeout(o(b),0)}}function a(f,m,w){f(m,w)}function c(f,m,w,b){var S=e[m],R=b?a:s,G;if(Object.prototype.hasOwnProperty.call(e,m))for(G in S)Object.prototype.hasOwnProperty.call(S,G)&&R(S[G],f,w)}function u(f,m,w){return function(){var S=String(f),R=S.lastIndexOf(".");for(c(f,f,m,w);R!==-1;)S=S.substr(0,R),R=S.lastIndexOf("."),c(f,S,m,w);c(f,r,m,w)}}function l(f){var m=String(f),w=!!(Object.prototype.hasOwnProperty.call(e,m)&&i(e[m]));return w}function d(f){for(var m=String(f),w=l(m)||l(r),b=m.lastIndexOf(".");!w&&b!==-1;)m=m.substr(0,b),b=m.lastIndexOf("."),w=l(m);return w}function h(f,m,w,b){f=typeof f=="symbol"?f.toString():f;var S=u(f,m,b),R=d(f);return R?(w===!0?S():setTimeout(S,0),!0):!1}n.publish=function(f,m){return h(f,m,!1,n.immediateExceptions)},n.publishSync=function(f,m){return h(f,m,!0,n.immediateExceptions)},n.subscribe=function(f,m){if(typeof m!="function")return!1;f=typeof f=="symbol"?f.toString():f,Object.prototype.hasOwnProperty.call(e,f)||(e[f]={});var w="uid_"+String(++t);return e[f][w]=m,w},n.subscribeAll=function(f){return n.subscribe(r,f)},n.subscribeOnce=function(f,m){var w=n.subscribe(f,function(){n.unsubscribe(w),m.apply(this,arguments)});return n},n.clearAllSubscriptions=function(){e={}},n.clearSubscriptions=function(m){var w;for(w in e)Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0&&delete e[w]},n.countSubscriptions=function(m){var w,b,S=0;for(w in e)if(Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0){for(b in e[w])S++;break}return S},n.getSubscriptions=function(m){var w,b=[];for(w in e)Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0&&b.push(w);return b},n.unsubscribe=function(f){var m=function(M){var A;for(A in e)if(Object.prototype.hasOwnProperty.call(e,A)&&A.indexOf(M)===0)return!0;return!1},w=typeof f=="string"&&(Object.prototype.hasOwnProperty.call(e,f)||m(f)),b=!w&&typeof f=="string",S=typeof f=="function",R=!1,G,U,H;if(w){n.clearSubscriptions(f);return}for(G in e)if(Object.prototype.hasOwnProperty.call(e,G)){if(U=e[G],b&&U[f]){delete U[f],R=f;break}if(S)for(H in U)Object.prototype.hasOwnProperty.call(U,H)&&U[H]===f&&(delete U[H],R=!0)}return R}})});var j9=oe(()=>{"use strict"});var NR=oe((W9,FR)=>{"use strict";(function(n,e){"use strict";function t(v,p){if(!v)throw new Error(p||"Assertion failed")}function r(v,p){v.super_=p;var x=function(){};x.prototype=p.prototype,v.prototype=new x,v.prototype.constructor=v}function i(v,p,x){if(i.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((p==="le"||p==="be")&&(x=p,p=10),this._init(v||0,p||10,x||"be"))}typeof n=="object"?n.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=j9().Buffer}catch{}i.isBN=function(p){return p instanceof i?!0:p!==null&&typeof p=="object"&&p.constructor.wordSize===i.wordSize&&Array.isArray(p.words)},i.max=function(p,x){return p.cmp(x)>0?p:x},i.min=function(p,x){return p.cmp(x)<0?p:x},i.prototype._init=function(p,x,y){if(typeof p=="number")return this._initNumber(p,x,y);if(typeof p=="object")return this._initArray(p,x,y);x==="hex"&&(x=16),t(x===(x|0)&&x>=2&&x<=36),p=p.toString().replace(/\s+/g,"");var I=0;p[0]==="-"&&(I++,this.negative=1),I<p.length&&(x===16?this._parseHex(p,I,y):(this._parseBase(p,x,I),y==="le"&&this._initArray(this.toArray(),x,y)))},i.prototype._initNumber=function(p,x,y){p<0&&(this.negative=1,p=-p),p<67108864?(this.words=[p&67108863],this.length=1):p<4503599627370496?(this.words=[p&67108863,p/67108864&67108863],this.length=2):(t(p<9007199254740992),this.words=[p&67108863,p/67108864&67108863,1],this.length=3),y==="le"&&this._initArray(this.toArray(),x,y)},i.prototype._initArray=function(p,x,y){if(t(typeof p.length=="number"),p.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(p.length/3),this.words=new Array(this.length);for(var I=0;I<this.length;I++)this.words[I]=0;var C,F,N=0;if(y==="be")for(I=p.length-1,C=0;I>=0;I-=3)F=p[I]|p[I-1]<<8|p[I-2]<<16,this.words[C]|=F<<N&67108863,this.words[C+1]=F>>>26-N&67108863,N+=24,N>=26&&(N-=26,C++);else if(y==="le")for(I=0,C=0;I<p.length;I+=3)F=p[I]|p[I+1]<<8|p[I+2]<<16,this.words[C]|=F<<N&67108863,this.words[C+1]=F>>>26-N&67108863,N+=24,N>=26&&(N-=26,C++);return this._strip()};function s(v,p){var x=v.charCodeAt(p);if(x>=48&&x<=57)return x-48;if(x>=65&&x<=70)return x-55;if(x>=97&&x<=102)return x-87;t(!1,"Invalid character in "+v)}function a(v,p,x){var y=s(v,x);return x-1>=p&&(y|=s(v,x-1)<<4),y}i.prototype._parseHex=function(p,x,y){this.length=Math.ceil((p.length-x)/6),this.words=new Array(this.length);for(var I=0;I<this.length;I++)this.words[I]=0;var C=0,F=0,N;if(y==="be")for(I=p.length-1;I>=x;I-=2)N=a(p,x,I)<<C,this.words[F]|=N&67108863,C>=18?(C-=18,F+=1,this.words[F]|=N>>>26):C+=8;else{var O=p.length-x;for(I=O%2===0?x+1:x;I<p.length;I+=2)N=a(p,x,I)<<C,this.words[F]|=N&67108863,C>=18?(C-=18,F+=1,this.words[F]|=N>>>26):C+=8}this._strip()};function c(v,p,x,y){for(var I=0,C=0,F=Math.min(v.length,x),N=p;N<F;N++){var O=v.charCodeAt(N)-48;I*=y,O>=49?C=O-49+10:O>=17?C=O-17+10:C=O,t(O>=0&&C<y,"Invalid character"),I+=C}return I}i.prototype._parseBase=function(p,x,y){this.words=[0],this.length=1;for(var I=0,C=1;C<=67108863;C*=x)I++;I--,C=C/x|0;for(var F=p.length-y,N=F%I,O=Math.min(F,F-N)+y,T=0,q=y;q<O;q+=I)T=c(p,q,q+I,x),this.imuln(C),this.words[0]+T<67108864?this.words[0]+=T:this._iaddn(T);if(N!==0){var _=1;for(T=c(p,q,p.length,x),q=0;q<N;q++)_*=x;this.imuln(_),this.words[0]+T<67108864?this.words[0]+=T:this._iaddn(T)}this._strip()},i.prototype.copy=function(p){p.words=new Array(this.length);for(var x=0;x<this.length;x++)p.words[x]=this.words[x];p.length=this.length,p.negative=this.negative,p.red=this.red};function u(v,p){v.words=p.words,v.length=p.length,v.negative=p.negative,v.red=p.red}if(i.prototype._move=function(p){u(p,this)},i.prototype.clone=function(){var p=new i(null);return this.copy(p),p},i.prototype._expand=function(p){for(;this.length<p;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch{i.prototype.inspect=l}else i.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],h=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(p,x){p=p||10,x=x|0||1;var y;if(p===16||p==="hex"){y="";for(var I=0,C=0,F=0;F<this.length;F++){var N=this.words[F],O=((N<<I|C)&16777215).toString(16);C=N>>>24-I&16777215,I+=2,I>=26&&(I-=26,F--),C!==0||F!==this.length-1?y=d[6-O.length]+O+y:y=O+y}for(C!==0&&(y=C.toString(16)+y);y.length%x!==0;)y="0"+y;return this.negative!==0&&(y="-"+y),y}if(p===(p|0)&&p>=2&&p<=36){var T=h[p],q=f[p];y="";var _=this.clone();for(_.negative=0;!_.isZero();){var L=_.modrn(q).toString(p);_=_.idivn(q),_.isZero()?y=L+y:y=d[T-L.length]+L+y}for(this.isZero()&&(y="0"+y);y.length%x!==0;)y="0"+y;return this.negative!==0&&(y="-"+y),y}t(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var p=this.words[0];return this.length===2?p+=this.words[1]*67108864:this.length===3&&this.words[2]===1?p+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-p:p},i.prototype.toJSON=function(){return this.toString(16,2)},o&&(i.prototype.toBuffer=function(p,x){return this.toArrayLike(o,p,x)}),i.prototype.toArray=function(p,x){return this.toArrayLike(Array,p,x)};var m=function(p,x){return p.allocUnsafe?p.allocUnsafe(x):new p(x)};i.prototype.toArrayLike=function(p,x,y){this._strip();var I=this.byteLength(),C=y||Math.max(1,I);t(I<=C,"byte array longer than desired length"),t(C>0,"Requested array length <= 0");var F=m(p,C),N=x==="le"?"LE":"BE";return this["_toArrayLike"+N](F,I),F},i.prototype._toArrayLikeLE=function(p,x){for(var y=0,I=0,C=0,F=0;C<this.length;C++){var N=this.words[C]<<F|I;p[y++]=N&255,y<p.length&&(p[y++]=N>>8&255),y<p.length&&(p[y++]=N>>16&255),F===6?(y<p.length&&(p[y++]=N>>24&255),I=0,F=0):(I=N>>>24,F+=2)}if(y<p.length)for(p[y++]=I;y<p.length;)p[y++]=0},i.prototype._toArrayLikeBE=function(p,x){for(var y=p.length-1,I=0,C=0,F=0;C<this.length;C++){var N=this.words[C]<<F|I;p[y--]=N&255,y>=0&&(p[y--]=N>>8&255),y>=0&&(p[y--]=N>>16&255),F===6?(y>=0&&(p[y--]=N>>24&255),I=0,F=0):(I=N>>>24,F+=2)}if(y>=0)for(p[y--]=I;y>=0;)p[y--]=0},Math.clz32?i.prototype._countBits=function(p){return 32-Math.clz32(p)}:i.prototype._countBits=function(p){var x=p,y=0;return x>=4096&&(y+=13,x>>>=13),x>=64&&(y+=7,x>>>=7),x>=8&&(y+=4,x>>>=4),x>=2&&(y+=2,x>>>=2),y+x},i.prototype._zeroBits=function(p){if(p===0)return 26;var x=p,y=0;return(x&8191)===0&&(y+=13,x>>>=13),(x&127)===0&&(y+=7,x>>>=7),(x&15)===0&&(y+=4,x>>>=4),(x&3)===0&&(y+=2,x>>>=2),(x&1)===0&&y++,y},i.prototype.bitLength=function(){var p=this.words[this.length-1],x=this._countBits(p);return(this.length-1)*26+x};function w(v){for(var p=new Array(v.bitLength()),x=0;x<p.length;x++){var y=x/26|0,I=x%26;p[x]=v.words[y]>>>I&1}return p}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var p=0,x=0;x<this.length;x++){var y=this._zeroBits(this.words[x]);if(p+=y,y!==26)break}return p},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(p){return this.negative!==0?this.abs().inotn(p).iaddn(1):this.clone()},i.prototype.fromTwos=function(p){return this.testn(p-1)?this.notn(p).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(p){for(;this.length<p.length;)this.words[this.length++]=0;for(var x=0;x<p.length;x++)this.words[x]=this.words[x]|p.words[x];return this._strip()},i.prototype.ior=function(p){return t((this.negative|p.negative)===0),this.iuor(p)},i.prototype.or=function(p){return this.length>p.length?this.clone().ior(p):p.clone().ior(this)},i.prototype.uor=function(p){return this.length>p.length?this.clone().iuor(p):p.clone().iuor(this)},i.prototype.iuand=function(p){var x;this.length>p.length?x=p:x=this;for(var y=0;y<x.length;y++)this.words[y]=this.words[y]&p.words[y];return this.length=x.length,this._strip()},i.prototype.iand=function(p){return t((this.negative|p.negative)===0),this.iuand(p)},i.prototype.and=function(p){return this.length>p.length?this.clone().iand(p):p.clone().iand(this)},i.prototype.uand=function(p){return this.length>p.length?this.clone().iuand(p):p.clone().iuand(this)},i.prototype.iuxor=function(p){var x,y;this.length>p.length?(x=this,y=p):(x=p,y=this);for(var I=0;I<y.length;I++)this.words[I]=x.words[I]^y.words[I];if(this!==x)for(;I<x.length;I++)this.words[I]=x.words[I];return this.length=x.length,this._strip()},i.prototype.ixor=function(p){return t((this.negative|p.negative)===0),this.iuxor(p)},i.prototype.xor=function(p){return this.length>p.length?this.clone().ixor(p):p.clone().ixor(this)},i.prototype.uxor=function(p){return this.length>p.length?this.clone().iuxor(p):p.clone().iuxor(this)},i.prototype.inotn=function(p){t(typeof p=="number"&&p>=0);var x=Math.ceil(p/26)|0,y=p%26;this._expand(x),y>0&&x--;for(var I=0;I<x;I++)this.words[I]=~this.words[I]&67108863;return y>0&&(this.words[I]=~this.words[I]&67108863>>26-y),this._strip()},i.prototype.notn=function(p){return this.clone().inotn(p)},i.prototype.setn=function(p,x){t(typeof p=="number"&&p>=0);var y=p/26|0,I=p%26;return this._expand(y+1),x?this.words[y]=this.words[y]|1<<I:this.words[y]=this.words[y]&~(1<<I),this._strip()},i.prototype.iadd=function(p){var x;if(this.negative!==0&&p.negative===0)return this.negative=0,x=this.isub(p),this.negative^=1,this._normSign();if(this.negative===0&&p.negative!==0)return p.negative=0,x=this.isub(p),p.negative=1,x._normSign();var y,I;this.length>p.length?(y=this,I=p):(y=p,I=this);for(var C=0,F=0;F<I.length;F++)x=(y.words[F]|0)+(I.words[F]|0)+C,this.words[F]=x&67108863,C=x>>>26;for(;C!==0&&F<y.length;F++)x=(y.words[F]|0)+C,this.words[F]=x&67108863,C=x>>>26;if(this.length=y.length,C!==0)this.words[this.length]=C,this.length++;else if(y!==this)for(;F<y.length;F++)this.words[F]=y.words[F];return this},i.prototype.add=function(p){var x;return p.negative!==0&&this.negative===0?(p.negative=0,x=this.sub(p),p.negative^=1,x):p.negative===0&&this.negative!==0?(this.negative=0,x=p.sub(this),this.negative=1,x):this.length>p.length?this.clone().iadd(p):p.clone().iadd(this)},i.prototype.isub=function(p){if(p.negative!==0){p.negative=0;var x=this.iadd(p);return p.negative=1,x._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(p),this.negative=1,this._normSign();var y=this.cmp(p);if(y===0)return this.negative=0,this.length=1,this.words[0]=0,this;var I,C;y>0?(I=this,C=p):(I=p,C=this);for(var F=0,N=0;N<C.length;N++)x=(I.words[N]|0)-(C.words[N]|0)+F,F=x>>26,this.words[N]=x&67108863;for(;F!==0&&N<I.length;N++)x=(I.words[N]|0)+F,F=x>>26,this.words[N]=x&67108863;if(F===0&&N<I.length&&I!==this)for(;N<I.length;N++)this.words[N]=I.words[N];return this.length=Math.max(this.length,N),I!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(p){return this.clone().isub(p)};function b(v,p,x){x.negative=p.negative^v.negative;var y=v.length+p.length|0;x.length=y,y=y-1|0;var I=v.words[0]|0,C=p.words[0]|0,F=I*C,N=F&67108863,O=F/67108864|0;x.words[0]=N;for(var T=1;T<y;T++){for(var q=O>>>26,_=O&67108863,L=Math.min(T,p.length-1),g=Math.max(0,T-v.length+1);g<=L;g++){var K=T-g|0;I=v.words[K]|0,C=p.words[g]|0,F=I*C+_,q+=F/67108864|0,_=F&67108863}x.words[T]=_|0,O=q|0}return O!==0?x.words[T]=O|0:x.length--,x._strip()}var S=function(p,x,y){var I=p.words,C=x.words,F=y.words,N=0,O,T,q,_=I[0]|0,L=_&8191,g=_>>>13,K=I[1]|0,E=K&8191,V=K>>>13,J=I[2]|0,B=J&8191,X=J>>>13,ce=I[3]|0,ne=ce&8191,ge=ce>>>13,He=I[4]|0,Le=He&8191,Fe=He>>>13,ft=I[5]|0,Te=ft&8191,De=ft>>>13,tt=I[6]|0,$e=tt&8191,Et=tt>>>13,_r=I[7]|0,Pt=_r&8191,zt=_r>>>13,er=I[8]|0,Ft=er&8191,Kt=er>>>13,Xo=I[9]|0,Xt=Xo&8191,ue=Xo>>>13,k=C[0]|0,P=k&8191,te=k>>>13,se=C[1]|0,$=se&8191,ae=se>>>13,re=C[2]|0,fe=re&8191,me=re>>>13,Ie=C[3]|0,le=Ie&8191,Ae=Ie>>>13,Qe=C[4]|0,Pe=Qe&8191,Se=Qe>>>13,nt=C[5]|0,Je=nt&8191,Ze=nt>>>13,st=C[6]|0,qe=st&8191,Oe=st>>>13,Yt=C[7]|0,Jt=Yt&8191,tn=Yt>>>13,Yu=C[8]|0,Rn=Yu&8191,Dn=Yu>>>13,ju=C[9]|0,Tn=ju&8191,Bn=ju>>>13;y.negative=p.negative^x.negative,y.length=19,O=Math.imul(L,P),T=Math.imul(L,te),T=T+Math.imul(g,P)|0,q=Math.imul(g,te);var qc=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(qc>>>26)|0,qc&=67108863,O=Math.imul(E,P),T=Math.imul(E,te),T=T+Math.imul(V,P)|0,q=Math.imul(V,te),O=O+Math.imul(L,$)|0,T=T+Math.imul(L,ae)|0,T=T+Math.imul(g,$)|0,q=q+Math.imul(g,ae)|0;var Ls=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Ls>>>26)|0,Ls&=67108863,O=Math.imul(B,P),T=Math.imul(B,te),T=T+Math.imul(X,P)|0,q=Math.imul(X,te),O=O+Math.imul(E,$)|0,T=T+Math.imul(E,ae)|0,T=T+Math.imul(V,$)|0,q=q+Math.imul(V,ae)|0,O=O+Math.imul(L,fe)|0,T=T+Math.imul(L,me)|0,T=T+Math.imul(g,fe)|0,q=q+Math.imul(g,me)|0;var _o=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(_o>>>26)|0,_o&=67108863,O=Math.imul(ne,P),T=Math.imul(ne,te),T=T+Math.imul(ge,P)|0,q=Math.imul(ge,te),O=O+Math.imul(B,$)|0,T=T+Math.imul(B,ae)|0,T=T+Math.imul(X,$)|0,q=q+Math.imul(X,ae)|0,O=O+Math.imul(E,fe)|0,T=T+Math.imul(E,me)|0,T=T+Math.imul(V,fe)|0,q=q+Math.imul(V,me)|0,O=O+Math.imul(L,le)|0,T=T+Math.imul(L,Ae)|0,T=T+Math.imul(g,le)|0,q=q+Math.imul(g,Ae)|0;var Ja=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Ja>>>26)|0,Ja&=67108863,O=Math.imul(Le,P),T=Math.imul(Le,te),T=T+Math.imul(Fe,P)|0,q=Math.imul(Fe,te),O=O+Math.imul(ne,$)|0,T=T+Math.imul(ne,ae)|0,T=T+Math.imul(ge,$)|0,q=q+Math.imul(ge,ae)|0,O=O+Math.imul(B,fe)|0,T=T+Math.imul(B,me)|0,T=T+Math.imul(X,fe)|0,q=q+Math.imul(X,me)|0,O=O+Math.imul(E,le)|0,T=T+Math.imul(E,Ae)|0,T=T+Math.imul(V,le)|0,q=q+Math.imul(V,Ae)|0,O=O+Math.imul(L,Pe)|0,T=T+Math.imul(L,Se)|0,T=T+Math.imul(g,Pe)|0,q=q+Math.imul(g,Se)|0;var vd=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(vd>>>26)|0,vd&=67108863,O=Math.imul(Te,P),T=Math.imul(Te,te),T=T+Math.imul(De,P)|0,q=Math.imul(De,te),O=O+Math.imul(Le,$)|0,T=T+Math.imul(Le,ae)|0,T=T+Math.imul(Fe,$)|0,q=q+Math.imul(Fe,ae)|0,O=O+Math.imul(ne,fe)|0,T=T+Math.imul(ne,me)|0,T=T+Math.imul(ge,fe)|0,q=q+Math.imul(ge,me)|0,O=O+Math.imul(B,le)|0,T=T+Math.imul(B,Ae)|0,T=T+Math.imul(X,le)|0,q=q+Math.imul(X,Ae)|0,O=O+Math.imul(E,Pe)|0,T=T+Math.imul(E,Se)|0,T=T+Math.imul(V,Pe)|0,q=q+Math.imul(V,Se)|0,O=O+Math.imul(L,Je)|0,T=T+Math.imul(L,Ze)|0,T=T+Math.imul(g,Je)|0,q=q+Math.imul(g,Ze)|0;var G8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(G8>>>26)|0,G8&=67108863,O=Math.imul($e,P),T=Math.imul($e,te),T=T+Math.imul(Et,P)|0,q=Math.imul(Et,te),O=O+Math.imul(Te,$)|0,T=T+Math.imul(Te,ae)|0,T=T+Math.imul(De,$)|0,q=q+Math.imul(De,ae)|0,O=O+Math.imul(Le,fe)|0,T=T+Math.imul(Le,me)|0,T=T+Math.imul(Fe,fe)|0,q=q+Math.imul(Fe,me)|0,O=O+Math.imul(ne,le)|0,T=T+Math.imul(ne,Ae)|0,T=T+Math.imul(ge,le)|0,q=q+Math.imul(ge,Ae)|0,O=O+Math.imul(B,Pe)|0,T=T+Math.imul(B,Se)|0,T=T+Math.imul(X,Pe)|0,q=q+Math.imul(X,Se)|0,O=O+Math.imul(E,Je)|0,T=T+Math.imul(E,Ze)|0,T=T+Math.imul(V,Je)|0,q=q+Math.imul(V,Ze)|0,O=O+Math.imul(L,qe)|0,T=T+Math.imul(L,Oe)|0,T=T+Math.imul(g,qe)|0,q=q+Math.imul(g,Oe)|0;var H8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(H8>>>26)|0,H8&=67108863,O=Math.imul(Pt,P),T=Math.imul(Pt,te),T=T+Math.imul(zt,P)|0,q=Math.imul(zt,te),O=O+Math.imul($e,$)|0,T=T+Math.imul($e,ae)|0,T=T+Math.imul(Et,$)|0,q=q+Math.imul(Et,ae)|0,O=O+Math.imul(Te,fe)|0,T=T+Math.imul(Te,me)|0,T=T+Math.imul(De,fe)|0,q=q+Math.imul(De,me)|0,O=O+Math.imul(Le,le)|0,T=T+Math.imul(Le,Ae)|0,T=T+Math.imul(Fe,le)|0,q=q+Math.imul(Fe,Ae)|0,O=O+Math.imul(ne,Pe)|0,T=T+Math.imul(ne,Se)|0,T=T+Math.imul(ge,Pe)|0,q=q+Math.imul(ge,Se)|0,O=O+Math.imul(B,Je)|0,T=T+Math.imul(B,Ze)|0,T=T+Math.imul(X,Je)|0,q=q+Math.imul(X,Ze)|0,O=O+Math.imul(E,qe)|0,T=T+Math.imul(E,Oe)|0,T=T+Math.imul(V,qe)|0,q=q+Math.imul(V,Oe)|0,O=O+Math.imul(L,Jt)|0,T=T+Math.imul(L,tn)|0,T=T+Math.imul(g,Jt)|0,q=q+Math.imul(g,tn)|0;var K8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(K8>>>26)|0,K8&=67108863,O=Math.imul(Ft,P),T=Math.imul(Ft,te),T=T+Math.imul(Kt,P)|0,q=Math.imul(Kt,te),O=O+Math.imul(Pt,$)|0,T=T+Math.imul(Pt,ae)|0,T=T+Math.imul(zt,$)|0,q=q+Math.imul(zt,ae)|0,O=O+Math.imul($e,fe)|0,T=T+Math.imul($e,me)|0,T=T+Math.imul(Et,fe)|0,q=q+Math.imul(Et,me)|0,O=O+Math.imul(Te,le)|0,T=T+Math.imul(Te,Ae)|0,T=T+Math.imul(De,le)|0,q=q+Math.imul(De,Ae)|0,O=O+Math.imul(Le,Pe)|0,T=T+Math.imul(Le,Se)|0,T=T+Math.imul(Fe,Pe)|0,q=q+Math.imul(Fe,Se)|0,O=O+Math.imul(ne,Je)|0,T=T+Math.imul(ne,Ze)|0,T=T+Math.imul(ge,Je)|0,q=q+Math.imul(ge,Ze)|0,O=O+Math.imul(B,qe)|0,T=T+Math.imul(B,Oe)|0,T=T+Math.imul(X,qe)|0,q=q+Math.imul(X,Oe)|0,O=O+Math.imul(E,Jt)|0,T=T+Math.imul(E,tn)|0,T=T+Math.imul(V,Jt)|0,q=q+Math.imul(V,tn)|0,O=O+Math.imul(L,Rn)|0,T=T+Math.imul(L,Dn)|0,T=T+Math.imul(g,Rn)|0,q=q+Math.imul(g,Dn)|0;var J8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(J8>>>26)|0,J8&=67108863,O=Math.imul(Xt,P),T=Math.imul(Xt,te),T=T+Math.imul(ue,P)|0,q=Math.imul(ue,te),O=O+Math.imul(Ft,$)|0,T=T+Math.imul(Ft,ae)|0,T=T+Math.imul(Kt,$)|0,q=q+Math.imul(Kt,ae)|0,O=O+Math.imul(Pt,fe)|0,T=T+Math.imul(Pt,me)|0,T=T+Math.imul(zt,fe)|0,q=q+Math.imul(zt,me)|0,O=O+Math.imul($e,le)|0,T=T+Math.imul($e,Ae)|0,T=T+Math.imul(Et,le)|0,q=q+Math.imul(Et,Ae)|0,O=O+Math.imul(Te,Pe)|0,T=T+Math.imul(Te,Se)|0,T=T+Math.imul(De,Pe)|0,q=q+Math.imul(De,Se)|0,O=O+Math.imul(Le,Je)|0,T=T+Math.imul(Le,Ze)|0,T=T+Math.imul(Fe,Je)|0,q=q+Math.imul(Fe,Ze)|0,O=O+Math.imul(ne,qe)|0,T=T+Math.imul(ne,Oe)|0,T=T+Math.imul(ge,qe)|0,q=q+Math.imul(ge,Oe)|0,O=O+Math.imul(B,Jt)|0,T=T+Math.imul(B,tn)|0,T=T+Math.imul(X,Jt)|0,q=q+Math.imul(X,tn)|0,O=O+Math.imul(E,Rn)|0,T=T+Math.imul(E,Dn)|0,T=T+Math.imul(V,Rn)|0,q=q+Math.imul(V,Dn)|0,O=O+Math.imul(L,Tn)|0,T=T+Math.imul(L,Bn)|0,T=T+Math.imul(g,Tn)|0,q=q+Math.imul(g,Bn)|0;var q8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(q8>>>26)|0,q8&=67108863,O=Math.imul(Xt,$),T=Math.imul(Xt,ae),T=T+Math.imul(ue,$)|0,q=Math.imul(ue,ae),O=O+Math.imul(Ft,fe)|0,T=T+Math.imul(Ft,me)|0,T=T+Math.imul(Kt,fe)|0,q=q+Math.imul(Kt,me)|0,O=O+Math.imul(Pt,le)|0,T=T+Math.imul(Pt,Ae)|0,T=T+Math.imul(zt,le)|0,q=q+Math.imul(zt,Ae)|0,O=O+Math.imul($e,Pe)|0,T=T+Math.imul($e,Se)|0,T=T+Math.imul(Et,Pe)|0,q=q+Math.imul(Et,Se)|0,O=O+Math.imul(Te,Je)|0,T=T+Math.imul(Te,Ze)|0,T=T+Math.imul(De,Je)|0,q=q+Math.imul(De,Ze)|0,O=O+Math.imul(Le,qe)|0,T=T+Math.imul(Le,Oe)|0,T=T+Math.imul(Fe,qe)|0,q=q+Math.imul(Fe,Oe)|0,O=O+Math.imul(ne,Jt)|0,T=T+Math.imul(ne,tn)|0,T=T+Math.imul(ge,Jt)|0,q=q+Math.imul(ge,tn)|0,O=O+Math.imul(B,Rn)|0,T=T+Math.imul(B,Dn)|0,T=T+Math.imul(X,Rn)|0,q=q+Math.imul(X,Dn)|0,O=O+Math.imul(E,Tn)|0,T=T+Math.imul(E,Bn)|0,T=T+Math.imul(V,Tn)|0,q=q+Math.imul(V,Bn)|0;var V8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(V8>>>26)|0,V8&=67108863,O=Math.imul(Xt,fe),T=Math.imul(Xt,me),T=T+Math.imul(ue,fe)|0,q=Math.imul(ue,me),O=O+Math.imul(Ft,le)|0,T=T+Math.imul(Ft,Ae)|0,T=T+Math.imul(Kt,le)|0,q=q+Math.imul(Kt,Ae)|0,O=O+Math.imul(Pt,Pe)|0,T=T+Math.imul(Pt,Se)|0,T=T+Math.imul(zt,Pe)|0,q=q+Math.imul(zt,Se)|0,O=O+Math.imul($e,Je)|0,T=T+Math.imul($e,Ze)|0,T=T+Math.imul(Et,Je)|0,q=q+Math.imul(Et,Ze)|0,O=O+Math.imul(Te,qe)|0,T=T+Math.imul(Te,Oe)|0,T=T+Math.imul(De,qe)|0,q=q+Math.imul(De,Oe)|0,O=O+Math.imul(Le,Jt)|0,T=T+Math.imul(Le,tn)|0,T=T+Math.imul(Fe,Jt)|0,q=q+Math.imul(Fe,tn)|0,O=O+Math.imul(ne,Rn)|0,T=T+Math.imul(ne,Dn)|0,T=T+Math.imul(ge,Rn)|0,q=q+Math.imul(ge,Dn)|0,O=O+Math.imul(B,Tn)|0,T=T+Math.imul(B,Bn)|0,T=T+Math.imul(X,Tn)|0,q=q+Math.imul(X,Bn)|0;var Q8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Q8>>>26)|0,Q8&=67108863,O=Math.imul(Xt,le),T=Math.imul(Xt,Ae),T=T+Math.imul(ue,le)|0,q=Math.imul(ue,Ae),O=O+Math.imul(Ft,Pe)|0,T=T+Math.imul(Ft,Se)|0,T=T+Math.imul(Kt,Pe)|0,q=q+Math.imul(Kt,Se)|0,O=O+Math.imul(Pt,Je)|0,T=T+Math.imul(Pt,Ze)|0,T=T+Math.imul(zt,Je)|0,q=q+Math.imul(zt,Ze)|0,O=O+Math.imul($e,qe)|0,T=T+Math.imul($e,Oe)|0,T=T+Math.imul(Et,qe)|0,q=q+Math.imul(Et,Oe)|0,O=O+Math.imul(Te,Jt)|0,T=T+Math.imul(Te,tn)|0,T=T+Math.imul(De,Jt)|0,q=q+Math.imul(De,tn)|0,O=O+Math.imul(Le,Rn)|0,T=T+Math.imul(Le,Dn)|0,T=T+Math.imul(Fe,Rn)|0,q=q+Math.imul(Fe,Dn)|0,O=O+Math.imul(ne,Tn)|0,T=T+Math.imul(ne,Bn)|0,T=T+Math.imul(ge,Tn)|0,q=q+Math.imul(ge,Bn)|0;var z8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(z8>>>26)|0,z8&=67108863,O=Math.imul(Xt,Pe),T=Math.imul(Xt,Se),T=T+Math.imul(ue,Pe)|0,q=Math.imul(ue,Se),O=O+Math.imul(Ft,Je)|0,T=T+Math.imul(Ft,Ze)|0,T=T+Math.imul(Kt,Je)|0,q=q+Math.imul(Kt,Ze)|0,O=O+Math.imul(Pt,qe)|0,T=T+Math.imul(Pt,Oe)|0,T=T+Math.imul(zt,qe)|0,q=q+Math.imul(zt,Oe)|0,O=O+Math.imul($e,Jt)|0,T=T+Math.imul($e,tn)|0,T=T+Math.imul(Et,Jt)|0,q=q+Math.imul(Et,tn)|0,O=O+Math.imul(Te,Rn)|0,T=T+Math.imul(Te,Dn)|0,T=T+Math.imul(De,Rn)|0,q=q+Math.imul(De,Dn)|0,O=O+Math.imul(Le,Tn)|0,T=T+Math.imul(Le,Bn)|0,T=T+Math.imul(Fe,Tn)|0,q=q+Math.imul(Fe,Bn)|0;var Y8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Y8>>>26)|0,Y8&=67108863,O=Math.imul(Xt,Je),T=Math.imul(Xt,Ze),T=T+Math.imul(ue,Je)|0,q=Math.imul(ue,Ze),O=O+Math.imul(Ft,qe)|0,T=T+Math.imul(Ft,Oe)|0,T=T+Math.imul(Kt,qe)|0,q=q+Math.imul(Kt,Oe)|0,O=O+Math.imul(Pt,Jt)|0,T=T+Math.imul(Pt,tn)|0,T=T+Math.imul(zt,Jt)|0,q=q+Math.imul(zt,tn)|0,O=O+Math.imul($e,Rn)|0,T=T+Math.imul($e,Dn)|0,T=T+Math.imul(Et,Rn)|0,q=q+Math.imul(Et,Dn)|0,O=O+Math.imul(Te,Tn)|0,T=T+Math.imul(Te,Bn)|0,T=T+Math.imul(De,Tn)|0,q=q+Math.imul(De,Bn)|0;var j8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(j8>>>26)|0,j8&=67108863,O=Math.imul(Xt,qe),T=Math.imul(Xt,Oe),T=T+Math.imul(ue,qe)|0,q=Math.imul(ue,Oe),O=O+Math.imul(Ft,Jt)|0,T=T+Math.imul(Ft,tn)|0,T=T+Math.imul(Kt,Jt)|0,q=q+Math.imul(Kt,tn)|0,O=O+Math.imul(Pt,Rn)|0,T=T+Math.imul(Pt,Dn)|0,T=T+Math.imul(zt,Rn)|0,q=q+Math.imul(zt,Dn)|0,O=O+Math.imul($e,Tn)|0,T=T+Math.imul($e,Bn)|0,T=T+Math.imul(Et,Tn)|0,q=q+Math.imul(Et,Bn)|0;var W8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(W8>>>26)|0,W8&=67108863,O=Math.imul(Xt,Jt),T=Math.imul(Xt,tn),T=T+Math.imul(ue,Jt)|0,q=Math.imul(ue,tn),O=O+Math.imul(Ft,Rn)|0,T=T+Math.imul(Ft,Dn)|0,T=T+Math.imul(Kt,Rn)|0,q=q+Math.imul(Kt,Dn)|0,O=O+Math.imul(Pt,Tn)|0,T=T+Math.imul(Pt,Bn)|0,T=T+Math.imul(zt,Tn)|0,q=q+Math.imul(zt,Bn)|0;var Z8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Z8>>>26)|0,Z8&=67108863,O=Math.imul(Xt,Rn),T=Math.imul(Xt,Dn),T=T+Math.imul(ue,Rn)|0,q=Math.imul(ue,Dn),O=O+Math.imul(Ft,Tn)|0,T=T+Math.imul(Ft,Bn)|0,T=T+Math.imul(Kt,Tn)|0,q=q+Math.imul(Kt,Bn)|0;var X8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(X8>>>26)|0,X8&=67108863,O=Math.imul(Xt,Tn),T=Math.imul(Xt,Bn),T=T+Math.imul(ue,Tn)|0,q=Math.imul(ue,Bn);var _8=(N+O|0)+((T&8191)<<13)|0;return N=(q+(T>>>13)|0)+(_8>>>26)|0,_8&=67108863,F[0]=qc,F[1]=Ls,F[2]=_o,F[3]=Ja,F[4]=vd,F[5]=G8,F[6]=H8,F[7]=K8,F[8]=J8,F[9]=q8,F[10]=V8,F[11]=Q8,F[12]=z8,F[13]=Y8,F[14]=j8,F[15]=W8,F[16]=Z8,F[17]=X8,F[18]=_8,N!==0&&(F[19]=N,y.length++),y};Math.imul||(S=b);function R(v,p,x){x.negative=p.negative^v.negative,x.length=v.length+p.length;for(var y=0,I=0,C=0;C<x.length-1;C++){var F=I;I=0;for(var N=y&67108863,O=Math.min(C,p.length-1),T=Math.max(0,C-v.length+1);T<=O;T++){var q=C-T,_=v.words[q]|0,L=p.words[T]|0,g=_*L,K=g&67108863;F=F+(g/67108864|0)|0,K=K+N|0,N=K&67108863,F=F+(K>>>26)|0,I+=F>>>26,F&=67108863}x.words[C]=N,y=F,F=I}return y!==0?x.words[C]=y:x.length--,x._strip()}function G(v,p,x){return R(v,p,x)}i.prototype.mulTo=function(p,x){var y,I=this.length+p.length;return this.length===10&&p.length===10?y=S(this,p,x):I<63?y=b(this,p,x):I<1024?y=R(this,p,x):y=G(this,p,x),y};function U(v,p){this.x=v,this.y=p}U.prototype.makeRBT=function(p){for(var x=new Array(p),y=i.prototype._countBits(p)-1,I=0;I<p;I++)x[I]=this.revBin(I,y,p);return x},U.prototype.revBin=function(p,x,y){if(p===0||p===y-1)return p;for(var I=0,C=0;C<x;C++)I|=(p&1)<<x-C-1,p>>=1;return I},U.prototype.permute=function(p,x,y,I,C,F){for(var N=0;N<F;N++)I[N]=x[p[N]],C[N]=y[p[N]]},U.prototype.transform=function(p,x,y,I,C,F){this.permute(F,p,x,y,I,C);for(var N=1;N<C;N<<=1)for(var O=N<<1,T=Math.cos(2*Math.PI/O),q=Math.sin(2*Math.PI/O),_=0;_<C;_+=O)for(var L=T,g=q,K=0;K<N;K++){var E=y[_+K],V=I[_+K],J=y[_+K+N],B=I[_+K+N],X=L*J-g*B;B=L*B+g*J,J=X,y[_+K]=E+J,I[_+K]=V+B,y[_+K+N]=E-J,I[_+K+N]=V-B,K!==O&&(X=T*L-q*g,g=T*g+q*L,L=X)}},U.prototype.guessLen13b=function(p,x){var y=Math.max(x,p)|1,I=y&1,C=0;for(y=y/2|0;y;y=y>>>1)C++;return 1<<C+1+I},U.prototype.conjugate=function(p,x,y){if(!(y<=1))for(var I=0;I<y/2;I++){var C=p[I];p[I]=p[y-I-1],p[y-I-1]=C,C=x[I],x[I]=-x[y-I-1],x[y-I-1]=-C}},U.prototype.normalize13b=function(p,x){for(var y=0,I=0;I<x/2;I++){var C=Math.round(p[2*I+1]/x)*8192+Math.round(p[2*I]/x)+y;p[I]=C&67108863,C<67108864?y=0:y=C/67108864|0}return p},U.prototype.convert13b=function(p,x,y,I){for(var C=0,F=0;F<x;F++)C=C+(p[F]|0),y[2*F]=C&8191,C=C>>>13,y[2*F+1]=C&8191,C=C>>>13;for(F=2*x;F<I;++F)y[F]=0;t(C===0),t((C&-8192)===0)},U.prototype.stub=function(p){for(var x=new Array(p),y=0;y<p;y++)x[y]=0;return x},U.prototype.mulp=function(p,x,y){var I=2*this.guessLen13b(p.length,x.length),C=this.makeRBT(I),F=this.stub(I),N=new Array(I),O=new Array(I),T=new Array(I),q=new Array(I),_=new Array(I),L=new Array(I),g=y.words;g.length=I,this.convert13b(p.words,p.length,N,I),this.convert13b(x.words,x.length,q,I),this.transform(N,F,O,T,I,C),this.transform(q,F,_,L,I,C);for(var K=0;K<I;K++){var E=O[K]*_[K]-T[K]*L[K];T[K]=O[K]*L[K]+T[K]*_[K],O[K]=E}return this.conjugate(O,T,I),this.transform(O,T,g,F,I,C),this.conjugate(g,F,I),this.normalize13b(g,I),y.negative=p.negative^x.negative,y.length=p.length+x.length,y._strip()},i.prototype.mul=function(p){var x=new i(null);return x.words=new Array(this.length+p.length),this.mulTo(p,x)},i.prototype.mulf=function(p){var x=new i(null);return x.words=new Array(this.length+p.length),G(this,p,x)},i.prototype.imul=function(p){return this.clone().mulTo(p,this)},i.prototype.imuln=function(p){var x=p<0;x&&(p=-p),t(typeof p=="number"),t(p<67108864);for(var y=0,I=0;I<this.length;I++){var C=(this.words[I]|0)*p,F=(C&67108863)+(y&67108863);y>>=26,y+=C/67108864|0,y+=F>>>26,this.words[I]=F&67108863}return y!==0&&(this.words[I]=y,this.length++),this.length=p===0?1:this.length,x?this.ineg():this},i.prototype.muln=function(p){return this.clone().imuln(p)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(p){var x=w(p);if(x.length===0)return new i(1);for(var y=this,I=0;I<x.length&&x[I]===0;I++,y=y.sqr());if(++I<x.length)for(var C=y.sqr();I<x.length;I++,C=C.sqr())x[I]!==0&&(y=y.mul(C));return y},i.prototype.iushln=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26,I=67108863>>>26-x<<26-x,C;if(x!==0){var F=0;for(C=0;C<this.length;C++){var N=this.words[C]&I,O=(this.words[C]|0)-N<<x;this.words[C]=O|F,F=N>>>26-x}F&&(this.words[C]=F,this.length++)}if(y!==0){for(C=this.length-1;C>=0;C--)this.words[C+y]=this.words[C];for(C=0;C<y;C++)this.words[C]=0;this.length+=y}return this._strip()},i.prototype.ishln=function(p){return t(this.negative===0),this.iushln(p)},i.prototype.iushrn=function(p,x,y){t(typeof p=="number"&&p>=0);var I;x?I=(x-x%26)/26:I=0;var C=p%26,F=Math.min((p-C)/26,this.length),N=67108863^67108863>>>C<<C,O=y;if(I-=F,I=Math.max(0,I),O){for(var T=0;T<F;T++)O.words[T]=this.words[T];O.length=F}if(F!==0)if(this.length>F)for(this.length-=F,T=0;T<this.length;T++)this.words[T]=this.words[T+F];else this.words[0]=0,this.length=1;var q=0;for(T=this.length-1;T>=0&&(q!==0||T>=I);T--){var _=this.words[T]|0;this.words[T]=q<<26-C|_>>>C,q=_&N}return O&&q!==0&&(O.words[O.length++]=q),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(p,x,y){return t(this.negative===0),this.iushrn(p,x,y)},i.prototype.shln=function(p){return this.clone().ishln(p)},i.prototype.ushln=function(p){return this.clone().iushln(p)},i.prototype.shrn=function(p){return this.clone().ishrn(p)},i.prototype.ushrn=function(p){return this.clone().iushrn(p)},i.prototype.testn=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26,I=1<<x;if(this.length<=y)return!1;var C=this.words[y];return!!(C&I)},i.prototype.imaskn=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=y)return this;if(x!==0&&y++,this.length=Math.min(y,this.length),x!==0){var I=67108863^67108863>>>x<<x;this.words[this.length-1]&=I}return this._strip()},i.prototype.maskn=function(p){return this.clone().imaskn(p)},i.prototype.iaddn=function(p){return t(typeof p=="number"),t(p<67108864),p<0?this.isubn(-p):this.negative!==0?this.length===1&&(this.words[0]|0)<=p?(this.words[0]=p-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(p),this.negative=1,this):this._iaddn(p)},i.prototype._iaddn=function(p){this.words[0]+=p;for(var x=0;x<this.length&&this.words[x]>=67108864;x++)this.words[x]-=67108864,x===this.length-1?this.words[x+1]=1:this.words[x+1]++;return this.length=Math.max(this.length,x+1),this},i.prototype.isubn=function(p){if(t(typeof p=="number"),t(p<67108864),p<0)return this.iaddn(-p);if(this.negative!==0)return this.negative=0,this.iaddn(p),this.negative=1,this;if(this.words[0]-=p,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var x=0;x<this.length&&this.words[x]<0;x++)this.words[x]+=67108864,this.words[x+1]-=1;return this._strip()},i.prototype.addn=function(p){return this.clone().iaddn(p)},i.prototype.subn=function(p){return this.clone().isubn(p)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(p,x,y){var I=p.length+y,C;this._expand(I);var F,N=0;for(C=0;C<p.length;C++){F=(this.words[C+y]|0)+N;var O=(p.words[C]|0)*x;F-=O&67108863,N=(F>>26)-(O/67108864|0),this.words[C+y]=F&67108863}for(;C<this.length-y;C++)F=(this.words[C+y]|0)+N,N=F>>26,this.words[C+y]=F&67108863;if(N===0)return this._strip();for(t(N===-1),N=0,C=0;C<this.length;C++)F=-(this.words[C]|0)+N,N=F>>26,this.words[C]=F&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(p,x){var y=this.length-p.length,I=this.clone(),C=p,F=C.words[C.length-1]|0,N=this._countBits(F);y=26-N,y!==0&&(C=C.ushln(y),I.iushln(y),F=C.words[C.length-1]|0);var O=I.length-C.length,T;if(x!=="mod"){T=new i(null),T.length=O+1,T.words=new Array(T.length);for(var q=0;q<T.length;q++)T.words[q]=0}var _=I.clone()._ishlnsubmul(C,1,O);_.negative===0&&(I=_,T&&(T.words[O]=1));for(var L=O-1;L>=0;L--){var g=(I.words[C.length+L]|0)*67108864+(I.words[C.length+L-1]|0);for(g=Math.min(g/F|0,67108863),I._ishlnsubmul(C,g,L);I.negative!==0;)g--,I.negative=0,I._ishlnsubmul(C,1,L),I.isZero()||(I.negative^=1);T&&(T.words[L]=g)}return T&&T._strip(),I._strip(),x!=="div"&&y!==0&&I.iushrn(y),{div:T||null,mod:I}},i.prototype.divmod=function(p,x,y){if(t(!p.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var I,C,F;return this.negative!==0&&p.negative===0?(F=this.neg().divmod(p,x),x!=="mod"&&(I=F.div.neg()),x!=="div"&&(C=F.mod.neg(),y&&C.negative!==0&&C.iadd(p)),{div:I,mod:C}):this.negative===0&&p.negative!==0?(F=this.divmod(p.neg(),x),x!=="mod"&&(I=F.div.neg()),{div:I,mod:F.mod}):(this.negative&p.negative)!==0?(F=this.neg().divmod(p.neg(),x),x!=="div"&&(C=F.mod.neg(),y&&C.negative!==0&&C.isub(p)),{div:F.div,mod:C}):p.length>this.length||this.cmp(p)<0?{div:new i(0),mod:this}:p.length===1?x==="div"?{div:this.divn(p.words[0]),mod:null}:x==="mod"?{div:null,mod:new i(this.modrn(p.words[0]))}:{div:this.divn(p.words[0]),mod:new i(this.modrn(p.words[0]))}:this._wordDiv(p,x)},i.prototype.div=function(p){return this.divmod(p,"div",!1).div},i.prototype.mod=function(p){return this.divmod(p,"mod",!1).mod},i.prototype.umod=function(p){return this.divmod(p,"mod",!0).mod},i.prototype.divRound=function(p){var x=this.divmod(p);if(x.mod.isZero())return x.div;var y=x.div.negative!==0?x.mod.isub(p):x.mod,I=p.ushrn(1),C=p.andln(1),F=y.cmp(I);return F<0||C===1&&F===0?x.div:x.div.negative!==0?x.div.isubn(1):x.div.iaddn(1)},i.prototype.modrn=function(p){var x=p<0;x&&(p=-p),t(p<=67108863);for(var y=(1<<26)%p,I=0,C=this.length-1;C>=0;C--)I=(y*I+(this.words[C]|0))%p;return x?-I:I},i.prototype.modn=function(p){return this.modrn(p)},i.prototype.idivn=function(p){var x=p<0;x&&(p=-p),t(p<=67108863);for(var y=0,I=this.length-1;I>=0;I--){var C=(this.words[I]|0)+y*67108864;this.words[I]=C/p|0,y=C%p}return this._strip(),x?this.ineg():this},i.prototype.divn=function(p){return this.clone().idivn(p)},i.prototype.egcd=function(p){t(p.negative===0),t(!p.isZero());var x=this,y=p.clone();x.negative!==0?x=x.umod(p):x=x.clone();for(var I=new i(1),C=new i(0),F=new i(0),N=new i(1),O=0;x.isEven()&&y.isEven();)x.iushrn(1),y.iushrn(1),++O;for(var T=y.clone(),q=x.clone();!x.isZero();){for(var _=0,L=1;(x.words[0]&L)===0&&_<26;++_,L<<=1);if(_>0)for(x.iushrn(_);_-- >0;)(I.isOdd()||C.isOdd())&&(I.iadd(T),C.isub(q)),I.iushrn(1),C.iushrn(1);for(var g=0,K=1;(y.words[0]&K)===0&&g<26;++g,K<<=1);if(g>0)for(y.iushrn(g);g-- >0;)(F.isOdd()||N.isOdd())&&(F.iadd(T),N.isub(q)),F.iushrn(1),N.iushrn(1);x.cmp(y)>=0?(x.isub(y),I.isub(F),C.isub(N)):(y.isub(x),F.isub(I),N.isub(C))}return{a:F,b:N,gcd:y.iushln(O)}},i.prototype._invmp=function(p){t(p.negative===0),t(!p.isZero());var x=this,y=p.clone();x.negative!==0?x=x.umod(p):x=x.clone();for(var I=new i(1),C=new i(0),F=y.clone();x.cmpn(1)>0&&y.cmpn(1)>0;){for(var N=0,O=1;(x.words[0]&O)===0&&N<26;++N,O<<=1);if(N>0)for(x.iushrn(N);N-- >0;)I.isOdd()&&I.iadd(F),I.iushrn(1);for(var T=0,q=1;(y.words[0]&q)===0&&T<26;++T,q<<=1);if(T>0)for(y.iushrn(T);T-- >0;)C.isOdd()&&C.iadd(F),C.iushrn(1);x.cmp(y)>=0?(x.isub(y),I.isub(C)):(y.isub(x),C.isub(I))}var _;return x.cmpn(1)===0?_=I:_=C,_.cmpn(0)<0&&_.iadd(p),_},i.prototype.gcd=function(p){if(this.isZero())return p.abs();if(p.isZero())return this.abs();var x=this.clone(),y=p.clone();x.negative=0,y.negative=0;for(var I=0;x.isEven()&&y.isEven();I++)x.iushrn(1),y.iushrn(1);do{for(;x.isEven();)x.iushrn(1);for(;y.isEven();)y.iushrn(1);var C=x.cmp(y);if(C<0){var F=x;x=y,y=F}else if(C===0||y.cmpn(1)===0)break;x.isub(y)}while(!0);return y.iushln(I)},i.prototype.invm=function(p){return this.egcd(p).a.umod(p)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(p){return this.words[0]&p},i.prototype.bincn=function(p){t(typeof p=="number");var x=p%26,y=(p-x)/26,I=1<<x;if(this.length<=y)return this._expand(y+1),this.words[y]|=I,this;for(var C=I,F=y;C!==0&&F<this.length;F++){var N=this.words[F]|0;N+=C,C=N>>>26,N&=67108863,this.words[F]=N}return C!==0&&(this.words[F]=C,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(p){var x=p<0;if(this.negative!==0&&!x)return-1;if(this.negative===0&&x)return 1;this._strip();var y;if(this.length>1)y=1;else{x&&(p=-p),t(p<=67108863,"Number is too big");var I=this.words[0]|0;y=I===p?0:I<p?-1:1}return this.negative!==0?-y|0:y},i.prototype.cmp=function(p){if(this.negative!==0&&p.negative===0)return-1;if(this.negative===0&&p.negative!==0)return 1;var x=this.ucmp(p);return this.negative!==0?-x|0:x},i.prototype.ucmp=function(p){if(this.length>p.length)return 1;if(this.length<p.length)return-1;for(var x=0,y=this.length-1;y>=0;y--){var I=this.words[y]|0,C=p.words[y]|0;if(I!==C){I<C?x=-1:I>C&&(x=1);break}}return x},i.prototype.gtn=function(p){return this.cmpn(p)===1},i.prototype.gt=function(p){return this.cmp(p)===1},i.prototype.gten=function(p){return this.cmpn(p)>=0},i.prototype.gte=function(p){return this.cmp(p)>=0},i.prototype.ltn=function(p){return this.cmpn(p)===-1},i.prototype.lt=function(p){return this.cmp(p)===-1},i.prototype.lten=function(p){return this.cmpn(p)<=0},i.prototype.lte=function(p){return this.cmp(p)<=0},i.prototype.eqn=function(p){return this.cmpn(p)===0},i.prototype.eq=function(p){return this.cmp(p)===0},i.red=function(p){return new Y(p)},i.prototype.toRed=function(p){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),p.convertTo(this)._forceRed(p)},i.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(p){return this.red=p,this},i.prototype.forceRed=function(p){return t(!this.red,"Already a number in reduction context"),this._forceRed(p)},i.prototype.redAdd=function(p){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,p)},i.prototype.redIAdd=function(p){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,p)},i.prototype.redSub=function(p){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,p)},i.prototype.redISub=function(p){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,p)},i.prototype.redShl=function(p){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,p)},i.prototype.redMul=function(p){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,p),this.red.mul(this,p)},i.prototype.redIMul=function(p){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,p),this.red.imul(this,p)},i.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(p){return t(this.red&&!p.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,p)};var H={k256:null,p224:null,p192:null,p25519:null};function M(v,p){this.name=v,this.p=new i(p,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}M.prototype._tmp=function(){var p=new i(null);return p.words=new Array(Math.ceil(this.n/13)),p},M.prototype.ireduce=function(p){var x=p,y;do this.split(x,this.tmp),x=this.imulK(x),x=x.iadd(this.tmp),y=x.bitLength();while(y>this.n);var I=y<this.n?-1:x.ucmp(this.p);return I===0?(x.words[0]=0,x.length=1):I>0?x.isub(this.p):x.strip!==void 0?x.strip():x._strip(),x},M.prototype.split=function(p,x){p.iushrn(this.n,0,x)},M.prototype.imulK=function(p){return p.imul(this.k)};function A(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(A,M),A.prototype.split=function(p,x){for(var y=4194303,I=Math.min(p.length,9),C=0;C<I;C++)x.words[C]=p.words[C];if(x.length=I,p.length<=9){p.words[0]=0,p.length=1;return}var F=p.words[9];for(x.words[x.length++]=F&y,C=10;C<p.length;C++){var N=p.words[C]|0;p.words[C-10]=(N&y)<<4|F>>>22,F=N}F>>>=22,p.words[C-10]=F,F===0&&p.length>10?p.length-=10:p.length-=9},A.prototype.imulK=function(p){p.words[p.length]=0,p.words[p.length+1]=0,p.length+=2;for(var x=0,y=0;y<p.length;y++){var I=p.words[y]|0;x+=I*977,p.words[y]=x&67108863,x=I*64+(x/67108864|0)}return p.words[p.length-1]===0&&(p.length--,p.words[p.length-1]===0&&p.length--),p};function D(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(D,M);function z(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(z,M);function j(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(j,M),j.prototype.imulK=function(p){for(var x=0,y=0;y<p.length;y++){var I=(p.words[y]|0)*19+x,C=I&67108863;I>>>=26,p.words[y]=C,x=I}return x!==0&&(p.words[p.length++]=x),p},i._prime=function(p){if(H[p])return H[p];var x;if(p==="k256")x=new A;else if(p==="p224")x=new D;else if(p==="p192")x=new z;else if(p==="p25519")x=new j;else throw new Error("Unknown prime "+p);return H[p]=x,x};function Y(v){if(typeof v=="string"){var p=i._prime(v);this.m=p.p,this.prime=p}else t(v.gtn(1),"modulus must be greater than 1"),this.m=v,this.prime=null}Y.prototype._verify1=function(p){t(p.negative===0,"red works only with positives"),t(p.red,"red works only with red numbers")},Y.prototype._verify2=function(p,x){t((p.negative|x.negative)===0,"red works only with positives"),t(p.red&&p.red===x.red,"red works only with red numbers")},Y.prototype.imod=function(p){return this.prime?this.prime.ireduce(p)._forceRed(this):(u(p,p.umod(this.m)._forceRed(this)),p)},Y.prototype.neg=function(p){return p.isZero()?p.clone():this.m.sub(p)._forceRed(this)},Y.prototype.add=function(p,x){this._verify2(p,x);var y=p.add(x);return y.cmp(this.m)>=0&&y.isub(this.m),y._forceRed(this)},Y.prototype.iadd=function(p,x){this._verify2(p,x);var y=p.iadd(x);return y.cmp(this.m)>=0&&y.isub(this.m),y},Y.prototype.sub=function(p,x){this._verify2(p,x);var y=p.sub(x);return y.cmpn(0)<0&&y.iadd(this.m),y._forceRed(this)},Y.prototype.isub=function(p,x){this._verify2(p,x);var y=p.isub(x);return y.cmpn(0)<0&&y.iadd(this.m),y},Y.prototype.shl=function(p,x){return this._verify1(p),this.imod(p.ushln(x))},Y.prototype.imul=function(p,x){return this._verify2(p,x),this.imod(p.imul(x))},Y.prototype.mul=function(p,x){return this._verify2(p,x),this.imod(p.mul(x))},Y.prototype.isqr=function(p){return this.imul(p,p.clone())},Y.prototype.sqr=function(p){return this.mul(p,p)},Y.prototype.sqrt=function(p){if(p.isZero())return p.clone();var x=this.m.andln(3);if(t(x%2===1),x===3){var y=this.m.add(new i(1)).iushrn(2);return this.pow(p,y)}for(var I=this.m.subn(1),C=0;!I.isZero()&&I.andln(1)===0;)C++,I.iushrn(1);t(!I.isZero());var F=new i(1).toRed(this),N=F.redNeg(),O=this.m.subn(1).iushrn(1),T=this.m.bitLength();for(T=new i(2*T*T).toRed(this);this.pow(T,O).cmp(N)!==0;)T.redIAdd(N);for(var q=this.pow(T,I),_=this.pow(p,I.addn(1).iushrn(1)),L=this.pow(p,I),g=C;L.cmp(F)!==0;){for(var K=L,E=0;K.cmp(F)!==0;E++)K=K.redSqr();t(E<g);var V=this.pow(q,new i(1).iushln(g-E-1));_=_.redMul(V),q=V.redSqr(),L=L.redMul(q),g=E}return _},Y.prototype.invm=function(p){var x=p._invmp(this.m);return x.negative!==0?(x.negative=0,this.imod(x).redNeg()):this.imod(x)},Y.prototype.pow=function(p,x){if(x.isZero())return new i(1).toRed(this);if(x.cmpn(1)===0)return p.clone();var y=4,I=new Array(1<<y);I[0]=new i(1).toRed(this),I[1]=p;for(var C=2;C<I.length;C++)I[C]=this.mul(I[C-1],p);var F=I[0],N=0,O=0,T=x.bitLength()%26;for(T===0&&(T=26),C=x.length-1;C>=0;C--){for(var q=x.words[C],_=T-1;_>=0;_--){var L=q>>_&1;if(F!==I[0]&&(F=this.sqr(F)),L===0&&N===0){O=0;continue}N<<=1,N|=L,O++,!(O!==y&&(C!==0||_!==0))&&(F=this.mul(F,I[N]),O=0,N=0)}T=26}return F},Y.prototype.convertTo=function(p){var x=p.umod(this.m);return x===p?x.clone():x},Y.prototype.convertFrom=function(p){var x=p.clone();return x.red=null,x},i.mont=function(p){return new Q(p)};function Q(v){Y.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(Q,Y),Q.prototype.convertTo=function(p){return this.imod(p.ushln(this.shift))},Q.prototype.convertFrom=function(p){var x=this.imod(p.mul(this.rinv));return x.red=null,x},Q.prototype.imul=function(p,x){if(p.isZero()||x.isZero())return p.words[0]=0,p.length=1,p;var y=p.imul(x),I=y.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),C=y.isub(I).iushrn(this.shift),F=C;return C.cmp(this.m)>=0?F=C.isub(this.m):C.cmpn(0)<0&&(F=C.iadd(this.m)),F._forceRed(this)},Q.prototype.mul=function(p,x){if(p.isZero()||x.isZero())return new i(0)._forceRed(this);var y=p.mul(x),I=y.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),C=y.isub(I).iushrn(this.shift),F=C;return C.cmp(this.m)>=0?F=C.isub(this.m):C.cmpn(0)<0&&(F=C.iadd(this.m)),F._forceRed(this)},Q.prototype.invm=function(p){var x=this.imod(p._invmp(this.m).mul(this.r2));return x._forceRed(this)}})(typeof FR>"u"||FR,W9)});var _9=oe(Sx=>{"use strict";Sx.byteLength=Pce;Sx.toByteArray=Mce;Sx.fromByteArray=Nce;var cu=[],wa=[],Bce=typeof Uint8Array<"u"?Uint8Array:Array,UR="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(wp=0,Z9=UR.length;wp<Z9;++wp)cu[wp]=UR[wp],wa[UR.charCodeAt(wp)]=wp;var wp,Z9;wa[45]=62;wa[95]=63;function X9(n){var e=n.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=n.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function Pce(n){var e=X9(n),t=e[0],r=e[1];return(t+r)*3/4-r}function kce(n,e,t){return(e+t)*3/4-t}function Mce(n){var e,t=X9(n),r=t[0],i=t[1],o=new Bce(kce(n,r,i)),s=0,a=i>0?r-4:r,c;for(c=0;c<a;c+=4)e=wa[n.charCodeAt(c)]<<18|wa[n.charCodeAt(c+1)]<<12|wa[n.charCodeAt(c+2)]<<6|wa[n.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=wa[n.charCodeAt(c)]<<2|wa[n.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=wa[n.charCodeAt(c)]<<10|wa[n.charCodeAt(c+1)]<<4|wa[n.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Oce(n){return cu[n>>18&63]+cu[n>>12&63]+cu[n>>6&63]+cu[n&63]}function Fce(n,e,t){for(var r,i=[],o=e;o<t;o+=3)r=(n[o]<<16&16711680)+(n[o+1]<<8&65280)+(n[o+2]&255),i.push(Oce(r));return i.join("")}function Nce(n){for(var e,t=n.length,r=t%3,i=[],o=16383,s=0,a=t-r;s<a;s+=o)i.push(Fce(n,s,s+o>a?a:s+o));return r===1?(e=n[t-1],i.push(cu[e>>2]+cu[e<<4&63]+"==")):r===2&&(e=(n[t-2]<<8)+n[t-1],i.push(cu[e>>10]+cu[e>>4&63]+cu[e<<2&63]+"=")),i.join("")}});var $9=oe(GR=>{"use strict";GR.read=function(n,e,t,r,i){var o,s,a=i*8-r-1,c=(1<<a)-1,u=c>>1,l=-7,d=t?i-1:0,h=t?-1:1,f=n[e+d];for(d+=h,o=f&(1<<-l)-1,f>>=-l,l+=a;l>0;o=o*256+n[e+d],d+=h,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=s*256+n[e+d],d+=h,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(f?-1:1)*(1/0);s=s+Math.pow(2,r),o=o-u}return(f?-1:1)*s*Math.pow(2,o-r)};GR.write=function(n,e,t,r,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,d=l>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,m=r?1:-1,w=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=h/c:e+=h*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*c-1)*Math.pow(2,i),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;n[t+f]=a&255,f+=m,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;n[t+f]=s&255,f+=m,s/=256,u-=8);n[t+f-m]|=w*128}});var _m=oe(Xm=>{"use strict";var HR=_9(),Wm=$9(),eH=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Xm.Buffer=Ee;Xm.SlowBuffer=qce;Xm.INSPECT_MAX_BYTES=50;var Cx=2147483647;Xm.kMaxLength=Cx;Ee.TYPED_ARRAY_SUPPORT=Uce();!Ee.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Uce(){try{let n=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(n,e),n.foo()===42}catch{return!1}}Object.defineProperty(Ee.prototype,"parent",{enumerable:!0,get:function(){if(Ee.isBuffer(this))return this.buffer}});Object.defineProperty(Ee.prototype,"offset",{enumerable:!0,get:function(){if(Ee.isBuffer(this))return this.byteOffset}});function Il(n){if(n>Cx)throw new RangeError('The value "'+n+'" is invalid for option "size"');let e=new Uint8Array(n);return Object.setPrototypeOf(e,Ee.prototype),e}function Ee(n,e,t){if(typeof n=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return VR(n)}return iH(n,e,t)}Ee.poolSize=8192;function iH(n,e,t){if(typeof n=="string")return Hce(n,e);if(ArrayBuffer.isView(n))return Kce(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(uu(n,ArrayBuffer)||n&&uu(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(uu(n,SharedArrayBuffer)||n&&uu(n.buffer,SharedArrayBuffer)))return JR(n,e,t);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=n.valueOf&&n.valueOf();if(r!=null&&r!==n)return Ee.from(r,e,t);let i=Jce(n);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return Ee.from(n[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}Ee.from=function(n,e,t){return iH(n,e,t)};Object.setPrototypeOf(Ee.prototype,Uint8Array.prototype);Object.setPrototypeOf(Ee,Uint8Array);function oH(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function Gce(n,e,t){return oH(n),n<=0?Il(n):e!==void 0?typeof t=="string"?Il(n).fill(e,t):Il(n).fill(e):Il(n)}Ee.alloc=function(n,e,t){return Gce(n,e,t)};function VR(n){return oH(n),Il(n<0?0:QR(n)|0)}Ee.allocUnsafe=function(n){return VR(n)};Ee.allocUnsafeSlow=function(n){return VR(n)};function Hce(n,e){if((typeof e!="string"||e==="")&&(e="utf8"),!Ee.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=sH(n,e)|0,r=Il(t),i=r.write(n,e);return i!==t&&(r=r.slice(0,i)),r}function KR(n){let e=n.length<0?0:QR(n.length)|0,t=Il(e);for(let r=0;r<e;r+=1)t[r]=n[r]&255;return t}function Kce(n){if(uu(n,Uint8Array)){let e=new Uint8Array(n);return JR(e.buffer,e.byteOffset,e.byteLength)}return KR(n)}function JR(n,e,t){if(e<0||n.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let r;return e===void 0&&t===void 0?r=new Uint8Array(n):t===void 0?r=new Uint8Array(n,e):r=new Uint8Array(n,e,t),Object.setPrototypeOf(r,Ee.prototype),r}function Jce(n){if(Ee.isBuffer(n)){let e=QR(n.length)|0,t=Il(e);return t.length===0||n.copy(t,0,0,e),t}if(n.length!==void 0)return typeof n.length!="number"||YR(n.length)?Il(0):KR(n);if(n.type==="Buffer"&&Array.isArray(n.data))return KR(n.data)}function QR(n){if(n>=Cx)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Cx.toString(16)+" bytes");return n|0}function qce(n){return+n!=n&&(n=0),Ee.alloc(+n)}Ee.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==Ee.prototype};Ee.compare=function(e,t){if(uu(e,Uint8Array)&&(e=Ee.from(e,e.offset,e.byteLength)),uu(t,Uint8Array)&&(t=Ee.from(t,t.offset,t.byteLength)),!Ee.isBuffer(e)||!Ee.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,i=t.length;for(let o=0,s=Math.min(r,i);o<s;++o)if(e[o]!==t[o]){r=e[o],i=t[o];break}return r<i?-1:i<r?1:0};Ee.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};Ee.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return Ee.alloc(0);let r;if(t===void 0)for(t=0,r=0;r<e.length;++r)t+=e[r].length;let i=Ee.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){let s=e[r];if(uu(s,Uint8Array))o+s.length>i.length?(Ee.isBuffer(s)||(s=Ee.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(Ee.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function sH(n,e){if(Ee.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||uu(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);let t=n.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return qR(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return mH(n).length;default:if(i)return r?-1:qR(n).length;e=(""+e).toLowerCase(),i=!0}}Ee.byteLength=sH;function Vce(n,e,t){let r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(n||(n="utf8");;)switch(n){case"hex":return eue(this,e,t);case"utf8":case"utf-8":return cH(this,e,t);case"ascii":return _ce(this,e,t);case"latin1":case"binary":return $ce(this,e,t);case"base64":return Zce(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return tue(this,e,t);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),r=!0}}Ee.prototype._isBuffer=!0;function bp(n,e,t){let r=n[e];n[e]=n[t],n[t]=r}Ee.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)bp(this,t,t+1);return this};Ee.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)bp(this,t,t+3),bp(this,t+1,t+2);return this};Ee.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)bp(this,t,t+7),bp(this,t+1,t+6),bp(this,t+2,t+5),bp(this,t+3,t+4);return this};Ee.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?cH(this,0,e):Vce.apply(this,arguments)};Ee.prototype.toLocaleString=Ee.prototype.toString;Ee.prototype.equals=function(e){if(!Ee.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:Ee.compare(this,e)===0};Ee.prototype.inspect=function(){let e="",t=Xm.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};eH&&(Ee.prototype[eH]=Ee.prototype.inspect);Ee.prototype.compare=function(e,t,r,i,o){if(uu(e,Uint8Array)&&(e=Ee.from(e,e.offset,e.byteLength)),!Ee.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),r===void 0&&(r=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||r>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=r)return 0;if(i>=o)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=r-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,r);for(let d=0;d<c;++d)if(u[d]!==l[d]){s=u[d],a=l[d];break}return s<a?-1:a<s?1:0};function aH(n,e,t,r,i){if(n.length===0)return-1;if(typeof t=="string"?(r=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,YR(t)&&(t=i?0:n.length-1),t<0&&(t=n.length+t),t>=n.length){if(i)return-1;t=n.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=Ee.from(e,r)),Ee.isBuffer(e))return e.length===0?-1:tH(n,e,t,r,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(n,e,t):Uint8Array.prototype.lastIndexOf.call(n,e,t):tH(n,[e],t,r,i);throw new TypeError("val must be string, number or Buffer")}function tH(n,e,t,r,i){let o=1,s=n.length,a=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(n.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,d){return o===1?l[d]:l.readUInt16BE(d*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(n,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let d=0;d<a;d++)if(c(n,u+d)!==c(e,d)){l=!1;break}if(l)return u}return-1}Ee.prototype.includes=function(e,t,r){return this.indexOf(e,t,r)!==-1};Ee.prototype.indexOf=function(e,t,r){return aH(this,e,t,r,!0)};Ee.prototype.lastIndexOf=function(e,t,r){return aH(this,e,t,r,!1)};function Qce(n,e,t,r){t=Number(t)||0;let i=n.length-t;r?(r=Number(r),r>i&&(r=i)):r=i;let o=e.length;r>o/2&&(r=o/2);let s;for(s=0;s<r;++s){let a=parseInt(e.substr(s*2,2),16);if(YR(a))return s;n[t+s]=a}return s}function zce(n,e,t,r){return Lx(qR(e,n.length-t),n,t,r)}function Yce(n,e,t,r){return Lx(oue(e),n,t,r)}function jce(n,e,t,r){return Lx(mH(e),n,t,r)}function Wce(n,e,t,r){return Lx(sue(e,n.length-t),n,t,r)}Ee.prototype.write=function(e,t,r,i){if(t===void 0)i="utf8",r=this.length,t=0;else if(r===void 0&&typeof t=="string")i=t,r=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(r)?(r=r>>>0,i===void 0&&(i="utf8")):(i=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((r===void 0||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Qce(this,e,t,r);case"utf8":case"utf-8":return zce(this,e,t,r);case"ascii":case"latin1":case"binary":return Yce(this,e,t,r);case"base64":return jce(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Wce(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};Ee.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Zce(n,e,t){return e===0&&t===n.length?HR.fromByteArray(n):HR.fromByteArray(n.slice(e,t))}function cH(n,e,t){t=Math.min(n.length,t);let r=[],i=e;for(;i<t;){let o=n[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=n[i+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=n[i+1],u=n[i+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=n[i+1],u=n[i+2],l=n[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),i+=a}return Xce(r)}var nH=4096;function Xce(n){let e=n.length;if(e<=nH)return String.fromCharCode.apply(String,n);let t="",r=0;for(;r<e;)t+=String.fromCharCode.apply(String,n.slice(r,r+=nH));return t}function _ce(n,e,t){let r="";t=Math.min(n.length,t);for(let i=e;i<t;++i)r+=String.fromCharCode(n[i]&127);return r}function $ce(n,e,t){let r="";t=Math.min(n.length,t);for(let i=e;i<t;++i)r+=String.fromCharCode(n[i]);return r}function eue(n,e,t){let r=n.length;(!e||e<0)&&(e=0),(!t||t<0||t>r)&&(t=r);let i="";for(let o=e;o<t;++o)i+=aue[n[o]];return i}function tue(n,e,t){let r=n.slice(e,t),i="";for(let o=0;o<r.length-1;o+=2)i+=String.fromCharCode(r[o]+r[o+1]*256);return i}Ee.prototype.slice=function(e,t){let r=this.length;e=~~e,t=t===void 0?r:~~t,e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,Ee.prototype),i};function ii(n,e,t){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+e>t)throw new RangeError("Trying to access beyond buffer length")}Ee.prototype.readUintLE=Ee.prototype.readUIntLE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};Ee.prototype.readUintBE=Ee.prototype.readUIntBE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};Ee.prototype.readUint8=Ee.prototype.readUInt8=function(e,t){return e=e>>>0,t||ii(e,1,this.length),this[e]};Ee.prototype.readUint16LE=Ee.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||ii(e,2,this.length),this[e]|this[e+1]<<8};Ee.prototype.readUint16BE=Ee.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||ii(e,2,this.length),this[e]<<8|this[e+1]};Ee.prototype.readUint32LE=Ee.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};Ee.prototype.readUint32BE=Ee.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};Ee.prototype.readBigUInt64LE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+r*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});Ee.prototype.readBigUInt64BE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r;return(BigInt(i)<<BigInt(32))+BigInt(o)});Ee.prototype.readIntLE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};Ee.prototype.readIntBE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};Ee.prototype.readInt8=function(e,t){return e=e>>>0,t||ii(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};Ee.prototype.readInt16LE=function(e,t){e=e>>>0,t||ii(e,2,this.length);let r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};Ee.prototype.readInt16BE=function(e,t){e=e>>>0,t||ii(e,2,this.length);let r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};Ee.prototype.readInt32LE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};Ee.prototype.readInt32BE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};Ee.prototype.readBigInt64LE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(r<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});Ee.prototype.readBigInt64BE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r)});Ee.prototype.readFloatLE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),Wm.read(this,e,!0,23,4)};Ee.prototype.readFloatBE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),Wm.read(this,e,!1,23,4)};Ee.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||ii(e,8,this.length),Wm.read(this,e,!0,52,8)};Ee.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||ii(e,8,this.length),Wm.read(this,e,!1,52,8)};function rs(n,e,t,r,i,o){if(!Ee.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+r>n.length)throw new RangeError("Index out of range")}Ee.prototype.writeUintLE=Ee.prototype.writeUIntLE=function(e,t,r,i){if(e=+e,t=t>>>0,r=r>>>0,!i){let a=Math.pow(2,8*r)-1;rs(this,e,t,r,a,0)}let o=1,s=0;for(this[t]=e&255;++s<r&&(o*=256);)this[t+s]=e/o&255;return t+r};Ee.prototype.writeUintBE=Ee.prototype.writeUIntBE=function(e,t,r,i){if(e=+e,t=t>>>0,r=r>>>0,!i){let a=Math.pow(2,8*r)-1;rs(this,e,t,r,a,0)}let o=r-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+r};Ee.prototype.writeUint8=Ee.prototype.writeUInt8=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,1,255,0),this[t]=e&255,t+1};Ee.prototype.writeUint16LE=Ee.prototype.writeUInt16LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};Ee.prototype.writeUint16BE=Ee.prototype.writeUInt16BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};Ee.prototype.writeUint32LE=Ee.prototype.writeUInt32LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};Ee.prototype.writeUint32BE=Ee.prototype.writeUInt32BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function uH(n,e,t,r,i){pH(e,r,i,n,t,7);let o=Number(e&BigInt(4294967295));n[t++]=o,o=o>>8,n[t++]=o,o=o>>8,n[t++]=o,o=o>>8,n[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return n[t++]=s,s=s>>8,n[t++]=s,s=s>>8,n[t++]=s,s=s>>8,n[t++]=s,t}function lH(n,e,t,r,i){pH(e,r,i,n,t,7);let o=Number(e&BigInt(4294967295));n[t+7]=o,o=o>>8,n[t+6]=o,o=o>>8,n[t+5]=o,o=o>>8,n[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return n[t+3]=s,s=s>>8,n[t+2]=s,s=s>>8,n[t+1]=s,s=s>>8,n[t]=s,t+8}Ee.prototype.writeBigUInt64LE=mf(function(e,t=0){return uH(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});Ee.prototype.writeBigUInt64BE=mf(function(e,t=0){return lH(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});Ee.prototype.writeIntLE=function(e,t,r,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*r-1);rs(this,e,t,r,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<r&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r};Ee.prototype.writeIntBE=function(e,t,r,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*r-1);rs(this,e,t,r,c-1,-c)}let o=r-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r};Ee.prototype.writeInt8=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};Ee.prototype.writeInt16LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};Ee.prototype.writeInt16BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};Ee.prototype.writeInt32LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};Ee.prototype.writeInt32BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};Ee.prototype.writeBigInt64LE=mf(function(e,t=0){return uH(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});Ee.prototype.writeBigInt64BE=mf(function(e,t=0){return lH(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function dH(n,e,t,r,i,o){if(t+r>n.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function fH(n,e,t,r,i){return e=+e,t=t>>>0,i||dH(n,e,t,4,34028234663852886e22,-34028234663852886e22),Wm.write(n,e,t,r,23,4),t+4}Ee.prototype.writeFloatLE=function(e,t,r){return fH(this,e,t,!0,r)};Ee.prototype.writeFloatBE=function(e,t,r){return fH(this,e,t,!1,r)};function hH(n,e,t,r,i){return e=+e,t=t>>>0,i||dH(n,e,t,8,17976931348623157e292,-17976931348623157e292),Wm.write(n,e,t,r,52,8),t+8}Ee.prototype.writeDoubleLE=function(e,t,r){return hH(this,e,t,!0,r)};Ee.prototype.writeDoubleBE=function(e,t,r){return hH(this,e,t,!1,r)};Ee.prototype.copy=function(e,t,r,i){if(!Ee.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<r&&(i=r),i===r||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-r&&(i=e.length-t+r);let o=i-r;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,r,i):Uint8Array.prototype.set.call(e,this.subarray(r,i),t),o};Ee.prototype.fill=function(e,t,r,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,r=this.length):typeof r=="string"&&(i=r,r=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!Ee.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;t=t>>>0,r=r===void 0?this.length:r>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<r;++o)this[o]=e;else{let s=Ee.isBuffer(e)?e:Ee.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var jm={};function zR(n,e,t){jm[n]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${n}]`,this.stack,delete this.name}get code(){return n}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${n}]: ${this.message}`}}}zR("ERR_BUFFER_OUT_OF_BOUNDS",function(n){return n?`${n} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);zR("ERR_INVALID_ARG_TYPE",function(n,e){return`The "${n}" argument must be of type number. Received type ${typeof e}`},TypeError);zR("ERR_OUT_OF_RANGE",function(n,e,t){let r=`The value of "${n}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=rH(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=rH(i)),i+="n"),r+=` It must be ${e}. Received ${i}`,r},RangeError);function rH(n){let e="",t=n.length,r=n[0]==="-"?1:0;for(;t>=r+4;t-=3)e=`_${n.slice(t-3,t)}${e}`;return`${n.slice(0,t)}${e}`}function nue(n,e,t){Zm(e,"offset"),(n[e]===void 0||n[e+t]===void 0)&&pb(e,n.length-(t+1))}function pH(n,e,t,r,i,o){if(n>t||n<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new jm.ERR_OUT_OF_RANGE("value",a,n)}nue(r,i,o)}function Zm(n,e){if(typeof n!="number")throw new jm.ERR_INVALID_ARG_TYPE(e,"number",n)}function pb(n,e,t){throw Math.floor(n)!==n?(Zm(n,t),new jm.ERR_OUT_OF_RANGE(t||"offset","an integer",n)):e<0?new jm.ERR_BUFFER_OUT_OF_BOUNDS:new jm.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,n)}var rue=/[^+/0-9A-Za-z-_]/g;function iue(n){if(n=n.split("=")[0],n=n.trim().replace(rue,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function qR(n,e){e=e||1/0;let t,r=n.length,i=null,o=[];for(let s=0;s<r;++s){if(t=n.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function oue(n){let e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t)&255);return e}function sue(n,e){let t,r,i,o=[];for(let s=0;s<n.length&&!((e-=2)<0);++s)t=n.charCodeAt(s),r=t>>8,i=t%256,o.push(i),o.push(r);return o}function mH(n){return HR.toByteArray(iue(n))}function Lx(n,e,t,r){let i;for(i=0;i<r&&!(i+t>=e.length||i>=n.length);++i)e[i+t]=n[i];return i}function uu(n,e){return n instanceof e||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===e.name}function YR(n){return n!==n}var aue=(function(){let n="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let r=t*16;for(let i=0;i<16;++i)e[r+i]=n[t]+n[i]}return e})();function mf(n){return typeof BigInt>"u"?cue:n}function cue(){throw new Error("BigInt not supported")}});var WR=oe((jR,yH)=>{"use strict";var Rx=_m(),lu=Rx.Buffer;function gH(n,e){for(var t in n)e[t]=n[t]}lu.from&&lu.alloc&&lu.allocUnsafe&&lu.allocUnsafeSlow?yH.exports=Rx:(gH(Rx,jR),jR.Buffer=Ep);function Ep(n,e,t){return lu(n,e,t)}Ep.prototype=Object.create(lu.prototype);gH(lu,Ep);Ep.from=function(n,e,t){if(typeof n=="number")throw new TypeError("Argument must not be a number");return lu(n,e,t)};Ep.alloc=function(n,e,t){if(typeof n!="number")throw new TypeError("Argument must be a number");var r=lu(n);return e!==void 0?typeof t=="string"?r.fill(e,t):r.fill(e):r.fill(0),r};Ep.allocUnsafe=function(n){if(typeof n!="number")throw new TypeError("Argument must be a number");return lu(n)};Ep.allocUnsafeSlow=function(n){if(typeof n!="number")throw new TypeError("Argument must be a number");return Rx.SlowBuffer(n)}});var bH=oe((l7e,wH)=>{"use strict";var Dx=WR().Buffer;function uue(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if((Array.isArray(f)||f instanceof Uint8Array)&&(f=Dx.from(f)),!Dx.isBuffer(f))throw new TypeError("Expected Buffer");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return Dx.alloc(0);for(var m=0,w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);m<f.length;){var G=f.charCodeAt(m);if(G>255)return;var U=e[G];if(U===255)return;for(var H=0,M=S-1;(U!==0||H<b)&&M!==-1;M--,H++)U+=s*R[M]>>>0,R[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=H,m++}for(var A=S-b;A!==S&&R[A]===0;)A++;var D=Dx.allocUnsafe(w+(S-A));D.fill(0,0,w);for(var z=w;A!==S;)D[z++]=R[A++];return D}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}wH.exports=uue});var IH=oe((d7e,EH)=>{"use strict";var lue=bH(),due="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";EH.exports=lue(due)});var AH=oe(_R=>{"use strict";function Al(n,e,t){return e<=n&&n<=t}function Mx(n){if(n===void 0)return{};if(n===Object(n))return n;throw TypeError("Could not convert argument to dictionary")}function fue(n){for(var e=String(n),t=e.length,r=0,i=[];r<t;){var o=e.charCodeAt(r);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(r===t-1)i.push(65533);else{var s=n.charCodeAt(r+1);if(56320<=s&&s<=57343){var a=o&1023,c=s&1023;i.push(65536+(a<<10)+c),r+=1}else i.push(65533)}r+=1}return i}function hue(n){for(var e="",t=0;t<n.length;++t){var r=n[t];r<=65535?e+=String.fromCharCode(r):(r-=65536,e+=String.fromCharCode((r>>10)+55296,(r&1023)+56320))}return e}var Tx=-1;function XR(n){this.tokens=[].slice.call(n)}XR.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Tx},prepend:function(n){if(Array.isArray(n))for(var e=n;e.length;)this.tokens.unshift(e.pop());else this.tokens.unshift(n)},push:function(n){if(Array.isArray(n))for(var e=n;e.length;)this.tokens.push(e.shift());else this.tokens.push(n)}};var $m=-1;function ZR(n,e){if(n)throw TypeError("Decoder error");return e||65533}var Bx="utf-8";function Px(n,e){if(!(this instanceof Px))return new Px(n,e);if(n=n!==void 0?String(n).toLowerCase():Bx,n!==Bx)throw new Error("Encoding not supported. Only utf-8 is supported");e=Mx(e),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=!!e.fatal,this._ignoreBOM=!!e.ignoreBOM,Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}Px.prototype={decode:function(e,t){var r;typeof e=="object"&&e instanceof ArrayBuffer?r=new Uint8Array(e):typeof e=="object"&&"buffer"in e&&e.buffer instanceof ArrayBuffer?r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):r=new Uint8Array(0),t=Mx(t),this._streaming||(this._decoder=new pue({fatal:this._fatal}),this._BOMseen=!1),this._streaming=!!t.stream;for(var i=new XR(r),o=[],s;!i.endOfStream()&&(s=this._decoder.handler(i,i.read()),s!==$m);)s!==null&&(Array.isArray(s)?o.push.apply(o,s):o.push(s));if(!this._streaming){do{if(s=this._decoder.handler(i,i.read()),s===$m)break;s!==null&&(Array.isArray(s)?o.push.apply(o,s):o.push(s))}while(!i.endOfStream());this._decoder=null}return o.length&&["utf-8"].indexOf(this.encoding)!==-1&&!this._ignoreBOM&&!this._BOMseen&&(o[0]===65279?(this._BOMseen=!0,o.shift()):this._BOMseen=!0),hue(o)}};function kx(n,e){if(!(this instanceof kx))return new kx(n,e);if(n=n!==void 0?String(n).toLowerCase():Bx,n!==Bx)throw new Error("Encoding not supported. Only utf-8 is supported");e=Mx(e),this._streaming=!1,this._encoder=null,this._options={fatal:!!e.fatal},Object.defineProperty(this,"encoding",{value:"utf-8"})}kx.prototype={encode:function(e,t){e=e?String(e):"",t=Mx(t),this._streaming||(this._encoder=new mue(this._options)),this._streaming=!!t.stream;for(var r=[],i=new XR(fue(e)),o;!i.endOfStream()&&(o=this._encoder.handler(i,i.read()),o!==$m);)Array.isArray(o)?r.push.apply(r,o):r.push(o);if(!this._streaming){for(;o=this._encoder.handler(i,i.read()),o!==$m;)Array.isArray(o)?r.push.apply(r,o):r.push(o);this._encoder=null}return new Uint8Array(r)}};function pue(n){var e=n.fatal,t=0,r=0,i=0,o=128,s=191;this.handler=function(a,c){if(c===Tx&&i!==0)return i=0,ZR(e);if(c===Tx)return $m;if(i===0){if(Al(c,0,127))return c;if(Al(c,194,223))i=1,t=c-192;else if(Al(c,224,239))c===224&&(o=160),c===237&&(s=159),i=2,t=c-224;else if(Al(c,240,244))c===240&&(o=144),c===244&&(s=143),i=3,t=c-240;else return ZR(e);return t=t<<6*i,null}if(!Al(c,o,s))return t=i=r=0,o=128,s=191,a.prepend(c),ZR(e);if(o=128,s=191,r+=1,t+=c-128<<6*(i-r),r!==i)return null;var u=t;return t=i=r=0,u}}function mue(n){var e=n.fatal;this.handler=function(t,r){if(r===Tx)return $m;if(Al(r,0,127))return r;var i,o;Al(r,128,2047)?(i=1,o=192):Al(r,2048,65535)?(i=2,o=224):Al(r,65536,1114111)&&(i=3,o=240);for(var s=[(r>>6*i)+o];i>0;){var a=r>>6*(i-1);s.push(128|a&63),i-=1}return s}}_R.TextEncoder=kx;_R.TextDecoder=Px});var tD=oe(Un=>{"use strict";var gue=Un&&Un.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=t),Object.defineProperty(n,r,{enumerable:!0,get:function(){return e[t]}})}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),yue=Un&&Un.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),du=Un&&Un.__decorate||function(n,e,t,r){var i=arguments.length,o=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,e,t,r);else for(var a=n.length-1;a>=0;a--)(s=n[a])&&(o=(i<3?s(o):i>3?s(e,t,o):s(e,t))||o);return i>3&&o&&Object.defineProperty(e,t,o),o},wue=Un&&Un.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var t in n)t!=="default"&&Object.hasOwnProperty.call(n,t)&&gue(e,n,t);return yue(e,n),e},xH=Un&&Un.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(Un,"__esModule",{value:!0});Un.deserializeUnchecked=Un.deserialize=Un.serialize=Un.BinaryReader=Un.BinaryWriter=Un.BorshError=Un.baseDecode=Un.baseEncode=void 0;var gf=xH(NR()),vH=xH(IH()),bue=wue(AH()),Eue=typeof TextDecoder!="function"?bue.TextDecoder:TextDecoder,Iue=new Eue("utf-8",{fatal:!0});function Aue(n){return typeof n=="string"&&(n=Buffer.from(n,"utf8")),vH.default.encode(Buffer.from(n))}Un.baseEncode=Aue;function xue(n){return Buffer.from(vH.default.decode(n))}Un.baseDecode=xue;var $R=1024,Ei=class extends Error{constructor(e){super(e),this.fieldPath=[],this.originalMessage=e}addToFieldPath(e){this.fieldPath.splice(0,0,e),this.message=this.originalMessage+": "+this.fieldPath.join(".")}};Un.BorshError=Ei;var Ox=class{constructor(){this.buf=Buffer.alloc($R),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=Buffer.concat([this.buf,Buffer.alloc($R)]))}writeU8(e){this.maybeResize(),this.buf.writeUInt8(e,this.length),this.length+=1}writeU16(e){this.maybeResize(),this.buf.writeUInt16LE(e,this.length),this.length+=2}writeU32(e){this.maybeResize(),this.buf.writeUInt32LE(e,this.length),this.length+=4}writeU64(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",8)))}writeU128(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",16)))}writeU256(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",32)))}writeU512(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",64)))}writeBuffer(e){this.buf=Buffer.concat([Buffer.from(this.buf.subarray(0,this.length)),e,Buffer.alloc($R)]),this.length+=e.length}writeString(e){this.maybeResize();let t=Buffer.from(e,"utf8");this.writeU32(t.length),this.writeBuffer(t)}writeFixedArray(e){this.writeBuffer(Buffer.from(e))}writeArray(e,t){this.maybeResize(),this.writeU32(e.length);for(let r of e)this.maybeResize(),t(r)}toArray(){return this.buf.subarray(0,this.length)}};Un.BinaryWriter=Ox;function fu(n,e,t){let r=t.value;t.value=function(...i){try{return r.apply(this,i)}catch(o){if(o instanceof RangeError){let s=o.code;if(["ERR_BUFFER_OUT_OF_BOUNDS","ERR_OUT_OF_RANGE"].indexOf(s)>=0)throw new Ei("Reached the end of buffer when deserializing")}throw o}}}var wo=class{constructor(e){this.buf=e,this.offset=0}readU8(){let e=this.buf.readUInt8(this.offset);return this.offset+=1,e}readU16(){let e=this.buf.readUInt16LE(this.offset);return this.offset+=2,e}readU32(){let e=this.buf.readUInt32LE(this.offset);return this.offset+=4,e}readU64(){let e=this.readBuffer(8);return new gf.default(e,"le")}readU128(){let e=this.readBuffer(16);return new gf.default(e,"le")}readU256(){let e=this.readBuffer(32);return new gf.default(e,"le")}readU512(){let e=this.readBuffer(64);return new gf.default(e,"le")}readBuffer(e){if(this.offset+e>this.buf.length)throw new Ei(`Expected buffer length ${e} isn't within bounds`);let t=this.buf.slice(this.offset,this.offset+e);return this.offset+=e,t}readString(){let e=this.readU32(),t=this.readBuffer(e);try{return Iue.decode(t)}catch(r){throw new Ei(`Error decoding UTF-8 string: ${r}`)}}readFixedArray(e){return new Uint8Array(this.readBuffer(e))}readArray(e){let t=this.readU32(),r=Array();for(let i=0;i<t;++i)r.push(e());return r}};du([fu],wo.prototype,"readU8",null);du([fu],wo.prototype,"readU16",null);du([fu],wo.prototype,"readU32",null);du([fu],wo.prototype,"readU64",null);du([fu],wo.prototype,"readU128",null);du([fu],wo.prototype,"readU256",null);du([fu],wo.prototype,"readU512",null);du([fu],wo.prototype,"readString",null);du([fu],wo.prototype,"readFixedArray",null);du([fu],wo.prototype,"readArray",null);Un.BinaryReader=wo;function SH(n){return n.charAt(0).toUpperCase()+n.slice(1)}function Ip(n,e,t,r,i){try{if(typeof r=="string")i[`write${SH(r)}`](t);else if(r instanceof Array)if(typeof r[0]=="number"){if(t.length!==r[0])throw new Ei(`Expecting byte array of length ${r[0]}, but got ${t.length} bytes`);i.writeFixedArray(t)}else if(r.length===2&&typeof r[1]=="number"){if(t.length!==r[1])throw new Ei(`Expecting byte array of length ${r[1]}, but got ${t.length} bytes`);for(let o=0;o<r[1];o++)Ip(n,null,t[o],r[0],i)}else i.writeArray(t,o=>{Ip(n,e,o,r[0],i)});else if(r.kind!==void 0)switch(r.kind){case"option":{t==null?i.writeU8(0):(i.writeU8(1),Ip(n,e,t,r.type,i));break}case"map":{i.writeU32(t.size),t.forEach((o,s)=>{Ip(n,e,s,r.key,i),Ip(n,e,o,r.value,i)});break}default:throw new Ei(`FieldType ${r} unrecognized`)}else CH(n,t,i)}catch(o){throw o instanceof Ei&&o.addToFieldPath(e),o}}function CH(n,e,t){if(typeof e.borshSerialize=="function"){e.borshSerialize(t);return}let r=n.get(e.constructor);if(!r)throw new Ei(`Class ${e.constructor.name} is missing in schema`);if(r.kind==="struct")r.fields.map(([i,o])=>{Ip(n,i,e[i],o,t)});else if(r.kind==="enum"){let i=e[r.field];for(let o=0;o<r.values.length;++o){let[s,a]=r.values[o];if(s===i){t.writeU8(o),Ip(n,s,e[s],a,t);break}}}else throw new Ei(`Unexpected schema kind: ${r.kind} for ${e.constructor.name}`)}function vue(n,e,t=Ox){let r=new t;return CH(n,e,r),r.toArray()}Un.serialize=vue;function Ap(n,e,t,r){try{if(typeof t=="string")return r[`read${SH(t)}`]();if(t instanceof Array){if(typeof t[0]=="number")return r.readFixedArray(t[0]);if(typeof t[1]=="number"){let i=[];for(let o=0;o<t[1];o++)i.push(Ap(n,null,t[0],r));return i}else return r.readArray(()=>Ap(n,e,t[0],r))}if(t.kind==="option")return r.readU8()?Ap(n,e,t.type,r):void 0;if(t.kind==="map"){let i=new Map,o=r.readU32();for(let s=0;s<o;s++){let a=Ap(n,e,t.key,r),c=Ap(n,e,t.value,r);i.set(a,c)}return i}return eD(n,t,r)}catch(i){throw i instanceof Ei&&i.addToFieldPath(e),i}}function eD(n,e,t){if(typeof e.borshDeserialize=="function")return e.borshDeserialize(t);let r=n.get(e);if(!r)throw new Ei(`Class ${e.name} is missing in schema`);if(r.kind==="struct"){let i={};for(let[o,s]of n.get(e).fields)i[o]=Ap(n,o,s,t);return new e(i)}if(r.kind==="enum"){let i=t.readU8();if(i>=r.values.length)throw new Ei(`Enum index: ${i} is out of range`);let[o,s]=r.values[i],a=Ap(n,o,s,t);return new e({[o]:a})}throw new Ei(`Unexpected schema kind: ${r.kind} for ${e.constructor.name}`)}function Sue(n,e,t,r=wo){let i=new r(t),o=eD(n,e,i);if(i.offset<t.length)throw new Ei(`Unexpected ${t.length-i.offset} bytes after deserialized data`);return o}Un.deserialize=Sue;function Cue(n,e,t,r=wo){let i=new r(t);return eD(n,e,i)}Un.deserializeUnchecked=Cue});var yK=oe((wD,bD)=>{"use strict";(function(n,e){typeof wD=="object"&&typeof bD<"u"?bD.exports=e():typeof define=="function"&&define.amd?define(e):(n=n||self,n.JSBI=e())})(wD,function(){"use strict";var n=Math.imul,e=Math.clz32;function t(j,Y){(Y==null||Y>j.length)&&(Y=j.length);for(var Q=0,v=Array(Y);Q<Y;Q++)v[Q]=j[Q];return v}function r(j){if(Array.isArray(j))return j}function i(j){if(j===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return j}function o(j,Y,Q){return Y=d(Y),S(j,m()?Reflect.construct(Y,Q||[],d(j).constructor):Y.apply(j,Q))}function s(j,Y){if(!(j instanceof Y))throw new TypeError("Cannot call a class as a function")}function a(j,Y,Q){if(m())return Reflect.construct.apply(null,arguments);var v=[null];v.push.apply(v,Y);var p=new(j.bind.apply(j,v));return Q&&R(p,Q.prototype),p}function c(j,Y){for(var Q,v=0;v<Y.length;v++)Q=Y[v],Q.enumerable=Q.enumerable||!1,Q.configurable=!0,"value"in Q&&(Q.writable=!0),Object.defineProperty(j,H(Q.key),Q)}function u(j,Y,Q){return Y&&c(j.prototype,Y),Q&&c(j,Q),Object.defineProperty(j,"prototype",{writable:!1}),j}function l(j,Y){var Q=typeof Symbol<"u"&&j[Symbol.iterator]||j["@@iterator"];if(!Q){if(Array.isArray(j)||(Q=A(j))||Y&&j&&typeof j.length=="number"){Q&&(j=Q);var v=0,p=function(){};return{s:p,n:function(){return v>=j.length?{done:!0}:{done:!1,value:j[v++]}},e:function(C){throw C},f:p}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
1
|
+
"use strict";var PolygonIdSdk=(()=>{var wne=Object.create;var LI=Object.defineProperty;var bne=Object.getOwnPropertyDescriptor;var Ene=Object.getOwnPropertyNames;var Ine=Object.getPrototypeOf,Ane=Object.prototype.hasOwnProperty;var co=(n,e)=>()=>(n&&(e=n(n=0)),e);var oe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Rr=(n,e)=>{for(var t in e)LI(n,t,{get:e[t],enumerable:!0})},fN=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ene(e))!Ane.call(n,i)&&i!==t&&LI(n,i,{get:()=>e[i],enumerable:!(r=bne(e,i))||r.enumerable});return n};var En=(n,e,t)=>(t=n!=null?wne(Ine(n)):{},fN(e||!n||!n.__esModule?LI(t,"default",{value:n,enumerable:!0}):t,n)),$8=n=>fN(LI({},"__esModule",{value:!0}),n);var Y9=oe((Ym,db)=>{"use strict";(function(n,e){"use strict";var t={};n.PubSub?(t=n.PubSub,console.warn("PubSub already loaded, using existing version")):(n.PubSub=t,e(t)),typeof Ym=="object"?(db!==void 0&&db.exports&&(Ym=db.exports=t),Ym.PubSub=t,db.exports=Ym=t):typeof define=="function"&&define.amd&&define(function(){return t})})(typeof window=="object"&&window||Ym||global,function(n){"use strict";var e={},t=-1,r="*";function i(f){var m;for(m in f)if(Object.prototype.hasOwnProperty.call(f,m))return!0;return!1}function o(f){return function(){throw f}}function s(f,m,w){try{f(m,w)}catch(b){setTimeout(o(b),0)}}function a(f,m,w){f(m,w)}function c(f,m,w,b){var S=e[m],R=b?a:s,G;if(Object.prototype.hasOwnProperty.call(e,m))for(G in S)Object.prototype.hasOwnProperty.call(S,G)&&R(S[G],f,w)}function u(f,m,w){return function(){var S=String(f),R=S.lastIndexOf(".");for(c(f,f,m,w);R!==-1;)S=S.substr(0,R),R=S.lastIndexOf("."),c(f,S,m,w);c(f,r,m,w)}}function l(f){var m=String(f),w=!!(Object.prototype.hasOwnProperty.call(e,m)&&i(e[m]));return w}function d(f){for(var m=String(f),w=l(m)||l(r),b=m.lastIndexOf(".");!w&&b!==-1;)m=m.substr(0,b),b=m.lastIndexOf("."),w=l(m);return w}function h(f,m,w,b){f=typeof f=="symbol"?f.toString():f;var S=u(f,m,b),R=d(f);return R?(w===!0?S():setTimeout(S,0),!0):!1}n.publish=function(f,m){return h(f,m,!1,n.immediateExceptions)},n.publishSync=function(f,m){return h(f,m,!0,n.immediateExceptions)},n.subscribe=function(f,m){if(typeof m!="function")return!1;f=typeof f=="symbol"?f.toString():f,Object.prototype.hasOwnProperty.call(e,f)||(e[f]={});var w="uid_"+String(++t);return e[f][w]=m,w},n.subscribeAll=function(f){return n.subscribe(r,f)},n.subscribeOnce=function(f,m){var w=n.subscribe(f,function(){n.unsubscribe(w),m.apply(this,arguments)});return n},n.clearAllSubscriptions=function(){e={}},n.clearSubscriptions=function(m){var w;for(w in e)Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0&&delete e[w]},n.countSubscriptions=function(m){var w,b,S=0;for(w in e)if(Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0){for(b in e[w])S++;break}return S},n.getSubscriptions=function(m){var w,b=[];for(w in e)Object.prototype.hasOwnProperty.call(e,w)&&w.indexOf(m)===0&&b.push(w);return b},n.unsubscribe=function(f){var m=function(M){var A;for(A in e)if(Object.prototype.hasOwnProperty.call(e,A)&&A.indexOf(M)===0)return!0;return!1},w=typeof f=="string"&&(Object.prototype.hasOwnProperty.call(e,f)||m(f)),b=!w&&typeof f=="string",S=typeof f=="function",R=!1,G,U,H;if(w){n.clearSubscriptions(f);return}for(G in e)if(Object.prototype.hasOwnProperty.call(e,G)){if(U=e[G],b&&U[f]){delete U[f],R=f;break}if(S)for(H in U)Object.prototype.hasOwnProperty.call(U,H)&&U[H]===f&&(delete U[H],R=!0)}return R}})});var j9=oe(()=>{"use strict"});var NR=oe((W9,FR)=>{"use strict";(function(n,e){"use strict";function t(v,p){if(!v)throw new Error(p||"Assertion failed")}function r(v,p){v.super_=p;var x=function(){};x.prototype=p.prototype,v.prototype=new x,v.prototype.constructor=v}function i(v,p,x){if(i.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((p==="le"||p==="be")&&(x=p,p=10),this._init(v||0,p||10,x||"be"))}typeof n=="object"?n.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=j9().Buffer}catch{}i.isBN=function(p){return p instanceof i?!0:p!==null&&typeof p=="object"&&p.constructor.wordSize===i.wordSize&&Array.isArray(p.words)},i.max=function(p,x){return p.cmp(x)>0?p:x},i.min=function(p,x){return p.cmp(x)<0?p:x},i.prototype._init=function(p,x,y){if(typeof p=="number")return this._initNumber(p,x,y);if(typeof p=="object")return this._initArray(p,x,y);x==="hex"&&(x=16),t(x===(x|0)&&x>=2&&x<=36),p=p.toString().replace(/\s+/g,"");var I=0;p[0]==="-"&&(I++,this.negative=1),I<p.length&&(x===16?this._parseHex(p,I,y):(this._parseBase(p,x,I),y==="le"&&this._initArray(this.toArray(),x,y)))},i.prototype._initNumber=function(p,x,y){p<0&&(this.negative=1,p=-p),p<67108864?(this.words=[p&67108863],this.length=1):p<4503599627370496?(this.words=[p&67108863,p/67108864&67108863],this.length=2):(t(p<9007199254740992),this.words=[p&67108863,p/67108864&67108863,1],this.length=3),y==="le"&&this._initArray(this.toArray(),x,y)},i.prototype._initArray=function(p,x,y){if(t(typeof p.length=="number"),p.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(p.length/3),this.words=new Array(this.length);for(var I=0;I<this.length;I++)this.words[I]=0;var C,F,N=0;if(y==="be")for(I=p.length-1,C=0;I>=0;I-=3)F=p[I]|p[I-1]<<8|p[I-2]<<16,this.words[C]|=F<<N&67108863,this.words[C+1]=F>>>26-N&67108863,N+=24,N>=26&&(N-=26,C++);else if(y==="le")for(I=0,C=0;I<p.length;I+=3)F=p[I]|p[I+1]<<8|p[I+2]<<16,this.words[C]|=F<<N&67108863,this.words[C+1]=F>>>26-N&67108863,N+=24,N>=26&&(N-=26,C++);return this._strip()};function s(v,p){var x=v.charCodeAt(p);if(x>=48&&x<=57)return x-48;if(x>=65&&x<=70)return x-55;if(x>=97&&x<=102)return x-87;t(!1,"Invalid character in "+v)}function a(v,p,x){var y=s(v,x);return x-1>=p&&(y|=s(v,x-1)<<4),y}i.prototype._parseHex=function(p,x,y){this.length=Math.ceil((p.length-x)/6),this.words=new Array(this.length);for(var I=0;I<this.length;I++)this.words[I]=0;var C=0,F=0,N;if(y==="be")for(I=p.length-1;I>=x;I-=2)N=a(p,x,I)<<C,this.words[F]|=N&67108863,C>=18?(C-=18,F+=1,this.words[F]|=N>>>26):C+=8;else{var O=p.length-x;for(I=O%2===0?x+1:x;I<p.length;I+=2)N=a(p,x,I)<<C,this.words[F]|=N&67108863,C>=18?(C-=18,F+=1,this.words[F]|=N>>>26):C+=8}this._strip()};function c(v,p,x,y){for(var I=0,C=0,F=Math.min(v.length,x),N=p;N<F;N++){var O=v.charCodeAt(N)-48;I*=y,O>=49?C=O-49+10:O>=17?C=O-17+10:C=O,t(O>=0&&C<y,"Invalid character"),I+=C}return I}i.prototype._parseBase=function(p,x,y){this.words=[0],this.length=1;for(var I=0,C=1;C<=67108863;C*=x)I++;I--,C=C/x|0;for(var F=p.length-y,N=F%I,O=Math.min(F,F-N)+y,T=0,q=y;q<O;q+=I)T=c(p,q,q+I,x),this.imuln(C),this.words[0]+T<67108864?this.words[0]+=T:this._iaddn(T);if(N!==0){var _=1;for(T=c(p,q,p.length,x),q=0;q<N;q++)_*=x;this.imuln(_),this.words[0]+T<67108864?this.words[0]+=T:this._iaddn(T)}this._strip()},i.prototype.copy=function(p){p.words=new Array(this.length);for(var x=0;x<this.length;x++)p.words[x]=this.words[x];p.length=this.length,p.negative=this.negative,p.red=this.red};function u(v,p){v.words=p.words,v.length=p.length,v.negative=p.negative,v.red=p.red}if(i.prototype._move=function(p){u(p,this)},i.prototype.clone=function(){var p=new i(null);return this.copy(p),p},i.prototype._expand=function(p){for(;this.length<p;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch{i.prototype.inspect=l}else i.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],h=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(p,x){p=p||10,x=x|0||1;var y;if(p===16||p==="hex"){y="";for(var I=0,C=0,F=0;F<this.length;F++){var N=this.words[F],O=((N<<I|C)&16777215).toString(16);C=N>>>24-I&16777215,I+=2,I>=26&&(I-=26,F--),C!==0||F!==this.length-1?y=d[6-O.length]+O+y:y=O+y}for(C!==0&&(y=C.toString(16)+y);y.length%x!==0;)y="0"+y;return this.negative!==0&&(y="-"+y),y}if(p===(p|0)&&p>=2&&p<=36){var T=h[p],q=f[p];y="";var _=this.clone();for(_.negative=0;!_.isZero();){var L=_.modrn(q).toString(p);_=_.idivn(q),_.isZero()?y=L+y:y=d[T-L.length]+L+y}for(this.isZero()&&(y="0"+y);y.length%x!==0;)y="0"+y;return this.negative!==0&&(y="-"+y),y}t(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var p=this.words[0];return this.length===2?p+=this.words[1]*67108864:this.length===3&&this.words[2]===1?p+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-p:p},i.prototype.toJSON=function(){return this.toString(16,2)},o&&(i.prototype.toBuffer=function(p,x){return this.toArrayLike(o,p,x)}),i.prototype.toArray=function(p,x){return this.toArrayLike(Array,p,x)};var m=function(p,x){return p.allocUnsafe?p.allocUnsafe(x):new p(x)};i.prototype.toArrayLike=function(p,x,y){this._strip();var I=this.byteLength(),C=y||Math.max(1,I);t(I<=C,"byte array longer than desired length"),t(C>0,"Requested array length <= 0");var F=m(p,C),N=x==="le"?"LE":"BE";return this["_toArrayLike"+N](F,I),F},i.prototype._toArrayLikeLE=function(p,x){for(var y=0,I=0,C=0,F=0;C<this.length;C++){var N=this.words[C]<<F|I;p[y++]=N&255,y<p.length&&(p[y++]=N>>8&255),y<p.length&&(p[y++]=N>>16&255),F===6?(y<p.length&&(p[y++]=N>>24&255),I=0,F=0):(I=N>>>24,F+=2)}if(y<p.length)for(p[y++]=I;y<p.length;)p[y++]=0},i.prototype._toArrayLikeBE=function(p,x){for(var y=p.length-1,I=0,C=0,F=0;C<this.length;C++){var N=this.words[C]<<F|I;p[y--]=N&255,y>=0&&(p[y--]=N>>8&255),y>=0&&(p[y--]=N>>16&255),F===6?(y>=0&&(p[y--]=N>>24&255),I=0,F=0):(I=N>>>24,F+=2)}if(y>=0)for(p[y--]=I;y>=0;)p[y--]=0},Math.clz32?i.prototype._countBits=function(p){return 32-Math.clz32(p)}:i.prototype._countBits=function(p){var x=p,y=0;return x>=4096&&(y+=13,x>>>=13),x>=64&&(y+=7,x>>>=7),x>=8&&(y+=4,x>>>=4),x>=2&&(y+=2,x>>>=2),y+x},i.prototype._zeroBits=function(p){if(p===0)return 26;var x=p,y=0;return(x&8191)===0&&(y+=13,x>>>=13),(x&127)===0&&(y+=7,x>>>=7),(x&15)===0&&(y+=4,x>>>=4),(x&3)===0&&(y+=2,x>>>=2),(x&1)===0&&y++,y},i.prototype.bitLength=function(){var p=this.words[this.length-1],x=this._countBits(p);return(this.length-1)*26+x};function w(v){for(var p=new Array(v.bitLength()),x=0;x<p.length;x++){var y=x/26|0,I=x%26;p[x]=v.words[y]>>>I&1}return p}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var p=0,x=0;x<this.length;x++){var y=this._zeroBits(this.words[x]);if(p+=y,y!==26)break}return p},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(p){return this.negative!==0?this.abs().inotn(p).iaddn(1):this.clone()},i.prototype.fromTwos=function(p){return this.testn(p-1)?this.notn(p).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(p){for(;this.length<p.length;)this.words[this.length++]=0;for(var x=0;x<p.length;x++)this.words[x]=this.words[x]|p.words[x];return this._strip()},i.prototype.ior=function(p){return t((this.negative|p.negative)===0),this.iuor(p)},i.prototype.or=function(p){return this.length>p.length?this.clone().ior(p):p.clone().ior(this)},i.prototype.uor=function(p){return this.length>p.length?this.clone().iuor(p):p.clone().iuor(this)},i.prototype.iuand=function(p){var x;this.length>p.length?x=p:x=this;for(var y=0;y<x.length;y++)this.words[y]=this.words[y]&p.words[y];return this.length=x.length,this._strip()},i.prototype.iand=function(p){return t((this.negative|p.negative)===0),this.iuand(p)},i.prototype.and=function(p){return this.length>p.length?this.clone().iand(p):p.clone().iand(this)},i.prototype.uand=function(p){return this.length>p.length?this.clone().iuand(p):p.clone().iuand(this)},i.prototype.iuxor=function(p){var x,y;this.length>p.length?(x=this,y=p):(x=p,y=this);for(var I=0;I<y.length;I++)this.words[I]=x.words[I]^y.words[I];if(this!==x)for(;I<x.length;I++)this.words[I]=x.words[I];return this.length=x.length,this._strip()},i.prototype.ixor=function(p){return t((this.negative|p.negative)===0),this.iuxor(p)},i.prototype.xor=function(p){return this.length>p.length?this.clone().ixor(p):p.clone().ixor(this)},i.prototype.uxor=function(p){return this.length>p.length?this.clone().iuxor(p):p.clone().iuxor(this)},i.prototype.inotn=function(p){t(typeof p=="number"&&p>=0);var x=Math.ceil(p/26)|0,y=p%26;this._expand(x),y>0&&x--;for(var I=0;I<x;I++)this.words[I]=~this.words[I]&67108863;return y>0&&(this.words[I]=~this.words[I]&67108863>>26-y),this._strip()},i.prototype.notn=function(p){return this.clone().inotn(p)},i.prototype.setn=function(p,x){t(typeof p=="number"&&p>=0);var y=p/26|0,I=p%26;return this._expand(y+1),x?this.words[y]=this.words[y]|1<<I:this.words[y]=this.words[y]&~(1<<I),this._strip()},i.prototype.iadd=function(p){var x;if(this.negative!==0&&p.negative===0)return this.negative=0,x=this.isub(p),this.negative^=1,this._normSign();if(this.negative===0&&p.negative!==0)return p.negative=0,x=this.isub(p),p.negative=1,x._normSign();var y,I;this.length>p.length?(y=this,I=p):(y=p,I=this);for(var C=0,F=0;F<I.length;F++)x=(y.words[F]|0)+(I.words[F]|0)+C,this.words[F]=x&67108863,C=x>>>26;for(;C!==0&&F<y.length;F++)x=(y.words[F]|0)+C,this.words[F]=x&67108863,C=x>>>26;if(this.length=y.length,C!==0)this.words[this.length]=C,this.length++;else if(y!==this)for(;F<y.length;F++)this.words[F]=y.words[F];return this},i.prototype.add=function(p){var x;return p.negative!==0&&this.negative===0?(p.negative=0,x=this.sub(p),p.negative^=1,x):p.negative===0&&this.negative!==0?(this.negative=0,x=p.sub(this),this.negative=1,x):this.length>p.length?this.clone().iadd(p):p.clone().iadd(this)},i.prototype.isub=function(p){if(p.negative!==0){p.negative=0;var x=this.iadd(p);return p.negative=1,x._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(p),this.negative=1,this._normSign();var y=this.cmp(p);if(y===0)return this.negative=0,this.length=1,this.words[0]=0,this;var I,C;y>0?(I=this,C=p):(I=p,C=this);for(var F=0,N=0;N<C.length;N++)x=(I.words[N]|0)-(C.words[N]|0)+F,F=x>>26,this.words[N]=x&67108863;for(;F!==0&&N<I.length;N++)x=(I.words[N]|0)+F,F=x>>26,this.words[N]=x&67108863;if(F===0&&N<I.length&&I!==this)for(;N<I.length;N++)this.words[N]=I.words[N];return this.length=Math.max(this.length,N),I!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(p){return this.clone().isub(p)};function b(v,p,x){x.negative=p.negative^v.negative;var y=v.length+p.length|0;x.length=y,y=y-1|0;var I=v.words[0]|0,C=p.words[0]|0,F=I*C,N=F&67108863,O=F/67108864|0;x.words[0]=N;for(var T=1;T<y;T++){for(var q=O>>>26,_=O&67108863,L=Math.min(T,p.length-1),g=Math.max(0,T-v.length+1);g<=L;g++){var K=T-g|0;I=v.words[K]|0,C=p.words[g]|0,F=I*C+_,q+=F/67108864|0,_=F&67108863}x.words[T]=_|0,O=q|0}return O!==0?x.words[T]=O|0:x.length--,x._strip()}var S=function(p,x,y){var I=p.words,C=x.words,F=y.words,N=0,O,T,q,_=I[0]|0,L=_&8191,g=_>>>13,K=I[1]|0,E=K&8191,V=K>>>13,J=I[2]|0,B=J&8191,X=J>>>13,ce=I[3]|0,ne=ce&8191,ge=ce>>>13,He=I[4]|0,Le=He&8191,Fe=He>>>13,ft=I[5]|0,Te=ft&8191,De=ft>>>13,tt=I[6]|0,$e=tt&8191,Et=tt>>>13,_r=I[7]|0,Pt=_r&8191,zt=_r>>>13,er=I[8]|0,Ft=er&8191,Kt=er>>>13,Xo=I[9]|0,Xt=Xo&8191,ue=Xo>>>13,k=C[0]|0,P=k&8191,te=k>>>13,se=C[1]|0,$=se&8191,ae=se>>>13,re=C[2]|0,fe=re&8191,me=re>>>13,Ie=C[3]|0,le=Ie&8191,Ae=Ie>>>13,Qe=C[4]|0,Pe=Qe&8191,Se=Qe>>>13,nt=C[5]|0,Je=nt&8191,Ze=nt>>>13,st=C[6]|0,qe=st&8191,Oe=st>>>13,Yt=C[7]|0,Jt=Yt&8191,tn=Yt>>>13,Yu=C[8]|0,Rn=Yu&8191,Dn=Yu>>>13,ju=C[9]|0,Tn=ju&8191,Bn=ju>>>13;y.negative=p.negative^x.negative,y.length=19,O=Math.imul(L,P),T=Math.imul(L,te),T=T+Math.imul(g,P)|0,q=Math.imul(g,te);var qc=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(qc>>>26)|0,qc&=67108863,O=Math.imul(E,P),T=Math.imul(E,te),T=T+Math.imul(V,P)|0,q=Math.imul(V,te),O=O+Math.imul(L,$)|0,T=T+Math.imul(L,ae)|0,T=T+Math.imul(g,$)|0,q=q+Math.imul(g,ae)|0;var Ls=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Ls>>>26)|0,Ls&=67108863,O=Math.imul(B,P),T=Math.imul(B,te),T=T+Math.imul(X,P)|0,q=Math.imul(X,te),O=O+Math.imul(E,$)|0,T=T+Math.imul(E,ae)|0,T=T+Math.imul(V,$)|0,q=q+Math.imul(V,ae)|0,O=O+Math.imul(L,fe)|0,T=T+Math.imul(L,me)|0,T=T+Math.imul(g,fe)|0,q=q+Math.imul(g,me)|0;var _o=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(_o>>>26)|0,_o&=67108863,O=Math.imul(ne,P),T=Math.imul(ne,te),T=T+Math.imul(ge,P)|0,q=Math.imul(ge,te),O=O+Math.imul(B,$)|0,T=T+Math.imul(B,ae)|0,T=T+Math.imul(X,$)|0,q=q+Math.imul(X,ae)|0,O=O+Math.imul(E,fe)|0,T=T+Math.imul(E,me)|0,T=T+Math.imul(V,fe)|0,q=q+Math.imul(V,me)|0,O=O+Math.imul(L,le)|0,T=T+Math.imul(L,Ae)|0,T=T+Math.imul(g,le)|0,q=q+Math.imul(g,Ae)|0;var Ja=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Ja>>>26)|0,Ja&=67108863,O=Math.imul(Le,P),T=Math.imul(Le,te),T=T+Math.imul(Fe,P)|0,q=Math.imul(Fe,te),O=O+Math.imul(ne,$)|0,T=T+Math.imul(ne,ae)|0,T=T+Math.imul(ge,$)|0,q=q+Math.imul(ge,ae)|0,O=O+Math.imul(B,fe)|0,T=T+Math.imul(B,me)|0,T=T+Math.imul(X,fe)|0,q=q+Math.imul(X,me)|0,O=O+Math.imul(E,le)|0,T=T+Math.imul(E,Ae)|0,T=T+Math.imul(V,le)|0,q=q+Math.imul(V,Ae)|0,O=O+Math.imul(L,Pe)|0,T=T+Math.imul(L,Se)|0,T=T+Math.imul(g,Pe)|0,q=q+Math.imul(g,Se)|0;var vd=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(vd>>>26)|0,vd&=67108863,O=Math.imul(Te,P),T=Math.imul(Te,te),T=T+Math.imul(De,P)|0,q=Math.imul(De,te),O=O+Math.imul(Le,$)|0,T=T+Math.imul(Le,ae)|0,T=T+Math.imul(Fe,$)|0,q=q+Math.imul(Fe,ae)|0,O=O+Math.imul(ne,fe)|0,T=T+Math.imul(ne,me)|0,T=T+Math.imul(ge,fe)|0,q=q+Math.imul(ge,me)|0,O=O+Math.imul(B,le)|0,T=T+Math.imul(B,Ae)|0,T=T+Math.imul(X,le)|0,q=q+Math.imul(X,Ae)|0,O=O+Math.imul(E,Pe)|0,T=T+Math.imul(E,Se)|0,T=T+Math.imul(V,Pe)|0,q=q+Math.imul(V,Se)|0,O=O+Math.imul(L,Je)|0,T=T+Math.imul(L,Ze)|0,T=T+Math.imul(g,Je)|0,q=q+Math.imul(g,Ze)|0;var G8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(G8>>>26)|0,G8&=67108863,O=Math.imul($e,P),T=Math.imul($e,te),T=T+Math.imul(Et,P)|0,q=Math.imul(Et,te),O=O+Math.imul(Te,$)|0,T=T+Math.imul(Te,ae)|0,T=T+Math.imul(De,$)|0,q=q+Math.imul(De,ae)|0,O=O+Math.imul(Le,fe)|0,T=T+Math.imul(Le,me)|0,T=T+Math.imul(Fe,fe)|0,q=q+Math.imul(Fe,me)|0,O=O+Math.imul(ne,le)|0,T=T+Math.imul(ne,Ae)|0,T=T+Math.imul(ge,le)|0,q=q+Math.imul(ge,Ae)|0,O=O+Math.imul(B,Pe)|0,T=T+Math.imul(B,Se)|0,T=T+Math.imul(X,Pe)|0,q=q+Math.imul(X,Se)|0,O=O+Math.imul(E,Je)|0,T=T+Math.imul(E,Ze)|0,T=T+Math.imul(V,Je)|0,q=q+Math.imul(V,Ze)|0,O=O+Math.imul(L,qe)|0,T=T+Math.imul(L,Oe)|0,T=T+Math.imul(g,qe)|0,q=q+Math.imul(g,Oe)|0;var H8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(H8>>>26)|0,H8&=67108863,O=Math.imul(Pt,P),T=Math.imul(Pt,te),T=T+Math.imul(zt,P)|0,q=Math.imul(zt,te),O=O+Math.imul($e,$)|0,T=T+Math.imul($e,ae)|0,T=T+Math.imul(Et,$)|0,q=q+Math.imul(Et,ae)|0,O=O+Math.imul(Te,fe)|0,T=T+Math.imul(Te,me)|0,T=T+Math.imul(De,fe)|0,q=q+Math.imul(De,me)|0,O=O+Math.imul(Le,le)|0,T=T+Math.imul(Le,Ae)|0,T=T+Math.imul(Fe,le)|0,q=q+Math.imul(Fe,Ae)|0,O=O+Math.imul(ne,Pe)|0,T=T+Math.imul(ne,Se)|0,T=T+Math.imul(ge,Pe)|0,q=q+Math.imul(ge,Se)|0,O=O+Math.imul(B,Je)|0,T=T+Math.imul(B,Ze)|0,T=T+Math.imul(X,Je)|0,q=q+Math.imul(X,Ze)|0,O=O+Math.imul(E,qe)|0,T=T+Math.imul(E,Oe)|0,T=T+Math.imul(V,qe)|0,q=q+Math.imul(V,Oe)|0,O=O+Math.imul(L,Jt)|0,T=T+Math.imul(L,tn)|0,T=T+Math.imul(g,Jt)|0,q=q+Math.imul(g,tn)|0;var K8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(K8>>>26)|0,K8&=67108863,O=Math.imul(Ft,P),T=Math.imul(Ft,te),T=T+Math.imul(Kt,P)|0,q=Math.imul(Kt,te),O=O+Math.imul(Pt,$)|0,T=T+Math.imul(Pt,ae)|0,T=T+Math.imul(zt,$)|0,q=q+Math.imul(zt,ae)|0,O=O+Math.imul($e,fe)|0,T=T+Math.imul($e,me)|0,T=T+Math.imul(Et,fe)|0,q=q+Math.imul(Et,me)|0,O=O+Math.imul(Te,le)|0,T=T+Math.imul(Te,Ae)|0,T=T+Math.imul(De,le)|0,q=q+Math.imul(De,Ae)|0,O=O+Math.imul(Le,Pe)|0,T=T+Math.imul(Le,Se)|0,T=T+Math.imul(Fe,Pe)|0,q=q+Math.imul(Fe,Se)|0,O=O+Math.imul(ne,Je)|0,T=T+Math.imul(ne,Ze)|0,T=T+Math.imul(ge,Je)|0,q=q+Math.imul(ge,Ze)|0,O=O+Math.imul(B,qe)|0,T=T+Math.imul(B,Oe)|0,T=T+Math.imul(X,qe)|0,q=q+Math.imul(X,Oe)|0,O=O+Math.imul(E,Jt)|0,T=T+Math.imul(E,tn)|0,T=T+Math.imul(V,Jt)|0,q=q+Math.imul(V,tn)|0,O=O+Math.imul(L,Rn)|0,T=T+Math.imul(L,Dn)|0,T=T+Math.imul(g,Rn)|0,q=q+Math.imul(g,Dn)|0;var J8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(J8>>>26)|0,J8&=67108863,O=Math.imul(Xt,P),T=Math.imul(Xt,te),T=T+Math.imul(ue,P)|0,q=Math.imul(ue,te),O=O+Math.imul(Ft,$)|0,T=T+Math.imul(Ft,ae)|0,T=T+Math.imul(Kt,$)|0,q=q+Math.imul(Kt,ae)|0,O=O+Math.imul(Pt,fe)|0,T=T+Math.imul(Pt,me)|0,T=T+Math.imul(zt,fe)|0,q=q+Math.imul(zt,me)|0,O=O+Math.imul($e,le)|0,T=T+Math.imul($e,Ae)|0,T=T+Math.imul(Et,le)|0,q=q+Math.imul(Et,Ae)|0,O=O+Math.imul(Te,Pe)|0,T=T+Math.imul(Te,Se)|0,T=T+Math.imul(De,Pe)|0,q=q+Math.imul(De,Se)|0,O=O+Math.imul(Le,Je)|0,T=T+Math.imul(Le,Ze)|0,T=T+Math.imul(Fe,Je)|0,q=q+Math.imul(Fe,Ze)|0,O=O+Math.imul(ne,qe)|0,T=T+Math.imul(ne,Oe)|0,T=T+Math.imul(ge,qe)|0,q=q+Math.imul(ge,Oe)|0,O=O+Math.imul(B,Jt)|0,T=T+Math.imul(B,tn)|0,T=T+Math.imul(X,Jt)|0,q=q+Math.imul(X,tn)|0,O=O+Math.imul(E,Rn)|0,T=T+Math.imul(E,Dn)|0,T=T+Math.imul(V,Rn)|0,q=q+Math.imul(V,Dn)|0,O=O+Math.imul(L,Tn)|0,T=T+Math.imul(L,Bn)|0,T=T+Math.imul(g,Tn)|0,q=q+Math.imul(g,Bn)|0;var q8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(q8>>>26)|0,q8&=67108863,O=Math.imul(Xt,$),T=Math.imul(Xt,ae),T=T+Math.imul(ue,$)|0,q=Math.imul(ue,ae),O=O+Math.imul(Ft,fe)|0,T=T+Math.imul(Ft,me)|0,T=T+Math.imul(Kt,fe)|0,q=q+Math.imul(Kt,me)|0,O=O+Math.imul(Pt,le)|0,T=T+Math.imul(Pt,Ae)|0,T=T+Math.imul(zt,le)|0,q=q+Math.imul(zt,Ae)|0,O=O+Math.imul($e,Pe)|0,T=T+Math.imul($e,Se)|0,T=T+Math.imul(Et,Pe)|0,q=q+Math.imul(Et,Se)|0,O=O+Math.imul(Te,Je)|0,T=T+Math.imul(Te,Ze)|0,T=T+Math.imul(De,Je)|0,q=q+Math.imul(De,Ze)|0,O=O+Math.imul(Le,qe)|0,T=T+Math.imul(Le,Oe)|0,T=T+Math.imul(Fe,qe)|0,q=q+Math.imul(Fe,Oe)|0,O=O+Math.imul(ne,Jt)|0,T=T+Math.imul(ne,tn)|0,T=T+Math.imul(ge,Jt)|0,q=q+Math.imul(ge,tn)|0,O=O+Math.imul(B,Rn)|0,T=T+Math.imul(B,Dn)|0,T=T+Math.imul(X,Rn)|0,q=q+Math.imul(X,Dn)|0,O=O+Math.imul(E,Tn)|0,T=T+Math.imul(E,Bn)|0,T=T+Math.imul(V,Tn)|0,q=q+Math.imul(V,Bn)|0;var V8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(V8>>>26)|0,V8&=67108863,O=Math.imul(Xt,fe),T=Math.imul(Xt,me),T=T+Math.imul(ue,fe)|0,q=Math.imul(ue,me),O=O+Math.imul(Ft,le)|0,T=T+Math.imul(Ft,Ae)|0,T=T+Math.imul(Kt,le)|0,q=q+Math.imul(Kt,Ae)|0,O=O+Math.imul(Pt,Pe)|0,T=T+Math.imul(Pt,Se)|0,T=T+Math.imul(zt,Pe)|0,q=q+Math.imul(zt,Se)|0,O=O+Math.imul($e,Je)|0,T=T+Math.imul($e,Ze)|0,T=T+Math.imul(Et,Je)|0,q=q+Math.imul(Et,Ze)|0,O=O+Math.imul(Te,qe)|0,T=T+Math.imul(Te,Oe)|0,T=T+Math.imul(De,qe)|0,q=q+Math.imul(De,Oe)|0,O=O+Math.imul(Le,Jt)|0,T=T+Math.imul(Le,tn)|0,T=T+Math.imul(Fe,Jt)|0,q=q+Math.imul(Fe,tn)|0,O=O+Math.imul(ne,Rn)|0,T=T+Math.imul(ne,Dn)|0,T=T+Math.imul(ge,Rn)|0,q=q+Math.imul(ge,Dn)|0,O=O+Math.imul(B,Tn)|0,T=T+Math.imul(B,Bn)|0,T=T+Math.imul(X,Tn)|0,q=q+Math.imul(X,Bn)|0;var Q8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Q8>>>26)|0,Q8&=67108863,O=Math.imul(Xt,le),T=Math.imul(Xt,Ae),T=T+Math.imul(ue,le)|0,q=Math.imul(ue,Ae),O=O+Math.imul(Ft,Pe)|0,T=T+Math.imul(Ft,Se)|0,T=T+Math.imul(Kt,Pe)|0,q=q+Math.imul(Kt,Se)|0,O=O+Math.imul(Pt,Je)|0,T=T+Math.imul(Pt,Ze)|0,T=T+Math.imul(zt,Je)|0,q=q+Math.imul(zt,Ze)|0,O=O+Math.imul($e,qe)|0,T=T+Math.imul($e,Oe)|0,T=T+Math.imul(Et,qe)|0,q=q+Math.imul(Et,Oe)|0,O=O+Math.imul(Te,Jt)|0,T=T+Math.imul(Te,tn)|0,T=T+Math.imul(De,Jt)|0,q=q+Math.imul(De,tn)|0,O=O+Math.imul(Le,Rn)|0,T=T+Math.imul(Le,Dn)|0,T=T+Math.imul(Fe,Rn)|0,q=q+Math.imul(Fe,Dn)|0,O=O+Math.imul(ne,Tn)|0,T=T+Math.imul(ne,Bn)|0,T=T+Math.imul(ge,Tn)|0,q=q+Math.imul(ge,Bn)|0;var z8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(z8>>>26)|0,z8&=67108863,O=Math.imul(Xt,Pe),T=Math.imul(Xt,Se),T=T+Math.imul(ue,Pe)|0,q=Math.imul(ue,Se),O=O+Math.imul(Ft,Je)|0,T=T+Math.imul(Ft,Ze)|0,T=T+Math.imul(Kt,Je)|0,q=q+Math.imul(Kt,Ze)|0,O=O+Math.imul(Pt,qe)|0,T=T+Math.imul(Pt,Oe)|0,T=T+Math.imul(zt,qe)|0,q=q+Math.imul(zt,Oe)|0,O=O+Math.imul($e,Jt)|0,T=T+Math.imul($e,tn)|0,T=T+Math.imul(Et,Jt)|0,q=q+Math.imul(Et,tn)|0,O=O+Math.imul(Te,Rn)|0,T=T+Math.imul(Te,Dn)|0,T=T+Math.imul(De,Rn)|0,q=q+Math.imul(De,Dn)|0,O=O+Math.imul(Le,Tn)|0,T=T+Math.imul(Le,Bn)|0,T=T+Math.imul(Fe,Tn)|0,q=q+Math.imul(Fe,Bn)|0;var Y8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Y8>>>26)|0,Y8&=67108863,O=Math.imul(Xt,Je),T=Math.imul(Xt,Ze),T=T+Math.imul(ue,Je)|0,q=Math.imul(ue,Ze),O=O+Math.imul(Ft,qe)|0,T=T+Math.imul(Ft,Oe)|0,T=T+Math.imul(Kt,qe)|0,q=q+Math.imul(Kt,Oe)|0,O=O+Math.imul(Pt,Jt)|0,T=T+Math.imul(Pt,tn)|0,T=T+Math.imul(zt,Jt)|0,q=q+Math.imul(zt,tn)|0,O=O+Math.imul($e,Rn)|0,T=T+Math.imul($e,Dn)|0,T=T+Math.imul(Et,Rn)|0,q=q+Math.imul(Et,Dn)|0,O=O+Math.imul(Te,Tn)|0,T=T+Math.imul(Te,Bn)|0,T=T+Math.imul(De,Tn)|0,q=q+Math.imul(De,Bn)|0;var j8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(j8>>>26)|0,j8&=67108863,O=Math.imul(Xt,qe),T=Math.imul(Xt,Oe),T=T+Math.imul(ue,qe)|0,q=Math.imul(ue,Oe),O=O+Math.imul(Ft,Jt)|0,T=T+Math.imul(Ft,tn)|0,T=T+Math.imul(Kt,Jt)|0,q=q+Math.imul(Kt,tn)|0,O=O+Math.imul(Pt,Rn)|0,T=T+Math.imul(Pt,Dn)|0,T=T+Math.imul(zt,Rn)|0,q=q+Math.imul(zt,Dn)|0,O=O+Math.imul($e,Tn)|0,T=T+Math.imul($e,Bn)|0,T=T+Math.imul(Et,Tn)|0,q=q+Math.imul(Et,Bn)|0;var W8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(W8>>>26)|0,W8&=67108863,O=Math.imul(Xt,Jt),T=Math.imul(Xt,tn),T=T+Math.imul(ue,Jt)|0,q=Math.imul(ue,tn),O=O+Math.imul(Ft,Rn)|0,T=T+Math.imul(Ft,Dn)|0,T=T+Math.imul(Kt,Rn)|0,q=q+Math.imul(Kt,Dn)|0,O=O+Math.imul(Pt,Tn)|0,T=T+Math.imul(Pt,Bn)|0,T=T+Math.imul(zt,Tn)|0,q=q+Math.imul(zt,Bn)|0;var Z8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(Z8>>>26)|0,Z8&=67108863,O=Math.imul(Xt,Rn),T=Math.imul(Xt,Dn),T=T+Math.imul(ue,Rn)|0,q=Math.imul(ue,Dn),O=O+Math.imul(Ft,Tn)|0,T=T+Math.imul(Ft,Bn)|0,T=T+Math.imul(Kt,Tn)|0,q=q+Math.imul(Kt,Bn)|0;var X8=(N+O|0)+((T&8191)<<13)|0;N=(q+(T>>>13)|0)+(X8>>>26)|0,X8&=67108863,O=Math.imul(Xt,Tn),T=Math.imul(Xt,Bn),T=T+Math.imul(ue,Tn)|0,q=Math.imul(ue,Bn);var _8=(N+O|0)+((T&8191)<<13)|0;return N=(q+(T>>>13)|0)+(_8>>>26)|0,_8&=67108863,F[0]=qc,F[1]=Ls,F[2]=_o,F[3]=Ja,F[4]=vd,F[5]=G8,F[6]=H8,F[7]=K8,F[8]=J8,F[9]=q8,F[10]=V8,F[11]=Q8,F[12]=z8,F[13]=Y8,F[14]=j8,F[15]=W8,F[16]=Z8,F[17]=X8,F[18]=_8,N!==0&&(F[19]=N,y.length++),y};Math.imul||(S=b);function R(v,p,x){x.negative=p.negative^v.negative,x.length=v.length+p.length;for(var y=0,I=0,C=0;C<x.length-1;C++){var F=I;I=0;for(var N=y&67108863,O=Math.min(C,p.length-1),T=Math.max(0,C-v.length+1);T<=O;T++){var q=C-T,_=v.words[q]|0,L=p.words[T]|0,g=_*L,K=g&67108863;F=F+(g/67108864|0)|0,K=K+N|0,N=K&67108863,F=F+(K>>>26)|0,I+=F>>>26,F&=67108863}x.words[C]=N,y=F,F=I}return y!==0?x.words[C]=y:x.length--,x._strip()}function G(v,p,x){return R(v,p,x)}i.prototype.mulTo=function(p,x){var y,I=this.length+p.length;return this.length===10&&p.length===10?y=S(this,p,x):I<63?y=b(this,p,x):I<1024?y=R(this,p,x):y=G(this,p,x),y};function U(v,p){this.x=v,this.y=p}U.prototype.makeRBT=function(p){for(var x=new Array(p),y=i.prototype._countBits(p)-1,I=0;I<p;I++)x[I]=this.revBin(I,y,p);return x},U.prototype.revBin=function(p,x,y){if(p===0||p===y-1)return p;for(var I=0,C=0;C<x;C++)I|=(p&1)<<x-C-1,p>>=1;return I},U.prototype.permute=function(p,x,y,I,C,F){for(var N=0;N<F;N++)I[N]=x[p[N]],C[N]=y[p[N]]},U.prototype.transform=function(p,x,y,I,C,F){this.permute(F,p,x,y,I,C);for(var N=1;N<C;N<<=1)for(var O=N<<1,T=Math.cos(2*Math.PI/O),q=Math.sin(2*Math.PI/O),_=0;_<C;_+=O)for(var L=T,g=q,K=0;K<N;K++){var E=y[_+K],V=I[_+K],J=y[_+K+N],B=I[_+K+N],X=L*J-g*B;B=L*B+g*J,J=X,y[_+K]=E+J,I[_+K]=V+B,y[_+K+N]=E-J,I[_+K+N]=V-B,K!==O&&(X=T*L-q*g,g=T*g+q*L,L=X)}},U.prototype.guessLen13b=function(p,x){var y=Math.max(x,p)|1,I=y&1,C=0;for(y=y/2|0;y;y=y>>>1)C++;return 1<<C+1+I},U.prototype.conjugate=function(p,x,y){if(!(y<=1))for(var I=0;I<y/2;I++){var C=p[I];p[I]=p[y-I-1],p[y-I-1]=C,C=x[I],x[I]=-x[y-I-1],x[y-I-1]=-C}},U.prototype.normalize13b=function(p,x){for(var y=0,I=0;I<x/2;I++){var C=Math.round(p[2*I+1]/x)*8192+Math.round(p[2*I]/x)+y;p[I]=C&67108863,C<67108864?y=0:y=C/67108864|0}return p},U.prototype.convert13b=function(p,x,y,I){for(var C=0,F=0;F<x;F++)C=C+(p[F]|0),y[2*F]=C&8191,C=C>>>13,y[2*F+1]=C&8191,C=C>>>13;for(F=2*x;F<I;++F)y[F]=0;t(C===0),t((C&-8192)===0)},U.prototype.stub=function(p){for(var x=new Array(p),y=0;y<p;y++)x[y]=0;return x},U.prototype.mulp=function(p,x,y){var I=2*this.guessLen13b(p.length,x.length),C=this.makeRBT(I),F=this.stub(I),N=new Array(I),O=new Array(I),T=new Array(I),q=new Array(I),_=new Array(I),L=new Array(I),g=y.words;g.length=I,this.convert13b(p.words,p.length,N,I),this.convert13b(x.words,x.length,q,I),this.transform(N,F,O,T,I,C),this.transform(q,F,_,L,I,C);for(var K=0;K<I;K++){var E=O[K]*_[K]-T[K]*L[K];T[K]=O[K]*L[K]+T[K]*_[K],O[K]=E}return this.conjugate(O,T,I),this.transform(O,T,g,F,I,C),this.conjugate(g,F,I),this.normalize13b(g,I),y.negative=p.negative^x.negative,y.length=p.length+x.length,y._strip()},i.prototype.mul=function(p){var x=new i(null);return x.words=new Array(this.length+p.length),this.mulTo(p,x)},i.prototype.mulf=function(p){var x=new i(null);return x.words=new Array(this.length+p.length),G(this,p,x)},i.prototype.imul=function(p){return this.clone().mulTo(p,this)},i.prototype.imuln=function(p){var x=p<0;x&&(p=-p),t(typeof p=="number"),t(p<67108864);for(var y=0,I=0;I<this.length;I++){var C=(this.words[I]|0)*p,F=(C&67108863)+(y&67108863);y>>=26,y+=C/67108864|0,y+=F>>>26,this.words[I]=F&67108863}return y!==0&&(this.words[I]=y,this.length++),this.length=p===0?1:this.length,x?this.ineg():this},i.prototype.muln=function(p){return this.clone().imuln(p)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(p){var x=w(p);if(x.length===0)return new i(1);for(var y=this,I=0;I<x.length&&x[I]===0;I++,y=y.sqr());if(++I<x.length)for(var C=y.sqr();I<x.length;I++,C=C.sqr())x[I]!==0&&(y=y.mul(C));return y},i.prototype.iushln=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26,I=67108863>>>26-x<<26-x,C;if(x!==0){var F=0;for(C=0;C<this.length;C++){var N=this.words[C]&I,O=(this.words[C]|0)-N<<x;this.words[C]=O|F,F=N>>>26-x}F&&(this.words[C]=F,this.length++)}if(y!==0){for(C=this.length-1;C>=0;C--)this.words[C+y]=this.words[C];for(C=0;C<y;C++)this.words[C]=0;this.length+=y}return this._strip()},i.prototype.ishln=function(p){return t(this.negative===0),this.iushln(p)},i.prototype.iushrn=function(p,x,y){t(typeof p=="number"&&p>=0);var I;x?I=(x-x%26)/26:I=0;var C=p%26,F=Math.min((p-C)/26,this.length),N=67108863^67108863>>>C<<C,O=y;if(I-=F,I=Math.max(0,I),O){for(var T=0;T<F;T++)O.words[T]=this.words[T];O.length=F}if(F!==0)if(this.length>F)for(this.length-=F,T=0;T<this.length;T++)this.words[T]=this.words[T+F];else this.words[0]=0,this.length=1;var q=0;for(T=this.length-1;T>=0&&(q!==0||T>=I);T--){var _=this.words[T]|0;this.words[T]=q<<26-C|_>>>C,q=_&N}return O&&q!==0&&(O.words[O.length++]=q),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(p,x,y){return t(this.negative===0),this.iushrn(p,x,y)},i.prototype.shln=function(p){return this.clone().ishln(p)},i.prototype.ushln=function(p){return this.clone().iushln(p)},i.prototype.shrn=function(p){return this.clone().ishrn(p)},i.prototype.ushrn=function(p){return this.clone().iushrn(p)},i.prototype.testn=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26,I=1<<x;if(this.length<=y)return!1;var C=this.words[y];return!!(C&I)},i.prototype.imaskn=function(p){t(typeof p=="number"&&p>=0);var x=p%26,y=(p-x)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=y)return this;if(x!==0&&y++,this.length=Math.min(y,this.length),x!==0){var I=67108863^67108863>>>x<<x;this.words[this.length-1]&=I}return this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.maskn=function(p){return this.clone().imaskn(p)},i.prototype.iaddn=function(p){return t(typeof p=="number"),t(p<67108864),p<0?this.isubn(-p):this.negative!==0?this.length===1&&(this.words[0]|0)<=p?(this.words[0]=p-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(p),this.negative=1,this):this._iaddn(p)},i.prototype._iaddn=function(p){this.words[0]+=p;for(var x=0;x<this.length&&this.words[x]>=67108864;x++)this.words[x]-=67108864,x===this.length-1?this.words[x+1]=1:this.words[x+1]++;return this.length=Math.max(this.length,x+1),this},i.prototype.isubn=function(p){if(t(typeof p=="number"),t(p<67108864),p<0)return this.iaddn(-p);if(this.negative!==0)return this.negative=0,this.iaddn(p),this.negative=1,this;if(this.words[0]-=p,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var x=0;x<this.length&&this.words[x]<0;x++)this.words[x]+=67108864,this.words[x+1]-=1;return this._strip()},i.prototype.addn=function(p){return this.clone().iaddn(p)},i.prototype.subn=function(p){return this.clone().isubn(p)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(p,x,y){var I=p.length+y,C;this._expand(I);var F,N=0;for(C=0;C<p.length;C++){F=(this.words[C+y]|0)+N;var O=(p.words[C]|0)*x;F-=O&67108863,N=(F>>26)-(O/67108864|0),this.words[C+y]=F&67108863}for(;C<this.length-y;C++)F=(this.words[C+y]|0)+N,N=F>>26,this.words[C+y]=F&67108863;if(N===0)return this._strip();for(t(N===-1),N=0,C=0;C<this.length;C++)F=-(this.words[C]|0)+N,N=F>>26,this.words[C]=F&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(p,x){var y=this.length-p.length,I=this.clone(),C=p,F=C.words[C.length-1]|0,N=this._countBits(F);y=26-N,y!==0&&(C=C.ushln(y),I.iushln(y),F=C.words[C.length-1]|0);var O=I.length-C.length,T;if(x!=="mod"){T=new i(null),T.length=O+1,T.words=new Array(T.length);for(var q=0;q<T.length;q++)T.words[q]=0}var _=I.clone()._ishlnsubmul(C,1,O);_.negative===0&&(I=_,T&&(T.words[O]=1));for(var L=O-1;L>=0;L--){var g=(I.words[C.length+L]|0)*67108864+(I.words[C.length+L-1]|0);for(g=Math.min(g/F|0,67108863),I._ishlnsubmul(C,g,L);I.negative!==0;)g--,I.negative=0,I._ishlnsubmul(C,1,L),I.isZero()||(I.negative^=1);T&&(T.words[L]=g)}return T&&T._strip(),I._strip(),x!=="div"&&y!==0&&I.iushrn(y),{div:T||null,mod:I}},i.prototype.divmod=function(p,x,y){if(t(!p.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var I,C,F;return this.negative!==0&&p.negative===0?(F=this.neg().divmod(p,x),x!=="mod"&&(I=F.div.neg()),x!=="div"&&(C=F.mod.neg(),y&&C.negative!==0&&C.iadd(p)),{div:I,mod:C}):this.negative===0&&p.negative!==0?(F=this.divmod(p.neg(),x),x!=="mod"&&(I=F.div.neg()),{div:I,mod:F.mod}):(this.negative&p.negative)!==0?(F=this.neg().divmod(p.neg(),x),x!=="div"&&(C=F.mod.neg(),y&&C.negative!==0&&C.isub(p)),{div:F.div,mod:C}):p.length>this.length||this.cmp(p)<0?{div:new i(0),mod:this}:p.length===1?x==="div"?{div:this.divn(p.words[0]),mod:null}:x==="mod"?{div:null,mod:new i(this.modrn(p.words[0]))}:{div:this.divn(p.words[0]),mod:new i(this.modrn(p.words[0]))}:this._wordDiv(p,x)},i.prototype.div=function(p){return this.divmod(p,"div",!1).div},i.prototype.mod=function(p){return this.divmod(p,"mod",!1).mod},i.prototype.umod=function(p){return this.divmod(p,"mod",!0).mod},i.prototype.divRound=function(p){var x=this.divmod(p);if(x.mod.isZero())return x.div;var y=x.div.negative!==0?x.mod.isub(p):x.mod,I=p.ushrn(1),C=p.andln(1),F=y.cmp(I);return F<0||C===1&&F===0?x.div:x.div.negative!==0?x.div.isubn(1):x.div.iaddn(1)},i.prototype.modrn=function(p){var x=p<0;x&&(p=-p),t(p<=67108863);for(var y=(1<<26)%p,I=0,C=this.length-1;C>=0;C--)I=(y*I+(this.words[C]|0))%p;return x?-I:I},i.prototype.modn=function(p){return this.modrn(p)},i.prototype.idivn=function(p){var x=p<0;x&&(p=-p),t(p<=67108863);for(var y=0,I=this.length-1;I>=0;I--){var C=(this.words[I]|0)+y*67108864;this.words[I]=C/p|0,y=C%p}return this._strip(),x?this.ineg():this},i.prototype.divn=function(p){return this.clone().idivn(p)},i.prototype.egcd=function(p){t(p.negative===0),t(!p.isZero());var x=this,y=p.clone();x.negative!==0?x=x.umod(p):x=x.clone();for(var I=new i(1),C=new i(0),F=new i(0),N=new i(1),O=0;x.isEven()&&y.isEven();)x.iushrn(1),y.iushrn(1),++O;for(var T=y.clone(),q=x.clone();!x.isZero();){for(var _=0,L=1;(x.words[0]&L)===0&&_<26;++_,L<<=1);if(_>0)for(x.iushrn(_);_-- >0;)(I.isOdd()||C.isOdd())&&(I.iadd(T),C.isub(q)),I.iushrn(1),C.iushrn(1);for(var g=0,K=1;(y.words[0]&K)===0&&g<26;++g,K<<=1);if(g>0)for(y.iushrn(g);g-- >0;)(F.isOdd()||N.isOdd())&&(F.iadd(T),N.isub(q)),F.iushrn(1),N.iushrn(1);x.cmp(y)>=0?(x.isub(y),I.isub(F),C.isub(N)):(y.isub(x),F.isub(I),N.isub(C))}return{a:F,b:N,gcd:y.iushln(O)}},i.prototype._invmp=function(p){t(p.negative===0),t(!p.isZero());var x=this,y=p.clone();x.negative!==0?x=x.umod(p):x=x.clone();for(var I=new i(1),C=new i(0),F=y.clone();x.cmpn(1)>0&&y.cmpn(1)>0;){for(var N=0,O=1;(x.words[0]&O)===0&&N<26;++N,O<<=1);if(N>0)for(x.iushrn(N);N-- >0;)I.isOdd()&&I.iadd(F),I.iushrn(1);for(var T=0,q=1;(y.words[0]&q)===0&&T<26;++T,q<<=1);if(T>0)for(y.iushrn(T);T-- >0;)C.isOdd()&&C.iadd(F),C.iushrn(1);x.cmp(y)>=0?(x.isub(y),I.isub(C)):(y.isub(x),C.isub(I))}var _;return x.cmpn(1)===0?_=I:_=C,_.cmpn(0)<0&&_.iadd(p),_},i.prototype.gcd=function(p){if(this.isZero())return p.abs();if(p.isZero())return this.abs();var x=this.clone(),y=p.clone();x.negative=0,y.negative=0;for(var I=0;x.isEven()&&y.isEven();I++)x.iushrn(1),y.iushrn(1);do{for(;x.isEven();)x.iushrn(1);for(;y.isEven();)y.iushrn(1);var C=x.cmp(y);if(C<0){var F=x;x=y,y=F}else if(C===0||y.cmpn(1)===0)break;x.isub(y)}while(!0);return y.iushln(I)},i.prototype.invm=function(p){return this.egcd(p).a.umod(p)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(p){return this.words[0]&p},i.prototype.bincn=function(p){t(typeof p=="number");var x=p%26,y=(p-x)/26,I=1<<x;if(this.length<=y)return this._expand(y+1),this.words[y]|=I,this;for(var C=I,F=y;C!==0&&F<this.length;F++){var N=this.words[F]|0;N+=C,C=N>>>26,N&=67108863,this.words[F]=N}return C!==0&&(this.words[F]=C,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(p){var x=p<0;if(this.negative!==0&&!x)return-1;if(this.negative===0&&x)return 1;this._strip();var y;if(this.length>1)y=1;else{x&&(p=-p),t(p<=67108863,"Number is too big");var I=this.words[0]|0;y=I===p?0:I<p?-1:1}return this.negative!==0?-y|0:y},i.prototype.cmp=function(p){if(this.negative!==0&&p.negative===0)return-1;if(this.negative===0&&p.negative!==0)return 1;var x=this.ucmp(p);return this.negative!==0?-x|0:x},i.prototype.ucmp=function(p){if(this.length>p.length)return 1;if(this.length<p.length)return-1;for(var x=0,y=this.length-1;y>=0;y--){var I=this.words[y]|0,C=p.words[y]|0;if(I!==C){I<C?x=-1:I>C&&(x=1);break}}return x},i.prototype.gtn=function(p){return this.cmpn(p)===1},i.prototype.gt=function(p){return this.cmp(p)===1},i.prototype.gten=function(p){return this.cmpn(p)>=0},i.prototype.gte=function(p){return this.cmp(p)>=0},i.prototype.ltn=function(p){return this.cmpn(p)===-1},i.prototype.lt=function(p){return this.cmp(p)===-1},i.prototype.lten=function(p){return this.cmpn(p)<=0},i.prototype.lte=function(p){return this.cmp(p)<=0},i.prototype.eqn=function(p){return this.cmpn(p)===0},i.prototype.eq=function(p){return this.cmp(p)===0},i.red=function(p){return new Y(p)},i.prototype.toRed=function(p){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),p.convertTo(this)._forceRed(p)},i.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(p){return this.red=p,this},i.prototype.forceRed=function(p){return t(!this.red,"Already a number in reduction context"),this._forceRed(p)},i.prototype.redAdd=function(p){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,p)},i.prototype.redIAdd=function(p){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,p)},i.prototype.redSub=function(p){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,p)},i.prototype.redISub=function(p){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,p)},i.prototype.redShl=function(p){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,p)},i.prototype.redMul=function(p){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,p),this.red.mul(this,p)},i.prototype.redIMul=function(p){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,p),this.red.imul(this,p)},i.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(p){return t(this.red&&!p.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,p)};var H={k256:null,p224:null,p192:null,p25519:null};function M(v,p){this.name=v,this.p=new i(p,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}M.prototype._tmp=function(){var p=new i(null);return p.words=new Array(Math.ceil(this.n/13)),p},M.prototype.ireduce=function(p){var x=p,y;do this.split(x,this.tmp),x=this.imulK(x),x=x.iadd(this.tmp),y=x.bitLength();while(y>this.n);var I=y<this.n?-1:x.ucmp(this.p);return I===0?(x.words[0]=0,x.length=1):I>0?x.isub(this.p):x.strip!==void 0?x.strip():x._strip(),x},M.prototype.split=function(p,x){p.iushrn(this.n,0,x)},M.prototype.imulK=function(p){return p.imul(this.k)};function A(){M.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(A,M),A.prototype.split=function(p,x){for(var y=4194303,I=Math.min(p.length,9),C=0;C<I;C++)x.words[C]=p.words[C];if(x.length=I,p.length<=9){p.words[0]=0,p.length=1;return}var F=p.words[9];for(x.words[x.length++]=F&y,C=10;C<p.length;C++){var N=p.words[C]|0;p.words[C-10]=(N&y)<<4|F>>>22,F=N}F>>>=22,p.words[C-10]=F,F===0&&p.length>10?p.length-=10:p.length-=9},A.prototype.imulK=function(p){p.words[p.length]=0,p.words[p.length+1]=0,p.length+=2;for(var x=0,y=0;y<p.length;y++){var I=p.words[y]|0;x+=I*977,p.words[y]=x&67108863,x=I*64+(x/67108864|0)}return p.words[p.length-1]===0&&(p.length--,p.words[p.length-1]===0&&p.length--),p};function D(){M.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(D,M);function z(){M.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(z,M);function j(){M.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(j,M),j.prototype.imulK=function(p){for(var x=0,y=0;y<p.length;y++){var I=(p.words[y]|0)*19+x,C=I&67108863;I>>>=26,p.words[y]=C,x=I}return x!==0&&(p.words[p.length++]=x),p},i._prime=function(p){if(H[p])return H[p];var x;if(p==="k256")x=new A;else if(p==="p224")x=new D;else if(p==="p192")x=new z;else if(p==="p25519")x=new j;else throw new Error("Unknown prime "+p);return H[p]=x,x};function Y(v){if(typeof v=="string"){var p=i._prime(v);this.m=p.p,this.prime=p}else t(v.gtn(1),"modulus must be greater than 1"),this.m=v,this.prime=null}Y.prototype._verify1=function(p){t(p.negative===0,"red works only with positives"),t(p.red,"red works only with red numbers")},Y.prototype._verify2=function(p,x){t((p.negative|x.negative)===0,"red works only with positives"),t(p.red&&p.red===x.red,"red works only with red numbers")},Y.prototype.imod=function(p){return this.prime?this.prime.ireduce(p)._forceRed(this):(u(p,p.umod(this.m)._forceRed(this)),p)},Y.prototype.neg=function(p){return p.isZero()?p.clone():this.m.sub(p)._forceRed(this)},Y.prototype.add=function(p,x){this._verify2(p,x);var y=p.add(x);return y.cmp(this.m)>=0&&y.isub(this.m),y._forceRed(this)},Y.prototype.iadd=function(p,x){this._verify2(p,x);var y=p.iadd(x);return y.cmp(this.m)>=0&&y.isub(this.m),y},Y.prototype.sub=function(p,x){this._verify2(p,x);var y=p.sub(x);return y.cmpn(0)<0&&y.iadd(this.m),y._forceRed(this)},Y.prototype.isub=function(p,x){this._verify2(p,x);var y=p.isub(x);return y.cmpn(0)<0&&y.iadd(this.m),y},Y.prototype.shl=function(p,x){return this._verify1(p),this.imod(p.ushln(x))},Y.prototype.imul=function(p,x){return this._verify2(p,x),this.imod(p.imul(x))},Y.prototype.mul=function(p,x){return this._verify2(p,x),this.imod(p.mul(x))},Y.prototype.isqr=function(p){return this.imul(p,p.clone())},Y.prototype.sqr=function(p){return this.mul(p,p)},Y.prototype.sqrt=function(p){if(p.isZero())return p.clone();var x=this.m.andln(3);if(t(x%2===1),x===3){var y=this.m.add(new i(1)).iushrn(2);return this.pow(p,y)}for(var I=this.m.subn(1),C=0;!I.isZero()&&I.andln(1)===0;)C++,I.iushrn(1);t(!I.isZero());var F=new i(1).toRed(this),N=F.redNeg(),O=this.m.subn(1).iushrn(1),T=this.m.bitLength();for(T=new i(2*T*T).toRed(this);this.pow(T,O).cmp(N)!==0;)T.redIAdd(N);for(var q=this.pow(T,I),_=this.pow(p,I.addn(1).iushrn(1)),L=this.pow(p,I),g=C;L.cmp(F)!==0;){for(var K=L,E=0;K.cmp(F)!==0;E++)K=K.redSqr();t(E<g);var V=this.pow(q,new i(1).iushln(g-E-1));_=_.redMul(V),q=V.redSqr(),L=L.redMul(q),g=E}return _},Y.prototype.invm=function(p){var x=p._invmp(this.m);return x.negative!==0?(x.negative=0,this.imod(x).redNeg()):this.imod(x)},Y.prototype.pow=function(p,x){if(x.isZero())return new i(1).toRed(this);if(x.cmpn(1)===0)return p.clone();var y=4,I=new Array(1<<y);I[0]=new i(1).toRed(this),I[1]=p;for(var C=2;C<I.length;C++)I[C]=this.mul(I[C-1],p);var F=I[0],N=0,O=0,T=x.bitLength()%26;for(T===0&&(T=26),C=x.length-1;C>=0;C--){for(var q=x.words[C],_=T-1;_>=0;_--){var L=q>>_&1;if(F!==I[0]&&(F=this.sqr(F)),L===0&&N===0){O=0;continue}N<<=1,N|=L,O++,!(O!==y&&(C!==0||_!==0))&&(F=this.mul(F,I[N]),O=0,N=0)}T=26}return F},Y.prototype.convertTo=function(p){var x=p.umod(this.m);return x===p?x.clone():x},Y.prototype.convertFrom=function(p){var x=p.clone();return x.red=null,x},i.mont=function(p){return new Q(p)};function Q(v){Y.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(Q,Y),Q.prototype.convertTo=function(p){return this.imod(p.ushln(this.shift))},Q.prototype.convertFrom=function(p){var x=this.imod(p.mul(this.rinv));return x.red=null,x},Q.prototype.imul=function(p,x){if(p.isZero()||x.isZero())return p.words[0]=0,p.length=1,p;var y=p.imul(x),I=y.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),C=y.isub(I).iushrn(this.shift),F=C;return C.cmp(this.m)>=0?F=C.isub(this.m):C.cmpn(0)<0&&(F=C.iadd(this.m)),F._forceRed(this)},Q.prototype.mul=function(p,x){if(p.isZero()||x.isZero())return new i(0)._forceRed(this);var y=p.mul(x),I=y.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),C=y.isub(I).iushrn(this.shift),F=C;return C.cmp(this.m)>=0?F=C.isub(this.m):C.cmpn(0)<0&&(F=C.iadd(this.m)),F._forceRed(this)},Q.prototype.invm=function(p){var x=this.imod(p._invmp(this.m).mul(this.r2));return x._forceRed(this)}})(typeof FR>"u"||FR,W9)});var _9=oe(Sx=>{"use strict";Sx.byteLength=Pce;Sx.toByteArray=Mce;Sx.fromByteArray=Nce;var cu=[],wa=[],Bce=typeof Uint8Array<"u"?Uint8Array:Array,UR="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(wp=0,Z9=UR.length;wp<Z9;++wp)cu[wp]=UR[wp],wa[UR.charCodeAt(wp)]=wp;var wp,Z9;wa[45]=62;wa[95]=63;function X9(n){var e=n.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=n.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function Pce(n){var e=X9(n),t=e[0],r=e[1];return(t+r)*3/4-r}function kce(n,e,t){return(e+t)*3/4-t}function Mce(n){var e,t=X9(n),r=t[0],i=t[1],o=new Bce(kce(n,r,i)),s=0,a=i>0?r-4:r,c;for(c=0;c<a;c+=4)e=wa[n.charCodeAt(c)]<<18|wa[n.charCodeAt(c+1)]<<12|wa[n.charCodeAt(c+2)]<<6|wa[n.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=wa[n.charCodeAt(c)]<<2|wa[n.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=wa[n.charCodeAt(c)]<<10|wa[n.charCodeAt(c+1)]<<4|wa[n.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Oce(n){return cu[n>>18&63]+cu[n>>12&63]+cu[n>>6&63]+cu[n&63]}function Fce(n,e,t){for(var r,i=[],o=e;o<t;o+=3)r=(n[o]<<16&16711680)+(n[o+1]<<8&65280)+(n[o+2]&255),i.push(Oce(r));return i.join("")}function Nce(n){for(var e,t=n.length,r=t%3,i=[],o=16383,s=0,a=t-r;s<a;s+=o)i.push(Fce(n,s,s+o>a?a:s+o));return r===1?(e=n[t-1],i.push(cu[e>>2]+cu[e<<4&63]+"==")):r===2&&(e=(n[t-2]<<8)+n[t-1],i.push(cu[e>>10]+cu[e>>4&63]+cu[e<<2&63]+"=")),i.join("")}});var $9=oe(GR=>{"use strict";GR.read=function(n,e,t,r,i){var o,s,a=i*8-r-1,c=(1<<a)-1,u=c>>1,l=-7,d=t?i-1:0,h=t?-1:1,f=n[e+d];for(d+=h,o=f&(1<<-l)-1,f>>=-l,l+=a;l>0;o=o*256+n[e+d],d+=h,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=s*256+n[e+d],d+=h,l-=8);if(o===0)o=1-u;else{if(o===c)return s?NaN:(f?-1:1)*(1/0);s=s+Math.pow(2,r),o=o-u}return(f?-1:1)*s*Math.pow(2,o-r)};GR.write=function(n,e,t,r,i,o){var s,a,c,u=o*8-i-1,l=(1<<u)-1,d=l>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:o-1,m=r?1:-1,w=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+d>=1?e+=h/c:e+=h*Math.pow(2,1-d),e*c>=2&&(s++,c/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*c-1)*Math.pow(2,i),s=s+d):(a=e*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;n[t+f]=a&255,f+=m,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;n[t+f]=s&255,f+=m,s/=256,u-=8);n[t+f-m]|=w*128}});var _m=oe(Xm=>{"use strict";var HR=_9(),Wm=$9(),eH=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Xm.Buffer=Ee;Xm.SlowBuffer=qce;Xm.INSPECT_MAX_BYTES=50;var Cx=2147483647;Xm.kMaxLength=Cx;Ee.TYPED_ARRAY_SUPPORT=Uce();!Ee.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Uce(){try{let n=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(n,e),n.foo()===42}catch{return!1}}Object.defineProperty(Ee.prototype,"parent",{enumerable:!0,get:function(){if(Ee.isBuffer(this))return this.buffer}});Object.defineProperty(Ee.prototype,"offset",{enumerable:!0,get:function(){if(Ee.isBuffer(this))return this.byteOffset}});function Il(n){if(n>Cx)throw new RangeError('The value "'+n+'" is invalid for option "size"');let e=new Uint8Array(n);return Object.setPrototypeOf(e,Ee.prototype),e}function Ee(n,e,t){if(typeof n=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return VR(n)}return iH(n,e,t)}Ee.poolSize=8192;function iH(n,e,t){if(typeof n=="string")return Hce(n,e);if(ArrayBuffer.isView(n))return Kce(n);if(n==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n);if(uu(n,ArrayBuffer)||n&&uu(n.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(uu(n,SharedArrayBuffer)||n&&uu(n.buffer,SharedArrayBuffer)))return JR(n,e,t);if(typeof n=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=n.valueOf&&n.valueOf();if(r!=null&&r!==n)return Ee.from(r,e,t);let i=Jce(n);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof n[Symbol.toPrimitive]=="function")return Ee.from(n[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof n)}Ee.from=function(n,e,t){return iH(n,e,t)};Object.setPrototypeOf(Ee.prototype,Uint8Array.prototype);Object.setPrototypeOf(Ee,Uint8Array);function oH(n){if(typeof n!="number")throw new TypeError('"size" argument must be of type number');if(n<0)throw new RangeError('The value "'+n+'" is invalid for option "size"')}function Gce(n,e,t){return oH(n),n<=0?Il(n):e!==void 0?typeof t=="string"?Il(n).fill(e,t):Il(n).fill(e):Il(n)}Ee.alloc=function(n,e,t){return Gce(n,e,t)};function VR(n){return oH(n),Il(n<0?0:QR(n)|0)}Ee.allocUnsafe=function(n){return VR(n)};Ee.allocUnsafeSlow=function(n){return VR(n)};function Hce(n,e){if((typeof e!="string"||e==="")&&(e="utf8"),!Ee.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=sH(n,e)|0,r=Il(t),i=r.write(n,e);return i!==t&&(r=r.slice(0,i)),r}function KR(n){let e=n.length<0?0:QR(n.length)|0,t=Il(e);for(let r=0;r<e;r+=1)t[r]=n[r]&255;return t}function Kce(n){if(uu(n,Uint8Array)){let e=new Uint8Array(n);return JR(e.buffer,e.byteOffset,e.byteLength)}return KR(n)}function JR(n,e,t){if(e<0||n.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(n.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let r;return e===void 0&&t===void 0?r=new Uint8Array(n):t===void 0?r=new Uint8Array(n,e):r=new Uint8Array(n,e,t),Object.setPrototypeOf(r,Ee.prototype),r}function Jce(n){if(Ee.isBuffer(n)){let e=QR(n.length)|0,t=Il(e);return t.length===0||n.copy(t,0,0,e),t}if(n.length!==void 0)return typeof n.length!="number"||YR(n.length)?Il(0):KR(n);if(n.type==="Buffer"&&Array.isArray(n.data))return KR(n.data)}function QR(n){if(n>=Cx)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Cx.toString(16)+" bytes");return n|0}function qce(n){return+n!=n&&(n=0),Ee.alloc(+n)}Ee.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==Ee.prototype};Ee.compare=function(e,t){if(uu(e,Uint8Array)&&(e=Ee.from(e,e.offset,e.byteLength)),uu(t,Uint8Array)&&(t=Ee.from(t,t.offset,t.byteLength)),!Ee.isBuffer(e)||!Ee.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,i=t.length;for(let o=0,s=Math.min(r,i);o<s;++o)if(e[o]!==t[o]){r=e[o],i=t[o];break}return r<i?-1:i<r?1:0};Ee.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};Ee.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return Ee.alloc(0);let r;if(t===void 0)for(t=0,r=0;r<e.length;++r)t+=e[r].length;let i=Ee.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){let s=e[r];if(uu(s,Uint8Array))o+s.length>i.length?(Ee.isBuffer(s)||(s=Ee.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(Ee.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function sH(n,e){if(Ee.isBuffer(n))return n.length;if(ArrayBuffer.isView(n)||uu(n,ArrayBuffer))return n.byteLength;if(typeof n!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof n);let t=n.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return qR(n).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return mH(n).length;default:if(i)return r?-1:qR(n).length;e=(""+e).toLowerCase(),i=!0}}Ee.byteLength=sH;function Vce(n,e,t){let r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(n||(n="utf8");;)switch(n){case"hex":return eue(this,e,t);case"utf8":case"utf-8":return cH(this,e,t);case"ascii":return _ce(this,e,t);case"latin1":case"binary":return $ce(this,e,t);case"base64":return Zce(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return tue(this,e,t);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(n+"").toLowerCase(),r=!0}}Ee.prototype._isBuffer=!0;function bp(n,e,t){let r=n[e];n[e]=n[t],n[t]=r}Ee.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)bp(this,t,t+1);return this};Ee.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)bp(this,t,t+3),bp(this,t+1,t+2);return this};Ee.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)bp(this,t,t+7),bp(this,t+1,t+6),bp(this,t+2,t+5),bp(this,t+3,t+4);return this};Ee.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?cH(this,0,e):Vce.apply(this,arguments)};Ee.prototype.toLocaleString=Ee.prototype.toString;Ee.prototype.equals=function(e){if(!Ee.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:Ee.compare(this,e)===0};Ee.prototype.inspect=function(){let e="",t=Xm.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};eH&&(Ee.prototype[eH]=Ee.prototype.inspect);Ee.prototype.compare=function(e,t,r,i,o){if(uu(e,Uint8Array)&&(e=Ee.from(e,e.offset,e.byteLength)),!Ee.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),r===void 0&&(r=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||r>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=r)return 0;if(i>=o)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=r-t,c=Math.min(s,a),u=this.slice(i,o),l=e.slice(t,r);for(let d=0;d<c;++d)if(u[d]!==l[d]){s=u[d],a=l[d];break}return s<a?-1:a<s?1:0};function aH(n,e,t,r,i){if(n.length===0)return-1;if(typeof t=="string"?(r=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,YR(t)&&(t=i?0:n.length-1),t<0&&(t=n.length+t),t>=n.length){if(i)return-1;t=n.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=Ee.from(e,r)),Ee.isBuffer(e))return e.length===0?-1:tH(n,e,t,r,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(n,e,t):Uint8Array.prototype.lastIndexOf.call(n,e,t):tH(n,[e],t,r,i);throw new TypeError("val must be string, number or Buffer")}function tH(n,e,t,r,i){let o=1,s=n.length,a=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(n.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function c(l,d){return o===1?l[d]:l.readUInt16BE(d*o)}let u;if(i){let l=-1;for(u=t;u<s;u++)if(c(n,u)===c(e,l===-1?0:u-l)){if(l===-1&&(l=u),u-l+1===a)return l*o}else l!==-1&&(u-=u-l),l=-1}else for(t+a>s&&(t=s-a),u=t;u>=0;u--){let l=!0;for(let d=0;d<a;d++)if(c(n,u+d)!==c(e,d)){l=!1;break}if(l)return u}return-1}Ee.prototype.includes=function(e,t,r){return this.indexOf(e,t,r)!==-1};Ee.prototype.indexOf=function(e,t,r){return aH(this,e,t,r,!0)};Ee.prototype.lastIndexOf=function(e,t,r){return aH(this,e,t,r,!1)};function Qce(n,e,t,r){t=Number(t)||0;let i=n.length-t;r?(r=Number(r),r>i&&(r=i)):r=i;let o=e.length;r>o/2&&(r=o/2);let s;for(s=0;s<r;++s){let a=parseInt(e.substr(s*2,2),16);if(YR(a))return s;n[t+s]=a}return s}function zce(n,e,t,r){return Lx(qR(e,n.length-t),n,t,r)}function Yce(n,e,t,r){return Lx(oue(e),n,t,r)}function jce(n,e,t,r){return Lx(mH(e),n,t,r)}function Wce(n,e,t,r){return Lx(sue(e,n.length-t),n,t,r)}Ee.prototype.write=function(e,t,r,i){if(t===void 0)i="utf8",r=this.length,t=0;else if(r===void 0&&typeof t=="string")i=t,r=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(r)?(r=r>>>0,i===void 0&&(i="utf8")):(i=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((r===void 0||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Qce(this,e,t,r);case"utf8":case"utf-8":return zce(this,e,t,r);case"ascii":case"latin1":case"binary":return Yce(this,e,t,r);case"base64":return jce(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Wce(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};Ee.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Zce(n,e,t){return e===0&&t===n.length?HR.fromByteArray(n):HR.fromByteArray(n.slice(e,t))}function cH(n,e,t){t=Math.min(n.length,t);let r=[],i=e;for(;i<t;){let o=n[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let c,u,l,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=n[i+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=n[i+1],u=n[i+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=n[i+1],u=n[i+2],l=n[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),i+=a}return Xce(r)}var nH=4096;function Xce(n){let e=n.length;if(e<=nH)return String.fromCharCode.apply(String,n);let t="",r=0;for(;r<e;)t+=String.fromCharCode.apply(String,n.slice(r,r+=nH));return t}function _ce(n,e,t){let r="";t=Math.min(n.length,t);for(let i=e;i<t;++i)r+=String.fromCharCode(n[i]&127);return r}function $ce(n,e,t){let r="";t=Math.min(n.length,t);for(let i=e;i<t;++i)r+=String.fromCharCode(n[i]);return r}function eue(n,e,t){let r=n.length;(!e||e<0)&&(e=0),(!t||t<0||t>r)&&(t=r);let i="";for(let o=e;o<t;++o)i+=aue[n[o]];return i}function tue(n,e,t){let r=n.slice(e,t),i="";for(let o=0;o<r.length-1;o+=2)i+=String.fromCharCode(r[o]+r[o+1]*256);return i}Ee.prototype.slice=function(e,t){let r=this.length;e=~~e,t=t===void 0?r:~~t,e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,Ee.prototype),i};function ii(n,e,t){if(n%1!==0||n<0)throw new RangeError("offset is not uint");if(n+e>t)throw new RangeError("Trying to access beyond buffer length")}Ee.prototype.readUintLE=Ee.prototype.readUIntLE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};Ee.prototype.readUintBE=Ee.prototype.readUIntBE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};Ee.prototype.readUint8=Ee.prototype.readUInt8=function(e,t){return e=e>>>0,t||ii(e,1,this.length),this[e]};Ee.prototype.readUint16LE=Ee.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||ii(e,2,this.length),this[e]|this[e+1]<<8};Ee.prototype.readUint16BE=Ee.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||ii(e,2,this.length),this[e]<<8|this[e+1]};Ee.prototype.readUint32LE=Ee.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};Ee.prototype.readUint32BE=Ee.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};Ee.prototype.readBigUInt64LE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+r*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});Ee.prototype.readBigUInt64BE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r;return(BigInt(i)<<BigInt(32))+BigInt(o)});Ee.prototype.readIntLE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};Ee.prototype.readIntBE=function(e,t,r){e=e>>>0,t=t>>>0,r||ii(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};Ee.prototype.readInt8=function(e,t){return e=e>>>0,t||ii(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};Ee.prototype.readInt16LE=function(e,t){e=e>>>0,t||ii(e,2,this.length);let r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};Ee.prototype.readInt16BE=function(e,t){e=e>>>0,t||ii(e,2,this.length);let r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};Ee.prototype.readInt32LE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};Ee.prototype.readInt32BE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};Ee.prototype.readBigInt64LE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(r<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});Ee.prototype.readBigInt64BE=mf(function(e){e=e>>>0,Zm(e,"offset");let t=this[e],r=this[e+7];(t===void 0||r===void 0)&&pb(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r)});Ee.prototype.readFloatLE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),Wm.read(this,e,!0,23,4)};Ee.prototype.readFloatBE=function(e,t){return e=e>>>0,t||ii(e,4,this.length),Wm.read(this,e,!1,23,4)};Ee.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||ii(e,8,this.length),Wm.read(this,e,!0,52,8)};Ee.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||ii(e,8,this.length),Wm.read(this,e,!1,52,8)};function rs(n,e,t,r,i,o){if(!Ee.isBuffer(n))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+r>n.length)throw new RangeError("Index out of range")}Ee.prototype.writeUintLE=Ee.prototype.writeUIntLE=function(e,t,r,i){if(e=+e,t=t>>>0,r=r>>>0,!i){let a=Math.pow(2,8*r)-1;rs(this,e,t,r,a,0)}let o=1,s=0;for(this[t]=e&255;++s<r&&(o*=256);)this[t+s]=e/o&255;return t+r};Ee.prototype.writeUintBE=Ee.prototype.writeUIntBE=function(e,t,r,i){if(e=+e,t=t>>>0,r=r>>>0,!i){let a=Math.pow(2,8*r)-1;rs(this,e,t,r,a,0)}let o=r-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+r};Ee.prototype.writeUint8=Ee.prototype.writeUInt8=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,1,255,0),this[t]=e&255,t+1};Ee.prototype.writeUint16LE=Ee.prototype.writeUInt16LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};Ee.prototype.writeUint16BE=Ee.prototype.writeUInt16BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};Ee.prototype.writeUint32LE=Ee.prototype.writeUInt32LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};Ee.prototype.writeUint32BE=Ee.prototype.writeUInt32BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function uH(n,e,t,r,i){pH(e,r,i,n,t,7);let o=Number(e&BigInt(4294967295));n[t++]=o,o=o>>8,n[t++]=o,o=o>>8,n[t++]=o,o=o>>8,n[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return n[t++]=s,s=s>>8,n[t++]=s,s=s>>8,n[t++]=s,s=s>>8,n[t++]=s,t}function lH(n,e,t,r,i){pH(e,r,i,n,t,7);let o=Number(e&BigInt(4294967295));n[t+7]=o,o=o>>8,n[t+6]=o,o=o>>8,n[t+5]=o,o=o>>8,n[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return n[t+3]=s,s=s>>8,n[t+2]=s,s=s>>8,n[t+1]=s,s=s>>8,n[t]=s,t+8}Ee.prototype.writeBigUInt64LE=mf(function(e,t=0){return uH(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});Ee.prototype.writeBigUInt64BE=mf(function(e,t=0){return lH(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});Ee.prototype.writeIntLE=function(e,t,r,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*r-1);rs(this,e,t,r,c-1,-c)}let o=0,s=1,a=0;for(this[t]=e&255;++o<r&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r};Ee.prototype.writeIntBE=function(e,t,r,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*r-1);rs(this,e,t,r,c-1,-c)}let o=r-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r};Ee.prototype.writeInt8=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};Ee.prototype.writeInt16LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};Ee.prototype.writeInt16BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};Ee.prototype.writeInt32LE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};Ee.prototype.writeInt32BE=function(e,t,r){return e=+e,t=t>>>0,r||rs(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};Ee.prototype.writeBigInt64LE=mf(function(e,t=0){return uH(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});Ee.prototype.writeBigInt64BE=mf(function(e,t=0){return lH(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function dH(n,e,t,r,i,o){if(t+r>n.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function fH(n,e,t,r,i){return e=+e,t=t>>>0,i||dH(n,e,t,4,34028234663852886e22,-34028234663852886e22),Wm.write(n,e,t,r,23,4),t+4}Ee.prototype.writeFloatLE=function(e,t,r){return fH(this,e,t,!0,r)};Ee.prototype.writeFloatBE=function(e,t,r){return fH(this,e,t,!1,r)};function hH(n,e,t,r,i){return e=+e,t=t>>>0,i||dH(n,e,t,8,17976931348623157e292,-17976931348623157e292),Wm.write(n,e,t,r,52,8),t+8}Ee.prototype.writeDoubleLE=function(e,t,r){return hH(this,e,t,!0,r)};Ee.prototype.writeDoubleBE=function(e,t,r){return hH(this,e,t,!1,r)};Ee.prototype.copy=function(e,t,r,i){if(!Ee.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<r&&(i=r),i===r||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-r&&(i=e.length-t+r);let o=i-r;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,r,i):Uint8Array.prototype.set.call(e,this.subarray(r,i),t),o};Ee.prototype.fill=function(e,t,r,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,r=this.length):typeof r=="string"&&(i=r,r=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!Ee.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;t=t>>>0,r=r===void 0?this.length:r>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<r;++o)this[o]=e;else{let s=Ee.isBuffer(e)?e:Ee.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var jm={};function zR(n,e,t){jm[n]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${n}]`,this.stack,delete this.name}get code(){return n}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${n}]: ${this.message}`}}}zR("ERR_BUFFER_OUT_OF_BOUNDS",function(n){return n?`${n} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);zR("ERR_INVALID_ARG_TYPE",function(n,e){return`The "${n}" argument must be of type number. Received type ${typeof e}`},TypeError);zR("ERR_OUT_OF_RANGE",function(n,e,t){let r=`The value of "${n}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=rH(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=rH(i)),i+="n"),r+=` It must be ${e}. Received ${i}`,r},RangeError);function rH(n){let e="",t=n.length,r=n[0]==="-"?1:0;for(;t>=r+4;t-=3)e=`_${n.slice(t-3,t)}${e}`;return`${n.slice(0,t)}${e}`}function nue(n,e,t){Zm(e,"offset"),(n[e]===void 0||n[e+t]===void 0)&&pb(e,n.length-(t+1))}function pH(n,e,t,r,i,o){if(n>t||n<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new jm.ERR_OUT_OF_RANGE("value",a,n)}nue(r,i,o)}function Zm(n,e){if(typeof n!="number")throw new jm.ERR_INVALID_ARG_TYPE(e,"number",n)}function pb(n,e,t){throw Math.floor(n)!==n?(Zm(n,t),new jm.ERR_OUT_OF_RANGE(t||"offset","an integer",n)):e<0?new jm.ERR_BUFFER_OUT_OF_BOUNDS:new jm.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,n)}var rue=/[^+/0-9A-Za-z-_]/g;function iue(n){if(n=n.split("=")[0],n=n.trim().replace(rue,""),n.length<2)return"";for(;n.length%4!==0;)n=n+"=";return n}function qR(n,e){e=e||1/0;let t,r=n.length,i=null,o=[];for(let s=0;s<r;++s){if(t=n.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function oue(n){let e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t)&255);return e}function sue(n,e){let t,r,i,o=[];for(let s=0;s<n.length&&!((e-=2)<0);++s)t=n.charCodeAt(s),r=t>>8,i=t%256,o.push(i),o.push(r);return o}function mH(n){return HR.toByteArray(iue(n))}function Lx(n,e,t,r){let i;for(i=0;i<r&&!(i+t>=e.length||i>=n.length);++i)e[i+t]=n[i];return i}function uu(n,e){return n instanceof e||n!=null&&n.constructor!=null&&n.constructor.name!=null&&n.constructor.name===e.name}function YR(n){return n!==n}var aue=(function(){let n="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let r=t*16;for(let i=0;i<16;++i)e[r+i]=n[t]+n[i]}return e})();function mf(n){return typeof BigInt>"u"?cue:n}function cue(){throw new Error("BigInt not supported")}});var WR=oe((jR,yH)=>{"use strict";var Rx=_m(),lu=Rx.Buffer;function gH(n,e){for(var t in n)e[t]=n[t]}lu.from&&lu.alloc&&lu.allocUnsafe&&lu.allocUnsafeSlow?yH.exports=Rx:(gH(Rx,jR),jR.Buffer=Ep);function Ep(n,e,t){return lu(n,e,t)}Ep.prototype=Object.create(lu.prototype);gH(lu,Ep);Ep.from=function(n,e,t){if(typeof n=="number")throw new TypeError("Argument must not be a number");return lu(n,e,t)};Ep.alloc=function(n,e,t){if(typeof n!="number")throw new TypeError("Argument must be a number");var r=lu(n);return e!==void 0?typeof t=="string"?r.fill(e,t):r.fill(e):r.fill(0),r};Ep.allocUnsafe=function(n){if(typeof n!="number")throw new TypeError("Argument must be a number");return lu(n)};Ep.allocUnsafeSlow=function(n){if(typeof n!="number")throw new TypeError("Argument must be a number");return Rx.SlowBuffer(n)}});var bH=oe((l7e,wH)=>{"use strict";var Dx=WR().Buffer;function uue(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if((Array.isArray(f)||f instanceof Uint8Array)&&(f=Dx.from(f)),!Dx.isBuffer(f))throw new TypeError("Expected Buffer");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return Dx.alloc(0);for(var m=0,w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);m<f.length;){var G=f.charCodeAt(m);if(G>255)return;var U=e[G];if(U===255)return;for(var H=0,M=S-1;(U!==0||H<b)&&M!==-1;M--,H++)U+=s*R[M]>>>0,R[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=H,m++}for(var A=S-b;A!==S&&R[A]===0;)A++;var D=Dx.allocUnsafe(w+(S-A));D.fill(0,0,w);for(var z=w;A!==S;)D[z++]=R[A++];return D}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}wH.exports=uue});var IH=oe((d7e,EH)=>{"use strict";var lue=bH(),due="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";EH.exports=lue(due)});var AH=oe(_R=>{"use strict";function Al(n,e,t){return e<=n&&n<=t}function Mx(n){if(n===void 0)return{};if(n===Object(n))return n;throw TypeError("Could not convert argument to dictionary")}function fue(n){for(var e=String(n),t=e.length,r=0,i=[];r<t;){var o=e.charCodeAt(r);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(r===t-1)i.push(65533);else{var s=n.charCodeAt(r+1);if(56320<=s&&s<=57343){var a=o&1023,c=s&1023;i.push(65536+(a<<10)+c),r+=1}else i.push(65533)}r+=1}return i}function hue(n){for(var e="",t=0;t<n.length;++t){var r=n[t];r<=65535?e+=String.fromCharCode(r):(r-=65536,e+=String.fromCharCode((r>>10)+55296,(r&1023)+56320))}return e}var Tx=-1;function XR(n){this.tokens=[].slice.call(n)}XR.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():Tx},prepend:function(n){if(Array.isArray(n))for(var e=n;e.length;)this.tokens.unshift(e.pop());else this.tokens.unshift(n)},push:function(n){if(Array.isArray(n))for(var e=n;e.length;)this.tokens.push(e.shift());else this.tokens.push(n)}};var $m=-1;function ZR(n,e){if(n)throw TypeError("Decoder error");return e||65533}var Bx="utf-8";function Px(n,e){if(!(this instanceof Px))return new Px(n,e);if(n=n!==void 0?String(n).toLowerCase():Bx,n!==Bx)throw new Error("Encoding not supported. Only utf-8 is supported");e=Mx(e),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=!!e.fatal,this._ignoreBOM=!!e.ignoreBOM,Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}Px.prototype={decode:function(e,t){var r;typeof e=="object"&&e instanceof ArrayBuffer?r=new Uint8Array(e):typeof e=="object"&&"buffer"in e&&e.buffer instanceof ArrayBuffer?r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):r=new Uint8Array(0),t=Mx(t),this._streaming||(this._decoder=new pue({fatal:this._fatal}),this._BOMseen=!1),this._streaming=!!t.stream;for(var i=new XR(r),o=[],s;!i.endOfStream()&&(s=this._decoder.handler(i,i.read()),s!==$m);)s!==null&&(Array.isArray(s)?o.push.apply(o,s):o.push(s));if(!this._streaming){do{if(s=this._decoder.handler(i,i.read()),s===$m)break;s!==null&&(Array.isArray(s)?o.push.apply(o,s):o.push(s))}while(!i.endOfStream());this._decoder=null}return o.length&&["utf-8"].indexOf(this.encoding)!==-1&&!this._ignoreBOM&&!this._BOMseen&&(o[0]===65279?(this._BOMseen=!0,o.shift()):this._BOMseen=!0),hue(o)}};function kx(n,e){if(!(this instanceof kx))return new kx(n,e);if(n=n!==void 0?String(n).toLowerCase():Bx,n!==Bx)throw new Error("Encoding not supported. Only utf-8 is supported");e=Mx(e),this._streaming=!1,this._encoder=null,this._options={fatal:!!e.fatal},Object.defineProperty(this,"encoding",{value:"utf-8"})}kx.prototype={encode:function(e,t){e=e?String(e):"",t=Mx(t),this._streaming||(this._encoder=new mue(this._options)),this._streaming=!!t.stream;for(var r=[],i=new XR(fue(e)),o;!i.endOfStream()&&(o=this._encoder.handler(i,i.read()),o!==$m);)Array.isArray(o)?r.push.apply(r,o):r.push(o);if(!this._streaming){for(;o=this._encoder.handler(i,i.read()),o!==$m;)Array.isArray(o)?r.push.apply(r,o):r.push(o);this._encoder=null}return new Uint8Array(r)}};function pue(n){var e=n.fatal,t=0,r=0,i=0,o=128,s=191;this.handler=function(a,c){if(c===Tx&&i!==0)return i=0,ZR(e);if(c===Tx)return $m;if(i===0){if(Al(c,0,127))return c;if(Al(c,194,223))i=1,t=c-192;else if(Al(c,224,239))c===224&&(o=160),c===237&&(s=159),i=2,t=c-224;else if(Al(c,240,244))c===240&&(o=144),c===244&&(s=143),i=3,t=c-240;else return ZR(e);return t=t<<6*i,null}if(!Al(c,o,s))return t=i=r=0,o=128,s=191,a.prepend(c),ZR(e);if(o=128,s=191,r+=1,t+=c-128<<6*(i-r),r!==i)return null;var u=t;return t=i=r=0,u}}function mue(n){var e=n.fatal;this.handler=function(t,r){if(r===Tx)return $m;if(Al(r,0,127))return r;var i,o;Al(r,128,2047)?(i=1,o=192):Al(r,2048,65535)?(i=2,o=224):Al(r,65536,1114111)&&(i=3,o=240);for(var s=[(r>>6*i)+o];i>0;){var a=r>>6*(i-1);s.push(128|a&63),i-=1}return s}}_R.TextEncoder=kx;_R.TextDecoder=Px});var tD=oe(Un=>{"use strict";var gue=Un&&Un.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=t),Object.defineProperty(n,r,{enumerable:!0,get:function(){return e[t]}})}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),yue=Un&&Un.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),du=Un&&Un.__decorate||function(n,e,t,r){var i=arguments.length,o=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,e,t,r);else for(var a=n.length-1;a>=0;a--)(s=n[a])&&(o=(i<3?s(o):i>3?s(e,t,o):s(e,t))||o);return i>3&&o&&Object.defineProperty(e,t,o),o},wue=Un&&Un.__importStar||function(n){if(n&&n.__esModule)return n;var e={};if(n!=null)for(var t in n)t!=="default"&&Object.hasOwnProperty.call(n,t)&&gue(e,n,t);return yue(e,n),e},xH=Un&&Un.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(Un,"__esModule",{value:!0});Un.deserializeUnchecked=Un.deserialize=Un.serialize=Un.BinaryReader=Un.BinaryWriter=Un.BorshError=Un.baseDecode=Un.baseEncode=void 0;var gf=xH(NR()),vH=xH(IH()),bue=wue(AH()),Eue=typeof TextDecoder!="function"?bue.TextDecoder:TextDecoder,Iue=new Eue("utf-8",{fatal:!0});function Aue(n){return typeof n=="string"&&(n=Buffer.from(n,"utf8")),vH.default.encode(Buffer.from(n))}Un.baseEncode=Aue;function xue(n){return Buffer.from(vH.default.decode(n))}Un.baseDecode=xue;var $R=1024,Ei=class extends Error{constructor(e){super(e),this.fieldPath=[],this.originalMessage=e}addToFieldPath(e){this.fieldPath.splice(0,0,e),this.message=this.originalMessage+": "+this.fieldPath.join(".")}};Un.BorshError=Ei;var Ox=class{constructor(){this.buf=Buffer.alloc($R),this.length=0}maybeResize(){this.buf.length<16+this.length&&(this.buf=Buffer.concat([this.buf,Buffer.alloc($R)]))}writeU8(e){this.maybeResize(),this.buf.writeUInt8(e,this.length),this.length+=1}writeU16(e){this.maybeResize(),this.buf.writeUInt16LE(e,this.length),this.length+=2}writeU32(e){this.maybeResize(),this.buf.writeUInt32LE(e,this.length),this.length+=4}writeU64(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",8)))}writeU128(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",16)))}writeU256(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",32)))}writeU512(e){this.maybeResize(),this.writeBuffer(Buffer.from(new gf.default(e).toArray("le",64)))}writeBuffer(e){this.buf=Buffer.concat([Buffer.from(this.buf.subarray(0,this.length)),e,Buffer.alloc($R)]),this.length+=e.length}writeString(e){this.maybeResize();let t=Buffer.from(e,"utf8");this.writeU32(t.length),this.writeBuffer(t)}writeFixedArray(e){this.writeBuffer(Buffer.from(e))}writeArray(e,t){this.maybeResize(),this.writeU32(e.length);for(let r of e)this.maybeResize(),t(r)}toArray(){return this.buf.subarray(0,this.length)}};Un.BinaryWriter=Ox;function fu(n,e,t){let r=t.value;t.value=function(...i){try{return r.apply(this,i)}catch(o){if(o instanceof RangeError){let s=o.code;if(["ERR_BUFFER_OUT_OF_BOUNDS","ERR_OUT_OF_RANGE"].indexOf(s)>=0)throw new Ei("Reached the end of buffer when deserializing")}throw o}}}var wo=class{constructor(e){this.buf=e,this.offset=0}readU8(){let e=this.buf.readUInt8(this.offset);return this.offset+=1,e}readU16(){let e=this.buf.readUInt16LE(this.offset);return this.offset+=2,e}readU32(){let e=this.buf.readUInt32LE(this.offset);return this.offset+=4,e}readU64(){let e=this.readBuffer(8);return new gf.default(e,"le")}readU128(){let e=this.readBuffer(16);return new gf.default(e,"le")}readU256(){let e=this.readBuffer(32);return new gf.default(e,"le")}readU512(){let e=this.readBuffer(64);return new gf.default(e,"le")}readBuffer(e){if(this.offset+e>this.buf.length)throw new Ei(`Expected buffer length ${e} isn't within bounds`);let t=this.buf.slice(this.offset,this.offset+e);return this.offset+=e,t}readString(){let e=this.readU32(),t=this.readBuffer(e);try{return Iue.decode(t)}catch(r){throw new Ei(`Error decoding UTF-8 string: ${r}`)}}readFixedArray(e){return new Uint8Array(this.readBuffer(e))}readArray(e){let t=this.readU32(),r=Array();for(let i=0;i<t;++i)r.push(e());return r}};du([fu],wo.prototype,"readU8",null);du([fu],wo.prototype,"readU16",null);du([fu],wo.prototype,"readU32",null);du([fu],wo.prototype,"readU64",null);du([fu],wo.prototype,"readU128",null);du([fu],wo.prototype,"readU256",null);du([fu],wo.prototype,"readU512",null);du([fu],wo.prototype,"readString",null);du([fu],wo.prototype,"readFixedArray",null);du([fu],wo.prototype,"readArray",null);Un.BinaryReader=wo;function SH(n){return n.charAt(0).toUpperCase()+n.slice(1)}function Ip(n,e,t,r,i){try{if(typeof r=="string")i[`write${SH(r)}`](t);else if(r instanceof Array)if(typeof r[0]=="number"){if(t.length!==r[0])throw new Ei(`Expecting byte array of length ${r[0]}, but got ${t.length} bytes`);i.writeFixedArray(t)}else if(r.length===2&&typeof r[1]=="number"){if(t.length!==r[1])throw new Ei(`Expecting byte array of length ${r[1]}, but got ${t.length} bytes`);for(let o=0;o<r[1];o++)Ip(n,null,t[o],r[0],i)}else i.writeArray(t,o=>{Ip(n,e,o,r[0],i)});else if(r.kind!==void 0)switch(r.kind){case"option":{t==null?i.writeU8(0):(i.writeU8(1),Ip(n,e,t,r.type,i));break}case"map":{i.writeU32(t.size),t.forEach((o,s)=>{Ip(n,e,s,r.key,i),Ip(n,e,o,r.value,i)});break}default:throw new Ei(`FieldType ${r} unrecognized`)}else CH(n,t,i)}catch(o){throw o instanceof Ei&&o.addToFieldPath(e),o}}function CH(n,e,t){if(typeof e.borshSerialize=="function"){e.borshSerialize(t);return}let r=n.get(e.constructor);if(!r)throw new Ei(`Class ${e.constructor.name} is missing in schema`);if(r.kind==="struct")r.fields.map(([i,o])=>{Ip(n,i,e[i],o,t)});else if(r.kind==="enum"){let i=e[r.field];for(let o=0;o<r.values.length;++o){let[s,a]=r.values[o];if(s===i){t.writeU8(o),Ip(n,s,e[s],a,t);break}}}else throw new Ei(`Unexpected schema kind: ${r.kind} for ${e.constructor.name}`)}function vue(n,e,t=Ox){let r=new t;return CH(n,e,r),r.toArray()}Un.serialize=vue;function Ap(n,e,t,r){try{if(typeof t=="string")return r[`read${SH(t)}`]();if(t instanceof Array){if(typeof t[0]=="number")return r.readFixedArray(t[0]);if(typeof t[1]=="number"){let i=[];for(let o=0;o<t[1];o++)i.push(Ap(n,null,t[0],r));return i}else return r.readArray(()=>Ap(n,e,t[0],r))}if(t.kind==="option")return r.readU8()?Ap(n,e,t.type,r):void 0;if(t.kind==="map"){let i=new Map,o=r.readU32();for(let s=0;s<o;s++){let a=Ap(n,e,t.key,r),c=Ap(n,e,t.value,r);i.set(a,c)}return i}return eD(n,t,r)}catch(i){throw i instanceof Ei&&i.addToFieldPath(e),i}}function eD(n,e,t){if(typeof e.borshDeserialize=="function")return e.borshDeserialize(t);let r=n.get(e);if(!r)throw new Ei(`Class ${e.name} is missing in schema`);if(r.kind==="struct"){let i={};for(let[o,s]of n.get(e).fields)i[o]=Ap(n,o,s,t);return new e(i)}if(r.kind==="enum"){let i=t.readU8();if(i>=r.values.length)throw new Ei(`Enum index: ${i} is out of range`);let[o,s]=r.values[i],a=Ap(n,o,s,t);return new e({[o]:a})}throw new Ei(`Unexpected schema kind: ${r.kind} for ${e.constructor.name}`)}function Sue(n,e,t,r=wo){let i=new r(t),o=eD(n,e,i);if(i.offset<t.length)throw new Ei(`Unexpected ${t.length-i.offset} bytes after deserialized data`);return o}Un.deserialize=Sue;function Cue(n,e,t,r=wo){let i=new r(t);return eD(n,e,i)}Un.deserializeUnchecked=Cue});var yK=oe((wD,bD)=>{"use strict";(function(n,e){typeof wD=="object"&&typeof bD<"u"?bD.exports=e():typeof define=="function"&&define.amd?define(e):(n=n||self,n.JSBI=e())})(wD,function(){"use strict";var n=Math.imul,e=Math.clz32;function t(j,Y){(Y==null||Y>j.length)&&(Y=j.length);for(var Q=0,v=Array(Y);Q<Y;Q++)v[Q]=j[Q];return v}function r(j){if(Array.isArray(j))return j}function i(j){if(j===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return j}function o(j,Y,Q){return Y=d(Y),S(j,m()?Reflect.construct(Y,Q||[],d(j).constructor):Y.apply(j,Q))}function s(j,Y){if(!(j instanceof Y))throw new TypeError("Cannot call a class as a function")}function a(j,Y,Q){if(m())return Reflect.construct.apply(null,arguments);var v=[null];v.push.apply(v,Y);var p=new(j.bind.apply(j,v));return Q&&R(p,Q.prototype),p}function c(j,Y){for(var Q,v=0;v<Y.length;v++)Q=Y[v],Q.enumerable=Q.enumerable||!1,Q.configurable=!0,"value"in Q&&(Q.writable=!0),Object.defineProperty(j,H(Q.key),Q)}function u(j,Y,Q){return Y&&c(j.prototype,Y),Q&&c(j,Q),Object.defineProperty(j,"prototype",{writable:!1}),j}function l(j,Y){var Q=typeof Symbol<"u"&&j[Symbol.iterator]||j["@@iterator"];if(!Q){if(Array.isArray(j)||(Q=A(j))||Y&&j&&typeof j.length=="number"){Q&&(j=Q);var v=0,p=function(){};return{s:p,n:function(){return v>=j.length?{done:!0}:{done:!1,value:j[v++]}},e:function(C){throw C},f:p}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var x,y=!0,I=!1;return{s:function(){Q=Q.call(j)},n:function(){var C=Q.next();return y=C.done,C},e:function(C){I=!0,x=C},f:function(){try{y||Q.return==null||Q.return()}finally{if(I)throw x}}}}function d(j){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(Y){return Y.__proto__||Object.getPrototypeOf(Y)},d(j)}function h(j,Y){if(typeof Y!="function"&&Y!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(Y&&Y.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),Y&&R(j,Y)}function f(j){try{return Function.toString.call(j).indexOf("[native code]")!==-1}catch{return typeof j=="function"}}function m(){try{var j=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(m=function(){return!!j})()}function w(j,Y){var Q=j==null?null:typeof Symbol<"u"&&j[Symbol.iterator]||j["@@iterator"];if(Q!=null){var v,p,x,y,I=[],C=!0,F=!1;try{if(x=(Q=Q.call(j)).next,Y===0){if(Object(Q)!==Q)return;C=!1}else for(;!(C=(v=x.call(Q)).done)&&(I.push(v.value),I.length!==Y);C=!0);}catch(N){F=!0,p=N}finally{try{if(!C&&Q.return!=null&&(y=Q.return(),Object(y)!==y))return}finally{if(F)throw p}}return I}}function b(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
3
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function S(j,Y){if(Y&&(typeof Y=="object"||typeof Y=="function"))return Y;if(Y!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return i(j)}function R(j,Y){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(Q,v){return Q.__proto__=v,Q},R(j,Y)}function G(j,Y){return r(j)||w(j,Y)||A(j,Y)||b()}function U(j,Y){if(typeof j!="object"||!j)return j;var Q=j[Symbol.toPrimitive];if(Q!==void 0){var v=Q.call(j,Y||"default");if(typeof v!="object")return v;throw new TypeError("@@toPrimitive must return a primitive value.")}return(Y==="string"?String:Number)(j)}function H(j){var Y=U(j,"string");return typeof Y=="symbol"?Y:Y+""}function M(j){"@babel/helpers - typeof";return M=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(Y){return typeof Y}:function(Y){return Y&&typeof Symbol=="function"&&Y.constructor===Symbol&&Y!==Symbol.prototype?"symbol":typeof Y},M(j)}function A(j,Y){if(j){if(typeof j=="string")return t(j,Y);var Q={}.toString.call(j).slice(8,-1);return Q==="Object"&&j.constructor&&(Q=j.constructor.name),Q==="Map"||Q==="Set"?Array.from(j):Q==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(Q)?t(j,Y):void 0}}function D(j){var Y=typeof Map=="function"?new Map:void 0;return D=function(Q){function v(){return a(Q,arguments,d(this).constructor)}if(Q===null||!f(Q))return Q;if(typeof Q!="function")throw new TypeError("Super expression must either be null or a function");if(Y!==void 0){if(Y.has(Q))return Y.get(Q);Y.set(Q,v)}return v.prototype=Object.create(Q.prototype,{constructor:{value:v,enumerable:!1,writable:!0,configurable:!0}}),R(v,Q)},D(j)}var z=(function(j){var Y=Math.abs,Q=Math.max,v=Math.floor;function p(x,y){var I;if(s(this,p),I=o(this,p,[x]),I.sign=y,Object.setPrototypeOf(I,p.prototype),x>p.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");return I}return h(p,j),u(p,[{key:"toDebugString",value:function(){var y,I=["BigInt["],C=l(this);try{for(C.s();!(y=C.n()).done;){var F=y.value;I.push((F&&(F>>>0).toString(16))+", ")}}catch(N){C.e(N)}finally{C.f()}return I.push("]"),I.join("")}},{key:"toString",value:function(){var y=0<arguments.length&&arguments[0]!==void 0?arguments[0]:10;if(2>y||36<y)throw new RangeError("toString() radix argument must be between 2 and 36");return this.length===0?"0":(y&y-1)==0?p.__toStringBasePowerOfTwo(this,y):p.__toStringGeneric(this,y,!1)}},{key:"valueOf",value:function(){throw new Error("Convert JSBI instances to native numbers using `toNumber`.")}},{key:"__copy",value:function(){for(var y=new p(this.length,this.sign),I=0;I<this.length;I++)y[I]=this[I];return y}},{key:"__trim",value:function(){for(var y=this.length,I=this[y-1];I===0;)y--,I=this[y-1],this.pop();return y===0&&(this.sign=!1),this}},{key:"__initializeDigits",value:function(){for(var y=0;y<this.length;y++)this[y]=0}},{key:"__clzmsd",value:function(){return p.__clz30(this.__digit(this.length-1))}},{key:"__inplaceMultiplyAdd",value:function(y,I,C){C>this.length&&(C=this.length);for(var F=32767&y,N=y>>>15,O=0,T=I,q=0;q<C;q++){var _=this.__digit(q),L=32767&_,g=_>>>15,K=p.__imul(L,F),E=p.__imul(L,N),V=p.__imul(g,F),J=p.__imul(g,N),B=T+K+O;O=B>>>30,B&=1073741823,B+=((32767&E)<<15)+((32767&V)<<15),O+=B>>>30,T=J+(E>>>15)+(V>>>15),this.__setDigit(q,1073741823&B)}if(O!==0||T!==0)throw new Error("implementation bug")}},{key:"__inplaceAdd",value:function(y,I,C){for(var F,N=0,O=0;O<C;O++)F=this.__halfDigit(I+O)+y.__halfDigit(O)+N,N=F>>>15,this.__setHalfDigit(I+O,32767&F);return N}},{key:"__inplaceSub",value:function(y,I,C){var F=C-1>>>1,N=0;if(1&I){I>>=1;for(var O=this.__digit(I),T=32767&O,q=0;q<F;q++){var _=y.__digit(q),L=(O>>>15)-(32767&_)-N;N=1&L>>>15,this.__setDigit(I+q,(32767&L)<<15|32767&T),O=this.__digit(I+q+1),T=(32767&O)-(_>>>15)-N,N=1&T>>>15}var g=y.__digit(q),K=(O>>>15)-(32767&g)-N;N=1&K>>>15,this.__setDigit(I+q,(32767&K)<<15|32767&T);var E=g>>>15;if(I+q+1>=this.length)throw new RangeError("out of bounds");(1&C)==0&&(O=this.__digit(I+q+1),T=(32767&O)-E-N,N=1&T>>>15,this.__setDigit(I+y.length,1073709056&O|32767&T))}else{I>>=1;for(var V=0;V<y.length-1;V++){var J=this.__digit(I+V),B=y.__digit(V),X=(32767&J)-(32767&B)-N;N=1&X>>>15;var ce=(J>>>15)-(B>>>15)-N;N=1&ce>>>15,this.__setDigit(I+V,(32767&ce)<<15|32767&X)}var ne=this.__digit(I+V),ge=y.__digit(V),He=(32767&ne)-(32767&ge)-N;N=1&He>>>15;var Le=0;(1&C)==0&&(Le=(ne>>>15)-(ge>>>15)-N,N=1&Le>>>15),this.__setDigit(I+V,(32767&Le)<<15|32767&He)}return N}},{key:"__inplaceRightShift",value:function(y){if(y!==0){for(var I,C=this.__digit(0)>>>y,F=this.length-1,N=0;N<F;N++)I=this.__digit(N+1),this.__setDigit(N,1073741823&I<<30-y|C),C=I>>>y;this.__setDigit(F,C)}}},{key:"__digit",value:function(y){return this[y]}},{key:"__unsignedDigit",value:function(y){return this[y]>>>0}},{key:"__setDigit",value:function(y,I){this[y]=0|I}},{key:"__setDigitGrow",value:function(y,I){this[y]=0|I}},{key:"__halfDigitLength",value:function(){var y=this.length;return 32767>=this.__unsignedDigit(y-1)?2*y-1:2*y}},{key:"__halfDigit",value:function(y){return 32767&this[y>>>1]>>>15*(1&y)}},{key:"__setHalfDigit",value:function(y,I){var C=y>>>1,F=this.__digit(C),N=1&y?32767&F|I<<15:1073709056&F|32767&I;this.__setDigit(C,N)}}],[{key:"BigInt",value:function(y){var I=Number.isFinite;if(typeof y=="number"){if(y===0)return p.__zero();if(p.__isOneDigitInt(y))return 0>y?p.__oneDigit(-y,!0):p.__oneDigit(y,!1);if(!I(y)||v(y)!==y)throw new RangeError("The number "+y+" cannot be converted to BigInt because it is not an integer");return p.__fromDouble(y)}if(typeof y=="string"){var C=p.__fromString(y);if(C===null)throw new SyntaxError("Cannot convert "+y+" to a BigInt");return C}if(typeof y=="boolean")return y===!0?p.__oneDigit(1,!1):p.__zero();if(M(y)==="object"){if(y.constructor===p)return y;var F=p.__toPrimitive(y);return p.BigInt(F)}throw new TypeError("Cannot convert "+y+" to a BigInt")}},{key:"toNumber",value:function(y){var I=y.length;if(I===0)return 0;if(I===1){var C=y.__unsignedDigit(0);return y.sign?-C:C}var F=y.__digit(I-1),N=p.__clz30(F),O=30*I-N;if(1024<O)return y.sign?-1/0:1/0;var T=O-1,q=F,_=I-1,L=N+3,g=L===32?0:q<<L;g>>>=12;var K=L-12,E=12<=L?0:q<<20+L,V=20+L;for(0<K&&0<_&&(_--,q=y.__digit(_),g|=q>>>30-K,E=q<<K+2,V=K+2);0<V&&0<_;)_--,q=y.__digit(_),E|=30<=V?q<<V-30:q>>>30-V,V-=30;var J=p.__decideRounding(y,V,_,q);if((J===1||J===0&&(1&E)==1)&&(E=E+1>>>0,E===0&&(g++,g>>>20!=0&&(g=0,T++,1023<T))))return y.sign?-1/0:1/0;var B=y.sign?-2147483648:0;return T=T+1023<<20,p.__kBitConversionInts[p.__kBitConversionIntHigh]=B|T|g,p.__kBitConversionInts[p.__kBitConversionIntLow]=E,p.__kBitConversionDouble[0]}},{key:"unaryMinus",value:function(y){if(y.length===0)return y;var I=y.__copy();return I.sign=!y.sign,I}},{key:"bitwiseNot",value:function(y){return y.sign?p.__absoluteSubOne(y).__trim():p.__absoluteAddOne(y,!0)}},{key:"exponentiate",value:function(y,I){if(I.sign)throw new RangeError("Exponent must be positive");if(I.length===0)return p.__oneDigit(1,!1);if(y.length===0)return y;if(y.length===1&&y.__digit(0)===1)return y.sign&&(1&I.__digit(0))==0?p.unaryMinus(y):y;if(1<I.length)throw new RangeError("BigInt too big");var C=I.__unsignedDigit(0);if(C===1)return y;if(C>=p.__kMaxLengthBits)throw new RangeError("BigInt too big");if(y.length===1&&y.__digit(0)===2){var F=1+(0|C/30),N=y.sign&&(1&C)!=0,O=new p(F,N);O.__initializeDigits();var T=1<<C%30;return O.__setDigit(F-1,T),O}var q=null,_=y;for((1&C)!=0&&(q=y),C>>=1;C!==0;C>>=1)_=p.multiply(_,_),(1&C)!=0&&(q===null?q=_:q=p.multiply(q,_));return q}},{key:"multiply",value:function(y,I){if(y.length===0)return y;if(I.length===0)return I;var C=y.length+I.length;30<=y.__clzmsd()+I.__clzmsd()&&C--;var F=new p(C,y.sign!==I.sign);F.__initializeDigits();for(var N=0;N<y.length;N++)p.__multiplyAccumulate(I,y.__digit(N),F,N);return F.__trim()}},{key:"divide",value:function(y,I){if(I.length===0)throw new RangeError("Division by zero");if(0>p.__absoluteCompare(y,I))return p.__zero();var C,F=y.sign!==I.sign,N=I.__unsignedDigit(0);if(I.length===1&&32767>=N){if(N===1)return F===y.sign?y:p.unaryMinus(y);C=p.__absoluteDivSmall(y,N,null)}else C=p.__absoluteDivLarge(y,I,!0,!1);return C.sign=F,C.__trim()}},{key:"remainder",value:function(y,I){if(I.length===0)throw new RangeError("Division by zero");if(0>p.__absoluteCompare(y,I))return y;var C=I.__unsignedDigit(0);if(I.length===1&&32767>=C){if(C===1)return p.__zero();var F=p.__absoluteModSmall(y,C);return F===0?p.__zero():p.__oneDigit(F,y.sign)}var N=p.__absoluteDivLarge(y,I,!1,!0);return N.sign=y.sign,N.__trim()}},{key:"add",value:function(y,I){var C=y.sign;return C===I.sign?p.__absoluteAdd(y,I,C):0<=p.__absoluteCompare(y,I)?p.__absoluteSub(y,I,C):p.__absoluteSub(I,y,!C)}},{key:"subtract",value:function(y,I){var C=y.sign;return C===I.sign?0<=p.__absoluteCompare(y,I)?p.__absoluteSub(y,I,C):p.__absoluteSub(I,y,!C):p.__absoluteAdd(y,I,C)}},{key:"leftShift",value:function(y,I){return I.length===0||y.length===0?y:I.sign?p.__rightShiftByAbsolute(y,I):p.__leftShiftByAbsolute(y,I)}},{key:"signedRightShift",value:function(y,I){return I.length===0||y.length===0?y:I.sign?p.__leftShiftByAbsolute(y,I):p.__rightShiftByAbsolute(y,I)}},{key:"unsignedRightShift",value:function(){throw new TypeError("BigInts have no unsigned right shift; use >> instead")}},{key:"lessThan",value:function(y,I){return 0>p.__compareToBigInt(y,I)}},{key:"lessThanOrEqual",value:function(y,I){return 0>=p.__compareToBigInt(y,I)}},{key:"greaterThan",value:function(y,I){return 0<p.__compareToBigInt(y,I)}},{key:"greaterThanOrEqual",value:function(y,I){return 0<=p.__compareToBigInt(y,I)}},{key:"equal",value:function(y,I){if(y.sign!==I.sign||y.length!==I.length)return!1;for(var C=0;C<y.length;C++)if(y.__digit(C)!==I.__digit(C))return!1;return!0}},{key:"notEqual",value:function(y,I){return!p.equal(y,I)}},{key:"bitwiseAnd",value:function(y,I){if(!y.sign&&!I.sign)return p.__absoluteAnd(y,I).__trim();if(y.sign&&I.sign){var C=Q(y.length,I.length)+1,F=p.__absoluteSubOne(y,C),N=p.__absoluteSubOne(I);return F=p.__absoluteOr(F,N,F),p.__absoluteAddOne(F,!0,F).__trim()}if(y.sign){var O=[I,y];y=O[0],I=O[1]}return p.__absoluteAndNot(y,p.__absoluteSubOne(I)).__trim()}},{key:"bitwiseXor",value:function(y,I){if(!y.sign&&!I.sign)return p.__absoluteXor(y,I).__trim();if(y.sign&&I.sign){var C=Q(y.length,I.length),F=p.__absoluteSubOne(y,C),N=p.__absoluteSubOne(I);return p.__absoluteXor(F,N,F).__trim()}var O=Q(y.length,I.length)+1;if(y.sign){var T=[I,y];y=T[0],I=T[1]}var q=p.__absoluteSubOne(I,O);return q=p.__absoluteXor(q,y,q),p.__absoluteAddOne(q,!0,q).__trim()}},{key:"bitwiseOr",value:function(y,I){var C=Q(y.length,I.length);if(!y.sign&&!I.sign)return p.__absoluteOr(y,I).__trim();if(y.sign&&I.sign){var F=p.__absoluteSubOne(y,C),N=p.__absoluteSubOne(I);return F=p.__absoluteAnd(F,N,F),p.__absoluteAddOne(F,!0,F).__trim()}if(y.sign){var O=[I,y];y=O[0],I=O[1]}var T=p.__absoluteSubOne(I,C);return T=p.__absoluteAndNot(T,y,T),p.__absoluteAddOne(T,!0,T).__trim()}},{key:"asIntN",value:function(y,I){if(I.length===0)return I;if(y=v(y),0>y)throw new RangeError("Invalid value: not (convertible to) a safe integer");if(y===0)return p.__zero();if(y>=p.__kMaxLengthBits)return I;var C=0|(y+29)/30;if(I.length<C)return I;var F=I.__unsignedDigit(C-1),N=1<<(y-1)%30;if(I.length===C&&F<N)return I;var O=(F&N)===N;if(!O)return p.__truncateToNBits(y,I);if(!I.sign)return p.__truncateAndSubFromPowerOfTwo(y,I,!0);if((F&N-1)==0){for(var T=C-2;0<=T;T--)if(I.__digit(T)!==0)return p.__truncateAndSubFromPowerOfTwo(y,I,!1);return I.length===C&&F===N?I:p.__truncateToNBits(y,I)}return p.__truncateAndSubFromPowerOfTwo(y,I,!1)}},{key:"asUintN",value:function(y,I){if(I.length===0)return I;if(y=v(y),0>y)throw new RangeError("Invalid value: not (convertible to) a safe integer");if(y===0)return p.__zero();if(I.sign){if(y>p.__kMaxLengthBits)throw new RangeError("BigInt too big");return p.__truncateAndSubFromPowerOfTwo(y,I,!1)}if(y>=p.__kMaxLengthBits)return I;var C=0|(y+29)/30;if(I.length<C)return I;var F=y%30;if(I.length==C){if(F===0)return I;var N=I.__digit(C-1);if(!(N>>>F))return I}return p.__truncateToNBits(y,I)}},{key:"ADD",value:function(y,I){if(y=p.__toPrimitive(y),I=p.__toPrimitive(I),typeof y=="string")return typeof I!="string"&&(I=I.toString()),y+I;if(typeof I=="string")return y.toString()+I;if(y=p.__toNumeric(y),I=p.__toNumeric(I),p.__isBigInt(y)&&p.__isBigInt(I))return p.add(y,I);if(typeof y=="number"&&typeof I=="number")return y+I;throw new TypeError("Cannot mix BigInt and other types, use explicit conversions")}},{key:"LT",value:function(y,I){return p.__compare(y,I,0)}},{key:"LE",value:function(y,I){return p.__compare(y,I,1)}},{key:"GT",value:function(y,I){return p.__compare(y,I,2)}},{key:"GE",value:function(y,I){return p.__compare(y,I,3)}},{key:"EQ",value:function(y,I){for(;;){if(p.__isBigInt(y))return p.__isBigInt(I)?p.equal(y,I):p.EQ(I,y);if(typeof y=="number"){if(p.__isBigInt(I))return p.__equalToNumber(I,y);if(M(I)!=="object")return y==I;I=p.__toPrimitive(I)}else if(typeof y=="string"){if(p.__isBigInt(I))return y=p.__fromString(y),y!==null&&p.equal(y,I);if(M(I)!=="object")return y==I;I=p.__toPrimitive(I)}else if(typeof y=="boolean"){if(p.__isBigInt(I))return p.__equalToNumber(I,+y);if(M(I)!=="object")return y==I;I=p.__toPrimitive(I)}else if(M(y)==="symbol"){if(p.__isBigInt(I))return!1;if(M(I)!=="object")return y==I;I=p.__toPrimitive(I)}else if(M(y)==="object"){if(M(I)==="object"&&I.constructor!==p)return y==I;y=p.__toPrimitive(y)}else return y==I}}},{key:"NE",value:function(y,I){return!p.EQ(y,I)}},{key:"DataViewGetBigInt64",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0&&arguments[2];return p.asIntN(64,p.DataViewGetBigUint64(y,I,C))}},{key:"DataViewGetBigUint64",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0&&arguments[2],F=C?[4,0]:[0,4],N=G(F,2),O=N[0],T=N[1],q=y.getUint32(I+O,C),_=y.getUint32(I+T,C),L=new p(3,!1);return L.__setDigit(0,1073741823&_),L.__setDigit(1,(268435455&q)<<2|_>>>30),L.__setDigit(2,q>>>28),L.__trim()}},{key:"DataViewSetBigInt64",value:function(y,I,C){var F=3<arguments.length&&arguments[3]!==void 0&&arguments[3];p.DataViewSetBigUint64(y,I,C,F)}},{key:"DataViewSetBigUint64",value:function(y,I,C){var F=3<arguments.length&&arguments[3]!==void 0&&arguments[3];C=p.asUintN(64,C);var N=0,O=0;if(0<C.length&&(O=C.__digit(0),1<C.length)){var T=C.__digit(1);O|=T<<30,N=T>>>2,2<C.length&&(N|=C.__digit(2)<<28)}var q=F?[4,0]:[0,4],_=G(q,2),L=_[0],g=_[1];y.setUint32(I+L,N,F),y.setUint32(I+g,O,F)}},{key:"__zero",value:function(){return new p(0,!1)}},{key:"__oneDigit",value:function(y,I){var C=new p(1,I);return C.__setDigit(0,y),C}},{key:"__decideRounding",value:function(y,I,C,F){if(0<I)return-1;var N;if(0>I)N=-I-1;else{if(C===0)return-1;C--,F=y.__digit(C),N=29}var O=1<<N;if((F&O)==0)return-1;if(O-=1,(F&O)!=0)return 1;for(;0<C;)if(C--,y.__digit(C)!==0)return 1;return 0}},{key:"__fromDouble",value:function(y){var I=0>y;p.__kBitConversionDouble[0]=y;var C,F=2047&p.__kBitConversionInts[p.__kBitConversionIntHigh]>>>20,N=F-1023,O=(0|N/30)+1,T=new p(O,I),q=1048576,_=1048575&p.__kBitConversionInts[p.__kBitConversionIntHigh]|q,L=p.__kBitConversionInts[p.__kBitConversionIntLow],g=20,K=N%30,E=0;if(K<g){var V=g-K;E=V+32,C=_>>>V,_=_<<32-V|L>>>V,L<<=32-V}else if(K===g)E=32,C=_,_=L,L=0;else{var J=K-g;E=32-J,C=_<<J|L>>>32-J,_=L<<J,L=0}T.__setDigit(O-1,C);for(var B=O-2;0<=B;B--)0<E?(E-=30,C=_>>>2,_=_<<30|L>>>2,L<<=30):C=0,T.__setDigit(B,C);return T.__trim()}},{key:"__isWhitespace",value:function(y){return 13>=y&&9<=y||(159>=y?y==32:131071>=y?y==160||y==5760:196607>=y?(y&=131071,10>=y||y==40||y==41||y==47||y==95||y==4096):y==65279)}},{key:"__fromString",value:function(y){var I=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0,C=0,F=y.length,N=0;if(N===F)return p.__zero();for(var O=y.charCodeAt(N);p.__isWhitespace(O);){if(++N===F)return p.__zero();O=y.charCodeAt(N)}if(O===43){if(++N===F)return null;O=y.charCodeAt(N),C=1}else if(O===45){if(++N===F)return null;O=y.charCodeAt(N),C=-1}if(I===0){if(I=10,O===48){if(++N===F)return p.__zero();if(O=y.charCodeAt(N),O===88||O===120){if(I=16,++N===F)return null;O=y.charCodeAt(N)}else if(O===79||O===111){if(I=8,++N===F)return null;O=y.charCodeAt(N)}else if(O===66||O===98){if(I=2,++N===F)return null;O=y.charCodeAt(N)}}}else if(I===16&&O===48){if(++N===F)return p.__zero();if(O=y.charCodeAt(N),O===88||O===120){if(++N===F)return null;O=y.charCodeAt(N)}}if(C!==0&&I!==10)return null;for(;O===48;){if(++N===F)return p.__zero();O=y.charCodeAt(N)}var T=F-N,q=p.__kMaxBitsPerChar[I],_=p.__kBitsPerCharTableMultiplier-1;if(T>1073741824/q)return null;var L=q*T+_>>>p.__kBitsPerCharTableShift,g=0|(L+29)/30,K=new p(g,!1),E=10>I?I:10,V=10<I?I-10:0;if((I&I-1)==0){q>>=p.__kBitsPerCharTableShift;var J=[],B=[],X=!1;do{for(var ce,ne=0,ge=0;;){if(ce=void 0,O-48>>>0<E)ce=O-48;else if((32|O)-97>>>0<V)ce=(32|O)-87;else{X=!0;break}if(ge+=q,ne=ne<<q|ce,++N===F){X=!0;break}if(O=y.charCodeAt(N),30<ge+q)break}J.push(ne),B.push(ge)}while(!X);p.__fillFromParts(K,J,B)}else{K.__initializeDigits();var He=!1,Le=0;do{for(var Fe,ft=0,Te=1;;){if(Fe=void 0,O-48>>>0<E)Fe=O-48;else if((32|O)-97>>>0<V)Fe=(32|O)-87;else{He=!0;break}var De=Te*I;if(1073741823<De)break;if(Te=De,ft=ft*I+Fe,Le++,++N===F){He=!0;break}O=y.charCodeAt(N)}_=30*p.__kBitsPerCharTableMultiplier-1;var tt=0|(q*Le+_>>>p.__kBitsPerCharTableShift)/30;K.__inplaceMultiplyAdd(Te,ft,tt)}while(!He)}if(N!==F){if(!p.__isWhitespace(O))return null;for(N++;N<F;N++)if(O=y.charCodeAt(N),!p.__isWhitespace(O))return null}return K.sign=C===-1,K.__trim()}},{key:"__fillFromParts",value:function(y,I,C){for(var F=0,N=0,O=0,T=I.length-1;0<=T;T--){var q=I[T],_=C[T];N|=q<<O,O+=_,O===30?(y.__setDigit(F++,N),O=0,N=0):30<O&&(y.__setDigit(F++,1073741823&N),O-=30,N=q>>>_-O)}if(N!==0){if(F>=y.length)throw new Error("implementation bug");y.__setDigit(F++,N)}for(;F<y.length;F++)y.__setDigit(F,0)}},{key:"__toStringBasePowerOfTwo",value:function(y,I){var C=y.length,F=I-1;F=(85&F>>>1)+(85&F),F=(51&F>>>2)+(51&F),F=(15&F>>>4)+(15&F);var N=F,O=I-1,T=y.__digit(C-1),q=p.__clz30(T),_=30*C-q,L=0|(_+N-1)/N;if(y.sign&&L++,268435456<L)throw new Error("string too long");for(var g=Array(L),K=L-1,E=0,V=0,J=0;J<C-1;J++){var B=y.__digit(J),X=(E|B<<V)&O;g[K--]=p.__kConversionChars[X];var ce=N-V;for(E=B>>>ce,V=30-ce;V>=N;)g[K--]=p.__kConversionChars[E&O],E>>>=N,V-=N}var ne=(E|T<<V)&O;for(g[K--]=p.__kConversionChars[ne],E=T>>>N-V;E!==0;)g[K--]=p.__kConversionChars[E&O],E>>>=N;if(y.sign&&(g[K--]="-"),K!==-1)throw new Error("implementation bug");return g.join("")}},{key:"__toStringGeneric",value:function(y,I,C){var F=y.length;if(F===0)return"";if(F===1){var N=y.__unsignedDigit(0).toString(I);return C===!1&&y.sign&&(N="-"+N),N}var O=30*F-p.__clz30(y.__digit(F-1)),T=p.__kMaxBitsPerChar[I],q=T-1,_=O*p.__kBitsPerCharTableMultiplier;_+=q-1,_=0|_/q;var L,g,K=_+1>>1,E=p.exponentiate(p.__oneDigit(I,!1),p.__oneDigit(K,!1)),V=E.__unsignedDigit(0);if(E.length===1&&32767>=V){L=new p(y.length,!1),L.__initializeDigits();for(var J,B=0,X=2*y.length-1;0<=X;X--)J=B<<15|y.__halfDigit(X),L.__setHalfDigit(X,0|J/V),B=0|J%V;g=B.toString(I)}else{var ce=p.__absoluteDivLarge(y,E,!0,!0);L=ce.quotient;var ne=ce.remainder.__trim();g=p.__toStringGeneric(ne,I,!0)}L.__trim();for(var ge=p.__toStringGeneric(L,I,!0);g.length<K;)g="0"+g;return C===!1&&y.sign&&(ge="-"+ge),ge+g}},{key:"__unequalSign",value:function(y){return y?-1:1}},{key:"__absoluteGreater",value:function(y){return y?-1:1}},{key:"__absoluteLess",value:function(y){return y?1:-1}},{key:"__compareToBigInt",value:function(y,I){var C=y.sign;if(C!==I.sign)return p.__unequalSign(C);var F=p.__absoluteCompare(y,I);return 0<F?p.__absoluteGreater(C):0>F?p.__absoluteLess(C):0}},{key:"__compareToNumber",value:function(y,I){if(p.__isOneDigitInt(I)){var C=y.sign,F=0>I;if(C!==F)return p.__unequalSign(C);if(y.length===0){if(F)throw new Error("implementation bug");return I===0?0:-1}if(1<y.length)return p.__absoluteGreater(C);var N=Y(I),O=y.__unsignedDigit(0);return O>N?p.__absoluteGreater(C):O<N?p.__absoluteLess(C):0}return p.__compareToDouble(y,I)}},{key:"__compareToDouble",value:function(y,I){if(I!==I)return I;if(I===1/0)return-1;if(I===-1/0)return 1;var C=y.sign,F=0>I;if(C!==F)return p.__unequalSign(C);if(I===0)throw new Error("implementation bug: should be handled elsewhere");if(y.length===0)return-1;p.__kBitConversionDouble[0]=I;var N=2047&p.__kBitConversionInts[p.__kBitConversionIntHigh]>>>20;if(N==2047)throw new Error("implementation bug: handled elsewhere");var O=N-1023;if(0>O)return p.__absoluteGreater(C);var T=y.length,q=y.__digit(T-1),_=p.__clz30(q),L=30*T-_,g=O+1;if(L<g)return p.__absoluteLess(C);if(L>g)return p.__absoluteGreater(C);var K=1048576,E=1048576|1048575&p.__kBitConversionInts[p.__kBitConversionIntHigh],V=p.__kBitConversionInts[p.__kBitConversionIntLow],J=20,B=29-_;if(B!==(0|(L-1)%30))throw new Error("implementation bug");var X,ce=0;if(B<J){var ne=J-B;ce=ne+32,X=E>>>ne,E=E<<32-ne|V>>>ne,V<<=32-ne}else if(B===J)ce=32,X=E,E=V,V=0;else{var ge=B-J;ce=32-ge,X=E<<ge|V>>>32-ge,E=V<<ge,V=0}if(q>>>=0,X>>>=0,q>X)return p.__absoluteGreater(C);if(q<X)return p.__absoluteLess(C);for(var He=T-2;0<=He;He--){0<ce?(ce-=30,X=E>>>2,E=E<<30|V>>>2,V<<=30):X=0;var Le=y.__unsignedDigit(He);if(Le>X)return p.__absoluteGreater(C);if(Le<X)return p.__absoluteLess(C)}if(E!==0||V!==0){if(ce===0)throw new Error("implementation bug");return p.__absoluteLess(C)}return 0}},{key:"__equalToNumber",value:function(y,I){return p.__isOneDigitInt(I)?I===0?y.length===0:y.length===1&&y.sign===0>I&&y.__unsignedDigit(0)===Y(I):p.__compareToDouble(y,I)===0}},{key:"__comparisonResultToBool",value:function(y,I){return I===0?0>y:I===1?0>=y:I===2?0<y:I===3?0<=y:void 0}},{key:"__compare",value:function(y,I,C){if(y=p.__toPrimitive(y),I=p.__toPrimitive(I),typeof y=="string"&&typeof I=="string")switch(C){case 0:return y<I;case 1:return y<=I;case 2:return y>I;case 3:return y>=I}if(p.__isBigInt(y)&&typeof I=="string")return I=p.__fromString(I),I!==null&&p.__comparisonResultToBool(p.__compareToBigInt(y,I),C);if(typeof y=="string"&&p.__isBigInt(I))return y=p.__fromString(y),y!==null&&p.__comparisonResultToBool(p.__compareToBigInt(y,I),C);if(y=p.__toNumeric(y),I=p.__toNumeric(I),p.__isBigInt(y)){if(p.__isBigInt(I))return p.__comparisonResultToBool(p.__compareToBigInt(y,I),C);if(typeof I!="number")throw new Error("implementation bug");return p.__comparisonResultToBool(p.__compareToNumber(y,I),C)}if(typeof y!="number")throw new Error("implementation bug");if(p.__isBigInt(I))return p.__comparisonResultToBool(p.__compareToNumber(I,y),2^C);if(typeof I!="number")throw new Error("implementation bug");return C===0?y<I:C===1?y<=I:C===2?y>I:C===3?y>=I:void 0}},{key:"__absoluteAdd",value:function(y,I,C){if(y.length<I.length)return p.__absoluteAdd(I,y,C);if(y.length===0)return y;if(I.length===0)return y.sign===C?y:p.unaryMinus(y);var F=y.length;(y.__clzmsd()===0||I.length===y.length&&I.__clzmsd()===0)&&F++;for(var N,O=new p(F,C),T=0,q=0;q<I.length;q++)N=y.__digit(q)+I.__digit(q)+T,T=N>>>30,O.__setDigit(q,1073741823&N);for(;q<y.length;q++){var _=y.__digit(q)+T;T=_>>>30,O.__setDigit(q,1073741823&_)}return q<O.length&&O.__setDigit(q,T),O.__trim()}},{key:"__absoluteSub",value:function(y,I,C){if(y.length===0)return y;if(I.length===0)return y.sign===C?y:p.unaryMinus(y);for(var F,N=new p(y.length,C),O=0,T=0;T<I.length;T++)F=y.__digit(T)-I.__digit(T)-O,O=1&F>>>30,N.__setDigit(T,1073741823&F);for(;T<y.length;T++){var q=y.__digit(T)-O;O=1&q>>>30,N.__setDigit(T,1073741823&q)}return N.__trim()}},{key:"__absoluteAddOne",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,F=y.length;C===null?C=new p(F,I):C.sign=I;for(var N,O=1,T=0;T<F;T++)N=y.__digit(T)+O,O=N>>>30,C.__setDigit(T,1073741823&N);return O!==0&&C.__setDigitGrow(F,1),C}},{key:"__absoluteSubOne",value:function(y,I){var C=y.length;I=I||C;for(var F,N=new p(I,!1),O=1,T=0;T<C;T++)F=y.__digit(T)-O,O=1&F>>>30,N.__setDigit(T,1073741823&F);if(O!==0)throw new Error("implementation bug");for(var q=C;q<I;q++)N.__setDigit(q,0);return N}},{key:"__absoluteAnd",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,F=y.length,N=I.length,O=N;if(F<N){O=F;var T=y,q=F;y=I,F=N,I=T,N=q}var _=O;C===null?C=new p(_,!1):_=C.length;for(var L=0;L<O;L++)C.__setDigit(L,y.__digit(L)&I.__digit(L));for(;L<_;L++)C.__setDigit(L,0);return C}},{key:"__absoluteAndNot",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,F=y.length,N=I.length,O=N;F<N&&(O=F);var T=F;C===null?C=new p(T,!1):T=C.length;for(var q=0;q<O;q++)C.__setDigit(q,y.__digit(q)&~I.__digit(q));for(;q<F;q++)C.__setDigit(q,y.__digit(q));for(;q<T;q++)C.__setDigit(q,0);return C}},{key:"__absoluteOr",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,F=y.length,N=I.length,O=N;if(F<N){O=F;var T=y,q=F;y=I,F=N,I=T,N=q}var _=F;C===null?C=new p(_,!1):_=C.length;for(var L=0;L<O;L++)C.__setDigit(L,y.__digit(L)|I.__digit(L));for(;L<F;L++)C.__setDigit(L,y.__digit(L));for(;L<_;L++)C.__setDigit(L,0);return C}},{key:"__absoluteXor",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,F=y.length,N=I.length,O=N;if(F<N){O=F;var T=y,q=F;y=I,F=N,I=T,N=q}var _=F;C===null?C=new p(_,!1):_=C.length;for(var L=0;L<O;L++)C.__setDigit(L,y.__digit(L)^I.__digit(L));for(;L<F;L++)C.__setDigit(L,y.__digit(L));for(;L<_;L++)C.__setDigit(L,0);return C}},{key:"__absoluteCompare",value:function(y,I){var C=y.length-I.length;if(C!=0)return C;for(var F=y.length-1;0<=F&&y.__digit(F)===I.__digit(F);)F--;return 0>F?0:y.__unsignedDigit(F)>I.__unsignedDigit(F)?1:-1}},{key:"__multiplyAccumulate",value:function(y,I,C,F){if(I!==0){for(var N=32767&I,O=I>>>15,T=0,q=0,_=0;_<y.length;_++,F++){var L=C.__digit(F),g=y.__digit(_),K=32767&g,E=g>>>15,V=p.__imul(K,N),J=p.__imul(K,O),B=p.__imul(E,N),X=p.__imul(E,O);L+=q+V+T,T=L>>>30,L&=1073741823,L+=((32767&J)<<15)+((32767&B)<<15),T+=L>>>30,q=X+(J>>>15)+(B>>>15),C.__setDigit(F,1073741823&L)}for(;T!==0||q!==0;F++){var ce=C.__digit(F);ce+=T+q,q=0,T=ce>>>30,C.__setDigit(F,1073741823&ce)}}}},{key:"__internalMultiplyAdd",value:function(y,I,C,F,N){for(var O=C,T=0,q=0;q<F;q++){var _=y.__digit(q),L=p.__imul(32767&_,I),g=p.__imul(_>>>15,I),K=L+((32767&g)<<15)+T+O;O=K>>>30,T=g>>>15,N.__setDigit(q,1073741823&K)}if(N.length>F)for(N.__setDigit(F++,O+T);F<N.length;)N.__setDigit(F++,0);else if(O+T!==0)throw new Error("implementation bug")}},{key:"__absoluteDivSmall",value:function(y,I){var C=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;C===null&&(C=new p(y.length,!1));for(var F=0,N=2*y.length-1;0<=N;N-=2){var O=(F<<15|y.__halfDigit(N))>>>0,T=0|O/I;F=0|O%I,O=(F<<15|y.__halfDigit(N-1))>>>0;var q=0|O/I;F=0|O%I,C.__setDigit(N>>>1,T<<15|q)}return C}},{key:"__absoluteModSmall",value:function(y,I){for(var C,F=0,N=2*y.length-1;0<=N;N--)C=(F<<15|y.__halfDigit(N))>>>0,F=0|C%I;return F}},{key:"__absoluteDivLarge",value:function(y,I,C,F){var N=I.__halfDigitLength(),O=I.length,T=y.__halfDigitLength()-N,q=null;C&&(q=new p(T+2>>>1,!1),q.__initializeDigits());var _=new p(N+2>>>1,!1);_.__initializeDigits();var L=p.__clz15(I.__halfDigit(N-1));0<L&&(I=p.__specialLeftShift(I,L,0));for(var g=p.__specialLeftShift(y,L,1),K=I.__halfDigit(N-1),E=0,V=T;0<=V;V--){var J=32767,B=g.__halfDigit(V+N);if(B!==K){var X=(B<<15|g.__halfDigit(V+N-1))>>>0;J=0|X/K;for(var ce=0|X%K,ne=I.__halfDigit(N-2),ge=g.__halfDigit(V+N-2);p.__imul(J,ne)>>>0>(ce<<16|ge)>>>0&&(J--,ce+=K,!(32767<ce)););}p.__internalMultiplyAdd(I,J,0,O,_);var He=g.__inplaceSub(_,V,N+1);He!==0&&(He=g.__inplaceAdd(I,V,N),g.__setHalfDigit(V+N,32767&g.__halfDigit(V+N)+He),J--),C&&(1&V?E=J<<15:q.__setDigit(V>>>1,E|J))}if(F)return g.__inplaceRightShift(L),C?{quotient:q,remainder:g}:g;if(C)return q;throw new Error("unreachable")}},{key:"__clz15",value:function(y){return p.__clz30(y)-15}},{key:"__specialLeftShift",value:function(y,I,C){var F=y.length,N=F+C,O=new p(N,!1);if(I===0){for(var T=0;T<F;T++)O.__setDigit(T,y.__digit(T));return 0<C&&O.__setDigit(F,0),O}for(var q,_=0,L=0;L<F;L++)q=y.__digit(L),O.__setDigit(L,1073741823&q<<I|_),_=q>>>30-I;return 0<C&&O.__setDigit(F,_),O}},{key:"__leftShiftByAbsolute",value:function(y,I){var C=p.__toShiftAmount(I);if(0>C)throw new RangeError("BigInt too big");var F=0|C/30,N=C%30,O=y.length,T=N!==0&&y.__digit(O-1)>>>30-N!=0,q=O+F+(T?1:0),_=new p(q,y.sign);if(N===0){for(var L=0;L<F;L++)_.__setDigit(L,0);for(;L<q;L++)_.__setDigit(L,y.__digit(L-F))}else{for(var g=0,K=0;K<F;K++)_.__setDigit(K,0);for(var E,V=0;V<O;V++)E=y.__digit(V),_.__setDigit(V+F,1073741823&E<<N|g),g=E>>>30-N;if(T)_.__setDigit(O+F,g);else if(g!==0)throw new Error("implementation bug")}return _.__trim()}},{key:"__rightShiftByAbsolute",value:function(y,I){var C=y.length,F=y.sign,N=p.__toShiftAmount(I);if(0>N)return p.__rightShiftByMaximum(F);var O=0|N/30,T=N%30,q=C-O;if(0>=q)return p.__rightShiftByMaximum(F);var _=!1;if(F){var L=(1<<T)-1;if((y.__digit(O)&L)!=0)_=!0;else for(var g=0;g<O;g++)if(y.__digit(g)!==0){_=!0;break}}if(_&&T===0){var K=y.__digit(C-1),E=~K==0;E&&q++}var V=new p(q,F);if(T===0){V.__setDigit(q-1,0);for(var J=O;J<C;J++)V.__setDigit(J-O,y.__digit(J))}else{for(var B,X=y.__digit(O)>>>T,ce=C-O-1,ne=0;ne<ce;ne++)B=y.__digit(ne+O+1),V.__setDigit(ne,1073741823&B<<30-T|X),X=B>>>T;V.__setDigit(ce,X)}return _&&(V=p.__absoluteAddOne(V,!0,V)),V.__trim()}},{key:"__rightShiftByMaximum",value:function(y){return y?p.__oneDigit(1,!0):p.__zero()}},{key:"__toShiftAmount",value:function(y){if(1<y.length)return-1;var I=y.__unsignedDigit(0);return I>p.__kMaxLengthBits?-1:I}},{key:"__toPrimitive",value:function(y){var I=1<arguments.length&&arguments[1]!==void 0?arguments[1]:"default";if(M(y)!=="object"||y.constructor===p)return y;if(typeof Symbol<"u"&&M(Symbol.toPrimitive)==="symbol"&&y[Symbol.toPrimitive]){var C=y[Symbol.toPrimitive](I);if(M(C)!=="object")return C;throw new TypeError("Cannot convert object to primitive value")}var F=y.valueOf;if(F){var N=F.call(y);if(M(N)!=="object")return N}var O=y.toString;if(O){var T=O.call(y);if(M(T)!=="object")return T}throw new TypeError("Cannot convert object to primitive value")}},{key:"__toNumeric",value:function(y){return p.__isBigInt(y)?y:+y}},{key:"__isBigInt",value:function(y){return M(y)==="object"&&y!==null&&y.constructor===p}},{key:"__truncateToNBits",value:function(y,I){for(var C=0|(y+29)/30,F=new p(C,I.sign),N=C-1,O=0;O<N;O++)F.__setDigit(O,I.__digit(O));var T=I.__digit(N);if(y%30!=0){var q=32-y%30;T=T<<q>>>q}return F.__setDigit(N,T),F.__trim()}},{key:"__truncateAndSubFromPowerOfTwo",value:function(y,I,C){for(var F=Math.min,N,O=0|(y+29)/30,T=new p(O,C),q=0,_=O-1,L=0,g=F(_,I.length);q<g;q++)N=0-I.__digit(q)-L,L=1&N>>>30,T.__setDigit(q,1073741823&N);for(;q<_;q++)T.__setDigit(q,0|1073741823&-L);var K,E=_<I.length?I.__digit(_):0,V=y%30;if(V===0)K=0-E-L,K&=1073741823;else{var J=32-V;E=E<<J>>>J;var B=1<<32-J;K=B-E-L,K&=B-1}return T.__setDigit(_,K),T.__trim()}},{key:"__digitPow",value:function(y,I){for(var C=1;0<I;)1&I&&(C*=y),I>>>=1,y*=y;return C}},{key:"__detectBigEndian",value:function(){return p.__kBitConversionDouble[0]=-0,p.__kBitConversionInts[0]!==0}},{key:"__isOneDigitInt",value:function(y){return(1073741823&y)===y}}])})(D(Array));return z.__kMaxLength=33554432,z.__kMaxLengthBits=z.__kMaxLength<<5,z.__kMaxBitsPerChar=[0,0,32,51,64,75,83,90,96,102,107,111,115,119,122,126,128,131,134,136,139,141,143,145,147,149,151,153,154,156,158,159,160,162,163,165,166],z.__kBitsPerCharTableShift=5,z.__kBitsPerCharTableMultiplier=1<<z.__kBitsPerCharTableShift,z.__kConversionChars=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],z.__kBitConversionBuffer=new ArrayBuffer(8),z.__kBitConversionDouble=new Float64Array(z.__kBitConversionBuffer),z.__kBitConversionInts=new Int32Array(z.__kBitConversionBuffer),z.__kBitConversionIntHigh=z.__detectBigEndian()?0:1,z.__kBitConversionIntLow=z.__detectBigEndian()?1:0,z.__clz30=e?function(j){return e(j)-2}:function(j){var Y=Math.LN2,Q=Math.log;return j===0?30:0|29-(0|Q(j>>>0)/Y)},z.__imul=n||function(j,Y){return 0|j*Y},z})});var D3=oe(($7e,$J)=>{"use strict";$J.exports=class _J{constructor(e,t=new Map,r=0){this.prefix=e,this._existing=t,this.counter=r}clone(){let{prefix:e,_existing:t,counter:r}=this;return new _J(e,new Map(t),r)}getId(e){let t=e&&this._existing.get(e);if(t)return t;let r=this.prefix+this.counter;return this.counter++,e&&this._existing.set(e,r),r}hasId(e){return this._existing.has(e)}getOldIds(){return[...this._existing.keys()]}}});var tq=oe(eq=>{"use strict";(function(n,e){"use strict";if(n.setImmediate)return;var t=1,r={},i=!1,o=n.document,s;function a(R){typeof R!="function"&&(R=new Function(""+R));for(var G=new Array(arguments.length-1),U=0;U<G.length;U++)G[U]=arguments[U+1];var H={callback:R,args:G};return r[t]=H,s(t),t++}function c(R){delete r[R]}function u(R){var G=R.callback,U=R.args;switch(U.length){case 0:G();break;case 1:G(U[0]);break;case 2:G(U[0],U[1]);break;case 3:G(U[0],U[1],U[2]);break;default:G.apply(e,U);break}}function l(R){if(i)setTimeout(l,0,R);else{var G=r[R];if(G){i=!0;try{u(G)}finally{c(R),i=!1}}}}function d(){s=function(R){process.nextTick(function(){l(R)})}}function h(){if(n.postMessage&&!n.importScripts){var R=!0,G=n.onmessage;return n.onmessage=function(){R=!1},n.postMessage("","*"),n.onmessage=G,R}}function f(){var R="setImmediate$"+Math.random()+"$",G=function(U){U.source===n&&typeof U.data=="string"&&U.data.indexOf(R)===0&&l(+U.data.slice(R.length))};n.addEventListener?n.addEventListener("message",G,!1):n.attachEvent("onmessage",G),s=function(U){n.postMessage(R+U,"*")}}function m(){var R=new MessageChannel;R.port1.onmessage=function(G){var U=G.data;l(U)},s=function(G){R.port2.postMessage(G)}}function w(){var R=o.documentElement;s=function(G){var U=o.createElement("script");U.onreadystatechange=function(){l(G),U.onreadystatechange=null,R.removeChild(U),U=null},R.appendChild(U)}}function b(){s=function(R){setTimeout(l,0,R)}}var S=Object.getPrototypeOf&&Object.getPrototypeOf(n);S=S&&S.setTimeout?S:n,{}.toString.call(n.process)==="[object process]"?d():h()?f():n.MessageChannel?m():o&&"onreadystatechange"in o.createElement("script")?w():b(),S.setImmediate=a,S.clearImmediate=c})(typeof self>"u"?typeof global>"u"?eq:global:self)});var I2=oe((n9e,nq)=>{"use strict";tq();var vT=self.crypto||self.msCrypto;nq.exports=class{constructor(e){if(!(vT&&vT.subtle))throw new Error("crypto.subtle not found.");if(e==="sha256")this.algorithm={name:"SHA-256"};else if(e==="sha1")this.algorithm={name:"SHA-1"};else throw new Error(`Unsupported algorithm "${e}".`);this._content=""}update(e){this._content+=e}async digest(){let e=new TextEncoder().encode(this._content),t=new Uint8Array(await vT.subtle.digest(this.algorithm,e)),r="";for(let i=0;i<t.length;++i)r+=t[i].toString(16).padStart(2,"0");return r}}});var ST=oe((i9e,rq)=>{"use strict";rq.exports=class{constructor(e){this.current=e.sort(),this.done=!1,this.dir=new Map;for(let t=0;t<e.length;++t)this.dir.set(e[t],!0)}hasNext(){return!this.done}next(){let{current:e,dir:t}=this,r=e.slice(),i=null,o=0,s=e.length;for(let a=0;a<s;++a){let c=e[a],u=t.get(c);(i===null||c>i)&&(u&&a>0&&c>e[a-1]||!u&&a<s-1&&c>e[a+1])&&(i=c,o=a)}if(i===null)this.done=!0;else{let a=t.get(i)?o-1:o+1;e[o]=e[a],e[a]=i;for(let c of e)c>i&&t.set(c,!t.get(c))}return r}}});var P3=oe((o9e,oq)=>{"use strict";var qle="http://www.w3.org/1999/02/22-rdf-syntax-ns#",CT=qle+"langString",LT="http://www.w3.org/2001/XMLSchema#string",Ic="NamedNode",qp="BlankNode",T3="Literal",iq="DefaultGraph",Pg={};(()=>{let n="(?:<([^:]+:[^>]*)>)",t="A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD"+"_",r=t+"0-9-\xB7\u0300-\u036F\u203F-\u2040",o="(_:(?:["+t+"0-9])(?:(?:["+r+".])*(?:["+r+"]))?)",s='"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"',a="(?:\\^\\^"+n+")",u="(?:"+s+"(?:"+a+"|"+"(?:@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*))"+")?)",l="[ \\t]+",d="[ \\t]*",h="(?:"+n+"|"+o+")"+l,f=n+l,m="(?:"+n+"|"+o+"|"+u+")"+d,w="(?:\\.|(?:(?:"+n+"|"+o+")"+d+"\\.))";Pg.eoln=/(?:\r\n)|(?:\n)|(?:\r)/g,Pg.empty=new RegExp("^"+d+"$"),Pg.quad=new RegExp("^"+d+h+f+m+w+d+"$")})();oq.exports=class B3{static parse(e){let t=[],r={},i=e.split(Pg.eoln),o=0;for(let s of i){if(o++,Pg.empty.test(s))continue;let a=s.match(Pg.quad);if(a===null)throw new Error("N-Quads parse error on line "+o+".");let c={subject:null,predicate:null,object:null,graph:null};if(a[1]!==void 0?c.subject={termType:Ic,value:a[1]}:c.subject={termType:qp,value:a[2]},c.predicate={termType:Ic,value:a[3]},a[4]!==void 0?c.object={termType:Ic,value:a[4]}:a[5]!==void 0?c.object={termType:qp,value:a[5]}:(c.object={termType:T3,value:void 0,datatype:{termType:Ic}},a[7]!==void 0?c.object.datatype.value=a[7]:a[8]!==void 0?(c.object.datatype.value=CT,c.object.language=a[8]):c.object.datatype.value=LT,c.object.value=jle(a[6])),a[9]!==void 0?c.graph={termType:Ic,value:a[9]}:a[10]!==void 0?c.graph={termType:qp,value:a[10]}:c.graph={termType:iq,value:""},!(c.graph.value in r))r[c.graph.value]=[c],t.push(c);else{let u=!0,l=r[c.graph.value];for(let d of l)if(Vle(d,c)){u=!1;break}u&&(l.push(c),t.push(c))}}return t}static serialize(e){Array.isArray(e)||(e=B3.legacyDatasetToQuads(e));let t=[];for(let r of e)t.push(B3.serializeQuad(r));return t.sort().join("")}static serializeQuadComponents(e,t,r,i){let o="";return e.termType===Ic?o+=`<${e.value}>`:o+=`${e.value}`,o+=` <${t.value}> `,r.termType===Ic?o+=`<${r.value}>`:r.termType===qp?o+=r.value:(o+=`"${zle(r.value)}"`,r.datatype.value===CT?r.language&&(o+=`@${r.language}`):r.datatype.value!==LT&&(o+=`^^<${r.datatype.value}>`)),i.termType===Ic?o+=` <${i.value}>`:i.termType===qp&&(o+=` ${i.value}`),o+=` .
|
|
4
4
|
`,o}static serializeQuad(e){return B3.serializeQuadComponents(e.subject,e.predicate,e.object,e.graph)}static legacyDatasetToQuads(e){let t=[],r={"blank node":qp,IRI:Ic,literal:T3};for(let i in e)e[i].forEach(s=>{let a={};for(let c in s){let u=s[c],l={termType:r[u.type],value:u.value};l.termType===T3&&(l.datatype={termType:Ic},"datatype"in u&&(l.datatype.value=u.datatype),"language"in u?("datatype"in u||(l.datatype.value=CT),l.language=u.language):"datatype"in u||(l.datatype.value=LT)),a[c]=l}i==="@default"?a.graph={termType:iq,value:""}:a.graph={termType:i.startsWith("_:")?qp:Ic,value:i},t.push(a)});return t}};function Vle(n,e){return!(n.subject.termType===e.subject.termType&&n.object.termType===e.object.termType)||!(n.subject.value===e.subject.value&&n.predicate.value===e.predicate.value&&n.object.value===e.object.value)?!1:n.object.termType!==T3?!0:n.object.datatype.termType===e.object.datatype.termType&&n.object.language===e.object.language&&n.object.datatype.value===e.object.datatype.value}var Qle=/["\\\n\r]/g;function zle(n){return n.replace(Qle,function(e){switch(e){case'"':return'\\"';case"\\":return"\\\\";case`
|
|
5
5
|
`:return"\\n";case"\r":return"\\r"}})}var Yle=/(?:\\([tbnrf"'\\]))|(?:\\u([0-9A-Fa-f]{4}))|(?:\\U([0-9A-Fa-f]{8}))/g;function jle(n){return n.replace(Yle,function(e,t,r,i){if(t)switch(t){case"t":return" ";case"b":return"\b";case"n":return`
|
|
6
|
-
`;case"r":return"\r";case"f":return"\f";case'"':return'"';case"'":return"'";case"\\":return"\\"}if(r)return String.fromCharCode(parseInt(r,16));if(i)throw new Error("Unsupported U escape")})}});var RT=oe((a9e,cq)=>{"use strict";var sq=D3(),Wle=I2(),Zle=ST(),aq=P3();cq.exports=class{constructor({createMessageDigest:e=()=>new Wle("sha256"),canonicalIdMap:t=new Map,maxDeepIterations:r=1/0}={}){this.name="URDNA2015",this.blankNodeInfo=new Map,this.canonicalIssuer=new sq("_:c14n",t),this.createMessageDigest=e,this.maxDeepIterations=r,this.quads=null,this.deepIterations=null}async main(e){this.deepIterations=new Map,this.quads=e;for(let c of e)this._addBlankNodeQuadInfo({quad:c,component:c.subject}),this._addBlankNodeQuadInfo({quad:c,component:c.object}),this._addBlankNodeQuadInfo({quad:c,component:c.graph});let t=new Map,r=[...this.blankNodeInfo.keys()],i=0;for(let c of r)++i%100===0&&await this._yield(),await this._hashAndTrackBlankNode({id:c,hashToBlankNodes:t});let o=[...t.keys()].sort(),s=[];for(let c of o){let u=t.get(c);if(u.length>1){s.push(u);continue}let l=u[0];this.canonicalIssuer.getId(l)}for(let c of s){let u=[];for(let l of c){if(this.canonicalIssuer.hasId(l))continue;let d=new sq("_:b");d.getId(l);let h=await this.hashNDegreeQuads(l,d);u.push(h)}u.sort(Xle);for(let l of u){let d=l.issuer.getOldIds();for(let h of d)this.canonicalIssuer.getId(h)}}let a=[];for(let c of this.quads){let u=aq.serializeQuadComponents(this._componentWithCanonicalId(c.subject),c.predicate,this._componentWithCanonicalId(c.object),this._componentWithCanonicalId(c.graph));a.push(u)}return a.sort(),a.join("")}async hashFirstDegreeQuads(e){let t=[],r=this.blankNodeInfo.get(e),i=r.quads;for(let s of i){let a={subject:null,predicate:s.predicate,object:null,graph:null};a.subject=this.modifyFirstDegreeComponent(e,s.subject,"subject"),a.object=this.modifyFirstDegreeComponent(e,s.object,"object"),a.graph=this.modifyFirstDegreeComponent(e,s.graph,"graph"),t.push(aq.serializeQuad(a))}t.sort();let o=this.createMessageDigest();for(let s of t)o.update(s);return r.hash=await o.digest(),r.hash}async hashRelatedBlankNode(e,t,r,i){let o;this.canonicalIssuer.hasId(e)?o=this.canonicalIssuer.getId(e):r.hasId(e)?o=r.getId(e):o=this.blankNodeInfo.get(e).hash;let s=this.createMessageDigest();return s.update(i),i!=="g"&&s.update(this.getRelatedPredicate(t)),s.update(o),s.digest()}async hashNDegreeQuads(e,t){let r=this.deepIterations.get(e)||0;if(r>this.maxDeepIterations)throw new Error(`Maximum deep iterations (${this.maxDeepIterations}) exceeded.`);this.deepIterations.set(e,r+1);let i=this.createMessageDigest(),o=await this.createHashToRelated(e,t),s=[...o.keys()].sort();for(let a of s){i.update(a);let c="",u,l=new Zle(o.get(a)),d=0;for(;l.hasNext();){let h=l.next();++d%3===0&&await this._yield();let f=t.clone(),m="",w=[],b=!1;for(let S of h)if(this.canonicalIssuer.hasId(S)?m+=this.canonicalIssuer.getId(S):(f.hasId(S)||w.push(S),m+=f.getId(S)),c.length!==0&&m>c){b=!0;break}if(!b){for(let S of w){let R=await this.hashNDegreeQuads(S,f);if(m+=f.getId(S),m+=`<${R.hash}>`,f=R.issuer,c.length!==0&&m>c){b=!0;break}}b||(c.length===0||m<c)&&(c=m,u=f)}}i.update(c),t=u}return{hash:await i.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return t.termType!=="BlankNode"?t:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}async createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads,o=0;for(let s of i)++o%100===0&&await this._yield(),await Promise.all([this._addRelatedBlankNodeHash({quad:s,component:s.subject,position:"s",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:s,component:s.object,position:"o",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:s,component:s.graph,position:"g",id:e,issuer:t,hashToRelated:r})]);return r}async _hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){let r=await this.hashFirstDegreeQuads(e),i=t.get(r);i?i.push(e):t.set(r,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if(t.termType!=="BlankNode")return;let r=t.value,i=this.blankNodeInfo.get(r);i?i.quads.add(e):this.blankNodeInfo.set(r,{quads:new Set([e]),hash:null})}async _addRelatedBlankNodeHash({quad:e,component:t,position:r,id:i,issuer:o,hashToRelated:s}){if(!(t.termType==="BlankNode"&&t.value!==i))return;let a=t.value,c=await this.hashRelatedBlankNode(a,e,o,r),u=s.get(c);u?u.push(a):s.set(c,[a])}_componentWithCanonicalId(e){return e.termType==="BlankNode"&&!e.value.startsWith(this.canonicalIssuer.prefix)?{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}:e}async _yield(){return new Promise(e=>setImmediate(e))}};function Xle(n,e){return n.hash<e.hash?-1:n.hash>e.hash?1:0}});var lq=oe((u9e,uq)=>{"use strict";var _le=I2(),$le=RT();uq.exports=class extends $le{constructor(){super(),this.name="URGNA2012",this.createMessageDigest=()=>new _le("sha1")}modifyFirstDegreeComponent(e,t,r){return t.termType!=="BlankNode"?t:r==="graph"?{termType:"BlankNode",value:"_:g"}:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return e.predicate.value}async createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads,o=0;for(let s of i){let a,c;if(s.subject.termType==="BlankNode"&&s.subject.value!==e)c=s.subject.value,a="p";else if(s.object.termType==="BlankNode"&&s.object.value!==e)c=s.object.value,a="r";else continue;++o%100===0&&await this._yield();let u=await this.hashRelatedBlankNode(c,s,t,a),l=r.get(u);l?l.push(c):r.set(u,[c])}return r}}});var DT=oe((d9e,hq)=>{"use strict";var dq=D3(),ede=I2(),tde=ST(),fq=P3();hq.exports=class{constructor({createMessageDigest:e=()=>new ede("sha256"),canonicalIdMap:t=new Map,maxDeepIterations:r=1/0}={}){this.name="URDNA2015",this.blankNodeInfo=new Map,this.canonicalIssuer=new dq("_:c14n",t),this.createMessageDigest=e,this.maxDeepIterations=r,this.quads=null,this.deepIterations=null}main(e){this.deepIterations=new Map,this.quads=e;for(let a of e)this._addBlankNodeQuadInfo({quad:a,component:a.subject}),this._addBlankNodeQuadInfo({quad:a,component:a.object}),this._addBlankNodeQuadInfo({quad:a,component:a.graph});let t=new Map,r=[...this.blankNodeInfo.keys()];for(let a of r)this._hashAndTrackBlankNode({id:a,hashToBlankNodes:t});let i=[...t.keys()].sort(),o=[];for(let a of i){let c=t.get(a);if(c.length>1){o.push(c);continue}let u=c[0];this.canonicalIssuer.getId(u)}for(let a of o){let c=[];for(let u of a){if(this.canonicalIssuer.hasId(u))continue;let l=new dq("_:b");l.getId(u);let d=this.hashNDegreeQuads(u,l);c.push(d)}c.sort(nde);for(let u of c){let l=u.issuer.getOldIds();for(let d of l)this.canonicalIssuer.getId(d)}}let s=[];for(let a of this.quads){let c=fq.serializeQuadComponents(this._componentWithCanonicalId({component:a.subject}),a.predicate,this._componentWithCanonicalId({component:a.object}),this._componentWithCanonicalId({component:a.graph}));s.push(c)}return s.sort(),s.join("")}hashFirstDegreeQuads(e){let t=[],r=this.blankNodeInfo.get(e),i=r.quads;for(let s of i){let a={subject:null,predicate:s.predicate,object:null,graph:null};a.subject=this.modifyFirstDegreeComponent(e,s.subject,"subject"),a.object=this.modifyFirstDegreeComponent(e,s.object,"object"),a.graph=this.modifyFirstDegreeComponent(e,s.graph,"graph"),t.push(fq.serializeQuad(a))}t.sort();let o=this.createMessageDigest();for(let s of t)o.update(s);return r.hash=o.digest(),r.hash}hashRelatedBlankNode(e,t,r,i){let o;this.canonicalIssuer.hasId(e)?o=this.canonicalIssuer.getId(e):r.hasId(e)?o=r.getId(e):o=this.blankNodeInfo.get(e).hash;let s=this.createMessageDigest();return s.update(i),i!=="g"&&s.update(this.getRelatedPredicate(t)),s.update(o),s.digest()}hashNDegreeQuads(e,t){let r=this.deepIterations.get(e)||0;if(r>this.maxDeepIterations)throw new Error(`Maximum deep iterations (${this.maxDeepIterations}) exceeded.`);this.deepIterations.set(e,r+1);let i=this.createMessageDigest(),o=this.createHashToRelated(e,t),s=[...o.keys()].sort();for(let a of s){i.update(a);let c="",u,l=new tde(o.get(a));for(;l.hasNext();){let d=l.next(),h=t.clone(),f="",m=[],w=!1;for(let b of d)if(this.canonicalIssuer.hasId(b)?f+=this.canonicalIssuer.getId(b):(h.hasId(b)||m.push(b),f+=h.getId(b)),c.length!==0&&f>c){w=!0;break}if(!w){for(let b of m){let S=this.hashNDegreeQuads(b,h);if(f+=h.getId(b),f+=`<${S.hash}>`,h=S.issuer,c.length!==0&&f>c){w=!0;break}}w||(c.length===0||f<c)&&(c=f,u=h)}}i.update(c),t=u}return{hash:i.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return t.termType!=="BlankNode"?t:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads;for(let o of i)this._addRelatedBlankNodeHash({quad:o,component:o.subject,position:"s",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:o,component:o.object,position:"o",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:o,component:o.graph,position:"g",id:e,issuer:t,hashToRelated:r});return r}_hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){let r=this.hashFirstDegreeQuads(e),i=t.get(r);i?i.push(e):t.set(r,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if(t.termType!=="BlankNode")return;let r=t.value,i=this.blankNodeInfo.get(r);i?i.quads.add(e):this.blankNodeInfo.set(r,{quads:new Set([e]),hash:null})}_addRelatedBlankNodeHash({quad:e,component:t,position:r,id:i,issuer:o,hashToRelated:s}){if(!(t.termType==="BlankNode"&&t.value!==i))return;let a=t.value,c=this.hashRelatedBlankNode(a,e,o,r),u=s.get(c);u?u.push(a):s.set(c,[a])}_componentWithCanonicalId({component:e}){return e.termType==="BlankNode"&&!e.value.startsWith(this.canonicalIssuer.prefix)?{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}:e}};function nde(n,e){return n.hash<e.hash?-1:n.hash>e.hash?1:0}});var mq=oe((h9e,pq)=>{"use strict";var rde=I2(),ide=DT();pq.exports=class extends ide{constructor(){super(),this.name="URGNA2012",this.createMessageDigest=()=>new rde("sha1")}modifyFirstDegreeComponent(e,t,r){return t.termType!=="BlankNode"?t:r==="graph"?{termType:"BlankNode",value:"_:g"}:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return e.predicate.value}createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads;for(let o of i){let s,a;if(o.subject.termType==="BlankNode"&&o.subject.value!==e)a=o.subject.value,s="p";else if(o.object.termType==="BlankNode"&&o.object.value!==e)a=o.object.value,s="r";else continue;let c=this.hashRelatedBlankNode(a,o,t,s),u=r.get(c);u?u.push(a):r.set(c,[a])}return r}}});var gq=oe(()=>{"use strict"});var wq=oe(Qp=>{"use strict";var ode=RT(),sde=lq(),ade=DT(),cde=mq(),Vp;try{Vp=gq()}catch{}function yq(n){return Array.isArray(n)?n:Qp.NQuads.legacyDatasetToQuads(n)}Qp.NQuads=P3();Qp.IdentifierIssuer=D3();Qp._rdfCanonizeNative=function(n){return n&&(Vp=n),Vp};Qp.canonize=async function(n,e){let t=yq(n,e);if(e.useNative){if(!Vp)throw new Error("rdf-canonize-native not available");if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "useNative".');return new Promise((r,i)=>Vp.canonize(t,e,(o,s)=>o?i(o):r(s)))}if(e.algorithm==="URDNA2015")return new ode(e).main(t);if(e.algorithm==="URGNA2012"){if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "URGNA2012".');return new sde(e).main(t)}throw"algorithm"in e?new Error("Invalid RDF Dataset Canonicalization algorithm: "+e.algorithm):new Error("No RDF Dataset Canonicalization algorithm specified.")};Qp._canonizeSync=function(n,e){let t=yq(n,e);if(e.useNative){if(!Vp)throw new Error("rdf-canonize-native not available");if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "useNative".');return Vp.canonizeSync(t,e)}if(e.algorithm==="URDNA2015")return new ade(e).main(t);if(e.algorithm==="URGNA2012"){if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "URGNA2012".');return new cde(e).main(t)}throw"algorithm"in e?new Error("Invalid RDF Dataset Canonicalization algorithm: "+e.algorithm):new Error("No RDF Dataset Canonicalization algorithm specified.")}});var k3=oe((y9e,bq)=>{"use strict";bq.exports=wq()});var ls=oe((w9e,Eq)=>{"use strict";var va={};Eq.exports=va;va.isArray=Array.isArray;va.isBoolean=n=>typeof n=="boolean"||Object.prototype.toString.call(n)==="[object Boolean]";va.isDouble=n=>va.isNumber(n)&&(String(n).indexOf(".")!==-1||Math.abs(n)>=1e21);va.isEmptyObject=n=>va.isObject(n)&&Object.keys(n).length===0;va.isNumber=n=>typeof n=="number"||Object.prototype.toString.call(n)==="[object Number]";va.isNumeric=n=>!isNaN(parseFloat(n))&&isFinite(n);va.isObject=n=>Object.prototype.toString.call(n)==="[object Object]";va.isString=n=>typeof n=="string"||Object.prototype.toString.call(n)==="[object String]";va.isUndefined=n=>typeof n>"u"});var Su=oe((b9e,Iq)=>{"use strict";var zp=ls(),Kl={};Iq.exports=Kl;Kl.isSubject=n=>zp.isObject(n)&&!("@value"in n||"@set"in n||"@list"in n)?Object.keys(n).length>1||!("@id"in n):!1;Kl.isSubjectReference=n=>zp.isObject(n)&&Object.keys(n).length===1&&"@id"in n;Kl.isValue=n=>zp.isObject(n)&&"@value"in n;Kl.isList=n=>zp.isObject(n)&&"@list"in n;Kl.isGraph=n=>zp.isObject(n)&&"@graph"in n&&Object.keys(n).filter(e=>e!=="@id"&&e!=="@index").length===1;Kl.isSimpleGraph=n=>Kl.isGraph(n)&&!("@id"in n);Kl.isBlankNode=n=>{if(zp.isObject(n)){if("@id"in n){let e=n["@id"];return!zp.isString(e)||e.indexOf("_:")===0}return Object.keys(n).length===0||!("@value"in n||"@set"in n||"@list"in n)}return!1}});var ds=oe((I9e,Aq)=>{"use strict";Aq.exports=class extends Error{constructor(e="An unspecified JSON-LD error occurred.",t="jsonld.Error",r={}){super(e),this.name=t,this.message=e,this.details=r}}});var fs=oe((A9e,Sq)=>{"use strict";var A2=Su(),zi=ls(),vq=k3().IdentifierIssuer,ude=ds(),lde=/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/,dde=/(?:<[^>]*?>|"[^"]*?"|[^,])+/g,fde=/\s*<([^>]*?)>\s*(?:;\s*(.*))?/,hde=/(.*?)=(?:(?:"([^"]*?)")|([^"]*?))\s*(?:(?:;\s*)|$)/g,pde=/^@[a-zA-Z]+$/,xq={headers:{accept:"application/ld+json, application/json"}},Sn={};Sq.exports=Sn;Sn.IdentifierIssuer=vq;Sn.REGEX_BCP47=lde;Sn.REGEX_KEYWORD=pde;Sn.clone=function(n){if(n&&typeof n=="object"){let e;if(zi.isArray(n)){e=[];for(let t=0;t<n.length;++t)e[t]=Sn.clone(n[t])}else if(n instanceof Map){e=new Map;for(let[t,r]of n)e.set(t,Sn.clone(r))}else if(n instanceof Set){e=new Set;for(let t of n)e.add(Sn.clone(t))}else if(zi.isObject(n)){e={};for(let t in n)e[t]=Sn.clone(n[t])}else e=n.toString();return e}return n};Sn.asArray=function(n){return Array.isArray(n)?n:[n]};Sn.buildHeaders=(n={})=>{if(Object.keys(n).some(t=>t.toLowerCase()==="accept"))throw new RangeError('Accept header may not be specified; only "'+xq.headers.accept+'" is supported.');return Object.assign({Accept:xq.headers.accept},n)};Sn.parseLinkHeader=n=>{let e={},t=n.match(dde);for(let r=0;r<t.length;++r){let i=t[r].match(fde);if(!i)continue;let o={target:i[1]},s=i[2];for(;i=hde.exec(s);)o[i[1]]=i[2]===void 0?i[3]:i[2];let a=o.rel||"";Array.isArray(e[a])?e[a].push(o):e.hasOwnProperty(a)?e[a]=[e[a],o]:e[a]=o}return e};Sn.validateTypeValue=(n,e)=>{if(!zi.isString(n)&&!(zi.isArray(n)&&n.every(t=>zi.isString(t)))){if(e&&zi.isObject(n))switch(Object.keys(n).length){case 0:return;case 1:if("@default"in n&&Sn.asArray(n["@default"]).every(t=>zi.isString(t)))return}throw new ude('Invalid JSON-LD syntax; "@type" value must a string, an array of strings, an empty object, or a default object.',"jsonld.SyntaxError",{code:"invalid type value",value:n})}};Sn.hasProperty=(n,e)=>{if(n.hasOwnProperty(e)){let t=n[e];return!zi.isArray(t)||t.length>0}return!1};Sn.hasValue=(n,e,t)=>{if(Sn.hasProperty(n,e)){let r=n[e],i=A2.isList(r);if(zi.isArray(r)||i){i&&(r=r["@list"]);for(let o=0;o<r.length;++o)if(Sn.compareValues(t,r[o]))return!0}else if(!zi.isArray(t))return Sn.compareValues(t,r)}return!1};Sn.addValue=(n,e,t,r)=>{if(r=r||{},"propertyIsArray"in r||(r.propertyIsArray=!1),"valueIsArray"in r||(r.valueIsArray=!1),"allowDuplicate"in r||(r.allowDuplicate=!0),"prependValue"in r||(r.prependValue=!1),r.valueIsArray)n[e]=t;else if(zi.isArray(t)){t.length===0&&r.propertyIsArray&&!n.hasOwnProperty(e)&&(n[e]=[]),r.prependValue&&(t=t.concat(n[e]),n[e]=[]);for(let i=0;i<t.length;++i)Sn.addValue(n,e,t[i],r)}else if(n.hasOwnProperty(e)){let i=!r.allowDuplicate&&Sn.hasValue(n,e,t);!zi.isArray(n[e])&&(!i||r.propertyIsArray)&&(n[e]=[n[e]]),i||(r.prependValue?n[e].unshift(t):n[e].push(t))}else n[e]=r.propertyIsArray?[t]:t};Sn.getValues=(n,e)=>[].concat(n[e]||[]);Sn.removeProperty=(n,e)=>{delete n[e]};Sn.removeValue=(n,e,t,r)=>{r=r||{},"propertyIsArray"in r||(r.propertyIsArray=!1);let i=Sn.getValues(n,e).filter(o=>!Sn.compareValues(o,t));i.length===0?Sn.removeProperty(n,e):i.length===1&&!r.propertyIsArray?n[e]=i[0]:n[e]=i};Sn.relabelBlankNodes=(n,e)=>{e=e||{};let t=e.issuer||new vq("_:b");return M3(t,n)};Sn.compareValues=(n,e)=>n===e||A2.isValue(n)&&A2.isValue(e)&&n["@value"]===e["@value"]&&n["@type"]===e["@type"]&&n["@language"]===e["@language"]&&n["@index"]===e["@index"]?!0:zi.isObject(n)&&"@id"in n&&zi.isObject(e)&&"@id"in e?n["@id"]===e["@id"]:!1;Sn.compareShortestLeast=(n,e)=>n.length<e.length?-1:e.length<n.length?1:n===e?0:n<e?-1:1;function M3(n,e){if(zi.isArray(e))for(let t=0;t<e.length;++t)e[t]=M3(n,e[t]);else if(A2.isList(e))e["@list"]=M3(n,e["@list"]);else if(zi.isObject(e)){A2.isBlankNode(e)&&(e["@id"]=n.getId(e["@id"]));let t=Object.keys(e).sort();for(let r=0;r<t.length;++r){let i=t[r];i!=="@id"&&(e[i]=M3(n,e[i]))}}return e}});var v2=oe((x9e,Cq)=>{"use strict";var Ac="http://www.w3.org/1999/02/22-rdf-syntax-ns#",x2="http://www.w3.org/2001/XMLSchema#";Cq.exports={LINK_HEADER_REL:"http://www.w3.org/ns/json-ld#context",LINK_HEADER_CONTEXT:"http://www.w3.org/ns/json-ld#context",RDF:Ac,RDF_LIST:Ac+"List",RDF_FIRST:Ac+"first",RDF_REST:Ac+"rest",RDF_NIL:Ac+"nil",RDF_TYPE:Ac+"type",RDF_PLAIN_LITERAL:Ac+"PlainLiteral",RDF_XML_LITERAL:Ac+"XMLLiteral",RDF_JSON_LITERAL:Ac+"JSON",RDF_OBJECT:Ac+"object",RDF_LANGSTRING:Ac+"langString",XSD:x2,XSD_BOOLEAN:x2+"boolean",XSD_DOUBLE:x2+"double",XSD_INTEGER:x2+"integer",XSD_STRING:x2+"string"}});var TT=oe((S9e,Lq)=>{"use strict";Lq.exports=class{constructor(){this._requests={}}wrapLoader(e){let t=this;return t._loader=e,function(){return t.add.apply(t,arguments)}}async add(e){let t=this._requests[e];if(t)return Promise.resolve(t);t=this._requests[e]=this._loader(e);try{return await t}finally{delete this._requests[e]}}}});var Cu=oe((C9e,Rq)=>{"use strict";var O3=ls(),Yi={};Rq.exports=Yi;Yi.parsers={simple:{keys:["href","scheme","authority","path","query","fragment"],regex:/^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/},full:{keys:["href","protocol","scheme","authority","auth","user","password","hostname","port","path","directory","file","query","fragment"],regex:/^(([a-zA-Z][a-zA-Z0-9+-.]*):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:(((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/}};Yi.parse=(n,e)=>{let t={},r=Yi.parsers[e||"full"],i=r.regex.exec(n),o=r.keys.length;for(;o--;)t[r.keys[o]]=i[o]===void 0?null:i[o];return(t.scheme==="https"&&t.port==="443"||t.scheme==="http"&&t.port==="80")&&(t.href=t.href.replace(":"+t.port,""),t.authority=t.authority.replace(":"+t.port,""),t.port=null),t.normalizedPath=Yi.removeDotSegments(t.path),t};Yi.prependBase=(n,e)=>{if(n===null||Yi.isAbsolute(e))return e;(!n||O3.isString(n))&&(n=Yi.parse(n||""));let t=Yi.parse(e),r={protocol:n.protocol||""};if(t.authority!==null)r.authority=t.authority,r.path=t.path,r.query=t.query;else if(r.authority=n.authority,t.path==="")r.path=n.path,t.query!==null?r.query=t.query:r.query=n.query;else{if(t.path.indexOf("/")===0)r.path=t.path;else{let o=n.path;o=o.substr(0,o.lastIndexOf("/")+1),(o.length>0||n.authority)&&o.substr(-1)!=="/"&&(o+="/"),o+=t.path,r.path=o}r.query=t.query}t.path!==""&&(r.path=Yi.removeDotSegments(r.path));let i=r.protocol;return r.authority!==null&&(i+="//"+r.authority),i+=r.path,r.query!==null&&(i+="?"+r.query),t.fragment!==null&&(i+="#"+t.fragment),i===""&&(i="./"),i};Yi.removeBase=(n,e)=>{if(n===null)return e;(!n||O3.isString(n))&&(n=Yi.parse(n||""));let t="";if(n.href!==""?t+=(n.protocol||"")+"//"+(n.authority||""):e.indexOf("//")&&(t+="//"),e.indexOf(t)!==0)return e;let r=Yi.parse(e.substr(t.length)),i=n.normalizedPath.split("/"),o=r.normalizedPath.split("/"),s=r.fragment||r.query?0:1;for(;i.length>0&&o.length>s&&i[0]===o[0];)i.shift(),o.shift();let a="";if(i.length>0){i.pop();for(let c=0;c<i.length;++c)a+="../"}return a+=o.join("/"),r.query!==null&&(a+="?"+r.query),r.fragment!==null&&(a+="#"+r.fragment),a===""&&(a="./"),a};Yi.removeDotSegments=n=>{if(n.length===0)return"";let e=n.split("/"),t=[];for(;e.length>0;){let r=e.shift(),i=e.length===0;if(r==="."){i&&t.push("");continue}if(r===".."){t.pop(),i&&t.push("");continue}t.push(r)}return n[0]==="/"&&t.length>0&&t[0]!==""&&t.unshift(""),t.length===1&&t[0]===""?"/":t.join("/")};var mde=/^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/;Yi.isAbsolute=n=>O3.isString(n)&&mde.test(n);Yi.isRelative=n=>O3.isString(n)});var Tq=oe((L9e,Dq)=>{"use strict";var{parseLinkHeader:gde,buildHeaders:yde}=fs(),{LINK_HEADER_CONTEXT:wde}=v2(),S2=ds(),bde=TT(),{prependBase:Ede}=Cu(),Ide=/(^|(\r\n))link:/i;Dq.exports=({secure:n,headers:e={},xhr:t}={headers:{}})=>{return e=yde(e),new bde().wrapLoader(i);async function i(o){if(o.indexOf("http:")!==0&&o.indexOf("https:")!==0)throw new S2('URL could not be dereferenced; only "http" and "https" URLs are supported.',"jsonld.InvalidUrl",{code:"loading document failed",url:o});if(n&&o.indexOf("https")!==0)throw new S2(`URL could not be dereferenced; secure mode is enabled and the URL's scheme is not "https".`,"jsonld.InvalidUrl",{code:"loading document failed",url:o});let s;try{s=await Ade(t,o,e)}catch(d){throw new S2("URL could not be dereferenced, an error occurred.","jsonld.LoadDocumentError",{code:"loading document failed",url:o,cause:d})}if(s.status>=400)throw new S2("URL could not be dereferenced: "+s.statusText,"jsonld.LoadDocumentError",{code:"loading document failed",url:o,httpStatusCode:s.status});let a={contextUrl:null,documentUrl:o,document:s.response},c=null,u=s.getResponseHeader("Content-Type"),l;if(Ide.test(s.getAllResponseHeaders())&&(l=s.getResponseHeader("Link")),l&&u!=="application/ld+json"){let d=gde(l),h=d[wde];if(Array.isArray(h))throw new S2("URL could not be dereferenced, it has more than one associated HTTP Link Header.","jsonld.InvalidUrl",{code:"multiple context link headers",url:o});h&&(a.contextUrl=h.target),c=d.alternate,c&&c.type=="application/ld+json"&&!(u||"").match(/^application\/(\w*\+)?json$/)&&(a=await i(Ede(o,c.target)))}return a}};function Ade(n,e,t){n=n||XMLHttpRequest;let r=new n;return new Promise((i,o)=>{r.onload=()=>i(r),r.onerror=s=>o(s),r.open("GET",e,!0);for(let s in t)r.setRequestHeader(s,t[s]);r.send()})}});var Pq=oe((R9e,Bq)=>{"use strict";var xde=Tq(),BT={};Bq.exports=BT;BT.setupDocumentLoaders=function(n){typeof XMLHttpRequest<"u"&&(n.documentLoaders.xhr=xde,n.useDocumentLoader("xhr"))};BT.setupGlobals=function(n){typeof globalThis.JsonLdProcessor>"u"&&Object.defineProperty(globalThis,"JsonLdProcessor",{writable:!0,enumerable:!1,configurable:!0,value:n.JsonLdProcessor})}});var Mq=oe((D9e,kq)=>{"use strict";kq.exports=function(n){n.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}});var Fq=oe((T9e,Oq)=>{"use strict";Oq.exports=gn;gn.Node=Yp;gn.create=gn;function gn(n){var e=this;if(e instanceof gn||(e=new gn),e.tail=null,e.head=null,e.length=0,n&&typeof n.forEach=="function")n.forEach(function(i){e.push(i)});else if(arguments.length>0)for(var t=0,r=arguments.length;t<r;t++)e.push(arguments[t]);return e}gn.prototype.removeNode=function(n){if(n.list!==this)throw new Error("removing node which does not belong to this list");var e=n.next,t=n.prev;return e&&(e.prev=t),t&&(t.next=e),n===this.head&&(this.head=e),n===this.tail&&(this.tail=t),n.list.length--,n.next=null,n.prev=null,n.list=null,e};gn.prototype.unshiftNode=function(n){if(n!==this.head){n.list&&n.list.removeNode(n);var e=this.head;n.list=this,n.next=e,e&&(e.prev=n),this.head=n,this.tail||(this.tail=n),this.length++}};gn.prototype.pushNode=function(n){if(n!==this.tail){n.list&&n.list.removeNode(n);var e=this.tail;n.list=this,n.prev=e,e&&(e.next=n),this.tail=n,this.head||(this.head=n),this.length++}};gn.prototype.push=function(){for(var n=0,e=arguments.length;n<e;n++)Sde(this,arguments[n]);return this.length};gn.prototype.unshift=function(){for(var n=0,e=arguments.length;n<e;n++)Cde(this,arguments[n]);return this.length};gn.prototype.pop=function(){if(this.tail){var n=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,n}};gn.prototype.shift=function(){if(this.head){var n=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,n}};gn.prototype.forEach=function(n,e){e=e||this;for(var t=this.head,r=0;t!==null;r++)n.call(e,t.value,r,this),t=t.next};gn.prototype.forEachReverse=function(n,e){e=e||this;for(var t=this.tail,r=this.length-1;t!==null;r--)n.call(e,t.value,r,this),t=t.prev};gn.prototype.get=function(n){for(var e=0,t=this.head;t!==null&&e<n;e++)t=t.next;if(e===n&&t!==null)return t.value};gn.prototype.getReverse=function(n){for(var e=0,t=this.tail;t!==null&&e<n;e++)t=t.prev;if(e===n&&t!==null)return t.value};gn.prototype.map=function(n,e){e=e||this;for(var t=new gn,r=this.head;r!==null;)t.push(n.call(e,r.value,this)),r=r.next;return t};gn.prototype.mapReverse=function(n,e){e=e||this;for(var t=new gn,r=this.tail;r!==null;)t.push(n.call(e,r.value,this)),r=r.prev;return t};gn.prototype.reduce=function(n,e){var t,r=this.head;if(arguments.length>1)t=e;else if(this.head)r=this.head.next,t=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var i=0;r!==null;i++)t=n(t,r.value,i),r=r.next;return t};gn.prototype.reduceReverse=function(n,e){var t,r=this.tail;if(arguments.length>1)t=e;else if(this.tail)r=this.tail.prev,t=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(var i=this.length-1;r!==null;i--)t=n(t,r.value,i),r=r.prev;return t};gn.prototype.toArray=function(){for(var n=new Array(this.length),e=0,t=this.head;t!==null;e++)n[e]=t.value,t=t.next;return n};gn.prototype.toArrayReverse=function(){for(var n=new Array(this.length),e=0,t=this.tail;t!==null;e++)n[e]=t.value,t=t.prev;return n};gn.prototype.slice=function(n,e){e=e||this.length,e<0&&(e+=this.length),n=n||0,n<0&&(n+=this.length);var t=new gn;if(e<n||e<0)return t;n<0&&(n=0),e>this.length&&(e=this.length);for(var r=0,i=this.head;i!==null&&r<n;r++)i=i.next;for(;i!==null&&r<e;r++,i=i.next)t.push(i.value);return t};gn.prototype.sliceReverse=function(n,e){e=e||this.length,e<0&&(e+=this.length),n=n||0,n<0&&(n+=this.length);var t=new gn;if(e<n||e<0)return t;n<0&&(n=0),e>this.length&&(e=this.length);for(var r=this.length,i=this.tail;i!==null&&r>e;r--)i=i.prev;for(;i!==null&&r>n;r--,i=i.prev)t.push(i.value);return t};gn.prototype.splice=function(n,e,...t){n>this.length&&(n=this.length-1),n<0&&(n=this.length+n);for(var r=0,i=this.head;i!==null&&r<n;r++)i=i.next;for(var o=[],r=0;i&&r<e;r++)o.push(i.value),i=this.removeNode(i);i===null&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev);for(var r=0;r<t.length;r++)i=vde(this,i,t[r]);return o};gn.prototype.reverse=function(){for(var n=this.head,e=this.tail,t=n;t!==null;t=t.prev){var r=t.prev;t.prev=t.next,t.next=r}return this.head=e,this.tail=n,this};function vde(n,e,t){var r=e===n.head?new Yp(t,null,e,n):new Yp(t,e,e.next,n);return r.next===null&&(n.tail=r),r.prev===null&&(n.head=r),n.length++,r}function Sde(n,e){n.tail=new Yp(e,n.tail,null,n),n.head||(n.head=n.tail),n.length++}function Cde(n,e){n.head=new Yp(e,null,n.head,n),n.tail||(n.tail=n.head),n.length++}function Yp(n,e,t,r){if(!(this instanceof Yp))return new Yp(n,e,t,r);this.list=r,this.value=n,e?(e.next=this,this.prev=e):this.prev=null,t?(t.prev=this,this.next=t):this.next=null}try{Mq()(gn)}catch{}});var FT=oe((B9e,Hq)=>{"use strict";var Lde=Fq(),jp=Symbol("max"),ql=Symbol("length"),kg=Symbol("lengthCalculator"),L2=Symbol("allowStale"),Wp=Symbol("maxAge"),Jl=Symbol("dispose"),Nq=Symbol("noDisposeOnSet"),ai=Symbol("lruList"),xc=Symbol("cache"),Gq=Symbol("updateAgeOnGet"),PT=()=>1,MT=class{constructor(e){if(typeof e=="number"&&(e={max:e}),e||(e={}),e.max&&(typeof e.max!="number"||e.max<0))throw new TypeError("max must be a non-negative number");let t=this[jp]=e.max||1/0,r=e.length||PT;if(this[kg]=typeof r!="function"?PT:r,this[L2]=e.stale||!1,e.maxAge&&typeof e.maxAge!="number")throw new TypeError("maxAge must be a number");this[Wp]=e.maxAge||0,this[Jl]=e.dispose,this[Nq]=e.noDisposeOnSet||!1,this[Gq]=e.updateAgeOnGet||!1,this.reset()}set max(e){if(typeof e!="number"||e<0)throw new TypeError("max must be a non-negative number");this[jp]=e||1/0,C2(this)}get max(){return this[jp]}set allowStale(e){this[L2]=!!e}get allowStale(){return this[L2]}set maxAge(e){if(typeof e!="number")throw new TypeError("maxAge must be a non-negative number");this[Wp]=e,C2(this)}get maxAge(){return this[Wp]}set lengthCalculator(e){typeof e!="function"&&(e=PT),e!==this[kg]&&(this[kg]=e,this[ql]=0,this[ai].forEach(t=>{t.length=this[kg](t.value,t.key),this[ql]+=t.length})),C2(this)}get lengthCalculator(){return this[kg]}get length(){return this[ql]}get itemCount(){return this[ai].length}rforEach(e,t){t=t||this;for(let r=this[ai].tail;r!==null;){let i=r.prev;Uq(this,e,r,t),r=i}}forEach(e,t){t=t||this;for(let r=this[ai].head;r!==null;){let i=r.next;Uq(this,e,r,t),r=i}}keys(){return this[ai].toArray().map(e=>e.key)}values(){return this[ai].toArray().map(e=>e.value)}reset(){this[Jl]&&this[ai]&&this[ai].length&&this[ai].forEach(e=>this[Jl](e.key,e.value)),this[xc]=new Map,this[ai]=new Lde,this[ql]=0}dump(){return this[ai].map(e=>F3(this,e)?!1:{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}).toArray().filter(e=>e)}dumpLru(){return this[ai]}set(e,t,r){if(r=r||this[Wp],r&&typeof r!="number")throw new TypeError("maxAge must be a number");let i=r?Date.now():0,o=this[kg](t,e);if(this[xc].has(e)){if(o>this[jp])return Mg(this,this[xc].get(e)),!1;let c=this[xc].get(e).value;return this[Jl]&&(this[Nq]||this[Jl](e,c.value)),c.now=i,c.maxAge=r,c.value=t,this[ql]+=o-c.length,c.length=o,this.get(e),C2(this),!0}let s=new OT(e,t,o,i,r);return s.length>this[jp]?(this[Jl]&&this[Jl](e,t),!1):(this[ql]+=s.length,this[ai].unshift(s),this[xc].set(e,this[ai].head),C2(this),!0)}has(e){if(!this[xc].has(e))return!1;let t=this[xc].get(e).value;return!F3(this,t)}get(e){return kT(this,e,!0)}peek(e){return kT(this,e,!1)}pop(){let e=this[ai].tail;return e?(Mg(this,e),e.value):null}del(e){Mg(this,this[xc].get(e))}load(e){this.reset();let t=Date.now();for(let r=e.length-1;r>=0;r--){let i=e[r],o=i.e||0;if(o===0)this.set(i.k,i.v);else{let s=o-t;s>0&&this.set(i.k,i.v,s)}}}prune(){this[xc].forEach((e,t)=>kT(this,t,!1))}},kT=(n,e,t)=>{let r=n[xc].get(e);if(r){let i=r.value;if(F3(n,i)){if(Mg(n,r),!n[L2])return}else t&&(n[Gq]&&(r.value.now=Date.now()),n[ai].unshiftNode(r));return i.value}},F3=(n,e)=>{if(!e||!e.maxAge&&!n[Wp])return!1;let t=Date.now()-e.now;return e.maxAge?t>e.maxAge:n[Wp]&&t>n[Wp]},C2=n=>{if(n[ql]>n[jp])for(let e=n[ai].tail;n[ql]>n[jp]&&e!==null;){let t=e.prev;Mg(n,e),e=t}},Mg=(n,e)=>{if(e){let t=e.value;n[Jl]&&n[Jl](t.key,t.value),n[ql]-=t.length,n[xc].delete(t.key),n[ai].removeNode(e)}},OT=class{constructor(e,t,r,i,o){this.key=e,this.value=t,this.length=r,this.now=i,this.maxAge=o||0}},Uq=(n,e,t,r)=>{let i=t.value;F3(n,i)&&(Mg(n,t),n[L2]||(i=void 0)),i&&e.call(r,i.value,i.key,n)};Hq.exports=MT});var Jq=oe((k9e,Kq)=>{"use strict";var Rde=FT(),Dde=10;Kq.exports=class{constructor({document:e}){this.document=e,this.cache=new Rde({max:Dde})}getProcessed(e){return this.cache.get(e)}setProcessed(e,t){this.cache.set(e,t)}}});var zq=oe((O9e,Qq)=>{"use strict";var{isArray:NT,isObject:D2,isString:N3}=ls(),{asArray:Tde}=fs(),{prependBase:UT}=Cu(),R2=ds(),qq=Jq(),Vq=10;Qq.exports=class{constructor({sharedCache:e}){this.perOpCache=new Map,this.sharedCache=e}async resolve({activeCtx:e,context:t,documentLoader:r,base:i,cycles:o=new Set}){t&&D2(t)&&t["@context"]&&(t=t["@context"]),t=Tde(t);let s=[];for(let a of t){if(N3(a)){let l=this._get(a);l||(l=await this._resolveRemoteContext({activeCtx:e,url:a,documentLoader:r,base:i,cycles:o})),NT(l)?s.push(...l):s.push(l);continue}if(a===null){s.push(new qq({document:null}));continue}D2(a)||Bde(t);let c=JSON.stringify(a),u=this._get(c);u||(u=new qq({document:a}),this._cacheResolvedContext({key:c,resolved:u,tag:"static"})),s.push(u)}return s}_get(e){let t=this.perOpCache.get(e);if(!t){let r=this.sharedCache.get(e);r&&(t=r.get("static"),t&&this.perOpCache.set(e,t))}return t}_cacheResolvedContext({key:e,resolved:t,tag:r}){if(this.perOpCache.set(e,t),r!==void 0){let i=this.sharedCache.get(e);i||(i=new Map,this.sharedCache.set(e,i)),i.set(r,t)}return t}async _resolveRemoteContext({activeCtx:e,url:t,documentLoader:r,base:i,cycles:o}){t=UT(i,t);let{context:s,remoteDoc:a}=await this._fetchContext({activeCtx:e,url:t,documentLoader:r,cycles:o});i=a.documentUrl||t,GT({context:s,base:i});let c=await this.resolve({activeCtx:e,context:s,documentLoader:r,base:i,cycles:o});return this._cacheResolvedContext({key:t,resolved:c,tag:a.tag}),c}async _fetchContext({activeCtx:e,url:t,documentLoader:r,cycles:i}){if(i.size>Vq)throw new R2("Maximum number of @context URLs exceeded.","jsonld.ContextUrlError",{code:e.processingMode==="json-ld-1.0"?"loading remote context failed":"context overflow",max:Vq});if(i.has(t))throw new R2("Cyclical @context URLs detected.","jsonld.ContextUrlError",{code:e.processingMode==="json-ld-1.0"?"recursive context inclusion":"context overflow",url:t});i.add(t);let o,s;try{s=await r(t),o=s.document||null,N3(o)&&(o=JSON.parse(o))}catch(a){throw new R2(`Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context. URL: "${t}".`,"jsonld.InvalidUrl",{code:"loading remote context failed",url:t,cause:a})}if(!D2(o))throw new R2(`Dereferencing a URL did not result in a JSON object. The response was valid JSON, but it was not a JSON object. URL: "${t}".`,"jsonld.InvalidUrl",{code:"invalid remote context",url:t});return"@context"in o?o={"@context":o["@context"]}:o={"@context":{}},s.contextUrl&&(NT(o["@context"])||(o["@context"]=[o["@context"]]),o["@context"].push(s.contextUrl)),{context:o,remoteDoc:s}}};function Bde(n){throw new R2("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:n})}function GT({context:n,base:e}){if(!n)return;let t=n["@context"];if(N3(t)){n["@context"]=UT(e,t);return}if(NT(t)){for(let r=0;r<t.length;++r){let i=t[r];if(N3(i)){t[r]=UT(e,i);continue}D2(i)&>({context:{"@context":i},base:e})}return}if(D2(t))for(let r in t)GT({context:t[r],base:e})}});var jq=oe((F9e,Yq)=>{"use strict";Yq.exports=k3().NQuads});var Og=oe((N9e,Xq)=>{"use strict";var HT=ds(),{isArray:Pde}=ls(),{asArray:Wq}=fs(),qs={};Xq.exports=qs;qs.defaultEventHandler=null;qs.setupEventHandler=({options:n={}})=>{let e=[].concat(n.safe?qs.safeEventHandler:[],n.eventHandler?Wq(n.eventHandler):[],qs.defaultEventHandler?qs.defaultEventHandler:[]);return e.length===0?null:e};qs.handleEvent=({event:n,options:e})=>{Zq({event:n,handlers:e.eventHandler})};function Zq({event:n,handlers:e}){let t=!0;for(let r=0;t&&r<e.length;++r){t=!1;let i=e[r];if(Pde(i))t=Zq({event:n,handlers:i});else if(typeof i=="function")i({event:n,next:()=>{t=!0}});else if(typeof i=="object")n.code in i?i[n.code]({event:n,next:()=>{t=!0}}):t=!0;else throw new HT("Invalid event handler.","jsonld.InvalidEventHandler",{event:n})}return t}var kde=new Set(["empty object","free-floating scalar","invalid @language value","invalid property","null @id value","null @value value","object with only @id","object with only @language","object with only @list","object with only @value","relative @id reference","relative @type reference","relative @vocab reference","reserved @id value","reserved @reverse value","reserved term","blank node predicate","relative graph reference","relative object reference","relative predicate reference","relative subject reference","rdfDirection not set"]);qs.safeEventHandler=function({event:e,next:t}){if(e.level==="warning"&&kde.has(e.code))throw new HT("Safe mode validation error.","jsonld.ValidationError",{event:e});t()};qs.logEventHandler=function({event:e,next:t}){console.log(`EVENT: ${e.message}`,{event:e}),t()};qs.logWarningEventHandler=function({event:e,next:t}){e.level==="warning"&&console.warn(`WARNING: ${e.message}`,{event:e}),t()};qs.unhandledEventHandler=function({event:e}){throw new HT("No handler for event.","jsonld.UnhandledEvent",{event:e})};qs.setDefaultEventHandler=function({eventHandler:n}={}){qs.defaultEventHandler=n?Wq(n):null}});var Of=oe((U9e,tV)=>{"use strict";var _q=fs(),ht=ds(),{isArray:$q,isObject:Mf,isString:hs,isUndefined:Mde}=ls(),{isAbsolute:Zp,isRelative:Ode,prependBase:T2}=Cu(),{handleEvent:Ng}=Og(),{REGEX_BCP47:Fde,REGEX_KEYWORD:G3,asArray:eV,compareShortestLeast:Nde}=fs(),U3=new Map,Ude=1e4,nr={};tV.exports=nr;nr.process=async({activeCtx:n,localCtx:e,options:t,propagate:r=!0,overrideProtected:i=!1,cycles:o=new Set})=>{if(Mf(e)&&"@context"in e&&$q(e["@context"])&&(e=e["@context"]),eV(e).length===0)return n;let a=[],c=[({event:h,next:f})=>{a.push(h),f()}];t.eventHandler&&c.push(t.eventHandler);let u=t;t={...t,eventHandler:c};let l=await t.contextResolver.resolve({activeCtx:n,context:e,documentLoader:t.documentLoader,base:t.base});Mf(l[0].document)&&typeof l[0].document["@propagate"]=="boolean"&&(r=l[0].document["@propagate"]);let d=n;!r&&!d.previousContext&&(d=d.clone(),d.previousContext=n);for(let h of l){let{document:f}=h;if(n=d,f===null){if(!i&&Object.keys(n.protected).length!==0)throw new ht("Tried to nullify a context with protected terms outside of a term definition.","jsonld.SyntaxError",{code:"invalid context nullification"});d=n=nr.getInitialContext(t).clone();continue}let m=h.getProcessed(n);if(m){if(u.eventHandler)for(let b of m.events)Ng({event:b,options:u});d=n=m.context;continue}if(Mf(f)&&"@context"in f&&(f=f["@context"]),!Mf(f))throw new ht("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:f});d=d.clone();let w=new Map;if("@version"in f){if(f["@version"]!==1.1)throw new ht("Unsupported JSON-LD version: "+f["@version"],"jsonld.UnsupportedVersion",{code:"invalid @version value",context:f});if(n.processingMode&&n.processingMode==="json-ld-1.0")throw new ht("@version: "+f["@version"]+" not compatible with "+n.processingMode,"jsonld.ProcessingModeConflict",{code:"processing mode conflict",context:f});d.processingMode="json-ld-1.1",d["@version"]=f["@version"],w.set("@version",!0)}if(d.processingMode=d.processingMode||n.processingMode,"@base"in f){let b=f["@base"];if(!(b===null||Zp(b)))if(Ode(b))b=T2(d["@base"],b);else throw new ht('Invalid JSON-LD syntax; the value of "@base" in a @context must be an absolute IRI, a relative IRI, or null.',"jsonld.SyntaxError",{code:"invalid base IRI",context:f});d["@base"]=b,w.set("@base",!0)}if("@vocab"in f){let b=f["@vocab"];if(b===null)delete d["@vocab"];else if(hs(b)){if(!Zp(b)&&nr.processingMode(d,1))throw new ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be an absolute IRI.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:f});{let S=Fg(d,b,{vocab:!0,base:!0},void 0,void 0,t);Zp(S)||t.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"relative @vocab reference",level:"warning",message:"Relative @vocab reference found.",details:{vocab:S}},options:t}),d["@vocab"]=S}}else throw new ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:f});w.set("@vocab",!0)}if("@language"in f){let b=f["@language"];if(b===null)delete d["@language"];else if(hs(b))b.match(Fde)||t.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:b}},options:t}),d["@language"]=b.toLowerCase();else throw new ht('Invalid JSON-LD syntax; the value of "@language" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid default language",context:f});w.set("@language",!0)}if("@direction"in f){let b=f["@direction"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @direction not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context member",context:f});if(b===null)delete d["@direction"];else{if(b!=="ltr"&&b!=="rtl")throw new ht('Invalid JSON-LD syntax; the value of "@direction" in a @context must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:f});d["@direction"]=b}w.set("@direction",!0)}if("@propagate"in f){let b=f["@propagate"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @propagate not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:f});if(typeof b!="boolean")throw new ht("Invalid JSON-LD syntax; @propagate value must be a boolean.","jsonld.SyntaxError",{code:"invalid @propagate value",context:e});w.set("@propagate",!0)}if("@import"in f){let b=f["@import"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @import not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:f});if(!hs(b))throw new ht("Invalid JSON-LD syntax; @import must be a string.","jsonld.SyntaxError",{code:"invalid @import value",context:e});let S=await t.contextResolver.resolve({activeCtx:n,context:b,documentLoader:t.documentLoader,base:t.base});if(S.length!==1)throw new ht("Invalid JSON-LD syntax; @import must reference a single context.","jsonld.SyntaxError",{code:"invalid remote context",context:e});let R=S[0].getProcessed(n);if(R)f=R;else{let G=S[0].document;if("@import"in G)throw new ht("Invalid JSON-LD syntax: imported context must not include @import.","jsonld.SyntaxError",{code:"invalid context entry",context:e});for(let U in G)f.hasOwnProperty(U)||(f[U]=G[U]);S[0].setProcessed(n,f)}w.set("@import",!0)}w.set("@protected",f["@protected"]||!1);for(let b in f)if(nr.createTermDefinition({activeCtx:d,localCtx:f,term:b,defined:w,options:t,overrideProtected:i}),Mf(f[b])&&"@context"in f[b]){let S=f[b]["@context"],R=!0;if(hs(S)){let G=T2(t.base,S);o.has(G)?R=!1:o.add(G)}if(R)try{await nr.process({activeCtx:d.clone(),localCtx:f[b]["@context"],overrideProtected:!0,options:t,cycles:o})}catch{throw new ht("Invalid JSON-LD syntax; invalid scoped context.","jsonld.SyntaxError",{code:"invalid scoped context",context:f[b]["@context"],term:b})}}h.setProcessed(n,{context:d,events:a})}return d};nr.createTermDefinition=({activeCtx:n,localCtx:e,term:t,defined:r,options:i,overrideProtected:o=!1})=>{if(r.has(t)){if(r.get(t))return;throw new ht("Cyclical context definition detected.","jsonld.CyclicalContext",{code:"cyclic IRI mapping",context:e,term:t})}r.set(t,!1);let s;if(e.hasOwnProperty(t)&&(s=e[t]),t==="@type"&&Mf(s)&&(s["@container"]||"@set")==="@set"&&nr.processingMode(n,1.1)){let f=["@container","@id","@protected"],m=Object.keys(s);if(m.length===0||m.some(w=>!f.includes(w)))throw new ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:e,term:t})}else{if(nr.isKeyword(t))throw new ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:e,term:t});if(t.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved term",level:"warning",message:'Terms beginning with "@" are reserved for future use and dropped.',details:{term:t}},options:i});return}else if(t==="")throw new ht("Invalid JSON-LD syntax; a term cannot be an empty string.","jsonld.SyntaxError",{code:"invalid term definition",context:e})}let a=n.mappings.get(t);n.mappings.has(t)&&n.mappings.delete(t);let c=!1;if((hs(s)||s===null)&&(c=!0,s={"@id":s}),!Mf(s))throw new ht("Invalid JSON-LD syntax; @context term values must be strings or objects.","jsonld.SyntaxError",{code:"invalid term definition",context:e});let u={};n.mappings.set(t,u),u.reverse=!1;let l=["@container","@id","@language","@reverse","@type"];nr.processingMode(n,1.1)&&l.push("@context","@direction","@index","@nest","@prefix","@protected");for(let f in s)if(!l.includes(f))throw new ht("Invalid JSON-LD syntax; a term definition must not contain "+f,"jsonld.SyntaxError",{code:"invalid term definition",context:e});let d=t.indexOf(":");if(u._termHasColon=d>0,"@reverse"in s){if("@id"in s)throw new ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @id.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});if("@nest"in s)throw new ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @nest.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});let f=s["@reverse"];if(!hs(f))throw new ht("Invalid JSON-LD syntax; a @context @reverse value must be a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(f.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved @reverse value",level:"warning",message:'@reverse values beginning with "@" are reserved for future use and dropped.',details:{reverse:f}},options:i}),a?n.mappings.set(t,a):n.mappings.delete(t);return}let m=Fg(n,f,{vocab:!0,base:!1},e,r,i);if(!Zp(m))throw new ht("Invalid JSON-LD syntax; a @context @reverse value must be an absolute IRI or a blank node identifier.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});u["@id"]=m,u.reverse=!0}else if("@id"in s){let f=s["@id"];if(f&&!hs(f))throw new ht("Invalid JSON-LD syntax; a @context @id value must be an array of strings or a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(f===null)u["@id"]=null;else if(!nr.isKeyword(f)&&f.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:'@id values beginning with "@" are reserved for future use and dropped.',details:{id:f}},options:i}),a?n.mappings.set(t,a):n.mappings.delete(t);return}else if(f!==t){if(f=Fg(n,f,{vocab:!0,base:!1},e,r,i),!Zp(f)&&!nr.isKeyword(f))throw new ht("Invalid JSON-LD syntax; a @context @id value must be an absolute IRI, a blank node identifier, or a keyword.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(t.match(/(?::[^:])|\//)){let m=new Map(r).set(t,!0);if(Fg(n,t,{vocab:!0,base:!1},e,m,i)!==f)throw new ht("Invalid JSON-LD syntax; term in form of IRI must expand to definition.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e})}u["@id"]=f,u._prefix=c&&!u._termHasColon&&f.match(/[:\/\?#\[\]@]$/)!==null}}if(!("@id"in u))if(u._termHasColon){let f=t.substr(0,d);if(e.hasOwnProperty(f)&&nr.createTermDefinition({activeCtx:n,localCtx:e,term:f,defined:r,options:i}),n.mappings.has(f)){let m=t.substr(d+1);u["@id"]=n.mappings.get(f)["@id"]+m}else u["@id"]=t}else if(t==="@type")u["@id"]=t;else{if(!("@vocab"in n))throw new ht("Invalid JSON-LD syntax; @context terms must define an @id.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e,term:t});u["@id"]=n["@vocab"]+t}if((s["@protected"]===!0||r.get("@protected")===!0&&s["@protected"]!==!1)&&(n.protected[t]=!0,u.protected=!0),r.set(t,!0),"@type"in s){let f=s["@type"];if(!hs(f))throw new ht("Invalid JSON-LD syntax; an @context @type value must be a string.","jsonld.SyntaxError",{code:"invalid type mapping",context:e});if(f==="@json"||f==="@none"){if(nr.processingMode(n,1))throw new ht(`Invalid JSON-LD syntax; an @context @type value must not be "${f}" in JSON-LD 1.0 mode.`,"jsonld.SyntaxError",{code:"invalid type mapping",context:e})}else if(f!=="@id"&&f!=="@vocab"){if(f=Fg(n,f,{vocab:!0,base:!1},e,r,i),!Zp(f))throw new ht("Invalid JSON-LD syntax; an @context @type value must be an absolute IRI.","jsonld.SyntaxError",{code:"invalid type mapping",context:e});if(f.indexOf("_:")===0)throw new ht("Invalid JSON-LD syntax; an @context @type value must be an IRI, not a blank node identifier.","jsonld.SyntaxError",{code:"invalid type mapping",context:e})}u["@type"]=f}if("@container"in s){let f=hs(s["@container"])?[s["@container"]]:s["@container"]||[],m=["@list","@set","@index","@language"],w=!0,b=f.includes("@set");if(nr.processingMode(n,1.1)){if(m.push("@graph","@id","@type"),f.includes("@list")){if(f.length!==1)throw new ht("Invalid JSON-LD syntax; @context @container with @list must have no other values","jsonld.SyntaxError",{code:"invalid container mapping",context:e})}else if(f.includes("@graph")){if(f.some(S=>S!=="@graph"&&S!=="@id"&&S!=="@index"&&S!=="@set"))throw new ht("Invalid JSON-LD syntax; @context @container with @graph must have no other values other than @id, @index, and @set","jsonld.SyntaxError",{code:"invalid container mapping",context:e})}else w&=f.length<=(b?2:1);if(f.includes("@type")&&(u["@type"]=u["@type"]||"@id",!["@id","@vocab"].includes(u["@type"])))throw new ht("Invalid JSON-LD syntax; container: @type requires @type to be @id or @vocab.","jsonld.SyntaxError",{code:"invalid type mapping",context:e})}else w&=!$q(s["@container"]),w&=f.length<=1;if(w&=f.every(S=>m.includes(S)),w&=!(b&&f.includes("@list")),!w)throw new ht("Invalid JSON-LD syntax; @context @container value must be one of the following: "+m.join(", "),"jsonld.SyntaxError",{code:"invalid container mapping",context:e});if(u.reverse&&!f.every(S=>["@index","@set"].includes(S)))throw new ht("Invalid JSON-LD syntax; @context @container value for a @reverse type definition must be @index or @set.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});u["@container"]=f}if("@index"in s){if(!("@container"in s)||!u["@container"].includes("@index"))throw new ht(`Invalid JSON-LD syntax; @index without @index in @container: "${s["@index"]}" on term "${t}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:e});if(!hs(s["@index"])||s["@index"].indexOf("@")===0)throw new ht(`Invalid JSON-LD syntax; @index must expand to an IRI: "${s["@index"]}" on term "${t}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:e});u["@index"]=s["@index"]}if("@context"in s&&(u["@context"]=s["@context"]),"@language"in s&&!("@type"in s)){let f=s["@language"];if(f!==null&&!hs(f))throw new ht("Invalid JSON-LD syntax; @context @language value must be a string or null.","jsonld.SyntaxError",{code:"invalid language mapping",context:e});f!==null&&(f=f.toLowerCase()),u["@language"]=f}if("@prefix"in s){if(t.match(/:|\//))throw new ht("Invalid JSON-LD syntax; @context @prefix used on a compact IRI term","jsonld.SyntaxError",{code:"invalid term definition",context:e});if(nr.isKeyword(u["@id"]))throw new ht("Invalid JSON-LD syntax; keywords may not be used as prefixes","jsonld.SyntaxError",{code:"invalid term definition",context:e});if(typeof s["@prefix"]=="boolean")u._prefix=s["@prefix"]===!0;else throw new ht("Invalid JSON-LD syntax; @context value for @prefix must be boolean","jsonld.SyntaxError",{code:"invalid @prefix value",context:e})}if("@direction"in s){let f=s["@direction"];if(f!==null&&f!=="ltr"&&f!=="rtl")throw new ht('Invalid JSON-LD syntax; @direction value must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:e});u["@direction"]=f}if("@nest"in s){let f=s["@nest"];if(!hs(f)||f!=="@nest"&&f.indexOf("@")===0)throw new ht("Invalid JSON-LD syntax; @context @nest value must be a string which is not a keyword other than @nest.","jsonld.SyntaxError",{code:"invalid @nest value",context:e});u["@nest"]=f}let h=u["@id"];if(h==="@context"||h==="@preserve")throw new ht("Invalid JSON-LD syntax; @context and @preserve cannot be aliased.","jsonld.SyntaxError",{code:"invalid keyword alias",context:e});if(a&&a.protected&&!o&&(n.protected[t]=!0,u.protected=!0,!KT(a,u)))throw new ht("Invalid JSON-LD syntax; tried to redefine a protected term.","jsonld.SyntaxError",{code:"protected term redefinition",context:e,term:t})};nr.expandIri=(n,e,t,r)=>Fg(n,e,t,void 0,void 0,r);function Fg(n,e,t,r,i,o){if(e===null||!hs(e)||nr.isKeyword(e))return e;if(e.match(G3))return null;if(r&&r.hasOwnProperty(e)&&i.get(e)!==!0&&nr.createTermDefinition({activeCtx:n,localCtx:r,term:e,defined:i,options:o}),t=t||{},t.vocab){let a=n.mappings.get(e);if(a===null)return null;if(Mf(a)&&"@id"in a)return a["@id"]}let s=e.indexOf(":");if(s>0){let a=e.substr(0,s),c=e.substr(s+1);if(a==="_"||c.indexOf("//")===0)return e;r&&r.hasOwnProperty(a)&&nr.createTermDefinition({activeCtx:n,localCtx:r,term:a,defined:i,options:o});let u=n.mappings.get(a);if(u&&u._prefix)return u["@id"]+c;if(Zp(e))return e}if(t.vocab&&"@vocab"in n)e=n["@vocab"]+e;else if(t.base){let a,c;"@base"in n?n["@base"]?(c=T2(o.base,n["@base"]),a=T2(c,e)):(c=n["@base"],a=e):(c=o.base,a=T2(o.base,e)),e=a}return e}nr.getInitialContext=n=>{let e=JSON.stringify({processingMode:n.processingMode}),t=U3.get(e);if(t)return t;let r={processingMode:n.processingMode,mappings:new Map,inverse:null,getInverse:i,clone:a,revertToPreviousContext:c,protected:{}};return U3.size===Ude&&U3.clear(),U3.set(e,r),r;function i(){let u=this;if(u.inverse)return u.inverse;let l=u.inverse={},d=u.fastCurieMap={},h={},f=(u["@language"]||"@none").toLowerCase(),m=u["@direction"],w=u.mappings,b=[...w.keys()].sort(Nde);for(let S of b){let R=w.get(S);if(R===null)continue;let G=R["@container"]||"@none";if(G=[].concat(G).sort().join(""),R["@id"]===null)continue;let U=eV(R["@id"]);for(let H of U){let M=l[H],A=nr.isKeyword(H);if(M)!A&&!R._termHasColon&&h[H].push(S);else if(l[H]=M={},!A&&!R._termHasColon){h[H]=[S];let D={iri:H,terms:h[H]};H[0]in d?d[H[0]].push(D):d[H[0]]=[D]}if(M[G]||(M[G]={"@language":{},"@type":{},"@any":{}}),M=M[G],s(S,M["@any"],"@none"),R.reverse)s(S,M["@type"],"@reverse");else if(R["@type"]==="@none")s(S,M["@any"],"@none"),s(S,M["@language"],"@none"),s(S,M["@type"],"@none");else if("@type"in R)s(S,M["@type"],R["@type"]);else if("@language"in R&&"@direction"in R){let D=R["@language"],z=R["@direction"];D&&z?s(S,M["@language"],`${D}_${z}`.toLowerCase()):D?s(S,M["@language"],D.toLowerCase()):z?s(S,M["@language"],`_${z}`):s(S,M["@language"],"@null")}else"@language"in R?s(S,M["@language"],(R["@language"]||"@null").toLowerCase()):"@direction"in R?R["@direction"]?s(S,M["@language"],`_${R["@direction"]}`):s(S,M["@language"],"@none"):m?(s(S,M["@language"],`_${m}`),s(S,M["@language"],"@none"),s(S,M["@type"],"@none")):(s(S,M["@language"],f),s(S,M["@language"],"@none"),s(S,M["@type"],"@none"))}}for(let S in d)o(d,S,1);return l}function o(u,l,d){let h=u[l],f=u[l]={},m,w;for(let b of h)m=b.iri,d>=m.length?w="":w=m[d],w in f?f[w].push(b):f[w]=[b];for(let b in f)b!==""&&o(f,b,d+1)}function s(u,l,d){l.hasOwnProperty(d)||(l[d]=u)}function a(){let u={};return u.mappings=_q.clone(this.mappings),u.clone=this.clone,u.inverse=null,u.getInverse=this.getInverse,u.protected=_q.clone(this.protected),this.previousContext&&(u.previousContext=this.previousContext.clone()),u.revertToPreviousContext=this.revertToPreviousContext,"@base"in this&&(u["@base"]=this["@base"]),"@language"in this&&(u["@language"]=this["@language"]),"@vocab"in this&&(u["@vocab"]=this["@vocab"]),u}function c(){return this.previousContext?this.previousContext.clone():this}};nr.getContextValue=(n,e,t)=>{if(e===null)return t==="@context"?void 0:null;if(n.mappings.has(e)){let r=n.mappings.get(e);if(Mde(t))return r;if(r.hasOwnProperty(t))return r[t]}if(t==="@language"&&t in n||t==="@direction"&&t in n)return n[t];if(t!=="@context")return null};nr.processingMode=(n,e)=>e.toString()>="1.1"?!n.processingMode||n.processingMode>="json-ld-"+e.toString():n.processingMode==="json-ld-1.0";nr.isKeyword=n=>{if(!hs(n)||n[0]!=="@")return!1;switch(n){case"@base":case"@container":case"@context":case"@default":case"@direction":case"@embed":case"@explicit":case"@graph":case"@id":case"@included":case"@index":case"@json":case"@language":case"@list":case"@nest":case"@none":case"@omitDefault":case"@prefix":case"@preserve":case"@protected":case"@requireAll":case"@reverse":case"@set":case"@type":case"@value":case"@version":case"@vocab":return!0}return!1};function KT(n,e){if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return n===e;let t=Array.isArray(n);if(t!==Array.isArray(e))return!1;if(t){if(n.length!==e.length)return!1;for(let o=0;o<n.length;++o)if(!KT(n[o],e[o]))return!1;return!0}let r=Object.keys(n),i=Object.keys(e);if(r.length!==i.length)return!1;for(let o in n){let s=n[o],a=e[o];if(o==="@container"&&Array.isArray(s)&&Array.isArray(a)&&(s=s.slice().sort(),a=a.slice().sort()),!KT(s,a))return!1}return!0}});var aV=oe((G9e,sV)=>{"use strict";var ur=ds(),{isArray:La,isObject:Sa,isEmptyObject:VT,isString:ji,isUndefined:J3}=ls(),{isList:JT,isValue:QT,isGraph:Gde,isSubject:Hde}=Su(),{expandIri:Gr,getContextValue:Qs,isKeyword:zT,process:B2,processingMode:H3}=Of(),{isAbsolute:K3}=Cu(),{REGEX_BCP47:nV,REGEX_KEYWORD:Kde,addValue:Vs,asArray:vc,getValues:Jde,validateTypeValue:qde}=fs(),{handleEvent:Ca}=Og(),Ff={};sV.exports=Ff;Ff.expand=async({activeCtx:n,activeProperty:e=null,element:t,options:r={},insideList:i=!1,insideIndex:o=!1,typeScopedContext:s=null})=>{if(t==null)return null;if(e==="@default"&&(r=Object.assign({},r,{isFrame:!1})),!La(t)&&!Sa(t))return!i&&(e===null||Gr(n,e,{vocab:!0},r)==="@graph")?(r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"free-floating scalar",level:"warning",message:"Dropping free-floating scalar not in a list.",details:{value:t}},options:r}),null):oV({activeCtx:n,activeProperty:e,value:t,options:r});if(La(t)){let m=[],w=Qs(n,e,"@container")||[];i=i||w.includes("@list");for(let b=0;b<t.length;++b){let S=await Ff.expand({activeCtx:n,activeProperty:e,element:t[b],options:r,insideIndex:o,typeScopedContext:s});i&&La(S)&&(S={"@list":S}),S!==null&&(La(S)?m=m.concat(S):m.push(S))}return m}let a=Gr(n,e,{vocab:!0},r),c=Qs(n,e,"@context");s=s||(n.previousContext?n:null);let u=Object.keys(t).sort(),l=!o;if(l&&s&&u.length<=2&&!u.includes("@context"))for(let m of u){let w=Gr(s,m,{vocab:!0},r);if(w==="@value"){l=!1,n=s;break}if(w==="@id"&&u.length===1){l=!1;break}}l&&(n=n.revertToPreviousContext()),J3(c)||(n=await B2({activeCtx:n,localCtx:c,propagate:!0,overrideProtected:!0,options:r})),"@context"in t&&(n=await B2({activeCtx:n,localCtx:t["@context"],options:r})),s=n;let d=null;for(let m of u)if(Gr(n,m,{vocab:!0},r)==="@type"){d=d||m;let b=t[m],S=Array.isArray(b)?b.length>1?b.slice().sort():b:[b];for(let R of S){let G=Qs(s,R,"@context");J3(G)||(n=await B2({activeCtx:n,localCtx:G,options:r,propagate:!1}))}}let h={};await iV({activeCtx:n,activeProperty:e,expandedActiveProperty:a,element:t,expandedParent:h,options:r,insideList:i,typeKey:d,typeScopedContext:s}),u=Object.keys(h);let f=u.length;if("@value"in h){if("@type"in h&&("@language"in h||"@direction"in h))throw new ur('Invalid JSON-LD syntax; an element containing "@value" may not contain both "@type" and either "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:h});let m=f-1;if("@type"in h&&(m-=1),"@index"in h&&(m-=1),"@language"in h&&(m-=1),"@direction"in h&&(m-=1),m!==0)throw new ur('Invalid JSON-LD syntax; an element containing "@value" may only have an "@index" property and either "@type" or either or both "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:h});let w=h["@value"]===null?[]:vc(h["@value"]),b=Jde(h,"@type");if(!(H3(n,1.1)&&b.includes("@json")&&b.length===1))if(w.length===0)r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"null @value value",level:"warning",message:"Dropping null @value value.",details:{value:h}},options:r}),h=null;else{if(!w.every(S=>ji(S)||VT(S))&&"@language"in h)throw new ur("Invalid JSON-LD syntax; only strings may be language-tagged.","jsonld.SyntaxError",{code:"invalid language-tagged value",element:h});if(!b.every(S=>K3(S)&&!(ji(S)&&S.indexOf("_:")===0)||VT(S)))throw new ur('Invalid JSON-LD syntax; an element containing "@value" and "@type" must have an absolute IRI for the value of "@type".',"jsonld.SyntaxError",{code:"invalid typed value",element:h})}}else if("@type"in h&&!La(h["@type"]))h["@type"]=[h["@type"]];else if("@set"in h||"@list"in h){if(f>1&&!(f===2&&"@index"in h))throw new ur('Invalid JSON-LD syntax; if an element has the property "@set" or "@list", then it can have at most one other property that is "@index".',"jsonld.SyntaxError",{code:"invalid set or list object",element:h});"@set"in h&&(h=h["@set"],u=Object.keys(h),f=u.length)}else f===1&&"@language"in h&&(r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"object with only @language",level:"warning",message:"Dropping object with only @language.",details:{value:h}},options:r}),h=null);return Sa(h)&&!r.keepFreeFloatingNodes&&!i&&(e===null||a==="@graph"||(Qs(n,e,"@container")||[]).includes("@graph"))&&(h=rV({value:h,count:f,options:r})),h};function rV({value:n,count:e,options:t}){if(e===0||"@value"in n||"@list"in n||e===1&&"@id"in n){if(t.eventHandler){let r,i;e===0?(r="empty object",i="Dropping empty object."):"@value"in n?(r="object with only @value",i="Dropping object with only @value."):"@list"in n?(r="object with only @list",i="Dropping object with only @list."):e===1&&"@id"in n&&(r="object with only @id",i="Dropping object with only @id."),Ca({event:{type:["JsonLdEvent"],code:r,level:"warning",message:i,details:{value:n}},options:t})}return null}return n}async function iV({activeCtx:n,activeProperty:e,expandedActiveProperty:t,element:r,expandedParent:i,options:o={},insideList:s,typeKey:a,typeScopedContext:c}){let u=Object.keys(r).sort(),l=[],d,h=r[a]&&Gr(n,La(r[a])?r[a][0]:r[a],{vocab:!0},{...o,typeExpansion:!0})==="@json";for(let f of u){let m=r[f],w;if(f==="@context")continue;let b=Gr(n,f,{vocab:!0},o);if(b===null||!(K3(b)||zT(b))){o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid property",level:"warning",message:"Dropping property that did not expand into an absolute IRI or keyword.",details:{property:f,expandedProperty:b}},options:o});continue}if(zT(b)){if(t==="@reverse")throw new ur("Invalid JSON-LD syntax; a keyword cannot be used as a @reverse property.","jsonld.SyntaxError",{code:"invalid reverse property map",value:m});if(b in i&&b!=="@included"&&b!=="@type")throw new ur("Invalid JSON-LD syntax; colliding keywords detected.","jsonld.SyntaxError",{code:"colliding keywords",keyword:b})}if(b==="@id"){if(!ji(m)){if(!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@id" value must a string.',"jsonld.SyntaxError",{code:"invalid @id value",value:m});if(Sa(m)){if(!VT(m))throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}else if(La(m)){if(!m.every(U=>ji(U)))throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}else throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}Vs(i,"@id",vc(m).map(U=>{if(ji(U)){let H=Gr(n,U,{base:!0},o);return o.eventHandler&&(H===null?Ca(U===null?{event:{type:["JsonLdEvent"],code:"null @id value",level:"warning",message:"Null @id found.",details:{id:U}},options:o}:{event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:U}},options:o}):K3(H)||Ca({event:{type:["JsonLdEvent"],code:"relative @id reference",level:"warning",message:"Relative @id reference found.",details:{id:U,expandedId:H}},options:o})),H}return U}),{propertyIsArray:o.isFrame});continue}if(b==="@type"){Sa(m)&&(m=Object.fromEntries(Object.entries(m).map(([U,H])=>[Gr(c,U,{vocab:!0}),vc(H).map(M=>Gr(c,M,{base:!0,vocab:!0},{...o,typeExpansion:!0}))]))),qde(m,o.isFrame),Vs(i,"@type",vc(m).map(U=>{if(ji(U)){let H=Gr(c,U,{base:!0,vocab:!0},{...o,typeExpansion:!0});return H!=="@json"&&!K3(H)&&o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"relative @type reference",level:"warning",message:"Relative @type reference found.",details:{type:U}},options:o}),H}return U}),{propertyIsArray:!!o.isFrame});continue}if(b==="@included"&&H3(n,1.1)){let U=vc(await Ff.expand({activeCtx:n,activeProperty:e,element:m,options:o}));if(!U.every(H=>Hde(H)))throw new ur("Invalid JSON-LD syntax; values of @included must expand to node objects.","jsonld.SyntaxError",{code:"invalid @included value",value:m});Vs(i,"@included",U,{propertyIsArray:!0});continue}if(b==="@graph"&&!(Sa(m)||La(m)))throw new ur('Invalid JSON-LD syntax; "@graph" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid @graph value",value:m});if(b==="@value"){d=m,h&&H3(n,1.1)?i["@value"]=m:Vs(i,"@value",m,{propertyIsArray:o.isFrame});continue}if(b==="@language"){if(m===null)continue;if(!ji(m)&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@language" value must be a string.',"jsonld.SyntaxError",{code:"invalid language-tagged string",value:m});m=vc(m).map(U=>ji(U)?U.toLowerCase():U);for(let U of m)ji(U)&&!U.match(nV)&&o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:U}},options:o});Vs(i,"@language",m,{propertyIsArray:o.isFrame});continue}if(b==="@direction"){if(!ji(m)&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@direction" value must be a string.',"jsonld.SyntaxError",{code:"invalid base direction",value:m});m=vc(m);for(let U of m)if(ji(U)&&U!=="ltr"&&U!=="rtl")throw new ur('Invalid JSON-LD syntax; "@direction" must be "ltr" or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",value:m});Vs(i,"@direction",m,{propertyIsArray:o.isFrame});continue}if(b==="@index"){if(!ji(m))throw new ur('Invalid JSON-LD syntax; "@index" value must be a string.',"jsonld.SyntaxError",{code:"invalid @index value",value:m});Vs(i,"@index",m);continue}if(b==="@reverse"){if(!Sa(m))throw new ur('Invalid JSON-LD syntax; "@reverse" value must be an object.',"jsonld.SyntaxError",{code:"invalid @reverse value",value:m});if(w=await Ff.expand({activeCtx:n,activeProperty:"@reverse",element:m,options:o}),"@reverse"in w)for(let H in w["@reverse"])Vs(i,H,w["@reverse"][H],{propertyIsArray:!0});let U=i["@reverse"]||null;for(let H in w){if(H==="@reverse")continue;U===null&&(U=i["@reverse"]={}),Vs(U,H,[],{propertyIsArray:!0});let M=w[H];for(let A=0;A<M.length;++A){let D=M[A];if(QT(D)||JT(D))throw new ur('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:w});Vs(U,H,D,{propertyIsArray:!0})}}continue}if(b==="@nest"){l.push(f);continue}let S=n,R=Qs(n,f,"@context");J3(R)||(S=await B2({activeCtx:n,localCtx:R,propagate:!0,overrideProtected:!0,options:o}));let G=Qs(n,f,"@container")||[];if(G.includes("@language")&&Sa(m)){let U=Qs(S,f,"@direction");w=Vde(S,m,U,o)}else if(G.includes("@index")&&Sa(m)){let U=G.includes("@graph"),H=Qs(S,f,"@index")||"@index",M=H!=="@index"&&Gr(n,H,{vocab:!0},o);w=await qT({activeCtx:S,options:o,activeProperty:f,value:m,asGraph:U,indexKey:H,propertyIndex:M})}else if(G.includes("@id")&&Sa(m)){let U=G.includes("@graph");w=await qT({activeCtx:S,options:o,activeProperty:f,value:m,asGraph:U,indexKey:"@id"})}else if(G.includes("@type")&&Sa(m))w=await qT({activeCtx:S.revertToPreviousContext(),options:o,activeProperty:f,value:m,asGraph:!1,indexKey:"@type"});else{let U=b==="@list";if(U||b==="@set"){let H=e;U&&t==="@graph"&&(H=null),w=await Ff.expand({activeCtx:S,activeProperty:H,element:m,options:o,insideList:U})}else Qs(n,f,"@type")==="@json"?w={"@type":"@json","@value":m}:w=await Ff.expand({activeCtx:S,activeProperty:f,element:m,options:o,insideList:!1})}if(!(w===null&&b!=="@value")){if(b!=="@list"&&!JT(w)&&G.includes("@list")&&(w={"@list":vc(w)}),G.includes("@graph")&&!G.some(U=>U==="@id"||U==="@index")){if(w=vc(w),o.isFrame||(w=w.filter(U=>{let H=Object.keys(U).length;return rV({value:U,count:H,options:o})!==null})),w.length===0)continue;w=w.map(U=>({"@graph":vc(U)}))}if(S.mappings.has(f)&&S.mappings.get(f).reverse){let U=i["@reverse"]=i["@reverse"]||{};w=vc(w);for(let H=0;H<w.length;++H){let M=w[H];if(QT(M)||JT(M))throw new ur('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:w});Vs(U,b,M,{propertyIsArray:!0})}continue}Vs(i,b,w,{propertyIsArray:!0})}}if("@value"in i&&!(i["@type"]==="@json"&&H3(n,1.1))){if((Sa(d)||La(d))&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@value" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid value object value",value:d})}for(let f of l){let m=La(r[f])?r[f]:[r[f]];for(let w of m){if(!Sa(w)||Object.keys(w).some(b=>Gr(n,b,{vocab:!0},o)==="@value"))throw new ur("Invalid JSON-LD syntax; nested value must be a node object.","jsonld.SyntaxError",{code:"invalid @nest value",value:w});await iV({activeCtx:n,activeProperty:e,expandedActiveProperty:t,element:w,expandedParent:i,options:o,insideList:s,typeScopedContext:c,typeKey:a})}}}function oV({activeCtx:n,activeProperty:e,value:t,options:r}){if(t==null)return null;let i=Gr(n,e,{vocab:!0},r);if(i==="@id")return Gr(n,t,{base:!0},r);if(i==="@type")return Gr(n,t,{vocab:!0,base:!0},{...r,typeExpansion:!0});let o=Qs(n,e,"@type");if((o==="@id"||i==="@graph")&&ji(t)){let a=Gr(n,t,{base:!0},r);return a===null&&t.match(Kde)&&r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:e}},options:r}),{"@id":a}}if(o==="@vocab"&&ji(t))return{"@id":Gr(n,t,{vocab:!0,base:!0},r)};if(zT(i))return t;let s={};if(o&&!["@id","@vocab","@none"].includes(o))s["@type"]=o;else if(ji(t)){let a=Qs(n,e,"@language");a!==null&&(s["@language"]=a);let c=Qs(n,e,"@direction");c!==null&&(s["@direction"]=c)}return["boolean","number","string"].includes(typeof t)||(t=t.toString()),s["@value"]=t,s}function Vde(n,e,t,r){let i=[],o=Object.keys(e).sort();for(let s of o){let a=Gr(n,s,{vocab:!0},r),c=e[s];La(c)||(c=[c]);for(let u of c){if(u===null)continue;if(!ji(u))throw new ur("Invalid JSON-LD syntax; language map values must be strings.","jsonld.SyntaxError",{code:"invalid language map value",languageMap:e});let l={"@value":u};a!=="@none"&&(s.match(nV)||r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:s}},options:r}),l["@language"]=s.toLowerCase()),t&&(l["@direction"]=t),i.push(l)}}return i}async function qT({activeCtx:n,options:e,activeProperty:t,value:r,asGraph:i,indexKey:o,propertyIndex:s}){let a=[],c=Object.keys(r).sort(),u=o==="@type";for(let l of c){if(u){let f=Qs(n,l,"@context");J3(f)||(n=await B2({activeCtx:n,localCtx:f,propagate:!1,options:e}))}let d=r[l];La(d)||(d=[d]),d=await Ff.expand({activeCtx:n,activeProperty:t,element:d,options:e,insideList:!1,insideIndex:!0});let h;s?l==="@none"?h="@none":h=oV({activeCtx:n,activeProperty:o,value:l,options:e}):h=Gr(n,l,{vocab:!0},e),o==="@id"?l=Gr(n,l,{base:!0},e):u&&(l=h);for(let f of d){if(i&&!Gde(f)&&(f={"@graph":[f]}),o==="@type")h==="@none"||(f["@type"]?f["@type"]=[l].concat(f["@type"]):f["@type"]=[l]);else{if(QT(f)&&!["@language","@type","@index"].includes(o))throw new ur(`Invalid JSON-LD syntax; Attempt to add illegal key to value object: "${o}".`,"jsonld.SyntaxError",{code:"invalid value object",value:f});s?h!=="@none"&&Vs(f,s,h,{propertyIsArray:!0,prependValue:!0}):h!=="@none"&&!(o in f)&&(f[o]=l)}a.push(f)}}return a}});var P2=oe((H9e,uV)=>{"use strict";var{isKeyword:cV}=Of(),Lu=Su(),YT=ls(),Ru=fs(),Qde=ds(),Go={};uV.exports=Go;Go.createMergedNodeMap=(n,e)=>{e=e||{};let t=e.issuer||new Ru.IdentifierIssuer("_:b"),r={"@default":{}};return Go.createNodeMap(n,r,"@default",t),Go.mergeNodeMaps(r)};Go.createNodeMap=(n,e,t,r,i,o)=>{if(YT.isArray(n)){for(let u of n)Go.createNodeMap(u,e,t,r,void 0,o);return}if(!YT.isObject(n)){o&&o.push(n);return}if(Lu.isValue(n)){if("@type"in n){let u=n["@type"];u.indexOf("_:")===0&&(n["@type"]=u=r.getId(u))}o&&o.push(n);return}else if(o&&Lu.isList(n)){let u=[];Go.createNodeMap(n["@list"],e,t,r,i,u),o.push({"@list":u});return}if("@type"in n){let u=n["@type"];for(let l of u)l.indexOf("_:")===0&&r.getId(l)}YT.isUndefined(i)&&(i=Lu.isBlankNode(n)?r.getId(n["@id"]):n["@id"]),o&&o.push({"@id":i});let s=e[t],a=s[i]=s[i]||{};a["@id"]=i;let c=Object.keys(n).sort();for(let u of c){if(u==="@id")continue;if(u==="@reverse"){let d={"@id":i},h=n["@reverse"];for(let f in h){let m=h[f];for(let w of m){let b=w["@id"];Lu.isBlankNode(w)&&(b=r.getId(b)),Go.createNodeMap(w,e,t,r,b),Ru.addValue(s[b],f,d,{propertyIsArray:!0,allowDuplicate:!1})}}continue}if(u==="@graph"){i in e||(e[i]={}),Go.createNodeMap(n[u],e,i,r);continue}if(u==="@included"){Go.createNodeMap(n[u],e,t,r);continue}if(u!=="@type"&&cV(u)){if(u==="@index"&&u in a&&(n[u]!==a[u]||n[u]["@id"]!==a[u]["@id"]))throw new Qde("Invalid JSON-LD syntax; conflicting @index property detected.","jsonld.SyntaxError",{code:"conflicting indexes",subject:a});a[u]=n[u];continue}let l=n[u];if(u.indexOf("_:")===0&&(u=r.getId(u)),l.length===0){Ru.addValue(a,u,[],{propertyIsArray:!0});continue}for(let d of l)if(u==="@type"&&(d=d.indexOf("_:")===0?r.getId(d):d),Lu.isSubject(d)||Lu.isSubjectReference(d)){if("@id"in d&&!d["@id"])continue;let h=Lu.isBlankNode(d)?r.getId(d["@id"]):d["@id"];Ru.addValue(a,u,{"@id":h},{propertyIsArray:!0,allowDuplicate:!1}),Go.createNodeMap(d,e,t,r,h)}else if(Lu.isValue(d))Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1});else if(Lu.isList(d)){let h=[];Go.createNodeMap(d["@list"],e,t,r,i,h),d={"@list":h},Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1})}else Go.createNodeMap(d,e,t,r,i),Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1})}};Go.mergeNodeMapGraphs=n=>{let e={};for(let t of Object.keys(n).sort())for(let r of Object.keys(n[t]).sort()){let i=n[t][r];r in e||(e[r]={"@id":r});let o=e[r];for(let s of Object.keys(i).sort())if(cV(s)&&s!=="@type")o[s]=Ru.clone(i[s]);else for(let a of i[s])Ru.addValue(o,s,Ru.clone(a),{propertyIsArray:!0,allowDuplicate:!1})}return e};Go.mergeNodeMaps=n=>{let e=n["@default"],t=Object.keys(n).sort();for(let r of t){if(r==="@default")continue;let i=n[r],o=e[r];o?"@graph"in o||(o["@graph"]=[]):e[r]=o={"@id":r,"@graph":[]};let s=o["@graph"];for(let a of Object.keys(i).sort()){let c=i[a];Lu.isSubjectReference(c)||s.push(c)}}return e}});var fV=oe((K9e,dV)=>{"use strict";var{isSubjectReference:zde}=Su(),{createMergedNodeMap:Yde}=P2(),lV={};dV.exports=lV;lV.flatten=n=>{let e=Yde(n),t=[],r=Object.keys(e).sort();for(let i=0;i<r.length;++i){let o=e[r[i]];zde(o)||t.push(o)}return t}});var IV=oe((J9e,EV)=>{"use strict";var $T=ds(),jT=Su(),k2=ls(),{REGEX_BCP47:hV,addValue:pV}=fs(),{handleEvent:mV}=Og(),{RDF_LIST:jde,RDF_FIRST:WT,RDF_REST:ZT,RDF_NIL:XT,RDF_TYPE:Wde,RDF_JSON_LITERAL:Zde,XSD_BOOLEAN:gV,XSD_DOUBLE:yV,XSD_INTEGER:wV,XSD_STRING:_T}=v2(),bV={};EV.exports=bV;bV.fromRDF=async(n,e)=>{let{useRdfType:t=!1,useNativeTypes:r=!1,rdfDirection:i=null}=e,o={},s={"@default":o},a={};if(i){if(i==="compound-literal")throw new $T("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if(i!=="i18n-datatype")throw new $T("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i})}for(let l of n){let d=l.graph.termType==="DefaultGraph"?"@default":l.graph.value;d in s||(s[d]={}),d!=="@default"&&!(d in o)&&(o[d]={"@id":d});let h=s[d],f=l.subject.value,m=l.predicate.value,w=l.object;f in h||(h[f]={"@id":f});let b=h[f],S=w.termType.endsWith("Node");if(S&&!(w.value in h)&&(h[w.value]={"@id":w.value}),m===Wde&&!t&&S){pV(b,"@type",w.value,{propertyIsArray:!0});continue}let R=Xde(w,r,i,e);if(pV(b,m,R,{propertyIsArray:!0}),S)if(w.value===XT){let G=h[w.value];"usages"in G||(G.usages=[]),G.usages.push({node:b,property:m,value:R})}else w.value in a?a[w.value]=!1:a[w.value]={node:b,property:m,value:R}}for(let l in s){let d=s[l];if(!(XT in d))continue;let h=d[XT];if(h.usages){for(let f of h.usages){let m=f.node,w=f.property,b=f.value,S=[],R=[],G=Object.keys(m).length;for(;w===ZT&&k2.isObject(a[m["@id"]])&&k2.isArray(m[WT])&&m[WT].length===1&&k2.isArray(m[ZT])&&m[ZT].length===1&&(G===3||G===4&&k2.isArray(m["@type"])&&m["@type"].length===1&&m["@type"][0]===jde)&&(S.push(m[WT][0]),R.push(m["@id"]),f=a[m["@id"]],m=f.node,w=f.property,b=f.value,G=Object.keys(m).length,!!jT.isBlankNode(m)););delete b["@id"],b["@list"]=S.reverse();for(let U of R)delete d[U]}delete h.usages}}let c=[],u=Object.keys(o).sort();for(let l of u){let d=o[l];if(l in s){let h=d["@graph"]=[],f=s[l],m=Object.keys(f).sort();for(let w of m){let b=f[w];jT.isSubjectReference(b)||h.push(b)}}jT.isSubjectReference(d)||c.push(d)}return c};function Xde(n,e,t,r){if(n.termType.endsWith("Node"))return{"@id":n.value};let i={"@value":n.value};if(n.language)n.language.match(hV)||r.eventHandler&&mV({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:n.language}},options:r}),i["@language"]=n.language;else{let o=n.datatype.value;if(o||(o=_T),o===Zde){o="@json";try{i["@value"]=JSON.parse(i["@value"])}catch(s){throw new $T("JSON literal could not be parsed.","jsonld.InvalidJsonLiteral",{code:"invalid JSON literal",value:i["@value"],cause:s})}}if(e){if(o===gV)i["@value"]==="true"?i["@value"]=!0:i["@value"]==="false"&&(i["@value"]=!1);else if(k2.isNumeric(i["@value"]))if(o===wV){let s=parseInt(i["@value"],10);s.toFixed(0)===i["@value"]&&(i["@value"]=s)}else o===yV&&(i["@value"]=parseFloat(i["@value"]));[gV,wV,yV,_T].includes(o)||(i["@type"]=o)}else if(t==="i18n-datatype"&&o.startsWith("https://www.w3.org/ns/i18n#")){let[,s,a]=o.split(/[#_]/);s.length>0&&(i["@language"]=s,s.match(hV)||r.eventHandler&&mV({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:s}},options:r})),i["@direction"]=a}else o!==_T&&(i["@type"]=o)}return i}});var xV=oe((q9e,AV)=>{"use strict";AV.exports=function n(e){return e===null||typeof e!="object"||e.toJSON!=null?JSON.stringify(e):Array.isArray(e)?"["+e.reduce((t,r,i)=>{let o=i===0?"":",",s=r===void 0||typeof r=="symbol"?null:r;return t+o+n(s)},"")+"]":"{"+Object.keys(e).sort().reduce((t,r,i)=>{if(e[r]===void 0||typeof e[r]=="symbol")return t;let o=t.length===0?"":",";return t+o+n(r)+":"+n(e[r])},"")+"}"}});var DV=oe((V9e,RV)=>{"use strict";var{createNodeMap:_de}=P2(),{isKeyword:$de}=Of(),vV=Su(),efe=xV(),SV=ds(),M2=ls(),tfe=fs(),{handleEvent:Xp}=Og(),{RDF_FIRST:nfe,RDF_REST:rfe,RDF_NIL:ife,RDF_TYPE:ofe,RDF_JSON_LITERAL:sfe,RDF_LANGSTRING:afe,XSD_BOOLEAN:cfe,XSD_DOUBLE:CV,XSD_INTEGER:ufe,XSD_STRING:lfe}=v2(),{isAbsolute:q3}=Cu(),LV={};RV.exports=LV;LV.toRDF=(n,e)=>{let t=new tfe.IdentifierIssuer("_:b"),r={"@default":{}};_de(n,r,"@default",t);let i=[],o=Object.keys(r).sort();for(let s of o){let a;if(s==="@default")a={termType:"DefaultGraph",value:""};else if(q3(s))s.startsWith("_:")?a={termType:"BlankNode"}:a={termType:"NamedNode"},a.value=s;else{e.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative graph reference",level:"warning",message:"Relative graph reference found.",details:{graph:s}},options:e});continue}dfe(i,r[s],a,t,e)}return i};function dfe(n,e,t,r,i){let o=Object.keys(e).sort();for(let s of o){let a=e[s],c=Object.keys(a).sort();for(let u of c){let l=a[u];if(u==="@type")u=ofe;else if($de(u))continue;for(let d of l){let h={termType:s.startsWith("_:")?"BlankNode":"NamedNode",value:s};if(!q3(s)){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative subject reference",level:"warning",message:"Relative subject reference found.",details:{subject:s}},options:i});continue}let f={termType:u.startsWith("_:")?"BlankNode":"NamedNode",value:u};if(!q3(u)){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative predicate reference",level:"warning",message:"Relative predicate reference found.",details:{predicate:u}},options:i});continue}if(f.termType==="BlankNode"&&!i.produceGeneralizedRdf){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"blank node predicate",level:"warning",message:"Dropping blank node predicate.",details:{property:r.getOldIds().find(w=>r.getId(w)===u)}},options:i});continue}let m=e6(d,r,n,t,i.rdfDirection,i);m&&n.push({subject:h,predicate:f,object:m,graph:t})}}}}function ffe(n,e,t,r,i,o){let s={termType:"NamedNode",value:nfe},a={termType:"NamedNode",value:rfe},c={termType:"NamedNode",value:ife},u=n.pop(),l=u?{termType:"BlankNode",value:e.getId()}:c,d=l;for(let h of n){let f=e6(h,e,t,r,i,o),m={termType:"BlankNode",value:e.getId()};t.push({subject:d,predicate:s,object:f,graph:r}),t.push({subject:d,predicate:a,object:m,graph:r}),d=m}if(u){let h=e6(u,e,t,r,i,o);t.push({subject:d,predicate:s,object:h,graph:r}),t.push({subject:d,predicate:a,object:c,graph:r})}return l}function e6(n,e,t,r,i,o){let s={};if(vV.isValue(n)){s.termType="Literal",s.value=void 0,s.datatype={termType:"NamedNode"};let a=n["@value"],c=n["@type"]||null;if(c==="@json")s.value=efe(a),s.datatype.value=sfe;else if(M2.isBoolean(a))s.value=a.toString(),s.datatype.value=c||cfe;else if(M2.isDouble(a)||c===CV)M2.isDouble(a)||(a=parseFloat(a)),s.value=a.toExponential(15).replace(/(\d)0*e\+?/,"$1E"),s.datatype.value=c||CV;else if(M2.isNumber(a))s.value=a.toFixed(0),s.datatype.value=c||ufe;else if("@direction"in n&&i==="i18n-datatype"){let u=(n["@language"]||"").toLowerCase(),l=n["@direction"],d=`https://www.w3.org/ns/i18n#${u}_${l}`;s.datatype.value=d,s.value=a}else{if("@direction"in n&&i==="compound-literal")throw new SV("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if("@direction"in n&&i)throw new SV("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});"@language"in n?("@direction"in n&&!i&&o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:s.value}},options:o}),s.value=a,s.datatype.value=c||afe,s.language=n["@language"]):("@direction"in n&&!i&&o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:s.value}},options:o}),s.value=a,s.datatype.value=c||lfe)}}else if(vV.isList(n)){let a=ffe(n["@list"],e,t,r,i,o);s.termType=a.termType,s.value=a.value}else{let a=M2.isObject(n)?n["@id"]:n;s.termType=a.startsWith("_:")?"BlankNode":"NamedNode",s.value=a}return s.termType==="NamedNode"&&!q3(s.value)?(o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative object reference",level:"warning",message:"Relative object reference found.",details:{object:s.value}},options:o}),null):s}});var FV=oe((Q9e,OV)=>{"use strict";var{isKeyword:t6}=Of(),Ra=Su(),qn=ls(),ci=fs(),TV=Cu(),O2=ds(),{createNodeMap:hfe,mergeNodeMapGraphs:pfe}=P2(),Da={};OV.exports=Da;Da.frameMergedOrDefault=(n,e,t)=>{let r={options:t,embedded:!1,graph:"@default",graphMap:{"@default":{}},subjectStack:[],link:{},bnodeMap:{}},i=new ci.IdentifierIssuer("_:b");hfe(n,r.graphMap,"@default",i),t.merged&&(r.graphMap["@merged"]=pfe(r.graphMap),r.graph="@merged"),r.subjects=r.graphMap[r.graph];let o=[];Da.frame(r,Object.keys(r.subjects).sort(),e,o),t.pruneBlankNodeIdentifiers&&(t.bnodesToClear=Object.keys(r.bnodeMap).filter(s=>r.bnodeMap[s].length===1));return t.link={},Q3(o,t)};Da.frame=(n,e,t,r,i=null)=>{kV(t),t=t[0];let o=n.options,s={embed:V3(t,o,"embed"),explicit:V3(t,o,"explicit"),requireAll:V3(t,o,"requireAll")};n.link.hasOwnProperty(n.graph)||(n.link[n.graph]={});let a=n.link[n.graph],c=gfe(n,e,t,s),u=Object.keys(c).sort();for(let l of u){let d=c[l];if(i===null?n.uniqueEmbeds={[n.graph]:{}}:n.uniqueEmbeds[n.graph]=n.uniqueEmbeds[n.graph]||{},s.embed==="@link"&&l in a){_p(r,i,a[l]);continue}let h={"@id":l};if(l.indexOf("_:")===0&&ci.addValue(n.bnodeMap,l,h,{propertyIsArray:!0}),a[l]=h,(s.embed==="@first"||s.embed==="@last")&&n.is11)throw new O2("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:t});if(!(!n.embedded&&n.uniqueEmbeds[n.graph].hasOwnProperty(l))){if(n.embedded&&(s.embed==="@never"||mfe(d,n.graph,n.subjectStack))){_p(r,i,h);continue}if(n.embedded&&(s.embed=="@first"||s.embed=="@once")&&n.uniqueEmbeds[n.graph].hasOwnProperty(l)){_p(r,i,h);continue}if(s.embed==="@last"&&l in n.uniqueEmbeds[n.graph]&&yfe(n,l),n.uniqueEmbeds[n.graph][l]={parent:r,property:i},n.subjectStack.push({subject:d,graph:n.graph}),l in n.graphMap){let f=!1,m=null;"@graph"in t?(m=t["@graph"][0],f=!(l==="@merged"||l==="@default"),qn.isObject(m)||(m={})):(f=n.graph!=="@merged",m={}),f&&Da.frame({...n,graph:l,embedded:!1},Object.keys(n.graphMap[l]).sort(),[m],h,"@graph")}"@included"in t&&Da.frame({...n,embedded:!1},e,t["@included"],h,"@included");for(let f of Object.keys(d).sort()){if(t6(f)){if(h[f]=ci.clone(d[f]),f==="@type")for(let m of d["@type"])m.indexOf("_:")===0&&ci.addValue(n.bnodeMap,m,h,{propertyIsArray:!0});continue}if(!(s.explicit&&!(f in t)))for(let m of d[f]){let w=f in t?t[f]:BV(s);if(Ra.isList(m)){let b=t[f]&&t[f][0]&&t[f][0]["@list"]?t[f][0]["@list"]:BV(s),S={"@list":[]};_p(h,f,S);let R=m["@list"];for(let G of R)Ra.isSubjectReference(G)?Da.frame({...n,embedded:!0},[G["@id"]],b,S,"@list"):_p(S,"@list",ci.clone(G))}else Ra.isSubjectReference(m)?Da.frame({...n,embedded:!0},[m["@id"]],w,h,f):n6(w[0],m)&&_p(h,f,ci.clone(m))}}for(let f of Object.keys(t).sort()){if(f==="@type"){if(!qn.isObject(t[f][0])||!("@default"in t[f][0]))continue}else if(t6(f))continue;let m=t[f][0]||{};if(!V3(m,o,"omitDefault")&&!(f in h)){let b="@null";"@default"in m&&(b=ci.clone(m["@default"])),qn.isArray(b)||(b=[b]),h[f]=[{"@preserve":b}]}}for(let f of Object.keys(t["@reverse"]||{}).sort()){let m=t["@reverse"][f];for(let w of Object.keys(n.subjects))ci.getValues(n.subjects[w],f).some(S=>S["@id"]===l)&&(h["@reverse"]=h["@reverse"]||{},ci.addValue(h["@reverse"],f,[],{propertyIsArray:!0}),Da.frame({...n,embedded:!0},[w],m,h["@reverse"][f],i))}_p(r,i,h),n.subjectStack.pop()}}};Da.cleanupNull=(n,e)=>{if(qn.isArray(n))return n.map(r=>Da.cleanupNull(r,e)).filter(r=>r);if(n==="@null")return null;if(qn.isObject(n)){if("@id"in n){let t=n["@id"];if(e.link.hasOwnProperty(t)){let r=e.link[t].indexOf(n);if(r!==-1)return e.link[t][r];e.link[t].push(n)}else e.link[t]=[n]}for(let t in n)n[t]=Da.cleanupNull(n[t],e)}return n};function BV(n){let e={};for(let t in n)n[t]!==void 0&&(e["@"+t]=[n[t]]);return[e]}function mfe(n,e,t){for(let r=t.length-1;r>=0;--r){let i=t[r];if(i.graph===e&&i.subject["@id"]===n["@id"])return!0}return!1}function V3(n,e,t){let r="@"+t,i=r in n?n[r][0]:e[t];if(t==="embed"){if(i===!0)i="@once";else if(i===!1)i="@never";else if(i!=="@always"&&i!=="@never"&&i!=="@link"&&i!=="@first"&&i!=="@last"&&i!=="@once")throw new O2("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:n})}return i}function kV(n){if(!qn.isArray(n)||n.length!==1||!qn.isObject(n[0]))throw new O2("Invalid JSON-LD syntax; a JSON-LD frame must be a single object.","jsonld.SyntaxError",{frame:n});if("@id"in n[0]){for(let e of ci.asArray(n[0]["@id"]))if(!(qn.isObject(e)||TV.isAbsolute(e))||qn.isString(e)&&e.indexOf("_:")===0)throw new O2("Invalid JSON-LD syntax; invalid @id in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:n})}if("@type"in n[0]){for(let e of ci.asArray(n[0]["@type"]))if(!(qn.isObject(e)||TV.isAbsolute(e)||e==="@json")||qn.isString(e)&&e.indexOf("_:")===0)throw new O2("Invalid JSON-LD syntax; invalid @type in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:n})}}function gfe(n,e,t,r){let i={};for(let o of e){let s=n.graphMap[n.graph][o];MV(n,s,t,r)&&(i[o]=s)}return i}function MV(n,e,t,r){let i=!0,o=!1;for(let s in t){let a=!1,c=ci.getValues(e,s),u=ci.getValues(t,s).length===0;if(s==="@id"){if(qn.isEmptyObject(t["@id"][0]||{})?a=!0:t["@id"].length>=0&&(a=t["@id"].includes(c[0])),!r.requireAll)return a}else if(s==="@type"){if(i=!1,u){if(c.length>0)return!1;a=!0}else if(t["@type"].length===1&&qn.isEmptyObject(t["@type"][0]))a=c.length>0;else for(let l of t["@type"])qn.isObject(l)&&"@default"in l?a=!0:a=a||c.some(d=>d===l);if(!r.requireAll)return a}else{if(t6(s))continue;{let l=ci.getValues(t,s)[0],d=!1;if(l&&(kV([l]),d="@default"in l),i=!1,c.length===0&&d)continue;if(c.length>0&&u)return!1;if(l===void 0){if(c.length>0)return!1;a=!0}else if(Ra.isList(l)){let h=l["@list"][0];if(Ra.isList(c[0])){let f=c[0]["@list"];Ra.isValue(h)?a=f.some(m=>n6(h,m)):(Ra.isSubject(h)||Ra.isSubjectReference(h))&&(a=f.some(m=>PV(n,h,m,r)))}}else Ra.isValue(l)?a=c.some(h=>n6(l,h)):Ra.isSubjectReference(l)?a=c.some(h=>PV(n,l,h,r)):qn.isObject(l)?a=c.length>0:a=!1}}if(!a&&r.requireAll)return!1;o=o||a}return i||o}function yfe(n,e){let t=n.uniqueEmbeds[n.graph],r=t[e],i=r.parent,o=r.property,s={"@id":e};if(qn.isArray(i)){for(let c=0;c<i.length;++c)if(ci.compareValues(i[c],s)){i[c]=s;break}}else{let c=qn.isArray(i[o]);ci.removeValue(i,o,s,{propertyIsArray:c}),ci.addValue(i,o,s,{propertyIsArray:c})}let a=c=>{let u=Object.keys(t);for(let l of u)l in t&&qn.isObject(t[l].parent)&&t[l].parent["@id"]===c&&(delete t[l],a(l))};a(e)}function Q3(n,e){if(qn.isArray(n))return n.map(t=>Q3(t,e));if(qn.isObject(n)){if("@preserve"in n)return n["@preserve"][0];if(Ra.isValue(n))return n;if(Ra.isList(n))return n["@list"]=Q3(n["@list"],e),n;if("@id"in n){let t=n["@id"];if(e.link.hasOwnProperty(t)){let r=e.link[t].indexOf(n);if(r!==-1)return e.link[t][r];e.link[t].push(n)}else e.link[t]=[n]}for(let t in n){if(t==="@id"&&e.bnodesToClear.includes(n[t])){delete n["@id"];continue}n[t]=Q3(n[t],e)}}return n}function _p(n,e,t){qn.isObject(n)?ci.addValue(n,e,t,{propertyIsArray:!0}):n.push(t)}function PV(n,e,t,r){if(!("@id"in t))return!1;let i=n.subjects[t["@id"]];return i&&MV(n,i,e,r)}function n6(n,e){let t=e["@value"],r=e["@type"],i=e["@language"],o=n["@value"]?qn.isArray(n["@value"])?n["@value"]:[n["@value"]]:[],s=n["@type"]?qn.isArray(n["@type"])?n["@type"]:[n["@type"]]:[],a=n["@language"]?qn.isArray(n["@language"])?n["@language"]:[n["@language"]]:[];return o.length===0&&s.length===0&&a.length===0?!0:!(!(o.includes(t)||qn.isEmptyObject(o[0]))||!(!r&&s.length===0||s.includes(r)||r&&qn.isEmptyObject(s[0]))||!(!i&&a.length===0||a.includes(i)||i&&qn.isEmptyObject(a[0])))}});var QV=oe((z9e,VV)=>{"use strict";var a6=ds(),{isArray:Nf,isObject:Uf,isString:HV,isUndefined:r6}=ls(),{isList:s6,isValue:Vl,isGraph:KV,isSimpleGraph:NV,isSubjectReference:i6}=Su(),{expandIri:JV,getContextValue:Ho,isKeyword:qV,process:o6,processingMode:wfe}=Of(),{removeBase:UV,prependBase:bfe}=Cu(),{REGEX_KEYWORD:Efe,addValue:zs,asArray:z3,compareShortestLeast:Ife}=fs(),Ot={};VV.exports=Ot;Ot.compact=async({activeCtx:n,activeProperty:e=null,element:t,options:r={}})=>{if(Nf(t)){let o=[];for(let s=0;s<t.length;++s){let a=await Ot.compact({activeCtx:n,activeProperty:e,element:t[s],options:r});a!==null&&o.push(a)}return r.compactArrays&&o.length===1&&(Ho(n,e,"@container")||[]).length===0&&(o=o[0]),o}let i=Ho(n,e,"@context");if(r6(i)||(n=await o6({activeCtx:n,localCtx:i,propagate:!0,overrideProtected:!0,options:r})),Uf(t)){if(r.link&&"@id"in t&&r.link.hasOwnProperty(t["@id"])){let h=r.link[t["@id"]];for(let f=0;f<h.length;++f)if(h[f].expanded===t)return h[f].compacted}if(Vl(t)||i6(t)){let h=Ot.compactValue({activeCtx:n,activeProperty:e,value:t,options:r});return r.link&&i6(t)&&(r.link.hasOwnProperty(t["@id"])||(r.link[t["@id"]]=[]),r.link[t["@id"]].push({expanded:t,compacted:h})),h}if(s6(t)&&(Ho(n,e,"@container")||[]).includes("@list"))return Ot.compact({activeCtx:n,activeProperty:e,element:t["@list"],options:r});let o=e==="@reverse",s={},a=n;!Vl(t)&&!i6(t)&&(n=n.revertToPreviousContext());let c=Ho(a,e,"@context");r6(c)||(n=await o6({activeCtx:n,localCtx:c,propagate:!0,overrideProtected:!0,options:r})),r.link&&"@id"in t&&(r.link.hasOwnProperty(t["@id"])||(r.link[t["@id"]]=[]),r.link[t["@id"]].push({expanded:t,compacted:s}));let u=t["@type"]||[];u.length>1&&(u=Array.from(u).sort());let l=n;for(let h of u){let f=Ot.compactIri({activeCtx:l,iri:h,relativeTo:{vocab:!0}}),m=Ho(a,f,"@context");r6(m)||(n=await o6({activeCtx:n,localCtx:m,options:r,propagate:!1}))}let d=Object.keys(t).sort();for(let h of d){let f=t[h];if(h==="@id"){let m=z3(f).map(b=>Ot.compactIri({activeCtx:n,iri:b,relativeTo:{vocab:!1},base:r.base}));m.length===1&&(m=m[0]);let w=Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}});s[w]=m;continue}if(h==="@type"){let m=z3(f).map(G=>Ot.compactIri({activeCtx:a,iri:G,relativeTo:{vocab:!0}}));m.length===1&&(m=m[0]);let w=Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}}),R=(Ho(n,w,"@container")||[]).includes("@set")&&wfe(n,1.1)||Nf(m)&&f.length===0;zs(s,w,m,{propertyIsArray:R});continue}if(h==="@reverse"){let m=await Ot.compact({activeCtx:n,activeProperty:"@reverse",element:f,options:r});for(let w in m)if(n.mappings.has(w)&&n.mappings.get(w).reverse){let b=m[w],R=(Ho(n,w,"@container")||[]).includes("@set")||!r.compactArrays;zs(s,w,b,{propertyIsArray:R}),delete m[w]}if(Object.keys(m).length>0){let w=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,w,m)}continue}if(h==="@preserve"){let m=await Ot.compact({activeCtx:n,activeProperty:e,element:f,options:r});Nf(m)&&m.length===0||zs(s,h,m);continue}if(h==="@index"){if((Ho(n,e,"@container")||[]).includes("@index"))continue;let w=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,w,f);continue}if(h!=="@graph"&&h!=="@list"&&h!=="@included"&&qV(h)){let m=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,m,f);continue}if(!Nf(f))throw new a6("JSON-LD expansion error; expanded value must be an array.","jsonld.SyntaxError");if(f.length===0){let m=Ot.compactIri({activeCtx:n,iri:h,value:f,relativeTo:{vocab:!0},reverse:o}),w=n.mappings.has(m)?n.mappings.get(m)["@nest"]:null,b=s;w&&(GV(n,w,r),Uf(s[w])||(s[w]={}),b=s[w]),zs(b,m,f,{propertyIsArray:!0})}for(let m of f){let w=Ot.compactIri({activeCtx:n,iri:h,value:m,relativeTo:{vocab:!0},reverse:o}),b=n.mappings.has(w)?n.mappings.get(w)["@nest"]:null,S=s;b&&(GV(n,b,r),Uf(s[b])||(s[b]={}),S=s[b]);let R=Ho(n,w,"@container")||[],G=KV(m),U=s6(m),H;U?H=m["@list"]:G&&(H=m["@graph"]);let M=await Ot.compact({activeCtx:n,activeProperty:w,element:U||G?H:m,options:r});if(U)if(Nf(M)||(M=[M]),!R.includes("@list"))M={[Ot.compactIri({activeCtx:n,iri:"@list",relativeTo:{vocab:!0}})]:M},"@index"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=m["@index"]);else{zs(S,w,M,{valueIsArray:!0,allowDuplicate:!0});continue}if(G)if(R.includes("@graph")&&(R.includes("@id")||R.includes("@index")&&NV(m))){let A;S.hasOwnProperty(w)?A=S[w]:S[w]=A={};let D=(R.includes("@id")?m["@id"]:m["@index"])||Ot.compactIri({activeCtx:n,iri:"@none",relativeTo:{vocab:!0}});zs(A,D,M,{propertyIsArray:!r.compactArrays||R.includes("@set")})}else R.includes("@graph")&&NV(m)?(Nf(M)&&M.length>1&&(M={"@included":M}),zs(S,w,M,{propertyIsArray:!r.compactArrays||R.includes("@set")})):(Nf(M)&&M.length===1&&r.compactArrays&&(M=M[0]),M={[Ot.compactIri({activeCtx:n,iri:"@graph",relativeTo:{vocab:!0}})]:M},"@id"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}})]=m["@id"]),"@index"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=m["@index"]),zs(S,w,M,{propertyIsArray:!r.compactArrays||R.includes("@set")}));else if(R.includes("@language")||R.includes("@index")||R.includes("@id")||R.includes("@type")){let A;S.hasOwnProperty(w)?A=S[w]:S[w]=A={};let D;if(R.includes("@language"))Vl(M)&&(M=M["@value"]),D=m["@language"];else if(R.includes("@index")){let z=Ho(n,w,"@index")||"@index",j=Ot.compactIri({activeCtx:n,iri:z,relativeTo:{vocab:!0}});if(z==="@index")D=m["@index"],delete M[j];else{let Y;if([D,...Y]=z3(M[z]||[]),!HV(D))D=null;else switch(Y.length){case 0:delete M[z];break;case 1:M[z]=Y[0];break;default:M[z]=Y;break}}}else if(R.includes("@id")){let z=Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}});D=M[z],delete M[z]}else if(R.includes("@type")){let z=Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}}),j;switch([D,...j]=z3(M[z]||[]),j.length){case 0:delete M[z];break;case 1:M[z]=j[0];break;default:M[z]=j;break}Object.keys(M).length===1&&"@id"in m&&(M=await Ot.compact({activeCtx:n,activeProperty:w,element:{"@id":m["@id"]},options:r}))}D||(D=Ot.compactIri({activeCtx:n,iri:"@none",relativeTo:{vocab:!0}})),zs(A,D,M,{propertyIsArray:R.includes("@set")})}else{let A=!r.compactArrays||R.includes("@set")||R.includes("@list")||Nf(M)&&M.length===0||h==="@list"||h==="@graph";zs(S,w,M,{propertyIsArray:A})}}}return s}return t};Ot.compactIri=({activeCtx:n,iri:e,value:t=null,relativeTo:r={vocab:!1},reverse:i=!1,base:o=null})=>{if(e===null)return e;n.isPropertyTermScoped&&n.previousContext&&(n=n.previousContext);let s=n.getInverse();if(qV(e)&&e in s&&"@none"in s[e]&&"@type"in s[e]["@none"]&&"@none"in s[e]["@none"]["@type"])return s[e]["@none"]["@type"]["@none"];if(r.vocab&&e in s){let d=n["@language"]||"@none",h=[];Uf(t)&&"@index"in t&&!("@graph"in t)&&h.push("@index","@index@set"),Uf(t)&&"@preserve"in t&&(t=t["@preserve"][0]),KV(t)?("@index"in t&&h.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in t&&h.push("@graph@id","@graph@id@set"),h.push("@graph","@graph@set","@set"),"@index"in t||h.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in t||h.push("@graph@id","@graph@id@set")):Uf(t)&&!Vl(t)&&h.push("@id","@id@set","@type","@set@type");let f="@language",m="@null";if(i)f="@type",m="@reverse",h.push("@set");else if(s6(t)){"@index"in t||h.push("@list");let b=t["@list"];if(b.length===0)f="@any",m="@none";else{let S=b.length===0?d:null,R=null;for(let G=0;G<b.length;++G){let U=b[G],H="@none",M="@none";if(Vl(U))if("@direction"in U){let A=(U["@language"]||"").toLowerCase(),D=U["@direction"];H=`${A}_${D}`}else"@language"in U?H=U["@language"].toLowerCase():"@type"in U?M=U["@type"]:H="@null";else M="@id";if(S===null?S=H:H!==S&&Vl(U)&&(S="@none"),R===null?R=M:M!==R&&(R="@none"),S==="@none"&&R==="@none")break}S=S||"@none",R=R||"@none",R!=="@none"?(f="@type",m=R):m=S}}else{if(Vl(t))if("@language"in t&&!("@index"in t)){h.push("@language","@language@set"),m=t["@language"];let b=t["@direction"];b&&(m=`${m}_${b}`)}else"@direction"in t&&!("@index"in t)?m=`_${t["@direction"]}`:"@type"in t&&(f="@type",m=t["@type"]);else f="@type",m="@id";h.push("@set")}h.push("@none"),Uf(t)&&!("@index"in t)&&h.push("@index","@index@set"),Vl(t)&&Object.keys(t).length===1&&h.push("@language","@language@set");let w=Afe(n,e,t,h,f,m);if(w!==null)return w}if(r.vocab&&"@vocab"in n){let d=n["@vocab"];if(e.indexOf(d)===0&&e!==d){let h=e.substr(d.length);if(!n.mappings.has(h))return h}}let a=null,c=[],u=n.fastCurieMap,l=e.length-1;for(let d=0;d<l&&e[d]in u;++d)u=u[e[d]],""in u&&c.push(u[""][0]);for(let d=c.length-1;d>=0;--d){let h=c[d],f=h.terms;for(let m of f){let w=m+":"+e.substr(h.iri.length);n.mappings.get(m)._prefix&&(!n.mappings.has(w)||t===null&&n.mappings.get(w)["@id"]===e)&&(a===null||Ife(w,a)<0)&&(a=w)}}if(a!==null)return a;for(let[d,h]of n.mappings)if(h&&h._prefix&&e.startsWith(d+":"))throw new a6(`Absolute IRI "${e}" confused with prefix "${d}".`,"jsonld.SyntaxError",{code:"IRI confused with prefix",context:n});if(!r.vocab)if("@base"in n)if(n["@base"]){let d=UV(bfe(o,n["@base"]),e);return Efe.test(d)?`./${d}`:d}else return e;else return UV(o,e);return e};Ot.compactValue=({activeCtx:n,activeProperty:e,value:t,options:r})=>{if(Vl(t)){let a=Ho(n,e,"@type"),c=Ho(n,e,"@language"),u=Ho(n,e,"@direction"),l=Ho(n,e,"@container")||[],d="@index"in t&&!l.includes("@index");if(!d&&a!=="@none"&&(t["@type"]===a||"@language"in t&&t["@language"]===c&&"@direction"in t&&t["@direction"]===u||"@language"in t&&t["@language"]===c||"@direction"in t&&t["@direction"]===u))return t["@value"];let h=Object.keys(t).length,f=h===1||h===2&&"@index"in t&&!d,m="@language"in n,w=HV(t["@value"]),b=n.mappings.has(e)&&n.mappings.get(e)["@language"]===null;if(f&&a!=="@none"&&(!m||!w||b))return t["@value"];let S={};return d&&(S[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=t["@index"]),"@type"in t?S[Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}})]=Ot.compactIri({activeCtx:n,iri:t["@type"],relativeTo:{vocab:!0}}):"@language"in t&&(S[Ot.compactIri({activeCtx:n,iri:"@language",relativeTo:{vocab:!0}})]=t["@language"]),"@direction"in t&&(S[Ot.compactIri({activeCtx:n,iri:"@direction",relativeTo:{vocab:!0}})]=t["@direction"]),S[Ot.compactIri({activeCtx:n,iri:"@value",relativeTo:{vocab:!0}})]=t["@value"],S}let i=JV(n,e,{vocab:!0},r),o=Ho(n,e,"@type"),s=Ot.compactIri({activeCtx:n,iri:t["@id"],relativeTo:{vocab:o==="@vocab"},base:r.base});return o==="@id"||o==="@vocab"||i==="@graph"?s:{[Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}})]:s}};function Afe(n,e,t,r,i,o){o===null&&(o="@null");let s=[];if((o==="@id"||o==="@reverse")&&Uf(t)&&"@id"in t){o==="@reverse"&&s.push("@reverse");let c=Ot.compactIri({activeCtx:n,iri:t["@id"],relativeTo:{vocab:!0}});n.mappings.has(c)&&n.mappings.get(c)&&n.mappings.get(c)["@id"]===t["@id"]?s.push.apply(s,["@vocab","@id"]):s.push.apply(s,["@id","@vocab"])}else{s.push(o);let c=s.find(u=>u.includes("_"));c&&s.push(c.replace(/^[^_]+_/,"_"))}s.push("@none");let a=n.inverse[e];for(let c of r){if(!(c in a))continue;let u=a[c][i];for(let l of s)if(l in u)return u[l]}return null}function GV(n,e,t){if(JV(n,e,{vocab:!0},t)!=="@nest")throw new a6("JSON-LD compact error; nested property must have an @nest value resolving to @nest.","jsonld.SyntaxError",{code:"invalid @nest value"})}});var YV=oe((Y9e,zV)=>{"use strict";zV.exports=n=>{class e{toString(){return"[object JsonLdProcessor]"}}return Object.defineProperty(e,"prototype",{writable:!1,enumerable:!1}),Object.defineProperty(e.prototype,"constructor",{writable:!0,enumerable:!1,configurable:!0,value:e}),e.compact=function(t,r){return arguments.length<2?Promise.reject(new TypeError("Could not compact, too few arguments.")):n.compact(t,r)},e.expand=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not expand, too few arguments.")):n.expand(t)},e.flatten=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not flatten, too few arguments.")):n.flatten(t)},e}});var Hf=oe((j9e,_V)=>{"use strict";var jV=k3(),WV=Pq(),Gf=fs(),Ql=zq(),c6=Gf.IdentifierIssuer,Du=ds(),xfe=FT(),Y3=jq(),{expand:vfe}=aV(),{flatten:Sfe}=fV(),{fromRDF:Cfe}=IV(),{toRDF:Lfe}=DV(),{frameMergedOrDefault:Rfe,cleanupNull:Dfe}=FV(),{isArray:Ug,isObject:$p,isString:Tu}=ls(),{isSubjectReference:Tfe}=Su(),{expandIri:Bfe,getInitialContext:j3,process:ZV,processingMode:u6}=Of(),{compact:Pfe,compactIri:kfe}=QV(),{createNodeMap:Mfe,createMergedNodeMap:Ofe,mergeNodeMaps:Ffe}=P2(),{logEventHandler:Nfe,logWarningEventHandler:Ufe,safeEventHandler:Gfe,setDefaultEventHandler:Hfe,setupEventHandler:Kfe,strictEventHandler:Jfe,unhandledEventHandler:qfe}=Og(),XV=function(n){let e={},r=new xfe({max:100});n.compact=async function(o,s,a){if(arguments.length<2)throw new TypeError("Could not compact, too few arguments.");if(s===null)throw new Du("The compaction context must not be null.","jsonld.CompactError",{code:"invalid local context"});if(o===null)return null;a=i(a,{base:Tu(o)?o:"",compactArrays:!0,compactToRelative:!0,graph:!1,skipExpansion:!1,link:!1,issuer:new c6("_:b"),contextResolver:new Ql({sharedCache:r})}),a.link&&(a.skipExpansion=!0),a.compactToRelative||delete a.base;let c;a.skipExpansion?c=o:c=await n.expand(o,a);let u=await n.processContext(j3(a),s,a),l=await Pfe({activeCtx:u,element:c,options:a});a.compactArrays&&!a.graph&&Ug(l)?l.length===1?l=l[0]:l.length===0&&(l={}):a.graph&&$p(l)&&(l=[l]),$p(s)&&"@context"in s&&(s=s["@context"]),s=Gf.clone(s),Ug(s)||(s=[s]);let d=s;s=[];for(let f=0;f<d.length;++f)(!$p(d[f])||Object.keys(d[f]).length>0)&&s.push(d[f]);let h=s.length>0;if(s.length===1&&(s=s[0]),Ug(l)){let f=kfe({activeCtx:u,iri:"@graph",relativeTo:{vocab:!0}}),m=l;l={},h&&(l["@context"]=s),l[f]=m}else if($p(l)&&h){let f=l;l={"@context":s};for(let m in f)l[m]=f[m]}return l},n.expand=async function(o,s){if(arguments.length<1)throw new TypeError("Could not expand, too few arguments.");s=i(s,{keepFreeFloatingNodes:!1,contextResolver:new Ql({sharedCache:r})});let a={},c=[];if("expandContext"in s){let h=Gf.clone(s.expandContext);$p(h)&&"@context"in h?a.expandContext=h:a.expandContext={"@context":h},c.push(a.expandContext)}let u;if(!Tu(o))a.input=Gf.clone(o);else{let h=await n.get(o,s);u=h.documentUrl,a.input=h.document,h.contextUrl&&(a.remoteContext={"@context":h.contextUrl},c.push(a.remoteContext))}"base"in s||(s.base=u||"");let l=j3(s);for(let h of c)l=await ZV({activeCtx:l,localCtx:h,options:s});let d=await vfe({activeCtx:l,element:a.input,options:s});return $p(d)&&"@graph"in d&&Object.keys(d).length===1?d=d["@graph"]:d===null&&(d=[]),Ug(d)||(d=[d]),d},n.flatten=async function(o,s,a){if(arguments.length<1)return new TypeError("Could not flatten, too few arguments.");typeof s=="function"?s=null:s=s||null,a=i(a,{base:Tu(o)?o:"",contextResolver:new Ql({sharedCache:r})});let c=await n.expand(o,a),u=Sfe(c);return s===null?u:(a.graph=!0,a.skipExpansion=!0,await n.compact(u,s,a))},n.frame=async function(o,s,a){if(arguments.length<2)throw new TypeError("Could not frame, too few arguments.");if(a=i(a,{base:Tu(o)?o:"",embed:"@once",explicit:!1,requireAll:!1,omitDefault:!1,bnodesToClear:[],contextResolver:new Ql({sharedCache:r})}),Tu(s)){let b=await n.get(s,a);if(s=b.document,b.contextUrl){let S=s["@context"];S?Ug(S)?S.push(b.contextUrl):S=[S,b.contextUrl]:S=b.contextUrl,s["@context"]=S}}let c=s?s["@context"]||{}:{},u=await n.processContext(j3(a),c,a);a.hasOwnProperty("omitGraph")||(a.omitGraph=u6(u,1.1)),a.hasOwnProperty("pruneBlankNodeIdentifiers")||(a.pruneBlankNodeIdentifiers=u6(u,1.1));let l=await n.expand(o,a),d={...a};d.isFrame=!0,d.keepFreeFloatingNodes=!0;let h=await n.expand(s,d),f=Object.keys(s).map(b=>Bfe(u,b,{vocab:!0}));d.merged=!f.includes("@graph"),d.is11=u6(u,1.1);let m=Rfe(l,h,d);d.graph=!a.omitGraph,d.skipExpansion=!0,d.link={},d.framing=!0;let w=await n.compact(m,c,d);return d.link={},w=Dfe(w,d),w},n.link=async function(o,s,a){let c={};return s&&(c["@context"]=s),c["@embed"]="@link",n.frame(o,c,a)},n.normalize=n.canonize=async function(o,s){if(arguments.length<1)throw new TypeError("Could not canonize, too few arguments.");if(s=i(s,{base:Tu(o)?o:null,algorithm:"URDNA2015",skipExpansion:!1,safe:!0,contextResolver:new Ql({sharedCache:r})}),"inputFormat"in s){if(s.inputFormat!=="application/n-quads"&&s.inputFormat!=="application/nquads")throw new Du("Unknown canonicalization input format.","jsonld.CanonizeError");let u=Y3.parse(o);return jV.canonize(u,s)}let a={...s};delete a.format,a.produceGeneralizedRdf=!1;let c=await n.toRDF(o,a);return jV.canonize(c,s)},n.fromRDF=async function(o,s){if(arguments.length<1)throw new TypeError("Could not convert from RDF, too few arguments.");s=i(s,{format:Tu(o)?"application/n-quads":void 0});let{format:a}=s,{rdfParser:c}=s;if(a){if(c=c||e[a],!c)throw new Du("Unknown input format.","jsonld.UnknownFormat",{format:a})}else c=()=>o;let u=await c(o);return Cfe(u,s)},n.toRDF=async function(o,s){if(arguments.length<1)throw new TypeError("Could not convert to RDF, too few arguments.");s=i(s,{base:Tu(o)?o:"",skipExpansion:!1,contextResolver:new Ql({sharedCache:r})});let a;s.skipExpansion?a=o:a=await n.expand(o,s);let c=Lfe(a,s);if(s.format){if(s.format==="application/n-quads"||s.format==="application/nquads")return Y3.serialize(c);throw new Du("Unknown output format.","jsonld.UnknownFormat",{format:s.format})}return c},n.createNodeMap=async function(o,s){if(arguments.length<1)throw new TypeError("Could not create node map, too few arguments.");s=i(s,{base:Tu(o)?o:"",contextResolver:new Ql({sharedCache:r})});let a=await n.expand(o,s);return Ofe(a,s)},n.merge=async function(o,s,a){if(arguments.length<1)throw new TypeError("Could not merge, too few arguments.");if(!Ug(o))throw new TypeError('Could not merge, "docs" must be an array.');typeof s=="function"?s=null:s=s||null,a=i(a,{contextResolver:new Ql({sharedCache:r})});let c=await Promise.all(o.map(b=>{let S={...a};return n.expand(b,S)})),u=!0;"mergeNodes"in a&&(u=a.mergeNodes);let l=a.issuer||new c6("_:b"),d={"@default":{}};for(let b=0;b<c.length;++b){let S=Gf.relabelBlankNodes(c[b],{issuer:new c6("_:b"+b+"-")}),R=u||b===0?d:{"@default":{}};if(Mfe(S,R,"@default",l),R!==d)for(let G in R){let U=R[G];if(!(G in d)){d[G]=U;continue}let H=d[G];for(let M in U)M in H||(H[M]=U[M])}}let h=Ffe(d),f=[],m=Object.keys(h).sort();for(let b=0;b<m.length;++b){let S=h[m[b]];Tfe(S)||f.push(S)}return s===null?f:(a.graph=!0,a.skipExpansion=!0,await n.compact(f,s,a))},Object.defineProperty(n,"documentLoader",{get:()=>n._documentLoader,set:o=>n._documentLoader=o}),n.documentLoader=async o=>{throw new Du("Could not retrieve a JSON-LD document from the URL. URL dereferencing not implemented.","jsonld.LoadDocumentError",{code:"loading document failed",url:o})},n.get=async function(o,s){let a;typeof s.documentLoader=="function"?a=s.documentLoader:a=n.documentLoader;let c=await a(o);try{if(!c.document)throw new Du("No remote document found at the given URL.","jsonld.NullRemoteDocument");Tu(c.document)&&(c.document=JSON.parse(c.document))}catch(u){throw new Du("Could not retrieve a JSON-LD document from the URL.","jsonld.LoadDocumentError",{code:"loading document failed",cause:u,remoteDoc:c})}return c},n.processContext=async function(o,s,a){return a=i(a,{base:"",contextResolver:new Ql({sharedCache:r})}),s===null?j3(a):(s=Gf.clone(s),$p(s)&&"@context"in s||(s={"@context":s}),ZV({activeCtx:o,localCtx:s,options:a}))},n.getContextValue=Of().getContextValue,n.documentLoaders={},n.useDocumentLoader=function(o){if(!(o in n.documentLoaders))throw new Du('Unknown document loader type: "'+o+'"',"jsonld.UnknownDocumentLoader",{type:o});n.documentLoader=n.documentLoaders[o].apply(n,Array.prototype.slice.call(arguments,1))},n.registerRDFParser=function(o,s){e[o]=s},n.unregisterRDFParser=function(o){delete e[o]},n.registerRDFParser("application/n-quads",Y3.parse),n.registerRDFParser("application/nquads",Y3.parse),n.url=Cu(),n.logEventHandler=Nfe,n.logWarningEventHandler=Ufe,n.safeEventHandler=Gfe,n.setDefaultEventHandler=Hfe,n.strictEventHandler=Jfe,n.unhandledEventHandler=qfe,n.util=Gf,Object.assign(n,Gf),n.promises=n,n.RequestQueue=TT(),n.JsonLdProcessor=YV()(n),WV.setupGlobals(n),WV.setupDocumentLoaders(n);function i(o,{documentLoader:s=n.documentLoader,...a}){if(o&&"compactionMap"in o)throw new Du('"compactionMap" not supported.',"jsonld.OptionsError");if(o&&"expansionMap"in o)throw new Du('"expansionMap" not supported.',"jsonld.OptionsError");return Object.assign({},{documentLoader:s},a,o,{eventHandler:Kfe({options:o})})}return n},l6=function(){return XV(function(){return l6()})};XV(l6);_V.exports=l6});var BQ=oe((XHe,TQ)=>{"use strict";var cv=WR().Buffer;function She(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if((Array.isArray(f)||f instanceof Uint8Array)&&(f=cv.from(f)),!cv.isBuffer(f))throw new TypeError("Expected Buffer");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return cv.alloc(0);for(var m=0,w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);m<f.length;){var G=f.charCodeAt(m);if(G>255)return;var U=e[G];if(U===255)return;for(var H=0,M=S-1;(U!==0||H<b)&&M!==-1;M--,H++)U+=s*R[M]>>>0,R[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=H,m++}for(var A=S-b;A!==S&&R[A]===0;)A++;var D=cv.allocUnsafe(w+(S-A));D.fill(0,0,w);for(var z=w;A!==S;)D[z++]=R[A++];return D}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}TQ.exports=She});var kQ=oe((_He,PQ)=>{"use strict";var Che=BQ(),Lhe="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";PQ.exports=Che(Lhe)});var D6=oe(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.s16=he.s8=he.nu64be=he.u48be=he.u40be=he.u32be=he.u24be=he.u16be=he.nu64=he.u48=he.u40=he.u32=he.u24=he.u16=he.u8=he.offset=he.greedy=he.Constant=he.UTF8=he.CString=he.Blob=he.Boolean=he.BitField=he.BitStructure=he.VariantLayout=he.Union=he.UnionLayoutDiscriminator=he.UnionDiscriminator=he.Structure=he.Sequence=he.DoubleBE=he.Double=he.FloatBE=he.Float=he.NearInt64BE=he.NearInt64=he.NearUInt64BE=he.NearUInt64=he.IntBE=he.Int=he.UIntBE=he.UInt=he.OffsetLayout=he.GreedyCount=he.ExternalLayout=he.bindConstructorLayout=he.nameWithProperty=he.Layout=he.uint8ArrayToBuffer=he.checkUint8Array=void 0;he.constant=he.utf8=he.cstr=he.blob=he.unionLayoutDiscriminator=he.union=he.seq=he.bits=he.struct=he.f64be=he.f64=he.f32be=he.f32=he.ns64be=he.s48be=he.s40be=he.s32be=he.s24be=he.s16be=he.ns64=he.s48=he.s40=he.s32=he.s24=void 0;var L6=_m();function zg(n){if(!(n instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}he.checkUint8Array=zg;function wn(n){return zg(n),L6.Buffer.from(n.buffer,n.byteOffset,n.length)}he.uint8ArrayToBuffer=wn;var Cn=class{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){let t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}};he.Layout=Cn;function R6(n,e){return e.property?n+"["+e.property+"]":n}he.nameWithProperty=R6;function Fhe(n,e){if(typeof n!="function")throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(n,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Cn))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");n.layout_=e,e.boundConstructor_=n,e.makeDestinationObject=(()=>new n),Object.defineProperty(n.prototype,"encode",{value(t,r){return e.encode(this,t,r)},writable:!0}),Object.defineProperty(n,"decode",{value(t,r){return e.decode(t,r)},writable:!0})}he.bindConstructorLayout=Fhe;var Zi=class extends Cn{isCount(){throw new Error("ExternalLayout is abstract")}};he.ExternalLayout=Zi;var mv=class extends Zi{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return!0}decode(e,t=0){zg(e);let r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}};he.GreedyCount=mv;var Z2=class extends Zi{constructor(e,t=0,r){if(!(e instanceof Cn))throw new TypeError("layout must be a Layout");if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof gs||this.layout instanceof js}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,r=0){return this.layout.encode(e,t,r+this.offset)}};he.OffsetLayout=Z2;var gs=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readUIntLE(t,this.span)}encode(e,t,r=0){return wn(t).writeUIntLE(e,r,this.span),this.span}};he.UInt=gs;var js=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readUIntBE(t,this.span)}encode(e,t,r=0){return wn(t).writeUIntBE(e,r,this.span),this.span}};he.UIntBE=js;var ed=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readIntLE(t,this.span)}encode(e,t,r=0){return wn(t).writeIntLE(e,r,this.span),this.span}};he.Int=ed;var qf=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readIntBE(t,this.span)}encode(e,t,r=0){return wn(t).writeIntBE(e,r,this.span),this.span}};he.IntBE=qf;var C6=Math.pow(2,32);function Pv(n){let e=Math.floor(n/C6),t=n-e*C6;return{hi32:e,lo32:t}}function kv(n,e){return n*C6+e}var gv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32LE(t),o=r.readUInt32LE(t+4);return kv(o,i)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32LE(i.lo32,r),o.writeUInt32LE(i.hi32,r+4),8}};he.NearUInt64=gv;var yv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32BE(t),o=r.readUInt32BE(t+4);return kv(i,o)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32BE(i.hi32,r),o.writeUInt32BE(i.lo32,r+4),8}};he.NearUInt64BE=yv;var wv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32LE(t),o=r.readInt32LE(t+4);return kv(o,i)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32LE(i.lo32,r),o.writeInt32LE(i.hi32,r+4),8}};he.NearInt64=wv;var bv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readInt32BE(t),o=r.readUInt32BE(t+4);return kv(i,o)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeInt32BE(i.hi32,r),o.writeUInt32BE(i.lo32,r+4),8}};he.NearInt64BE=bv;var Ev=class extends Cn{constructor(e){super(4,e)}decode(e,t=0){return wn(e).readFloatLE(t)}encode(e,t,r=0){return wn(t).writeFloatLE(e,r),4}};he.Float=Ev;var Iv=class extends Cn{constructor(e){super(4,e)}decode(e,t=0){return wn(e).readFloatBE(t)}encode(e,t,r=0){return wn(t).writeFloatBE(e,r),4}};he.FloatBE=Iv;var Av=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){return wn(e).readDoubleLE(t)}encode(e,t,r=0){return wn(t).writeDoubleLE(e,r),8}};he.Double=Av;var xv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){return wn(e).readDoubleBE(t)}encode(e,t,r=0){return wn(t).writeDoubleBE(e,r),8}};he.DoubleBE=xv;var vv=class extends Cn{constructor(e,t,r){if(!(e instanceof Cn))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof Zi&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let i=-1;!(t instanceof Zi)&&0<e.span&&(i=t*e.span),super(i,r),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0,i=this.count;if(i instanceof Zi&&(i=i.decode(e,t)),0<this.elementLayout.span)r=i*this.elementLayout.span;else{let o=0;for(;o<i;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t=0){let r=[],i=0,o=this.count;for(o instanceof Zi&&(o=o.decode(e,t));i<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),i+=1;return r}encode(e,t,r=0){let i=this.elementLayout,o=e.reduce((s,a)=>s+i.encode(a,t,r+s),0);return this.count instanceof Zi&&this.count.encode(e.length,t,r),o}};he.Sequence=vv;var Sv=class extends Cn{constructor(e,t,r){if(!(Array.isArray(e)&&e.reduce((o,s)=>o&&s instanceof Cn,!0)))throw new TypeError("fields must be array of Layout instances");typeof t=="boolean"&&r===void 0&&(r=t,t=void 0);for(let o of e)if(0>o.span&&o.property===void 0)throw new Error("fields cannot contain unnamed variable-length layout");let i=-1;try{i=e.reduce((o,s)=>o+s.getSpan(),0)}catch{}super(i,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;try{r=this.fields.reduce((i,o)=>{let s=o.getSpan(e,t);return t+=s,i+s},0)}catch{throw new RangeError("indeterminate span")}return r}decode(e,t=0){zg(e);let r=this.makeDestinationObject();for(let i of this.fields)if(i.property!==void 0&&(r[i.property]=i.decode(e,t)),t+=i.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r=0){let i=r,o=0,s=0;for(let a of this.fields){let c=a.span;if(s=0<c?c:0,a.property!==void 0){let u=e[a.property];u!==void 0&&(s=a.encode(u,t,r),0>c&&(c=a.getSpan(t,r)))}o=r,r+=c}return o+s-i}fromArray(e){let t=this.makeDestinationObject();for(let r of this.fields)r.property!==void 0&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}offsetOf(e){if(typeof e!="string")throw new TypeError("property must be string");let t=0;for(let r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}};he.Structure=Sv;var X2=class{constructor(e){this.property=e}decode(e,t){throw new Error("UnionDiscriminator is abstract")}encode(e,t,r){throw new Error("UnionDiscriminator is abstract")}};he.UnionDiscriminator=X2;var Qg=class extends X2{constructor(e,t){if(!(e instanceof Zi&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}};he.UnionLayoutDiscriminator=Qg;var _2=class extends Cn{constructor(e,t,r){let i;if(e instanceof gs||e instanceof js)i=new Qg(new Z2(e));else if(e instanceof Zi&&e.isCount())i=new Qg(e);else if(e instanceof X2)i=e;else throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(t===void 0&&(t=null),!(t===null||t instanceof Cn))throw new TypeError("defaultLayout must be null or a Layout");if(t!==null){if(0>t.span)throw new Error("defaultLayout must have constant span");t.property===void 0&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&(e instanceof gs||e instanceof js)&&(o+=i.layout.span)),super(o,r),this.discriminator=i,this.usesPrefixDiscriminator=e instanceof gs||e instanceof js,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(a){return s(a)},this.configGetSourceVariant=function(a){s=a.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;let r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(Object.prototype.hasOwnProperty.call(e,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(e,this.defaultLayout.property))return;let t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||t.property&&Object.prototype.hasOwnProperty.call(e,t.property)))return t}else for(let t in this.registry){let r=this.registry[t];if(r.property&&Object.prototype.hasOwnProperty.call(e,r.property))return r}throw new Error("unable to infer src variant")}decode(e,t=0){let r,i=this.discriminator,o=i.decode(e,t),s=this.registry[o];if(s===void 0){let a=this.defaultLayout,c=0;this.usesPrefixDiscriminator&&(c=i.layout.span),r=this.makeDestinationObject(),r[i.property]=o,r[a.property]=a.decode(e,t+c)}else r=s.decode(e,t);return r}encode(e,t,r=0){let i=this.getSourceVariant(e);if(i===void 0){let o=this.discriminator,s=this.defaultLayout,a=0;return this.usesPrefixDiscriminator&&(a=o.layout.span),o.encode(e[o.property],t,r),a+s.encode(e[s.property],t,r+a)}return i.encode(e,t,r)}addVariant(e,t,r){let i=new Cv(this,e,t,r);return this.registry[e]=i,i}getVariant(e,t=0){let r;return e instanceof Uint8Array?r=this.discriminator.decode(e,t):r=e,this.registry[r]}};he.Union=_2;var Cv=class extends Cn{constructor(e,t,r,i){if(!(e instanceof _2))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if(typeof r=="string"&&i===void 0&&(i=r,r=null),r){if(!(r instanceof Cn))throw new TypeError("layout must be a Layout");if(e.defaultLayout!==null&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if(typeof i!="string")throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,i),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span);let i=0;return this.layout&&(i=this.layout.getSpan(e,t+r)),r+i}decode(e,t=0){let r=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let i=0;return this.union.usesPrefixDiscriminator&&(i=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+i):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r=0){let i=0;if(this.union.usesPrefixDiscriminator&&(i=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=i;if(this.layout&&(this.layout.encode(e[this.property],t,r+i),o+=this.layout.getSpan(t,r+i),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}};he.VariantLayout=Cv;function Vg(n){return 0>n&&(n+=4294967296),n}var $2=class extends Cn{constructor(e,t,r){if(!(e instanceof gs||e instanceof js))throw new TypeError("word must be a UInt or UIntBE layout");if(typeof t=="string"&&r===void 0&&(r=t,t=!1),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let i=0;this._packedSetValue=function(o){return i=Vg(o),this},this._packedGetValue=function(){return i}}decode(e,t=0){let r=this.makeDestinationObject(),i=this.word.decode(e,t);this._packedSetValue(i);for(let o of this.fields)o.property!==void 0&&(r[o.property]=o.decode(e));return r}encode(e,t,r=0){let i=this.word.decode(t,r);this._packedSetValue(i);for(let o of this.fields)if(o.property!==void 0){let s=e[o.property];s!==void 0&&o.encode(s)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){let r=new e1(this,e,t);return this.fields.push(r),r}addBoolean(e){let t=new Lv(this,e);return this.fields.push(t),t}fieldFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}};he.BitStructure=$2;var e1=class{constructor(e,t,r){if(!(e instanceof $2))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");let i=8*e.span,o=e.fields.reduce((s,a)=>s+a.bits,0);if(t+o>i)throw new Error("bits too long for span remainder ("+(i-o)+" of "+i+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,t===32&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=i-o-t),this.wordMask=Vg(this.valueMask<<this.start),this.property=r}decode(e,t){let r=this.container._packedGetValue();return Vg(r&this.wordMask)>>>this.start}encode(e){if(typeof e!="number"||!Number.isInteger(e)||e!==Vg(e&this.valueMask))throw new TypeError(R6("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);let t=this.container._packedGetValue(),r=Vg(e<<this.start);this.container._packedSetValue(Vg(t&~this.wordMask)|r)}};he.BitField=e1;var Lv=class extends e1{constructor(e,t){super(e,1,t)}decode(e,t){return!!super.decode(e,t)}encode(e){typeof e=="boolean"&&(e=+e),super.encode(e)}};he.Boolean=Lv;var Rv=class extends Cn{constructor(e,t){if(!(e instanceof Zi&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof Zi||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t=0){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),wn(e).slice(t,t+r)}encode(e,t,r){let i=this.length;if(this.length instanceof Zi&&(i=e.length),!(e instanceof Uint8Array&&i===e.length))throw new TypeError(R6("Blob.encode",this)+" requires (length "+i+") Uint8Array as src");if(r+i>t.length)throw new RangeError("encoding overruns Uint8Array");let o=wn(e);return wn(t).write(o.toString("hex"),r,i,"hex"),this.length instanceof Zi&&this.length.encode(i,t,r),i}};he.Blob=Rv;var Dv=class extends Cn{constructor(e){super(-1,e)}getSpan(e,t=0){zg(e);let r=t;for(;r<e.length&&e[r]!==0;)r+=1;return 1+r-t}decode(e,t=0){let r=this.getSpan(e,t);return wn(e).slice(t,t+r-1).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let i=L6.Buffer.from(e,"utf8"),o=i.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");let s=wn(t);return i.copy(s,r),s[r+o]=0,o+1}};he.CString=Dv;var Tv=class extends Cn{constructor(e,t){if(typeof e=="string"&&t===void 0&&(t=e,e=void 0),e===void 0)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t=0){return zg(e),e.length-t}decode(e,t=0){let r=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<r)throw new RangeError("text length exceeds maxSpan");return wn(e).slice(t,t+r).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let i=L6.Buffer.from(e,"utf8"),o=i.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return i.copy(wn(t),r),o}};he.UTF8=Tv;var Bv=class extends Cn{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,r){return 0}};he.Constant=Bv;he.greedy=((n,e)=>new mv(n,e));he.offset=((n,e,t)=>new Z2(n,e,t));he.u8=(n=>new gs(1,n));he.u16=(n=>new gs(2,n));he.u24=(n=>new gs(3,n));he.u32=(n=>new gs(4,n));he.u40=(n=>new gs(5,n));he.u48=(n=>new gs(6,n));he.nu64=(n=>new gv(n));he.u16be=(n=>new js(2,n));he.u24be=(n=>new js(3,n));he.u32be=(n=>new js(4,n));he.u40be=(n=>new js(5,n));he.u48be=(n=>new js(6,n));he.nu64be=(n=>new yv(n));he.s8=(n=>new ed(1,n));he.s16=(n=>new ed(2,n));he.s24=(n=>new ed(3,n));he.s32=(n=>new ed(4,n));he.s40=(n=>new ed(5,n));he.s48=(n=>new ed(6,n));he.ns64=(n=>new wv(n));he.s16be=(n=>new qf(2,n));he.s24be=(n=>new qf(3,n));he.s32be=(n=>new qf(4,n));he.s40be=(n=>new qf(5,n));he.s48be=(n=>new qf(6,n));he.ns64be=(n=>new bv(n));he.f32=(n=>new Ev(n));he.f32be=(n=>new Iv(n));he.f64=(n=>new Av(n));he.f64be=(n=>new xv(n));he.struct=((n,e,t)=>new Sv(n,e,t));he.bits=((n,e,t)=>new $2(n,e,t));he.seq=((n,e,t)=>new vv(n,e,t));he.union=((n,e,t)=>new _2(n,e,t));he.unionLayoutDiscriminator=((n,e)=>new Qg(n,e));he.blob=((n,e)=>new Rv(n,e));he.cstr=(n=>new Dv(n));he.utf8=((n,e)=>new Tv(n,e));he.constant=((n,e)=>new Bv(n,e))});function r1(){if(!Nv&&(Nv=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Nv))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Nv(Zge)}var Nv,Zge,H6=co(()=>{"use strict";Zge=new Uint8Array(16)});var cz,uz=co(()=>{"use strict";cz=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i});function Xge(n){return typeof n=="string"&&cz.test(n)}var Qf,i1=co(()=>{"use strict";uz();Qf=Xge});function _ge(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(Ri[n[e+0]]+Ri[n[e+1]]+Ri[n[e+2]]+Ri[n[e+3]]+"-"+Ri[n[e+4]]+Ri[n[e+5]]+"-"+Ri[n[e+6]]+Ri[n[e+7]]+"-"+Ri[n[e+8]]+Ri[n[e+9]]+"-"+Ri[n[e+10]]+Ri[n[e+11]]+Ri[n[e+12]]+Ri[n[e+13]]+Ri[n[e+14]]+Ri[n[e+15]]).toLowerCase();if(!Qf(t))throw TypeError("Stringified UUID is invalid");return t}var Ri,Uv,zf,o1=co(()=>{"use strict";i1();Ri=[];for(Uv=0;Uv<256;++Uv)Ri.push((Uv+256).toString(16).substr(1));zf=_ge});function $ge(n,e,t){var r=e&&t||0,i=e||new Array(16);n=n||{};var o=n.node||lz,s=n.clockseq!==void 0?n.clockseq:K6;if(o==null||s==null){var a=n.random||(n.rng||r1)();o==null&&(o=lz=[a[0]|1,a[1],a[2],a[3],a[4],a[5]]),s==null&&(s=K6=(a[6]<<8|a[7])&16383)}var c=n.msecs!==void 0?n.msecs:Date.now(),u=n.nsecs!==void 0?n.nsecs:q6+1,l=c-J6+(u-q6)/1e4;if(l<0&&n.clockseq===void 0&&(s=s+1&16383),(l<0||c>J6)&&n.nsecs===void 0&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");J6=c,q6=u,K6=s,c+=122192928e5;var d=((c&268435455)*1e4+u)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=d&255;var h=c/4294967296*1e4&268435455;i[r++]=h>>>8&255,i[r++]=h&255,i[r++]=h>>>24&15|16,i[r++]=h>>>16&255,i[r++]=s>>>8|128,i[r++]=s&255;for(var f=0;f<6;++f)i[r+f]=o[f];return e||zf(i)}var lz,K6,J6,q6,dz,fz=co(()=>{"use strict";H6();o1();J6=0,q6=0;dz=$ge});function eye(n){if(!Qf(n))throw TypeError("Invalid UUID");var e,t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}var Gv,V6=co(()=>{"use strict";i1();Gv=eye});function tye(n){n=unescape(encodeURIComponent(n));for(var e=[],t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}function Hv(n,e,t){function r(i,o,s,a){if(typeof i=="string"&&(i=tye(i)),typeof o=="string"&&(o=Gv(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var c=new Uint8Array(16+i.length);if(c.set(o),c.set(i,o.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,s){a=a||0;for(var u=0;u<16;++u)s[a+u]=c[u];return s}return zf(c)}try{r.name=n}catch{}return r.DNS=nye,r.URL=rye,r}var nye,rye,Q6=co(()=>{"use strict";o1();V6();nye="6ba7b810-9dad-11d1-80b4-00c04fd430c8",rye="6ba7b811-9dad-11d1-80b4-00c04fd430c8"});function iye(n){if(typeof n=="string"){var e=unescape(encodeURIComponent(n));n=new Uint8Array(e.length);for(var t=0;t<e.length;++t)n[t]=e.charCodeAt(t)}return oye(sye(aye(n),n.length*8))}function oye(n){for(var e=[],t=n.length*32,r="0123456789abcdef",i=0;i<t;i+=8){var o=n[i>>5]>>>i%32&255,s=parseInt(r.charAt(o>>>4&15)+r.charAt(o&15),16);e.push(s)}return e}function hz(n){return(n+64>>>9<<4)+14+1}function sye(n,e){n[e>>5]|=128<<e%32,n[hz(e)-1]=e;for(var t=1732584193,r=-271733879,i=-1732584194,o=271733878,s=0;s<n.length;s+=16){var a=t,c=r,u=i,l=o;t=_i(t,r,i,o,n[s],7,-680876936),o=_i(o,t,r,i,n[s+1],12,-389564586),i=_i(i,o,t,r,n[s+2],17,606105819),r=_i(r,i,o,t,n[s+3],22,-1044525330),t=_i(t,r,i,o,n[s+4],7,-176418897),o=_i(o,t,r,i,n[s+5],12,1200080426),i=_i(i,o,t,r,n[s+6],17,-1473231341),r=_i(r,i,o,t,n[s+7],22,-45705983),t=_i(t,r,i,o,n[s+8],7,1770035416),o=_i(o,t,r,i,n[s+9],12,-1958414417),i=_i(i,o,t,r,n[s+10],17,-42063),r=_i(r,i,o,t,n[s+11],22,-1990404162),t=_i(t,r,i,o,n[s+12],7,1804603682),o=_i(o,t,r,i,n[s+13],12,-40341101),i=_i(i,o,t,r,n[s+14],17,-1502002290),r=_i(r,i,o,t,n[s+15],22,1236535329),t=$i(t,r,i,o,n[s+1],5,-165796510),o=$i(o,t,r,i,n[s+6],9,-1069501632),i=$i(i,o,t,r,n[s+11],14,643717713),r=$i(r,i,o,t,n[s],20,-373897302),t=$i(t,r,i,o,n[s+5],5,-701558691),o=$i(o,t,r,i,n[s+10],9,38016083),i=$i(i,o,t,r,n[s+15],14,-660478335),r=$i(r,i,o,t,n[s+4],20,-405537848),t=$i(t,r,i,o,n[s+9],5,568446438),o=$i(o,t,r,i,n[s+14],9,-1019803690),i=$i(i,o,t,r,n[s+3],14,-187363961),r=$i(r,i,o,t,n[s+8],20,1163531501),t=$i(t,r,i,o,n[s+13],5,-1444681467),o=$i(o,t,r,i,n[s+2],9,-51403784),i=$i(i,o,t,r,n[s+7],14,1735328473),r=$i(r,i,o,t,n[s+12],20,-1926607734),t=eo(t,r,i,o,n[s+5],4,-378558),o=eo(o,t,r,i,n[s+8],11,-2022574463),i=eo(i,o,t,r,n[s+11],16,1839030562),r=eo(r,i,o,t,n[s+14],23,-35309556),t=eo(t,r,i,o,n[s+1],4,-1530992060),o=eo(o,t,r,i,n[s+4],11,1272893353),i=eo(i,o,t,r,n[s+7],16,-155497632),r=eo(r,i,o,t,n[s+10],23,-1094730640),t=eo(t,r,i,o,n[s+13],4,681279174),o=eo(o,t,r,i,n[s],11,-358537222),i=eo(i,o,t,r,n[s+3],16,-722521979),r=eo(r,i,o,t,n[s+6],23,76029189),t=eo(t,r,i,o,n[s+9],4,-640364487),o=eo(o,t,r,i,n[s+12],11,-421815835),i=eo(i,o,t,r,n[s+15],16,530742520),r=eo(r,i,o,t,n[s+2],23,-995338651),t=to(t,r,i,o,n[s],6,-198630844),o=to(o,t,r,i,n[s+7],10,1126891415),i=to(i,o,t,r,n[s+14],15,-1416354905),r=to(r,i,o,t,n[s+5],21,-57434055),t=to(t,r,i,o,n[s+12],6,1700485571),o=to(o,t,r,i,n[s+3],10,-1894986606),i=to(i,o,t,r,n[s+10],15,-1051523),r=to(r,i,o,t,n[s+1],21,-2054922799),t=to(t,r,i,o,n[s+8],6,1873313359),o=to(o,t,r,i,n[s+15],10,-30611744),i=to(i,o,t,r,n[s+6],15,-1560198380),r=to(r,i,o,t,n[s+13],21,1309151649),t=to(t,r,i,o,n[s+4],6,-145523070),o=to(o,t,r,i,n[s+11],10,-1120210379),i=to(i,o,t,r,n[s+2],15,718787259),r=to(r,i,o,t,n[s+9],21,-343485551),t=Yf(t,a),r=Yf(r,c),i=Yf(i,u),o=Yf(o,l)}return[t,r,i,o]}function aye(n){if(n.length===0)return[];for(var e=n.length*8,t=new Uint32Array(hz(e)),r=0;r<e;r+=8)t[r>>5]|=(n[r/8]&255)<<r%32;return t}function Yf(n,e){var t=(n&65535)+(e&65535),r=(n>>16)+(e>>16)+(t>>16);return r<<16|t&65535}function cye(n,e){return n<<e|n>>>32-e}function Kv(n,e,t,r,i,o){return Yf(cye(Yf(Yf(e,n),Yf(r,o)),i),t)}function _i(n,e,t,r,i,o,s){return Kv(e&t|~e&r,n,e,i,o,s)}function $i(n,e,t,r,i,o,s){return Kv(e&r|t&~r,n,e,i,o,s)}function eo(n,e,t,r,i,o,s){return Kv(e^t^r,n,e,i,o,s)}function to(n,e,t,r,i,o,s){return Kv(t^(e|~r),n,e,i,o,s)}var pz,mz=co(()=>{"use strict";pz=iye});var uye,gz,yz=co(()=>{"use strict";Q6();mz();uye=Hv("v3",48,pz),gz=uye});function lye(n,e,t){n=n||{};var r=n.random||(n.rng||r1)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){t=t||0;for(var i=0;i<16;++i)e[t+i]=r[i];return e}return zf(r)}var wz,bz=co(()=>{"use strict";H6();o1();wz=lye});function dye(n,e,t,r){switch(n){case 0:return e&t^~e&r;case 1:return e^t^r;case 2:return e&t^e&r^t&r;case 3:return e^t^r}}function z6(n,e){return n<<e|n>>>32-e}function fye(n){var e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){var r=unescape(encodeURIComponent(n));n=[];for(var i=0;i<r.length;++i)n.push(r.charCodeAt(i))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);for(var o=n.length/4+2,s=Math.ceil(o/16),a=new Array(s),c=0;c<s;++c){for(var u=new Uint32Array(16),l=0;l<16;++l)u[l]=n[c*64+l*4]<<24|n[c*64+l*4+1]<<16|n[c*64+l*4+2]<<8|n[c*64+l*4+3];a[c]=u}a[s-1][14]=(n.length-1)*8/Math.pow(2,32),a[s-1][14]=Math.floor(a[s-1][14]),a[s-1][15]=(n.length-1)*8&4294967295;for(var d=0;d<s;++d){for(var h=new Uint32Array(80),f=0;f<16;++f)h[f]=a[d][f];for(var m=16;m<80;++m)h[m]=z6(h[m-3]^h[m-8]^h[m-14]^h[m-16],1);for(var w=t[0],b=t[1],S=t[2],R=t[3],G=t[4],U=0;U<80;++U){var H=Math.floor(U/20),M=z6(w,5)+dye(H,b,S,R)+G+e[H]+h[U]>>>0;G=R,R=S,S=z6(b,30)>>>0,b=w,w=M}t[0]=t[0]+w>>>0,t[1]=t[1]+b>>>0,t[2]=t[2]+S>>>0,t[3]=t[3]+R>>>0,t[4]=t[4]+G>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var Ez,Iz=co(()=>{"use strict";Ez=fye});var hye,Az,xz=co(()=>{"use strict";Q6();Iz();hye=Hv("v5",80,Ez),Az=hye});var vz,Sz=co(()=>{"use strict";vz="00000000-0000-0000-0000-000000000000"});function pye(n){if(!Qf(n))throw TypeError("Invalid UUID");return parseInt(n.substr(14,1),16)}var Cz,Lz=co(()=>{"use strict";i1();Cz=pye});var Y6={};Rr(Y6,{NIL:()=>vz,parse:()=>Gv,stringify:()=>zf,v1:()=>dz,v3:()=>gz,v4:()=>wz,v5:()=>Az,validate:()=>Qf,version:()=>Cz});var j6=co(()=>{"use strict";fz();yz();bz();xz();Sz();Lz();i1();o1();V6()});var Dz=oe((sJe,Rz)=>{"use strict";var mye=(j6(),$8(Y6)).v4,gye=function(n,e,t,r){if(typeof n!="string")throw new TypeError(n+" must be a string");r=r||{};let i=typeof r.version=="number"?r.version:2;if(i!==1&&i!==2)throw new TypeError(i+" must be 1 or 2");let o={method:n};if(i===2&&(o.jsonrpc="2.0"),e){if(typeof e!="object"&&!Array.isArray(e))throw new TypeError(e+" must be an object, array or omitted");o.params=e}if(typeof t>"u"){let s=typeof r.generator=="function"?r.generator:function(){return mye()};o.id=s(o,r)}else i===2&&t===null?r.notificationIdNull&&(o.id=null):o.id=t;return o};Rz.exports=gye});var Bz=oe((aJe,Tz)=>{"use strict";var yye=(j6(),$8(Y6)).v4,wye=Dz(),s1=function(n,e){if(!(this instanceof s1))return new s1(n,e);e||(e={}),this.options={reviver:typeof e.reviver<"u"?e.reviver:null,replacer:typeof e.replacer<"u"?e.replacer:null,generator:typeof e.generator<"u"?e.generator:function(){return yye()},version:typeof e.version<"u"?e.version:2,notificationIdNull:typeof e.notificationIdNull=="boolean"?e.notificationIdNull:!1},this.callServer=n};Tz.exports=s1;s1.prototype.request=function(n,e,t,r){let i=this,o=null,s=Array.isArray(n)&&typeof e=="function";if(this.options.version===1&&s)throw new TypeError("JSON-RPC 1.0 does not support batching");if(s||!s&&n&&typeof n=="object"&&typeof e=="function")r=e,o=n;else{typeof t=="function"&&(r=t,t=void 0);let u=typeof r=="function";try{o=wye(n,e,t,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(l){if(u)return r(l);throw l}if(!u)return o}let c;try{c=JSON.stringify(o,this.options.replacer)}catch(u){return r(u)}return this.callServer(c,function(u,l){i._parseResponse(u,l,r)}),o};s1.prototype._parseResponse=function(n,e,t){if(n){t(n);return}if(!e)return t();let r;try{r=JSON.parse(e,this.options.reviver)}catch(i){return t(i)}if(t.length===3)if(Array.isArray(r)){let i=function(s){return typeof s.error<"u"},o=function(s){return!i(s)};return t(null,r.filter(i),r.filter(o))}else return t(null,r.error,r.result);t(null,r)}});var kz=oe((cJe,W6)=>{"use strict";var bye=Object.prototype.hasOwnProperty,Jo="~";function a1(){}Object.create&&(a1.prototype=Object.create(null),new a1().__proto__||(Jo=!1));function Eye(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Pz(n,e,t,r,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Eye(t,r||n,i),s=Jo?Jo+e:e;return n._events[s]?n._events[s].fn?n._events[s]=[n._events[s],o]:n._events[s].push(o):(n._events[s]=o,n._eventsCount++),n}function Jv(n,e){--n._eventsCount===0?n._events=new a1:delete n._events[e]}function no(){this._events=new a1,this._eventsCount=0}no.prototype.eventNames=function(){var e=[],t,r;if(this._eventsCount===0)return e;for(r in t=this._events)bye.call(t,r)&&e.push(Jo?r.slice(1):r);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};no.prototype.listeners=function(e){var t=Jo?Jo+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,o=r.length,s=new Array(o);i<o;i++)s[i]=r[i].fn;return s};no.prototype.listenerCount=function(e){var t=Jo?Jo+e:e,r=this._events[t];return r?r.fn?1:r.length:0};no.prototype.emit=function(e,t,r,i,o,s){var a=Jo?Jo+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,r),!0;case 4:return c.fn.call(c.context,t,r,i),!0;case 5:return c.fn.call(c.context,t,r,i,o),!0;case 6:return c.fn.call(c.context,t,r,i,o,s),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var h=c.length,f;for(d=0;d<h;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,r);break;case 4:c[d].fn.call(c[d].context,t,r,i);break;default:if(!l)for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c[d].fn.apply(c[d].context,l)}}return!0};no.prototype.on=function(e,t,r){return Pz(this,e,t,r,!1)};no.prototype.once=function(e,t,r){return Pz(this,e,t,r,!0)};no.prototype.removeListener=function(e,t,r,i){var o=Jo?Jo+e:e;if(!this._events[o])return this;if(!t)return Jv(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!r||s.context===r)&&Jv(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||r&&s[a].context!==r)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Jv(this,o)}return this};no.prototype.removeAllListeners=function(e){var t;return e?(t=Jo?Jo+e:e,this._events[t]&&Jv(this,t)):(this._events=new a1,this._eventsCount=0),this};no.prototype.off=no.prototype.removeListener;no.prototype.addListener=no.prototype.on;no.prefixed=Jo;no.EventEmitter=no;typeof W6<"u"&&(W6.exports=no)});var JY=oe((vQe,KY)=>{"use strict";function Vbe(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var m=0;if(f[m]!==" "){for(var w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);f[m];){var G=e[f.charCodeAt(m)];if(G===255)return;for(var U=0,H=S-1;(G!==0||U<b)&&H!==-1;H--,U++)G+=s*R[H]>>>0,R[H]=G%256>>>0,G=G/256>>>0;if(G!==0)throw new Error("Non-zero carry");b=U,m++}if(f[m]!==" "){for(var M=S-b;M!==S&&R[M]===0;)M++;for(var A=new Uint8Array(w+(S-M)),D=w;M!==S;)A[D++]=R[M++];return A}}}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}KY.exports=Vbe});var hS=oe((SQe,qY)=>{"use strict";var Qbe=new TextDecoder,zbe=n=>Qbe.decode(n),Ybe=new TextEncoder,jbe=n=>Ybe.encode(n);function Wbe(n,e){let t=new Uint8Array(e),r=0;for(let i of n)t.set(i,r),r+=i.length;return t}qY.exports={decodeText:zbe,encodeText:jbe,concat:Wbe}});var QY=oe((CQe,VY)=>{"use strict";var{encodeText:Zbe}=hS(),XB=class{constructor(e,t,r,i){this.name=e,this.code=t,this.codeBuf=Zbe(this.code),this.alphabet=i,this.codec=r(i)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};VY.exports=XB});var YY=oe((LQe,zY)=>{"use strict";var Xbe=(n,e,t)=>{let r={};for(let u=0;u<e.length;++u)r[e[u]]=u;let i=n.length;for(;n[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),s=0,a=0,c=0;for(let u=0;u<i;++u){let l=r[n[u]];if(l===void 0)throw new SyntaxError("Invalid character "+n[u]);a=a<<t|l,s+=t,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=t||255&a<<8-s)throw new SyntaxError("Unexpected end of data");return o},_be=(n,e,t)=>{let r=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<n.length;++c)for(a=a<<8|n[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s&&(o+=e[i&a<<t-s]),r)for(;o.length*t&7;)o+="=";return o},$be=n=>e=>({encode(t){return _be(t,e,n)},decode(t){return Xbe(t,e,n)}});zY.exports={rfc4648:$be}});var XY=oe((RQe,ZY)=>{"use strict";var v1=JY(),e2e=QY(),{rfc4648:Ti}=YY(),{decodeText:t2e,encodeText:n2e}=hS(),r2e=()=>({encode:t2e,decode:n2e}),jY=[["identity","\0",r2e,""],["base2","0",Ti(1),"01"],["base8","7",Ti(3),"01234567"],["base10","9",v1,"0123456789"],["base16","f",Ti(4),"0123456789abcdef"],["base16upper","F",Ti(4),"0123456789ABCDEF"],["base32hex","v",Ti(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Ti(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Ti(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Ti(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Ti(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Ti(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Ti(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Ti(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Ti(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",v1,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",v1,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",v1,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",v1,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],WY=jY.reduce((n,e)=>(n[e[0]]=new e2e(e[0],e[1],e[2],e[3]),n),{}),i2e=jY.reduce((n,e)=>(n[e[1]]=WY[e[0]],n),{});ZY.exports={names:WY,codes:i2e}});var ej=oe((id,$Y)=>{"use strict";var oy=XY(),{encodeText:o2e,decodeText:pS,concat:_Y}=hS();function s2e(n,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:r}=y0(n);return l2e(t,e),_Y([r,e],r.length+e.length)}function a2e(n,e){let t=y0(n),r=o2e(t.encode(e));return _Y([t.codeBuf,r],t.codeBuf.length+r.length)}function c2e(n){n instanceof Uint8Array&&(n=pS(n));let e=n[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(n=n.toLowerCase()),y0(n[0]).decode(n.substring(1))}function u2e(n){if(n instanceof Uint8Array&&(n=pS(n)),Object.prototype.toString.call(n)!=="[object String]")return!1;try{return y0(n[0]).name}catch{return!1}}function l2e(n,e){y0(n).decode(pS(e))}function y0(n){if(Object.prototype.hasOwnProperty.call(oy.names,n))return oy.names[n];if(Object.prototype.hasOwnProperty.call(oy.codes,n))return oy.codes[n];throw new Error(`Unsupported encoding: ${n}`)}function d2e(n){return n instanceof Uint8Array&&(n=pS(n)),y0(n[0])}id=$Y.exports=s2e;id.encode=a2e;id.decode=c2e;id.isEncoded=u2e;id.encoding=y0;id.encodingFromData=d2e;var f2e=Object.freeze(oy.names),h2e=Object.freeze(oy.codes);id.names=f2e;id.codes=h2e});var iP=oe((sze,Dj)=>{"use strict";Dj.exports=function n(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?n(e.toJSON()):Array.isArray(e)?`[${e.reduce((i,o,s)=>`${i}${s===0?"":","}${n(o===void 0||typeof o=="symbol"?null:o)}`,"")}]`:`{${Object.keys(e).sort().reduce((r,i)=>{if(e[i]===void 0||typeof e[i]=="symbol")return r;let o=r.length===0?"":",";return`${r}${o}${n(i)}:${n(e[i])}`},"")}}`}});var k1=oe(ln=>{"use strict";Object.defineProperty(ln,"__esModule",{value:!0});ln.regexpCode=ln.getEsmExportName=ln.getProperty=ln.safeStringify=ln.stringify=ln.strConcat=ln.addCodeArg=ln.str=ln._=ln.nil=ln._Code=ln.Name=ln.IDENTIFIER=ln._CodeOrName=void 0;var B1=class{};ln._CodeOrName=B1;ln.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;var E0=class extends B1{constructor(e){if(super(),!ln.IDENTIFIER.test(e))throw new Error("CodeGen: name must be a valid identifier");this.str=e}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}};ln.Name=E0;var ka=class extends B1{constructor(e){super(),this._items=typeof e=="string"?[e]:e}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;let e=this._items[0];return e===""||e==='""'}get str(){var e;return(e=this._str)!==null&&e!==void 0?e:this._str=this._items.reduce((t,r)=>`${t}${r}`,"")}get names(){var e;return(e=this._names)!==null&&e!==void 0?e:this._names=this._items.reduce((t,r)=>(r instanceof E0&&(t[r.str]=(t[r.str]||0)+1),t),{})}};ln._Code=ka;ln.nil=new ka("");function oW(n,...e){let t=[n[0]],r=0;for(;r<e.length;)DP(t,e[r]),t.push(n[++r]);return new ka(t)}ln._=oW;var RP=new ka("+");function sW(n,...e){let t=[P1(n[0])],r=0;for(;r<e.length;)t.push(RP),DP(t,e[r]),t.push(RP,P1(n[++r]));return H1e(t),new ka(t)}ln.str=sW;function DP(n,e){e instanceof ka?n.push(...e._items):e instanceof E0?n.push(e):n.push(q1e(e))}ln.addCodeArg=DP;function H1e(n){let e=1;for(;e<n.length-1;){if(n[e]===RP){let t=K1e(n[e-1],n[e+1]);if(t!==void 0){n.splice(e-1,3,t);continue}n[e++]="+"}e++}}function K1e(n,e){if(e==='""')return n;if(n==='""')return e;if(typeof n=="string")return e instanceof E0||n[n.length-1]!=='"'?void 0:typeof e!="string"?`${n.slice(0,-1)}${e}"`:e[0]==='"'?n.slice(0,-1)+e.slice(1):void 0;if(typeof e=="string"&&e[0]==='"'&&!(n instanceof E0))return`"${n}${e.slice(1)}`}function J1e(n,e){return e.emptyStr()?n:n.emptyStr()?e:sW`${n}${e}`}ln.strConcat=J1e;function q1e(n){return typeof n=="number"||typeof n=="boolean"||n===null?n:P1(Array.isArray(n)?n.join(","):n)}function V1e(n){return new ka(P1(n))}ln.stringify=V1e;function P1(n){return JSON.stringify(n).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}ln.safeStringify=P1;function Q1e(n){return typeof n=="string"&&ln.IDENTIFIER.test(n)?new ka(`.${n}`):oW`[${n}]`}ln.getProperty=Q1e;function z1e(n){if(typeof n=="string"&&ln.IDENTIFIER.test(n))return new ka(`${n}`);throw new Error(`CodeGen: invalid export name: ${n}, use explicit $id name mapping`)}ln.getEsmExportName=z1e;function Y1e(n){return new ka(n.toString())}ln.regexpCode=Y1e});var PP=oe(Es=>{"use strict";Object.defineProperty(Es,"__esModule",{value:!0});Es.ValueScope=Es.ValueScopeName=Es.Scope=Es.varKinds=Es.UsedValueState=void 0;var bs=k1(),TP=class extends Error{constructor(e){super(`CodeGen: "code" for ${e} not defined`),this.value=e.value}},RS;(function(n){n[n.Started=0]="Started",n[n.Completed=1]="Completed"})(RS||(Es.UsedValueState=RS={}));Es.varKinds={const:new bs.Name("const"),let:new bs.Name("let"),var:new bs.Name("var")};var DS=class{constructor({prefixes:e,parent:t}={}){this._names={},this._prefixes=e,this._parent=t}toName(e){return e instanceof bs.Name?e:this.name(e)}name(e){return new bs.Name(this._newName(e))}_newName(e){let t=this._names[e]||this._nameGroup(e);return`${e}${t.index++}`}_nameGroup(e){var t,r;if(!((r=(t=this._parent)===null||t===void 0?void 0:t._prefixes)===null||r===void 0)&&r.has(e)||this._prefixes&&!this._prefixes.has(e))throw new Error(`CodeGen: prefix "${e}" is not allowed in this scope`);return this._names[e]={prefix:e,index:0}}};Es.Scope=DS;var TS=class extends bs.Name{constructor(e,t){super(t),this.prefix=e}setValue(e,{property:t,itemIndex:r}){this.value=e,this.scopePath=(0,bs._)`.${new bs.Name(t)}[${r}]`}};Es.ValueScopeName=TS;var j1e=(0,bs._)`\n`,BP=class extends DS{constructor(e){super(e),this._values={},this._scope=e.scope,this.opts={...e,_n:e.lines?j1e:bs.nil}}get(){return this._scope}name(e){return new TS(e,this._newName(e))}value(e,t){var r;if(t.ref===void 0)throw new Error("CodeGen: ref must be passed in value");let i=this.toName(e),{prefix:o}=i,s=(r=t.key)!==null&&r!==void 0?r:t.ref,a=this._values[o];if(a){let l=a.get(s);if(l)return l}else a=this._values[o]=new Map;a.set(s,i);let c=this._scope[o]||(this._scope[o]=[]),u=c.length;return c[u]=t.ref,i.setValue(t,{property:o,itemIndex:u}),i}getValue(e,t){let r=this._values[e];if(r)return r.get(t)}scopeRefs(e,t=this._values){return this._reduceValues(t,r=>{if(r.scopePath===void 0)throw new Error(`CodeGen: name "${r}" has no value`);return(0,bs._)`${e}${r.scopePath}`})}scopeCode(e=this._values,t,r){return this._reduceValues(e,i=>{if(i.value===void 0)throw new Error(`CodeGen: name "${i}" has no value`);return i.value.code},t,r)}_reduceValues(e,t,r={},i){let o=bs.nil;for(let s in e){let a=e[s];if(!a)continue;let c=r[s]=r[s]||new Map;a.forEach(u=>{if(c.has(u))return;c.set(u,RS.Started);let l=t(u);if(l){let d=this.opts.es5?Es.varKinds.var:Es.varKinds.const;o=(0,bs._)`${o}${d} ${u} = ${l};${this.opts._n}`}else if(l=i?.(u))o=(0,bs._)`${o}${l}${this.opts._n}`;else throw new TP(u);c.set(u,RS.Completed)})}return o}};Es.ValueScope=BP});var xt=oe(Gt=>{"use strict";Object.defineProperty(Gt,"__esModule",{value:!0});Gt.or=Gt.and=Gt.not=Gt.CodeGen=Gt.operators=Gt.varKinds=Gt.ValueScopeName=Gt.ValueScope=Gt.Scope=Gt.Name=Gt.regexpCode=Gt.stringify=Gt.getProperty=Gt.nil=Gt.strConcat=Gt.str=Gt._=void 0;var en=k1(),Pc=PP(),$f=k1();Object.defineProperty(Gt,"_",{enumerable:!0,get:function(){return $f._}});Object.defineProperty(Gt,"str",{enumerable:!0,get:function(){return $f.str}});Object.defineProperty(Gt,"strConcat",{enumerable:!0,get:function(){return $f.strConcat}});Object.defineProperty(Gt,"nil",{enumerable:!0,get:function(){return $f.nil}});Object.defineProperty(Gt,"getProperty",{enumerable:!0,get:function(){return $f.getProperty}});Object.defineProperty(Gt,"stringify",{enumerable:!0,get:function(){return $f.stringify}});Object.defineProperty(Gt,"regexpCode",{enumerable:!0,get:function(){return $f.regexpCode}});Object.defineProperty(Gt,"Name",{enumerable:!0,get:function(){return $f.Name}});var MS=PP();Object.defineProperty(Gt,"Scope",{enumerable:!0,get:function(){return MS.Scope}});Object.defineProperty(Gt,"ValueScope",{enumerable:!0,get:function(){return MS.ValueScope}});Object.defineProperty(Gt,"ValueScopeName",{enumerable:!0,get:function(){return MS.ValueScopeName}});Object.defineProperty(Gt,"varKinds",{enumerable:!0,get:function(){return MS.varKinds}});Gt.operators={GT:new en._Code(">"),GTE:new en._Code(">="),LT:new en._Code("<"),LTE:new en._Code("<="),EQ:new en._Code("==="),NEQ:new en._Code("!=="),NOT:new en._Code("!"),OR:new en._Code("||"),AND:new en._Code("&&"),ADD:new en._Code("+")};var sd=class{optimizeNodes(){return this}optimizeNames(e,t){return this}},kP=class extends sd{constructor(e,t,r){super(),this.varKind=e,this.name=t,this.rhs=r}render({es5:e,_n:t}){let r=e?Pc.varKinds.var:this.varKind,i=this.rhs===void 0?"":` = ${this.rhs}`;return`${r} ${this.name}${i};`+t}optimizeNames(e,t){if(e[this.name.str])return this.rhs&&(this.rhs=fy(this.rhs,e,t)),this}get names(){return this.rhs instanceof en._CodeOrName?this.rhs.names:{}}},BS=class extends sd{constructor(e,t,r){super(),this.lhs=e,this.rhs=t,this.sideEffects=r}render({_n:e}){return`${this.lhs} = ${this.rhs};`+e}optimizeNames(e,t){if(!(this.lhs instanceof en.Name&&!e[this.lhs.str]&&!this.sideEffects))return this.rhs=fy(this.rhs,e,t),this}get names(){let e=this.lhs instanceof en.Name?{}:{...this.lhs.names};return kS(e,this.rhs)}},MP=class extends BS{constructor(e,t,r,i){super(e,r,i),this.op=t}render({_n:e}){return`${this.lhs} ${this.op}= ${this.rhs};`+e}},OP=class extends sd{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`${this.label}:`+e}},FP=class extends sd{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`break${this.label?` ${this.label}`:""};`+e}},NP=class extends sd{constructor(e){super(),this.error=e}render({_n:e}){return`throw ${this.error};`+e}get names(){return this.error.names}},UP=class extends sd{constructor(e){super(),this.code=e}render({_n:e}){return`${this.code};`+e}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(e,t){return this.code=fy(this.code,e,t),this}get names(){return this.code instanceof en._CodeOrName?this.code.names:{}}},M1=class extends sd{constructor(e=[]){super(),this.nodes=e}render(e){return this.nodes.reduce((t,r)=>t+r.render(e),"")}optimizeNodes(){let{nodes:e}=this,t=e.length;for(;t--;){let r=e[t].optimizeNodes();Array.isArray(r)?e.splice(t,1,...r):r?e[t]=r:e.splice(t,1)}return e.length>0?this:void 0}optimizeNames(e,t){let{nodes:r}=this,i=r.length;for(;i--;){let o=r[i];o.optimizeNames(e,t)||(W1e(e,o.names),r.splice(i,1))}return r.length>0?this:void 0}get names(){return this.nodes.reduce((e,t)=>x0(e,t.names),{})}},ad=class extends M1{render(e){return"{"+e._n+super.render(e)+"}"+e._n}},GP=class extends M1{},dy=class extends ad{};dy.kind="else";var I0=class n extends ad{constructor(e,t){super(t),this.condition=e}render(e){let t=`if(${this.condition})`+super.render(e);return this.else&&(t+="else "+this.else.render(e)),t}optimizeNodes(){super.optimizeNodes();let e=this.condition;if(e===!0)return this.nodes;let t=this.else;if(t){let r=t.optimizeNodes();t=this.else=Array.isArray(r)?new dy(r):r}if(t)return e===!1?t instanceof n?t:t.nodes:this.nodes.length?this:new n(aW(e),t instanceof n?[t]:t.nodes);if(!(e===!1||!this.nodes.length))return this}optimizeNames(e,t){var r;if(this.else=(r=this.else)===null||r===void 0?void 0:r.optimizeNames(e,t),!!(super.optimizeNames(e,t)||this.else))return this.condition=fy(this.condition,e,t),this}get names(){let e=super.names;return kS(e,this.condition),this.else&&x0(e,this.else.names),e}};I0.kind="if";var A0=class extends ad{};A0.kind="for";var HP=class extends A0{constructor(e){super(),this.iteration=e}render(e){return`for(${this.iteration})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iteration=fy(this.iteration,e,t),this}get names(){return x0(super.names,this.iteration.names)}},KP=class extends A0{constructor(e,t,r,i){super(),this.varKind=e,this.name=t,this.from=r,this.to=i}render(e){let t=e.es5?Pc.varKinds.var:this.varKind,{name:r,from:i,to:o}=this;return`for(${t} ${r}=${i}; ${r}<${o}; ${r}++)`+super.render(e)}get names(){let e=kS(super.names,this.from);return kS(e,this.to)}},PS=class extends A0{constructor(e,t,r,i){super(),this.loop=e,this.varKind=t,this.name=r,this.iterable=i}render(e){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iterable=fy(this.iterable,e,t),this}get names(){return x0(super.names,this.iterable.names)}},O1=class extends ad{constructor(e,t,r){super(),this.name=e,this.args=t,this.async=r}render(e){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(e)}};O1.kind="func";var F1=class extends M1{render(e){return"return "+super.render(e)}};F1.kind="return";var JP=class extends ad{render(e){let t="try"+super.render(e);return this.catch&&(t+=this.catch.render(e)),this.finally&&(t+=this.finally.render(e)),t}optimizeNodes(){var e,t;return super.optimizeNodes(),(e=this.catch)===null||e===void 0||e.optimizeNodes(),(t=this.finally)===null||t===void 0||t.optimizeNodes(),this}optimizeNames(e,t){var r,i;return super.optimizeNames(e,t),(r=this.catch)===null||r===void 0||r.optimizeNames(e,t),(i=this.finally)===null||i===void 0||i.optimizeNames(e,t),this}get names(){let e=super.names;return this.catch&&x0(e,this.catch.names),this.finally&&x0(e,this.finally.names),e}},N1=class extends ad{constructor(e){super(),this.error=e}render(e){return`catch(${this.error})`+super.render(e)}};N1.kind="catch";var U1=class extends ad{render(e){return"finally"+super.render(e)}};U1.kind="finally";var qP=class{constructor(e,t={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...t,_n:t.lines?`
|
|
6
|
+
`;case"r":return"\r";case"f":return"\f";case'"':return'"';case"'":return"'";case"\\":return"\\"}if(r)return String.fromCharCode(parseInt(r,16));if(i)throw new Error("Unsupported U escape")})}});var RT=oe((a9e,cq)=>{"use strict";var sq=D3(),Wle=I2(),Zle=ST(),aq=P3();cq.exports=class{constructor({createMessageDigest:e=()=>new Wle("sha256"),canonicalIdMap:t=new Map,maxDeepIterations:r=1/0}={}){this.name="URDNA2015",this.blankNodeInfo=new Map,this.canonicalIssuer=new sq("_:c14n",t),this.createMessageDigest=e,this.maxDeepIterations=r,this.quads=null,this.deepIterations=null}async main(e){this.deepIterations=new Map,this.quads=e;for(let c of e)this._addBlankNodeQuadInfo({quad:c,component:c.subject}),this._addBlankNodeQuadInfo({quad:c,component:c.object}),this._addBlankNodeQuadInfo({quad:c,component:c.graph});let t=new Map,r=[...this.blankNodeInfo.keys()],i=0;for(let c of r)++i%100===0&&await this._yield(),await this._hashAndTrackBlankNode({id:c,hashToBlankNodes:t});let o=[...t.keys()].sort(),s=[];for(let c of o){let u=t.get(c);if(u.length>1){s.push(u);continue}let l=u[0];this.canonicalIssuer.getId(l)}for(let c of s){let u=[];for(let l of c){if(this.canonicalIssuer.hasId(l))continue;let d=new sq("_:b");d.getId(l);let h=await this.hashNDegreeQuads(l,d);u.push(h)}u.sort(Xle);for(let l of u){let d=l.issuer.getOldIds();for(let h of d)this.canonicalIssuer.getId(h)}}let a=[];for(let c of this.quads){let u=aq.serializeQuadComponents(this._componentWithCanonicalId(c.subject),c.predicate,this._componentWithCanonicalId(c.object),this._componentWithCanonicalId(c.graph));a.push(u)}return a.sort(),a.join("")}async hashFirstDegreeQuads(e){let t=[],r=this.blankNodeInfo.get(e),i=r.quads;for(let s of i){let a={subject:null,predicate:s.predicate,object:null,graph:null};a.subject=this.modifyFirstDegreeComponent(e,s.subject,"subject"),a.object=this.modifyFirstDegreeComponent(e,s.object,"object"),a.graph=this.modifyFirstDegreeComponent(e,s.graph,"graph"),t.push(aq.serializeQuad(a))}t.sort();let o=this.createMessageDigest();for(let s of t)o.update(s);return r.hash=await o.digest(),r.hash}async hashRelatedBlankNode(e,t,r,i){let o;this.canonicalIssuer.hasId(e)?o=this.canonicalIssuer.getId(e):r.hasId(e)?o=r.getId(e):o=this.blankNodeInfo.get(e).hash;let s=this.createMessageDigest();return s.update(i),i!=="g"&&s.update(this.getRelatedPredicate(t)),s.update(o),s.digest()}async hashNDegreeQuads(e,t){let r=this.deepIterations.get(e)||0;if(r>this.maxDeepIterations)throw new Error(`Maximum deep iterations (${this.maxDeepIterations}) exceeded.`);this.deepIterations.set(e,r+1);let i=this.createMessageDigest(),o=await this.createHashToRelated(e,t),s=[...o.keys()].sort();for(let a of s){i.update(a);let c="",u,l=new Zle(o.get(a)),d=0;for(;l.hasNext();){let h=l.next();++d%3===0&&await this._yield();let f=t.clone(),m="",w=[],b=!1;for(let S of h)if(this.canonicalIssuer.hasId(S)?m+=this.canonicalIssuer.getId(S):(f.hasId(S)||w.push(S),m+=f.getId(S)),c.length!==0&&m>c){b=!0;break}if(!b){for(let S of w){let R=await this.hashNDegreeQuads(S,f);if(m+=f.getId(S),m+=`<${R.hash}>`,f=R.issuer,c.length!==0&&m>c){b=!0;break}}b||(c.length===0||m<c)&&(c=m,u=f)}}i.update(c),t=u}return{hash:await i.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return t.termType!=="BlankNode"?t:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}async createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads,o=0;for(let s of i)++o%100===0&&await this._yield(),await Promise.all([this._addRelatedBlankNodeHash({quad:s,component:s.subject,position:"s",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:s,component:s.object,position:"o",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:s,component:s.graph,position:"g",id:e,issuer:t,hashToRelated:r})]);return r}async _hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){let r=await this.hashFirstDegreeQuads(e),i=t.get(r);i?i.push(e):t.set(r,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if(t.termType!=="BlankNode")return;let r=t.value,i=this.blankNodeInfo.get(r);i?i.quads.add(e):this.blankNodeInfo.set(r,{quads:new Set([e]),hash:null})}async _addRelatedBlankNodeHash({quad:e,component:t,position:r,id:i,issuer:o,hashToRelated:s}){if(!(t.termType==="BlankNode"&&t.value!==i))return;let a=t.value,c=await this.hashRelatedBlankNode(a,e,o,r),u=s.get(c);u?u.push(a):s.set(c,[a])}_componentWithCanonicalId(e){return e.termType==="BlankNode"&&!e.value.startsWith(this.canonicalIssuer.prefix)?{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}:e}async _yield(){return new Promise(e=>setImmediate(e))}};function Xle(n,e){return n.hash<e.hash?-1:n.hash>e.hash?1:0}});var lq=oe((u9e,uq)=>{"use strict";var _le=I2(),$le=RT();uq.exports=class extends $le{constructor(){super(),this.name="URGNA2012",this.createMessageDigest=()=>new _le("sha1")}modifyFirstDegreeComponent(e,t,r){return t.termType!=="BlankNode"?t:r==="graph"?{termType:"BlankNode",value:"_:g"}:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return e.predicate.value}async createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads,o=0;for(let s of i){let a,c;if(s.subject.termType==="BlankNode"&&s.subject.value!==e)c=s.subject.value,a="p";else if(s.object.termType==="BlankNode"&&s.object.value!==e)c=s.object.value,a="r";else continue;++o%100===0&&await this._yield();let u=await this.hashRelatedBlankNode(c,s,t,a),l=r.get(u);l?l.push(c):r.set(u,[c])}return r}}});var DT=oe((d9e,hq)=>{"use strict";var dq=D3(),ede=I2(),tde=ST(),fq=P3();hq.exports=class{constructor({createMessageDigest:e=()=>new ede("sha256"),canonicalIdMap:t=new Map,maxDeepIterations:r=1/0}={}){this.name="URDNA2015",this.blankNodeInfo=new Map,this.canonicalIssuer=new dq("_:c14n",t),this.createMessageDigest=e,this.maxDeepIterations=r,this.quads=null,this.deepIterations=null}main(e){this.deepIterations=new Map,this.quads=e;for(let a of e)this._addBlankNodeQuadInfo({quad:a,component:a.subject}),this._addBlankNodeQuadInfo({quad:a,component:a.object}),this._addBlankNodeQuadInfo({quad:a,component:a.graph});let t=new Map,r=[...this.blankNodeInfo.keys()];for(let a of r)this._hashAndTrackBlankNode({id:a,hashToBlankNodes:t});let i=[...t.keys()].sort(),o=[];for(let a of i){let c=t.get(a);if(c.length>1){o.push(c);continue}let u=c[0];this.canonicalIssuer.getId(u)}for(let a of o){let c=[];for(let u of a){if(this.canonicalIssuer.hasId(u))continue;let l=new dq("_:b");l.getId(u);let d=this.hashNDegreeQuads(u,l);c.push(d)}c.sort(nde);for(let u of c){let l=u.issuer.getOldIds();for(let d of l)this.canonicalIssuer.getId(d)}}let s=[];for(let a of this.quads){let c=fq.serializeQuadComponents(this._componentWithCanonicalId({component:a.subject}),a.predicate,this._componentWithCanonicalId({component:a.object}),this._componentWithCanonicalId({component:a.graph}));s.push(c)}return s.sort(),s.join("")}hashFirstDegreeQuads(e){let t=[],r=this.blankNodeInfo.get(e),i=r.quads;for(let s of i){let a={subject:null,predicate:s.predicate,object:null,graph:null};a.subject=this.modifyFirstDegreeComponent(e,s.subject,"subject"),a.object=this.modifyFirstDegreeComponent(e,s.object,"object"),a.graph=this.modifyFirstDegreeComponent(e,s.graph,"graph"),t.push(fq.serializeQuad(a))}t.sort();let o=this.createMessageDigest();for(let s of t)o.update(s);return r.hash=o.digest(),r.hash}hashRelatedBlankNode(e,t,r,i){let o;this.canonicalIssuer.hasId(e)?o=this.canonicalIssuer.getId(e):r.hasId(e)?o=r.getId(e):o=this.blankNodeInfo.get(e).hash;let s=this.createMessageDigest();return s.update(i),i!=="g"&&s.update(this.getRelatedPredicate(t)),s.update(o),s.digest()}hashNDegreeQuads(e,t){let r=this.deepIterations.get(e)||0;if(r>this.maxDeepIterations)throw new Error(`Maximum deep iterations (${this.maxDeepIterations}) exceeded.`);this.deepIterations.set(e,r+1);let i=this.createMessageDigest(),o=this.createHashToRelated(e,t),s=[...o.keys()].sort();for(let a of s){i.update(a);let c="",u,l=new tde(o.get(a));for(;l.hasNext();){let d=l.next(),h=t.clone(),f="",m=[],w=!1;for(let b of d)if(this.canonicalIssuer.hasId(b)?f+=this.canonicalIssuer.getId(b):(h.hasId(b)||m.push(b),f+=h.getId(b)),c.length!==0&&f>c){w=!0;break}if(!w){for(let b of m){let S=this.hashNDegreeQuads(b,h);if(f+=h.getId(b),f+=`<${S.hash}>`,h=S.issuer,c.length!==0&&f>c){w=!0;break}}w||(c.length===0||f<c)&&(c=f,u=h)}}i.update(c),t=u}return{hash:i.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return t.termType!=="BlankNode"?t:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads;for(let o of i)this._addRelatedBlankNodeHash({quad:o,component:o.subject,position:"s",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:o,component:o.object,position:"o",id:e,issuer:t,hashToRelated:r}),this._addRelatedBlankNodeHash({quad:o,component:o.graph,position:"g",id:e,issuer:t,hashToRelated:r});return r}_hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){let r=this.hashFirstDegreeQuads(e),i=t.get(r);i?i.push(e):t.set(r,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if(t.termType!=="BlankNode")return;let r=t.value,i=this.blankNodeInfo.get(r);i?i.quads.add(e):this.blankNodeInfo.set(r,{quads:new Set([e]),hash:null})}_addRelatedBlankNodeHash({quad:e,component:t,position:r,id:i,issuer:o,hashToRelated:s}){if(!(t.termType==="BlankNode"&&t.value!==i))return;let a=t.value,c=this.hashRelatedBlankNode(a,e,o,r),u=s.get(c);u?u.push(a):s.set(c,[a])}_componentWithCanonicalId({component:e}){return e.termType==="BlankNode"&&!e.value.startsWith(this.canonicalIssuer.prefix)?{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}:e}};function nde(n,e){return n.hash<e.hash?-1:n.hash>e.hash?1:0}});var mq=oe((h9e,pq)=>{"use strict";var rde=I2(),ide=DT();pq.exports=class extends ide{constructor(){super(),this.name="URGNA2012",this.createMessageDigest=()=>new rde("sha1")}modifyFirstDegreeComponent(e,t,r){return t.termType!=="BlankNode"?t:r==="graph"?{termType:"BlankNode",value:"_:g"}:{termType:"BlankNode",value:t.value===e?"_:a":"_:z"}}getRelatedPredicate(e){return e.predicate.value}createHashToRelated(e,t){let r=new Map,i=this.blankNodeInfo.get(e).quads;for(let o of i){let s,a;if(o.subject.termType==="BlankNode"&&o.subject.value!==e)a=o.subject.value,s="p";else if(o.object.termType==="BlankNode"&&o.object.value!==e)a=o.object.value,s="r";else continue;let c=this.hashRelatedBlankNode(a,o,t,s),u=r.get(c);u?u.push(a):r.set(c,[a])}return r}}});var gq=oe(()=>{"use strict"});var wq=oe(Qp=>{"use strict";var ode=RT(),sde=lq(),ade=DT(),cde=mq(),Vp;try{Vp=gq()}catch{}function yq(n){return Array.isArray(n)?n:Qp.NQuads.legacyDatasetToQuads(n)}Qp.NQuads=P3();Qp.IdentifierIssuer=D3();Qp._rdfCanonizeNative=function(n){return n&&(Vp=n),Vp};Qp.canonize=async function(n,e){let t=yq(n,e);if(e.useNative){if(!Vp)throw new Error("rdf-canonize-native not available");if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "useNative".');return new Promise((r,i)=>Vp.canonize(t,e,(o,s)=>o?i(o):r(s)))}if(e.algorithm==="URDNA2015")return new ode(e).main(t);if(e.algorithm==="URGNA2012"){if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "URGNA2012".');return new sde(e).main(t)}throw"algorithm"in e?new Error("Invalid RDF Dataset Canonicalization algorithm: "+e.algorithm):new Error("No RDF Dataset Canonicalization algorithm specified.")};Qp._canonizeSync=function(n,e){let t=yq(n,e);if(e.useNative){if(!Vp)throw new Error("rdf-canonize-native not available");if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "useNative".');return Vp.canonizeSync(t,e)}if(e.algorithm==="URDNA2015")return new ade(e).main(t);if(e.algorithm==="URGNA2012"){if(e.createMessageDigest)throw new Error('"createMessageDigest" cannot be used with "URGNA2012".');return new cde(e).main(t)}throw"algorithm"in e?new Error("Invalid RDF Dataset Canonicalization algorithm: "+e.algorithm):new Error("No RDF Dataset Canonicalization algorithm specified.")}});var k3=oe((y9e,bq)=>{"use strict";bq.exports=wq()});var ls=oe((w9e,Eq)=>{"use strict";var va={};Eq.exports=va;va.isArray=Array.isArray;va.isBoolean=n=>typeof n=="boolean"||Object.prototype.toString.call(n)==="[object Boolean]";va.isDouble=n=>va.isNumber(n)&&(String(n).indexOf(".")!==-1||Math.abs(n)>=1e21);va.isEmptyObject=n=>va.isObject(n)&&Object.keys(n).length===0;va.isNumber=n=>typeof n=="number"||Object.prototype.toString.call(n)==="[object Number]";va.isNumeric=n=>!isNaN(parseFloat(n))&&isFinite(n);va.isObject=n=>Object.prototype.toString.call(n)==="[object Object]";va.isString=n=>typeof n=="string"||Object.prototype.toString.call(n)==="[object String]";va.isUndefined=n=>typeof n>"u"});var Su=oe((b9e,Iq)=>{"use strict";var zp=ls(),Kl={};Iq.exports=Kl;Kl.isSubject=n=>zp.isObject(n)&&!("@value"in n||"@set"in n||"@list"in n)?Object.keys(n).length>1||!("@id"in n):!1;Kl.isSubjectReference=n=>zp.isObject(n)&&Object.keys(n).length===1&&"@id"in n;Kl.isValue=n=>zp.isObject(n)&&"@value"in n;Kl.isList=n=>zp.isObject(n)&&"@list"in n;Kl.isGraph=n=>zp.isObject(n)&&"@graph"in n&&Object.keys(n).filter(e=>e!=="@id"&&e!=="@index").length===1;Kl.isSimpleGraph=n=>Kl.isGraph(n)&&!("@id"in n);Kl.isBlankNode=n=>{if(zp.isObject(n)){if("@id"in n){let e=n["@id"];return!zp.isString(e)||e.indexOf("_:")===0}return Object.keys(n).length===0||!("@value"in n||"@set"in n||"@list"in n)}return!1}});var ds=oe((I9e,Aq)=>{"use strict";Aq.exports=class extends Error{constructor(e="An unspecified JSON-LD error occurred.",t="jsonld.Error",r={}){super(e),this.name=t,this.message=e,this.details=r}}});var fs=oe((A9e,Sq)=>{"use strict";var A2=Su(),zi=ls(),vq=k3().IdentifierIssuer,ude=ds(),lde=/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/,dde=/(?:<[^>]*?>|"[^"]*?"|[^,])+/g,fde=/\s*<([^>]*?)>\s*(?:;\s*(.*))?/,hde=/(.*?)=(?:(?:"([^"]*?)")|([^"]*?))\s*(?:(?:;\s*)|$)/g,pde=/^@[a-zA-Z]+$/,xq={headers:{accept:"application/ld+json, application/json"}},Sn={};Sq.exports=Sn;Sn.IdentifierIssuer=vq;Sn.REGEX_BCP47=lde;Sn.REGEX_KEYWORD=pde;Sn.clone=function(n){if(n&&typeof n=="object"){let e;if(zi.isArray(n)){e=[];for(let t=0;t<n.length;++t)e[t]=Sn.clone(n[t])}else if(n instanceof Map){e=new Map;for(let[t,r]of n)e.set(t,Sn.clone(r))}else if(n instanceof Set){e=new Set;for(let t of n)e.add(Sn.clone(t))}else if(zi.isObject(n)){e={};for(let t in n)e[t]=Sn.clone(n[t])}else e=n.toString();return e}return n};Sn.asArray=function(n){return Array.isArray(n)?n:[n]};Sn.buildHeaders=(n={})=>{if(Object.keys(n).some(t=>t.toLowerCase()==="accept"))throw new RangeError('Accept header may not be specified; only "'+xq.headers.accept+'" is supported.');return Object.assign({Accept:xq.headers.accept},n)};Sn.parseLinkHeader=n=>{let e={},t=n.match(dde);for(let r=0;r<t.length;++r){let i=t[r].match(fde);if(!i)continue;let o={target:i[1]},s=i[2];for(;i=hde.exec(s);)o[i[1]]=i[2]===void 0?i[3]:i[2];let a=o.rel||"";Array.isArray(e[a])?e[a].push(o):e.hasOwnProperty(a)?e[a]=[e[a],o]:e[a]=o}return e};Sn.validateTypeValue=(n,e)=>{if(!zi.isString(n)&&!(zi.isArray(n)&&n.every(t=>zi.isString(t)))){if(e&&zi.isObject(n))switch(Object.keys(n).length){case 0:return;case 1:if("@default"in n&&Sn.asArray(n["@default"]).every(t=>zi.isString(t)))return}throw new ude('Invalid JSON-LD syntax; "@type" value must a string, an array of strings, an empty object, or a default object.',"jsonld.SyntaxError",{code:"invalid type value",value:n})}};Sn.hasProperty=(n,e)=>{if(n.hasOwnProperty(e)){let t=n[e];return!zi.isArray(t)||t.length>0}return!1};Sn.hasValue=(n,e,t)=>{if(Sn.hasProperty(n,e)){let r=n[e],i=A2.isList(r);if(zi.isArray(r)||i){i&&(r=r["@list"]);for(let o=0;o<r.length;++o)if(Sn.compareValues(t,r[o]))return!0}else if(!zi.isArray(t))return Sn.compareValues(t,r)}return!1};Sn.addValue=(n,e,t,r)=>{if(r=r||{},"propertyIsArray"in r||(r.propertyIsArray=!1),"valueIsArray"in r||(r.valueIsArray=!1),"allowDuplicate"in r||(r.allowDuplicate=!0),"prependValue"in r||(r.prependValue=!1),r.valueIsArray)n[e]=t;else if(zi.isArray(t)){t.length===0&&r.propertyIsArray&&!n.hasOwnProperty(e)&&(n[e]=[]),r.prependValue&&(t=t.concat(n[e]),n[e]=[]);for(let i=0;i<t.length;++i)Sn.addValue(n,e,t[i],r)}else if(n.hasOwnProperty(e)){let i=!r.allowDuplicate&&Sn.hasValue(n,e,t);!zi.isArray(n[e])&&(!i||r.propertyIsArray)&&(n[e]=[n[e]]),i||(r.prependValue?n[e].unshift(t):n[e].push(t))}else n[e]=r.propertyIsArray?[t]:t};Sn.getValues=(n,e)=>[].concat(n[e]||[]);Sn.removeProperty=(n,e)=>{delete n[e]};Sn.removeValue=(n,e,t,r)=>{r=r||{},"propertyIsArray"in r||(r.propertyIsArray=!1);let i=Sn.getValues(n,e).filter(o=>!Sn.compareValues(o,t));i.length===0?Sn.removeProperty(n,e):i.length===1&&!r.propertyIsArray?n[e]=i[0]:n[e]=i};Sn.relabelBlankNodes=(n,e)=>{e=e||{};let t=e.issuer||new vq("_:b");return M3(t,n)};Sn.compareValues=(n,e)=>n===e||A2.isValue(n)&&A2.isValue(e)&&n["@value"]===e["@value"]&&n["@type"]===e["@type"]&&n["@language"]===e["@language"]&&n["@index"]===e["@index"]?!0:zi.isObject(n)&&"@id"in n&&zi.isObject(e)&&"@id"in e?n["@id"]===e["@id"]:!1;Sn.compareShortestLeast=(n,e)=>n.length<e.length?-1:e.length<n.length?1:n===e?0:n<e?-1:1;function M3(n,e){if(zi.isArray(e))for(let t=0;t<e.length;++t)e[t]=M3(n,e[t]);else if(A2.isList(e))e["@list"]=M3(n,e["@list"]);else if(zi.isObject(e)){A2.isBlankNode(e)&&(e["@id"]=n.getId(e["@id"]));let t=Object.keys(e).sort();for(let r=0;r<t.length;++r){let i=t[r];i!=="@id"&&(e[i]=M3(n,e[i]))}}return e}});var v2=oe((x9e,Cq)=>{"use strict";var Ac="http://www.w3.org/1999/02/22-rdf-syntax-ns#",x2="http://www.w3.org/2001/XMLSchema#";Cq.exports={LINK_HEADER_REL:"http://www.w3.org/ns/json-ld#context",LINK_HEADER_CONTEXT:"http://www.w3.org/ns/json-ld#context",RDF:Ac,RDF_LIST:Ac+"List",RDF_FIRST:Ac+"first",RDF_REST:Ac+"rest",RDF_NIL:Ac+"nil",RDF_TYPE:Ac+"type",RDF_PLAIN_LITERAL:Ac+"PlainLiteral",RDF_XML_LITERAL:Ac+"XMLLiteral",RDF_JSON_LITERAL:Ac+"JSON",RDF_OBJECT:Ac+"object",RDF_LANGSTRING:Ac+"langString",XSD:x2,XSD_BOOLEAN:x2+"boolean",XSD_DOUBLE:x2+"double",XSD_INTEGER:x2+"integer",XSD_STRING:x2+"string"}});var TT=oe((S9e,Lq)=>{"use strict";Lq.exports=class{constructor(){this._requests={}}wrapLoader(e){let t=this;return t._loader=e,function(){return t.add.apply(t,arguments)}}async add(e){let t=this._requests[e];if(t)return Promise.resolve(t);t=this._requests[e]=this._loader(e);try{return await t}finally{delete this._requests[e]}}}});var Cu=oe((C9e,Rq)=>{"use strict";var O3=ls(),Yi={};Rq.exports=Yi;Yi.parsers={simple:{keys:["href","scheme","authority","path","query","fragment"],regex:/^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/},full:{keys:["href","protocol","scheme","authority","auth","user","password","hostname","port","path","directory","file","query","fragment"],regex:/^(([a-zA-Z][a-zA-Z0-9+-.]*):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:(((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/}};Yi.parse=(n,e)=>{let t={},r=Yi.parsers[e||"full"],i=r.regex.exec(n),o=r.keys.length;for(;o--;)t[r.keys[o]]=i[o]===void 0?null:i[o];return(t.scheme==="https"&&t.port==="443"||t.scheme==="http"&&t.port==="80")&&(t.href=t.href.replace(":"+t.port,""),t.authority=t.authority.replace(":"+t.port,""),t.port=null),t.normalizedPath=Yi.removeDotSegments(t.path),t};Yi.prependBase=(n,e)=>{if(n===null||Yi.isAbsolute(e))return e;(!n||O3.isString(n))&&(n=Yi.parse(n||""));let t=Yi.parse(e),r={protocol:n.protocol||""};if(t.authority!==null)r.authority=t.authority,r.path=t.path,r.query=t.query;else if(r.authority=n.authority,t.path==="")r.path=n.path,t.query!==null?r.query=t.query:r.query=n.query;else{if(t.path.indexOf("/")===0)r.path=t.path;else{let o=n.path;o=o.substr(0,o.lastIndexOf("/")+1),(o.length>0||n.authority)&&o.substr(-1)!=="/"&&(o+="/"),o+=t.path,r.path=o}r.query=t.query}t.path!==""&&(r.path=Yi.removeDotSegments(r.path));let i=r.protocol;return r.authority!==null&&(i+="//"+r.authority),i+=r.path,r.query!==null&&(i+="?"+r.query),t.fragment!==null&&(i+="#"+t.fragment),i===""&&(i="./"),i};Yi.removeBase=(n,e)=>{if(n===null)return e;(!n||O3.isString(n))&&(n=Yi.parse(n||""));let t="";if(n.href!==""?t+=(n.protocol||"")+"//"+(n.authority||""):e.indexOf("//")&&(t+="//"),e.indexOf(t)!==0)return e;let r=Yi.parse(e.substr(t.length)),i=n.normalizedPath.split("/"),o=r.normalizedPath.split("/"),s=r.fragment||r.query?0:1;for(;i.length>0&&o.length>s&&i[0]===o[0];)i.shift(),o.shift();let a="";if(i.length>0){i.pop();for(let c=0;c<i.length;++c)a+="../"}return a+=o.join("/"),r.query!==null&&(a+="?"+r.query),r.fragment!==null&&(a+="#"+r.fragment),a===""&&(a="./"),a};Yi.removeDotSegments=n=>{if(n.length===0)return"";let e=n.split("/"),t=[];for(;e.length>0;){let r=e.shift(),i=e.length===0;if(r==="."){i&&t.push("");continue}if(r===".."){t.pop(),i&&t.push("");continue}t.push(r)}return n[0]==="/"&&t.length>0&&t[0]!==""&&t.unshift(""),t.length===1&&t[0]===""?"/":t.join("/")};var mde=/^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/;Yi.isAbsolute=n=>O3.isString(n)&&mde.test(n);Yi.isRelative=n=>O3.isString(n)});var Tq=oe((L9e,Dq)=>{"use strict";var{parseLinkHeader:gde,buildHeaders:yde}=fs(),{LINK_HEADER_CONTEXT:wde}=v2(),S2=ds(),bde=TT(),{prependBase:Ede}=Cu(),Ide=/(^|(\r\n))link:/i;Dq.exports=({secure:n,headers:e={},xhr:t}={headers:{}})=>{return e=yde(e),new bde().wrapLoader(i);async function i(o){if(o.indexOf("http:")!==0&&o.indexOf("https:")!==0)throw new S2('URL could not be dereferenced; only "http" and "https" URLs are supported.',"jsonld.InvalidUrl",{code:"loading document failed",url:o});if(n&&o.indexOf("https")!==0)throw new S2(`URL could not be dereferenced; secure mode is enabled and the URL's scheme is not "https".`,"jsonld.InvalidUrl",{code:"loading document failed",url:o});let s;try{s=await Ade(t,o,e)}catch(d){throw new S2("URL could not be dereferenced, an error occurred.","jsonld.LoadDocumentError",{code:"loading document failed",url:o,cause:d})}if(s.status>=400)throw new S2("URL could not be dereferenced: "+s.statusText,"jsonld.LoadDocumentError",{code:"loading document failed",url:o,httpStatusCode:s.status});let a={contextUrl:null,documentUrl:o,document:s.response},c=null,u=s.getResponseHeader("Content-Type"),l;if(Ide.test(s.getAllResponseHeaders())&&(l=s.getResponseHeader("Link")),l&&u!=="application/ld+json"){let d=gde(l),h=d[wde];if(Array.isArray(h))throw new S2("URL could not be dereferenced, it has more than one associated HTTP Link Header.","jsonld.InvalidUrl",{code:"multiple context link headers",url:o});h&&(a.contextUrl=h.target),c=d.alternate,c&&c.type=="application/ld+json"&&!(u||"").match(/^application\/(\w*\+)?json$/)&&(a=await i(Ede(o,c.target)))}return a}};function Ade(n,e,t){n=n||XMLHttpRequest;let r=new n;return new Promise((i,o)=>{r.onload=()=>i(r),r.onerror=s=>o(s),r.open("GET",e,!0);for(let s in t)r.setRequestHeader(s,t[s]);r.send()})}});var Pq=oe((R9e,Bq)=>{"use strict";var xde=Tq(),BT={};Bq.exports=BT;BT.setupDocumentLoaders=function(n){typeof XMLHttpRequest<"u"&&(n.documentLoaders.xhr=xde,n.useDocumentLoader("xhr"))};BT.setupGlobals=function(n){typeof globalThis.JsonLdProcessor>"u"&&Object.defineProperty(globalThis,"JsonLdProcessor",{writable:!0,enumerable:!1,configurable:!0,value:n.JsonLdProcessor})}});var Mq=oe((D9e,kq)=>{"use strict";kq.exports=function(n){n.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}});var Fq=oe((T9e,Oq)=>{"use strict";Oq.exports=gn;gn.Node=Yp;gn.create=gn;function gn(n){var e=this;if(e instanceof gn||(e=new gn),e.tail=null,e.head=null,e.length=0,n&&typeof n.forEach=="function")n.forEach(function(i){e.push(i)});else if(arguments.length>0)for(var t=0,r=arguments.length;t<r;t++)e.push(arguments[t]);return e}gn.prototype.removeNode=function(n){if(n.list!==this)throw new Error("removing node which does not belong to this list");var e=n.next,t=n.prev;return e&&(e.prev=t),t&&(t.next=e),n===this.head&&(this.head=e),n===this.tail&&(this.tail=t),n.list.length--,n.next=null,n.prev=null,n.list=null,e};gn.prototype.unshiftNode=function(n){if(n!==this.head){n.list&&n.list.removeNode(n);var e=this.head;n.list=this,n.next=e,e&&(e.prev=n),this.head=n,this.tail||(this.tail=n),this.length++}};gn.prototype.pushNode=function(n){if(n!==this.tail){n.list&&n.list.removeNode(n);var e=this.tail;n.list=this,n.prev=e,e&&(e.next=n),this.tail=n,this.head||(this.head=n),this.length++}};gn.prototype.push=function(){for(var n=0,e=arguments.length;n<e;n++)Sde(this,arguments[n]);return this.length};gn.prototype.unshift=function(){for(var n=0,e=arguments.length;n<e;n++)Cde(this,arguments[n]);return this.length};gn.prototype.pop=function(){if(this.tail){var n=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,n}};gn.prototype.shift=function(){if(this.head){var n=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,n}};gn.prototype.forEach=function(n,e){e=e||this;for(var t=this.head,r=0;t!==null;r++)n.call(e,t.value,r,this),t=t.next};gn.prototype.forEachReverse=function(n,e){e=e||this;for(var t=this.tail,r=this.length-1;t!==null;r--)n.call(e,t.value,r,this),t=t.prev};gn.prototype.get=function(n){for(var e=0,t=this.head;t!==null&&e<n;e++)t=t.next;if(e===n&&t!==null)return t.value};gn.prototype.getReverse=function(n){for(var e=0,t=this.tail;t!==null&&e<n;e++)t=t.prev;if(e===n&&t!==null)return t.value};gn.prototype.map=function(n,e){e=e||this;for(var t=new gn,r=this.head;r!==null;)t.push(n.call(e,r.value,this)),r=r.next;return t};gn.prototype.mapReverse=function(n,e){e=e||this;for(var t=new gn,r=this.tail;r!==null;)t.push(n.call(e,r.value,this)),r=r.prev;return t};gn.prototype.reduce=function(n,e){var t,r=this.head;if(arguments.length>1)t=e;else if(this.head)r=this.head.next,t=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var i=0;r!==null;i++)t=n(t,r.value,i),r=r.next;return t};gn.prototype.reduceReverse=function(n,e){var t,r=this.tail;if(arguments.length>1)t=e;else if(this.tail)r=this.tail.prev,t=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(var i=this.length-1;r!==null;i--)t=n(t,r.value,i),r=r.prev;return t};gn.prototype.toArray=function(){for(var n=new Array(this.length),e=0,t=this.head;t!==null;e++)n[e]=t.value,t=t.next;return n};gn.prototype.toArrayReverse=function(){for(var n=new Array(this.length),e=0,t=this.tail;t!==null;e++)n[e]=t.value,t=t.prev;return n};gn.prototype.slice=function(n,e){e=e||this.length,e<0&&(e+=this.length),n=n||0,n<0&&(n+=this.length);var t=new gn;if(e<n||e<0)return t;n<0&&(n=0),e>this.length&&(e=this.length);for(var r=0,i=this.head;i!==null&&r<n;r++)i=i.next;for(;i!==null&&r<e;r++,i=i.next)t.push(i.value);return t};gn.prototype.sliceReverse=function(n,e){e=e||this.length,e<0&&(e+=this.length),n=n||0,n<0&&(n+=this.length);var t=new gn;if(e<n||e<0)return t;n<0&&(n=0),e>this.length&&(e=this.length);for(var r=this.length,i=this.tail;i!==null&&r>e;r--)i=i.prev;for(;i!==null&&r>n;r--,i=i.prev)t.push(i.value);return t};gn.prototype.splice=function(n,e,...t){n>this.length&&(n=this.length-1),n<0&&(n=this.length+n);for(var r=0,i=this.head;i!==null&&r<n;r++)i=i.next;for(var o=[],r=0;i&&r<e;r++)o.push(i.value),i=this.removeNode(i);i===null&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev);for(var r=0;r<t.length;r++)i=vde(this,i,t[r]);return o};gn.prototype.reverse=function(){for(var n=this.head,e=this.tail,t=n;t!==null;t=t.prev){var r=t.prev;t.prev=t.next,t.next=r}return this.head=e,this.tail=n,this};function vde(n,e,t){var r=e===n.head?new Yp(t,null,e,n):new Yp(t,e,e.next,n);return r.next===null&&(n.tail=r),r.prev===null&&(n.head=r),n.length++,r}function Sde(n,e){n.tail=new Yp(e,n.tail,null,n),n.head||(n.head=n.tail),n.length++}function Cde(n,e){n.head=new Yp(e,null,n.head,n),n.tail||(n.tail=n.head),n.length++}function Yp(n,e,t,r){if(!(this instanceof Yp))return new Yp(n,e,t,r);this.list=r,this.value=n,e?(e.next=this,this.prev=e):this.prev=null,t?(t.prev=this,this.next=t):this.next=null}try{Mq()(gn)}catch{}});var FT=oe((B9e,Hq)=>{"use strict";var Lde=Fq(),jp=Symbol("max"),ql=Symbol("length"),kg=Symbol("lengthCalculator"),L2=Symbol("allowStale"),Wp=Symbol("maxAge"),Jl=Symbol("dispose"),Nq=Symbol("noDisposeOnSet"),ai=Symbol("lruList"),xc=Symbol("cache"),Gq=Symbol("updateAgeOnGet"),PT=()=>1,MT=class{constructor(e){if(typeof e=="number"&&(e={max:e}),e||(e={}),e.max&&(typeof e.max!="number"||e.max<0))throw new TypeError("max must be a non-negative number");let t=this[jp]=e.max||1/0,r=e.length||PT;if(this[kg]=typeof r!="function"?PT:r,this[L2]=e.stale||!1,e.maxAge&&typeof e.maxAge!="number")throw new TypeError("maxAge must be a number");this[Wp]=e.maxAge||0,this[Jl]=e.dispose,this[Nq]=e.noDisposeOnSet||!1,this[Gq]=e.updateAgeOnGet||!1,this.reset()}set max(e){if(typeof e!="number"||e<0)throw new TypeError("max must be a non-negative number");this[jp]=e||1/0,C2(this)}get max(){return this[jp]}set allowStale(e){this[L2]=!!e}get allowStale(){return this[L2]}set maxAge(e){if(typeof e!="number")throw new TypeError("maxAge must be a non-negative number");this[Wp]=e,C2(this)}get maxAge(){return this[Wp]}set lengthCalculator(e){typeof e!="function"&&(e=PT),e!==this[kg]&&(this[kg]=e,this[ql]=0,this[ai].forEach(t=>{t.length=this[kg](t.value,t.key),this[ql]+=t.length})),C2(this)}get lengthCalculator(){return this[kg]}get length(){return this[ql]}get itemCount(){return this[ai].length}rforEach(e,t){t=t||this;for(let r=this[ai].tail;r!==null;){let i=r.prev;Uq(this,e,r,t),r=i}}forEach(e,t){t=t||this;for(let r=this[ai].head;r!==null;){let i=r.next;Uq(this,e,r,t),r=i}}keys(){return this[ai].toArray().map(e=>e.key)}values(){return this[ai].toArray().map(e=>e.value)}reset(){this[Jl]&&this[ai]&&this[ai].length&&this[ai].forEach(e=>this[Jl](e.key,e.value)),this[xc]=new Map,this[ai]=new Lde,this[ql]=0}dump(){return this[ai].map(e=>F3(this,e)?!1:{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}).toArray().filter(e=>e)}dumpLru(){return this[ai]}set(e,t,r){if(r=r||this[Wp],r&&typeof r!="number")throw new TypeError("maxAge must be a number");let i=r?Date.now():0,o=this[kg](t,e);if(this[xc].has(e)){if(o>this[jp])return Mg(this,this[xc].get(e)),!1;let c=this[xc].get(e).value;return this[Jl]&&(this[Nq]||this[Jl](e,c.value)),c.now=i,c.maxAge=r,c.value=t,this[ql]+=o-c.length,c.length=o,this.get(e),C2(this),!0}let s=new OT(e,t,o,i,r);return s.length>this[jp]?(this[Jl]&&this[Jl](e,t),!1):(this[ql]+=s.length,this[ai].unshift(s),this[xc].set(e,this[ai].head),C2(this),!0)}has(e){if(!this[xc].has(e))return!1;let t=this[xc].get(e).value;return!F3(this,t)}get(e){return kT(this,e,!0)}peek(e){return kT(this,e,!1)}pop(){let e=this[ai].tail;return e?(Mg(this,e),e.value):null}del(e){Mg(this,this[xc].get(e))}load(e){this.reset();let t=Date.now();for(let r=e.length-1;r>=0;r--){let i=e[r],o=i.e||0;if(o===0)this.set(i.k,i.v);else{let s=o-t;s>0&&this.set(i.k,i.v,s)}}}prune(){this[xc].forEach((e,t)=>kT(this,t,!1))}},kT=(n,e,t)=>{let r=n[xc].get(e);if(r){let i=r.value;if(F3(n,i)){if(Mg(n,r),!n[L2])return}else t&&(n[Gq]&&(r.value.now=Date.now()),n[ai].unshiftNode(r));return i.value}},F3=(n,e)=>{if(!e||!e.maxAge&&!n[Wp])return!1;let t=Date.now()-e.now;return e.maxAge?t>e.maxAge:n[Wp]&&t>n[Wp]},C2=n=>{if(n[ql]>n[jp])for(let e=n[ai].tail;n[ql]>n[jp]&&e!==null;){let t=e.prev;Mg(n,e),e=t}},Mg=(n,e)=>{if(e){let t=e.value;n[Jl]&&n[Jl](t.key,t.value),n[ql]-=t.length,n[xc].delete(t.key),n[ai].removeNode(e)}},OT=class{constructor(e,t,r,i,o){this.key=e,this.value=t,this.length=r,this.now=i,this.maxAge=o||0}},Uq=(n,e,t,r)=>{let i=t.value;F3(n,i)&&(Mg(n,t),n[L2]||(i=void 0)),i&&e.call(r,i.value,i.key,n)};Hq.exports=MT});var Jq=oe((k9e,Kq)=>{"use strict";var Rde=FT(),Dde=10;Kq.exports=class{constructor({document:e}){this.document=e,this.cache=new Rde({max:Dde})}getProcessed(e){return this.cache.get(e)}setProcessed(e,t){this.cache.set(e,t)}}});var zq=oe((O9e,Qq)=>{"use strict";var{isArray:NT,isObject:D2,isString:N3}=ls(),{asArray:Tde}=fs(),{prependBase:UT}=Cu(),R2=ds(),qq=Jq(),Vq=10;Qq.exports=class{constructor({sharedCache:e}){this.perOpCache=new Map,this.sharedCache=e}async resolve({activeCtx:e,context:t,documentLoader:r,base:i,cycles:o=new Set}){t&&D2(t)&&t["@context"]&&(t=t["@context"]),t=Tde(t);let s=[];for(let a of t){if(N3(a)){let l=this._get(a);l||(l=await this._resolveRemoteContext({activeCtx:e,url:a,documentLoader:r,base:i,cycles:o})),NT(l)?s.push(...l):s.push(l);continue}if(a===null){s.push(new qq({document:null}));continue}D2(a)||Bde(t);let c=JSON.stringify(a),u=this._get(c);u||(u=new qq({document:a}),this._cacheResolvedContext({key:c,resolved:u,tag:"static"})),s.push(u)}return s}_get(e){let t=this.perOpCache.get(e);if(!t){let r=this.sharedCache.get(e);r&&(t=r.get("static"),t&&this.perOpCache.set(e,t))}return t}_cacheResolvedContext({key:e,resolved:t,tag:r}){if(this.perOpCache.set(e,t),r!==void 0){let i=this.sharedCache.get(e);i||(i=new Map,this.sharedCache.set(e,i)),i.set(r,t)}return t}async _resolveRemoteContext({activeCtx:e,url:t,documentLoader:r,base:i,cycles:o}){t=UT(i,t);let{context:s,remoteDoc:a}=await this._fetchContext({activeCtx:e,url:t,documentLoader:r,cycles:o});i=a.documentUrl||t,GT({context:s,base:i});let c=await this.resolve({activeCtx:e,context:s,documentLoader:r,base:i,cycles:o});return this._cacheResolvedContext({key:t,resolved:c,tag:a.tag}),c}async _fetchContext({activeCtx:e,url:t,documentLoader:r,cycles:i}){if(i.size>Vq)throw new R2("Maximum number of @context URLs exceeded.","jsonld.ContextUrlError",{code:e.processingMode==="json-ld-1.0"?"loading remote context failed":"context overflow",max:Vq});if(i.has(t))throw new R2("Cyclical @context URLs detected.","jsonld.ContextUrlError",{code:e.processingMode==="json-ld-1.0"?"recursive context inclusion":"context overflow",url:t});i.add(t);let o,s;try{s=await r(t),o=s.document||null,N3(o)&&(o=JSON.parse(o))}catch(a){throw new R2(`Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context. URL: "${t}".`,"jsonld.InvalidUrl",{code:"loading remote context failed",url:t,cause:a})}if(!D2(o))throw new R2(`Dereferencing a URL did not result in a JSON object. The response was valid JSON, but it was not a JSON object. URL: "${t}".`,"jsonld.InvalidUrl",{code:"invalid remote context",url:t});return"@context"in o?o={"@context":o["@context"]}:o={"@context":{}},s.contextUrl&&(NT(o["@context"])||(o["@context"]=[o["@context"]]),o["@context"].push(s.contextUrl)),{context:o,remoteDoc:s}}};function Bde(n){throw new R2("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:n})}function GT({context:n,base:e}){if(!n)return;let t=n["@context"];if(N3(t)){n["@context"]=UT(e,t);return}if(NT(t)){for(let r=0;r<t.length;++r){let i=t[r];if(N3(i)){t[r]=UT(e,i);continue}D2(i)&>({context:{"@context":i},base:e})}return}if(D2(t))for(let r in t)GT({context:t[r],base:e})}});var jq=oe((F9e,Yq)=>{"use strict";Yq.exports=k3().NQuads});var Og=oe((N9e,Xq)=>{"use strict";var HT=ds(),{isArray:Pde}=ls(),{asArray:Wq}=fs(),qs={};Xq.exports=qs;qs.defaultEventHandler=null;qs.setupEventHandler=({options:n={}})=>{let e=[].concat(n.safe?qs.safeEventHandler:[],n.eventHandler?Wq(n.eventHandler):[],qs.defaultEventHandler?qs.defaultEventHandler:[]);return e.length===0?null:e};qs.handleEvent=({event:n,options:e})=>{Zq({event:n,handlers:e.eventHandler})};function Zq({event:n,handlers:e}){let t=!0;for(let r=0;t&&r<e.length;++r){t=!1;let i=e[r];if(Pde(i))t=Zq({event:n,handlers:i});else if(typeof i=="function")i({event:n,next:()=>{t=!0}});else if(typeof i=="object")n.code in i?i[n.code]({event:n,next:()=>{t=!0}}):t=!0;else throw new HT("Invalid event handler.","jsonld.InvalidEventHandler",{event:n})}return t}var kde=new Set(["empty object","free-floating scalar","invalid @language value","invalid property","null @id value","null @value value","object with only @id","object with only @language","object with only @list","object with only @value","relative @id reference","relative @type reference","relative @vocab reference","reserved @id value","reserved @reverse value","reserved term","blank node predicate","relative graph reference","relative object reference","relative predicate reference","relative subject reference","rdfDirection not set"]);qs.safeEventHandler=function({event:e,next:t}){if(e.level==="warning"&&kde.has(e.code))throw new HT("Safe mode validation error.","jsonld.ValidationError",{event:e});t()};qs.logEventHandler=function({event:e,next:t}){console.log(`EVENT: ${e.message}`,{event:e}),t()};qs.logWarningEventHandler=function({event:e,next:t}){e.level==="warning"&&console.warn(`WARNING: ${e.message}`,{event:e}),t()};qs.unhandledEventHandler=function({event:e}){throw new HT("No handler for event.","jsonld.UnhandledEvent",{event:e})};qs.setDefaultEventHandler=function({eventHandler:n}={}){qs.defaultEventHandler=n?Wq(n):null}});var Of=oe((U9e,tV)=>{"use strict";var _q=fs(),ht=ds(),{isArray:$q,isObject:Mf,isString:hs,isUndefined:Mde}=ls(),{isAbsolute:Zp,isRelative:Ode,prependBase:T2}=Cu(),{handleEvent:Ng}=Og(),{REGEX_BCP47:Fde,REGEX_KEYWORD:G3,asArray:eV,compareShortestLeast:Nde}=fs(),U3=new Map,Ude=1e4,nr={};tV.exports=nr;nr.process=async({activeCtx:n,localCtx:e,options:t,propagate:r=!0,overrideProtected:i=!1,cycles:o=new Set})=>{if(Mf(e)&&"@context"in e&&$q(e["@context"])&&(e=e["@context"]),eV(e).length===0)return n;let a=[],c=[({event:h,next:f})=>{a.push(h),f()}];t.eventHandler&&c.push(t.eventHandler);let u=t;t={...t,eventHandler:c};let l=await t.contextResolver.resolve({activeCtx:n,context:e,documentLoader:t.documentLoader,base:t.base});Mf(l[0].document)&&typeof l[0].document["@propagate"]=="boolean"&&(r=l[0].document["@propagate"]);let d=n;!r&&!d.previousContext&&(d=d.clone(),d.previousContext=n);for(let h of l){let{document:f}=h;if(n=d,f===null){if(!i&&Object.keys(n.protected).length!==0)throw new ht("Tried to nullify a context with protected terms outside of a term definition.","jsonld.SyntaxError",{code:"invalid context nullification"});d=n=nr.getInitialContext(t).clone();continue}let m=h.getProcessed(n);if(m){if(u.eventHandler)for(let b of m.events)Ng({event:b,options:u});d=n=m.context;continue}if(Mf(f)&&"@context"in f&&(f=f["@context"]),!Mf(f))throw new ht("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:f});d=d.clone();let w=new Map;if("@version"in f){if(f["@version"]!==1.1)throw new ht("Unsupported JSON-LD version: "+f["@version"],"jsonld.UnsupportedVersion",{code:"invalid @version value",context:f});if(n.processingMode&&n.processingMode==="json-ld-1.0")throw new ht("@version: "+f["@version"]+" not compatible with "+n.processingMode,"jsonld.ProcessingModeConflict",{code:"processing mode conflict",context:f});d.processingMode="json-ld-1.1",d["@version"]=f["@version"],w.set("@version",!0)}if(d.processingMode=d.processingMode||n.processingMode,"@base"in f){let b=f["@base"];if(!(b===null||Zp(b)))if(Ode(b))b=T2(d["@base"],b);else throw new ht('Invalid JSON-LD syntax; the value of "@base" in a @context must be an absolute IRI, a relative IRI, or null.',"jsonld.SyntaxError",{code:"invalid base IRI",context:f});d["@base"]=b,w.set("@base",!0)}if("@vocab"in f){let b=f["@vocab"];if(b===null)delete d["@vocab"];else if(hs(b)){if(!Zp(b)&&nr.processingMode(d,1))throw new ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be an absolute IRI.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:f});{let S=Fg(d,b,{vocab:!0,base:!0},void 0,void 0,t);Zp(S)||t.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"relative @vocab reference",level:"warning",message:"Relative @vocab reference found.",details:{vocab:S}},options:t}),d["@vocab"]=S}}else throw new ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:f});w.set("@vocab",!0)}if("@language"in f){let b=f["@language"];if(b===null)delete d["@language"];else if(hs(b))b.match(Fde)||t.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:b}},options:t}),d["@language"]=b.toLowerCase();else throw new ht('Invalid JSON-LD syntax; the value of "@language" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid default language",context:f});w.set("@language",!0)}if("@direction"in f){let b=f["@direction"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @direction not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context member",context:f});if(b===null)delete d["@direction"];else{if(b!=="ltr"&&b!=="rtl")throw new ht('Invalid JSON-LD syntax; the value of "@direction" in a @context must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:f});d["@direction"]=b}w.set("@direction",!0)}if("@propagate"in f){let b=f["@propagate"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @propagate not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:f});if(typeof b!="boolean")throw new ht("Invalid JSON-LD syntax; @propagate value must be a boolean.","jsonld.SyntaxError",{code:"invalid @propagate value",context:e});w.set("@propagate",!0)}if("@import"in f){let b=f["@import"];if(n.processingMode==="json-ld-1.0")throw new ht("Invalid JSON-LD syntax; @import not compatible with "+n.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:f});if(!hs(b))throw new ht("Invalid JSON-LD syntax; @import must be a string.","jsonld.SyntaxError",{code:"invalid @import value",context:e});let S=await t.contextResolver.resolve({activeCtx:n,context:b,documentLoader:t.documentLoader,base:t.base});if(S.length!==1)throw new ht("Invalid JSON-LD syntax; @import must reference a single context.","jsonld.SyntaxError",{code:"invalid remote context",context:e});let R=S[0].getProcessed(n);if(R)f=R;else{let G=S[0].document;if("@import"in G)throw new ht("Invalid JSON-LD syntax: imported context must not include @import.","jsonld.SyntaxError",{code:"invalid context entry",context:e});for(let U in G)f.hasOwnProperty(U)||(f[U]=G[U]);S[0].setProcessed(n,f)}w.set("@import",!0)}w.set("@protected",f["@protected"]||!1);for(let b in f)if(nr.createTermDefinition({activeCtx:d,localCtx:f,term:b,defined:w,options:t,overrideProtected:i}),Mf(f[b])&&"@context"in f[b]){let S=f[b]["@context"],R=!0;if(hs(S)){let G=T2(t.base,S);o.has(G)?R=!1:o.add(G)}if(R)try{await nr.process({activeCtx:d.clone(),localCtx:f[b]["@context"],overrideProtected:!0,options:t,cycles:o})}catch{throw new ht("Invalid JSON-LD syntax; invalid scoped context.","jsonld.SyntaxError",{code:"invalid scoped context",context:f[b]["@context"],term:b})}}h.setProcessed(n,{context:d,events:a})}return d};nr.createTermDefinition=({activeCtx:n,localCtx:e,term:t,defined:r,options:i,overrideProtected:o=!1})=>{if(r.has(t)){if(r.get(t))return;throw new ht("Cyclical context definition detected.","jsonld.CyclicalContext",{code:"cyclic IRI mapping",context:e,term:t})}r.set(t,!1);let s;if(e.hasOwnProperty(t)&&(s=e[t]),t==="@type"&&Mf(s)&&(s["@container"]||"@set")==="@set"&&nr.processingMode(n,1.1)){let f=["@container","@id","@protected"],m=Object.keys(s);if(m.length===0||m.some(w=>!f.includes(w)))throw new ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:e,term:t})}else{if(nr.isKeyword(t))throw new ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:e,term:t});if(t.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved term",level:"warning",message:'Terms beginning with "@" are reserved for future use and dropped.',details:{term:t}},options:i});return}else if(t==="")throw new ht("Invalid JSON-LD syntax; a term cannot be an empty string.","jsonld.SyntaxError",{code:"invalid term definition",context:e})}let a=n.mappings.get(t);n.mappings.has(t)&&n.mappings.delete(t);let c=!1;if((hs(s)||s===null)&&(c=!0,s={"@id":s}),!Mf(s))throw new ht("Invalid JSON-LD syntax; @context term values must be strings or objects.","jsonld.SyntaxError",{code:"invalid term definition",context:e});let u={};n.mappings.set(t,u),u.reverse=!1;let l=["@container","@id","@language","@reverse","@type"];nr.processingMode(n,1.1)&&l.push("@context","@direction","@index","@nest","@prefix","@protected");for(let f in s)if(!l.includes(f))throw new ht("Invalid JSON-LD syntax; a term definition must not contain "+f,"jsonld.SyntaxError",{code:"invalid term definition",context:e});let d=t.indexOf(":");if(u._termHasColon=d>0,"@reverse"in s){if("@id"in s)throw new ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @id.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});if("@nest"in s)throw new ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @nest.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});let f=s["@reverse"];if(!hs(f))throw new ht("Invalid JSON-LD syntax; a @context @reverse value must be a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(f.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved @reverse value",level:"warning",message:'@reverse values beginning with "@" are reserved for future use and dropped.',details:{reverse:f}},options:i}),a?n.mappings.set(t,a):n.mappings.delete(t);return}let m=Fg(n,f,{vocab:!0,base:!1},e,r,i);if(!Zp(m))throw new ht("Invalid JSON-LD syntax; a @context @reverse value must be an absolute IRI or a blank node identifier.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});u["@id"]=m,u.reverse=!0}else if("@id"in s){let f=s["@id"];if(f&&!hs(f))throw new ht("Invalid JSON-LD syntax; a @context @id value must be an array of strings or a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(f===null)u["@id"]=null;else if(!nr.isKeyword(f)&&f.match(G3)){i.eventHandler&&Ng({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:'@id values beginning with "@" are reserved for future use and dropped.',details:{id:f}},options:i}),a?n.mappings.set(t,a):n.mappings.delete(t);return}else if(f!==t){if(f=Fg(n,f,{vocab:!0,base:!1},e,r,i),!Zp(f)&&!nr.isKeyword(f))throw new ht("Invalid JSON-LD syntax; a @context @id value must be an absolute IRI, a blank node identifier, or a keyword.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e});if(t.match(/(?::[^:])|\//)){let m=new Map(r).set(t,!0);if(Fg(n,t,{vocab:!0,base:!1},e,m,i)!==f)throw new ht("Invalid JSON-LD syntax; term in form of IRI must expand to definition.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e})}u["@id"]=f,u._prefix=c&&!u._termHasColon&&f.match(/[:\/\?#\[\]@]$/)!==null}}if(!("@id"in u))if(u._termHasColon){let f=t.substr(0,d);if(e.hasOwnProperty(f)&&nr.createTermDefinition({activeCtx:n,localCtx:e,term:f,defined:r,options:i}),n.mappings.has(f)){let m=t.substr(d+1);u["@id"]=n.mappings.get(f)["@id"]+m}else u["@id"]=t}else if(t==="@type")u["@id"]=t;else{if(!("@vocab"in n))throw new ht("Invalid JSON-LD syntax; @context terms must define an @id.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:e,term:t});u["@id"]=n["@vocab"]+t}if((s["@protected"]===!0||r.get("@protected")===!0&&s["@protected"]!==!1)&&(n.protected[t]=!0,u.protected=!0),r.set(t,!0),"@type"in s){let f=s["@type"];if(!hs(f))throw new ht("Invalid JSON-LD syntax; an @context @type value must be a string.","jsonld.SyntaxError",{code:"invalid type mapping",context:e});if(f==="@json"||f==="@none"){if(nr.processingMode(n,1))throw new ht(`Invalid JSON-LD syntax; an @context @type value must not be "${f}" in JSON-LD 1.0 mode.`,"jsonld.SyntaxError",{code:"invalid type mapping",context:e})}else if(f!=="@id"&&f!=="@vocab"){if(f=Fg(n,f,{vocab:!0,base:!1},e,r,i),!Zp(f))throw new ht("Invalid JSON-LD syntax; an @context @type value must be an absolute IRI.","jsonld.SyntaxError",{code:"invalid type mapping",context:e});if(f.indexOf("_:")===0)throw new ht("Invalid JSON-LD syntax; an @context @type value must be an IRI, not a blank node identifier.","jsonld.SyntaxError",{code:"invalid type mapping",context:e})}u["@type"]=f}if("@container"in s){let f=hs(s["@container"])?[s["@container"]]:s["@container"]||[],m=["@list","@set","@index","@language"],w=!0,b=f.includes("@set");if(nr.processingMode(n,1.1)){if(m.push("@graph","@id","@type"),f.includes("@list")){if(f.length!==1)throw new ht("Invalid JSON-LD syntax; @context @container with @list must have no other values","jsonld.SyntaxError",{code:"invalid container mapping",context:e})}else if(f.includes("@graph")){if(f.some(S=>S!=="@graph"&&S!=="@id"&&S!=="@index"&&S!=="@set"))throw new ht("Invalid JSON-LD syntax; @context @container with @graph must have no other values other than @id, @index, and @set","jsonld.SyntaxError",{code:"invalid container mapping",context:e})}else w&=f.length<=(b?2:1);if(f.includes("@type")&&(u["@type"]=u["@type"]||"@id",!["@id","@vocab"].includes(u["@type"])))throw new ht("Invalid JSON-LD syntax; container: @type requires @type to be @id or @vocab.","jsonld.SyntaxError",{code:"invalid type mapping",context:e})}else w&=!$q(s["@container"]),w&=f.length<=1;if(w&=f.every(S=>m.includes(S)),w&=!(b&&f.includes("@list")),!w)throw new ht("Invalid JSON-LD syntax; @context @container value must be one of the following: "+m.join(", "),"jsonld.SyntaxError",{code:"invalid container mapping",context:e});if(u.reverse&&!f.every(S=>["@index","@set"].includes(S)))throw new ht("Invalid JSON-LD syntax; @context @container value for a @reverse type definition must be @index or @set.","jsonld.SyntaxError",{code:"invalid reverse property",context:e});u["@container"]=f}if("@index"in s){if(!("@container"in s)||!u["@container"].includes("@index"))throw new ht(`Invalid JSON-LD syntax; @index without @index in @container: "${s["@index"]}" on term "${t}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:e});if(!hs(s["@index"])||s["@index"].indexOf("@")===0)throw new ht(`Invalid JSON-LD syntax; @index must expand to an IRI: "${s["@index"]}" on term "${t}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:e});u["@index"]=s["@index"]}if("@context"in s&&(u["@context"]=s["@context"]),"@language"in s&&!("@type"in s)){let f=s["@language"];if(f!==null&&!hs(f))throw new ht("Invalid JSON-LD syntax; @context @language value must be a string or null.","jsonld.SyntaxError",{code:"invalid language mapping",context:e});f!==null&&(f=f.toLowerCase()),u["@language"]=f}if("@prefix"in s){if(t.match(/:|\//))throw new ht("Invalid JSON-LD syntax; @context @prefix used on a compact IRI term","jsonld.SyntaxError",{code:"invalid term definition",context:e});if(nr.isKeyword(u["@id"]))throw new ht("Invalid JSON-LD syntax; keywords may not be used as prefixes","jsonld.SyntaxError",{code:"invalid term definition",context:e});if(typeof s["@prefix"]=="boolean")u._prefix=s["@prefix"]===!0;else throw new ht("Invalid JSON-LD syntax; @context value for @prefix must be boolean","jsonld.SyntaxError",{code:"invalid @prefix value",context:e})}if("@direction"in s){let f=s["@direction"];if(f!==null&&f!=="ltr"&&f!=="rtl")throw new ht('Invalid JSON-LD syntax; @direction value must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:e});u["@direction"]=f}if("@nest"in s){let f=s["@nest"];if(!hs(f)||f!=="@nest"&&f.indexOf("@")===0)throw new ht("Invalid JSON-LD syntax; @context @nest value must be a string which is not a keyword other than @nest.","jsonld.SyntaxError",{code:"invalid @nest value",context:e});u["@nest"]=f}let h=u["@id"];if(h==="@context"||h==="@preserve")throw new ht("Invalid JSON-LD syntax; @context and @preserve cannot be aliased.","jsonld.SyntaxError",{code:"invalid keyword alias",context:e});if(a&&a.protected&&!o&&(n.protected[t]=!0,u.protected=!0,!KT(a,u)))throw new ht("Invalid JSON-LD syntax; tried to redefine a protected term.","jsonld.SyntaxError",{code:"protected term redefinition",context:e,term:t})};nr.expandIri=(n,e,t,r)=>Fg(n,e,t,void 0,void 0,r);function Fg(n,e,t,r,i,o){if(e===null||!hs(e)||nr.isKeyword(e))return e;if(e.match(G3))return null;if(r&&r.hasOwnProperty(e)&&i.get(e)!==!0&&nr.createTermDefinition({activeCtx:n,localCtx:r,term:e,defined:i,options:o}),t=t||{},t.vocab){let a=n.mappings.get(e);if(a===null)return null;if(Mf(a)&&"@id"in a)return a["@id"]}let s=e.indexOf(":");if(s>0){let a=e.substr(0,s),c=e.substr(s+1);if(a==="_"||c.indexOf("//")===0)return e;r&&r.hasOwnProperty(a)&&nr.createTermDefinition({activeCtx:n,localCtx:r,term:a,defined:i,options:o});let u=n.mappings.get(a);if(u&&u._prefix)return u["@id"]+c;if(Zp(e))return e}if(t.vocab&&"@vocab"in n)e=n["@vocab"]+e;else if(t.base){let a,c;"@base"in n?n["@base"]?(c=T2(o.base,n["@base"]),a=T2(c,e)):(c=n["@base"],a=e):(c=o.base,a=T2(o.base,e)),e=a}return e}nr.getInitialContext=n=>{let e=JSON.stringify({processingMode:n.processingMode}),t=U3.get(e);if(t)return t;let r={processingMode:n.processingMode,mappings:new Map,inverse:null,getInverse:i,clone:a,revertToPreviousContext:c,protected:{}};return U3.size===Ude&&U3.clear(),U3.set(e,r),r;function i(){let u=this;if(u.inverse)return u.inverse;let l=u.inverse={},d=u.fastCurieMap={},h={},f=(u["@language"]||"@none").toLowerCase(),m=u["@direction"],w=u.mappings,b=[...w.keys()].sort(Nde);for(let S of b){let R=w.get(S);if(R===null)continue;let G=R["@container"]||"@none";if(G=[].concat(G).sort().join(""),R["@id"]===null)continue;let U=eV(R["@id"]);for(let H of U){let M=l[H],A=nr.isKeyword(H);if(M)!A&&!R._termHasColon&&h[H].push(S);else if(l[H]=M={},!A&&!R._termHasColon){h[H]=[S];let D={iri:H,terms:h[H]};H[0]in d?d[H[0]].push(D):d[H[0]]=[D]}if(M[G]||(M[G]={"@language":{},"@type":{},"@any":{}}),M=M[G],s(S,M["@any"],"@none"),R.reverse)s(S,M["@type"],"@reverse");else if(R["@type"]==="@none")s(S,M["@any"],"@none"),s(S,M["@language"],"@none"),s(S,M["@type"],"@none");else if("@type"in R)s(S,M["@type"],R["@type"]);else if("@language"in R&&"@direction"in R){let D=R["@language"],z=R["@direction"];D&&z?s(S,M["@language"],`${D}_${z}`.toLowerCase()):D?s(S,M["@language"],D.toLowerCase()):z?s(S,M["@language"],`_${z}`):s(S,M["@language"],"@null")}else"@language"in R?s(S,M["@language"],(R["@language"]||"@null").toLowerCase()):"@direction"in R?R["@direction"]?s(S,M["@language"],`_${R["@direction"]}`):s(S,M["@language"],"@none"):m?(s(S,M["@language"],`_${m}`),s(S,M["@language"],"@none"),s(S,M["@type"],"@none")):(s(S,M["@language"],f),s(S,M["@language"],"@none"),s(S,M["@type"],"@none"))}}for(let S in d)o(d,S,1);return l}function o(u,l,d){let h=u[l],f=u[l]={},m,w;for(let b of h)m=b.iri,d>=m.length?w="":w=m[d],w in f?f[w].push(b):f[w]=[b];for(let b in f)b!==""&&o(f,b,d+1)}function s(u,l,d){l.hasOwnProperty(d)||(l[d]=u)}function a(){let u={};return u.mappings=_q.clone(this.mappings),u.clone=this.clone,u.inverse=null,u.getInverse=this.getInverse,u.protected=_q.clone(this.protected),this.previousContext&&(u.previousContext=this.previousContext.clone()),u.revertToPreviousContext=this.revertToPreviousContext,"@base"in this&&(u["@base"]=this["@base"]),"@language"in this&&(u["@language"]=this["@language"]),"@vocab"in this&&(u["@vocab"]=this["@vocab"]),u}function c(){return this.previousContext?this.previousContext.clone():this}};nr.getContextValue=(n,e,t)=>{if(e===null)return t==="@context"?void 0:null;if(n.mappings.has(e)){let r=n.mappings.get(e);if(Mde(t))return r;if(r.hasOwnProperty(t))return r[t]}if(t==="@language"&&t in n||t==="@direction"&&t in n)return n[t];if(t!=="@context")return null};nr.processingMode=(n,e)=>e.toString()>="1.1"?!n.processingMode||n.processingMode>="json-ld-"+e.toString():n.processingMode==="json-ld-1.0";nr.isKeyword=n=>{if(!hs(n)||n[0]!=="@")return!1;switch(n){case"@base":case"@container":case"@context":case"@default":case"@direction":case"@embed":case"@explicit":case"@graph":case"@id":case"@included":case"@index":case"@json":case"@language":case"@list":case"@nest":case"@none":case"@omitDefault":case"@prefix":case"@preserve":case"@protected":case"@requireAll":case"@reverse":case"@set":case"@type":case"@value":case"@version":case"@vocab":return!0}return!1};function KT(n,e){if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return n===e;let t=Array.isArray(n);if(t!==Array.isArray(e))return!1;if(t){if(n.length!==e.length)return!1;for(let o=0;o<n.length;++o)if(!KT(n[o],e[o]))return!1;return!0}let r=Object.keys(n),i=Object.keys(e);if(r.length!==i.length)return!1;for(let o in n){let s=n[o],a=e[o];if(o==="@container"&&Array.isArray(s)&&Array.isArray(a)&&(s=s.slice().sort(),a=a.slice().sort()),!KT(s,a))return!1}return!0}});var aV=oe((G9e,sV)=>{"use strict";var ur=ds(),{isArray:La,isObject:Sa,isEmptyObject:VT,isString:ji,isUndefined:J3}=ls(),{isList:JT,isValue:QT,isGraph:Gde,isSubject:Hde}=Su(),{expandIri:Gr,getContextValue:Qs,isKeyword:zT,process:B2,processingMode:H3}=Of(),{isAbsolute:K3}=Cu(),{REGEX_BCP47:nV,REGEX_KEYWORD:Kde,addValue:Vs,asArray:vc,getValues:Jde,validateTypeValue:qde}=fs(),{handleEvent:Ca}=Og(),Ff={};sV.exports=Ff;Ff.expand=async({activeCtx:n,activeProperty:e=null,element:t,options:r={},insideList:i=!1,insideIndex:o=!1,typeScopedContext:s=null})=>{if(t==null)return null;if(e==="@default"&&(r=Object.assign({},r,{isFrame:!1})),!La(t)&&!Sa(t))return!i&&(e===null||Gr(n,e,{vocab:!0},r)==="@graph")?(r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"free-floating scalar",level:"warning",message:"Dropping free-floating scalar not in a list.",details:{value:t}},options:r}),null):oV({activeCtx:n,activeProperty:e,value:t,options:r});if(La(t)){let m=[],w=Qs(n,e,"@container")||[];i=i||w.includes("@list");for(let b=0;b<t.length;++b){let S=await Ff.expand({activeCtx:n,activeProperty:e,element:t[b],options:r,insideIndex:o,typeScopedContext:s});i&&La(S)&&(S={"@list":S}),S!==null&&(La(S)?m=m.concat(S):m.push(S))}return m}let a=Gr(n,e,{vocab:!0},r),c=Qs(n,e,"@context");s=s||(n.previousContext?n:null);let u=Object.keys(t).sort(),l=!o;if(l&&s&&u.length<=2&&!u.includes("@context"))for(let m of u){let w=Gr(s,m,{vocab:!0},r);if(w==="@value"){l=!1,n=s;break}if(w==="@id"&&u.length===1){l=!1;break}}l&&(n=n.revertToPreviousContext()),J3(c)||(n=await B2({activeCtx:n,localCtx:c,propagate:!0,overrideProtected:!0,options:r})),"@context"in t&&(n=await B2({activeCtx:n,localCtx:t["@context"],options:r})),s=n;let d=null;for(let m of u)if(Gr(n,m,{vocab:!0},r)==="@type"){d=d||m;let b=t[m],S=Array.isArray(b)?b.length>1?b.slice().sort():b:[b];for(let R of S){let G=Qs(s,R,"@context");J3(G)||(n=await B2({activeCtx:n,localCtx:G,options:r,propagate:!1}))}}let h={};await iV({activeCtx:n,activeProperty:e,expandedActiveProperty:a,element:t,expandedParent:h,options:r,insideList:i,typeKey:d,typeScopedContext:s}),u=Object.keys(h);let f=u.length;if("@value"in h){if("@type"in h&&("@language"in h||"@direction"in h))throw new ur('Invalid JSON-LD syntax; an element containing "@value" may not contain both "@type" and either "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:h});let m=f-1;if("@type"in h&&(m-=1),"@index"in h&&(m-=1),"@language"in h&&(m-=1),"@direction"in h&&(m-=1),m!==0)throw new ur('Invalid JSON-LD syntax; an element containing "@value" may only have an "@index" property and either "@type" or either or both "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:h});let w=h["@value"]===null?[]:vc(h["@value"]),b=Jde(h,"@type");if(!(H3(n,1.1)&&b.includes("@json")&&b.length===1))if(w.length===0)r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"null @value value",level:"warning",message:"Dropping null @value value.",details:{value:h}},options:r}),h=null;else{if(!w.every(S=>ji(S)||VT(S))&&"@language"in h)throw new ur("Invalid JSON-LD syntax; only strings may be language-tagged.","jsonld.SyntaxError",{code:"invalid language-tagged value",element:h});if(!b.every(S=>K3(S)&&!(ji(S)&&S.indexOf("_:")===0)||VT(S)))throw new ur('Invalid JSON-LD syntax; an element containing "@value" and "@type" must have an absolute IRI for the value of "@type".',"jsonld.SyntaxError",{code:"invalid typed value",element:h})}}else if("@type"in h&&!La(h["@type"]))h["@type"]=[h["@type"]];else if("@set"in h||"@list"in h){if(f>1&&!(f===2&&"@index"in h))throw new ur('Invalid JSON-LD syntax; if an element has the property "@set" or "@list", then it can have at most one other property that is "@index".',"jsonld.SyntaxError",{code:"invalid set or list object",element:h});"@set"in h&&(h=h["@set"],u=Object.keys(h),f=u.length)}else f===1&&"@language"in h&&(r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"object with only @language",level:"warning",message:"Dropping object with only @language.",details:{value:h}},options:r}),h=null);return Sa(h)&&!r.keepFreeFloatingNodes&&!i&&(e===null||a==="@graph"||(Qs(n,e,"@container")||[]).includes("@graph"))&&(h=rV({value:h,count:f,options:r})),h};function rV({value:n,count:e,options:t}){if(e===0||"@value"in n||"@list"in n||e===1&&"@id"in n){if(t.eventHandler){let r,i;e===0?(r="empty object",i="Dropping empty object."):"@value"in n?(r="object with only @value",i="Dropping object with only @value."):"@list"in n?(r="object with only @list",i="Dropping object with only @list."):e===1&&"@id"in n&&(r="object with only @id",i="Dropping object with only @id."),Ca({event:{type:["JsonLdEvent"],code:r,level:"warning",message:i,details:{value:n}},options:t})}return null}return n}async function iV({activeCtx:n,activeProperty:e,expandedActiveProperty:t,element:r,expandedParent:i,options:o={},insideList:s,typeKey:a,typeScopedContext:c}){let u=Object.keys(r).sort(),l=[],d,h=r[a]&&Gr(n,La(r[a])?r[a][0]:r[a],{vocab:!0},{...o,typeExpansion:!0})==="@json";for(let f of u){let m=r[f],w;if(f==="@context")continue;let b=Gr(n,f,{vocab:!0},o);if(b===null||!(K3(b)||zT(b))){o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid property",level:"warning",message:"Dropping property that did not expand into an absolute IRI or keyword.",details:{property:f,expandedProperty:b}},options:o});continue}if(zT(b)){if(t==="@reverse")throw new ur("Invalid JSON-LD syntax; a keyword cannot be used as a @reverse property.","jsonld.SyntaxError",{code:"invalid reverse property map",value:m});if(b in i&&b!=="@included"&&b!=="@type")throw new ur("Invalid JSON-LD syntax; colliding keywords detected.","jsonld.SyntaxError",{code:"colliding keywords",keyword:b})}if(b==="@id"){if(!ji(m)){if(!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@id" value must a string.',"jsonld.SyntaxError",{code:"invalid @id value",value:m});if(Sa(m)){if(!VT(m))throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}else if(La(m)){if(!m.every(U=>ji(U)))throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}else throw new ur('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:m})}Vs(i,"@id",vc(m).map(U=>{if(ji(U)){let H=Gr(n,U,{base:!0},o);return o.eventHandler&&(H===null?Ca(U===null?{event:{type:["JsonLdEvent"],code:"null @id value",level:"warning",message:"Null @id found.",details:{id:U}},options:o}:{event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:U}},options:o}):K3(H)||Ca({event:{type:["JsonLdEvent"],code:"relative @id reference",level:"warning",message:"Relative @id reference found.",details:{id:U,expandedId:H}},options:o})),H}return U}),{propertyIsArray:o.isFrame});continue}if(b==="@type"){Sa(m)&&(m=Object.fromEntries(Object.entries(m).map(([U,H])=>[Gr(c,U,{vocab:!0}),vc(H).map(M=>Gr(c,M,{base:!0,vocab:!0},{...o,typeExpansion:!0}))]))),qde(m,o.isFrame),Vs(i,"@type",vc(m).map(U=>{if(ji(U)){let H=Gr(c,U,{base:!0,vocab:!0},{...o,typeExpansion:!0});return H!=="@json"&&!K3(H)&&o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"relative @type reference",level:"warning",message:"Relative @type reference found.",details:{type:U}},options:o}),H}return U}),{propertyIsArray:!!o.isFrame});continue}if(b==="@included"&&H3(n,1.1)){let U=vc(await Ff.expand({activeCtx:n,activeProperty:e,element:m,options:o}));if(!U.every(H=>Hde(H)))throw new ur("Invalid JSON-LD syntax; values of @included must expand to node objects.","jsonld.SyntaxError",{code:"invalid @included value",value:m});Vs(i,"@included",U,{propertyIsArray:!0});continue}if(b==="@graph"&&!(Sa(m)||La(m)))throw new ur('Invalid JSON-LD syntax; "@graph" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid @graph value",value:m});if(b==="@value"){d=m,h&&H3(n,1.1)?i["@value"]=m:Vs(i,"@value",m,{propertyIsArray:o.isFrame});continue}if(b==="@language"){if(m===null)continue;if(!ji(m)&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@language" value must be a string.',"jsonld.SyntaxError",{code:"invalid language-tagged string",value:m});m=vc(m).map(U=>ji(U)?U.toLowerCase():U);for(let U of m)ji(U)&&!U.match(nV)&&o.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:U}},options:o});Vs(i,"@language",m,{propertyIsArray:o.isFrame});continue}if(b==="@direction"){if(!ji(m)&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@direction" value must be a string.',"jsonld.SyntaxError",{code:"invalid base direction",value:m});m=vc(m);for(let U of m)if(ji(U)&&U!=="ltr"&&U!=="rtl")throw new ur('Invalid JSON-LD syntax; "@direction" must be "ltr" or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",value:m});Vs(i,"@direction",m,{propertyIsArray:o.isFrame});continue}if(b==="@index"){if(!ji(m))throw new ur('Invalid JSON-LD syntax; "@index" value must be a string.',"jsonld.SyntaxError",{code:"invalid @index value",value:m});Vs(i,"@index",m);continue}if(b==="@reverse"){if(!Sa(m))throw new ur('Invalid JSON-LD syntax; "@reverse" value must be an object.',"jsonld.SyntaxError",{code:"invalid @reverse value",value:m});if(w=await Ff.expand({activeCtx:n,activeProperty:"@reverse",element:m,options:o}),"@reverse"in w)for(let H in w["@reverse"])Vs(i,H,w["@reverse"][H],{propertyIsArray:!0});let U=i["@reverse"]||null;for(let H in w){if(H==="@reverse")continue;U===null&&(U=i["@reverse"]={}),Vs(U,H,[],{propertyIsArray:!0});let M=w[H];for(let A=0;A<M.length;++A){let D=M[A];if(QT(D)||JT(D))throw new ur('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:w});Vs(U,H,D,{propertyIsArray:!0})}}continue}if(b==="@nest"){l.push(f);continue}let S=n,R=Qs(n,f,"@context");J3(R)||(S=await B2({activeCtx:n,localCtx:R,propagate:!0,overrideProtected:!0,options:o}));let G=Qs(n,f,"@container")||[];if(G.includes("@language")&&Sa(m)){let U=Qs(S,f,"@direction");w=Vde(S,m,U,o)}else if(G.includes("@index")&&Sa(m)){let U=G.includes("@graph"),H=Qs(S,f,"@index")||"@index",M=H!=="@index"&&Gr(n,H,{vocab:!0},o);w=await qT({activeCtx:S,options:o,activeProperty:f,value:m,asGraph:U,indexKey:H,propertyIndex:M})}else if(G.includes("@id")&&Sa(m)){let U=G.includes("@graph");w=await qT({activeCtx:S,options:o,activeProperty:f,value:m,asGraph:U,indexKey:"@id"})}else if(G.includes("@type")&&Sa(m))w=await qT({activeCtx:S.revertToPreviousContext(),options:o,activeProperty:f,value:m,asGraph:!1,indexKey:"@type"});else{let U=b==="@list";if(U||b==="@set"){let H=e;U&&t==="@graph"&&(H=null),w=await Ff.expand({activeCtx:S,activeProperty:H,element:m,options:o,insideList:U})}else Qs(n,f,"@type")==="@json"?w={"@type":"@json","@value":m}:w=await Ff.expand({activeCtx:S,activeProperty:f,element:m,options:o,insideList:!1})}if(!(w===null&&b!=="@value")){if(b!=="@list"&&!JT(w)&&G.includes("@list")&&(w={"@list":vc(w)}),G.includes("@graph")&&!G.some(U=>U==="@id"||U==="@index")){if(w=vc(w),o.isFrame||(w=w.filter(U=>{let H=Object.keys(U).length;return rV({value:U,count:H,options:o})!==null})),w.length===0)continue;w=w.map(U=>({"@graph":vc(U)}))}if(S.mappings.has(f)&&S.mappings.get(f).reverse){let U=i["@reverse"]=i["@reverse"]||{};w=vc(w);for(let H=0;H<w.length;++H){let M=w[H];if(QT(M)||JT(M))throw new ur('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:w});Vs(U,b,M,{propertyIsArray:!0})}continue}Vs(i,b,w,{propertyIsArray:!0})}}if("@value"in i&&!(i["@type"]==="@json"&&H3(n,1.1))){if((Sa(d)||La(d))&&!o.isFrame)throw new ur('Invalid JSON-LD syntax; "@value" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid value object value",value:d})}for(let f of l){let m=La(r[f])?r[f]:[r[f]];for(let w of m){if(!Sa(w)||Object.keys(w).some(b=>Gr(n,b,{vocab:!0},o)==="@value"))throw new ur("Invalid JSON-LD syntax; nested value must be a node object.","jsonld.SyntaxError",{code:"invalid @nest value",value:w});await iV({activeCtx:n,activeProperty:e,expandedActiveProperty:t,element:w,expandedParent:i,options:o,insideList:s,typeScopedContext:c,typeKey:a})}}}function oV({activeCtx:n,activeProperty:e,value:t,options:r}){if(t==null)return null;let i=Gr(n,e,{vocab:!0},r);if(i==="@id")return Gr(n,t,{base:!0},r);if(i==="@type")return Gr(n,t,{vocab:!0,base:!0},{...r,typeExpansion:!0});let o=Qs(n,e,"@type");if((o==="@id"||i==="@graph")&&ji(t)){let a=Gr(n,t,{base:!0},r);return a===null&&t.match(Kde)&&r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:e}},options:r}),{"@id":a}}if(o==="@vocab"&&ji(t))return{"@id":Gr(n,t,{vocab:!0,base:!0},r)};if(zT(i))return t;let s={};if(o&&!["@id","@vocab","@none"].includes(o))s["@type"]=o;else if(ji(t)){let a=Qs(n,e,"@language");a!==null&&(s["@language"]=a);let c=Qs(n,e,"@direction");c!==null&&(s["@direction"]=c)}return["boolean","number","string"].includes(typeof t)||(t=t.toString()),s["@value"]=t,s}function Vde(n,e,t,r){let i=[],o=Object.keys(e).sort();for(let s of o){let a=Gr(n,s,{vocab:!0},r),c=e[s];La(c)||(c=[c]);for(let u of c){if(u===null)continue;if(!ji(u))throw new ur("Invalid JSON-LD syntax; language map values must be strings.","jsonld.SyntaxError",{code:"invalid language map value",languageMap:e});let l={"@value":u};a!=="@none"&&(s.match(nV)||r.eventHandler&&Ca({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:s}},options:r}),l["@language"]=s.toLowerCase()),t&&(l["@direction"]=t),i.push(l)}}return i}async function qT({activeCtx:n,options:e,activeProperty:t,value:r,asGraph:i,indexKey:o,propertyIndex:s}){let a=[],c=Object.keys(r).sort(),u=o==="@type";for(let l of c){if(u){let f=Qs(n,l,"@context");J3(f)||(n=await B2({activeCtx:n,localCtx:f,propagate:!1,options:e}))}let d=r[l];La(d)||(d=[d]),d=await Ff.expand({activeCtx:n,activeProperty:t,element:d,options:e,insideList:!1,insideIndex:!0});let h;s?l==="@none"?h="@none":h=oV({activeCtx:n,activeProperty:o,value:l,options:e}):h=Gr(n,l,{vocab:!0},e),o==="@id"?l=Gr(n,l,{base:!0},e):u&&(l=h);for(let f of d){if(i&&!Gde(f)&&(f={"@graph":[f]}),o==="@type")h==="@none"||(f["@type"]?f["@type"]=[l].concat(f["@type"]):f["@type"]=[l]);else{if(QT(f)&&!["@language","@type","@index"].includes(o))throw new ur(`Invalid JSON-LD syntax; Attempt to add illegal key to value object: "${o}".`,"jsonld.SyntaxError",{code:"invalid value object",value:f});s?h!=="@none"&&Vs(f,s,h,{propertyIsArray:!0,prependValue:!0}):h!=="@none"&&!(o in f)&&(f[o]=l)}a.push(f)}}return a}});var P2=oe((H9e,uV)=>{"use strict";var{isKeyword:cV}=Of(),Lu=Su(),YT=ls(),Ru=fs(),Qde=ds(),Go={};uV.exports=Go;Go.createMergedNodeMap=(n,e)=>{e=e||{};let t=e.issuer||new Ru.IdentifierIssuer("_:b"),r={"@default":{}};return Go.createNodeMap(n,r,"@default",t),Go.mergeNodeMaps(r)};Go.createNodeMap=(n,e,t,r,i,o)=>{if(YT.isArray(n)){for(let u of n)Go.createNodeMap(u,e,t,r,void 0,o);return}if(!YT.isObject(n)){o&&o.push(n);return}if(Lu.isValue(n)){if("@type"in n){let u=n["@type"];u.indexOf("_:")===0&&(n["@type"]=u=r.getId(u))}o&&o.push(n);return}else if(o&&Lu.isList(n)){let u=[];Go.createNodeMap(n["@list"],e,t,r,i,u),o.push({"@list":u});return}if("@type"in n){let u=n["@type"];for(let l of u)l.indexOf("_:")===0&&r.getId(l)}YT.isUndefined(i)&&(i=Lu.isBlankNode(n)?r.getId(n["@id"]):n["@id"]),o&&o.push({"@id":i});let s=e[t],a=s[i]=s[i]||{};a["@id"]=i;let c=Object.keys(n).sort();for(let u of c){if(u==="@id")continue;if(u==="@reverse"){let d={"@id":i},h=n["@reverse"];for(let f in h){let m=h[f];for(let w of m){let b=w["@id"];Lu.isBlankNode(w)&&(b=r.getId(b)),Go.createNodeMap(w,e,t,r,b),Ru.addValue(s[b],f,d,{propertyIsArray:!0,allowDuplicate:!1})}}continue}if(u==="@graph"){i in e||(e[i]={}),Go.createNodeMap(n[u],e,i,r);continue}if(u==="@included"){Go.createNodeMap(n[u],e,t,r);continue}if(u!=="@type"&&cV(u)){if(u==="@index"&&u in a&&(n[u]!==a[u]||n[u]["@id"]!==a[u]["@id"]))throw new Qde("Invalid JSON-LD syntax; conflicting @index property detected.","jsonld.SyntaxError",{code:"conflicting indexes",subject:a});a[u]=n[u];continue}let l=n[u];if(u.indexOf("_:")===0&&(u=r.getId(u)),l.length===0){Ru.addValue(a,u,[],{propertyIsArray:!0});continue}for(let d of l)if(u==="@type"&&(d=d.indexOf("_:")===0?r.getId(d):d),Lu.isSubject(d)||Lu.isSubjectReference(d)){if("@id"in d&&!d["@id"])continue;let h=Lu.isBlankNode(d)?r.getId(d["@id"]):d["@id"];Ru.addValue(a,u,{"@id":h},{propertyIsArray:!0,allowDuplicate:!1}),Go.createNodeMap(d,e,t,r,h)}else if(Lu.isValue(d))Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1});else if(Lu.isList(d)){let h=[];Go.createNodeMap(d["@list"],e,t,r,i,h),d={"@list":h},Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1})}else Go.createNodeMap(d,e,t,r,i),Ru.addValue(a,u,d,{propertyIsArray:!0,allowDuplicate:!1})}};Go.mergeNodeMapGraphs=n=>{let e={};for(let t of Object.keys(n).sort())for(let r of Object.keys(n[t]).sort()){let i=n[t][r];r in e||(e[r]={"@id":r});let o=e[r];for(let s of Object.keys(i).sort())if(cV(s)&&s!=="@type")o[s]=Ru.clone(i[s]);else for(let a of i[s])Ru.addValue(o,s,Ru.clone(a),{propertyIsArray:!0,allowDuplicate:!1})}return e};Go.mergeNodeMaps=n=>{let e=n["@default"],t=Object.keys(n).sort();for(let r of t){if(r==="@default")continue;let i=n[r],o=e[r];o?"@graph"in o||(o["@graph"]=[]):e[r]=o={"@id":r,"@graph":[]};let s=o["@graph"];for(let a of Object.keys(i).sort()){let c=i[a];Lu.isSubjectReference(c)||s.push(c)}}return e}});var fV=oe((K9e,dV)=>{"use strict";var{isSubjectReference:zde}=Su(),{createMergedNodeMap:Yde}=P2(),lV={};dV.exports=lV;lV.flatten=n=>{let e=Yde(n),t=[],r=Object.keys(e).sort();for(let i=0;i<r.length;++i){let o=e[r[i]];zde(o)||t.push(o)}return t}});var IV=oe((J9e,EV)=>{"use strict";var $T=ds(),jT=Su(),k2=ls(),{REGEX_BCP47:hV,addValue:pV}=fs(),{handleEvent:mV}=Og(),{RDF_LIST:jde,RDF_FIRST:WT,RDF_REST:ZT,RDF_NIL:XT,RDF_TYPE:Wde,RDF_JSON_LITERAL:Zde,XSD_BOOLEAN:gV,XSD_DOUBLE:yV,XSD_INTEGER:wV,XSD_STRING:_T}=v2(),bV={};EV.exports=bV;bV.fromRDF=async(n,e)=>{let{useRdfType:t=!1,useNativeTypes:r=!1,rdfDirection:i=null}=e,o={},s={"@default":o},a={};if(i){if(i==="compound-literal")throw new $T("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if(i!=="i18n-datatype")throw new $T("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i})}for(let l of n){let d=l.graph.termType==="DefaultGraph"?"@default":l.graph.value;d in s||(s[d]={}),d!=="@default"&&!(d in o)&&(o[d]={"@id":d});let h=s[d],f=l.subject.value,m=l.predicate.value,w=l.object;f in h||(h[f]={"@id":f});let b=h[f],S=w.termType.endsWith("Node");if(S&&!(w.value in h)&&(h[w.value]={"@id":w.value}),m===Wde&&!t&&S){pV(b,"@type",w.value,{propertyIsArray:!0});continue}let R=Xde(w,r,i,e);if(pV(b,m,R,{propertyIsArray:!0}),S)if(w.value===XT){let G=h[w.value];"usages"in G||(G.usages=[]),G.usages.push({node:b,property:m,value:R})}else w.value in a?a[w.value]=!1:a[w.value]={node:b,property:m,value:R}}for(let l in s){let d=s[l];if(!(XT in d))continue;let h=d[XT];if(h.usages){for(let f of h.usages){let m=f.node,w=f.property,b=f.value,S=[],R=[],G=Object.keys(m).length;for(;w===ZT&&k2.isObject(a[m["@id"]])&&k2.isArray(m[WT])&&m[WT].length===1&&k2.isArray(m[ZT])&&m[ZT].length===1&&(G===3||G===4&&k2.isArray(m["@type"])&&m["@type"].length===1&&m["@type"][0]===jde)&&(S.push(m[WT][0]),R.push(m["@id"]),f=a[m["@id"]],m=f.node,w=f.property,b=f.value,G=Object.keys(m).length,!!jT.isBlankNode(m)););delete b["@id"],b["@list"]=S.reverse();for(let U of R)delete d[U]}delete h.usages}}let c=[],u=Object.keys(o).sort();for(let l of u){let d=o[l];if(l in s){let h=d["@graph"]=[],f=s[l],m=Object.keys(f).sort();for(let w of m){let b=f[w];jT.isSubjectReference(b)||h.push(b)}}jT.isSubjectReference(d)||c.push(d)}return c};function Xde(n,e,t,r){if(n.termType.endsWith("Node"))return{"@id":n.value};let i={"@value":n.value};if(n.language)n.language.match(hV)||r.eventHandler&&mV({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:n.language}},options:r}),i["@language"]=n.language;else{let o=n.datatype.value;if(o||(o=_T),o===Zde){o="@json";try{i["@value"]=JSON.parse(i["@value"])}catch(s){throw new $T("JSON literal could not be parsed.","jsonld.InvalidJsonLiteral",{code:"invalid JSON literal",value:i["@value"],cause:s})}}if(e){if(o===gV)i["@value"]==="true"?i["@value"]=!0:i["@value"]==="false"&&(i["@value"]=!1);else if(k2.isNumeric(i["@value"]))if(o===wV){let s=parseInt(i["@value"],10);s.toFixed(0)===i["@value"]&&(i["@value"]=s)}else o===yV&&(i["@value"]=parseFloat(i["@value"]));[gV,wV,yV,_T].includes(o)||(i["@type"]=o)}else if(t==="i18n-datatype"&&o.startsWith("https://www.w3.org/ns/i18n#")){let[,s,a]=o.split(/[#_]/);s.length>0&&(i["@language"]=s,s.match(hV)||r.eventHandler&&mV({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:s}},options:r})),i["@direction"]=a}else o!==_T&&(i["@type"]=o)}return i}});var xV=oe((q9e,AV)=>{"use strict";AV.exports=function n(e){return e===null||typeof e!="object"||e.toJSON!=null?JSON.stringify(e):Array.isArray(e)?"["+e.reduce((t,r,i)=>{let o=i===0?"":",",s=r===void 0||typeof r=="symbol"?null:r;return t+o+n(s)},"")+"]":"{"+Object.keys(e).sort().reduce((t,r,i)=>{if(e[r]===void 0||typeof e[r]=="symbol")return t;let o=t.length===0?"":",";return t+o+n(r)+":"+n(e[r])},"")+"}"}});var DV=oe((V9e,RV)=>{"use strict";var{createNodeMap:_de}=P2(),{isKeyword:$de}=Of(),vV=Su(),efe=xV(),SV=ds(),M2=ls(),tfe=fs(),{handleEvent:Xp}=Og(),{RDF_FIRST:nfe,RDF_REST:rfe,RDF_NIL:ife,RDF_TYPE:ofe,RDF_JSON_LITERAL:sfe,RDF_LANGSTRING:afe,XSD_BOOLEAN:cfe,XSD_DOUBLE:CV,XSD_INTEGER:ufe,XSD_STRING:lfe}=v2(),{isAbsolute:q3}=Cu(),LV={};RV.exports=LV;LV.toRDF=(n,e)=>{let t=new tfe.IdentifierIssuer("_:b"),r={"@default":{}};_de(n,r,"@default",t);let i=[],o=Object.keys(r).sort();for(let s of o){let a;if(s==="@default")a={termType:"DefaultGraph",value:""};else if(q3(s))s.startsWith("_:")?a={termType:"BlankNode"}:a={termType:"NamedNode"},a.value=s;else{e.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative graph reference",level:"warning",message:"Relative graph reference found.",details:{graph:s}},options:e});continue}dfe(i,r[s],a,t,e)}return i};function dfe(n,e,t,r,i){let o=Object.keys(e).sort();for(let s of o){let a=e[s],c=Object.keys(a).sort();for(let u of c){let l=a[u];if(u==="@type")u=ofe;else if($de(u))continue;for(let d of l){let h={termType:s.startsWith("_:")?"BlankNode":"NamedNode",value:s};if(!q3(s)){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative subject reference",level:"warning",message:"Relative subject reference found.",details:{subject:s}},options:i});continue}let f={termType:u.startsWith("_:")?"BlankNode":"NamedNode",value:u};if(!q3(u)){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative predicate reference",level:"warning",message:"Relative predicate reference found.",details:{predicate:u}},options:i});continue}if(f.termType==="BlankNode"&&!i.produceGeneralizedRdf){i.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"blank node predicate",level:"warning",message:"Dropping blank node predicate.",details:{property:r.getOldIds().find(w=>r.getId(w)===u)}},options:i});continue}let m=e6(d,r,n,t,i.rdfDirection,i);m&&n.push({subject:h,predicate:f,object:m,graph:t})}}}}function ffe(n,e,t,r,i,o){let s={termType:"NamedNode",value:nfe},a={termType:"NamedNode",value:rfe},c={termType:"NamedNode",value:ife},u=n.pop(),l=u?{termType:"BlankNode",value:e.getId()}:c,d=l;for(let h of n){let f=e6(h,e,t,r,i,o),m={termType:"BlankNode",value:e.getId()};t.push({subject:d,predicate:s,object:f,graph:r}),t.push({subject:d,predicate:a,object:m,graph:r}),d=m}if(u){let h=e6(u,e,t,r,i,o);t.push({subject:d,predicate:s,object:h,graph:r}),t.push({subject:d,predicate:a,object:c,graph:r})}return l}function e6(n,e,t,r,i,o){let s={};if(vV.isValue(n)){s.termType="Literal",s.value=void 0,s.datatype={termType:"NamedNode"};let a=n["@value"],c=n["@type"]||null;if(c==="@json")s.value=efe(a),s.datatype.value=sfe;else if(M2.isBoolean(a))s.value=a.toString(),s.datatype.value=c||cfe;else if(M2.isDouble(a)||c===CV)M2.isDouble(a)||(a=parseFloat(a)),s.value=a.toExponential(15).replace(/(\d)0*e\+?/,"$1E"),s.datatype.value=c||CV;else if(M2.isNumber(a))s.value=a.toFixed(0),s.datatype.value=c||ufe;else if("@direction"in n&&i==="i18n-datatype"){let u=(n["@language"]||"").toLowerCase(),l=n["@direction"],d=`https://www.w3.org/ns/i18n#${u}_${l}`;s.datatype.value=d,s.value=a}else{if("@direction"in n&&i==="compound-literal")throw new SV("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if("@direction"in n&&i)throw new SV("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});"@language"in n?("@direction"in n&&!i&&o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:s.value}},options:o}),s.value=a,s.datatype.value=c||afe,s.language=n["@language"]):("@direction"in n&&!i&&o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:s.value}},options:o}),s.value=a,s.datatype.value=c||lfe)}}else if(vV.isList(n)){let a=ffe(n["@list"],e,t,r,i,o);s.termType=a.termType,s.value=a.value}else{let a=M2.isObject(n)?n["@id"]:n;s.termType=a.startsWith("_:")?"BlankNode":"NamedNode",s.value=a}return s.termType==="NamedNode"&&!q3(s.value)?(o.eventHandler&&Xp({event:{type:["JsonLdEvent"],code:"relative object reference",level:"warning",message:"Relative object reference found.",details:{object:s.value}},options:o}),null):s}});var FV=oe((Q9e,OV)=>{"use strict";var{isKeyword:t6}=Of(),Ra=Su(),qn=ls(),ci=fs(),TV=Cu(),O2=ds(),{createNodeMap:hfe,mergeNodeMapGraphs:pfe}=P2(),Da={};OV.exports=Da;Da.frameMergedOrDefault=(n,e,t)=>{let r={options:t,embedded:!1,graph:"@default",graphMap:{"@default":{}},subjectStack:[],link:{},bnodeMap:{}},i=new ci.IdentifierIssuer("_:b");hfe(n,r.graphMap,"@default",i),t.merged&&(r.graphMap["@merged"]=pfe(r.graphMap),r.graph="@merged"),r.subjects=r.graphMap[r.graph];let o=[];Da.frame(r,Object.keys(r.subjects).sort(),e,o),t.pruneBlankNodeIdentifiers&&(t.bnodesToClear=Object.keys(r.bnodeMap).filter(s=>r.bnodeMap[s].length===1));return t.link={},Q3(o,t)};Da.frame=(n,e,t,r,i=null)=>{kV(t),t=t[0];let o=n.options,s={embed:V3(t,o,"embed"),explicit:V3(t,o,"explicit"),requireAll:V3(t,o,"requireAll")};n.link.hasOwnProperty(n.graph)||(n.link[n.graph]={});let a=n.link[n.graph],c=gfe(n,e,t,s),u=Object.keys(c).sort();for(let l of u){let d=c[l];if(i===null?n.uniqueEmbeds={[n.graph]:{}}:n.uniqueEmbeds[n.graph]=n.uniqueEmbeds[n.graph]||{},s.embed==="@link"&&l in a){_p(r,i,a[l]);continue}let h={"@id":l};if(l.indexOf("_:")===0&&ci.addValue(n.bnodeMap,l,h,{propertyIsArray:!0}),a[l]=h,(s.embed==="@first"||s.embed==="@last")&&n.is11)throw new O2("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:t});if(!(!n.embedded&&n.uniqueEmbeds[n.graph].hasOwnProperty(l))){if(n.embedded&&(s.embed==="@never"||mfe(d,n.graph,n.subjectStack))){_p(r,i,h);continue}if(n.embedded&&(s.embed=="@first"||s.embed=="@once")&&n.uniqueEmbeds[n.graph].hasOwnProperty(l)){_p(r,i,h);continue}if(s.embed==="@last"&&l in n.uniqueEmbeds[n.graph]&&yfe(n,l),n.uniqueEmbeds[n.graph][l]={parent:r,property:i},n.subjectStack.push({subject:d,graph:n.graph}),l in n.graphMap){let f=!1,m=null;"@graph"in t?(m=t["@graph"][0],f=!(l==="@merged"||l==="@default"),qn.isObject(m)||(m={})):(f=n.graph!=="@merged",m={}),f&&Da.frame({...n,graph:l,embedded:!1},Object.keys(n.graphMap[l]).sort(),[m],h,"@graph")}"@included"in t&&Da.frame({...n,embedded:!1},e,t["@included"],h,"@included");for(let f of Object.keys(d).sort()){if(t6(f)){if(h[f]=ci.clone(d[f]),f==="@type")for(let m of d["@type"])m.indexOf("_:")===0&&ci.addValue(n.bnodeMap,m,h,{propertyIsArray:!0});continue}if(!(s.explicit&&!(f in t)))for(let m of d[f]){let w=f in t?t[f]:BV(s);if(Ra.isList(m)){let b=t[f]&&t[f][0]&&t[f][0]["@list"]?t[f][0]["@list"]:BV(s),S={"@list":[]};_p(h,f,S);let R=m["@list"];for(let G of R)Ra.isSubjectReference(G)?Da.frame({...n,embedded:!0},[G["@id"]],b,S,"@list"):_p(S,"@list",ci.clone(G))}else Ra.isSubjectReference(m)?Da.frame({...n,embedded:!0},[m["@id"]],w,h,f):n6(w[0],m)&&_p(h,f,ci.clone(m))}}for(let f of Object.keys(t).sort()){if(f==="@type"){if(!qn.isObject(t[f][0])||!("@default"in t[f][0]))continue}else if(t6(f))continue;let m=t[f][0]||{};if(!V3(m,o,"omitDefault")&&!(f in h)){let b="@null";"@default"in m&&(b=ci.clone(m["@default"])),qn.isArray(b)||(b=[b]),h[f]=[{"@preserve":b}]}}for(let f of Object.keys(t["@reverse"]||{}).sort()){let m=t["@reverse"][f];for(let w of Object.keys(n.subjects))ci.getValues(n.subjects[w],f).some(S=>S["@id"]===l)&&(h["@reverse"]=h["@reverse"]||{},ci.addValue(h["@reverse"],f,[],{propertyIsArray:!0}),Da.frame({...n,embedded:!0},[w],m,h["@reverse"][f],i))}_p(r,i,h),n.subjectStack.pop()}}};Da.cleanupNull=(n,e)=>{if(qn.isArray(n))return n.map(r=>Da.cleanupNull(r,e)).filter(r=>r);if(n==="@null")return null;if(qn.isObject(n)){if("@id"in n){let t=n["@id"];if(e.link.hasOwnProperty(t)){let r=e.link[t].indexOf(n);if(r!==-1)return e.link[t][r];e.link[t].push(n)}else e.link[t]=[n]}for(let t in n)n[t]=Da.cleanupNull(n[t],e)}return n};function BV(n){let e={};for(let t in n)n[t]!==void 0&&(e["@"+t]=[n[t]]);return[e]}function mfe(n,e,t){for(let r=t.length-1;r>=0;--r){let i=t[r];if(i.graph===e&&i.subject["@id"]===n["@id"])return!0}return!1}function V3(n,e,t){let r="@"+t,i=r in n?n[r][0]:e[t];if(t==="embed"){if(i===!0)i="@once";else if(i===!1)i="@never";else if(i!=="@always"&&i!=="@never"&&i!=="@link"&&i!=="@first"&&i!=="@last"&&i!=="@once")throw new O2("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:n})}return i}function kV(n){if(!qn.isArray(n)||n.length!==1||!qn.isObject(n[0]))throw new O2("Invalid JSON-LD syntax; a JSON-LD frame must be a single object.","jsonld.SyntaxError",{frame:n});if("@id"in n[0]){for(let e of ci.asArray(n[0]["@id"]))if(!(qn.isObject(e)||TV.isAbsolute(e))||qn.isString(e)&&e.indexOf("_:")===0)throw new O2("Invalid JSON-LD syntax; invalid @id in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:n})}if("@type"in n[0]){for(let e of ci.asArray(n[0]["@type"]))if(!(qn.isObject(e)||TV.isAbsolute(e)||e==="@json")||qn.isString(e)&&e.indexOf("_:")===0)throw new O2("Invalid JSON-LD syntax; invalid @type in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:n})}}function gfe(n,e,t,r){let i={};for(let o of e){let s=n.graphMap[n.graph][o];MV(n,s,t,r)&&(i[o]=s)}return i}function MV(n,e,t,r){let i=!0,o=!1;for(let s in t){let a=!1,c=ci.getValues(e,s),u=ci.getValues(t,s).length===0;if(s==="@id"){if(qn.isEmptyObject(t["@id"][0]||{})?a=!0:t["@id"].length>=0&&(a=t["@id"].includes(c[0])),!r.requireAll)return a}else if(s==="@type"){if(i=!1,u){if(c.length>0)return!1;a=!0}else if(t["@type"].length===1&&qn.isEmptyObject(t["@type"][0]))a=c.length>0;else for(let l of t["@type"])qn.isObject(l)&&"@default"in l?a=!0:a=a||c.some(d=>d===l);if(!r.requireAll)return a}else{if(t6(s))continue;{let l=ci.getValues(t,s)[0],d=!1;if(l&&(kV([l]),d="@default"in l),i=!1,c.length===0&&d)continue;if(c.length>0&&u)return!1;if(l===void 0){if(c.length>0)return!1;a=!0}else if(Ra.isList(l)){let h=l["@list"][0];if(Ra.isList(c[0])){let f=c[0]["@list"];Ra.isValue(h)?a=f.some(m=>n6(h,m)):(Ra.isSubject(h)||Ra.isSubjectReference(h))&&(a=f.some(m=>PV(n,h,m,r)))}}else Ra.isValue(l)?a=c.some(h=>n6(l,h)):Ra.isSubjectReference(l)?a=c.some(h=>PV(n,l,h,r)):qn.isObject(l)?a=c.length>0:a=!1}}if(!a&&r.requireAll)return!1;o=o||a}return i||o}function yfe(n,e){let t=n.uniqueEmbeds[n.graph],r=t[e],i=r.parent,o=r.property,s={"@id":e};if(qn.isArray(i)){for(let c=0;c<i.length;++c)if(ci.compareValues(i[c],s)){i[c]=s;break}}else{let c=qn.isArray(i[o]);ci.removeValue(i,o,s,{propertyIsArray:c}),ci.addValue(i,o,s,{propertyIsArray:c})}let a=c=>{let u=Object.keys(t);for(let l of u)l in t&&qn.isObject(t[l].parent)&&t[l].parent["@id"]===c&&(delete t[l],a(l))};a(e)}function Q3(n,e){if(qn.isArray(n))return n.map(t=>Q3(t,e));if(qn.isObject(n)){if("@preserve"in n)return n["@preserve"][0];if(Ra.isValue(n))return n;if(Ra.isList(n))return n["@list"]=Q3(n["@list"],e),n;if("@id"in n){let t=n["@id"];if(e.link.hasOwnProperty(t)){let r=e.link[t].indexOf(n);if(r!==-1)return e.link[t][r];e.link[t].push(n)}else e.link[t]=[n]}for(let t in n){if(t==="@id"&&e.bnodesToClear.includes(n[t])){delete n["@id"];continue}n[t]=Q3(n[t],e)}}return n}function _p(n,e,t){qn.isObject(n)?ci.addValue(n,e,t,{propertyIsArray:!0}):n.push(t)}function PV(n,e,t,r){if(!("@id"in t))return!1;let i=n.subjects[t["@id"]];return i&&MV(n,i,e,r)}function n6(n,e){let t=e["@value"],r=e["@type"],i=e["@language"],o=n["@value"]?qn.isArray(n["@value"])?n["@value"]:[n["@value"]]:[],s=n["@type"]?qn.isArray(n["@type"])?n["@type"]:[n["@type"]]:[],a=n["@language"]?qn.isArray(n["@language"])?n["@language"]:[n["@language"]]:[];return o.length===0&&s.length===0&&a.length===0?!0:!(!(o.includes(t)||qn.isEmptyObject(o[0]))||!(!r&&s.length===0||s.includes(r)||r&&qn.isEmptyObject(s[0]))||!(!i&&a.length===0||a.includes(i)||i&&qn.isEmptyObject(a[0])))}});var QV=oe((z9e,VV)=>{"use strict";var a6=ds(),{isArray:Nf,isObject:Uf,isString:HV,isUndefined:r6}=ls(),{isList:s6,isValue:Vl,isGraph:KV,isSimpleGraph:NV,isSubjectReference:i6}=Su(),{expandIri:JV,getContextValue:Ho,isKeyword:qV,process:o6,processingMode:wfe}=Of(),{removeBase:UV,prependBase:bfe}=Cu(),{REGEX_KEYWORD:Efe,addValue:zs,asArray:z3,compareShortestLeast:Ife}=fs(),Ot={};VV.exports=Ot;Ot.compact=async({activeCtx:n,activeProperty:e=null,element:t,options:r={}})=>{if(Nf(t)){let o=[];for(let s=0;s<t.length;++s){let a=await Ot.compact({activeCtx:n,activeProperty:e,element:t[s],options:r});a!==null&&o.push(a)}return r.compactArrays&&o.length===1&&(Ho(n,e,"@container")||[]).length===0&&(o=o[0]),o}let i=Ho(n,e,"@context");if(r6(i)||(n=await o6({activeCtx:n,localCtx:i,propagate:!0,overrideProtected:!0,options:r})),Uf(t)){if(r.link&&"@id"in t&&r.link.hasOwnProperty(t["@id"])){let h=r.link[t["@id"]];for(let f=0;f<h.length;++f)if(h[f].expanded===t)return h[f].compacted}if(Vl(t)||i6(t)){let h=Ot.compactValue({activeCtx:n,activeProperty:e,value:t,options:r});return r.link&&i6(t)&&(r.link.hasOwnProperty(t["@id"])||(r.link[t["@id"]]=[]),r.link[t["@id"]].push({expanded:t,compacted:h})),h}if(s6(t)&&(Ho(n,e,"@container")||[]).includes("@list"))return Ot.compact({activeCtx:n,activeProperty:e,element:t["@list"],options:r});let o=e==="@reverse",s={},a=n;!Vl(t)&&!i6(t)&&(n=n.revertToPreviousContext());let c=Ho(a,e,"@context");r6(c)||(n=await o6({activeCtx:n,localCtx:c,propagate:!0,overrideProtected:!0,options:r})),r.link&&"@id"in t&&(r.link.hasOwnProperty(t["@id"])||(r.link[t["@id"]]=[]),r.link[t["@id"]].push({expanded:t,compacted:s}));let u=t["@type"]||[];u.length>1&&(u=Array.from(u).sort());let l=n;for(let h of u){let f=Ot.compactIri({activeCtx:l,iri:h,relativeTo:{vocab:!0}}),m=Ho(a,f,"@context");r6(m)||(n=await o6({activeCtx:n,localCtx:m,options:r,propagate:!1}))}let d=Object.keys(t).sort();for(let h of d){let f=t[h];if(h==="@id"){let m=z3(f).map(b=>Ot.compactIri({activeCtx:n,iri:b,relativeTo:{vocab:!1},base:r.base}));m.length===1&&(m=m[0]);let w=Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}});s[w]=m;continue}if(h==="@type"){let m=z3(f).map(G=>Ot.compactIri({activeCtx:a,iri:G,relativeTo:{vocab:!0}}));m.length===1&&(m=m[0]);let w=Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}}),R=(Ho(n,w,"@container")||[]).includes("@set")&&wfe(n,1.1)||Nf(m)&&f.length===0;zs(s,w,m,{propertyIsArray:R});continue}if(h==="@reverse"){let m=await Ot.compact({activeCtx:n,activeProperty:"@reverse",element:f,options:r});for(let w in m)if(n.mappings.has(w)&&n.mappings.get(w).reverse){let b=m[w],R=(Ho(n,w,"@container")||[]).includes("@set")||!r.compactArrays;zs(s,w,b,{propertyIsArray:R}),delete m[w]}if(Object.keys(m).length>0){let w=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,w,m)}continue}if(h==="@preserve"){let m=await Ot.compact({activeCtx:n,activeProperty:e,element:f,options:r});Nf(m)&&m.length===0||zs(s,h,m);continue}if(h==="@index"){if((Ho(n,e,"@container")||[]).includes("@index"))continue;let w=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,w,f);continue}if(h!=="@graph"&&h!=="@list"&&h!=="@included"&&qV(h)){let m=Ot.compactIri({activeCtx:n,iri:h,relativeTo:{vocab:!0}});zs(s,m,f);continue}if(!Nf(f))throw new a6("JSON-LD expansion error; expanded value must be an array.","jsonld.SyntaxError");if(f.length===0){let m=Ot.compactIri({activeCtx:n,iri:h,value:f,relativeTo:{vocab:!0},reverse:o}),w=n.mappings.has(m)?n.mappings.get(m)["@nest"]:null,b=s;w&&(GV(n,w,r),Uf(s[w])||(s[w]={}),b=s[w]),zs(b,m,f,{propertyIsArray:!0})}for(let m of f){let w=Ot.compactIri({activeCtx:n,iri:h,value:m,relativeTo:{vocab:!0},reverse:o}),b=n.mappings.has(w)?n.mappings.get(w)["@nest"]:null,S=s;b&&(GV(n,b,r),Uf(s[b])||(s[b]={}),S=s[b]);let R=Ho(n,w,"@container")||[],G=KV(m),U=s6(m),H;U?H=m["@list"]:G&&(H=m["@graph"]);let M=await Ot.compact({activeCtx:n,activeProperty:w,element:U||G?H:m,options:r});if(U)if(Nf(M)||(M=[M]),!R.includes("@list"))M={[Ot.compactIri({activeCtx:n,iri:"@list",relativeTo:{vocab:!0}})]:M},"@index"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=m["@index"]);else{zs(S,w,M,{valueIsArray:!0,allowDuplicate:!0});continue}if(G)if(R.includes("@graph")&&(R.includes("@id")||R.includes("@index")&&NV(m))){let A;S.hasOwnProperty(w)?A=S[w]:S[w]=A={};let D=(R.includes("@id")?m["@id"]:m["@index"])||Ot.compactIri({activeCtx:n,iri:"@none",relativeTo:{vocab:!0}});zs(A,D,M,{propertyIsArray:!r.compactArrays||R.includes("@set")})}else R.includes("@graph")&&NV(m)?(Nf(M)&&M.length>1&&(M={"@included":M}),zs(S,w,M,{propertyIsArray:!r.compactArrays||R.includes("@set")})):(Nf(M)&&M.length===1&&r.compactArrays&&(M=M[0]),M={[Ot.compactIri({activeCtx:n,iri:"@graph",relativeTo:{vocab:!0}})]:M},"@id"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}})]=m["@id"]),"@index"in m&&(M[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=m["@index"]),zs(S,w,M,{propertyIsArray:!r.compactArrays||R.includes("@set")}));else if(R.includes("@language")||R.includes("@index")||R.includes("@id")||R.includes("@type")){let A;S.hasOwnProperty(w)?A=S[w]:S[w]=A={};let D;if(R.includes("@language"))Vl(M)&&(M=M["@value"]),D=m["@language"];else if(R.includes("@index")){let z=Ho(n,w,"@index")||"@index",j=Ot.compactIri({activeCtx:n,iri:z,relativeTo:{vocab:!0}});if(z==="@index")D=m["@index"],delete M[j];else{let Y;if([D,...Y]=z3(M[z]||[]),!HV(D))D=null;else switch(Y.length){case 0:delete M[z];break;case 1:M[z]=Y[0];break;default:M[z]=Y;break}}}else if(R.includes("@id")){let z=Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}});D=M[z],delete M[z]}else if(R.includes("@type")){let z=Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}}),j;switch([D,...j]=z3(M[z]||[]),j.length){case 0:delete M[z];break;case 1:M[z]=j[0];break;default:M[z]=j;break}Object.keys(M).length===1&&"@id"in m&&(M=await Ot.compact({activeCtx:n,activeProperty:w,element:{"@id":m["@id"]},options:r}))}D||(D=Ot.compactIri({activeCtx:n,iri:"@none",relativeTo:{vocab:!0}})),zs(A,D,M,{propertyIsArray:R.includes("@set")})}else{let A=!r.compactArrays||R.includes("@set")||R.includes("@list")||Nf(M)&&M.length===0||h==="@list"||h==="@graph";zs(S,w,M,{propertyIsArray:A})}}}return s}return t};Ot.compactIri=({activeCtx:n,iri:e,value:t=null,relativeTo:r={vocab:!1},reverse:i=!1,base:o=null})=>{if(e===null)return e;n.isPropertyTermScoped&&n.previousContext&&(n=n.previousContext);let s=n.getInverse();if(qV(e)&&e in s&&"@none"in s[e]&&"@type"in s[e]["@none"]&&"@none"in s[e]["@none"]["@type"])return s[e]["@none"]["@type"]["@none"];if(r.vocab&&e in s){let d=n["@language"]||"@none",h=[];Uf(t)&&"@index"in t&&!("@graph"in t)&&h.push("@index","@index@set"),Uf(t)&&"@preserve"in t&&(t=t["@preserve"][0]),KV(t)?("@index"in t&&h.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in t&&h.push("@graph@id","@graph@id@set"),h.push("@graph","@graph@set","@set"),"@index"in t||h.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in t||h.push("@graph@id","@graph@id@set")):Uf(t)&&!Vl(t)&&h.push("@id","@id@set","@type","@set@type");let f="@language",m="@null";if(i)f="@type",m="@reverse",h.push("@set");else if(s6(t)){"@index"in t||h.push("@list");let b=t["@list"];if(b.length===0)f="@any",m="@none";else{let S=b.length===0?d:null,R=null;for(let G=0;G<b.length;++G){let U=b[G],H="@none",M="@none";if(Vl(U))if("@direction"in U){let A=(U["@language"]||"").toLowerCase(),D=U["@direction"];H=`${A}_${D}`}else"@language"in U?H=U["@language"].toLowerCase():"@type"in U?M=U["@type"]:H="@null";else M="@id";if(S===null?S=H:H!==S&&Vl(U)&&(S="@none"),R===null?R=M:M!==R&&(R="@none"),S==="@none"&&R==="@none")break}S=S||"@none",R=R||"@none",R!=="@none"?(f="@type",m=R):m=S}}else{if(Vl(t))if("@language"in t&&!("@index"in t)){h.push("@language","@language@set"),m=t["@language"];let b=t["@direction"];b&&(m=`${m}_${b}`)}else"@direction"in t&&!("@index"in t)?m=`_${t["@direction"]}`:"@type"in t&&(f="@type",m=t["@type"]);else f="@type",m="@id";h.push("@set")}h.push("@none"),Uf(t)&&!("@index"in t)&&h.push("@index","@index@set"),Vl(t)&&Object.keys(t).length===1&&h.push("@language","@language@set");let w=Afe(n,e,t,h,f,m);if(w!==null)return w}if(r.vocab&&"@vocab"in n){let d=n["@vocab"];if(e.indexOf(d)===0&&e!==d){let h=e.substr(d.length);if(!n.mappings.has(h))return h}}let a=null,c=[],u=n.fastCurieMap,l=e.length-1;for(let d=0;d<l&&e[d]in u;++d)u=u[e[d]],""in u&&c.push(u[""][0]);for(let d=c.length-1;d>=0;--d){let h=c[d],f=h.terms;for(let m of f){let w=m+":"+e.substr(h.iri.length);n.mappings.get(m)._prefix&&(!n.mappings.has(w)||t===null&&n.mappings.get(w)["@id"]===e)&&(a===null||Ife(w,a)<0)&&(a=w)}}if(a!==null)return a;for(let[d,h]of n.mappings)if(h&&h._prefix&&e.startsWith(d+":"))throw new a6(`Absolute IRI "${e}" confused with prefix "${d}".`,"jsonld.SyntaxError",{code:"IRI confused with prefix",context:n});if(!r.vocab)if("@base"in n)if(n["@base"]){let d=UV(bfe(o,n["@base"]),e);return Efe.test(d)?`./${d}`:d}else return e;else return UV(o,e);return e};Ot.compactValue=({activeCtx:n,activeProperty:e,value:t,options:r})=>{if(Vl(t)){let a=Ho(n,e,"@type"),c=Ho(n,e,"@language"),u=Ho(n,e,"@direction"),l=Ho(n,e,"@container")||[],d="@index"in t&&!l.includes("@index");if(!d&&a!=="@none"&&(t["@type"]===a||"@language"in t&&t["@language"]===c&&"@direction"in t&&t["@direction"]===u||"@language"in t&&t["@language"]===c||"@direction"in t&&t["@direction"]===u))return t["@value"];let h=Object.keys(t).length,f=h===1||h===2&&"@index"in t&&!d,m="@language"in n,w=HV(t["@value"]),b=n.mappings.has(e)&&n.mappings.get(e)["@language"]===null;if(f&&a!=="@none"&&(!m||!w||b))return t["@value"];let S={};return d&&(S[Ot.compactIri({activeCtx:n,iri:"@index",relativeTo:{vocab:!0}})]=t["@index"]),"@type"in t?S[Ot.compactIri({activeCtx:n,iri:"@type",relativeTo:{vocab:!0}})]=Ot.compactIri({activeCtx:n,iri:t["@type"],relativeTo:{vocab:!0}}):"@language"in t&&(S[Ot.compactIri({activeCtx:n,iri:"@language",relativeTo:{vocab:!0}})]=t["@language"]),"@direction"in t&&(S[Ot.compactIri({activeCtx:n,iri:"@direction",relativeTo:{vocab:!0}})]=t["@direction"]),S[Ot.compactIri({activeCtx:n,iri:"@value",relativeTo:{vocab:!0}})]=t["@value"],S}let i=JV(n,e,{vocab:!0},r),o=Ho(n,e,"@type"),s=Ot.compactIri({activeCtx:n,iri:t["@id"],relativeTo:{vocab:o==="@vocab"},base:r.base});return o==="@id"||o==="@vocab"||i==="@graph"?s:{[Ot.compactIri({activeCtx:n,iri:"@id",relativeTo:{vocab:!0}})]:s}};function Afe(n,e,t,r,i,o){o===null&&(o="@null");let s=[];if((o==="@id"||o==="@reverse")&&Uf(t)&&"@id"in t){o==="@reverse"&&s.push("@reverse");let c=Ot.compactIri({activeCtx:n,iri:t["@id"],relativeTo:{vocab:!0}});n.mappings.has(c)&&n.mappings.get(c)&&n.mappings.get(c)["@id"]===t["@id"]?s.push.apply(s,["@vocab","@id"]):s.push.apply(s,["@id","@vocab"])}else{s.push(o);let c=s.find(u=>u.includes("_"));c&&s.push(c.replace(/^[^_]+_/,"_"))}s.push("@none");let a=n.inverse[e];for(let c of r){if(!(c in a))continue;let u=a[c][i];for(let l of s)if(l in u)return u[l]}return null}function GV(n,e,t){if(JV(n,e,{vocab:!0},t)!=="@nest")throw new a6("JSON-LD compact error; nested property must have an @nest value resolving to @nest.","jsonld.SyntaxError",{code:"invalid @nest value"})}});var YV=oe((Y9e,zV)=>{"use strict";zV.exports=n=>{class e{toString(){return"[object JsonLdProcessor]"}}return Object.defineProperty(e,"prototype",{writable:!1,enumerable:!1}),Object.defineProperty(e.prototype,"constructor",{writable:!0,enumerable:!1,configurable:!0,value:e}),e.compact=function(t,r){return arguments.length<2?Promise.reject(new TypeError("Could not compact, too few arguments.")):n.compact(t,r)},e.expand=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not expand, too few arguments.")):n.expand(t)},e.flatten=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not flatten, too few arguments.")):n.flatten(t)},e}});var Hf=oe((j9e,_V)=>{"use strict";var jV=k3(),WV=Pq(),Gf=fs(),Ql=zq(),c6=Gf.IdentifierIssuer,Du=ds(),xfe=FT(),Y3=jq(),{expand:vfe}=aV(),{flatten:Sfe}=fV(),{fromRDF:Cfe}=IV(),{toRDF:Lfe}=DV(),{frameMergedOrDefault:Rfe,cleanupNull:Dfe}=FV(),{isArray:Ug,isObject:$p,isString:Tu}=ls(),{isSubjectReference:Tfe}=Su(),{expandIri:Bfe,getInitialContext:j3,process:ZV,processingMode:u6}=Of(),{compact:Pfe,compactIri:kfe}=QV(),{createNodeMap:Mfe,createMergedNodeMap:Ofe,mergeNodeMaps:Ffe}=P2(),{logEventHandler:Nfe,logWarningEventHandler:Ufe,safeEventHandler:Gfe,setDefaultEventHandler:Hfe,setupEventHandler:Kfe,strictEventHandler:Jfe,unhandledEventHandler:qfe}=Og(),XV=function(n){let e={},r=new xfe({max:100});n.compact=async function(o,s,a){if(arguments.length<2)throw new TypeError("Could not compact, too few arguments.");if(s===null)throw new Du("The compaction context must not be null.","jsonld.CompactError",{code:"invalid local context"});if(o===null)return null;a=i(a,{base:Tu(o)?o:"",compactArrays:!0,compactToRelative:!0,graph:!1,skipExpansion:!1,link:!1,issuer:new c6("_:b"),contextResolver:new Ql({sharedCache:r})}),a.link&&(a.skipExpansion=!0),a.compactToRelative||delete a.base;let c;a.skipExpansion?c=o:c=await n.expand(o,a);let u=await n.processContext(j3(a),s,a),l=await Pfe({activeCtx:u,element:c,options:a});a.compactArrays&&!a.graph&&Ug(l)?l.length===1?l=l[0]:l.length===0&&(l={}):a.graph&&$p(l)&&(l=[l]),$p(s)&&"@context"in s&&(s=s["@context"]),s=Gf.clone(s),Ug(s)||(s=[s]);let d=s;s=[];for(let f=0;f<d.length;++f)(!$p(d[f])||Object.keys(d[f]).length>0)&&s.push(d[f]);let h=s.length>0;if(s.length===1&&(s=s[0]),Ug(l)){let f=kfe({activeCtx:u,iri:"@graph",relativeTo:{vocab:!0}}),m=l;l={},h&&(l["@context"]=s),l[f]=m}else if($p(l)&&h){let f=l;l={"@context":s};for(let m in f)l[m]=f[m]}return l},n.expand=async function(o,s){if(arguments.length<1)throw new TypeError("Could not expand, too few arguments.");s=i(s,{keepFreeFloatingNodes:!1,contextResolver:new Ql({sharedCache:r})});let a={},c=[];if("expandContext"in s){let h=Gf.clone(s.expandContext);$p(h)&&"@context"in h?a.expandContext=h:a.expandContext={"@context":h},c.push(a.expandContext)}let u;if(!Tu(o))a.input=Gf.clone(o);else{let h=await n.get(o,s);u=h.documentUrl,a.input=h.document,h.contextUrl&&(a.remoteContext={"@context":h.contextUrl},c.push(a.remoteContext))}"base"in s||(s.base=u||"");let l=j3(s);for(let h of c)l=await ZV({activeCtx:l,localCtx:h,options:s});let d=await vfe({activeCtx:l,element:a.input,options:s});return $p(d)&&"@graph"in d&&Object.keys(d).length===1?d=d["@graph"]:d===null&&(d=[]),Ug(d)||(d=[d]),d},n.flatten=async function(o,s,a){if(arguments.length<1)return new TypeError("Could not flatten, too few arguments.");typeof s=="function"?s=null:s=s||null,a=i(a,{base:Tu(o)?o:"",contextResolver:new Ql({sharedCache:r})});let c=await n.expand(o,a),u=Sfe(c);return s===null?u:(a.graph=!0,a.skipExpansion=!0,await n.compact(u,s,a))},n.frame=async function(o,s,a){if(arguments.length<2)throw new TypeError("Could not frame, too few arguments.");if(a=i(a,{base:Tu(o)?o:"",embed:"@once",explicit:!1,requireAll:!1,omitDefault:!1,bnodesToClear:[],contextResolver:new Ql({sharedCache:r})}),Tu(s)){let b=await n.get(s,a);if(s=b.document,b.contextUrl){let S=s["@context"];S?Ug(S)?S.push(b.contextUrl):S=[S,b.contextUrl]:S=b.contextUrl,s["@context"]=S}}let c=s?s["@context"]||{}:{},u=await n.processContext(j3(a),c,a);a.hasOwnProperty("omitGraph")||(a.omitGraph=u6(u,1.1)),a.hasOwnProperty("pruneBlankNodeIdentifiers")||(a.pruneBlankNodeIdentifiers=u6(u,1.1));let l=await n.expand(o,a),d={...a};d.isFrame=!0,d.keepFreeFloatingNodes=!0;let h=await n.expand(s,d),f=Object.keys(s).map(b=>Bfe(u,b,{vocab:!0}));d.merged=!f.includes("@graph"),d.is11=u6(u,1.1);let m=Rfe(l,h,d);d.graph=!a.omitGraph,d.skipExpansion=!0,d.link={},d.framing=!0;let w=await n.compact(m,c,d);return d.link={},w=Dfe(w,d),w},n.link=async function(o,s,a){let c={};return s&&(c["@context"]=s),c["@embed"]="@link",n.frame(o,c,a)},n.normalize=n.canonize=async function(o,s){if(arguments.length<1)throw new TypeError("Could not canonize, too few arguments.");if(s=i(s,{base:Tu(o)?o:null,algorithm:"URDNA2015",skipExpansion:!1,safe:!0,contextResolver:new Ql({sharedCache:r})}),"inputFormat"in s){if(s.inputFormat!=="application/n-quads"&&s.inputFormat!=="application/nquads")throw new Du("Unknown canonicalization input format.","jsonld.CanonizeError");let u=Y3.parse(o);return jV.canonize(u,s)}let a={...s};delete a.format,a.produceGeneralizedRdf=!1;let c=await n.toRDF(o,a);return jV.canonize(c,s)},n.fromRDF=async function(o,s){if(arguments.length<1)throw new TypeError("Could not convert from RDF, too few arguments.");s=i(s,{format:Tu(o)?"application/n-quads":void 0});let{format:a}=s,{rdfParser:c}=s;if(a){if(c=c||e[a],!c)throw new Du("Unknown input format.","jsonld.UnknownFormat",{format:a})}else c=()=>o;let u=await c(o);return Cfe(u,s)},n.toRDF=async function(o,s){if(arguments.length<1)throw new TypeError("Could not convert to RDF, too few arguments.");s=i(s,{base:Tu(o)?o:"",skipExpansion:!1,contextResolver:new Ql({sharedCache:r})});let a;s.skipExpansion?a=o:a=await n.expand(o,s);let c=Lfe(a,s);if(s.format){if(s.format==="application/n-quads"||s.format==="application/nquads")return Y3.serialize(c);throw new Du("Unknown output format.","jsonld.UnknownFormat",{format:s.format})}return c},n.createNodeMap=async function(o,s){if(arguments.length<1)throw new TypeError("Could not create node map, too few arguments.");s=i(s,{base:Tu(o)?o:"",contextResolver:new Ql({sharedCache:r})});let a=await n.expand(o,s);return Ofe(a,s)},n.merge=async function(o,s,a){if(arguments.length<1)throw new TypeError("Could not merge, too few arguments.");if(!Ug(o))throw new TypeError('Could not merge, "docs" must be an array.');typeof s=="function"?s=null:s=s||null,a=i(a,{contextResolver:new Ql({sharedCache:r})});let c=await Promise.all(o.map(b=>{let S={...a};return n.expand(b,S)})),u=!0;"mergeNodes"in a&&(u=a.mergeNodes);let l=a.issuer||new c6("_:b"),d={"@default":{}};for(let b=0;b<c.length;++b){let S=Gf.relabelBlankNodes(c[b],{issuer:new c6("_:b"+b+"-")}),R=u||b===0?d:{"@default":{}};if(Mfe(S,R,"@default",l),R!==d)for(let G in R){let U=R[G];if(!(G in d)){d[G]=U;continue}let H=d[G];for(let M in U)M in H||(H[M]=U[M])}}let h=Ffe(d),f=[],m=Object.keys(h).sort();for(let b=0;b<m.length;++b){let S=h[m[b]];Tfe(S)||f.push(S)}return s===null?f:(a.graph=!0,a.skipExpansion=!0,await n.compact(f,s,a))},Object.defineProperty(n,"documentLoader",{get:()=>n._documentLoader,set:o=>n._documentLoader=o}),n.documentLoader=async o=>{throw new Du("Could not retrieve a JSON-LD document from the URL. URL dereferencing not implemented.","jsonld.LoadDocumentError",{code:"loading document failed",url:o})},n.get=async function(o,s){let a;typeof s.documentLoader=="function"?a=s.documentLoader:a=n.documentLoader;let c=await a(o);try{if(!c.document)throw new Du("No remote document found at the given URL.","jsonld.NullRemoteDocument");Tu(c.document)&&(c.document=JSON.parse(c.document))}catch(u){throw new Du("Could not retrieve a JSON-LD document from the URL.","jsonld.LoadDocumentError",{code:"loading document failed",cause:u,remoteDoc:c})}return c},n.processContext=async function(o,s,a){return a=i(a,{base:"",contextResolver:new Ql({sharedCache:r})}),s===null?j3(a):(s=Gf.clone(s),$p(s)&&"@context"in s||(s={"@context":s}),ZV({activeCtx:o,localCtx:s,options:a}))},n.getContextValue=Of().getContextValue,n.documentLoaders={},n.useDocumentLoader=function(o){if(!(o in n.documentLoaders))throw new Du('Unknown document loader type: "'+o+'"',"jsonld.UnknownDocumentLoader",{type:o});n.documentLoader=n.documentLoaders[o].apply(n,Array.prototype.slice.call(arguments,1))},n.registerRDFParser=function(o,s){e[o]=s},n.unregisterRDFParser=function(o){delete e[o]},n.registerRDFParser("application/n-quads",Y3.parse),n.registerRDFParser("application/nquads",Y3.parse),n.url=Cu(),n.logEventHandler=Nfe,n.logWarningEventHandler=Ufe,n.safeEventHandler=Gfe,n.setDefaultEventHandler=Hfe,n.strictEventHandler=Jfe,n.unhandledEventHandler=qfe,n.util=Gf,Object.assign(n,Gf),n.promises=n,n.RequestQueue=TT(),n.JsonLdProcessor=YV()(n),WV.setupGlobals(n),WV.setupDocumentLoaders(n);function i(o,{documentLoader:s=n.documentLoader,...a}){if(o&&"compactionMap"in o)throw new Du('"compactionMap" not supported.',"jsonld.OptionsError");if(o&&"expansionMap"in o)throw new Du('"expansionMap" not supported.',"jsonld.OptionsError");return Object.assign({},{documentLoader:s},a,o,{eventHandler:Kfe({options:o})})}return n},l6=function(){return XV(function(){return l6()})};XV(l6);_V.exports=l6});var BQ=oe((XHe,TQ)=>{"use strict";var cv=WR().Buffer;function She(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if((Array.isArray(f)||f instanceof Uint8Array)&&(f=cv.from(f)),!cv.isBuffer(f))throw new TypeError("Expected Buffer");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return cv.alloc(0);for(var m=0,w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);m<f.length;){var G=f.charCodeAt(m);if(G>255)return;var U=e[G];if(U===255)return;for(var H=0,M=S-1;(U!==0||H<b)&&M!==-1;M--,H++)U+=s*R[M]>>>0,R[M]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=H,m++}for(var A=S-b;A!==S&&R[A]===0;)A++;var D=cv.allocUnsafe(w+(S-A));D.fill(0,0,w);for(var z=w;A!==S;)D[z++]=R[A++];return D}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}TQ.exports=She});var kQ=oe((_He,PQ)=>{"use strict";var Che=BQ(),Lhe="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";PQ.exports=Che(Lhe)});var D6=oe(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.s16=he.s8=he.nu64be=he.u48be=he.u40be=he.u32be=he.u24be=he.u16be=he.nu64=he.u48=he.u40=he.u32=he.u24=he.u16=he.u8=he.offset=he.greedy=he.Constant=he.UTF8=he.CString=he.Blob=he.Boolean=he.BitField=he.BitStructure=he.VariantLayout=he.Union=he.UnionLayoutDiscriminator=he.UnionDiscriminator=he.Structure=he.Sequence=he.DoubleBE=he.Double=he.FloatBE=he.Float=he.NearInt64BE=he.NearInt64=he.NearUInt64BE=he.NearUInt64=he.IntBE=he.Int=he.UIntBE=he.UInt=he.OffsetLayout=he.GreedyCount=he.ExternalLayout=he.bindConstructorLayout=he.nameWithProperty=he.Layout=he.uint8ArrayToBuffer=he.checkUint8Array=void 0;he.constant=he.utf8=he.cstr=he.blob=he.unionLayoutDiscriminator=he.union=he.seq=he.bits=he.struct=he.f64be=he.f64=he.f32be=he.f32=he.ns64be=he.s48be=he.s40be=he.s32be=he.s24be=he.s16be=he.ns64=he.s48=he.s40=he.s32=he.s24=void 0;var L6=_m();function zg(n){if(!(n instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}he.checkUint8Array=zg;function wn(n){return zg(n),L6.Buffer.from(n.buffer,n.byteOffset,n.length)}he.uint8ArrayToBuffer=wn;var Cn=class{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){let t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}};he.Layout=Cn;function R6(n,e){return e.property?n+"["+e.property+"]":n}he.nameWithProperty=R6;function Fhe(n,e){if(typeof n!="function")throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(n,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Cn))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");n.layout_=e,e.boundConstructor_=n,e.makeDestinationObject=(()=>new n),Object.defineProperty(n.prototype,"encode",{value(t,r){return e.encode(this,t,r)},writable:!0}),Object.defineProperty(n,"decode",{value(t,r){return e.decode(t,r)},writable:!0})}he.bindConstructorLayout=Fhe;var Zi=class extends Cn{isCount(){throw new Error("ExternalLayout is abstract")}};he.ExternalLayout=Zi;var mv=class extends Zi{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return!0}decode(e,t=0){zg(e);let r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}};he.GreedyCount=mv;var Z2=class extends Zi{constructor(e,t=0,r){if(!(e instanceof Cn))throw new TypeError("layout must be a Layout");if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof gs||this.layout instanceof js}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,r=0){return this.layout.encode(e,t,r+this.offset)}};he.OffsetLayout=Z2;var gs=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readUIntLE(t,this.span)}encode(e,t,r=0){return wn(t).writeUIntLE(e,r,this.span),this.span}};he.UInt=gs;var js=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readUIntBE(t,this.span)}encode(e,t,r=0){return wn(t).writeUIntBE(e,r,this.span),this.span}};he.UIntBE=js;var ed=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readIntLE(t,this.span)}encode(e,t,r=0){return wn(t).writeIntLE(e,r,this.span),this.span}};he.Int=ed;var qf=class extends Cn{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return wn(e).readIntBE(t,this.span)}encode(e,t,r=0){return wn(t).writeIntBE(e,r,this.span),this.span}};he.IntBE=qf;var C6=Math.pow(2,32);function Pv(n){let e=Math.floor(n/C6),t=n-e*C6;return{hi32:e,lo32:t}}function kv(n,e){return n*C6+e}var gv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32LE(t),o=r.readUInt32LE(t+4);return kv(o,i)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32LE(i.lo32,r),o.writeUInt32LE(i.hi32,r+4),8}};he.NearUInt64=gv;var yv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32BE(t),o=r.readUInt32BE(t+4);return kv(i,o)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32BE(i.hi32,r),o.writeUInt32BE(i.lo32,r+4),8}};he.NearUInt64BE=yv;var wv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readUInt32LE(t),o=r.readInt32LE(t+4);return kv(o,i)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeUInt32LE(i.lo32,r),o.writeInt32LE(i.hi32,r+4),8}};he.NearInt64=wv;var bv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){let r=wn(e),i=r.readInt32BE(t),o=r.readUInt32BE(t+4);return kv(i,o)}encode(e,t,r=0){let i=Pv(e),o=wn(t);return o.writeInt32BE(i.hi32,r),o.writeUInt32BE(i.lo32,r+4),8}};he.NearInt64BE=bv;var Ev=class extends Cn{constructor(e){super(4,e)}decode(e,t=0){return wn(e).readFloatLE(t)}encode(e,t,r=0){return wn(t).writeFloatLE(e,r),4}};he.Float=Ev;var Iv=class extends Cn{constructor(e){super(4,e)}decode(e,t=0){return wn(e).readFloatBE(t)}encode(e,t,r=0){return wn(t).writeFloatBE(e,r),4}};he.FloatBE=Iv;var Av=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){return wn(e).readDoubleLE(t)}encode(e,t,r=0){return wn(t).writeDoubleLE(e,r),8}};he.Double=Av;var xv=class extends Cn{constructor(e){super(8,e)}decode(e,t=0){return wn(e).readDoubleBE(t)}encode(e,t,r=0){return wn(t).writeDoubleBE(e,r),8}};he.DoubleBE=xv;var vv=class extends Cn{constructor(e,t,r){if(!(e instanceof Cn))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof Zi&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let i=-1;!(t instanceof Zi)&&0<e.span&&(i=t*e.span),super(i,r),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0,i=this.count;if(i instanceof Zi&&(i=i.decode(e,t)),0<this.elementLayout.span)r=i*this.elementLayout.span;else{let o=0;for(;o<i;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t=0){let r=[],i=0,o=this.count;for(o instanceof Zi&&(o=o.decode(e,t));i<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),i+=1;return r}encode(e,t,r=0){let i=this.elementLayout,o=e.reduce((s,a)=>s+i.encode(a,t,r+s),0);return this.count instanceof Zi&&this.count.encode(e.length,t,r),o}};he.Sequence=vv;var Sv=class extends Cn{constructor(e,t,r){if(!(Array.isArray(e)&&e.reduce((o,s)=>o&&s instanceof Cn,!0)))throw new TypeError("fields must be array of Layout instances");typeof t=="boolean"&&r===void 0&&(r=t,t=void 0);for(let o of e)if(0>o.span&&o.property===void 0)throw new Error("fields cannot contain unnamed variable-length layout");let i=-1;try{i=e.reduce((o,s)=>o+s.getSpan(),0)}catch{}super(i,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;try{r=this.fields.reduce((i,o)=>{let s=o.getSpan(e,t);return t+=s,i+s},0)}catch{throw new RangeError("indeterminate span")}return r}decode(e,t=0){zg(e);let r=this.makeDestinationObject();for(let i of this.fields)if(i.property!==void 0&&(r[i.property]=i.decode(e,t)),t+=i.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r=0){let i=r,o=0,s=0;for(let a of this.fields){let c=a.span;if(s=0<c?c:0,a.property!==void 0){let u=e[a.property];u!==void 0&&(s=a.encode(u,t,r),0>c&&(c=a.getSpan(t,r)))}o=r,r+=c}return o+s-i}fromArray(e){let t=this.makeDestinationObject();for(let r of this.fields)r.property!==void 0&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}offsetOf(e){if(typeof e!="string")throw new TypeError("property must be string");let t=0;for(let r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}};he.Structure=Sv;var X2=class{constructor(e){this.property=e}decode(e,t){throw new Error("UnionDiscriminator is abstract")}encode(e,t,r){throw new Error("UnionDiscriminator is abstract")}};he.UnionDiscriminator=X2;var Qg=class extends X2{constructor(e,t){if(!(e instanceof Zi&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}};he.UnionLayoutDiscriminator=Qg;var _2=class extends Cn{constructor(e,t,r){let i;if(e instanceof gs||e instanceof js)i=new Qg(new Z2(e));else if(e instanceof Zi&&e.isCount())i=new Qg(e);else if(e instanceof X2)i=e;else throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(t===void 0&&(t=null),!(t===null||t instanceof Cn))throw new TypeError("defaultLayout must be null or a Layout");if(t!==null){if(0>t.span)throw new Error("defaultLayout must have constant span");t.property===void 0&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&(e instanceof gs||e instanceof js)&&(o+=i.layout.span)),super(o,r),this.discriminator=i,this.usesPrefixDiscriminator=e instanceof gs||e instanceof js,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(a){return s(a)},this.configGetSourceVariant=function(a){s=a.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;let r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(Object.prototype.hasOwnProperty.call(e,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(e,this.defaultLayout.property))return;let t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||t.property&&Object.prototype.hasOwnProperty.call(e,t.property)))return t}else for(let t in this.registry){let r=this.registry[t];if(r.property&&Object.prototype.hasOwnProperty.call(e,r.property))return r}throw new Error("unable to infer src variant")}decode(e,t=0){let r,i=this.discriminator,o=i.decode(e,t),s=this.registry[o];if(s===void 0){let a=this.defaultLayout,c=0;this.usesPrefixDiscriminator&&(c=i.layout.span),r=this.makeDestinationObject(),r[i.property]=o,r[a.property]=a.decode(e,t+c)}else r=s.decode(e,t);return r}encode(e,t,r=0){let i=this.getSourceVariant(e);if(i===void 0){let o=this.discriminator,s=this.defaultLayout,a=0;return this.usesPrefixDiscriminator&&(a=o.layout.span),o.encode(e[o.property],t,r),a+s.encode(e[s.property],t,r+a)}return i.encode(e,t,r)}addVariant(e,t,r){let i=new Cv(this,e,t,r);return this.registry[e]=i,i}getVariant(e,t=0){let r;return e instanceof Uint8Array?r=this.discriminator.decode(e,t):r=e,this.registry[r]}};he.Union=_2;var Cv=class extends Cn{constructor(e,t,r,i){if(!(e instanceof _2))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if(typeof r=="string"&&i===void 0&&(i=r,r=null),r){if(!(r instanceof Cn))throw new TypeError("layout must be a Layout");if(e.defaultLayout!==null&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if(typeof i!="string")throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,i),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t=0){if(0<=this.span)return this.span;let r=0;this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span);let i=0;return this.layout&&(i=this.layout.getSpan(e,t+r)),r+i}decode(e,t=0){let r=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let i=0;return this.union.usesPrefixDiscriminator&&(i=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+i):this.property?r[this.property]=!0:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r=0){let i=0;if(this.union.usesPrefixDiscriminator&&(i=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=i;if(this.layout&&(this.layout.encode(e[this.property],t,r+i),o+=this.layout.getSpan(t,r+i),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}};he.VariantLayout=Cv;function Vg(n){return 0>n&&(n+=4294967296),n}var $2=class extends Cn{constructor(e,t,r){if(!(e instanceof gs||e instanceof js))throw new TypeError("word must be a UInt or UIntBE layout");if(typeof t=="string"&&r===void 0&&(r=t,t=!1),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let i=0;this._packedSetValue=function(o){return i=Vg(o),this},this._packedGetValue=function(){return i}}decode(e,t=0){let r=this.makeDestinationObject(),i=this.word.decode(e,t);this._packedSetValue(i);for(let o of this.fields)o.property!==void 0&&(r[o.property]=o.decode(e));return r}encode(e,t,r=0){let i=this.word.decode(t,r);this._packedSetValue(i);for(let o of this.fields)if(o.property!==void 0){let s=e[o.property];s!==void 0&&o.encode(s)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){let r=new e1(this,e,t);return this.fields.push(r),r}addBoolean(e){let t=new Lv(this,e);return this.fields.push(t),t}fieldFor(e){if(typeof e!="string")throw new TypeError("property must be string");for(let t of this.fields)if(t.property===e)return t}};he.BitStructure=$2;var e1=class{constructor(e,t,r){if(!(e instanceof $2))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");let i=8*e.span,o=e.fields.reduce((s,a)=>s+a.bits,0);if(t+o>i)throw new Error("bits too long for span remainder ("+(i-o)+" of "+i+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,t===32&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=i-o-t),this.wordMask=Vg(this.valueMask<<this.start),this.property=r}decode(e,t){let r=this.container._packedGetValue();return Vg(r&this.wordMask)>>>this.start}encode(e){if(typeof e!="number"||!Number.isInteger(e)||e!==Vg(e&this.valueMask))throw new TypeError(R6("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);let t=this.container._packedGetValue(),r=Vg(e<<this.start);this.container._packedSetValue(Vg(t&~this.wordMask)|r)}};he.BitField=e1;var Lv=class extends e1{constructor(e,t){super(e,1,t)}decode(e,t){return!!super.decode(e,t)}encode(e){typeof e=="boolean"&&(e=+e),super.encode(e)}};he.Boolean=Lv;var Rv=class extends Cn{constructor(e,t){if(!(e instanceof Zi&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof Zi||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t=0){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),wn(e).slice(t,t+r)}encode(e,t,r){let i=this.length;if(this.length instanceof Zi&&(i=e.length),!(e instanceof Uint8Array&&i===e.length))throw new TypeError(R6("Blob.encode",this)+" requires (length "+i+") Uint8Array as src");if(r+i>t.length)throw new RangeError("encoding overruns Uint8Array");let o=wn(e);return wn(t).write(o.toString("hex"),r,i,"hex"),this.length instanceof Zi&&this.length.encode(i,t,r),i}};he.Blob=Rv;var Dv=class extends Cn{constructor(e){super(-1,e)}getSpan(e,t=0){zg(e);let r=t;for(;r<e.length&&e[r]!==0;)r+=1;return 1+r-t}decode(e,t=0){let r=this.getSpan(e,t);return wn(e).slice(t,t+r-1).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let i=L6.Buffer.from(e,"utf8"),o=i.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");let s=wn(t);return i.copy(s,r),s[r+o]=0,o+1}};he.CString=Dv;var Tv=class extends Cn{constructor(e,t){if(typeof e=="string"&&t===void 0&&(t=e,e=void 0),e===void 0)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t=0){return zg(e),e.length-t}decode(e,t=0){let r=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<r)throw new RangeError("text length exceeds maxSpan");return wn(e).slice(t,t+r).toString("utf-8")}encode(e,t,r=0){typeof e!="string"&&(e=String(e));let i=L6.Buffer.from(e,"utf8"),o=i.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return i.copy(wn(t),r),o}};he.UTF8=Tv;var Bv=class extends Cn{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,r){return 0}};he.Constant=Bv;he.greedy=((n,e)=>new mv(n,e));he.offset=((n,e,t)=>new Z2(n,e,t));he.u8=(n=>new gs(1,n));he.u16=(n=>new gs(2,n));he.u24=(n=>new gs(3,n));he.u32=(n=>new gs(4,n));he.u40=(n=>new gs(5,n));he.u48=(n=>new gs(6,n));he.nu64=(n=>new gv(n));he.u16be=(n=>new js(2,n));he.u24be=(n=>new js(3,n));he.u32be=(n=>new js(4,n));he.u40be=(n=>new js(5,n));he.u48be=(n=>new js(6,n));he.nu64be=(n=>new yv(n));he.s8=(n=>new ed(1,n));he.s16=(n=>new ed(2,n));he.s24=(n=>new ed(3,n));he.s32=(n=>new ed(4,n));he.s40=(n=>new ed(5,n));he.s48=(n=>new ed(6,n));he.ns64=(n=>new wv(n));he.s16be=(n=>new qf(2,n));he.s24be=(n=>new qf(3,n));he.s32be=(n=>new qf(4,n));he.s40be=(n=>new qf(5,n));he.s48be=(n=>new qf(6,n));he.ns64be=(n=>new bv(n));he.f32=(n=>new Ev(n));he.f32be=(n=>new Iv(n));he.f64=(n=>new Av(n));he.f64be=(n=>new xv(n));he.struct=((n,e,t)=>new Sv(n,e,t));he.bits=((n,e,t)=>new $2(n,e,t));he.seq=((n,e,t)=>new vv(n,e,t));he.union=((n,e,t)=>new _2(n,e,t));he.unionLayoutDiscriminator=((n,e)=>new Qg(n,e));he.blob=((n,e)=>new Rv(n,e));he.cstr=(n=>new Dv(n));he.utf8=((n,e)=>new Tv(n,e));he.constant=((n,e)=>new Bv(n,e))});function r1(){if(!Nv&&(Nv=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Nv))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Nv(Zge)}var Nv,Zge,H6=co(()=>{"use strict";Zge=new Uint8Array(16)});var cz,uz=co(()=>{"use strict";cz=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i});function Xge(n){return typeof n=="string"&&cz.test(n)}var Qf,i1=co(()=>{"use strict";uz();Qf=Xge});function _ge(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(Ri[n[e+0]]+Ri[n[e+1]]+Ri[n[e+2]]+Ri[n[e+3]]+"-"+Ri[n[e+4]]+Ri[n[e+5]]+"-"+Ri[n[e+6]]+Ri[n[e+7]]+"-"+Ri[n[e+8]]+Ri[n[e+9]]+"-"+Ri[n[e+10]]+Ri[n[e+11]]+Ri[n[e+12]]+Ri[n[e+13]]+Ri[n[e+14]]+Ri[n[e+15]]).toLowerCase();if(!Qf(t))throw TypeError("Stringified UUID is invalid");return t}var Ri,Uv,zf,o1=co(()=>{"use strict";i1();Ri=[];for(Uv=0;Uv<256;++Uv)Ri.push((Uv+256).toString(16).substr(1));zf=_ge});function $ge(n,e,t){var r=e&&t||0,i=e||new Array(16);n=n||{};var o=n.node||lz,s=n.clockseq!==void 0?n.clockseq:K6;if(o==null||s==null){var a=n.random||(n.rng||r1)();o==null&&(o=lz=[a[0]|1,a[1],a[2],a[3],a[4],a[5]]),s==null&&(s=K6=(a[6]<<8|a[7])&16383)}var c=n.msecs!==void 0?n.msecs:Date.now(),u=n.nsecs!==void 0?n.nsecs:q6+1,l=c-J6+(u-q6)/1e4;if(l<0&&n.clockseq===void 0&&(s=s+1&16383),(l<0||c>J6)&&n.nsecs===void 0&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");J6=c,q6=u,K6=s,c+=122192928e5;var d=((c&268435455)*1e4+u)%4294967296;i[r++]=d>>>24&255,i[r++]=d>>>16&255,i[r++]=d>>>8&255,i[r++]=d&255;var h=c/4294967296*1e4&268435455;i[r++]=h>>>8&255,i[r++]=h&255,i[r++]=h>>>24&15|16,i[r++]=h>>>16&255,i[r++]=s>>>8|128,i[r++]=s&255;for(var f=0;f<6;++f)i[r+f]=o[f];return e||zf(i)}var lz,K6,J6,q6,dz,fz=co(()=>{"use strict";H6();o1();J6=0,q6=0;dz=$ge});function eye(n){if(!Qf(n))throw TypeError("Invalid UUID");var e,t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}var Gv,V6=co(()=>{"use strict";i1();Gv=eye});function tye(n){n=unescape(encodeURIComponent(n));for(var e=[],t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}function Hv(n,e,t){function r(i,o,s,a){if(typeof i=="string"&&(i=tye(i)),typeof o=="string"&&(o=Gv(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var c=new Uint8Array(16+i.length);if(c.set(o),c.set(i,o.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,s){a=a||0;for(var u=0;u<16;++u)s[a+u]=c[u];return s}return zf(c)}try{r.name=n}catch{}return r.DNS=nye,r.URL=rye,r}var nye,rye,Q6=co(()=>{"use strict";o1();V6();nye="6ba7b810-9dad-11d1-80b4-00c04fd430c8",rye="6ba7b811-9dad-11d1-80b4-00c04fd430c8"});function iye(n){if(typeof n=="string"){var e=unescape(encodeURIComponent(n));n=new Uint8Array(e.length);for(var t=0;t<e.length;++t)n[t]=e.charCodeAt(t)}return oye(sye(aye(n),n.length*8))}function oye(n){for(var e=[],t=n.length*32,r="0123456789abcdef",i=0;i<t;i+=8){var o=n[i>>5]>>>i%32&255,s=parseInt(r.charAt(o>>>4&15)+r.charAt(o&15),16);e.push(s)}return e}function hz(n){return(n+64>>>9<<4)+14+1}function sye(n,e){n[e>>5]|=128<<e%32,n[hz(e)-1]=e;for(var t=1732584193,r=-271733879,i=-1732584194,o=271733878,s=0;s<n.length;s+=16){var a=t,c=r,u=i,l=o;t=_i(t,r,i,o,n[s],7,-680876936),o=_i(o,t,r,i,n[s+1],12,-389564586),i=_i(i,o,t,r,n[s+2],17,606105819),r=_i(r,i,o,t,n[s+3],22,-1044525330),t=_i(t,r,i,o,n[s+4],7,-176418897),o=_i(o,t,r,i,n[s+5],12,1200080426),i=_i(i,o,t,r,n[s+6],17,-1473231341),r=_i(r,i,o,t,n[s+7],22,-45705983),t=_i(t,r,i,o,n[s+8],7,1770035416),o=_i(o,t,r,i,n[s+9],12,-1958414417),i=_i(i,o,t,r,n[s+10],17,-42063),r=_i(r,i,o,t,n[s+11],22,-1990404162),t=_i(t,r,i,o,n[s+12],7,1804603682),o=_i(o,t,r,i,n[s+13],12,-40341101),i=_i(i,o,t,r,n[s+14],17,-1502002290),r=_i(r,i,o,t,n[s+15],22,1236535329),t=$i(t,r,i,o,n[s+1],5,-165796510),o=$i(o,t,r,i,n[s+6],9,-1069501632),i=$i(i,o,t,r,n[s+11],14,643717713),r=$i(r,i,o,t,n[s],20,-373897302),t=$i(t,r,i,o,n[s+5],5,-701558691),o=$i(o,t,r,i,n[s+10],9,38016083),i=$i(i,o,t,r,n[s+15],14,-660478335),r=$i(r,i,o,t,n[s+4],20,-405537848),t=$i(t,r,i,o,n[s+9],5,568446438),o=$i(o,t,r,i,n[s+14],9,-1019803690),i=$i(i,o,t,r,n[s+3],14,-187363961),r=$i(r,i,o,t,n[s+8],20,1163531501),t=$i(t,r,i,o,n[s+13],5,-1444681467),o=$i(o,t,r,i,n[s+2],9,-51403784),i=$i(i,o,t,r,n[s+7],14,1735328473),r=$i(r,i,o,t,n[s+12],20,-1926607734),t=eo(t,r,i,o,n[s+5],4,-378558),o=eo(o,t,r,i,n[s+8],11,-2022574463),i=eo(i,o,t,r,n[s+11],16,1839030562),r=eo(r,i,o,t,n[s+14],23,-35309556),t=eo(t,r,i,o,n[s+1],4,-1530992060),o=eo(o,t,r,i,n[s+4],11,1272893353),i=eo(i,o,t,r,n[s+7],16,-155497632),r=eo(r,i,o,t,n[s+10],23,-1094730640),t=eo(t,r,i,o,n[s+13],4,681279174),o=eo(o,t,r,i,n[s],11,-358537222),i=eo(i,o,t,r,n[s+3],16,-722521979),r=eo(r,i,o,t,n[s+6],23,76029189),t=eo(t,r,i,o,n[s+9],4,-640364487),o=eo(o,t,r,i,n[s+12],11,-421815835),i=eo(i,o,t,r,n[s+15],16,530742520),r=eo(r,i,o,t,n[s+2],23,-995338651),t=to(t,r,i,o,n[s],6,-198630844),o=to(o,t,r,i,n[s+7],10,1126891415),i=to(i,o,t,r,n[s+14],15,-1416354905),r=to(r,i,o,t,n[s+5],21,-57434055),t=to(t,r,i,o,n[s+12],6,1700485571),o=to(o,t,r,i,n[s+3],10,-1894986606),i=to(i,o,t,r,n[s+10],15,-1051523),r=to(r,i,o,t,n[s+1],21,-2054922799),t=to(t,r,i,o,n[s+8],6,1873313359),o=to(o,t,r,i,n[s+15],10,-30611744),i=to(i,o,t,r,n[s+6],15,-1560198380),r=to(r,i,o,t,n[s+13],21,1309151649),t=to(t,r,i,o,n[s+4],6,-145523070),o=to(o,t,r,i,n[s+11],10,-1120210379),i=to(i,o,t,r,n[s+2],15,718787259),r=to(r,i,o,t,n[s+9],21,-343485551),t=Yf(t,a),r=Yf(r,c),i=Yf(i,u),o=Yf(o,l)}return[t,r,i,o]}function aye(n){if(n.length===0)return[];for(var e=n.length*8,t=new Uint32Array(hz(e)),r=0;r<e;r+=8)t[r>>5]|=(n[r/8]&255)<<r%32;return t}function Yf(n,e){var t=(n&65535)+(e&65535),r=(n>>16)+(e>>16)+(t>>16);return r<<16|t&65535}function cye(n,e){return n<<e|n>>>32-e}function Kv(n,e,t,r,i,o){return Yf(cye(Yf(Yf(e,n),Yf(r,o)),i),t)}function _i(n,e,t,r,i,o,s){return Kv(e&t|~e&r,n,e,i,o,s)}function $i(n,e,t,r,i,o,s){return Kv(e&r|t&~r,n,e,i,o,s)}function eo(n,e,t,r,i,o,s){return Kv(e^t^r,n,e,i,o,s)}function to(n,e,t,r,i,o,s){return Kv(t^(e|~r),n,e,i,o,s)}var pz,mz=co(()=>{"use strict";pz=iye});var uye,gz,yz=co(()=>{"use strict";Q6();mz();uye=Hv("v3",48,pz),gz=uye});function lye(n,e,t){n=n||{};var r=n.random||(n.rng||r1)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){t=t||0;for(var i=0;i<16;++i)e[t+i]=r[i];return e}return zf(r)}var wz,bz=co(()=>{"use strict";H6();o1();wz=lye});function dye(n,e,t,r){switch(n){case 0:return e&t^~e&r;case 1:return e^t^r;case 2:return e&t^e&r^t&r;case 3:return e^t^r}}function z6(n,e){return n<<e|n>>>32-e}function fye(n){var e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){var r=unescape(encodeURIComponent(n));n=[];for(var i=0;i<r.length;++i)n.push(r.charCodeAt(i))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);for(var o=n.length/4+2,s=Math.ceil(o/16),a=new Array(s),c=0;c<s;++c){for(var u=new Uint32Array(16),l=0;l<16;++l)u[l]=n[c*64+l*4]<<24|n[c*64+l*4+1]<<16|n[c*64+l*4+2]<<8|n[c*64+l*4+3];a[c]=u}a[s-1][14]=(n.length-1)*8/Math.pow(2,32),a[s-1][14]=Math.floor(a[s-1][14]),a[s-1][15]=(n.length-1)*8&4294967295;for(var d=0;d<s;++d){for(var h=new Uint32Array(80),f=0;f<16;++f)h[f]=a[d][f];for(var m=16;m<80;++m)h[m]=z6(h[m-3]^h[m-8]^h[m-14]^h[m-16],1);for(var w=t[0],b=t[1],S=t[2],R=t[3],G=t[4],U=0;U<80;++U){var H=Math.floor(U/20),M=z6(w,5)+dye(H,b,S,R)+G+e[H]+h[U]>>>0;G=R,R=S,S=z6(b,30)>>>0,b=w,w=M}t[0]=t[0]+w>>>0,t[1]=t[1]+b>>>0,t[2]=t[2]+S>>>0,t[3]=t[3]+R>>>0,t[4]=t[4]+G>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var Ez,Iz=co(()=>{"use strict";Ez=fye});var hye,Az,xz=co(()=>{"use strict";Q6();Iz();hye=Hv("v5",80,Ez),Az=hye});var vz,Sz=co(()=>{"use strict";vz="00000000-0000-0000-0000-000000000000"});function pye(n){if(!Qf(n))throw TypeError("Invalid UUID");return parseInt(n.substr(14,1),16)}var Cz,Lz=co(()=>{"use strict";i1();Cz=pye});var Y6={};Rr(Y6,{NIL:()=>vz,parse:()=>Gv,stringify:()=>zf,v1:()=>dz,v3:()=>gz,v4:()=>wz,v5:()=>Az,validate:()=>Qf,version:()=>Cz});var j6=co(()=>{"use strict";fz();yz();bz();xz();Sz();Lz();i1();o1();V6()});var Dz=oe((sJe,Rz)=>{"use strict";var mye=(j6(),$8(Y6)).v4,gye=function(n,e,t,r){if(typeof n!="string")throw new TypeError(n+" must be a string");r=r||{};let i=typeof r.version=="number"?r.version:2;if(i!==1&&i!==2)throw new TypeError(i+" must be 1 or 2");let o={method:n};if(i===2&&(o.jsonrpc="2.0"),e){if(typeof e!="object"&&!Array.isArray(e))throw new TypeError(e+" must be an object, array or omitted");o.params=e}if(typeof t>"u"){let s=typeof r.generator=="function"?r.generator:function(){return mye()};o.id=s(o,r)}else i===2&&t===null?r.notificationIdNull&&(o.id=null):o.id=t;return o};Rz.exports=gye});var Bz=oe((aJe,Tz)=>{"use strict";var yye=(j6(),$8(Y6)).v4,wye=Dz(),s1=function(n,e){if(!(this instanceof s1))return new s1(n,e);e||(e={}),this.options={reviver:typeof e.reviver<"u"?e.reviver:null,replacer:typeof e.replacer<"u"?e.replacer:null,generator:typeof e.generator<"u"?e.generator:function(){return yye()},version:typeof e.version<"u"?e.version:2,notificationIdNull:typeof e.notificationIdNull=="boolean"?e.notificationIdNull:!1},this.callServer=n};Tz.exports=s1;s1.prototype.request=function(n,e,t,r){let i=this,o=null,s=Array.isArray(n)&&typeof e=="function";if(this.options.version===1&&s)throw new TypeError("JSON-RPC 1.0 does not support batching");if(s||!s&&n&&typeof n=="object"&&typeof e=="function")r=e,o=n;else{typeof t=="function"&&(r=t,t=void 0);let u=typeof r=="function";try{o=wye(n,e,t,{generator:this.options.generator,version:this.options.version,notificationIdNull:this.options.notificationIdNull})}catch(l){if(u){r(l);return}throw l}if(!u)return o}let c;try{c=JSON.stringify(o,this.options.replacer)}catch(u){r(u);return}return this.callServer(c,function(u,l){i._parseResponse(u,l,r)}),o};s1.prototype._parseResponse=function(n,e,t){if(n){t(n);return}if(!e){t();return}let r;try{r=JSON.parse(e,this.options.reviver)}catch(i){t(i);return}if(t.length===3)if(Array.isArray(r)){let i=function(s){return typeof s.error<"u"},o=function(s){return!i(s)};t(null,r.filter(i),r.filter(o));return}else{t(null,r.error,r.result);return}t(null,r)}});var kz=oe((cJe,W6)=>{"use strict";var bye=Object.prototype.hasOwnProperty,Jo="~";function a1(){}Object.create&&(a1.prototype=Object.create(null),new a1().__proto__||(Jo=!1));function Eye(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Pz(n,e,t,r,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var o=new Eye(t,r||n,i),s=Jo?Jo+e:e;return n._events[s]?n._events[s].fn?n._events[s]=[n._events[s],o]:n._events[s].push(o):(n._events[s]=o,n._eventsCount++),n}function Jv(n,e){--n._eventsCount===0?n._events=new a1:delete n._events[e]}function no(){this._events=new a1,this._eventsCount=0}no.prototype.eventNames=function(){var e=[],t,r;if(this._eventsCount===0)return e;for(r in t=this._events)bye.call(t,r)&&e.push(Jo?r.slice(1):r);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};no.prototype.listeners=function(e){var t=Jo?Jo+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,o=r.length,s=new Array(o);i<o;i++)s[i]=r[i].fn;return s};no.prototype.listenerCount=function(e){var t=Jo?Jo+e:e,r=this._events[t];return r?r.fn?1:r.length:0};no.prototype.emit=function(e,t,r,i,o,s){var a=Jo?Jo+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,r),!0;case 4:return c.fn.call(c.context,t,r,i),!0;case 5:return c.fn.call(c.context,t,r,i,o),!0;case 6:return c.fn.call(c.context,t,r,i,o,s),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var h=c.length,f;for(d=0;d<h;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,r);break;case 4:c[d].fn.call(c[d].context,t,r,i);break;default:if(!l)for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c[d].fn.apply(c[d].context,l)}}return!0};no.prototype.on=function(e,t,r){return Pz(this,e,t,r,!1)};no.prototype.once=function(e,t,r){return Pz(this,e,t,r,!0)};no.prototype.removeListener=function(e,t,r,i){var o=Jo?Jo+e:e;if(!this._events[o])return this;if(!t)return Jv(this,o),this;var s=this._events[o];if(s.fn)s.fn===t&&(!i||s.once)&&(!r||s.context===r)&&Jv(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||i&&!s[a].once||r&&s[a].context!==r)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Jv(this,o)}return this};no.prototype.removeAllListeners=function(e){var t;return e?(t=Jo?Jo+e:e,this._events[t]&&Jv(this,t)):(this._events=new a1,this._eventsCount=0),this};no.prototype.off=no.prototype.removeListener;no.prototype.addListener=no.prototype.on;no.prefixed=Jo;no.EventEmitter=no;typeof W6<"u"&&(W6.exports=no)});var JY=oe((vQe,KY)=>{"use strict";function Vbe(n){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var r=0;r<n.length;r++){var i=n.charAt(r),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=r}var s=n.length,a=n.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var m=0,w=0,b=0,S=f.length;b!==S&&f[b]===0;)b++,m++;for(var R=(S-b)*u+1>>>0,G=new Uint8Array(R);b!==S;){for(var U=f[b],H=0,M=R-1;(U!==0||H<w)&&M!==-1;M--,H++)U+=256*G[M]>>>0,G[M]=U%s>>>0,U=U/s>>>0;if(U!==0)throw new Error("Non-zero carry");w=H,b++}for(var A=R-w;A!==R&&G[A]===0;)A++;for(var D=a.repeat(m);A<R;++A)D+=n.charAt(G[A]);return D}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var m=0;if(f[m]!==" "){for(var w=0,b=0;f[m]===a;)w++,m++;for(var S=(f.length-m)*c+1>>>0,R=new Uint8Array(S);f[m];){var G=e[f.charCodeAt(m)];if(G===255)return;for(var U=0,H=S-1;(G!==0||U<b)&&H!==-1;H--,U++)G+=s*R[H]>>>0,R[H]=G%256>>>0,G=G/256>>>0;if(G!==0)throw new Error("Non-zero carry");b=U,m++}if(f[m]!==" "){for(var M=S-b;M!==S&&R[M]===0;)M++;for(var A=new Uint8Array(w+(S-M)),D=w;M!==S;)A[D++]=R[M++];return A}}}function h(f){var m=d(f);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:l,decodeUnsafe:d,decode:h}}KY.exports=Vbe});var hS=oe((SQe,qY)=>{"use strict";var Qbe=new TextDecoder,zbe=n=>Qbe.decode(n),Ybe=new TextEncoder,jbe=n=>Ybe.encode(n);function Wbe(n,e){let t=new Uint8Array(e),r=0;for(let i of n)t.set(i,r),r+=i.length;return t}qY.exports={decodeText:zbe,encodeText:jbe,concat:Wbe}});var QY=oe((CQe,VY)=>{"use strict";var{encodeText:Zbe}=hS(),XB=class{constructor(e,t,r,i){this.name=e,this.code=t,this.codeBuf=Zbe(this.code),this.alphabet=i,this.codec=r(i)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}};VY.exports=XB});var YY=oe((LQe,zY)=>{"use strict";var Xbe=(n,e,t)=>{let r={};for(let u=0;u<e.length;++u)r[e[u]]=u;let i=n.length;for(;n[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),s=0,a=0,c=0;for(let u=0;u<i;++u){let l=r[n[u]];if(l===void 0)throw new SyntaxError("Invalid character "+n[u]);a=a<<t|l,s+=t,s>=8&&(s-=8,o[c++]=255&a>>s)}if(s>=t||255&a<<8-s)throw new SyntaxError("Unexpected end of data");return o},_be=(n,e,t)=>{let r=e[e.length-1]==="=",i=(1<<t)-1,o="",s=0,a=0;for(let c=0;c<n.length;++c)for(a=a<<8|n[c],s+=8;s>t;)s-=t,o+=e[i&a>>s];if(s&&(o+=e[i&a<<t-s]),r)for(;o.length*t&7;)o+="=";return o},$be=n=>e=>({encode(t){return _be(t,e,n)},decode(t){return Xbe(t,e,n)}});zY.exports={rfc4648:$be}});var XY=oe((RQe,ZY)=>{"use strict";var v1=JY(),e2e=QY(),{rfc4648:Ti}=YY(),{decodeText:t2e,encodeText:n2e}=hS(),r2e=()=>({encode:t2e,decode:n2e}),jY=[["identity","\0",r2e,""],["base2","0",Ti(1),"01"],["base8","7",Ti(3),"01234567"],["base10","9",v1,"0123456789"],["base16","f",Ti(4),"0123456789abcdef"],["base16upper","F",Ti(4),"0123456789ABCDEF"],["base32hex","v",Ti(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",Ti(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",Ti(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",Ti(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",Ti(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",Ti(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",Ti(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",Ti(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",Ti(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",v1,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",v1,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",v1,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",v1,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",Ti(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],WY=jY.reduce((n,e)=>(n[e[0]]=new e2e(e[0],e[1],e[2],e[3]),n),{}),i2e=jY.reduce((n,e)=>(n[e[1]]=WY[e[0]],n),{});ZY.exports={names:WY,codes:i2e}});var ej=oe((id,$Y)=>{"use strict";var oy=XY(),{encodeText:o2e,decodeText:pS,concat:_Y}=hS();function s2e(n,e){if(!e)throw new Error("requires an encoded Uint8Array");let{name:t,codeBuf:r}=y0(n);return l2e(t,e),_Y([r,e],r.length+e.length)}function a2e(n,e){let t=y0(n),r=o2e(t.encode(e));return _Y([t.codeBuf,r],t.codeBuf.length+r.length)}function c2e(n){n instanceof Uint8Array&&(n=pS(n));let e=n[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(e)&&(n=n.toLowerCase()),y0(n[0]).decode(n.substring(1))}function u2e(n){if(n instanceof Uint8Array&&(n=pS(n)),Object.prototype.toString.call(n)!=="[object String]")return!1;try{return y0(n[0]).name}catch{return!1}}function l2e(n,e){y0(n).decode(pS(e))}function y0(n){if(Object.prototype.hasOwnProperty.call(oy.names,n))return oy.names[n];if(Object.prototype.hasOwnProperty.call(oy.codes,n))return oy.codes[n];throw new Error(`Unsupported encoding: ${n}`)}function d2e(n){return n instanceof Uint8Array&&(n=pS(n)),y0(n[0])}id=$Y.exports=s2e;id.encode=a2e;id.decode=c2e;id.isEncoded=u2e;id.encoding=y0;id.encodingFromData=d2e;var f2e=Object.freeze(oy.names),h2e=Object.freeze(oy.codes);id.names=f2e;id.codes=h2e});var iP=oe((sze,Dj)=>{"use strict";Dj.exports=function n(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?n(e.toJSON()):Array.isArray(e)?`[${e.reduce((i,o,s)=>`${i}${s===0?"":","}${n(o===void 0||typeof o=="symbol"?null:o)}`,"")}]`:`{${Object.keys(e).sort().reduce((r,i)=>{if(e[i]===void 0||typeof e[i]=="symbol")return r;let o=r.length===0?"":",";return`${r}${o}${n(i)}:${n(e[i])}`},"")}}`}});var k1=oe(ln=>{"use strict";Object.defineProperty(ln,"__esModule",{value:!0});ln.regexpCode=ln.getEsmExportName=ln.getProperty=ln.safeStringify=ln.stringify=ln.strConcat=ln.addCodeArg=ln.str=ln._=ln.nil=ln._Code=ln.Name=ln.IDENTIFIER=ln._CodeOrName=void 0;var B1=class{};ln._CodeOrName=B1;ln.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;var E0=class extends B1{constructor(e){if(super(),!ln.IDENTIFIER.test(e))throw new Error("CodeGen: name must be a valid identifier");this.str=e}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}};ln.Name=E0;var ka=class extends B1{constructor(e){super(),this._items=typeof e=="string"?[e]:e}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;let e=this._items[0];return e===""||e==='""'}get str(){var e;return(e=this._str)!==null&&e!==void 0?e:this._str=this._items.reduce((t,r)=>`${t}${r}`,"")}get names(){var e;return(e=this._names)!==null&&e!==void 0?e:this._names=this._items.reduce((t,r)=>(r instanceof E0&&(t[r.str]=(t[r.str]||0)+1),t),{})}};ln._Code=ka;ln.nil=new ka("");function oW(n,...e){let t=[n[0]],r=0;for(;r<e.length;)DP(t,e[r]),t.push(n[++r]);return new ka(t)}ln._=oW;var RP=new ka("+");function sW(n,...e){let t=[P1(n[0])],r=0;for(;r<e.length;)t.push(RP),DP(t,e[r]),t.push(RP,P1(n[++r]));return H1e(t),new ka(t)}ln.str=sW;function DP(n,e){e instanceof ka?n.push(...e._items):e instanceof E0?n.push(e):n.push(q1e(e))}ln.addCodeArg=DP;function H1e(n){let e=1;for(;e<n.length-1;){if(n[e]===RP){let t=K1e(n[e-1],n[e+1]);if(t!==void 0){n.splice(e-1,3,t);continue}n[e++]="+"}e++}}function K1e(n,e){if(e==='""')return n;if(n==='""')return e;if(typeof n=="string")return e instanceof E0||n[n.length-1]!=='"'?void 0:typeof e!="string"?`${n.slice(0,-1)}${e}"`:e[0]==='"'?n.slice(0,-1)+e.slice(1):void 0;if(typeof e=="string"&&e[0]==='"'&&!(n instanceof E0))return`"${n}${e.slice(1)}`}function J1e(n,e){return e.emptyStr()?n:n.emptyStr()?e:sW`${n}${e}`}ln.strConcat=J1e;function q1e(n){return typeof n=="number"||typeof n=="boolean"||n===null?n:P1(Array.isArray(n)?n.join(","):n)}function V1e(n){return new ka(P1(n))}ln.stringify=V1e;function P1(n){return JSON.stringify(n).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}ln.safeStringify=P1;function Q1e(n){return typeof n=="string"&&ln.IDENTIFIER.test(n)?new ka(`.${n}`):oW`[${n}]`}ln.getProperty=Q1e;function z1e(n){if(typeof n=="string"&&ln.IDENTIFIER.test(n))return new ka(`${n}`);throw new Error(`CodeGen: invalid export name: ${n}, use explicit $id name mapping`)}ln.getEsmExportName=z1e;function Y1e(n){return new ka(n.toString())}ln.regexpCode=Y1e});var PP=oe(Es=>{"use strict";Object.defineProperty(Es,"__esModule",{value:!0});Es.ValueScope=Es.ValueScopeName=Es.Scope=Es.varKinds=Es.UsedValueState=void 0;var bs=k1(),TP=class extends Error{constructor(e){super(`CodeGen: "code" for ${e} not defined`),this.value=e.value}},RS;(function(n){n[n.Started=0]="Started",n[n.Completed=1]="Completed"})(RS||(Es.UsedValueState=RS={}));Es.varKinds={const:new bs.Name("const"),let:new bs.Name("let"),var:new bs.Name("var")};var DS=class{constructor({prefixes:e,parent:t}={}){this._names={},this._prefixes=e,this._parent=t}toName(e){return e instanceof bs.Name?e:this.name(e)}name(e){return new bs.Name(this._newName(e))}_newName(e){let t=this._names[e]||this._nameGroup(e);return`${e}${t.index++}`}_nameGroup(e){var t,r;if(!((r=(t=this._parent)===null||t===void 0?void 0:t._prefixes)===null||r===void 0)&&r.has(e)||this._prefixes&&!this._prefixes.has(e))throw new Error(`CodeGen: prefix "${e}" is not allowed in this scope`);return this._names[e]={prefix:e,index:0}}};Es.Scope=DS;var TS=class extends bs.Name{constructor(e,t){super(t),this.prefix=e}setValue(e,{property:t,itemIndex:r}){this.value=e,this.scopePath=(0,bs._)`.${new bs.Name(t)}[${r}]`}};Es.ValueScopeName=TS;var j1e=(0,bs._)`\n`,BP=class extends DS{constructor(e){super(e),this._values={},this._scope=e.scope,this.opts={...e,_n:e.lines?j1e:bs.nil}}get(){return this._scope}name(e){return new TS(e,this._newName(e))}value(e,t){var r;if(t.ref===void 0)throw new Error("CodeGen: ref must be passed in value");let i=this.toName(e),{prefix:o}=i,s=(r=t.key)!==null&&r!==void 0?r:t.ref,a=this._values[o];if(a){let l=a.get(s);if(l)return l}else a=this._values[o]=new Map;a.set(s,i);let c=this._scope[o]||(this._scope[o]=[]),u=c.length;return c[u]=t.ref,i.setValue(t,{property:o,itemIndex:u}),i}getValue(e,t){let r=this._values[e];if(r)return r.get(t)}scopeRefs(e,t=this._values){return this._reduceValues(t,r=>{if(r.scopePath===void 0)throw new Error(`CodeGen: name "${r}" has no value`);return(0,bs._)`${e}${r.scopePath}`})}scopeCode(e=this._values,t,r){return this._reduceValues(e,i=>{if(i.value===void 0)throw new Error(`CodeGen: name "${i}" has no value`);return i.value.code},t,r)}_reduceValues(e,t,r={},i){let o=bs.nil;for(let s in e){let a=e[s];if(!a)continue;let c=r[s]=r[s]||new Map;a.forEach(u=>{if(c.has(u))return;c.set(u,RS.Started);let l=t(u);if(l){let d=this.opts.es5?Es.varKinds.var:Es.varKinds.const;o=(0,bs._)`${o}${d} ${u} = ${l};${this.opts._n}`}else if(l=i?.(u))o=(0,bs._)`${o}${l}${this.opts._n}`;else throw new TP(u);c.set(u,RS.Completed)})}return o}};Es.ValueScope=BP});var xt=oe(Gt=>{"use strict";Object.defineProperty(Gt,"__esModule",{value:!0});Gt.or=Gt.and=Gt.not=Gt.CodeGen=Gt.operators=Gt.varKinds=Gt.ValueScopeName=Gt.ValueScope=Gt.Scope=Gt.Name=Gt.regexpCode=Gt.stringify=Gt.getProperty=Gt.nil=Gt.strConcat=Gt.str=Gt._=void 0;var en=k1(),Pc=PP(),$f=k1();Object.defineProperty(Gt,"_",{enumerable:!0,get:function(){return $f._}});Object.defineProperty(Gt,"str",{enumerable:!0,get:function(){return $f.str}});Object.defineProperty(Gt,"strConcat",{enumerable:!0,get:function(){return $f.strConcat}});Object.defineProperty(Gt,"nil",{enumerable:!0,get:function(){return $f.nil}});Object.defineProperty(Gt,"getProperty",{enumerable:!0,get:function(){return $f.getProperty}});Object.defineProperty(Gt,"stringify",{enumerable:!0,get:function(){return $f.stringify}});Object.defineProperty(Gt,"regexpCode",{enumerable:!0,get:function(){return $f.regexpCode}});Object.defineProperty(Gt,"Name",{enumerable:!0,get:function(){return $f.Name}});var MS=PP();Object.defineProperty(Gt,"Scope",{enumerable:!0,get:function(){return MS.Scope}});Object.defineProperty(Gt,"ValueScope",{enumerable:!0,get:function(){return MS.ValueScope}});Object.defineProperty(Gt,"ValueScopeName",{enumerable:!0,get:function(){return MS.ValueScopeName}});Object.defineProperty(Gt,"varKinds",{enumerable:!0,get:function(){return MS.varKinds}});Gt.operators={GT:new en._Code(">"),GTE:new en._Code(">="),LT:new en._Code("<"),LTE:new en._Code("<="),EQ:new en._Code("==="),NEQ:new en._Code("!=="),NOT:new en._Code("!"),OR:new en._Code("||"),AND:new en._Code("&&"),ADD:new en._Code("+")};var sd=class{optimizeNodes(){return this}optimizeNames(e,t){return this}},kP=class extends sd{constructor(e,t,r){super(),this.varKind=e,this.name=t,this.rhs=r}render({es5:e,_n:t}){let r=e?Pc.varKinds.var:this.varKind,i=this.rhs===void 0?"":` = ${this.rhs}`;return`${r} ${this.name}${i};`+t}optimizeNames(e,t){if(e[this.name.str])return this.rhs&&(this.rhs=fy(this.rhs,e,t)),this}get names(){return this.rhs instanceof en._CodeOrName?this.rhs.names:{}}},BS=class extends sd{constructor(e,t,r){super(),this.lhs=e,this.rhs=t,this.sideEffects=r}render({_n:e}){return`${this.lhs} = ${this.rhs};`+e}optimizeNames(e,t){if(!(this.lhs instanceof en.Name&&!e[this.lhs.str]&&!this.sideEffects))return this.rhs=fy(this.rhs,e,t),this}get names(){let e=this.lhs instanceof en.Name?{}:{...this.lhs.names};return kS(e,this.rhs)}},MP=class extends BS{constructor(e,t,r,i){super(e,r,i),this.op=t}render({_n:e}){return`${this.lhs} ${this.op}= ${this.rhs};`+e}},OP=class extends sd{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`${this.label}:`+e}},FP=class extends sd{constructor(e){super(),this.label=e,this.names={}}render({_n:e}){return`break${this.label?` ${this.label}`:""};`+e}},NP=class extends sd{constructor(e){super(),this.error=e}render({_n:e}){return`throw ${this.error};`+e}get names(){return this.error.names}},UP=class extends sd{constructor(e){super(),this.code=e}render({_n:e}){return`${this.code};`+e}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(e,t){return this.code=fy(this.code,e,t),this}get names(){return this.code instanceof en._CodeOrName?this.code.names:{}}},M1=class extends sd{constructor(e=[]){super(),this.nodes=e}render(e){return this.nodes.reduce((t,r)=>t+r.render(e),"")}optimizeNodes(){let{nodes:e}=this,t=e.length;for(;t--;){let r=e[t].optimizeNodes();Array.isArray(r)?e.splice(t,1,...r):r?e[t]=r:e.splice(t,1)}return e.length>0?this:void 0}optimizeNames(e,t){let{nodes:r}=this,i=r.length;for(;i--;){let o=r[i];o.optimizeNames(e,t)||(W1e(e,o.names),r.splice(i,1))}return r.length>0?this:void 0}get names(){return this.nodes.reduce((e,t)=>x0(e,t.names),{})}},ad=class extends M1{render(e){return"{"+e._n+super.render(e)+"}"+e._n}},GP=class extends M1{},dy=class extends ad{};dy.kind="else";var I0=class n extends ad{constructor(e,t){super(t),this.condition=e}render(e){let t=`if(${this.condition})`+super.render(e);return this.else&&(t+="else "+this.else.render(e)),t}optimizeNodes(){super.optimizeNodes();let e=this.condition;if(e===!0)return this.nodes;let t=this.else;if(t){let r=t.optimizeNodes();t=this.else=Array.isArray(r)?new dy(r):r}if(t)return e===!1?t instanceof n?t:t.nodes:this.nodes.length?this:new n(aW(e),t instanceof n?[t]:t.nodes);if(!(e===!1||!this.nodes.length))return this}optimizeNames(e,t){var r;if(this.else=(r=this.else)===null||r===void 0?void 0:r.optimizeNames(e,t),!!(super.optimizeNames(e,t)||this.else))return this.condition=fy(this.condition,e,t),this}get names(){let e=super.names;return kS(e,this.condition),this.else&&x0(e,this.else.names),e}};I0.kind="if";var A0=class extends ad{};A0.kind="for";var HP=class extends A0{constructor(e){super(),this.iteration=e}render(e){return`for(${this.iteration})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iteration=fy(this.iteration,e,t),this}get names(){return x0(super.names,this.iteration.names)}},KP=class extends A0{constructor(e,t,r,i){super(),this.varKind=e,this.name=t,this.from=r,this.to=i}render(e){let t=e.es5?Pc.varKinds.var:this.varKind,{name:r,from:i,to:o}=this;return`for(${t} ${r}=${i}; ${r}<${o}; ${r}++)`+super.render(e)}get names(){let e=kS(super.names,this.from);return kS(e,this.to)}},PS=class extends A0{constructor(e,t,r,i){super(),this.loop=e,this.varKind=t,this.name=r,this.iterable=i}render(e){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(e)}optimizeNames(e,t){if(super.optimizeNames(e,t))return this.iterable=fy(this.iterable,e,t),this}get names(){return x0(super.names,this.iterable.names)}},O1=class extends ad{constructor(e,t,r){super(),this.name=e,this.args=t,this.async=r}render(e){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(e)}};O1.kind="func";var F1=class extends M1{render(e){return"return "+super.render(e)}};F1.kind="return";var JP=class extends ad{render(e){let t="try"+super.render(e);return this.catch&&(t+=this.catch.render(e)),this.finally&&(t+=this.finally.render(e)),t}optimizeNodes(){var e,t;return super.optimizeNodes(),(e=this.catch)===null||e===void 0||e.optimizeNodes(),(t=this.finally)===null||t===void 0||t.optimizeNodes(),this}optimizeNames(e,t){var r,i;return super.optimizeNames(e,t),(r=this.catch)===null||r===void 0||r.optimizeNames(e,t),(i=this.finally)===null||i===void 0||i.optimizeNames(e,t),this}get names(){let e=super.names;return this.catch&&x0(e,this.catch.names),this.finally&&x0(e,this.finally.names),e}},N1=class extends ad{constructor(e){super(),this.error=e}render(e){return`catch(${this.error})`+super.render(e)}};N1.kind="catch";var U1=class extends ad{render(e){return"finally"+super.render(e)}};U1.kind="finally";var qP=class{constructor(e,t={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...t,_n:t.lines?`
|
|
7
7
|
`:""},this._extScope=e,this._scope=new Pc.Scope({parent:e}),this._nodes=[new GP]}toString(){return this._root.render(this.opts)}name(e){return this._scope.name(e)}scopeName(e){return this._extScope.name(e)}scopeValue(e,t){let r=this._extScope.value(e,t);return(this._values[r.prefix]||(this._values[r.prefix]=new Set)).add(r),r}getScopeValue(e,t){return this._extScope.getValue(e,t)}scopeRefs(e){return this._extScope.scopeRefs(e,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(e,t,r,i){let o=this._scope.toName(t);return r!==void 0&&i&&(this._constants[o.str]=r),this._leafNode(new kP(e,o,r)),o}const(e,t,r){return this._def(Pc.varKinds.const,e,t,r)}let(e,t,r){return this._def(Pc.varKinds.let,e,t,r)}var(e,t,r){return this._def(Pc.varKinds.var,e,t,r)}assign(e,t,r){return this._leafNode(new BS(e,t,r))}add(e,t){return this._leafNode(new MP(e,Gt.operators.ADD,t))}code(e){return typeof e=="function"?e():e!==en.nil&&this._leafNode(new UP(e)),this}object(...e){let t=["{"];for(let[r,i]of e)t.length>1&&t.push(","),t.push(r),(r!==i||this.opts.es5)&&(t.push(":"),(0,en.addCodeArg)(t,i));return t.push("}"),new en._Code(t)}if(e,t,r){if(this._blockNode(new I0(e)),t&&r)this.code(t).else().code(r).endIf();else if(t)this.code(t).endIf();else if(r)throw new Error('CodeGen: "else" body without "then" body');return this}elseIf(e){return this._elseNode(new I0(e))}else(){return this._elseNode(new dy)}endIf(){return this._endBlockNode(I0,dy)}_for(e,t){return this._blockNode(e),t&&this.code(t).endFor(),this}for(e,t){return this._for(new HP(e),t)}forRange(e,t,r,i,o=this.opts.es5?Pc.varKinds.var:Pc.varKinds.let){let s=this._scope.toName(e);return this._for(new KP(o,s,t,r),()=>i(s))}forOf(e,t,r,i=Pc.varKinds.const){let o=this._scope.toName(e);if(this.opts.es5){let s=t instanceof en.Name?t:this.var("_arr",t);return this.forRange("_i",0,(0,en._)`${s}.length`,a=>{this.var(o,(0,en._)`${s}[${a}]`),r(o)})}return this._for(new PS("of",i,o,t),()=>r(o))}forIn(e,t,r,i=this.opts.es5?Pc.varKinds.var:Pc.varKinds.const){if(this.opts.ownProperties)return this.forOf(e,(0,en._)`Object.keys(${t})`,r);let o=this._scope.toName(e);return this._for(new PS("in",i,o,t),()=>r(o))}endFor(){return this._endBlockNode(A0)}label(e){return this._leafNode(new OP(e))}break(e){return this._leafNode(new FP(e))}return(e){let t=new F1;if(this._blockNode(t),this.code(e),t.nodes.length!==1)throw new Error('CodeGen: "return" should have one node');return this._endBlockNode(F1)}try(e,t,r){if(!t&&!r)throw new Error('CodeGen: "try" without "catch" and "finally"');let i=new JP;if(this._blockNode(i),this.code(e),t){let o=this.name("e");this._currNode=i.catch=new N1(o),t(o)}return r&&(this._currNode=i.finally=new U1,this.code(r)),this._endBlockNode(N1,U1)}throw(e){return this._leafNode(new NP(e))}block(e,t){return this._blockStarts.push(this._nodes.length),e&&this.code(e).endBlock(t),this}endBlock(e){let t=this._blockStarts.pop();if(t===void 0)throw new Error("CodeGen: not in self-balancing block");let r=this._nodes.length-t;if(r<0||e!==void 0&&r!==e)throw new Error(`CodeGen: wrong number of nodes: ${r} vs ${e} expected`);return this._nodes.length=t,this}func(e,t=en.nil,r,i){return this._blockNode(new O1(e,t,r)),i&&this.code(i).endFunc(),this}endFunc(){return this._endBlockNode(O1)}optimize(e=1){for(;e-- >0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(e){return this._currNode.nodes.push(e),this}_blockNode(e){this._currNode.nodes.push(e),this._nodes.push(e)}_endBlockNode(e,t){let r=this._currNode;if(r instanceof e||t&&r instanceof t)return this._nodes.pop(),this;throw new Error(`CodeGen: not in block "${t?`${e.kind}/${t.kind}`:e.kind}"`)}_elseNode(e){let t=this._currNode;if(!(t instanceof I0))throw new Error('CodeGen: "else" without "if"');return this._currNode=t.else=e,this}get _root(){return this._nodes[0]}get _currNode(){let e=this._nodes;return e[e.length-1]}set _currNode(e){let t=this._nodes;t[t.length-1]=e}};Gt.CodeGen=qP;function x0(n,e){for(let t in e)n[t]=(n[t]||0)+(e[t]||0);return n}function kS(n,e){return e instanceof en._CodeOrName?x0(n,e.names):n}function fy(n,e,t){if(n instanceof en.Name)return r(n);if(!i(n))return n;return new en._Code(n._items.reduce((o,s)=>(s instanceof en.Name&&(s=r(s)),s instanceof en._Code?o.push(...s._items):o.push(s),o),[]));function r(o){let s=t[o.str];return s===void 0||e[o.str]!==1?o:(delete e[o.str],s)}function i(o){return o instanceof en._Code&&o._items.some(s=>s instanceof en.Name&&e[s.str]===1&&t[s.str]!==void 0)}}function W1e(n,e){for(let t in e)n[t]=(n[t]||0)-(e[t]||0)}function aW(n){return typeof n=="boolean"||typeof n=="number"||n===null?!n:(0,en._)`!${VP(n)}`}Gt.not=aW;var Z1e=cW(Gt.operators.AND);function X1e(...n){return n.reduce(Z1e)}Gt.and=X1e;var _1e=cW(Gt.operators.OR);function $1e(...n){return n.reduce(_1e)}Gt.or=$1e;function cW(n){return(e,t)=>e===en.nil?t:t===en.nil?e:(0,en._)`${VP(e)} ${n} ${VP(t)}`}function VP(n){return n instanceof en.Name?n:(0,en._)`(${n})`}});var Qt=oe(Ht=>{"use strict";Object.defineProperty(Ht,"__esModule",{value:!0});Ht.checkStrictMode=Ht.getErrorPath=Ht.Type=Ht.useFunc=Ht.setEvaluated=Ht.evaluatedPropsToName=Ht.mergeEvaluated=Ht.eachItem=Ht.unescapeJsonPointer=Ht.escapeJsonPointer=Ht.escapeFragment=Ht.unescapeFragment=Ht.schemaRefOrVal=Ht.schemaHasRulesButRef=Ht.schemaHasRules=Ht.checkUnknownRules=Ht.alwaysValidSchema=Ht.toHash=void 0;var Qn=xt(),eEe=k1();function tEe(n){let e={};for(let t of n)e[t]=!0;return e}Ht.toHash=tEe;function nEe(n,e){return typeof e=="boolean"?e:Object.keys(e).length===0?!0:(dW(n,e),!fW(e,n.self.RULES.all))}Ht.alwaysValidSchema=nEe;function dW(n,e=n.schema){let{opts:t,self:r}=n;if(!t.strictSchema||typeof e=="boolean")return;let i=r.RULES.keywords;for(let o in e)i[o]||mW(n,`unknown keyword: "${o}"`)}Ht.checkUnknownRules=dW;function fW(n,e){if(typeof n=="boolean")return!n;for(let t in n)if(e[t])return!0;return!1}Ht.schemaHasRules=fW;function rEe(n,e){if(typeof n=="boolean")return!n;for(let t in n)if(t!=="$ref"&&e.all[t])return!0;return!1}Ht.schemaHasRulesButRef=rEe;function iEe({topSchemaRef:n,schemaPath:e},t,r,i){if(!i){if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string")return(0,Qn._)`${t}`}return(0,Qn._)`${n}${e}${(0,Qn.getProperty)(r)}`}Ht.schemaRefOrVal=iEe;function oEe(n){return hW(decodeURIComponent(n))}Ht.unescapeFragment=oEe;function sEe(n){return encodeURIComponent(zP(n))}Ht.escapeFragment=sEe;function zP(n){return typeof n=="number"?`${n}`:n.replace(/~/g,"~0").replace(/\//g,"~1")}Ht.escapeJsonPointer=zP;function hW(n){return n.replace(/~1/g,"/").replace(/~0/g,"~")}Ht.unescapeJsonPointer=hW;function aEe(n,e){if(Array.isArray(n))for(let t of n)e(t);else e(n)}Ht.eachItem=aEe;function uW({mergeNames:n,mergeToName:e,mergeValues:t,resultToName:r}){return(i,o,s,a)=>{let c=s===void 0?o:s instanceof Qn.Name?(o instanceof Qn.Name?n(i,o,s):e(i,o,s),s):o instanceof Qn.Name?(e(i,s,o),o):t(o,s);return a===Qn.Name&&!(c instanceof Qn.Name)?r(i,c):c}}Ht.mergeEvaluated={props:uW({mergeNames:(n,e,t)=>n.if((0,Qn._)`${t} !== true && ${e} !== undefined`,()=>{n.if((0,Qn._)`${e} === true`,()=>n.assign(t,!0),()=>n.assign(t,(0,Qn._)`${t} || {}`).code((0,Qn._)`Object.assign(${t}, ${e})`))}),mergeToName:(n,e,t)=>n.if((0,Qn._)`${t} !== true`,()=>{e===!0?n.assign(t,!0):(n.assign(t,(0,Qn._)`${t} || {}`),YP(n,t,e))}),mergeValues:(n,e)=>n===!0?!0:{...n,...e},resultToName:pW}),items:uW({mergeNames:(n,e,t)=>n.if((0,Qn._)`${t} !== true && ${e} !== undefined`,()=>n.assign(t,(0,Qn._)`${e} === true ? true : ${t} > ${e} ? ${t} : ${e}`)),mergeToName:(n,e,t)=>n.if((0,Qn._)`${t} !== true`,()=>n.assign(t,e===!0?!0:(0,Qn._)`${t} > ${e} ? ${t} : ${e}`)),mergeValues:(n,e)=>n===!0?!0:Math.max(n,e),resultToName:(n,e)=>n.var("items",e)})};function pW(n,e){if(e===!0)return n.var("props",!0);let t=n.var("props",(0,Qn._)`{}`);return e!==void 0&&YP(n,t,e),t}Ht.evaluatedPropsToName=pW;function YP(n,e,t){Object.keys(t).forEach(r=>n.assign((0,Qn._)`${e}${(0,Qn.getProperty)(r)}`,!0))}Ht.setEvaluated=YP;var lW={};function cEe(n,e){return n.scopeValue("func",{ref:e,code:lW[e.code]||(lW[e.code]=new eEe._Code(e.code))})}Ht.useFunc=cEe;var QP;(function(n){n[n.Num=0]="Num",n[n.Str=1]="Str"})(QP||(Ht.Type=QP={}));function uEe(n,e,t){if(n instanceof Qn.Name){let r=e===QP.Num;return t?r?(0,Qn._)`"[" + ${n} + "]"`:(0,Qn._)`"['" + ${n} + "']"`:r?(0,Qn._)`"/" + ${n}`:(0,Qn._)`"/" + ${n}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return t?(0,Qn.getProperty)(n).toString():"/"+zP(n)}Ht.getErrorPath=uEe;function mW(n,e,t=n.opts.strictSchema){if(t){if(e=`strict mode: ${e}`,t===!0)throw new Error(e);n.self.logger.warn(e)}}Ht.checkStrictMode=mW});var Ma=oe(jP=>{"use strict";Object.defineProperty(jP,"__esModule",{value:!0});var ro=xt(),lEe={data:new ro.Name("data"),valCxt:new ro.Name("valCxt"),instancePath:new ro.Name("instancePath"),parentData:new ro.Name("parentData"),parentDataProperty:new ro.Name("parentDataProperty"),rootData:new ro.Name("rootData"),dynamicAnchors:new ro.Name("dynamicAnchors"),vErrors:new ro.Name("vErrors"),errors:new ro.Name("errors"),this:new ro.Name("this"),self:new ro.Name("self"),scope:new ro.Name("scope"),json:new ro.Name("json"),jsonPos:new ro.Name("jsonPos"),jsonLen:new ro.Name("jsonLen"),jsonPart:new ro.Name("jsonPart")};jP.default=lEe});var G1=oe(io=>{"use strict";Object.defineProperty(io,"__esModule",{value:!0});io.extendErrors=io.resetErrorsCount=io.reportExtraError=io.reportError=io.keyword$DataError=io.keywordError=void 0;var on=xt(),OS=Qt(),Vo=Ma();io.keywordError={message:({keyword:n})=>(0,on.str)`must pass "${n}" keyword validation`};io.keyword$DataError={message:({keyword:n,schemaType:e})=>e?(0,on.str)`"${n}" keyword must be ${e} ($data)`:(0,on.str)`"${n}" keyword is invalid ($data)`};function dEe(n,e=io.keywordError,t,r){let{it:i}=n,{gen:o,compositeRule:s,allErrors:a}=i,c=wW(n,e,t);r??(s||a)?gW(o,c):yW(i,(0,on._)`[${c}]`)}io.reportError=dEe;function fEe(n,e=io.keywordError,t){let{it:r}=n,{gen:i,compositeRule:o,allErrors:s}=r,a=wW(n,e,t);gW(i,a),o||s||yW(r,Vo.default.vErrors)}io.reportExtraError=fEe;function hEe(n,e){n.assign(Vo.default.errors,e),n.if((0,on._)`${Vo.default.vErrors} !== null`,()=>n.if(e,()=>n.assign((0,on._)`${Vo.default.vErrors}.length`,e),()=>n.assign(Vo.default.vErrors,null)))}io.resetErrorsCount=hEe;function pEe({gen:n,keyword:e,schemaValue:t,data:r,errsCount:i,it:o}){if(i===void 0)throw new Error("ajv implementation error");let s=n.name("err");n.forRange("i",i,Vo.default.errors,a=>{n.const(s,(0,on._)`${Vo.default.vErrors}[${a}]`),n.if((0,on._)`${s}.instancePath === undefined`,()=>n.assign((0,on._)`${s}.instancePath`,(0,on.strConcat)(Vo.default.instancePath,o.errorPath))),n.assign((0,on._)`${s}.schemaPath`,(0,on.str)`${o.errSchemaPath}/${e}`),o.opts.verbose&&(n.assign((0,on._)`${s}.schema`,t),n.assign((0,on._)`${s}.data`,r))})}io.extendErrors=pEe;function gW(n,e){let t=n.const("err",e);n.if((0,on._)`${Vo.default.vErrors} === null`,()=>n.assign(Vo.default.vErrors,(0,on._)`[${t}]`),(0,on._)`${Vo.default.vErrors}.push(${t})`),n.code((0,on._)`${Vo.default.errors}++`)}function yW(n,e){let{gen:t,validateName:r,schemaEnv:i}=n;i.$async?t.throw((0,on._)`new ${n.ValidationError}(${e})`):(t.assign((0,on._)`${r}.errors`,e),t.return(!1))}var v0={keyword:new on.Name("keyword"),schemaPath:new on.Name("schemaPath"),params:new on.Name("params"),propertyName:new on.Name("propertyName"),message:new on.Name("message"),schema:new on.Name("schema"),parentSchema:new on.Name("parentSchema")};function wW(n,e,t){let{createErrors:r}=n.it;return r===!1?(0,on._)`{}`:mEe(n,e,t)}function mEe(n,e,t={}){let{gen:r,it:i}=n,o=[gEe(i,t),yEe(n,t)];return wEe(n,e,o),r.object(...o)}function gEe({errorPath:n},{instancePath:e}){let t=e?(0,on.str)`${n}${(0,OS.getErrorPath)(e,OS.Type.Str)}`:n;return[Vo.default.instancePath,(0,on.strConcat)(Vo.default.instancePath,t)]}function yEe({keyword:n,it:{errSchemaPath:e}},{schemaPath:t,parentSchema:r}){let i=r?e:(0,on.str)`${e}/${n}`;return t&&(i=(0,on.str)`${i}${(0,OS.getErrorPath)(t,OS.Type.Str)}`),[v0.schemaPath,i]}function wEe(n,{params:e,message:t},r){let{keyword:i,data:o,schemaValue:s,it:a}=n,{opts:c,propertyName:u,topSchemaRef:l,schemaPath:d}=a;r.push([v0.keyword,i],[v0.params,typeof e=="function"?e(n):e||(0,on._)`{}`]),c.messages&&r.push([v0.message,typeof t=="function"?t(n):t]),c.verbose&&r.push([v0.schema,s],[v0.parentSchema,(0,on._)`${l}${d}`],[Vo.default.data,o]),u&&r.push([v0.propertyName,u])}});var EW=oe(hy=>{"use strict";Object.defineProperty(hy,"__esModule",{value:!0});hy.boolOrEmptySchema=hy.topBoolOrEmptySchema=void 0;var bEe=G1(),EEe=xt(),IEe=Ma(),AEe={message:"boolean schema is false"};function xEe(n){let{gen:e,schema:t,validateName:r}=n;t===!1?bW(n,!1):typeof t=="object"&&t.$async===!0?e.return(IEe.default.data):(e.assign((0,EEe._)`${r}.errors`,null),e.return(!0))}hy.topBoolOrEmptySchema=xEe;function vEe(n,e){let{gen:t,schema:r}=n;r===!1?(t.var(e,!1),bW(n)):t.var(e,!0)}hy.boolOrEmptySchema=vEe;function bW(n,e){let{gen:t,data:r}=n,i={gen:t,keyword:"false schema",data:r,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:n};(0,bEe.reportError)(i,AEe,void 0,e)}});var WP=oe(py=>{"use strict";Object.defineProperty(py,"__esModule",{value:!0});py.getRules=py.isJSONType=void 0;var SEe=["string","number","integer","boolean","null","object","array"],CEe=new Set(SEe);function LEe(n){return typeof n=="string"&&CEe.has(n)}py.isJSONType=LEe;function REe(){let n={number:{type:"number",rules:[]},string:{type:"string",rules:[]},array:{type:"array",rules:[]},object:{type:"object",rules:[]}};return{types:{...n,integer:!0,boolean:!0,null:!0},rules:[{rules:[]},n.number,n.string,n.array,n.object],post:{rules:[]},all:{},keywords:{}}}py.getRules=REe});var ZP=oe(eh=>{"use strict";Object.defineProperty(eh,"__esModule",{value:!0});eh.shouldUseRule=eh.shouldUseGroup=eh.schemaHasRulesForType=void 0;function DEe({schema:n,self:e},t){let r=e.RULES.types[t];return r&&r!==!0&&IW(n,r)}eh.schemaHasRulesForType=DEe;function IW(n,e){return e.rules.some(t=>AW(n,t))}eh.shouldUseGroup=IW;function AW(n,e){var t;return n[e.keyword]!==void 0||((t=e.definition.implements)===null||t===void 0?void 0:t.some(r=>n[r]!==void 0))}eh.shouldUseRule=AW});var H1=oe(oo=>{"use strict";Object.defineProperty(oo,"__esModule",{value:!0});oo.reportTypeError=oo.checkDataTypes=oo.checkDataType=oo.coerceAndCheckDataType=oo.getJSONTypes=oo.getSchemaTypes=oo.DataType=void 0;var TEe=WP(),BEe=ZP(),PEe=G1(),Bt=xt(),xW=Qt(),my;(function(n){n[n.Correct=0]="Correct",n[n.Wrong=1]="Wrong"})(my||(oo.DataType=my={}));function kEe(n){let e=vW(n.type);if(e.includes("null")){if(n.nullable===!1)throw new Error("type: null contradicts nullable: false")}else{if(!e.length&&n.nullable!==void 0)throw new Error('"nullable" cannot be used without "type"');n.nullable===!0&&e.push("null")}return e}oo.getSchemaTypes=kEe;function vW(n){let e=Array.isArray(n)?n:n?[n]:[];if(e.every(TEe.isJSONType))return e;throw new Error("type must be JSONType or JSONType[]: "+e.join(","))}oo.getJSONTypes=vW;function MEe(n,e){let{gen:t,data:r,opts:i}=n,o=OEe(e,i.coerceTypes),s=e.length>0&&!(o.length===0&&e.length===1&&(0,BEe.schemaHasRulesForType)(n,e[0]));if(s){let a=_P(e,r,i.strictNumbers,my.Wrong);t.if(a,()=>{o.length?FEe(n,e,o):$P(n)})}return s}oo.coerceAndCheckDataType=MEe;var SW=new Set(["string","number","integer","boolean","null"]);function OEe(n,e){return e?n.filter(t=>SW.has(t)||e==="array"&&t==="array"):[]}function FEe(n,e,t){let{gen:r,data:i,opts:o}=n,s=r.let("dataType",(0,Bt._)`typeof ${i}`),a=r.let("coerced",(0,Bt._)`undefined`);o.coerceTypes==="array"&&r.if((0,Bt._)`${s} == 'object' && Array.isArray(${i}) && ${i}.length == 1`,()=>r.assign(i,(0,Bt._)`${i}[0]`).assign(s,(0,Bt._)`typeof ${i}`).if(_P(e,i,o.strictNumbers),()=>r.assign(a,i))),r.if((0,Bt._)`${a} !== undefined`);for(let u of t)(SW.has(u)||u==="array"&&o.coerceTypes==="array")&&c(u);r.else(),$P(n),r.endIf(),r.if((0,Bt._)`${a} !== undefined`,()=>{r.assign(i,a),NEe(n,a)});function c(u){switch(u){case"string":r.elseIf((0,Bt._)`${s} == "number" || ${s} == "boolean"`).assign(a,(0,Bt._)`"" + ${i}`).elseIf((0,Bt._)`${i} === null`).assign(a,(0,Bt._)`""`);return;case"number":r.elseIf((0,Bt._)`${s} == "boolean" || ${i} === null
|
|
8
8
|
|| (${s} == "string" && ${i} && ${i} == +${i})`).assign(a,(0,Bt._)`+${i}`);return;case"integer":r.elseIf((0,Bt._)`${s} === "boolean" || ${i} === null
|
|
9
9
|
|| (${s} === "string" && ${i} && ${i} == +${i} && !(${i} % 1))`).assign(a,(0,Bt._)`+${i}`);return;case"boolean":r.elseIf((0,Bt._)`${i} === "false" || ${i} === 0 || ${i} === null`).assign(a,!1).elseIf((0,Bt._)`${i} === "true" || ${i} === 1`).assign(a,!0);return;case"null":r.elseIf((0,Bt._)`${i} === "" || ${i} === 0 || ${i} === false`),r.assign(a,null);return;case"array":r.elseIf((0,Bt._)`${s} === "string" || ${s} === "number"
|
|
@@ -420,7 +420,7 @@ if (cid) {
|
|
|
420
420
|
`?i="":(i!==""&&(i+=" "),i+=l)},showSharedRWMemory:function(){u()}}}),s=e;return new SO(o,s);function c(){let l="",d=o.exports.getMessageChar();for(;d!=0;)l+=String.fromCharCode(d),d=o.exports.getMessageChar();return l}function u(){let l=o.exports.getFieldNumLen32(),d=new Uint32Array(l);for(let h=0;h<l;h++)d[l-1-h]=o.exports.readSharedRWMemory(h);i!==""&&(i+=" "),i+=CO(d).toString()}}var SO=class{instance;version;n32;prime;witnessSize;sanityCheck;constructor(e,t){this.instance=e,this.instance=e,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();let r=new Uint32Array(this.n32);for(let i=0;i<this.n32;i++)r[this.n32-1-i]=this.instance.exports.readSharedRWMemory(i);this.prime=CO(r),this.witnessSize=this.instance.exports.getWitnessSize(),this.sanityCheck=t}circom_version(){return this.instance.exports.getVersion()}async _doCalculateWitness(e,t){this.instance.exports.init(this.sanityCheck||t?1:0);let r=Object.keys(e),i=0;if(r.forEach(o=>{let s=PLe(o),a=parseInt(s.slice(0,8),16),c=parseInt(s.slice(8,16),16),u=BLe(e[o]),l=this.instance.exports.getInputSignalSize(a,c);if(l<0)throw new Error(`Signal ${o} not found
|
|
421
421
|
`);if(u.length<l)throw new Error(`Not enough values for input signal ${o}
|
|
422
422
|
`);if(u.length>l)throw new Error(`Too many values for input signal ${o}
|
|
423
|
-
`);for(let d=0;d<u.length;d++){let h=TLe(BigInt(u[d])%this.prime,this.n32);for(let f=0;f<this.n32;f++)this.instance.exports.writeSharedRWMemory(f,h[this.n32-1-f]);try{this.instance.exports.setInputSignal(a,c,d),i++}catch(f){throw new Error(f)}}}),i<this.instance.exports.getInputSize())throw new Error(`Not all inputs have been set. Only ${i} out of ${this.instance.exports.getInputSize()}`)}async calculateWitness(e,t){let r=[];await this._doCalculateWitness(e,t);for(let i=0;i<this.witnessSize;i++){this.instance.exports.getWitness(i);let o=new Uint32Array(this.n32);for(let s=0;s<this.n32;s++)o[this.n32-1-s]=this.instance.exports.readSharedRWMemory(s);r.push(CO(o))}return r}async calculateBinWitness(e,t){let r=new Uint32Array(this.witnessSize*this.n32),i=new Uint8Array(r.buffer);await this._doCalculateWitness(e,t);for(let o=0;o<this.witnessSize;o++){this.instance.exports.getWitness(o);let s=o*this.n32;for(let a=0;a<this.n32;a++)r[s+a]=this.instance.exports.readSharedRWMemory(a)}return i}async calculateWTNSBin(e,t){let r=new Uint32Array(this.witnessSize*this.n32+this.n32+11),i=new Uint8Array(r.buffer);await this._doCalculateWitness(e,t),i[0]=119,i[1]=116,i[2]=110,i[3]=115,r[1]=2,r[2]=2,r[3]=1;let o=this.n32*4,a=(8+o).toString(16);r[4]=parseInt(a.slice(0,8),16),r[5]=parseInt(a.slice(8,16),16),r[6]=o,this.instance.exports.getRawPrime();let c=7;for(let d=0;d<this.n32;d++)r[c+d]=this.instance.exports.readSharedRWMemory(d);c+=this.n32,r[c]=this.witnessSize,c++,r[c]=2,c++;let l=(o*this.witnessSize).toString(16);r[c]=parseInt(l.slice(0,8),16),r[c+1]=parseInt(l.slice(8,16),16),c+=2;for(let d=0;d<this.witnessSize;d++){this.instance.exports.getWitness(d);for(let h=0;h<this.n32;h++)r[c+h]=this.instance.exports.readSharedRWMemory(h);c+=this.n32}return i}};function TLe(n,e){let t=[],r=BigInt(4294967296);for(;n;)t.unshift(Number(n%r)),n=n/r;if(e){let i=e-t.length;for(;i>0;)t.unshift(0),i--}return t}function CO(n){let e=BigInt(0),t=BigInt(4294967296);for(let r=0;r<n.length;r++)e=e*t+BigInt(n[r]);return e}function BLe(n){let e=[];return t(e,n),e;function t(r,i){if(Array.isArray(i))for(let o=0;o<i.length;o++)t(r,i[o]);else r.push(i)}}function PLe(n){let e=BigInt(2)**BigInt(64),t=BigInt("0xCBF29CE484222325");for(let o=0;o<n.length;o++)t^=BigInt(n[o].charCodeAt()),t*=BigInt(1099511628211),t%=e;let r=t.toString(16),i=16-r.length;return r="0".repeat(i).concat(r),r}var Vy=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function $E(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function LO(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function Gc(n,...e){if(!$E(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function Pee(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");LO(n.outputLen),LO(n.blockLen)}function $C(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function kLe(n,e){Gc(n);let t=e.outputLen;if(n.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function e8(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function mO(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Ku(n,e){return n<<32-e|n>>>e}var kee=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",MLe=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function zy(n){if(Gc(n),kee)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=MLe[n[t]];return e}var wd={_0:48,_9:57,A:65,F:70,a:97,f:102};function dee(n){if(n>=wd._0&&n<=wd._9)return n-wd._0;if(n>=wd.A&&n<=wd.F)return n-(wd.A-10);if(n>=wd.a&&n<=wd.f)return n-(wd.a-10)}function t8(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(kee)return Uint8Array.fromHex(n);let e=n.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=dee(n.charCodeAt(o)),a=dee(n.charCodeAt(o+1));if(s===void 0||a===void 0){let c=n[o]+n[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}r[i]=s*16+a}return r}function eI(n){if(typeof n!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(n))}function QO(n){return typeof n=="string"&&(n=eI(n)),Gc(n),n}function Fi(...n){let e=0;for(let r=0;r<n.length;r++){let i=n[r];Gc(i),e+=i.length}let t=new Uint8Array(e);for(let r=0,i=0;r<n.length;r++){let o=n[r];t.set(o,i),i+=o.length}return t}var n8=class{};function OLe(n){let e=r=>n().update(QO(r)).digest(),t=n();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>n(),e}function zO(n=32){if(Vy&&typeof Vy.getRandomValues=="function")return Vy.getRandomValues(new Uint8Array(n));if(Vy&&typeof Vy.randomBytes=="function")return Uint8Array.from(Vy.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}function FLe(n,e,t,r){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,t,r);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=r?4:0,u=r?0:4;n.setUint32(e+c,s,r),n.setUint32(e+u,a,r)}function NLe(n,e,t){return n&e^~n&t}function ULe(n,e,t){return n&e^n&t^e&t}var RO=class extends n8{constructor(e,t,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=mO(this.buffer)}update(e){$C(this),e=QO(e),Gc(e);let{view:t,buffer:r,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=mO(e);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){$C(this),kLe(e,this),this.finished=!0;let{buffer:t,view:r,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,e8(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(r,0),s=0);for(let d=s;d<i;d++)t[d]=0;FLe(r,i-8,BigInt(this.length*8),o),this.process(r,0);let a=mO(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:r,length:i,finished:o,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=a,i%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}},mh=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),GLe=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),gh=new Uint32Array(64),DO=class extends RO{constructor(e=32){super(64,e,8,!1),this.A=mh[0]|0,this.B=mh[1]|0,this.C=mh[2]|0,this.D=mh[3]|0,this.E=mh[4]|0,this.F=mh[5]|0,this.G=mh[6]|0,this.H=mh[7]|0}get(){let{A:e,B:t,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,r,i,o,s,a,c]}set(e,t,r,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let d=0;d<16;d++,t+=4)gh[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){let h=gh[d-15],f=gh[d-2],m=Ku(h,7)^Ku(h,18)^h>>>3,w=Ku(f,17)^Ku(f,19)^f>>>10;gh[d]=w+gh[d-7]+m+gh[d-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let h=Ku(a,6)^Ku(a,11)^Ku(a,25),f=l+h+NLe(a,c,u)+GLe[d]+gh[d]|0,w=(Ku(r,2)^Ku(r,13)^Ku(r,22))+ULe(r,i,o)|0;l=u,u=c,c=a,a=s+f|0,s=o,o=i,i=r,r=f+w|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,i,o,s,a,c,u,l)}roundClean(){e8(gh)}destroy(){this.set(0,0,0,0,0,0,0,0),e8(this.buffer)}},Mee=OLe(()=>new DO);var YO=BigInt(0),r8=BigInt(1);function i8(n,e=""){if(typeof n!="boolean"){let t=e&&`"${e}"`;throw new Error(t+"expected boolean, got type="+typeof n)}return n}function H0(n,e,t=""){let r=$E(n),i=n?.length,o=e!==void 0;if(!r||o&&i!==e){let s=t&&`"${t}" `,a=o?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof n}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return n}function jC(n){let e=n.toString(16);return e.length&1?"0"+e:e}function Oee(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?YO:BigInt("0x"+n)}function tI(n){return Oee(zy(n))}function Fee(n){return Gc(n),Oee(zy(Uint8Array.from(n).reverse()))}function jO(n,e){return t8(n.toString(16).padStart(e*2,"0"))}function Nee(n,e){return jO(n,e).reverse()}function ao(n,e,t){let r;if(typeof e=="string")try{r=t8(e)}catch(i){throw new Error(n+" must be hex string or Uint8Array, cause: "+i)}else if($E(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");return r}var gO=n=>typeof n=="bigint"&&YO<=n;function Uee(n,e,t){return gO(n)&&gO(e)&&gO(t)&&e<=n&&n<t}function HLe(n,e,t,r){if(!Uee(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}function WE(n){let e;for(e=0;n>YO;n>>=r8,e+=1);return e}function KLe(n,e){return n>>BigInt(e)&r8}var nI=n=>(r8<<BigInt(n))-r8;function JLe(n,e,t){if(typeof n!="number"||n<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=f=>new Uint8Array(f),i=f=>Uint8Array.of(f),o=r(n),s=r(n),a=0,c=()=>{o.fill(1),s.fill(0),a=0},u=(...f)=>t(s,o,...f),l=(f=r(0))=>{s=u(i(0),f),o=u(),f.length!==0&&(s=u(i(1),f),o=u())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){o=u();let w=o.slice();m.push(w),f+=o.length}return Fi(...m)};return(f,m)=>{c(),l(f);let w;for(;!(w=m(d()));)l();return c(),w}}function qLe(n){return typeof n=="function"&&Number.isSafeInteger(n.outputLen)}function u8(n,e,t={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(i,o,s){let a=n[i];if(s&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${c}`)}Object.entries(e).forEach(([i,o])=>r(i,o,!1)),Object.entries(t).forEach(([i,o])=>r(i,o,!0))}var ui=()=>{throw new Error("not implemented")};function TO(n){let e=new WeakMap;return(t,...r)=>{let i=e.get(t);if(i!==void 0)return i;let o=n(t,...r);return e.set(t,o),o}}var ea=BigInt(0),Wo=BigInt(1),K0=BigInt(2),Gee=BigInt(3),Hee=BigInt(4),Kee=BigInt(5),VLe=BigInt(7),Jee=BigInt(8),QLe=BigInt(9),qee=BigInt(16);function Ga(n,e){let t=n%e;return t>=ea?t:e+t}function fee(n,e){if(n===ea)throw new Error("invert: expected non-zero number");if(e<=ea)throw new Error("invert: expected positive modulus, got "+e);let t=Ga(n,e),r=e,i=ea,o=Wo;for(;t!==ea;){let a=r/t,c=r%t,u=i-o*a;r=t,t=c,i=o,o=u}if(r!==Wo)throw new Error("invert: does not exist");return Ga(i,e)}function WO(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function Vee(n,e){let t=(n.ORDER+Wo)/Hee,r=n.pow(e,t);return WO(n,r,e),r}function zLe(n,e){let t=(n.ORDER-Kee)/Jee,r=n.mul(e,K0),i=n.pow(r,t),o=n.mul(e,i),s=n.mul(n.mul(o,K0),i),a=n.mul(o,n.sub(s,n.ONE));return WO(n,a,e),a}function YLe(n){let e=jy(n),t=Qee(n),r=t(e,e.neg(e.ONE)),i=t(e,r),o=t(e,e.neg(r)),s=(n+VLe)/qee;return(a,c)=>{let u=a.pow(c,s),l=a.mul(u,r),d=a.mul(u,i),h=a.mul(u,o),f=a.eql(a.sqr(l),c),m=a.eql(a.sqr(d),c);u=a.cmov(u,l,f),l=a.cmov(h,d,m);let w=a.eql(a.sqr(l),c),b=a.cmov(u,l,w);return WO(a,b,c),b}}function Qee(n){if(n<Gee)throw new Error("sqrt is not defined for small field");let e=n-Wo,t=0;for(;e%K0===ea;)e/=K0,t++;let r=K0,i=jy(n);for(;o8(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Vee;let o=i.pow(r,e),s=(e+Wo)/K0;return function(c,u){if(c.is0(u))return u;if(o8(c,u)!==1)throw new Error("Cannot find square root");let l=t,d=c.mul(c.ONE,o),h=c.pow(u,e),f=c.pow(u,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,w=c.sqr(h);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===l)throw new Error("Cannot find square root");let b=Wo<<BigInt(l-m-1),S=c.pow(d,b);l=m,d=c.sqr(S),h=c.mul(h,d),f=c.mul(f,S)}return f}}function jLe(n){return n%Hee===Gee?Vee:n%Jee===Kee?zLe:n%qee===QLe?YLe(n):Qee(n)}var WLe=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ZLe(n){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=WLe.reduce((r,i)=>(r[i]="function",r),e);return u8(n,t),n}function l8(n,e,t){if(t<ea)throw new Error("invalid exponent, negatives unsupported");if(t===ea)return n.ONE;if(t===Wo)return e;let r=n.ONE,i=e;for(;t>ea;)t&Wo&&(r=n.mul(r,i)),i=n.sqr(i),t>>=Wo;return r}function rI(n,e,t=!1){let r=new Array(e.length).fill(t?n.ZERO:void 0),i=e.reduce((s,a,c)=>n.is0(a)?s:(r[c]=s,n.mul(s,a)),n.ONE),o=n.inv(i);return e.reduceRight((s,a,c)=>n.is0(a)?s:(r[c]=n.mul(s,r[c]),n.mul(s,a)),o),r}function o8(n,e){let t=(n.ORDER-Wo)/K0,r=n.pow(e,t),i=n.eql(r,n.ONE),o=n.eql(r,n.ZERO),s=n.eql(r,n.neg(n.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function zee(n,e){e!==void 0&&LO(e);let t=e!==void 0?e:n.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function jy(n,e,t=!1,r={}){if(n<=ea)throw new Error("invalid field: expected ORDER > 0, got "+n);let i,o,s=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(i=h.BITS),h.sqrt&&(o=h.sqrt),typeof h.isLE=="boolean"&&(t=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),a=h.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(o=r.sqrt);let{nBitLength:c,nByteLength:u}=zee(n,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:n,isLE:t,BITS:c,BYTES:u,MASK:nI(c),ZERO:ea,ONE:Wo,allowedLengths:a,create:h=>Ga(h,n),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return ea<=h&&h<n},is0:h=>h===ea,isValidNot0:h=>!d.is0(h)&&d.isValid(h),isOdd:h=>(h&Wo)===Wo,neg:h=>Ga(-h,n),eql:(h,f)=>h===f,sqr:h=>Ga(h*h,n),add:(h,f)=>Ga(h+f,n),sub:(h,f)=>Ga(h-f,n),mul:(h,f)=>Ga(h*f,n),pow:(h,f)=>l8(d,h,f),div:(h,f)=>Ga(h*fee(f,n),n),sqrN:h=>h*h,addN:(h,f)=>h+f,subN:(h,f)=>h-f,mulN:(h,f)=>h*f,inv:h=>fee(h,n),sqrt:o||(h=>(l||(l=jLe(n)),l(d,h))),toBytes:h=>t?Nee(h,u):jO(h,u),fromBytes:(h,f=!0)=>{if(a){if(!a.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+h.length);let w=new Uint8Array(u);w.set(h,t?0:w.length-h.length),h=w}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let m=t?Fee(h):tI(h);if(s&&(m=Ga(m,n)),!f&&!d.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>rI(d,h),cmov:(h,f,m)=>m?f:h});return Object.freeze(d)}function Yee(n){if(typeof n!="bigint")throw new Error("field order must be bigint");let e=n.toString(2).length;return Math.ceil(e/8)}function ZO(n){let e=Yee(n);return e+Math.ceil(e/2)}function jee(n,e,t=!1){let r=n.length,i=Yee(e),o=ZO(e);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);let s=t?Fee(n):tI(n),a=Ga(s,e-Wo)+Wo;return t?Nee(a,i):jO(a,i)}var Yy=BigInt(0),J0=BigInt(1);function s8(n,e){let t=e.negate();return n?t:e}function jE(n,e){let t=rI(n.Fp,e.map(r=>r.Z));return e.map((r,i)=>n.fromAffine(r.toAffine(t[i])))}function Wee(n,e){if(!Number.isSafeInteger(n)||n<=0||n>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+n)}function yO(n,e){Wee(n,e);let t=Math.ceil(e/n)+1,r=2**(n-1),i=2**n,o=nI(n),s=BigInt(n);return{windows:t,windowSize:r,mask:o,maxNumber:i,shiftBy:s}}function hee(n,e,t){let{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=t,a=Number(n&i),c=n>>s;a>r&&(a-=o,c+=J0);let u=e*r,l=u+Math.abs(a)-1,d=a===0,h=a<0,f=e%2!==0;return{nextN:c,offset:l,isZero:d,isNeg:h,isNegF:f,offsetF:u}}function XLe(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((t,r)=>{if(!(t instanceof e))throw new Error("invalid point at index "+r)})}function _Le(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((t,r)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+r)})}var wO=new WeakMap,Zee=new WeakMap;function bO(n){return Zee.get(n)||1}function pee(n){if(n!==Yy)throw new Error("invalid wNAF")}var BO=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,r=this.ZERO){let i=e;for(;t>Yy;)t&J0&&(r=r.add(i)),i=i.double(),t>>=J0;return r}precomputeWindow(e,t){let{windows:r,windowSize:i}=yO(t,this.bits),o=[],s=e,a=s;for(let c=0;c<r;c++){a=s,o.push(a);for(let u=1;u<i;u++)a=a.add(s),o.push(a);s=a.double()}return o}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=yO(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:h,offsetF:f}=hee(r,a,s);r=c,l?o=o.add(s8(h,t[f])):i=i.add(s8(d,t[u]))}return pee(r),{p:i,f:o}}wNAFUnsafe(e,t,r,i=this.ZERO){let o=yO(e,this.bits);for(let s=0;s<o.windows&&r!==Yy;s++){let{nextN:a,offset:c,isZero:u,isNeg:l}=hee(r,s,o);if(r=a,!u){let d=t[c];i=i.add(l?d.negate():d)}}return pee(r),i}getPrecomputes(e,t,r){let i=wO.get(t);return i||(i=this.precomputeWindow(t,e),e!==1&&(typeof r=="function"&&(i=r(i)),wO.set(t,i))),i}cached(e,t,r){let i=bO(e);return this.wNAF(i,this.getPrecomputes(i,e,r),t)}unsafe(e,t,r,i){let o=bO(e);return o===1?this._unsafeLadder(e,t,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,i)}createCache(e,t){Wee(t,this.bits),Zee.set(e,t),wO.delete(e)}hasCache(e){return bO(e)!==1}};function $Le(n,e,t,r){let i=e,o=n.ZERO,s=n.ZERO;for(;t>Yy||r>Yy;)t&J0&&(o=o.add(i)),r&J0&&(s=s.add(i)),i=i.double(),t>>=J0,r>>=J0;return{p1:o,p2:s}}function eRe(n,e,t,r){XLe(t,n),_Le(r,e);let i=t.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let s=n.ZERO,a=WE(BigInt(i)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=nI(c),l=new Array(Number(u)+1).fill(s),d=Math.floor((e.BITS-1)/c)*c,h=s;for(let f=d;f>=0;f-=c){l.fill(s);for(let w=0;w<o;w++){let b=r[w],S=Number(b>>BigInt(f)&u);l[S]=l[S].add(t[w])}let m=s;for(let w=l.length-1,b=s;w>0;w--)b=b.add(l[w]),m=m.add(b);if(h=h.add(m),f!==0)for(let w=0;w<c;w++)h=h.double()}return h}function mee(n,e,t){if(e){if(e.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ZLe(e),e}else return jy(n,{isLE:t})}function tRe(n,e,t={},r){if(r===void 0&&(r=n==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${n} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Yy))throw new Error(`CURVE.${c} must be positive bigint`)}let i=mee(e.p,t.Fp,r),o=mee(e.n,t.Fn,r),a=["Gx","Gy","a","b"];for(let c of a)if(!i.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}var nRe=tI;function yh(n,e){if(ZE(n),ZE(e),n<0||n>=1<<8*e)throw new Error("invalid I2OSP input: "+n);let t=Array.from({length:e}).fill(0);for(let r=e-1;r>=0;r--)t[r]=n&255,n>>>=8;return new Uint8Array(t)}function rRe(n,e){let t=new Uint8Array(n.length);for(let r=0;r<n.length;r++)t[r]=n[r]^e[r];return t}function ZE(n){if(!Number.isSafeInteger(n))throw new Error("number expected")}function Xee(n){if(!$E(n)&&typeof n!="string")throw new Error("DST must be Uint8Array or string");return typeof n=="string"?eI(n):n}function iRe(n,e,t,r){Gc(n),ZE(t),e=Xee(e),e.length>255&&(e=r(Fi(eI("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:o}=r,s=Math.ceil(t/i);if(t>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Fi(e,yh(e.length,1)),c=yh(0,o),u=yh(t,2),l=new Array(s),d=r(Fi(c,n,u,yh(0,1),a));l[0]=r(Fi(d,yh(1,1),a));for(let f=1;f<=s;f++){let m=[rRe(d,l[f-1]),yh(f+1,1),a];l[f]=r(Fi(...m))}return Fi(...l).slice(0,t)}function oRe(n,e,t,r,i){if(Gc(n),ZE(t),e=Xee(e),e.length>255){let o=Math.ceil(2*r/8);e=i.create({dkLen:o}).update(eI("H2C-OVERSIZE-DST-")).update(e).digest()}if(t>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:t}).update(n).update(yh(t,2)).update(e).update(yh(e.length,1)).digest()}function EO(n,e,t){u8(t,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:r,k:i,m:o,hash:s,expand:a,DST:c}=t;if(!qLe(t.hash))throw new Error("expected valid hash");Gc(n),ZE(e);let u=r.toString(2).length,l=Math.ceil((u+i)/8),d=e*o*l,h;if(a==="xmd")h=iRe(n,c,d,s);else if(a==="xof")h=oRe(n,c,d,i,s);else if(a==="_internal_pass")h=n;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(e);for(let m=0;m<e;m++){let w=new Array(o);for(let b=0;b<o;b++){let S=l*(b+m*o),R=h.subarray(S,S+l);w[b]=Ga(nRe(R),r)}f[m]=w}return f}var sRe=eI("HashToScalar-");function gee(n,e,t){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function r(o){return n.fromAffine(e(o))}function i(o){let s=o.clearCofactor();return s.equals(n.ZERO)?n.ZERO:(s.assertValidity(),s)}return{defaults:t,hashToCurve(o,s){let a=Object.assign({},t,s),c=EO(o,2,a),u=r(c[0]),l=r(c[1]);return i(u.add(l))},encodeToCurve(o,s){let a=t.encodeDST?{DST:t.encodeDST}:{},c=Object.assign({},t,a,s),u=EO(o,1,c),l=r(u[0]);return i(l)},mapToCurve(o){if(!Array.isArray(o))throw new Error("expected array of bigints");for(let s of o)if(typeof s!="bigint")throw new Error("expected array of bigints");return i(r(o))},hashToScalar(o,s){let a=n.Fn.ORDER,c=Object.assign({},t,{p:a,m:1,DST:sRe},s);return EO(o,1,c)[0][0]}}}var a8=class extends n8{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Pee(e);let r=QO(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(r.length>i?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),e8(o)}update(e){return $C(this),this.iHash.update(e),this}digestInto(e){$C(this),Gc(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:r,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},_ee=(n,e,t)=>new a8(n,e).update(t).digest();_ee.create=(n,e)=>new a8(n,e);var yee=(n,e)=>(n+(n>=0?e:-e)/$ee)/e;function aRe(n,e,t){let[[r,i],[o,s]]=e,a=yee(s*n,t),c=yee(-i*n,t),u=n-a*r-c*o,l=-a*i-c*s,d=u<Ed,h=l<Ed;d&&(u=-u),h&&(l=-l);let f=nI(Math.ceil(WE(t)/2))+q0;if(u<Ed||u>=f||l<Ed||l>=f)throw new Error("splitScalar (endomorphism): failed, k="+n);return{k1neg:d,k1:u,k2neg:h,k2:l}}function PO(n){if(!["compact","recovered","der"].includes(n))throw new Error('Signature format must be "compact", "recovered", or "der"');return n}function IO(n,e){let t={};for(let r of Object.keys(e))t[r]=n[r]===void 0?e[r]:n[r];return i8(t.lowS,"lowS"),i8(t.prehash,"prehash"),t.format!==void 0&&PO(t.format),t}var kO=class extends Error{constructor(e=""){super(e)}},bd={Err:kO,_tlv:{encode:(n,e)=>{let{Err:t}=bd;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let r=e.length/2,i=jC(r);if(i.length/2&128)throw new t("tlv.encode: long form length too big");let o=r>127?jC(i.length/2|128):"";return jC(n)+o+i+e},decode(n,e){let{Err:t}=bd,r=0;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[r++]!==n)throw new t("tlv.decode: wrong tlv");let i=e[r++],o=!!(i&128),s=0;if(!o)s=i;else{let c=i&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(r,r+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)s=s<<8|l;if(r+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(r,r+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+s)}}},_int:{encode(n){let{Err:e}=bd;if(n<Ed)throw new e("integer: negative integers are not allowed");let t=jC(n);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(n){let{Err:e}=bd;if(n[0]&128)throw new e("invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tI(n)}},toSig(n){let{Err:e,_int:t,_tlv:r}=bd,i=ao("signature",n),{v:o,l:s}=r.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=r.decode(2,o),{v:u,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(n){let{_tlv:e,_int:t}=bd,r=e.encode(2,t.encode(n.r)),i=e.encode(2,t.encode(n.s)),o=r+i;return e.encode(48,o)}},Ed=BigInt(0),q0=BigInt(1),$ee=BigInt(2),WC=BigInt(3),cRe=BigInt(4);function Id(n,e){let{BYTES:t}=n,r;if(typeof e=="bigint")r=e;else{let i=ao("private key",e);try{r=n.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!n.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function ete(n,e={}){let t=tRe("weierstrass",n,e),{Fp:r,Fn:i}=t,o=t.CURVE,{h:s,n:a}=o;u8(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!r.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=nte(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(Q,v,p){let{x,y}=v.toAffine(),I=r.toBytes(x);if(i8(p,"isCompressed"),p){l();let C=!r.isOdd(y);return Fi(tte(C),I)}else return Fi(Uint8Array.of(4),I,r.toBytes(y))}function h(Q){H0(Q,void 0,"Point");let{publicKey:v,publicKeyUncompressed:p}=u,x=Q.length,y=Q[0],I=Q.subarray(1);if(x===v&&(y===2||y===3)){let C=r.fromBytes(I);if(!r.isValid(C))throw new Error("bad point: is not on curve, wrong x");let F=w(C),N;try{N=r.sqrt(F)}catch(q){let _=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+_)}l();let O=r.isOdd(N);return(y&1)===1!==O&&(N=r.neg(N)),{x:C,y:N}}else if(x===p&&y===4){let C=r.BYTES,F=r.fromBytes(I.subarray(0,C)),N=r.fromBytes(I.subarray(C,C*2));if(!b(F,N))throw new Error("bad point: is not on curve");return{x:F,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${v} or uncompressed=${p}`)}let f=e.toBytes||d,m=e.fromBytes||h;function w(Q){let v=r.sqr(Q),p=r.mul(v,Q);return r.add(r.add(p,r.mul(Q,o.a)),o.b)}function b(Q,v){let p=r.sqr(v),x=w(Q);return r.eql(p,x)}if(!b(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=r.mul(r.pow(o.a,WC),cRe),R=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(S,R)))throw new Error("bad curve params: a or b");function G(Q,v,p=!1){if(!r.isValid(v)||p&&r.is0(v))throw new Error(`bad point coordinate ${Q}`);return v}function U(Q){if(!(Q instanceof z))throw new Error("ProjectivePoint expected")}function H(Q){if(!c||!c.basises)throw new Error("no endo");return aRe(Q,c.basises,i.ORDER)}let M=TO((Q,v)=>{let{X:p,Y:x,Z:y}=Q;if(r.eql(y,r.ONE))return{x:p,y:x};let I=Q.is0();v==null&&(v=I?r.ONE:r.inv(y));let C=r.mul(p,v),F=r.mul(x,v),N=r.mul(y,v);if(I)return{x:r.ZERO,y:r.ZERO};if(!r.eql(N,r.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}),A=TO(Q=>{if(Q.is0()){if(e.allowInfinityPoint&&!r.is0(Q.Y))return;throw new Error("bad point: ZERO")}let{x:v,y:p}=Q.toAffine();if(!r.isValid(v)||!r.isValid(p))throw new Error("bad point: x or y not field elements");if(!b(v,p))throw new Error("bad point: equation left != right");if(!Q.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function D(Q,v,p,x,y){return p=new z(r.mul(p.X,Q),p.Y,p.Z),v=s8(x,v),p=s8(y,p),v.add(p)}class z{constructor(v,p,x){this.X=G("x",v),this.Y=G("y",p,!0),this.Z=G("z",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(v){let{x:p,y:x}=v||{};if(!v||!r.isValid(p)||!r.isValid(x))throw new Error("invalid affine point");if(v instanceof z)throw new Error("projective point not allowed");return r.is0(p)&&r.is0(x)?z.ZERO:new z(p,x,r.ONE)}static fromBytes(v){let p=z.fromAffine(m(H0(v,void 0,"point")));return p.assertValidity(),p}static fromHex(v){return z.fromBytes(ao("pointHex",v))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(v=8,p=!0){return Y.createCache(this,v),p||this.multiply(WC),this}assertValidity(){A(this)}hasEvenY(){let{y:v}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(v)}equals(v){U(v);let{X:p,Y:x,Z:y}=this,{X:I,Y:C,Z:F}=v,N=r.eql(r.mul(p,F),r.mul(I,y)),O=r.eql(r.mul(x,F),r.mul(C,y));return N&&O}negate(){return new z(this.X,r.neg(this.Y),this.Z)}double(){let{a:v,b:p}=o,x=r.mul(p,WC),{X:y,Y:I,Z:C}=this,F=r.ZERO,N=r.ZERO,O=r.ZERO,T=r.mul(y,y),q=r.mul(I,I),_=r.mul(C,C),L=r.mul(y,I);return L=r.add(L,L),O=r.mul(y,C),O=r.add(O,O),F=r.mul(v,O),N=r.mul(x,_),N=r.add(F,N),F=r.sub(q,N),N=r.add(q,N),N=r.mul(F,N),F=r.mul(L,F),O=r.mul(x,O),_=r.mul(v,_),L=r.sub(T,_),L=r.mul(v,L),L=r.add(L,O),O=r.add(T,T),T=r.add(O,T),T=r.add(T,_),T=r.mul(T,L),N=r.add(N,T),_=r.mul(I,C),_=r.add(_,_),T=r.mul(_,L),F=r.sub(F,T),O=r.mul(_,q),O=r.add(O,O),O=r.add(O,O),new z(F,N,O)}add(v){U(v);let{X:p,Y:x,Z:y}=this,{X:I,Y:C,Z:F}=v,N=r.ZERO,O=r.ZERO,T=r.ZERO,q=o.a,_=r.mul(o.b,WC),L=r.mul(p,I),g=r.mul(x,C),K=r.mul(y,F),E=r.add(p,x),V=r.add(I,C);E=r.mul(E,V),V=r.add(L,g),E=r.sub(E,V),V=r.add(p,y);let J=r.add(I,F);return V=r.mul(V,J),J=r.add(L,K),V=r.sub(V,J),J=r.add(x,y),N=r.add(C,F),J=r.mul(J,N),N=r.add(g,K),J=r.sub(J,N),T=r.mul(q,V),N=r.mul(_,K),T=r.add(N,T),N=r.sub(g,T),T=r.add(g,T),O=r.mul(N,T),g=r.add(L,L),g=r.add(g,L),K=r.mul(q,K),V=r.mul(_,V),g=r.add(g,K),K=r.sub(L,K),K=r.mul(q,K),V=r.add(V,K),L=r.mul(g,V),O=r.add(O,L),L=r.mul(J,V),N=r.mul(E,N),N=r.sub(N,L),L=r.mul(E,g),T=r.mul(J,T),T=r.add(T,L),new z(N,O,T)}subtract(v){return this.add(v.negate())}is0(){return this.equals(z.ZERO)}multiply(v){let{endo:p}=e;if(!i.isValidNot0(v))throw new Error("invalid scalar: out of range");let x,y,I=C=>Y.cached(this,C,F=>jE(z,F));if(p){let{k1neg:C,k1:F,k2neg:N,k2:O}=H(v),{p:T,f:q}=I(F),{p:_,f:L}=I(O);y=q.add(L),x=D(p.beta,T,_,C,N)}else{let{p:C,f:F}=I(v);x=C,y=F}return jE(z,[x,y])[0]}multiplyUnsafe(v){let{endo:p}=e,x=this;if(!i.isValid(v))throw new Error("invalid scalar: out of range");if(v===Ed||x.is0())return z.ZERO;if(v===q0)return x;if(Y.hasCache(this))return this.multiply(v);if(p){let{k1neg:y,k1:I,k2neg:C,k2:F}=H(v),{p1:N,p2:O}=$Le(z,x,I,F);return D(p.beta,N,O,y,C)}else return Y.unsafe(x,v)}multiplyAndAddUnsafe(v,p,x){let y=this.multiplyUnsafe(p).add(v.multiplyUnsafe(x));return y.is0()?void 0:y}toAffine(v){return M(this,v)}isTorsionFree(){let{isTorsionFree:v}=e;return s===q0?!0:v?v(z,this):Y.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:v}=e;return s===q0?this:v?v(z,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(v=!0){return i8(v,"isCompressed"),this.assertValidity(),f(z,this,v)}toHex(v=!0){return zy(this.toBytes(v))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(v=!0){return this.toBytes(v)}_setWindowSize(v){this.precompute(v)}static normalizeZ(v){return jE(z,v)}static msm(v,p){return eRe(z,i,v,p)}static fromPrivateKey(v){return z.BASE.multiply(Id(i,v))}}z.BASE=new z(o.Gx,o.Gy,r.ONE),z.ZERO=new z(r.ZERO,r.ONE,r.ZERO),z.Fp=r,z.Fn=i;let j=i.BITS,Y=new BO(z,e.endo?Math.ceil(j/2):j);return z.BASE.precompute(8),z}function tte(n){return Uint8Array.of(n?2:3)}function nte(n,e){return{secretKey:e.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function uRe(n,e={}){let{Fn:t}=n,r=e.randomBytes||zO,i=Object.assign(nte(n.Fp,t),{seed:ZO(t.ORDER)});function o(f){try{return!!Id(t,f)}catch{return!1}}function s(f,m){let{publicKey:w,publicKeyUncompressed:b}=i;try{let S=f.length;return m===!0&&S!==w||m===!1&&S!==b?!1:!!n.fromBytes(f)}catch{return!1}}function a(f=r(i.seed)){return jee(H0(f,i.seed,"seed"),t.ORDER)}function c(f,m=!0){return n.BASE.multiply(Id(t,f)).toBytes(m)}function u(f){let m=a(f);return{secretKey:m,publicKey:c(m)}}function l(f){if(typeof f=="bigint")return!1;if(f instanceof n)return!0;let{secretKey:m,publicKey:w,publicKeyUncompressed:b}=i;if(t.allowedLengths||m===w)return;let S=ao("key",f).length;return S===w||S===b}function d(f,m,w=!0){if(l(f)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");let b=Id(t,f);return n.fromHex(m).multiply(b).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:n,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:f=>Id(t,f),precompute(f=8,m=n.BASE){return m.precompute(f,!1)}},lengths:i})}function lRe(n,e,t={}){Pee(e),u8(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let r=t.randomBytes||zO,i=t.hmac||((p,...x)=>_ee(e,p,Fi(...x))),{Fp:o,Fn:s}=n,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:d,utils:h,lengths:f}=uRe(n,t),m={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function b(p){let x=a>>q0;return p>x}function S(p,x){if(!s.isValidNot0(x))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return x}function R(p,x){PO(x);let y=f.signature,I=x==="compact"?y:x==="recovered"?y+1:void 0;return H0(p,I,`${x} signature`)}class G{constructor(x,y,I){this.r=S("r",x),this.s=S("s",y),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(x,y=w){R(x,y);let I;if(y==="der"){let{r:O,s:T}=bd.toSig(H0(x));return new G(O,T)}y==="recovered"&&(I=x[0],y="compact",x=x.subarray(1));let C=s.BYTES,F=x.subarray(0,C),N=x.subarray(C,C*2);return new G(s.fromBytes(F),s.fromBytes(N),I)}static fromHex(x,y){return this.fromBytes(t8(x),y)}addRecoveryBit(x){return new G(this.r,this.s,x)}recoverPublicKey(x){let y=o.ORDER,{r:I,s:C,recovery:F}=this;if(F==null||![0,1,2,3].includes(F))throw new Error("recovery id invalid");if(a*$ee<y&&F>1)throw new Error("recovery id is ambiguous for h>1 curve");let O=F===2||F===3?I+a:I;if(!o.isValid(O))throw new Error("recovery id 2 or 3 invalid");let T=o.toBytes(O),q=n.fromBytes(Fi(tte((F&1)===0),T)),_=s.inv(O),L=H(ao("msgHash",x)),g=s.create(-L*_),K=s.create(C*_),E=n.BASE.multiplyUnsafe(g).add(q.multiplyUnsafe(K));if(E.is0())throw new Error("point at infinify");return E.assertValidity(),E}hasHighS(){return b(this.s)}toBytes(x=w){if(PO(x),x==="der")return t8(bd.hexFromSig(this));let y=s.toBytes(this.r),I=s.toBytes(this.s);if(x==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Fi(Uint8Array.of(this.recovery),y,I)}return Fi(y,I)}toHex(x){return zy(this.toBytes(x))}assertValidity(){}static fromCompact(x){return G.fromBytes(ao("sig",x),"compact")}static fromDER(x){return G.fromBytes(ao("sig",x),"der")}normalizeS(){return this.hasHighS()?new G(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return zy(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return zy(this.toBytes("compact"))}}let U=t.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");let y=tI(x),I=x.length*8-c;return I>0?y>>BigInt(I):y},H=t.bits2int_modN||function(x){return s.create(U(x))},M=nI(c);function A(p){return HLe("num < 2^"+c,p,Ed,M),s.toBytes(p)}function D(p,x){return H0(p,void 0,"message"),x?H0(e(p),void 0,"prehashed message"):p}function z(p,x,y){if(["recovered","canonical"].some(g=>g in y))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:C,extraEntropy:F}=IO(y,m);p=D(p,C);let N=H(p),O=Id(s,x),T=[A(O),A(N)];if(F!=null&&F!==!1){let g=F===!0?r(f.secretKey):F;T.push(ao("extraEntropy",g))}let q=Fi(...T),_=N;function L(g){let K=U(g);if(!s.isValidNot0(K))return;let E=s.inv(K),V=n.BASE.multiply(K).toAffine(),J=s.create(V.x);if(J===Ed)return;let B=s.create(E*s.create(_+J*O));if(B===Ed)return;let X=(V.x===J?0:2)|Number(V.y&q0),ce=B;return I&&b(B)&&(ce=s.neg(B),X^=1),new G(J,ce,X)}return{seed:q,k2sig:L}}function j(p,x,y={}){p=ao("message",p);let{seed:I,k2sig:C}=z(p,x,y);return JLe(e.outputLen,s.BYTES,i)(I,C)}function Y(p){let x,y=typeof p=="string"||$E(p),I=!y&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!y&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)x=new G(p.r,p.s);else if(y){try{x=G.fromBytes(ao("sig",p),"der")}catch(C){if(!(C instanceof bd.Err))throw C}if(!x)try{x=G.fromBytes(ao("sig",p),"compact")}catch{return!1}}return x||!1}function Q(p,x,y,I={}){let{lowS:C,prehash:F,format:N}=IO(I,m);if(y=ao("publicKey",y),x=D(ao("message",x),F),"strict"in I)throw new Error("options.strict was renamed to lowS");let O=N===void 0?Y(p):G.fromBytes(ao("sig",p),N);if(O===!1)return!1;try{let T=n.fromBytes(y);if(C&&O.hasHighS())return!1;let{r:q,s:_}=O,L=H(x),g=s.inv(_),K=s.create(L*g),E=s.create(q*g),V=n.BASE.multiplyUnsafe(K).add(T.multiplyUnsafe(E));return V.is0()?!1:s.create(V.x)===q}catch{return!1}}function v(p,x,y={}){let{prehash:I}=IO(y,m);return x=D(x,I),G.fromBytes(p,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:d,utils:h,lengths:f,Point:n,sign:j,verify:Q,recoverPublicKey:v,Signature:G,hash:e})}function wee(n){let{CURVE:e,curveOpts:t}=rte(n),r=ete(e,t);return hRe(n,r)}function rte(n){let e={a:n.a,b:n.b,p:n.Fp.ORDER,n:n.n,h:n.h,Gx:n.Gx,Gy:n.Gy},t=n.Fp,r=n.allowedPrivateKeyLengths?Array.from(new Set(n.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,i=jy(e.n,{BITS:n.nBitLength,allowedLengths:r,modFromBytes:n.wrapPrivateKey}),o={Fp:t,Fn:i,allowInfinityPoint:n.allowInfinityPoint,endo:n.endo,isTorsionFree:n.isTorsionFree,clearCofactor:n.clearCofactor,fromBytes:n.fromBytes,toBytes:n.toBytes};return{CURVE:e,curveOpts:o}}function dRe(n){let{CURVE:e,curveOpts:t}=rte(n),r={hmac:n.hmac,randomBytes:n.randomBytes,lowS:n.lowS,bits2int:n.bits2int,bits2int_modN:n.bits2int_modN};return{CURVE:e,curveOpts:t,hash:n.hash,ecdsaOpts:r}}function fRe(n,e,t){function r(i){let o=n.sqr(i),s=n.mul(o,i);return n.add(n.add(s,n.mul(i,e)),t)}return r}function hRe(n,e){let{Fp:t,Fn:r}=e;function i(s){return Uee(s,q0,r.ORDER)}let o=fRe(t,n.a,n.b);return Object.assign({},{CURVE:n,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:s=>Id(r,s),weierstrassEquation:o,isWithinCurveOrder:i})}function pRe(n,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},n,zee(t.Fn.ORDER,t.Fn.BITS))})}function mRe(n){let{CURVE:e,curveOpts:t,hash:r,ecdsaOpts:i}=dRe(n),o=ete(e,t),s=lRe(o,r,i);return pRe(n,s)}var gRe=BigInt(0),ZC=BigInt(1),bee=BigInt(2),Qy=BigInt(3);function yRe(n){let e=[];for(;n>ZC;n>>=ZC)(n&ZC)===gRe?e.unshift(0):(n&Qy)===Qy?(e.unshift(-1),n+=ZC):e.unshift(1);return e}function AO(n){if(!Array.isArray(n)||n.length===0)throw new Error("expected non-empty array")}function wRe(n,e,t,r){let{Fp2:i,Fp12:o}=n,{twistType:s,ateLoopSize:a,xNegative:c,postPrecompute:u}=r,l;if(s==="multiplicative")l=(G,U,H,M,A,D)=>o.mul014(M,G,i.mul(U,A),i.mul(H,D));else if(s==="divisive")l=(G,U,H,M,A,D)=>o.mul034(M,i.mul(H,D),i.mul(U,A),G);else throw new Error("bls: unknown twist type");let d=i.div(i.ONE,i.mul(i.ONE,bee));function h(G,U,H,M){let A=i.sqr(H),D=i.sqr(M),z=i.mulByB(i.mul(D,Qy)),j=i.mul(z,Qy),Y=i.sub(i.sub(i.sqr(i.add(H,M)),D),A),Q=i.sub(z,A),v=i.mul(i.sqr(U),Qy),p=i.neg(Y);return G.push([Q,v,p]),U=i.mul(i.mul(i.mul(i.sub(A,j),U),H),d),H=i.sub(i.sqr(i.mul(i.add(A,j),d)),i.mul(i.sqr(z),Qy)),M=i.mul(A,Y),{Rx:U,Ry:H,Rz:M}}function f(G,U,H,M,A,D){let z=i.sub(H,i.mul(D,M)),j=i.sub(U,i.mul(A,M)),Y=i.sub(i.mul(z,A),i.mul(j,D)),Q=i.neg(z),v=j;G.push([Y,Q,v]);let p=i.sqr(j),x=i.mul(p,j),y=i.mul(p,U),I=i.add(i.sub(x,i.mul(y,bee)),i.mul(i.sqr(z),M));return U=i.mul(j,I),H=i.sub(i.mul(i.sub(y,I),z),i.mul(x,H)),M=i.mul(M,x),{Rx:U,Ry:H,Rz:M}}let m=yRe(a),w=TO(G=>{let U=G,{x:H,y:M}=U.toAffine(),A=H,D=M,z=i.neg(M),j=A,Y=D,Q=i.ONE,v=[];for(let p of m){let x=[];({Rx:j,Ry:Y,Rz:Q}=h(x,j,Y,Q)),p&&({Rx:j,Ry:Y,Rz:Q}=f(x,j,Y,Q,A,p===-1?z:D)),v.push(x)}if(u){let p=v[v.length-1];u(j,Y,Q,A,D,f.bind(null,p))}return v});function b(G,U=!1){let H=o.ONE;if(G.length){let M=G[0][0].length;for(let A=0;A<M;A++){H=o.sqr(H);for(let[D,z,j]of G)for(let[Y,Q,v]of D[A])H=l(Y,Q,v,H,z,j)}}return c&&(H=o.conjugate(H)),U?o.finalExponentiate(H):H}function S(G,U=!0){let H=[];jE(e,G.map(({g1:M})=>M)),jE(t,G.map(({g2:M})=>M));for(let{g1:M,g2:A}of G){if(M.is0()||A.is0())throw new Error("pairing is not available for ZERO point");M.assertValidity(),A.assertValidity();let D=M.toAffine();H.push([w(A),D.x,D.y])}return b(H,U)}function R(G,U,H=!0){return S([{g1:G,g2:U}],H)}return{Fp12:o,millerLoopBatch:b,pairing:R,pairingBatch:S,calcPairingPrecomputes:w}}function Eee(n,e,t,r,i){let{Fp12:o,pairingBatch:s}=n;function a(d){return d instanceof e.Point?d:e.Point.fromHex(d)}function c(d){return d instanceof t.Point?d:t.Point.fromHex(d)}function u(d){if(!(d instanceof t.Point))throw new Error(`expected valid message hashed to ${i?"G1":"G2"} curve`);return d}let l=i?(d,h)=>({g1:h,g2:d}):(d,h)=>({g1:d,g2:h});return{getPublicKey(d){let h=Id(e.Point.Fn,d);return e.Point.BASE.multiply(h)},sign(d,h,f){if(f!=null)throw new Error("sign() expects 2 arguments");let m=Id(e.Point.Fn,h);return u(d).assertValidity(),d.multiply(m)},verify(d,h,f,m){if(m!=null)throw new Error("verify() expects 3 arguments");d=c(d),f=a(f);let w=f.negate(),b=e.Point.BASE,S=u(h),R=d,G=s([l(w,S),l(b,R)]);return o.eql(G,o.ONE)},verifyBatch(d,h,f){if(AO(h),f.length!==h.length)throw new Error("amount of public keys and messages should be equal");let m=c(d),w=h,b=f.map(a),S=new Map;for(let U=0;U<b.length;U++){let H=b[U],M=w[U],A=S.get(M);A===void 0&&(A=[],S.set(M,A)),A.push(H)}let R=[],G=e.Point.BASE;try{for(let[U,H]of S){let M=H.reduce((A,D)=>A.add(D));R.push(l(M,U))}return R.push(l(G.negate(),m)),o.eql(s(R),o.ONE)}catch{return!1}},aggregatePublicKeys(d){AO(d),d=d.map(f=>a(f));let h=d.reduce((f,m)=>f.add(m),e.Point.ZERO);return h.assertValidity(),h},aggregateSignatures(d){AO(d),d=d.map(f=>c(f));let h=d.reduce((f,m)=>f.add(m),t.Point.ZERO);return h.assertValidity(),h},hash(d,h){Gc(d);let f=h?{DST:h}:void 0;return t.hashToCurve(d,f)},Signature:r}}function bRe(n){let{Fp:e,Fr:t,Fp2:r,Fp6:i,Fp12:o}=n.fields,s=wee(n.G1),a=Object.assign(s,gee(s.Point,n.G1.mapToCurve,{...n.htfDefaults,...n.G1.htfDefaults})),c=wee(n.G2),u=Object.assign(c,gee(c.Point,n.G2.mapToCurve,{...n.htfDefaults,...n.G2.htfDefaults})),l=wRe(n.fields,a.Point,u.Point,{...n.params,postPrecompute:n.postPrecompute}),{millerLoopBatch:d,pairing:h,pairingBatch:f,calcPairingPrecomputes:m}=l,w=Eee(l,a,u,n.G2.Signature,!1),b=Eee(l,u,a,n.G1.ShortSignature,!0),S=n.randomBytes||zO,R=()=>{let C=ZO(t.ORDER);return jee(S(C),t.ORDER)},G={randomSecretKey:R,randomPrivateKey:R,calcPairingPrecomputes:m},{ShortSignature:U}=n.G1,{Signature:H}=n.G2;function M(C,F){return C instanceof a.Point?C:b.hash(ao("point",C),F?.DST)}function A(C,F){return C instanceof u.Point?C:w.hash(ao("point",C),F?.DST)}function D(C){return w.getPublicKey(C).toBytes(!0)}function z(C){return b.getPublicKey(C).toBytes(!0)}function j(C,F,N){let O=A(C,N),T=w.sign(O,F);return C instanceof u.Point?T:H.toBytes(T)}function Y(C,F,N){let O=M(C,N),T=b.sign(O,F);return C instanceof a.Point?T:U.toBytes(T)}function Q(C,F,N,O){let T=A(F,O);return w.verify(C,T,N)}function v(C,F,N,O){let T=M(F,O);return b.verify(C,T,N)}function p(C){let F=w.aggregatePublicKeys(C);return C[0]instanceof a.Point?F:F.toBytes(!0)}function x(C){let F=w.aggregateSignatures(C);return C[0]instanceof u.Point?F:H.toBytes(F)}function y(C){let F=b.aggregateSignatures(C);return C[0]instanceof a.Point?F:U.toBytes(F)}function I(C,F,N,O){let T=F.map(q=>A(q,O));return w.verifyBatch(C,T,N)}return a.Point.BASE.precompute(4),{longSignatures:w,shortSignatures:b,millerLoopBatch:d,pairing:h,pairingBatch:f,verifyBatch:I,fields:{Fr:t,Fp:e,Fp2:r,Fp6:i,Fp12:o},params:{ateLoopSize:n.params.ateLoopSize,twistType:n.params.twistType,r:n.params.r,G1b:n.G1.b,G2b:n.G2.b},utils:G,getPublicKey:D,getPublicKeyForShortSignatures:z,sign:j,signShortSignature:Y,verify:Q,verifyShortSignature:v,aggregatePublicKeys:p,aggregateSignatures:x,aggregateShortSignatures:y,G1:a,G2:u,Signature:H,ShortSignature:U}}var Iee=BigInt(0),Ad=BigInt(1),jo=BigInt(2),Aee=BigInt(3);function XO(n,e,t,r,i=1,o){let s=BigInt(o===void 0?r:o),a=t**BigInt(r),c=[];for(let u=0;u<i;u++){let l=BigInt(u+1),d=[];for(let h=0,f=Ad;h<r;h++){let m=(l*f-l)/s%a;d.push(n.pow(e,m)),f*=t}c.push(d)}return c}function ERe(n,e,t){let r=e.pow(t,(n.ORDER-Ad)/Aee),i=e.pow(t,(n.ORDER-Ad)/jo);function o(h,f){let m=e.mul(e.frobeniusMap(h,1),r),w=e.mul(e.frobeniusMap(f,1),i);return[m,w]}let s=e.pow(t,(n.ORDER**jo-Ad)/Aee),a=e.pow(t,(n.ORDER**jo-Ad)/jo);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(h,f){return[e.mul(h,s),e.neg(f)]}let u=h=>(f,m)=>{let w=m.toAffine(),b=h(w.x,w.y);return f.fromAffine({x:b[0],y:b[1]})},l=u(o),d=u(c);return{psi:o,psi2:c,G2psi:l,G2psi2:d,PSI_X:r,PSI_Y:i,PSI2_X:s,PSI2_Y:a}}var xee=(n,e)=>{if(e.length!==2)throw new Error("invalid tuple");let t=e.map(r=>n.create(r));return{c0:t[0],c1:t[1]}},MO=class{constructor(e,t={}){this.MASK=Ad;let r=e.ORDER,i=r*r;this.Fp=e,this.ORDER=i,this.BITS=WE(i),this.BYTES=Math.ceil(WE(i)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(t.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,jo),this.NONRESIDUE=xee(e,t.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=XO(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=t.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return xee(this.Fp,e)}create(e){return e}isValid({c0:e,c1:t}){function r(i,o){return typeof i=="bigint"&&Iee<=i&&i<o}return r(e,this.ORDER)&&r(t,this.ORDER)}is0({c0:e,c1:t}){return this.Fp.is0(e)&&this.Fp.is0(t)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:t},{c0:r,c1:i}){return this.Fp.eql(e,r)&&this.Fp.eql(t,i)}neg({c0:e,c1:t}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(t)}}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}add(e,t){let{c0:r,c1:i}=e,{c0:o,c1:s}=t;return{c0:this.Fp.add(r,o),c1:this.Fp.add(i,s)}}sub({c0:e,c1:t},{c0:r,c1:i}){return{c0:this.Fp.sub(e,r),c1:this.Fp.sub(t,i)}}mul({c0:e,c1:t},r){let{Fp:i}=this;if(typeof r=="bigint")return{c0:i.mul(e,r),c1:i.mul(t,r)};let{c0:o,c1:s}=r,a=i.mul(e,o),c=i.mul(t,s),u=i.sub(a,c),l=i.sub(i.mul(i.add(e,t),i.add(o,s)),i.add(a,c));return{c0:u,c1:l}}sqr({c0:e,c1:t}){let{Fp:r}=this,i=r.add(e,t),o=r.sub(e,t),s=r.add(e,e);return{c0:r.mul(i,o),c1:r.mul(s,t)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}div(e,t){let{Fp:r}=this;return this.mul(e,typeof t=="bigint"?r.inv(r.create(t)):this.inv(t))}inv({c0:e,c1:t}){let{Fp:r}=this,i=r.inv(r.create(e*e+t*t));return{c0:r.mul(i,r.create(e)),c1:r.mul(i,r.create(-t))}}sqrt(e){let{Fp:t}=this,r=this,{c0:i,c1:o}=e;if(t.is0(o))return o8(t,i)===1?r.create({c0:t.sqrt(i),c1:t.ZERO}):r.create({c0:t.ZERO,c1:t.sqrt(t.div(i,this.Fp_NONRESIDUE))});let s=t.sqrt(t.sub(t.sqr(i),t.mul(t.sqr(o),this.Fp_NONRESIDUE))),a=t.mul(t.add(s,i),this.Fp_div2);o8(t,a)===-1&&(a=t.sub(a,s));let u=t.sqrt(a),l=r.create({c0:u,c1:t.div(t.mul(o,this.Fp_div2),u)});if(!r.eql(r.sqr(l),e))throw new Error("Cannot find square root");let d=l,h=r.neg(d),{re:f,im:m}=r.reim(d),{re:w,im:b}=r.reim(h);return m>b||m===b&&f>w?d:h}isOdd(e){let{re:t,im:r}=this.reim(e),i=t%jo,o=t===Iee,s=r%jo;return BigInt(i||o&&s)==Ad}fromBytes(e){let{Fp:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:t.fromBytes(e.subarray(0,t.BYTES)),c1:t.fromBytes(e.subarray(t.BYTES))}}toBytes({c0:e,c1:t}){return Fi(this.Fp.toBytes(e),this.Fp.toBytes(t))}cmov({c0:e,c1:t},{c0:r,c1:i},o){return{c0:this.Fp.cmov(e,r,o),c1:this.Fp.cmov(t,i,o)}}reim({c0:e,c1:t}){return{re:e,im:t}}Fp4Square(e,t){let r=this,i=r.sqr(e),o=r.sqr(t);return{first:r.add(r.mulByNonresidue(o),i),second:r.sub(r.sub(r.sqr(r.add(e,t)),i),o)}}mulByNonresidue({c0:e,c1:t}){return this.mul({c0:e,c1:t},this.NONRESIDUE)}frobeniusMap({c0:e,c1:t},r){return{c0:e,c1:this.Fp.mul(t,this.FROBENIUS_COEFFICIENTS[r%2])}}},OO=class{constructor(e){this.MASK=Ad,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:t}=e,r=XO(e,e.NONRESIDUE,t.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=r[0],this.FROBENIUS_COEFFICIENTS_2=r[1],Object.seal(this)}add({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return{c0:a.add(e,i),c1:a.add(t,o),c2:a.add(r,s)}}sub({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return{c0:a.sub(e,i),c1:a.sub(t,o),c2:a.sub(r,s)}}mul({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;if(typeof i=="bigint")return{c0:o.mul(e,i),c1:o.mul(t,i),c2:o.mul(r,i)};let{c0:s,c1:a,c2:c}=i,u=o.mul(e,s),l=o.mul(t,a),d=o.mul(r,c);return{c0:o.add(u,o.mulByNonresidue(o.sub(o.mul(o.add(t,r),o.add(a,c)),o.add(l,d)))),c1:o.add(o.sub(o.mul(o.add(e,t),o.add(s,a)),o.add(u,l)),o.mulByNonresidue(d)),c2:o.sub(o.add(l,o.mul(o.add(e,r),o.add(s,c))),o.add(u,d))}}sqr({c0:e,c1:t,c2:r}){let{Fp2:i}=this,o=i.sqr(e),s=i.mul(i.mul(e,t),jo),a=i.mul(i.mul(t,r),jo),c=i.sqr(r);return{c0:i.add(i.mulByNonresidue(a),o),c1:i.add(i.mulByNonresidue(c),s),c2:i.sub(i.sub(i.add(i.add(s,i.sqr(i.add(i.sub(e,t),r))),a),o),c)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}create(e){return e}isValid({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return i.isValid(e)&&i.isValid(t)&&i.isValid(r)}is0({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return i.is0(e)&&i.is0(t)&&i.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return{c0:i.neg(e),c1:i.neg(t),c2:i.neg(r)}}eql({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return a.eql(e,i)&&a.eql(t,o)&&a.eql(r,s)}sqrt(e){return ui()}div(e,t){let{Fp2:r}=this,{Fp:i}=r;return this.mul(e,typeof t=="bigint"?i.inv(i.create(t)):this.inv(t))}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}inv({c0:e,c1:t,c2:r}){let{Fp2:i}=this,o=i.sub(i.sqr(e),i.mulByNonresidue(i.mul(r,t))),s=i.sub(i.mulByNonresidue(i.sqr(r)),i.mul(e,t)),a=i.sub(i.sqr(t),i.mul(e,r)),c=i.inv(i.add(i.mulByNonresidue(i.add(i.mul(r,s),i.mul(t,a))),i.mul(e,o)));return{c0:i.mul(c,o),c1:i.mul(c,s),c2:i.mul(c,a)}}fromBytes(e){let{Fp2:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let r=t.BYTES;return{c0:t.fromBytes(e.subarray(0,r)),c1:t.fromBytes(e.subarray(r,r*2)),c2:t.fromBytes(e.subarray(2*r))}}toBytes({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return Fi(i.toBytes(e),i.toBytes(t),i.toBytes(r))}cmov({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s},a){let{Fp2:c}=this;return{c0:c.cmov(e,i,a),c1:c.cmov(t,o,a),c2:c.cmov(r,s,a)}}fromBigSix(e){let{Fp2:t}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:t.fromBigTuple(e.slice(0,2)),c1:t.fromBigTuple(e.slice(2,4)),c2:t.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.frobeniusMap(e,i),c1:o.mul(o.frobeniusMap(t,i),this.FROBENIUS_COEFFICIENTS_1[i%6]),c2:o.mul(o.frobeniusMap(r,i),this.FROBENIUS_COEFFICIENTS_2[i%6])}}mulByFp2({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.mul(e,i),c1:o.mul(t,i),c2:o.mul(r,i)}}mulByNonresidue({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return{c0:i.mulByNonresidue(r),c1:e,c2:t}}mul1({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.mulByNonresidue(o.mul(r,i)),c1:o.mul(e,i),c2:o.mul(t,i)}}mul01({c0:e,c1:t,c2:r},i,o){let{Fp2:s}=this,a=s.mul(e,i),c=s.mul(t,o);return{c0:s.add(s.mulByNonresidue(s.sub(s.mul(s.add(t,r),o),c)),a),c1:s.sub(s.sub(s.mul(s.add(i,o),s.add(e,t)),a),c),c2:s.add(s.sub(s.mul(s.add(e,r),i),a),c)}}},FO=class{constructor(e,t){this.MASK=Ad;let{Fp2:r}=e,{Fp:i}=r;this.Fp6=e,this.ORDER=r.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=XO(r,r.NONRESIDUE,i.ORDER,12,1,6)[0],this.X_LEN=t.X_LEN,this.finalExponentiate=t.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:t}){let{Fp6:r}=this;return r.isValid(e)&&r.isValid(t)}is0({c0:e,c1:t}){let{Fp6:r}=this;return r.is0(e)&&r.is0(t)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:t}){let{Fp6:r}=this;return{c0:r.neg(e),c1:r.neg(t)}}eql({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return o.eql(e,r)&&o.eql(t,i)}sqrt(e){ui()}inv({c0:e,c1:t}){let{Fp6:r}=this,i=r.inv(r.sub(r.sqr(e),r.mulByNonresidue(r.sqr(t))));return{c0:r.mul(e,i),c1:r.neg(r.mul(t,i))}}div(e,t){let{Fp6:r}=this,{Fp2:i}=r,{Fp:o}=i;return this.mul(e,typeof t=="bigint"?o.inv(o.create(t)):this.inv(t))}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}add({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return{c0:o.add(e,r),c1:o.add(t,i)}}sub({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return{c0:o.sub(e,r),c1:o.sub(t,i)}}mul({c0:e,c1:t},r){let{Fp6:i}=this;if(typeof r=="bigint")return{c0:i.mul(e,r),c1:i.mul(t,r)};let{c0:o,c1:s}=r,a=i.mul(e,o),c=i.mul(t,s);return{c0:i.add(a,i.mulByNonresidue(c)),c1:i.sub(i.mul(i.add(e,t),i.add(o,s)),i.add(a,c))}}sqr({c0:e,c1:t}){let{Fp6:r}=this,i=r.mul(e,t);return{c0:r.sub(r.sub(r.mul(r.add(r.mulByNonresidue(t),e),r.add(e,t)),i),r.mulByNonresidue(i)),c1:r.add(i,i)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}fromBytes(e){let{Fp6:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:t.fromBytes(e.subarray(0,t.BYTES)),c1:t.fromBytes(e.subarray(t.BYTES))}}toBytes({c0:e,c1:t}){let{Fp6:r}=this;return Fi(r.toBytes(e),r.toBytes(t))}cmov({c0:e,c1:t},{c0:r,c1:i},o){let{Fp6:s}=this;return{c0:s.cmov(e,r,o),c1:s.cmov(t,i,o)}}fromBigTwelve(e){let{Fp6:t}=this;return{c0:t.fromBigSix(e.slice(0,6)),c1:t.fromBigSix(e.slice(6,12))}}frobeniusMap(e,t){let{Fp6:r}=this,{Fp2:i}=r,{c0:o,c1:s,c2:a}=r.frobeniusMap(e.c1,t),c=this.FROBENIUS_COEFFICIENTS[t%12];return{c0:r.frobeniusMap(e.c0,t),c1:r.create({c0:i.mul(o,c),c1:i.mul(s,c),c2:i.mul(a,c)})}}mulByFp2({c0:e,c1:t},r){let{Fp6:i}=this;return{c0:i.mulByFp2(e,r),c1:i.mulByFp2(t,r)}}conjugate({c0:e,c1:t}){return{c0:e,c1:this.Fp6.neg(t)}}mul014({c0:e,c1:t},r,i,o){let{Fp6:s}=this,{Fp2:a}=s,c=s.mul01(e,r,i),u=s.mul1(t,o);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(s.sub(s.mul01(s.add(t,e),r,a.add(i,o)),c),u)}}mul034({c0:e,c1:t},r,i,o){let{Fp6:s}=this,{Fp2:a}=s,c=s.create({c0:a.mul(e.c0,r),c1:a.mul(e.c1,r),c2:a.mul(e.c2,r)}),u=s.mul01(t,i,o),l=s.mul01(s.add(e,t),a.add(r,i),o);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(l,s.add(c,u))}}_cyclotomicSquare({c0:e,c1:t}){let{Fp6:r}=this,{Fp2:i}=r,{c0:o,c1:s,c2:a}=e,{c0:c,c1:u,c2:l}=t,{first:d,second:h}=i.Fp4Square(o,u),{first:f,second:m}=i.Fp4Square(c,a),{first:w,second:b}=i.Fp4Square(s,l),S=i.mulByNonresidue(b);return{c0:r.create({c0:i.add(i.mul(i.sub(d,o),jo),d),c1:i.add(i.mul(i.sub(f,s),jo),f),c2:i.add(i.mul(i.sub(w,a),jo),w)}),c1:r.create({c0:i.add(i.mul(i.add(S,c),jo),S),c1:i.add(i.mul(i.add(h,u),jo),h),c2:i.add(i.mul(i.add(m,l),jo),m)})}}_cyclotomicExp(e,t){let r=this.ONE;for(let i=this.X_LEN-1;i>=0;i--)r=this._cyclotomicSquare(r),KLe(t,i)&&(r=this.mul(r,e));return r}};function IRe(n){let e=jy(n.ORDER),t=new MO(e,n),r=new OO(t),i=new FO(r,n);return{Fp:e,Fp2:t,Fp6:r,Fp12:i}}var ARe=BigInt(0),NO=BigInt(1),ite=BigInt(2),xRe=BigInt(3),ote=BigInt(6),d8=BigInt("4965661367192848881"),vRe=WE(d8),SRe=ote*d8**ite,f8={p:BigInt("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"),n:BigInt("0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"),h:NO,a:ARe,b:xRe,Gx:NO,Gy:BigInt(2)},vee=jy(f8.n),ste={c0:BigInt("19485874751759354771024239261021720505790618469301721065564631296452457478373"),c1:BigInt("266929791119991161246907387137283842545076965332900288569378510910307636690")},{Fp:XE,Fp2:Ju,Fp6:CRe,Fp12:zn}=IRe({ORDER:f8.p,X_LEN:vRe,FP2_NONRESIDUE:[BigInt(9),NO],Fp2mulByB:n=>Ju.mul(n,ste),Fp12finalExponentiate:n=>{let e=l=>zn.conjugate(zn._cyclotomicExp(l,d8)),t=zn.mul(zn.conjugate(n),zn.inv(n)),r=zn.mul(zn.frobeniusMap(t,2),t),i=zn._cyclotomicSquare(e(r)),o=zn.mul(zn._cyclotomicSquare(i),i),s=e(o),a=e(zn._cyclotomicSquare(s)),c=zn.mul(zn.mul(zn.conjugate(a),s),zn.conjugate(o)),u=zn.mul(c,i);return zn.mul(zn.frobeniusMap(zn.mul(zn.conjugate(r),u),3),zn.mul(zn.frobeniusMap(c,2),zn.mul(zn.frobeniusMap(u,1),zn.mul(zn.mul(c,s),r))))}}),{G2psi:LRe,psi:See}=ERe(XE,Ju,Ju.NONRESIDUE),xO=Object.freeze({DST:"BN254G2_XMD:SHA-256_SVDW_RO_",encodeDST:"BN254G2_XMD:SHA-256_SVDW_RO_",p:XE.ORDER,m:2,k:128,expand:"xmd",hash:Mee}),RRe=(n,e,t,r,i,o)=>{let s=See(r,i);({Rx:n,Ry:e,Rz:t}=o(n,e,t,s[0],s[1]));let a=See(s[0],s[1]);o(n,e,t,a[0],Ju.neg(a[1]))},DRe={p:Ju.ORDER,n:f8.n,h:BigInt("0x30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d"),a:Ju.ZERO,b:ste,Gx:Ju.fromBigTuple([BigInt("10857046999023057135944570762232829481370756359578518086990519993285655852781"),BigInt("11559732032986387107991004021392285783925812861821192530917403151452391805634")]),Gy:Ju.fromBigTuple([BigInt("8495653923123431417604973247489272438418190587263600148770280649306958101930"),BigInt("4082367875863433681332203403145435568316851327593401208105741076214120093531")])},V0=bRe({fields:{Fp:XE,Fp2:Ju,Fp6:CRe,Fp12:zn,Fr:vee},G1:{...f8,Fp:XE,htfDefaults:{...xO,m:1,DST:"BN254G2_XMD:SHA-256_SVDW_RO_"},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:ui,fromBytes:ui,toBytes:ui,ShortSignature:{fromBytes:ui,fromHex:ui,toBytes:ui,toRawBytes:ui,toHex:ui}},G2:{...DRe,Fp:Ju,hEff:BigInt("21888242871839275222246405745257275088844257914179612981679871602714643921549"),htfDefaults:{...xO},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(n,e)=>e.multiplyUnsafe(SRe).equals(LRe(n,e)),mapToCurve:ui,fromBytes:ui,toBytes:ui,Signature:{fromBytes:ui,fromHex:ui,toBytes:ui,toRawBytes:ui,toHex:ui}},params:{ateLoopSize:d8*ote+ite,r:vee.ORDER,xNegative:!1,twistType:"divisive"},htfDefaults:xO,postPrecompute:RRe});mRe({a:BigInt(0),b:BigInt(3),Fp:XE,n:BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"),Gx:BigInt(1),Gy:BigInt(2),h:BigInt(1),hash:Mee});var h8="groth16",TRe="auth",BRe="authV2",PRe="authV3",kRe="authV3-8-32",MRe=new TextDecoder,Cee=BigInt(0),Lee=V0.fields.Fp2,Ree=V0.fields.Fp12;async function _O(n,e,t){let r=await DLe(t),i=new TextDecoder().decode(n),o=JSON.parse(i),s=await r.calculateWTNSBin(o,0),{proof:a,publicSignals:c}=await YC.prove(e,s);return{proof:a,pub_signals:c}}var[UO,ORe]=[V0.G1.ProjectivePoint,V0.G2.ProjectivePoint],XC=([n,e])=>UO.fromAffine({x:BigInt(n),y:BigInt(e)}),_C=([[n,e],[t,r]])=>ORe.fromAffine({x:Lee.fromBigTuple([BigInt(n),BigInt(e)]),y:Lee.fromBigTuple([BigInt(t),BigInt(r)])});async function $O(n,e,t,r){if(r(e.pub_signals).challenge!==qI(n))throw new Error("challenge is not equal to message hash");let o=JSON.parse(MRe.decode(t));return eF(e,o)}function eF(n,e){if(!e.IC)throw new Error("verification file doesn't exist for circuit");let{proof:t,pub_signals:r}=n;if(r.length+1!==e.IC.length)throw new Error(`Invalid number of public signals, expected ${e.IC.length-1} but got ${r.length}`);let i=UO.ZERO;for(let s=0;s<r.length;s++){if(BigInt(r[s])<Cee||BigInt(r[s])>=V0.G1.CURVE.n)throw new Error(`Input value is not in the field ${V0.G1.CURVE.n}`);if(BigInt(r[s])!==Cee){let[a,c]=e.IC[s+1].map(BigInt);i=i.add(UO.fromAffine({x:a,y:c}).multiply(BigInt(r[s])))}}i=i.add(XC(e.IC[0]));let o=V0.pairingBatch([{g1:XC(t.pi_a).negate(),g2:_C(t.pi_b)},{g1:i,g2:_C(e.vk_gamma_2)},{g1:XC(t.pi_c),g2:_C(e.vk_delta_2)},{g1:XC(e.vk_alpha_1),g2:_C(e.vk_beta_2)}]);return Ree.eql(o,Ree.ONE)}var GO=class{methodAlg;constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}unmarshall(e){let t={};if(e.length!=3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return t.challenge=BigInt(e[0]),t.userState=BigInt(e[1]),t.userId=Xe.fromBigInt(BigInt(e[2])),t}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}prove(e,t,r){return _O(e,t,r)}},HO=new GO(new Uc(h8,TRe)),KO=class n{methodAlg;static curveName="bn128";constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}async prove(e,t,r){let i=await _O(e,t,r);return await this.terminateCurve(),i}async terminateCurve(){(await VE(n.curveName)).terminate()}unmarshall(e){if(e.length!==3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return{userID:Xe.fromBigInt(BigInt(e[0])),challenge:BigInt(e[1]),GISTRoot:be.fromString(e[2])}}},JO=new KO(new Uc(h8,BRe)),c8=class n{methodAlg;static curveName="bn128";constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}async prove(e,t,r){let i=await _O(e,t,r);return await this.terminateCurve(),i}async terminateCurve(){(await VE(n.curveName)).terminate()}unmarshall(e){if(e.length!==3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return{userID:Xe.fromBigInt(BigInt(e[0])),challenge:BigInt(e[1]),GISTRoot:be.fromString(e[2])}}},qO=new c8(new Uc(h8,PRe)),VO=new c8(new Uc(h8,kRe));_E(HO.methodAlg,()=>HO);_E(JO.methodAlg,()=>JO);_E(qO.methodAlg,()=>qO);_E(VO.methodAlg,()=>VO);var Q0={registerProvingMethod:_E,getProvingMethod:Bee,provingMethodGroth16AuthInstance:HO,provingMethodGroth16AuthV2Instance:JO,provingMethodGroth16AuthV3Instance:qO,provingMethodGroth16AuthV3_8_32Instance:VO};var ate="unknown circuit ID. can't verify msg sender",p8="sender of message is not used for jwz token creation",cte="message was packed with unsupported circuit",ute="message proof is invalid",lte="message state verification failed",dte="unknown proving method algorithm";var{getProvingMethod:FRe}=Q0,iI=class{constructor(e){this.dataPrepareFunc=e}prepare(e,t,r){return this.dataPrepareFunc(e,t,r)}},oI=class{constructor(e){this.stateVerificationFunc=e}verify(e,t,r){return this.stateVerificationFunc(e,t,r)}},sI=class{constructor(e,t,r={acceptedStateTransitionDelay:pM}){this.provingParamsMap=e;this.verificationParamsMap=t;this._opts=r;let i=Array.from(this.provingParamsMap.keys()).map(s=>s.split(":")[1]),o=Array.from(this.verificationParamsMap.keys()).map(s=>s.split(":")[1]);this.supportedCircuitIds=[...new Set([...i,...o])]}supportedProtocolVersions=["iden3comm/v1"];supportedAlgorithms=["groth16"];supportedCircuitIds;packMessage(e,t){return this.pack(ke.encode(JSON.stringify(e)),t)}async pack(e,t){let r=await FRe(t.provingMethodAlg),i=this.provingParamsMap.get(t.provingMethodAlg.toString());if(!i)throw new Error(dte);let o=new wh(r,lt.decode(e),(a,c)=>i?.dataPreparer?.prepare(a,t.senderDID,c));o.setHeader(Ha.Type,"application/iden3-zkp-json");let s=await o.prove(i.provingKey,i.wasm);return ke.encode(s)}async unpackMessage(e,t){let r=this.verificationParamsMap.get(t.toString());if(!r?.key)throw new Error(cte);if(!await e.verify(r?.key))throw new Error(ute);if(!await r?.verificationFn?.verify(e.circuitId,e.zkProof.pub_signals,this._opts))throw new Error(lte);let s=JSON.parse(e.getPayload());return await NRe(e,s),s}parseToken(e){return wh.parse(lt.decode(e))}async unpack(e){let t=await this.parseToken(e),r=new Uc(t.alg,t.circuitId);return this.unpackMessage(t,r)}mediaType(){return"application/iden3-zkp-json"}getSupportedProfiles(){return this.supportedProtocolVersions.map(e=>`${e};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(",")};circuitIds=${this.supportedCircuitIds.join(",")}`)}isProfileSupported(e){let{protocolVersion:t,env:r,circuits:i,alg:o}=xs(e);if(!this.supportedProtocolVersions.includes(t)||r!==this.mediaType())return!1;let s=this.supportedCircuitIds,a=!i?.length||i.some(l=>s.includes(l)),c=this.supportedAlgorithms;return(!o?.length||o.some(l=>c.includes(l)))&&a}},NRe=async(n,e)=>{switch(n.circuitId){case"authV2":case"authV3-8-32":case"authV3":{if(!e.from)throw new Error(p8);let t=(n.circuitId==="authV2"?new Zs:new Gu).pubSignalsUnmarshal(ke.encode(JSON.stringify(n.zkProof.pub_signals))),r=ve.parseFromId(t.userID),i=await n.getMessageHash();if(It.bytesToInt(i.reverse())!==t.challenge)throw new Error(p8);if(e.from!==r.string())throw new Error(p8)}break;default:throw new Error(ate)}};var tF=class extends sI{constructor(t,r,i){super(new Map,new Map,{...i});this.circuitStorage=t;this.proofService=r;this.supportedCircuitIds=["authV2","authV3","authV3-8-32"]}async pack(t,r){let i=r.provingMethodAlg,o=i.circuitId,s=i.toString();if(!this.provingParamsMap.has(s)){let{provingKey:a,wasm:c}=await this.circuitStorage.loadCircuitData(o,{mode:"proving"});if(!a||!c)throw new Error(`circuit data not found for circuit id: ${o}`);this.provingParamsMap.set(s,{provingKey:a,wasm:c,dataPreparer:new iI(this.proofService.generateAuthInputs.bind(this.proofService))})}return super.pack(t,r)}async unpack(t){let r=await this.parseToken(t),i=r.circuitId,o=new Uc(r.alg,i);if(!this.verificationParamsMap.has(o.toString())){let{verificationKey:s}=await this.circuitStorage.loadCircuitData(i,{mode:"verification"});if(!s)throw new Error(`verification key not found for circuit id: ${i}`);this.verificationParamsMap.set(o.toString(),{key:s,verificationFn:new oI(this.proofService.verifyState.bind(this.proofService))})}return super.unpackMessage(r,o)}};var fte=(r=>(r.Pending="pending",r.Completed="completed",r.Rejected="rejected",r))(fte||{});var nF=(i=>(i.AUTHV2="authV2",i.AUTHV3="authV3",i.AUTHV3_8_32="authV3-8-32",i.ETH_IDENTITY="ethIdentity",i))(nF||{});var hte=(e=>(e.FeatureType="feature-type",e))(hte||{}),pte=(i=>(i.Accept="accept",i.Protocol="protocol",i.GoalCode="goal-code",i.Header="header",i))(pte||{});var Kc=Q0.provingMethodGroth16AuthV2Instance.methodAlg,Ni=class{nextMessageHandler;setNext(e){return this.nextMessageHandler=e,e}async handle(e,t){return t.allowExpiredMessages||Lr(e),this.nextMessageHandler?this.nextMessageHandler.handle(e,t):Promise.reject("Message handler not provided or message not supported")}},rF=class{constructor(e){this._params=e;this.registerHandlers(e.messageHandlers)}messageHandler;registerHandlers(e){if(!e.length)return;let[t,...r]=e,i=t;for(let o of r){let s=i;for(;s.nextMessageHandler;)s=s.nextMessageHandler;s.setNext(o)}this.messageHandler?this.messageHandler.setNext(t):this.messageHandler=t}async handleMessage(e,t){let{unpackedMediaType:r,unpackedMessage:i}=await this._params.packageManager.unpack(e);if(!this.messageHandler)return Promise.reject(new Error("Message handler not provided"));r==="application/iden3-zkp-json"&&(t.messageProvingMethodAlg=await Hc(e));let o=await this.messageHandler.handle(i,t);if(!o)return null;let s={},a=t?.senderDid;return r==="application/iden3-zkp-json"&&a?(s={senderDID:a,provingMethodAlg:await Hc(e)},this._params.packageManager.packMessage(r,o,s)):this._params.packageManager.packMessage("application/iden3comm-plain-json",o,s)}};async function Hc(n){try{let e=lt.decode(n);return(await wh.parse(e)).method.methodAlg}catch{return Kc}}var URe=n=>n.reduce((e,t)=>{let r=t.query;if(!r)return e;let i=r.groupId;if(!i)return e;let o=e.get(i);if(!o){let a=Qc(12),u=new DataView(a.buffer).getUint32(0);return e.set(i,{query:r,linkNonce:u}),e}let s=C4(o.query.credentialSubject,r.credentialSubject);return e.set(i,{...o,query:{skipClaimRevocationCheck:o.query.skipClaimRevocationCheck||r.skipClaimRevocationCheck,...o.query,credentialSubject:s}}),e},new Map),Wy=async(n,e,t,r,i)=>{let o=e??[],s=URe(o),a=new Map,c=[];for(let u of o){let l;try{if(!i.supportedCircuits.includes(u.circuitId)){if(u.optional){console.log(`Circuit ${u.circuitId} is not supported, skipping optional proof request`);continue}throw new Error(`Circuit ${u.circuitId} is not allowed`)}let h=u.query,f=h?.groupId,m=s.get(f);if(f){if(!m)throw new Error(`Invalid group id ${h?.groupId}`);let b=m.query;if(!a.has(f)){let S=await r.findCredentialByProofQuery(n,m.query);if(!S.cred){if(u.optional){console.log("No credential found for optional proof request, skipping");continue}throw new Error(Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY+`${JSON.stringify(b)}`)}a.set(f,S)}}let w=a.get(f);l=await r.generateProof(u,n,{verifierDid:t,challenge:i.challenge,skipRevocation:!!h?.skipClaimRevocationCheck,credential:w?.cred,credentialRevocationStatus:w?.revStatus,linkNonce:m?.linkNonce?BigInt(m.linkNonce):void 0,bypassCache:i.bypassProofsCache,allowExpiredCredentials:i.allowExpiredCredentials})}catch(d){let h=[Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE,Ge.ERRORS.ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY,Ge.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED,Ge.ERRORS.PROOF_SERVICE_CREDENTIAL_IS_EXPIRED];if(d instanceof Error&&(h.includes(d.message)||d.message.includes(Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY))&&u.optional){console.log(`Error in optional proof request: ${d.message}, skipping`);continue}throw d}c.push(l)}return c},iF=async(n,e,t)=>{switch(t.acceptProfile||(t.acceptProfile=TE),t.acceptProfile.env){case"application/iden3-zkp-json":if(!t.acceptProfile.circuits)throw new Error("Circuit not specified in accept profile");for(let r of t.acceptProfile.circuits){if(!t.supportedCircuits.includes(r))throw new Error(`Circuit ${r} is not supported`);if(!t.senderAddress)throw new Error("Sender address is not provided");let i=mte(t.senderAddress,t.zkpResponses),o=await e.generateAuthProof(r,n,{challenge:i});return{authProof:{authMethod:r,zkp:o}}}throw new Error("Auth method is not supported");case"application/iden3comm-signed-json":if(!t.acceptProfile.alg||t.acceptProfile.alg.length===0)throw new Error("Algorithm not specified");if(t.acceptProfile.alg[0]==="ES256K-R")return{authProof:{authMethod:"ethIdentity",userDid:n}};throw new Error(`Algorithm ${t.acceptProfile.alg[0]} not supported`);default:throw new Error("Accept env not supported")}},aI=n=>{let e=n.id,t=n.pub_signals,r="0x";if(t.length===0)return{requestId:e,zkProofEncoded:r,metadata:r};let i=M0(n.proof),o=wC(t,i.a,i.b,i.c),s=mn.AbiCoder.defaultAbiCoder().encode(["string"],[n.circuitId]);return{requestId:e,zkProofEncoded:o,metadata:s}},mte=(n,e)=>{let t=e.map(r=>{let i=aI(r);return{requestId:i.requestId,proof:i.zkProofEncoded,metadata:i.metadata}});return BigInt(mn.keccak256(new mn.AbiCoder().encode(["address","(uint256 requestId,bytes proof,bytes metadata)[]"],[n,t])))&BigInt("0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},GRe=n=>new mn.AbiCoder().encode(["tuple(string key,bytes value)[]"],[n]),Lr=n=>{if(n?.expires_time&&n.expires_time<Lt(new Date))throw new Error("Message expired")},ta=(n,e,t)=>{if(n==="application/iden3comm-signed-json"||n==="application/iden3comm-encrypted-json"){if(!e)throw new Error(`packer options are required for ${n}`);return e}if(n==="application/iden3comm-plain-json")return{};if(n==="application/iden3-zkp-json"){let r={provingMethodAlg:e?.provingMethodAlg||t?.provingMethodAlg||Kc,senderDID:e?.senderDID||t?.senderDID};if(!r.senderDID)throw new Error("senderDID is required for ZKPMessage");return r}throw new Error(`unsupported media type ${n}`)};function HRe(n,e,t,r){return gte(n,"",e,t,r)}function gte(n,e,t,r,i){let o=Ut();return{id:o,thid:o,from:t,typ:"application/iden3comm-plain-json",type:at.AUTHORIZATION_REQUEST_MESSAGE_TYPE,body:{accept:i?.accept,reason:n,message:e,callbackUrl:r,scope:i?.scope??[]},created_time:Lt(new Date),expires_time:i?.expires_time?Lt(i.expires_time):void 0,attachments:i?.attachments}}var oF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._proofService=r}_supportedCircuits=Object.values(Nc);handle(t,r){switch(t.type){case at.AUTHORIZATION_REQUEST_MESSAGE_TYPE:return this.handleAuthRequest(t,r);case at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE:return this.handleAuthResponse(t,r);default:return super.handle(t,r)}}async parseAuthorizationRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.AUTHORIZATION_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i.body.scope=i.body.scope||[],i}async handleAuthRequest(t,r){if(t.type!==at.AUTHORIZATION_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for authorization request");let i=t.to?ve.parse(t.to):r.senderDid,o=Ut();if(!t.from)throw new Error("auth request should contain from field");let s=at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,a=this.getSupportedMediaTypeByProfile(r,t.body.accept),c=ve.parse(t.from),u=await Wy(i,t?.body.scope,c,this._proofService,{mediaType:a,supportedCircuits:this._supportedCircuits,bypassProofsCache:r.bypassProofsCache,allowExpiredCredentials:r.allowExpiredCredentials});return{id:o,typ:a,type:s,thid:t.thid??o,body:{message:t?.body?.message,scope:u},created_time:Lt(new Date),from:i.string(),to:t.from}}async handleAuthorizationRequest(t,r,i){let o=await this.parseAuthorizationRequest(r);i?.allowExpiredMessages||Lr(o),i||(i={mediaType:"application/iden3-zkp-json"});let s=await this.handleAuthRequest(o,{senderDid:t,mediaType:i.mediaType,bypassProofsCache:i.bypassProofsCache,allowExpiredCredentials:i.allowExpiredCredentials}),a=ke.encode(JSON.stringify(s)),c=ta(i.mediaType,i.packerOptions,{provingMethodAlg:this.getDefaultProvingMethodAlg(i.preferredAuthProvingMethod,o.body.accept),senderDID:t}),u=lt.decode(await this._packerMgr.pack(i.mediaType,a,c));return{authRequest:o,authResponse:s,token:u}}async handleAuthResponse(t,r){let i=r.request;if(t.type!==at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE)throw new Error("Invalid message type for authorization response");if((i.body.message??"")!==(t.body.message??""))throw new Error("message for signing from request is not presented in response");if(i.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${i.from}, given ${t.to}`);this.verifyAuthRequest(i);let o=i.body.scope||[],s=t.body.scope||[];if(!t.from)throw new Error("proof response doesn't contain from field");let a=new Map;for(let c of o){let u=c.query?.groupId,l=s.find(w=>w.id.toString()===c.id.toString());if(!l){if(c.optional)continue;throw new Error(`proof is not given for requestId ${c.id}`)}let d=oM(c.circuitId);if(!d.includes(l.circuitId))throw new Error(`proof is not given for requested circuit expected: ${d.join(", ")}, given ${l.circuitId} `);let h=c.params??{};h.verifierDid=ve.parse(i.from);let f=[r.acceptedProofGenerationDelay,r.acceptedStateTransitionDelay].some(w=>w!==void 0)?{acceptedProofGenerationDelay:r.acceptedProofGenerationDelay,acceptedStateTransitionDelay:r.acceptedStateTransitionDelay}:void 0,{linkID:m}=await this._proofService.verifyZKPResponse(l,{query:c.query,sender:t.from,params:h,opts:f});m&&u&&a.set(u,[...a.get(u)??[],{linkID:m.toString(),requestId:l.id}])}for(let[c,u]of a.entries())if(u.some(l=>l.linkID!==u[0].linkID))throw new Error(`Link id validation failed for group ${c}, request linkID to requestIds info: ${JSON.stringify(u)}`);return t}async handleAuthorizationResponse(t,r,i){i?.allowExpiredMessages||Lr(t);let o=await this.handleAuthResponse(t,{request:r,acceptedStateTransitionDelay:i?.acceptedStateTransitionDelay,acceptedProofGenerationDelay:i?.acceptedProofGenerationDelay});return{request:r,response:o}}verifyAuthRequest(t){let r={},i=t.body.scope||[];for(let o of i){let s=o.query;if(!s)continue;let a=s.groupId;if(a){let c=r[a]??[];for(let u of c){let l=u.query;if(!l)continue;if(l.type!==s?.type)throw new Error("all requests in the group should have the same type");if(l.context!==s?.context)throw new Error("all requests in the group should have the same context");let d=s?.allowedIssuers,h=l.allowedIssuers;if(!(d.includes("*")||d.every(f=>h.includes(f))))throw new Error("all requests in the group should have the same issuer")}r[a]=[...r[a]??[],o]}}}getSupportedMediaTypeByProfile(t,r){let i;if(!r?.length)return t.mediaType||"application/iden3-zkp-json";let o=[];for(let s of r){let{env:a}=xs(s);this._packerMgr.isProfileSupported(a,s)&&o.push(a)}if(!o.length)throw new Error("no packer with profile which meets `accept` header requirements");return i=o.includes("application/iden3-zkp-json")?"application/iden3-zkp-json":o[0],t.mediaType&&o.includes(t.mediaType)&&(i=t.mediaType),i}getDefaultProvingMethodAlg(t,r){if(!r?.length)return Kc;let i=[Q0.provingMethodGroth16AuthV3_8_32Instance.methodAlg,Q0.provingMethodGroth16AuthV3Instance.methodAlg];if(t){let o=i.indexOf(t);o!==-1&&i.splice(o,1),i.unshift(t)}for(let o of i)if(this._packerMgr.isProfileSupported("application/iden3-zkp-json",bM(o))&&EM(r,o))return o;return Kc}};var yte=[{inputs:[],name:"MAX_SMT_DEPTH",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"key",type:"uint256"}],name:"getNode",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatus",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatusByIdAndState",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256[][]",name:"nodes",type:"uint256[][]"}],name:"saveNodes",outputs:[],stateMutability:"nonpayable",type:"function"}];var cI=class n{constructor(e,t,r){this._config=e;this._signer=r;this._provider=new jt(e.url);let i=new Ln(t,yte,this._provider);this._signer&&(this._signer=this._signer.connect(this._provider),i=i.connect(this._signer)),this._contract=i,this._transactionService=new Xs(this._provider)}_contract;_provider;_transactionService;async getRevocationStatusByIdAndState(e,t,r){let i=await this._contract.getRevocationStatusByIdAndState(e,t,r),o=n.convertIssuerInfo(i.issuer),s=n.convertSmtProofToProof(i.mtp);return{issuer:o,mtp:s}}async getRevocationStatus(e,t){let r=await this._contract.getRevocationStatus(e,t),i=n.convertIssuerInfo(r.issuer),o=n.convertSmtProofToProof(r.mtp);return{issuer:i,mtp:o}}async saveNodes(e){if(!this._signer)throw new Error("No signer provided");let t=await this._provider.getFeeData(),r=this._config.maxFeePerGas?BigInt(this._config.maxFeePerGas):t.maxFeePerGas,i=this._config.maxPriorityFeePerGas?BigInt(this._config.maxPriorityFeePerGas):t.maxPriorityFeePerGas,o=await this._contract.saveNodes.estimateGas(e),s=await this._contract.saveNodes.populateTransaction(e),a={to:s.to,data:s.data,gasLimit:o,maxFeePerGas:r,maxPriorityFeePerGas:i},{txnReceipt:c}=await this._transactionService.sendTransactionRequest(this._signer,a);return c}static convertIssuerInfo(e){let[t,r,i,o]=e.map(s=>be.fromBigInt(s).hex());return{state:t,claimsTreeRoot:r,revocationTreeRoot:i,rootOfRoots:o}}static convertSmtProofToProof(e){let t,r=e.siblings?.map(i=>i.toString());return e.auxExistence&&(t={key:e.auxIndex.toString(),value:e.auxValue.toString()}),kt.fromJSON({existence:e.existence,node_aux:t,siblings:r})}};function JRe(n){return typeof n=="object"&&n!==null&&"errorArgs"in n&&Array.isArray(n.errorArgs)}function qRe(n){return(JRe(n)?n.errorArgs[0]:void 0)||(n instanceof Error?n.message:"")}function Zy(n,e){return qRe(n).includes(e)}function z0(n){return Zy(n,Ge.ERRORS.IDENTITY_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR)}function sF(n){return Zy(n,Ge.ERRORS.STATE_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.STATE_DOES_NOT_EXIST_CUSTOM_ERROR)}function aF(n){return Zy(n,Ge.ERRORS.ROOT_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.ROOT_DOES_NOT_EXIST_CUSTOM_ERROR)}var cF=class{constructor(e,t){this._configs=e;this._stateStorage=new uI(e,t?.stateStorageOptions)}_stateStorage;async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");return this.getRevocationOnChain(e,t.issuerDID)}async getRevocationOnChain(e,t){let{contractAddress:r,chainId:i,revocationNonce:o,stateHex:s}=this.extractCredentialStatusInfo(e);if(o!==e.revocationNonce)throw new Error("revocationNonce does not match");let a=ve.idFromDID(t),c;try{let h=await this._stateStorage.getLatestStateById(a.bigInt());if(!h.state)throw new Error("state contract returned empty state");c=h.state}catch(h){if(!z0(h))throw h;if(!s)throw new Error("latest state not found and state parameter is not present in credentialStatus.id");let f=be.fromHex(s).bigInt();if(!pf(t,f))throw new Error(`latest state not found and state parameter ${s} is not genesis state`);c=f}let u=ve.idFromDID(t);return await this._getOnChainRevocationStorageForIssuer(i,r).getRevocationStatusByIdAndState(u.bigInt(),c,o)}extractCredentialStatusInfo(e){if(!e.id)throw new Error("credentialStatus id is empty");if(e.id.split("/").length!==2)throw new Error("invalid credentialStatus id");let r=new URL(e.id),i=r.searchParams.get("state")||"",o=r.searchParams.get("contractAddress");if(!o)throw new Error("contractAddress not found in credentialStatus.id field");let s=o.split(":");if(s.length!=2)throw new Error("invalid contract address encoding. should be chainId:contractAddress");let a=parseInt(s[0],10),c=s[1],u=r.searchParams.get("revocationNonce")||e.revocationNonce;if(u==null)throw new Error("revocationNonce not found in credentialStatus id field");let l=typeof u=="number"?u:parseInt(u,10);return{contractAddress:c,chainId:a,revocationNonce:l,stateHex:i}}networkByChainId(e){let t=this._configs.find(r=>r.chainId===e);if(!t)throw new Error(`chainId "${e}" not supported`);return t}_getOnChainRevocationStorageForIssuer(e,t){let r=this.networkByChainId(e);return new cI(r,t)}};var Y0=class{async resolve(e){let r=await(await fetch(e.id)).json();return m8(r)}},m8=({issuer:n,mtp:e})=>({mtp:kt.fromJSON(e),issuer:n});var j0=class n{constructor(e=Ne,t=[]){this.hash=e;this.children=t}nodeType(){return this.children.length===2?1:this.children.length===3&&this.children[2].hex()===be.fromBigInt(BigInt(1)).hex()?2:this.children.length===3?3:0}toJSON(){return{hash:this.hash.hex(),children:this.children.map(e=>e.hex())}}static fromHex(e){return new n(be.fromHex(e.hash),e.children.map(t=>be.fromHex(t)))}};var uF=class{constructor(e){this._state=e}async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");try{return await this.getStatus(e,t.issuerDID,t.issuerData,t.issuerGenesisState)}catch(r){if(e?.statusIssuer?.type==="SparseMerkleTreeProof")try{return await new Y0().resolve(e.statusIssuer)}catch(i){throw new Error(`can't fetch revocation status from backup endpoint: ${i?.message}`)}throw new Error(`can't fetch revocation status: ${r?.message}`)}}async getStatus(e,t,r,i){let o=ve.idFromDID(t),s;try{let l=await this._state.getLatestStateById(o.bigInt());if(!l.state)throw new Error("state contract returned empty state");s=l.state}catch(l){if(!z0(l))throw l;let d=this.extractState(e.id);if(!d)return this.getRevocationStatusFromIssuerData(t,r,i);let h=be.fromHex(d).bigInt(),f=gp(t);if(!f&&!pf(t,h))throw new Error(`latest state not found and state parameter ${d} is not genesis state`);if(f)throw new Error("State must be published for Ethereum based identity");s=h}let a=e.id.split("/node")[0],c=be.fromBigInt(BigInt(e.revocationNonce??0)),u=be.fromBigInt(s);return await this.getRevocationStatusFromRHS(c,u,a)}getRevocationStatusFromIssuerData(e,t,r){if(r&&pf(e,r.value.bigInt()))return{mtp:new kt,issuer:{state:r.value.hex(),revocationTreeRoot:r.revocationTreeRoot.hex(),rootOfRoots:r.rootOfRoots.hex(),claimsTreeRoot:r.claimsTreeRoot.hex()}};if(t&&pf(e,t.state.value))return{mtp:new kt,issuer:{state:t.state.value,revocationTreeRoot:t.state.revocationTreeRoot,rootOfRoots:t.state.rootOfRoots,claimsTreeRoot:t.state.claimsTreeRoot}};throw new Error("issuer data / genesis state param is empty")}async getRevocationStatusFromRHS(e,t,r){if(!r)throw new Error("HTTP reverse hash service URL is not specified");let o=(await(await fetch(`${r}/node/${t.hex()}`)).json())?.node;if(o.children.length!==3)throw new Error("state should has tree children");let s=t.hex(),[a,c,u]=o.children,l=be.fromHex(c);return{mtp:await this.rhsGenerateProof(l,e,`${r}/node`),issuer:{state:s,claimsTreeRoot:a,revocationTreeRoot:c,rootOfRoots:u}}}async rhsGenerateProof(e,t,r){let i=!1,o=[],s,a=()=>new kt({siblings:o,existence:i,nodeAux:s}),c=e;for(let u=0;u<t.bytes.length*8;u++){if(c.bytes.every(f=>f===0))return a();let d=(await(await fetch(`${r}/${c.hex()}`)).json())?.node,h=j0.fromHex(d);switch(h.nodeType()){case 2:return t.bytes.every((f,m)=>f===h.children[0].bytes[m])?(i=!0,a()):(s={key:h.children[0],value:h.children[1]},a());case 1:Ew(t.bytes,u)?(c=h.children[1],o.push(h.children[0])):(c=h.children[0],o.push(h.children[1]));break;default:throw new Error(`found unexpected node type in tree ${h.hash.hex()}`)}}throw new Error("tree depth is too high")}extractState(e){return new URL(e).searchParams.get("state")}};function VRe(n,e){let t=ve.parse(n),r=ve.idFromDID(t),{method:i,blockchain:o,networkId:s}=ve.decodePartsFromId(r),a=It.hexToBytes(e),c=It.bytesToInt(a),u=jc(i,o,s);return wte(ve.idFromDID(t).bigInt(),c,u)}function wte(n,e,t){let r=Xe.idGenesisFromIdenState(t,e);return n.toString()===r.bigInt().toString()}var lI=class{resolvers=new Map;register(e,t){this.resolvers.set(e,t)}get(e){return this.resolvers.get(e)}};var dI=class{async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");if(!t?.userDID)throw new Error("UserDID is not set in options");if(typeof e.revocationNonce!="number")throw new Error("Revocation nonce is not set in credential status");let r=t.userDID.string(),i=t.issuerDID.string(),o=QRe(r,i,e.revocationNonce),a=await(await fetch(e.id,{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})).json();return m8(a.body)}};function QRe(n,e,t){return{id:Ut(),typ:"application/iden3comm-plain-json",type:at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE,body:{revocation_nonce:t},thid:Ut(),from:n,to:e}}var fI=class{_publishers=new Map;register(e,...t){let r=this._publishers.get(e)??[];r.push(...t),this._publishers.set(e,r)}get(e){return this._publishers.get(e)}},lF=class{constructor(e){this._storage=e}async publish(e){if(!["Iden3OnchainSparseMerkleTreeProof2023"].includes(e.credentialStatusType))throw new Error(`On-chain publishing is not supported for credential status type ${e.credentialStatusType}`);let t=e.nodes.map(o=>o.children.map(s=>s.bigInt())),r=this._storage.saveNodes(t),i=e.onChain?.publishMode??"sync";switch(e.onChain?.txCallback&&(i="callback"),i){case"sync":await r;break;case"callback":{if(!e.onChain?.txCallback)throw new Error('txCallback is required for publishMode "callback"');let o=e.onChain?.txCallback;r.then(s=>o(s));break}case"async":{let o=hb.getInstance();r.then(s=>o.publish(OR.TX_RECEIPT_ACCEPTED,s));break}default:throw new Error(`Invalid publishMode: ${i}`)}}},W0=class{async publish(e){if(!["Iden3ReverseSparseMerkleTreeProof"].includes(e.credentialStatusType))throw new Error(`On-chain publishing is not supported for credential status type ${e.credentialStatusType}`);let t=e.nodes.map(i=>i.toJSON()),r=await fetch(e.rhsUrl+"/node",{method:"post",body:JSON.stringify(t)});if(r.status!==200)throw new Error(`Failed to publish credential status. Status: ${r.status}`)}};var dF=class{constructor(e){this.didResolverUrl=e}async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");let r=`${this.didResolverUrl}/1.0/credential-status/${encodeURIComponent(t.issuerDID.string())}`;return await(await fetch(r,{method:"POST",body:JSON.stringify(e)})).json()}};var fF=class{constructor(e,t){this._storage=e;this._credentialStatusResolverRegistry=t;this._credentialStatusResolverRegistry||(this._credentialStatusResolverRegistry=new lI,this._credentialStatusResolverRegistry.register("SparseMerkleTreeProof",new Y0),this._credentialStatusResolverRegistry.register("Iden3commRevocationStatusV1.0",new dI))}getCredentialStatusResolverRegistry(){return this._credentialStatusResolverRegistry}async getAuthBJJCredential(e){let t=await this._storage.credential.findCredentialsByQuery({context:Ge.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,type:Ge.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,allowedIssuers:[e.string()]});if(!t.length)throw new Error(Ge.ERRORS.NO_AUTH_CRED_FOUND);for(let r=0;r<t.length;r++){let i=t[r];if(!(await this.getRevocationStatusFromCredential(i)).mtp.existence)return i}throw new Error("all auth bjj credentials are revoked")}async getAllAuthBJJCredentials(e){return this._storage.credential.findCredentialsByQuery({context:Ge.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,type:Ge.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,allowedIssuers:[e.string()]})}async getRevocationStatusFromCredential(e){let t=e.getIden3SparseMerkleTreeProof(),r=e.getBJJSignature2021Proof(),i=t?t.issuerData.state:r?.issuerData.state,o=ve.parse(e.issuer),s=Xl(o,e),a={issuerGenesisState:i,issuerDID:o,userDID:s};return this.getRevocationStatus(e.credentialStatus,a)}async getRevocationStatus(e,t){let r=this._credentialStatusResolverRegistry?.get(e.type);if(!r)throw new Error(`credential status resolver does not exist for ${e.type} type`);return r.resolve(e,t)}createCredential=(e,t,r)=>{if(!r.$metadata.uris.jsonLdContext)throw new Error("jsonLdContext is missing is the schema");let i={...t};return i.context=i.context??[],i.displayMethod?.type==="Iden3BasicDisplayMethodV1"&&!i.context.includes(Ge.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD)&&i.context.push(Ge.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD),i.context.push(r.$metadata.uris.jsonLdContext),i.expiration=i.expiration?i.expiration*1e3:void 0,i.id=i.id?i.id:`urn:${Ut()}`,i.issuanceDate=i.issuanceDate?i.issuanceDate*1e3:Date.now(),Er.fromCredentialRequest(e,i)};async findById(e){return this._storage.credential.findCredentialById(e)}async findByContextType(e,t){return this._storage.credential.findCredentialsByQuery({context:e,type:t})}async save(e){return this._storage.credential.saveCredential(e)}async saveAll(e){return this._storage.credential.saveAllCredentials(e)}async remove(e){return this._storage.credential.removeCredential(e)}async list(){return this._storage.credential.listCredentials()}async findByQuery(e){return this._storage.credential.findCredentialsByQuery(e)}async filterByCredentialSubject(e,t){return e.filter(r=>r.credentialSubject.id===t.string())}async findNonRevokedCredential(e){for(let t of e){let r=await this.getRevocationStatusFromCredential(t);if(!r.mtp.existence)return{cred:t,revStatus:r}}throw new Error(Ge.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED)}};async function g8(n,e,t,r){let i=await y8(r,e,n);await new W0().publish({nodes:i,credentialStatusType:"Iden3ReverseSparseMerkleTreeProof",rhsUrl:t})}async function y8(n,e,t){let r=new hF;return n&&await YRe(r,e,n),await zRe(r,e),t.bytes.every(i=>i===0)||r.addProofNode(new j0(t,[await e.claimsTree.root(),await e.revocationTree.root(),await e.rootsTree.root()])),r.nodes}async function zRe(n,e){let t=e.rootsTree,r=e.claimsTree;return n.addKey(t,(await r.root()).bigInt())}async function YRe(n,e,t){let r=e.revocationTree;for(let i of t)await n.addKey(r,BigInt(i))}var hF=class{constructor(e=[],t=new Map){this.nodes=e;this.seen=t}async addKey(e,t){let{value:r,siblings:i}=await e.get(t),o=be.fromBigInt(t),s=be.fromBigInt(r),a=new Zc(o,s),c=await jRe(i,a);for(let u of c)this.seen.get(u.hash.hex())||(this.nodes.push(u),this.seen.set(u.hash.hex(),!0))}addProofNode(e){let t=e.hash.hex();this.seen.get(t)||(this.nodes.push(e),this.seen.set(t,!0))}};async function jRe(n,e){if(e.type!==oa)throw new Error("node is not a leaf");let t=await e.getKey(),r=n.length,i=new Array(r+1);for(let a=0;a<i.length;a++)i[a]=new j0;i[r].hash=t;let o=be.fromBigInt(BigInt(1));i[r].children=[e.entry[0],e.entry[1],o];let s=e.entry[0];for(let a=r-1;a>=0;a--){let c=Ew(s.bytes,a);i[a].children=new Array(2),c?(i[a].children[0]=n[a],i[a].children[1]=t):(i[a].children[0]=t,i[a].children[1]=n[a]),i[a].hash=Ch([i[a].children[0].bigInt(),i[a].children[1].bigInt()]),t=i[a].hash}return i}var pF=class n extends Ni{constructor(t,r){super();this._packerMgr=t;this.opts=r}async handle(t,r){switch(t.type){case at.CREDENTIAL_OFFER_MESSAGE_TYPE:{let i=await this.handleOfferMessage(t,r);if(Array.isArray(i)){let o=this.opts?.credentialWallet;if(!o)throw new Error("Credential wallet is not provided");return await o.saveAll(i),null}return i}case at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE:return this.handleFetchRequest(t);case at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:return this.handleIssuanceResponseMsg(t);case at.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE:{let i=await this.handleOnchainOfferMessage(t);if(Array.isArray(i)){let o=this.opts?.credentialWallet;if(!o)throw new Error("Credential wallet is not provided");return await o.saveAll(i),null}return i}case at.ENCRYPTED_CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:return await this.handleEncryptedIssuanceResponseMessage(t),null;default:return super.handle(t,r)}}async handleOnchainOfferMessage(t){if(!this.opts?.onchainIssuer)throw new Error("onchain issuer is not provided");let r=[];for(let i of t.body.credentials){let o=ve.parse(t.from),s=ve.parse(t.to),a=await this.opts.onchainIssuer.getCredential(o,s,BigInt(i.id));r.push(a)}return r}async handleOfferMessage(t,r){r.mediaType||(r.mediaType="application/iden3-zkp-json");let i=[];for(let o of t.body.credentials){let s=Ut(),a={id:s,typ:r.mediaType,type:at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE,thid:t.thid??s,body:{id:o.id},from:t.to,to:t.from},c=ke.encode(JSON.stringify(a)),u=ve.parse(t.to),l=ta(r.mediaType,r.packerOptions,{senderDID:u}),d=lt.decode(await this._packerMgr.pack(r.mediaType,c,l));try{if(!t?.body?.url)throw new Error("could not fetch W3C credential, body url is missing");let f=await(await fetch(t.body.url,{method:"post",headers:{"Content-Type":fM[r.mediaType],...r.headers},body:d})).arrayBuffer();if(!f.byteLength)throw new Error(`could not fetch , ${o?.id}, response is empty`);let{unpackedMessage:m}=await this._packerMgr.unpack(new Uint8Array(f));if(m.type===at.ENCRYPTED_CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE)return await this.handleEncryptedIssuanceResponseMessage(m),[];if(m.type!==at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE)return m;i.push(Er.fromJSON(m.body.credential))}catch(h){throw new Error(`could not fetch protocol message for credential offer id: , ${o?.id}, error: ${h.message??h}`)}}return i}async handleCredentialOffer(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_OFFER_MESSAGE_TYPE);r?.allowExpiredMessages||Lr(i);let o=r?.mediaType||"application/iden3-zkp-json",s=ta(o,r?.packerOptions,{provingMethodAlg:r?.messageProvingMethodAlg||await Hc(t),senderDID:ve.parse(i.to)}),a=await this.handleOfferMessage(i,{mediaType:o,headers:r?.headers,packerOptions:s});if(Array.isArray(a))return a;throw new Error("invalid protocol message response")}async handleOnchainOffer(t){let r=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE);return this.handleOnchainOfferMessage(r)}async handleFetchRequest(t){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");let r=ve.parse(t.to),i=ve.parse(t.from),o=t.body?.id;if(!o)throw new Error("invalid credential id in fetch request body");if(!this.opts?.credentialWallet)throw new Error("please, provide credential wallet in options");let s=await this.opts.credentialWallet.findById(o);if(!s)throw new Error("credential not found");if(Xl(r,s).string()!==i.string())throw new Error("credential subject is not a sender DID");return{id:Ut(),type:at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE,typ:t.typ??"application/iden3comm-plain-json",thid:t.thid??Ut(),body:{credential:s},from:t.to,to:t.from}}async handleCredentialFetchRequest(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);r?.allowExpiredMessages||Lr(i);let o=await this.handleFetchRequest(i);return this._packerMgr.pack("application/iden3comm-plain-json",ke.encode(JSON.stringify(o)),{})}async handleEncryptedIssuanceResponseMessage(t){if(!this.opts?.joseService)throw new Error("JoseService is not initialized. Encrypted issuance response cannot be handled");let{plaintext:r}=await this.opts.joseService.decrypt(t.body.data),i=Er.fromJSON({...JSON.parse(lt.decode(r)),proof:t.body.proof});if(!this.opts?.credentialWallet)throw new Error("please provide credential wallet in options for encrypted issuance response handling");if(!this.opts?.didResolverUrl)throw new Error("please provide resolver URL in options for encrypted issuance response handling");if(!this.opts?.merklizeOptions)throw new Error("please provide merklize options for encrypted issuance response handling");let o=this.opts.credentialWallet.getCredentialStatusResolverRegistry();if(!o)throw new Error("credential status resolver registry is not available in credential wallet");if(!await i.verifyProofs(this.opts.didResolverUrl,{credStatusResolverRegistry:o,merklizeOptions:this.opts.merklizeOptions}))throw new Error("credential proof verification failed");return await this.opts?.credentialWallet?.save(i),null}async handleIssuanceResponseMsg(t){if(!this.opts?.credentialWallet)throw new Error("please provide credential wallet in options");if(!t.body?.credential)throw new Error("credential is missing in issuance response message");if(!(t.body.credential instanceof Er))throw new Error("credential object is not properly unmarshaled");return await this.opts.credentialWallet.save(t.body.credential),null}async handleIssuanceResponseMessage(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);return r?.allowExpiredMessages||Lr(i),i.body.credential=Er.fromJSON(i.body.credential),await this.handleIssuanceResponseMsg(i),Uint8Array.from([])}static async unpackMessage(t,r,i){let{unpackedMessage:o}=await t.unpack(r),s=o;if(o.type!==i)throw new Error("Invalid message type");return s}};var mF=class extends Ni{constructor(t,r,i){super();this._packerMgr=t;this._proofService=r;this._zkpVerifier=i}_supportedCircuits=["authV2","credentialAtomicQueryMTPV2OnChain","credentialAtomicQuerySigV2OnChain","credentialAtomicQueryV3OnChain-beta.1","credentialAtomicQueryV3OnChain","authV2","authV3","authV3-8-32","linkedMultiQuery10-beta.1","credentialAtomicQueryV3","linkedMultiQuery"];async handle(t,r){switch(t.type){case at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE:{let i=t,o=await this.handleContractInvoke(i,r);return this.createContractInvokeResponse(i,o)}default:return super.handle(t,r)}}async handleContractInvoke(t,r){if(t.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for contract invoke request");let{senderDid:i,ethSigner:o,challenge:s}=r;if(!r.ethSigner)throw new Error("Can't sign transaction. Provide Signer in options.");let{chain_id:a}=t.body.transaction_data;if(!Object.keys(na).find(f=>na[f]===a))throw new Error(`Invalid chain id ${a}`);let u=t.from?ve.parse(t.from):void 0,{scope:l=[]}=t.body,d=await Wy(i,l,u,this._proofService,{ethSigner:o,challenge:s??It.bytesToInt(di(await o.getAddress())),supportedCircuits:this._supportedCircuits});switch(t.body.transaction_data.method_id.replace("0x","")){case"ade09fcd":{let f=await this._zkpVerifier.submitZKPResponseV2(o,t.body.transaction_data,d),m=new Map;for(let[w,b]of f)m.set(w,{responses:b});return t.body.transaction_data.txHash=f.keys().next().value,m}case"b68967e2":{let f=await this._zkpVerifier.submitZKPResponse(o,t.body.transaction_data,d),m=new Map;for(let[w,b]of f)m.set(w,{responses:[b]});return t.body.transaction_data.txHash=f.keys().next().value,m}case"06c86a91":{if(!t.to)throw new Error("failed message. empty 'to' field");let f=this.getFirstSupportedProfile(at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE,t.body.accept),m=ve.parse(t.to),{authProof:w}=await iF(m,this._proofService,{supportedCircuits:this._supportedCircuits,acceptProfile:f,senderAddress:await o.getAddress(),zkpResponses:d}),b=await this._zkpVerifier.submitResponse(o,t.body.transaction_data,d,w);return t.body.transaction_data.txHash=b.keys().next().value,b}default:throw new Error("Not supported method id. Only 'b68967e2, ade09fcd and 06c86a91 are supported.'")}}getFirstSupportedProfile(t,r){if(r?.length)for(let i of r){let o=xs(i),s=Number(t.split("/").at(-2));if(!(o.protocolVersion!=="iden3comm/v1"||o.protocolVersion==="iden3comm/v1"&&(s<1||s>=2))&&this._packerMgr.isProfileSupported(o.env,i))return o}return TE}async parseContractInvokeRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i.body.scope=i.body.scope||[],i}async createContractInvokeResponse(t,r){let i={id:t.id,thid:t.thid,type:at.CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE,from:t.to,to:t.from,body:{transaction_data:t.body.transaction_data,scope:[]},created_time:Lt(new Date)};for(let[o,s]of r){for(let a of s.responses)i.body.scope.push({txHash:o,...a});i.body={...i.body,crossChainProof:s.crossChainProof,authProof:s.authProof}}return i}async handleContractInvokeRequest(t,r,i){let o=await this.parseContractInvokeRequest(r);if(i.allowExpiredMessages||Lr(o),o.body.transaction_data.method_id!=="b68967e2")throw new Error("please use handle method to work with other method ids");if(o.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for contract invoke request");let{ethSigner:s,challenge:a}=i;if(!s)throw new Error("Can't sign transaction. Provide Signer in options.");let{chain_id:c}=o.body.transaction_data;if(!Object.keys(na).find(h=>na[h]===c))throw new Error(`Invalid chain id ${c}`);let l=o.from?ve.parse(o.from):void 0,d=await Wy(t,o?.body?.scope,l,this._proofService,{ethSigner:s,challenge:a,supportedCircuits:this._supportedCircuits});return this._zkpVerifier.submitZKPResponse(s,o.body.transaction_data,d)}};var gF=class{constructor(e){this._options=e}async refreshCredential(e,t){if(!e.refreshService)throw new Error("refreshService not specified for W3CCredential");if(e.refreshService.type!=="Iden3RefreshService2023")throw new Error(`refresh service type ${e.refreshService.type} is not supported`);let r=e.credentialSubject.id;if(!r)throw new Error("self credentials do not support refresh");let i=ve.parse(r),o=t?.mediaType||"application/iden3-zkp-json",s=t?.packerOptions??{senderDID:i,provingMethodAlg:Kc},a={id:Ut(),typ:"application/iden3-zkp-json",type:at.CREDENTIAL_REFRESH_MESSAGE_TYPE,thid:Ut(),body:{id:e.id,reason:t?.reason??"credential is expired"},from:r,to:e.issuer},c=ke.encode(JSON.stringify(a)),u=await this._options.packageManager.pack(o,c,s),l=await fetch(e.refreshService.id,{method:"post",headers:{"Content-Type":"application/json"},body:u.buffer});if(l.status!==200)throw new Error(`could not refresh W3C credential, return status ${l.status}`);let d=await l.json();if(!d.body?.credential)throw new Error("no credential in CredentialIssuanceMessage response");return Er.fromJSON(d.body.credential)}};var yF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._identityWallet=r}handle(t,r){if(!r.senderDid)throw new Error("DID is required");if(!r.mediaType)throw new Error("mediaType is required");switch(t.type){case at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE:return this.handleRevocationStatusRequestMessage(t,r);default:return super.handle(t,r)}}async handleRevocationStatusRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body?.revocation_nonce)throw new Error("failed request. empty 'revocation_nonce' field");let i=ve.parse(t.to),o=await this._identityWallet.generateNonRevocationMtpWithNonce(i,BigInt(t.body.revocation_nonce),r.treeState),s=o.treeState,a={issuer:{state:s?.state.string(),claimsTreeRoot:s.claimsRoot.string(),revocationTreeRoot:s.revocationRoot.string(),rootOfRoots:s.rootOfRoots.string()},mtp:o.proof},c=Ut();return{id:c,typ:"application/iden3comm-plain-json",type:at.REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE,thid:t.thid??c,body:a,from:r.senderDid.string(),to:t.from}}async parseRevocationStatusRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handleRevocationStatusRequest(t,r,i){i||(i={mediaType:"application/iden3comm-plain-json"});let o=await this.parseRevocationStatusRequest(r);i.allowExpiredMessages||Lr(o);let s=await this.handleRevocationStatusRequestMessage(o,{senderDid:t,mediaType:i.mediaType,packerOptions:i.packerOptions,treeState:i.treeState});if(!o.to)throw new Error("failed request. empty 'to' field");let a=ve.parse(o.to),c=ta(i.mediaType,i.packerOptions,{senderDID:a,provingMethodAlg:i.packerOptions?.provingMethodAlg||await Hc(r)});return this._packerMgr.pack(i.mediaType,ke.encode(JSON.stringify(s)),c)}};function WRe(n,e,t){let r=Ut();return{id:r,thid:r,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PROPOSAL_REQUEST_MESSAGE_TYPE,body:{credentials:t.credentials,did_doc:t.did_doc},created_time:Lt(new Date),expires_time:t?.expires_time?Lt(t.expires_time):void 0,attachments:t.attachments}}function ZRe(n,e,t,r){let i=Ut();return{id:i,thid:i,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PROPOSAL_MESSAGE_TYPE,body:{proposals:t||[]},created_time:Lt(new Date),expires_time:r?.expires_time?Lt(r.expires_time):void 0}}var wF=class extends Ni{constructor(t,r,i){super();this._packerMgr=t;this._identityWallet=r;this._params=i}async handle(t,r){switch(t.type){case at.PROPOSAL_REQUEST_MESSAGE_TYPE:return await this.handleProposalRequestMessage(t,r);default:return super.handle(t,r)}}async parseProposalRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.PROPOSAL_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handleProposalRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body?.credentials?.length)throw new Error("failed request. no 'credentials' in body");let i,o;for(let s=0;s<t.body.credentials.length;s++){let a=t.body.credentials[s],c=[];if(!r?.forceCredentialReissue){try{c=await this._identityWallet.credentialWallet.findByQuery({credentialSubject:{id:{$eq:t.from}},type:a.type,context:a.context,allowedIssuers:[t.to]})}catch(l){if(l.message!=="no credential satisfied query")throw l}if(c.length){let l=Ut();i||(i={id:l,typ:this._params.packerParams.mediaType,type:at.CREDENTIAL_OFFER_MESSAGE_TYPE,thid:t.thid??l,body:{url:this._params.agentUrl,credentials:[]},from:t.to,to:t.from}),i.body.credentials.push(...c.map(d=>({id:d.id,description:""})));continue}}let u=await this._params.proposalResolverFn(a.context,a.type,{msg:t});if(!u)throw new Error(`can't resolve Proposal for type: ${a.type}, context: ${a.context}`);if(!o){let l=Ut();o={id:l,typ:this._params.packerParams.mediaType,type:at.PROPOSAL_MESSAGE_TYPE,thid:t.thid??l,body:{proposals:[]},from:t.to,to:t.from}}o.body?.proposals.push(u)}return o??i}async handleProposalRequest(t,r){let i=await this.parseProposalRequest(t);if(!i.from)throw new Error("failed request. empty 'from' field");r?.allowExpiredMessages||Lr(i);let o=ve.parse(i.from),s=await this.handleProposalRequestMessage(i),a=ke.encode(JSON.stringify(s)),c=ta(this._params.packerParams.mediaType,this._params.packerParams.packerOptions,{provingMethodAlg:await Hc(t),senderDID:o});return this._packerMgr.pack(this._params.packerParams.mediaType,a,c)}async handleProposal(t,r){if(r?.allowExpiredMessages||Lr(t),r?.proposalRequest&&r.proposalRequest.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${r.proposalRequest.from}, given ${t.to}`);return{proposal:t}}};function bte(n,e,t,r,i){let o=Ut();return{id:o,thid:o,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PAYMENT_REQUEST_MESSAGE_TYPE,body:{agent:t,payments:r},created_time:Lt(new Date),expires_time:i?.expires_time?Lt(i.expires_time):void 0}}function Ete(n,e,t,r){let i=Ut();return{id:i,thid:i,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PAYMENT_MESSAGE_TYPE,body:{payments:t},created_time:Lt(new Date),expires_time:r?.expires_time?Lt(r.expires_time):void 0}}var bF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._params=r}async handle(t,r){switch(t.type){case at.PAYMENT_REQUEST_MESSAGE_TYPE:return await this.handlePaymentRequestMessage(t,r);case at.PAYMENT_MESSAGE_TYPE:return await this.handlePayment(t,r),null;default:return super.handle(t,r)}}async parsePaymentRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.PAYMENT_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handlePaymentRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body.payments?.length)throw new Error("failed request. no 'payments' in body");if(!r.paymentHandler)throw new Error("please provide payment handler in context");let i=ve.parse(t.to),o=ve.parse(t.from),s=[];for(let m=0;m<t.body.payments.length;m++){let{data:w}=t.body.payments[m],b=Array.isArray(w)?w.find(S=>S.type==="Iden3PaymentRequestCryptoV1"?S.id===r.nonce:S.nonce===r.nonce):w;if(!b)throw new Error(`failed request. no payment in request for nonce ${r.nonce}`);switch(b.type){case"Iden3PaymentRequestCryptoV1":s.push(await this.handleIden3PaymentRequestCryptoV1(b,r.paymentHandler));break;case"Iden3PaymentRailsRequestV1":s.push(await this.handleIden3PaymentRailsRequestV1(b,r.paymentHandler));break;case"Iden3PaymentRailsERC20RequestV1":s.push(await this.handleIden3PaymentRailsERC20RequestV1(b,r.paymentHandler,r.erc20TokenApproveHandler));break;case"Iden3PaymentRailsSolanaRequestV1":s.push(await this.handleIden3PaymentRailsSolanaRequestV1(b,r.paymentHandler));break;case"Iden3PaymentRailsSolanaSPLRequestV1":s.push(await this.handleIden3PaymentRailsSolanaSPLRequestV1({...b,type:"Iden3PaymentRailsSolanaSPLRequestV1"},r.paymentHandler));break}}let a=Ete(i,o,s),c=r?.mediaType||this._params.packerParams.mediaType||"application/iden3-zkp-json",u=ta(c,r?.packerOptions||this._params.packerParams,{senderDID:i,provingMethodAlg:r.messageProvingMethodAlg}),l=await this.packMessage(a,i,c,u),h=await(await fetch(t.body.agent,{method:"POST",body:l.buffer,headers:{...r.headers,"Content-Type":this._params.packerParams.mediaType==="application/iden3comm-plain-json"?"application/json":"application/octet-stream"}})).arrayBuffer();if(!h.byteLength)return null;let{unpackedMessage:f}=await this._packerMgr.unpack(new Uint8Array(h));return f}async handlePaymentRequest(t,r){let i=await this.parsePaymentRequest(t);if(!i.from)throw new Error("failed request. empty 'from' field");if(!i.to)throw new Error("failed request. empty 'to' field");r?.allowExpiredMessages||Lr(i);let o=r.mediaType||this._params.packerParams.mediaType||"application/iden3-zkp-json";r.packerOptions||(r.packerOptions=this._params.packerParams.packerOptions),r.mediaType=o;let s=ve.parse(i.to);r.packerOptions=ta(o,r.packerOptions,{provingMethodAlg:await Hc(t),senderDID:s});let a=await this.handlePaymentRequestMessage(i,r);return a?this.packMessage(a,s,r.mediaType||"application/iden3-zkp-json",r.packerOptions):null}async handlePayment(t,r){if(r?.allowExpiredMessages||Lr(t),r.paymentRequest.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${r.paymentRequest.from}, given ${t.to}`);if(!t.body.payments.length)throw new Error("failed request. empty 'payments' field in body");if(!r.paymentValidationHandler)throw new Error("please provide payment validation handler in options");for(let i=0;i<t.body.payments.length;i++){let o=t.body.payments[i],s=o.type==="Iden3PaymentCryptoV1"?o.id:o.nonce,c=r.paymentRequest.body.payments.map(u=>Array.isArray(u.data)?u.data:[u.data]).flat().find(u=>u.type==="Iden3PaymentRequestCryptoV1"?u.id===s:u.nonce===s);if(!c)throw new Error(`can't find payment request for payment ${o.type==="Iden3PaymentCryptoV1"?"id":"nonce"} ${s}`);await r.paymentValidationHandler(o.paymentData.txId,c)}}async createPaymentRailsV1(t,r,i,o,s,a){let c=[];for(let u=0;u<s.length;u++){let{credentials:l,description:d}=s[u],h=[];for(let f=0;f<s[u].options.length;f++){let{nonce:m,amount:w,chainId:b,optionId:S,expirationDate:R}=s[u].options[f],G=this._params.multiChainPaymentConfig?.find(z=>z.chainId===b);if(!G)throw new Error(`failed request. no config for chain ${b}`);let{recipient:U,paymentRails:H,options:M}=G,A=M.find(z=>z.id===S);if(!A)throw new Error(`failed request. no option for id ${S}`);if((A.type==="Iden3PaymentRailsERC20RequestV1"||A.type==="Iden3PaymentRailsSolanaSPLRequestV1")&&!A.contractAddress)throw new Error(`failed request. no token address for option id ${S}`);let D=R??new Date(new Date().setHours(new Date().getHours()+1));if(A.type==="Iden3PaymentRailsSolanaRequestV1"||A.type==="Iden3PaymentRailsSolanaSPLRequestV1"){if(!a?.solSigner)throw new Error(`please provide solana signer in context for ${A.type} payment type`);let z=await SB(a.solSigner,A,b,H,U,BigInt(w),D,m);h.push(z)}else{let z=await CB(o,A,b,H,U,BigInt(w),D,m);h.push(z)}}c.push({data:h,credentials:l,description:d})}return bte(t,r,i,c)}async packMessage(t,r,i,o){let s=ke.encode(JSON.stringify(t)),a=i==="application/iden3comm-signed-json"?o:{provingMethodAlg:o?.provingMethodAlg||Kc};return await this._packerMgr.pack(i,s,{senderDID:r,...a})}async handleIden3PaymentRequestCryptoV1(t,r){if(t.expiration&&new Date(t.expiration)<new Date)throw new Error("failed request. expired request");let i=await r(t);return{id:t.id,"@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentCryptoV1",type:"Iden3PaymentCryptoV1",paymentData:{txId:i}}}async handleIden3PaymentRailsRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");let i=await aS(t,this._params.documentResolver);if(this._params.allowedSigners&&!this._params.allowedSigners.includes(i))throw new Error("failed request. signer is not in the allowed signers list");let o=await r(t),s=Array.isArray(t.proof)?t.proof[0]:t.proof;return{nonce:t.nonce,type:"Iden3PaymentRailsV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsV1",paymentData:{txId:o,chainId:s.eip712.domain.chainId}}}async handleIden3PaymentRailsSolanaRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");if(!await sS(t,this._params.documentResolver))throw new Error("failed request. invalid Solana payment request signature");let o=Array.isArray(t.proof)?t.proof[0]:t.proof,s=o.verificationMethod.split(":").slice(-1)[0];if(this._params.allowedSigners&&!this._params.allowedSigners.includes(s))throw new Error("failed request. signer is not in the allowed signers list");let a=await r(t);return{nonce:t.nonce,type:"Iden3PaymentRailsSolanaV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaV1",paymentData:{txId:a,chainId:o.domain.chainId}}}async handleIden3PaymentRailsSolanaSPLRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");if(!await sS(t,this._params.documentResolver))throw new Error("failed request. invalid Solana payment request signature");let o=Array.isArray(t.proof)?t.proof[0]:t.proof,s=o.verificationMethod.split(":").slice(-1)[0];if(this._params.allowedSigners&&!this._params.allowedSigners.includes(s))throw new Error("failed request. signer is not in the allowed signers list");let a=await r(t);return{nonce:t.nonce,type:"Iden3PaymentRailsSolanaSPLV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaSPLV1",paymentData:{txId:a,chainId:o.domain.chainId,tokenAddress:t.tokenAddress}}}async handleIden3PaymentRailsERC20RequestV1(t,r,i){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");let o=await aS(t,this._params.documentResolver);if(this._params.allowedSigners&&!this._params.allowedSigners.includes(o))throw new Error("failed request. signer is not in the allowed signers list");if(!t.features?.includes("EIP-2612")&&!i)throw new Error("please provide erc20TokenApproveHandler in context for ERC-20 payment type");i&&await i(t);let s=await r(t),a=Array.isArray(t.proof)?t.proof[0]:t.proof;return{nonce:t.nonce,type:"Iden3PaymentRailsERC20V1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20V1",paymentData:{txId:s,chainId:a.eip712.domain.chainId,tokenAddress:t.tokenAddress}}}};function XRe(n,e){let t=Ut();return{id:t,thid:t,typ:"application/iden3comm-plain-json",type:at.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,body:{queries:n},from:e?.from,to:e?.to,created_time:Lt(new Date),expires_time:e?.expires_time}}function Ite(n,e){let t=Ut();return{id:t,typ:"application/iden3comm-plain-json",thid:t,type:at.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,body:{disclosures:n},from:e?.from,to:e?.to,created_time:Lt(new Date),expires_time:e?.expires_time}}var EF=class extends Ni{constructor(t){super();this._options=t;let r=["id","typ","type","thid","body","from","to","created_time","expires_time"];t.headers||(t.headers=r)}async handle(t,r){switch(t.type){case at.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:return await this.handleDiscoveryQuery(t,r);default:return super.handle(t,r)}}async handleDiscoveryQuery(t,r){r?.allowExpiredMessages||Lr(t);let i=[];for(let o of t.body.queries)i.push(...this.handleQuery(o));return Promise.resolve(Ite(i,{to:t.from,from:t.to,expires_time:r?.disclosureExpiresDate?Lt(r.disclosureExpiresDate):void 0}))}handleQuery(t){let r=[];switch(t["feature-type"]){case"accept":r=this.handleAcceptQuery();break;case"protocol":r=this.handleProtocolQuery();break;case"goal-code":r=this.handleGoalCodeQuery();break;case"header":r=this.handleHeaderQuery();break}return this.handleMatch(r,t.match)}handleAcceptQuery(){return this._options.packageManager.getSupportedProfiles().map(r=>({"feature-type":"accept",id:r}))}handleProtocolQuery(){return this._options.protocols?.map(t=>({"feature-type":"protocol",id:t}))??[]}handleGoalCodeQuery(){return this._options.goalCodes?.map(t=>({"feature-type":"goal-code",id:t}))??[]}handleHeaderQuery(){return this._options.headers?.map(t=>({"feature-type":"header",id:t}))??[]}handleMatch(t,r){if(!r||r==="*")return t;let i=this.wildcardToRegExp(r);return t.filter(o=>i.test(o.id))}wildcardToRegExp(t){let r=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${r}$`)}};function Ate(n,e){return{id:Ut(),pthid:e?.pthid,typ:"application/iden3comm-plain-json",type:at.PROBLEM_REPORT_MESSAGE_TYPE,ack:e?.ack,body:{code:n,comment:e?.comment,args:e?.args,escalate_to:e?.escalate_to},from:e?.from,to:e?.to}}function _Re(n,e,t){return Ate(e,{pthid:n,...t})}var xte=new TextEncoder,Z0=new TextDecoder,w8=2**32;function Ss(...n){let e=n.reduce((i,{length:o})=>i+o,0),t=new Uint8Array(e),r=0;for(let i of n)t.set(i,r),r+=i.length;return t}function IF(n,e,t){if(e<0||e>=w8)throw new RangeError(`value must be >= 0 and <= ${w8-1}. Received ${e}`);n.set([e>>>24,e>>>16,e>>>8,e&255],t)}function b8(n){let e=Math.floor(n/w8),t=n%w8,r=new Uint8Array(8);return IF(r,e,0),IF(r,t,4),r}function E8(n){let e=new Uint8Array(4);return IF(e,n),e}function Ka(n){let e=new Uint8Array(n.length);for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r>127)throw new TypeError("non-ASCII string encountered in encode()");e[t]=r}return e}function vte(n){if(Uint8Array.prototype.toBase64)return n.toBase64();let e=32768,t=[];for(let r=0;r<n.length;r+=e)t.push(String.fromCharCode.apply(null,n.subarray(r,r+e)));return btoa(t.join(""))}function Ste(n){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(n);let e=atob(n),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function Zr(n){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof n=="string"?n:Z0.decode(n),{alphabet:"base64url"});let e=n;e instanceof Uint8Array&&(e=Z0.decode(e)),e=e.replace(/-/g,"+").replace(/_/g,"/");try{return Ste(e)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}function Xr(n){let e=n;return typeof e=="string"&&(e=xte.encode(e)),Uint8Array.prototype.toBase64?e.toBase64({alphabet:"base64url",omitPadding:!0}):vte(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var Xy=class extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};var hI=class extends Xy{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},Zt=class extends Xy{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},bh=class extends Xy{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}},Ve=class extends Xy{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"};function AF(n){switch(n){case"A128GCM":case"A128GCMKW":case"A192GCM":case"A192GCMKW":case"A256GCM":case"A256GCMKW":return 96;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return 128;default:throw new Zt(`Unsupported JWE Algorithm: ${n}`)}}var Cte=n=>crypto.getRandomValues(new Uint8Array(AF(n)>>3));function I8(n,e){if(e.length<<3!==AF(n))throw new Ve("Invalid Initialization Vector length")}function _y(n,e){let t=n.byteLength<<3;if(t!==e)throw new Ve(`Invalid Content Encryption Key length. Expected ${e} bits, got ${t} bits`)}var Eh=(n,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${n}`),A8=(n,e)=>n.name===e;function $Re(n){return parseInt(n.name.slice(4),10)}function eDe(n,e){if(e&&!n.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function Cs(n,e,t){switch(e){case"A128GCM":case"A192GCM":case"A256GCM":{if(!A8(n.algorithm,"AES-GCM"))throw Eh("AES-GCM");let r=parseInt(e.slice(1,4),10);if(n.algorithm.length!==r)throw Eh(r,"algorithm.length");break}case"A128KW":case"A192KW":case"A256KW":{if(!A8(n.algorithm,"AES-KW"))throw Eh("AES-KW");let r=parseInt(e.slice(1,4),10);if(n.algorithm.length!==r)throw Eh(r,"algorithm.length");break}case"ECDH":{switch(n.algorithm.name){case"ECDH":case"X25519":break;default:throw Eh("ECDH or X25519")}break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":if(!A8(n.algorithm,"PBKDF2"))throw Eh("PBKDF2");break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(!A8(n.algorithm,"RSA-OAEP"))throw Eh("RSA-OAEP");let r=parseInt(e.slice(9),10)||1;if($Re(n.algorithm.hash)!==r)throw Eh(`SHA-${r}`,"algorithm.hash");break}default:throw new TypeError("CryptoKey does not support this operation")}eDe(n,t)}function Lte(n,e,...t){if(t=t.filter(Boolean),t.length>2){let r=t.pop();n+=`one of type ${t.join(", ")}, or ${r}.`}else t.length===2?n+=`one of type ${t[0]} or ${t[1]}.`:n+=`of type ${t[0]}.`;return e==null?n+=` Received ${e}`:typeof e=="function"&&e.name?n+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(n+=` Received an instance of ${e.constructor.name}`),n}var Ih=(n,...e)=>Lte("Key must be ",n,...e),xF=(n,e,...t)=>Lte(`Key for the ${n} algorithm must be `,e,...t);function X0(n){if(!qu(n))throw new Error("CryptoKey instance expected")}var qu=n=>{if(n?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return n instanceof CryptoKey}catch{return!1}},pI=n=>n?.[Symbol.toStringTag]==="KeyObject",vF=n=>qu(n)||pI(n);async function tDe(n,e){if(!(n instanceof Uint8Array))throw new TypeError("First argument must be a buffer");if(!(e instanceof Uint8Array))throw new TypeError("Second argument must be a buffer");let t={name:"HMAC",hash:"SHA-256"},r=await crypto.subtle.generateKey(t,!1,["sign"]),i=new Uint8Array(await crypto.subtle.sign(t,r,n)),o=new Uint8Array(await crypto.subtle.sign(t,r,e)),s=0,a=-1;for(;++a<32;)s|=i[a]^o[a];return s===0}async function nDe(n,e,t,r,i,o){if(!(e instanceof Uint8Array))throw new TypeError(Ih(e,"Uint8Array"));let s=parseInt(n.slice(1,4),10),a=await crypto.subtle.importKey("raw",e.subarray(s>>3),"AES-CBC",!1,["decrypt"]),c=await crypto.subtle.importKey("raw",e.subarray(0,s>>3),{hash:`SHA-${s<<1}`,name:"HMAC"},!1,["sign"]),u=Ss(o,r,t,b8(o.length<<3)),l=new Uint8Array((await crypto.subtle.sign("HMAC",c,u)).slice(0,s>>3)),d;try{d=await tDe(i,l)}catch{}if(!d)throw new bh;let h;try{h=new Uint8Array(await crypto.subtle.decrypt({iv:r,name:"AES-CBC"},a,t))}catch{}if(!h)throw new bh;return h}async function rDe(n,e,t,r,i,o){let s;e instanceof Uint8Array?s=await crypto.subtle.importKey("raw",e,"AES-GCM",!1,["decrypt"]):(Cs(e,n,"decrypt"),s=e);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:o,iv:r,name:"AES-GCM",tagLength:128},s,Ss(t,i)))}catch{throw new bh}}async function x8(n,e,t,r,i,o){if(!qu(e)&&!(e instanceof Uint8Array))throw new TypeError(Ih(e,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!r)throw new Ve("JWE Initialization Vector missing");if(!i)throw new Ve("JWE Authentication Tag missing");switch(I8(n,r),n){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return e instanceof Uint8Array&&_y(e,parseInt(n.slice(-3),10)),nDe(n,e,t,r,i,o);case"A128GCM":case"A192GCM":case"A256GCM":return e instanceof Uint8Array&&_y(e,parseInt(n.slice(1,4),10)),rDe(n,e,t,r,i,o);default:throw new Zt("Unsupported JWE Content Encryption Algorithm")}}function $y(...n){let e=n.filter(Boolean);if(e.length===0||e.length===1)return!0;let t;for(let r of e){let i=Object.keys(r);if(!t||t.size===0){t=new Set(i);continue}for(let o of i){if(t.has(o))return!1;t.add(o)}}return!0}var iDe=n=>typeof n=="object"&&n!==null;function Zo(n){if(!iDe(n)||Object.prototype.toString.call(n)!=="[object Object]")return!1;if(Object.getPrototypeOf(n)===null)return!0;let e=n;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(n)===e}function Rte(n,e){if(n.algorithm.length!==parseInt(e.slice(1,4),10))throw new TypeError(`Invalid key size for alg: ${e}`)}function Dte(n,e,t){return n instanceof Uint8Array?crypto.subtle.importKey("raw",n,"AES-KW",!0,[t]):(Cs(n,e,t),n)}async function mI(n,e,t){let r=await Dte(e,n,"wrapKey");Rte(r,n);let i=await crypto.subtle.importKey("raw",t,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",i,r,"AES-KW"))}async function gI(n,e,t){let r=await Dte(e,n,"unwrapKey");Rte(r,n);let i=await crypto.subtle.unwrapKey("raw",t,r,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",i))}async function Tte(n,e){let t=`SHA-${n.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(t,e))}function CF(n){return Ss(E8(n.length),n)}async function oDe(n,e,t){let r=e>>3,i=32,o=Math.ceil(r/i),s=new Uint8Array(o*i);for(let a=1;a<=o;a++){let c=new Uint8Array(4+n.length+t.length);c.set(E8(a),0),c.set(n,4),c.set(t,4+n.length);let u=await Tte("sha256",c);s.set(u,(a-1)*i)}return s.slice(0,r)}async function v8(n,e,t,r,i=new Uint8Array,o=new Uint8Array){Cs(n,"ECDH"),Cs(e,"ECDH","deriveBits");let s=CF(Ka(t)),a=CF(i),c=CF(o),u=E8(r),l=new Uint8Array,d=Ss(s,a,c,u,l),h=new Uint8Array(await crypto.subtle.deriveBits({name:n.algorithm.name,public:n},e,sDe(n)));return oDe(h,r,d)}function sDe(n){return n.algorithm.name==="X25519"?256:Math.ceil(parseInt(n.algorithm.namedCurve.slice(-3),10)/8)<<3}function S8(n){switch(n.algorithm.namedCurve){case"P-256":case"P-384":case"P-521":return!0;default:return n.algorithm.name==="X25519"}}function aDe(n,e){return n instanceof Uint8Array?crypto.subtle.importKey("raw",n,"PBKDF2",!1,["deriveBits"]):(Cs(n,e,"deriveBits"),n)}var cDe=(n,e)=>Ss(Ka(n),Uint8Array.of(0),e);async function Pte(n,e,t,r){if(!(n instanceof Uint8Array)||n.length<8)throw new Ve("PBES2 Salt Input must be 8 or more octets");let i=cDe(e,n),o=parseInt(e.slice(13,16),10),s={hash:`SHA-${e.slice(8,11)}`,iterations:t,name:"PBKDF2",salt:i},a=await aDe(r,e);return new Uint8Array(await crypto.subtle.deriveBits(s,a,o))}async function kte(n,e,t,r=2048,i=crypto.getRandomValues(new Uint8Array(16))){let o=await Pte(i,n,r,e);return{encryptedKey:await mI(n.slice(-6),o,t),p2c:r,p2s:Xr(i)}}async function Mte(n,e,t,r,i){let o=await Pte(i,n,r,e);return gI(n.slice(-6),o,t)}function LF(n,e){if(n.startsWith("RS")||n.startsWith("PS")){let{modulusLength:t}=e.algorithm;if(typeof t!="number"||t<2048)throw new TypeError(`${n} requires key modulusLength to be 2048 bits or larger`)}}var Fte=n=>{switch(n){case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return"RSA-OAEP";default:throw new Zt(`alg ${n} is not supported either by JOSE or your javascript runtime`)}};async function Nte(n,e,t){return Cs(e,n,"encrypt"),LF(n,e),new Uint8Array(await crypto.subtle.encrypt(Fte(n),e,t))}async function Ute(n,e,t){return Cs(e,n,"decrypt"),LF(n,e),new Uint8Array(await crypto.subtle.decrypt(Fte(n),e,t))}function yI(n){switch(n){case"A128GCM":return 128;case"A192GCM":return 192;case"A256GCM":case"A128CBC-HS256":return 256;case"A192CBC-HS384":return 384;case"A256CBC-HS512":return 512;default:throw new Zt(`Unsupported JWE Algorithm: ${n}`)}}var Vu=n=>crypto.getRandomValues(new Uint8Array(yI(n)>>3));function uDe(n){let e,t;switch(n.kty){case"AKP":{switch(n.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":e={name:n.alg},t=n.priv?["sign"]:["verify"];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"RSA":{switch(n.alg){case"PS256":case"PS384":case"PS512":e={name:"RSA-PSS",hash:`SHA-${n.alg.slice(-3)}`},t=n.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":e={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${n.alg.slice(-3)}`},t=n.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":e={name:"RSA-OAEP",hash:`SHA-${parseInt(n.alg.slice(-3),10)||1}`},t=n.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"EC":{switch(n.alg){case"ES256":e={name:"ECDSA",namedCurve:"P-256"},t=n.d?["sign"]:["verify"];break;case"ES384":e={name:"ECDSA",namedCurve:"P-384"},t=n.d?["sign"]:["verify"];break;case"ES512":e={name:"ECDSA",namedCurve:"P-521"},t=n.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:"ECDH",namedCurve:n.crv},t=n.d?["deriveBits"]:[];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"OKP":{switch(n.alg){case"Ed25519":case"EdDSA":e={name:"Ed25519"},t=n.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:n.crv},t=n.d?["deriveBits"]:[];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}default:throw new Zt('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:e,keyUsages:t}}async function ew(n){if(!n.alg)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');let{algorithm:e,keyUsages:t}=uDe(n),r={...n};return r.kty!=="AKP"&&delete r.alg,delete r.use,crypto.subtle.importKey("jwk",r,e,n.ext??!(n.d||n.priv),n.key_ops??t)}async function Hte(n,e,t){if(!Zo(n))throw new TypeError("JWK must be an object");let r;switch(e??=n.alg,r??=t?.extractable??n.ext,n.kty){case"oct":if(typeof n.k!="string"||!n.k)throw new TypeError('missing "k" (Key Value) Parameter value');return Zr(n.k);case"RSA":if("oth"in n&&n.oth!==void 0)throw new Zt('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');return ew({...n,alg:e,ext:r});case"AKP":{if(typeof n.alg!="string"||!n.alg)throw new TypeError('missing "alg" (Algorithm) Parameter value');if(e!==void 0&&e!==n.alg)throw new TypeError("JWK alg and alg option value mismatch");return ew({...n,ext:r})}case"EC":case"OKP":return ew({...n,alg:e,ext:r});default:throw new Zt('Unsupported "kty" (Key Type) Parameter value')}}async function lDe(n,e,t,r,i){if(!(t instanceof Uint8Array))throw new TypeError(Ih(t,"Uint8Array"));let o=parseInt(n.slice(1,4),10),s=await crypto.subtle.importKey("raw",t.subarray(o>>3),"AES-CBC",!1,["encrypt"]),a=await crypto.subtle.importKey("raw",t.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]),c=new Uint8Array(await crypto.subtle.encrypt({iv:r,name:"AES-CBC"},s,e)),u=Ss(i,r,c,b8(i.length<<3)),l=new Uint8Array((await crypto.subtle.sign("HMAC",a,u)).slice(0,o>>3));return{ciphertext:c,tag:l,iv:r}}async function dDe(n,e,t,r,i){let o;t instanceof Uint8Array?o=await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["encrypt"]):(Cs(t,n,"encrypt"),o=t);let s=new Uint8Array(await crypto.subtle.encrypt({additionalData:i,iv:r,name:"AES-GCM",tagLength:128},o,e)),a=s.slice(-16);return{ciphertext:s.slice(0,-16),tag:a,iv:r}}async function C8(n,e,t,r,i){if(!qu(t)&&!(t instanceof Uint8Array))throw new TypeError(Ih(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));switch(r?I8(n,r):r=Cte(n),n){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return t instanceof Uint8Array&&_y(t,parseInt(n.slice(-3),10)),lDe(n,e,t,r,i);case"A128GCM":case"A192GCM":case"A256GCM":return t instanceof Uint8Array&&_y(t,parseInt(n.slice(1,4),10)),dDe(n,e,t,r,i);default:throw new Zt("Unsupported JWE Content Encryption Algorithm")}}async function Kte(n,e,t,r){let i=n.slice(0,7),o=await C8(i,t,e,r,new Uint8Array);return{encryptedKey:o.ciphertext,iv:Xr(o.iv),tag:Xr(o.tag)}}async function Jte(n,e,t,r,i){let o=n.slice(0,7);return x8(o,e,t,r,i,new Uint8Array)}async function qte(n,e,t,r,i){switch(n){case"dir":{if(t!==void 0)throw new Ve("Encountered unexpected JWE Encrypted Key");return e}case"ECDH-ES":if(t!==void 0)throw new Ve("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(!Zo(r.epk))throw new Ve('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(X0(e),!S8(e))throw new Zt("ECDH with the provided key is not allowed or not supported by your javascript runtime");let o=await Hte(r.epk,n);X0(o);let s,a;if(r.apu!==void 0){if(typeof r.apu!="string")throw new Ve('JOSE Header "apu" (Agreement PartyUInfo) invalid');try{s=Zr(r.apu)}catch{throw new Ve("Failed to base64url decode the apu")}}if(r.apv!==void 0){if(typeof r.apv!="string")throw new Ve('JOSE Header "apv" (Agreement PartyVInfo) invalid');try{a=Zr(r.apv)}catch{throw new Ve("Failed to base64url decode the apv")}}let c=await v8(o,e,n==="ECDH-ES"?r.enc:n,n==="ECDH-ES"?yI(r.enc):parseInt(n.slice(-5,-2),10),s,a);if(n==="ECDH-ES")return c;if(t===void 0)throw new Ve("JWE Encrypted Key missing");return gI(n.slice(-6),c,t)}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");return X0(e),Ute(n,e,t)}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");if(typeof r.p2c!="number")throw new Ve('JOSE Header "p2c" (PBES2 Count) missing or invalid');let o=i?.maxPBES2Count||1e4;if(r.p2c>o)throw new Ve('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof r.p2s!="string")throw new Ve('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let s;try{s=Zr(r.p2s)}catch{throw new Ve("Failed to base64url decode the p2s")}return Mte(n,e,t,r.p2c,s)}case"A128KW":case"A192KW":case"A256KW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");return gI(n,e,t)}case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");if(typeof r.iv!="string")throw new Ve('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof r.tag!="string")throw new Ve('JOSE Header "tag" (Authentication Tag) missing or invalid');let o;try{o=Zr(r.iv)}catch{throw new Ve("Failed to base64url decode the iv")}let s;try{s=Zr(r.tag)}catch{throw new Ve("Failed to base64url decode the tag")}return Jte(n,e,t,o,s)}default:throw new Zt('Invalid or unsupported "alg" (JWE Algorithm) header value')}}function tw(n,e,t,r,i){if(i.crit!==void 0&&r?.crit===void 0)throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');if(!r||r.crit===void 0)return new Set;if(!Array.isArray(r.crit)||r.crit.length===0||r.crit.some(s=>typeof s!="string"||s.length===0))throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let o;t!==void 0?o=new Map([...Object.entries(t),...e.entries()]):o=e;for(let s of r.crit){if(!o.has(s))throw new Zt(`Extension Header Parameter "${s}" is not recognized`);if(i[s]===void 0)throw new n(`Extension Header Parameter "${s}" is missing`);if(o.get(s)&&r[s]===void 0)throw new n(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(r.crit)}function RF(n,e){if(e!==void 0&&(!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new TypeError(`"${n}" option must be an array of strings`);if(e)return new Set(e)}var wI=n=>Zo(n)&&typeof n.kty=="string",Vte=n=>n.kty!=="oct"&&(n.kty==="AKP"&&typeof n.priv=="string"||typeof n.d=="string"),Qte=n=>n.kty!=="oct"&&n.d===void 0&&n.priv===void 0,zte=n=>n.kty==="oct"&&typeof n.k=="string";var nw,Yte=async(n,e,t,r=!1)=>{nw||=new WeakMap;let i=nw.get(n);if(i?.[t])return i[t];let o=await ew({...e,alg:t});return r&&Object.freeze(n),i?i[t]=o:nw.set(n,{[t]:o}),o},hDe=(n,e)=>{nw||=new WeakMap;let t=nw.get(n);if(t?.[e])return t[e];let r=n.type==="public",i=!!r,o;if(n.asymmetricKeyType==="x25519"){switch(e){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}o=n.toCryptoKey(n.asymmetricKeyType,i,r?[]:["deriveBits"])}if(n.asymmetricKeyType==="ed25519"){if(e!=="EdDSA"&&e!=="Ed25519")throw new TypeError("given KeyObject instance cannot be used for this algorithm");o=n.toCryptoKey(n.asymmetricKeyType,i,[r?"verify":"sign"])}switch(n.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":{if(e!==n.asymmetricKeyType.toUpperCase())throw new TypeError("given KeyObject instance cannot be used for this algorithm");o=n.toCryptoKey(n.asymmetricKeyType,i,[r?"verify":"sign"])}}if(n.asymmetricKeyType==="rsa"){let s;switch(e){case"RSA-OAEP":s="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":s="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":s="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":s="SHA-512";break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}if(e.startsWith("RSA-OAEP"))return n.toCryptoKey({name:"RSA-OAEP",hash:s},i,r?["encrypt"]:["decrypt"]);o=n.toCryptoKey({name:e.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:s},i,[r?"verify":"sign"])}if(n.asymmetricKeyType==="ec"){let a=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(n.asymmetricKeyDetails?.namedCurve);if(!a)throw new TypeError("given KeyObject instance cannot be used for this algorithm");e==="ES256"&&a==="P-256"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e==="ES384"&&a==="P-384"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e==="ES512"&&a==="P-521"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e.startsWith("ECDH-ES")&&(o=n.toCryptoKey({name:"ECDH",namedCurve:a},i,r?[]:["deriveBits"]))}if(!o)throw new TypeError("given KeyObject instance cannot be used for this algorithm");return t?t[e]=o:nw.set(n,{[e]:o}),o};async function Ah(n,e){if(n instanceof Uint8Array||qu(n))return n;if(pI(n)){if(n.type==="secret")return n.export();if("toCryptoKey"in n&&typeof n.toCryptoKey=="function")try{return hDe(n,e)}catch(r){if(r instanceof TypeError)throw r}let t=n.export({format:"jwk"});return Yte(n,t,e)}if(wI(n))return n.k?Zr(n.k):Yte(n,n,e,!0);throw new Error("unreachable")}var rw=n=>n?.[Symbol.toStringTag],DF=(n,e,t)=>{if(e.use!==void 0){let r;switch(t){case"sign":case"verify":r="sig";break;case"encrypt":case"decrypt":r="enc";break}if(e.use!==r)throw new TypeError(`Invalid key for this operation, its "use" must be "${r}" when present`)}if(e.alg!==void 0&&e.alg!==n)throw new TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(e.key_ops)){let r;switch(!0){case(t==="sign"||t==="verify"):case n==="dir":case n.includes("CBC-HS"):r=t;break;case n.startsWith("PBES2"):r="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(n):!n.includes("GCM")&&n.endsWith("KW")?r=t==="encrypt"?"wrapKey":"unwrapKey":r=t;break;case(t==="encrypt"&&n.startsWith("RSA")):r="wrapKey";break;case t==="decrypt":r=n.startsWith("RSA")?"unwrapKey":"deriveBits";break}if(r&&e.key_ops?.includes?.(r)===!1)throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${r}" when present`)}return!0},pDe=(n,e,t)=>{if(!(e instanceof Uint8Array)){if(wI(e)){if(zte(e)&&DF(n,e,t))return;throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!vF(e))throw new TypeError(xF(n,e,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if(e.type!=="secret")throw new TypeError(`${rw(e)} instances for symmetric algorithms must be of type "secret"`)}},mDe=(n,e,t)=>{if(wI(e))switch(t){case"decrypt":case"sign":if(Vte(e)&&DF(n,e,t))return;throw new TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if(Qte(e)&&DF(n,e,t))return;throw new TypeError("JSON Web Key for this operation must be a public JWK")}if(!vF(e))throw new TypeError(xF(n,e,"CryptoKey","KeyObject","JSON Web Key"));if(e.type==="secret")throw new TypeError(`${rw(e)} instances for asymmetric algorithms must not be of type "secret"`);if(e.type==="public")switch(t){case"sign":throw new TypeError(`${rw(e)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw new TypeError(`${rw(e)} instances for asymmetric algorithm decryption must be of type "private"`)}if(e.type==="private")switch(t){case"verify":throw new TypeError(`${rw(e)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw new TypeError(`${rw(e)} instances for asymmetric algorithm encryption must be of type "public"`)}};function iw(n,e,t){switch(n.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":pDe(n,e,t);break;default:mDe(n,e,t)}}async function bI(n,e,t){if(!Zo(n))throw new Ve("Flattened JWE must be an object");if(n.protected===void 0&&n.header===void 0&&n.unprotected===void 0)throw new Ve("JOSE Header missing");if(n.iv!==void 0&&typeof n.iv!="string")throw new Ve("JWE Initialization Vector incorrect type");if(typeof n.ciphertext!="string")throw new Ve("JWE Ciphertext missing or incorrect type");if(n.tag!==void 0&&typeof n.tag!="string")throw new Ve("JWE Authentication Tag incorrect type");if(n.protected!==void 0&&typeof n.protected!="string")throw new Ve("JWE Protected Header incorrect type");if(n.encrypted_key!==void 0&&typeof n.encrypted_key!="string")throw new Ve("JWE Encrypted Key incorrect type");if(n.aad!==void 0&&typeof n.aad!="string")throw new Ve("JWE AAD incorrect type");if(n.header!==void 0&&!Zo(n.header))throw new Ve("JWE Shared Unprotected Header incorrect type");if(n.unprotected!==void 0&&!Zo(n.unprotected))throw new Ve("JWE Per-Recipient Unprotected Header incorrect type");let r;if(n.protected)try{let U=Zr(n.protected);r=JSON.parse(Z0.decode(U))}catch{throw new Ve("JWE Protected Header is invalid")}if(!$y(r,n.header,n.unprotected))throw new Ve("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let i={...r,...n.header,...n.unprotected};if(tw(Ve,new Map,t?.crit,r,i),i.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');let{alg:o,enc:s}=i;if(typeof o!="string"||!o)throw new Ve("missing JWE Algorithm (alg) in JWE Header");if(typeof s!="string"||!s)throw new Ve("missing JWE Encryption Algorithm (enc) in JWE Header");let a=t&&RF("keyManagementAlgorithms",t.keyManagementAlgorithms),c=t&&RF("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms);if(a&&!a.has(o)||!a&&o.startsWith("PBES2"))throw new hI('"alg" (Algorithm) Header Parameter value not allowed');if(c&&!c.has(s))throw new hI('"enc" (Encryption Algorithm) Header Parameter value not allowed');let u;if(n.encrypted_key!==void 0)try{u=Zr(n.encrypted_key)}catch{throw new Ve("Failed to base64url decode the encrypted_key")}let l=!1;typeof e=="function"&&(e=await e(r,n),l=!0),iw(o==="dir"?s:o,e,"decrypt");let d=await Ah(e,o),h;try{h=await qte(o,d,u,i,t)}catch(U){if(U instanceof TypeError||U instanceof Ve||U instanceof Zt)throw U;h=Vu(s)}let f,m;if(n.iv!==void 0)try{f=Zr(n.iv)}catch{throw new Ve("Failed to base64url decode the iv")}if(n.tag!==void 0)try{m=Zr(n.tag)}catch{throw new Ve("Failed to base64url decode the tag")}let w=n.protected!==void 0?Ka(n.protected):new Uint8Array,b;n.aad!==void 0?b=Ss(w,Ka("."),Ka(n.aad)):b=w;let S;try{S=Zr(n.ciphertext)}catch{throw new Ve("Failed to base64url decode the ciphertext")}let G={plaintext:await x8(s,h,S,f,m,b)};if(n.protected!==void 0&&(G.protectedHeader=r),n.aad!==void 0)try{G.additionalAuthenticatedData=Zr(n.aad)}catch{throw new Ve("Failed to base64url decode the aad")}return n.unprotected!==void 0&&(G.sharedUnprotectedHeader=n.unprotected),n.header!==void 0&&(G.unprotectedHeader=n.header),l?{...G,key:d}:G}async function TF(n,e,t){if(!Zo(n))throw new Ve("General JWE must be an object");if(!Array.isArray(n.recipients)||!n.recipients.every(Zo))throw new Ve("JWE Recipients missing or incorrect type");if(!n.recipients.length)throw new Ve("JWE Recipients has no members");for(let r of n.recipients)try{return await bI({aad:n.aad,ciphertext:n.ciphertext,encrypted_key:r.encrypted_key,header:r.header,iv:n.iv,protected:n.protected,tag:n.tag,unprotected:n.unprotected},e,t)}catch{}throw new bh}var L8=Symbol();async function jte(n){if(pI(n))if(n.type==="secret")n=n.export();else return n.export({format:"jwk"});if(n instanceof Uint8Array)return{kty:"oct",k:Xr(n)};if(!qu(n))throw new TypeError(Ih(n,"CryptoKey","KeyObject","Uint8Array"));if(!n.extractable)throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:e,key_ops:t,alg:r,use:i,...o}=await crypto.subtle.exportKey("jwk",n);return o.kty==="AKP"&&(o.alg=r),o}async function Wte(n){return jte(n)}async function R8(n,e,t,r,i={}){let o,s,a;switch(n){case"dir":{a=t;break}case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(X0(t),!S8(t))throw new Zt("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:c,apv:u}=i,l;i.epk?l=await Ah(i.epk,n):l=(await crypto.subtle.generateKey(t.algorithm,!0,["deriveBits"])).privateKey;let{x:d,y:h,crv:f,kty:m}=await Wte(l),w=await v8(t,l,n==="ECDH-ES"?e:n,n==="ECDH-ES"?yI(e):parseInt(n.slice(-5,-2),10),c,u);if(s={epk:{x:d,crv:f,kty:m}},m==="EC"&&(s.epk.y=h),c&&(s.apu=Xr(c)),u&&(s.apv=Xr(u)),n==="ECDH-ES"){a=w;break}a=r||Vu(e);let b=n.slice(-6);o=await mI(b,w,a);break}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{a=r||Vu(e),X0(t),o=await Nte(n,t,a);break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{a=r||Vu(e);let{p2c:c,p2s:u}=i;({encryptedKey:o,...s}=await kte(n,t,a,c,u));break}case"A128KW":case"A192KW":case"A256KW":{a=r||Vu(e),o=await mI(n,t,a);break}case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{a=r||Vu(e);let{iv:c}=i;({encryptedKey:o,...s}=await Kte(n,t,a,c));break}default:throw new Zt('Invalid or unsupported "alg" (JWE Algorithm) header value')}return{cek:a,encryptedKey:o,parameters:s}}var EI=class{#e;#t;#n;#r;#i;#o;#s;#a;constructor(e){if(!(e instanceof Uint8Array))throw new TypeError("plaintext must be an instance of Uint8Array");this.#e=e}setKeyManagementParameters(e){if(this.#a)throw new TypeError("setKeyManagementParameters can only be called once");return this.#a=e,this}setProtectedHeader(e){if(this.#t)throw new TypeError("setProtectedHeader can only be called once");return this.#t=e,this}setSharedUnprotectedHeader(e){if(this.#n)throw new TypeError("setSharedUnprotectedHeader can only be called once");return this.#n=e,this}setUnprotectedHeader(e){if(this.#r)throw new TypeError("setUnprotectedHeader can only be called once");return this.#r=e,this}setAdditionalAuthenticatedData(e){return this.#i=e,this}setContentEncryptionKey(e){if(this.#o)throw new TypeError("setContentEncryptionKey can only be called once");return this.#o=e,this}setInitializationVector(e){if(this.#s)throw new TypeError("setInitializationVector can only be called once");return this.#s=e,this}async encrypt(e,t){if(!this.#t&&!this.#r&&!this.#n)throw new Ve("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!$y(this.#t,this.#r,this.#n))throw new Ve("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let r={...this.#t,...this.#r,...this.#n};if(tw(Ve,new Map,t?.crit,this.#t,r),r.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');let{alg:i,enc:o}=r;if(typeof i!="string"||!i)throw new Ve('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof o!="string"||!o)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');let s;if(this.#o&&(i==="dir"||i==="ECDH-ES"))throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${i}`);iw(i==="dir"?o:i,e,"encrypt");let a;{let b,S=await Ah(e,i);({cek:a,encryptedKey:s,parameters:b}=await R8(i,o,S,this.#o,this.#a)),b&&(t&&L8 in t?this.#r?this.#r={...this.#r,...b}:this.setUnprotectedHeader(b):this.#t?this.#t={...this.#t,...b}:this.setProtectedHeader(b))}let c,u,l,d;if(this.#t?(u=Xr(JSON.stringify(this.#t)),l=Ka(u)):(u="",l=new Uint8Array),this.#i){d=Xr(this.#i);let b=Ka(d);c=Ss(l,Ka("."),b)}else c=l;let{ciphertext:h,tag:f,iv:m}=await C8(o,this.#e,a,this.#s,c),w={ciphertext:Xr(h)};return m&&(w.iv=Xr(m)),f&&(w.tag=Xr(f)),s&&(w.encrypted_key=Xr(s)),d&&(w.aad=d),this.#t&&(w.protected=u),this.#n&&(w.unprotected=this.#n),this.#r&&(w.header=this.#r),w}};var BF=class{#e;unprotectedHeader;keyManagementParameters;key;options;constructor(e,t,r){this.#e=e,this.key=t,this.options=r}setUnprotectedHeader(e){if(this.unprotectedHeader)throw new TypeError("setUnprotectedHeader can only be called once");return this.unprotectedHeader=e,this}setKeyManagementParameters(e){if(this.keyManagementParameters)throw new TypeError("setKeyManagementParameters can only be called once");return this.keyManagementParameters=e,this}addRecipient(...e){return this.#e.addRecipient(...e)}encrypt(...e){return this.#e.encrypt(...e)}done(){return this.#e}},II=class{#e;#t=[];#n;#r;#i;constructor(e){this.#e=e}addRecipient(e,t){let r=new BF(this,e,{crit:t?.crit});return this.#t.push(r),r}setProtectedHeader(e){if(this.#n)throw new TypeError("setProtectedHeader can only be called once");return this.#n=e,this}setSharedUnprotectedHeader(e){if(this.#r)throw new TypeError("setSharedUnprotectedHeader can only be called once");return this.#r=e,this}setAdditionalAuthenticatedData(e){return this.#i=e,this}async encrypt(){if(!this.#t.length)throw new Ve("at least one recipient must be added");if(this.#t.length===1){let[i]=this.#t,o=await new EI(this.#e).setAdditionalAuthenticatedData(this.#i).setProtectedHeader(this.#n).setSharedUnprotectedHeader(this.#r).setUnprotectedHeader(i.unprotectedHeader).encrypt(i.key,{...i.options}),s={ciphertext:o.ciphertext,iv:o.iv,recipients:[{}],tag:o.tag};return o.aad&&(s.aad=o.aad),o.protected&&(s.protected=o.protected),o.unprotected&&(s.unprotected=o.unprotected),o.encrypted_key&&(s.recipients[0].encrypted_key=o.encrypted_key),o.header&&(s.recipients[0].header=o.header),s}let e;for(let i=0;i<this.#t.length;i++){let o=this.#t[i];if(!$y(this.#n,this.#r,o.unprotectedHeader))throw new Ve("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let s={...this.#n,...this.#r,...o.unprotectedHeader},{alg:a}=s;if(typeof a!="string"||!a)throw new Ve('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(a==="dir"||a==="ECDH-ES")throw new Ve('"dir" and "ECDH-ES" alg may only be used with a single recipient');if(typeof s.enc!="string"||!s.enc)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(!e)e=s.enc;else if(e!==s.enc)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');if(tw(Ve,new Map,o.options.crit,this.#n,s),s.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.')}let t=Vu(e),r={ciphertext:"",recipients:[]};for(let i=0;i<this.#t.length;i++){let o=this.#t[i],s={};if(r.recipients.push(s),i===0){let d=await new EI(this.#e).setAdditionalAuthenticatedData(this.#i).setContentEncryptionKey(t).setProtectedHeader(this.#n).setSharedUnprotectedHeader(this.#r).setUnprotectedHeader(o.unprotectedHeader).setKeyManagementParameters(o.keyManagementParameters).encrypt(o.key,{...o.options,[L8]:!0});r.ciphertext=d.ciphertext,r.iv=d.iv,r.tag=d.tag,d.aad&&(r.aad=d.aad),d.protected&&(r.protected=d.protected),d.unprotected&&(r.unprotected=d.unprotected),s.encrypted_key=d.encrypted_key,d.header&&(s.header=d.header);continue}let a=o.unprotectedHeader?.alg||this.#n?.alg||this.#r?.alg;iw(a==="dir"?e:a,o.key,"encrypt");let c=await Ah(o.key,a),{encryptedKey:u,parameters:l}=await R8(a,e,c,t,o.keyManagementParameters);s.encrypted_key=Xr(u),(o.unprotectedHeader||l)&&(s.header={...o.unprotectedHeader,...l})}return r}};function PF(n){let e;if(typeof n=="string"){let t=n.split(".");(t.length===3||t.length===5)&&([e]=t)}else if(typeof n=="object"&&n)if("protected"in n)e=n.protected;else throw new TypeError("Token does not contain a Protected Header");try{if(typeof e!="string"||!e)throw new Error;let t=JSON.parse(Z0.decode(Zr(e)));if(!Zo(t))throw new Error;return t}catch{throw new TypeError("Invalid Token or Protected Header formatting")}}var D8=class{constructor(e){this.resolvePrivateKeyByKid=e}async encrypt(e,t){let{enc:r,typ:i,recipients:o}=t,s=new II(e).setProtectedHeader({enc:r,typ:i});return o.forEach(({recipientJWK:c,alg:u,kid:l})=>{s.addRecipient(c).setUnprotectedHeader({alg:u,kid:l})}),await s.encrypt()}async decrypt(e){let t=(r,i)=>{let o=i.header?.kid||r&&r.kid;if(!o)throw new Error("kid is required");return this.resolvePrivateKeyByKid(o)};if(Object.prototype.hasOwnProperty.call(e,"encrypted_key")){let r=e;return r.header=this.removeDuplicates(PF(r),r.header||{}),bI(e,t)}return TF(e,t)}removeDuplicates=(e,t)=>{let r={...t};for(let[i,o]of Object.entries(e))r[i]===o&&delete r[i];return r}};var T8=class{constructor(e){this.kms=e}resolvePrivateKeyByKid=async e=>{let[,t]=e.split("#");if(!t)throw new Error("Missing key identifier");let[r]=t.split(":");if(!r)throw new Error("Missing key type in alias for default key resolver");let i=await this.kms.getKeyProvider(r)?.getPkStore();if(!i)throw new Error(`Key provider not found for ${r}`);try{return JSON.parse(await i.get({alias:t}))}catch{throw new Error(`Key not found for ${t}`)}}};var MF={};Rr(MF,{DeviceNotificationStatus:()=>_te,NotificationServiceType:()=>Zte,NotificationStatus:()=>Xte,PushNotifier:()=>kF});var Zte=(e=>(e.Push="push-notification",e))(Zte||{}),Xte=(t=>(t.Success="success",t.Failed="failed",t))(Xte||{});var _te=(r=>(r.Success="success",r.Rejected="rejected",r.Failed="failed",r))(_te||{}),gDe={type:"push-notification",send:async({url:n,pushService:e,message:t})=>{try{let r=new Request(n,{method:"POST",body:JSON.stringify({metadata:e.metadata,message:t})}),i=await fetch(r);if(i.status!==200)throw new Error(`could not send push notification, return status ${i.status}`);let o=await i.json();return{status:"success",devices:o}}catch(r){return{status:"failed",error:r.toString()}}}},kF=class{constructor(e=gDe){this._publisher=e;if(e.type!=="push-notification")throw new Error(`PushNotifier: publisher type ${e.type} is not supported`)}async notify(e,t){let r=(t.didDocument.service??[]).find(s=>s.type==="push-notification");if(!r)throw new Error("no push service in did document");if(!r.metadata?.devices?.length)throw new Error("no devices in push service");let o=[r.serviceEndpoint??[]].flat().reduce((s,a)=>typeof a=="string"?[...s,a]:typeof a.uri=="string"?[...s,a.uri]:s,[]).map(async s=>this._publisher.send({url:s,pushService:r,message:e}));return await Promise.all(o)}};var xd={url:"http://localhost:8545",defaultGasLimit:6e5,minGasPrice:"0",maxGasPrice:"100000000000",confirmationBlockCount:5,confirmationTimeout:6e5,contractAddress:"",receiptTimeout:6e5,rpcResponseTimeout:5e3,waitReceiptCycleTime:3e4,waitBlockCycleTime:3e3},$te={state:0n,replacedByState:0n,createdAtTimestamp:0n,replacedAtTimestamp:0n,createdAtBlock:0n,replacedAtBlock:0n},uI=class{constructor(e,t){this.ethConfig=e;let r=Array.isArray(e)?e[0]:e;this.provider=new jt(r.url),this.stateContract=new Ln(r.contractAddress,aM,this.provider),this._transactionService=new Xs(this.getRpcProvider()),this._latestStateCacheOptions={ttl:t?.latestStateCacheOptions?.ttl??jr.DEFAULT_PROOF_VERIFY_DELAY/2,maxSize:t?.latestStateCacheOptions?.maxSize??lg},this._stateCacheOptions={notReplacedTtl:t?.stateCacheOptions?.notReplacedTtl??jr.DEFAULT_PROOF_VERIFY_DELAY/2,replacedTtl:t?.stateCacheOptions?.replacedTtl??jr.DEFAULT_PROOF_VERIFY_DELAY,maxSize:t?.stateCacheOptions?.maxSize??lg},this._rootCacheOptions={replacedTtl:t?.rootCacheOptions?.replacedTtl??jr.DEFAULT_AUTH_VERIFY_DELAY,notReplacedTtl:t?.rootCacheOptions?.notReplacedTtl??jr.DEFAULT_AUTH_VERIFY_DELAY/2,maxSize:t?.rootCacheOptions?.maxSize??lg},this._gistProofCacheOptions={ttl:jr.DEFAULT_AUTH_VERIFY_DELAY/2,maxSize:t?.gistProofCacheOptions?.maxSize??lg},this._latestStateResolveCache=t?.latestStateCacheOptions?.cache??lh({maxSize:this._latestStateCacheOptions.maxSize,ttl:this._latestStateCacheOptions.ttl}),this._stateResolveCache=t?.stateCacheOptions?.cache??lh({maxSize:this._stateCacheOptions.maxSize,ttl:this._stateCacheOptions.replacedTtl}),this._rootResolveCache=t?.rootCacheOptions?.cache??lh({maxSize:this._rootCacheOptions.maxSize,ttl:this._rootCacheOptions.replacedTtl}),this._gistProofResolveCache=t?.gistProofCacheOptions?.cache??lh({maxSize:this._gistProofCacheOptions.maxSize,ttl:this._gistProofCacheOptions.ttl}),this._disableCache=t?.disableCache??!1}stateContract;provider;_transactionService;_latestStateResolveCache;_stateResolveCache;_rootResolveCache;_gistProofResolveCache;_latestStateCacheOptions;_stateCacheOptions;_rootCacheOptions;_gistProofCacheOptions;_disableCache=!1;async getLatestStateById(e){let t=this.getLatestStateCacheKey(e);if(!this._disableCache){let s=await this._latestStateResolveCache?.get(t);if(s){if(s.state===0n&&s.createdAtTimestamp===0n)throw new Error(Ge.ERRORS.IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR);return s}}let{stateContract:r}=this.getStateContractAndProviderForId(e),i=[];try{i=await r.getStateInfoById(e)}catch(s){throw z0(s)&&!this._disableCache&&await this._latestStateResolveCache?.set(t,{id:e,...$te},this._latestStateCacheOptions.ttl),s}let o={id:BigInt(i[0]),state:BigInt(i[1]),replacedByState:BigInt(i[2]),createdAtTimestamp:BigInt(i[3]),replacedAtTimestamp:BigInt(i[4]),createdAtBlock:BigInt(i[5]),replacedAtBlock:BigInt(i[6])};return!this._disableCache&&await this._latestStateResolveCache?.set(t,o,this._latestStateCacheOptions.ttl),o}async getStateInfoByIdAndState(e,t){let r=this.getStateCacheKey(e,t);if(!this._disableCache){let a=await this._stateResolveCache?.get(r);if(a)return a}let{stateContract:i}=this.getStateContractAndProviderForId(e),o;try{let a=await i.getStateInfoByIdAndState(e,t);o={id:BigInt(a[0]),state:BigInt(a[1]),replacedByState:BigInt(a[2]),createdAtTimestamp:BigInt(a[3]),replacedAtTimestamp:BigInt(a[4]),createdAtBlock:BigInt(a[5]),replacedAtBlock:BigInt(a[6])}}catch(a){if(!sF(a))throw a;if(!xx(Xe.fromBigInt(e),t))throw new Error(`State ${t} for identity ${e} is not genesis and not registered in the smart contract`);o={id:e,...$te,state:t}}let s=o.replacedAtTimestamp===0n?this._stateCacheOptions.notReplacedTtl:this._stateCacheOptions.replacedTtl;return!this._disableCache&&await this._stateResolveCache?.set(r,o,s),o}async publishState(e,t){let r=new vE;r.pubSignalsUnmarshal(ke.encode(JSON.stringify(e.pub_signals)));let{userId:i,oldUserState:o,newUserState:s,isOldStateGenesis:a}=r,{stateContract:c,provider:u}=this.getStateContractAndProviderForId(i.bigInt()),l=c.connect(t),d=M0(e.proof),h=[i.bigInt().toString(),o.bigInt().toString(),s.bigInt().toString(),a,d.a,d.b,d.c],f=await u.getFeeData(),m=xd.maxFeePerGas?BigInt(xd.maxFeePerGas):f.maxFeePerGas,w=xd.maxPriorityFeePerGas?BigInt(xd.maxPriorityFeePerGas):f.maxPriorityFeePerGas,b=await l.transitState.estimateGas(...h),S=await l.transitState.populateTransaction(...h),R={to:S.to,data:S.data,gasLimit:b,maxFeePerGas:m,maxPriorityFeePerGas:w},{txnHash:G}=await this._transactionService.sendTransactionRequest(t,R);return await this._latestStateResolveCache?.delete(this.getLatestStateCacheKey(i.bigInt())),G}async publishStateGeneric(e,t){let{userId:r,oldUserState:i,newUserState:o,isOldStateGenesis:s,methodId:a,methodParams:c}=t,{stateContract:u,provider:l}=this.getStateContractAndProviderForId(r.bigInt()),d=u.connect(e),h=await l.getFeeData(),f=xd.maxFeePerGas?BigInt(xd.maxFeePerGas):h.maxFeePerGas,m=xd.maxPriorityFeePerGas?BigInt(xd.maxPriorityFeePerGas):h.maxPriorityFeePerGas,w=[r.bigInt().toString(),i.bigInt().toString(),o.bigInt().toString(),s,a,c],b=await d.transitStateGeneric.estimateGas(...w),S=await d.transitStateGeneric.populateTransaction(...w),R={to:S.to,data:S.data,gasLimit:b,maxFeePerGas:f,maxPriorityFeePerGas:m},{txnHash:G}=await this._transactionService.sendTransactionRequest(e,R);return await this._latestStateResolveCache?.delete(this.getLatestStateCacheKey(r.bigInt())),G}async getGISTProof(e){let t=this.getGistProofCacheKey(e);if(!this._disableCache){let s=await this._gistProofResolveCache?.get(t);if(s)return s}let{stateContract:r}=this.getStateContractAndProviderForId(e),i=await r.getGISTProof(e),o={root:BigInt(i.root.toString()),existence:i.existence,siblings:i.siblings?.map(s=>BigInt(s.toString())),index:BigInt(i.index.toString()),value:BigInt(i.value.toString()),auxExistence:i.auxExistence,auxIndex:BigInt(i.auxIndex.toString()),auxValue:BigInt(i.auxValue.toString())};return!this._disableCache&&await this._gistProofResolveCache?.set(t,o,this._gistProofCacheOptions.ttl),o}async getGISTRootInfo(e,t){let r=Xe.fromBigInt(t),i=tm(ve.blockchainFromId(r),ve.networkIdFromId(r)),o=this.getRootCacheKey(i,e);if(!this._disableCache){let l=await this._rootResolveCache?.get(o);if(l)return l}let{stateContract:s}=this.getStateContractAndProviderForId(t),a=await s.getGISTRootInfo(e),c={root:BigInt(a.root.toString()),replacedByRoot:BigInt(a.replacedByRoot.toString()),createdAtTimestamp:BigInt(a.createdAtTimestamp.toString()),replacedAtTimestamp:BigInt(a.replacedAtTimestamp.toString()),createdAtBlock:BigInt(a.createdAtBlock.toString()),replacedAtBlock:BigInt(a.replacedAtBlock.toString())},u=c.replacedAtTimestamp==0n?this._rootCacheOptions.notReplacedTtl:this._rootCacheOptions.replacedTtl;return!this._disableCache&&await this._rootResolveCache?.set(o,c,u),c}getRpcProvider(){return this.provider}enableCache(){this._disableCache=!1}disableCache(){this._disableCache=!0}getStateContractAndProviderForId(e){let t=Xe.fromBigInt(e),r=tm(ve.blockchainFromId(t),ve.networkIdFromId(t)),i=this.networkByChainId(r),o=new jt(i.url);return{stateContract:new Ln(i.contractAddress,aM,o),provider:o}}networkByChainId(e){let r=(Array.isArray(this.ethConfig)?this.ethConfig:[this.ethConfig]).find(i=>i.chainId===e);if(!r)throw new Error(`chainId "${e}" not supported`);return r}getGistProofCacheKey(e){return`gist:${e.toString()}`}getLatestStateCacheKey(e){return`latest-state:${e.toString()}`}getStateCacheKey(e,t){return`state:${e.toString()}-${t.toString()}`}getRootCacheKey(e,t){return`root:${e.toString()}-${t.toString()}`}};var OF=[{inputs:[],name:"InvalidInitialization",type:"error"},{inputs:[{internalType:"string",name:"message",type:"string"},{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256",name:"linkID",type:"uint256"},{internalType:"uint64",name:"requestIdToCompare",type:"uint64"},{internalType:"uint256",name:"linkIdToCompare",type:"uint256"}],name:"LinkedProofError",type:"error"},{inputs:[],name:"NotInitializing",type:"error"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"OwnableInvalidOwner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"OwnableUnauthorizedAccount",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"version",type:"uint64"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"requestId",type:"uint64"},{indexed:!0,internalType:"address",name:"requestOwner",type:"address"},{indexed:!1,internalType:"string",name:"metadata",type:"string"},{indexed:!1,internalType:"address",name:"validator",type:"address"},{indexed:!1,internalType:"bytes",name:"data",type:"bytes"}],name:"ZKPRequestSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"requestId",type:"uint64"},{indexed:!0,internalType:"address",name:"caller",type:"address"}],name:"ZKPResponseSubmitted",type:"event"},{inputs:[],name:"REQUESTS_RETURN_LIMIT",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"acceptOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"addValidatorToWhitelist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"disableZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"enableZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getProofStatus",outputs:[{components:[{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"uint256",name:"blockTimestamp",type:"uint256"}],internalType:"struct IZKPVerifier.ProofStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"string",name:"key",type:"string"}],name:"getProofStorageField",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getRequestOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getZKPRequest",outputs:[{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest",name:"zkpRequest",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"length",type:"uint256"}],name:"getZKPRequests",outputs:[{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getZKPRequestsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IStateCrossChain",name:"stateCrossChain",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"}],name:"isProofVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"isWhitelistedValidator",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"isZKPRequestEnabled",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pendingOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"removeValidatorFromWhitelist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"requestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"address",name:"requestOwner",type:"address"}],name:"setRequestOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest",name:"request",type:"tuple"}],name:"setZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256[]",name:"inputs",type:"uint256[]"},{internalType:"uint256[2]",name:"a",type:"uint256[2]"},{internalType:"uint256[2][2]",name:"b",type:"uint256[2][2]"},{internalType:"uint256[2]",name:"c",type:"uint256[2]"}],name:"submitZKPResponse",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"bytes",name:"zkProof",type:"bytes"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ZKPResponse[]",name:"responses",type:"tuple[]"},{internalType:"bytes",name:"crossChainProof",type:"bytes"}],name:"submitZKPResponseV2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64[]",name:"requestIds",type:"uint64[]"}],name:"verifyLinkedProofs",outputs:[],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256[]",name:"inputs",type:"uint256[]"},{internalType:"uint256[2]",name:"a",type:"uint256[2]"},{internalType:"uint256[2][2]",name:"b",type:"uint256[2][2]"},{internalType:"uint256[2]",name:"c",type:"uint256[2]"},{internalType:"address",name:"sender",type:"address"}],name:"verifyZKPResponse",outputs:[{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"inputValue",type:"uint256"}],internalType:"struct ICircuitValidator.KeyToInputValue[]",name:"",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"}];var FF=[{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"address",name:"userAddress",type:"address"}],name:"areMultiRequestProofsVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"groupID",type:"uint256"}],name:"getGroupedRequests",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.RequestInfo[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getGroupsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"}],name:"getMultiRequest",outputs:[{components:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"uint256[]",name:"requestIds",type:"uint256[]"},{internalType:"uint256[]",name:"groupIds",type:"uint256[]"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.MultiRequest",name:"multiRequest",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"address",name:"userAddress",type:"address"}],name:"getMultiRequestProofsStatus",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"timestamp",type:"uint256"}],internalType:"struct IVerifier.RequestProofStatus[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"}],name:"getRequest",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.RequestInfo",name:"request",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"requestId",type:"uint256"}],name:"getRequestProofStatus",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"timestamp",type:"uint256"}],internalType:"struct IVerifier.RequestProofStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRequestsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"address",name:"sender",type:"address"},{internalType:"string",name:"responseFieldName",type:"string"}],name:"getResponseFieldValue",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"address",name:"sender",type:"address"}],name:"getResponseFields",outputs:[{components:[{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct IRequestValidator.ResponseField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"groupId",type:"uint256"}],name:"groupIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"requestId",type:"uint256"}],name:"isRequestProofVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"}],name:"multiRequestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"}],name:"requestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"string",name:"authMethod",type:"string"},{internalType:"contract IAuthValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"}],internalType:"struct IVerifier.AuthMethod",name:"authMethod",type:"tuple"}],name:"setAuthMethod",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"uint256[]",name:"requestIds",type:"uint256[]"},{internalType:"uint256[]",name:"groupIds",type:"uint256[]"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.MultiRequest",name:"multiRequest",type:"tuple"}],name:"setMultiRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.Request[]",name:"requests",type:"tuple[]"}],name:"setRequests",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"string",name:"authMethod",type:"string"},{internalType:"bytes",name:"proof",type:"bytes"}],internalType:"struct IVerifier.AuthResponse",name:"authResponse",type:"tuple"},{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bytes",name:"proof",type:"bytes"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.Response[]",name:"responses",type:"tuple[]"},{internalType:"bytes",name:"crossChainProofs",type:"bytes"}],name:"submitResponse",outputs:[],stateMutability:"nonpayable",type:"function"}];var NF=10000000n,ene=(r=>(r.SubmitZKPResponseV1="b68967e2",r.SubmitZKPResponseV2="ade09fcd",r.SubmitResponse="06c86a91",r))(ene||{}),tne=function(n){return[{authMethod:n.authProof.raw.authMethod,proof:n.authProof.encoded},n.proofs.map(e=>({requestId:e.requestId,proof:e.encoded,metadata:e.metadata})),n.crossChainProof.encoded]},UF=class n{constructor(e,t){this._configs=e;this._opts=t}static _supportedCircuits=["authV2","authV3","authV3-8-32","credentialAtomicQueryMTPV2OnChain","credentialAtomicQuerySigV2OnChain","credentialAtomicQueryV3OnChain-beta.1","credentialAtomicQueryV3OnChain"];static async prepareTxArgsSubmitV1(e,t){if(e.method_id.replace("0x","")!=="b68967e2")throw new Error("prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0xb68967e2' is supported.");let r=t.id,i=t.pub_signals,o=M0(t.proof);return[r,i,o.a,o.b,o.c]}async prepareTxArgsSubmitV1(e,t){return n.prepareTxArgsSubmitV1(e,t)}async submitZKPResponse(e,t,r){let i=this._configs.find(d=>d.chainId==t.chain_id);if(!i)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="b68967e2")throw new Error("submitZKPResponse function doesn't implement requested method id. Only '0xb68967e2' is supported.");let o=new jt(i.url,i.chainId);e=e.connect(o);let s=new Map,a=await o.getFeeData(),c=i.maxFeePerGas?BigInt(i.maxFeePerGas):a.maxFeePerGas,u=i.maxPriorityFeePerGas?BigInt(i.maxPriorityFeePerGas):a.maxPriorityFeePerGas,l=new Ln(t.contract_address,OF);for(let d of r){let h=await this.prepareTxArgsSubmitV1(t,d),f=await l.submitZKPResponse.populateTransaction(...h),m={to:t.contract_address,data:f.data,maxFeePerGas:c,maxPriorityFeePerGas:u},w;try{w=await e.estimateGas(m)}catch{w=NF}m.gasLimit=w;let b=new Xs(o),{txnHash:S}=await b.sendTransactionRequest(e,m);s.set(S,d)}return s}async submitZKPResponseV2(e,t,r){let i=this._configs.find(b=>b.chainId==t.chain_id);if(!i)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="ade09fcd")throw new Error("submitZKPResponseV2 function doesn't implement requested method id. Only '0xade09fcd' is supported.");if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");let o=new jt(i.url,i.chainId);e=e.connect(o);let s=await this.prepareTxArgsSubmitV2(t,r),a=await o.getFeeData(),c=i.maxFeePerGas?BigInt(i.maxFeePerGas):a.maxFeePerGas,u=i.maxPriorityFeePerGas?BigInt(i.maxPriorityFeePerGas):a.maxPriorityFeePerGas,d=await new Ln(t.contract_address,OF).submitZKPResponseV2.populateTransaction(...s),h={to:t.contract_address,data:d.data,maxFeePerGas:c,maxPriorityFeePerGas:u},f;try{f=await e.estimateGas(h)}catch{f=NF}h.gasLimit=f;let m=new Xs(o),{txnHash:w}=await m.sendTransactionRequest(e,h);return new Map().set(w,r)}async submitResponse(e,t,r,i){let o=this._configs.find(S=>S.chainId==t.chain_id);if(!o)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="06c86a91")throw new Error("submitResponse function doesn't implement requested method id. Only '0x06c86a91' is supported.");if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");let s=new jt(o.url,o.chainId);e=e.connect(s);let a=await this.prepareTxArgsSubmit(t,r,i),c=await s.getFeeData(),u=o.maxFeePerGas?BigInt(o.maxFeePerGas):c.maxFeePerGas,l=o.maxPriorityFeePerGas?BigInt(o.maxPriorityFeePerGas):c.maxPriorityFeePerGas,h=await new Ln(t.contract_address,FF).submitResponse.populateTransaction(...a.txDataArgs),f={to:t.contract_address,data:h.data,maxFeePerGas:u,maxPriorityFeePerGas:l},m;try{m=await e.estimateGas(f)}catch{m=NF}f.gasLimit=m;let w=new Xs(s),{txnHash:b}=await w.sendTransactionRequest(e,f);return new Map().set(b,{authProof:a.result.authProof.raw,crossChainProof:a.result.crossChainProof.raw,responses:a.result.proofs.map(S=>S.proof)})}static async prepareTxArgsSubmit(e,t,r,i){if(t.method_id.replace("0x","")!=="06c86a91")throw new Error("submit cross chain doesn't implement requested method id. Only '0x06c86a91' is supported.");let o=[],s=[],a=[],c="0x",u="";switch(i.authMethod){case"authV2":case"authV3":case"authV3-8-32":{let f=M0(i.zkp.proof);u=wC(i.zkp.pub_signals,f.a,f.b,f.c);break}case"ethIdentity":{u=nne(i.userDid);break}default:throw new Error("auth proof must use method authV2, authV3, authV3-8-32 or ethIdentity")}for(let f of r){this.checkSupportedCircuit(f.circuitId);let{requestId:m,zkProofEncoded:w,metadata:b}=aI(f);a.push({proof:f,requestId:m,encoded:w,metadata:b})}let l=r.map(f=>({circuitId:f.circuitId,pub_signals:f.pub_signals}));["authV2","authV3","authV3-8-32"].includes(i.authMethod)&&l.push({circuitId:i.zkp.circuitId,pub_signals:i.zkp.pub_signals});for(let f of l){let{gistUpdateResolutions:m,stateUpdateResolutions:w}=this.getUpdateResolutions(e,t.chain_id,f.circuitId,f.pub_signals);m.length>0&&o.push(...await Promise.all(m)),w.length>0&&s.push(...await Promise.all(w))}let d=o.length||s.length?this.packCrossChainProofs(o,s):c,h={authProof:{raw:i,encoded:u},proofs:a,crossChainProof:{raw:{globalStateProofs:o||[],identityStateProofs:s||[]},encoded:d}};return{result:h,txDataArgs:tne(h)}}async prepareTxArgsSubmit(e,t,r){if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");return n.prepareTxArgsSubmit(this._opts.didResolverUrl,e,t,r)}static checkSupportedCircuit(e){if(!iM(this._supportedCircuits).includes(e))throw new Error(`Circuit ${e} not supported by OnChainZKPVerifier`)}static getCrossChainResolvers(e,t,r,i){return[...new Set(e.map(o=>JSON.stringify({id:o.id.string(),[r]:r==="gist"?o.root?.string():o.state?.string()})))].reduce((o,s)=>{let a=JSON.parse(s),c=Xe.fromString(a.id),u=lw(ve.parseFromId(c));if(t===u)return o;let l=this.resolveDidDocumentEip712MessageAndSignature(ve.parseFromId(Xe.fromString(a.id)),i,{[r]:be.fromString(a[r])});return[...o,l]},[])}static async prepareTxArgsSubmitV2(e,t,r){if(t.method_id.replace("0x","")!=="ade09fcd")throw new Error("submit cross chain doesn't implement requested method id. Only '0xade09fcd' is supported.");let i=[],o=[],s=[],a="0x";for(let u of r){this.checkSupportedCircuit(u.circuitId);let{requestId:l,zkProofEncoded:d,metadata:h}=aI(u);s.push({requestId:l,zkProof:d,data:h});let{gistUpdateResolutions:f,stateUpdateResolutions:m}=this.getUpdateResolutions(e,t.chain_id,u.circuitId,u.pub_signals);f.length>0&&i.push(...await Promise.all(f)),m.length>0&&o.push(...await Promise.all(m))}let c=i.length||o.length?this.packCrossChainProofs(i,o):a;return[s,c]}async prepareTxArgsSubmitV2(e,t){if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");return n.prepareTxArgsSubmitV2(this._opts.didResolverUrl,e,t)}static getUpdateResolutions(e,t,r,i){let o=this.getOnChainGistRootStatePubSignals(r,i),s=this.getCrossChainResolvers(o.gists,t,"gist",e),a=this.getCrossChainResolvers(o.states,t,"state",e);return{gistUpdateResolutions:s,stateUpdateResolutions:a}}static packCrossChainProofs(e,t){let r=[];for(let i of e)r.push({proofType:"globalStateProof",proof:this.packGlobalStateMsg(i)});for(let i of t)r.push({proofType:"stateProof",proof:this.packIdentityStateMsg(i)});return new mn.AbiCoder().encode(["tuple(string proofType,bytes proof)[]"],[r])}static packGlobalStateMsg(e){return new mn.AbiCoder().encode(["tuple(tuple(uint256 timestamp,bytes2 idType,uint256 root,uint256 replacedAtTimestamp) globalStateMsg,bytes signature,)"],[e])}static packIdentityStateMsg(e){return new mn.AbiCoder().encode(["tuple(tuple(uint256 timestamp,uint256 id,uint256 state,uint256 replacedAtTimestamp) idStateMsg,bytes signature,)"],[e])}static getOnChainGistRootStatePubSignals(e,t){let r=sM(e);if(!r||!r.unmarshaller)throw new Error(`Circuit ${e} not supported by OnChainZKPVerifier`);let i=r.unmarshaller,o=new i(r.opts),s=ke.encode(JSON.stringify(t)),a=o.pubSignalsUnmarshal(s);if(a.getStatesInfo===void 0)throw new Error(`Public signals unmarshaller for circuit ${e} does not support getStatesInfo method`);return a.getStatesInfo()}static async resolveDidDocumentEip712MessageAndSignature(e,t,r){let i=await yp(e,t,{...r,signature:"EthereumEip712Signature2021"});if(!i.didResolutionMetadata.proof?.length)throw new Error("No proof found in resolved DID document");let o=i.didResolutionMetadata.proof[0].eip712.message,s=i.didResolutionMetadata.proof[0].proofValue;return r?.gist&&!r.state?{globalStateMsg:{timestamp:o.timestamp,idType:o.idType,root:o.root,replacedAtTimestamp:o.replacedAtTimestamp},signature:s}:{idStateMsg:{timestamp:o.timestamp,id:o.id,state:o.state,replacedAtTimestamp:o.replacedAtTimestamp},signature:s}}},nne=n=>`0x${Br(It.intToBytes(ve.idFromDID(n).bigInt()))}`;var GF=[{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"},{internalType:"uint256",name:"_credentialId",type:"uint256"}],name:"getCredential",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"string[]",name:"context",type:"string[]"},{internalType:"string",name:"_type",type:"string"},{internalType:"uint64",name:"issuanceDate",type:"uint64"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.CredentialSchema",name:"credentialSchema",type:"tuple"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.DisplayMethod",name:"displayMethod",type:"tuple"}],internalType:"struct INonMerklizedIssuer.CredentialData",name:"",type:"tuple"},{internalType:"uint256[8]",name:"",type:"uint256[8]"},{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct INonMerklizedIssuer.SubjectField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCredentialAdapterVersion",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"}],name:"getUserCredentialIds",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"}];var HF=[{inputs:[],name:"CREDENTIAL_ADAPTER_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"}],name:"getClaimProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getClaimProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"}],name:"getClaimProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getClaimsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"},{internalType:"uint256",name:"_credentialId",type:"uint256"}],name:"getCredential",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"string[]",name:"context",type:"string[]"},{internalType:"string",name:"_type",type:"string"},{internalType:"uint64",name:"issuanceDate",type:"uint64"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.CredentialSchema",name:"credentialSchema",type:"tuple"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.DisplayMethod",name:"displayMethod",type:"tuple"}],internalType:"struct INonMerklizedIssuer.CredentialData",name:"",type:"tuple"},{internalType:"uint256[8]",name:"",type:"uint256[8]"},{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct INonMerklizedIssuer.SubjectField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCredentialAdapterVersion",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"},{inputs:[],name:"getId",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getIsOldStateGenesis",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedClaimsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedRevocationsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedRootsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedState",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"}],name:"getRevocationProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getRevocationProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"}],name:"getRevocationProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatus",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatusByIdAndState",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRevocationsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"rootsTreeRoot",type:"uint256"}],name:"getRootProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getRootProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"rootsTreeRoot",type:"uint256"}],name:"getRootProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"state",type:"uint256"}],name:"getRootsByState",outputs:[{components:[{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.Roots",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRootsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSmtDepth",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"}],name:"getUserCredentialIds",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"_stateContractAddr",type:"address"},{internalType:"bytes2",name:"idType",type:"bytes2"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}],ow=class{static abi=HF;static createInterface(){return new dc(HF)}static connect(e,t){return new Ln(e,HF,t)}};var AI=class{_contract;_contractAddress;_chainId;_issuerDid;_merklizationOptions;constructor(e,t,r){if(!e.chainId)throw new Error("Chain ID is required");this._chainId=e.chainId,this._contractAddress=mn.getAddress(mn.hexlify(Xe.ethAddressFromId(ve.idFromDID(t)))),this._contract=ow.connect(this._contractAddress,new mn.JsonRpcProvider(e.url)),this._issuerDid=t,this._merklizationOptions=r?.merklizationOptions}async isInterfaceSupported(){let e=[{name:"Interface detection ERC-165",value:"0x01ffc9a7"},{name:"Interface non-merklized issuer",value:"0x58874949"},{name:"Interface get credential",value:"0x5d1ca631"}],r=(await Promise.all(e.map(async i=>await this._contract.supportsInterface(i.value)?null:i.name))).filter(i=>i!==null);if(r.length>0)throw new Error(`Unsupported interfaces: ${r.join(", ")}`)}async getCredential(e,t){let[r,i,o]=await this._contract.getCredential(e.bigInt(),t);return{credentialData:r,coreClaimBigInts:i,credentialSubjectFields:o}}async getUserCredentialsIds(e){return this._contract.getUserCredentialIds(e.bigInt())}async convertOnChainInfoToW3CCredential(e,t,r){let i=new Ir().unMarshalJson(JSON.stringify(t.map(u=>u.toString()))),o=await this.convertCredentialSubject(i,e.context,e._type,r),s={id:this.credentialId(e.id),credentialSchema:e.credentialSchema.id,type:e._type,credentialSubject:o,expiration:i.getExpirationDate()?.getTime(),displayMethod:this.convertDisplayMethod(e.displayMethod),context:e.context,revocationOpts:{id:this._contractAddress,nonce:Number(i.getRevocationNonce()),type:"Iden3OnchainSparseMerkleTreeProof2023"},issuanceDate:ra(Number(e.issuanceDate)).getTime()},a=await this.existenceProof(i),c=Er.fromCredentialRequest(this._issuerDid,s);return c.proof=[a],c}credentialId(e){return`urn:iden3:onchain:${this._chainId}:${this._contractAddress}:${e}`}async convertCredentialSubject(e,t,r,i){let o=JSON.stringify({"@context":t}),s={};for(let u of i){let l=await Hr.newTypeFromContext(o,`${r}.${u.key}`,this._merklizationOptions);switch(l){case"http://www.w3.org/2001/XMLSchema#boolean":{switch(u.rawValue.toString()){case"18586133768512220936620570745912940619677854269274689475585506675881198879027":s[u.key]=!0;break;case"19014214495641488759237505126948346942972912379615652741039992445865937985820":s[u.key]=!1;break}break}case("http://www.w3.org/2001/XMLSchema#nonNegativeInteger","http://www.w3.org/2001/XMLSchema#nonPositiveInteger","http://www.w3.org/2001/XMLSchema#negativeInteger","http://www.w3.org/2001/XMLSchema#positiveInteger"):{s[u.key]=u.value.toString();break}case"http://www.w3.org/2001/XMLSchema#integer":{s[u.key]=Number(u.value);break}case"http://www.w3.org/2001/XMLSchema#string":{this.validateSourceValue(l,u.value,u.rawValue),s[u.key]=u.rawValue;break}case"http://www.w3.org/2001/XMLSchema#dateTime":{let d=BigInt(u.rawValue),h=ra(Number(d)).toISOString();this.validateSourceValue(l,u.value,h),s[u.key]=h;break}case"http://www.w3.org/2001/XMLSchema#double":{let d=Number(u.rawValue);this.validateSourceValue(l,u.value,d),s[u.key]=d;break}default:throw new Error(`Unsupported data type ${l}`)}}s.type=r;let a=e.getId(),c=ve.parseFromId(a);return s.id=c.string(),s}async existenceProof(e){let[t,r]=await this._contract.getClaimProofWithStateInfo(e.hIndex());if(!t.existence)throw new Error("Claim does not exist");let i=be.fromBigInt(r.state),o=be.fromBigInt(r.claimsRoot),s=be.fromBigInt(r.revocationsRoot),a=be.fromBigInt(r.rootsRoot),c=new kt({siblings:t.siblings.map(u=>be.fromBigInt(u)),existence:t.existence,nodeAux:t.auxExistence?{key:be.fromBigInt(t.auxIndex),value:be.fromBigInt(t.auxValue)}:void 0});return new mc({issuerData:{id:this._issuerDid,state:{value:i,claimsTreeRoot:o,revocationTreeRoot:s,rootOfRoots:a}},mtp:c,coreClaim:e})}async validateSourceValue(e,t,r){if(await Bu.hashValue(e,r)!==t)throw new Error(`Invalid source value for ${e} type`)}convertDisplayMethod(e){if(!(!e.id||!e._type))switch(e._type){case"Iden3BasicDisplayMethodV1":return{id:e.id,type:"Iden3BasicDisplayMethodV1"};default:throw new Error(`Unsupported display method type ${e._type}`)}}};var KF=class{_ethConnectionConfig;_onchainIssuerOptions;constructor(e,t){this._ethConnectionConfig=e,this._onchainIssuerOptions=t}async getCredential(e,t,r){let{contract:i,connection:o}=this.getContractConnection(e),s=await i.getCredentialAdapterVersion();switch(s){case"0.0.1":{let a=new AI(o,e,{merklizationOptions:this._onchainIssuerOptions?.merklizationOptions});await a.isInterfaceSupported();let{credentialData:c,coreClaimBigInts:u,credentialSubjectFields:l}=await a.getCredential(ve.idFromDID(t),r);return await a.convertOnChainInfoToW3CCredential(c,u,l)}default:throw new Error(`Unsupported adapter version ${s}`)}}async getUserCredentialIds(e,t){let{contract:r,connection:i}=this.getContractConnection(e),o=await r.getCredentialAdapterVersion();switch(o){case"0.0.1":{let s=new AI(i,e,{merklizationOptions:this._onchainIssuerOptions?.merklizationOptions});return await s.isInterfaceSupported(),await s.getUserCredentialsIds(ve.idFromDID(t))}default:throw new Error(`Unsupported adapter version ${o}`)}}getContractConnection(e){let t=ve.idFromDID(e),r=lw(e),i=mn.getAddress(mn.hexlify(Xe.ethAddressFromId(t))),o=this._ethConnectionConfig.find(a=>a.chainId===r);if(!o)throw new Error(`No connection found for chain ID ${r}`);if(!o.url)throw new Error(`No URL found for chain ID ${r}`);return{contract:new Ln(i,GF,new mn.JsonRpcProvider(o.url)),connection:o}}};var JF=class{constructor(e){this.resolverUrl=e}async getLatestStateById(e){return this.getStateInfo(e)}async getStateInfoByIdAndState(e,t){return this.getStateInfo(e,t)}async getGISTProof(e){let{didDocument:t}=await yp(ve.parseFromId(Xe.fromBigInt(e)),this.resolverUrl),{global:r}=this.getIden3StateInfo2023(t);if(!r)throw new Error("GIST root not found");let{proof:i}=r;if(!i)throw new Error("GIST proof not found");return{root:r.root,existence:i.existence,siblings:i.siblings?.map(o=>BigInt(o)),index:BigInt(0),value:BigInt(0),auxExistence:!!i.node_aux,auxIndex:i.node_aux?BigInt(i.node_aux.key):BigInt(0),auxValue:i.node_aux?BigInt(i.node_aux.value):BigInt(0)}}async getGISTRootInfo(e,t){let{didDocument:r}=await yp(ve.parseFromId(Xe.fromBigInt(t)),this.resolverUrl,{gist:be.fromBigInt(e)}),{global:i}=this.getIden3StateInfo2023(r);if(!i)throw new Error("GIST root not found");return i}getRpcProvider(){return new jt}publishState(){throw new Error("publishState method not implemented.")}publishStateGeneric(){throw new Error("publishStateGeneric method not implemented.")}async getStateInfo(e,t){let r=t?{state:be.fromBigInt(t)}:void 0,{didDocument:i}=await yp(ve.parseFromId(Xe.fromBigInt(e)),this.resolverUrl,r),{info:o,published:s}=this.getIden3StateInfo2023(i);if(!o&&!s)throw new Error(Ge.ERRORS.STATE_DOES_NOT_EXIST);if(!o)throw new Error("State info not found");return o.id=e,o.state=r?.state?.bigInt(),{...o}}getIden3StateInfo2023(e){let t=e.verificationMethod?.find(r=>r.type==="Iden3StateInfo2023");if(!t)throw new Error("Iden3StateInfo2023 verification method not found");return t}};var rne=[{inputs:[],name:"ECDSAInvalidSignature",type:"error"},{inputs:[{internalType:"uint256",name:"length",type:"uint256"}],name:"ECDSAInvalidSignatureLength",type:"error"},{inputs:[{internalType:"bytes32",name:"s",type:"bytes32"}],name:"ECDSAInvalidSignatureS",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{inputs:[{internalType:"uint256",name:"deadline",type:"uint256"}],name:"ERC2612ExpiredSignature",type:"error"},{inputs:[{internalType:"address",name:"signer",type:"address"},{internalType:"address",name:"owner",type:"address"}],name:"ERC2612InvalidSigner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"},{internalType:"uint256",name:"currentNonce",type:"uint256"}],name:"InvalidAccountNonce",type:"error"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var ine=[{inputs:[{internalType:"uint256",name:"initialSupply",type:"uint256"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];async function SDe(n,e,t,r,i,o){let s=new Ln(e,rne,n),a=await s.nonces(await n.getAddress()),[c,u]=await Promise.all([s.name(),s.version?.().catch(()=>"1")??Promise.resolve("1")]),l={name:c,version:u,chainId:o,verifyingContract:e},d={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},h={owner:await n.getAddress(),spender:t,value:r,nonce:a,deadline:i};return n.signTypedData(l,d,h)}async function CDe(n,e){return new Ln(n,ine,e).decimals()}var lne=(t=>(t.NotDefinedQueryKey="not defined query key",t.NotDefinedComparator="not defined comparator",t))(lne||{}),dne=(o=>(o[o.BigInt=0]="BigInt",o[o.Boolean=1]="Boolean",o[o.Double=2]="Double",o[o.DateTime=3]="DateTime",o[o.String=4]="String",o))(dne||{}),qF=[!0,1,"true"],VF=[!1,0,"false"],one=(n,e)=>Array.isArray(n)&&Array.isArray(e)?n.length===e.length&&n.every((t,r)=>t===e[r]):!Array.isArray(n)&&Array.isArray(e)?e.includes(n):Array.isArray(n)&&!Array.isArray(e)?n.includes(e):(n=n,e=e,qF.includes(n)&&qF.includes(e)||VF.includes(n)&&VF.includes(e)?!0:n===e),sne=(n,e)=>hne(n,e,(r,i)=>{switch(pne(r.toString())){case 0:case 1:return BigInt(r)>BigInt(i);case 3:return Date.parse(r.toString())>Date.parse(i.toString());case 2:case 4:default:return r>i}}),ane=(n,e)=>hne(n,e,(r,i)=>{switch(pne(r.toString())){case 0:case 1:return BigInt(r)>=BigInt(i);case 3:return Date.parse(r.toString())>=Date.parse(i.toString());case 2:case 4:default:return r>=i}}),LDe=(n,e)=>!!(qF.includes(e)&&typeof n<"u"||VF.includes(e)&&(n===void 0||Array.isArray(n)&&!n.length)),cne=(n,e)=>Array.isArray(n)&&Array.isArray(e)?n.every(t=>e.includes(t)):!Array.isArray(n)&&Array.isArray(e)?e.includes(n):Array.isArray(n)&&!Array.isArray(e)?n.includes(e):!1,une=(n,e)=>{if(!Array.isArray(e)||e.length!==2)throw new Error("$between/$nonbetween operator value should be 2 elements array");let[t,r]=e.map(BigInt),i=o=>o>=t&&o<=r;return Array.isArray(n)?n.map(BigInt).every(i):i(BigInt(n))},Qu={$noop:()=>!0,$sd:()=>!0,$exists:(n,e)=>LDe(n,e),$eq:(n,e)=>one(n,e),$in:(n,e)=>cne(n,e),$nin:(n,e)=>!cne(n,e),$gt:(n,e)=>sne(n,e),$lt:(n,e)=>!ane(n,e),$ne:(n,e)=>!one(n,e),$gte:(n,e)=>ane(n,e),$lte:(n,e)=>!sne(n,e),$between:(n,e)=>une(n,e),$nonbetween:(n,e)=>!une(n,e)},fne=(n,e,t=null)=>{let r=e.split("."),i=n;for(let o of r){if(i==null)return t;i=i[o]}return i},Jc=class{constructor(e,t,r,i=!1){this.path=e;this.operatorFunc=t;this.value=r;this.isReverseParams=i}execute(e){if(!this.operatorFunc)throw new Error("not defined comparator");let t=fne(e,this.path);return t==null&&this.operatorFunc!==Qu.$exists?!1:this.isReverseParams?this.operatorFunc(this.value,t):this.operatorFunc(t,this.value)}},QF=n=>Object.keys(n).reduce((e,t)=>{let r=n[t];switch(t){case"claimId":return e.concat(new Jc("id",Qu.$eq,r));case"allowedIssuers":return(r||["*"]).includes("*")?e:e.concat(new Jc("issuer",Qu.$in,r));case"type":return e.concat(new Jc("type",Qu.$in,r,!0));case"context":return e.concat(new Jc("@context",Qu.$in,r,!0));case"credentialSubjectId":return e.concat(new Jc("credentialSubject.id",Qu.$eq,r));case"schema":return e.concat(new Jc("credentialSchema.id",Qu.$eq,r));case"credentialSubject":{let i=Object.keys(r).reduce((o,s)=>{let a=r[s];if(typeof a=="object"&&Object.keys(a).length===0)return o.concat([new Jc(`credentialSubject.${s}`,Qu.$noop,null)]);let c=Object.keys(a).map(u=>{let l=a[u],d=`credentialSubject.${s}`;return new Jc(d,Qu[u],l)});return o.concat(c)},[]);return e.concat(i)}case"proofType":case"groupId":case"skipClaimRevocationCheck":return e;default:throw new Error(`${t} : not defined query key`)}},[]),hne=(n,e,t)=>Array.isArray(n)&&Array.isArray(e)?n.every((r,i)=>t(r,e[i])):!Array.isArray(n)&&Array.isArray(e)?e.every(r=>t(n,r)):Array.isArray(n)&&!Array.isArray(e)?n.every(r=>t(r,e)):t(n,e),RDe=/^[+-]?\d+$/,DDe=/^(-?)(0|([1-9][0-9]*))(\\.[0-9]+)?$/,TDe=/^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/,BDe=/^(true)|(false)$/,PDe=/^\d{4}-\d{2}-\d{2}$/,pne=n=>RDe.test(n)?0:DDe.test(n)?2:TDe.test(n)||PDe.test(n)?3:BDe.test(n)?1:4;var zF=class{constructor(e){this._localStorageKey=e;localStorage.getItem(this._localStorageKey)||localStorage.setItem(e,JSON.stringify([]))}async save(e,t,r="id"){if(localStorage){let i=localStorage.getItem(this._localStorageKey),o=[];i&&(o=JSON.parse(i));let s=o.findIndex(a=>a[r]===e);s===-1?o.push(t):o[s]=t,localStorage.setItem(this._localStorageKey,JSON.stringify(o))}}async get(e,t="id"){let r=localStorage.getItem(this._localStorageKey),i=[];return r&&(i=JSON.parse(r)),i.find(o=>o[t]===e)}async load(){let e=localStorage.getItem(this._localStorageKey);return e&&JSON.parse(e)}async delete(e,t="id"){let r=localStorage.getItem(this._localStorageKey),i=[];r&&(i=JSON.parse(r));let o=i.filter(s=>s[t]!==e);if(i.length===o.length)throw new Error(`item not found to delete: ${e}`);localStorage.setItem(this._localStorageKey,JSON.stringify(o))}};var YF=class n{constructor(e){this._mtDepth=e}static storageKeyMeta="merkle-tree-meta";async createIdentityMerkleTrees(e){e||(e=`${Ut()}`);let t=localStorage.getItem(n.storageKeyMeta);if(t){let i=JSON.parse(t);if(i.find(c=>c.treeId===`${e}+${c.type}`))throw new Error(`Present merkle tree meta information in the store for current identifier ${e}`);let s=i.filter(c=>c.identifier===e);if(s.length>0)return s;let a=ky(e);return localStorage.setItem(n.storageKeyMeta,JSON.stringify([...i,...a])),[...i,...a]}let r=ky(e);return localStorage.setItem(n.storageKeyMeta,JSON.stringify(r)),r}async getIdentityMerkleTreesInfo(e){let t=localStorage.getItem(n.storageKeyMeta);if(t)return JSON.parse(t).filter(i=>i.identifier===e);throw new Error(`Merkle tree meta not found for identifier ${e}`)}async getMerkleTreeByIdentifierAndType(e,t){let r=this.getMeta(e,t);return new sa(new ww(Xc(r.treeId)),!0,this._mtDepth)}getMeta(e,t){let r=localStorage.getItem(n.storageKeyMeta),i=new Error(`Merkle tree not found for identifier ${e} and type ${t}`);if(!r)throw i;let s=JSON.parse(r).filter(a=>a.identifier===e&&a.type===t)[0];if(!s)throw i;return s}async addToMerkleTree(e,t,r,i){let o=this.getMeta(e,t);await new sa(new ww(Xc(o.treeId)),!0,this._mtDepth).add(r,i)}async bindMerkleTreeToNewIdentifier(e,t){let r=localStorage.getItem(n.storageKeyMeta);if(!r)throw new Error(`Merkle tree meta not found for identifier ${e}`);let i=JSON.parse(r),o=i.filter(a=>a.identifier===e).map(a=>({...a,identifier:t}));if(o.length===0)throw new Error(`Merkle tree meta not found for identifier ${e}`);let s=[...i.filter(a=>a.identifier!==e),...o];localStorage.setItem(n.storageKeyMeta,JSON.stringify(s))}};var jF=class{constructor(e){this._storageKey=e;this._store=Od(`${e}-db`,e)}_store;async save(e,t,r="id"){return Fd(e,t,this._store)}async get(e,t="id"){return Wc(e,this._store)}async load(){return WN(this._store)}async delete(e,t="id"){return QI(e,this._store)}};var WF=class n{constructor(e){this._mtDepth=e;this._merkleTreeMetaStore=Od(`${n.storageKeyMeta}-db`,n.storageKeyMeta),this._bindingStore=Od(`${n.storageBindingKeyMeta}-db`,n.storageBindingKeyMeta)}static storageKeyMeta="merkle-tree-meta";static storageBindingKeyMeta="binding-did";_merkleTreeMetaStore;_bindingStore;async createIdentityMerkleTrees(e){if(e||(e=`${Ut()}`),await Wc(e,this._bindingStore))throw new Error(`Present merkle tree meta information in the store for current identifier ${e}`);let r=ky(e);return await Fd(e,r,this._merkleTreeMetaStore),r}async getIdentityMerkleTreesInfo(e){let t=await Wc(e,this._merkleTreeMetaStore);if(t)return t;throw new Error(`Merkle tree meta not found for identifier ${e}`)}async getMerkleTreeByIdentifierAndType(e,t){let r=await Wc(e,this._merkleTreeMetaStore),i=new Error(`Merkle tree not found for identifier ${e} and type ${t}`);if(!r)throw i;let o=r.find(s=>s.identifier===e&&s.type===t);if(!o)throw i;return new sa(new bw(Xc(o.treeId)),!0,this._mtDepth)}async addToMerkleTree(e,t,r,i){let o=await Wc(e,this._merkleTreeMetaStore);if(!o)throw new Error(`Merkle tree meta not found for identifier ${e}`);let s=o.find(c=>c.identifier===e&&c.type===t);if(!s)throw new Error(`Merkle tree not found for identifier ${e} and type ${t}`);await new sa(new bw(Xc(s.treeId)),!0,this._mtDepth).add(r,i)}async bindMerkleTreeToNewIdentifier(e,t){let r=await Wc(e,this._merkleTreeMetaStore);if(!r||!r?.length)throw new Error(`Merkle tree meta not found for identifier ${e}`);let i=r.map(o=>({...o,identifier:t}));await QI(e,this._merkleTreeMetaStore),await Fd(t,i,this._merkleTreeMetaStore),await Fd(e,t,this._bindingStore)}};var ZF=class{constructor(e){this._dataSource=e}static storageKey="circuits";async loadCircuitData(e){let t=await this._dataSource.get(e.toString(),"circuitId");if(!t)throw new Error(`item not found: ${e}`);return t}async saveCircuitData(e,t){await this._dataSource.save(e.toString(),t,"circuitId")}};var XF=class{constructor(e){this._dataSource=e}static storageKey="credentials";async listCredentials(){return(await this._dataSource.load()).filter(t=>t!==void 0).map(t=>t&&Er.fromJSON(t))}async saveCredential(e){return this._dataSource.save(e.id,e.toJSON())}async saveAllCredentials(e){for(let t of e)await this.saveCredential(t)}async removeCredential(e){return this._dataSource.delete(e)}async findCredentialById(e){let t=await this._dataSource.get(e);return t&&Er.fromJSON(t)}async findCredentialsByQuery(e){let t=QF(e);return(await this._dataSource.load()).filter(o=>t.every(s=>s.execute(o))).filter(o=>o!==void 0).map(o=>Er.fromJSON(o))}};var _F=class{constructor(e,t){this._identityDataSource=e;this._profileDataSource=t}static identitiesStorageKey="identities";static profilesStorageKey="profiles";async saveProfile(e){let r=(await this._profileDataSource.load()).filter(o=>o.genesisIdentifier===e.genesisIdentifier),i=r.length?[...r,e]:[e];for(let o=0;o<i.length;o++){let s=i[o];await this._profileDataSource.save(s.id,s)}}async getProfileByVerifier(e){return this._profileDataSource.get(e,"verifier")}async getProfilesByVerifier(e,t){return(await this._profileDataSource.load()).filter(r=>r.verifier===e&&(!t||t.every(i=>r.tags?.includes(i))))}async getProfileById(e){return this._profileDataSource.get(e)}async getProfilesByGenesisIdentifier(e){return(await this._profileDataSource.load()).filter(t=>t.genesisIdentifier===e)}async getAllIdentities(){return this._identityDataSource.load()}async saveIdentity(e){return this._identityDataSource.save(e.did,e,"did")}async getIdentity(e){return this._identityDataSource.get(e,"did")}};var $F=class{constructor(e){this.opts=e;this._verificationKeyPath=this.opts.verificationFileName??this._verificationKeyPath,this._provingKeyPath=this.opts.provingFileName??this._provingKeyPath,this._wasmFilePath=this.opts.wasmFileName??this._wasmFilePath}_verificationKeyPath="verification_key.json";_provingKeyPath="circuit_final.zkey";_wasmFilePath="circuit.wasm";_fs=null;_browserNotSupportedError=new Error("File system operations are not supported in browser environment");async getFs(){return this._fs?this._fs:(this._fs={existsSync:()=>{throw this._browserNotSupportedError},readFileSync:()=>{throw this._browserNotSupportedError},writeFileSync:()=>{throw this._browserNotSupportedError},mkdirSync:()=>{throw this._browserNotSupportedError}},this._fs)}async loadCircuitData(e,t){let r=t?.mode??"full",i={wasm:r==="proving"||r==="full"?this.loadCircuitFile(e,this._wasmFilePath):Promise.resolve(null),provingKey:r==="proving"||r==="full"?this.loadCircuitFile(e,this._provingKeyPath):Promise.resolve(null),verificationKey:r==="verification"||r==="full"?this.loadCircuitFile(e,this._verificationKeyPath):Promise.resolve(null)},[o,s,a]=await Promise.all([i.wasm,i.provingKey,i.verificationKey]);return{circuitId:e,wasm:o,provingKey:s,verificationKey:a}}async loadCircuitFile(e,t){let r=`${this.opts.dirname}/${e}/${t}`,i=await this.getFs();if(i.existsSync(r)){let o=i.readFileSync(r);return new Uint8Array(o)}return null}async writeCircuitFile(e,t,r,i){let o=`${this.opts.dirname}/${e}`,s=`${o}/${t}`,a=await this.getFs();a.mkdirSync(o,{recursive:!0}),a.writeFileSync(s,r,i)}async saveCircuitData(e,t){t.verificationKey&&await this.writeCircuitFile(e,this._verificationKeyPath,t.verificationKey,"utf-8"),t.provingKey&&await this.writeCircuitFile(e,this._provingKeyPath,t.provingKey),t.wasm&&await this.writeCircuitFile(e,this._wasmFilePath,t.wasm)}};var zu=n=>{if(!n){let e=On.hash(new Array(3).fill(0n));return{proof:new kt,treeState:{state:be.fromBigInt(e),claimsRoot:Ne,revocationRoot:Ne,rootOfRoots:Ne}}}return{proof:n.mtp,treeState:$5(n.issuer.state,n.issuer.claimsTreeRoot,n.issuer.revocationTreeRoot,n.issuer.rootOfRoots)}},sw=n=>{let e=!1,t;n.existence?e=!0:n.auxExistence&&(t={key:be.fromBigInt(n.auxIndex),value:be.fromBigInt(n.auxValue)});let r=n.siblings.map(s=>be.fromBigInt(s)),i=new kt({siblings:r,nodeAux:t,existence:e});return{root:be.fromBigInt(n.root),proof:i}},B8=n=>{if(!n)return[{operator:dn.$noop,fieldName:""}];let e=[],t=Object.entries(n);if(!t.length)throw new Error("query must have at least 1 predicate");for(let[r,i]of t){let o=Object.entries(i);if(o.length===0){e.push({operator:dn.$sd,fieldName:r});continue}for(let[a,c]of o){if(!dn[a])throw new Error("operator is not supported by lib");let u=dn[a];e.push({operator:u,fieldName:r,operatorValue:c})}}return e},P8=async(n,e,t,r)=>{let i={...n,slotIndex:0,merklizedSchema:!1,datatype:"",claimPathKey:BigInt(0),values:[],path:new Hr};if(!n.fieldName&&n.operator!==0)throw new Error("query must have a field name if operator is not $noop");if(n.fieldName&&(i.datatype=await Hr.newTypeFromContext(e,`${t}.${n.fieldName}`,r)),await Q2(JSON.parse(e),r,t)||(i.merklizedSchema=!0),!i.merklizedSchema)i.slotIndex=await V2(n.fieldName,t,ke.encode(e));else try{let s=await I6(e,t,n.fieldName,r);i.claimPathKey=await s.mtEntry(),i.path=s}catch(s){throw new Error(`field does not exist in the schema ${s.message}`)}if(n.operatorValue!==void 0){if(!tM(i.datatype,n.operator))throw new Error(`operator ${n.operator} is not supported for datatype ${i.datatype}`);if((n.operator===0||n.operator===16)&&n.operatorValue)throw new Error(`operator value should be undefined for ${n.operator} operator`);let s;switch(n.operator){case 0:case 16:s=[];break;case 11:s=kDe(n.operatorValue);break;default:s=await k8(n.operatorValue,i.datatype)}i.values=s}return i},xI=async(n,e,t,r)=>{let i=B8(t);return Promise.all(i.map(o=>P8(o,e,n,r)))},k8=async(n,e)=>{let t=[];if(Array.isArray(n))for(let r=0;r<n.length;r++)t[r]=await Bu.hashValue(e,n[r]);else t[0]=await Bu.hashValue(e,n);return t},kDe=n=>{if(typeof n=="boolean")return[BigInt(n)];throw new Error("exists operator value must be true or false")},M8=n=>["authV2","authV3","authV3-8-32"].includes(n);async function nN(n,e){e=e||{};let t;try{t=await WebAssembly.compile(n)}catch(l){throw new Error(l)}let r="",i="",o=await WebAssembly.instantiate(t,{runtime:{exceptionHandler:function(l){let d;throw l==1?d=`Signal not found.
|
|
423
|
+
`);for(let d=0;d<u.length;d++){let h=TLe(BigInt(u[d])%this.prime,this.n32);for(let f=0;f<this.n32;f++)this.instance.exports.writeSharedRWMemory(f,h[this.n32-1-f]);try{this.instance.exports.setInputSignal(a,c,d),i++}catch(f){throw new Error(f)}}}),i<this.instance.exports.getInputSize())throw new Error(`Not all inputs have been set. Only ${i} out of ${this.instance.exports.getInputSize()}`)}async calculateWitness(e,t){let r=[];await this._doCalculateWitness(e,t);for(let i=0;i<this.witnessSize;i++){this.instance.exports.getWitness(i);let o=new Uint32Array(this.n32);for(let s=0;s<this.n32;s++)o[this.n32-1-s]=this.instance.exports.readSharedRWMemory(s);r.push(CO(o))}return r}async calculateBinWitness(e,t){let r=new Uint32Array(this.witnessSize*this.n32),i=new Uint8Array(r.buffer);await this._doCalculateWitness(e,t);for(let o=0;o<this.witnessSize;o++){this.instance.exports.getWitness(o);let s=o*this.n32;for(let a=0;a<this.n32;a++)r[s+a]=this.instance.exports.readSharedRWMemory(a)}return i}async calculateWTNSBin(e,t){let r=new Uint32Array(this.witnessSize*this.n32+this.n32+11),i=new Uint8Array(r.buffer);await this._doCalculateWitness(e,t),i[0]=119,i[1]=116,i[2]=110,i[3]=115,r[1]=2,r[2]=2,r[3]=1;let o=this.n32*4,a=(8+o).toString(16);r[4]=parseInt(a.slice(0,8),16),r[5]=parseInt(a.slice(8,16),16),r[6]=o,this.instance.exports.getRawPrime();let c=7;for(let d=0;d<this.n32;d++)r[c+d]=this.instance.exports.readSharedRWMemory(d);c+=this.n32,r[c]=this.witnessSize,c++,r[c]=2,c++;let l=(o*this.witnessSize).toString(16);r[c]=parseInt(l.slice(0,8),16),r[c+1]=parseInt(l.slice(8,16),16),c+=2;for(let d=0;d<this.witnessSize;d++){this.instance.exports.getWitness(d);for(let h=0;h<this.n32;h++)r[c+h]=this.instance.exports.readSharedRWMemory(h);c+=this.n32}return i}};function TLe(n,e){let t=[],r=BigInt(4294967296);for(;n;)t.unshift(Number(n%r)),n=n/r;if(e){let i=e-t.length;for(;i>0;)t.unshift(0),i--}return t}function CO(n){let e=BigInt(0),t=BigInt(4294967296);for(let r=0;r<n.length;r++)e=e*t+BigInt(n[r]);return e}function BLe(n){let e=[];return t(e,n),e;function t(r,i){if(Array.isArray(i))for(let o=0;o<i.length;o++)t(r,i[o]);else r.push(i)}}function PLe(n){let e=BigInt(2)**BigInt(64),t=BigInt("0xCBF29CE484222325");for(let o=0;o<n.length;o++)t^=BigInt(n[o].charCodeAt()),t*=BigInt(1099511628211),t%=e;let r=t.toString(16),i=16-r.length;return r="0".repeat(i).concat(r),r}var Vy=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function $E(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function LO(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function Gc(n,...e){if(!$E(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function Pee(n){if(typeof n!="function"||typeof n.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");LO(n.outputLen),LO(n.blockLen)}function $C(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function kLe(n,e){Gc(n);let t=e.outputLen;if(n.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function e8(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function mO(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function Ku(n,e){return n<<32-e|n>>>e}var kee=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",MLe=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function zy(n){if(Gc(n),kee)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=MLe[n[t]];return e}var wd={_0:48,_9:57,A:65,F:70,a:97,f:102};function dee(n){if(n>=wd._0&&n<=wd._9)return n-wd._0;if(n>=wd.A&&n<=wd.F)return n-(wd.A-10);if(n>=wd.a&&n<=wd.f)return n-(wd.a-10)}function t8(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(kee)return Uint8Array.fromHex(n);let e=n.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=dee(n.charCodeAt(o)),a=dee(n.charCodeAt(o+1));if(s===void 0||a===void 0){let c=n[o]+n[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}r[i]=s*16+a}return r}function eI(n){if(typeof n!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(n))}function QO(n){return typeof n=="string"&&(n=eI(n)),Gc(n),n}function Fi(...n){let e=0;for(let r=0;r<n.length;r++){let i=n[r];Gc(i),e+=i.length}let t=new Uint8Array(e);for(let r=0,i=0;r<n.length;r++){let o=n[r];t.set(o,i),i+=o.length}return t}var n8=class{};function OLe(n){let e=r=>n().update(QO(r)).digest(),t=n();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>n(),e}function zO(n=32){if(Vy&&typeof Vy.getRandomValues=="function")return Vy.getRandomValues(new Uint8Array(n));if(Vy&&typeof Vy.randomBytes=="function")return Uint8Array.from(Vy.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}function FLe(n,e,t,r){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,t,r);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=r?4:0,u=r?0:4;n.setUint32(e+c,s,r),n.setUint32(e+u,a,r)}function NLe(n,e,t){return n&e^~n&t}function ULe(n,e,t){return n&e^n&t^e&t}var RO=class extends n8{constructor(e,t,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=mO(this.buffer)}update(e){$C(this),e=QO(e),Gc(e);let{view:t,buffer:r,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=mO(e);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){$C(this),kLe(e,this),this.finished=!0;let{buffer:t,view:r,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,e8(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(r,0),s=0);for(let d=s;d<i;d++)t[d]=0;FLe(r,i-8,BigInt(this.length*8),o),this.process(r,0);let a=mO(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:r,length:i,finished:o,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=a,i%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}},mh=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),GLe=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),gh=new Uint32Array(64),DO=class extends RO{constructor(e=32){super(64,e,8,!1),this.A=mh[0]|0,this.B=mh[1]|0,this.C=mh[2]|0,this.D=mh[3]|0,this.E=mh[4]|0,this.F=mh[5]|0,this.G=mh[6]|0,this.H=mh[7]|0}get(){let{A:e,B:t,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,r,i,o,s,a,c]}set(e,t,r,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let d=0;d<16;d++,t+=4)gh[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){let h=gh[d-15],f=gh[d-2],m=Ku(h,7)^Ku(h,18)^h>>>3,w=Ku(f,17)^Ku(f,19)^f>>>10;gh[d]=w+gh[d-7]+m+gh[d-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let h=Ku(a,6)^Ku(a,11)^Ku(a,25),f=l+h+NLe(a,c,u)+GLe[d]+gh[d]|0,w=(Ku(r,2)^Ku(r,13)^Ku(r,22))+ULe(r,i,o)|0;l=u,u=c,c=a,a=s+f|0,s=o,o=i,i=r,r=f+w|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,i,o,s,a,c,u,l)}roundClean(){e8(gh)}destroy(){this.set(0,0,0,0,0,0,0,0),e8(this.buffer)}},Mee=OLe(()=>new DO);var YO=BigInt(0),r8=BigInt(1);function i8(n,e=""){if(typeof n!="boolean"){let t=e&&`"${e}"`;throw new Error(t+"expected boolean, got type="+typeof n)}return n}function H0(n,e,t=""){let r=$E(n),i=n?.length,o=e!==void 0;if(!r||o&&i!==e){let s=t&&`"${t}" `,a=o?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof n}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return n}function jC(n){let e=n.toString(16);return e.length&1?"0"+e:e}function Oee(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?YO:BigInt("0x"+n)}function tI(n){return Oee(zy(n))}function Fee(n){return Gc(n),Oee(zy(Uint8Array.from(n).reverse()))}function jO(n,e){return t8(n.toString(16).padStart(e*2,"0"))}function Nee(n,e){return jO(n,e).reverse()}function ao(n,e,t){let r;if(typeof e=="string")try{r=t8(e)}catch(i){throw new Error(n+" must be hex string or Uint8Array, cause: "+i)}else if($E(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");return r}var gO=n=>typeof n=="bigint"&&YO<=n;function Uee(n,e,t){return gO(n)&&gO(e)&&gO(t)&&e<=n&&n<t}function HLe(n,e,t,r){if(!Uee(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}function WE(n){let e;for(e=0;n>YO;n>>=r8,e+=1);return e}function KLe(n,e){return n>>BigInt(e)&r8}var nI=n=>(r8<<BigInt(n))-r8;function JLe(n,e,t){if(typeof n!="number"||n<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=f=>new Uint8Array(f),i=f=>Uint8Array.of(f),o=r(n),s=r(n),a=0,c=()=>{o.fill(1),s.fill(0),a=0},u=(...f)=>t(s,o,...f),l=(f=r(0))=>{s=u(i(0),f),o=u(),f.length!==0&&(s=u(i(1),f),o=u())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,m=[];for(;f<e;){o=u();let w=o.slice();m.push(w),f+=o.length}return Fi(...m)};return(f,m)=>{c(),l(f);let w;for(;!(w=m(d()));)l();return c(),w}}function qLe(n){return typeof n=="function"&&Number.isSafeInteger(n.outputLen)}function u8(n,e,t={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(i,o,s){let a=n[i];if(s&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${c}`)}Object.entries(e).forEach(([i,o])=>r(i,o,!1)),Object.entries(t).forEach(([i,o])=>r(i,o,!0))}var ui=()=>{throw new Error("not implemented")};function TO(n){let e=new WeakMap;return(t,...r)=>{let i=e.get(t);if(i!==void 0)return i;let o=n(t,...r);return e.set(t,o),o}}var ea=BigInt(0),Wo=BigInt(1),K0=BigInt(2),Gee=BigInt(3),Hee=BigInt(4),Kee=BigInt(5),VLe=BigInt(7),Jee=BigInt(8),QLe=BigInt(9),qee=BigInt(16);function Ga(n,e){let t=n%e;return t>=ea?t:e+t}function fee(n,e){if(n===ea)throw new Error("invert: expected non-zero number");if(e<=ea)throw new Error("invert: expected positive modulus, got "+e);let t=Ga(n,e),r=e,i=ea,o=Wo;for(;t!==ea;){let a=r/t,c=r%t,u=i-o*a;r=t,t=c,i=o,o=u}if(r!==Wo)throw new Error("invert: does not exist");return Ga(i,e)}function WO(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function Vee(n,e){let t=(n.ORDER+Wo)/Hee,r=n.pow(e,t);return WO(n,r,e),r}function zLe(n,e){let t=(n.ORDER-Kee)/Jee,r=n.mul(e,K0),i=n.pow(r,t),o=n.mul(e,i),s=n.mul(n.mul(o,K0),i),a=n.mul(o,n.sub(s,n.ONE));return WO(n,a,e),a}function YLe(n){let e=jy(n),t=Qee(n),r=t(e,e.neg(e.ONE)),i=t(e,r),o=t(e,e.neg(r)),s=(n+VLe)/qee;return(a,c)=>{let u=a.pow(c,s),l=a.mul(u,r),d=a.mul(u,i),h=a.mul(u,o),f=a.eql(a.sqr(l),c),m=a.eql(a.sqr(d),c);u=a.cmov(u,l,f),l=a.cmov(h,d,m);let w=a.eql(a.sqr(l),c),b=a.cmov(u,l,w);return WO(a,b,c),b}}function Qee(n){if(n<Gee)throw new Error("sqrt is not defined for small field");let e=n-Wo,t=0;for(;e%K0===ea;)e/=K0,t++;let r=K0,i=jy(n);for(;o8(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Vee;let o=i.pow(r,e),s=(e+Wo)/K0;return function(c,u){if(c.is0(u))return u;if(o8(c,u)!==1)throw new Error("Cannot find square root");let l=t,d=c.mul(c.ONE,o),h=c.pow(u,e),f=c.pow(u,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,w=c.sqr(h);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===l)throw new Error("Cannot find square root");let b=Wo<<BigInt(l-m-1),S=c.pow(d,b);l=m,d=c.sqr(S),h=c.mul(h,d),f=c.mul(f,S)}return f}}function jLe(n){return n%Hee===Gee?Vee:n%Jee===Kee?zLe:n%qee===QLe?YLe(n):Qee(n)}var WLe=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ZLe(n){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=WLe.reduce((r,i)=>(r[i]="function",r),e);return u8(n,t),n}function l8(n,e,t){if(t<ea)throw new Error("invalid exponent, negatives unsupported");if(t===ea)return n.ONE;if(t===Wo)return e;let r=n.ONE,i=e;for(;t>ea;)t&Wo&&(r=n.mul(r,i)),i=n.sqr(i),t>>=Wo;return r}function rI(n,e,t=!1){let r=new Array(e.length).fill(t?n.ZERO:void 0),i=e.reduce((s,a,c)=>n.is0(a)?s:(r[c]=s,n.mul(s,a)),n.ONE),o=n.inv(i);return e.reduceRight((s,a,c)=>n.is0(a)?s:(r[c]=n.mul(s,r[c]),n.mul(s,a)),o),r}function o8(n,e){let t=(n.ORDER-Wo)/K0,r=n.pow(e,t),i=n.eql(r,n.ONE),o=n.eql(r,n.ZERO),s=n.eql(r,n.neg(n.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function zee(n,e){e!==void 0&&LO(e);let t=e!==void 0?e:n.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function jy(n,e,t=!1,r={}){if(n<=ea)throw new Error("invalid field: expected ORDER > 0, got "+n);let i,o,s=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(i=h.BITS),h.sqrt&&(o=h.sqrt),typeof h.isLE=="boolean"&&(t=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),a=h.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(o=r.sqrt);let{nBitLength:c,nByteLength:u}=zee(n,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:n,isLE:t,BITS:c,BYTES:u,MASK:nI(c),ZERO:ea,ONE:Wo,allowedLengths:a,create:h=>Ga(h,n),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return ea<=h&&h<n},is0:h=>h===ea,isValidNot0:h=>!d.is0(h)&&d.isValid(h),isOdd:h=>(h&Wo)===Wo,neg:h=>Ga(-h,n),eql:(h,f)=>h===f,sqr:h=>Ga(h*h,n),add:(h,f)=>Ga(h+f,n),sub:(h,f)=>Ga(h-f,n),mul:(h,f)=>Ga(h*f,n),pow:(h,f)=>l8(d,h,f),div:(h,f)=>Ga(h*fee(f,n),n),sqrN:h=>h*h,addN:(h,f)=>h+f,subN:(h,f)=>h-f,mulN:(h,f)=>h*f,inv:h=>fee(h,n),sqrt:o||(h=>(l||(l=jLe(n)),l(d,h))),toBytes:h=>t?Nee(h,u):jO(h,u),fromBytes:(h,f=!0)=>{if(a){if(!a.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+h.length);let w=new Uint8Array(u);w.set(h,t?0:w.length-h.length),h=w}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let m=t?Fee(h):tI(h);if(s&&(m=Ga(m,n)),!f&&!d.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>rI(d,h),cmov:(h,f,m)=>m?f:h});return Object.freeze(d)}function Yee(n){if(typeof n!="bigint")throw new Error("field order must be bigint");let e=n.toString(2).length;return Math.ceil(e/8)}function ZO(n){let e=Yee(n);return e+Math.ceil(e/2)}function jee(n,e,t=!1){let r=n.length,i=Yee(e),o=ZO(e);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);let s=t?Fee(n):tI(n),a=Ga(s,e-Wo)+Wo;return t?Nee(a,i):jO(a,i)}var Yy=BigInt(0),J0=BigInt(1);function s8(n,e){let t=e.negate();return n?t:e}function jE(n,e){let t=rI(n.Fp,e.map(r=>r.Z));return e.map((r,i)=>n.fromAffine(r.toAffine(t[i])))}function Wee(n,e){if(!Number.isSafeInteger(n)||n<=0||n>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+n)}function yO(n,e){Wee(n,e);let t=Math.ceil(e/n)+1,r=2**(n-1),i=2**n,o=nI(n),s=BigInt(n);return{windows:t,windowSize:r,mask:o,maxNumber:i,shiftBy:s}}function hee(n,e,t){let{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=t,a=Number(n&i),c=n>>s;a>r&&(a-=o,c+=J0);let u=e*r,l=u+Math.abs(a)-1,d=a===0,h=a<0,f=e%2!==0;return{nextN:c,offset:l,isZero:d,isNeg:h,isNegF:f,offsetF:u}}function XLe(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((t,r)=>{if(!(t instanceof e))throw new Error("invalid point at index "+r)})}function _Le(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((t,r)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+r)})}var wO=new WeakMap,Zee=new WeakMap;function bO(n){return Zee.get(n)||1}function pee(n){if(n!==Yy)throw new Error("invalid wNAF")}var BO=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,r=this.ZERO){let i=e;for(;t>Yy;)t&J0&&(r=r.add(i)),i=i.double(),t>>=J0;return r}precomputeWindow(e,t){let{windows:r,windowSize:i}=yO(t,this.bits),o=[],s=e,a=s;for(let c=0;c<r;c++){a=s,o.push(a);for(let u=1;u<i;u++)a=a.add(s),o.push(a);s=a.double()}return o}wNAF(e,t,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=yO(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:h,offsetF:f}=hee(r,a,s);r=c,l?o=o.add(s8(h,t[f])):i=i.add(s8(d,t[u]))}return pee(r),{p:i,f:o}}wNAFUnsafe(e,t,r,i=this.ZERO){let o=yO(e,this.bits);for(let s=0;s<o.windows&&r!==Yy;s++){let{nextN:a,offset:c,isZero:u,isNeg:l}=hee(r,s,o);if(r=a,!u){let d=t[c];i=i.add(l?d.negate():d)}}return pee(r),i}getPrecomputes(e,t,r){let i=wO.get(t);return i||(i=this.precomputeWindow(t,e),e!==1&&(typeof r=="function"&&(i=r(i)),wO.set(t,i))),i}cached(e,t,r){let i=bO(e);return this.wNAF(i,this.getPrecomputes(i,e,r),t)}unsafe(e,t,r,i){let o=bO(e);return o===1?this._unsafeLadder(e,t,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,i)}createCache(e,t){Wee(t,this.bits),Zee.set(e,t),wO.delete(e)}hasCache(e){return bO(e)!==1}};function $Le(n,e,t,r){let i=e,o=n.ZERO,s=n.ZERO;for(;t>Yy||r>Yy;)t&J0&&(o=o.add(i)),r&J0&&(s=s.add(i)),i=i.double(),t>>=J0,r>>=J0;return{p1:o,p2:s}}function eRe(n,e,t,r){XLe(t,n),_Le(r,e);let i=t.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");let s=n.ZERO,a=WE(BigInt(i)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=nI(c),l=new Array(Number(u)+1).fill(s),d=Math.floor((e.BITS-1)/c)*c,h=s;for(let f=d;f>=0;f-=c){l.fill(s);for(let w=0;w<o;w++){let b=r[w],S=Number(b>>BigInt(f)&u);l[S]=l[S].add(t[w])}let m=s;for(let w=l.length-1,b=s;w>0;w--)b=b.add(l[w]),m=m.add(b);if(h=h.add(m),f!==0)for(let w=0;w<c;w++)h=h.double()}return h}function mee(n,e,t){if(e){if(e.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ZLe(e),e}else return jy(n,{isLE:t})}function tRe(n,e,t={},r){if(r===void 0&&(r=n==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${n} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Yy))throw new Error(`CURVE.${c} must be positive bigint`)}let i=mee(e.p,t.Fp,r),o=mee(e.n,t.Fn,r),a=["Gx","Gy","a","b"];for(let c of a)if(!i.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}var nRe=tI;function yh(n,e){if(ZE(n),ZE(e),n<0||n>=1<<8*e)throw new Error("invalid I2OSP input: "+n);let t=Array.from({length:e}).fill(0);for(let r=e-1;r>=0;r--)t[r]=n&255,n>>>=8;return new Uint8Array(t)}function rRe(n,e){let t=new Uint8Array(n.length);for(let r=0;r<n.length;r++)t[r]=n[r]^e[r];return t}function ZE(n){if(!Number.isSafeInteger(n))throw new Error("number expected")}function Xee(n){if(!$E(n)&&typeof n!="string")throw new Error("DST must be Uint8Array or string");return typeof n=="string"?eI(n):n}function iRe(n,e,t,r){Gc(n),ZE(t),e=Xee(e),e.length>255&&(e=r(Fi(eI("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:o}=r,s=Math.ceil(t/i);if(t>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Fi(e,yh(e.length,1)),c=yh(0,o),u=yh(t,2),l=new Array(s),d=r(Fi(c,n,u,yh(0,1),a));l[0]=r(Fi(d,yh(1,1),a));for(let f=1;f<=s;f++){let m=[rRe(d,l[f-1]),yh(f+1,1),a];l[f]=r(Fi(...m))}return Fi(...l).slice(0,t)}function oRe(n,e,t,r,i){if(Gc(n),ZE(t),e=Xee(e),e.length>255){let o=Math.ceil(2*r/8);e=i.create({dkLen:o}).update(eI("H2C-OVERSIZE-DST-")).update(e).digest()}if(t>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:t}).update(n).update(yh(t,2)).update(e).update(yh(e.length,1)).digest()}function EO(n,e,t){u8(t,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:r,k:i,m:o,hash:s,expand:a,DST:c}=t;if(!qLe(t.hash))throw new Error("expected valid hash");Gc(n),ZE(e);let u=r.toString(2).length,l=Math.ceil((u+i)/8),d=e*o*l,h;if(a==="xmd")h=iRe(n,c,d,s);else if(a==="xof")h=oRe(n,c,d,i,s);else if(a==="_internal_pass")h=n;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(e);for(let m=0;m<e;m++){let w=new Array(o);for(let b=0;b<o;b++){let S=l*(b+m*o),R=h.subarray(S,S+l);w[b]=Ga(nRe(R),r)}f[m]=w}return f}var sRe=eI("HashToScalar-");function gee(n,e,t){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function r(o){return n.fromAffine(e(o))}function i(o){let s=o.clearCofactor();return s.equals(n.ZERO)?n.ZERO:(s.assertValidity(),s)}return{defaults:t,hashToCurve(o,s){let a=Object.assign({},t,s),c=EO(o,2,a),u=r(c[0]),l=r(c[1]);return i(u.add(l))},encodeToCurve(o,s){let a=t.encodeDST?{DST:t.encodeDST}:{},c=Object.assign({},t,a,s),u=EO(o,1,c),l=r(u[0]);return i(l)},mapToCurve(o){if(!Array.isArray(o))throw new Error("expected array of bigints");for(let s of o)if(typeof s!="bigint")throw new Error("expected array of bigints");return i(r(o))},hashToScalar(o,s){let a=n.Fn.ORDER,c=Object.assign({},t,{p:a,m:1,DST:sRe},s);return EO(o,1,c)[0][0]}}}var a8=class extends n8{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Pee(e);let r=QO(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(r.length>i?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),e8(o)}update(e){return $C(this),this.iHash.update(e),this}digestInto(e){$C(this),Gc(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:r,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},_ee=(n,e,t)=>new a8(n,e).update(t).digest();_ee.create=(n,e)=>new a8(n,e);var yee=(n,e)=>(n+(n>=0?e:-e)/$ee)/e;function aRe(n,e,t){let[[r,i],[o,s]]=e,a=yee(s*n,t),c=yee(-i*n,t),u=n-a*r-c*o,l=-a*i-c*s,d=u<Ed,h=l<Ed;d&&(u=-u),h&&(l=-l);let f=nI(Math.ceil(WE(t)/2))+q0;if(u<Ed||u>=f||l<Ed||l>=f)throw new Error("splitScalar (endomorphism): failed, k="+n);return{k1neg:d,k1:u,k2neg:h,k2:l}}function PO(n){if(!["compact","recovered","der"].includes(n))throw new Error('Signature format must be "compact", "recovered", or "der"');return n}function IO(n,e){let t={};for(let r of Object.keys(e))t[r]=n[r]===void 0?e[r]:n[r];return i8(t.lowS,"lowS"),i8(t.prehash,"prehash"),t.format!==void 0&&PO(t.format),t}var kO=class extends Error{constructor(e=""){super(e)}},bd={Err:kO,_tlv:{encode:(n,e)=>{let{Err:t}=bd;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let r=e.length/2,i=jC(r);if(i.length/2&128)throw new t("tlv.encode: long form length too big");let o=r>127?jC(i.length/2|128):"";return jC(n)+o+i+e},decode(n,e){let{Err:t}=bd,r=0;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[r++]!==n)throw new t("tlv.decode: wrong tlv");let i=e[r++],o=!!(i&128),s=0;if(!o)s=i;else{let c=i&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(r,r+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)s=s<<8|l;if(r+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(r,r+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+s)}}},_int:{encode(n){let{Err:e}=bd;if(n<Ed)throw new e("integer: negative integers are not allowed");let t=jC(n);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(n){let{Err:e}=bd;if(n[0]&128)throw new e("invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return tI(n)}},toSig(n){let{Err:e,_int:t,_tlv:r}=bd,i=ao("signature",n),{v:o,l:s}=r.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=r.decode(2,o),{v:u,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(n){let{_tlv:e,_int:t}=bd,r=e.encode(2,t.encode(n.r)),i=e.encode(2,t.encode(n.s)),o=r+i;return e.encode(48,o)}},Ed=BigInt(0),q0=BigInt(1),$ee=BigInt(2),WC=BigInt(3),cRe=BigInt(4);function Id(n,e){let{BYTES:t}=n,r;if(typeof e=="bigint")r=e;else{let i=ao("private key",e);try{r=n.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!n.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function ete(n,e={}){let t=tRe("weierstrass",n,e),{Fp:r,Fn:i}=t,o=t.CURVE,{h:s,n:a}=o;u8(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!r.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=nte(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(Q,v,p){let{x,y}=v.toAffine(),I=r.toBytes(x);if(i8(p,"isCompressed"),p){l();let C=!r.isOdd(y);return Fi(tte(C),I)}else return Fi(Uint8Array.of(4),I,r.toBytes(y))}function h(Q){H0(Q,void 0,"Point");let{publicKey:v,publicKeyUncompressed:p}=u,x=Q.length,y=Q[0],I=Q.subarray(1);if(x===v&&(y===2||y===3)){let C=r.fromBytes(I);if(!r.isValid(C))throw new Error("bad point: is not on curve, wrong x");let F=w(C),N;try{N=r.sqrt(F)}catch(q){let _=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+_)}l();let O=r.isOdd(N);return(y&1)===1!==O&&(N=r.neg(N)),{x:C,y:N}}else if(x===p&&y===4){let C=r.BYTES,F=r.fromBytes(I.subarray(0,C)),N=r.fromBytes(I.subarray(C,C*2));if(!b(F,N))throw new Error("bad point: is not on curve");return{x:F,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${v} or uncompressed=${p}`)}let f=e.toBytes||d,m=e.fromBytes||h;function w(Q){let v=r.sqr(Q),p=r.mul(v,Q);return r.add(r.add(p,r.mul(Q,o.a)),o.b)}function b(Q,v){let p=r.sqr(v),x=w(Q);return r.eql(p,x)}if(!b(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let S=r.mul(r.pow(o.a,WC),cRe),R=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(S,R)))throw new Error("bad curve params: a or b");function G(Q,v,p=!1){if(!r.isValid(v)||p&&r.is0(v))throw new Error(`bad point coordinate ${Q}`);return v}function U(Q){if(!(Q instanceof z))throw new Error("ProjectivePoint expected")}function H(Q){if(!c||!c.basises)throw new Error("no endo");return aRe(Q,c.basises,i.ORDER)}let M=TO((Q,v)=>{let{X:p,Y:x,Z:y}=Q;if(r.eql(y,r.ONE))return{x:p,y:x};let I=Q.is0();v==null&&(v=I?r.ONE:r.inv(y));let C=r.mul(p,v),F=r.mul(x,v),N=r.mul(y,v);if(I)return{x:r.ZERO,y:r.ZERO};if(!r.eql(N,r.ONE))throw new Error("invZ was invalid");return{x:C,y:F}}),A=TO(Q=>{if(Q.is0()){if(e.allowInfinityPoint&&!r.is0(Q.Y))return;throw new Error("bad point: ZERO")}let{x:v,y:p}=Q.toAffine();if(!r.isValid(v)||!r.isValid(p))throw new Error("bad point: x or y not field elements");if(!b(v,p))throw new Error("bad point: equation left != right");if(!Q.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function D(Q,v,p,x,y){return p=new z(r.mul(p.X,Q),p.Y,p.Z),v=s8(x,v),p=s8(y,p),v.add(p)}class z{constructor(v,p,x){this.X=G("x",v),this.Y=G("y",p,!0),this.Z=G("z",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(v){let{x:p,y:x}=v||{};if(!v||!r.isValid(p)||!r.isValid(x))throw new Error("invalid affine point");if(v instanceof z)throw new Error("projective point not allowed");return r.is0(p)&&r.is0(x)?z.ZERO:new z(p,x,r.ONE)}static fromBytes(v){let p=z.fromAffine(m(H0(v,void 0,"point")));return p.assertValidity(),p}static fromHex(v){return z.fromBytes(ao("pointHex",v))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(v=8,p=!0){return Y.createCache(this,v),p||this.multiply(WC),this}assertValidity(){A(this)}hasEvenY(){let{y:v}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(v)}equals(v){U(v);let{X:p,Y:x,Z:y}=this,{X:I,Y:C,Z:F}=v,N=r.eql(r.mul(p,F),r.mul(I,y)),O=r.eql(r.mul(x,F),r.mul(C,y));return N&&O}negate(){return new z(this.X,r.neg(this.Y),this.Z)}double(){let{a:v,b:p}=o,x=r.mul(p,WC),{X:y,Y:I,Z:C}=this,F=r.ZERO,N=r.ZERO,O=r.ZERO,T=r.mul(y,y),q=r.mul(I,I),_=r.mul(C,C),L=r.mul(y,I);return L=r.add(L,L),O=r.mul(y,C),O=r.add(O,O),F=r.mul(v,O),N=r.mul(x,_),N=r.add(F,N),F=r.sub(q,N),N=r.add(q,N),N=r.mul(F,N),F=r.mul(L,F),O=r.mul(x,O),_=r.mul(v,_),L=r.sub(T,_),L=r.mul(v,L),L=r.add(L,O),O=r.add(T,T),T=r.add(O,T),T=r.add(T,_),T=r.mul(T,L),N=r.add(N,T),_=r.mul(I,C),_=r.add(_,_),T=r.mul(_,L),F=r.sub(F,T),O=r.mul(_,q),O=r.add(O,O),O=r.add(O,O),new z(F,N,O)}add(v){U(v);let{X:p,Y:x,Z:y}=this,{X:I,Y:C,Z:F}=v,N=r.ZERO,O=r.ZERO,T=r.ZERO,q=o.a,_=r.mul(o.b,WC),L=r.mul(p,I),g=r.mul(x,C),K=r.mul(y,F),E=r.add(p,x),V=r.add(I,C);E=r.mul(E,V),V=r.add(L,g),E=r.sub(E,V),V=r.add(p,y);let J=r.add(I,F);return V=r.mul(V,J),J=r.add(L,K),V=r.sub(V,J),J=r.add(x,y),N=r.add(C,F),J=r.mul(J,N),N=r.add(g,K),J=r.sub(J,N),T=r.mul(q,V),N=r.mul(_,K),T=r.add(N,T),N=r.sub(g,T),T=r.add(g,T),O=r.mul(N,T),g=r.add(L,L),g=r.add(g,L),K=r.mul(q,K),V=r.mul(_,V),g=r.add(g,K),K=r.sub(L,K),K=r.mul(q,K),V=r.add(V,K),L=r.mul(g,V),O=r.add(O,L),L=r.mul(J,V),N=r.mul(E,N),N=r.sub(N,L),L=r.mul(E,g),T=r.mul(J,T),T=r.add(T,L),new z(N,O,T)}subtract(v){return this.add(v.negate())}is0(){return this.equals(z.ZERO)}multiply(v){let{endo:p}=e;if(!i.isValidNot0(v))throw new Error("invalid scalar: out of range");let x,y,I=C=>Y.cached(this,C,F=>jE(z,F));if(p){let{k1neg:C,k1:F,k2neg:N,k2:O}=H(v),{p:T,f:q}=I(F),{p:_,f:L}=I(O);y=q.add(L),x=D(p.beta,T,_,C,N)}else{let{p:C,f:F}=I(v);x=C,y=F}return jE(z,[x,y])[0]}multiplyUnsafe(v){let{endo:p}=e,x=this;if(!i.isValid(v))throw new Error("invalid scalar: out of range");if(v===Ed||x.is0())return z.ZERO;if(v===q0)return x;if(Y.hasCache(this))return this.multiply(v);if(p){let{k1neg:y,k1:I,k2neg:C,k2:F}=H(v),{p1:N,p2:O}=$Le(z,x,I,F);return D(p.beta,N,O,y,C)}else return Y.unsafe(x,v)}multiplyAndAddUnsafe(v,p,x){let y=this.multiplyUnsafe(p).add(v.multiplyUnsafe(x));return y.is0()?void 0:y}toAffine(v){return M(this,v)}isTorsionFree(){let{isTorsionFree:v}=e;return s===q0?!0:v?v(z,this):Y.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:v}=e;return s===q0?this:v?v(z,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(v=!0){return i8(v,"isCompressed"),this.assertValidity(),f(z,this,v)}toHex(v=!0){return zy(this.toBytes(v))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(v=!0){return this.toBytes(v)}_setWindowSize(v){this.precompute(v)}static normalizeZ(v){return jE(z,v)}static msm(v,p){return eRe(z,i,v,p)}static fromPrivateKey(v){return z.BASE.multiply(Id(i,v))}}z.BASE=new z(o.Gx,o.Gy,r.ONE),z.ZERO=new z(r.ZERO,r.ONE,r.ZERO),z.Fp=r,z.Fn=i;let j=i.BITS,Y=new BO(z,e.endo?Math.ceil(j/2):j);return z.BASE.precompute(8),z}function tte(n){return Uint8Array.of(n?2:3)}function nte(n,e){return{secretKey:e.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function uRe(n,e={}){let{Fn:t}=n,r=e.randomBytes||zO,i=Object.assign(nte(n.Fp,t),{seed:ZO(t.ORDER)});function o(f){try{return!!Id(t,f)}catch{return!1}}function s(f,m){let{publicKey:w,publicKeyUncompressed:b}=i;try{let S=f.length;return m===!0&&S!==w||m===!1&&S!==b?!1:!!n.fromBytes(f)}catch{return!1}}function a(f=r(i.seed)){return jee(H0(f,i.seed,"seed"),t.ORDER)}function c(f,m=!0){return n.BASE.multiply(Id(t,f)).toBytes(m)}function u(f){let m=a(f);return{secretKey:m,publicKey:c(m)}}function l(f){if(typeof f=="bigint")return!1;if(f instanceof n)return!0;let{secretKey:m,publicKey:w,publicKeyUncompressed:b}=i;if(t.allowedLengths||m===w)return;let S=ao("key",f).length;return S===w||S===b}function d(f,m,w=!0){if(l(f)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");let b=Id(t,f);return n.fromHex(m).multiply(b).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:u,Point:n,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:f=>Id(t,f),precompute(f=8,m=n.BASE){return m.precompute(f,!1)}},lengths:i})}function lRe(n,e,t={}){Pee(e),u8(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let r=t.randomBytes||zO,i=t.hmac||((p,...x)=>_ee(e,p,Fi(...x))),{Fp:o,Fn:s}=n,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:d,utils:h,lengths:f}=uRe(n,t),m={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function b(p){let x=a>>q0;return p>x}function S(p,x){if(!s.isValidNot0(x))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return x}function R(p,x){PO(x);let y=f.signature,I=x==="compact"?y:x==="recovered"?y+1:void 0;return H0(p,I,`${x} signature`)}class G{constructor(x,y,I){this.r=S("r",x),this.s=S("s",y),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(x,y=w){R(x,y);let I;if(y==="der"){let{r:O,s:T}=bd.toSig(H0(x));return new G(O,T)}y==="recovered"&&(I=x[0],y="compact",x=x.subarray(1));let C=s.BYTES,F=x.subarray(0,C),N=x.subarray(C,C*2);return new G(s.fromBytes(F),s.fromBytes(N),I)}static fromHex(x,y){return this.fromBytes(t8(x),y)}addRecoveryBit(x){return new G(this.r,this.s,x)}recoverPublicKey(x){let y=o.ORDER,{r:I,s:C,recovery:F}=this;if(F==null||![0,1,2,3].includes(F))throw new Error("recovery id invalid");if(a*$ee<y&&F>1)throw new Error("recovery id is ambiguous for h>1 curve");let O=F===2||F===3?I+a:I;if(!o.isValid(O))throw new Error("recovery id 2 or 3 invalid");let T=o.toBytes(O),q=n.fromBytes(Fi(tte((F&1)===0),T)),_=s.inv(O),L=H(ao("msgHash",x)),g=s.create(-L*_),K=s.create(C*_),E=n.BASE.multiplyUnsafe(g).add(q.multiplyUnsafe(K));if(E.is0())throw new Error("point at infinify");return E.assertValidity(),E}hasHighS(){return b(this.s)}toBytes(x=w){if(PO(x),x==="der")return t8(bd.hexFromSig(this));let y=s.toBytes(this.r),I=s.toBytes(this.s);if(x==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Fi(Uint8Array.of(this.recovery),y,I)}return Fi(y,I)}toHex(x){return zy(this.toBytes(x))}assertValidity(){}static fromCompact(x){return G.fromBytes(ao("sig",x),"compact")}static fromDER(x){return G.fromBytes(ao("sig",x),"der")}normalizeS(){return this.hasHighS()?new G(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return zy(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return zy(this.toBytes("compact"))}}let U=t.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");let y=tI(x),I=x.length*8-c;return I>0?y>>BigInt(I):y},H=t.bits2int_modN||function(x){return s.create(U(x))},M=nI(c);function A(p){return HLe("num < 2^"+c,p,Ed,M),s.toBytes(p)}function D(p,x){return H0(p,void 0,"message"),x?H0(e(p),void 0,"prehashed message"):p}function z(p,x,y){if(["recovered","canonical"].some(g=>g in y))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:C,extraEntropy:F}=IO(y,m);p=D(p,C);let N=H(p),O=Id(s,x),T=[A(O),A(N)];if(F!=null&&F!==!1){let g=F===!0?r(f.secretKey):F;T.push(ao("extraEntropy",g))}let q=Fi(...T),_=N;function L(g){let K=U(g);if(!s.isValidNot0(K))return;let E=s.inv(K),V=n.BASE.multiply(K).toAffine(),J=s.create(V.x);if(J===Ed)return;let B=s.create(E*s.create(_+J*O));if(B===Ed)return;let X=(V.x===J?0:2)|Number(V.y&q0),ce=B;return I&&b(B)&&(ce=s.neg(B),X^=1),new G(J,ce,X)}return{seed:q,k2sig:L}}function j(p,x,y={}){p=ao("message",p);let{seed:I,k2sig:C}=z(p,x,y);return JLe(e.outputLen,s.BYTES,i)(I,C)}function Y(p){let x,y=typeof p=="string"||$E(p),I=!y&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!y&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)x=new G(p.r,p.s);else if(y){try{x=G.fromBytes(ao("sig",p),"der")}catch(C){if(!(C instanceof bd.Err))throw C}if(!x)try{x=G.fromBytes(ao("sig",p),"compact")}catch{return!1}}return x||!1}function Q(p,x,y,I={}){let{lowS:C,prehash:F,format:N}=IO(I,m);if(y=ao("publicKey",y),x=D(ao("message",x),F),"strict"in I)throw new Error("options.strict was renamed to lowS");let O=N===void 0?Y(p):G.fromBytes(ao("sig",p),N);if(O===!1)return!1;try{let T=n.fromBytes(y);if(C&&O.hasHighS())return!1;let{r:q,s:_}=O,L=H(x),g=s.inv(_),K=s.create(L*g),E=s.create(q*g),V=n.BASE.multiplyUnsafe(K).add(T.multiplyUnsafe(E));return V.is0()?!1:s.create(V.x)===q}catch{return!1}}function v(p,x,y={}){let{prehash:I}=IO(y,m);return x=D(x,I),G.fromBytes(p,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:d,utils:h,lengths:f,Point:n,sign:j,verify:Q,recoverPublicKey:v,Signature:G,hash:e})}function wee(n){let{CURVE:e,curveOpts:t}=rte(n),r=ete(e,t);return hRe(n,r)}function rte(n){let e={a:n.a,b:n.b,p:n.Fp.ORDER,n:n.n,h:n.h,Gx:n.Gx,Gy:n.Gy},t=n.Fp,r=n.allowedPrivateKeyLengths?Array.from(new Set(n.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,i=jy(e.n,{BITS:n.nBitLength,allowedLengths:r,modFromBytes:n.wrapPrivateKey}),o={Fp:t,Fn:i,allowInfinityPoint:n.allowInfinityPoint,endo:n.endo,isTorsionFree:n.isTorsionFree,clearCofactor:n.clearCofactor,fromBytes:n.fromBytes,toBytes:n.toBytes};return{CURVE:e,curveOpts:o}}function dRe(n){let{CURVE:e,curveOpts:t}=rte(n),r={hmac:n.hmac,randomBytes:n.randomBytes,lowS:n.lowS,bits2int:n.bits2int,bits2int_modN:n.bits2int_modN};return{CURVE:e,curveOpts:t,hash:n.hash,ecdsaOpts:r}}function fRe(n,e,t){function r(i){let o=n.sqr(i),s=n.mul(o,i);return n.add(n.add(s,n.mul(i,e)),t)}return r}function hRe(n,e){let{Fp:t,Fn:r}=e;function i(s){return Uee(s,q0,r.ORDER)}let o=fRe(t,n.a,n.b);return Object.assign({},{CURVE:n,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:s=>Id(r,s),weierstrassEquation:o,isWithinCurveOrder:i})}function pRe(n,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},n,zee(t.Fn.ORDER,t.Fn.BITS))})}function mRe(n){let{CURVE:e,curveOpts:t,hash:r,ecdsaOpts:i}=dRe(n),o=ete(e,t),s=lRe(o,r,i);return pRe(n,s)}var gRe=BigInt(0),ZC=BigInt(1),bee=BigInt(2),Qy=BigInt(3);function yRe(n){let e=[];for(;n>ZC;n>>=ZC)(n&ZC)===gRe?e.unshift(0):(n&Qy)===Qy?(e.unshift(-1),n+=ZC):e.unshift(1);return e}function AO(n){if(!Array.isArray(n)||n.length===0)throw new Error("expected non-empty array")}function wRe(n,e,t,r){let{Fp2:i,Fp12:o}=n,{twistType:s,ateLoopSize:a,xNegative:c,postPrecompute:u}=r,l;if(s==="multiplicative")l=(G,U,H,M,A,D)=>o.mul014(M,G,i.mul(U,A),i.mul(H,D));else if(s==="divisive")l=(G,U,H,M,A,D)=>o.mul034(M,i.mul(H,D),i.mul(U,A),G);else throw new Error("bls: unknown twist type");let d=i.div(i.ONE,i.mul(i.ONE,bee));function h(G,U,H,M){let A=i.sqr(H),D=i.sqr(M),z=i.mulByB(i.mul(D,Qy)),j=i.mul(z,Qy),Y=i.sub(i.sub(i.sqr(i.add(H,M)),D),A),Q=i.sub(z,A),v=i.mul(i.sqr(U),Qy),p=i.neg(Y);return G.push([Q,v,p]),U=i.mul(i.mul(i.mul(i.sub(A,j),U),H),d),H=i.sub(i.sqr(i.mul(i.add(A,j),d)),i.mul(i.sqr(z),Qy)),M=i.mul(A,Y),{Rx:U,Ry:H,Rz:M}}function f(G,U,H,M,A,D){let z=i.sub(H,i.mul(D,M)),j=i.sub(U,i.mul(A,M)),Y=i.sub(i.mul(z,A),i.mul(j,D)),Q=i.neg(z),v=j;G.push([Y,Q,v]);let p=i.sqr(j),x=i.mul(p,j),y=i.mul(p,U),I=i.add(i.sub(x,i.mul(y,bee)),i.mul(i.sqr(z),M));return U=i.mul(j,I),H=i.sub(i.mul(i.sub(y,I),z),i.mul(x,H)),M=i.mul(M,x),{Rx:U,Ry:H,Rz:M}}let m=yRe(a),w=TO(G=>{let U=G,{x:H,y:M}=U.toAffine(),A=H,D=M,z=i.neg(M),j=A,Y=D,Q=i.ONE,v=[];for(let p of m){let x=[];({Rx:j,Ry:Y,Rz:Q}=h(x,j,Y,Q)),p&&({Rx:j,Ry:Y,Rz:Q}=f(x,j,Y,Q,A,p===-1?z:D)),v.push(x)}if(u){let p=v[v.length-1];u(j,Y,Q,A,D,f.bind(null,p))}return v});function b(G,U=!1){let H=o.ONE;if(G.length){let M=G[0][0].length;for(let A=0;A<M;A++){H=o.sqr(H);for(let[D,z,j]of G)for(let[Y,Q,v]of D[A])H=l(Y,Q,v,H,z,j)}}return c&&(H=o.conjugate(H)),U?o.finalExponentiate(H):H}function S(G,U=!0){let H=[];jE(e,G.map(({g1:M})=>M)),jE(t,G.map(({g2:M})=>M));for(let{g1:M,g2:A}of G){if(M.is0()||A.is0())throw new Error("pairing is not available for ZERO point");M.assertValidity(),A.assertValidity();let D=M.toAffine();H.push([w(A),D.x,D.y])}return b(H,U)}function R(G,U,H=!0){return S([{g1:G,g2:U}],H)}return{Fp12:o,millerLoopBatch:b,pairing:R,pairingBatch:S,calcPairingPrecomputes:w}}function Eee(n,e,t,r,i){let{Fp12:o,pairingBatch:s}=n;function a(d){return d instanceof e.Point?d:e.Point.fromHex(d)}function c(d){return d instanceof t.Point?d:t.Point.fromHex(d)}function u(d){if(!(d instanceof t.Point))throw new Error(`expected valid message hashed to ${i?"G1":"G2"} curve`);return d}let l=i?(d,h)=>({g1:h,g2:d}):(d,h)=>({g1:d,g2:h});return{getPublicKey(d){let h=Id(e.Point.Fn,d);return e.Point.BASE.multiply(h)},sign(d,h,f){if(f!=null)throw new Error("sign() expects 2 arguments");let m=Id(e.Point.Fn,h);return u(d).assertValidity(),d.multiply(m)},verify(d,h,f,m){if(m!=null)throw new Error("verify() expects 3 arguments");d=c(d),f=a(f);let w=f.negate(),b=e.Point.BASE,S=u(h),R=d,G=s([l(w,S),l(b,R)]);return o.eql(G,o.ONE)},verifyBatch(d,h,f){if(AO(h),f.length!==h.length)throw new Error("amount of public keys and messages should be equal");let m=c(d),w=h,b=f.map(a),S=new Map;for(let U=0;U<b.length;U++){let H=b[U],M=w[U],A=S.get(M);A===void 0&&(A=[],S.set(M,A)),A.push(H)}let R=[],G=e.Point.BASE;try{for(let[U,H]of S){let M=H.reduce((A,D)=>A.add(D));R.push(l(M,U))}return R.push(l(G.negate(),m)),o.eql(s(R),o.ONE)}catch{return!1}},aggregatePublicKeys(d){AO(d),d=d.map(f=>a(f));let h=d.reduce((f,m)=>f.add(m),e.Point.ZERO);return h.assertValidity(),h},aggregateSignatures(d){AO(d),d=d.map(f=>c(f));let h=d.reduce((f,m)=>f.add(m),t.Point.ZERO);return h.assertValidity(),h},hash(d,h){Gc(d);let f=h?{DST:h}:void 0;return t.hashToCurve(d,f)},Signature:r}}function bRe(n){let{Fp:e,Fr:t,Fp2:r,Fp6:i,Fp12:o}=n.fields,s=wee(n.G1),a=Object.assign(s,gee(s.Point,n.G1.mapToCurve,{...n.htfDefaults,...n.G1.htfDefaults})),c=wee(n.G2),u=Object.assign(c,gee(c.Point,n.G2.mapToCurve,{...n.htfDefaults,...n.G2.htfDefaults})),l=wRe(n.fields,a.Point,u.Point,{...n.params,postPrecompute:n.postPrecompute}),{millerLoopBatch:d,pairing:h,pairingBatch:f,calcPairingPrecomputes:m}=l,w=Eee(l,a,u,n.G2.Signature,!1),b=Eee(l,u,a,n.G1.ShortSignature,!0),S=n.randomBytes||zO,R=()=>{let C=ZO(t.ORDER);return jee(S(C),t.ORDER)},G={randomSecretKey:R,randomPrivateKey:R,calcPairingPrecomputes:m},{ShortSignature:U}=n.G1,{Signature:H}=n.G2;function M(C,F){return C instanceof a.Point?C:b.hash(ao("point",C),F?.DST)}function A(C,F){return C instanceof u.Point?C:w.hash(ao("point",C),F?.DST)}function D(C){return w.getPublicKey(C).toBytes(!0)}function z(C){return b.getPublicKey(C).toBytes(!0)}function j(C,F,N){let O=A(C,N),T=w.sign(O,F);return C instanceof u.Point?T:H.toBytes(T)}function Y(C,F,N){let O=M(C,N),T=b.sign(O,F);return C instanceof a.Point?T:U.toBytes(T)}function Q(C,F,N,O){let T=A(F,O);return w.verify(C,T,N)}function v(C,F,N,O){let T=M(F,O);return b.verify(C,T,N)}function p(C){let F=w.aggregatePublicKeys(C);return C[0]instanceof a.Point?F:F.toBytes(!0)}function x(C){let F=w.aggregateSignatures(C);return C[0]instanceof u.Point?F:H.toBytes(F)}function y(C){let F=b.aggregateSignatures(C);return C[0]instanceof a.Point?F:U.toBytes(F)}function I(C,F,N,O){let T=F.map(q=>A(q,O));return w.verifyBatch(C,T,N)}return a.Point.BASE.precompute(4),{longSignatures:w,shortSignatures:b,millerLoopBatch:d,pairing:h,pairingBatch:f,verifyBatch:I,fields:{Fr:t,Fp:e,Fp2:r,Fp6:i,Fp12:o},params:{ateLoopSize:n.params.ateLoopSize,twistType:n.params.twistType,r:n.params.r,G1b:n.G1.b,G2b:n.G2.b},utils:G,getPublicKey:D,getPublicKeyForShortSignatures:z,sign:j,signShortSignature:Y,verify:Q,verifyShortSignature:v,aggregatePublicKeys:p,aggregateSignatures:x,aggregateShortSignatures:y,G1:a,G2:u,Signature:H,ShortSignature:U}}var Iee=BigInt(0),Ad=BigInt(1),jo=BigInt(2),Aee=BigInt(3);function XO(n,e,t,r,i=1,o){let s=BigInt(o===void 0?r:o),a=t**BigInt(r),c=[];for(let u=0;u<i;u++){let l=BigInt(u+1),d=[];for(let h=0,f=Ad;h<r;h++){let m=(l*f-l)/s%a;d.push(n.pow(e,m)),f*=t}c.push(d)}return c}function ERe(n,e,t){let r=e.pow(t,(n.ORDER-Ad)/Aee),i=e.pow(t,(n.ORDER-Ad)/jo);function o(h,f){let m=e.mul(e.frobeniusMap(h,1),r),w=e.mul(e.frobeniusMap(f,1),i);return[m,w]}let s=e.pow(t,(n.ORDER**jo-Ad)/Aee),a=e.pow(t,(n.ORDER**jo-Ad)/jo);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(h,f){return[e.mul(h,s),e.neg(f)]}let u=h=>(f,m)=>{let w=m.toAffine(),b=h(w.x,w.y);return f.fromAffine({x:b[0],y:b[1]})},l=u(o),d=u(c);return{psi:o,psi2:c,G2psi:l,G2psi2:d,PSI_X:r,PSI_Y:i,PSI2_X:s,PSI2_Y:a}}var xee=(n,e)=>{if(e.length!==2)throw new Error("invalid tuple");let t=e.map(r=>n.create(r));return{c0:t[0],c1:t[1]}},MO=class{constructor(e,t={}){this.MASK=Ad;let r=e.ORDER,i=r*r;this.Fp=e,this.ORDER=i,this.BITS=WE(i),this.BYTES=Math.ceil(WE(i)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(t.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,jo),this.NONRESIDUE=xee(e,t.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=XO(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=t.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return xee(this.Fp,e)}create(e){return e}isValid({c0:e,c1:t}){function r(i,o){return typeof i=="bigint"&&Iee<=i&&i<o}return r(e,this.ORDER)&&r(t,this.ORDER)}is0({c0:e,c1:t}){return this.Fp.is0(e)&&this.Fp.is0(t)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:t},{c0:r,c1:i}){return this.Fp.eql(e,r)&&this.Fp.eql(t,i)}neg({c0:e,c1:t}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(t)}}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}add(e,t){let{c0:r,c1:i}=e,{c0:o,c1:s}=t;return{c0:this.Fp.add(r,o),c1:this.Fp.add(i,s)}}sub({c0:e,c1:t},{c0:r,c1:i}){return{c0:this.Fp.sub(e,r),c1:this.Fp.sub(t,i)}}mul({c0:e,c1:t},r){let{Fp:i}=this;if(typeof r=="bigint")return{c0:i.mul(e,r),c1:i.mul(t,r)};let{c0:o,c1:s}=r,a=i.mul(e,o),c=i.mul(t,s),u=i.sub(a,c),l=i.sub(i.mul(i.add(e,t),i.add(o,s)),i.add(a,c));return{c0:u,c1:l}}sqr({c0:e,c1:t}){let{Fp:r}=this,i=r.add(e,t),o=r.sub(e,t),s=r.add(e,e);return{c0:r.mul(i,o),c1:r.mul(s,t)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}div(e,t){let{Fp:r}=this;return this.mul(e,typeof t=="bigint"?r.inv(r.create(t)):this.inv(t))}inv({c0:e,c1:t}){let{Fp:r}=this,i=r.inv(r.create(e*e+t*t));return{c0:r.mul(i,r.create(e)),c1:r.mul(i,r.create(-t))}}sqrt(e){let{Fp:t}=this,r=this,{c0:i,c1:o}=e;if(t.is0(o))return o8(t,i)===1?r.create({c0:t.sqrt(i),c1:t.ZERO}):r.create({c0:t.ZERO,c1:t.sqrt(t.div(i,this.Fp_NONRESIDUE))});let s=t.sqrt(t.sub(t.sqr(i),t.mul(t.sqr(o),this.Fp_NONRESIDUE))),a=t.mul(t.add(s,i),this.Fp_div2);o8(t,a)===-1&&(a=t.sub(a,s));let u=t.sqrt(a),l=r.create({c0:u,c1:t.div(t.mul(o,this.Fp_div2),u)});if(!r.eql(r.sqr(l),e))throw new Error("Cannot find square root");let d=l,h=r.neg(d),{re:f,im:m}=r.reim(d),{re:w,im:b}=r.reim(h);return m>b||m===b&&f>w?d:h}isOdd(e){let{re:t,im:r}=this.reim(e),i=t%jo,o=t===Iee,s=r%jo;return BigInt(i||o&&s)==Ad}fromBytes(e){let{Fp:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:t.fromBytes(e.subarray(0,t.BYTES)),c1:t.fromBytes(e.subarray(t.BYTES))}}toBytes({c0:e,c1:t}){return Fi(this.Fp.toBytes(e),this.Fp.toBytes(t))}cmov({c0:e,c1:t},{c0:r,c1:i},o){return{c0:this.Fp.cmov(e,r,o),c1:this.Fp.cmov(t,i,o)}}reim({c0:e,c1:t}){return{re:e,im:t}}Fp4Square(e,t){let r=this,i=r.sqr(e),o=r.sqr(t);return{first:r.add(r.mulByNonresidue(o),i),second:r.sub(r.sub(r.sqr(r.add(e,t)),i),o)}}mulByNonresidue({c0:e,c1:t}){return this.mul({c0:e,c1:t},this.NONRESIDUE)}frobeniusMap({c0:e,c1:t},r){return{c0:e,c1:this.Fp.mul(t,this.FROBENIUS_COEFFICIENTS[r%2])}}},OO=class{constructor(e){this.MASK=Ad,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:t}=e,r=XO(e,e.NONRESIDUE,t.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=r[0],this.FROBENIUS_COEFFICIENTS_2=r[1],Object.seal(this)}add({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return{c0:a.add(e,i),c1:a.add(t,o),c2:a.add(r,s)}}sub({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return{c0:a.sub(e,i),c1:a.sub(t,o),c2:a.sub(r,s)}}mul({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;if(typeof i=="bigint")return{c0:o.mul(e,i),c1:o.mul(t,i),c2:o.mul(r,i)};let{c0:s,c1:a,c2:c}=i,u=o.mul(e,s),l=o.mul(t,a),d=o.mul(r,c);return{c0:o.add(u,o.mulByNonresidue(o.sub(o.mul(o.add(t,r),o.add(a,c)),o.add(l,d)))),c1:o.add(o.sub(o.mul(o.add(e,t),o.add(s,a)),o.add(u,l)),o.mulByNonresidue(d)),c2:o.sub(o.add(l,o.mul(o.add(e,r),o.add(s,c))),o.add(u,d))}}sqr({c0:e,c1:t,c2:r}){let{Fp2:i}=this,o=i.sqr(e),s=i.mul(i.mul(e,t),jo),a=i.mul(i.mul(t,r),jo),c=i.sqr(r);return{c0:i.add(i.mulByNonresidue(a),o),c1:i.add(i.mulByNonresidue(c),s),c2:i.sub(i.sub(i.add(i.add(s,i.sqr(i.add(i.sub(e,t),r))),a),o),c)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}create(e){return e}isValid({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return i.isValid(e)&&i.isValid(t)&&i.isValid(r)}is0({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return i.is0(e)&&i.is0(t)&&i.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return{c0:i.neg(e),c1:i.neg(t),c2:i.neg(r)}}eql({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s}){let{Fp2:a}=this;return a.eql(e,i)&&a.eql(t,o)&&a.eql(r,s)}sqrt(e){return ui()}div(e,t){let{Fp2:r}=this,{Fp:i}=r;return this.mul(e,typeof t=="bigint"?i.inv(i.create(t)):this.inv(t))}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}inv({c0:e,c1:t,c2:r}){let{Fp2:i}=this,o=i.sub(i.sqr(e),i.mulByNonresidue(i.mul(r,t))),s=i.sub(i.mulByNonresidue(i.sqr(r)),i.mul(e,t)),a=i.sub(i.sqr(t),i.mul(e,r)),c=i.inv(i.add(i.mulByNonresidue(i.add(i.mul(r,s),i.mul(t,a))),i.mul(e,o)));return{c0:i.mul(c,o),c1:i.mul(c,s),c2:i.mul(c,a)}}fromBytes(e){let{Fp2:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let r=t.BYTES;return{c0:t.fromBytes(e.subarray(0,r)),c1:t.fromBytes(e.subarray(r,r*2)),c2:t.fromBytes(e.subarray(2*r))}}toBytes({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return Fi(i.toBytes(e),i.toBytes(t),i.toBytes(r))}cmov({c0:e,c1:t,c2:r},{c0:i,c1:o,c2:s},a){let{Fp2:c}=this;return{c0:c.cmov(e,i,a),c1:c.cmov(t,o,a),c2:c.cmov(r,s,a)}}fromBigSix(e){let{Fp2:t}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:t.fromBigTuple(e.slice(0,2)),c1:t.fromBigTuple(e.slice(2,4)),c2:t.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.frobeniusMap(e,i),c1:o.mul(o.frobeniusMap(t,i),this.FROBENIUS_COEFFICIENTS_1[i%6]),c2:o.mul(o.frobeniusMap(r,i),this.FROBENIUS_COEFFICIENTS_2[i%6])}}mulByFp2({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.mul(e,i),c1:o.mul(t,i),c2:o.mul(r,i)}}mulByNonresidue({c0:e,c1:t,c2:r}){let{Fp2:i}=this;return{c0:i.mulByNonresidue(r),c1:e,c2:t}}mul1({c0:e,c1:t,c2:r},i){let{Fp2:o}=this;return{c0:o.mulByNonresidue(o.mul(r,i)),c1:o.mul(e,i),c2:o.mul(t,i)}}mul01({c0:e,c1:t,c2:r},i,o){let{Fp2:s}=this,a=s.mul(e,i),c=s.mul(t,o);return{c0:s.add(s.mulByNonresidue(s.sub(s.mul(s.add(t,r),o),c)),a),c1:s.sub(s.sub(s.mul(s.add(i,o),s.add(e,t)),a),c),c2:s.add(s.sub(s.mul(s.add(e,r),i),a),c)}}},FO=class{constructor(e,t){this.MASK=Ad;let{Fp2:r}=e,{Fp:i}=r;this.Fp6=e,this.ORDER=r.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=XO(r,r.NONRESIDUE,i.ORDER,12,1,6)[0],this.X_LEN=t.X_LEN,this.finalExponentiate=t.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:t}){let{Fp6:r}=this;return r.isValid(e)&&r.isValid(t)}is0({c0:e,c1:t}){let{Fp6:r}=this;return r.is0(e)&&r.is0(t)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:t}){let{Fp6:r}=this;return{c0:r.neg(e),c1:r.neg(t)}}eql({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return o.eql(e,r)&&o.eql(t,i)}sqrt(e){ui()}inv({c0:e,c1:t}){let{Fp6:r}=this,i=r.inv(r.sub(r.sqr(e),r.mulByNonresidue(r.sqr(t))));return{c0:r.mul(e,i),c1:r.neg(r.mul(t,i))}}div(e,t){let{Fp6:r}=this,{Fp2:i}=r,{Fp:o}=i;return this.mul(e,typeof t=="bigint"?o.inv(o.create(t)):this.inv(t))}pow(e,t){return l8(this,e,t)}invertBatch(e){return rI(this,e)}add({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return{c0:o.add(e,r),c1:o.add(t,i)}}sub({c0:e,c1:t},{c0:r,c1:i}){let{Fp6:o}=this;return{c0:o.sub(e,r),c1:o.sub(t,i)}}mul({c0:e,c1:t},r){let{Fp6:i}=this;if(typeof r=="bigint")return{c0:i.mul(e,r),c1:i.mul(t,r)};let{c0:o,c1:s}=r,a=i.mul(e,o),c=i.mul(t,s);return{c0:i.add(a,i.mulByNonresidue(c)),c1:i.sub(i.mul(i.add(e,t),i.add(o,s)),i.add(a,c))}}sqr({c0:e,c1:t}){let{Fp6:r}=this,i=r.mul(e,t);return{c0:r.sub(r.sub(r.mul(r.add(r.mulByNonresidue(t),e),r.add(e,t)),i),r.mulByNonresidue(i)),c1:r.add(i,i)}}addN(e,t){return this.add(e,t)}subN(e,t){return this.sub(e,t)}mulN(e,t){return this.mul(e,t)}sqrN(e){return this.sqr(e)}fromBytes(e){let{Fp6:t}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:t.fromBytes(e.subarray(0,t.BYTES)),c1:t.fromBytes(e.subarray(t.BYTES))}}toBytes({c0:e,c1:t}){let{Fp6:r}=this;return Fi(r.toBytes(e),r.toBytes(t))}cmov({c0:e,c1:t},{c0:r,c1:i},o){let{Fp6:s}=this;return{c0:s.cmov(e,r,o),c1:s.cmov(t,i,o)}}fromBigTwelve(e){let{Fp6:t}=this;return{c0:t.fromBigSix(e.slice(0,6)),c1:t.fromBigSix(e.slice(6,12))}}frobeniusMap(e,t){let{Fp6:r}=this,{Fp2:i}=r,{c0:o,c1:s,c2:a}=r.frobeniusMap(e.c1,t),c=this.FROBENIUS_COEFFICIENTS[t%12];return{c0:r.frobeniusMap(e.c0,t),c1:r.create({c0:i.mul(o,c),c1:i.mul(s,c),c2:i.mul(a,c)})}}mulByFp2({c0:e,c1:t},r){let{Fp6:i}=this;return{c0:i.mulByFp2(e,r),c1:i.mulByFp2(t,r)}}conjugate({c0:e,c1:t}){return{c0:e,c1:this.Fp6.neg(t)}}mul014({c0:e,c1:t},r,i,o){let{Fp6:s}=this,{Fp2:a}=s,c=s.mul01(e,r,i),u=s.mul1(t,o);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(s.sub(s.mul01(s.add(t,e),r,a.add(i,o)),c),u)}}mul034({c0:e,c1:t},r,i,o){let{Fp6:s}=this,{Fp2:a}=s,c=s.create({c0:a.mul(e.c0,r),c1:a.mul(e.c1,r),c2:a.mul(e.c2,r)}),u=s.mul01(t,i,o),l=s.mul01(s.add(e,t),a.add(r,i),o);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(l,s.add(c,u))}}_cyclotomicSquare({c0:e,c1:t}){let{Fp6:r}=this,{Fp2:i}=r,{c0:o,c1:s,c2:a}=e,{c0:c,c1:u,c2:l}=t,{first:d,second:h}=i.Fp4Square(o,u),{first:f,second:m}=i.Fp4Square(c,a),{first:w,second:b}=i.Fp4Square(s,l),S=i.mulByNonresidue(b);return{c0:r.create({c0:i.add(i.mul(i.sub(d,o),jo),d),c1:i.add(i.mul(i.sub(f,s),jo),f),c2:i.add(i.mul(i.sub(w,a),jo),w)}),c1:r.create({c0:i.add(i.mul(i.add(S,c),jo),S),c1:i.add(i.mul(i.add(h,u),jo),h),c2:i.add(i.mul(i.add(m,l),jo),m)})}}_cyclotomicExp(e,t){let r=this.ONE;for(let i=this.X_LEN-1;i>=0;i--)r=this._cyclotomicSquare(r),KLe(t,i)&&(r=this.mul(r,e));return r}};function IRe(n){let e=jy(n.ORDER),t=new MO(e,n),r=new OO(t),i=new FO(r,n);return{Fp:e,Fp2:t,Fp6:r,Fp12:i}}var ARe=BigInt(0),NO=BigInt(1),ite=BigInt(2),xRe=BigInt(3),ote=BigInt(6),d8=BigInt("4965661367192848881"),vRe=WE(d8),SRe=ote*d8**ite,f8={p:BigInt("0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"),n:BigInt("0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"),h:NO,a:ARe,b:xRe,Gx:NO,Gy:BigInt(2)},vee=jy(f8.n),ste={c0:BigInt("19485874751759354771024239261021720505790618469301721065564631296452457478373"),c1:BigInt("266929791119991161246907387137283842545076965332900288569378510910307636690")},{Fp:XE,Fp2:Ju,Fp6:CRe,Fp12:zn}=IRe({ORDER:f8.p,X_LEN:vRe,FP2_NONRESIDUE:[BigInt(9),NO],Fp2mulByB:n=>Ju.mul(n,ste),Fp12finalExponentiate:n=>{let e=l=>zn.conjugate(zn._cyclotomicExp(l,d8)),t=zn.mul(zn.conjugate(n),zn.inv(n)),r=zn.mul(zn.frobeniusMap(t,2),t),i=zn._cyclotomicSquare(e(r)),o=zn.mul(zn._cyclotomicSquare(i),i),s=e(o),a=e(zn._cyclotomicSquare(s)),c=zn.mul(zn.mul(zn.conjugate(a),s),zn.conjugate(o)),u=zn.mul(c,i);return zn.mul(zn.frobeniusMap(zn.mul(zn.conjugate(r),u),3),zn.mul(zn.frobeniusMap(c,2),zn.mul(zn.frobeniusMap(u,1),zn.mul(zn.mul(c,s),r))))}}),{G2psi:LRe,psi:See}=ERe(XE,Ju,Ju.NONRESIDUE),xO=Object.freeze({DST:"BN254G2_XMD:SHA-256_SVDW_RO_",encodeDST:"BN254G2_XMD:SHA-256_SVDW_RO_",p:XE.ORDER,m:2,k:128,expand:"xmd",hash:Mee}),RRe=(n,e,t,r,i,o)=>{let s=See(r,i);({Rx:n,Ry:e,Rz:t}=o(n,e,t,s[0],s[1]));let a=See(s[0],s[1]);o(n,e,t,a[0],Ju.neg(a[1]))},DRe={p:Ju.ORDER,n:f8.n,h:BigInt("0x30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d"),a:Ju.ZERO,b:ste,Gx:Ju.fromBigTuple([BigInt("10857046999023057135944570762232829481370756359578518086990519993285655852781"),BigInt("11559732032986387107991004021392285783925812861821192530917403151452391805634")]),Gy:Ju.fromBigTuple([BigInt("8495653923123431417604973247489272438418190587263600148770280649306958101930"),BigInt("4082367875863433681332203403145435568316851327593401208105741076214120093531")])},V0=bRe({fields:{Fp:XE,Fp2:Ju,Fp6:CRe,Fp12:zn,Fr:vee},G1:{...f8,Fp:XE,htfDefaults:{...xO,m:1,DST:"BN254G2_XMD:SHA-256_SVDW_RO_"},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:ui,fromBytes:ui,toBytes:ui,ShortSignature:{fromBytes:ui,fromHex:ui,toBytes:ui,toRawBytes:ui,toHex:ui}},G2:{...DRe,Fp:Ju,hEff:BigInt("21888242871839275222246405745257275088844257914179612981679871602714643921549"),htfDefaults:{...xO},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(n,e)=>e.multiplyUnsafe(SRe).equals(LRe(n,e)),mapToCurve:ui,fromBytes:ui,toBytes:ui,Signature:{fromBytes:ui,fromHex:ui,toBytes:ui,toRawBytes:ui,toHex:ui}},params:{ateLoopSize:d8*ote+ite,r:vee.ORDER,xNegative:!1,twistType:"divisive"},htfDefaults:xO,postPrecompute:RRe});mRe({a:BigInt(0),b:BigInt(3),Fp:XE,n:BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"),Gx:BigInt(1),Gy:BigInt(2),h:BigInt(1),hash:Mee});var h8="groth16",TRe="auth",BRe="authV2",PRe="authV3",kRe="authV3-8-32",MRe=new TextDecoder,Cee=BigInt(0),Lee=V0.fields.Fp2,Ree=V0.fields.Fp12;async function _O(n,e,t){let r=await DLe(t),i=new TextDecoder().decode(n),o=JSON.parse(i),s=await r.calculateWTNSBin(o,0),{proof:a,publicSignals:c}=await YC.prove(e,s);return{proof:a,pub_signals:c}}var[UO,ORe]=[V0.G1.ProjectivePoint,V0.G2.ProjectivePoint],XC=([n,e])=>UO.fromAffine({x:BigInt(n),y:BigInt(e)}),_C=([[n,e],[t,r]])=>ORe.fromAffine({x:Lee.fromBigTuple([BigInt(n),BigInt(e)]),y:Lee.fromBigTuple([BigInt(t),BigInt(r)])});async function $O(n,e,t,r){if(r(e.pub_signals).challenge!==qI(n))throw new Error("challenge is not equal to message hash");let o=JSON.parse(MRe.decode(t));return eF(e,o)}function eF(n,e){if(!e.IC)throw new Error("verification file doesn't exist for circuit");let{proof:t,pub_signals:r}=n;if(r.length+1!==e.IC.length)throw new Error(`Invalid number of public signals, expected ${e.IC.length-1} but got ${r.length}`);let i=UO.ZERO;for(let s=0;s<r.length;s++){if(BigInt(r[s])<Cee||BigInt(r[s])>=V0.G1.CURVE.n)throw new Error(`Input value is not in the field ${V0.G1.CURVE.n}`);if(BigInt(r[s])!==Cee){let[a,c]=e.IC[s+1].map(BigInt);i=i.add(UO.fromAffine({x:a,y:c}).multiply(BigInt(r[s])))}}i=i.add(XC(e.IC[0]));let o=V0.pairingBatch([{g1:XC(t.pi_a).negate(),g2:_C(t.pi_b)},{g1:i,g2:_C(e.vk_gamma_2)},{g1:XC(t.pi_c),g2:_C(e.vk_delta_2)},{g1:XC(e.vk_alpha_1),g2:_C(e.vk_beta_2)}]);return Ree.eql(o,Ree.ONE)}var GO=class{methodAlg;constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}unmarshall(e){let t={};if(e.length!=3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return t.challenge=BigInt(e[0]),t.userState=BigInt(e[1]),t.userId=Xe.fromBigInt(BigInt(e[2])),t}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}prove(e,t,r){return _O(e,t,r)}},HO=new GO(new Uc(h8,TRe)),KO=class n{methodAlg;static curveName="bn128";constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}async prove(e,t,r){let i=await _O(e,t,r);return await this.terminateCurve(),i}async terminateCurve(){(await VE(n.curveName)).terminate()}unmarshall(e){if(e.length!==3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return{userID:Xe.fromBigInt(BigInt(e[0])),challenge:BigInt(e[1]),GISTRoot:be.fromString(e[2])}}},JO=new KO(new Uc(h8,BRe)),c8=class n{methodAlg;static curveName="bn128";constructor(e){this.methodAlg=e}get alg(){return this.methodAlg.alg}get circuitId(){return this.methodAlg.circuitId}async verify(e,t,r){return $O(e,t,r,this.unmarshall)}async prove(e,t,r){let i=await _O(e,t,r);return await this.terminateCurve(),i}async terminateCurve(){(await VE(n.curveName)).terminate()}unmarshall(e){if(e.length!==3)throw new Error(`invalid number of Output values expected 3 got ${e.length}`);return{userID:Xe.fromBigInt(BigInt(e[0])),challenge:BigInt(e[1]),GISTRoot:be.fromString(e[2])}}},qO=new c8(new Uc(h8,PRe)),VO=new c8(new Uc(h8,kRe));_E(HO.methodAlg,()=>HO);_E(JO.methodAlg,()=>JO);_E(qO.methodAlg,()=>qO);_E(VO.methodAlg,()=>VO);var Q0={registerProvingMethod:_E,getProvingMethod:Bee,provingMethodGroth16AuthInstance:HO,provingMethodGroth16AuthV2Instance:JO,provingMethodGroth16AuthV3Instance:qO,provingMethodGroth16AuthV3_8_32Instance:VO};var ate="unknown circuit ID. can't verify msg sender",p8="sender of message is not used for jwz token creation",cte="message was packed with unsupported circuit",ute="message proof is invalid",lte="message state verification failed",dte="unknown proving method algorithm";var{getProvingMethod:FRe}=Q0,iI=class{constructor(e){this.dataPrepareFunc=e}prepare(e,t,r){return this.dataPrepareFunc(e,t,r)}},oI=class{constructor(e){this.stateVerificationFunc=e}verify(e,t,r){return this.stateVerificationFunc(e,t,r)}},sI=class{constructor(e,t,r={acceptedStateTransitionDelay:pM}){this.provingParamsMap=e;this.verificationParamsMap=t;this._opts=r;let i=Array.from(this.provingParamsMap.keys()).map(s=>s.split(":")[1]),o=Array.from(this.verificationParamsMap.keys()).map(s=>s.split(":")[1]);this.supportedCircuitIds=[...new Set([...i,...o])]}supportedProtocolVersions=["iden3comm/v1"];supportedAlgorithms=["groth16"];supportedCircuitIds;packMessage(e,t){return this.pack(ke.encode(JSON.stringify(e)),t)}async pack(e,t){let r=await FRe(t.provingMethodAlg),i=this.provingParamsMap.get(t.provingMethodAlg.toString());if(!i)throw new Error(dte);let o=new wh(r,lt.decode(e),(a,c)=>i?.dataPreparer?.prepare(a,t.senderDID,c));o.setHeader(Ha.Type,"application/iden3-zkp-json");let s=await o.prove(i.provingKey,i.wasm);return ke.encode(s)}async unpackMessage(e,t){let r=this.verificationParamsMap.get(t.toString());if(!r?.key)throw new Error(cte);if(!await e.verify(r?.key))throw new Error(ute);if(!await r?.verificationFn?.verify(e.circuitId,e.zkProof.pub_signals,this._opts))throw new Error(lte);let s=JSON.parse(e.getPayload());return await NRe(e,s),s}parseToken(e){return wh.parse(lt.decode(e))}async unpack(e){let t=await this.parseToken(e),r=new Uc(t.alg,t.circuitId);return this.unpackMessage(t,r)}mediaType(){return"application/iden3-zkp-json"}getSupportedProfiles(){return this.supportedProtocolVersions.map(e=>`${e};env=${this.mediaType()};alg=${this.supportedAlgorithms.join(",")};circuitIds=${this.supportedCircuitIds.join(",")}`)}isProfileSupported(e){let{protocolVersion:t,env:r,circuits:i,alg:o}=xs(e);if(!this.supportedProtocolVersions.includes(t)||r!==this.mediaType())return!1;let s=this.supportedCircuitIds,a=!i?.length||i.some(l=>s.includes(l)),c=this.supportedAlgorithms;return(!o?.length||o.some(l=>c.includes(l)))&&a}},NRe=async(n,e)=>{switch(n.circuitId){case"authV2":case"authV3-8-32":case"authV3":{if(!e.from)throw new Error(p8);let t=(n.circuitId==="authV2"?new Zs:new Gu).pubSignalsUnmarshal(ke.encode(JSON.stringify(n.zkProof.pub_signals))),r=ve.parseFromId(t.userID),i=await n.getMessageHash();if(It.bytesToInt(i.reverse())!==t.challenge)throw new Error(p8);if(e.from!==r.string())throw new Error(p8)}break;default:throw new Error(ate)}};var tF=class extends sI{constructor(t,r,i){super(new Map,new Map,{...i});this.circuitStorage=t;this.proofService=r;this.supportedCircuitIds=["authV2","authV3","authV3-8-32"]}async pack(t,r){let i=r.provingMethodAlg,o=i.circuitId,s=i.toString();if(!this.provingParamsMap.has(s)){let{provingKey:a,wasm:c}=await this.circuitStorage.loadCircuitData(o,{mode:"proving"});if(!a||!c)throw new Error(`circuit data not found for circuit id: ${o}`);this.provingParamsMap.set(s,{provingKey:a,wasm:c,dataPreparer:new iI(this.proofService.generateAuthInputs.bind(this.proofService))})}return super.pack(t,r)}async unpack(t){let r=await this.parseToken(t),i=r.circuitId,o=new Uc(r.alg,i);if(!this.verificationParamsMap.has(o.toString())){let{verificationKey:s}=await this.circuitStorage.loadCircuitData(i,{mode:"verification"});if(!s)throw new Error(`verification key not found for circuit id: ${i}`);this.verificationParamsMap.set(o.toString(),{key:s,verificationFn:new oI(this.proofService.verifyState.bind(this.proofService))})}return super.unpackMessage(r,o)}};var fte=(r=>(r.Pending="pending",r.Completed="completed",r.Rejected="rejected",r))(fte||{});var nF=(o=>(o.AUTHV2="authV2",o.AUTHV3="authV3",o.AUTHV3_8_32="authV3-8-32",o.ETH_IDENTITY="ethIdentity",o.EMBEDDED_AUTH="embeddedAuth",o))(nF||{});var hte=(e=>(e.FeatureType="feature-type",e))(hte||{}),pte=(i=>(i.Accept="accept",i.Protocol="protocol",i.GoalCode="goal-code",i.Header="header",i))(pte||{});var Kc=Q0.provingMethodGroth16AuthV2Instance.methodAlg,Ni=class{nextMessageHandler;setNext(e){return this.nextMessageHandler=e,e}async handle(e,t){return t.allowExpiredMessages||Lr(e),this.nextMessageHandler?this.nextMessageHandler.handle(e,t):Promise.reject("Message handler not provided or message not supported")}},rF=class{constructor(e){this._params=e;this.registerHandlers(e.messageHandlers)}messageHandler;registerHandlers(e){if(!e.length)return;let[t,...r]=e,i=t;for(let o of r){let s=i;for(;s.nextMessageHandler;)s=s.nextMessageHandler;s.setNext(o)}this.messageHandler?this.messageHandler.setNext(t):this.messageHandler=t}async handleMessage(e,t){let{unpackedMediaType:r,unpackedMessage:i}=await this._params.packageManager.unpack(e);if(!this.messageHandler)return Promise.reject(new Error("Message handler not provided"));r==="application/iden3-zkp-json"&&(t.messageProvingMethodAlg=await Hc(e));let o=await this.messageHandler.handle(i,t);if(!o)return null;let s={},a=t?.senderDid;return r==="application/iden3-zkp-json"&&a?(s={senderDID:a,provingMethodAlg:await Hc(e)},this._params.packageManager.packMessage(r,o,s)):this._params.packageManager.packMessage("application/iden3comm-plain-json",o,s)}};async function Hc(n){try{let e=lt.decode(n);return(await wh.parse(e)).method.methodAlg}catch{return Kc}}var URe=n=>n.reduce((e,t)=>{let r=t.query;if(!r)return e;let i=r.groupId;if(!i)return e;let o=e.get(i);if(!o){let a=Qc(12),u=new DataView(a.buffer).getUint32(0);return e.set(i,{query:r,linkNonce:u}),e}let s=C4(o.query.credentialSubject,r.credentialSubject);return e.set(i,{...o,query:{skipClaimRevocationCheck:o.query.skipClaimRevocationCheck||r.skipClaimRevocationCheck,...o.query,credentialSubject:s}}),e},new Map),Wy=async(n,e,t,r,i)=>{let o=e??[],s=URe(o),a=new Map,c=[];for(let u of o){let l;try{if(!i.supportedCircuits.includes(u.circuitId)){if(u.optional){console.log(`Circuit ${u.circuitId} is not supported, skipping optional proof request`);continue}throw new Error(`Circuit ${u.circuitId} is not allowed`)}let h=u.query,f=h?.groupId,m=s.get(f);if(f){if(!m)throw new Error(`Invalid group id ${h?.groupId}`);let b=m.query;if(!a.has(f)){let S=await r.findCredentialByProofQuery(n,m.query);if(!S.cred){if(u.optional){console.log("No credential found for optional proof request, skipping");continue}throw new Error(Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY+`${JSON.stringify(b)}`)}a.set(f,S)}}let w=a.get(f);l=await r.generateProof(u,n,{verifierDid:t,challenge:i.challenge,skipRevocation:!!h?.skipClaimRevocationCheck,credential:w?.cred,credentialRevocationStatus:w?.revStatus,linkNonce:m?.linkNonce?BigInt(m.linkNonce):void 0,bypassCache:i.bypassProofsCache,allowExpiredCredentials:i.allowExpiredCredentials})}catch(d){let h=[Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_IDENTITY_OR_PROFILE,Ge.ERRORS.ID_WALLET_NO_CREDENTIAL_SATISFIED_QUERY,Ge.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED,Ge.ERRORS.PROOF_SERVICE_CREDENTIAL_IS_EXPIRED];if(d instanceof Error&&(h.includes(d.message)||d.message.includes(Ge.ERRORS.PROOF_SERVICE_NO_CREDENTIAL_FOR_QUERY))&&u.optional){console.log(`Error in optional proof request: ${d.message}, skipping`);continue}throw d}c.push(l)}return c},iF=async(n,e,t)=>{switch(t.acceptProfile||(t.acceptProfile=TE),t.acceptProfile.env){case"application/iden3comm-plain-json":return{authProof:{authMethod:"embeddedAuth"}};case"application/iden3-zkp-json":if(!t.acceptProfile.circuits)throw new Error("Circuit not specified in accept profile");for(let r of t.acceptProfile.circuits){if(!t.supportedCircuits.includes(r))throw new Error(`Circuit ${r} is not supported`);if(!t.senderAddress)throw new Error("Sender address is not provided");let i=mte(t.senderAddress,t.zkpResponses),o=await e.generateAuthProof(r,n,{challenge:i});return{authProof:{authMethod:r,zkp:o}}}throw new Error("Auth method is not supported");case"application/iden3comm-signed-json":if(!t.acceptProfile.alg||t.acceptProfile.alg.length===0)throw new Error("Algorithm not specified");if(t.acceptProfile.alg[0]==="ES256K-R")return{authProof:{authMethod:"ethIdentity",userDid:n}};throw new Error(`Algorithm ${t.acceptProfile.alg[0]} not supported`);default:throw new Error("Accept env not supported")}},aI=n=>{let e=n.id,t=n.pub_signals,r="0x";if(t.length===0)return{requestId:e,zkProofEncoded:r,metadata:r};let i=M0(n.proof),o=wC(t,i.a,i.b,i.c),s=mn.AbiCoder.defaultAbiCoder().encode(["string"],[n.circuitId]);return{requestId:e,zkProofEncoded:o,metadata:s}},mte=(n,e)=>{let t=e.map(r=>{let i=aI(r);return{requestId:i.requestId,proof:i.zkProofEncoded,metadata:i.metadata}});return BigInt(mn.keccak256(new mn.AbiCoder().encode(["address","(uint256 requestId,bytes proof,bytes metadata)[]"],[n,t])))&BigInt("0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},GRe=n=>new mn.AbiCoder().encode(["tuple(string key,bytes value)[]"],[n]),Lr=n=>{if(n?.expires_time&&n.expires_time<Lt(new Date))throw new Error("Message expired")},ta=(n,e,t)=>{if(n==="application/iden3comm-signed-json"||n==="application/iden3comm-encrypted-json"){if(!e)throw new Error(`packer options are required for ${n}`);return e}if(n==="application/iden3comm-plain-json")return{};if(n==="application/iden3-zkp-json"){let r={provingMethodAlg:e?.provingMethodAlg||t?.provingMethodAlg||Kc,senderDID:e?.senderDID||t?.senderDID};if(!r.senderDID)throw new Error("senderDID is required for ZKPMessage");return r}throw new Error(`unsupported media type ${n}`)};function HRe(n,e,t,r){return gte(n,"",e,t,r)}function gte(n,e,t,r,i){let o=Ut();return{id:o,thid:o,from:t,typ:"application/iden3comm-plain-json",type:at.AUTHORIZATION_REQUEST_MESSAGE_TYPE,body:{accept:i?.accept,reason:n,message:e,callbackUrl:r,scope:i?.scope??[]},created_time:Lt(new Date),expires_time:i?.expires_time?Lt(i.expires_time):void 0,attachments:i?.attachments}}var oF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._proofService=r}_supportedCircuits=Object.values(Nc);handle(t,r){switch(t.type){case at.AUTHORIZATION_REQUEST_MESSAGE_TYPE:return this.handleAuthRequest(t,r);case at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE:return this.handleAuthResponse(t,r);default:return super.handle(t,r)}}async parseAuthorizationRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.AUTHORIZATION_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i.body.scope=i.body.scope||[],i}async handleAuthRequest(t,r){if(t.type!==at.AUTHORIZATION_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for authorization request");let i=t.to?ve.parse(t.to):r.senderDid,o=Ut();if(!t.from)throw new Error("auth request should contain from field");let s=at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,a=this.getSupportedMediaTypeByProfile(r,t.body.accept),c=ve.parse(t.from),u=await Wy(i,t?.body.scope,c,this._proofService,{mediaType:a,supportedCircuits:this._supportedCircuits,bypassProofsCache:r.bypassProofsCache,allowExpiredCredentials:r.allowExpiredCredentials});return{id:o,typ:a,type:s,thid:t.thid??o,body:{message:t?.body?.message,scope:u},created_time:Lt(new Date),from:i.string(),to:t.from}}async handleAuthorizationRequest(t,r,i){let o=await this.parseAuthorizationRequest(r);i?.allowExpiredMessages||Lr(o),i||(i={mediaType:"application/iden3-zkp-json"});let s=await this.handleAuthRequest(o,{senderDid:t,mediaType:i.mediaType,bypassProofsCache:i.bypassProofsCache,allowExpiredCredentials:i.allowExpiredCredentials}),a=ke.encode(JSON.stringify(s)),c=ta(i.mediaType,i.packerOptions,{provingMethodAlg:this.getDefaultProvingMethodAlg(i.preferredAuthProvingMethod,o.body.accept),senderDID:t}),u=lt.decode(await this._packerMgr.pack(i.mediaType,a,c));return{authRequest:o,authResponse:s,token:u}}async handleAuthResponse(t,r){let i=r.request;if(t.type!==at.AUTHORIZATION_RESPONSE_MESSAGE_TYPE)throw new Error("Invalid message type for authorization response");if((i.body.message??"")!==(t.body.message??""))throw new Error("message for signing from request is not presented in response");if(i.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${i.from}, given ${t.to}`);this.verifyAuthRequest(i);let o=i.body.scope||[],s=t.body.scope||[];if(!t.from)throw new Error("proof response doesn't contain from field");let a=new Map;for(let c of o){let u=c.query?.groupId,l=s.find(w=>w.id.toString()===c.id.toString());if(!l){if(c.optional)continue;throw new Error(`proof is not given for requestId ${c.id}`)}let d=oM(c.circuitId);if(!d.includes(l.circuitId))throw new Error(`proof is not given for requested circuit expected: ${d.join(", ")}, given ${l.circuitId} `);let h=c.params??{};h.verifierDid=ve.parse(i.from);let f=[r.acceptedProofGenerationDelay,r.acceptedStateTransitionDelay].some(w=>w!==void 0)?{acceptedProofGenerationDelay:r.acceptedProofGenerationDelay,acceptedStateTransitionDelay:r.acceptedStateTransitionDelay}:void 0,{linkID:m}=await this._proofService.verifyZKPResponse(l,{query:c.query,sender:t.from,params:h,opts:f});m&&u&&a.set(u,[...a.get(u)??[],{linkID:m.toString(),requestId:l.id}])}for(let[c,u]of a.entries())if(u.some(l=>l.linkID!==u[0].linkID))throw new Error(`Link id validation failed for group ${c}, request linkID to requestIds info: ${JSON.stringify(u)}`);return t}async handleAuthorizationResponse(t,r,i){i?.allowExpiredMessages||Lr(t);let o=await this.handleAuthResponse(t,{request:r,acceptedStateTransitionDelay:i?.acceptedStateTransitionDelay,acceptedProofGenerationDelay:i?.acceptedProofGenerationDelay});return{request:r,response:o}}verifyAuthRequest(t){let r={},i=t.body.scope||[];for(let o of i){let s=o.query;if(!s)continue;let a=s.groupId;if(a){let c=r[a]??[];for(let u of c){let l=u.query;if(!l)continue;if(l.type!==s?.type)throw new Error("all requests in the group should have the same type");if(l.context!==s?.context)throw new Error("all requests in the group should have the same context");let d=s?.allowedIssuers,h=l.allowedIssuers;if(!(d.includes("*")||d.every(f=>h.includes(f))))throw new Error("all requests in the group should have the same issuer")}r[a]=[...r[a]??[],o]}}}getSupportedMediaTypeByProfile(t,r){let i;if(!r?.length)return t.mediaType||"application/iden3-zkp-json";let o=[];for(let s of r){let{env:a}=xs(s);this._packerMgr.isProfileSupported(a,s)&&o.push(a)}if(!o.length)throw new Error("no packer with profile which meets `accept` header requirements");return i=o.includes("application/iden3-zkp-json")?"application/iden3-zkp-json":o[0],t.mediaType&&o.includes(t.mediaType)&&(i=t.mediaType),i}getDefaultProvingMethodAlg(t,r){if(!r?.length)return Kc;let i=[Q0.provingMethodGroth16AuthV3_8_32Instance.methodAlg,Q0.provingMethodGroth16AuthV3Instance.methodAlg];if(t){let o=i.indexOf(t);o!==-1&&i.splice(o,1),i.unshift(t)}for(let o of i)if(this._packerMgr.isProfileSupported("application/iden3-zkp-json",bM(o))&&EM(r,o))return o;return Kc}};var yte=[{inputs:[],name:"MAX_SMT_DEPTH",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"key",type:"uint256"}],name:"getNode",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatus",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatusByIdAndState",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256[][]",name:"nodes",type:"uint256[][]"}],name:"saveNodes",outputs:[],stateMutability:"nonpayable",type:"function"}];var cI=class n{constructor(e,t,r){this._config=e;this._signer=r;this._provider=new jt(e.url);let i=new Ln(t,yte,this._provider);this._signer&&(this._signer=this._signer.connect(this._provider),i=i.connect(this._signer)),this._contract=i,this._transactionService=new Xs(this._provider)}_contract;_provider;_transactionService;async getRevocationStatusByIdAndState(e,t,r){let i=await this._contract.getRevocationStatusByIdAndState(e,t,r),o=n.convertIssuerInfo(i.issuer),s=n.convertSmtProofToProof(i.mtp);return{issuer:o,mtp:s}}async getRevocationStatus(e,t){let r=await this._contract.getRevocationStatus(e,t),i=n.convertIssuerInfo(r.issuer),o=n.convertSmtProofToProof(r.mtp);return{issuer:i,mtp:o}}async saveNodes(e){if(!this._signer)throw new Error("No signer provided");let t=await this._provider.getFeeData(),r=this._config.maxFeePerGas?BigInt(this._config.maxFeePerGas):t.maxFeePerGas,i=this._config.maxPriorityFeePerGas?BigInt(this._config.maxPriorityFeePerGas):t.maxPriorityFeePerGas,o=await this._contract.saveNodes.estimateGas(e),s=await this._contract.saveNodes.populateTransaction(e),a={to:s.to,data:s.data,gasLimit:o,maxFeePerGas:r,maxPriorityFeePerGas:i},{txnReceipt:c}=await this._transactionService.sendTransactionRequest(this._signer,a);return c}static convertIssuerInfo(e){let[t,r,i,o]=e.map(s=>be.fromBigInt(s).hex());return{state:t,claimsTreeRoot:r,revocationTreeRoot:i,rootOfRoots:o}}static convertSmtProofToProof(e){let t,r=e.siblings?.map(i=>i.toString());return e.auxExistence&&(t={key:e.auxIndex.toString(),value:e.auxValue.toString()}),kt.fromJSON({existence:e.existence,node_aux:t,siblings:r})}};function JRe(n){return typeof n=="object"&&n!==null&&"errorArgs"in n&&Array.isArray(n.errorArgs)}function qRe(n){return(JRe(n)?n.errorArgs[0]:void 0)||(n instanceof Error?n.message:"")}function Zy(n,e){return qRe(n).includes(e)}function z0(n){return Zy(n,Ge.ERRORS.IDENTITY_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR)}function sF(n){return Zy(n,Ge.ERRORS.STATE_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.STATE_DOES_NOT_EXIST_CUSTOM_ERROR)}function aF(n){return Zy(n,Ge.ERRORS.ROOT_DOES_NOT_EXIST)||Zy(n,Ge.ERRORS.ROOT_DOES_NOT_EXIST_CUSTOM_ERROR)}var cF=class{constructor(e,t){this._configs=e;this._stateStorage=new uI(e,t?.stateStorageOptions)}_stateStorage;async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");return this.getRevocationOnChain(e,t.issuerDID)}async getRevocationOnChain(e,t){let{contractAddress:r,chainId:i,revocationNonce:o,stateHex:s}=this.extractCredentialStatusInfo(e);if(o!==e.revocationNonce)throw new Error("revocationNonce does not match");let a=ve.idFromDID(t),c;try{let h=await this._stateStorage.getLatestStateById(a.bigInt());if(!h.state)throw new Error("state contract returned empty state");c=h.state}catch(h){if(!z0(h))throw h;if(!s)throw new Error("latest state not found and state parameter is not present in credentialStatus.id");let f=be.fromHex(s).bigInt();if(!pf(t,f))throw new Error(`latest state not found and state parameter ${s} is not genesis state`);c=f}let u=ve.idFromDID(t);return await this._getOnChainRevocationStorageForIssuer(i,r).getRevocationStatusByIdAndState(u.bigInt(),c,o)}extractCredentialStatusInfo(e){if(!e.id)throw new Error("credentialStatus id is empty");if(e.id.split("/").length!==2)throw new Error("invalid credentialStatus id");let r=new URL(e.id),i=r.searchParams.get("state")||"",o=r.searchParams.get("contractAddress");if(!o)throw new Error("contractAddress not found in credentialStatus.id field");let s=o.split(":");if(s.length!=2)throw new Error("invalid contract address encoding. should be chainId:contractAddress");let a=parseInt(s[0],10),c=s[1],u=r.searchParams.get("revocationNonce")||e.revocationNonce;if(u==null)throw new Error("revocationNonce not found in credentialStatus id field");let l=typeof u=="number"?u:parseInt(u,10);return{contractAddress:c,chainId:a,revocationNonce:l,stateHex:i}}networkByChainId(e){let t=this._configs.find(r=>r.chainId===e);if(!t)throw new Error(`chainId "${e}" not supported`);return t}_getOnChainRevocationStorageForIssuer(e,t){let r=this.networkByChainId(e);return new cI(r,t)}};var Y0=class{async resolve(e){let r=await(await fetch(e.id)).json();return m8(r)}},m8=({issuer:n,mtp:e})=>({mtp:kt.fromJSON(e),issuer:n});var j0=class n{constructor(e=Ne,t=[]){this.hash=e;this.children=t}nodeType(){return this.children.length===2?1:this.children.length===3&&this.children[2].hex()===be.fromBigInt(BigInt(1)).hex()?2:this.children.length===3?3:0}toJSON(){return{hash:this.hash.hex(),children:this.children.map(e=>e.hex())}}static fromHex(e){return new n(be.fromHex(e.hash),e.children.map(t=>be.fromHex(t)))}};var uF=class{constructor(e){this._state=e}async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");try{return await this.getStatus(e,t.issuerDID,t.issuerData,t.issuerGenesisState)}catch(r){if(e?.statusIssuer?.type==="SparseMerkleTreeProof")try{return await new Y0().resolve(e.statusIssuer)}catch(i){throw new Error(`can't fetch revocation status from backup endpoint: ${i?.message}`)}throw new Error(`can't fetch revocation status: ${r?.message}`)}}async getStatus(e,t,r,i){let o=ve.idFromDID(t),s;try{let l=await this._state.getLatestStateById(o.bigInt());if(!l.state)throw new Error("state contract returned empty state");s=l.state}catch(l){if(!z0(l))throw l;let d=this.extractState(e.id);if(!d)return this.getRevocationStatusFromIssuerData(t,r,i);let h=be.fromHex(d).bigInt(),f=gp(t);if(!f&&!pf(t,h))throw new Error(`latest state not found and state parameter ${d} is not genesis state`);if(f)throw new Error("State must be published for Ethereum based identity");s=h}let a=e.id.split("/node")[0],c=be.fromBigInt(BigInt(e.revocationNonce??0)),u=be.fromBigInt(s);return await this.getRevocationStatusFromRHS(c,u,a)}getRevocationStatusFromIssuerData(e,t,r){if(r&&pf(e,r.value.bigInt()))return{mtp:new kt,issuer:{state:r.value.hex(),revocationTreeRoot:r.revocationTreeRoot.hex(),rootOfRoots:r.rootOfRoots.hex(),claimsTreeRoot:r.claimsTreeRoot.hex()}};if(t&&pf(e,t.state.value))return{mtp:new kt,issuer:{state:t.state.value,revocationTreeRoot:t.state.revocationTreeRoot,rootOfRoots:t.state.rootOfRoots,claimsTreeRoot:t.state.claimsTreeRoot}};throw new Error("issuer data / genesis state param is empty")}async getRevocationStatusFromRHS(e,t,r){if(!r)throw new Error("HTTP reverse hash service URL is not specified");let o=(await(await fetch(`${r}/node/${t.hex()}`)).json())?.node;if(o.children.length!==3)throw new Error("state should has tree children");let s=t.hex(),[a,c,u]=o.children,l=be.fromHex(c);return{mtp:await this.rhsGenerateProof(l,e,`${r}/node`),issuer:{state:s,claimsTreeRoot:a,revocationTreeRoot:c,rootOfRoots:u}}}async rhsGenerateProof(e,t,r){let i=!1,o=[],s,a=()=>new kt({siblings:o,existence:i,nodeAux:s}),c=e;for(let u=0;u<t.bytes.length*8;u++){if(c.bytes.every(f=>f===0))return a();let d=(await(await fetch(`${r}/${c.hex()}`)).json())?.node,h=j0.fromHex(d);switch(h.nodeType()){case 2:return t.bytes.every((f,m)=>f===h.children[0].bytes[m])?(i=!0,a()):(s={key:h.children[0],value:h.children[1]},a());case 1:Ew(t.bytes,u)?(c=h.children[1],o.push(h.children[0])):(c=h.children[0],o.push(h.children[1]));break;default:throw new Error(`found unexpected node type in tree ${h.hash.hex()}`)}}throw new Error("tree depth is too high")}extractState(e){return new URL(e).searchParams.get("state")}};function VRe(n,e){let t=ve.parse(n),r=ve.idFromDID(t),{method:i,blockchain:o,networkId:s}=ve.decodePartsFromId(r),a=It.hexToBytes(e),c=It.bytesToInt(a),u=jc(i,o,s);return wte(ve.idFromDID(t).bigInt(),c,u)}function wte(n,e,t){let r=Xe.idGenesisFromIdenState(t,e);return n.toString()===r.bigInt().toString()}var lI=class{resolvers=new Map;register(e,t){this.resolvers.set(e,t)}get(e){return this.resolvers.get(e)}};var dI=class{async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");if(!t?.userDID)throw new Error("UserDID is not set in options");if(typeof e.revocationNonce!="number")throw new Error("Revocation nonce is not set in credential status");let r=t.userDID.string(),i=t.issuerDID.string(),o=QRe(r,i,e.revocationNonce),a=await(await fetch(e.id,{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"}})).json();return m8(a.body)}};function QRe(n,e,t){return{id:Ut(),typ:"application/iden3comm-plain-json",type:at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE,body:{revocation_nonce:t},thid:Ut(),from:n,to:e}}var fI=class{_publishers=new Map;register(e,...t){let r=this._publishers.get(e)??[];r.push(...t),this._publishers.set(e,r)}get(e){return this._publishers.get(e)}},lF=class{constructor(e){this._storage=e}async publish(e){if(!["Iden3OnchainSparseMerkleTreeProof2023"].includes(e.credentialStatusType))throw new Error(`On-chain publishing is not supported for credential status type ${e.credentialStatusType}`);let t=e.nodes.map(o=>o.children.map(s=>s.bigInt())),r=this._storage.saveNodes(t),i=e.onChain?.publishMode??"sync";switch(e.onChain?.txCallback&&(i="callback"),i){case"sync":await r;break;case"callback":{if(!e.onChain?.txCallback)throw new Error('txCallback is required for publishMode "callback"');let o=e.onChain?.txCallback;r.then(s=>o(s));break}case"async":{let o=hb.getInstance();r.then(s=>o.publish(OR.TX_RECEIPT_ACCEPTED,s));break}default:throw new Error(`Invalid publishMode: ${i}`)}}},W0=class{async publish(e){if(!["Iden3ReverseSparseMerkleTreeProof"].includes(e.credentialStatusType))throw new Error(`On-chain publishing is not supported for credential status type ${e.credentialStatusType}`);let t=e.nodes.map(i=>i.toJSON()),r=await fetch(e.rhsUrl+"/node",{method:"post",body:JSON.stringify(t)});if(r.status!==200)throw new Error(`Failed to publish credential status. Status: ${r.status}`)}};var dF=class{constructor(e){this.didResolverUrl=e}async resolve(e,t){if(!t?.issuerDID)throw new Error("IssuerDID is not set in options");let r=`${this.didResolverUrl}/1.0/credential-status/${encodeURIComponent(t.issuerDID.string())}`;return await(await fetch(r,{method:"POST",body:JSON.stringify(e)})).json()}};var fF=class{constructor(e,t){this._storage=e;this._credentialStatusResolverRegistry=t;this._credentialStatusResolverRegistry||(this._credentialStatusResolverRegistry=new lI,this._credentialStatusResolverRegistry.register("SparseMerkleTreeProof",new Y0),this._credentialStatusResolverRegistry.register("Iden3commRevocationStatusV1.0",new dI))}getCredentialStatusResolverRegistry(){return this._credentialStatusResolverRegistry}async getAuthBJJCredential(e){let t=await this._storage.credential.findCredentialsByQuery({context:Ge.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,type:Ge.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,allowedIssuers:[e.string()]});if(!t.length)throw new Error(Ge.ERRORS.NO_AUTH_CRED_FOUND);for(let r=0;r<t.length;r++){let i=t[r];if(!(await this.getRevocationStatusFromCredential(i)).mtp.existence)return i}throw new Error("all auth bjj credentials are revoked")}async getAllAuthBJJCredentials(e){return this._storage.credential.findCredentialsByQuery({context:Ge.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL,type:Ge.AUTH.AUTH_BJJ_CREDENTIAL_TYPE,allowedIssuers:[e.string()]})}async getRevocationStatusFromCredential(e){let t=e.getIden3SparseMerkleTreeProof(),r=e.getBJJSignature2021Proof(),i=t?t.issuerData.state:r?.issuerData.state,o=ve.parse(e.issuer),s=Xl(o,e),a={issuerGenesisState:i,issuerDID:o,userDID:s};return this.getRevocationStatus(e.credentialStatus,a)}async getRevocationStatus(e,t){let r=this._credentialStatusResolverRegistry?.get(e.type);if(!r)throw new Error(`credential status resolver does not exist for ${e.type} type`);return r.resolve(e,t)}createCredential=(e,t,r)=>{if(!r.$metadata.uris.jsonLdContext)throw new Error("jsonLdContext is missing is the schema");let i={...t};return i.context=i.context??[],i.displayMethod?.type==="Iden3BasicDisplayMethodV1"&&!i.context.includes(Ge.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD)&&i.context.push(Ge.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD),i.context.push(r.$metadata.uris.jsonLdContext),i.expiration=i.expiration?i.expiration*1e3:void 0,i.id=i.id?i.id:`urn:${Ut()}`,i.issuanceDate=i.issuanceDate?i.issuanceDate*1e3:Date.now(),Er.fromCredentialRequest(e,i)};async findById(e){return this._storage.credential.findCredentialById(e)}async findByContextType(e,t){return this._storage.credential.findCredentialsByQuery({context:e,type:t})}async save(e){return this._storage.credential.saveCredential(e)}async saveAll(e){return this._storage.credential.saveAllCredentials(e)}async remove(e){return this._storage.credential.removeCredential(e)}async list(){return this._storage.credential.listCredentials()}async findByQuery(e){return this._storage.credential.findCredentialsByQuery(e)}async filterByCredentialSubject(e,t){return e.filter(r=>r.credentialSubject.id===t.string())}async findNonRevokedCredential(e){for(let t of e){let r=await this.getRevocationStatusFromCredential(t);if(!r.mtp.existence)return{cred:t,revStatus:r}}throw new Error(Ge.ERRORS.CREDENTIAL_WALLET_ALL_CREDENTIALS_ARE_REVOKED)}};async function g8(n,e,t,r){let i=await y8(r,e,n);await new W0().publish({nodes:i,credentialStatusType:"Iden3ReverseSparseMerkleTreeProof",rhsUrl:t})}async function y8(n,e,t){let r=new hF;return n&&await YRe(r,e,n),await zRe(r,e),t.bytes.every(i=>i===0)||r.addProofNode(new j0(t,[await e.claimsTree.root(),await e.revocationTree.root(),await e.rootsTree.root()])),r.nodes}async function zRe(n,e){let t=e.rootsTree,r=e.claimsTree;return n.addKey(t,(await r.root()).bigInt())}async function YRe(n,e,t){let r=e.revocationTree;for(let i of t)await n.addKey(r,BigInt(i))}var hF=class{constructor(e=[],t=new Map){this.nodes=e;this.seen=t}async addKey(e,t){let{value:r,siblings:i}=await e.get(t),o=be.fromBigInt(t),s=be.fromBigInt(r),a=new Zc(o,s),c=await jRe(i,a);for(let u of c)this.seen.get(u.hash.hex())||(this.nodes.push(u),this.seen.set(u.hash.hex(),!0))}addProofNode(e){let t=e.hash.hex();this.seen.get(t)||(this.nodes.push(e),this.seen.set(t,!0))}};async function jRe(n,e){if(e.type!==oa)throw new Error("node is not a leaf");let t=await e.getKey(),r=n.length,i=new Array(r+1);for(let a=0;a<i.length;a++)i[a]=new j0;i[r].hash=t;let o=be.fromBigInt(BigInt(1));i[r].children=[e.entry[0],e.entry[1],o];let s=e.entry[0];for(let a=r-1;a>=0;a--){let c=Ew(s.bytes,a);i[a].children=new Array(2),c?(i[a].children[0]=n[a],i[a].children[1]=t):(i[a].children[0]=t,i[a].children[1]=n[a]),i[a].hash=Ch([i[a].children[0].bigInt(),i[a].children[1].bigInt()]),t=i[a].hash}return i}var pF=class n extends Ni{constructor(t,r){super();this._packerMgr=t;this.opts=r}async handle(t,r){switch(t.type){case at.CREDENTIAL_OFFER_MESSAGE_TYPE:{let i=await this.handleOfferMessage(t,r);if(Array.isArray(i)){let o=this.opts?.credentialWallet;if(!o)throw new Error("Credential wallet is not provided");return await o.saveAll(i),null}return i}case at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE:return this.handleFetchRequest(t);case at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:return this.handleIssuanceResponseMsg(t);case at.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE:{let i=await this.handleOnchainOfferMessage(t);if(Array.isArray(i)){let o=this.opts?.credentialWallet;if(!o)throw new Error("Credential wallet is not provided");return await o.saveAll(i),null}return i}case at.ENCRYPTED_CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE:return await this.handleEncryptedIssuanceResponseMessage(t),null;default:return super.handle(t,r)}}async handleOnchainOfferMessage(t){if(!this.opts?.onchainIssuer)throw new Error("onchain issuer is not provided");let r=[];for(let i of t.body.credentials){let o=ve.parse(t.from),s=ve.parse(t.to),a=await this.opts.onchainIssuer.getCredential(o,s,BigInt(i.id));r.push(a)}return r}async handleOfferMessage(t,r){r.mediaType||(r.mediaType="application/iden3-zkp-json");let i=[];for(let o of t.body.credentials){let s=Ut(),a={id:s,typ:r.mediaType,type:at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE,thid:t.thid??s,body:{id:o.id},from:t.to,to:t.from},c=ke.encode(JSON.stringify(a)),u=ve.parse(t.to),l=ta(r.mediaType,r.packerOptions,{senderDID:u}),d=lt.decode(await this._packerMgr.pack(r.mediaType,c,l));try{if(!t?.body?.url)throw new Error("could not fetch W3C credential, body url is missing");let f=await(await fetch(t.body.url,{method:"post",headers:{"Content-Type":fM[r.mediaType],...r.headers},body:d})).arrayBuffer();if(!f.byteLength)throw new Error(`could not fetch , ${o?.id}, response is empty`);let{unpackedMessage:m}=await this._packerMgr.unpack(new Uint8Array(f));if(m.type===at.ENCRYPTED_CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE)return await this.handleEncryptedIssuanceResponseMessage(m),[];if(m.type!==at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE)return m;i.push(Er.fromJSON(m.body.credential))}catch(h){throw new Error(`could not fetch protocol message for credential offer id: , ${o?.id}, error: ${h.message??h}`)}}return i}async handleCredentialOffer(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_OFFER_MESSAGE_TYPE);r?.allowExpiredMessages||Lr(i);let o=r?.mediaType||"application/iden3-zkp-json",s=ta(o,r?.packerOptions,{provingMethodAlg:r?.messageProvingMethodAlg||await Hc(t),senderDID:ve.parse(i.to)}),a=await this.handleOfferMessage(i,{mediaType:o,headers:r?.headers,packerOptions:s});if(Array.isArray(a))return a;throw new Error("invalid protocol message response")}async handleOnchainOffer(t){let r=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_ONCHAIN_OFFER_MESSAGE_TYPE);return this.handleOnchainOfferMessage(r)}async handleFetchRequest(t){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");let r=ve.parse(t.to),i=ve.parse(t.from),o=t.body?.id;if(!o)throw new Error("invalid credential id in fetch request body");if(!this.opts?.credentialWallet)throw new Error("please, provide credential wallet in options");let s=await this.opts.credentialWallet.findById(o);if(!s)throw new Error("credential not found");if(Xl(r,s).string()!==i.string())throw new Error("credential subject is not a sender DID");return{id:Ut(),type:at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE,typ:t.typ??"application/iden3comm-plain-json",thid:t.thid??Ut(),body:{credential:s},from:t.to,to:t.from}}async handleCredentialFetchRequest(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_FETCH_REQUEST_MESSAGE_TYPE);r?.allowExpiredMessages||Lr(i);let o=await this.handleFetchRequest(i);return this._packerMgr.pack("application/iden3comm-plain-json",ke.encode(JSON.stringify(o)),{})}async handleEncryptedIssuanceResponseMessage(t){if(!this.opts?.joseService)throw new Error("JoseService is not initialized. Encrypted issuance response cannot be handled");let{plaintext:r}=await this.opts.joseService.decrypt(t.body.data),i=Er.fromJSON({...JSON.parse(lt.decode(r)),proof:t.body.proof});if(!this.opts?.credentialWallet)throw new Error("please provide credential wallet in options for encrypted issuance response handling");if(!this.opts?.didResolverUrl)throw new Error("please provide resolver URL in options for encrypted issuance response handling");if(!this.opts?.merklizeOptions)throw new Error("please provide merklize options for encrypted issuance response handling");let o=this.opts.credentialWallet.getCredentialStatusResolverRegistry();if(!o)throw new Error("credential status resolver registry is not available in credential wallet");if(!await i.verifyProofs(this.opts.didResolverUrl,{credStatusResolverRegistry:o,merklizeOptions:this.opts.merklizeOptions}))throw new Error("credential proof verification failed");return await this.opts?.credentialWallet?.save(i),null}async handleIssuanceResponseMsg(t){if(!this.opts?.credentialWallet)throw new Error("please provide credential wallet in options");if(!t.body?.credential)throw new Error("credential is missing in issuance response message");if(!(t.body.credential instanceof Er))throw new Error("credential object is not properly unmarshaled");return await this.opts.credentialWallet.save(t.body.credential),null}async handleIssuanceResponseMessage(t,r){let i=await n.unpackMessage(this._packerMgr,t,at.CREDENTIAL_ISSUANCE_RESPONSE_MESSAGE_TYPE);return r?.allowExpiredMessages||Lr(i),i.body.credential=Er.fromJSON(i.body.credential),await this.handleIssuanceResponseMsg(i),Uint8Array.from([])}static async unpackMessage(t,r,i){let{unpackedMessage:o}=await t.unpack(r),s=o;if(o.type!==i)throw new Error("Invalid message type");return s}};var mF=class extends Ni{constructor(t,r,i){super();this._packerMgr=t;this._proofService=r;this._zkpVerifier=i}_supportedCircuits=["authV2","credentialAtomicQueryMTPV2OnChain","credentialAtomicQuerySigV2OnChain","credentialAtomicQueryV3OnChain-beta.1","credentialAtomicQueryV3OnChain","authV2","authV3","authV3-8-32","linkedMultiQuery10-beta.1","credentialAtomicQueryV3","linkedMultiQuery"];async handle(t,r){switch(t.type){case at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE:{let i=t,o=await this.handleContractInvoke(i,r);return this.createContractInvokeResponse(i,o)}default:return super.handle(t,r)}}async handleContractInvoke(t,r){if(t.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for contract invoke request");let{senderDid:i,ethSigner:o,challenge:s}=r;if(!r.ethSigner)throw new Error("Can't sign transaction. Provide Signer in options.");let{chain_id:a}=t.body.transaction_data;if(!Object.keys(na).find(f=>na[f]===a))throw new Error(`Invalid chain id ${a}`);let u=t.from?ve.parse(t.from):void 0,{scope:l=[]}=t.body,d=await Wy(i,l,u,this._proofService,{ethSigner:o,challenge:s??It.bytesToInt(di(await o.getAddress())),supportedCircuits:this._supportedCircuits});switch(t.body.transaction_data.method_id.replace("0x","")){case"ade09fcd":{let f=await this._zkpVerifier.submitZKPResponseV2(o,t.body.transaction_data,d),m=new Map;for(let[w,b]of f)m.set(w,{responses:b});return t.body.transaction_data.txHash=f.keys().next().value,m}case"b68967e2":{let f=await this._zkpVerifier.submitZKPResponse(o,t.body.transaction_data,d),m=new Map;for(let[w,b]of f)m.set(w,{responses:[b]});return t.body.transaction_data.txHash=f.keys().next().value,m}case"06c86a91":{if(!t.to)throw new Error("failed message. empty 'to' field");let f=this.getFirstSupportedProfile(at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE,t.body.accept),m=ve.parse(t.to),{authProof:w}=await iF(m,this._proofService,{supportedCircuits:this._supportedCircuits,acceptProfile:f,senderAddress:await o.getAddress(),zkpResponses:d}),b=await this._zkpVerifier.submitResponse(o,t.body.transaction_data,d,w);return t.body.transaction_data.txHash=b.keys().next().value,b}default:throw new Error("Not supported method id. Only 'b68967e2, ade09fcd and 06c86a91 are supported.'")}}getFirstSupportedProfile(t,r){if(r?.length)for(let i of r){let o=xs(i),s=Number(t.split("/").at(-2));if(!(o.protocolVersion!=="iden3comm/v1"||o.protocolVersion==="iden3comm/v1"&&(s<1||s>=2))&&this._packerMgr.isProfileSupported(o.env,i))return o}return TE}async parseContractInvokeRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i.body.scope=i.body.scope||[],i}async createContractInvokeResponse(t,r){let i={id:t.id,thid:t.thid,type:at.CONTRACT_INVOKE_RESPONSE_MESSAGE_TYPE,from:t.to,to:t.from,body:{transaction_data:t.body.transaction_data,scope:[]},created_time:Lt(new Date)};for(let[o,s]of r){for(let a of s.responses)i.body.scope.push({txHash:o,...a});i.body={...i.body,crossChainProof:s.crossChainProof,authProof:s.authProof}}return i}async handleContractInvokeRequest(t,r,i){let o=await this.parseContractInvokeRequest(r);if(i.allowExpiredMessages||Lr(o),o.body.transaction_data.method_id!=="b68967e2")throw new Error("please use handle method to work with other method ids");if(o.type!==at.CONTRACT_INVOKE_REQUEST_MESSAGE_TYPE)throw new Error("Invalid message type for contract invoke request");let{ethSigner:s,challenge:a}=i;if(!s)throw new Error("Can't sign transaction. Provide Signer in options.");let{chain_id:c}=o.body.transaction_data;if(!Object.keys(na).find(h=>na[h]===c))throw new Error(`Invalid chain id ${c}`);let l=o.from?ve.parse(o.from):void 0,d=await Wy(t,o?.body?.scope,l,this._proofService,{ethSigner:s,challenge:a,supportedCircuits:this._supportedCircuits});return this._zkpVerifier.submitZKPResponse(s,o.body.transaction_data,d)}};var gF=class{constructor(e){this._options=e}async refreshCredential(e,t){if(!e.refreshService)throw new Error("refreshService not specified for W3CCredential");if(e.refreshService.type!=="Iden3RefreshService2023")throw new Error(`refresh service type ${e.refreshService.type} is not supported`);let r=e.credentialSubject.id;if(!r)throw new Error("self credentials do not support refresh");let i=ve.parse(r),o=t?.mediaType||"application/iden3-zkp-json",s=t?.packerOptions??{senderDID:i,provingMethodAlg:Kc},a={id:Ut(),typ:"application/iden3-zkp-json",type:at.CREDENTIAL_REFRESH_MESSAGE_TYPE,thid:Ut(),body:{id:e.id,reason:t?.reason??"credential is expired"},from:r,to:e.issuer},c=ke.encode(JSON.stringify(a)),u=await this._options.packageManager.pack(o,c,s),l=await fetch(e.refreshService.id,{method:"post",headers:{"Content-Type":"application/json"},body:u.buffer});if(l.status!==200)throw new Error(`could not refresh W3C credential, return status ${l.status}`);let d=await l.json();if(!d.body?.credential)throw new Error("no credential in CredentialIssuanceMessage response");return Er.fromJSON(d.body.credential)}};var yF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._identityWallet=r}handle(t,r){if(!r.senderDid)throw new Error("DID is required");if(!r.mediaType)throw new Error("mediaType is required");switch(t.type){case at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE:return this.handleRevocationStatusRequestMessage(t,r);default:return super.handle(t,r)}}async handleRevocationStatusRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body?.revocation_nonce)throw new Error("failed request. empty 'revocation_nonce' field");let i=ve.parse(t.to),o=await this._identityWallet.generateNonRevocationMtpWithNonce(i,BigInt(t.body.revocation_nonce),r.treeState),s=o.treeState,a={issuer:{state:s?.state.string(),claimsTreeRoot:s.claimsRoot.string(),revocationTreeRoot:s.revocationRoot.string(),rootOfRoots:s.rootOfRoots.string()},mtp:o.proof},c=Ut();return{id:c,typ:"application/iden3comm-plain-json",type:at.REVOCATION_STATUS_RESPONSE_MESSAGE_TYPE,thid:t.thid??c,body:a,from:r.senderDid.string(),to:t.from}}async parseRevocationStatusRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.REVOCATION_STATUS_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handleRevocationStatusRequest(t,r,i){i||(i={mediaType:"application/iden3comm-plain-json"});let o=await this.parseRevocationStatusRequest(r);i.allowExpiredMessages||Lr(o);let s=await this.handleRevocationStatusRequestMessage(o,{senderDid:t,mediaType:i.mediaType,packerOptions:i.packerOptions,treeState:i.treeState});if(!o.to)throw new Error("failed request. empty 'to' field");let a=ve.parse(o.to),c=ta(i.mediaType,i.packerOptions,{senderDID:a,provingMethodAlg:i.packerOptions?.provingMethodAlg||await Hc(r)});return this._packerMgr.pack(i.mediaType,ke.encode(JSON.stringify(s)),c)}};function WRe(n,e,t){let r=Ut();return{id:r,thid:r,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PROPOSAL_REQUEST_MESSAGE_TYPE,body:{credentials:t.credentials,did_doc:t.did_doc},created_time:Lt(new Date),expires_time:t?.expires_time?Lt(t.expires_time):void 0,attachments:t.attachments}}function ZRe(n,e,t,r){let i=Ut();return{id:i,thid:i,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PROPOSAL_MESSAGE_TYPE,body:{proposals:t||[]},created_time:Lt(new Date),expires_time:r?.expires_time?Lt(r.expires_time):void 0}}var wF=class extends Ni{constructor(t,r,i){super();this._packerMgr=t;this._identityWallet=r;this._params=i}async handle(t,r){switch(t.type){case at.PROPOSAL_REQUEST_MESSAGE_TYPE:return await this.handleProposalRequestMessage(t,r);default:return super.handle(t,r)}}async parseProposalRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.PROPOSAL_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handleProposalRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body?.credentials?.length)throw new Error("failed request. no 'credentials' in body");let i,o;for(let s=0;s<t.body.credentials.length;s++){let a=t.body.credentials[s],c=[];if(!r?.forceCredentialReissue){try{c=await this._identityWallet.credentialWallet.findByQuery({credentialSubject:{id:{$eq:t.from}},type:a.type,context:a.context,allowedIssuers:[t.to]})}catch(l){if(l.message!=="no credential satisfied query")throw l}if(c.length){let l=Ut();i||(i={id:l,typ:this._params.packerParams.mediaType,type:at.CREDENTIAL_OFFER_MESSAGE_TYPE,thid:t.thid??l,body:{url:this._params.agentUrl,credentials:[]},from:t.to,to:t.from}),i.body.credentials.push(...c.map(d=>({id:d.id,description:""})));continue}}let u=await this._params.proposalResolverFn(a.context,a.type,{msg:t});if(!u)throw new Error(`can't resolve Proposal for type: ${a.type}, context: ${a.context}`);if(!o){let l=Ut();o={id:l,typ:this._params.packerParams.mediaType,type:at.PROPOSAL_MESSAGE_TYPE,thid:t.thid??l,body:{proposals:[]},from:t.to,to:t.from}}o.body?.proposals.push(u)}return o??i}async handleProposalRequest(t,r){let i=await this.parseProposalRequest(t);if(!i.from)throw new Error("failed request. empty 'from' field");r?.allowExpiredMessages||Lr(i);let o=ve.parse(i.from),s=await this.handleProposalRequestMessage(i),a=ke.encode(JSON.stringify(s)),c=ta(this._params.packerParams.mediaType,this._params.packerParams.packerOptions,{provingMethodAlg:await Hc(t),senderDID:o});return this._packerMgr.pack(this._params.packerParams.mediaType,a,c)}async handleProposal(t,r){if(r?.allowExpiredMessages||Lr(t),r?.proposalRequest&&r.proposalRequest.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${r.proposalRequest.from}, given ${t.to}`);return{proposal:t}}};function bte(n,e,t,r,i){let o=Ut();return{id:o,thid:o,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PAYMENT_REQUEST_MESSAGE_TYPE,body:{agent:t,payments:r},created_time:Lt(new Date),expires_time:i?.expires_time?Lt(i.expires_time):void 0}}function Ete(n,e,t,r){let i=Ut();return{id:i,thid:i,from:n.string(),to:e.string(),typ:"application/iden3comm-plain-json",type:at.PAYMENT_MESSAGE_TYPE,body:{payments:t},created_time:Lt(new Date),expires_time:r?.expires_time?Lt(r.expires_time):void 0}}var bF=class extends Ni{constructor(t,r){super();this._packerMgr=t;this._params=r}async handle(t,r){switch(t.type){case at.PAYMENT_REQUEST_MESSAGE_TYPE:return await this.handlePaymentRequestMessage(t,r);case at.PAYMENT_MESSAGE_TYPE:return await this.handlePayment(t,r),null;default:return super.handle(t,r)}}async parsePaymentRequest(t){let{unpackedMessage:r}=await this._packerMgr.unpack(t),i=r;if(r.type!==at.PAYMENT_REQUEST_MESSAGE_TYPE)throw new Error("Invalid media type");return i}async handlePaymentRequestMessage(t,r){if(!t.to)throw new Error("failed request. empty 'to' field");if(!t.from)throw new Error("failed request. empty 'from' field");if(!t.body.payments?.length)throw new Error("failed request. no 'payments' in body");if(!r.paymentHandler)throw new Error("please provide payment handler in context");let i=ve.parse(t.to),o=ve.parse(t.from),s=[];for(let m=0;m<t.body.payments.length;m++){let{data:w}=t.body.payments[m],b=Array.isArray(w)?w.find(S=>S.type==="Iden3PaymentRequestCryptoV1"?S.id===r.nonce:S.nonce===r.nonce):w;if(!b)throw new Error(`failed request. no payment in request for nonce ${r.nonce}`);switch(b.type){case"Iden3PaymentRequestCryptoV1":s.push(await this.handleIden3PaymentRequestCryptoV1(b,r.paymentHandler));break;case"Iden3PaymentRailsRequestV1":s.push(await this.handleIden3PaymentRailsRequestV1(b,r.paymentHandler));break;case"Iden3PaymentRailsERC20RequestV1":s.push(await this.handleIden3PaymentRailsERC20RequestV1(b,r.paymentHandler,r.erc20TokenApproveHandler));break;case"Iden3PaymentRailsSolanaRequestV1":s.push(await this.handleIden3PaymentRailsSolanaRequestV1(b,r.paymentHandler));break;case"Iden3PaymentRailsSolanaSPLRequestV1":s.push(await this.handleIden3PaymentRailsSolanaSPLRequestV1({...b,type:"Iden3PaymentRailsSolanaSPLRequestV1"},r.paymentHandler));break}}let a=Ete(i,o,s),c=r?.mediaType||this._params.packerParams.mediaType||"application/iden3-zkp-json",u=ta(c,r?.packerOptions||this._params.packerParams,{senderDID:i,provingMethodAlg:r.messageProvingMethodAlg}),l=await this.packMessage(a,i,c,u),h=await(await fetch(t.body.agent,{method:"POST",body:l.buffer,headers:{...r.headers,"Content-Type":this._params.packerParams.mediaType==="application/iden3comm-plain-json"?"application/json":"application/octet-stream"}})).arrayBuffer();if(!h.byteLength)return null;let{unpackedMessage:f}=await this._packerMgr.unpack(new Uint8Array(h));return f}async handlePaymentRequest(t,r){let i=await this.parsePaymentRequest(t);if(!i.from)throw new Error("failed request. empty 'from' field");if(!i.to)throw new Error("failed request. empty 'to' field");r?.allowExpiredMessages||Lr(i);let o=r.mediaType||this._params.packerParams.mediaType||"application/iden3-zkp-json";r.packerOptions||(r.packerOptions=this._params.packerParams.packerOptions),r.mediaType=o;let s=ve.parse(i.to);r.packerOptions=ta(o,r.packerOptions,{provingMethodAlg:await Hc(t),senderDID:s});let a=await this.handlePaymentRequestMessage(i,r);return a?this.packMessage(a,s,r.mediaType||"application/iden3-zkp-json",r.packerOptions):null}async handlePayment(t,r){if(r?.allowExpiredMessages||Lr(t),r.paymentRequest.from!==t.to)throw new Error(`sender of the request is not a target of response - expected ${r.paymentRequest.from}, given ${t.to}`);if(!t.body.payments.length)throw new Error("failed request. empty 'payments' field in body");if(!r.paymentValidationHandler)throw new Error("please provide payment validation handler in options");for(let i=0;i<t.body.payments.length;i++){let o=t.body.payments[i],s=o.type==="Iden3PaymentCryptoV1"?o.id:o.nonce,c=r.paymentRequest.body.payments.map(u=>Array.isArray(u.data)?u.data:[u.data]).flat().find(u=>u.type==="Iden3PaymentRequestCryptoV1"?u.id===s:u.nonce===s);if(!c)throw new Error(`can't find payment request for payment ${o.type==="Iden3PaymentCryptoV1"?"id":"nonce"} ${s}`);await r.paymentValidationHandler(o.paymentData.txId,c)}}async createPaymentRailsV1(t,r,i,o,s,a){let c=[];for(let u=0;u<s.length;u++){let{credentials:l,description:d}=s[u],h=[];for(let f=0;f<s[u].options.length;f++){let{nonce:m,amount:w,chainId:b,optionId:S,expirationDate:R}=s[u].options[f],G=this._params.multiChainPaymentConfig?.find(z=>z.chainId===b);if(!G)throw new Error(`failed request. no config for chain ${b}`);let{recipient:U,paymentRails:H,options:M}=G,A=M.find(z=>z.id===S);if(!A)throw new Error(`failed request. no option for id ${S}`);if((A.type==="Iden3PaymentRailsERC20RequestV1"||A.type==="Iden3PaymentRailsSolanaSPLRequestV1")&&!A.contractAddress)throw new Error(`failed request. no token address for option id ${S}`);let D=R??new Date(new Date().setHours(new Date().getHours()+1));if(A.type==="Iden3PaymentRailsSolanaRequestV1"||A.type==="Iden3PaymentRailsSolanaSPLRequestV1"){if(!a?.solSigner)throw new Error(`please provide solana signer in context for ${A.type} payment type`);let z=await SB(a.solSigner,A,b,H,U,BigInt(w),D,m);h.push(z)}else{let z=await CB(o,A,b,H,U,BigInt(w),D,m);h.push(z)}}c.push({data:h,credentials:l,description:d})}return bte(t,r,i,c)}async packMessage(t,r,i,o){let s=ke.encode(JSON.stringify(t)),a=i==="application/iden3comm-signed-json"?o:{provingMethodAlg:o?.provingMethodAlg||Kc};return await this._packerMgr.pack(i,s,{senderDID:r,...a})}async handleIden3PaymentRequestCryptoV1(t,r){if(t.expiration&&new Date(t.expiration)<new Date)throw new Error("failed request. expired request");let i=await r(t);return{id:t.id,"@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentCryptoV1",type:"Iden3PaymentCryptoV1",paymentData:{txId:i}}}async handleIden3PaymentRailsRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");let i=await aS(t,this._params.documentResolver);if(this._params.allowedSigners&&!this._params.allowedSigners.includes(i))throw new Error("failed request. signer is not in the allowed signers list");let o=await r(t),s=Array.isArray(t.proof)?t.proof[0]:t.proof;return{nonce:t.nonce,type:"Iden3PaymentRailsV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsV1",paymentData:{txId:o,chainId:s.eip712.domain.chainId}}}async handleIden3PaymentRailsSolanaRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");if(!await sS(t,this._params.documentResolver))throw new Error("failed request. invalid Solana payment request signature");let o=Array.isArray(t.proof)?t.proof[0]:t.proof,s=o.verificationMethod.split(":").slice(-1)[0];if(this._params.allowedSigners&&!this._params.allowedSigners.includes(s))throw new Error("failed request. signer is not in the allowed signers list");let a=await r(t);return{nonce:t.nonce,type:"Iden3PaymentRailsSolanaV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaV1",paymentData:{txId:a,chainId:o.domain.chainId}}}async handleIden3PaymentRailsSolanaSPLRequestV1(t,r){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");if(!await sS(t,this._params.documentResolver))throw new Error("failed request. invalid Solana payment request signature");let o=Array.isArray(t.proof)?t.proof[0]:t.proof,s=o.verificationMethod.split(":").slice(-1)[0];if(this._params.allowedSigners&&!this._params.allowedSigners.includes(s))throw new Error("failed request. signer is not in the allowed signers list");let a=await r(t);return{nonce:t.nonce,type:"Iden3PaymentRailsSolanaSPLV1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsSolanaSPLV1",paymentData:{txId:a,chainId:o.domain.chainId,tokenAddress:t.tokenAddress}}}async handleIden3PaymentRailsERC20RequestV1(t,r,i){if(t.expirationDate&&new Date(t.expirationDate)<new Date)throw new Error("failed request. expired request");let o=await aS(t,this._params.documentResolver);if(this._params.allowedSigners&&!this._params.allowedSigners.includes(o))throw new Error("failed request. signer is not in the allowed signers list");if(!t.features?.includes("EIP-2612")&&!i)throw new Error("please provide erc20TokenApproveHandler in context for ERC-20 payment type");i&&await i(t);let s=await r(t),a=Array.isArray(t.proof)?t.proof[0]:t.proof;return{nonce:t.nonce,type:"Iden3PaymentRailsERC20V1","@context":"https://schema.iden3.io/core/jsonld/payment.jsonld#Iden3PaymentRailsERC20V1",paymentData:{txId:s,chainId:a.eip712.domain.chainId,tokenAddress:t.tokenAddress}}}};function XRe(n,e){let t=Ut();return{id:t,thid:t,typ:"application/iden3comm-plain-json",type:at.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE,body:{queries:n},from:e?.from,to:e?.to,created_time:Lt(new Date),expires_time:e?.expires_time}}function Ite(n,e){let t=Ut();return{id:t,typ:"application/iden3comm-plain-json",thid:t,type:at.DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE,body:{disclosures:n},from:e?.from,to:e?.to,created_time:Lt(new Date),expires_time:e?.expires_time}}var EF=class extends Ni{constructor(t){super();this._options=t;let r=["id","typ","type","thid","body","from","to","created_time","expires_time"];t.headers||(t.headers=r)}async handle(t,r){switch(t.type){case at.DISCOVERY_PROTOCOL_QUERIES_MESSAGE_TYPE:return await this.handleDiscoveryQuery(t,r);default:return super.handle(t,r)}}async handleDiscoveryQuery(t,r){r?.allowExpiredMessages||Lr(t);let i=[];for(let o of t.body.queries)i.push(...this.handleQuery(o));return Promise.resolve(Ite(i,{to:t.from,from:t.to,expires_time:r?.disclosureExpiresDate?Lt(r.disclosureExpiresDate):void 0}))}handleQuery(t){let r=[];switch(t["feature-type"]){case"accept":r=this.handleAcceptQuery();break;case"protocol":r=this.handleProtocolQuery();break;case"goal-code":r=this.handleGoalCodeQuery();break;case"header":r=this.handleHeaderQuery();break}return this.handleMatch(r,t.match)}handleAcceptQuery(){return this._options.packageManager.getSupportedProfiles().map(r=>({"feature-type":"accept",id:r}))}handleProtocolQuery(){return this._options.protocols?.map(t=>({"feature-type":"protocol",id:t}))??[]}handleGoalCodeQuery(){return this._options.goalCodes?.map(t=>({"feature-type":"goal-code",id:t}))??[]}handleHeaderQuery(){return this._options.headers?.map(t=>({"feature-type":"header",id:t}))??[]}handleMatch(t,r){if(!r||r==="*")return t;let i=this.wildcardToRegExp(r);return t.filter(o=>i.test(o.id))}wildcardToRegExp(t){let r=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${r}$`)}};function Ate(n,e){return{id:Ut(),pthid:e?.pthid,typ:"application/iden3comm-plain-json",type:at.PROBLEM_REPORT_MESSAGE_TYPE,ack:e?.ack,body:{code:n,comment:e?.comment,args:e?.args,escalate_to:e?.escalate_to},from:e?.from,to:e?.to}}function _Re(n,e,t){return Ate(e,{pthid:n,...t})}var xte=new TextEncoder,Z0=new TextDecoder,w8=2**32;function Ss(...n){let e=n.reduce((i,{length:o})=>i+o,0),t=new Uint8Array(e),r=0;for(let i of n)t.set(i,r),r+=i.length;return t}function IF(n,e,t){if(e<0||e>=w8)throw new RangeError(`value must be >= 0 and <= ${w8-1}. Received ${e}`);n.set([e>>>24,e>>>16,e>>>8,e&255],t)}function b8(n){let e=Math.floor(n/w8),t=n%w8,r=new Uint8Array(8);return IF(r,e,0),IF(r,t,4),r}function E8(n){let e=new Uint8Array(4);return IF(e,n),e}function Ka(n){let e=new Uint8Array(n.length);for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);if(r>127)throw new TypeError("non-ASCII string encountered in encode()");e[t]=r}return e}function vte(n){if(Uint8Array.prototype.toBase64)return n.toBase64();let e=32768,t=[];for(let r=0;r<n.length;r+=e)t.push(String.fromCharCode.apply(null,n.subarray(r,r+e)));return btoa(t.join(""))}function Ste(n){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(n);let e=atob(n),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function Zr(n){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof n=="string"?n:Z0.decode(n),{alphabet:"base64url"});let e=n;e instanceof Uint8Array&&(e=Z0.decode(e)),e=e.replace(/-/g,"+").replace(/_/g,"/");try{return Ste(e)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}function Xr(n){let e=n;return typeof e=="string"&&(e=xte.encode(e)),Uint8Array.prototype.toBase64?e.toBase64({alphabet:"base64url",omitPadding:!0}):vte(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var Xy=class extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};var hI=class extends Xy{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"},Zt=class extends Xy{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"},bh=class extends Xy{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}},Ve=class extends Xy{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"};function AF(n){switch(n){case"A128GCM":case"A128GCMKW":case"A192GCM":case"A192GCMKW":case"A256GCM":case"A256GCMKW":return 96;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return 128;default:throw new Zt(`Unsupported JWE Algorithm: ${n}`)}}var Cte=n=>crypto.getRandomValues(new Uint8Array(AF(n)>>3));function I8(n,e){if(e.length<<3!==AF(n))throw new Ve("Invalid Initialization Vector length")}function _y(n,e){let t=n.byteLength<<3;if(t!==e)throw new Ve(`Invalid Content Encryption Key length. Expected ${e} bits, got ${t} bits`)}var Eh=(n,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${n}`),A8=(n,e)=>n.name===e;function $Re(n){return parseInt(n.name.slice(4),10)}function eDe(n,e){if(e&&!n.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function Cs(n,e,t){switch(e){case"A128GCM":case"A192GCM":case"A256GCM":{if(!A8(n.algorithm,"AES-GCM"))throw Eh("AES-GCM");let r=parseInt(e.slice(1,4),10);if(n.algorithm.length!==r)throw Eh(r,"algorithm.length");break}case"A128KW":case"A192KW":case"A256KW":{if(!A8(n.algorithm,"AES-KW"))throw Eh("AES-KW");let r=parseInt(e.slice(1,4),10);if(n.algorithm.length!==r)throw Eh(r,"algorithm.length");break}case"ECDH":{switch(n.algorithm.name){case"ECDH":case"X25519":break;default:throw Eh("ECDH or X25519")}break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":if(!A8(n.algorithm,"PBKDF2"))throw Eh("PBKDF2");break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(!A8(n.algorithm,"RSA-OAEP"))throw Eh("RSA-OAEP");let r=parseInt(e.slice(9),10)||1;if($Re(n.algorithm.hash)!==r)throw Eh(`SHA-${r}`,"algorithm.hash");break}default:throw new TypeError("CryptoKey does not support this operation")}eDe(n,t)}function Lte(n,e,...t){if(t=t.filter(Boolean),t.length>2){let r=t.pop();n+=`one of type ${t.join(", ")}, or ${r}.`}else t.length===2?n+=`one of type ${t[0]} or ${t[1]}.`:n+=`of type ${t[0]}.`;return e==null?n+=` Received ${e}`:typeof e=="function"&&e.name?n+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(n+=` Received an instance of ${e.constructor.name}`),n}var Ih=(n,...e)=>Lte("Key must be ",n,...e),xF=(n,e,...t)=>Lte(`Key for the ${n} algorithm must be `,e,...t);function X0(n){if(!qu(n))throw new Error("CryptoKey instance expected")}var qu=n=>{if(n?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return n instanceof CryptoKey}catch{return!1}},pI=n=>n?.[Symbol.toStringTag]==="KeyObject",vF=n=>qu(n)||pI(n);async function tDe(n,e){if(!(n instanceof Uint8Array))throw new TypeError("First argument must be a buffer");if(!(e instanceof Uint8Array))throw new TypeError("Second argument must be a buffer");let t={name:"HMAC",hash:"SHA-256"},r=await crypto.subtle.generateKey(t,!1,["sign"]),i=new Uint8Array(await crypto.subtle.sign(t,r,n)),o=new Uint8Array(await crypto.subtle.sign(t,r,e)),s=0,a=-1;for(;++a<32;)s|=i[a]^o[a];return s===0}async function nDe(n,e,t,r,i,o){if(!(e instanceof Uint8Array))throw new TypeError(Ih(e,"Uint8Array"));let s=parseInt(n.slice(1,4),10),a=await crypto.subtle.importKey("raw",e.subarray(s>>3),"AES-CBC",!1,["decrypt"]),c=await crypto.subtle.importKey("raw",e.subarray(0,s>>3),{hash:`SHA-${s<<1}`,name:"HMAC"},!1,["sign"]),u=Ss(o,r,t,b8(o.length<<3)),l=new Uint8Array((await crypto.subtle.sign("HMAC",c,u)).slice(0,s>>3)),d;try{d=await tDe(i,l)}catch{}if(!d)throw new bh;let h;try{h=new Uint8Array(await crypto.subtle.decrypt({iv:r,name:"AES-CBC"},a,t))}catch{}if(!h)throw new bh;return h}async function rDe(n,e,t,r,i,o){let s;e instanceof Uint8Array?s=await crypto.subtle.importKey("raw",e,"AES-GCM",!1,["decrypt"]):(Cs(e,n,"decrypt"),s=e);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:o,iv:r,name:"AES-GCM",tagLength:128},s,Ss(t,i)))}catch{throw new bh}}async function x8(n,e,t,r,i,o){if(!qu(e)&&!(e instanceof Uint8Array))throw new TypeError(Ih(e,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!r)throw new Ve("JWE Initialization Vector missing");if(!i)throw new Ve("JWE Authentication Tag missing");switch(I8(n,r),n){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return e instanceof Uint8Array&&_y(e,parseInt(n.slice(-3),10)),nDe(n,e,t,r,i,o);case"A128GCM":case"A192GCM":case"A256GCM":return e instanceof Uint8Array&&_y(e,parseInt(n.slice(1,4),10)),rDe(n,e,t,r,i,o);default:throw new Zt("Unsupported JWE Content Encryption Algorithm")}}function $y(...n){let e=n.filter(Boolean);if(e.length===0||e.length===1)return!0;let t;for(let r of e){let i=Object.keys(r);if(!t||t.size===0){t=new Set(i);continue}for(let o of i){if(t.has(o))return!1;t.add(o)}}return!0}var iDe=n=>typeof n=="object"&&n!==null;function Zo(n){if(!iDe(n)||Object.prototype.toString.call(n)!=="[object Object]")return!1;if(Object.getPrototypeOf(n)===null)return!0;let e=n;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(n)===e}function Rte(n,e){if(n.algorithm.length!==parseInt(e.slice(1,4),10))throw new TypeError(`Invalid key size for alg: ${e}`)}function Dte(n,e,t){return n instanceof Uint8Array?crypto.subtle.importKey("raw",n,"AES-KW",!0,[t]):(Cs(n,e,t),n)}async function mI(n,e,t){let r=await Dte(e,n,"wrapKey");Rte(r,n);let i=await crypto.subtle.importKey("raw",t,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",i,r,"AES-KW"))}async function gI(n,e,t){let r=await Dte(e,n,"unwrapKey");Rte(r,n);let i=await crypto.subtle.unwrapKey("raw",t,r,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",i))}async function Tte(n,e){let t=`SHA-${n.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(t,e))}function CF(n){return Ss(E8(n.length),n)}async function oDe(n,e,t){let r=e>>3,i=32,o=Math.ceil(r/i),s=new Uint8Array(o*i);for(let a=1;a<=o;a++){let c=new Uint8Array(4+n.length+t.length);c.set(E8(a),0),c.set(n,4),c.set(t,4+n.length);let u=await Tte("sha256",c);s.set(u,(a-1)*i)}return s.slice(0,r)}async function v8(n,e,t,r,i=new Uint8Array,o=new Uint8Array){Cs(n,"ECDH"),Cs(e,"ECDH","deriveBits");let s=CF(Ka(t)),a=CF(i),c=CF(o),u=E8(r),l=new Uint8Array,d=Ss(s,a,c,u,l),h=new Uint8Array(await crypto.subtle.deriveBits({name:n.algorithm.name,public:n},e,sDe(n)));return oDe(h,r,d)}function sDe(n){return n.algorithm.name==="X25519"?256:Math.ceil(parseInt(n.algorithm.namedCurve.slice(-3),10)/8)<<3}function S8(n){switch(n.algorithm.namedCurve){case"P-256":case"P-384":case"P-521":return!0;default:return n.algorithm.name==="X25519"}}function aDe(n,e){return n instanceof Uint8Array?crypto.subtle.importKey("raw",n,"PBKDF2",!1,["deriveBits"]):(Cs(n,e,"deriveBits"),n)}var cDe=(n,e)=>Ss(Ka(n),Uint8Array.of(0),e);async function Pte(n,e,t,r){if(!(n instanceof Uint8Array)||n.length<8)throw new Ve("PBES2 Salt Input must be 8 or more octets");let i=cDe(e,n),o=parseInt(e.slice(13,16),10),s={hash:`SHA-${e.slice(8,11)}`,iterations:t,name:"PBKDF2",salt:i},a=await aDe(r,e);return new Uint8Array(await crypto.subtle.deriveBits(s,a,o))}async function kte(n,e,t,r=2048,i=crypto.getRandomValues(new Uint8Array(16))){let o=await Pte(i,n,r,e);return{encryptedKey:await mI(n.slice(-6),o,t),p2c:r,p2s:Xr(i)}}async function Mte(n,e,t,r,i){let o=await Pte(i,n,r,e);return gI(n.slice(-6),o,t)}function LF(n,e){if(n.startsWith("RS")||n.startsWith("PS")){let{modulusLength:t}=e.algorithm;if(typeof t!="number"||t<2048)throw new TypeError(`${n} requires key modulusLength to be 2048 bits or larger`)}}var Fte=n=>{switch(n){case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return"RSA-OAEP";default:throw new Zt(`alg ${n} is not supported either by JOSE or your javascript runtime`)}};async function Nte(n,e,t){return Cs(e,n,"encrypt"),LF(n,e),new Uint8Array(await crypto.subtle.encrypt(Fte(n),e,t))}async function Ute(n,e,t){return Cs(e,n,"decrypt"),LF(n,e),new Uint8Array(await crypto.subtle.decrypt(Fte(n),e,t))}function yI(n){switch(n){case"A128GCM":return 128;case"A192GCM":return 192;case"A256GCM":case"A128CBC-HS256":return 256;case"A192CBC-HS384":return 384;case"A256CBC-HS512":return 512;default:throw new Zt(`Unsupported JWE Algorithm: ${n}`)}}var Vu=n=>crypto.getRandomValues(new Uint8Array(yI(n)>>3));function uDe(n){let e,t;switch(n.kty){case"AKP":{switch(n.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":e={name:n.alg},t=n.priv?["sign"]:["verify"];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"RSA":{switch(n.alg){case"PS256":case"PS384":case"PS512":e={name:"RSA-PSS",hash:`SHA-${n.alg.slice(-3)}`},t=n.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":e={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${n.alg.slice(-3)}`},t=n.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":e={name:"RSA-OAEP",hash:`SHA-${parseInt(n.alg.slice(-3),10)||1}`},t=n.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"EC":{switch(n.alg){case"ES256":e={name:"ECDSA",namedCurve:"P-256"},t=n.d?["sign"]:["verify"];break;case"ES384":e={name:"ECDSA",namedCurve:"P-384"},t=n.d?["sign"]:["verify"];break;case"ES512":e={name:"ECDSA",namedCurve:"P-521"},t=n.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:"ECDH",namedCurve:n.crv},t=n.d?["deriveBits"]:[];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"OKP":{switch(n.alg){case"Ed25519":case"EdDSA":e={name:"Ed25519"},t=n.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:n.crv},t=n.d?["deriveBits"]:[];break;default:throw new Zt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}default:throw new Zt('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:e,keyUsages:t}}async function ew(n){if(!n.alg)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');let{algorithm:e,keyUsages:t}=uDe(n),r={...n};return r.kty!=="AKP"&&delete r.alg,delete r.use,crypto.subtle.importKey("jwk",r,e,n.ext??!(n.d||n.priv),n.key_ops??t)}async function Hte(n,e,t){if(!Zo(n))throw new TypeError("JWK must be an object");let r;switch(e??=n.alg,r??=t?.extractable??n.ext,n.kty){case"oct":if(typeof n.k!="string"||!n.k)throw new TypeError('missing "k" (Key Value) Parameter value');return Zr(n.k);case"RSA":if("oth"in n&&n.oth!==void 0)throw new Zt('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');return ew({...n,alg:e,ext:r});case"AKP":{if(typeof n.alg!="string"||!n.alg)throw new TypeError('missing "alg" (Algorithm) Parameter value');if(e!==void 0&&e!==n.alg)throw new TypeError("JWK alg and alg option value mismatch");return ew({...n,ext:r})}case"EC":case"OKP":return ew({...n,alg:e,ext:r});default:throw new Zt('Unsupported "kty" (Key Type) Parameter value')}}async function lDe(n,e,t,r,i){if(!(t instanceof Uint8Array))throw new TypeError(Ih(t,"Uint8Array"));let o=parseInt(n.slice(1,4),10),s=await crypto.subtle.importKey("raw",t.subarray(o>>3),"AES-CBC",!1,["encrypt"]),a=await crypto.subtle.importKey("raw",t.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]),c=new Uint8Array(await crypto.subtle.encrypt({iv:r,name:"AES-CBC"},s,e)),u=Ss(i,r,c,b8(i.length<<3)),l=new Uint8Array((await crypto.subtle.sign("HMAC",a,u)).slice(0,o>>3));return{ciphertext:c,tag:l,iv:r}}async function dDe(n,e,t,r,i){let o;t instanceof Uint8Array?o=await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["encrypt"]):(Cs(t,n,"encrypt"),o=t);let s=new Uint8Array(await crypto.subtle.encrypt({additionalData:i,iv:r,name:"AES-GCM",tagLength:128},o,e)),a=s.slice(-16);return{ciphertext:s.slice(0,-16),tag:a,iv:r}}async function C8(n,e,t,r,i){if(!qu(t)&&!(t instanceof Uint8Array))throw new TypeError(Ih(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));switch(r?I8(n,r):r=Cte(n),n){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return t instanceof Uint8Array&&_y(t,parseInt(n.slice(-3),10)),lDe(n,e,t,r,i);case"A128GCM":case"A192GCM":case"A256GCM":return t instanceof Uint8Array&&_y(t,parseInt(n.slice(1,4),10)),dDe(n,e,t,r,i);default:throw new Zt("Unsupported JWE Content Encryption Algorithm")}}async function Kte(n,e,t,r){let i=n.slice(0,7),o=await C8(i,t,e,r,new Uint8Array);return{encryptedKey:o.ciphertext,iv:Xr(o.iv),tag:Xr(o.tag)}}async function Jte(n,e,t,r,i){let o=n.slice(0,7);return x8(o,e,t,r,i,new Uint8Array)}async function qte(n,e,t,r,i){switch(n){case"dir":{if(t!==void 0)throw new Ve("Encountered unexpected JWE Encrypted Key");return e}case"ECDH-ES":if(t!==void 0)throw new Ve("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(!Zo(r.epk))throw new Ve('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(X0(e),!S8(e))throw new Zt("ECDH with the provided key is not allowed or not supported by your javascript runtime");let o=await Hte(r.epk,n);X0(o);let s,a;if(r.apu!==void 0){if(typeof r.apu!="string")throw new Ve('JOSE Header "apu" (Agreement PartyUInfo) invalid');try{s=Zr(r.apu)}catch{throw new Ve("Failed to base64url decode the apu")}}if(r.apv!==void 0){if(typeof r.apv!="string")throw new Ve('JOSE Header "apv" (Agreement PartyVInfo) invalid');try{a=Zr(r.apv)}catch{throw new Ve("Failed to base64url decode the apv")}}let c=await v8(o,e,n==="ECDH-ES"?r.enc:n,n==="ECDH-ES"?yI(r.enc):parseInt(n.slice(-5,-2),10),s,a);if(n==="ECDH-ES")return c;if(t===void 0)throw new Ve("JWE Encrypted Key missing");return gI(n.slice(-6),c,t)}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");return X0(e),Ute(n,e,t)}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");if(typeof r.p2c!="number")throw new Ve('JOSE Header "p2c" (PBES2 Count) missing or invalid');let o=i?.maxPBES2Count||1e4;if(r.p2c>o)throw new Ve('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof r.p2s!="string")throw new Ve('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let s;try{s=Zr(r.p2s)}catch{throw new Ve("Failed to base64url decode the p2s")}return Mte(n,e,t,r.p2c,s)}case"A128KW":case"A192KW":case"A256KW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");return gI(n,e,t)}case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{if(t===void 0)throw new Ve("JWE Encrypted Key missing");if(typeof r.iv!="string")throw new Ve('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof r.tag!="string")throw new Ve('JOSE Header "tag" (Authentication Tag) missing or invalid');let o;try{o=Zr(r.iv)}catch{throw new Ve("Failed to base64url decode the iv")}let s;try{s=Zr(r.tag)}catch{throw new Ve("Failed to base64url decode the tag")}return Jte(n,e,t,o,s)}default:throw new Zt('Invalid or unsupported "alg" (JWE Algorithm) header value')}}function tw(n,e,t,r,i){if(i.crit!==void 0&&r?.crit===void 0)throw new n('"crit" (Critical) Header Parameter MUST be integrity protected');if(!r||r.crit===void 0)return new Set;if(!Array.isArray(r.crit)||r.crit.length===0||r.crit.some(s=>typeof s!="string"||s.length===0))throw new n('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let o;t!==void 0?o=new Map([...Object.entries(t),...e.entries()]):o=e;for(let s of r.crit){if(!o.has(s))throw new Zt(`Extension Header Parameter "${s}" is not recognized`);if(i[s]===void 0)throw new n(`Extension Header Parameter "${s}" is missing`);if(o.get(s)&&r[s]===void 0)throw new n(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(r.crit)}function RF(n,e){if(e!==void 0&&(!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new TypeError(`"${n}" option must be an array of strings`);if(e)return new Set(e)}var wI=n=>Zo(n)&&typeof n.kty=="string",Vte=n=>n.kty!=="oct"&&(n.kty==="AKP"&&typeof n.priv=="string"||typeof n.d=="string"),Qte=n=>n.kty!=="oct"&&n.d===void 0&&n.priv===void 0,zte=n=>n.kty==="oct"&&typeof n.k=="string";var nw,Yte=async(n,e,t,r=!1)=>{nw||=new WeakMap;let i=nw.get(n);if(i?.[t])return i[t];let o=await ew({...e,alg:t});return r&&Object.freeze(n),i?i[t]=o:nw.set(n,{[t]:o}),o},hDe=(n,e)=>{nw||=new WeakMap;let t=nw.get(n);if(t?.[e])return t[e];let r=n.type==="public",i=!!r,o;if(n.asymmetricKeyType==="x25519"){switch(e){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}o=n.toCryptoKey(n.asymmetricKeyType,i,r?[]:["deriveBits"])}if(n.asymmetricKeyType==="ed25519"){if(e!=="EdDSA"&&e!=="Ed25519")throw new TypeError("given KeyObject instance cannot be used for this algorithm");o=n.toCryptoKey(n.asymmetricKeyType,i,[r?"verify":"sign"])}switch(n.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":{if(e!==n.asymmetricKeyType.toUpperCase())throw new TypeError("given KeyObject instance cannot be used for this algorithm");o=n.toCryptoKey(n.asymmetricKeyType,i,[r?"verify":"sign"])}}if(n.asymmetricKeyType==="rsa"){let s;switch(e){case"RSA-OAEP":s="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":s="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":s="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":s="SHA-512";break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}if(e.startsWith("RSA-OAEP"))return n.toCryptoKey({name:"RSA-OAEP",hash:s},i,r?["encrypt"]:["decrypt"]);o=n.toCryptoKey({name:e.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:s},i,[r?"verify":"sign"])}if(n.asymmetricKeyType==="ec"){let a=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(n.asymmetricKeyDetails?.namedCurve);if(!a)throw new TypeError("given KeyObject instance cannot be used for this algorithm");e==="ES256"&&a==="P-256"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e==="ES384"&&a==="P-384"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e==="ES512"&&a==="P-521"&&(o=n.toCryptoKey({name:"ECDSA",namedCurve:a},i,[r?"verify":"sign"])),e.startsWith("ECDH-ES")&&(o=n.toCryptoKey({name:"ECDH",namedCurve:a},i,r?[]:["deriveBits"]))}if(!o)throw new TypeError("given KeyObject instance cannot be used for this algorithm");return t?t[e]=o:nw.set(n,{[e]:o}),o};async function Ah(n,e){if(n instanceof Uint8Array||qu(n))return n;if(pI(n)){if(n.type==="secret")return n.export();if("toCryptoKey"in n&&typeof n.toCryptoKey=="function")try{return hDe(n,e)}catch(r){if(r instanceof TypeError)throw r}let t=n.export({format:"jwk"});return Yte(n,t,e)}if(wI(n))return n.k?Zr(n.k):Yte(n,n,e,!0);throw new Error("unreachable")}var rw=n=>n?.[Symbol.toStringTag],DF=(n,e,t)=>{if(e.use!==void 0){let r;switch(t){case"sign":case"verify":r="sig";break;case"encrypt":case"decrypt":r="enc";break}if(e.use!==r)throw new TypeError(`Invalid key for this operation, its "use" must be "${r}" when present`)}if(e.alg!==void 0&&e.alg!==n)throw new TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(e.key_ops)){let r;switch(!0){case(t==="sign"||t==="verify"):case n==="dir":case n.includes("CBC-HS"):r=t;break;case n.startsWith("PBES2"):r="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(n):!n.includes("GCM")&&n.endsWith("KW")?r=t==="encrypt"?"wrapKey":"unwrapKey":r=t;break;case(t==="encrypt"&&n.startsWith("RSA")):r="wrapKey";break;case t==="decrypt":r=n.startsWith("RSA")?"unwrapKey":"deriveBits";break}if(r&&e.key_ops?.includes?.(r)===!1)throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${r}" when present`)}return!0},pDe=(n,e,t)=>{if(!(e instanceof Uint8Array)){if(wI(e)){if(zte(e)&&DF(n,e,t))return;throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!vF(e))throw new TypeError(xF(n,e,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if(e.type!=="secret")throw new TypeError(`${rw(e)} instances for symmetric algorithms must be of type "secret"`)}},mDe=(n,e,t)=>{if(wI(e))switch(t){case"decrypt":case"sign":if(Vte(e)&&DF(n,e,t))return;throw new TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if(Qte(e)&&DF(n,e,t))return;throw new TypeError("JSON Web Key for this operation must be a public JWK")}if(!vF(e))throw new TypeError(xF(n,e,"CryptoKey","KeyObject","JSON Web Key"));if(e.type==="secret")throw new TypeError(`${rw(e)} instances for asymmetric algorithms must not be of type "secret"`);if(e.type==="public")switch(t){case"sign":throw new TypeError(`${rw(e)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw new TypeError(`${rw(e)} instances for asymmetric algorithm decryption must be of type "private"`)}if(e.type==="private")switch(t){case"verify":throw new TypeError(`${rw(e)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw new TypeError(`${rw(e)} instances for asymmetric algorithm encryption must be of type "public"`)}};function iw(n,e,t){switch(n.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":pDe(n,e,t);break;default:mDe(n,e,t)}}async function bI(n,e,t){if(!Zo(n))throw new Ve("Flattened JWE must be an object");if(n.protected===void 0&&n.header===void 0&&n.unprotected===void 0)throw new Ve("JOSE Header missing");if(n.iv!==void 0&&typeof n.iv!="string")throw new Ve("JWE Initialization Vector incorrect type");if(typeof n.ciphertext!="string")throw new Ve("JWE Ciphertext missing or incorrect type");if(n.tag!==void 0&&typeof n.tag!="string")throw new Ve("JWE Authentication Tag incorrect type");if(n.protected!==void 0&&typeof n.protected!="string")throw new Ve("JWE Protected Header incorrect type");if(n.encrypted_key!==void 0&&typeof n.encrypted_key!="string")throw new Ve("JWE Encrypted Key incorrect type");if(n.aad!==void 0&&typeof n.aad!="string")throw new Ve("JWE AAD incorrect type");if(n.header!==void 0&&!Zo(n.header))throw new Ve("JWE Shared Unprotected Header incorrect type");if(n.unprotected!==void 0&&!Zo(n.unprotected))throw new Ve("JWE Per-Recipient Unprotected Header incorrect type");let r;if(n.protected)try{let U=Zr(n.protected);r=JSON.parse(Z0.decode(U))}catch{throw new Ve("JWE Protected Header is invalid")}if(!$y(r,n.header,n.unprotected))throw new Ve("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let i={...r,...n.header,...n.unprotected};if(tw(Ve,new Map,t?.crit,r,i),i.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');let{alg:o,enc:s}=i;if(typeof o!="string"||!o)throw new Ve("missing JWE Algorithm (alg) in JWE Header");if(typeof s!="string"||!s)throw new Ve("missing JWE Encryption Algorithm (enc) in JWE Header");let a=t&&RF("keyManagementAlgorithms",t.keyManagementAlgorithms),c=t&&RF("contentEncryptionAlgorithms",t.contentEncryptionAlgorithms);if(a&&!a.has(o)||!a&&o.startsWith("PBES2"))throw new hI('"alg" (Algorithm) Header Parameter value not allowed');if(c&&!c.has(s))throw new hI('"enc" (Encryption Algorithm) Header Parameter value not allowed');let u;if(n.encrypted_key!==void 0)try{u=Zr(n.encrypted_key)}catch{throw new Ve("Failed to base64url decode the encrypted_key")}let l=!1;typeof e=="function"&&(e=await e(r,n),l=!0),iw(o==="dir"?s:o,e,"decrypt");let d=await Ah(e,o),h;try{h=await qte(o,d,u,i,t)}catch(U){if(U instanceof TypeError||U instanceof Ve||U instanceof Zt)throw U;h=Vu(s)}let f,m;if(n.iv!==void 0)try{f=Zr(n.iv)}catch{throw new Ve("Failed to base64url decode the iv")}if(n.tag!==void 0)try{m=Zr(n.tag)}catch{throw new Ve("Failed to base64url decode the tag")}let w=n.protected!==void 0?Ka(n.protected):new Uint8Array,b;n.aad!==void 0?b=Ss(w,Ka("."),Ka(n.aad)):b=w;let S;try{S=Zr(n.ciphertext)}catch{throw new Ve("Failed to base64url decode the ciphertext")}let G={plaintext:await x8(s,h,S,f,m,b)};if(n.protected!==void 0&&(G.protectedHeader=r),n.aad!==void 0)try{G.additionalAuthenticatedData=Zr(n.aad)}catch{throw new Ve("Failed to base64url decode the aad")}return n.unprotected!==void 0&&(G.sharedUnprotectedHeader=n.unprotected),n.header!==void 0&&(G.unprotectedHeader=n.header),l?{...G,key:d}:G}async function TF(n,e,t){if(!Zo(n))throw new Ve("General JWE must be an object");if(!Array.isArray(n.recipients)||!n.recipients.every(Zo))throw new Ve("JWE Recipients missing or incorrect type");if(!n.recipients.length)throw new Ve("JWE Recipients has no members");for(let r of n.recipients)try{return await bI({aad:n.aad,ciphertext:n.ciphertext,encrypted_key:r.encrypted_key,header:r.header,iv:n.iv,protected:n.protected,tag:n.tag,unprotected:n.unprotected},e,t)}catch{}throw new bh}var L8=Symbol();async function jte(n){if(pI(n))if(n.type==="secret")n=n.export();else return n.export({format:"jwk"});if(n instanceof Uint8Array)return{kty:"oct",k:Xr(n)};if(!qu(n))throw new TypeError(Ih(n,"CryptoKey","KeyObject","Uint8Array"));if(!n.extractable)throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:e,key_ops:t,alg:r,use:i,...o}=await crypto.subtle.exportKey("jwk",n);return o.kty==="AKP"&&(o.alg=r),o}async function Wte(n){return jte(n)}async function R8(n,e,t,r,i={}){let o,s,a;switch(n){case"dir":{a=t;break}case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(X0(t),!S8(t))throw new Zt("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:c,apv:u}=i,l;i.epk?l=await Ah(i.epk,n):l=(await crypto.subtle.generateKey(t.algorithm,!0,["deriveBits"])).privateKey;let{x:d,y:h,crv:f,kty:m}=await Wte(l),w=await v8(t,l,n==="ECDH-ES"?e:n,n==="ECDH-ES"?yI(e):parseInt(n.slice(-5,-2),10),c,u);if(s={epk:{x:d,crv:f,kty:m}},m==="EC"&&(s.epk.y=h),c&&(s.apu=Xr(c)),u&&(s.apv=Xr(u)),n==="ECDH-ES"){a=w;break}a=r||Vu(e);let b=n.slice(-6);o=await mI(b,w,a);break}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{a=r||Vu(e),X0(t),o=await Nte(n,t,a);break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{a=r||Vu(e);let{p2c:c,p2s:u}=i;({encryptedKey:o,...s}=await kte(n,t,a,c,u));break}case"A128KW":case"A192KW":case"A256KW":{a=r||Vu(e),o=await mI(n,t,a);break}case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{a=r||Vu(e);let{iv:c}=i;({encryptedKey:o,...s}=await Kte(n,t,a,c));break}default:throw new Zt('Invalid or unsupported "alg" (JWE Algorithm) header value')}return{cek:a,encryptedKey:o,parameters:s}}var EI=class{#e;#t;#n;#r;#i;#o;#s;#a;constructor(e){if(!(e instanceof Uint8Array))throw new TypeError("plaintext must be an instance of Uint8Array");this.#e=e}setKeyManagementParameters(e){if(this.#a)throw new TypeError("setKeyManagementParameters can only be called once");return this.#a=e,this}setProtectedHeader(e){if(this.#t)throw new TypeError("setProtectedHeader can only be called once");return this.#t=e,this}setSharedUnprotectedHeader(e){if(this.#n)throw new TypeError("setSharedUnprotectedHeader can only be called once");return this.#n=e,this}setUnprotectedHeader(e){if(this.#r)throw new TypeError("setUnprotectedHeader can only be called once");return this.#r=e,this}setAdditionalAuthenticatedData(e){return this.#i=e,this}setContentEncryptionKey(e){if(this.#o)throw new TypeError("setContentEncryptionKey can only be called once");return this.#o=e,this}setInitializationVector(e){if(this.#s)throw new TypeError("setInitializationVector can only be called once");return this.#s=e,this}async encrypt(e,t){if(!this.#t&&!this.#r&&!this.#n)throw new Ve("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!$y(this.#t,this.#r,this.#n))throw new Ve("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let r={...this.#t,...this.#r,...this.#n};if(tw(Ve,new Map,t?.crit,this.#t,r),r.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');let{alg:i,enc:o}=r;if(typeof i!="string"||!i)throw new Ve('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof o!="string"||!o)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');let s;if(this.#o&&(i==="dir"||i==="ECDH-ES"))throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${i}`);iw(i==="dir"?o:i,e,"encrypt");let a;{let b,S=await Ah(e,i);({cek:a,encryptedKey:s,parameters:b}=await R8(i,o,S,this.#o,this.#a)),b&&(t&&L8 in t?this.#r?this.#r={...this.#r,...b}:this.setUnprotectedHeader(b):this.#t?this.#t={...this.#t,...b}:this.setProtectedHeader(b))}let c,u,l,d;if(this.#t?(u=Xr(JSON.stringify(this.#t)),l=Ka(u)):(u="",l=new Uint8Array),this.#i){d=Xr(this.#i);let b=Ka(d);c=Ss(l,Ka("."),b)}else c=l;let{ciphertext:h,tag:f,iv:m}=await C8(o,this.#e,a,this.#s,c),w={ciphertext:Xr(h)};return m&&(w.iv=Xr(m)),f&&(w.tag=Xr(f)),s&&(w.encrypted_key=Xr(s)),d&&(w.aad=d),this.#t&&(w.protected=u),this.#n&&(w.unprotected=this.#n),this.#r&&(w.header=this.#r),w}};var BF=class{#e;unprotectedHeader;keyManagementParameters;key;options;constructor(e,t,r){this.#e=e,this.key=t,this.options=r}setUnprotectedHeader(e){if(this.unprotectedHeader)throw new TypeError("setUnprotectedHeader can only be called once");return this.unprotectedHeader=e,this}setKeyManagementParameters(e){if(this.keyManagementParameters)throw new TypeError("setKeyManagementParameters can only be called once");return this.keyManagementParameters=e,this}addRecipient(...e){return this.#e.addRecipient(...e)}encrypt(...e){return this.#e.encrypt(...e)}done(){return this.#e}},II=class{#e;#t=[];#n;#r;#i;constructor(e){this.#e=e}addRecipient(e,t){let r=new BF(this,e,{crit:t?.crit});return this.#t.push(r),r}setProtectedHeader(e){if(this.#n)throw new TypeError("setProtectedHeader can only be called once");return this.#n=e,this}setSharedUnprotectedHeader(e){if(this.#r)throw new TypeError("setSharedUnprotectedHeader can only be called once");return this.#r=e,this}setAdditionalAuthenticatedData(e){return this.#i=e,this}async encrypt(){if(!this.#t.length)throw new Ve("at least one recipient must be added");if(this.#t.length===1){let[i]=this.#t,o=await new EI(this.#e).setAdditionalAuthenticatedData(this.#i).setProtectedHeader(this.#n).setSharedUnprotectedHeader(this.#r).setUnprotectedHeader(i.unprotectedHeader).encrypt(i.key,{...i.options}),s={ciphertext:o.ciphertext,iv:o.iv,recipients:[{}],tag:o.tag};return o.aad&&(s.aad=o.aad),o.protected&&(s.protected=o.protected),o.unprotected&&(s.unprotected=o.unprotected),o.encrypted_key&&(s.recipients[0].encrypted_key=o.encrypted_key),o.header&&(s.recipients[0].header=o.header),s}let e;for(let i=0;i<this.#t.length;i++){let o=this.#t[i];if(!$y(this.#n,this.#r,o.unprotectedHeader))throw new Ve("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let s={...this.#n,...this.#r,...o.unprotectedHeader},{alg:a}=s;if(typeof a!="string"||!a)throw new Ve('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(a==="dir"||a==="ECDH-ES")throw new Ve('"dir" and "ECDH-ES" alg may only be used with a single recipient');if(typeof s.enc!="string"||!s.enc)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(!e)e=s.enc;else if(e!==s.enc)throw new Ve('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');if(tw(Ve,new Map,o.options.crit,this.#n,s),s.zip!==void 0)throw new Zt('JWE "zip" (Compression Algorithm) Header Parameter is not supported.')}let t=Vu(e),r={ciphertext:"",recipients:[]};for(let i=0;i<this.#t.length;i++){let o=this.#t[i],s={};if(r.recipients.push(s),i===0){let d=await new EI(this.#e).setAdditionalAuthenticatedData(this.#i).setContentEncryptionKey(t).setProtectedHeader(this.#n).setSharedUnprotectedHeader(this.#r).setUnprotectedHeader(o.unprotectedHeader).setKeyManagementParameters(o.keyManagementParameters).encrypt(o.key,{...o.options,[L8]:!0});r.ciphertext=d.ciphertext,r.iv=d.iv,r.tag=d.tag,d.aad&&(r.aad=d.aad),d.protected&&(r.protected=d.protected),d.unprotected&&(r.unprotected=d.unprotected),s.encrypted_key=d.encrypted_key,d.header&&(s.header=d.header);continue}let a=o.unprotectedHeader?.alg||this.#n?.alg||this.#r?.alg;iw(a==="dir"?e:a,o.key,"encrypt");let c=await Ah(o.key,a),{encryptedKey:u,parameters:l}=await R8(a,e,c,t,o.keyManagementParameters);s.encrypted_key=Xr(u),(o.unprotectedHeader||l)&&(s.header={...o.unprotectedHeader,...l})}return r}};function PF(n){let e;if(typeof n=="string"){let t=n.split(".");(t.length===3||t.length===5)&&([e]=t)}else if(typeof n=="object"&&n)if("protected"in n)e=n.protected;else throw new TypeError("Token does not contain a Protected Header");try{if(typeof e!="string"||!e)throw new Error;let t=JSON.parse(Z0.decode(Zr(e)));if(!Zo(t))throw new Error;return t}catch{throw new TypeError("Invalid Token or Protected Header formatting")}}var D8=class{constructor(e){this.resolvePrivateKeyByKid=e}async encrypt(e,t){let{enc:r,typ:i,recipients:o}=t,s=new II(e).setProtectedHeader({enc:r,typ:i});return o.forEach(({recipientJWK:c,alg:u,kid:l})=>{s.addRecipient(c).setUnprotectedHeader({alg:u,kid:l})}),await s.encrypt()}async decrypt(e){let t=(r,i)=>{let o=i.header?.kid||r&&r.kid;if(!o)throw new Error("kid is required");return this.resolvePrivateKeyByKid(o)};if(Object.prototype.hasOwnProperty.call(e,"encrypted_key")){let r=e;return r.header=this.removeDuplicates(PF(r),r.header||{}),bI(e,t)}return TF(e,t)}removeDuplicates=(e,t)=>{let r={...t};for(let[i,o]of Object.entries(e))r[i]===o&&delete r[i];return r}};var T8=class{constructor(e){this.kms=e}resolvePrivateKeyByKid=async e=>{let[,t]=e.split("#");if(!t)throw new Error("Missing key identifier");let[r]=t.split(":");if(!r)throw new Error("Missing key type in alias for default key resolver");let i=await this.kms.getKeyProvider(r)?.getPkStore();if(!i)throw new Error(`Key provider not found for ${r}`);try{return JSON.parse(await i.get({alias:t}))}catch{throw new Error(`Key not found for ${t}`)}}};var MF={};Rr(MF,{DeviceNotificationStatus:()=>_te,NotificationServiceType:()=>Zte,NotificationStatus:()=>Xte,PushNotifier:()=>kF});var Zte=(e=>(e.Push="push-notification",e))(Zte||{}),Xte=(t=>(t.Success="success",t.Failed="failed",t))(Xte||{});var _te=(r=>(r.Success="success",r.Rejected="rejected",r.Failed="failed",r))(_te||{}),gDe={type:"push-notification",send:async({url:n,pushService:e,message:t})=>{try{let r=new Request(n,{method:"POST",body:JSON.stringify({metadata:e.metadata,message:t})}),i=await fetch(r);if(i.status!==200)throw new Error(`could not send push notification, return status ${i.status}`);let o=await i.json();return{status:"success",devices:o}}catch(r){return{status:"failed",error:r.toString()}}}},kF=class{constructor(e=gDe){this._publisher=e;if(e.type!=="push-notification")throw new Error(`PushNotifier: publisher type ${e.type} is not supported`)}async notify(e,t){let r=(t.didDocument.service??[]).find(s=>s.type==="push-notification");if(!r)throw new Error("no push service in did document");if(!r.metadata?.devices?.length)throw new Error("no devices in push service");let o=[r.serviceEndpoint??[]].flat().reduce((s,a)=>typeof a=="string"?[...s,a]:typeof a.uri=="string"?[...s,a.uri]:s,[]).map(async s=>this._publisher.send({url:s,pushService:r,message:e}));return await Promise.all(o)}};var xd={url:"http://localhost:8545",defaultGasLimit:6e5,minGasPrice:"0",maxGasPrice:"100000000000",confirmationBlockCount:5,confirmationTimeout:6e5,contractAddress:"",receiptTimeout:6e5,rpcResponseTimeout:5e3,waitReceiptCycleTime:3e4,waitBlockCycleTime:3e3},$te={state:0n,replacedByState:0n,createdAtTimestamp:0n,replacedAtTimestamp:0n,createdAtBlock:0n,replacedAtBlock:0n},uI=class{constructor(e,t){this.ethConfig=e;let r=Array.isArray(e)?e[0]:e;this.provider=new jt(r.url),this.stateContract=new Ln(r.contractAddress,aM,this.provider),this._transactionService=new Xs(this.getRpcProvider()),this._latestStateCacheOptions={ttl:t?.latestStateCacheOptions?.ttl??jr.DEFAULT_PROOF_VERIFY_DELAY/2,maxSize:t?.latestStateCacheOptions?.maxSize??lg},this._stateCacheOptions={notReplacedTtl:t?.stateCacheOptions?.notReplacedTtl??jr.DEFAULT_PROOF_VERIFY_DELAY/2,replacedTtl:t?.stateCacheOptions?.replacedTtl??jr.DEFAULT_PROOF_VERIFY_DELAY,maxSize:t?.stateCacheOptions?.maxSize??lg},this._rootCacheOptions={replacedTtl:t?.rootCacheOptions?.replacedTtl??jr.DEFAULT_AUTH_VERIFY_DELAY,notReplacedTtl:t?.rootCacheOptions?.notReplacedTtl??jr.DEFAULT_AUTH_VERIFY_DELAY/2,maxSize:t?.rootCacheOptions?.maxSize??lg},this._gistProofCacheOptions={ttl:jr.DEFAULT_AUTH_VERIFY_DELAY/2,maxSize:t?.gistProofCacheOptions?.maxSize??lg},this._latestStateResolveCache=t?.latestStateCacheOptions?.cache??lh({maxSize:this._latestStateCacheOptions.maxSize,ttl:this._latestStateCacheOptions.ttl}),this._stateResolveCache=t?.stateCacheOptions?.cache??lh({maxSize:this._stateCacheOptions.maxSize,ttl:this._stateCacheOptions.replacedTtl}),this._rootResolveCache=t?.rootCacheOptions?.cache??lh({maxSize:this._rootCacheOptions.maxSize,ttl:this._rootCacheOptions.replacedTtl}),this._gistProofResolveCache=t?.gistProofCacheOptions?.cache??lh({maxSize:this._gistProofCacheOptions.maxSize,ttl:this._gistProofCacheOptions.ttl}),this._disableCache=t?.disableCache??!1}stateContract;provider;_transactionService;_latestStateResolveCache;_stateResolveCache;_rootResolveCache;_gistProofResolveCache;_latestStateCacheOptions;_stateCacheOptions;_rootCacheOptions;_gistProofCacheOptions;_disableCache=!1;async getLatestStateById(e){let t=this.getLatestStateCacheKey(e);if(!this._disableCache){let s=await this._latestStateResolveCache?.get(t);if(s){if(s.state===0n&&s.createdAtTimestamp===0n)throw new Error(Ge.ERRORS.IDENTITY_DOES_NOT_EXIST_CUSTOM_ERROR);return s}}let{stateContract:r}=this.getStateContractAndProviderForId(e),i=[];try{i=await r.getStateInfoById(e)}catch(s){throw z0(s)&&!this._disableCache&&await this._latestStateResolveCache?.set(t,{id:e,...$te},this._latestStateCacheOptions.ttl),s}let o={id:BigInt(i[0]),state:BigInt(i[1]),replacedByState:BigInt(i[2]),createdAtTimestamp:BigInt(i[3]),replacedAtTimestamp:BigInt(i[4]),createdAtBlock:BigInt(i[5]),replacedAtBlock:BigInt(i[6])};return!this._disableCache&&await this._latestStateResolveCache?.set(t,o,this._latestStateCacheOptions.ttl),o}async getStateInfoByIdAndState(e,t){let r=this.getStateCacheKey(e,t);if(!this._disableCache){let a=await this._stateResolveCache?.get(r);if(a)return a}let{stateContract:i}=this.getStateContractAndProviderForId(e),o;try{let a=await i.getStateInfoByIdAndState(e,t);o={id:BigInt(a[0]),state:BigInt(a[1]),replacedByState:BigInt(a[2]),createdAtTimestamp:BigInt(a[3]),replacedAtTimestamp:BigInt(a[4]),createdAtBlock:BigInt(a[5]),replacedAtBlock:BigInt(a[6])}}catch(a){if(!sF(a))throw a;if(!xx(Xe.fromBigInt(e),t))throw new Error(`State ${t} for identity ${e} is not genesis and not registered in the smart contract`);o={id:e,...$te,state:t}}let s=o.replacedAtTimestamp===0n?this._stateCacheOptions.notReplacedTtl:this._stateCacheOptions.replacedTtl;return!this._disableCache&&await this._stateResolveCache?.set(r,o,s),o}async publishState(e,t){let r=new vE;r.pubSignalsUnmarshal(ke.encode(JSON.stringify(e.pub_signals)));let{userId:i,oldUserState:o,newUserState:s,isOldStateGenesis:a}=r,{stateContract:c,provider:u}=this.getStateContractAndProviderForId(i.bigInt()),l=c.connect(t),d=M0(e.proof),h=[i.bigInt().toString(),o.bigInt().toString(),s.bigInt().toString(),a,d.a,d.b,d.c],f=await u.getFeeData(),m=xd.maxFeePerGas?BigInt(xd.maxFeePerGas):f.maxFeePerGas,w=xd.maxPriorityFeePerGas?BigInt(xd.maxPriorityFeePerGas):f.maxPriorityFeePerGas,b=await l.transitState.estimateGas(...h),S=await l.transitState.populateTransaction(...h),R={to:S.to,data:S.data,gasLimit:b,maxFeePerGas:m,maxPriorityFeePerGas:w},{txnHash:G}=await this._transactionService.sendTransactionRequest(t,R);return await this._latestStateResolveCache?.delete(this.getLatestStateCacheKey(i.bigInt())),G}async publishStateGeneric(e,t){let{userId:r,oldUserState:i,newUserState:o,isOldStateGenesis:s,methodId:a,methodParams:c}=t,{stateContract:u,provider:l}=this.getStateContractAndProviderForId(r.bigInt()),d=u.connect(e),h=await l.getFeeData(),f=xd.maxFeePerGas?BigInt(xd.maxFeePerGas):h.maxFeePerGas,m=xd.maxPriorityFeePerGas?BigInt(xd.maxPriorityFeePerGas):h.maxPriorityFeePerGas,w=[r.bigInt().toString(),i.bigInt().toString(),o.bigInt().toString(),s,a,c],b=await d.transitStateGeneric.estimateGas(...w),S=await d.transitStateGeneric.populateTransaction(...w),R={to:S.to,data:S.data,gasLimit:b,maxFeePerGas:f,maxPriorityFeePerGas:m},{txnHash:G}=await this._transactionService.sendTransactionRequest(e,R);return await this._latestStateResolveCache?.delete(this.getLatestStateCacheKey(r.bigInt())),G}async getGISTProof(e){let t=this.getGistProofCacheKey(e);if(!this._disableCache){let s=await this._gistProofResolveCache?.get(t);if(s)return s}let{stateContract:r}=this.getStateContractAndProviderForId(e),i=await r.getGISTProof(e),o={root:BigInt(i.root.toString()),existence:i.existence,siblings:i.siblings?.map(s=>BigInt(s.toString())),index:BigInt(i.index.toString()),value:BigInt(i.value.toString()),auxExistence:i.auxExistence,auxIndex:BigInt(i.auxIndex.toString()),auxValue:BigInt(i.auxValue.toString())};return!this._disableCache&&await this._gistProofResolveCache?.set(t,o,this._gistProofCacheOptions.ttl),o}async getGISTRootInfo(e,t){let r=Xe.fromBigInt(t),i=tm(ve.blockchainFromId(r),ve.networkIdFromId(r)),o=this.getRootCacheKey(i,e);if(!this._disableCache){let l=await this._rootResolveCache?.get(o);if(l)return l}let{stateContract:s}=this.getStateContractAndProviderForId(t),a=await s.getGISTRootInfo(e),c={root:BigInt(a.root.toString()),replacedByRoot:BigInt(a.replacedByRoot.toString()),createdAtTimestamp:BigInt(a.createdAtTimestamp.toString()),replacedAtTimestamp:BigInt(a.replacedAtTimestamp.toString()),createdAtBlock:BigInt(a.createdAtBlock.toString()),replacedAtBlock:BigInt(a.replacedAtBlock.toString())},u=c.replacedAtTimestamp==0n?this._rootCacheOptions.notReplacedTtl:this._rootCacheOptions.replacedTtl;return!this._disableCache&&await this._rootResolveCache?.set(o,c,u),c}getRpcProvider(){return this.provider}enableCache(){this._disableCache=!1}disableCache(){this._disableCache=!0}getStateContractAndProviderForId(e){let t=Xe.fromBigInt(e),r=tm(ve.blockchainFromId(t),ve.networkIdFromId(t)),i=this.networkByChainId(r),o=new jt(i.url);return{stateContract:new Ln(i.contractAddress,aM,o),provider:o}}networkByChainId(e){let r=(Array.isArray(this.ethConfig)?this.ethConfig:[this.ethConfig]).find(i=>i.chainId===e);if(!r)throw new Error(`chainId "${e}" not supported`);return r}getGistProofCacheKey(e){return`gist:${e.toString()}`}getLatestStateCacheKey(e){return`latest-state:${e.toString()}`}getStateCacheKey(e,t){return`state:${e.toString()}-${t.toString()}`}getRootCacheKey(e,t){return`root:${e.toString()}-${t.toString()}`}};var OF=[{inputs:[],name:"InvalidInitialization",type:"error"},{inputs:[{internalType:"string",name:"message",type:"string"},{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256",name:"linkID",type:"uint256"},{internalType:"uint64",name:"requestIdToCompare",type:"uint64"},{internalType:"uint256",name:"linkIdToCompare",type:"uint256"}],name:"LinkedProofError",type:"error"},{inputs:[],name:"NotInitializing",type:"error"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"OwnableInvalidOwner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"OwnableUnauthorizedAccount",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"version",type:"uint64"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"requestId",type:"uint64"},{indexed:!0,internalType:"address",name:"requestOwner",type:"address"},{indexed:!1,internalType:"string",name:"metadata",type:"string"},{indexed:!1,internalType:"address",name:"validator",type:"address"},{indexed:!1,internalType:"bytes",name:"data",type:"bytes"}],name:"ZKPRequestSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"requestId",type:"uint64"},{indexed:!0,internalType:"address",name:"caller",type:"address"}],name:"ZKPResponseSubmitted",type:"event"},{inputs:[],name:"REQUESTS_RETURN_LIMIT",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"acceptOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"addValidatorToWhitelist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"disableZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"enableZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getProofStatus",outputs:[{components:[{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"uint256",name:"blockTimestamp",type:"uint256"}],internalType:"struct IZKPVerifier.ProofStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"string",name:"key",type:"string"}],name:"getProofStorageField",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getRequestOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"getZKPRequest",outputs:[{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest",name:"zkpRequest",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"length",type:"uint256"}],name:"getZKPRequests",outputs:[{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getZKPRequestsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IStateCrossChain",name:"stateCrossChain",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64",name:"requestId",type:"uint64"}],name:"isProofVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"isWhitelistedValidator",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"isZKPRequestEnabled",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pendingOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract ICircuitValidator",name:"validator",type:"address"}],name:"removeValidatorFromWhitelist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"}],name:"requestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"address",name:"requestOwner",type:"address"}],name:"setRequestOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{components:[{internalType:"string",name:"metadata",type:"string"},{internalType:"contract ICircuitValidator",name:"validator",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct IZKPVerifier.ZKPRequest",name:"request",type:"tuple"}],name:"setZKPRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256[]",name:"inputs",type:"uint256[]"},{internalType:"uint256[2]",name:"a",type:"uint256[2]"},{internalType:"uint256[2][2]",name:"b",type:"uint256[2][2]"},{internalType:"uint256[2]",name:"c",type:"uint256[2]"}],name:"submitZKPResponse",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"bytes",name:"zkProof",type:"bytes"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ZKPResponse[]",name:"responses",type:"tuple[]"},{internalType:"bytes",name:"crossChainProof",type:"bytes"}],name:"submitZKPResponseV2",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint64[]",name:"requestIds",type:"uint64[]"}],name:"verifyLinkedProofs",outputs:[],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"requestId",type:"uint64"},{internalType:"uint256[]",name:"inputs",type:"uint256[]"},{internalType:"uint256[2]",name:"a",type:"uint256[2]"},{internalType:"uint256[2][2]",name:"b",type:"uint256[2][2]"},{internalType:"uint256[2]",name:"c",type:"uint256[2]"},{internalType:"address",name:"sender",type:"address"}],name:"verifyZKPResponse",outputs:[{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"inputValue",type:"uint256"}],internalType:"struct ICircuitValidator.KeyToInputValue[]",name:"",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"}];var FF=[{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"address",name:"userAddress",type:"address"}],name:"areMultiRequestProofsVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"groupID",type:"uint256"}],name:"getGroupedRequests",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.RequestInfo[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getGroupsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"}],name:"getMultiRequest",outputs:[{components:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"uint256[]",name:"requestIds",type:"uint256[]"},{internalType:"uint256[]",name:"groupIds",type:"uint256[]"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.MultiRequest",name:"multiRequest",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"address",name:"userAddress",type:"address"}],name:"getMultiRequestProofsStatus",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"timestamp",type:"uint256"}],internalType:"struct IVerifier.RequestProofStatus[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"}],name:"getRequest",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.RequestInfo",name:"request",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"requestId",type:"uint256"}],name:"getRequestProofStatus",outputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bool",name:"isVerified",type:"bool"},{internalType:"string",name:"validatorVersion",type:"string"},{internalType:"uint256",name:"timestamp",type:"uint256"}],internalType:"struct IVerifier.RequestProofStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRequestsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"address",name:"sender",type:"address"},{internalType:"string",name:"responseFieldName",type:"string"}],name:"getResponseFieldValue",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"address",name:"sender",type:"address"}],name:"getResponseFields",outputs:[{components:[{internalType:"string",name:"name",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct IRequestValidator.ResponseField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"groupId",type:"uint256"}],name:"groupIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"requestId",type:"uint256"}],name:"isRequestProofVerified",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"multiRequestId",type:"uint256"}],name:"multiRequestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"requestId",type:"uint256"}],name:"requestIdExists",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"string",name:"authMethod",type:"string"},{internalType:"contract IAuthValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"}],internalType:"struct IVerifier.AuthMethod",name:"authMethod",type:"tuple"}],name:"setAuthMethod",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint256",name:"multiRequestId",type:"uint256"},{internalType:"uint256[]",name:"requestIds",type:"uint256[]"},{internalType:"uint256[]",name:"groupIds",type:"uint256[]"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.MultiRequest",name:"multiRequest",type:"tuple"}],name:"setMultiRequest",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"string",name:"metadata",type:"string"},{internalType:"contract IRequestValidator",name:"validator",type:"address"},{internalType:"bytes",name:"params",type:"bytes"},{internalType:"address",name:"creator",type:"address"}],internalType:"struct IVerifier.Request[]",name:"requests",type:"tuple[]"}],name:"setRequests",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"string",name:"authMethod",type:"string"},{internalType:"bytes",name:"proof",type:"bytes"}],internalType:"struct IVerifier.AuthResponse",name:"authResponse",type:"tuple"},{components:[{internalType:"uint256",name:"requestId",type:"uint256"},{internalType:"bytes",name:"proof",type:"bytes"},{internalType:"bytes",name:"metadata",type:"bytes"}],internalType:"struct IVerifier.Response[]",name:"responses",type:"tuple[]"},{internalType:"bytes",name:"crossChainProofs",type:"bytes"}],name:"submitResponse",outputs:[],stateMutability:"nonpayable",type:"function"}];var NF=10000000n,ene=(r=>(r.SubmitZKPResponseV1="b68967e2",r.SubmitZKPResponseV2="ade09fcd",r.SubmitResponse="06c86a91",r))(ene||{}),tne=function(n){return[{authMethod:n.authProof.raw.authMethod,proof:n.authProof.encoded},n.proofs.map(e=>({requestId:e.requestId,proof:e.encoded,metadata:e.metadata})),n.crossChainProof.encoded]},UF=class n{constructor(e,t){this._configs=e;this._opts=t}static _supportedCircuits=["authV2","authV3","authV3-8-32","credentialAtomicQueryMTPV2OnChain","credentialAtomicQuerySigV2OnChain","credentialAtomicQueryV3OnChain-beta.1","credentialAtomicQueryV3OnChain"];static async prepareTxArgsSubmitV1(e,t){if(e.method_id.replace("0x","")!=="b68967e2")throw new Error("prepareTxArgsSubmitV1 function doesn't implement requested method id. Only '0xb68967e2' is supported.");let r=t.id,i=t.pub_signals,o=M0(t.proof);return[r,i,o.a,o.b,o.c]}async prepareTxArgsSubmitV1(e,t){return n.prepareTxArgsSubmitV1(e,t)}async submitZKPResponse(e,t,r){let i=this._configs.find(d=>d.chainId==t.chain_id);if(!i)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="b68967e2")throw new Error("submitZKPResponse function doesn't implement requested method id. Only '0xb68967e2' is supported.");let o=new jt(i.url,i.chainId);e=e.connect(o);let s=new Map,a=await o.getFeeData(),c=i.maxFeePerGas?BigInt(i.maxFeePerGas):a.maxFeePerGas,u=i.maxPriorityFeePerGas?BigInt(i.maxPriorityFeePerGas):a.maxPriorityFeePerGas,l=new Ln(t.contract_address,OF);for(let d of r){let h=await this.prepareTxArgsSubmitV1(t,d),f=await l.submitZKPResponse.populateTransaction(...h),m={to:t.contract_address,data:f.data,maxFeePerGas:c,maxPriorityFeePerGas:u},w;try{w=await e.estimateGas(m)}catch{w=NF}m.gasLimit=w;let b=new Xs(o),{txnHash:S}=await b.sendTransactionRequest(e,m);s.set(S,d)}return s}async submitZKPResponseV2(e,t,r){let i=this._configs.find(b=>b.chainId==t.chain_id);if(!i)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="ade09fcd")throw new Error("submitZKPResponseV2 function doesn't implement requested method id. Only '0xade09fcd' is supported.");if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");let o=new jt(i.url,i.chainId);e=e.connect(o);let s=await this.prepareTxArgsSubmitV2(t,r),a=await o.getFeeData(),c=i.maxFeePerGas?BigInt(i.maxFeePerGas):a.maxFeePerGas,u=i.maxPriorityFeePerGas?BigInt(i.maxPriorityFeePerGas):a.maxPriorityFeePerGas,d=await new Ln(t.contract_address,OF).submitZKPResponseV2.populateTransaction(...s),h={to:t.contract_address,data:d.data,maxFeePerGas:c,maxPriorityFeePerGas:u},f;try{f=await e.estimateGas(h)}catch{f=NF}h.gasLimit=f;let m=new Xs(o),{txnHash:w}=await m.sendTransactionRequest(e,h);return new Map().set(w,r)}async submitResponse(e,t,r,i){let o=this._configs.find(S=>S.chainId==t.chain_id);if(!o)throw new Error(`config for chain id ${t.chain_id} was not found`);if(t.method_id.replace("0x","")!=="06c86a91")throw new Error("submitResponse function doesn't implement requested method id. Only '0x06c86a91' is supported.");if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");let s=new jt(o.url,o.chainId);e=e.connect(s);let a=await this.prepareTxArgsSubmit(t,r,i),c=await s.getFeeData(),u=o.maxFeePerGas?BigInt(o.maxFeePerGas):c.maxFeePerGas,l=o.maxPriorityFeePerGas?BigInt(o.maxPriorityFeePerGas):c.maxPriorityFeePerGas,h=await new Ln(t.contract_address,FF).submitResponse.populateTransaction(...a.txDataArgs),f={to:t.contract_address,data:h.data,maxFeePerGas:u,maxPriorityFeePerGas:l},m;try{m=await e.estimateGas(f)}catch{m=NF}f.gasLimit=m;let w=new Xs(s),{txnHash:b}=await w.sendTransactionRequest(e,f);return new Map().set(b,{authProof:a.result.authProof.raw,crossChainProof:a.result.crossChainProof.raw,responses:a.result.proofs.map(S=>S.proof)})}static async prepareTxArgsSubmit(e,t,r,i){if(t.method_id.replace("0x","")!=="06c86a91")throw new Error("submit cross chain doesn't implement requested method id. Only '0x06c86a91' is supported.");let o=[],s=[],a=[],c="0x",u="";switch(i.authMethod){case"authV2":case"authV3":case"authV3-8-32":{let f=M0(i.zkp.proof);u=wC(i.zkp.pub_signals,f.a,f.b,f.c);break}case"ethIdentity":{u=nne(i.userDid);break}case"embeddedAuth":{u="0x";break}default:throw new Error("auth proof must use method authV2, authV3, authV3-8-32 or ethIdentity")}for(let f of r){this.checkSupportedCircuit(f.circuitId);let{requestId:m,zkProofEncoded:w,metadata:b}=aI(f);a.push({proof:f,requestId:m,encoded:w,metadata:b})}let l=r.map(f=>({circuitId:f.circuitId,pub_signals:f.pub_signals}));["authV2","authV3","authV3-8-32"].includes(i.authMethod)&&l.push({circuitId:i.zkp.circuitId,pub_signals:i.zkp.pub_signals});for(let f of l){let{gistUpdateResolutions:m,stateUpdateResolutions:w}=this.getUpdateResolutions(e,t.chain_id,f.circuitId,f.pub_signals);m.length>0&&o.push(...await Promise.all(m)),w.length>0&&s.push(...await Promise.all(w))}let d=o.length||s.length?this.packCrossChainProofs(o,s):c,h={authProof:{raw:i,encoded:u},proofs:a,crossChainProof:{raw:{globalStateProofs:o||[],identityStateProofs:s||[]},encoded:d}};return{result:h,txDataArgs:tne(h)}}async prepareTxArgsSubmit(e,t,r){if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");return n.prepareTxArgsSubmit(this._opts.didResolverUrl,e,t,r)}static checkSupportedCircuit(e){if(!iM(this._supportedCircuits).includes(e))throw new Error(`Circuit ${e} not supported by OnChainZKPVerifier`)}static getCrossChainResolvers(e,t,r,i){return[...new Set(e.map(o=>JSON.stringify({id:o.id.string(),[r]:r==="gist"?o.root?.string():o.state?.string()})))].reduce((o,s)=>{let a=JSON.parse(s),c=Xe.fromString(a.id),u=lw(ve.parseFromId(c));if(t===u)return o;let l=this.resolveDidDocumentEip712MessageAndSignature(ve.parseFromId(Xe.fromString(a.id)),i,{[r]:be.fromString(a[r])});return[...o,l]},[])}static async prepareTxArgsSubmitV2(e,t,r){if(t.method_id.replace("0x","")!=="ade09fcd")throw new Error("submit cross chain doesn't implement requested method id. Only '0xade09fcd' is supported.");let i=[],o=[],s=[],a="0x";for(let u of r){this.checkSupportedCircuit(u.circuitId);let{requestId:l,zkProofEncoded:d,metadata:h}=aI(u);s.push({requestId:l,zkProof:d,data:h});let{gistUpdateResolutions:f,stateUpdateResolutions:m}=this.getUpdateResolutions(e,t.chain_id,u.circuitId,u.pub_signals);f.length>0&&i.push(...await Promise.all(f)),m.length>0&&o.push(...await Promise.all(m))}let c=i.length||o.length?this.packCrossChainProofs(i,o):a;return[s,c]}async prepareTxArgsSubmitV2(e,t){if(!this._opts?.didResolverUrl)throw new Error("did resolver url required for crosschain verification");return n.prepareTxArgsSubmitV2(this._opts.didResolverUrl,e,t)}static getUpdateResolutions(e,t,r,i){let o=this.getOnChainGistRootStatePubSignals(r,i),s=this.getCrossChainResolvers(o.gists,t,"gist",e),a=this.getCrossChainResolvers(o.states,t,"state",e);return{gistUpdateResolutions:s,stateUpdateResolutions:a}}static packCrossChainProofs(e,t){let r=[];for(let i of e)r.push({proofType:"globalStateProof",proof:this.packGlobalStateMsg(i)});for(let i of t)r.push({proofType:"stateProof",proof:this.packIdentityStateMsg(i)});return new mn.AbiCoder().encode(["tuple(string proofType,bytes proof)[]"],[r])}static packGlobalStateMsg(e){return new mn.AbiCoder().encode(["tuple(tuple(uint256 timestamp,bytes2 idType,uint256 root,uint256 replacedAtTimestamp) globalStateMsg,bytes signature,)"],[e])}static packIdentityStateMsg(e){return new mn.AbiCoder().encode(["tuple(tuple(uint256 timestamp,uint256 id,uint256 state,uint256 replacedAtTimestamp) idStateMsg,bytes signature,)"],[e])}static getOnChainGistRootStatePubSignals(e,t){let r=sM(e);if(!r||!r.unmarshaller)throw new Error(`Circuit ${e} not supported by OnChainZKPVerifier`);let i=r.unmarshaller,o=new i(r.opts),s=ke.encode(JSON.stringify(t)),a=o.pubSignalsUnmarshal(s);if(a.getStatesInfo===void 0)throw new Error(`Public signals unmarshaller for circuit ${e} does not support getStatesInfo method`);return a.getStatesInfo()}static async resolveDidDocumentEip712MessageAndSignature(e,t,r){let i=await yp(e,t,{...r,signature:"EthereumEip712Signature2021"});if(!i.didResolutionMetadata.proof?.length)throw new Error("No proof found in resolved DID document");let o=i.didResolutionMetadata.proof[0].eip712.message,s=i.didResolutionMetadata.proof[0].proofValue;return r?.gist&&!r.state?{globalStateMsg:{timestamp:o.timestamp,idType:o.idType,root:o.root,replacedAtTimestamp:o.replacedAtTimestamp},signature:s}:{idStateMsg:{timestamp:o.timestamp,id:o.id,state:o.state,replacedAtTimestamp:o.replacedAtTimestamp},signature:s}}},nne=n=>`0x${Br(It.intToBytes(ve.idFromDID(n).bigInt()))}`;var GF=[{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"},{internalType:"uint256",name:"_credentialId",type:"uint256"}],name:"getCredential",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"string[]",name:"context",type:"string[]"},{internalType:"string",name:"_type",type:"string"},{internalType:"uint64",name:"issuanceDate",type:"uint64"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.CredentialSchema",name:"credentialSchema",type:"tuple"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.DisplayMethod",name:"displayMethod",type:"tuple"}],internalType:"struct INonMerklizedIssuer.CredentialData",name:"",type:"tuple"},{internalType:"uint256[8]",name:"",type:"uint256[8]"},{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct INonMerklizedIssuer.SubjectField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCredentialAdapterVersion",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"}],name:"getUserCredentialIds",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"}];var HF=[{inputs:[],name:"CREDENTIAL_ADAPTER_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"}],name:"getClaimProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getClaimProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimIndexHash",type:"uint256"}],name:"getClaimProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getClaimsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"},{internalType:"uint256",name:"_credentialId",type:"uint256"}],name:"getCredential",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"string[]",name:"context",type:"string[]"},{internalType:"string",name:"_type",type:"string"},{internalType:"uint64",name:"issuanceDate",type:"uint64"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.CredentialSchema",name:"credentialSchema",type:"tuple"},{components:[{internalType:"string",name:"id",type:"string"},{internalType:"string",name:"_type",type:"string"}],internalType:"struct INonMerklizedIssuer.DisplayMethod",name:"displayMethod",type:"tuple"}],internalType:"struct INonMerklizedIssuer.CredentialData",name:"",type:"tuple"},{internalType:"uint256[8]",name:"",type:"uint256[8]"},{components:[{internalType:"string",name:"key",type:"string"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"rawValue",type:"bytes"}],internalType:"struct INonMerklizedIssuer.SubjectField[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCredentialAdapterVersion",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"pure",type:"function"},{inputs:[],name:"getId",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getIsOldStateGenesis",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedClaimsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedRevocationsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedRootsRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLatestPublishedState",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"}],name:"getRevocationProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getRevocationProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint64",name:"revocationNonce",type:"uint64"}],name:"getRevocationProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatus",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint64",name:"nonce",type:"uint64"}],name:"getRevocationStatusByIdAndState",outputs:[{components:[{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"revocationTreeRoot",type:"uint256"},{internalType:"uint256",name:"rootOfRoots",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.IdentityStateRoots",name:"issuer",type:"tuple"},{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct IOnchainCredentialStatusResolver.Proof",name:"mtp",type:"tuple"}],internalType:"struct IOnchainCredentialStatusResolver.CredentialStatus",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRevocationsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"rootsTreeRoot",type:"uint256"}],name:"getRootProof",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"claimsTreeRoot",type:"uint256"},{internalType:"uint256",name:"root",type:"uint256"}],name:"getRootProofByRoot",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"rootsTreeRoot",type:"uint256"}],name:"getRootProofWithStateInfo",outputs:[{components:[{internalType:"uint256",name:"root",type:"uint256"},{internalType:"bool",name:"existence",type:"bool"},{internalType:"uint256[]",name:"siblings",type:"uint256[]"},{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"auxExistence",type:"bool"},{internalType:"uint256",name:"auxIndex",type:"uint256"},{internalType:"uint256",name:"auxValue",type:"uint256"}],internalType:"struct SmtLib.Proof",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"state",type:"uint256"},{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.StateInfo",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"state",type:"uint256"}],name:"getRootsByState",outputs:[{components:[{internalType:"uint256",name:"claimsRoot",type:"uint256"},{internalType:"uint256",name:"revocationsRoot",type:"uint256"},{internalType:"uint256",name:"rootsRoot",type:"uint256"}],internalType:"struct IdentityLib.Roots",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRootsTreeRoot",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSmtDepth",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint256",name:"_userId",type:"uint256"}],name:"getUserCredentialIds",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"_stateContractAddr",type:"address"},{internalType:"bytes2",name:"idType",type:"bytes2"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}],ow=class{static abi=HF;static createInterface(){return new dc(HF)}static connect(e,t){return new Ln(e,HF,t)}};var AI=class{_contract;_contractAddress;_chainId;_issuerDid;_merklizationOptions;constructor(e,t,r){if(!e.chainId)throw new Error("Chain ID is required");this._chainId=e.chainId,this._contractAddress=mn.getAddress(mn.hexlify(Xe.ethAddressFromId(ve.idFromDID(t)))),this._contract=ow.connect(this._contractAddress,new mn.JsonRpcProvider(e.url)),this._issuerDid=t,this._merklizationOptions=r?.merklizationOptions}async isInterfaceSupported(){let e=[{name:"Interface detection ERC-165",value:"0x01ffc9a7"},{name:"Interface non-merklized issuer",value:"0x58874949"},{name:"Interface get credential",value:"0x5d1ca631"}],r=(await Promise.all(e.map(async i=>await this._contract.supportsInterface(i.value)?null:i.name))).filter(i=>i!==null);if(r.length>0)throw new Error(`Unsupported interfaces: ${r.join(", ")}`)}async getCredential(e,t){let[r,i,o]=await this._contract.getCredential(e.bigInt(),t);return{credentialData:r,coreClaimBigInts:i,credentialSubjectFields:o}}async getUserCredentialsIds(e){return this._contract.getUserCredentialIds(e.bigInt())}async convertOnChainInfoToW3CCredential(e,t,r){let i=new Ir().unMarshalJson(JSON.stringify(t.map(u=>u.toString()))),o=await this.convertCredentialSubject(i,e.context,e._type,r),s={id:this.credentialId(e.id),credentialSchema:e.credentialSchema.id,type:e._type,credentialSubject:o,expiration:i.getExpirationDate()?.getTime(),displayMethod:this.convertDisplayMethod(e.displayMethod),context:e.context,revocationOpts:{id:this._contractAddress,nonce:Number(i.getRevocationNonce()),type:"Iden3OnchainSparseMerkleTreeProof2023"},issuanceDate:ra(Number(e.issuanceDate)).getTime()},a=await this.existenceProof(i),c=Er.fromCredentialRequest(this._issuerDid,s);return c.proof=[a],c}credentialId(e){return`urn:iden3:onchain:${this._chainId}:${this._contractAddress}:${e}`}async convertCredentialSubject(e,t,r,i){let o=JSON.stringify({"@context":t}),s={};for(let u of i){let l=await Hr.newTypeFromContext(o,`${r}.${u.key}`,this._merklizationOptions);switch(l){case"http://www.w3.org/2001/XMLSchema#boolean":{switch(u.rawValue.toString()){case"18586133768512220936620570745912940619677854269274689475585506675881198879027":s[u.key]=!0;break;case"19014214495641488759237505126948346942972912379615652741039992445865937985820":s[u.key]=!1;break}break}case("http://www.w3.org/2001/XMLSchema#nonNegativeInteger","http://www.w3.org/2001/XMLSchema#nonPositiveInteger","http://www.w3.org/2001/XMLSchema#negativeInteger","http://www.w3.org/2001/XMLSchema#positiveInteger"):{s[u.key]=u.value.toString();break}case"http://www.w3.org/2001/XMLSchema#integer":{s[u.key]=Number(u.value);break}case"http://www.w3.org/2001/XMLSchema#string":{this.validateSourceValue(l,u.value,u.rawValue),s[u.key]=u.rawValue;break}case"http://www.w3.org/2001/XMLSchema#dateTime":{let d=BigInt(u.rawValue),h=ra(Number(d)).toISOString();this.validateSourceValue(l,u.value,h),s[u.key]=h;break}case"http://www.w3.org/2001/XMLSchema#double":{let d=Number(u.rawValue);this.validateSourceValue(l,u.value,d),s[u.key]=d;break}default:throw new Error(`Unsupported data type ${l}`)}}s.type=r;let a=e.getId(),c=ve.parseFromId(a);return s.id=c.string(),s}async existenceProof(e){let[t,r]=await this._contract.getClaimProofWithStateInfo(e.hIndex());if(!t.existence)throw new Error("Claim does not exist");let i=be.fromBigInt(r.state),o=be.fromBigInt(r.claimsRoot),s=be.fromBigInt(r.revocationsRoot),a=be.fromBigInt(r.rootsRoot),c=new kt({siblings:t.siblings.map(u=>be.fromBigInt(u)),existence:t.existence,nodeAux:t.auxExistence?{key:be.fromBigInt(t.auxIndex),value:be.fromBigInt(t.auxValue)}:void 0});return new mc({issuerData:{id:this._issuerDid,state:{value:i,claimsTreeRoot:o,revocationTreeRoot:s,rootOfRoots:a}},mtp:c,coreClaim:e})}async validateSourceValue(e,t,r){if(await Bu.hashValue(e,r)!==t)throw new Error(`Invalid source value for ${e} type`)}convertDisplayMethod(e){if(!(!e.id||!e._type))switch(e._type){case"Iden3BasicDisplayMethodV1":return{id:e.id,type:"Iden3BasicDisplayMethodV1"};default:throw new Error(`Unsupported display method type ${e._type}`)}}};var KF=class{_ethConnectionConfig;_onchainIssuerOptions;constructor(e,t){this._ethConnectionConfig=e,this._onchainIssuerOptions=t}async getCredential(e,t,r){let{contract:i,connection:o}=this.getContractConnection(e),s=await i.getCredentialAdapterVersion();switch(s){case"0.0.1":{let a=new AI(o,e,{merklizationOptions:this._onchainIssuerOptions?.merklizationOptions});await a.isInterfaceSupported();let{credentialData:c,coreClaimBigInts:u,credentialSubjectFields:l}=await a.getCredential(ve.idFromDID(t),r);return await a.convertOnChainInfoToW3CCredential(c,u,l)}default:throw new Error(`Unsupported adapter version ${s}`)}}async getUserCredentialIds(e,t){let{contract:r,connection:i}=this.getContractConnection(e),o=await r.getCredentialAdapterVersion();switch(o){case"0.0.1":{let s=new AI(i,e,{merklizationOptions:this._onchainIssuerOptions?.merklizationOptions});return await s.isInterfaceSupported(),await s.getUserCredentialsIds(ve.idFromDID(t))}default:throw new Error(`Unsupported adapter version ${o}`)}}getContractConnection(e){let t=ve.idFromDID(e),r=lw(e),i=mn.getAddress(mn.hexlify(Xe.ethAddressFromId(t))),o=this._ethConnectionConfig.find(a=>a.chainId===r);if(!o)throw new Error(`No connection found for chain ID ${r}`);if(!o.url)throw new Error(`No URL found for chain ID ${r}`);return{contract:new Ln(i,GF,new mn.JsonRpcProvider(o.url)),connection:o}}};var JF=class{constructor(e){this.resolverUrl=e}async getLatestStateById(e){return this.getStateInfo(e)}async getStateInfoByIdAndState(e,t){return this.getStateInfo(e,t)}async getGISTProof(e){let{didDocument:t}=await yp(ve.parseFromId(Xe.fromBigInt(e)),this.resolverUrl),{global:r}=this.getIden3StateInfo2023(t);if(!r)throw new Error("GIST root not found");let{proof:i}=r;if(!i)throw new Error("GIST proof not found");return{root:r.root,existence:i.existence,siblings:i.siblings?.map(o=>BigInt(o)),index:BigInt(0),value:BigInt(0),auxExistence:!!i.node_aux,auxIndex:i.node_aux?BigInt(i.node_aux.key):BigInt(0),auxValue:i.node_aux?BigInt(i.node_aux.value):BigInt(0)}}async getGISTRootInfo(e,t){let{didDocument:r}=await yp(ve.parseFromId(Xe.fromBigInt(t)),this.resolverUrl,{gist:be.fromBigInt(e)}),{global:i}=this.getIden3StateInfo2023(r);if(!i)throw new Error("GIST root not found");return i}getRpcProvider(){return new jt}publishState(){throw new Error("publishState method not implemented.")}publishStateGeneric(){throw new Error("publishStateGeneric method not implemented.")}async getStateInfo(e,t){let r=t?{state:be.fromBigInt(t)}:void 0,{didDocument:i}=await yp(ve.parseFromId(Xe.fromBigInt(e)),this.resolverUrl,r),{info:o,published:s}=this.getIden3StateInfo2023(i);if(!o&&!s)throw new Error(Ge.ERRORS.STATE_DOES_NOT_EXIST);if(!o)throw new Error("State info not found");return o.id=e,o.state=r?.state?.bigInt(),{...o}}getIden3StateInfo2023(e){let t=e.verificationMethod?.find(r=>r.type==="Iden3StateInfo2023");if(!t)throw new Error("Iden3StateInfo2023 verification method not found");return t}};var rne=[{inputs:[],name:"ECDSAInvalidSignature",type:"error"},{inputs:[{internalType:"uint256",name:"length",type:"uint256"}],name:"ECDSAInvalidSignatureLength",type:"error"},{inputs:[{internalType:"bytes32",name:"s",type:"bytes32"}],name:"ECDSAInvalidSignatureS",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{inputs:[{internalType:"uint256",name:"deadline",type:"uint256"}],name:"ERC2612ExpiredSignature",type:"error"},{inputs:[{internalType:"address",name:"signer",type:"address"},{internalType:"address",name:"owner",type:"address"}],name:"ERC2612InvalidSigner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"},{internalType:"uint256",name:"currentNonce",type:"uint256"}],name:"InvalidAccountNonce",type:"error"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var ine=[{inputs:[{internalType:"uint256",name:"initialSupply",type:"uint256"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];async function SDe(n,e,t,r,i,o){let s=new Ln(e,rne,n),a=await s.nonces(await n.getAddress()),[c,u]=await Promise.all([s.name(),s.version?.().catch(()=>"1")??Promise.resolve("1")]),l={name:c,version:u,chainId:o,verifyingContract:e},d={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},h={owner:await n.getAddress(),spender:t,value:r,nonce:a,deadline:i};return n.signTypedData(l,d,h)}async function CDe(n,e){return new Ln(n,ine,e).decimals()}var lne=(t=>(t.NotDefinedQueryKey="not defined query key",t.NotDefinedComparator="not defined comparator",t))(lne||{}),dne=(o=>(o[o.BigInt=0]="BigInt",o[o.Boolean=1]="Boolean",o[o.Double=2]="Double",o[o.DateTime=3]="DateTime",o[o.String=4]="String",o))(dne||{}),qF=[!0,1,"true"],VF=[!1,0,"false"],one=(n,e)=>Array.isArray(n)&&Array.isArray(e)?n.length===e.length&&n.every((t,r)=>t===e[r]):!Array.isArray(n)&&Array.isArray(e)?e.includes(n):Array.isArray(n)&&!Array.isArray(e)?n.includes(e):(n=n,e=e,qF.includes(n)&&qF.includes(e)||VF.includes(n)&&VF.includes(e)?!0:n===e),sne=(n,e)=>hne(n,e,(r,i)=>{switch(pne(r.toString())){case 0:case 1:return BigInt(r)>BigInt(i);case 3:return Date.parse(r.toString())>Date.parse(i.toString());case 2:case 4:default:return r>i}}),ane=(n,e)=>hne(n,e,(r,i)=>{switch(pne(r.toString())){case 0:case 1:return BigInt(r)>=BigInt(i);case 3:return Date.parse(r.toString())>=Date.parse(i.toString());case 2:case 4:default:return r>=i}}),LDe=(n,e)=>!!(qF.includes(e)&&typeof n<"u"||VF.includes(e)&&(n===void 0||Array.isArray(n)&&!n.length)),cne=(n,e)=>Array.isArray(n)&&Array.isArray(e)?n.every(t=>e.includes(t)):!Array.isArray(n)&&Array.isArray(e)?e.includes(n):Array.isArray(n)&&!Array.isArray(e)?n.includes(e):!1,une=(n,e)=>{if(!Array.isArray(e)||e.length!==2)throw new Error("$between/$nonbetween operator value should be 2 elements array");let[t,r]=e.map(BigInt),i=o=>o>=t&&o<=r;return Array.isArray(n)?n.map(BigInt).every(i):i(BigInt(n))},Qu={$noop:()=>!0,$sd:()=>!0,$exists:(n,e)=>LDe(n,e),$eq:(n,e)=>one(n,e),$in:(n,e)=>cne(n,e),$nin:(n,e)=>!cne(n,e),$gt:(n,e)=>sne(n,e),$lt:(n,e)=>!ane(n,e),$ne:(n,e)=>!one(n,e),$gte:(n,e)=>ane(n,e),$lte:(n,e)=>!sne(n,e),$between:(n,e)=>une(n,e),$nonbetween:(n,e)=>!une(n,e)},fne=(n,e,t=null)=>{let r=e.split("."),i=n;for(let o of r){if(i==null)return t;i=i[o]}return i},Jc=class{constructor(e,t,r,i=!1){this.path=e;this.operatorFunc=t;this.value=r;this.isReverseParams=i}execute(e){if(!this.operatorFunc)throw new Error("not defined comparator");let t=fne(e,this.path);return t==null&&this.operatorFunc!==Qu.$exists?!1:this.isReverseParams?this.operatorFunc(this.value,t):this.operatorFunc(t,this.value)}},QF=n=>Object.keys(n).reduce((e,t)=>{let r=n[t];switch(t){case"claimId":return e.concat(new Jc("id",Qu.$eq,r));case"allowedIssuers":return(r||["*"]).includes("*")?e:e.concat(new Jc("issuer",Qu.$in,r));case"type":return e.concat(new Jc("type",Qu.$in,r,!0));case"context":return e.concat(new Jc("@context",Qu.$in,r,!0));case"credentialSubjectId":return e.concat(new Jc("credentialSubject.id",Qu.$eq,r));case"schema":return e.concat(new Jc("credentialSchema.id",Qu.$eq,r));case"credentialSubject":{let i=Object.keys(r).reduce((o,s)=>{let a=r[s];if(typeof a=="object"&&Object.keys(a).length===0)return o.concat([new Jc(`credentialSubject.${s}`,Qu.$noop,null)]);let c=Object.keys(a).map(u=>{let l=a[u],d=`credentialSubject.${s}`;return new Jc(d,Qu[u],l)});return o.concat(c)},[]);return e.concat(i)}case"proofType":case"groupId":case"skipClaimRevocationCheck":return e;default:throw new Error(`${t} : not defined query key`)}},[]),hne=(n,e,t)=>Array.isArray(n)&&Array.isArray(e)?n.every((r,i)=>t(r,e[i])):!Array.isArray(n)&&Array.isArray(e)?e.every(r=>t(n,r)):Array.isArray(n)&&!Array.isArray(e)?n.every(r=>t(r,e)):t(n,e),RDe=/^[+-]?\d+$/,DDe=/^(-?)(0|([1-9][0-9]*))(\\.[0-9]+)?$/,TDe=/^([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/,BDe=/^(true)|(false)$/,PDe=/^\d{4}-\d{2}-\d{2}$/,pne=n=>RDe.test(n)?0:DDe.test(n)?2:TDe.test(n)||PDe.test(n)?3:BDe.test(n)?1:4;var zF=class{constructor(e){this._localStorageKey=e;localStorage.getItem(this._localStorageKey)||localStorage.setItem(e,JSON.stringify([]))}async save(e,t,r="id"){if(localStorage){let i=localStorage.getItem(this._localStorageKey),o=[];i&&(o=JSON.parse(i));let s=o.findIndex(a=>a[r]===e);s===-1?o.push(t):o[s]=t,localStorage.setItem(this._localStorageKey,JSON.stringify(o))}}async get(e,t="id"){let r=localStorage.getItem(this._localStorageKey),i=[];return r&&(i=JSON.parse(r)),i.find(o=>o[t]===e)}async load(){let e=localStorage.getItem(this._localStorageKey);return e&&JSON.parse(e)}async delete(e,t="id"){let r=localStorage.getItem(this._localStorageKey),i=[];r&&(i=JSON.parse(r));let o=i.filter(s=>s[t]!==e);if(i.length===o.length)throw new Error(`item not found to delete: ${e}`);localStorage.setItem(this._localStorageKey,JSON.stringify(o))}};var YF=class n{constructor(e){this._mtDepth=e}static storageKeyMeta="merkle-tree-meta";async createIdentityMerkleTrees(e){e||(e=`${Ut()}`);let t=localStorage.getItem(n.storageKeyMeta);if(t){let i=JSON.parse(t);if(i.find(c=>c.treeId===`${e}+${c.type}`))throw new Error(`Present merkle tree meta information in the store for current identifier ${e}`);let s=i.filter(c=>c.identifier===e);if(s.length>0)return s;let a=ky(e);return localStorage.setItem(n.storageKeyMeta,JSON.stringify([...i,...a])),[...i,...a]}let r=ky(e);return localStorage.setItem(n.storageKeyMeta,JSON.stringify(r)),r}async getIdentityMerkleTreesInfo(e){let t=localStorage.getItem(n.storageKeyMeta);if(t)return JSON.parse(t).filter(i=>i.identifier===e);throw new Error(`Merkle tree meta not found for identifier ${e}`)}async getMerkleTreeByIdentifierAndType(e,t){let r=this.getMeta(e,t);return new sa(new ww(Xc(r.treeId)),!0,this._mtDepth)}getMeta(e,t){let r=localStorage.getItem(n.storageKeyMeta),i=new Error(`Merkle tree not found for identifier ${e} and type ${t}`);if(!r)throw i;let s=JSON.parse(r).filter(a=>a.identifier===e&&a.type===t)[0];if(!s)throw i;return s}async addToMerkleTree(e,t,r,i){let o=this.getMeta(e,t);await new sa(new ww(Xc(o.treeId)),!0,this._mtDepth).add(r,i)}async bindMerkleTreeToNewIdentifier(e,t){let r=localStorage.getItem(n.storageKeyMeta);if(!r)throw new Error(`Merkle tree meta not found for identifier ${e}`);let i=JSON.parse(r),o=i.filter(a=>a.identifier===e).map(a=>({...a,identifier:t}));if(o.length===0)throw new Error(`Merkle tree meta not found for identifier ${e}`);let s=[...i.filter(a=>a.identifier!==e),...o];localStorage.setItem(n.storageKeyMeta,JSON.stringify(s))}};var jF=class{constructor(e){this._storageKey=e;this._store=Od(`${e}-db`,e)}_store;async save(e,t,r="id"){return Fd(e,t,this._store)}async get(e,t="id"){return Wc(e,this._store)}async load(){return WN(this._store)}async delete(e,t="id"){return QI(e,this._store)}};var WF=class n{constructor(e){this._mtDepth=e;this._merkleTreeMetaStore=Od(`${n.storageKeyMeta}-db`,n.storageKeyMeta),this._bindingStore=Od(`${n.storageBindingKeyMeta}-db`,n.storageBindingKeyMeta)}static storageKeyMeta="merkle-tree-meta";static storageBindingKeyMeta="binding-did";_merkleTreeMetaStore;_bindingStore;async createIdentityMerkleTrees(e){if(e||(e=`${Ut()}`),await Wc(e,this._bindingStore))throw new Error(`Present merkle tree meta information in the store for current identifier ${e}`);let r=ky(e);return await Fd(e,r,this._merkleTreeMetaStore),r}async getIdentityMerkleTreesInfo(e){let t=await Wc(e,this._merkleTreeMetaStore);if(t)return t;throw new Error(`Merkle tree meta not found for identifier ${e}`)}async getMerkleTreeByIdentifierAndType(e,t){let r=await Wc(e,this._merkleTreeMetaStore),i=new Error(`Merkle tree not found for identifier ${e} and type ${t}`);if(!r)throw i;let o=r.find(s=>s.identifier===e&&s.type===t);if(!o)throw i;return new sa(new bw(Xc(o.treeId)),!0,this._mtDepth)}async addToMerkleTree(e,t,r,i){let o=await Wc(e,this._merkleTreeMetaStore);if(!o)throw new Error(`Merkle tree meta not found for identifier ${e}`);let s=o.find(c=>c.identifier===e&&c.type===t);if(!s)throw new Error(`Merkle tree not found for identifier ${e} and type ${t}`);await new sa(new bw(Xc(s.treeId)),!0,this._mtDepth).add(r,i)}async bindMerkleTreeToNewIdentifier(e,t){let r=await Wc(e,this._merkleTreeMetaStore);if(!r||!r?.length)throw new Error(`Merkle tree meta not found for identifier ${e}`);let i=r.map(o=>({...o,identifier:t}));await QI(e,this._merkleTreeMetaStore),await Fd(t,i,this._merkleTreeMetaStore),await Fd(e,t,this._bindingStore)}};var ZF=class{constructor(e){this._dataSource=e}static storageKey="circuits";async loadCircuitData(e){let t=await this._dataSource.get(e.toString(),"circuitId");if(!t)throw new Error(`item not found: ${e}`);return t}async saveCircuitData(e,t){await this._dataSource.save(e.toString(),t,"circuitId")}};var XF=class{constructor(e){this._dataSource=e}static storageKey="credentials";async listCredentials(){return(await this._dataSource.load()).filter(t=>t!==void 0).map(t=>t&&Er.fromJSON(t))}async saveCredential(e){return this._dataSource.save(e.id,e.toJSON())}async saveAllCredentials(e){for(let t of e)await this.saveCredential(t)}async removeCredential(e){return this._dataSource.delete(e)}async findCredentialById(e){let t=await this._dataSource.get(e);return t&&Er.fromJSON(t)}async findCredentialsByQuery(e){let t=QF(e);return(await this._dataSource.load()).filter(o=>t.every(s=>s.execute(o))).filter(o=>o!==void 0).map(o=>Er.fromJSON(o))}};var _F=class{constructor(e,t){this._identityDataSource=e;this._profileDataSource=t}static identitiesStorageKey="identities";static profilesStorageKey="profiles";async saveProfile(e){let r=(await this._profileDataSource.load()).filter(o=>o.genesisIdentifier===e.genesisIdentifier),i=r.length?[...r,e]:[e];for(let o=0;o<i.length;o++){let s=i[o];await this._profileDataSource.save(s.id,s)}}async getProfileByVerifier(e){return this._profileDataSource.get(e,"verifier")}async getProfilesByVerifier(e,t){return(await this._profileDataSource.load()).filter(r=>r.verifier===e&&(!t||t.every(i=>r.tags?.includes(i))))}async getProfileById(e){return this._profileDataSource.get(e)}async getProfilesByGenesisIdentifier(e){return(await this._profileDataSource.load()).filter(t=>t.genesisIdentifier===e)}async getAllIdentities(){return this._identityDataSource.load()}async saveIdentity(e){return this._identityDataSource.save(e.did,e,"did")}async getIdentity(e){return this._identityDataSource.get(e,"did")}};var $F=class{constructor(e){this.opts=e;this._verificationKeyPath=this.opts.verificationFileName??this._verificationKeyPath,this._provingKeyPath=this.opts.provingFileName??this._provingKeyPath,this._wasmFilePath=this.opts.wasmFileName??this._wasmFilePath}_verificationKeyPath="verification_key.json";_provingKeyPath="circuit_final.zkey";_wasmFilePath="circuit.wasm";_fs=null;_browserNotSupportedError=new Error("File system operations are not supported in browser environment");async getFs(){return this._fs?this._fs:(this._fs={existsSync:()=>{throw this._browserNotSupportedError},readFileSync:()=>{throw this._browserNotSupportedError},writeFileSync:()=>{throw this._browserNotSupportedError},mkdirSync:()=>{throw this._browserNotSupportedError}},this._fs)}async loadCircuitData(e,t){let r=t?.mode??"full",i={wasm:r==="proving"||r==="full"?this.loadCircuitFile(e,this._wasmFilePath):Promise.resolve(null),provingKey:r==="proving"||r==="full"?this.loadCircuitFile(e,this._provingKeyPath):Promise.resolve(null),verificationKey:r==="verification"||r==="full"?this.loadCircuitFile(e,this._verificationKeyPath):Promise.resolve(null)},[o,s,a]=await Promise.all([i.wasm,i.provingKey,i.verificationKey]);return{circuitId:e,wasm:o,provingKey:s,verificationKey:a}}async loadCircuitFile(e,t){let r=`${this.opts.dirname}/${e}/${t}`,i=await this.getFs();if(i.existsSync(r)){let o=i.readFileSync(r);return new Uint8Array(o)}return null}async writeCircuitFile(e,t,r,i){let o=`${this.opts.dirname}/${e}`,s=`${o}/${t}`,a=await this.getFs();a.mkdirSync(o,{recursive:!0}),a.writeFileSync(s,r,i)}async saveCircuitData(e,t){t.verificationKey&&await this.writeCircuitFile(e,this._verificationKeyPath,t.verificationKey,"utf-8"),t.provingKey&&await this.writeCircuitFile(e,this._provingKeyPath,t.provingKey),t.wasm&&await this.writeCircuitFile(e,this._wasmFilePath,t.wasm)}};var zu=n=>{if(!n){let e=On.hash(new Array(3).fill(0n));return{proof:new kt,treeState:{state:be.fromBigInt(e),claimsRoot:Ne,revocationRoot:Ne,rootOfRoots:Ne}}}return{proof:n.mtp,treeState:$5(n.issuer.state,n.issuer.claimsTreeRoot,n.issuer.revocationTreeRoot,n.issuer.rootOfRoots)}},sw=n=>{let e=!1,t;n.existence?e=!0:n.auxExistence&&(t={key:be.fromBigInt(n.auxIndex),value:be.fromBigInt(n.auxValue)});let r=n.siblings.map(s=>be.fromBigInt(s)),i=new kt({siblings:r,nodeAux:t,existence:e});return{root:be.fromBigInt(n.root),proof:i}},B8=n=>{if(!n)return[{operator:dn.$noop,fieldName:""}];let e=[],t=Object.entries(n);if(!t.length)throw new Error("query must have at least 1 predicate");for(let[r,i]of t){let o=Object.entries(i);if(o.length===0){e.push({operator:dn.$sd,fieldName:r});continue}for(let[a,c]of o){if(!dn[a])throw new Error("operator is not supported by lib");let u=dn[a];e.push({operator:u,fieldName:r,operatorValue:c})}}return e},P8=async(n,e,t,r)=>{let i={...n,slotIndex:0,merklizedSchema:!1,datatype:"",claimPathKey:BigInt(0),values:[],path:new Hr};if(!n.fieldName&&n.operator!==0)throw new Error("query must have a field name if operator is not $noop");if(n.fieldName&&(i.datatype=await Hr.newTypeFromContext(e,`${t}.${n.fieldName}`,r)),await Q2(JSON.parse(e),r,t)||(i.merklizedSchema=!0),!i.merklizedSchema)i.slotIndex=await V2(n.fieldName,t,ke.encode(e));else try{let s=await I6(e,t,n.fieldName,r);i.claimPathKey=await s.mtEntry(),i.path=s}catch(s){throw new Error(`field does not exist in the schema ${s.message}`)}if(n.operatorValue!==void 0){if(!tM(i.datatype,n.operator))throw new Error(`operator ${n.operator} is not supported for datatype ${i.datatype}`);if((n.operator===0||n.operator===16)&&n.operatorValue)throw new Error(`operator value should be undefined for ${n.operator} operator`);let s;switch(n.operator){case 0:case 16:s=[];break;case 11:s=kDe(n.operatorValue);break;default:s=await k8(n.operatorValue,i.datatype)}i.values=s}return i},xI=async(n,e,t,r)=>{let i=B8(t);return Promise.all(i.map(o=>P8(o,e,n,r)))},k8=async(n,e)=>{let t=[];if(Array.isArray(n))for(let r=0;r<n.length;r++)t[r]=await Bu.hashValue(e,n[r]);else t[0]=await Bu.hashValue(e,n);return t},kDe=n=>{if(typeof n=="boolean")return[BigInt(n)];throw new Error("exists operator value must be true or false")},M8=n=>["authV2","authV3","authV3-8-32"].includes(n);async function nN(n,e){e=e||{};let t;try{t=await WebAssembly.compile(n)}catch(l){throw new Error(l)}let r="",i="",o=await WebAssembly.instantiate(t,{runtime:{exceptionHandler:function(l){let d;throw l==1?d=`Signal not found.
|
|
424
424
|
`:l==2?d=`Too many signals set.
|
|
425
425
|
`:l==3?d=`Signal already set.
|
|
426
426
|
`:l==4?d=`Assert Failed.
|