@liascript/editor 1.1.4--0.14.12 → 1.1.4--0.15.0

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.
Files changed (143) hide show
  1. package/README.md +1 -1
  2. package/dist/{Base.484f46a6.js → Base.af251b35.js} +1 -1
  3. package/dist/Base.f3bc500b.js +1 -0
  4. package/dist/Edrys.37f10c7c.js +1 -0
  5. package/dist/Edrys.947d4ad2.js +1 -0
  6. package/dist/{Trystero.d69546d5.js → Trystero.8dffee2c.js} +1 -1
  7. package/dist/{Trystero.dde47cf4.js → Trystero.d7221dbd.js} +1 -1
  8. package/dist/ace.js +1 -1
  9. package/dist/audio.flac +0 -0
  10. package/dist/ext-inline_autocomplete.js +1 -1
  11. package/dist/ext-language_tools.js +1 -1
  12. package/dist/ext-prompt.js +1 -1
  13. package/dist/ext-searchbox.js +1 -1
  14. package/dist/index.175cb4f9.js +1 -0
  15. package/dist/index.47534769.js +1 -0
  16. package/dist/index.513e6c88.js +1 -0
  17. package/dist/index.5cc1b71c.js +34 -0
  18. package/dist/index.71d55514.js +6 -0
  19. package/dist/index.75afde29.js +1 -0
  20. package/dist/index.77da9204.js +1 -0
  21. package/dist/index.875dceb5.js +1 -0
  22. package/dist/index.8890ab2e.js +10 -0
  23. package/dist/index.8a657cf2.js +6 -0
  24. package/dist/index.8c2d384e.js +1 -0
  25. package/dist/index.bcb37d0a.js +34 -0
  26. package/dist/index.e1efdf52.js +1 -0
  27. package/dist/index.ff04285d.css +1 -0
  28. package/dist/index.html +1 -1
  29. package/dist/mode-apex.js +1 -1
  30. package/dist/mode-asl.js +1 -1
  31. package/dist/mode-astro.js +1 -1
  32. package/dist/mode-c_cpp.js +1 -1
  33. package/dist/mode-coldfusion.js +1 -1
  34. package/dist/mode-csharp.js +1 -1
  35. package/dist/mode-csound_document.js +1 -1
  36. package/dist/mode-csound_orchestra.js +1 -1
  37. package/dist/mode-css.js +1 -1
  38. package/dist/mode-curly.js +1 -1
  39. package/dist/mode-d.js +1 -1
  40. package/dist/mode-dart.js +1 -1
  41. package/dist/mode-django.js +1 -1
  42. package/dist/mode-dot.js +1 -1
  43. package/dist/mode-drools.js +1 -1
  44. package/dist/mode-edifact.js +1 -1
  45. package/dist/mode-ejs.js +1 -1
  46. package/dist/mode-erlang.js +1 -1
  47. package/dist/mode-ftl.js +1 -1
  48. package/dist/mode-glsl.js +1 -1
  49. package/dist/mode-gobstones.js +1 -1
  50. package/dist/mode-golang.js +1 -1
  51. package/dist/mode-groovy.js +1 -1
  52. package/dist/mode-haml.js +1 -1
  53. package/dist/mode-handlebars.js +1 -1
  54. package/dist/mode-haxe.js +1 -1
  55. package/dist/mode-html.js +1 -1
  56. package/dist/mode-html_elixir.js +1 -1
  57. package/dist/mode-html_ruby.js +1 -1
  58. package/dist/mode-jade.js +1 -1
  59. package/dist/mode-java.js +1 -1
  60. package/dist/mode-javascript.js +1 -1
  61. package/dist/mode-jsoniq.js +1 -1
  62. package/dist/mode-jsp.js +1 -1
  63. package/dist/mode-jsx.js +1 -1
  64. package/dist/mode-latte.js +1 -1
  65. package/dist/mode-less.js +1 -1
  66. package/dist/mode-liquid.js +1 -1
  67. package/dist/mode-lua.js +1 -1
  68. package/dist/mode-luapage.js +1 -1
  69. package/dist/mode-markdown.js +1 -1
  70. package/dist/mode-mask.js +1 -1
  71. package/dist/mode-mysql.js +1 -1
  72. package/dist/mode-nix.js +1 -1
  73. package/dist/mode-nunjucks.js +1 -1
  74. package/dist/mode-objectivec.js +1 -1
  75. package/dist/mode-odin.js +1 -1
  76. package/dist/mode-pgsql.js +1 -1
  77. package/dist/mode-php.js +1 -1
  78. package/dist/mode-php_laravel_blade.js +1 -1
  79. package/dist/mode-protobuf.js +1 -1
  80. package/dist/mode-razor.js +1 -1
  81. package/dist/mode-redshift.js +1 -1
  82. package/dist/mode-rhtml.js +1 -1
  83. package/dist/mode-ruby.js +1 -1
  84. package/dist/mode-rust.js +1 -1
  85. package/dist/mode-sac.js +1 -1
  86. package/dist/mode-sass.js +1 -1
  87. package/dist/mode-scad.js +1 -1
  88. package/dist/mode-scala.js +1 -1
  89. package/dist/mode-scrypt.js +1 -1
  90. package/dist/mode-scss.js +1 -1
  91. package/dist/mode-sjs.js +1 -1
  92. package/dist/mode-slim.js +1 -1
  93. package/dist/mode-smarty.js +1 -1
  94. package/dist/mode-soy_template.js +1 -1
  95. package/dist/mode-sqlserver.js +1 -1
  96. package/dist/mode-stylus.js +1 -1
  97. package/dist/mode-svg.js +1 -1
  98. package/dist/mode-swift.js +1 -1
  99. package/dist/mode-tsx.js +1 -1
  100. package/dist/mode-twig.js +1 -1
  101. package/dist/mode-typescript.js +1 -1
  102. package/dist/mode-velocity.js +1 -1
  103. package/dist/mode-visualforce.js +1 -1
  104. package/dist/mode-vue.js +1 -1
  105. package/dist/mode-wollok.js +1 -1
  106. package/dist/mode-xml.js +1 -1
  107. package/dist/mode-xquery.js +1 -1
  108. package/dist/{p2pt.ffc6565a.js → p2pt.33ef209b.js} +3 -3
  109. package/dist/{p2pt.72acf006.js → p2pt.cd402f50.js} +3 -3
  110. package/dist/pako.esm.34f30e86.js +1 -0
  111. package/dist/pako.esm.e6a51df7.js +1 -0
  112. package/dist/theme-cloud_editor.js +1 -1
  113. package/dist/theme-cloud_editor_dark.js +1 -1
  114. package/dist/trystero-mqtt.min.52f29dd5.js +1 -0
  115. package/dist/trystero-mqtt.min.b4f9f9d6.js +1 -0
  116. package/dist/trystero-nostr.min.1de4bf18.js +1 -0
  117. package/dist/trystero-nostr.min.4602d9cb.js +1 -0
  118. package/dist/{trystero-torrent.min.942f97c0.js → trystero-torrent.min.91429d42.js} +1 -1
  119. package/dist/{trystero-torrent.min.21aa41bd.js → trystero-torrent.min.b5d9ebed.js} +1 -1
  120. package/package.json +5 -5
  121. package/dist/Base.2509d532.js +0 -1
  122. package/dist/Edrys.74e9e834.js +0 -1
  123. package/dist/Edrys.f0cb7bde.js +0 -1
  124. package/dist/index.2238fc60.js +0 -6
  125. package/dist/index.40c93815.js +0 -1
  126. package/dist/index.4ca86089.js +0 -1
  127. package/dist/index.7612a0f5.js +0 -1
  128. package/dist/index.7d9384fb.js +0 -1
  129. package/dist/index.8170c3eb.css +0 -1
  130. package/dist/index.b1f73fbe.js +0 -1
  131. package/dist/index.b432ef75.js +0 -34
  132. package/dist/index.b9ed5a40.js +0 -1
  133. package/dist/index.c7a6ef7b.js +0 -10
  134. package/dist/index.cc7df34b.js +0 -1
  135. package/dist/index.ef4f64b2.js +0 -1
  136. package/dist/index.fad28349.js +0 -6
  137. package/dist/index.fd1f7137.js +0 -34
  138. package/dist/pako.esm.0ea7bfc4.js +0 -1
  139. package/dist/pako.esm.d14f4b71.js +0 -1
  140. package/dist/trystero-mqtt.min.797e6207.js +0 -1
  141. package/dist/trystero-mqtt.min.a3a16184.js +0 -1
  142. package/dist/trystero-nostr.min.24890b5b.js +0 -1
  143. package/dist/trystero-nostr.min.6e0fc857.js +0 -1
@@ -1 +0,0 @@
1
- ("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequirea18f.register("9ZhAU",(function(t,e){var n,r;function i(t){if(!Number.isSafeInteger(t)||t<0)throw Error("Wrong positive integer: "+t)}function s(t,...e){if(!((n=t)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw Error("Expected Uint8Array");var n;if(e.length>0&&!e.includes(t.length))throw Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(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")}n=t.exports,r=function(){return Re},Object.defineProperty(n,"joinRoom",{get:r,set:undefined,enumerable:!0,configurable:!0});const a="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function c(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}const h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),d=(t,e)=>t<<32-e|t>>>e;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw Error("Non little-endian hardware is not supported");function l(t){if("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)),!c(t))throw Error("expected Uint8Array, got "+typeof t);return t}class u{clone(){return this._cloneInto()}}function f(t=32){if(a&&"function"==typeof a.getRandomValues)return a.getRandomValues(new Uint8Array(t));throw Error("crypto.getRandomValues must be defined")}class g extends u{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=h(this.buffer)}update(t){o(this);const{view:e,buffer:n,blockLen:r}=this,i=(t=l(t)).length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o!==r)n.set(t.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(e,0),this.pos=0);else{const e=h(t);for(;r<=i-s;s+=r)this.process(e,s)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){o(this),function(t,e){s(t);const n=e.outputLen;if(t.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:i}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(n,0),a=0);for(let t=a;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,h=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+h,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const c=h(t),d=this.outputLen;if(d%4)throw Error("_sha2: outputLen should be aligned to 32bit");const l=d/4,u=this.get();if(l>u.length)throw Error("_sha2: outputLen bigger than state");for(let t=0;t<l;t++)c.setUint32(4*t,u[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:s,pos:o}=this;return t.length=r,t.pos=o,t.finished=i,t.destroyed=s,r%e&&t.buffer.set(n),t}}const p=(t,e,n)=>t&e^t&n^e&n,y=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]),m=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_=new Uint32Array(64);class b extends g{constructor(){super(64,32,8,!1),this.A=0|m[0],this.B=0|m[1],this.C=0|m[2],this.D=0|m[3],this.E=0|m[4],this.F=0|m[5],this.G=0|m[6],this.H=0|m[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:s,G:o,H:a}=this;return[t,e,n,r,i,s,o,a]}set(t,e,n,r,i,s,o,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|o,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)_[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=_[t-15],n=_[t-2],r=d(e,7)^d(e,18)^e>>>3,i=d(n,17)^d(n,19)^n>>>10;_[t]=i+_[t-7]+r+_[t-16]|0}let{A:n,B:r,C:i,D:s,E:o,F:a,G:c,H:h}=this;for(let t=0;t<64;t++){const e=h+(d(o,6)^d(o,11)^d(o,25))+((l=o)&a^~l&c)+y[t]+_[t]|0,u=(d(n,2)^d(n,13)^d(n,22))+p(n,r,i)|0;h=c,c=a,a=o,o=s+e|0,s=i,i=r,r=n,n=e+u|0}var l;n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,o=o+this.E|0,a=a+this.F|0,c=c+this.G|0,h=h+this.H|0,this.set(n,r,i,s,o,a,c,h)}roundClean(){_.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const E=function(t){const e=e=>t().update(l(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}((()=>new b)),w=BigInt(0),R=BigInt(1),A=BigInt(2);function v(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}const S=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function T(t){if(!v(t))throw Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=S[t[n]];return e}function C(t){const e=t.toString(16);return 1&e.length?"0"+e:e}function B(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":"0x"+t)}const I=48,N=57,O=65,k=70,x=97,D=102;function L(t){return t>=I&&t<=N?t-I:t>=O&&t<=k?t-(O-10):t>=x&&t<=D?t-(x-10):void 0}function P(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let e=0,i=0;e<n;e++,i+=2){const n=L(t.charCodeAt(i)),s=L(t.charCodeAt(i+1));if(void 0===n||void 0===s){const e=t[i]+t[i+1];throw Error('hex string expected, got non-hex character "'+e+'" at index '+i)}r[e]=16*n+s}return r}function q(t){return B(T(t))}function U(t){if(!v(t))throw Error("Uint8Array expected");return B(T(Uint8Array.from(t).reverse()))}function H(t,e){return P(t.toString(16).padStart(2*e,"0"))}function $(t,e){return H(t,e).reverse()}function F(t,e,n){let r;if("string"==typeof e)try{r=P(e)}catch(n){throw Error(`${t} must be valid hex string, got "${e}". Cause: ${n}`)}else{if(!v(e))throw Error(t+" must be hex string or Uint8Array");r=Uint8Array.from(e)}const i=r.length;if("number"==typeof n&&i!==n)throw Error(`${t} expected ${n} bytes, got ${i}`);return r}function M(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];if(!v(r))throw Error("Uint8Array expected");e+=r.length}let n=new Uint8Array(e),r=0;for(let e=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}const j=t=>(A<<BigInt(t-1))-R,z=t=>new Uint8Array(t),V=t=>Uint8Array.from(t);function K(t,e,n){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 n)throw Error("hmacFn must be a function");let r=z(t),i=z(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...t)=>n(i,r,...t),c=(t=z())=>{i=a(V([0]),t),r=a(),0!==t.length&&(i=a(V([1]),t),r=a())},h=()=>{if(s++>=1e3)throw Error("drbg: tried 1000 values");let t=0;const n=[];for(;t<e;){r=a();const e=r.slice();n.push(e),t+=r.length}return M(...n)};return(t,e)=>{let n;for(o(),c(t);!(n=e(h()));)c();return o(),n}}const Z={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||v(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 Y(t,e,n={}){const r=(e,n,r)=>{const i=Z[n];if("function"!=typeof i)throw Error(`Invalid validator "${n}", expected function`);const s=t[e];if(!(r&&void 0===s||i(s,t)))throw Error(`Invalid param ${e+""}=${s} (${typeof s}), expected ${n}`)};for(const[t,n]of Object.entries(e))r(t,n,!1);for(const[t,e]of Object.entries(n))r(t,e,!0);return t}var W=Object.freeze({__proto__:null,bitGet:(t,e)=>t>>BigInt(e)&R,bitLen(t){let e;for(e=0;t>w;t>>=R,e+=1);return e},bitMask:j,bitSet:(t,e,n)=>t|(n?R:w)<<BigInt(e),bytesToHex:T,bytesToNumberBE:q,bytesToNumberLE:U,concatBytes:M,createHmacDrbg:K,ensureBytes:F,equalBytes(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return 0===n},hexToBytes:P,hexToNumber:B,isBytes:v,numberToBytesBE:H,numberToBytesLE:$,numberToHexUnpadded:C,numberToVarBytesBE:t=>P(C(t)),utf8ToBytes(t){if("string"!=typeof t)throw Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))},validateObject:Y});const G=BigInt(0),J=BigInt(1),Q=BigInt(2),X=BigInt(3),tt=BigInt(4),et=BigInt(5),nt=BigInt(8);function rt(t,e){const n=t%e;return n>=G?n:e+n}function it(t,e,n){if(n<=G||e<G)throw Error("Expected power/modulo > 0");if(n===J)return G;let r=J;for(;e>G;)e&J&&(r=r*t%n),t=t*t%n,e>>=J;return r}function st(t,e,n){let r=t;for(;e-- >G;)r*=r,r%=n;return r}function ot(t,e){if(t===G||e<=G)throw Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=rt(t,e),r=e,i=G,s=J;for(;n!==G;){const t=r%n,e=i-s*(r/n);r=n,n=t,i=s,s=e}if(r!==J)throw Error("invert: does not exist");return rt(i,e)}BigInt(9),BigInt(16);const at=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ct(t,e){const n=void 0!==e?e:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function ht(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=ht(t);return e+Math.ceil(e/2)}const lt=BigInt(0),ut=BigInt(1);function ft(t){return Y(t.Fp,at.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),Y(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ct(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const{bytesToNumberBE:gt,hexToBytes:pt}=W,yt={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){const{Err:e}=yt;if(t.length<2||2!==t[0])throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(128&r[0])throw new e("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new e("Invalid signature integer: unnecessary leading zero");return{d:gt(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=yt,n="string"==typeof t?pt(t):t;if(!v(n))throw Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:i,l:s}=yt._parseInt(n.subarray(2)),{d:o,l:a}=yt._parseInt(s);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(t){const e=t=>8&Number.parseInt(t[0],16)?"00"+t:t,n=t=>{const e=t.toString(16);return 1&e.length?"0"+e:e},r=e(n(t.s)),i=e(n(t.r)),s=r.length/2,o=i.length/2,a=n(s),c=n(o);return`30${n(o+s+4)}02${c}${i}02${a}${r}`}},mt=BigInt(0),_t=BigInt(1);BigInt(2);const bt=BigInt(3);BigInt(4);class Et extends u{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");i(t.outputLen),i(t.blockLen)}(t);const n=l(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 r=this.blockLen,s=new Uint8Array(r);s.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<s.length;t++)s[t]^=54;this.iHash.update(s),this.oHash=t.create();for(let t=0;t<s.length;t++)s[t]^=106;this.oHash.update(s),s.fill(0)}update(t){return o(this),this.iHash.update(t),this}digestInto(t){o(this),s(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:n,finished:r,destroyed:i,blockLen:s,outputLen:o}=this;return t.finished=r,t.destroyed=i,t.blockLen=s,t.outputLen=o,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const wt=(t,e,n)=>new Et(t,e).update(n).digest();function Rt(t){return{hash:t,hmac:(e,...n)=>wt(t,e,function(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];if(!c(r))throw Error("Uint8Array expected");e+=r.length}const n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}(...n)),randomBytes:f}}wt.create=(t,e)=>new Et(t,e);const At=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),St=BigInt(1),Tt=BigInt(2),Ct=(t,e)=>(t+e/Tt)/e;function Bt(t){const e=At,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),h=t*t*t%e,d=h*h*t%e,l=st(d,n,e)*d%e,u=st(l,n,e)*d%e,f=st(u,Tt,e)*h%e,g=st(f,i,e)*f%e,p=st(g,s,e)*g%e,y=st(p,a,e)*p%e,m=st(y,c,e)*y%e,_=st(m,a,e)*p%e,b=st(_,n,e)*d%e,E=st(b,o,e)*g%e,w=st(E,r,e)*h%e,R=st(w,Tt,e);if(!It.eql(It.sqr(R),t))throw Error("Cannot find square root");return R}const It=function(t,e,n=!1,r={}){if(t<=G)throw Error("Expected Field ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=ct(t,e);if(s>2048)throw Error("Field lengths over 2048 bytes are not supported");const o=function(t){if(t%tt===X){const e=(t+J)/tt;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw Error("Cannot find square root");return r}}if(t%nt===et){const e=(t-et)/nt;return function(t,n){const r=t.mul(n,Q),i=t.pow(r,e),s=t.mul(n,i),o=t.mul(t.mul(s,Q),i),a=t.mul(s,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),n))throw Error("Cannot find square root");return a}}return function(t){const e=(t-J)/Q;let n,r,i;for(n=t-J,r=0;n%Q===G;n/=Q,r++);for(i=Q;i<t&&it(i,e,t)!==t-J;i++);if(1===r){const e=(t+J)/tt;return(t,n)=>{const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw Error("Cannot find square root");return r}}const s=(n+J)/Q;return(t,o)=>{if(t.pow(o,e)===t.neg(t.ONE))throw Error("Cannot find square root");let a=r,c=t.pow(t.mul(t.ONE,i),n),h=t.pow(o,s),d=t.pow(o,n);for(;!t.eql(d,t.ONE);){if(t.eql(d,t.ZERO))return t.ZERO;let e=1;for(let n=t.sqr(d);e<a&&!t.eql(n,t.ONE);e++)n=t.sqr(n);const n=t.pow(c,J<<BigInt(a-e-1));c=t.sqr(n),h=t.mul(h,n),d=t.mul(d,c),a=e}return h}}(t)}(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:s,MASK:j(i),ZERO:G,ONE:J,create:e=>rt(e,t),isValid(e){if("bigint"!=typeof e)throw Error("Invalid field element: expected bigint, got "+typeof e);return G<=e&&e<t},is0:t=>t===G,isOdd:t=>(t&J)===J,neg:e=>rt(-e,t),eql:(t,e)=>t===e,sqr:e=>rt(e*e,t),add:(e,n)=>rt(e+n,t),sub:(e,n)=>rt(e-n,t),mul:(e,n)=>rt(e*n,t),pow:(t,e)=>function(t,e,n){if(n<G)throw Error("Expected power > 0");if(n===G)return t.ONE;if(n===J)return e;let r=t.ONE,i=e;for(;n>G;)n&J&&(r=t.mul(r,i)),i=t.sqr(i),n>>=J;return r}(a,t,e),div:(e,n)=>rt(e*ot(n,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>ot(e,t),sqrt:r.sqrt||(t=>o(a,t)),invertBatch:t=>function(t,e){const n=Array(e.length),r=e.reduce(((e,r,i)=>t.is0(r)?e:(n[i]=e,t.mul(e,r))),t.ONE),i=t.inv(r);return e.reduceRight(((e,r,i)=>t.is0(r)?e:(n[i]=t.mul(e,n[i]),t.mul(e,r))),i),n}(a,t),cmov:(t,e,n)=>n?e:t,toBytes:t=>n?$(t,s):H(t,s),fromBytes(t){if(t.length!==s)throw Error(`Fp.fromBytes: expected ${s}, got ${t.length}`);return n?U(t):q(t)}});return Object.freeze(a)}(At,void 0,void 0,{sqrt:Bt}),Nt=function(t,e){const n=e=>function(t){const e=function(t){const e=ft(t);return Y(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}(t),{Fp:n,n:r}=e,i=n.BYTES+1,s=2*n.BYTES+1;function o(t){return rt(t,r)}function a(t){return ot(t,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:h,weierstrassEquation:d,isWithinCurveOrder:l}=function(t){const e=function(t){const e=ft(t);Y(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=e;if(n){if(!r.eql(i,r.ZERO))throw Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}(t),{Fp:n}=e,r=e.toBytes||((t,e)=>{const r=e.toAffine();return M(Uint8Array.from([4]),n.toBytes(r.x),n.toBytes(r.y))}),i=e.fromBytes||(t=>{const e=t.subarray(1);return{x:n.fromBytes(e.subarray(0,n.BYTES)),y:n.fromBytes(e.subarray(n.BYTES,2*n.BYTES))}});function s(t){const{a:r,b:i}=e,s=n.sqr(t),o=n.mul(s,t);return n.add(n.add(o,n.mul(t,r)),i)}if(!n.eql(n.sqr(e.Gy),s(e.Gx)))throw Error("bad generator point: equation left != right");function o(t){return"bigint"==typeof t&&mt<t&&t<e.n}function a(t){if(!o(t))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function c(t){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:s}=e;if(n&&"bigint"!=typeof t){if(v(t)&&(t=T(t)),"string"!=typeof t||!n.includes(t.length))throw Error("Invalid key");t=t.padStart(2*r,"0")}let o;try{o="bigint"==typeof t?t:q(F("private key",t,r))}catch(e){throw Error(`private key must be ${r} bytes, hex or bigint, not ${typeof t}`)}return i&&(o=rt(o,s)),a(o),o}const h=new Map;function d(t){if(!(t instanceof l))throw Error("ProjectivePoint expected")}class l{constructor(t,e,r){if(this.px=t,this.py=e,this.pz=r,null==t||!n.isValid(t))throw Error("x required");if(null==e||!n.isValid(e))throw Error("y required");if(null==r||!n.isValid(r))throw Error("z required")}static fromAffine(t){const{x:e,y:r}=t||{};if(!t||!n.isValid(e)||!n.isValid(r))throw Error("invalid affine point");if(t instanceof l)throw Error("projective point not allowed");const i=t=>n.eql(t,n.ZERO);return i(e)&&i(r)?l.ZERO:new l(e,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(l.fromAffine)}static fromHex(t){const e=l.fromAffine(i(F("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return l.BASE.multiply(c(t))}_setWindowSize(t){this._WINDOW_SIZE=t,h.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw Error("bad point: ZERO")}const{x:t,y:r}=this.toAffine();if(!n.isValid(t)||!n.isValid(r))throw Error("bad point: x or y not FE");const i=n.sqr(r),o=s(t);if(!n.eql(i,o))throw Error("bad point: equation left != right");if(!this.isTorsionFree())throw Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:t}=this.toAffine();if(n.isOdd)return!n.isOdd(t);throw Error("Field doesn't support isOdd")}equals(t){d(t);const{px:e,py:r,pz:i}=this,{px:s,py:o,pz:a}=t,c=n.eql(n.mul(e,a),n.mul(s,i)),h=n.eql(n.mul(r,a),n.mul(o,i));return c&&h}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:t,b:r}=e,i=n.mul(r,bt),{px:s,py:o,pz:a}=this;let c=n.ZERO,h=n.ZERO,d=n.ZERO,u=n.mul(s,s),f=n.mul(o,o),g=n.mul(a,a),p=n.mul(s,o);return p=n.add(p,p),d=n.mul(s,a),d=n.add(d,d),c=n.mul(t,d),h=n.mul(i,g),h=n.add(c,h),c=n.sub(f,h),h=n.add(f,h),h=n.mul(c,h),c=n.mul(p,c),d=n.mul(i,d),g=n.mul(t,g),p=n.sub(u,g),p=n.mul(t,p),p=n.add(p,d),d=n.add(u,u),u=n.add(d,u),u=n.add(u,g),u=n.mul(u,p),h=n.add(h,u),g=n.mul(o,a),g=n.add(g,g),u=n.mul(g,p),c=n.sub(c,u),d=n.mul(g,f),d=n.add(d,d),d=n.add(d,d),new l(c,h,d)}add(t){d(t);const{px:r,py:i,pz:s}=this,{px:o,py:a,pz:c}=t;let h=n.ZERO,u=n.ZERO,f=n.ZERO;const g=e.a,p=n.mul(e.b,bt);let y=n.mul(r,o),m=n.mul(i,a),_=n.mul(s,c),b=n.add(r,i),E=n.add(o,a);b=n.mul(b,E),E=n.add(y,m),b=n.sub(b,E),E=n.add(r,s);let w=n.add(o,c);return E=n.mul(E,w),w=n.add(y,_),E=n.sub(E,w),w=n.add(i,s),h=n.add(a,c),w=n.mul(w,h),h=n.add(m,_),w=n.sub(w,h),f=n.mul(g,E),h=n.mul(p,_),f=n.add(h,f),h=n.sub(m,f),f=n.add(m,f),u=n.mul(h,f),m=n.add(y,y),m=n.add(m,y),_=n.mul(g,_),E=n.mul(p,E),m=n.add(m,_),_=n.sub(y,_),_=n.mul(g,_),E=n.add(E,_),y=n.mul(m,E),u=n.add(u,y),y=n.mul(w,E),h=n.mul(b,h),h=n.sub(h,y),y=n.mul(b,m),f=n.mul(w,f),f=n.add(f,y),new l(h,u,f)}subtract(t){return this.add(t.negate())}is0(){return this.equals(l.ZERO)}wNAF(t){return f.wNAFCached(this,h,t,(t=>{const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(l.fromAffine)}))}multiplyUnsafe(t){const r=l.ZERO;if(t===mt)return r;if(a(t),t===_t)return this;const{endo:i}=e;if(!i)return f.unsafeLadder(this,t);let{k1neg:s,k1:o,k2neg:c,k2:h}=i.splitScalar(t),d=r,u=r,g=this;for(;o>mt||h>mt;)o&_t&&(d=d.add(g)),h&_t&&(u=u.add(g)),g=g.double(),o>>=_t,h>>=_t;return s&&(d=d.negate()),c&&(u=u.negate()),u=new l(n.mul(u.px,i.beta),u.py,u.pz),d.add(u)}multiply(t){a(t);let r,i,s=t;const{endo:o}=e;if(o){const{k1neg:t,k1:e,k2neg:a,k2:c}=o.splitScalar(s);let{p:h,f:d}=this.wNAF(e),{p:u,f:g}=this.wNAF(c);h=f.constTimeNegate(t,h),u=f.constTimeNegate(a,u),u=new l(n.mul(u.px,o.beta),u.py,u.pz),r=h.add(u),i=d.add(g)}else{const{p:t,f:e}=this.wNAF(s);r=t,i=e}return l.normalizeZ([r,i])[0]}multiplyAndAddUnsafe(t,e,n){const r=l.BASE,i=(t,e)=>e!==mt&&e!==_t&&t.equals(r)?t.multiply(e):t.multiplyUnsafe(e),s=i(this,e).add(i(t,n));return s.is0()?void 0:s}toAffine(t){const{px:e,py:r,pz:i}=this,s=this.is0();null==t&&(t=s?n.ONE:n.inv(i));const o=n.mul(e,t),a=n.mul(r,t),c=n.mul(i,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw Error("invZ was invalid");return{x:o,y:a}}isTorsionFree(){const{h:t,isTorsionFree:n}=e;if(t===_t)return!0;if(n)return n(l,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:n}=e;return t===_t?this:n?n(l,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return this.assertValidity(),r(l,this,t)}toHex(t=!0){return T(this.toRawBytes(t))}}l.BASE=new l(e.Gx,e.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const u=e.nBitLength,f=function(t,e){const n=(t,e)=>{const n=e.negate();return t?n:e},r=t=>({windows:Math.ceil(e/t)+1,windowSize:2**(t-1)});return{constTimeNegate:n,unsafeLadder(e,n){let r=t.ZERO,i=e;for(;n>lt;)n&ut&&(r=r.add(i)),i=i.double(),n>>=ut;return r},precomputeWindow(t,e){const{windows:n,windowSize:i}=r(e),s=[];let o=t,a=o;for(let t=0;t<n;t++){a=o,s.push(a);for(let t=1;t<i;t++)a=a.add(o),s.push(a);o=a.double()}return s},wNAF(e,i,s){const{windows:o,windowSize:a}=r(e);let c=t.ZERO,h=t.BASE;const d=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let t=0;t<o;t++){const e=t*a;let r=Number(s&d);s>>=u,r>a&&(r-=l,s+=ut);const o=e,f=e+Math.abs(r)-1,g=t%2!=0,p=r<0;0===r?h=h.add(n(g,i[o])):c=c.add(n(p,i[f]))}return{p:c,f:h}},wNAFCached(t,e,n,r){const i=t._WINDOW_SIZE||1;let s=e.get(t);return s||(s=this.precomputeWindow(t,i),1!==i&&e.set(t,r(s))),this.wNAF(i,s,n)}}}(l,e.endo?Math.ceil(u/2):u);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:o}}({...e,toBytes(t,e,r){const i=e.toAffine(),s=n.toBytes(i.x),o=M;return r?o(Uint8Array.from([e.hasEvenY()?2:3]),s):o(Uint8Array.from([4]),s,n.toBytes(i.y))},fromBytes(t){const e=t.length,r=t[0],o=t.subarray(1);if(e!==i||2!==r&&3!==r){if(e===s&&4===r)return{x:n.fromBytes(o.subarray(0,n.BYTES)),y:n.fromBytes(o.subarray(n.BYTES,2*n.BYTES))};throw Error(`Point of length ${e} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}{const t=q(o);if(!(mt<(a=t)&&a<n.ORDER))throw Error("Point is not on curve");const e=d(t);let i=n.sqrt(e);return 1==(1&r)!=((i&_t)===_t)&&(i=n.neg(i)),{x:t,y:i}}var a}}),u=t=>T(H(t,e.nByteLength));function f(t){return t>r>>_t}const g=(t,e,n)=>q(t.slice(e,n));class p{constructor(t,e,n){this.r=t,this.s=e,this.recovery=n,this.assertValidity()}static fromCompact(t){const n=e.nByteLength;return t=F("compactSignature",t,2*n),new p(g(t,0,n),g(t,n,2*n))}static fromDER(t){const{r:e,s:n}=yt.toSig(F("DER",t));return new p(e,n)}assertValidity(){if(!l(this.r))throw Error("r must be 0 < r < CURVE.n");if(!l(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit(t){return new p(this.r,this.s,t)}recoverPublicKey(t){const{r:r,s:i,recovery:s}=this,h=b(F("msgHash",t));if(null==s||![0,1,2,3].includes(s))throw Error("recovery id invalid");const d=2===s||3===s?r+e.n:r;if(d>=n.ORDER)throw Error("recovery id 2 or 3 invalid");const l=0==(1&s)?"02":"03",f=c.fromHex(l+u(d)),g=a(d),p=o(-h*g),y=o(i*g),m=c.BASE.multiplyAndAddUnsafe(f,p,y);if(!m)throw Error("point at infinify");return m.assertValidity(),m}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return P(this.toDERHex())}toDERHex(){return yt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return P(this.toCompactHex())}toCompactHex(){return u(this.r)+u(this.s)}}const y={isValidPrivateKey(t){try{return h(t),!0}catch(t){return!1}},normPrivateKeyToScalar:h,randomPrivateKey(){const t=dt(e.n);return function(t,e,n=!1){const r=t.length,i=ht(e),s=dt(e);if(r<16||r<s||r>1024)throw Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=rt(n?q(t):U(t),e-J)+J;return n?$(o,i):H(o,i)}(e.randomBytes(t),e.n)},precompute:(t=8,e=c.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function m(t){const e=v(t),n="string"==typeof t,r=(e||n)&&t.length;return e?r===i||r===s:n?r===2*i||r===2*s:t instanceof c}const _=e.bits2int||(t=>{const n=q(t),r=8*t.length-e.nBitLength;return r>0?n>>BigInt(r):n}),b=e.bits2int_modN||(t=>o(_(t))),E=j(e.nBitLength);function w(t){if("bigint"!=typeof t)throw Error("bigint expected");if(!(mt<=t&&t<E))throw Error("bigint expected < 2^"+e.nBitLength);return H(t,e.nByteLength)}function R(t,r,i=A){if(["recovered","canonical"].some((t=>t in i)))throw Error("sign() legacy options not supported");const{hash:s,randomBytes:d}=e;let{lowS:u,prehash:g,extraEntropy:y}=i;null==u&&(u=!0),t=F("msgHash",t),g&&(t=F("prehashed msgHash",s(t)));const m=b(t),E=h(r),R=[w(E),w(m)];if(null!=y){const t=!0===y?d(n.BYTES):y;R.push(F("extraEntropy",t))}const v=M(...R),S=m;return{seed:v,k2sig(t){const e=_(t);if(!l(e))return;const n=a(e),r=c.BASE.multiply(e).toAffine(),i=o(r.x);if(i===mt)return;const s=o(n*o(S+i*E));if(s===mt)return;let h=(r.x===i?0:2)|Number(r.y&_t),d=s;return u&&f(s)&&(d=function(t){return f(t)?o(-t):t}(s),h^=1),new p(i,d,h)}}}const A={lowS:e.lowS,prehash:!1},S={lowS:e.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:e,getPublicKey:(t,e=!0)=>c.fromPrivateKey(t).toRawBytes(e),getSharedSecret(t,e,n=!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(h(t)).toRawBytes(n)},sign(t,n,r=A){const{seed:i,k2sig:s}=R(t,n,r),o=e;return K(o.hash.outputLen,o.nByteLength,o.hmac)(i,s)},verify(t,n,r,i=S){const s=t;if(n=F("msgHash",n),r=F("publicKey",r),"strict"in i)throw Error("options.strict was renamed to lowS");const{lowS:h,prehash:d}=i;let l,u;try{if("string"==typeof s||v(s))try{l=p.fromDER(s)}catch(t){if(!(t instanceof yt.Err))throw t;l=p.fromCompact(s)}else{if("object"!=typeof s||"bigint"!=typeof s.r||"bigint"!=typeof s.s)throw Error("PARSE");{const{r:t,s:e}=s;l=new p(t,e)}}u=c.fromHex(r)}catch(t){if("PARSE"===t.message)throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(h&&l.hasHighS())return!1;d&&(n=e.hash(n));const{r:f,s:g}=l,y=b(n),m=a(g),_=o(y*m),E=o(f*m),w=c.BASE.multiplyAndAddUnsafe(u,_,E)?.toAffine();return!!w&&o(w.x)===f},ProjectivePoint:c,Signature:p,utils:y}}({...t,...Rt(e)});return Object.freeze({...n(e),create:n})}({a:BigInt(0),b:BigInt(7),Fp:It,n:vt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const e=vt,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-St*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=Ct(s*t,e),c=Ct(-r*t,e);let h=rt(t-a*n-c*i,e),d=rt(-a*r-c*s,e);const l=h>o,u=d>o;if(l&&(h=e-h),u&&(d=e-d),h>o||d>o)throw Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:h,k2neg:u,k2:d}}}},E),Ot=BigInt(0),kt=t=>"bigint"==typeof t&&Ot<t&&t<At,xt={};function Dt(t,...e){let n=xt[t];if(void 0===n){const e=E(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=M(e,e),xt[t]=n}return E(M(n,...e))}const Lt=t=>t.toRawBytes(!0).slice(1),Pt=t=>H(t,32),qt=t=>rt(t,At),Ut=t=>rt(t,vt),Ht=Nt.ProjectivePoint;function $t(t){let e=Nt.utils.normPrivateKeyToScalar(t),n=Ht.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:Ut(-e),bytes:Lt(n)}}function Ft(t){if(!kt(t))throw Error("bad x: need 0 < x < p");const e=qt(t*t);let n=Bt(qt(e*t+BigInt(7)));n%Tt!==Ot&&(n=qt(-n));const r=new Ht(t,n,St);return r.assertValidity(),r}function Mt(...t){return Ut(q(Dt("BIP0340/challenge",...t)))}function jt(t,e,n){const r=F("signature",t,64),i=F("message",e),s=F("publicKey",n,32);try{const t=Ft(q(s)),e=q(r.subarray(0,32));if(!kt(e))return!1;const n=q(r.subarray(32,64));if(!(t=>"bigint"==typeof t&&Ot<t&&t<vt)(n))return!1;const o=Mt(Pt(e),Lt(t),i),a=((t,e,n)=>Ht.BASE.multiplyAndAddUnsafe(t,e,n))(t,n,Ut(-o));return!(!a||!a.hasEvenY()||a.toAffine().x!==e)}catch(t){return!1}}const zt={getPublicKey:function(t){return $t(t).bytes},sign:function(t,e,n=f(32)){const r=F("message",t),{bytes:i,scalar:s}=$t(e),o=F("auxRand",n,32),a=Pt(s^q(Dt("BIP0340/aux",o))),c=Dt("BIP0340/nonce",a,i,r),h=Ut(q(c));if(h===Ot)throw Error("sign failed: k is zero");const{bytes:d,scalar:l}=$t(h),u=Mt(d,i,r),g=new Uint8Array(64);if(g.set(d,0),g.set(Pt(Ut(l+u*s)),32),!jt(g,r,i))throw Error("sign: Invalid signature produced");return g},verify:jt,utils:{randomPrivateKey:Nt.utils.randomPrivateKey,lift_x:Ft,pointToBytes:Lt,numberToBytesBE:H,bytesToNumberBE:q,taggedHash:Dt,mod:rt}};function Vt(t){const e=new Uint8Array(t);for(let n=0;n<t;n++)e[n]=256*Math.random()|0;return e}function Kt(){if("undefined"==typeof globalThis)return null;const t={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return t.RTCPeerConnection?t:null}function Zt(t,e){return Object.defineProperty(t,"code",{value:e,enumerable:!0,configurable:!0}),t}function Yt(t){return t.replace(/a=ice-options:trickle\s\n/g,"")}class Wt{constructor(t={}){if(this._map=new Map,this._id=Vt(4).toString("hex").slice(0,7),this._doDebug=t.debug,this._debug("new peer %o",t),this.channelName=t.initiator?t.channelName||Vt(20).toString("hex"):null,this.initiator=t.initiator||!1,this.channelConfig=t.channelConfig||Wt.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},Wt.config,t.config),this.offerOptions=t.offerOptions||{},this.answerOptions=t.answerOptions||{},this.sdpTransform=t.sdpTransform||(t=>t),this.streams=t.streams||(t.stream?[t.stream]:[]),this.trickle=void 0===t.trickle||t.trickle,this.allowHalfTrickle=void 0!==t.allowHalfTrickle&&t.allowHalfTrickle,this.iceCompleteTimeout=t.iceCompleteTimeout||5e3,this.destroyed=!1,this.destroying=!1,this._connected=!1,this.remoteAddress=void 0,this.remoteFamily=void 0,this.remotePort=void 0,this.localAddress=void 0,this.localFamily=void 0,this.localPort=void 0,this._wrtc=t.wrtc&&"object"==typeof t.wrtc?t.wrtc:Kt(),!this._wrtc)throw"undefined"==typeof window?Zt(Error("No WebRTC support: Specify `opts.wrtc` option in this environment"),"ERR_WEBRTC_SUPPORT"):Zt(Error("No WebRTC support: Not a supported browser"),"ERR_WEBRTC_SUPPORT");this._pcReady=!1,this._channelReady=!1,this._iceComplete=!1,this._iceCompleteTimer=null,this._channel=null,this._pendingCandidates=[],this._isNegotiating=!1,this._firstNegotiation=!0,this._batchedNegotiation=!1,this._queuedNegotiation=!1,this._sendersAwaitingStable=[],this._senderMap=new Map,this._closingInterval=null,this._remoteTracks=[],this._remoteStreams=[],this._chunk=null,this._cb=null,this._interval=null;try{this._pc=new this._wrtc.RTCPeerConnection(this.config)}catch(t){return void this.destroy(Zt(t,"ERR_PC_CONSTRUCTOR"))}this._isReactNativeWebrtc="number"==typeof this._pc._peerConnectionId,this._pc.oniceconnectionstatechange=()=>{this._onIceStateChange()},this._pc.onicegatheringstatechange=()=>{this._onIceStateChange()},this._pc.onconnectionstatechange=()=>{this._onConnectionStateChange()},this._pc.onsignalingstatechange=()=>{this._onSignalingStateChange()},this._pc.onicecandidate=t=>{this._onIceCandidate(t)},"object"==typeof this._pc.peerIdentity&&this._pc.peerIdentity.catch((t=>{this.destroy(Zt(t,"ERR_PC_PEER_IDENTITY"))})),this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=t=>{this._setupData(t)},this.streams&&this.streams.forEach((t=>{this.addStream(t)})),this._pc.ontrack=t=>{this._onTrack(t)},this._debug("initial negotiation"),this._needsNegotiation()}get bufferSize(){return this._channel&&this._channel.bufferedAmount||0}get connected(){return this._connected&&"open"===this._channel.readyState}address(){return{port:this.localPort,family:this.localFamily,address:this.localAddress}}signal(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot signal after peer is destroyed"),"ERR_DESTROYED");if("string"==typeof t)try{t=JSON.parse(t)}catch(e){t={}}this._debug("signal()"),t.renegotiate&&this.initiator&&(this._debug("got request to renegotiate"),this._needsNegotiation()),t.transceiverRequest&&this.initiator&&(this._debug("got request for transceiver"),this.addTransceiver(t.transceiverRequest.kind,t.transceiverRequest.init)),t.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(t.candidate):this._pendingCandidates.push(t.candidate)),t.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(t)).then((()=>{this.destroyed||(this._pendingCandidates.forEach((t=>{this._addIceCandidate(t)})),this._pendingCandidates=[],"offer"===this._pc.remoteDescription.type&&this._createAnswer())})).catch((t=>{this.destroy(Zt(t,"ERR_SET_REMOTE_DESCRIPTION"))})),t.sdp||t.candidate||t.renegotiate||t.transceiverRequest||this.destroy(Zt(Error("signal() called with invalid signal data"),"ERR_SIGNALING"))}}_addIceCandidate(t){const e=new this._wrtc.RTCIceCandidate(t);this._pc.addIceCandidate(e).catch((t=>{!e.address||e.address.endsWith(".local")?console.warn("Ignoring unsupported ICE candidate."):this.destroy(Zt(t,"ERR_ADD_ICE_CANDIDATE"))}))}send(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot send after peer is destroyed"),"ERR_DESTROYED");this._channel.send(t)}}addTransceiver(t,e){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot addTransceiver after peer is destroyed"),"ERR_DESTROYED");if(this._debug("addTransceiver()"),this.initiator)try{this._pc.addTransceiver(t,e),this._needsNegotiation()}catch(t){this.destroy(Zt(t,"ERR_ADD_TRANSCEIVER"))}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:t,init:e}})}}addStream(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot addStream after peer is destroyed"),"ERR_DESTROYED");this._debug("addStream()"),t.getTracks().forEach((e=>{this.addTrack(e,t)}))}}addTrack(t,e){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot addTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("addTrack()");const n=this._senderMap.get(t)||new Map;let r=n.get(e);if(r)throw r.removed?Zt(Error("Track has been removed. You should enable/disable tracks that you want to re-add."),"ERR_SENDER_REMOVED"):Zt(Error("Track has already been added to that stream."),"ERR_SENDER_ALREADY_ADDED");r=this._pc.addTrack(t,e),n.set(e,r),this._senderMap.set(t,n),this._needsNegotiation()}replaceTrack(t,e,n){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot replaceTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("replaceTrack()");const r=this._senderMap.get(t),i=r?r.get(n):null;if(!i)throw Zt(Error("Cannot replace track that was never added."),"ERR_TRACK_NOT_ADDED");e&&this._senderMap.set(e,r),null!=i.replaceTrack?i.replaceTrack(e):this.destroy(Zt(Error("replaceTrack is not supported in this browser"),"ERR_UNSUPPORTED_REPLACETRACK"))}removeTrack(t,e){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot removeTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSender()");const n=this._senderMap.get(t),r=n?n.get(e):null;if(!r)throw Zt(Error("Cannot remove track that was never added."),"ERR_TRACK_NOT_ADDED");try{r.removed=!0,this._pc.removeTrack(r)}catch(t){"NS_ERROR_UNEXPECTED"===t.name?this._sendersAwaitingStable.push(r):this.destroy(Zt(t,"ERR_REMOVE_TRACK"))}this._needsNegotiation()}removeStream(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot removeStream after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSenders()"),t.getTracks().forEach((e=>{this.removeTrack(e,t)}))}}_needsNegotiation(){this._debug("_needsNegotiation"),this._batchedNegotiation||(this._batchedNegotiation=!0,queueMicrotask((()=>{this._batchedNegotiation=!1,this.initiator||!this._firstNegotiation?(this._debug("starting batched negotiation"),this.negotiate()):this._debug("non-initiator initial negotiation request discarded"),this._firstNegotiation=!1})))}negotiate(){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot negotiate after peer is destroyed"),"ERR_DESTROYED");this.initiator?this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("start negotiation"),setTimeout((()=>{this._createOffer()}),0)):this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("requesting negotiation from initiator"),this.emit("signal",{type:"renegotiate",renegotiate:!0})),this._isNegotiating=!0}}destroy(t){this.destroyed||this.destroying||(this.destroying=!0,this._debug("destroying (error: %s)",t&&(t.message||t)),queueMicrotask((()=>{if(this.destroyed=!0,this.destroying=!1,this._debug("destroy (error: %s)",t&&(t.message||t)),this._connected=!1,this._pcReady=!1,this._channelReady=!1,this._remoteTracks=null,this._remoteStreams=null,this._senderMap=null,clearInterval(this._closingInterval),this._closingInterval=null,clearInterval(this._interval),this._interval=null,this._chunk=null,this._cb=null,this._channel){try{this._channel.close()}catch(t){}this._channel.onmessage=null,this._channel.onopen=null,this._channel.onclose=null,this._channel.onerror=null}if(this._pc){try{this._pc.close()}catch(t){}this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ontrack=null,this._pc.ondatachannel=null}this._pc=null,this._channel=null,t&&this.emit("error",t),this.emit("close")})))}_setupData(t){if(!t.channel)return this.destroy(Zt(Error("Data channel event is missing `channel` property"),"ERR_DATA_CHANNEL"));this._channel=t.channel,this._channel.binaryType="arraybuffer","number"==typeof this._channel.bufferedAmountLowThreshold&&(this._channel.bufferedAmountLowThreshold=65536),this.channelName=this._channel.label,this._channel.onmessage=t=>{this._onChannelMessage(t)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=t=>{this.destroy(Zt(t,"ERR_DATA_CHANNEL"))};let e=!1;this._closingInterval=setInterval((()=>{this._channel&&"closing"===this._channel.readyState?(e&&this._onChannelClose(),e=!0):e=!1}),5e3)}_startIceCompleteTimeout(){this.destroyed||this._iceCompleteTimer||(this._debug("started iceComplete timeout"),this._iceCompleteTimer=setTimeout((()=>{this._iceComplete||(this._iceComplete=!0,this._debug("iceComplete timeout completed"),this.emit("iceTimeout"),this.emit("_iceComplete"))}),this.iceCompleteTimeout))}_createOffer(){this.destroyed||this._pc.createOffer(this.offerOptions).then((t=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(t.sdp=Yt(t.sdp)),t.sdp=this.sdpTransform(t.sdp);const e=()=>{if(this.destroyed)return;const e=this._pc.localDescription||t;this._debug("signal"),this.emit("signal",{type:e.type,sdp:e.sdp})};this._pc.setLocalDescription(t).then((()=>{this._debug("createOffer success"),this.destroyed||(this.trickle||this._iceComplete?e():this.once("_iceComplete",e))})).catch((t=>{this.destroy(Zt(t,"ERR_SET_LOCAL_DESCRIPTION"))}))})).catch((t=>{this.destroy(Zt(t,"ERR_CREATE_OFFER"))}))}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach((t=>{t.mid||!t.sender.track||t.requested||(t.requested=!0,this.addTransceiver(t.sender.track.kind))}))}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then((t=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(t.sdp=Yt(t.sdp)),t.sdp=this.sdpTransform(t.sdp);const e=()=>{if(this.destroyed)return;const e=this._pc.localDescription||t;this._debug("signal"),this.emit("signal",{type:e.type,sdp:e.sdp}),this.initiator||this._requestMissingTransceivers()};this._pc.setLocalDescription(t).then((()=>{this.destroyed||(this.trickle||this._iceComplete?e():this.once("_iceComplete",e))})).catch((t=>{this.destroy(Zt(t,"ERR_SET_LOCAL_DESCRIPTION"))}))})).catch((t=>{this.destroy(Zt(t,"ERR_CREATE_ANSWER"))}))}_onConnectionStateChange(){this.destroyed||"failed"===this._pc.connectionState&&this.destroy(Zt(Error("Connection failed."),"ERR_CONNECTION_FAILURE"))}_onIceStateChange(){if(this.destroyed)return;const t=this._pc.iceConnectionState,e=this._pc.iceGatheringState;this._debug("iceStateChange (connection: %s) (gathering: %s)",t,e),this.emit("iceStateChange",t,e),"connected"!==t&&"completed"!==t||(this._pcReady=!0,this._maybeReady()),"failed"===t&&this.destroy(Zt(Error("Ice connection failed."),"ERR_ICE_CONNECTION_FAILURE")),"closed"===t&&this.destroy(Zt(Error("Ice connection closed."),"ERR_ICE_CONNECTION_CLOSED"))}getStats(t){const e=t=>("[object Array]"==={}.toString.call(t.values)&&t.values.forEach((e=>{Object.assign(t,e)})),t);0===this._pc.getStats.length||this._isReactNativeWebrtc?this._pc.getStats().then((n=>{const r=[];n.forEach((t=>{r.push(e(t))})),t(null,r)}),(e=>t(e))):this._pc.getStats.length>0?this._pc.getStats((n=>{if(this.destroyed)return;const r=[];n.result().forEach((t=>{const n={};t.names().forEach((e=>{n[e]=t.stat(e)})),n.id=t.id,n.type=t.type,n.timestamp=t.timestamp,r.push(e(n))})),t(null,r)}),(e=>t(e))):t(null,[])}_maybeReady(){if(this._debug("maybeReady pc %s channel %s",this._pcReady,this._channelReady),this._connected||this._connecting||!this._pcReady||!this._channelReady)return;this._connecting=!0;const t=()=>{this.destroyed||this.getStats(((e,n)=>{if(this.destroyed)return;e&&(n=[]);const r={},i={},s={};let o=!1;n.forEach((t=>{"remotecandidate"!==t.type&&"remote-candidate"!==t.type||(r[t.id]=t),"localcandidate"!==t.type&&"local-candidate"!==t.type||(i[t.id]=t),"candidatepair"!==t.type&&"candidate-pair"!==t.type||(s[t.id]=t)}));const a=t=>{o=!0;let e=i[t.localCandidateId];e&&(e.ip||e.address)?(this.localAddress=e.ip||e.address,this.localPort=Number(e.port)):e&&e.ipAddress?(this.localAddress=e.ipAddress,this.localPort=Number(e.portNumber)):"string"==typeof t.googLocalAddress&&(e=t.googLocalAddress.split(":"),this.localAddress=e[0],this.localPort=Number(e[1])),this.localAddress&&(this.localFamily=this.localAddress.includes(":")?"IPv6":"IPv4");let n=r[t.remoteCandidateId];n&&(n.ip||n.address)?(this.remoteAddress=n.ip||n.address,this.remotePort=Number(n.port)):n&&n.ipAddress?(this.remoteAddress=n.ipAddress,this.remotePort=Number(n.portNumber)):"string"==typeof t.googRemoteAddress&&(n=t.googRemoteAddress.split(":"),this.remoteAddress=n[0],this.remotePort=Number(n[1])),this.remoteAddress&&(this.remoteFamily=this.remoteAddress.includes(":")?"IPv6":"IPv4"),this._debug("connect local: %s:%s remote: %s:%s",this.localAddress,this.localPort,this.remoteAddress,this.remotePort)};if(n.forEach((t=>{"transport"===t.type&&t.selectedCandidatePairId&&a(s[t.selectedCandidatePairId]),("googCandidatePair"===t.type&&"true"===t.googActiveConnection||("candidatepair"===t.type||"candidate-pair"===t.type)&&t.selected)&&a(t)})),o||Object.keys(s).length&&!Object.keys(i).length){if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(e){return this.destroy(Zt(e,"ERR_DATA_CHANNEL"))}this._chunk=null,this._debug('sent chunk from "write before connect"');const t=this._cb;this._cb=null,t(null)}"number"!=typeof this._channel.bufferedAmountLowThreshold&&(this._interval=setInterval((()=>this._onInterval()),150),this._interval.unref&&this._interval.unref()),this._debug("connect"),this.emit("connect")}else setTimeout(t,100)}))};t()}_onInterval(){!this._cb||!this._channel||this._channel.bufferedAmount>65536||this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||("stable"===this._pc.signalingState&&(this._isNegotiating=!1,this._debug("flushing sender queue",this._sendersAwaitingStable),this._sendersAwaitingStable.forEach((t=>{this._pc.removeTrack(t),this._queuedNegotiation=!0})),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._debug("flushing negotiation queue"),this._queuedNegotiation=!1,this._needsNegotiation()):(this._debug("negotiated"),this.emit("negotiated"))),this._debug("signalingStateChange %s",this._pc.signalingState),this.emit("signalingStateChange",this._pc.signalingState))}_onIceCandidate(t){this.destroyed||(t.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:t.candidate.candidate,sdpMLineIndex:t.candidate.sdpMLineIndex,sdpMid:t.candidate.sdpMid}}):t.candidate||this._iceComplete||(this._iceComplete=!0,this.emit("_iceComplete")),t.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(t){if(this.destroyed)return;let e=t.data;e instanceof ArrayBuffer&&(e=new Uint8Array(e)),this.emit("data",e)}_onChannelBufferedAmountLow(){if(this.destroyed||!this._cb)return;this._debug("ending backpressure: bufferedAmount %d",this._channel.bufferedAmount);const t=this._cb;this._cb=null,t(null)}_onChannelOpen(){this._connected||this.destroyed||(this._debug("on channel open"),this._channelReady=!0,this._maybeReady())}_onChannelClose(){this.destroyed||(this._debug("on channel close"),this.destroy())}_onTrack(t){this.destroyed||t.streams.forEach((e=>{this._debug("on track"),this.emit("track",t.track,e),this._remoteTracks.push({track:t.track,stream:e}),this._remoteStreams.some((t=>t.id===e.id))||(this._remoteStreams.push(e),queueMicrotask((()=>{this._debug("on stream"),this.emit("stream",e)})))}))}_debug(...t){this._doDebug&&(t[0]="["+this._id+"] "+t[0])}on(t,e){const n=this._map;n.has(t)||n.set(t,new Set),n.get(t).add(e)}off(t,e){const n=this._map,r=n.get(t);r&&(r.delete(e),0===r.size&&n.delete(t))}once(t,e){const n=(...r)=>{this.off(t,n),e(...r)};this.on(t,n)}emit(t,...e){const n=this._map;if(n.has(t))for(const r of n.get(t))try{r(...e)}catch(t){console.error(t)}}}Wt.WEBRTC_SUPPORT=!!Kt(),Wt.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},Wt.channelConfig={};const Gt=(t,e,n)=>{const r=new Wt({initiator:t,trickle:e,config:n}),i=t=>r.__earlyDataBuffer.push(t);return r.on(ce.data,i),r.__earlyDataBuffer=[],r.__drainEarlyData=t=>{r.off(ce.data,i),r.__earlyDataBuffer.forEach(t),delete r.__earlyDataBuffer,delete r.__drainEarlyData},r},Jt=t=>Array(t).fill().map((()=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Math.floor(62*Math.random())])).join(""),Qt=Jt(20),{keys:Xt,values:te,entries:ee,fromEntries:ne}=Object,re=()=>{},ie=t=>Error(`Trystero: ${t}`),se=t=>(new TextEncoder).encode(t),oe=t=>(new TextDecoder).decode(t),ae=t=>t.reduce(((t,e)=>t+e.toString(16).padStart(2,"0")),""),ce=ne(["close","connect","data","error","signal","stream","track"].map((t=>[t,t]))),he=Object.getPrototypeOf(Uint8Array),de=16369,le=255,ue="bufferedamountlow",fe="AES-CBC",ge=async(t,e)=>{const n=crypto.getRandomValues(new Uint8Array(16));var r;return JSON.stringify({c:(r=await crypto.subtle.encrypt({name:fe,iv:n},await t,se(e)),btoa(String.fromCharCode.apply(null,new Uint8Array(r)))),iv:[...n]})},pe=async(t,e)=>{const{c:n,iv:r}=JSON.parse(e);return oe(await crypto.subtle.decrypt({name:fe,iv:new Uint8Array(r)},await t,(t=>{const e=atob(t);return new Uint8Array(e.length).map(((t,n)=>e.charCodeAt(n))).buffer})(n)))},ye={},me=ae(crypto.getRandomValues(new Uint8Array(32))),_e=ae(zt.getPublicKey(me)),be={},Ee=()=>Math.floor(Date.now()/1e3),we=["wss://relay.nostr.net","wss://relay.blackbyte.nl","wss://relay.piazza.today","wss://relay.exit.pub","wss://relay.nostr.band","wss://relay.damus.io","wss://nostr.mom","wss://relay.snort.social","wss://nostr.lu.ke","wss://relay.plebstr.com","wss://nostr.sathoarder.com","wss://nsrelay.assilvestrar.club","wss://nostrasia.casa","wss://relay.nostr.bg","wss://relay.nostrr.de","wss://relay.nostrss.re"],Re=(Ae=ye,(t,e)=>{if(Ae[e])return Ae[e];if(!t)throw ie("requires a config map as the first argument");if(!t.appId&&!t.firebaseApp)throw ie("config map is missing appId field");if(!e)throw ie("namespace argument required");return Ae[e]=((t,e)=>{const n=t.password&&(async(t,e)=>crypto.subtle.importKey("raw",await crypto.subtle.digest({name:"SHA-256"},se(`${t}:${e}`)),{name:fe},!1,["encrypt","decrypt"]))(t.password,e),r=`trystero/${t.appId}/${e}`,i=`${r}/${Qt}`,s=Jt(64),o=Jt(64),a={},c={},h={},d=((t,e,n)=>(t.relayUrls||e).slice(0,t.relayUrls?t.relayUrls.length:t.relayRedundancy||4))(t,we),l=(t,e)=>{y(t,e),h[e]=t},u=t=>{delete a[t],delete c[t],delete h[t]},f=(t,e)=>JSON.stringify(["REQ",t,{kinds:[29333],since:Ee(),"#x":[e]}]),g=t=>JSON.stringify(["CLOSE",t]),p=async(t,e)=>{const n={kind:29333,content:JSON.stringify(e),pubkey:_e,created_at:Ee(),tags:[["x",t]]},r=ae(new Uint8Array(await crypto.subtle.digest("SHA-256",se(JSON.stringify([0,n.pubkey,n.created_at,n.kind,n.tags,n.content])))));return JSON.stringify(["EVENT",{...n,id:r,sig:ae(await zt.sign(r,me))}])};let y=re;return d.forEach((e=>{const d=new WebSocket(e);be[e]=d,d.addEventListener("open",(async()=>{d.send(f(s,r)),d.send(f(o,i)),d.send(await p(r,Qt))})),d.addEventListener("message",(async e=>{const[i,f,g,y]=JSON.parse(e.data);if("EVENT"!==i)return void("OK"!==i||g||console.warn(`Trystero: relay failure from ${d.url} - ${y}`));const m=JSON.parse(g.content);if(f===s){const e=m;if(e!==Qt&&!h[e]&&!c[e]){c[e]=!0;const i=a[e]=Gt(!0,!1,t.rtcConfig);i.once(ce.signal,(async t=>{d.send(await p(`${r}/${e}`,{peerId:Qt,offer:n?{...t,sdp:await ge(n,t.sdp)}:t}))})),i.once(ce.connect,(()=>l(i,e))),i.once(ce.close,(()=>u(e)))}}else if(f===o){const{peerId:e,offer:i,answer:s}=m;if(a[e]&&s)return void a[e].signal(n?{...s,sdp:await pe(n,s.sdp)}:s);if(!i)return;const o=Gt(!1,!1,t.rtcConfig);o.once(ce.signal,(async t=>d.send(await p(`${r}/${e}`,{peerId:Qt,answer:n?{...t,sdp:await ge(n,t.sdp)}:t})))),o.once(ce.connect,(()=>l(o,e))),o.once(ce.close,(()=>u(e))),o.signal(i)}}))})),((t,e)=>{const n={},r={},i={},s={},o={},a={},c=(t,e)=>(t?Array.isArray(t)?t:[t]:Xt(n)).flatMap((t=>{const r=n[t];return r?e(t,r):(console.warn(`Trystero: no peer with id ${t} found`),[])})),h=t=>{if(r[t])return[r[t].send,r[t].setOnComplete,r[t].setOnProgress];if(!t)throw ie("action type argument is required");const e=se(t);if(e.byteLength>12)throw ie(`action type string "${t}" (${e.byteLength}b) exceeds byte limit (12). Hint: choose a shorter name.`);const i=new Uint8Array(12);i.set(e);let s=0;return r[t]={onComplete:re,onProgress:re,setOnComplete:e=>r[t]={...r[t],onComplete:e},setOnProgress:e=>r[t]={...r[t],onProgress:e},async send(t,e,r,o){if(r&&"object"!=typeof r)throw ie("action meta argument must be an object");if(void 0===t)throw ie("action data cannot be undefined");const a="string"!=typeof t,h=t instanceof Blob,d=h||t instanceof ArrayBuffer||t instanceof he;if(r&&!d)throw ie("action meta argument can only be used with binary data");const l=d?new Uint8Array(h?await t.arrayBuffer():t):se(a?JSON.stringify(t):t),u=r?se(JSON.stringify(r)):null,f=Math.ceil(l.byteLength/de)+(r?1:0)||1,g=Array(f).fill().map(((t,e)=>{const n=e===f-1,o=r&&0===e,c=new Uint8Array(15+(o?u.byteLength:n?l.byteLength-de*(f-(r?2:1)):de));return c.set(i),c.set([s],12),c.set([n|o<<1|d<<2|a<<3],13),c.set([Math.round((e+1)/f*le)],14),c.set(r?o?u:l.subarray((e-1)*de,e*de):l.subarray(e*de,(e+1)*de),15),c}));return s=s+1&le,Promise.all(c(e,(async(t,e)=>{const i=e._channel;let s=0;for(;s<f;){const a=g[s];if(i.bufferedAmount>i.bufferedAmountLowThreshold&&await new Promise((t=>{const e=()=>{i.removeEventListener(ue,e),t()};i.addEventListener(ue,e)})),!n[t])break;e.send(a),s++,o&&o(a[14]/le,t,r)}})))}},[r[t].send,r[t].setOnComplete,r[t].setOnProgress]},d=(t,e)=>{const n=new Uint8Array(e),s=oe(n.subarray(0,12)).replaceAll("\0",""),[o]=n.subarray(12,13),[a]=n.subarray(13,14),[c]=n.subarray(14,15),h=n.subarray(15),d=!!(1&a),l=!!(2&a),u=!!(4&a),f=!!(8&a);if(!r[s])throw ie(`received message with unregistered type (${s})`);i[t]||(i[t]={}),i[t][s]||(i[t][s]={});let g=i[t][s][o];if(g||(g=i[t][s][o]={chunks:[]}),l?g.meta=JSON.parse(oe(h)):g.chunks.push(h),r[s].onProgress(c/le,t,g.meta),!d)return;const p=new Uint8Array(g.chunks.reduce(((t,e)=>t+e.byteLength),0));if(g.chunks.reduce(((t,e)=>(p.set(e,t),t+e.byteLength)),0),u)r[s].onComplete(p,t,g.meta);else{const e=oe(p);r[s].onComplete(f?JSON.parse(e):e,t)}delete i[t][s][o]},[l,u]=h("__91n6__"),[f,g]=h("__90n6__"),[p,y]=h("__516n4L__"),[m,_]=h("__57r34m__"),[b,E]=h("__7r4ck__");let w=re,R=re,A=re,v=re;return t(((t,e)=>{if(n[e])return;const r=d.bind(null,e);n[e]=t,t.on(ce.signal,(t=>p(t,e))),t.on(ce.close,(()=>(t=>{n[t]&&(delete n[t],delete i[t],delete s[t],R(t))})(e))),t.on(ce.data,r),t.on(ce.stream,(t=>{A(t,e,o[e]),delete o[e]})),t.on(ce.track,((t,n)=>{v(t,n,e,a[e]),delete a[e]})),t.on(ce.error,(t=>{"ERR_DATA_CHANNEL"!==t.code&&console.error(t)})),w(e),t.__drainEarlyData(r)})),u(((t,e)=>f("",e))),g(((t,e)=>{s[e]&&(s[e](),delete s[e])})),y(((t,e)=>{n[e]&&n[e].signal(t)})),_(((t,e)=>o[e]=t)),E(((t,e)=>a[e]=t)),{makeAction:h,async ping(t){if(!t)throw ie("ping() must be called with target peer ID");const e=Date.now();return l("",t),await new Promise((e=>s[t]=e)),Date.now()-e},leave(){ee(n).forEach((([t,e])=>{e.destroy(),delete n[t]})),e()},getPeers:()=>ne(ee(n).map((([t,e])=>[t,e._pc]))),addStream:(t,e,n)=>c(e,(async(e,r)=>{n&&await m(n,e),r.addStream(t)})),removeStream:(t,e)=>c(e,((e,n)=>n.removeStream(t))),addTrack:(t,e,n,r)=>c(n,(async(n,i)=>{r&&await b(r,n),i.addTrack(t,e)})),removeTrack:(t,e,n)=>c(n,((n,r)=>r.removeTrack(t,e))),replaceTrack:(t,e,n,r,i)=>c(r,(async(r,s)=>{i&&await b(i,r),s.replaceTrack(t,e,n)})),onPeerJoin:t=>w=t,onPeerLeave:t=>R=t,onPeerStream:t=>A=t,onPeerTrack:t=>v=t}})((t=>y=t),(()=>{delete ye[e],te(be).forEach((t=>{t.send(g(s)),t.send(g(o))}))}))})(t,e)});var Ae}));
@@ -1 +0,0 @@
1
- ("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequirea18f.register("5lNoZ",(function(t,e){var n,r;function i(t){if(!Number.isSafeInteger(t)||t<0)throw Error("Wrong positive integer: "+t)}function s(t,...e){if(!((n=t)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw Error("Expected Uint8Array");var n;if(e.length>0&&!e.includes(t.length))throw Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(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")}n=t.exports,r=()=>Re,Object.defineProperty(n,"joinRoom",{get:r,set:undefined,enumerable:!0,configurable:!0});const a="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function c(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}const h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),d=(t,e)=>t<<32-e|t>>>e;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw Error("Non little-endian hardware is not supported");function l(t){if("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)),!c(t))throw Error("expected Uint8Array, got "+typeof t);return t}class u{clone(){return this._cloneInto()}}function f(t=32){if(a&&"function"==typeof a.getRandomValues)return a.getRandomValues(new Uint8Array(t));throw Error("crypto.getRandomValues must be defined")}class g extends u{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=h(this.buffer)}update(t){o(this);const{view:e,buffer:n,blockLen:r}=this,i=(t=l(t)).length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o!==r)n.set(t.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(e,0),this.pos=0);else{const e=h(t);for(;r<=i-s;s+=r)this.process(e,s)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){o(this),function(t,e){s(t);const n=e.outputLen;if(t.length<n)throw Error("digestInto() expects output buffer of length at least "+n)}(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:i}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(n,0),a=0);for(let t=a;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,h=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+h,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const c=h(t),d=this.outputLen;if(d%4)throw Error("_sha2: outputLen should be aligned to 32bit");const l=d/4,u=this.get();if(l>u.length)throw Error("_sha2: outputLen bigger than state");for(let t=0;t<l;t++)c.setUint32(4*t,u[t],i)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:s,pos:o}=this;return t.length=r,t.pos=o,t.finished=i,t.destroyed=s,r%e&&t.buffer.set(n),t}}const p=(t,e,n)=>t&e^t&n^e&n,y=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]),m=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_=new Uint32Array(64);class b extends g{constructor(){super(64,32,8,!1),this.A=0|m[0],this.B=0|m[1],this.C=0|m[2],this.D=0|m[3],this.E=0|m[4],this.F=0|m[5],this.G=0|m[6],this.H=0|m[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:s,G:o,H:a}=this;return[t,e,n,r,i,s,o,a]}set(t,e,n,r,i,s,o,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|o,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)_[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=_[t-15],n=_[t-2],r=d(e,7)^d(e,18)^e>>>3,i=d(n,17)^d(n,19)^n>>>10;_[t]=i+_[t-7]+r+_[t-16]|0}let{A:n,B:r,C:i,D:s,E:o,F:a,G:c,H:h}=this;for(let t=0;t<64;t++){const e=h+(d(o,6)^d(o,11)^d(o,25))+((l=o)&a^~l&c)+y[t]+_[t]|0,u=(d(n,2)^d(n,13)^d(n,22))+p(n,r,i)|0;h=c,c=a,a=o,o=s+e|0,s=i,i=r,r=n,n=e+u|0}var l;n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,o=o+this.E|0,a=a+this.F|0,c=c+this.G|0,h=h+this.H|0,this.set(n,r,i,s,o,a,c,h)}roundClean(){_.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const E=function(t){const e=e=>t().update(l(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}((()=>new b)),w=BigInt(0),R=BigInt(1),A=BigInt(2);function v(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}const S=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function T(t){if(!v(t))throw Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=S[t[n]];return e}function C(t){const e=t.toString(16);return 1&e.length?"0"+e:e}function B(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":"0x"+t)}const I=48,N=57,O=65,k=70,x=97,D=102;function L(t){return t>=I&&t<=N?t-I:t>=O&&t<=k?t-(O-10):t>=x&&t<=D?t-(x-10):void 0}function P(t){if("string"!=typeof t)throw Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let e=0,i=0;e<n;e++,i+=2){const n=L(t.charCodeAt(i)),s=L(t.charCodeAt(i+1));if(void 0===n||void 0===s){const e=t[i]+t[i+1];throw Error('hex string expected, got non-hex character "'+e+'" at index '+i)}r[e]=16*n+s}return r}function q(t){return B(T(t))}function U(t){if(!v(t))throw Error("Uint8Array expected");return B(T(Uint8Array.from(t).reverse()))}function H(t,e){return P(t.toString(16).padStart(2*e,"0"))}function $(t,e){return H(t,e).reverse()}function F(t,e,n){let r;if("string"==typeof e)try{r=P(e)}catch(n){throw Error(`${t} must be valid hex string, got "${e}". Cause: ${n}`)}else{if(!v(e))throw Error(t+" must be hex string or Uint8Array");r=Uint8Array.from(e)}const i=r.length;if("number"==typeof n&&i!==n)throw Error(`${t} expected ${n} bytes, got ${i}`);return r}function M(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];if(!v(r))throw Error("Uint8Array expected");e+=r.length}let n=new Uint8Array(e),r=0;for(let e=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}const j=t=>(A<<BigInt(t-1))-R,z=t=>new Uint8Array(t),V=t=>Uint8Array.from(t);function K(t,e,n){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 n)throw Error("hmacFn must be a function");let r=z(t),i=z(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...t)=>n(i,r,...t),c=(t=z())=>{i=a(V([0]),t),r=a(),0!==t.length&&(i=a(V([1]),t),r=a())},h=()=>{if(s++>=1e3)throw Error("drbg: tried 1000 values");let t=0;const n=[];for(;t<e;){r=a();const e=r.slice();n.push(e),t+=r.length}return M(...n)};return(t,e)=>{let n;for(o(),c(t);!(n=e(h()));)c();return o(),n}}const Z={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||v(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 Y(t,e,n={}){const r=(e,n,r)=>{const i=Z[n];if("function"!=typeof i)throw Error(`Invalid validator "${n}", expected function`);const s=t[e];if(!(r&&void 0===s||i(s,t)))throw Error(`Invalid param ${e+""}=${s} (${typeof s}), expected ${n}`)};for(const[t,n]of Object.entries(e))r(t,n,!1);for(const[t,e]of Object.entries(n))r(t,e,!0);return t}var W=Object.freeze({__proto__:null,bitGet:(t,e)=>t>>BigInt(e)&R,bitLen(t){let e;for(e=0;t>w;t>>=R,e+=1);return e},bitMask:j,bitSet:(t,e,n)=>t|(n?R:w)<<BigInt(e),bytesToHex:T,bytesToNumberBE:q,bytesToNumberLE:U,concatBytes:M,createHmacDrbg:K,ensureBytes:F,equalBytes(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return 0===n},hexToBytes:P,hexToNumber:B,isBytes:v,numberToBytesBE:H,numberToBytesLE:$,numberToHexUnpadded:C,numberToVarBytesBE:t=>P(C(t)),utf8ToBytes(t){if("string"!=typeof t)throw Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))},validateObject:Y});const G=BigInt(0),J=BigInt(1),Q=BigInt(2),X=BigInt(3),tt=BigInt(4),et=BigInt(5),nt=BigInt(8);function rt(t,e){const n=t%e;return n>=G?n:e+n}function it(t,e,n){if(n<=G||e<G)throw Error("Expected power/modulo > 0");if(n===J)return G;let r=J;for(;e>G;)e&J&&(r=r*t%n),t=t*t%n,e>>=J;return r}function st(t,e,n){let r=t;for(;e-- >G;)r*=r,r%=n;return r}function ot(t,e){if(t===G||e<=G)throw Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=rt(t,e),r=e,i=G,s=J;for(;n!==G;){const t=r%n,e=i-s*(r/n);r=n,n=t,i=s,s=e}if(r!==J)throw Error("invert: does not exist");return rt(i,e)}BigInt(9),BigInt(16);const at=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ct(t,e){const n=void 0!==e?e:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function ht(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=ht(t);return e+Math.ceil(e/2)}const lt=BigInt(0),ut=BigInt(1);function ft(t){return Y(t.Fp,at.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),Y(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ct(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const{bytesToNumberBE:gt,hexToBytes:pt}=W,yt={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){const{Err:e}=yt;if(t.length<2||2!==t[0])throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(128&r[0])throw new e("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new e("Invalid signature integer: unnecessary leading zero");return{d:gt(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=yt,n="string"==typeof t?pt(t):t;if(!v(n))throw Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:i,l:s}=yt._parseInt(n.subarray(2)),{d:o,l:a}=yt._parseInt(s);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(t){const e=t=>8&Number.parseInt(t[0],16)?"00"+t:t,n=t=>{const e=t.toString(16);return 1&e.length?"0"+e:e},r=e(n(t.s)),i=e(n(t.r)),s=r.length/2,o=i.length/2,a=n(s),c=n(o);return`30${n(o+s+4)}02${c}${i}02${a}${r}`}},mt=BigInt(0),_t=BigInt(1);BigInt(2);const bt=BigInt(3);BigInt(4);class Et extends u{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");i(t.outputLen),i(t.blockLen)}(t);const n=l(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 r=this.blockLen,s=new Uint8Array(r);s.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<s.length;t++)s[t]^=54;this.iHash.update(s),this.oHash=t.create();for(let t=0;t<s.length;t++)s[t]^=106;this.oHash.update(s),s.fill(0)}update(t){return o(this),this.iHash.update(t),this}digestInto(t){o(this),s(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:n,finished:r,destroyed:i,blockLen:s,outputLen:o}=this;return t.finished=r,t.destroyed=i,t.blockLen=s,t.outputLen=o,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const wt=(t,e,n)=>new Et(t,e).update(n).digest();function Rt(t){return{hash:t,hmac:(e,...n)=>wt(t,e,function(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];if(!c(r))throw Error("Uint8Array expected");e+=r.length}const n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}(...n)),randomBytes:f}}wt.create=(t,e)=>new Et(t,e);const At=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),St=BigInt(1),Tt=BigInt(2),Ct=(t,e)=>(t+e/Tt)/e;function Bt(t){const e=At,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),h=t*t*t%e,d=h*h*t%e,l=st(d,n,e)*d%e,u=st(l,n,e)*d%e,f=st(u,Tt,e)*h%e,g=st(f,i,e)*f%e,p=st(g,s,e)*g%e,y=st(p,a,e)*p%e,m=st(y,c,e)*y%e,_=st(m,a,e)*p%e,b=st(_,n,e)*d%e,E=st(b,o,e)*g%e,w=st(E,r,e)*h%e,R=st(w,Tt,e);if(!It.eql(It.sqr(R),t))throw Error("Cannot find square root");return R}const It=function(t,e,n=!1,r={}){if(t<=G)throw Error("Expected Field ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=ct(t,e);if(s>2048)throw Error("Field lengths over 2048 bytes are not supported");const o=function(t){if(t%tt===X){const e=(t+J)/tt;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw Error("Cannot find square root");return r}}if(t%nt===et){const e=(t-et)/nt;return function(t,n){const r=t.mul(n,Q),i=t.pow(r,e),s=t.mul(n,i),o=t.mul(t.mul(s,Q),i),a=t.mul(s,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),n))throw Error("Cannot find square root");return a}}return function(t){const e=(t-J)/Q;let n,r,i;for(n=t-J,r=0;n%Q===G;n/=Q,r++);for(i=Q;i<t&&it(i,e,t)!==t-J;i++);if(1===r){const e=(t+J)/tt;return(t,n)=>{const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw Error("Cannot find square root");return r}}const s=(n+J)/Q;return(t,o)=>{if(t.pow(o,e)===t.neg(t.ONE))throw Error("Cannot find square root");let a=r,c=t.pow(t.mul(t.ONE,i),n),h=t.pow(o,s),d=t.pow(o,n);for(;!t.eql(d,t.ONE);){if(t.eql(d,t.ZERO))return t.ZERO;let e=1;for(let n=t.sqr(d);e<a&&!t.eql(n,t.ONE);e++)n=t.sqr(n);const n=t.pow(c,J<<BigInt(a-e-1));c=t.sqr(n),h=t.mul(h,n),d=t.mul(d,c),a=e}return h}}(t)}(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:s,MASK:j(i),ZERO:G,ONE:J,create:e=>rt(e,t),isValid(e){if("bigint"!=typeof e)throw Error("Invalid field element: expected bigint, got "+typeof e);return G<=e&&e<t},is0:t=>t===G,isOdd:t=>(t&J)===J,neg:e=>rt(-e,t),eql:(t,e)=>t===e,sqr:e=>rt(e*e,t),add:(e,n)=>rt(e+n,t),sub:(e,n)=>rt(e-n,t),mul:(e,n)=>rt(e*n,t),pow:(t,e)=>function(t,e,n){if(n<G)throw Error("Expected power > 0");if(n===G)return t.ONE;if(n===J)return e;let r=t.ONE,i=e;for(;n>G;)n&J&&(r=t.mul(r,i)),i=t.sqr(i),n>>=J;return r}(a,t,e),div:(e,n)=>rt(e*ot(n,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>ot(e,t),sqrt:r.sqrt||(t=>o(a,t)),invertBatch:t=>function(t,e){const n=Array(e.length),r=e.reduce(((e,r,i)=>t.is0(r)?e:(n[i]=e,t.mul(e,r))),t.ONE),i=t.inv(r);return e.reduceRight(((e,r,i)=>t.is0(r)?e:(n[i]=t.mul(e,n[i]),t.mul(e,r))),i),n}(a,t),cmov:(t,e,n)=>n?e:t,toBytes:t=>n?$(t,s):H(t,s),fromBytes(t){if(t.length!==s)throw Error(`Fp.fromBytes: expected ${s}, got ${t.length}`);return n?U(t):q(t)}});return Object.freeze(a)}(At,void 0,void 0,{sqrt:Bt}),Nt=function(t,e){const n=e=>function(t){const e=function(t){const e=ft(t);return Y(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}(t),{Fp:n,n:r}=e,i=n.BYTES+1,s=2*n.BYTES+1;function o(t){return rt(t,r)}function a(t){return ot(t,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:h,weierstrassEquation:d,isWithinCurveOrder:l}=function(t){const e=function(t){const e=ft(t);Y(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=e;if(n){if(!r.eql(i,r.ZERO))throw Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}(t),{Fp:n}=e,r=e.toBytes||((t,e)=>{const r=e.toAffine();return M(Uint8Array.from([4]),n.toBytes(r.x),n.toBytes(r.y))}),i=e.fromBytes||(t=>{const e=t.subarray(1);return{x:n.fromBytes(e.subarray(0,n.BYTES)),y:n.fromBytes(e.subarray(n.BYTES,2*n.BYTES))}});function s(t){const{a:r,b:i}=e,s=n.sqr(t),o=n.mul(s,t);return n.add(n.add(o,n.mul(t,r)),i)}if(!n.eql(n.sqr(e.Gy),s(e.Gx)))throw Error("bad generator point: equation left != right");function o(t){return"bigint"==typeof t&&mt<t&&t<e.n}function a(t){if(!o(t))throw Error("Expected valid bigint: 0 < bigint < curve.n")}function c(t){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:s}=e;if(n&&"bigint"!=typeof t){if(v(t)&&(t=T(t)),"string"!=typeof t||!n.includes(t.length))throw Error("Invalid key");t=t.padStart(2*r,"0")}let o;try{o="bigint"==typeof t?t:q(F("private key",t,r))}catch(e){throw Error(`private key must be ${r} bytes, hex or bigint, not ${typeof t}`)}return i&&(o=rt(o,s)),a(o),o}const h=new Map;function d(t){if(!(t instanceof l))throw Error("ProjectivePoint expected")}class l{constructor(t,e,r){if(this.px=t,this.py=e,this.pz=r,null==t||!n.isValid(t))throw Error("x required");if(null==e||!n.isValid(e))throw Error("y required");if(null==r||!n.isValid(r))throw Error("z required")}static fromAffine(t){const{x:e,y:r}=t||{};if(!t||!n.isValid(e)||!n.isValid(r))throw Error("invalid affine point");if(t instanceof l)throw Error("projective point not allowed");const i=t=>n.eql(t,n.ZERO);return i(e)&&i(r)?l.ZERO:new l(e,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(l.fromAffine)}static fromHex(t){const e=l.fromAffine(i(F("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return l.BASE.multiply(c(t))}_setWindowSize(t){this._WINDOW_SIZE=t,h.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw Error("bad point: ZERO")}const{x:t,y:r}=this.toAffine();if(!n.isValid(t)||!n.isValid(r))throw Error("bad point: x or y not FE");const i=n.sqr(r),o=s(t);if(!n.eql(i,o))throw Error("bad point: equation left != right");if(!this.isTorsionFree())throw Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:t}=this.toAffine();if(n.isOdd)return!n.isOdd(t);throw Error("Field doesn't support isOdd")}equals(t){d(t);const{px:e,py:r,pz:i}=this,{px:s,py:o,pz:a}=t,c=n.eql(n.mul(e,a),n.mul(s,i)),h=n.eql(n.mul(r,a),n.mul(o,i));return c&&h}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:t,b:r}=e,i=n.mul(r,bt),{px:s,py:o,pz:a}=this;let c=n.ZERO,h=n.ZERO,d=n.ZERO,u=n.mul(s,s),f=n.mul(o,o),g=n.mul(a,a),p=n.mul(s,o);return p=n.add(p,p),d=n.mul(s,a),d=n.add(d,d),c=n.mul(t,d),h=n.mul(i,g),h=n.add(c,h),c=n.sub(f,h),h=n.add(f,h),h=n.mul(c,h),c=n.mul(p,c),d=n.mul(i,d),g=n.mul(t,g),p=n.sub(u,g),p=n.mul(t,p),p=n.add(p,d),d=n.add(u,u),u=n.add(d,u),u=n.add(u,g),u=n.mul(u,p),h=n.add(h,u),g=n.mul(o,a),g=n.add(g,g),u=n.mul(g,p),c=n.sub(c,u),d=n.mul(g,f),d=n.add(d,d),d=n.add(d,d),new l(c,h,d)}add(t){d(t);const{px:r,py:i,pz:s}=this,{px:o,py:a,pz:c}=t;let h=n.ZERO,u=n.ZERO,f=n.ZERO;const g=e.a,p=n.mul(e.b,bt);let y=n.mul(r,o),m=n.mul(i,a),_=n.mul(s,c),b=n.add(r,i),E=n.add(o,a);b=n.mul(b,E),E=n.add(y,m),b=n.sub(b,E),E=n.add(r,s);let w=n.add(o,c);return E=n.mul(E,w),w=n.add(y,_),E=n.sub(E,w),w=n.add(i,s),h=n.add(a,c),w=n.mul(w,h),h=n.add(m,_),w=n.sub(w,h),f=n.mul(g,E),h=n.mul(p,_),f=n.add(h,f),h=n.sub(m,f),f=n.add(m,f),u=n.mul(h,f),m=n.add(y,y),m=n.add(m,y),_=n.mul(g,_),E=n.mul(p,E),m=n.add(m,_),_=n.sub(y,_),_=n.mul(g,_),E=n.add(E,_),y=n.mul(m,E),u=n.add(u,y),y=n.mul(w,E),h=n.mul(b,h),h=n.sub(h,y),y=n.mul(b,m),f=n.mul(w,f),f=n.add(f,y),new l(h,u,f)}subtract(t){return this.add(t.negate())}is0(){return this.equals(l.ZERO)}wNAF(t){return f.wNAFCached(this,h,t,(t=>{const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(l.fromAffine)}))}multiplyUnsafe(t){const r=l.ZERO;if(t===mt)return r;if(a(t),t===_t)return this;const{endo:i}=e;if(!i)return f.unsafeLadder(this,t);let{k1neg:s,k1:o,k2neg:c,k2:h}=i.splitScalar(t),d=r,u=r,g=this;for(;o>mt||h>mt;)o&_t&&(d=d.add(g)),h&_t&&(u=u.add(g)),g=g.double(),o>>=_t,h>>=_t;return s&&(d=d.negate()),c&&(u=u.negate()),u=new l(n.mul(u.px,i.beta),u.py,u.pz),d.add(u)}multiply(t){a(t);let r,i,s=t;const{endo:o}=e;if(o){const{k1neg:t,k1:e,k2neg:a,k2:c}=o.splitScalar(s);let{p:h,f:d}=this.wNAF(e),{p:u,f:g}=this.wNAF(c);h=f.constTimeNegate(t,h),u=f.constTimeNegate(a,u),u=new l(n.mul(u.px,o.beta),u.py,u.pz),r=h.add(u),i=d.add(g)}else{const{p:t,f:e}=this.wNAF(s);r=t,i=e}return l.normalizeZ([r,i])[0]}multiplyAndAddUnsafe(t,e,n){const r=l.BASE,i=(t,e)=>e!==mt&&e!==_t&&t.equals(r)?t.multiply(e):t.multiplyUnsafe(e),s=i(this,e).add(i(t,n));return s.is0()?void 0:s}toAffine(t){const{px:e,py:r,pz:i}=this,s=this.is0();null==t&&(t=s?n.ONE:n.inv(i));const o=n.mul(e,t),a=n.mul(r,t),c=n.mul(i,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw Error("invZ was invalid");return{x:o,y:a}}isTorsionFree(){const{h:t,isTorsionFree:n}=e;if(t===_t)return!0;if(n)return n(l,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:n}=e;return t===_t?this:n?n(l,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return this.assertValidity(),r(l,this,t)}toHex(t=!0){return T(this.toRawBytes(t))}}l.BASE=new l(e.Gx,e.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const u=e.nBitLength,f=function(t,e){const n=(t,e)=>{const n=e.negate();return t?n:e},r=t=>({windows:Math.ceil(e/t)+1,windowSize:2**(t-1)});return{constTimeNegate:n,unsafeLadder(e,n){let r=t.ZERO,i=e;for(;n>lt;)n&ut&&(r=r.add(i)),i=i.double(),n>>=ut;return r},precomputeWindow(t,e){const{windows:n,windowSize:i}=r(e),s=[];let o=t,a=o;for(let t=0;t<n;t++){a=o,s.push(a);for(let t=1;t<i;t++)a=a.add(o),s.push(a);o=a.double()}return s},wNAF(e,i,s){const{windows:o,windowSize:a}=r(e);let c=t.ZERO,h=t.BASE;const d=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let t=0;t<o;t++){const e=t*a;let r=Number(s&d);s>>=u,r>a&&(r-=l,s+=ut);const o=e,f=e+Math.abs(r)-1,g=t%2!=0,p=r<0;0===r?h=h.add(n(g,i[o])):c=c.add(n(p,i[f]))}return{p:c,f:h}},wNAFCached(t,e,n,r){const i=t._WINDOW_SIZE||1;let s=e.get(t);return s||(s=this.precomputeWindow(t,i),1!==i&&e.set(t,r(s))),this.wNAF(i,s,n)}}}(l,e.endo?Math.ceil(u/2):u);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:o}}({...e,toBytes(t,e,r){const i=e.toAffine(),s=n.toBytes(i.x),o=M;return r?o(Uint8Array.from([e.hasEvenY()?2:3]),s):o(Uint8Array.from([4]),s,n.toBytes(i.y))},fromBytes(t){const e=t.length,r=t[0],o=t.subarray(1);if(e!==i||2!==r&&3!==r){if(e===s&&4===r)return{x:n.fromBytes(o.subarray(0,n.BYTES)),y:n.fromBytes(o.subarray(n.BYTES,2*n.BYTES))};throw Error(`Point of length ${e} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}{const t=q(o);if(!(mt<(a=t)&&a<n.ORDER))throw Error("Point is not on curve");const e=d(t);let i=n.sqrt(e);return 1==(1&r)!=((i&_t)===_t)&&(i=n.neg(i)),{x:t,y:i}}var a}}),u=t=>T(H(t,e.nByteLength));function f(t){return t>r>>_t}const g=(t,e,n)=>q(t.slice(e,n));class p{constructor(t,e,n){this.r=t,this.s=e,this.recovery=n,this.assertValidity()}static fromCompact(t){const n=e.nByteLength;return t=F("compactSignature",t,2*n),new p(g(t,0,n),g(t,n,2*n))}static fromDER(t){const{r:e,s:n}=yt.toSig(F("DER",t));return new p(e,n)}assertValidity(){if(!l(this.r))throw Error("r must be 0 < r < CURVE.n");if(!l(this.s))throw Error("s must be 0 < s < CURVE.n")}addRecoveryBit(t){return new p(this.r,this.s,t)}recoverPublicKey(t){const{r:r,s:i,recovery:s}=this,h=b(F("msgHash",t));if(null==s||![0,1,2,3].includes(s))throw Error("recovery id invalid");const d=2===s||3===s?r+e.n:r;if(d>=n.ORDER)throw Error("recovery id 2 or 3 invalid");const l=0==(1&s)?"02":"03",f=c.fromHex(l+u(d)),g=a(d),p=o(-h*g),y=o(i*g),m=c.BASE.multiplyAndAddUnsafe(f,p,y);if(!m)throw Error("point at infinify");return m.assertValidity(),m}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return P(this.toDERHex())}toDERHex(){return yt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return P(this.toCompactHex())}toCompactHex(){return u(this.r)+u(this.s)}}const y={isValidPrivateKey(t){try{return h(t),!0}catch(t){return!1}},normPrivateKeyToScalar:h,randomPrivateKey(){const t=dt(e.n);return function(t,e,n=!1){const r=t.length,i=ht(e),s=dt(e);if(r<16||r<s||r>1024)throw Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=rt(n?q(t):U(t),e-J)+J;return n?$(o,i):H(o,i)}(e.randomBytes(t),e.n)},precompute:(t=8,e=c.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function m(t){const e=v(t),n="string"==typeof t,r=(e||n)&&t.length;return e?r===i||r===s:n?r===2*i||r===2*s:t instanceof c}const _=e.bits2int||(t=>{const n=q(t),r=8*t.length-e.nBitLength;return r>0?n>>BigInt(r):n}),b=e.bits2int_modN||(t=>o(_(t))),E=j(e.nBitLength);function w(t){if("bigint"!=typeof t)throw Error("bigint expected");if(!(mt<=t&&t<E))throw Error("bigint expected < 2^"+e.nBitLength);return H(t,e.nByteLength)}function R(t,r,i=A){if(["recovered","canonical"].some((t=>t in i)))throw Error("sign() legacy options not supported");const{hash:s,randomBytes:d}=e;let{lowS:u,prehash:g,extraEntropy:y}=i;null==u&&(u=!0),t=F("msgHash",t),g&&(t=F("prehashed msgHash",s(t)));const m=b(t),E=h(r),R=[w(E),w(m)];if(null!=y){const t=!0===y?d(n.BYTES):y;R.push(F("extraEntropy",t))}const v=M(...R),S=m;return{seed:v,k2sig(t){const e=_(t);if(!l(e))return;const n=a(e),r=c.BASE.multiply(e).toAffine(),i=o(r.x);if(i===mt)return;const s=o(n*o(S+i*E));if(s===mt)return;let h=(r.x===i?0:2)|Number(r.y&_t),d=s;return u&&f(s)&&(d=function(t){return f(t)?o(-t):t}(s),h^=1),new p(i,d,h)}}}const A={lowS:e.lowS,prehash:!1},S={lowS:e.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:e,getPublicKey:(t,e=!0)=>c.fromPrivateKey(t).toRawBytes(e),getSharedSecret(t,e,n=!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(h(t)).toRawBytes(n)},sign(t,n,r=A){const{seed:i,k2sig:s}=R(t,n,r),o=e;return K(o.hash.outputLen,o.nByteLength,o.hmac)(i,s)},verify(t,n,r,i=S){const s=t;if(n=F("msgHash",n),r=F("publicKey",r),"strict"in i)throw Error("options.strict was renamed to lowS");const{lowS:h,prehash:d}=i;let l,u;try{if("string"==typeof s||v(s))try{l=p.fromDER(s)}catch(t){if(!(t instanceof yt.Err))throw t;l=p.fromCompact(s)}else{if("object"!=typeof s||"bigint"!=typeof s.r||"bigint"!=typeof s.s)throw Error("PARSE");{const{r:t,s:e}=s;l=new p(t,e)}}u=c.fromHex(r)}catch(t){if("PARSE"===t.message)throw Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(h&&l.hasHighS())return!1;d&&(n=e.hash(n));const{r:f,s:g}=l,y=b(n),m=a(g),_=o(y*m),E=o(f*m),w=c.BASE.multiplyAndAddUnsafe(u,_,E)?.toAffine();return!!w&&o(w.x)===f},ProjectivePoint:c,Signature:p,utils:y}}({...t,...Rt(e)});return Object.freeze({...n(e),create:n})}({a:BigInt(0),b:BigInt(7),Fp:It,n:vt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const e=vt,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-St*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=Ct(s*t,e),c=Ct(-r*t,e);let h=rt(t-a*n-c*i,e),d=rt(-a*r-c*s,e);const l=h>o,u=d>o;if(l&&(h=e-h),u&&(d=e-d),h>o||d>o)throw Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:h,k2neg:u,k2:d}}}},E),Ot=BigInt(0),kt=t=>"bigint"==typeof t&&Ot<t&&t<At,xt={};function Dt(t,...e){let n=xt[t];if(void 0===n){const e=E(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=M(e,e),xt[t]=n}return E(M(n,...e))}const Lt=t=>t.toRawBytes(!0).slice(1),Pt=t=>H(t,32),qt=t=>rt(t,At),Ut=t=>rt(t,vt),Ht=Nt.ProjectivePoint;function $t(t){let e=Nt.utils.normPrivateKeyToScalar(t),n=Ht.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:Ut(-e),bytes:Lt(n)}}function Ft(t){if(!kt(t))throw Error("bad x: need 0 < x < p");const e=qt(t*t);let n=Bt(qt(e*t+BigInt(7)));n%Tt!==Ot&&(n=qt(-n));const r=new Ht(t,n,St);return r.assertValidity(),r}function Mt(...t){return Ut(q(Dt("BIP0340/challenge",...t)))}function jt(t,e,n){const r=F("signature",t,64),i=F("message",e),s=F("publicKey",n,32);try{const t=Ft(q(s)),e=q(r.subarray(0,32));if(!kt(e))return!1;const n=q(r.subarray(32,64));if(!(t=>"bigint"==typeof t&&Ot<t&&t<vt)(n))return!1;const o=Mt(Pt(e),Lt(t),i),a=((t,e,n)=>Ht.BASE.multiplyAndAddUnsafe(t,e,n))(t,n,Ut(-o));return!(!a||!a.hasEvenY()||a.toAffine().x!==e)}catch(t){return!1}}const zt={getPublicKey:function(t){return $t(t).bytes},sign:function(t,e,n=f(32)){const r=F("message",t),{bytes:i,scalar:s}=$t(e),o=F("auxRand",n,32),a=Pt(s^q(Dt("BIP0340/aux",o))),c=Dt("BIP0340/nonce",a,i,r),h=Ut(q(c));if(h===Ot)throw Error("sign failed: k is zero");const{bytes:d,scalar:l}=$t(h),u=Mt(d,i,r),g=new Uint8Array(64);if(g.set(d,0),g.set(Pt(Ut(l+u*s)),32),!jt(g,r,i))throw Error("sign: Invalid signature produced");return g},verify:jt,utils:{randomPrivateKey:Nt.utils.randomPrivateKey,lift_x:Ft,pointToBytes:Lt,numberToBytesBE:H,bytesToNumberBE:q,taggedHash:Dt,mod:rt}};function Vt(t){const e=new Uint8Array(t);for(let n=0;n<t;n++)e[n]=256*Math.random()|0;return e}function Kt(){if("undefined"==typeof globalThis)return null;const t={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return t.RTCPeerConnection?t:null}function Zt(t,e){return Object.defineProperty(t,"code",{value:e,enumerable:!0,configurable:!0}),t}function Yt(t){return t.replace(/a=ice-options:trickle\s\n/g,"")}class Wt{constructor(t={}){if(this._map=new Map,this._id=Vt(4).toString("hex").slice(0,7),this._doDebug=t.debug,this._debug("new peer %o",t),this.channelName=t.initiator?t.channelName||Vt(20).toString("hex"):null,this.initiator=t.initiator||!1,this.channelConfig=t.channelConfig||Wt.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},Wt.config,t.config),this.offerOptions=t.offerOptions||{},this.answerOptions=t.answerOptions||{},this.sdpTransform=t.sdpTransform||(t=>t),this.streams=t.streams||(t.stream?[t.stream]:[]),this.trickle=void 0===t.trickle||t.trickle,this.allowHalfTrickle=void 0!==t.allowHalfTrickle&&t.allowHalfTrickle,this.iceCompleteTimeout=t.iceCompleteTimeout||5e3,this.destroyed=!1,this.destroying=!1,this._connected=!1,this.remoteAddress=void 0,this.remoteFamily=void 0,this.remotePort=void 0,this.localAddress=void 0,this.localFamily=void 0,this.localPort=void 0,this._wrtc=t.wrtc&&"object"==typeof t.wrtc?t.wrtc:Kt(),!this._wrtc)throw"undefined"==typeof window?Zt(Error("No WebRTC support: Specify `opts.wrtc` option in this environment"),"ERR_WEBRTC_SUPPORT"):Zt(Error("No WebRTC support: Not a supported browser"),"ERR_WEBRTC_SUPPORT");this._pcReady=!1,this._channelReady=!1,this._iceComplete=!1,this._iceCompleteTimer=null,this._channel=null,this._pendingCandidates=[],this._isNegotiating=!1,this._firstNegotiation=!0,this._batchedNegotiation=!1,this._queuedNegotiation=!1,this._sendersAwaitingStable=[],this._senderMap=new Map,this._closingInterval=null,this._remoteTracks=[],this._remoteStreams=[],this._chunk=null,this._cb=null,this._interval=null;try{this._pc=new this._wrtc.RTCPeerConnection(this.config)}catch(t){return void this.destroy(Zt(t,"ERR_PC_CONSTRUCTOR"))}this._isReactNativeWebrtc="number"==typeof this._pc._peerConnectionId,this._pc.oniceconnectionstatechange=()=>{this._onIceStateChange()},this._pc.onicegatheringstatechange=()=>{this._onIceStateChange()},this._pc.onconnectionstatechange=()=>{this._onConnectionStateChange()},this._pc.onsignalingstatechange=()=>{this._onSignalingStateChange()},this._pc.onicecandidate=t=>{this._onIceCandidate(t)},"object"==typeof this._pc.peerIdentity&&this._pc.peerIdentity.catch((t=>{this.destroy(Zt(t,"ERR_PC_PEER_IDENTITY"))})),this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=t=>{this._setupData(t)},this.streams&&this.streams.forEach((t=>{this.addStream(t)})),this._pc.ontrack=t=>{this._onTrack(t)},this._debug("initial negotiation"),this._needsNegotiation()}get bufferSize(){return this._channel&&this._channel.bufferedAmount||0}get connected(){return this._connected&&"open"===this._channel.readyState}address(){return{port:this.localPort,family:this.localFamily,address:this.localAddress}}signal(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot signal after peer is destroyed"),"ERR_DESTROYED");if("string"==typeof t)try{t=JSON.parse(t)}catch(e){t={}}this._debug("signal()"),t.renegotiate&&this.initiator&&(this._debug("got request to renegotiate"),this._needsNegotiation()),t.transceiverRequest&&this.initiator&&(this._debug("got request for transceiver"),this.addTransceiver(t.transceiverRequest.kind,t.transceiverRequest.init)),t.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(t.candidate):this._pendingCandidates.push(t.candidate)),t.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(t)).then((()=>{this.destroyed||(this._pendingCandidates.forEach((t=>{this._addIceCandidate(t)})),this._pendingCandidates=[],"offer"===this._pc.remoteDescription.type&&this._createAnswer())})).catch((t=>{this.destroy(Zt(t,"ERR_SET_REMOTE_DESCRIPTION"))})),t.sdp||t.candidate||t.renegotiate||t.transceiverRequest||this.destroy(Zt(Error("signal() called with invalid signal data"),"ERR_SIGNALING"))}}_addIceCandidate(t){const e=new this._wrtc.RTCIceCandidate(t);this._pc.addIceCandidate(e).catch((t=>{!e.address||e.address.endsWith(".local")?console.warn("Ignoring unsupported ICE candidate."):this.destroy(Zt(t,"ERR_ADD_ICE_CANDIDATE"))}))}send(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot send after peer is destroyed"),"ERR_DESTROYED");this._channel.send(t)}}addTransceiver(t,e){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot addTransceiver after peer is destroyed"),"ERR_DESTROYED");if(this._debug("addTransceiver()"),this.initiator)try{this._pc.addTransceiver(t,e),this._needsNegotiation()}catch(t){this.destroy(Zt(t,"ERR_ADD_TRANSCEIVER"))}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:t,init:e}})}}addStream(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot addStream after peer is destroyed"),"ERR_DESTROYED");this._debug("addStream()"),t.getTracks().forEach((e=>{this.addTrack(e,t)}))}}addTrack(t,e){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot addTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("addTrack()");const n=this._senderMap.get(t)||new Map;let r=n.get(e);if(r)throw r.removed?Zt(Error("Track has been removed. You should enable/disable tracks that you want to re-add."),"ERR_SENDER_REMOVED"):Zt(Error("Track has already been added to that stream."),"ERR_SENDER_ALREADY_ADDED");r=this._pc.addTrack(t,e),n.set(e,r),this._senderMap.set(t,n),this._needsNegotiation()}replaceTrack(t,e,n){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot replaceTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("replaceTrack()");const r=this._senderMap.get(t),i=r?r.get(n):null;if(!i)throw Zt(Error("Cannot replace track that was never added."),"ERR_TRACK_NOT_ADDED");e&&this._senderMap.set(e,r),null!=i.replaceTrack?i.replaceTrack(e):this.destroy(Zt(Error("replaceTrack is not supported in this browser"),"ERR_UNSUPPORTED_REPLACETRACK"))}removeTrack(t,e){if(this.destroying)return;if(this.destroyed)throw Zt(Error("cannot removeTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSender()");const n=this._senderMap.get(t),r=n?n.get(e):null;if(!r)throw Zt(Error("Cannot remove track that was never added."),"ERR_TRACK_NOT_ADDED");try{r.removed=!0,this._pc.removeTrack(r)}catch(t){"NS_ERROR_UNEXPECTED"===t.name?this._sendersAwaitingStable.push(r):this.destroy(Zt(t,"ERR_REMOVE_TRACK"))}this._needsNegotiation()}removeStream(t){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot removeStream after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSenders()"),t.getTracks().forEach((e=>{this.removeTrack(e,t)}))}}_needsNegotiation(){this._debug("_needsNegotiation"),this._batchedNegotiation||(this._batchedNegotiation=!0,queueMicrotask((()=>{this._batchedNegotiation=!1,this.initiator||!this._firstNegotiation?(this._debug("starting batched negotiation"),this.negotiate()):this._debug("non-initiator initial negotiation request discarded"),this._firstNegotiation=!1})))}negotiate(){if(!this.destroying){if(this.destroyed)throw Zt(Error("cannot negotiate after peer is destroyed"),"ERR_DESTROYED");this.initiator?this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("start negotiation"),setTimeout((()=>{this._createOffer()}),0)):this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("requesting negotiation from initiator"),this.emit("signal",{type:"renegotiate",renegotiate:!0})),this._isNegotiating=!0}}destroy(t){this.destroyed||this.destroying||(this.destroying=!0,this._debug("destroying (error: %s)",t&&(t.message||t)),queueMicrotask((()=>{if(this.destroyed=!0,this.destroying=!1,this._debug("destroy (error: %s)",t&&(t.message||t)),this._connected=!1,this._pcReady=!1,this._channelReady=!1,this._remoteTracks=null,this._remoteStreams=null,this._senderMap=null,clearInterval(this._closingInterval),this._closingInterval=null,clearInterval(this._interval),this._interval=null,this._chunk=null,this._cb=null,this._channel){try{this._channel.close()}catch(t){}this._channel.onmessage=null,this._channel.onopen=null,this._channel.onclose=null,this._channel.onerror=null}if(this._pc){try{this._pc.close()}catch(t){}this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ontrack=null,this._pc.ondatachannel=null}this._pc=null,this._channel=null,t&&this.emit("error",t),this.emit("close")})))}_setupData(t){if(!t.channel)return this.destroy(Zt(Error("Data channel event is missing `channel` property"),"ERR_DATA_CHANNEL"));this._channel=t.channel,this._channel.binaryType="arraybuffer","number"==typeof this._channel.bufferedAmountLowThreshold&&(this._channel.bufferedAmountLowThreshold=65536),this.channelName=this._channel.label,this._channel.onmessage=t=>{this._onChannelMessage(t)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=t=>{this.destroy(Zt(t,"ERR_DATA_CHANNEL"))};let e=!1;this._closingInterval=setInterval((()=>{this._channel&&"closing"===this._channel.readyState?(e&&this._onChannelClose(),e=!0):e=!1}),5e3)}_startIceCompleteTimeout(){this.destroyed||this._iceCompleteTimer||(this._debug("started iceComplete timeout"),this._iceCompleteTimer=setTimeout((()=>{this._iceComplete||(this._iceComplete=!0,this._debug("iceComplete timeout completed"),this.emit("iceTimeout"),this.emit("_iceComplete"))}),this.iceCompleteTimeout))}_createOffer(){this.destroyed||this._pc.createOffer(this.offerOptions).then((t=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(t.sdp=Yt(t.sdp)),t.sdp=this.sdpTransform(t.sdp);const e=()=>{if(this.destroyed)return;const e=this._pc.localDescription||t;this._debug("signal"),this.emit("signal",{type:e.type,sdp:e.sdp})};this._pc.setLocalDescription(t).then((()=>{this._debug("createOffer success"),this.destroyed||(this.trickle||this._iceComplete?e():this.once("_iceComplete",e))})).catch((t=>{this.destroy(Zt(t,"ERR_SET_LOCAL_DESCRIPTION"))}))})).catch((t=>{this.destroy(Zt(t,"ERR_CREATE_OFFER"))}))}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach((t=>{t.mid||!t.sender.track||t.requested||(t.requested=!0,this.addTransceiver(t.sender.track.kind))}))}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then((t=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(t.sdp=Yt(t.sdp)),t.sdp=this.sdpTransform(t.sdp);const e=()=>{if(this.destroyed)return;const e=this._pc.localDescription||t;this._debug("signal"),this.emit("signal",{type:e.type,sdp:e.sdp}),this.initiator||this._requestMissingTransceivers()};this._pc.setLocalDescription(t).then((()=>{this.destroyed||(this.trickle||this._iceComplete?e():this.once("_iceComplete",e))})).catch((t=>{this.destroy(Zt(t,"ERR_SET_LOCAL_DESCRIPTION"))}))})).catch((t=>{this.destroy(Zt(t,"ERR_CREATE_ANSWER"))}))}_onConnectionStateChange(){this.destroyed||"failed"===this._pc.connectionState&&this.destroy(Zt(Error("Connection failed."),"ERR_CONNECTION_FAILURE"))}_onIceStateChange(){if(this.destroyed)return;const t=this._pc.iceConnectionState,e=this._pc.iceGatheringState;this._debug("iceStateChange (connection: %s) (gathering: %s)",t,e),this.emit("iceStateChange",t,e),"connected"!==t&&"completed"!==t||(this._pcReady=!0,this._maybeReady()),"failed"===t&&this.destroy(Zt(Error("Ice connection failed."),"ERR_ICE_CONNECTION_FAILURE")),"closed"===t&&this.destroy(Zt(Error("Ice connection closed."),"ERR_ICE_CONNECTION_CLOSED"))}getStats(t){const e=t=>("[object Array]"==={}.toString.call(t.values)&&t.values.forEach((e=>{Object.assign(t,e)})),t);0===this._pc.getStats.length||this._isReactNativeWebrtc?this._pc.getStats().then((n=>{const r=[];n.forEach((t=>{r.push(e(t))})),t(null,r)}),(e=>t(e))):this._pc.getStats.length>0?this._pc.getStats((n=>{if(this.destroyed)return;const r=[];n.result().forEach((t=>{const n={};t.names().forEach((e=>{n[e]=t.stat(e)})),n.id=t.id,n.type=t.type,n.timestamp=t.timestamp,r.push(e(n))})),t(null,r)}),(e=>t(e))):t(null,[])}_maybeReady(){if(this._debug("maybeReady pc %s channel %s",this._pcReady,this._channelReady),this._connected||this._connecting||!this._pcReady||!this._channelReady)return;this._connecting=!0;const t=()=>{this.destroyed||this.getStats(((e,n)=>{if(this.destroyed)return;e&&(n=[]);const r={},i={},s={};let o=!1;n.forEach((t=>{"remotecandidate"!==t.type&&"remote-candidate"!==t.type||(r[t.id]=t),"localcandidate"!==t.type&&"local-candidate"!==t.type||(i[t.id]=t),"candidatepair"!==t.type&&"candidate-pair"!==t.type||(s[t.id]=t)}));const a=t=>{o=!0;let e=i[t.localCandidateId];e&&(e.ip||e.address)?(this.localAddress=e.ip||e.address,this.localPort=Number(e.port)):e&&e.ipAddress?(this.localAddress=e.ipAddress,this.localPort=Number(e.portNumber)):"string"==typeof t.googLocalAddress&&(e=t.googLocalAddress.split(":"),this.localAddress=e[0],this.localPort=Number(e[1])),this.localAddress&&(this.localFamily=this.localAddress.includes(":")?"IPv6":"IPv4");let n=r[t.remoteCandidateId];n&&(n.ip||n.address)?(this.remoteAddress=n.ip||n.address,this.remotePort=Number(n.port)):n&&n.ipAddress?(this.remoteAddress=n.ipAddress,this.remotePort=Number(n.portNumber)):"string"==typeof t.googRemoteAddress&&(n=t.googRemoteAddress.split(":"),this.remoteAddress=n[0],this.remotePort=Number(n[1])),this.remoteAddress&&(this.remoteFamily=this.remoteAddress.includes(":")?"IPv6":"IPv4"),this._debug("connect local: %s:%s remote: %s:%s",this.localAddress,this.localPort,this.remoteAddress,this.remotePort)};if(n.forEach((t=>{"transport"===t.type&&t.selectedCandidatePairId&&a(s[t.selectedCandidatePairId]),("googCandidatePair"===t.type&&"true"===t.googActiveConnection||("candidatepair"===t.type||"candidate-pair"===t.type)&&t.selected)&&a(t)})),o||Object.keys(s).length&&!Object.keys(i).length){if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(e){return this.destroy(Zt(e,"ERR_DATA_CHANNEL"))}this._chunk=null,this._debug('sent chunk from "write before connect"');const t=this._cb;this._cb=null,t(null)}"number"!=typeof this._channel.bufferedAmountLowThreshold&&(this._interval=setInterval((()=>this._onInterval()),150),this._interval.unref&&this._interval.unref()),this._debug("connect"),this.emit("connect")}else setTimeout(t,100)}))};t()}_onInterval(){!this._cb||!this._channel||this._channel.bufferedAmount>65536||this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||("stable"===this._pc.signalingState&&(this._isNegotiating=!1,this._debug("flushing sender queue",this._sendersAwaitingStable),this._sendersAwaitingStable.forEach((t=>{this._pc.removeTrack(t),this._queuedNegotiation=!0})),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._debug("flushing negotiation queue"),this._queuedNegotiation=!1,this._needsNegotiation()):(this._debug("negotiated"),this.emit("negotiated"))),this._debug("signalingStateChange %s",this._pc.signalingState),this.emit("signalingStateChange",this._pc.signalingState))}_onIceCandidate(t){this.destroyed||(t.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:t.candidate.candidate,sdpMLineIndex:t.candidate.sdpMLineIndex,sdpMid:t.candidate.sdpMid}}):t.candidate||this._iceComplete||(this._iceComplete=!0,this.emit("_iceComplete")),t.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(t){if(this.destroyed)return;let e=t.data;e instanceof ArrayBuffer&&(e=new Uint8Array(e)),this.emit("data",e)}_onChannelBufferedAmountLow(){if(this.destroyed||!this._cb)return;this._debug("ending backpressure: bufferedAmount %d",this._channel.bufferedAmount);const t=this._cb;this._cb=null,t(null)}_onChannelOpen(){this._connected||this.destroyed||(this._debug("on channel open"),this._channelReady=!0,this._maybeReady())}_onChannelClose(){this.destroyed||(this._debug("on channel close"),this.destroy())}_onTrack(t){this.destroyed||t.streams.forEach((e=>{this._debug("on track"),this.emit("track",t.track,e),this._remoteTracks.push({track:t.track,stream:e}),this._remoteStreams.some((t=>t.id===e.id))||(this._remoteStreams.push(e),queueMicrotask((()=>{this._debug("on stream"),this.emit("stream",e)})))}))}_debug(...t){this._doDebug&&(t[0]="["+this._id+"] "+t[0])}on(t,e){const n=this._map;n.has(t)||n.set(t,new Set),n.get(t).add(e)}off(t,e){const n=this._map,r=n.get(t);r&&(r.delete(e),0===r.size&&n.delete(t))}once(t,e){const n=(...r)=>{this.off(t,n),e(...r)};this.on(t,n)}emit(t,...e){const n=this._map;if(n.has(t))for(const r of n.get(t))try{r(...e)}catch(t){console.error(t)}}}Wt.WEBRTC_SUPPORT=!!Kt(),Wt.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},Wt.channelConfig={};const Gt=(t,e,n)=>{const r=new Wt({initiator:t,trickle:e,config:n}),i=t=>r.__earlyDataBuffer.push(t);return r.on(ce.data,i),r.__earlyDataBuffer=[],r.__drainEarlyData=t=>{r.off(ce.data,i),r.__earlyDataBuffer.forEach(t),delete r.__earlyDataBuffer,delete r.__drainEarlyData},r},Jt=t=>Array(t).fill().map((()=>"0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"[Math.floor(62*Math.random())])).join(""),Qt=Jt(20),{keys:Xt,values:te,entries:ee,fromEntries:ne}=Object,re=()=>{},ie=t=>Error(`Trystero: ${t}`),se=t=>(new TextEncoder).encode(t),oe=t=>(new TextDecoder).decode(t),ae=t=>t.reduce(((t,e)=>t+e.toString(16).padStart(2,"0")),""),ce=ne(["close","connect","data","error","signal","stream","track"].map((t=>[t,t]))),he=Object.getPrototypeOf(Uint8Array),de=16369,le=255,ue="bufferedamountlow",fe="AES-CBC",ge=async(t,e)=>{const n=crypto.getRandomValues(new Uint8Array(16));var r;return JSON.stringify({c:(r=await crypto.subtle.encrypt({name:fe,iv:n},await t,se(e)),btoa(String.fromCharCode.apply(null,new Uint8Array(r)))),iv:[...n]})},pe=async(t,e)=>{const{c:n,iv:r}=JSON.parse(e);return oe(await crypto.subtle.decrypt({name:fe,iv:new Uint8Array(r)},await t,(t=>{const e=atob(t);return new Uint8Array(e.length).map(((t,n)=>e.charCodeAt(n))).buffer})(n)))},ye={},me=ae(crypto.getRandomValues(new Uint8Array(32))),_e=ae(zt.getPublicKey(me)),be={},Ee=()=>Math.floor(Date.now()/1e3),we=["wss://relay.nostr.net","wss://relay.blackbyte.nl","wss://relay.piazza.today","wss://relay.exit.pub","wss://relay.nostr.band","wss://relay.damus.io","wss://nostr.mom","wss://relay.snort.social","wss://nostr.lu.ke","wss://relay.plebstr.com","wss://nostr.sathoarder.com","wss://nsrelay.assilvestrar.club","wss://nostrasia.casa","wss://relay.nostr.bg","wss://relay.nostrr.de","wss://relay.nostrss.re"],Re=(Ae=ye,(t,e)=>{if(Ae[e])return Ae[e];if(!t)throw ie("requires a config map as the first argument");if(!t.appId&&!t.firebaseApp)throw ie("config map is missing appId field");if(!e)throw ie("namespace argument required");return Ae[e]=((t,e)=>{const n=t.password&&(async(t,e)=>crypto.subtle.importKey("raw",await crypto.subtle.digest({name:"SHA-256"},se(`${t}:${e}`)),{name:fe},!1,["encrypt","decrypt"]))(t.password,e),r=`trystero/${t.appId}/${e}`,i=`${r}/${Qt}`,s=Jt(64),o=Jt(64),a={},c={},h={},d=((t,e,n)=>(t.relayUrls||e).slice(0,t.relayUrls?t.relayUrls.length:t.relayRedundancy||4))(t,we),l=(t,e)=>{y(t,e),h[e]=t},u=t=>{delete a[t],delete c[t],delete h[t]},f=(t,e)=>JSON.stringify(["REQ",t,{kinds:[29333],since:Ee(),"#x":[e]}]),g=t=>JSON.stringify(["CLOSE",t]),p=async(t,e)=>{const n={kind:29333,content:JSON.stringify(e),pubkey:_e,created_at:Ee(),tags:[["x",t]]},r=ae(new Uint8Array(await crypto.subtle.digest("SHA-256",se(JSON.stringify([0,n.pubkey,n.created_at,n.kind,n.tags,n.content])))));return JSON.stringify(["EVENT",{...n,id:r,sig:ae(await zt.sign(r,me))}])};let y=re;return d.forEach((e=>{const d=new WebSocket(e);be[e]=d,d.addEventListener("open",(async()=>{d.send(f(s,r)),d.send(f(o,i)),d.send(await p(r,Qt))})),d.addEventListener("message",(async e=>{const[i,f,g,y]=JSON.parse(e.data);if("EVENT"!==i)return void("OK"!==i||g||console.warn(`Trystero: relay failure from ${d.url} - ${y}`));const m=JSON.parse(g.content);if(f===s){const e=m;if(e!==Qt&&!h[e]&&!c[e]){c[e]=!0;const i=a[e]=Gt(!0,!1,t.rtcConfig);i.once(ce.signal,(async t=>{d.send(await p(`${r}/${e}`,{peerId:Qt,offer:n?{...t,sdp:await ge(n,t.sdp)}:t}))})),i.once(ce.connect,(()=>l(i,e))),i.once(ce.close,(()=>u(e)))}}else if(f===o){const{peerId:e,offer:i,answer:s}=m;if(a[e]&&s)return void a[e].signal(n?{...s,sdp:await pe(n,s.sdp)}:s);if(!i)return;const o=Gt(!1,!1,t.rtcConfig);o.once(ce.signal,(async t=>d.send(await p(`${r}/${e}`,{peerId:Qt,answer:n?{...t,sdp:await ge(n,t.sdp)}:t})))),o.once(ce.connect,(()=>l(o,e))),o.once(ce.close,(()=>u(e))),o.signal(i)}}))})),((t,e)=>{const n={},r={},i={},s={},o={},a={},c=(t,e)=>(t?Array.isArray(t)?t:[t]:Xt(n)).flatMap((t=>{const r=n[t];return r?e(t,r):(console.warn(`Trystero: no peer with id ${t} found`),[])})),h=t=>{if(r[t])return[r[t].send,r[t].setOnComplete,r[t].setOnProgress];if(!t)throw ie("action type argument is required");const e=se(t);if(e.byteLength>12)throw ie(`action type string "${t}" (${e.byteLength}b) exceeds byte limit (12). Hint: choose a shorter name.`);const i=new Uint8Array(12);i.set(e);let s=0;return r[t]={onComplete:re,onProgress:re,setOnComplete:e=>r[t]={...r[t],onComplete:e},setOnProgress:e=>r[t]={...r[t],onProgress:e},async send(t,e,r,o){if(r&&"object"!=typeof r)throw ie("action meta argument must be an object");if(void 0===t)throw ie("action data cannot be undefined");const a="string"!=typeof t,h=t instanceof Blob,d=h||t instanceof ArrayBuffer||t instanceof he;if(r&&!d)throw ie("action meta argument can only be used with binary data");const l=d?new Uint8Array(h?await t.arrayBuffer():t):se(a?JSON.stringify(t):t),u=r?se(JSON.stringify(r)):null,f=Math.ceil(l.byteLength/de)+(r?1:0)||1,g=Array(f).fill().map(((t,e)=>{const n=e===f-1,o=r&&0===e,c=new Uint8Array(15+(o?u.byteLength:n?l.byteLength-de*(f-(r?2:1)):de));return c.set(i),c.set([s],12),c.set([n|o<<1|d<<2|a<<3],13),c.set([Math.round((e+1)/f*le)],14),c.set(r?o?u:l.subarray((e-1)*de,e*de):l.subarray(e*de,(e+1)*de),15),c}));return s=s+1&le,Promise.all(c(e,(async(t,e)=>{const i=e._channel;let s=0;for(;s<f;){const a=g[s];if(i.bufferedAmount>i.bufferedAmountLowThreshold&&await new Promise((t=>{const e=()=>{i.removeEventListener(ue,e),t()};i.addEventListener(ue,e)})),!n[t])break;e.send(a),s++,o&&o(a[14]/le,t,r)}})))}},[r[t].send,r[t].setOnComplete,r[t].setOnProgress]},d=(t,e)=>{const n=new Uint8Array(e),s=oe(n.subarray(0,12)).replaceAll("\0",""),[o]=n.subarray(12,13),[a]=n.subarray(13,14),[c]=n.subarray(14,15),h=n.subarray(15),d=!!(1&a),l=!!(2&a),u=!!(4&a),f=!!(8&a);if(!r[s])throw ie(`received message with unregistered type (${s})`);i[t]||(i[t]={}),i[t][s]||(i[t][s]={});let g=i[t][s][o];if(g||(g=i[t][s][o]={chunks:[]}),l?g.meta=JSON.parse(oe(h)):g.chunks.push(h),r[s].onProgress(c/le,t,g.meta),!d)return;const p=new Uint8Array(g.chunks.reduce(((t,e)=>t+e.byteLength),0));if(g.chunks.reduce(((t,e)=>(p.set(e,t),t+e.byteLength)),0),u)r[s].onComplete(p,t,g.meta);else{const e=oe(p);r[s].onComplete(f?JSON.parse(e):e,t)}delete i[t][s][o]},[l,u]=h("__91n6__"),[f,g]=h("__90n6__"),[p,y]=h("__516n4L__"),[m,_]=h("__57r34m__"),[b,E]=h("__7r4ck__");let w=re,R=re,A=re,v=re;return t(((t,e)=>{if(n[e])return;const r=d.bind(null,e);n[e]=t,t.on(ce.signal,(t=>p(t,e))),t.on(ce.close,(()=>(t=>{n[t]&&(delete n[t],delete i[t],delete s[t],R(t))})(e))),t.on(ce.data,r),t.on(ce.stream,(t=>{A(t,e,o[e]),delete o[e]})),t.on(ce.track,((t,n)=>{v(t,n,e,a[e]),delete a[e]})),t.on(ce.error,(t=>{"ERR_DATA_CHANNEL"!==t.code&&console.error(t)})),w(e),t.__drainEarlyData(r)})),u(((t,e)=>f("",e))),g(((t,e)=>{s[e]&&(s[e](),delete s[e])})),y(((t,e)=>{n[e]&&n[e].signal(t)})),_(((t,e)=>o[e]=t)),E(((t,e)=>a[e]=t)),{makeAction:h,async ping(t){if(!t)throw ie("ping() must be called with target peer ID");const e=Date.now();return l("",t),await new Promise((e=>s[t]=e)),Date.now()-e},leave(){ee(n).forEach((([t,e])=>{e.destroy(),delete n[t]})),e()},getPeers:()=>ne(ee(n).map((([t,e])=>[t,e._pc]))),addStream:(t,e,n)=>c(e,(async(e,r)=>{n&&await m(n,e),r.addStream(t)})),removeStream:(t,e)=>c(e,((e,n)=>n.removeStream(t))),addTrack:(t,e,n,r)=>c(n,(async(n,i)=>{r&&await b(r,n),i.addTrack(t,e)})),removeTrack:(t,e,n)=>c(n,((n,r)=>r.removeTrack(t,e))),replaceTrack:(t,e,n,r,i)=>c(r,(async(r,s)=>{i&&await b(i,r),s.replaceTrack(t,e,n)})),onPeerJoin:t=>w=t,onPeerLeave:t=>R=t,onPeerStream:t=>A=t,onPeerTrack:t=>v=t}})((t=>y=t),(()=>{delete ye[e],te(be).forEach((t=>{t.send(g(s)),t.send(g(o))}))}))})(t,e)});var Ae}));