@libp2p/webrtc 5.2.20 → 5.2.21
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 +12 -12
- package/dist/index.min.js.map +3 -3
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +99 -125
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +2 -2
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +9 -21
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/package.json +2 -2
- package/src/private-to-private/initiate-connection.ts +106 -132
- package/src/private-to-private/transport.ts +13 -25
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 K_=Object.create;var ku=Object.defineProperty;var H_=Object.getOwnPropertyDescriptor;var V_=Object.getOwnPropertyNames;var $_=Object.getPrototypeOf,F_=Object.prototype.hasOwnProperty;var Kp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_t=(r,e)=>{for(var t in e)ku(r,t,{get:e[t],enumerable:!0})},hg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of V_(e))!F_.call(r,o)&&o!==t&&ku(r,o,{get:()=>e[o],enumerable:!(n=H_(e,o))||n.enumerable});return r};var Vr=(r,e,t)=>(t=r!=null?K_($_(r)):{},hg(e||!r||!r.__esModule?ku(t,"default",{value:r,enumerable:!0}):t,r)),W_=r=>hg(ku({},"__esModule",{value:!0}),r);var Cb=Kp(()=>{var Eb;(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 Mp(Object.create(null))}:c?function(){return Mp({__proto__:null})}:function(){return Mp({})},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:j_(),m=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:R_(),x=typeof WeakMap=="function"?WeakMap:L_(),v=o?Symbol.for("@reflect-metadata:registry"):void 0,d=k_(),C=N_(d);function R(b,S,k,$){if(U(k)){if(!or(b))throw new TypeError;if(!sg(S))throw new TypeError;return O(b,S)}else{if(!or(b))throw new TypeError;if(!se(S))throw new TypeError;if(!se($)&&!U($)&&!he($))throw new TypeError;return he($)&&($=void 0),k=ut(k),B(b,S,k,$)}}e("decorate",R);function D(b,S){function k($,ce){if(!se($))throw new TypeError;if(!U(ce)&&!P_(ce))throw new TypeError;X(b,S,$,ce)}return k}e("metadata",D);function Z(b,S,k,$){if(!se(k))throw new TypeError;return U($)||($=ut($)),X(b,S,k,$)}e("defineMetadata",Z);function P(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),j(b,S,k)}e("hasMetadata",P);function q(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),N(b,S,k)}e("hasOwnMetadata",q);function M(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),L(b,S,k)}e("getMetadata",M);function K(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),F(b,S,k)}e("getOwnMetadata",K);function g(b,S){if(!se(b))throw new TypeError;return U(S)||(S=ut(S)),W(b,S)}e("getMetadataKeys",g);function I(b,S){if(!se(b))throw new TypeError;return U(S)||(S=ut(S)),ie(b,S)}e("getOwnMetadataKeys",I);function E(b,S,k){if(!se(S))throw new TypeError;if(U(k)||(k=ut(k)),!se(S))throw new TypeError;U(k)||(k=ut(k));var $=ma(S,k,!1);return U($)?!1:$.OrdinaryDeleteMetadata(b,S,k)}e("deleteMetadata",E);function O(b,S){for(var k=b.length-1;k>=0;--k){var $=b[k],ce=$(S);if(!U(ce)&&!he(ce)){if(!sg(ce))throw new TypeError;S=ce}}return S}function B(b,S,k,$){for(var ce=b.length-1;ce>=0;--ce){var qe=b[ce],rt=qe(S,k,$);if(!U(rt)&&!he(rt)){if(!se(rt))throw new TypeError;$=rt}}return $}function j(b,S,k){var $=N(b,S,k);if($)return!0;var ce=Up(S);return he(ce)?!1:j(b,ce,k)}function N(b,S,k){var $=ma(S,k,!1);return U($)?!1:et($.OrdinaryHasOwnMetadata(b,S,k))}function L(b,S,k){var $=N(b,S,k);if($)return F(b,S,k);var ce=Up(S);if(!he(ce))return L(b,ce,k)}function F(b,S,k){var $=ma(S,k,!1);if(!U($))return $.OrdinaryGetOwnMetadata(b,S,k)}function X(b,S,k,$){var ce=ma(k,$,!0);ce.OrdinaryDefineOwnMetadata(b,S,k,$)}function W(b,S){var k=ie(b,S),$=Up(b);if($===null)return k;var ce=W($,S);if(ce.length<=0)return k;if(k.length<=0)return ce;for(var qe=new m,rt=[],ge=0,J=k;ge<J.length;ge++){var ee=J[ge],re=qe.has(ee);re||(qe.add(ee),rt.push(ee))}for(var ne=0,we=ce;ne<we.length;ne++){var ee=we[ne],re=qe.has(ee);re||(qe.add(ee),rt.push(ee))}return rt}function ie(b,S){var k=ma(b,S,!1);return k?k.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 he(b){return b===null}function Oe(b){return typeof b=="symbol"}function se(b){return typeof b=="object"?b!==null:typeof b=="function"}function Ne(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 k=S===3?"string":S===5?"number":"default",$=ag(b,i);if($!==void 0){var ce=$.call(b,k);if(se(ce))throw new TypeError;return ce}return vt(b,k==="default"?"number":k)}function vt(b,S){if(S==="string"){var k=b.toString;if(zi(k)){var $=k.call(b);if(!se($))return $}var ce=b.valueOf;if(zi(ce)){var $=ce.call(b);if(!se($))return $}}else{var ce=b.valueOf;if(zi(ce)){var $=ce.call(b);if(!se($))return $}var qe=b.toString;if(zi(qe)){var $=qe.call(b);if(!se($))return $}}throw new TypeError}function et(b){return!!b}function tt(b){return""+b}function ut(b){var S=Ne(b,3);return Oe(S)?S:tt(S)}function or(b){return Array.isArray?Array.isArray(b):b instanceof Object?b instanceof Array:Object.prototype.toString.call(b)==="[object Array]"}function zi(b){return typeof b=="function"}function sg(b){return typeof b=="function"}function P_(b){switch(Y(b)){case 3:return!0;case 4:return!0;default:return!1}}function Lp(b,S){return b===S||b!==b&&S!==S}function ag(b,S){var k=b[S];if(k!=null){if(!zi(k))throw new TypeError;return k}}function cg(b){var S=ag(b,s);if(!zi(S))throw new TypeError;var k=S.call(b);if(!se(k))throw new TypeError;return k}function ug(b){return b.value}function lg(b){var S=b.next();return S.done?!1:S}function fg(b){var S=b.return;S&&S.call(b)}function Up(b){var S=Object.getPrototypeOf(b);if(typeof b!="function"||b===p||S!==p)return S;var k=b.prototype,$=k&&Object.getPrototypeOf(k);if($==null||$===Object.prototype)return S;var ce=$.constructor;return typeof ce!="function"||ce===b?S:ce}function B_(){var b;!U(v)&&typeof t.Reflect<"u"&&!(v in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(b=D_(t.Reflect));var S,k,$,ce=new x,qe={registerProvider:rt,getProvider:J,setProvider:re};return qe;function rt(ne){if(!Object.isExtensible(qe))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(k):k=ne;break;case k===ne:break;default:$===void 0&&($=new m),$.add(ne);break}}function ge(ne,we){if(!U(S)){if(S.isProviderFor(ne,we))return S;if(!U(k)){if(k.isProviderFor(ne,we))return S;if(!U($))for(var Ue=cg($);;){var ze=lg(Ue);if(!ze)return;var br=ug(ze);if(br.isProviderFor(ne,we))return fg(Ue),br}}}if(!U(b)&&b.isProviderFor(ne,we))return b}function J(ne,we){var Ue=ce.get(ne),ze;return U(Ue)||(ze=Ue.get(we)),U(ze)&&(ze=ge(ne,we),U(ze)||(U(Ue)&&(Ue=new y,ce.set(ne,Ue)),Ue.set(we,ze))),ze}function ee(ne){if(U(ne))throw new TypeError;return S===ne||k===ne||!U($)&&$.has(ne)}function re(ne,we,Ue){if(!ee(Ue))throw new Error("Metadata provider not registered.");var ze=J(ne,we);if(ze!==Ue){if(!U(ze))return!1;var br=ce.get(ne);U(br)&&(br=new y,ce.set(ne,br)),br.set(we,Ue)}return!0}}function k_(){var b;return!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&(b=t.Reflect[v]),U(b)&&(b=B_()),!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,v,{enumerable:!1,configurable:!1,writable:!1,value:b}),b}function N_(b){var S=new x,k={isProviderFor:function(ee,re){var ne=S.get(ee);return U(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:rt,OrdinaryHasOwnMetadata:ce,OrdinaryGetOwnMetadata:qe,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:J};return d.registerProvider(k),k;function $(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 ze=we.get(re);if(U(ze)){if(!ne)return;if(ze=new y,we.set(re,ze),!b.setProvider(ee,re,k))throw we.delete(re),Ue&&S.delete(ee),new Error("Wrong provider for target.")}return ze}function ce(ee,re,ne){var we=$(re,ne,!1);return U(we)?!1:et(we.has(ee))}function qe(ee,re,ne){var we=$(re,ne,!1);if(!U(we))return we.get(ee)}function rt(ee,re,ne,we){var Ue=$(ne,we,!0);Ue.set(ee,re)}function ge(ee,re){var ne=[],we=$(ee,re,!1);if(U(we))return ne;for(var Ue=we.keys(),ze=cg(Ue),br=0;;){var pg=lg(ze);if(!pg)return ne.length=br,ne;var U_=ug(pg);try{ne[br]=U_}catch(M_){try{fg(ze)}finally{throw M_}}br++}}function J(ee,re,ne){var we=$(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 D_(b){var S=b.defineMetadata,k=b.hasOwnMetadata,$=b.getOwnMetadata,ce=b.getOwnMetadataKeys,qe=b.deleteMetadata,rt=new x,ge={isProviderFor:function(J,ee){var re=rt.get(J);return!U(re)&&re.has(ee)?!0:ce(J,ee).length?(U(re)&&(re=new m,rt.set(J,re)),re.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:k,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:ce,OrdinaryDeleteMetadata:qe};return ge}function ma(b,S,k){var $=d.getProvider(b,S);if(!U($))return $;if(k){if(d.setProvider(b,S,C))return C;throw new Error("Illegal state.")}}function j_(){var b={},S=[],k=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}(),$=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--,Lp(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 k(this._keys,this._values,ce)},ge.prototype.values=function(){return new k(this._keys,this._values,qe)},ge.prototype.entries=function(){return new k(this._keys,this._values,rt)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(J,ee){if(!Lp(this._cacheKey,J)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(Lp(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 $;function ce(ge,J){return ge}function qe(ge,J){return J}function rt(ge,J){return[ge,J]}}function R_(){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(k){return this._map.has(k)},S.prototype.add=function(k){return this._map.set(k,k),this},S.prototype.delete=function(k){return this._map.delete(k)},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 L_(){var b=16,S=f.create(),k=$();return function(){function J(){this._key=$()}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=$()},J}();function $(){var J;do J="@@WeakMap@@"+ge();while(f.has(S,J));return S[J]=!0,J}function ce(J,ee){if(!n.call(J,k)){if(!ee)return;Object.defineProperty(J,k,{value:f.create()})}return J[k]}function qe(J,ee){for(var re=0;re<ee;++re)J[re]=Math.random()*255|0;return J}function rt(J){if(typeof Uint8Array=="function"){var ee=new Uint8Array(J);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):qe(ee,J),ee}return qe(new Array(J),J)}function ge(){var J=rt(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 Mp(b){return b.__=void 0,delete b.__,b}})})(Eb||(Eb={}))});var _n=Kp(Cs=>{"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}},Fd="string",Y2=/^[0-9a-f\s]+$/i,J2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Q2=/^[a-zA-Z0-9-_]+$/,nf=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))}},cr=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}},of=class r{static isHex(e){return typeof e===Fd&&Y2.test(e)}static isBase64(e){return typeof e===Fd&&J2.test(e)}static isBase64Url(e){return typeof e===Fd&&Q2.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 cr.toString(n,!0);case"utf16":case"utf16be":return cr.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 cr.fromString(e,!0);case"utf16":case"utf16be":return cr.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 nf.fromString(e);case"utf16":case"utf16be":return cr.fromString(e);case"utf16le":case"usc2":return cr.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 nf.toString(e);case"utf16":case"utf16be":return cr.toString(e);case"utf16le":case"usc2":return cr.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 cr.toString(e,t)}static FromUtf16String(e,t=!1){return cr.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,"")||""}};of.DEFAULT_UTF8_ENCODING="utf8";function eC(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 tC(...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 rC(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}Cs.BufferSourceConverter=vn;Cs.Convert=of;Cs.assign=eC;Cs.combine=tC;Cs.isEqual=rC});var xv=Kp((h$,Qf)=>{var ev,tv,rv,nv,ov,iv,sv,av,cv,Jf,Yy,uv,lv,ra,fv,pv,hv,dv,yv,mv,gv,wv,bv;(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 Qf=="object"&&typeof Qf.exports=="object"?r(t(e,t(Qf.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])};ev=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},tv=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},rv=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},nv=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},ov=function(t,n){return function(o,i){n(o,i,t)}},iv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},sv=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())})},av=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}}},bv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},cv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Jf=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.")},Yy=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},uv=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Yy(arguments[n]));return t},lv=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},ra=function(t){return this instanceof ra?(this.v=t,this):new ra(t)},fv=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,C){a.push([x,v,d,C])>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 ra?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])}},pv=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:ra(t[s](c)),done:s==="return"}:a?a(c):c}:a}},hv=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 Jf=="function"?Jf(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)}},dv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},yv=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},mv=function(t){return t&&t.__esModule?t:{default:t}},gv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},wv=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",ev),r("__assign",tv),r("__rest",rv),r("__decorate",nv),r("__param",ov),r("__metadata",iv),r("__awaiter",sv),r("__generator",av),r("__exportStar",cv),r("__createBinding",bv),r("__values",Jf),r("__read",Yy),r("__spread",uv),r("__spreadArrays",lv),r("__await",ra),r("__asyncGenerator",fv),r("__asyncDelegator",pv),r("__asyncValues",hv),r("__makeTemplateObject",dv),r("__importStar",yv),r("__importDefault",mv),r("__classPrivateFieldGet",gv),r("__classPrivateFieldSet",wv)})});var iI={};_t(iI,{webRTC:()=>oI,webRTCDirect:()=>nI});var Hp=Symbol.for("@libp2p/peer-id");var Nu=Symbol.for("@libp2p/transport");var dg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(dg||(dg={}));var Du=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},ju=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Xi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ga=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Ru=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Lu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Oo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Po=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Uu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Mu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ku=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Hu=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Vu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var $n=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Fn=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 Zi=Symbol.for("@libp2p/service-capabilities"),yg=Symbol.for("@libp2p/service-dependencies");var Gp={};_t(Gp,{base58btc:()=>De,base58flickr:()=>J_});var kI=new Uint8Array(0);function mg(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 pn(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 gg(r){return new TextEncoder().encode(r)}function wg(r){return new TextDecoder().decode(r)}function G_(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,C=0,R=x.length;C!==R&&x[C]===0;)C++,v++;for(var D=(R-C)*f+1>>>0,Z=new Uint8Array(D);C!==R;){for(var P=x[C],q=0,M=D-1;(P!==0||q<d)&&M!==-1;M--,q++)P+=256*Z[M]>>>0,Z[M]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");d=q,C++}for(var K=D-d;K!==D&&Z[K]===0;)K++;for(var g=c.repeat(v);K<D;++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,C=0;x[v]===c;)d++,v++;for(var R=(x.length-v)*l+1>>>0,D=new Uint8Array(R);x[v];){var Z=t[x.charCodeAt(v)];if(Z===255)return;for(var P=0,q=R-1;(Z!==0||P<C)&&q!==-1;q--,P++)Z+=a*D[q]>>>0,D[q]=Z%256>>>0,Z=Z/256>>>0;if(Z!==0)throw new Error("Non-zero carry");C=P,v++}if(x[v]!==" "){for(var M=R-C;M!==R&&D[M]===0;)M++;for(var K=new Uint8Array(d+(R-M)),g=d;M!==R;)K[g++]=D[M++];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 q_=G_,z_=q_,xg=z_;var Vp=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")}},$p=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 vg(this,e)}},Fp=class{decoders;constructor(e){this.decoders=e}or(e){return vg(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 vg(r,e){return new Fp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Wp=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 Vp(e,t,n),this.decoder=new $p(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Yi({name:r,prefix:e,encode:t,decode:n}){return new Wp(r,e,t,n)}function Wn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=xg(t,r);return Yi({prefix:e,name:r,encode:n,decode:i=>pn(o(i))})}function X_(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 Z_(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 Y_(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function $e({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Y_(n);return Yi({prefix:e,name:r,encode(i){return Z_(i,n,t)},decode(i){return X_(i,o,t,r)}})}var De=Wn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),J_=Wn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qp={};_t(qp,{base32:()=>Gn,base32hex:()=>rS,base32hexpad:()=>oS,base32hexpadupper:()=>iS,base32hexupper:()=>nS,base32pad:()=>eS,base32padupper:()=>tS,base32upper:()=>Q_,base32z:()=>sS});var Gn=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Q_=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eS=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tS=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rS=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nS=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),oS=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),iS=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sS=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zp={};_t(zp,{base36:()=>wa,base36upper:()=>aS});var wa=Wn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),aS=Wn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xr={};_t(xr,{Digest:()=>Bo,create:()=>St,decode:()=>es,equals:()=>Zp,hasCode:()=>CS});var cS=Ag,_g=128,uS=127,lS=~uS,fS=Math.pow(2,31);function Ag(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fS;)e[t++]=r&255|_g,r/=128;for(;r&lS;)e[t++]=r&255|_g,r>>>=7;return e[t]=r|0,Ag.bytes=t-n+1,e}var pS=Xp,hS=128,Sg=127;function Xp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Xp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Sg)<<o:(s&Sg)*Math.pow(2,o),o+=7}while(s>=hS);return Xp.bytes=i-n,t}var dS=Math.pow(2,7),yS=Math.pow(2,14),mS=Math.pow(2,21),gS=Math.pow(2,28),wS=Math.pow(2,35),bS=Math.pow(2,42),xS=Math.pow(2,49),vS=Math.pow(2,56),_S=Math.pow(2,63),SS=function(r){return r<dS?1:r<yS?2:r<mS?3:r<gS?4:r<wS?5:r<bS?6:r<xS?7:r<vS?8:r<_S?9:10},AS={encode:cS,decode:pS,encodingLength:SS},ES=AS,ba=ES;function xa(r,e=0){return[ba.decode(r,e),ba.decode.bytes]}function Ji(r,e,t=0){return ba.encode(r,e,t),e}function Qi(r){return ba.encodingLength(r)}function St(r,e){let t=e.byteLength,n=Qi(r),o=n+Qi(t),i=new Uint8Array(o+t);return Ji(r,i,0),Ji(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function es(r){let e=pn(r),[t,n]=xa(e),[o,i]=xa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Zp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&mg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function CS(r,e){return r.code===e}function Eg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return IS(t,Yp(r),e??De.encoder);default:return OS(t,Yp(r),e??Gn.encoder)}}var Cg=new WeakMap;function Yp(r){let e=Cg.get(r);if(e==null){let t=new Map;return Cg.set(r,t),t}return e}var Xe=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!==PS)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=St(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&&Zp(e.multihash,n.multihash)}toString(e){return Eg(this,e)}toJSON(){return{"/":Eg(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??Tg(n,o,i.bytes))}else if(t[BS]===!0){let{version:n,multihash:o,code:i}=t,s=es(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=Tg(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=pn(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 Bo(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]=xa(e.subarray(t));return t+=y,p},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(),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]=TS(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 Yp(i).set(n,e),i}};function TS(r,e){switch(r[0]){case"Q":{let t=e??De;return[De.prefix,t.decode(`${De.prefix}${r}`)]}case De.prefix:{let t=e??De;return[De.prefix,t.decode(r)]}case Gn.prefix:{let t=e??Gn;return[Gn.prefix,t.decode(r)]}case wa.prefix:{let t=e??wa;return[wa.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 IS(r,e,t){let{prefix:n}=t;if(n!==De.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 OS(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,PS=18;function Tg(r,e,t){let n=Qi(r),o=n+Qi(e),i=new Uint8Array(o+t.byteLength);return Ji(r,i,0),Ji(e,i,n),i.set(t,o),i}var BS=Symbol.for("@ipld/js-cid/CID");var Jp={};_t(Jp,{identity:()=>vr});var Ig=0,kS="identity",Og=pn;function NS(r){return St(Ig,Og(r))}var vr={code:Ig,name:kS,encode:Og,digest:NS};function Fe(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 nt(r=0){return new Uint8Array(r)}function ot(r=0){return new Uint8Array(r)}function Pt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ot(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Bg=Symbol.for("@achingbrain/uint8arraylist");function Pg(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 Fu(r){return!!r?.[Bg]}var be=class r{bufs;length;[Bg]=!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(Fu(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(Fu(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=Pg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Pg(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(Fu(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 Pt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Pt(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(!Fu(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=ot(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=nt(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=nt(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=nt(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=ot(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=nt(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=nt(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=nt(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=nt(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=nt(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(!Fe(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 Qp={};_t(Qp,{base10:()=>jS});var jS=Wn({prefix:"9",name:"base10",alphabet:"0123456789"});var eh={};_t(eh,{base16:()=>RS,base16upper:()=>LS});var RS=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),LS=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var th={};_t(th,{base2:()=>US});var US=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rh={};_t(rh,{base256emoji:()=>$S});var kg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),MS=kg.reduce((r,e,t)=>(r[t]=e,r),[]),KS=kg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function HS(r){return r.reduce((e,t)=>(e+=MS[t],e),"")}function VS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=KS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var $S=Yi({prefix:"\u{1F680}",name:"base256emoji",encode:HS,decode:VS});var nh={};_t(nh,{base64:()=>FS,base64pad:()=>WS,base64url:()=>hn,base64urlpad:()=>GS});var FS=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),WS=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),hn=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),GS=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oh={};_t(oh,{base8:()=>qS});var qS=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ih={};_t(ih,{identity:()=>zS});var zS=Yi({prefix:"\0",name:"identity",encode:r=>wg(r),decode:r=>gg(r)});var dO=new TextEncoder,yO=new TextDecoder;var ch={};_t(ch,{sha256:()=>ir,sha512:()=>YS});function ah({name:r,code:e,encode:t}){return new sh(r,e,t)}var sh=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?St(this.code,t):t.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Dg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ir=ah({name:"sha2-256",code:18,encode:Dg("SHA-256")}),YS=ah({name:"sha2-512",code:19,encode:Dg("SHA-512")});var ko={...ih,...th,...oh,...Qp,...eh,...qp,...zp,...Gp,...nh,...rh},TO={...ch,...Jp};function Rg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var jg=Rg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uh=Rg("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=ot(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),JS={utf8:jg,"utf-8":jg,hex:ko.base16,latin1:uh,ascii:uh,binary:uh,...ko},Wu=JS;function pe(r,e="utf8"){let t=Wu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function le(r,e="utf8"){let t=Wu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var QS=parseInt("11111",2),lh=parseInt("10000000",2),eA=parseInt("01111111",2),Lg={0:_a,1:_a,2:tA,3:oA,4:iA,5:nA,6:rA,16:_a,22:_a,48:_a};function dn(r,e={offset:0}){let t=r[e.offset]&QS;if(e.offset++,Lg[t]!=null)return Lg[t](r,e);throw new Error("No decoder for tag "+t)}function Sa(r,e){let t=0;if((r[e.offset]&lh)===lh){let n=r[e.offset]&eA,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){Sa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=dn(r,e);if(n===null)break;t.push(n)}return t}function tA(r,e){let t=Sa(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 rA(r,e){let t=Sa(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 nA(r,e){return e.offset++,null}function oA(r,e){let t=Sa(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 iA(r,e){let t=Sa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function sA(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 Gu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=sA(r.byteLength);return new be(Uint8Array.from([e.byteLength|lh]),e)}function Bt(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]),Gu(e),e)}function Aa(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Gu(t),t)}function Ug(r){return new be(Uint8Array.from([4]),Gu(r),r)}function _r(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Gu(t),t)}async function Mg(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 Kg(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 Hg(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 aA=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),cA=Uint8Array.from([6,5,43,129,4,0,34]),uA=Uint8Array.from([6,5,43,129,4,0,35]),lA={ext:!0,kty:"EC",crv:"P-256"},fA={ext:!0,kty:"EC",crv:"P-384"},pA={ext:!0,kty:"EC",crv:"P-521"},fh=32,ph=48,hh=66;function dh(r){let e=dn(r);return Vg(e)}function Vg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===fh*2+1)return n=le(e.subarray(t,t+fh),"base64url"),o=le(e.subarray(t+fh),"base64url"),new No({...lA,key_ops:["verify"],x:n,y:o});if(e.byteLength===ph*2+1)return n=le(e.subarray(t,t+ph),"base64url"),o=le(e.subarray(t+ph),"base64url"),new No({...fA,key_ops:["verify"],x:n,y:o});if(e.byteLength===hh*2+1)return n=le(e.subarray(t,t+hh),"base64url"),o=le(e.subarray(t+hh),"base64url"),new No({...pA,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function $g(r){return _r([Bt(Uint8Array.from([1])),Ug(pe(r.d??"","base64url")),_r([Wg(r.crv)],160),_r([Aa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function Fg(r){return _r([Bt(Uint8Array.from([1])),_r([Wg(r.crv)],160),_r([Aa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function Wg(r){if(r==="P-256")return aA;if(r==="P-384")return cA;if(r==="P-521")return uA;throw new ve(`Invalid curve ${r}`)}async function Gg(r="P-256"){let e=await Mg(r);return new qu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Fg(this.jwk)),this._raw}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async verify(e,t,n){return Hg(this.jwk,t,e,n)}},qu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({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=$g(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async sign(e,t){return Kg(this.jwk,e,t)}};var Do=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function rs(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function jo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function At(r,...e){if(!rs(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 Ea(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");jo(r.outputLen),jo(r.blockLen)}function ns(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 zg(r,e){At(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Sr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function zu(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ar(r,e){return r<<32-e|r>>>e}var Xg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hA=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function $r(r){if(At(r),Xg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=hA[r[t]];return e}var yn={_0:48,_9:57,A:65,F:70,a:97,f:102};function qg(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 os(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Xg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=qg(r.charCodeAt(i)),a=qg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Zg(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function zn(r){return typeof r=="string"&&(r=Zg(r)),At(r),r}function Yt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];At(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 ts=class{};function yh(r){let e=n=>r().update(zn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ro(r=32){if(Do&&typeof Do.getRandomValues=="function")return Do.getRandomValues(new Uint8Array(r));if(Do&&typeof Do.randomBytes=="function")return Uint8Array.from(Do.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function dA(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 Yg(r,e,t){return r&e^~r&t}function Jg(r,e,t){return r&e^r&t^e&t}var Ca=class extends ts{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=zu(this.buffer)}update(e){ns(this),e=zn(e),At(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=zu(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){ns(this),zg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Sr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;dA(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=zu(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 lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Xu=BigInt(4294967295),Qg=BigInt(32);function yA(r,e=!1){return e?{h:Number(r&Xu),l:Number(r>>Qg&Xu)}:{h:Number(r>>Qg&Xu)|0,l:Number(r&Xu)|0}}function e0(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}=yA(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var mh=(r,e,t)=>r>>>t,gh=(r,e,t)=>r<<32-t|e>>>t,Lo=(r,e,t)=>r>>>t|e<<32-t,Uo=(r,e,t)=>r<<32-t|e>>>t,Ta=(r,e,t)=>r<<64-t|e>>>t-32,Ia=(r,e,t)=>r>>>t-32|e<<64-t;function Fr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var t0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),r0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,n0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),o0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,i0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),s0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var gA=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]),Xn=new Uint32Array(64),Zu=class extends Ca{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)Xn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let y=Xn[p-15],m=Xn[p-2],x=Ar(y,7)^Ar(y,18)^y>>>3,v=Ar(m,17)^Ar(m,19)^m>>>10;Xn[p]=v+Xn[p-7]+x+Xn[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=Ar(a,6)^Ar(a,11)^Ar(a,25),m=f+y+Yg(a,c,l)+gA[p]+Xn[p]|0,v=(Ar(n,2)^Ar(n,13)^Ar(n,22))+Jg(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(){Sr(Xn)}destroy(){this.set(0,0,0,0,0,0,0,0),Sr(this.buffer)}};var a0=e0(["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))),wA=a0[0],bA=a0[1],Zn=new Uint32Array(80),Yn=new Uint32Array(80),wh=class extends Ca{constructor(e=64){super(128,e,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[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 D=0;D<16;D++,t+=4)Zn[D]=e.getUint32(t),Yn[D]=e.getUint32(t+=4);for(let D=16;D<80;D++){let Z=Zn[D-15]|0,P=Yn[D-15]|0,q=Lo(Z,P,1)^Lo(Z,P,8)^mh(Z,P,7),M=Uo(Z,P,1)^Uo(Z,P,8)^gh(Z,P,7),K=Zn[D-2]|0,g=Yn[D-2]|0,I=Lo(K,g,19)^Ta(K,g,61)^mh(K,g,6),E=Uo(K,g,19)^Ia(K,g,61)^gh(K,g,6),O=n0(M,E,Yn[D-7],Yn[D-16]),B=o0(O,q,I,Zn[D-7],Zn[D-16]);Zn[D]=B|0,Yn[D]=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:C,Hl:R}=this;for(let D=0;D<80;D++){let Z=Lo(p,y,14)^Lo(p,y,18)^Ta(p,y,41),P=Uo(p,y,14)^Uo(p,y,18)^Ia(p,y,41),q=p&m^~p&v,M=y&x^~y&d,K=i0(R,P,M,bA[D],Yn[D]),g=s0(K,C,Z,q,wA[D],Zn[D]),I=K|0,E=Lo(n,o,28)^Ta(n,o,34)^Ta(n,o,39),O=Uo(n,o,28)^Ia(n,o,34)^Ia(n,o,39),B=n&i^n&a^i&a,j=o&s^o&c^s&c;C=v|0,R=d|0,v=m|0,d=x|0,m=p|0,x=y|0,{h:p,l:y}=Fr(l|0,f|0,g|0,I|0),l=a|0,f=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let N=t0(I,O,j);n=r0(N,g,E,B),o=N|0}({h:n,l:o}=Fr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Fr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Fr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=Fr(this.Dh|0,this.Dl|0,l|0,f|0),{h:p,l:y}=Fr(this.Eh|0,this.El|0,p|0,y|0),{h:m,l:x}=Fr(this.Fh|0,this.Fl|0,m|0,x|0),{h:v,l:d}=Fr(this.Gh|0,this.Gl|0,v|0,d|0),{h:C,l:R}=Fr(this.Hh|0,this.Hl|0,C|0,R|0),this.set(n,o,i,s,a,c,l,f,p,y,m,x,v,d,C,R)}roundClean(){Sr(Zn,Yn)}destroy(){Sr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Yu=yh(()=>new Zu);var c0=yh(()=>new wh);var vh=BigInt(0),xh=BigInt(1);function gn(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Oa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function u0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?vh:BigInt("0x"+r)}function is(r){return u0($r(r))}function Wr(r){return At(r),u0($r(Uint8Array.from(r).reverse()))}function Ju(r,e){return os(r.toString(16).padStart(e*2,"0"))}function Jn(r,e){return Ju(r,e).reverse()}function ke(r,e,t){let n;if(typeof e=="string")try{n=os(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(rs(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 bh=r=>typeof r=="bigint"&&vh<=r;function l0(r,e,t){return bh(r)&&bh(e)&&bh(t)&&e<=r&&r<t}function Er(r,e,t,n){if(!l0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function f0(r){let e;for(e=0;r>vh;r>>=xh,e+=1);return e}var Mo=r=>(xh<<BigInt(r))-xh;function p0(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 Yt(...x)};return(m,x)=>{c(),f(m);let v;for(;!(v=x(p()));)f();return c(),v}}function Gr(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 kt=BigInt(0),at=BigInt(1),Ko=BigInt(2),xA=BigInt(3),y0=BigInt(4),m0=BigInt(5),g0=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 h0(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=at,s=at,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!==at)throw new Error("invert: does not exist");return je(o,e)}function w0(r,e){let t=(r.ORDER+at)/y0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function vA(r,e){let t=(r.ORDER-m0)/g0,n=r.mul(e,Ko),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Ko),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 _A(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Ko===kt;)e/=Ko,t++;let n=Ko,o=Cr(r);for(;d0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return w0;let i=o.pow(n,e),s=(e+at)/Ko;return function(c,l){if(c.is0(l))return l;if(d0(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=at<<BigInt(f-x-1),C=c.pow(p,d);f=x,p=c.sqr(C),y=c.mul(y,p),m=c.mul(m,C)}return m}}function SA(r){return r%y0===xA?w0:r%g0===m0?vA:_A(r)}var b0=(r,e)=>(je(r,e)&at)===at,AA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _h(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=AA.reduce((n,o)=>(n[o]="function",n),e);return Gr(r,t),r}function EA(r,e,t){if(t<kt)throw new Error("invalid exponent, negatives unsupported");if(t===kt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>kt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function Pa(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 d0(r,e){let t=(r.ORDER-at)/Ko,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&&jo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Cr(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}=x0(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:Mo(s),ZERO:kt,ONE:at,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&at)===at,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)=>EA(l,f,p),div:(f,p)=>je(f*h0(p,r),r),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>h0(f,r),sqrt:i||(f=>(c||(c=SA(r)),c(l,f))),toBytes:f=>t?Jn(f,a):Ju(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return t?Wr(f):is(f)},invertBatch:f=>Pa(l,f),cmov:(f,p,y)=>y?p:f});return Object.freeze(l)}function v0(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 Sh(r){let e=v0(r);return e+Math.ceil(e/2)}function _0(r,e,t=!1){let n=r.length,o=v0(e),i=Sh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Wr(r):is(r),a=je(s,e-at)+at;return t?Jn(a,o):Ju(a,o)}var cs=BigInt(0),Ho=BigInt(1);function as(r,e){let t=e.negate();return r?t:e}function Qu(r,e,t){let n=e==="pz"?s=>s.pz:s=>s.ez,o=Pa(r.Fp,t.map(n));return t.map((s,a)=>s.toAffine(o[a])).map(r.fromAffine)}function C0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Ah(r,e){C0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Mo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function S0(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+=Ho);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 CA(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 TA(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 Eh=new WeakMap,T0=new WeakMap;function Ch(r){return T0.get(r)||1}function A0(r){if(r!==cs)throw new Error("invalid wNAF")}function el(r,e){return{constTimeNegate:as,hasPrecomputes(t){return Ch(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>cs;)n&Ho&&(o=o.add(i)),i=i.double(),n>>=Ho;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=Ah(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=Ah(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:f,isZero:p,isNeg:y,isNegF:m,offsetF:x}=S0(o,c,a);o=l,p?s=s.add(as(m,n[x])):i=i.add(as(y,n[f]))}return A0(o),{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=Ah(t,e);for(let a=0;a<s.windows&&o!==cs;a++){let{nextN:c,offset:l,isZero:f,isNeg:p}=S0(o,a,s);if(o=c,!f){let y=n[l];i=i.add(p?y.negate():y)}}return A0(o),i},getPrecomputes(t,n,o){let i=Eh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof o=="function"&&(i=o(i)),Eh.set(n,i))),i},wNAFCached(t,n,o){let i=Ch(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=Ch(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){C0(n,e),T0.set(t,n),Eh.delete(t)}}}function I0(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>cs||n>cs;)t&Ho&&(i=i.add(o)),n&Ho&&(s=s.add(o)),o=o.double(),t>>=Ho,n>>=Ho;return{p1:i,p2:s}}function tl(r,e,t,n){CA(t,r),TA(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=f0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Mo(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],C=Number(d>>BigInt(m)&l);f[C]=f[C].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 E0(r,e){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _h(e),e}else return Cr(r)}function rl(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>cs))throw new Error(`CURVE.${a} must be positive bigint`)}let n=E0(e.p,t.Fp),o=E0(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 qr=BigInt(0),Nt=BigInt(1),Th=BigInt(2),IA=BigInt(8),OA={zip215:!0};function PA(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 BA(r,e={}){let{Fp:t,Fn:n}=rl("edwards",r,e),{h:o,n:i}=r;Gr(e,{},{uvRatio:"function"});let s=Th<<BigInt(n.BYTES*8)-Nt,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:qr}}});if(!PA(t,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(v,d,C=!1){let R=C?Nt:qr;return Er("coordinate "+v,d,R,s),d}function f(v){if(!(v instanceof m))throw new Error("ExtendedPoint expected")}let p=ss((v,d)=>{let{ex:C,ey:R,ez:D}=v,Z=v.is0();d==null&&(d=Z?IA:t.inv(D));let P=a(C*d),q=a(R*d),M=a(D*d);if(Z)return{x:qr,y:Nt};if(M!==Nt)throw new Error("invZ was invalid");return{x:P,y:q}}),y=ss(v=>{let{a:d,d:C}=r;if(v.is0())throw new Error("bad point: ZERO");let{ex:R,ey:D,ez:Z,et:P}=v,q=a(R*R),M=a(D*D),K=a(Z*Z),g=a(K*K),I=a(q*d),E=a(K*a(I+M)),O=a(g+a(C*a(q*M)));if(E!==O)throw new Error("bad point: equation left != right (1)");let B=a(R*D),j=a(Z*P);if(B!==j)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,C,R,D){this.ex=l("x",d),this.ey=l("y",C),this.ez=l("z",R,!0),this.et=l("t",D),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:C,y:R}=d||{};return l("x",C),l("y",R),new m(C,R,Nt,a(C*R))}static normalizeZ(d){return Qu(m,"ez",d)}static msm(d,C){return tl(m,n,d,C)}_setWindowSize(d){this.precompute(d)}precompute(d=8,C=!0){return x.setWindowSize(this,d),C||this.multiply(Th),this}assertValidity(){y(this)}equals(d){f(d);let{ex:C,ey:R,ez:D}=this,{ex:Z,ey:P,ez:q}=d,M=a(C*q),K=a(Z*D),g=a(R*q),I=a(P*D);return M===K&&g===I}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:C,ey:R,ez:D}=this,Z=a(C*C),P=a(R*R),q=a(Th*a(D*D)),M=a(d*Z),K=C+R,g=a(a(K*K)-Z-P),I=M+P,E=I-q,O=M-P,B=a(g*E),j=a(I*O),N=a(g*O),L=a(E*I);return new m(B,j,L,N)}add(d){f(d);let{a:C,d:R}=r,{ex:D,ey:Z,ez:P,et:q}=this,{ex:M,ey:K,ez:g,et:I}=d,E=a(D*M),O=a(Z*K),B=a(q*R*I),j=a(P*g),N=a((D+Z)*(M+K)-E-O),L=j-B,F=j+B,X=a(O-C*E),W=a(N*L),ie=a(F*X),Y=a(N*X),U=a(L*F);return new m(W,ie,U,Y)}subtract(d){return this.add(d.negate())}multiply(d){let C=d;Er("scalar",C,Nt,i);let{p:R,f:D}=x.wNAFCached(this,C,m.normalizeZ);return m.normalizeZ([R,D])[0]}multiplyUnsafe(d,C=m.ZERO){let R=d;return Er("scalar",R,qr,i),R===qr?m.ZERO:this.is0()||R===Nt?this:x.wNAFCachedUnsafe(this,R,m.normalizeZ,C)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return x.wNAFCachedUnsafe(this,i).is0()}toAffine(d){return p(this,d)}clearCofactor(){return o===Nt?this:this.multiplyUnsafe(o)}static fromBytes(d,C=!1){return At(d),this.fromHex(d,C)}static fromHex(d,C=!1){let{d:R,a:D}=r,Z=t.BYTES;d=ke("pointHex",d,Z),gn("zip215",C);let P=d.slice(),q=d[Z-1];P[Z-1]=q&-129;let M=Wr(P),K=C?s:t.ORDER;Er("pointHex.y",M,qr,K);let g=a(M*M),I=a(g-Nt),E=a(R*g-D),{isValid:O,value:B}=c(I,E);if(!O)throw new Error("Point.fromHex: invalid y coordinate");let j=(B&Nt)===Nt,N=(q&128)!==0;if(!C&&B===qr&&N)throw new Error("Point.fromHex: x=0 and x_0=1");return N!==j&&(B=a(-B)),m.fromAffine({x:B,y:M})}static fromPrivateScalar(d){return m.BASE.multiply(d)}toBytes(){let{x:d,y:C}=this.toAffine(),R=Jn(C,t.BYTES);return R[R.length-1]|=d&Nt?128:0,R}toRawBytes(){return this.toBytes()}toHex(){return $r(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,Nt,a(r.Gx*r.Gy)),m.ZERO=new m(qr,Nt,Nt,qr),m.Fp=t,m.Fn=n;let x=el(m,n.BYTES*8);return m}function kA(r,e){Gr(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||Ro,l=e.adjustScalarBytes||(P=>P),f=e.domain||((P,q,M)=>{if(gn("phflag",M),q.length||M)throw new Error("Contexts/pre-hash are not supported");return P});function p(P){return s.create(P)}function y(P){return p(Wr(P))}function m(P){let q=i.BYTES;P=ke("private key",P,q);let M=ke("hashed private key",n(P),2*q),K=l(M.slice(0,q)),g=M.slice(q,2*q),I=y(K);return{head:K,prefix:g,scalar:I}}function x(P){let{head:q,prefix:M,scalar:K}=m(P),g=o.multiply(K),I=g.toBytes();return{head:q,prefix:M,scalar:K,point:g,pointBytes:I}}function v(P){return x(P).pointBytes}function d(P=Uint8Array.of(),...q){let M=Yt(...q);return y(n(f(M,ke("context",P),!!t)))}function C(P,q,M={}){P=ke("message",P),t&&(P=t(P));let{prefix:K,scalar:g,pointBytes:I}=x(q),E=d(M.context,K,P),O=o.multiply(E).toBytes(),B=d(M.context,O,I,P),j=p(E+B*g);Er("signature.s",j,qr,a);let N=i.BYTES,L=Yt(O,Jn(j,N));return ke("result",L,N*2)}let R=OA;function D(P,q,M,K=R){let{context:g,zip215:I}=K,E=i.BYTES;P=ke("signature",P,2*E),q=ke("message",q),M=ke("publicKey",M,E),I!==void 0&&gn("zip215",I),t&&(q=t(q));let O=Wr(P.slice(E,2*E)),B,j,N;try{B=r.fromHex(M,I),j=r.fromHex(P.slice(0,E),I),N=o.multiplyUnsafe(O)}catch{return!1}if(!I&&B.isSmallOrder())return!1;let L=d(g,j.toBytes(),B.toBytes(),q);return j.add(B.multiplyUnsafe(L)).subtract(N).clearCofactor().is0()}return o.precompute(8),{getPublicKey:v,sign:C,verify:D,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>c(i.BYTES),precompute(P=8,q=r.BASE){return q.precompute(P,!1)}},Point:r}}function NA(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=Cr(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 DA(r,e){return Object.assign({},e,{ExtendedPoint:e.Point,CURVE:r})}function O0(r){let{CURVE:e,curveOpts:t,eddsaOpts:n}=NA(r),o=BA(e,t),i=kA(o,n);return DA(r,i)}var Ba=BigInt(0),us=BigInt(1),nl=BigInt(2);function jA(r){return Gr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function P0(r){let e=jA(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||Ro,l=a?255:448,f=a?32:56,p=BigInt(a?9:5),y=BigInt(a?121665:39081),m=a?nl**BigInt(254):nl**BigInt(447),x=a?BigInt(8)*nl**BigInt(251)-us:BigInt(4)*nl**BigInt(445)-us,v=m+x+us,d=g=>je(g,t),C=R(p);function R(g){return Jn(d(g),f)}function D(g){let I=ke("u coordinate",g,f);return a&&(I[31]&=127),d(Wr(I))}function Z(g){return Wr(o(ke("scalar",g,f)))}function P(g,I){let E=K(D(I),Z(g));if(E===Ba)throw new Error("invalid private or public key received");return R(E)}function q(g){return P(g,C)}function M(g,I,E){let O=d(g*(I-E));return I=d(I-O),E=d(E+O),{x_2:I,x_3:E}}function K(g,I){Er("u",g,Ba,t),Er("scalar",I,m,v);let E=I,O=g,B=us,j=Ba,N=g,L=us,F=Ba;for(let W=BigInt(l-1);W>=Ba;W--){let ie=E>>W&us;F^=ie,{x_2:B,x_3:N}=M(F,B,N),{x_2:j,x_3:L}=M(F,j,L),F=ie;let Y=B+j,U=d(Y*Y),he=B-j,Oe=d(he*he),se=U-Oe,Ne=N+L,vt=N-L,et=d(vt*Y),tt=d(Ne*he),ut=et+tt,or=et-tt;N=d(ut*ut),L=d(O*d(or*or)),B=d(U*Oe),j=d(se*(U+d(y*se)))}({x_2:B,x_3:N}=M(F,B,N)),{x_2:j,x_3:L}=M(F,j,L);let X=i(j);return d(B*X)}return{scalarMult:P,scalarMultBase:q,getSharedSecret:(g,I)=>P(g,I),getPublicKey:g=>q(g),utils:{randomPrivateKey:()=>c(f)},GuBytes:C.slice()}}var NP=BigInt(0),RA=BigInt(1),B0=BigInt(2),LA=BigInt(3),UA=BigInt(5),MA=BigInt(8),ka={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:MA,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function N0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=ka.p,a=r*r%i*r%i,c=Me(a,B0,i)*a%i,l=Me(c,RA,i)*r%i,f=Me(l,UA,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,B0,i)*r%i,b2:a}}function D0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var k0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function KA(r,e){let t=ka.p,n=je(e*e*e,t),o=je(n*n*e,t),i=N0(r*o).pow_p_5_8,s=je(r*n*i,t),a=je(e*s*s,t),c=s,l=je(s*k0,t),f=a===r,p=a===je(-r,t),y=a===je(-r*k0,t);return f&&(s=c),(p||y)&&(s=l),b0(s,t)&&(s=je(-s,t)),{isValid:f||p,value:s}}var HA=Cr(ka.p,void 0,!0),VA={...ka,Fp:HA,hash:c0,adjustScalarBytes:D0,uvRatio:KA},Na=O0(VA);var Da=(()=>{let r=ka.p;return P0({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=N0(e);return je(Me(t,LA,r)*n,r)},adjustScalarBytes:D0})})();var ja=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ra=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},ol=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var j0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new ol("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 Lt=j0;var il=32,La=64,Ih=32;var ls,R0=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function L0(){let r=Na.utils.randomPrivateKey(),e=Na.getPublicKey(r);return{privateKey:qA(r,e),publicKey:e}}async function $A(r,e){let t;r.length===La?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 Lt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Lt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function FA(r,e){let t=r.subarray(0,Ih);return Na.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function U0(r,e){return ls==null&&(ls=await R0),ls?$A(r,e):FA(r,e)}async function WA(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.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 GA(r,e,t){return Na.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function M0(r,e,t){return ls==null&&(ls=await R0),ls?WA(r,e,t):GA(r,e,t)}function qA(r,e){let t=new Uint8Array(La);for(let n=0;n<Ih;n++)t[n]=r[n],t[Ih+n]=e[n];return t}function fs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Ua=class{type="Ed25519";raw;constructor(e){this.raw=al(e,il)}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=M0(this.raw,t,e);return fs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},sl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=al(e,La),this.publicKey=new Ua(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=U0(this.raw,e);return fs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Oh(r){return r=al(r,il),new Ua(r)}async function H0(){let{privateKey:r,publicKey:e}=L0();return new sl(r,e)}function al(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var zA=Math.pow(2,7),XA=Math.pow(2,14),ZA=Math.pow(2,21),Ph=Math.pow(2,28),Bh=Math.pow(2,35),kh=Math.pow(2,42),Nh=Math.pow(2,49),Te=128,Et=127;function He(r){if(r<zA)return 1;if(r<XA)return 2;if(r<ZA)return 3;if(r<Ph)return 4;if(r<Bh)return 5;if(r<kh)return 6;if(r<Nh)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(He(r)){case 8:e[t++]=r&255|Te,r/=128;case 7:e[t++]=r&255|Te,r/=128;case 6:e[t++]=r&255|Te,r/=128;case 5:e[t++]=r&255|Te,r/=128;case 4:e[t++]=r&255|Te,r>>>=7;case 3:e[t++]=r&255|Te,r>>>=7;case 2:e[t++]=r&255|Te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function YA(r,e,t=0){switch(He(r)){case 8:e.set(t++,r&255|Te),r/=128;case 7:e.set(t++,r&255|Te),r/=128;case 6:e.set(t++,r&255|Te),r/=128;case 5:e.set(t++,r&255|Te),r/=128;case 4:e.set(t++,r&255|Te),r>>>=7;case 3:e.set(t++,r&255|Te),r>>>=7;case 2:e.set(t++,r&255|Te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Dh(r,e){let t=r[e],n=0;if(n+=t&Et,t<Te||(t=r[e+1],n+=(t&Et)<<7,t<Te)||(t=r[e+2],n+=(t&Et)<<14,t<Te)||(t=r[e+3],n+=(t&Et)<<21,t<Te)||(t=r[e+4],n+=(t&Et)*Ph,t<Te)||(t=r[e+5],n+=(t&Et)*Bh,t<Te)||(t=r[e+6],n+=(t&Et)*kh,t<Te)||(t=r[e+7],n+=(t&Et)*Nh,t<Te))return n;throw new RangeError("Could not decode varint")}function JA(r,e){let t=r.get(e),n=0;if(n+=t&Et,t<Te||(t=r.get(e+1),n+=(t&Et)<<7,t<Te)||(t=r.get(e+2),n+=(t&Et)<<14,t<Te)||(t=r.get(e+3),n+=(t&Et)<<21,t<Te)||(t=r.get(e+4),n+=(t&Et)*Ph,t<Te)||(t=r.get(e+5),n+=(t&Et)*Bh,t<Te)||(t=r.get(e+6),n+=(t&Et)*kh,t<Te)||(t=r.get(e+7),n+=(t&Et)*Nh,t<Te))return n;throw new RangeError("Could not decode varint")}function cl(r,e,t=0){return e==null&&(e=ot(He(r))),e instanceof Uint8Array?ps(r,e,t):YA(r,e,t)}function Vo(r,e=0){return r instanceof Uint8Array?Dh(r,e):JA(r,e)}var jh=new Float32Array([-0]),Qn=new Uint8Array(jh.buffer);function V0(r,e,t){jh[0]=r,e[t]=Qn[0],e[t+1]=Qn[1],e[t+2]=Qn[2],e[t+3]=Qn[3]}function $0(r,e){return Qn[0]=r[e],Qn[1]=r[e+1],Qn[2]=r[e+2],Qn[3]=r[e+3],jh[0]}var Rh=new Float64Array([-0]),Ct=new Uint8Array(Rh.buffer);function F0(r,e,t){Rh[0]=r,e[t]=Ct[0],e[t+1]=Ct[1],e[t+2]=Ct[2],e[t+3]=Ct[3],e[t+4]=Ct[4],e[t+5]=Ct[5],e[t+6]=Ct[6],e[t+7]=Ct[7]}function W0(r,e){return Ct[0]=r[e],Ct[1]=r[e+1],Ct[2]=r[e+2],Ct[3]=r[e+3],Ct[4]=r[e+4],Ct[5]=r[e+5],Ct[6]=r[e+6],Ct[7]=r[e+7],Rh[0]}var QA=BigInt(Number.MAX_SAFE_INTEGER),eE=BigInt(Number.MIN_SAFE_INTEGER),Jt=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 $o;if(e<QA&&e>eE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>G0&&(o=0n,++n>G0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return $o;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):$o}},$o=new Jt(0,0);$o.toBigInt=function(){return 0n};$o.zzEncode=$o.zzDecode=function(){return this};$o.length=function(){return 1};var G0=4294967296n;function q0(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 z0(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 Lh(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 Tr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ll(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Uh=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,Tr(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 Tr(this,4);return ll(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tr(this,4);return ll(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tr(this,4);let e=$0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Tr(this,4);let e=W0(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 Tr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return z0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Tr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Tr(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 Jt(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 Tr(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 Tr(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 Tr(this,8);let e=ll(this.buf,this.pos+=4),t=ll(this.buf,this.pos+=4);return new Jt(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=Dh(this.buf,this.pos);return this.pos+=He(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 Mh(r){return new Uh(r instanceof Uint8Array?r:r.subarray())}function Ir(r,e,t){let n=Mh(r);return e.decode(n,void 0,t)}function Kh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ot(s);o+s>e&&(n=ot(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Fo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Hh(){}var $h=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},tE=Kh();function rE(r){return globalThis.Buffer!=null?ot(r):tE(r)}var Ka=class{len;head;tail;states;constructor(){this.len=0,this.head=new Fo(Hh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Fo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(fl,10,Jt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Jt.fromBigInt(e);return this._push(fl,t.length(),t)}uint64Number(e){return this._push(ps,He(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=Jt.fromBigInt(e).zzEncode();return this._push(fl,t.length(),t)}sint64Number(e){let t=Jt.fromNumber(e).zzEncode();return this._push(fl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vh,1,e?1:0)}fixed32(e){return this._push(Ma,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Jt.fromBigInt(e);return this._push(Ma,4,t.lo)._push(Ma,4,t.hi)}fixed64Number(e){let t=Jt.fromNumber(e);return this._push(Ma,4,t.lo)._push(Ma,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(V0,4,e)}double(e){return this._push(F0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Vh,1,0):this.uint32(t)._push(oE,t,e)}string(e){let t=q0(e);return t!==0?this.uint32(t)._push(Lh,t,e):this._push(Vh,1,0)}fork(){return this.states=new $h(this),this.head=this.tail=new Fo(Hh,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 Fo(Hh,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=rE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Vh(r,e,t){e[t]=r&255}function nE(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Fh=class extends Fo{next;constructor(e,t){super(nE,e,t),this.next=void 0}};function fl(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Ma(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 oE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Ka.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(iE,e,r),this},Ka.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sE,e,r),this});function iE(r,e,t){e.set(r,t)}function sE(r,e,t){r.length<40?Lh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(pe(r),t)}function Wh(){return new Ka}function Or(r,e){let t=Wh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var hs;(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"})(hs||(hs={}));function pl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Wo(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 pl("enum",hs.VARINT,t,n)}function Pr(r,e){return pl("message",hs.LENGTH_DELIMITED,r,e)}var Ha=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ze;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ze||(Ze={}));var Gh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Gh||(Gh={}));(function(r){r.codec=()=>Wo(Gh)})(Ze||(Ze={}));var zr;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ze.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=Ze.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(zr||(zr={}));var qh;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ze.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=Ze.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(qh||(qh={}));var $a={};_t($a,{MAX_RSA_KEY_SIZE:()=>zh,generateRSAKeyPair:()=>nd,jwkToJWKKeyPair:()=>ew,jwkToPkcs1:()=>lE,jwkToPkix:()=>Jh,jwkToRSAPrivateKey:()=>rd,pkcs1MessageToJwk:()=>Zh,pkcs1MessageToRSAPrivateKey:()=>Qh,pkcs1ToJwk:()=>uE,pkcs1ToRSAPrivateKey:()=>Q0,pkixMessageToJwk:()=>Yh,pkixMessageToRSAPublicKey:()=>td,pkixToJwk:()=>fE,pkixToRSAPublicKey:()=>ed});var eo=Yu;var ds=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=$a.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Xe.createV1(114,this._multihash)}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return J0(this.jwk,t,e,n)}},Va=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=$a.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return Y0(this.jwk,e,t)}};var zh=8192,Xh=18,aE=1062,cE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function uE(r){let e=dn(r);return Zh(e)}function Zh(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 lE(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return _r([Bt(Uint8Array.from([0])),Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url")),Bt(pe(r.d,"base64url")),Bt(pe(r.p,"base64url")),Bt(pe(r.q,"base64url")),Bt(pe(r.dp,"base64url")),Bt(pe(r.dq,"base64url")),Bt(pe(r.qi,"base64url"))]).subarray()}function fE(r){let e=dn(r,{offset:0});return Yh(e)}function Yh(r){let e=dn(r[1],{offset:0});return{kty:"RSA",n:le(e[0],"base64url"),e:le(e[1],"base64url")}}function Jh(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return _r([cE,Aa(_r([Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url"))]))]).subarray()}function Q0(r){let e=dn(r);return Qh(e)}function Qh(r){let e=Zh(r);return rd(e)}function ed(r,e){if(r.byteLength>=aE)throw new Xi("Key size is too large");let t=dn(r,{offset:0});return td(t,r,e)}function td(r,e,t){let n=Yh(r);if(t==null){let o=eo(zr.encode({Type:Ze.RSA,Data:e}));t=St(Xh,o)}return new ds(n,t)}function rd(r){if(rw(r)>zh)throw new ve("Key size is too large");let e=ew(r),t=eo(zr.encode({Type:Ze.RSA,Data:Jh(e.publicKey)})),n=St(Xh,t);return new Va(e.privateKey,new ds(e.publicKey,n))}async function nd(r){if(r>zh)throw new ve("Key size is too large");let e=await tw(r),t=eo(zr.encode({Type:Ze.RSA,Data:Jh(e.publicKey)})),n=St(Xh,t);return new Va(e.privateKey,new ds(e.publicKey,n))}function ew(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function tw(r,e){let t=await Lt.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 pE(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Y0(r,e,t){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Lt.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 J0(r,e,t,n){let o=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function pE(r,e){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");let t=await Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function rw(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return pe(r.n,"base64url").length*8}var hl=class extends ts{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ea(e);let n=zn(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),Sr(i)}update(e){return ns(this),this.iHash.update(e),this}digestInto(e){ns(this),At(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()}},ys=(r,e,t)=>new hl(r,e).update(t).digest();ys.create=(r,e)=>new hl(r,e);function nw(r){r.lowS!==void 0&&gn("lowS",r.lowS),r.prehash!==void 0&&gn("prehash",r.prehash)}var od=class extends Error{constructor(e=""){super(e)}},wn={Err:od,_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=Oa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Oa(o.length/2|128):"";return Oa(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<Fa)throw new e("integer: negative integers are not allowed");let t=Oa(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 is(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=wn,o=ke("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)}},Fa=BigInt(0),Wa=BigInt(1),hE=BigInt(2),dl=BigInt(3),dE=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 ow(r,e,t){let{BYTES:n}=r;function o(i){let s;if(typeof i=="bigint")s=i;else{let a=ke("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 mE(r,e={}){let{Fp:t,Fn:n}=rl("weierstrass",r,e),{h:o,n:i}=r;Gr(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,I){let{x:E,y:O}=g.toAffine(),B=t.toBytes(E);if(gn("isCompressed",I),I){a();let j=!t.isOdd(O);return Yt(iw(j),B)}else return Yt(Uint8Array.of(4),B,t.toBytes(O))}function l(K){At(K);let g=t.BYTES,I=g+1,E=2*g+1,O=K.length,B=K[0],j=K.subarray(1);if(O===I&&(B===2||B===3)){let N=t.fromBytes(j);if(!t.isValid(N))throw new Error("bad point: is not on curve, wrong x");let L=y(N),F;try{F=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(F);return(B&1)===1!==X&&(F=t.neg(F)),{x:N,y:F}}else if(O===E&&B===4){let N=t.fromBytes(j.subarray(g*0,g*1)),L=t.fromBytes(j.subarray(g*1,g*2));if(!m(N,L))throw new Error("bad point: is not on curve");return{x:N,y:L}}else throw new Error(`bad point: got length ${O}, expected compressed=${I} or uncompressed=${E}`)}let f=e.toBytes||c,p=e.fromBytes||l,y=yE(t,r.a,r.b);function m(K,g){let I=t.sqr(g),E=y(K);return t.eql(I,E)}if(!m(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let x=t.mul(t.pow(r.a,dl),dE),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,I=!1){if(!t.isValid(g)||I&&t.is0(g))throw new Error(`bad point coordinate ${K}`);return g}function C(K){if(!(K instanceof P))throw new Error("ProjectivePoint expected")}let R=ss((K,g)=>{let{px:I,py:E,pz:O}=K;if(t.eql(O,t.ONE))return{x:I,y:E};let B=K.is0();g==null&&(g=B?t.ONE:t.inv(O));let j=t.mul(I,g),N=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:j,y:N}}),D=ss(K=>{if(K.is0()){if(e.allowInfinityPoint&&!t.is0(K.py))return;throw new Error("bad point: ZERO")}let{x:g,y:I}=K.toAffine();if(!t.isValid(g)||!t.isValid(I))throw new Error("bad point: x or y not field elements");if(!m(g,I))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,I,E,O){return I=new P(t.mul(I.px,K),I.py,I.pz),g=as(E,g),I=as(O,I),g.add(I)}class P{constructor(g,I,E){this.px=d("x",g),this.py=d("y",I,!0),this.pz=d("z",E),Object.freeze(this)}static fromAffine(g){let{x:I,y:E}=g||{};if(!g||!t.isValid(I)||!t.isValid(E))throw new Error("invalid affine point");if(g instanceof P)throw new Error("projective point not allowed");return t.is0(I)&&t.is0(E)?P.ZERO:new P(I,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){return Qu(P,"pz",g)}static fromBytes(g){return At(g),P.fromHex(g)}static fromHex(g){let I=P.fromAffine(p(ke("pointHex",g)));return I.assertValidity(),I}static fromPrivateKey(g){let I=ow(n,e.allowedPrivateKeyLengths,e.wrapPrivateKey);return P.BASE.multiply(I(g))}static msm(g,I){return tl(P,n,g,I)}precompute(g=8,I=!0){return M.setWindowSize(this,g),I||this.multiply(dl),this}_setWindowSize(g){this.precompute(g)}assertValidity(){D(this)}hasEvenY(){let{y:g}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(g)}equals(g){C(g);let{px:I,py:E,pz:O}=this,{px:B,py:j,pz:N}=g,L=t.eql(t.mul(I,N),t.mul(B,O)),F=t.eql(t.mul(E,N),t.mul(j,O));return L&&F}negate(){return new P(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:I}=r,E=t.mul(I,dl),{px:O,py:B,pz:j}=this,N=t.ZERO,L=t.ZERO,F=t.ZERO,X=t.mul(O,O),W=t.mul(B,B),ie=t.mul(j,j),Y=t.mul(O,B);return Y=t.add(Y,Y),F=t.mul(O,j),F=t.add(F,F),N=t.mul(g,F),L=t.mul(E,ie),L=t.add(N,L),N=t.sub(W,L),L=t.add(W,L),L=t.mul(N,L),N=t.mul(Y,N),F=t.mul(E,F),ie=t.mul(g,ie),Y=t.sub(X,ie),Y=t.mul(g,Y),Y=t.add(Y,F),F=t.add(X,X),X=t.add(F,X),X=t.add(X,ie),X=t.mul(X,Y),L=t.add(L,X),ie=t.mul(B,j),ie=t.add(ie,ie),X=t.mul(ie,Y),N=t.sub(N,X),F=t.mul(ie,W),F=t.add(F,F),F=t.add(F,F),new P(N,L,F)}add(g){C(g);let{px:I,py:E,pz:O}=this,{px:B,py:j,pz:N}=g,L=t.ZERO,F=t.ZERO,X=t.ZERO,W=r.a,ie=t.mul(r.b,dl),Y=t.mul(I,B),U=t.mul(E,j),he=t.mul(O,N),Oe=t.add(I,E),se=t.add(B,j);Oe=t.mul(Oe,se),se=t.add(Y,U),Oe=t.sub(Oe,se),se=t.add(I,O);let Ne=t.add(B,N);return se=t.mul(se,Ne),Ne=t.add(Y,he),se=t.sub(se,Ne),Ne=t.add(E,O),L=t.add(j,N),Ne=t.mul(Ne,L),L=t.add(U,he),Ne=t.sub(Ne,L),X=t.mul(W,se),L=t.mul(ie,he),X=t.add(L,X),L=t.sub(U,X),X=t.add(U,X),F=t.mul(L,X),U=t.add(Y,Y),U=t.add(U,Y),he=t.mul(W,he),se=t.mul(ie,se),U=t.add(U,he),he=t.sub(Y,he),he=t.mul(W,he),se=t.add(se,he),Y=t.mul(U,se),F=t.add(F,Y),Y=t.mul(Ne,se),L=t.mul(Oe,L),L=t.sub(L,Y),Y=t.mul(Oe,U),X=t.mul(Ne,X),X=t.add(X,Y),new P(L,F,X)}subtract(g){return this.add(g.negate())}is0(){return this.equals(P.ZERO)}multiply(g){let{endo:I}=e;if(!n.isValidNot0(g))throw new Error("invalid scalar: out of range");let E,O,B=j=>M.wNAFCached(this,j,P.normalizeZ);if(I){let{k1neg:j,k1:N,k2neg:L,k2:F}=I.splitScalar(g),{p:X,f:W}=B(N),{p:ie,f:Y}=B(F);O=W.add(Y),E=Z(I.beta,X,ie,j,L)}else{let{p:j,f:N}=B(g);E=j,O=N}return P.normalizeZ([E,O])[0]}multiplyUnsafe(g){let{endo:I}=e,E=this;if(!n.isValid(g))throw new Error("invalid scalar: out of range");if(g===Fa||E.is0())return P.ZERO;if(g===Wa)return E;if(M.hasPrecomputes(this))return this.multiply(g);if(I){let{k1neg:O,k1:B,k2neg:j,k2:N}=I.splitScalar(g),{p1:L,p2:F}=I0(P,E,B,N);return Z(I.beta,L,F,O,j)}else return M.wNAFCachedUnsafe(E,g)}multiplyAndAddUnsafe(g,I,E){let O=this.multiplyUnsafe(I).add(g.multiplyUnsafe(E));return O.is0()?void 0:O}toAffine(g){return R(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return o===Wa?!0:g?g(P,this):M.wNAFCachedUnsafe(this,i).is0()}clearCofactor(){let{clearCofactor:g}=e;return o===Wa?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 $r(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 q=n.BITS,M=el(P,e.endo?Math.ceil(q/2):q);return P}function iw(r){return Uint8Array.of(r?2:3)}function gE(r,e,t={}){Gr(e,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Ro,o=e.hmac||((E,...O)=>ys(e.hash,E,Yt(...O))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s;function l(E){let O=a>>Wa;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,j){p("r",O),p("s",B),this.r=O,this.s=B,j!=null&&(this.recovery=j),Object.freeze(this)}static fromCompact(O){let B=s.BYTES,j=ke("compactSignature",O,B*2);return new y(s.fromBytes(j.subarray(0,B)),s.fromBytes(j.subarray(B,B*2)))}static fromDER(O){let{r:B,s:j}=wn.toSig(ke("DER",O));return new y(B,j)}assertValidity(){}addRecoveryBit(O){return new y(this.r,this.s,O)}recoverPublicKey(O){let B=i.ORDER,{r:j,s:N,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*hE<B&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let X=L===2||L===3?j+a:j;if(!i.isValid(X))throw new Error("recovery id 2 or 3 invalid");let W=i.toBytes(X),ie=r.fromHex(Yt(iw((L&1)===0),W)),Y=s.inv(X),U=D(ke("msgHash",O)),he=s.create(-U*Y),Oe=s.create(N*Y),se=r.BASE.multiplyUnsafe(he).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 Yt(s.toBytes(this.r),s.toBytes(this.s));if(O==="der")return os(wn.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return $r(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return $r(this.toBytes("compact"))}}let m=ow(s,t.allowedPrivateKeyLengths,t.wrapPrivateKey),x={isValidPrivateKey(E){try{return m(E),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let E=a;return _0(n(Sh(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=ke("key",E).length,j=i.BYTES,N=j+1,L=2*j+1;if(!(t.allowedPrivateKeyLengths||s.BYTES===N))return B===N||B===L}function C(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 R=e.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let O=is(E),B=E.length*8-c;return B>0?O>>BigInt(B):O},D=e.bits2int_modN||function(E){return s.create(R(E))},Z=Mo(c);function P(E){return Er("num < 2^"+c,E,Fa,Z),s.toBytes(E)}function q(E,O,B=M){if(["recovered","canonical"].some(Oe=>Oe in B))throw new Error("sign() legacy options not supported");let{hash:j}=e,{lowS:N,prehash:L,extraEntropy:F}=B;N==null&&(N=!0),E=ke("msgHash",E),nw(B),L&&(E=ke("prehashed msgHash",j(E)));let X=D(E),W=m(O),ie=[P(W),P(X)];if(F!=null&&F!==!1){let Oe=F===!0?n(i.BYTES):F;ie.push(ke("extraEntropy",Oe))}let Y=Yt(...ie),U=X;function he(Oe){let se=R(Oe);if(!s.isValidNot0(se))return;let Ne=s.inv(se),vt=r.BASE.multiply(se).toAffine(),et=s.create(vt.x);if(et===Fa)return;let tt=s.create(Ne*s.create(U+et*W));if(tt===Fa)return;let ut=(vt.x===et?0:2)|Number(vt.y&Wa),or=tt;return N&&l(tt)&&(or=f(tt),ut^=1),new y(et,or,ut)}return{seed:Y,k2sig:he}}let M={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function g(E,O,B=M){let{seed:j,k2sig:N}=q(E,O,B);return p0(e.hash.outputLen,s.BYTES,o)(j,N)}r.BASE.precompute(8);function I(E,O,B,j=K){let N=E;O=ke("msgHash",O),B=ke("publicKey",B),nw(j);let{lowS:L,prehash:F,format:X}=j;if("strict"in j)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 W=typeof N=="string"||rs(N),ie=!W&&!X&&typeof N=="object"&&N!==null&&typeof N.r=="bigint"&&typeof N.s=="bigint";if(!W&&!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(N.r,N.s);else throw new Error("invalid format");if(W){try{X!=="compact"&&(Y=y.fromDER(N))}catch(or){if(!(or instanceof wn.Err))throw or}!Y&&X!=="der"&&(Y=y.fromCompact(N))}U=r.fromHex(B)}catch{return!1}if(!Y||L&&Y.hasHighS())return!1;F&&(O=e.hash(O));let{r:he,s:Oe}=Y,se=D(O),Ne=s.inv(Oe),vt=s.create(se*Ne),et=s.create(he*Ne),tt=r.BASE.multiplyUnsafe(vt).add(U.multiplyUnsafe(et));return tt.is0()?!1:s.create(tt.x)===he}return Object.freeze({getPublicKey:v,getSharedSecret:C,sign:g,verify:I,utils:x,Point:r,Signature:y})}function wE(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=Cr(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 bE(r){let{CURVE:e,curveOpts:t}=wE(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 xE(r,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:r})}function sw(r){let{CURVE:e,curveOpts:t,ecdsaOpts:n}=bE(r),o=mE(e,t),i=gE(o,n,t);return xE(r,i)}function aw(r,e){let t=n=>sw({...r,hash:n});return{...t(e),create:t}}var yl={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},m8=BigInt(0),vE=BigInt(1),id=BigInt(2),cw=(r,e)=>(r+e/id)/e;function _E(r){let e=yl.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,id,e)*l%e,x=Me(m,o,e)*m%e,v=Me(x,i,e)*x%e,d=Me(v,a,e)*v%e,C=Me(d,c,e)*d%e,R=Me(C,a,e)*v%e,D=Me(R,t,e)*f%e,Z=Me(D,s,e)*x%e,P=Me(Z,n,e)*l%e,q=Me(P,id,e);if(!sd.eql(sd.sqr(q),r))throw new Error("Cannot find square root");return q}var sd=Cr(yl.p,void 0,void 0,{sqrt:_E}),Br=aw({...yl,Fp:sd,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=yl.n,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-vE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=cw(i*r,e),c=cw(-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}}}},Yu);function uw(r,e,t){let n=ir.digest(e instanceof Uint8Array?e:e.subarray());if(fs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Br.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new ja(String(o))});try{return Br.sign(n.digest,r).toDERRawBytes()}catch(o){throw new ja(String(o))}}function lw(r,e,t,n){let o=ir.digest(t instanceof Uint8Array?t:t.subarray());if(fs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Br.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Ra(String(i))});try{return n?.signal?.throwIfAborted(),Br.verify(e,o.digest,r)}catch(i){throw new Ra(String(i))}}var Ga=class{type="secp256k1";raw;_key;constructor(e){this._key=hw(e),this.raw=fw(this._key)}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return lw(this._key,t,e,n)}},ml=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=pw(e),this.publicKey=new Ga(t??dw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return uw(this.raw,e,t)}};function ad(r){return new Ga(r)}async function yw(){let r=SE();return new ml(r)}function fw(r){return Br.ProjectivePoint.fromHex(r).toRawBytes(!0)}function pw(r){try{return Br.getPublicKey(r,!0),r}catch(e){throw new ga(String(e))}}function hw(r){try{return Br.ProjectivePoint.fromHex(r),r}catch(e){throw new Xi(String(e))}}function dw(r){try{return Br.getPublicKey(r,!0)}catch(e){throw new ga(String(e))}}function SE(){return Br.utils.randomPrivateKey()}async function mw(r,e){if(r==="Ed25519")return H0();if(r==="secp256k1")return yw();if(r==="RSA")return nd(AE(e));if(r==="ECDSA")return Gg(EE(e));throw new $n}function qa(r,e){let{Type:t,Data:n}=zr.decode(r),o=n??new Uint8Array;switch(t){case Ze.RSA:return ed(o,e);case Ze.Ed25519:return Oh(o);case Ze.secp256k1:return ad(o);case Ze.ECDSA:return dh(o);default:throw new $n}}function gw(r){let{Type:e,Data:t}=zr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ze.Ed25519:return Oh(n);case Ze.secp256k1:return ad(n);case Ze.ECDSA:return dh(n);default:throw new $n}}function qn(r){return zr.encode({Type:Ze[r.type],Data:r.raw})}function AE(r){return r==null?2048:parseInt(r,10)}function EE(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function gl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var ww=Symbol.for("nodejs.util.inspect.custom"),CE=114,za=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()})`}[Hp]=!0;toString(){return this.string==null&&(this.string=De.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Xe.createV1(CE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ww](){return`PeerId(${this.toString()})`}},Xa=class extends za{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Za=class extends za{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Ya=class extends za{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},TE=2336,Ja=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=vr.digest(pe(this.url))}[ww](){return`PeerId(${this.url})`}[Hp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Xe.createV1(TE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=le(e)),e.toString()===this.toString())}};var IE=114,bw=2336;function ms(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=es(De.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return OE(Xe.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=es(e.decode(r))}return xw(t)}function cd(r){if(r.type==="Ed25519")return new Za({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Ya({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Xa({multihash:r.toCID().multihash,publicKey:r});throw new $n}function xw(r){if(BE(r))return new Xa({multihash:r});if(PE(r))try{let e=gw(r);if(e.type==="Ed25519")return new Za({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Ya({multihash:r,publicKey:e})}catch{let t=le(r.digest);return new Ja(new URL(t))}throw new Mu("Supplied PeerID Multihash is invalid")}function OE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==IE&&r.code!==bw)throw new Uu("Supplied PeerID CID is invalid");if(r.code===bw){let e=le(r.multihash.digest);return new Ja(new URL(e))}return xw(r.multihash)}function PE(r){return r.code===vr.code}function BE(r){return r.code===ir.code}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},bn=class extends Error{static name="ValidationError";name="ValidationError"},Qa=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},wl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var bl=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 kE=45,NE=15,xl=new bl;function ud(r){if(!(r.length>NE))return xl.new(r).parseWith(()=>xl.readIPv4Addr())}function ld(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>kE))return xl.new(r).parseWith(()=>xl.readIPv6Addr())}function gs(r){return!!ud(r)}function vl(r){return!!ld(r)}function pd(r){return e=>le(e,r)}function hd(r){return e=>pe(e,r)}function ws(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Go(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function _w(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=pe(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=Go(n);return Pt([t,o],t.length+o.length)}function Sw(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=Gn.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=Go(n);return Pt([t,o],t.length+o.length)}function dd(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=le(e,"base32"),o=ws(t);return`${n}:${o}`}var yd=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 ft("Invalid byte value in IP address");e[n]=o}),e},Aw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=gs(t[n]),s;i&&(s=yd(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 ft("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Ew=function(r){if(r.byteLength!==4)throw new ft("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Cw=function(r){if(r.byteLength!==16)throw new ft("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 ft(`Invalid IPv6 address "${t}"`)}};function Tw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}}var fd=Object.values(ko).map(r=>r.decoder),DE=function(){let r=fd[0].or(fd[1]);return fd.slice(2).forEach(e=>r=r.or(e)),r}();function Iw(r){return DE.decode(r)}function Ow(r){return e=>r.encoder.encode(e)}function jE(r){if(parseInt(r).toString()!==r)throw new bn("Value must be an integer")}function RE(r){if(r<0)throw new bn("Value must be a positive integer, or zero")}function LE(r){return e=>{if(e>r)throw new bn(`Value must be smaller than or equal to ${r}`)}}function UE(...r){return e=>{for(let t of r)t(e)}}var ec=UE(jE,RE,LE(65535));var ct=-1,md=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 wl(`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)}))}},Qt=new md,d2=[{code:4,name:"ip4",size:32,valueToBytes:yd,bytesToValue:Ew,validate:r=>{if(!gs(r))throw new bn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Go,bytesToValue:ws,validate:ec},{code:273,name:"udp",size:16,valueToBytes:Go,bytesToValue:ws,validate:ec},{code:33,name:"dccp",size:16,valueToBytes:Go,bytesToValue:ws,validate:ec},{code:41,name:"ip6",size:128,valueToBytes:Aw,bytesToValue:Cw,stringToValue:Tw,validate:r=>{if(!vl(r))throw new bn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:pd("base10"),valueToBytes:hd("base10")},{code:53,name:"dns",size:ct,resolvable:!0},{code:54,name:"dns4",size:ct,resolvable:!0},{code:55,name:"dns6",size:ct,resolvable:!0},{code:56,name:"dnsaddr",size:ct,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Go,bytesToValue:ws,validate:ec},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:pd("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?hd("base58btc")(r):Xe.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:dd,valueToBytes:_w},{code:445,name:"onion3",size:296,bytesToValue:dd,valueToBytes:Sw},{code:446,name:"garlic64",size:ct},{code:447,name:"garlic32",size:ct},{code:448,name:"tls"},{code:449,name:"sni",size:ct},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ct,bytesToValue:Ow(hn),valueToBytes:Iw},{code:480,name:"http"},{code:481,name:"http-path",size:ct,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:ct}];d2.forEach(r=>{Qt.addProtocol(r)});function Pw(r){let e=[],t=0;for(;t<r.length;){let n=Vo(r,t),o=Qt.getProtocol(n),i=He(n),s=y2(o,r,t+i),a=0;s>0&&o.size===ct&&(a=He(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 Bw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=Qt.getProtocol(n.code),i=He(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??pe(n.value),a=s.byteLength,o.size===ct&&(c=He(a)));let l=new Uint8Array(i+c+a),f=0;ps(n.code,l,f),f+=i,s!=null&&(o.size===ct&&(ps(a,l,f),f+=c),l.set(s,f)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Pt(t,e)}function kw(r){if(r.charAt(0)!=="/")throw new ft('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=Qt.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 ft(`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 ft(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return e}function Nw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=Qt.getProtocol(e.code);if(t==null)throw new ft(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function y2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Vo(e,t)}var m2=Symbol.for("nodejs.util.inspect.custom"),Ad=Symbol.for("@multiformats/multiaddr"),g2=[53,54,55,56],Sd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function w2(r){if(r==null&&(r="/"),jw(r))return r.getComponents();if(r instanceof Uint8Array)return Pw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),kw(r);if(Array.isArray(r))return r;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Cl=class r{[Ad]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=w2(e),t.validate!==!1&&b2(this)}get bytes(){return this.#r==null&&(this.#r=Bw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Nw(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??""}`),g2.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=Qt.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=Qt.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??pe(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 Qa(`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(De.decode(`z${n}`),"base58btc"):le(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(Qt.getProtocol(e.code).path)return e.value??null;return null}equals(e){return Fe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Dw.get(t.name);if(n==null)throw new Sd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Xr(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)}[m2](){return`Multiaddr(${this.toString()})`}};function b2(r){r.getComponents().forEach(e=>{let t=Qt.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var n5=parseInt("0xFFFF",16),o5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Dw=new Map;function jw(r){return!!r?.[Ad]}function Xr(r){return new Cl(r)}var A2=r=>r.toString().split("/").slice(1),bs=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>bs(t=>t===r).match(e),pattern:r}),qo=()=>({match:r=>bs(e=>typeof e=="string").match(r),pattern:"{string}"}),xs=()=>({match:r=>bs(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ie=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{De.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),rc=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{hn.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ee=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Tt=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),xe=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function Re(...r){function e(o){let i=A2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var E2=Ie(),z5=Re(E2),Il=xe(ye("dns4"),qo()),Ol=xe(ye("dns6"),qo()),Pl=xe(ye("dnsaddr"),qo()),Cd=xe(ye("dns"),qo()),X5=Re(Il,Ee(Ie())),Z5=Re(Ol,Ee(Ie())),Y5=Re(Pl,Ee(Ie())),J5=Re(Tt(Cd,Pl,Il,Ol),Ee(Ie())),Uw=xe(ye("ip4"),bs(gs)),Mw=xe(ye("ip6"),bs(vl)),Td=Tt(Uw,Mw),xn=Tt(Td,Cd,Il,Ol,Pl),Q5=Re(Tt(Td,xe(Tt(Cd,Pl,Il,Ol),Ee(Ie())))),e4=Re(Uw),t4=Re(Mw),r4=Re(Td),Id=xe(xn,ye("tcp"),xs()),nc=xe(xn,ye("udp"),xs()),n4=Re(xe(Id,Ee(Ie()))),o4=Re(nc),Od=xe(nc,ye("quic"),Ee(Ie())),Bl=xe(nc,ye("quic-v1"),Ee(Ie())),C2=Tt(Od,Bl),i4=Re(Od),s4=Re(Bl),Ed=Tt(xn,Id,nc,Od,Bl),Kw=Tt(xe(Ed,ye("ws"),Ee(Ie()))),a4=Re(Kw),Hw=Tt(xe(Ed,ye("wss"),Ee(Ie())),xe(Ed,ye("tls"),Ee(xe(ye("sni"),qo())),ye("ws"),Ee(Ie()))),c4=Re(Hw),Vw=xe(nc,ye("webrtc-direct"),Ee(rc()),Ee(rc()),Ee(Ie())),$w=Re(Vw),Fw=xe(Bl,ye("webtransport"),Ee(rc()),Ee(rc()),Ee(Ie())),u4=Re(Fw),Tl=Tt(Kw,Hw,xe(Id,Ee(Ie())),xe(C2,Ee(Ie())),xe(xn,Ee(Ie())),Vw,Fw,Ie()),Ww=Re(Tl),T2=xe(Tl,ye("p2p-circuit"),Ie()),l4=Re(T2),I2=Tt(xe(Tl,ye("p2p-circuit"),ye("webrtc"),Ee(Ie())),xe(Tl,ye("webrtc"),Ee(Ie())),xe(ye("webrtc"),Ee(Ie()))),Gw=Re(I2),O2=Tt(xe(xn,ye("tcp"),xs(),ye("http"),Ee(Ie())),xe(xn,ye("http"),Ee(Ie()))),f4=Re(O2),P2=Tt(xe(xn,ye("tcp"),Tt(xe(ye("443"),ye("http")),xe(xs(),ye("https")),xe(xs(),ye("tls"),ye("http"))),Ee(Ie())),xe(xn,ye("tls"),ye("http"),Ee(Ie())),xe(xn,ye("https"),Ee(Ie()))),p4=Re(P2),B2=Tt(xe(ye("memory"),qo(),Ee(Ie()))),h4=Re(B2);var It;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Wo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Pr((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=>Or(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(It||(It={}));var qw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Pd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),zw="libp2p+webrtc+v1/";var Xw=466,Zw=2*1024*1024,Yw=30*1e3,vs=16*1024;function k2(r=vs){let e=He(r-He(r)),t=1+He(Object.keys(It.Flag).length-1),n=1,o=r-e-t-n,i=He(o);return e+t+n+i}var Jw=k2(),Qw=5e3,eb=5e3,tb=3e4,Bd="/webrtc",oc="/webrtc-signaling/0.0.1",rb="/libp2p/webrtc-direct/certificate",nb="webrtc-direct-certificate-private-key";var ob=12096e5,kd=864e5;var ib=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))},N2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var D2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var j2=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 R2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var L2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var U2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,M2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,sb=3,K2=[["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",U2]],ab=[["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 ub(r){return r?cb(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new L2:typeof navigator<"u"?cb(navigator.userAgent):$2()}function H2(r){return r!==""&&K2.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 cb(r){var e=H2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new R2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<sb&&(o=ib(ib([],o,!0),F2(sb-o.length),!0)):o=[];var i=o.join("."),s=V2(r),a=M2.exec(r);return a&&a[1]?new j2(t,i,s,a[1]):new N2(t,i,s)}function V2(r){for(var e=0,t=ab.length;e<t;e++){var n=ab[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function $2(){var r=typeof process<"u"&&process.version;return r?new D2(process.version.slice(1)):null}function F2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ye(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Nd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Dd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},lb=r=>globalThis.DOMException===void 0?new Dd(r):new DOMException(r),fb=r=>{let e=r.reason===void 0?lb("This operation was aborted."):r.reason;return e instanceof Error?e:lb(e)};function ic(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(fb(m)),a=()=>{p(fb(m))},m.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(f,p);return}let y=new Nd;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 pb=ub(),sc=pb!=null&&pb.name==="firefox",kl=async function*(){},Nl=async r=>{};function hb(r,e,t=tb,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=Ye(),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 ic(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function jd(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??qw.map(e=>({urls:[e]})),r}var db=(r=32)=>zw+[...Array(r)].map(()=>Pd.at(Math.floor(Math.random()*Pd.length))).join("");var zo=class{log;peerConnection;remoteAddr;timeline;metrics;source=kl();sink=Nl;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 Dl=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}},_s=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Dl(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 Dl(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 Rd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ss(r={}){return W2(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 W2(r,e){e=e??{};let t=e.onEnd,n=new _s,o,i,s,a=Ye(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,C)=>{i=R=>{i=null,n.push(R);try{d(r(n))}catch(D){C(D)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ye()})}},l=d=>i!=null?i(d):(n.push(d),o),f=d=>(n=new _s,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 _s,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 C=d?.signal;if(C?.throwIfAborted(),n.isEmpty())return;let R,D;C!=null&&(R=new Promise((Z,P)=>{D=()=>{P(new Rd)},C.addEventListener("abort",D)}));try{await Promise.race([a.promise,R])}finally{D!=null&&C!=null&&C?.removeEventListener("abort",D)}}},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 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 sr(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 yb(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 mb(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function gb(r,e){let t=yb(r).return?.();mb(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var G2=5e3;function Ld(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Rl=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=Ye(),this.closed=Ye(),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??G2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=Ss({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new Oo(`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);Ld(o)&&await o}let n=()=>{gb(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);Ld(i)&&(this.sendingData=Ye(),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 sr(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 sr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await sr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await sr(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();Ld(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 Lu("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 Ud(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 Ll=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},As=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ul=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},ac=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ml(r){return r[Symbol.asyncIterator]!=null}function wb(r,e){if(r.byteLength>e)throw new As("Message length too long")}var Hl=r=>{let e=He(r),t=ot(e);return cl(r,t),Hl.bytes=e,t};Hl.bytes=0;function cc(r,e){e=e??{};let t=e.lengthEncoder??Hl,n=e?.maxDataLength??4194304;function*o(i){wb(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Ml(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}cc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Hl,n=e?.maxDataLength??4194304;return wb(r,n),new be(t(r.byteLength),r)};var Xo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Xo||(Xo={}));var Md=r=>{let e=Vo(r);return Md.bytes=He(e),e};Md.bytes=0;function Zo(r,e){let t=new be,n=Xo.LENGTH,o=-1,i=e?.lengthDecoder??Md,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Xo.LENGTH)try{if(o=i(t),o<0)throw new Ll("Invalid message length");if(o>a)throw new As("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Xo.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new Ul("Message length length too long");break}throw l}if(n===Xo.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Xo.LENGTH}}}return Ml(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new ac("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new ac("Unexpected end of input")}()}Zo.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 Zo(n,{...e??{},onLength:i=>{t=i}})};var Kd=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 uc(r,e,t,n){let o=new Kd(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 Hd=class extends Rl{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 ic(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Ss(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Yw,this.maxBufferedAmount=e.maxBufferedAmount??Zw,this.maxMessageSize=(e.maxMessageSize??vs)-Jw,this.receiveFinAck=Ye(),this.finAckTimeout=e.closeTimeout??Qw,this.openTimeout=e.openTimeout??eb,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 Oo("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 Zo(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 Oo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Ud([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 uc(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=Ud([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await uc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Hu(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=It.encode({message:o}),s=cc.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(It.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(It.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await sr(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(It.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=It.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===It.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(It.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===It.Flag.RESET&&this.reset(),t.flag===It.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===It.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=It.encode({flag:e}),n=cc.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 Es(r){let{channel:e,direction:t,handshake:n}=r;return new Hd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var to=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Bd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=Es({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Vd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Vd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Bd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=Es({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),hb(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=Nl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=Es({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Vl=globalThis.RTCPeerConnection,$l=globalThis.RTCSessionDescription,bb=globalThis.RTCIceCandidate;var $d=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ye(),this.haveNext=Ye()}[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=Ye(),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=Ye(),await sr(this.readNext.promise,t?.signal,t)}};function Fl(){return new $d}var Wl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function xb(r,e){let t=Fl();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 sr(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await sr(n.next(),s?.signal);if(l===!0)throw new Wl("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 Gl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ql=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function lc(r,e={}){let t=xb(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=He(e.maxDataLength));let n=e?.lengthDecoder??Vo,o=e?.lengthEncoder??cl;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 Gl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new zl("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ql("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 Xl(r,e){let t=lc(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 er=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var ro=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ar=class extends ro{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Zl=class extends ro{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Yl=class extends ro{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Jl=class extends ro{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Ut;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Wo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Pr((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=>Or(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(Ut||(Ut={}));var Ql=async(r,e,t)=>{try{let n=Ye();for(X2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Ut.Type.ICE_CANDIDATE)throw new Ku("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new er("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new bb(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new er("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&&ef(r)!=="connected")throw n}};function ef(r){return sc?r.iceConnectionState:r.connectionState}function X2(r,e){r[sc?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(ef(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Ru("RTCPeerConnection was closed"));break;default:break}}}async function vb({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{baseAddr:f}=_b(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",f);let p=f.getPeerId();if(p==null)throw new ve("Relay peer was missing");let y=i.getConnections(ms(p)),m,x=!1;y.length===0?(l?.(new er("webrtc:dial-relay")),m=await s.dial(f,{signal:t,onProgress:l}),x=!0):(l?.(new er("webrtc:reuse-relay-connection")),m=y[0]);try{l?.(new er("webrtc:open-signaling-stream"));let v=await m.newStream(oc,{signal:t,runOnLimitedConnection:!0}),d=Xl(v).pb(Ut),C=new Vl(r),R=new to({logger:c},{peerConnection:C,dataChannelOptions:e});try{let D=C.createDataChannel("init");C.onicecandidate=({candidate:M})=>{let K=JSON.stringify(M?.toJSON()??null);a.trace("initiator sending ICE candidate %o",M),d.write({type:Ut.Type.ICE_CANDIDATE,data:K},{signal:t}).catch(g=>{a.error("error sending ICE candidate",g)})},C.onicecandidateerror=M=>{a.error("initiator ICE candidate error",M)};let Z=await C.createOffer().catch(M=>{throw a.error("could not execute createOffer",M),new ar("Failed to set createOffer")});a.trace("initiator send SDP offer %s",Z.sdp),l?.(new er("webrtc:send-sdp-offer")),await d.write({type:Ut.Type.SDP_OFFER,data:Z.sdp},{signal:t}),await C.setLocalDescription(Z).catch(M=>{throw a.error("could not execute setLocalDescription",M),new ar("Failed to set localDescription")}),l?.(new er("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let P=await d.read({signal:t});if(P.type!==Ut.Type.SDP_ANSWER)throw new ar("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",P.data);let q=new $l({type:"answer",sdp:P.data});return await C.setRemoteDescription(q).catch(M=>{throw a.error("could not execute setRemoteDescription",M),new ar("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new er("webrtc:read-ice-candidates")),await Ql(C,d,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),D.close(),l?.(new er("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await v.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:C,muxerFactory:R}}catch(D){throw a.error("outgoing signaling error",D),C.close(),v.abort(D),D}finally{C.onicecandidate=null,C.onicecandidateerror=null}}finally{if(x)try{await m.close({signal:t})}catch(v){m.abort(v)}}}var Sb=Re(Ww.matchers[0],ye("p2p-circuit")),tf=class r extends Fn{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=>Sb.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=>Sb.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 Ab({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Xl(e).pb(Ut);try{r.onicecandidate=({candidate:f})=>{let p=JSON.stringify(f?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Ut.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!==Ut.Type.SDP_OFFER)throw new ar(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new $l({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(f=>{throw o.error("could not execute setRemoteDescription",f),new ar("Failed to set remoteDescription")});let l=await r.createAnswer().catch(f=>{throw o.error("could not execute createAnswer",f),new ar("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:Ut.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(f=>{throw o.error("could not execute setLocalDescription",f),new ar("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Ql(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(ef(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=Xr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var rf=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"})})}[Nu]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Zi]=["@libp2p/transport"];[yg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(oc,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(oc),this._started=!1}createListener(e){return new tf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Gw.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 vb({rtcConfiguration:await jd(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 zo(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 Vl(await jd(this.init.rtcConfiguration)),i=new to(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await Ab({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new zo(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 _b(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new ve("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new ve("p2p-circuit protocol was not present in multiaddr");let t=Xr(e[0]),o=Xr("/"+e[1]).getPeerId();if(o==null)throw new ve("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new ve("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:ms(o)}}var Uz=Vr(Cb());var Qr={};_t(Qr,{Any:()=>Yr,BaseBlock:()=>Je,BaseStringBlock:()=>dc,BitString:()=>Dr,BmpString:()=>ti,Boolean:()=>Jo,CharacterString:()=>li,Choice:()=>Is,Constructed:()=>it,DATE:()=>xc,DateTime:()=>_c,Duration:()=>Sc,EndOfContent:()=>yc,Enumerated:()=>Qo,GeneralString:()=>ui,GeneralizedTime:()=>fi,GraphicString:()=>ci,HexBlock:()=>Jr,IA5String:()=>ai,Integer:()=>En,Null:()=>kr,NumericString:()=>ni,ObjectIdentifier:()=>ei,OctetString:()=>Nr,Primitive:()=>An,PrintableString:()=>oi,RawData:()=>qd,RelativeObjectIdentifier:()=>bc,Repeated:()=>pi,Sequence:()=>Ht,Set:()=>Vt,TIME:()=>Ac,TeletexString:()=>ii,TimeOfDay:()=>vc,UTCTime:()=>so,UniversalString:()=>ri,Utf8String:()=>ur,ValueBlock:()=>pt,VideotexString:()=>si,ViewWriter:()=>Ts,VisibleString:()=>io,compareSchema:()=>oo,fromBER:()=>Tn,verifySchema:()=>mC});var de=Vr(_n());function Yo(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 no(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 sf(...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 Wd(){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=Yo(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,Yo(i,8)-n}function Tb(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=no(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=no(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 Ib(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 Mt(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 KN=Math.log(2);function af(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function zd(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 Ts=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return zd(this.items)}},fc=[new Uint8Array([1])],Ob="0123456789",Gd="name",Pb="valueHexView",oC="isHexOnly",iC="idBlock",sC="tagClass",aC="tagNumber",cC="isConstructed",uC="fromBER",lC="toBER",fC="local",Kt="",jr=new ArrayBuffer(0),_f=new Uint8Array(0),hc="EndOfContent",kb="OCTET STRING",Nb="BIT STRING";function Jr(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?de.BufferSourceConverter.toUint8Array(i.valueHex):_f}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",jr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:de.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=Kt,warnings:n=[],valueBeforeDecode:o=_f}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=de.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:de.Convert.ToHex(this.valueBeforeDecodeView)}}};Sn.NAME="baseBlock";var pt=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'")}};pt.NAME="valueBlock";var cf=class extends Jr(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?de.BufferSourceConverter.toUint8Array(e.valueHex):_f,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",jr}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=no(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=de.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=Yo(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}}};cf.NAME="identificationBlock";var uf=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=de.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=Yo(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=no(this.length,8);if(o.byteLength>127)return this.error="Too big length",jr;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}}};uf.NAME="lengthBlock";var Q={},Je=class extends Sn{constructor({name:e=Kt,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 uf(o),this.valueBlock=i?new i(o):new pt(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 Ts;t||Db(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?jr: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():de.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=de.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 Ib(t,n)}};Je.NAME="BaseBlock";function Db(r){var e;if(r instanceof Q.Constructed)for(let t of r.valueBlock.value)Db(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var dc=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Kt,...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 lf=class extends Jr(pt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};lf.NAME="PrimitiveValueBlock";var jb,An=class extends Je{constructor(e={}){super(e,lf),this.idBlock.isConstructed=!1}};jb=An;Q.Primitive=jb;An.NAME="PRIMITIVE";function pC(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 Os(r,e=0,t=r.length){let n=e,o=new Je({},pt),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=Je;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=pC(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 Je({},pt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Os(de.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function hC(r,e){return r?1:e}var Zr=class extends pt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=de.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(;hC(this.isIndefiniteForm,n)>0;){let s=Os(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===hc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===hc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Ts;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?jr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Zr.NAME="ConstructedValueBlock";var Rb,it=class extends Je{constructor(e={}){super(e,Zr),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 K_=Object.create;var Bu=Object.defineProperty;var H_=Object.getOwnPropertyDescriptor;var V_=Object.getOwnPropertyNames;var $_=Object.getPrototypeOf,F_=Object.prototype.hasOwnProperty;var Kp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_t=(r,e)=>{for(var t in e)Bu(r,t,{get:e[t],enumerable:!0})},hg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of V_(e))!F_.call(r,o)&&o!==t&&Bu(r,o,{get:()=>e[o],enumerable:!(n=H_(e,o))||n.enumerable});return r};var Vr=(r,e,t)=>(t=r!=null?K_($_(r)):{},hg(e||!r||!r.__esModule?Bu(t,"default",{value:r,enumerable:!0}):t,r)),W_=r=>hg(Bu({},"__esModule",{value:!0}),r);var Cb=Kp(()=>{var Eb;(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 Mp(Object.create(null))}:c?function(){return Mp({__proto__:null})}:function(){return Mp({})},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:j_(),m=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:R_(),x=typeof WeakMap=="function"?WeakMap:L_(),v=o?Symbol.for("@reflect-metadata:registry"):void 0,d=k_(),I=N_(d);function D(b,S,k,F){if(U(k)){if(!or(b))throw new TypeError;if(!sg(S))throw new TypeError;return O(b,S)}else{if(!or(b))throw new TypeError;if(!se(S))throw new TypeError;if(!se(F)&&!U(F)&&!he(F))throw new TypeError;return he(F)&&(F=void 0),k=ut(k),B(b,S,k,F)}}e("decorate",D);function j(b,S){function k(F,ce){if(!se(F))throw new TypeError;if(!U(ce)&&!P_(ce))throw new TypeError;X(b,S,F,ce)}return k}e("metadata",j);function Z(b,S,k,F){if(!se(k))throw new TypeError;return U(F)||(F=ut(F)),X(b,S,k,F)}e("defineMetadata",Z);function P(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),R(b,S,k)}e("hasMetadata",P);function M(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),N(b,S,k)}e("hasOwnMetadata",M);function V(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),L(b,S,k)}e("getMetadata",V);function K(b,S,k){if(!se(S))throw new TypeError;return U(k)||(k=ut(k)),W(b,S,k)}e("getOwnMetadata",K);function g(b,S){if(!se(b))throw new TypeError;return U(S)||(S=ut(S)),G(b,S)}e("getMetadataKeys",g);function T(b,S){if(!se(b))throw new TypeError;return U(S)||(S=ut(S)),ie(b,S)}e("getOwnMetadataKeys",T);function E(b,S,k){if(!se(S))throw new TypeError;if(U(k)||(k=ut(k)),!se(S))throw new TypeError;U(k)||(k=ut(k));var F=ya(S,k,!1);return U(F)?!1:F.OrdinaryDeleteMetadata(b,S,k)}e("deleteMetadata",E);function O(b,S){for(var k=b.length-1;k>=0;--k){var F=b[k],ce=F(S);if(!U(ce)&&!he(ce)){if(!sg(ce))throw new TypeError;S=ce}}return S}function B(b,S,k,F){for(var ce=b.length-1;ce>=0;--ce){var qe=b[ce],rt=qe(S,k,F);if(!U(rt)&&!he(rt)){if(!se(rt))throw new TypeError;F=rt}}return F}function R(b,S,k){var F=N(b,S,k);if(F)return!0;var ce=Up(S);return he(ce)?!1:R(b,ce,k)}function N(b,S,k){var F=ya(S,k,!1);return U(F)?!1:et(F.OrdinaryHasOwnMetadata(b,S,k))}function L(b,S,k){var F=N(b,S,k);if(F)return W(b,S,k);var ce=Up(S);if(!he(ce))return L(b,ce,k)}function W(b,S,k){var F=ya(S,k,!1);if(!U(F))return F.OrdinaryGetOwnMetadata(b,S,k)}function X(b,S,k,F){var ce=ya(k,F,!0);ce.OrdinaryDefineOwnMetadata(b,S,k,F)}function G(b,S){var k=ie(b,S),F=Up(b);if(F===null)return k;var ce=G(F,S);if(ce.length<=0)return k;if(k.length<=0)return ce;for(var qe=new m,rt=[],ge=0,J=k;ge<J.length;ge++){var ee=J[ge],re=qe.has(ee);re||(qe.add(ee),rt.push(ee))}for(var ne=0,we=ce;ne<we.length;ne++){var ee=we[ne],re=qe.has(ee);re||(qe.add(ee),rt.push(ee))}return rt}function ie(b,S){var k=ya(b,S,!1);return k?k.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 he(b){return b===null}function Oe(b){return typeof b=="symbol"}function se(b){return typeof b=="object"?b!==null:typeof b=="function"}function Ne(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 k=S===3?"string":S===5?"number":"default",F=ag(b,i);if(F!==void 0){var ce=F.call(b,k);if(se(ce))throw new TypeError;return ce}return vt(b,k==="default"?"number":k)}function vt(b,S){if(S==="string"){var k=b.toString;if(zi(k)){var F=k.call(b);if(!se(F))return F}var ce=b.valueOf;if(zi(ce)){var F=ce.call(b);if(!se(F))return F}}else{var ce=b.valueOf;if(zi(ce)){var F=ce.call(b);if(!se(F))return F}var qe=b.toString;if(zi(qe)){var F=qe.call(b);if(!se(F))return F}}throw new TypeError}function et(b){return!!b}function tt(b){return""+b}function ut(b){var S=Ne(b,3);return Oe(S)?S:tt(S)}function or(b){return Array.isArray?Array.isArray(b):b instanceof Object?b instanceof Array:Object.prototype.toString.call(b)==="[object Array]"}function zi(b){return typeof b=="function"}function sg(b){return typeof b=="function"}function P_(b){switch(Y(b)){case 3:return!0;case 4:return!0;default:return!1}}function Lp(b,S){return b===S||b!==b&&S!==S}function ag(b,S){var k=b[S];if(k!=null){if(!zi(k))throw new TypeError;return k}}function cg(b){var S=ag(b,s);if(!zi(S))throw new TypeError;var k=S.call(b);if(!se(k))throw new TypeError;return k}function ug(b){return b.value}function lg(b){var S=b.next();return S.done?!1:S}function fg(b){var S=b.return;S&&S.call(b)}function Up(b){var S=Object.getPrototypeOf(b);if(typeof b!="function"||b===p||S!==p)return S;var k=b.prototype,F=k&&Object.getPrototypeOf(k);if(F==null||F===Object.prototype)return S;var ce=F.constructor;return typeof ce!="function"||ce===b?S:ce}function B_(){var b;!U(v)&&typeof t.Reflect<"u"&&!(v in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(b=D_(t.Reflect));var S,k,F,ce=new x,qe={registerProvider:rt,getProvider:J,setProvider:re};return qe;function rt(ne){if(!Object.isExtensible(qe))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(k):k=ne;break;case k===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(k)){if(k.isProviderFor(ne,we))return S;if(!U(F))for(var Ue=cg(F);;){var ze=lg(Ue);if(!ze)return;var br=ug(ze);if(br.isProviderFor(ne,we))return fg(Ue),br}}}if(!U(b)&&b.isProviderFor(ne,we))return b}function J(ne,we){var Ue=ce.get(ne),ze;return U(Ue)||(ze=Ue.get(we)),U(ze)&&(ze=ge(ne,we),U(ze)||(U(Ue)&&(Ue=new y,ce.set(ne,Ue)),Ue.set(we,ze))),ze}function ee(ne){if(U(ne))throw new TypeError;return S===ne||k===ne||!U(F)&&F.has(ne)}function re(ne,we,Ue){if(!ee(Ue))throw new Error("Metadata provider not registered.");var ze=J(ne,we);if(ze!==Ue){if(!U(ze))return!1;var br=ce.get(ne);U(br)&&(br=new y,ce.set(ne,br)),br.set(we,Ue)}return!0}}function k_(){var b;return!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&(b=t.Reflect[v]),U(b)&&(b=B_()),!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,v,{enumerable:!1,configurable:!1,writable:!1,value:b}),b}function N_(b){var S=new x,k={isProviderFor:function(ee,re){var ne=S.get(ee);return U(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:rt,OrdinaryHasOwnMetadata:ce,OrdinaryGetOwnMetadata:qe,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:J};return d.registerProvider(k),k;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 ze=we.get(re);if(U(ze)){if(!ne)return;if(ze=new y,we.set(re,ze),!b.setProvider(ee,re,k))throw we.delete(re),Ue&&S.delete(ee),new Error("Wrong provider for target.")}return ze}function ce(ee,re,ne){var we=F(re,ne,!1);return U(we)?!1:et(we.has(ee))}function qe(ee,re,ne){var we=F(re,ne,!1);if(!U(we))return we.get(ee)}function rt(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(),ze=cg(Ue),br=0;;){var pg=lg(ze);if(!pg)return ne.length=br,ne;var U_=ug(pg);try{ne[br]=U_}catch(M_){try{fg(ze)}finally{throw M_}}br++}}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 D_(b){var S=b.defineMetadata,k=b.hasOwnMetadata,F=b.getOwnMetadata,ce=b.getOwnMetadataKeys,qe=b.deleteMetadata,rt=new x,ge={isProviderFor:function(J,ee){var re=rt.get(J);return!U(re)&&re.has(ee)?!0:ce(J,ee).length?(U(re)&&(re=new m,rt.set(J,re)),re.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:k,OrdinaryGetOwnMetadata:F,OrdinaryOwnMetadataKeys:ce,OrdinaryDeleteMetadata:qe};return ge}function ya(b,S,k){var F=d.getProvider(b,S);if(!U(F))return F;if(k){if(d.setProvider(b,S,I))return I;throw new Error("Illegal state.")}}function j_(){var b={},S=[],k=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--,Lp(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 k(this._keys,this._values,ce)},ge.prototype.values=function(){return new k(this._keys,this._values,qe)},ge.prototype.entries=function(){return new k(this._keys,this._values,rt)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(J,ee){if(!Lp(this._cacheKey,J)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(Lp(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 qe(ge,J){return J}function rt(ge,J){return[ge,J]}}function R_(){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(k){return this._map.has(k)},S.prototype.add=function(k){return this._map.set(k,k),this},S.prototype.delete=function(k){return this._map.delete(k)},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 L_(){var b=16,S=f.create(),k=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,k)){if(!ee)return;Object.defineProperty(J,k,{value:f.create()})}return J[k]}function qe(J,ee){for(var re=0;re<ee;++re)J[re]=Math.random()*255|0;return J}function rt(J){if(typeof Uint8Array=="function"){var ee=new Uint8Array(J);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):qe(ee,J),ee}return qe(new Array(J),J)}function ge(){var J=rt(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 Mp(b){return b.__=void 0,delete b.__,b}})})(Eb||(Eb={}))});var _n=Kp(Es=>{"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}},Fd="string",Y2=/^[0-9a-f\s]+$/i,J2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Q2=/^[a-zA-Z0-9-_]+$/,nf=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))}},cr=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}},of=class r{static isHex(e){return typeof e===Fd&&Y2.test(e)}static isBase64(e){return typeof e===Fd&&J2.test(e)}static isBase64Url(e){return typeof e===Fd&&Q2.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 cr.toString(n,!0);case"utf16":case"utf16be":return cr.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 cr.fromString(e,!0);case"utf16":case"utf16be":return cr.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 nf.fromString(e);case"utf16":case"utf16be":return cr.fromString(e);case"utf16le":case"usc2":return cr.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 nf.toString(e);case"utf16":case"utf16be":return cr.toString(e);case"utf16le":case"usc2":return cr.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 cr.toString(e,t)}static FromUtf16String(e,t=!1){return cr.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,"")||""}};of.DEFAULT_UTF8_ENCODING="utf8";function eC(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 tC(...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 rC(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}Es.BufferSourceConverter=vn;Es.Convert=of;Es.assign=eC;Es.combine=tC;Es.isEqual=rC});var xv=Kp((f$,Qf)=>{var ev,tv,rv,nv,ov,iv,sv,av,cv,Jf,Yy,uv,lv,ta,fv,pv,hv,dv,yv,mv,gv,wv,bv;(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 Qf=="object"&&typeof Qf.exports=="object"?r(t(e,t(Qf.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])};ev=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},tv=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},rv=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},nv=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},ov=function(t,n){return function(o,i){n(o,i,t)}},iv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},sv=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())})},av=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}}},bv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},cv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Jf=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.")},Yy=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},uv=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Yy(arguments[n]));return t},lv=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},ta=function(t){return this instanceof ta?(this.v=t,this):new ta(t)},fv=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 ta?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])}},pv=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:ta(t[s](c)),done:s==="return"}:a?a(c):c}:a}},hv=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 Jf=="function"?Jf(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)}},dv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},yv=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},mv=function(t){return t&&t.__esModule?t:{default:t}},gv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},wv=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",ev),r("__assign",tv),r("__rest",rv),r("__decorate",nv),r("__param",ov),r("__metadata",iv),r("__awaiter",sv),r("__generator",av),r("__exportStar",cv),r("__createBinding",bv),r("__values",Jf),r("__read",Yy),r("__spread",uv),r("__spreadArrays",lv),r("__await",ta),r("__asyncGenerator",fv),r("__asyncDelegator",pv),r("__asyncValues",hv),r("__makeTemplateObject",dv),r("__importStar",yv),r("__importDefault",mv),r("__classPrivateFieldGet",gv),r("__classPrivateFieldSet",wv)})});var iI={};_t(iI,{webRTC:()=>oI,webRTCDirect:()=>nI});var Hp=Symbol.for("@libp2p/peer-id");var ku=Symbol.for("@libp2p/transport");var dg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(dg||(dg={}));var Nu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},Du=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Te=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Xi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ma=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var ju=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Ru=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Oo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Po=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Lu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Uu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Mu=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Ku=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Hu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var $n=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Fn=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 Zi=Symbol.for("@libp2p/service-capabilities"),yg=Symbol.for("@libp2p/service-dependencies");var Gp={};_t(Gp,{base58btc:()=>De,base58flickr:()=>J_});var kI=new Uint8Array(0);function mg(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 fn(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 gg(r){return new TextEncoder().encode(r)}function wg(r){return new TextDecoder().decode(r)}function G_(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,V=j-1;(P!==0||M<d)&&V!==-1;V--,M++)P+=256*Z[V]>>>0,Z[V]=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 V=D-I;V!==D&&j[V]===0;)V++;for(var K=new Uint8Array(d+(D-V)),g=d;V!==D;)K[g++]=j[V++];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 q_=G_,z_=q_,xg=z_;var Vp=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")}},$p=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 vg(this,e)}},Fp=class{decoders;constructor(e){this.decoders=e}or(e){return vg(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 vg(r,e){return new Fp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Wp=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 Vp(e,t,n),this.decoder=new $p(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Yi({name:r,prefix:e,encode:t,decode:n}){return new Wp(r,e,t,n)}function Wn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=xg(t,r);return Yi({prefix:e,name:r,encode:n,decode:i=>fn(o(i))})}function X_(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 Z_(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 Y_(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function $e({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Y_(n);return Yi({prefix:e,name:r,encode(i){return Z_(i,n,t)},decode(i){return X_(i,o,t,r)}})}var De=Wn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),J_=Wn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qp={};_t(qp,{base32:()=>Gn,base32hex:()=>rS,base32hexpad:()=>oS,base32hexpadupper:()=>iS,base32hexupper:()=>nS,base32pad:()=>eS,base32padupper:()=>tS,base32upper:()=>Q_,base32z:()=>sS});var Gn=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Q_=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eS=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tS=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rS=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nS=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),oS=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),iS=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),sS=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zp={};_t(zp,{base36:()=>ga,base36upper:()=>aS});var ga=Wn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),aS=Wn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xr={};_t(xr,{Digest:()=>Bo,create:()=>St,decode:()=>es,equals:()=>Zp,hasCode:()=>CS});var cS=Ag,_g=128,uS=127,lS=~uS,fS=Math.pow(2,31);function Ag(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fS;)e[t++]=r&255|_g,r/=128;for(;r&lS;)e[t++]=r&255|_g,r>>>=7;return e[t]=r|0,Ag.bytes=t-n+1,e}var pS=Xp,hS=128,Sg=127;function Xp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Xp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Sg)<<o:(s&Sg)*Math.pow(2,o),o+=7}while(s>=hS);return Xp.bytes=i-n,t}var dS=Math.pow(2,7),yS=Math.pow(2,14),mS=Math.pow(2,21),gS=Math.pow(2,28),wS=Math.pow(2,35),bS=Math.pow(2,42),xS=Math.pow(2,49),vS=Math.pow(2,56),_S=Math.pow(2,63),SS=function(r){return r<dS?1:r<yS?2:r<mS?3:r<gS?4:r<wS?5:r<bS?6:r<xS?7:r<vS?8:r<_S?9:10},AS={encode:cS,decode:pS,encodingLength:SS},ES=AS,wa=ES;function ba(r,e=0){return[wa.decode(r,e),wa.decode.bytes]}function Ji(r,e,t=0){return wa.encode(r,e,t),e}function Qi(r){return wa.encodingLength(r)}function St(r,e){let t=e.byteLength,n=Qi(r),o=n+Qi(t),i=new Uint8Array(o+t);return Ji(r,i,0),Ji(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function es(r){let e=fn(r),[t,n]=ba(e),[o,i]=ba(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Zp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&mg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function CS(r,e){return r.code===e}function Eg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return IS(t,Yp(r),e??De.encoder);default:return OS(t,Yp(r),e??Gn.encoder)}}var Cg=new WeakMap;function Yp(r){let e=Cg.get(r);if(e==null){let t=new Map;return Cg.set(r,t),t}return e}var Xe=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!==xa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==PS)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=St(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&&Zp(e.multihash,n.multihash)}toString(e){return Eg(this,e)}toJSON(){return{"/":Eg(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??Tg(n,o,i.bytes))}else if(t[BS]===!0){let{version:n,multihash:o,code:i}=t,s=es(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!==xa)throw new Error(`Version 0 CID must use dag-pb (code: ${xa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Tg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,xa,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=fn(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 Bo(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]=ba(e.subarray(t));return t+=y,p},o=n(),i=xa;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]=TS(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 Yp(i).set(n,e),i}};function TS(r,e){switch(r[0]){case"Q":{let t=e??De;return[De.prefix,t.decode(`${De.prefix}${r}`)]}case De.prefix:{let t=e??De;return[De.prefix,t.decode(r)]}case Gn.prefix:{let t=e??Gn;return[Gn.prefix,t.decode(r)]}case ga.prefix:{let t=e??ga;return[ga.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 IS(r,e,t){let{prefix:n}=t;if(n!==De.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 OS(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 xa=112,PS=18;function Tg(r,e,t){let n=Qi(r),o=n+Qi(e),i=new Uint8Array(o+t.byteLength);return Ji(r,i,0),Ji(e,i,n),i.set(t,o),i}var BS=Symbol.for("@ipld/js-cid/CID");var Jp={};_t(Jp,{identity:()=>vr});var Ig=0,kS="identity",Og=fn;function NS(r){return St(Ig,Og(r))}var vr={code:Ig,name:kS,encode:Og,digest:NS};function Fe(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 nt(r=0){return new Uint8Array(r)}function ot(r=0){return new Uint8Array(r)}function Pt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ot(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Bg=Symbol.for("@achingbrain/uint8arraylist");function Pg(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 $u(r){return!!r?.[Bg]}var be=class r{bufs;length;[Bg]=!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($u(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($u(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=Pg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Pg(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($u(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 Pt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Pt(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(!$u(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=ot(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=nt(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=nt(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=nt(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=ot(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=nt(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=nt(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=nt(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=nt(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=nt(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(!Fe(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 Qp={};_t(Qp,{base10:()=>jS});var jS=Wn({prefix:"9",name:"base10",alphabet:"0123456789"});var eh={};_t(eh,{base16:()=>RS,base16upper:()=>LS});var RS=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),LS=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var th={};_t(th,{base2:()=>US});var US=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rh={};_t(rh,{base256emoji:()=>$S});var kg=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),MS=kg.reduce((r,e,t)=>(r[t]=e,r),[]),KS=kg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function HS(r){return r.reduce((e,t)=>(e+=MS[t],e),"")}function VS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=KS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var $S=Yi({prefix:"\u{1F680}",name:"base256emoji",encode:HS,decode:VS});var nh={};_t(nh,{base64:()=>FS,base64pad:()=>WS,base64url:()=>pn,base64urlpad:()=>GS});var FS=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),WS=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pn=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),GS=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oh={};_t(oh,{base8:()=>qS});var qS=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ih={};_t(ih,{identity:()=>zS});var zS=Yi({prefix:"\0",name:"identity",encode:r=>wg(r),decode:r=>gg(r)});var dO=new TextEncoder,yO=new TextDecoder;var ch={};_t(ch,{sha256:()=>ir,sha512:()=>YS});function ah({name:r,code:e,encode:t}){return new sh(r,e,t)}var sh=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?St(this.code,t):t.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Dg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ir=ah({name:"sha2-256",code:18,encode:Dg("SHA-256")}),YS=ah({name:"sha2-512",code:19,encode:Dg("SHA-512")});var ko={...ih,...th,...oh,...Qp,...eh,...qp,...zp,...Gp,...nh,...rh},TO={...ch,...Jp};function Rg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var jg=Rg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uh=Rg("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=ot(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),JS={utf8:jg,"utf-8":jg,hex:ko.base16,latin1:uh,ascii:uh,binary:uh,...ko},Fu=JS;function pe(r,e="utf8"){let t=Fu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function le(r,e="utf8"){let t=Fu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var QS=parseInt("11111",2),lh=parseInt("10000000",2),eA=parseInt("01111111",2),Lg={0:va,1:va,2:tA,3:oA,4:iA,5:nA,6:rA,16:va,22:va,48:va};function hn(r,e={offset:0}){let t=r[e.offset]&QS;if(e.offset++,Lg[t]!=null)return Lg[t](r,e);throw new Error("No decoder for tag "+t)}function _a(r,e){let t=0;if((r[e.offset]&lh)===lh){let n=r[e.offset]&eA,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 va(r,e){_a(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=hn(r,e);if(n===null)break;t.push(n)}return t}function tA(r,e){let t=_a(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 rA(r,e){let t=_a(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 nA(r,e){return e.offset++,null}function oA(r,e){let t=_a(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 iA(r,e){let t=_a(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function sA(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 Wu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=sA(r.byteLength);return new be(Uint8Array.from([e.byteLength|lh]),e)}function Bt(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]),Wu(e),e)}function Sa(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Wu(t),t)}function Ug(r){return new be(Uint8Array.from([4]),Wu(r),r)}function _r(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Wu(t),t)}async function Mg(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 Kg(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 Hg(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 aA=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),cA=Uint8Array.from([6,5,43,129,4,0,34]),uA=Uint8Array.from([6,5,43,129,4,0,35]),lA={ext:!0,kty:"EC",crv:"P-256"},fA={ext:!0,kty:"EC",crv:"P-384"},pA={ext:!0,kty:"EC",crv:"P-521"},fh=32,ph=48,hh=66;function dh(r){let e=hn(r);return Vg(e)}function Vg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===fh*2+1)return n=le(e.subarray(t,t+fh),"base64url"),o=le(e.subarray(t+fh),"base64url"),new No({...lA,key_ops:["verify"],x:n,y:o});if(e.byteLength===ph*2+1)return n=le(e.subarray(t,t+ph),"base64url"),o=le(e.subarray(t+ph),"base64url"),new No({...fA,key_ops:["verify"],x:n,y:o});if(e.byteLength===hh*2+1)return n=le(e.subarray(t,t+hh),"base64url"),o=le(e.subarray(t+hh),"base64url"),new No({...pA,key_ops:["verify"],x:n,y:o});throw new Te(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function $g(r){return _r([Bt(Uint8Array.from([1])),Ug(pe(r.d??"","base64url")),_r([Wg(r.crv)],160),_r([Sa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function Fg(r){return _r([Bt(Uint8Array.from([1])),_r([Wg(r.crv)],160),_r([Sa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function Wg(r){if(r==="P-256")return aA;if(r==="P-384")return cA;if(r==="P-521")return uA;throw new Te(`Invalid curve ${r}`)}async function Gg(r="P-256"){let e=await Mg(r);return new Gu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Fg(this.jwk)),this._raw}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async verify(e,t,n){return Hg(this.jwk,t,e,n)}},Gu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({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=$g(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async sign(e,t){return Kg(this.jwk,e,t)}};var Do=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function rs(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function jo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function At(r,...e){if(!rs(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 Aa(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");jo(r.outputLen),jo(r.blockLen)}function ns(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 zg(r,e){At(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Sr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function qu(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Ar(r,e){return r<<32-e|r>>>e}var Xg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hA=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function $r(r){if(At(r),Xg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=hA[r[t]];return e}var dn={_0:48,_9:57,A:65,F:70,a:97,f:102};function qg(r){if(r>=dn._0&&r<=dn._9)return r-dn._0;if(r>=dn.A&&r<=dn.F)return r-(dn.A-10);if(r>=dn.a&&r<=dn.f)return r-(dn.a-10)}function os(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Xg)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=qg(r.charCodeAt(i)),a=qg(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Zg(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function zn(r){return typeof r=="string"&&(r=Zg(r)),At(r),r}function Yt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];At(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 ts=class{};function yh(r){let e=n=>r().update(zn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ro(r=32){if(Do&&typeof Do.getRandomValues=="function")return Do.getRandomValues(new Uint8Array(r));if(Do&&typeof Do.randomBytes=="function")return Uint8Array.from(Do.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function dA(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 Yg(r,e,t){return r&e^~r&t}function Jg(r,e,t){return r&e^r&t^e&t}var Ea=class extends ts{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=qu(this.buffer)}update(e){ns(this),e=zn(e),At(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=qu(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){ns(this),zg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Sr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;dA(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=qu(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()}},yn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var zu=BigInt(4294967295),Qg=BigInt(32);function yA(r,e=!1){return e?{h:Number(r&zu),l:Number(r>>Qg&zu)}:{h:Number(r>>Qg&zu)|0,l:Number(r&zu)|0}}function e0(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}=yA(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var mh=(r,e,t)=>r>>>t,gh=(r,e,t)=>r<<32-t|e>>>t,Lo=(r,e,t)=>r>>>t|e<<32-t,Uo=(r,e,t)=>r<<32-t|e>>>t,Ca=(r,e,t)=>r<<64-t|e>>>t-32,Ta=(r,e,t)=>r>>>t-32|e<<64-t;function Fr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var t0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),r0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,n0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),o0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,i0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),s0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var gA=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]),Xn=new Uint32Array(64),Xu=class extends Ea{constructor(e=32){super(64,e,8,!1),this.A=yn[0]|0,this.B=yn[1]|0,this.C=yn[2]|0,this.D=yn[3]|0,this.E=yn[4]|0,this.F=yn[5]|0,this.G=yn[6]|0,this.H=yn[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)Xn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let y=Xn[p-15],m=Xn[p-2],x=Ar(y,7)^Ar(y,18)^y>>>3,v=Ar(m,17)^Ar(m,19)^m>>>10;Xn[p]=v+Xn[p-7]+x+Xn[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=Ar(a,6)^Ar(a,11)^Ar(a,25),m=f+y+Yg(a,c,l)+gA[p]+Xn[p]|0,v=(Ar(n,2)^Ar(n,13)^Ar(n,22))+Jg(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(){Sr(Xn)}destroy(){this.set(0,0,0,0,0,0,0,0),Sr(this.buffer)}};var a0=e0(["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))),wA=a0[0],bA=a0[1],Zn=new Uint32Array(80),Yn=new Uint32Array(80),wh=class extends Ea{constructor(e=64){super(128,e,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[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)Zn[j]=e.getUint32(t),Yn[j]=e.getUint32(t+=4);for(let j=16;j<80;j++){let Z=Zn[j-15]|0,P=Yn[j-15]|0,M=Lo(Z,P,1)^Lo(Z,P,8)^mh(Z,P,7),V=Uo(Z,P,1)^Uo(Z,P,8)^gh(Z,P,7),K=Zn[j-2]|0,g=Yn[j-2]|0,T=Lo(K,g,19)^Ca(K,g,61)^mh(K,g,6),E=Uo(K,g,19)^Ta(K,g,61)^gh(K,g,6),O=n0(V,E,Yn[j-7],Yn[j-16]),B=o0(O,M,T,Zn[j-7],Zn[j-16]);Zn[j]=B|0,Yn[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=Lo(p,y,14)^Lo(p,y,18)^Ca(p,y,41),P=Uo(p,y,14)^Uo(p,y,18)^Ta(p,y,41),M=p&m^~p&v,V=y&x^~y&d,K=i0(D,P,V,bA[j],Yn[j]),g=s0(K,I,Z,M,wA[j],Zn[j]),T=K|0,E=Lo(n,o,28)^Ca(n,o,34)^Ca(n,o,39),O=Uo(n,o,28)^Ta(n,o,34)^Ta(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}=Fr(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 N=t0(T,O,R);n=r0(N,g,E,B),o=N|0}({h:n,l:o}=Fr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Fr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Fr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=Fr(this.Dh|0,this.Dl|0,l|0,f|0),{h:p,l:y}=Fr(this.Eh|0,this.El|0,p|0,y|0),{h:m,l:x}=Fr(this.Fh|0,this.Fl|0,m|0,x|0),{h:v,l:d}=Fr(this.Gh|0,this.Gl|0,v|0,d|0),{h:I,l:D}=Fr(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(){Sr(Zn,Yn)}destroy(){Sr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Zu=yh(()=>new Xu);var c0=yh(()=>new wh);var vh=BigInt(0),xh=BigInt(1);function mn(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Ia(r){let e=r.toString(16);return e.length&1?"0"+e:e}function u0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?vh:BigInt("0x"+r)}function is(r){return u0($r(r))}function Wr(r){return At(r),u0($r(Uint8Array.from(r).reverse()))}function Yu(r,e){return os(r.toString(16).padStart(e*2,"0"))}function Jn(r,e){return Yu(r,e).reverse()}function ke(r,e,t){let n;if(typeof e=="string")try{n=os(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(rs(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 bh=r=>typeof r=="bigint"&&vh<=r;function l0(r,e,t){return bh(r)&&bh(e)&&bh(t)&&e<=r&&r<t}function Er(r,e,t,n){if(!l0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function f0(r){let e;for(e=0;r>vh;r>>=xh,e+=1);return e}var Mo=r=>(xh<<BigInt(r))-xh;function p0(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 Yt(...x)};return(m,x)=>{c(),f(m);let v;for(;!(v=x(p()));)f();return c(),v}}function Gr(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 kt=BigInt(0),at=BigInt(1),Ko=BigInt(2),xA=BigInt(3),y0=BigInt(4),m0=BigInt(5),g0=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 h0(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=at,s=at,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!==at)throw new Error("invert: does not exist");return je(o,e)}function w0(r,e){let t=(r.ORDER+at)/y0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function vA(r,e){let t=(r.ORDER-m0)/g0,n=r.mul(e,Ko),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Ko),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 _A(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Ko===kt;)e/=Ko,t++;let n=Ko,o=Cr(r);for(;d0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return w0;let i=o.pow(n,e),s=(e+at)/Ko;return function(c,l){if(c.is0(l))return l;if(d0(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=at<<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 SA(r){return r%y0===xA?w0:r%g0===m0?vA:_A(r)}var b0=(r,e)=>(je(r,e)&at)===at,AA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _h(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=AA.reduce((n,o)=>(n[o]="function",n),e);return Gr(r,t),r}function EA(r,e,t){if(t<kt)throw new Error("invalid exponent, negatives unsupported");if(t===kt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>kt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function Oa(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 d0(r,e){let t=(r.ORDER-at)/Ko,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&&jo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Cr(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}=x0(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:Mo(s),ZERO:kt,ONE:at,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&at)===at,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)=>EA(l,f,p),div:(f,p)=>je(f*h0(p,r),r),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>h0(f,r),sqrt:i||(f=>(c||(c=SA(r)),c(l,f))),toBytes:f=>t?Jn(f,a):Yu(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return t?Wr(f):is(f)},invertBatch:f=>Oa(l,f),cmov:(f,p,y)=>y?p:f});return Object.freeze(l)}function v0(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 Sh(r){let e=v0(r);return e+Math.ceil(e/2)}function _0(r,e,t=!1){let n=r.length,o=v0(e),i=Sh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Wr(r):is(r),a=je(s,e-at)+at;return t?Jn(a,o):Yu(a,o)}var cs=BigInt(0),Ho=BigInt(1);function as(r,e){let t=e.negate();return r?t:e}function Ju(r,e,t){let n=e==="pz"?s=>s.pz:s=>s.ez,o=Oa(r.Fp,t.map(n));return t.map((s,a)=>s.toAffine(o[a])).map(r.fromAffine)}function C0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Ah(r,e){C0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Mo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function S0(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+=Ho);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 CA(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 TA(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 Eh=new WeakMap,T0=new WeakMap;function Ch(r){return T0.get(r)||1}function A0(r){if(r!==cs)throw new Error("invalid wNAF")}function Qu(r,e){return{constTimeNegate:as,hasPrecomputes(t){return Ch(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>cs;)n&Ho&&(o=o.add(i)),i=i.double(),n>>=Ho;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=Ah(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=Ah(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:f,isZero:p,isNeg:y,isNegF:m,offsetF:x}=S0(o,c,a);o=l,p?s=s.add(as(m,n[x])):i=i.add(as(y,n[f]))}return A0(o),{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=Ah(t,e);for(let a=0;a<s.windows&&o!==cs;a++){let{nextN:c,offset:l,isZero:f,isNeg:p}=S0(o,a,s);if(o=c,!f){let y=n[l];i=i.add(p?y.negate():y)}}return A0(o),i},getPrecomputes(t,n,o){let i=Eh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof o=="function"&&(i=o(i)),Eh.set(n,i))),i},wNAFCached(t,n,o){let i=Ch(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=Ch(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){C0(n,e),T0.set(t,n),Eh.delete(t)}}}function I0(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>cs||n>cs;)t&Ho&&(i=i.add(o)),n&Ho&&(s=s.add(o)),o=o.double(),t>>=Ho,n>>=Ho;return{p1:i,p2:s}}function el(r,e,t,n){CA(t,r),TA(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=f0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Mo(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 E0(r,e){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _h(e),e}else return Cr(r)}function tl(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>cs))throw new Error(`CURVE.${a} must be positive bigint`)}let n=E0(e.p,t.Fp),o=E0(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 qr=BigInt(0),Nt=BigInt(1),Th=BigInt(2),IA=BigInt(8),OA={zip215:!0};function PA(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 BA(r,e={}){let{Fp:t,Fn:n}=tl("edwards",r,e),{h:o,n:i}=r;Gr(e,{},{uvRatio:"function"});let s=Th<<BigInt(n.BYTES*8)-Nt,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:qr}}});if(!PA(t,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(v,d,I=!1){let D=I?Nt:qr;return Er("coordinate "+v,d,D,s),d}function f(v){if(!(v instanceof m))throw new Error("ExtendedPoint expected")}let p=ss((v,d)=>{let{ex:I,ey:D,ez:j}=v,Z=v.is0();d==null&&(d=Z?IA:t.inv(j));let P=a(I*d),M=a(D*d),V=a(j*d);if(Z)return{x:qr,y:Nt};if(V!==Nt)throw new Error("invZ was invalid");return{x:P,y:M}}),y=ss(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),V=a(j*j),K=a(Z*Z),g=a(K*K),T=a(M*d),E=a(K*a(T+V)),O=a(g+a(I*a(M*V)));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,Nt,a(I*D))}static normalizeZ(d){return Ju(m,"ez",d)}static msm(d,I){return el(m,n,d,I)}_setWindowSize(d){this.precompute(d)}precompute(d=8,I=!0){return x.setWindowSize(this,d),I||this.multiply(Th),this}assertValidity(){y(this)}equals(d){f(d);let{ex:I,ey:D,ez:j}=this,{ex:Z,ey:P,ez:M}=d,V=a(I*M),K=a(Z*j),g=a(D*M),T=a(P*j);return V===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(Th*a(j*j)),V=a(d*Z),K=I+D,g=a(a(K*K)-Z-P),T=V+P,E=T-M,O=V-P,B=a(g*E),R=a(T*O),N=a(g*O),L=a(E*T);return new m(B,R,L,N)}add(d){f(d);let{a:I,d:D}=r,{ex:j,ey:Z,ez:P,et:M}=this,{ex:V,ey:K,ez:g,et:T}=d,E=a(j*V),O=a(Z*K),B=a(M*D*T),R=a(P*g),N=a((j+Z)*(V+K)-E-O),L=R-B,W=R+B,X=a(O-I*E),G=a(N*L),ie=a(W*X),Y=a(N*X),U=a(L*W);return new m(G,ie,U,Y)}subtract(d){return this.add(d.negate())}multiply(d){let I=d;Er("scalar",I,Nt,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 Er("scalar",D,qr,i),D===qr?m.ZERO:this.is0()||D===Nt?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===Nt?this:this.multiplyUnsafe(o)}static fromBytes(d,I=!1){return At(d),this.fromHex(d,I)}static fromHex(d,I=!1){let{d:D,a:j}=r,Z=t.BYTES;d=ke("pointHex",d,Z),mn("zip215",I);let P=d.slice(),M=d[Z-1];P[Z-1]=M&-129;let V=Wr(P),K=I?s:t.ORDER;Er("pointHex.y",V,qr,K);let g=a(V*V),T=a(g-Nt),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&Nt)===Nt,N=(M&128)!==0;if(!I&&B===qr&&N)throw new Error("Point.fromHex: x=0 and x_0=1");return N!==R&&(B=a(-B)),m.fromAffine({x:B,y:V})}static fromPrivateScalar(d){return m.BASE.multiply(d)}toBytes(){let{x:d,y:I}=this.toAffine(),D=Jn(I,t.BYTES);return D[D.length-1]|=d&Nt?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return $r(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}m.BASE=new m(r.Gx,r.Gy,Nt,a(r.Gx*r.Gy)),m.ZERO=new m(qr,Nt,Nt,qr),m.Fp=t,m.Fn=n;let x=Qu(m,n.BYTES*8);return m}function kA(r,e){Gr(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||Ro,l=e.adjustScalarBytes||(P=>P),f=e.domain||((P,M,V)=>{if(mn("phflag",V),M.length||V)throw new Error("Contexts/pre-hash are not supported");return P});function p(P){return s.create(P)}function y(P){return p(Wr(P))}function m(P){let M=i.BYTES;P=ke("private key",P,M);let V=ke("hashed private key",n(P),2*M),K=l(V.slice(0,M)),g=V.slice(M,2*M),T=y(K);return{head:K,prefix:g,scalar:T}}function x(P){let{head:M,prefix:V,scalar:K}=m(P),g=o.multiply(K),T=g.toBytes();return{head:M,prefix:V,scalar:K,point:g,pointBytes:T}}function v(P){return x(P).pointBytes}function d(P=Uint8Array.of(),...M){let V=Yt(...M);return y(n(f(V,ke("context",P),!!t)))}function I(P,M,V={}){P=ke("message",P),t&&(P=t(P));let{prefix:K,scalar:g,pointBytes:T}=x(M),E=d(V.context,K,P),O=o.multiply(E).toBytes(),B=d(V.context,O,T,P),R=p(E+B*g);Er("signature.s",R,qr,a);let N=i.BYTES,L=Yt(O,Jn(R,N));return ke("result",L,N*2)}let D=OA;function j(P,M,V,K=D){let{context:g,zip215:T}=K,E=i.BYTES;P=ke("signature",P,2*E),M=ke("message",M),V=ke("publicKey",V,E),T!==void 0&&mn("zip215",T),t&&(M=t(M));let O=Wr(P.slice(E,2*E)),B,R,N;try{B=r.fromHex(V,T),R=r.fromHex(P.slice(0,E),T),N=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(N).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 NA(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=Cr(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 DA(r,e){return Object.assign({},e,{ExtendedPoint:e.Point,CURVE:r})}function O0(r){let{CURVE:e,curveOpts:t,eddsaOpts:n}=NA(r),o=BA(e,t),i=kA(o,n);return DA(r,i)}var Pa=BigInt(0),us=BigInt(1),rl=BigInt(2);function jA(r){return Gr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function P0(r){let e=jA(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||Ro,l=a?255:448,f=a?32:56,p=BigInt(a?9:5),y=BigInt(a?121665:39081),m=a?rl**BigInt(254):rl**BigInt(447),x=a?BigInt(8)*rl**BigInt(251)-us:BigInt(4)*rl**BigInt(445)-us,v=m+x+us,d=g=>je(g,t),I=D(p);function D(g){return Jn(d(g),f)}function j(g){let T=ke("u coordinate",g,f);return a&&(T[31]&=127),d(Wr(T))}function Z(g){return Wr(o(ke("scalar",g,f)))}function P(g,T){let E=K(j(T),Z(g));if(E===Pa)throw new Error("invalid private or public key received");return D(E)}function M(g){return P(g,I)}function V(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){Er("u",g,Pa,t),Er("scalar",T,m,v);let E=T,O=g,B=us,R=Pa,N=g,L=us,W=Pa;for(let G=BigInt(l-1);G>=Pa;G--){let ie=E>>G&us;W^=ie,{x_2:B,x_3:N}=V(W,B,N),{x_2:R,x_3:L}=V(W,R,L),W=ie;let Y=B+R,U=d(Y*Y),he=B-R,Oe=d(he*he),se=U-Oe,Ne=N+L,vt=N-L,et=d(vt*Y),tt=d(Ne*he),ut=et+tt,or=et-tt;N=d(ut*ut),L=d(O*d(or*or)),B=d(U*Oe),R=d(se*(U+d(y*se)))}({x_2:B,x_3:N}=V(W,B,N)),{x_2:R,x_3:L}=V(W,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 NP=BigInt(0),RA=BigInt(1),B0=BigInt(2),LA=BigInt(3),UA=BigInt(5),MA=BigInt(8),Ba={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:MA,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function N0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Ba.p,a=r*r%i*r%i,c=Me(a,B0,i)*a%i,l=Me(c,RA,i)*r%i,f=Me(l,UA,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,B0,i)*r%i,b2:a}}function D0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var k0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function KA(r,e){let t=Ba.p,n=je(e*e*e,t),o=je(n*n*e,t),i=N0(r*o).pow_p_5_8,s=je(r*n*i,t),a=je(e*s*s,t),c=s,l=je(s*k0,t),f=a===r,p=a===je(-r,t),y=a===je(-r*k0,t);return f&&(s=c),(p||y)&&(s=l),b0(s,t)&&(s=je(-s,t)),{isValid:f||p,value:s}}var HA=Cr(Ba.p,void 0,!0),VA={...Ba,Fp:HA,hash:c0,adjustScalarBytes:D0,uvRatio:KA},ka=O0(VA);var Na=(()=>{let r=Ba.p;return P0({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=N0(e);return je(Me(t,LA,r)*n,r)},adjustScalarBytes:D0})})();var Da=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},ja=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},nl=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var j0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new nl("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 Lt=j0;var ol=32,Ra=64,Ih=32;var ls,R0=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function L0(){let r=ka.utils.randomPrivateKey(),e=ka.getPublicKey(r);return{privateKey:qA(r,e),publicKey:e}}async function $A(r,e){let t;r.length===Ra?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 Lt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Lt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function FA(r,e){let t=r.subarray(0,Ih);return ka.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function U0(r,e){return ls==null&&(ls=await R0),ls?$A(r,e):FA(r,e)}async function WA(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.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 GA(r,e,t){return ka.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function M0(r,e,t){return ls==null&&(ls=await R0),ls?WA(r,e,t):GA(r,e,t)}function qA(r,e){let t=new Uint8Array(Ra);for(let n=0;n<Ih;n++)t[n]=r[n],t[Ih+n]=e[n];return t}function fs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var La=class{type="Ed25519";raw;constructor(e){this.raw=sl(e,ol)}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=M0(this.raw,t,e);return fs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},il=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=sl(e,Ra),this.publicKey=new La(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=U0(this.raw,e);return fs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Oh(r){return r=sl(r,ol),new La(r)}async function H0(){let{privateKey:r,publicKey:e}=L0();return new il(r,e)}function sl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Te(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var zA=Math.pow(2,7),XA=Math.pow(2,14),ZA=Math.pow(2,21),Ph=Math.pow(2,28),Bh=Math.pow(2,35),kh=Math.pow(2,42),Nh=Math.pow(2,49),Ce=128,Et=127;function He(r){if(r<zA)return 1;if(r<XA)return 2;if(r<ZA)return 3;if(r<Ph)return 4;if(r<Bh)return 5;if(r<kh)return 6;if(r<Nh)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(He(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 YA(r,e,t=0){switch(He(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 Dh(r,e){let t=r[e],n=0;if(n+=t&Et,t<Ce||(t=r[e+1],n+=(t&Et)<<7,t<Ce)||(t=r[e+2],n+=(t&Et)<<14,t<Ce)||(t=r[e+3],n+=(t&Et)<<21,t<Ce)||(t=r[e+4],n+=(t&Et)*Ph,t<Ce)||(t=r[e+5],n+=(t&Et)*Bh,t<Ce)||(t=r[e+6],n+=(t&Et)*kh,t<Ce)||(t=r[e+7],n+=(t&Et)*Nh,t<Ce))return n;throw new RangeError("Could not decode varint")}function JA(r,e){let t=r.get(e),n=0;if(n+=t&Et,t<Ce||(t=r.get(e+1),n+=(t&Et)<<7,t<Ce)||(t=r.get(e+2),n+=(t&Et)<<14,t<Ce)||(t=r.get(e+3),n+=(t&Et)<<21,t<Ce)||(t=r.get(e+4),n+=(t&Et)*Ph,t<Ce)||(t=r.get(e+5),n+=(t&Et)*Bh,t<Ce)||(t=r.get(e+6),n+=(t&Et)*kh,t<Ce)||(t=r.get(e+7),n+=(t&Et)*Nh,t<Ce))return n;throw new RangeError("Could not decode varint")}function al(r,e,t=0){return e==null&&(e=ot(He(r))),e instanceof Uint8Array?ps(r,e,t):YA(r,e,t)}function Vo(r,e=0){return r instanceof Uint8Array?Dh(r,e):JA(r,e)}var jh=new Float32Array([-0]),Qn=new Uint8Array(jh.buffer);function V0(r,e,t){jh[0]=r,e[t]=Qn[0],e[t+1]=Qn[1],e[t+2]=Qn[2],e[t+3]=Qn[3]}function $0(r,e){return Qn[0]=r[e],Qn[1]=r[e+1],Qn[2]=r[e+2],Qn[3]=r[e+3],jh[0]}var Rh=new Float64Array([-0]),Ct=new Uint8Array(Rh.buffer);function F0(r,e,t){Rh[0]=r,e[t]=Ct[0],e[t+1]=Ct[1],e[t+2]=Ct[2],e[t+3]=Ct[3],e[t+4]=Ct[4],e[t+5]=Ct[5],e[t+6]=Ct[6],e[t+7]=Ct[7]}function W0(r,e){return Ct[0]=r[e],Ct[1]=r[e+1],Ct[2]=r[e+2],Ct[3]=r[e+3],Ct[4]=r[e+4],Ct[5]=r[e+5],Ct[6]=r[e+6],Ct[7]=r[e+7],Rh[0]}var QA=BigInt(Number.MAX_SAFE_INTEGER),eE=BigInt(Number.MIN_SAFE_INTEGER),Jt=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 $o;if(e<QA&&e>eE)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>G0&&(o=0n,++n>G0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return $o;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):$o}},$o=new Jt(0,0);$o.toBigInt=function(){return 0n};$o.zzEncode=$o.zzDecode=function(){return this};$o.length=function(){return 1};var G0=4294967296n;function q0(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 z0(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 Lh(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 Tr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ul(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Uh=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,Tr(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 Tr(this,4);return ul(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tr(this,4);return ul(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tr(this,4);let e=$0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Tr(this,4);let e=W0(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 Tr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return z0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Tr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Tr(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 Jt(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 Tr(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 Tr(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 Tr(this,8);let e=ul(this.buf,this.pos+=4),t=ul(this.buf,this.pos+=4);return new Jt(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=Dh(this.buf,this.pos);return this.pos+=He(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 Mh(r){return new Uh(r instanceof Uint8Array?r:r.subarray())}function Ir(r,e,t){let n=Mh(r);return e.decode(n,void 0,t)}function Kh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ot(s);o+s>e&&(n=ot(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Fo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Hh(){}var $h=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},tE=Kh();function rE(r){return globalThis.Buffer!=null?ot(r):tE(r)}var Ma=class{len;head;tail;states;constructor(){this.len=0,this.head=new Fo(Hh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Fo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fh((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(ll,10,Jt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Jt.fromBigInt(e);return this._push(ll,t.length(),t)}uint64Number(e){return this._push(ps,He(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=Jt.fromBigInt(e).zzEncode();return this._push(ll,t.length(),t)}sint64Number(e){let t=Jt.fromNumber(e).zzEncode();return this._push(ll,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vh,1,e?1:0)}fixed32(e){return this._push(Ua,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Jt.fromBigInt(e);return this._push(Ua,4,t.lo)._push(Ua,4,t.hi)}fixed64Number(e){let t=Jt.fromNumber(e);return this._push(Ua,4,t.lo)._push(Ua,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(V0,4,e)}double(e){return this._push(F0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Vh,1,0):this.uint32(t)._push(oE,t,e)}string(e){let t=q0(e);return t!==0?this.uint32(t)._push(Lh,t,e):this._push(Vh,1,0)}fork(){return this.states=new $h(this),this.head=this.tail=new Fo(Hh,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 Fo(Hh,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=rE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Vh(r,e,t){e[t]=r&255}function nE(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Fh=class extends Fo{next;constructor(e,t){super(nE,e,t),this.next=void 0}};function ll(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 Ua(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 oE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Ma.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(iE,e,r),this},Ma.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(sE,e,r),this});function iE(r,e,t){e.set(r,t)}function sE(r,e,t){r.length<40?Lh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(pe(r),t)}function Wh(){return new Ma}function Or(r,e){let t=Wh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var hs;(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"})(hs||(hs={}));function fl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Wo(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 fl("enum",hs.VARINT,t,n)}function Pr(r,e){return fl("message",hs.LENGTH_DELIMITED,r,e)}var Ka=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ze;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ze||(Ze={}));var Gh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Gh||(Gh={}));(function(r){r.codec=()=>Wo(Gh)})(Ze||(Ze={}));var zr;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ze.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=Ze.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(zr||(zr={}));var qh;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ze.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=Ze.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(qh||(qh={}));var Va={};_t(Va,{MAX_RSA_KEY_SIZE:()=>zh,generateRSAKeyPair:()=>nd,jwkToJWKKeyPair:()=>ew,jwkToPkcs1:()=>lE,jwkToPkix:()=>Jh,jwkToRSAPrivateKey:()=>rd,pkcs1MessageToJwk:()=>Zh,pkcs1MessageToRSAPrivateKey:()=>Qh,pkcs1ToJwk:()=>uE,pkcs1ToRSAPrivateKey:()=>Q0,pkixMessageToJwk:()=>Yh,pkixMessageToRSAPublicKey:()=>td,pkixToJwk:()=>fE,pkixToRSAPublicKey:()=>ed});var eo=Zu;var ds=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=Va.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Xe.createV1(114,this._multihash)}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return J0(this.jwk,t,e,n)}},Ha=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Va.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return Y0(this.jwk,e,t)}};var zh=8192,Xh=18,aE=1062,cE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function uE(r){let e=hn(r);return Zh(e)}function Zh(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 lE(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 Te("JWK was missing components");return _r([Bt(Uint8Array.from([0])),Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url")),Bt(pe(r.d,"base64url")),Bt(pe(r.p,"base64url")),Bt(pe(r.q,"base64url")),Bt(pe(r.dp,"base64url")),Bt(pe(r.dq,"base64url")),Bt(pe(r.qi,"base64url"))]).subarray()}function fE(r){let e=hn(r,{offset:0});return Yh(e)}function Yh(r){let e=hn(r[1],{offset:0});return{kty:"RSA",n:le(e[0],"base64url"),e:le(e[1],"base64url")}}function Jh(r){if(r.n==null||r.e==null)throw new Te("JWK was missing components");return _r([cE,Sa(_r([Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url"))]))]).subarray()}function Q0(r){let e=hn(r);return Qh(e)}function Qh(r){let e=Zh(r);return rd(e)}function ed(r,e){if(r.byteLength>=aE)throw new Xi("Key size is too large");let t=hn(r,{offset:0});return td(t,r,e)}function td(r,e,t){let n=Yh(r);if(t==null){let o=eo(zr.encode({Type:Ze.RSA,Data:e}));t=St(Xh,o)}return new ds(n,t)}function rd(r){if(rw(r)>zh)throw new Te("Key size is too large");let e=ew(r),t=eo(zr.encode({Type:Ze.RSA,Data:Jh(e.publicKey)})),n=St(Xh,t);return new Ha(e.privateKey,new ds(e.publicKey,n))}async function nd(r){if(r>zh)throw new Te("Key size is too large");let e=await tw(r),t=eo(zr.encode({Type:Ze.RSA,Data:Jh(e.publicKey)})),n=St(Xh,t);return new Ha(e.privateKey,new ds(e.publicKey,n))}function ew(r){if(r==null)throw new Te("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function tw(r,e){let t=await Lt.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 pE(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Y0(r,e,t){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Lt.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 J0(r,e,t,n){let o=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function pE(r,e){if(r.privateKey==null||r.publicKey==null)throw new Te("Private and public key are required");let t=await Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function rw(r){if(r.kty!=="RSA")throw new Te("invalid key type");if(r.n==null)throw new Te("invalid key modulus");return pe(r.n,"base64url").length*8}var pl=class extends ts{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Aa(e);let n=zn(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),Sr(i)}update(e){return ns(this),this.iHash.update(e),this}digestInto(e){ns(this),At(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()}},ys=(r,e,t)=>new pl(r,e).update(t).digest();ys.create=(r,e)=>new pl(r,e);function nw(r){r.lowS!==void 0&&mn("lowS",r.lowS),r.prehash!==void 0&&mn("prehash",r.prehash)}var od=class extends Error{constructor(e=""){super(e)}},gn={Err:od,_tlv:{encode:(r,e)=>{let{Err:t}=gn;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=Ia(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Ia(o.length/2|128):"";return Ia(r)+i+o+e},decode(r,e){let{Err:t}=gn,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}=gn;if(r<$a)throw new e("integer: negative integers are not allowed");let t=Ia(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}=gn;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 is(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=gn,o=ke("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}=gn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},$a=BigInt(0),Fa=BigInt(1),hE=BigInt(2),hl=BigInt(3),dE=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 ow(r,e,t){let{BYTES:n}=r;function o(i){let s;if(typeof i=="bigint")s=i;else{let a=ke("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 mE(r,e={}){let{Fp:t,Fn:n}=tl("weierstrass",r,e),{h:o,n:i}=r;Gr(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(mn("isCompressed",T),T){a();let R=!t.isOdd(O);return Yt(iw(R),B)}else return Yt(Uint8Array.of(4),B,t.toBytes(O))}function l(K){At(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 N=t.fromBytes(R);if(!t.isValid(N))throw new Error("bad point: is not on curve, wrong x");let L=y(N),W;try{W=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(W);return(B&1)===1!==X&&(W=t.neg(W)),{x:N,y:W}}else if(O===E&&B===4){let N=t.fromBytes(R.subarray(g*0,g*1)),L=t.fromBytes(R.subarray(g*1,g*2));if(!m(N,L))throw new Error("bad point: is not on curve");return{x:N,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=yE(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,hl),dE),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=ss((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),N=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:N}}),j=ss(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=as(E,g),T=as(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 Ju(P,"pz",g)}static fromBytes(g){return At(g),P.fromHex(g)}static fromHex(g){let T=P.fromAffine(p(ke("pointHex",g)));return T.assertValidity(),T}static fromPrivateKey(g){let T=ow(n,e.allowedPrivateKeyLengths,e.wrapPrivateKey);return P.BASE.multiply(T(g))}static msm(g,T){return el(P,n,g,T)}precompute(g=8,T=!0){return V.setWindowSize(this,g),T||this.multiply(hl),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:N}=g,L=t.eql(t.mul(T,N),t.mul(B,O)),W=t.eql(t.mul(E,N),t.mul(R,O));return L&&W}negate(){return new P(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:T}=r,E=t.mul(T,hl),{px:O,py:B,pz:R}=this,N=t.ZERO,L=t.ZERO,W=t.ZERO,X=t.mul(O,O),G=t.mul(B,B),ie=t.mul(R,R),Y=t.mul(O,B);return Y=t.add(Y,Y),W=t.mul(O,R),W=t.add(W,W),N=t.mul(g,W),L=t.mul(E,ie),L=t.add(N,L),N=t.sub(G,L),L=t.add(G,L),L=t.mul(N,L),N=t.mul(Y,N),W=t.mul(E,W),ie=t.mul(g,ie),Y=t.sub(X,ie),Y=t.mul(g,Y),Y=t.add(Y,W),W=t.add(X,X),X=t.add(W,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),N=t.sub(N,X),W=t.mul(ie,G),W=t.add(W,W),W=t.add(W,W),new P(N,L,W)}add(g){I(g);let{px:T,py:E,pz:O}=this,{px:B,py:R,pz:N}=g,L=t.ZERO,W=t.ZERO,X=t.ZERO,G=r.a,ie=t.mul(r.b,hl),Y=t.mul(T,B),U=t.mul(E,R),he=t.mul(O,N),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 Ne=t.add(B,N);return se=t.mul(se,Ne),Ne=t.add(Y,he),se=t.sub(se,Ne),Ne=t.add(E,O),L=t.add(R,N),Ne=t.mul(Ne,L),L=t.add(U,he),Ne=t.sub(Ne,L),X=t.mul(G,se),L=t.mul(ie,he),X=t.add(L,X),L=t.sub(U,X),X=t.add(U,X),W=t.mul(L,X),U=t.add(Y,Y),U=t.add(U,Y),he=t.mul(G,he),se=t.mul(ie,se),U=t.add(U,he),he=t.sub(Y,he),he=t.mul(G,he),se=t.add(se,he),Y=t.mul(U,se),W=t.add(W,Y),Y=t.mul(Ne,se),L=t.mul(Oe,L),L=t.sub(L,Y),Y=t.mul(Oe,U),X=t.mul(Ne,X),X=t.add(X,Y),new P(L,W,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=>V.wNAFCached(this,R,P.normalizeZ);if(T){let{k1neg:R,k1:N,k2neg:L,k2:W}=T.splitScalar(g),{p:X,f:G}=B(N),{p:ie,f:Y}=B(W);O=G.add(Y),E=Z(T.beta,X,ie,R,L)}else{let{p:R,f:N}=B(g);E=R,O=N}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===$a||E.is0())return P.ZERO;if(g===Fa)return E;if(V.hasPrecomputes(this))return this.multiply(g);if(T){let{k1neg:O,k1:B,k2neg:R,k2:N}=T.splitScalar(g),{p1:L,p2:W}=I0(P,E,B,N);return Z(T.beta,L,W,O,R)}else return V.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===Fa?!0:g?g(P,this):V.wNAFCachedUnsafe(this,i).is0()}clearCofactor(){let{clearCofactor:g}=e;return o===Fa?this:g?g(P,this):this.multiplyUnsafe(o)}toBytes(g=!0){return mn("isCompressed",g),this.assertValidity(),f(P,this,g)}toRawBytes(g=!0){return this.toBytes(g)}toHex(g=!0){return $r(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,V=Qu(P,e.endo?Math.ceil(M/2):M);return P}function iw(r){return Uint8Array.of(r?2:3)}function gE(r,e,t={}){Gr(e,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Ro,o=e.hmac||((E,...O)=>ys(e.hash,E,Yt(...O))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s;function l(E){let O=a>>Fa;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=ke("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}=gn.toSig(ke("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:N,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*hE<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 G=i.toBytes(X),ie=r.fromHex(Yt(iw((L&1)===0),G)),Y=s.inv(X),U=j(ke("msgHash",O)),he=s.create(-U*Y),Oe=s.create(N*Y),se=r.BASE.multiplyUnsafe(he).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 Yt(s.toBytes(this.r),s.toBytes(this.s));if(O==="der")return os(gn.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return $r(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return $r(this.toBytes("compact"))}}let m=ow(s,t.allowedPrivateKeyLengths,t.wrapPrivateKey),x={isValidPrivateKey(E){try{return m(E),!0}catch{return!1}},normPrivateKeyToScalar:m,randomPrivateKey:()=>{let E=a;return _0(n(Sh(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=ke("key",E).length,R=i.BYTES,N=R+1,L=2*R+1;if(!(t.allowedPrivateKeyLengths||s.BYTES===N))return B===N||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=is(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=Mo(c);function P(E){return Er("num < 2^"+c,E,$a,Z),s.toBytes(E)}function M(E,O,B=V){if(["recovered","canonical"].some(Oe=>Oe in B))throw new Error("sign() legacy options not supported");let{hash:R}=e,{lowS:N,prehash:L,extraEntropy:W}=B;N==null&&(N=!0),E=ke("msgHash",E),nw(B),L&&(E=ke("prehashed msgHash",R(E)));let X=j(E),G=m(O),ie=[P(G),P(X)];if(W!=null&&W!==!1){let Oe=W===!0?n(i.BYTES):W;ie.push(ke("extraEntropy",Oe))}let Y=Yt(...ie),U=X;function he(Oe){let se=D(Oe);if(!s.isValidNot0(se))return;let Ne=s.inv(se),vt=r.BASE.multiply(se).toAffine(),et=s.create(vt.x);if(et===$a)return;let tt=s.create(Ne*s.create(U+et*G));if(tt===$a)return;let ut=(vt.x===et?0:2)|Number(vt.y&Fa),or=tt;return N&&l(tt)&&(or=f(tt),ut^=1),new y(et,or,ut)}return{seed:Y,k2sig:he}}let V={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function g(E,O,B=V){let{seed:R,k2sig:N}=M(E,O,B);return p0(e.hash.outputLen,s.BYTES,o)(R,N)}r.BASE.precompute(8);function T(E,O,B,R=K){let N=E;O=ke("msgHash",O),B=ke("publicKey",B),nw(R);let{lowS:L,prehash:W,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 G=typeof N=="string"||rs(N),ie=!G&&!X&&typeof N=="object"&&N!==null&&typeof N.r=="bigint"&&typeof N.s=="bigint";if(!G&&!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(N.r,N.s);else throw new Error("invalid format");if(G){try{X!=="compact"&&(Y=y.fromDER(N))}catch(or){if(!(or instanceof gn.Err))throw or}!Y&&X!=="der"&&(Y=y.fromCompact(N))}U=r.fromHex(B)}catch{return!1}if(!Y||L&&Y.hasHighS())return!1;W&&(O=e.hash(O));let{r:he,s:Oe}=Y,se=j(O),Ne=s.inv(Oe),vt=s.create(se*Ne),et=s.create(he*Ne),tt=r.BASE.multiplyUnsafe(vt).add(U.multiplyUnsafe(et));return tt.is0()?!1:s.create(tt.x)===he}return Object.freeze({getPublicKey:v,getSharedSecret:I,sign:g,verify:T,utils:x,Point:r,Signature:y})}function wE(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=Cr(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 bE(r){let{CURVE:e,curveOpts:t}=wE(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 xE(r,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:r})}function sw(r){let{CURVE:e,curveOpts:t,ecdsaOpts:n}=bE(r),o=mE(e,t),i=gE(o,n,t);return xE(r,i)}function aw(r,e){let t=n=>sw({...r,hash:n});return{...t(e),create:t}}var dl={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},m8=BigInt(0),vE=BigInt(1),id=BigInt(2),cw=(r,e)=>(r+e/id)/e;function _E(r){let e=dl.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,id,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,id,e);if(!sd.eql(sd.sqr(M),r))throw new Error("Cannot find square root");return M}var sd=Cr(dl.p,void 0,void 0,{sqrt:_E}),Br=aw({...dl,Fp:sd,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=dl.n,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-vE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=cw(i*r,e),c=cw(-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}}}},Zu);function uw(r,e,t){let n=ir.digest(e instanceof Uint8Array?e:e.subarray());if(fs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Br.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Da(String(o))});try{return Br.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Da(String(o))}}function lw(r,e,t,n){let o=ir.digest(t instanceof Uint8Array?t:t.subarray());if(fs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Br.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new ja(String(i))});try{return n?.signal?.throwIfAborted(),Br.verify(e,o.digest,r)}catch(i){throw new ja(String(i))}}var Wa=class{type="secp256k1";raw;_key;constructor(e){this._key=hw(e),this.raw=fw(this._key)}toMultihash(){return vr.digest(qn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t,n){return lw(this._key,t,e,n)}},yl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=pw(e),this.publicKey=new Wa(t??dw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e,t){return uw(this.raw,e,t)}};function ad(r){return new Wa(r)}async function yw(){let r=SE();return new yl(r)}function fw(r){return Br.ProjectivePoint.fromHex(r).toRawBytes(!0)}function pw(r){try{return Br.getPublicKey(r,!0),r}catch(e){throw new ma(String(e))}}function hw(r){try{return Br.ProjectivePoint.fromHex(r),r}catch(e){throw new Xi(String(e))}}function dw(r){try{return Br.getPublicKey(r,!0)}catch(e){throw new ma(String(e))}}function SE(){return Br.utils.randomPrivateKey()}async function mw(r,e){if(r==="Ed25519")return H0();if(r==="secp256k1")return yw();if(r==="RSA")return nd(AE(e));if(r==="ECDSA")return Gg(EE(e));throw new $n}function Ga(r,e){let{Type:t,Data:n}=zr.decode(r),o=n??new Uint8Array;switch(t){case Ze.RSA:return ed(o,e);case Ze.Ed25519:return Oh(o);case Ze.secp256k1:return ad(o);case Ze.ECDSA:return dh(o);default:throw new $n}}function gw(r){let{Type:e,Data:t}=zr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ze.Ed25519:return Oh(n);case Ze.secp256k1:return ad(n);case Ze.ECDSA:return dh(n);default:throw new $n}}function qn(r){return zr.encode({Type:Ze[r.type],Data:r.raw})}function AE(r){return r==null?2048:parseInt(r,10)}function EE(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 Te("Unsupported curve, should be P-256, P-384 or P-521")}async function ml(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 Te("Only RSA and ECDSA keys are supported")}var ww=Symbol.for("nodejs.util.inspect.custom"),CE=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()})`}[Hp]=!0;toString(){return this.string==null&&(this.string=De.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Xe.createV1(CE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ww](){return`PeerId(${this.toString()})`}},za=class extends qa{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xa=class extends qa{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Za=class extends qa{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},TE=2336,Ya=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=vr.digest(pe(this.url))}[ww](){return`PeerId(${this.url})`}[Hp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Xe.createV1(TE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=le(e)),e.toString()===this.toString())}};var IE=114,bw=2336;function gl(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=es(De.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return OE(Xe.parse(r));if(e==null)throw new Te('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=es(e.decode(r))}return xw(t)}function cd(r){if(r.type==="Ed25519")return new Xa({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Za({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new za({multihash:r.toCID().multihash,publicKey:r});throw new $n}function xw(r){if(BE(r))return new za({multihash:r});if(PE(r))try{let e=gw(r);if(e.type==="Ed25519")return new Xa({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Za({multihash:r,publicKey:e})}catch{let t=le(r.digest);return new Ya(new URL(t))}throw new Uu("Supplied PeerID Multihash is invalid")}function OE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==IE&&r.code!==bw)throw new Lu("Supplied PeerID CID is invalid");if(r.code===bw){let e=le(r.multihash.digest);return new Ya(new URL(e))}return xw(r.multihash)}function PE(r){return r.code===vr.code}function BE(r){return r.code===ir.code}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},wn=class extends Error{static name="ValidationError";name="ValidationError"},Ja=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},wl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var bl=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 kE=45,NE=15,xl=new bl;function ud(r){if(!(r.length>NE))return xl.new(r).parseWith(()=>xl.readIPv4Addr())}function ld(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>kE))return xl.new(r).parseWith(()=>xl.readIPv6Addr())}function ms(r){return!!ud(r)}function vl(r){return!!ld(r)}function pd(r){return e=>le(e,r)}function hd(r){return e=>pe(e,r)}function gs(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Go(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function _w(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=pe(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=Go(n);return Pt([t,o],t.length+o.length)}function Sw(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=Gn.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=Go(n);return Pt([t,o],t.length+o.length)}function dd(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=le(e,"base32"),o=gs(t);return`${n}:${o}`}var yd=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 ft("Invalid byte value in IP address");e[n]=o}),e},Aw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=ms(t[n]),s;i&&(s=yd(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 ft("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Ew=function(r){if(r.byteLength!==4)throw new ft("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Cw=function(r){if(r.byteLength!==16)throw new ft("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 ft(`Invalid IPv6 address "${t}"`)}};function Tw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}}var fd=Object.values(ko).map(r=>r.decoder),DE=function(){let r=fd[0].or(fd[1]);return fd.slice(2).forEach(e=>r=r.or(e)),r}();function Iw(r){return DE.decode(r)}function Ow(r){return e=>r.encoder.encode(e)}function jE(r){if(parseInt(r).toString()!==r)throw new wn("Value must be an integer")}function RE(r){if(r<0)throw new wn("Value must be a positive integer, or zero")}function LE(r){return e=>{if(e>r)throw new wn(`Value must be smaller than or equal to ${r}`)}}function UE(...r){return e=>{for(let t of r)t(e)}}var Qa=UE(jE,RE,LE(65535));var ct=-1,md=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 wl(`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)}))}},Qt=new md,d2=[{code:4,name:"ip4",size:32,valueToBytes:yd,bytesToValue:Ew,validate:r=>{if(!ms(r))throw new wn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Go,bytesToValue:gs,validate:Qa},{code:273,name:"udp",size:16,valueToBytes:Go,bytesToValue:gs,validate:Qa},{code:33,name:"dccp",size:16,valueToBytes:Go,bytesToValue:gs,validate:Qa},{code:41,name:"ip6",size:128,valueToBytes:Aw,bytesToValue:Cw,stringToValue:Tw,validate:r=>{if(!vl(r))throw new wn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:pd("base10"),valueToBytes:hd("base10")},{code:53,name:"dns",size:ct,resolvable:!0},{code:54,name:"dns4",size:ct,resolvable:!0},{code:55,name:"dns6",size:ct,resolvable:!0},{code:56,name:"dnsaddr",size:ct,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:Go,bytesToValue:gs,validate:Qa},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:pd("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?hd("base58btc")(r):Xe.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:dd,valueToBytes:_w},{code:445,name:"onion3",size:296,bytesToValue:dd,valueToBytes:Sw},{code:446,name:"garlic64",size:ct},{code:447,name:"garlic32",size:ct},{code:448,name:"tls"},{code:449,name:"sni",size:ct},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ct,bytesToValue:Ow(pn),valueToBytes:Iw},{code:480,name:"http"},{code:481,name:"http-path",size:ct,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:ct}];d2.forEach(r=>{Qt.addProtocol(r)});function Pw(r){let e=[],t=0;for(;t<r.length;){let n=Vo(r,t),o=Qt.getProtocol(n),i=He(n),s=y2(o,r,t+i),a=0;s>0&&o.size===ct&&(a=He(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 Bw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=Qt.getProtocol(n.code),i=He(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??pe(n.value),a=s.byteLength,o.size===ct&&(c=He(a)));let l=new Uint8Array(i+c+a),f=0;ps(n.code,l,f),f+=i,s!=null&&(o.size===ct&&(ps(a,l,f),f+=c),l.set(s,f)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Pt(t,e)}function kw(r){if(r.charAt(0)!=="/")throw new ft('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=Qt.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 ft(`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 ft(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return e}function Nw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=Qt.getProtocol(e.code);if(t==null)throw new ft(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function y2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Vo(e,t)}var m2=Symbol.for("nodejs.util.inspect.custom"),Ad=Symbol.for("@multiformats/multiaddr"),g2=[53,54,55,56],Sd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function w2(r){if(r==null&&(r="/"),jw(r))return r.getComponents();if(r instanceof Uint8Array)return Pw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),kw(r);if(Array.isArray(r))return r;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Cl=class r{[Ad]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=w2(e),t.validate!==!1&&b2(this)}get bytes(){return this.#r==null&&(this.#r=Bw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Nw(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??""}`),g2.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=Qt.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=Qt.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??pe(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 Ja(`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(De.decode(`z${n}`),"base58btc"):le(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(Qt.getProtocol(e.code).path)return e.value??null;return null}equals(e){return Fe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Dw.get(t.name);if(n==null)throw new Sd(`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)}[m2](){return`Multiaddr(${this.toString()})`}};function b2(r){r.getComponents().forEach(e=>{let t=Qt.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var n5=parseInt("0xFFFF",16),o5=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Dw=new Map;function jw(r){return!!r?.[Ad]}function bn(r){return new Cl(r)}var A2=r=>r.toString().split("/").slice(1),ws=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>ws(t=>t===r).match(e),pattern:r}),qo=()=>({match:r=>ws(e=>typeof e=="string").match(r),pattern:"{string}"}),bs=()=>({match:r=>ws(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ie=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{De.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),tc=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{pn.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ae=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Tt=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),xe=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function Re(...r){function e(o){let i=A2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var E2=Ie(),z5=Re(E2),Il=xe(ye("dns4"),qo()),Ol=xe(ye("dns6"),qo()),Pl=xe(ye("dnsaddr"),qo()),Cd=xe(ye("dns"),qo()),X5=Re(Il,Ae(Ie())),Z5=Re(Ol,Ae(Ie())),Y5=Re(Pl,Ae(Ie())),J5=Re(Tt(Cd,Pl,Il,Ol),Ae(Ie())),Uw=xe(ye("ip4"),ws(ms)),Mw=xe(ye("ip6"),ws(vl)),Td=Tt(Uw,Mw),xn=Tt(Td,Cd,Il,Ol,Pl),Q5=Re(Tt(Td,xe(Tt(Cd,Pl,Il,Ol),Ae(Ie())))),e4=Re(Uw),t4=Re(Mw),r4=Re(Td),Id=xe(xn,ye("tcp"),bs()),rc=xe(xn,ye("udp"),bs()),n4=Re(xe(Id,Ae(Ie()))),o4=Re(rc),Od=xe(rc,ye("quic"),Ae(Ie())),Bl=xe(rc,ye("quic-v1"),Ae(Ie())),C2=Tt(Od,Bl),i4=Re(Od),s4=Re(Bl),Ed=Tt(xn,Id,rc,Od,Bl),Kw=Tt(xe(Ed,ye("ws"),Ae(Ie()))),a4=Re(Kw),Hw=Tt(xe(Ed,ye("wss"),Ae(Ie())),xe(Ed,ye("tls"),Ae(xe(ye("sni"),qo())),ye("ws"),Ae(Ie()))),c4=Re(Hw),Vw=xe(rc,ye("webrtc-direct"),Ae(tc()),Ae(tc()),Ae(Ie())),$w=Re(Vw),Fw=xe(Bl,ye("webtransport"),Ae(tc()),Ae(tc()),Ae(Ie())),u4=Re(Fw),Tl=Tt(Kw,Hw,xe(Id,Ae(Ie())),xe(C2,Ae(Ie())),xe(xn,Ae(Ie())),Vw,Fw,Ie()),Ww=Re(Tl),T2=xe(Tl,ye("p2p-circuit"),Ie()),l4=Re(T2),I2=Tt(xe(Tl,ye("p2p-circuit"),ye("webrtc"),Ae(Ie())),xe(Tl,ye("webrtc"),Ae(Ie())),xe(ye("webrtc"),Ae(Ie()))),Gw=Re(I2),O2=Tt(xe(xn,ye("tcp"),bs(),ye("http"),Ae(Ie())),xe(xn,ye("http"),Ae(Ie()))),f4=Re(O2),P2=Tt(xe(xn,ye("tcp"),Tt(xe(ye("443"),ye("http")),xe(bs(),ye("https")),xe(bs(),ye("tls"),ye("http"))),Ae(Ie())),xe(xn,ye("tls"),ye("http"),Ae(Ie())),xe(xn,ye("https"),Ae(Ie()))),p4=Re(P2),B2=Tt(xe(ye("memory"),qo(),Ae(Ie()))),h4=Re(B2);var It;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Wo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Pr((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=>Or(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(It||(It={}));var qw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Pd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),zw="libp2p+webrtc+v1/";var Xw=466,Zw=2*1024*1024,Yw=30*1e3,xs=16*1024;function k2(r=xs){let e=He(r-He(r)),t=1+He(Object.keys(It.Flag).length-1),n=1,o=r-e-t-n,i=He(o);return e+t+n+i}var Jw=k2(),Qw=5e3,eb=5e3,tb=3e4,Bd="/webrtc",nc="/webrtc-signaling/0.0.1",rb="/libp2p/webrtc-direct/certificate",nb="webrtc-direct-certificate-private-key";var ob=12096e5,kd=864e5;var ib=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))},N2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var D2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var j2=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 R2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var L2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var U2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,M2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,sb=3,K2=[["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",U2]],ab=[["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 ub(r){return r?cb(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new L2:typeof navigator<"u"?cb(navigator.userAgent):$2()}function H2(r){return r!==""&&K2.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 cb(r){var e=H2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new R2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<sb&&(o=ib(ib([],o,!0),F2(sb-o.length),!0)):o=[];var i=o.join("."),s=V2(r),a=M2.exec(r);return a&&a[1]?new j2(t,i,s,a[1]):new N2(t,i,s)}function V2(r){for(var e=0,t=ab.length;e<t;e++){var n=ab[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function $2(){var r=typeof process<"u"&&process.version;return r?new D2(process.version.slice(1)):null}function F2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ye(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Nd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Dd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},lb=r=>globalThis.DOMException===void 0?new Dd(r):new DOMException(r),fb=r=>{let e=r.reason===void 0?lb("This operation was aborted."):r.reason;return e instanceof Error?e:lb(e)};function oc(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(fb(m)),a=()=>{p(fb(m))},m.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(f,p);return}let y=new Nd;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 pb=ub(),ic=pb!=null&&pb.name==="firefox",kl=async function*(){},Nl=async r=>{};function hb(r,e,t=tb,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=Ye(),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 oc(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function jd(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??qw.map(e=>({urls:[e]})),r}var db=(r=32)=>zw+[...Array(r)].map(()=>Pd.at(Math.floor(Math.random()*Pd.length))).join("");var zo=class{log;peerConnection;remoteAddr;timeline;metrics;source=kl();sink=Nl;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 Dl=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}},vs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Dl(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 Dl(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 Rd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function _s(r={}){return W2(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 W2(r,e){e=e??{};let t=e.onEnd,n=new vs,o,i,s,a=Ye(),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=Ye()})}},l=d=>i!=null?i(d):(n.push(d),o),f=d=>(n=new vs,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 vs,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 Rd)},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 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 sr(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 yb(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 mb(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function gb(r,e){let t=yb(r).return?.();mb(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var G2=5e3;function Ld(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Rl=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=Ye(),this.closed=Ye(),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??G2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=_s({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 Oo(`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);Ld(o)&&await o}let n=()=>{gb(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);Ld(i)&&(this.sendingData=Ye(),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 sr(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 sr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await sr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await sr(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();Ld(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 Ru("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 Ud(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 Ll=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ss=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ul=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},sc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ml(r){return r[Symbol.asyncIterator]!=null}function wb(r,e){if(r.byteLength>e)throw new Ss("Message length too long")}var Hl=r=>{let e=He(r),t=ot(e);return al(r,t),Hl.bytes=e,t};Hl.bytes=0;function ac(r,e){e=e??{};let t=e.lengthEncoder??Hl,n=e?.maxDataLength??4194304;function*o(i){wb(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Ml(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}ac.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Hl,n=e?.maxDataLength??4194304;return wb(r,n),new be(t(r.byteLength),r)};var Xo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Xo||(Xo={}));var Md=r=>{let e=Vo(r);return Md.bytes=He(e),e};Md.bytes=0;function Zo(r,e){let t=new be,n=Xo.LENGTH,o=-1,i=e?.lengthDecoder??Md,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Xo.LENGTH)try{if(o=i(t),o<0)throw new Ll("Invalid message length");if(o>a)throw new Ss("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Xo.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new Ul("Message length length too long");break}throw l}if(n===Xo.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Xo.LENGTH}}}return Ml(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new sc("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new sc("Unexpected end of input")}()}Zo.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 Zo(n,{...e??{},onLength:i=>{t=i}})};var Kd=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 cc(r,e,t,n){let o=new Kd(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 Hd=class extends Rl{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 oc(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=_s(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Yw,this.maxBufferedAmount=e.maxBufferedAmount??Zw,this.maxMessageSize=(e.maxMessageSize??xs)-Jw,this.receiveFinAck=Ye(),this.finAckTimeout=e.closeTimeout??Qw,this.openTimeout=e.openTimeout??eb,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 Oo("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 Zo(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 Oo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Ud([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 cc(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=Ud([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await cc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Ku(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=It.encode({message:o}),s=ac.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(It.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(It.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await sr(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(It.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=It.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===It.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(It.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===It.Flag.RESET&&this.reset(),t.flag===It.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===It.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=It.encode({flag:e}),n=ac.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 As(r){let{channel:e,direction:t,handshake:n}=r;return new Hd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var to=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Bd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=As({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Vd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Vd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Bd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=As({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),hb(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=Nl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=As({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Vl=globalThis.RTCPeerConnection,$l=globalThis.RTCSessionDescription,bb=globalThis.RTCIceCandidate;var $d=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ye(),this.haveNext=Ye()}[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=Ye(),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=Ye(),await sr(this.readNext.promise,t?.signal,t)}};function Fl(){return new $d}var Wl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function xb(r,e){let t=Fl();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 sr(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await sr(n.next(),s?.signal);if(l===!0)throw new Wl("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 Gl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ql=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function uc(r,e={}){let t=xb(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=He(e.maxDataLength));let n=e?.lengthDecoder??Vo,o=e?.lengthEncoder??al;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 Gl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new zl("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ql("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 Xl(r,e){let t=uc(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 er=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var ro=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ar=class extends ro{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Zl=class extends ro{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Yl=class extends ro{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Jl=class extends ro{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Ut;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Wo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Pr((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=>Or(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(Ut||(Ut={}));var Ql=async(r,e,t)=>{try{let n=Ye();for(X2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Ut.Type.ICE_CANDIDATE)throw new Mu("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new er("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new bb(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new er("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&&ef(r)!=="connected")throw n}};function ef(r){return ic?r.iceConnectionState:r.connectionState}function X2(r,e){r[ic?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(ef(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new ju("RTCPeerConnection was closed"));break;default:break}}}async function vb({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}=_b(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",f);let y=i.getConnections(p),m;y.length===0?(l?.(new er("webrtc:dial-relay")),m=await s.dial(f,{signal:t,onProgress:l})):(l?.(new er("webrtc:reuse-relay-connection")),m=y[0]),l?.(new er("webrtc:open-signaling-stream"));let x=await m.newStream(nc,{signal:t,runOnLimitedConnection:!0}),v=Xl(x).pb(Ut),d=new Vl(r),I=new to({logger:c},{peerConnection:d,dataChannelOptions:e});try{let D=d.createDataChannel("init");d.onicecandidate=({candidate:M})=>{let V=JSON.stringify(M?.toJSON()??null);a.trace("initiator sending ICE candidate %o",M),v.write({type:Ut.Type.ICE_CANDIDATE,data:V},{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 ar("Failed to set createOffer")});a.trace("initiator send SDP offer %s",j.sdp),l?.(new er("webrtc:send-sdp-offer")),await v.write({type:Ut.Type.SDP_OFFER,data:j.sdp},{signal:t}),await d.setLocalDescription(j).catch(M=>{throw a.error("could not execute setLocalDescription",M),new ar("Failed to set localDescription")}),l?.(new er("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let Z=await v.read({signal:t});if(Z.type!==Ut.Type.SDP_ANSWER)throw new ar("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",Z.data);let P=new $l({type:"answer",sdp:Z.data});return await d.setRemoteDescription(P).catch(M=>{throw a.error("could not execute setRemoteDescription",M),new ar("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new er("webrtc:read-ice-candidates")),await Ql(d,v,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),D.close(),l?.(new er("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 Sb=Re(Ww.matchers[0],ye("p2p-circuit")),tf=class r extends Fn{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=>Sb.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=>Sb.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 Ab({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Xl(e).pb(Ut);try{r.onicecandidate=({candidate:f})=>{let p=JSON.stringify(f?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Ut.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!==Ut.Type.SDP_OFFER)throw new ar(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new $l({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(f=>{throw o.error("could not execute setRemoteDescription",f),new ar("Failed to set remoteDescription")});let l=await r.createAnswer().catch(f=>{throw o.error("could not execute createAnswer",f),new ar("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:Ut.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(f=>{throw o.error("could not execute setLocalDescription",f),new ar("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Ql(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(ef(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 rf=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"})})}[ku]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Zi]=["@libp2p/transport"];[yg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(nc,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(nc),this._started=!1}createListener(e){return new tf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Gw.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 vb({rtcConfiguration:await jd(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 zo(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 Vl(await jd(this.init.rtcConfiguration)),i=new to(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await Ab({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new zo(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 _b(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new Te("Destination peer id was missing");return{circuitAddress:bn(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:gl(e)}}var Rz=Vr(Cb());var Jr={};_t(Jr,{Any:()=>Zr,BaseBlock:()=>Je,BaseStringBlock:()=>hc,BitString:()=>Dr,BmpString:()=>ti,Boolean:()=>Jo,CharacterString:()=>li,Choice:()=>Ts,Constructed:()=>it,DATE:()=>bc,DateTime:()=>vc,Duration:()=>_c,EndOfContent:()=>dc,Enumerated:()=>Qo,GeneralString:()=>ui,GeneralizedTime:()=>fi,GraphicString:()=>ci,HexBlock:()=>Yr,IA5String:()=>ai,Integer:()=>En,Null:()=>kr,NumericString:()=>ni,ObjectIdentifier:()=>ei,OctetString:()=>Nr,Primitive:()=>An,PrintableString:()=>oi,RawData:()=>qd,RelativeObjectIdentifier:()=>wc,Repeated:()=>pi,Sequence:()=>Ht,Set:()=>Vt,TIME:()=>Sc,TeletexString:()=>ii,TimeOfDay:()=>xc,UTCTime:()=>so,UniversalString:()=>ri,Utf8String:()=>ur,ValueBlock:()=>pt,VideotexString:()=>si,ViewWriter:()=>Cs,VisibleString:()=>io,compareSchema:()=>oo,fromBER:()=>Tn,verifySchema:()=>mC});var de=Vr(_n());function Yo(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 no(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 sf(...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 Wd(){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=Yo(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,Yo(i,8)-n}function Tb(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=no(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=no(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 Ib(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 Mt(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 UN=Math.log(2);function af(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function zd(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 Cs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return zd(this.items)}},lc=[new Uint8Array([1])],Ob="0123456789",Gd="name",Pb="valueHexView",oC="isHexOnly",iC="idBlock",sC="tagClass",aC="tagNumber",cC="isConstructed",uC="fromBER",lC="toBER",fC="local",Kt="",jr=new ArrayBuffer(0),_f=new Uint8Array(0),pc="EndOfContent",kb="OCTET STRING",Nb="BIT STRING";function Yr(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?de.BufferSourceConverter.toUint8Array(i.valueHex):_f}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",jr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:de.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=Kt,warnings:n=[],valueBeforeDecode:o=_f}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=de.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:de.Convert.ToHex(this.valueBeforeDecodeView)}}};Sn.NAME="baseBlock";var pt=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'")}};pt.NAME="valueBlock";var cf=class extends Yr(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?de.BufferSourceConverter.toUint8Array(e.valueHex):_f,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",jr}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=no(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=de.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=Yo(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}}};cf.NAME="identificationBlock";var uf=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=de.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=Yo(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=no(this.length,8);if(o.byteLength>127)return this.error="Too big length",jr;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}}};uf.NAME="lengthBlock";var Q={},Je=class extends Sn{constructor({name:e=Kt,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 uf(o),this.valueBlock=i?new i(o):new pt(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 Cs;t||Db(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?jr: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():de.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=de.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 Ib(t,n)}};Je.NAME="BaseBlock";function Db(r){var e;if(r instanceof Q.Constructed)for(let t of r.valueBlock.value)Db(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var hc=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Kt,...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}'`}};hc.NAME="BaseStringBlock";var lf=class extends Yr(pt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};lf.NAME="PrimitiveValueBlock";var jb,An=class extends Je{constructor(e={}){super(e,lf),this.idBlock.isConstructed=!1}};jb=An;Q.Primitive=jb;An.NAME="PRIMITIVE";function pC(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 Is(r,e=0,t=r.length){let n=e,o=new Je({},pt),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=Je;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=pC(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 Je({},pt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Is(de.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function hC(r,e){return r?1:e}var Xr=class extends pt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=de.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(;hC(this.isIndefiniteForm,n)>0;){let s=Is(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===pc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===pc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Cs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?jr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Xr.NAME="ConstructedValueBlock";var Rb,it=class extends Je{constructor(e={}){super(e,Xr),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} :`}};Rb=it;Q.Constructed=Rb;it.NAME="CONSTRUCTED";var ff=class extends pt{fromBER(e,t,n){return t}toBER(e){return jr}};ff.override="EndOfContentValueBlock";var Lb,yc=class extends Je{constructor(e={}){super(e,ff),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Lb=yc;Q.EndOfContent=Lb;yc.NAME=hc;var Ub,kr=class extends Je{constructor(e={}){super(e,pt),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}`}};Ub=kr;Q.Null=Ub;kr.NAME="NULL";var pf=class extends Jr(pt){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=de.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=de.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,Wd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};pf.NAME="BooleanValueBlock";var Mb,Jo=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,pf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Mb=Jo;Q.Boolean=Mb;Jo.NAME="BOOLEAN";var hf=class extends Jr(Zr){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=Zr.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===hc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==kb)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?Zr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};hf.NAME="OctetStringValueBlock";var Xd,Nr=class extends Je{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},hf),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=Os(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 it.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=de.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 Xd&&e.push(t.valueBlock.valueHexView);return de.BufferSourceConverter.concat(e)}};Xd=Nr;Q.OctetString=Xd;Nr.NAME=kb;var df=class extends Jr(Zr){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=Zr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===hc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Nb)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=de.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=Os(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 Zr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return jr;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}}};df.NAME="BitStringValueBlock";var Kb,Dr=class extends Je{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},df),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 it.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}`}}};Kb=Dr;Q.BitString=Kb;Dr.NAME=Nb;var Hb;function dC(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=sf(new Uint8Array([l%10]),i);break;default:i[s-p]=l%10}}return t[0]>0&&(i=sf(t,i)),i}function Bb(r){if(r>=fc.length)for(let e=fc.length;e<=r;e++){let t=new Uint8Array([0]),n=fc[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=sf(t,n)),fc.push(n)}return fc[r]}function yC(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 mc=class extends Jr(pt){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=Wd.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(Tb(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=yC(Bb(n),t),s="-";break;default:t=dC(t,Bb(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Ob.charAt(t[c]));return a===!1&&(s+=Ob.charAt(0)),s}};Hb=mc;mc.NAME="IntegerValueBlock";Object.defineProperty(Hb.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var pc,En=class extends Je{constructor(e={}){super(e,mc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return af(),BigInt(this.valueBlock.toString())}static fromBigInt(e){af();let t=BigInt(e),n=new Ts,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(de.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${de.Convert.ToHex(a)}`)+t,f=de.BufferSourceConverter.toUint8Array(de.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 pc({valueHex:n.final()})}convertToDER(){let e=new pc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new pc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};pc=En;Q.Integer=pc;En.NAME="INTEGER";var Vb,Qo=class extends En{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Vb=Qo;Q.Enumerated=Vb;Qo.NAME="ENUMERATED";var gc=class extends Jr(pt){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=de.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=Yo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){af();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=no(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;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=de.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}}};gc.NAME="sidBlock";var yf=class extends pt{constructor({value:e=Kt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new gc;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,jr;t.push(o)}return zd(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 gc;if(o>Number.MAX_SAFE_INTEGER){af();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}};yf.NAME="ObjectIdentifierValueBlock";var $b,ei=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,yf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};$b=ei;Q.ObjectIdentifier=$b;ei.NAME="OBJECT IDENTIFIER";var wc=class extends Jr(Sn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=de.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=Yo(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=no(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;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=de.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};wc.NAME="relativeSidBlock";var mf=class extends pt{constructor({value:e=Kt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new wc;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,jr;n.push(i)}return zd(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 wc;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}};mf.NAME="RelativeObjectIdentifierValueBlock";var Fb,bc=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,mf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Fb=bc;Q.RelativeObjectIdentifier=Fb;bc.NAME="RelativeObjectIdentifier";var Wb,Ht=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Wb=Ht;Q.Sequence=Wb;Ht.NAME="SEQUENCE";var Gb,Vt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Gb=Vt;Q.Set=Gb;Vt.NAME="SET";var gf=class extends Jr(pt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Kt}toJSON(){return{...super.toJSON(),value:this.value}}};gf.NAME="StringValueBlock";var wf=class extends gf{};wf.NAME="SimpleStringValueBlock";var Dt=class extends dc{constructor({...e}={}){super(e,wf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,de.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}};Dt.NAME="SIMPLE STRING";var bf=class extends Dt{fromBuffer(e){this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=de.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=de.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf8String(e)),this.valueBlock.value=e}};bf.NAME="Utf8StringValueBlock";var qb,ur=class extends bf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};qb=ur;Q.Utf8String=qb;ur.NAME="UTF8String";var xf=class extends Dt{fromBuffer(e){this.valueBlock.value=de.Convert.ToUtf16String(e),this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf16String(e))}};xf.NAME="BmpStringValueBlock";var zb,ti=class extends xf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};zb=ti;Q.BmpString=zb;ti.NAME="BMPString";var vf=class extends Dt{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=no(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}};vf.NAME="UniversalStringValueBlock";var Xb,ri=class extends vf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Xb=ri;Q.UniversalString=Xb;ri.NAME="UniversalString";var Zb,ni=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Zb=ni;Q.NumericString=Zb;ni.NAME="NumericString";var Yb,oi=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Yb=oi;Q.PrintableString=Yb;oi.NAME="PrintableString";var Jb,ii=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Jb=ii;Q.TeletexString=Jb;ii.NAME="TeletexString";var Qb,si=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Qb=si;Q.VideotexString=Qb;si.NAME="VideotexString";var ex,ai=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};ex=ai;Q.IA5String=ex;ai.NAME="IA5String";var tx,ci=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};tx=ci;Q.GraphicString=tx;ci.NAME="GraphicString";var rx,io=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};rx=io;Q.VisibleString=rx;io.NAME="VisibleString";var nx,ui=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};nx=ui;Q.GeneralString=nx;ui.NAME="GeneralString";var ox,li=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ox=li;Q.CharacterString=ox;li.NAME="CharacterString";var ix,so=class extends io{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,de.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]=Mt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Mt(this.month,2),t[2]=Mt(this.day,2),t[3]=Mt(this.hour,2),t[4]=Mt(this.minute,2),t[5]=Mt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};ix=so;Q.UTCTime=ix;so.NAME="UTCTime";var sx,fi=class extends so{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(Mt(this.year,4)),t.push(Mt(this.month,2)),t.push(Mt(this.day,2)),t.push(Mt(this.hour,2)),t.push(Mt(this.minute,2)),t.push(Mt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Mt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};sx=fi;Q.GeneralizedTime=sx;fi.NAME="GeneralizedTime";var ax,xc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};ax=xc;Q.DATE=ax;xc.NAME="DATE";var cx,vc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};cx=vc;Q.TimeOfDay=cx;vc.NAME="TimeOfDay";var ux,_c=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};ux=_c;Q.DateTime=ux;_c.NAME="DateTime";var lx,Sc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};lx=Sc;Q.Duration=lx;Sc.NAME="Duration";var fx,Ac=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};fx=Ac;Q.TIME=fx;Ac.NAME="TIME";var Yr=class{constructor({name:e=Kt,optional:t=!1}={}){this.name=e,this.optional=t}},Is=class extends Yr{constructor({value:e=[],...t}={}){super(t),this.value=e}},pi=class extends Yr{constructor({value:e=new Yr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},qd=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=de.BufferSourceConverter.toUint8Array(e)}constructor({data:e=_f}={}){this.dataView=de.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=de.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function oo(r,e,t){if(t instanceof Is){for(let i of t.value)if(oo(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Gd)&&(i.name=t.name),i}}if(t instanceof Yr)return t.hasOwnProperty(Gd)&&(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(!(iC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(uC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(lC 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(sC)===!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(aC)===!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(cC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(oC 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(!(Pb 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,Kt),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 pi&&(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,Kt),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,Kt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof pi){if(s=oo(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,Kt),t.name&&delete r[t.name]),s;if(Gd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};fC 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=oo(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,Kt),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,Kt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Pb in e.valueBlock){let i=Os(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,Kt),t.name&&(delete r[t.name],s.name=t.name)),s}return oo(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function mC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Os(de.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:oo(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 Zd=Vr(_n()),en=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Zd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Zd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Dr))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 Dr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Dr({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 Yd=Vr(_n()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Yd.BufferSourceConverter.isBufferSource(e)?this.buffer=Yd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Nr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Nr({valueHex:this.buffer})}toSchema(e){return new Nr({name:e})}};var gC={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}},wC={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new En({value:+r})},bC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Qo({value:r})},me={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new En({valueHex:r})};var xC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Dr({valueHex:r})},vC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ei({value:r})},_C={fromASN:r=>r.valueBlock.value,toASN:r=>new Jo({value:r})},Ps={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Nr({valueHex:r})},px={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function lr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Jd=lr(ur),SC=lr(ti),AC=lr(ri),EC=lr(ni),CC=lr(oi),TC=lr(ii),IC=lr(si),OC=lr(ai),PC=lr(ci),BC=lr(io),kC=lr(ui),NC=lr(li),DC={fromASN:r=>r.toDate(),toASN:r=>new so({valueDate:r})},jC={fromASN:r=>r.toDate(),toASN:r=>new fi({valueDate:r})},RC={fromASN:()=>null,toASN:()=>new kr};function Bs(r){switch(r){case h.Any:return gC;case h.BitString:return xC;case h.BmpString:return SC;case h.Boolean:return _C;case h.CharacterString:return NC;case h.Enumerated:return bC;case h.GeneralString:return kC;case h.GeneralizedTime:return jC;case h.GraphicString:return PC;case h.IA5String:return OC;case h.Integer:return wC;case h.Null:return RC;case h.NumericString:return EC;case h.ObjectIdentifier:return vC;case h.OctetString:return Ps;case h.PrintableString:return CC;case h.TeletexString:return TC;case h.UTCTime:return DC;case h.UniversalString:return AC;case h.Utf8String:return Jd;case h.VideotexString:return IC;case h.VisibleString:return BC;default:return null}}function fr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:fr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function ey(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:ey(t)}return!1}function hx(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 Sf=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=Qr[f];if(!p)throw new Error(`Cannot get ASN1 class by name '${f}'`);c=new p({name:a})}else fr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===_.Choice?c=new Yr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Yr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let f=s.repeated==="set"?Vt:Ht;c=new f({name:"",value:[new pi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||fr(s.type)){let f=s.repeated?it: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 it({name:f?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new it({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case _.Sequence:return new Ht({value:o,name:""});case _.Set:return new Vt({value:o,name:""});case _.Choice:return new Is({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 jt=new Sf;var A=r=>e=>{let t;jt.has(e)?t=jt.get(e):(t=jt.createDefault(e),jt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;jt.has(e.constructor)?n=jt.get(e.constructor):(n=jt.createDefault(e.constructor),jt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Bs(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 Ec=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Cc=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(fr(t))return new t().fromASN(e);let o=jt.get(t);jt.cache(t);let i=o.schema;if(e.constructor===it&&o.type!==_.Choice){i=new it({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=oo({},e,i);if(!s.verified)throw new Ec(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(ey(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=Bs(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"||fr(p)){let y=(n=f.converter)!==null&&n!==void 0?n:fr(p)?new p:null;if(!y)throw new Error("Converter is empty");if(f.repeated)if(f.implicit){let m=f.repeated==="sequence"?Ht:Vt,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,C=>y.fromASN(C))}else a[c]=Array.from(l,m=>y.fromASN(m));else{let m=l;if(f.implicit){let x;if(fr(p))x=new p().toSchema("");else{let v=h[p],d=Qr[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 Ec&&o.schemas.push(t.name),o}}};var Tc=class r{static serialize(e){return e instanceof Je?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&fr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=jt.get(t);jt.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=Bs(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"&&hx(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"||fr(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 it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new it({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 Ht({value:o});break;case _.Set:i=new Vt({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"?Ht:Vt;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"?Ht:Vt;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 ty=Vr(_n());var G=class r{static serialize(e){return Tc.serialize(e)}static parse(e,t){return Cc.parse(e,t)}static toString(e){let t=ty.BufferSourceConverter.isBufferSource(e)?ty.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 dx=Vr(_n()),Ic=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(dx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var yx=Vr(_n()),ry,ny,oy,Qe=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};w([u({type:h.TeletexString})],Qe.prototype,"teletexString",void 0);w([u({type:h.PrintableString})],Qe.prototype,"printableString",void 0);w([u({type:h.UniversalString})],Qe.prototype,"universalString",void 0);w([u({type:h.Utf8String})],Qe.prototype,"utf8String",void 0);w([u({type:h.BmpString})],Qe.prototype,"bmpString",void 0);Qe=w([A({type:_.Choice})],Qe);var ks=class extends Qe{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?yx.Convert.ToHex(this.anyValue):super.toString())}};w([u({type:h.IA5String})],ks.prototype,"ia5String",void 0);w([u({type:h.Any})],ks.prototype,"anyValue",void 0);ks=w([A({type:_.Choice})],ks);var hi=class{constructor(e={}){this.type="",this.value=new ks,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],hi.prototype,"type",void 0);w([u({type:ks})],hi.prototype,"value",void 0);var ao=ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};ao=ry=w([A({type:_.Set,itemType:hi})],ao);var iy=ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};iy=ny=w([A({type:_.Sequence,itemType:ao})],iy);var Pe=oy=class extends iy{constructor(e){super(e),Object.setPrototypeOf(this,oy.prototype)}};Pe=oy=w([A({type:_.Sequence})],Pe);var LC={fromASN:r=>Ic.toString(Ps.fromASN(r)),toASN:r=>Ps.toASN(Ic.fromString(r))},co=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],co.prototype,"typeId",void 0);w([u({type:h.Any,context:0})],co.prototype,"value",void 0);var Oc=class{constructor(e={}){this.partyName=new Qe,Object.assign(this,e)}};w([u({type:Qe,optional:!0,context:0,implicit:!0})],Oc.prototype,"nameAssigner",void 0);w([u({type:Qe,context:1,implicit:!0})],Oc.prototype,"partyName",void 0);var ue=class{constructor(e={}){Object.assign(this,e)}};w([u({type:co,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:Oc,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:LC})],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 uo="1.3.6.1.5.5.7",lo=`${uo}.1`,mx=`${uo}.2`,di=`${uo}.3`,Af=`${uo}.48`,Z3=`${mx}.1`,Y3=`${mx}.2`,sy=`${Af}.1`,ay=`${Af}.2`,cy=`${Af}.3`,uy=`${Af}.5`,fe="2.5.29";var ly,Ef=`${lo}.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 yi=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};yi=ly=w([A({type:_.Sequence,itemType:In})],yi);var Cf=`${fe}.35`,mi=class extends ae{},tn=class{constructor(e={}){e&&Object.assign(this,e)}};w([u({type:mi,context:0,optional:!0,implicit:!0})],tn.prototype,"keyIdentifier",void 0);w([u({type:ue,context:1,optional:!0,implicit:!0,repeated:"sequence"})],tn.prototype,"authorityCertIssuer",void 0);w([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:me})],tn.prototype,"authorityCertSerialNumber",void 0);var Tf=`${fe}.19`,gi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};w([u({type:h.Boolean,defaultValue:!1})],gi.prototype,"cA",void 0);w([u({type:h.Integer,optional:!0})],gi.prototype,"pathLenConstraint",void 0);var fy,Ke=fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};Ke=fy=w([A({type:_.Sequence,itemType:ue})],Ke);var py,UC=`${fe}.29`,gx=py=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};gx=py=w([A({type:_.Sequence})],gx);var hy,Of=`${fe}.32`,OD=`${Of}.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 Pc=class{constructor(e={}){this.organization=new On,this.noticeNumbers=[],Object.assign(this,e)}};w([u({type:On})],Pc.prototype,"organization",void 0);w([u({type:h.Integer,repeated:"sequence"})],Pc.prototype,"noticeNumbers",void 0);var Bc=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Pc,optional:!0})],Bc.prototype,"noticeRef",void 0);w([u({type:On,optional:!0})],Bc.prototype,"explicitText",void 0);var If=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.IA5String})],If.prototype,"cPSuri",void 0);w([u({type:Bc})],If.prototype,"userNotice",void 0);If=w([A({type:_.Choice})],If);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 wi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],wi.prototype,"policyIdentifier",void 0);w([u({type:kc,repeated:"sequence",optional:!0})],wi.prototype,"policyQualifiers",void 0);var Nc=hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};Nc=hy=w([A({type:_.Sequence,itemType:wi})],Nc);var LD=`${fe}.20`,Dc=class{constructor(e=0){this.value=e}};w([u({type:h.Integer})],Dc.prototype,"value",void 0);Dc=w([A({type:_.Choice})],Dc);var FD=`${fe}.27`,wx=class extends Dc{};wx=w([A({type:_.Choice})],wx);var dy,Pf=`${fe}.31`,Rr;(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"})(Rr||(Rr={}));var jc=class extends en{toJSON(){let e=[],t=this.toNumber();return t&Rr.aACompromise&&e.push("aACompromise"),t&Rr.affiliationChanged&&e.push("affiliationChanged"),t&Rr.cACompromise&&e.push("cACompromise"),t&Rr.certificateHold&&e.push("certificateHold"),t&Rr.cessationOfOperation&&e.push("cessationOfOperation"),t&Rr.keyCompromise&&e.push("keyCompromise"),t&Rr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Rr.superseded&&e.push("superseded"),t&Rr.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:ao,context:1,implicit:!0})],Pn.prototype,"nameRelativeToCRLIssuer",void 0);Pn=w([A({type:_.Choice})],Pn);var rn=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Pn,context:0,optional:!0})],rn.prototype,"distributionPoint",void 0);w([u({type:jc,context:1,optional:!0,implicit:!0})],rn.prototype,"reasons",void 0);w([u({type:ue,context:2,optional:!0,repeated:"sequence",implicit:!0})],rn.prototype,"cRLIssuer",void 0);var fo=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};fo=dy=w([A({type:_.Sequence,itemType:rn})],fo);var yy,ij=`${fe}.46`,bx=yy=class extends fo{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};bx=yy=w([A({type:_.Sequence,itemType:rn})],bx);var hj=`${fe}.28`,tr=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};tr.ONLY=!1;w([u({type:Pn,context:0,optional:!0})],tr.prototype,"distributionPoint",void 0);w([u({type:h.Boolean,context:1,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsUserCerts",void 0);w([u({type:h.Boolean,context:2,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsCACerts",void 0);w([u({type:jc,context:3,optional:!0,implicit:!0})],tr.prototype,"onlySomeReasons",void 0);w([u({type:h.Boolean,context:4,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"indirectCRL",void 0);w([u({type:h.Boolean,context:5,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsAttributeCerts",void 0);var xx=`${fe}.21`,Rc;(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"})(Rc||(Rc={}));var Lc=class{constructor(e=Rc.unspecified){this.reason=Rc.unspecified,this.reason=e}toJSON(){return Rc[this.reason]}toString(){return this.toJSON()}};w([u({type:h.Enumerated})],Lc.prototype,"reason",void 0);Lc=w([A({type:_.Choice})],Lc);var my,Bf=`${fe}.37`,Uc=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};Uc=my=w([A({type:_.Sequence,itemType:h.ObjectIdentifier})],Uc);var Aj=`${Bf}.0`,vx=`${di}.1`,_x=`${di}.2`,Sx=`${di}.3`,Ax=`${di}.4`,Ex=`${di}.8`,Cx=`${di}.9`;var Oj=`${fe}.54`,gy=class{constructor(e=new ArrayBuffer(0)){this.value=e}};w([u({type:h.Integer,converter:me})],gy.prototype,"value",void 0);gy=w([A({type:_.Choice})],gy);var Tx=`${fe}.24`,Mc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};w([u({type:h.GeneralizedTime})],Mc.prototype,"value",void 0);Mc=w([A({type:_.Choice})],Mc);var wy,Hj=`${fe}.18`,Ix=wy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Ix=wy=w([A({type:_.Sequence})],Ix);var kf=`${fe}.15`,Lr;(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"})(Lr||(Lr={}));var Ns=class extends en{toJSON(){let e=this.toNumber(),t=[];return e&Lr.cRLSign&&t.push("crlSign"),e&Lr.dataEncipherment&&t.push("dataEncipherment"),e&Lr.decipherOnly&&t.push("decipherOnly"),e&Lr.digitalSignature&&t.push("digitalSignature"),e&Lr.encipherOnly&&t.push("encipherOnly"),e&Lr.keyAgreement&&t.push("keyAgreement"),e&Lr.keyCertSign&&t.push("keyCertSign"),e&Lr.keyEncipherment&&t.push("keyEncipherment"),e&Lr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var by,Yj=`${fe}.30`,Ds=class{constructor(e={}){this.base=new ue,this.minimum=0,Object.assign(this,e)}};w([u({type:ue})],Ds.prototype,"base",void 0);w([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Ds.prototype,"minimum",void 0);w([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Ds.prototype,"maximum",void 0);var Nf=by=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};Nf=by=w([A({type:_.Sequence,itemType:Ds})],Nf);var Df=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Nf,context:0,optional:!0,implicit:!0})],Df.prototype,"permittedSubtrees",void 0);w([u({type:Nf,context:1,optional:!0,implicit:!0})],Df.prototype,"excludedSubtrees",void 0);var nR=`${fe}.36`,jf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:me})],jf.prototype,"requireExplicitPolicy",void 0);w([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:me})],jf.prototype,"inhibitPolicyMapping",void 0);var xy,cR=`${fe}.33`,Kc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Kc.prototype,"issuerDomainPolicy",void 0);w([u({type:h.ObjectIdentifier})],Kc.prototype,"subjectDomainPolicy",void 0);var Ox=xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};Ox=xy=w([A({type:_.Sequence,itemType:Kc})],Ox);var vy,_y=`${fe}.17`,Rf=vy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,vy.prototype)}};Rf=vy=w([A({type:_.Sequence})],Rf);var ht=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],ht.prototype,"type",void 0);w([u({type:h.Any,repeated:"set"})],ht.prototype,"values",void 0);var Sy,AR=`${fe}.9`,Px=Sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};Px=Sy=w([A({type:_.Sequence,itemType:ht})],Px);var Ay=`${fe}.14`,$t=class extends mi{};var NR=`${fe}.16`,Lf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],Lf.prototype,"notBefore",void 0);w([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],Lf.prototype,"notAfter",void 0);var Hc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Hc||(Hc={}));var Uf=class extends en{toJSON(){let e=[],t=this.toNumber();return t&Hc.pKIXCertificate&&e.push("pKIXCertificate"),t&Hc.newExtensions&&e.push("newExtensions"),t&Hc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Mf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Uf,Object.assign(this,e)}};w([u({type:h.GeneralString})],Mf.prototype,"entrustVers",void 0);w([u({type:Uf})],Mf.prototype,"entrustInfoFlags",void 0);var Ey,VR=`${lo}.11`,Bx=Ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};Bx=Ey=w([A({type:_.Sequence,itemType:In})],Bx);var kx=Vr(_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&&kx.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 dt=class{constructor(e={}){this.algorithm=new H,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:H})],dt.prototype,"algorithm",void 0);w([u({type:h.BitString})],dt.prototype,"subjectPublicKey",void 0);var We=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})],We.prototype,"utcTime",void 0);w([u({type:h.GeneralizedTime})],We.prototype,"generalTime",void 0);We=w([A({type:_.Choice})],We);var Bn=class{constructor(e){this.notBefore=new We(new Date),this.notAfter=new We(new Date),e&&(this.notBefore=new We(e.notBefore),this.notAfter=new We(e.notAfter))}};w([u({type:We})],Bn.prototype,"notBefore",void 0);w([u({type:We})],Bn.prototype,"notAfter",void 0);var Cy,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};yt.CRITICAL=!1;w([u({type:h.ObjectIdentifier})],yt.prototype,"extnID",void 0);w([u({type:h.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);w([u({type:ae})],yt.prototype,"extnValue",void 0);var rr=Cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};rr=Cy=w([A({type:_.Sequence,itemType:yt})],rr);var nn;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(nn||(nn={}));var mt=class{constructor(e={}){this.version=nn.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 dt,Object.assign(this,e)}};w([u({type:h.Integer,context:0,defaultValue:nn.v1})],mt.prototype,"version",void 0);w([u({type:h.Integer,converter:me})],mt.prototype,"serialNumber",void 0);w([u({type:H})],mt.prototype,"signature",void 0);w([u({type:Pe})],mt.prototype,"issuer",void 0);w([u({type:Bn})],mt.prototype,"validity",void 0);w([u({type:Pe})],mt.prototype,"subject",void 0);w([u({type:dt})],mt.prototype,"subjectPublicKeyInfo",void 0);w([u({type:h.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);w([u({type:h.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);w([u({type:rr,context:3,optional:!0})],mt.prototype,"extensions",void 0);var pr=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:mt})],pr.prototype,"tbsCertificate",void 0);w([u({type:H})],pr.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],pr.prototype,"signatureValue",void 0);var bi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new We,Object.assign(this,e)}};w([u({type:h.Integer,converter:me})],bi.prototype,"userCertificate",void 0);w([u({type:We})],bi.prototype,"revocationDate",void 0);w([u({type:yt,optional:!0,repeated:"sequence"})],bi.prototype,"crlEntryExtensions",void 0);var nr=class{constructor(e={}){this.signature=new H,this.issuer=new Pe,this.thisUpdate=new We,Object.assign(this,e)}};w([u({type:h.Integer,optional:!0})],nr.prototype,"version",void 0);w([u({type:H})],nr.prototype,"signature",void 0);w([u({type:Pe})],nr.prototype,"issuer",void 0);w([u({type:We})],nr.prototype,"thisUpdate",void 0);w([u({type:We,optional:!0})],nr.prototype,"nextUpdate",void 0);w([u({type:bi,repeated:"sequence",optional:!0})],nr.prototype,"revokedCertificates",void 0);w([u({type:yt,optional:!0,context:0,repeated:"sequence"})],nr.prototype,"crlExtensions",void 0);var xi=class{constructor(e={}){this.tbsCertList=new nr,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:nr})],xi.prototype,"tbsCertList",void 0);w([u({type:H})],xi.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],xi.prototype,"signature",void 0);var V=Vr(_n());function T(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 Ur=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:Pe})],Ur.prototype,"issuer",void 0);T([u({type:h.Integer,converter:me})],Ur.prototype,"serialNumber",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};T([u({type:$t,context:0,implicit:!0})],vi.prototype,"subjectKeyIdentifier",void 0);T([u({type:Ur})],vi.prototype,"issuerAndSerialNumber",void 0);vi=T([A({type:_.Choice})],vi);var gt;(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"})(gt||(gt={}));var _i=class extends H{};_i=T([A({type:_.Sequence})],_i);var Vc=class extends H{};Vc=T([A({type:_.Sequence})],Vc);var Ft=class extends H{};Ft=T([A({type:_.Sequence})],Ft);var $c=class extends H{};$c=T([A({type:_.Sequence})],$c);var Dx=class extends H{};Dx=T([A({type:_.Sequence})],Dx);var Kf=class extends H{};Kf=T([A({type:_.Sequence})],Kf);var Mr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],Mr.prototype,"attrType",void 0);T([u({type:h.Any,repeated:"set"})],Mr.prototype,"attrValues",void 0);var Ty,Wt=class{constructor(e={}){this.version=gt.v0,this.sid=new vi,this.digestAlgorithm=new _i,this.signatureAlgorithm=new Vc,this.signature=new ae,Object.assign(this,e)}};T([u({type:h.Integer})],Wt.prototype,"version",void 0);T([u({type:vi})],Wt.prototype,"sid",void 0);T([u({type:_i})],Wt.prototype,"digestAlgorithm",void 0);T([u({type:Mr,repeated:"set",context:0,implicit:!0,optional:!0})],Wt.prototype,"signedAttrs",void 0);T([u({type:Vc})],Wt.prototype,"signatureAlgorithm",void 0);T([u({type:ae})],Wt.prototype,"signature",void 0);T([u({type:Mr,repeated:"set",context:1,implicit:!0,optional:!0})],Wt.prototype,"unsignedAttrs",void 0);var Fc=Ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};Fc=Ty=T([A({type:_.Set,itemType:Wt})],Fc);var jx=class extends We{};jx=T([A({type:_.Choice})],jx);var Rx=class extends Wt{};Rx=T([A({type:_.Sequence})],Rx);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 Wc=class{constructor(e={}){this.acIssuer=new ue,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:ue})],Wc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Wc.prototype,"acSerial",void 0);z([u({type:ht,repeated:"sequence"})],Wc.prototype,"attrs",void 0);var Iy,Gc=Iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Iy.prototype)}};Gc=Iy=z([A({type:_.Sequence,itemType:h.ObjectIdentifier})],Gc);var js=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],js.prototype,"pathLenConstraint",void 0);z([u({type:Gc,implicit:!0,context:0,optional:!0})],js.prototype,"permittedAttrs",void 0);z([u({type:Gc,implicit:!0,context:1,optional:!0})],js.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],js.prototype,"permitUnSpecified",void 0);var hr=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})],hr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:me})],hr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],hr.prototype,"issuerUID",void 0);var Oy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(Oy||(Oy={}));var dr=class{constructor(e={}){this.digestedObjectType=Oy.publicKey,this.digestAlgorithm=new H,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],dr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],dr.prototype,"otherObjectTypeID",void 0);z([u({type:H})],dr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],dr.prototype,"objectDigest",void 0);var Si=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,optional:!0})],Si.prototype,"issuerName",void 0);z([u({type:hr,context:0,implicit:!0,optional:!0})],Si.prototype,"baseCertificateID",void 0);z([u({type:dr,context:1,implicit:!0,optional:!0})],Si.prototype,"objectDigestInfo",void 0);var Ai=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,repeated:"sequence"})],Ai.prototype,"v1Form",void 0);z([u({type:Si,context:0,implicit:!0})],Ai.prototype,"v2Form",void 0);Ai=z([A({type:_.Choice})],Ai);var Ei=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Ei.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Ei.prototype,"notAfterTime",void 0);var po=class{constructor(e={}){Object.assign(this,e)}};z([u({type:hr,implicit:!0,context:0,optional:!0})],po.prototype,"baseCertificateID",void 0);z([u({type:Ke,implicit:!0,context:1,optional:!0})],po.prototype,"entityName",void 0);z([u({type:dr,implicit:!0,context:2,optional:!0})],po.prototype,"objectDigestInfo",void 0);var Py;(function(r){r[r.v2=1]="v2"})(Py||(Py={}));var Gt=class{constructor(e={}){this.version=Py.v2,this.holder=new po,this.issuer=new Ai,this.signature=new H,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Ei,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],Gt.prototype,"version",void 0);z([u({type:po})],Gt.prototype,"holder",void 0);z([u({type:Ai})],Gt.prototype,"issuer",void 0);z([u({type:H})],Gt.prototype,"signature",void 0);z([u({type:h.Integer,converter:me})],Gt.prototype,"serialNumber",void 0);z([u({type:Ei})],Gt.prototype,"attrCertValidityPeriod",void 0);z([u({type:ht,repeated:"sequence"})],Gt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],Gt.prototype,"issuerUniqueID",void 0);z([u({type:rr,optional:!0})],Gt.prototype,"extensions",void 0);var Ci=class{constructor(e={}){this.acinfo=new Gt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Gt})],Ci.prototype,"acinfo",void 0);z([u({type:H})],Ci.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Ci.prototype,"signatureValue",void 0);var qc;(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"})(qc||(qc={}));var Rs=class extends en{};var Ls=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],Ls.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],Ls.prototype,"value",void 0);var zc=class{constructor(e={}){this.policyId="",this.classList=new Rs(qc.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],zc.prototype,"policyId",void 0);z([u({type:Rs,defaultValue:new Rs(qc.unclassified)})],zc.prototype,"classList",void 0);z([u({type:Ls,repeated:"set"})],zc.prototype,"securityCategories",void 0);var Us=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ae})],Us.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],Us.prototype,"oid",void 0);z([u({type:h.Utf8String})],Us.prototype,"string",void 0);var Hf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],Hf.prototype,"policyAuthority",void 0);z([u({type:Us,repeated:"sequence"})],Hf.prototype,"values",void 0);var A9=`${lo}.4`,E9=`${lo}.6`,C9=`${lo}.10`,T9=`${fe}.55`,Xc=`${uo}.10`,I9=`${Xc}.1`,O9=`${Xc}.2`,P9=`${Xc}.3`,B9=`${Xc}.4`,k9=`${Xc}.6`,By="2.5.4",N9=`${By}.72`;var ky,Ms=class{constructor(e={}){this.targetCertificate=new hr,Object.assign(this,e)}};z([u({type:hr})],Ms.prototype,"targetCertificate",void 0);z([u({type:ue,optional:!0})],Ms.prototype,"targetName",void 0);z([u({type:dr,optional:!0})],Ms.prototype,"certDigestInfo",void 0);var Ks=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,context:0,implicit:!0})],Ks.prototype,"targetName",void 0);z([u({type:ue,context:1,implicit:!0})],Ks.prototype,"targetGroup",void 0);z([u({type:Ms,context:2,implicit:!0})],Ks.prototype,"targetCert",void 0);Ks=z([A({type:_.Choice})],Ks);var Vf=ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Vf=ky=z([A({type:_.Sequence,itemType:Ks})],Vf);var Ny,Lx=Ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};Lx=Ny=z([A({type:_.Sequence,itemType:Vf})],Lx);var $f=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],$f.prototype,"roleAuthority",void 0);z([u({type:ue,implicit:!0,context:1})],$f.prototype,"roleName",void 0);var Zc=class{constructor(e={}){this.service=new ue,this.ident=new ue,Object.assign(this,e)}};z([u({type:ue})],Zc.prototype,"service",void 0);z([u({type:ue})],Zc.prototype,"ident",void 0);z([u({type:ae,optional:!0})],Zc.prototype,"authInfo",void 0);var Dy,Yc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],Yc.prototype,"otherCertFormat",void 0);T([u({type:h.Any})],Yc.prototype,"otherCert",void 0);var Ti=class{constructor(e={}){Object.assign(this,e)}};T([u({type:pr})],Ti.prototype,"certificate",void 0);T([u({type:Ci,context:2,implicit:!0})],Ti.prototype,"v2AttrCert",void 0);T([u({type:Yc,context:3,implicit:!0})],Ti.prototype,"other",void 0);Ti=T([A({type:_.Choice})],Ti);var Ii=Dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};Ii=Dy=T([A({type:_.Set,itemType:Ti})],Ii);var yr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],yr.prototype,"contentType",void 0);T([u({type:h.Any,context:0})],yr.prototype,"content",void 0);var Hs=class{constructor(e={}){Object.assign(this,e)}};T([u({type:ae})],Hs.prototype,"single",void 0);T([u({type:h.Any})],Hs.prototype,"any",void 0);Hs=T([A({type:_.Choice})],Hs);var Oi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],Oi.prototype,"eContentType",void 0);T([u({type:Hs,context:0,optional:!0})],Oi.prototype,"eContent",void 0);var Jc=class{constructor(e={}){Object.assign(this,e)}};T([u({type:ae,context:0,implicit:!0,optional:!0})],Jc.prototype,"value",void 0);T([u({type:ae,converter:px,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Jc.prototype,"constructedValue",void 0);Jc=T([A({type:_.Choice})],Jc);var ho=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new $c,Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],ho.prototype,"contentType",void 0);T([u({type:$c})],ho.prototype,"contentEncryptionAlgorithm",void 0);T([u({type:Jc,optional:!0})],ho.prototype,"encryptedContent",void 0);var yo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],yo.prototype,"keyAttrId",void 0);T([u({type:h.Any,optional:!0})],yo.prototype,"keyAttr",void 0);var jy,Vs=class{constructor(e={}){this.subjectKeyIdentifier=new $t,Object.assign(this,e)}};T([u({type:$t})],Vs.prototype,"subjectKeyIdentifier",void 0);T([u({type:h.GeneralizedTime,optional:!0})],Vs.prototype,"date",void 0);T([u({type:yo,optional:!0})],Vs.prototype,"other",void 0);var $s=class{constructor(e={}){Object.assign(this,e)}};T([u({type:Vs,context:0,implicit:!0,optional:!0})],$s.prototype,"rKeyId",void 0);T([u({type:Ur,optional:!0})],$s.prototype,"issuerAndSerialNumber",void 0);$s=T([A({type:_.Choice})],$s);var Qc=class{constructor(e={}){this.rid=new $s,this.encryptedKey=new ae,Object.assign(this,e)}};T([u({type:$s})],Qc.prototype,"rid",void 0);T([u({type:ae})],Qc.prototype,"encryptedKey",void 0);var Ff=jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};Ff=jy=T([A({type:_.Sequence,itemType:Qc})],Ff);var eu=class{constructor(e={}){this.algorithm=new H,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:H})],eu.prototype,"algorithm",void 0);T([u({type:h.BitString})],eu.prototype,"publicKey",void 0);var Pi=class{constructor(e={}){Object.assign(this,e)}};T([u({type:$t,context:0,implicit:!0,optional:!0})],Pi.prototype,"subjectKeyIdentifier",void 0);T([u({type:eu,context:1,implicit:!0,optional:!0})],Pi.prototype,"originatorKey",void 0);T([u({type:Ur,optional:!0})],Pi.prototype,"issuerAndSerialNumber",void 0);Pi=T([A({type:_.Choice})],Pi);var kn=class{constructor(e={}){this.version=gt.v3,this.originator=new Pi,this.keyEncryptionAlgorithm=new Ft,this.recipientEncryptedKeys=new Ff,Object.assign(this,e)}};T([u({type:h.Integer})],kn.prototype,"version",void 0);T([u({type:Pi,context:0})],kn.prototype,"originator",void 0);T([u({type:ae,context:1,optional:!0})],kn.prototype,"ukm",void 0);T([u({type:Ft})],kn.prototype,"keyEncryptionAlgorithm",void 0);T([u({type:Ff})],kn.prototype,"recipientEncryptedKeys",void 0);var Fs=class{constructor(e={}){Object.assign(this,e)}};T([u({type:$t,context:0,implicit:!0})],Fs.prototype,"subjectKeyIdentifier",void 0);T([u({type:Ur})],Fs.prototype,"issuerAndSerialNumber",void 0);Fs=T([A({type:_.Choice})],Fs);var mo=class{constructor(e={}){this.version=gt.v0,this.rid=new Fs,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};T([u({type:h.Integer})],mo.prototype,"version",void 0);T([u({type:Fs})],mo.prototype,"rid",void 0);T([u({type:Ft})],mo.prototype,"keyEncryptionAlgorithm",void 0);T([u({type:ae})],mo.prototype,"encryptedKey",void 0);var Bi=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};T([u({type:ae})],Bi.prototype,"keyIdentifier",void 0);T([u({type:h.GeneralizedTime,optional:!0})],Bi.prototype,"date",void 0);T([u({type:yo,optional:!0})],Bi.prototype,"other",void 0);var go=class{constructor(e={}){this.version=gt.v4,this.kekid=new Bi,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};T([u({type:h.Integer})],go.prototype,"version",void 0);T([u({type:Bi})],go.prototype,"kekid",void 0);T([u({type:Ft})],go.prototype,"keyEncryptionAlgorithm",void 0);T([u({type:ae})],go.prototype,"encryptedKey",void 0);var wo=class{constructor(e={}){this.version=gt.v0,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};T([u({type:h.Integer})],wo.prototype,"version",void 0);T([u({type:Kf,context:0,optional:!0})],wo.prototype,"keyDerivationAlgorithm",void 0);T([u({type:Ft})],wo.prototype,"keyEncryptionAlgorithm",void 0);T([u({type:ae})],wo.prototype,"encryptedKey",void 0);var tu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],tu.prototype,"oriType",void 0);T([u({type:h.Any})],tu.prototype,"oriValue",void 0);var Nn=class{constructor(e={}){Object.assign(this,e)}};T([u({type:mo,optional:!0})],Nn.prototype,"ktri",void 0);T([u({type:kn,context:1,implicit:!0,optional:!0})],Nn.prototype,"kari",void 0);T([u({type:go,context:2,implicit:!0,optional:!0})],Nn.prototype,"kekri",void 0);T([u({type:wo,context:3,implicit:!0,optional:!0})],Nn.prototype,"pwri",void 0);T([u({type:tu,context:4,implicit:!0,optional:!0})],Nn.prototype,"ori",void 0);Nn=T([A({type:_.Choice})],Nn);var Ry,ru=Ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ry.prototype)}};ru=Ry=T([A({type:_.Set,itemType:Nn})],ru);var Ly,Ux=`${uo}.16`,kH=`${Ux}.2`,NH=`${Ux}.4`,Ws=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};T([u({type:h.ObjectIdentifier})],Ws.prototype,"otherRevInfoFormat",void 0);T([u({type:h.Any})],Ws.prototype,"otherRevInfo",void 0);var Wf=class{constructor(e={}){this.other=new Ws,Object.assign(this,e)}};T([u({type:Ws,context:1,implicit:!0})],Wf.prototype,"other",void 0);Wf=T([A({type:_.Choice})],Wf);var Gs=Ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Gs=Ly=T([A({type:_.Set,itemType:Wf})],Gs);var qs=class{constructor(e={}){Object.assign(this,e)}};T([u({type:Ii,context:0,implicit:!0,optional:!0})],qs.prototype,"certs",void 0);T([u({type:Gs,context:1,implicit:!0,optional:!0})],qs.prototype,"crls",void 0);var Uy,My=Uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Uy.prototype)}};My=Uy=T([A({type:_.Set,itemType:Mr})],My);var ki=class{constructor(e={}){this.version=gt.v0,this.recipientInfos=new ru,this.encryptedContentInfo=new ho,Object.assign(this,e)}};T([u({type:h.Integer})],ki.prototype,"version",void 0);T([u({type:qs,context:0,implicit:!0,optional:!0})],ki.prototype,"originatorInfo",void 0);T([u({type:ru})],ki.prototype,"recipientInfos",void 0);T([u({type:ho})],ki.prototype,"encryptedContentInfo",void 0);T([u({type:My,context:1,implicit:!0,optional:!0})],ki.prototype,"unprotectedAttrs",void 0);var Mx="1.2.840.113549.1.7.2";var Ky,Gf=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};Gf=Ky=T([A({type:_.Set,itemType:_i})],Gf);var Dn=class{constructor(e={}){this.version=gt.v0,this.digestAlgorithms=new Gf,this.encapContentInfo=new Oi,this.signerInfos=new Fc,Object.assign(this,e)}};T([u({type:h.Integer})],Dn.prototype,"version",void 0);T([u({type:Gf})],Dn.prototype,"digestAlgorithms",void 0);T([u({type:Oi})],Dn.prototype,"encapContentInfo",void 0);T([u({type:Ii,context:0,implicit:!0,optional:!0})],Dn.prototype,"certificates",void 0);T([u({type:Gs,context:1,implicit:!0,optional:!0})],Dn.prototype,"crls",void 0);T([u({type:Fc})],Dn.prototype,"signerInfos",void 0);var Ni="1.2.840.10045.2.1";var nu="1.2.840.10045.4.1",qf="1.2.840.10045.4.3.1",ou="1.2.840.10045.4.3.2",iu="1.2.840.10045.4.3.3",su="1.2.840.10045.4.3.4";var Hy="1.2.840.10045.3.1.7";var Vy="1.3.132.0.34";var $y="1.3.132.0.35";function au(r){return new H({algorithm:r})}var Hx=au(nu),OV=au(qf),Vx=au(ou),$x=au(iu),Fx=au(su);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 cu=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],cu.prototype,"fieldType",void 0);Be([u({type:h.Any})],cu.prototype,"parameters",void 0);cu=Be([A({type:_.Sequence})],cu);var Fy=class extends ae{};var zs=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.OctetString})],zs.prototype,"a",void 0);Be([u({type:h.OctetString})],zs.prototype,"b",void 0);Be([u({type:h.BitString,optional:!0})],zs.prototype,"seed",void 0);zs=Be([A({type:_.Sequence})],zs);var Wy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Wy||(Wy={}));var on=class{constructor(e={}){this.version=Wy.ecpVer1,Object.assign(this,e)}};Be([u({type:h.Integer})],on.prototype,"version",void 0);Be([u({type:cu})],on.prototype,"fieldID",void 0);Be([u({type:zs})],on.prototype,"curve",void 0);Be([u({type:Fy})],on.prototype,"base",void 0);Be([u({type:h.Integer,converter:me})],on.prototype,"order",void 0);Be([u({type:h.Integer,optional:!0})],on.prototype,"cofactor",void 0);on=Be([A({type:_.Sequence})],on);var sn=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],sn.prototype,"namedCurve",void 0);Be([u({type:h.Null})],sn.prototype,"implicitCurve",void 0);Be([u({type:on})],sn.prototype,"specifiedCurve",void 0);sn=Be([A({type:_.Choice})],sn);var Xs=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};Be([u({type:h.Integer})],Xs.prototype,"version",void 0);Be([u({type:ae})],Xs.prototype,"privateKey",void 0);Be([u({type:sn,context:0,optional:!0})],Xs.prototype,"parameters",void 0);Be([u({type:h.BitString,context:1,optional:!0})],Xs.prototype,"publicKey",void 0);var Di=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Be([u({type:h.Integer,converter:me})],Di.prototype,"r",void 0);Be([u({type:h.Integer,converter:me})],Di.prototype,"s",void 0);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 qt="1.2.840.113549.1.1",an=`${qt}.1`,Wx=`${qt}.7`,Gx=`${qt}.9`,bo=`${qt}.10`,qx=`${qt}.2`,zx=`${qt}.4`,Zs=`${qt}.5`,Xx=`${qt}.14`;var zf=`${qt}.11`,Ys=`${qt}.12`,Js=`${qt}.13`,Gy=`${qt}.15`,qy=`${qt}.16`,ji="1.3.14.3.2.26",Xf="2.16.840.1.101.3.4.2.4",Ri="2.16.840.1.101.3.4.2.1",Li="2.16.840.1.101.3.4.2.2",Ui="2.16.840.1.101.3.4.2.3",Zx="2.16.840.1.101.3.4.2.5",Yx="2.16.840.1.101.3.4.2.6",Jx="1.2.840.113549.2.2",Qx="1.2.840.113549.2.5",xo=`${qt}.8`;function st(r){return new H({algorithm:r,parameters:null})}var i7=st(Jx),s7=st(Qx),jn=st(ji),a7=st(Xf),c7=st(Ri),u7=st(Li),l7=st(Ui),f7=st(Zx),p7=st(Yx),Zf=new H({algorithm:xo,parameters:G.serialize(jn)}),zy=new H({algorithm:Gx,parameters:G.serialize(Ps.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),h7=st(an),d7=st(qx),y7=st(zx),m7=st(Zs),g7=st(Gy),w7=st(qy),b7=st(Ys),x7=st(Js),v7=st(Gy),_7=st(qy);var Qs=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:xo,parameters:G.serialize(jn)}),this.pSourceAlgorithm=new H(zy),Object.assign(this,e)}};Ce([u({type:H,context:0,defaultValue:jn})],Qs.prototype,"hashAlgorithm",void 0);Ce([u({type:H,context:1,defaultValue:Zf})],Qs.prototype,"maskGenAlgorithm",void 0);Ce([u({type:H,context:2,defaultValue:zy})],Qs.prototype,"pSourceAlgorithm",void 0);var O7=new H({algorithm:Wx,parameters:G.serialize(new Qs)});var cn=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:xo,parameters:G.serialize(jn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Ce([u({type:H,context:0,defaultValue:jn})],cn.prototype,"hashAlgorithm",void 0);Ce([u({type:H,context:1,defaultValue:Zf})],cn.prototype,"maskGenAlgorithm",void 0);Ce([u({type:h.Integer,context:2,defaultValue:20})],cn.prototype,"saltLength",void 0);Ce([u({type:h.Integer,context:3,defaultValue:1})],cn.prototype,"trailerField",void 0);var R7=new H({algorithm:bo,parameters:G.serialize(new cn)});var Mi=class{constructor(e={}){this.digestAlgorithm=new H,this.digest=new ae,Object.assign(this,e)}};Ce([u({type:H})],Mi.prototype,"digestAlgorithm",void 0);Ce([u({type:ae})],Mi.prototype,"digest",void 0);var Xy,ea=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Ce([u({type:h.Integer,converter:me})],ea.prototype,"prime",void 0);Ce([u({type:h.Integer,converter:me})],ea.prototype,"exponent",void 0);Ce([u({type:h.Integer,converter:me})],ea.prototype,"coefficient",void 0);var Yf=Xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};Yf=Xy=Ce([A({type:_.Sequence,itemType:ea})],Yf);var mr=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)}};Ce([u({type:h.Integer})],mr.prototype,"version",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"modulus",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"publicExponent",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"privateExponent",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"prime1",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"prime2",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"exponent1",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"exponent2",void 0);Ce([u({type:h.Integer,converter:me})],mr.prototype,"coefficient",void 0);Ce([u({type:Yf,optional:!0})],mr.prototype,"otherPrimeInfos",void 0);var ta=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Ce([u({type:h.Integer,converter:me})],ta.prototype,"modulus",void 0);Ce([u({type:h.Integer,converter:me})],ta.prototype,"publicExponent",void 0);function uu(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 Zy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Zy||(Zy={}));var wt=Zy;var vv=Vr(xv(),1),{__extends:na,__assign:d$,__rest:FC,__decorate:y$,__param:m$,__metadata:g$,__awaiter:_v,__generator:Sv,__exportStar:w$,__createBinding:b$,__values:lu,__read:fu,__spread:Kr,__spreadArrays:x$,__await:v$,__asyncGenerator:_$,__asyncDelegator:S$,__asyncValues:A$,__makeTemplateObject:E$,__importStar:C$,__importDefault:T$,__classPrivateFieldGet:I$,__classPrivateFieldSet:O$}=vv.default;var WC="injectionTokens";function Jy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(WC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function pu(r){return!!r.useClass}function oa(r){return!!r.useFactory}var ep=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,Kr(i))}};return this.reflectMethods.forEach(n),t},r}();function vo(r){return typeof r=="string"||typeof r=="symbol"}function Qy(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function tp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Av(r){return typeof r=="function"||r instanceof ep}function Ki(r){return!!r.useToken}function Hi(r){return r.useValue!=null}function Ev(r){return pu(r)||Hi(r)||Ki(r)||oa(r)}var GC=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}(),hu=GC;var qC=function(r){na(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(hu),Cv=qC;var zC=function(){function r(){this.scopedResolutions=new Map}return r}(),du=zC;function XC(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=" "),Kr([r],e.message.split(`
|
6
|
+
`)}`:`${t} :`}};Rb=it;Q.Constructed=Rb;it.NAME="CONSTRUCTED";var ff=class extends pt{fromBER(e,t,n){return t}toBER(e){return jr}};ff.override="EndOfContentValueBlock";var Lb,dc=class extends Je{constructor(e={}){super(e,ff),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Lb=dc;Q.EndOfContent=Lb;dc.NAME=pc;var Ub,kr=class extends Je{constructor(e={}){super(e,pt),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}`}};Ub=kr;Q.Null=Ub;kr.NAME="NULL";var pf=class extends Yr(pt){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=de.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=de.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,Wd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};pf.NAME="BooleanValueBlock";var Mb,Jo=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,pf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Mb=Jo;Q.Boolean=Mb;Jo.NAME="BOOLEAN";var hf=class extends Yr(Xr){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=Xr.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===pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==kb)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?Xr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};hf.NAME="OctetStringValueBlock";var Xd,Nr=class extends Je{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},hf),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=Is(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 it.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=de.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 Xd&&e.push(t.valueBlock.valueHexView);return de.BufferSourceConverter.concat(e)}};Xd=Nr;Q.OctetString=Xd;Nr.NAME=kb;var df=class extends Yr(Xr){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=Xr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Nb)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=de.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=Is(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 Xr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return jr;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}}};df.NAME="BitStringValueBlock";var Kb,Dr=class extends Je{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},df),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 it.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}`}}};Kb=Dr;Q.BitString=Kb;Dr.NAME=Nb;var Hb;function dC(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=sf(new Uint8Array([l%10]),i);break;default:i[s-p]=l%10}}return t[0]>0&&(i=sf(t,i)),i}function Bb(r){if(r>=lc.length)for(let e=lc.length;e<=r;e++){let t=new Uint8Array([0]),n=lc[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=sf(t,n)),lc.push(n)}return lc[r]}function yC(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 yc=class extends Yr(pt){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=Wd.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(Tb(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=yC(Bb(n),t),s="-";break;default:t=dC(t,Bb(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Ob.charAt(t[c]));return a===!1&&(s+=Ob.charAt(0)),s}};Hb=yc;yc.NAME="IntegerValueBlock";Object.defineProperty(Hb.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var fc,En=class extends Je{constructor(e={}){super(e,yc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return af(),BigInt(this.valueBlock.toString())}static fromBigInt(e){af();let t=BigInt(e),n=new Cs,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(de.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${de.Convert.ToHex(a)}`)+t,f=de.BufferSourceConverter.toUint8Array(de.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 fc({valueHex:n.final()})}convertToDER(){let e=new fc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new fc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};fc=En;Q.Integer=fc;En.NAME="INTEGER";var Vb,Qo=class extends En{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Vb=Qo;Q.Enumerated=Vb;Qo.NAME="ENUMERATED";var mc=class extends Yr(pt){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=de.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=Yo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){af();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=no(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;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=de.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}}};mc.NAME="sidBlock";var yf=class extends pt{constructor({value:e=Kt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new mc;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,jr;t.push(o)}return zd(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 mc;if(o>Number.MAX_SAFE_INTEGER){af();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}};yf.NAME="ObjectIdentifierValueBlock";var $b,ei=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,yf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};$b=ei;Q.ObjectIdentifier=$b;ei.NAME="OBJECT IDENTIFIER";var gc=class extends Yr(Sn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=de.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=Yo(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=no(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;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=de.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};gc.NAME="relativeSidBlock";var mf=class extends pt{constructor({value:e=Kt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new gc;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,jr;n.push(i)}return zd(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 gc;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}};mf.NAME="RelativeObjectIdentifierValueBlock";var Fb,wc=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,mf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Fb=wc;Q.RelativeObjectIdentifier=Fb;wc.NAME="RelativeObjectIdentifier";var Wb,Ht=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Wb=Ht;Q.Sequence=Wb;Ht.NAME="SEQUENCE";var Gb,Vt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Gb=Vt;Q.Set=Gb;Vt.NAME="SET";var gf=class extends Yr(pt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Kt}toJSON(){return{...super.toJSON(),value:this.value}}};gf.NAME="StringValueBlock";var wf=class extends gf{};wf.NAME="SimpleStringValueBlock";var Dt=class extends hc{constructor({...e}={}){super(e,wf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,de.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}};Dt.NAME="SIMPLE STRING";var bf=class extends Dt{fromBuffer(e){this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=de.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=de.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf8String(e)),this.valueBlock.value=e}};bf.NAME="Utf8StringValueBlock";var qb,ur=class extends bf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};qb=ur;Q.Utf8String=qb;ur.NAME="UTF8String";var xf=class extends Dt{fromBuffer(e){this.valueBlock.value=de.Convert.ToUtf16String(e),this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf16String(e))}};xf.NAME="BmpStringValueBlock";var zb,ti=class extends xf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};zb=ti;Q.BmpString=zb;ti.NAME="BMPString";var vf=class extends Dt{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=no(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}};vf.NAME="UniversalStringValueBlock";var Xb,ri=class extends vf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Xb=ri;Q.UniversalString=Xb;ri.NAME="UniversalString";var Zb,ni=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Zb=ni;Q.NumericString=Zb;ni.NAME="NumericString";var Yb,oi=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Yb=oi;Q.PrintableString=Yb;oi.NAME="PrintableString";var Jb,ii=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Jb=ii;Q.TeletexString=Jb;ii.NAME="TeletexString";var Qb,si=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Qb=si;Q.VideotexString=Qb;si.NAME="VideotexString";var ex,ai=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};ex=ai;Q.IA5String=ex;ai.NAME="IA5String";var tx,ci=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};tx=ci;Q.GraphicString=tx;ci.NAME="GraphicString";var rx,io=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};rx=io;Q.VisibleString=rx;io.NAME="VisibleString";var nx,ui=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};nx=ui;Q.GeneralString=nx;ui.NAME="GeneralString";var ox,li=class extends Dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ox=li;Q.CharacterString=ox;li.NAME="CharacterString";var ix,so=class extends io{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,de.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]=Mt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Mt(this.month,2),t[2]=Mt(this.day,2),t[3]=Mt(this.hour,2),t[4]=Mt(this.minute,2),t[5]=Mt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};ix=so;Q.UTCTime=ix;so.NAME="UTCTime";var sx,fi=class extends so{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(Mt(this.year,4)),t.push(Mt(this.month,2)),t.push(Mt(this.day,2)),t.push(Mt(this.hour,2)),t.push(Mt(this.minute,2)),t.push(Mt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Mt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};sx=fi;Q.GeneralizedTime=sx;fi.NAME="GeneralizedTime";var ax,bc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};ax=bc;Q.DATE=ax;bc.NAME="DATE";var cx,xc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};cx=xc;Q.TimeOfDay=cx;xc.NAME="TimeOfDay";var ux,vc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};ux=vc;Q.DateTime=ux;vc.NAME="DateTime";var lx,_c=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};lx=_c;Q.Duration=lx;_c.NAME="Duration";var fx,Sc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};fx=Sc;Q.TIME=fx;Sc.NAME="TIME";var Zr=class{constructor({name:e=Kt,optional:t=!1}={}){this.name=e,this.optional=t}},Ts=class extends Zr{constructor({value:e=[],...t}={}){super(t),this.value=e}},pi=class extends Zr{constructor({value:e=new Zr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},qd=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=de.BufferSourceConverter.toUint8Array(e)}constructor({data:e=_f}={}){this.dataView=de.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=de.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function oo(r,e,t){if(t instanceof Ts){for(let i of t.value)if(oo(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Gd)&&(i.name=t.name),i}}if(t instanceof Zr)return t.hasOwnProperty(Gd)&&(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(!(iC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(uC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(lC 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(sC)===!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(aC)===!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(cC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(oC 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(!(Pb 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,Kt),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 pi&&(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,Kt),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,Kt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof pi){if(s=oo(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,Kt),t.name&&delete r[t.name]),s;if(Gd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};fC 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=oo(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,Kt),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,Kt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Pb in e.valueBlock){let i=Is(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,Kt),t.name&&(delete r[t.name],s.name=t.name)),s}return oo(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function mC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Is(de.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:oo(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 Zd=Vr(_n()),Qr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Zd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Zd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Dr))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 Dr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Dr({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 Yd=Vr(_n()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Yd.BufferSourceConverter.isBufferSource(e)?this.buffer=Yd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Nr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Nr({valueHex:this.buffer})}toSchema(e){return new Nr({name:e})}};var gC={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}},wC={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new En({value:+r})},bC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Qo({value:r})},me={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new En({valueHex:r})};var xC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Dr({valueHex:r})},vC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ei({value:r})},_C={fromASN:r=>r.valueBlock.value,toASN:r=>new Jo({value:r})},Os={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Nr({valueHex:r})},px={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function lr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Jd=lr(ur),SC=lr(ti),AC=lr(ri),EC=lr(ni),CC=lr(oi),TC=lr(ii),IC=lr(si),OC=lr(ai),PC=lr(ci),BC=lr(io),kC=lr(ui),NC=lr(li),DC={fromASN:r=>r.toDate(),toASN:r=>new so({valueDate:r})},jC={fromASN:r=>r.toDate(),toASN:r=>new fi({valueDate:r})},RC={fromASN:()=>null,toASN:()=>new kr};function Ps(r){switch(r){case h.Any:return gC;case h.BitString:return xC;case h.BmpString:return SC;case h.Boolean:return _C;case h.CharacterString:return NC;case h.Enumerated:return bC;case h.GeneralString:return kC;case h.GeneralizedTime:return jC;case h.GraphicString:return PC;case h.IA5String:return OC;case h.Integer:return wC;case h.Null:return RC;case h.NumericString:return EC;case h.ObjectIdentifier:return vC;case h.OctetString:return Os;case h.PrintableString:return CC;case h.TeletexString:return TC;case h.UTCTime:return DC;case h.UniversalString:return AC;case h.Utf8String:return Jd;case h.VideotexString:return IC;case h.VisibleString:return BC;default:return null}}function fr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:fr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function ey(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:ey(t)}return!1}function hx(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 Sf=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=Jr[f];if(!p)throw new Error(`Cannot get ASN1 class by name '${f}'`);c=new p({name:a})}else fr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===_.Choice?c=new Zr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Zr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let f=s.repeated==="set"?Vt:Ht;c=new f({name:"",value:[new pi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||fr(s.type)){let f=s.repeated?it: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 it({name:f?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new it({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case _.Sequence:return new Ht({value:o,name:""});case _.Set:return new Vt({value:o,name:""});case _.Choice:return new Ts({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 jt=new Sf;var A=r=>e=>{let t;jt.has(e)?t=jt.get(e):(t=jt.createDefault(e),jt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;jt.has(e.constructor)?n=jt.get(e.constructor):(n=jt.createDefault(e.constructor),jt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Ps(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 Ac=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Ec=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(fr(t))return new t().fromASN(e);let o=jt.get(t);jt.cache(t);let i=o.schema;if(e.constructor===it&&o.type!==_.Choice){i=new it({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=oo({},e,i);if(!s.verified)throw new Ac(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(ey(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=Ps(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"||fr(p)){let y=(n=f.converter)!==null&&n!==void 0?n:fr(p)?new p:null;if(!y)throw new Error("Converter is empty");if(f.repeated)if(f.implicit){let m=f.repeated==="sequence"?Ht:Vt,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(fr(p))x=new p().toSchema("");else{let v=h[p],d=Jr[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 Ac&&o.schemas.push(t.name),o}}};var Cc=class r{static serialize(e){return e instanceof Je?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&fr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=jt.get(t);jt.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=Ps(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"&&hx(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"||fr(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 it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new it({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 Ht({value:o});break;case _.Set:i=new Vt({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"?Ht:Vt;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"?Ht:Vt;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 ty=Vr(_n());var q=class r{static serialize(e){return Cc.serialize(e)}static parse(e,t){return Ec.parse(e,t)}static toString(e){let t=ty.BufferSourceConverter.isBufferSource(e)?ty.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 dx=Vr(_n()),Tc=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(dx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var yx=Vr(_n()),ry,ny,oy,Qe=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};w([u({type:h.TeletexString})],Qe.prototype,"teletexString",void 0);w([u({type:h.PrintableString})],Qe.prototype,"printableString",void 0);w([u({type:h.UniversalString})],Qe.prototype,"universalString",void 0);w([u({type:h.Utf8String})],Qe.prototype,"utf8String",void 0);w([u({type:h.BmpString})],Qe.prototype,"bmpString",void 0);Qe=w([A({type:_.Choice})],Qe);var Bs=class extends Qe{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?yx.Convert.ToHex(this.anyValue):super.toString())}};w([u({type:h.IA5String})],Bs.prototype,"ia5String",void 0);w([u({type:h.Any})],Bs.prototype,"anyValue",void 0);Bs=w([A({type:_.Choice})],Bs);var hi=class{constructor(e={}){this.type="",this.value=new Bs,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],hi.prototype,"type",void 0);w([u({type:Bs})],hi.prototype,"value",void 0);var ao=ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};ao=ry=w([A({type:_.Set,itemType:hi})],ao);var iy=ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};iy=ny=w([A({type:_.Sequence,itemType:ao})],iy);var Pe=oy=class extends iy{constructor(e){super(e),Object.setPrototypeOf(this,oy.prototype)}};Pe=oy=w([A({type:_.Sequence})],Pe);var LC={fromASN:r=>Tc.toString(Os.fromASN(r)),toASN:r=>Os.toASN(Tc.fromString(r))},co=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],co.prototype,"typeId",void 0);w([u({type:h.Any,context:0})],co.prototype,"value",void 0);var Ic=class{constructor(e={}){this.partyName=new Qe,Object.assign(this,e)}};w([u({type:Qe,optional:!0,context:0,implicit:!0})],Ic.prototype,"nameAssigner",void 0);w([u({type:Qe,context:1,implicit:!0})],Ic.prototype,"partyName",void 0);var ue=class{constructor(e={}){Object.assign(this,e)}};w([u({type:co,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:Ic,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:LC})],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 uo="1.3.6.1.5.5.7",lo=`${uo}.1`,mx=`${uo}.2`,di=`${uo}.3`,Af=`${uo}.48`,z3=`${mx}.1`,X3=`${mx}.2`,sy=`${Af}.1`,ay=`${Af}.2`,cy=`${Af}.3`,uy=`${Af}.5`,fe="2.5.29";var ly,Ef=`${lo}.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 yi=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};yi=ly=w([A({type:_.Sequence,itemType:In})],yi);var Cf=`${fe}.35`,mi=class extends ae{},en=class{constructor(e={}){e&&Object.assign(this,e)}};w([u({type:mi,context:0,optional:!0,implicit:!0})],en.prototype,"keyIdentifier",void 0);w([u({type:ue,context:1,optional:!0,implicit:!0,repeated:"sequence"})],en.prototype,"authorityCertIssuer",void 0);w([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:me})],en.prototype,"authorityCertSerialNumber",void 0);var Tf=`${fe}.19`,gi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};w([u({type:h.Boolean,defaultValue:!1})],gi.prototype,"cA",void 0);w([u({type:h.Integer,optional:!0})],gi.prototype,"pathLenConstraint",void 0);var fy,Ke=fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};Ke=fy=w([A({type:_.Sequence,itemType:ue})],Ke);var py,UC=`${fe}.29`,gx=py=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};gx=py=w([A({type:_.Sequence})],gx);var hy,Of=`${fe}.32`,TD=`${Of}.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 Oc=class{constructor(e={}){this.organization=new On,this.noticeNumbers=[],Object.assign(this,e)}};w([u({type:On})],Oc.prototype,"organization",void 0);w([u({type:h.Integer,repeated:"sequence"})],Oc.prototype,"noticeNumbers",void 0);var Pc=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Oc,optional:!0})],Pc.prototype,"noticeRef",void 0);w([u({type:On,optional:!0})],Pc.prototype,"explicitText",void 0);var If=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.IA5String})],If.prototype,"cPSuri",void 0);w([u({type:Pc})],If.prototype,"userNotice",void 0);If=w([A({type:_.Choice})],If);var Bc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Bc.prototype,"policyQualifierId",void 0);w([u({type:h.Any})],Bc.prototype,"qualifier",void 0);var wi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],wi.prototype,"policyIdentifier",void 0);w([u({type:Bc,repeated:"sequence",optional:!0})],wi.prototype,"policyQualifiers",void 0);var kc=hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};kc=hy=w([A({type:_.Sequence,itemType:wi})],kc);var jD=`${fe}.20`,Nc=class{constructor(e=0){this.value=e}};w([u({type:h.Integer})],Nc.prototype,"value",void 0);Nc=w([A({type:_.Choice})],Nc);var VD=`${fe}.27`,wx=class extends Nc{};wx=w([A({type:_.Choice})],wx);var dy,Pf=`${fe}.31`,Rr;(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"})(Rr||(Rr={}));var Dc=class extends Qr{toJSON(){let e=[],t=this.toNumber();return t&Rr.aACompromise&&e.push("aACompromise"),t&Rr.affiliationChanged&&e.push("affiliationChanged"),t&Rr.cACompromise&&e.push("cACompromise"),t&Rr.certificateHold&&e.push("certificateHold"),t&Rr.cessationOfOperation&&e.push("cessationOfOperation"),t&Rr.keyCompromise&&e.push("keyCompromise"),t&Rr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Rr.superseded&&e.push("superseded"),t&Rr.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:ao,context:1,implicit:!0})],Pn.prototype,"nameRelativeToCRLIssuer",void 0);Pn=w([A({type:_.Choice})],Pn);var tn=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Pn,context:0,optional:!0})],tn.prototype,"distributionPoint",void 0);w([u({type:Dc,context:1,optional:!0,implicit:!0})],tn.prototype,"reasons",void 0);w([u({type:ue,context:2,optional:!0,repeated:"sequence",implicit:!0})],tn.prototype,"cRLIssuer",void 0);var fo=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};fo=dy=w([A({type:_.Sequence,itemType:tn})],fo);var yy,nj=`${fe}.46`,bx=yy=class extends fo{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};bx=yy=w([A({type:_.Sequence,itemType:tn})],bx);var fj=`${fe}.28`,tr=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};tr.ONLY=!1;w([u({type:Pn,context:0,optional:!0})],tr.prototype,"distributionPoint",void 0);w([u({type:h.Boolean,context:1,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsUserCerts",void 0);w([u({type:h.Boolean,context:2,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsCACerts",void 0);w([u({type:Dc,context:3,optional:!0,implicit:!0})],tr.prototype,"onlySomeReasons",void 0);w([u({type:h.Boolean,context:4,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"indirectCRL",void 0);w([u({type:h.Boolean,context:5,defaultValue:tr.ONLY,implicit:!0})],tr.prototype,"onlyContainsAttributeCerts",void 0);var xx=`${fe}.21`,jc;(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"})(jc||(jc={}));var Rc=class{constructor(e=jc.unspecified){this.reason=jc.unspecified,this.reason=e}toJSON(){return jc[this.reason]}toString(){return this.toJSON()}};w([u({type:h.Enumerated})],Rc.prototype,"reason",void 0);Rc=w([A({type:_.Choice})],Rc);var my,Bf=`${fe}.37`,Lc=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};Lc=my=w([A({type:_.Sequence,itemType:h.ObjectIdentifier})],Lc);var _j=`${Bf}.0`,vx=`${di}.1`,_x=`${di}.2`,Sx=`${di}.3`,Ax=`${di}.4`,Ex=`${di}.8`,Cx=`${di}.9`;var Tj=`${fe}.54`,gy=class{constructor(e=new ArrayBuffer(0)){this.value=e}};w([u({type:h.Integer,converter:me})],gy.prototype,"value",void 0);gy=w([A({type:_.Choice})],gy);var Tx=`${fe}.24`,Uc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};w([u({type:h.GeneralizedTime})],Uc.prototype,"value",void 0);Uc=w([A({type:_.Choice})],Uc);var wy,Mj=`${fe}.18`,Ix=wy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Ix=wy=w([A({type:_.Sequence})],Ix);var kf=`${fe}.15`,Lr;(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"})(Lr||(Lr={}));var ks=class extends Qr{toJSON(){let e=this.toNumber(),t=[];return e&Lr.cRLSign&&t.push("crlSign"),e&Lr.dataEncipherment&&t.push("dataEncipherment"),e&Lr.decipherOnly&&t.push("decipherOnly"),e&Lr.digitalSignature&&t.push("digitalSignature"),e&Lr.encipherOnly&&t.push("encipherOnly"),e&Lr.keyAgreement&&t.push("keyAgreement"),e&Lr.keyCertSign&&t.push("keyCertSign"),e&Lr.keyEncipherment&&t.push("keyEncipherment"),e&Lr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var by,Xj=`${fe}.30`,Ns=class{constructor(e={}){this.base=new ue,this.minimum=0,Object.assign(this,e)}};w([u({type:ue})],Ns.prototype,"base",void 0);w([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Ns.prototype,"minimum",void 0);w([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Ns.prototype,"maximum",void 0);var Nf=by=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};Nf=by=w([A({type:_.Sequence,itemType:Ns})],Nf);var Df=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Nf,context:0,optional:!0,implicit:!0})],Df.prototype,"permittedSubtrees",void 0);w([u({type:Nf,context:1,optional:!0,implicit:!0})],Df.prototype,"excludedSubtrees",void 0);var tR=`${fe}.36`,jf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:me})],jf.prototype,"requireExplicitPolicy",void 0);w([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:me})],jf.prototype,"inhibitPolicyMapping",void 0);var xy,sR=`${fe}.33`,Mc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Mc.prototype,"issuerDomainPolicy",void 0);w([u({type:h.ObjectIdentifier})],Mc.prototype,"subjectDomainPolicy",void 0);var Ox=xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};Ox=xy=w([A({type:_.Sequence,itemType:Mc})],Ox);var vy,_y=`${fe}.17`,Rf=vy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,vy.prototype)}};Rf=vy=w([A({type:_.Sequence})],Rf);var ht=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],ht.prototype,"type",void 0);w([u({type:h.Any,repeated:"set"})],ht.prototype,"values",void 0);var Sy,_R=`${fe}.9`,Px=Sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};Px=Sy=w([A({type:_.Sequence,itemType:ht})],Px);var Ay=`${fe}.14`,$t=class extends mi{};var BR=`${fe}.16`,Lf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],Lf.prototype,"notBefore",void 0);w([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],Lf.prototype,"notAfter",void 0);var Kc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Kc||(Kc={}));var Uf=class extends Qr{toJSON(){let e=[],t=this.toNumber();return t&Kc.pKIXCertificate&&e.push("pKIXCertificate"),t&Kc.newExtensions&&e.push("newExtensions"),t&Kc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Mf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Uf,Object.assign(this,e)}};w([u({type:h.GeneralString})],Mf.prototype,"entrustVers",void 0);w([u({type:Uf})],Mf.prototype,"entrustInfoFlags",void 0);var Ey,KR=`${lo}.11`,Bx=Ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};Bx=Ey=w([A({type:_.Sequence,itemType:In})],Bx);var kx=Vr(_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&&kx.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 dt=class{constructor(e={}){this.algorithm=new H,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:H})],dt.prototype,"algorithm",void 0);w([u({type:h.BitString})],dt.prototype,"subjectPublicKey",void 0);var We=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})],We.prototype,"utcTime",void 0);w([u({type:h.GeneralizedTime})],We.prototype,"generalTime",void 0);We=w([A({type:_.Choice})],We);var Bn=class{constructor(e){this.notBefore=new We(new Date),this.notAfter=new We(new Date),e&&(this.notBefore=new We(e.notBefore),this.notAfter=new We(e.notAfter))}};w([u({type:We})],Bn.prototype,"notBefore",void 0);w([u({type:We})],Bn.prototype,"notAfter",void 0);var Cy,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};yt.CRITICAL=!1;w([u({type:h.ObjectIdentifier})],yt.prototype,"extnID",void 0);w([u({type:h.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);w([u({type:ae})],yt.prototype,"extnValue",void 0);var rr=Cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};rr=Cy=w([A({type:_.Sequence,itemType:yt})],rr);var rn;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(rn||(rn={}));var mt=class{constructor(e={}){this.version=rn.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 dt,Object.assign(this,e)}};w([u({type:h.Integer,context:0,defaultValue:rn.v1})],mt.prototype,"version",void 0);w([u({type:h.Integer,converter:me})],mt.prototype,"serialNumber",void 0);w([u({type:H})],mt.prototype,"signature",void 0);w([u({type:Pe})],mt.prototype,"issuer",void 0);w([u({type:Bn})],mt.prototype,"validity",void 0);w([u({type:Pe})],mt.prototype,"subject",void 0);w([u({type:dt})],mt.prototype,"subjectPublicKeyInfo",void 0);w([u({type:h.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);w([u({type:h.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);w([u({type:rr,context:3,optional:!0})],mt.prototype,"extensions",void 0);var pr=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:mt})],pr.prototype,"tbsCertificate",void 0);w([u({type:H})],pr.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],pr.prototype,"signatureValue",void 0);var bi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new We,Object.assign(this,e)}};w([u({type:h.Integer,converter:me})],bi.prototype,"userCertificate",void 0);w([u({type:We})],bi.prototype,"revocationDate",void 0);w([u({type:yt,optional:!0,repeated:"sequence"})],bi.prototype,"crlEntryExtensions",void 0);var nr=class{constructor(e={}){this.signature=new H,this.issuer=new Pe,this.thisUpdate=new We,Object.assign(this,e)}};w([u({type:h.Integer,optional:!0})],nr.prototype,"version",void 0);w([u({type:H})],nr.prototype,"signature",void 0);w([u({type:Pe})],nr.prototype,"issuer",void 0);w([u({type:We})],nr.prototype,"thisUpdate",void 0);w([u({type:We,optional:!0})],nr.prototype,"nextUpdate",void 0);w([u({type:bi,repeated:"sequence",optional:!0})],nr.prototype,"revokedCertificates",void 0);w([u({type:yt,optional:!0,context:0,repeated:"sequence"})],nr.prototype,"crlExtensions",void 0);var xi=class{constructor(e={}){this.tbsCertList=new nr,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:nr})],xi.prototype,"tbsCertList",void 0);w([u({type:H})],xi.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],xi.prototype,"signature",void 0);var $=Vr(_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 Ur=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:Pe})],Ur.prototype,"issuer",void 0);C([u({type:h.Integer,converter:me})],Ur.prototype,"serialNumber",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};C([u({type:$t,context:0,implicit:!0})],vi.prototype,"subjectKeyIdentifier",void 0);C([u({type:Ur})],vi.prototype,"issuerAndSerialNumber",void 0);vi=C([A({type:_.Choice})],vi);var gt;(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"})(gt||(gt={}));var _i=class extends H{};_i=C([A({type:_.Sequence})],_i);var Hc=class extends H{};Hc=C([A({type:_.Sequence})],Hc);var Ft=class extends H{};Ft=C([A({type:_.Sequence})],Ft);var Vc=class extends H{};Vc=C([A({type:_.Sequence})],Vc);var Dx=class extends H{};Dx=C([A({type:_.Sequence})],Dx);var Kf=class extends H{};Kf=C([A({type:_.Sequence})],Kf);var Mr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Mr.prototype,"attrType",void 0);C([u({type:h.Any,repeated:"set"})],Mr.prototype,"attrValues",void 0);var Ty,Wt=class{constructor(e={}){this.version=gt.v0,this.sid=new vi,this.digestAlgorithm=new _i,this.signatureAlgorithm=new Hc,this.signature=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],Wt.prototype,"version",void 0);C([u({type:vi})],Wt.prototype,"sid",void 0);C([u({type:_i})],Wt.prototype,"digestAlgorithm",void 0);C([u({type:Mr,repeated:"set",context:0,implicit:!0,optional:!0})],Wt.prototype,"signedAttrs",void 0);C([u({type:Hc})],Wt.prototype,"signatureAlgorithm",void 0);C([u({type:ae})],Wt.prototype,"signature",void 0);C([u({type:Mr,repeated:"set",context:1,implicit:!0,optional:!0})],Wt.prototype,"unsignedAttrs",void 0);var $c=Ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};$c=Ty=C([A({type:_.Set,itemType:Wt})],$c);var jx=class extends We{};jx=C([A({type:_.Choice})],jx);var Rx=class extends Wt{};Rx=C([A({type:_.Sequence})],Rx);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 Fc=class{constructor(e={}){this.acIssuer=new ue,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:ue})],Fc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Fc.prototype,"acSerial",void 0);z([u({type:ht,repeated:"sequence"})],Fc.prototype,"attrs",void 0);var Iy,Wc=Iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Iy.prototype)}};Wc=Iy=z([A({type:_.Sequence,itemType:h.ObjectIdentifier})],Wc);var Ds=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],Ds.prototype,"pathLenConstraint",void 0);z([u({type:Wc,implicit:!0,context:0,optional:!0})],Ds.prototype,"permittedAttrs",void 0);z([u({type:Wc,implicit:!0,context:1,optional:!0})],Ds.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],Ds.prototype,"permitUnSpecified",void 0);var hr=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})],hr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:me})],hr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],hr.prototype,"issuerUID",void 0);var Oy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(Oy||(Oy={}));var dr=class{constructor(e={}){this.digestedObjectType=Oy.publicKey,this.digestAlgorithm=new H,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],dr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],dr.prototype,"otherObjectTypeID",void 0);z([u({type:H})],dr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],dr.prototype,"objectDigest",void 0);var Si=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,optional:!0})],Si.prototype,"issuerName",void 0);z([u({type:hr,context:0,implicit:!0,optional:!0})],Si.prototype,"baseCertificateID",void 0);z([u({type:dr,context:1,implicit:!0,optional:!0})],Si.prototype,"objectDigestInfo",void 0);var Ai=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,repeated:"sequence"})],Ai.prototype,"v1Form",void 0);z([u({type:Si,context:0,implicit:!0})],Ai.prototype,"v2Form",void 0);Ai=z([A({type:_.Choice})],Ai);var Ei=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Ei.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Ei.prototype,"notAfterTime",void 0);var po=class{constructor(e={}){Object.assign(this,e)}};z([u({type:hr,implicit:!0,context:0,optional:!0})],po.prototype,"baseCertificateID",void 0);z([u({type:Ke,implicit:!0,context:1,optional:!0})],po.prototype,"entityName",void 0);z([u({type:dr,implicit:!0,context:2,optional:!0})],po.prototype,"objectDigestInfo",void 0);var Py;(function(r){r[r.v2=1]="v2"})(Py||(Py={}));var Gt=class{constructor(e={}){this.version=Py.v2,this.holder=new po,this.issuer=new Ai,this.signature=new H,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Ei,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],Gt.prototype,"version",void 0);z([u({type:po})],Gt.prototype,"holder",void 0);z([u({type:Ai})],Gt.prototype,"issuer",void 0);z([u({type:H})],Gt.prototype,"signature",void 0);z([u({type:h.Integer,converter:me})],Gt.prototype,"serialNumber",void 0);z([u({type:Ei})],Gt.prototype,"attrCertValidityPeriod",void 0);z([u({type:ht,repeated:"sequence"})],Gt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],Gt.prototype,"issuerUniqueID",void 0);z([u({type:rr,optional:!0})],Gt.prototype,"extensions",void 0);var Ci=class{constructor(e={}){this.acinfo=new Gt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Gt})],Ci.prototype,"acinfo",void 0);z([u({type:H})],Ci.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Ci.prototype,"signatureValue",void 0);var Gc;(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"})(Gc||(Gc={}));var js=class extends Qr{};var Rs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],Rs.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],Rs.prototype,"value",void 0);var qc=class{constructor(e={}){this.policyId="",this.classList=new js(Gc.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],qc.prototype,"policyId",void 0);z([u({type:js,defaultValue:new js(Gc.unclassified)})],qc.prototype,"classList",void 0);z([u({type:Rs,repeated:"set"})],qc.prototype,"securityCategories",void 0);var Ls=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ae})],Ls.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],Ls.prototype,"oid",void 0);z([u({type:h.Utf8String})],Ls.prototype,"string",void 0);var Hf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],Hf.prototype,"policyAuthority",void 0);z([u({type:Ls,repeated:"sequence"})],Hf.prototype,"values",void 0);var _9=`${lo}.4`,S9=`${lo}.6`,A9=`${lo}.10`,E9=`${fe}.55`,zc=`${uo}.10`,C9=`${zc}.1`,T9=`${zc}.2`,I9=`${zc}.3`,O9=`${zc}.4`,P9=`${zc}.6`,By="2.5.4",B9=`${By}.72`;var ky,Us=class{constructor(e={}){this.targetCertificate=new hr,Object.assign(this,e)}};z([u({type:hr})],Us.prototype,"targetCertificate",void 0);z([u({type:ue,optional:!0})],Us.prototype,"targetName",void 0);z([u({type:dr,optional:!0})],Us.prototype,"certDigestInfo",void 0);var Ms=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ue,context:0,implicit:!0})],Ms.prototype,"targetName",void 0);z([u({type:ue,context:1,implicit:!0})],Ms.prototype,"targetGroup",void 0);z([u({type:Us,context:2,implicit:!0})],Ms.prototype,"targetCert",void 0);Ms=z([A({type:_.Choice})],Ms);var Vf=ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Vf=ky=z([A({type:_.Sequence,itemType:Ms})],Vf);var Ny,Lx=Ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};Lx=Ny=z([A({type:_.Sequence,itemType:Vf})],Lx);var $f=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ke,implicit:!0,context:0,optional:!0})],$f.prototype,"roleAuthority",void 0);z([u({type:ue,implicit:!0,context:1})],$f.prototype,"roleName",void 0);var Xc=class{constructor(e={}){this.service=new ue,this.ident=new ue,Object.assign(this,e)}};z([u({type:ue})],Xc.prototype,"service",void 0);z([u({type:ue})],Xc.prototype,"ident",void 0);z([u({type:ae,optional:!0})],Xc.prototype,"authInfo",void 0);var Dy,Zc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Zc.prototype,"otherCertFormat",void 0);C([u({type:h.Any})],Zc.prototype,"otherCert",void 0);var Ti=class{constructor(e={}){Object.assign(this,e)}};C([u({type:pr})],Ti.prototype,"certificate",void 0);C([u({type:Ci,context:2,implicit:!0})],Ti.prototype,"v2AttrCert",void 0);C([u({type:Zc,context:3,implicit:!0})],Ti.prototype,"other",void 0);Ti=C([A({type:_.Choice})],Ti);var Ii=Dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};Ii=Dy=C([A({type:_.Set,itemType:Ti})],Ii);var yr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],yr.prototype,"contentType",void 0);C([u({type:h.Any,context:0})],yr.prototype,"content",void 0);var Ks=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae})],Ks.prototype,"single",void 0);C([u({type:h.Any})],Ks.prototype,"any",void 0);Ks=C([A({type:_.Choice})],Ks);var Oi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Oi.prototype,"eContentType",void 0);C([u({type:Ks,context:0,optional:!0})],Oi.prototype,"eContent",void 0);var Yc=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae,context:0,implicit:!0,optional:!0})],Yc.prototype,"value",void 0);C([u({type:ae,converter:px,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Yc.prototype,"constructedValue",void 0);Yc=C([A({type:_.Choice})],Yc);var ho=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Vc,Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],ho.prototype,"contentType",void 0);C([u({type:Vc})],ho.prototype,"contentEncryptionAlgorithm",void 0);C([u({type:Yc,optional:!0})],ho.prototype,"encryptedContent",void 0);var yo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],yo.prototype,"keyAttrId",void 0);C([u({type:h.Any,optional:!0})],yo.prototype,"keyAttr",void 0);var jy,Hs=class{constructor(e={}){this.subjectKeyIdentifier=new $t,Object.assign(this,e)}};C([u({type:$t})],Hs.prototype,"subjectKeyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Hs.prototype,"date",void 0);C([u({type:yo,optional:!0})],Hs.prototype,"other",void 0);var Vs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Hs,context:0,implicit:!0,optional:!0})],Vs.prototype,"rKeyId",void 0);C([u({type:Ur,optional:!0})],Vs.prototype,"issuerAndSerialNumber",void 0);Vs=C([A({type:_.Choice})],Vs);var Jc=class{constructor(e={}){this.rid=new Vs,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:Vs})],Jc.prototype,"rid",void 0);C([u({type:ae})],Jc.prototype,"encryptedKey",void 0);var Ff=jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};Ff=jy=C([A({type:_.Sequence,itemType:Jc})],Ff);var Qc=class{constructor(e={}){this.algorithm=new H,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:H})],Qc.prototype,"algorithm",void 0);C([u({type:h.BitString})],Qc.prototype,"publicKey",void 0);var Pi=class{constructor(e={}){Object.assign(this,e)}};C([u({type:$t,context:0,implicit:!0,optional:!0})],Pi.prototype,"subjectKeyIdentifier",void 0);C([u({type:Qc,context:1,implicit:!0,optional:!0})],Pi.prototype,"originatorKey",void 0);C([u({type:Ur,optional:!0})],Pi.prototype,"issuerAndSerialNumber",void 0);Pi=C([A({type:_.Choice})],Pi);var kn=class{constructor(e={}){this.version=gt.v3,this.originator=new Pi,this.keyEncryptionAlgorithm=new Ft,this.recipientEncryptedKeys=new Ff,Object.assign(this,e)}};C([u({type:h.Integer})],kn.prototype,"version",void 0);C([u({type:Pi,context:0})],kn.prototype,"originator",void 0);C([u({type:ae,context:1,optional:!0})],kn.prototype,"ukm",void 0);C([u({type:Ft})],kn.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:Ff})],kn.prototype,"recipientEncryptedKeys",void 0);var $s=class{constructor(e={}){Object.assign(this,e)}};C([u({type:$t,context:0,implicit:!0})],$s.prototype,"subjectKeyIdentifier",void 0);C([u({type:Ur})],$s.prototype,"issuerAndSerialNumber",void 0);$s=C([A({type:_.Choice})],$s);var mo=class{constructor(e={}){this.version=gt.v0,this.rid=new $s,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],mo.prototype,"version",void 0);C([u({type:$s})],mo.prototype,"rid",void 0);C([u({type:Ft})],mo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],mo.prototype,"encryptedKey",void 0);var Bi=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};C([u({type:ae})],Bi.prototype,"keyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Bi.prototype,"date",void 0);C([u({type:yo,optional:!0})],Bi.prototype,"other",void 0);var go=class{constructor(e={}){this.version=gt.v4,this.kekid=new Bi,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],go.prototype,"version",void 0);C([u({type:Bi})],go.prototype,"kekid",void 0);C([u({type:Ft})],go.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],go.prototype,"encryptedKey",void 0);var wo=class{constructor(e={}){this.version=gt.v0,this.keyEncryptionAlgorithm=new Ft,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],wo.prototype,"version",void 0);C([u({type:Kf,context:0,optional:!0})],wo.prototype,"keyDerivationAlgorithm",void 0);C([u({type:Ft})],wo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],wo.prototype,"encryptedKey",void 0);var eu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],eu.prototype,"oriType",void 0);C([u({type:h.Any})],eu.prototype,"oriValue",void 0);var Nn=class{constructor(e={}){Object.assign(this,e)}};C([u({type:mo,optional:!0})],Nn.prototype,"ktri",void 0);C([u({type:kn,context:1,implicit:!0,optional:!0})],Nn.prototype,"kari",void 0);C([u({type:go,context:2,implicit:!0,optional:!0})],Nn.prototype,"kekri",void 0);C([u({type:wo,context:3,implicit:!0,optional:!0})],Nn.prototype,"pwri",void 0);C([u({type:eu,context:4,implicit:!0,optional:!0})],Nn.prototype,"ori",void 0);Nn=C([A({type:_.Choice})],Nn);var Ry,tu=Ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ry.prototype)}};tu=Ry=C([A({type:_.Set,itemType:Nn})],tu);var Ly,Ux=`${uo}.16`,PH=`${Ux}.2`,BH=`${Ux}.4`,Fs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Fs.prototype,"otherRevInfoFormat",void 0);C([u({type:h.Any})],Fs.prototype,"otherRevInfo",void 0);var Wf=class{constructor(e={}){this.other=new Fs,Object.assign(this,e)}};C([u({type:Fs,context:1,implicit:!0})],Wf.prototype,"other",void 0);Wf=C([A({type:_.Choice})],Wf);var Ws=Ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Ws=Ly=C([A({type:_.Set,itemType:Wf})],Ws);var Gs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Ii,context:0,implicit:!0,optional:!0})],Gs.prototype,"certs",void 0);C([u({type:Ws,context:1,implicit:!0,optional:!0})],Gs.prototype,"crls",void 0);var Uy,My=Uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Uy.prototype)}};My=Uy=C([A({type:_.Set,itemType:Mr})],My);var ki=class{constructor(e={}){this.version=gt.v0,this.recipientInfos=new tu,this.encryptedContentInfo=new ho,Object.assign(this,e)}};C([u({type:h.Integer})],ki.prototype,"version",void 0);C([u({type:Gs,context:0,implicit:!0,optional:!0})],ki.prototype,"originatorInfo",void 0);C([u({type:tu})],ki.prototype,"recipientInfos",void 0);C([u({type:ho})],ki.prototype,"encryptedContentInfo",void 0);C([u({type:My,context:1,implicit:!0,optional:!0})],ki.prototype,"unprotectedAttrs",void 0);var Mx="1.2.840.113549.1.7.2";var Ky,Gf=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};Gf=Ky=C([A({type:_.Set,itemType:_i})],Gf);var Dn=class{constructor(e={}){this.version=gt.v0,this.digestAlgorithms=new Gf,this.encapContentInfo=new Oi,this.signerInfos=new $c,Object.assign(this,e)}};C([u({type:h.Integer})],Dn.prototype,"version",void 0);C([u({type:Gf})],Dn.prototype,"digestAlgorithms",void 0);C([u({type:Oi})],Dn.prototype,"encapContentInfo",void 0);C([u({type:Ii,context:0,implicit:!0,optional:!0})],Dn.prototype,"certificates",void 0);C([u({type:Ws,context:1,implicit:!0,optional:!0})],Dn.prototype,"crls",void 0);C([u({type:$c})],Dn.prototype,"signerInfos",void 0);var Ni="1.2.840.10045.2.1";var ru="1.2.840.10045.4.1",qf="1.2.840.10045.4.3.1",nu="1.2.840.10045.4.3.2",ou="1.2.840.10045.4.3.3",iu="1.2.840.10045.4.3.4";var Hy="1.2.840.10045.3.1.7";var Vy="1.3.132.0.34";var $y="1.3.132.0.35";function su(r){return new H({algorithm:r})}var Hx=su(ru),TV=su(qf),Vx=su(nu),$x=su(ou),Fx=su(iu);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 au=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],au.prototype,"fieldType",void 0);Be([u({type:h.Any})],au.prototype,"parameters",void 0);au=Be([A({type:_.Sequence})],au);var Fy=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 Wy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Wy||(Wy={}));var nn=class{constructor(e={}){this.version=Wy.ecpVer1,Object.assign(this,e)}};Be([u({type:h.Integer})],nn.prototype,"version",void 0);Be([u({type:au})],nn.prototype,"fieldID",void 0);Be([u({type:qs})],nn.prototype,"curve",void 0);Be([u({type:Fy})],nn.prototype,"base",void 0);Be([u({type:h.Integer,converter:me})],nn.prototype,"order",void 0);Be([u({type:h.Integer,optional:!0})],nn.prototype,"cofactor",void 0);nn=Be([A({type:_.Sequence})],nn);var on=class{constructor(e={}){Object.assign(this,e)}};Be([u({type:h.ObjectIdentifier})],on.prototype,"namedCurve",void 0);Be([u({type:h.Null})],on.prototype,"implicitCurve",void 0);Be([u({type:nn})],on.prototype,"specifiedCurve",void 0);on=Be([A({type:_.Choice})],on);var zs=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};Be([u({type:h.Integer})],zs.prototype,"version",void 0);Be([u({type:ae})],zs.prototype,"privateKey",void 0);Be([u({type:on,context:0,optional:!0})],zs.prototype,"parameters",void 0);Be([u({type:h.BitString,context:1,optional:!0})],zs.prototype,"publicKey",void 0);var Di=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Be([u({type:h.Integer,converter:me})],Di.prototype,"r",void 0);Be([u({type:h.Integer,converter:me})],Di.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 qt="1.2.840.113549.1.1",sn=`${qt}.1`,Wx=`${qt}.7`,Gx=`${qt}.9`,bo=`${qt}.10`,qx=`${qt}.2`,zx=`${qt}.4`,Xs=`${qt}.5`,Xx=`${qt}.14`;var zf=`${qt}.11`,Zs=`${qt}.12`,Ys=`${qt}.13`,Gy=`${qt}.15`,qy=`${qt}.16`,ji="1.3.14.3.2.26",Xf="2.16.840.1.101.3.4.2.4",Ri="2.16.840.1.101.3.4.2.1",Li="2.16.840.1.101.3.4.2.2",Ui="2.16.840.1.101.3.4.2.3",Zx="2.16.840.1.101.3.4.2.5",Yx="2.16.840.1.101.3.4.2.6",Jx="1.2.840.113549.2.2",Qx="1.2.840.113549.2.5",xo=`${qt}.8`;function st(r){return new H({algorithm:r,parameters:null})}var n7=st(Jx),o7=st(Qx),jn=st(ji),i7=st(Xf),s7=st(Ri),a7=st(Li),c7=st(Ui),u7=st(Zx),l7=st(Yx),Zf=new H({algorithm:xo,parameters:q.serialize(jn)}),zy=new H({algorithm:Gx,parameters:q.serialize(Os.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),f7=st(sn),p7=st(qx),h7=st(zx),d7=st(Xs),y7=st(Gy),m7=st(qy),g7=st(Zs),w7=st(Ys),b7=st(Gy),x7=st(qy);var Js=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:xo,parameters:q.serialize(jn)}),this.pSourceAlgorithm=new H(zy),Object.assign(this,e)}};Ee([u({type:H,context:0,defaultValue:jn})],Js.prototype,"hashAlgorithm",void 0);Ee([u({type:H,context:1,defaultValue:Zf})],Js.prototype,"maskGenAlgorithm",void 0);Ee([u({type:H,context:2,defaultValue:zy})],Js.prototype,"pSourceAlgorithm",void 0);var T7=new H({algorithm:Wx,parameters:q.serialize(new Js)});var an=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:xo,parameters:q.serialize(jn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Ee([u({type:H,context:0,defaultValue:jn})],an.prototype,"hashAlgorithm",void 0);Ee([u({type:H,context:1,defaultValue:Zf})],an.prototype,"maskGenAlgorithm",void 0);Ee([u({type:h.Integer,context:2,defaultValue:20})],an.prototype,"saltLength",void 0);Ee([u({type:h.Integer,context:3,defaultValue:1})],an.prototype,"trailerField",void 0);var D7=new H({algorithm:bo,parameters:q.serialize(new an)});var Mi=class{constructor(e={}){this.digestAlgorithm=new H,this.digest=new ae,Object.assign(this,e)}};Ee([u({type:H})],Mi.prototype,"digestAlgorithm",void 0);Ee([u({type:ae})],Mi.prototype,"digest",void 0);var Xy,Qs=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})],Qs.prototype,"prime",void 0);Ee([u({type:h.Integer,converter:me})],Qs.prototype,"exponent",void 0);Ee([u({type:h.Integer,converter:me})],Qs.prototype,"coefficient",void 0);var Yf=Xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};Yf=Xy=Ee([A({type:_.Sequence,itemType:Qs})],Yf);var mr=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})],mr.prototype,"version",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"modulus",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"publicExponent",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"privateExponent",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"prime1",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"prime2",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"exponent1",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"exponent2",void 0);Ee([u({type:h.Integer,converter:me})],mr.prototype,"coefficient",void 0);Ee([u({type:Yf,optional:!0})],mr.prototype,"otherPrimeInfos",void 0);var ea=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Ee([u({type:h.Integer,converter:me})],ea.prototype,"modulus",void 0);Ee([u({type:h.Integer,converter:me})],ea.prototype,"publicExponent",void 0);function cu(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 Zy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Zy||(Zy={}));var wt=Zy;var vv=Vr(xv(),1),{__extends:ra,__assign:p$,__rest:FC,__decorate:h$,__param:d$,__metadata:y$,__awaiter:_v,__generator:Sv,__exportStar:m$,__createBinding:g$,__values:uu,__read:lu,__spread:Kr,__spreadArrays:w$,__await:b$,__asyncGenerator:x$,__asyncDelegator:v$,__asyncValues:_$,__makeTemplateObject:S$,__importStar:A$,__importDefault:E$,__classPrivateFieldGet:C$,__classPrivateFieldSet:T$}=vv.default;var WC="injectionTokens";function Jy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(WC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function fu(r){return!!r.useClass}function na(r){return!!r.useFactory}var ep=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,Kr(i))}};return this.reflectMethods.forEach(n),t},r}();function vo(r){return typeof r=="string"||typeof r=="symbol"}function Qy(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function tp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Av(r){return typeof r=="function"||r instanceof ep}function Ki(r){return!!r.useToken}function Hi(r){return r.useValue!=null}function Ev(r){return fu(r)||Hi(r)||Ki(r)||na(r)}var GC=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}(),pu=GC;var qC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu),Cv=qC;var zC=function(){function r(){this.scopedResolutions=new Map}return r}(),hu=zC;function XC(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=" "),Kr([r],e.message.split(`
|
7
7
|
`).map(function(n){return t+n})).join(`
|
8
|
-
`)}function em(r,e,t){var n=fu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=XC(i,e);return ZC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function Tv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var YC=function(r){na(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(hu);var JC=function(r){na(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(hu);var QC=function(){function r(){this.preResolution=new YC,this.postResolution=new JC}return r}(),Iv=QC;var tm=new Map,eT=function(){function r(e){this.parent=e,this._registry=new Cv,this.interceptors=new Iv,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:wt.Transient}),this.ensureNotDisposed();var o;if(Ev(t)?o=t:o={useClass:t},Ki(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Kr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Ki(c.provider)?s=c.provider:s=null}if((n.lifecycle===wt.Singleton||n.lifecycle==wt.ContainerScoped||n.lifecycle==wt.ResolutionScoped)&&(Hi(o)||oa(o)))throw new Error('Cannot use lifecycle "'+wt[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(),vo(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(),vo(e)){if(vo(t))return this.register(e,{useToken:t},{lifecycle:wt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:wt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!vo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:wt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new du),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&vo(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(Av(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=lu(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=lu(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===wt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===wt.Singleton,o=e.options.lifecycle===wt.ContainerScoped,i=n||o,s;return Hi(e.provider)?s=e.provider.useValue:Ki(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):oa(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===wt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new du),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&vo(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=lu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=fu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Hi(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=lu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=fu(i.value,2),a=s[0],c=s[1];c.some(function(l){var f=l.options;return f.lifecycle===wt.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===wt.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 _v(this,void 0,void 0,function(){var e;return Sv(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 ep)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=tm.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,Kr([void 0],s)))}();return Tv(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 Qy(o)?tp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Kr([n.resolveAll(o.token,new du,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Kr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new du,o.isOptional):n.resolve(o.token,e,o.isOptional):tp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Kr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(em(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 eT;function tT(r){return function(e){tm.set(e,Jy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Le.register(t,e)}):Le.register(r.token,e))}}var _o=tT;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 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}function Ae(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,Vi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Ae([u({type:h.ObjectIdentifier})],Vi.prototype,"attrId",void 0);Ae([u({type:h.Any,repeated:"set"})],Vi.prototype,"attrValues",void 0);var Ov=nm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};Ov=nm=Ae([A({type:_.Sequence,itemType:Vi})],Ov);var om,Pv=om=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};Pv=om=Ae([A({type:_.Sequence,itemType:yr})],Pv);var rT="1.2.840.113549",nT=`${rT}.1`,Bv=`${nT}.12`,ia=`${Bv}.1`,VW=`${ia}.1`,$W=`${ia}.2`,FW=`${ia}.3`,WW=`${ia}.4`,GW=`${ia}.5`,qW=`${ia}.6`,$i=`${Bv}.10.1`;var ZW=`${$i}.1`,YW=`${$i}.2`,JW=`${$i}.3`,QW=`${$i}.4`,eG=`${$i}.5`,tG=`${$i}.6`,rp="1.2.840.113549.1.9";var np=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Ae([u({type:h.ObjectIdentifier})],np.prototype,"certId",void 0);Ae([u({type:h.Any,context:0})],np.prototype,"certValue",void 0);var kv=`${rp}.22`,sG=`${kv}.1`,aG=`${kv}.2`;var op=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Ae([u({type:h.ObjectIdentifier})],op.prototype,"crlId",void 0);Ae([u({type:h.Any,context:0})],op.prototype,"crltValue",void 0);var oT=`${rp}.23`,pG=`${oT}.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 ip=class extends ae{},So=class{constructor(e={}){this.encryptionAlgorithm=new H,this.encryptedData=new ip,Object.assign(this,e)}};Rn([u({type:H})],So.prototype,"encryptionAlgorithm",void 0);Rn([u({type:ip})],So.prototype,"encryptedData",void 0);var im,sm;(function(r){r[r.v1=0]="v1"})(sm||(sm={}));var sp=class extends ae{},am=im=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};am=im=Rn([A({type:_.Sequence,itemType:ht})],am);var Ao=class{constructor(e={}){this.version=sm.v1,this.privateKeyAlgorithm=new H,this.privateKey=new sp,Object.assign(this,e)}};Rn([u({type:h.Integer})],Ao.prototype,"version",void 0);Rn([u({type:H})],Ao.prototype,"privateKeyAlgorithm",void 0);Rn([u({type:sp})],Ao.prototype,"privateKey",void 0);Rn([u({type:am,implicit:!0,context:0,optional:!0})],Ao.prototype,"attributes",void 0);var Nv=class extends Ao{};Nv=Ae([A({type:_.Sequence})],Nv);var Dv=class extends So{};Dv=Ae([A({type:_.Sequence})],Dv);var ap=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Ae([u({type:h.ObjectIdentifier})],ap.prototype,"secretTypeId",void 0);Ae([u({type:h.Any,context:0})],ap.prototype,"secretValue",void 0);var Eo=class{constructor(e={}){this.mac=new Mi,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Ae([u({type:Mi})],Eo.prototype,"mac",void 0);Ae([u({type:ae})],Eo.prototype,"macSalt",void 0);Ae([u({type:h.Integer,defaultValue:1})],Eo.prototype,"iterations",void 0);var Fi=class{constructor(e={}){this.version=3,this.authSafe=new yr,this.macData=new Eo,Object.assign(this,e)}};Ae([u({type:h.Integer})],Fi.prototype,"version",void 0);Ae([u({type:yr})],Fi.prototype,"authSafe",void 0);Ae([u({type:Eo,optional:!0})],Fi.prototype,"macData",void 0);var cm,sa=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Ae([u({type:h.ObjectIdentifier})],sa.prototype,"bagId",void 0);Ae([u({type:h.Any,context:0})],sa.prototype,"bagValue",void 0);Ae([u({type:Vi,repeated:"set",optional:!0})],sa.prototype,"bagAttributes",void 0);var jv=cm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};jv=cm=Ae([A({type:_.Sequence,itemType:sa})],jv);var um,lm,fm,Ge="1.2.840.113549.1.9",yq=`${Ge}.0`,Xv=`${Ge}.24`,mu=`${Ge}.25`,Zv=`${Ge}.26`,Yv=`${Ge}.27`,mq=`${Xv}.1`,gq=`${Xv}.2`,wq=`${Ge}.1`,bq=`${Ge}.2`,xq=`${Ge}.3`,vq=`${Ge}.4`,_q=`${Ge}.5`,Sq=`${Ge}.6`,bm=`${Ge}.7`,Aq=`${Ge}.8`,Eq=`${Ge}.9`,Cq=`${Ge}.13`,gu=`${Ge}.14`,Tq=`${Ge}.15`,Iq=`${Ge}.20`,Oq=`${Ge}.21`;var Pq=`${mu}.1`,Bq=`${mu}.2`,kq=`${mu}.3`,Nq=`${mu}.4`,Dq=`${mu}.5`,wu="1.3.6.1.5.5.7.9",jq=`${wu}.1`,Rq=`${wu}.2`,Lq=`${wu}.3`,Uq=`${wu}.4`,Mq=`${wu}.5`,Kq=`${Zv}.1`,Hq=`${Zv}.2`,Vq=`${Yv}.1`,$q=`${Yv}.2`,Fq=`${Ge}.16`,Wq=`${Ge}.22`,Gq=`${Ge}.23`,qq=`${By}.65`,cp=class extends Qe{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Se([u({type:h.IA5String})],cp.prototype,"ia5String",void 0);cp=Se([A({type:_.Choice})],cp);var Rv=class extends yr{};Rv=Se([A({type:_.Sequence})],Rv);var Lv=class extends Fi{};Lv=Se([A({type:_.Sequence})],Lv);var Uv=class extends So{};Uv=Se([A({type:_.Sequence})],Uv);var pm=class{constructor(e=""){this.value=e}toString(){return this.value}};Se([u({type:h.IA5String})],pm.prototype,"value",void 0);pm=Se([A({type:_.Choice})],pm);var Mv=class extends cp{};Mv=Se([A({type:_.Choice})],Mv);var Kv=class extends Qe{};Kv=Se([A({type:_.Choice})],Kv);var hm=class{constructor(e=new Date){this.value=e}};Se([u({type:h.GeneralizedTime})],hm.prototype,"value",void 0);hm=Se([A({type:_.Choice})],hm);var Hv=class extends Qe{};Hv=Se([A({type:_.Choice})],Hv);var dm=class{constructor(e="M"){this.value=e}toString(){return this.value}};Se([u({type:h.PrintableString})],dm.prototype,"value",void 0);dm=Se([A({type:_.Choice})],dm);var up=class{constructor(e=""){this.value=e}toString(){return this.value}};Se([u({type:h.PrintableString})],up.prototype,"value",void 0);up=Se([A({type:_.Choice})],up);var Vv=class extends up{};Vv=Se([A({type:_.Choice})],Vv);var $v=class extends Qe{};$v=Se([A({type:_.Choice})],$v);var ym=class{constructor(e=""){this.value=e}toString(){return this.value}};Se([u({type:h.ObjectIdentifier})],ym.prototype,"value",void 0);ym=Se([A({type:_.Choice})],ym);var Fv=class extends We{};Fv=Se([A({type:_.Choice})],Fv);var mm=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Se([u({type:h.Integer})],mm.prototype,"value",void 0);mm=Se([A({type:_.Choice})],mm);var Wv=class extends Wt{};Wv=Se([A({type:_.Sequence})],Wv);var yu=class extends Qe{};yu=Se([A({type:_.Choice})],yu);var Gv=um=class extends rr{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};Gv=um=Se([A({type:_.Sequence})],Gv);var qv=lm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};qv=lm=Se([A({type:_.Set,itemType:Mr})],qv);var gm=class{constructor(e=""){this.value=e}toString(){return this.value}};Se([u({type:h.BmpString})],gm.prototype,"value",void 0);gm=Se([A({type:_.Choice})],gm);var wm=class extends H{};wm=Se([A({type:_.Sequence})],wm);var zv=fm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};zv=fm=Se([A({type:_.Sequence,itemType:wm})],zv);function Hr(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,bu=xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};bu=xm=Hr([A({type:_.Sequence,itemType:ht})],bu);var un=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new dt,this.attributes=new bu,Object.assign(this,e)}};Hr([u({type:h.Integer})],un.prototype,"version",void 0);Hr([u({type:Pe})],un.prototype,"subject",void 0);Hr([u({type:dt})],un.prototype,"subjectPKInfo",void 0);Hr([u({type:bu,implicit:!0,context:0})],un.prototype,"attributes",void 0);var Co=class{constructor(e={}){this.certificationRequestInfo=new un,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Hr([u({type:un})],Co.prototype,"certificationRequestInfo",void 0);Hr([u({type:H})],Co.prototype,"signatureAlgorithm",void 0);Hr([u({type:h.BitString})],Co.prototype,"signature",void 0);var Eu="crypto.algorithm",Pm=class{getAlgorithms(){return Le.resolveAll(Eu)}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}}},Wi="crypto.algorithmProvider";Le.registerSingleton(Wi,Pm);var hp,Zt="1.3.36.3.3.2.8.1.1",Jv=`${Zt}.1`,Qv=`${Zt}.2`,e1=`${Zt}.3`,t1=`${Zt}.4`,r1=`${Zt}.5`,n1=`${Zt}.6`,o1=`${Zt}.7`,i1=`${Zt}.8`,s1=`${Zt}.9`,a1=`${Zt}.10`,c1=`${Zt}.11`,u1=`${Zt}.12`,l1=`${Zt}.13`,f1=`${Zt}.14`,p1="brainpoolP160r1",h1="brainpoolP160t1",d1="brainpoolP192r1",y1="brainpoolP192t1",m1="brainpoolP224r1",g1="brainpoolP224t1",w1="brainpoolP256r1",b1="brainpoolP256t1",x1="brainpoolP320r1",v1="brainpoolP320t1",_1="brainpoolP384r1",S1="brainpoolP384t1",A1="brainpoolP512r1",E1="brainpoolP512t1",Ve="ECDSA",vu=hp=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Ve.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Hx;case"sha-256":return Vx;case"sha-384":return $x;case"sha-512":return Fx}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Hy;break;case"K-256":t=hp.SECP256K1;break;case"P-384":t=Vy;break;case"P-521":t=$y;break;case p1:t=Jv;break;case h1:t=Qv;break;case d1:t=e1;break;case y1:t=t1;break;case m1:t=r1;break;case g1:t=n1;break;case w1:t=o1;break;case b1:t=i1;break;case x1:t=s1;break;case v1:t=a1;break;case _1:t=c1;break;case S1:t=u1;break;case A1:t=l1;break;case E1:t=f1;break}if(t)return new H({algorithm:Ni,parameters:G.serialize(new sn({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case nu:return{name:Ve,hash:{name:"SHA-1"}};case ou:return{name:Ve,hash:{name:"SHA-256"}};case iu:return{name:Ve,hash:{name:"SHA-384"}};case su:return{name:Ve,hash:{name:"SHA-512"}};case Ni:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(G.parse(e.parameters,sn).namedCurve){case Hy:return{name:Ve,namedCurve:"P-256"};case hp.SECP256K1:return{name:Ve,namedCurve:"K-256"};case Vy:return{name:Ve,namedCurve:"P-384"};case $y:return{name:Ve,namedCurve:"P-521"};case Jv:return{name:Ve,namedCurve:p1};case Qv:return{name:Ve,namedCurve:h1};case e1:return{name:Ve,namedCurve:d1};case t1:return{name:Ve,namedCurve:y1};case r1:return{name:Ve,namedCurve:m1};case n1:return{name:Ve,namedCurve:g1};case o1:return{name:Ve,namedCurve:w1};case i1:return{name:Ve,namedCurve:b1};case s1:return{name:Ve,namedCurve:x1};case a1:return{name:Ve,namedCurve:v1};case c1:return{name:Ve,namedCurve:_1};case u1:return{name:Ve,namedCurve:S1};case l1:return{name:Ve,namedCurve:A1};case f1:return{name:Ve,namedCurve:E1}}}}return null}};vu.SECP256K1="1.3.132.0.10";vu=hp=uu([_o()],vu);Le.registerSingleton(Eu,vu);var R1=Symbol("name"),L1=Symbol("value"),_e=class{constructor(e,t={},n=""){this[R1]=e,this[L1]=n;for(let o in t)this[o]=t[o]}};_e.NAME=R1;_e.VALUE=L1;var Bm=class{static toTextObject(e){let t=new _e("Algorithm Identifier",{},fn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Ni:{let n=new vu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},fn=class{static toString(e){let t=this.items[e];return t||e}};fn.items={[ji]:"sha1",[Xf]:"sha224",[Ri]:"sha256",[Li]:"sha384",[Ui]:"sha512",[an]:"rsaEncryption",[Zs]:"sha1WithRSAEncryption",[Xx]:"sha224WithRSAEncryption",[zf]:"sha256WithRSAEncryption",[Ys]:"sha384WithRSAEncryption",[Js]:"sha512WithRSAEncryption",[Ni]:"ecPublicKey",[nu]:"ecdsaWithSHA1",[qf]:"ecdsaWithSHA224",[ou]:"ecdsaWithSHA256",[iu]:"ecdsaWithSHA384",[su]:"ecdsaWithSHA512",[vx]:"TLS WWW server authentication",[_x]:"TLS WWW client authentication",[Sx]:"Code Signing",[Ax]:"E-mail Protection",[Ex]:"Time Stamping",[Cx]:"OCSP Signing",[Mx]:"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[
|
10
|
-
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return
|
11
|
-
`)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData
|
12
|
-
`)}};Rt.CertificateTag="CERTIFICATE";Rt.CrlTag="CRL";Rt.CertificateRequestTag="CERTIFICATE REQUEST";Rt.PublicKeyTag="PUBLIC KEY";Rt.PrivateKeyTag="PRIVATE KEY";var Io=class r extends To{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Rt.isPem(e))return Rt.decode(e)[0];if(V.Convert.isHex(e))return V.Convert.FromHex(e);if(V.Convert.isBase64(e))return V.Convert.FromBase64(e);if(V.Convert.isBase64Url(e))return V.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=V.Convert.ToBinary(e);return Rt.isPem(t)?Rt.decode(t)[0]:V.Convert.isHex(t)?V.Convert.FromHex(t):V.Convert.isBase64(t)?V.Convert.FromBase64(t):V.Convert.isBase64Url(t)?V.Convert.FromBase64Url(t):V.BufferSourceConverter.toArrayBuffer(e)}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Rt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Ln=class r extends Io{static async create(e,t=bt.get()){if(e instanceof r)return e;if(_u.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){Io.isAsnEncoded(e)?super(e,dt):super(e),this.tag=Rt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||bt.get()):t=e[0]||bt.get();let i=this.rawData,s=G.parse(this.rawData,dt);return s.algorithm.algorithm===bo&&(i=xT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Le.resolve(Wi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case an:{let o=G.parse(e.subjectPublicKey,ta),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]||bt.get()):n=e[0]||bt.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=bt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=bt.get();let o=G.parse(this.rawData,dt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,dt);switch(e.Algorithm=Un.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ni:e["EC Point"]=t.subjectPublicKey;break;case an:default:e["Raw Data"]=t.subjectPublicKey}return e}};function xT(r,e){return r.algorithm=new H({algorithm:an,parameters:null}),e=G.serialize(r),e}var mp=class r extends wr{static async create(e,t=!1,n=bt.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 tn({keyIdentifier:new mi(V.Convert.FromHex(e[0]))});super(Cf,e[1],G.serialize(t))}else{let t=e[0],n=t.name instanceof Gi?G.parse(t.name.rawData,Ke):t.name,o=new tn({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(Cf,e[1],G.serialize(o))}}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,tn);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=G.parse(this.value,tn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Gi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};mp.NAME="Authority Key Identifier";var ca=class extends wr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,gi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new gi({cA:e[0],pathLenConstraint:e[1]});super(Tf,e[2],G.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}};ca.NAME="Basic Constraints";var B1;(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"})(B1||(B1={}));var gp=class extends wr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,Uc);this.usages=t.map(n=>n)}else{let t=new Uc(e[0]);super(Bf,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>fn.toString(t)).join(", "),e}};gp.NAME="Extended Key Usages";var k1;(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"})(k1||(k1={}));var wp=class extends wr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,Ns);this.usages=t.toNumber()}else{let t=new Ns(e[0]);super(kf,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,Ns);return e[""]=t.toJSON().join(", "),e}};wp.NAME="Key Usages";var bp=class r extends wr{static async create(e,t=!1,n=bt.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=G.parse(this.value,$t);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new $t(t);super(Ay,e[1],G.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,$t);return e[""]=t,e}};bp.NAME="Subject Key Identifier";var xp=class extends wr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(_y,e[1],new Gi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,Rf);this.names=new Gi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};xp.NAME="Subject Alternative Name";var Xt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new wr(e),n=this.items.get(t.type);return n?new n(e):t}};Xt.items=new Map;var vp=class extends wr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=G.parse(this.value,Nc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Nc(n.map(s=>new wi({policyIdentifier:s})));super(Of,o,G.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new _e("",{},fn.toString(t))),e}};vp.NAME="Certificate Policies";Xt.register(Of,vp);var _p=class extends wr{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 rn({distributionPoint:new Pn({fullName:[new ue({uniformResourceIdentifier:s})]})})),i=new fo(o);super(Pf,e[1],G.serialize(i))}else{let n=new fo(e[0]);super(Pf,e[1],G.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,fo);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 ln(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};_p.NAME="CRL Distribution Points";var Sp=class extends wr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof yi){let s=new yi(e[0]);super(Ef,e[1],G.serialize(s))}else{let s=e[0],a=new yi;pp(a,s,sy,"ocsp"),pp(a,s,ay,"caIssuers"),pp(a,s,cy,"timeStamping"),pp(a,s,uy,"caRepository"),super(Ef,e[1],G.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=[],G.parse(e.extnValue,yi).forEach(n=>{switch(n.accessMethod){case sy:this.ocsp.push(new ln(n.accessLocation));break;case ay:this.caIssuers.push(new ln(n.accessLocation));break;case cy:this.timeStamping.push(new ln(n.accessLocation));break;case uy:this.caRepository.push(new ln(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&fp(e,"OCSP",this.ocsp),this.caIssuers.length&&fp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&fp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&fp(e,"CA Repository",this.caRepository),e}};Sp.NAME="Authority Info Access";function fp(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 pp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new ln("url",s)),r.push(new In({accessMethod:t,accessLocation:G.parse(s.rawData,ue)}))})}var ua=class r extends To{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=G.serialize(new ht({type:n,values:o}))}super(t,ht)}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]=fn.toString(this.type)),e}};ua.NAME="Attribute";var Ap=class extends ua{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new yu({printableString:e[0]});super(bm,[G.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],yu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[_e.VALUE]=this.password,e}};Ap.NAME="Challenge Password";var Au=class extends ua{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new rr;for(let i of n)o.push(G.parse(i.rawData,yt));super(gu,[G.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],rr);this.items=t.map(n=>Xt.create(G.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}};Au.NAME="Extensions";var la=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ua(e),n=this.items.get(t.type);return n?new n(e):t}};la.items=new Map;var Cu="crypto.signatureFormatter",km=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},dp,Nm=dp=class{static createPssParams(e,t){let n=dp.getHashAlgorithm(e);return n?new cn({hashAlgorithm:n,maskGenAlgorithm:new H({algorithm:xo,parameters:G.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Le.resolve(Wi);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:Zs,parameters:null});case"sha-256":return new H({algorithm:zf,parameters:null});case"sha-384":return new H({algorithm:Ys,parameters:null});case"sha-512":return new H({algorithm:Js,parameters:null})}}else return new H({algorithm:an,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=dp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new H({algorithm:bo,parameters:G.serialize(t)})}else return new H({algorithm:bo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case an:return{name:"RSASSA-PKCS1-v1_5"};case Zs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case zf:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Ys:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Js:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case bo:if(e.parameters){let t=G.parse(e.parameters,cn);return{name:"RSA-PSS",hash:Le.resolve(Wi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Nm=dp=uu([_o()],Nm);Le.registerSingleton(Eu,Nm);var Dm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new H({algorithm:ji});case"sha-256":return new H({algorithm:Ri});case"sha-384":return new H({algorithm:Li});case"sha-512":return new H({algorithm:Ui})}return null}toWebAlgorithm(e){switch(e.algorithm){case ji:return{name:"SHA-1"};case Ri:return{name:"SHA-256"};case Li:return{name:"SHA-384"};case Ui:return{name:"SHA-512"}}return null}};Dm=uu([_o()],Dm);Le.registerSingleton(Eu,Dm);var Mn=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 Di,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),G.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=G.parse(t,Di),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}};Mn.namedCurveSize=new Map;Mn.defaultNamedCurveSize=32;var Im="1.3.101.110",N1="1.3.101.111",Om="1.3.101.112",D1="1.3.101.113",jm=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=Om;break;case"x25519":t=Im;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=Om;break;case"ed448":t=D1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Im;break;case"x448":t=N1;break}}return t?new H({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case Om:return{name:"Ed25519"};case D1:return{name:"EdDSA",namedCurve:"Ed448"};case Im:return{name:"X25519"};case N1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};jm=uu([_o()],jm);Le.registerSingleton(Eu,jm);var Rm=class extends Io{constructor(e){Io.isAsnEncoded(e)?super(e,Co):super(e),this.tag=Rt.CertificateRequestTag}onInit(e){this.tbs=G.serialize(e.certificationRequestInfo),this.publicKey=new Ln(e.certificationRequestInfo.subjectPKInfo);let t=Le.resolve(Wi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>la.create(G.serialize(o)));let n=this.getAttribute(gu);this.extensions=[],n instanceof Au&&(this.extensions=n.items),this.subjectName=new gr(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=bt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Le.resolveAll(Cu).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=G.parse(this.rawData,Co),n=t.certificationRequestInfo,o=new _e("",{Version:`${nn[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:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Rm.NAME="PKCS#10 Certificate Request";var fa=class extends Io{constructor(e){Io.isAsnEncoded(e)?super(e,pr):super(e),this.tag=Rt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=G.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 gr(t.subject),this.subject=new gr(t.subject).toString(),this.issuerName=new gr(t.issuer),this.issuer=this.issuerName.toString();let o=Le.resolve(Wi);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=>Xt.create(G.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=bt.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(Cu).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=bt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=bt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,pr),n=t.tbsCertificate,o=new _e("",{Version:`${nn[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Un.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:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};fa.NAME="Certificate";var Ep=class{static async createSelfSigned(e,t=bt.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=bt.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)):t.getRandomValues(new Uint8Array(16));if(i[0]>127){let d=new Uint8Array(i.length+1);d[0]=0,d.set(i,1),i=d}let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new pr({tbsCertificate:new mt({version:nn.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new rr(((n=e.extensions)===null||n===void 0?void 0:n.map(d=>G.parse(d.rawData,yt)))||[]),subjectPublicKeyInfo:G.parse(o,dt)})});if(e.subject){let d=e.subject instanceof gr?e.subject:new gr(e.subject);c.tbsCertificate.subject=G.parse(d.toArrayBuffer(),Pe)}if(e.issuer){let d=e.issuer instanceof gr?e.issuer:new gr(e.issuer);c.tbsCertificate.issuer=G.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(Wi);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(f);let y=G.serialize(c.tbsCertificate),m="signingKey"in e?await t.subtle.sign(f,e.signingKey,y):e.signature,x=Le.resolveAll(Cu).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 fa(G.serialize(c))}},j1;(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"})(j1||(j1={}));Xt.register(Tf,ca);Xt.register(Bf,gp);Xt.register(kf,wp);Xt.register(Ay,bp);Xt.register(Cf,mp);Xt.register(_y,xp);Xt.register(Pf,_p);Xt.register(Ef,Sp);la.register(bm,Ap);la.register(gu,Au);Le.registerSingleton(Cu,km);Le.registerSingleton(Cu,Mn);Mn.namedCurveSize.set("P-256",32);Mn.namedCurveSize.set("K-256",32);Mn.namedCurveSize.set("P-384",48);Mn.namedCurveSize.set("P-521",66);var Kn="/",K1=new TextEncoder().encode(Kn),Cp=K1[0],Tu=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=pe(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]!==Cp)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(Kn))}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=K1),this._buf[0]!==Cp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Cp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Cp;)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(Kn).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(Kn)||(e+=Kn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Kn):new r(e.slice(0,-1).join(Kn))}child(e){return this.toString()===Kn?e:e.toString()===Kn?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(),...ST(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 ST(r){return[].concat(...r)}var Tp=class extends Fn{async listen(){throw new Yl("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Lm(){let r=Ye(),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 H1(){let r=Lm(),e=Lm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function AT(r){return r[Symbol.asyncIterator]!=null}async function ET(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*CT(r){let e=new AbortController,t=Fl();ET(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*TT(r){for(let e of r)yield*e}function IT(...r){let e=[];for(let t of r)AT(t)||e.push(t);return e.length===r.length?TT(e):CT(r)}var V1=IT;function $1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Um(r)){let n=r;r=()=>n.source}else if(W1(r)||F1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Um(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++)Um(t[n])&&(t[n]=PT(t[n]));return OT(...t)}var OT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},F1=r=>r?.[Symbol.asyncIterator]!=null,W1=r=>r?.[Symbol.iterator]!=null,Um=r=>r==null?!1:r.sink!=null&&r.source!=null,PT=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Ss({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(F1(i))o=async function*(){yield*i,n.end()};else if(W1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return V1(n,o())}return r.source};var pa=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function q1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ip(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Op(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ot(r,...e){if(!q1(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 Mm(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 z1(r,e){Ot(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Hn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Vn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function BT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var kT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function NT(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Pp(r){if(typeof r=="string")r=NT(r);else if(q1(r))r=Bp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function X1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function Z1(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 Km=(r,e)=>{function t(n,...o){if(Ot(n),!kT)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?Ot(f):Ot(f,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Ot(o[1]);let s=e(n,...o),a=(f,p)=>{if(p!==void 0){if(f!==2)throw new Error("cipher output not supported");Ot(p)}},c=!1;return{encrypt(f,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Ot(f),a(s.encrypt.length,p),s.encrypt(f,p)},decrypt(f,p){if(Ot(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 Hm(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&&!DT(e))throw new Error("invalid output, must be aligned");return e}function G1(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 Y1(r,e,t){Ip(t);let n=new Uint8Array(16),o=BT(n);return G1(o,0,BigInt(e),t),G1(o,8,BigInt(r),t),n}function DT(r){return r.byteOffset%4===0}function Bp(r){return Uint8Array.from(r)}var Q1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),jT=Q1("expand 16-byte k"),RT=Q1("expand 32-byte k"),LT=Hn(jT),UT=Hn(RT);function te(r,e){return r<<e|r>>>32-e}function Vm(r){return r.byteOffset%4===0}var kp=64,MT=16,e_=2**32-1,J1=new Uint32Array;function KT(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(kp),f=Hn(l),p=Vm(o)&&Vm(i),y=p?Hn(o):J1,m=p?Hn(i):J1;for(let x=0;x<c;s++){if(r(e,t,n,f,s,a),s>=e_)throw new Error("arx: counter overflow");let v=Math.min(kp,c-x);if(p&&v===kp){let d=x/4;if(x%4!==0)throw new Error("arx: invalid block position");for(let C=0,R;C<MT;C++)R=d+C,m[R]=y[R]^f[C];x+=kp;continue}for(let d=0,C;d<v;d++)C=x+d,i[C]=o[C]^l[d];x+=v}}function $m(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=X1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Op(o),Op(s),Ip(i),Ip(t),(a,c,l,f,p=0)=>{Ot(a),Ot(c),Ot(l);let y=l.length;if(f===void 0&&(f=new Uint8Array(y)),Ot(f),Op(p),p<0||p>=e_)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=Bp(a)),d=UT;else if(x===16&&t)v=new Uint8Array(32),v.set(a),v.set(a,16),d=LT,m.push(v);else throw new Error(`arx: invalid 32-byte key, got length=${x}`);Vm(c)||m.push(c=Bp(c));let C=Hn(v);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,C,Hn(c.subarray(0,16)),C),c=c.subarray(16)}let R=16-o;if(R!==c.length)throw new Error(`arx: nonce must be ${R} or 16 bytes`);if(R!==12){let Z=new Uint8Array(12);Z.set(c,i?0:12-c.length),c=Z,m.push(c)}let D=Hn(c);return KT(r,d,C,D,l,f,p,s),Vn(...m),f}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Fm=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Pp(e),Ot(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),l=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let f=0;f<8;f++)this.pad[f]=xt(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],C=xt(e,t+0),R=xt(e,t+2),D=xt(e,t+4),Z=xt(e,t+6),P=xt(e,t+8),q=xt(e,t+10),M=xt(e,t+12),K=xt(e,t+14),g=i[0]+(C&8191),I=i[1]+((C>>>13|R<<3)&8191),E=i[2]+((R>>>10|D<<6)&8191),O=i[3]+((D>>>7|Z<<9)&8191),B=i[4]+((Z>>>4|P<<12)&8191),j=i[5]+(P>>>1&8191),N=i[6]+((P>>>14|q<<2)&8191),L=i[7]+((q>>>11|M<<5)&8191),F=i[8]+((M>>>8|K<<8)&8191),X=i[9]+(K>>>5|o),W=0,ie=W+g*a+I*(5*d)+E*(5*v)+O*(5*x)+B*(5*m);W=ie>>>13,ie&=8191,ie+=j*(5*y)+N*(5*p)+L*(5*f)+F*(5*l)+X*(5*c),W+=ie>>>13,ie&=8191;let Y=W+g*c+I*a+E*(5*d)+O*(5*v)+B*(5*x);W=Y>>>13,Y&=8191,Y+=j*(5*m)+N*(5*y)+L*(5*p)+F*(5*f)+X*(5*l),W+=Y>>>13,Y&=8191;let U=W+g*l+I*c+E*a+O*(5*d)+B*(5*v);W=U>>>13,U&=8191,U+=j*(5*x)+N*(5*m)+L*(5*y)+F*(5*p)+X*(5*f),W+=U>>>13,U&=8191;let he=W+g*f+I*l+E*c+O*a+B*(5*d);W=he>>>13,he&=8191,he+=j*(5*v)+N*(5*x)+L*(5*m)+F*(5*y)+X*(5*p),W+=he>>>13,he&=8191;let Oe=W+g*p+I*f+E*l+O*c+B*a;W=Oe>>>13,Oe&=8191,Oe+=j*(5*d)+N*(5*v)+L*(5*x)+F*(5*m)+X*(5*y),W+=Oe>>>13,Oe&=8191;let se=W+g*y+I*p+E*f+O*l+B*c;W=se>>>13,se&=8191,se+=j*a+N*(5*d)+L*(5*v)+F*(5*x)+X*(5*m),W+=se>>>13,se&=8191;let Ne=W+g*m+I*y+E*p+O*f+B*l;W=Ne>>>13,Ne&=8191,Ne+=j*c+N*a+L*(5*d)+F*(5*v)+X*(5*x),W+=Ne>>>13,Ne&=8191;let vt=W+g*x+I*m+E*y+O*p+B*f;W=vt>>>13,vt&=8191,vt+=j*l+N*c+L*a+F*(5*d)+X*(5*v),W+=vt>>>13,vt&=8191;let et=W+g*v+I*x+E*m+O*y+B*p;W=et>>>13,et&=8191,et+=j*f+N*l+L*c+F*a+X*(5*d),W+=et>>>13,et&=8191;let tt=W+g*d+I*v+E*x+O*m+B*y;W=tt>>>13,tt&=8191,tt+=j*p+N*f+L*l+F*c+X*a,W+=tt>>>13,tt&=8191,W=(W<<2)+W|0,W=W+ie|0,ie=W&8191,W=W>>>13,Y+=W,i[0]=ie,i[1]=Y,i[2]=U,i[3]=he,i[4]=Oe,i[5]=se,i[6]=Ne,i[7]=vt,i[8]=et,i[9]=tt}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;Vn(n)}update(e){Mm(this),e=Pp(e),Ot(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(){Vn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Mm(this),z1(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 HT(r){let e=(n,o)=>r(o).update(Pp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var t_=HT(r=>new Fm(r));function o_(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],C=e[7],R=o,D=t[0],Z=t[1],P=t[2],q=s,M=a,K=c,g=l,I=f,E=p,O=y,B=m,j=x,N=v,L=d,F=C,X=R,W=D,ie=Z,Y=P;for(let he=0;he<i;he+=2)q=q+I|0,X=te(X^q,16),j=j+X|0,I=te(I^j,12),q=q+I|0,X=te(X^q,8),j=j+X|0,I=te(I^j,7),M=M+E|0,W=te(W^M,16),N=N+W|0,E=te(E^N,12),M=M+E|0,W=te(W^M,8),N=N+W|0,E=te(E^N,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),F=F+Y|0,B=te(B^F,12),g=g+B|0,Y=te(Y^g,8),F=F+Y|0,B=te(B^F,7),q=q+E|0,Y=te(Y^q,16),L=L+Y|0,E=te(E^L,12),q=q+E|0,Y=te(Y^q,8),L=L+Y|0,E=te(E^L,7),M=M+O|0,X=te(X^M,16),F=F+X|0,O=te(O^F,12),M=M+O|0,X=te(X^M,8),F=F+X|0,O=te(O^F,7),K=K+B|0,W=te(W^K,16),j=j+W|0,B=te(B^j,12),K=K+B|0,W=te(W^K,8),j=j+W|0,B=te(B^j,7),g=g+I|0,ie=te(ie^g,16),N=N+ie|0,I=te(I^N,12),g=g+I|0,ie=te(ie^g,8),N=N+ie|0,I=te(I^N,7);let U=0;n[U++]=s+q|0,n[U++]=a+M|0,n[U++]=c+K|0,n[U++]=l+g|0,n[U++]=f+I|0,n[U++]=p+E|0,n[U++]=y+O|0,n[U++]=m+B|0,n[U++]=x+j|0,n[U++]=v+N|0,n[U++]=d+L|0,n[U++]=C+F|0,n[U++]=R+X|0,n[U++]=D+W|0,n[U++]=Z+ie|0,n[U++]=P+Y|0}function VT(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],C=t[1],R=t[2],D=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,C=te(C^i,16),m=m+C|0,l=te(l^m,12),i=i+l|0,C=te(C^i,8),m=m+C|0,l=te(l^m,7),s=s+f|0,R=te(R^s,16),x=x+R|0,f=te(f^x,12),s=s+f|0,R=te(R^s,8),x=x+R|0,f=te(f^x,7),a=a+p|0,D=te(D^a,16),v=v+D|0,p=te(p^v,12),a=a+p|0,D=te(D^a,8),v=v+D|0,p=te(p^v,7),o=o+l|0,D=te(D^o,16),x=x+D|0,l=te(l^x,12),o=o+l|0,D=te(D^o,8),x=x+D|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,C=te(C^s,16),y=y+C|0,p=te(p^y,12),s=s+p|0,C=te(C^s,8),y=y+C|0,p=te(p^y,7),a=a+c|0,R=te(R^a,16),m=m+R|0,c=te(c^m,12),a=a+c|0,R=te(R^a,8),m=m+R|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++]=C,n[Z++]=R,n[Z++]=D}var $T=$m(o_,{counterRight:!1,counterLength:4,allowShortKeys:!1}),FT=$m(o_,{counterRight:!1,counterLength:8,extendNonceFn:VT,allowShortKeys:!1});var WT=new Uint8Array(16),r_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(WT.subarray(t))},GT=new Uint8Array(32);function n_(r,e,t,n,o){let i=r(e,t,GT),s=t_.create(i);o&&r_(s,o),r_(s,n);let a=Y1(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Vn(i,a),c}var i_=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Hm(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=n_(r,e,t,c,n);return s.set(l,a),Vn(l),s},decrypt(i,s){s=Hm(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=n_(r,e,t,a,n);if(!Z1(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Vn(l),s}}),Wm=Km({blockSize:64,nonceLength:12,tagLength:16},i_($T)),EX=Km({blockSize:64,nonceLength:24,tagLength:16},i_(FT));function a_(r,e,t){return Ea(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ys(r,zn(t),zn(e))}var Gm=Uint8Array.from([0]),s_=Uint8Array.of();function c_(r,e,t,n=32){Ea(r),jo(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=s_);let s=new Uint8Array(i*o),a=ys.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let f=0;f<i;f++)Gm[0]=f+1,c.update(f===0?s_:l).update(t).update(Gm).digestInto(l),s.set(l,o*f),a._cloneInto(c);return a.destroy(),c.destroy(),Sr(l,Gm),s.slice(0,n)}var qm={hashSHA256(r){return eo(r.subarray())},getHKDF(r,e){let t=a_(eo,e,r),o=c_(eo,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=Da.utils.randomPrivateKey();return{publicKey:Da.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Da.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Da.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Wm(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Wm(n,e,t).decrypt(r.subarray(),o)}};var u_=qm;function l_(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 ha=r=>{let e=ot(2);return e[0]=r>>8,e[1]=r,e};ha.bytes=2;var Iu=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)};Iu.bytes=2;function f_(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 zm(r,e){!e.enabled||!pa||(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 Xm(r,e){!e.enabled||!pa||(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 p_(r,e){!e.enabled||!pa||e(r?`REMOTE_STATIC_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote static public key.")}function Zm(r,e){!e.enabled||!pa||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ym(r,e,t){!t.enabled||!pa||(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 da=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var qT=0,zT=4294967295,XT="Cipherstate has reached maximum n, a new handshake must be performed",Np=class{n;bytes;view;constructor(e=qT){this.n=e,this.bytes=nt(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>zT)throw new Error(XT)}};var qi=nt(0),ya=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Np(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}},Jm=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=pe(t,"utf-8");this.h=ZT(e,n),this.ck=this.h,this.cs=new ya(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new ya(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,qi);return[new ya(this.crypto,e),new ya(this.crypto,t)]}},Qm=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 Jm(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()}},Ou=class extends Qm{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 da(`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 da(`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 da(`handshake stage 2 validation fail: ${t.message}`)}}};function ZT(r,e){if(e.length<=32){let t=nt(32);return t.set(e),t}else return r.hash(e)}var Dp;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((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 Ha('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 Ha('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=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Dp||(Dp={}));var Pu;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((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),Dp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:nt(0),identitySig:nt(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=Dp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Pu||(Pu={}));async function eg(r,e,t){let n=await r.sign(h_(e));return Pu.encode({identityKey:qn(r.publicKey),identitySig:n,extensions:t})}async function tg(r,e,t){try{let n=Pu.decode(r),o=qa(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=h_(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Du(n.message)}}function h_(r){let e=pe("noise-libp2p-static-key:");return r instanceof Uint8Array?Pt([e,r],e.length+r.length):(r.prepend(e),r)}async function d_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await eg(i,a.publicKey,l),p=new Ou({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});zm(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(qi),e),t.trace("Stage 0 - Initiator finished sending first message."),Xm(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."),Zm(p.re,t),p_(p.rs,t),t.trace("Initiator going to check remote's signature...");let m=await tg(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 Ym(x,v,t),{payload:m,encrypt:d=>x.encryptWithAd(qi,d),decrypt:(d,C)=>v.decryptWithAd(qi,d,C)}}async function y_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await eg(i,a.publicKey,l),p=new Ou({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});zm(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."),Zm(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."),Xm(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 tg(y,p.rs,c),[x,v]=p.ss.split();return Ym(x,v,t),{payload:m,encrypt:d=>v.encryptWithAd(qi,d),decrypt:(d,C)=>x.decryptWithAd(qi,d,C)}}var g_=16;function w_(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(ha(s.byteLength),s)}}}function b_(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-g_<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-g_);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var jp=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??u_;this.crypto=l_(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?f_(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??nt(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Zi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=lc(e,{lengthEncoder:ha,lengthDecoder:Iu,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=qa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:cd(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 ju("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=lc(e,{lengthEncoder:ha,lengthDecoder:Iu,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=qa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:cd(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 d_({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 y_({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]=H1(),i=e.unwrap();return await $1(n,w_(t,this.metrics),i,s=>Zo(s,{lengthDecoder:Iu}),b_(t,this.metrics),n),o}};function x_(r={}){return e=>new jp(e,r)}var rg=Object.values(ko).map(r=>r.decoder).reduce((r,e)=>r.or(e)),YT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function v_(r){return r?.match(YT)?.groups?.fingerprint}function ng(r){let t=r.stringTuples().filter(n=>n[0]===Xw).map(n=>n[1])[0];if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function JT(r){return xr.decode(rg.decode(r))}function QT(r){let e=JT(ng(r)),t=eI(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 Zl(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function __(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=St(ir.code,t);return Xr(`/certhash/${hn.encode(n.bytes)}`)}function eI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Jl(r)}}function S_(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=QT(r);return{type:"answer",sdp:`v=0
|
8
|
+
`)}function em(r,e,t){var n=lu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=XC(i,e);return ZC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function Tv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var YC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu);var JC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu);var QC=function(){function r(){this.preResolution=new YC,this.postResolution=new JC}return r}(),Iv=QC;var tm=new Map,eT=function(){function r(e){this.parent=e,this._registry=new Cv,this.interceptors=new Iv,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:wt.Transient}),this.ensureNotDisposed();var o;if(Ev(t)?o=t:o={useClass:t},Ki(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Kr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Ki(c.provider)?s=c.provider:s=null}if((n.lifecycle===wt.Singleton||n.lifecycle==wt.ContainerScoped||n.lifecycle==wt.ResolutionScoped)&&(Hi(o)||na(o)))throw new Error('Cannot use lifecycle "'+wt[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(),vo(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(),vo(e)){if(vo(t))return this.register(e,{useToken:t},{lifecycle:wt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:wt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!vo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:wt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new hu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&vo(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(Av(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=uu(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=uu(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===wt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===wt.Singleton,o=e.options.lifecycle===wt.ContainerScoped,i=n||o,s;return Hi(e.provider)?s=e.provider.useValue:Ki(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):fu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):na(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===wt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new hu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&vo(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=uu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=lu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Hi(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=uu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=lu(i.value,2),a=s[0],c=s[1];c.some(function(l){var f=l.options;return f.lifecycle===wt.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===wt.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 _v(this,void 0,void 0,function(){var e;return Sv(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 ep)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=tm.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,Kr([void 0],s)))}();return Tv(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 Qy(o)?tp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Kr([n.resolveAll(o.token,new hu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Kr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new hu,o.isOptional):n.resolve(o.token,e,o.isOptional):tp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Kr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(em(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 eT;function tT(r){return function(e){tm.set(e,Jy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Le.register(t,e)}):Le.register(r.token,e))}}var _o=tT;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 nm,Vi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Se([u({type:h.ObjectIdentifier})],Vi.prototype,"attrId",void 0);Se([u({type:h.Any,repeated:"set"})],Vi.prototype,"attrValues",void 0);var Ov=nm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};Ov=nm=Se([A({type:_.Sequence,itemType:Vi})],Ov);var om,Pv=om=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};Pv=om=Se([A({type:_.Sequence,itemType:yr})],Pv);var rT="1.2.840.113549",nT=`${rT}.1`,Bv=`${nT}.12`,oa=`${Bv}.1`,KW=`${oa}.1`,HW=`${oa}.2`,VW=`${oa}.3`,$W=`${oa}.4`,FW=`${oa}.5`,WW=`${oa}.6`,$i=`${Bv}.10.1`;var zW=`${$i}.1`,XW=`${$i}.2`,ZW=`${$i}.3`,YW=`${$i}.4`,JW=`${$i}.5`,QW=`${$i}.6`,rp="1.2.840.113549.1.9";var np=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],np.prototype,"certId",void 0);Se([u({type:h.Any,context:0})],np.prototype,"certValue",void 0);var kv=`${rp}.22`,oG=`${kv}.1`,iG=`${kv}.2`;var op=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],op.prototype,"crlId",void 0);Se([u({type:h.Any,context:0})],op.prototype,"crltValue",void 0);var oT=`${rp}.23`,lG=`${oT}.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 ip=class extends ae{},So=class{constructor(e={}){this.encryptionAlgorithm=new H,this.encryptedData=new ip,Object.assign(this,e)}};Rn([u({type:H})],So.prototype,"encryptionAlgorithm",void 0);Rn([u({type:ip})],So.prototype,"encryptedData",void 0);var im,sm;(function(r){r[r.v1=0]="v1"})(sm||(sm={}));var sp=class extends ae{},am=im=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};am=im=Rn([A({type:_.Sequence,itemType:ht})],am);var Ao=class{constructor(e={}){this.version=sm.v1,this.privateKeyAlgorithm=new H,this.privateKey=new sp,Object.assign(this,e)}};Rn([u({type:h.Integer})],Ao.prototype,"version",void 0);Rn([u({type:H})],Ao.prototype,"privateKeyAlgorithm",void 0);Rn([u({type:sp})],Ao.prototype,"privateKey",void 0);Rn([u({type:am,implicit:!0,context:0,optional:!0})],Ao.prototype,"attributes",void 0);var Nv=class extends Ao{};Nv=Se([A({type:_.Sequence})],Nv);var Dv=class extends So{};Dv=Se([A({type:_.Sequence})],Dv);var ap=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],ap.prototype,"secretTypeId",void 0);Se([u({type:h.Any,context:0})],ap.prototype,"secretValue",void 0);var Eo=class{constructor(e={}){this.mac=new Mi,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Se([u({type:Mi})],Eo.prototype,"mac",void 0);Se([u({type:ae})],Eo.prototype,"macSalt",void 0);Se([u({type:h.Integer,defaultValue:1})],Eo.prototype,"iterations",void 0);var Fi=class{constructor(e={}){this.version=3,this.authSafe=new yr,this.macData=new Eo,Object.assign(this,e)}};Se([u({type:h.Integer})],Fi.prototype,"version",void 0);Se([u({type:yr})],Fi.prototype,"authSafe",void 0);Se([u({type:Eo,optional:!0})],Fi.prototype,"macData",void 0);var cm,ia=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],ia.prototype,"bagId",void 0);Se([u({type:h.Any,context:0})],ia.prototype,"bagValue",void 0);Se([u({type:Vi,repeated:"set",optional:!0})],ia.prototype,"bagAttributes",void 0);var jv=cm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};jv=cm=Se([A({type:_.Sequence,itemType:ia})],jv);var um,lm,fm,Ge="1.2.840.113549.1.9",hq=`${Ge}.0`,Xv=`${Ge}.24`,yu=`${Ge}.25`,Zv=`${Ge}.26`,Yv=`${Ge}.27`,dq=`${Xv}.1`,yq=`${Xv}.2`,mq=`${Ge}.1`,gq=`${Ge}.2`,wq=`${Ge}.3`,bq=`${Ge}.4`,xq=`${Ge}.5`,vq=`${Ge}.6`,bm=`${Ge}.7`,_q=`${Ge}.8`,Sq=`${Ge}.9`,Aq=`${Ge}.13`,mu=`${Ge}.14`,Eq=`${Ge}.15`,Cq=`${Ge}.20`,Tq=`${Ge}.21`;var Iq=`${yu}.1`,Oq=`${yu}.2`,Pq=`${yu}.3`,Bq=`${yu}.4`,kq=`${yu}.5`,gu="1.3.6.1.5.5.7.9",Nq=`${gu}.1`,Dq=`${gu}.2`,jq=`${gu}.3`,Rq=`${gu}.4`,Lq=`${gu}.5`,Uq=`${Zv}.1`,Mq=`${Zv}.2`,Kq=`${Yv}.1`,Hq=`${Yv}.2`,Vq=`${Ge}.16`,$q=`${Ge}.22`,Fq=`${Ge}.23`,Wq=`${By}.65`,cp=class extends Qe{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};_e([u({type:h.IA5String})],cp.prototype,"ia5String",void 0);cp=_e([A({type:_.Choice})],cp);var Rv=class extends yr{};Rv=_e([A({type:_.Sequence})],Rv);var Lv=class extends Fi{};Lv=_e([A({type:_.Sequence})],Lv);var Uv=class extends So{};Uv=_e([A({type:_.Sequence})],Uv);var pm=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.IA5String})],pm.prototype,"value",void 0);pm=_e([A({type:_.Choice})],pm);var Mv=class extends cp{};Mv=_e([A({type:_.Choice})],Mv);var Kv=class extends Qe{};Kv=_e([A({type:_.Choice})],Kv);var hm=class{constructor(e=new Date){this.value=e}};_e([u({type:h.GeneralizedTime})],hm.prototype,"value",void 0);hm=_e([A({type:_.Choice})],hm);var Hv=class extends Qe{};Hv=_e([A({type:_.Choice})],Hv);var dm=class{constructor(e="M"){this.value=e}toString(){return this.value}};_e([u({type:h.PrintableString})],dm.prototype,"value",void 0);dm=_e([A({type:_.Choice})],dm);var up=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.PrintableString})],up.prototype,"value",void 0);up=_e([A({type:_.Choice})],up);var Vv=class extends up{};Vv=_e([A({type:_.Choice})],Vv);var $v=class extends Qe{};$v=_e([A({type:_.Choice})],$v);var ym=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.ObjectIdentifier})],ym.prototype,"value",void 0);ym=_e([A({type:_.Choice})],ym);var Fv=class extends We{};Fv=_e([A({type:_.Choice})],Fv);var mm=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};_e([u({type:h.Integer})],mm.prototype,"value",void 0);mm=_e([A({type:_.Choice})],mm);var Wv=class extends Wt{};Wv=_e([A({type:_.Sequence})],Wv);var du=class extends Qe{};du=_e([A({type:_.Choice})],du);var Gv=um=class extends rr{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};Gv=um=_e([A({type:_.Sequence})],Gv);var qv=lm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};qv=lm=_e([A({type:_.Set,itemType:Mr})],qv);var gm=class{constructor(e=""){this.value=e}toString(){return this.value}};_e([u({type:h.BmpString})],gm.prototype,"value",void 0);gm=_e([A({type:_.Choice})],gm);var wm=class extends H{};wm=_e([A({type:_.Sequence})],wm);var zv=fm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};zv=fm=_e([A({type:_.Sequence,itemType:wm})],zv);function Hr(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,wu=xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};wu=xm=Hr([A({type:_.Sequence,itemType:ht})],wu);var cn=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new dt,this.attributes=new wu,Object.assign(this,e)}};Hr([u({type:h.Integer})],cn.prototype,"version",void 0);Hr([u({type:Pe})],cn.prototype,"subject",void 0);Hr([u({type:dt})],cn.prototype,"subjectPKInfo",void 0);Hr([u({type:wu,implicit:!0,context:0})],cn.prototype,"attributes",void 0);var Co=class{constructor(e={}){this.certificationRequestInfo=new cn,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Hr([u({type:cn})],Co.prototype,"certificationRequestInfo",void 0);Hr([u({type:H})],Co.prototype,"signatureAlgorithm",void 0);Hr([u({type:h.BitString})],Co.prototype,"signature",void 0);var Au="crypto.algorithm",Pm=class{getAlgorithms(){return Le.resolveAll(Au)}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}}},Wi="crypto.algorithmProvider";Le.registerSingleton(Wi,Pm);var hp,Zt="1.3.36.3.3.2.8.1.1",Jv=`${Zt}.1`,Qv=`${Zt}.2`,e1=`${Zt}.3`,t1=`${Zt}.4`,r1=`${Zt}.5`,n1=`${Zt}.6`,o1=`${Zt}.7`,i1=`${Zt}.8`,s1=`${Zt}.9`,a1=`${Zt}.10`,c1=`${Zt}.11`,u1=`${Zt}.12`,l1=`${Zt}.13`,f1=`${Zt}.14`,p1="brainpoolP160r1",h1="brainpoolP160t1",d1="brainpoolP192r1",y1="brainpoolP192t1",m1="brainpoolP224r1",g1="brainpoolP224t1",w1="brainpoolP256r1",b1="brainpoolP256t1",x1="brainpoolP320r1",v1="brainpoolP320t1",_1="brainpoolP384r1",S1="brainpoolP384t1",A1="brainpoolP512r1",E1="brainpoolP512t1",Ve="ECDSA",xu=hp=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Ve.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Hx;case"sha-256":return Vx;case"sha-384":return $x;case"sha-512":return Fx}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Hy;break;case"K-256":t=hp.SECP256K1;break;case"P-384":t=Vy;break;case"P-521":t=$y;break;case p1:t=Jv;break;case h1:t=Qv;break;case d1:t=e1;break;case y1:t=t1;break;case m1:t=r1;break;case g1:t=n1;break;case w1:t=o1;break;case b1:t=i1;break;case x1:t=s1;break;case v1:t=a1;break;case _1:t=c1;break;case S1:t=u1;break;case A1:t=l1;break;case E1:t=f1;break}if(t)return new H({algorithm:Ni,parameters:q.serialize(new on({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case ru:return{name:Ve,hash:{name:"SHA-1"}};case nu:return{name:Ve,hash:{name:"SHA-256"}};case ou:return{name:Ve,hash:{name:"SHA-384"}};case iu:return{name:Ve,hash:{name:"SHA-512"}};case Ni:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(q.parse(e.parameters,on).namedCurve){case Hy:return{name:Ve,namedCurve:"P-256"};case hp.SECP256K1:return{name:Ve,namedCurve:"K-256"};case Vy:return{name:Ve,namedCurve:"P-384"};case $y:return{name:Ve,namedCurve:"P-521"};case Jv:return{name:Ve,namedCurve:p1};case Qv:return{name:Ve,namedCurve:h1};case e1:return{name:Ve,namedCurve:d1};case t1:return{name:Ve,namedCurve:y1};case r1:return{name:Ve,namedCurve:m1};case n1:return{name:Ve,namedCurve:g1};case o1:return{name:Ve,namedCurve:w1};case i1:return{name:Ve,namedCurve:b1};case s1:return{name:Ve,namedCurve:x1};case a1:return{name:Ve,namedCurve:v1};case c1:return{name:Ve,namedCurve:_1};case u1:return{name:Ve,namedCurve:S1};case l1:return{name:Ve,namedCurve:A1};case f1:return{name:Ve,namedCurve:E1}}}}return null}};xu.SECP256K1="1.3.132.0.10";xu=hp=cu([_o()],xu);Le.registerSingleton(Au,xu);var R1=Symbol("name"),L1=Symbol("value"),ve=class{constructor(e,t={},n=""){this[R1]=e,this[L1]=n;for(let o in t)this[o]=t[o]}};ve.NAME=R1;ve.VALUE=L1;var Bm=class{static toTextObject(e){let t=new ve("Algorithm Identifier",{},ln.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Ni:{let n=new xu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},ln=class{static toString(e){let t=this.items[e];return t||e}};ln.items={[ji]:"sha1",[Xf]:"sha224",[Ri]:"sha256",[Li]:"sha384",[Ui]:"sha512",[sn]:"rsaEncryption",[Xs]:"sha1WithRSAEncryption",[Xx]:"sha224WithRSAEncryption",[zf]:"sha256WithRSAEncryption",[Zs]:"sha384WithRSAEncryption",[Ys]:"sha512WithRSAEncryption",[Ni]:"ecPublicKey",[ru]:"ecdsaWithSHA1",[qf]:"ecdsaWithSHA224",[nu]:"ecdsaWithSHA256",[ou]:"ecdsaWithSHA384",[iu]:"ecdsaWithSHA512",[vx]:"TLS WWW server authentication",[_x]:"TLS WWW client authentication",[Sx]:"Code Signing",[Ax]:"E-mail Protection",[Ex]:"Time Stamping",[Cx]:"OCSP Signing",[Mx]:"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[ve.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[ve.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[ve.NAME]=a,n.push(...this.serializeObj(f,t));else if(c instanceof ve)c[ve.NAME]=a,n.push(...this.serializeObj(c,t));else if($.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[ve.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=$.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=ln;Un.algorithmSerializer=Bm;var To=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 Un.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 ve(this.getTextName(),{},e)}};To.NAME="ASN";var wr=class r extends To{constructor(...e){let t;$.BufferSourceConverter.isBufferSource(e[0])?t=$.BufferSourceConverter.toArrayBuffer(e[0]):t=q.serialize(new yt({extnID:e[0],critical:e[1],extnValue:new ae($.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,yt)}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[ve.NAME]===r.NAME&&(e[ve.NAME]=ln.toString(this.type)),e}},U1,vu=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[U1]="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}};U1=Symbol.toStringTag;vu.DEFAULT="default";var bt=new vu,cT=/^[0-2](?:\.[1-9][0-9]*)+$/;function uT(r){return new RegExp(cT).test(r)}var yp=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 uT(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},zt=new yp;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 lT(r,e){return`\\${$.Convert.ToHex($.Convert.FromUtf8String(e)).toUpperCase()}`}function fT(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,lT)}var gr=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 yp,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:$.BufferSourceConverter.isBufferSource(e)?this.asn=q.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?`#${$.Convert.ToHex(t.value.anyValue)}`:fT(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 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 ao([f])),i=l}return t}fromJSON(e){let t=new Pe;for(let n of e){let o=new ao;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 hi({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]||bt.get()):n=e[0]||bt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},M1="Cannot initialize GeneralName from ASN.1 data.",C1=`${M1} Unsupported string format in use.`,pT=`${M1} Value doesn't match to GUID regular expression.`,T1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,I1="1.3.6.1.4.1.311.25.1",O1="1.3.6.1.4.1.311.20.2.3",vm="dns",_m="dn",Sm="email",Am="ip",Em="url",Cm="guid",Tm="upn",lp="id",un=class extends To{constructor(...e){let t;if(e.length===2)switch(e[0]){case _m:{let n=new gr(e[1]).toArrayBuffer(),o=q.parse(n,Pe);t=new ue({directoryName:o});break}case vm:t=new ue({dNSName:e[1]});break;case Sm:t=new ue({rfc822Name:e[1]});break;case Cm:{let n=new RegExp(T1,"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 ue({otherName:new co({typeId:I1,value:q.serialize(new ae($.Convert.FromHex(o)))})});break}case Am:t=new ue({iPAddress:e[1]});break;case lp:t=new ue({registeredID:e[1]});break;case Tm:{t=new ue({otherName:new co({typeId:O1,value:q.serialize(Jd.toASN(e[1]))})});break}case Em:t=new ue({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],ue):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=vm,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=Sm,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=Am,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Em,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=lp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=_m,this.value=new gr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===I1){this.type=Cm;let t=q.parse(e.otherName.value,ae),n=new RegExp(T1,"i").exec($.Convert.ToHex(t));if(!n)throw new Error(pT);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===O1)this.type=Tm,this.value=q.parse(e.otherName.value,Qe).toString();else throw new Error(C1);else throw new Error(C1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case _m:case vm:case Cm:case Am:case lp:case Tm:case Em:e=this.type.toUpperCase();break;case Sm:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===lp&&(t=ln.toString(t)),new ve(e,void 0,t)}},Gi=class extends To{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=q.parse(new un(o.type,o.value).rawData,ue);n.push(i)}t=new Ke(n)}else if($.BufferSourceConverter.isBufferSource(e))t=q.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 un(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[ve.NAME]];Array.isArray(o)||(o=[],e[n[ve.NAME]]=o),o.push(n)}return e}};Gi.NAME="GeneralNames";var bu="-{5}",_u="\\n",hT=`[^${_u}]+`,dT=`${bu}BEGIN (${hT}(?=${bu}))${bu}`,yT=`${bu}END \\1${bu}`,sa="\\n",mT=`[^:${_u}]+`,gT=`(?:[^${_u}]+${sa}(?: +[^${_u}]+${sa})*)`,wT="[a-zA-Z0-9=+/]+",bT=`(?:${wT}${sa})+`,P1=`${dT}${sa}(?:((?:${mT}: ${gT})+))?${sa}?(${bT})${yT}`,Rt=class{static isPem(e){return typeof e=="string"&&new RegExp(P1,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(P1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${_u}]+`,"g"),""),s={type:o[1],headers:[],rawData:$.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(sa,"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(!$.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 l of e.headers)o.push(`${l.key}: ${l.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
|
+
`)}};Rt.CertificateTag="CERTIFICATE";Rt.CrlTag="CRL";Rt.CertificateRequestTag="CERTIFICATE REQUEST";Rt.PublicKeyTag="PUBLIC KEY";Rt.PrivateKeyTag="PRIVATE KEY";var Io=class r extends To{static isAsnEncoded(e){return $.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Rt.isPem(e))return Rt.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 Rt.isPem(t)?Rt.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 Rt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Ln=class r extends Io{static async create(e,t=bt.get()){if(e instanceof r)return e;if(vu.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){Io.isAsnEncoded(e)?super(e,dt):super(e),this.tag=Rt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||bt.get()):t=e[0]||bt.get();let i=this.rawData,s=q.parse(this.rawData,dt);return s.algorithm.algorithm===bo&&(i=xT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Le.resolve(Wi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case sn:{let o=q.parse(e.subjectPublicKey,ea),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]||bt.get()):n=e[0]||bt.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=bt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=bt.get();let o=q.parse(this.rawData,dt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,dt);switch(e.Algorithm=Un.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ni:e["EC Point"]=t.subjectPublicKey;break;case sn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function xT(r,e){return r.algorithm=new H({algorithm:sn,parameters:null}),e=q.serialize(r),e}var mp=class r extends wr{static async create(e,t=!1,n=bt.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($.Convert.ToHex(i),t)}constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new en({keyIdentifier:new mi($.Convert.FromHex(e[0]))});super(Cf,e[1],q.serialize(t))}else{let t=e[0],n=t.name instanceof Gi?q.parse(t.name.rawData,Ke):t.name,o=new en({authorityCertIssuer:n,authorityCertSerialNumber:$.Convert.FromHex(t.serialNumber)});super(Cf,e[1],q.serialize(o))}}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,en);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,en);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Gi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};mp.NAME="Authority Key Identifier";var aa=class extends wr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,gi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new gi({cA:e[0],pathLenConstraint:e[1]});super(Tf,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}};aa.NAME="Basic Constraints";var B1;(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"})(B1||(B1={}));var gp=class extends wr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Lc);this.usages=t.map(n=>n)}else{let t=new Lc(e[0]);super(Bf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>ln.toString(t)).join(", "),e}};gp.NAME="Extended Key Usages";var k1;(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"})(k1||(k1={}));var wp=class extends wr{constructor(...e){if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,ks);this.usages=t.toNumber()}else{let t=new ks(e[0]);super(kf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,ks);return e[""]=t.toJSON().join(", "),e}};wp.NAME="Key Usages";var bp=class r extends wr{static async create(e,t=!1,n=bt.get()){let i=await(await Ln.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,$t);this.keyId=$.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?$.Convert.FromHex(e[0]):e[0],n=new $t(t);super(Ay,e[1],q.serialize(n)),this.keyId=$.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,$t);return e[""]=t,e}};bp.NAME="Subject Key Identifier";var xp=class extends wr{constructor(...e){$.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(_y,e[1],new Gi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,Rf);this.names=new Gi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};xp.NAME="Subject Alternative Name";var Xt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new wr(e),n=this.items.get(t.type);return n?new n(e):t}};Xt.items=new Map;var vp=class extends wr{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=q.parse(this.value,kc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new kc(n.map(s=>new wi({policyIdentifier:s})));super(Of,o,q.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new ve("",{},ln.toString(t))),e}};vp.NAME="Certificate Policies";Xt.register(Of,vp);var _p=class extends wr{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 tn({distributionPoint:new Pn({fullName:[new ue({uniformResourceIdentifier:s})]})})),i=new fo(o);super(Pf,e[1],q.serialize(i))}else{let n=new fo(e[0]);super(Pf,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,fo);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 un(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};_p.NAME="CRL Distribution Points";var Sp=class extends wr{constructor(...e){var t,n,o,i;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof yi){let s=new yi(e[0]);super(Ef,e[1],q.serialize(s))}else{let s=e[0],a=new yi;pp(a,s,sy,"ocsp"),pp(a,s,ay,"caIssuers"),pp(a,s,cy,"timeStamping"),pp(a,s,uy,"caRepository"),super(Ef,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,yi).forEach(n=>{switch(n.accessMethod){case sy:this.ocsp.push(new un(n.accessLocation));break;case ay:this.caIssuers.push(new un(n.accessLocation));break;case cy:this.timeStamping.push(new un(n.accessLocation));break;case uy:this.caRepository.push(new un(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&fp(e,"OCSP",this.ocsp),this.caIssuers.length&&fp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&fp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&fp(e,"CA Repository",this.caRepository),e}};Sp.NAME="Authority Info Access";function fp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new ve("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[ve.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function pp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new un("url",s)),r.push(new In({accessMethod:t,accessLocation:q.parse(s.rawData,ue)}))})}var ca=class r extends To{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 ht({type:n,values:o}))}super(t,ht)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new ve("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[ve.NAME]===r.NAME&&(e[ve.NAME]=ln.toString(this.type)),e}};ca.NAME="Attribute";var Ap=class extends ca{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new du({printableString:e[0]});super(bm,[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[ve.VALUE]=this.password,e}};Ap.NAME="Challenge Password";var Su=class extends ca{constructor(...e){var t;if($.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new rr;for(let i of n)o.push(q.parse(i.rawData,yt));super(mu,[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],rr);this.items=t.map(n=>Xt.create(q.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[ve.NAME]]=n;return e}};Su.NAME="Extensions";var ua=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ca(e),n=this.items.get(t.type);return n?new n(e):t}};ua.items=new Map;var Eu="crypto.signatureFormatter",km=class{toAsnSignature(e,t){return $.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return $.BufferSourceConverter.toArrayBuffer(t)}},dp,Nm=dp=class{static createPssParams(e,t){let n=dp.getHashAlgorithm(e);return n?new an({hashAlgorithm:n,maskGenAlgorithm:new H({algorithm:xo,parameters:q.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Le.resolve(Wi);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:Xs,parameters:null});case"sha-256":return new H({algorithm:zf,parameters:null});case"sha-384":return new H({algorithm:Zs,parameters:null});case"sha-512":return new H({algorithm:Ys,parameters:null})}}else return new H({algorithm:sn,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=dp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new H({algorithm:bo,parameters:q.serialize(t)})}else return new H({algorithm:bo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case sn:return{name:"RSASSA-PKCS1-v1_5"};case Xs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case zf:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Zs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Ys:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case bo:if(e.parameters){let t=q.parse(e.parameters,an);return{name:"RSA-PSS",hash:Le.resolve(Wi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Nm=dp=cu([_o()],Nm);Le.registerSingleton(Au,Nm);var Dm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new H({algorithm:ji});case"sha-256":return new H({algorithm:Ri});case"sha-384":return new H({algorithm:Li});case"sha-512":return new H({algorithm:Ui})}return null}toWebAlgorithm(e){switch(e.algorithm){case ji:return{name:"SHA-1"};case Ri:return{name:"SHA-256"};case Li:return{name:"SHA-384"};case Ui:return{name:"SHA-512"}}return null}};Dm=cu([_o()],Dm);Le.registerSingleton(Au,Dm);var Mn=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 Di,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,Di),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}};Mn.namedCurveSize=new Map;Mn.defaultNamedCurveSize=32;var Im="1.3.101.110",N1="1.3.101.111",Om="1.3.101.112",D1="1.3.101.113",jm=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=Om;break;case"x25519":t=Im;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=Om;break;case"ed448":t=D1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Im;break;case"x448":t=N1;break}}return t?new H({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case Om:return{name:"Ed25519"};case D1:return{name:"EdDSA",namedCurve:"Ed448"};case Im:return{name:"X25519"};case N1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};jm=cu([_o()],jm);Le.registerSingleton(Au,jm);var Rm=class extends Io{constructor(e){Io.isAsnEncoded(e)?super(e,Co):super(e),this.tag=Rt.CertificateRequestTag}onInit(e){this.tbs=q.serialize(e.certificationRequestInfo),this.publicKey=new Ln(e.certificationRequestInfo.subjectPKInfo);let t=Le.resolve(Wi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>ua.create(q.serialize(o)));let n=this.getAttribute(mu);this.extensions=[],n instanceof Su&&(this.extensions=n.items),this.subjectName=new gr(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=bt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Le.resolveAll(Eu).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,Co),n=t.certificationRequestInfo,o=new ve("",{Version:`${rn[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new ve("");for(let s of this.attributes){let a=s.toTextObject();i[a[ve.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new ve("",{Algorithm:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Rm.NAME="PKCS#10 Certificate Request";var la=class extends Io{constructor(e){Io.isAsnEncoded(e)?super(e,pr):super(e),this.tag=Rt.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 gr(t.subject),this.subject=new gr(t.subject).toString(),this.issuerName=new gr(t.issuer),this.issuer=this.issuerName.toString();let o=Le.resolve(Wi);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=>Xt.create(q.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=bt.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($.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(Eu).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=bt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=bt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,pr),n=t.tbsCertificate,o=new ve("",{Version:`${rn[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Un.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new ve("",{"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 ve("");for(let s of this.extensions){let a=s.toTextObject();i[a[ve.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new ve("",{Algorithm:Un.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};la.NAME="Certificate";var Ep=class{static async createSelfSigned(e,t=bt.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=bt.get()){var n;let o;e.publicKey instanceof Ln?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)):t.getRandomValues(new Uint8Array(16));if(i[0]>127){let d=new Uint8Array(i.length+1);d[0]=0,d.set(i,1),i=d}let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new pr({tbsCertificate:new mt({version:rn.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new rr(((n=e.extensions)===null||n===void 0?void 0:n.map(d=>q.parse(d.rawData,yt)))||[]),subjectPublicKeyInfo:q.parse(o,dt)})});if(e.subject){let d=e.subject instanceof gr?e.subject:new gr(e.subject);c.tbsCertificate.subject=q.parse(d.toArrayBuffer(),Pe)}if(e.issuer){let d=e.issuer instanceof gr?e.issuer:new gr(e.issuer);c.tbsCertificate.issuer=q.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(Wi);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(f);let y=q.serialize(c.tbsCertificate),m="signingKey"in e?await t.subtle.sign(f,e.signingKey,y):e.signature,x=Le.resolveAll(Eu).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 la(q.serialize(c))}},j1;(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"})(j1||(j1={}));Xt.register(Tf,aa);Xt.register(Bf,gp);Xt.register(kf,wp);Xt.register(Ay,bp);Xt.register(Cf,mp);Xt.register(_y,xp);Xt.register(Pf,_p);Xt.register(Ef,Sp);ua.register(bm,Ap);ua.register(mu,Su);Le.registerSingleton(Eu,km);Le.registerSingleton(Eu,Mn);Mn.namedCurveSize.set("P-256",32);Mn.namedCurveSize.set("K-256",32);Mn.namedCurveSize.set("P-384",48);Mn.namedCurveSize.set("P-521",66);var Kn="/",K1=new TextEncoder().encode(Kn),Cp=K1[0],Cu=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=pe(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]!==Cp)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(Kn))}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=K1),this._buf[0]!==Cp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Cp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Cp;)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(Kn).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(Kn)||(e+=Kn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Kn):new r(e.slice(0,-1).join(Kn))}child(e){return this.toString()===Kn?e:e.toString()===Kn?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(),...ST(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 ST(r){return[].concat(...r)}var Tp=class extends Fn{async listen(){throw new Yl("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Lm(){let r=Ye(),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 H1(){let r=Lm(),e=Lm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function AT(r){return r[Symbol.asyncIterator]!=null}async function ET(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*CT(r){let e=new AbortController,t=Fl();ET(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*TT(r){for(let e of r)yield*e}function IT(...r){let e=[];for(let t of r)AT(t)||e.push(t);return e.length===r.length?TT(e):CT(r)}var V1=IT;function $1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Um(r)){let n=r;r=()=>n.source}else if(W1(r)||F1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Um(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++)Um(t[n])&&(t[n]=PT(t[n]));return OT(...t)}var OT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},F1=r=>r?.[Symbol.asyncIterator]!=null,W1=r=>r?.[Symbol.iterator]!=null,Um=r=>r==null?!1:r.sink!=null&&r.source!=null,PT=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=_s({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(F1(i))o=async function*(){yield*i,n.end()};else if(W1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return V1(n,o())}return r.source};var fa=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function q1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ip(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Op(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ot(r,...e){if(!q1(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 Mm(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 z1(r,e){Ot(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Hn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Vn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function BT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var kT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function NT(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Pp(r){if(typeof r=="string")r=NT(r);else if(q1(r))r=Bp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function X1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function Z1(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 Km=(r,e)=>{function t(n,...o){if(Ot(n),!kT)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?Ot(f):Ot(f,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Ot(o[1]);let s=e(n,...o),a=(f,p)=>{if(p!==void 0){if(f!==2)throw new Error("cipher output not supported");Ot(p)}},c=!1;return{encrypt(f,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Ot(f),a(s.encrypt.length,p),s.encrypt(f,p)},decrypt(f,p){if(Ot(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 Hm(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&&!DT(e))throw new Error("invalid output, must be aligned");return e}function G1(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 Y1(r,e,t){Ip(t);let n=new Uint8Array(16),o=BT(n);return G1(o,0,BigInt(e),t),G1(o,8,BigInt(r),t),n}function DT(r){return r.byteOffset%4===0}function Bp(r){return Uint8Array.from(r)}var Q1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),jT=Q1("expand 16-byte k"),RT=Q1("expand 32-byte k"),LT=Hn(jT),UT=Hn(RT);function te(r,e){return r<<e|r>>>32-e}function Vm(r){return r.byteOffset%4===0}var kp=64,MT=16,e_=2**32-1,J1=new Uint32Array;function KT(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(kp),f=Hn(l),p=Vm(o)&&Vm(i),y=p?Hn(o):J1,m=p?Hn(i):J1;for(let x=0;x<c;s++){if(r(e,t,n,f,s,a),s>=e_)throw new Error("arx: counter overflow");let v=Math.min(kp,c-x);if(p&&v===kp){let d=x/4;if(x%4!==0)throw new Error("arx: invalid block position");for(let I=0,D;I<MT;I++)D=d+I,m[D]=y[D]^f[I];x+=kp;continue}for(let d=0,I;d<v;d++)I=x+d,i[I]=o[I]^l[d];x+=v}}function $m(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=X1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Op(o),Op(s),Ip(i),Ip(t),(a,c,l,f,p=0)=>{Ot(a),Ot(c),Ot(l);let y=l.length;if(f===void 0&&(f=new Uint8Array(y)),Ot(f),Op(p),p<0||p>=e_)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=Bp(a)),d=UT;else if(x===16&&t)v=new Uint8Array(32),v.set(a),v.set(a,16),d=LT,m.push(v);else throw new Error(`arx: invalid 32-byte key, got length=${x}`);Vm(c)||m.push(c=Bp(c));let I=Hn(v);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,I,Hn(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=Hn(c);return KT(r,d,I,j,l,f,p,s),Vn(...m),f}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Fm=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Pp(e),Ot(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),l=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let f=0;f<8;f++)this.pad[f]=xt(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=xt(e,t+0),D=xt(e,t+2),j=xt(e,t+4),Z=xt(e,t+6),P=xt(e,t+8),M=xt(e,t+10),V=xt(e,t+12),K=xt(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),N=i[6]+((P>>>14|M<<2)&8191),L=i[7]+((M>>>11|V<<5)&8191),W=i[8]+((V>>>8|K<<8)&8191),X=i[9]+(K>>>5|o),G=0,ie=G+g*a+T*(5*d)+E*(5*v)+O*(5*x)+B*(5*m);G=ie>>>13,ie&=8191,ie+=R*(5*y)+N*(5*p)+L*(5*f)+W*(5*l)+X*(5*c),G+=ie>>>13,ie&=8191;let Y=G+g*c+T*a+E*(5*d)+O*(5*v)+B*(5*x);G=Y>>>13,Y&=8191,Y+=R*(5*m)+N*(5*y)+L*(5*p)+W*(5*f)+X*(5*l),G+=Y>>>13,Y&=8191;let U=G+g*l+T*c+E*a+O*(5*d)+B*(5*v);G=U>>>13,U&=8191,U+=R*(5*x)+N*(5*m)+L*(5*y)+W*(5*p)+X*(5*f),G+=U>>>13,U&=8191;let he=G+g*f+T*l+E*c+O*a+B*(5*d);G=he>>>13,he&=8191,he+=R*(5*v)+N*(5*x)+L*(5*m)+W*(5*y)+X*(5*p),G+=he>>>13,he&=8191;let Oe=G+g*p+T*f+E*l+O*c+B*a;G=Oe>>>13,Oe&=8191,Oe+=R*(5*d)+N*(5*v)+L*(5*x)+W*(5*m)+X*(5*y),G+=Oe>>>13,Oe&=8191;let se=G+g*y+T*p+E*f+O*l+B*c;G=se>>>13,se&=8191,se+=R*a+N*(5*d)+L*(5*v)+W*(5*x)+X*(5*m),G+=se>>>13,se&=8191;let Ne=G+g*m+T*y+E*p+O*f+B*l;G=Ne>>>13,Ne&=8191,Ne+=R*c+N*a+L*(5*d)+W*(5*v)+X*(5*x),G+=Ne>>>13,Ne&=8191;let vt=G+g*x+T*m+E*y+O*p+B*f;G=vt>>>13,vt&=8191,vt+=R*l+N*c+L*a+W*(5*d)+X*(5*v),G+=vt>>>13,vt&=8191;let et=G+g*v+T*x+E*m+O*y+B*p;G=et>>>13,et&=8191,et+=R*f+N*l+L*c+W*a+X*(5*d),G+=et>>>13,et&=8191;let tt=G+g*d+T*v+E*x+O*m+B*y;G=tt>>>13,tt&=8191,tt+=R*p+N*f+L*l+W*c+X*a,G+=tt>>>13,tt&=8191,G=(G<<2)+G|0,G=G+ie|0,ie=G&8191,G=G>>>13,Y+=G,i[0]=ie,i[1]=Y,i[2]=U,i[3]=he,i[4]=Oe,i[5]=se,i[6]=Ne,i[7]=vt,i[8]=et,i[9]=tt}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;Vn(n)}update(e){Mm(this),e=Pp(e),Ot(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(){Vn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Mm(this),z1(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 HT(r){let e=(n,o)=>r(o).update(Pp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var t_=HT(r=>new Fm(r));function o_(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,V=a,K=c,g=l,T=f,E=p,O=y,B=m,R=x,N=v,L=d,W=I,X=D,G=j,ie=Z,Y=P;for(let he=0;he<i;he+=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),V=V+E|0,G=te(G^V,16),N=N+G|0,E=te(E^N,12),V=V+E|0,G=te(G^V,8),N=N+G|0,E=te(E^N,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),W=W+Y|0,B=te(B^W,12),g=g+B|0,Y=te(Y^g,8),W=W+Y|0,B=te(B^W,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),V=V+O|0,X=te(X^V,16),W=W+X|0,O=te(O^W,12),V=V+O|0,X=te(X^V,8),W=W+X|0,O=te(O^W,7),K=K+B|0,G=te(G^K,16),R=R+G|0,B=te(B^R,12),K=K+B|0,G=te(G^K,8),R=R+G|0,B=te(B^R,7),g=g+T|0,ie=te(ie^g,16),N=N+ie|0,T=te(T^N,12),g=g+T|0,ie=te(ie^g,8),N=N+ie|0,T=te(T^N,7);let U=0;n[U++]=s+M|0,n[U++]=a+V|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+N|0,n[U++]=d+L|0,n[U++]=I+W|0,n[U++]=D+X|0,n[U++]=j+G|0,n[U++]=Z+ie|0,n[U++]=P+Y|0}function VT(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 $T=$m(o_,{counterRight:!1,counterLength:4,allowShortKeys:!1}),FT=$m(o_,{counterRight:!1,counterLength:8,extendNonceFn:VT,allowShortKeys:!1});var WT=new Uint8Array(16),r_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(WT.subarray(t))},GT=new Uint8Array(32);function n_(r,e,t,n,o){let i=r(e,t,GT),s=t_.create(i);o&&r_(s,o),r_(s,n);let a=Y1(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Vn(i,a),c}var i_=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Hm(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=n_(r,e,t,c,n);return s.set(l,a),Vn(l),s},decrypt(i,s){s=Hm(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=n_(r,e,t,a,n);if(!Z1(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Vn(l),s}}),Wm=Km({blockSize:64,nonceLength:12,tagLength:16},i_($T)),SX=Km({blockSize:64,nonceLength:24,tagLength:16},i_(FT));function a_(r,e,t){return Aa(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ys(r,zn(t),zn(e))}var Gm=Uint8Array.from([0]),s_=Uint8Array.of();function c_(r,e,t,n=32){Aa(r),jo(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=s_);let s=new Uint8Array(i*o),a=ys.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let f=0;f<i;f++)Gm[0]=f+1,c.update(f===0?s_:l).update(t).update(Gm).digestInto(l),s.set(l,o*f),a._cloneInto(c);return a.destroy(),c.destroy(),Sr(l,Gm),s.slice(0,n)}var qm={hashSHA256(r){return eo(r.subarray())},getHKDF(r,e){let t=a_(eo,e,r),o=c_(eo,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=Na.utils.randomPrivateKey();return{publicKey:Na.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Na.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Na.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Wm(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Wm(n,e,t).decrypt(r.subarray(),o)}};var u_=qm;function l_(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 pa=r=>{let e=ot(2);return e[0]=r>>8,e[1]=r,e};pa.bytes=2;var Tu=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)};Tu.bytes=2;function f_(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 zm(r,e){!e.enabled||!fa||(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 Xm(r,e){!e.enabled||!fa||(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 p_(r,e){!e.enabled||!fa||e(r?`REMOTE_STATIC_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote static public key.")}function Zm(r,e){!e.enabled||!fa||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ym(r,e,t){!t.enabled||!fa||(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 ha=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var qT=0,zT=4294967295,XT="Cipherstate has reached maximum n, a new handshake must be performed",Np=class{n;bytes;view;constructor(e=qT){this.n=e,this.bytes=nt(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>zT)throw new Error(XT)}};var qi=nt(0),da=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Np(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}},Jm=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=pe(t,"utf-8");this.h=ZT(e,n),this.ck=this.h,this.cs=new da(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new da(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,qi);return[new da(this.crypto,e),new da(this.crypto,t)]}},Qm=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 Jm(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()}},Iu=class extends Qm{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 ha(`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 ha(`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 ha(`handshake stage 2 validation fail: ${t.message}`)}}};function ZT(r,e){if(e.length<=32){let t=nt(32);return t.set(e),t}else return r.hash(e)}var Dp;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((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 Ka('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 Ka('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=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Dp||(Dp={}));var Ou;(function(r){let e;r.codec=()=>(e==null&&(e=Pr((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),Dp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:nt(0),identitySig:nt(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=Dp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Or(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Ou||(Ou={}));async function eg(r,e,t){let n=await r.sign(h_(e));return Ou.encode({identityKey:qn(r.publicKey),identitySig:n,extensions:t})}async function tg(r,e,t){try{let n=Ou.decode(r),o=Ga(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=h_(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Nu(n.message)}}function h_(r){let e=pe("noise-libp2p-static-key:");return r instanceof Uint8Array?Pt([e,r],e.length+r.length):(r.prepend(e),r)}async function d_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await eg(i,a.publicKey,l),p=new Iu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});zm(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(qi),e),t.trace("Stage 0 - Initiator finished sending first message."),Xm(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."),Zm(p.re,t),p_(p.rs,t),t.trace("Initiator going to check remote's signature...");let m=await tg(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 Ym(x,v,t),{payload:m,encrypt:d=>x.encryptWithAd(qi,d),decrypt:(d,I)=>v.decryptWithAd(qi,d,I)}}async function y_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,f=await eg(i,a.publicKey,l),p=new Iu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});zm(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."),Zm(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."),Xm(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 tg(y,p.rs,c),[x,v]=p.ss.split();return Ym(x,v,t),{payload:m,encrypt:d=>v.encryptWithAd(qi,d),decrypt:(d,I)=>x.decryptWithAd(qi,d,I)}}var g_=16;function w_(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(pa(s.byteLength),s)}}}function b_(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-g_<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-g_);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var jp=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??u_;this.crypto=l_(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?f_(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??nt(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Zi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=uc(e,{lengthEncoder:pa,lengthDecoder:Tu,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=Ga(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:cd(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 Du("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=uc(e,{lengthEncoder:pa,lengthDecoder:Tu,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=Ga(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:cd(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 d_({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 y_({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]=H1(),i=e.unwrap();return await $1(n,w_(t,this.metrics),i,s=>Zo(s,{lengthDecoder:Tu}),b_(t,this.metrics),n),o}};function x_(r={}){return e=>new jp(e,r)}var rg=Object.values(ko).map(r=>r.decoder).reduce((r,e)=>r.or(e)),YT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function v_(r){return r?.match(YT)?.groups?.fingerprint}function ng(r){let t=r.stringTuples().filter(n=>n[0]===Xw).map(n=>n[1])[0];if(t===void 0||t==="")throw new Te(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function JT(r){return xr.decode(rg.decode(r))}function QT(r){let e=JT(ng(r)),t=eI(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 Zl(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function __(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=St(ir.code,t);return bn(`/certhash/${pn.encode(n.bytes)}`)}function eI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Jl(r)}}function S_(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=QT(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,7 +23,7 @@ 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:${
|
26
|
+
a=max-message-size:${xs}
|
27
27
|
a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
|
28
28
|
a=end-of-candidates
|
29
29
|
`}}function A_(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
|
@@ -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:${
|
42
|
+
a=max-message-size:${xs}
|
43
43
|
a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
|
44
44
|
a=end-of-candidates
|
45
|
-
`}}function og(r,e){if(r.sdp===void 0)throw new
|
45
|
+
`}}function og(r,e){if(r.sdp===void 0)throw new Te("Can't munge a missing SDP");let t=r.sdp.includes(`\r
|
46
46
|
`)?`\r
|
47
47
|
`:`
|
48
48
|
`;return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
|
49
49
|
a=ice-ufrag:`+e+t).replace(/\na=ice-pwd:[^\n]*\n/,`
|
50
|
-
a=ice-pwd:`+e+t),r}var ig=pe("libp2p-webrtc-noise:");function C_(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=pe(n,"hex"),i=St(ir.code,o),s=rg.decode(ng(e)),a=ig.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?Pt([ig,s,i.bytes],a):Pt([ig,i.bytes,s],a)}var tI=
|
51
|
-
`)}var Rp=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 Fn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new
|
50
|
+
a=ice-pwd:`+e+t),r}var ig=pe("libp2p-webrtc-noise:");function C_(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=pe(n,"hex"),i=St(ir.code,o),s=rg.decode(ng(e)),a=ig.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?Pt([ig,s,i.bytes],a):Pt([ig,i.bytes,s],a)}var tI=ic?"iceconnectionstatechange":"connectionstatechange";async function T_(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=og(p,e);t.log.trace("client setting local offer %s",y.sdp),await r.setLocalDescription(y);let m=S_(t.remoteAddr,e);t.log.trace("client setting server description %s",m.sdp),await r.setRemoteDescription(m)}else{let p=A_(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=og(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 cc(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(__(p))}let o=v_(r.localDescription?.sdp);if(o==null)throw new ro("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=C_(o,t.remoteAddr,t.role),s=x_({prologueBytes:i})(t),a=As({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new zo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(tI,()=>{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 to(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 I_(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 O_(r){let e=await ml(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 Rp=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 Fn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new Te("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"})})}[ku]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Zi]=["@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=gl(o));let i=db(),s=await I_("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await T_(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 Hu;return new Tp(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter($w.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(rI(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 O_(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??nb,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Po;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 mw("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 Cu(this.init.certificateDatastoreKey??rb),i=await ml(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Po;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??kd)-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:pn.encode((await ir.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new la(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??kd);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Po;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(!Fe(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 Po;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??ob));n.setMilliseconds(0),o.setMilliseconds(0);let i=await Ep.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 aa(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,pe(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 rI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function nI(r){return e=>new Rp(e,r)}function oI(r){return e=>new rf(e,r)}return W_(iI);})();
|
52
52
|
/*! Bundled license information:
|
53
53
|
|
54
54
|
reflect-metadata/Reflect.js:
|