@libp2p/webrtc 5.2.10-b9e32cc37 → 5.2.10-f09bef843

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,15 +1,15 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebrtc = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebrtc=(()=>{var gA=Object.create;var ml=Object.defineProperty;var wA=Object.getOwnPropertyDescriptor;var xA=Object.getOwnPropertyNames;var bA=Object.getPrototypeOf,vA=Object.prototype.hasOwnProperty;var Ep=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),vt=(r,e)=>{for(var t in e)ml(r,t,{get:e[t],enumerable:!0})},ag=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xA(e))!vA.call(r,o)&&o!==t&&ml(r,o,{get:()=>e[o],enumerable:!(n=wA(e,o))||n.enumerable});return r};var Dr=(r,e,t)=>(t=r!=null?gA(bA(r)):{},ag(e||!r||!r.__esModule?ml(t,"default",{value:r,enumerable:!0}):t,r)),AA=r=>ag(ml({},"__esModule",{value:!0}),r);var rx=Ep(()=>{var tx;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,u){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),u&&u(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,u=!a&&!c,h={create:a?function(){return Sp(Object.create(null))}:c?function(){return Sp({__proto__:null})}:function(){return Sp({})},has:u?function(x,E){return n.call(x,E)}:function(x,E){return E in x},get:u?function(x,E){return n.call(x,E)?x[E]:void 0}:function(x,E){return x[E]}},p=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:pA(),w=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:hA(),b=typeof WeakMap=="function"?WeakMap:dA(),g=o?Symbol.for("@reflect-metadata:registry"):void 0,y=lA(),S=uA(y);function T(x,E,B,$){if(N(B)){if(!Ye(x))throw new TypeError;if(!bt(E))throw new TypeError;return Y(x,E)}else{if(!Ye(x))throw new TypeError;if(!Q(E))throw new TypeError;if(!Q($)&&!N($)&&!ie($))throw new TypeError;return ie($)&&($=void 0),B=je(B),le(x,E,B,$)}}e("decorate",T);function v(x,E){function B($,se){if(!Q($))throw new TypeError;if(!N(se)&&!Yt(se))throw new TypeError;C(x,E,$,se)}return B}e("metadata",v);function P(x,E,B,$){if(!Q(B))throw new TypeError;return N($)||($=je($)),C(x,E,B,$)}e("defineMetadata",P);function W(x,E,B){if(!Q(E))throw new TypeError;return N(B)||(B=je(B)),R(x,E,B)}e("hasMetadata",W);function H(x,E,B){if(!Q(E))throw new TypeError;return N(B)||(B=je(B)),D(x,E,B)}e("hasOwnMetadata",H);function O(x,E,B){if(!Q(E))throw new TypeError;return N(B)||(B=je(B)),j(x,E,B)}e("getMetadata",O);function K(x,E,B){if(!Q(E))throw new TypeError;return N(B)||(B=je(B)),k(x,E,B)}e("getOwnMetadata",K);function L(x,E){if(!Q(x))throw new TypeError;return N(E)||(E=je(E)),I(x,E)}e("getMetadataKeys",L);function te(x,E){if(!Q(x))throw new TypeError;return N(E)||(E=je(E)),U(x,E)}e("getOwnMetadataKeys",te);function z(x,E,B){if(!Q(E))throw new TypeError;if(N(B)||(B=je(B)),!Q(E))throw new TypeError;N(B)||(B=je(B));var $=ta(E,B,!1);return N($)?!1:$.OrdinaryDeleteMetadata(x,E,B)}e("deleteMetadata",z);function Y(x,E){for(var B=x.length-1;B>=0;--B){var $=x[B],se=$(E);if(!N(se)&&!ie(se)){if(!bt(se))throw new TypeError;E=se}}return E}function le(x,E,B,$){for(var se=x.length-1;se>=0;--se){var Ze=x[se],ot=Ze(E,B,$);if(!N(ot)&&!ie(ot)){if(!Q(ot))throw new TypeError;$=ot}}return $}function R(x,E,B){var $=D(x,E,B);if($)return!0;var se=Ap(E);return ie(se)?!1:R(x,se,B)}function D(x,E,B){var $=ta(E,B,!1);return N($)?!1:Ee($.OrdinaryHasOwnMetadata(x,E,B))}function j(x,E,B){var $=D(x,E,B);if($)return k(x,E,B);var se=Ap(E);if(!ie(se))return j(x,se,B)}function k(x,E,B){var $=ta(E,B,!1);if(!N($))return $.OrdinaryGetOwnMetadata(x,E,B)}function C(x,E,B,$){var se=ta(B,$,!0);se.OrdinaryDefineOwnMetadata(x,E,B,$)}function I(x,E){var B=U(x,E),$=Ap(x);if($===null)return B;var se=I($,E);if(se.length<=0)return B;if(B.length<=0)return se;for(var Ze=new w,ot=[],we=0,G=B;we<G.length;we++){var Z=G[we],ee=Ze.has(Z);ee||(Ze.add(Z),ot.push(Z))}for(var re=0,xe=se;re<xe.length;re++){var Z=xe[re],ee=Ze.has(Z);ee||(Ze.add(Z),ot.push(Z))}return ot}function U(x,E){var B=ta(x,E,!1);return B?B.OrdinaryOwnMetadataKeys(x,E):[]}function q(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function N(x){return x===void 0}function ie(x){return x===null}function fe(x){return typeof x=="symbol"}function Q(x){return typeof x=="object"?x!==null:typeof x=="function"}function ye(x,E){switch(q(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var B=E===3?"string":E===5?"number":"default",$=ea(x,i);if($!==void 0){var se=$.call(x,B);if(Q(se))throw new TypeError;return se}return Be(x,B==="default"?"number":B)}function Be(x,E){if(E==="string"){var B=x.toString;if($e(B)){var $=B.call(x);if(!Q($))return $}var se=x.valueOf;if($e(se)){var $=se.call(x);if(!Q($))return $}}else{var se=x.valueOf;if($e(se)){var $=se.call(x);if(!Q($))return $}var Ze=x.toString;if($e(Ze)){var $=Ze.call(x);if(!Q($))return $}}throw new TypeError}function Ee(x){return!!x}function Le(x){return""+x}function je(x){var E=ye(x,3);return fe(E)?E:Le(E)}function Ye(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function $e(x){return typeof x=="function"}function bt(x){return typeof x=="function"}function Yt(x){switch(q(x)){case 3:return!0;case 4:return!0;default:return!1}}function nn(x,E){return x===E||x!==x&&E!==E}function ea(x,E){var B=x[E];if(B!=null){if(!$e(B))throw new TypeError;return B}}function fl(x){var E=ea(x,s);if(!$e(E))throw new TypeError;var B=E.call(x);if(!Q(B))throw new TypeError;return B}function pl(x){return x.value}function hl(x){var E=x.next();return E.done?!1:E}function dl(x){var E=x.return;E&&E.call(x)}function Ap(x){var E=Object.getPrototypeOf(x);if(typeof x!="function"||x===p||E!==p)return E;var B=x.prototype,$=B&&Object.getPrototypeOf(B);if($==null||$===Object.prototype)return E;var se=$.constructor;return typeof se!="function"||se===x?E:se}function cA(){var x;!N(g)&&typeof t.Reflect<"u"&&!(g in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=fA(t.Reflect));var E,B,$,se=new b,Ze={registerProvider:ot,getProvider:G,setProvider:ee};return Ze;function ot(re){if(!Object.isExtensible(Ze))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===re:break;case N(E):E=re;break;case E===re:break;case N(B):B=re;break;case B===re:break;default:$===void 0&&($=new w),$.add(re);break}}function we(re,xe){if(!N(E)){if(E.isProviderFor(re,xe))return E;if(!N(B)){if(B.isProviderFor(re,xe))return E;if(!N($))for(var Me=fl($);;){var Je=hl(Me);if(!Je)return;var gr=pl(Je);if(gr.isProviderFor(re,xe))return dl(Me),gr}}}if(!N(x)&&x.isProviderFor(re,xe))return x}function G(re,xe){var Me=se.get(re),Je;return N(Me)||(Je=Me.get(xe)),N(Je)&&(Je=we(re,xe),N(Je)||(N(Me)&&(Me=new m,se.set(re,Me)),Me.set(xe,Je))),Je}function Z(re){if(N(re))throw new TypeError;return E===re||B===re||!N($)&&$.has(re)}function ee(re,xe,Me){if(!Z(Me))throw new Error("Metadata provider not registered.");var Je=G(re,xe);if(Je!==Me){if(!N(Je))return!1;var gr=se.get(re);N(gr)&&(gr=new m,se.set(re,gr)),gr.set(xe,Me)}return!0}}function lA(){var x;return!N(g)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[g]),N(x)&&(x=cA()),!N(g)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,g,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function uA(x){var E=new b,B={isProviderFor:function(Z,ee){var re=E.get(Z);return N(re)?!1:re.has(ee)},OrdinaryDefineOwnMetadata:ot,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Ze,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:G};return y.registerProvider(B),B;function $(Z,ee,re){var xe=E.get(Z),Me=!1;if(N(xe)){if(!re)return;xe=new m,E.set(Z,xe),Me=!0}var Je=xe.get(ee);if(N(Je)){if(!re)return;if(Je=new m,xe.set(ee,Je),!x.setProvider(Z,ee,B))throw xe.delete(ee),Me&&E.delete(Z),new Error("Wrong provider for target.")}return Je}function se(Z,ee,re){var xe=$(ee,re,!1);return N(xe)?!1:Ee(xe.has(Z))}function Ze(Z,ee,re){var xe=$(ee,re,!1);if(!N(xe))return xe.get(Z)}function ot(Z,ee,re,xe){var Me=$(re,xe,!0);Me.set(Z,ee)}function we(Z,ee){var re=[],xe=$(Z,ee,!1);if(N(xe))return re;for(var Me=xe.keys(),Je=fl(Me),gr=0;;){var sg=hl(Je);if(!sg)return re.length=gr,re;var mA=pl(sg);try{re[gr]=mA}catch(yA){try{dl(Je)}finally{throw yA}}gr++}}function G(Z,ee,re){var xe=$(ee,re,!1);if(N(xe)||!xe.delete(Z))return!1;if(xe.size===0){var Me=E.get(ee);N(Me)||(Me.delete(re),Me.size===0&&E.delete(Me))}return!0}}function fA(x){var E=x.defineMetadata,B=x.hasOwnMetadata,$=x.getOwnMetadata,se=x.getOwnMetadataKeys,Ze=x.deleteMetadata,ot=new b,we={isProviderFor:function(G,Z){var ee=ot.get(G);return!N(ee)&&ee.has(Z)?!0:se(G,Z).length?(N(ee)&&(ee=new w,ot.set(G,ee)),ee.add(Z),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:B,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Ze};return we}function ta(x,E,B){var $=y.getProvider(x,E);if(!N($))return $;if(B){if(y.setProvider(x,E,S))return S;throw new Error("Illegal state.")}}function pA(){var x={},E=[],B=function(){function we(G,Z,ee){this._index=0,this._keys=G,this._values=Z,this._selector=ee}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var G=this._index;if(G>=0&&G<this._keys.length){var Z=this._selector(this._keys[G],this._values[G]);return G+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:Z,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(G){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),G},we.prototype.return=function(G){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:G,done:!0}},we}(),$=function(){function we(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(G){return this._find(G,!1)>=0},we.prototype.get=function(G){var Z=this._find(G,!1);return Z>=0?this._values[Z]:void 0},we.prototype.set=function(G,Z){var ee=this._find(G,!0);return this._values[ee]=Z,this},we.prototype.delete=function(G){var Z=this._find(G,!1);if(Z>=0){for(var ee=this._keys.length,re=Z+1;re<ee;re++)this._keys[re-1]=this._keys[re],this._values[re-1]=this._values[re];return this._keys.length--,this._values.length--,nn(G,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},we.prototype.keys=function(){return new B(this._keys,this._values,se)},we.prototype.values=function(){return new B(this._keys,this._values,Ze)},we.prototype.entries=function(){return new B(this._keys,this._values,ot)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(G,Z){if(!nn(this._cacheKey,G)){this._cacheIndex=-1;for(var ee=0;ee<this._keys.length;ee++)if(nn(this._keys[ee],G)){this._cacheIndex=ee;break}}return this._cacheIndex<0&&Z&&(this._cacheIndex=this._keys.length,this._keys.push(G),this._values.push(void 0)),this._cacheIndex},we}();return $;function se(we,G){return we}function Ze(we,G){return G}function ot(we,G){return[we,G]}}function hA(){var x=function(){function E(){this._map=new m}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(B){return this._map.has(B)},E.prototype.add=function(B){return this._map.set(B,B),this},E.prototype.delete=function(B){return this._map.delete(B)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E}();return x}function dA(){var x=16,E=h.create(),B=$();return function(){function G(){this._key=$()}return G.prototype.has=function(Z){var ee=se(Z,!1);return ee!==void 0?h.has(ee,this._key):!1},G.prototype.get=function(Z){var ee=se(Z,!1);return ee!==void 0?h.get(ee,this._key):void 0},G.prototype.set=function(Z,ee){var re=se(Z,!0);return re[this._key]=ee,this},G.prototype.delete=function(Z){var ee=se(Z,!1);return ee!==void 0?delete ee[this._key]:!1},G.prototype.clear=function(){this._key=$()},G}();function $(){var G;do G="@@WeakMap@@"+we();while(h.has(E,G));return E[G]=!0,G}function se(G,Z){if(!n.call(G,B)){if(!Z)return;Object.defineProperty(G,B,{value:h.create()})}return G[B]}function Ze(G,Z){for(var ee=0;ee<Z;++ee)G[ee]=Math.random()*255|0;return G}function ot(G){if(typeof Uint8Array=="function"){var Z=new Uint8Array(G);return typeof crypto<"u"?crypto.getRandomValues(Z):typeof msCrypto<"u"?msCrypto.getRandomValues(Z):Ze(Z,G),Z}return Ze(new Array(G),G)}function we(){var G=ot(x);G[6]=G[6]&79|64,G[8]=G[8]&191|128;for(var Z="",ee=0;ee<x;++ee){var re=G[ee];(ee===4||ee===6||ee===8)&&(Z+="-"),re<16&&(Z+="0"),Z+=re.toString(16).toLowerCase()}return Z}}function Sp(x){return x.__=void 0,delete x.__,x}})})(tx||(tx={}))});var dn=Ep(ls=>{"use strict";var f_="[object ArrayBuffer]",hn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===f_}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Dd="string",p_=/^[0-9a-f\s]+$/i,h_=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,d_=/^[a-zA-Z0-9-_]+$/,Ru=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=hn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},sr=class{static toString(e,t=!1){let n=hn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},Lu=class r{static isHex(e){return typeof e===Dd&&p_.test(e)}static isBase64(e){return typeof e===Dd&&h_.test(e)}static isBase64Url(e){return typeof e===Dd&&d_.test(e)}static ToString(e,t="utf8"){let n=hn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return sr.toString(n,!0);case"utf16":case"utf16be":return sr.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return sr.fromString(e,!0);case"utf16":case"utf16be":return sr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=hn.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Ru.fromString(e);case"utf16":case"utf16be":return sr.fromString(e);case"utf16le":case"usc2":return sr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Ru.toString(e);case"utf16":case"utf16be":return sr.toString(e);case"utf16le":case"usc2":return sr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=hn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=hn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return sr.toString(e,t)}static FromUtf16String(e,t=!1){return sr.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Lu.DEFAULT_UTF8_ENCODING="utf8";function m_(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function y_(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function g_(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}ls.BufferSourceConverter=hn;ls.Convert=Lu;ls.assign=m_;ls.combine=y_;ls.isEqual=g_});var Yb=Ep((EV,kf)=>{var kb,Nb,Pb,Ob,Rb,Lb,Db,Ub,jb,Bf,$m,Mb,Kb,Ms,Hb,Vb,$b,Fb,Wb,qb,Gb,zb,Xb;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof kf=="object"&&typeof kf.exports=="object"?r(t(e,t(kf.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};kb=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Nb=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Pb=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},Ob=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Rb=function(t,n){return function(o,i){n(o,i,t)}},Lb=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Db=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function u(m){try{p(i.next(m))}catch(w){c(w)}}function h(m){try{p(i.throw(m))}catch(w){c(w)}}function p(m){m.done?a(m.value):s(m.value).then(u,h)}p((i=i.apply(t,n||[])).next())})},Ub=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function u(p){return function(m){return h([p,m])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(m){p=[6,m],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Xb=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},jb=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Bf=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},$m=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(u){c={error:u}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mb=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat($m(arguments[n]));return t},Kb=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,u=a.length;c<u;c++,s++)i[s]=a[c];return i},Ms=function(t){return this instanceof Ms?(this.v=t,this):new Ms(t)},Hb=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(b){i[b]&&(s[b]=function(g){return new Promise(function(y,S){a.push([b,g,y,S])>1||u(b,g)})})}function u(b,g){try{h(i[b](g))}catch(y){w(a[0][3],y)}}function h(b){b.value instanceof Ms?Promise.resolve(b.value.v).then(p,m):w(a[0][2],b)}function p(b){u("next",b)}function m(b){u("throw",b)}function w(b,g){b(g),a.shift(),a.length&&u(a[0][0],a[0][1])}},Vb=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Ms(t[s](c)),done:s==="return"}:a?a(c):c}:a}},$b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof Bf=="function"?Bf(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(u,h){c=t[a](c),s(u,h,c.done,c.value)})}}function s(a,c,u,h){Promise.resolve(h).then(function(p){a({value:p,done:u})},c)}},Fb=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Wb=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},qb=function(t){return t&&t.__esModule?t:{default:t}},Gb=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},zb=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",kb),r("__assign",Nb),r("__rest",Pb),r("__decorate",Ob),r("__param",Rb),r("__metadata",Lb),r("__awaiter",Db),r("__generator",Ub),r("__exportStar",jb),r("__createBinding",Xb),r("__values",Bf),r("__read",$m),r("__spread",Mb),r("__spreadArrays",Kb),r("__await",Ms),r("__asyncGenerator",Hb),r("__asyncDelegator",Vb),r("__asyncValues",$b),r("__makeTemplateObject",Fb),r("__importStar",Wb),r("__importDefault",qb),r("__classPrivateFieldGet",Gb),r("__classPrivateFieldSet",zb)})});var bI={};vt(bI,{webRTC:()=>xI,webRTCDirect:()=>wI});var _p=Symbol.for("@libp2p/peer-id");var yl=Symbol.for("@libp2p/transport");var cg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(cg||(cg={}));var gl=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},wl=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ki=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ra=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var xl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var bl=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},_o=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Co=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var vl=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Al=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Sl=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var El=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},_l=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Rn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ln=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Hi=Symbol.for("@libp2p/service-capabilities"),lg=Symbol.for("@libp2p/service-dependencies");var kp={};vt(kp,{base58btc:()=>Ne,base58flickr:()=>TA});var zI=new Uint8Array(0);function ug(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function on(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function fg(r){return new TextEncoder().encode(r)}function pg(r){return new TextDecoder().decode(r)}function SA(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var g=0,y=0,S=0,T=b.length;S!==T&&b[S]===0;)S++,g++;for(var v=(T-S)*h+1>>>0,P=new Uint8Array(v);S!==T;){for(var W=b[S],H=0,O=v-1;(W!==0||H<y)&&O!==-1;O--,H++)W+=256*P[O]>>>0,P[O]=W%a>>>0,W=W/a>>>0;if(W!==0)throw new Error("Non-zero carry");y=H,S++}for(var K=v-y;K!==v&&P[K]===0;)K++;for(var L=c.repeat(g);K<v;++K)L+=r.charAt(P[K]);return L}function m(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var g=0;if(b[g]!==" "){for(var y=0,S=0;b[g]===c;)y++,g++;for(var T=(b.length-g)*u+1>>>0,v=new Uint8Array(T);b[g];){var P=t[b.charCodeAt(g)];if(P===255)return;for(var W=0,H=T-1;(P!==0||W<S)&&H!==-1;H--,W++)P+=a*v[H]>>>0,v[H]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=W,g++}if(b[g]!==" "){for(var O=T-S;O!==T&&v[O]===0;)O++;for(var K=new Uint8Array(y+(T-O)),L=y;O!==T;)K[L++]=v[O++];return K}}}function w(b){var g=m(b);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:w}}var EA=SA,_A=EA,dg=_A;var Cp=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ip=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return mg(this,e)}},Tp=class{decoders;constructor(e){this.decoders=e}or(e){return mg(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function mg(r,e){return new Tp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Bp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Cp(e,t,n),this.decoder=new Ip(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Vi({name:r,prefix:e,encode:t,decode:n}){return new Bp(r,e,t,n)}function Dn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=dg(t,r);return Vi({prefix:e,name:r,encode:n,decode:i=>on(o(i))})}function CA(r,e,t,n){let o={};for(let h=0;h<e.length;++h)o[e[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let h=0;h<i;++h){let p=o[r[h]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|p,a+=t,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=t||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function IA(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function qe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Vi({prefix:e,name:r,encode(o){return IA(o,n,t)},decode(o){return CA(o,n,t,r)}})}var Ne=Dn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),TA=Dn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Np={};vt(Np,{base32:()=>sn,base32hex:()=>PA,base32hexpad:()=>RA,base32hexpadupper:()=>LA,base32hexupper:()=>OA,base32pad:()=>kA,base32padupper:()=>NA,base32upper:()=>BA,base32z:()=>DA});var sn=qe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),BA=qe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kA=qe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),NA=qe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),PA=qe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),OA=qe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),RA=qe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),LA=qe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),DA=qe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pp={};vt(Pp,{base36:()=>na,base36upper:()=>UA});var na=Dn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),UA=Dn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var rr={};vt(rr,{Digest:()=>Io,create:()=>At,decode:()=>Un,equals:()=>Rp,hasCode:()=>rS});var jA=wg,yg=128,MA=127,KA=~MA,HA=Math.pow(2,31);function wg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=HA;)e[t++]=r&255|yg,r/=128;for(;r&KA;)e[t++]=r&255|yg,r>>>=7;return e[t]=r|0,wg.bytes=t-n+1,e}var VA=Op,$A=128,gg=127;function Op(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Op.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&gg)<<o:(s&gg)*Math.pow(2,o),o+=7}while(s>=$A);return Op.bytes=i-n,t}var FA=Math.pow(2,7),WA=Math.pow(2,14),qA=Math.pow(2,21),GA=Math.pow(2,28),zA=Math.pow(2,35),XA=Math.pow(2,42),YA=Math.pow(2,49),ZA=Math.pow(2,56),JA=Math.pow(2,63),QA=function(r){return r<FA?1:r<WA?2:r<qA?3:r<GA?4:r<zA?5:r<XA?6:r<YA?7:r<ZA?8:r<JA?9:10},eS={encode:jA,decode:VA,encodingLength:QA},tS=eS,oa=tS;function ia(r,e=0){return[oa.decode(r,e),oa.decode.bytes]}function $i(r,e,t=0){return oa.encode(r,e,t),e}function Fi(r){return oa.encodingLength(r)}function At(r,e){let t=e.byteLength,n=Fi(r),o=n+Fi(t),i=new Uint8Array(o+t);return $i(r,i,0),$i(t,i,n),i.set(e,o),new Io(r,t,e,i)}function Un(r){let e=on(r),[t,n]=ia(e),[o,i]=ia(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Io(t,o,s,e)}function Rp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ug(r.bytes,t.bytes)}}var Io=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function rS(r,e){return r.code===e}function xg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return oS(t,Lp(r),e??Ne.encoder);default:return iS(t,Lp(r),e??sn.encoder)}}var bg=new WeakMap;function Lp(r){let e=bg.get(r);if(e==null){let t=new Map;return bg.set(r,t),t}return e}var Qe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==sa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==sS)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=At(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Rp(e.multihash,n.multihash)}toString(e){return xg(this,e)}toJSON(){return{"/":xg(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??vg(n,o,i.bytes))}else if(t[aS]===!0){let{version:n,multihash:o,code:i}=t,s=Un(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==sa)throw new Error(`Version 0 CID must use dag-pb (code: ${sa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=vg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,sa,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=on(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Io(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,m]=ia(e.subarray(t));return t+=m,p},o=n(),i=sa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,h=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:u}}static parse(e,t){let[n,o]=nS(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lp(i).set(n,e),i}};function nS(r,e){switch(r[0]){case"Q":{let t=e??Ne;return[Ne.prefix,t.decode(`${Ne.prefix}${r}`)]}case Ne.prefix:{let t=e??Ne;return[Ne.prefix,t.decode(r)]}case sn.prefix:{let t=e??sn;return[sn.prefix,t.decode(r)]}case na.prefix:{let t=e??na;return[na.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function oS(r,e,t){let{prefix:n}=t;if(n!==Ne.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function iS(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var sa=112,sS=18;function vg(r,e,t){let n=Fi(r),o=n+Fi(e),i=new Uint8Array(o+t.byteLength);return $i(r,i,0),$i(e,i,n),i.set(t,o),i}var aS=Symbol.for("@ipld/js-cid/CID");var Dp={};vt(Dp,{identity:()=>wr});var Ag=0,cS="identity",Sg=on;function lS(r){return At(Ag,Sg(r))}var wr={code:Ag,name:cS,encode:Sg,digest:lS};function Ge(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function it(r=0){return new Uint8Array(r)}function et(r=0){return new Uint8Array(r)}function st(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=et(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var _g=Symbol.for("@achingbrain/uint8arraylist");function Eg(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Il(r){return!!r?.[_g]}var ue=class r{bufs;length;[_g]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Il(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Il(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Eg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Eg(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Il(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return st(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:st(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,h=t>a&&t<=c;if(u&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Il(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let m=u;m>=0;m--){let w=this.get(p+m);if(n[m]!==w){h=Math.max(1,m-a[w]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=it(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=it(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ge(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Up={};vt(Up,{base10:()=>fS});var fS=Dn({prefix:"9",name:"base10",alphabet:"0123456789"});var jp={};vt(jp,{base16:()=>pS,base16upper:()=>hS});var pS=qe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hS=qe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Mp={};vt(Mp,{base2:()=>dS});var dS=qe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kp={};vt(Kp,{base256emoji:()=>xS});var Cg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),mS=Cg.reduce((r,e,t)=>(r[t]=e,r),[]),yS=Cg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function gS(r){return r.reduce((e,t)=>(e+=mS[t],e),"")}function wS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=yS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var xS=Vi({prefix:"\u{1F680}",name:"base256emoji",encode:gS,decode:wS});var Hp={};vt(Hp,{base64:()=>bS,base64pad:()=>vS,base64url:()=>To,base64urlpad:()=>AS});var bS=qe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vS=qe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),To=qe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),AS=qe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vp={};vt(Vp,{base8:()=>SS});var SS=qe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $p={};vt($p,{identity:()=>ES});var ES=Vi({prefix:"\0",name:"identity",encode:r=>pg(r),decode:r=>fg(r)});var kT=new TextEncoder,NT=new TextDecoder;var qp={};vt(qp,{sha256:()=>nr,sha512:()=>IS});function Wp({name:r,code:e,encode:t}){return new Fp(r,e,t)}var Fp=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?At(this.code,t):t.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Tg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var nr=Wp({name:"sha2-256",code:18,encode:Tg("SHA-256")}),IS=Wp({name:"sha2-512",code:19,encode:Tg("SHA-512")});var Bo={...$p,...Mp,...Vp,...Up,...jp,...Np,...Pp,...kp,...Hp,...Kp},$T={...qp,...Dp};function kg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Bg=kg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Gp=kg("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=et(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),TS={utf8:Bg,"utf-8":Bg,hex:Bo.base16,latin1:Gp,ascii:Gp,binary:Gp,...Bo},Tl=TS;function de(r,e="utf8"){let t=Tl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ce(r,e="utf8"){let t=Tl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var BS=parseInt("11111",2),zp=parseInt("10000000",2),kS=parseInt("01111111",2),Ng={0:aa,1:aa,2:NS,3:RS,4:LS,5:OS,6:PS,16:aa,22:aa,48:aa};function an(r,e={offset:0}){let t=r[e.offset]&BS;if(e.offset++,Ng[t]!=null)return Ng[t](r,e);throw new Error("No decoder for tag "+t)}function ca(r,e){let t=0;if((r[e.offset]&zp)===zp){let n=r[e.offset]&kS,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function aa(r,e){ca(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=an(r,e);if(n===null)break;t.push(n)}return t}function NS(r,e){let t=ca(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function PS(r,e){let t=ca(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function OS(r,e){return e.offset++,null}function RS(r,e){let t=ca(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function LS(r,e){let t=ca(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function DS(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new ue;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Bl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=DS(r.byteLength);return new ue(Uint8Array.from([e.byteLength|zp]),e)}function Bt(r){let e=new ue,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new ue(Uint8Array.from([2]),Bl(e),e)}function la(r){let e=Uint8Array.from([0]),t=new ue(e,r);return new ue(Uint8Array.from([3]),Bl(t),t)}function Pg(r){return new ue(Uint8Array.from([4]),Bl(r),r)}function xr(r,e=48){let t=new ue;for(let n of r)t.append(n);return new ue(Uint8Array.from([e]),Bl(t),t)}async function Og(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Rg(r,e){let t=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Lg(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,e,t.subarray())}var US=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),jS=Uint8Array.from([6,5,43,129,4,0,34]),MS=Uint8Array.from([6,5,43,129,4,0,35]),KS={ext:!0,kty:"EC",crv:"P-256"},HS={ext:!0,kty:"EC",crv:"P-384"},VS={ext:!0,kty:"EC",crv:"P-521"},Xp=32,Yp=48,Zp=66;function Jp(r){let e=an(r);return Dg(e)}function Dg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Xp*2+1)return n=ce(e.subarray(t,t+Xp),"base64url"),o=ce(e.subarray(t+Xp),"base64url"),new ko({...KS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Yp*2+1)return n=ce(e.subarray(t,t+Yp),"base64url"),o=ce(e.subarray(t+Yp),"base64url"),new ko({...HS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Zp*2+1)return n=ce(e.subarray(t,t+Zp),"base64url"),o=ce(e.subarray(t+Zp),"base64url"),new ko({...VS,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ug(r){return xr([Bt(Uint8Array.from([1])),Pg(de(r.d??"","base64url")),xr([Mg(r.crv)],160),xr([la(new ue(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function jg(r){return xr([Bt(Uint8Array.from([1])),xr([Mg(r.crv)],160),xr([la(new ue(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Mg(r){if(r==="P-256")return US;if(r==="P-384")return jS;if(r==="P-521")return MS;throw new ve(`Invalid curve ${r}`)}async function Kg(r="P-256"){let e=await Og(r);return new kl(e.privateKey)}var ko=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=jg(this.jwk)),this._raw}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}async verify(e,t){return Lg(this.jwk,t,e)}},kl=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new ko({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Ug(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}async sign(e){return Rg(this.jwk,e)}};function Nl(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function $S(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Wi(r,...e){if(!$S(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function ua(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Nl(r.outputLen),Nl(r.blockLen)}function qi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Hg(r,e){Wi(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var No=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Pl(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function br(r,e){return r<<32-e|r>>>e}var vB=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Vg(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Mn(r){return typeof r=="string"&&(r=Vg(r)),Wi(r),r}function Qp(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Wi(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Gi=class{clone(){return this._cloneInto()}};function Ol(r){let e=n=>r().update(Mn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function fa(r=32){if(No&&typeof No.getRandomValues=="function")return No.getRandomValues(new Uint8Array(r));if(No&&typeof No.randomBytes=="function")return Uint8Array.from(No.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function FS(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function $g(r,e,t){return r&e^~r&t}function Fg(r,e,t){return r&e^r&t^e&t}var zi=class extends Gi{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Pl(this.buffer)}update(e){qi(this);let{view:t,buffer:n,blockLen:o}=this;e=Mn(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Pl(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){qi(this),Hg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;FS(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Pl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<u;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var WS=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]),Kn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=new Uint32Array(64),eh=class extends zi{constructor(e=32){super(64,e,8,!1),this.A=Kn[0]|0,this.B=Kn[1]|0,this.C=Kn[2]|0,this.D=Kn[3]|0,this.E=Kn[4]|0,this.F=Kn[5]|0,this.G=Kn[6]|0,this.H=Kn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)Hn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let m=Hn[p-15],w=Hn[p-2],b=br(m,7)^br(m,18)^m>>>3,g=br(w,17)^br(w,19)^w>>>10;Hn[p]=g+Hn[p-7]+b+Hn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:h}=this;for(let p=0;p<64;p++){let m=br(a,6)^br(a,11)^br(a,25),w=h+m+$g(a,c,u)+WS[p]+Hn[p]|0,g=(br(n,2)^br(n,13)^br(n,22))+Fg(n,o,i)|0;h=u,u=c,c=a,a=s+w|0,s=i,i=o,o=n,n=w+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,u,h)}roundClean(){Hn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var vr=Ol(()=>new eh);var Rl=BigInt(4294967295),th=BigInt(32);function Wg(r,e=!1){return e?{h:Number(r&Rl),l:Number(r>>th&Rl)}:{h:Number(r>>th&Rl)|0,l:Number(r&Rl)|0}}function qS(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=Wg(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var GS=(r,e)=>BigInt(r>>>0)<<th|BigInt(e>>>0),zS=(r,e,t)=>r>>>t,XS=(r,e,t)=>r<<32-t|e>>>t,YS=(r,e,t)=>r>>>t|e<<32-t,ZS=(r,e,t)=>r<<32-t|e>>>t,JS=(r,e,t)=>r<<64-t|e>>>t-32,QS=(r,e,t)=>r>>>t-32|e<<64-t,eE=(r,e)=>e,tE=(r,e)=>r,rE=(r,e,t)=>r<<t|e>>>32-t,nE=(r,e,t)=>e<<t|r>>>32-t,oE=(r,e,t)=>e<<t-32|r>>>64-t,iE=(r,e,t)=>r<<t-32|e>>>64-t;function sE(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var aE=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),cE=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,lE=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),uE=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,fE=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),pE=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var hE={fromBig:Wg,split:qS,toBig:GS,shrSH:zS,shrSL:XS,rotrSH:YS,rotrSL:ZS,rotrBH:JS,rotrBL:QS,rotr32H:eE,rotr32L:tE,rotlSH:rE,rotlSL:nE,rotlBH:oE,rotlBL:iE,add:sE,add3L:aE,add3H:cE,add4L:lE,add4H:uE,add5H:pE,add5L:fE},he=hE;var[dE,mE]=he.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Vn=new Uint32Array(80),$n=new Uint32Array(80),rh=class extends zi{constructor(e=64){super(128,e,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:h,Fh:p,Fl:m,Gh:w,Gl:b,Hh:g,Hl:y}=this;return[e,t,n,o,i,s,a,c,u,h,p,m,w,b,g,y]}set(e,t,n,o,i,s,a,c,u,h,p,m,w,b,g,y){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=h|0,this.Fh=p|0,this.Fl=m|0,this.Gh=w|0,this.Gl=b|0,this.Hh=g|0,this.Hl=y|0}process(e,t){for(let v=0;v<16;v++,t+=4)Vn[v]=e.getUint32(t),$n[v]=e.getUint32(t+=4);for(let v=16;v<80;v++){let P=Vn[v-15]|0,W=$n[v-15]|0,H=he.rotrSH(P,W,1)^he.rotrSH(P,W,8)^he.shrSH(P,W,7),O=he.rotrSL(P,W,1)^he.rotrSL(P,W,8)^he.shrSL(P,W,7),K=Vn[v-2]|0,L=$n[v-2]|0,te=he.rotrSH(K,L,19)^he.rotrBH(K,L,61)^he.shrSH(K,L,6),z=he.rotrSL(K,L,19)^he.rotrBL(K,L,61)^he.shrSL(K,L,6),Y=he.add4L(O,z,$n[v-7],$n[v-16]),le=he.add4H(Y,H,te,Vn[v-7],Vn[v-16]);Vn[v]=le|0,$n[v]=Y|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:h,Eh:p,El:m,Fh:w,Fl:b,Gh:g,Gl:y,Hh:S,Hl:T}=this;for(let v=0;v<80;v++){let P=he.rotrSH(p,m,14)^he.rotrSH(p,m,18)^he.rotrBH(p,m,41),W=he.rotrSL(p,m,14)^he.rotrSL(p,m,18)^he.rotrBL(p,m,41),H=p&w^~p&g,O=m&b^~m&y,K=he.add5L(T,W,O,mE[v],$n[v]),L=he.add5H(K,S,P,H,dE[v],Vn[v]),te=K|0,z=he.rotrSH(n,o,28)^he.rotrBH(n,o,34)^he.rotrBH(n,o,39),Y=he.rotrSL(n,o,28)^he.rotrBL(n,o,34)^he.rotrBL(n,o,39),le=n&i^n&a^i&a,R=o&s^o&c^s&c;S=g|0,T=y|0,g=w|0,y=b|0,w=p|0,b=m|0,{h:p,l:m}=he.add(u|0,h|0,L|0,te|0),u=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let D=he.add3L(te,Y,R);n=he.add3H(D,L,z,le),o=D|0}({h:n,l:o}=he.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=he.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=he.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:h}=he.add(this.Dh|0,this.Dl|0,u|0,h|0),{h:p,l:m}=he.add(this.Eh|0,this.El|0,p|0,m|0),{h:w,l:b}=he.add(this.Fh|0,this.Fl|0,w|0,b|0),{h:g,l:y}=he.add(this.Gh|0,this.Gl|0,g|0,y|0),{h:S,l:T}=he.add(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,i,s,a,c,u,h,p,m,w,b,g,y,S,T)}roundClean(){Vn.fill(0),$n.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var nh=Ol(()=>new rh);var ah=BigInt(0),sh=BigInt(1);function Po(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ch(r){if(!Po(r))throw new Error("Uint8Array expected")}function Ur(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function pa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function zg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ah:BigInt("0x"+r)}var Xg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",yE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Fn(r){if(ch(r),Xg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=yE[r[t]];return e}var cn={_0:48,_9:57,A:65,F:70,a:97,f:102};function qg(r){if(r>=cn._0&&r<=cn._9)return r-cn._0;if(r>=cn.A&&r<=cn.F)return r-(cn.A-10);if(r>=cn.a&&r<=cn.f)return r-(cn.a-10)}function ha(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Xg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=qg(r.charCodeAt(i)),a=qg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ln(r){return zg(Fn(r))}function jr(r){return ch(r),zg(Fn(Uint8Array.from(r).reverse()))}function Oo(r,e){return ha(r.toString(16).padStart(e*2,"0"))}function Wn(r,e){return Oo(r,e).reverse()}function De(r,e,t){let n;if(typeof e=="string")try{n=ha(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Po(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function qn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ch(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var oh=r=>typeof r=="bigint"&&ah<=r;function Ll(r,e,t){return oh(r)&&oh(e)&&oh(t)&&e<=r&&r<t}function St(r,e,t,n){if(!Ll(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Yg(r){let e;for(e=0;r>ah;r>>=sh,e+=1);return e}var Ro=r=>(sh<<BigInt(r))-sh,ih=r=>new Uint8Array(r),Gg=r=>Uint8Array.from(r);function Zg(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=ih(r),o=ih(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...p)=>t(o,n,...p),c=(p=ih(0))=>{o=a(Gg([0]),p),n=a(),p.length!==0&&(o=a(Gg([1]),p),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,m=[];for(;p<e;){n=a();let w=n.slice();m.push(w),p+=n.length}return qn(...m)};return(p,m)=>{s(),c(p);let w;for(;!(w=m(u()));)c();return s(),w}}var gE={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Po(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Ar(r,e,t={}){let n=(o,i,s)=>{let a=gE[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}function Xi(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var at=BigInt(0),He=BigInt(1),Lo=BigInt(2),wE=BigInt(3),lh=BigInt(4),Jg=BigInt(5),Qg=BigInt(8),xE=BigInt(9),bE=BigInt(16);function _e(r,e){let t=r%e;return t>=at?t:e+t}function uh(r,e,t){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(t<=at)throw new Error("invalid modulus");if(t===He)return at;let n=He;for(;e>at;)e&He&&(n=n*r%t),r=r*r%t,e>>=He;return n}function Ke(r,e,t){let n=r;for(;e-- >at;)n*=n,n%=t;return n}function Dl(r,e){if(r===at)throw new Error("invert: expected non-zero number");if(e<=at)throw new Error("invert: expected positive modulus, got "+e);let t=_e(r,e),n=e,o=at,i=He,s=He,a=at;for(;t!==at;){let u=n/t,h=n%t,p=o-s*u,m=i-a*u;n=t,t=h,o=s,i=a,s=p,a=m}if(n!==He)throw new Error("invert: does not exist");return _e(o,e)}function vE(r){let e=(r-He)/Lo,t,n,o;for(t=r-He,n=0;t%Lo===at;t/=Lo,n++);for(o=Lo;o<r&&uh(o,e,r)!==r-He;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+He)/lh;return function(c,u){let h=c.pow(u,s);if(!c.eql(c.sqr(h),u))throw new Error("Cannot find square root");return h}}let i=(t+He)/Lo;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,h=a.pow(a.mul(a.ONE,o),t),p=a.pow(c,i),m=a.pow(c,t);for(;!a.eql(m,a.ONE);){if(a.eql(m,a.ZERO))return a.ZERO;let w=1;for(let g=a.sqr(m);w<u&&!a.eql(g,a.ONE);w++)g=a.sqr(g);let b=a.pow(h,He<<BigInt(u-w-1));h=a.sqr(b),p=a.mul(p,b),m=a.mul(m,h),u=w}return p}}function AE(r){if(r%lh===wE){let e=(r+He)/lh;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%Qg===Jg){let e=(r-Jg)/Qg;return function(n,o){let i=n.mul(o,Lo),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,Lo),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%bE,vE(r)}var e0=(r,e)=>(_e(r,e)&He)===He,SE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=SE.reduce((n,o)=>(n[o]="function",n),e);return Ar(r,t)}function EE(r,e,t){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(t===at)return r.ONE;if(t===He)return e;let n=r.ONE,o=e;for(;t>at;)t&He&&(n=r.mul(n,o)),o=r.sqr(o),t>>=He;return n}function _E(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function ph(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Gn(r,e,t=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=ph(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:t,BITS:o,BYTES:i,MASK:Ro(o),ZERO:at,ONE:He,create:c=>_e(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&He)===He,neg:c=>_e(-c,r),eql:(c,u)=>c===u,sqr:c=>_e(c*c,r),add:(c,u)=>_e(c+u,r),sub:(c,u)=>_e(c-u,r),mul:(c,u)=>_e(c*u,r),pow:(c,u)=>EE(a,c,u),div:(c,u)=>_e(c*Dl(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Dl(c,r),sqrt:n.sqrt||(c=>(s||(s=AE(r)),s(a,c))),invertBatch:c=>_E(a,c),cmov:(c,u,h)=>h?u:c,toBytes:c=>t?Wn(c,i):Oo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?jr(c):ln(c)}});return Object.freeze(a)}function t0(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function hh(r){let e=t0(r);return e+Math.ceil(e/2)}function r0(r,e,t=!1){let n=r.length,o=t0(e),i=hh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?jr(r):ln(r),a=_e(s,e-He)+He;return t?Wn(a,o):Oo(a,o)}var n0=BigInt(0),wh=BigInt(1);function dh(r,e){let t=e.negate();return r?t:e}function i0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function mh(r,e){i0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Ro(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function o0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=wh);let u=e*n,h=u+Math.abs(a)-1,p=a===0,m=a<0,w=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:m,isNegF:w,offsetF:u}}function CE(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function IE(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var yh=new WeakMap,s0=new WeakMap;function gh(r){return s0.get(r)||1}function Ul(r,e){return{constTimeNegate:dh,hasPrecomputes(t){return gh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>n0;)n&wh&&(o=o.add(i)),i=i.double(),n>>=wh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=mh(n,e),s=[],a=t,c=a;for(let u=0;u<o;u++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=mh(t,e);for(let c=0;c<a.windows;c++){let{nextN:u,offset:h,isZero:p,isNeg:m,isNegF:w,offsetF:b}=o0(o,c,a);o=u,p?s=s.add(dh(w,n[b])):i=i.add(dh(m,n[h]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=mh(t,e);for(let a=0;a<s.windows&&o!==n0;a++){let{nextN:c,offset:u,isZero:h,isNeg:p}=o0(o,a,s);if(o=c,!h){let m=n[u];i=i.add(p?m.negate():m)}}return i},getPrecomputes(t,n,o){let i=yh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&yh.set(n,o(i))),i},wNAFCached(t,n,o){let i=gh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=gh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){i0(n,e),s0.set(t,n),yh.delete(t)}}}function jl(r,e,t,n){if(CE(t,r),IE(n,e),t.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,i=Yg(BigInt(t.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=Ro(s),c=new Array(Number(a)+1).fill(o),u=Math.floor((e.BITS-1)/s)*s,h=o;for(let p=u;p>=0;p-=s){c.fill(o);for(let w=0;w<n.length;w++){let b=n[w],g=Number(b>>BigInt(p)&a);c[g]=c[g].add(t[w])}let m=o;for(let w=c.length-1,b=o;w>0;w--)b=b.add(c[w]),m=m.add(b);if(h=h.add(m),p!==0)for(let w=0;w<s;w++)h=h.double()}return h}function da(r){return fh(r.Fp),Ar(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ph(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Mr=BigInt(0),kt=BigInt(1),a0=BigInt(2),TE=BigInt(8),BE={zip215:!0};function kE(r){let e=da(r);return Ar(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function c0(r){let e=kE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,u=a0<<BigInt(a*8)-kt,h=t.create,p=Gn(e.n,e.nBitLength),m=e.uvRatio||((k,C)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(C))}}catch{return{isValid:!1,value:Mr}}}),w=e.adjustScalarBytes||(k=>k),b=e.domain||((k,C,I)=>{if(Ur("phflag",I),C.length||I)throw new Error("Contexts/pre-hash are not supported");return k});function g(k,C,I=!1){let U=I?kt:Mr;St("coordinate "+k,C,U,u)}function y(k){if(!(k instanceof v))throw new Error("ExtendedPoint expected")}let S=Xi((k,C)=>{let{ex:I,ey:U,ez:q}=k,N=k.is0();C==null&&(C=N?TE:t.inv(q));let ie=h(I*C),fe=h(U*C),Q=h(q*C);if(N)return{x:Mr,y:kt};if(Q!==kt)throw new Error("invZ was invalid");return{x:ie,y:fe}}),T=Xi(k=>{let{a:C,d:I}=e;if(k.is0())throw new Error("bad point: ZERO");let{ex:U,ey:q,ez:N,et:ie}=k,fe=h(U*U),Q=h(q*q),ye=h(N*N),Be=h(ye*ye),Ee=h(fe*C),Le=h(ye*h(Ee+Q)),je=h(Be+h(I*h(fe*Q)));if(Le!==je)throw new Error("bad point: equation left != right (1)");let Ye=h(U*q),$e=h(N*ie);if(Ye!==$e)throw new Error("bad point: equation left != right (2)");return!0});class v{constructor(C,I,U,q){g("x",C),g("y",I),g("z",U,!0),g("t",q),this.ex=C,this.ey=I,this.ez=U,this.et=q,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(C){if(C instanceof v)throw new Error("extended point not allowed");let{x:I,y:U}=C||{};return g("x",I),g("y",U),new v(I,U,kt,h(I*U))}static normalizeZ(C){let I=t.invertBatch(C.map(U=>U.ez));return C.map((U,q)=>U.toAffine(I[q])).map(v.fromAffine)}static msm(C,I){return jl(v,p,C,I)}_setWindowSize(C){H.setWindowSize(this,C)}assertValidity(){T(this)}equals(C){y(C);let{ex:I,ey:U,ez:q}=this,{ex:N,ey:ie,ez:fe}=C,Q=h(I*fe),ye=h(N*q),Be=h(U*fe),Ee=h(ie*q);return Q===ye&&Be===Ee}is0(){return this.equals(v.ZERO)}negate(){return new v(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:C}=e,{ex:I,ey:U,ez:q}=this,N=h(I*I),ie=h(U*U),fe=h(a0*h(q*q)),Q=h(C*N),ye=I+U,Be=h(h(ye*ye)-N-ie),Ee=Q+ie,Le=Ee-fe,je=Q-ie,Ye=h(Be*Le),$e=h(Ee*je),bt=h(Be*je),Yt=h(Le*Ee);return new v(Ye,$e,Yt,bt)}add(C){y(C);let{a:I,d:U}=e,{ex:q,ey:N,ez:ie,et:fe}=this,{ex:Q,ey:ye,ez:Be,et:Ee}=C,Le=h(q*Q),je=h(N*ye),Ye=h(fe*U*Ee),$e=h(ie*Be),bt=h((q+N)*(Q+ye)-Le-je),Yt=$e-Ye,nn=$e+Ye,ea=h(je-I*Le),fl=h(bt*Yt),pl=h(nn*ea),hl=h(bt*ea),dl=h(Yt*nn);return new v(fl,pl,dl,hl)}subtract(C){return this.add(C.negate())}wNAF(C){return H.wNAFCached(this,C,v.normalizeZ)}multiply(C){let I=C;St("scalar",I,kt,n);let{p:U,f:q}=this.wNAF(I);return v.normalizeZ([U,q])[0]}multiplyUnsafe(C,I=v.ZERO){let U=C;return St("scalar",U,Mr,n),U===Mr?W:this.is0()||U===kt?this:H.wNAFCachedUnsafe(this,U,v.normalizeZ,I)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return H.unsafeLadder(this,n).is0()}toAffine(C){return S(this,C)}clearCofactor(){let{h:C}=e;return C===kt?this:this.multiplyUnsafe(C)}static fromHex(C,I=!1){let{d:U,a:q}=e,N=t.BYTES;C=De("pointHex",C,N),Ur("zip215",I);let ie=C.slice(),fe=C[N-1];ie[N-1]=fe&-129;let Q=jr(ie),ye=I?u:t.ORDER;St("pointHex.y",Q,Mr,ye);let Be=h(Q*Q),Ee=h(Be-kt),Le=h(U*Be-q),{isValid:je,value:Ye}=m(Ee,Le);if(!je)throw new Error("Point.fromHex: invalid y coordinate");let $e=(Ye&kt)===kt,bt=(fe&128)!==0;if(!I&&Ye===Mr&&bt)throw new Error("Point.fromHex: x=0 and x_0=1");return bt!==$e&&(Ye=h(-Ye)),v.fromAffine({x:Ye,y:Q})}static fromPrivateKey(C){let{scalar:I}=L(C);return P.multiply(I)}toRawBytes(){let{x:C,y:I}=this.toAffine(),U=Wn(I,t.BYTES);return U[U.length-1]|=C&kt?128:0,U}toHex(){return Fn(this.toRawBytes())}}v.BASE=new v(e.Gx,e.Gy,kt,h(e.Gx*e.Gy)),v.ZERO=new v(Mr,kt,kt,Mr);let{BASE:P,ZERO:W}=v,H=Ul(v,a*8);function O(k){return _e(k,n)}function K(k){return O(jr(k))}function L(k){let C=t.BYTES;k=De("private key",k,C);let I=De("hashed private key",i(k),2*C),U=w(I.slice(0,C)),q=I.slice(C,2*C),N=K(U);return{head:U,prefix:q,scalar:N}}function te(k){let{head:C,prefix:I,scalar:U}=L(k),q=P.multiply(U),N=q.toRawBytes();return{head:C,prefix:I,scalar:U,point:q,pointBytes:N}}function z(k){return te(k).pointBytes}function Y(k=new Uint8Array,...C){let I=qn(...C);return K(i(b(I,De("context",k),!!o)))}function le(k,C,I={}){k=De("message",k),o&&(k=o(k));let{prefix:U,scalar:q,pointBytes:N}=te(C),ie=Y(I.context,U,k),fe=P.multiply(ie).toRawBytes(),Q=Y(I.context,fe,N,k),ye=O(ie+Q*q);St("signature.s",ye,Mr,n);let Be=qn(fe,Wn(ye,t.BYTES));return De("result",Be,t.BYTES*2)}let R=BE;function D(k,C,I,U=R){let{context:q,zip215:N}=U,ie=t.BYTES;k=De("signature",k,2*ie),C=De("message",C),I=De("publicKey",I,ie),N!==void 0&&Ur("zip215",N),o&&(C=o(C));let fe=jr(k.slice(ie,2*ie)),Q,ye,Be;try{Q=v.fromHex(I,N),ye=v.fromHex(k.slice(0,ie),N),Be=P.multiplyUnsafe(fe)}catch{return!1}if(!N&&Q.isSmallOrder())return!1;let Ee=Y(q,ye.toRawBytes(),Q.toRawBytes(),C);return ye.add(Q.multiplyUnsafe(Ee)).subtract(Be).clearCofactor().equals(v.ZERO)}return P._setWindowSize(8),{CURVE:e,getPublicKey:z,sign:le,verify:D,ExtendedPoint:v,utils:{getExtendedPublicKey:te,randomPrivateKey:()=>s(t.BYTES),precompute(k=8,C=v.BASE){return C._setWindowSize(k),C.multiply(BigInt(3)),C}}}}var Yi=BigInt(0),xh=BigInt(1);function NE(r){return Ar(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function l0(r){let e=NE(r),{P:t}=e,n=T=>_e(T,t),o=e.montgomeryBits,i=Math.ceil(o/8),s=e.nByteLength,a=e.adjustScalarBytes||(T=>T),c=e.powPminus2||(T=>uh(T,t-BigInt(2),t));function u(T,v,P){let W=n(T*(v-P));return v=n(v-W),P=n(P+W),[v,P]}let h=(e.a-BigInt(2))/BigInt(4);function p(T,v){St("u",T,Yi,t),St("scalar",v,Yi,t);let P=v,W=T,H=xh,O=Yi,K=T,L=xh,te=Yi,z;for(let le=BigInt(o-1);le>=Yi;le--){let R=P>>le&xh;te^=R,z=u(te,H,K),H=z[0],K=z[1],z=u(te,O,L),O=z[0],L=z[1],te=R;let D=H+O,j=n(D*D),k=H-O,C=n(k*k),I=j-C,U=K+L,q=K-L,N=n(q*D),ie=n(U*k),fe=N+ie,Q=N-ie;K=n(fe*fe),L=n(W*n(Q*Q)),H=n(j*C),O=n(I*(j+n(h*I)))}z=u(te,H,K),H=z[0],K=z[1],z=u(te,O,L),O=z[0],L=z[1];let Y=c(O);return n(H*Y)}function m(T){return Wn(n(T),i)}function w(T){let v=De("u coordinate",T,i);return s===32&&(v[31]&=127),jr(v)}function b(T){let v=De("scalar",T),P=v.length;if(P!==i&&P!==s){let W=""+i+" or "+s;throw new Error("invalid scalar, expected "+W+" bytes, got "+P)}return jr(a(v))}function g(T,v){let P=w(v),W=b(T),H=p(P,W);if(H===Yi)throw new Error("invalid private or public key received");return m(H)}let y=m(e.Gu);function S(T){return g(T,y)}return{scalarMult:g,scalarMultBase:S,getSharedSecret:(T,v)=>g(T,v),getPublicKey:T=>S(T),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:y}}var ma=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),u0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),s8=BigInt(0),PE=BigInt(1),f0=BigInt(2),OE=BigInt(3),RE=BigInt(5),LE=BigInt(8);function h0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=ma,a=r*r%i*r%i,c=Ke(a,f0,i)*a%i,u=Ke(c,PE,i)*r%i,h=Ke(u,RE,i)*u%i,p=Ke(h,e,i)*h%i,m=Ke(p,t,i)*p%i,w=Ke(m,n,i)*m%i,b=Ke(w,o,i)*w%i,g=Ke(b,o,i)*w%i,y=Ke(g,e,i)*h%i;return{pow_p_5_8:Ke(y,f0,i)*r%i,b2:a}}function d0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function DE(r,e){let t=ma,n=_e(e*e*e,t),o=_e(n*n*e,t),i=h0(r*o).pow_p_5_8,s=_e(r*n*i,t),a=_e(e*s*s,t),c=s,u=_e(s*u0,t),h=a===r,p=a===_e(-r,t),m=a===_e(-r*u0,t);return h&&(s=c),(p||m)&&(s=u),e0(s,t)&&(s=_e(-s,t)),{isValid:h||p,value:s}}var p0=Gn(ma,void 0,!0),UE={a:p0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:p0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:LE,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:nh,randomBytes:fa,adjustScalarBytes:d0,uvRatio:DE},ya=c0(UE);var ga=l0({P:ma,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=ma,{pow_p_5_8:t,b2:n}=h0(r);return _e(Ke(t,OE,e)*n,e)},adjustScalarBytes:d0,randomBytes:fa});var Ml=32,Kl=64,bh=32;function m0(){let r=ya.utils.randomPrivateKey(),e=ya.getPublicKey(r);return{privateKey:jE(r,e),publicKey:e}}function y0(r,e){let t=r.subarray(0,bh);return ya.sign(e instanceof Uint8Array?e:e.subarray(),t)}function g0(r,e,t){return ya.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function jE(r,e){let t=new Uint8Array(Kl);for(let n=0;n<bh;n++)t[n]=r[n],t[bh+n]=e[n];return t}var wa=class{type="Ed25519";raw;constructor(e){this.raw=Vl(e,Ml)}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t){return g0(this.raw,t,e)}},Hl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Vl(e,Kl),this.publicKey=new wa(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e){return y0(this.raw,e)}};function vh(r){return r=Vl(r,Ml),new wa(r)}async function x0(){let{privateKey:r,publicKey:e}=m0();return new Hl(r,e)}function Vl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var ME=Math.pow(2,7),KE=Math.pow(2,14),HE=Math.pow(2,21),Ah=Math.pow(2,28),Sh=Math.pow(2,35),Eh=Math.pow(2,42),_h=Math.pow(2,49),Te=128,Et=127;function Ce(r){if(r<ME)return 1;if(r<KE)return 2;if(r<HE)return 3;if(r<Ah)return 4;if(r<Sh)return 5;if(r<Eh)return 6;if(r<_h)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ch(r,e,t=0){switch(Ce(r)){case 8:e[t++]=r&255|Te,r/=128;case 7:e[t++]=r&255|Te,r/=128;case 6:e[t++]=r&255|Te,r/=128;case 5:e[t++]=r&255|Te,r/=128;case 4:e[t++]=r&255|Te,r>>>=7;case 3:e[t++]=r&255|Te,r>>>=7;case 2:e[t++]=r&255|Te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function VE(r,e,t=0){switch(Ce(r)){case 8:e.set(t++,r&255|Te),r/=128;case 7:e.set(t++,r&255|Te),r/=128;case 6:e.set(t++,r&255|Te),r/=128;case 5:e.set(t++,r&255|Te),r/=128;case 4:e.set(t++,r&255|Te),r>>>=7;case 3:e.set(t++,r&255|Te),r>>>=7;case 2:e.set(t++,r&255|Te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ih(r,e){let t=r[e],n=0;if(n+=t&Et,t<Te||(t=r[e+1],n+=(t&Et)<<7,t<Te)||(t=r[e+2],n+=(t&Et)<<14,t<Te)||(t=r[e+3],n+=(t&Et)<<21,t<Te)||(t=r[e+4],n+=(t&Et)*Ah,t<Te)||(t=r[e+5],n+=(t&Et)*Sh,t<Te)||(t=r[e+6],n+=(t&Et)*Eh,t<Te)||(t=r[e+7],n+=(t&Et)*_h,t<Te))return n;throw new RangeError("Could not decode varint")}function $E(r,e){let t=r.get(e),n=0;if(n+=t&Et,t<Te||(t=r.get(e+1),n+=(t&Et)<<7,t<Te)||(t=r.get(e+2),n+=(t&Et)<<14,t<Te)||(t=r.get(e+3),n+=(t&Et)<<21,t<Te)||(t=r.get(e+4),n+=(t&Et)*Ah,t<Te)||(t=r.get(e+5),n+=(t&Et)*Sh,t<Te)||(t=r.get(e+6),n+=(t&Et)*Eh,t<Te)||(t=r.get(e+7),n+=(t&Et)*_h,t<Te))return n;throw new RangeError("Could not decode varint")}function Lt(r,e,t=0){return e==null&&(e=et(Ce(r))),e instanceof Uint8Array?Ch(r,e,t):VE(r,e,t)}function Nt(r,e=0){return r instanceof Uint8Array?Ih(r,e):$E(r,e)}var Th=new Float32Array([-0]),Xn=new Uint8Array(Th.buffer);function b0(r,e,t){Th[0]=r,e[t]=Xn[0],e[t+1]=Xn[1],e[t+2]=Xn[2],e[t+3]=Xn[3]}function v0(r,e){return Xn[0]=r[e],Xn[1]=r[e+1],Xn[2]=r[e+2],Xn[3]=r[e+3],Th[0]}var Bh=new Float64Array([-0]),_t=new Uint8Array(Bh.buffer);function A0(r,e,t){Bh[0]=r,e[t]=_t[0],e[t+1]=_t[1],e[t+2]=_t[2],e[t+3]=_t[3],e[t+4]=_t[4],e[t+5]=_t[5],e[t+6]=_t[6],e[t+7]=_t[7]}function S0(r,e){return _t[0]=r[e],_t[1]=r[e+1],_t[2]=r[e+2],_t[3]=r[e+3],_t[4]=r[e+4],_t[5]=r[e+5],_t[6]=r[e+6],_t[7]=r[e+7],Bh[0]}var FE=BigInt(Number.MAX_SAFE_INTEGER),WE=BigInt(Number.MIN_SAFE_INTEGER),Zt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Do;if(e<FE&&e>WE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>E0&&(o=0n,++n>E0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Do;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Do}},Do=new Zt(0,0);Do.toBigInt=function(){return 0n};Do.zzEncode=Do.zzDecode=function(){return this};Do.length=function(){return 1};var E0=4294967296n;function _0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function C0(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function kh(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Sr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function $l(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Nh=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Sr(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Sr(this,4);return $l(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Sr(this,4);return $l(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Sr(this,4);let e=v0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Sr(this,4);let e=S0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Sr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return C0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Sr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Sr(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Zt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Sr(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Sr(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Sr(this,8);let e=$l(this.buf,this.pos+=4),t=$l(this.buf,this.pos+=4);return new Zt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ih(this.buf,this.pos);return this.pos+=Ce(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ph(r){return new Nh(r instanceof Uint8Array?r:r.subarray())}function Er(r,e,t){let n=Ph(r);return e.decode(n,void 0,t)}function Oh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return et(s);o+s>e&&(n=et(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Uo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Rh(){}var Dh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},qE=Oh();function GE(r){return globalThis.Buffer!=null?et(r):qE(r)}var ba=class{len;head;tail;states;constructor(){this.len=0,this.head=new Uo(Rh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Uo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Uh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Fl,10,Zt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Zt.fromBigInt(e);return this._push(Fl,t.length(),t)}uint64Number(e){return this._push(Ch,Ce(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Zt.fromBigInt(e).zzEncode();return this._push(Fl,t.length(),t)}sint64Number(e){let t=Zt.fromNumber(e).zzEncode();return this._push(Fl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Lh,1,e?1:0)}fixed32(e){return this._push(xa,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Zt.fromBigInt(e);return this._push(xa,4,t.lo)._push(xa,4,t.hi)}fixed64Number(e){let t=Zt.fromNumber(e);return this._push(xa,4,t.lo)._push(xa,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(b0,4,e)}double(e){return this._push(A0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Lh,1,0):this.uint32(t)._push(XE,t,e)}string(e){let t=_0(e);return t!==0?this.uint32(t)._push(kh,t,e):this._push(Lh,1,0)}fork(){return this.states=new Dh(this),this.head=this.tail=new Uo(Rh,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Uo(Rh,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=GE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Lh(r,e,t){e[t]=r&255}function zE(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Uh=class extends Uo{next;constructor(e,t){super(zE,e,t),this.next=void 0}};function Fl(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function xa(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function XE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ba.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(YE,e,r),this},ba.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(ZE,e,r),this});function YE(r,e,t){e.set(r,t)}function ZE(r,e,t){r.length<40?kh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function jh(){return new ba}function _r(r,e){let t=jh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Zi;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Zi||(Zi={}));function Wl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function jo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return Wl("enum",Zi.VARINT,t,n)}function Cr(r,e){return Wl("message",Zi.LENGTH_DELIMITED,r,e)}var va=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Mh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Mh||(Mh={}));(function(r){r.codec=()=>jo(Mh)})(tt||(tt={}));var Kr;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),tt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(Kr||(Kr={}));var Kh;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),tt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(Kh||(Kh={}));var Aa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Sa=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},ql=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var B0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new ql("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Yn=B0;var _a={};vt(_a,{MAX_RSA_KEY_SIZE:()=>Hh,generateRSAKeyPair:()=>Yh,jwkToJWKKeyPair:()=>O0,jwkToPkcs1:()=>t2,jwkToPkix:()=>Wh,jwkToRSAPrivateKey:()=>Xh,pkcs1MessageToJwk:()=>$h,pkcs1MessageToRSAPrivateKey:()=>qh,pkcs1ToJwk:()=>e2,pkcs1ToRSAPrivateKey:()=>P0,pkixMessageToJwk:()=>Fh,pkixMessageToRSAPublicKey:()=>zh,pkixToJwk:()=>r2,pkixToRSAPublicKey:()=>Gh});var Ji=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=_a.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Qe.createV1(114,this._multihash)}toString(){return Ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t){return N0(this.jwk,t,e)}},Ea=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=_a.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e){return k0(this.jwk,e)}};var Hh=8192,Vh=18,JE=1062,QE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function e2(r){let e=an(r);return $h(e)}function $h(r){return{n:ce(r[1],"base64url"),e:ce(r[2],"base64url"),d:ce(r[3],"base64url"),p:ce(r[4],"base64url"),q:ce(r[5],"base64url"),dp:ce(r[6],"base64url"),dq:ce(r[7],"base64url"),qi:ce(r[8],"base64url"),kty:"RSA"}}function t2(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return xr([Bt(Uint8Array.from([0])),Bt(de(r.n,"base64url")),Bt(de(r.e,"base64url")),Bt(de(r.d,"base64url")),Bt(de(r.p,"base64url")),Bt(de(r.q,"base64url")),Bt(de(r.dp,"base64url")),Bt(de(r.dq,"base64url")),Bt(de(r.qi,"base64url"))]).subarray()}function r2(r){let e=an(r,{offset:0});return Fh(e)}function Fh(r){let e=an(r[1],{offset:0});return{kty:"RSA",n:ce(e[0],"base64url"),e:ce(e[1],"base64url")}}function Wh(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return xr([QE,la(xr([Bt(de(r.n,"base64url")),Bt(de(r.e,"base64url"))]))]).subarray()}function P0(r){let e=an(r);return qh(e)}function qh(r){let e=$h(r);return Xh(e)}function Gh(r,e){if(r.byteLength>=JE)throw new Ki("Key size is too large");let t=an(r,{offset:0});return zh(t,r,e)}function zh(r,e,t){let n=Fh(r);if(t==null){let o=vr(Kr.encode({Type:tt.RSA,Data:e}));t=At(Vh,o)}return new Ji(n,t)}function Xh(r){if(L0(r)>Hh)throw new ve("Key size is too large");let e=O0(r),t=vr(Kr.encode({Type:tt.RSA,Data:Wh(e.publicKey)})),n=At(Vh,t);return new Ea(e.privateKey,new Ji(e.publicKey,n))}async function Yh(r){if(r>Hh)throw new ve("Key size is too large");let e=await R0(r),t=vr(Kr.encode({Type:tt.RSA,Data:Wh(e.publicKey)})),n=At(Vh,t);return new Ea(e.privateKey,new Ji(e.publicKey,n))}function O0(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function R0(r){let e=await Yn.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await n2(e);return{privateKey:t[0],publicKey:t[1]}}async function k0(r,e){let t=await Yn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Yn.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function N0(r,e,t){let n=await Yn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Yn.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function n2(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([Yn.get().subtle.exportKey("jwk",r.privateKey),Yn.get().subtle.exportKey("jwk",r.publicKey)])}function L0(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return de(r.n,"base64url").length*8}var Gl=class extends Gi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ua(e);let n=Mn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return qi(this),this.iHash.update(e),this}digestInto(e){qi(this),Wi(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qi=(r,e,t)=>new Gl(r,e).update(t).digest();Qi.create=(r,e)=>new Gl(r,e);function D0(r){r.lowS!==void 0&&Ur("lowS",r.lowS),r.prehash!==void 0&&Ur("prehash",r.prehash)}function o2(r){let e=da(r);Ar(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var Zh=class extends Error{constructor(e=""){super(e)}},un={Err:Zh,_tlv:{encode:(r,e)=>{let{Err:t}=un;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=pa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?pa(o.length/2|128):"";return pa(r)+i+o+e},decode(r,e){let{Err:t}=un,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of u)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=un;if(r<fn)throw new e("integer: negative integers are not allowed");let t=pa(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=un;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ln(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=un,o=De("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(r){let{_tlv:e,_int:t}=un,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},fn=BigInt(0),ut=BigInt(1),Bk=BigInt(2),U0=BigInt(3),kk=BigInt(4);function i2(r){let e=o2(r),{Fp:t}=e,n=Gn(e.n,e.nBitLength),o=e.toBytes||((g,y,S)=>{let T=y.toAffine();return qn(Uint8Array.from([4]),t.toBytes(T.x),t.toBytes(T.y))}),i=e.fromBytes||(g=>{let y=g.subarray(1),S=t.fromBytes(y.subarray(0,t.BYTES)),T=t.fromBytes(y.subarray(t.BYTES,2*t.BYTES));return{x:S,y:T}});function s(g){let{a:y,b:S}=e,T=t.sqr(g),v=t.mul(T,g);return t.add(t.add(v,t.mul(g,y)),S)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Ll(g,ut,e.n)}function c(g){let{allowedPrivateKeyLengths:y,nByteLength:S,wrapPrivateKey:T,n:v}=e;if(y&&typeof g!="bigint"){if(Po(g)&&(g=Fn(g)),typeof g!="string"||!y.includes(g.length))throw new Error("invalid private key");g=g.padStart(S*2,"0")}let P;try{P=typeof g=="bigint"?g:ln(De("private key",g,S))}catch{throw new Error("invalid private key, expected hex or "+S+" bytes, got "+typeof g)}return T&&(P=_e(P,v)),St("private key",P,ut,v),P}function u(g){if(!(g instanceof m))throw new Error("ProjectivePoint expected")}let h=Xi((g,y)=>{let{px:S,py:T,pz:v}=g;if(t.eql(v,t.ONE))return{x:S,y:T};let P=g.is0();y==null&&(y=P?t.ONE:t.inv(v));let W=t.mul(S,y),H=t.mul(T,y),O=t.mul(v,y);if(P)return{x:t.ZERO,y:t.ZERO};if(!t.eql(O,t.ONE))throw new Error("invZ was invalid");return{x:W,y:H}}),p=Xi(g=>{if(g.is0()){if(e.allowInfinityPoint&&!t.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:y,y:S}=g.toAffine();if(!t.isValid(y)||!t.isValid(S))throw new Error("bad point: x or y not FE");let T=t.sqr(S),v=s(y);if(!t.eql(T,v))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(y,S,T){if(y==null||!t.isValid(y))throw new Error("x required");if(S==null||!t.isValid(S))throw new Error("y required");if(T==null||!t.isValid(T))throw new Error("z required");this.px=y,this.py=S,this.pz=T,Object.freeze(this)}static fromAffine(y){let{x:S,y:T}=y||{};if(!y||!t.isValid(S)||!t.isValid(T))throw new Error("invalid affine point");if(y instanceof m)throw new Error("projective point not allowed");let v=P=>t.eql(P,t.ZERO);return v(S)&&v(T)?m.ZERO:new m(S,T,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){let S=t.invertBatch(y.map(T=>T.pz));return y.map((T,v)=>T.toAffine(S[v])).map(m.fromAffine)}static fromHex(y){let S=m.fromAffine(i(De("pointHex",y)));return S.assertValidity(),S}static fromPrivateKey(y){return m.BASE.multiply(c(y))}static msm(y,S){return jl(m,n,y,S)}_setWindowSize(y){b.setWindowSize(this,y)}assertValidity(){p(this)}hasEvenY(){let{y}=this.toAffine();if(t.isOdd)return!t.isOdd(y);throw new Error("Field doesn't support isOdd")}equals(y){u(y);let{px:S,py:T,pz:v}=this,{px:P,py:W,pz:H}=y,O=t.eql(t.mul(S,H),t.mul(P,v)),K=t.eql(t.mul(T,H),t.mul(W,v));return O&&K}negate(){return new m(this.px,t.neg(this.py),this.pz)}double(){let{a:y,b:S}=e,T=t.mul(S,U0),{px:v,py:P,pz:W}=this,H=t.ZERO,O=t.ZERO,K=t.ZERO,L=t.mul(v,v),te=t.mul(P,P),z=t.mul(W,W),Y=t.mul(v,P);return Y=t.add(Y,Y),K=t.mul(v,W),K=t.add(K,K),H=t.mul(y,K),O=t.mul(T,z),O=t.add(H,O),H=t.sub(te,O),O=t.add(te,O),O=t.mul(H,O),H=t.mul(Y,H),K=t.mul(T,K),z=t.mul(y,z),Y=t.sub(L,z),Y=t.mul(y,Y),Y=t.add(Y,K),K=t.add(L,L),L=t.add(K,L),L=t.add(L,z),L=t.mul(L,Y),O=t.add(O,L),z=t.mul(P,W),z=t.add(z,z),L=t.mul(z,Y),H=t.sub(H,L),K=t.mul(z,te),K=t.add(K,K),K=t.add(K,K),new m(H,O,K)}add(y){u(y);let{px:S,py:T,pz:v}=this,{px:P,py:W,pz:H}=y,O=t.ZERO,K=t.ZERO,L=t.ZERO,te=e.a,z=t.mul(e.b,U0),Y=t.mul(S,P),le=t.mul(T,W),R=t.mul(v,H),D=t.add(S,T),j=t.add(P,W);D=t.mul(D,j),j=t.add(Y,le),D=t.sub(D,j),j=t.add(S,v);let k=t.add(P,H);return j=t.mul(j,k),k=t.add(Y,R),j=t.sub(j,k),k=t.add(T,v),O=t.add(W,H),k=t.mul(k,O),O=t.add(le,R),k=t.sub(k,O),L=t.mul(te,j),O=t.mul(z,R),L=t.add(O,L),O=t.sub(le,L),L=t.add(le,L),K=t.mul(O,L),le=t.add(Y,Y),le=t.add(le,Y),R=t.mul(te,R),j=t.mul(z,j),le=t.add(le,R),R=t.sub(Y,R),R=t.mul(te,R),j=t.add(j,R),Y=t.mul(le,j),K=t.add(K,Y),Y=t.mul(k,j),O=t.mul(D,O),O=t.sub(O,Y),Y=t.mul(D,le),L=t.mul(k,L),L=t.add(L,Y),new m(O,K,L)}subtract(y){return this.add(y.negate())}is0(){return this.equals(m.ZERO)}wNAF(y){return b.wNAFCached(this,y,m.normalizeZ)}multiplyUnsafe(y){let{endo:S,n:T}=e;St("scalar",y,fn,T);let v=m.ZERO;if(y===fn)return v;if(this.is0()||y===ut)return this;if(!S||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,y,m.normalizeZ);let{k1neg:P,k1:W,k2neg:H,k2:O}=S.splitScalar(y),K=v,L=v,te=this;for(;W>fn||O>fn;)W&ut&&(K=K.add(te)),O&ut&&(L=L.add(te)),te=te.double(),W>>=ut,O>>=ut;return P&&(K=K.negate()),H&&(L=L.negate()),L=new m(t.mul(L.px,S.beta),L.py,L.pz),K.add(L)}multiply(y){let{endo:S,n:T}=e;St("scalar",y,ut,T);let v,P;if(S){let{k1neg:W,k1:H,k2neg:O,k2:K}=S.splitScalar(y),{p:L,f:te}=this.wNAF(H),{p:z,f:Y}=this.wNAF(K);L=b.constTimeNegate(W,L),z=b.constTimeNegate(O,z),z=new m(t.mul(z.px,S.beta),z.py,z.pz),v=L.add(z),P=te.add(Y)}else{let{p:W,f:H}=this.wNAF(y);v=W,P=H}return m.normalizeZ([v,P])[0]}multiplyAndAddUnsafe(y,S,T){let v=m.BASE,P=(H,O)=>O===fn||O===ut||!H.equals(v)?H.multiplyUnsafe(O):H.multiply(O),W=P(this,S).add(P(y,T));return W.is0()?void 0:W}toAffine(y){return h(this,y)}isTorsionFree(){let{h:y,isTorsionFree:S}=e;if(y===ut)return!0;if(S)return S(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:y,clearCofactor:S}=e;return y===ut?this:S?S(m,this):this.multiplyUnsafe(e.h)}toRawBytes(y=!0){return Ur("isCompressed",y),this.assertValidity(),o(m,this,y)}toHex(y=!0){return Ur("isCompressed",y),Fn(this.toRawBytes(y))}}m.BASE=new m(e.Gx,e.Gy,t.ONE),m.ZERO=new m(t.ZERO,t.ONE,t.ZERO);let w=e.nBitLength,b=Ul(m,e.endo?Math.ceil(w/2):w);return{CURVE:e,ProjectivePoint:m,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function s2(r){let e=da(r);return Ar(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function j0(r){let e=s2(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(R){return _e(R,n)}function a(R){return Dl(R,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:h,isWithinCurveOrder:p}=i2({...e,toBytes(R,D,j){let k=D.toAffine(),C=t.toBytes(k.x),I=qn;return Ur("isCompressed",j),j?I(Uint8Array.from([D.hasEvenY()?2:3]),C):I(Uint8Array.from([4]),C,t.toBytes(k.y))},fromBytes(R){let D=R.length,j=R[0],k=R.subarray(1);if(D===o&&(j===2||j===3)){let C=ln(k);if(!Ll(C,ut,t.ORDER))throw new Error("Point is not on curve");let I=h(C),U;try{U=t.sqrt(I)}catch(ie){let fe=ie instanceof Error?": "+ie.message:"";throw new Error("Point is not on curve"+fe)}let q=(U&ut)===ut;return(j&1)===1!==q&&(U=t.neg(U)),{x:C,y:U}}else if(D===i&&j===4){let C=t.fromBytes(k.subarray(0,t.BYTES)),I=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:C,y:I}}else{let C=o,I=i;throw new Error("invalid Point, expected length of "+C+", or uncompressed "+I+", got "+D)}}}),m=R=>Fn(Oo(R,e.nByteLength));function w(R){let D=n>>ut;return R>D}function b(R){return w(R)?s(-R):R}let g=(R,D,j)=>ln(R.slice(D,j));class y{constructor(D,j,k){St("r",D,ut,n),St("s",j,ut,n),this.r=D,this.s=j,k!=null&&(this.recovery=k),Object.freeze(this)}static fromCompact(D){let j=e.nByteLength;return D=De("compactSignature",D,j*2),new y(g(D,0,j),g(D,j,2*j))}static fromDER(D){let{r:j,s:k}=un.toSig(De("DER",D));return new y(j,k)}assertValidity(){}addRecoveryBit(D){return new y(this.r,this.s,D)}recoverPublicKey(D){let{r:j,s:k,recovery:C}=this,I=H(De("msgHash",D));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");let U=C===2||C===3?j+e.n:j;if(U>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let q=(C&1)===0?"02":"03",N=c.fromHex(q+m(U)),ie=a(U),fe=s(-I*ie),Q=s(k*ie),ye=c.BASE.multiplyAndAddUnsafe(N,fe,Q);if(!ye)throw new Error("point at infinify");return ye.assertValidity(),ye}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return ha(this.toDERHex())}toDERHex(){return un.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ha(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let S={isValidPrivateKey(R){try{return u(R),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let R=hh(e.n);return r0(e.randomBytes(R),e.n)},precompute(R=8,D=c.BASE){return D._setWindowSize(R),D.multiply(BigInt(3)),D}};function T(R,D=!0){return c.fromPrivateKey(R).toRawBytes(D)}function v(R){let D=Po(R),j=typeof R=="string",k=(D||j)&&R.length;return D?k===o||k===i:j?k===2*o||k===2*i:R instanceof c}function P(R,D,j=!0){if(v(R))throw new Error("first arg must be private key");if(!v(D))throw new Error("second arg must be public key");return c.fromHex(D).multiply(u(R)).toRawBytes(j)}let W=e.bits2int||function(R){if(R.length>8192)throw new Error("input is too large");let D=ln(R),j=R.length*8-e.nBitLength;return j>0?D>>BigInt(j):D},H=e.bits2int_modN||function(R){return s(W(R))},O=Ro(e.nBitLength);function K(R){return St("num < 2^"+e.nBitLength,R,fn,O),Oo(R,e.nByteLength)}function L(R,D,j=te){if(["recovered","canonical"].some(Ee=>Ee in j))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:C}=e,{lowS:I,prehash:U,extraEntropy:q}=j;I==null&&(I=!0),R=De("msgHash",R),D0(j),U&&(R=De("prehashed msgHash",k(R)));let N=H(R),ie=u(D),fe=[K(ie),K(N)];if(q!=null&&q!==!1){let Ee=q===!0?C(t.BYTES):q;fe.push(De("extraEntropy",Ee))}let Q=qn(...fe),ye=N;function Be(Ee){let Le=W(Ee);if(!p(Le))return;let je=a(Le),Ye=c.BASE.multiply(Le).toAffine(),$e=s(Ye.x);if($e===fn)return;let bt=s(je*s(ye+$e*ie));if(bt===fn)return;let Yt=(Ye.x===$e?0:2)|Number(Ye.y&ut),nn=bt;return I&&w(bt)&&(nn=b(bt),Yt^=1),new y($e,nn,Yt)}return{seed:Q,k2sig:Be}}let te={lowS:e.lowS,prehash:!1},z={lowS:e.lowS,prehash:!1};function Y(R,D,j=te){let{seed:k,k2sig:C}=L(R,D,j),I=e;return Zg(I.hash.outputLen,I.nByteLength,I.hmac)(k,C)}c.BASE._setWindowSize(8);function le(R,D,j,k=z){let C=R;D=De("msgHash",D),j=De("publicKey",j);let{lowS:I,prehash:U,format:q}=k;if(D0(k),"strict"in k)throw new Error("options.strict was renamed to lowS");if(q!==void 0&&q!=="compact"&&q!=="der")throw new Error("format must be compact or der");let N=typeof C=="string"||Po(C),ie=!N&&!q&&typeof C=="object"&&C!==null&&typeof C.r=="bigint"&&typeof C.s=="bigint";if(!N&&!ie)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let fe,Q;try{if(ie&&(fe=new y(C.r,C.s)),N){try{q!=="compact"&&(fe=y.fromDER(C))}catch(Yt){if(!(Yt instanceof un.Err))throw Yt}!fe&&q!=="der"&&(fe=y.fromCompact(C))}Q=c.fromHex(j)}catch{return!1}if(!fe||I&&fe.hasHighS())return!1;U&&(D=e.hash(D));let{r:ye,s:Be}=fe,Ee=H(D),Le=a(Be),je=s(Ee*Le),Ye=s(ye*Le),$e=c.BASE.multiplyAndAddUnsafe(Q,je,Ye)?.toAffine();return $e?s($e.x)===ye:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:P,sign:Y,verify:le,ProjectivePoint:c,Signature:y,utils:S}}function a2(r){return{hash:r,hmac:(e,...t)=>Qi(r,e,Qp(...t)),randomBytes:fa}}function M0(r,e){let t=n=>j0({...r,...a2(n)});return{...t(e),create:t}}var V0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),K0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),c2=BigInt(1),Jh=BigInt(2),H0=(r,e)=>(r+e/Jh)/e;function l2(r){let e=V0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,h=u*u*r%e,p=Ke(h,t,e)*h%e,m=Ke(p,t,e)*h%e,w=Ke(m,Jh,e)*u%e,b=Ke(w,o,e)*w%e,g=Ke(b,i,e)*b%e,y=Ke(g,a,e)*g%e,S=Ke(y,c,e)*y%e,T=Ke(S,a,e)*g%e,v=Ke(T,t,e)*h%e,P=Ke(v,s,e)*b%e,W=Ke(P,n,e)*u%e,H=Ke(W,Jh,e);if(!Qh.eql(Qh.sqr(H),r))throw new Error("Cannot find square root");return H}var Qh=Gn(V0,void 0,void 0,{sqrt:l2}),or=M0({a:BigInt(0),b:BigInt(7),Fp:Qh,n:K0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=K0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-c2*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=H0(i*r,e),c=H0(-n*r,e),u=_e(r-a*t-c*o,e),h=_e(-a*n-c*i,e),p=u>s,m=h>s;if(p&&(u=e-u),m&&(h=e-h),u>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:u,k2neg:m,k2:h}}}},vr),Mk=BigInt(0);var Kk=or.ProjectivePoint;function ed(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function $0(r,e){let t=nr.digest(e instanceof Uint8Array?e:e.subarray());if(ed(t))return t.then(({digest:n})=>or.sign(n,r).toDERRawBytes()).catch(n=>{throw new Aa(String(n))});try{return or.sign(t.digest,r).toDERRawBytes()}catch(n){throw new Aa(String(n))}}function F0(r,e,t){let n=nr.digest(t instanceof Uint8Array?t:t.subarray());if(ed(n))return n.then(({digest:o})=>or.verify(e,o,r)).catch(o=>{throw new Sa(String(o))});try{return or.verify(e,n.digest,r)}catch(o){throw new Sa(String(o))}}var Ca=class{type="secp256k1";raw;_key;constructor(e){this._key=G0(e),this.raw=W0(this._key)}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t){return F0(this._key,t,e)}},zl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=q0(e),this.publicKey=new Ca(t??z0(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e){return $0(this.raw,e)}};function td(r){return new Ca(r)}async function X0(){let r=u2();return new zl(r)}function W0(r){return or.ProjectivePoint.fromHex(r).toRawBytes(!0)}function q0(r){try{return or.getPublicKey(r,!0),r}catch(e){throw new ra(String(e))}}function G0(r){try{return or.ProjectivePoint.fromHex(r),r}catch(e){throw new Ki(String(e))}}function z0(r){try{return or.getPublicKey(r,!0)}catch(e){throw new ra(String(e))}}function u2(){return or.utils.randomPrivateKey()}async function Y0(r,e){if(r==="Ed25519")return x0();if(r==="secp256k1")return X0();if(r==="RSA")return Yh(f2(e));if(r==="ECDSA")return Kg(p2(e));throw new Rn}function Ia(r,e){let{Type:t,Data:n}=Kr.decode(r),o=n??new Uint8Array;switch(t){case tt.RSA:return Gh(o,e);case tt.Ed25519:return vh(o);case tt.secp256k1:return td(o);case tt.ECDSA:return Jp(o);default:throw new Rn}}function Z0(r){let{Type:e,Data:t}=Kr.decode(r.digest),n=t??new Uint8Array;switch(e){case tt.Ed25519:return vh(n);case tt.secp256k1:return td(n);case tt.ECDSA:return Jp(n);default:throw new Rn}}function jn(r){return Kr.encode({Type:tt[r.type],Data:r.raw})}function f2(r){return r==null?2048:parseInt(r,10)}function p2(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function Xl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var J0=Symbol.for("nodejs.util.inspect.custom"),h2=114,Ta=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[_p]=!0;toString(){return this.string==null&&(this.string=Ne.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Qe.createV1(h2,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ge(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ge(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[J0](){return`PeerId(${this.toString()})`}},Ba=class extends Ta{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},ka=class extends Ta{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Na=class extends Ta{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},d2=2336,Pa=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=wr.digest(de(this.url))}[J0](){return`PeerId(${this.url})`}[_p]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Qe.createV1(d2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ce(e)),e.toString()===this.toString())}};var m2=114,Q0=2336;function es(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Un(Ne.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return y2(Qe.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Un(e.decode(r))}return ew(t)}function rd(r){if(r.type==="Ed25519")return new ka({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Na({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Ba({multihash:r.toCID().multihash,publicKey:r});throw new Rn}function ew(r){if(w2(r))return new Ba({multihash:r});if(g2(r))try{let e=Z0(r);if(e.type==="Ed25519")return new ka({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Na({multihash:r,publicKey:e})}catch{let t=ce(r.digest);return new Pa(new URL(t))}throw new Al("Supplied PeerID Multihash is invalid")}function y2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==m2&&r.code!==Q0)throw new vl("Supplied PeerID CID is invalid");if(r.code===Q0){let e=ce(r.multihash.digest);return new Pa(new URL(e))}return ew(r.multihash)}function g2(r){return r.code===wr.code}function w2(r){return r.code===nr.code}var Yl=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let m=Number.parseInt(p,e);if(!Number.isNaN(m))return m});if(h===void 0)break;if(i*=e,i+=h,i>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var tw=45,x2=15,ts=new Yl;function nd(r){if(!(r.length>x2))return ts.new(r).parseWith(()=>ts.readIPv4Addr())}function od(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>tw))return ts.new(r).parseWith(()=>ts.readIPv6Addr())}function Zl(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>tw)return;let t=ts.new(r).parseWith(()=>ts.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var W5=parseInt("0xFFFF",16),q5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Jl(r){return!!nd(r)}function Ql(r){return!!od(r)}function eu(r){return!!Zl(r)}var ow=Jl,E2=Ql,id=function(r){let e=0;if(r=r.toString().trim(),ow(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(E2(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=ow(t[n]),s;i&&(s=id(t[n]),t[n]=ce(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ce(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},iw=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var rs={},sd={},C2=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];C2.forEach(r=>{let e=I2(...r);sd[e.code]=e,rs[e.name]=e});function I2(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Oe(r){if(typeof r=="number"){if(sd[r]!=null)return sd[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(rs[r]!=null)return rs[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var B4=Oe("ip4"),k4=Oe("ip6"),N4=Oe("ipcidr");function ud(r,e){switch(Oe(r).code){case 4:case 41:return B2(e);case 42:return ld(e);case 43:return ce(e,"base10");case 6:case 273:case 33:case 132:return cw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ld(e);case 421:return O2(e);case 444:return aw(e);case 445:return aw(e);case 466:return P2(e);case 481:return globalThis.encodeURIComponent(ld(e));default:return ce(e,"base16")}}function fd(r,e){switch(Oe(r).code){case 4:return sw(e);case 41:return sw(e);case 42:return cd(e);case 43:return de(e,"base10");case 6:case 273:case 33:case 132:return pd(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return cd(e);case 421:return k2(e);case 444:return R2(e);case 445:return L2(e);case 466:return N2(e);case 481:return cd(globalThis.decodeURIComponent(e));default:return de(e,"base16")}}var ad=Object.values(Bo).map(r=>r.decoder),T2=function(){let r=ad[0].or(ad[1]);return ad.slice(2).forEach(e=>r=r.or(e)),r}();function sw(r){if(!eu(r))throw new Error("invalid ip address");return id(r)}function B2(r){let e=iw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!eu(e))throw new Error("invalid ip address");return e}function pd(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function cw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function cd(r){let e=de(r),t=Uint8Array.from(Lt(e.length));return st([t,e],t.length+e.length)}function ld(r){let e=Nt(r);if(r=r.slice(Ce(e)),r.length!==e)throw new Error("inconsistent lengths");return ce(r)}function k2(r){let e;r[0]==="Q"||r[0]==="1"?e=Un(Ne.decode(`z${r}`)).bytes:e=Qe.parse(r).multihash.bytes;let t=Uint8Array.from(Lt(e.length));return st([t,e],t.length+e.length)}function N2(r){let e=T2.decode(r),t=Uint8Array.from(Lt(e.length));return st([t,e],t.length+e.length)}function P2(r){let e=Nt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ce(t,"base64url")}function O2(r){let e=Nt(r),t=r.slice(Ce(e));if(t.length!==e)throw new Error("inconsistent lengths");return ce(t,"base58btc")}function R2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=sn.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pd(n);return st([t,o],t.length+o.length)}function L2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=sn.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pd(n);return st([t,o],t.length+o.length)}function aw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ce(e,"base32"),o=cw(t);return`${n}:${o}`}function lw(r){r=hd(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Oe(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new tu("invalid address: "+r);if(a.path===!0){n=hd(o.slice(i).join("/")),e.push([a.code,fd(a.code,n)]),t.push([a.code,n]);break}let c=fd(a.code,o[i]);e.push([a.code,c]),t.push([a.code,ud(a.code,c)])}return{string:uw(t),bytes:ru(e),tuples:e,stringTuples:t,path:n}}function dd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=Nt(r,o),s=Ce(i),a=Oe(i),c=D2(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let u=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new tu("Invalid address Uint8Array: "+ce(r,"base16"));e.push([i,u]);let h=ud(i,u);if(t.push([i,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:uw(t),tuples:e,stringTuples:t,path:n}}function uw(r){let e=[];return r.map(t=>{let n=Oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),hd(e.join("/"))}function ru(r){return st(r.map(e=>{let t=Oe(e[0]),n=Uint8Array.from(Lt(t.code));return e.length>1&&e[1]!=null&&(n=st([n,e[1]])),n}))}function D2(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Nt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ce(t)}}function hd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var tu=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var U2=Symbol.for("nodejs.util.inspect.custom"),yd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),j2=[Oe("dns").code,Oe("dns4").code,Oe("dns6").code,Oe("dnsaddr").code],md=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},nu=class r{bytes;#e;#t;#r;#n;[yd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=dd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lw(e)}else if(pw(e))t=dd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=Oe("tcp"),a=Oe("udp"),c=Oe("ip4"),u=Oe("ip6"),h=Oe("dns6"),p=Oe("ip6zone");for(let[w,b]of this.stringTuples())w===p.code&&(i=`%${b??""}`),j2.includes(w)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${i}`,e=w===h.code?6:4),(w===s.code||w===a.code)&&(t=Oe(w).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(w===c.code||w===u.code)&&(t=Oe(w).name==="tcp"?"tcp":"udp",n=`${b??""}${i}`,e=w===u.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},Oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Oe(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ru(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===rs.p2p.code&&e.push([n,o]),n===rs["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ce(Ne.decode(`z${n}`),"base58btc"):ce(Qe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ge(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=fw.get(t.name);if(n==null)throw new md(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Hr(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[U2](){return`Multiaddr(${this.#e})`}};var fw=new Map;function pw(r){return!!r?.[yd]}function Hr(r){return new nu(r)}var M2=r=>r.toString().split("/").slice(1),ns=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),be=r=>({match:e=>ns(t=>t===r).match(e),pattern:r}),Mo=()=>({match:r=>ns(e=>typeof e=="string").match(r),pattern:"{string}"}),Oa=()=>({match:r=>ns(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),ke=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Ne.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ra=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{To.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ie=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ct=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),Ae=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function Ue(...r){function e(o){let i=M2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var K2=ke(),c6=Ue(K2),iu=Ae(be("dns4"),Mo()),su=Ae(be("dns6"),Mo()),au=Ae(be("dnsaddr"),Mo()),wd=Ae(be("dns"),Mo()),l6=Ue(iu,Ie(ke())),u6=Ue(su,Ie(ke())),f6=Ue(au,Ie(ke())),p6=Ue(Ct(wd,au,iu,su),Ie(ke())),hw=Ae(be("ip4"),ns(Jl)),dw=Ae(be("ip6"),ns(Ql)),xd=Ct(hw,dw),pn=Ct(xd,wd,iu,su,au),h6=Ue(Ct(xd,Ae(Ct(wd,au,iu,su),Ie(ke())))),d6=Ue(hw),m6=Ue(dw),y6=Ue(xd),bd=Ae(pn,be("tcp"),Oa()),La=Ae(pn,be("udp"),Oa()),g6=Ue(Ae(bd,Ie(ke()))),w6=Ue(La),vd=Ae(La,be("quic"),Ie(ke())),cu=Ae(La,be("quic-v1"),Ie(ke())),H2=Ct(vd,cu),x6=Ue(vd),b6=Ue(cu),gd=Ct(pn,bd,La,vd,cu),mw=Ct(Ae(gd,be("ws"),Ie(ke()))),v6=Ue(mw),yw=Ct(Ae(gd,be("wss"),Ie(ke())),Ae(gd,be("tls"),Ie(Ae(be("sni"),Mo())),be("ws"),Ie(ke()))),A6=Ue(yw),gw=Ae(La,be("webrtc-direct"),Ie(Ra()),Ie(Ra()),Ie(ke())),ww=Ue(gw),xw=Ae(cu,be("webtransport"),Ie(Ra()),Ie(Ra()),Ie(ke())),S6=Ue(xw),ou=Ct(mw,yw,Ae(bd,Ie(ke())),Ae(H2,Ie(ke())),Ae(pn,Ie(ke())),gw,xw,ke()),bw=Ue(ou),V2=Ae(ou,be("p2p-circuit"),ke()),E6=Ue(V2),$2=Ct(Ae(ou,be("p2p-circuit"),be("webrtc"),Ie(ke())),Ae(ou,be("webrtc"),Ie(ke())),Ae(be("webrtc"),Ie(ke()))),vw=Ue($2),F2=Ct(Ae(pn,be("tcp"),Oa(),be("http"),Ie(ke())),Ae(pn,be("http"),Ie(ke()))),_6=Ue(F2),W2=Ct(Ae(pn,be("tcp"),Ct(Ae(be("443"),be("http")),Ae(Oa(),be("https"))),Ie(ke())),Ae(pn,be("tls"),be("http"),Ie(ke())),Ae(pn,be("https"),Ie(ke()))),C6=Ue(W2),q2=Ct(Ae(be("memory"),Mo(),Ie(ke()))),I6=Ue(q2);var It;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>jo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>_r(o,r.codec()),r.decode=(o,i)=>Er(o,r.codec(),i)})(It||(It={}));var Aw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Ad=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Sw="libp2p+webrtc+v1/";var Ew=466,_w=2*1024*1024,Cw=30*1e3,os=16*1024;function G2(r=os){let e=Ce(r-Ce(r)),t=1+Ce(Object.keys(It.Flag).length-1),n=1,o=r-e-t-n,i=Ce(o);return e+t+n+i}var Iw=G2(),Tw=5e3,Bw=5e3,kw=3e4,Sd="/webrtc",Da="/webrtc-signaling/0.0.1",Nw="/libp2p/webrtc-direct/certificate",Pw="webrtc-direct-certificate-private-key";var Ow=12096e5,Ed=864e5;var Rw=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},z2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var X2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var Y2=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var Z2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var J2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var Q2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,e_=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Lw=3,t_=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Q2]],Dw=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function jw(r){return r?Uw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new J2:typeof navigator<"u"?Uw(navigator.userAgent):o_()}function r_(r){return r!==""&&t_.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function Uw(r){var e=r_(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Z2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Lw&&(o=Rw(Rw([],o,!0),i_(Lw-o.length),!0)):o=[];var i=o.join("."),s=n_(r),a=e_.exec(r);return a&&a[1]?new Y2(t,i,s,a[1]):new z2(t,i,s)}function n_(r){for(var e=0,t=Dw.length;e<t;e++){var n=Dw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function o_(){var r=typeof process<"u"&&process.version;return r?new X2(process.version.slice(1)):null}function i_(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Re(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var _d=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Cd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Mw=r=>globalThis.DOMException===void 0?new Cd(r):new DOMException(r),Kw=r=>{let e=r.reason===void 0?Mw("This operation was aborted."):r.reason;return e instanceof Error?e:Mw(e)};function Ua(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,u=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:w}=e;w.aborted&&p(Kw(w)),a=()=>{p(Kw(w))},w.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let m=new _d;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){p(w)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${t} milliseconds`,p(m))},t),(async()=>{try{h(await r)}catch(w){p(w)}})()}).finally(()=>{u.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}var Hw=jw(),ja=Hw!=null&&Hw.name==="firefox",lu=async function*(){},uu=async r=>{};function Vw(r,e,t=kw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Re(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Ua(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Id(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Aw.map(e=>({urls:[e]})),r}var $w=(r=32)=>Sw+[...Array(r)].map(()=>Ad.at(Math.floor(Math.random()*Ad.length))).join("");var Ko=class{log;peerConnection;remoteAddr;timeline;metrics;source=lu();sink=uu;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection,o=n.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",n.connectionState,"initial state",o),(n.connectionState==="disconnected"||n.connectionState==="failed"||n.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var fu=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},is=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new fu(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new fu(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Td=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ss(r={}){return s_(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function s_(r,e){e=e??{};let t=e.onEnd,n=new is,o,i,s,a=Re(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,S)=>{i=T=>{i=null,n.push(T);try{y(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Re()})}},u=y=>i!=null?i(y):(n.push(y),o),h=y=>(n=new is,i!=null?i({error:y}):(n.push({error:y}),o)),p=y=>{if(s)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},m=y=>s?o:(s=!0,y!=null?h(y):u({done:!0})),w=()=>(n=new is,m(),{done:!0}),b=y=>(m(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:w,throw:b,push:p,end:m,get readableLength(){return n.size},onEmpty:async y=>{let S=y?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,v;S!=null&&(T=new Promise((P,W)=>{v=()=>{W(new Td)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,T])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},t==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(y){return g.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return g.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(y){return g.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return g.readableLength},onEmpty:y=>g.onEmpty(y)},o}var pu=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function Dt(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new pu(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new pu(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}function Fw(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function Ww(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function qw(r,e){let t=Fw(r).return?.();Ww(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var a_=5e3;function Bd(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var hu=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Re(),this.closed=Re(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??a_,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=ss({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new _o(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Bd(o)&&await o}let n=()=>{qw(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new ue(o):o;let i=this.sendData(o,t);Bd(i)&&(this.sendingData=Re(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await Dt(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await Dt(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await Dt(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await Dt(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Bd(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new bl("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function kd(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var du=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},as=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mu=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ma=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yu(r){return r[Symbol.asyncIterator]!=null}function Gw(r,e){if(r.byteLength>e)throw new as("Message length too long")}var wu=r=>{let e=Ce(r),t=et(e);return Lt(r,t),wu.bytes=e,t};wu.bytes=0;function Ka(r,e){e=e??{};let t=e.lengthEncoder??wu,n=e?.maxDataLength??4194304;function*o(i){Gw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return yu(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ka.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??wu,n=e?.maxDataLength??4194304;return Gw(r,n),new ue(t(r.byteLength),r)};var Ho;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ho||(Ho={}));var Nd=r=>{let e=Nt(r);return Nd.bytes=Ce(e),e};Nd.bytes=0;function Ha(r,e){let t=new ue,n=Ho.LENGTH,o=-1,i=e?.lengthDecoder??Nd,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Ho.LENGTH)try{if(o=i(t),o<0)throw new du("Invalid message length");if(o>a)throw new as("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=Ho.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new mu("Message length length too long");break}throw u}if(n===Ho.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=Ho.LENGTH}}}return yu(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Ma("Unexpected end of input")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Ma("Unexpected end of input")}()}Ha.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return Ha(n,{...e??{},onLength:i=>{t=i}})};var Pd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Va(r,e,t,n){let o=new Pd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",h),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(m){a(),s(m);return}a(),i(p)},u=p=>{a(),s(p.detail)},h=()=>{a(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var Od=class extends hu{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await Ua(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=ss(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Cw,this.maxBufferedAmount=e.maxBufferedAmount??_w,this.maxMessageSize=(e.maxMessageSize??os)-Iw,this.receiveFinAck=Re(),this.finAckTimeout=e.closeTimeout??Tw,this.openTimeout=e.openTimeout??Bw,this.closeController=new AbortController,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new _o("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of Ha(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new ue(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new _o(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=kd([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Va(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=kd([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Va(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new El(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=It.encode({message:o}),s=Ka.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(It.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(It.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await Dt(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(It.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=It.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===It.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(It.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===It.Flag.RESET&&this.reset(),t.flag===It.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===It.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',this.channel.readyState,e.toString()),!1;this.log.trace("sending flag %s",e.toString());let t=It.encode({flag:e}),n=Ka.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function cs(r){let{channel:e,direction:t,handshake:n}=r;return new Od({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var Zn=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Sd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=cs({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Rd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Rd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Sd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=cs({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),Vw(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=lu();sink=uu;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=cs({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var xu=globalThis.RTCPeerConnection,bu=globalThis.RTCSessionDescription,zw=globalThis.RTCIceCandidate;var Ld=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Re(),this.haveNext=Re()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Re(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Re(),await Dt(this.readNext.promise,t?.signal,t)}};function vu(){return new Ld}var Au=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Xw(r,e){let t=vu();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ue;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:u}=await Dt(n.next(),s?.signal);return c===!0?null:u}for(;o.byteLength<s.bytes;){let{value:c,done:u}=await Dt(n.next(),s?.signal);if(u===!0)throw new Au("unexpected end of input");o.append(c)}let a=o.sublist(0,s.bytes);return o.consume(s.bytes),a},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Su=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Eu=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},_u=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Yw(r,e={}){let t=Xw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ce(e.maxDataLength));let n=e?.lengthDecoder??Nt,o=e?.lengthEncoder??Lt;return{read:async s=>{let a=-1,c=new ue;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Su("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new _u("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Eu("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new ue(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new ue(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Cu(r,e){let t=Yw(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Jt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Jn=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ir=class extends Jn{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Iu=class extends Jn{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Tu=class extends Jn{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Bu=class extends Jn{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Ut;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>jo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>_r(o,r.codec()),r.decode=(o,i)=>Er(o,r.codec(),i)})(Ut||(Ut={}));var ku=async(r,e,t)=>{try{let n=Re();for(u_(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Ut.Type.ICE_CANDIDATE)throw new Sl("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Jt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new zw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Jt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Nu(r)!=="connected")throw n}};function Nu(r){return ja?r.iceConnectionState:r.connectionState}function u_(r,e){r[ja?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Nu(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new xl("RTCPeerConnection was closed"));break;default:break}}}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:u}){let{baseAddr:h}=Jw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",h);let p=h.getPeerId();if(p==null)throw new ve("Relay peer was missing");let m=i.getConnections(es(p)),w,b=!1;m.length===0?(u?.(new Jt("webrtc:dial-relay")),w=await s.dial(h,{signal:t,onProgress:u}),b=!0):(u?.(new Jt("webrtc:reuse-relay-connection")),w=m[0]);try{u?.(new Jt("webrtc:open-signaling-stream"));let g=await w.newStream(Da,{signal:t,runOnLimitedConnection:!0}),y=Cu(g).pb(Ut),S=new xu(r),T=new Zn({logger:c},{peerConnection:S,dataChannelOptions:e});try{let v=S.createDataChannel("init");S.onicecandidate=({candidate:O})=>{let K=JSON.stringify(O?.toJSON()??null);a.trace("initiator sending ICE candidate %o",O),y.write({type:Ut.Type.ICE_CANDIDATE,data:K},{signal:t}).catch(L=>{a.error("error sending ICE candidate",L)})},S.onicecandidateerror=O=>{a.error("initiator ICE candidate error",O)};let P=await S.createOffer().catch(O=>{throw a.error("could not execute createOffer",O),new ir("Failed to set createOffer")});a.trace("initiator send SDP offer %s",P.sdp),u?.(new Jt("webrtc:send-sdp-offer")),await y.write({type:Ut.Type.SDP_OFFER,data:P.sdp},{signal:t}),await S.setLocalDescription(P).catch(O=>{throw a.error("could not execute setLocalDescription",O),new ir("Failed to set localDescription")}),u?.(new Jt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let W=await y.read({signal:t});if(W.type!==Ut.Type.SDP_ANSWER)throw new ir("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",W.data);let H=new bu({type:"answer",sdp:W.data});return await S.setRemoteDescription(H).catch(O=>{throw a.error("could not execute setRemoteDescription",O),new ir("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),u?.(new Jt("webrtc:read-ice-candidates")),await ku(S,y,{direction:"initiator",signal:t,log:a,onProgress:u}),a.trace("initiator connected, closing init channel"),v.close(),u?.(new Jt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await g.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:S,muxerFactory:T}}catch(v){throw a.error("outgoing signaling error",v),S.close(),g.abort(v),v}finally{S.onicecandidate=null,S.onicecandidateerror=null}}finally{if(b)try{await w.close({signal:t})}catch(g){w.abort(g)}}}var Qw=Ue(bw.matchers[0],be("p2p-circuit")),Pu=class r extends Ln{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Qw.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Qw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function ex({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Cu(e).pb(Ut);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Ut.Type.ICE_CANDIDATE,data:p},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Ut.Type.SDP_OFFER)throw new ir(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new bu({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new ir("Failed to set remoteDescription")});let u=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new ir("Failed to create answer")});o.trace("recipient send SDP answer %s",u.sdp),await i.write({type:Ut.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(h=>{throw o.error("could not execute setLocalDescription",h),new ir("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await ku(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Nu(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=Hr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Ou=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,this.shutdownController.signal,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[yl]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Hi]=["@libp2p/transport"];[lg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Da,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Da),this._started=!1}createListener(e){return new Pu(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(vw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await Id(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new Ko(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new xu(await Id(this.init.rtcConfiguration)),i=new Zn(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await ex({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Ko(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Jw(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new ve("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new ve("p2p-circuit protocol was not present in multiaddr");let t=Hr(e[0]),o=Hr("/"+e[1]).getPeerId();if(o==null)throw new ve("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new ve("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:es(o)}}var FG=Dr(rx());var Wr={};vt(Wr,{Any:()=>$r,BaseBlock:()=>rt,BaseStringBlock:()=>qa,BitString:()=>Br,BmpString:()=>qo,Boolean:()=>$o,CharacterString:()=>ti,Choice:()=>fs,Constructed:()=>ct,DATE:()=>Ja,DateTime:()=>ec,Duration:()=>tc,EndOfContent:()=>Ga,Enumerated:()=>Fo,GeneralString:()=>ei,GeneralizedTime:()=>ri,GraphicString:()=>Qo,HexBlock:()=>Fr,IA5String:()=>Jo,Integer:()=>gn,Null:()=>Ir,NumericString:()=>zo,ObjectIdentifier:()=>Wo,OctetString:()=>Tr,Primitive:()=>yn,PrintableString:()=>Xo,RawData:()=>Md,RelativeObjectIdentifier:()=>Za,Repeated:()=>ni,Sequence:()=>Kt,Set:()=>Ht,TIME:()=>rc,TeletexString:()=>Yo,TimeOfDay:()=>Qa,UTCTime:()=>ro,UniversalString:()=>Go,Utf8String:()=>ar,ValueBlock:()=>ft,VideotexString:()=>Zo,ViewWriter:()=>us,VisibleString:()=>to,compareSchema:()=>eo,fromBER:()=>xn,verifySchema:()=>N_});var me=Dr(dn());function Vo(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Qn(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let u=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);u[i-h-1]=Math.floor(o/p),o-=u[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Du(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Ud(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Vo(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Vo(i,8)-n}function nx(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=Qn(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Qn(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ox(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function jt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var r3=Math.log(2);function Uu(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Kd(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function wn(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var us=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Kd(this.items)}},$a=[new Uint8Array([1])],ix="0123456789",jd="name",sx="valueHexView",x_="isHexOnly",b_="idBlock",v_="tagClass",A_="tagNumber",S_="isConstructed",E_="fromBER",__="toBER",C_="local",Mt="",kr=new ArrayBuffer(0),Ju=new Uint8Array(0),Wa="EndOfContent",cx="OCTET STRING",lx="BIT STRING";function Fr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?me.BufferSourceConverter.toUint8Array(i.valueHex):Ju}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!wn(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",kr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:me.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var mn=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=Mt,warnings:n=[],valueBeforeDecode:o=Ju}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=me.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:me.Convert.ToHex(this.valueBeforeDecodeView)}}};mn.NAME="baseBlock";var ft=class extends mn{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ft.NAME="valueBlock";var ju=class extends Fr(mn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?me.BufferSourceConverter.toUint8Array(e.valueHex):Ju,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",kr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Qn(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let m=new Uint8Array(h);for(let w=0;w<u.length;w++)m[w]=u[w];u=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,u[c-1]=i[c]&127;let p=new Uint8Array(c);for(let m=0;m<c;m++)p[m]=u[m];u=this.valueHexView=new Uint8Array(c),u.set(p),this.blockLength<=9?this.tagNumber=Vo(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ju.NAME="identificationBlock";var Mu=class extends mn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Vo(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=Qn(this.length,8);if(o.byteLength>127)return this.error="Too big length",kr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Mu.NAME="lengthBlock";var X={},rt=class extends mn{constructor({name:e=Mt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new ju(o),this.lenBlock=new Mu(o),this.valueBlock=i?new i(o):new ft(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new us;t||ux(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?kr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():me.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return ox(t,n)}};rt.NAME="BaseBlock";function ux(r){var e;if(r instanceof X.Constructed)for(let t of r.valueBlock.value)ux(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var qa=class extends rt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Mt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};qa.NAME="BaseStringBlock";var Ku=class extends Fr(ft){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Ku.NAME="PrimitiveValueBlock";var fx,yn=class extends rt{constructor(e={}){super(e,Ku),this.idBlock.isConstructed=!1}};fx=yn;X.Primitive=fx;yn.NAME="PRIMITIVE";function I_(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ps(r,e=0,t=r.length){let n=e,o=new rt({},ft),i=new mn;if(!wn(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=rt;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=X.EndOfContent;break;case 1:c=X.Boolean;break;case 2:c=X.Integer;break;case 3:c=X.BitString;break;case 4:c=X.OctetString;break;case 5:c=X.Null;break;case 6:c=X.ObjectIdentifier;break;case 10:c=X.Enumerated;break;case 12:c=X.Utf8String;break;case 13:c=X.RelativeObjectIdentifier;break;case 14:c=X.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=X.Sequence;break;case 17:c=X.Set;break;case 18:c=X.NumericString;break;case 19:c=X.PrintableString;break;case 20:c=X.TeletexString;break;case 21:c=X.VideotexString;break;case 22:c=X.IA5String;break;case 23:c=X.UTCTime;break;case 24:c=X.GeneralizedTime;break;case 25:c=X.GraphicString;break;case 26:c=X.VisibleString;break;case 27:c=X.GeneralString;break;case 28:c=X.UniversalString;break;case 29:c=X.CharacterString;break;case 30:c=X.BmpString;break;case 31:c=X.DATE;break;case 32:c=X.TimeOfDay;break;case 33:c=X.DateTime;break;case 34:c=X.Duration;break;default:{let u=o.idBlock.isConstructed?new X.Constructed:new X.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?X.Constructed:X.Primitive}return o=I_(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function xn(r){if(!r.byteLength){let e=new rt({},ft);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ps(me.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function T_(r,e){return r?1:e}var Vr=class extends ft{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;T_(this.isIndefiniteForm,n)>0;){let s=ps(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===Wa)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Wa?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new us;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?kr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Vr.NAME="ConstructedValueBlock";var px,ct=class extends rt{constructor(e={}){super(e,Vr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PWebrtc=(()=>{var aA=Object.create;var yl=Object.defineProperty;var cA=Object.getOwnPropertyDescriptor;var lA=Object.getOwnPropertyNames;var uA=Object.getPrototypeOf,fA=Object.prototype.hasOwnProperty;var vp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),vt=(r,e)=>{for(var t in e)yl(r,t,{get:e[t],enumerable:!0})},eg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of lA(e))!fA.call(r,o)&&o!==t&&yl(r,o,{get:()=>e[o],enumerable:!(n=cA(e,o))||n.enumerable});return r};var Dr=(r,e,t)=>(t=r!=null?aA(uA(r)):{},eg(e||!r||!r.__esModule?yl(t,"default",{value:r,enumerable:!0}):t,r)),pA=r=>eg(yl({},"__esModule",{value:!0}),r);var zw=vp(()=>{var Gw;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,u){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),u&&u(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,u=!a&&!c,h={create:a?function(){return bp(Object.create(null))}:c?function(){return bp({__proto__:null})}:function(){return bp({})},has:u?function(x,E){return n.call(x,E)}:function(x,E){return E in x},get:u?function(x,E){return n.call(x,E)?x[E]:void 0}:function(x,E){return x[E]}},p=Object.getPrototypeOf(Function),y=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:rA(),w=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:nA(),b=typeof WeakMap=="function"?WeakMap:oA(),g=o?Symbol.for("@reflect-metadata:registry"):void 0,m=Q1(),S=eA(m);function T(x,E,B,$){if(P(B)){if(!Ye(x))throw new TypeError;if(!bt(E))throw new TypeError;return Y(x,E)}else{if(!Ye(x))throw new TypeError;if(!Q(E))throw new TypeError;if(!Q($)&&!P($)&&!ie($))throw new TypeError;return ie($)&&($=void 0),B=je(B),le(x,E,B,$)}}e("decorate",T);function v(x,E){function B($,se){if(!Q($))throw new TypeError;if(!P(se)&&!Gt(se))throw new TypeError;C(x,E,$,se)}return B}e("metadata",v);function N(x,E,B,$){if(!Q(B))throw new TypeError;return P($)||($=je($)),C(x,E,B,$)}e("defineMetadata",N);function W(x,E,B){if(!Q(E))throw new TypeError;return P(B)||(B=je(B)),R(x,E,B)}e("hasMetadata",W);function H(x,E,B){if(!Q(E))throw new TypeError;return P(B)||(B=je(B)),D(x,E,B)}e("hasOwnMetadata",H);function O(x,E,B){if(!Q(E))throw new TypeError;return P(B)||(B=je(B)),j(x,E,B)}e("getMetadata",O);function K(x,E,B){if(!Q(E))throw new TypeError;return P(B)||(B=je(B)),k(x,E,B)}e("getOwnMetadata",K);function L(x,E){if(!Q(x))throw new TypeError;return P(E)||(E=je(E)),I(x,E)}e("getMetadataKeys",L);function te(x,E){if(!Q(x))throw new TypeError;return P(E)||(E=je(E)),U(x,E)}e("getOwnMetadataKeys",te);function z(x,E,B){if(!Q(E))throw new TypeError;if(P(B)||(B=je(B)),!Q(E))throw new TypeError;P(B)||(B=je(B));var $=ta(E,B,!1);return P($)?!1:$.OrdinaryDeleteMetadata(x,E,B)}e("deleteMetadata",z);function Y(x,E){for(var B=x.length-1;B>=0;--B){var $=x[B],se=$(E);if(!P(se)&&!ie(se)){if(!bt(se))throw new TypeError;E=se}}return E}function le(x,E,B,$){for(var se=x.length-1;se>=0;--se){var Ze=x[se],ot=Ze(E,B,$);if(!P(ot)&&!ie(ot)){if(!Q(ot))throw new TypeError;$=ot}}return $}function R(x,E,B){var $=D(x,E,B);if($)return!0;var se=xp(E);return ie(se)?!1:R(x,se,B)}function D(x,E,B){var $=ta(E,B,!1);return P($)?!1:Ee($.OrdinaryHasOwnMetadata(x,E,B))}function j(x,E,B){var $=D(x,E,B);if($)return k(x,E,B);var se=xp(E);if(!ie(se))return j(x,se,B)}function k(x,E,B){var $=ta(E,B,!1);if(!P($))return $.OrdinaryGetOwnMetadata(x,E,B)}function C(x,E,B,$){var se=ta(B,$,!0);se.OrdinaryDefineOwnMetadata(x,E,B,$)}function I(x,E){var B=U(x,E),$=xp(x);if($===null)return B;var se=I($,E);if(se.length<=0)return B;if(B.length<=0)return se;for(var Ze=new w,ot=[],we=0,G=B;we<G.length;we++){var Z=G[we],ee=Ze.has(Z);ee||(Ze.add(Z),ot.push(Z))}for(var re=0,xe=se;re<xe.length;re++){var Z=xe[re],ee=Ze.has(Z);ee||(Ze.add(Z),ot.push(Z))}return ot}function U(x,E){var B=ta(x,E,!1);return B?B.OrdinaryOwnMetadataKeys(x,E):[]}function q(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function P(x){return x===void 0}function ie(x){return x===null}function ue(x){return typeof x=="symbol"}function Q(x){return typeof x=="object"?x!==null:typeof x=="function"}function ye(x,E){switch(q(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var B=E===3?"string":E===5?"number":"default",$=ea(x,i);if($!==void 0){var se=$.call(x,B);if(Q(se))throw new TypeError;return se}return Te(x,B==="default"?"number":B)}function Te(x,E){if(E==="string"){var B=x.toString;if($e(B)){var $=B.call(x);if(!Q($))return $}var se=x.valueOf;if($e(se)){var $=se.call(x);if(!Q($))return $}}else{var se=x.valueOf;if($e(se)){var $=se.call(x);if(!Q($))return $}var Ze=x.toString;if($e(Ze)){var $=Ze.call(x);if(!Q($))return $}}throw new TypeError}function Ee(x){return!!x}function Re(x){return""+x}function je(x){var E=ye(x,3);return ue(E)?E:Re(E)}function Ye(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function $e(x){return typeof x=="function"}function bt(x){return typeof x=="function"}function Gt(x){switch(q(x)){case 3:return!0;case 4:return!0;default:return!1}}function nn(x,E){return x===E||x!==x&&E!==E}function ea(x,E){var B=x[E];if(B!=null){if(!$e(B))throw new TypeError;return B}}function pl(x){var E=ea(x,s);if(!$e(E))throw new TypeError;var B=E.call(x);if(!Q(B))throw new TypeError;return B}function hl(x){return x.value}function dl(x){var E=x.next();return E.done?!1:E}function ml(x){var E=x.return;E&&E.call(x)}function xp(x){var E=Object.getPrototypeOf(x);if(typeof x!="function"||x===p||E!==p)return E;var B=x.prototype,$=B&&Object.getPrototypeOf(B);if($==null||$===Object.prototype)return E;var se=$.constructor;return typeof se!="function"||se===x?E:se}function J1(){var x;!P(g)&&typeof t.Reflect<"u"&&!(g in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=tA(t.Reflect));var E,B,$,se=new b,Ze={registerProvider:ot,getProvider:G,setProvider:ee};return Ze;function ot(re){if(!Object.isExtensible(Ze))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===re:break;case P(E):E=re;break;case E===re:break;case P(B):B=re;break;case B===re:break;default:$===void 0&&($=new w),$.add(re);break}}function we(re,xe){if(!P(E)){if(E.isProviderFor(re,xe))return E;if(!P(B)){if(B.isProviderFor(re,xe))return E;if(!P($))for(var Me=pl($);;){var Je=dl(Me);if(!Je)return;var gr=hl(Je);if(gr.isProviderFor(re,xe))return ml(Me),gr}}}if(!P(x)&&x.isProviderFor(re,xe))return x}function G(re,xe){var Me=se.get(re),Je;return P(Me)||(Je=Me.get(xe)),P(Je)&&(Je=we(re,xe),P(Je)||(P(Me)&&(Me=new y,se.set(re,Me)),Me.set(xe,Je))),Je}function Z(re){if(P(re))throw new TypeError;return E===re||B===re||!P($)&&$.has(re)}function ee(re,xe,Me){if(!Z(Me))throw new Error("Metadata provider not registered.");var Je=G(re,xe);if(Je!==Me){if(!P(Je))return!1;var gr=se.get(re);P(gr)&&(gr=new y,se.set(re,gr)),gr.set(xe,Me)}return!0}}function Q1(){var x;return!P(g)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[g]),P(x)&&(x=J1()),!P(g)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,g,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function eA(x){var E=new b,B={isProviderFor:function(Z,ee){var re=E.get(Z);return P(re)?!1:re.has(ee)},OrdinaryDefineOwnMetadata:ot,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Ze,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:G};return m.registerProvider(B),B;function $(Z,ee,re){var xe=E.get(Z),Me=!1;if(P(xe)){if(!re)return;xe=new y,E.set(Z,xe),Me=!0}var Je=xe.get(ee);if(P(Je)){if(!re)return;if(Je=new y,xe.set(ee,Je),!x.setProvider(Z,ee,B))throw xe.delete(ee),Me&&E.delete(Z),new Error("Wrong provider for target.")}return Je}function se(Z,ee,re){var xe=$(ee,re,!1);return P(xe)?!1:Ee(xe.has(Z))}function Ze(Z,ee,re){var xe=$(ee,re,!1);if(!P(xe))return xe.get(Z)}function ot(Z,ee,re,xe){var Me=$(re,xe,!0);Me.set(Z,ee)}function we(Z,ee){var re=[],xe=$(Z,ee,!1);if(P(xe))return re;for(var Me=xe.keys(),Je=pl(Me),gr=0;;){var Qy=dl(Je);if(!Qy)return re.length=gr,re;var iA=hl(Qy);try{re[gr]=iA}catch(sA){try{ml(Je)}finally{throw sA}}gr++}}function G(Z,ee,re){var xe=$(ee,re,!1);if(P(xe)||!xe.delete(Z))return!1;if(xe.size===0){var Me=E.get(ee);P(Me)||(Me.delete(re),Me.size===0&&E.delete(Me))}return!0}}function tA(x){var E=x.defineMetadata,B=x.hasOwnMetadata,$=x.getOwnMetadata,se=x.getOwnMetadataKeys,Ze=x.deleteMetadata,ot=new b,we={isProviderFor:function(G,Z){var ee=ot.get(G);return!P(ee)&&ee.has(Z)?!0:se(G,Z).length?(P(ee)&&(ee=new w,ot.set(G,ee)),ee.add(Z),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:B,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Ze};return we}function ta(x,E,B){var $=m.getProvider(x,E);if(!P($))return $;if(B){if(m.setProvider(x,E,S))return S;throw new Error("Illegal state.")}}function rA(){var x={},E=[],B=function(){function we(G,Z,ee){this._index=0,this._keys=G,this._values=Z,this._selector=ee}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var G=this._index;if(G>=0&&G<this._keys.length){var Z=this._selector(this._keys[G],this._values[G]);return G+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:Z,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(G){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),G},we.prototype.return=function(G){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:G,done:!0}},we}(),$=function(){function we(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(G){return this._find(G,!1)>=0},we.prototype.get=function(G){var Z=this._find(G,!1);return Z>=0?this._values[Z]:void 0},we.prototype.set=function(G,Z){var ee=this._find(G,!0);return this._values[ee]=Z,this},we.prototype.delete=function(G){var Z=this._find(G,!1);if(Z>=0){for(var ee=this._keys.length,re=Z+1;re<ee;re++)this._keys[re-1]=this._keys[re],this._values[re-1]=this._values[re];return this._keys.length--,this._values.length--,nn(G,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},we.prototype.keys=function(){return new B(this._keys,this._values,se)},we.prototype.values=function(){return new B(this._keys,this._values,Ze)},we.prototype.entries=function(){return new B(this._keys,this._values,ot)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(G,Z){if(!nn(this._cacheKey,G)){this._cacheIndex=-1;for(var ee=0;ee<this._keys.length;ee++)if(nn(this._keys[ee],G)){this._cacheIndex=ee;break}}return this._cacheIndex<0&&Z&&(this._cacheIndex=this._keys.length,this._keys.push(G),this._values.push(void 0)),this._cacheIndex},we}();return $;function se(we,G){return we}function Ze(we,G){return G}function ot(we,G){return[we,G]}}function nA(){var x=function(){function E(){this._map=new y}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(B){return this._map.has(B)},E.prototype.add=function(B){return this._map.set(B,B),this},E.prototype.delete=function(B){return this._map.delete(B)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E}();return x}function oA(){var x=16,E=h.create(),B=$();return function(){function G(){this._key=$()}return G.prototype.has=function(Z){var ee=se(Z,!1);return ee!==void 0?h.has(ee,this._key):!1},G.prototype.get=function(Z){var ee=se(Z,!1);return ee!==void 0?h.get(ee,this._key):void 0},G.prototype.set=function(Z,ee){var re=se(Z,!0);return re[this._key]=ee,this},G.prototype.delete=function(Z){var ee=se(Z,!1);return ee!==void 0?delete ee[this._key]:!1},G.prototype.clear=function(){this._key=$()},G}();function $(){var G;do G="@@WeakMap@@"+we();while(h.has(E,G));return E[G]=!0,G}function se(G,Z){if(!n.call(G,B)){if(!Z)return;Object.defineProperty(G,B,{value:h.create()})}return G[B]}function Ze(G,Z){for(var ee=0;ee<Z;++ee)G[ee]=Math.random()*255|0;return G}function ot(G){if(typeof Uint8Array=="function"){var Z=new Uint8Array(G);return typeof crypto<"u"?crypto.getRandomValues(Z):typeof msCrypto<"u"?msCrypto.getRandomValues(Z):Ze(Z,G),Z}return Ze(new Array(G),G)}function we(){var G=ot(x);G[6]=G[6]&79|64,G[8]=G[8]&191|128;for(var Z="",ee=0;ee<x;++ee){var re=G[ee];(ee===4||ee===6||ee===8)&&(Z+="-"),re<16&&(Z+="0"),Z+=re.toString(16).toLowerCase()}return Z}}function bp(x){return x.__=void 0,delete x.__,x}})})(Gw||(Gw={}))});var dn=vp(ls=>{"use strict";var t_="[object ArrayBuffer]",hn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===t_}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Od="string",r_=/^[0-9a-f\s]+$/i,n_=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,o_=/^[a-zA-Z0-9-_]+$/,Lu=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=hn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},sr=class{static toString(e,t=!1){let n=hn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},Du=class r{static isHex(e){return typeof e===Od&&r_.test(e)}static isBase64(e){return typeof e===Od&&n_.test(e)}static isBase64Url(e){return typeof e===Od&&o_.test(e)}static ToString(e,t="utf8"){let n=hn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return sr.toString(n,!0);case"utf16":case"utf16be":return sr.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return sr.fromString(e,!0);case"utf16":case"utf16be":return sr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=hn.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Lu.fromString(e);case"utf16":case"utf16be":return sr.fromString(e);case"utf16le":case"usc2":return sr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Lu.toString(e);case"utf16":case"utf16be":return sr.toString(e);case"utf16le":case"usc2":return sr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=hn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=hn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return sr.toString(e,t)}static FromUtf16String(e,t=!1){return sr.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Du.DEFAULT_UTF8_ENCODING="utf8";function i_(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let o=arguments[n];for(let i in o)t[i]=o[i]}return t}function s_(...r){let e=r.map(o=>o.byteLength).reduce((o,i)=>o+i),t=new Uint8Array(e),n=0;return r.map(o=>new Uint8Array(o)).forEach(o=>{for(let i of o)t[n++]=i}),t.buffer}function a_(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}ls.BufferSourceConverter=hn;ls.Convert=Du;ls.assign=i_;ls.combine=s_;ls.isEqual=a_});var Vb=vp((dV,Pf)=>{var Ab,Sb,Eb,_b,Cb,Ib,Tb,Bb,kb,kf,Km,Pb,Nb,Ms,Ob,Rb,Lb,Db,Ub,jb,Mb,Kb,Hb;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof Pf=="object"&&typeof Pf.exports=="object"?r(t(e,t(Pf.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};Ab=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Sb=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++){n=arguments[o];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Eb=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},_b=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Cb=function(t,n){return function(o,i){n(o,i,t)}},Ib=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Tb=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function u(y){try{p(i.next(y))}catch(w){c(w)}}function h(y){try{p(i.throw(y))}catch(w){c(w)}}function p(y){y.done?a(y.value):s(y.value).then(u,h)}p((i=i.apply(t,n||[])).next())})},Bb=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function u(p){return function(y){return h([p,y])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(y){p=[6,y],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Hb=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},kb=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},kf=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Km=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(u){c={error:u}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Pb=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Km(arguments[n]));return t},Nb=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,u=a.length;c<u;c++,s++)i[s]=a[c];return i},Ms=function(t){return this instanceof Ms?(this.v=t,this):new Ms(t)},Ob=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(b){i[b]&&(s[b]=function(g){return new Promise(function(m,S){a.push([b,g,m,S])>1||u(b,g)})})}function u(b,g){try{h(i[b](g))}catch(m){w(a[0][3],m)}}function h(b){b.value instanceof Ms?Promise.resolve(b.value.v).then(p,y):w(a[0][2],b)}function p(b){u("next",b)}function y(b){u("throw",b)}function w(b,g){b(g),a.shift(),a.length&&u(a[0][0],a[0][1])}},Rb=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Ms(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Lb=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof kf=="function"?kf(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(u,h){c=t[a](c),s(u,h,c.done,c.value)})}}function s(a,c,u,h){Promise.resolve(h).then(function(p){a({value:p,done:u})},c)}},Db=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Ub=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},jb=function(t){return t&&t.__esModule?t:{default:t}},Mb=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Kb=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",Ab),r("__assign",Sb),r("__rest",Eb),r("__decorate",_b),r("__param",Cb),r("__metadata",Ib),r("__awaiter",Tb),r("__generator",Bb),r("__exportStar",kb),r("__createBinding",Hb),r("__values",kf),r("__read",Km),r("__spread",Pb),r("__spreadArrays",Nb),r("__await",Ms),r("__asyncGenerator",Ob),r("__asyncDelegator",Rb),r("__asyncValues",Lb),r("__makeTemplateObject",Db),r("__importStar",Ub),r("__importDefault",jb),r("__classPrivateFieldGet",Mb),r("__classPrivateFieldSet",Kb)})});var uI={};vt(uI,{webRTC:()=>lI,webRTCDirect:()=>cI});var Ap=Symbol.for("@libp2p/peer-id");var gl=Symbol.for("@libp2p/transport");var tg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(tg||(tg={}));var wl=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},xl=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ki=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ra=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var bl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var vl=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Eo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},_o=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Al=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Sl=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var El=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var _l=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Cl=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Rn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ln=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Hi=Symbol.for("@libp2p/service-capabilities"),rg=Symbol.for("@libp2p/service-dependencies");var Ip={};vt(Ip,{base58btc:()=>Pe,base58flickr:()=>wA});var jI=new Uint8Array(0);function ng(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function on(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function og(r){return new TextEncoder().encode(r)}function ig(r){return new TextDecoder().decode(r)}function hA(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var g=0,m=0,S=0,T=b.length;S!==T&&b[S]===0;)S++,g++;for(var v=(T-S)*h+1>>>0,N=new Uint8Array(v);S!==T;){for(var W=b[S],H=0,O=v-1;(W!==0||H<m)&&O!==-1;O--,H++)W+=256*N[O]>>>0,N[O]=W%a>>>0,W=W/a>>>0;if(W!==0)throw new Error("Non-zero carry");m=H,S++}for(var K=v-m;K!==v&&N[K]===0;)K++;for(var L=c.repeat(g);K<v;++K)L+=r.charAt(N[K]);return L}function y(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var g=0;if(b[g]!==" "){for(var m=0,S=0;b[g]===c;)m++,g++;for(var T=(b.length-g)*u+1>>>0,v=new Uint8Array(T);b[g];){var N=t[b.charCodeAt(g)];if(N===255)return;for(var W=0,H=T-1;(N!==0||W<S)&&H!==-1;H--,W++)N+=a*v[H]>>>0,v[H]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");S=W,g++}if(b[g]!==" "){for(var O=T-S;O!==T&&v[O]===0;)O++;for(var K=new Uint8Array(m+(T-O)),L=m;O!==T;)K[L++]=v[O++];return K}}}function w(b){var g=y(b);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:y,decode:w}}var dA=hA,mA=dA,ag=mA;var Sp=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ep=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return cg(this,e)}},_p=class{decoders;constructor(e){this.decoders=e}or(e){return cg(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cg(r,e){return new _p({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Cp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sp(e,t,n),this.decoder=new Ep(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Vi({name:r,prefix:e,encode:t,decode:n}){return new Cp(r,e,t,n)}function Dn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ag(t,r);return Vi({prefix:e,name:r,encode:n,decode:i=>on(o(i))})}function yA(r,e,t,n){let o={};for(let h=0;h<e.length;++h)o[e[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,c=0,u=0;for(let h=0;h<i;++h){let p=o[r[h]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|p,a+=t,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=t||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function gA(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function We({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Vi({prefix:e,name:r,encode(o){return gA(o,n,t)},decode(o){return yA(o,n,t,r)}})}var Pe=Dn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),wA=Dn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Tp={};vt(Tp,{base32:()=>sn,base32hex:()=>AA,base32hexpad:()=>EA,base32hexpadupper:()=>_A,base32hexupper:()=>SA,base32pad:()=>bA,base32padupper:()=>vA,base32upper:()=>xA,base32z:()=>CA});var sn=We({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xA=We({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),bA=We({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),vA=We({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),AA=We({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),SA=We({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),EA=We({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_A=We({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),CA=We({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bp={};vt(Bp,{base36:()=>na,base36upper:()=>IA});var na=Dn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),IA=Dn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var er={};vt(er,{Digest:()=>Co,create:()=>At,decode:()=>Un,equals:()=>Pp,hasCode:()=>qA});var TA=fg,lg=128,BA=127,kA=~BA,PA=Math.pow(2,31);function fg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=PA;)e[t++]=r&255|lg,r/=128;for(;r&kA;)e[t++]=r&255|lg,r>>>=7;return e[t]=r|0,fg.bytes=t-n+1,e}var NA=kp,OA=128,ug=127;function kp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw kp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&ug)<<o:(s&ug)*Math.pow(2,o),o+=7}while(s>=OA);return kp.bytes=i-n,t}var RA=Math.pow(2,7),LA=Math.pow(2,14),DA=Math.pow(2,21),UA=Math.pow(2,28),jA=Math.pow(2,35),MA=Math.pow(2,42),KA=Math.pow(2,49),HA=Math.pow(2,56),VA=Math.pow(2,63),$A=function(r){return r<RA?1:r<LA?2:r<DA?3:r<UA?4:r<jA?5:r<MA?6:r<KA?7:r<HA?8:r<VA?9:10},FA={encode:TA,decode:NA,encodingLength:$A},WA=FA,oa=WA;function ia(r,e=0){return[oa.decode(r,e),oa.decode.bytes]}function $i(r,e,t=0){return oa.encode(r,e,t),e}function Fi(r){return oa.encodingLength(r)}function At(r,e){let t=e.byteLength,n=Fi(r),o=n+Fi(t),i=new Uint8Array(o+t);return $i(r,i,0),$i(t,i,n),i.set(e,o),new Co(r,t,e,i)}function Un(r){let e=on(r),[t,n]=ia(e),[o,i]=ia(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Co(t,o,s,e)}function Pp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ng(r.bytes,t.bytes)}}var Co=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function qA(r,e){return r.code===e}function pg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return zA(t,Np(r),e??Pe.encoder);default:return XA(t,Np(r),e??sn.encoder)}}var hg=new WeakMap;function Np(r){let e=hg.get(r);if(e==null){let t=new Map;return hg.set(r,t),t}return e}var Qe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==sa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==YA)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=At(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Pp(e.multihash,n.multihash)}toString(e){return pg(this,e)}toJSON(){return{"/":pg(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??dg(n,o,i.bytes))}else if(t[ZA]===!0){let{version:n,multihash:o,code:i}=t,s=Un(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==sa)throw new Error(`Version 0 CID must use dag-pb (code: ${sa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=dg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,sa,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=on(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Co(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,y]=ia(e.subarray(t));return t+=y,p},o=n(),i=sa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,h=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:u}}static parse(e,t){let[n,o]=GA(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Np(i).set(n,e),i}};function GA(r,e){switch(r[0]){case"Q":{let t=e??Pe;return[Pe.prefix,t.decode(`${Pe.prefix}${r}`)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}case sn.prefix:{let t=e??sn;return[sn.prefix,t.decode(r)]}case na.prefix:{let t=e??na;return[na.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function zA(r,e,t){let{prefix:n}=t;if(n!==Pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function XA(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var sa=112,YA=18;function dg(r,e,t){let n=Fi(r),o=n+Fi(e),i=new Uint8Array(o+t.byteLength);return $i(r,i,0),$i(e,i,n),i.set(t,o),i}var ZA=Symbol.for("@ipld/js-cid/CID");var Op={};vt(Op,{identity:()=>wr});var mg=0,JA="identity",yg=on;function QA(r){return At(mg,yg(r))}var wr={code:mg,name:JA,encode:yg,digest:QA};function qe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function it(r=0){return new Uint8Array(r)}function et(r=0){return new Uint8Array(r)}function st(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=et(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var wg=Symbol.for("@achingbrain/uint8arraylist");function gg(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Tl(r){return!!r?.[wg]}var he=class r{bufs;length;[wg]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Tl(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Tl(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=gg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=gg(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Tl(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return st(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:st(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,h=t>a&&t<=c;if(u&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Tl(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let y=u;y>=0;y--){let w=this.get(p+y);if(n[y]!==w){h=Math.max(1,y-a[w]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=it(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=it(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=it(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!qe(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Rp={};vt(Rp,{base10:()=>tS});var tS=Dn({prefix:"9",name:"base10",alphabet:"0123456789"});var Lp={};vt(Lp,{base16:()=>rS,base16upper:()=>nS});var rS=We({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),nS=We({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dp={};vt(Dp,{base2:()=>oS});var oS=We({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Up={};vt(Up,{base256emoji:()=>lS});var xg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),iS=xg.reduce((r,e,t)=>(r[t]=e,r),[]),sS=xg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function aS(r){return r.reduce((e,t)=>(e+=iS[t],e),"")}function cS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=sS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var lS=Vi({prefix:"\u{1F680}",name:"base256emoji",encode:aS,decode:cS});var jp={};vt(jp,{base64:()=>uS,base64pad:()=>fS,base64url:()=>Io,base64urlpad:()=>pS});var uS=We({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),fS=We({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Io=We({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pS=We({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mp={};vt(Mp,{base8:()=>hS});var hS=We({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kp={};vt(Kp,{identity:()=>dS});var dS=Vi({prefix:"\0",name:"identity",encode:r=>ig(r),decode:r=>og(r)});var bT=new TextEncoder,vT=new TextDecoder;var $p={};vt($p,{sha256:()=>tr,sha512:()=>gS});function Vp({name:r,code:e,encode:t}){return new Hp(r,e,t)}var Hp=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?At(this.code,t):t.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function vg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Vp({name:"sha2-256",code:18,encode:vg("SHA-256")}),gS=Vp({name:"sha2-512",code:19,encode:vg("SHA-512")});var To={...Kp,...Dp,...Mp,...Rp,...Lp,...Tp,...Bp,...Ip,...jp,...Up},OT={...$p,...Op};function Sg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ag=Sg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fp=Sg("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=et(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),wS={utf8:Ag,"utf-8":Ag,hex:To.base16,latin1:Fp,ascii:Fp,binary:Fp,...To},Bl=wS;function de(r,e="utf8"){let t=Bl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ce(r,e="utf8"){let t=Bl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var xS=parseInt("11111",2),Wp=parseInt("10000000",2),bS=parseInt("01111111",2),Eg={0:aa,1:aa,2:vS,3:ES,4:_S,5:SS,6:AS,16:aa,22:aa,48:aa};function an(r,e={offset:0}){let t=r[e.offset]&xS;if(e.offset++,Eg[t]!=null)return Eg[t](r,e);throw new Error("No decoder for tag "+t)}function ca(r,e){let t=0;if((r[e.offset]&Wp)===Wp){let n=r[e.offset]&bS,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function aa(r,e){ca(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=an(r,e);if(n===null)break;t.push(n)}return t}function vS(r,e){let t=ca(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function AS(r,e){let t=ca(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function SS(r,e){return e.offset++,null}function ES(r,e){let t=ca(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function _S(r,e){let t=ca(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function CS(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new he;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function kl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=CS(r.byteLength);return new he(Uint8Array.from([e.byteLength|Wp]),e)}function Bt(r){let e=new he,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new he(Uint8Array.from([2]),kl(e),e)}function la(r){let e=Uint8Array.from([0]),t=new he(e,r);return new he(Uint8Array.from([3]),kl(t),t)}function _g(r){return new he(Uint8Array.from([4]),kl(r),r)}function xr(r,e=48){let t=new he;for(let n of r)t.append(n);return new he(Uint8Array.from([e]),kl(t),t)}async function Cg(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Ig(r,e){let t=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Tg(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,e,t.subarray())}var IS=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),TS=Uint8Array.from([6,5,43,129,4,0,34]),BS=Uint8Array.from([6,5,43,129,4,0,35]),kS={ext:!0,kty:"EC",crv:"P-256"},PS={ext:!0,kty:"EC",crv:"P-384"},NS={ext:!0,kty:"EC",crv:"P-521"},qp=32,Gp=48,zp=66;function Xp(r){let e=an(r);return Bg(e)}function Bg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===qp*2+1)return n=ce(e.subarray(t,t+qp),"base64url"),o=ce(e.subarray(t+qp),"base64url"),new Bo({...kS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Gp*2+1)return n=ce(e.subarray(t,t+Gp),"base64url"),o=ce(e.subarray(t+Gp),"base64url"),new Bo({...PS,key_ops:["verify"],x:n,y:o});if(e.byteLength===zp*2+1)return n=ce(e.subarray(t,t+zp),"base64url"),o=ce(e.subarray(t+zp),"base64url"),new Bo({...NS,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function kg(r){return xr([Bt(Uint8Array.from([1])),_g(de(r.d??"","base64url")),xr([Ng(r.crv)],160),xr([la(new he(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Pg(r){return xr([Bt(Uint8Array.from([1])),xr([Ng(r.crv)],160),xr([la(new he(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Ng(r){if(r==="P-256")return IS;if(r==="P-384")return TS;if(r==="P-521")return BS;throw new ve(`Invalid curve ${r}`)}async function Og(r="P-256"){let e=await Cg(r);return new Pl(e.privateKey)}var Bo=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Pg(this.jwk)),this._raw}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}async verify(e,t){return Tg(this.jwk,t,e)}},Pl=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Bo({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=kg(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}async sign(e){return Ig(this.jwk,e)}};function Nl(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function OS(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Wi(r,...e){if(!OS(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function ua(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Nl(r.outputLen),Nl(r.blockLen)}function qi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Rg(r,e){Wi(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var ko=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ol(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function br(r,e){return r<<32-e|r>>>e}var fB=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Lg(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Mn(r){return typeof r=="string"&&(r=Lg(r)),Wi(r),r}function Yp(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Wi(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var Gi=class{clone(){return this._cloneInto()}};function Rl(r){let e=n=>r().update(Mn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function fa(r=32){if(ko&&typeof ko.getRandomValues=="function")return ko.getRandomValues(new Uint8Array(r));if(ko&&typeof ko.randomBytes=="function")return Uint8Array.from(ko.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function RS(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function Dg(r,e,t){return r&e^~r&t}function Ug(r,e,t){return r&e^r&t^e&t}var zi=class extends Gi{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Ol(this.buffer)}update(e){qi(this);let{view:t,buffer:n,blockLen:o}=this;e=Mn(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Ol(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){qi(this),Rg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;RS(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Ol(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<u;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%t&&e.buffer.set(n),e}};var LS=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]),Kn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=new Uint32Array(64),Zp=class extends zi{constructor(e=32){super(64,e,8,!1),this.A=Kn[0]|0,this.B=Kn[1]|0,this.C=Kn[2]|0,this.D=Kn[3]|0,this.E=Kn[4]|0,this.F=Kn[5]|0,this.G=Kn[6]|0,this.H=Kn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)Hn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let y=Hn[p-15],w=Hn[p-2],b=br(y,7)^br(y,18)^y>>>3,g=br(w,17)^br(w,19)^w>>>10;Hn[p]=g+Hn[p-7]+b+Hn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:h}=this;for(let p=0;p<64;p++){let y=br(a,6)^br(a,11)^br(a,25),w=h+y+Dg(a,c,u)+LS[p]+Hn[p]|0,g=(br(n,2)^br(n,13)^br(n,22))+Ug(n,o,i)|0;h=u,u=c,c=a,a=s+w|0,s=i,i=o,o=n,n=w+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,u,h)}roundClean(){Hn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var vr=Rl(()=>new Zp);var Ll=BigInt(4294967295),Jp=BigInt(32);function jg(r,e=!1){return e?{h:Number(r&Ll),l:Number(r>>Jp&Ll)}:{h:Number(r>>Jp&Ll)|0,l:Number(r&Ll)|0}}function DS(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=jg(r[o],e);[t[o],n[o]]=[i,s]}return[t,n]}var US=(r,e)=>BigInt(r>>>0)<<Jp|BigInt(e>>>0),jS=(r,e,t)=>r>>>t,MS=(r,e,t)=>r<<32-t|e>>>t,KS=(r,e,t)=>r>>>t|e<<32-t,HS=(r,e,t)=>r<<32-t|e>>>t,VS=(r,e,t)=>r<<64-t|e>>>t-32,$S=(r,e,t)=>r>>>t-32|e<<64-t,FS=(r,e)=>e,WS=(r,e)=>r,qS=(r,e,t)=>r<<t|e>>>32-t,GS=(r,e,t)=>e<<t|r>>>32-t,zS=(r,e,t)=>e<<t-32|r>>>64-t,XS=(r,e,t)=>r<<t-32|e>>>64-t;function YS(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var ZS=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),JS=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,QS=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),eE=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,tE=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),rE=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var nE={fromBig:jg,split:DS,toBig:US,shrSH:jS,shrSL:MS,rotrSH:KS,rotrSL:HS,rotrBH:VS,rotrBL:$S,rotr32H:FS,rotr32L:WS,rotlSH:qS,rotlSL:GS,rotlBH:zS,rotlBL:XS,add:YS,add3L:ZS,add3H:JS,add4L:QS,add4H:eE,add5H:rE,add5L:tE},pe=nE;var[oE,iE]=pe.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Vn=new Uint32Array(80),$n=new Uint32Array(80),Qp=class extends zi{constructor(e=64){super(128,e,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:h,Fh:p,Fl:y,Gh:w,Gl:b,Hh:g,Hl:m}=this;return[e,t,n,o,i,s,a,c,u,h,p,y,w,b,g,m]}set(e,t,n,o,i,s,a,c,u,h,p,y,w,b,g,m){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=h|0,this.Fh=p|0,this.Fl=y|0,this.Gh=w|0,this.Gl=b|0,this.Hh=g|0,this.Hl=m|0}process(e,t){for(let v=0;v<16;v++,t+=4)Vn[v]=e.getUint32(t),$n[v]=e.getUint32(t+=4);for(let v=16;v<80;v++){let N=Vn[v-15]|0,W=$n[v-15]|0,H=pe.rotrSH(N,W,1)^pe.rotrSH(N,W,8)^pe.shrSH(N,W,7),O=pe.rotrSL(N,W,1)^pe.rotrSL(N,W,8)^pe.shrSL(N,W,7),K=Vn[v-2]|0,L=$n[v-2]|0,te=pe.rotrSH(K,L,19)^pe.rotrBH(K,L,61)^pe.shrSH(K,L,6),z=pe.rotrSL(K,L,19)^pe.rotrBL(K,L,61)^pe.shrSL(K,L,6),Y=pe.add4L(O,z,$n[v-7],$n[v-16]),le=pe.add4H(Y,H,te,Vn[v-7],Vn[v-16]);Vn[v]=le|0,$n[v]=Y|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:h,Eh:p,El:y,Fh:w,Fl:b,Gh:g,Gl:m,Hh:S,Hl:T}=this;for(let v=0;v<80;v++){let N=pe.rotrSH(p,y,14)^pe.rotrSH(p,y,18)^pe.rotrBH(p,y,41),W=pe.rotrSL(p,y,14)^pe.rotrSL(p,y,18)^pe.rotrBL(p,y,41),H=p&w^~p&g,O=y&b^~y&m,K=pe.add5L(T,W,O,iE[v],$n[v]),L=pe.add5H(K,S,N,H,oE[v],Vn[v]),te=K|0,z=pe.rotrSH(n,o,28)^pe.rotrBH(n,o,34)^pe.rotrBH(n,o,39),Y=pe.rotrSL(n,o,28)^pe.rotrBL(n,o,34)^pe.rotrBL(n,o,39),le=n&i^n&a^i&a,R=o&s^o&c^s&c;S=g|0,T=m|0,g=w|0,m=b|0,w=p|0,b=y|0,{h:p,l:y}=pe.add(u|0,h|0,L|0,te|0),u=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let D=pe.add3L(te,Y,R);n=pe.add3H(D,L,z,le),o=D|0}({h:n,l:o}=pe.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=pe.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=pe.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:h}=pe.add(this.Dh|0,this.Dl|0,u|0,h|0),{h:p,l:y}=pe.add(this.Eh|0,this.El|0,p|0,y|0),{h:w,l:b}=pe.add(this.Fh|0,this.Fl|0,w|0,b|0),{h:g,l:m}=pe.add(this.Gh|0,this.Gl|0,g|0,m|0),{h:S,l:T}=pe.add(this.Hh|0,this.Hl|0,S|0,T|0),this.set(n,o,i,s,a,c,u,h,p,y,w,b,g,m,S,T)}roundClean(){Vn.fill(0),$n.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var eh=Rl(()=>new Qp);var oh=BigInt(0),nh=BigInt(1);function Po(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ih(r){if(!Po(r))throw new Error("Uint8Array expected")}function Ur(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function pa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function Hg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?oh:BigInt("0x"+r)}var Vg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",sE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Fn(r){if(ih(r),Vg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=sE[r[t]];return e}var cn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Mg(r){if(r>=cn._0&&r<=cn._9)return r-cn._0;if(r>=cn.A&&r<=cn.F)return r-(cn.A-10);if(r>=cn.a&&r<=cn.f)return r-(cn.a-10)}function ha(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Vg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=Mg(r.charCodeAt(i)),a=Mg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ln(r){return Hg(Fn(r))}function jr(r){return ih(r),Hg(Fn(Uint8Array.from(r).reverse()))}function No(r,e){return ha(r.toString(16).padStart(e*2,"0"))}function Wn(r,e){return No(r,e).reverse()}function Le(r,e,t){let n;if(typeof e=="string")try{n=ha(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Po(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function qn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ih(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var th=r=>typeof r=="bigint"&&oh<=r;function Dl(r,e,t){return th(r)&&th(e)&&th(t)&&e<=r&&r<t}function St(r,e,t,n){if(!Dl(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function $g(r){let e;for(e=0;r>oh;r>>=nh,e+=1);return e}var Oo=r=>(nh<<BigInt(r))-nh,rh=r=>new Uint8Array(r),Kg=r=>Uint8Array.from(r);function Fg(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=rh(r),o=rh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...p)=>t(o,n,...p),c=(p=rh(0))=>{o=a(Kg([0]),p),n=a(),p.length!==0&&(o=a(Kg([1]),p),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,y=[];for(;p<e;){n=a();let w=n.slice();y.push(w),p+=n.length}return qn(...y)};return(p,y)=>{s(),c(p);let w;for(;!(w=y(u()));)c();return s(),w}}var aE={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Po(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Ar(r,e,t={}){let n=(o,i,s)=>{let a=aE[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}function Xi(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var at=BigInt(0),He=BigInt(1),Ro=BigInt(2),cE=BigInt(3),sh=BigInt(4),Wg=BigInt(5),qg=BigInt(8),lE=BigInt(9),uE=BigInt(16);function _e(r,e){let t=r%e;return t>=at?t:e+t}function ah(r,e,t){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(t<=at)throw new Error("invalid modulus");if(t===He)return at;let n=He;for(;e>at;)e&He&&(n=n*r%t),r=r*r%t,e>>=He;return n}function Ke(r,e,t){let n=r;for(;e-- >at;)n*=n,n%=t;return n}function Ul(r,e){if(r===at)throw new Error("invert: expected non-zero number");if(e<=at)throw new Error("invert: expected positive modulus, got "+e);let t=_e(r,e),n=e,o=at,i=He,s=He,a=at;for(;t!==at;){let u=n/t,h=n%t,p=o-s*u,y=i-a*u;n=t,t=h,o=s,i=a,s=p,a=y}if(n!==He)throw new Error("invert: does not exist");return _e(o,e)}function fE(r){let e=(r-He)/Ro,t,n,o;for(t=r-He,n=0;t%Ro===at;t/=Ro,n++);for(o=Ro;o<r&&ah(o,e,r)!==r-He;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+He)/sh;return function(c,u){let h=c.pow(u,s);if(!c.eql(c.sqr(h),u))throw new Error("Cannot find square root");return h}}let i=(t+He)/Ro;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,h=a.pow(a.mul(a.ONE,o),t),p=a.pow(c,i),y=a.pow(c,t);for(;!a.eql(y,a.ONE);){if(a.eql(y,a.ZERO))return a.ZERO;let w=1;for(let g=a.sqr(y);w<u&&!a.eql(g,a.ONE);w++)g=a.sqr(g);let b=a.pow(h,He<<BigInt(u-w-1));h=a.sqr(b),p=a.mul(p,b),y=a.mul(y,h),u=w}return p}}function pE(r){if(r%sh===cE){let e=(r+He)/sh;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%qg===Wg){let e=(r-Wg)/qg;return function(n,o){let i=n.mul(o,Ro),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,Ro),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%uE,fE(r)}var Gg=(r,e)=>(_e(r,e)&He)===He,hE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ch(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=hE.reduce((n,o)=>(n[o]="function",n),e);return Ar(r,t)}function dE(r,e,t){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(t===at)return r.ONE;if(t===He)return e;let n=r.ONE,o=e;for(;t>at;)t&He&&(n=r.mul(n,o)),o=r.sqr(o),t>>=He;return n}function mE(r,e){let t=new Array(e.length),n=e.reduce((i,s,a)=>r.is0(s)?i:(t[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return e.reduceRight((i,s,a)=>r.is0(s)?i:(t[a]=r.mul(i,t[a]),r.mul(i,s)),o),t}function lh(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Gn(r,e,t=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=lh(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:t,BITS:o,BYTES:i,MASK:Oo(o),ZERO:at,ONE:He,create:c=>_e(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&He)===He,neg:c=>_e(-c,r),eql:(c,u)=>c===u,sqr:c=>_e(c*c,r),add:(c,u)=>_e(c+u,r),sub:(c,u)=>_e(c-u,r),mul:(c,u)=>_e(c*u,r),pow:(c,u)=>dE(a,c,u),div:(c,u)=>_e(c*Ul(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Ul(c,r),sqrt:n.sqrt||(c=>(s||(s=pE(r)),s(a,c))),invertBatch:c=>mE(a,c),cmov:(c,u,h)=>h?u:c,toBytes:c=>t?Wn(c,i):No(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?jr(c):ln(c)}});return Object.freeze(a)}function zg(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function uh(r){let e=zg(r);return e+Math.ceil(e/2)}function Xg(r,e,t=!1){let n=r.length,o=zg(e),i=uh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?jr(r):ln(r),a=_e(s,e-He)+He;return t?Wn(a,o):No(a,o)}var Yg=BigInt(0),mh=BigInt(1);function fh(r,e){let t=e.negate();return r?t:e}function Jg(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function ph(r,e){Jg(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Oo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Zg(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=mh);let u=e*n,h=u+Math.abs(a)-1,p=a===0,y=a<0,w=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:y,isNegF:w,offsetF:u}}function yE(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function gE(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var hh=new WeakMap,Qg=new WeakMap;function dh(r){return Qg.get(r)||1}function jl(r,e){return{constTimeNegate:fh,hasPrecomputes(t){return dh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>Yg;)n&mh&&(o=o.add(i)),i=i.double(),n>>=mh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=ph(n,e),s=[],a=t,c=a;for(let u=0;u<o;u++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=ph(t,e);for(let c=0;c<a.windows;c++){let{nextN:u,offset:h,isZero:p,isNeg:y,isNegF:w,offsetF:b}=Zg(o,c,a);o=u,p?s=s.add(fh(w,n[b])):i=i.add(fh(y,n[h]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=ph(t,e);for(let a=0;a<s.windows&&o!==Yg;a++){let{nextN:c,offset:u,isZero:h,isNeg:p}=Zg(o,a,s);if(o=c,!h){let y=n[u];i=i.add(p?y.negate():y)}}return i},getPrecomputes(t,n,o){let i=hh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&hh.set(n,o(i))),i},wNAFCached(t,n,o){let i=dh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=dh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){Jg(n,e),Qg.set(t,n),hh.delete(t)}}}function Ml(r,e,t,n){if(yE(t,r),gE(n,e),t.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,i=$g(BigInt(t.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=Oo(s),c=new Array(Number(a)+1).fill(o),u=Math.floor((e.BITS-1)/s)*s,h=o;for(let p=u;p>=0;p-=s){c.fill(o);for(let w=0;w<n.length;w++){let b=n[w],g=Number(b>>BigInt(p)&a);c[g]=c[g].add(t[w])}let y=o;for(let w=c.length-1,b=o;w>0;w--)b=b.add(c[w]),y=y.add(b);if(h=h.add(y),p!==0)for(let w=0;w<s;w++)h=h.double()}return h}function da(r){return ch(r.Fp),Ar(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...lh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Mr=BigInt(0),kt=BigInt(1),e0=BigInt(2),wE=BigInt(8),xE={zip215:!0};function bE(r){let e=da(r);return Ar(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function t0(r){let e=bE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,u=e0<<BigInt(a*8)-kt,h=t.create,p=Gn(e.n,e.nBitLength),y=e.uvRatio||((k,C)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(C))}}catch{return{isValid:!1,value:Mr}}}),w=e.adjustScalarBytes||(k=>k),b=e.domain||((k,C,I)=>{if(Ur("phflag",I),C.length||I)throw new Error("Contexts/pre-hash are not supported");return k});function g(k,C,I=!1){let U=I?kt:Mr;St("coordinate "+k,C,U,u)}function m(k){if(!(k instanceof v))throw new Error("ExtendedPoint expected")}let S=Xi((k,C)=>{let{ex:I,ey:U,ez:q}=k,P=k.is0();C==null&&(C=P?wE:t.inv(q));let ie=h(I*C),ue=h(U*C),Q=h(q*C);if(P)return{x:Mr,y:kt};if(Q!==kt)throw new Error("invZ was invalid");return{x:ie,y:ue}}),T=Xi(k=>{let{a:C,d:I}=e;if(k.is0())throw new Error("bad point: ZERO");let{ex:U,ey:q,ez:P,et:ie}=k,ue=h(U*U),Q=h(q*q),ye=h(P*P),Te=h(ye*ye),Ee=h(ue*C),Re=h(ye*h(Ee+Q)),je=h(Te+h(I*h(ue*Q)));if(Re!==je)throw new Error("bad point: equation left != right (1)");let Ye=h(U*q),$e=h(P*ie);if(Ye!==$e)throw new Error("bad point: equation left != right (2)");return!0});class v{constructor(C,I,U,q){g("x",C),g("y",I),g("z",U,!0),g("t",q),this.ex=C,this.ey=I,this.ez=U,this.et=q,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(C){if(C instanceof v)throw new Error("extended point not allowed");let{x:I,y:U}=C||{};return g("x",I),g("y",U),new v(I,U,kt,h(I*U))}static normalizeZ(C){let I=t.invertBatch(C.map(U=>U.ez));return C.map((U,q)=>U.toAffine(I[q])).map(v.fromAffine)}static msm(C,I){return Ml(v,p,C,I)}_setWindowSize(C){H.setWindowSize(this,C)}assertValidity(){T(this)}equals(C){m(C);let{ex:I,ey:U,ez:q}=this,{ex:P,ey:ie,ez:ue}=C,Q=h(I*ue),ye=h(P*q),Te=h(U*ue),Ee=h(ie*q);return Q===ye&&Te===Ee}is0(){return this.equals(v.ZERO)}negate(){return new v(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:C}=e,{ex:I,ey:U,ez:q}=this,P=h(I*I),ie=h(U*U),ue=h(e0*h(q*q)),Q=h(C*P),ye=I+U,Te=h(h(ye*ye)-P-ie),Ee=Q+ie,Re=Ee-ue,je=Q-ie,Ye=h(Te*Re),$e=h(Ee*je),bt=h(Te*je),Gt=h(Re*Ee);return new v(Ye,$e,Gt,bt)}add(C){m(C);let{a:I,d:U}=e,{ex:q,ey:P,ez:ie,et:ue}=this,{ex:Q,ey:ye,ez:Te,et:Ee}=C,Re=h(q*Q),je=h(P*ye),Ye=h(ue*U*Ee),$e=h(ie*Te),bt=h((q+P)*(Q+ye)-Re-je),Gt=$e-Ye,nn=$e+Ye,ea=h(je-I*Re),pl=h(bt*Gt),hl=h(nn*ea),dl=h(bt*ea),ml=h(Gt*nn);return new v(pl,hl,ml,dl)}subtract(C){return this.add(C.negate())}wNAF(C){return H.wNAFCached(this,C,v.normalizeZ)}multiply(C){let I=C;St("scalar",I,kt,n);let{p:U,f:q}=this.wNAF(I);return v.normalizeZ([U,q])[0]}multiplyUnsafe(C,I=v.ZERO){let U=C;return St("scalar",U,Mr,n),U===Mr?W:this.is0()||U===kt?this:H.wNAFCachedUnsafe(this,U,v.normalizeZ,I)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return H.unsafeLadder(this,n).is0()}toAffine(C){return S(this,C)}clearCofactor(){let{h:C}=e;return C===kt?this:this.multiplyUnsafe(C)}static fromHex(C,I=!1){let{d:U,a:q}=e,P=t.BYTES;C=Le("pointHex",C,P),Ur("zip215",I);let ie=C.slice(),ue=C[P-1];ie[P-1]=ue&-129;let Q=jr(ie),ye=I?u:t.ORDER;St("pointHex.y",Q,Mr,ye);let Te=h(Q*Q),Ee=h(Te-kt),Re=h(U*Te-q),{isValid:je,value:Ye}=y(Ee,Re);if(!je)throw new Error("Point.fromHex: invalid y coordinate");let $e=(Ye&kt)===kt,bt=(ue&128)!==0;if(!I&&Ye===Mr&&bt)throw new Error("Point.fromHex: x=0 and x_0=1");return bt!==$e&&(Ye=h(-Ye)),v.fromAffine({x:Ye,y:Q})}static fromPrivateKey(C){let{scalar:I}=L(C);return N.multiply(I)}toRawBytes(){let{x:C,y:I}=this.toAffine(),U=Wn(I,t.BYTES);return U[U.length-1]|=C&kt?128:0,U}toHex(){return Fn(this.toRawBytes())}}v.BASE=new v(e.Gx,e.Gy,kt,h(e.Gx*e.Gy)),v.ZERO=new v(Mr,kt,kt,Mr);let{BASE:N,ZERO:W}=v,H=jl(v,a*8);function O(k){return _e(k,n)}function K(k){return O(jr(k))}function L(k){let C=t.BYTES;k=Le("private key",k,C);let I=Le("hashed private key",i(k),2*C),U=w(I.slice(0,C)),q=I.slice(C,2*C),P=K(U);return{head:U,prefix:q,scalar:P}}function te(k){let{head:C,prefix:I,scalar:U}=L(k),q=N.multiply(U),P=q.toRawBytes();return{head:C,prefix:I,scalar:U,point:q,pointBytes:P}}function z(k){return te(k).pointBytes}function Y(k=new Uint8Array,...C){let I=qn(...C);return K(i(b(I,Le("context",k),!!o)))}function le(k,C,I={}){k=Le("message",k),o&&(k=o(k));let{prefix:U,scalar:q,pointBytes:P}=te(C),ie=Y(I.context,U,k),ue=N.multiply(ie).toRawBytes(),Q=Y(I.context,ue,P,k),ye=O(ie+Q*q);St("signature.s",ye,Mr,n);let Te=qn(ue,Wn(ye,t.BYTES));return Le("result",Te,t.BYTES*2)}let R=xE;function D(k,C,I,U=R){let{context:q,zip215:P}=U,ie=t.BYTES;k=Le("signature",k,2*ie),C=Le("message",C),I=Le("publicKey",I,ie),P!==void 0&&Ur("zip215",P),o&&(C=o(C));let ue=jr(k.slice(ie,2*ie)),Q,ye,Te;try{Q=v.fromHex(I,P),ye=v.fromHex(k.slice(0,ie),P),Te=N.multiplyUnsafe(ue)}catch{return!1}if(!P&&Q.isSmallOrder())return!1;let Ee=Y(q,ye.toRawBytes(),Q.toRawBytes(),C);return ye.add(Q.multiplyUnsafe(Ee)).subtract(Te).clearCofactor().equals(v.ZERO)}return N._setWindowSize(8),{CURVE:e,getPublicKey:z,sign:le,verify:D,ExtendedPoint:v,utils:{getExtendedPublicKey:te,randomPrivateKey:()=>s(t.BYTES),precompute(k=8,C=v.BASE){return C._setWindowSize(k),C.multiply(BigInt(3)),C}}}}var Yi=BigInt(0),yh=BigInt(1);function vE(r){return Ar(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function r0(r){let e=vE(r),{P:t}=e,n=T=>_e(T,t),o=e.montgomeryBits,i=Math.ceil(o/8),s=e.nByteLength,a=e.adjustScalarBytes||(T=>T),c=e.powPminus2||(T=>ah(T,t-BigInt(2),t));function u(T,v,N){let W=n(T*(v-N));return v=n(v-W),N=n(N+W),[v,N]}let h=(e.a-BigInt(2))/BigInt(4);function p(T,v){St("u",T,Yi,t),St("scalar",v,Yi,t);let N=v,W=T,H=yh,O=Yi,K=T,L=yh,te=Yi,z;for(let le=BigInt(o-1);le>=Yi;le--){let R=N>>le&yh;te^=R,z=u(te,H,K),H=z[0],K=z[1],z=u(te,O,L),O=z[0],L=z[1],te=R;let D=H+O,j=n(D*D),k=H-O,C=n(k*k),I=j-C,U=K+L,q=K-L,P=n(q*D),ie=n(U*k),ue=P+ie,Q=P-ie;K=n(ue*ue),L=n(W*n(Q*Q)),H=n(j*C),O=n(I*(j+n(h*I)))}z=u(te,H,K),H=z[0],K=z[1],z=u(te,O,L),O=z[0],L=z[1];let Y=c(O);return n(H*Y)}function y(T){return Wn(n(T),i)}function w(T){let v=Le("u coordinate",T,i);return s===32&&(v[31]&=127),jr(v)}function b(T){let v=Le("scalar",T),N=v.length;if(N!==i&&N!==s){let W=""+i+" or "+s;throw new Error("invalid scalar, expected "+W+" bytes, got "+N)}return jr(a(v))}function g(T,v){let N=w(v),W=b(T),H=p(N,W);if(H===Yi)throw new Error("invalid private or public key received");return y(H)}let m=y(e.Gu);function S(T){return g(T,m)}return{scalarMult:g,scalarMultBase:S,getSharedSecret:(T,v)=>g(T,v),getPublicKey:T=>S(T),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:m}}var ma=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),n0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),YB=BigInt(0),AE=BigInt(1),o0=BigInt(2),SE=BigInt(3),EE=BigInt(5),_E=BigInt(8);function s0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=ma,a=r*r%i*r%i,c=Ke(a,o0,i)*a%i,u=Ke(c,AE,i)*r%i,h=Ke(u,EE,i)*u%i,p=Ke(h,e,i)*h%i,y=Ke(p,t,i)*p%i,w=Ke(y,n,i)*y%i,b=Ke(w,o,i)*w%i,g=Ke(b,o,i)*w%i,m=Ke(g,e,i)*h%i;return{pow_p_5_8:Ke(m,o0,i)*r%i,b2:a}}function a0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function CE(r,e){let t=ma,n=_e(e*e*e,t),o=_e(n*n*e,t),i=s0(r*o).pow_p_5_8,s=_e(r*n*i,t),a=_e(e*s*s,t),c=s,u=_e(s*n0,t),h=a===r,p=a===_e(-r,t),y=a===_e(-r*n0,t);return h&&(s=c),(p||y)&&(s=u),Gg(s,t)&&(s=_e(-s,t)),{isValid:h||p,value:s}}var i0=Gn(ma,void 0,!0),IE={a:i0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:i0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:_E,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:eh,randomBytes:fa,adjustScalarBytes:a0,uvRatio:CE},ya=t0(IE);var ga=r0({P:ma,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=ma,{pow_p_5_8:t,b2:n}=s0(r);return _e(Ke(t,SE,e)*n,e)},adjustScalarBytes:a0,randomBytes:fa});var Kl=32,Hl=64,gh=32;function c0(){let r=ya.utils.randomPrivateKey(),e=ya.getPublicKey(r);return{privateKey:TE(r,e),publicKey:e}}function l0(r,e){let t=r.subarray(0,gh);return ya.sign(e instanceof Uint8Array?e:e.subarray(),t)}function u0(r,e,t){return ya.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function TE(r,e){let t=new Uint8Array(Hl);for(let n=0;n<gh;n++)t[n]=r[n],t[gh+n]=e[n];return t}var wa=class{type="Ed25519";raw;constructor(e){this.raw=$l(e,Kl)}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}verify(e,t){return u0(this.raw,t,e)}},Vl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=$l(e,Hl),this.publicKey=new wa(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}sign(e){return l0(this.raw,e)}};function wh(r){return r=$l(r,Kl),new wa(r)}async function p0(){let{privateKey:r,publicKey:e}=c0();return new Vl(r,e)}function $l(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var BE=Math.pow(2,7),kE=Math.pow(2,14),PE=Math.pow(2,21),xh=Math.pow(2,28),bh=Math.pow(2,35),vh=Math.pow(2,42),Ah=Math.pow(2,49),Ie=128,Et=127;function Be(r){if(r<BE)return 1;if(r<kE)return 2;if(r<PE)return 3;if(r<xh)return 4;if(r<bh)return 5;if(r<vh)return 6;if(r<Ah)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Sh(r,e,t=0){switch(Be(r)){case 8:e[t++]=r&255|Ie,r/=128;case 7:e[t++]=r&255|Ie,r/=128;case 6:e[t++]=r&255|Ie,r/=128;case 5:e[t++]=r&255|Ie,r/=128;case 4:e[t++]=r&255|Ie,r>>>=7;case 3:e[t++]=r&255|Ie,r>>>=7;case 2:e[t++]=r&255|Ie,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function NE(r,e,t=0){switch(Be(r)){case 8:e.set(t++,r&255|Ie),r/=128;case 7:e.set(t++,r&255|Ie),r/=128;case 6:e.set(t++,r&255|Ie),r/=128;case 5:e.set(t++,r&255|Ie),r/=128;case 4:e.set(t++,r&255|Ie),r>>>=7;case 3:e.set(t++,r&255|Ie),r>>>=7;case 2:e.set(t++,r&255|Ie),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Eh(r,e){let t=r[e],n=0;if(n+=t&Et,t<Ie||(t=r[e+1],n+=(t&Et)<<7,t<Ie)||(t=r[e+2],n+=(t&Et)<<14,t<Ie)||(t=r[e+3],n+=(t&Et)<<21,t<Ie)||(t=r[e+4],n+=(t&Et)*xh,t<Ie)||(t=r[e+5],n+=(t&Et)*bh,t<Ie)||(t=r[e+6],n+=(t&Et)*vh,t<Ie)||(t=r[e+7],n+=(t&Et)*Ah,t<Ie))return n;throw new RangeError("Could not decode varint")}function OE(r,e){let t=r.get(e),n=0;if(n+=t&Et,t<Ie||(t=r.get(e+1),n+=(t&Et)<<7,t<Ie)||(t=r.get(e+2),n+=(t&Et)<<14,t<Ie)||(t=r.get(e+3),n+=(t&Et)<<21,t<Ie)||(t=r.get(e+4),n+=(t&Et)*xh,t<Ie)||(t=r.get(e+5),n+=(t&Et)*bh,t<Ie)||(t=r.get(e+6),n+=(t&Et)*vh,t<Ie)||(t=r.get(e+7),n+=(t&Et)*Ah,t<Ie))return n;throw new RangeError("Could not decode varint")}function rr(r,e,t=0){return e==null&&(e=et(Be(r))),e instanceof Uint8Array?Sh(r,e,t):NE(r,e,t)}function zt(r,e=0){return r instanceof Uint8Array?Eh(r,e):OE(r,e)}var _h=new Float32Array([-0]),zn=new Uint8Array(_h.buffer);function h0(r,e,t){_h[0]=r,e[t]=zn[0],e[t+1]=zn[1],e[t+2]=zn[2],e[t+3]=zn[3]}function d0(r,e){return zn[0]=r[e],zn[1]=r[e+1],zn[2]=r[e+2],zn[3]=r[e+3],_h[0]}var Ch=new Float64Array([-0]),_t=new Uint8Array(Ch.buffer);function m0(r,e,t){Ch[0]=r,e[t]=_t[0],e[t+1]=_t[1],e[t+2]=_t[2],e[t+3]=_t[3],e[t+4]=_t[4],e[t+5]=_t[5],e[t+6]=_t[6],e[t+7]=_t[7]}function y0(r,e){return _t[0]=r[e],_t[1]=r[e+1],_t[2]=r[e+2],_t[3]=r[e+3],_t[4]=r[e+4],_t[5]=r[e+5],_t[6]=r[e+6],_t[7]=r[e+7],Ch[0]}var RE=BigInt(Number.MAX_SAFE_INTEGER),LE=BigInt(Number.MIN_SAFE_INTEGER),Xt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Do;if(e<RE&&e>LE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>g0&&(o=0n,++n>g0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Do;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Do}},Do=new Xt(0,0);Do.toBigInt=function(){return 0n};Do.zzEncode=Do.zzDecode=function(){return this};Do.length=function(){return 1};var g0=4294967296n;function w0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function x0(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ih(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Sr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Fl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Th=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Sr(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Sr(this,4);return Fl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Sr(this,4);return Fl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Sr(this,4);let e=d0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Sr(this,4);let e=y0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Sr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return x0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Sr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Sr(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Xt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Sr(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Sr(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Sr(this,8);let e=Fl(this.buf,this.pos+=4),t=Fl(this.buf,this.pos+=4);return new Xt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Eh(this.buf,this.pos);return this.pos+=Be(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bh(r){return new Th(r instanceof Uint8Array?r:r.subarray())}function Er(r,e,t){let n=Bh(r);return e.decode(n,void 0,t)}function kh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return et(s);o+s>e&&(n=et(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Uo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Ph(){}var Oh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},DE=kh();function UE(r){return globalThis.Buffer!=null?et(r):DE(r)}var ba=class{len;head;tail;states;constructor(){this.len=0,this.head=new Uo(Ph,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Uo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Rh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Wl,10,Xt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Xt.fromBigInt(e);return this._push(Wl,t.length(),t)}uint64Number(e){return this._push(Sh,Be(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Xt.fromBigInt(e).zzEncode();return this._push(Wl,t.length(),t)}sint64Number(e){let t=Xt.fromNumber(e).zzEncode();return this._push(Wl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Nh,1,e?1:0)}fixed32(e){return this._push(xa,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Xt.fromBigInt(e);return this._push(xa,4,t.lo)._push(xa,4,t.hi)}fixed64Number(e){let t=Xt.fromNumber(e);return this._push(xa,4,t.lo)._push(xa,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(h0,4,e)}double(e){return this._push(m0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Nh,1,0):this.uint32(t)._push(ME,t,e)}string(e){let t=w0(e);return t!==0?this.uint32(t)._push(Ih,t,e):this._push(Nh,1,0)}fork(){return this.states=new Oh(this),this.head=this.tail=new Uo(Ph,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Uo(Ph,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=UE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Nh(r,e,t){e[t]=r&255}function jE(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Rh=class extends Uo{next;constructor(e,t){super(jE,e,t),this.next=void 0}};function Wl(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function xa(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function ME(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ba.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(KE,e,r),this},ba.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(HE,e,r),this});function KE(r,e,t){e.set(r,t)}function HE(r,e,t){r.length<40?Ih(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function Lh(){return new ba}function _r(r,e){let t=Lh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Zi;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Zi||(Zi={}));function ql(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function jo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return ql("enum",Zi.VARINT,t,n)}function Cr(r,e){return ql("message",Zi.LENGTH_DELIMITED,r,e)}var va=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Dh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Dh||(Dh={}));(function(r){r.codec=()=>jo(Dh)})(tt||(tt={}));var Kr;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),tt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(Kr||(Kr={}));var Uh;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),tt.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=tt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(Uh||(Uh={}));var Aa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Sa=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Gl=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var A0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new Gl("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Xn=A0;var _a={};vt(_a,{MAX_RSA_KEY_SIZE:()=>jh,generateRSAKeyPair:()=>Gh,jwkToJWKKeyPair:()=>C0,jwkToPkcs1:()=>WE,jwkToPkix:()=>Vh,jwkToRSAPrivateKey:()=>qh,pkcs1MessageToJwk:()=>Kh,pkcs1MessageToRSAPrivateKey:()=>$h,pkcs1ToJwk:()=>FE,pkcs1ToRSAPrivateKey:()=>_0,pkixMessageToJwk:()=>Hh,pkixMessageToRSAPublicKey:()=>Wh,pkixToJwk:()=>qE,pkixToRSAPublicKey:()=>Fh});var Ji=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=_a.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Qe.createV1(114,this._multihash)}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}verify(e,t){return E0(this.jwk,t,e)}},Ea=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=_a.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}sign(e){return S0(this.jwk,e)}};var jh=8192,Mh=18,VE=1062,$E=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function FE(r){let e=an(r);return Kh(e)}function Kh(r){return{n:ce(r[1],"base64url"),e:ce(r[2],"base64url"),d:ce(r[3],"base64url"),p:ce(r[4],"base64url"),q:ce(r[5],"base64url"),dp:ce(r[6],"base64url"),dq:ce(r[7],"base64url"),qi:ce(r[8],"base64url"),kty:"RSA"}}function WE(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return xr([Bt(Uint8Array.from([0])),Bt(de(r.n,"base64url")),Bt(de(r.e,"base64url")),Bt(de(r.d,"base64url")),Bt(de(r.p,"base64url")),Bt(de(r.q,"base64url")),Bt(de(r.dp,"base64url")),Bt(de(r.dq,"base64url")),Bt(de(r.qi,"base64url"))]).subarray()}function qE(r){let e=an(r,{offset:0});return Hh(e)}function Hh(r){let e=an(r[1],{offset:0});return{kty:"RSA",n:ce(e[0],"base64url"),e:ce(e[1],"base64url")}}function Vh(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return xr([$E,la(xr([Bt(de(r.n,"base64url")),Bt(de(r.e,"base64url"))]))]).subarray()}function _0(r){let e=an(r);return $h(e)}function $h(r){let e=Kh(r);return qh(e)}function Fh(r,e){if(r.byteLength>=VE)throw new Ki("Key size is too large");let t=an(r,{offset:0});return Wh(t,r,e)}function Wh(r,e,t){let n=Hh(r);if(t==null){let o=vr(Kr.encode({Type:tt.RSA,Data:e}));t=At(Mh,o)}return new Ji(n,t)}function qh(r){if(T0(r)>jh)throw new ve("Key size is too large");let e=C0(r),t=vr(Kr.encode({Type:tt.RSA,Data:Vh(e.publicKey)})),n=At(Mh,t);return new Ea(e.privateKey,new Ji(e.publicKey,n))}async function Gh(r){if(r>jh)throw new ve("Key size is too large");let e=await I0(r),t=vr(Kr.encode({Type:tt.RSA,Data:Vh(e.publicKey)})),n=At(Mh,t);return new Ea(e.privateKey,new Ji(e.publicKey,n))}function C0(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function I0(r){let e=await Xn.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await GE(e);return{privateKey:t[0],publicKey:t[1]}}async function S0(r,e){let t=await Xn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Xn.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function E0(r,e,t){let n=await Xn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Xn.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function GE(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([Xn.get().subtle.exportKey("jwk",r.privateKey),Xn.get().subtle.exportKey("jwk",r.publicKey)])}function T0(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return de(r.n,"base64url").length*8}var zl=class extends Gi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ua(e);let n=Mn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return qi(this),this.iHash.update(e),this}digestInto(e){qi(this),Wi(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qi=(r,e,t)=>new zl(r,e).update(t).digest();Qi.create=(r,e)=>new zl(r,e);function B0(r){r.lowS!==void 0&&Ur("lowS",r.lowS),r.prehash!==void 0&&Ur("prehash",r.prehash)}function zE(r){let e=da(r);Ar(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var zh=class extends Error{constructor(e=""){super(e)}},un={Err:zh,_tlv:{encode:(r,e)=>{let{Err:t}=un;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=pa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?pa(o.length/2|128):"";return pa(r)+i+o+e},decode(r,e){let{Err:t}=un,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of u)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=un;if(r<fn)throw new e("integer: negative integers are not allowed");let t=pa(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=un;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ln(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=un,o=Le("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(u)}},hexFromSig(r){let{_tlv:e,_int:t}=un,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},fn=BigInt(0),ut=BigInt(1),xk=BigInt(2),k0=BigInt(3),bk=BigInt(4);function XE(r){let e=zE(r),{Fp:t}=e,n=Gn(e.n,e.nBitLength),o=e.toBytes||((g,m,S)=>{let T=m.toAffine();return qn(Uint8Array.from([4]),t.toBytes(T.x),t.toBytes(T.y))}),i=e.fromBytes||(g=>{let m=g.subarray(1),S=t.fromBytes(m.subarray(0,t.BYTES)),T=t.fromBytes(m.subarray(t.BYTES,2*t.BYTES));return{x:S,y:T}});function s(g){let{a:m,b:S}=e,T=t.sqr(g),v=t.mul(T,g);return t.add(t.add(v,t.mul(g,m)),S)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(g){return Dl(g,ut,e.n)}function c(g){let{allowedPrivateKeyLengths:m,nByteLength:S,wrapPrivateKey:T,n:v}=e;if(m&&typeof g!="bigint"){if(Po(g)&&(g=Fn(g)),typeof g!="string"||!m.includes(g.length))throw new Error("invalid private key");g=g.padStart(S*2,"0")}let N;try{N=typeof g=="bigint"?g:ln(Le("private key",g,S))}catch{throw new Error("invalid private key, expected hex or "+S+" bytes, got "+typeof g)}return T&&(N=_e(N,v)),St("private key",N,ut,v),N}function u(g){if(!(g instanceof y))throw new Error("ProjectivePoint expected")}let h=Xi((g,m)=>{let{px:S,py:T,pz:v}=g;if(t.eql(v,t.ONE))return{x:S,y:T};let N=g.is0();m==null&&(m=N?t.ONE:t.inv(v));let W=t.mul(S,m),H=t.mul(T,m),O=t.mul(v,m);if(N)return{x:t.ZERO,y:t.ZERO};if(!t.eql(O,t.ONE))throw new Error("invZ was invalid");return{x:W,y:H}}),p=Xi(g=>{if(g.is0()){if(e.allowInfinityPoint&&!t.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:m,y:S}=g.toAffine();if(!t.isValid(m)||!t.isValid(S))throw new Error("bad point: x or y not FE");let T=t.sqr(S),v=s(m);if(!t.eql(T,v))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class y{constructor(m,S,T){if(m==null||!t.isValid(m))throw new Error("x required");if(S==null||!t.isValid(S))throw new Error("y required");if(T==null||!t.isValid(T))throw new Error("z required");this.px=m,this.py=S,this.pz=T,Object.freeze(this)}static fromAffine(m){let{x:S,y:T}=m||{};if(!m||!t.isValid(S)||!t.isValid(T))throw new Error("invalid affine point");if(m instanceof y)throw new Error("projective point not allowed");let v=N=>t.eql(N,t.ZERO);return v(S)&&v(T)?y.ZERO:new y(S,T,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let S=t.invertBatch(m.map(T=>T.pz));return m.map((T,v)=>T.toAffine(S[v])).map(y.fromAffine)}static fromHex(m){let S=y.fromAffine(i(Le("pointHex",m)));return S.assertValidity(),S}static fromPrivateKey(m){return y.BASE.multiply(c(m))}static msm(m,S){return Ml(y,n,m,S)}_setWindowSize(m){b.setWindowSize(this,m)}assertValidity(){p(this)}hasEvenY(){let{y:m}=this.toAffine();if(t.isOdd)return!t.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){u(m);let{px:S,py:T,pz:v}=this,{px:N,py:W,pz:H}=m,O=t.eql(t.mul(S,H),t.mul(N,v)),K=t.eql(t.mul(T,H),t.mul(W,v));return O&&K}negate(){return new y(this.px,t.neg(this.py),this.pz)}double(){let{a:m,b:S}=e,T=t.mul(S,k0),{px:v,py:N,pz:W}=this,H=t.ZERO,O=t.ZERO,K=t.ZERO,L=t.mul(v,v),te=t.mul(N,N),z=t.mul(W,W),Y=t.mul(v,N);return Y=t.add(Y,Y),K=t.mul(v,W),K=t.add(K,K),H=t.mul(m,K),O=t.mul(T,z),O=t.add(H,O),H=t.sub(te,O),O=t.add(te,O),O=t.mul(H,O),H=t.mul(Y,H),K=t.mul(T,K),z=t.mul(m,z),Y=t.sub(L,z),Y=t.mul(m,Y),Y=t.add(Y,K),K=t.add(L,L),L=t.add(K,L),L=t.add(L,z),L=t.mul(L,Y),O=t.add(O,L),z=t.mul(N,W),z=t.add(z,z),L=t.mul(z,Y),H=t.sub(H,L),K=t.mul(z,te),K=t.add(K,K),K=t.add(K,K),new y(H,O,K)}add(m){u(m);let{px:S,py:T,pz:v}=this,{px:N,py:W,pz:H}=m,O=t.ZERO,K=t.ZERO,L=t.ZERO,te=e.a,z=t.mul(e.b,k0),Y=t.mul(S,N),le=t.mul(T,W),R=t.mul(v,H),D=t.add(S,T),j=t.add(N,W);D=t.mul(D,j),j=t.add(Y,le),D=t.sub(D,j),j=t.add(S,v);let k=t.add(N,H);return j=t.mul(j,k),k=t.add(Y,R),j=t.sub(j,k),k=t.add(T,v),O=t.add(W,H),k=t.mul(k,O),O=t.add(le,R),k=t.sub(k,O),L=t.mul(te,j),O=t.mul(z,R),L=t.add(O,L),O=t.sub(le,L),L=t.add(le,L),K=t.mul(O,L),le=t.add(Y,Y),le=t.add(le,Y),R=t.mul(te,R),j=t.mul(z,j),le=t.add(le,R),R=t.sub(Y,R),R=t.mul(te,R),j=t.add(j,R),Y=t.mul(le,j),K=t.add(K,Y),Y=t.mul(k,j),O=t.mul(D,O),O=t.sub(O,Y),Y=t.mul(D,le),L=t.mul(k,L),L=t.add(L,Y),new y(O,K,L)}subtract(m){return this.add(m.negate())}is0(){return this.equals(y.ZERO)}wNAF(m){return b.wNAFCached(this,m,y.normalizeZ)}multiplyUnsafe(m){let{endo:S,n:T}=e;St("scalar",m,fn,T);let v=y.ZERO;if(m===fn)return v;if(this.is0()||m===ut)return this;if(!S||b.hasPrecomputes(this))return b.wNAFCachedUnsafe(this,m,y.normalizeZ);let{k1neg:N,k1:W,k2neg:H,k2:O}=S.splitScalar(m),K=v,L=v,te=this;for(;W>fn||O>fn;)W&ut&&(K=K.add(te)),O&ut&&(L=L.add(te)),te=te.double(),W>>=ut,O>>=ut;return N&&(K=K.negate()),H&&(L=L.negate()),L=new y(t.mul(L.px,S.beta),L.py,L.pz),K.add(L)}multiply(m){let{endo:S,n:T}=e;St("scalar",m,ut,T);let v,N;if(S){let{k1neg:W,k1:H,k2neg:O,k2:K}=S.splitScalar(m),{p:L,f:te}=this.wNAF(H),{p:z,f:Y}=this.wNAF(K);L=b.constTimeNegate(W,L),z=b.constTimeNegate(O,z),z=new y(t.mul(z.px,S.beta),z.py,z.pz),v=L.add(z),N=te.add(Y)}else{let{p:W,f:H}=this.wNAF(m);v=W,N=H}return y.normalizeZ([v,N])[0]}multiplyAndAddUnsafe(m,S,T){let v=y.BASE,N=(H,O)=>O===fn||O===ut||!H.equals(v)?H.multiplyUnsafe(O):H.multiply(O),W=N(this,S).add(N(m,T));return W.is0()?void 0:W}toAffine(m){return h(this,m)}isTorsionFree(){let{h:m,isTorsionFree:S}=e;if(m===ut)return!0;if(S)return S(y,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:S}=e;return m===ut?this:S?S(y,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return Ur("isCompressed",m),this.assertValidity(),o(y,this,m)}toHex(m=!0){return Ur("isCompressed",m),Fn(this.toRawBytes(m))}}y.BASE=new y(e.Gx,e.Gy,t.ONE),y.ZERO=new y(t.ZERO,t.ONE,t.ZERO);let w=e.nBitLength,b=jl(y,e.endo?Math.ceil(w/2):w);return{CURVE:e,ProjectivePoint:y,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function YE(r){let e=da(r);return Ar(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function P0(r){let e=YE(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(R){return _e(R,n)}function a(R){return Ul(R,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:h,isWithinCurveOrder:p}=XE({...e,toBytes(R,D,j){let k=D.toAffine(),C=t.toBytes(k.x),I=qn;return Ur("isCompressed",j),j?I(Uint8Array.from([D.hasEvenY()?2:3]),C):I(Uint8Array.from([4]),C,t.toBytes(k.y))},fromBytes(R){let D=R.length,j=R[0],k=R.subarray(1);if(D===o&&(j===2||j===3)){let C=ln(k);if(!Dl(C,ut,t.ORDER))throw new Error("Point is not on curve");let I=h(C),U;try{U=t.sqrt(I)}catch(ie){let ue=ie instanceof Error?": "+ie.message:"";throw new Error("Point is not on curve"+ue)}let q=(U&ut)===ut;return(j&1)===1!==q&&(U=t.neg(U)),{x:C,y:U}}else if(D===i&&j===4){let C=t.fromBytes(k.subarray(0,t.BYTES)),I=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:C,y:I}}else{let C=o,I=i;throw new Error("invalid Point, expected length of "+C+", or uncompressed "+I+", got "+D)}}}),y=R=>Fn(No(R,e.nByteLength));function w(R){let D=n>>ut;return R>D}function b(R){return w(R)?s(-R):R}let g=(R,D,j)=>ln(R.slice(D,j));class m{constructor(D,j,k){St("r",D,ut,n),St("s",j,ut,n),this.r=D,this.s=j,k!=null&&(this.recovery=k),Object.freeze(this)}static fromCompact(D){let j=e.nByteLength;return D=Le("compactSignature",D,j*2),new m(g(D,0,j),g(D,j,2*j))}static fromDER(D){let{r:j,s:k}=un.toSig(Le("DER",D));return new m(j,k)}assertValidity(){}addRecoveryBit(D){return new m(this.r,this.s,D)}recoverPublicKey(D){let{r:j,s:k,recovery:C}=this,I=H(Le("msgHash",D));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");let U=C===2||C===3?j+e.n:j;if(U>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let q=(C&1)===0?"02":"03",P=c.fromHex(q+y(U)),ie=a(U),ue=s(-I*ie),Q=s(k*ie),ye=c.BASE.multiplyAndAddUnsafe(P,ue,Q);if(!ye)throw new Error("point at infinify");return ye.assertValidity(),ye}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return ha(this.toDERHex())}toDERHex(){return un.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ha(this.toCompactHex())}toCompactHex(){return y(this.r)+y(this.s)}}let S={isValidPrivateKey(R){try{return u(R),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let R=uh(e.n);return Xg(e.randomBytes(R),e.n)},precompute(R=8,D=c.BASE){return D._setWindowSize(R),D.multiply(BigInt(3)),D}};function T(R,D=!0){return c.fromPrivateKey(R).toRawBytes(D)}function v(R){let D=Po(R),j=typeof R=="string",k=(D||j)&&R.length;return D?k===o||k===i:j?k===2*o||k===2*i:R instanceof c}function N(R,D,j=!0){if(v(R))throw new Error("first arg must be private key");if(!v(D))throw new Error("second arg must be public key");return c.fromHex(D).multiply(u(R)).toRawBytes(j)}let W=e.bits2int||function(R){if(R.length>8192)throw new Error("input is too large");let D=ln(R),j=R.length*8-e.nBitLength;return j>0?D>>BigInt(j):D},H=e.bits2int_modN||function(R){return s(W(R))},O=Oo(e.nBitLength);function K(R){return St("num < 2^"+e.nBitLength,R,fn,O),No(R,e.nByteLength)}function L(R,D,j=te){if(["recovered","canonical"].some(Ee=>Ee in j))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:C}=e,{lowS:I,prehash:U,extraEntropy:q}=j;I==null&&(I=!0),R=Le("msgHash",R),B0(j),U&&(R=Le("prehashed msgHash",k(R)));let P=H(R),ie=u(D),ue=[K(ie),K(P)];if(q!=null&&q!==!1){let Ee=q===!0?C(t.BYTES):q;ue.push(Le("extraEntropy",Ee))}let Q=qn(...ue),ye=P;function Te(Ee){let Re=W(Ee);if(!p(Re))return;let je=a(Re),Ye=c.BASE.multiply(Re).toAffine(),$e=s(Ye.x);if($e===fn)return;let bt=s(je*s(ye+$e*ie));if(bt===fn)return;let Gt=(Ye.x===$e?0:2)|Number(Ye.y&ut),nn=bt;return I&&w(bt)&&(nn=b(bt),Gt^=1),new m($e,nn,Gt)}return{seed:Q,k2sig:Te}}let te={lowS:e.lowS,prehash:!1},z={lowS:e.lowS,prehash:!1};function Y(R,D,j=te){let{seed:k,k2sig:C}=L(R,D,j),I=e;return Fg(I.hash.outputLen,I.nByteLength,I.hmac)(k,C)}c.BASE._setWindowSize(8);function le(R,D,j,k=z){let C=R;D=Le("msgHash",D),j=Le("publicKey",j);let{lowS:I,prehash:U,format:q}=k;if(B0(k),"strict"in k)throw new Error("options.strict was renamed to lowS");if(q!==void 0&&q!=="compact"&&q!=="der")throw new Error("format must be compact or der");let P=typeof C=="string"||Po(C),ie=!P&&!q&&typeof C=="object"&&C!==null&&typeof C.r=="bigint"&&typeof C.s=="bigint";if(!P&&!ie)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let ue,Q;try{if(ie&&(ue=new m(C.r,C.s)),P){try{q!=="compact"&&(ue=m.fromDER(C))}catch(Gt){if(!(Gt instanceof un.Err))throw Gt}!ue&&q!=="der"&&(ue=m.fromCompact(C))}Q=c.fromHex(j)}catch{return!1}if(!ue||I&&ue.hasHighS())return!1;U&&(D=e.hash(D));let{r:ye,s:Te}=ue,Ee=H(D),Re=a(Te),je=s(Ee*Re),Ye=s(ye*Re),$e=c.BASE.multiplyAndAddUnsafe(Q,je,Ye)?.toAffine();return $e?s($e.x)===ye:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:N,sign:Y,verify:le,ProjectivePoint:c,Signature:m,utils:S}}function ZE(r){return{hash:r,hmac:(e,...t)=>Qi(r,e,Yp(...t)),randomBytes:fa}}function N0(r,e){let t=n=>P0({...r,...ZE(n)});return{...t(e),create:t}}var L0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),O0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),JE=BigInt(1),Xh=BigInt(2),R0=(r,e)=>(r+e/Xh)/e;function QE(r){let e=L0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,h=u*u*r%e,p=Ke(h,t,e)*h%e,y=Ke(p,t,e)*h%e,w=Ke(y,Xh,e)*u%e,b=Ke(w,o,e)*w%e,g=Ke(b,i,e)*b%e,m=Ke(g,a,e)*g%e,S=Ke(m,c,e)*m%e,T=Ke(S,a,e)*g%e,v=Ke(T,t,e)*h%e,N=Ke(v,s,e)*b%e,W=Ke(N,n,e)*u%e,H=Ke(W,Xh,e);if(!Yh.eql(Yh.sqr(H),r))throw new Error("Cannot find square root");return H}var Yh=Gn(L0,void 0,void 0,{sqrt:QE}),nr=N0({a:BigInt(0),b:BigInt(7),Fp:Yh,n:O0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=O0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-JE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=R0(i*r,e),c=R0(-n*r,e),u=_e(r-a*t-c*o,e),h=_e(-a*n-c*i,e),p=u>s,y=h>s;if(p&&(u=e-u),y&&(h=e-h),u>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:u,k2neg:y,k2:h}}}},vr),Bk=BigInt(0);var kk=nr.ProjectivePoint;function Zh(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function D0(r,e){let t=tr.digest(e instanceof Uint8Array?e:e.subarray());if(Zh(t))return t.then(({digest:n})=>nr.sign(n,r).toDERRawBytes()).catch(n=>{throw new Aa(String(n))});try{return nr.sign(t.digest,r).toDERRawBytes()}catch(n){throw new Aa(String(n))}}function U0(r,e,t){let n=tr.digest(t instanceof Uint8Array?t:t.subarray());if(Zh(n))return n.then(({digest:o})=>nr.verify(e,o,r)).catch(o=>{throw new Sa(String(o))});try{return nr.verify(e,n.digest,r)}catch(o){throw new Sa(String(o))}}var Ca=class{type="secp256k1";raw;_key;constructor(e){this._key=K0(e),this.raw=j0(this._key)}toMultihash(){return wr.digest(jn(this))}toCID(){return Qe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}verify(e,t){return U0(this._key,t,e)}},Xl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=M0(e),this.publicKey=new Ca(t??H0(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:qe(this.raw,e.raw)}sign(e){return D0(this.raw,e)}};function Jh(r){return new Ca(r)}async function V0(){let r=e2();return new Xl(r)}function j0(r){return nr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function M0(r){try{return nr.getPublicKey(r,!0),r}catch(e){throw new ra(String(e))}}function K0(r){try{return nr.ProjectivePoint.fromHex(r),r}catch(e){throw new Ki(String(e))}}function H0(r){try{return nr.getPublicKey(r,!0)}catch(e){throw new ra(String(e))}}function e2(){return nr.utils.randomPrivateKey()}async function $0(r,e){if(r==="Ed25519")return p0();if(r==="secp256k1")return V0();if(r==="RSA")return Gh(t2(e));if(r==="ECDSA")return Og(r2(e));throw new Rn}function Ia(r,e){let{Type:t,Data:n}=Kr.decode(r),o=n??new Uint8Array;switch(t){case tt.RSA:return Fh(o,e);case tt.Ed25519:return wh(o);case tt.secp256k1:return Jh(o);case tt.ECDSA:return Xp(o);default:throw new Rn}}function F0(r){let{Type:e,Data:t}=Kr.decode(r.digest),n=t??new Uint8Array;switch(e){case tt.Ed25519:return wh(n);case tt.secp256k1:return Jh(n);case tt.ECDSA:return Xp(n);default:throw new Rn}}function jn(r){return Kr.encode({Type:tt[r.type],Data:r.raw})}function t2(r){return r==null?2048:parseInt(r,10)}function r2(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function Yl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var W0=Symbol.for("nodejs.util.inspect.custom"),n2=114,Ta=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ap]=!0;toString(){return this.string==null&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Qe.createV1(n2,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return qe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return qe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[W0](){return`PeerId(${this.toString()})`}},Ba=class extends Ta{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},ka=class extends Ta{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Pa=class extends Ta{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},o2=2336,Na=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=wr.digest(de(this.url))}[W0](){return`PeerId(${this.url})`}[Ap]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Qe.createV1(o2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ce(e)),e.toString()===this.toString())}};var i2=114,q0=2336;function es(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Un(Pe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return s2(Qe.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Un(e.decode(r))}return G0(t)}function Qh(r){if(r.type==="Ed25519")return new ka({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Pa({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Ba({multihash:r.toCID().multihash,publicKey:r});throw new Rn}function G0(r){if(c2(r))return new Ba({multihash:r});if(a2(r))try{let e=F0(r);if(e.type==="Ed25519")return new ka({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Pa({multihash:r,publicKey:e})}catch{let t=ce(r.digest);return new Na(new URL(t))}throw new Sl("Supplied PeerID Multihash is invalid")}function s2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==i2&&r.code!==q0)throw new Al("Supplied PeerID CID is invalid");if(r.code===q0){let e=ce(r.multihash.digest);return new Na(new URL(e))}return G0(r.multihash)}function a2(r){return r.code===wr.code}function c2(r){return r.code===tr.code}var Zl=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let y=Number.parseInt(p,e);if(!Number.isNaN(y))return y});if(h===void 0)break;if(i*=e,i+=h,i>u||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var z0=45,l2=15,ts=new Zl;function ed(r){if(!(r.length>l2))return ts.new(r).parseWith(()=>ts.readIPv4Addr())}function td(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>z0))return ts.new(r).parseWith(()=>ts.readIPv6Addr())}function Jl(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>z0)return;let t=ts.new(r).parseWith(()=>ts.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var L5=parseInt("0xFFFF",16),D5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ql(r){return!!ed(r)}function eu(r){return!!td(r)}function tu(r){return!!Jl(r)}var Z0=Ql,d2=eu,rd=function(r){let e=0;if(r=r.toString().trim(),Z0(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(d2(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Z0(t[n]),s;i&&(s=rd(t[n]),t[n]=ce(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ce(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},J0=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var rs={},nd={},y2=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];y2.forEach(r=>{let e=g2(...r);nd[e.code]=e,rs[e.name]=e});function g2(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Oe(r){if(typeof r=="number"){if(nd[r]!=null)return nd[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(rs[r]!=null)return rs[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var x4=Oe("ip4"),b4=Oe("ip6"),v4=Oe("ipcidr");function ad(r,e){switch(Oe(r).code){case 4:case 41:return x2(e);case 42:return sd(e);case 43:return ce(e,"base10");case 6:case 273:case 33:case 132:return tw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sd(e);case 421:return S2(e);case 444:return ew(e);case 445:return ew(e);case 466:return A2(e);case 481:return globalThis.encodeURIComponent(sd(e));default:return ce(e,"base16")}}function cd(r,e){switch(Oe(r).code){case 4:return Q0(e);case 41:return Q0(e);case 42:return id(e);case 43:return de(e,"base10");case 6:case 273:case 33:case 132:return ld(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return id(e);case 421:return b2(e);case 444:return E2(e);case 445:return _2(e);case 466:return v2(e);case 481:return id(globalThis.decodeURIComponent(e));default:return de(e,"base16")}}var od=Object.values(To).map(r=>r.decoder),w2=function(){let r=od[0].or(od[1]);return od.slice(2).forEach(e=>r=r.or(e)),r}();function Q0(r){if(!tu(r))throw new Error("invalid ip address");return rd(r)}function x2(r){let e=J0(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!tu(e))throw new Error("invalid ip address");return e}function ld(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function tw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function id(r){let e=de(r),t=Uint8Array.from(rr(e.length));return st([t,e],t.length+e.length)}function sd(r){let e=zt(r);if(r=r.slice(Be(e)),r.length!==e)throw new Error("inconsistent lengths");return ce(r)}function b2(r){let e;r[0]==="Q"||r[0]==="1"?e=Un(Pe.decode(`z${r}`)).bytes:e=Qe.parse(r).multihash.bytes;let t=Uint8Array.from(rr(e.length));return st([t,e],t.length+e.length)}function v2(r){let e=w2.decode(r),t=Uint8Array.from(rr(e.length));return st([t,e],t.length+e.length)}function A2(r){let e=zt(r),t=r.slice(Be(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ce(t,"base64url")}function S2(r){let e=zt(r),t=r.slice(Be(e));if(t.length!==e)throw new Error("inconsistent lengths");return ce(t,"base58btc")}function E2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=sn.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return st([t,o],t.length+o.length)}function _2(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=sn.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return st([t,o],t.length+o.length)}function ew(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ce(e,"base32"),o=tw(t);return`${n}:${o}`}function rw(r){r=ud(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Oe(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new ru("invalid address: "+r);if(a.path===!0){n=ud(o.slice(i).join("/")),e.push([a.code,cd(a.code,n)]),t.push([a.code,n]);break}let c=cd(a.code,o[i]);e.push([a.code,c]),t.push([a.code,ad(a.code,c)])}return{string:nw(t),bytes:nu(e),tuples:e,stringTuples:t,path:n}}function fd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=zt(r,o),s=Be(i),a=Oe(i),c=C2(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let u=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new ru("Invalid address Uint8Array: "+ce(r,"base16"));e.push([i,u]);let h=ad(i,u);if(t.push([i,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:nw(t),tuples:e,stringTuples:t,path:n}}function nw(r){let e=[];return r.map(t=>{let n=Oe(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ud(e.join("/"))}function nu(r){return st(r.map(e=>{let t=Oe(e[0]),n=Uint8Array.from(rr(t.code));return e.length>1&&e[1]!=null&&(n=st([n,e[1]])),n}))}function C2(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=zt(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Be(t)}}function ud(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var ru=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var I2=Symbol.for("nodejs.util.inspect.custom"),hd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),T2=[Oe("dns").code,Oe("dns4").code,Oe("dns6").code,Oe("dnsaddr").code],pd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},ou=class r{bytes;#e;#t;#r;#n;[hd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=fd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=rw(e)}else if(iw(e))t=fd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=Oe("tcp"),a=Oe("udp"),c=Oe("ip4"),u=Oe("ip6"),h=Oe("dns6"),p=Oe("ip6zone");for(let[w,b]of this.stringTuples())w===p.code&&(i=`%${b??""}`),T2.includes(w)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${i}`,e=w===h.code?6:4),(w===s.code||w===a.code)&&(t=Oe(w).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(w===c.code||w===u.code)&&(t=Oe(w).name==="tcp"?"tcp":"udp",n=`${b??""}${i}`,e=w===u.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},Oe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Oe(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(nu(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===rs.p2p.code&&e.push([n,o]),n===rs["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ce(Pe.decode(`z${n}`),"base58btc"):ce(Qe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return qe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=ow.get(t.name);if(n==null)throw new pd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Hr(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[I2](){return`Multiaddr(${this.#e})`}};var ow=new Map;function iw(r){return!!r?.[hd]}function Hr(r){return new ou(r)}var B2=r=>r.toString().split("/").slice(1),ns=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),be=r=>({match:e=>ns(t=>t===r).match(e),pattern:r}),Mo=()=>({match:r=>ns(e=>typeof e=="string").match(r),pattern:"{string}"}),Oa=()=>({match:r=>ns(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),ke=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ra=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Io.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ce=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ct=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),Ae=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function De(...r){function e(o){let i=B2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var k2=ke(),J4=De(k2),su=Ae(be("dns4"),Mo()),au=Ae(be("dns6"),Mo()),cu=Ae(be("dnsaddr"),Mo()),md=Ae(be("dns"),Mo()),Q4=De(su,Ce(ke())),e6=De(au,Ce(ke())),t6=De(cu,Ce(ke())),r6=De(Ct(md,cu,su,au),Ce(ke())),sw=Ae(be("ip4"),ns(Ql)),aw=Ae(be("ip6"),ns(eu)),yd=Ct(sw,aw),pn=Ct(yd,md,su,au,cu),n6=De(Ct(yd,Ae(Ct(md,cu,su,au),Ce(ke())))),o6=De(sw),i6=De(aw),s6=De(yd),gd=Ae(pn,be("tcp"),Oa()),La=Ae(pn,be("udp"),Oa()),a6=De(Ae(gd,Ce(ke()))),c6=De(La),wd=Ae(La,be("quic"),Ce(ke())),lu=Ae(La,be("quic-v1"),Ce(ke())),P2=Ct(wd,lu),l6=De(wd),u6=De(lu),dd=Ct(pn,gd,La,wd,lu),cw=Ct(Ae(dd,be("ws"),Ce(ke()))),f6=De(cw),lw=Ct(Ae(dd,be("wss"),Ce(ke())),Ae(dd,be("tls"),Ce(Ae(be("sni"),Mo())),be("ws"),Ce(ke()))),p6=De(lw),uw=Ae(La,be("webrtc-direct"),Ce(Ra()),Ce(Ra()),Ce(ke())),fw=De(uw),pw=Ae(lu,be("webtransport"),Ce(Ra()),Ce(Ra()),Ce(ke())),h6=De(pw),iu=Ct(cw,lw,Ae(gd,Ce(ke())),Ae(P2,Ce(ke())),Ae(pn,Ce(ke())),uw,pw,ke()),hw=De(iu),N2=Ae(iu,be("p2p-circuit"),ke()),d6=De(N2),O2=Ct(Ae(iu,be("p2p-circuit"),be("webrtc"),Ce(ke())),Ae(iu,be("webrtc"),Ce(ke())),Ae(be("webrtc"),Ce(ke()))),dw=De(O2),R2=Ct(Ae(pn,be("tcp"),Oa(),be("http"),Ce(ke())),Ae(pn,be("http"),Ce(ke()))),m6=De(R2),L2=Ct(Ae(pn,be("tcp"),Ct(Ae(be("443"),be("http")),Ae(Oa(),be("https"))),Ce(ke())),Ae(pn,be("tls"),be("http"),Ce(ke())),Ae(pn,be("https"),Ce(ke()))),y6=De(L2),D2=Ct(Ae(be("memory"),Mo(),Ce(ke()))),g6=De(D2);var It;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>jo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>_r(o,r.codec()),r.decode=(o,i)=>Er(o,r.codec(),i)})(It||(It={}));var mw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],xd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),yw="libp2p+webrtc+v1/";var gw=466,ww=2*1024*1024,xw=30*1e3,os=16*1024;function U2(r=os){let e=Be(r-Be(r)),t=1+Be(Object.keys(It.Flag).length-1),n=1,o=r-e-t-n,i=Be(o);return e+t+n+i}var bw=U2(),vw=5e3,Aw=5e3,Sw=3e4,bd="/webrtc",Da="/webrtc-signaling/0.0.1",Ew="/libp2p/webrtc-direct/certificate",_w="webrtc-direct-certificate-private-key";var Cw=12096e5,vd=864e5;var Iw=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},j2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var M2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var K2=function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r}();var H2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var V2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var $2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,F2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Tw=3,W2=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",$2]],Bw=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Pw(r){return r?kw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new V2:typeof navigator<"u"?kw(navigator.userAgent):z2()}function q2(r){return r!==""&&W2.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function kw(r){var e=q2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new H2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Tw&&(o=Iw(Iw([],o,!0),X2(Tw-o.length),!0)):o=[];var i=o.join("."),s=G2(r),a=F2.exec(r);return a&&a[1]?new K2(t,i,s,a[1]):new j2(t,i,s)}function G2(r){for(var e=0,t=Bw.length;e<t;e++){var n=Bw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function z2(){var r=typeof process<"u"&&process.version;return r?new M2(process.version.slice(1)):null}function X2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ge(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ad=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Sd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nw=r=>globalThis.DOMException===void 0?new Sd(r):new DOMException(r),Ow=r=>{let e=r.reason===void 0?Nw("This operation was aborted."):r.reason;return e instanceof Error?e:Nw(e)};function Ua(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,u=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:w}=e;w.aborted&&p(Ow(w)),a=()=>{p(Ow(w))},w.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let y=new Ad;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(w){p(w)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(y.message=o??`Promise timed out after ${t} milliseconds`,p(y))},t),(async()=>{try{h(await r)}catch(w){p(w)}})()}).finally(()=>{u.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}var Rw=Pw(),ja=Rw!=null&&Rw.name==="firefox",uu=async function*(){},fu=async r=>{};function Lw(r,e,t=Sw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Ge(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Ua(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Ed(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??mw.map(e=>({urls:[e]})),r}var Dw=(r=32)=>yw+[...Array(r)].map(()=>xd.at(Math.floor(Math.random()*xd.length))).join("");var Ko=class{log;peerConnection;remoteAddr;timeline;metrics;source=uu();sink=fu;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection,o=n.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",n.connectionState,"initial state",o),(n.connectionState==="disconnected"||n.connectionState==="failed"||n.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var pu=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},is=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new pu(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new pu(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var _d=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ss(r={}){return Y2(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Y2(r,e){e=e??{};let t=e.onEnd,n=new is,o,i,s,a=Ge(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((m,S)=>{i=T=>{i=null,n.push(T);try{m(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ge()})}},u=m=>i!=null?i(m):(n.push(m),o),h=m=>(n=new is,i!=null?i({error:m}):(n.push({error:m}),o)),p=m=>{if(s)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},y=m=>s?o:(s=!0,m!=null?h(m):u({done:!0})),w=()=>(n=new is,y(),{done:!0}),b=m=>(y(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:w,throw:b,push:p,end:y,get readableLength(){return n.size},onEmpty:async m=>{let S=m?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let T,v;S!=null&&(T=new Promise((N,W)=>{v=()=>{W(new _d)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,T])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},t==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(m){return g.throw(m),t!=null&&(t(m),t=void 0),{done:!0}},return(){return g.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(m){return g.end(m),t!=null&&(t(m),t=void 0),o},get readableLength(){return g.readableLength},onEmpty:m=>g.onEmpty(m)},o}var hu=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function or(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new hu(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new hu(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}function Uw(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function jw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Mw(r,e){let t=Uw(r).return?.();jw(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var Z2=5e3;function Cd(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var du=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Ge(),this.closed=Ge(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??Z2,this.onEnd=e.onEnd,this.onCloseRead=e?.onCloseRead,this.onCloseWrite=e?.onCloseWrite,this.onReset=e?.onReset,this.onAbort=e?.onAbort,this.source=this.streamSource=ss({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new Eo(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Cd(o)&&await o}let n=()=>{Mw(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new he(o):o;let i=this.sendData(o,t);Cd(i)&&(this.sendingData=Ge(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await or(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await or(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await or(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await or(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Cd(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new vl("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Id(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var mu=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},as=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},yu=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Ma=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gu(r){return r[Symbol.asyncIterator]!=null}function Kw(r,e){if(r.byteLength>e)throw new as("Message length too long")}var xu=r=>{let e=Be(r),t=et(e);return rr(r,t),xu.bytes=e,t};xu.bytes=0;function Ka(r,e){e=e??{};let t=e.lengthEncoder??xu,n=e?.maxDataLength??4194304;function*o(i){Kw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return gu(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ka.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??xu,n=e?.maxDataLength??4194304;return Kw(r,n),new he(t(r.byteLength),r)};var Ho;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Ho||(Ho={}));var Td=r=>{let e=zt(r);return Td.bytes=Be(e),e};Td.bytes=0;function Ha(r,e){let t=new he,n=Ho.LENGTH,o=-1,i=e?.lengthDecoder??Td,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Ho.LENGTH)try{if(o=i(t),o<0)throw new mu("Invalid message length");if(o>a)throw new as("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=Ho.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new yu("Message length length too long");break}throw u}if(n===Ho.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=Ho.LENGTH}}}return gu(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Ma("Unexpected end of input")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Ma("Unexpected end of input")}()}Ha.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return Ha(n,{...e??{},onLength:i=>{t=i}})};var Bd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Va(r,e,t,n){let o=new Bd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",h),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,u)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(y){a(),s(y);return}a(),i(p)},u=p=>{a(),s(p.detail)},h=()=>{a(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,u)})}var kd=class extends du{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await Ua(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=ss(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??xw,this.maxBufferedAmount=e.maxBufferedAmount??ww,this.maxMessageSize=(e.maxMessageSize??os)-bw,this.receiveFinAck=Ge(),this.finAckTimeout=e.closeTimeout??vw,this.openTimeout=e.openTimeout??Aw,this.closeController=new AbortController,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new Eo("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of Ha(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new he(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new Eo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Id([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Va(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Id([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Va(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new _l(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=It.encode({message:o}),s=Ka.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(It.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(It.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await or(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(It.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=It.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===It.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(It.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===It.Flag.RESET&&this.reset(),t.flag===It.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===It.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=It.encode({flag:e}),n=Ka.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function cs(r){let{channel:e,direction:t,handshake:n}=r;return new kd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var Yn=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??bd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=cs({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Pd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Pd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??bd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=cs({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),Lw(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=uu();sink=fu;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=cs({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var bu=globalThis.RTCPeerConnection,vu=globalThis.RTCSessionDescription,Hw=globalThis.RTCIceCandidate;var Nd=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ge(),this.haveNext=Ge()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ge(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ge(),await or(this.readNext.promise,t?.signal,t)}};function Au(){return new Nd}var Su=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Vw(r,e){let t=Au();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new he;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:u}=await or(n.next(),s?.signal);return c===!0?null:u}for(;o.byteLength<s.bytes;){let{value:c,done:u}=await or(n.next(),s?.signal);if(u===!0)throw new Su("unexpected end of input");o.append(c)}let a=o.sublist(0,s.bytes);return o.consume(s.bytes),a},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Eu=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},_u=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Cu=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $a(r,e={}){let t=Vw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Be(e.maxDataLength));let n=e?.lengthDecoder??zt,o=e?.lengthEncoder??rr;return{read:async s=>{let a=-1,c=new he;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Eu("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Cu("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new _u("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new he(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new he(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Iu(r,e){let t=$a(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Yt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Zn=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ir=class extends Zn{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Tu=class extends Zn{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Bu=class extends Zn{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},ku=class extends Zn{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Rt;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>jo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>_r(o,r.codec()),r.decode=(o,i)=>Er(o,r.codec(),i)})(Rt||(Rt={}));var Pu=async(r,e,t)=>{try{let n=Ge();for(e_(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Rt.Type.ICE_CANDIDATE)throw new El("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Yt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Hw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Yt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Nu(r)!=="connected")throw n}};function Nu(r){return ja?r.iceConnectionState:r.connectionState}function e_(r,e){r[ja?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Nu(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new bl("RTCPeerConnection was closed"));break;default:break}}}async function $w({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:u}){let{baseAddr:h}=Fw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",h);let p=h.getPeerId();if(p==null)throw new ve("Relay peer was missing");let y=i.getConnections(es(p)),w,b=!1;y.length===0?(u?.(new Yt("webrtc:dial-relay")),w=await s.dial(h,{signal:t,onProgress:u}),b=!0):(u?.(new Yt("webrtc:reuse-relay-connection")),w=y[0]);try{u?.(new Yt("webrtc:open-signaling-stream"));let g=await w.newStream(Da,{signal:t,runOnLimitedConnection:!0}),m=Iu(g).pb(Rt),S=new bu(r),T=new Yn({logger:c},{peerConnection:S,dataChannelOptions:e});try{let v=S.createDataChannel("init");S.onicecandidate=({candidate:O})=>{let K=JSON.stringify(O?.toJSON()??null);a.trace("initiator sending ICE candidate %o",O),m.write({type:Rt.Type.ICE_CANDIDATE,data:K},{signal:t}).catch(L=>{a.error("error sending ICE candidate",L)})},S.onicecandidateerror=O=>{a.error("initiator ICE candidate error",O)};let N=await S.createOffer().catch(O=>{throw a.error("could not execute createOffer",O),new ir("Failed to set createOffer")});a.trace("initiator send SDP offer %s",N.sdp),u?.(new Yt("webrtc:send-sdp-offer")),await m.write({type:Rt.Type.SDP_OFFER,data:N.sdp},{signal:t}),await S.setLocalDescription(N).catch(O=>{throw a.error("could not execute setLocalDescription",O),new ir("Failed to set localDescription")}),u?.(new Yt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let W=await m.read({signal:t});if(W.type!==Rt.Type.SDP_ANSWER)throw new ir("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",W.data);let H=new vu({type:"answer",sdp:W.data});return await S.setRemoteDescription(H).catch(O=>{throw a.error("could not execute setRemoteDescription",O),new ir("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),u?.(new Yt("webrtc:read-ice-candidates")),await Pu(S,m,{direction:"initiator",signal:t,log:a,onProgress:u}),a.trace("initiator connected, closing init channel"),v.close(),u?.(new Yt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await g.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:S,muxerFactory:T}}catch(v){throw a.error("outgoing signaling error",v),S.close(),g.abort(v),v}finally{S.onicecandidate=null,S.onicecandidateerror=null}}finally{if(b)try{await w.close({signal:t})}catch(g){w.abort(g)}}}var Ww=De(hw.matchers[0],be("p2p-circuit")),Ou=class r extends Ln{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Ww.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Ww.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function qw({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Iu(e).pb(Rt);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Rt.Type.ICE_CANDIDATE,data:p},{signal:t}).catch(y=>{o.error("error sending ICE candidate",y)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Rt.Type.SDP_OFFER)throw new ir(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new vu({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new ir("Failed to set remoteDescription")});let u=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new ir("Failed to create answer")});o.trace("recipient send SDP answer %s",u.sdp),await i.write({type:Rt.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(h=>{throw o.error("could not execute setLocalDescription",h),new ir("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Pu(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Nu(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=Hr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Ru=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,this.shutdownController.signal,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[gl]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Hi]=["@libp2p/transport"];[rg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Da,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Da),this._started=!1}createListener(e){return new Ou(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(dw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await $w({rtcConfiguration:await Ed(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new Ko(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new bu(await Ed(this.init.rtcConfiguration)),i=new Yn(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await qw({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Ko(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Fw(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new ve("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new ve("p2p-circuit protocol was not present in multiaddr");let t=Hr(e[0]),o=Hr("/"+e[1]).getPeerId();if(o==null)throw new ve("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new ve("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:es(o)}}var LG=Dr(zw());var Wr={};vt(Wr,{Any:()=>$r,BaseBlock:()=>rt,BaseStringBlock:()=>Ga,BitString:()=>Br,BmpString:()=>qo,Boolean:()=>$o,CharacterString:()=>ti,Choice:()=>fs,Constructed:()=>ct,DATE:()=>Qa,DateTime:()=>tc,Duration:()=>rc,EndOfContent:()=>za,Enumerated:()=>Fo,GeneralString:()=>ei,GeneralizedTime:()=>ri,GraphicString:()=>Qo,HexBlock:()=>Fr,IA5String:()=>Jo,Integer:()=>gn,Null:()=>Ir,NumericString:()=>zo,ObjectIdentifier:()=>Wo,OctetString:()=>Tr,Primitive:()=>yn,PrintableString:()=>Xo,RawData:()=>Dd,RelativeObjectIdentifier:()=>Ja,Repeated:()=>ni,Sequence:()=>Ut,Set:()=>jt,TIME:()=>nc,TeletexString:()=>Yo,TimeOfDay:()=>ec,UTCTime:()=>to,UniversalString:()=>Go,Utf8String:()=>ar,ValueBlock:()=>ft,VideotexString:()=>Zo,ViewWriter:()=>us,VisibleString:()=>eo,compareSchema:()=>Qn,fromBER:()=>xn,verifySchema:()=>v_});var me=Dr(dn());function Vo(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Jn(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let u=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);u[i-h-1]=Math.floor(o/p),o-=u[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Uu(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Rd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Vo(t,8),o=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(o);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,Vo(i,8)-n}function Xw(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=Jn(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=Jn(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Yw(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Lt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var qN=Math.log(2);function ju(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ud(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function wn(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var us=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ud(this.items)}},Fa=[new Uint8Array([1])],Zw="0123456789",Ld="name",Jw="valueHexView",l_="isHexOnly",u_="idBlock",f_="tagClass",p_="tagNumber",h_="isConstructed",d_="fromBER",m_="toBER",y_="local",Dt="",kr=new ArrayBuffer(0),Qu=new Uint8Array(0),qa="EndOfContent",ex="OCTET STRING",tx="BIT STRING";function Fr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?me.BufferSourceConverter.toUint8Array(i.valueHex):Qu}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!wn(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",kr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:me.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var mn=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=Dt,warnings:n=[],valueBeforeDecode:o=Qu}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=me.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:me.Convert.ToHex(this.valueBeforeDecodeView)}}};mn.NAME="baseBlock";var ft=class extends mn{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ft.NAME="valueBlock";var Mu=class extends Fr(mn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?me.BufferSourceConverter.toUint8Array(e.valueHex):Qu,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",kr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=Jn(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(u[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let y=new Uint8Array(h);for(let w=0;w<u.length;w++)y[w]=u[w];u=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,u[c-1]=i[c]&127;let p=new Uint8Array(c);for(let y=0;y<c;y++)p[y]=u[y];u=this.valueHexView=new Uint8Array(c),u.set(p),this.blockLength<=9?this.tagNumber=Vo(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};Mu.NAME="identificationBlock";var Ku=class extends mn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Vo(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=Jn(this.length,8);if(o.byteLength>127)return this.error="Too big length",kr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Ku.NAME="lengthBlock";var X={},rt=class extends mn{constructor({name:e=Dt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Mu(o),this.lenBlock=new Ku(o),this.valueBlock=i?new i(o):new ft(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new us;t||rx(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?kr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():me.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Yw(t,n)}};rt.NAME="BaseBlock";function rx(r){var e;if(r instanceof X.Constructed)for(let t of r.valueBlock.value)rx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var Ga=class extends rt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Dt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Ga.NAME="BaseStringBlock";var Hu=class extends Fr(ft){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Hu.NAME="PrimitiveValueBlock";var nx,yn=class extends rt{constructor(e={}){super(e,Hu),this.idBlock.isConstructed=!1}};nx=yn;X.Primitive=nx;yn.NAME="PRIMITIVE";function g_(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ps(r,e=0,t=r.length){let n=e,o=new rt({},ft),i=new mn;if(!wn(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=rt;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=X.EndOfContent;break;case 1:c=X.Boolean;break;case 2:c=X.Integer;break;case 3:c=X.BitString;break;case 4:c=X.OctetString;break;case 5:c=X.Null;break;case 6:c=X.ObjectIdentifier;break;case 10:c=X.Enumerated;break;case 12:c=X.Utf8String;break;case 13:c=X.RelativeObjectIdentifier;break;case 14:c=X.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=X.Sequence;break;case 17:c=X.Set;break;case 18:c=X.NumericString;break;case 19:c=X.PrintableString;break;case 20:c=X.TeletexString;break;case 21:c=X.VideotexString;break;case 22:c=X.IA5String;break;case 23:c=X.UTCTime;break;case 24:c=X.GeneralizedTime;break;case 25:c=X.GraphicString;break;case 26:c=X.VisibleString;break;case 27:c=X.GeneralString;break;case 28:c=X.UniversalString;break;case 29:c=X.CharacterString;break;case 30:c=X.BmpString;break;case 31:c=X.DATE;break;case 32:c=X.TimeOfDay;break;case 33:c=X.DateTime;break;case 34:c=X.Duration;break;default:{let u=o.idBlock.isConstructed?new X.Constructed:new X.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?X.Constructed:X.Primitive}return o=g_(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function xn(r){if(!r.byteLength){let e=new rt({},ft);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ps(me.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function w_(r,e){return r?1:e}var Vr=class extends ft{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;w_(this.isIndefiniteForm,n)>0;){let s=ps(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===qa)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===qa?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new us;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?kr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Vr.NAME="ConstructedValueBlock";var ox,ct=class extends rt{constructor(e={}){super(e,Vr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
3
3
  `).map(o=>` ${o}`).join(`
4
4
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
5
5
  ${e.join(`
6
- `)}`:`${t} :`}};px=ct;X.Constructed=px;ct.NAME="CONSTRUCTED";var Hu=class extends ft{fromBER(e,t,n){return t}toBER(e){return kr}};Hu.override="EndOfContentValueBlock";var hx,Ga=class extends rt{constructor(e={}){super(e,Hu),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};hx=Ga;X.EndOfContent=hx;Ga.NAME=Wa;var dx,Ir=class extends rt{constructor(e={}){super(e,ft),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};dx=Ir;X.Null=dx;Ir.NAME="NULL";var Vu=class extends Fr(ft){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=me.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);return wn(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Ud.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Vu.NAME="BooleanValueBlock";var mx,$o=class extends rt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Vu),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};mx=$o;X.Boolean=mx;$o.NAME="BOOLEAN";var $u=class extends Fr(Vr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=Vr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===Wa){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==cx)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?Vr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};$u.NAME="OctetStringValueBlock";var Hd,Tr=class extends rt{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},$u),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=ps(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ct.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof Hd&&e.push(t.valueBlock.valueHexView);return me.BufferSourceConverter.concat(e)}};Hd=Tr;X.OctetString=Hd;Tr.NAME=cx;var Fu=class extends Fr(Vr){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=Vr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Wa){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==lx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let i=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=ps(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return Vr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return kr;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Fu.NAME="BitStringValueBlock";var yx,Br=class extends rt{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Fu),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ct.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join(""),o=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${o} : ${i}`}}};yx=Br;X.BitString=yx;Br.NAME=lx;var gx;function B_(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u=0,h=c<s?s:c,p=0;for(let m=h;m>=0;m--,p++){switch(!0){case p<a.length:u=i[s-p]+a[c-p]+t[0];break;default:u=i[s-p]+t[0]}switch(t[0]=u/10,!0){case p>=i.length:i=Du(new Uint8Array([u%10]),i);break;default:i[s-p]=u%10}}return t[0]>0&&(i=Du(t,i)),i}function ax(r){if(r>=$a.length)for(let e=$a.length;e<=r;e++){let t=new Uint8Array([0]),n=$a[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=Du(t,n)),$a.push(n)}return $a[r]}function k_(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u,h=0;for(let p=c;p>=0;p--,h++)switch(u=i[s-h]-a[c-h]-t,!0){case u<0:t=1,i[s-h]=u+10;break;default:t=0,i[s-h]=u}if(t>0)for(let p=s-c+1;p>=0;p--,h++)if(u=i[s-h]-t,u<0)t=1,i[s-h]=u+10;else{t=0,i[s-h]=u;break}return i.slice()}var za=class extends Fr(ft){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Ud.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(nx(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=k_(ax(n),t),s="-";break;default:t=B_(t,ax(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=ix.charAt(t[c]));return a===!1&&(s+=ix.charAt(0)),s}};gx=za;za.NAME="IntegerValueBlock";Object.defineProperty(gx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Fa,gn=class extends rt{constructor(e={}){super(e,za),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Uu(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Uu();let t=BigInt(e),n=new us,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(me.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${me.Convert.ToHex(a)}`)+t,h=me.BufferSourceConverter.toUint8Array(me.Convert.FromHex(u.toString(16)));h[0]|=128,n.write(h)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new Fa({valueHex:n.final()})}convertToDER(){let e=new Fa({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Fa({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Fa=gn;X.Integer=Fa;gn.NAME="INTEGER";var wx,Fo=class extends gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};wx=Fo;X.Enumerated=wx;Fo.NAME="ENUMERATED";var Xa=class extends Fr(ft){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Vo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Uu();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Qn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=me.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Xa.NAME="sidBlock";var Wu=class extends ft{constructor({value:e=Mt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Xa;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,kr;t.push(o)}return Kd(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new Xa;if(o>Number.MAX_SAFE_INTEGER){Uu();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Wu.NAME="ObjectIdentifierValueBlock";var xx,Wo=class extends rt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Wu),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};xx=Wo;X.ObjectIdentifier=xx;Wo.NAME="OBJECT IDENTIFIER";var Ya=class extends Fr(mn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Vo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Qn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=me.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Ya.NAME="relativeSidBlock";var qu=class extends ft{constructor({value:e=Mt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Ya;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,kr;n.push(i)}return Kd(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new Ya;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};qu.NAME="RelativeObjectIdentifierValueBlock";var bx,Za=class extends rt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,qu),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};bx=Za;X.RelativeObjectIdentifier=bx;Za.NAME="RelativeObjectIdentifier";var vx,Kt=class extends ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};vx=Kt;X.Sequence=vx;Kt.NAME="SEQUENCE";var Ax,Ht=class extends ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ax=Ht;X.Set=Ax;Ht.NAME="SET";var Gu=class extends Fr(ft){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Mt}toJSON(){return{...super.toJSON(),value:this.value}}};Gu.NAME="StringValueBlock";var zu=class extends Gu{};zu.NAME="SimpleStringValueBlock";var Pt=class extends qa{constructor({...e}={}){super(e,zu)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Pt.NAME="SIMPLE STRING";var Xu=class extends Pt{fromBuffer(e){this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=me.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=me.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Xu.NAME="Utf8StringValueBlock";var Sx,ar=class extends Xu{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Sx=ar;X.Utf8String=Sx;ar.NAME="UTF8String";var Yu=class extends Pt{fromBuffer(e){this.valueBlock.value=me.Convert.ToUtf16String(e),this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf16String(e))}};Yu.NAME="BmpStringValueBlock";var Ex,qo=class extends Yu{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Ex=qo;X.BmpString=Ex;qo.NAME="BMPString";var Zu=class extends Pt{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Qn(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};Zu.NAME="UniversalStringValueBlock";var _x,Go=class extends Zu{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};_x=Go;X.UniversalString=_x;Go.NAME="UniversalString";var Cx,zo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Cx=zo;X.NumericString=Cx;zo.NAME="NumericString";var Ix,Xo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ix=Xo;X.PrintableString=Ix;Xo.NAME="PrintableString";var Tx,Yo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Tx=Yo;X.TeletexString=Tx;Yo.NAME="TeletexString";var Bx,Zo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Bx=Zo;X.VideotexString=Bx;Zo.NAME="VideotexString";var kx,Jo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};kx=Jo;X.IA5String=kx;Jo.NAME="IA5String";var Nx,Qo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Nx=Qo;X.GraphicString=Nx;Qo.NAME="GraphicString";var Px,to=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Px=to;X.VisibleString=Px;to.NAME="VisibleString";var Ox,ei=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Ox=ei;X.GeneralString=Ox;ei.NAME="GeneralString";var Rx,ti=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Rx=ti;X.CharacterString=Rx;ti.NAME="CharacterString";var Lx,ro=class extends to{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=jt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=jt(this.month,2),t[2]=jt(this.day,2),t[3]=jt(this.hour,2),t[4]=jt(this.minute,2),t[5]=jt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Lx=ro;X.UTCTime=Lx;ro.NAME="UTCTime";var Dx,ri=class extends ro{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let p=new Number(e[e.length-1]);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let p=1,m=n.indexOf("+"),w="";if(m===-1&&(m=n.indexOf("-"),p=-1),m!==-1){if(w=n.substring(m+1),n=n.substring(0,m),w.length!==2&&w.length!==4)throw new Error("Wrong input string for conversion");let b=parseInt(w.substring(0,2),10);if(isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*b,w.length===4){if(b=parseInt(w.substring(2,4),10),isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");c=p*b}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let p=new Number(`0${n.substring(u)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=60*i;this.minute=Math.floor(p),p=60*(p-this.minute),this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=60*i;this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let h=s.exec(o);if(h===null)throw new Error("Wrong input string for conversion");for(let p=1;p<h.length;p++)switch(p){case 1:this.year=parseInt(h[p],10);break;case 2:this.month=parseInt(h[p],10);break;case 3:this.day=parseInt(h[p],10);break;case 4:this.hour=parseInt(h[p],10)+a;break;case 5:this.minute=parseInt(h[p],10)+c;break;case 6:this.second=parseInt(h[p],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let p=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=p.getUTCFullYear(),this.month=p.getUTCMonth(),this.day=p.getUTCDay(),this.hour=p.getUTCHours(),this.minute=p.getUTCMinutes(),this.second=p.getUTCSeconds(),this.millisecond=p.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(jt(this.year,4)),t.push(jt(this.month,2)),t.push(jt(this.day,2)),t.push(jt(this.hour,2)),t.push(jt(this.minute,2)),t.push(jt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(jt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Dx=ri;X.GeneralizedTime=Dx;ri.NAME="GeneralizedTime";var Ux,Ja=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Ux=Ja;X.DATE=Ux;Ja.NAME="DATE";var jx,Qa=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};jx=Qa;X.TimeOfDay=jx;Qa.NAME="TimeOfDay";var Mx,ec=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Mx=ec;X.DateTime=Mx;ec.NAME="DateTime";var Kx,tc=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Kx=tc;X.Duration=Kx;tc.NAME="Duration";var Hx,rc=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Hx=rc;X.TIME=Hx;rc.NAME="TIME";var $r=class{constructor({name:e=Mt,optional:t=!1}={}){this.name=e,this.optional=t}},fs=class extends $r{constructor({value:e=[],...t}={}){super(t),this.value=e}},ni=class extends $r{constructor({value:e=new $r,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Md=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=me.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Ju}={}){this.dataView=me.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=me.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function eo(r,e,t){if(t instanceof fs){for(let i of t.value)if(eo(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(jd)&&(i.name=t.name),i}}if(t instanceof $r)return t.hasOwnProperty(jd)&&(r[t.name]=e),{verified:!0,result:r};if(!(r instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(b_ in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(E_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(__ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let n=t.idBlock.toBER(!1);if(n.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(t.idBlock.fromBER(n,0,n.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(t.idBlock.hasOwnProperty(v_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(A_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(S_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(x_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:r};if(t.idBlock.isHexOnly){if(!(sx in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let i=t.idBlock.valueHexView,s=e.idBlock.valueHexView;if(i.length!==s.length)return{verified:!1,result:r};for(let a=0;a<i.length;a++)if(i[a]!==s[1])return{verified:!1,result:r}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(r[t.name]=e)),t instanceof X.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof ni&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let u=0;u<t.valueBlock.value.length;u++)c=c&&(t.valueBlock.value[u].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){let u={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(delete r[t.name],u.name=t.name)),u}}else if(t.valueBlock.value[0]instanceof ni){if(s=eo(r,e.valueBlock.value[c],t.valueBlock.value[0].value),s.verified===!1)if(t.valueBlock.value[0].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&delete r[t.name]),s;if(jd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let u={};C_ in t.valueBlock.value[0]&&t.valueBlock.value[0].local?u=e:u=r,typeof u[t.valueBlock.value[0].name]>"u"&&(u[t.valueBlock.value[0].name]=[]),u[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=eo(r,e.valueBlock.value[c-i],t.valueBlock.value[c]),s.verified===!1)if(t.valueBlock.value[c].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&delete r[t.name]),s;if(s.verified===!1){let c={verified:!1,result:r};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&sx in e.valueBlock){let i=ps(e.valueBlock.valueHexView);if(i.offset===-1){let s={verified:!1,result:i.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(delete r[t.name],s.name=t.name)),s}return eo(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function N_(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=ps(me.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:eo(t.result,t.result,e)}var A;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(A||(A={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var Vd=Dr(dn()),qr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Vd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Vd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Br))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Br({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Br({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var $d=Dr(dn()),oe=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):$d.BufferSourceConverter.isBufferSource(e)?this.buffer=$d.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Tr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Tr({valueHex:this.buffer})}toSchema(e){return new Tr({name:e})}};var P_={fromASN:r=>r instanceof Ir?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Ir;let e=xn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},O_={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new gn({value:+r})},R_={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Fo({value:r})},ge={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new gn({valueHex:r})};var L_={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Br({valueHex:r})},D_={fromASN:r=>r.valueBlock.toString(),toASN:r=>new Wo({value:r})},U_={fromASN:r=>r.valueBlock.value,toASN:r=>new $o({value:r})},hs={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Tr({valueHex:r})},Vx={fromASN:r=>new oe(r.getValue()),toASN:r=>r.toASN()};function cr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Fd=cr(ar),j_=cr(qo),M_=cr(Go),K_=cr(zo),H_=cr(Xo),V_=cr(Yo),$_=cr(Zo),F_=cr(Jo),W_=cr(Qo),q_=cr(to),G_=cr(ei),z_=cr(ti),X_={fromASN:r=>r.toDate(),toASN:r=>new ro({valueDate:r})},Y_={fromASN:r=>r.toDate(),toASN:r=>new ri({valueDate:r})},Z_={fromASN:()=>null,toASN:()=>new Ir};function ds(r){switch(r){case d.Any:return P_;case d.BitString:return L_;case d.BmpString:return j_;case d.Boolean:return U_;case d.CharacterString:return z_;case d.Enumerated:return R_;case d.GeneralString:return G_;case d.GeneralizedTime:return Y_;case d.GraphicString:return W_;case d.IA5String:return F_;case d.Integer:return O_;case d.Null:return Z_;case d.NumericString:return K_;case d.ObjectIdentifier:return D_;case d.OctetString:return hs;case d.PrintableString:return H_;case d.TeletexString:return V_;case d.UTCTime:return X_;case d.UniversalString:return M_;case d.Utf8String:return Fd;case d.VideotexString:return $_;case d.VisibleString:return q_;default:return null}}function lr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:lr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function qd(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:qd(t)}return!1}function $x(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}var Qu=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:A.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let h=d[s.type],p=Wr[h];if(!p)throw new Error(`Cannot get ASN1 class by name '${h}'`);c=new p({name:a})}else lr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===A.Choice?c=new $r({name:a}):(c=this.create(s.type,!1),c.name=a):c=new $r({name:a});let u=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let h=s.repeated==="set"?Ht:Kt;c=new h({name:"",value:[new ni({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||lr(s.type)){let h=s.repeated?ct:yn;o.push(new h({name:a,optional:u,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let h=!!s.repeated,p=h?c:this.get(s.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,o.push(new ct({name:h?"":a,optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new ct({optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=u,o.push(c)}switch(n.type){case A.Sequence:return new Kt({value:o,name:""});case A.Set:return new Ht({value:o,name:""});case A.Choice:return new fs({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var Ot=new Qu;var _=r=>e=>{let t;Ot.has(e)?t=Ot.get(e):(t=Ot.createDefault(e),Ot.set(e,t)),Object.assign(t,r)};var f=r=>(e,t)=>{let n;Ot.has(e.constructor)?n=Ot.get(e.constructor):(n=Ot.createDefault(e.constructor),Ot.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=ds(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}n.items[t]=o};var nc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var oc=class{static parse(e,t){let n=xn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(lr(t))return new t().fromASN(e);let o=Ot.get(t);Ot.cache(t);let i=o.schema;if(e.constructor===ct&&o.type!==A.Choice){i=new ct({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=eo({},e,i);if(!s.verified)throw new nc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(qd(t)){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=o.itemType;if(typeof c=="number"){let u=ds(c);if(!u)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,h=>u.fromASN(h))}else return t.from(e.valueBlock.value,u=>this.fromASN(u,c))}for(let c in o.items){let u=s.result[c];if(!u)continue;let h=o.items[c],p=h.type;if(typeof p=="number"||lr(p)){let m=(n=h.converter)!==null&&n!==void 0?n:lr(p)?new p:null;if(!m)throw new Error("Converter is empty");if(h.repeated)if(h.implicit){let w=h.repeated==="sequence"?Kt:Ht,b=new w;b.valueBlock=u.valueBlock;let g=xn(b.toBER(!1));if(g.offset===-1)throw new Error(`Cannot parse the child item. ${g.result.error}`);if(!("value"in g.result.valueBlock&&Array.isArray(g.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let y=g.result.valueBlock.value;a[c]=Array.from(y,S=>m.fromASN(S))}else a[c]=Array.from(u,w=>m.fromASN(w));else{let w=u;if(h.implicit){let b;if(lr(p))b=new p().toSchema("");else{let g=d[p],y=Wr[g];if(!y)throw new Error(`Cannot get '${g}' class from asn1js module`);b=new y}b.valueBlock=w.valueBlock,w=xn(b.toBER(!1)).result}a[c]=m.fromASN(w)}}else if(h.repeated){if(!Array.isArray(u))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");a[c]=Array.from(u,m=>this.fromASN(m,p))}else a[c]=this.fromASN(u,p)}return a}catch(o){throw o instanceof nc&&o.schemas.push(t.name),o}}};var ic=class r{static serialize(e){return e instanceof rt?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&lr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Ot.get(t);Ot.cache(t);let o=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let s=ds(n.itemType);if(!s)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);o=e.map(a=>s.toASN(a))}else o=e.map(s=>this.toAsnItem({type:n.itemType},"[]",t,s))}else for(let s in n.items){let a=n.items[s],c=e[s];if(c===void 0||a.defaultValue===c||typeof a.defaultValue=="object"&&typeof c=="object"&&$x(this.serialize(a.defaultValue),this.serialize(c)))continue;let u=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||lr(a.type))){let h={};h.valueHex=u instanceof Ir?u.valueBeforeDecodeView:u.valueBlock.toBER(),o.push(new yn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...h}))}else o.push(new ct({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:u.valueBlock.value}));else o.push(new ct({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[u]}));else a.repeated?o=o.concat(u):o.push(u)}let i;switch(n.type){case A.Sequence:i=new Kt({value:o});break;case A.Set:i=new Ht({value:o});break;case A.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,u=>s.toASN(u)),c=e.repeated==="sequence"?Kt:Ht;i=new c({value:a})}else i=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let s=Array.from(o,c=>this.toASN(c)),a=e.repeated==="sequence"?Kt:Ht;i=new a({value:s})}else i=this.toASN(o);return i}};var ne=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var Gd=Dr(dn());var F=class r{static serialize(e){return ic.serialize(e)}static parse(e,t){return oc.parse(e,t)}static toString(e){let t=Gd.BufferSourceConverter.isBufferSource(e)?Gd.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=xn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function l(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Fx=Dr(dn()),sc=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,u)=>c+(u.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(Fx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var Wx=Dr(dn()),zd,Xd,Yd,nt=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};l([f({type:d.TeletexString})],nt.prototype,"teletexString",void 0);l([f({type:d.PrintableString})],nt.prototype,"printableString",void 0);l([f({type:d.UniversalString})],nt.prototype,"universalString",void 0);l([f({type:d.Utf8String})],nt.prototype,"utf8String",void 0);l([f({type:d.BmpString})],nt.prototype,"bmpString",void 0);nt=l([_({type:A.Choice})],nt);var ms=class extends nt{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Wx.Convert.ToHex(this.anyValue):super.toString())}};l([f({type:d.IA5String})],ms.prototype,"ia5String",void 0);l([f({type:d.Any})],ms.prototype,"anyValue",void 0);ms=l([_({type:A.Choice})],ms);var oi=class{constructor(e={}){this.type="",this.value=new ms,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],oi.prototype,"type",void 0);l([f({type:ms})],oi.prototype,"value",void 0);var no=zd=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,zd.prototype)}};no=zd=l([_({type:A.Set,itemType:oi})],no);var Zd=Xd=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Xd.prototype)}};Zd=Xd=l([_({type:A.Sequence,itemType:no})],Zd);var Pe=Yd=class extends Zd{constructor(e){super(e),Object.setPrototypeOf(this,Yd.prototype)}};Pe=Yd=l([_({type:A.Sequence})],Pe);var J_={fromASN:r=>sc.toString(hs.fromASN(r)),toASN:r=>hs.toASN(sc.fromString(r))},oo=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],oo.prototype,"typeId",void 0);l([f({type:d.Any,context:0})],oo.prototype,"value",void 0);var ac=class{constructor(e={}){this.partyName=new nt,Object.assign(this,e)}};l([f({type:nt,optional:!0,context:0,implicit:!0})],ac.prototype,"nameAssigner",void 0);l([f({type:nt,context:1,implicit:!0})],ac.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oo,context:0,implicit:!0})],ae.prototype,"otherName",void 0);l([f({type:d.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);l([f({type:d.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);l([f({type:d.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);l([f({type:Pe,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);l([f({type:ac,context:5})],ae.prototype,"ediPartyName",void 0);l([f({type:d.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);l([f({type:d.OctetString,context:7,implicit:!0,converter:J_})],ae.prototype,"iPAddress",void 0);l([f({type:d.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=l([_({type:A.Choice})],ae);var io="1.3.6.1.5.5.7",so=`${io}.1`,qx=`${io}.2`,ii=`${io}.3`,ef=`${io}.48`,pO=`${qx}.1`,hO=`${qx}.2`,Jd=`${ef}.1`,Qd=`${ef}.2`,em=`${ef}.3`,tm=`${ef}.5`,pe="2.5.29";var rm,tf=`${so}.1`,bn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],bn.prototype,"accessMethod",void 0);l([f({type:ae})],bn.prototype,"accessLocation",void 0);var si=rm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};si=rm=l([_({type:A.Sequence,itemType:bn})],si);var rf=`${pe}.35`,ai=class extends oe{},Gr=class{constructor(e={}){e&&Object.assign(this,e)}};l([f({type:ai,context:0,optional:!0,implicit:!0})],Gr.prototype,"keyIdentifier",void 0);l([f({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Gr.prototype,"authorityCertIssuer",void 0);l([f({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ge})],Gr.prototype,"authorityCertSerialNumber",void 0);var nf=`${pe}.19`,ci=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};l([f({type:d.Boolean,defaultValue:!1})],ci.prototype,"cA",void 0);l([f({type:d.Integer,optional:!0})],ci.prototype,"pathLenConstraint",void 0);var nm,Ve=nm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};Ve=nm=l([_({type:A.Sequence,itemType:ae})],Ve);var om,Q_=`${pe}.29`,Gx=om=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};Gx=om=l([_({type:A.Sequence})],Gx);var im,sf=`${pe}.32`,WO=`${sf}.0`,vn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};l([f({type:d.IA5String})],vn.prototype,"ia5String",void 0);l([f({type:d.VisibleString})],vn.prototype,"visibleString",void 0);l([f({type:d.BmpString})],vn.prototype,"bmpString",void 0);l([f({type:d.Utf8String})],vn.prototype,"utf8String",void 0);vn=l([_({type:A.Choice})],vn);var cc=class{constructor(e={}){this.organization=new vn,this.noticeNumbers=[],Object.assign(this,e)}};l([f({type:vn})],cc.prototype,"organization",void 0);l([f({type:d.Integer,repeated:"sequence"})],cc.prototype,"noticeNumbers",void 0);var lc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:cc,optional:!0})],lc.prototype,"noticeRef",void 0);l([f({type:vn,optional:!0})],lc.prototype,"explicitText",void 0);var of=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.IA5String})],of.prototype,"cPSuri",void 0);l([f({type:lc})],of.prototype,"userNotice",void 0);of=l([_({type:A.Choice})],of);var uc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],uc.prototype,"policyQualifierId",void 0);l([f({type:d.Any})],uc.prototype,"qualifier",void 0);var li=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],li.prototype,"policyIdentifier",void 0);l([f({type:uc,repeated:"sequence",optional:!0})],li.prototype,"policyQualifiers",void 0);var fc=im=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};fc=im=l([_({type:A.Sequence,itemType:li})],fc);var QO=`${pe}.20`,pc=class{constructor(e=0){this.value=e}};l([f({type:d.Integer})],pc.prototype,"value",void 0);pc=l([_({type:A.Choice})],pc);var sR=`${pe}.27`,zx=class extends pc{};zx=l([_({type:A.Choice})],zx);var sm,af=`${pe}.31`,Nr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Nr||(Nr={}));var hc=class extends qr{toJSON(){let e=[],t=this.toNumber();return t&Nr.aACompromise&&e.push("aACompromise"),t&Nr.affiliationChanged&&e.push("affiliationChanged"),t&Nr.cACompromise&&e.push("cACompromise"),t&Nr.certificateHold&&e.push("certificateHold"),t&Nr.cessationOfOperation&&e.push("cessationOfOperation"),t&Nr.keyCompromise&&e.push("keyCompromise"),t&Nr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Nr.superseded&&e.push("superseded"),t&Nr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},An=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,context:0,repeated:"sequence",implicit:!0})],An.prototype,"fullName",void 0);l([f({type:no,context:1,implicit:!0})],An.prototype,"nameRelativeToCRLIssuer",void 0);An=l([_({type:A.Choice})],An);var zr=class{constructor(e={}){Object.assign(this,e)}};l([f({type:An,context:0,optional:!0})],zr.prototype,"distributionPoint",void 0);l([f({type:hc,context:1,optional:!0,implicit:!0})],zr.prototype,"reasons",void 0);l([f({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],zr.prototype,"cRLIssuer",void 0);var ao=sm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,sm.prototype)}};ao=sm=l([_({type:A.Sequence,itemType:zr})],ao);var am,vR=`${pe}.46`,Xx=am=class extends ao{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};Xx=am=l([_({type:A.Sequence,itemType:zr})],Xx);var BR=`${pe}.28`,Qt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Qt.ONLY=!1;l([f({type:An,context:0,optional:!0})],Qt.prototype,"distributionPoint",void 0);l([f({type:d.Boolean,context:1,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsUserCerts",void 0);l([f({type:d.Boolean,context:2,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsCACerts",void 0);l([f({type:hc,context:3,optional:!0,implicit:!0})],Qt.prototype,"onlySomeReasons",void 0);l([f({type:d.Boolean,context:4,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"indirectCRL",void 0);l([f({type:d.Boolean,context:5,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsAttributeCerts",void 0);var Yx=`${pe}.21`,dc;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(dc||(dc={}));var mc=class{constructor(e=dc.unspecified){this.reason=dc.unspecified,this.reason=e}toJSON(){return dc[this.reason]}toString(){return this.toJSON()}};l([f({type:d.Enumerated})],mc.prototype,"reason",void 0);mc=l([_({type:A.Choice})],mc);var cm,cf=`${pe}.37`,yc=cm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};yc=cm=l([_({type:A.Sequence,itemType:d.ObjectIdentifier})],yc);var KR=`${cf}.0`,Zx=`${ii}.1`,Jx=`${ii}.2`,Qx=`${ii}.3`,eb=`${ii}.4`,tb=`${ii}.8`,rb=`${ii}.9`;var WR=`${pe}.54`,lm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};l([f({type:d.Integer,converter:ge})],lm.prototype,"value",void 0);lm=l([_({type:A.Choice})],lm);var nb=`${pe}.24`,gc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};l([f({type:d.GeneralizedTime})],gc.prototype,"value",void 0);gc=l([_({type:A.Choice})],gc);var um,nL=`${pe}.18`,ob=um=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};ob=um=l([_({type:A.Sequence})],ob);var lf=`${pe}.15`,Pr;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(Pr||(Pr={}));var ys=class extends qr{toJSON(){let e=this.toNumber(),t=[];return e&Pr.cRLSign&&t.push("crlSign"),e&Pr.dataEncipherment&&t.push("dataEncipherment"),e&Pr.decipherOnly&&t.push("decipherOnly"),e&Pr.digitalSignature&&t.push("digitalSignature"),e&Pr.encipherOnly&&t.push("encipherOnly"),e&Pr.keyAgreement&&t.push("keyAgreement"),e&Pr.keyCertSign&&t.push("keyCertSign"),e&Pr.keyEncipherment&&t.push("keyEncipherment"),e&Pr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var fm,hL=`${pe}.30`,gs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};l([f({type:ae})],gs.prototype,"base",void 0);l([f({type:d.Integer,context:0,defaultValue:0,implicit:!0})],gs.prototype,"minimum",void 0);l([f({type:d.Integer,context:1,optional:!0,implicit:!0})],gs.prototype,"maximum",void 0);var uf=fm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};uf=fm=l([_({type:A.Sequence,itemType:gs})],uf);var ff=class{constructor(e={}){Object.assign(this,e)}};l([f({type:uf,context:0,optional:!0,implicit:!0})],ff.prototype,"permittedSubtrees",void 0);l([f({type:uf,context:1,optional:!0,implicit:!0})],ff.prototype,"excludedSubtrees",void 0);var xL=`${pe}.36`,pf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ge})],pf.prototype,"requireExplicitPolicy",void 0);l([f({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ge})],pf.prototype,"inhibitPolicyMapping",void 0);var pm,EL=`${pe}.33`,wc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],wc.prototype,"issuerDomainPolicy",void 0);l([f({type:d.ObjectIdentifier})],wc.prototype,"subjectDomainPolicy",void 0);var ib=pm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,pm.prototype)}};ib=pm=l([_({type:A.Sequence,itemType:wc})],ib);var hm,dm=`${pe}.17`,hf=hm=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,hm.prototype)}};hf=hm=l([_({type:A.Sequence})],hf);var pt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],pt.prototype,"type",void 0);l([f({type:d.Any,repeated:"set"})],pt.prototype,"values",void 0);var mm,KL=`${pe}.9`,sb=mm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};sb=mm=l([_({type:A.Sequence,itemType:pt})],sb);var ym=`${pe}.14`,Vt=class extends ai{};var XL=`${pe}.16`,df=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],df.prototype,"notBefore",void 0);l([f({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],df.prototype,"notAfter",void 0);var xc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(xc||(xc={}));var mf=class extends qr{toJSON(){let e=[],t=this.toNumber();return t&xc.pKIXCertificate&&e.push("pKIXCertificate"),t&xc.newExtensions&&e.push("newExtensions"),t&xc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},yf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new mf,Object.assign(this,e)}};l([f({type:d.GeneralString})],yf.prototype,"entrustVers",void 0);l([f({type:mf})],yf.prototype,"entrustInfoFlags",void 0);var gm,oD=`${so}.11`,ab=gm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};ab=gm=l([_({type:A.Sequence,itemType:bn})],ab);var cb=Dr(dn()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&cb.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};l([f({type:d.ObjectIdentifier})],M.prototype,"algorithm",void 0);l([f({type:d.Any,optional:!0})],M.prototype,"parameters",void 0);var ht=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:M})],ht.prototype,"algorithm",void 0);l([f({type:d.BitString})],ht.prototype,"subjectPublicKey",void 0);var ze=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};l([f({type:d.UTCTime})],ze.prototype,"utcTime",void 0);l([f({type:d.GeneralizedTime})],ze.prototype,"generalTime",void 0);ze=l([_({type:A.Choice})],ze);var Sn=class{constructor(e){this.notBefore=new ze(new Date),this.notAfter=new ze(new Date),e&&(this.notBefore=new ze(e.notBefore),this.notAfter=new ze(e.notAfter))}};l([f({type:ze})],Sn.prototype,"notBefore",void 0);l([f({type:ze})],Sn.prototype,"notAfter",void 0);var wm,dt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new oe,Object.assign(this,e)}};dt.CRITICAL=!1;l([f({type:d.ObjectIdentifier})],dt.prototype,"extnID",void 0);l([f({type:d.Boolean,defaultValue:dt.CRITICAL})],dt.prototype,"critical",void 0);l([f({type:oe})],dt.prototype,"extnValue",void 0);var er=wm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,wm.prototype)}};er=wm=l([_({type:A.Sequence,itemType:dt})],er);var Xr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(Xr||(Xr={}));var mt=class{constructor(e={}){this.version=Xr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new Pe,this.validity=new Sn,this.subject=new Pe,this.subjectPublicKeyInfo=new ht,Object.assign(this,e)}};l([f({type:d.Integer,context:0,defaultValue:Xr.v1})],mt.prototype,"version",void 0);l([f({type:d.Integer,converter:ge})],mt.prototype,"serialNumber",void 0);l([f({type:M})],mt.prototype,"signature",void 0);l([f({type:Pe})],mt.prototype,"issuer",void 0);l([f({type:Sn})],mt.prototype,"validity",void 0);l([f({type:Pe})],mt.prototype,"subject",void 0);l([f({type:ht})],mt.prototype,"subjectPublicKeyInfo",void 0);l([f({type:d.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);l([f({type:d.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);l([f({type:er,context:3,optional:!0})],mt.prototype,"extensions",void 0);var ur=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:mt})],ur.prototype,"tbsCertificate",void 0);l([f({type:M})],ur.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],ur.prototype,"signatureValue",void 0);var ui=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new ze,Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],ui.prototype,"userCertificate",void 0);l([f({type:ze})],ui.prototype,"revocationDate",void 0);l([f({type:dt,optional:!0,repeated:"sequence"})],ui.prototype,"crlEntryExtensions",void 0);var tr=class{constructor(e={}){this.signature=new M,this.issuer=new Pe,this.thisUpdate=new ze,Object.assign(this,e)}};l([f({type:d.Integer,optional:!0})],tr.prototype,"version",void 0);l([f({type:M})],tr.prototype,"signature",void 0);l([f({type:Pe})],tr.prototype,"issuer",void 0);l([f({type:ze})],tr.prototype,"thisUpdate",void 0);l([f({type:ze,optional:!0})],tr.prototype,"nextUpdate",void 0);l([f({type:ui,repeated:"sequence",optional:!0})],tr.prototype,"revokedCertificates",void 0);l([f({type:dt,optional:!0,context:0,repeated:"sequence"})],tr.prototype,"crlExtensions",void 0);var fi=class{constructor(e={}){this.tbsCertList=new tr,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:tr})],fi.prototype,"tbsCertList",void 0);l([f({type:M})],fi.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],fi.prototype,"signature",void 0);var V=Dr(dn());var Or=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Pe})],Or.prototype,"issuer",void 0);l([f({type:d.Integer,converter:ge})],Or.prototype,"serialNumber",void 0);var pi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Vt,context:0,implicit:!0})],pi.prototype,"subjectKeyIdentifier",void 0);l([f({type:Or})],pi.prototype,"issuerAndSerialNumber",void 0);pi=l([_({type:A.Choice})],pi);var yt;(function(r){r[r.v0=0]="v0",r[r.v1=1]="v1",r[r.v2=2]="v2",r[r.v3=3]="v3",r[r.v4=4]="v4",r[r.v5=5]="v5"})(yt||(yt={}));var hi=class extends M{};hi=l([_({type:A.Sequence})],hi);var bc=class extends M{};bc=l([_({type:A.Sequence})],bc);var $t=class extends M{};$t=l([_({type:A.Sequence})],$t);var vc=class extends M{};vc=l([_({type:A.Sequence})],vc);var ub=class extends M{};ub=l([_({type:A.Sequence})],ub);var gf=class extends M{};gf=l([_({type:A.Sequence})],gf);var Rr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Rr.prototype,"attrType",void 0);l([f({type:d.Any,repeated:"set"})],Rr.prototype,"attrValues",void 0);var xm,Ft=class{constructor(e={}){this.version=yt.v0,this.sid=new pi,this.digestAlgorithm=new hi,this.signatureAlgorithm=new bc,this.signature=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],Ft.prototype,"version",void 0);l([f({type:pi})],Ft.prototype,"sid",void 0);l([f({type:hi})],Ft.prototype,"digestAlgorithm",void 0);l([f({type:Rr,repeated:"set",context:0,implicit:!0,optional:!0})],Ft.prototype,"signedAttrs",void 0);l([f({type:bc})],Ft.prototype,"signatureAlgorithm",void 0);l([f({type:oe})],Ft.prototype,"signature",void 0);l([f({type:Rr,repeated:"set",context:1,implicit:!0,optional:!0})],Ft.prototype,"unsignedAttrs",void 0);var Ac=xm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};Ac=xm=l([_({type:A.Set,itemType:Ft})],Ac);var fb=class extends ze{};fb=l([_({type:A.Choice})],fb);var pb=class extends Ft{};pb=l([_({type:A.Sequence})],pb);var Sc=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};l([f({type:ae})],Sc.prototype,"acIssuer",void 0);l([f({type:d.Integer})],Sc.prototype,"acSerial",void 0);l([f({type:pt,repeated:"sequence"})],Sc.prototype,"attrs",void 0);var bm,Ec=bm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,bm.prototype)}};Ec=bm=l([_({type:A.Sequence,itemType:d.ObjectIdentifier})],Ec);var ws=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};l([f({type:d.Integer,optional:!0})],ws.prototype,"pathLenConstraint",void 0);l([f({type:Ec,implicit:!0,context:0,optional:!0})],ws.prototype,"permittedAttrs",void 0);l([f({type:Ec,implicit:!0,context:1,optional:!0})],ws.prototype,"excludedAttrs",void 0);l([f({type:d.Boolean,defaultValue:!0})],ws.prototype,"permitUnSpecified",void 0);var fr=class{constructor(e={}){this.issuer=new Ve,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Ve})],fr.prototype,"issuer",void 0);l([f({type:d.Integer,converter:ge})],fr.prototype,"serial",void 0);l([f({type:d.BitString,optional:!0})],fr.prototype,"issuerUID",void 0);var vm;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(vm||(vm={}));var pr=class{constructor(e={}){this.digestedObjectType=vm.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Enumerated})],pr.prototype,"digestedObjectType",void 0);l([f({type:d.ObjectIdentifier,optional:!0})],pr.prototype,"otherObjectTypeID",void 0);l([f({type:M})],pr.prototype,"digestAlgorithm",void 0);l([f({type:d.BitString})],pr.prototype,"objectDigest",void 0);var di=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Ve,optional:!0})],di.prototype,"issuerName",void 0);l([f({type:fr,context:0,implicit:!0,optional:!0})],di.prototype,"baseCertificateID",void 0);l([f({type:pr,context:1,implicit:!0,optional:!0})],di.prototype,"objectDigestInfo",void 0);var mi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,repeated:"sequence"})],mi.prototype,"v1Form",void 0);l([f({type:di,context:0,implicit:!0})],mi.prototype,"v2Form",void 0);mi=l([_({type:A.Choice})],mi);var yi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};l([f({type:d.GeneralizedTime})],yi.prototype,"notBeforeTime",void 0);l([f({type:d.GeneralizedTime})],yi.prototype,"notAfterTime",void 0);var co=class{constructor(e={}){Object.assign(this,e)}};l([f({type:fr,implicit:!0,context:0,optional:!0})],co.prototype,"baseCertificateID",void 0);l([f({type:Ve,implicit:!0,context:1,optional:!0})],co.prototype,"entityName",void 0);l([f({type:pr,implicit:!0,context:2,optional:!0})],co.prototype,"objectDigestInfo",void 0);var Am;(function(r){r[r.v2=1]="v2"})(Am||(Am={}));var Wt=class{constructor(e={}){this.version=Am.v2,this.holder=new co,this.issuer=new mi,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new yi,this.attributes=[],Object.assign(this,e)}};l([f({type:d.Integer})],Wt.prototype,"version",void 0);l([f({type:co})],Wt.prototype,"holder",void 0);l([f({type:mi})],Wt.prototype,"issuer",void 0);l([f({type:M})],Wt.prototype,"signature",void 0);l([f({type:d.Integer,converter:ge})],Wt.prototype,"serialNumber",void 0);l([f({type:yi})],Wt.prototype,"attrCertValidityPeriod",void 0);l([f({type:pt,repeated:"sequence"})],Wt.prototype,"attributes",void 0);l([f({type:d.BitString,optional:!0})],Wt.prototype,"issuerUniqueID",void 0);l([f({type:er,optional:!0})],Wt.prototype,"extensions",void 0);var gi=class{constructor(e={}){this.acinfo=new Wt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Wt})],gi.prototype,"acinfo",void 0);l([f({type:M})],gi.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],gi.prototype,"signatureValue",void 0);var _c;(function(r){r[r.unmarked=1]="unmarked",r[r.unclassified=2]="unclassified",r[r.restricted=4]="restricted",r[r.confidential=8]="confidential",r[r.secret=16]="secret",r[r.topSecret=32]="topSecret"})(_c||(_c={}));var xs=class extends qr{};var bs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier,implicit:!0,context:0})],bs.prototype,"type",void 0);l([f({type:d.Any,implicit:!0,context:1})],bs.prototype,"value",void 0);var Cc=class{constructor(e={}){this.policyId="",this.classList=new xs(_c.unclassified),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Cc.prototype,"policyId",void 0);l([f({type:xs,defaultValue:new xs(_c.unclassified)})],Cc.prototype,"classList",void 0);l([f({type:bs,repeated:"set"})],Cc.prototype,"securityCategories",void 0);var vs=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe})],vs.prototype,"cotets",void 0);l([f({type:d.ObjectIdentifier})],vs.prototype,"oid",void 0);l([f({type:d.Utf8String})],vs.prototype,"string",void 0);var wf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};l([f({type:Ve,implicit:!0,context:0,optional:!0})],wf.prototype,"policyAuthority",void 0);l([f({type:vs,repeated:"sequence"})],wf.prototype,"values",void 0);var jj=`${so}.4`,Mj=`${so}.6`,Kj=`${so}.10`,Hj=`${pe}.55`,Ic=`${io}.10`,Vj=`${Ic}.1`,$j=`${Ic}.2`,Fj=`${Ic}.3`,Wj=`${Ic}.4`,qj=`${Ic}.6`,Sm="2.5.4",Gj=`${Sm}.72`;var Em,As=class{constructor(e={}){this.targetCertificate=new fr,Object.assign(this,e)}};l([f({type:fr})],As.prototype,"targetCertificate",void 0);l([f({type:ae,optional:!0})],As.prototype,"targetName",void 0);l([f({type:pr,optional:!0})],As.prototype,"certDigestInfo",void 0);var Ss=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,context:0,implicit:!0})],Ss.prototype,"targetName",void 0);l([f({type:ae,context:1,implicit:!0})],Ss.prototype,"targetGroup",void 0);l([f({type:As,context:2,implicit:!0})],Ss.prototype,"targetCert",void 0);Ss=l([_({type:A.Choice})],Ss);var xf=Em=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Em.prototype)}};xf=Em=l([_({type:A.Sequence,itemType:Ss})],xf);var _m,hb=_m=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};hb=_m=l([_({type:A.Sequence,itemType:xf})],hb);var bf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Ve,implicit:!0,context:0,optional:!0})],bf.prototype,"roleAuthority",void 0);l([f({type:ae,implicit:!0,context:1})],bf.prototype,"roleName",void 0);var Tc=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};l([f({type:ae})],Tc.prototype,"service",void 0);l([f({type:ae})],Tc.prototype,"ident",void 0);l([f({type:oe,optional:!0})],Tc.prototype,"authInfo",void 0);var Cm,Bc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Bc.prototype,"otherCertFormat",void 0);l([f({type:d.Any})],Bc.prototype,"otherCert",void 0);var wi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ur})],wi.prototype,"certificate",void 0);l([f({type:gi,context:2,implicit:!0})],wi.prototype,"v2AttrCert",void 0);l([f({type:Bc,context:3,implicit:!0})],wi.prototype,"other",void 0);wi=l([_({type:A.Choice})],wi);var xi=Cm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Cm.prototype)}};xi=Cm=l([_({type:A.Set,itemType:wi})],xi);var hr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],hr.prototype,"contentType",void 0);l([f({type:d.Any,context:0})],hr.prototype,"content",void 0);var Es=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe})],Es.prototype,"single",void 0);l([f({type:d.Any})],Es.prototype,"any",void 0);Es=l([_({type:A.Choice})],Es);var bi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],bi.prototype,"eContentType",void 0);l([f({type:Es,context:0,optional:!0})],bi.prototype,"eContent",void 0);var kc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe,context:0,implicit:!0,optional:!0})],kc.prototype,"value",void 0);l([f({type:oe,converter:Vx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],kc.prototype,"constructedValue",void 0);kc=l([_({type:A.Choice})],kc);var lo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new vc,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],lo.prototype,"contentType",void 0);l([f({type:vc})],lo.prototype,"contentEncryptionAlgorithm",void 0);l([f({type:kc,optional:!0})],lo.prototype,"encryptedContent",void 0);var uo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],uo.prototype,"keyAttrId",void 0);l([f({type:d.Any,optional:!0})],uo.prototype,"keyAttr",void 0);var Im,_s=class{constructor(e={}){this.subjectKeyIdentifier=new Vt,Object.assign(this,e)}};l([f({type:Vt})],_s.prototype,"subjectKeyIdentifier",void 0);l([f({type:d.GeneralizedTime,optional:!0})],_s.prototype,"date",void 0);l([f({type:uo,optional:!0})],_s.prototype,"other",void 0);var Cs=class{constructor(e={}){Object.assign(this,e)}};l([f({type:_s,context:0,implicit:!0,optional:!0})],Cs.prototype,"rKeyId",void 0);l([f({type:Or,optional:!0})],Cs.prototype,"issuerAndSerialNumber",void 0);Cs=l([_({type:A.Choice})],Cs);var Nc=class{constructor(e={}){this.rid=new Cs,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:Cs})],Nc.prototype,"rid",void 0);l([f({type:oe})],Nc.prototype,"encryptedKey",void 0);var vf=Im=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Im.prototype)}};vf=Im=l([_({type:A.Sequence,itemType:Nc})],vf);var Pc=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:M})],Pc.prototype,"algorithm",void 0);l([f({type:d.BitString})],Pc.prototype,"publicKey",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Vt,context:0,implicit:!0,optional:!0})],vi.prototype,"subjectKeyIdentifier",void 0);l([f({type:Pc,context:1,implicit:!0,optional:!0})],vi.prototype,"originatorKey",void 0);l([f({type:Or,optional:!0})],vi.prototype,"issuerAndSerialNumber",void 0);vi=l([_({type:A.Choice})],vi);var En=class{constructor(e={}){this.version=yt.v3,this.originator=new vi,this.keyEncryptionAlgorithm=new $t,this.recipientEncryptedKeys=new vf,Object.assign(this,e)}};l([f({type:d.Integer})],En.prototype,"version",void 0);l([f({type:vi,context:0})],En.prototype,"originator",void 0);l([f({type:oe,context:1,optional:!0})],En.prototype,"ukm",void 0);l([f({type:$t})],En.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:vf})],En.prototype,"recipientEncryptedKeys",void 0);var Is=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Vt,context:0,implicit:!0})],Is.prototype,"subjectKeyIdentifier",void 0);l([f({type:Or})],Is.prototype,"issuerAndSerialNumber",void 0);Is=l([_({type:A.Choice})],Is);var fo=class{constructor(e={}){this.version=yt.v0,this.rid=new Is,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],fo.prototype,"version",void 0);l([f({type:Is})],fo.prototype,"rid",void 0);l([f({type:$t})],fo.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],fo.prototype,"encryptedKey",void 0);var Ai=class{constructor(e={}){this.keyIdentifier=new oe,Object.assign(this,e)}};l([f({type:oe})],Ai.prototype,"keyIdentifier",void 0);l([f({type:d.GeneralizedTime,optional:!0})],Ai.prototype,"date",void 0);l([f({type:uo,optional:!0})],Ai.prototype,"other",void 0);var po=class{constructor(e={}){this.version=yt.v4,this.kekid=new Ai,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],po.prototype,"version",void 0);l([f({type:Ai})],po.prototype,"kekid",void 0);l([f({type:$t})],po.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],po.prototype,"encryptedKey",void 0);var ho=class{constructor(e={}){this.version=yt.v0,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],ho.prototype,"version",void 0);l([f({type:gf,context:0,optional:!0})],ho.prototype,"keyDerivationAlgorithm",void 0);l([f({type:$t})],ho.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],ho.prototype,"encryptedKey",void 0);var Oc=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Oc.prototype,"oriType",void 0);l([f({type:d.Any})],Oc.prototype,"oriValue",void 0);var _n=class{constructor(e={}){Object.assign(this,e)}};l([f({type:fo,optional:!0})],_n.prototype,"ktri",void 0);l([f({type:En,context:1,implicit:!0,optional:!0})],_n.prototype,"kari",void 0);l([f({type:po,context:2,implicit:!0,optional:!0})],_n.prototype,"kekri",void 0);l([f({type:ho,context:3,implicit:!0,optional:!0})],_n.prototype,"pwri",void 0);l([f({type:Oc,context:4,implicit:!0,optional:!0})],_n.prototype,"ori",void 0);_n=l([_({type:A.Choice})],_n);var Tm,Rc=Tm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Tm.prototype)}};Rc=Tm=l([_({type:A.Set,itemType:_n})],Rc);var Bm,db=`${io}.16`,qK=`${db}.2`,GK=`${db}.4`,Ts=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Ts.prototype,"otherRevInfoFormat",void 0);l([f({type:d.Any})],Ts.prototype,"otherRevInfo",void 0);var Af=class{constructor(e={}){this.other=new Ts,Object.assign(this,e)}};l([f({type:Ts,context:1,implicit:!0})],Af.prototype,"other",void 0);Af=l([_({type:A.Choice})],Af);var Bs=Bm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Bm.prototype)}};Bs=Bm=l([_({type:A.Set,itemType:Af})],Bs);var ks=class{constructor(e={}){Object.assign(this,e)}};l([f({type:xi,context:0,implicit:!0,optional:!0})],ks.prototype,"certs",void 0);l([f({type:Bs,context:1,implicit:!0,optional:!0})],ks.prototype,"crls",void 0);var km,Nm=km=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,km.prototype)}};Nm=km=l([_({type:A.Set,itemType:Rr})],Nm);var Si=class{constructor(e={}){this.version=yt.v0,this.recipientInfos=new Rc,this.encryptedContentInfo=new lo,Object.assign(this,e)}};l([f({type:d.Integer})],Si.prototype,"version",void 0);l([f({type:ks,context:0,implicit:!0,optional:!0})],Si.prototype,"originatorInfo",void 0);l([f({type:Rc})],Si.prototype,"recipientInfos",void 0);l([f({type:lo})],Si.prototype,"encryptedContentInfo",void 0);l([f({type:Nm,context:1,implicit:!0,optional:!0})],Si.prototype,"unprotectedAttrs",void 0);var mb="1.2.840.113549.1.7.2";var Pm,Sf=Pm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Pm.prototype)}};Sf=Pm=l([_({type:A.Set,itemType:hi})],Sf);var Cn=class{constructor(e={}){this.version=yt.v0,this.digestAlgorithms=new Sf,this.encapContentInfo=new bi,this.signerInfos=new Ac,Object.assign(this,e)}};l([f({type:d.Integer})],Cn.prototype,"version",void 0);l([f({type:Sf})],Cn.prototype,"digestAlgorithms",void 0);l([f({type:bi})],Cn.prototype,"encapContentInfo",void 0);l([f({type:xi,context:0,implicit:!0,optional:!0})],Cn.prototype,"certificates",void 0);l([f({type:Bs,context:1,implicit:!0,optional:!0})],Cn.prototype,"crls",void 0);l([f({type:Ac})],Cn.prototype,"signerInfos",void 0);var Ei="1.2.840.10045.2.1";var Lc="1.2.840.10045.4.1",Ef="1.2.840.10045.4.3.1",Dc="1.2.840.10045.4.3.2",Uc="1.2.840.10045.4.3.3",jc="1.2.840.10045.4.3.4";var Om="1.2.840.10045.3.1.7";var Rm="1.3.132.0.34";var Lm="1.3.132.0.35";function Mc(r){return new M({algorithm:r})}var gb=Mc(Lc),$H=Mc(Ef),wb=Mc(Dc),xb=Mc(Uc),bb=Mc(jc);var Kc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Kc.prototype,"fieldType",void 0);l([f({type:d.Any})],Kc.prototype,"parameters",void 0);Kc=l([_({type:A.Sequence})],Kc);var Dm=class extends oe{};var Ns=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.OctetString})],Ns.prototype,"a",void 0);l([f({type:d.OctetString})],Ns.prototype,"b",void 0);l([f({type:d.BitString,optional:!0})],Ns.prototype,"seed",void 0);Ns=l([_({type:A.Sequence})],Ns);var Um;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Um||(Um={}));var Yr=class{constructor(e={}){this.version=Um.ecpVer1,Object.assign(this,e)}};l([f({type:d.Integer})],Yr.prototype,"version",void 0);l([f({type:Kc})],Yr.prototype,"fieldID",void 0);l([f({type:Ns})],Yr.prototype,"curve",void 0);l([f({type:Dm})],Yr.prototype,"base",void 0);l([f({type:d.Integer,converter:ge})],Yr.prototype,"order",void 0);l([f({type:d.Integer,optional:!0})],Yr.prototype,"cofactor",void 0);Yr=l([_({type:A.Sequence})],Yr);var Zr=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Zr.prototype,"namedCurve",void 0);l([f({type:d.Null})],Zr.prototype,"implicitCurve",void 0);l([f({type:Yr})],Zr.prototype,"specifiedCurve",void 0);Zr=l([_({type:A.Choice})],Zr);var Ps=class{constructor(e={}){this.version=1,this.privateKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],Ps.prototype,"version",void 0);l([f({type:oe})],Ps.prototype,"privateKey",void 0);l([f({type:Zr,context:0,optional:!0})],Ps.prototype,"parameters",void 0);l([f({type:d.BitString,context:1,optional:!0})],Ps.prototype,"publicKey",void 0);var _i=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],_i.prototype,"r",void 0);l([f({type:d.Integer,converter:ge})],_i.prototype,"s",void 0);var qt="1.2.840.113549.1.1",Jr=`${qt}.1`,vb=`${qt}.7`,Ab=`${qt}.9`,mo=`${qt}.10`,Sb=`${qt}.2`,Eb=`${qt}.4`,Os=`${qt}.5`,_b=`${qt}.14`;var _f=`${qt}.11`,Rs=`${qt}.12`,Ls=`${qt}.13`,jm=`${qt}.15`,Mm=`${qt}.16`,Ci="1.3.14.3.2.26",Cf="2.16.840.1.101.3.4.2.4",Ii="2.16.840.1.101.3.4.2.1",Ti="2.16.840.1.101.3.4.2.2",Bi="2.16.840.1.101.3.4.2.3",Cb="2.16.840.1.101.3.4.2.5",Ib="2.16.840.1.101.3.4.2.6",Tb="1.2.840.113549.2.2",Bb="1.2.840.113549.2.5",yo=`${qt}.8`;function lt(r){return new M({algorithm:r,parameters:null})}var g7=lt(Tb),w7=lt(Bb),In=lt(Ci),x7=lt(Cf),b7=lt(Ii),v7=lt(Ti),A7=lt(Bi),S7=lt(Cb),E7=lt(Ib),If=new M({algorithm:yo,parameters:F.serialize(In)}),Km=new M({algorithm:Ab,parameters:F.serialize(hs.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),_7=lt(Jr),C7=lt(Sb),I7=lt(Eb),T7=lt(Os),B7=lt(jm),k7=lt(Mm),N7=lt(Rs),P7=lt(Ls),O7=lt(jm),R7=lt(Mm);var Ds=class{constructor(e={}){this.hashAlgorithm=new M(In),this.maskGenAlgorithm=new M({algorithm:yo,parameters:F.serialize(In)}),this.pSourceAlgorithm=new M(Km),Object.assign(this,e)}};l([f({type:M,context:0,defaultValue:In})],Ds.prototype,"hashAlgorithm",void 0);l([f({type:M,context:1,defaultValue:If})],Ds.prototype,"maskGenAlgorithm",void 0);l([f({type:M,context:2,defaultValue:Km})],Ds.prototype,"pSourceAlgorithm",void 0);var H7=new M({algorithm:vb,parameters:F.serialize(new Ds)});var Qr=class{constructor(e={}){this.hashAlgorithm=new M(In),this.maskGenAlgorithm=new M({algorithm:yo,parameters:F.serialize(In)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};l([f({type:M,context:0,defaultValue:In})],Qr.prototype,"hashAlgorithm",void 0);l([f({type:M,context:1,defaultValue:If})],Qr.prototype,"maskGenAlgorithm",void 0);l([f({type:d.Integer,context:2,defaultValue:20})],Qr.prototype,"saltLength",void 0);l([f({type:d.Integer,context:3,defaultValue:1})],Qr.prototype,"trailerField",void 0);var z7=new M({algorithm:mo,parameters:F.serialize(new Qr)});var ki=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new oe,Object.assign(this,e)}};l([f({type:M})],ki.prototype,"digestAlgorithm",void 0);l([f({type:oe})],ki.prototype,"digest",void 0);var Hm,Us=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],Us.prototype,"prime",void 0);l([f({type:d.Integer,converter:ge})],Us.prototype,"exponent",void 0);l([f({type:d.Integer,converter:ge})],Us.prototype,"coefficient",void 0);var Tf=Hm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Hm.prototype)}};Tf=Hm=l([_({type:A.Sequence,itemType:Us})],Tf);var dr=class{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer})],dr.prototype,"version",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"modulus",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"publicExponent",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"privateExponent",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"prime1",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"prime2",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"exponent1",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"exponent2",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"coefficient",void 0);l([f({type:Tf,optional:!0})],dr.prototype,"otherPrimeInfos",void 0);var js=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],js.prototype,"modulus",void 0);l([f({type:d.Integer,converter:ge})],js.prototype,"publicExponent",void 0);var Vm;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Vm||(Vm={}));var gt=Vm;var Zb=Dr(Yb(),1),{__extends:Ks,__assign:_V,__rest:iC,__decorate:CV,__param:IV,__metadata:TV,__awaiter:Jb,__generator:Qb,__exportStar:BV,__createBinding:kV,__values:Hc,__read:Vc,__spread:Lr,__spreadArrays:NV,__await:PV,__asyncGenerator:OV,__asyncDelegator:RV,__asyncValues:LV,__makeTemplateObject:DV,__importStar:UV,__importDefault:jV,__classPrivateFieldGet:MV,__classPrivateFieldSet:KV}=Zb.default;var sC="injectionTokens";function Fm(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(sC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function $c(r){return!!r.useClass}function Hs(r){return!!r.useFactory}var Nf=function(){function r(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return r.prototype.createProxy=function(e){var t=this,n={},o=!1,i,s=function(){return o||(i=e(t.wrap()),o=!0),i};return new Proxy(n,this.createHandler(s))},r.prototype.createHandler=function(e){var t={},n=function(o){t[o]=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];i[0]=e();var a=Reflect[o];return a.apply(void 0,Lr(i))}};return this.reflectMethods.forEach(n),t},r}();function go(r){return typeof r=="string"||typeof r=="symbol"}function Wm(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Pf(r){return typeof r=="object"&&"token"in r&&"transform"in r}function ev(r){return typeof r=="function"||r instanceof Nf}function Ni(r){return!!r.useToken}function Pi(r){return r.useValue!=null}function tv(r){return $c(r)||Pi(r)||Ni(r)||Hs(r)}var aC=function(){function r(){this._registryMap=new Map}return r.prototype.entries=function(){return this._registryMap.entries()},r.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},r.prototype.get=function(e){this.ensure(e);var t=this._registryMap.get(e);return t[t.length-1]||null},r.prototype.set=function(e,t){this.ensure(e),this._registryMap.get(e).push(t)},r.prototype.setAll=function(e,t){this._registryMap.set(e,t)},r.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},r.prototype.clear=function(){this._registryMap.clear()},r.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},r}(),Fc=aC;var cC=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Fc),rv=cC;var lC=function(){function r(){this.scopedResolutions=new Map}return r}(),Wc=lC;function uC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function fC(r,e,t){return t===void 0&&(t=" "),Lr([r],e.message.split(`
6
+ `)}`:`${t} :`}};ox=ct;X.Constructed=ox;ct.NAME="CONSTRUCTED";var Vu=class extends ft{fromBER(e,t,n){return t}toBER(e){return kr}};Vu.override="EndOfContentValueBlock";var ix,za=class extends rt{constructor(e={}){super(e,Vu),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};ix=za;X.EndOfContent=ix;za.NAME=qa;var sx,Ir=class extends rt{constructor(e={}){super(e,ft),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};sx=Ir;X.Null=sx;Ir.NAME="NULL";var $u=class extends Fr(ft){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=me.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);return wn(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Rd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};$u.NAME="BooleanValueBlock";var ax,$o=class extends rt{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,$u),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};ax=$o;X.Boolean=ax;$o.NAME="BOOLEAN";var Fu=class extends Fr(Vr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=Vr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===qa){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==ex)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?Vr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Fu.NAME="OctetStringValueBlock";var jd,Tr=class extends rt{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Fu),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=ps(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ct.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof jd&&e.push(t.valueBlock.valueHexView);return me.BufferSourceConverter.concat(e)}};jd=Tr;X.OctetString=jd;Tr.NAME=ex;var Wu=class extends Fr(Vr){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=Vr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===qa){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==tx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let i=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=ps(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return Vr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return kr;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Wu.NAME="BitStringValueBlock";var cx,Br=class extends rt{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Wu),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ct.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join(""),o=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${o} : ${i}`}}};cx=Br;X.BitString=cx;Br.NAME=tx;var lx;function x_(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u=0,h=c<s?s:c,p=0;for(let y=h;y>=0;y--,p++){switch(!0){case p<a.length:u=i[s-p]+a[c-p]+t[0];break;default:u=i[s-p]+t[0]}switch(t[0]=u/10,!0){case p>=i.length:i=Uu(new Uint8Array([u%10]),i);break;default:i[s-p]=u%10}}return t[0]>0&&(i=Uu(t,i)),i}function Qw(r){if(r>=Fa.length)for(let e=Fa.length;e<=r;e++){let t=new Uint8Array([0]),n=Fa[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=Uu(t,n)),Fa.push(n)}return Fa[r]}function b_(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,u,h=0;for(let p=c;p>=0;p--,h++)switch(u=i[s-h]-a[c-h]-t,!0){case u<0:t=1,i[s-h]=u+10;break;default:t=0,i[s-h]=u}if(t>0)for(let p=s-c+1;p>=0;p--,h++)if(u=i[s-h]-t,u<0)t=1,i[s-h]=u+10;else{t=0,i[s-h]=u;break}return i.slice()}var Xa=class extends Fr(ft){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Rd.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Xw(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=b_(Qw(n),t),s="-";break;default:t=x_(t,Qw(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Zw.charAt(t[c]));return a===!1&&(s+=Zw.charAt(0)),s}};lx=Xa;Xa.NAME="IntegerValueBlock";Object.defineProperty(lx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Wa,gn=class extends rt{constructor(e={}){super(e,Xa),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return ju(),BigInt(this.valueBlock.toString())}static fromBigInt(e){ju();let t=BigInt(e),n=new us,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(me.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${me.Convert.ToHex(a)}`)+t,h=me.BufferSourceConverter.toUint8Array(me.Convert.FromHex(u.toString(16)));h[0]|=128,n.write(h)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new Wa({valueHex:n.final()})}convertToDER(){let e=new Wa({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Wa({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Wa=gn;X.Integer=Wa;gn.NAME="INTEGER";var ux,Fo=class extends gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};ux=Fo;X.Enumerated=ux;Fo.NAME="ENUMERATED";var Ya=class extends Fr(ft){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Vo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){ju();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Jn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=me.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Ya.NAME="sidBlock";var qu=class extends ft{constructor({value:e=Dt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Ya;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,kr;t.push(o)}return Ud(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new Ya;if(o>Number.MAX_SAFE_INTEGER){ju();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};qu.NAME="ObjectIdentifierValueBlock";var fx,Wo=class extends rt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,qu),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};fx=Wo;X.ObjectIdentifier=fx;Wo.NAME="OBJECT IDENTIFIER";var Za=class extends Fr(mn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!wn(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Vo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Jn(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=me.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Za.NAME="relativeSidBlock";var Gu=class extends ft{constructor({value:e=Dt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Za;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,kr;n.push(i)}return Ud(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new Za;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Gu.NAME="RelativeObjectIdentifierValueBlock";var px,Ja=class extends rt{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Gu),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};px=Ja;X.RelativeObjectIdentifier=px;Ja.NAME="RelativeObjectIdentifier";var hx,Ut=class extends ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};hx=Ut;X.Sequence=hx;Ut.NAME="SEQUENCE";var dx,jt=class extends ct{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};dx=jt;X.Set=dx;jt.NAME="SET";var zu=class extends Fr(ft){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Dt}toJSON(){return{...super.toJSON(),value:this.value}}};zu.NAME="StringValueBlock";var Xu=class extends zu{};Xu.NAME="SimpleStringValueBlock";var Pt=class extends Ga{constructor({...e}={}){super(e,Xu)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Pt.NAME="SIMPLE STRING";var Yu=class extends Pt{fromBuffer(e){this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=me.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=me.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Yu.NAME="Utf8StringValueBlock";var mx,ar=class extends Yu{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};mx=ar;X.Utf8String=mx;ar.NAME="UTF8String";var Zu=class extends Pt{fromBuffer(e){this.valueBlock.value=me.Convert.ToUtf16String(e),this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf16String(e))}};Zu.NAME="BmpStringValueBlock";var yx,qo=class extends Zu{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};yx=qo;X.BmpString=yx;qo.NAME="BMPString";var Ju=class extends Pt{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Jn(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};Ju.NAME="UniversalStringValueBlock";var gx,Go=class extends Ju{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};gx=Go;X.UniversalString=gx;Go.NAME="UniversalString";var wx,zo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};wx=zo;X.NumericString=wx;zo.NAME="NumericString";var xx,Xo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};xx=Xo;X.PrintableString=xx;Xo.NAME="PrintableString";var bx,Yo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};bx=Yo;X.TeletexString=bx;Yo.NAME="TeletexString";var vx,Zo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};vx=Zo;X.VideotexString=vx;Zo.NAME="VideotexString";var Ax,Jo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Ax=Jo;X.IA5String=Ax;Jo.NAME="IA5String";var Sx,Qo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Sx=Qo;X.GraphicString=Sx;Qo.NAME="GraphicString";var Ex,eo=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ex=eo;X.VisibleString=Ex;eo.NAME="VisibleString";var _x,ei=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};_x=ei;X.GeneralString=_x;ei.NAME="GeneralString";var Cx,ti=class extends Pt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Cx=ti;X.CharacterString=Cx;ti.NAME="CharacterString";var Ix,to=class extends eo{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Lt(this.month,2),t[2]=Lt(this.day,2),t[3]=Lt(this.hour,2),t[4]=Lt(this.minute,2),t[5]=Lt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Ix=to;X.UTCTime=Ix;to.NAME="UTCTime";var Tx,ri=class extends to{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let p=new Number(e[e.length-1]);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let p=1,y=n.indexOf("+"),w="";if(y===-1&&(y=n.indexOf("-"),p=-1),y!==-1){if(w=n.substring(y+1),n=n.substring(0,y),w.length!==2&&w.length!==4)throw new Error("Wrong input string for conversion");let b=parseInt(w.substring(0,2),10);if(isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*b,w.length===4){if(b=parseInt(w.substring(2,4),10),isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");c=p*b}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let p=new Number(`0${n.substring(u)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=60*i;this.minute=Math.floor(p),p=60*(p-this.minute),this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=60*i;this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let h=s.exec(o);if(h===null)throw new Error("Wrong input string for conversion");for(let p=1;p<h.length;p++)switch(p){case 1:this.year=parseInt(h[p],10);break;case 2:this.month=parseInt(h[p],10);break;case 3:this.day=parseInt(h[p],10);break;case 4:this.hour=parseInt(h[p],10)+a;break;case 5:this.minute=parseInt(h[p],10)+c;break;case 6:this.second=parseInt(h[p],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let p=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=p.getUTCFullYear(),this.month=p.getUTCMonth(),this.day=p.getUTCDay(),this.hour=p.getUTCHours(),this.minute=p.getUTCMinutes(),this.second=p.getUTCSeconds(),this.millisecond=p.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Lt(this.year,4)),t.push(Lt(this.month,2)),t.push(Lt(this.day,2)),t.push(Lt(this.hour,2)),t.push(Lt(this.minute,2)),t.push(Lt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Lt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Tx=ri;X.GeneralizedTime=Tx;ri.NAME="GeneralizedTime";var Bx,Qa=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Bx=Qa;X.DATE=Bx;Qa.NAME="DATE";var kx,ec=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};kx=ec;X.TimeOfDay=kx;ec.NAME="TimeOfDay";var Px,tc=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Px=tc;X.DateTime=Px;tc.NAME="DateTime";var Nx,rc=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Nx=rc;X.Duration=Nx;rc.NAME="Duration";var Ox,nc=class extends ar{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Ox=nc;X.TIME=Ox;nc.NAME="TIME";var $r=class{constructor({name:e=Dt,optional:t=!1}={}){this.name=e,this.optional=t}},fs=class extends $r{constructor({value:e=[],...t}={}){super(t),this.value=e}},ni=class extends $r{constructor({value:e=new $r,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Dd=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=me.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Qu}={}){this.dataView=me.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=me.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function Qn(r,e,t){if(t instanceof fs){for(let i of t.value)if(Qn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Ld)&&(i.name=t.name),i}}if(t instanceof $r)return t.hasOwnProperty(Ld)&&(r[t.name]=e),{verified:!0,result:r};if(!(r instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(u_ in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(d_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(m_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let n=t.idBlock.toBER(!1);if(n.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(t.idBlock.fromBER(n,0,n.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(t.idBlock.hasOwnProperty(f_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(p_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(h_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(l_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:r};if(t.idBlock.isHexOnly){if(!(Jw in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let i=t.idBlock.valueHexView,s=e.idBlock.valueHexView;if(i.length!==s.length)return{verified:!1,result:r};for(let a=0;a<i.length;a++)if(i[a]!==s[1])return{verified:!1,result:r}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&(r[t.name]=e)),t instanceof X.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof ni&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let u=0;u<t.valueBlock.value.length;u++)c=c&&(t.valueBlock.value[u].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){let u={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&(delete r[t.name],u.name=t.name)),u}}else if(t.valueBlock.value[0]instanceof ni){if(s=Qn(r,e.valueBlock.value[c],t.valueBlock.value[0].value),s.verified===!1)if(t.valueBlock.value[0].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&delete r[t.name]),s;if(Ld in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let u={};y_ in t.valueBlock.value[0]&&t.valueBlock.value[0].local?u=e:u=r,typeof u[t.valueBlock.value[0].name]>"u"&&(u[t.valueBlock.value[0].name]=[]),u[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=Qn(r,e.valueBlock.value[c-i],t.valueBlock.value[c]),s.verified===!1)if(t.valueBlock.value[c].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&delete r[t.name]),s;if(s.verified===!1){let c={verified:!1,result:r};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Jw in e.valueBlock){let i=ps(e.valueBlock.valueHexView);if(i.offset===-1){let s={verified:!1,result:i.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Dt),t.name&&(delete r[t.name],s.name=t.name)),s}return Qn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function v_(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=ps(me.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:Qn(t.result,t.result,e)}var A;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(A||(A={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var Md=Dr(dn()),qr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Md.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Md.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Br))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Br({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Br({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Kd=Dr(dn()),oe=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Kd.BufferSourceConverter.isBufferSource(e)?this.buffer=Kd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Tr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Tr({valueHex:this.buffer})}toSchema(e){return new Tr({name:e})}};var A_={fromASN:r=>r instanceof Ir?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Ir;let e=xn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},S_={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new gn({value:+r})},E_={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Fo({value:r})},ge={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new gn({valueHex:r})};var __={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Br({valueHex:r})},C_={fromASN:r=>r.valueBlock.toString(),toASN:r=>new Wo({value:r})},I_={fromASN:r=>r.valueBlock.value,toASN:r=>new $o({value:r})},hs={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Tr({valueHex:r})},Rx={fromASN:r=>new oe(r.getValue()),toASN:r=>r.toASN()};function cr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Hd=cr(ar),T_=cr(qo),B_=cr(Go),k_=cr(zo),P_=cr(Xo),N_=cr(Yo),O_=cr(Zo),R_=cr(Jo),L_=cr(Qo),D_=cr(eo),U_=cr(ei),j_=cr(ti),M_={fromASN:r=>r.toDate(),toASN:r=>new to({valueDate:r})},K_={fromASN:r=>r.toDate(),toASN:r=>new ri({valueDate:r})},H_={fromASN:()=>null,toASN:()=>new Ir};function ds(r){switch(r){case d.Any:return A_;case d.BitString:return __;case d.BmpString:return T_;case d.Boolean:return I_;case d.CharacterString:return j_;case d.Enumerated:return E_;case d.GeneralString:return U_;case d.GeneralizedTime:return K_;case d.GraphicString:return L_;case d.IA5String:return R_;case d.Integer:return S_;case d.Null:return H_;case d.NumericString:return k_;case d.ObjectIdentifier:return C_;case d.OctetString:return hs;case d.PrintableString:return P_;case d.TeletexString:return N_;case d.UTCTime:return M_;case d.UniversalString:return B_;case d.Utf8String:return Hd;case d.VideotexString:return O_;case d.VisibleString:return D_;default:return null}}function lr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:lr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function $d(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:$d(t)}return!1}function Lx(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}var ef=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:A.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let h=d[s.type],p=Wr[h];if(!p)throw new Error(`Cannot get ASN1 class by name '${h}'`);c=new p({name:a})}else lr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===A.Choice?c=new $r({name:a}):(c=this.create(s.type,!1),c.name=a):c=new $r({name:a});let u=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let h=s.repeated==="set"?jt:Ut;c=new h({name:"",value:[new ni({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||lr(s.type)){let h=s.repeated?ct:yn;o.push(new h({name:a,optional:u,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let h=!!s.repeated,p=h?c:this.get(s.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,o.push(new ct({name:h?"":a,optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new ct({optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=u,o.push(c)}switch(n.type){case A.Sequence:return new Ut({value:o,name:""});case A.Set:return new jt({value:o,name:""});case A.Choice:return new fs({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var Nt=new ef;var _=r=>e=>{let t;Nt.has(e)?t=Nt.get(e):(t=Nt.createDefault(e),Nt.set(e,t)),Object.assign(t,r)};var f=r=>(e,t)=>{let n;Nt.has(e.constructor)?n=Nt.get(e.constructor):(n=Nt.createDefault(e.constructor),Nt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=ds(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}n.items[t]=o};var oc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var ic=class{static parse(e,t){let n=xn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(lr(t))return new t().fromASN(e);let o=Nt.get(t);Nt.cache(t);let i=o.schema;if(e.constructor===ct&&o.type!==A.Choice){i=new ct({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=Qn({},e,i);if(!s.verified)throw new oc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if($d(t)){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=o.itemType;if(typeof c=="number"){let u=ds(c);if(!u)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,h=>u.fromASN(h))}else return t.from(e.valueBlock.value,u=>this.fromASN(u,c))}for(let c in o.items){let u=s.result[c];if(!u)continue;let h=o.items[c],p=h.type;if(typeof p=="number"||lr(p)){let y=(n=h.converter)!==null&&n!==void 0?n:lr(p)?new p:null;if(!y)throw new Error("Converter is empty");if(h.repeated)if(h.implicit){let w=h.repeated==="sequence"?Ut:jt,b=new w;b.valueBlock=u.valueBlock;let g=xn(b.toBER(!1));if(g.offset===-1)throw new Error(`Cannot parse the child item. ${g.result.error}`);if(!("value"in g.result.valueBlock&&Array.isArray(g.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let m=g.result.valueBlock.value;a[c]=Array.from(m,S=>y.fromASN(S))}else a[c]=Array.from(u,w=>y.fromASN(w));else{let w=u;if(h.implicit){let b;if(lr(p))b=new p().toSchema("");else{let g=d[p],m=Wr[g];if(!m)throw new Error(`Cannot get '${g}' class from asn1js module`);b=new m}b.valueBlock=w.valueBlock,w=xn(b.toBER(!1)).result}a[c]=y.fromASN(w)}}else if(h.repeated){if(!Array.isArray(u))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");a[c]=Array.from(u,y=>this.fromASN(y,p))}else a[c]=this.fromASN(u,p)}return a}catch(o){throw o instanceof oc&&o.schemas.push(t.name),o}}};var sc=class r{static serialize(e){return e instanceof rt?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&lr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Nt.get(t);Nt.cache(t);let o=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let s=ds(n.itemType);if(!s)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);o=e.map(a=>s.toASN(a))}else o=e.map(s=>this.toAsnItem({type:n.itemType},"[]",t,s))}else for(let s in n.items){let a=n.items[s],c=e[s];if(c===void 0||a.defaultValue===c||typeof a.defaultValue=="object"&&typeof c=="object"&&Lx(this.serialize(a.defaultValue),this.serialize(c)))continue;let u=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||lr(a.type))){let h={};h.valueHex=u instanceof Ir?u.valueBeforeDecodeView:u.valueBlock.toBER(),o.push(new yn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...h}))}else o.push(new ct({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:u.valueBlock.value}));else o.push(new ct({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[u]}));else a.repeated?o=o.concat(u):o.push(u)}let i;switch(n.type){case A.Sequence:i=new Ut({value:o});break;case A.Set:i=new jt({value:o});break;case A.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,u=>s.toASN(u)),c=e.repeated==="sequence"?Ut:jt;i=new c({value:a})}else i=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let s=Array.from(o,c=>this.toASN(c)),a=e.repeated==="sequence"?Ut:jt;i=new a({value:s})}else i=this.toASN(o);return i}};var ne=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var Fd=Dr(dn());var F=class r{static serialize(e){return sc.serialize(e)}static parse(e,t){return ic.parse(e,t)}static toString(e){let t=Fd.BufferSourceConverter.isBufferSource(e)?Fd.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=xn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function l(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Dx=Dr(dn()),ac=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,u)=>c+(u.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(Dx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var Ux=Dr(dn()),Wd,qd,Gd,nt=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};l([f({type:d.TeletexString})],nt.prototype,"teletexString",void 0);l([f({type:d.PrintableString})],nt.prototype,"printableString",void 0);l([f({type:d.UniversalString})],nt.prototype,"universalString",void 0);l([f({type:d.Utf8String})],nt.prototype,"utf8String",void 0);l([f({type:d.BmpString})],nt.prototype,"bmpString",void 0);nt=l([_({type:A.Choice})],nt);var ms=class extends nt{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Ux.Convert.ToHex(this.anyValue):super.toString())}};l([f({type:d.IA5String})],ms.prototype,"ia5String",void 0);l([f({type:d.Any})],ms.prototype,"anyValue",void 0);ms=l([_({type:A.Choice})],ms);var oi=class{constructor(e={}){this.type="",this.value=new ms,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],oi.prototype,"type",void 0);l([f({type:ms})],oi.prototype,"value",void 0);var ro=Wd=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Wd.prototype)}};ro=Wd=l([_({type:A.Set,itemType:oi})],ro);var zd=qd=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,qd.prototype)}};zd=qd=l([_({type:A.Sequence,itemType:ro})],zd);var Ne=Gd=class extends zd{constructor(e){super(e),Object.setPrototypeOf(this,Gd.prototype)}};Ne=Gd=l([_({type:A.Sequence})],Ne);var V_={fromASN:r=>ac.toString(hs.fromASN(r)),toASN:r=>hs.toASN(ac.fromString(r))},no=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],no.prototype,"typeId",void 0);l([f({type:d.Any,context:0})],no.prototype,"value",void 0);var cc=class{constructor(e={}){this.partyName=new nt,Object.assign(this,e)}};l([f({type:nt,optional:!0,context:0,implicit:!0})],cc.prototype,"nameAssigner",void 0);l([f({type:nt,context:1,implicit:!0})],cc.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};l([f({type:no,context:0,implicit:!0})],ae.prototype,"otherName",void 0);l([f({type:d.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);l([f({type:d.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);l([f({type:d.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);l([f({type:Ne,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);l([f({type:cc,context:5})],ae.prototype,"ediPartyName",void 0);l([f({type:d.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);l([f({type:d.OctetString,context:7,implicit:!0,converter:V_})],ae.prototype,"iPAddress",void 0);l([f({type:d.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=l([_({type:A.Choice})],ae);var oo="1.3.6.1.5.5.7",io=`${oo}.1`,jx=`${oo}.2`,ii=`${oo}.3`,tf=`${oo}.48`,rO=`${jx}.1`,nO=`${jx}.2`,Xd=`${tf}.1`,Yd=`${tf}.2`,Zd=`${tf}.3`,Jd=`${tf}.5`,fe="2.5.29";var Qd,rf=`${io}.1`,bn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],bn.prototype,"accessMethod",void 0);l([f({type:ae})],bn.prototype,"accessLocation",void 0);var si=Qd=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Qd.prototype)}};si=Qd=l([_({type:A.Sequence,itemType:bn})],si);var nf=`${fe}.35`,ai=class extends oe{},Gr=class{constructor(e={}){e&&Object.assign(this,e)}};l([f({type:ai,context:0,optional:!0,implicit:!0})],Gr.prototype,"keyIdentifier",void 0);l([f({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Gr.prototype,"authorityCertIssuer",void 0);l([f({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ge})],Gr.prototype,"authorityCertSerialNumber",void 0);var of=`${fe}.19`,ci=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};l([f({type:d.Boolean,defaultValue:!1})],ci.prototype,"cA",void 0);l([f({type:d.Integer,optional:!0})],ci.prototype,"pathLenConstraint",void 0);var em,Ve=em=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,em.prototype)}};Ve=em=l([_({type:A.Sequence,itemType:ae})],Ve);var tm,$_=`${fe}.29`,Mx=tm=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,tm.prototype)}};Mx=tm=l([_({type:A.Sequence})],Mx);var rm,af=`${fe}.32`,LO=`${af}.0`,vn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};l([f({type:d.IA5String})],vn.prototype,"ia5String",void 0);l([f({type:d.VisibleString})],vn.prototype,"visibleString",void 0);l([f({type:d.BmpString})],vn.prototype,"bmpString",void 0);l([f({type:d.Utf8String})],vn.prototype,"utf8String",void 0);vn=l([_({type:A.Choice})],vn);var lc=class{constructor(e={}){this.organization=new vn,this.noticeNumbers=[],Object.assign(this,e)}};l([f({type:vn})],lc.prototype,"organization",void 0);l([f({type:d.Integer,repeated:"sequence"})],lc.prototype,"noticeNumbers",void 0);var uc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:lc,optional:!0})],uc.prototype,"noticeRef",void 0);l([f({type:vn,optional:!0})],uc.prototype,"explicitText",void 0);var sf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.IA5String})],sf.prototype,"cPSuri",void 0);l([f({type:uc})],sf.prototype,"userNotice",void 0);sf=l([_({type:A.Choice})],sf);var fc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],fc.prototype,"policyQualifierId",void 0);l([f({type:d.Any})],fc.prototype,"qualifier",void 0);var li=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],li.prototype,"policyIdentifier",void 0);l([f({type:fc,repeated:"sequence",optional:!0})],li.prototype,"policyQualifiers",void 0);var pc=rm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};pc=rm=l([_({type:A.Sequence,itemType:li})],pc);var $O=`${fe}.20`,hc=class{constructor(e=0){this.value=e}};l([f({type:d.Integer})],hc.prototype,"value",void 0);hc=l([_({type:A.Choice})],hc);var YO=`${fe}.27`,Kx=class extends hc{};Kx=l([_({type:A.Choice})],Kx);var nm,cf=`${fe}.31`,Pr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Pr||(Pr={}));var dc=class extends qr{toJSON(){let e=[],t=this.toNumber();return t&Pr.aACompromise&&e.push("aACompromise"),t&Pr.affiliationChanged&&e.push("affiliationChanged"),t&Pr.cACompromise&&e.push("cACompromise"),t&Pr.certificateHold&&e.push("certificateHold"),t&Pr.cessationOfOperation&&e.push("cessationOfOperation"),t&Pr.keyCompromise&&e.push("keyCompromise"),t&Pr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Pr.superseded&&e.push("superseded"),t&Pr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},An=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,context:0,repeated:"sequence",implicit:!0})],An.prototype,"fullName",void 0);l([f({type:ro,context:1,implicit:!0})],An.prototype,"nameRelativeToCRLIssuer",void 0);An=l([_({type:A.Choice})],An);var zr=class{constructor(e={}){Object.assign(this,e)}};l([f({type:An,context:0,optional:!0})],zr.prototype,"distributionPoint",void 0);l([f({type:dc,context:1,optional:!0,implicit:!0})],zr.prototype,"reasons",void 0);l([f({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],zr.prototype,"cRLIssuer",void 0);var so=nm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};so=nm=l([_({type:A.Sequence,itemType:zr})],so);var om,fR=`${fe}.46`,Hx=om=class extends so{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};Hx=om=l([_({type:A.Sequence,itemType:zr})],Hx);var xR=`${fe}.28`,Zt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Zt.ONLY=!1;l([f({type:An,context:0,optional:!0})],Zt.prototype,"distributionPoint",void 0);l([f({type:d.Boolean,context:1,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsUserCerts",void 0);l([f({type:d.Boolean,context:2,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsCACerts",void 0);l([f({type:dc,context:3,optional:!0,implicit:!0})],Zt.prototype,"onlySomeReasons",void 0);l([f({type:d.Boolean,context:4,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"indirectCRL",void 0);l([f({type:d.Boolean,context:5,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsAttributeCerts",void 0);var Vx=`${fe}.21`,mc;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(mc||(mc={}));var yc=class{constructor(e=mc.unspecified){this.reason=mc.unspecified,this.reason=e}toJSON(){return mc[this.reason]}toString(){return this.toJSON()}};l([f({type:d.Enumerated})],yc.prototype,"reason",void 0);yc=l([_({type:A.Choice})],yc);var im,lf=`${fe}.37`,gc=im=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};gc=im=l([_({type:A.Sequence,itemType:d.ObjectIdentifier})],gc);var kR=`${lf}.0`,$x=`${ii}.1`,Fx=`${ii}.2`,Wx=`${ii}.3`,qx=`${ii}.4`,Gx=`${ii}.8`,zx=`${ii}.9`;var LR=`${fe}.54`,sm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};l([f({type:d.Integer,converter:ge})],sm.prototype,"value",void 0);sm=l([_({type:A.Choice})],sm);var Xx=`${fe}.24`,wc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};l([f({type:d.GeneralizedTime})],wc.prototype,"value",void 0);wc=l([_({type:A.Choice})],wc);var am,GR=`${fe}.18`,Yx=am=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};Yx=am=l([_({type:A.Sequence})],Yx);var uf=`${fe}.15`,Nr;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(Nr||(Nr={}));var ys=class extends qr{toJSON(){let e=this.toNumber(),t=[];return e&Nr.cRLSign&&t.push("crlSign"),e&Nr.dataEncipherment&&t.push("dataEncipherment"),e&Nr.decipherOnly&&t.push("decipherOnly"),e&Nr.digitalSignature&&t.push("digitalSignature"),e&Nr.encipherOnly&&t.push("encipherOnly"),e&Nr.keyAgreement&&t.push("keyAgreement"),e&Nr.keyCertSign&&t.push("keyCertSign"),e&Nr.keyEncipherment&&t.push("keyEncipherment"),e&Nr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var cm,nL=`${fe}.30`,gs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};l([f({type:ae})],gs.prototype,"base",void 0);l([f({type:d.Integer,context:0,defaultValue:0,implicit:!0})],gs.prototype,"minimum",void 0);l([f({type:d.Integer,context:1,optional:!0,implicit:!0})],gs.prototype,"maximum",void 0);var ff=cm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};ff=cm=l([_({type:A.Sequence,itemType:gs})],ff);var pf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ff,context:0,optional:!0,implicit:!0})],pf.prototype,"permittedSubtrees",void 0);l([f({type:ff,context:1,optional:!0,implicit:!0})],pf.prototype,"excludedSubtrees",void 0);var lL=`${fe}.36`,hf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ge})],hf.prototype,"requireExplicitPolicy",void 0);l([f({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ge})],hf.prototype,"inhibitPolicyMapping",void 0);var lm,dL=`${fe}.33`,xc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],xc.prototype,"issuerDomainPolicy",void 0);l([f({type:d.ObjectIdentifier})],xc.prototype,"subjectDomainPolicy",void 0);var Zx=lm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};Zx=lm=l([_({type:A.Sequence,itemType:xc})],Zx);var um,fm=`${fe}.17`,df=um=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};df=um=l([_({type:A.Sequence})],df);var pt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],pt.prototype,"type",void 0);l([f({type:d.Any,repeated:"set"})],pt.prototype,"values",void 0);var pm,kL=`${fe}.9`,Jx=pm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,pm.prototype)}};Jx=pm=l([_({type:A.Sequence,itemType:pt})],Jx);var hm=`${fe}.14`,Mt=class extends ai{};var ML=`${fe}.16`,mf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],mf.prototype,"notBefore",void 0);l([f({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],mf.prototype,"notAfter",void 0);var bc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(bc||(bc={}));var yf=class extends qr{toJSON(){let e=[],t=this.toNumber();return t&bc.pKIXCertificate&&e.push("pKIXCertificate"),t&bc.newExtensions&&e.push("newExtensions"),t&bc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},gf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new yf,Object.assign(this,e)}};l([f({type:d.GeneralString})],gf.prototype,"entrustVers",void 0);l([f({type:yf})],gf.prototype,"entrustInfoFlags",void 0);var dm,zL=`${io}.11`,Qx=dm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,dm.prototype)}};Qx=dm=l([_({type:A.Sequence,itemType:bn})],Qx);var eb=Dr(dn()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&eb.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};l([f({type:d.ObjectIdentifier})],M.prototype,"algorithm",void 0);l([f({type:d.Any,optional:!0})],M.prototype,"parameters",void 0);var ht=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:M})],ht.prototype,"algorithm",void 0);l([f({type:d.BitString})],ht.prototype,"subjectPublicKey",void 0);var ze=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};l([f({type:d.UTCTime})],ze.prototype,"utcTime",void 0);l([f({type:d.GeneralizedTime})],ze.prototype,"generalTime",void 0);ze=l([_({type:A.Choice})],ze);var Sn=class{constructor(e){this.notBefore=new ze(new Date),this.notAfter=new ze(new Date),e&&(this.notBefore=new ze(e.notBefore),this.notAfter=new ze(e.notAfter))}};l([f({type:ze})],Sn.prototype,"notBefore",void 0);l([f({type:ze})],Sn.prototype,"notAfter",void 0);var mm,dt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new oe,Object.assign(this,e)}};dt.CRITICAL=!1;l([f({type:d.ObjectIdentifier})],dt.prototype,"extnID",void 0);l([f({type:d.Boolean,defaultValue:dt.CRITICAL})],dt.prototype,"critical",void 0);l([f({type:oe})],dt.prototype,"extnValue",void 0);var Jt=mm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};Jt=mm=l([_({type:A.Sequence,itemType:dt})],Jt);var Xr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(Xr||(Xr={}));var mt=class{constructor(e={}){this.version=Xr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new Ne,this.validity=new Sn,this.subject=new Ne,this.subjectPublicKeyInfo=new ht,Object.assign(this,e)}};l([f({type:d.Integer,context:0,defaultValue:Xr.v1})],mt.prototype,"version",void 0);l([f({type:d.Integer,converter:ge})],mt.prototype,"serialNumber",void 0);l([f({type:M})],mt.prototype,"signature",void 0);l([f({type:Ne})],mt.prototype,"issuer",void 0);l([f({type:Sn})],mt.prototype,"validity",void 0);l([f({type:Ne})],mt.prototype,"subject",void 0);l([f({type:ht})],mt.prototype,"subjectPublicKeyInfo",void 0);l([f({type:d.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);l([f({type:d.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);l([f({type:Jt,context:3,optional:!0})],mt.prototype,"extensions",void 0);var ur=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:mt})],ur.prototype,"tbsCertificate",void 0);l([f({type:M})],ur.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],ur.prototype,"signatureValue",void 0);var ui=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new ze,Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],ui.prototype,"userCertificate",void 0);l([f({type:ze})],ui.prototype,"revocationDate",void 0);l([f({type:dt,optional:!0,repeated:"sequence"})],ui.prototype,"crlEntryExtensions",void 0);var Qt=class{constructor(e={}){this.signature=new M,this.issuer=new Ne,this.thisUpdate=new ze,Object.assign(this,e)}};l([f({type:d.Integer,optional:!0})],Qt.prototype,"version",void 0);l([f({type:M})],Qt.prototype,"signature",void 0);l([f({type:Ne})],Qt.prototype,"issuer",void 0);l([f({type:ze})],Qt.prototype,"thisUpdate",void 0);l([f({type:ze,optional:!0})],Qt.prototype,"nextUpdate",void 0);l([f({type:ui,repeated:"sequence",optional:!0})],Qt.prototype,"revokedCertificates",void 0);l([f({type:dt,optional:!0,context:0,repeated:"sequence"})],Qt.prototype,"crlExtensions",void 0);var fi=class{constructor(e={}){this.tbsCertList=new Qt,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Qt})],fi.prototype,"tbsCertList",void 0);l([f({type:M})],fi.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],fi.prototype,"signature",void 0);var V=Dr(dn());var Or=class{constructor(e={}){this.issuer=new Ne,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Ne})],Or.prototype,"issuer",void 0);l([f({type:d.Integer,converter:ge})],Or.prototype,"serialNumber",void 0);var pi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Mt,context:0,implicit:!0})],pi.prototype,"subjectKeyIdentifier",void 0);l([f({type:Or})],pi.prototype,"issuerAndSerialNumber",void 0);pi=l([_({type:A.Choice})],pi);var yt;(function(r){r[r.v0=0]="v0",r[r.v1=1]="v1",r[r.v2=2]="v2",r[r.v3=3]="v3",r[r.v4=4]="v4",r[r.v5=5]="v5"})(yt||(yt={}));var hi=class extends M{};hi=l([_({type:A.Sequence})],hi);var vc=class extends M{};vc=l([_({type:A.Sequence})],vc);var Kt=class extends M{};Kt=l([_({type:A.Sequence})],Kt);var Ac=class extends M{};Ac=l([_({type:A.Sequence})],Ac);var rb=class extends M{};rb=l([_({type:A.Sequence})],rb);var wf=class extends M{};wf=l([_({type:A.Sequence})],wf);var Rr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Rr.prototype,"attrType",void 0);l([f({type:d.Any,repeated:"set"})],Rr.prototype,"attrValues",void 0);var ym,Ht=class{constructor(e={}){this.version=yt.v0,this.sid=new pi,this.digestAlgorithm=new hi,this.signatureAlgorithm=new vc,this.signature=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],Ht.prototype,"version",void 0);l([f({type:pi})],Ht.prototype,"sid",void 0);l([f({type:hi})],Ht.prototype,"digestAlgorithm",void 0);l([f({type:Rr,repeated:"set",context:0,implicit:!0,optional:!0})],Ht.prototype,"signedAttrs",void 0);l([f({type:vc})],Ht.prototype,"signatureAlgorithm",void 0);l([f({type:oe})],Ht.prototype,"signature",void 0);l([f({type:Rr,repeated:"set",context:1,implicit:!0,optional:!0})],Ht.prototype,"unsignedAttrs",void 0);var Sc=ym=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ym.prototype)}};Sc=ym=l([_({type:A.Set,itemType:Ht})],Sc);var nb=class extends ze{};nb=l([_({type:A.Choice})],nb);var ob=class extends Ht{};ob=l([_({type:A.Sequence})],ob);var Ec=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};l([f({type:ae})],Ec.prototype,"acIssuer",void 0);l([f({type:d.Integer})],Ec.prototype,"acSerial",void 0);l([f({type:pt,repeated:"sequence"})],Ec.prototype,"attrs",void 0);var gm,_c=gm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};_c=gm=l([_({type:A.Sequence,itemType:d.ObjectIdentifier})],_c);var ws=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};l([f({type:d.Integer,optional:!0})],ws.prototype,"pathLenConstraint",void 0);l([f({type:_c,implicit:!0,context:0,optional:!0})],ws.prototype,"permittedAttrs",void 0);l([f({type:_c,implicit:!0,context:1,optional:!0})],ws.prototype,"excludedAttrs",void 0);l([f({type:d.Boolean,defaultValue:!0})],ws.prototype,"permitUnSpecified",void 0);var fr=class{constructor(e={}){this.issuer=new Ve,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Ve})],fr.prototype,"issuer",void 0);l([f({type:d.Integer,converter:ge})],fr.prototype,"serial",void 0);l([f({type:d.BitString,optional:!0})],fr.prototype,"issuerUID",void 0);var wm;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(wm||(wm={}));var pr=class{constructor(e={}){this.digestedObjectType=wm.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Enumerated})],pr.prototype,"digestedObjectType",void 0);l([f({type:d.ObjectIdentifier,optional:!0})],pr.prototype,"otherObjectTypeID",void 0);l([f({type:M})],pr.prototype,"digestAlgorithm",void 0);l([f({type:d.BitString})],pr.prototype,"objectDigest",void 0);var di=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Ve,optional:!0})],di.prototype,"issuerName",void 0);l([f({type:fr,context:0,implicit:!0,optional:!0})],di.prototype,"baseCertificateID",void 0);l([f({type:pr,context:1,implicit:!0,optional:!0})],di.prototype,"objectDigestInfo",void 0);var mi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,repeated:"sequence"})],mi.prototype,"v1Form",void 0);l([f({type:di,context:0,implicit:!0})],mi.prototype,"v2Form",void 0);mi=l([_({type:A.Choice})],mi);var yi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};l([f({type:d.GeneralizedTime})],yi.prototype,"notBeforeTime",void 0);l([f({type:d.GeneralizedTime})],yi.prototype,"notAfterTime",void 0);var ao=class{constructor(e={}){Object.assign(this,e)}};l([f({type:fr,implicit:!0,context:0,optional:!0})],ao.prototype,"baseCertificateID",void 0);l([f({type:Ve,implicit:!0,context:1,optional:!0})],ao.prototype,"entityName",void 0);l([f({type:pr,implicit:!0,context:2,optional:!0})],ao.prototype,"objectDigestInfo",void 0);var xm;(function(r){r[r.v2=1]="v2"})(xm||(xm={}));var Vt=class{constructor(e={}){this.version=xm.v2,this.holder=new ao,this.issuer=new mi,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new yi,this.attributes=[],Object.assign(this,e)}};l([f({type:d.Integer})],Vt.prototype,"version",void 0);l([f({type:ao})],Vt.prototype,"holder",void 0);l([f({type:mi})],Vt.prototype,"issuer",void 0);l([f({type:M})],Vt.prototype,"signature",void 0);l([f({type:d.Integer,converter:ge})],Vt.prototype,"serialNumber",void 0);l([f({type:yi})],Vt.prototype,"attrCertValidityPeriod",void 0);l([f({type:pt,repeated:"sequence"})],Vt.prototype,"attributes",void 0);l([f({type:d.BitString,optional:!0})],Vt.prototype,"issuerUniqueID",void 0);l([f({type:Jt,optional:!0})],Vt.prototype,"extensions",void 0);var gi=class{constructor(e={}){this.acinfo=new Vt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:Vt})],gi.prototype,"acinfo",void 0);l([f({type:M})],gi.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],gi.prototype,"signatureValue",void 0);var Cc;(function(r){r[r.unmarked=1]="unmarked",r[r.unclassified=2]="unclassified",r[r.restricted=4]="restricted",r[r.confidential=8]="confidential",r[r.secret=16]="secret",r[r.topSecret=32]="topSecret"})(Cc||(Cc={}));var xs=class extends qr{};var bs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier,implicit:!0,context:0})],bs.prototype,"type",void 0);l([f({type:d.Any,implicit:!0,context:1})],bs.prototype,"value",void 0);var Ic=class{constructor(e={}){this.policyId="",this.classList=new xs(Cc.unclassified),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Ic.prototype,"policyId",void 0);l([f({type:xs,defaultValue:new xs(Cc.unclassified)})],Ic.prototype,"classList",void 0);l([f({type:bs,repeated:"set"})],Ic.prototype,"securityCategories",void 0);var vs=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe})],vs.prototype,"cotets",void 0);l([f({type:d.ObjectIdentifier})],vs.prototype,"oid",void 0);l([f({type:d.Utf8String})],vs.prototype,"string",void 0);var xf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};l([f({type:Ve,implicit:!0,context:0,optional:!0})],xf.prototype,"policyAuthority",void 0);l([f({type:vs,repeated:"sequence"})],xf.prototype,"values",void 0);var Tj=`${io}.4`,Bj=`${io}.6`,kj=`${io}.10`,Pj=`${fe}.55`,Tc=`${oo}.10`,Nj=`${Tc}.1`,Oj=`${Tc}.2`,Rj=`${Tc}.3`,Lj=`${Tc}.4`,Dj=`${Tc}.6`,bm="2.5.4",Uj=`${bm}.72`;var vm,As=class{constructor(e={}){this.targetCertificate=new fr,Object.assign(this,e)}};l([f({type:fr})],As.prototype,"targetCertificate",void 0);l([f({type:ae,optional:!0})],As.prototype,"targetName",void 0);l([f({type:pr,optional:!0})],As.prototype,"certDigestInfo",void 0);var Ss=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ae,context:0,implicit:!0})],Ss.prototype,"targetName",void 0);l([f({type:ae,context:1,implicit:!0})],Ss.prototype,"targetGroup",void 0);l([f({type:As,context:2,implicit:!0})],Ss.prototype,"targetCert",void 0);Ss=l([_({type:A.Choice})],Ss);var bf=vm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,vm.prototype)}};bf=vm=l([_({type:A.Sequence,itemType:Ss})],bf);var Am,ib=Am=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Am.prototype)}};ib=Am=l([_({type:A.Sequence,itemType:bf})],ib);var vf=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Ve,implicit:!0,context:0,optional:!0})],vf.prototype,"roleAuthority",void 0);l([f({type:ae,implicit:!0,context:1})],vf.prototype,"roleName",void 0);var Bc=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};l([f({type:ae})],Bc.prototype,"service",void 0);l([f({type:ae})],Bc.prototype,"ident",void 0);l([f({type:oe,optional:!0})],Bc.prototype,"authInfo",void 0);var Sm,kc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],kc.prototype,"otherCertFormat",void 0);l([f({type:d.Any})],kc.prototype,"otherCert",void 0);var wi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:ur})],wi.prototype,"certificate",void 0);l([f({type:gi,context:2,implicit:!0})],wi.prototype,"v2AttrCert",void 0);l([f({type:kc,context:3,implicit:!0})],wi.prototype,"other",void 0);wi=l([_({type:A.Choice})],wi);var xi=Sm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Sm.prototype)}};xi=Sm=l([_({type:A.Set,itemType:wi})],xi);var hr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],hr.prototype,"contentType",void 0);l([f({type:d.Any,context:0})],hr.prototype,"content",void 0);var Es=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe})],Es.prototype,"single",void 0);l([f({type:d.Any})],Es.prototype,"any",void 0);Es=l([_({type:A.Choice})],Es);var bi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],bi.prototype,"eContentType",void 0);l([f({type:Es,context:0,optional:!0})],bi.prototype,"eContent",void 0);var Pc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:oe,context:0,implicit:!0,optional:!0})],Pc.prototype,"value",void 0);l([f({type:oe,converter:Rx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Pc.prototype,"constructedValue",void 0);Pc=l([_({type:A.Choice})],Pc);var co=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Ac,Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],co.prototype,"contentType",void 0);l([f({type:Ac})],co.prototype,"contentEncryptionAlgorithm",void 0);l([f({type:Pc,optional:!0})],co.prototype,"encryptedContent",void 0);var lo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],lo.prototype,"keyAttrId",void 0);l([f({type:d.Any,optional:!0})],lo.prototype,"keyAttr",void 0);var Em,_s=class{constructor(e={}){this.subjectKeyIdentifier=new Mt,Object.assign(this,e)}};l([f({type:Mt})],_s.prototype,"subjectKeyIdentifier",void 0);l([f({type:d.GeneralizedTime,optional:!0})],_s.prototype,"date",void 0);l([f({type:lo,optional:!0})],_s.prototype,"other",void 0);var Cs=class{constructor(e={}){Object.assign(this,e)}};l([f({type:_s,context:0,implicit:!0,optional:!0})],Cs.prototype,"rKeyId",void 0);l([f({type:Or,optional:!0})],Cs.prototype,"issuerAndSerialNumber",void 0);Cs=l([_({type:A.Choice})],Cs);var Nc=class{constructor(e={}){this.rid=new Cs,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:Cs})],Nc.prototype,"rid",void 0);l([f({type:oe})],Nc.prototype,"encryptedKey",void 0);var Af=Em=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Em.prototype)}};Af=Em=l([_({type:A.Sequence,itemType:Nc})],Af);var Oc=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:M})],Oc.prototype,"algorithm",void 0);l([f({type:d.BitString})],Oc.prototype,"publicKey",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Mt,context:0,implicit:!0,optional:!0})],vi.prototype,"subjectKeyIdentifier",void 0);l([f({type:Oc,context:1,implicit:!0,optional:!0})],vi.prototype,"originatorKey",void 0);l([f({type:Or,optional:!0})],vi.prototype,"issuerAndSerialNumber",void 0);vi=l([_({type:A.Choice})],vi);var En=class{constructor(e={}){this.version=yt.v3,this.originator=new vi,this.keyEncryptionAlgorithm=new Kt,this.recipientEncryptedKeys=new Af,Object.assign(this,e)}};l([f({type:d.Integer})],En.prototype,"version",void 0);l([f({type:vi,context:0})],En.prototype,"originator",void 0);l([f({type:oe,context:1,optional:!0})],En.prototype,"ukm",void 0);l([f({type:Kt})],En.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:Af})],En.prototype,"recipientEncryptedKeys",void 0);var Is=class{constructor(e={}){Object.assign(this,e)}};l([f({type:Mt,context:0,implicit:!0})],Is.prototype,"subjectKeyIdentifier",void 0);l([f({type:Or})],Is.prototype,"issuerAndSerialNumber",void 0);Is=l([_({type:A.Choice})],Is);var uo=class{constructor(e={}){this.version=yt.v0,this.rid=new Is,this.keyEncryptionAlgorithm=new Kt,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],uo.prototype,"version",void 0);l([f({type:Is})],uo.prototype,"rid",void 0);l([f({type:Kt})],uo.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],uo.prototype,"encryptedKey",void 0);var Ai=class{constructor(e={}){this.keyIdentifier=new oe,Object.assign(this,e)}};l([f({type:oe})],Ai.prototype,"keyIdentifier",void 0);l([f({type:d.GeneralizedTime,optional:!0})],Ai.prototype,"date",void 0);l([f({type:lo,optional:!0})],Ai.prototype,"other",void 0);var fo=class{constructor(e={}){this.version=yt.v4,this.kekid=new Ai,this.keyEncryptionAlgorithm=new Kt,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],fo.prototype,"version",void 0);l([f({type:Ai})],fo.prototype,"kekid",void 0);l([f({type:Kt})],fo.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],fo.prototype,"encryptedKey",void 0);var po=class{constructor(e={}){this.version=yt.v0,this.keyEncryptionAlgorithm=new Kt,this.encryptedKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],po.prototype,"version",void 0);l([f({type:wf,context:0,optional:!0})],po.prototype,"keyDerivationAlgorithm",void 0);l([f({type:Kt})],po.prototype,"keyEncryptionAlgorithm",void 0);l([f({type:oe})],po.prototype,"encryptedKey",void 0);var Rc=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Rc.prototype,"oriType",void 0);l([f({type:d.Any})],Rc.prototype,"oriValue",void 0);var _n=class{constructor(e={}){Object.assign(this,e)}};l([f({type:uo,optional:!0})],_n.prototype,"ktri",void 0);l([f({type:En,context:1,implicit:!0,optional:!0})],_n.prototype,"kari",void 0);l([f({type:fo,context:2,implicit:!0,optional:!0})],_n.prototype,"kekri",void 0);l([f({type:po,context:3,implicit:!0,optional:!0})],_n.prototype,"pwri",void 0);l([f({type:Rc,context:4,implicit:!0,optional:!0})],_n.prototype,"ori",void 0);_n=l([_({type:A.Choice})],_n);var _m,Lc=_m=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};Lc=_m=l([_({type:A.Set,itemType:_n})],Lc);var Cm,sb=`${oo}.16`,DK=`${sb}.2`,UK=`${sb}.4`,Ts=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Ts.prototype,"otherRevInfoFormat",void 0);l([f({type:d.Any})],Ts.prototype,"otherRevInfo",void 0);var Sf=class{constructor(e={}){this.other=new Ts,Object.assign(this,e)}};l([f({type:Ts,context:1,implicit:!0})],Sf.prototype,"other",void 0);Sf=l([_({type:A.Choice})],Sf);var Bs=Cm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Cm.prototype)}};Bs=Cm=l([_({type:A.Set,itemType:Sf})],Bs);var ks=class{constructor(e={}){Object.assign(this,e)}};l([f({type:xi,context:0,implicit:!0,optional:!0})],ks.prototype,"certs",void 0);l([f({type:Bs,context:1,implicit:!0,optional:!0})],ks.prototype,"crls",void 0);var Im,Tm=Im=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Im.prototype)}};Tm=Im=l([_({type:A.Set,itemType:Rr})],Tm);var Si=class{constructor(e={}){this.version=yt.v0,this.recipientInfos=new Lc,this.encryptedContentInfo=new co,Object.assign(this,e)}};l([f({type:d.Integer})],Si.prototype,"version",void 0);l([f({type:ks,context:0,implicit:!0,optional:!0})],Si.prototype,"originatorInfo",void 0);l([f({type:Lc})],Si.prototype,"recipientInfos",void 0);l([f({type:co})],Si.prototype,"encryptedContentInfo",void 0);l([f({type:Tm,context:1,implicit:!0,optional:!0})],Si.prototype,"unprotectedAttrs",void 0);var ab="1.2.840.113549.1.7.2";var Bm,Ef=Bm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Bm.prototype)}};Ef=Bm=l([_({type:A.Set,itemType:hi})],Ef);var Cn=class{constructor(e={}){this.version=yt.v0,this.digestAlgorithms=new Ef,this.encapContentInfo=new bi,this.signerInfos=new Sc,Object.assign(this,e)}};l([f({type:d.Integer})],Cn.prototype,"version",void 0);l([f({type:Ef})],Cn.prototype,"digestAlgorithms",void 0);l([f({type:bi})],Cn.prototype,"encapContentInfo",void 0);l([f({type:xi,context:0,implicit:!0,optional:!0})],Cn.prototype,"certificates",void 0);l([f({type:Bs,context:1,implicit:!0,optional:!0})],Cn.prototype,"crls",void 0);l([f({type:Sc})],Cn.prototype,"signerInfos",void 0);var Ei="1.2.840.10045.2.1";var Dc="1.2.840.10045.4.1",_f="1.2.840.10045.4.3.1",Uc="1.2.840.10045.4.3.2",jc="1.2.840.10045.4.3.3",Mc="1.2.840.10045.4.3.4";var km="1.2.840.10045.3.1.7";var Pm="1.3.132.0.34";var Nm="1.3.132.0.35";function Kc(r){return new M({algorithm:r})}var lb=Kc(Dc),OH=Kc(_f),ub=Kc(Uc),fb=Kc(jc),pb=Kc(Mc);var Hc=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Hc.prototype,"fieldType",void 0);l([f({type:d.Any})],Hc.prototype,"parameters",void 0);Hc=l([_({type:A.Sequence})],Hc);var Om=class extends oe{};var Ps=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.OctetString})],Ps.prototype,"a",void 0);l([f({type:d.OctetString})],Ps.prototype,"b",void 0);l([f({type:d.BitString,optional:!0})],Ps.prototype,"seed",void 0);Ps=l([_({type:A.Sequence})],Ps);var Rm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Rm||(Rm={}));var Yr=class{constructor(e={}){this.version=Rm.ecpVer1,Object.assign(this,e)}};l([f({type:d.Integer})],Yr.prototype,"version",void 0);l([f({type:Hc})],Yr.prototype,"fieldID",void 0);l([f({type:Ps})],Yr.prototype,"curve",void 0);l([f({type:Om})],Yr.prototype,"base",void 0);l([f({type:d.Integer,converter:ge})],Yr.prototype,"order",void 0);l([f({type:d.Integer,optional:!0})],Yr.prototype,"cofactor",void 0);Yr=l([_({type:A.Sequence})],Yr);var Zr=class{constructor(e={}){Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Zr.prototype,"namedCurve",void 0);l([f({type:d.Null})],Zr.prototype,"implicitCurve",void 0);l([f({type:Yr})],Zr.prototype,"specifiedCurve",void 0);Zr=l([_({type:A.Choice})],Zr);var Ns=class{constructor(e={}){this.version=1,this.privateKey=new oe,Object.assign(this,e)}};l([f({type:d.Integer})],Ns.prototype,"version",void 0);l([f({type:oe})],Ns.prototype,"privateKey",void 0);l([f({type:Zr,context:0,optional:!0})],Ns.prototype,"parameters",void 0);l([f({type:d.BitString,context:1,optional:!0})],Ns.prototype,"publicKey",void 0);var _i=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],_i.prototype,"r",void 0);l([f({type:d.Integer,converter:ge})],_i.prototype,"s",void 0);var $t="1.2.840.113549.1.1",Jr=`${$t}.1`,hb=`${$t}.7`,db=`${$t}.9`,ho=`${$t}.10`,mb=`${$t}.2`,yb=`${$t}.4`,Os=`${$t}.5`,gb=`${$t}.14`;var Cf=`${$t}.11`,Rs=`${$t}.12`,Ls=`${$t}.13`,Lm=`${$t}.15`,Dm=`${$t}.16`,Ci="1.3.14.3.2.26",If="2.16.840.1.101.3.4.2.4",Ii="2.16.840.1.101.3.4.2.1",Ti="2.16.840.1.101.3.4.2.2",Bi="2.16.840.1.101.3.4.2.3",wb="2.16.840.1.101.3.4.2.5",xb="2.16.840.1.101.3.4.2.6",bb="1.2.840.113549.2.2",vb="1.2.840.113549.2.5",mo=`${$t}.8`;function lt(r){return new M({algorithm:r,parameters:null})}var a7=lt(bb),c7=lt(vb),In=lt(Ci),l7=lt(If),u7=lt(Ii),f7=lt(Ti),p7=lt(Bi),h7=lt(wb),d7=lt(xb),Tf=new M({algorithm:mo,parameters:F.serialize(In)}),Um=new M({algorithm:db,parameters:F.serialize(hs.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),m7=lt(Jr),y7=lt(mb),g7=lt(yb),w7=lt(Os),x7=lt(Lm),b7=lt(Dm),v7=lt(Rs),A7=lt(Ls),S7=lt(Lm),E7=lt(Dm);var Ds=class{constructor(e={}){this.hashAlgorithm=new M(In),this.maskGenAlgorithm=new M({algorithm:mo,parameters:F.serialize(In)}),this.pSourceAlgorithm=new M(Um),Object.assign(this,e)}};l([f({type:M,context:0,defaultValue:In})],Ds.prototype,"hashAlgorithm",void 0);l([f({type:M,context:1,defaultValue:Tf})],Ds.prototype,"maskGenAlgorithm",void 0);l([f({type:M,context:2,defaultValue:Um})],Ds.prototype,"pSourceAlgorithm",void 0);var P7=new M({algorithm:hb,parameters:F.serialize(new Ds)});var Qr=class{constructor(e={}){this.hashAlgorithm=new M(In),this.maskGenAlgorithm=new M({algorithm:mo,parameters:F.serialize(In)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};l([f({type:M,context:0,defaultValue:In})],Qr.prototype,"hashAlgorithm",void 0);l([f({type:M,context:1,defaultValue:Tf})],Qr.prototype,"maskGenAlgorithm",void 0);l([f({type:d.Integer,context:2,defaultValue:20})],Qr.prototype,"saltLength",void 0);l([f({type:d.Integer,context:3,defaultValue:1})],Qr.prototype,"trailerField",void 0);var j7=new M({algorithm:ho,parameters:F.serialize(new Qr)});var ki=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new oe,Object.assign(this,e)}};l([f({type:M})],ki.prototype,"digestAlgorithm",void 0);l([f({type:oe})],ki.prototype,"digest",void 0);var jm,Us=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],Us.prototype,"prime",void 0);l([f({type:d.Integer,converter:ge})],Us.prototype,"exponent",void 0);l([f({type:d.Integer,converter:ge})],Us.prototype,"coefficient",void 0);var Bf=jm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,jm.prototype)}};Bf=jm=l([_({type:A.Sequence,itemType:Us})],Bf);var dr=class{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer})],dr.prototype,"version",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"modulus",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"publicExponent",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"privateExponent",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"prime1",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"prime2",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"exponent1",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"exponent2",void 0);l([f({type:d.Integer,converter:ge})],dr.prototype,"coefficient",void 0);l([f({type:Bf,optional:!0})],dr.prototype,"otherPrimeInfos",void 0);var js=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.Integer,converter:ge})],js.prototype,"modulus",void 0);l([f({type:d.Integer,converter:ge})],js.prototype,"publicExponent",void 0);var Mm;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Mm||(Mm={}));var gt=Mm;var $b=Dr(Vb(),1),{__extends:Ks,__assign:mV,__rest:X_,__decorate:yV,__param:gV,__metadata:wV,__awaiter:Fb,__generator:Wb,__exportStar:xV,__createBinding:bV,__values:Vc,__read:$c,__spread:Lr,__spreadArrays:vV,__await:AV,__asyncGenerator:SV,__asyncDelegator:EV,__asyncValues:_V,__makeTemplateObject:CV,__importStar:IV,__importDefault:TV,__classPrivateFieldGet:BV,__classPrivateFieldSet:kV}=$b.default;var Y_="injectionTokens";function Hm(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(Y_,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function Fc(r){return!!r.useClass}function Hs(r){return!!r.useFactory}var Nf=function(){function r(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return r.prototype.createProxy=function(e){var t=this,n={},o=!1,i,s=function(){return o||(i=e(t.wrap()),o=!0),i};return new Proxy(n,this.createHandler(s))},r.prototype.createHandler=function(e){var t={},n=function(o){t[o]=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];i[0]=e();var a=Reflect[o];return a.apply(void 0,Lr(i))}};return this.reflectMethods.forEach(n),t},r}();function yo(r){return typeof r=="string"||typeof r=="symbol"}function Vm(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Of(r){return typeof r=="object"&&"token"in r&&"transform"in r}function qb(r){return typeof r=="function"||r instanceof Nf}function Pi(r){return!!r.useToken}function Ni(r){return r.useValue!=null}function Gb(r){return Fc(r)||Ni(r)||Pi(r)||Hs(r)}var Z_=function(){function r(){this._registryMap=new Map}return r.prototype.entries=function(){return this._registryMap.entries()},r.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},r.prototype.get=function(e){this.ensure(e);var t=this._registryMap.get(e);return t[t.length-1]||null},r.prototype.set=function(e,t){this.ensure(e),this._registryMap.get(e).push(t)},r.prototype.setAll=function(e,t){this._registryMap.set(e,t)},r.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},r.prototype.clear=function(){this._registryMap.clear()},r.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},r}(),Wc=Z_;var J_=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Wc),zb=J_;var Q_=function(){function r(){this.scopedResolutions=new Map}return r}(),qc=Q_;function eC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function tC(r,e,t){return t===void 0&&(t=" "),Lr([r],e.message.split(`
7
7
  `).map(function(n){return t+n})).join(`
8
- `)}function qm(r,e,t){var n=Vc(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=uC(i,e);return fC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function nv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var pC=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Fc);var hC=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Fc);var dC=function(){function r(){this.preResolution=new pC,this.postResolution=new hC}return r}(),ov=dC;var Gm=new Map,mC=function(){function r(e){this.parent=e,this._registry=new rv,this.interceptors=new ov,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:gt.Transient}),this.ensureNotDisposed();var o;if(tv(t)?o=t:o={useClass:t},Ni(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Lr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Ni(c.provider)?s=c.provider:s=null}if((n.lifecycle===gt.Singleton||n.lifecycle==gt.ContainerScoped||n.lifecycle==gt.ResolutionScoped)&&(Pi(o)||Hs(o)))throw new Error('Cannot use lifecycle "'+gt[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:o,options:n}),this},r.prototype.registerType=function(e,t){return this.ensureNotDisposed(),go(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},r.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},r.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),go(e)){if(go(t))return this.register(e,{useToken:t},{lifecycle:gt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:gt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!go(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:gt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new Wc),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&go(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),o){var i=this.resolveRegistration(o,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(ev(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=Hc(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Hc(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var u=c.value;u.options.frequency!="Once"&&s.push(u),u.callback(e,t,n)}}catch(h){o={error:h}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===gt.Singleton,o=e.options.lifecycle===gt.ContainerScoped,i=n||o,s;return Pi(e.provider)?s=e.provider.useValue:Ni(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):$c(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Hs(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new Wc),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&go(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=Hc(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Vc(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Pi(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=Hc(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Vc(i.value,2),a=s[0],c=s[1];c.some(function(u){var h=u.options;return h.lifecycle===gt.ContainerScoped})&&n._registry.setAll(a,c.map(function(u){return u.options.lifecycle===gt.ContainerScoped?{provider:u.provider,options:u.options}:u}))}}catch(u){e={error:u}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},r.prototype.beforeResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:n})},r.prototype.afterResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:n})},r.prototype.dispose=function(){return Jb(this,void 0,void 0,function(){var e;return Qb(this,function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var o=n.dispose();o&&e.push(o)}),[4,Promise.all(e)];case 1:return t.sent(),[2]}})})},r.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},r.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},r.prototype.construct=function(e,t){var n=this;if(e instanceof Nf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=Gm.get(e);if(!i||i.length===0){if(e.length===0)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var s=i.map(n.resolveParams(t,e));return new(e.bind.apply(e,Lr([void 0],s)))}();return nv(o)&&this.disposables.add(o),o},r.prototype.resolveParams=function(e,t){var n=this;return function(o,i){var s,a,c;try{return Wm(o)?Pf(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Lr([n.resolveAll(o.token,new Wc,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Lr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new Wc,o.isOptional):n.resolve(o.token,e,o.isOptional):Pf(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Lr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(u){throw new Error(qm(t,i,u))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r}(),Fe=new mC;function yC(){return function(r){Gm.set(r,Fm(r))}}var wo=yC;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var Xm,Oi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};l([f({type:d.ObjectIdentifier})],Oi.prototype,"attrId",void 0);l([f({type:d.Any,repeated:"set"})],Oi.prototype,"attrValues",void 0);var iv=Xm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};iv=Xm=l([_({type:A.Sequence,itemType:Oi})],iv);var Ym,sv=Ym=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Ym.prototype)}};sv=Ym=l([_({type:A.Sequence,itemType:hr})],sv);var gC="1.2.840.113549",wC=`${gC}.1`,av=`${wC}.12`,Vs=`${av}.1`,YF=`${Vs}.1`,ZF=`${Vs}.2`,JF=`${Vs}.3`,QF=`${Vs}.4`,eW=`${Vs}.5`,tW=`${Vs}.6`,Ri=`${av}.10.1`;var oW=`${Ri}.1`,iW=`${Ri}.2`,sW=`${Ri}.3`,aW=`${Ri}.4`,cW=`${Ri}.5`,lW=`${Ri}.6`,Of="1.2.840.113549.1.9";var Rf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Rf.prototype,"certId",void 0);l([f({type:d.Any,context:0})],Rf.prototype,"certValue",void 0);var cv=`${Of}.22`,dW=`${cv}.1`,mW=`${cv}.2`;var Lf=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Lf.prototype,"crlId",void 0);l([f({type:d.Any,context:0})],Lf.prototype,"crltValue",void 0);var xC=`${Of}.23`,bW=`${xC}.1`;var Df=class extends oe{},xo=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Df,Object.assign(this,e)}};l([f({type:M})],xo.prototype,"encryptionAlgorithm",void 0);l([f({type:Df})],xo.prototype,"encryptedData",void 0);var Zm,Jm;(function(r){r[r.v1=0]="v1"})(Jm||(Jm={}));var Uf=class extends oe{},Qm=Zm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Zm.prototype)}};Qm=Zm=l([_({type:A.Sequence,itemType:pt})],Qm);var bo=class{constructor(e={}){this.version=Jm.v1,this.privateKeyAlgorithm=new M,this.privateKey=new Uf,Object.assign(this,e)}};l([f({type:d.Integer})],bo.prototype,"version",void 0);l([f({type:M})],bo.prototype,"privateKeyAlgorithm",void 0);l([f({type:Uf})],bo.prototype,"privateKey",void 0);l([f({type:Qm,implicit:!0,context:0,optional:!0})],bo.prototype,"attributes",void 0);var lv=class extends bo{};lv=l([_({type:A.Sequence})],lv);var uv=class extends xo{};uv=l([_({type:A.Sequence})],uv);var jf=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],jf.prototype,"secretTypeId",void 0);l([f({type:d.Any,context:0})],jf.prototype,"secretValue",void 0);var vo=class{constructor(e={}){this.mac=new ki,this.macSalt=new oe,this.iterations=1,Object.assign(this,e)}};l([f({type:ki})],vo.prototype,"mac",void 0);l([f({type:oe})],vo.prototype,"macSalt",void 0);l([f({type:d.Integer,defaultValue:1})],vo.prototype,"iterations",void 0);var Li=class{constructor(e={}){this.version=3,this.authSafe=new hr,this.macData=new vo,Object.assign(this,e)}};l([f({type:d.Integer})],Li.prototype,"version",void 0);l([f({type:hr})],Li.prototype,"authSafe",void 0);l([f({type:vo,optional:!0})],Li.prototype,"macData",void 0);var ey,$s=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],$s.prototype,"bagId",void 0);l([f({type:d.Any,context:0})],$s.prototype,"bagValue",void 0);l([f({type:Oi,repeated:"set",optional:!0})],$s.prototype,"bagAttributes",void 0);var fv=ey=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ey.prototype)}};fv=ey=l([_({type:A.Sequence,itemType:$s})],fv);var ty,ry,ny,Xe="1.2.840.113549.1.9",Aq=`${Xe}.0`,_v=`${Xe}.24`,Gc=`${Xe}.25`,Cv=`${Xe}.26`,Iv=`${Xe}.27`,Sq=`${_v}.1`,Eq=`${_v}.2`,_q=`${Xe}.1`,Cq=`${Xe}.2`,Iq=`${Xe}.3`,Tq=`${Xe}.4`,Bq=`${Xe}.5`,kq=`${Xe}.6`,fy=`${Xe}.7`,Nq=`${Xe}.8`,Pq=`${Xe}.9`,Oq=`${Xe}.13`,zc=`${Xe}.14`,Rq=`${Xe}.15`,Lq=`${Xe}.20`,Dq=`${Xe}.21`;var Uq=`${Gc}.1`,jq=`${Gc}.2`,Mq=`${Gc}.3`,Kq=`${Gc}.4`,Hq=`${Gc}.5`,Xc="1.3.6.1.5.5.7.9",Vq=`${Xc}.1`,$q=`${Xc}.2`,Fq=`${Xc}.3`,Wq=`${Xc}.4`,qq=`${Xc}.5`,Gq=`${Cv}.1`,zq=`${Cv}.2`,Xq=`${Iv}.1`,Yq=`${Iv}.2`,Zq=`${Xe}.16`,Jq=`${Xe}.22`,Qq=`${Xe}.23`,eG=`${Sm}.65`,Mf=class extends nt{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};l([f({type:d.IA5String})],Mf.prototype,"ia5String",void 0);Mf=l([_({type:A.Choice})],Mf);var pv=class extends hr{};pv=l([_({type:A.Sequence})],pv);var hv=class extends Li{};hv=l([_({type:A.Sequence})],hv);var dv=class extends xo{};dv=l([_({type:A.Sequence})],dv);var oy=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.IA5String})],oy.prototype,"value",void 0);oy=l([_({type:A.Choice})],oy);var mv=class extends Mf{};mv=l([_({type:A.Choice})],mv);var yv=class extends nt{};yv=l([_({type:A.Choice})],yv);var iy=class{constructor(e=new Date){this.value=e}};l([f({type:d.GeneralizedTime})],iy.prototype,"value",void 0);iy=l([_({type:A.Choice})],iy);var gv=class extends nt{};gv=l([_({type:A.Choice})],gv);var sy=class{constructor(e="M"){this.value=e}toString(){return this.value}};l([f({type:d.PrintableString})],sy.prototype,"value",void 0);sy=l([_({type:A.Choice})],sy);var Kf=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.PrintableString})],Kf.prototype,"value",void 0);Kf=l([_({type:A.Choice})],Kf);var wv=class extends Kf{};wv=l([_({type:A.Choice})],wv);var xv=class extends nt{};xv=l([_({type:A.Choice})],xv);var ay=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.ObjectIdentifier})],ay.prototype,"value",void 0);ay=l([_({type:A.Choice})],ay);var bv=class extends ze{};bv=l([_({type:A.Choice})],bv);var cy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};l([f({type:d.Integer})],cy.prototype,"value",void 0);cy=l([_({type:A.Choice})],cy);var vv=class extends Ft{};vv=l([_({type:A.Sequence})],vv);var qc=class extends nt{};qc=l([_({type:A.Choice})],qc);var Av=ty=class extends er{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};Av=ty=l([_({type:A.Sequence})],Av);var Sv=ry=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};Sv=ry=l([_({type:A.Set,itemType:Rr})],Sv);var ly=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.BmpString})],ly.prototype,"value",void 0);ly=l([_({type:A.Choice})],ly);var uy=class extends M{};uy=l([_({type:A.Sequence})],uy);var Ev=ny=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};Ev=ny=l([_({type:A.Sequence,itemType:uy})],Ev);var py,Yc=py=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};Yc=py=l([_({type:A.Sequence,itemType:pt})],Yc);var en=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new ht,this.attributes=new Yc,Object.assign(this,e)}};l([f({type:d.Integer})],en.prototype,"version",void 0);l([f({type:Pe})],en.prototype,"subject",void 0);l([f({type:ht})],en.prototype,"subjectPKInfo",void 0);l([f({type:Yc,implicit:!0,context:0})],en.prototype,"attributes",void 0);var Ao=class{constructor(e={}){this.certificationRequestInfo=new en,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:en})],Ao.prototype,"certificationRequestInfo",void 0);l([f({type:M})],Ao.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],Ao.prototype,"signature",void 0);var rl="crypto.algorithm",Ay=class{getAlgorithms(){return Fe.resolveAll(rl)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Di="crypto.algorithmProvider";Fe.registerSingleton(Di,Ay);var Ff,Xt="1.3.36.3.3.2.8.1.1",Tv=`${Xt}.1`,Bv=`${Xt}.2`,kv=`${Xt}.3`,Nv=`${Xt}.4`,Pv=`${Xt}.5`,Ov=`${Xt}.6`,Rv=`${Xt}.7`,Lv=`${Xt}.8`,Dv=`${Xt}.9`,Uv=`${Xt}.10`,jv=`${Xt}.11`,Mv=`${Xt}.12`,Kv=`${Xt}.13`,Hv=`${Xt}.14`,Vv="brainpoolP160r1",$v="brainpoolP160t1",Fv="brainpoolP192r1",Wv="brainpoolP192t1",qv="brainpoolP224r1",Gv="brainpoolP224t1",zv="brainpoolP256r1",Xv="brainpoolP256t1",Yv="brainpoolP320r1",Zv="brainpoolP320t1",Jv="brainpoolP384r1",Qv="brainpoolP384t1",e1="brainpoolP512r1",t1="brainpoolP512t1",We="ECDSA",Jc=Ff=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case We.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return gb;case"sha-256":return wb;case"sha-384":return xb;case"sha-512":return bb}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Om;break;case"K-256":t=Ff.SECP256K1;break;case"P-384":t=Rm;break;case"P-521":t=Lm;break;case Vv:t=Tv;break;case $v:t=Bv;break;case Fv:t=kv;break;case Wv:t=Nv;break;case qv:t=Pv;break;case Gv:t=Ov;break;case zv:t=Rv;break;case Xv:t=Lv;break;case Yv:t=Dv;break;case Zv:t=Uv;break;case Jv:t=jv;break;case Qv:t=Mv;break;case e1:t=Kv;break;case t1:t=Hv;break}if(t)return new M({algorithm:Ei,parameters:F.serialize(new Zr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Lc:return{name:We,hash:{name:"SHA-1"}};case Dc:return{name:We,hash:{name:"SHA-256"}};case Uc:return{name:We,hash:{name:"SHA-384"}};case jc:return{name:We,hash:{name:"SHA-512"}};case Ei:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,Zr).namedCurve){case Om:return{name:We,namedCurve:"P-256"};case Ff.SECP256K1:return{name:We,namedCurve:"K-256"};case Rm:return{name:We,namedCurve:"P-384"};case Lm:return{name:We,namedCurve:"P-521"};case Tv:return{name:We,namedCurve:Vv};case Bv:return{name:We,namedCurve:$v};case kv:return{name:We,namedCurve:Fv};case Nv:return{name:We,namedCurve:Wv};case Pv:return{name:We,namedCurve:qv};case Ov:return{name:We,namedCurve:Gv};case Rv:return{name:We,namedCurve:zv};case Lv:return{name:We,namedCurve:Xv};case Dv:return{name:We,namedCurve:Yv};case Uv:return{name:We,namedCurve:Zv};case jv:return{name:We,namedCurve:Jv};case Mv:return{name:We,namedCurve:Qv};case Kv:return{name:We,namedCurve:e1};case Hv:return{name:We,namedCurve:t1}}}}return null}};Jc.SECP256K1="1.3.132.0.10";Jc=Ff=l([wo()],Jc);Fe.registerSingleton(rl,Jc);var p1=Symbol("name"),h1=Symbol("value"),Se=class{constructor(e,t={},n=""){this[p1]=e,this[h1]=n;for(let o in t)this[o]=t[o]}};Se.NAME=p1;Se.VALUE=h1;var Sy=class{static toTextObject(e){let t=new Se("Algorithm Identifier",{},rn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Ei:{let n=new Jc().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},rn=class{static toString(e){let t=this.items[e];return t||e}};rn.items={[Ci]:"sha1",[Cf]:"sha224",[Ii]:"sha256",[Ti]:"sha384",[Bi]:"sha512",[Jr]:"rsaEncryption",[Os]:"sha1WithRSAEncryption",[_b]:"sha224WithRSAEncryption",[_f]:"sha256WithRSAEncryption",[Rs]:"sha384WithRSAEncryption",[Ls]:"sha512WithRSAEncryption",[Ei]:"ecPublicKey",[Lc]:"ecdsaWithSHA1",[Ef]:"ecdsaWithSHA224",[Dc]:"ecdsaWithSHA256",[Uc]:"ecdsaWithSHA384",[jc]:"ecdsaWithSHA512",[Zx]:"TLS WWW server authentication",[Jx]:"TLS WWW client authentication",[Qx]:"Code Signing",[eb]:"E-mail Protection",[tb]:"Time Stamping",[rb]:"OCSP Signing",[mb]:"Signed Data"};var Bn=class{static serialize(e){return this.serializeObj(e).join(`
9
- `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Se.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Se.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],u=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${u}${c}`);else if(c instanceof Date)n.push(`${o}${u}${c.toUTCString()}`);else if(Array.isArray(c))for(let h of c)h[Se.NAME]=a,n.push(...this.serializeObj(h,t));else if(c instanceof Se)c[Se.NAME]=a,n.push(...this.serializeObj(c,t));else if(V.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${u}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let h=c.toTextObject();h[Se.NAME]=a,n.push(...this.serializeObj(h,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=V.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let u=o[s++].toString(16).padStart(2,"0");a.push(u)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Bn.oidSerializer=rn;Bn.algorithmSerializer=Sy;var So=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=F.serialize(t),this.onInit(t)}else{let t=F.parse(e[0],e[1]);this.rawData=V.BufferSourceConverter.toArrayBuffer(e[0]),this.onInit(t)}}equal(e){return e instanceof r?(0,V.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return F.toString(this.rawData);case"text":return Bn.serialize(this.toTextObject());case"hex":return V.Convert.ToHex(this.rawData);case"base64":return V.Convert.ToBase64(this.rawData);case"base64url":return V.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new Se(this.getTextName(),{},e)}};So.NAME="ASN";var yr=class r extends So{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=F.serialize(new dt({extnID:e[0],critical:e[1],extnValue:new oe(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,dt)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[Se.NAME]===r.NAME&&(e[Se.NAME]=rn.toString(this.type)),e}},d1,Qc=class r{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[d1]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(r.DEFAULT,crypto):typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle&&this.set(r.DEFAULT,globalThis.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,t){return this.items.forEach(e,t)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=r.DEFAULT){let t=this.items.get(e.toLowerCase());if(!t)throw new Error(`Cannot get Crypto by name '${e}'`);return t}set(e,t){if(typeof e=="string"){if(!t)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),t)}else this.items.set(r.DEFAULT,e);return this}};d1=Symbol.toStringTag;Qc.DEFAULT="default";var wt=new Qc,SC=/^[0-2](?:\.[1-9][0-9]*)+$/;function EC(r){return new RegExp(SC).test(r)}var qf=class{constructor(e={}){this.items={};for(let t in e)this.register(t,e[t])}get(e){return this.items[e]||null}findId(e){return EC(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Gt=new qf;Gt.register("CN","2.5.4.3");Gt.register("L","2.5.4.7");Gt.register("ST","2.5.4.8");Gt.register("O","2.5.4.10");Gt.register("OU","2.5.4.11");Gt.register("C","2.5.4.6");Gt.register("DC","0.9.2342.19200300.100.1.25");Gt.register("E","1.2.840.113549.1.9.1");Gt.register("G","2.5.4.42");Gt.register("I","2.5.4.43");Gt.register("SN","2.5.4.4");Gt.register("T","2.5.4.12");function _C(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function CC(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,_C)}var mr=class r{static isASCII(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new qf,this.asn=new Pe;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let o=t[n];this.extraNames.register(n,o)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Pe?this.asn=e:V.BufferSourceConverter.isBufferSource(e)?this.asn=F.parse(e,Pe):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Gt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||Gt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${V.Convert.ToHex(t.value.anyValue)}`:CC(t.value.toString());return`${n}=${o}`}).join("+")).join(", ")}toJSON(){var e;let t=[];for(let n of this.asn){let o={};for(let i of n){let s=this.getName(i.type)||i.type;(e=o[s])!==null&&e!==void 0||(o[s]=[]),o[s].push(i.value.anyValue?`#${V.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Pe,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,o=null,i=",";for(;o=n.exec(`${e},`);){let[,s,a]=o,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),o[3]=c);let u=o[3];s=this.getTypeOid(s);let h=this.createAttribute(s,a);i==="+"?t[t.length-1].push(h):t.push(new no([h])),i=u}return t}fromJSON(e){let t=new Pe;for(let n of e){let o=new no;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let u=this.createAttribute(s,c);o.push(u)}}t.push(o)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){let n=new oi({type:e});if(typeof t=="object")for(let o in t)switch(o){case"ia5String":n.value.ia5String=t[o];break;case"utf8String":n.value.utf8String=t[o];break;case"universalString":n.value.universalString=t[o];break;case"bmpString":n.value.bmpString=t[o];break;case"printableString":n.value.printableString=t[o];break}else if(t[0]==="#")n.value.anyValue=V.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
10
- `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return F.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},m1="Cannot initialize GeneralName from ASN.1 data.",r1=`${m1} Unsupported string format in use.`,IC=`${m1} Value doesn't match to GUID regular expression.`,n1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,o1="1.3.6.1.4.1.311.25.1",i1="1.3.6.1.4.1.311.20.2.3",hy="dns",dy="dn",my="email",yy="ip",gy="url",wy="guid",xy="upn",Hf="id",tn=class extends So{constructor(...e){let t;if(e.length===2)switch(e[0]){case dy:{let n=new mr(e[1]).toArrayBuffer(),o=F.parse(n,Pe);t=new ae({directoryName:o});break}case hy:t=new ae({dNSName:e[1]});break;case my:t=new ae({rfc822Name:e[1]});break;case wy:{let n=new RegExp(n1,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let o=n.slice(1).map((i,s)=>s<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(i)).reverse()):i).join("");t=new ae({otherName:new oo({typeId:o1,value:F.serialize(new oe(V.Convert.FromHex(o)))})});break}case yy:t=new ae({iPAddress:e[1]});break;case Hf:t=new ae({registeredID:e[1]});break;case xy:{t=new ae({otherName:new oo({typeId:i1,value:F.serialize(Fd.toASN(e[1]))})});break}case gy:t=new ae({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else V.BufferSourceConverter.isBufferSource(e[0])?t=F.parse(e[0],ae):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=hy,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=my,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=yy,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=gy,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Hf,this.value=e.registeredID;else if(e.directoryName!=null)this.type=dy,this.value=new mr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===o1){this.type=wy;let t=F.parse(e.otherName.value,oe),n=new RegExp(n1,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(IC);this.value=n.slice(1).map((o,i)=>i<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===i1)this.type=xy,this.value=F.parse(e.otherName.value,nt).toString();else throw new Error(r1);else throw new Error(r1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case dy:case hy:case wy:case yy:case Hf:case xy:case gy:e=this.type.toUpperCase();break;case my:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Hf&&(t=rn.toString(t)),new Se(e,void 0,t)}},Ui=class extends So{constructor(e){let t;if(e instanceof Ve)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ae)n.push(o);else{let i=F.parse(new tn(o.type,o.value).rawData,ae);n.push(i)}t=new Ve(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=F.parse(e,Ve);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new tn(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[Se.NAME]];Array.isArray(o)||(o=[],e[n[Se.NAME]]=o),o.push(n)}return e}};Ui.NAME="GeneralNames";var Zc="-{5}",el="\\n",TC=`[^${el}]+`,BC=`${Zc}BEGIN (${TC}(?=${Zc}))${Zc}`,kC=`${Zc}END \\1${Zc}`,Fs="\\n",NC=`[^:${el}]+`,PC=`(?:[^${el}]+${Fs}(?: +[^${el}]+${Fs})*)`,OC="[a-zA-Z0-9=+/]+",RC=`(?:${OC}${Fs})+`,s1=`${BC}${Fs}(?:((?:${NC}: ${PC})+))?${Fs}?(${RC})${kC}`,Rt=class{static isPem(e){return typeof e=="string"&&new RegExp(s1,"g").test(e)}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(s1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${el}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Fs,"g")),u=null;for(let h of c){let[p,m]=h.split(/:(.*)/);if(m===void 0){if(!u)throw new Error("Cannot parse PEM string. Incorrect header value");u.value+=p.trim()}else u&&s.headers.push(u),u={key:p,value:m.trim()}}u&&s.headers.push(u)}n.push(s)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){let n=new Array;return t?e.forEach(o=>{if(!V.BufferSourceConverter.isBufferSource(o))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:t,rawData:V.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
8
+ `)}function $m(r,e,t){var n=$c(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=eC(i,e);return tC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function Xb(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var rC=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Wc);var nC=function(r){Ks(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(Wc);var oC=function(){function r(){this.preResolution=new rC,this.postResolution=new nC}return r}(),Yb=oC;var Fm=new Map,iC=function(){function r(e){this.parent=e,this._registry=new zb,this.interceptors=new Yb,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:gt.Transient}),this.ensureNotDisposed();var o;if(Gb(t)?o=t:o={useClass:t},Pi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Lr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Pi(c.provider)?s=c.provider:s=null}if((n.lifecycle===gt.Singleton||n.lifecycle==gt.ContainerScoped||n.lifecycle==gt.ResolutionScoped)&&(Ni(o)||Hs(o)))throw new Error('Cannot use lifecycle "'+gt[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:o,options:n}),this},r.prototype.registerType=function(e,t){return this.ensureNotDisposed(),yo(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},r.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},r.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),yo(e)){if(yo(t))return this.register(e,{useToken:t},{lifecycle:gt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:gt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!yo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:gt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new qc),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&yo(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),o){var i=this.resolveRegistration(o,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(qb(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=Vc(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Vc(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var u=c.value;u.options.frequency!="Once"&&s.push(u),u.callback(e,t,n)}}catch(h){o={error:h}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===gt.Singleton,o=e.options.lifecycle===gt.ContainerScoped,i=n||o,s;return Ni(e.provider)?s=e.provider.useValue:Pi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):Fc(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Hs(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new qc),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&yo(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=Vc(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=$c(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Ni(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=Vc(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=$c(i.value,2),a=s[0],c=s[1];c.some(function(u){var h=u.options;return h.lifecycle===gt.ContainerScoped})&&n._registry.setAll(a,c.map(function(u){return u.options.lifecycle===gt.ContainerScoped?{provider:u.provider,options:u.options}:u}))}}catch(u){e={error:u}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},r.prototype.beforeResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:n})},r.prototype.afterResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:n})},r.prototype.dispose=function(){return Fb(this,void 0,void 0,function(){var e;return Wb(this,function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var o=n.dispose();o&&e.push(o)}),[4,Promise.all(e)];case 1:return t.sent(),[2]}})})},r.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},r.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},r.prototype.construct=function(e,t){var n=this;if(e instanceof Nf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=Fm.get(e);if(!i||i.length===0){if(e.length===0)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var s=i.map(n.resolveParams(t,e));return new(e.bind.apply(e,Lr([void 0],s)))}();return Xb(o)&&this.disposables.add(o),o},r.prototype.resolveParams=function(e,t){var n=this;return function(o,i){var s,a,c;try{return Vm(o)?Of(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Lr([n.resolveAll(o.token,new qc,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Lr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new qc,o.isOptional):n.resolve(o.token,e,o.isOptional):Of(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Lr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(u){throw new Error($m(t,i,u))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r}(),Ue=new iC;function sC(r){return function(e){Fm.set(e,Hm(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Ue.register(t,e)}):Ue.register(r.token,e))}}var go=sC;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var qm,Oi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};l([f({type:d.ObjectIdentifier})],Oi.prototype,"attrId",void 0);l([f({type:d.Any,repeated:"set"})],Oi.prototype,"attrValues",void 0);var Zb=qm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,qm.prototype)}};Zb=qm=l([_({type:A.Sequence,itemType:Oi})],Zb);var Gm,Jb=Gm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};Jb=Gm=l([_({type:A.Sequence,itemType:hr})],Jb);var aC="1.2.840.113549",cC=`${aC}.1`,Qb=`${cC}.12`,Vs=`${Qb}.1`,HF=`${Vs}.1`,VF=`${Vs}.2`,$F=`${Vs}.3`,FF=`${Vs}.4`,WF=`${Vs}.5`,qF=`${Vs}.6`,Ri=`${Qb}.10.1`;var XF=`${Ri}.1`,YF=`${Ri}.2`,ZF=`${Ri}.3`,JF=`${Ri}.4`,QF=`${Ri}.5`,eW=`${Ri}.6`,Rf="1.2.840.113549.1.9";var Lf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Lf.prototype,"certId",void 0);l([f({type:d.Any,context:0})],Lf.prototype,"certValue",void 0);var ev=`${Rf}.22`,iW=`${ev}.1`,sW=`${ev}.2`;var Df=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Df.prototype,"crlId",void 0);l([f({type:d.Any,context:0})],Df.prototype,"crltValue",void 0);var lC=`${Rf}.23`,fW=`${lC}.1`;var Uf=class extends oe{},wo=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Uf,Object.assign(this,e)}};l([f({type:M})],wo.prototype,"encryptionAlgorithm",void 0);l([f({type:Uf})],wo.prototype,"encryptedData",void 0);var zm,Xm;(function(r){r[r.v1=0]="v1"})(Xm||(Xm={}));var jf=class extends oe{},Ym=zm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,zm.prototype)}};Ym=zm=l([_({type:A.Sequence,itemType:pt})],Ym);var xo=class{constructor(e={}){this.version=Xm.v1,this.privateKeyAlgorithm=new M,this.privateKey=new jf,Object.assign(this,e)}};l([f({type:d.Integer})],xo.prototype,"version",void 0);l([f({type:M})],xo.prototype,"privateKeyAlgorithm",void 0);l([f({type:jf})],xo.prototype,"privateKey",void 0);l([f({type:Ym,implicit:!0,context:0,optional:!0})],xo.prototype,"attributes",void 0);var tv=class extends xo{};tv=l([_({type:A.Sequence})],tv);var rv=class extends wo{};rv=l([_({type:A.Sequence})],rv);var Mf=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],Mf.prototype,"secretTypeId",void 0);l([f({type:d.Any,context:0})],Mf.prototype,"secretValue",void 0);var bo=class{constructor(e={}){this.mac=new ki,this.macSalt=new oe,this.iterations=1,Object.assign(this,e)}};l([f({type:ki})],bo.prototype,"mac",void 0);l([f({type:oe})],bo.prototype,"macSalt",void 0);l([f({type:d.Integer,defaultValue:1})],bo.prototype,"iterations",void 0);var Li=class{constructor(e={}){this.version=3,this.authSafe=new hr,this.macData=new bo,Object.assign(this,e)}};l([f({type:d.Integer})],Li.prototype,"version",void 0);l([f({type:hr})],Li.prototype,"authSafe",void 0);l([f({type:bo,optional:!0})],Li.prototype,"macData",void 0);var Zm,$s=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:d.ObjectIdentifier})],$s.prototype,"bagId",void 0);l([f({type:d.Any,context:0})],$s.prototype,"bagValue",void 0);l([f({type:Oi,repeated:"set",optional:!0})],$s.prototype,"bagAttributes",void 0);var nv=Zm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Zm.prototype)}};nv=Zm=l([_({type:A.Sequence,itemType:$s})],nv);var Jm,Qm,ey,Xe="1.2.840.113549.1.9",hq=`${Xe}.0`,gv=`${Xe}.24`,zc=`${Xe}.25`,wv=`${Xe}.26`,xv=`${Xe}.27`,dq=`${gv}.1`,mq=`${gv}.2`,yq=`${Xe}.1`,gq=`${Xe}.2`,wq=`${Xe}.3`,xq=`${Xe}.4`,bq=`${Xe}.5`,vq=`${Xe}.6`,cy=`${Xe}.7`,Aq=`${Xe}.8`,Sq=`${Xe}.9`,Eq=`${Xe}.13`,Xc=`${Xe}.14`,_q=`${Xe}.15`,Cq=`${Xe}.20`,Iq=`${Xe}.21`;var Tq=`${zc}.1`,Bq=`${zc}.2`,kq=`${zc}.3`,Pq=`${zc}.4`,Nq=`${zc}.5`,Yc="1.3.6.1.5.5.7.9",Oq=`${Yc}.1`,Rq=`${Yc}.2`,Lq=`${Yc}.3`,Dq=`${Yc}.4`,Uq=`${Yc}.5`,jq=`${wv}.1`,Mq=`${wv}.2`,Kq=`${xv}.1`,Hq=`${xv}.2`,Vq=`${Xe}.16`,$q=`${Xe}.22`,Fq=`${Xe}.23`,Wq=`${bm}.65`,Kf=class extends nt{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};l([f({type:d.IA5String})],Kf.prototype,"ia5String",void 0);Kf=l([_({type:A.Choice})],Kf);var ov=class extends hr{};ov=l([_({type:A.Sequence})],ov);var iv=class extends Li{};iv=l([_({type:A.Sequence})],iv);var sv=class extends wo{};sv=l([_({type:A.Sequence})],sv);var ty=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.IA5String})],ty.prototype,"value",void 0);ty=l([_({type:A.Choice})],ty);var av=class extends Kf{};av=l([_({type:A.Choice})],av);var cv=class extends nt{};cv=l([_({type:A.Choice})],cv);var ry=class{constructor(e=new Date){this.value=e}};l([f({type:d.GeneralizedTime})],ry.prototype,"value",void 0);ry=l([_({type:A.Choice})],ry);var lv=class extends nt{};lv=l([_({type:A.Choice})],lv);var ny=class{constructor(e="M"){this.value=e}toString(){return this.value}};l([f({type:d.PrintableString})],ny.prototype,"value",void 0);ny=l([_({type:A.Choice})],ny);var Hf=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.PrintableString})],Hf.prototype,"value",void 0);Hf=l([_({type:A.Choice})],Hf);var uv=class extends Hf{};uv=l([_({type:A.Choice})],uv);var fv=class extends nt{};fv=l([_({type:A.Choice})],fv);var oy=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.ObjectIdentifier})],oy.prototype,"value",void 0);oy=l([_({type:A.Choice})],oy);var pv=class extends ze{};pv=l([_({type:A.Choice})],pv);var iy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};l([f({type:d.Integer})],iy.prototype,"value",void 0);iy=l([_({type:A.Choice})],iy);var hv=class extends Ht{};hv=l([_({type:A.Sequence})],hv);var Gc=class extends nt{};Gc=l([_({type:A.Choice})],Gc);var dv=Jm=class extends Jt{constructor(e){super(e),Object.setPrototypeOf(this,Jm.prototype)}};dv=Jm=l([_({type:A.Sequence})],dv);var mv=Qm=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};mv=Qm=l([_({type:A.Set,itemType:Rr})],mv);var sy=class{constructor(e=""){this.value=e}toString(){return this.value}};l([f({type:d.BmpString})],sy.prototype,"value",void 0);sy=l([_({type:A.Choice})],sy);var ay=class extends M{};ay=l([_({type:A.Sequence})],ay);var yv=ey=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ey.prototype)}};yv=ey=l([_({type:A.Sequence,itemType:ay})],yv);var ly,Zc=ly=class extends ne{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};Zc=ly=l([_({type:A.Sequence,itemType:pt})],Zc);var en=class{constructor(e={}){this.version=0,this.subject=new Ne,this.subjectPKInfo=new ht,this.attributes=new Zc,Object.assign(this,e)}};l([f({type:d.Integer})],en.prototype,"version",void 0);l([f({type:Ne})],en.prototype,"subject",void 0);l([f({type:ht})],en.prototype,"subjectPKInfo",void 0);l([f({type:Zc,implicit:!0,context:0})],en.prototype,"attributes",void 0);var vo=class{constructor(e={}){this.certificationRequestInfo=new en,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};l([f({type:en})],vo.prototype,"certificationRequestInfo",void 0);l([f({type:M})],vo.prototype,"signatureAlgorithm",void 0);l([f({type:d.BitString})],vo.prototype,"signature",void 0);var nl="crypto.algorithm",xy=class{getAlgorithms(){return Ue.resolveAll(nl)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Di="crypto.algorithmProvider";Ue.registerSingleton(Di,xy);var Wf,qt="1.3.36.3.3.2.8.1.1",bv=`${qt}.1`,vv=`${qt}.2`,Av=`${qt}.3`,Sv=`${qt}.4`,Ev=`${qt}.5`,_v=`${qt}.6`,Cv=`${qt}.7`,Iv=`${qt}.8`,Tv=`${qt}.9`,Bv=`${qt}.10`,kv=`${qt}.11`,Pv=`${qt}.12`,Nv=`${qt}.13`,Ov=`${qt}.14`,Rv="brainpoolP160r1",Lv="brainpoolP160t1",Dv="brainpoolP192r1",Uv="brainpoolP192t1",jv="brainpoolP224r1",Mv="brainpoolP224t1",Kv="brainpoolP256r1",Hv="brainpoolP256t1",Vv="brainpoolP320r1",$v="brainpoolP320t1",Fv="brainpoolP384r1",Wv="brainpoolP384t1",qv="brainpoolP512r1",Gv="brainpoolP512t1",Fe="ECDSA",Qc=Wf=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Fe.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return lb;case"sha-256":return ub;case"sha-384":return fb;case"sha-512":return pb}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=km;break;case"K-256":t=Wf.SECP256K1;break;case"P-384":t=Pm;break;case"P-521":t=Nm;break;case Rv:t=bv;break;case Lv:t=vv;break;case Dv:t=Av;break;case Uv:t=Sv;break;case jv:t=Ev;break;case Mv:t=_v;break;case Kv:t=Cv;break;case Hv:t=Iv;break;case Vv:t=Tv;break;case $v:t=Bv;break;case Fv:t=kv;break;case Wv:t=Pv;break;case qv:t=Nv;break;case Gv:t=Ov;break}if(t)return new M({algorithm:Ei,parameters:F.serialize(new Zr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Dc:return{name:Fe,hash:{name:"SHA-1"}};case Uc:return{name:Fe,hash:{name:"SHA-256"}};case jc:return{name:Fe,hash:{name:"SHA-384"}};case Mc:return{name:Fe,hash:{name:"SHA-512"}};case Ei:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,Zr).namedCurve){case km:return{name:Fe,namedCurve:"P-256"};case Wf.SECP256K1:return{name:Fe,namedCurve:"K-256"};case Pm:return{name:Fe,namedCurve:"P-384"};case Nm:return{name:Fe,namedCurve:"P-521"};case bv:return{name:Fe,namedCurve:Rv};case vv:return{name:Fe,namedCurve:Lv};case Av:return{name:Fe,namedCurve:Dv};case Sv:return{name:Fe,namedCurve:Uv};case Ev:return{name:Fe,namedCurve:jv};case _v:return{name:Fe,namedCurve:Mv};case Cv:return{name:Fe,namedCurve:Kv};case Iv:return{name:Fe,namedCurve:Hv};case Tv:return{name:Fe,namedCurve:Vv};case Bv:return{name:Fe,namedCurve:$v};case kv:return{name:Fe,namedCurve:Fv};case Pv:return{name:Fe,namedCurve:Wv};case Nv:return{name:Fe,namedCurve:qv};case Ov:return{name:Fe,namedCurve:Gv}}}}return null}};Qc.SECP256K1="1.3.132.0.10";Qc=Wf=l([go()],Qc);Ue.registerSingleton(nl,Qc);var o1=Symbol("name"),i1=Symbol("value"),Se=class{constructor(e,t={},n=""){this[o1]=e,this[i1]=n;for(let o in t)this[o]=t[o]}};Se.NAME=o1;Se.VALUE=i1;var by=class{static toTextObject(e){let t=new Se("Algorithm Identifier",{},rn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Ei:{let n=new Qc().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},rn=class{static toString(e){let t=this.items[e];return t||e}};rn.items={[Ci]:"sha1",[If]:"sha224",[Ii]:"sha256",[Ti]:"sha384",[Bi]:"sha512",[Jr]:"rsaEncryption",[Os]:"sha1WithRSAEncryption",[gb]:"sha224WithRSAEncryption",[Cf]:"sha256WithRSAEncryption",[Rs]:"sha384WithRSAEncryption",[Ls]:"sha512WithRSAEncryption",[Ei]:"ecPublicKey",[Dc]:"ecdsaWithSHA1",[_f]:"ecdsaWithSHA224",[Uc]:"ecdsaWithSHA256",[jc]:"ecdsaWithSHA384",[Mc]:"ecdsaWithSHA512",[$x]:"TLS WWW server authentication",[Fx]:"TLS WWW client authentication",[Wx]:"Code Signing",[qx]:"E-mail Protection",[Gx]:"Time Stamping",[zx]:"OCSP Signing",[ab]:"Signed Data"};var Bn=class{static serialize(e){return this.serializeObj(e).join(`
9
+ `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Se.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Se.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],u=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${u}${c}`);else if(c instanceof Date)n.push(`${o}${u}${c.toUTCString()}`);else if(Array.isArray(c))for(let h of c)h[Se.NAME]=a,n.push(...this.serializeObj(h,t));else if(c instanceof Se)c[Se.NAME]=a,n.push(...this.serializeObj(c,t));else if(V.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${u}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let h=c.toTextObject();h[Se.NAME]=a,n.push(...this.serializeObj(h,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=V.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let u=o[s++].toString(16).padStart(2,"0");a.push(u)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Bn.oidSerializer=rn;Bn.algorithmSerializer=by;var Ao=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=F.serialize(t),this.onInit(t)}else{let t=F.parse(e[0],e[1]);this.rawData=V.BufferSourceConverter.toArrayBuffer(e[0]),this.onInit(t)}}equal(e){return e instanceof r?(0,V.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return F.toString(this.rawData);case"text":return Bn.serialize(this.toTextObject());case"hex":return V.Convert.ToHex(this.rawData);case"base64":return V.Convert.ToBase64(this.rawData);case"base64url":return V.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new Se(this.getTextName(),{},e)}};Ao.NAME="ASN";var yr=class r extends Ao{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=F.serialize(new dt({extnID:e[0],critical:e[1],extnValue:new oe(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,dt)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[Se.NAME]===r.NAME&&(e[Se.NAME]=rn.toString(this.type)),e}},s1,el=class r{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[s1]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(r.DEFAULT,crypto):typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle&&this.set(r.DEFAULT,globalThis.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,t){return this.items.forEach(e,t)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=r.DEFAULT){let t=this.items.get(e.toLowerCase());if(!t)throw new Error(`Cannot get Crypto by name '${e}'`);return t}set(e,t){if(typeof e=="string"){if(!t)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),t)}else this.items.set(r.DEFAULT,e);return this}};s1=Symbol.toStringTag;el.DEFAULT="default";var wt=new el,hC=/^[0-2](?:\.[1-9][0-9]*)+$/;function dC(r){return new RegExp(hC).test(r)}var Gf=class{constructor(e={}){this.items={};for(let t in e)this.register(t,e[t])}get(e){return this.items[e]||null}findId(e){return dC(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Ft=new Gf;Ft.register("CN","2.5.4.3");Ft.register("L","2.5.4.7");Ft.register("ST","2.5.4.8");Ft.register("O","2.5.4.10");Ft.register("OU","2.5.4.11");Ft.register("C","2.5.4.6");Ft.register("DC","0.9.2342.19200300.100.1.25");Ft.register("E","1.2.840.113549.1.9.1");Ft.register("G","2.5.4.42");Ft.register("I","2.5.4.43");Ft.register("SN","2.5.4.4");Ft.register("T","2.5.4.12");function mC(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function yC(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,mC)}var mr=class r{static isASCII(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new Gf,this.asn=new Ne;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let o=t[n];this.extraNames.register(n,o)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Ne?this.asn=e:V.BufferSourceConverter.isBufferSource(e)?this.asn=F.parse(e,Ne):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Ft.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||Ft.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${V.Convert.ToHex(t.value.anyValue)}`:yC(t.value.toString());return`${n}=${o}`}).join("+")).join(", ")}toJSON(){var e;let t=[];for(let n of this.asn){let o={};for(let i of n){let s=this.getName(i.type)||i.type;(e=o[s])!==null&&e!==void 0||(o[s]=[]),o[s].push(i.value.anyValue?`#${V.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Ne,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,o=null,i=",";for(;o=n.exec(`${e},`);){let[,s,a]=o,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),o[3]=c);let u=o[3];s=this.getTypeOid(s);let h=this.createAttribute(s,a);i==="+"?t[t.length-1].push(h):t.push(new ro([h])),i=u}return t}fromJSON(e){let t=new Ne;for(let n of e){let o=new ro;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let u=this.createAttribute(s,c);o.push(u)}}t.push(o)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){let n=new oi({type:e});if(typeof t=="object")for(let o in t)switch(o){case"ia5String":n.value.ia5String=t[o];break;case"utf8String":n.value.utf8String=t[o];break;case"universalString":n.value.universalString=t[o];break;case"bmpString":n.value.bmpString=t[o];break;case"printableString":n.value.printableString=t[o];break}else if(t[0]==="#")n.value.anyValue=V.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
10
+ `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return F.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},a1="Cannot initialize GeneralName from ASN.1 data.",zv=`${a1} Unsupported string format in use.`,gC=`${a1} Value doesn't match to GUID regular expression.`,Xv=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,Yv="1.3.6.1.4.1.311.25.1",Zv="1.3.6.1.4.1.311.20.2.3",uy="dns",fy="dn",py="email",hy="ip",dy="url",my="guid",yy="upn",Vf="id",tn=class extends Ao{constructor(...e){let t;if(e.length===2)switch(e[0]){case fy:{let n=new mr(e[1]).toArrayBuffer(),o=F.parse(n,Ne);t=new ae({directoryName:o});break}case uy:t=new ae({dNSName:e[1]});break;case py:t=new ae({rfc822Name:e[1]});break;case my:{let n=new RegExp(Xv,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let o=n.slice(1).map((i,s)=>s<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(i)).reverse()):i).join("");t=new ae({otherName:new no({typeId:Yv,value:F.serialize(new oe(V.Convert.FromHex(o)))})});break}case hy:t=new ae({iPAddress:e[1]});break;case Vf:t=new ae({registeredID:e[1]});break;case yy:{t=new ae({otherName:new no({typeId:Zv,value:F.serialize(Hd.toASN(e[1]))})});break}case dy:t=new ae({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else V.BufferSourceConverter.isBufferSource(e[0])?t=F.parse(e[0],ae):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=uy,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=py,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=hy,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=dy,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Vf,this.value=e.registeredID;else if(e.directoryName!=null)this.type=fy,this.value=new mr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===Yv){this.type=my;let t=F.parse(e.otherName.value,oe),n=new RegExp(Xv,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(gC);this.value=n.slice(1).map((o,i)=>i<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===Zv)this.type=yy,this.value=F.parse(e.otherName.value,nt).toString();else throw new Error(zv);else throw new Error(zv)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case fy:case uy:case my:case hy:case Vf:case yy:case dy:e=this.type.toUpperCase();break;case py:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Vf&&(t=rn.toString(t)),new Se(e,void 0,t)}},Ui=class extends Ao{constructor(e){let t;if(e instanceof Ve)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ae)n.push(o);else{let i=F.parse(new tn(o.type,o.value).rawData,ae);n.push(i)}t=new Ve(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=F.parse(e,Ve);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new tn(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[Se.NAME]];Array.isArray(o)||(o=[],e[n[Se.NAME]]=o),o.push(n)}return e}};Ui.NAME="GeneralNames";var Jc="-{5}",tl="\\n",wC=`[^${tl}]+`,xC=`${Jc}BEGIN (${wC}(?=${Jc}))${Jc}`,bC=`${Jc}END \\1${Jc}`,Fs="\\n",vC=`[^:${tl}]+`,AC=`(?:[^${tl}]+${Fs}(?: +[^${tl}]+${Fs})*)`,SC="[a-zA-Z0-9=+/]+",EC=`(?:${SC}${Fs})+`,Jv=`${xC}${Fs}(?:((?:${vC}: ${AC})+))?${Fs}?(${EC})${bC}`,Ot=class{static isPem(e){return typeof e=="string"&&new RegExp(Jv,"g").test(e)}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(Jv,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${tl}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Fs,"g")),u=null;for(let h of c){let[p,y]=h.split(/:(.*)/);if(y===void 0){if(!u)throw new Error("Cannot parse PEM string. Incorrect header value");u.value+=p.trim()}else u&&s.headers.push(u),u={key:p,value:y.trim()}}u&&s.headers.push(u)}n.push(s)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){let n=new Array;return t?e.forEach(o=>{if(!V.BufferSourceConverter.isBufferSource(o))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:t,rawData:V.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
11
11
  `)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:V.BufferSourceConverter.toArrayBuffer(e)})}}static encodeStruct(e){var t;let n=e.type.toLocaleUpperCase(),o=[];if(o.push(`-----BEGIN ${n}-----`),!((t=e.headers)===null||t===void 0)&&t.length){for(let u of e.headers)o.push(`${u.key}: ${u.value}`);o.push("")}let i=V.Convert.ToBase64(e.rawData),s,a=0,c=Array();for(;a<i.length&&(i.length-a<64?s=i.substring(a):(s=i.substring(a,a+64),a+=64),s.length!==0);)if(c.push(s),s.length<64)break;return o.push(...c),o.push(`-----END ${n}-----`),o.join(`
12
- `)}};Rt.CertificateTag="CERTIFICATE";Rt.CrlTag="CRL";Rt.CertificateRequestTag="CERTIFICATE REQUEST";Rt.PublicKeyTag="PUBLIC KEY";Rt.PrivateKeyTag="PRIVATE KEY";var Eo=class r extends So{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Rt.isPem(e))return Rt.decode(e)[0];if(V.Convert.isHex(e))return V.Convert.FromHex(e);if(V.Convert.isBase64(e))return V.Convert.FromBase64(e);if(V.Convert.isBase64Url(e))return V.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=V.Convert.ToBinary(e);return Rt.isPem(t)?Rt.decode(t)[0]:V.Convert.isHex(t)?V.Convert.FromHex(t):V.Convert.isBase64(t)?V.Convert.FromBase64(t):V.Convert.isBase64Url(t)?V.Convert.FromBase64Url(t):V.BufferSourceConverter.toArrayBuffer(e)}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Rt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Tn=class r extends Eo{static async create(e,t=wt.get()){if(e instanceof r)return e;if(Qc.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(V.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Eo.isAsnEncoded(e)?super(e,ht):super(e),this.tag=Rt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||wt.get()):t=e[0]||wt.get();let i=this.rawData,s=F.parse(this.rawData,ht);return s.algorithm.algorithm===mo&&(i=LC(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Fe.resolve(Di),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Jr:{let o=F.parse(e.subjectPublicKey,js),i=V.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=V.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=wt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=wt.get();let o=F.parse(this.rawData,ht);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,ht);switch(e.Algorithm=Bn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ei:e["EC Point"]=t.subjectPublicKey;break;case Jr:default:e["Raw Data"]=t.subjectPublicKey}return e}};function LC(r,e){return r.algorithm=new M({algorithm:Jr,parameters:null}),e=F.serialize(r),e}var Gf=class r extends yr{static async create(e,t=!1,n=wt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Tn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new Gr({keyIdentifier:new ai(V.Convert.FromHex(e[0]))});super(rf,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Ui?F.parse(t.name.rawData,Ve):t.name,o=new Gr({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(rf,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Gr);t.keyIdentifier&&(this.keyId=V.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?V.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Gr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Ui(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Gf.NAME="Authority Key Identifier";var Ws=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,ci);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new ci({cA:e[0],pathLenConstraint:e[1]});super(nf,e[2],F.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};Ws.NAME="Basic Constraints";var a1;(function(r){r.serverAuth="1.3.6.1.5.5.7.3.1",r.clientAuth="1.3.6.1.5.5.7.3.2",r.codeSigning="1.3.6.1.5.5.7.3.3",r.emailProtection="1.3.6.1.5.5.7.3.4",r.timeStamping="1.3.6.1.5.5.7.3.8",r.ocspSigning="1.3.6.1.5.5.7.3.9"})(a1||(a1={}));var zf=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,yc);this.usages=t.map(n=>n)}else{let t=new yc(e[0]);super(cf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>rn.toString(t)).join(", "),e}};zf.NAME="Extended Key Usages";var c1;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(c1||(c1={}));var Xf=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,ys);this.usages=t.toNumber()}else{let t=new ys(e[0]);super(lf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,ys);return e[""]=t.toJSON().join(", "),e}};Xf.NAME="Key Usages";var Yf=class r extends yr{static async create(e,t=!1,n=wt.get()){let i=await(await Tn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Vt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new Vt(t);super(ym,e[1],F.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Vt);return e[""]=t,e}};Yf.NAME="Subject Key Identifier";var Zf=class extends yr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(dm,e[1],new Ui(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,hf);this.names=new Ui(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Zf.NAME="Subject Alternative Name";var zt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new yr(e),n=this.items.get(t.type);return n?new n(e):t}};zt.items=new Map;var Jf=class extends yr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,fc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new fc(n.map(s=>new li({policyIdentifier:s})));super(sf,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Se("",{},rn.toString(t))),e}};Jf.NAME="Certificate Policies";zt.register(sf,Jf);var Qf=class extends yr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new zr({distributionPoint:new An({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new ao(o);super(af,e[1],F.serialize(i))}else{let n=new ao(e[0]);super(af,e[1],F.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,ao);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new tn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Qf.NAME="CRL Distribution Points";var ep=class extends yr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof si){let s=new si(e[0]);super(tf,e[1],F.serialize(s))}else{let s=e[0],a=new si;$f(a,s,Jd,"ocsp"),$f(a,s,Qd,"caIssuers"),$f(a,s,em,"timeStamping"),$f(a,s,tm,"caRepository"),super(tf,e[1],F.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],F.parse(e.extnValue,si).forEach(n=>{switch(n.accessMethod){case Jd:this.ocsp.push(new tn(n.accessLocation));break;case Qd:this.caIssuers.push(new tn(n.accessLocation));break;case em:this.timeStamping.push(new tn(n.accessLocation));break;case tm:this.caRepository.push(new tn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&Vf(e,"OCSP",this.ocsp),this.caIssuers.length&&Vf(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Vf(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Vf(e,"CA Repository",this.caRepository),e}};ep.NAME="Authority Info Access";function Vf(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Se("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Se.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function $f(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new tn("url",s)),r.push(new bn({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var qs=class r extends So{constructor(...e){let t;if(V.BufferSourceConverter.isBufferSource(e[0]))t=V.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>V.BufferSourceConverter.toArrayBuffer(i)):[];t=F.serialize(new pt({type:n,values:o}))}super(t,pt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Se("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Se.NAME]===r.NAME&&(e[Se.NAME]=rn.toString(this.type)),e}};qs.NAME="Attribute";var tp=class extends qs{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new qc({printableString:e[0]});super(fy,[F.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],qc);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Se.VALUE]=this.password,e}};tp.NAME="Challenge Password";var tl=class extends qs{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new er;for(let i of n)o.push(F.parse(i.rawData,dt));super(zc,[F.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],er);this.items=t.map(n=>zt.create(F.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Se.NAME]]=n;return e}};tl.NAME="Extensions";var Gs=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new qs(e),n=this.items.get(t.type);return n?new n(e):t}};Gs.items=new Map;var nl="crypto.signatureFormatter",Ey=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},Wf,_y=Wf=class{static createPssParams(e,t){let n=Wf.getHashAlgorithm(e);return n?new Qr({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:yo,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Fe.resolve(Di);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:Os,parameters:null});case"sha-256":return new M({algorithm:_f,parameters:null});case"sha-384":return new M({algorithm:Rs,parameters:null});case"sha-512":return new M({algorithm:Ls,parameters:null})}}else return new M({algorithm:Jr,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let t=Wf.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:mo,parameters:F.serialize(t)})}else return new M({algorithm:mo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Jr:return{name:"RSASSA-PKCS1-v1_5"};case Os:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case _f:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Rs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Ls:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case mo:if(e.parameters){let t=F.parse(e.parameters,Qr);return{name:"RSA-PSS",hash:Fe.resolve(Di).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};_y=Wf=l([wo()],_y);Fe.registerSingleton(rl,_y);var Cy=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Ci});case"sha-256":return new M({algorithm:Ii});case"sha-384":return new M({algorithm:Ti});case"sha-512":return new M({algorithm:Bi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ci:return{name:"SHA-1"};case Ii:return{name:"SHA-256"};case Ti:return{name:"SHA-384"};case Bi:return{name:"SHA-512"}}return null}};Cy=l([wo()],Cy);Fe.registerSingleton(rl,Cy);var kn=class r{addPadding(e,t){let n=V.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=V.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new _i,s=V.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),F.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=F.parse(t,_i),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,V.combine)(s,a)}return null}};kn.namedCurveSize=new Map;kn.defaultNamedCurveSize=32;var by="1.3.101.110",l1="1.3.101.111",vy="1.3.101.112",u1="1.3.101.113",Iy=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=vy;break;case"x25519":t=by;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=vy;break;case"ed448":t=u1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=by;break;case"x448":t=l1;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case vy:return{name:"Ed25519"};case u1:return{name:"EdDSA",namedCurve:"Ed448"};case by:return{name:"X25519"};case l1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Iy=l([wo()],Iy);Fe.registerSingleton(rl,Iy);var Ty=class extends Eo{constructor(e){Eo.isAsnEncoded(e)?super(e,Ao):super(e),this.tag=Rt.CertificateRequestTag}onInit(e){this.tbs=F.serialize(e.certificationRequestInfo),this.publicKey=new Tn(e.certificationRequestInfo.subjectPKInfo);let t=Fe.resolve(Di);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>Gs.create(F.serialize(o)));let n=this.getAttribute(zc);this.extensions=[],n instanceof tl&&(this.extensions=n.items),this.subjectName=new mr(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=wt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Fe.resolveAll(nl).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,Ao),n=t.certificationRequestInfo,o=new Se("",{Version:`${Xr[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Se("");for(let s of this.attributes){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Se("",{Algorithm:Bn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Ty.NAME="PKCS#10 Certificate Request";var zs=class extends Eo{constructor(e){Eo.isAsnEncoded(e)?super(e,ur):super(e),this.tag=Rt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=F.serialize(t),this.serialNumber=V.Convert.ToHex(t.serialNumber),this.subjectName=new mr(t.subject),this.subject=new mr(t.subject).toString(),this.issuerName=new mr(t.issuer),this.issuer=this.issuerName.toString();let n=Fe.resolve(Di);this.signatureAlgorithm=n.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let o=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!o)throw new Error("Cannot get 'notBefore' value");this.notBefore=o;let i=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!i)throw new Error("Cannot get 'notAfter' value");this.notAfter=i,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(s=>zt.create(F.serialize(s)))),this.publicKey=new Tn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=wt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Tn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let u=new Tn(i);n={...u.algorithm,...this.signatureAlgorithm},o=await u.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Fe.resolveAll(nl).reverse(),a=null;for(let u of s)if(a=u.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let h=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<h&&h<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=wt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=wt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,ur),n=t.tbsCertificate,o=new Se("",{Version:`${Xr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Bn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Se("",{"Not Before":n.validity.notBefore.getTime(),"Not After":n.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(n.issuerUniqueID&&(o["Issuer Unique ID"]=n.issuerUniqueID),n.subjectUniqueID&&(o["Subject Unique ID"]=n.subjectUniqueID),this.extensions.length){let i=new Se("");for(let s of this.extensions){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Se("",{Algorithm:Bn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};zs.NAME="Certificate";var rp=class{static async createSelfSigned(e,t=wt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=wt.get()){var n;let o;e.publicKey instanceof Tn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:V.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?V.BufferSourceConverter.toUint8Array(V.Convert.FromHex(e.serialNumber)):t.getRandomValues(new Uint8Array(16));i[0]>127&&(i[0]&=127),i.length>1&&i[0]===0&&(i[1]|=128);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new ur({tbsCertificate:new mt({version:Xr.v3,serialNumber:i,validity:new Sn({notBefore:s,notAfter:a}),extensions:new er(((n=e.extensions)===null||n===void 0?void 0:n.map(y=>F.parse(y.rawData,dt)))||[]),subjectPublicKeyInfo:F.parse(o,ht)})});if(e.subject){let y=e.subject instanceof mr?e.subject:new mr(e.subject);c.tbsCertificate.subject=F.parse(y.toArrayBuffer(),Pe)}if(e.issuer){let y=e.issuer instanceof mr?e.issuer:new mr(e.issuer);c.tbsCertificate.issuer=F.parse(y.toArrayBuffer(),Pe)}let u={hash:"SHA-256"},h="signingKey"in e?{...u,...e.signingAlgorithm,...e.signingKey.algorithm}:{...u,...e.signingAlgorithm},p=Fe.resolve(Di);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(h);let m=F.serialize(c.tbsCertificate),w="signingKey"in e?await t.subtle.sign(h,e.signingKey,m):e.signature,b=Fe.resolveAll(nl).reverse(),g=null;for(let y of b)if(g=y.toAsnSignature(h,w),g)break;if(!g)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=g,new zs(F.serialize(c))}},f1;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(f1||(f1={}));zt.register(nf,Ws);zt.register(cf,zf);zt.register(lf,Xf);zt.register(ym,Yf);zt.register(rf,Gf);zt.register(dm,Zf);zt.register(af,Qf);zt.register(tf,ep);Gs.register(fy,tp);Gs.register(zc,tl);Fe.registerSingleton(nl,Ey);Fe.registerSingleton(nl,kn);kn.namedCurveSize.set("P-256",32);kn.namedCurveSize.set("K-256",32);kn.namedCurveSize.set("P-384",48);kn.namedCurveSize.set("P-521",66);var Nn="/",y1=new TextEncoder().encode(Nn),np=y1[0],ol=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=de(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==np)throw new Error("Invalid key")}toString(e="utf8"){return ce(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Nn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=y1),this._buf[0]!==np){let e=new Uint8Array(this._buf.byteLength+1);e.fill(np,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===np;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Nn).slice(1)}type(){return DC(this.baseNamespace())}name(){return UC(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Nn)||(e+=Nn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Nn):new r(e.slice(0,-1).join(Nn))}child(e){return this.toString()===Nn?e:e.toString()===Nn?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...jC(e.map(t=>t.namespaces()))])}};function DC(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function UC(r){let e=r.split(":");return e[e.length-1]}function jC(r){return[].concat(...r)}var op=class extends Ln{async listen(){throw new Tu("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var ip=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sp=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},il=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ap(r){return r[Symbol.asyncIterator]!=null}function g1(r,e){if(r.byteLength>e)throw new Xs("Message length too long")}var lp=r=>{let e=Ce(r),t=et(e);return Lt(r,t),lp.bytes=e,t};lp.bytes=0;function w1(r,e){e=e??{};let t=e.lengthEncoder??lp,n=e?.maxDataLength??4194304;function*o(i){g1(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return ap(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}w1.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??lp,n=e?.maxDataLength??4194304;return g1(r,n),new ue(t(r.byteLength),r)};var ji;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ji||(ji={}));var By=r=>{let e=Nt(r);return By.bytes=Ce(e),e};By.bytes=0;function sl(r,e){let t=new ue,n=ji.LENGTH,o=-1,i=e?.lengthDecoder??By,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===ji.LENGTH)try{if(o=i(t),o<0)throw new ip("Invalid message length");if(o>a)throw new Xs("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=ji.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new sp("Message length length too long");break}throw u}if(n===ji.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=ji.LENGTH}}}return ap(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new il("Unexpected end of input")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new il("Unexpected end of input")}()}sl.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return sl(n,{...e??{},onLength:i=>{t=i}})};var ky=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Re(),this.haveNext=Re()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Re(),e}async throw(e){return this.ended=!0,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Re(),await Dt(this.readNext.promise,t?.signal,t)}};function x1(){return new ky}var up=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Ny=class extends Error{code;constructor(e,t){super(e),this.code=t}},Py=class extends Ny{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function b1(r,e){let t=x1();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ue;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((h,p)=>{c=()=>{p(new Py("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:p,value:m}=await Promise.race([n.next(),u]);return p===!0?new ue:m}for(;o.byteLength<s;){let{value:p,done:m}=await Promise.race([n.next(),u]);if(m===!0)throw new up("unexpected end of input");o.append(p)}let h=o.sublist(0,s);return o.consume(s),h}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var fp=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pp=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hp=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Oy(r,e={}){let t=b1(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ce(e.maxDataLength));let n=e?.lengthDecoder??Nt,o=e?.lengthEncoder??Lt;return{read:async s=>{let a=-1,c=new ue;for(;;){c.append(await t.read(1,s));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new fp("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new hp("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new pp("message length too long");return t.read(a,s)},write:async(s,a)=>{await t.write(new ue(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new ue(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Ry(){let r=Re(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function v1(){let r=Ry(),e=Ry();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function KC(r){return r[Symbol.asyncIterator]!=null}async function HC(r,e){try{await Promise.all(r.map(async t=>{for await(let n of t)await e.push(n)})),await e.end()}catch(t){await e.end(t).catch(()=>{})}}async function*VC(r){let e=vu();HC(r,e).catch(()=>{}),yield*e}function*$C(r){for(let e of r)yield*e}function FC(...r){let e=[];for(let t of r)KC(t)||e.push(t);return e.length===r.length?$C(e):VC(r)}var A1=FC;function S1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Ly(r)){let n=r;r=()=>n.source}else if(_1(r)||E1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Ly(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Ly(t[n])&&(t[n]=qC(t[n]));return WC(...t)}var WC=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},E1=r=>r?.[Symbol.asyncIterator]!=null,_1=r=>r?.[Symbol.iterator]!=null,Ly=r=>r==null?!1:r.sink!=null&&r.source!=null,qC=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=ss({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(E1(i))o=async function*(){yield*i,n.end()};else if(_1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return A1(n,o())}return r.source};var Ys=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function dp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Dy(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Tt(r,...e){if(!Dy(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Uy(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function C1(r,e){Tt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function jy(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}var Pn=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),I1=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),GC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!GC)throw new Error("Non little-endian hardware is not supported");function zC(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function mp(r){if(typeof r=="string")r=zC(r);else if(Dy(r))r=yp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function T1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function B1(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var My=(r,e)=>{function t(n,...o){if(Tt(n),r.nonceLength!==void 0){let h=o[0];if(!h)throw new Error("nonce / iv required");r.varSizeNonce?Tt(h):Tt(h,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Tt(o[1]);let s=e(n,...o),a=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");Tt(p)}},c=!1;return{encrypt(h,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Tt(h),a(s.encrypt.length,p),s.encrypt(h,p)},decrypt(h,p){if(Tt(h),i&&h.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,p),s.decrypt(h,p)}}}return Object.assign(t,r),t};function Ky(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error("invalid output length, expected "+r+", got: "+e.length);if(t&&!XC(e))throw new Error("invalid output, must be aligned");return e}function Hy(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function XC(r){return r.byteOffset%4===0}function yp(r){return Uint8Array.from(r)}function On(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}var N1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),YC=N1("expand 16-byte k"),ZC=N1("expand 32-byte k"),JC=Pn(YC),QC=Pn(ZC);function J(r,e){return r<<e|r>>>32-e}function Vy(r){return r.byteOffset%4===0}var gp=64,eI=16,P1=2**32-1,k1=new Uint32Array;function tI(r,e,t,n,o,i,s,a){let c=o.length,u=new Uint8Array(gp),h=Pn(u),p=Vy(o)&&Vy(i),m=p?Pn(o):k1,w=p?Pn(i):k1;for(let b=0;b<c;s++){if(r(e,t,n,h,s,a),s>=P1)throw new Error("arx: counter overflow");let g=Math.min(gp,c-b);if(p&&g===gp){let y=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let S=0,T;S<eI;S++)T=y+S,w[T]=m[T]^h[S];b+=gp;continue}for(let y=0,S;y<g;y++)S=b+y,i[S]=o[S]^u[y];b+=g}}function $y(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=T1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return dp(o),dp(s),jy(i),jy(t),(a,c,u,h,p=0)=>{Tt(a),Tt(c),Tt(u);let m=u.length;if(h===void 0&&(h=new Uint8Array(m)),Tt(h),dp(p),p<0||p>=P1)throw new Error("arx: counter overflow");if(h.length<m)throw new Error(`arx: output (${h.length}) is shorter than data (${m})`);let w=[],b=a.length,g,y;if(b===32)w.push(g=yp(a)),y=QC;else if(b===16&&t)g=new Uint8Array(32),g.set(a),g.set(a,16),y=JC,w.push(g);else throw new Error(`arx: invalid 32-byte key, got length=${b}`);Vy(c)||w.push(c=yp(c));let S=Pn(g);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(y,S,Pn(c.subarray(0,16)),S),c=c.subarray(16)}let T=16-o;if(T!==c.length)throw new Error(`arx: nonce must be ${T} or 16 bytes`);if(T!==12){let P=new Uint8Array(12);P.set(c,i?0:12-c.length),c=P,w.push(c)}let v=Pn(c);return tI(r,y,S,v,u,h,p,s),On(...w),h}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Fy=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=mp(e),Tt(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),u=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let h=0;h<8;h++)this.pad[h]=xt(e,16+2*h)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],u=s[2],h=s[3],p=s[4],m=s[5],w=s[6],b=s[7],g=s[8],y=s[9],S=xt(e,t+0),T=xt(e,t+2),v=xt(e,t+4),P=xt(e,t+6),W=xt(e,t+8),H=xt(e,t+10),O=xt(e,t+12),K=xt(e,t+14),L=i[0]+(S&8191),te=i[1]+((S>>>13|T<<3)&8191),z=i[2]+((T>>>10|v<<6)&8191),Y=i[3]+((v>>>7|P<<9)&8191),le=i[4]+((P>>>4|W<<12)&8191),R=i[5]+(W>>>1&8191),D=i[6]+((W>>>14|H<<2)&8191),j=i[7]+((H>>>11|O<<5)&8191),k=i[8]+((O>>>8|K<<8)&8191),C=i[9]+(K>>>5|o),I=0,U=I+L*a+te*(5*y)+z*(5*g)+Y*(5*b)+le*(5*w);I=U>>>13,U&=8191,U+=R*(5*m)+D*(5*p)+j*(5*h)+k*(5*u)+C*(5*c),I+=U>>>13,U&=8191;let q=I+L*c+te*a+z*(5*y)+Y*(5*g)+le*(5*b);I=q>>>13,q&=8191,q+=R*(5*w)+D*(5*m)+j*(5*p)+k*(5*h)+C*(5*u),I+=q>>>13,q&=8191;let N=I+L*u+te*c+z*a+Y*(5*y)+le*(5*g);I=N>>>13,N&=8191,N+=R*(5*b)+D*(5*w)+j*(5*m)+k*(5*p)+C*(5*h),I+=N>>>13,N&=8191;let ie=I+L*h+te*u+z*c+Y*a+le*(5*y);I=ie>>>13,ie&=8191,ie+=R*(5*g)+D*(5*b)+j*(5*w)+k*(5*m)+C*(5*p),I+=ie>>>13,ie&=8191;let fe=I+L*p+te*h+z*u+Y*c+le*a;I=fe>>>13,fe&=8191,fe+=R*(5*y)+D*(5*g)+j*(5*b)+k*(5*w)+C*(5*m),I+=fe>>>13,fe&=8191;let Q=I+L*m+te*p+z*h+Y*u+le*c;I=Q>>>13,Q&=8191,Q+=R*a+D*(5*y)+j*(5*g)+k*(5*b)+C*(5*w),I+=Q>>>13,Q&=8191;let ye=I+L*w+te*m+z*p+Y*h+le*u;I=ye>>>13,ye&=8191,ye+=R*c+D*a+j*(5*y)+k*(5*g)+C*(5*b),I+=ye>>>13,ye&=8191;let Be=I+L*b+te*w+z*m+Y*p+le*h;I=Be>>>13,Be&=8191,Be+=R*u+D*c+j*a+k*(5*y)+C*(5*g),I+=Be>>>13,Be&=8191;let Ee=I+L*g+te*b+z*w+Y*m+le*p;I=Ee>>>13,Ee&=8191,Ee+=R*h+D*u+j*c+k*a+C*(5*y),I+=Ee>>>13,Ee&=8191;let Le=I+L*y+te*g+z*b+Y*w+le*m;I=Le>>>13,Le&=8191,Le+=R*p+D*h+j*u+k*c+C*a,I+=Le>>>13,Le&=8191,I=(I<<2)+I|0,I=I+U|0,U=I&8191,I=I>>>13,q+=I,i[0]=U,i[1]=q,i[2]=N,i[3]=ie,i[4]=fe,i[5]=Q,i[6]=ye,i[7]=Be,i[8]=Ee,i[9]=Le}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;On(n)}update(e){Uy(this);let{buffer:t,blockLen:n}=this;e=mp(e);let o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){On(this.h,this.r,this.buffer,this.pad)}digestInto(e){Uy(this),C1(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:o}=this;if(o){for(t[o++]=1;o<16;o++)t[o]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let s=0;s<8;s++)e[i++]=n[s]>>>0,e[i++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function rI(r){let e=(n,o)=>r(o).update(mp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var O1=rI(r=>new Fy(r));function D1(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],u=r[3],h=e[0],p=e[1],m=e[2],w=e[3],b=e[4],g=e[5],y=e[6],S=e[7],T=o,v=t[0],P=t[1],W=t[2],H=s,O=a,K=c,L=u,te=h,z=p,Y=m,le=w,R=b,D=g,j=y,k=S,C=T,I=v,U=P,q=W;for(let ie=0;ie<i;ie+=2)H=H+te|0,C=J(C^H,16),R=R+C|0,te=J(te^R,12),H=H+te|0,C=J(C^H,8),R=R+C|0,te=J(te^R,7),O=O+z|0,I=J(I^O,16),D=D+I|0,z=J(z^D,12),O=O+z|0,I=J(I^O,8),D=D+I|0,z=J(z^D,7),K=K+Y|0,U=J(U^K,16),j=j+U|0,Y=J(Y^j,12),K=K+Y|0,U=J(U^K,8),j=j+U|0,Y=J(Y^j,7),L=L+le|0,q=J(q^L,16),k=k+q|0,le=J(le^k,12),L=L+le|0,q=J(q^L,8),k=k+q|0,le=J(le^k,7),H=H+z|0,q=J(q^H,16),j=j+q|0,z=J(z^j,12),H=H+z|0,q=J(q^H,8),j=j+q|0,z=J(z^j,7),O=O+Y|0,C=J(C^O,16),k=k+C|0,Y=J(Y^k,12),O=O+Y|0,C=J(C^O,8),k=k+C|0,Y=J(Y^k,7),K=K+le|0,I=J(I^K,16),R=R+I|0,le=J(le^R,12),K=K+le|0,I=J(I^K,8),R=R+I|0,le=J(le^R,7),L=L+te|0,U=J(U^L,16),D=D+U|0,te=J(te^D,12),L=L+te|0,U=J(U^L,8),D=D+U|0,te=J(te^D,7);let N=0;n[N++]=s+H|0,n[N++]=a+O|0,n[N++]=c+K|0,n[N++]=u+L|0,n[N++]=h+te|0,n[N++]=p+z|0,n[N++]=m+Y|0,n[N++]=w+le|0,n[N++]=b+R|0,n[N++]=g+D|0,n[N++]=y+j|0,n[N++]=S+k|0,n[N++]=T+C|0,n[N++]=v+I|0,n[N++]=P+U|0,n[N++]=W+q|0}function nI(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],u=e[1],h=e[2],p=e[3],m=e[4],w=e[5],b=e[6],g=e[7],y=t[0],S=t[1],T=t[2],v=t[3];for(let W=0;W<20;W+=2)o=o+c|0,y=J(y^o,16),m=m+y|0,c=J(c^m,12),o=o+c|0,y=J(y^o,8),m=m+y|0,c=J(c^m,7),i=i+u|0,S=J(S^i,16),w=w+S|0,u=J(u^w,12),i=i+u|0,S=J(S^i,8),w=w+S|0,u=J(u^w,7),s=s+h|0,T=J(T^s,16),b=b+T|0,h=J(h^b,12),s=s+h|0,T=J(T^s,8),b=b+T|0,h=J(h^b,7),a=a+p|0,v=J(v^a,16),g=g+v|0,p=J(p^g,12),a=a+p|0,v=J(v^a,8),g=g+v|0,p=J(p^g,7),o=o+u|0,v=J(v^o,16),b=b+v|0,u=J(u^b,12),o=o+u|0,v=J(v^o,8),b=b+v|0,u=J(u^b,7),i=i+h|0,y=J(y^i,16),g=g+y|0,h=J(h^g,12),i=i+h|0,y=J(y^i,8),g=g+y|0,h=J(h^g,7),s=s+p|0,S=J(S^s,16),m=m+S|0,p=J(p^m,12),s=s+p|0,S=J(S^s,8),m=m+S|0,p=J(p^m,7),a=a+c|0,T=J(T^a,16),w=w+T|0,c=J(c^w,12),a=a+c|0,T=J(T^a,8),w=w+T|0,c=J(c^w,7);let P=0;n[P++]=o,n[P++]=i,n[P++]=s,n[P++]=a,n[P++]=y,n[P++]=S,n[P++]=T,n[P++]=v}var oI=$y(D1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),iI=$y(D1,{counterRight:!1,counterLength:8,extendNonceFn:nI,allowShortKeys:!1});var sI=new Uint8Array(16),R1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(sI.subarray(t))},aI=new Uint8Array(32);function L1(r,e,t,n,o){let i=r(e,t,aI),s=O1.create(i);o&&R1(s,o),R1(s,n);let a=new Uint8Array(16),c=I1(a);Hy(c,0,BigInt(o?o.length:0),!0),Hy(c,8,BigInt(n.length),!0),s.update(a);let u=s.digest();return On(i,a),u}var U1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Ky(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let u=L1(r,e,t,c,n);return s.set(u,a),On(u),s},decrypt(i,s){s=Ky(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=L1(r,e,t,a,n);if(!B1(c,u))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),On(u),s}}),Wy=My({blockSize:64,nonceLength:12,tagLength:16},U1(oI)),fX=My({blockSize:64,nonceLength:24,tagLength:16},U1(iI));function M1(r,e,t){return ua(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Qi(r,Mn(t),Mn(e))}var qy=new Uint8Array([0]),j1=new Uint8Array;function K1(r,e,t,n=32){if(ua(r),Nl(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/r.outputLen);t===void 0&&(t=j1);let i=new Uint8Array(o*r.outputLen),s=Qi.create(r,e),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let u=0;u<o;u++)qy[0]=u+1,a.update(u===0?j1:c).update(t).update(qy).digestInto(c),i.set(c,r.outputLen*u),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),qy.fill(0),i.slice(0,n)}var Gy={hashSHA256(r){return vr(r.subarray())},getHKDF(r,e){let t=M1(vr,e,r),o=K1(vr,t,void 0,96),i=o.subarray(0,32),s=o.subarray(32,64),a=o.subarray(64,96);return[i,s,a]},generateX25519KeyPair(){let r=ga.utils.randomPrivateKey();return{publicKey:ga.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:ga.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return ga.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Wy(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Wy(n,e,t).decrypt(r.subarray(),o)}};var H1=Gy;function V1(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var Zs=r=>{let e=et(2);return e[0]=r>>8,e[1]=r,e};Zs.bytes=2;var al=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};al.bytes=2;function $1(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function zy(r,e){!e.enabled||!Ys||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local static keys."))}function Xy(r,e){!e.enabled||!Ys||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function F1(r,e){!e.enabled||!Ys||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote static public key.")}function Yy(r,e){!e.enabled||!Ys||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Zy(r,e,t){!t.enabled||!Ys||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ce(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ce(e.k,"hex")}`))}var Js=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var cI=0,lI=4294967295,uI="Cipherstate has reached maximum n, a new handshake must be performed",wp=class{n;bytes;view;constructor(e=cI){this.n=e,this.bytes=it(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>lI)throw new Error(uI)}};var Mi=it(0),Qs=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new wp(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},Jy=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=fI(e,n),this.ck=this.h,this.cs=new Qs(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Qs(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new ue(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Mi);return[new Qs(this.crypto,e),new Qs(this.crypto,t)]}},Qy=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:u}=e;this.crypto=t,this.ss=new Jy(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},cl=class extends Qy{writeMessageA(e){return new ue(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new ue(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new ue(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new Js(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new Js(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new Js(`handshake stage 2 validation fail: ${t.message}`)}}};function fI(r,e){if(e.length<=32){let t=it(32);return t.set(e),t}else return r.hash(e)}var xp;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let i of t.webtransportCerthashes)n.uint32(10),n.bytes(i);if(t.streamMuxers!=null)for(let i of t.streamMuxers)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={webtransportCerthashes:[],streamMuxers:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&i.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new va('Decode error - map field "webtransportCerthashes" had too many elements');i.webtransportCerthashes.push(t.bytes());break}case 2:{if(o.limits?.streamMuxers!=null&&i.streamMuxers.length===o.limits.streamMuxers)throw new va('Decode error - map field "streamMuxers" had too many elements');i.streamMuxers.push(t.string());break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(xp||(xp={}));var ll;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),xp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:it(0),identitySig:it(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.identityKey=t.bytes();break}case 2:{i.identitySig=t.bytes();break}case 4:{i.extensions=xp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(ll||(ll={}));async function eg(r,e,t){let n=await r.sign(W1(e));return ll.encode({identityKey:jn(r.publicKey),identitySig:n,extensions:t})}async function tg(r,e,t){try{let n=ll.decode(r),o=Ia(n.identityKey);if(t?.equals(o)===!1)throw new Error(`Payload identity key ${o} does not match expected remote identity key ${t}`);if(!e)throw new Error("Remote static does not exist");let i=W1(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new gl(n.message)}}function W1(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?st([e,r],e.length+r.length):(r.prepend(e),r)}async function q1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,h=await eg(i,a.publicKey,u),p=new cl({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});zy(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(Mi),e),t.trace("Stage 0 - Initiator finished sending first message."),Xy(p.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let m=p.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Yy(p.re,t),F1(p.rs,t),t.trace("Initiator going to check remote's signature...");let w=await tg(m,p.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(p.writeMessageC(h),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[b,g]=p.ss.split();return Zy(b,g,t),{payload:w,encrypt:y=>b.encryptWithAd(Mi,y),decrypt:(y,S)=>g.decryptWithAd(Mi,y,S)}}async function G1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,h=await eg(i,a.publicKey,u),p=new cl({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});zy(p.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),p.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),Yy(p.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(p.writeMessageB(h),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xy(p.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let m=p.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let w=await tg(m,p.rs,c),[b,g]=p.ss.split();return Zy(b,g,t),{payload:w,encrypt:y=>g.encryptWithAd(Mi,y),decrypt:(y,S)=>b.decryptWithAd(Mi,y,S)}}var X1=16;function Y1(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let i=o+65519;i>n.length&&(i=n.length);let s;n instanceof Uint8Array?s=r.encrypt(n.subarray(o,i)):s=r.encrypt(n.sublist(o,i)),e?.encryptedPackets.increment(),yield new ue(Zs(s.byteLength),s)}}}function Z1(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65535){let i=o+65535;if(i>n.length&&(i=n.length),i-X1<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-X1);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var bp=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e;let c=i??H1;this.crypto=V1(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?$1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??it(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Hi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=Oy(e,{lengthEncoder:Zs,lengthDecoder:al,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Ia(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:rd(s),streamMuxer:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new wl("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=Oy(e,{lengthEncoder:Zs,lengthDecoder:al,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Ia(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:rd(s),streamMuxer:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o){let i;try{i=await q1({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:[...this.components.upgrader.getStreamMuxers().keys()],webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return i}async performHandshakeResponder(e,t,n,o){let i;try{i=await G1({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:[...this.components.upgrader.getStreamMuxers().keys()],webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return i}async createSecureConnection(e,t){let[n,o]=v1(),i=e.unwrap();return await S1(n,Y1(t,this.metrics),i,s=>sl(s,{lengthDecoder:al}),Z1(t,this.metrics),n),o}};function J1(r={}){return e=>new bp(e,r)}var rg=Object.values(Bo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),pI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function Q1(r){return r?.match(pI)?.groups?.fingerprint}function ng(r){let t=r.stringTuples().filter(n=>n[0]===Ew).map(n=>n[1])[0];if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function hI(r){return rr.decode(rg.decode(r))}function dI(r){let e=hI(ng(r)),t=mI(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new Iu(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function eA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=At(nr.code,t);return Hr(`/certhash/${To.encode(n.bytes)}`)}function mI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Bu(r)}}function tA(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=dI(r);return{type:"answer",sdp:`v=0
12
+ `)}};Ot.CertificateTag="CERTIFICATE";Ot.CrlTag="CRL";Ot.CertificateRequestTag="CERTIFICATE REQUEST";Ot.PublicKeyTag="PUBLIC KEY";Ot.PrivateKeyTag="PRIVATE KEY";var So=class r extends Ao{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ot.isPem(e))return Ot.decode(e)[0];if(V.Convert.isHex(e))return V.Convert.FromHex(e);if(V.Convert.isBase64(e))return V.Convert.FromBase64(e);if(V.Convert.isBase64Url(e))return V.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=V.Convert.ToBinary(e);return Ot.isPem(t)?Ot.decode(t)[0]:V.Convert.isHex(t)?V.Convert.FromHex(t):V.Convert.isBase64(t)?V.Convert.FromBase64(t):V.Convert.isBase64Url(t)?V.Convert.FromBase64Url(t):V.BufferSourceConverter.toArrayBuffer(e)}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Ot.encode(this.rawData,this.tag);default:return super.toString(e)}}},Tn=class r extends So{static async create(e,t=wt.get()){if(e instanceof r)return e;if(el.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(V.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){So.isAsnEncoded(e)?super(e,ht):super(e),this.tag=Ot.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||wt.get()):t=e[0]||wt.get();let i=this.rawData,s=F.parse(this.rawData,ht);return s.algorithm.algorithm===ho&&(i=_C(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Ue.resolve(Di),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Jr:{let o=F.parse(e.subjectPublicKey,js),i=V.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=V.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=wt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=wt.get();let o=F.parse(this.rawData,ht);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,ht);switch(e.Algorithm=Bn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ei:e["EC Point"]=t.subjectPublicKey;break;case Jr:default:e["Raw Data"]=t.subjectPublicKey}return e}};function _C(r,e){return r.algorithm=new M({algorithm:Jr,parameters:null}),e=F.serialize(r),e}var zf=class r extends yr{static async create(e,t=!1,n=wt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Tn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new Gr({keyIdentifier:new ai(V.Convert.FromHex(e[0]))});super(nf,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Ui?F.parse(t.name.rawData,Ve):t.name,o=new Gr({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(nf,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Gr);t.keyIdentifier&&(this.keyId=V.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?V.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Gr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Ui(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};zf.NAME="Authority Key Identifier";var Ws=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,ci);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new ci({cA:e[0],pathLenConstraint:e[1]});super(of,e[2],F.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};Ws.NAME="Basic Constraints";var Qv;(function(r){r.serverAuth="1.3.6.1.5.5.7.3.1",r.clientAuth="1.3.6.1.5.5.7.3.2",r.codeSigning="1.3.6.1.5.5.7.3.3",r.emailProtection="1.3.6.1.5.5.7.3.4",r.timeStamping="1.3.6.1.5.5.7.3.8",r.ocspSigning="1.3.6.1.5.5.7.3.9"})(Qv||(Qv={}));var Xf=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,gc);this.usages=t.map(n=>n)}else{let t=new gc(e[0]);super(lf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>rn.toString(t)).join(", "),e}};Xf.NAME="Extended Key Usages";var e1;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(e1||(e1={}));var Yf=class extends yr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,ys);this.usages=t.toNumber()}else{let t=new ys(e[0]);super(uf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,ys);return e[""]=t.toJSON().join(", "),e}};Yf.NAME="Key Usages";var Zf=class r extends yr{static async create(e,t=!1,n=wt.get()){let i=await(await Tn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Mt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new Mt(t);super(hm,e[1],F.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Mt);return e[""]=t,e}};Zf.NAME="Subject Key Identifier";var Jf=class extends yr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(fm,e[1],new Ui(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,df);this.names=new Ui(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Jf.NAME="Subject Alternative Name";var Wt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new yr(e),n=this.items.get(t.type);return n?new n(e):t}};Wt.items=new Map;var Qf=class extends yr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,pc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new pc(n.map(s=>new li({policyIdentifier:s})));super(af,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Se("",{},rn.toString(t))),e}};Qf.NAME="Certificate Policies";Wt.register(af,Qf);var ep=class extends yr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new zr({distributionPoint:new An({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new so(o);super(cf,e[1],F.serialize(i))}else{let n=new so(e[0]);super(cf,e[1],F.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,so);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new tn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};ep.NAME="CRL Distribution Points";var tp=class extends yr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof si){let s=new si(e[0]);super(rf,e[1],F.serialize(s))}else{let s=e[0],a=new si;Ff(a,s,Xd,"ocsp"),Ff(a,s,Yd,"caIssuers"),Ff(a,s,Zd,"timeStamping"),Ff(a,s,Jd,"caRepository"),super(rf,e[1],F.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],F.parse(e.extnValue,si).forEach(n=>{switch(n.accessMethod){case Xd:this.ocsp.push(new tn(n.accessLocation));break;case Yd:this.caIssuers.push(new tn(n.accessLocation));break;case Zd:this.timeStamping.push(new tn(n.accessLocation));break;case Jd:this.caRepository.push(new tn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&$f(e,"OCSP",this.ocsp),this.caIssuers.length&&$f(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&$f(e,"Time Stamping",this.timeStamping),this.caRepository.length&&$f(e,"CA Repository",this.caRepository),e}};tp.NAME="Authority Info Access";function $f(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Se("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Se.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function Ff(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new tn("url",s)),r.push(new bn({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var qs=class r extends Ao{constructor(...e){let t;if(V.BufferSourceConverter.isBufferSource(e[0]))t=V.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>V.BufferSourceConverter.toArrayBuffer(i)):[];t=F.serialize(new pt({type:n,values:o}))}super(t,pt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Se("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Se.NAME]===r.NAME&&(e[Se.NAME]=rn.toString(this.type)),e}};qs.NAME="Attribute";var rp=class extends qs{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new Gc({printableString:e[0]});super(cy,[F.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],Gc);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Se.VALUE]=this.password,e}};rp.NAME="Challenge Password";var rl=class extends qs{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new Jt;for(let i of n)o.push(F.parse(i.rawData,dt));super(Xc,[F.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],Jt);this.items=t.map(n=>Wt.create(F.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Se.NAME]]=n;return e}};rl.NAME="Extensions";var Gs=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new qs(e),n=this.items.get(t.type);return n?new n(e):t}};Gs.items=new Map;var ol="crypto.signatureFormatter",vy=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},qf,Ay=qf=class{static createPssParams(e,t){let n=qf.getHashAlgorithm(e);return n?new Qr({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:mo,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Ue.resolve(Di);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:Os,parameters:null});case"sha-256":return new M({algorithm:Cf,parameters:null});case"sha-384":return new M({algorithm:Rs,parameters:null});case"sha-512":return new M({algorithm:Ls,parameters:null})}}else return new M({algorithm:Jr,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let t=qf.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:ho,parameters:F.serialize(t)})}else return new M({algorithm:ho,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Jr:return{name:"RSASSA-PKCS1-v1_5"};case Os:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Cf:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Rs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Ls:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case ho:if(e.parameters){let t=F.parse(e.parameters,Qr);return{name:"RSA-PSS",hash:Ue.resolve(Di).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Ay=qf=l([go()],Ay);Ue.registerSingleton(nl,Ay);var Sy=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Ci});case"sha-256":return new M({algorithm:Ii});case"sha-384":return new M({algorithm:Ti});case"sha-512":return new M({algorithm:Bi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ci:return{name:"SHA-1"};case Ii:return{name:"SHA-256"};case Ti:return{name:"SHA-384"};case Bi:return{name:"SHA-512"}}return null}};Sy=l([go()],Sy);Ue.registerSingleton(nl,Sy);var kn=class r{addPadding(e,t){let n=V.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=V.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new _i,s=V.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),F.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=F.parse(t,_i),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,V.combine)(s,a)}return null}};kn.namedCurveSize=new Map;kn.defaultNamedCurveSize=32;var gy="1.3.101.110",t1="1.3.101.111",wy="1.3.101.112",r1="1.3.101.113",Ey=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=wy;break;case"x25519":t=gy;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=wy;break;case"ed448":t=r1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=gy;break;case"x448":t=t1;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case wy:return{name:"Ed25519"};case r1:return{name:"EdDSA",namedCurve:"Ed448"};case gy:return{name:"X25519"};case t1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Ey=l([go()],Ey);Ue.registerSingleton(nl,Ey);var _y=class extends So{constructor(e){So.isAsnEncoded(e)?super(e,vo):super(e),this.tag=Ot.CertificateRequestTag}onInit(e){this.tbs=F.serialize(e.certificationRequestInfo),this.publicKey=new Tn(e.certificationRequestInfo.subjectPKInfo);let t=Ue.resolve(Di);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>Gs.create(F.serialize(o)));let n=this.getAttribute(Xc);this.extensions=[],n instanceof rl&&(this.extensions=n.items),this.subjectName=new mr(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=wt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Ue.resolveAll(ol).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,vo),n=t.certificationRequestInfo,o=new Se("",{Version:`${Xr[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Se("");for(let s of this.attributes){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Se("",{Algorithm:Bn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};_y.NAME="PKCS#10 Certificate Request";var zs=class extends So{constructor(e){So.isAsnEncoded(e)?super(e,ur):super(e),this.tag=Ot.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=F.serialize(t),this.serialNumber=V.Convert.ToHex(t.serialNumber),this.subjectName=new mr(t.subject),this.subject=new mr(t.subject).toString(),this.issuerName=new mr(t.issuer),this.issuer=this.issuerName.toString();let n=Ue.resolve(Di);this.signatureAlgorithm=n.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let o=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!o)throw new Error("Cannot get 'notBefore' value");this.notBefore=o;let i=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!i)throw new Error("Cannot get 'notAfter' value");this.notAfter=i,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(s=>Wt.create(F.serialize(s)))),this.publicKey=new Tn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=wt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Tn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let u=new Tn(i);n={...u.algorithm,...this.signatureAlgorithm},o=await u.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Ue.resolveAll(ol).reverse(),a=null;for(let u of s)if(a=u.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let h=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<h&&h<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=wt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=wt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,ur),n=t.tbsCertificate,o=new Se("",{Version:`${Xr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Bn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Se("",{"Not Before":n.validity.notBefore.getTime(),"Not After":n.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(n.issuerUniqueID&&(o["Issuer Unique ID"]=n.issuerUniqueID),n.subjectUniqueID&&(o["Subject Unique ID"]=n.subjectUniqueID),this.extensions.length){let i=new Se("");for(let s of this.extensions){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Se("",{Algorithm:Bn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};zs.NAME="Certificate";var np=class{static async createSelfSigned(e,t=wt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=wt.get()){var n;let o;e.publicKey instanceof Tn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:V.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?V.BufferSourceConverter.toUint8Array(V.Convert.FromHex(e.serialNumber)):t.getRandomValues(new Uint8Array(16));i[0]>127&&(i[0]&=127),i.length>1&&i[0]===0&&(i[1]|=128);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new ur({tbsCertificate:new mt({version:Xr.v3,serialNumber:i,validity:new Sn({notBefore:s,notAfter:a}),extensions:new Jt(((n=e.extensions)===null||n===void 0?void 0:n.map(m=>F.parse(m.rawData,dt)))||[]),subjectPublicKeyInfo:F.parse(o,ht)})});if(e.subject){let m=e.subject instanceof mr?e.subject:new mr(e.subject);c.tbsCertificate.subject=F.parse(m.toArrayBuffer(),Ne)}if(e.issuer){let m=e.issuer instanceof mr?e.issuer:new mr(e.issuer);c.tbsCertificate.issuer=F.parse(m.toArrayBuffer(),Ne)}let u={hash:"SHA-256"},h="signingKey"in e?{...u,...e.signingAlgorithm,...e.signingKey.algorithm}:{...u,...e.signingAlgorithm},p=Ue.resolve(Di);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(h);let y=F.serialize(c.tbsCertificate),w="signingKey"in e?await t.subtle.sign(h,e.signingKey,y):e.signature,b=Ue.resolveAll(ol).reverse(),g=null;for(let m of b)if(g=m.toAsnSignature(h,w),g)break;if(!g)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=g,new zs(F.serialize(c))}},n1;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(n1||(n1={}));Wt.register(of,Ws);Wt.register(lf,Xf);Wt.register(uf,Yf);Wt.register(hm,Zf);Wt.register(nf,zf);Wt.register(fm,Jf);Wt.register(cf,ep);Wt.register(rf,tp);Gs.register(cy,rp);Gs.register(Xc,rl);Ue.registerSingleton(ol,vy);Ue.registerSingleton(ol,kn);kn.namedCurveSize.set("P-256",32);kn.namedCurveSize.set("K-256",32);kn.namedCurveSize.set("P-384",48);kn.namedCurveSize.set("P-521",66);var Pn="/",c1=new TextEncoder().encode(Pn),op=c1[0],il=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=de(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==op)throw new Error("Invalid key")}toString(e="utf8"){return ce(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Pn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=c1),this._buf[0]!==op){let e=new Uint8Array(this._buf.byteLength+1);e.fill(op,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===op;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Pn).slice(1)}type(){return CC(this.baseNamespace())}name(){return IC(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Pn)||(e+=Pn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Pn):new r(e.slice(0,-1).join(Pn))}child(e){return this.toString()===Pn?e:e.toString()===Pn?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...TC(e.map(t=>t.namespaces()))])}};function CC(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function IC(r){let e=r.split(":");return e[e.length-1]}function TC(r){return[].concat(...r)}var ip=class extends Ln{async listen(){throw new Bu("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var sp=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ap=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},sl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function cp(r){return r[Symbol.asyncIterator]!=null}function l1(r,e){if(r.byteLength>e)throw new Xs("Message length too long")}var up=r=>{let e=Be(r),t=et(e);return rr(r,t),up.bytes=e,t};up.bytes=0;function u1(r,e){e=e??{};let t=e.lengthEncoder??up,n=e?.maxDataLength??4194304;function*o(i){l1(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return cp(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}u1.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??up,n=e?.maxDataLength??4194304;return l1(r,n),new he(t(r.byteLength),r)};var ji;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ji||(ji={}));var Cy=r=>{let e=zt(r);return Cy.bytes=Be(e),e};Cy.bytes=0;function al(r,e){let t=new he,n=ji.LENGTH,o=-1,i=e?.lengthDecoder??Cy,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===ji.LENGTH)try{if(o=i(t),o<0)throw new sp("Invalid message length");if(o>a)throw new Xs("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=ji.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new ap("Message length length too long");break}throw u}if(n===ji.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=ji.LENGTH}}}return cp(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new sl("Unexpected end of input")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new sl("Unexpected end of input")}()}al.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return al(n,{...e??{},onLength:i=>{t=i}})};function Iy(){let r=Ge(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function f1(){let r=Iy(),e=Iy();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function kC(r){return r[Symbol.asyncIterator]!=null}async function PC(r,e){try{await Promise.all(r.map(async t=>{for await(let n of t)await e.push(n)})),await e.end()}catch(t){await e.end(t).catch(()=>{})}}async function*NC(r){let e=Au();PC(r,e).catch(()=>{}),yield*e}function*OC(r){for(let e of r)yield*e}function RC(...r){let e=[];for(let t of r)kC(t)||e.push(t);return e.length===r.length?OC(e):NC(r)}var p1=RC;function h1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Ty(r)){let n=r;r=()=>n.source}else if(m1(r)||d1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Ty(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Ty(t[n])&&(t[n]=DC(t[n]));return LC(...t)}var LC=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},d1=r=>r?.[Symbol.asyncIterator]!=null,m1=r=>r?.[Symbol.iterator]!=null,Ty=r=>r==null?!1:r.sink!=null&&r.source!=null,DC=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=ss({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(d1(i))o=async function*(){yield*i,n.end()};else if(m1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return p1(n,o())}return r.source};var Ys=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function fp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function By(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Tt(r,...e){if(!By(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function ky(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function y1(r,e){Tt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Py(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}var Nn=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),g1=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),UC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!UC)throw new Error("Non little-endian hardware is not supported");function jC(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function pp(r){if(typeof r=="string")r=jC(r);else if(By(r))r=hp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function w1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function x1(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var Ny=(r,e)=>{function t(n,...o){if(Tt(n),r.nonceLength!==void 0){let h=o[0];if(!h)throw new Error("nonce / iv required");r.varSizeNonce?Tt(h):Tt(h,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Tt(o[1]);let s=e(n,...o),a=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");Tt(p)}},c=!1;return{encrypt(h,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Tt(h),a(s.encrypt.length,p),s.encrypt(h,p)},decrypt(h,p){if(Tt(h),i&&h.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,p),s.decrypt(h,p)}}}return Object.assign(t,r),t};function Oy(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error("invalid output length, expected "+r+", got: "+e.length);if(t&&!MC(e))throw new Error("invalid output, must be aligned");return e}function Ry(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function MC(r){return r.byteOffset%4===0}function hp(r){return Uint8Array.from(r)}function On(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}var v1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),KC=v1("expand 16-byte k"),HC=v1("expand 32-byte k"),VC=Nn(KC),$C=Nn(HC);function J(r,e){return r<<e|r>>>32-e}function Ly(r){return r.byteOffset%4===0}var dp=64,FC=16,A1=2**32-1,b1=new Uint32Array;function WC(r,e,t,n,o,i,s,a){let c=o.length,u=new Uint8Array(dp),h=Nn(u),p=Ly(o)&&Ly(i),y=p?Nn(o):b1,w=p?Nn(i):b1;for(let b=0;b<c;s++){if(r(e,t,n,h,s,a),s>=A1)throw new Error("arx: counter overflow");let g=Math.min(dp,c-b);if(p&&g===dp){let m=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let S=0,T;S<FC;S++)T=m+S,w[T]=y[T]^h[S];b+=dp;continue}for(let m=0,S;m<g;m++)S=b+m,i[S]=o[S]^u[m];b+=g}}function Dy(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=w1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return fp(o),fp(s),Py(i),Py(t),(a,c,u,h,p=0)=>{Tt(a),Tt(c),Tt(u);let y=u.length;if(h===void 0&&(h=new Uint8Array(y)),Tt(h),fp(p),p<0||p>=A1)throw new Error("arx: counter overflow");if(h.length<y)throw new Error(`arx: output (${h.length}) is shorter than data (${y})`);let w=[],b=a.length,g,m;if(b===32)w.push(g=hp(a)),m=$C;else if(b===16&&t)g=new Uint8Array(32),g.set(a),g.set(a,16),m=VC,w.push(g);else throw new Error(`arx: invalid 32-byte key, got length=${b}`);Ly(c)||w.push(c=hp(c));let S=Nn(g);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(m,S,Nn(c.subarray(0,16)),S),c=c.subarray(16)}let T=16-o;if(T!==c.length)throw new Error(`arx: nonce must be ${T} or 16 bytes`);if(T!==12){let N=new Uint8Array(12);N.set(c,i?0:12-c.length),c=N,w.push(c)}let v=Nn(c);return WC(r,m,S,v,u,h,p,s),On(...w),h}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Uy=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=pp(e),Tt(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),u=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let h=0;h<8;h++)this.pad[h]=xt(e,16+2*h)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],u=s[2],h=s[3],p=s[4],y=s[5],w=s[6],b=s[7],g=s[8],m=s[9],S=xt(e,t+0),T=xt(e,t+2),v=xt(e,t+4),N=xt(e,t+6),W=xt(e,t+8),H=xt(e,t+10),O=xt(e,t+12),K=xt(e,t+14),L=i[0]+(S&8191),te=i[1]+((S>>>13|T<<3)&8191),z=i[2]+((T>>>10|v<<6)&8191),Y=i[3]+((v>>>7|N<<9)&8191),le=i[4]+((N>>>4|W<<12)&8191),R=i[5]+(W>>>1&8191),D=i[6]+((W>>>14|H<<2)&8191),j=i[7]+((H>>>11|O<<5)&8191),k=i[8]+((O>>>8|K<<8)&8191),C=i[9]+(K>>>5|o),I=0,U=I+L*a+te*(5*m)+z*(5*g)+Y*(5*b)+le*(5*w);I=U>>>13,U&=8191,U+=R*(5*y)+D*(5*p)+j*(5*h)+k*(5*u)+C*(5*c),I+=U>>>13,U&=8191;let q=I+L*c+te*a+z*(5*m)+Y*(5*g)+le*(5*b);I=q>>>13,q&=8191,q+=R*(5*w)+D*(5*y)+j*(5*p)+k*(5*h)+C*(5*u),I+=q>>>13,q&=8191;let P=I+L*u+te*c+z*a+Y*(5*m)+le*(5*g);I=P>>>13,P&=8191,P+=R*(5*b)+D*(5*w)+j*(5*y)+k*(5*p)+C*(5*h),I+=P>>>13,P&=8191;let ie=I+L*h+te*u+z*c+Y*a+le*(5*m);I=ie>>>13,ie&=8191,ie+=R*(5*g)+D*(5*b)+j*(5*w)+k*(5*y)+C*(5*p),I+=ie>>>13,ie&=8191;let ue=I+L*p+te*h+z*u+Y*c+le*a;I=ue>>>13,ue&=8191,ue+=R*(5*m)+D*(5*g)+j*(5*b)+k*(5*w)+C*(5*y),I+=ue>>>13,ue&=8191;let Q=I+L*y+te*p+z*h+Y*u+le*c;I=Q>>>13,Q&=8191,Q+=R*a+D*(5*m)+j*(5*g)+k*(5*b)+C*(5*w),I+=Q>>>13,Q&=8191;let ye=I+L*w+te*y+z*p+Y*h+le*u;I=ye>>>13,ye&=8191,ye+=R*c+D*a+j*(5*m)+k*(5*g)+C*(5*b),I+=ye>>>13,ye&=8191;let Te=I+L*b+te*w+z*y+Y*p+le*h;I=Te>>>13,Te&=8191,Te+=R*u+D*c+j*a+k*(5*m)+C*(5*g),I+=Te>>>13,Te&=8191;let Ee=I+L*g+te*b+z*w+Y*y+le*p;I=Ee>>>13,Ee&=8191,Ee+=R*h+D*u+j*c+k*a+C*(5*m),I+=Ee>>>13,Ee&=8191;let Re=I+L*m+te*g+z*b+Y*w+le*y;I=Re>>>13,Re&=8191,Re+=R*p+D*h+j*u+k*c+C*a,I+=Re>>>13,Re&=8191,I=(I<<2)+I|0,I=I+U|0,U=I&8191,I=I>>>13,q+=I,i[0]=U,i[1]=q,i[2]=P,i[3]=ie,i[4]=ue,i[5]=Q,i[6]=ye,i[7]=Te,i[8]=Ee,i[9]=Re}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;On(n)}update(e){ky(this);let{buffer:t,blockLen:n}=this;e=pp(e);let o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){On(this.h,this.r,this.buffer,this.pad)}digestInto(e){ky(this),y1(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:o}=this;if(o){for(t[o++]=1;o<16;o++)t[o]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let s=0;s<8;s++)e[i++]=n[s]>>>0,e[i++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function qC(r){let e=(n,o)=>r(o).update(pp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var S1=qC(r=>new Uy(r));function C1(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],u=r[3],h=e[0],p=e[1],y=e[2],w=e[3],b=e[4],g=e[5],m=e[6],S=e[7],T=o,v=t[0],N=t[1],W=t[2],H=s,O=a,K=c,L=u,te=h,z=p,Y=y,le=w,R=b,D=g,j=m,k=S,C=T,I=v,U=N,q=W;for(let ie=0;ie<i;ie+=2)H=H+te|0,C=J(C^H,16),R=R+C|0,te=J(te^R,12),H=H+te|0,C=J(C^H,8),R=R+C|0,te=J(te^R,7),O=O+z|0,I=J(I^O,16),D=D+I|0,z=J(z^D,12),O=O+z|0,I=J(I^O,8),D=D+I|0,z=J(z^D,7),K=K+Y|0,U=J(U^K,16),j=j+U|0,Y=J(Y^j,12),K=K+Y|0,U=J(U^K,8),j=j+U|0,Y=J(Y^j,7),L=L+le|0,q=J(q^L,16),k=k+q|0,le=J(le^k,12),L=L+le|0,q=J(q^L,8),k=k+q|0,le=J(le^k,7),H=H+z|0,q=J(q^H,16),j=j+q|0,z=J(z^j,12),H=H+z|0,q=J(q^H,8),j=j+q|0,z=J(z^j,7),O=O+Y|0,C=J(C^O,16),k=k+C|0,Y=J(Y^k,12),O=O+Y|0,C=J(C^O,8),k=k+C|0,Y=J(Y^k,7),K=K+le|0,I=J(I^K,16),R=R+I|0,le=J(le^R,12),K=K+le|0,I=J(I^K,8),R=R+I|0,le=J(le^R,7),L=L+te|0,U=J(U^L,16),D=D+U|0,te=J(te^D,12),L=L+te|0,U=J(U^L,8),D=D+U|0,te=J(te^D,7);let P=0;n[P++]=s+H|0,n[P++]=a+O|0,n[P++]=c+K|0,n[P++]=u+L|0,n[P++]=h+te|0,n[P++]=p+z|0,n[P++]=y+Y|0,n[P++]=w+le|0,n[P++]=b+R|0,n[P++]=g+D|0,n[P++]=m+j|0,n[P++]=S+k|0,n[P++]=T+C|0,n[P++]=v+I|0,n[P++]=N+U|0,n[P++]=W+q|0}function GC(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],u=e[1],h=e[2],p=e[3],y=e[4],w=e[5],b=e[6],g=e[7],m=t[0],S=t[1],T=t[2],v=t[3];for(let W=0;W<20;W+=2)o=o+c|0,m=J(m^o,16),y=y+m|0,c=J(c^y,12),o=o+c|0,m=J(m^o,8),y=y+m|0,c=J(c^y,7),i=i+u|0,S=J(S^i,16),w=w+S|0,u=J(u^w,12),i=i+u|0,S=J(S^i,8),w=w+S|0,u=J(u^w,7),s=s+h|0,T=J(T^s,16),b=b+T|0,h=J(h^b,12),s=s+h|0,T=J(T^s,8),b=b+T|0,h=J(h^b,7),a=a+p|0,v=J(v^a,16),g=g+v|0,p=J(p^g,12),a=a+p|0,v=J(v^a,8),g=g+v|0,p=J(p^g,7),o=o+u|0,v=J(v^o,16),b=b+v|0,u=J(u^b,12),o=o+u|0,v=J(v^o,8),b=b+v|0,u=J(u^b,7),i=i+h|0,m=J(m^i,16),g=g+m|0,h=J(h^g,12),i=i+h|0,m=J(m^i,8),g=g+m|0,h=J(h^g,7),s=s+p|0,S=J(S^s,16),y=y+S|0,p=J(p^y,12),s=s+p|0,S=J(S^s,8),y=y+S|0,p=J(p^y,7),a=a+c|0,T=J(T^a,16),w=w+T|0,c=J(c^w,12),a=a+c|0,T=J(T^a,8),w=w+T|0,c=J(c^w,7);let N=0;n[N++]=o,n[N++]=i,n[N++]=s,n[N++]=a,n[N++]=m,n[N++]=S,n[N++]=T,n[N++]=v}var zC=Dy(C1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),XC=Dy(C1,{counterRight:!1,counterLength:8,extendNonceFn:GC,allowShortKeys:!1});var YC=new Uint8Array(16),E1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(YC.subarray(t))},ZC=new Uint8Array(32);function _1(r,e,t,n,o){let i=r(e,t,ZC),s=S1.create(i);o&&E1(s,o),E1(s,n);let a=new Uint8Array(16),c=g1(a);Ry(c,0,BigInt(o?o.length:0),!0),Ry(c,8,BigInt(n.length),!0),s.update(a);let u=s.digest();return On(i,a),u}var I1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Oy(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let u=_1(r,e,t,c,n);return s.set(u,a),On(u),s},decrypt(i,s){s=Oy(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=_1(r,e,t,a,n);if(!x1(c,u))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),On(u),s}}),jy=Ny({blockSize:64,nonceLength:12,tagLength:16},I1(zC)),$z=Ny({blockSize:64,nonceLength:24,tagLength:16},I1(XC));function B1(r,e,t){return ua(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Qi(r,Mn(t),Mn(e))}var My=new Uint8Array([0]),T1=new Uint8Array;function k1(r,e,t,n=32){if(ua(r),Nl(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(n/r.outputLen);t===void 0&&(t=T1);let i=new Uint8Array(o*r.outputLen),s=Qi.create(r,e),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let u=0;u<o;u++)My[0]=u+1,a.update(u===0?T1:c).update(t).update(My).digestInto(c),i.set(c,r.outputLen*u),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),My.fill(0),i.slice(0,n)}var Ky={hashSHA256(r){return vr(r.subarray())},getHKDF(r,e){let t=B1(vr,e,r),o=k1(vr,t,void 0,96),i=o.subarray(0,32),s=o.subarray(32,64),a=o.subarray(64,96);return[i,s,a]},generateX25519KeyPair(){let r=ga.utils.randomPrivateKey();return{publicKey:ga.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:ga.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return ga.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return jy(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return jy(n,e,t).decrypt(r.subarray(),o)}};var P1=Ky;function N1(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var Zs=r=>{let e=et(2);return e[0]=r>>8,e[1]=r,e};Zs.bytes=2;var cl=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};cl.bytes=2;function O1(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Hy(r,e){!e.enabled||!Ys||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local static keys."))}function Vy(r,e){!e.enabled||!Ys||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function R1(r,e){!e.enabled||!Ys||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote static public key.")}function $y(r,e){!e.enabled||!Ys||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Fy(r,e,t){!t.enabled||!Ys||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ce(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ce(e.k,"hex")}`))}var Js=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var JC=0,QC=4294967295,eI="Cipherstate has reached maximum n, a new handshake must be performed",mp=class{n;bytes;view;constructor(e=JC){this.n=e,this.bytes=it(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>QC)throw new Error(eI)}};var Mi=it(0),Qs=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new mp(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},Wy=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=tI(e,n),this.ck=this.h,this.cs=new Qs(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Qs(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new he(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Mi);return[new Qs(this.crypto,e),new Qs(this.crypto,t)]}},qy=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:u}=e;this.crypto=t,this.ss=new Wy(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=u}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},ll=class extends qy{writeMessageA(e){return new he(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new he(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new he(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new Js(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new Js(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new Js(`handshake stage 2 validation fail: ${t.message}`)}}};function tI(r,e){if(e.length<=32){let t=it(32);return t.set(e),t}else return r.hash(e)}var yp;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let i of t.webtransportCerthashes)n.uint32(10),n.bytes(i);if(t.streamMuxers!=null)for(let i of t.streamMuxers)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={webtransportCerthashes:[],streamMuxers:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&i.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new va('Decode error - map field "webtransportCerthashes" had too many elements');i.webtransportCerthashes.push(t.bytes());break}case 2:{if(o.limits?.streamMuxers!=null&&i.streamMuxers.length===o.limits.streamMuxers)throw new va('Decode error - map field "streamMuxers" had too many elements');i.streamMuxers.push(t.string());break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(yp||(yp={}));var ul;(function(r){let e;r.codec=()=>(e==null&&(e=Cr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),yp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:it(0),identitySig:it(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.identityKey=t.bytes();break}case 2:{i.identitySig=t.bytes();break}case 4:{i.extensions=yp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>_r(t,r.codec()),r.decode=(t,n)=>Er(t,r.codec(),n)})(ul||(ul={}));async function Gy(r,e,t){let n=await r.sign(L1(e));return ul.encode({identityKey:jn(r.publicKey),identitySig:n,extensions:t})}async function zy(r,e,t){try{let n=ul.decode(r),o=Ia(n.identityKey);if(t?.equals(o)===!1)throw new Error(`Payload identity key ${o} does not match expected remote identity key ${t}`);if(!e)throw new Error("Remote static does not exist");let i=L1(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new wl(n.message)}}function L1(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?st([e,r],e.length+r.length):(r.prepend(e),r)}async function D1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,h=await Gy(i,a.publicKey,u),p=new ll({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Hy(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(Mi),e),t.trace("Stage 0 - Initiator finished sending first message."),Vy(p.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let y=p.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),$y(p.re,t),R1(p.rs,t),t.trace("Initiator going to check remote's signature...");let w=await zy(y,p.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(p.writeMessageC(h),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[b,g]=p.ss.split();return Fy(b,g,t),{payload:w,encrypt:m=>b.encryptWithAd(Mi,m),decrypt:(m,S)=>g.decryptWithAd(Mi,m,S)}}async function U1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,h=await Gy(i,a.publicKey,u),p=new ll({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Hy(p.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),p.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),$y(p.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(p.writeMessageB(h),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Vy(p.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let y=p.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let w=await zy(y,p.rs,c),[b,g]=p.ss.split();return Fy(b,g,t),{payload:w,encrypt:m=>g.encryptWithAd(Mi,m),decrypt:(m,S)=>b.decryptWithAd(Mi,m,S)}}var M1=16;function K1(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let i=o+65519;i>n.length&&(i=n.length);let s;n instanceof Uint8Array?s=r.encrypt(n.subarray(o,i)):s=r.encrypt(n.sublist(o,i)),e?.encryptedPackets.increment(),yield new he(Zs(s.byteLength),s)}}}function H1(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65535){let i=o+65535;if(i>n.length&&(i=n.length),i-M1<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-M1);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var gp=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e;let c=i??P1;this.crypto=N1(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?O1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??it(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Hi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=$a(e,{lengthEncoder:Zs,lengthDecoder:cl,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Ia(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:Qh(s),streamMuxer:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new xl("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=$a(e,{lengthEncoder:Zs,lengthDecoder:cl,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Ia(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:Qh(s),streamMuxer:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o){let i;try{i=await D1({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:[...this.components.upgrader.getStreamMuxers().keys()],webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return i}async performHandshakeResponder(e,t,n,o){let i;try{i=await U1({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:[...this.components.upgrader.getStreamMuxers().keys()],webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(s){throw this.metrics?.xxHandshakeErrors.increment(),s}return i}async createSecureConnection(e,t){let[n,o]=f1(),i=e.unwrap();return await h1(n,K1(t,this.metrics),i,s=>al(s,{lengthDecoder:cl}),H1(t,this.metrics),n),o}};function V1(r={}){return e=>new gp(e,r)}var Xy=Object.values(To).map(r=>r.decoder).reduce((r,e)=>r.or(e)),rI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function $1(r){return r?.match(rI)?.groups?.fingerprint}function Yy(r){let t=r.stringTuples().filter(n=>n[0]===gw).map(n=>n[1])[0];if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function nI(r){return er.decode(Xy.decode(r))}function oI(r){let e=nI(Yy(r)),t=iI(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new Tu(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function F1(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=At(tr.code,t);return Hr(`/certhash/${Io.encode(n.bytes)}`)}function iI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new ku(r)}}function W1(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=oI(r);return{type:"answer",sdp:`v=0
13
13
  o=- 0 0 IN IP${o} ${t}
14
14
  s=-
15
15
  t=0 0
@@ -26,7 +26,7 @@ a=sctp-port:5000
26
26
  a=max-message-size:${os}
27
27
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
28
28
  a=end-of-candidates
29
- `}}function rA(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
29
+ `}}function q1(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
30
30
  o=- 0 0 IN IP${o} ${t}
31
31
  s=-
32
32
  c=IN IP${o} ${t}
@@ -42,13 +42,13 @@ a=sctp-port:5000
42
42
  a=max-message-size:${os}
43
43
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
44
44
  a=end-of-candidates
45
- `}}function og(r,e){if(r.sdp===void 0)throw new ve("Can't munge a missing SDP");let t=r.sdp.includes(`\r
45
+ `}}function Zy(r,e){if(r.sdp===void 0)throw new ve("Can't munge a missing SDP");let t=r.sdp.includes(`\r
46
46
  `)?`\r
47
47
  `:`
48
48
  `;return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
49
49
  a=ice-ufrag:`+e+t).replace(/\na=ice-pwd:[^\n]*\n/,`
50
- a=ice-pwd:`+e+t),r}var ig=de("libp2p-webrtc-noise:");function oA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=At(nr.code,o),s=rg.decode(ng(e)),a=ig.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?st([ig,s,i.bytes],a):st([ig,i.bytes,s],a)}var yI=ja?"iceconnectionstatechange":"connectionstatechange";async function iA(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let p=await r.createOffer();t.log.trace("client created local offer %s",p.sdp);let m=og(p,e);t.log.trace("client setting local offer %s",m.sdp),await r.setLocalDescription(m);let w=tA(t.remoteAddr,e);t.log.trace("client setting server description %s",w.sdp),await r.setRemoteDescription(w)}else{let p=rA(t.remoteAddr,e);t.log.trace("server setting client %s %s",p.type,p.sdp),await r.setRemoteDescription(p),t.log.trace("server creating local answer");let m=await r.createAnswer();t.log.trace("server created local answer");let w=og(m,e);t.log.trace("server setting local description %s",m.sdp),await r.setLocalDescription(w)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await Va(n,"open",t.signal)),t.log.trace("%s handshake channel opened",t.role),t.role==="server"){let p=r.remoteFingerprint()?.value??"";t.remoteAddr=t.remoteAddr.encapsulate(eA(p))}let o=Q1(r.localDescription?.sdp);if(o==null)throw new Jn("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=oA(o,t.remoteAddr,t.role),s=J1({prologueBytes:i})(t),a=cs({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new Ko(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(yI,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":c.close().catch(p=>{t.log.error("error closing connection",p),c.abort(p)});break;default:break}}),t.events?.increment({peer_connection:!0});let u=new Zn(t,{peerConnection:r,metrics:t.events,dataChannelOptions:t.dataChannel});if(t.role==="client")return t.log.trace("%s secure inbound",t.role),await s.secureInbound(a,{remotePeer:t.remotePeerId,signal:t.signal}),t.log.trace("%s closing handshake datachannel",t.role),n.close(),t.log.trace("%s upgrade outbound",t.role),await t.upgrader.upgradeOutbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:u,signal:t.signal});t.log.trace("%s secure outbound",t.role);let h=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${h.remotePeer}`),t.log.trace("%s upgrade inbound",t.role),await t.upgrader.upgradeInbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:u,signal:t.signal})}catch(o){throw n.close(),o}}async function sA(r,e,t,n){n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t=="function"?await t():t;return new RTCPeerConnection({...o??{},certificates:[n]})}async function aA(r){let e=await Xl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ce(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
- `)}var vp=class{log;metrics;components;init;certificate;privateKey;emitter;renewCertificateTask;constructor(e,t={}){if(this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,this.emitter=new Ln,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new ve("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[yl]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Hi]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getPeerId();o!=null&&(n=es(o));let i=$w(),s=await sA("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await iA(s,i,{role:"client",log:this.log,logger:this.components.logger,metrics:this.components.metrics,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeerId:n,privateKey:this.components.privateKey})}catch(a){throw s.close(),a}}createListener(e){if(this.certificate==null)throw new _l;return new op(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(ww.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(gI(this.init.certificate))return this.log("using provided TLS certificate"),this.init.certificate;let t=await this.loadOrCreatePrivateKey(),{pem:n,certhash:o}=await this.loadOrCreateCertificate(t,e);return{privateKey:await aA(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Pw,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Co;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await Y0("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new ol(this.init.certificateDatastoreKey??Nw),i=await Xl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Co;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??Ed)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:To.encode((await nr.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new zs(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??Ed);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Co;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!Ge(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new Co;return this.log("loaded certificate, expiry time is %o",i),o}async createCertificate(e,t){let n=new Date,o=new Date(Date.now()+(this.init.certificateLifespan??Ow));n.setMilliseconds(0),o.setMilliseconds(0);let i=await rp.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new Ws(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,de(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function gI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function wI(r){return e=>new vp(e,r)}function xI(r){return e=>new Ou(e,r)}return AA(bI);})();
50
+ a=ice-pwd:`+e+t),r}var Jy=de("libp2p-webrtc-noise:");function z1(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=At(tr.code,o),s=Xy.decode(Yy(e)),a=Jy.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?st([Jy,s,i.bytes],a):st([Jy,i.bytes,s],a)}var sI=ja?"iceconnectionstatechange":"connectionstatechange";async function X1(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let p=await r.createOffer();t.log.trace("client created local offer %s",p.sdp);let y=Zy(p,e);t.log.trace("client setting local offer %s",y.sdp),await r.setLocalDescription(y);let w=W1(t.remoteAddr,e);t.log.trace("client setting server description %s",w.sdp),await r.setRemoteDescription(w)}else{let p=q1(t.remoteAddr,e);t.log.trace("server setting client %s %s",p.type,p.sdp),await r.setRemoteDescription(p),t.log.trace("server creating local answer");let y=await r.createAnswer();t.log.trace("server created local answer");let w=Zy(y,e);t.log.trace("server setting local description %s",y.sdp),await r.setLocalDescription(w)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await Va(n,"open",t.signal)),t.log.trace("%s handshake channel opened",t.role),t.role==="server"){let p=r.remoteFingerprint()?.value??"";t.remoteAddr=t.remoteAddr.encapsulate(F1(p))}let o=$1(r.localDescription?.sdp);if(o==null)throw new Zn("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=z1(o,t.remoteAddr,t.role),s=V1({prologueBytes:i})(t),a=cs({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new Ko(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(sI,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":c.close().catch(p=>{t.log.error("error closing connection",p),c.abort(p)});break;default:break}}),t.events?.increment({peer_connection:!0});let u=new Yn(t,{peerConnection:r,metrics:t.events,dataChannelOptions:t.dataChannel});if(t.role==="client")return t.log.trace("%s secure inbound",t.role),await s.secureInbound(a,{remotePeer:t.remotePeerId,signal:t.signal}),t.log.trace("%s upgrade outbound",t.role),await t.upgrader.upgradeOutbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:u,signal:t.signal});t.log.trace("%s secure outbound",t.role);let h=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${h.remotePeer}`),t.log.trace("%s upgrade inbound",t.role),await t.upgrader.upgradeInbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:u,signal:t.signal})}catch(o){throw n.close(),o}}async function Y1(r,e,t,n){n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t=="function"?await t():t;return new RTCPeerConnection({...o??{},certificates:[n]})}async function Z1(r){let e=await Yl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ce(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
+ `)}var wp=class{log;metrics;components;init;certificate;privateKey;emitter;renewCertificateTask;constructor(e,t={}){if(this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,this.emitter=new Ln,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new ve("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[gl]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Hi]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getPeerId();o!=null&&(n=es(o));let i=Dw(),s=await Y1("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await X1(s,i,{role:"client",log:this.log,logger:this.components.logger,metrics:this.components.metrics,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeerId:n,privateKey:this.components.privateKey})}catch(a){throw s.close(),a}}createListener(e){if(this.certificate==null)throw new Cl;return new ip(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(fw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(aI(this.init.certificate))return this.log("using provided TLS certificate"),this.init.certificate;let t=await this.loadOrCreatePrivateKey(),{pem:n,certhash:o}=await this.loadOrCreateCertificate(t,e);return{privateKey:await Z1(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??_w,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new _o;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await $0("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new il(this.init.certificateDatastoreKey??Ew),i=await Yl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new _o;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??vd)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:Io.encode((await tr.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new zs(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??vd);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new _o;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!qe(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new _o;return this.log("loaded certificate, expiry time is %o",i),o}async createCertificate(e,t){let n=new Date,o=new Date(Date.now()+(this.init.certificateLifespan??Cw));n.setMilliseconds(0),o.setMilliseconds(0);let i=await np.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new Ws(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,de(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function aI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function cI(r){return e=>new wp(e,r)}function lI(r){return e=>new Ru(e,r)}return pA(uI);})();
52
52
  /*! Bundled license information:
53
53
 
54
54
  reflect-metadata/Reflect.js: