UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 47.8 kB
var t=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;t.register("g9MJ9",(function(e,r){var n,o;n=e.exports,o=function(){return vr},Object.defineProperty(n,"joinRoom",{get:o,set:undefined,enumerable:!0,configurable:!0});var i,s,a,c,l,f,u,d,h,p,g,y,m,w,b,v,E=t("dM3DM"),B=t("aQXMn");function A(t){if(!Number.isSafeInteger(t)||t<0)throw Error("positive integer expected, got "+t)}function x(t,...e){if(!((r=t)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw Error("Uint8Array expected");var r;if(e.length>0&&!e.includes(t.length))throw Error("Uint8Array expected of length "+e+", got length="+t.length)}function S(t,e=!0){if(t.destroyed)throw Error("Hash instance has been destroyed");if(e&&t.finished)throw Error("Hash#digest() has already been called")}const I="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function k(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function T(t,e){return t<<32-e|t>>>e}function P(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),x(t),t}class O{clone(){return this._cloneInto()}}function L(t=32){if(I&&"function"==typeof I.getRandomValues)return I.getRandomValues(new Uint8Array(t));if(I&&"function"==typeof I.randomBytes)return I.randomBytes(t);throw Error("crypto.getRandomValues must be defined")}function R(t,e,r){return t&e^t&r^e&r}class U extends O{update(t){S(this);const{view:e,buffer:r,blockLen:n}=this,o=(t=P(t)).length;for(let i=0;i<o;){const s=Math.min(n-this.pos,o-i);if(s!==n)r.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(e,0),this.pos=0);else{const e=k(t);for(;n<=o-i;i+=n)this.process(e,i)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){S(this),function(t,e){x(t);const r=e.outputLen;if(t.length<r)throw Error("digestInto() expects output buffer of length at least "+r)}(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:n,isLE:o}=this;let{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>n-i&&(this.process(r,0),i=0);for(let t=i;t<n;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,l=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+l,a,n)}(r,n-8,BigInt(8*this.length),o),this.process(r,0);const s=k(t),a=this.outputLen;if(a%4)throw Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,l=this.get();if(c>l.length)throw Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)s.setUint32(4*t,l[t],o)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return t.length=n,t.pos=s,t.finished=o,t.destroyed=i,n%e&&t.buffer.set(r),t}constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=k(this.buffer)}}const N=new Uint32Array([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]),q=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),H=new Uint32Array(64);class C extends U{get(){const{A:t,B:e,C:r,D:n,E:o,F:i,G:s,H:a}=this;return[t,e,r,n,o,i,s,a]}set(t,e,r,n,o,i,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)H[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=H[t-15],r=H[t-2],n=T(e,7)^T(e,18)^e>>>3,o=T(r,17)^T(r,19)^r>>>10;H[t]=o+H[t-7]+n+H[t-16]|0}let{A:r,B:n,C:o,D:i,E:s,F:a,G:c,H:l}=this;for(let t=0;t<64;t++){const e=l+(T(s,6)^T(s,11)^T(s,25))+((f=s)&a^~f&c)+N[t]+H[t]|0,u=(T(r,2)^T(r,13)^T(r,22))+R(r,n,o)|0;l=c,c=a,a=s,s=i+e|0,i=o,o=n,n=r,r=e+u|0}var f;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(r,n,o,i,s,a,c,l)}roundClean(){H.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}constructor(){super(64,32,8,!1),this.A=0|q[0],this.B=0|q[1],this.C=0|q[2],this.D=0|q[3],this.E=0|q[4],this.F=0|q[5],this.G=0|q[6],this.H=0|q[7]}}const D=function(t){const e=e=>t().update(P(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}((()=>new C));class z extends O{update(t){return S(this),this.iHash.update(t),this}digestInto(t){S(this),x(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:r,finished:n,destroyed:o,blockLen:i,outputLen:s}=this;return t.finished=n,t.destroyed=o,t.blockLen=i,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}constructor(t,e){super(),this.finished=!1,this.destroyed=!1,function(t){if("function"!=typeof t||"function"!=typeof t.create)throw Error("Hash should be wrapped by utils.wrapConstructor");A(t.outputLen),A(t.blockLen)}(t);const r=P(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),o.fill(0)}}const F=(t,e,r)=>new z(t,e).update(r).digest();F.create=(t,e)=>new z(t,e);const j=BigInt(0),V=BigInt(1),Z=BigInt(2);function K(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function _(t){if(!K(t))throw Error("Uint8Array expected")}function M(t,e){if("boolean"!=typeof e)throw Error(t+" boolean expected, got "+e)}const G=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function $(t){_(t);let e="";for(let r=0;r<t.length;r++)e+=G[t[r]];return e}function Y(t){const e=t.toString(16);return 1&e.length?"0"+e:e}function W(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);return""===t?j:BigInt("0x"+t)}const J=48,Q=57,X=65,tt=70,et=97,rt=102;function nt(t){return t>=J&&t<=Q?t-J:t>=X&&t<=tt?t-(X-10):t>=et&&t<=rt?t-(et-10):void 0}function ot(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let e=0,o=0;e<r;e++,o+=2){const r=nt(t.charCodeAt(o)),i=nt(t.charCodeAt(o+1));if(void 0===r||void 0===i){const e=t[o]+t[o+1];throw Error('hex string expected, got non-hex character "'+e+'" at index '+o)}n[e]=16*r+i}return n}function it(t){return W($(t))}function st(t){return _(t),W($(Uint8Array.from(t).reverse()))}function at(t,e){return ot(t.toString(16).padStart(2*e,"0"))}function ct(t,e){return at(t,e).reverse()}function lt(t,e,r){let n;if("string"==typeof e)try{n=ot(e)}catch(e){throw Error(t+" must be hex string or Uint8Array, cause: "+e)}else{if(!K(e))throw Error(t+" must be hex string or Uint8Array");n=Uint8Array.from(e)}const o=n.length;if("number"==typeof r&&o!==r)throw Error(t+" of length "+r+" expected, got "+o);return n}function ft(...t){let e=0;for(let r=0;r<t.length;r++){const n=t[r];_(n),e+=n.length}const r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const o=t[e];r.set(o,n),n+=o.length}return r}const ut=t=>"bigint"==typeof t&&j<=t;function dt(t,e,r){return ut(t)&&ut(e)&&ut(r)&&e<=t&&t<r}function ht(t,e,r,n){if(!dt(e,r,n))throw Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function pt(t){let e;for(e=0;t>j;t>>=V,e+=1);return e}const gt=t=>(Z<<BigInt(t-1))-V,yt=t=>new Uint8Array(t),mt=t=>Uint8Array.from(t);function wt(t,e,r){if("number"!=typeof t||t<2)throw Error("hashLen must be a number");if("number"!=typeof e||e<2)throw Error("qByteLen must be a number");if("function"!=typeof r)throw Error("hmacFn must be a function");let n=yt(t),o=yt(t),i=0;const s=()=>{n.fill(1),o.fill(0),i=0},a=(...t)=>r(o,n,...t),c=(t=yt())=>{o=a(mt([0]),t),n=a(),0!==t.length&&(o=a(mt([1]),t),n=a())},l=()=>{if(i++>=1e3)throw Error("drbg: tried 1000 values");let t=0;const r=[];for(;t<e;){n=a();const e=n.slice();r.push(e),t+=n.length}return ft(...r)};return(t,e)=>{let r;for(s(),c(t);!(r=e(l()));)c();return s(),r}}const bt={bigint:t=>"bigint"==typeof t,function:t=>"function"==typeof t,boolean:t=>"boolean"==typeof t,string:t=>"string"==typeof t,stringOrUint8Array:t=>"string"==typeof t||K(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>"function"==typeof t&&Number.isSafeInteger(t.outputLen)};function vt(t,e,r={}){const n=(e,r,n)=>{const o=bt[r];if("function"!=typeof o)throw Error("invalid validator function");const i=t[e];if(!(n&&void 0===i||o(i,t)))throw Error("param "+e+" is invalid. Expected "+r+", got "+i)};for(const[t,r]of Object.entries(e))n(t,r,!1);for(const[t,e]of Object.entries(r))n(t,e,!0);return t}function Et(t){const e=new WeakMap;return(r,...n)=>{const o=e.get(r);if(void 0!==o)return o;const i=t(r,...n);return e.set(r,i),i}}var Bt=Object.freeze({__proto__:null,aInRange:ht,abool:M,abytes:_,bitGet:(t,e)=>t>>BigInt(e)&V,bitLen:pt,bitMask:gt,bitSet:(t,e,r)=>t|(r?V:j)<<BigInt(e),bytesToHex:$,bytesToNumberBE:it,bytesToNumberLE:st,concatBytes:ft,createHmacDrbg:wt,ensureBytes:lt,equalBytes(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return 0===r},hexToBytes:ot,hexToNumber:W,inRange:dt,isBytes:K,memoized:Et,notImplemented(){throw Error("not implemented")},numberToBytesBE:at,numberToBytesLE:ct,numberToHexUnpadded:Y,numberToVarBytesBE:t=>ot(Y(t)),utf8ToBytes(t){if("string"!=typeof t)throw Error("string expected");return new Uint8Array((new TextEncoder).encode(t))},validateObject:vt});const At=BigInt(0),xt=BigInt(1),St=BigInt(2),It=BigInt(3),kt=BigInt(4),Tt=BigInt(5),Pt=BigInt(8);function Ot(t,e){const r=t%e;return r>=At?r:e+r}function Lt(t,e,r){if(e<At)throw Error("invalid exponent, negatives unsupported");if(r<=At)throw Error("invalid modulus");if(r===xt)return At;let n=xt;for(;e>At;)e&xt&&(n=n*t%r),t=t*t%r,e>>=xt;return n}function Rt(t,e,r){let n=t;for(;e-- >At;)n*=n,n%=r;return n}function Ut(t,e){if(t===At)throw Error("invert: expected non-zero number");if(e<=At)throw Error("invert: expected positive modulus, got "+e);let r=Ot(t,e),n=e,o=At,i=xt;for(;r!==At;){const t=n%r,e=o-i*(n/r);n=r,r=t,o=i,i=e}if(n!==xt)throw Error("invert: does not exist");return Ot(o,e)}const Nt=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qt(t,e){const r=void 0!==e?e:t.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function Ht(t,e,r=!1,n={}){if(t<=At)throw Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:o,nByteLength:i}=qt(t,e);if(i>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let s;const a=Object.freeze({ORDER:t,isLE:r,BITS:o,BYTES:i,MASK:gt(o),ZERO:At,ONE:xt,create:e=>Ot(e,t),isValid(e){if("bigint"!=typeof e)throw Error("invalid field element: expected bigint, got "+typeof e);return At<=e&&e<t},is0:t=>t===At,isOdd:t=>(t&xt)===xt,neg:e=>Ot(-e,t),eql:(t,e)=>t===e,sqr:e=>Ot(e*e,t),add:(e,r)=>Ot(e+r,t),sub:(e,r)=>Ot(e-r,t),mul:(e,r)=>Ot(e*r,t),pow:(t,e)=>function(t,e,r){if(r<At)throw Error("invalid exponent, negatives unsupported");if(r===At)return t.ONE;if(r===xt)return e;let n=t.ONE,o=e;for(;r>At;)r&xt&&(n=t.mul(n,o)),o=t.sqr(o),r>>=xt;return n}(a,t,e),div:(e,r)=>Ot(e*Ut(r,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>Ut(e,t),sqrt:n.sqrt||(e=>(s||(s=function(t){if(t%kt===It){const e=(t+xt)/kt;return function(t,r){const n=t.pow(r,e);if(!t.eql(t.sqr(n),r))throw Error("Cannot find square root");return n}}if(t%Pt===Tt){const e=(t-Tt)/Pt;return function(t,r){const n=t.mul(r,St),o=t.pow(n,e),i=t.mul(r,o),s=t.mul(t.mul(i,St),o),a=t.mul(i,t.sub(s,t.ONE));if(!t.eql(t.sqr(a),r))throw Error("Cannot find square root");return a}}return function(t){const e=(t-xt)/St;let r,n,o;for(r=t-xt,n=0;r%St===At;r/=St,n++);for(o=St;o<t&&Lt(o,e,t)!==t-xt;o++)if(o>1e3)throw Error("Cannot find square root: likely non-prime P");if(1===n){const e=(t+xt)/kt;return(t,r)=>{const n=t.pow(r,e);if(!t.eql(t.sqr(n),r))throw Error("Cannot find square root");return n}}const i=(r+xt)/St;return(t,s)=>{if(t.pow(s,e)===t.neg(t.ONE))throw Error("Cannot find square root");let a=n,c=t.pow(t.mul(t.ONE,o),r),l=t.pow(s,i),f=t.pow(s,r);for(;!t.eql(f,t.ONE);){if(t.eql(f,t.ZERO))return t.ZERO;let e=1;for(let r=t.sqr(f);e<a&&!t.eql(r,t.ONE);e++)r=t.sqr(r);const r=t.pow(c,xt<<BigInt(a-e-1));c=t.sqr(r),l=t.mul(l,r),f=t.mul(f,c),a=e}return l}}(t)}(t)),s(a,e))),invertBatch:t=>function(t,e){const r=Array(e.length),n=e.reduce(((e,n,o)=>t.is0(n)?e:(r[o]=e,t.mul(e,n))),t.ONE),o=t.inv(n);return e.reduceRight(((e,n,o)=>t.is0(n)?e:(r[o]=t.mul(e,r[o]),t.mul(e,n))),o),r}(a,t),cmov:(t,e,r)=>r?e:t,toBytes:t=>r?ct(t,i):at(t,i),fromBytes(t){if(t.length!==i)throw Error("Field.fromBytes: expected "+i+" bytes, got "+t.length);return r?st(t):it(t)}});return Object.freeze(a)}function Ct(t){if("bigint"!=typeof t)throw Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function Dt(t){const e=Ct(t);return e+Math.ceil(e/2)}const zt=BigInt(0),Ft=BigInt(1);function jt(t,e){const r=e.negate();return t?r:e}function Vt(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw Error("invalid window size, expected [1.."+e+"], got W="+t)}function Zt(t,e){return Vt(t,e),{windows:Math.ceil(e/t)+1,windowSize:2**(t-1)}}const Kt=new WeakMap,_t=new WeakMap;function Mt(t){return _t.get(t)||1}function Gt(t){return vt(t.Fp,Nt.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),vt(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze((0,B.default)((0,E.default)({},qt(t.n,t.nBitLength),t),{p:t.Fp.ORDER}))}function $t(t){void 0!==t.lowS&&M("lowS",t.lowS),void 0!==t.prehash&&M("prehash",t.prehash)}const{bytesToNumberBE:Yt,hexToBytes:Wt}=Bt,Jt={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode(t,e){const{Err:r}=Jt;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(1&e.length)throw new r("tlv.encode: unpadded data");const n=e.length/2,o=Y(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");const i=n>127?Y(o.length/2|128):"";return Y(t)+i+o+e},decode(t,e){const{Err:r}=Jt;let n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");const o=e[n++];let i=0;if(128&o){const t=127&o;if(!t)throw new r("tlv.decode(long): indefinite length not supported");if(t>4)throw new r("tlv.decode(long): byte length is too big");const s=e.subarray(n,n+t);if(s.length!==t)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const t of s)i=i<<8|t;if(n+=t,i<128)throw new r("tlv.decode(long): not minimal encoding")}else i=o;const s=e.subarray(n,n+i);if(s.length!==i)throw new r("tlv.decode: wrong value length");return{v:s,l:e.subarray(n+i)}}},_int:{encode(t){const{Err:e}=Jt;if(t<Qt)throw new e("integer: negative integers are not allowed");let r=Y(t);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){const{Err:e}=Jt;if(128&t[0])throw new e("invalid signature integer: negative");if(0===t[0]&&!(128&t[1]))throw new e("invalid signature integer: unnecessary leading zero");return Yt(t)}},toSig(t){const{Err:e,_int:r,_tlv:n}=Jt,o="string"==typeof t?Wt(t):t;_(o);const{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=n.decode(2,i),{v:l,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(t){const{_tlv:e,_int:r}=Jt,n=e.encode(2,r.encode(t.r))+e.encode(2,r.encode(t.s));return e.encode(48,n)}},Qt=BigInt(0),Xt=BigInt(1);BigInt(2);const te=BigInt(3);BigInt(4);const ee=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),re=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ne=BigInt(1),oe=BigInt(2),ie=(t,e)=>(t+e/oe)/e;function se(t){const e=ee,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=t*t*t%e,f=l*l*t%e,u=Rt(f,r,e)*f%e,d=Rt(u,r,e)*f%e,h=Rt(d,oe,e)*l%e,p=Rt(h,o,e)*h%e,g=Rt(p,i,e)*p%e,y=Rt(g,a,e)*g%e,m=Rt(y,c,e)*y%e,w=Rt(m,a,e)*g%e,b=Rt(w,r,e)*f%e,v=Rt(b,s,e)*p%e,E=Rt(v,n,e)*l%e,B=Rt(E,oe,e);if(!ae.eql(ae.sqr(B),t))throw Error("Cannot find square root");return B}const ae=Ht(ee,void 0,void 0,{sqrt:se}),ce=function(t,e){const r=e=>function(t){const e=function(t){const e=Gt(t);return vt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze((0,E.default)({lowS:!0},e))}(t),{Fp:r,n:n}=e,o=r.BYTES+1,i=2*r.BYTES+1;function s(t){return Ot(t,n)}function a(t){return Ut(t,n)}const{ProjectivePoint:c,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:u}=function(t){const e=function(t){const e=Gt(t);vt(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:o}=e;if(r){if(!n.eql(o,n.ZERO))throw Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if("object"!=typeof r||"bigint"!=typeof r.beta||"function"!=typeof r.splitScalar)throw Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze((0,E.default)({},e))}(t),{Fp:r}=e,n=Ht(e.n,e.nBitLength),o=e.toBytes||((t,e)=>{const n=e.toAffine();return ft(Uint8Array.from([4]),r.toBytes(n.x),r.toBytes(n.y))}),i=e.fromBytes||(t=>{const e=t.subarray(1);return{x:r.fromBytes(e.subarray(0,r.BYTES)),y:r.fromBytes(e.subarray(r.BYTES,2*r.BYTES))}});function s(t){const{a:n,b:o}=e,i=r.sqr(t),s=r.mul(i,t);return r.add(r.add(s,r.mul(t,n)),o)}if(!r.eql(r.sqr(e.Gy),s(e.Gx)))throw Error("bad generator point: equation left != right");function a(t){const{allowedPrivateKeyLengths:r,nByteLength:n,wrapPrivateKey:o,n:i}=e;if(r&&"bigint"!=typeof t){if(K(t)&&(t=$(t)),"string"!=typeof t||!r.includes(t.length))throw Error("invalid private key");t=t.padStart(2*n,"0")}let s;try{s="bigint"==typeof t?t:it(lt("private key",t,n))}catch(e){throw Error("invalid private key, expected hex or "+n+" bytes, got "+typeof t)}return o&&(s=Ot(s,i)),ht("private key",s,Xt,i),s}function c(t){if(!(t instanceof u))throw Error("ProjectivePoint expected")}const l=Et(((t,e)=>{const{px:n,py:o,pz:i}=t;if(r.eql(i,r.ONE))return{x:n,y:o};const s=t.is0();null==e&&(e=s?r.ONE:r.inv(i));const a=r.mul(n,e),c=r.mul(o,e),l=r.mul(i,e);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw Error("invZ was invalid");return{x:a,y:c}})),f=Et((t=>{if(t.is0()){if(e.allowInfinityPoint&&!r.is0(t.py))return;throw Error("bad point: ZERO")}const{x:n,y:o}=t.toAffine();if(!r.isValid(n)||!r.isValid(o))throw Error("bad point: x or y not FE");const i=r.sqr(o),a=s(n);if(!r.eql(i,a))throw Error("bad point: equation left != right");if(!t.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0}));class u{static fromAffine(t){const{x:e,y:n}=t||{};if(!t||!r.isValid(e)||!r.isValid(n))throw Error("invalid affine point");if(t instanceof u)throw Error("projective point not allowed");const o=t=>r.eql(t,r.ZERO);return o(e)&&o(n)?u.ZERO:new u(e,n,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=r.invertBatch(t.map((t=>t.pz)));return t.map(((t,r)=>t.toAffine(e[r]))).map(u.fromAffine)}static fromHex(t){const e=u.fromAffine(i(lt("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return u.BASE.multiply(a(t))}static msm(t,e){return function(t,e,r,n){if(function(t,e){if(!Array.isArray(t))throw Error("array expected");t.forEach(((t,r)=>{if(!(t instanceof e))throw Error("invalid point at index "+r)}))}(r,t),function(t,e){if(!Array.isArray(t))throw Error("array of scalars expected");t.forEach(((t,r)=>{if(!e.isValid(t))throw Error("invalid scalar at index "+r)}))}(n,e),r.length!==n.length)throw Error("arrays of points and scalars must have equal length");const o=t.ZERO,i=pt(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=(1<<s)-1,c=Array(a+1).fill(o);let l=o;for(let t=Math.floor((e.BITS-1)/s)*s;t>=0;t-=s){c.fill(o);for(let e=0;e<n.length;e++){const o=n[e],i=Number(o>>BigInt(t)&BigInt(a));c[i]=c[i].add(r[e])}let e=o;for(let t=c.length-1,r=o;t>0;t--)r=r.add(c[t]),e=e.add(r);if(l=l.add(e),0!==t)for(let t=0;t<s;t++)l=l.double()}return l}(u,n,t,e)}_setWindowSize(t){h.setWindowSize(this,t)}assertValidity(){f(this)}hasEvenY(){const{y:t}=this.toAffine();if(r.isOdd)return!r.isOdd(t);throw Error("Field doesn't support isOdd")}equals(t){c(t);const{px:e,py:n,pz:o}=this,{px:i,py:s,pz:a}=t,l=r.eql(r.mul(e,a),r.mul(i,o)),f=r.eql(r.mul(n,a),r.mul(s,o));return l&&f}negate(){return new u(this.px,r.neg(this.py),this.pz)}double(){const{a:t,b:n}=e,o=r.mul(n,te),{px:i,py:s,pz:a}=this;let c=r.ZERO,l=r.ZERO,f=r.ZERO,d=r.mul(i,i),h=r.mul(s,s),p=r.mul(a,a),g=r.mul(i,s);return g=r.add(g,g),f=r.mul(i,a),f=r.add(f,f),c=r.mul(t,f),l=r.mul(o,p),l=r.add(c,l),c=r.sub(h,l),l=r.add(h,l),l=r.mul(c,l),c=r.mul(g,c),f=r.mul(o,f),p=r.mul(t,p),g=r.sub(d,p),g=r.mul(t,g),g=r.add(g,f),f=r.add(d,d),d=r.add(f,d),d=r.add(d,p),d=r.mul(d,g),l=r.add(l,d),p=r.mul(s,a),p=r.add(p,p),d=r.mul(p,g),c=r.sub(c,d),f=r.mul(p,h),f=r.add(f,f),f=r.add(f,f),new u(c,l,f)}add(t){c(t);const{px:n,py:o,pz:i}=this,{px:s,py:a,pz:l}=t;let f=r.ZERO,d=r.ZERO,h=r.ZERO;const p=e.a,g=r.mul(e.b,te);let y=r.mul(n,s),m=r.mul(o,a),w=r.mul(i,l),b=r.add(n,o),v=r.add(s,a);b=r.mul(b,v),v=r.add(y,m),b=r.sub(b,v),v=r.add(n,i);let E=r.add(s,l);return v=r.mul(v,E),E=r.add(y,w),v=r.sub(v,E),E=r.add(o,i),f=r.add(a,l),E=r.mul(E,f),f=r.add(m,w),E=r.sub(E,f),h=r.mul(p,v),f=r.mul(g,w),h=r.add(f,h),f=r.sub(m,h),h=r.add(m,h),d=r.mul(f,h),m=r.add(y,y),m=r.add(m,y),w=r.mul(p,w),v=r.mul(g,v),m=r.add(m,w),w=r.sub(y,w),w=r.mul(p,w),v=r.add(v,w),y=r.mul(m,v),d=r.add(d,y),y=r.mul(E,v),f=r.mul(b,f),f=r.sub(f,y),y=r.mul(b,m),h=r.mul(E,h),h=r.add(h,y),new u(f,d,h)}subtract(t){return this.add(t.negate())}is0(){return this.equals(u.ZERO)}wNAF(t){return h.wNAFCached(this,t,u.normalizeZ)}multiplyUnsafe(t){const{endo:n,n:o}=e;ht("scalar",t,Qt,o);const i=u.ZERO;if(t===Qt)return i;if(this.is0()||t===Xt)return this;if(!n||h.hasPrecomputes(this))return h.wNAFCachedUnsafe(this,t,u.normalizeZ);let{k1neg:s,k1:a,k2neg:c,k2:l}=n.splitScalar(t),f=i,d=i,p=this;for(;a>Qt||l>Qt;)a&Xt&&(f=f.add(p)),l&Xt&&(d=d.add(p)),p=p.double(),a>>=Xt,l>>=Xt;return s&&(f=f.negate()),c&&(d=d.negate()),d=new u(r.mul(d.px,n.beta),d.py,d.pz),f.add(d)}multiply(t){const{endo:n,n:o}=e;let i,s;if(ht("scalar",t,Xt,o),n){const{k1neg:e,k1:o,k2neg:a,k2:c}=n.splitScalar(t);let{p:l,f:f}=this.wNAF(o),{p:d,f:p}=this.wNAF(c);l=h.constTimeNegate(e,l),d=h.constTimeNegate(a,d),d=new u(r.mul(d.px,n.beta),d.py,d.pz),i=l.add(d),s=f.add(p)}else{const{p:e,f:r}=this.wNAF(t);i=e,s=r}return u.normalizeZ([i,s])[0]}multiplyAndAddUnsafe(t,e,r){const n=u.BASE,o=(t,e)=>e!==Qt&&e!==Xt&&t.equals(n)?t.multiply(e):t.multiplyUnsafe(e),i=o(this,e).add(o(t,r));return i.is0()?void 0:i}toAffine(t){return l(this,t)}isTorsionFree(){const{h:t,isTorsionFree:r}=e;if(t===Xt)return!0;if(r)return r(u,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:r}=e;return t===Xt?this:r?r(u,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return M("isCompressed",t),this.assertValidity(),o(u,this,t)}toHex(t=!0){return M("isCompressed",t),$(this.toRawBytes(t))}constructor(t,e,n){if(this.px=t,this.py=e,this.pz=n,null==t||!r.isValid(t))throw Error("x required");if(null==e||!r.isValid(e))throw Error("y required");if(null==n||!r.isValid(n))throw Error("z required");Object.freeze(this)}}u.BASE=new u(e.Gx,e.Gy,r.ONE),u.ZERO=new u(r.ZERO,r.ONE,r.ZERO);const d=e.nBitLength,h=(p=u,g=e.endo?Math.ceil(d/2):d,{constTimeNegate:jt,hasPrecomputes:t=>1!==Mt(t),unsafeLadder(t,e,r=p.ZERO){let n=t;for(;e>zt;)e&Ft&&(r=r.add(n)),n=n.double(),e>>=Ft;return r},precomputeWindow(t,e){const{windows:r,windowSize:n}=Zt(e,g),o=[];let i=t,s=i;for(let t=0;t<r;t++){s=i,o.push(s);for(let t=1;t<n;t++)s=s.add(i),o.push(s);i=s.double()}return o},wNAF(t,e,r){const{windows:n,windowSize:o}=Zt(t,g);let i=p.ZERO,s=p.BASE;const a=BigInt(2**t-1),c=2**t,l=BigInt(t);for(let t=0;t<n;t++){const n=t*o;let f=Number(r&a);r>>=l,f>o&&(f-=c,r+=Ft);const u=n,d=n+Math.abs(f)-1,h=t%2!=0,p=f<0;0===f?s=s.add(jt(h,e[u])):i=i.add(jt(p,e[d]))}return{p:i,f:s}},wNAFUnsafe(t,e,r,n=p.ZERO){const{windows:o,windowSize:i}=Zt(t,g),s=BigInt(2**t-1),a=2**t,c=BigInt(t);for(let t=0;t<o;t++){const o=t*i;if(r===zt)break;let l=Number(r&s);if(r>>=c,l>i&&(l-=a,r+=Ft),0===l)continue;let f=e[o+Math.abs(l)-1];l<0&&(f=f.negate()),n=n.add(f)}return n},getPrecomputes(t,e,r){let n=Kt.get(e);return n||(n=this.precomputeWindow(e,t),1!==t&&Kt.set(e,r(n))),n},wNAFCached(t,e,r){const n=Mt(t);return this.wNAF(n,this.getPrecomputes(n,t,r),e)},wNAFCachedUnsafe(t,e,r,n){const o=Mt(t);return 1===o?this.unsafeLadder(t,e,n):this.wNAFUnsafe(o,this.getPrecomputes(o,t,r),e,n)},setWindowSize(t,e){Vt(e,g),_t.set(t,e),Kt.delete(t)}});var p,g;return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:t=>dt(t,Xt,e.n)}}((0,B.default)((0,E.default)({},e),{toBytes(t,e,n){const o=e.toAffine(),i=r.toBytes(o.x),s=ft;return M("isCompressed",n),n?s(Uint8Array.from([e.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,r.toBytes(o.y))},fromBytes(t){const e=t.length,n=t[0],s=t.subarray(1);if(e!==o||2!==n&&3!==n){if(e===i&&4===n)return{x:r.fromBytes(s.subarray(0,r.BYTES)),y:r.fromBytes(s.subarray(r.BYTES,2*r.BYTES))};throw Error("invalid Point, expected length of "+o+", or uncompressed "+i+", got "+e)}{const e=it(s);if(!dt(e,Xt,r.ORDER))throw Error("Point is not on curve");const o=f(e);let i;try{i=r.sqrt(o)}catch(t){const e=t instanceof Error?": "+t.message:"";throw Error("Point is not on curve"+e)}return!(1&~n)!=((i&Xt)===Xt)&&(i=r.neg(i)),{x:e,y:i}}}})),d=t=>$(at(t,e.nByteLength));function h(t){return t>n>>Xt}const p=(t,e,r)=>it(t.slice(e,r));class g{static fromCompact(t){const r=e.nByteLength;return t=lt("compactSignature",t,2*r),new g(p(t,0,r),p(t,r,2*r))}static fromDER(t){const{r:e,s:r}=Jt.toSig(lt("DER",t));return new g(e,r)}assertValidity(){ht("r",this.r,Xt,n),ht("s",this.s,Xt,n)}addRecoveryBit(t){return new g(this.r,this.s,t)}recoverPublicKey(t){const{r:n,s:o,recovery:i}=this,l=b(lt("msgHash",t));if(null==i||![0,1,2,3].includes(i))throw Error("recovery id invalid");const f=2===i||3===i?n+e.n:n;if(f>=r.ORDER)throw Error("recovery id 2 or 3 invalid");const u=1&i?"03":"02",h=c.fromHex(u+d(f)),p=a(f),g=s(-l*p),y=s(o*p),m=c.BASE.multiplyAndAddUnsafe(h,g,y);if(!m)throw Error("point at infinify");return m.assertValidity(),m}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return ot(this.toDERHex())}toDERHex(){return Jt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ot(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}constructor(t,e,r){this.r=t,this.s=e,this.recovery=r,this.assertValidity()}}const y={isValidPrivateKey(t){try{return l(t),!0}catch(t){return!1}},normPrivateKeyToScalar:l,randomPrivateKey(){const t=Dt(e.n);return function(t,e,r=!1){const n=t.length,o=Ct(e),i=Dt(e);if(n<16||n<i||n>1024)throw Error("expected "+i+"-1024 bytes of input, got "+n);const s=Ot(r?st(t):it(t),e-xt)+xt;return r?ct(s,o):at(s,o)}(e.randomBytes(t),e.n)},precompute:(t=8,e=c.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function m(t){const e=K(t),r="string"==typeof t,n=(e||r)&&t.length;return e?n===o||n===i:r?n===2*o||n===2*i:t instanceof c}const w=e.bits2int||(t=>{if(t.length>8192)throw Error("input is too large");const r=it(t),n=8*t.length-e.nBitLength;return n>0?r>>BigInt(n):r}),b=e.bits2int_modN||(t=>s(w(t))),v=gt(e.nBitLength);function A(t){return ht("num < 2^"+e.nBitLength,t,Qt,v),at(t,e.nByteLength)}function x(t,n,o=S){if(["recovered","canonical"].some((t=>t in o)))throw Error("sign() legacy options not supported");const{hash:i,randomBytes:f}=e;let{lowS:d,prehash:p,extraEntropy:y}=o;null==d&&(d=!0),t=lt("msgHash",t),$t(o),p&&(t=lt("prehashed msgHash",i(t)));const m=b(t),v=l(n),E=[A(v),A(m)];if(null!=y&&!1!==y){const t=!0===y?f(r.BYTES):y;E.push(lt("extraEntropy",t))}const B=ft(...E),x=m;return{seed:B,k2sig(t){const e=w(t);if(!u(e))return;const r=a(e),n=c.BASE.multiply(e).toAffine(),o=s(n.x);if(o===Qt)return;const i=s(r*s(x+o*v));if(i===Qt)return;let l=(n.x===o?0:2)|Number(n.y&Xt),f=i;return d&&h(i)&&(f=function(t){return h(t)?s(-t):t}(i),l^=1),new g(o,f,l)}}}const S={lowS:e.lowS,prehash:!1},I={lowS:e.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:e,getPublicKey:(t,e=!0)=>c.fromPrivateKey(t).toRawBytes(e),getSharedSecret(t,e,r=!0){if(m(t))throw Error("first arg must be private key");if(!m(e))throw Error("second arg must be public key");return c.fromHex(e).multiply(l(t)).toRawBytes(r)},sign(t,r,n=S){const{seed:o,k2sig:i}=x(t,r,n),s=e;return wt(s.hash.outputLen,s.nByteLength,s.hmac)(o,i)},verify(t,r,n,o=I){var i;const l=t;r=lt("msgHash",r),n=lt("publicKey",n);const{lowS:f,prehash:u,format:d}=o;if($t(o),"strict"in o)throw Error("options.strict was renamed to lowS");if(void 0!==d&&"compact"!==d&&"der"!==d)throw Error("format must be compact or der");const h="string"==typeof l||K(l),p=!h&&!d&&"object"==typeof l&&null!==l&&"bigint"==typeof l.r&&"bigint"==typeof l.s;if(!h&&!p)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");let y,m;try{if(p&&(y=new g(l.r,l.s)),h){try{"compact"!==d&&(y=g.fromDER(l))}catch(t){if(!(t instanceof Jt.Err))throw t}y||"der"===d||(y=g.fromCompact(l))}m=c.fromHex(n)}catch(t){return!1}if(!y)return!1;if(f&&y.hasHighS())return!1;u&&(r=e.hash(r));const{r:w,s:v}=y,E=b(r),B=a(v),A=s(E*B),x=s(w*B),S=null===(i=c.BASE.multiplyAndAddUnsafe(m,A,x))||void 0===i?void 0:i.toAffine();return!!S&&s(S.x)===w},ProjectivePoint:c,Signature:g,utils:y}}((0,E.default)({},t,function(t){return{hash:t,hmac:(e,...r)=>F(t,e,function(...t){let e=0;for(let r=0;r<t.length;r++){const n=t[r];x(n),e+=n.length}const r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const o=t[e];r.set(o,n),n+=o.length}return r}(...r)),randomBytes:L}}(e)));return(0,B.default)((0,E.default)({},r(e)),{create:r})}({a:BigInt(0),b:BigInt(7),Fp:ae,n:re,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const e=re,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ne*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=ie(i*t,e),c=ie(-n*t,e);let l=Ot(t-a*r-c*o,e),f=Ot(-a*n-c*i,e);const u=l>s,d=f>s;if(u&&(l=e-l),d&&(f=e-f),l>s||f>s)throw Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:l,k2neg:d,k2:f}}}},D),le=BigInt(0),fe={};function ue(t,...e){let r=fe[t];if(void 0===r){const e=D(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=ft(e,e),fe[t]=r}return D(ft(r,...e))}const de=t=>t.toRawBytes(!0).slice(1),he=t=>at(t,32),pe=t=>Ot(t,ee),ge=t=>Ot(t,re),ye=ce.ProjectivePoint;function me(t){let e=ce.utils.normPrivateKeyToScalar(t),r=ye.fromPrivateKey(e);return{scalar:r.hasEvenY()?e:ge(-e),bytes:de(r)}}function we(t){ht("x",t,ne,ee);const e=pe(t*t);let r=se(pe(e*t+BigInt(7)));r%oe!==le&&(r=pe(-r));const n=new ye(t,r,ne);return n.assertValidity(),n}const be=it;function ve(...t){return ge(be(ue("BIP0340/challenge",...t)))}function Ee(t,e,r){const n=lt("signature",t,64),o=lt("message",e),i=lt("publicKey",r,32);try{const t=we(be(i)),e=be(n.subarray(0,32));if(!dt(e,ne,ee))return!1;const r=be(n.subarray(32,64));if(!dt(r,ne,re))return!1;const l=ve(he(e),de(t),o),f=(s=t,a=r,c=ge(-l),ye.BASE.multiplyAndAddUnsafe(s,a,c));return!(!f||!f.hasEvenY()||f.toAffine().x!==e)}catch(t){return!1}var s,a,c}const Be={getPublicKey:function(t){return me(t).bytes},sign:function(t,e,r=L(32)){const n=lt("message",t),{bytes:o,scalar:i}=me(e),s=lt("auxRand",r,32),a=he(i^be(ue("BIP0340/aux",s))),c=ue("BIP0340/nonce",a,o,n),l=ge(be(c));if(l===le)throw Error("sign failed: k is zero");const{bytes:f,scalar:u}=me(l),d=ve(f,o,n),h=new Uint8Array(64);if(h.set(f,0),h.set(he(ge(u+d*i)),32),!Ee(h,n,o))throw Error("sign: Invalid signature produced");return h},verify:Ee,utils:{randomPrivateKey:ce.utils.randomPrivateKey,lift_x:we,pointToBytes:de,numberToBytesBE:at,bytesToNumberBE:it,taggedHash:ue,mod:Ot}},{floor:Ae,random:xe,sin:Se}=Math,Ie="Trystero",ke=(t,e)=>Array(t).fill().map(e),Te=t=>ke(t,(()=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Ae(62*xe())])).join(""),Pe=Te(20),Oe=Promise.all.bind(Promise),Le="undefined"!=typeof window,{entries:Re,fromEntries:Ue,keys:Ne}=Object,qe=()=>{},He=t=>Error(`${Ie}: ${t}`),Ce=new TextEncoder,De=new TextDecoder,ze=t=>Ce.encode(t),Fe=t=>De.decode(t),je=t=>t.reduce(((t,e)=>t+e.toString(16).padStart(2,"0")),""),Ve=(...t)=>t.join("@"),Ze=JSON.stringify,Ke=JSON.parse,_e=(t,e=Number.MAX_SAFE_INTEGER)=>t.split("").reduce(((t,e)=>t+e.charCodeAt(0)),0)%e,Me={},Ge="AES-GCM",$e={},Ye=async t=>$e[t]||($e[t]=Array.from(new Uint8Array(await crypto.subtle.digest("SHA-1",ze(t)))).map((t=>t.toString(36))).join("")),We=async(t,e)=>{const r=crypto.getRandomValues(new Uint8Array(16));var n;return r.join(",")+"$"+(n=await crypto.subtle.encrypt({name:Ge,iv:r},await t,ze(e)),btoa(String.fromCharCode.apply(null,new Uint8Array(n))))},Je=async(t,e)=>{const[r,n]=e.split("$");return Fe(await crypto.subtle.decrypt({name:Ge,iv:new Uint8Array(r.split(","))},await t,(t=>{const e=atob(t);return new Uint8Array(e.length).map(((t,r)=>e.charCodeAt(r))).buffer})(n)))},Qe="icegatheringstatechange",Xe=t=>t.replace(/a=ice-options:trickle\s\n/g,"");var tr=(t,{rtcConfig:e,rtcPolyfill:r,turnConfig:n})=>{const o=new(r||RTCPeerConnection)((0,E.default)({iceServers:er.concat(n||[])},e)),i={},s=t=>{t.binaryType="arraybuffer",t.bufferedAmountLowThreshold=65535,t.onmessage=t=>{var e;return null===(e=i.data)||void 0===e?void 0:e.call(i,t.data)},t.onopen=()=>{var t;return null===(t=i.connect)||void 0===t?void 0:t.call(i)},t.onclose=()=>{var t;return null===(t=i.close)||void 0===t?void 0:t.call(i)},t.onerror=t=>{var e;return null===(e=i.error)||void 0===e?void 0:e.call(i,t)}},a=async t=>{if(!t.localDescription)throw Error("No local description available");return await Promise.race([new Promise((e=>{const r=()=>{"complete"===t.iceGatheringState&&(t.removeEventListener(Qe,r),e())};t.addEventListener(Qe,r),r()})),new Promise((t=>setTimeout(t,5e3)))]),{type:t.localDescription.type,sdp:Xe(t.localDescription.sdp)}};let c=!1,l=null,f=!1;return t?(l=o.createDataChannel("data"),s(l)):o.ondatachannel=({channel:t})=>{l=t,s(t)},o.onnegotiationneeded=async()=>{try{var t;c=!0,await o.setLocalDescription();const e=await a(o);null===(t=i.signal)||void 0===t||t.call(i,{type:e.type,sdp:Xe(e.sdp)})}catch(t){var e;null===(e=i.error)||void 0===e||e.call(i,t)}finally{c=!1}},o.onconnectionstatechange=()=>{var t;["disconnected","failed","closed"].includes(o.connectionState)&&(null===(t=i.close)||void 0===t||t.call(i))},o.ontrack=t=>{var e,r;null===(e=i.track)||void 0===e||e.call(i,t.track,t.streams[0]),null===(r=i.stream)||void 0===r||r.call(i,t.streams[0])},o.onremovestream=t=>{var e;null===(e=i.stream)||void 0===e||e.call(i,t.stream,{removed:!0})},{created:Date.now(),connection:o,get channel(){return l},get isDead(){return"closed"===o.connectionState},async signal(e){if("open"!==(null==l?void 0:l.readyState))try{if("offer"===e.type){var r;if((c||"stable"!==o.signalingState)&&(f=!t,f))return;await o.setRemoteDescription(e),await o.setLocalDescription();const n=await a(o),s=Xe(n.sdp);return null===(r=i.signal)||void 0===r||r.call(i,{type:n.type,sdp:s}),{type:n.type,sdp:s}}"answer"!==e.type||"have-local-offer"!==o.signalingState&&"have-remote-offer"!==o.signalingState||await o.setRemoteDescription(e)}catch(t){var n;null===(n=i.error)||void 0===n||n.call(i,t)}else if(("offer"===e.type||"stable"!==o.signalingState)&&(await o.setRemoteDescription(e),"offer"===e.type)){var s;await o.setLocalDescription();const t=await a(o);return null===(s=i.signal)||void 0===s||s.call(i,{type:t.type,sdp:t.sdp}),{type:t.type,sdp:t.sdp}}},sendData:t=>l.send(t),destroy(){l&&l.close(),o.close()},setHandlers:t=>Object.assign(i,t),offerPromise:t?new Promise((t=>{i.signal=e=>{"offer"===e.type&&t(e)}})):Promise.resolve(),addStream(t){t.getTracks().forEach((e=>o.addTrack(e,t)))},removeStream(t){o.getSenders().filter((e=>t.getTracks().includes(e.track))).forEach((t=>o.removeTrack(t)))},addTrack:(t,e)=>o.addTrack(t,e),removeTrack(t){const e=o.getSenders().find((e=>e.track===t));e&&o.removeTrack(e)},async replaceTrack(t,e){const r=o.getSenders().find((e=>e.track===t));r&&await r.replaceTrack(e)}}};const er=[...ke(3,((t,e)=>`stun:stun${e||""}.l.google.com:19302`)),"stun:global.stun.twilio.com:3478"].map((t=>({urls:t}))),rr=Object.getPrototypeOf(Uint8Array),nr=16369,or=255,ir="bufferedamountlow",sr=t=>"@_"+t;var ar;const cr={},lr="EVENT",fr=Be.utils.randomPrivateKey(),ur=je(Be.getPublicKey(fr)),dr={},hr={},pr={},gr=()=>Math.floor(Date.now()/1e3),yr=t=>null!==(ar=(i=pr)[s=t])&&void 0!==ar?ar:i[s]=_e(t,1e4)+2e4,mr=async(t,e)=>{const r={kind:yr(t),content:e,pubkey:ur,created_at:gr(),tags:[["x",t]]},n=je(new Uint8Array(await crypto.subtle.digest("SHA-256",ze(Ze([0,r.pubkey,r.created_at,r.kind,r.tags,r.content])))));return Ze([lr,(0,B.default)((0,E.default)({},r),{id:n,sig:je(await Be.sign(n,fr))})])},wr=(t,e)=>(dr[t]=e,Ze(["REQ",t,{kinds:[yr(e)],since:gr(),"#x":[e]}])),br=t=>(delete dr[t],Ze(["CLOSE",t])),vr=(({init:t,subscribe:e,announce:r})=>{const n={};let o,i,s,b=!1;return(v,A,x)=>{var S;const{appId:I}=v;if(null===(S=n[I])||void 0===S?void 0:S[A])return n[I][A];const k={},T={},P=Ve(Ie,I,A),O=Ye(P),L=Ye(Ve(P,Pe)),R=(async(t,e,r)=>crypto.subtle.importKey("raw",await crypto.subtle.digest({name:"SHA-256"},ze(`${t}:${e}:${r}`)),{name:Ge},!1,["encrypt","decrypt"]))(v.password||"",I,A),U=t=>async e=>({type:e.type,sdp:await t(R,e.sdp)}),N=U(Je),q=U(We),H=()=>tr(!0,v),C=(t,e,r)=>{var n;T[e]?T[e]!==t&&t.destroy():(T[e]=t,K(t,e),null===(n=k[e])||void 0===n||n.forEach(((t,e)=>{e!==r&&t.destroy()})),delete k[e])},D=(t,e)=>{T[e]===t&&delete T[e]},z=t=>(i.push(...ke(t,H)),Oe(i.splice(0,t).map((t=>t.offerPromise.then(q).then((e=>({peer:t,offer:e}))))))),F=(t,e)=>null==x?void 0:x({error:`incorrect password (${v.password}) when decrypting ${e}`,appId:I,peerId:t,roomId:A});if(!v)throw He("requires a config map as the first argument");if(!I&&!v.firebaseApp)throw He("config map is missing appId field");if(!A)throw He("roomId argument required");if(!b){const e=t(v);i=ke(20,H),o=Array.isArray(e)?e:[e],b=!0,s=setInterval((()=>i=i.filter((t=>{const e=Date.now()-t.created<57333;return e||t.destroy(),e}))),59052.99)}const j=o.map((()=>5333)),V=[],Z=o.map((async(t,r)=>e(await t,await O,await L,(t=>async(e,r,n)=>{const[o,i]=await Oe([O,L]);if(e!==o&&e!==i)return;const{peerId:s,offer:l,answer:f,peer:u}="string"==typeof r?Ke(r):r;if(s!==Pe&&!T[s])if(!s||l||f){if(l){var d;if((null===(d=k[s])||void 0===d?void 0:d[t])&&Pe>s)return;const r=tr(!1,v);let o;r.setHandlers({connect:()=>C(r,s,t),close:()=>D(r,s)});try{o=await N(l)}catch(e){return void F(s,"offer")}if(r.isDead)return;const[i,a]=await Oe([Ye(Ve(P,s)),r.signal(o)]);n(i,Ze({peerId:Pe,answer:await q(a)}))}else if(f){let e;try{e=await N(f)}catch(t){return void F(s,"answer")}if(u)u.setHandlers({connect:()=>C(u,s,t),close:()=>D(u,s)}),u.signal(e);else{var h;const r=null===(h=k[s])||void 0===h?void 0:h[t];r&&!r.isDead&&r.signal(e)}}}else{var p;if(null===(p=k[s])||void 0===p?void 0:p[t])return;const[[{peer:e,offer:r}],o]=await Oe([z(1),Ye(Ve(P,s))]);(a=k)[c=s]||(a[c]=[]),k[s][t]=e,setTimeout((()=>((t,e)=>{var r;if(T[t])return;const n=null===(r=k[t])||void 0===r?void 0:r[e];n&&(delete k[t][e],n.destroy())})(s,t)),.9*j[t]),e.setHandlers({connect:()=>C(e,s,t),close:()=>D(e,s)}),n(o,Ze({peerId:Pe,offer:r}))}})(r),z)));Oe([O,L]).then((([t,e])=>{const n=async(o,i)=>{const s=await r(o,t,e);"number"==typeof s&&(j[i]=s),V[i]=setTimeout((()=>n(o,i)),j[i])};Z.forEach((async(t,e)=>{await t,n(await o[e],e)}))}));let K=qe;return(l=n)[f=I]||(l[f]={}),n[I][A]=((t,e,r)=>{const n={},o={},i={},s={},a={},c={},l={},f={onPeerJoin:qe,onPeerLeave:qe,onPeerStream:qe,onPeerTrack:qe},b=(t,e)=>(t?Array.isArray(t)?t:[t]:Ne(n)).flatMap((t=>{const r=n[t];return r?e(t,r):(console.warn(`${Ie}: no peer with id ${t} found`),[])})),v=t=>{n[t]&&(delete n[t],delete s[t],delete a[t],f.onPeerLeave(t),e(t))},A=t=>{if(o[t])return i[t];if(!t)throw He("action type argument is required");const e=ze(t);if(e.byteLength>12)throw He(`action type string "${t}" (${e.byteLength}b) exceeds byte limit (12). Hint: choose a shorter name.`);const r=new Uint8Array(12);r.set(e);let s=0;return o[t]={onComplete:qe,onProgress:qe,setOnComplete:e=>o[t]=(0,B.default)((0,E.default)({},o[t]),{onComplete:e}),setOnProgress:e=>o[t]=(0,B.default)((0,E.default)({},o[t]),{onProgress:e}),async send(t,e,o,i){if(o&&"object"!=typeof o)throw He("action meta argument must be an object");const a=typeof t;if("undefined"===a)throw He("action data cannot be undefined");const c="string"!==a,l=t instanceof Blob,f=l||t instanceof ArrayBuffer||t instanceof rr;if(o&&!f)throw He("action meta argument can only be used with binary data");const u=f?new Uint8Array(l?await t.arrayBuffer():t):ze(c?Ze(t):t),d=o?ze(Ze(o)):null,h=Math.ceil(u.byteLength/nr)+(o?1:0)||1,p=ke(h,((t,e)=>{const n=e===h-1,i=o&&0===e,a=new Uint8Array(15+(i?d.byteLength:n?u.byteLength-nr*(h-(o?2:1)):nr));return a.set(r),a.set([s],12),a.set([n|i<<1|f<<2|c<<3],13),a.set([Math.round((e+1)/h*or)],14),a.set(o?i?d:u.subarray((e-1)*nr,e*nr):u.subarray(e*nr,(e+1)*nr),15),a}));return s=s+1&or,Oe(b(e,(async(t,e)=>{const{channel:r}=e;let s=0;for(;s<h;){const a=p[s];if(r.bufferedAmount>r.bufferedAmountLowThreshold&&await new Promise((t=>{const e=()=>{r.removeEventListener(ir,e),t()};r.addEventListener(ir,e)})),!n[t])break;e.sendData(a),s++,null==i||i(a[14]/or,t,o)}})))}},(u=i)[d=t]||(u[d]=[o[t].send,o[t].setOnComplete,o[t].setOnProgress])},x=(t,e)=>{const r=new Uint8Array(e),n=Fe(r.subarray(0,12)).replaceAll("\0",""),[i]=r.subarray(12,13),[a]=r.subarray(13,14),[c]=r.subarray(14,15),l=r.subarray(15),f=!!(1&a),u=!!(2&a),d=!!(4&a),b=!!(8&a);if(!o[n])return void console.warn(`${Ie}: received message with unregistered type (${n})`);(h=s)[p=t]||(h[p]={}),(g=s[t])[y=n]||(g[y]={});const v=(m=s[t][n])[w=i]||(m[w]={chunks:[]});if(u?v.meta=Ke(Fe(l)):v.chunks.push(l),o[n].onProgress(c/or,t,v.meta),!f)return;const E=new Uint8Array(v.chunks.reduce(((t,e)=>t+e.byteLength),0));if(v.chunks.reduce(((t,e)=>(E.set(e,t),t+e.byteLength)),0),delete s[t][n][i],d)o[n].onComplete(E,t,v.meta);else{const e=Fe(E);o[n].onComplete(b?Ke(e):e,t)}},S=async()=>{await H(""),await new Promise((t=>setTimeout(t,99))),Re(n).forEach((([t,e])=>{e.destroy(),delete n[t]})),r()},[I,k]=A(sr("ping")),[T,P]=A(sr("pong")),[O,L]=A(sr("signal")),[R,U]=A(sr("stream")),[N,q]=A(sr("track")),[H,C]=A(sr("leave"));return K=(t,e)=>{var r;n[e]||(n[e]=t,t.setHandlers({data:t=>x(e,t),stream(t){f.onPeerStream(t,e,c[e]),delete c[e]},track(t,r){f.onPeerTrack(t,r,e,l[e]),delete l[e]},signal:t=>O(t,e),close:()=>v(e),error:()=>v(e)}),f.onPeerJoin(e),null===(r=t.drainEarlyData)||void 0===r||r.call(t,(t=>x(e,t))))},k(((t,e)=>T("",e))),P(((t,e)=>{var r;null===(r=a[e])||void 0===r||r.call(a),delete a[e]})),L(((t,e)=>{var r;return null===(r=n[e])||void 0===r?void 0:r.signal(t)})),U(((t,e)=>c[e]=t)),q(((t,e)=>l[e]=t)),C(((t,e)=>v(e))),Le&&addEventListener("beforeunload",S),{makeAction:A,leave:S,async ping(t){if(!t)throw He("ping() must be called with target peer ID");const e=Date.now();return I("",t),await new Promise((e=>a[t]=e)),Date.now()-e},getPeers:()=>Ue(Re(n).map((([t,e])=>[t,e.connection]))),addStream:(t,e,r)=>b(e,(async(e,n)=>{r&&await R(r,e),n.addStream(t)})),removeStream:(t,e)=>b(e,((e,r)=>r.removeStream(t))),addTrack:(t,e,r,n)=>b(r,(async(r,o)=>{n&&await N(n,r),o.addTrack(t,e)})),removeTrack:(t,e,r)=>b(r,((r,n)=>n.removeTrack(t,e))),replaceTrack:(t,e,r,n,o)=>b(n,(async(n,i)=>{o&&await N(o,n),i.replaceTrack(t,e,r)})),onPeerJoin:t=>f.onPeerJoin=t,onPeerLeave:t=>f.onPeerLeave=t,onPeerStream:t=>f.onPeerStream=t,onPeerTrack:t=>f.onPeerTrack=t}})(0,(t=>delete T[t]),(()=>{delete n[I][A],V.forEach(clearTimeout),Z.forEach((async t=>(await t)())),clearInterval(s)}))}})({init:t=>((t,e,r)=>(t.relayUrls||((t,e)=>{const r=[...t],n=()=>{const t=1e4*Se(e++);return t-Ae(t)};let o=r.length;for(;o;){const t=Ae(n()*o--);[r[o],r[t]]=[r[t],r[o]]}return r})(e,_e(t.appId))).slice(0,t.relayUrls?t.relayUrls.length:t.relayRedundancy||5))(t,Er).map((t=>{const e=((t,e)=>{const r={},n=()=>{const o=new WebSocket(t);o.onclose=()=>{var e;null!==(e=(b=Me)[v=t])&&void 0!==e||(b[v]=3333),setTimeout(n,Me[t]),Me[t]*=2},o.onmessage=t=>e(t.data),r.socket=o,r.url=o.url,r.ready=new Promise((e=>o.onopen=()=>{e(r),Me[t]=3333})),r.send=t=>{1===o.readyState&&o.send(t)}};return n(),r})(t,(t=>{var r;const[n,o,i,s]=Ke(t);if(n===lr)null===(r=hr[o])||void 0===r||r.call(hr,dr[o],i.content);else{const t=`${Ie}: relay failure from ${e.url} - `;"NOTICE"===n?console.warn(t+o):"OK"!==n||i||console.warn(t+s)}}));return cr[t]=e,e.ready})),subscribe(t,e,r,n){const o=Te(64),i=Te(64);return hr[o]=hr[i]=(e,r)=>n(e,r,(async(e,r)=>t.send(await mr(e,r)))),t.send(wr(o,e)),t.send(wr(i,r)),()=>{t.send(br(o)),t.send(br(i)),delete hr[o],delete hr[i]}},announce:async(t,e)=>t.send(await mr(e,Ze({peerId:Pe})))});const Er=["eu.purplerelay.com","ftp.halifax.rwth-aachen.de/nostr","longhorn.bgp.rodeo","multiplexer.huszonegy.world","nfdb.noswhere.com","nostr-verified.wellorder.net","nostr.cool110.xyz","nostr.data.haus","nostr.grooveix.com","nostr.huszonegy.world","nostr.mom","nostr.openhoofd.nl","nostr.petrkr.net/strfry","nostr.sathoarder.com","nostr.stakey.net","nostr.vulpem.com","nostr2.sanhauf.com","nostrelay.circum.space","relay.fountain.fm","relay.nostraddress.com","relay.nostromo.social","relay.snort.social","relay.verified-nostr.com","strfry.openhoofd.nl","yabu.me/v2"].map((t=>"wss://"+t))}));