@libp2p/webrtc 5.2.23-79473c99a → 5.2.23-cb1c14e62

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 Q_=Object.create;var Ku=Object.defineProperty;var eS=Object.getOwnPropertyDescriptor;var tS=Object.getOwnPropertyNames;var rS=Object.getPrototypeOf,nS=Object.prototype.hasOwnProperty;var Xp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),St=(r,e)=>{for(var t in e)Ku(r,t,{get:e[t],enumerable:!0})},Eg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of tS(e))!nS.call(r,o)&&o!==t&&Ku(r,o,{get:()=>e[o],enumerable:!(n=eS(e,o))||n.enumerable});return r};var $r=(r,e,t)=>(t=r!=null?Q_(rS(r)):{},Eg(e||!r||!r.__esModule?Ku(t,"default",{value:r,enumerable:!0}):t,r)),oS=r=>Eg(Ku({},"__esModule",{value:!0}),r);var Mb=Xp(()=>{var Ub;(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,l){return function(f,p){Object.defineProperty(c,f,{configurable:!0,writable:!0,value:p}),l&&l(f,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,l=!a&&!c,f={create:a?function(){return zp(Object.create(null))}:c?function(){return zp({__proto__:null})}:function(){return zp({})},has:l?function(b,S){return n.call(b,S)}:function(b,S){return S in b},get:l?function(b,S){return n.call(b,S)?b[S]:void 0}:function(b,S){return b[S]}},p=Object.getPrototypeOf(Function),y=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:z_(),m=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:X_(),x=typeof WeakMap=="function"?WeakMap:Z_(),v=o?Symbol.for("@reflect-metadata:registry"):void 0,d=W_(),I=G_(d);function D(b,S,N,F){if(U(N)){if(!sr(b))throw new TypeError;if(!wg(S))throw new TypeError;return O(b,S)}else{if(!sr(b))throw new TypeError;if(!se(S))throw new TypeError;if(!se(F)&&!U(F)&&!de(F))throw new TypeError;return de(F)&&(F=void 0),N=lt(N),B(b,S,N,F)}}e("decorate",D);function j(b,S){function N(F,ce){if(!se(F))throw new TypeError;if(!U(ce)&&!$_(ce))throw new TypeError;X(b,S,F,ce)}return N}e("metadata",j);function Z(b,S,N,F){if(!se(N))throw new TypeError;return U(F)||(F=lt(F)),X(b,S,N,F)}e("defineMetadata",Z);function P(b,S,N){if(!se(S))throw new TypeError;return U(N)||(N=lt(N)),R(b,S,N)}e("hasMetadata",P);function M(b,S,N){if(!se(S))throw new TypeError;return U(N)||(N=lt(N)),k(b,S,N)}e("hasOwnMetadata",M);function $(b,S,N){if(!se(S))throw new TypeError;return U(N)||(N=lt(N)),L(b,S,N)}e("getMetadata",$);function K(b,S,N){if(!se(S))throw new TypeError;return U(N)||(N=lt(N)),G(b,S,N)}e("getOwnMetadata",K);function g(b,S){if(!se(b))throw new TypeError;return U(S)||(S=lt(S)),q(b,S)}e("getMetadataKeys",g);function T(b,S){if(!se(b))throw new TypeError;return U(S)||(S=lt(S)),ie(b,S)}e("getOwnMetadataKeys",T);function E(b,S,N){if(!se(S))throw new TypeError;if(U(N)||(N=lt(N)),!se(S))throw new TypeError;U(N)||(N=lt(N));var F=va(S,N,!1);return U(F)?!1:F.OrdinaryDeleteMetadata(b,S,N)}e("deleteMetadata",E);function O(b,S){for(var N=b.length-1;N>=0;--N){var F=b[N],ce=F(S);if(!U(ce)&&!de(ce)){if(!wg(ce))throw new TypeError;S=ce}}return S}function B(b,S,N,F){for(var ce=b.length-1;ce>=0;--ce){var ze=b[ce],nt=ze(S,N,F);if(!U(nt)&&!de(nt)){if(!se(nt))throw new TypeError;F=nt}}return F}function R(b,S,N){var F=k(b,S,N);if(F)return!0;var ce=qp(S);return de(ce)?!1:R(b,ce,N)}function k(b,S,N){var F=va(S,N,!1);return U(F)?!1:tt(F.OrdinaryHasOwnMetadata(b,S,N))}function L(b,S,N){var F=k(b,S,N);if(F)return G(b,S,N);var ce=qp(S);if(!de(ce))return L(b,ce,N)}function G(b,S,N){var F=va(S,N,!1);if(!U(F))return F.OrdinaryGetOwnMetadata(b,S,N)}function X(b,S,N,F){var ce=va(N,F,!0);ce.OrdinaryDefineOwnMetadata(b,S,N,F)}function q(b,S){var N=ie(b,S),F=qp(b);if(F===null)return N;var ce=q(F,S);if(ce.length<=0)return N;if(N.length<=0)return ce;for(var ze=new m,nt=[],ge=0,J=N;ge<J.length;ge++){var ee=J[ge],re=ze.has(ee);re||(ze.add(ee),nt.push(ee))}for(var ne=0,we=ce;ne<we.length;ne++){var ee=we[ne],re=ze.has(ee);re||(ze.add(ee),nt.push(ee))}return nt}function ie(b,S){var N=va(b,S,!1);return N?N.OrdinaryOwnMetadataKeys(b,S):[]}function Y(b){if(b===null)return 1;switch(typeof b){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return b===null?1:6;default:return 6}}function U(b){return b===void 0}function de(b){return b===null}function Oe(b){return typeof b=="symbol"}function se(b){return typeof b=="object"?b!==null:typeof b=="function"}function De(b,S){switch(Y(b)){case 0:return b;case 1:return b;case 2:return b;case 3:return b;case 4:return b;case 5:return b}var N=S===3?"string":S===5?"number":"default",F=bg(b,i);if(F!==void 0){var ce=F.call(b,N);if(se(ce))throw new TypeError;return ce}return _t(b,N==="default"?"number":N)}function _t(b,S){if(S==="string"){var N=b.toString;if(Ji(N)){var F=N.call(b);if(!se(F))return F}var ce=b.valueOf;if(Ji(ce)){var F=ce.call(b);if(!se(F))return F}}else{var ce=b.valueOf;if(Ji(ce)){var F=ce.call(b);if(!se(F))return F}var ze=b.toString;if(Ji(ze)){var F=ze.call(b);if(!se(F))return F}}throw new TypeError}function tt(b){return!!b}function rt(b){return""+b}function lt(b){var S=De(b,3);return Oe(S)?S:rt(S)}function sr(b){return Array.isArray?Array.isArray(b):b instanceof Object?b instanceof Array:Object.prototype.toString.call(b)==="[object Array]"}function Ji(b){return typeof b=="function"}function wg(b){return typeof b=="function"}function $_(b){switch(Y(b)){case 3:return!0;case 4:return!0;default:return!1}}function Gp(b,S){return b===S||b!==b&&S!==S}function bg(b,S){var N=b[S];if(N!=null){if(!Ji(N))throw new TypeError;return N}}function xg(b){var S=bg(b,s);if(!Ji(S))throw new TypeError;var N=S.call(b);if(!se(N))throw new TypeError;return N}function vg(b){return b.value}function _g(b){var S=b.next();return S.done?!1:S}function Sg(b){var S=b.return;S&&S.call(b)}function qp(b){var S=Object.getPrototypeOf(b);if(typeof b!="function"||b===p||S!==p)return S;var N=b.prototype,F=N&&Object.getPrototypeOf(N);if(F==null||F===Object.prototype)return S;var ce=F.constructor;return typeof ce!="function"||ce===b?S:ce}function F_(){var b;!U(v)&&typeof t.Reflect<"u"&&!(v in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(b=q_(t.Reflect));var S,N,F,ce=new x,ze={registerProvider:nt,getProvider:J,setProvider:re};return ze;function nt(ne){if(!Object.isExtensible(ze))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case b===ne:break;case U(S):S=ne;break;case S===ne:break;case U(N):N=ne;break;case N===ne:break;default:F===void 0&&(F=new m),F.add(ne);break}}function ge(ne,we){if(!U(S)){if(S.isProviderFor(ne,we))return S;if(!U(N)){if(N.isProviderFor(ne,we))return S;if(!U(F))for(var Ue=xg(F);;){var Xe=_g(Ue);if(!Xe)return;var xr=vg(Xe);if(xr.isProviderFor(ne,we))return Sg(Ue),xr}}}if(!U(b)&&b.isProviderFor(ne,we))return b}function J(ne,we){var Ue=ce.get(ne),Xe;return U(Ue)||(Xe=Ue.get(we)),U(Xe)&&(Xe=ge(ne,we),U(Xe)||(U(Ue)&&(Ue=new y,ce.set(ne,Ue)),Ue.set(we,Xe))),Xe}function ee(ne){if(U(ne))throw new TypeError;return S===ne||N===ne||!U(F)&&F.has(ne)}function re(ne,we,Ue){if(!ee(Ue))throw new Error("Metadata provider not registered.");var Xe=J(ne,we);if(Xe!==Ue){if(!U(Xe))return!1;var xr=ce.get(ne);U(xr)&&(xr=new y,ce.set(ne,xr)),xr.set(we,Ue)}return!0}}function W_(){var b;return!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&(b=t.Reflect[v]),U(b)&&(b=F_()),!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,v,{enumerable:!1,configurable:!1,writable:!1,value:b}),b}function G_(b){var S=new x,N={isProviderFor:function(ee,re){var ne=S.get(ee);return U(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:nt,OrdinaryHasOwnMetadata:ce,OrdinaryGetOwnMetadata:ze,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:J};return d.registerProvider(N),N;function F(ee,re,ne){var we=S.get(ee),Ue=!1;if(U(we)){if(!ne)return;we=new y,S.set(ee,we),Ue=!0}var Xe=we.get(re);if(U(Xe)){if(!ne)return;if(Xe=new y,we.set(re,Xe),!b.setProvider(ee,re,N))throw we.delete(re),Ue&&S.delete(ee),new Error("Wrong provider for target.")}return Xe}function ce(ee,re,ne){var we=F(re,ne,!1);return U(we)?!1:tt(we.has(ee))}function ze(ee,re,ne){var we=F(re,ne,!1);if(!U(we))return we.get(ee)}function nt(ee,re,ne,we){var Ue=F(ne,we,!0);Ue.set(ee,re)}function ge(ee,re){var ne=[],we=F(ee,re,!1);if(U(we))return ne;for(var Ue=we.keys(),Xe=xg(Ue),xr=0;;){var Ag=_g(Xe);if(!Ag)return ne.length=xr,ne;var Y_=vg(Ag);try{ne[xr]=Y_}catch(J_){try{Sg(Xe)}finally{throw J_}}xr++}}function J(ee,re,ne){var we=F(re,ne,!1);if(U(we)||!we.delete(ee))return!1;if(we.size===0){var Ue=S.get(re);U(Ue)||(Ue.delete(ne),Ue.size===0&&S.delete(Ue))}return!0}}function q_(b){var S=b.defineMetadata,N=b.hasOwnMetadata,F=b.getOwnMetadata,ce=b.getOwnMetadataKeys,ze=b.deleteMetadata,nt=new x,ge={isProviderFor:function(J,ee){var re=nt.get(J);return!U(re)&&re.has(ee)?!0:ce(J,ee).length?(U(re)&&(re=new m,nt.set(J,re)),re.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:N,OrdinaryGetOwnMetadata:F,OrdinaryOwnMetadataKeys:ce,OrdinaryDeleteMetadata:ze};return ge}function va(b,S,N){var F=d.getProvider(b,S);if(!U(F))return F;if(N){if(d.setProvider(b,S,I))return I;throw new Error("Illegal state.")}}function z_(){var b={},S=[],N=function(){function ge(J,ee,re){this._index=0,this._keys=J,this._values=ee,this._selector=re}return ge.prototype["@@iterator"]=function(){return this},ge.prototype[s]=function(){return this},ge.prototype.next=function(){var J=this._index;if(J>=0&&J<this._keys.length){var ee=this._selector(this._keys[J],this._values[J]);return J+1>=this._keys.length?(this._index=-1,this._keys=S,this._values=S):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},ge.prototype.throw=function(J){throw this._index>=0&&(this._index=-1,this._keys=S,this._values=S),J},ge.prototype.return=function(J){return this._index>=0&&(this._index=-1,this._keys=S,this._values=S),{value:J,done:!0}},ge}(),F=function(){function ge(){this._keys=[],this._values=[],this._cacheKey=b,this._cacheIndex=-2}return Object.defineProperty(ge.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),ge.prototype.has=function(J){return this._find(J,!1)>=0},ge.prototype.get=function(J){var ee=this._find(J,!1);return ee>=0?this._values[ee]:void 0},ge.prototype.set=function(J,ee){var re=this._find(J,!0);return this._values[re]=ee,this},ge.prototype.delete=function(J){var ee=this._find(J,!1);if(ee>=0){for(var re=this._keys.length,ne=ee+1;ne<re;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Gp(J,this._cacheKey)&&(this._cacheKey=b,this._cacheIndex=-2),!0}return!1},ge.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=b,this._cacheIndex=-2},ge.prototype.keys=function(){return new N(this._keys,this._values,ce)},ge.prototype.values=function(){return new N(this._keys,this._values,ze)},ge.prototype.entries=function(){return new N(this._keys,this._values,nt)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(J,ee){if(!Gp(this._cacheKey,J)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(Gp(this._keys[re],J)){this._cacheIndex=re;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(J),this._values.push(void 0)),this._cacheIndex},ge}();return F;function ce(ge,J){return ge}function ze(ge,J){return J}function nt(ge,J){return[ge,J]}}function X_(){var b=function(){function S(){this._map=new y}return Object.defineProperty(S.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),S.prototype.has=function(N){return this._map.has(N)},S.prototype.add=function(N){return this._map.set(N,N),this},S.prototype.delete=function(N){return this._map.delete(N)},S.prototype.clear=function(){this._map.clear()},S.prototype.keys=function(){return this._map.keys()},S.prototype.values=function(){return this._map.keys()},S.prototype.entries=function(){return this._map.entries()},S.prototype["@@iterator"]=function(){return this.keys()},S.prototype[s]=function(){return this.keys()},S}();return b}function Z_(){var b=16,S=f.create(),N=F();return function(){function J(){this._key=F()}return J.prototype.has=function(ee){var re=ce(ee,!1);return re!==void 0?f.has(re,this._key):!1},J.prototype.get=function(ee){var re=ce(ee,!1);return re!==void 0?f.get(re,this._key):void 0},J.prototype.set=function(ee,re){var ne=ce(ee,!0);return ne[this._key]=re,this},J.prototype.delete=function(ee){var re=ce(ee,!1);return re!==void 0?delete re[this._key]:!1},J.prototype.clear=function(){this._key=F()},J}();function F(){var J;do J="@@WeakMap@@"+ge();while(f.has(S,J));return S[J]=!0,J}function ce(J,ee){if(!n.call(J,N)){if(!ee)return;Object.defineProperty(J,N,{value:f.create()})}return J[N]}function ze(J,ee){for(var re=0;re<ee;++re)J[re]=Math.random()*255|0;return J}function nt(J){if(typeof Uint8Array=="function"){var ee=new Uint8Array(J);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):ze(ee,J),ee}return ze(new Array(J),J)}function ge(){var J=nt(b);J[6]=J[6]&79|64,J[8]=J[8]&191|128;for(var ee="",re=0;re<b;++re){var ne=J[re];(re===4||re===6||re===8)&&(ee+="-"),ne<16&&(ee+="0"),ee+=ne.toString(16).toLowerCase()}return ee}}function zp(b){return b.__=void 0,delete b.__,b}})})(Ub||(Ub={}))});var _n=Xp(Bs=>{"use strict";var z2="[object ArrayBuffer]",vn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===z2}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}},ty="string",X2=/^[0-9a-f\s]+$/i,Z2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Y2=/^[a-zA-Z0-9-_]+$/,pf=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=vn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},lr=class{static toString(e,t=!1){let n=vn.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}},hf=class r{static isHex(e){return typeof e===ty&&X2.test(e)}static isBase64(e){return typeof e===ty&&Z2.test(e)}static isBase64Url(e){return typeof e===ty&&Y2.test(e)}static ToString(e,t="utf8"){let n=vn.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 lr.toString(n,!0);case"utf16":case"utf16be":return lr.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 lr.fromString(e,!0);case"utf16":case"utf16be":return lr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=vn.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 pf.fromString(e);case"utf16":case"utf16be":return lr.fromString(e);case"utf16le":case"usc2":return lr.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 pf.toString(e);case"utf16":case"utf16be":return lr.toString(e);case"utf16le":case"usc2":return lr.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=vn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=vn.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 lr.toString(e,t)}static FromUtf16String(e,t=!1){return lr.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,"")||""}};hf.DEFAULT_UTF8_ENCODING="utf8";function J2(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 Q2(...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 eC(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}Bs.BufferSourceConverter=vn;Bs.Convert=hf;Bs.assign=J2;Bs.combine=Q2;Bs.isEqual=eC});var kv=Xp((c$,ap)=>{var hv,dv,yv,mv,gv,wv,bv,xv,vv,sp,um,_v,Sv,aa,Av,Ev,Cv,Tv,Iv,Ov,Pv,Bv,Nv;(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 ap=="object"&&typeof ap.exports=="object"?r(t(e,t(ap.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])};hv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},dv=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},yv=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},mv=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 l=t.length-1;l>=0;l--)(c=t[l])&&(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},gv=function(t,n){return function(o,i){n(o,i,t)}},wv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},bv=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 l(y){try{p(i.next(y))}catch(m){c(m)}}function f(y){try{p(i.throw(y))}catch(m){c(m)}}function p(y){y.done?a(y.value):s(y.value).then(l,f)}p((i=i.apply(t,n||[])).next())})},xv=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:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(p){return function(y){return f([p,y])}}function f(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}}},Nv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},vv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},sp=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.")},um=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(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},_v=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(um(arguments[n]));return t},Sv=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,l=a.length;c<l;c++,s++)i[s]=a[c];return i},aa=function(t){return this instanceof aa?(this.v=t,this):new aa(t)},Av=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(x){i[x]&&(s[x]=function(v){return new Promise(function(d,I){a.push([x,v,d,I])>1||l(x,v)})})}function l(x,v){try{f(i[x](v))}catch(d){m(a[0][3],d)}}function f(x){x.value instanceof aa?Promise.resolve(x.value.v).then(p,y):m(a[0][2],x)}function p(x){l("next",x)}function y(x){l("throw",x)}function m(x,v){x(v),a.shift(),a.length&&l(a[0][0],a[0][1])}},Ev=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:aa(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Cv=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 sp=="function"?sp(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(l,f){c=t[a](c),s(l,f,c.done,c.value)})}}function s(a,c,l,f){Promise.resolve(f).then(function(p){a({value:p,done:l})},c)}},Tv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Iv=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},Ov=function(t){return t&&t.__esModule?t:{default:t}},Pv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Bv=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",hv),r("__assign",dv),r("__rest",yv),r("__decorate",mv),r("__param",gv),r("__metadata",wv),r("__awaiter",bv),r("__generator",xv),r("__exportStar",vv),r("__createBinding",Nv),r("__values",sp),r("__read",um),r("__spread",_v),r("__spreadArrays",Sv),r("__await",aa),r("__asyncGenerator",Av),r("__asyncDelegator",Ev),r("__asyncValues",Cv),r("__makeTemplateObject",Tv),r("__importStar",Iv),r("__importDefault",Ov),r("__classPrivateFieldGet",Pv),r("__classPrivateFieldSet",Bv)})});var nI={};St(nI,{webRTC:()=>rI,webRTCDirect:()=>tI});var Zp=Symbol.for("@libp2p/peer-id");var Hu=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 Vu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},$u=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Ie=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Qi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},_a=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Fu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Wu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Bo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},No=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Gu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},qu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var zu=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Xu=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Zu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Fn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Wn=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 es=Symbol.for("@libp2p/service-capabilities"),Tg=Symbol.for("@libp2p/service-dependencies");var th={};St(th,{base58btc:()=>He,base58flickr:()=>fS});var PI=new Uint8Array(0);function Ig(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 hn(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 Pg(r){return new TextDecoder().decode(r)}function iS(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),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function p(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var v=0,d=0,I=0,D=x.length;I!==D&&x[I]===0;)I++,v++;for(var j=(D-I)*f+1>>>0,Z=new Uint8Array(j);I!==D;){for(var P=x[I],M=0,$=j-1;(P!==0||M<d)&&$!==-1;$--,M++)P+=256*Z[$]>>>0,Z[$]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");d=M,I++}for(var K=j-d;K!==j&&Z[K]===0;)K++;for(var g=c.repeat(v);K<j;++K)g+=r.charAt(Z[K]);return g}function y(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var v=0;if(x[v]!==" "){for(var d=0,I=0;x[v]===c;)d++,v++;for(var D=(x.length-v)*l+1>>>0,j=new Uint8Array(D);x[v];){var Z=t[x.charCodeAt(v)];if(Z===255)return;for(var P=0,M=D-1;(Z!==0||P<I)&&M!==-1;M--,P++)Z+=a*j[M]>>>0,j[M]=Z%256>>>0,Z=Z/256>>>0;if(Z!==0)throw new Error("Non-zero carry");I=P,v++}if(x[v]!==" "){for(var $=D-I;$!==D&&j[$]===0;)$++;for(var K=new Uint8Array(d+(D-$)),g=d;$!==D;)K[g++]=j[$++];return K}}}function m(x){var v=y(x);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:y,decode:m}}var sS=iS,aS=sS,Ng=aS;var Yp=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")}},Jp=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 kg(this,e)}},Qp=class{decoders;constructor(e){this.decoders=e}or(e){return kg(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 kg(r,e){return new Qp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var eh=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 Yp(e,t,n),this.decoder=new Jp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ts({name:r,prefix:e,encode:t,decode:n}){return new eh(r,e,t,n)}function Gn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Ng(t,r);return ts({prefix:e,name:r,encode:n,decode:i=>hn(o(i))})}function cS(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let f=e[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function uS(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 lS(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Fe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=lS(n);return ts({prefix:e,name:r,encode(i){return uS(i,n,t)},decode(i){return cS(i,o,t,r)}})}var He=Gn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fS=Gn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rh={};St(rh,{base32:()=>qn,base32hex:()=>yS,base32hexpad:()=>gS,base32hexpadupper:()=>wS,base32hexupper:()=>mS,base32pad:()=>hS,base32padupper:()=>dS,base32upper:()=>pS,base32z:()=>bS});var qn=Fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pS=Fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hS=Fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),dS=Fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yS=Fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),mS=Fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gS=Fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wS=Fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bS=Fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nh={};St(nh,{base36:()=>Sa,base36upper:()=>xS});var Sa=Gn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xS=Gn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vr={};St(vr,{Digest:()=>ko,create:()=>At,decode:()=>os,equals:()=>ih,hasCode:()=>MS});var vS=Rg,Dg=128,_S=127,SS=~_S,AS=Math.pow(2,31);function Rg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=AS;)e[t++]=r&255|Dg,r/=128;for(;r&SS;)e[t++]=r&255|Dg,r>>>=7;return e[t]=r|0,Rg.bytes=t-n+1,e}var ES=oh,CS=128,jg=127;function oh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw oh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&jg)<<o:(s&jg)*Math.pow(2,o),o+=7}while(s>=CS);return oh.bytes=i-n,t}var TS=Math.pow(2,7),IS=Math.pow(2,14),OS=Math.pow(2,21),PS=Math.pow(2,28),BS=Math.pow(2,35),NS=Math.pow(2,42),kS=Math.pow(2,49),DS=Math.pow(2,56),jS=Math.pow(2,63),RS=function(r){return r<TS?1:r<IS?2:r<OS?3:r<PS?4:r<BS?5:r<NS?6:r<kS?7:r<DS?8:r<jS?9:10},LS={encode:vS,decode:ES,encodingLength:RS},US=LS,Aa=US;function Ea(r,e=0){return[Aa.decode(r,e),Aa.decode.bytes]}function rs(r,e,t=0){return Aa.encode(r,e,t),e}function ns(r){return Aa.encodingLength(r)}function At(r,e){let t=e.byteLength,n=ns(r),o=n+ns(t),i=new Uint8Array(o+t);return rs(r,i,0),rs(t,i,n),i.set(e,o),new ko(r,t,e,i)}function os(r){let e=hn(r),[t,n]=Ea(e),[o,i]=Ea(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ko(t,o,s,e)}function ih(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ig(r.bytes,t.bytes)}}var ko=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function MS(r,e){return r.code===e}function Lg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return HS(t,sh(r),e??He.encoder);default:return VS(t,sh(r),e??qn.encoder)}}var Ug=new WeakMap;function sh(r){let e=Ug.get(r);if(e==null){let t=new Map;return Ug.set(r,t),t}return e}var Ze=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!==Ca)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==$S)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&&ih(e.multihash,n.multihash)}toString(e){return Lg(this,e)}toJSON(){return{"/":Lg(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??Mg(n,o,i.bytes))}else if(t[FS]===!0){let{version:n,multihash:o,code:i}=t,s=os(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!==Ca)throw new Error(`Version 0 CID must use dag-pb (code: ${Ca}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Mg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ca,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=hn(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 ko(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]=Ea(e.subarray(t));return t+=y,p},o=n(),i=Ca;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(),l=t+c,f=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(e,t){let[n,o]=KS(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 sh(i).set(n,e),i}};function KS(r,e){switch(r[0]){case"Q":{let t=e??He;return[He.prefix,t.decode(`${He.prefix}${r}`)]}case He.prefix:{let t=e??He;return[He.prefix,t.decode(r)]}case qn.prefix:{let t=e??qn;return[qn.prefix,t.decode(r)]}case Sa.prefix:{let t=e??Sa;return[Sa.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 HS(r,e,t){let{prefix:n}=t;if(n!==He.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 VS(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 Ca=112,$S=18;function Mg(r,e,t){let n=ns(r),o=n+ns(e),i=new Uint8Array(o+t.byteLength);return rs(r,i,0),rs(e,i,n),i.set(t,o),i}var FS=Symbol.for("@ipld/js-cid/CID");var ah={};St(ah,{identity:()=>_r});var Kg=0,WS="identity",Hg=hn;function GS(r){return At(Kg,Hg(r))}var _r={code:Kg,name:WS,encode:Hg,digest:GS};function We(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 ot(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function Bt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=it(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var $g=Symbol.for("@achingbrain/uint8arraylist");function Vg(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 Ju(r){return!!r?.[$g]}var be=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(Ju(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(Ju(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=Vg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Vg(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(Ju(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 Bt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Bt(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 l=e>=a&&e<c,f=t>a&&t<=c;if(l&&f){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){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(!Ju(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,l=n.byteLength-1,f;for(let p=t;p<=c;p+=f){f=0;for(let y=l;y>=0;y--){let m=this.get(p+y);if(n[y]!==m){f=Math.max(1,y-a[m]);break}}if(f===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=it(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=ot(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=ot(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=ot(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=it(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=ot(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=ot(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=ot(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=ot(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=ot(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(!We(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 ch={};St(ch,{base10:()=>zS});var zS=Gn({prefix:"9",name:"base10",alphabet:"0123456789"});var uh={};St(uh,{base16:()=>XS,base16upper:()=>ZS});var XS=Fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ZS=Fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var lh={};St(lh,{base2:()=>YS});var YS=Fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fh={};St(fh,{base256emoji:()=>rA});var Fg=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}"),JS=Fg.reduce((r,e,t)=>(r[t]=e,r),[]),QS=Fg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function eA(r){return r.reduce((e,t)=>(e+=JS[t],e),"")}function tA(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=QS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var rA=ts({prefix:"\u{1F680}",name:"base256emoji",encode:eA,decode:tA});var ph={};St(ph,{base64:()=>nA,base64pad:()=>oA,base64url:()=>Do,base64urlpad:()=>iA});var nA=Fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),oA=Fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Do=Fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),iA=Fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hh={};St(hh,{base8:()=>sA});var sA=Fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dh={};St(dh,{identity:()=>aA});var aA=ts({prefix:"\0",name:"identity",encode:r=>Pg(r),decode:r=>Og(r)});var pO=new TextEncoder,hO=new TextDecoder;var gh={};St(gh,{sha256:()=>ar,sha512:()=>lA});function mh({name:r,code:e,encode:t}){return new yh(r,e,t)}var yh=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 Gg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ar=mh({name:"sha2-256",code:18,encode:Gg("SHA-256")}),lA=mh({name:"sha2-512",code:19,encode:Gg("SHA-512")});var jo={...dh,...lh,...hh,...ch,...uh,...rh,...nh,...th,...ph,...fh},EO={...gh,...ah};function zg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var qg=zg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),wh=zg("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=it(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),fA={utf8:qg,"utf-8":qg,hex:jo.base16,latin1:wh,ascii:wh,binary:wh,...jo},Qu=fA;function he(r,e="utf8"){let t=Qu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function le(r,e="utf8"){let t=Qu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var pA=parseInt("11111",2),bh=parseInt("10000000",2),hA=parseInt("01111111",2),Xg={0:Ta,1:Ta,2:dA,3:gA,4:wA,5:mA,6:yA,16:Ta,22:Ta,48:Ta};function dn(r,e={offset:0}){let t=r[e.offset]&pA;if(e.offset++,Xg[t]!=null)return Xg[t](r,e);throw new Error("No decoder for tag "+t)}function Ia(r,e){let t=0;if((r[e.offset]&bh)===bh){let n=r[e.offset]&hA,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 Ta(r,e){Ia(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=dn(r,e);if(n===null)break;t.push(n)}return t}function dA(r,e){let t=Ia(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 yA(r,e){let t=Ia(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 l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let f=0;for(let p=0;p<c.length;p++)f+=c[p]<<p*7;a+=`.${f}`,c=[]}}return a}function mA(r,e){return e.offset++,null}function gA(r,e){let t=Ia(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 wA(r,e){let t=Ia(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function bA(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new be;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function el(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=bA(r.byteLength);return new be(Uint8Array.from([e.byteLength|bh]),e)}function Nt(r){let e=new be,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new be(Uint8Array.from([2]),el(e),e)}function Oa(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),el(t),t)}function Zg(r){return new be(Uint8Array.from([4]),el(r),r)}function Sr(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),el(t),t)}async function Yg(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 Jg(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qg(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,t.subarray());return n?.signal?.throwIfAborted(),i}var xA=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vA=Uint8Array.from([6,5,43,129,4,0,34]),_A=Uint8Array.from([6,5,43,129,4,0,35]),SA={ext:!0,kty:"EC",crv:"P-256"},AA={ext:!0,kty:"EC",crv:"P-384"},EA={ext:!0,kty:"EC",crv:"P-521"},xh=32,vh=48,_h=66;function Sh(r){let e=dn(r);return e0(e)}function e0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===xh*2+1)return n=le(e.subarray(t,t+xh),"base64url"),o=le(e.subarray(t+xh),"base64url"),new Ro({...SA,key_ops:["verify"],x:n,y:o});if(e.byteLength===vh*2+1)return n=le(e.subarray(t,t+vh),"base64url"),o=le(e.subarray(t+vh),"base64url"),new Ro({...AA,key_ops:["verify"],x:n,y:o});if(e.byteLength===_h*2+1)return n=le(e.subarray(t,t+_h),"base64url"),o=le(e.subarray(t+_h),"base64url"),new Ro({...EA,key_ops:["verify"],x:n,y:o});throw new Ie(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function t0(r){return Sr([Nt(Uint8Array.from([1])),Zg(he(r.d??"","base64url")),Sr([n0(r.crv)],160),Sr([Oa(new be(Uint8Array.from([4]),he(r.x??"","base64url"),he(r.y??"","base64url")))],161)]).subarray()}function r0(r){return Sr([Nt(Uint8Array.from([1])),Sr([n0(r.crv)],160),Sr([Oa(new be(Uint8Array.from([4]),he(r.x??"","base64url"),he(r.y??"","base64url")))],161)]).subarray()}function n0(r){if(r==="P-256")return xA;if(r==="P-384")return vA;if(r==="P-521")return _A;throw new Ie(`Invalid curve ${r}`)}async function o0(r="P-256"){let e=await Yg(r);return new tl(e.privateKey)}var Ro=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=r0(this.jwk)),this._raw}toMultihash(){return _r.digest(zn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async verify(e,t,n){return Qg(this.jwk,t,e,n)}},tl=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Ro({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=t0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async sign(e,t){return Jg(this.jwk,e,t)}};var Lo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ss(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Uo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Et(r,...e){if(!ss(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 Pa(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Uo(r.outputLen),Uo(r.blockLen)}function as(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 s0(r,e){Et(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Ar(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function rl(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Er(r,e){return r<<32-e|r>>>e}var a0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",CA=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Fr(r){if(Et(r),a0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=CA[r[t]];return e}var yn={_0:48,_9:57,A:65,F:70,a:97,f:102};function i0(r){if(r>=yn._0&&r<=yn._9)return r-yn._0;if(r>=yn.A&&r<=yn.F)return r-(yn.A-10);if(r>=yn.a&&r<=yn.f)return r-(yn.a-10)}function cs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(a0)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=i0(r.charCodeAt(i)),a=i0(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 c0(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Xn(r){return typeof r=="string"&&(r=c0(r)),Et(r),r}function Jt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Et(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 is=class{};function Ah(r){let e=n=>r().update(Xn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Mo(r=32){if(Lo&&typeof Lo.getRandomValues=="function")return Lo.getRandomValues(new Uint8Array(r));if(Lo&&typeof Lo.randomBytes=="function")return Uint8Array.from(Lo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function TA(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,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function u0(r,e,t){return r&e^~r&t}function l0(r,e,t){return r&e^r&t^e&t}var Ba=class extends is{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=rl(this.buffer)}update(e){as(this),e=Xn(e),Et(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=rl(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){as(this),s0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Ar(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;TA(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=rl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,f[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.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},mn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var nl=BigInt(4294967295),f0=BigInt(32);function IA(r,e=!1){return e?{h:Number(r&nl),l:Number(r>>f0&nl)}:{h:Number(r>>f0&nl)|0,l:Number(r&nl)|0}}function p0(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=IA(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Eh=(r,e,t)=>r>>>t,Ch=(r,e,t)=>r<<32-t|e>>>t,Ko=(r,e,t)=>r>>>t|e<<32-t,Ho=(r,e,t)=>r<<32-t|e>>>t,Na=(r,e,t)=>r<<64-t|e>>>t-32,ka=(r,e,t)=>r>>>t-32|e<<64-t;function Wr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var h0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),d0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,y0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),m0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,g0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),w0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var PA=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zn=new Uint32Array(64),ol=class extends Ba{constructor(e=32){super(64,e,8,!1),this.A=mn[0]|0,this.B=mn[1]|0,this.C=mn[2]|0,this.D=mn[3]|0,this.E=mn[4]|0,this.F=mn[5]|0,this.G=mn[6]|0,this.H=mn[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)Zn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let y=Zn[p-15],m=Zn[p-2],x=Er(y,7)^Er(y,18)^y>>>3,v=Er(m,17)^Er(m,19)^m>>>10;Zn[p]=v+Zn[p-7]+x+Zn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:f}=this;for(let p=0;p<64;p++){let y=Er(a,6)^Er(a,11)^Er(a,25),m=f+y+u0(a,c,l)+PA[p]+Zn[p]|0,v=(Er(n,2)^Er(n,13)^Er(n,22))+l0(n,o,i)|0;f=l,l=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+v|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,l=l+this.G|0,f=f+this.H|0,this.set(n,o,i,s,a,c,l,f)}roundClean(){Ar(Zn)}destroy(){this.set(0,0,0,0,0,0,0,0),Ar(this.buffer)}};var b0=p0(["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))),BA=b0[0],NA=b0[1],Yn=new Uint32Array(80),Jn=new Uint32Array(80),Th=class extends Ba{constructor(e=64){super(128,e,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:f,Fh:p,Fl:y,Gh:m,Gl:x,Hh:v,Hl:d}=this;return[e,t,n,o,i,s,a,c,l,f,p,y,m,x,v,d]}set(e,t,n,o,i,s,a,c,l,f,p,y,m,x,v,d){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=l|0,this.El=f|0,this.Fh=p|0,this.Fl=y|0,this.Gh=m|0,this.Gl=x|0,this.Hh=v|0,this.Hl=d|0}process(e,t){for(let j=0;j<16;j++,t+=4)Yn[j]=e.getUint32(t),Jn[j]=e.getUint32(t+=4);for(let j=16;j<80;j++){let Z=Yn[j-15]|0,P=Jn[j-15]|0,M=Ko(Z,P,1)^Ko(Z,P,8)^Eh(Z,P,7),$=Ho(Z,P,1)^Ho(Z,P,8)^Ch(Z,P,7),K=Yn[j-2]|0,g=Jn[j-2]|0,T=Ko(K,g,19)^Na(K,g,61)^Eh(K,g,6),E=Ho(K,g,19)^ka(K,g,61)^Ch(K,g,6),O=y0($,E,Jn[j-7],Jn[j-16]),B=m0(O,M,T,Yn[j-7],Yn[j-16]);Yn[j]=B|0,Jn[j]=O|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:f,Eh:p,El:y,Fh:m,Fl:x,Gh:v,Gl:d,Hh:I,Hl:D}=this;for(let j=0;j<80;j++){let Z=Ko(p,y,14)^Ko(p,y,18)^Na(p,y,41),P=Ho(p,y,14)^Ho(p,y,18)^ka(p,y,41),M=p&m^~p&v,$=y&x^~y&d,K=g0(D,P,$,NA[j],Jn[j]),g=w0(K,I,Z,M,BA[j],Yn[j]),T=K|0,E=Ko(n,o,28)^Na(n,o,34)^Na(n,o,39),O=Ho(n,o,28)^ka(n,o,34)^ka(n,o,39),B=n&i^n&a^i&a,R=o&s^o&c^s&c;I=v|0,D=d|0,v=m|0,d=x|0,m=p|0,x=y|0,{h:p,l:y}=Wr(l|0,f|0,g|0,T|0),l=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=h0(T,O,R);n=d0(k,g,E,B),o=k|0}({h:n,l:o}=Wr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Wr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Wr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=Wr(this.Dh|0,this.Dl|0,l|0,f|0),{h:p,l:y}=Wr(this.Eh|0,this.El|0,p|0,y|0),{h:m,l:x}=Wr(this.Fh|0,this.Fl|0,m|0,x|0),{h:v,l:d}=Wr(this.Gh|0,this.Gl|0,v|0,d|0),{h:I,l:D}=Wr(this.Hh|0,this.Hl|0,I|0,D|0),this.set(n,o,i,s,a,c,l,f,p,y,m,x,v,d,I,D)}roundClean(){Ar(Yn,Jn)}destroy(){Ar(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var il=Ah(()=>new ol);var x0=Ah(()=>new Th);var Ph=BigInt(0),Oh=BigInt(1);function gn(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Da(r){let e=r.toString(16);return e.length&1?"0"+e:e}function v0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ph:BigInt("0x"+r)}function us(r){return v0(Fr(r))}function Gr(r){return Et(r),v0(Fr(Uint8Array.from(r).reverse()))}function sl(r,e){return cs(r.toString(16).padStart(e*2,"0"))}function Qn(r,e){return sl(r,e).reverse()}function Ne(r,e,t){let n;if(typeof e=="string")try{n=cs(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(ss(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}var Ih=r=>typeof r=="bigint"&&Ph<=r;function _0(r,e,t){return Ih(r)&&Ih(e)&&Ih(t)&&e<=r&&r<t}function Cr(r,e,t,n){if(!_0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function S0(r){let e;for(e=0;r>Ph;r>>=Oh,e+=1);return e}var Vo=r=>(Oh<<BigInt(r))-Oh;function A0(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=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},l=(...m)=>t(s,i,...m),f=(m=n(0))=>{s=l(o(0),m),i=l(),m.length!==0&&(s=l(o(1),m),i=l())},p=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,x=[];for(;m<e;){i=l();let v=i.slice();x.push(v),m+=i.length}return Jt(...x)};return(m,x)=>{c(),f(m);let v;for(;!(v=x(p()));)f();return c(),v}}function qr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}function ls(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 kt=BigInt(0),ct=BigInt(1),$o=BigInt(2),kA=BigInt(3),T0=BigInt(4),I0=BigInt(5),O0=BigInt(8);function je(r,e){let t=r%e;return t>=kt?t:e+t}function Me(r,e,t){let n=r;for(;e-- >kt;)n*=n,n%=t;return n}function E0(r,e){if(r===kt)throw new Error("invert: expected non-zero number");if(e<=kt)throw new Error("invert: expected positive modulus, got "+e);let t=je(r,e),n=e,o=kt,i=ct,s=ct,a=kt;for(;t!==kt;){let l=n/t,f=n%t,p=o-s*l,y=i-a*l;n=t,t=f,o=s,i=a,s=p,a=y}if(n!==ct)throw new Error("invert: does not exist");return je(o,e)}function P0(r,e){let t=(r.ORDER+ct)/T0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function DA(r,e){let t=(r.ORDER-I0)/O0,n=r.mul(e,$o),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,$o),o),a=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(a),e))throw new Error("Cannot find square root");return a}function jA(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-ct,t=0;for(;e%$o===kt;)e/=$o,t++;let n=$o,o=Tr(r);for(;C0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return P0;let i=o.pow(n,e),s=(e+ct)/$o;return function(c,l){if(c.is0(l))return l;if(C0(c,l)!==1)throw new Error("Cannot find square root");let f=t,p=c.mul(c.ONE,i),y=c.pow(l,e),m=c.pow(l,s);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let x=1,v=c.sqr(y);for(;!c.eql(v,c.ONE);)if(x++,v=c.sqr(v),x===f)throw new Error("Cannot find square root");let d=ct<<BigInt(f-x-1),I=c.pow(p,d);f=x,p=c.sqr(I),y=c.mul(y,p),m=c.mul(m,I)}return m}}function RA(r){return r%T0===kA?P0:r%O0===I0?DA:jA(r)}var B0=(r,e)=>(je(r,e)&ct)===ct,LA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Bh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=LA.reduce((n,o)=>(n[o]="function",n),e);return qr(r,t),r}function UA(r,e,t){if(t<kt)throw new Error("invalid exponent, negatives unsupported");if(t===kt)return r.ONE;if(t===ct)return e;let n=r.ONE,o=e;for(;t>kt;)t&ct&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ct;return n}function ja(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function C0(r,e){let t=(r.ORDER-ct)/$o,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function N0(r,e){e!==void 0&&Uo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Tr(r,e,t=!1,n={}){if(r<=kt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let f=e;f.BITS&&(o=f.BITS),f.sqrt&&(i=f.sqrt),typeof f.isLE=="boolean"&&(t=f.isLE)}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:s,nByteLength:a}=N0(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:t,BITS:s,BYTES:a,MASK:Vo(s),ZERO:kt,ONE:ct,create:f=>je(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return kt<=f&&f<r},is0:f=>f===kt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&ct)===ct,neg:f=>je(-f,r),eql:(f,p)=>f===p,sqr:f=>je(f*f,r),add:(f,p)=>je(f+p,r),sub:(f,p)=>je(f-p,r),mul:(f,p)=>je(f*p,r),pow:(f,p)=>UA(l,f,p),div:(f,p)=>je(f*E0(p,r),r),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>E0(f,r),sqrt:i||(f=>(c||(c=RA(r)),c(l,f))),toBytes:f=>t?Qn(f,a):sl(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return t?Gr(f):us(f)},invertBatch:f=>ja(l,f),cmov:(f,p,y)=>y?p:f});return Object.freeze(l)}function k0(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 Nh(r){let e=k0(r);return e+Math.ceil(e/2)}function D0(r,e,t=!1){let n=r.length,o=k0(e),i=Nh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Gr(r):us(r),a=je(s,e-ct)+ct;return t?Qn(a,o):sl(a,o)}var ps=BigInt(0),Fo=BigInt(1);function fs(r,e){let t=e.negate();return r?t:e}function al(r,e,t){let n=e==="pz"?s=>s.pz:s=>s.ez,o=ja(r.Fp,t.map(n));return t.map((s,a)=>s.toAffine(o[a])).map(r.fromAffine)}function U0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function kh(r,e){U0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Vo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function j0(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+=Fo);let l=e*n,f=l+Math.abs(a)-1,p=a===0,y=a<0,m=e%2!==0;return{nextN:c,offset:f,isZero:p,isNeg:y,isNegF:m,offsetF:l}}function MA(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 KA(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 Dh=new WeakMap,M0=new WeakMap;function jh(r){return M0.get(r)||1}function R0(r){if(r!==ps)throw new Error("invalid wNAF")}function cl(r,e){return{constTimeNegate:fs,hasPrecomputes(t){return jh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>ps;)n&Fo&&(o=o.add(i)),i=i.double(),n>>=Fo;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=kh(n,e),s=[],a=t,c=a;for(let l=0;l<o;l++){c=a,s.push(c);for(let f=1;f<i;f++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=kh(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:f,isZero:p,isNeg:y,isNegF:m,offsetF:x}=j0(o,c,a);o=l,p?s=s.add(fs(m,n[x])):i=i.add(fs(y,n[f]))}return R0(o),{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=kh(t,e);for(let a=0;a<s.windows&&o!==ps;a++){let{nextN:c,offset:l,isZero:f,isNeg:p}=j0(o,a,s);if(o=c,!f){let y=n[l];i=i.add(p?y.negate():y)}}return R0(o),i},getPrecomputes(t,n,o){let i=Dh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof o=="function"&&(i=o(i)),Dh.set(n,i))),i},wNAFCached(t,n,o){let i=jh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=jh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){U0(n,e),M0.set(t,n),Dh.delete(t)}}}function K0(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>ps||n>ps;)t&Fo&&(i=i.add(o)),n&Fo&&(s=s.add(o)),o=o.double(),t>>=Fo,n>>=Fo;return{p1:i,p2:s}}function ul(r,e,t,n){MA(t,r),KA(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=S0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Vo(c),f=new Array(Number(l)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,y=s;for(let m=p;m>=0;m-=c){f.fill(s);for(let v=0;v<i;v++){let d=n[v],I=Number(d>>BigInt(m)&l);f[I]=f[I].add(t[v])}let x=s;for(let v=f.length-1,d=s;v>0;v--)d=d.add(f[v]),x=x.add(d);if(y=y.add(x),m!==0)for(let v=0;v<c;v++)y=y.double()}return y}function L0(r,e){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Bh(e),e}else return Tr(r)}function ll(r,e,t={}){if(!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=e[a];if(!(typeof c=="bigint"&&c>ps))throw new Error(`CURVE.${a} must be positive bigint`)}let n=L0(e.p,t.Fp),o=L0(e.n,t.Fn),s=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of s)if(!n.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var zr=BigInt(0),Dt=BigInt(1),Rh=BigInt(2),HA=BigInt(8),VA={zip215:!0};function $A(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function FA(r,e={}){let{Fp:t,Fn:n}=ll("edwards",r,e),{h:o,n:i}=r;qr(e,{},{uvRatio:"function"});let s=Rh<<BigInt(n.BYTES*8)-Dt,a=v=>t.create(v),c=e.uvRatio||((v,d)=>{try{return{isValid:!0,value:t.sqrt(t.div(v,d))}}catch{return{isValid:!1,value:zr}}});if(!$A(t,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(v,d,I=!1){let D=I?Dt:zr;return Cr("coordinate "+v,d,D,s),d}function f(v){if(!(v instanceof m))throw new Error("ExtendedPoint expected")}let p=ls((v,d)=>{let{ex:I,ey:D,ez:j}=v,Z=v.is0();d==null&&(d=Z?HA:t.inv(j));let P=a(I*d),M=a(D*d),$=a(j*d);if(Z)return{x:zr,y:Dt};if($!==Dt)throw new Error("invZ was invalid");return{x:P,y:M}}),y=ls(v=>{let{a:d,d:I}=r;if(v.is0())throw new Error("bad point: ZERO");let{ex:D,ey:j,ez:Z,et:P}=v,M=a(D*D),$=a(j*j),K=a(Z*Z),g=a(K*K),T=a(M*d),E=a(K*a(T+$)),O=a(g+a(I*a(M*$)));if(E!==O)throw new Error("bad point: equation left != right (1)");let B=a(D*j),R=a(Z*P);if(B!==R)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,I,D,j){this.ex=l("x",d),this.ey=l("y",I),this.ez=l("z",D,!0),this.et=l("t",j),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x:I,y:D}=d||{};return l("x",I),l("y",D),new m(I,D,Dt,a(I*D))}static normalizeZ(d){return al(m,"ez",d)}static msm(d,I){return ul(m,n,d,I)}_setWindowSize(d){this.precompute(d)}precompute(d=8,I=!0){return x.setWindowSize(this,d),I||this.multiply(Rh),this}assertValidity(){y(this)}equals(d){f(d);let{ex:I,ey:D,ez:j}=this,{ex:Z,ey:P,ez:M}=d,$=a(I*M),K=a(Z*j),g=a(D*M),T=a(P*j);return $===K&&g===T}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:I,ey:D,ez:j}=this,Z=a(I*I),P=a(D*D),M=a(Rh*a(j*j)),$=a(d*Z),K=I+D,g=a(a(K*K)-Z-P),T=$+P,E=T-M,O=$-P,B=a(g*E),R=a(T*O),k=a(g*O),L=a(E*T);return new m(B,R,L,k)}add(d){f(d);let{a:I,d:D}=r,{ex:j,ey:Z,ez:P,et:M}=this,{ex:$,ey:K,ez:g,et:T}=d,E=a(j*$),O=a(Z*K),B=a(M*D*T),R=a(P*g),k=a((j+Z)*($+K)-E-O),L=R-B,G=R+B,X=a(O-I*E),q=a(k*L),ie=a(G*X),Y=a(k*X),U=a(L*G);return new m(q,ie,U,Y)}subtract(d){return this.add(d.negate())}multiply(d){let I=d;Cr("scalar",I,Dt,i);let{p:D,f:j}=x.wNAFCached(this,I,m.normalizeZ);return m.normalizeZ([D,j])[0]}multiplyUnsafe(d,I=m.ZERO){let D=d;return Cr("scalar",D,zr,i),D===zr?m.ZERO:this.is0()||D===Dt?this:x.wNAFCachedUnsafe(this,D,m.normalizeZ,I)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return x.wNAFCachedUnsafe(this,i).is0()}toAffine(d){return p(this,d)}clearCofactor(){return o===Dt?this:this.multiplyUnsafe(o)}static fromBytes(d,I=!1){return Et(d),this.fromHex(d,I)}static fromHex(d,I=!1){let{d:D,a:j}=r,Z=t.BYTES;d=Ne("pointHex",d,Z),gn("zip215",I);let P=d.slice(),M=d[Z-1];P[Z-1]=M&-129;let $=Gr(P),K=I?s:t.ORDER;Cr("pointHex.y",$,zr,K);let g=a($*$),T=a(g-Dt),E=a(D*g-j),{isValid:O,value:B}=c(T,E);if(!O)throw new Error("Point.fromHex: invalid y coordinate");let R=(B&Dt)===Dt,k=(M&128)!==0;if(!I&&B===zr&&k)throw new Error("Point.fromHex: x=0 and x_0=1");return k!==R&&(B=a(-B)),m.fromAffine({x:B,y:$})}static fromPrivateScalar(d){return m.BASE.multiply(d)}toBytes(){let{x:d,y:I}=this.toAffine(),D=Qn(I,t.BYTES);return D[D.length-1]|=d&Dt?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return Fr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,Dt,a(r.Gx*r.Gy)),m.ZERO=new m(zr,Dt,Dt,zr),m.Fp=t,m.Fn=n;let x=cl(m,n.BYTES*8);return m}function WA(r,e){qr(e,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:t,hash:n}=e,{BASE:o,Fp:i,Fn:s}=r,a=s.ORDER,c=e.randomBytes||Mo,l=e.adjustScalarBytes||(P=>P),f=e.domain||((P,M,$)=>{if(gn("phflag",$),M.length||$)throw new Error("Contexts/pre-hash are not supported");return P});function p(P){return s.create(P)}function y(P){return p(Gr(P))}function m(P){let M=i.BYTES;P=Ne("private key",P,M);let $=Ne("hashed private key",n(P),2*M),K=l($.slice(0,M)),g=$.slice(M,2*M),T=y(K);return{head:K,prefix:g,scalar:T}}function x(P){let{head:M,prefix:$,scalar:K}=m(P),g=o.multiply(K),T=g.toBytes();return{head:M,prefix:$,scalar:K,point:g,pointBytes:T}}function v(P){return x(P).pointBytes}function d(P=Uint8Array.of(),...M){let $=Jt(...M);return y(n(f($,Ne("context",P),!!t)))}function I(P,M,$={}){P=Ne("message",P),t&&(P=t(P));let{prefix:K,scalar:g,pointBytes:T}=x(M),E=d($.context,K,P),O=o.multiply(E).toBytes(),B=d($.context,O,T,P),R=p(E+B*g);Cr("signature.s",R,zr,a);let k=i.BYTES,L=Jt(O,Qn(R,k));return Ne("result",L,k*2)}let D=VA;function j(P,M,$,K=D){let{context:g,zip215:T}=K,E=i.BYTES;P=Ne("signature",P,2*E),M=Ne("message",M),$=Ne("publicKey",$,E),T!==void 0&&gn("zip215",T),t&&(M=t(M));let O=Gr(P.slice(E,2*E)),B,R,k;try{B=r.fromHex($,T),R=r.fromHex(P.slice(0,E),T),k=o.multiplyUnsafe(O)}catch{return!1}if(!T&&B.isSmallOrder())return!1;let L=d(g,R.toBytes(),B.toBytes(),M);return R.add(B.multiplyUnsafe(L)).subtract(k).clearCofactor().is0()}return o.precompute(8),{getPublicKey:v,sign:I,verify:j,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>c(i.BYTES),precompute(P=8,M=r.BASE){return M.precompute(P,!1)}},Point:r}}function GA(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=Tr(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,eddsaOpts:i}}function qA(r,e){return Object.assign({},e,{ExtendedPoint:e.Point,CURVE:r})}function H0(r){let{CURVE:e,curveOpts:t,eddsaOpts:n}=GA(r),o=FA(e,t),i=WA(o,n);return qA(r,i)}var Ra=BigInt(0),hs=BigInt(1),fl=BigInt(2);function zA(r){return qr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function V0(r){let e=zA(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||Mo,l=a?255:448,f=a?32:56,p=BigInt(a?9:5),y=BigInt(a?121665:39081),m=a?fl**BigInt(254):fl**BigInt(447),x=a?BigInt(8)*fl**BigInt(251)-hs:BigInt(4)*fl**BigInt(445)-hs,v=m+x+hs,d=g=>je(g,t),I=D(p);function D(g){return Qn(d(g),f)}function j(g){let T=Ne("u coordinate",g,f);return a&&(T[31]&=127),d(Gr(T))}function Z(g){return Gr(o(Ne("scalar",g,f)))}function P(g,T){let E=K(j(T),Z(g));if(E===Ra)throw new Error("invalid private or public key received");return D(E)}function M(g){return P(g,I)}function $(g,T,E){let O=d(g*(T-E));return T=d(T-O),E=d(E+O),{x_2:T,x_3:E}}function K(g,T){Cr("u",g,Ra,t),Cr("scalar",T,m,v);let E=T,O=g,B=hs,R=Ra,k=g,L=hs,G=Ra;for(let q=BigInt(l-1);q>=Ra;q--){let ie=E>>q&hs;G^=ie,{x_2:B,x_3:k}=$(G,B,k),{x_2:R,x_3:L}=$(G,R,L),G=ie;let Y=B+R,U=d(Y*Y),de=B-R,Oe=d(de*de),se=U-Oe,De=k+L,_t=k-L,tt=d(_t*Y),rt=d(De*de),lt=tt+rt,sr=tt-rt;k=d(lt*lt),L=d(O*d(sr*sr)),B=d(U*Oe),R=d(se*(U+d(y*se)))}({x_2:B,x_3:k}=$(G,B,k)),{x_2:R,x_3:L}=$(G,R,L);let X=i(R);return d(B*X)}return{scalarMult:P,scalarMultBase:M,getSharedSecret:(g,T)=>P(g,T),getPublicKey:g=>M(g),utils:{randomPrivateKey:()=>c(f)},GuBytes:I.slice()}}var BP=BigInt(0),XA=BigInt(1),$0=BigInt(2),ZA=BigInt(3),YA=BigInt(5),JA=BigInt(8),La={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:JA,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function W0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=La.p,a=r*r%i*r%i,c=Me(a,$0,i)*a%i,l=Me(c,XA,i)*r%i,f=Me(l,YA,i)*l%i,p=Me(f,e,i)*f%i,y=Me(p,t,i)*p%i,m=Me(y,n,i)*y%i,x=Me(m,o,i)*m%i,v=Me(x,o,i)*m%i,d=Me(v,e,i)*f%i;return{pow_p_5_8:Me(d,$0,i)*r%i,b2:a}}function G0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var F0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function QA(r,e){let t=La.p,n=je(e*e*e,t),o=je(n*n*e,t),i=W0(r*o).pow_p_5_8,s=je(r*n*i,t),a=je(e*s*s,t),c=s,l=je(s*F0,t),f=a===r,p=a===je(-r,t),y=a===je(-r*F0,t);return f&&(s=c),(p||y)&&(s=l),B0(s,t)&&(s=je(-s,t)),{isValid:f||p,value:s}}var eE=Tr(La.p,void 0,!0),tE={...La,Fp:eE,hash:x0,adjustScalarBytes:G0,uvRatio:QA},Ua=H0(tE);var Ma=(()=>{let r=La.p;return V0({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=W0(e);return je(Me(t,ZA,r)*n,r)},adjustScalarBytes:G0})})();var Ka=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ha=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},pl=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var q0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new pl("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 Mt=q0;var hl=32,Va=64,Lh=32;var ds,z0=(async()=>{try{return await Mt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function X0(){let r=Ua.utils.randomPrivateKey(),e=Ua.getPublicKey(r);return{privateKey:sE(r,e),publicKey:e}}async function rE(r,e){let t;r.length===Va?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:le(r.subarray(32),"base64url"),d:le(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Mt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Mt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function nE(r,e){let t=r.subarray(0,Lh);return Ua.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function Z0(r,e){return ds==null&&(ds=await z0),ds?rE(r,e):nE(r,e)}async function oE(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Mt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Mt.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function iE(r,e,t){return Ua.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Y0(r,e,t){return ds==null&&(ds=await z0),ds?oE(r,e,t):iE(r,e,t)}function sE(r,e){let t=new Uint8Array(Va);for(let n=0;n<Lh;n++)t[n]=r[n],t[Lh+n]=e[n];return t}function ys(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var $a=class{type="Ed25519";raw;constructor(e){this.raw=yl(e,hl)}toMultihash(){return _r.digest(zn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=Y0(this.raw,t,e);return ys(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},dl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=yl(e,Va),this.publicKey=new $a(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=Z0(this.raw,e);return ys(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Uh(r){return r=yl(r,hl),new $a(r)}async function Q0(){let{privateKey:r,publicKey:e}=X0();return new dl(r,e)}function yl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Ie(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var aE=Math.pow(2,7),cE=Math.pow(2,14),uE=Math.pow(2,21),Mh=Math.pow(2,28),Kh=Math.pow(2,35),Hh=Math.pow(2,42),Vh=Math.pow(2,49),Ce=128,Ct=127;function Ve(r){if(r<aE)return 1;if(r<cE)return 2;if(r<uE)return 3;if(r<Mh)return 4;if(r<Kh)return 5;if(r<Hh)return 6;if(r<Vh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ms(r,e,t=0){switch(Ve(r)){case 8:e[t++]=r&255|Ce,r/=128;case 7:e[t++]=r&255|Ce,r/=128;case 6:e[t++]=r&255|Ce,r/=128;case 5:e[t++]=r&255|Ce,r/=128;case 4:e[t++]=r&255|Ce,r>>>=7;case 3:e[t++]=r&255|Ce,r>>>=7;case 2:e[t++]=r&255|Ce,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function lE(r,e,t=0){switch(Ve(r)){case 8:e.set(t++,r&255|Ce),r/=128;case 7:e.set(t++,r&255|Ce),r/=128;case 6:e.set(t++,r&255|Ce),r/=128;case 5:e.set(t++,r&255|Ce),r/=128;case 4:e.set(t++,r&255|Ce),r>>>=7;case 3:e.set(t++,r&255|Ce),r>>>=7;case 2:e.set(t++,r&255|Ce),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function $h(r,e){let t=r[e],n=0;if(n+=t&Ct,t<Ce||(t=r[e+1],n+=(t&Ct)<<7,t<Ce)||(t=r[e+2],n+=(t&Ct)<<14,t<Ce)||(t=r[e+3],n+=(t&Ct)<<21,t<Ce)||(t=r[e+4],n+=(t&Ct)*Mh,t<Ce)||(t=r[e+5],n+=(t&Ct)*Kh,t<Ce)||(t=r[e+6],n+=(t&Ct)*Hh,t<Ce)||(t=r[e+7],n+=(t&Ct)*Vh,t<Ce))return n;throw new RangeError("Could not decode varint")}function fE(r,e){let t=r.get(e),n=0;if(n+=t&Ct,t<Ce||(t=r.get(e+1),n+=(t&Ct)<<7,t<Ce)||(t=r.get(e+2),n+=(t&Ct)<<14,t<Ce)||(t=r.get(e+3),n+=(t&Ct)<<21,t<Ce)||(t=r.get(e+4),n+=(t&Ct)*Mh,t<Ce)||(t=r.get(e+5),n+=(t&Ct)*Kh,t<Ce)||(t=r.get(e+6),n+=(t&Ct)*Hh,t<Ce)||(t=r.get(e+7),n+=(t&Ct)*Vh,t<Ce))return n;throw new RangeError("Could not decode varint")}function ml(r,e,t=0){return e==null&&(e=it(Ve(r))),e instanceof Uint8Array?ms(r,e,t):lE(r,e,t)}function Wo(r,e=0){return r instanceof Uint8Array?$h(r,e):fE(r,e)}var Fh=new Float32Array([-0]),eo=new Uint8Array(Fh.buffer);function ew(r,e,t){Fh[0]=r,e[t]=eo[0],e[t+1]=eo[1],e[t+2]=eo[2],e[t+3]=eo[3]}function tw(r,e){return eo[0]=r[e],eo[1]=r[e+1],eo[2]=r[e+2],eo[3]=r[e+3],Fh[0]}var Wh=new Float64Array([-0]),Tt=new Uint8Array(Wh.buffer);function rw(r,e,t){Wh[0]=r,e[t]=Tt[0],e[t+1]=Tt[1],e[t+2]=Tt[2],e[t+3]=Tt[3],e[t+4]=Tt[4],e[t+5]=Tt[5],e[t+6]=Tt[6],e[t+7]=Tt[7]}function nw(r,e){return Tt[0]=r[e],Tt[1]=r[e+1],Tt[2]=r[e+2],Tt[3]=r[e+3],Tt[4]=r[e+4],Tt[5]=r[e+5],Tt[6]=r[e+6],Tt[7]=r[e+7],Wh[0]}var pE=BigInt(Number.MAX_SAFE_INTEGER),hE=BigInt(Number.MIN_SAFE_INTEGER),Qt=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 Go;if(e<pE&&e>hE)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>ow&&(o=0n,++n>ow&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Go;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):Go}},Go=new Qt(0,0);Go.toBigInt=function(){return 0n};Go.zzEncode=Go.zzDecode=function(){return this};Go.length=function(){return 1};var ow=4294967296n;function iw(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 sw(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 Gh(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 Ir(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function wl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var qh=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,Ir(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 Ir(this,4);return wl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ir(this,4);return wl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ir(this,4);let e=tw(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ir(this,4);let e=nw(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 Ir(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return sw(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ir(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ir(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 Qt(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 Ir(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 Ir(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 Ir(this,8);let e=wl(this.buf,this.pos+=4),t=wl(this.buf,this.pos+=4);return new Qt(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=$h(this.buf,this.pos);return this.pos+=Ve(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 zh(r){return new qh(r instanceof Uint8Array?r:r.subarray())}function Or(r,e,t){let n=zh(r);return e.decode(n,void 0,t)}function Xh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return it(s);o+s>e&&(n=it(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var qo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Zh(){}var Jh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},dE=Xh();function yE(r){return globalThis.Buffer!=null?it(r):dE(r)}var Wa=class{len;head;tail;states;constructor(){this.len=0,this.head=new qo(Zh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new qo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Qh((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(bl,10,Qt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Qt.fromBigInt(e);return this._push(bl,t.length(),t)}uint64Number(e){return this._push(ms,Ve(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=Qt.fromBigInt(e).zzEncode();return this._push(bl,t.length(),t)}sint64Number(e){let t=Qt.fromNumber(e).zzEncode();return this._push(bl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Yh,1,e?1:0)}fixed32(e){return this._push(Fa,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Qt.fromBigInt(e);return this._push(Fa,4,t.lo)._push(Fa,4,t.hi)}fixed64Number(e){let t=Qt.fromNumber(e);return this._push(Fa,4,t.lo)._push(Fa,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(ew,4,e)}double(e){return this._push(rw,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Yh,1,0):this.uint32(t)._push(gE,t,e)}string(e){let t=iw(e);return t!==0?this.uint32(t)._push(Gh,t,e):this._push(Yh,1,0)}fork(){return this.states=new Jh(this),this.head=this.tail=new qo(Zh,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 qo(Zh,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=yE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Yh(r,e,t){e[t]=r&255}function mE(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Qh=class extends qo{next;constructor(e,t){super(mE,e,t),this.next=void 0}};function bl(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 Fa(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 gE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Wa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(wE,e,r),this},Wa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(bE,e,r),this});function wE(r,e,t){e.set(r,t)}function bE(r,e,t){r.length<40?Gh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(he(r),t)}function ed(){return new Wa}function Pr(r,e){let t=ed();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var gs;(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"})(gs||(gs={}));function xl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function zo(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 xl("enum",gs.VARINT,t,n)}function Br(r,e){return xl("message",gs.LENGTH_DELIMITED,r,e)}var Ga=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var td;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(td||(td={}));(function(r){r.codec=()=>zo(td)})(Ye||(Ye={}));var Xr;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.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=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Xr||(Xr={}));var rd;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.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=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(rd||(rd={}));var za={};St(za,{MAX_RSA_KEY_SIZE:()=>nd,generateRSAKeyPair:()=>pd,jwkToJWKKeyPair:()=>pw,jwkToPkcs1:()=>SE,jwkToPkix:()=>ad,jwkToRSAPrivateKey:()=>fd,pkcs1MessageToJwk:()=>id,pkcs1MessageToRSAPrivateKey:()=>cd,pkcs1ToJwk:()=>_E,pkcs1ToRSAPrivateKey:()=>fw,pkixMessageToJwk:()=>sd,pkixMessageToRSAPublicKey:()=>ld,pkixToJwk:()=>AE,pkixToRSAPublicKey:()=>ud});var to=il;var ws=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=za.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Ze.createV1(114,this._multihash)}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return lw(this.jwk,t,e,n)}},qa=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=za.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return uw(this.jwk,e,t)}};var nd=8192,od=18,xE=1062,vE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function _E(r){let e=dn(r);return id(e)}function id(r){return{n:le(r[1],"base64url"),e:le(r[2],"base64url"),d:le(r[3],"base64url"),p:le(r[4],"base64url"),q:le(r[5],"base64url"),dp:le(r[6],"base64url"),dq:le(r[7],"base64url"),qi:le(r[8],"base64url"),kty:"RSA"}}function SE(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 Ie("JWK was missing components");return Sr([Nt(Uint8Array.from([0])),Nt(he(r.n,"base64url")),Nt(he(r.e,"base64url")),Nt(he(r.d,"base64url")),Nt(he(r.p,"base64url")),Nt(he(r.q,"base64url")),Nt(he(r.dp,"base64url")),Nt(he(r.dq,"base64url")),Nt(he(r.qi,"base64url"))]).subarray()}function AE(r){let e=dn(r,{offset:0});return sd(e)}function sd(r){let e=dn(r[1],{offset:0});return{kty:"RSA",n:le(e[0],"base64url"),e:le(e[1],"base64url")}}function ad(r){if(r.n==null||r.e==null)throw new Ie("JWK was missing components");return Sr([vE,Oa(Sr([Nt(he(r.n,"base64url")),Nt(he(r.e,"base64url"))]))]).subarray()}function fw(r){let e=dn(r);return cd(e)}function cd(r){let e=id(r);return fd(e)}function ud(r,e){if(r.byteLength>=xE)throw new Qi("Key size is too large");let t=dn(r,{offset:0});return ld(t,r,e)}function ld(r,e,t){let n=sd(r);if(t==null){let o=to(Xr.encode({Type:Ye.RSA,Data:e}));t=At(od,o)}return new ws(n,t)}function fd(r){if(dw(r)>nd)throw new Ie("Key size is too large");let e=pw(r),t=to(Xr.encode({Type:Ye.RSA,Data:ad(e.publicKey)})),n=At(od,t);return new qa(e.privateKey,new ws(e.publicKey,n))}async function pd(r){if(r>nd)throw new Ie("Key size is too large");let e=await hw(r),t=to(Xr.encode({Type:Ye.RSA,Data:ad(e.publicKey)})),n=At(od,t);return new qa(e.privateKey,new ws(e.publicKey,n))}function pw(r){if(r==null)throw new Ie("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function hw(r,e){let t=await Mt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await EE(t,e);return{privateKey:n[0],publicKey:n[1]}}async function uw(r,e,t){let n=await Mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Mt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function lw(r,e,t,n){let o=await Mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function EE(r,e){if(r.privateKey==null||r.publicKey==null)throw new Ie("Private and public key are required");let t=await Promise.all([Mt.get().subtle.exportKey("jwk",r.privateKey),Mt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function dw(r){if(r.kty!=="RSA")throw new Ie("invalid key type");if(r.n==null)throw new Ie("invalid key modulus");return he(r.n,"base64url").length*8}var vl=class extends is{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Pa(e);let n=Xn(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),Ar(i)}update(e){return as(this),this.iHash.update(e),this}digestInto(e){as(this),Et(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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},bs=(r,e,t)=>new vl(r,e).update(t).digest();bs.create=(r,e)=>new vl(r,e);function yw(r){r.lowS!==void 0&&gn("lowS",r.lowS),r.prehash!==void 0&&gn("prehash",r.prehash)}var hd=class extends Error{constructor(e=""){super(e)}},wn={Err:hd,_tlv:{encode:(r,e)=>{let{Err:t}=wn;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=Da(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Da(o.length/2|128):"";return Da(r)+i+o+e},decode(r,e){let{Err:t}=wn,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 l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let f of l)s=s<<8|f;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}=wn;if(r<Xa)throw new e("integer: negative integers are not allowed");let t=Da(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}=wn;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 us(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=wn,o=Ne("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:l,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=wn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},Xa=BigInt(0),Za=BigInt(1),CE=BigInt(2),_l=BigInt(3),TE=BigInt(4);function IE(r,e,t){function n(o){let i=r.sqr(o),s=r.mul(i,o);return r.add(r.add(s,r.mul(o,e)),t)}return n}function mw(r,e,t){let{BYTES:n}=r;function o(i){let s;if(typeof i=="bigint")s=i;else{let a=Ne("private key",i);if(e){if(!e.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{s=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof i}`)}}if(t&&(s=r.create(s)),!r.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}return o}function OE(r,e={}){let{Fp:t,Fn:n}=ll("weierstrass",r,e),{h:o,n:i}=r;qr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:s}=e;if(s&&(!t.is0(r.a)||typeof s.beta!="bigint"||typeof s.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(K,g,T){let{x:E,y:O}=g.toAffine(),B=t.toBytes(E);if(gn("isCompressed",T),T){a();let R=!t.isOdd(O);return Jt(gw(R),B)}else return Jt(Uint8Array.of(4),B,t.toBytes(O))}function l(K){Et(K);let g=t.BYTES,T=g+1,E=2*g+1,O=K.length,B=K[0],R=K.subarray(1);if(O===T&&(B===2||B===3)){let k=t.fromBytes(R);if(!t.isValid(k))throw new Error("bad point: is not on curve, wrong x");let L=y(k),G;try{G=t.sqrt(L)}catch(ie){let Y=ie instanceof Error?": "+ie.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}a();let X=t.isOdd(G);return(B&1)===1!==X&&(G=t.neg(G)),{x:k,y:G}}else if(O===E&&B===4){let k=t.fromBytes(R.subarray(g*0,g*1)),L=t.fromBytes(R.subarray(g*1,g*2));if(!m(k,L))throw new Error("bad point: is not on curve");return{x:k,y:L}}else throw new Error(`bad point: got length ${O}, expected compressed=${T} or uncompressed=${E}`)}let f=e.toBytes||c,p=e.fromBytes||l,y=IE(t,r.a,r.b);function m(K,g){let T=t.sqr(g),E=y(K);return t.eql(T,E)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let x=t.mul(t.pow(r.a,_l),TE),v=t.mul(t.sqr(r.b),BigInt(27));if(t.is0(t.add(x,v)))throw new Error("bad curve params: a or b");function d(K,g,T=!1){if(!t.isValid(g)||T&&t.is0(g))throw new Error(`bad point coordinate ${K}`);return g}function I(K){if(!(K instanceof P))throw new Error("ProjectivePoint expected")}let D=ls((K,g)=>{let{px:T,py:E,pz:O}=K;if(t.eql(O,t.ONE))return{x:T,y:E};let B=K.is0();g==null&&(g=B?t.ONE:t.inv(O));let R=t.mul(T,g),k=t.mul(E,g),L=t.mul(O,g);if(B)return{x:t.ZERO,y:t.ZERO};if(!t.eql(L,t.ONE))throw new Error("invZ was invalid");return{x:R,y:k}}),j=ls(K=>{if(K.is0()){if(e.allowInfinityPoint&&!t.is0(K.py))return;throw new Error("bad point: ZERO")}let{x:g,y:T}=K.toAffine();if(!t.isValid(g)||!t.isValid(T))throw new Error("bad point: x or y not field elements");if(!m(g,T))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Z(K,g,T,E,O){return T=new P(t.mul(T.px,K),T.py,T.pz),g=fs(E,g),T=fs(O,T),g.add(T)}class P{constructor(g,T,E){this.px=d("x",g),this.py=d("y",T,!0),this.pz=d("z",E),Object.freeze(this)}static fromAffine(g){let{x:T,y:E}=g||{};if(!g||!t.isValid(T)||!t.isValid(E))throw new Error("invalid affine point");if(g instanceof P)throw new Error("projective point not allowed");return t.is0(T)&&t.is0(E)?P.ZERO:new P(T,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){return al(P,"pz",g)}static fromBytes(g){return Et(g),P.fromHex(g)}static fromHex(g){let T=P.fromAffine(p(Ne("pointHex",g)));return T.assertValidity(),T}static fromPrivateKey(g){let T=mw(n,e.allowedPrivateKeyLengths,e.wrapPrivateKey);return P.BASE.multiply(T(g))}static msm(g,T){return ul(P,n,g,T)}precompute(g=8,T=!0){return $.setWindowSize(this,g),T||this.multiply(_l),this}_setWindowSize(g){this.precompute(g)}assertValidity(){j(this)}hasEvenY(){let{y:g}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(g)}equals(g){I(g);let{px:T,py:E,pz:O}=this,{px:B,py:R,pz:k}=g,L=t.eql(t.mul(T,k),t.mul(B,O)),G=t.eql(t.mul(E,k),t.mul(R,O));return L&&G}negate(){return new P(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:T}=r,E=t.mul(T,_l),{px:O,py:B,pz:R}=this,k=t.ZERO,L=t.ZERO,G=t.ZERO,X=t.mul(O,O),q=t.mul(B,B),ie=t.mul(R,R),Y=t.mul(O,B);return Y=t.add(Y,Y),G=t.mul(O,R),G=t.add(G,G),k=t.mul(g,G),L=t.mul(E,ie),L=t.add(k,L),k=t.sub(q,L),L=t.add(q,L),L=t.mul(k,L),k=t.mul(Y,k),G=t.mul(E,G),ie=t.mul(g,ie),Y=t.sub(X,ie),Y=t.mul(g,Y),Y=t.add(Y,G),G=t.add(X,X),X=t.add(G,X),X=t.add(X,ie),X=t.mul(X,Y),L=t.add(L,X),ie=t.mul(B,R),ie=t.add(ie,ie),X=t.mul(ie,Y),k=t.sub(k,X),G=t.mul(ie,q),G=t.add(G,G),G=t.add(G,G),new P(k,L,G)}add(g){I(g);let{px:T,py:E,pz:O}=this,{px:B,py:R,pz:k}=g,L=t.ZERO,G=t.ZERO,X=t.ZERO,q=r.a,ie=t.mul(r.b,_l),Y=t.mul(T,B),U=t.mul(E,R),de=t.mul(O,k),Oe=t.add(T,E),se=t.add(B,R);Oe=t.mul(Oe,se),se=t.add(Y,U),Oe=t.sub(Oe,se),se=t.add(T,O);let De=t.add(B,k);return se=t.mul(se,De),De=t.add(Y,de),se=t.sub(se,De),De=t.add(E,O),L=t.add(R,k),De=t.mul(De,L),L=t.add(U,de),De=t.sub(De,L),X=t.mul(q,se),L=t.mul(ie,de),X=t.add(L,X),L=t.sub(U,X),X=t.add(U,X),G=t.mul(L,X),U=t.add(Y,Y),U=t.add(U,Y),de=t.mul(q,de),se=t.mul(ie,se),U=t.add(U,de),de=t.sub(Y,de),de=t.mul(q,de),se=t.add(se,de),Y=t.mul(U,se),G=t.add(G,Y),Y=t.mul(De,se),L=t.mul(Oe,L),L=t.sub(L,Y),Y=t.mul(Oe,U),X=t.mul(De,X),X=t.add(X,Y),new P(L,G,X)}subtract(g){return this.add(g.negate())}is0(){return this.equals(P.ZERO)}multiply(g){let{endo:T}=e;if(!n.isValidNot0(g))throw new Error("invalid scalar: out of range");let E,O,B=R=>$.wNAFCached(this,R,P.normalizeZ);if(T){let{k1neg:R,k1:k,k2neg:L,k2:G}=T.splitScalar(g),{p:X,f:q}=B(k),{p:ie,f:Y}=B(G);O=q.add(Y),E=Z(T.beta,X,ie,R,L)}else{let{p:R,f:k}=B(g);E=R,O=k}return P.normalizeZ([E,O])[0]}multiplyUnsafe(g){let{endo:T}=e,E=this;if(!n.isValid(g))throw new Error("invalid scalar: out of range");if(g===Xa||E.is0())return P.ZERO;if(g===Za)return E;if($.hasPrecomputes(this))return this.multiply(g);if(T){let{k1neg:O,k1:B,k2neg:R,k2:k}=T.splitScalar(g),{p1:L,p2:G}=K0(P,E,B,k);return Z(T.beta,L,G,O,R)}else return $.wNAFCachedUnsafe(E,g)}multiplyAndAddUnsafe(g,T,E){let O=this.multiplyUnsafe(T).add(g.multiplyUnsafe(E));return O.is0()?void 0:O}toAffine(g){return D(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return o===Za?!0:g?g(P,this):$.wNAFCachedUnsafe(this,i).is0()}clearCofactor(){let{clearCofactor:g}=e;return o===Za?this:g?g(P,this):this.multiplyUnsafe(o)}toBytes(g=!0){return gn("isCompressed",g),this.assertValidity(),f(P,this,g)}toRawBytes(g=!0){return this.toBytes(g)}toHex(g=!0){return Fr(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}P.BASE=new P(r.Gx,r.Gy,t.ONE),P.ZERO=new P(t.ZERO,t.ONE,t.ZERO),P.Fp=t,P.Fn=n;let M=n.BITS,$=cl(P,e.endo?Math.ceil(M/2):M);return P}function gw(r){return Uint8Array.of(r?2:3)}function PE(r,e,t={}){qr(e,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Mo,o=e.hmac||((E,...O)=>bs(e.hash,E,Jt(...O))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s;function l(E){let O=a>>Za;return E>O}function f(E){return l(E)?s.neg(E):E}function p(E,O){if(!s.isValidNot0(O))throw new Error(`invalid signature ${E}: out of range 1..CURVE.n`)}class y{constructor(O,B,R){p("r",O),p("s",B),this.r=O,this.s=B,R!=null&&(this.recovery=R),Object.freeze(this)}static fromCompact(O){let B=s.BYTES,R=Ne("compactSignature",O,B*2);return new y(s.fromBytes(R.subarray(0,B)),s.fromBytes(R.subarray(B,B*2)))}static fromDER(O){let{r:B,s:R}=wn.toSig(Ne("DER",O));return new y(B,R)}assertValidity(){}addRecoveryBit(O){return new y(this.r,this.s,O)}recoverPublicKey(O){let B=i.ORDER,{r:R,s:k,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*CE<B&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let X=L===2||L===3?R+a:R;if(!i.isValid(X))throw new Error("recovery id 2 or 3 invalid");let q=i.toBytes(X),ie=r.fromHex(Jt(gw((L&1)===0),q)),Y=s.inv(X),U=j(Ne("msgHash",O)),de=s.create(-U*Y),Oe=s.create(k*Y),se=r.BASE.multiplyUnsafe(de).add(ie.multiplyUnsafe(Oe));if(se.is0())throw new Error("point at infinify");return se.assertValidity(),se}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,s.neg(this.s),this.recovery):this}toBytes(O){if(O==="compact")return Jt(s.toBytes(this.r),s.toBytes(this.s));if(O==="der")return cs(wn.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Fr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Fr(this.toBytes("compact"))}}let m=mw(s,t.allowedPrivateKeyLengths,t.wrapPrivateKey),x={isValidPrivateKey(E){try{return m(E),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let E=a;return D0(n(Nh(E)),E)},precompute(E=8,O=r.BASE){return O.precompute(E,!1)}};function v(E,O=!0){return r.fromPrivateKey(E).toBytes(O)}function d(E){if(typeof E=="bigint")return!1;if(E instanceof r)return!0;let B=Ne("key",E).length,R=i.BYTES,k=R+1,L=2*R+1;if(!(t.allowedPrivateKeyLengths||s.BYTES===k))return B===k||B===L}function I(E,O,B=!0){if(d(E)===!0)throw new Error("first arg must be private key");if(d(O)===!1)throw new Error("second arg must be public key");return r.fromHex(O).multiply(m(E)).toBytes(B)}let D=e.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let O=us(E),B=E.length*8-c;return B>0?O>>BigInt(B):O},j=e.bits2int_modN||function(E){return s.create(D(E))},Z=Vo(c);function P(E){return Cr("num < 2^"+c,E,Xa,Z),s.toBytes(E)}function M(E,O,B=$){if(["recovered","canonical"].some(Oe=>Oe in B))throw new Error("sign() legacy options not supported");let{hash:R}=e,{lowS:k,prehash:L,extraEntropy:G}=B;k==null&&(k=!0),E=Ne("msgHash",E),yw(B),L&&(E=Ne("prehashed msgHash",R(E)));let X=j(E),q=m(O),ie=[P(q),P(X)];if(G!=null&&G!==!1){let Oe=G===!0?n(i.BYTES):G;ie.push(Ne("extraEntropy",Oe))}let Y=Jt(...ie),U=X;function de(Oe){let se=D(Oe);if(!s.isValidNot0(se))return;let De=s.inv(se),_t=r.BASE.multiply(se).toAffine(),tt=s.create(_t.x);if(tt===Xa)return;let rt=s.create(De*s.create(U+tt*q));if(rt===Xa)return;let lt=(_t.x===tt?0:2)|Number(_t.y&Za),sr=rt;return k&&l(rt)&&(sr=f(rt),lt^=1),new y(tt,sr,lt)}return{seed:Y,k2sig:de}}let $={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function g(E,O,B=$){let{seed:R,k2sig:k}=M(E,O,B);return A0(e.hash.outputLen,s.BYTES,o)(R,k)}r.BASE.precompute(8);function T(E,O,B,R=K){let k=E;O=Ne("msgHash",O),B=Ne("publicKey",B),yw(R);let{lowS:L,prehash:G,format:X}=R;if("strict"in R)throw new Error("options.strict was renamed to lowS");if(X!==void 0&&!["compact","der","js"].includes(X))throw new Error('format must be "compact", "der" or "js"');let q=typeof k=="string"||ss(k),ie=!q&&!X&&typeof k=="object"&&k!==null&&typeof k.r=="bigint"&&typeof k.s=="bigint";if(!q&&!ie)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Y,U;try{if(ie)if(X===void 0||X==="js")Y=new y(k.r,k.s);else throw new Error("invalid format");if(q){try{X!=="compact"&&(Y=y.fromDER(k))}catch(sr){if(!(sr instanceof wn.Err))throw sr}!Y&&X!=="der"&&(Y=y.fromCompact(k))}U=r.fromHex(B)}catch{return!1}if(!Y||L&&Y.hasHighS())return!1;G&&(O=e.hash(O));let{r:de,s:Oe}=Y,se=j(O),De=s.inv(Oe),_t=s.create(se*De),tt=s.create(de*De),rt=r.BASE.multiplyUnsafe(_t).add(U.multiplyUnsafe(tt));return rt.is0()?!1:s.create(rt.x)===de}return Object.freeze({getPublicKey:v,getSharedSecret:I,sign:g,verify:T,utils:x,Point:r,Signature:y})}function BE(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=Tr(e.n,r.nBitLength),o={Fp:t,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:o}}function NE(r){let{CURVE:e,curveOpts:t}=BE(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,ecdsaOpts:n}}function kE(r,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:r})}function ww(r){let{CURVE:e,curveOpts:t,ecdsaOpts:n}=NE(r),o=OE(e,t),i=PE(o,n,t);return kE(r,i)}function bw(r,e){let t=n=>ww({...r,hash:n});return{...t(e),create:t}}var Sl={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},d8=BigInt(0),DE=BigInt(1),dd=BigInt(2),xw=(r,e)=>(r+e/dd)/e;function jE(r){let e=Sl.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,f=l*l*r%e,p=Me(f,t,e)*f%e,y=Me(p,t,e)*f%e,m=Me(y,dd,e)*l%e,x=Me(m,o,e)*m%e,v=Me(x,i,e)*x%e,d=Me(v,a,e)*v%e,I=Me(d,c,e)*d%e,D=Me(I,a,e)*v%e,j=Me(D,t,e)*f%e,Z=Me(j,s,e)*x%e,P=Me(Z,n,e)*l%e,M=Me(P,dd,e);if(!yd.eql(yd.sqr(M),r))throw new Error("Cannot find square root");return M}var yd=Tr(Sl.p,void 0,void 0,{sqrt:jE}),Nr=bw({...Sl,Fp:yd,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Sl.n,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-DE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=xw(i*r,e),c=xw(-n*r,e),l=je(r-a*t-c*o,e),f=je(-a*n-c*i,e),p=l>s,y=f>s;if(p&&(l=e-l),y&&(f=e-f),l>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:l,k2neg:y,k2:f}}}},il);function vw(r,e,t){let n=ar.digest(e instanceof Uint8Array?e:e.subarray());if(ys(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Nr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ka(String(o))});try{return Nr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Ka(String(o))}}function _w(r,e,t,n){let o=ar.digest(t instanceof Uint8Array?t:t.subarray());if(ys(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Nr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Ha(String(i))});try{return n?.signal?.throwIfAborted(),Nr.verify(e,o.digest,r)}catch(i){throw new Ha(String(i))}}var Ya=class{type="secp256k1";raw;_key;constructor(e){this._key=Ew(e),this.raw=Sw(this._key)}toMultihash(){return _r.digest(zn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return _w(this._key,t,e,n)}},Al=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=Aw(e),this.publicKey=new Ya(t??Cw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return vw(this.raw,e,t)}};function md(r){return new Ya(r)}async function Tw(){let r=RE();return new Al(r)}function Sw(r){return Nr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Aw(r){try{return Nr.getPublicKey(r,!0),r}catch(e){throw new _a(String(e))}}function Ew(r){try{return Nr.ProjectivePoint.fromHex(r),r}catch(e){throw new Qi(String(e))}}function Cw(r){try{return Nr.getPublicKey(r,!0)}catch(e){throw new _a(String(e))}}function RE(){return Nr.utils.randomPrivateKey()}async function Iw(r,e){if(r==="Ed25519")return Q0();if(r==="secp256k1")return Tw();if(r==="RSA")return pd(LE(e));if(r==="ECDSA")return o0(UE(e));throw new Fn}function Ja(r,e){let{Type:t,Data:n}=Xr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return ud(o,e);case Ye.Ed25519:return Uh(o);case Ye.secp256k1:return md(o);case Ye.ECDSA:return Sh(o);default:throw new Fn}}function Ow(r){let{Type:e,Data:t}=Xr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return Uh(n);case Ye.secp256k1:return md(n);case Ye.ECDSA:return Sh(n);default:throw new Fn}}function zn(r){return Xr.encode({Type:Ye[r.type],Data:r.raw})}function LE(r){return r==null?2048:parseInt(r,10)}function UE(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 Ie("Unsupported curve, should be P-256, P-384 or P-521")}async function El(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 Ie("Only RSA and ECDSA keys are supported")}var Pw=Symbol.for("nodejs.util.inspect.custom"),ME=114,Qa=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()})`}[Zp]=!0;toString(){return this.string==null&&(this.string=He.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Ze.createV1(ME,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return We(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return We(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Pw](){return`PeerId(${this.toString()})`}},ec=class extends Qa{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},tc=class extends Qa{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},rc=class extends Qa{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},KE=2336,nc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=_r.digest(he(this.url))}[Pw](){return`PeerId(${this.url})`}[Zp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Ze.createV1(KE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=le(e)),e.toString()===this.toString())}};var HE=114,Bw=2336;function Cl(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=os(He.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return VE(Ze.parse(r));if(e==null)throw new Ie('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=os(e.decode(r))}return Nw(t)}function gd(r){if(r.type==="Ed25519")return new tc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new rc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ec({multihash:r.toCID().multihash,publicKey:r});throw new Fn}function Nw(r){if(FE(r))return new ec({multihash:r});if($E(r))try{let e=Ow(r);if(e.type==="Ed25519")return new tc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new rc({multihash:r,publicKey:e})}catch{let t=le(r.digest);return new nc(new URL(t))}throw new qu("Supplied PeerID Multihash is invalid")}function VE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==HE&&r.code!==Bw)throw new Gu("Supplied PeerID CID is invalid");if(r.code===Bw){let e=le(r.multihash.digest);return new nc(new URL(e))}return Nw(r.multihash)}function $E(r){return r.code===_r.code}function FE(r){return r.code===ar.code}var pt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},bn=class extends Error{static name="ValidationError";name="ValidationError"},oc=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Tl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Il=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",l=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let y=Number.parseInt(p,e);if(!Number.isNaN(y))return y});if(f===void 0)break;if(i*=e,i+=f,i>l||(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 WE=45,GE=15,Ol=new Il;function wd(r){if(!(r.length>GE))return Ol.new(r).parseWith(()=>Ol.readIPv4Addr())}function bd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>WE))return Ol.new(r).parseWith(()=>Ol.readIPv6Addr())}function Pl(r){return!!wd(r)}function Dw(r){return!!bd(r)}function vd(r){return e=>le(e,r)}function _d(r){return e=>he(e,r)}function xs(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Xo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function jw(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=he(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Xo(n);return Bt([t,o],t.length+o.length)}function Rw(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=qn.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=Xo(n);return Bt([t,o],t.length+o.length)}function Sd(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=le(e,"base32"),o=xs(t);return`${n}:${o}`}var Ad=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new pt("Invalid byte value in IP address");e[n]=o}),e},Lw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Pl(t[n]),s;i&&(s=Ad(t[n]),t[n]=le(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,le(s.subarray(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++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new pt("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Uw=function(r){if(r.byteLength!==4)throw new pt("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Mw=function(r){if(r.byteLength!==16)throw new pt("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${t}"`)}};function Kw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${r}"`)}}var xd=Object.values(jo).map(r=>r.decoder),qE=function(){let r=xd[0].or(xd[1]);return xd.slice(2).forEach(e=>r=r.or(e)),r}();function Hw(r){return qE.decode(r)}function Vw(r){return e=>r.encoder.encode(e)}function zE(r){if(parseInt(r).toString()!==r)throw new bn("Value must be an integer")}function XE(r){if(r<0)throw new bn("Value must be a positive integer, or zero")}function ZE(r){return e=>{if(e>r)throw new bn(`Value must be smaller than or equal to ${r}`)}}function YE(...r){return e=>{for(let t of r)t(e)}}var ic=YE(zE,XE,ZE(65535));var ut=-1,Ed=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Tl(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},er=new Ed,p2=[{code:4,name:"ip4",size:32,valueToBytes:Ad,bytesToValue:Uw,validate:r=>{if(!Pl(r))throw new bn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Xo,bytesToValue:xs,validate:ic},{code:273,name:"udp",size:16,valueToBytes:Xo,bytesToValue:xs,validate:ic},{code:33,name:"dccp",size:16,valueToBytes:Xo,bytesToValue:xs,validate:ic},{code:41,name:"ip6",size:128,valueToBytes:Lw,bytesToValue:Mw,stringToValue:Kw,validate:r=>{if(!Dw(r))throw new bn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:vd("base10"),valueToBytes:_d("base10")},{code:53,name:"dns",size:ut,resolvable:!0},{code:54,name:"dns4",size:ut,resolvable:!0},{code:55,name:"dns6",size:ut,resolvable:!0},{code:56,name:"dnsaddr",size:ut,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Xo,bytesToValue:xs,validate:ic},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:vd("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?_d("base58btc")(r):Ze.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Sd,valueToBytes:jw},{code:445,name:"onion3",size:296,bytesToValue:Sd,valueToBytes:Rw},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Vw(Do),valueToBytes:Hw},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];p2.forEach(r=>{er.addProtocol(r)});function $w(r){let e=[],t=0;for(;t<r.length;){let n=Wo(r,t),o=er.getProtocol(n),i=Ve(n),s=h2(o,r,t+i),a=0;s>0&&o.size===ut&&(a=Ve(s));let c=i+a+s,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let f=t+i+a,p=r.subarray(f,f+s);l.value=o.bytesToValue?.(p)??le(p)}e.push(l),t+=c}return e}function Fw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=er.getProtocol(n.code),i=Ve(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??he(n.value),a=s.byteLength,o.size===ut&&(c=Ve(a)));let l=new Uint8Array(i+c+a),f=0;ms(n.code,l,f),f+=i,s!=null&&(o.size===ut&&(ms(a,l,f),f+=c),l.set(s,f)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Bt(t,e)}function Ww(r){if(r.charAt(0)!=="/")throw new pt('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=er.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new pt(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new pt(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new pt("Incomplete multiaddr");return e}function Gw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=er.getProtocol(e.code);if(t==null)throw new pt(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function h2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Wo(e,t)}var d2=Symbol.for("nodejs.util.inspect.custom"),jd=Symbol.for("@multiformats/multiaddr"),y2=[53,54,55,56],Dd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function m2(r){if(r==null&&(r="/"),zw(r))return r.getComponents();if(r instanceof Uint8Array)return $w(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Ww(r);if(Array.isArray(r))return r;throw new pt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Dl=class r{[jd]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=m2(e),t.validate!==!1&&g2(this)}get bytes(){return this.#r==null&&(this.#r=Fw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Gw(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="";for(let{code:a,name:c,value:l}of this.#e)a===42&&(i=`%${l??""}`),y2.includes(a)&&(t="tcp",o=443,n=`${l??""}${i}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(t="tcp",n=`${l??""}${i}`,e=a===41?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}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=er.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=er.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??he(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new oc(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?le(He.decode(`z${n}`),"base58btc"):le(Ze.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(er.getProtocol(e.code).path)return e.value??null;return null}equals(e){return We(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=qw.get(t.name);if(n==null)throw new Dd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>xn(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(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[d2](){return`Multiaddr(${this.toString()})`}};function g2(r){r.getComponents().forEach(e=>{let t=er.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var t5=parseInt("0xFFFF",16),r5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var qw=new Map;function zw(r){return!!r?.[jd]}function xn(r){return new Dl(r)}var Re=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),fe=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),ve=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),It=(...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}}),Te=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function ke(...r){function e(o){let i=o.getComponents();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 _2=fe(421),F5=ke(_2),Rl=fe(54),Ll=fe(55),Ul=fe(56),Ld=fe(53),W5=ke(Rl,ve(fe(421))),G5=ke(Ll,ve(fe(421))),q5=ke(Ul,ve(fe(421))),z5=ke(It(Ld,Ul,Rl,Ll),ve(fe(421))),Yw=Te(fe(4),ve(fe(43))),Jw=Te(ve(fe(42)),fe(41),ve(fe(43))),Ud=It(Yw,Jw),Jo=It(Ud,Ld,Rl,Ll,Ul),X5=ke(It(Ud,Te(It(Ld,Ul,Rl,Ll),ve(fe(421))))),Z5=ke(Yw),Y5=ke(Jw),J5=ke(Ud),Md=Te(Jo,fe(6)),fc=Te(Jo,fe(273)),Q5=ke(Te(Md,ve(fe(421)))),e4=ke(fc),Kd=Te(fc,Re(460),ve(fe(421))),Ml=Te(fc,Re(461),ve(fe(421))),S2=It(Kd,Ml),t4=ke(Kd),r4=ke(Ml),Rd=It(Jo,Md,fc,Kd,Ml),Qw=It(Te(Rd,Re(477),ve(fe(421)))),n4=ke(Qw),eb=It(Te(Rd,Re(478),ve(fe(421))),Te(Rd,Re(448),ve(fe(449)),Re(477),ve(fe(421)))),o4=ke(eb),tb=Te(fc,Re(280),ve(fe(466)),ve(fe(466)),ve(fe(421))),rb=ke(tb),nb=Te(Ml,Re(465),ve(fe(466)),ve(fe(466)),ve(fe(421))),i4=ke(nb),jl=It(Qw,eb,Te(Md,ve(fe(421))),Te(S2,ve(fe(421))),Te(Jo,ve(fe(421))),tb,nb,fe(421)),ob=ke(jl),A2=Te(jl,Re(290),fe(421)),s4=ke(A2),E2=It(Te(jl,Re(290),Re(281),ve(fe(421))),Te(jl,Re(281),ve(fe(421))),Te(Re(281),ve(fe(421)))),ib=ke(E2),C2=It(Te(Jo,fe(6),Re(480),ve(fe(421))),Te(Jo,Re(480),ve(fe(421)))),a4=ke(C2),T2=Te(Jo,It(Te(fe(6,"443"),Re(480)),Te(fe(6),Re(443)),Te(fe(6),Re(448),Re(480)),Te(Re(448),Re(480)),Re(448),Re(443)),ve(fe(421))),c4=ke(T2),I2=It(Te(fe(777),ve(fe(421)))),u4=ke(I2),O2=It(Te(fe(400),ve(fe(421)))),l4=ke(O2);var Ot;(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=()=>zo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Br((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 l=o.uint32();switch(l>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Pr(o,r.codec()),r.decode=(o,i)=>Or(o,r.codec(),i)})(Ot||(Ot={}));var sb=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Hd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),ab="libp2p+webrtc+v1/";var cb=466,ub=2*1024*1024,lb=30*1e3,Cs=16*1024;function P2(r=Cs){let e=Ve(r-Ve(r)),t=1+Ve(Object.keys(Ot.Flag).length-1),n=1,o=r-e-t-n,i=Ve(o);return e+t+n+i}var fb=P2(),pb=5e3,hb=5e3,db=3e4,Vd="/webrtc",pc="/webrtc-signaling/0.0.1",yb="/libp2p/webrtc-direct/certificate",mb="webrtc-direct-certificate-private-key";var gb=12096e5,$d=864e5;var wb=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))},B2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var N2=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 D2=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 R2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,L2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,bb=3,U2=[["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",R2]],xb=[["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 _b(r){return r?vb(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new j2:typeof navigator<"u"?vb(navigator.userAgent):H2()}function M2(r){return r!==""&&U2.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 vb(r){var e=M2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new D2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<bb&&(o=wb(wb([],o,!0),V2(bb-o.length),!0)):o=[];var i=o.join("."),s=K2(r),a=L2.exec(r);return a&&a[1]?new k2(t,i,s,a[1]):new B2(t,i,s)}function K2(r){for(var e=0,t=xb.length;e<t;e++){var n=xb[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function H2(){var r=typeof process<"u"&&process.version;return r?new N2(process.version.slice(1)):null}function V2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Je(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Fd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Wd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Sb=r=>globalThis.DOMException===void 0?new Wd(r):new DOMException(r),Ab=r=>{let e=r.reason===void 0?Sb("This operation was aborted."):r.reason;return e instanceof Error?e:Sb(e)};function hc(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((f,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:m}=e;m.aborted&&p(Ab(m)),a=()=>{p(Ab(m))},m.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(f,p);return}let y=new Fd;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){p(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?p(o):(y.message=o??`Promise timed out after ${t} milliseconds`,p(y))},t),(async()=>{try{f(await r)}catch(m){p(m)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var Eb=_b(),dc=Eb!=null&&Eb.name==="firefox",Kl=async function*(){},Hl=async r=>{};function Cb(r,e,t=db,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=Je(),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 hc(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Gd(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??sb.map(e=>({urls:[e]})),r}var Tb=(r=32)=>ab+[...Array(r)].map(()=>Hd.at(Math.floor(Math.random()*Hd.length))).join("");var Qo=class{log;peerConnection;remoteAddr;timeline;metrics;source=Kl();sink=Hl;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 Vl=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}},Ts=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Vl(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 Vl(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 qd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Is(r={}){return $2(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 $2(r,e){e=e??{};let t=e.onEnd,n=new Ts,o,i,s,a=Je(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,I)=>{i=D=>{i=null,n.push(D);try{d(r(n))}catch(j){I(j)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Je()})}},l=d=>i!=null?i(d):(n.push(d),o),f=d=>(n=new Ts,i!=null?i({error:d}):(n.push({error:d}),o)),p=d=>{if(s)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},y=d=>s?o:(s=!0,d!=null?f(d):l({done:!0})),m=()=>(n=new Ts,y(),{done:!0}),x=d=>(y(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:x,push:p,end:y,get readableLength(){return n.size},onEmpty:async d=>{let I=d?.signal;if(I?.throwIfAborted(),n.isEmpty())return;let D,j;I!=null&&(D=new Promise((Z,P)=>{j=()=>{P(new qd)},I.addEventListener("abort",j)}));try{await Promise.race([a.promise,D])}finally{j!=null&&I!=null&&I?.removeEventListener("abort",j)}}},t==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(d){return v.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return v.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(d){return v.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return v.readableLength},onEmpty:d=>v.onEmpty(d)},o}var $l=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 cr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new $l(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new $l(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 Ib(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 Ob(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Pb(r,e){let t=Ib(r).return?.();Ob(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var F2=5e3;function zd(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Fl=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=Je(),this.closed=Je(),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??F2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=Is({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 Bo(`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);zd(o)&&await o}let n=()=>{Pb(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 be(o):o;let i=this.sendData(o,t);zd(i)&&(this.sendingData=Je(),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 cr(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 cr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await cr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await cr(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();zd(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 Wu("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 Xd(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 Wl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Os=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Gl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},yc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ql(r){return r[Symbol.asyncIterator]!=null}function Bb(r,e){if(r.byteLength>e)throw new Os("Message length too long")}var Xl=r=>{let e=Ve(r),t=it(e);return ml(r,t),Xl.bytes=e,t};Xl.bytes=0;function mc(r,e){e=e??{};let t=e.lengthEncoder??Xl,n=e?.maxDataLength??4194304;function*o(i){Bb(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return ql(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}mc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Xl,n=e?.maxDataLength??4194304;return Bb(r,n),new be(t(r.byteLength),r)};var ei;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ei||(ei={}));var Zd=r=>{let e=Wo(r);return Zd.bytes=Ve(e),e};Zd.bytes=0;function ti(r,e){let t=new be,n=ei.LENGTH,o=-1,i=e?.lengthDecoder??Zd,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===ei.LENGTH)try{if(o=i(t),o<0)throw new Wl("Invalid message length");if(o>a)throw new Os("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=ei.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new Gl("Message length length too long");break}throw l}if(n===ei.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=ei.LENGTH}}}return ql(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new yc("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new yc("Unexpected end of input")}()}ti.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 ti(n,{...e??{},onLength:i=>{t=i}})};var Yd=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 gc(r,e,t,n){let o=new Yd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",f),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(y){a(),s(y);return}a(),i(p)},l=p=>{a(),s(p.detail)},f=()=>{a(),s(o)};t?.addEventListener("abort",f),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var Jd=class extends Fl{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 hc(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=Is(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??lb,this.maxBufferedAmount=e.maxBufferedAmount??ub,this.maxMessageSize=(e.maxMessageSize??Cs)-fb,this.receiveFinAck=Je(),this.finAckTimeout=e.closeTimeout??pb,this.openTimeout=e.openTimeout??hb,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 Bo("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 ti(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new be(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 Bo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Xd([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 gc(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=Xd([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await gc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Xu(`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=Ot.encode({message:o}),s=mc.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(Ot.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(Ot.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await cr(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(Ot.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=Ot.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===Ot.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(Ot.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===Ot.Flag.RESET&&this.reset(),t.flag===Ot.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===Ot.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=Ot.encode({flag:e}),n=mc.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 Ps(r){let{channel:e,direction:t,handshake:n}=r;return new Jd({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`)})}var no=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??Vd,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=Ps({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},log:this.log,...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 Qd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Qd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=t.log?.newScope("muxer")??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??Vd,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=Ps({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},log:this.log,...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),Cb(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=Kl();sink=Hl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=Ps({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},log:this.log,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Zl=globalThis.RTCPeerConnection,Yl=globalThis.RTCSessionDescription,Nb=globalThis.RTCIceCandidate;var ey=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Je(),this.haveNext=Je()}[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=Je(),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=Je(),await cr(this.readNext.promise,t?.signal,t)}};function Jl(){return new ey}var Ql=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function kb(r,e){let t=Jl();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 be;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:l}=await cr(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await cr(n.next(),s?.signal);if(l===!0)throw new Ql("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 ef=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},tf=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},rf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function wc(r,e={}){let t=kb(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ve(e.maxDataLength));let n=e?.lengthDecoder??Wo,o=e?.lengthEncoder??ml;return{read:async s=>{let a=-1,c=new be;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new ef("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new rf("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new tf("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new be(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new be(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function nf(r,e){let t=wc(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 tr=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var oo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ur=class extends oo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var of=class extends oo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var sf=class extends oo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},af=class extends oo{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 Kt;(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=()=>zo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Br((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 l=o.uint32();switch(l>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Pr(o,r.codec()),r.decode=(o,i)=>Or(o,r.codec(),i)})(Kt||(Kt={}));var cf=async(r,e,t)=>{try{let n=Je();for(q2(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!==Kt.Type.ICE_CANDIDATE)throw new zu("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new tr("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Nb(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new tr("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&&uf(r)!=="connected")throw n}};function uf(r){return dc?r.iceConnectionState:r.connectionState}function q2(r,e){r[dc?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(uf(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Fu("RTCPeerConnection was closed"));break;default:break}}}async function Db({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{circuitAddress:f,targetPeer:p}=jb(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",f);let y=i.getConnections(p),m;y.length===0?(l?.(new tr("webrtc:dial-relay")),m=await s.dial(f,{signal:t,onProgress:l})):(l?.(new tr("webrtc:reuse-relay-connection")),m=y[0]),l?.(new tr("webrtc:open-signaling-stream"));let x=await m.newStream(pc,{signal:t,runOnLimitedConnection:!0}),v=nf(x).pb(Kt),d=new Zl(r),I=new no({logger:c},{peerConnection:d,dataChannelOptions:e});try{let D=d.createDataChannel("init");d.onicecandidate=({candidate:M})=>{let $=JSON.stringify(M?.toJSON()??null);a.trace("initiator sending ICE candidate %o",M),v.write({type:Kt.Type.ICE_CANDIDATE,data:$},{signal:t}).catch(K=>{a.error("error sending ICE candidate",K)})},d.onicecandidateerror=M=>{a.error("initiator ICE candidate error",M)};let j=await d.createOffer().catch(M=>{throw a.error("could not execute createOffer",M),new ur("Failed to set createOffer")});a.trace("initiator send SDP offer %s",j.sdp),l?.(new tr("webrtc:send-sdp-offer")),await v.write({type:Kt.Type.SDP_OFFER,data:j.sdp},{signal:t}),await d.setLocalDescription(j).catch(M=>{throw a.error("could not execute setLocalDescription",M),new ur("Failed to set localDescription")}),l?.(new tr("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let Z=await v.read({signal:t});if(Z.type!==Kt.Type.SDP_ANSWER)throw new ur("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",Z.data);let P=new Yl({type:"answer",sdp:Z.data});return await d.setRemoteDescription(P).catch(M=>{throw a.error("could not execute setRemoteDescription",M),new ur("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new tr("webrtc:read-ice-candidates")),await cf(d,v,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),D.close(),l?.(new tr("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await x.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:d,muxerFactory:I}}catch(D){throw a.error("outgoing signaling error",D),d.close(),x.abort(D),D}finally{d.onicecandidate=null,d.onicecandidateerror=null}}var Rb=ke(ob.matchers[0],Re(290)),lf=class r extends Wn{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=>Rb.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=>Rb.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 Lb({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=nf(e).pb(Kt);try{r.onicecandidate=({candidate:f})=>{let p=JSON.stringify(f?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Kt.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!==Kt.Type.SDP_OFFER)throw new ur(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Yl({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(f=>{throw o.error("could not execute setRemoteDescription",f),new ur("Failed to set remoteDescription")});let l=await r.createAnswer().catch(f=>{throw o.error("could not execute createAnswer",f),new ur("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:Kt.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(f=>{throw o.error("could not execute setLocalDescription",f),new ur("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await cf(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(uf(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=xn(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var ff=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"})})}[Hu]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[es]=["@libp2p/transport"];[Tg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(pc,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(pc),this._started=!1}createListener(e){return new lf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(ib.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 Db({rtcConfiguration:await Gd(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 Qo(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 Zl(await Gd(this.init.rtcConfiguration)),i=new no(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await Lb({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Qo(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 jb(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new Ie("Destination peer id was missing");return{circuitAddress:xn(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:Cl(e)}}var kz=$r(Mb());var en={};St(en,{Any:()=>Jr,BaseBlock:()=>Qe,BaseStringBlock:()=>_c,BitString:()=>jr,BmpString:()=>si,Boolean:()=>ni,CharacterString:()=>yi,Choice:()=>ks,Constructed:()=>st,DATE:()=>Ic,DateTime:()=>Pc,Duration:()=>Bc,EndOfContent:()=>Sc,Enumerated:()=>oi,GeneralString:()=>di,GeneralizedTime:()=>mi,GraphicString:()=>hi,HexBlock:()=>Qr,IA5String:()=>pi,Integer:()=>En,Null:()=>kr,NumericString:()=>ci,ObjectIdentifier:()=>ii,OctetString:()=>Dr,Primitive:()=>An,PrintableString:()=>ui,RawData:()=>oy,RelativeObjectIdentifier:()=>Tc,Repeated:()=>gi,Sequence:()=>$t,Set:()=>Ft,TIME:()=>Nc,TeletexString:()=>li,TimeOfDay:()=>Oc,UTCTime:()=>co,UniversalString:()=>ai,Utf8String:()=>fr,ValueBlock:()=>ht,VideotexString:()=>fi,ViewWriter:()=>Ns,VisibleString:()=>ao,compareSchema:()=>so,fromBER:()=>Tn,verifySchema:()=>dC});var ye=$r(_n());function ri(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 io(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 l=new Uint8Array(c);for(let f=a-1;f>=0;f--){let p=Math.pow(2,f*e);l[i-f-1]=Math.floor(o/p),o-=l[i-f-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function df(...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 ry(){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=ri(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,ri(i,8)-n}function Kb(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=io(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=io(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 Hb(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 Ht(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 Rk=Math.log(2);function yf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function iy(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 Cn(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 Ns=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return iy(this.items)}},bc=[new Uint8Array([1])],Vb="0123456789",ny="name",$b="valueHexView",rC="isHexOnly",nC="idBlock",oC="tagClass",iC="tagNumber",sC="isConstructed",aC="fromBER",cC="toBER",uC="local",Vt="",Rr=new ArrayBuffer(0),Pf=new Uint8Array(0),vc="EndOfContent",Wb="OCTET STRING",Gb="BIT STRING";function Qr(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?ye.BufferSourceConverter.toUint8Array(i.valueHex):Pf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Cn(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",Rr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ye.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Sn=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=Vt,warnings:n=[],valueBeforeDecode:o=Pf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ye.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ye.Convert.ToHex(this.valueBeforeDecodeView)}}};Sn.NAME="baseBlock";var ht=class extends Sn{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'")}};ht.NAME="valueBlock";var mf=class extends Qr(Sn){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?ye.BufferSourceConverter.toUint8Array(e.valueHex):Pf,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",Rr}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=io(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=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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,l=this.valueHexView=new Uint8Array(255),f=255;for(;i[c]&128;){if(l[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;let y=new Uint8Array(f);for(let m=0;m<l.length;m++)y[m]=l[m];l=this.valueHexView=new Uint8Array(f)}}this.blockLength=c+1,l[c-1]=i[c]&127;let p=new Uint8Array(c);for(let y=0;y<c;y++)p[y]=l[y];l=this.valueHexView=new Uint8Array(c),l.set(p),this.blockLength<=9?this.tagNumber=ri(l,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}}};mf.NAME="identificationBlock";var gf=class extends Sn{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=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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=ri(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=io(this.length,8);if(o.byteLength>127)return this.error="Too big length",Rr;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}}};gf.NAME="lengthBlock";var Q={},Qe=class extends Sn{constructor({name:e=Vt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new mf(o),this.lenBlock=new gf(o),this.valueBlock=i?new i(o):new ht(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 Ns;t||qb(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?Rr: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():ye.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ye.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 Hb(t,n)}};Qe.NAME="BaseBlock";function qb(r){var e;if(r instanceof Q.Constructed)for(let t of r.valueBlock.value)qb(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var _c=class extends Qe{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Vt,...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}'`}};_c.NAME="BaseStringBlock";var wf=class extends Qr(ht){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};wf.NAME="PrimitiveValueBlock";var zb,An=class extends Qe{constructor(e={}){super(e,wf),this.idBlock.isConstructed=!1}};zb=An;Q.Primitive=zb;An.NAME="PRIMITIVE";function lC(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 Ds(r,e=0,t=r.length){let n=e,o=new Qe({},ht),i=new Sn;if(!Cn(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=Qe;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=Q.EndOfContent;break;case 1:c=Q.Boolean;break;case 2:c=Q.Integer;break;case 3:c=Q.BitString;break;case 4:c=Q.OctetString;break;case 5:c=Q.Null;break;case 6:c=Q.ObjectIdentifier;break;case 10:c=Q.Enumerated;break;case 12:c=Q.Utf8String;break;case 13:c=Q.RelativeObjectIdentifier;break;case 14:c=Q.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Q.Sequence;break;case 17:c=Q.Set;break;case 18:c=Q.NumericString;break;case 19:c=Q.PrintableString;break;case 20:c=Q.TeletexString;break;case 21:c=Q.VideotexString;break;case 22:c=Q.IA5String;break;case 23:c=Q.UTCTime;break;case 24:c=Q.GeneralizedTime;break;case 25:c=Q.GraphicString;break;case 26:c=Q.VisibleString;break;case 27:c=Q.GeneralString;break;case 28:c=Q.UniversalString;break;case 29:c=Q.CharacterString;break;case 30:c=Q.BmpString;break;case 31:c=Q.DATE;break;case 32:c=Q.TimeOfDay;break;case 33:c=Q.DateTime;break;case 34:c=Q.Duration;break;default:{let l=o.idBlock.isConstructed?new Q.Constructed:new Q.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Q.Constructed:Q.Primitive}return o=lC(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 Tn(r){if(!r.byteLength){let e=new Qe({},ht);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ds(ye.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function fC(r,e){return r?1:e}var Yr=class extends ht{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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(;fC(this.isIndefiniteForm,n)>0;){let s=Ds(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===vc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===vc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Ns;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Rr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Yr.NAME="ConstructedValueBlock";var Xb,st=class extends Qe{constructor(e={}){super(e,Yr),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 gS=Object.create;var Yu=Object.defineProperty;var bS=Object.getOwnPropertyDescriptor;var wS=Object.getOwnPropertyNames;var xS=Object.getPrototypeOf,vS=Object.prototype.hasOwnProperty;var oh=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Tt=(r,e)=>{for(var t in e)Yu(r,t,{get:e[t],enumerable:!0})},Hg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of wS(e))!vS.call(r,o)&&o!==t&&Yu(r,o,{get:()=>e[o],enumerable:!(n=bS(e,o))||n.enumerable});return r};var Xr=(r,e,t)=>(t=r!=null?gS(xS(r)):{},Hg(e||!r||!r.__esModule?Yu(t,"default",{value:r,enumerable:!0}):t,r)),_S=r=>Hg(Yu({},"__esModule",{value:!0}),r);var ox=oh(()=>{var nx;(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(p,f){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:f}),u&&u(p,f)}}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,p={create:a?function(){return nh(Object.create(null))}:c?function(){return nh({__proto__:null})}:function(){return nh({})},has:u?function(x,S){return n.call(x,S)}:function(x,S){return S in x},get:u?function(x,S){return n.call(x,S)?x[S]:void 0}:function(x,S){return x[S]}},f=Object.getPrototypeOf(Function),d=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:pS(),m=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:hS(),g=typeof WeakMap=="function"?WeakMap:dS(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,y=uS(),T=lS(y);function j(x,S,N,W){if(D(N)){if(!zr(x))throw new TypeError;if(!Ar(S))throw new TypeError;return k(x,S)}else{if(!zr(x))throw new TypeError;if(!pe(S))throw new TypeError;if(!pe(W)&&!D(W)&&!fe(W))throw new TypeError;return fe(W)&&(W=void 0),N=ot(N),P(x,S,N,W)}}e("decorate",j);function L(x,S){function N(W,ae){if(!pe(W))throw new TypeError;if(!D(ae)&&!$o(ae))throw new TypeError;R(x,S,W,ae)}return N}e("metadata",L);function V(x,S,N,W){if(!pe(N))throw new TypeError;return D(W)||(W=ot(W)),R(x,S,N,W)}e("defineMetadata",V);function re(x,S,N){if(!pe(S))throw new TypeError;return D(N)||(N=ot(N)),M(x,S,N)}e("hasMetadata",re);function U(x,S,N){if(!pe(S))throw new TypeError;return D(N)||(N=ot(N)),H(x,S,N)}e("hasOwnMetadata",U);function Y(x,S,N){if(!pe(S))throw new TypeError;return D(N)||(N=ot(N)),I(x,S,N)}e("getMetadata",Y);function Q(x,S,N){if(!pe(S))throw new TypeError;return D(N)||(N=ot(N)),_(x,S,N)}e("getOwnMetadata",Q);function F(x,S){if(!pe(x))throw new TypeError;return D(S)||(S=ot(S)),B(x,S)}e("getMetadataKeys",F);function C(x,S){if(!pe(x))throw new TypeError;return D(S)||(S=ot(S)),G(x,S)}e("getOwnMetadataKeys",C);function E(x,S,N){if(!pe(S))throw new TypeError;if(D(N)||(N=ot(N)),!pe(S))throw new TypeError;D(N)||(N=ot(N));var W=La(S,N,!1);return D(W)?!1:W.OrdinaryDeleteMetadata(x,S,N)}e("deleteMetadata",E);function k(x,S){for(var N=x.length-1;N>=0;--N){var W=x[N],ae=W(S);if(!D(ae)&&!fe(ae)){if(!Ar(ae))throw new TypeError;S=ae}}return S}function P(x,S,N,W){for(var ae=x.length-1;ae>=0;--ae){var Je=x[ae],ct=Je(S,N,W);if(!D(ct)&&!fe(ct)){if(!pe(ct))throw new TypeError;W=ct}}return W}function M(x,S,N){var W=H(x,S,N);if(W)return!0;var ae=rh(S);return fe(ae)?!1:M(x,ae,N)}function H(x,S,N){var W=La(S,N,!1);return D(W)?!1:Re(W.OrdinaryHasOwnMetadata(x,S,N))}function I(x,S,N){var W=H(x,S,N);if(W)return _(x,S,N);var ae=rh(S);if(!fe(ae))return I(x,ae,N)}function _(x,S,N){var W=La(S,N,!1);if(!D(W))return W.OrdinaryGetOwnMetadata(x,S,N)}function R(x,S,N,W){var ae=La(N,W,!0);ae.OrdinaryDefineOwnMetadata(x,S,N,W)}function B(x,S){var N=G(x,S),W=rh(x);if(W===null)return N;var ae=B(W,S);if(ae.length<=0)return N;if(N.length<=0)return ae;for(var Je=new m,ct=[],we=0,Z=N;we<Z.length;we++){var ee=Z[we],ne=Je.has(ee);ne||(Je.add(ee),ct.push(ee))}for(var oe=0,xe=ae;oe<xe.length;oe++){var ee=xe[oe],ne=Je.has(ee);ne||(Je.add(ee),ct.push(ee))}return ct}function G(x,S){var N=La(x,S,!1);return N?N.OrdinaryOwnMetadataKeys(x,S):[]}function X(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 D(x){return x===void 0}function fe(x){return x===null}function me(x){return typeof x=="symbol"}function pe(x){return typeof x=="object"?x!==null:typeof x=="function"}function ye(x,S){switch(X(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 N=S===3?"string":S===5?"number":"default",W=jg(x,i);if(W!==void 0){var ae=W.call(x,N);if(pe(ae))throw new TypeError;return ae}return Ae(x,N==="default"?"number":N)}function Ae(x,S){if(S==="string"){var N=x.toString;if(yt(N)){var W=N.call(x);if(!pe(W))return W}var ae=x.valueOf;if(yt(ae)){var W=ae.call(x);if(!pe(W))return W}}else{var ae=x.valueOf;if(yt(ae)){var W=ae.call(x);if(!pe(W))return W}var Je=x.toString;if(yt(Je)){var W=Je.call(x);if(!pe(W))return W}}throw new TypeError}function Re(x){return!!x}function nt(x){return""+x}function ot(x){var S=ye(x,3);return me(S)?S:nt(S)}function zr(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function yt(x){return typeof x=="function"}function Ar(x){return typeof x=="function"}function $o(x){switch(X(x)){case 3:return!0;case 4:return!0;default:return!1}}function gn(x,S){return x===S||x!==x&&S!==S}function jg(x,S){var N=x[S];if(N!=null){if(!yt(N))throw new TypeError;return N}}function Rg(x){var S=jg(x,s);if(!yt(S))throw new TypeError;var N=S.call(x);if(!pe(N))throw new TypeError;return N}function Lg(x){return x.value}function Ug(x){var S=x.next();return S.done?!1:S}function Mg(x){var S=x.return;S&&S.call(x)}function rh(x){var S=Object.getPrototypeOf(x);if(typeof x!="function"||x===f||S!==f)return S;var N=x.prototype,W=N&&Object.getPrototypeOf(N);if(W==null||W===Object.prototype)return S;var ae=W.constructor;return typeof ae!="function"||ae===x?S:ae}function cS(){var x;!D(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=fS(t.Reflect));var S,N,W,ae=new g,Je={registerProvider:ct,getProvider:Z,setProvider:ne};return Je;function ct(oe){if(!Object.isExtensible(Je))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===oe:break;case D(S):S=oe;break;case S===oe:break;case D(N):N=oe;break;case N===oe:break;default:W===void 0&&(W=new m),W.add(oe);break}}function we(oe,xe){if(!D(S)){if(S.isProviderFor(oe,xe))return S;if(!D(N)){if(N.isProviderFor(oe,xe))return S;if(!D(W))for(var Me=Rg(W);;){var Qe=Ug(Me);if(!Qe)return;var Er=Lg(Qe);if(Er.isProviderFor(oe,xe))return Mg(Me),Er}}}if(!D(x)&&x.isProviderFor(oe,xe))return x}function Z(oe,xe){var Me=ae.get(oe),Qe;return D(Me)||(Qe=Me.get(xe)),D(Qe)&&(Qe=we(oe,xe),D(Qe)||(D(Me)&&(Me=new d,ae.set(oe,Me)),Me.set(xe,Qe))),Qe}function ee(oe){if(D(oe))throw new TypeError;return S===oe||N===oe||!D(W)&&W.has(oe)}function ne(oe,xe,Me){if(!ee(Me))throw new Error("Metadata provider not registered.");var Qe=Z(oe,xe);if(Qe!==Me){if(!D(Qe))return!1;var Er=ae.get(oe);D(Er)&&(Er=new d,ae.set(oe,Er)),Er.set(xe,Me)}return!0}}function uS(){var x;return!D(w)&&pe(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[w]),D(x)&&(x=cS()),!D(w)&&pe(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function lS(x){var S=new g,N={isProviderFor:function(ee,ne){var oe=S.get(ee);return D(oe)?!1:oe.has(ne)},OrdinaryDefineOwnMetadata:ct,OrdinaryHasOwnMetadata:ae,OrdinaryGetOwnMetadata:Je,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:Z};return y.registerProvider(N),N;function W(ee,ne,oe){var xe=S.get(ee),Me=!1;if(D(xe)){if(!oe)return;xe=new d,S.set(ee,xe),Me=!0}var Qe=xe.get(ne);if(D(Qe)){if(!oe)return;if(Qe=new d,xe.set(ne,Qe),!x.setProvider(ee,ne,N))throw xe.delete(ne),Me&&S.delete(ee),new Error("Wrong provider for target.")}return Qe}function ae(ee,ne,oe){var xe=W(ne,oe,!1);return D(xe)?!1:Re(xe.has(ee))}function Je(ee,ne,oe){var xe=W(ne,oe,!1);if(!D(xe))return xe.get(ee)}function ct(ee,ne,oe,xe){var Me=W(oe,xe,!0);Me.set(ee,ne)}function we(ee,ne){var oe=[],xe=W(ee,ne,!1);if(D(xe))return oe;for(var Me=xe.keys(),Qe=Rg(Me),Er=0;;){var Kg=Ug(Qe);if(!Kg)return oe.length=Er,oe;var yS=Lg(Kg);try{oe[Er]=yS}catch(mS){try{Mg(Qe)}finally{throw mS}}Er++}}function Z(ee,ne,oe){var xe=W(ne,oe,!1);if(D(xe)||!xe.delete(ee))return!1;if(xe.size===0){var Me=S.get(ne);D(Me)||(Me.delete(oe),Me.size===0&&S.delete(Me))}return!0}}function fS(x){var S=x.defineMetadata,N=x.hasOwnMetadata,W=x.getOwnMetadata,ae=x.getOwnMetadataKeys,Je=x.deleteMetadata,ct=new g,we={isProviderFor:function(Z,ee){var ne=ct.get(Z);return!D(ne)&&ne.has(ee)?!0:ae(Z,ee).length?(D(ne)&&(ne=new m,ct.set(Z,ne)),ne.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:N,OrdinaryGetOwnMetadata:W,OrdinaryOwnMetadataKeys:ae,OrdinaryDeleteMetadata:Je};return we}function La(x,S,N){var W=y.getProvider(x,S);if(!D(W))return W;if(N){if(y.setProvider(x,S,T))return T;throw new Error("Illegal state.")}}function pS(){var x={},S=[],N=function(){function we(Z,ee,ne){this._index=0,this._keys=Z,this._values=ee,this._selector=ne}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var Z=this._index;if(Z>=0&&Z<this._keys.length){var ee=this._selector(this._keys[Z],this._values[Z]);return Z+1>=this._keys.length?(this._index=-1,this._keys=S,this._values=S):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(Z){throw this._index>=0&&(this._index=-1,this._keys=S,this._values=S),Z},we.prototype.return=function(Z){return this._index>=0&&(this._index=-1,this._keys=S,this._values=S),{value:Z,done:!0}},we}(),W=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(Z){return this._find(Z,!1)>=0},we.prototype.get=function(Z){var ee=this._find(Z,!1);return ee>=0?this._values[ee]:void 0},we.prototype.set=function(Z,ee){var ne=this._find(Z,!0);return this._values[ne]=ee,this},we.prototype.delete=function(Z){var ee=this._find(Z,!1);if(ee>=0){for(var ne=this._keys.length,oe=ee+1;oe<ne;oe++)this._keys[oe-1]=this._keys[oe],this._values[oe-1]=this._values[oe];return this._keys.length--,this._values.length--,gn(Z,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 N(this._keys,this._values,ae)},we.prototype.values=function(){return new N(this._keys,this._values,Je)},we.prototype.entries=function(){return new N(this._keys,this._values,ct)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(Z,ee){if(!gn(this._cacheKey,Z)){this._cacheIndex=-1;for(var ne=0;ne<this._keys.length;ne++)if(gn(this._keys[ne],Z)){this._cacheIndex=ne;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(Z),this._values.push(void 0)),this._cacheIndex},we}();return W;function ae(we,Z){return we}function Je(we,Z){return Z}function ct(we,Z){return[we,Z]}}function hS(){var x=function(){function S(){this._map=new d}return Object.defineProperty(S.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),S.prototype.has=function(N){return this._map.has(N)},S.prototype.add=function(N){return this._map.set(N,N),this},S.prototype.delete=function(N){return this._map.delete(N)},S.prototype.clear=function(){this._map.clear()},S.prototype.keys=function(){return this._map.keys()},S.prototype.values=function(){return this._map.keys()},S.prototype.entries=function(){return this._map.entries()},S.prototype["@@iterator"]=function(){return this.keys()},S.prototype[s]=function(){return this.keys()},S}();return x}function dS(){var x=16,S=p.create(),N=W();return function(){function Z(){this._key=W()}return Z.prototype.has=function(ee){var ne=ae(ee,!1);return ne!==void 0?p.has(ne,this._key):!1},Z.prototype.get=function(ee){var ne=ae(ee,!1);return ne!==void 0?p.get(ne,this._key):void 0},Z.prototype.set=function(ee,ne){var oe=ae(ee,!0);return oe[this._key]=ne,this},Z.prototype.delete=function(ee){var ne=ae(ee,!1);return ne!==void 0?delete ne[this._key]:!1},Z.prototype.clear=function(){this._key=W()},Z}();function W(){var Z;do Z="@@WeakMap@@"+we();while(p.has(S,Z));return S[Z]=!0,Z}function ae(Z,ee){if(!n.call(Z,N)){if(!ee)return;Object.defineProperty(Z,N,{value:p.create()})}return Z[N]}function Je(Z,ee){for(var ne=0;ne<ee;++ne)Z[ne]=Math.random()*255|0;return Z}function ct(Z){if(typeof Uint8Array=="function"){var ee=new Uint8Array(Z);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):Je(ee,Z),ee}return Je(new Array(Z),Z)}function we(){var Z=ct(x);Z[6]=Z[6]&79|64,Z[8]=Z[8]&191|128;for(var ee="",ne=0;ne<x;++ne){var oe=Z[ne];(ne===4||ne===6||ne===8)&&(ee+="-"),oe<16&&(ee+="0"),ee+=oe.toString(16).toLowerCase()}return ee}}function nh(x){return x.__=void 0,delete x.__,x}})})(nx||(nx={}))});var kn=oh(zs=>{"use strict";var gC="[object ArrayBuffer]",Pn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===gC}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}},by="string",bC=/^[0-9a-f\s]+$/i,wC=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,xC=/^[a-zA-Z0-9-_]+$/,_f=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=Pn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},dr=class{static toString(e,t=!1){let n=Pn.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}},Sf=class r{static isHex(e){return typeof e===by&&bC.test(e)}static isBase64(e){return typeof e===by&&wC.test(e)}static isBase64Url(e){return typeof e===by&&xC.test(e)}static ToString(e,t="utf8"){let n=Pn.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 dr.toString(n,!0);case"utf16":case"utf16be":return dr.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 dr.fromString(e,!0);case"utf16":case"utf16be":return dr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pn.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 _f.fromString(e);case"utf16":case"utf16be":return dr.fromString(e);case"utf16le":case"usc2":return dr.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 _f.toString(e);case"utf16":case"utf16be":return dr.toString(e);case"utf16le":case"usc2":return dr.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=Pn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Pn.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 dr.toString(e,t)}static FromUtf16String(e,t=!1){return dr.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,"")||""}};Sf.DEFAULT_UTF8_ENCODING="utf8";function vC(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 _C(...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 SC(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}zs.BufferSourceConverter=Pn;zs.Convert=Sf;zs.assign=vC;zs.combine=_C;zs.isEqual=SC});var Jv=oh((j$,gp)=>{var kv,Nv,Dv,jv,Rv,Lv,Uv,Mv,Kv,mp,Cm,Hv,Vv,Sa,$v,Fv,Wv,qv,Gv,zv,Xv,Zv,Yv;(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 gp=="object"&&typeof gp.exports=="object"?r(t(e,t(gp.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])};kv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Nv=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},Dv=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},jv=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},Rv=function(t,n){return function(o,i){n(o,i,t)}},Lv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Uv=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(d){try{f(i.next(d))}catch(m){c(m)}}function p(d){try{f(i.throw(d))}catch(m){c(m)}}function f(d){d.done?a(d.value):s(d.value).then(u,p)}f((i=i.apply(t,n||[])).next())})},Mv=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(f){return function(d){return p([f,d])}}function p(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(d){f=[6,d],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},Yv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Kv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},mp=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.")},Cm=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},Hv=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Cm(arguments[n]));return t},Vv=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},Sa=function(t){return this instanceof Sa?(this.v=t,this):new Sa(t)},$v=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(g){i[g]&&(s[g]=function(w){return new Promise(function(y,T){a.push([g,w,y,T])>1||u(g,w)})})}function u(g,w){try{p(i[g](w))}catch(y){m(a[0][3],y)}}function p(g){g.value instanceof Sa?Promise.resolve(g.value.v).then(f,d):m(a[0][2],g)}function f(g){u("next",g)}function d(g){u("throw",g)}function m(g,w){g(w),a.shift(),a.length&&u(a[0][0],a[0][1])}},Fv=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:Sa(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Wv=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 mp=="function"?mp(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,p){c=t[a](c),s(u,p,c.done,c.value)})}}function s(a,c,u,p){Promise.resolve(p).then(function(f){a({value:f,done:u})},c)}},qv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Gv=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},zv=function(t){return t&&t.__esModule?t:{default:t}},Xv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Zv=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",kv),r("__assign",Nv),r("__rest",Dv),r("__decorate",jv),r("__param",Rv),r("__metadata",Lv),r("__awaiter",Uv),r("__generator",Mv),r("__exportStar",Kv),r("__createBinding",Yv),r("__values",mp),r("__read",Cm),r("__spread",Hv),r("__spreadArrays",Vv),r("__await",Sa),r("__asyncGenerator",$v),r("__asyncDelegator",Fv),r("__asyncValues",Wv),r("__makeTemplateObject",qv),r("__importStar",Gv),r("__importDefault",zv),r("__classPrivateFieldGet",Xv),r("__classPrivateFieldSet",Zv)})});var CI={};Tt(CI,{webRTC:()=>EI,webRTCDirect:()=>AI});var ih=Symbol.for("@libp2p/peer-id");var Ju=Symbol.for("@libp2p/transport");var Vg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Vg||(Vg={}));var Qu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},el=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ke=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ds=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ua=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var tl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var rl=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Fo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Wo=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var nl=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},ol=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var il=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var sl=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},al=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var to=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var ro=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 ys=Symbol.for("@libp2p/service-capabilities"),$g=Symbol.for("@libp2p/service-dependencies");var lh={};Tt(lh,{base58btc:()=>$e,base58flickr:()=>OS});var QI=new Uint8Array(0);function Fg(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 bn(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 Wg(r){return new TextEncoder().encode(r)}function qg(r){return new TextDecoder().decode(r)}function SS(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),p=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,y=0,T=0,j=g.length;T!==j&&g[T]===0;)T++,w++;for(var L=(j-T)*p+1>>>0,V=new Uint8Array(L);T!==j;){for(var re=g[T],U=0,Y=L-1;(re!==0||U<y)&&Y!==-1;Y--,U++)re+=256*V[Y]>>>0,V[Y]=re%a>>>0,re=re/a>>>0;if(re!==0)throw new Error("Non-zero carry");y=U,T++}for(var Q=L-y;Q!==L&&V[Q]===0;)Q++;for(var F=c.repeat(w);Q<L;++Q)F+=r.charAt(V[Q]);return F}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var y=0,T=0;g[w]===c;)y++,w++;for(var j=(g.length-w)*u+1>>>0,L=new Uint8Array(j);g[w];){var V=t[g.charCodeAt(w)];if(V===255)return;for(var re=0,U=j-1;(V!==0||re<T)&&U!==-1;U--,re++)V+=a*L[U]>>>0,L[U]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");T=re,w++}if(g[w]!==" "){for(var Y=j-T;Y!==j&&L[Y]===0;)Y++;for(var Q=new Uint8Array(y+(j-Y)),F=y;Y!==j;)Q[F++]=L[Y++];return Q}}}function m(g){var w=d(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:m}}var AS=SS,ES=AS,zg=ES;var sh=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")}},ah=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 Xg(this,e)}},ch=class{decoders;constructor(e){this.decoders=e}or(e){return Xg(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 Xg(r,e){return new ch({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var uh=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 sh(e,t,n),this.decoder=new ah(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ms({name:r,prefix:e,encode:t,decode:n}){return new uh(r,e,t,n)}function no({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=zg(t,r);return ms({prefix:e,name:r,encode:n,decode:i=>bn(o(i))})}function CS(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let p=e[r[u]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|p,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function TS(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 IS(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function qe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=IS(n);return ms({prefix:e,name:r,encode(i){return TS(i,n,t)},decode(i){return CS(i,o,t,r)}})}var $e=no({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),OS=no({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fh={};Tt(fh,{base32:()=>oo,base32hex:()=>NS,base32hexpad:()=>jS,base32hexpadupper:()=>RS,base32hexupper:()=>DS,base32pad:()=>PS,base32padupper:()=>kS,base32upper:()=>BS,base32z:()=>LS});var oo=qe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),BS=qe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),PS=qe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kS=qe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),NS=qe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),DS=qe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),jS=qe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),RS=qe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),LS=qe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ph={};Tt(ph,{base36:()=>Ma,base36upper:()=>US});var Ma=no({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),US=no({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cr={};Tt(Cr,{Digest:()=>qo,create:()=>It,decode:()=>ws,equals:()=>dh,hasCode:()=>nA});var MS=Jg,Zg=128,KS=127,HS=~KS,VS=Math.pow(2,31);function Jg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=VS;)e[t++]=r&255|Zg,r/=128;for(;r&HS;)e[t++]=r&255|Zg,r>>>=7;return e[t]=r|0,Jg.bytes=t-n+1,e}var $S=hh,FS=128,Yg=127;function hh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw hh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Yg)<<o:(s&Yg)*Math.pow(2,o),o+=7}while(s>=FS);return hh.bytes=i-n,t}var WS=Math.pow(2,7),qS=Math.pow(2,14),GS=Math.pow(2,21),zS=Math.pow(2,28),XS=Math.pow(2,35),ZS=Math.pow(2,42),YS=Math.pow(2,49),JS=Math.pow(2,56),QS=Math.pow(2,63),eA=function(r){return r<WS?1:r<qS?2:r<GS?3:r<zS?4:r<XS?5:r<ZS?6:r<YS?7:r<JS?8:r<QS?9:10},tA={encode:MS,decode:$S,encodingLength:eA},rA=tA,Ka=rA;function Ha(r,e=0){return[Ka.decode(r,e),Ka.decode.bytes]}function gs(r,e,t=0){return Ka.encode(r,e,t),e}function bs(r){return Ka.encodingLength(r)}function It(r,e){let t=e.byteLength,n=bs(r),o=n+bs(t),i=new Uint8Array(o+t);return gs(r,i,0),gs(t,i,n),i.set(e,o),new qo(r,t,e,i)}function ws(r){let e=bn(r),[t,n]=Ha(e),[o,i]=Ha(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new qo(t,o,s,e)}function dh(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Fg(r.bytes,t.bytes)}}var qo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function nA(r,e){return r.code===e}function Qg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return iA(t,yh(r),e??$e.encoder);default:return sA(t,yh(r),e??oo.encoder)}}var e0=new WeakMap;function yh(r){let e=e0.get(r);if(e==null){let t=new Map;return e0.set(r,t),t}return e}var et=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!==Va)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==aA)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=It(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&&dh(e.multihash,n.multihash)}toString(e){return Qg(this,e)}toJSON(){return{"/":Qg(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??t0(n,o,i.bytes))}else if(t[cA]===!0){let{version:n,multihash:o,code:i}=t,s=ws(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!==Va)throw new Error(`Version 0 CID must use dag-pb (code: ${Va}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=t0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Va,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=bn(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 qo(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[f,d]=Ha(e.subarray(t));return t+=d,f},o=n(),i=Va;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,p=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:u}}static parse(e,t){let[n,o]=oA(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 yh(i).set(n,e),i}};function oA(r,e){switch(r[0]){case"Q":{let t=e??$e;return[$e.prefix,t.decode(`${$e.prefix}${r}`)]}case $e.prefix:{let t=e??$e;return[$e.prefix,t.decode(r)]}case oo.prefix:{let t=e??oo;return[oo.prefix,t.decode(r)]}case Ma.prefix:{let t=e??Ma;return[Ma.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 iA(r,e,t){let{prefix:n}=t;if(n!==$e.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 sA(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 Va=112,aA=18;function t0(r,e,t){let n=bs(r),o=n+bs(e),i=new Uint8Array(o+t.byteLength);return gs(r,i,0),gs(e,i,n),i.set(t,o),i}var cA=Symbol.for("@ipld/js-cid/CID");var mh={};Tt(mh,{identity:()=>Tr});var r0=0,uA="identity",n0=bn;function lA(r){return It(r0,n0(r))}var Tr={code:r0,name:uA,encode:n0,digest:lA};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 ut(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function Rt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=lt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var i0=Symbol.for("@achingbrain/uint8arraylist");function o0(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 ul(r){return!!r?.[i0]}var ve=class r{bufs;length;[i0]=!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(ul(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(ul(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=o0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=o0(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(ul(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 Rt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Rt(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,p=t>a&&t<=c;if(u&&p){if(e===a&&t===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(p){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(!ul(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 f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,p;for(let f=t;f<=c;f+=p){p=0;for(let d=u;d>=0;d--){let m=this.get(f+d);if(n[d]!==m){p=Math.max(1,d-a[m]);break}}if(p===0)return f}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=lt(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=ut(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=ut(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=ut(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=lt(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=ut(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=ut(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=ut(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=ut(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=ut(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 gh={};Tt(gh,{base10:()=>pA});var pA=no({prefix:"9",name:"base10",alphabet:"0123456789"});var bh={};Tt(bh,{base16:()=>hA,base16upper:()=>dA});var hA=qe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dA=qe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wh={};Tt(wh,{base2:()=>yA});var yA=qe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xh={};Tt(xh,{base256emoji:()=>xA});var s0=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}"),mA=s0.reduce((r,e,t)=>(r[t]=e,r),[]),gA=s0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function bA(r){return r.reduce((e,t)=>(e+=mA[t],e),"")}function wA(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=gA[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var xA=ms({prefix:"\u{1F680}",name:"base256emoji",encode:bA,decode:wA});var vh={};Tt(vh,{base64:()=>vA,base64pad:()=>_A,base64url:()=>Go,base64urlpad:()=>SA});var vA=qe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_A=qe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Go=qe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),SA=qe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _h={};Tt(_h,{base8:()=>AA});var AA=qe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Sh={};Tt(Sh,{identity:()=>EA});var EA=ms({prefix:"\0",name:"identity",encode:r=>qg(r),decode:r=>Wg(r)});var jO=new TextEncoder,RO=new TextDecoder;var Ch={};Tt(Ch,{sha256:()=>ur,sha512:()=>IA});function Eh({name:r,code:e,encode:t}){return new Ah(r,e,t)}var Ah=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?It(this.code,t):t.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function c0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ur=Eh({name:"sha2-256",code:18,encode:c0("SHA-256")}),IA=Eh({name:"sha2-512",code:19,encode:c0("SHA-512")});var zo={...Sh,...wh,..._h,...gh,...bh,...fh,...ph,...lh,...vh,...xh},zO={...Ch,...mh};function l0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var u0=l0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Th=l0("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=lt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),OA={utf8:u0,"utf-8":u0,hex:zo.base16,latin1:Th,ascii:Th,binary:Th,...zo},ll=OA;function de(r,e="utf8"){let t=ll[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=ll[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var BA=parseInt("11111",2),Ih=parseInt("10000000",2),PA=parseInt("01111111",2),f0={0:$a,1:$a,2:kA,3:jA,4:RA,5:DA,6:NA,16:$a,22:$a,48:$a};function wn(r,e={offset:0}){let t=r[e.offset]&BA;if(e.offset++,f0[t]!=null)return f0[t](r,e);throw new Error("No decoder for tag "+t)}function Fa(r,e){let t=0;if((r[e.offset]&Ih)===Ih){let n=r[e.offset]&PA,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 $a(r,e){Fa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=wn(r,e);if(n===null)break;t.push(n)}return t}function kA(r,e){let t=Fa(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 NA(r,e){let t=Fa(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 p=0;for(let f=0;f<c.length;f++)p+=c[f]<<f*7;a+=`.${p}`,c=[]}}return a}function DA(r,e){return e.offset++,null}function jA(r,e){let t=Fa(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 RA(r,e){let t=Fa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function LA(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new ve;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function fl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=LA(r.byteLength);return new ve(Uint8Array.from([e.byteLength|Ih]),e)}function Lt(r){let e=new ve,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new ve(Uint8Array.from([2]),fl(e),e)}function Wa(r){let e=Uint8Array.from([0]),t=new ve(e,r);return new ve(Uint8Array.from([3]),fl(t),t)}function p0(r){return new ve(Uint8Array.from([4]),fl(r),r)}function Ir(r,e=48){let t=new ve;for(let n of r)t.append(n);return new ve(Uint8Array.from([e]),fl(t),t)}async function h0(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 d0(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function y0(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,t.subarray());return n?.signal?.throwIfAborted(),i}var UA=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),MA=Uint8Array.from([6,5,43,129,4,0,34]),KA=Uint8Array.from([6,5,43,129,4,0,35]),HA={ext:!0,kty:"EC",crv:"P-256"},VA={ext:!0,kty:"EC",crv:"P-384"},$A={ext:!0,kty:"EC",crv:"P-521"},Oh=32,Bh=48,Ph=66;function kh(r){let e=wn(r);return m0(e)}function m0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Oh*2+1)return n=ue(e.subarray(t,t+Oh),"base64url"),o=ue(e.subarray(t+Oh),"base64url"),new Xo({...HA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Bh*2+1)return n=ue(e.subarray(t,t+Bh),"base64url"),o=ue(e.subarray(t+Bh),"base64url"),new Xo({...VA,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ph*2+1)return n=ue(e.subarray(t,t+Ph),"base64url"),o=ue(e.subarray(t+Ph),"base64url"),new Xo({...$A,key_ops:["verify"],x:n,y:o});throw new ke(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function g0(r){return Ir([Lt(Uint8Array.from([1])),p0(de(r.d??"","base64url")),Ir([w0(r.crv)],160),Ir([Wa(new ve(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function b0(r){return Ir([Lt(Uint8Array.from([1])),Ir([w0(r.crv)],160),Ir([Wa(new ve(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function w0(r){if(r==="P-256")return UA;if(r==="P-384")return MA;if(r==="P-521")return KA;throw new ke(`Invalid curve ${r}`)}async function x0(r="P-256"){let e=await h0(r);return new pl(e.privateKey)}var Xo=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=b0(this.jwk)),this._raw}toMultihash(){return Tr.digest(io(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $e.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,n){return y0(this.jwk,t,e,n)}},pl=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Xo({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=g0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}async sign(e,t){return d0(this.jwk,e,t)}};var Zo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Jo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Yo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ze(r,...e){if(!Jo(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 Qo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Yo(r.outputLen),Yo(r.blockLen)}function vs(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 _0(r,e){ze(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Or(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function hl(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Br(r,e){return r<<32-e|r>>>e}var S0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",FA=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function lr(r){if(ze(r),S0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=FA[r[t]];return e}var xn={_0:48,_9:57,A:65,F:70,a:97,f:102};function v0(r){if(r>=xn._0&&r<=xn._9)return r-xn._0;if(r>=xn.A&&r<=xn.F)return r-(xn.A-10);if(r>=xn.a&&r<=xn.f)return r-(xn.a-10)}function ei(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(S0)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=v0(r.charCodeAt(i)),a=v0(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 Nh(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function so(r){return typeof r=="string"&&(r=Nh(r)),ze(r),r}function $t(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ze(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 xs=class{};function Dh(r){let e=n=>r().update(so(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ti(r=32){if(Zo&&typeof Zo.getRandomValues=="function")return Zo.getRandomValues(new Uint8Array(r));if(Zo&&typeof Zo.randomBytes=="function")return Uint8Array.from(Zo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function WA(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 A0(r,e,t){return r&e^~r&t}function E0(r,e,t){return r&e^r&t^e&t}var qa=class extends xs{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=hl(this.buffer)}update(e){vs(this),e=so(e),ze(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=hl(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){vs(this),_0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Or(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;WA(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=hl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,p=this.get();if(u>p.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,p[f],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.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},vn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var dl=BigInt(4294967295),C0=BigInt(32);function qA(r,e=!1){return e?{h:Number(r&dl),l:Number(r>>C0&dl)}:{h:Number(r>>C0&dl)|0,l:Number(r&dl)|0}}function T0(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let i=0;i<t;i++){let{h:s,l:a}=qA(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var jh=(r,e,t)=>r>>>t,Rh=(r,e,t)=>r<<32-t|e>>>t,ri=(r,e,t)=>r>>>t|e<<32-t,ni=(r,e,t)=>r<<32-t|e>>>t,Ga=(r,e,t)=>r<<64-t|e>>>t-32,za=(r,e,t)=>r>>>t-32|e<<64-t;function Zr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var I0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),O0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,B0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),P0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,k0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),N0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var zA=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ao=new Uint32Array(64),yl=class extends qa{constructor(e=32){super(64,e,8,!1),this.A=vn[0]|0,this.B=vn[1]|0,this.C=vn[2]|0,this.D=vn[3]|0,this.E=vn[4]|0,this.F=vn[5]|0,this.G=vn[6]|0,this.H=vn[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 f=0;f<16;f++,t+=4)ao[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let d=ao[f-15],m=ao[f-2],g=Br(d,7)^Br(d,18)^d>>>3,w=Br(m,17)^Br(m,19)^m>>>10;ao[f]=w+ao[f-7]+g+ao[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:p}=this;for(let f=0;f<64;f++){let d=Br(a,6)^Br(a,11)^Br(a,25),m=p+d+A0(a,c,u)+zA[f]+ao[f]|0,w=(Br(n,2)^Br(n,13)^Br(n,22))+E0(n,o,i)|0;p=u,u=c,c=a,a=s+m|0,s=i,i=o,o=n,n=m+w|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,p=p+this.H|0,this.set(n,o,i,s,a,c,u,p)}roundClean(){Or(ao)}destroy(){this.set(0,0,0,0,0,0,0,0),Or(this.buffer)}};var D0=T0(["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))),XA=D0[0],ZA=D0[1],co=new Uint32Array(80),uo=new Uint32Array(80),Lh=class extends qa{constructor(e=64){super(128,e,16,!1),this.Ah=mt[0]|0,this.Al=mt[1]|0,this.Bh=mt[2]|0,this.Bl=mt[3]|0,this.Ch=mt[4]|0,this.Cl=mt[5]|0,this.Dh=mt[6]|0,this.Dl=mt[7]|0,this.Eh=mt[8]|0,this.El=mt[9]|0,this.Fh=mt[10]|0,this.Fl=mt[11]|0,this.Gh=mt[12]|0,this.Gl=mt[13]|0,this.Hh=mt[14]|0,this.Hl=mt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:p,Fh:f,Fl:d,Gh:m,Gl:g,Hh:w,Hl:y}=this;return[e,t,n,o,i,s,a,c,u,p,f,d,m,g,w,y]}set(e,t,n,o,i,s,a,c,u,p,f,d,m,g,w,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=p|0,this.Fh=f|0,this.Fl=d|0,this.Gh=m|0,this.Gl=g|0,this.Hh=w|0,this.Hl=y|0}process(e,t){for(let L=0;L<16;L++,t+=4)co[L]=e.getUint32(t),uo[L]=e.getUint32(t+=4);for(let L=16;L<80;L++){let V=co[L-15]|0,re=uo[L-15]|0,U=ri(V,re,1)^ri(V,re,8)^jh(V,re,7),Y=ni(V,re,1)^ni(V,re,8)^Rh(V,re,7),Q=co[L-2]|0,F=uo[L-2]|0,C=ri(Q,F,19)^Ga(Q,F,61)^jh(Q,F,6),E=ni(Q,F,19)^za(Q,F,61)^Rh(Q,F,6),k=B0(Y,E,uo[L-7],uo[L-16]),P=P0(k,U,C,co[L-7],co[L-16]);co[L]=P|0,uo[L]=k|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:p,Eh:f,El:d,Fh:m,Fl:g,Gh:w,Gl:y,Hh:T,Hl:j}=this;for(let L=0;L<80;L++){let V=ri(f,d,14)^ri(f,d,18)^Ga(f,d,41),re=ni(f,d,14)^ni(f,d,18)^za(f,d,41),U=f&m^~f&w,Y=d&g^~d&y,Q=k0(j,re,Y,ZA[L],uo[L]),F=N0(Q,T,V,U,XA[L],co[L]),C=Q|0,E=ri(n,o,28)^Ga(n,o,34)^Ga(n,o,39),k=ni(n,o,28)^za(n,o,34)^za(n,o,39),P=n&i^n&a^i&a,M=o&s^o&c^s&c;T=w|0,j=y|0,w=m|0,y=g|0,m=f|0,g=d|0,{h:f,l:d}=Zr(u|0,p|0,F|0,C|0),u=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let H=I0(C,k,M);n=O0(H,F,E,P),o=H|0}({h:n,l:o}=Zr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Zr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Zr(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:p}=Zr(this.Dh|0,this.Dl|0,u|0,p|0),{h:f,l:d}=Zr(this.Eh|0,this.El|0,f|0,d|0),{h:m,l:g}=Zr(this.Fh|0,this.Fl|0,m|0,g|0),{h:w,l:y}=Zr(this.Gh|0,this.Gl|0,w|0,y|0),{h:T,l:j}=Zr(this.Hh|0,this.Hl|0,T|0,j|0),this.set(n,o,i,s,a,c,u,p,f,d,m,g,w,y,T,j)}roundClean(){Or(co,uo)}destroy(){Or(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ml=Dh(()=>new yl);var j0=Dh(()=>new Lh);var Kh=BigInt(0),Mh=BigInt(1);function _n(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Xa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function R0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Kh:BigInt("0x"+r)}function _s(r){return R0(lr(r))}function fr(r){return ze(r),R0(lr(Uint8Array.from(r).reverse()))}function gl(r,e){return ei(r.toString(16).padStart(e*2,"0"))}function Pr(r,e){return gl(r,e).reverse()}function Te(r,e,t){let n;if(typeof e=="string")try{n=ei(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Jo(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 L0(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 Uh=r=>typeof r=="bigint"&&Kh<=r;function U0(r,e,t){return Uh(r)&&Uh(e)&&Uh(t)&&e<=r&&r<t}function kr(r,e,t,n){if(!U0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function bl(r){let e;for(e=0;r>Kh;r>>=Mh,e+=1);return e}var lo=r=>(Mh<<BigInt(r))-Mh;function M0(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=m=>new Uint8Array(m),o=m=>Uint8Array.of(m),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},u=(...m)=>t(s,i,...m),p=(m=n(0))=>{s=u(o(0),m),i=u(),m.length!==0&&(s=u(o(1),m),i=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let m=0,g=[];for(;m<e;){i=u();let w=i.slice();g.push(w),m+=i.length}return $t(...g)};return(m,g)=>{c(),p(m);let w;for(;!(w=g(f()));)p();return c(),w}}function Yr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}function Ss(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 Ut=BigInt(0),ht=BigInt(1),oi=BigInt(2),V0=BigInt(3),$0=BigInt(4),F0=BigInt(5),YA=BigInt(7),W0=BigInt(8),JA=BigInt(9),q0=BigInt(16);function Ke(r,e){let t=r%e;return t>=Ut?t:e+t}function He(r,e,t){let n=r;for(;e-- >Ut;)n*=n,n%=t;return n}function K0(r,e){if(r===Ut)throw new Error("invert: expected non-zero number");if(e<=Ut)throw new Error("invert: expected positive modulus, got "+e);let t=Ke(r,e),n=e,o=Ut,i=ht,s=ht,a=Ut;for(;t!==Ut;){let u=n/t,p=n%t,f=o-s*u,d=i-a*u;n=t,t=p,o=s,i=a,s=f,a=d}if(n!==ht)throw new Error("invert: does not exist");return Ke(o,e)}function Hh(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function G0(r,e){let t=(r.ORDER+ht)/$0,n=r.pow(e,t);return Hh(r,n,e),n}function QA(r,e){let t=(r.ORDER-F0)/W0,n=r.mul(e,oi),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,oi),o),a=r.mul(i,r.sub(s,r.ONE));return Hh(r,a,e),a}function eE(r){let e=tr(r),t=z0(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+YA)/q0;return(a,c)=>{let u=a.pow(c,s),p=a.mul(u,n),f=a.mul(u,o),d=a.mul(u,i),m=a.eql(a.sqr(p),c),g=a.eql(a.sqr(f),c);u=a.cmov(u,p,m),p=a.cmov(d,f,g);let w=a.eql(a.sqr(p),c),y=a.cmov(u,p,w);return Hh(a,y,c),y}}function z0(r){if(r<V0)throw new Error("sqrt is not defined for small field");let e=r-ht,t=0;for(;e%oi===Ut;)e/=oi,t++;let n=oi,o=tr(r);for(;H0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return G0;let i=o.pow(n,e),s=(e+ht)/oi;return function(c,u){if(c.is0(u))return u;if(H0(c,u)!==1)throw new Error("Cannot find square root");let p=t,f=c.mul(c.ONE,i),d=c.pow(u,e),m=c.pow(u,s);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let g=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===p)throw new Error("Cannot find square root");let y=ht<<BigInt(p-g-1),T=c.pow(f,y);p=g,f=c.sqr(T),d=c.mul(d,f),m=c.mul(m,T)}return m}}function tE(r){return r%$0===V0?G0:r%W0===F0?QA:r%q0===JA?eE(r):z0(r)}var Sn=(r,e)=>(Ke(r,e)&ht)===ht,rE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Vh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=rE.reduce((n,o)=>(n[o]="function",n),e);return Yr(r,t),r}function nE(r,e,t){if(t<Ut)throw new Error("invalid exponent, negatives unsupported");if(t===Ut)return r.ONE;if(t===ht)return e;let n=r.ONE,o=e;for(;t>Ut;)t&ht&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ht;return n}function Za(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function H0(r,e){let t=(r.ORDER-ht)/oi,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function X0(r,e){e!==void 0&&Yo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function tr(r,e,t=!1,n={}){if(r<=Ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i,s=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let d=e;d.BITS&&(o=d.BITS),d.sqrt&&(i=d.sqrt),typeof d.isLE=="boolean"&&(t=d.isLE),typeof d.modOnDecode=="boolean"&&(s=d.modOnDecode),a=d.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=X0(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,f=Object.freeze({ORDER:r,isLE:t,BITS:c,BYTES:u,MASK:lo(c),ZERO:Ut,ONE:ht,allowedLengths:a,create:d=>Ke(d,r),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Ut<=d&&d<r},is0:d=>d===Ut,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&ht)===ht,neg:d=>Ke(-d,r),eql:(d,m)=>d===m,sqr:d=>Ke(d*d,r),add:(d,m)=>Ke(d+m,r),sub:(d,m)=>Ke(d-m,r),mul:(d,m)=>Ke(d*m,r),pow:(d,m)=>nE(f,d,m),div:(d,m)=>Ke(d*K0(m,r),r),sqrN:d=>d*d,addN:(d,m)=>d+m,subN:(d,m)=>d-m,mulN:(d,m)=>d*m,inv:d=>K0(d,r),sqrt:i||(d=>(p||(p=tE(r)),p(f,d))),toBytes:d=>t?Pr(d,u):gl(d,u),fromBytes:(d,m=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);let w=new Uint8Array(u);w.set(d,t?0:w.length-d.length),d=w}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let g=t?fr(d):_s(d);if(s&&(g=Ke(g,r)),!m&&!f.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:d=>Za(f,d),cmov:(d,m,g)=>g?m:d});return Object.freeze(f)}function Z0(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 $h(r){let e=Z0(r);return e+Math.ceil(e/2)}function Fh(r,e,t=!1){let n=r.length,o=Z0(e),i=$h(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?fr(r):_s(r),a=Ke(s,e-ht)+ht;return t?Pr(a,o):gl(a,o)}var As=BigInt(0),ii=BigInt(1);function Ya(r,e){let t=e.negate();return r?t:e}function An(r,e){let t=Za(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function eb(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Wh(r,e){eb(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=lo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Y0(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+=ii);let u=e*n,p=u+Math.abs(a)-1,f=a===0,d=a<0,m=e%2!==0;return{nextN:c,offset:p,isZero:f,isNeg:d,isNegF:m,offsetF:u}}function oE(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 qh=new WeakMap,tb=new WeakMap;function Gh(r){return tb.get(r)||1}function J0(r){if(r!==As)throw new Error("invalid wNAF")}var Es=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>As;)t&ii&&(n=n.add(o)),o=o.double(),t>>=ii;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=Wh(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Wh(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:p,isNeg:f,isNegF:d,offsetF:m}=Y0(n,a,s);n=c,p?i=i.add(Ya(d,t[m])):o=o.add(Ya(f,t[u]))}return J0(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=Wh(e,this.bits);for(let s=0;s<i.windows&&n!==As;s++){let{nextN:a,offset:c,isZero:u,isNeg:p}=Y0(n,s,i);if(n=a,!u){let f=t[c];o=o.add(p?f.negate():f)}}return J0(n),o}getPrecomputes(e,t,n){let o=qh.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),qh.set(t,o))),o}cached(e,t,n){let o=Gh(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=Gh(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){eb(t,this.bits),tb.set(e,t),qh.delete(e)}hasCache(e){return Gh(e)!==1}};function rb(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>As||n>As;)t&ii&&(i=i.add(o)),n&ii&&(s=s.add(o)),o=o.double(),t>>=ii,n>>=ii;return{p1:i,p2:s}}function Cs(r,e,t,n){oE(t,r),iE(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=bl(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=lo(c),p=new Array(Number(u)+1).fill(s),f=Math.floor((e.BITS-1)/c)*c,d=s;for(let m=f;m>=0;m-=c){p.fill(s);for(let w=0;w<i;w++){let y=n[w],T=Number(y>>BigInt(m)&u);p[T]=p[T].add(t[w])}let g=s;for(let w=p.length-1,y=s;w>0;w--)y=y.add(p[w]),g=g.add(y);if(d=d.add(g),m!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Q0(r,e){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Vh(e),e}else return tr(r)}function wl(r,e,t={}){if(!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=e[a];if(!(typeof c=="bigint"&&c>As))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Q0(e.p,t.Fp),o=Q0(e.n,t.Fn),s=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of s)if(!n.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Jr=BigInt(0),ft=BigInt(1),zh=BigInt(2),sE=BigInt(8);function aE(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function cE(r,e={}){let{Fp:t,Fn:n}=wl("edwards",r,e),{h:o,n:i}=r;Yr(e,{},{uvRatio:"function"});let s=zh<<BigInt(n.BYTES*8)-ft,a=w=>t.create(w),c=e.uvRatio||((w,y)=>{try{return{isValid:!0,value:t.sqrt(t.div(w,y))}}catch{return{isValid:!1,value:Jr}}});if(!aE(t,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function u(w,y,T=!1){let j=T?ft:Jr;return kr("coordinate "+w,y,j,s),y}function p(w){if(!(w instanceof m))throw new Error("ExtendedPoint expected")}let f=Ss((w,y)=>{let{X:T,Y:j,Z:L}=w,V=w.is0();y==null&&(y=V?sE:t.inv(L));let re=a(T*y),U=a(j*y),Y=t.mul(L,y);if(V)return{x:Jr,y:ft};if(Y!==ft)throw new Error("invZ was invalid");return{x:re,y:U}}),d=Ss(w=>{let{a:y,d:T}=r;if(w.is0())throw new Error("bad point: ZERO");let{X:j,Y:L,Z:V,T:re}=w,U=a(j*j),Y=a(L*L),Q=a(V*V),F=a(Q*Q),C=a(U*y),E=a(Q*a(C+Y)),k=a(F+a(T*a(U*Y)));if(E!==k)throw new Error("bad point: equation left != right (1)");let P=a(j*L),M=a(V*re);if(P!==M)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(y,T,j,L){this.X=u("x",y),this.Y=u("y",T),this.Z=u("z",j,!0),this.T=u("t",L),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return An(m,y)}static msm(y,T){return Cs(m,n,y,T)}_setWindowSize(y){this.precompute(y)}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:T,y:j}=y||{};return u("x",T),u("y",j),new m(T,j,ft,a(T*j))}precompute(y=8,T=!0){return g.createCache(this,y),T||this.multiply(zh),this}assertValidity(){d(this)}equals(y){p(y);let{X:T,Y:j,Z:L}=this,{X:V,Y:re,Z:U}=y,Y=a(T*U),Q=a(V*L),F=a(j*U),C=a(re*L);return Y===Q&&F===C}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:y}=r,{X:T,Y:j,Z:L}=this,V=a(T*T),re=a(j*j),U=a(zh*a(L*L)),Y=a(y*V),Q=T+j,F=a(a(Q*Q)-V-re),C=Y+re,E=C-U,k=Y-re,P=a(F*E),M=a(C*k),H=a(F*k),I=a(E*C);return new m(P,M,I,H)}add(y){p(y);let{a:T,d:j}=r,{X:L,Y:V,Z:re,T:U}=this,{X:Y,Y:Q,Z:F,T:C}=y,E=a(L*Y),k=a(V*Q),P=a(U*j*C),M=a(re*F),H=a((L+V)*(Y+Q)-E-k),I=M-P,_=M+P,R=a(k-T*E),B=a(H*I),G=a(_*R),X=a(H*R),D=a(I*_);return new m(B,G,D,X)}subtract(y){return this.add(y.negate())}multiply(y){let T=y;kr("scalar",T,ft,i);let{p:j,f:L}=g.cached(this,T,V=>An(m,V));return An(m,[j,L])[0]}multiplyUnsafe(y,T=m.ZERO){let j=y;return kr("scalar",j,Jr,i),j===Jr?m.ZERO:this.is0()||j===ft?this:g.unsafe(this,j,L=>An(m,L),T)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,i).is0()}toAffine(y){return f(this,y)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(y,T=!1){return ze(y),m.fromHex(y,T)}static fromHex(y,T=!1){let{d:j,a:L}=r,V=t.BYTES;y=Te("pointHex",y,V),_n("zip215",T);let re=y.slice(),U=y[V-1];re[V-1]=U&-129;let Y=fr(re),Q=T?s:t.ORDER;kr("pointHex.y",Y,Jr,Q);let F=a(Y*Y),C=a(F-ft),E=a(j*F-L),{isValid:k,value:P}=c(C,E);if(!k)throw new Error("Point.fromHex: invalid y coordinate");let M=(P&ft)===ft,H=(U&128)!==0;if(!T&&P===Jr&&H)throw new Error("Point.fromHex: x=0 and x_0=1");return H!==M&&(P=a(-P)),m.fromAffine({x:P,y:Y})}toBytes(){let{x:y,y:T}=this.toAffine(),j=Pr(T,t.BYTES);return j[j.length-1]|=y&ft?128:0,j}toRawBytes(){return this.toBytes()}toHex(){return lr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),m.ZERO=new m(Jr,ft,ft,Jr),m.Fp=t,m.Fn=n;let g=new Es(m,n.BYTES*8);return m}var xl=class{constructor(e){this.ep=e}static fromBytes(e){throw new Error("fromBytes must be implemented by subclass")}static fromHex(e){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toRawBytes(){return this.toBytes()}toHex(){return lr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}};function uE(r,e,t){if(typeof e!="function")throw new Error('"hash" function param is required');Yr(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=s.ORDER,c=t.randomBytes||ti,u=t.adjustScalarBytes||(E=>E),p=t.domain||((E,k,P)=>{if(_n("phflag",P),k.length||P)throw new Error("Contexts/pre-hash are not supported");return E});function f(E){return s.create(E)}function d(E){return f(fr(E))}function m(E){let k=i.BYTES;E=Te("private key",E,k);let P=Te("hashed private key",e(E),2*k),M=u(P.slice(0,k)),H=P.slice(k,2*k),I=d(M);return{head:M,prefix:H,scalar:I}}function g(E){let{head:k,prefix:P,scalar:M}=m(E),H=o.multiply(M),I=H.toBytes();return{head:k,prefix:P,scalar:M,point:H,pointBytes:I}}function w(E){return g(E).pointBytes}function y(E=Uint8Array.of(),...k){let P=$t(...k);return d(e(p(P,Te("context",E),!!n)))}function T(E,k,P={}){E=Te("message",E),n&&(E=n(E));let{prefix:M,scalar:H,pointBytes:I}=g(k),_=y(P.context,M,E),R=o.multiply(_).toBytes(),B=y(P.context,R,I,E),G=f(_+B*H);kr("signature.s",G,Jr,a);let X=i.BYTES,D=$t(R,Pr(G,X));return Te("result",D,X*2)}let j={zip215:!0};function L(E,k,P,M=j){let{context:H,zip215:I}=M,_=i.BYTES;E=Te("signature",E,2*_),k=Te("message",k),P=Te("publicKey",P,_),I!==void 0&&_n("zip215",I),n&&(k=n(k));let R=fr(E.slice(_,2*_)),B,G,X;try{B=r.fromHex(P,I),G=r.fromHex(E.slice(0,_),I),X=o.multiplyUnsafe(R)}catch{return!1}if(!I&&B.isSmallOrder())return!1;let D=y(H,G.toBytes(),B.toBytes(),k);return G.add(B.multiplyUnsafe(D)).subtract(X).clearCofactor().is0()}o.precompute(8);let V=i.BYTES,re={secret:V,public:V,signature:2*V,seed:V};function U(E=c(re.seed)){return E}let Y={getExtendedPublicKey:g,randomSecretKey:U,isValidSecretKey:F,isValidPublicKey:C,randomPrivateKey:U,toMontgomery(E){let{y:k}=r.fromBytes(E),P=V===32;if(!P&&V!==57)throw new Error("only defined for 25519 and 448");let M=P?i.div(ft+k,ft-k):i.div(k-ft,k+ft);return i.toBytes(M)},toMontgomeryPriv(E){ze(E,V);let k=e(E.subarray(0,V));return u(k).subarray(0,V)},precompute(E=8,k=r.BASE){return k.precompute(E,!1)}};function Q(E){let k=Y.randomSecretKey(E);return{secretKey:k,publicKey:w(k)}}function F(E){try{return!!s.fromBytes(E,!1)}catch{return!1}}function C(E,k){try{return!!r.fromBytes(E,k)}catch{return!1}}return Object.freeze({keygen:Q,getPublicKey:w,sign:T,verify:L,utils:Y,Point:r,info:{type:"edwards",lengths:re}})}function lE(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=tr(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,hash:r.hash,eddsaOpts:i}}function fE(r,e){return Object.assign({},e,{ExtendedPoint:e.Point,CURVE:r})}function nb(r){let{CURVE:e,curveOpts:t,hash:n,eddsaOpts:o}=lE(r),i=cE(e,t),s=uE(i,n,o);return fE(r,s)}var Ja=BigInt(0),Ts=BigInt(1),vl=BigInt(2);function pE(r){return Yr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function ob(r){let e=pE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||ti,u=a?255:448,p=a?32:56,f=BigInt(a?9:5),d=BigInt(a?121665:39081),m=a?vl**BigInt(254):vl**BigInt(447),g=a?BigInt(8)*vl**BigInt(251)-Ts:BigInt(4)*vl**BigInt(445)-Ts,w=m+g+Ts,y=P=>Ke(P,t),T=j(f);function j(P){return Pr(y(P),p)}function L(P){let M=Te("u coordinate",P,p);return a&&(M[31]&=127),y(fr(M))}function V(P){return fr(o(Te("scalar",P,p)))}function re(P,M){let H=Q(L(M),V(P));if(H===Ja)throw new Error("invalid private or public key received");return j(H)}function U(P){return re(P,T)}function Y(P,M,H){let I=y(P*(M-H));return M=y(M-I),H=y(H+I),{x_2:M,x_3:H}}function Q(P,M){kr("u",P,Ja,t),kr("scalar",M,m,w);let H=M,I=P,_=Ts,R=Ja,B=P,G=Ts,X=Ja;for(let fe=BigInt(u-1);fe>=Ja;fe--){let me=H>>fe&Ts;X^=me,{x_2:_,x_3:B}=Y(X,_,B),{x_2:R,x_3:G}=Y(X,R,G),X=me;let pe=_+R,ye=y(pe*pe),Ae=_-R,Re=y(Ae*Ae),nt=ye-Re,ot=B+G,zr=B-G,yt=y(zr*pe),Ar=y(ot*Ae),$o=yt+Ar,gn=yt-Ar;B=y($o*$o),G=y(I*y(gn*gn)),_=y(ye*Re),R=y(nt*(ye+y(d*nt)))}({x_2:_,x_3:B}=Y(X,_,B)),{x_2:R,x_3:G}=Y(X,R,G);let D=i(R);return y(_*D)}let F=(P=c(p))=>P,C={randomSecretKey:F,randomPrivateKey:F};function E(P){let M=C.randomSecretKey(P);return{secretKey:M,publicKey:U(M)}}let k={secret:p,public:p,seed:p};return{keygen:E,getSharedSecret:(P,M)=>re(P,M),getPublicKey:P=>U(P),scalarMult:re,scalarMultBase:U,utils:C,GuBytes:T.slice(),info:{type:"montgomery",lengths:k}}}var hE=BigInt(0),En=BigInt(1),ib=BigInt(2),dE=BigInt(3),yE=BigInt(5),mE=BigInt(8),Is={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mE,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function cb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Is.p,a=r*r%i*r%i,c=He(a,ib,i)*a%i,u=He(c,En,i)*r%i,p=He(u,yE,i)*u%i,f=He(p,e,i)*p%i,d=He(f,t,i)*f%i,m=He(d,n,i)*d%i,g=He(m,o,i)*m%i,w=He(g,o,i)*m%i,y=He(w,e,i)*p%i;return{pow_p_5_8:He(y,ib,i)*r%i,b2:a}}function ub(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Xh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Jh(r,e){let t=Is.p,n=Ke(e*e*e,t),o=Ke(n*n*e,t),i=cb(r*o).pow_p_5_8,s=Ke(r*n*i,t),a=Ke(e*s*s,t),c=s,u=Ke(s*Xh,t),p=a===r,f=a===Ke(-r,t),d=a===Ke(-r*Xh,t);return p&&(s=c),(f||d)&&(s=u),Sn(s,t)&&(s=Ke(-s,t)),{isValid:p||f,value:s}}var si=tr(Is.p,{isLE:!0}),gE=tr(Is.n,{isLE:!0}),bE={...Is,Fp:si,hash:j0,adjustScalarBytes:ub,uvRatio:Jh},Ot=nb(bE);var Qa=(()=>{let r=Is.p;return ob({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=cb(e);return Ke(He(t,dE,r)*n,r)},adjustScalarBytes:ub})})();var Zh=Xh,wE=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),xE=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),vE=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),_E=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),sb=r=>Jh(En,r),SE=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Yh=r=>Ot.CURVE.Fp.create(fr(r)&SE);function ab(r){let{d:e}=Ot.CURVE,t=Ot.CURVE.Fp.ORDER,n=Ot.CURVE.Fp.create,o=n(Zh*r*r),i=n((o+En)*vE),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=Jh(i,a),p=n(u*r);Sn(p,t)||(p=n(-p)),c||(u=p),c||(s=o);let f=n(s*(o-En)*_E-a),d=u*u,m=n((u+u)*a),g=n(f*wE),w=n(En-d),y=n(En+d);return new Ot.Point(n(m*y),n(w*g),n(g*y),n(m*w))}function AE(r){ze(r,64);let e=Yh(r.subarray(0,32)),t=ab(e),n=Yh(r.subarray(32,64)),o=ab(n);return new Cn(t.add(o))}var Cn=class r extends xl{constructor(e){super(e)}static fromAffine(e){return new r(Ot.Point.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static hashToCurve(e){return AE(Te("ristrettoHash",e,64))}static fromBytes(e){ze(e,32);let{a:t,d:n}=Ot.CURVE,o=si.ORDER,i=si.create,s=Yh(e);if(!L0(Pr(s,32),e)||Sn(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(En+t*a),u=i(En-t*a),p=i(c*c),f=i(u*u),d=i(t*n*p-f),{isValid:m,value:g}=sb(i(d*f)),w=i(g*u),y=i(g*w*d),T=i((s+s)*w);Sn(T,o)&&(T=i(-T));let j=i(c*y),L=i(T*j);if(!m||Sn(L,o)||j===hE)throw new Error("invalid ristretto255 encoding 2");return new r(new Ot.Point(T,j,En,L))}static fromHex(e){return r.fromBytes(Te("ristrettoHex",e,32))}static msm(e,t){return Cs(r,Ot.Point.Fn,e,t)}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,i=si.ORDER,s=si.create,a=s(s(n+t)*s(n-t)),c=s(e*t),u=s(c*c),{value:p}=sb(s(a*u)),f=s(p*a),d=s(p*c),m=s(f*d*o),g;if(Sn(o*m,i)){let y=s(t*Zh),T=s(e*Zh);e=y,t=T,g=s(f*xE)}else g=d;Sn(e*m,i)&&(t=s(-t));let w=s((n-t)*g);return Sn(w,i)&&(w=s(-w)),Pr(w,32)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=si.create,a=s(t*i)===s(n*o),c=s(n*i)===s(t*o);return a||c}is0(){return this.equals(r.ZERO)}};Cn.BASE=new Cn(Ot.Point.BASE);Cn.ZERO=new Cn(Ot.Point.ZERO);Cn.Fp=si;Cn.Fn=gE;var ec=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},tc=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},_l=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var lb={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new _l("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 Ft=lb;var Sl=32,rc=64,Qh=32;var Os,fb=(async()=>{try{return await Ft.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function pb(){let r=Ot.utils.randomPrivateKey(),e=Ot.getPublicKey(r);return{privateKey:OE(r,e),publicKey:e}}async function EE(r,e){let t;r.length===rc?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:ue(r.subarray(32),"base64url"),d:ue(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Ft.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ft.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function CE(r,e){let t=r.subarray(0,Qh);return Ot.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function hb(r,e){return Os==null&&(Os=await fb),Os?EE(r,e):CE(r,e)}async function TE(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Ft.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ft.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function IE(r,e,t){return Ot.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function db(r,e,t){return Os==null&&(Os=await fb),Os?TE(r,e,t):IE(r,e,t)}function OE(r,e){let t=new Uint8Array(rc);for(let n=0;n<Qh;n++)t[n]=r[n],t[Qh+n]=e[n];return t}function Bs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var nc=class{type="Ed25519";raw;constructor(e){this.raw=El(e,Sl)}toMultihash(){return Tr.digest(io(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $e.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=db(this.raw,t,e);return Bs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},Al=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=El(e,rc),this.publicKey=new nc(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=hb(this.raw,e);return Bs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function ed(r){return r=El(r,Sl),new nc(r)}async function mb(){let{privateKey:r,publicKey:e}=pb();return new Al(r,e)}function El(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ke(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var BE=Math.pow(2,7),PE=Math.pow(2,14),kE=Math.pow(2,21),td=Math.pow(2,28),rd=Math.pow(2,35),nd=Math.pow(2,42),od=Math.pow(2,49),Be=128,Bt=127;function Fe(r){if(r<BE)return 1;if(r<PE)return 2;if(r<kE)return 3;if(r<td)return 4;if(r<rd)return 5;if(r<nd)return 6;if(r<od)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ps(r,e,t=0){switch(Fe(r)){case 8:e[t++]=r&255|Be,r/=128;case 7:e[t++]=r&255|Be,r/=128;case 6:e[t++]=r&255|Be,r/=128;case 5:e[t++]=r&255|Be,r/=128;case 4:e[t++]=r&255|Be,r>>>=7;case 3:e[t++]=r&255|Be,r>>>=7;case 2:e[t++]=r&255|Be,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(Fe(r)){case 8:e.set(t++,r&255|Be),r/=128;case 7:e.set(t++,r&255|Be),r/=128;case 6:e.set(t++,r&255|Be),r/=128;case 5:e.set(t++,r&255|Be),r/=128;case 4:e.set(t++,r&255|Be),r>>>=7;case 3:e.set(t++,r&255|Be),r>>>=7;case 2:e.set(t++,r&255|Be),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function id(r,e){let t=r[e],n=0;if(n+=t&Bt,t<Be||(t=r[e+1],n+=(t&Bt)<<7,t<Be)||(t=r[e+2],n+=(t&Bt)<<14,t<Be)||(t=r[e+3],n+=(t&Bt)<<21,t<Be)||(t=r[e+4],n+=(t&Bt)*td,t<Be)||(t=r[e+5],n+=(t&Bt)*rd,t<Be)||(t=r[e+6],n+=(t&Bt)*nd,t<Be)||(t=r[e+7],n+=(t&Bt)*od,t<Be))return n;throw new RangeError("Could not decode varint")}function DE(r,e){let t=r.get(e),n=0;if(n+=t&Bt,t<Be||(t=r.get(e+1),n+=(t&Bt)<<7,t<Be)||(t=r.get(e+2),n+=(t&Bt)<<14,t<Be)||(t=r.get(e+3),n+=(t&Bt)<<21,t<Be)||(t=r.get(e+4),n+=(t&Bt)*td,t<Be)||(t=r.get(e+5),n+=(t&Bt)*rd,t<Be)||(t=r.get(e+6),n+=(t&Bt)*nd,t<Be)||(t=r.get(e+7),n+=(t&Bt)*od,t<Be))return n;throw new RangeError("Could not decode varint")}function Cl(r,e,t=0){return e==null&&(e=lt(Fe(r))),e instanceof Uint8Array?Ps(r,e,t):NE(r,e,t)}function ai(r,e=0){return r instanceof Uint8Array?id(r,e):DE(r,e)}var sd=new Float32Array([-0]),fo=new Uint8Array(sd.buffer);function gb(r,e,t){sd[0]=r,e[t]=fo[0],e[t+1]=fo[1],e[t+2]=fo[2],e[t+3]=fo[3]}function bb(r,e){return fo[0]=r[e],fo[1]=r[e+1],fo[2]=r[e+2],fo[3]=r[e+3],sd[0]}var ad=new Float64Array([-0]),Pt=new Uint8Array(ad.buffer);function wb(r,e,t){ad[0]=r,e[t]=Pt[0],e[t+1]=Pt[1],e[t+2]=Pt[2],e[t+3]=Pt[3],e[t+4]=Pt[4],e[t+5]=Pt[5],e[t+6]=Pt[6],e[t+7]=Pt[7]}function xb(r,e){return Pt[0]=r[e],Pt[1]=r[e+1],Pt[2]=r[e+2],Pt[3]=r[e+3],Pt[4]=r[e+4],Pt[5]=r[e+5],Pt[6]=r[e+6],Pt[7]=r[e+7],ad[0]}var jE=BigInt(Number.MAX_SAFE_INTEGER),RE=BigInt(Number.MIN_SAFE_INTEGER),rr=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 ci;if(e<jE&&e>RE)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>vb&&(o=0n,++n>vb&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return ci;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):ci}},ci=new rr(0,0);ci.toBigInt=function(){return 0n};ci.zzEncode=ci.zzDecode=function(){return this};ci.length=function(){return 1};var vb=4294967296n;function _b(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 Sb(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 cd(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 Nr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Il(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var ud=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,Nr(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 Nr(this,4);return Il(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Nr(this,4);return Il(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Nr(this,4);let e=bb(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Nr(this,4);let e=xb(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 Nr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Sb(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Nr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Nr(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 rr(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 Nr(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 Nr(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 Nr(this,8);let e=Il(this.buf,this.pos+=4),t=Il(this.buf,this.pos+=4);return new rr(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=id(this.buf,this.pos);return this.pos+=Fe(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 ld(r){return new ud(r instanceof Uint8Array?r:r.subarray())}function Dr(r,e,t){let n=ld(r);return e.decode(n,void 0,t)}function fd(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return lt(s);o+s>e&&(n=lt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ui=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function pd(){}var dd=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},LE=fd();function UE(r){return globalThis.Buffer!=null?lt(r):LE(r)}var ic=class{len;head;tail;states;constructor(){this.len=0,this.head=new ui(pd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ui(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new yd((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(Ol,10,rr.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=rr.fromBigInt(e);return this._push(Ol,t.length(),t)}uint64Number(e){return this._push(Ps,Fe(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=rr.fromBigInt(e).zzEncode();return this._push(Ol,t.length(),t)}sint64Number(e){let t=rr.fromNumber(e).zzEncode();return this._push(Ol,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(hd,1,e?1:0)}fixed32(e){return this._push(oc,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=rr.fromBigInt(e);return this._push(oc,4,t.lo)._push(oc,4,t.hi)}fixed64Number(e){let t=rr.fromNumber(e);return this._push(oc,4,t.lo)._push(oc,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(gb,4,e)}double(e){return this._push(wb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(hd,1,0):this.uint32(t)._push(KE,t,e)}string(e){let t=_b(e);return t!==0?this.uint32(t)._push(cd,t,e):this._push(hd,1,0)}fork(){return this.states=new dd(this),this.head=this.tail=new ui(pd,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 ui(pd,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 hd(r,e,t){e[t]=r&255}function ME(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var yd=class extends ui{next;constructor(e,t){super(ME,e,t),this.next=void 0}};function Ol(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 oc(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 KE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(ic.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(HE,e,r),this},ic.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(VE,e,r),this});function HE(r,e,t){e.set(r,t)}function VE(r,e,t){r.length<40?cd(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function md(){return new ic}function jr(r,e){let t=md();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ks;(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"})(ks||(ks={}));function Bl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function li(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 Bl("enum",ks.VARINT,t,n)}function Rr(r,e){return Bl("message",ks.LENGTH_DELIMITED,r,e)}var sc=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 gd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(gd||(gd={}));(function(r){r.codec=()=>li(gd)})(tt||(tt={}));var Qr;(function(r){let e;r.codec=()=>(e==null&&(e=Rr((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=>jr(t,r.codec()),r.decode=(t,n)=>Dr(t,r.codec(),n)})(Qr||(Qr={}));var bd;(function(r){let e;r.codec=()=>(e==null&&(e=Rr((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=>jr(t,r.codec()),r.decode=(t,n)=>Dr(t,r.codec(),n)})(bd||(bd={}));var cc={};Tt(cc,{MAX_RSA_KEY_SIZE:()=>wd,generateRSAKeyPair:()=>Id,jwkToJWKKeyPair:()=>Ob,jwkToPkcs1:()=>qE,jwkToPkix:()=>Sd,jwkToRSAPrivateKey:()=>Td,pkcs1MessageToJwk:()=>vd,pkcs1MessageToRSAPrivateKey:()=>Ad,pkcs1ToJwk:()=>WE,pkcs1ToRSAPrivateKey:()=>Ib,pkixMessageToJwk:()=>_d,pkixMessageToRSAPublicKey:()=>Cd,pkixToJwk:()=>GE,pkixToRSAPublicKey:()=>Ed});var po=ml;var Ns=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=cc.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return $e.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t,n){return Tb(this.jwk,t,e,n)}},ac=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=cc.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e,t){return Cb(this.jwk,e,t)}};var wd=8192,xd=18,$E=1062,FE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function WE(r){let e=wn(r);return vd(e)}function vd(r){return{n:ue(r[1],"base64url"),e:ue(r[2],"base64url"),d:ue(r[3],"base64url"),p:ue(r[4],"base64url"),q:ue(r[5],"base64url"),dp:ue(r[6],"base64url"),dq:ue(r[7],"base64url"),qi:ue(r[8],"base64url"),kty:"RSA"}}function qE(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 ke("JWK was missing components");return Ir([Lt(Uint8Array.from([0])),Lt(de(r.n,"base64url")),Lt(de(r.e,"base64url")),Lt(de(r.d,"base64url")),Lt(de(r.p,"base64url")),Lt(de(r.q,"base64url")),Lt(de(r.dp,"base64url")),Lt(de(r.dq,"base64url")),Lt(de(r.qi,"base64url"))]).subarray()}function GE(r){let e=wn(r,{offset:0});return _d(e)}function _d(r){let e=wn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Sd(r){if(r.n==null||r.e==null)throw new ke("JWK was missing components");return Ir([FE,Wa(Ir([Lt(de(r.n,"base64url")),Lt(de(r.e,"base64url"))]))]).subarray()}function Ib(r){let e=wn(r);return Ad(e)}function Ad(r){let e=vd(r);return Td(e)}function Ed(r,e){if(r.byteLength>=$E)throw new ds("Key size is too large");let t=wn(r,{offset:0});return Cd(t,r,e)}function Cd(r,e,t){let n=_d(r);if(t==null){let o=po(Qr.encode({Type:tt.RSA,Data:e}));t=It(xd,o)}return new Ns(n,t)}function Td(r){if(Pb(r)>wd)throw new ke("Key size is too large");let e=Ob(r),t=po(Qr.encode({Type:tt.RSA,Data:Sd(e.publicKey)})),n=It(xd,t);return new ac(e.privateKey,new Ns(e.publicKey,n))}async function Id(r){if(r>wd)throw new ke("Key size is too large");let e=await Bb(r),t=po(Qr.encode({Type:tt.RSA,Data:Sd(e.publicKey)})),n=It(xd,t);return new ac(e.privateKey,new Ns(e.publicKey,n))}function Ob(r){if(r==null)throw new ke("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Bb(r,e){let t=await Ft.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await zE(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Cb(r,e,t){let n=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Ft.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Tb(r,e,t,n){let o=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function zE(r,e){if(r.privateKey==null||r.publicKey==null)throw new ke("Private and public key are required");let t=await Promise.all([Ft.get().subtle.exportKey("jwk",r.privateKey),Ft.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function Pb(r){if(r.kty!=="RSA")throw new ke("invalid key type");if(r.n==null)throw new ke("invalid key modulus");return de(r.n,"base64url").length*8}var Pl=class extends xs{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Qo(e);let n=so(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),Or(i)}update(e){return vs(this),this.iHash.update(e),this}digestInto(e){vs(this),ze(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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ds=(r,e,t)=>new Pl(r,e).update(t).digest();Ds.create=(r,e)=>new Pl(r,e);var kb=(r,e)=>(r+(r>=0?e:-e)/Db)/e;function XE(r,e,t){let[[n,o],[i,s]]=e,a=kb(s*r,t),c=kb(-o*r,t),u=r-a*n-c*i,p=-a*o-c*s,f=u<In,d=p<In;f&&(u=-u),d&&(p=-p);let m=lo(Math.ceil(bl(t)/2))+Rs;if(u<In||u>=m||p<In||p>=m)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:p}}function Nb(r){r.lowS!==void 0&&_n("lowS",r.lowS),r.prehash!==void 0&&_n("prehash",r.prehash)}var Od=class extends Error{constructor(e=""){super(e)}},Tn={Err:Od,_tlv:{encode:(r,e)=>{let{Err:t}=Tn;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=Xa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Xa(o.length/2|128):"";return Xa(r)+i+o+e},decode(r,e){let{Err:t}=Tn,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 p of u)s=s<<8|p;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}=Tn;if(r<In)throw new e("integer: negative integers are not allowed");let t=Xa(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}=Tn;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 _s(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Tn,o=Te("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:p}=n.decode(2,c);if(p.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}=Tn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},In=BigInt(0),Rs=BigInt(1),Db=BigInt(2),kl=BigInt(3),ZE=BigInt(4);function YE(r,e,t){function n(o){let i=r.sqr(o),s=r.mul(i,o);return r.add(r.add(s,r.mul(o,e)),t)}return n}function js(r,e){let{BYTES:t}=r,n;if(typeof e=="bigint")n=e;else{let o=Te("private key",e);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function JE(r,e={}){let{Fp:t,Fn:n}=wl("weierstrass",r,e),{h:o,n:i}=r;Yr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:s}=e;if(s&&(!t.is0(r.a)||typeof s.beta!="bigint"||!Array.isArray(s.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(F,C,E){let{x:k,y:P}=C.toAffine(),M=t.toBytes(k);if(_n("isCompressed",E),E){a();let H=!t.isOdd(P);return $t(jb(H),M)}else return $t(Uint8Array.of(4),M,t.toBytes(P))}function u(F){ze(F);let C=t.BYTES,E=C+1,k=2*C+1,P=F.length,M=F[0],H=F.subarray(1);if(P===E&&(M===2||M===3)){let I=t.fromBytes(H);if(!t.isValid(I))throw new Error("bad point: is not on curve, wrong x");let _=d(I),R;try{R=t.sqrt(_)}catch(X){let D=X instanceof Error?": "+X.message:"";throw new Error("bad point: is not on curve, sqrt error"+D)}a();let B=t.isOdd(R);return(M&1)===1!==B&&(R=t.neg(R)),{x:I,y:R}}else if(P===k&&M===4){let I=t.fromBytes(H.subarray(C*0,C*1)),_=t.fromBytes(H.subarray(C*1,C*2));if(!m(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${P}, expected compressed=${E} or uncompressed=${k}`)}let p=e.toBytes||c,f=e.fromBytes||u,d=YE(t,r.a,r.b);function m(F,C){let E=t.sqr(C),k=d(F);return t.eql(E,k)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let g=t.mul(t.pow(r.a,kl),ZE),w=t.mul(t.sqr(r.b),BigInt(27));if(t.is0(t.add(g,w)))throw new Error("bad curve params: a or b");function y(F,C,E=!1){if(!t.isValid(C)||E&&t.is0(C))throw new Error(`bad point coordinate ${F}`);return C}function T(F){if(!(F instanceof U))throw new Error("ProjectivePoint expected")}function j(F){if(!s||!s.basises)throw new Error("no endo");return XE(F,s.basises,n.ORDER)}let L=Ss((F,C)=>{let{X:E,Y:k,Z:P}=F;if(t.eql(P,t.ONE))return{x:E,y:k};let M=F.is0();C==null&&(C=M?t.ONE:t.inv(P));let H=t.mul(E,C),I=t.mul(k,C),_=t.mul(P,C);if(M)return{x:t.ZERO,y:t.ZERO};if(!t.eql(_,t.ONE))throw new Error("invZ was invalid");return{x:H,y:I}}),V=Ss(F=>{if(F.is0()){if(e.allowInfinityPoint&&!t.is0(F.Y))return;throw new Error("bad point: ZERO")}let{x:C,y:E}=F.toAffine();if(!t.isValid(C)||!t.isValid(E))throw new Error("bad point: x or y not field elements");if(!m(C,E))throw new Error("bad point: equation left != right");if(!F.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function re(F,C,E,k,P){return E=new U(t.mul(E.X,F),E.Y,E.Z),C=Ya(k,C),E=Ya(P,E),C.add(E)}class U{constructor(C,E,k){this.X=y("x",C),this.Y=y("y",E,!0),this.Z=y("z",k),Object.freeze(this)}static fromAffine(C){let{x:E,y:k}=C||{};if(!C||!t.isValid(E)||!t.isValid(k))throw new Error("invalid affine point");if(C instanceof U)throw new Error("projective point not allowed");return t.is0(E)&&t.is0(k)?U.ZERO:new U(E,k,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(C){return An(U,C)}static fromBytes(C){return ze(C),U.fromHex(C)}static fromHex(C){let E=U.fromAffine(f(Te("pointHex",C)));return E.assertValidity(),E}static fromPrivateKey(C){return U.BASE.multiply(js(n,C))}static msm(C,E){return Cs(U,n,C,E)}_setWindowSize(C){this.precompute(C)}precompute(C=8,E=!0){return Q.createCache(this,C),E||this.multiply(kl),this}assertValidity(){V(this)}hasEvenY(){let{y:C}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(C)}equals(C){T(C);let{X:E,Y:k,Z:P}=this,{X:M,Y:H,Z:I}=C,_=t.eql(t.mul(E,I),t.mul(M,P)),R=t.eql(t.mul(k,I),t.mul(H,P));return _&&R}negate(){return new U(this.X,t.neg(this.Y),this.Z)}double(){let{a:C,b:E}=r,k=t.mul(E,kl),{X:P,Y:M,Z:H}=this,I=t.ZERO,_=t.ZERO,R=t.ZERO,B=t.mul(P,P),G=t.mul(M,M),X=t.mul(H,H),D=t.mul(P,M);return D=t.add(D,D),R=t.mul(P,H),R=t.add(R,R),I=t.mul(C,R),_=t.mul(k,X),_=t.add(I,_),I=t.sub(G,_),_=t.add(G,_),_=t.mul(I,_),I=t.mul(D,I),R=t.mul(k,R),X=t.mul(C,X),D=t.sub(B,X),D=t.mul(C,D),D=t.add(D,R),R=t.add(B,B),B=t.add(R,B),B=t.add(B,X),B=t.mul(B,D),_=t.add(_,B),X=t.mul(M,H),X=t.add(X,X),B=t.mul(X,D),I=t.sub(I,B),R=t.mul(X,G),R=t.add(R,R),R=t.add(R,R),new U(I,_,R)}add(C){T(C);let{X:E,Y:k,Z:P}=this,{X:M,Y:H,Z:I}=C,_=t.ZERO,R=t.ZERO,B=t.ZERO,G=r.a,X=t.mul(r.b,kl),D=t.mul(E,M),fe=t.mul(k,H),me=t.mul(P,I),pe=t.add(E,k),ye=t.add(M,H);pe=t.mul(pe,ye),ye=t.add(D,fe),pe=t.sub(pe,ye),ye=t.add(E,P);let Ae=t.add(M,I);return ye=t.mul(ye,Ae),Ae=t.add(D,me),ye=t.sub(ye,Ae),Ae=t.add(k,P),_=t.add(H,I),Ae=t.mul(Ae,_),_=t.add(fe,me),Ae=t.sub(Ae,_),B=t.mul(G,ye),_=t.mul(X,me),B=t.add(_,B),_=t.sub(fe,B),B=t.add(fe,B),R=t.mul(_,B),fe=t.add(D,D),fe=t.add(fe,D),me=t.mul(G,me),ye=t.mul(X,ye),fe=t.add(fe,me),me=t.sub(D,me),me=t.mul(G,me),ye=t.add(ye,me),D=t.mul(fe,ye),R=t.add(R,D),D=t.mul(Ae,ye),_=t.mul(pe,_),_=t.sub(_,D),D=t.mul(pe,fe),B=t.mul(Ae,B),B=t.add(B,D),new U(_,R,B)}subtract(C){return this.add(C.negate())}is0(){return this.equals(U.ZERO)}multiply(C){let{endo:E}=e;if(!n.isValidNot0(C))throw new Error("invalid scalar: out of range");let k,P,M=H=>Q.cached(this,H,I=>An(U,I));if(E){let{k1neg:H,k1:I,k2neg:_,k2:R}=j(C),{p:B,f:G}=M(I),{p:X,f:D}=M(R);P=G.add(D),k=re(E.beta,B,X,H,_)}else{let{p:H,f:I}=M(C);k=H,P=I}return An(U,[k,P])[0]}multiplyUnsafe(C){let{endo:E}=e,k=this;if(!n.isValid(C))throw new Error("invalid scalar: out of range");if(C===In||k.is0())return U.ZERO;if(C===Rs)return k;if(Q.hasCache(this))return this.multiply(C);if(E){let{k1neg:P,k1:M,k2neg:H,k2:I}=j(C),{p1:_,p2:R}=rb(U,k,M,I);return re(E.beta,_,R,P,H)}else return Q.unsafe(k,C)}multiplyAndAddUnsafe(C,E,k){let P=this.multiplyUnsafe(E).add(C.multiplyUnsafe(k));return P.is0()?void 0:P}toAffine(C){return L(this,C)}isTorsionFree(){let{isTorsionFree:C}=e;return o===Rs?!0:C?C(U,this):Q.unsafe(this,i).is0()}clearCofactor(){let{clearCofactor:C}=e;return o===Rs?this:C?C(U,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(C=!0){return _n("isCompressed",C),this.assertValidity(),p(U,this,C)}toRawBytes(C=!0){return this.toBytes(C)}toHex(C=!0){return lr(this.toBytes(C))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}U.BASE=new U(r.Gx,r.Gy,t.ONE),U.ZERO=new U(t.ZERO,t.ONE,t.ZERO),U.Fp=t,U.Fn=n;let Y=n.BITS,Q=new Es(U,e.endo?Math.ceil(Y/2):Y);return U}function jb(r){return Uint8Array.of(r?2:3)}function QE(r,e,t={}){Qo(e),Yr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||ti,o=t.hmac||((I,..._)=>Ds(e,I,$t(..._))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,u=$h(a),p={secret:s.BYTES,public:1+i.BYTES,publicUncompressed:1+2*i.BYTES,signature:2*s.BYTES,seed:u};function f(I){let _=a>>Rs;return I>_}function d(I){return f(I)?s.neg(I):I}function m(I,_){if(!s.isValidNot0(_))throw new Error(`invalid signature ${I}: out of range 1..CURVE.n`)}class g{constructor(_,R,B){m("r",_),m("s",R),this.r=_,this.s=R,B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(_,R="compact"){if(R==="compact"){let B=s.BYTES;ze(_,B*2);let G=_.subarray(0,B),X=_.subarray(B,B*2);return new g(s.fromBytes(G),s.fromBytes(X))}if(R==="der"){ze(_);let{r:B,s:G}=Tn.toSig(_);return new g(B,G)}throw new Error("invalid format")}static fromHex(_,R){return this.fromBytes(ei(_),R)}addRecoveryBit(_){return new g(this.r,this.s,_)}recoverPublicKey(_){let R=i.ORDER,{r:B,s:G,recovery:X}=this;if(X==null||![0,1,2,3].includes(X))throw new Error("recovery id invalid");if(a*Db<R&&X>1)throw new Error("recovery id is ambiguous for h>1 curve");let fe=X===2||X===3?B+a:B;if(!i.isValid(fe))throw new Error("recovery id 2 or 3 invalid");let me=i.toBytes(fe),pe=r.fromHex($t(jb((X&1)===0),me)),ye=s.inv(fe),Ae=Y(Te("msgHash",_)),Re=s.create(-Ae*ye),nt=s.create(G*ye),ot=r.BASE.multiplyUnsafe(Re).add(pe.multiplyUnsafe(nt));if(ot.is0())throw new Error("point at infinify");return ot.assertValidity(),ot}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s.neg(this.s),this.recovery):this}toBytes(_="compact"){if(_==="compact")return $t(s.toBytes(this.r),s.toBytes(this.s));if(_==="der")return ei(Tn.hexFromSig(this));throw new Error("invalid format")}toHex(_){return lr(this.toBytes(_))}assertValidity(){}static fromCompact(_){return g.fromBytes(Te("sig",_),"compact")}static fromDER(_){return g.fromBytes(Te("sig",_),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return lr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return lr(this.toBytes("compact"))}}function w(I){try{return!!js(s,I)}catch{return!1}}function y(I,_){try{let R=I.length;return _===!0&&R!==p.public||_===!1&&R!==p.publicUncompressed?!1:!!r.fromBytes(I)}catch{return!1}}function T(I=n(u)){return Fh(I,a)}let j={isValidSecretKey:w,isValidPublicKey:y,randomSecretKey:T,isValidPrivateKey:w,randomPrivateKey:T,normPrivateKeyToScalar:I=>js(s,I),precompute(I=8,_=r.BASE){return _.precompute(I,!1)}};function L(I,_=!0){return r.BASE.multiply(js(s,I)).toBytes(_)}function V(I){if(typeof I=="bigint")return!1;if(I instanceof r)return!0;if(s.allowedLengths||p.secret===p.public)return;let _=Te("key",I).length;return _===p.public||_===p.publicUncompressed}function re(I,_,R=!0){if(V(I)===!0)throw new Error("first arg must be private key");if(V(_)===!1)throw new Error("second arg must be public key");let B=js(s,I);return r.fromHex(_).multiply(B).toBytes(R)}let U=t.bits2int||function(I){if(I.length>8192)throw new Error("input is too large");let _=_s(I),R=I.length*8-c;return R>0?_>>BigInt(R):_},Y=t.bits2int_modN||function(I){return s.create(U(I))},Q=lo(c);function F(I){return kr("num < 2^"+c,I,In,Q),s.toBytes(I)}function C(I,_,R=E){if(["recovered","canonical"].some(Re=>Re in R))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:G,extraEntropy:X}=R;B==null&&(B=!0),I=Te("msgHash",I),Nb(R),G&&(I=Te("prehashed msgHash",e(I)));let D=Y(I),fe=js(s,_),me=[F(fe),F(D)];if(X!=null&&X!==!1){let Re=X===!0?n(p.secret):X;me.push(Te("extraEntropy",Re))}let pe=$t(...me),ye=D;function Ae(Re){let nt=U(Re);if(!s.isValidNot0(nt))return;let ot=s.inv(nt),zr=r.BASE.multiply(nt).toAffine(),yt=s.create(zr.x);if(yt===In)return;let Ar=s.create(ot*s.create(ye+yt*fe));if(Ar===In)return;let $o=(zr.x===yt?0:2)|Number(zr.y&Rs),gn=Ar;return B&&f(Ar)&&(gn=d(Ar),$o^=1),new g(yt,gn,$o)}return{seed:pe,k2sig:Ae}}let E={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function P(I,_,R=E){let{seed:B,k2sig:G}=C(I,_,R);return M0(e.outputLen,s.BYTES,o)(B,G)}r.BASE.precompute(8);function M(I,_,R,B=k){let G=I;_=Te("msgHash",_),R=Te("publicKey",R),Nb(B);let{lowS:X,prehash:D,format:fe}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");let me,pe;if(fe===void 0){let ye=typeof G=="string"||Jo(G),Ae=!ye&&G!==null&&typeof G=="object"&&typeof G.r=="bigint"&&typeof G.s=="bigint";if(!ye&&!Ae)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(Ae)me=new g(G.r,G.s);else if(ye){try{me=g.fromDER(G)}catch(Re){if(!(Re instanceof Tn.Err))throw Re}if(!me)try{me=g.fromCompact(G)}catch{return!1}}}else if(fe==="compact"||fe==="der"){if(typeof G!="string"&&!Jo(G))throw new Error('"der" / "compact" format expects Uint8Array signature');me=g.fromBytes(Te("sig",G),fe)}else if(fe==="js"){if(!(G instanceof g))throw new Error('"js" format expects Signature instance');me=G}else throw new Error('format must be "compact", "der" or "js"');if(!me)return!1;try{if(pe=r.fromHex(R),X&&me.hasHighS())return!1;D&&(_=e(_));let{r:ye,s:Ae}=me,Re=Y(_),nt=s.inv(Ae),ot=s.create(Re*nt),zr=s.create(ye*nt),yt=r.BASE.multiplyUnsafe(ot).add(pe.multiplyUnsafe(zr));return yt.is0()?!1:s.create(yt.x)===ye}catch{return!1}}function H(I){let _=j.randomSecretKey(I);return{secretKey:_,publicKey:L(_)}}return Object.freeze({keygen:H,getPublicKey:L,sign:P,verify:M,getSharedSecret:re,utils:j,Point:r,Signature:g,info:{type:"weierstrass",lengths:p,publicKeyHasPrefix:!0}})}function e2(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=tr(e.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),i={Fp:t,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:i}}function t2(r){let{CURVE:e,curveOpts:t}=e2(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,hash:r.hash,ecdsaOpts:n}}function r2(r,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:r})}function Rb(r){let{CURVE:e,curveOpts:t,hash:n,ecdsaOpts:o}=t2(r),i=JE(e,t),s=QE(i,n,o);return r2(r,s)}function Lb(r,e){let t=n=>Rb({...r,hash:n});return{...t(e),create:t}}var Pd={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},n2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ub=BigInt(2);function o2(r){let e=Pd.p,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,p=u*u*r%e,f=He(p,t,e)*p%e,d=He(f,t,e)*p%e,m=He(d,Ub,e)*u%e,g=He(m,o,e)*m%e,w=He(g,i,e)*g%e,y=He(w,a,e)*w%e,T=He(y,c,e)*y%e,j=He(T,a,e)*w%e,L=He(j,t,e)*p%e,V=He(L,s,e)*g%e,re=He(V,n,e)*u%e,U=He(re,Ub,e);if(!Bd.eql(Bd.sqr(U),r))throw new Error("Cannot find square root");return U}var Bd=tr(Pd.p,void 0,void 0,{sqrt:o2}),Lr=Lb({...Pd,Fp:Bd,lowS:!0,endo:n2},ml);function Mb(r,e,t){let n=ur.digest(e instanceof Uint8Array?e:e.subarray());if(Bs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Lr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new ec(String(o))});try{return Lr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new ec(String(o))}}function Kb(r,e,t,n){let o=ur.digest(t instanceof Uint8Array?t:t.subarray());if(Bs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Lr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new tc(String(i))});try{return n?.signal?.throwIfAborted(),Lr.verify(e,o.digest,r)}catch(i){throw new tc(String(i))}}var uc=class{type="secp256k1";raw;_key;constructor(e){this._key=$b(e),this.raw=Hb(this._key)}toMultihash(){return Tr.digest(io(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $e.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}verify(e,t,n){return Kb(this._key,t,e,n)}},Nl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=Vb(e),this.publicKey=new uc(t??Fb(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ge(this.raw,e.raw)}sign(e,t){return Mb(this.raw,e,t)}};function kd(r){return new uc(r)}async function Wb(){let r=i2();return new Nl(r)}function Hb(r){return Lr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Vb(r){try{return Lr.getPublicKey(r,!0),r}catch(e){throw new Ua(String(e))}}function $b(r){try{return Lr.ProjectivePoint.fromHex(r),r}catch(e){throw new ds(String(e))}}function Fb(r){try{return Lr.getPublicKey(r,!0)}catch(e){throw new Ua(String(e))}}function i2(){return Lr.utils.randomPrivateKey()}async function qb(r,e){if(r==="Ed25519")return mb();if(r==="secp256k1")return Wb();if(r==="RSA")return Id(s2(e));if(r==="ECDSA")return x0(a2(e));throw new to}function lc(r,e){let{Type:t,Data:n}=Qr.decode(r),o=n??new Uint8Array;switch(t){case tt.RSA:return Ed(o,e);case tt.Ed25519:return ed(o);case tt.secp256k1:return kd(o);case tt.ECDSA:return kh(o);default:throw new to}}function Gb(r){let{Type:e,Data:t}=Qr.decode(r.digest),n=t??new Uint8Array;switch(e){case tt.Ed25519:return ed(n);case tt.secp256k1:return kd(n);case tt.ECDSA:return kh(n);default:throw new to}}function io(r){return Qr.encode({Type:tt[r.type],Data:r.raw})}function s2(r){return r==null?2048:parseInt(r,10)}function a2(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 ke("Unsupported curve, should be P-256, P-384 or P-521")}async function Dl(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 ke("Only RSA and ECDSA keys are supported")}var zb=Symbol.for("nodejs.util.inspect.custom"),c2=114,fc=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()})`}[ih]=!0;toString(){return this.string==null&&(this.string=$e.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(c2,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")}[zb](){return`PeerId(${this.toString()})`}},pc=class extends fc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},hc=class extends fc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},dc=class extends fc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},u2=2336,yc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Tr.digest(de(this.url))}[zb](){return`PeerId(${this.url})`}[ih]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(u2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var l2=114,Xb=2336;function jl(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ws($e.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return f2(et.parse(r));if(e==null)throw new ke('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ws(e.decode(r))}return Zb(t)}function Nd(r){if(r.type==="Ed25519")return new hc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new dc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new pc({multihash:r.toCID().multihash,publicKey:r});throw new to}function Zb(r){if(h2(r))return new pc({multihash:r});if(p2(r))try{let e=Gb(r);if(e.type==="Ed25519")return new hc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new dc({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new yc(new URL(t))}throw new ol("Supplied PeerID Multihash is invalid")}function f2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==l2&&r.code!==Xb)throw new nl("Supplied PeerID CID is invalid");if(r.code===Xb){let e=ue(r.multihash.digest);return new yc(new URL(e))}return Zb(r.multihash)}function p2(r){return r.code===Tr.code}function h2(r){return r.code===ur.code}var gt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},On=class extends Error{static name="ValidationError";name="ValidationError"},mc=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Rl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ll=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 p=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,e);if(!Number.isNaN(d))return d});if(p===void 0)break;if(i*=e,i+=p,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 d2=45,y2=15,Ul=new Ll;function Dd(r){if(!(r.length>y2))return Ul.new(r).parseWith(()=>Ul.readIPv4Addr())}function jd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>d2))return Ul.new(r).parseWith(()=>Ul.readIPv6Addr())}function Ml(r){return!!Dd(r)}function Jb(r){return!!jd(r)}function Ld(r){return e=>ue(e,r)}function Ud(r){return e=>de(e,r)}function Ls(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function fi(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Qb(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=de(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=fi(n);return Rt([t,o],t.length+o.length)}function ew(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=oo.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=fi(n);return Rt([t,o],t.length+o.length)}function Md(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ue(e,"base32"),o=Ls(t);return`${n}:${o}`}var Kd=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new gt("Invalid byte value in IP address");e[n]=o}),e},tw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Ml(t[n]),s;i&&(s=Kd(t[n]),t[n]=ue(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.subarray(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++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new gt("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},rw=function(r){if(r.byteLength!==4)throw new gt("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},nw=function(r){if(r.byteLength!==16)throw new gt("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${t}"`)}};function ow(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${r}"`)}}var Rd=Object.values(zo).map(r=>r.decoder),m2=function(){let r=Rd[0].or(Rd[1]);return Rd.slice(2).forEach(e=>r=r.or(e)),r}();function iw(r){return m2.decode(r)}function sw(r){return e=>r.encoder.encode(e)}function g2(r){if(parseInt(r).toString()!==r)throw new On("Value must be an integer")}function b2(r){if(r<0)throw new On("Value must be a positive integer, or zero")}function w2(r){return e=>{if(e>r)throw new On(`Value must be smaller than or equal to ${r}`)}}function x2(...r){return e=>{for(let t of r)t(e)}}var gc=x2(g2,b2,w2(65535));var dt=-1,Hd=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Rl(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},nr=new Hd,j2=[{code:4,name:"ip4",size:32,valueToBytes:Kd,bytesToValue:rw,validate:r=>{if(!Ml(r))throw new On(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:fi,bytesToValue:Ls,validate:gc},{code:273,name:"udp",size:16,valueToBytes:fi,bytesToValue:Ls,validate:gc},{code:33,name:"dccp",size:16,valueToBytes:fi,bytesToValue:Ls,validate:gc},{code:41,name:"ip6",size:128,valueToBytes:tw,bytesToValue:nw,stringToValue:ow,validate:r=>{if(!Jb(r))throw new On(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:Ld("base10"),valueToBytes:Ud("base10")},{code:53,name:"dns",size:dt,resolvable:!0},{code:54,name:"dns4",size:dt,resolvable:!0},{code:55,name:"dns6",size:dt,resolvable:!0},{code:56,name:"dnsaddr",size:dt,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:fi,bytesToValue:Ls,validate:gc},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:Ld("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ud("base58btc")(r):et.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Md,valueToBytes:Qb},{code:445,name:"onion3",size:296,bytesToValue:Md,valueToBytes:ew},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:sw(Go),valueToBytes:iw},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];j2.forEach(r=>{nr.addProtocol(r)});function aw(r){let e=[],t=0;for(;t<r.length;){let n=ai(r,t),o=nr.getProtocol(n),i=Fe(n),s=R2(o,r,t+i),a=0;s>0&&o.size===dt&&(a=Fe(s));let c=i+a+s,u={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let p=t+i+a,f=r.subarray(p,p+s);u.value=o.bytesToValue?.(f)??ue(f)}e.push(u),t+=c}return e}function cw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=nr.getProtocol(n.code),i=Fe(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??de(n.value),a=s.byteLength,o.size===dt&&(c=Fe(a)));let u=new Uint8Array(i+c+a),p=0;Ps(n.code,u,p),p+=i,s!=null&&(o.size===dt&&(Ps(a,u,p),p+=c),u.set(s,p)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return Rt(t,e)}function uw(r){if(r.charAt(0)!=="/")throw new gt('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=nr.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new gt(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new gt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new gt("Incomplete multiaddr");return e}function lw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=nr.getProtocol(e.code);if(t==null)throw new gt(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function R2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:ai(e,t)}var L2=Symbol.for("nodejs.util.inspect.custom"),Yd=Symbol.for("@multiformats/multiaddr"),U2=[53,54,55,56],Zd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function M2(r){if(r==null&&(r="/"),pw(r))return r.getComponents();if(r instanceof Uint8Array)return aw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),uw(r);if(Array.isArray(r))return r;throw new gt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var $l=class r{[Yd]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=M2(e),t.validate!==!1&&K2(this)}get bytes(){return this.#r==null&&(this.#r=cw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=lw(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="";for(let{code:a,name:c,value:u}of this.#e)a===42&&(i=`%${u??""}`),U2.includes(a)&&(t="tcp",o=443,n=`${u??""}${i}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(t="tcp",n=`${u??""}${i}`,e=a===41?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}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=nr.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=nr.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??de(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new mc(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ue($e.decode(`z${n}`),"base58btc"):ue(et.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(nr.getProtocol(e.code).path)return e.value??null;return null}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 Zd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Bn(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(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[L2](){return`Multiaddr(${this.toString()})`}};function K2(r){r.getComponents().forEach(e=>{let t=nr.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var C5=parseInt("0xFFFF",16),T5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var fw=new Map;function pw(r){return!!r?.[Yd]}function Bn(r){return new $l(r)}var Le=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),le=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Se=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),kt=(...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}}),Pe=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function je(...r){function e(o){if(o==null)return!1;let i=o.getComponents();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 W2=le(421),yk=je(W2),Wl=le(54),ql=le(55),Gl=le(56),Qd=le(53),mk=je(Wl,Se(le(421))),gk=je(ql,Se(le(421))),bk=je(Gl,Se(le(421))),wk=je(kt(Qd,Gl,Wl,ql),Se(le(421))),yw=Pe(le(4),Se(le(43))),mw=Pe(Se(le(42)),le(41),Se(le(43))),ey=kt(yw,mw),di=kt(ey,Qd,Wl,ql,Gl),xk=je(kt(ey,Pe(kt(Qd,Gl,Wl,ql),Se(le(421))))),vk=je(yw),_k=je(mw),Sk=je(ey),ty=Pe(di,le(6)),Sc=Pe(di,le(273)),Ak=je(Pe(ty,Se(le(421)))),Ek=je(Sc),ry=Pe(Sc,Le(460),Se(le(421))),zl=Pe(Sc,Le(461),Se(le(421))),q2=kt(ry,zl),Ck=je(ry),Tk=je(zl),Jd=kt(di,ty,Sc,ry,zl),gw=kt(Pe(Jd,Le(477),Se(le(421)))),Ik=je(gw),bw=kt(Pe(Jd,Le(478),Se(le(421))),Pe(Jd,Le(448),Se(le(449)),Le(477),Se(le(421)))),Ok=je(bw),ww=Pe(Sc,Le(280),Se(le(466)),Se(le(466)),Se(le(421))),xw=je(ww),vw=Pe(zl,Le(465),Se(le(466)),Se(le(466)),Se(le(421))),Bk=je(vw),Fl=kt(gw,bw,Pe(ty,Se(le(421))),Pe(q2,Se(le(421))),Pe(di,Se(le(421))),ww,vw,le(421)),_w=je(Fl),G2=Pe(Fl,Le(290),le(421)),Pk=je(G2),z2=kt(Pe(Fl,Le(290),Le(281),Se(le(421))),Pe(Fl,Le(281),Se(le(421))),Pe(Le(281),Se(le(421)))),Sw=je(z2),X2=kt(Pe(di,le(6),Le(480),Se(le(421))),Pe(di,Le(480),Se(le(421)))),kk=je(X2),Z2=Pe(di,kt(Pe(le(6,"443"),Le(480)),Pe(le(6),Le(443)),Pe(le(6),Le(448),Le(480)),Pe(Le(448),Le(480)),Le(448),Le(443)),Se(le(421))),Nk=je(Z2),Y2=kt(Pe(le(777),Se(le(421)))),Dk=je(Y2),J2=kt(Pe(le(400),Se(le(421)))),jk=je(J2);var Nt;(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=()=>li(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Rr((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=>jr(o,r.codec()),r.decode=(o,i)=>Dr(o,r.codec(),i)})(Nt||(Nt={}));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"],ny=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ew="libp2p+webrtc+v1/";var Cw=466,Tw=2*1024*1024,Iw=30*1e3,$s=16*1024;function Q2(r=$s){let e=Fe(r-Fe(r)),t=1+Fe(Object.keys(Nt.Flag).length-1),n=1,o=r-e-t-n,i=Fe(o);return e+t+n+i}var Ow=Q2(),Bw=5e3,Pw=5e3,kw=3e4,oy="/webrtc",Ac="/webrtc-signaling/0.0.1",Nw="/libp2p/webrtc-direct/certificate",Dw="webrtc-direct-certificate-private-key";var jw=12096e5,iy=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))},eC=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var tC=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var rC=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 nC=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var oC=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var iC=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,sC=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Lw=3,aC=[["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",iC]],Uw=[["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 Kw(r){return r?Mw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new oC:typeof navigator<"u"?Mw(navigator.userAgent):lC()}function cC(r){return r!==""&&aC.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 Mw(r){var e=cC(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new nC;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Lw&&(o=Rw(Rw([],o,!0),fC(Lw-o.length),!0)):o=[];var i=o.join("."),s=uC(r),a=sC.exec(r);return a&&a[1]?new rC(t,i,s,a[1]):new eC(t,i,s)}function uC(r){for(var e=0,t=Uw.length;e<t;e++){var n=Uw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function lC(){var r=typeof process<"u"&&process.version;return r?new tC(process.version.slice(1)):null}function fC(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function rt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var sy=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},ay=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Hw=r=>globalThis.DOMException===void 0?new ay(r):new DOMException(r),Vw=r=>{let e=r.reason===void 0?Hw("This operation was aborted."):r.reason;return e instanceof Error?e:Hw(e)};function Ec(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,u=new Promise((p,f)=>{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:m}=e;m.aborted&&f(Vw(m)),a=()=>{f(Vw(m))},m.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,f);return}let d=new sy;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(m){f(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{p(await r)}catch(m){f(m)}})()}).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 $w=Kw(),Cc=$w!=null&&$w.name==="firefox",Xl=async function*(){},Zl=async r=>{};function Fw(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=rt(),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 Ec(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function cy(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Aw.map(e=>({urls:[e]})),r}var Ww=(r=32)=>Ew+[...Array(r)].map(()=>ny.at(Math.floor(Math.random()*ny.length))).join("");var yi=class{log;peerConnection;remoteAddr;timeline;metrics;source=Xl();sink=Zl;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 Yl=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}},Fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Yl(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 Yl(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 uy=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ws(r={}){return pC(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 pC(r,e){e=e??{};let t=e.onEnd,n=new Fs,o,i,s,a=rt(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,T)=>{i=j=>{i=null,n.push(j);try{y(r(n))}catch(L){T(L)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=rt()})}},u=y=>i!=null?i(y):(n.push(y),o),p=y=>(n=new Fs,i!=null?i({error:y}):(n.push({error:y}),o)),f=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})},d=y=>s?o:(s=!0,y!=null?p(y):u({done:!0})),m=()=>(n=new Fs,d(),{done:!0}),g=y=>(d(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:g,push:f,end:d,get readableLength(){return n.size},onEmpty:async y=>{let T=y?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let j,L;T!=null&&(j=new Promise((V,re)=>{L=()=>{re(new uy)},T.addEventListener("abort",L)}));try{await Promise.race([a.promise,j])}finally{L!=null&&T!=null&&T?.removeEventListener("abort",L)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),t!=null&&(t(y),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(y){return w.end(y),t!=null&&(t(y),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var Jl=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 pr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new Jl(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new Jl(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 qw(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 Gw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function zw(r,e){let t=qw(r).return?.();Gw(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var hC=5e3;function ly(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Ql=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=rt(),this.closed=rt(),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??hC,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=Ws({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 Fo(`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);ly(o)&&await o}let n=()=>{zw(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 ve(o):o;let i=this.sendData(o,t);ly(i)&&(this.sendingData=rt(),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 pr(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 pr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await pr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await pr(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();ly(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 rl("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 fy(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 ef=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},qs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},tf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Tc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function rf(r){return r[Symbol.asyncIterator]!=null}function Xw(r,e){if(r.byteLength>e)throw new qs("Message length too long")}var of=r=>{let e=Fe(r),t=lt(e);return Cl(r,t),of.bytes=e,t};of.bytes=0;function Ic(r,e){e=e??{};let t=e.lengthEncoder??of,n=e?.maxDataLength??4194304;function*o(i){Xw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return rf(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ic.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??of,n=e?.maxDataLength??4194304;return Xw(r,n),new ve(t(r.byteLength),r)};var mi;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(mi||(mi={}));var py=r=>{let e=ai(r);return py.bytes=Fe(e),e};py.bytes=0;function gi(r,e){let t=new ve,n=mi.LENGTH,o=-1,i=e?.lengthDecoder??py,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===mi.LENGTH)try{if(o=i(t),o<0)throw new ef("Invalid message length");if(o>a)throw new qs("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=mi.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new tf("Message length length too long");break}throw u}if(n===mi.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=mi.LENGTH}}}return rf(r)?async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Tc("Unexpected end of input")}():function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Tc("Unexpected end of input")}()}gi.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 gi(n,{...e??{},onLength:i=>{t=i}})};var sf=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...t){super(e,...t)}};async function Oc(r,e,t,n){let o=new sf(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let i=n?.errorEvent??"error";return t?.aborted===!0?Promise.reject(o):new Promise((s,a)=>{function c(){dy(t,"abort",f),dy(r,e,u),dy(r,i,p)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(m){c(),a(m);return}c(),s(d)},p=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},f=()=>{c(),a(o)};hy(t,"abort",f),hy(r,e,u),hy(r,i,p)})}function hy(r,e,t){r!=null&&(Zw(r)?r.addEventListener(e,t):r.addListener(e,t))}function dy(r,e,t){r!=null&&(Zw(r)?r.removeEventListener(e,t):r.removeListener(e,t))}function Zw(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var yy=class extends Ql{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 Ec(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=Ws(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Iw,this.maxBufferedAmount=e.maxBufferedAmount??Tw,this.maxMessageSize=(e.maxMessageSize??$s)-Ow,this.receiveFinAck=rt(),this.finAckTimeout=e.closeTimeout??Bw,this.openTimeout=e.openTimeout??Pw,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 Fo("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 gi(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new ve(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 Fo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=fy([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 Oc(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=fy([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Oc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new sl(`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=Nt.encode({message:o}),s=Ic.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(Nt.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(Nt.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await pr(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(Nt.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=Nt.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===Nt.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(Nt.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===Nt.Flag.RESET&&this.reset(),t.flag===Nt.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===Nt.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=Nt.encode({flag:e}),n=Ic.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 Gs(r){let{channel:e,direction:t,handshake:n}=r;return new yy({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`)})}var yo=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??oy,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=Gs({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},log:this.log,...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 my(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},my=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=t.log?.newScope("muxer")??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??oy,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=Gs({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},log:this.log,...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),Fw(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=Xl();sink=Zl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=Gs({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},log:this.log,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var af=globalThis.RTCPeerConnection,cf=globalThis.RTCSessionDescription,Yw=globalThis.RTCIceCandidate;var gy=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=rt(),this.haveNext=rt()}[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=rt(),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=rt(),await pr(this.readNext.promise,t?.signal,t)}};function uf(){return new gy}var lf=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Jw(r,e){let t=uf();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 ve;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:u}=await pr(n.next(),s?.signal);return c===!0?null:u}for(;o.byteLength<s.bytes;){let{value:c,done:u}=await pr(n.next(),s?.signal);if(u===!0)throw new lf("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 ff=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pf=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Bc(r,e={}){let t=Jw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Fe(e.maxDataLength));let n=e?.lengthDecoder??ai,o=e?.lengthEncoder??Cl;return{read:async s=>{let a=-1,c=new ve;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 ff("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new hf("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new pf("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new ve(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new ve(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function df(r,e){let t=Bc(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 or=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var mo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},hr=class extends mo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var yf=class extends mo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var mf=class extends mo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},gf=class extends mo{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 Wt;(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=()=>li(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Rr((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=>jr(o,r.codec()),r.decode=(o,i)=>Dr(o,r.codec(),i)})(Wt||(Wt={}));var bf=async(r,e,t)=>{try{let n=rt();for(mC(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!==Wt.Type.ICE_CANDIDATE)throw new il("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new or("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Yw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new or("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&&wf(r)!=="connected")throw n}};function wf(r){return Cc?r.iceConnectionState:r.connectionState}function mC(r,e){r[Cc?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(wf(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new tl("RTCPeerConnection was closed"));break;default:break}}}async function Qw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:u}){let{circuitAddress:p,targetPeer:f}=ex(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",p);let d=i.getConnections(f),m;d.length===0?(u?.(new or("webrtc:dial-relay")),m=await s.dial(p,{signal:t,onProgress:u})):(u?.(new or("webrtc:reuse-relay-connection")),m=d[0]),u?.(new or("webrtc:open-signaling-stream"));let g=await m.newStream(Ac,{signal:t,runOnLimitedConnection:!0}),w=df(g).pb(Wt),y=new af(r),T=new yo({logger:c},{peerConnection:y,dataChannelOptions:e});try{let j=y.createDataChannel("init");y.onicecandidate=({candidate:U})=>{let Y=JSON.stringify(U?.toJSON()??null);a.trace("initiator sending ICE candidate %o",U),w.write({type:Wt.Type.ICE_CANDIDATE,data:Y},{signal:t}).catch(Q=>{a.error("error sending ICE candidate",Q)})},y.onicecandidateerror=U=>{a.error("initiator ICE candidate error",U)};let L=await y.createOffer().catch(U=>{throw a.error("could not execute createOffer",U),new hr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",L.sdp),u?.(new or("webrtc:send-sdp-offer")),await w.write({type:Wt.Type.SDP_OFFER,data:L.sdp},{signal:t}),await y.setLocalDescription(L).catch(U=>{throw a.error("could not execute setLocalDescription",U),new hr("Failed to set localDescription")}),u?.(new or("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let V=await w.read({signal:t});if(V.type!==Wt.Type.SDP_ANSWER)throw new hr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",V.data);let re=new cf({type:"answer",sdp:V.data});return await y.setRemoteDescription(re).catch(U=>{throw a.error("could not execute setRemoteDescription",U),new hr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),u?.(new or("webrtc:read-ice-candidates")),await bf(y,w,{direction:"initiator",signal:t,log:a,onProgress:u}),a.trace("initiator connected, closing init channel"),j.close(),u?.(new or("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:y,muxerFactory:T}}catch(j){throw a.error("outgoing signaling error",j),y.close(),g.abort(j),j}finally{y.onicecandidate=null,y.onicecandidateerror=null}}var tx=je(_w.matchers[0],Le(290)),xf=class r extends ro{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=>tx.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=>tx.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 rx({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=df(e).pb(Wt);try{r.onicecandidate=({candidate:p})=>{let f=JSON.stringify(p?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),i.write({type:Wt.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(d=>{o.error("error sending ICE candidate",d)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Wt.Type.SDP_OFFER)throw new hr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new cf({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(p=>{throw o.error("could not execute setRemoteDescription",p),new hr("Failed to set remoteDescription")});let u=await r.createAnswer().catch(p=>{throw o.error("could not execute createAnswer",p),new hr("Failed to create answer")});o.trace("recipient send SDP answer %s",u.sdp),await i.write({type:Wt.Type.SDP_ANSWER,data:u.sdp},{signal:t}),await r.setLocalDescription(u).catch(p=>{throw o.error("could not execute setLocalDescription",p),new hr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await bf(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(wf(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=Bn(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var vf=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"})})}[Ju]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[ys]=["@libp2p/transport"];[$g]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Ac,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(Ac),this._started=!1}createListener(e){return new xf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Sw.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 Qw({rtcConfiguration:await cy(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 yi(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 af(await cy(this.init.rtcConfiguration)),i=new yo(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await rx({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new yi(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 ex(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new ke("Destination peer id was missing");return{circuitAddress:Bn(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:jl(e)}}var sX=Xr(ox());var on={};Tt(on,{Any:()=>rn,BaseBlock:()=>it,BaseStringBlock:()=>Dc,BitString:()=>Kr,BmpString:()=>_i,Boolean:()=>wi,CharacterString:()=>Pi,Choice:()=>Zs,Constructed:()=>st,DATE:()=>Kc,DateTime:()=>Vc,Duration:()=>$c,EndOfContent:()=>jc,Enumerated:()=>xi,GeneralString:()=>Bi,GeneralizedTime:()=>ki,GraphicString:()=>Oi,HexBlock:()=>nn,IA5String:()=>Ii,Integer:()=>Rn,Null:()=>Ur,NumericString:()=>Ai,ObjectIdentifier:()=>vi,OctetString:()=>Mr,Primitive:()=>jn,PrintableString:()=>Ei,RawData:()=>vy,RelativeObjectIdentifier:()=>Mc,Repeated:()=>Ni,Sequence:()=>Dt,Set:()=>Mt,TIME:()=>Fc,TeletexString:()=>Ci,TimeOfDay:()=>Hc,UTCTime:()=>wo,UniversalString:()=>Si,Utf8String:()=>yr,ValueBlock:()=>bt,VideotexString:()=>Ti,ViewWriter:()=>Xs,VisibleString:()=>bo,compareSchema:()=>Nn,fromBER:()=>Un,verifySchema:()=>LC});var ge=Xr(kn());function bi(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 go(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 p=a-1;p>=0;p--){let f=Math.pow(2,p*e);u[i-p-1]=Math.floor(o/f),o-=u[i-p-1]*f}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Af(...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 wy(){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=bi(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,bi(i,8)-n}function ix(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=go(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=go(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 sx(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 qt(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 u3=Math.log(2);function Ef(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function _y(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 Ln(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 Xs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return _y(this.items)}},Pc=[new Uint8Array([1])],ax="0123456789",xy="name",cx="valueHexView",EC="isHexOnly",CC="idBlock",TC="tagClass",IC="tagNumber",OC="isConstructed",BC="fromBER",PC="toBER",kC="local",Gt="",Hr=new ArrayBuffer(0),Kf=new Uint8Array(0),Nc="EndOfContent",lx="OCTET STRING",fx="BIT STRING";function nn(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?ge.BufferSourceConverter.toUint8Array(i.valueHex):Kf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ln(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",Hr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ge.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Dn=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=Gt,warnings:n=[],valueBeforeDecode:o=Kf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ge.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ge.Convert.ToHex(this.valueBeforeDecodeView)}}};Dn.NAME="baseBlock";var bt=class extends Dn{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'")}};bt.NAME="valueBlock";var Cf=class extends nn(Dn){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?ge.BufferSourceConverter.toUint8Array(e.valueHex):Kf,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",Hr}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=go(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=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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),p=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===p){p+=255;let d=new Uint8Array(p);for(let m=0;m<u.length;m++)d[m]=u[m];u=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,u[c-1]=i[c]&127;let f=new Uint8Array(c);for(let d=0;d<c;d++)f[d]=u[d];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=bi(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}}};Cf.NAME="identificationBlock";var Tf=class extends Dn{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=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=bi(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=go(this.length,8);if(o.byteLength>127)return this.error="Too big length",Hr;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}}};Tf.NAME="lengthBlock";var J={},it=class extends Dn{constructor({name:e=Gt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Cf(o),this.lenBlock=new Tf(o),this.valueBlock=i?new i(o):new bt(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 Xs;t||px(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?Hr: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():ge.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ge.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 sx(t,n)}};it.NAME="BaseBlock";function px(r){var e;if(r instanceof J.Constructed)for(let t of r.valueBlock.value)px(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var Dc=class extends it{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Gt,...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}'`}};Dc.NAME="BaseStringBlock";var If=class extends nn(bt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};If.NAME="PrimitiveValueBlock";var hx,jn=class extends it{constructor(e={}){super(e,If),this.idBlock.isConstructed=!1}};hx=jn;J.Primitive=hx;jn.NAME="PRIMITIVE";function NC(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 Ys(r,e=0,t=r.length){let n=e,o=new it({},bt),i=new Dn;if(!Ln(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=it;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=J.EndOfContent;break;case 1:c=J.Boolean;break;case 2:c=J.Integer;break;case 3:c=J.BitString;break;case 4:c=J.OctetString;break;case 5:c=J.Null;break;case 6:c=J.ObjectIdentifier;break;case 10:c=J.Enumerated;break;case 12:c=J.Utf8String;break;case 13:c=J.RelativeObjectIdentifier;break;case 14:c=J.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=J.Sequence;break;case 17:c=J.Set;break;case 18:c=J.NumericString;break;case 19:c=J.PrintableString;break;case 20:c=J.TeletexString;break;case 21:c=J.VideotexString;break;case 22:c=J.IA5String;break;case 23:c=J.UTCTime;break;case 24:c=J.GeneralizedTime;break;case 25:c=J.GraphicString;break;case 26:c=J.VisibleString;break;case 27:c=J.GeneralString;break;case 28:c=J.UniversalString;break;case 29:c=J.CharacterString;break;case 30:c=J.BmpString;break;case 31:c=J.DATE;break;case 32:c=J.TimeOfDay;break;case 33:c=J.DateTime;break;case 34:c=J.Duration;break;default:{let u=o.idBlock.isConstructed?new J.Constructed:new J.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?J.Constructed:J.Primitive}return o=NC(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 Un(r){if(!r.byteLength){let e=new it({},bt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ys(ge.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function DC(r,e){return r?1:e}var tn=class extends bt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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(;DC(this.isIndefiniteForm,n)>0;){let s=Ys(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===Nc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Nc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Xs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Hr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};tn.NAME="ConstructedValueBlock";var dx,st=class extends it{constructor(e={}){super(e,tn),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} :`}};Xb=st;Q.Constructed=Xb;st.NAME="CONSTRUCTED";var bf=class extends ht{fromBER(e,t,n){return t}toBER(e){return Rr}};bf.override="EndOfContentValueBlock";var Zb,Sc=class extends Qe{constructor(e={}){super(e,bf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Zb=Sc;Q.EndOfContent=Zb;Sc.NAME=vc;var Yb,kr=class extends Qe{constructor(e={}){super(e,ht),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}`}};Yb=kr;Q.Null=Yb;kr.NAME="NULL";var xf=class extends Qr(ht){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=ye.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);return Cn(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,ry.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};xf.NAME="BooleanValueBlock";var Jb,ni=class extends Qe{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,xf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Jb=ni;Q.Boolean=Jb;ni.NAME="BOOLEAN";var vf=class extends Qr(Yr){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=Yr.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===vc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Wb)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?Yr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};vf.NAME="OctetStringValueBlock";var sy,Dr=class extends Qe{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},vf),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=Ds(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 st.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ye.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 sy&&e.push(t.valueBlock.valueHexView);return ye.BufferSourceConverter.concat(e)}};sy=Dr;Q.OctetString=sy;Dr.NAME=Wb;var _f=class extends Qr(Yr){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=Yr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===vc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Gb)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return o}let i=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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=Ds(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 Yr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Rr;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}}};_f.NAME="BitStringValueBlock";var Qb,jr=class extends Qe{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},_f),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 st.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}`}}};Qb=jr;Q.BitString=Qb;jr.NAME=Gb;var ex;function pC(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,l=0,f=c<s?s:c,p=0;for(let y=f;y>=0;y--,p++){switch(!0){case p<a.length:l=i[s-p]+a[c-p]+t[0];break;default:l=i[s-p]+t[0]}switch(t[0]=l/10,!0){case p>=i.length:i=df(new Uint8Array([l%10]),i);break;default:i[s-p]=l%10}}return t[0]>0&&(i=df(t,i)),i}function Fb(r){if(r>=bc.length)for(let e=bc.length;e<=r;e++){let t=new Uint8Array([0]),n=bc[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=df(t,n)),bc.push(n)}return bc[r]}function hC(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,l,f=0;for(let p=c;p>=0;p--,f++)switch(l=i[s-f]-a[c-f]-t,!0){case l<0:t=1,i[s-f]=l+10;break;default:t=0,i[s-f]=l}if(t>0)for(let p=s-c+1;p>=0;p--,f++)if(l=i[s-f]-t,l<0)t=1,i[s-f]=l+10;else{t=0,i[s-f]=l;break}return i.slice()}var Ac=class extends Qr(ht){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=ry.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(Kb(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 l=0;l<8;l++){if((o&1)===1)switch(n){case e:t=hC(Fb(n),t),s="-";break;default:t=pC(t,Fb(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Vb.charAt(t[c]));return a===!1&&(s+=Vb.charAt(0)),s}};ex=Ac;Ac.NAME="IntegerValueBlock";Object.defineProperty(ex.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var xc,En=class extends Qe{constructor(e={}){super(e,Ac),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return yf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){yf();let t=BigInt(e),n=new Ns,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ye.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${ye.Convert.ToHex(a)}`)+t,f=ye.BufferSourceConverter.toUint8Array(ye.Convert.FromHex(l.toString(16)));f[0]|=128,n.write(f)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new xc({valueHex:n.final()})}convertToDER(){let e=new xc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new xc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};xc=En;Q.Integer=xc;En.NAME="INTEGER";var tx,oi=class extends En{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};tx=oi;Q.Enumerated=tx;oi.NAME="ENUMERATED";var Ec=class extends Qr(ht){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=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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=ri(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){yf();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=io(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Rr;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=ye.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}}};Ec.NAME="sidBlock";var Sf=class extends ht{constructor({value:e=Vt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Ec;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,Rr;t.push(o)}return iy(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 Ec;if(o>Number.MAX_SAFE_INTEGER){yf();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}};Sf.NAME="ObjectIdentifierValueBlock";var rx,ii=class extends Qe{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Sf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};rx=ii;Q.ObjectIdentifier=rx;ii.NAME="OBJECT IDENTIFIER";var Cc=class extends Qr(Sn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ye.BufferSourceConverter.toUint8Array(e);if(!Cn(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=ri(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=io(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Rr;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=ye.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Cc.NAME="relativeSidBlock";var Af=class extends ht{constructor({value:e=Vt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Cc;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,Rr;n.push(i)}return iy(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 Cc;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}};Af.NAME="RelativeObjectIdentifierValueBlock";var nx,Tc=class extends Qe{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Af),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};nx=Tc;Q.RelativeObjectIdentifier=nx;Tc.NAME="RelativeObjectIdentifier";var ox,$t=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};ox=$t;Q.Sequence=ox;$t.NAME="SEQUENCE";var ix,Ft=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};ix=Ft;Q.Set=ix;Ft.NAME="SET";var Ef=class extends Qr(ht){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Vt}toJSON(){return{...super.toJSON(),value:this.value}}};Ef.NAME="StringValueBlock";var Cf=class extends Ef{};Cf.NAME="SimpleStringValueBlock";var jt=class extends _c{constructor({...e}={}){super(e,Cf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ye.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}};jt.NAME="SIMPLE STRING";var Tf=class extends jt{fromBuffer(e){this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ye.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ye.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Tf.NAME="Utf8StringValueBlock";var sx,fr=class extends Tf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};sx=fr;Q.Utf8String=sx;fr.NAME="UTF8String";var If=class extends jt{fromBuffer(e){this.valueBlock.value=ye.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf16String(e))}};If.NAME="BmpStringValueBlock";var ax,si=class extends If{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};ax=si;Q.BmpString=ax;si.NAME="BMPString";var Of=class extends jt{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=io(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}};Of.NAME="UniversalStringValueBlock";var cx,ai=class extends Of{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};cx=ai;Q.UniversalString=cx;ai.NAME="UniversalString";var ux,ci=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};ux=ci;Q.NumericString=ux;ci.NAME="NumericString";var lx,ui=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};lx=ui;Q.PrintableString=lx;ui.NAME="PrintableString";var fx,li=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};fx=li;Q.TeletexString=fx;li.NAME="TeletexString";var px,fi=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};px=fi;Q.VideotexString=px;fi.NAME="VideotexString";var hx,pi=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};hx=pi;Q.IA5String=hx;pi.NAME="IA5String";var dx,hi=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};dx=hi;Q.GraphicString=dx;hi.NAME="GraphicString";var yx,ao=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};yx=ao;Q.VisibleString=yx;ao.NAME="VisibleString";var mx,di=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};mx=di;Q.GeneralString=mx;di.NAME="GeneralString";var gx,yi=class extends jt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};gx=yi;Q.CharacterString=gx;yi.NAME="CharacterString";var wx,co=class extends ao{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,ye.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]=Ht(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ht(this.month,2),t[2]=Ht(this.day,2),t[3]=Ht(this.hour,2),t[4]=Ht(this.minute,2),t[5]=Ht(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}}};wx=co;Q.UTCTime=wx;co.NAME="UTCTime";var bx,mi=class extends co{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("+"),m="";if(y===-1&&(y=n.indexOf("-"),p=-1),y!==-1){if(m=n.substring(y+1),n=n.substring(0,y),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let x=parseInt(m.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*x,m.length===4){if(x=parseInt(m.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=p*x}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let p=new Number(`0${n.substring(l)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,l)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,l!==-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,l!==-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,l!==-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,l!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let f=s.exec(o);if(f===null)throw new Error("Wrong input string for conversion");for(let p=1;p<f.length;p++)switch(p){case 1:this.year=parseInt(f[p],10);break;case 2:this.month=parseInt(f[p],10);break;case 3:this.day=parseInt(f[p],10);break;case 4:this.hour=parseInt(f[p],10)+a;break;case 5:this.minute=parseInt(f[p],10)+c;break;case 6:this.second=parseInt(f[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(Ht(this.year,4)),t.push(Ht(this.month,2)),t.push(Ht(this.day,2)),t.push(Ht(this.hour,2)),t.push(Ht(this.minute,2)),t.push(Ht(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ht(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};bx=mi;Q.GeneralizedTime=bx;mi.NAME="GeneralizedTime";var xx,Ic=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};xx=Ic;Q.DATE=xx;Ic.NAME="DATE";var vx,Oc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};vx=Oc;Q.TimeOfDay=vx;Oc.NAME="TimeOfDay";var _x,Pc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};_x=Pc;Q.DateTime=_x;Pc.NAME="DateTime";var Sx,Bc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Sx=Bc;Q.Duration=Sx;Bc.NAME="Duration";var Ax,Nc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Ax=Nc;Q.TIME=Ax;Nc.NAME="TIME";var Jr=class{constructor({name:e=Vt,optional:t=!1}={}){this.name=e,this.optional=t}},ks=class extends Jr{constructor({value:e=[],...t}={}){super(t),this.value=e}},gi=class extends Jr{constructor({value:e=new Jr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},oy=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Pf}={}){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ye.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function so(r,e,t){if(t instanceof ks){for(let i of t.value)if(so(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(ny)&&(i.name=t.name),i}}if(t instanceof Jr)return t.hasOwnProperty(ny)&&(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(!(nC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(aC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(cC 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(oC)===!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(iC)===!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(sC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(rC 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(!($b 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,Vt),t.name&&(r[t.name]=e)),t instanceof Q.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof gi&&(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 l=0;l<t.valueBlock.value.length;l++)c=c&&(t.valueBlock.value[l].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Vt),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 l={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,Vt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof gi){if(s=so(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,Vt),t.name&&delete r[t.name]),s;if(ny in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};uC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?l=e:l=r,typeof l[t.valueBlock.value[0].name]>"u"&&(l[t.valueBlock.value[0].name]=[]),l[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=so(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,Vt),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,Vt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&$b in e.valueBlock){let i=Ds(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,Vt),t.name&&(delete r[t.name],s.name=t.name)),s}return so(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function dC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Ds(ye.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:so(t.result,t.result,e)}var _;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(_||(_={}));var h;(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"})(h||(h={}));var ay=$r(_n()),tn=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(ay.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=ay.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof jr))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 jr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new jr({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 cy=$r(_n()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):cy.BufferSourceConverter.isBufferSource(e)?this.buffer=cy.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Dr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Dr({valueHex:this.buffer})}toSchema(e){return new Dr({name:e})}};var yC={fromASN:r=>r instanceof kr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new kr;let e=Tn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},mC={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new En({value:+r})},gC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new oi({value:r})},me={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new En({valueHex:r})};var wC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new jr({valueHex:r})},bC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ii({value:r})},xC={fromASN:r=>r.valueBlock.value,toASN:r=>new ni({value:r})},js={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Dr({valueHex:r})},Ex={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function pr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var uy=pr(fr),vC=pr(si),_C=pr(ai),SC=pr(ci),AC=pr(ui),EC=pr(li),CC=pr(fi),TC=pr(pi),IC=pr(hi),OC=pr(ao),PC=pr(di),BC=pr(yi),NC={fromASN:r=>r.toDate(),toASN:r=>new co({valueDate:r})},kC={fromASN:r=>r.toDate(),toASN:r=>new mi({valueDate:r})},DC={fromASN:()=>null,toASN:()=>new kr};function Rs(r){switch(r){case h.Any:return yC;case h.BitString:return wC;case h.BmpString:return vC;case h.Boolean:return xC;case h.CharacterString:return BC;case h.Enumerated:return gC;case h.GeneralString:return PC;case h.GeneralizedTime:return kC;case h.GraphicString:return IC;case h.IA5String:return TC;case h.Integer:return mC;case h.Null:return DC;case h.NumericString:return SC;case h.ObjectIdentifier:return bC;case h.OctetString:return js;case h.PrintableString:return AC;case h.TeletexString:return EC;case h.UTCTime:return NC;case h.UniversalString:return _C;case h.Utf8String:return uy;case h.VideotexString:return CC;case h.VisibleString:return OC;default:return null}}function hr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:hr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function fy(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:fy(t)}return!1}function Cx(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 Bf=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:_.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 f=h[s.type],p=en[f];if(!p)throw new Error(`Cannot get ASN1 class by name '${f}'`);c=new p({name:a})}else hr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===_.Choice?c=new Jr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Jr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let f=s.repeated==="set"?Ft:$t;c=new f({name:"",value:[new gi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||hr(s.type)){let f=s.repeated?st:An;o.push(new f({name:a,optional:l,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let f=!!s.repeated,p=f?c:this.get(s.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,o.push(new st({name:f?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new st({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case _.Sequence:return new $t({value:o,name:""});case _.Set:return new Ft({value:o,name:""});case _.Choice:return new ks({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 Rt=new Bf;var A=r=>e=>{let t;Rt.has(e)?t=Rt.get(e):(t=Rt.createDefault(e),Rt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;Rt.has(e.constructor)?n=Rt.get(e.constructor):(n=Rt.createDefault(e.constructor),Rt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Rs(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 kc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Dc=class{static parse(e,t){let n=Tn(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(hr(t))return new t().fromASN(e);let o=Rt.get(t);Rt.cache(t);let i=o.schema;if(e.constructor===st&&o.type!==_.Choice){i=new st({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=so({},e,i);if(!s.verified)throw new kc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(fy(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 l=Rs(c);if(!l)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,f=>l.fromASN(f))}else return t.from(e.valueBlock.value,l=>this.fromASN(l,c))}for(let c in o.items){let l=s.result[c];if(!l)continue;let f=o.items[c],p=f.type;if(typeof p=="number"||hr(p)){let y=(n=f.converter)!==null&&n!==void 0?n:hr(p)?new p:null;if(!y)throw new Error("Converter is empty");if(f.repeated)if(f.implicit){let m=f.repeated==="sequence"?$t:Ft,x=new m;x.valueBlock=l.valueBlock;let v=Tn(x.toBER(!1));if(v.offset===-1)throw new Error(`Cannot parse the child item. ${v.result.error}`);if(!("value"in v.result.valueBlock&&Array.isArray(v.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let d=v.result.valueBlock.value;a[c]=Array.from(d,I=>y.fromASN(I))}else a[c]=Array.from(l,m=>y.fromASN(m));else{let m=l;if(f.implicit){let x;if(hr(p))x=new p().toSchema("");else{let v=h[p],d=en[v];if(!d)throw new Error(`Cannot get '${v}' class from asn1js module`);x=new d}x.valueBlock=m.valueBlock,m=Tn(x.toBER(!1)).result}a[c]=y.fromASN(m)}}else if(f.repeated){if(!Array.isArray(l))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");a[c]=Array.from(l,y=>this.fromASN(y,p))}else a[c]=this.fromASN(l,p)}return a}catch(o){throw o instanceof kc&&o.schemas.push(t.name),o}}};var jc=class r{static serialize(e){return e instanceof Qe?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&hr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Rt.get(t);Rt.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=Rs(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"&&Cx(this.serialize(a.defaultValue),this.serialize(c)))continue;let l=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||hr(a.type))){let f={};f.valueHex=l instanceof kr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new An({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...f}))}else o.push(new st({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new st({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else a.repeated?o=o.concat(l):o.push(l)}let i;switch(n.type){case _.Sequence:i=new $t({value:o});break;case _.Set:i=new Ft({value:o});break;case _.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 ${h[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,l=>s.toASN(l)),c=e.repeated==="sequence"?$t:Ft;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"?$t:Ft;i=new a({value:s})}else i=this.toASN(o);return i}};var oe=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var py=$r(_n());var W=class r{static serialize(e){return jc.serialize(e)}static parse(e,t){return Dc.parse(e,t)}static toString(e){let t=py.BufferSourceConverter.isBufferSource(e)?py.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Tn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function w(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 Tx=$r(_n()),Rc=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,l)=>c+(l.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(Tx.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 Ix=$r(_n()),hy,dy,yy,et=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};w([u({type:h.TeletexString})],et.prototype,"teletexString",void 0);w([u({type:h.PrintableString})],et.prototype,"printableString",void 0);w([u({type:h.UniversalString})],et.prototype,"universalString",void 0);w([u({type:h.Utf8String})],et.prototype,"utf8String",void 0);w([u({type:h.BmpString})],et.prototype,"bmpString",void 0);et=w([A({type:_.Choice})],et);var Ls=class extends et{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Ix.Convert.ToHex(this.anyValue):super.toString())}};w([u({type:h.IA5String})],Ls.prototype,"ia5String",void 0);w([u({type:h.Any})],Ls.prototype,"anyValue",void 0);Ls=w([A({type:_.Choice})],Ls);var wi=class{constructor(e={}){this.type="",this.value=new Ls,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],wi.prototype,"type",void 0);w([u({type:Ls})],wi.prototype,"value",void 0);var uo=hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};uo=hy=w([A({type:_.Set,itemType:wi})],uo);var my=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};my=dy=w([A({type:_.Sequence,itemType:uo})],my);var Pe=yy=class extends my{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};Pe=yy=w([A({type:_.Sequence})],Pe);var jC={fromASN:r=>Rc.toString(js.fromASN(r)),toASN:r=>js.toASN(Rc.fromString(r))},lo=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],lo.prototype,"typeId",void 0);w([u({type:h.Any,context:0})],lo.prototype,"value",void 0);var Lc=class{constructor(e={}){this.partyName=new et,Object.assign(this,e)}};w([u({type:et,optional:!0,context:0,implicit:!0})],Lc.prototype,"nameAssigner",void 0);w([u({type:et,context:1,implicit:!0})],Lc.prototype,"partyName",void 0);var ue=class{constructor(e={}){Object.assign(this,e)}};w([u({type:lo,context:0,implicit:!0})],ue.prototype,"otherName",void 0);w([u({type:h.IA5String,context:1,implicit:!0})],ue.prototype,"rfc822Name",void 0);w([u({type:h.IA5String,context:2,implicit:!0})],ue.prototype,"dNSName",void 0);w([u({type:h.Any,context:3,implicit:!0})],ue.prototype,"x400Address",void 0);w([u({type:Pe,context:4,implicit:!1})],ue.prototype,"directoryName",void 0);w([u({type:Lc,context:5})],ue.prototype,"ediPartyName",void 0);w([u({type:h.IA5String,context:6,implicit:!0})],ue.prototype,"uniformResourceIdentifier",void 0);w([u({type:h.OctetString,context:7,implicit:!0,converter:jC})],ue.prototype,"iPAddress",void 0);w([u({type:h.ObjectIdentifier,context:8,implicit:!0})],ue.prototype,"registeredID",void 0);ue=w([A({type:_.Choice})],ue);var fo="1.3.6.1.5.5.7",po=`${fo}.1`,Ox=`${fo}.2`,bi=`${fo}.3`,Nf=`${fo}.48`,G3=`${Ox}.1`,q3=`${Ox}.2`,gy=`${Nf}.1`,wy=`${Nf}.2`,by=`${Nf}.3`,xy=`${Nf}.5`,pe="2.5.29";var vy,kf=`${po}.1`,In=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ue,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],In.prototype,"accessMethod",void 0);w([u({type:ue})],In.prototype,"accessLocation",void 0);var xi=vy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,vy.prototype)}};xi=vy=w([A({type:_.Sequence,itemType:In})],xi);var Df=`${pe}.35`,vi=class extends ae{},rn=class{constructor(e={}){e&&Object.assign(this,e)}};w([u({type:vi,context:0,optional:!0,implicit:!0})],rn.prototype,"keyIdentifier",void 0);w([u({type:ue,context:1,optional:!0,implicit:!0,repeated:"sequence"})],rn.prototype,"authorityCertIssuer",void 0);w([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:me})],rn.prototype,"authorityCertSerialNumber",void 0);var jf=`${pe}.19`,_i=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};w([u({type:h.Boolean,defaultValue:!1})],_i.prototype,"cA",void 0);w([u({type:h.Integer,optional:!0})],_i.prototype,"pathLenConstraint",void 0);var _y,Ke=_y=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,_y.prototype)}};Ke=_y=w([A({type:_.Sequence,itemType:ue})],Ke);var Sy,RC=`${pe}.29`,Px=Sy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};Px=Sy=w([A({type:_.Sequence})],Px);var Ay,Lf=`${pe}.32`,ED=`${Lf}.0`,On=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};w([u({type:h.IA5String})],On.prototype,"ia5String",void 0);w([u({type:h.VisibleString})],On.prototype,"visibleString",void 0);w([u({type:h.BmpString})],On.prototype,"bmpString",void 0);w([u({type:h.Utf8String})],On.prototype,"utf8String",void 0);On=w([A({type:_.Choice})],On);var Uc=class{constructor(e={}){this.organization=new On,this.noticeNumbers=[],Object.assign(this,e)}};w([u({type:On})],Uc.prototype,"organization",void 0);w([u({type:h.Integer,repeated:"sequence"})],Uc.prototype,"noticeNumbers",void 0);var Mc=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Uc,optional:!0})],Mc.prototype,"noticeRef",void 0);w([u({type:On,optional:!0})],Mc.prototype,"explicitText",void 0);var Rf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.IA5String})],Rf.prototype,"cPSuri",void 0);w([u({type:Mc})],Rf.prototype,"userNotice",void 0);Rf=w([A({type:_.Choice})],Rf);var Kc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Kc.prototype,"policyQualifierId",void 0);w([u({type:h.Any})],Kc.prototype,"qualifier",void 0);var Si=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Si.prototype,"policyIdentifier",void 0);w([u({type:Kc,repeated:"sequence",optional:!0})],Si.prototype,"policyQualifiers",void 0);var Hc=Ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};Hc=Ay=w([A({type:_.Sequence,itemType:Si})],Hc);var kD=`${pe}.20`,Vc=class{constructor(e=0){this.value=e}};w([u({type:h.Integer})],Vc.prototype,"value",void 0);Vc=w([A({type:_.Choice})],Vc);var KD=`${pe}.27`,Bx=class extends Vc{};Bx=w([A({type:_.Choice})],Bx);var Ey,Uf=`${pe}.31`,Lr;(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"})(Lr||(Lr={}));var $c=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&Lr.aACompromise&&e.push("aACompromise"),t&Lr.affiliationChanged&&e.push("affiliationChanged"),t&Lr.cACompromise&&e.push("cACompromise"),t&Lr.certificateHold&&e.push("certificateHold"),t&Lr.cessationOfOperation&&e.push("cessationOfOperation"),t&Lr.keyCompromise&&e.push("keyCompromise"),t&Lr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Lr.superseded&&e.push("superseded"),t&Lr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Pn=class{constructor(e={}){Object.assign(this,e)}};w([u({type:ue,context:0,repeated:"sequence",implicit:!0})],Pn.prototype,"fullName",void 0);w([u({type:uo,context:1,implicit:!0})],Pn.prototype,"nameRelativeToCRLIssuer",void 0);Pn=w([A({type:_.Choice})],Pn);var nn=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Pn,context:0,optional:!0})],nn.prototype,"distributionPoint",void 0);w([u({type:$c,context:1,optional:!0,implicit:!0})],nn.prototype,"reasons",void 0);w([u({type:ue,context:2,optional:!0,repeated:"sequence",implicit:!0})],nn.prototype,"cRLIssuer",void 0);var ho=Ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};ho=Ey=w([A({type:_.Sequence,itemType:nn})],ho);var Cy,tj=`${pe}.46`,Nx=Cy=class extends ho{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};Nx=Cy=w([A({type:_.Sequence,itemType:nn})],Nx);var uj=`${pe}.28`,rr=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};rr.ONLY=!1;w([u({type:Pn,context:0,optional:!0})],rr.prototype,"distributionPoint",void 0);w([u({type:h.Boolean,context:1,defaultValue:rr.ONLY,implicit:!0})],rr.prototype,"onlyContainsUserCerts",void 0);w([u({type:h.Boolean,context:2,defaultValue:rr.ONLY,implicit:!0})],rr.prototype,"onlyContainsCACerts",void 0);w([u({type:$c,context:3,optional:!0,implicit:!0})],rr.prototype,"onlySomeReasons",void 0);w([u({type:h.Boolean,context:4,defaultValue:rr.ONLY,implicit:!0})],rr.prototype,"indirectCRL",void 0);w([u({type:h.Boolean,context:5,defaultValue:rr.ONLY,implicit:!0})],rr.prototype,"onlyContainsAttributeCerts",void 0);var kx=`${pe}.21`,Fc;(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"})(Fc||(Fc={}));var Wc=class{constructor(e=Fc.unspecified){this.reason=Fc.unspecified,this.reason=e}toJSON(){return Fc[this.reason]}toString(){return this.toJSON()}};w([u({type:h.Enumerated})],Wc.prototype,"reason",void 0);Wc=w([A({type:_.Choice})],Wc);var Ty,Mf=`${pe}.37`,Gc=Ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};Gc=Ty=w([A({type:_.Sequence,itemType:h.ObjectIdentifier})],Gc);var xj=`${Mf}.0`,Dx=`${bi}.1`,jx=`${bi}.2`,Rx=`${bi}.3`,Lx=`${bi}.4`,Ux=`${bi}.8`,Mx=`${bi}.9`;var Ej=`${pe}.54`,Iy=class{constructor(e=new ArrayBuffer(0)){this.value=e}};w([u({type:h.Integer,converter:me})],Iy.prototype,"value",void 0);Iy=w([A({type:_.Choice})],Iy);var Kx=`${pe}.24`,qc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};w([u({type:h.GeneralizedTime})],qc.prototype,"value",void 0);qc=w([A({type:_.Choice})],qc);var Oy,Py=`${pe}.18`,Hx=Oy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,Oy.prototype)}};Hx=Oy=w([A({type:_.Sequence})],Hx);var Kf=`${pe}.15`,Ur;(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"})(Ur||(Ur={}));var Us=class extends tn{toJSON(){let e=this.toNumber(),t=[];return e&Ur.cRLSign&&t.push("crlSign"),e&Ur.dataEncipherment&&t.push("dataEncipherment"),e&Ur.decipherOnly&&t.push("decipherOnly"),e&Ur.digitalSignature&&t.push("digitalSignature"),e&Ur.encipherOnly&&t.push("encipherOnly"),e&Ur.keyAgreement&&t.push("keyAgreement"),e&Ur.keyCertSign&&t.push("keyCertSign"),e&Ur.keyEncipherment&&t.push("keyEncipherment"),e&Ur.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var By,Gj=`${pe}.30`,Ms=class{constructor(e={}){this.base=new ue,this.minimum=0,Object.assign(this,e)}};w([u({type:ue})],Ms.prototype,"base",void 0);w([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Ms.prototype,"minimum",void 0);w([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Ms.prototype,"maximum",void 0);var Hf=By=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,By.prototype)}};Hf=By=w([A({type:_.Sequence,itemType:Ms})],Hf);var Vf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Hf,context:0,optional:!0,implicit:!0})],Vf.prototype,"permittedSubtrees",void 0);w([u({type:Hf,context:1,optional:!0,implicit:!0})],Vf.prototype,"excludedSubtrees",void 0);var Jj=`${pe}.36`,$f=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:me})],$f.prototype,"requireExplicitPolicy",void 0);w([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:me})],$f.prototype,"inhibitPolicyMapping",void 0);var Ny,nR=`${pe}.33`,zc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],zc.prototype,"issuerDomainPolicy",void 0);w([u({type:h.ObjectIdentifier})],zc.prototype,"subjectDomainPolicy",void 0);var Vx=Ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};Vx=Ny=w([A({type:_.Sequence,itemType:zc})],Vx);var ky,Dy=`${pe}.17`,Ff=ky=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Ff=ky=w([A({type:_.Sequence})],Ff);var dt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],dt.prototype,"type",void 0);w([u({type:h.Any,repeated:"set"})],dt.prototype,"values",void 0);var jy,bR=`${pe}.9`,$x=jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};$x=jy=w([A({type:_.Sequence,itemType:dt})],$x);var Ry=`${pe}.14`,Wt=class extends vi{};var IR=`${pe}.16`,Wf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],Wf.prototype,"notBefore",void 0);w([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],Wf.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 Gf=class extends tn{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(", ")}]`}},qf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Gf,Object.assign(this,e)}};w([u({type:h.GeneralString})],qf.prototype,"entrustVers",void 0);w([u({type:Gf})],qf.prototype,"entrustInfoFlags",void 0);var Ly,LR=`${po}.11`,Fx=Ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Fx=Ly=w([A({type:_.Sequence,itemType:In})],Fx);var Wx=$r(_n()),H=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&Wx.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};w([u({type:h.ObjectIdentifier})],H.prototype,"algorithm",void 0);w([u({type:h.Any,optional:!0})],H.prototype,"parameters",void 0);var yt=class{constructor(e={}){this.algorithm=new H,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:H})],yt.prototype,"algorithm",void 0);w([u({type:h.BitString})],yt.prototype,"subjectPublicKey",void 0);var Ge=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}};w([u({type:h.UTCTime})],Ge.prototype,"utcTime",void 0);w([u({type:h.GeneralizedTime})],Ge.prototype,"generalTime",void 0);Ge=w([A({type:_.Choice})],Ge);var Bn=class{constructor(e){this.notBefore=new Ge(new Date),this.notAfter=new Ge(new Date),e&&(this.notBefore=new Ge(e.notBefore),this.notAfter=new Ge(e.notAfter))}};w([u({type:Ge})],Bn.prototype,"notBefore",void 0);w([u({type:Ge})],Bn.prototype,"notAfter",void 0);var Uy,mt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};mt.CRITICAL=!1;w([u({type:h.ObjectIdentifier})],mt.prototype,"extnID",void 0);w([u({type:h.Boolean,defaultValue:mt.CRITICAL})],mt.prototype,"critical",void 0);w([u({type:ae})],mt.prototype,"extnValue",void 0);var nr=Uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Uy.prototype)}};nr=Uy=w([A({type:_.Sequence,itemType:mt})],nr);var on;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(on||(on={}));var gt=class{constructor(e={}){this.version=on.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new H,this.issuer=new Pe,this.validity=new Bn,this.subject=new Pe,this.subjectPublicKeyInfo=new yt,Object.assign(this,e)}};w([u({type:h.Integer,context:0,defaultValue:on.v1})],gt.prototype,"version",void 0);w([u({type:h.Integer,converter:me})],gt.prototype,"serialNumber",void 0);w([u({type:H})],gt.prototype,"signature",void 0);w([u({type:Pe})],gt.prototype,"issuer",void 0);w([u({type:Bn})],gt.prototype,"validity",void 0);w([u({type:Pe})],gt.prototype,"subject",void 0);w([u({type:yt})],gt.prototype,"subjectPublicKeyInfo",void 0);w([u({type:h.BitString,context:1,implicit:!0,optional:!0})],gt.prototype,"issuerUniqueID",void 0);w([u({type:h.BitString,context:2,implicit:!0,optional:!0})],gt.prototype,"subjectUniqueID",void 0);w([u({type:nr,context:3,optional:!0})],gt.prototype,"extensions",void 0);var dr=class{constructor(e={}){this.tbsCertificate=new gt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:gt})],dr.prototype,"tbsCertificate",void 0);w([u({type:H})],dr.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],dr.prototype,"signatureValue",void 0);var Ai=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ge,Object.assign(this,e)}};w([u({type:h.Integer,converter:me})],Ai.prototype,"userCertificate",void 0);w([u({type:Ge})],Ai.prototype,"revocationDate",void 0);w([u({type:mt,optional:!0,repeated:"sequence"})],Ai.prototype,"crlEntryExtensions",void 0);var or=class{constructor(e={}){this.signature=new H,this.issuer=new Pe,this.thisUpdate=new Ge,Object.assign(this,e)}};w([u({type:h.Integer,optional:!0})],or.prototype,"version",void 0);w([u({type:H})],or.prototype,"signature",void 0);w([u({type:Pe})],or.prototype,"issuer",void 0);w([u({type:Ge})],or.prototype,"thisUpdate",void 0);w([u({type:Ge,optional:!0})],or.prototype,"nextUpdate",void 0);w([u({type:Ai,repeated:"sequence",optional:!0})],or.prototype,"revokedCertificates",void 0);w([u({type:mt,optional:!0,context:0,repeated:"sequence"})],or.prototype,"crlExtensions",void 0);var Ei=class{constructor(e={}){this.tbsCertList=new or,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:or})],Ei.prototype,"tbsCertList",void 0);w([u({type:H})],Ei.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],Ei.prototype,"signature",void 0);var V=$r(_n());function C(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 Mr=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:Pe})],Mr.prototype,"issuer",void 0);C([u({type:h.Integer,converter:me})],Mr.prototype,"serialNumber",void 0);var Ci=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Wt,context:0,implicit:!0})],Ci.prototype,"subjectKeyIdentifier",void 0);C([u({type:Mr})],Ci.prototype,"issuerAndSerialNumber",void 0);Ci=C([A({type:_.Choice})],Ci);var wt;(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"})(wt||(wt={}));var Ti=class extends H{};Ti=C([A({type:_.Sequence})],Ti);var Zc=class extends H{};Zc=C([A({type:_.Sequence})],Zc);var Gt=class extends H{};Gt=C([A({type:_.Sequence})],Gt);var Yc=class extends H{};Yc=C([A({type:_.Sequence})],Yc);var qx=class extends H{};qx=C([A({type:_.Sequence})],qx);var zf=class extends H{};zf=C([A({type:_.Sequence})],zf);var Kr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Kr.prototype,"attrType",void 0);C([u({type:h.Any,repeated:"set"})],Kr.prototype,"attrValues",void 0);var My,qt=class{constructor(e={}){this.version=wt.v0,this.sid=new Ci,this.digestAlgorithm=new Ti,this.signatureAlgorithm=new Zc,this.signature=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],qt.prototype,"version",void 0);C([u({type:Ci})],qt.prototype,"sid",void 0);C([u({type:Ti})],qt.prototype,"digestAlgorithm",void 0);C([u({type:Kr,repeated:"set",context:0,implicit:!0,optional:!0})],qt.prototype,"signedAttrs",void 0);C([u({type:Zc})],qt.prototype,"signatureAlgorithm",void 0);C([u({type:ae})],qt.prototype,"signature",void 0);C([u({type:Kr,repeated:"set",context:1,implicit:!0,optional:!0})],qt.prototype,"unsignedAttrs",void 0);var Jc=My=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,My.prototype)}};Jc=My=C([A({type:_.Set,itemType:qt})],Jc);var zx=class extends Ge{};zx=C([A({type:_.Choice})],zx);var Xx=class extends qt{};Xx=C([A({type:_.Sequence})],Xx);function z(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 Qc=class{constructor(e={}){this.acIssuer=new ue,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:ue})],Qc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Qc.prototype,"acSerial",void 0);z([u({type:dt,repeated:"sequence"})],Qc.prototype,"attrs",void 0);var Ky,eu=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};eu=Ky=z([A({type:_.Sequence,itemType:h.ObjectIdentifier})],eu);var Ks=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],Ks.prototype,"pathLenConstraint",void 0);z([u({type:eu,implicit:!0,context:0,optional:!0})],Ks.prototype,"permittedAttrs",void 0);z([u({type:eu,implicit:!0,context:1,optional:!0})],Ks.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],Ks.prototype,"permitUnSpecified",void 0);var yr=class{constructor(e={}){this.issuer=new Ke,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Ke})],yr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:me})],yr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],yr.prototype,"issuerUID",void 0);var Hy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(Hy||(Hy={}));var mr=class{constructor(e={}){this.digestedObjectType=Hy.publicKey,this.digestAlgorithm=new H,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],mr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],mr.prototype,"otherObjectTypeID",void 0);z([u({type:H})],mr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],mr.prototype,"objectDigest",void 0);var Ii=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,optional:!0})],Ii.prototype,"issuerName",void 0);z([u({type:yr,context:0,implicit:!0,optional:!0})],Ii.prototype,"baseCertificateID",void 0);z([u({type:mr,context:1,implicit:!0,optional:!0})],Ii.prototype,"objectDigestInfo",void 0);var Oi=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,repeated:"sequence"})],Oi.prototype,"v1Form",void 0);z([u({type:Ii,context:0,implicit:!0})],Oi.prototype,"v2Form",void 0);Oi=z([A({type:_.Choice})],Oi);var Pi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Pi.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Pi.prototype,"notAfterTime",void 0);var yo=class{constructor(e={}){Object.assign(this,e)}};z([u({type:yr,implicit:!0,context:0,optional:!0})],yo.prototype,"baseCertificateID",void 0);z([u({type:Ke,implicit:!0,context:1,optional:!0})],yo.prototype,"entityName",void 0);z([u({type:mr,implicit:!0,context:2,optional:!0})],yo.prototype,"objectDigestInfo",void 0);var Vy;(function(r){r[r.v2=1]="v2"})(Vy||(Vy={}));var zt=class{constructor(e={}){this.version=Vy.v2,this.holder=new yo,this.issuer=new Oi,this.signature=new H,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Pi,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],zt.prototype,"version",void 0);z([u({type:yo})],zt.prototype,"holder",void 0);z([u({type:Oi})],zt.prototype,"issuer",void 0);z([u({type:H})],zt.prototype,"signature",void 0);z([u({type:h.Integer,converter:me})],zt.prototype,"serialNumber",void 0);z([u({type:Pi})],zt.prototype,"attrCertValidityPeriod",void 0);z([u({type:dt,repeated:"sequence"})],zt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],zt.prototype,"issuerUniqueID",void 0);z([u({type:nr,optional:!0})],zt.prototype,"extensions",void 0);var Bi=class{constructor(e={}){this.acinfo=new zt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:zt})],Bi.prototype,"acinfo",void 0);z([u({type:H})],Bi.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Bi.prototype,"signatureValue",void 0);var tu;(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"})(tu||(tu={}));var Hs=class extends tn{};var Vs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],Vs.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],Vs.prototype,"value",void 0);var ru=class{constructor(e={}){this.policyId="",this.classList=new Hs(tu.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],ru.prototype,"policyId",void 0);z([u({type:Hs,defaultValue:new Hs(tu.unclassified)})],ru.prototype,"classList",void 0);z([u({type:Vs,repeated:"set"})],ru.prototype,"securityCategories",void 0);var $s=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ae})],$s.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],$s.prototype,"oid",void 0);z([u({type:h.Utf8String})],$s.prototype,"string",void 0);var Xf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],Xf.prototype,"policyAuthority",void 0);z([u({type:$s,repeated:"sequence"})],Xf.prototype,"values",void 0);var b9=`${po}.4`,x9=`${po}.6`,v9=`${po}.10`,_9=`${pe}.55`,nu=`${fo}.10`,S9=`${nu}.1`,A9=`${nu}.2`,E9=`${nu}.3`,C9=`${nu}.4`,T9=`${nu}.6`,$y="2.5.4",I9=`${$y}.72`;var Fy,Fs=class{constructor(e={}){this.targetCertificate=new yr,Object.assign(this,e)}};z([u({type:yr})],Fs.prototype,"targetCertificate",void 0);z([u({type:ue,optional:!0})],Fs.prototype,"targetName",void 0);z([u({type:mr,optional:!0})],Fs.prototype,"certDigestInfo",void 0);var Ws=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,context:0,implicit:!0})],Ws.prototype,"targetName",void 0);z([u({type:ue,context:1,implicit:!0})],Ws.prototype,"targetGroup",void 0);z([u({type:Fs,context:2,implicit:!0})],Ws.prototype,"targetCert",void 0);Ws=z([A({type:_.Choice})],Ws);var Zf=Fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Fy.prototype)}};Zf=Fy=z([A({type:_.Sequence,itemType:Ws})],Zf);var Wy,Zx=Wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Wy.prototype)}};Zx=Wy=z([A({type:_.Sequence,itemType:Zf})],Zx);var Yf=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],Yf.prototype,"roleAuthority",void 0);z([u({type:ue,implicit:!0,context:1})],Yf.prototype,"roleName",void 0);var ou=class{constructor(e={}){this.service=new ue,this.ident=new ue,Object.assign(this,e)}};z([u({type:ue})],ou.prototype,"service",void 0);z([u({type:ue})],ou.prototype,"ident",void 0);z([u({type:ae,optional:!0})],ou.prototype,"authInfo",void 0);var Gy,iu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],iu.prototype,"otherCertFormat",void 0);C([u({type:h.Any})],iu.prototype,"otherCert",void 0);var Ni=class{constructor(e={}){Object.assign(this,e)}};C([u({type:dr})],Ni.prototype,"certificate",void 0);C([u({type:Bi,context:2,implicit:!0})],Ni.prototype,"v2AttrCert",void 0);C([u({type:iu,context:3,implicit:!0})],Ni.prototype,"other",void 0);Ni=C([A({type:_.Choice})],Ni);var ki=Gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gy.prototype)}};ki=Gy=C([A({type:_.Set,itemType:Ni})],ki);var gr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],gr.prototype,"contentType",void 0);C([u({type:h.Any,context:0})],gr.prototype,"content",void 0);var Gs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae})],Gs.prototype,"single",void 0);C([u({type:h.Any})],Gs.prototype,"any",void 0);Gs=C([A({type:_.Choice})],Gs);var Di=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Di.prototype,"eContentType",void 0);C([u({type:Gs,context:0,optional:!0})],Di.prototype,"eContent",void 0);var su=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae,context:0,implicit:!0,optional:!0})],su.prototype,"value",void 0);C([u({type:ae,converter:Ex,context:0,implicit:!0,optional:!0,repeated:"sequence"})],su.prototype,"constructedValue",void 0);su=C([A({type:_.Choice})],su);var mo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Yc,Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],mo.prototype,"contentType",void 0);C([u({type:Yc})],mo.prototype,"contentEncryptionAlgorithm",void 0);C([u({type:su,optional:!0})],mo.prototype,"encryptedContent",void 0);var go=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],go.prototype,"keyAttrId",void 0);C([u({type:h.Any,optional:!0})],go.prototype,"keyAttr",void 0);var qy,qs=class{constructor(e={}){this.subjectKeyIdentifier=new Wt,Object.assign(this,e)}};C([u({type:Wt})],qs.prototype,"subjectKeyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],qs.prototype,"date",void 0);C([u({type:go,optional:!0})],qs.prototype,"other",void 0);var zs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:qs,context:0,implicit:!0,optional:!0})],zs.prototype,"rKeyId",void 0);C([u({type:Mr,optional:!0})],zs.prototype,"issuerAndSerialNumber",void 0);zs=C([A({type:_.Choice})],zs);var au=class{constructor(e={}){this.rid=new zs,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:zs})],au.prototype,"rid",void 0);C([u({type:ae})],au.prototype,"encryptedKey",void 0);var Jf=qy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qy.prototype)}};Jf=qy=C([A({type:_.Sequence,itemType:au})],Jf);var cu=class{constructor(e={}){this.algorithm=new H,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:H})],cu.prototype,"algorithm",void 0);C([u({type:h.BitString})],cu.prototype,"publicKey",void 0);var ji=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Wt,context:0,implicit:!0,optional:!0})],ji.prototype,"subjectKeyIdentifier",void 0);C([u({type:cu,context:1,implicit:!0,optional:!0})],ji.prototype,"originatorKey",void 0);C([u({type:Mr,optional:!0})],ji.prototype,"issuerAndSerialNumber",void 0);ji=C([A({type:_.Choice})],ji);var Nn=class{constructor(e={}){this.version=wt.v3,this.originator=new ji,this.keyEncryptionAlgorithm=new Gt,this.recipientEncryptedKeys=new Jf,Object.assign(this,e)}};C([u({type:h.Integer})],Nn.prototype,"version",void 0);C([u({type:ji,context:0})],Nn.prototype,"originator",void 0);C([u({type:ae,context:1,optional:!0})],Nn.prototype,"ukm",void 0);C([u({type:Gt})],Nn.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:Jf})],Nn.prototype,"recipientEncryptedKeys",void 0);var Xs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Wt,context:0,implicit:!0})],Xs.prototype,"subjectKeyIdentifier",void 0);C([u({type:Mr})],Xs.prototype,"issuerAndSerialNumber",void 0);Xs=C([A({type:_.Choice})],Xs);var wo=class{constructor(e={}){this.version=wt.v0,this.rid=new Xs,this.keyEncryptionAlgorithm=new Gt,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],wo.prototype,"version",void 0);C([u({type:Xs})],wo.prototype,"rid",void 0);C([u({type:Gt})],wo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],wo.prototype,"encryptedKey",void 0);var Ri=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};C([u({type:ae})],Ri.prototype,"keyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Ri.prototype,"date",void 0);C([u({type:go,optional:!0})],Ri.prototype,"other",void 0);var bo=class{constructor(e={}){this.version=wt.v4,this.kekid=new Ri,this.keyEncryptionAlgorithm=new Gt,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],bo.prototype,"version",void 0);C([u({type:Ri})],bo.prototype,"kekid",void 0);C([u({type:Gt})],bo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],bo.prototype,"encryptedKey",void 0);var xo=class{constructor(e={}){this.version=wt.v0,this.keyEncryptionAlgorithm=new Gt,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],xo.prototype,"version",void 0);C([u({type:zf,context:0,optional:!0})],xo.prototype,"keyDerivationAlgorithm",void 0);C([u({type:Gt})],xo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],xo.prototype,"encryptedKey",void 0);var uu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],uu.prototype,"oriType",void 0);C([u({type:h.Any})],uu.prototype,"oriValue",void 0);var kn=class{constructor(e={}){Object.assign(this,e)}};C([u({type:wo,optional:!0})],kn.prototype,"ktri",void 0);C([u({type:Nn,context:1,implicit:!0,optional:!0})],kn.prototype,"kari",void 0);C([u({type:bo,context:2,implicit:!0,optional:!0})],kn.prototype,"kekri",void 0);C([u({type:xo,context:3,implicit:!0,optional:!0})],kn.prototype,"pwri",void 0);C([u({type:uu,context:4,implicit:!0,optional:!0})],kn.prototype,"ori",void 0);kn=C([A({type:_.Choice})],kn);var zy,lu=zy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,zy.prototype)}};lu=zy=C([A({type:_.Set,itemType:kn})],lu);var Xy,Yx=`${fo}.16`,TH=`${Yx}.2`,IH=`${Yx}.4`,Zs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Zs.prototype,"otherRevInfoFormat",void 0);C([u({type:h.Any})],Zs.prototype,"otherRevInfo",void 0);var Qf=class{constructor(e={}){this.other=new Zs,Object.assign(this,e)}};C([u({type:Zs,context:1,implicit:!0})],Qf.prototype,"other",void 0);Qf=C([A({type:_.Choice})],Qf);var Ys=Xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};Ys=Xy=C([A({type:_.Set,itemType:Qf})],Ys);var Js=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ki,context:0,implicit:!0,optional:!0})],Js.prototype,"certs",void 0);C([u({type:Ys,context:1,implicit:!0,optional:!0})],Js.prototype,"crls",void 0);var Zy,Yy=Zy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Zy.prototype)}};Yy=Zy=C([A({type:_.Set,itemType:Kr})],Yy);var Li=class{constructor(e={}){this.version=wt.v0,this.recipientInfos=new lu,this.encryptedContentInfo=new mo,Object.assign(this,e)}};C([u({type:h.Integer})],Li.prototype,"version",void 0);C([u({type:Js,context:0,implicit:!0,optional:!0})],Li.prototype,"originatorInfo",void 0);C([u({type:lu})],Li.prototype,"recipientInfos",void 0);C([u({type:mo})],Li.prototype,"encryptedContentInfo",void 0);C([u({type:Yy,context:1,implicit:!0,optional:!0})],Li.prototype,"unprotectedAttrs",void 0);var Jx="1.2.840.113549.1.7.2";var Jy,ep=Jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Jy.prototype)}};ep=Jy=C([A({type:_.Set,itemType:Ti})],ep);var Dn=class{constructor(e={}){this.version=wt.v0,this.digestAlgorithms=new ep,this.encapContentInfo=new Di,this.signerInfos=new Jc,Object.assign(this,e)}};C([u({type:h.Integer})],Dn.prototype,"version",void 0);C([u({type:ep})],Dn.prototype,"digestAlgorithms",void 0);C([u({type:Di})],Dn.prototype,"encapContentInfo",void 0);C([u({type:ki,context:0,implicit:!0,optional:!0})],Dn.prototype,"certificates",void 0);C([u({type:Ys,context:1,implicit:!0,optional:!0})],Dn.prototype,"crls",void 0);C([u({type:Jc})],Dn.prototype,"signerInfos",void 0);var Ui="1.2.840.10045.2.1";var fu="1.2.840.10045.4.1",tp="1.2.840.10045.4.3.1",pu="1.2.840.10045.4.3.2",hu="1.2.840.10045.4.3.3",du="1.2.840.10045.4.3.4";var Qy="1.2.840.10045.3.1.7";var em="1.3.132.0.34";var tm="1.3.132.0.35";function yu(r){return new H({algorithm:r})}var ev=yu(fu),AV=yu(tp),tv=yu(pu),rv=yu(hu),nv=yu(du);function Be(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 mu=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],mu.prototype,"fieldType",void 0);Be([u({type:h.Any})],mu.prototype,"parameters",void 0);mu=Be([A({type:_.Sequence})],mu);var rm=class extends ae{};var Qs=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.OctetString})],Qs.prototype,"a",void 0);Be([u({type:h.OctetString})],Qs.prototype,"b",void 0);Be([u({type:h.BitString,optional:!0})],Qs.prototype,"seed",void 0);Qs=Be([A({type:_.Sequence})],Qs);var nm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(nm||(nm={}));var sn=class{constructor(e={}){this.version=nm.ecpVer1,Object.assign(this,e)}};Be([u({type:h.Integer})],sn.prototype,"version",void 0);Be([u({type:mu})],sn.prototype,"fieldID",void 0);Be([u({type:Qs})],sn.prototype,"curve",void 0);Be([u({type:rm})],sn.prototype,"base",void 0);Be([u({type:h.Integer,converter:me})],sn.prototype,"order",void 0);Be([u({type:h.Integer,optional:!0})],sn.prototype,"cofactor",void 0);sn=Be([A({type:_.Sequence})],sn);var an=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],an.prototype,"namedCurve",void 0);Be([u({type:h.Null})],an.prototype,"implicitCurve",void 0);Be([u({type:sn})],an.prototype,"specifiedCurve",void 0);an=Be([A({type:_.Choice})],an);var ea=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};Be([u({type:h.Integer})],ea.prototype,"version",void 0);Be([u({type:ae})],ea.prototype,"privateKey",void 0);Be([u({type:an,context:0,optional:!0})],ea.prototype,"parameters",void 0);Be([u({type:h.BitString,context:1,optional:!0})],ea.prototype,"publicKey",void 0);var Mi=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Be([u({type:h.Integer,converter:me})],Mi.prototype,"r",void 0);Be([u({type:h.Integer,converter:me})],Mi.prototype,"s",void 0);function Ee(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 Xt="1.2.840.113549.1.1",cn=`${Xt}.1`,ov=`${Xt}.7`,iv=`${Xt}.9`,vo=`${Xt}.10`,sv=`${Xt}.2`,av=`${Xt}.4`,ta=`${Xt}.5`,cv=`${Xt}.14`;var rp=`${Xt}.11`,ra=`${Xt}.12`,na=`${Xt}.13`,om=`${Xt}.15`,im=`${Xt}.16`,Ki="1.3.14.3.2.26",np="2.16.840.1.101.3.4.2.4",Hi="2.16.840.1.101.3.4.2.1",Vi="2.16.840.1.101.3.4.2.2",$i="2.16.840.1.101.3.4.2.3",uv="2.16.840.1.101.3.4.2.5",lv="2.16.840.1.101.3.4.2.6",fv="1.2.840.113549.2.2",pv="1.2.840.113549.2.5",_o=`${Xt}.8`;function at(r){return new H({algorithm:r,parameters:null})}var e7=at(fv),t7=at(pv),jn=at(Ki),r7=at(np),n7=at(Hi),o7=at(Vi),i7=at($i),s7=at(uv),a7=at(lv),op=new H({algorithm:_o,parameters:W.serialize(jn)}),sm=new H({algorithm:iv,parameters:W.serialize(js.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),c7=at(cn),u7=at(sv),l7=at(av),f7=at(ta),p7=at(om),h7=at(im),d7=at(ra),y7=at(na),m7=at(om),g7=at(im);var oa=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:_o,parameters:W.serialize(jn)}),this.pSourceAlgorithm=new H(sm),Object.assign(this,e)}};Ee([u({type:H,context:0,defaultValue:jn})],oa.prototype,"hashAlgorithm",void 0);Ee([u({type:H,context:1,defaultValue:op})],oa.prototype,"maskGenAlgorithm",void 0);Ee([u({type:H,context:2,defaultValue:sm})],oa.prototype,"pSourceAlgorithm",void 0);var A7=new H({algorithm:ov,parameters:W.serialize(new oa)});var un=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:_o,parameters:W.serialize(jn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Ee([u({type:H,context:0,defaultValue:jn})],un.prototype,"hashAlgorithm",void 0);Ee([u({type:H,context:1,defaultValue:op})],un.prototype,"maskGenAlgorithm",void 0);Ee([u({type:h.Integer,context:2,defaultValue:20})],un.prototype,"saltLength",void 0);Ee([u({type:h.Integer,context:3,defaultValue:1})],un.prototype,"trailerField",void 0);var B7=new H({algorithm:vo,parameters:W.serialize(new un)});var Fi=class{constructor(e={}){this.digestAlgorithm=new H,this.digest=new ae,Object.assign(this,e)}};Ee([u({type:H})],Fi.prototype,"digestAlgorithm",void 0);Ee([u({type:ae})],Fi.prototype,"digest",void 0);var am,ia=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Ee([u({type:h.Integer,converter:me})],ia.prototype,"prime",void 0);Ee([u({type:h.Integer,converter:me})],ia.prototype,"exponent",void 0);Ee([u({type:h.Integer,converter:me})],ia.prototype,"coefficient",void 0);var ip=am=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};ip=am=Ee([A({type:_.Sequence,itemType:ia})],ip);var wr=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)}};Ee([u({type:h.Integer})],wr.prototype,"version",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"modulus",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"publicExponent",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"privateExponent",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"prime1",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"prime2",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"exponent1",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"exponent2",void 0);Ee([u({type:h.Integer,converter:me})],wr.prototype,"coefficient",void 0);Ee([u({type:ip,optional:!0})],wr.prototype,"otherPrimeInfos",void 0);var sa=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Ee([u({type:h.Integer,converter:me})],sa.prototype,"modulus",void 0);Ee([u({type:h.Integer,converter:me})],sa.prototype,"publicExponent",void 0);function gu(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 cm;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(cm||(cm={}));var bt=cm;var Dv=$r(kv(),1),{__extends:ca,__assign:u$,__rest:VC,__decorate:l$,__param:f$,__metadata:p$,__awaiter:jv,__generator:Rv,__exportStar:h$,__createBinding:d$,__values:wu,__read:bu,__spread:Hr,__spreadArrays:y$,__await:m$,__asyncGenerator:g$,__asyncDelegator:w$,__asyncValues:b$,__makeTemplateObject:x$,__importStar:v$,__importDefault:_$,__classPrivateFieldGet:S$,__classPrivateFieldSet:A$}=Dv.default;var $C="injectionTokens";function lm(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata($C,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function xu(r){return!!r.useClass}function ua(r){return!!r.useFactory}var cp=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,Hr(i))}};return this.reflectMethods.forEach(n),t},r}();function So(r){return typeof r=="string"||typeof r=="symbol"}function fm(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function up(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Lv(r){return typeof r=="function"||r instanceof cp}function Wi(r){return!!r.useToken}function Gi(r){return r.useValue!=null}function Uv(r){return xu(r)||Gi(r)||Wi(r)||ua(r)}var FC=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}(),vu=FC;var WC=function(r){ca(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(vu),Mv=WC;var GC=function(){function r(){this.scopedResolutions=new Map}return r}(),_u=GC;function qC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function zC(r,e,t){return t===void 0&&(t=" "),Hr([r],e.message.split(`
6
+ `)}`:`${t} :`}};dx=st;J.Constructed=dx;st.NAME="CONSTRUCTED";var Of=class extends bt{fromBER(e,t,n){return t}toBER(e){return Hr}};Of.override="EndOfContentValueBlock";var yx,jc=class extends it{constructor(e={}){super(e,Of),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};yx=jc;J.EndOfContent=yx;jc.NAME=Nc;var mx,Ur=class extends it{constructor(e={}){super(e,bt),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}`}};mx=Ur;J.Null=mx;Ur.NAME="NULL";var Bf=class extends nn(bt){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=ge.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);return Ln(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,wy.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Bf.NAME="BooleanValueBlock";var gx,wi=class extends it{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Bf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};gx=wi;J.Boolean=gx;wi.NAME="BOOLEAN";var Pf=class extends nn(tn){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=tn.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===Nc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==lx)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?tn.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Pf.NAME="OctetStringValueBlock";var Sy,Mr=class extends it{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},Pf),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=Ys(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 st.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ge.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 Sy&&e.push(t.valueBlock.valueHexView);return ge.BufferSourceConverter.concat(e)}};Sy=Mr;J.OctetString=Sy;Mr.NAME=lx;var kf=class extends nn(tn){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=tn.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Nc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==fx)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=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=Ys(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 tn.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Hr;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}}};kf.NAME="BitStringValueBlock";var bx,Kr=class extends it{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},kf),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 st.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}`}}};bx=Kr;J.BitString=bx;Kr.NAME=fx;var wx;function jC(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,p=c<s?s:c,f=0;for(let d=p;d>=0;d--,f++){switch(!0){case f<a.length:u=i[s-f]+a[c-f]+t[0];break;default:u=i[s-f]+t[0]}switch(t[0]=u/10,!0){case f>=i.length:i=Af(new Uint8Array([u%10]),i);break;default:i[s-f]=u%10}}return t[0]>0&&(i=Af(t,i)),i}function ux(r){if(r>=Pc.length)for(let e=Pc.length;e<=r;e++){let t=new Uint8Array([0]),n=Pc[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=Af(t,n)),Pc.push(n)}return Pc[r]}function RC(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,p=0;for(let f=c;f>=0;f--,p++)switch(u=i[s-p]-a[c-p]-t,!0){case u<0:t=1,i[s-p]=u+10;break;default:t=0,i[s-p]=u}if(t>0)for(let f=s-c+1;f>=0;f--,p++)if(u=i[s-p]-t,u<0)t=1,i[s-p]=u+10;else{t=0,i[s-p]=u;break}return i.slice()}var Rc=class extends nn(bt){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=wy.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(ix(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=RC(ux(n),t),s="-";break;default:t=jC(t,ux(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=ax.charAt(t[c]));return a===!1&&(s+=ax.charAt(0)),s}};wx=Rc;Rc.NAME="IntegerValueBlock";Object.defineProperty(wx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var kc,Rn=class extends it{constructor(e={}){super(e,Rc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ef(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Ef();let t=BigInt(e),n=new Xs,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ge.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${ge.Convert.ToHex(a)}`)+t,p=ge.BufferSourceConverter.toUint8Array(ge.Convert.FromHex(u.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new kc({valueHex:n.final()})}convertToDER(){let e=new kc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new kc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};kc=Rn;J.Integer=kc;Rn.NAME="INTEGER";var xx,xi=class extends Rn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};xx=xi;J.Enumerated=xx;xi.NAME="ENUMERATED";var Lc=class extends nn(bt){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=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=bi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Ef();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=go(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Hr;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=ge.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}}};Lc.NAME="sidBlock";var Nf=class extends bt{constructor({value:e=Gt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Lc;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,Hr;t.push(o)}return _y(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 Lc;if(o>Number.MAX_SAFE_INTEGER){Ef();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}};Nf.NAME="ObjectIdentifierValueBlock";var vx,vi=class extends it{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Nf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};vx=vi;J.ObjectIdentifier=vx;vi.NAME="OBJECT IDENTIFIER";var Uc=class extends nn(Dn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=bi(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=go(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Hr;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=ge.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Uc.NAME="relativeSidBlock";var Df=class extends bt{constructor({value:e=Gt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Uc;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,Hr;n.push(i)}return _y(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 Uc;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}};Df.NAME="RelativeObjectIdentifierValueBlock";var _x,Mc=class extends it{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Df),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};_x=Mc;J.RelativeObjectIdentifier=_x;Mc.NAME="RelativeObjectIdentifier";var Sx,Dt=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Sx=Dt;J.Sequence=Sx;Dt.NAME="SEQUENCE";var Ax,Mt=class extends st{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ax=Mt;J.Set=Ax;Mt.NAME="SET";var jf=class extends nn(bt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Gt}toJSON(){return{...super.toJSON(),value:this.value}}};jf.NAME="StringValueBlock";var Rf=class extends jf{};Rf.NAME="SimpleStringValueBlock";var Kt=class extends Dc{constructor({...e}={}){super(e,Rf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ge.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}};Kt.NAME="SIMPLE STRING";var Lf=class extends Kt{fromBuffer(e){this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ge.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ge.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Lf.NAME="Utf8StringValueBlock";var Ex,yr=class extends Lf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ex=yr;J.Utf8String=Ex;yr.NAME="UTF8String";var Uf=class extends Kt{fromBuffer(e){this.valueBlock.value=ge.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf16String(e))}};Uf.NAME="BmpStringValueBlock";var Cx,_i=class extends Uf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Cx=_i;J.BmpString=Cx;_i.NAME="BMPString";var Mf=class extends Kt{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=go(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}};Mf.NAME="UniversalStringValueBlock";var Tx,Si=class extends Mf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Tx=Si;J.UniversalString=Tx;Si.NAME="UniversalString";var Ix,Ai=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ix=Ai;J.NumericString=Ix;Ai.NAME="NumericString";var Ox,Ei=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ox=Ei;J.PrintableString=Ox;Ei.NAME="PrintableString";var Bx,Ci=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Bx=Ci;J.TeletexString=Bx;Ci.NAME="TeletexString";var Px,Ti=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Px=Ti;J.VideotexString=Px;Ti.NAME="VideotexString";var kx,Ii=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};kx=Ii;J.IA5String=kx;Ii.NAME="IA5String";var Nx,Oi=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Nx=Oi;J.GraphicString=Nx;Oi.NAME="GraphicString";var Dx,bo=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Dx=bo;J.VisibleString=Dx;bo.NAME="VisibleString";var jx,Bi=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};jx=Bi;J.GeneralString=jx;Bi.NAME="GeneralString";var Rx,Pi=class extends Kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Rx=Pi;J.CharacterString=Rx;Pi.NAME="CharacterString";var Lx,wo=class extends bo{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,ge.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]=qt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=qt(this.month,2),t[2]=qt(this.day,2),t[3]=qt(this.hour,2),t[4]=qt(this.minute,2),t[5]=qt(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=wo;J.UTCTime=Lx;wo.NAME="UTCTime";var Ux,ki=class extends wo{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 f=new Number(e[e.length-1]);if(isNaN(f.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 f=1,d=n.indexOf("+"),m="";if(d===-1&&(d=n.indexOf("-"),f=-1),d!==-1){if(m=n.substring(d+1),n=n.substring(0,d),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(m.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*g,m.length===4){if(g=parseInt(m.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=f*g}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.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 f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let p=s.exec(o);if(p===null)throw new Error("Wrong input string for conversion");for(let f=1;f<p.length;f++)switch(f){case 1:this.year=parseInt(p[f],10);break;case 2:this.month=parseInt(p[f],10);break;case 3:this.day=parseInt(p[f],10);break;case 4:this.hour=parseInt(p[f],10)+a;break;case 5:this.minute=parseInt(p[f],10)+c;break;case 6:this.second=parseInt(p[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(qt(this.year,4)),t.push(qt(this.month,2)),t.push(qt(this.day,2)),t.push(qt(this.hour,2)),t.push(qt(this.minute,2)),t.push(qt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(qt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Ux=ki;J.GeneralizedTime=Ux;ki.NAME="GeneralizedTime";var Mx,Kc=class extends yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Mx=Kc;J.DATE=Mx;Kc.NAME="DATE";var Kx,Hc=class extends yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Kx=Hc;J.TimeOfDay=Kx;Hc.NAME="TimeOfDay";var Hx,Vc=class extends yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Hx=Vc;J.DateTime=Hx;Vc.NAME="DateTime";var Vx,$c=class extends yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Vx=$c;J.Duration=Vx;$c.NAME="Duration";var $x,Fc=class extends yr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};$x=Fc;J.TIME=$x;Fc.NAME="TIME";var rn=class{constructor({name:e=Gt,optional:t=!1}={}){this.name=e,this.optional=t}},Zs=class extends rn{constructor({value:e=[],...t}={}){super(t),this.value=e}},Ni=class extends rn{constructor({value:e=new rn,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},vy=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Kf}={}){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ge.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function Nn(r,e,t){if(t instanceof Zs){for(let i of t.value)if(Nn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(xy)&&(i.name=t.name),i}}if(t instanceof rn)return t.hasOwnProperty(xy)&&(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(!(CC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(BC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(PC 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(TC)===!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(IC)===!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(OC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(EC 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(!(cx 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,Gt),t.name&&(r[t.name]=e)),t instanceof J.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,Gt),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,Gt),t.name&&(delete r[t.name],u.name=t.name)),u}}else if(t.valueBlock.value[0]instanceof Ni){if(s=Nn(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,Gt),t.name&&delete r[t.name]),s;if(xy in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let u={};kC 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=Nn(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,Gt),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,Gt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&cx in e.valueBlock){let i=Ys(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,Gt),t.name&&(delete r[t.name],s.name=t.name)),s}return Nn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function LC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Ys(ge.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:Nn(t.result,t.result,e)}var v;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(v||(v={}));var h;(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"})(h||(h={}));var Ay=Xr(kn()),sn=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Ay.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Ay.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Kr))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 Kr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Kr({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 Ey=Xr(kn()),se=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Ey.BufferSourceConverter.isBufferSource(e)?this.buffer=Ey.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Mr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Mr({valueHex:this.buffer})}toSchema(e){return new Mr({name:e})}};var UC={fromASN:r=>r instanceof Ur?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Ur;let e=Un(r);if(e.result.error)throw new Error(e.result.error);return e.result}},MC={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Rn({value:+r})},KC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new xi({value:r})},be={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Rn({valueHex:r})};var HC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Kr({valueHex:r})},VC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new vi({value:r})},$C={fromASN:r=>r.valueBlock.value,toASN:r=>new wi({value:r})},Js={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Mr({valueHex:r})},Fx={fromASN:r=>new se(r.getValue()),toASN:r=>r.toASN()};function mr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Cy=mr(yr),FC=mr(_i),WC=mr(Si),qC=mr(Ai),GC=mr(Ei),zC=mr(Ci),XC=mr(Ti),ZC=mr(Ii),YC=mr(Oi),JC=mr(bo),QC=mr(Bi),eT=mr(Pi),tT={fromASN:r=>r.toDate(),toASN:r=>new wo({valueDate:r})},rT={fromASN:r=>r.toDate(),toASN:r=>new ki({valueDate:r})},nT={fromASN:()=>null,toASN:()=>new Ur};function xo(r){switch(r){case h.Any:return UC;case h.BitString:return HC;case h.BmpString:return FC;case h.Boolean:return $C;case h.CharacterString:return eT;case h.Enumerated:return KC;case h.GeneralString:return QC;case h.GeneralizedTime:return rT;case h.GraphicString:return YC;case h.IA5String:return ZC;case h.Integer:return MC;case h.Null:return nT;case h.NumericString:return qC;case h.ObjectIdentifier:return VC;case h.OctetString:return Js;case h.PrintableString:return GC;case h.TeletexString:return zC;case h.UTCTime:return tT;case h.UniversalString:return WC;case h.Utf8String:return Cy;case h.VideotexString:return XC;case h.VisibleString:return JC;default:return null}}function gr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:gr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Iy(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Iy(t)}return!1}function Wx(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 Hf=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:v.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 p=h[s.type],f=on[p];if(!f)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new f({name:a})}else gr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===v.Choice?c=new rn({name:a}):(c=this.create(s.type,!1),c.name=a):c=new rn({name:a});let u=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Mt:Dt;c=new p({name:"",value:[new Ni({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||gr(s.type)){let p=s.repeated?st:jn;o.push(new p({name:a,optional:u,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,f=p?c:this.get(s.type,!0).schema;f="valueBlock"in f?f.valueBlock.value:f.value,o.push(new st({name:p?"":a,optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:f}))}else o.push(new st({optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=u,o.push(c)}switch(n.type){case v.Sequence:return new Dt({value:o,name:""});case v.Set:return new Mt({value:o,name:""});case v.Choice:return new Zs({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 Xe=new Hf;var A=r=>e=>{let t;Xe.has(e)?t=Xe.get(e):(t=Xe.createDefault(e),Xe.set(e,t)),Object.assign(t,r)};var l=r=>(e,t)=>{let n;Xe.has(e.constructor)?n=Xe.get(e.constructor):(n=Xe.createDefault(e.constructor),Xe.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=xo(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 vo=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Wc=class{static parse(e,t){let n=Un(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(gr(t))return new t().fromASN(e);let n=Xe.get(t);Xe.cache(t);let o=n.schema,i=this.handleChoiceTypes(e,n,t,o);if(i?.result)return i.result;i?.targetSchema&&(o=i.targetSchema);let s=this.handleSequenceTypes(e,n,t,o);if(s&&"isManualMapping"in s)return s.result;let a=s,c=new t;return Iy(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof vo&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===st&&t.type===v.Choice&&e.idBlock.tagClass===3)for(let i in t.items){let s=t.items[i];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&Xe.has(s.type)){let a=Xe.get(s.type);if(a&&a.type===v.Sequence){let c=new Dt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let u=this.fromASN(c,s.type),p=new n;return p[i]=u,{result:p}}}}}else if(e.constructor===st&&t.type!==v.Choice){let i=new st({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(let s in t.items)delete e[s];return{targetSchema:i}}return null}static handleSequenceTypes(e,t,n,o){if(t.type===v.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&Xe.has(c.type)&&Xe.get(c.type).type===v.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=Nn({},e,o);if(!s.verified)throw new vo(`Data does not match to ${n.name} ASN1 schema. ${s.result.error}`);return s}else{let i=Nn({},e,o);if(!i.verified)throw new vo(`Data does not match to ${n.name} ASN1 schema. ${i.result.error}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let u=s[c],p=t.items[u];if(a>=i.length)break;if(p.repeated){o[u]=this.processRepeatedField(i,a,p);break}else if(typeof p.type=="number")o[u]=this.processPrimitiveField(i[a],p),a++;else if(this.isOptionalChoiceField(p)){let f=this.processOptionalChoiceField(i[a],p);f.processed&&(o[u]=f.value,a++)}else o[u]=this.fromASN(i[a],p.type),a++}return{result:o,verified:!0,isManualMapping:!0}}static processRepeatedField(e,t,n){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){let i=o[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(o=i.valueBlock.value)}if(typeof n.type=="number"){let i=xo(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return i.fromASN(s)}catch{return}}).filter(s=>s!==void 0)}else return o.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,t){let n=xo(t.type);if(!n)throw new Error(`No converter for ASN.1 type ${t.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Xe.has(e.type)&&Xe.get(e.type).type===v.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof vo&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,t,n){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 o=t.itemType;if(typeof o=="number"){let i=xo(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type;typeof a=="number"||gr(a)?n[o]=this.processPrimitiveSchemaItem(i,s,a):n[o]=this.processComplexSchemaItem(i,s,a)}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:gr(n)?new n:null;if(!i)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,i):this.processSinglePrimitiveItem(e,t,n,i)}static processRepeatedPrimitiveItem(e,t,n){if(t.implicit){let o=t.repeated==="sequence"?Dt:Mt,i=new o;i.valueBlock=e.valueBlock;let s=Un(i.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let a=s.result.valueBlock.value;return Array.from(a,c=>n.fromASN(c))}else return Array.from(e,o=>n.fromASN(o))}static processSinglePrimitiveItem(e,t,n,o){let i=e;if(t.implicit){let s;if(gr(n))s=new n().toSchema("");else{let a=h[n],c=on[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Un(s.toBER(!1)).result}return o.fromASN(i)}static processComplexSchemaItem(e,t,n){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,n))}else{let o=this.handleImplicitTagging(e,t,n);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,n)}catch(i){if(i instanceof vo&&/Wrong values for Choice type/.test(i.message))return;throw i}else return this.fromASN(o,n)}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=Xe.get(n);if(o.type===v.Sequence){let i=new Dt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(o.type===v.Set){let i=new Mt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var qc=class r{static serialize(e){return e instanceof it?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&gr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Xe.get(t);Xe.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=xo(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"&&Wx(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"||gr(a.type))){let p={};p.valueHex=u instanceof Ur?u.valueBeforeDecodeView:u.valueBlock.toBER(),o.push(new jn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new st({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:u.valueBlock.value}));else o.push(new st({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 v.Sequence:i=new Dt({value:o});break;case v.Set:i=new Mt({value:o});break;case v.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 ${h[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"?Dt:Mt;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"?Dt:Mt;i=new a({value:s})}else i=this.toASN(o);return i}};var ie=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var Oy=Xr(kn());var q=class r{static serialize(e){return qc.serialize(e)}static parse(e,t){return Wc.parse(e,t)}static toString(e){let t=Oy.BufferSourceConverter.isBufferSource(e)?Oy.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Un(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function b(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 qx=Xr(kn()),Gc=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(qx.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 Gx=Xr(kn()),By,Py,ky,at=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};b([l({type:h.TeletexString})],at.prototype,"teletexString",void 0);b([l({type:h.PrintableString})],at.prototype,"printableString",void 0);b([l({type:h.UniversalString})],at.prototype,"universalString",void 0);b([l({type:h.Utf8String})],at.prototype,"utf8String",void 0);b([l({type:h.BmpString})],at.prototype,"bmpString",void 0);at=b([A({type:v.Choice})],at);var Qs=class extends at{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Gx.Convert.ToHex(this.anyValue):super.toString())}};b([l({type:h.IA5String})],Qs.prototype,"ia5String",void 0);b([l({type:h.Any})],Qs.prototype,"anyValue",void 0);Qs=b([A({type:v.Choice})],Qs);var Di=class{constructor(e={}){this.type="",this.value=new Qs,Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],Di.prototype,"type",void 0);b([l({type:Qs})],Di.prototype,"value",void 0);var _o=By=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,By.prototype)}};_o=By=b([A({type:v.Set,itemType:Di})],_o);var Ny=Py=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Py.prototype)}};Ny=Py=b([A({type:v.Sequence,itemType:_o})],Ny);var Ne=ky=class extends Ny{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Ne=ky=b([A({type:v.Sequence})],Ne);var oT={fromASN:r=>Gc.toString(Js.fromASN(r)),toASN:r=>Js.toASN(Gc.fromString(r))},So=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],So.prototype,"typeId",void 0);b([l({type:h.Any,context:0})],So.prototype,"value",void 0);var zc=class{constructor(e={}){this.partyName=new at,Object.assign(this,e)}};b([l({type:at,optional:!0,context:0,implicit:!0})],zc.prototype,"nameAssigner",void 0);b([l({type:at,context:1,implicit:!0})],zc.prototype,"partyName",void 0);var ce=class{constructor(e={}){Object.assign(this,e)}};b([l({type:So,context:0,implicit:!0})],ce.prototype,"otherName",void 0);b([l({type:h.IA5String,context:1,implicit:!0})],ce.prototype,"rfc822Name",void 0);b([l({type:h.IA5String,context:2,implicit:!0})],ce.prototype,"dNSName",void 0);b([l({type:h.Any,context:3,implicit:!0})],ce.prototype,"x400Address",void 0);b([l({type:Ne,context:4,implicit:!1})],ce.prototype,"directoryName",void 0);b([l({type:zc,context:5})],ce.prototype,"ediPartyName",void 0);b([l({type:h.IA5String,context:6,implicit:!0})],ce.prototype,"uniformResourceIdentifier",void 0);b([l({type:h.OctetString,context:7,implicit:!0,converter:oT})],ce.prototype,"iPAddress",void 0);b([l({type:h.ObjectIdentifier,context:8,implicit:!0})],ce.prototype,"registeredID",void 0);ce=b([A({type:v.Choice})],ce);var Ao="1.3.6.1.5.5.7",Eo=`${Ao}.1`,zx=`${Ao}.2`,ji=`${Ao}.3`,Vf=`${Ao}.48`,wD=`${zx}.1`,xD=`${zx}.2`,Dy=`${Vf}.1`,jy=`${Vf}.2`,Ry=`${Vf}.3`,Ly=`${Vf}.5`,he="2.5.29";var Uy,$f=`${Eo}.1`,Mn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ce,Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],Mn.prototype,"accessMethod",void 0);b([l({type:ce})],Mn.prototype,"accessLocation",void 0);var Ri=Uy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Uy.prototype)}};Ri=Uy=b([A({type:v.Sequence,itemType:Mn})],Ri);var Ff=`${he}.35`,Li=class extends se{},an=class{constructor(e={}){e&&Object.assign(this,e)}};b([l({type:Li,context:0,optional:!0,implicit:!0})],an.prototype,"keyIdentifier",void 0);b([l({type:ce,context:1,optional:!0,implicit:!0,repeated:"sequence"})],an.prototype,"authorityCertIssuer",void 0);b([l({type:h.Integer,context:2,optional:!0,implicit:!0,converter:be})],an.prototype,"authorityCertSerialNumber",void 0);var Wf=`${he}.19`,Ui=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};b([l({type:h.Boolean,defaultValue:!1})],Ui.prototype,"cA",void 0);b([l({type:h.Integer,optional:!0})],Ui.prototype,"pathLenConstraint",void 0);var My,Ve=My=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,My.prototype)}};Ve=My=b([A({type:v.Sequence,itemType:ce})],Ve);var Ky,iT=`${he}.29`,Xx=Ky=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};Xx=Ky=b([A({type:v.Sequence})],Xx);var Hy,Gf=`${he}.32`,JD=`${Gf}.0`,Kn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};b([l({type:h.IA5String})],Kn.prototype,"ia5String",void 0);b([l({type:h.VisibleString})],Kn.prototype,"visibleString",void 0);b([l({type:h.BmpString})],Kn.prototype,"bmpString",void 0);b([l({type:h.Utf8String})],Kn.prototype,"utf8String",void 0);Kn=b([A({type:v.Choice})],Kn);var Xc=class{constructor(e={}){this.organization=new Kn,this.noticeNumbers=[],Object.assign(this,e)}};b([l({type:Kn})],Xc.prototype,"organization",void 0);b([l({type:h.Integer,repeated:"sequence"})],Xc.prototype,"noticeNumbers",void 0);var Zc=class{constructor(e={}){Object.assign(this,e)}};b([l({type:Xc,optional:!0})],Zc.prototype,"noticeRef",void 0);b([l({type:Kn,optional:!0})],Zc.prototype,"explicitText",void 0);var qf=class{constructor(e={}){Object.assign(this,e)}};b([l({type:h.IA5String})],qf.prototype,"cPSuri",void 0);b([l({type:Zc})],qf.prototype,"userNotice",void 0);qf=b([A({type:v.Choice})],qf);var Yc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],Yc.prototype,"policyQualifierId",void 0);b([l({type:h.Any})],Yc.prototype,"qualifier",void 0);var Mi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],Mi.prototype,"policyIdentifier",void 0);b([l({type:Yc,repeated:"sequence",optional:!0})],Mi.prototype,"policyQualifiers",void 0);var Jc=Hy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Hy.prototype)}};Jc=Hy=b([A({type:v.Sequence,itemType:Mi})],Jc);var sj=`${he}.20`,Qc=class{constructor(e=0){this.value=e}};b([l({type:h.Integer})],Qc.prototype,"value",void 0);Qc=b([A({type:v.Choice})],Qc);var hj=`${he}.27`,Zx=class extends Qc{};Zx=b([A({type:v.Choice})],Zx);var Vy,zf=`${he}.31`,Vr;(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"})(Vr||(Vr={}));var eu=class extends sn{toJSON(){let e=[],t=this.toNumber();return t&Vr.aACompromise&&e.push("aACompromise"),t&Vr.affiliationChanged&&e.push("affiliationChanged"),t&Vr.cACompromise&&e.push("cACompromise"),t&Vr.certificateHold&&e.push("certificateHold"),t&Vr.cessationOfOperation&&e.push("cessationOfOperation"),t&Vr.keyCompromise&&e.push("keyCompromise"),t&Vr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Vr.superseded&&e.push("superseded"),t&Vr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Hn=class{constructor(e={}){Object.assign(this,e)}};b([l({type:ce,context:0,repeated:"sequence",implicit:!0})],Hn.prototype,"fullName",void 0);b([l({type:_o,context:1,implicit:!0})],Hn.prototype,"nameRelativeToCRLIssuer",void 0);Hn=b([A({type:v.Choice})],Hn);var cn=class{constructor(e={}){Object.assign(this,e)}};b([l({type:Hn,context:0,optional:!0})],cn.prototype,"distributionPoint",void 0);b([l({type:eu,context:1,optional:!0,implicit:!0})],cn.prototype,"reasons",void 0);b([l({type:ce,context:2,optional:!0,repeated:"sequence",implicit:!0})],cn.prototype,"cRLIssuer",void 0);var Co=Vy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Vy.prototype)}};Co=Vy=b([A({type:v.Sequence,itemType:cn})],Co);var $y,Ij=`${he}.46`,Yx=$y=class extends Co{constructor(e){super(e),Object.setPrototypeOf(this,$y.prototype)}};Yx=$y=b([A({type:v.Sequence,itemType:cn})],Yx);var Rj=`${he}.28`,ir=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};ir.ONLY=!1;b([l({type:Hn,context:0,optional:!0})],ir.prototype,"distributionPoint",void 0);b([l({type:h.Boolean,context:1,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsUserCerts",void 0);b([l({type:h.Boolean,context:2,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsCACerts",void 0);b([l({type:eu,context:3,optional:!0,implicit:!0})],ir.prototype,"onlySomeReasons",void 0);b([l({type:h.Boolean,context:4,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"indirectCRL",void 0);b([l({type:h.Boolean,context:5,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsAttributeCerts",void 0);var Jx=`${he}.21`,tu;(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"})(tu||(tu={}));var ru=class{constructor(e=tu.unspecified){this.reason=tu.unspecified,this.reason=e}toJSON(){return tu[this.reason]}toString(){return this.toJSON()}};b([l({type:h.Enumerated})],ru.prototype,"reason",void 0);ru=b([A({type:v.Choice})],ru);var Fy,Xf=`${he}.37`,nu=Fy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Fy.prototype)}};nu=Fy=b([A({type:v.Sequence,itemType:h.ObjectIdentifier})],nu);var Gj=`${Xf}.0`,Qx=`${ji}.1`,ev=`${ji}.2`,tv=`${ji}.3`,rv=`${ji}.4`,nv=`${ji}.8`,ov=`${ji}.9`;var Jj=`${he}.54`,Wy=class{constructor(e=new ArrayBuffer(0)){this.value=e}};b([l({type:h.Integer,converter:be})],Wy.prototype,"value",void 0);Wy=b([A({type:v.Choice})],Wy);var iv=`${he}.24`,ou=class{constructor(e){this.value=new Date,e&&(this.value=e)}};b([l({type:h.GeneralizedTime})],ou.prototype,"value",void 0);ou=b([A({type:v.Choice})],ou);var qy,Gy=`${he}.18`,sv=qy=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,qy.prototype)}};sv=qy=b([A({type:v.Sequence})],sv);var Zf=`${he}.15`,$r;(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"})($r||($r={}));var ea=class extends sn{toJSON(){let e=this.toNumber(),t=[];return e&$r.cRLSign&&t.push("crlSign"),e&$r.dataEncipherment&&t.push("dataEncipherment"),e&$r.decipherOnly&&t.push("decipherOnly"),e&$r.digitalSignature&&t.push("digitalSignature"),e&$r.encipherOnly&&t.push("encipherOnly"),e&$r.keyAgreement&&t.push("keyAgreement"),e&$r.keyCertSign&&t.push("keyCertSign"),e&$r.keyEncipherment&&t.push("keyEncipherment"),e&$r.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var zy,wR=`${he}.30`,ta=class{constructor(e={}){this.base=new ce,this.minimum=0,Object.assign(this,e)}};b([l({type:ce})],ta.prototype,"base",void 0);b([l({type:h.Integer,context:0,defaultValue:0,implicit:!0})],ta.prototype,"minimum",void 0);b([l({type:h.Integer,context:1,optional:!0,implicit:!0})],ta.prototype,"maximum",void 0);var Yf=zy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,zy.prototype)}};Yf=zy=b([A({type:v.Sequence,itemType:ta})],Yf);var Jf=class{constructor(e={}){Object.assign(this,e)}};b([l({type:Yf,context:0,optional:!0,implicit:!0})],Jf.prototype,"permittedSubtrees",void 0);b([l({type:Yf,context:1,optional:!0,implicit:!0})],Jf.prototype,"excludedSubtrees",void 0);var ER=`${he}.36`,Qf=class{constructor(e={}){Object.assign(this,e)}};b([l({type:h.Integer,context:0,implicit:!0,optional:!0,converter:be})],Qf.prototype,"requireExplicitPolicy",void 0);b([l({type:h.Integer,context:1,implicit:!0,optional:!0,converter:be})],Qf.prototype,"inhibitPolicyMapping",void 0);var Xy,BR=`${he}.33`,iu=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],iu.prototype,"issuerDomainPolicy",void 0);b([l({type:h.ObjectIdentifier})],iu.prototype,"subjectDomainPolicy",void 0);var av=Xy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};av=Xy=b([A({type:v.Sequence,itemType:iu})],av);var Zy,Yy=`${he}.17`,ep=Zy=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,Zy.prototype)}};ep=Zy=b([A({type:v.Sequence})],ep);var wt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};b([l({type:h.ObjectIdentifier})],wt.prototype,"type",void 0);b([l({type:h.Any,repeated:"set"})],wt.prototype,"values",void 0);var Jy,qR=`${he}.9`,cv=Jy=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Jy.prototype)}};cv=Jy=b([A({type:v.Sequence,itemType:wt})],cv);var Qy=`${he}.14`,zt=class extends Li{};var tL=`${he}.16`,tp=class{constructor(e={}){Object.assign(this,e)}};b([l({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],tp.prototype,"notBefore",void 0);b([l({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],tp.prototype,"notAfter",void 0);var su;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(su||(su={}));var rp=class extends sn{toJSON(){let e=[],t=this.toNumber();return t&su.pKIXCertificate&&e.push("pKIXCertificate"),t&su.newExtensions&&e.push("newExtensions"),t&su.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},np=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new rp,Object.assign(this,e)}};b([l({type:h.GeneralString})],np.prototype,"entrustVers",void 0);b([l({type:rp})],np.prototype,"entrustInfoFlags",void 0);var em,lL=`${Eo}.11`,uv=em=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,em.prototype)}};uv=em=b([A({type:v.Sequence,itemType:Mn})],uv);var lv=Xr(kn()),K=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&lv.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};b([l({type:h.ObjectIdentifier})],K.prototype,"algorithm",void 0);b([l({type:h.Any,optional:!0})],K.prototype,"parameters",void 0);var xt=class{constructor(e={}){this.algorithm=new K,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};b([l({type:K})],xt.prototype,"algorithm",void 0);b([l({type:h.BitString})],xt.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}};b([l({type:h.UTCTime})],Ze.prototype,"utcTime",void 0);b([l({type:h.GeneralizedTime})],Ze.prototype,"generalTime",void 0);Ze=b([A({type:v.Choice})],Ze);var Vn=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))}};b([l({type:Ze})],Vn.prototype,"notBefore",void 0);b([l({type:Ze})],Vn.prototype,"notAfter",void 0);var tm,vt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new se,Object.assign(this,e)}};vt.CRITICAL=!1;b([l({type:h.ObjectIdentifier})],vt.prototype,"extnID",void 0);b([l({type:h.Boolean,defaultValue:vt.CRITICAL})],vt.prototype,"critical",void 0);b([l({type:se})],vt.prototype,"extnValue",void 0);var sr=tm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,tm.prototype)}};sr=tm=b([A({type:v.Sequence,itemType:vt})],sr);var un;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(un||(un={}));var _t=class{constructor(e={}){this.version=un.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new K,this.issuer=new Ne,this.validity=new Vn,this.subject=new Ne,this.subjectPublicKeyInfo=new xt,Object.assign(this,e)}};b([l({type:h.Integer,context:0,defaultValue:un.v1})],_t.prototype,"version",void 0);b([l({type:h.Integer,converter:be})],_t.prototype,"serialNumber",void 0);b([l({type:K})],_t.prototype,"signature",void 0);b([l({type:Ne})],_t.prototype,"issuer",void 0);b([l({type:Vn})],_t.prototype,"validity",void 0);b([l({type:Ne})],_t.prototype,"subject",void 0);b([l({type:xt})],_t.prototype,"subjectPublicKeyInfo",void 0);b([l({type:h.BitString,context:1,implicit:!0,optional:!0})],_t.prototype,"issuerUniqueID",void 0);b([l({type:h.BitString,context:2,implicit:!0,optional:!0})],_t.prototype,"subjectUniqueID",void 0);b([l({type:sr,context:3,optional:!0})],_t.prototype,"extensions",void 0);var br=class{constructor(e={}){this.tbsCertificate=new _t,this.signatureAlgorithm=new K,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};b([l({type:_t})],br.prototype,"tbsCertificate",void 0);b([l({type:K})],br.prototype,"signatureAlgorithm",void 0);b([l({type:h.BitString})],br.prototype,"signatureValue",void 0);var Ki=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ze,Object.assign(this,e)}};b([l({type:h.Integer,converter:be})],Ki.prototype,"userCertificate",void 0);b([l({type:Ze})],Ki.prototype,"revocationDate",void 0);b([l({type:vt,optional:!0,repeated:"sequence"})],Ki.prototype,"crlEntryExtensions",void 0);var ar=class{constructor(e={}){this.signature=new K,this.issuer=new Ne,this.thisUpdate=new Ze,Object.assign(this,e)}};b([l({type:h.Integer,optional:!0})],ar.prototype,"version",void 0);b([l({type:K})],ar.prototype,"signature",void 0);b([l({type:Ne})],ar.prototype,"issuer",void 0);b([l({type:Ze})],ar.prototype,"thisUpdate",void 0);b([l({type:Ze,optional:!0})],ar.prototype,"nextUpdate",void 0);b([l({type:Ki,repeated:"sequence",optional:!0})],ar.prototype,"revokedCertificates",void 0);b([l({type:vt,optional:!0,context:0,repeated:"sequence"})],ar.prototype,"crlExtensions",void 0);var Hi=class{constructor(e={}){this.tbsCertList=new ar,this.signatureAlgorithm=new K,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};b([l({type:ar})],Hi.prototype,"tbsCertList",void 0);b([l({type:K})],Hi.prototype,"signatureAlgorithm",void 0);b([l({type:h.BitString})],Hi.prototype,"signature",void 0);var $=Xr(kn());function O(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 Fr=class{constructor(e={}){this.issuer=new Ne,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:Ne})],Fr.prototype,"issuer",void 0);O([l({type:h.Integer,converter:be})],Fr.prototype,"serialNumber",void 0);var Vi=class{constructor(e={}){Object.assign(this,e)}};O([l({type:zt,context:0,implicit:!0})],Vi.prototype,"subjectKeyIdentifier",void 0);O([l({type:Fr})],Vi.prototype,"issuerAndSerialNumber",void 0);Vi=O([A({type:v.Choice})],Vi);var St;(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"})(St||(St={}));var $i=class extends K{};$i=O([A({type:v.Sequence})],$i);var au=class extends K{};au=O([A({type:v.Sequence})],au);var Xt=class extends K{};Xt=O([A({type:v.Sequence})],Xt);var cu=class extends K{};cu=O([A({type:v.Sequence})],cu);var pv=class extends K{};pv=O([A({type:v.Sequence})],pv);var op=class extends K{};op=O([A({type:v.Sequence})],op);var Wr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],Wr.prototype,"attrType",void 0);O([l({type:h.Any,repeated:"set"})],Wr.prototype,"attrValues",void 0);var rm,Zt=class{constructor(e={}){this.version=St.v0,this.sid=new Vi,this.digestAlgorithm=new $i,this.signatureAlgorithm=new au,this.signature=new se,Object.assign(this,e)}};O([l({type:h.Integer})],Zt.prototype,"version",void 0);O([l({type:Vi})],Zt.prototype,"sid",void 0);O([l({type:$i})],Zt.prototype,"digestAlgorithm",void 0);O([l({type:Wr,repeated:"set",context:0,implicit:!0,optional:!0})],Zt.prototype,"signedAttrs",void 0);O([l({type:au})],Zt.prototype,"signatureAlgorithm",void 0);O([l({type:se})],Zt.prototype,"signature",void 0);O([l({type:Wr,repeated:"set",context:1,implicit:!0,optional:!0})],Zt.prototype,"unsignedAttrs",void 0);var uu=rm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};uu=rm=O([A({type:v.Set,itemType:Zt})],uu);var hv=class extends Ze{};hv=O([A({type:v.Choice})],hv);var dv=class extends Zt{};dv=O([A({type:v.Sequence})],dv);function z(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 lu=class{constructor(e={}){this.acIssuer=new ce,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([l({type:ce})],lu.prototype,"acIssuer",void 0);z([l({type:h.Integer})],lu.prototype,"acSerial",void 0);z([l({type:wt,repeated:"sequence"})],lu.prototype,"attrs",void 0);var nm,fu=nm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};fu=nm=z([A({type:v.Sequence,itemType:h.ObjectIdentifier})],fu);var ra=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([l({type:h.Integer,optional:!0})],ra.prototype,"pathLenConstraint",void 0);z([l({type:fu,implicit:!0,context:0,optional:!0})],ra.prototype,"permittedAttrs",void 0);z([l({type:fu,implicit:!0,context:1,optional:!0})],ra.prototype,"excludedAttrs",void 0);z([l({type:h.Boolean,defaultValue:!0})],ra.prototype,"permitUnSpecified",void 0);var wr=class{constructor(e={}){this.issuer=new Ve,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};z([l({type:Ve})],wr.prototype,"issuer",void 0);z([l({type:h.Integer,converter:be})],wr.prototype,"serial",void 0);z([l({type:h.BitString,optional:!0})],wr.prototype,"issuerUID",void 0);var om;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(om||(om={}));var xr=class{constructor(e={}){this.digestedObjectType=om.publicKey,this.digestAlgorithm=new K,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([l({type:h.Enumerated})],xr.prototype,"digestedObjectType",void 0);z([l({type:h.ObjectIdentifier,optional:!0})],xr.prototype,"otherObjectTypeID",void 0);z([l({type:K})],xr.prototype,"digestAlgorithm",void 0);z([l({type:h.BitString})],xr.prototype,"objectDigest",void 0);var Fi=class{constructor(e={}){Object.assign(this,e)}};z([l({type:Ve,optional:!0})],Fi.prototype,"issuerName",void 0);z([l({type:wr,context:0,implicit:!0,optional:!0})],Fi.prototype,"baseCertificateID",void 0);z([l({type:xr,context:1,implicit:!0,optional:!0})],Fi.prototype,"objectDigestInfo",void 0);var Wi=class{constructor(e={}){Object.assign(this,e)}};z([l({type:ce,repeated:"sequence"})],Wi.prototype,"v1Form",void 0);z([l({type:Fi,context:0,implicit:!0})],Wi.prototype,"v2Form",void 0);Wi=z([A({type:v.Choice})],Wi);var qi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([l({type:h.GeneralizedTime})],qi.prototype,"notBeforeTime",void 0);z([l({type:h.GeneralizedTime})],qi.prototype,"notAfterTime",void 0);var To=class{constructor(e={}){Object.assign(this,e)}};z([l({type:wr,implicit:!0,context:0,optional:!0})],To.prototype,"baseCertificateID",void 0);z([l({type:Ve,implicit:!0,context:1,optional:!0})],To.prototype,"entityName",void 0);z([l({type:xr,implicit:!0,context:2,optional:!0})],To.prototype,"objectDigestInfo",void 0);var im;(function(r){r[r.v2=1]="v2"})(im||(im={}));var Yt=class{constructor(e={}){this.version=im.v2,this.holder=new To,this.issuer=new Wi,this.signature=new K,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new qi,this.attributes=[],Object.assign(this,e)}};z([l({type:h.Integer})],Yt.prototype,"version",void 0);z([l({type:To})],Yt.prototype,"holder",void 0);z([l({type:Wi})],Yt.prototype,"issuer",void 0);z([l({type:K})],Yt.prototype,"signature",void 0);z([l({type:h.Integer,converter:be})],Yt.prototype,"serialNumber",void 0);z([l({type:qi})],Yt.prototype,"attrCertValidityPeriod",void 0);z([l({type:wt,repeated:"sequence"})],Yt.prototype,"attributes",void 0);z([l({type:h.BitString,optional:!0})],Yt.prototype,"issuerUniqueID",void 0);z([l({type:sr,optional:!0})],Yt.prototype,"extensions",void 0);var Gi=class{constructor(e={}){this.acinfo=new Yt,this.signatureAlgorithm=new K,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([l({type:Yt})],Gi.prototype,"acinfo",void 0);z([l({type:K})],Gi.prototype,"signatureAlgorithm",void 0);z([l({type:h.BitString})],Gi.prototype,"signatureValue",void 0);var pu;(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"})(pu||(pu={}));var na=class extends sn{};var oa=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([l({type:h.ObjectIdentifier,implicit:!0,context:0})],oa.prototype,"type",void 0);z([l({type:h.Any,implicit:!0,context:1})],oa.prototype,"value",void 0);var hu=class{constructor(e={}){this.policyId="",this.classList=new na(pu.unclassified),Object.assign(this,e)}};z([l({type:h.ObjectIdentifier})],hu.prototype,"policyId",void 0);z([l({type:na,defaultValue:new na(pu.unclassified)})],hu.prototype,"classList",void 0);z([l({type:oa,repeated:"set"})],hu.prototype,"securityCategories",void 0);var ia=class{constructor(e={}){Object.assign(this,e)}};z([l({type:se})],ia.prototype,"cotets",void 0);z([l({type:h.ObjectIdentifier})],ia.prototype,"oid",void 0);z([l({type:h.Utf8String})],ia.prototype,"string",void 0);var ip=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([l({type:Ve,implicit:!0,context:0,optional:!0})],ip.prototype,"policyAuthority",void 0);z([l({type:ia,repeated:"sequence"})],ip.prototype,"values",void 0);var q9=`${Eo}.4`,G9=`${Eo}.6`,z9=`${Eo}.10`,X9=`${he}.55`,du=`${Ao}.10`,Z9=`${du}.1`,Y9=`${du}.2`,J9=`${du}.3`,Q9=`${du}.4`,eK=`${du}.6`,sm="2.5.4",tK=`${sm}.72`;var am,sa=class{constructor(e={}){this.targetCertificate=new wr,Object.assign(this,e)}};z([l({type:wr})],sa.prototype,"targetCertificate",void 0);z([l({type:ce,optional:!0})],sa.prototype,"targetName",void 0);z([l({type:xr,optional:!0})],sa.prototype,"certDigestInfo",void 0);var aa=class{constructor(e={}){Object.assign(this,e)}};z([l({type:ce,context:0,implicit:!0})],aa.prototype,"targetName",void 0);z([l({type:ce,context:1,implicit:!0})],aa.prototype,"targetGroup",void 0);z([l({type:sa,context:2,implicit:!0})],aa.prototype,"targetCert",void 0);aa=z([A({type:v.Choice})],aa);var sp=am=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};sp=am=z([A({type:v.Sequence,itemType:aa})],sp);var cm,yv=cm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};yv=cm=z([A({type:v.Sequence,itemType:sp})],yv);var ap=class{constructor(e={}){Object.assign(this,e)}};z([l({type:Ve,implicit:!0,context:0,optional:!0})],ap.prototype,"roleAuthority",void 0);z([l({type:ce,implicit:!0,context:1})],ap.prototype,"roleName",void 0);var yu=class{constructor(e={}){this.service=new ce,this.ident=new ce,Object.assign(this,e)}};z([l({type:ce})],yu.prototype,"service",void 0);z([l({type:ce})],yu.prototype,"ident",void 0);z([l({type:se,optional:!0})],yu.prototype,"authInfo",void 0);var um,mu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],mu.prototype,"otherCertFormat",void 0);O([l({type:h.Any})],mu.prototype,"otherCert",void 0);var zi=class{constructor(e={}){Object.assign(this,e)}};O([l({type:br})],zi.prototype,"certificate",void 0);O([l({type:Gi,context:2,implicit:!0})],zi.prototype,"v2AttrCert",void 0);O([l({type:mu,context:3,implicit:!0})],zi.prototype,"other",void 0);zi=O([A({type:v.Choice})],zi);var Xi=um=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};Xi=um=O([A({type:v.Set,itemType:zi})],Xi);var vr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],vr.prototype,"contentType",void 0);O([l({type:h.Any,context:0})],vr.prototype,"content",void 0);var ca=class{constructor(e={}){Object.assign(this,e)}};O([l({type:se})],ca.prototype,"single",void 0);O([l({type:h.Any})],ca.prototype,"any",void 0);ca=O([A({type:v.Choice})],ca);var Zi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],Zi.prototype,"eContentType",void 0);O([l({type:ca,context:0,optional:!0})],Zi.prototype,"eContent",void 0);var gu=class{constructor(e={}){Object.assign(this,e)}};O([l({type:se,context:0,implicit:!0,optional:!0})],gu.prototype,"value",void 0);O([l({type:se,converter:Fx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],gu.prototype,"constructedValue",void 0);gu=O([A({type:v.Choice})],gu);var Io=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new cu,Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],Io.prototype,"contentType",void 0);O([l({type:cu})],Io.prototype,"contentEncryptionAlgorithm",void 0);O([l({type:gu,optional:!0})],Io.prototype,"encryptedContent",void 0);var Oo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],Oo.prototype,"keyAttrId",void 0);O([l({type:h.Any,optional:!0})],Oo.prototype,"keyAttr",void 0);var lm,ua=class{constructor(e={}){this.subjectKeyIdentifier=new zt,Object.assign(this,e)}};O([l({type:zt})],ua.prototype,"subjectKeyIdentifier",void 0);O([l({type:h.GeneralizedTime,optional:!0})],ua.prototype,"date",void 0);O([l({type:Oo,optional:!0})],ua.prototype,"other",void 0);var la=class{constructor(e={}){Object.assign(this,e)}};O([l({type:ua,context:0,implicit:!0,optional:!0})],la.prototype,"rKeyId",void 0);O([l({type:Fr,optional:!0})],la.prototype,"issuerAndSerialNumber",void 0);la=O([A({type:v.Choice})],la);var bu=class{constructor(e={}){this.rid=new la,this.encryptedKey=new se,Object.assign(this,e)}};O([l({type:la})],bu.prototype,"rid",void 0);O([l({type:se})],bu.prototype,"encryptedKey",void 0);var cp=lm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};cp=lm=O([A({type:v.Sequence,itemType:bu})],cp);var wu=class{constructor(e={}){this.algorithm=new K,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:K})],wu.prototype,"algorithm",void 0);O([l({type:h.BitString})],wu.prototype,"publicKey",void 0);var Yi=class{constructor(e={}){Object.assign(this,e)}};O([l({type:zt,context:0,implicit:!0,optional:!0})],Yi.prototype,"subjectKeyIdentifier",void 0);O([l({type:wu,context:1,implicit:!0,optional:!0})],Yi.prototype,"originatorKey",void 0);O([l({type:Fr,optional:!0})],Yi.prototype,"issuerAndSerialNumber",void 0);Yi=O([A({type:v.Choice})],Yi);var $n=class{constructor(e={}){this.version=St.v3,this.originator=new Yi,this.keyEncryptionAlgorithm=new Xt,this.recipientEncryptedKeys=new cp,Object.assign(this,e)}};O([l({type:h.Integer})],$n.prototype,"version",void 0);O([l({type:Yi,context:0})],$n.prototype,"originator",void 0);O([l({type:se,context:1,optional:!0})],$n.prototype,"ukm",void 0);O([l({type:Xt})],$n.prototype,"keyEncryptionAlgorithm",void 0);O([l({type:cp})],$n.prototype,"recipientEncryptedKeys",void 0);var fa=class{constructor(e={}){Object.assign(this,e)}};O([l({type:zt,context:0,implicit:!0})],fa.prototype,"subjectKeyIdentifier",void 0);O([l({type:Fr})],fa.prototype,"issuerAndSerialNumber",void 0);fa=O([A({type:v.Choice})],fa);var Bo=class{constructor(e={}){this.version=St.v0,this.rid=new fa,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new se,Object.assign(this,e)}};O([l({type:h.Integer})],Bo.prototype,"version",void 0);O([l({type:fa})],Bo.prototype,"rid",void 0);O([l({type:Xt})],Bo.prototype,"keyEncryptionAlgorithm",void 0);O([l({type:se})],Bo.prototype,"encryptedKey",void 0);var Ji=class{constructor(e={}){this.keyIdentifier=new se,Object.assign(this,e)}};O([l({type:se})],Ji.prototype,"keyIdentifier",void 0);O([l({type:h.GeneralizedTime,optional:!0})],Ji.prototype,"date",void 0);O([l({type:Oo,optional:!0})],Ji.prototype,"other",void 0);var Po=class{constructor(e={}){this.version=St.v4,this.kekid=new Ji,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new se,Object.assign(this,e)}};O([l({type:h.Integer})],Po.prototype,"version",void 0);O([l({type:Ji})],Po.prototype,"kekid",void 0);O([l({type:Xt})],Po.prototype,"keyEncryptionAlgorithm",void 0);O([l({type:se})],Po.prototype,"encryptedKey",void 0);var ko=class{constructor(e={}){this.version=St.v0,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new se,Object.assign(this,e)}};O([l({type:h.Integer})],ko.prototype,"version",void 0);O([l({type:op,context:0,optional:!0})],ko.prototype,"keyDerivationAlgorithm",void 0);O([l({type:Xt})],ko.prototype,"keyEncryptionAlgorithm",void 0);O([l({type:se})],ko.prototype,"encryptedKey",void 0);var xu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],xu.prototype,"oriType",void 0);O([l({type:h.Any})],xu.prototype,"oriValue",void 0);var Fn=class{constructor(e={}){Object.assign(this,e)}};O([l({type:Bo,optional:!0})],Fn.prototype,"ktri",void 0);O([l({type:$n,context:1,implicit:!0,optional:!0})],Fn.prototype,"kari",void 0);O([l({type:Po,context:2,implicit:!0,optional:!0})],Fn.prototype,"kekri",void 0);O([l({type:ko,context:3,implicit:!0,optional:!0})],Fn.prototype,"pwri",void 0);O([l({type:xu,context:4,implicit:!0,optional:!0})],Fn.prototype,"ori",void 0);Fn=O([A({type:v.Choice})],Fn);var fm,vu=fm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};vu=fm=O([A({type:v.Set,itemType:Fn})],vu);var pm,mv=`${Ao}.16`,eV=`${mv}.2`,tV=`${mv}.4`,pa=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};O([l({type:h.ObjectIdentifier})],pa.prototype,"otherRevInfoFormat",void 0);O([l({type:h.Any})],pa.prototype,"otherRevInfo",void 0);var up=class{constructor(e={}){this.other=new pa,Object.assign(this,e)}};O([l({type:pa,context:1,implicit:!0})],up.prototype,"other",void 0);up=O([A({type:v.Choice})],up);var ha=pm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,pm.prototype)}};ha=pm=O([A({type:v.Set,itemType:up})],ha);var da=class{constructor(e={}){Object.assign(this,e)}};O([l({type:Xi,context:0,implicit:!0,optional:!0})],da.prototype,"certs",void 0);O([l({type:ha,context:1,implicit:!0,optional:!0})],da.prototype,"crls",void 0);var hm,dm=hm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,hm.prototype)}};dm=hm=O([A({type:v.Set,itemType:Wr})],dm);var Qi=class{constructor(e={}){this.version=St.v0,this.recipientInfos=new vu,this.encryptedContentInfo=new Io,Object.assign(this,e)}};O([l({type:h.Integer})],Qi.prototype,"version",void 0);O([l({type:da,context:0,implicit:!0,optional:!0})],Qi.prototype,"originatorInfo",void 0);O([l({type:vu})],Qi.prototype,"recipientInfos",void 0);O([l({type:Io})],Qi.prototype,"encryptedContentInfo",void 0);O([l({type:dm,context:1,implicit:!0,optional:!0})],Qi.prototype,"unprotectedAttrs",void 0);var gv="1.2.840.113549.1.7.2";var ym,lp=ym=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,ym.prototype)}};lp=ym=O([A({type:v.Set,itemType:$i})],lp);var Wn=class{constructor(e={}){this.version=St.v0,this.digestAlgorithms=new lp,this.encapContentInfo=new Zi,this.signerInfos=new uu,Object.assign(this,e)}};O([l({type:h.Integer})],Wn.prototype,"version",void 0);O([l({type:lp})],Wn.prototype,"digestAlgorithms",void 0);O([l({type:Zi})],Wn.prototype,"encapContentInfo",void 0);O([l({type:Xi,context:0,implicit:!0,optional:!0})],Wn.prototype,"certificates",void 0);O([l({type:ha,context:1,implicit:!0,optional:!0})],Wn.prototype,"crls",void 0);O([l({type:uu})],Wn.prototype,"signerInfos",void 0);var es="1.2.840.10045.2.1";var _u="1.2.840.10045.4.1",fp="1.2.840.10045.4.3.1",Su="1.2.840.10045.4.3.2",Au="1.2.840.10045.4.3.3",Eu="1.2.840.10045.4.3.4";var mm="1.2.840.10045.3.1.7";var gm="1.3.132.0.34";var bm="1.3.132.0.35";function Cu(r){return new K({algorithm:r})}var wv=Cu(_u),YV=Cu(fp),xv=Cu(Su),vv=Cu(Au),_v=Cu(Eu);function De(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 Tu=class{constructor(e={}){Object.assign(this,e)}};De([l({type:h.ObjectIdentifier})],Tu.prototype,"fieldType",void 0);De([l({type:h.Any})],Tu.prototype,"parameters",void 0);Tu=De([A({type:v.Sequence})],Tu);var wm=class extends se{};var ya=class{constructor(e={}){Object.assign(this,e)}};De([l({type:h.OctetString})],ya.prototype,"a",void 0);De([l({type:h.OctetString})],ya.prototype,"b",void 0);De([l({type:h.BitString,optional:!0})],ya.prototype,"seed",void 0);ya=De([A({type:v.Sequence})],ya);var xm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(xm||(xm={}));var ln=class{constructor(e={}){this.version=xm.ecpVer1,Object.assign(this,e)}};De([l({type:h.Integer})],ln.prototype,"version",void 0);De([l({type:Tu})],ln.prototype,"fieldID",void 0);De([l({type:ya})],ln.prototype,"curve",void 0);De([l({type:wm})],ln.prototype,"base",void 0);De([l({type:h.Integer,converter:be})],ln.prototype,"order",void 0);De([l({type:h.Integer,optional:!0})],ln.prototype,"cofactor",void 0);ln=De([A({type:v.Sequence})],ln);var fn=class{constructor(e={}){Object.assign(this,e)}};De([l({type:h.ObjectIdentifier})],fn.prototype,"namedCurve",void 0);De([l({type:h.Null})],fn.prototype,"implicitCurve",void 0);De([l({type:ln})],fn.prototype,"specifiedCurve",void 0);fn=De([A({type:v.Choice})],fn);var ma=class{constructor(e={}){this.version=1,this.privateKey=new se,Object.assign(this,e)}};De([l({type:h.Integer})],ma.prototype,"version",void 0);De([l({type:se})],ma.prototype,"privateKey",void 0);De([l({type:fn,context:0,optional:!0})],ma.prototype,"parameters",void 0);De([l({type:h.BitString,context:1,optional:!0})],ma.prototype,"publicKey",void 0);var ts=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};De([l({type:h.Integer,converter:be})],ts.prototype,"r",void 0);De([l({type:h.Integer,converter:be})],ts.prototype,"s",void 0);function Oe(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 Jt="1.2.840.113549.1.1",pn=`${Jt}.1`,Sv=`${Jt}.7`,Av=`${Jt}.9`,No=`${Jt}.10`,Ev=`${Jt}.2`,Cv=`${Jt}.4`,ga=`${Jt}.5`,Tv=`${Jt}.14`;var pp=`${Jt}.11`,ba=`${Jt}.12`,wa=`${Jt}.13`,vm=`${Jt}.15`,_m=`${Jt}.16`,rs="1.3.14.3.2.26",hp="2.16.840.1.101.3.4.2.4",ns="2.16.840.1.101.3.4.2.1",os="2.16.840.1.101.3.4.2.2",is="2.16.840.1.101.3.4.2.3",Iv="2.16.840.1.101.3.4.2.5",Ov="2.16.840.1.101.3.4.2.6",Bv="1.2.840.113549.2.2",Pv="1.2.840.113549.2.5",Do=`${Jt}.8`;function pt(r){return new K({algorithm:r,parameters:null})}var T7=pt(Bv),I7=pt(Pv),qn=pt(rs),O7=pt(hp),B7=pt(ns),P7=pt(os),k7=pt(is),N7=pt(Iv),D7=pt(Ov),dp=new K({algorithm:Do,parameters:q.serialize(qn)}),Sm=new K({algorithm:Av,parameters:q.serialize(Js.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),j7=pt(pn),R7=pt(Ev),L7=pt(Cv),U7=pt(ga),M7=pt(vm),K7=pt(_m),H7=pt(ba),V7=pt(wa),$7=pt(vm),F7=pt(_m);var xa=class{constructor(e={}){this.hashAlgorithm=new K(qn),this.maskGenAlgorithm=new K({algorithm:Do,parameters:q.serialize(qn)}),this.pSourceAlgorithm=new K(Sm),Object.assign(this,e)}};Oe([l({type:K,context:0,defaultValue:qn})],xa.prototype,"hashAlgorithm",void 0);Oe([l({type:K,context:1,defaultValue:dp})],xa.prototype,"maskGenAlgorithm",void 0);Oe([l({type:K,context:2,defaultValue:Sm})],xa.prototype,"pSourceAlgorithm",void 0);var Y7=new K({algorithm:Sv,parameters:q.serialize(new xa)});var hn=class{constructor(e={}){this.hashAlgorithm=new K(qn),this.maskGenAlgorithm=new K({algorithm:Do,parameters:q.serialize(qn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Oe([l({type:K,context:0,defaultValue:qn})],hn.prototype,"hashAlgorithm",void 0);Oe([l({type:K,context:1,defaultValue:dp})],hn.prototype,"maskGenAlgorithm",void 0);Oe([l({type:h.Integer,context:2,defaultValue:20})],hn.prototype,"saltLength",void 0);Oe([l({type:h.Integer,context:3,defaultValue:1})],hn.prototype,"trailerField",void 0);var o$=new K({algorithm:No,parameters:q.serialize(new hn)});var ss=class{constructor(e={}){this.digestAlgorithm=new K,this.digest=new se,Object.assign(this,e)}};Oe([l({type:K})],ss.prototype,"digestAlgorithm",void 0);Oe([l({type:se})],ss.prototype,"digest",void 0);var Am,va=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Oe([l({type:h.Integer,converter:be})],va.prototype,"prime",void 0);Oe([l({type:h.Integer,converter:be})],va.prototype,"exponent",void 0);Oe([l({type:h.Integer,converter:be})],va.prototype,"coefficient",void 0);var yp=Am=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Am.prototype)}};yp=Am=Oe([A({type:v.Sequence,itemType:va})],yp);var _r=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)}};Oe([l({type:h.Integer})],_r.prototype,"version",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"modulus",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"publicExponent",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"privateExponent",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"prime1",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"prime2",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"exponent1",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"exponent2",void 0);Oe([l({type:h.Integer,converter:be})],_r.prototype,"coefficient",void 0);Oe([l({type:yp,optional:!0})],_r.prototype,"otherPrimeInfos",void 0);var _a=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Oe([l({type:h.Integer,converter:be})],_a.prototype,"modulus",void 0);Oe([l({type:h.Integer,converter:be})],_a.prototype,"publicExponent",void 0);function Iu(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 Em;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Em||(Em={}));var At=Em;var Qv=Xr(Jv(),1),{__extends:Aa,__assign:R$,__rest:fT,__decorate:L$,__param:U$,__metadata:M$,__awaiter:e1,__generator:t1,__exportStar:K$,__createBinding:H$,__values:Ou,__read:Bu,__spread:qr,__spreadArrays:V$,__await:$$,__asyncGenerator:F$,__asyncDelegator:W$,__asyncValues:q$,__makeTemplateObject:G$,__importStar:z$,__importDefault:X$,__classPrivateFieldGet:Z$,__classPrivateFieldSet:Y$}=Qv.default;var pT="injectionTokens";function Tm(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(pT,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function Pu(r){return!!r.useClass}function Ea(r){return!!r.useFactory}var bp=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,qr(i))}};return this.reflectMethods.forEach(n),t},r}();function jo(r){return typeof r=="string"||typeof r=="symbol"}function Im(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function wp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function r1(r){return typeof r=="function"||r instanceof bp}function as(r){return!!r.useToken}function cs(r){return r.useValue!=null}function n1(r){return Pu(r)||cs(r)||as(r)||Ea(r)}var hT=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}(),ku=hT;var dT=function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(ku),o1=dT;var yT=function(){function r(){this.scopedResolutions=new Map}return r}(),Nu=yT;function mT(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function gT(r,e,t){return t===void 0&&(t=" "),qr([r],e.message.split(`
7
7
  `).map(function(n){return t+n})).join(`
8
- `)}function pm(r,e,t){var n=bu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=qC(i,e);return zC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function Kv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var XC=function(r){ca(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(vu);var ZC=function(r){ca(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(vu);var YC=function(){function r(){this.preResolution=new XC,this.postResolution=new ZC}return r}(),Hv=YC;var hm=new Map,JC=function(){function r(e){this.parent=e,this._registry=new Mv,this.interceptors=new Hv,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:bt.Transient}),this.ensureNotDisposed();var o;if(Uv(t)?o=t:o={useClass:t},Wi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Hr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Wi(c.provider)?s=c.provider:s=null}if((n.lifecycle===bt.Singleton||n.lifecycle==bt.ContainerScoped||n.lifecycle==bt.ResolutionScoped)&&(Gi(o)||ua(o)))throw new Error('Cannot use lifecycle "'+bt[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(),So(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(),So(e)){if(So(t))return this.register(e,{useToken:t},{lifecycle:bt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:bt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!So(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:bt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new _u),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&So(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(Lv(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=wu(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(l){n={error:l}}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=wu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var l=c.value;l.options.frequency!="Once"&&s.push(l),l.callback(e,t,n)}}catch(f){o={error:f}}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===bt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===bt.Singleton,o=e.options.lifecycle===bt.ContainerScoped,i=n||o,s;return Gi(e.provider)?s=e.provider.useValue:Wi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):xu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ua(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===bt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new _u),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&So(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=wu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=bu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Gi(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=wu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=bu(i.value,2),a=s[0],c=s[1];c.some(function(l){var f=l.options;return f.lifecycle===bt.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===bt.ContainerScoped?{provider:l.provider,options:l.options}:l}))}}catch(l){e={error:l}}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 jv(this,void 0,void 0,function(){var e;return Rv(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 cp)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=hm.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,Hr([void 0],s)))}();return Kv(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 fm(o)?up(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Hr([n.resolveAll(o.token,new _u,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Hr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new _u,o.isOptional):n.resolve(o.token,e,o.isOptional):up(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Hr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(pm(t,i,l))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r}(),Le=new JC;function QC(r){return function(e){hm.set(e,lm(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Le.register(t,e)}):Le.register(r.token,e))}}var Ao=QC;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.`);function _e(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}function Se(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 ym,qi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Se([u({type:h.ObjectIdentifier})],qi.prototype,"attrId",void 0);Se([u({type:h.Any,repeated:"set"})],qi.prototype,"attrValues",void 0);var Vv=ym=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ym.prototype)}};Vv=ym=Se([A({type:_.Sequence,itemType:qi})],Vv);var mm,$v=mm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};$v=mm=Se([A({type:_.Sequence,itemType:gr})],$v);var eT="1.2.840.113549",tT=`${eT}.1`,Fv=`${tT}.12`,la=`${Fv}.1`,LW=`${la}.1`,UW=`${la}.2`,MW=`${la}.3`,KW=`${la}.4`,HW=`${la}.5`,VW=`${la}.6`,zi=`${Fv}.10.1`;var WW=`${zi}.1`,GW=`${zi}.2`,qW=`${zi}.3`,zW=`${zi}.4`,XW=`${zi}.5`,ZW=`${zi}.6`,lp="1.2.840.113549.1.9";var fp=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],fp.prototype,"certId",void 0);Se([u({type:h.Any,context:0})],fp.prototype,"certValue",void 0);var Wv=`${lp}.22`,tG=`${Wv}.1`,rG=`${Wv}.2`;var pp=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],pp.prototype,"crlId",void 0);Se([u({type:h.Any,context:0})],pp.prototype,"crltValue",void 0);var rT=`${lp}.23`,aG=`${rT}.1`;function Rn(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 hp=class extends ae{},Eo=class{constructor(e={}){this.encryptionAlgorithm=new H,this.encryptedData=new hp,Object.assign(this,e)}};Rn([u({type:H})],Eo.prototype,"encryptionAlgorithm",void 0);Rn([u({type:hp})],Eo.prototype,"encryptedData",void 0);var gm,wm;(function(r){r[r.v1=0]="v1"})(wm||(wm={}));var dp=class extends ae{},bm=gm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};bm=gm=Rn([A({type:_.Sequence,itemType:dt})],bm);var Co=class{constructor(e={}){this.version=wm.v1,this.privateKeyAlgorithm=new H,this.privateKey=new dp,Object.assign(this,e)}};Rn([u({type:h.Integer})],Co.prototype,"version",void 0);Rn([u({type:H})],Co.prototype,"privateKeyAlgorithm",void 0);Rn([u({type:dp})],Co.prototype,"privateKey",void 0);Rn([u({type:bm,implicit:!0,context:0,optional:!0})],Co.prototype,"attributes",void 0);var Gv=class extends Co{};Gv=Se([A({type:_.Sequence})],Gv);var qv=class extends Eo{};qv=Se([A({type:_.Sequence})],qv);var yp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],yp.prototype,"secretTypeId",void 0);Se([u({type:h.Any,context:0})],yp.prototype,"secretValue",void 0);var To=class{constructor(e={}){this.mac=new Fi,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Se([u({type:Fi})],To.prototype,"mac",void 0);Se([u({type:ae})],To.prototype,"macSalt",void 0);Se([u({type:h.Integer,defaultValue:1})],To.prototype,"iterations",void 0);var Xi=class{constructor(e={}){this.version=3,this.authSafe=new gr,this.macData=new To,Object.assign(this,e)}};Se([u({type:h.Integer})],Xi.prototype,"version",void 0);Se([u({type:gr})],Xi.prototype,"authSafe",void 0);Se([u({type:To,optional:!0})],Xi.prototype,"macData",void 0);var xm,fa=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],fa.prototype,"bagId",void 0);Se([u({type:h.Any,context:0})],fa.prototype,"bagValue",void 0);Se([u({type:qi,repeated:"set",optional:!0})],fa.prototype,"bagAttributes",void 0);var zv=xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};zv=xm=Se([A({type:_.Sequence,itemType:fa})],zv);var vm,_m,Sm,qe="1.2.840.113549.1.9",lq=`${qe}.0`,c1=`${qe}.24`,Au=`${qe}.25`,u1=`${qe}.26`,l1=`${qe}.27`,fq=`${c1}.1`,pq=`${c1}.2`,hq=`${qe}.1`,dq=`${qe}.2`,yq=`${qe}.3`,mq=`${qe}.4`,gq=`${qe}.5`,wq=`${qe}.6`,Bm=`${qe}.7`,bq=`${qe}.8`,xq=`${qe}.9`,vq=`${qe}.13`,Eu=`${qe}.14`,_q=`${qe}.15`,Sq=`${qe}.20`,Aq=`${qe}.21`;var Eq=`${Au}.1`,Cq=`${Au}.2`,Tq=`${Au}.3`,Iq=`${Au}.4`,Oq=`${Au}.5`,Cu="1.3.6.1.5.5.7.9",Pq=`${Cu}.1`,Bq=`${Cu}.2`,Nq=`${Cu}.3`,kq=`${Cu}.4`,Dq=`${Cu}.5`,jq=`${u1}.1`,Rq=`${u1}.2`,Lq=`${l1}.1`,Uq=`${l1}.2`,Mq=`${qe}.16`,Kq=`${qe}.22`,Hq=`${qe}.23`,Vq=`${$y}.65`,mp=class extends et{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};_e([u({type:h.IA5String})],mp.prototype,"ia5String",void 0);mp=_e([A({type:_.Choice})],mp);var Xv=class extends gr{};Xv=_e([A({type:_.Sequence})],Xv);var Zv=class extends Xi{};Zv=_e([A({type:_.Sequence})],Zv);var Yv=class extends Eo{};Yv=_e([A({type:_.Sequence})],Yv);var Am=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.IA5String})],Am.prototype,"value",void 0);Am=_e([A({type:_.Choice})],Am);var Jv=class extends mp{};Jv=_e([A({type:_.Choice})],Jv);var Qv=class extends et{};Qv=_e([A({type:_.Choice})],Qv);var Em=class{constructor(e=new Date){this.value=e}};_e([u({type:h.GeneralizedTime})],Em.prototype,"value",void 0);Em=_e([A({type:_.Choice})],Em);var e1=class extends et{};e1=_e([A({type:_.Choice})],e1);var Cm=class{constructor(e="M"){this.value=e}toString(){return this.value}};_e([u({type:h.PrintableString})],Cm.prototype,"value",void 0);Cm=_e([A({type:_.Choice})],Cm);var gp=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.PrintableString})],gp.prototype,"value",void 0);gp=_e([A({type:_.Choice})],gp);var t1=class extends gp{};t1=_e([A({type:_.Choice})],t1);var r1=class extends et{};r1=_e([A({type:_.Choice})],r1);var Tm=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.ObjectIdentifier})],Tm.prototype,"value",void 0);Tm=_e([A({type:_.Choice})],Tm);var n1=class extends Ge{};n1=_e([A({type:_.Choice})],n1);var Im=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};_e([u({type:h.Integer})],Im.prototype,"value",void 0);Im=_e([A({type:_.Choice})],Im);var o1=class extends qt{};o1=_e([A({type:_.Sequence})],o1);var Su=class extends et{};Su=_e([A({type:_.Choice})],Su);var i1=vm=class extends nr{constructor(e){super(e),Object.setPrototypeOf(this,vm.prototype)}};i1=vm=_e([A({type:_.Sequence})],i1);var s1=_m=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};s1=_m=_e([A({type:_.Set,itemType:Kr})],s1);var Om=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.BmpString})],Om.prototype,"value",void 0);Om=_e([A({type:_.Choice})],Om);var Pm=class extends H{};Pm=_e([A({type:_.Sequence})],Pm);var a1=Sm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sm.prototype)}};a1=Sm=_e([A({type:_.Sequence,itemType:Pm})],a1);function Vr(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 Nm,Tu=Nm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Nm.prototype)}};Tu=Nm=Vr([A({type:_.Sequence,itemType:dt})],Tu);var ln=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new yt,this.attributes=new Tu,Object.assign(this,e)}};Vr([u({type:h.Integer})],ln.prototype,"version",void 0);Vr([u({type:Pe})],ln.prototype,"subject",void 0);Vr([u({type:yt})],ln.prototype,"subjectPKInfo",void 0);Vr([u({type:Tu,implicit:!0,context:0})],ln.prototype,"attributes",void 0);var Io=class{constructor(e={}){this.certificationRequestInfo=new ln,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Vr([u({type:ln})],Io.prototype,"certificationRequestInfo",void 0);Vr([u({type:H})],Io.prototype,"signatureAlgorithm",void 0);Vr([u({type:h.BitString})],Io.prototype,"signature",void 0);var ku="crypto.algorithm",Vm=class{getAlgorithms(){return Le.resolveAll(ku)}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 H({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}}},Zi="crypto.algorithmProvider";Le.registerSingleton(Zi,Vm);var vp,Yt="1.3.36.3.3.2.8.1.1",f1=`${Yt}.1`,p1=`${Yt}.2`,h1=`${Yt}.3`,d1=`${Yt}.4`,y1=`${Yt}.5`,m1=`${Yt}.6`,g1=`${Yt}.7`,w1=`${Yt}.8`,b1=`${Yt}.9`,x1=`${Yt}.10`,v1=`${Yt}.11`,_1=`${Yt}.12`,S1=`${Yt}.13`,A1=`${Yt}.14`,E1="brainpoolP160r1",C1="brainpoolP160t1",T1="brainpoolP192r1",I1="brainpoolP192t1",O1="brainpoolP224r1",P1="brainpoolP224t1",B1="brainpoolP256r1",N1="brainpoolP256t1",k1="brainpoolP320r1",D1="brainpoolP320t1",j1="brainpoolP384r1",R1="brainpoolP384t1",L1="brainpoolP512r1",U1="brainpoolP512t1",$e="ECDSA",Ou=vp=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case $e.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return ev;case"sha-256":return tv;case"sha-384":return rv;case"sha-512":return nv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Qy;break;case"K-256":t=vp.SECP256K1;break;case"P-384":t=em;break;case"P-521":t=tm;break;case E1:t=f1;break;case C1:t=p1;break;case T1:t=h1;break;case I1:t=d1;break;case O1:t=y1;break;case P1:t=m1;break;case B1:t=g1;break;case N1:t=w1;break;case k1:t=b1;break;case D1:t=x1;break;case j1:t=v1;break;case R1:t=_1;break;case L1:t=S1;break;case U1:t=A1;break}if(t)return new H({algorithm:Ui,parameters:W.serialize(new an({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case fu:return{name:$e,hash:{name:"SHA-1"}};case pu:return{name:$e,hash:{name:"SHA-256"}};case hu:return{name:$e,hash:{name:"SHA-384"}};case du:return{name:$e,hash:{name:"SHA-512"}};case Ui:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(W.parse(e.parameters,an).namedCurve){case Qy:return{name:$e,namedCurve:"P-256"};case vp.SECP256K1:return{name:$e,namedCurve:"K-256"};case em:return{name:$e,namedCurve:"P-384"};case tm:return{name:$e,namedCurve:"P-521"};case f1:return{name:$e,namedCurve:E1};case p1:return{name:$e,namedCurve:C1};case h1:return{name:$e,namedCurve:T1};case d1:return{name:$e,namedCurve:I1};case y1:return{name:$e,namedCurve:O1};case m1:return{name:$e,namedCurve:P1};case g1:return{name:$e,namedCurve:B1};case w1:return{name:$e,namedCurve:N1};case b1:return{name:$e,namedCurve:k1};case x1:return{name:$e,namedCurve:D1};case v1:return{name:$e,namedCurve:j1};case _1:return{name:$e,namedCurve:R1};case S1:return{name:$e,namedCurve:L1};case A1:return{name:$e,namedCurve:U1}}}}return null}};Ou.SECP256K1="1.3.132.0.10";Ou=vp=gu([Ao()],Ou);Le.registerSingleton(ku,Ou);var X1=Symbol("name"),Z1=Symbol("value"),xe=class{constructor(e,t={},n=""){this[X1]=e,this[Z1]=n;for(let o in t)this[o]=t[o]}};xe.NAME=X1;xe.VALUE=Z1;var $m=class{static toTextObject(e){let t=new xe("Algorithm Identifier",{},pn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Ui:{let n=new Ou().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},pn=class{static toString(e){let t=this.items[e];return t||e}};pn.items={[Ki]:"sha1",[np]:"sha224",[Hi]:"sha256",[Vi]:"sha384",[$i]:"sha512",[cn]:"rsaEncryption",[ta]:"sha1WithRSAEncryption",[cv]:"sha224WithRSAEncryption",[rp]:"sha256WithRSAEncryption",[ra]:"sha384WithRSAEncryption",[na]:"sha512WithRSAEncryption",[Ui]:"ecPublicKey",[fu]:"ecdsaWithSHA1",[tp]:"ecdsaWithSHA224",[pu]:"ecdsaWithSHA256",[hu]:"ecdsaWithSHA384",[du]:"ecdsaWithSHA512",[Dx]:"TLS WWW server authentication",[jx]:"TLS WWW client authentication",[Rx]:"Code Signing",[Lx]:"E-mail Protection",[Ux]:"Time Stamping",[Mx]:"OCSP Signing",[Jx]:"Signed Data"};var Un=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[xe.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[xe.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],l=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${l}${c}`);else if(c instanceof Date)n.push(`${o}${l}${c.toUTCString()}`);else if(Array.isArray(c))for(let f of c)f[xe.NAME]=a,n.push(...this.serializeObj(f,t));else if(c instanceof xe)c[xe.NAME]=a,n.push(...this.serializeObj(c,t));else if(V.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${l}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let f=c.toTextObject();f[xe.NAME]=a,n.push(...this.serializeObj(f,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 l=o[s++].toString(16).padStart(2,"0");a.push(l)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Un.oidSerializer=pn;Un.algorithmSerializer=$m;var Oo=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=W.serialize(t),this.onInit(t)}else{let t=W.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 W.toString(this.rawData);case"text":return Un.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 xe(this.getTextName(),{},e)}};Oo.NAME="ASN";var ir=class r extends Oo{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=W.serialize(new mt({extnID:e[0],critical:e[1],extnValue:new ae(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,mt)}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[xe.NAME]===r.NAME&&(e[xe.NAME]=pn.toString(this.type)),e}},Y1,Pu=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[Y1]="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}};Y1=Symbol.toStringTag;Pu.DEFAULT="default";var xt=new Pu,sT=/^[0-2](?:\.[1-9][0-9]*)+$/;function aT(r){return new RegExp(sT).test(r)}var Sp=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 aT(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Zt=new Sp;Zt.register("CN","2.5.4.3");Zt.register("L","2.5.4.7");Zt.register("ST","2.5.4.8");Zt.register("O","2.5.4.10");Zt.register("OU","2.5.4.11");Zt.register("C","2.5.4.6");Zt.register("DC","0.9.2342.19200300.100.1.25");Zt.register("E","1.2.840.113549.1.9.1");Zt.register("G","2.5.4.42");Zt.register("I","2.5.4.43");Zt.register("SN","2.5.4.4");Zt.register("T","2.5.4.12");function cT(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function uT(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,cT)}var br=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 Sp,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=W.parse(e,Pe):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Zt.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)||Zt.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)}`:uT(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 l=o[3];s=this.getTypeOid(s);let f=this.createAttribute(s,a);i==="+"?t[t.length-1].push(f):t.push(new uo([f])),i=l}return t}fromJSON(e){let t=new Pe;for(let n of e){let o=new uo;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let l=this.createAttribute(s,c);o.push(l)}}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 wi({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 W.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]||xt.get()):n=e[0]||xt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},J1="Cannot initialize GeneralName from ASN.1 data.",M1=`${J1} Unsupported string format in use.`,lT=`${J1} Value doesn't match to GUID regular expression.`,K1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,H1="1.3.6.1.4.1.311.25.1",V1="1.3.6.1.4.1.311.20.2.3",km="dns",Dm="dn",jm="email",Rm="ip",Lm="url",Um="guid",Mm="upn",wp="id",fn=class extends Oo{constructor(...e){let t;if(e.length===2)switch(e[0]){case Dm:{let n=new br(e[1]).toArrayBuffer(),o=W.parse(n,Pe);t=new ue({directoryName:o});break}case km:t=new ue({dNSName:e[1]});break;case jm:t=new ue({rfc822Name:e[1]});break;case Um:{let n=new RegExp(K1,"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 ue({otherName:new lo({typeId:H1,value:W.serialize(new ae(V.Convert.FromHex(o)))})});break}case Rm:t=new ue({iPAddress:e[1]});break;case wp:t=new ue({registeredID:e[1]});break;case Mm:{t=new ue({otherName:new lo({typeId:V1,value:W.serialize(uy.toASN(e[1]))})});break}case Lm:t=new ue({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else V.BufferSourceConverter.isBufferSource(e[0])?t=W.parse(e[0],ue):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=km,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=jm,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=Rm,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Lm,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=wp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Dm,this.value=new br(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===H1){this.type=Um;let t=W.parse(e.otherName.value,ae),n=new RegExp(K1,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(lT);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===V1)this.type=Mm,this.value=W.parse(e.otherName.value,et).toString();else throw new Error(M1);else throw new Error(M1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Dm:case km:case Um:case Rm:case wp:case Mm:case Lm:e=this.type.toUpperCase();break;case jm:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===wp&&(t=pn.toString(t)),new xe(e,void 0,t)}},Mn=class extends Oo{constructor(e){let t;if(e instanceof Ke)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ue)n.push(o);else{let i=W.parse(new fn(o.type,o.value).rawData,ue);n.push(i)}t=new Ke(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=W.parse(e,Ke);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 fn(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[xe.NAME]];Array.isArray(o)||(o=[],e[n[xe.NAME]]=o),o.push(n)}return e}};Mn.NAME="GeneralNames";var Iu="-{5}",Bu="\\n",fT=`[^${Bu}]+`,pT=`${Iu}BEGIN (${fT}(?=${Iu}))${Iu}`,hT=`${Iu}END \\1${Iu}`,pa="\\n",dT=`[^:${Bu}]+`,yT=`(?:[^${Bu}]+${pa}(?: +[^${Bu}]+${pa})*)`,mT="[a-zA-Z0-9=+/]+",gT=`(?:${mT}${pa})+`,$1=`${pT}${pa}(?:((?:${dT}: ${yT})+))?${pa}?(${gT})${hT}`,Lt=class{static isPem(e){return typeof e=="string"&&new RegExp($1,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp($1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${Bu}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(pa,"g")),l=null;for(let f of c){let[p,y]=f.split(/:(.*)/);if(y===void 0){if(!l)throw new Error("Cannot parse PEM string. Incorrect header value");l.value+=p.trim()}else l&&s.headers.push(l),l={key:p,value:y.trim()}}l&&s.headers.push(l)}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
- `)}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 l of e.headers)o.push(`${l.key}: ${l.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
- `)}};Lt.CertificateTag="CERTIFICATE";Lt.CrlTag="CRL";Lt.CertificateRequestTag="CERTIFICATE REQUEST";Lt.PublicKeyTag="PUBLIC KEY";Lt.PrivateKeyTag="PRIVATE KEY";var Po=class r extends Oo{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Lt.isPem(e))return Lt.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 Lt.isPem(t)?Lt.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 Lt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Ln=class r extends Po{static async create(e,t=xt.get()){if(e instanceof r)return e;if(Pu.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){Po.isAsnEncoded(e)?super(e,yt):super(e),this.tag=Lt.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]||xt.get()):t=e[0]||xt.get();let i=this.rawData,s=W.parse(this.rawData,yt);return s.algorithm.algorithm===vo&&(i=wT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Le.resolve(Zi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case cn:{let o=W.parse(e.subjectPublicKey,sa),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]||xt.get()):n=e[0]||xt.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=xt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=xt.get();let o=W.parse(this.rawData,yt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,yt);switch(e.Algorithm=Un.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ui:e["EC Point"]=t.subjectPublicKey;break;case cn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function wT(r,e){return r.algorithm=new H({algorithm:cn,parameters:null}),e=W.serialize(r),e}var Ap=class r extends ir{static async create(e,t=!1,n=xt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Ln.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 rn({keyIdentifier:new vi(V.Convert.FromHex(e[0]))});super(Df,e[1],W.serialize(t))}else{let t=e[0],n=t.name instanceof Mn?W.parse(t.name.rawData,Ke):t.name,o=new rn({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(Df,e[1],W.serialize(o))}}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,rn);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=W.parse(this.value,rn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Mn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Ap.NAME="Authority Key Identifier";var ha=class extends ir{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,_i);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new _i({cA:e[0],pathLenConstraint:e[1]});super(jf,e[2],W.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}};ha.NAME="Basic Constraints";var F1;(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"})(F1||(F1={}));var Ep=class extends ir{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,Gc);this.usages=t.map(n=>n)}else{let t=new Gc(e[0]);super(Mf,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>pn.toString(t)).join(", "),e}};Ep.NAME="Extended Key Usages";var W1;(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"})(W1||(W1={}));var Cp=class extends ir{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,Us);this.usages=t.toNumber()}else{let t=new Us(e[0]);super(Kf,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,Us);return e[""]=t.toJSON().join(", "),e}};Cp.NAME="Key Usages";var Tp=class r extends ir{static async create(e,t=!1,n=xt.get()){let i=await(await Ln.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=W.parse(this.value,Wt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new Wt(t);super(Ry,e[1],W.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,Wt);return e[""]=t,e}};Tp.NAME="Subject Key Identifier";var Ip=class extends ir{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Dy,e[1],new Mn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,Ff);this.names=new Mn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Ip.NAME="Subject Alternative Name";var Ut=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ir(e),n=this.items.get(t.type);return n?new n(e):t}};Ut.items=new Map;var Op=class extends ir{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=W.parse(this.value,Hc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Hc(n.map(s=>new Si({policyIdentifier:s})));super(Lf,o,W.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new xe("",{},pn.toString(t))),e}};Op.NAME="Certificate Policies";Ut.register(Lf,Op);var Pp=class extends ir{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 nn({distributionPoint:new Pn({fullName:[new ue({uniformResourceIdentifier:s})]})})),i=new ho(o);super(Uf,e[1],W.serialize(i))}else{let n=new ho(e[0]);super(Uf,e[1],W.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,ho);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 fn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Pp.NAME="CRL Distribution Points";var Bp=class extends ir{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof xi){let s=new xi(e[0]);super(kf,e[1],W.serialize(s))}else{let s=e[0],a=new xi;xp(a,s,gy,"ocsp"),xp(a,s,wy,"caIssuers"),xp(a,s,by,"timeStamping"),xp(a,s,xy,"caRepository"),super(kf,e[1],W.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=[],W.parse(e.extnValue,xi).forEach(n=>{switch(n.accessMethod){case gy:this.ocsp.push(new fn(n.accessLocation));break;case wy:this.caIssuers.push(new fn(n.accessLocation));break;case by:this.timeStamping.push(new fn(n.accessLocation));break;case xy:this.caRepository.push(new fn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&bp(e,"OCSP",this.ocsp),this.caIssuers.length&&bp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&bp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&bp(e,"CA Repository",this.caRepository),e}};Bp.NAME="Authority Info Access";function bp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new xe("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[xe.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function xp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new fn("url",s)),r.push(new In({accessMethod:t,accessLocation:W.parse(s.rawData,ue)}))})}var Np=class extends ir{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Py,e[1],new Mn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,Ke);this.names=new Mn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Np.NAME="Issuer Alternative Name";var da=class r extends Oo{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=W.serialize(new dt({type:n,values:o}))}super(t,dt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new xe("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[xe.NAME]===r.NAME&&(e[xe.NAME]=pn.toString(this.type)),e}};da.NAME="Attribute";var kp=class extends da{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new Su({printableString:e[0]});super(Bm,[W.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],Su);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[xe.VALUE]=this.password,e}};kp.NAME="Challenge Password";var Nu=class extends da{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new nr;for(let i of n)o.push(W.parse(i.rawData,mt));super(Eu,[W.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],nr);this.items=t.map(n=>Ut.create(W.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[xe.NAME]]=n;return e}};Nu.NAME="Extensions";var ya=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new da(e),n=this.items.get(t.type);return n?new n(e):t}};ya.items=new Map;var Du="crypto.signatureFormatter",Fm=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},_p,Wm=_p=class{static createPssParams(e,t){let n=_p.getHashAlgorithm(e);return n?new un({hashAlgorithm:n,maskGenAlgorithm:new H({algorithm:_o,parameters:W.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Le.resolve(Zi);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 H({algorithm:ta,parameters:null});case"sha-256":return new H({algorithm:rp,parameters:null});case"sha-384":return new H({algorithm:ra,parameters:null});case"sha-512":return new H({algorithm:na,parameters:null})}}else return new H({algorithm:cn,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=_p.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new H({algorithm:vo,parameters:W.serialize(t)})}else return new H({algorithm:vo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case cn:return{name:"RSASSA-PKCS1-v1_5"};case ta:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case rp:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ra:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case na:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case vo:if(e.parameters){let t=W.parse(e.parameters,un);return{name:"RSA-PSS",hash:Le.resolve(Zi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Wm=_p=gu([Ao()],Wm);Le.registerSingleton(ku,Wm);var Gm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new H({algorithm:Ki});case"sha-256":return new H({algorithm:Hi});case"sha-384":return new H({algorithm:Vi});case"sha-512":return new H({algorithm:$i})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ki:return{name:"SHA-1"};case Hi:return{name:"SHA-256"};case Vi:return{name:"SHA-384"};case $i:return{name:"SHA-512"}}return null}};Gm=gu([Ao()],Gm);Le.registerSingleton(ku,Gm);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 Mi,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),W.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=W.parse(t,Mi),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 Km="1.3.101.110",G1="1.3.101.111",Hm="1.3.101.112",q1="1.3.101.113",qm=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=Hm;break;case"x25519":t=Km;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=Hm;break;case"ed448":t=q1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Km;break;case"x448":t=G1;break}}return t?new H({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case Hm:return{name:"Ed25519"};case q1:return{name:"EdDSA",namedCurve:"Ed448"};case Km:return{name:"X25519"};case G1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};qm=gu([Ao()],qm);Le.registerSingleton(ku,qm);var zm=class extends Po{constructor(e){Po.isAsnEncoded(e)?super(e,Io):super(e),this.tag=Lt.CertificateRequestTag}onInit(e){this.tbs=W.serialize(e.certificationRequestInfo),this.publicKey=new Ln(e.certificationRequestInfo.subjectPKInfo);let t=Le.resolve(Zi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>ya.create(W.serialize(o)));let n=this.getAttribute(Eu);this.extensions=[],n instanceof Nu&&(this.extensions=n.items),this.subjectName=new br(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=xt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Le.resolveAll(Du).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=W.parse(this.rawData,Io),n=t.certificationRequestInfo,o=new xe("",{Version:`${on[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new xe("");for(let s of this.attributes){let a=s.toTextObject();i[a[xe.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new xe("",{Algorithm:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};zm.NAME="PKCS#10 Certificate Request";var ma=class extends Po{constructor(e){Po.isAsnEncoded(e)?super(e,dr):super(e),this.tag=Lt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=W.serialize(t);let n=new Uint8Array(t.serialNumber);n.length>1&&n[0]===0&&n[1]>127&&(n=n.slice(1)),this.serialNumber=V.Convert.ToHex(n),this.subjectName=new br(t.subject),this.subject=new br(t.subject).toString(),this.issuerName=new br(t.issuer),this.issuer=this.issuerName.toString();let o=Le.resolve(Zi);this.signatureAlgorithm=o.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let i=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!i)throw new Error("Cannot get 'notBefore' value");this.notBefore=i;let s=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!s)throw new Error("Cannot get 'notAfter' value");this.notAfter=s,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(a=>Ut.create(W.serialize(a)))),this.publicKey=new Ln(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=xt.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 Ln)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let l=new Ln(i);n={...l.algorithm,...this.signatureAlgorithm},o=await l.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Le.resolveAll(Du).reverse(),a=null;for(let l of s)if(a=l.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 f=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<f&&f<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=xt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=xt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,dr),n=t.tbsCertificate,o=new xe("",{Version:`${on[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Un.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new xe("",{"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 xe("");for(let s of this.extensions){let a=s.toTextObject();i[a[xe.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new xe("",{Algorithm:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ma.NAME="Certificate";var Dp=class{static async createSelfSigned(e,t=xt.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=xt.get()){var n;let o;e.publicKey instanceof Ln?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)):void 0;i=this.generateSerialNumber(i,t);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new dr({tbsCertificate:new gt({version:on.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new nr(((n=e.extensions)===null||n===void 0?void 0:n.map(d=>W.parse(d.rawData,mt)))||[]),subjectPublicKeyInfo:W.parse(o,yt)})});if(e.subject){let d=e.subject instanceof br?e.subject:new br(e.subject);c.tbsCertificate.subject=W.parse(d.toArrayBuffer(),Pe)}if(e.issuer){let d=e.issuer instanceof br?e.issuer:new br(e.issuer);c.tbsCertificate.issuer=W.parse(d.toArrayBuffer(),Pe)}let l={hash:"SHA-256"},f="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},p=Le.resolve(Zi);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(f);let y=W.serialize(c.tbsCertificate),m="signingKey"in e?await t.subtle.sign(f,e.signingKey,y):e.signature,x=Le.resolveAll(Du).reverse(),v=null;for(let d of x)if(v=d.toAsnSignature(f,m),v)break;if(!v)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=v,new ma(W.serialize(c))}static generateSerialNumber(e,t){let n=e&&e.length&&e.some(i=>i>0)?new Uint8Array(e):void 0;n||(n=t.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n}},z1;(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"})(z1||(z1={}));Ut.register(jf,ha);Ut.register(Mf,Ep);Ut.register(Kf,Cp);Ut.register(Ry,Tp);Ut.register(Df,Ap);Ut.register(Dy,Ip);Ut.register(Uf,Pp);Ut.register(kf,Bp);Ut.register(Py,Np);ya.register(Bm,kp);ya.register(Eu,Nu);Le.registerSingleton(Du,Fm);Le.registerSingleton(Du,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 Hn="/",Q1=new TextEncoder().encode(Hn),jp=Q1[0],ju=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=he(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]!==jp)throw new Error("Invalid key")}toString(e="utf8"){return le(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Hn))}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=Q1),this._buf[0]!==jp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(jp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===jp;)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(Hn).slice(1)}type(){return bT(this.baseNamespace())}name(){return xT(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Hn)||(e+=Hn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Hn):new r(e.slice(0,-1).join(Hn))}child(e){return this.toString()===Hn?e:e.toString()===Hn?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(),...vT(e.map(t=>t.namespaces()))])}};function bT(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function xT(r){let e=r.split(":");return e[e.length-1]}function vT(r){return[].concat(...r)}var Rp=class extends Wn{async listen(){throw new sf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Xm(){let r=Je(),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 e_(){let r=Xm(),e=Xm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function _T(r){return r[Symbol.asyncIterator]!=null}async function ST(r,e,t){try{await Promise.all(r.map(async n=>{for await(let o of n)await e.push(o,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*AT(r){let e=new AbortController,t=Jl();ST(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*ET(r){for(let e of r)yield*e}function CT(...r){let e=[];for(let t of r)_T(t)||e.push(t);return e.length===r.length?ET(e):AT(r)}var t_=CT;function r_(r,...e){if(r==null)throw new Error("Empty pipeline");if(Zm(r)){let n=r;r=()=>n.source}else if(o_(r)||n_(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Zm(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++)Zm(t[n])&&(t[n]=IT(t[n]));return TT(...t)}var TT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},n_=r=>r?.[Symbol.asyncIterator]!=null,o_=r=>r?.[Symbol.iterator]!=null,Zm=r=>r==null?!1:r.sink!=null&&r.source!=null,IT=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Is({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(n_(i))o=async function*(){yield*i,n.end()};else if(o_(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return t_(n,o())}return r.source};var ga=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function s_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Lp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Up(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Pt(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 Ym(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 a_(r,e){Pt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Vn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function $n(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function OT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var PT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function BT(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=BT(r);else if(s_(r))r=Kp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function c_(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function u_(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 Jm=(r,e)=>{function t(n,...o){if(Pt(n),!PT)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let f=o[0];if(!f)throw new Error("nonce / iv required");r.varSizeNonce?Pt(f):Pt(f,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Pt(o[1]);let s=e(n,...o),a=(f,p)=>{if(p!==void 0){if(f!==2)throw new Error("cipher output not supported");Pt(p)}},c=!1;return{encrypt(f,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Pt(f),a(s.encrypt.length,p),s.encrypt(f,p)},decrypt(f,p){if(Pt(f),i&&f.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,p),s.decrypt(f,p)}}}return Object.assign(t,r),t};function Qm(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&&!NT(e))throw new Error("invalid output, must be aligned");return e}function i_(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,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function l_(r,e,t){Lp(t);let n=new Uint8Array(16),o=OT(n);return i_(o,0,BigInt(e),t),i_(o,8,BigInt(r),t),n}function NT(r){return r.byteOffset%4===0}function Kp(r){return Uint8Array.from(r)}var p_=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),kT=p_("expand 16-byte k"),DT=p_("expand 32-byte k"),jT=Vn(kT),RT=Vn(DT);function te(r,e){return r<<e|r>>>32-e}function eg(r){return r.byteOffset%4===0}var Hp=64,LT=16,h_=2**32-1,f_=new Uint32Array;function UT(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(Hp),f=Vn(l),p=eg(o)&&eg(i),y=p?Vn(o):f_,m=p?Vn(i):f_;for(let x=0;x<c;s++){if(r(e,t,n,f,s,a),s>=h_)throw new Error("arx: counter overflow");let v=Math.min(Hp,c-x);if(p&&v===Hp){let d=x/4;if(x%4!==0)throw new Error("arx: invalid block position");for(let I=0,D;I<LT;I++)D=d+I,m[D]=y[D]^f[I];x+=Hp;continue}for(let d=0,I;d<v;d++)I=x+d,i[I]=o[I]^l[d];x+=v}}function tg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=c_({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Up(o),Up(s),Lp(i),Lp(t),(a,c,l,f,p=0)=>{Pt(a),Pt(c),Pt(l);let y=l.length;if(f===void 0&&(f=new Uint8Array(y)),Pt(f),Up(p),p<0||p>=h_)throw new Error("arx: counter overflow");if(f.length<y)throw new Error(`arx: output (${f.length}) is shorter than data (${y})`);let m=[],x=a.length,v,d;if(x===32)m.push(v=Kp(a)),d=RT;else if(x===16&&t)v=new Uint8Array(32),v.set(a),v.set(a,16),d=jT,m.push(v);else throw new Error(`arx: invalid 32-byte key, got length=${x}`);eg(c)||m.push(c=Kp(c));let I=Vn(v);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,I,Vn(c.subarray(0,16)),I),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let Z=new Uint8Array(12);Z.set(c,i?0:12-c.length),c=Z,m.push(c)}let j=Vn(c);return UT(r,d,I,j,l,f,p,s),$n(...m),f}}var vt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,rg=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),Pt(e,32);let t=vt(e,0),n=vt(e,2),o=vt(e,4),i=vt(e,6),s=vt(e,8),a=vt(e,10),c=vt(e,12),l=vt(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|l<<8)&8191,this.r[9]=l>>>5&127;for(let f=0;f<8;f++)this.pad[f]=vt(e,16+2*f)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],l=s[2],f=s[3],p=s[4],y=s[5],m=s[6],x=s[7],v=s[8],d=s[9],I=vt(e,t+0),D=vt(e,t+2),j=vt(e,t+4),Z=vt(e,t+6),P=vt(e,t+8),M=vt(e,t+10),$=vt(e,t+12),K=vt(e,t+14),g=i[0]+(I&8191),T=i[1]+((I>>>13|D<<3)&8191),E=i[2]+((D>>>10|j<<6)&8191),O=i[3]+((j>>>7|Z<<9)&8191),B=i[4]+((Z>>>4|P<<12)&8191),R=i[5]+(P>>>1&8191),k=i[6]+((P>>>14|M<<2)&8191),L=i[7]+((M>>>11|$<<5)&8191),G=i[8]+(($>>>8|K<<8)&8191),X=i[9]+(K>>>5|o),q=0,ie=q+g*a+T*(5*d)+E*(5*v)+O*(5*x)+B*(5*m);q=ie>>>13,ie&=8191,ie+=R*(5*y)+k*(5*p)+L*(5*f)+G*(5*l)+X*(5*c),q+=ie>>>13,ie&=8191;let Y=q+g*c+T*a+E*(5*d)+O*(5*v)+B*(5*x);q=Y>>>13,Y&=8191,Y+=R*(5*m)+k*(5*y)+L*(5*p)+G*(5*f)+X*(5*l),q+=Y>>>13,Y&=8191;let U=q+g*l+T*c+E*a+O*(5*d)+B*(5*v);q=U>>>13,U&=8191,U+=R*(5*x)+k*(5*m)+L*(5*y)+G*(5*p)+X*(5*f),q+=U>>>13,U&=8191;let de=q+g*f+T*l+E*c+O*a+B*(5*d);q=de>>>13,de&=8191,de+=R*(5*v)+k*(5*x)+L*(5*m)+G*(5*y)+X*(5*p),q+=de>>>13,de&=8191;let Oe=q+g*p+T*f+E*l+O*c+B*a;q=Oe>>>13,Oe&=8191,Oe+=R*(5*d)+k*(5*v)+L*(5*x)+G*(5*m)+X*(5*y),q+=Oe>>>13,Oe&=8191;let se=q+g*y+T*p+E*f+O*l+B*c;q=se>>>13,se&=8191,se+=R*a+k*(5*d)+L*(5*v)+G*(5*x)+X*(5*m),q+=se>>>13,se&=8191;let De=q+g*m+T*y+E*p+O*f+B*l;q=De>>>13,De&=8191,De+=R*c+k*a+L*(5*d)+G*(5*v)+X*(5*x),q+=De>>>13,De&=8191;let _t=q+g*x+T*m+E*y+O*p+B*f;q=_t>>>13,_t&=8191,_t+=R*l+k*c+L*a+G*(5*d)+X*(5*v),q+=_t>>>13,_t&=8191;let tt=q+g*v+T*x+E*m+O*y+B*p;q=tt>>>13,tt&=8191,tt+=R*f+k*l+L*c+G*a+X*(5*d),q+=tt>>>13,tt&=8191;let rt=q+g*d+T*v+E*x+O*m+B*y;q=rt>>>13,rt&=8191,rt+=R*p+k*f+L*l+G*c+X*a,q+=rt>>>13,rt&=8191,q=(q<<2)+q|0,q=q+ie|0,ie=q&8191,q=q>>>13,Y+=q,i[0]=ie,i[1]=Y,i[2]=U,i[3]=de,i[4]=Oe,i[5]=se,i[6]=De,i[7]=_t,i[8]=tt,i[9]=rt}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;$n(n)}update(e){Ym(this),e=Mp(e),Pt(e);let{buffer:t,blockLen:n}=this,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(){$n(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ym(this),a_(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 MT(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 d_=MT(r=>new rg(r));function g_(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],l=r[3],f=e[0],p=e[1],y=e[2],m=e[3],x=e[4],v=e[5],d=e[6],I=e[7],D=o,j=t[0],Z=t[1],P=t[2],M=s,$=a,K=c,g=l,T=f,E=p,O=y,B=m,R=x,k=v,L=d,G=I,X=D,q=j,ie=Z,Y=P;for(let de=0;de<i;de+=2)M=M+T|0,X=te(X^M,16),R=R+X|0,T=te(T^R,12),M=M+T|0,X=te(X^M,8),R=R+X|0,T=te(T^R,7),$=$+E|0,q=te(q^$,16),k=k+q|0,E=te(E^k,12),$=$+E|0,q=te(q^$,8),k=k+q|0,E=te(E^k,7),K=K+O|0,ie=te(ie^K,16),L=L+ie|0,O=te(O^L,12),K=K+O|0,ie=te(ie^K,8),L=L+ie|0,O=te(O^L,7),g=g+B|0,Y=te(Y^g,16),G=G+Y|0,B=te(B^G,12),g=g+B|0,Y=te(Y^g,8),G=G+Y|0,B=te(B^G,7),M=M+E|0,Y=te(Y^M,16),L=L+Y|0,E=te(E^L,12),M=M+E|0,Y=te(Y^M,8),L=L+Y|0,E=te(E^L,7),$=$+O|0,X=te(X^$,16),G=G+X|0,O=te(O^G,12),$=$+O|0,X=te(X^$,8),G=G+X|0,O=te(O^G,7),K=K+B|0,q=te(q^K,16),R=R+q|0,B=te(B^R,12),K=K+B|0,q=te(q^K,8),R=R+q|0,B=te(B^R,7),g=g+T|0,ie=te(ie^g,16),k=k+ie|0,T=te(T^k,12),g=g+T|0,ie=te(ie^g,8),k=k+ie|0,T=te(T^k,7);let U=0;n[U++]=s+M|0,n[U++]=a+$|0,n[U++]=c+K|0,n[U++]=l+g|0,n[U++]=f+T|0,n[U++]=p+E|0,n[U++]=y+O|0,n[U++]=m+B|0,n[U++]=x+R|0,n[U++]=v+k|0,n[U++]=d+L|0,n[U++]=I+G|0,n[U++]=D+X|0,n[U++]=j+q|0,n[U++]=Z+ie|0,n[U++]=P+Y|0}function KT(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],l=e[1],f=e[2],p=e[3],y=e[4],m=e[5],x=e[6],v=e[7],d=t[0],I=t[1],D=t[2],j=t[3];for(let P=0;P<20;P+=2)o=o+c|0,d=te(d^o,16),y=y+d|0,c=te(c^y,12),o=o+c|0,d=te(d^o,8),y=y+d|0,c=te(c^y,7),i=i+l|0,I=te(I^i,16),m=m+I|0,l=te(l^m,12),i=i+l|0,I=te(I^i,8),m=m+I|0,l=te(l^m,7),s=s+f|0,D=te(D^s,16),x=x+D|0,f=te(f^x,12),s=s+f|0,D=te(D^s,8),x=x+D|0,f=te(f^x,7),a=a+p|0,j=te(j^a,16),v=v+j|0,p=te(p^v,12),a=a+p|0,j=te(j^a,8),v=v+j|0,p=te(p^v,7),o=o+l|0,j=te(j^o,16),x=x+j|0,l=te(l^x,12),o=o+l|0,j=te(j^o,8),x=x+j|0,l=te(l^x,7),i=i+f|0,d=te(d^i,16),v=v+d|0,f=te(f^v,12),i=i+f|0,d=te(d^i,8),v=v+d|0,f=te(f^v,7),s=s+p|0,I=te(I^s,16),y=y+I|0,p=te(p^y,12),s=s+p|0,I=te(I^s,8),y=y+I|0,p=te(p^y,7),a=a+c|0,D=te(D^a,16),m=m+D|0,c=te(c^m,12),a=a+c|0,D=te(D^a,8),m=m+D|0,c=te(c^m,7);let Z=0;n[Z++]=o,n[Z++]=i,n[Z++]=s,n[Z++]=a,n[Z++]=d,n[Z++]=I,n[Z++]=D,n[Z++]=j}var HT=tg(g_,{counterRight:!1,counterLength:4,allowShortKeys:!1}),VT=tg(g_,{counterRight:!1,counterLength:8,extendNonceFn:KT,allowShortKeys:!1});var $T=new Uint8Array(16),y_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update($T.subarray(t))},FT=new Uint8Array(32);function m_(r,e,t,n,o){let i=r(e,t,FT),s=d_.create(i);o&&y_(s,o),y_(s,n);let a=l_(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return $n(i,a),c}var w_=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Qm(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=m_(r,e,t,c,n);return s.set(l,a),$n(l),s},decrypt(i,s){s=Qm(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=m_(r,e,t,a,n);if(!u_(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),$n(l),s}}),ng=Jm({blockSize:64,nonceLength:12,tagLength:16},w_(HT)),xX=Jm({blockSize:64,nonceLength:24,tagLength:16},w_(VT));function x_(r,e,t){return Pa(r),t===void 0&&(t=new Uint8Array(r.outputLen)),bs(r,Xn(t),Xn(e))}var og=Uint8Array.from([0]),b_=Uint8Array.of();function v_(r,e,t,n=32){Pa(r),Uo(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=b_);let s=new Uint8Array(i*o),a=bs.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let f=0;f<i;f++)og[0]=f+1,c.update(f===0?b_:l).update(t).update(og).digestInto(l),s.set(l,o*f),a._cloneInto(c);return a.destroy(),c.destroy(),Ar(l,og),s.slice(0,n)}var ig={hashSHA256(r){return to(r.subarray())},getHKDF(r,e){let t=x_(to,e,r),o=v_(to,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=Ma.utils.randomPrivateKey();return{publicKey:Ma.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Ma.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Ma.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return ng(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return ng(n,e,t).decrypt(r.subarray(),o)}};var __=ig;function S_(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 wa=r=>{let e=it(2);return e[0]=r>>8,e[1]=r,e};wa.bytes=2;var Ru=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)};Ru.bytes=2;function A_(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 sg(r,e){!e.enabled||!ga||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${le(r.privateKey,"hex")}`)):e("Missing local static keys."))}function ag(r,e){!e.enabled||!ga||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${le(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function E_(r,e){!e.enabled||!ga||e(r?`REMOTE_STATIC_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote static public key.")}function cg(r,e){!e.enabled||!ga||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function ug(r,e,t){!t.enabled||!ga||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&le(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&le(e.k,"hex")}`))}var ba=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var WT=0,GT=4294967295,qT="Cipherstate has reached maximum n, a new handshake must be performed",Vp=class{n;bytes;view;constructor(e=WT){this.n=e,this.bytes=ot(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>GT)throw new Error(qT)}};var Yi=ot(0),xa=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Vp(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}},lg=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=he(t,"utf-8");this.h=zT(e,n),this.ck=this.h,this.cs=new xa(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new xa(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new be(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,Yi);return[new xa(this.crypto,e),new xa(this.crypto,t)]}},fg=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:l}=e;this.crypto=t,this.ss=new lg(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=l}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()}},Lu=class extends fg{writeMessageA(e){return new be(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new be(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new be(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new ba(`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 ba(`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 ba(`handshake stage 2 validation fail: ${t.message}`)}}};function zT(r,e){if(e.length<=32){let t=ot(32);return t.set(e),t}else return r.hash(e)}var $p;(function(r){let e;r.codec=()=>(e==null&&(e=Br((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 Ga('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 Ga('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=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})($p||($p={}));var Uu;(function(r){let e;r.codec=()=>(e==null&&(e=Br((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),$p.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ot(0),identitySig:ot(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=$p.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Uu||(Uu={}));async function pg(r,e,t){let n=await r.sign(C_(e));return Uu.encode({identityKey:zn(r.publicKey),identitySig:n,extensions:t})}async function hg(r,e,t){try{let n=Uu.decode(r),o=Ja(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=C_(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Vu(n.message)}}function C_(r){let e=he("noise-libp2p-static-key:");return r instanceof Uint8Array?Bt([e,r],e.length+r.length):(r.prepend(e),r)}async function T_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await pg(i,a.publicKey,l),p=new Lu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});sg(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(Yi),e),t.trace("Stage 0 - Initiator finished sending first message."),ag(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."),cg(p.re,t),E_(p.rs,t),t.trace("Initiator going to check remote's signature...");let m=await hg(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(f),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[x,v]=p.ss.split();return ug(x,v,t),{payload:m,encrypt:d=>x.encryptWithAd(Yi,d),decrypt:(d,I)=>v.decryptWithAd(Yi,d,I)}}async function I_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await pg(i,a.publicKey,l),p=new Lu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});sg(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."),cg(p.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(p.writeMessageB(f),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),ag(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 m=await hg(y,p.rs,c),[x,v]=p.ss.split();return ug(x,v,t),{payload:m,encrypt:d=>v.encryptWithAd(Yi,d),decrypt:(d,I)=>x.decryptWithAd(Yi,d,I)}}var P_=16;function B_(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 be(wa(s.byteLength),s)}}}function N_(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-P_<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-P_);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var Fp=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??__;this.crypto=S_(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?A_(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ot(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[es]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=wc(e,{lengthEncoder:wa,lengthDecoder:Ru,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=Ja(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:gd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)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 $u("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=wc(e,{lengthEncoder:wa,lengthDecoder:Ru,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=Ja(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:gd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await T_({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:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async performHandshakeResponder(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await I_({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:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async createSecureConnection(e,t){let[n,o]=e_(),i=e.unwrap();return await r_(n,B_(t,this.metrics),i,s=>ti(s,{lengthDecoder:Ru}),N_(t,this.metrics),n),o}};function k_(r={}){return e=>new Fp(e,r)}var dg=Object.values(jo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),XT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function D_(r){return r?.match(XT)?.groups?.fingerprint}function yg(r){let t=r.stringTuples().filter(n=>n[0]===cb).map(n=>n[1])[0];if(t===void 0||t==="")throw new Ie(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function ZT(r){return vr.decode(dg.decode(r))}function YT(r){let e=ZT(yg(r)),t=JT(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 of(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function j_(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=At(ar.code,t);return xn(`/certhash/${Do.encode(n.bytes)}`)}function JT(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new af(r)}}function R_(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=YT(r);return{type:"answer",sdp:`v=0
8
+ `)}function Om(r,e,t){var n=Bu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=mT(i,e);return gT("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function i1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var bT=function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(ku);var wT=function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(ku);var xT=function(){function r(){this.preResolution=new bT,this.postResolution=new wT}return r}(),s1=xT;var Bm=new Map,vT=function(){function r(e){this.parent=e,this._registry=new o1,this.interceptors=new s1,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:At.Transient}),this.ensureNotDisposed();var o;if(n1(t)?o=t:o={useClass:t},as(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+qr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&as(c.provider)?s=c.provider:s=null}if((n.lifecycle===At.Singleton||n.lifecycle==At.ContainerScoped||n.lifecycle==At.ResolutionScoped)&&(cs(o)||Ea(o)))throw new Error('Cannot use lifecycle "'+At[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(),jo(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(),jo(e)){if(jo(t))return this.register(e,{useToken:t},{lifecycle:At.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:At.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!jo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:At.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new Nu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&jo(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(r1(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=Ou(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=Ou(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(p){o={error:p}}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===At.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===At.Singleton,o=e.options.lifecycle===At.ContainerScoped,i=n||o,s;return cs(e.provider)?s=e.provider.useValue:as(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):Pu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Ea(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===At.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new Nu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&jo(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=Ou(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Bu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!cs(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=Ou(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Bu(i.value,2),a=s[0],c=s[1];c.some(function(u){var p=u.options;return p.lifecycle===At.ContainerScoped})&&n._registry.setAll(a,c.map(function(u){return u.options.lifecycle===At.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 e1(this,void 0,void 0,function(){var e;return t1(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 bp)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=Bm.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,qr([void 0],s)))}();return i1(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 Im(o)?wp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,qr([n.resolveAll(o.token,new Nu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,qr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new Nu,o.isOptional):n.resolve(o.token,e,o.isOptional):wp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,qr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(u){throw new Error(Om(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 vT;function _T(r){return function(e){Bm.set(e,Tm(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Ue.register(t,e)}):Ue.register(r.token,e))}}var Ro=_T;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.`);function Ee(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}function Ce(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 km,us=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Ce([l({type:h.ObjectIdentifier})],us.prototype,"attrId",void 0);Ce([l({type:h.Any,repeated:"set"})],us.prototype,"attrValues",void 0);var a1=km=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,km.prototype)}};a1=km=Ce([A({type:v.Sequence,itemType:us})],a1);var Nm,c1=Nm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Nm.prototype)}};c1=Nm=Ce([A({type:v.Sequence,itemType:vr})],c1);var ST="1.2.840.113549",AT=`${ST}.1`,u1=`${AT}.12`,Ca=`${u1}.1`,lq=`${Ca}.1`,fq=`${Ca}.2`,pq=`${Ca}.3`,hq=`${Ca}.4`,dq=`${Ca}.5`,yq=`${Ca}.6`,ls=`${u1}.10.1`;var bq=`${ls}.1`,wq=`${ls}.2`,xq=`${ls}.3`,vq=`${ls}.4`,_q=`${ls}.5`,Sq=`${ls}.6`,xp="1.2.840.113549.1.9";var vp=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Ce([l({type:h.ObjectIdentifier})],vp.prototype,"certId",void 0);Ce([l({type:h.Any,context:0})],vp.prototype,"certValue",void 0);var l1=`${xp}.22`,Iq=`${l1}.1`,Oq=`${l1}.2`;var _p=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Ce([l({type:h.ObjectIdentifier})],_p.prototype,"crlId",void 0);Ce([l({type:h.Any,context:0})],_p.prototype,"crltValue",void 0);var ET=`${xp}.23`,Dq=`${ET}.1`;function Gn(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 Sp=class extends se{},Lo=class{constructor(e={}){this.encryptionAlgorithm=new K,this.encryptedData=new Sp,Object.assign(this,e)}};Gn([l({type:K})],Lo.prototype,"encryptionAlgorithm",void 0);Gn([l({type:Sp})],Lo.prototype,"encryptedData",void 0);var Dm,jm;(function(r){r[r.v1=0]="v1"})(jm||(jm={}));var Ap=class extends se{},Rm=Dm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Dm.prototype)}};Rm=Dm=Gn([A({type:v.Sequence,itemType:wt})],Rm);var Uo=class{constructor(e={}){this.version=jm.v1,this.privateKeyAlgorithm=new K,this.privateKey=new Ap,Object.assign(this,e)}};Gn([l({type:h.Integer})],Uo.prototype,"version",void 0);Gn([l({type:K})],Uo.prototype,"privateKeyAlgorithm",void 0);Gn([l({type:Ap})],Uo.prototype,"privateKey",void 0);Gn([l({type:Rm,implicit:!0,context:0,optional:!0})],Uo.prototype,"attributes",void 0);var f1=class extends Uo{};f1=Ce([A({type:v.Sequence})],f1);var p1=class extends Lo{};p1=Ce([A({type:v.Sequence})],p1);var Ep=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Ce([l({type:h.ObjectIdentifier})],Ep.prototype,"secretTypeId",void 0);Ce([l({type:h.Any,context:0})],Ep.prototype,"secretValue",void 0);var Mo=class{constructor(e={}){this.mac=new ss,this.macSalt=new se,this.iterations=1,Object.assign(this,e)}};Ce([l({type:ss})],Mo.prototype,"mac",void 0);Ce([l({type:se})],Mo.prototype,"macSalt",void 0);Ce([l({type:h.Integer,defaultValue:1})],Mo.prototype,"iterations",void 0);var fs=class{constructor(e={}){this.version=3,this.authSafe=new vr,this.macData=new Mo,Object.assign(this,e)}};Ce([l({type:h.Integer})],fs.prototype,"version",void 0);Ce([l({type:vr})],fs.prototype,"authSafe",void 0);Ce([l({type:Mo,optional:!0})],fs.prototype,"macData",void 0);var Lm,Ta=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Ce([l({type:h.ObjectIdentifier})],Ta.prototype,"bagId",void 0);Ce([l({type:h.Any,context:0})],Ta.prototype,"bagValue",void 0);Ce([l({type:us,repeated:"set",optional:!0})],Ta.prototype,"bagAttributes",void 0);var h1=Lm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Lm.prototype)}};h1=Lm=Ce([A({type:v.Sequence,itemType:Ta})],h1);var Um,Mm,Km,Ye="1.2.840.113549.1.9",LG=`${Ye}.0`,T1=`${Ye}.24`,ju=`${Ye}.25`,I1=`${Ye}.26`,O1=`${Ye}.27`,UG=`${T1}.1`,MG=`${T1}.2`,KG=`${Ye}.1`,HG=`${Ye}.2`,VG=`${Ye}.3`,$G=`${Ye}.4`,FG=`${Ye}.5`,WG=`${Ye}.6`,zm=`${Ye}.7`,qG=`${Ye}.8`,GG=`${Ye}.9`,zG=`${Ye}.13`,Ru=`${Ye}.14`,XG=`${Ye}.15`,ZG=`${Ye}.20`,YG=`${Ye}.21`;var JG=`${ju}.1`,QG=`${ju}.2`,ez=`${ju}.3`,tz=`${ju}.4`,rz=`${ju}.5`,Lu="1.3.6.1.5.5.7.9",nz=`${Lu}.1`,oz=`${Lu}.2`,iz=`${Lu}.3`,sz=`${Lu}.4`,az=`${Lu}.5`,cz=`${I1}.1`,uz=`${I1}.2`,lz=`${O1}.1`,fz=`${O1}.2`,pz=`${Ye}.16`,hz=`${Ye}.22`,dz=`${Ye}.23`,yz=`${sm}.65`,Cp=class extends at{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Ee([l({type:h.IA5String})],Cp.prototype,"ia5String",void 0);Cp=Ee([A({type:v.Choice})],Cp);var d1=class extends vr{};d1=Ee([A({type:v.Sequence})],d1);var y1=class extends fs{};y1=Ee([A({type:v.Sequence})],y1);var m1=class extends Lo{};m1=Ee([A({type:v.Sequence})],m1);var Hm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ee([l({type:h.IA5String})],Hm.prototype,"value",void 0);Hm=Ee([A({type:v.Choice})],Hm);var g1=class extends Cp{};g1=Ee([A({type:v.Choice})],g1);var b1=class extends at{};b1=Ee([A({type:v.Choice})],b1);var Vm=class{constructor(e=new Date){this.value=e}};Ee([l({type:h.GeneralizedTime})],Vm.prototype,"value",void 0);Vm=Ee([A({type:v.Choice})],Vm);var w1=class extends at{};w1=Ee([A({type:v.Choice})],w1);var $m=class{constructor(e="M"){this.value=e}toString(){return this.value}};Ee([l({type:h.PrintableString})],$m.prototype,"value",void 0);$m=Ee([A({type:v.Choice})],$m);var Tp=class{constructor(e=""){this.value=e}toString(){return this.value}};Ee([l({type:h.PrintableString})],Tp.prototype,"value",void 0);Tp=Ee([A({type:v.Choice})],Tp);var x1=class extends Tp{};x1=Ee([A({type:v.Choice})],x1);var v1=class extends at{};v1=Ee([A({type:v.Choice})],v1);var Fm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ee([l({type:h.ObjectIdentifier})],Fm.prototype,"value",void 0);Fm=Ee([A({type:v.Choice})],Fm);var _1=class extends Ze{};_1=Ee([A({type:v.Choice})],_1);var Wm=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Ee([l({type:h.Integer})],Wm.prototype,"value",void 0);Wm=Ee([A({type:v.Choice})],Wm);var S1=class extends Zt{};S1=Ee([A({type:v.Sequence})],S1);var Du=class extends at{};Du=Ee([A({type:v.Choice})],Du);var A1=Um=class extends sr{constructor(e){super(e),Object.setPrototypeOf(this,Um.prototype)}};A1=Um=Ee([A({type:v.Sequence})],A1);var E1=Mm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};E1=Mm=Ee([A({type:v.Set,itemType:Wr})],E1);var qm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ee([l({type:h.BmpString})],qm.prototype,"value",void 0);qm=Ee([A({type:v.Choice})],qm);var Gm=class extends K{};Gm=Ee([A({type:v.Sequence})],Gm);var C1=Km=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Km.prototype)}};C1=Km=Ee([A({type:v.Sequence,itemType:Gm})],C1);function Gr(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 Xm,Uu=Xm=class extends ie{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};Uu=Xm=Gr([A({type:v.Sequence,itemType:wt})],Uu);var dn=class{constructor(e={}){this.version=0,this.subject=new Ne,this.subjectPKInfo=new xt,this.attributes=new Uu,Object.assign(this,e)}};Gr([l({type:h.Integer})],dn.prototype,"version",void 0);Gr([l({type:Ne})],dn.prototype,"subject",void 0);Gr([l({type:xt})],dn.prototype,"subjectPKInfo",void 0);Gr([l({type:Uu,implicit:!0,context:0})],dn.prototype,"attributes",void 0);var Ko=class{constructor(e={}){this.certificationRequestInfo=new dn,this.signatureAlgorithm=new K,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Gr([l({type:dn})],Ko.prototype,"certificationRequestInfo",void 0);Gr([l({type:K})],Ko.prototype,"signatureAlgorithm",void 0);Gr([l({type:h.BitString})],Ko.prototype,"signature",void 0);var Fu="crypto.algorithm",ig=class{getAlgorithms(){return Ue.resolveAll(Fu)}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 K({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}}},ps="crypto.algorithmProvider";Ue.registerSingleton(ps,ig);var Pp,er="1.3.36.3.3.2.8.1.1",B1=`${er}.1`,P1=`${er}.2`,k1=`${er}.3`,N1=`${er}.4`,D1=`${er}.5`,j1=`${er}.6`,R1=`${er}.7`,L1=`${er}.8`,U1=`${er}.9`,M1=`${er}.10`,K1=`${er}.11`,H1=`${er}.12`,V1=`${er}.13`,$1=`${er}.14`,F1="brainpoolP160r1",W1="brainpoolP160t1",q1="brainpoolP192r1",G1="brainpoolP192t1",z1="brainpoolP224r1",X1="brainpoolP224t1",Z1="brainpoolP256r1",Y1="brainpoolP256t1",J1="brainpoolP320r1",Q1="brainpoolP320t1",e_="brainpoolP384r1",t_="brainpoolP384t1",r_="brainpoolP512r1",n_="brainpoolP512t1",We="ECDSA",Ku=Pp=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 wv;case"sha-256":return xv;case"sha-384":return vv;case"sha-512":return _v}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=mm;break;case"K-256":t=Pp.SECP256K1;break;case"P-384":t=gm;break;case"P-521":t=bm;break;case F1:t=B1;break;case W1:t=P1;break;case q1:t=k1;break;case G1:t=N1;break;case z1:t=D1;break;case X1:t=j1;break;case Z1:t=R1;break;case Y1:t=L1;break;case J1:t=U1;break;case Q1:t=M1;break;case e_:t=K1;break;case t_:t=H1;break;case r_:t=V1;break;case n_:t=$1;break}if(t)return new K({algorithm:es,parameters:q.serialize(new fn({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case _u:return{name:We,hash:{name:"SHA-1"}};case Su:return{name:We,hash:{name:"SHA-256"}};case Au:return{name:We,hash:{name:"SHA-384"}};case Eu:return{name:We,hash:{name:"SHA-512"}};case es:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(q.parse(e.parameters,fn).namedCurve){case mm:return{name:We,namedCurve:"P-256"};case Pp.SECP256K1:return{name:We,namedCurve:"K-256"};case gm:return{name:We,namedCurve:"P-384"};case bm:return{name:We,namedCurve:"P-521"};case B1:return{name:We,namedCurve:F1};case P1:return{name:We,namedCurve:W1};case k1:return{name:We,namedCurve:q1};case N1:return{name:We,namedCurve:G1};case D1:return{name:We,namedCurve:z1};case j1:return{name:We,namedCurve:X1};case R1:return{name:We,namedCurve:Z1};case L1:return{name:We,namedCurve:Y1};case U1:return{name:We,namedCurve:J1};case M1:return{name:We,namedCurve:Q1};case K1:return{name:We,namedCurve:e_};case H1:return{name:We,namedCurve:t_};case V1:return{name:We,namedCurve:r_};case $1:return{name:We,namedCurve:n_}}}}return null}};Ku.SECP256K1="1.3.132.0.10";Ku=Pp=Iu([Ro()],Ku);Ue.registerSingleton(Fu,Ku);var d_=Symbol("name"),y_=Symbol("value"),_e=class{constructor(e,t={},n=""){this[d_]=e,this[y_]=n;for(let o in t)this[o]=t[o]}};_e.NAME=d_;_e.VALUE=y_;var sg=class{static toTextObject(e){let t=new _e("Algorithm Identifier",{},mn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case es:{let n=new Ku().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},mn=class{static toString(e){let t=this.items[e];return t||e}};mn.items={[rs]:"sha1",[hp]:"sha224",[ns]:"sha256",[os]:"sha384",[is]:"sha512",[pn]:"rsaEncryption",[ga]:"sha1WithRSAEncryption",[Tv]:"sha224WithRSAEncryption",[pp]:"sha256WithRSAEncryption",[ba]:"sha384WithRSAEncryption",[wa]:"sha512WithRSAEncryption",[es]:"ecPublicKey",[_u]:"ecdsaWithSHA1",[fp]:"ecdsaWithSHA224",[Su]:"ecdsaWithSHA256",[Au]:"ecdsaWithSHA384",[Eu]:"ecdsaWithSHA512",[Qx]:"TLS WWW server authentication",[ev]:"TLS WWW client authentication",[tv]:"Code Signing",[rv]:"E-mail Protection",[nv]:"Time Stamping",[ov]:"OCSP Signing",[gv]:"Signed Data"};var Xn=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[_e.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[_e.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 p of c)p[_e.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof _e)c[_e.NAME]=a,n.push(...this.serializeObj(c,t));else if($.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 p=c.toTextObject();p[_e.NAME]=a,n.push(...this.serializeObj(p,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=$.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)}};Xn.oidSerializer=mn;Xn.algorithmSerializer=sg;var Ho=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=q.serialize(t),this.onInit(t)}else{let t=q.parse(e[0],e[1]);this.rawData=$.BufferSourceConverter.toArrayBuffer(e[0]),this.onInit(t)}}equal(e){return e instanceof r?(0,$.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return q.toString(this.rawData);case"text":return Xn.serialize(this.toTextObject());case"hex":return $.Convert.ToHex(this.rawData);case"base64":return $.Convert.ToBase64(this.rawData);case"base64url":return $.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 _e(this.getTextName(),{},e)}};Ho.NAME="ASN";var cr=class r extends Ho{constructor(...e){let t;$.BufferSourceConverter.isBufferSource(e[0])?t=$.BufferSourceConverter.toArrayBuffer(e[0]):t=q.serialize(new vt({extnID:e[0],critical:e[1],extnValue:new se($.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,vt)}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[_e.NAME]===r.NAME&&(e[_e.NAME]=mn.toString(this.type)),e}},m_,Hu=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[m_]="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}};m_=Symbol.toStringTag;Hu.DEFAULT="default";var Et=new Hu,OT=/^[0-2](?:\.[1-9][0-9]*)+$/;function BT(r){return new RegExp(OT).test(r)}var Np=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 BT(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Qt=new Np;Qt.register("CN","2.5.4.3");Qt.register("L","2.5.4.7");Qt.register("ST","2.5.4.8");Qt.register("O","2.5.4.10");Qt.register("OU","2.5.4.11");Qt.register("C","2.5.4.6");Qt.register("DC","0.9.2342.19200300.100.1.25");Qt.register("E","1.2.840.113549.1.9.1");Qt.register("G","2.5.4.42");Qt.register("I","2.5.4.43");Qt.register("SN","2.5.4.4");Qt.register("T","2.5.4.12");function PT(r,e){return`\\${$.Convert.ToHex($.Convert.FromUtf8String(e)).toUpperCase()}`}function kT(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,PT)}var Sr=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 Np,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:$.BufferSourceConverter.isBufferSource(e)?this.asn=q.parse(e,Ne):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Qt.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)||Qt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${$.Convert.ToHex(t.value.anyValue)}`:kT(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?`#${$.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 p=this.createAttribute(s,a);i==="+"?t[t.length-1].push(p):t.push(new _o([p])),i=u}return t}fromJSON(e){let t=new Ne;for(let n of e){let o=new _o;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 Di({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=$.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 q.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]||Et.get()):n=e[0]||Et.get(),await n.subtle.digest(o,this.toArrayBuffer())}},g_="Cannot initialize GeneralName from ASN.1 data.",o_=`${g_} Unsupported string format in use.`,NT=`${g_} Value doesn't match to GUID regular expression.`,i_=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,s_="1.3.6.1.4.1.311.25.1",a_="1.3.6.1.4.1.311.20.2.3",Zm="dns",Ym="dn",Jm="email",Qm="ip",eg="url",tg="guid",rg="upn",Ip="id",yn=class extends Ho{constructor(...e){let t;if(e.length===2)switch(e[0]){case Ym:{let n=new Sr(e[1]).toArrayBuffer(),o=q.parse(n,Ne);t=new ce({directoryName:o});break}case Zm:t=new ce({dNSName:e[1]});break;case Jm:t=new ce({rfc822Name:e[1]});break;case tg:{let n=new RegExp(i_,"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?$.Convert.ToHex(new Uint8Array($.Convert.FromHex(i)).reverse()):i).join("");t=new ce({otherName:new So({typeId:s_,value:q.serialize(new se($.Convert.FromHex(o)))})});break}case Qm:t=new ce({iPAddress:e[1]});break;case Ip:t=new ce({registeredID:e[1]});break;case rg:{t=new ce({otherName:new So({typeId:a_,value:q.serialize(Cy.toASN(e[1]))})});break}case eg:t=new ce({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else $.BufferSourceConverter.isBufferSource(e[0])?t=q.parse(e[0],ce):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=Zm,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=Jm,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=Qm,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=eg,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Ip,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Ym,this.value=new Sr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===s_){this.type=tg;let t=q.parse(e.otherName.value,se),n=new RegExp(i_,"i").exec($.Convert.ToHex(t));if(!n)throw new Error(NT);this.value=n.slice(1).map((o,i)=>i<3?$.Convert.ToHex(new Uint8Array($.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===a_)this.type=rg,this.value=q.parse(e.otherName.value,at).toString();else throw new Error(o_);else throw new Error(o_)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Ym:case Zm:case tg:case Qm:case Ip:case rg:case eg:e=this.type.toUpperCase();break;case Jm:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Ip&&(t=mn.toString(t)),new _e(e,void 0,t)}},Zn=class extends Ho{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 ce)n.push(o);else{let i=q.parse(new yn(o.type,o.value).rawData,ce);n.push(i)}t=new Ve(n)}else if($.BufferSourceConverter.isBufferSource(e))t=q.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 yn(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[_e.NAME]];Array.isArray(o)||(o=[],e[n[_e.NAME]]=o),o.push(n)}return e}};Zn.NAME="GeneralNames";var Mu="-{5}",Vu="\\n",DT=`[^${Vu}]+`,jT=`${Mu}BEGIN (${DT}(?=${Mu}))${Mu}`,RT=`${Mu}END \\1${Mu}`,Ia="\\n",LT=`[^:${Vu}]+`,UT=`(?:[^${Vu}]+${Ia}(?: +[^${Vu}]+${Ia})*)`,MT="[a-zA-Z0-9=+/]+",KT=`(?:${MT}${Ia})+`,c_=`${jT}${Ia}(?:((?:${LT}: ${UT})+))?${Ia}?(${KT})${RT}`,Ht=class{static isPem(e){return typeof e=="string"&&new RegExp(c_,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(c_,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${Vu}]+`,"g"),""),s={type:o[1],headers:[],rawData:$.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Ia,"g")),u=null;for(let p of c){let[f,d]=p.split(/:(.*)/);if(d===void 0){if(!u)throw new Error("Cannot parse PEM string. Incorrect header value");u.value+=f.trim()}else u&&s.headers.push(u),u={key:f,value:d.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(!$.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:$.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
+ `)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:$.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=$.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
+ `)}};Ht.CertificateTag="CERTIFICATE";Ht.CrlTag="CRL";Ht.CertificateRequestTag="CERTIFICATE REQUEST";Ht.PublicKeyTag="PUBLIC KEY";Ht.PrivateKeyTag="PRIVATE KEY";var Vo=class r extends Ho{static isAsnEncoded(e){return $.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ht.isPem(e))return Ht.decode(e)[0];if($.Convert.isHex(e))return $.Convert.FromHex(e);if($.Convert.isBase64(e))return $.Convert.FromBase64(e);if($.Convert.isBase64Url(e))return $.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=$.Convert.ToBinary(e);return Ht.isPem(t)?Ht.decode(t)[0]:$.Convert.isHex(t)?$.Convert.FromHex(t):$.Convert.isBase64(t)?$.Convert.FromBase64(t):$.Convert.isBase64Url(t)?$.Convert.FromBase64Url(t):$.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 Ht.encode(this.rawData,this.tag);default:return super.toString(e)}}},zn=class r extends Vo{static async create(e,t=Et.get()){if(e instanceof r)return e;if(Hu.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($.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Vo.isAsnEncoded(e)?super(e,xt):super(e),this.tag=Ht.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]||Et.get()):t=e[0]||Et.get();let i=this.rawData,s=q.parse(this.rawData,xt);return s.algorithm.algorithm===No&&(i=HT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Ue.resolve(ps),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case pn:{let o=q.parse(e.subjectPublicKey,_a),i=$.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=$.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]||Et.get()):n=e[0]||Et.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=Et.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=Et.get();let o=q.parse(this.rawData,xt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,xt);switch(e.Algorithm=Xn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case es:e["EC Point"]=t.subjectPublicKey;break;case pn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function HT(r,e){return r.algorithm=new K({algorithm:pn,parameters:null}),e=q.serialize(r),e}var Dp=class r extends cr{static async create(e,t=!1,n=Et.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r($.Convert.ToHex(i),t)}constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new an({keyIdentifier:new Li($.Convert.FromHex(e[0]))});super(Ff,e[1],q.serialize(t))}else{let t=e[0],n=t.name instanceof Zn?q.parse(t.name.rawData,Ve):t.name,o=new an({authorityCertIssuer:n,authorityCertSerialNumber:$.Convert.FromHex(t.serialNumber)});super(Ff,e[1],q.serialize(o))}}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,an);t.keyIdentifier&&(this.keyId=$.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?$.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,an);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Zn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Dp.NAME="Authority Key Identifier";var Oa=class extends cr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Ui);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new Ui({cA:e[0],pathLenConstraint:e[1]});super(Wf,e[2],q.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}};Oa.NAME="Basic Constraints";var u_;(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"})(u_||(u_={}));var jp=class extends cr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,nu);this.usages=t.map(n=>n)}else{let t=new nu(e[0]);super(Xf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>mn.toString(t)).join(", "),e}};jp.NAME="Extended Key Usages";var l_;(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"})(l_||(l_={}));var Rp=class extends cr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,ea);this.usages=t.toNumber()}else{let t=new ea(e[0]);super(Zf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,ea);return e[""]=t.toJSON().join(", "),e}};Rp.NAME="Key Usages";var Lp=class r extends cr{static async create(e,t=!1,n=Et.get()){let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r($.Convert.ToHex(i),t)}constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,zt);this.keyId=$.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?$.Convert.FromHex(e[0]):e[0],n=new zt(t);super(Qy,e[1],q.serialize(n)),this.keyId=$.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,zt);return e[""]=t,e}};Lp.NAME="Subject Key Identifier";var Up=class extends cr{constructor(...e){$.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Yy,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,ep);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Up.NAME="Subject Alternative Name";var Vt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new cr(e),n=this.items.get(t.type);return n?new n(e):t}};Vt.items=new Map;var Mp=class extends cr{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=q.parse(this.value,Jc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Jc(n.map(s=>new Mi({policyIdentifier:s})));super(Gf,o,q.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new _e("",{},mn.toString(t))),e}};Mp.NAME="Certificate Policies";Vt.register(Gf,Mp);var Kp=class extends cr{constructor(...e){var t;if($.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 cn({distributionPoint:new Hn({fullName:[new ce({uniformResourceIdentifier:s})]})})),i=new Co(o);super(zf,e[1],q.serialize(i))}else{let n=new Co(e[0]);super(zf,e[1],q.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,Co);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 yn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Kp.NAME="CRL Distribution Points";var Hp=class extends cr{constructor(...e){var t,n,o,i;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Ri){let s=new Ri(e[0]);super($f,e[1],q.serialize(s))}else{let s=e[0],a=new Ri;Bp(a,s,Dy,"ocsp"),Bp(a,s,jy,"caIssuers"),Bp(a,s,Ry,"timeStamping"),Bp(a,s,Ly,"caRepository"),super($f,e[1],q.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=[],q.parse(e.extnValue,Ri).forEach(n=>{switch(n.accessMethod){case Dy:this.ocsp.push(new yn(n.accessLocation));break;case jy:this.caIssuers.push(new yn(n.accessLocation));break;case Ry:this.timeStamping.push(new yn(n.accessLocation));break;case Ly:this.caRepository.push(new yn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&Op(e,"OCSP",this.ocsp),this.caIssuers.length&&Op(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Op(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Op(e,"CA Repository",this.caRepository),e}};Hp.NAME="Authority Info Access";function Op(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new _e("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[_e.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function Bp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new yn("url",s)),r.push(new Mn({accessMethod:t,accessLocation:q.parse(s.rawData,ce)}))})}var Vp=class extends cr{constructor(...e){$.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Gy,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,Ve);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Vp.NAME="Issuer Alternative Name";var Ba=class r extends Ho{constructor(...e){let t;if($.BufferSourceConverter.isBufferSource(e[0]))t=$.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>$.BufferSourceConverter.toArrayBuffer(i)):[];t=q.serialize(new wt({type:n,values:o}))}super(t,wt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new _e("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[_e.NAME]===r.NAME&&(e[_e.NAME]=mn.toString(this.type)),e}};Ba.NAME="Attribute";var $p=class extends Ba{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new Du({printableString:e[0]});super(zm,[q.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],Du);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[_e.VALUE]=this.password,e}};$p.NAME="Challenge Password";var $u=class extends Ba{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new sr;for(let i of n)o.push(q.parse(i.rawData,vt));super(Ru,[q.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],sr);this.items=t.map(n=>Vt.create(q.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[_e.NAME]]=n;return e}};$u.NAME="Extensions";var Pa=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new Ba(e),n=this.items.get(t.type);return n?new n(e):t}};Pa.items=new Map;var Wu="crypto.signatureFormatter",ag=class{toAsnSignature(e,t){return $.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return $.BufferSourceConverter.toArrayBuffer(t)}},kp,cg=kp=class{static createPssParams(e,t){let n=kp.getHashAlgorithm(e);return n?new hn({hashAlgorithm:n,maskGenAlgorithm:new K({algorithm:Do,parameters:q.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Ue.resolve(ps);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 K({algorithm:ga,parameters:null});case"sha-256":return new K({algorithm:pp,parameters:null});case"sha-384":return new K({algorithm:ba,parameters:null});case"sha-512":return new K({algorithm:wa,parameters:null})}}else return new K({algorithm:pn,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=kp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new K({algorithm:No,parameters:q.serialize(t)})}else return new K({algorithm:No,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case pn:return{name:"RSASSA-PKCS1-v1_5"};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case pp:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ba:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case wa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case No:if(e.parameters){let t=q.parse(e.parameters,hn);return{name:"RSA-PSS",hash:Ue.resolve(ps).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};cg=kp=Iu([Ro()],cg);Ue.registerSingleton(Fu,cg);var ug=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new K({algorithm:rs});case"sha-256":return new K({algorithm:ns});case"sha-384":return new K({algorithm:os});case"sha-512":return new K({algorithm:is})}return null}toWebAlgorithm(e){switch(e.algorithm){case rs:return{name:"SHA-1"};case ns:return{name:"SHA-256"};case os:return{name:"SHA-384"};case is:return{name:"SHA-512"}}return null}};ug=Iu([Ro()],ug);Ue.registerSingleton(Fu,ug);var Yn=class r{addPadding(e,t){let n=$.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=$.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 ts,s=$.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),q.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=q.parse(t,ts),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,$.combine)(s,a)}return null}};Yn.namedCurveSize=new Map;Yn.defaultNamedCurveSize=32;var ng="1.3.101.110",f_="1.3.101.111",og="1.3.101.112",p_="1.3.101.113",lg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=og;break;case"x25519":t=ng;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=og;break;case"ed448":t=p_;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=ng;break;case"x448":t=f_;break}}return t?new K({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case og:return{name:"Ed25519"};case p_:return{name:"EdDSA",namedCurve:"Ed448"};case ng:return{name:"X25519"};case f_:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};lg=Iu([Ro()],lg);Ue.registerSingleton(Fu,lg);var fg=class extends Vo{constructor(e){Vo.isAsnEncoded(e)?super(e,Ko):super(e),this.tag=Ht.CertificateRequestTag}onInit(e){this.tbs=q.serialize(e.certificationRequestInfo),this.publicKey=new zn(e.certificationRequestInfo.subjectPKInfo);let t=Ue.resolve(ps);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>Pa.create(q.serialize(o)));let n=this.getAttribute(Ru);this.extensions=[],n instanceof $u&&(this.extensions=n.items),this.subjectName=new Sr(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=Et.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Ue.resolveAll(Wu).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=q.parse(this.rawData,Ko),n=t.certificationRequestInfo,o=new _e("",{Version:`${un[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new _e("");for(let s of this.attributes){let a=s.toTextObject();i[a[_e.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new _e("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};fg.NAME="PKCS#10 Certificate Request";var ka=class extends Vo{constructor(e){Vo.isAsnEncoded(e)?super(e,br):super(e),this.tag=Ht.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=q.serialize(t);let n=new Uint8Array(t.serialNumber);n.length>1&&n[0]===0&&n[1]>127&&(n=n.slice(1)),this.serialNumber=$.Convert.ToHex(n),this.subjectName=new Sr(t.subject),this.subject=new Sr(t.subject).toString(),this.issuerName=new Sr(t.issuer),this.issuer=this.issuerName.toString();let o=Ue.resolve(ps);this.signatureAlgorithm=o.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let i=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!i)throw new Error("Cannot get 'notBefore' value");this.notBefore=i;let s=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!s)throw new Error("Cannot get 'notAfter' value");this.notAfter=s,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(a=>Vt.create(q.serialize(a)))),this.publicKey=new zn(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=Et.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 zn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if($.BufferSourceConverter.isBufferSource(i)){let u=new zn(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(Wu).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 p=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<p&&p<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=Et.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=Et.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,br),n=t.tbsCertificate,o=new _e("",{Version:`${un[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Xn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new _e("",{"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 _e("");for(let s of this.extensions){let a=s.toTextObject();i[a[_e.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new _e("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ka.NAME="Certificate";var Fp=class{static async createSelfSigned(e,t=Et.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=Et.get()){var n;let o;e.publicKey instanceof zn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:$.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?$.BufferSourceConverter.toUint8Array($.Convert.FromHex(e.serialNumber)):void 0;i=this.generateSerialNumber(i,t);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new br({tbsCertificate:new _t({version:un.v3,serialNumber:i,validity:new Vn({notBefore:s,notAfter:a}),extensions:new sr(((n=e.extensions)===null||n===void 0?void 0:n.map(y=>q.parse(y.rawData,vt)))||[]),subjectPublicKeyInfo:q.parse(o,xt)})});if(e.subject){let y=e.subject instanceof Sr?e.subject:new Sr(e.subject);c.tbsCertificate.subject=q.parse(y.toArrayBuffer(),Ne)}if(e.issuer){let y=e.issuer instanceof Sr?e.issuer:new Sr(e.issuer);c.tbsCertificate.issuer=q.parse(y.toArrayBuffer(),Ne)}let u={hash:"SHA-256"},p="signingKey"in e?{...u,...e.signingAlgorithm,...e.signingKey.algorithm}:{...u,...e.signingAlgorithm},f=Ue.resolve(ps);c.tbsCertificate.signature=c.signatureAlgorithm=f.toAsnAlgorithm(p);let d=q.serialize(c.tbsCertificate),m="signingKey"in e?await t.subtle.sign(p,e.signingKey,d):e.signature,g=Ue.resolveAll(Wu).reverse(),w=null;for(let y of g)if(w=y.toAsnSignature(p,m),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new ka(q.serialize(c))}static generateSerialNumber(e,t){let n=e&&e.length&&e.some(i=>i>0)?new Uint8Array(e):void 0;n||(n=t.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n}},h_;(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"})(h_||(h_={}));Vt.register(Wf,Oa);Vt.register(Xf,jp);Vt.register(Zf,Rp);Vt.register(Qy,Lp);Vt.register(Ff,Dp);Vt.register(Yy,Up);Vt.register(zf,Kp);Vt.register($f,Hp);Vt.register(Gy,Vp);Pa.register(zm,$p);Pa.register(Ru,$u);Ue.registerSingleton(Wu,ag);Ue.registerSingleton(Wu,Yn);Yn.namedCurveSize.set("P-256",32);Yn.namedCurveSize.set("K-256",32);Yn.namedCurveSize.set("P-384",48);Yn.namedCurveSize.set("P-521",66);var Jn="/",b_=new TextEncoder().encode(Jn),Wp=b_[0],qu=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]!==Wp)throw new Error("Invalid key")}toString(e="utf8"){return ue(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Jn))}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=b_),this._buf[0]!==Wp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Wp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Wp;)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(Jn).slice(1)}type(){return VT(this.baseNamespace())}name(){return $T(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Jn)||(e+=Jn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Jn):new r(e.slice(0,-1).join(Jn))}child(e){return this.toString()===Jn?e:e.toString()===Jn?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(),...FT(e.map(t=>t.namespaces()))])}};function VT(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function $T(r){let e=r.split(":");return e[e.length-1]}function FT(r){return[].concat(...r)}var qp=class extends ro{async listen(){throw new mf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function pg(){let r=rt(),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 w_(){let r=pg(),e=pg();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function WT(r){return r[Symbol.asyncIterator]!=null}async function qT(r,e,t){try{await Promise.all(r.map(async n=>{for await(let o of n)await e.push(o,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*GT(r){let e=new AbortController,t=uf();qT(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*zT(r){for(let e of r)yield*e}function XT(...r){let e=[];for(let t of r)WT(t)||e.push(t);return e.length===r.length?zT(e):GT(r)}var x_=XT;function v_(r,...e){if(r==null)throw new Error("Empty pipeline");if(hg(r)){let n=r;r=()=>n.source}else if(S_(r)||__(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&hg(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++)hg(t[n])&&(t[n]=YT(t[n]));return ZT(...t)}var ZT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},__=r=>r?.[Symbol.asyncIterator]!=null,S_=r=>r?.[Symbol.iterator]!=null,hg=r=>r==null?!1:r.sink!=null&&r.source!=null,YT=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Ws({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(__(i))o=async function*(){yield*i,n.end()};else if(S_(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return x_(n,o())}return r.source};var Na=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function E_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Gp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function zp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function jt(r,...e){if(!E_(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 dg(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 C_(r,e){jt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Qn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function eo(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function JT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var QT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function eI(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Xp(r){if(typeof r=="string")r=eI(r);else if(E_(r))r=Zp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function T_(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function I_(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 yg=(r,e)=>{function t(n,...o){if(jt(n),!QT)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let p=o[0];if(!p)throw new Error("nonce / iv required");r.varSizeNonce?jt(p):jt(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&jt(o[1]);let s=e(n,...o),a=(p,f)=>{if(f!==void 0){if(p!==2)throw new Error("cipher output not supported");jt(f)}},c=!1;return{encrypt(p,f){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,jt(p),a(s.encrypt.length,f),s.encrypt(p,f)},decrypt(p,f){if(jt(p),i&&p.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,f),s.decrypt(p,f)}}}return Object.assign(t,r),t};function mg(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&&!tI(e))throw new Error("invalid output, must be aligned");return e}function A_(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 O_(r,e,t){Gp(t);let n=new Uint8Array(16),o=JT(n);return A_(o,0,BigInt(e),t),A_(o,8,BigInt(r),t),n}function tI(r){return r.byteOffset%4===0}function Zp(r){return Uint8Array.from(r)}var P_=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),rI=P_("expand 16-byte k"),nI=P_("expand 32-byte k"),oI=Qn(rI),iI=Qn(nI);function te(r,e){return r<<e|r>>>32-e}function gg(r){return r.byteOffset%4===0}var Yp=64,sI=16,k_=2**32-1,B_=new Uint32Array;function aI(r,e,t,n,o,i,s,a){let c=o.length,u=new Uint8Array(Yp),p=Qn(u),f=gg(o)&&gg(i),d=f?Qn(o):B_,m=f?Qn(i):B_;for(let g=0;g<c;s++){if(r(e,t,n,p,s,a),s>=k_)throw new Error("arx: counter overflow");let w=Math.min(Yp,c-g);if(f&&w===Yp){let y=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let T=0,j;T<sI;T++)j=y+T,m[j]=d[j]^p[T];g+=Yp;continue}for(let y=0,T;y<w;y++)T=g+y,i[T]=o[T]^u[y];g+=w}}function bg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=T_({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return zp(o),zp(s),Gp(i),Gp(t),(a,c,u,p,f=0)=>{jt(a),jt(c),jt(u);let d=u.length;if(p===void 0&&(p=new Uint8Array(d)),jt(p),zp(f),f<0||f>=k_)throw new Error("arx: counter overflow");if(p.length<d)throw new Error(`arx: output (${p.length}) is shorter than data (${d})`);let m=[],g=a.length,w,y;if(g===32)m.push(w=Zp(a)),y=iI;else if(g===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),y=oI,m.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);gg(c)||m.push(c=Zp(c));let T=Qn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(y,T,Qn(c.subarray(0,16)),T),c=c.subarray(16)}let j=16-o;if(j!==c.length)throw new Error(`arx: nonce must be ${j} or 16 bytes`);if(j!==12){let V=new Uint8Array(12);V.set(c,i?0:12-c.length),c=V,m.push(c)}let L=Qn(c);return aI(r,y,T,L,u,p,f,s),eo(...m),p}}var Ct=(r,e)=>r[e++]&255|(r[e++]&255)<<8,wg=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=Xp(e),jt(e,32);let t=Ct(e,0),n=Ct(e,2),o=Ct(e,4),i=Ct(e,6),s=Ct(e,8),a=Ct(e,10),c=Ct(e,12),u=Ct(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 p=0;p<8;p++)this.pad[p]=Ct(e,16+2*p)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],u=s[2],p=s[3],f=s[4],d=s[5],m=s[6],g=s[7],w=s[8],y=s[9],T=Ct(e,t+0),j=Ct(e,t+2),L=Ct(e,t+4),V=Ct(e,t+6),re=Ct(e,t+8),U=Ct(e,t+10),Y=Ct(e,t+12),Q=Ct(e,t+14),F=i[0]+(T&8191),C=i[1]+((T>>>13|j<<3)&8191),E=i[2]+((j>>>10|L<<6)&8191),k=i[3]+((L>>>7|V<<9)&8191),P=i[4]+((V>>>4|re<<12)&8191),M=i[5]+(re>>>1&8191),H=i[6]+((re>>>14|U<<2)&8191),I=i[7]+((U>>>11|Y<<5)&8191),_=i[8]+((Y>>>8|Q<<8)&8191),R=i[9]+(Q>>>5|o),B=0,G=B+F*a+C*(5*y)+E*(5*w)+k*(5*g)+P*(5*m);B=G>>>13,G&=8191,G+=M*(5*d)+H*(5*f)+I*(5*p)+_*(5*u)+R*(5*c),B+=G>>>13,G&=8191;let X=B+F*c+C*a+E*(5*y)+k*(5*w)+P*(5*g);B=X>>>13,X&=8191,X+=M*(5*m)+H*(5*d)+I*(5*f)+_*(5*p)+R*(5*u),B+=X>>>13,X&=8191;let D=B+F*u+C*c+E*a+k*(5*y)+P*(5*w);B=D>>>13,D&=8191,D+=M*(5*g)+H*(5*m)+I*(5*d)+_*(5*f)+R*(5*p),B+=D>>>13,D&=8191;let fe=B+F*p+C*u+E*c+k*a+P*(5*y);B=fe>>>13,fe&=8191,fe+=M*(5*w)+H*(5*g)+I*(5*m)+_*(5*d)+R*(5*f),B+=fe>>>13,fe&=8191;let me=B+F*f+C*p+E*u+k*c+P*a;B=me>>>13,me&=8191,me+=M*(5*y)+H*(5*w)+I*(5*g)+_*(5*m)+R*(5*d),B+=me>>>13,me&=8191;let pe=B+F*d+C*f+E*p+k*u+P*c;B=pe>>>13,pe&=8191,pe+=M*a+H*(5*y)+I*(5*w)+_*(5*g)+R*(5*m),B+=pe>>>13,pe&=8191;let ye=B+F*m+C*d+E*f+k*p+P*u;B=ye>>>13,ye&=8191,ye+=M*c+H*a+I*(5*y)+_*(5*w)+R*(5*g),B+=ye>>>13,ye&=8191;let Ae=B+F*g+C*m+E*d+k*f+P*p;B=Ae>>>13,Ae&=8191,Ae+=M*u+H*c+I*a+_*(5*y)+R*(5*w),B+=Ae>>>13,Ae&=8191;let Re=B+F*w+C*g+E*m+k*d+P*f;B=Re>>>13,Re&=8191,Re+=M*p+H*u+I*c+_*a+R*(5*y),B+=Re>>>13,Re&=8191;let nt=B+F*y+C*w+E*g+k*m+P*d;B=nt>>>13,nt&=8191,nt+=M*f+H*p+I*u+_*c+R*a,B+=nt>>>13,nt&=8191,B=(B<<2)+B|0,B=B+G|0,G=B&8191,B=B>>>13,X+=B,i[0]=G,i[1]=X,i[2]=D,i[3]=fe,i[4]=me,i[5]=pe,i[6]=ye,i[7]=Ae,i[8]=Re,i[9]=nt}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;eo(n)}update(e){dg(this),e=Xp(e),jt(e);let{buffer:t,blockLen:n}=this,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(){eo(this.h,this.r,this.buffer,this.pad)}digestInto(e){dg(this),C_(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 cI(r){let e=(n,o)=>r(o).update(Xp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var N_=cI(r=>new wg(r));function R_(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],u=r[3],p=e[0],f=e[1],d=e[2],m=e[3],g=e[4],w=e[5],y=e[6],T=e[7],j=o,L=t[0],V=t[1],re=t[2],U=s,Y=a,Q=c,F=u,C=p,E=f,k=d,P=m,M=g,H=w,I=y,_=T,R=j,B=L,G=V,X=re;for(let fe=0;fe<i;fe+=2)U=U+C|0,R=te(R^U,16),M=M+R|0,C=te(C^M,12),U=U+C|0,R=te(R^U,8),M=M+R|0,C=te(C^M,7),Y=Y+E|0,B=te(B^Y,16),H=H+B|0,E=te(E^H,12),Y=Y+E|0,B=te(B^Y,8),H=H+B|0,E=te(E^H,7),Q=Q+k|0,G=te(G^Q,16),I=I+G|0,k=te(k^I,12),Q=Q+k|0,G=te(G^Q,8),I=I+G|0,k=te(k^I,7),F=F+P|0,X=te(X^F,16),_=_+X|0,P=te(P^_,12),F=F+P|0,X=te(X^F,8),_=_+X|0,P=te(P^_,7),U=U+E|0,X=te(X^U,16),I=I+X|0,E=te(E^I,12),U=U+E|0,X=te(X^U,8),I=I+X|0,E=te(E^I,7),Y=Y+k|0,R=te(R^Y,16),_=_+R|0,k=te(k^_,12),Y=Y+k|0,R=te(R^Y,8),_=_+R|0,k=te(k^_,7),Q=Q+P|0,B=te(B^Q,16),M=M+B|0,P=te(P^M,12),Q=Q+P|0,B=te(B^Q,8),M=M+B|0,P=te(P^M,7),F=F+C|0,G=te(G^F,16),H=H+G|0,C=te(C^H,12),F=F+C|0,G=te(G^F,8),H=H+G|0,C=te(C^H,7);let D=0;n[D++]=s+U|0,n[D++]=a+Y|0,n[D++]=c+Q|0,n[D++]=u+F|0,n[D++]=p+C|0,n[D++]=f+E|0,n[D++]=d+k|0,n[D++]=m+P|0,n[D++]=g+M|0,n[D++]=w+H|0,n[D++]=y+I|0,n[D++]=T+_|0,n[D++]=j+R|0,n[D++]=L+B|0,n[D++]=V+G|0,n[D++]=re+X|0}function uI(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],u=e[1],p=e[2],f=e[3],d=e[4],m=e[5],g=e[6],w=e[7],y=t[0],T=t[1],j=t[2],L=t[3];for(let re=0;re<20;re+=2)o=o+c|0,y=te(y^o,16),d=d+y|0,c=te(c^d,12),o=o+c|0,y=te(y^o,8),d=d+y|0,c=te(c^d,7),i=i+u|0,T=te(T^i,16),m=m+T|0,u=te(u^m,12),i=i+u|0,T=te(T^i,8),m=m+T|0,u=te(u^m,7),s=s+p|0,j=te(j^s,16),g=g+j|0,p=te(p^g,12),s=s+p|0,j=te(j^s,8),g=g+j|0,p=te(p^g,7),a=a+f|0,L=te(L^a,16),w=w+L|0,f=te(f^w,12),a=a+f|0,L=te(L^a,8),w=w+L|0,f=te(f^w,7),o=o+u|0,L=te(L^o,16),g=g+L|0,u=te(u^g,12),o=o+u|0,L=te(L^o,8),g=g+L|0,u=te(u^g,7),i=i+p|0,y=te(y^i,16),w=w+y|0,p=te(p^w,12),i=i+p|0,y=te(y^i,8),w=w+y|0,p=te(p^w,7),s=s+f|0,T=te(T^s,16),d=d+T|0,f=te(f^d,12),s=s+f|0,T=te(T^s,8),d=d+T|0,f=te(f^d,7),a=a+c|0,j=te(j^a,16),m=m+j|0,c=te(c^m,12),a=a+c|0,j=te(j^a,8),m=m+j|0,c=te(c^m,7);let V=0;n[V++]=o,n[V++]=i,n[V++]=s,n[V++]=a,n[V++]=y,n[V++]=T,n[V++]=j,n[V++]=L}var lI=bg(R_,{counterRight:!1,counterLength:4,allowShortKeys:!1}),fI=bg(R_,{counterRight:!1,counterLength:8,extendNonceFn:uI,allowShortKeys:!1});var pI=new Uint8Array(16),D_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(pI.subarray(t))},hI=new Uint8Array(32);function j_(r,e,t,n,o){let i=r(e,t,hI),s=N_.create(i);o&&D_(s,o),D_(s,n);let a=O_(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return eo(i,a),c}var L_=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=mg(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let u=j_(r,e,t,c,n);return s.set(u,a),eo(u),s},decrypt(i,s){s=mg(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=j_(r,e,t,a,n);if(!I_(c,u))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),eo(u),s}}),xg=yg({blockSize:64,nonceLength:12,tagLength:16},L_(lI)),GX=yg({blockSize:64,nonceLength:24,tagLength:16},L_(fI));function M_(r,e,t){return Qo(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Ds(r,so(t),so(e))}var vg=Uint8Array.from([0]),U_=Uint8Array.of();function K_(r,e,t,n=32){Qo(r),Yo(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=U_);let s=new Uint8Array(i*o),a=Ds.create(r,e),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)vg[0]=p+1,c.update(p===0?U_:u).update(t).update(vg).digestInto(u),s.set(u,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),Or(u,vg),s.slice(0,n)}var _g={hashSHA256(r){return po(r.subarray())},getHKDF(r,e){let t=M_(po,e,r),o=K_(po,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=Qa.utils.randomPrivateKey();return{publicKey:Qa.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Qa.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Qa.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return xg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return xg(n,e,t).decrypt(r.subarray(),o)}};var H_=_g;function V_(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 Da=r=>{let e=lt(2);return e[0]=r>>8,e[1]=r,e};Da.bytes=2;var Gu=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)};Gu.bytes=2;function $_(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 Sg(r,e){!e.enabled||!Na||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local static keys."))}function Ag(r,e){!e.enabled||!Na||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function F_(r,e){!e.enabled||!Na||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function Eg(r,e){!e.enabled||!Na||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Cg(r,e,t){!t.enabled||!Na||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ue(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ue(e.k,"hex")}`))}var ja=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var dI=0,yI=4294967295,mI="Cipherstate has reached maximum n, a new handshake must be performed",Jp=class{n;bytes;view;constructor(e=dI){this.n=e,this.bytes=ut(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>yI)throw new Error(mI)}};var hs=ut(0),Ra=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Jp(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}},Tg=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=gI(e,n),this.ck=this.h,this.cs=new Ra(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Ra(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new ve(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,hs);return[new Ra(this.crypto,e),new Ra(this.crypto,t)]}},Ig=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 Tg(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()}},zu=class extends Ig{writeMessageA(e){return new ve(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new ve(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new ve(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new ja(`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 ja(`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 ja(`handshake stage 2 validation fail: ${t.message}`)}}};function gI(r,e){if(e.length<=32){let t=ut(32);return t.set(e),t}else return r.hash(e)}var Qp;(function(r){let e;r.codec=()=>(e==null&&(e=Rr((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 sc('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 sc('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=>jr(t,r.codec()),r.decode=(t,n)=>Dr(t,r.codec(),n)})(Qp||(Qp={}));var Xu;(function(r){let e;r.codec=()=>(e==null&&(e=Rr((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),Qp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ut(0),identitySig:ut(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=Qp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>jr(t,r.codec()),r.decode=(t,n)=>Dr(t,r.codec(),n)})(Xu||(Xu={}));async function Og(r,e,t){let n=await r.sign(W_(e));return Xu.encode({identityKey:io(r.publicKey),identitySig:n,extensions:t})}async function Bg(r,e,t){try{let n=Xu.decode(r),o=lc(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=W_(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Qu(n.message)}}function W_(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?Rt([e,r],e.length+r.length):(r.prepend(e),r)}async function q_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await Og(i,a.publicKey,u),f=new zu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Sg(f.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(f.writeMessageA(hs),e),t.trace("Stage 0 - Initiator finished sending first message."),Ag(f.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=f.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Eg(f.re,t),F_(f.rs,t),t.trace("Initiator going to check remote's signature...");let m=await Bg(d,f.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(f.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,w]=f.ss.split();return Cg(g,w,t),{payload:m,encrypt:y=>g.encryptWithAd(hs,y),decrypt:(y,T)=>w.decryptWithAd(hs,y,T)}}async function G_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await Og(i,a.publicKey,u),f=new zu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Sg(f.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),f.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),Eg(f.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(f.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Ag(f.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let d=f.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let m=await Bg(d,f.rs,c),[g,w]=f.ss.split();return Cg(g,w,t),{payload:m,encrypt:y=>w.encryptWithAd(hs,y),decrypt:(y,T)=>g.decryptWithAd(hs,y,T)}}var X_=16;function Z_(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 ve(Da(s.byteLength),s)}}}function Y_(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-X_<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-X_);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var eh=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??H_;this.crypto=V_(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?$_(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ut(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[ys]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=Bc(e,{lengthEncoder:Da,lengthDecoder:Gu,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=lc(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:Nd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)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 el("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=Bc(e,{lengthEncoder:Da,lengthDecoder:Gu,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=lc(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:Nd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await q_({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:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async performHandshakeResponder(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await G_({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:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async createSecureConnection(e,t){let[n,o]=w_(),i=e.unwrap();return await v_(n,Z_(t,this.metrics),i,s=>gi(s,{lengthDecoder:Gu}),Y_(t,this.metrics),n),o}};function J_(r={}){return e=>new eh(e,r)}var Pg=Object.values(zo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),bI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function Q_(r){return r?.match(bI)?.groups?.fingerprint}function kg(r){let t=r.stringTuples().filter(n=>n[0]===Cw).map(n=>n[1])[0];if(t===void 0||t==="")throw new ke(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function wI(r){return Cr.decode(Pg.decode(r))}function xI(r){let e=wI(kg(r)),t=vI(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 yf(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function eS(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=It(ur.code,t);return Bn(`/certhash/${Go.encode(n.bytes)}`)}function vI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new gf(r)}}function tS(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=xI(r);return{type:"answer",sdp:`v=0
13
13
  o=- 0 0 IN IP${o} ${t}
14
14
  s=-
15
15
  t=0 0
@@ -23,10 +23,10 @@ a=ice-pwd:${e}
23
23
  a=fingerprint:${i}
24
24
  a=setup:passive
25
25
  a=sctp-port:5000
26
- a=max-message-size:${Cs}
26
+ a=max-message-size:${$s}
27
27
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
28
28
  a=end-of-candidates
29
- `}}function L_(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
29
+ `}}function rS(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}
@@ -39,16 +39,16 @@ a=ice-ufrag:${e}
39
39
  a=ice-pwd:${e}
40
40
  a=fingerprint:sha-256 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
41
41
  a=sctp-port:5000
42
- a=max-message-size:${Cs}
42
+ a=max-message-size:${$s}
43
43
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
44
44
  a=end-of-candidates
45
- `}}function mg(r,e){if(r.sdp===void 0)throw new Ie("Can't munge a missing SDP");let t=r.sdp.includes(`\r
45
+ `}}function Ng(r,e){if(r.sdp===void 0)throw new ke("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 gg=he("libp2p-webrtc-noise:");function M_(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=he(n,"hex"),i=At(ar.code,o),s=dg.decode(yg(e)),a=gg.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?Bt([gg,s,i.bytes],a):Bt([gg,i.bytes,s],a)}var QT=dc?"iceconnectionstatechange":"connectionstatechange";async function K_(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=mg(p,e);t.log.trace("client setting local offer %s",y.sdp),await r.setLocalDescription(y);let m=R_(t.remoteAddr,e);t.log.trace("client setting server description %s",m.sdp),await r.setRemoteDescription(m)}else{let p=L_(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 m=mg(y,e);t.log.trace("server setting local description %s",y.sdp),await r.setLocalDescription(m)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await gc(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(j_(p))}let o=D_(r.localDescription?.sdp);if(o==null)throw new oo("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=M_(o,t.remoteAddr,t.role),s=k_({prologueBytes:i})(t),a=Ps({channel:n,direction:"outbound",handshake:!0,log:t.log,...t.dataChannel??{}}),c=new Qo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(QT,()=>{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 l=new no(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,skipStreamMuxerNegotiation:!0}),t.log.trace("%s upgrade outbound",t.role),await t.upgrader.upgradeOutbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:l,signal:t.signal});t.log.trace("%s secure outbound",t.role);let f=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal,skipStreamMuxerNegotiation:!0});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${f.remotePeer}`),t.log.trace("%s upgrade inbound",t.role),await t.upgrader.upgradeInbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:l,signal:t.signal})}catch(o){throw n.close(),o}}async function H_(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 V_(r){let e=await El(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...le(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 Wn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new Ie("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"})})}[Hu]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[es]=["@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=Cl(o));let i=Tb(),s=await H_("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await K_(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 Zu;return new Rp(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(rb.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(eI(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 V_(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??mb,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new No;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 Iw("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 ju(this.init.certificateDatastoreKey??yb),i=await El(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new No;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??$d)-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:Do.encode((await ar.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ma(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??$d);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new No;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(!We(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 No;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??gb));n.setMilliseconds(0),o.setMilliseconds(0);let i=await Dp.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 ha(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,he(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 eI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function tI(r){return e=>new Wp(e,r)}function rI(r){return e=>new ff(e,r)}return oS(nI);})();
50
+ a=ice-pwd:`+e+t),r}var Dg=de("libp2p-webrtc-noise:");function oS(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=It(ur.code,o),s=Pg.decode(kg(e)),a=Dg.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?Rt([Dg,s,i.bytes],a):Rt([Dg,i.bytes,s],a)}var _I=Cc?"iceconnectionstatechange":"connectionstatechange";async function iS(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let f=await r.createOffer();t.log.trace("client created local offer %s",f.sdp);let d=Ng(f,e);t.log.trace("client setting local offer %s",d.sdp),await r.setLocalDescription(d);let m=tS(t.remoteAddr,e);t.log.trace("client setting server description %s",m.sdp),await r.setRemoteDescription(m)}else{let f=rS(t.remoteAddr,e);t.log.trace("server setting client %s %s",f.type,f.sdp),await r.setRemoteDescription(f),t.log.trace("server creating local answer");let d=await r.createAnswer();t.log.trace("server created local answer");let m=Ng(d,e);t.log.trace("server setting local description %s",d.sdp),await r.setLocalDescription(m)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await Oc(n,"open",t.signal)),t.log.trace("%s handshake channel opened",t.role),t.role==="server"){let f=r.remoteFingerprint()?.value??"";t.remoteAddr=t.remoteAddr.encapsulate(eS(f))}let o=Q_(r.localDescription?.sdp);if(o==null)throw new mo("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=oS(o,t.remoteAddr,t.role),s=J_({prologueBytes:i})(t),a=Gs({channel:n,direction:"outbound",handshake:!0,log:t.log,...t.dataChannel??{}}),c=new yi(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(_I,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":c.close().catch(f=>{t.log.error("error closing connection",f),c.abort(f)});break;default:break}}),t.events?.increment({peer_connection:!0});let u=new yo(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,skipStreamMuxerNegotiation:!0}),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 p=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal,skipStreamMuxerNegotiation:!0});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${p.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 sS(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 aS(r){let e=await Dl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ue(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
+ `)}var th=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 ro,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new ke("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"})})}[Ju]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[ys]=["@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=jl(o));let i=Ww(),s=await sS("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await iS(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 al;return new qp(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(xw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(SI(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 aS(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Dw,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Wo;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 qb("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 qu(this.init.certificateDatastoreKey??Nw),i=await Dl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Wo;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??iy)-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:Go.encode((await ur.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ka(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??iy);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Wo;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 Wo;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??jw));n.setMilliseconds(0),o.setMilliseconds(0);let i=await Fp.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 Oa(!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 SI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function AI(r){return e=>new th(e,r)}function EI(r){return e=>new vf(e,r)}return _S(CI);})();
52
52
  /*! Bundled license information:
53
53
 
54
54
  reflect-metadata/Reflect.js: