@libp2p/webrtc 6.0.2 → 6.0.3-de2ad9ca5
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 +6 -6
- package/dist/index.min.js.map +3 -3
- package/dist/src/muxer.d.ts +8 -0
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +38 -15
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/private-to-private/initiate-connection.d.ts +1 -2
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +5 -4
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/signaling-stream-handler.js +4 -4
- package/dist/src/private-to-private/signaling-stream-handler.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +5 -3
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-public/listener.d.ts +1 -0
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +9 -4
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +5 -3
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/private-to-public/utils/connect.d.ts +4 -4
- package/dist/src/private-to-public/utils/connect.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/connect.js +7 -9
- package/dist/src/private-to-public/utils/connect.js.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.browser.d.ts +6 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.browser.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.browser.js +15 -3
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.browser.js.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts +17 -2
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js +18 -7
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js.map +1 -1
- package/dist/src/rtcpeerconnection-to-conn.d.ts +0 -1
- package/dist/src/rtcpeerconnection-to-conn.d.ts.map +1 -1
- package/dist/src/rtcpeerconnection-to-conn.js.map +1 -1
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +25 -17
- package/dist/src/stream.js.map +1 -1
- package/dist/src/util.js +1 -1
- package/dist/src/util.js.map +1 -1
- package/package.json +8 -8
- package/src/muxer.ts +50 -15
- package/src/private-to-private/initiate-connection.ts +6 -5
- package/src/private-to-private/signaling-stream-handler.ts +4 -4
- package/src/private-to-private/transport.ts +6 -4
- package/src/private-to-public/listener.ts +10 -4
- package/src/private-to-public/transport.ts +8 -3
- package/src/private-to-public/utils/connect.ts +11 -14
- package/src/private-to-public/utils/get-rtcpeerconnection.browser.ts +20 -3
- package/src/private-to-public/utils/get-rtcpeerconnection.ts +31 -8
- package/src/rtcpeerconnection-to-conn.ts +0 -1
- package/src/stream.ts +26 -18
- package/src/util.ts +1 -1
- package/dist/typedoc-urls.json +0 -14
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 oS=Object.create;var Qu=Object.defineProperty;var iS=Object.getOwnPropertyDescriptor;var sS=Object.getOwnPropertyNames;var aS=Object.getPrototypeOf,cS=Object.prototype.hasOwnProperty;var np=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),vt=(r,e)=>{for(var t in e)Qu(r,t,{get:e[t],enumerable:!0})},zg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of sS(e))!cS.call(r,o)&&o!==t&&Qu(r,o,{get:()=>e[o],enumerable:!(n=iS(e,o))||n.enumerable});return r};var Rr=(r,e,t)=>(t=r!=null?oS(aS(r)):{},zg(e||!r||!r.__esModule?Qu(t,"default",{value:r,enumerable:!0}):t,r)),uS=r=>zg(Qu({},"__esModule",{value:!0}),r);var tx=np(()=>{var ex;(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,f){return function(p,h){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:h}),f&&f(p,h)}}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,f=!a&&!c,p={create:a?function(){return rp(Object.create(null))}:c?function(){return rp({__proto__:null})}:function(){return rp({})},has:f?function(w,E){return n.call(w,E)}:function(w,E){return E in w},get:f?function(w,E){return n.call(w,E)?w[E]:void 0}:function(w,E){return w[E]}},h=Object.getPrototypeOf(Function),y=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:QA(),b=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:eS(),g=typeof WeakMap=="function"?WeakMap:tS(),C=o?Symbol.for("@reflect-metadata:registry"):void 0,m=ZA(),S=YA(m);function N(w,E,P,$){if(O(P)){if(!rn(w))throw new TypeError;if(!jn(E))throw new TypeError;return V(w,E)}else{if(!rn(w))throw new TypeError;if(!ee(E))throw new TypeError;if(!ee($)&&!O($)&&!pe($))throw new TypeError;return pe($)&&($=void 0),P=Ie(P),B(w,E,P,$)}}e("decorate",N);function I(w,E){function P($,se){if(!ee($))throw new TypeError;if(!O(se)&&!Ju(se))throw new TypeError;L(w,E,$,se)}return P}e("metadata",I);function K(w,E,P,$){if(!ee(P))throw new TypeError;return O($)||($=Ie($)),L(w,E,P,$)}e("defineMetadata",K);function Z(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),A(w,E,P)}e("hasMetadata",Z);function q(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),v(w,E,P)}e("hasOwnMetadata",q);function re(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),D(w,E,P)}e("getMetadata",re);function R(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),U(w,E,P)}e("getOwnMetadata",R);function k(w,E){if(!ee(w))throw new TypeError;return O(E)||(E=Ie(E)),T(w,E)}e("getMetadataKeys",k);function G(w,E){if(!ee(w))throw new TypeError;return O(E)||(E=Ie(E)),M(w,E)}e("getOwnMetadataKeys",G);function Y(w,E,P){if(!ee(E))throw new TypeError;if(O(P)||(P=Ie(P)),!ee(E))throw new TypeError;O(P)||(P=Ie(P));var $=Sa(E,P,!1);return O($)?!1:$.OrdinaryDeleteMetadata(w,E,P)}e("deleteMetadata",Y);function V(w,E){for(var P=w.length-1;P>=0;--P){var $=w[P],se=$(E);if(!O(se)&&!pe(se)){if(!jn(se))throw new TypeError;E=se}}return E}function B(w,E,P,$){for(var se=w.length-1;se>=0;--se){var Xe=w[se],tt=Xe(E,P,$);if(!O(tt)&&!pe(tt)){if(!ee(tt))throw new TypeError;$=tt}}return $}function A(w,E,P){var $=v(w,E,P);if($)return!0;var se=tp(E);return pe(se)?!1:A(w,se,P)}function v(w,E,P){var $=Sa(E,P,!1);return O($)?!1:Ke($.OrdinaryHasOwnMetadata(w,E,P))}function D(w,E,P){var $=v(w,E,P);if($)return U(w,E,P);var se=tp(E);if(!pe(se))return D(w,se,P)}function U(w,E,P){var $=Sa(E,P,!1);if(!O($))return $.OrdinaryGetOwnMetadata(w,E,P)}function L(w,E,P,$){var se=Sa(P,$,!0);se.OrdinaryDefineOwnMetadata(w,E,P,$)}function T(w,E){var P=M(w,E),$=tp(w);if($===null)return P;var se=T($,E);if(se.length<=0)return P;if(P.length<=0)return se;for(var Xe=new b,tt=[],we=0,z=P;we<z.length;we++){var J=z[we],te=Xe.has(J);te||(Xe.add(J),tt.push(J))}for(var ne=0,ve=se;ne<ve.length;ne++){var J=ve[ne],te=Xe.has(J);te||(Xe.add(J),tt.push(J))}return tt}function M(w,E){var P=Sa(w,E,!1);return P?P.OrdinaryOwnMetadataKeys(w,E):[]}function W(w){if(w===null)return 1;switch(typeof w){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return w===null?1:6;default:return 6}}function O(w){return w===void 0}function pe(w){return w===null}function be(w){return typeof w=="symbol"}function ee(w){return typeof w=="object"?w!==null:typeof w=="function"}function Ae(w,E){switch(W(w)){case 0:return w;case 1:return w;case 2:return w;case 3:return w;case 4:return w;case 5:return w}var P=E===3?"string":E===5?"number":"default",$=Aa(w,i);if($!==void 0){var se=$.call(w,P);if(ee(se))throw new TypeError;return se}return Be(w,P==="default"?"number":P)}function Be(w,E){if(E==="string"){var P=w.toString;if(pr(P)){var $=P.call(w);if(!ee($))return $}var se=w.valueOf;if(pr(se)){var $=se.call(w);if(!ee($))return $}}else{var se=w.valueOf;if(pr(se)){var $=se.call(w);if(!ee($))return $}var Xe=w.toString;if(pr(Xe)){var $=Xe.call(w);if(!ee($))return $}}throw new TypeError}function Ke(w){return!!w}function Ee(w){return""+w}function Ie(w){var E=Ae(w,3);return be(E)?E:Ee(E)}function rn(w){return Array.isArray?Array.isArray(w):w instanceof Object?w instanceof Array:Object.prototype.toString.call(w)==="[object Array]"}function pr(w){return typeof w=="function"}function jn(w){return typeof w=="function"}function Ju(w){switch(W(w)){case 3:return!0;case 4:return!0;default:return!1}}function Gi(w,E){return w===E||w!==w&&E!==E}function Aa(w,E){var P=w[E];if(P!=null){if(!pr(P))throw new TypeError;return P}}function $g(w){var E=Aa(w,s);if(!pr(E))throw new TypeError;var P=E.call(w);if(!ee(P))throw new TypeError;return P}function Fg(w){return w.value}function Wg(w){var E=w.next();return E.done?!1:E}function qg(w){var E=w.return;E&&E.call(w)}function tp(w){var E=Object.getPrototypeOf(w);if(typeof w!="function"||w===h||E!==h)return E;var P=w.prototype,$=P&&Object.getPrototypeOf(P);if($==null||$===Object.prototype)return E;var se=$.constructor;return typeof se!="function"||se===w?E:se}function XA(){var w;!O(C)&&typeof t.Reflect<"u"&&!(C in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(w=JA(t.Reflect));var E,P,$,se=new g,Xe={registerProvider:tt,getProvider:z,setProvider:te};return Xe;function tt(ne){if(!Object.isExtensible(Xe))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case w===ne:break;case O(E):E=ne;break;case E===ne:break;case O(P):P=ne;break;case P===ne:break;default:$===void 0&&($=new b),$.add(ne);break}}function we(ne,ve){if(!O(E)){if(E.isProviderFor(ne,ve))return E;if(!O(P)){if(P.isProviderFor(ne,ve))return E;if(!O($))for(var Re=$g($);;){var Ze=Wg(Re);if(!Ze)return;var dr=Fg(Ze);if(dr.isProviderFor(ne,ve))return qg(Re),dr}}}if(!O(w)&&w.isProviderFor(ne,ve))return w}function z(ne,ve){var Re=se.get(ne),Ze;return O(Re)||(Ze=Re.get(ve)),O(Ze)&&(Ze=we(ne,ve),O(Ze)||(O(Re)&&(Re=new y,se.set(ne,Re)),Re.set(ve,Ze))),Ze}function J(ne){if(O(ne))throw new TypeError;return E===ne||P===ne||!O($)&&$.has(ne)}function te(ne,ve,Re){if(!J(Re))throw new Error("Metadata provider not registered.");var Ze=z(ne,ve);if(Ze!==Re){if(!O(Ze))return!1;var dr=se.get(ne);O(dr)&&(dr=new y,se.set(ne,dr)),dr.set(ve,Re)}return!0}}function ZA(){var w;return!O(C)&&ee(t.Reflect)&&Object.isExtensible(t.Reflect)&&(w=t.Reflect[C]),O(w)&&(w=XA()),!O(C)&&ee(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,C,{enumerable:!1,configurable:!1,writable:!1,value:w}),w}function YA(w){var E=new g,P={isProviderFor:function(J,te){var ne=E.get(J);return O(ne)?!1:ne.has(te)},OrdinaryDefineOwnMetadata:tt,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Xe,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:z};return m.registerProvider(P),P;function $(J,te,ne){var ve=E.get(J),Re=!1;if(O(ve)){if(!ne)return;ve=new y,E.set(J,ve),Re=!0}var Ze=ve.get(te);if(O(Ze)){if(!ne)return;if(Ze=new y,ve.set(te,Ze),!w.setProvider(J,te,P))throw ve.delete(te),Re&&E.delete(J),new Error("Wrong provider for target.")}return Ze}function se(J,te,ne){var ve=$(te,ne,!1);return O(ve)?!1:Ke(ve.has(J))}function Xe(J,te,ne){var ve=$(te,ne,!1);if(!O(ve))return ve.get(J)}function tt(J,te,ne,ve){var Re=$(ne,ve,!0);Re.set(J,te)}function we(J,te){var ne=[],ve=$(J,te,!1);if(O(ve))return ne;for(var Re=ve.keys(),Ze=$g(Re),dr=0;;){var Gg=Wg(Ze);if(!Gg)return ne.length=dr,ne;var rS=Fg(Gg);try{ne[dr]=rS}catch(nS){try{qg(Ze)}finally{throw nS}}dr++}}function z(J,te,ne){var ve=$(te,ne,!1);if(O(ve)||!ve.delete(J))return!1;if(ve.size===0){var Re=E.get(te);O(Re)||(Re.delete(ne),Re.size===0&&E.delete(Re))}return!0}}function JA(w){var E=w.defineMetadata,P=w.hasOwnMetadata,$=w.getOwnMetadata,se=w.getOwnMetadataKeys,Xe=w.deleteMetadata,tt=new g,we={isProviderFor:function(z,J){var te=tt.get(z);return!O(te)&&te.has(J)?!0:se(z,J).length?(O(te)&&(te=new b,tt.set(z,te)),te.add(J),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:P,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Xe};return we}function Sa(w,E,P){var $=m.getProvider(w,E);if(!O($))return $;if(P){if(m.setProvider(w,E,S))return S;throw new Error("Illegal state.")}}function QA(){var w={},E=[],P=(function(){function we(z,J,te){this._index=0,this._keys=z,this._values=J,this._selector=te}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var z=this._index;if(z>=0&&z<this._keys.length){var J=this._selector(this._keys[z],this._values[z]);return z+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(z){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),z},we.prototype.return=function(z){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:z,done:!0}},we})(),$=(function(){function we(){this._keys=[],this._values=[],this._cacheKey=w,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(z){return this._find(z,!1)>=0},we.prototype.get=function(z){var J=this._find(z,!1);return J>=0?this._values[J]:void 0},we.prototype.set=function(z,J){var te=this._find(z,!0);return this._values[te]=J,this},we.prototype.delete=function(z){var J=this._find(z,!1);if(J>=0){for(var te=this._keys.length,ne=J+1;ne<te;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Gi(z,this._cacheKey)&&(this._cacheKey=w,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=w,this._cacheIndex=-2},we.prototype.keys=function(){return new P(this._keys,this._values,se)},we.prototype.values=function(){return new P(this._keys,this._values,Xe)},we.prototype.entries=function(){return new P(this._keys,this._values,tt)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(z,J){if(!Gi(this._cacheKey,z)){this._cacheIndex=-1;for(var te=0;te<this._keys.length;te++)if(Gi(this._keys[te],z)){this._cacheIndex=te;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(z),this._values.push(void 0)),this._cacheIndex},we})();return $;function se(we,z){return we}function Xe(we,z){return z}function tt(we,z){return[we,z]}}function eS(){var w=(function(){function E(){this._map=new y}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(P){return this._map.has(P)},E.prototype.add=function(P){return this._map.set(P,P),this},E.prototype.delete=function(P){return this._map.delete(P)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E})();return w}function tS(){var w=16,E=p.create(),P=$();return(function(){function z(){this._key=$()}return z.prototype.has=function(J){var te=se(J,!1);return te!==void 0?p.has(te,this._key):!1},z.prototype.get=function(J){var te=se(J,!1);return te!==void 0?p.get(te,this._key):void 0},z.prototype.set=function(J,te){var ne=se(J,!0);return ne[this._key]=te,this},z.prototype.delete=function(J){var te=se(J,!1);return te!==void 0?delete te[this._key]:!1},z.prototype.clear=function(){this._key=$()},z})();function $(){var z;do z="@@WeakMap@@"+we();while(p.has(E,z));return E[z]=!0,z}function se(z,J){if(!n.call(z,P)){if(!J)return;Object.defineProperty(z,P,{value:p.create()})}return z[P]}function Xe(z,J){for(var te=0;te<J;++te)z[te]=Math.random()*255|0;return z}function tt(z){if(typeof Uint8Array=="function"){var J=new Uint8Array(z);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Xe(J,z),J}return Xe(new Array(z),z)}function we(){var z=tt(w);z[6]=z[6]&79|64,z[8]=z[8]&191|128;for(var J="",te=0;te<w;++te){var ne=z[te];(te===4||te===6||te===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function rp(w){return w.__=void 0,delete w.__,w}})})(ex||(ex={}))});var gn=np(Is=>{"use strict";var Y2="[object ArrayBuffer]",yn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Y2}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}},_m="string",J2=/^[0-9a-f\s]+$/i,Q2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,eC=/^[a-zA-Z0-9-_]+$/,Sf=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=yn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},or=class{static toString(e,t=!1){let n=yn.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}},Ef=class r{static isHex(e){return typeof e===_m&&J2.test(e)}static isBase64(e){return typeof e===_m&&Q2.test(e)}static isBase64Url(e){return typeof e===_m&&eC.test(e)}static ToString(e,t="utf8"){let n=yn.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 or.toString(n,!0);case"utf16":case"utf16be":return or.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 or.fromString(e,!0);case"utf16":case"utf16be":return or.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=yn.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 Sf.fromString(e);case"utf16":case"utf16be":return or.fromString(e);case"utf16le":case"usc2":return or.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 Sf.toString(e);case"utf16":case"utf16be":return or.toString(e);case"utf16le":case"usc2":return or.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=yn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=yn.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 or.toString(e,t)}static FromUtf16String(e,t=!1){return or.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,"")||""}};Ef.DEFAULT_UTF8_ENCODING="utf8";function tC(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 rC(...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 nC(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}Is.BufferSourceConverter=yn;Is.Convert=Ef;Is.assign=tC;Is.combine=rC;Is.isEqual=nC});var Xv=np((N7,bh)=>{var Tv,kv,Ov,Pv,Nv,Dv,Rv,Lv,Uv,gh,Ny,Mv,jv,na,Kv,Hv,Vv,$v,Fv,Wv,qv,Gv,zv;(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 bh=="object"&&typeof bh.exports=="object"?r(t(e,t(bh.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])};Tv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},kv=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},Ov=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},Pv=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 f=t.length-1;f>=0;f--)(c=t[f])&&(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},Nv=function(t,n){return function(o,i){n(o,i,t)}},Dv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Rv=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 f(y){try{h(i.next(y))}catch(b){c(b)}}function p(y){try{h(i.throw(y))}catch(b){c(b)}}function h(y){y.done?a(y.value):s(y.value).then(f,p)}h((i=i.apply(t,n||[])).next())})},Lv=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:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function f(h){return function(y){return p([h,y])}}function p(h){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=h[0]&2?s.return:h[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,h[1])).done)return a;switch(s=0,a&&(h=[h[0]&2,a.value]),h[0]){case 0:case 1:a=h;break;case 4:return o.label++,{value:h[1],done:!1};case 5:o.label++,s=h[1],h=[0];continue;case 7:h=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(h[0]===6||h[0]===2)){o=0;continue}if(h[0]===3&&(!a||h[1]>a[0]&&h[1]<a[3])){o.label=h[1];break}if(h[0]===6&&o.label<a[1]){o.label=a[1],a=h;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(h);break}a[2]&&o.ops.pop(),o.trys.pop();continue}h=n.call(t,o)}catch(y){h=[6,y],s=0}finally{i=a=0}if(h[0]&5)throw h[1];return{value:h[0]?h[1]:void 0,done:!0}}},zv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Uv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},gh=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.")},Ny=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(f){c={error:f}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mv=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Ny(arguments[n]));return t},jv=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,f=a.length;c<f;c++,s++)i[s]=a[c];return i},na=function(t){return this instanceof na?(this.v=t,this):new na(t)},Kv=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(C){return new Promise(function(m,S){a.push([g,C,m,S])>1||f(g,C)})})}function f(g,C){try{p(i[g](C))}catch(m){b(a[0][3],m)}}function p(g){g.value instanceof na?Promise.resolve(g.value.v).then(h,y):b(a[0][2],g)}function h(g){f("next",g)}function y(g){f("throw",g)}function b(g,C){g(C),a.shift(),a.length&&f(a[0][0],a[0][1])}},Hv=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:na(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Vv=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 gh=="function"?gh(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(f,p){c=t[a](c),s(f,p,c.done,c.value)})}}function s(a,c,f,p){Promise.resolve(p).then(function(h){a({value:h,done:f})},c)}},$v=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Fv=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},Wv=function(t){return t&&t.__esModule?t:{default:t}},qv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Gv=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",Tv),r("__assign",kv),r("__rest",Ov),r("__decorate",Pv),r("__param",Nv),r("__metadata",Dv),r("__awaiter",Rv),r("__generator",Lv),r("__exportStar",Uv),r("__createBinding",zv),r("__values",gh),r("__read",Ny),r("__spread",Mv),r("__spreadArrays",jv),r("__await",na),r("__asyncGenerator",Kv),r("__asyncDelegator",Hv),r("__asyncValues",Vv),r("__makeTemplateObject",$v),r("__importStar",Fv),r("__importDefault",Wv),r("__classPrivateFieldGet",qv),r("__classPrivateFieldSet",Gv)})});var hI={};vt(hI,{webRTC:()=>fI,webRTCDirect:()=>lI});var el=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},tl=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},xe=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ea=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var rl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},nl=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Xi=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var nn=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},_a=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},To=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var ol=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},il=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},sl=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var al=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var cl=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Kn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var ul=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},Zi=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},ll=class extends Zi{constructor(e,t){super(!0,e,t)}},fl=class extends Zi{constructor(e,t){super(!1,e,t)}};var op=Symbol.for("@libp2p/peer-id");var hl=Symbol.for("@libp2p/transport");var Xg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Xg||(Xg={}));var er=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 Yi=Symbol.for("@libp2p/service-capabilities"),Zg=Symbol.for("@libp2p/service-dependencies");var up={};vt(up,{base58btc:()=>Fe,base58flickr:()=>yS});var FI=new Uint8Array(0);function Yg(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function on(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Jg(r){return new TextEncoder().encode(r)}function Qg(r){return new TextDecoder().decode(r)}function lS(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),f=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var C=0,m=0,S=0,N=g.length;S!==N&&g[S]===0;)S++,C++;for(var I=(N-S)*p+1>>>0,K=new Uint8Array(I);S!==N;){for(var Z=g[S],q=0,re=I-1;(Z!==0||q<m)&&re!==-1;re--,q++)Z+=256*K[re]>>>0,K[re]=Z%a>>>0,Z=Z/a>>>0;if(Z!==0)throw new Error("Non-zero carry");m=q,S++}for(var R=I-m;R!==I&&K[R]===0;)R++;for(var k=c.repeat(C);R<I;++R)k+=r.charAt(K[R]);return k}function y(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var C=0;if(g[C]!==" "){for(var m=0,S=0;g[C]===c;)m++,C++;for(var N=(g.length-C)*f+1>>>0,I=new Uint8Array(N);g[C];){var K=t[g.charCodeAt(C)];if(K===255)return;for(var Z=0,q=N-1;(K!==0||Z<S)&&q!==-1;q--,Z++)K+=a*I[q]>>>0,I[q]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");S=Z,C++}if(g[C]!==" "){for(var re=N-S;re!==N&&I[re]===0;)re++;for(var R=new Uint8Array(m+(N-re)),k=m;re!==N;)R[k++]=I[re++];return R}}}function b(g){var C=y(g);if(C)return C;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:y,decode:b}}var fS=lS,hS=fS,t0=hS;var ip=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")}},sp=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 r0(this,e)}},ap=class{decoders;constructor(e){this.decoders=e}or(e){return r0(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 r0(r,e){return new ap({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var cp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ip(e,t,n),this.decoder=new sp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ji({name:r,prefix:e,encode:t,decode:n}){return new cp(r,e,t,n)}function Hn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=t0(t,r);return Ji({prefix:e,name:r,encode:n,decode:i=>on(o(i))})}function pS(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 f=0;f<o;++f){let p=e[r[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|p,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function dS(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 mS(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=mS(n);return Ji({prefix:e,name:r,encode(i){return dS(i,n,t)},decode(i){return pS(i,o,t,r)}})}var Fe=Hn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yS=Hn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lp={};vt(lp,{base32:()=>Vn,base32hex:()=>xS,base32hexpad:()=>AS,base32hexpadupper:()=>SS,base32hexupper:()=>vS,base32pad:()=>bS,base32padupper:()=>wS,base32upper:()=>gS,base32z:()=>ES});var Vn=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),gS=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),bS=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wS=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xS=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vS=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),AS=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),SS=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ES=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fp={};vt(fp,{base36:()=>Ca,base36upper:()=>_S});var Ca=Hn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_S=Hn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mr={};vt(mr,{Digest:()=>ko,create:()=>Bt,decode:()=>ts,equals:()=>pp,hasCode:()=>FS});var CS=i0,n0=128,BS=127,IS=~BS,TS=Math.pow(2,31);function i0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=TS;)e[t++]=r&255|n0,r/=128;for(;r&IS;)e[t++]=r&255|n0,r>>>=7;return e[t]=r|0,i0.bytes=t-n+1,e}var kS=hp,OS=128,o0=127;function hp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw hp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&o0)<<o:(s&o0)*Math.pow(2,o),o+=7}while(s>=OS);return hp.bytes=i-n,t}var PS=Math.pow(2,7),NS=Math.pow(2,14),DS=Math.pow(2,21),RS=Math.pow(2,28),LS=Math.pow(2,35),US=Math.pow(2,42),MS=Math.pow(2,49),jS=Math.pow(2,56),KS=Math.pow(2,63),HS=function(r){return r<PS?1:r<NS?2:r<DS?3:r<RS?4:r<LS?5:r<US?6:r<MS?7:r<jS?8:r<KS?9:10},VS={encode:CS,decode:kS,encodingLength:HS},$S=VS,Ba=$S;function Ia(r,e=0){return[Ba.decode(r,e),Ba.decode.bytes]}function Qi(r,e,t=0){return Ba.encode(r,e,t),e}function es(r){return Ba.encodingLength(r)}function Bt(r,e){let t=e.byteLength,n=es(r),o=n+es(t),i=new Uint8Array(o+t);return Qi(r,i,0),Qi(t,i,n),i.set(e,o),new ko(r,t,e,i)}function ts(r){let e=on(r),[t,n]=Ia(e),[o,i]=Ia(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ko(t,o,s,e)}function pp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Yg(r.bytes,t.bytes)}}var ko=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function FS(r,e){return r.code===e}function s0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return qS(t,dp(r),e??Fe.encoder);default:return GS(t,dp(r),e??Vn.encoder)}}var a0=new WeakMap;function dp(r){let e=a0.get(r);if(e==null){let t=new Map;return a0.set(r,t),t}return e}var rt=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!==Ta)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zS)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=Bt(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&pp(e.multihash,n.multihash)}toString(e){return s0(this,e)}toJSON(){return{"/":s0(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??c0(n,o,i.bytes))}else if(t[XS]===!0){let{version:n,multihash:o,code:i}=t,s=ts(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!==Ta)throw new Error(`Version 0 CID must use dag-pb (code: ${Ta}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=c0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ta,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=on(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new ko(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,y]=Ia(e.subarray(t));return t+=y,h},o=n(),i=Ta;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(),f=t+c,p=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:f}}static parse(e,t){let[n,o]=WS(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 dp(i).set(n,e),i}};function WS(r,e){switch(r[0]){case"Q":{let t=e??Fe;return[Fe.prefix,t.decode(`${Fe.prefix}${r}`)]}case Fe.prefix:{let t=e??Fe;return[Fe.prefix,t.decode(r)]}case Vn.prefix:{let t=e??Vn;return[Vn.prefix,t.decode(r)]}case Ca.prefix:{let t=e??Ca;return[Ca.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 qS(r,e,t){let{prefix:n}=t;if(n!==Fe.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 GS(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 Ta=112,zS=18;function c0(r,e,t){let n=es(r),o=n+es(e),i=new Uint8Array(o+t.byteLength);return Qi(r,i,0),Qi(e,i,n),i.set(t,o),i}var XS=Symbol.for("@ipld/js-cid/CID");var mp={};vt(mp,{identity:()=>yr});var u0=0,ZS="identity",l0=on;function YS(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Bt(u0,l0(r))}var yr={code:u0,name:ZS,encode:l0,digest:YS};function We(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function nt(r=0){return new Uint8Array(r)}function ot(r=0){return new Uint8Array(r)}function It(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 h0=Symbol.for("@achingbrain/uint8arraylist");function f0(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 dl(r){return!!r?.[h0]}var me=class r{bufs;length;[h0]=!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(dl(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(dl(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=f0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=f0(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(dl(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 It(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:It(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 f=e>=a&&e<c,p=t>a&&t<=c;if(f&&p){if(e===a&&t===c){n.push(s);break}let h=e-a;n.push(s.subarray(h,h+(t-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(p){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!dl(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 h=0;h<i;h++)s[h]=-1;for(let h=0;h<o;h++)s[n[h]]=h;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let h=t;h<=c;h+=p){p=0;for(let y=f;y>=0;y--){let b=this.get(h+y);if(n[y]!==b){p=Math.max(1,y-a[b]);break}}if(p===0)return h}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(!We(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var yp={};vt(yp,{base10:()=>QS});var QS=Hn({prefix:"9",name:"base10",alphabet:"0123456789"});var gp={};vt(gp,{base16:()=>eE,base16upper:()=>tE});var eE=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tE=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bp={};vt(bp,{base2:()=>rE});var rE=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wp={};vt(wp,{base256emoji:()=>aE});var p0=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}"),nE=p0.reduce((r,e,t)=>(r[t]=e,r),[]),oE=p0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function iE(r){return r.reduce((e,t)=>(e+=nE[t],e),"")}function sE(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=oE[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var aE=Ji({prefix:"\u{1F680}",name:"base256emoji",encode:iE,decode:sE});var xp={};vt(xp,{base64:()=>cE,base64pad:()=>uE,base64url:()=>Oo,base64urlpad:()=>lE});var cE=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uE=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Oo=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lE=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vp={};vt(vp,{base8:()=>fE});var fE=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ap={};vt(Ap,{identity:()=>hE});var hE=Ji({prefix:"\0",name:"identity",encode:r=>Qg(r),decode:r=>Jg(r)});var CT=new TextEncoder,BT=new TextDecoder;var _p={};vt(_p,{sha256:()=>tr,sha512:()=>yE});var mE=20;function Ep({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Sp(r,e,t,n,o)}var Sp=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??mE,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?d0(n,this.code,t?.truncate):n.then(o=>d0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function d0(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Bt(e,r)}function y0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Ep({name:"sha2-256",code:18,encode:y0("SHA-256")}),yE=Ep({name:"sha2-512",code:19,encode:y0("SHA-512")});var Po={...Ap,...bp,...vp,...yp,...gp,...lp,...fp,...up,...xp,...wp},jT={..._p,...mp};function b0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var g0=b0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Cp=b0("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}),gE={utf8:g0,"utf-8":g0,hex:Po.base16,latin1:Cp,ascii:Cp,binary:Cp,...Po},ml=gE;function de(r,e="utf8"){let t=ml[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=ml[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var bE=parseInt("11111",2),Bp=parseInt("10000000",2),wE=parseInt("01111111",2),w0={0:ka,1:ka,2:xE,3:SE,4:EE,5:AE,6:vE,16:ka,22:ka,48:ka};function sn(r,e={offset:0}){let t=r[e.offset]&bE;if(e.offset++,w0[t]!=null)return w0[t](r,e);throw new Error("No decoder for tag "+t)}function Oa(r,e){let t=0;if((r[e.offset]&Bp)===Bp){let n=r[e.offset]&wE,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 ka(r,e){Oa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=sn(r,e);if(n===null)break;t.push(n)}return t}function xE(r,e){let t=Oa(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 vE(r,e){let t=Oa(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 f=r[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let p=0;for(let h=0;h<c.length;h++)p+=c[h]<<h*7;a+=`.${p}`,c=[]}}return a}function AE(r,e){return e.offset++,null}function SE(r,e){let t=Oa(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 EE(r,e){let t=Oa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function _E(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new me;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function yl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=_E(r.byteLength);return new me(Uint8Array.from([e.byteLength|Bp]),e)}function Tt(r){let e=new me,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new me(Uint8Array.from([2]),yl(e),e)}function Pa(r){let e=Uint8Array.from([0]),t=new me(e,r);return new me(Uint8Array.from([3]),yl(t),t)}function x0(r){return new me(Uint8Array.from([4]),yl(r),r)}function gr(r,e=48){let t=new me;for(let n of r)t.append(n);return new me(Uint8Array.from([e]),yl(t),t)}async function v0(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 A0(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 S0(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 CE=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),BE=Uint8Array.from([6,5,43,129,4,0,34]),IE=Uint8Array.from([6,5,43,129,4,0,35]),TE={ext:!0,kty:"EC",crv:"P-256"},kE={ext:!0,kty:"EC",crv:"P-384"},OE={ext:!0,kty:"EC",crv:"P-521"},Ip=32,Tp=48,kp=66;function Op(r){let e=sn(r);return E0(e)}function E0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Ip*2+1)return n=ue(e.subarray(t,t+Ip),"base64url"),o=ue(e.subarray(t+Ip),"base64url"),new No({...TE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Tp*2+1)return n=ue(e.subarray(t,t+Tp),"base64url"),o=ue(e.subarray(t+Tp),"base64url"),new No({...kE,key_ops:["verify"],x:n,y:o});if(e.byteLength===kp*2+1)return n=ue(e.subarray(t,t+kp),"base64url"),o=ue(e.subarray(t+kp),"base64url"),new No({...OE,key_ops:["verify"],x:n,y:o});throw new xe(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function _0(r){return gr([Tt(Uint8Array.from([1])),x0(de(r.d??"","base64url")),gr([B0(r.crv)],160),gr([Pa(new me(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function C0(r){return gr([Tt(Uint8Array.from([1])),gr([B0(r.crv)],160),gr([Pa(new me(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function B0(r){if(r==="P-256")return CE;if(r==="P-384")return BE;if(r==="P-521")return IE;throw new xe(`Invalid curve ${r}`)}async function I0(r="P-256"){let e=await v0(r);return new gl(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=C0(this.jwk)),this._raw}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async verify(e,t,n){return S0(this.jwk,t,e,n)}},gl=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=_0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async sign(e,t){return A0(this.jwk,e,t)}};function Do(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function rr(r,e=""){if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new Error(`${t}expected integer >= 0, got ${r}`)}}function fe(r,e,t=""){let n=Do(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function Ro(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");rr(r.outputLen),rr(r.blockLen)}function rs(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 k0(r,e){fe(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new Error('"digestInto() output" expected to be of length >='+t)}function br(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function bl(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function wr(r,e){return r<<32-e|r>>>e}var O0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",PE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function cn(r){if(fe(r),O0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=PE[r[t]];return e}var an={_0:48,_9:57,A:65,F:70,a:97,f:102};function T0(r){if(r>=an._0&&r<=an._9)return r-an._0;if(r>=an.A&&r<=an.F)return r-(an.A-10);if(r>=an.a&&r<=an.f)return r-(an.a-10)}function un(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(O0)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=T0(r.charCodeAt(i)),a=T0(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 Lt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];fe(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}function Pp(r,e={}){let t=(o,i)=>r(i).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function Fn(r=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(r))}var Np=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function P0(r,e,t){return r&e^~r&t}function N0(r,e,t){return r&e^r&t^e&t}var Na=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=bl(this.buffer)}update(e){rs(this),fe(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=bl(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){rs(this),k0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,br(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let h=s;h<o;h++)t[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=bl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,p[h],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(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()}},ln=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var wl=BigInt(4294967295),D0=BigInt(32);function NE(r,e=!1){return e?{h:Number(r&wl),l:Number(r>>D0&wl)}:{h:Number(r>>D0&wl)|0,l:Number(r&wl)|0}}function R0(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}=NE(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Dp=(r,e,t)=>r>>>t,Rp=(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,Da=(r,e,t)=>r<<64-t|e>>>t-32,Ra=(r,e,t)=>r>>>t-32|e<<64-t;function Lr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var L0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),U0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,M0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),j0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,K0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),H0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var RE=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]),Wn=new Uint32Array(64),Lp=class extends Na{constructor(e){super(64,e,8,!1)}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 h=0;h<16;h++,t+=4)Wn[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let y=Wn[h-15],b=Wn[h-2],g=wr(y,7)^wr(y,18)^y>>>3,C=wr(b,17)^wr(b,19)^b>>>10;Wn[h]=C+Wn[h-7]+g+Wn[h-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:p}=this;for(let h=0;h<64;h++){let y=wr(a,6)^wr(a,11)^wr(a,25),b=p+y+P0(a,c,f)+RE[h]+Wn[h]|0,C=(wr(n,2)^wr(n,13)^wr(n,22))+N0(n,o,i)|0;p=f,f=c,c=a,a=s+b|0,s=i,i=o,o=n,n=b+C|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,f=f+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,f,p)}roundClean(){br(Wn)}destroy(){this.set(0,0,0,0,0,0,0,0),br(this.buffer)}},Up=class extends Lp{A=ln[0]|0;B=ln[1]|0;C=ln[2]|0;D=ln[3]|0;E=ln[4]|0;F=ln[5]|0;G=ln[6]|0;H=ln[7]|0;constructor(){super(32)}};var V0=R0(["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))),LE=V0[0],UE=V0[1],qn=new Uint32Array(80),Gn=new Uint32Array(80),Mp=class extends Na{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:p,Fh:h,Fl:y,Gh:b,Gl:g,Hh:C,Hl:m}=this;return[e,t,n,o,i,s,a,c,f,p,h,y,b,g,C,m]}set(e,t,n,o,i,s,a,c,f,p,h,y,b,g,C,m){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=p|0,this.Fh=h|0,this.Fl=y|0,this.Gh=b|0,this.Gl=g|0,this.Hh=C|0,this.Hl=m|0}process(e,t){for(let I=0;I<16;I++,t+=4)qn[I]=e.getUint32(t),Gn[I]=e.getUint32(t+=4);for(let I=16;I<80;I++){let K=qn[I-15]|0,Z=Gn[I-15]|0,q=Lo(K,Z,1)^Lo(K,Z,8)^Dp(K,Z,7),re=Uo(K,Z,1)^Uo(K,Z,8)^Rp(K,Z,7),R=qn[I-2]|0,k=Gn[I-2]|0,G=Lo(R,k,19)^Da(R,k,61)^Dp(R,k,6),Y=Uo(R,k,19)^Ra(R,k,61)^Rp(R,k,6),V=M0(re,Y,Gn[I-7],Gn[I-16]),B=j0(V,q,G,qn[I-7],qn[I-16]);qn[I]=B|0,Gn[I]=V|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:p,Eh:h,El:y,Fh:b,Fl:g,Gh:C,Gl:m,Hh:S,Hl:N}=this;for(let I=0;I<80;I++){let K=Lo(h,y,14)^Lo(h,y,18)^Da(h,y,41),Z=Uo(h,y,14)^Uo(h,y,18)^Ra(h,y,41),q=h&b^~h&C,re=y&g^~y&m,R=K0(N,Z,re,UE[I],Gn[I]),k=H0(R,S,K,q,LE[I],qn[I]),G=R|0,Y=Lo(n,o,28)^Da(n,o,34)^Da(n,o,39),V=Uo(n,o,28)^Ra(n,o,34)^Ra(n,o,39),B=n&i^n&a^i&a,A=o&s^o&c^s&c;S=C|0,N=m|0,C=b|0,m=g|0,b=h|0,g=y|0,{h,l:y}=Lr(f|0,p|0,k|0,G|0),f=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let v=L0(G,V,A);n=U0(v,k,Y,B),o=v|0}({h:n,l:o}=Lr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Lr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Lr(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:p}=Lr(this.Dh|0,this.Dl|0,f|0,p|0),{h,l:y}=Lr(this.Eh|0,this.El|0,h|0,y|0),{h:b,l:g}=Lr(this.Fh|0,this.Fl|0,b|0,g|0),{h:C,l:m}=Lr(this.Gh|0,this.Gl|0,C|0,m|0),{h:S,l:N}=Lr(this.Hh|0,this.Hl|0,S|0,N|0),this.set(n,o,i,s,a,c,f,p,h,y,b,g,C,m,S,N)}roundClean(){br(qn,Gn)}destroy(){br(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jp=class extends Mp{Ah=ft[0]|0;Al=ft[1]|0;Bh=ft[2]|0;Bl=ft[3]|0;Ch=ft[4]|0;Cl=ft[5]|0;Dh=ft[6]|0;Dl=ft[7]|0;Eh=ft[8]|0;El=ft[9]|0;Fh=ft[10]|0;Fl=ft[11]|0;Gh=ft[12]|0;Gl=ft[13]|0;Hh=ft[14]|0;Hl=ft[15]|0;constructor(){super(64)}};var Ur=Pp(()=>new Up,Np(1));var $0=Pp(()=>new jp,Np(3));var Hp=BigInt(0),Kp=BigInt(1);function fn(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}" `;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function F0(r){if(typeof r=="bigint"){if(!xl(r))throw new Error("positive bigint expected, got "+r)}else rr(r);return r}function La(r){let e=F0(r).toString(16);return e.length&1?"0"+e:e}function W0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Hp:BigInt("0x"+r)}function ns(r){return W0(cn(r))}function Mr(r){return W0(cn(Mo(fe(r)).reverse()))}function vl(r,e){rr(e),r=F0(r);let t=un(r.toString(16).padStart(e*2,"0"));if(t.length!==e)throw new Error("number too large");return t}function Ua(r,e){return vl(r,e).reverse()}function Mo(r){return Uint8Array.from(r)}var xl=r=>typeof r=="bigint"&&Hp<=r;function ME(r,e,t){return xl(r)&&xl(e)&&xl(t)&&e<=r&&r<t}function zn(r,e,t,n){if(!ME(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Vp(r){let e;for(e=0;r>Hp;r>>=Kp,e+=1);return e}var Ma=r=>(Kp<<BigInt(r))-Kp;function q0(r,e,t){if(rr(r,"hashLen"),rr(e,"qByteLen"),typeof t!="function")throw new Error("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),p=0,h=()=>{c.fill(1),f.fill(0),p=0},y=(...m)=>t(f,Lt(c,...m)),b=(m=o)=>{f=y(i,m),c=y(),m.length!==0&&(f=y(s,m),c=y())},g=()=>{if(p++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,S=[];for(;m<e;){c=y();let N=c.slice();S.push(N),m+=c.length}return Lt(...S)};return(m,S)=>{h(),b(m);let N;for(;!(N=S(g()));)b();return h(),N}}function jr(r,e={},t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,s,a){let c=r[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(t,!0)}function os(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),st=BigInt(1),jo=BigInt(2),X0=BigInt(3),Z0=BigInt(4),Y0=BigInt(5),jE=BigInt(7),J0=BigInt(8),KE=BigInt(9),Q0=BigInt(16);function He(r,e){let t=r%e;return t>=kt?t:e+t}function Le(r,e,t){let n=r;for(;e-- >kt;)n*=n,n%=t;return n}function G0(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=He(r,e),n=e,o=kt,i=st,s=st,a=kt;for(;t!==kt;){let f=n/t,p=n%t,h=o-s*f,y=i-a*f;n=t,t=p,o=s,i=a,s=h,a=y}if(n!==st)throw new Error("invert: does not exist");return He(o,e)}function Fp(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function eb(r,e){let t=(r.ORDER+st)/Z0,n=r.pow(e,t);return Fp(r,n,e),n}function HE(r,e){let t=(r.ORDER-Y0)/J0,n=r.mul(e,jo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,jo),o),a=r.mul(i,r.sub(s,r.ONE));return Fp(r,a,e),a}function VE(r){let e=is(r),t=tb(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+jE)/Q0;return(a,c)=>{let f=a.pow(c,s),p=a.mul(f,n),h=a.mul(f,o),y=a.mul(f,i),b=a.eql(a.sqr(p),c),g=a.eql(a.sqr(h),c);f=a.cmov(f,p,b),p=a.cmov(y,h,g);let C=a.eql(a.sqr(p),c),m=a.cmov(f,p,C);return Fp(a,m,c),m}}function tb(r){if(r<X0)throw new Error("sqrt is not defined for small field");let e=r-st,t=0;for(;e%jo===kt;)e/=jo,t++;let n=jo,o=is(r);for(;z0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return eb;let i=o.pow(n,e),s=(e+st)/jo;return function(c,f){if(c.is0(f))return f;if(z0(c,f)!==1)throw new Error("Cannot find square root");let p=t,h=c.mul(c.ONE,i),y=c.pow(f,e),b=c.pow(f,s);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let g=1,C=c.sqr(y);for(;!c.eql(C,c.ONE);)if(g++,C=c.sqr(C),g===p)throw new Error("Cannot find square root");let m=st<<BigInt(p-g-1),S=c.pow(h,m);p=g,h=c.sqr(S),y=c.mul(y,h),b=c.mul(b,S)}return b}}function $E(r){return r%Z0===X0?eb:r%J0===Y0?HE:r%Q0===KE?VE(r):tb(r)}var rb=(r,e)=>(He(r,e)&st)===st,FE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wp(r){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},t=FE.reduce((n,o)=>(n[o]="function",n),e);return jr(r,t),r}function WE(r,e,t){if(t<kt)throw new Error("invalid exponent, negatives unsupported");if(t===kt)return r.ONE;if(t===st)return e;let n=r.ONE,o=e;for(;t>kt;)t&st&&(n=r.mul(n,o)),o=r.sqr(o),t>>=st;return n}function ja(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function z0(r,e){let t=(r.ORDER-st)/jo,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 qE(r,e){e!==void 0&&rr(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}var $p=class{ORDER;BITS;BYTES;isLE;ZERO=kt;ONE=st;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=kt)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&(this.sqrt=t.sqrt),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:i}=qE(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return He(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return kt<=e&&e<this.ORDER}is0(e){return e===kt}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&st)===st}neg(e){return He(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return He(e*e,this.ORDER)}add(e,t){return He(e+t,this.ORDER)}sub(e,t){return He(e-t,this.ORDER)}mul(e,t){return He(e*t,this.ORDER)}pow(e,t){return WE(this,e,t)}div(e,t){return He(e*G0(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return G0(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=$E(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Ua(e,this.BYTES):vl(e,this.BYTES)}fromBytes(e,t=!1){fe(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Mr(e):ns(e);if(a&&(c=He(c,s)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return ja(this,e)}cmov(e,t,n){return n?t:e}};function is(r,e={}){return new $p(r,e)}function nb(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 qp(r){let e=nb(r);return e+Math.ceil(e/2)}function Gp(r,e,t=!1){fe(r);let n=r.length,o=nb(e),i=qp(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Mr(r):ns(r),a=He(s,e-st)+st;return t?Ua(a,o):vl(a,o)}var ss=BigInt(0),Ko=BigInt(1);function Ka(r,e){let t=e.negate();return r?t:e}function Ho(r,e){let t=ja(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function ab(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function zp(r,e){ab(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Ma(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function ob(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+=Ko);let f=e*n,p=f+Math.abs(a)-1,h=a===0,y=a<0,b=e%2!==0;return{nextN:c,offset:p,isZero:h,isNeg:y,isNegF:b,offsetF:f}}var Xp=new WeakMap,cb=new WeakMap;function Zp(r){return cb.get(r)||1}function ib(r){if(r!==ss)throw new Error("invalid wNAF")}var as=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>ss;)t&Ko&&(n=n.add(o)),o=o.double(),t>>=Ko;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=zp(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=zp(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:p,isNeg:h,isNegF:y,offsetF:b}=ob(n,a,s);n=c,p?i=i.add(Ka(y,t[b])):o=o.add(Ka(h,t[f]))}return ib(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=zp(e,this.bits);for(let s=0;s<i.windows&&n!==ss;s++){let{nextN:a,offset:c,isZero:f,isNeg:p}=ob(n,s,i);if(n=a,!f){let h=t[c];o=o.add(p?h.negate():h)}}return ib(n),o}getPrecomputes(e,t,n){let o=Xp.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),Xp.set(t,o))),o}cached(e,t,n){let o=Zp(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=Zp(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){ab(t,this.bits),cb.set(e,t),Xp.delete(e)}hasCache(e){return Zp(e)!==1}};function ub(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>ss||n>ss;)t&Ko&&(i=i.add(o)),n&Ko&&(s=s.add(o)),o=o.double(),t>>=Ko,n>>=Ko;return{p1:i,p2:s}}function sb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wp(e),e}else return is(r,{isLE:t})}function Al(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=e[c];if(!(typeof f=="bigint"&&f>ss))throw new Error(`CURVE.${c} must be positive bigint`)}let o=sb(e.p,t.Fp,n),i=sb(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function cs(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var Xn=BigInt(0),at=BigInt(1),Yp=BigInt(2),GE=BigInt(8);function zE(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 lb(r,e={}){let t=Al("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;jr(e,{},{uvRatio:"function"});let a=Yp<<BigInt(o.BYTES*8)-at,c=m=>n.create(m),f=e.uvRatio||((m,S)=>{try{return{isValid:!0,value:n.sqrt(n.div(m,S))}}catch{return{isValid:!1,value:Xn}}});if(!zE(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(m,S,N=!1){let I=N?at:Xn;return zn("coordinate "+m,S,I,a),S}function h(m){if(!(m instanceof g))throw new Error("EdwardsPoint expected")}let y=os((m,S)=>{let{X:N,Y:I,Z:K}=m,Z=m.is0();S==null&&(S=Z?GE:n.inv(K));let q=c(N*S),re=c(I*S),R=n.mul(K,S);if(Z)return{x:Xn,y:at};if(R!==at)throw new Error("invZ was invalid");return{x:q,y:re}}),b=os(m=>{let{a:S,d:N}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:I,Y:K,Z,T:q}=m,re=c(I*I),R=c(K*K),k=c(Z*Z),G=c(k*k),Y=c(re*S),V=c(k*c(Y+R)),B=c(G+c(N*c(re*R)));if(V!==B)throw new Error("bad point: equation left != right (1)");let A=c(I*K),v=c(Z*q);if(A!==v)throw new Error("bad point: equation left != right (2)");return!0});class g{static BASE=new g(i.Gx,i.Gy,at,c(i.Gx*i.Gy));static ZERO=new g(Xn,at,at,Xn);static Fp=n;static Fn=o;X;Y;Z;T;constructor(S,N,I,K){this.X=p("x",S),this.Y=p("y",N),this.Z=p("z",I,!0),this.T=p("t",K),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){if(S instanceof g)throw new Error("extended point not allowed");let{x:N,y:I}=S||{};return p("x",N),p("y",I),new g(N,I,at,c(N*I))}static fromBytes(S,N=!1){let I=n.BYTES,{a:K,d:Z}=i;S=Mo(fe(S,I,"point")),fn(N,"zip215");let q=Mo(S),re=S[I-1];q[I-1]=re&-129;let R=Mr(q),k=N?a:n.ORDER;zn("point.y",R,Xn,k);let G=c(R*R),Y=c(G-at),V=c(Z*G-K),{isValid:B,value:A}=f(Y,V);if(!B)throw new Error("bad point: invalid y coordinate");let v=(A&at)===at,D=(re&128)!==0;if(!N&&A===Xn&&D)throw new Error("bad point: x=0 and x_0=1");return D!==v&&(A=c(-A)),g.fromAffine({x:A,y:R})}static fromHex(S,N=!1){return g.fromBytes(un(S),N)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,N=!0){return C.createCache(this,S),N||this.multiply(Yp),this}assertValidity(){b(this)}equals(S){h(S);let{X:N,Y:I,Z:K}=this,{X:Z,Y:q,Z:re}=S,R=c(N*re),k=c(Z*K),G=c(I*re),Y=c(q*K);return R===k&&G===Y}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:S}=i,{X:N,Y:I,Z:K}=this,Z=c(N*N),q=c(I*I),re=c(Yp*c(K*K)),R=c(S*Z),k=N+I,G=c(c(k*k)-Z-q),Y=R+q,V=Y-re,B=R-q,A=c(G*V),v=c(Y*B),D=c(G*B),U=c(V*Y);return new g(A,v,U,D)}add(S){h(S);let{a:N,d:I}=i,{X:K,Y:Z,Z:q,T:re}=this,{X:R,Y:k,Z:G,T:Y}=S,V=c(K*R),B=c(Z*k),A=c(re*I*Y),v=c(q*G),D=c((K+Z)*(R+k)-V-B),U=v-A,L=v+A,T=c(B-N*V),M=c(D*U),W=c(L*T),O=c(D*T),pe=c(U*L);return new g(M,W,pe,O)}subtract(S){return this.add(S.negate())}multiply(S){if(!o.isValidNot0(S))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:N,f:I}=C.cached(this,S,K=>Ho(g,K));return Ho(g,[N,I])[0]}multiplyUnsafe(S,N=g.ZERO){if(!o.isValid(S))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return S===Xn?g.ZERO:this.is0()||S===at?this:C.unsafe(this,S,I=>Ho(g,I),N)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return C.unsafe(this,i.n).is0()}toAffine(S){return y(this,S)}clearCofactor(){return s===at?this:this.multiplyUnsafe(s)}toBytes(){let{x:S,y:N}=this.toAffine(),I=n.toBytes(N);return I[I.length-1]|=S&at?128:0,I}toHex(){return cn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=new as(g,o.BITS);return g.BASE.precompute(8),g}function fb(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');jr(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||Fn,c=t.adjustScalarBytes||(R=>R),f=t.domain||((R,k,G)=>{if(fn(G,"phflag"),k.length||G)throw new Error("Contexts/pre-hash are not supported");return R});function p(R){return s.create(Mr(R))}function h(R){let k=I.secretKey;fe(R,I.secretKey,"secretKey");let G=fe(e(R),2*k,"hashedSecretKey"),Y=c(G.slice(0,k)),V=G.slice(k,2*k),B=p(Y);return{head:Y,prefix:V,scalar:B}}function y(R){let{head:k,prefix:G,scalar:Y}=h(R),V=o.multiply(Y),B=V.toBytes();return{head:k,prefix:G,scalar:Y,point:V,pointBytes:B}}function b(R){return y(R).pointBytes}function g(R=Uint8Array.of(),...k){let G=Lt(...k);return p(e(f(G,fe(R,void 0,"context"),!!n)))}function C(R,k,G={}){R=fe(R,void 0,"message"),n&&(R=n(R));let{prefix:Y,scalar:V,pointBytes:B}=y(k),A=g(G.context,Y,R),v=o.multiply(A).toBytes(),D=g(G.context,v,B,R),U=s.create(A+D*V);if(!s.isValid(U))throw new Error("sign failed: invalid s");let L=Lt(v,s.toBytes(U));return fe(L,I.signature,"result")}let m={zip215:!0};function S(R,k,G,Y=m){let{context:V,zip215:B}=Y,A=I.signature;R=fe(R,A,"signature"),k=fe(k,void 0,"message"),G=fe(G,I.publicKey,"publicKey"),B!==void 0&&fn(B,"zip215"),n&&(k=n(k));let v=A/2,D=R.subarray(0,v),U=Mr(R.subarray(v,A)),L,T,M;try{L=r.fromBytes(G,B),T=r.fromBytes(D,B),M=o.multiplyUnsafe(U)}catch{return!1}if(!B&&L.isSmallOrder())return!1;let W=g(V,T.toBytes(),L.toBytes(),k);return T.add(L.multiplyUnsafe(W)).subtract(M).clearCofactor().is0()}let N=i.BYTES,I={secretKey:N,publicKey:N,signature:2*N,seed:N};function K(R=a(I.seed)){return fe(R,I.seed,"seed")}function Z(R){return Do(R)&&R.length===s.BYTES}function q(R,k){try{return!!r.fromBytes(R,k)}catch{return!1}}let re={getExtendedPublicKey:y,randomSecretKey:K,isValidSecretKey:Z,isValidPublicKey:q,toMontgomery(R){let{y:k}=r.fromBytes(R),G=I.publicKey,Y=G===32;if(!Y&&G!==57)throw new Error("only defined for 25519 and 448");let V=Y?i.div(at+k,at-k):i.div(k-at,k+at);return i.toBytes(V)},toMontgomerySecret(R){let k=I.secretKey;fe(R,k);let G=e(R.subarray(0,k));return c(G).subarray(0,k)}};return Object.freeze({keygen:cs(K,b),getPublicKey:b,sign:C,verify:S,utils:re,Point:r,lengths:I})}var Ha=BigInt(0),us=BigInt(1),Sl=BigInt(2);function XE(r){return jr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function hb(r){let e=XE(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||Fn,f=a?255:448,p=a?32:56,h=BigInt(a?9:5),y=BigInt(a?121665:39081),b=a?Sl**BigInt(254):Sl**BigInt(447),g=a?BigInt(8)*Sl**BigInt(251)-us:BigInt(4)*Sl**BigInt(445)-us,C=b+g+us,m=A=>He(A,t),S=N(h);function N(A){return Ua(m(A),p)}function I(A){let v=Mo(fe(A,p,"uCoordinate"));return a&&(v[31]&=127),m(Mr(v))}function K(A){return Mr(o(Mo(fe(A,p,"scalar"))))}function Z(A,v){let D=G(I(v),K(A));if(D===Ha)throw new Error("invalid private or public key received");return N(D)}function q(A){return Z(A,S)}let re=q,R=Z;function k(A,v,D){let U=m(A*(v-D));return v=m(v-U),D=m(D+U),{x_2:v,x_3:D}}function G(A,v){zn("u",A,Ha,t),zn("scalar",v,b,C);let D=v,U=A,L=us,T=Ha,M=A,W=us,O=Ha;for(let be=BigInt(f-1);be>=Ha;be--){let ee=D>>be&us;O^=ee,{x_2:L,x_3:M}=k(O,L,M),{x_2:T,x_3:W}=k(O,T,W),O=ee;let Ae=L+T,Be=m(Ae*Ae),Ke=L-T,Ee=m(Ke*Ke),Ie=Be-Ee,rn=M+W,pr=M-W,jn=m(pr*Ae),Ju=m(rn*Ke),Gi=jn+Ju,Aa=jn-Ju;M=m(Gi*Gi),W=m(U*m(Aa*Aa)),L=m(Be*Ee),T=m(Ie*(Be+m(y*Ie)))}({x_2:L,x_3:M}=k(O,L,M)),{x_2:T,x_3:W}=k(O,T,W);let pe=i(T);return m(L*pe)}let Y={secretKey:p,publicKey:p,seed:p},V=(A=c(p))=>(fe(A,Y.seed,"seed"),A),B={randomSecretKey:V};return Object.freeze({keygen:cs(V,re),getSharedSecret:R,getPublicKey:re,scalarMult:Z,scalarMultBase:q,utils:B,GuBytes:S.slice(),lengths:Y})}var ZE=BigInt(1),pb=BigInt(2),YE=BigInt(3),JE=BigInt(5),QE=BigInt(8),El=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),e_={p:El,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:QE,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function mb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=El,a=r*r%i*r%i,c=Le(a,pb,i)*a%i,f=Le(c,ZE,i)*r%i,p=Le(f,JE,i)*f%i,h=Le(p,e,i)*p%i,y=Le(h,t,i)*h%i,b=Le(y,n,i)*y%i,g=Le(b,o,i)*b%i,C=Le(g,o,i)*b%i,m=Le(C,e,i)*p%i;return{pow_p_5_8:Le(m,pb,i)*r%i,b2:a}}function yb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var db=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function t_(r,e){let t=El,n=He(e*e*e,t),o=He(n*n*e,t),i=mb(r*o).pow_p_5_8,s=He(r*n*i,t),a=He(e*s*s,t),c=s,f=He(s*db,t),p=a===r,h=a===He(-r,t),y=a===He(-r*db,t);return p&&(s=c),(h||y)&&(s=f),rb(s,t)&&(s=He(-s,t)),{isValid:p||h,value:s}}var r_=lb(e_,{uvRatio:t_});function n_(r){return fb(r_,$0,Object.assign({adjustScalarBytes:yb},r))}var Va=n_({});var $a=(()=>{let r=El;return hb({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=mb(e);return He(Le(t,YE,r)*n,r)},adjustScalarBytes:yb})})();var Fa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Wa=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},_l=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var gb={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new _l("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ut=gb;var Cl=32,qa=64,Jp=32;var ls,bb=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function wb(){let r=Va.utils.randomSecretKey(),e=Va.getPublicKey(r);return{privateKey:c_(r,e),publicKey:e}}async function o_(r,e){let t;r.length===qa?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:ue(r.subarray(32),"base64url"),d:ue(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Ut.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ut.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function i_(r,e){let t=r.subarray(0,Jp);return Va.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function xb(r,e){return ls==null&&(ls=await bb),ls?o_(r,e):i_(r,e)}async function s_(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Ut.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ut.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 a_(r,e,t){return Va.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function vb(r,e,t){return ls==null&&(ls=await bb),ls?s_(r,e,t):a_(r,e,t)}function c_(r,e){let t=new Uint8Array(qa);for(let n=0;n<Jp;n++)t[n]=r[n],t[Jp+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 Ga=class{type="Ed25519";raw;constructor(e){this.raw=Il(e,Cl)}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=vb(this.raw,t,e);return fs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},Bl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Il(e,qa),this.publicKey=new Ga(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=xb(this.raw,e);return fs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Qp(r){return r=Il(r,Cl),new Ga(r)}async function Sb(){let{privateKey:r,publicKey:e}=wb();return new Bl(r,e)}function Il(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new xe(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var u_=Math.pow(2,7),l_=Math.pow(2,14),f_=Math.pow(2,21),ed=Math.pow(2,28),td=Math.pow(2,35),rd=Math.pow(2,42),nd=Math.pow(2,49),Te=128,At=127;function Ue(r){if(r<u_)return 1;if(r<l_)return 2;if(r<f_)return 3;if(r<ed)return 4;if(r<td)return 5;if(r<rd)return 6;if(r<nd)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hs(r,e,t=0){switch(Ue(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 h_(r,e,t=0){switch(Ue(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 od(r,e){let t=r[e],n=0;if(n+=t&At,t<Te||(t=r[e+1],n+=(t&At)<<7,t<Te)||(t=r[e+2],n+=(t&At)<<14,t<Te)||(t=r[e+3],n+=(t&At)<<21,t<Te)||(t=r[e+4],n+=(t&At)*ed,t<Te)||(t=r[e+5],n+=(t&At)*td,t<Te)||(t=r[e+6],n+=(t&At)*rd,t<Te)||(t=r[e+7],n+=(t&At)*nd,t<Te))return n;throw new RangeError("Could not decode varint")}function p_(r,e){let t=r.get(e),n=0;if(n+=t&At,t<Te||(t=r.get(e+1),n+=(t&At)<<7,t<Te)||(t=r.get(e+2),n+=(t&At)<<14,t<Te)||(t=r.get(e+3),n+=(t&At)<<21,t<Te)||(t=r.get(e+4),n+=(t&At)*ed,t<Te)||(t=r.get(e+5),n+=(t&At)*td,t<Te)||(t=r.get(e+6),n+=(t&At)*rd,t<Te)||(t=r.get(e+7),n+=(t&At)*nd,t<Te))return n;throw new RangeError("Could not decode varint")}function Tl(r,e,t=0){return e==null&&(e=ot(Ue(r))),e instanceof Uint8Array?hs(r,e,t):h_(r,e,t)}function hn(r,e=0){return r instanceof Uint8Array?od(r,e):p_(r,e)}var id=new Float32Array([-0]),Zn=new Uint8Array(id.buffer);function Eb(r,e,t){id[0]=r,e[t]=Zn[0],e[t+1]=Zn[1],e[t+2]=Zn[2],e[t+3]=Zn[3]}function _b(r,e){return Zn[0]=r[e],Zn[1]=r[e+1],Zn[2]=r[e+2],Zn[3]=r[e+3],id[0]}var sd=new Float64Array([-0]),St=new Uint8Array(sd.buffer);function Cb(r,e,t){sd[0]=r,e[t]=St[0],e[t+1]=St[1],e[t+2]=St[2],e[t+3]=St[3],e[t+4]=St[4],e[t+5]=St[5],e[t+6]=St[6],e[t+7]=St[7]}function Bb(r,e){return St[0]=r[e],St[1]=r[e+1],St[2]=r[e+2],St[3]=r[e+3],St[4]=r[e+4],St[5]=r[e+5],St[6]=r[e+6],St[7]=r[e+7],sd[0]}var d_=BigInt(Number.MAX_SAFE_INTEGER),m_=BigInt(Number.MIN_SAFE_INTEGER),zt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Vo;if(e<d_&&e>m_)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>Ib&&(o=0n,++n>Ib&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Vo;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):Vo}},Vo=new zt(0,0);Vo.toBigInt=function(){return 0n};Vo.zzEncode=Vo.zzDecode=function(){return this};Vo.length=function(){return 1};var Ib=4294967296n;function Tb(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 kb(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 ad(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 xr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function kl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var cd=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,xr(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 xr(this,4);return kl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw xr(this,4);return kl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw xr(this,4);let e=_b(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw xr(this,4);let e=Bb(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 xr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return kb(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw xr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw xr(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new zt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw xr(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 xr(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 xr(this,8);let e=kl(this.buf,this.pos+=4),t=kl(this.buf,this.pos+=4);return new zt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=od(this.buf,this.pos);return this.pos+=Ue(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 ud(r){return new cd(r instanceof Uint8Array?r:r.subarray())}function vr(r,e,t){let n=ud(r);return e.decode(n,void 0,t)}function ld(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 $o=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function fd(){}var pd=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},y_=ld();function g_(r){return globalThis.Buffer!=null?ot(r):y_(r)}var Za=class{len;head;tail;states;constructor(){this.len=0,this.head=new $o(fd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new $o(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new dd((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ol,10,zt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=zt.fromBigInt(e);return this._push(Ol,t.length(),t)}uint64Number(e){return this._push(hs,Ue(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=zt.fromBigInt(e).zzEncode();return this._push(Ol,t.length(),t)}sint64Number(e){let t=zt.fromNumber(e).zzEncode();return this._push(Ol,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(hd,1,e?1:0)}fixed32(e){return this._push(Xa,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=zt.fromBigInt(e);return this._push(Xa,4,t.lo)._push(Xa,4,t.hi)}fixed64Number(e){let t=zt.fromNumber(e);return this._push(Xa,4,t.lo)._push(Xa,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Eb,4,e)}double(e){return this._push(Cb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(hd,1,0):this.uint32(t)._push(w_,t,e)}string(e){let t=Tb(e);return t!==0?this.uint32(t)._push(ad,t,e):this._push(hd,1,0)}fork(){return this.states=new pd(this),this.head=this.tail=new $o(fd,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 $o(fd,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=g_(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function hd(r,e,t){e[t]=r&255}function b_(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var dd=class extends $o{next;constructor(e,t){super(b_,e,t),this.next=void 0}};function Ol(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Xa(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function w_(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Za.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(x_,e,r),this},Za.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(v_,e,r),this});function x_(r,e,t){e.set(r,t)}function v_(r,e,t){r.length<40?ad(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function md(){return new Za}function Ar(r,e){let t=md();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ps;(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"})(ps||(ps={}));function Pl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Fo(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",ps.VARINT,t,n)}function Sr(r,e){return Pl("message",ps.LENGTH_DELIMITED,r,e)}var Ya=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var yd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(yd||(yd={}));(function(r){r.codec=()=>Fo(yd)})(Ye||(Ye={}));var Kr;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Kr||(Kr={}));var gd;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(gd||(gd={}));var Qa={};vt(Qa,{MAX_RSA_KEY_SIZE:()=>bd,generateRSAKeyPair:()=>Bd,jwkToJWKKeyPair:()=>Lb,jwkToPkcs1:()=>__,jwkToPkix:()=>Ad,jwkToRSAPrivateKey:()=>Cd,pkcs1MessageToJwk:()=>xd,pkcs1MessageToRSAPrivateKey:()=>Sd,pkcs1ToJwk:()=>E_,pkcs1ToRSAPrivateKey:()=>Rb,pkixMessageToJwk:()=>vd,pkixMessageToRSAPublicKey:()=>_d,pkixToJwk:()=>C_,pkixToRSAPublicKey:()=>Ed});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=Qa.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return Db(this.jwk,t,e,n)}},Ja=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Qa.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return Nb(this.jwk,e,t)}};var bd=8192,wd=18,A_=1062,S_=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function E_(r){let e=sn(r);return xd(e)}function xd(r){return{n:ue(r[1],"base64url"),e:ue(r[2],"base64url"),d:ue(r[3],"base64url"),p:ue(r[4],"base64url"),q:ue(r[5],"base64url"),dp:ue(r[6],"base64url"),dq:ue(r[7],"base64url"),qi:ue(r[8],"base64url"),kty:"RSA"}}function __(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 xe("JWK was missing components");return gr([Tt(Uint8Array.from([0])),Tt(de(r.n,"base64url")),Tt(de(r.e,"base64url")),Tt(de(r.d,"base64url")),Tt(de(r.p,"base64url")),Tt(de(r.q,"base64url")),Tt(de(r.dp,"base64url")),Tt(de(r.dq,"base64url")),Tt(de(r.qi,"base64url"))]).subarray()}function C_(r){let e=sn(r,{offset:0});return vd(e)}function vd(r){let e=sn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Ad(r){if(r.n==null||r.e==null)throw new xe("JWK was missing components");return gr([S_,Pa(gr([Tt(de(r.n,"base64url")),Tt(de(r.e,"base64url"))]))]).subarray()}function Rb(r){let e=sn(r);return Sd(e)}function Sd(r){let e=xd(r);return Cd(e)}function Ed(r,e){if(r.byteLength>=A_)throw new zi("Key size is too large");let t=sn(r,{offset:0});return _d(t,r,e)}function _d(r,e,t){let n=vd(r);if(t==null){let o=Ur(Kr.encode({Type:Ye.RSA,Data:e}));t=Bt(wd,o)}return new ds(n,t)}function Cd(r){if(Mb(r)>bd)throw new xe("Key size is too large");let e=Lb(r),t=Ur(Kr.encode({Type:Ye.RSA,Data:Ad(e.publicKey)})),n=Bt(wd,t);return new Ja(e.privateKey,new ds(e.publicKey,n))}async function Bd(r){if(r>bd)throw new xe("Key size is too large");let e=await Ub(r),t=Ur(Kr.encode({Type:Ye.RSA,Data:Ad(e.publicKey)})),n=Bt(wd,t);return new Ja(e.privateKey,new ds(e.publicKey,n))}function Lb(r){if(r==null)throw new xe("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ub(r,e){let t=await Ut.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 B_(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Nb(r,e,t){let n=await Ut.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Ut.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 Db(r,e,t,n){let o=await Ut.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ut.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function B_(r,e){if(r.privateKey==null||r.publicKey==null)throw new xe("Private and public key are required");let t=await Promise.all([Ut.get().subtle.exportKey("jwk",r.privateKey),Ut.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function Mb(r){if(r.kty!=="RSA")throw new xe("invalid key type");if(r.n==null)throw new xe("invalid key modulus");return de(r.n,"base64url").length*8}var Nl=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Ro(e),fe(t,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),br(o)}update(e){return rs(this),this.iHash.update(e),this}digestInto(e){rs(this),fe(e,this.outputLen,"output"),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||=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()}},ms=(r,e,t)=>new Nl(r,e).update(t).digest();ms.create=(r,e)=>new Nl(r,e);var jb=(r,e)=>(r+(r>=0?e:-e)/Kb)/e;function I_(r,e,t){let[[n,o],[i,s]]=e,a=jb(s*r,t),c=jb(-o*r,t),f=r-a*n-c*i,p=-a*o-c*s,h=f<pn,y=p<pn;h&&(f=-f),y&&(p=-p);let b=Ma(Math.ceil(Vp(t)/2))+ys;if(f<pn||f>=b||p<pn||p>=b)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:h,k1:f,k2neg:y,k2:p}}function Td(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Id(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return fn(t.lowS,"lowS"),fn(t.prehash,"prehash"),t.format!==void 0&&Td(t.format),t}var kd=class extends Error{constructor(e=""){super(e)}},Yn={Err:kd,_tlv:{encode:(r,e)=>{let{Err:t}=Yn;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=La(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?La(o.length/2|128):"";return La(r)+i+o+e},decode(r,e){let{Err:t}=Yn,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 f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let p of f)s=s<<8|p;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=Yn;if(r<pn)throw new e("integer: negative integers are not allowed");let t=La(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}=Yn;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 ns(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Yn,o=fe(r,void 0,"signature"),{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:f,l:p}=n.decode(2,c);if(p.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=Yn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},pn=BigInt(0),ys=BigInt(1),Kb=BigInt(2),Dl=BigInt(3),T_=BigInt(4);function Hb(r,e={}){let t=Al("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;jr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=$b(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(V,B,A){let{x:v,y:D}=B.toAffine(),U=n.toBytes(v);if(fn(A,"isCompressed"),A){p();let L=!n.isOdd(D);return Lt(Vb(L),U)}else return Lt(Uint8Array.of(4),U,n.toBytes(D))}function y(V){fe(V,void 0,"Point");let{publicKey:B,publicKeyUncompressed:A}=f,v=V.length,D=V[0],U=V.subarray(1);if(v===B&&(D===2||D===3)){let L=n.fromBytes(U);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let T=C(L),M;try{M=n.sqrt(T)}catch(pe){let be=pe instanceof Error?": "+pe.message:"";throw new Error("bad point: is not on curve, sqrt error"+be)}p();let W=n.isOdd(M);return(D&1)===1!==W&&(M=n.neg(M)),{x:L,y:M}}else if(v===A&&D===4){let L=n.BYTES,T=n.fromBytes(U.subarray(0,L)),M=n.fromBytes(U.subarray(L,L*2));if(!m(T,M))throw new Error("bad point: is not on curve");return{x:T,y:M}}else throw new Error(`bad point: got length ${v}, expected compressed=${B} or uncompressed=${A}`)}let b=e.toBytes||h,g=e.fromBytes||y;function C(V){let B=n.sqr(V),A=n.mul(B,V);return n.add(n.add(A,n.mul(V,i.a)),i.b)}function m(V,B){let A=n.sqr(B),v=C(V);return n.eql(A,v)}if(!m(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(i.a,Dl),T_),N=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(S,N)))throw new Error("bad curve params: a or b");function I(V,B,A=!1){if(!n.isValid(B)||A&&n.is0(B))throw new Error(`bad point coordinate ${V}`);return B}function K(V){if(!(V instanceof k))throw new Error("Weierstrass Point expected")}function Z(V){if(!c||!c.basises)throw new Error("no endo");return I_(V,c.basises,o.ORDER)}let q=os((V,B)=>{let{X:A,Y:v,Z:D}=V;if(n.eql(D,n.ONE))return{x:A,y:v};let U=V.is0();B==null&&(B=U?n.ONE:n.inv(D));let L=n.mul(A,B),T=n.mul(v,B),M=n.mul(D,B);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(M,n.ONE))throw new Error("invZ was invalid");return{x:L,y:T}}),re=os(V=>{if(V.is0()){if(e.allowInfinityPoint&&!n.is0(V.Y))return;throw new Error("bad point: ZERO")}let{x:B,y:A}=V.toAffine();if(!n.isValid(B)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!m(B,A))throw new Error("bad point: equation left != right");if(!V.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(V,B,A,v,D){return A=new k(n.mul(A.X,V),A.Y,A.Z),B=Ka(v,B),A=Ka(D,A),B.add(A)}class k{static BASE=new k(i.Gx,i.Gy,n.ONE);static ZERO=new k(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(B,A,v){this.X=I("x",B),this.Y=I("y",A,!0),this.Z=I("z",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(B){let{x:A,y:v}=B||{};if(!B||!n.isValid(A)||!n.isValid(v))throw new Error("invalid affine point");if(B instanceof k)throw new Error("projective point not allowed");return n.is0(A)&&n.is0(v)?k.ZERO:new k(A,v,n.ONE)}static fromBytes(B){let A=k.fromAffine(g(fe(B,void 0,"point")));return A.assertValidity(),A}static fromHex(B){return k.fromBytes(un(B))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(B=8,A=!0){return Y.createCache(this,B),A||this.multiply(Dl),this}assertValidity(){re(this)}hasEvenY(){let{y:B}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(B)}equals(B){K(B);let{X:A,Y:v,Z:D}=this,{X:U,Y:L,Z:T}=B,M=n.eql(n.mul(A,T),n.mul(U,D)),W=n.eql(n.mul(v,T),n.mul(L,D));return M&&W}negate(){return new k(this.X,n.neg(this.Y),this.Z)}double(){let{a:B,b:A}=i,v=n.mul(A,Dl),{X:D,Y:U,Z:L}=this,T=n.ZERO,M=n.ZERO,W=n.ZERO,O=n.mul(D,D),pe=n.mul(U,U),be=n.mul(L,L),ee=n.mul(D,U);return ee=n.add(ee,ee),W=n.mul(D,L),W=n.add(W,W),T=n.mul(B,W),M=n.mul(v,be),M=n.add(T,M),T=n.sub(pe,M),M=n.add(pe,M),M=n.mul(T,M),T=n.mul(ee,T),W=n.mul(v,W),be=n.mul(B,be),ee=n.sub(O,be),ee=n.mul(B,ee),ee=n.add(ee,W),W=n.add(O,O),O=n.add(W,O),O=n.add(O,be),O=n.mul(O,ee),M=n.add(M,O),be=n.mul(U,L),be=n.add(be,be),O=n.mul(be,ee),T=n.sub(T,O),W=n.mul(be,pe),W=n.add(W,W),W=n.add(W,W),new k(T,M,W)}add(B){K(B);let{X:A,Y:v,Z:D}=this,{X:U,Y:L,Z:T}=B,M=n.ZERO,W=n.ZERO,O=n.ZERO,pe=i.a,be=n.mul(i.b,Dl),ee=n.mul(A,U),Ae=n.mul(v,L),Be=n.mul(D,T),Ke=n.add(A,v),Ee=n.add(U,L);Ke=n.mul(Ke,Ee),Ee=n.add(ee,Ae),Ke=n.sub(Ke,Ee),Ee=n.add(A,D);let Ie=n.add(U,T);return Ee=n.mul(Ee,Ie),Ie=n.add(ee,Be),Ee=n.sub(Ee,Ie),Ie=n.add(v,D),M=n.add(L,T),Ie=n.mul(Ie,M),M=n.add(Ae,Be),Ie=n.sub(Ie,M),O=n.mul(pe,Ee),M=n.mul(be,Be),O=n.add(M,O),M=n.sub(Ae,O),O=n.add(Ae,O),W=n.mul(M,O),Ae=n.add(ee,ee),Ae=n.add(Ae,ee),Be=n.mul(pe,Be),Ee=n.mul(be,Ee),Ae=n.add(Ae,Be),Be=n.sub(ee,Be),Be=n.mul(pe,Be),Ee=n.add(Ee,Be),ee=n.mul(Ae,Ee),W=n.add(W,ee),ee=n.mul(Ie,Ee),M=n.mul(Ke,M),M=n.sub(M,ee),ee=n.mul(Ke,Ae),O=n.mul(Ie,O),O=n.add(O,ee),new k(M,W,O)}subtract(B){return this.add(B.negate())}is0(){return this.equals(k.ZERO)}multiply(B){let{endo:A}=e;if(!o.isValidNot0(B))throw new Error("invalid scalar: out of range");let v,D,U=L=>Y.cached(this,L,T=>Ho(k,T));if(A){let{k1neg:L,k1:T,k2neg:M,k2:W}=Z(B),{p:O,f:pe}=U(T),{p:be,f:ee}=U(W);D=pe.add(ee),v=R(A.beta,O,be,L,M)}else{let{p:L,f:T}=U(B);v=L,D=T}return Ho(k,[v,D])[0]}multiplyUnsafe(B){let{endo:A}=e,v=this;if(!o.isValid(B))throw new Error("invalid scalar: out of range");if(B===pn||v.is0())return k.ZERO;if(B===ys)return v;if(Y.hasCache(this))return this.multiply(B);if(A){let{k1neg:D,k1:U,k2neg:L,k2:T}=Z(B),{p1:M,p2:W}=ub(k,v,U,T);return R(A.beta,M,W,D,L)}else return Y.unsafe(v,B)}toAffine(B){return q(this,B)}isTorsionFree(){let{isTorsionFree:B}=e;return s===ys?!0:B?B(k,this):Y.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:B}=e;return s===ys?this:B?B(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(B=!0){return fn(B,"isCompressed"),this.assertValidity(),b(k,this,B)}toHex(B=!0){return cn(this.toBytes(B))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=o.BITS,Y=new as(k,e.endo?Math.ceil(G/2):G);return k.BASE.precompute(8),k}function Vb(r){return Uint8Array.of(r?2:3)}function $b(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function k_(r,e={}){let{Fn:t}=r,n=e.randomBytes||Fn,o=Object.assign($b(r.Fp,t),{seed:qp(t.ORDER)});function i(b){try{let g=t.fromBytes(b);return t.isValidNot0(g)}catch{return!1}}function s(b,g){let{publicKey:C,publicKeyUncompressed:m}=o;try{let S=b.length;return g===!0&&S!==C||g===!1&&S!==m?!1:!!r.fromBytes(b)}catch{return!1}}function a(b=n(o.seed)){return Gp(fe(b,o.seed,"seed"),t.ORDER)}function c(b,g=!0){return r.BASE.multiply(t.fromBytes(b)).toBytes(g)}function f(b){let{secretKey:g,publicKey:C,publicKeyUncompressed:m}=o;if(!Do(b)||"_lengths"in t&&t._lengths||g===C)return;let S=fe(b,void 0,"key").length;return S===C||S===m}function p(b,g,C=!0){if(f(b)===!0)throw new Error("first arg must be private key");if(f(g)===!1)throw new Error("second arg must be public key");let m=t.fromBytes(b);return r.fromBytes(g).multiply(m).toBytes(C)}let h={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},y=cs(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:p,keygen:y,Point:r,utils:h,lengths:o})}function Fb(r,e,t={}){Ro(e),jr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),t=Object.assign({},t);let n=t.randomBytes||Fn,o=t.hmac||((A,v)=>ms(e,A,v)),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:p,getSharedSecret:h,utils:y,lengths:b}=k_(r,t),g={prehash:!0,lowS:typeof t.lowS=="boolean"?t.lowS:!0,format:"compact",extraEntropy:!1},C=a*Kb<i.ORDER;function m(A){let v=a>>ys;return A>v}function S(A,v){if(!s.isValidNot0(v))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return v}function N(){if(C)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(A,v){Td(v);let D=b.signature,U=v==="compact"?D:v==="recovered"?D+1:void 0;return fe(A,U)}class K{r;s;recovery;constructor(v,D,U){if(this.r=S("r",v),this.s=S("s",D),U!=null){if(N(),![0,1,2,3].includes(U))throw new Error("invalid recovery id");this.recovery=U}Object.freeze(this)}static fromBytes(v,D=g.format){I(v,D);let U;if(D==="der"){let{r:W,s:O}=Yn.toSig(fe(v));return new K(W,O)}D==="recovered"&&(U=v[0],D="compact",v=v.subarray(1));let L=b.signature/2,T=v.subarray(0,L),M=v.subarray(L,L*2);return new K(s.fromBytes(T),s.fromBytes(M),U)}static fromHex(v,D){return this.fromBytes(un(v),D)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new K(this.r,this.s,v)}recoverPublicKey(v){let{r:D,s:U}=this,L=this.assertRecovery(),T=L===2||L===3?D+a:D;if(!i.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=i.toBytes(T),W=r.fromBytes(Lt(Vb((L&1)===0),M)),O=s.inv(T),pe=q(fe(v,void 0,"msgHash")),be=s.create(-pe*O),ee=s.create(U*O),Ae=r.BASE.multiplyUnsafe(be).add(W.multiplyUnsafe(ee));if(Ae.is0())throw new Error("invalid recovery: point at infinify");return Ae.assertValidity(),Ae}hasHighS(){return m(this.s)}toBytes(v=g.format){if(Td(v),v==="der")return un(Yn.hexFromSig(this));let{r:D,s:U}=this,L=s.toBytes(D),T=s.toBytes(U);return v==="recovered"?(N(),Lt(Uint8Array.of(this.assertRecovery()),L,T)):Lt(L,T)}toHex(v){return cn(this.toBytes(v))}}let Z=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let D=ns(v),U=v.length*8-c;return U>0?D>>BigInt(U):D},q=t.bits2int_modN||function(v){return s.create(Z(v))},re=Ma(c);function R(A){return zn("num < 2^"+c,A,pn,re),s.toBytes(A)}function k(A,v){return fe(A,void 0,"message"),v?fe(e(A),void 0,"prehashed message"):A}function G(A,v,D){let{lowS:U,prehash:L,extraEntropy:T}=Id(D,g);A=k(A,L);let M=q(A),W=s.fromBytes(v);if(!s.isValidNot0(W))throw new Error("invalid private key");let O=[R(W),R(M)];if(T!=null&&T!==!1){let Ae=T===!0?n(b.secretKey):T;O.push(fe(Ae,void 0,"extraEntropy"))}let pe=Lt(...O),be=M;function ee(Ae){let Be=Z(Ae);if(!s.isValidNot0(Be))return;let Ke=s.inv(Be),Ee=r.BASE.multiply(Be).toAffine(),Ie=s.create(Ee.x);if(Ie===pn)return;let rn=s.create(Ke*s.create(be+Ie*W));if(rn===pn)return;let pr=(Ee.x===Ie?0:2)|Number(Ee.y&ys),jn=rn;return U&&m(rn)&&(jn=s.neg(rn),pr^=1),new K(Ie,jn,C?void 0:pr)}return{seed:pe,k2sig:ee}}function Y(A,v,D={}){let{seed:U,k2sig:L}=G(A,v,D);return q0(e.outputLen,s.BYTES,o)(U,L).toBytes(D.format)}function V(A,v,D,U={}){let{lowS:L,prehash:T,format:M}=Id(U,g);if(D=fe(D,void 0,"publicKey"),v=k(v,T),!Do(A)){let W=A instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+W)}I(A,M);try{let W=K.fromBytes(A,M),O=r.fromBytes(D);if(L&&W.hasHighS())return!1;let{r:pe,s:be}=W,ee=q(v),Ae=s.inv(be),Be=s.create(ee*Ae),Ke=s.create(pe*Ae),Ee=r.BASE.multiplyUnsafe(Be).add(O.multiplyUnsafe(Ke));return Ee.is0()?!1:s.create(Ee.x)===pe}catch{return!1}}function B(A,v,D={}){let{prehash:U}=Id(D,g);return v=k(v,U),K.fromBytes(A,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:h,utils:y,lengths:b,Point:r,sign:Y,verify:V,recoverPublicKey:B,Signature:K,hash:e})}var Pd={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},O_={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Wb=BigInt(2);function P_(r){let e=Pd.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,p=f*f*r%e,h=Le(p,t,e)*p%e,y=Le(h,t,e)*p%e,b=Le(y,Wb,e)*f%e,g=Le(b,o,e)*b%e,C=Le(g,i,e)*g%e,m=Le(C,a,e)*C%e,S=Le(m,c,e)*m%e,N=Le(S,a,e)*C%e,I=Le(N,t,e)*p%e,K=Le(I,s,e)*g%e,Z=Le(K,n,e)*f%e,q=Le(Z,Wb,e);if(!Od.eql(Od.sqr(q),r))throw new Error("Cannot find square root");return q}var Od=is(Pd.p,{sqrt:P_}),N_=Hb(Pd,{Fp:Od,endo:O_}),Er=Fb(N_,Ur);function qb(r,e,t){let n=tr.digest(e instanceof Uint8Array?e:e.subarray());if(fs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Er.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Fa(String(o))});try{return Er.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Fa(String(o))}}function Gb(r,e,t,n){let o=tr.digest(t instanceof Uint8Array?t:t.subarray());if(fs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Er.verify(e,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Wa(String(i))});try{return n?.signal?.throwIfAborted(),Er.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Wa(String(i))}}var ec=class{type="secp256k1";raw;_key;constructor(e){this._key=Zb(e),this.raw=zb(this._key)}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return Gb(this._key,t,e,n)}},Rl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=Xb(e),this.publicKey=new ec(t??Yb(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return qb(this.raw,e,t)}};function Nd(r){return new ec(r)}async function Jb(){let r=D_();return new Rl(r)}function zb(r){return Er.Point.fromBytes(r).toBytes()}function Xb(r){try{return Er.getPublicKey(r,!0),r}catch(e){throw new Ea(String(e))}}function Zb(r){try{return Er.Point.fromBytes(r),r}catch(e){throw new zi(String(e))}}function Yb(r){try{return Er.getPublicKey(r,!0)}catch(e){throw new Ea(String(e))}}function D_(){return Er.utils.randomSecretKey()}async function Qb(r,e){if(r==="Ed25519")return Sb();if(r==="secp256k1")return Jb();if(r==="RSA")return Bd(R_(e));if(r==="ECDSA")return I0(L_(e));throw new Kn}function tc(r,e){let{Type:t,Data:n}=Kr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return Ed(o,e);case Ye.Ed25519:return Qp(o);case Ye.secp256k1:return Nd(o);case Ye.ECDSA:return Op(o);default:throw new Kn}}function ew(r){let{Type:e,Data:t}=Kr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return Qp(n);case Ye.secp256k1:return Nd(n);case Ye.ECDSA:return Op(n);default:throw new Kn}}function $n(r){return Kr.encode({Type:Ye[r.type],Data:r.raw})}function R_(r){return r==null?2048:parseInt(r,10)}function L_(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 xe("Unsupported curve, should be P-256, P-384 or P-521")}async function Ll(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 xe("Only RSA and ECDSA keys are supported")}var tw=Symbol.for("nodejs.util.inspect.custom"),U_=114,rc=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()})`}[op]=!0;toString(){return this.string==null&&(this.string=Fe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1(U_,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return We(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return We(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[tw](){return`PeerId(${this.toString()})`}},nc=class extends rc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},oc=class extends rc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},ic=class extends rc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},M_=2336,sc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=yr.digest(de(this.url))}[tw](){return`PeerId(${this.url})`}[op]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(M_,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var j_=114,rw=2336;function gs(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ts(Fe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return K_(rt.parse(r));if(e==null)throw new xe('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ts(e.decode(r))}return nw(t)}function Dd(r){if(r.type==="Ed25519")return new oc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ic({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nc({multihash:r.toCID().multihash,publicKey:r});throw new Kn}function nw(r){if(V_(r))return new nc({multihash:r});if(H_(r))try{let e=ew(r);if(e.type==="Ed25519")return new oc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new ic({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new sc(new URL(t))}throw new sl("Supplied PeerID Multihash is invalid")}function K_(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==j_&&r.code!==rw)throw new il("Supplied PeerID CID is invalid");if(r.code===rw){let e=ue(r.multihash.digest);return new sc(new URL(e))}return nw(r.multihash)}function H_(r){return r.code===yr.code}function V_(r){return r.code===tr.code}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},dn=class extends Error{static name="ValidationError";name="ValidationError"},Ul=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ml=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var jl=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",f=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let y=Number.parseInt(h,e);if(!Number.isNaN(y))return y});if(p===void 0)break;if(i*=e,i+=p,i>f||(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 $_=45,F_=15,Kl=new jl;function ow(r){if(!(r.length>F_))return Kl.new(r).parseWith(()=>Kl.readIPv4Addr())}function iw(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$_))return Kl.new(r).parseWith(()=>Kl.readIPv6Addr())}function Hl(r){return!!ow(r)}function sw(r){return!!iw(r)}function Ld(r){return e=>ue(e,r)}function Ud(r){return e=>de(e,r)}function bs(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Wo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function aw(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=de(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Wo(n);return It([t,o],t.length+o.length)}function cw(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=Vn.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=Wo(n);return It([t,o],t.length+o.length)}function Md(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ue(e,"base32"),o=bs(t);return`${n}:${o}`}var jd=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 ht("Invalid byte value in IP address");e[n]=o}),e},uw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Hl(t[n]),s;i&&(s=jd(t[n]),t[n]=ue(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new ht("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},lw=function(r){if(r.byteLength!==4)throw new ht("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},fw=function(r){if(r.byteLength!==16)throw new ht("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 ht(`Invalid IPv6 address "${t}"`)}};function hw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${r}"`)}}var Rd=Object.values(Po).map(r=>r.decoder),W_=(function(){let r=Rd[0].or(Rd[1]);return Rd.slice(2).forEach(e=>r=r.or(e)),r})();function pw(r){return W_.decode(r)}function dw(r){return e=>r.encoder.encode(e)}function q_(r){if(parseInt(r).toString()!==r)throw new dn("Value must be an integer")}function G_(r){if(r<0)throw new dn("Value must be a positive integer, or zero")}function z_(r){return e=>{if(e>r)throw new dn(`Value must be smaller than or equal to ${r}`)}}function X_(...r){return e=>{for(let t of r)t(e)}}var ac=X_(q_,G_,z_(65535));var ct=-1,Kd=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 Ml(`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)}))}},mn=new Kd,l2=[{code:4,name:"ip4",size:32,valueToBytes:jd,bytesToValue:lw,validate:r=>{if(!Hl(r))throw new dn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:273,name:"udp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:33,name:"dccp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:41,name:"ip6",size:128,valueToBytes:uw,bytesToValue:fw,stringToValue:hw,validate:r=>{if(!sw(r))throw new dn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:Ld("base10"),valueToBytes:Ud("base10")},{code:53,name:"dns",size:ct},{code:54,name:"dns4",size:ct},{code:55,name:"dns6",size:ct},{code:56,name:"dnsaddr",size:ct},{code:132,name:"sctp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:Ld("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ud("base58btc")(r):rt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Md,valueToBytes:aw},{code:445,name:"onion3",size:296,bytesToValue:Md,valueToBytes:cw},{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:dw(Oo),valueToBytes:pw},{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}];l2.forEach(r=>{mn.addProtocol(r)});function mw(r){let e=[],t=0;for(;t<r.length;){let n=hn(r,t),o=mn.getProtocol(n),i=Ue(n),s=f2(o,r,t+i),a=0;s>0&&o.size===ct&&(a=Ue(s));let c=i+a+s,f={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let p=t+i+a,h=r.subarray(p,p+s);f.value=o.bytesToValue?.(h)??ue(h)}e.push(f),t+=c}return e}function yw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=mn.getProtocol(n.code),i=Ue(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??de(n.value),a=s.byteLength,o.size===ct&&(c=Ue(a)));let f=new Uint8Array(i+c+a),p=0;hs(n.code,f,p),p+=i,s!=null&&(o.size===ct&&(hs(a,f,p),p+=c),f.set(s,p)),n.bytes=f}t.push(n.bytes),e+=n.bytes.byteLength}return It(t,e)}function gw(r){if(r.charAt(0)!=="/")throw new ht('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=mn.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 ht(`Component ${o} was missing value`);t="value"}else if(t==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ht(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return e}function bw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=mn.getProtocol(e.code);if(t==null)throw new ht(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function f2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:hn(e,t)}var h2=Symbol.for("nodejs.util.inspect.custom"),nm=Symbol.for("@multiformats/multiaddr");function p2(r){if(r==null&&(r="/"),ww(r))return r.getComponents();if(r instanceof Uint8Array)return mw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),gw(r);if(Array.isArray(r))return r;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wl=class r{[nm]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=p2(e),t.validate!==!1&&d2(this)}get bytes(){return this.#r==null&&(this.#r=yw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=bw(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 Ul(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return We(this.bytes,e.bytes)}[h2](){return`Multiaddr(${this.toString()})`}};function d2(r){r.getComponents().forEach(e=>{let t=mn.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function ww(r){return!!r?.[nm]}function As(r){return new Wl(r)}var Pe=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),ce=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),xw=r=>({match:e=>r.match(e)===!1?e:!1}),Se=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),Et=(...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}}),ke=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function Ne(...r){function e(o){if(o==null)return!1;let i=o.getComponents();for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var m2=ce(421),oO=Ne(m2),Gl=ce(54),zl=ce(55),Xl=ce(56),im=ce(53),iO=Ne(Gl,Se(ce(421))),sO=Ne(zl,Se(ce(421))),aO=Ne(Xl,Se(ce(421))),cO=Ne(Et(im,Xl,Gl,zl),Se(ce(421))),vw=ke(ce(4),Se(ce(43))),Aw=ke(Se(ce(42)),ce(41),Se(ce(43))),sm=Et(vw,Aw),zo=Et(sm,im,Gl,zl,Xl),uO=Ne(Et(sm,ke(Et(im,Xl,Gl,zl),Se(ce(421))))),lO=Ne(vw),fO=Ne(Aw),hO=Ne(sm),am=ke(zo,ce(6)),cc=ke(zo,ce(273)),pO=Ne(ke(am,Se(ce(421)))),dO=Ne(cc),cm=ke(cc,Pe(460),Se(ce(421))),Zl=ke(cc,Pe(461),Se(ce(421))),y2=Et(cm,Zl),mO=Ne(cm),yO=Ne(Zl),om=Et(zo,am,cc,cm,Zl),Sw=Et(ke(om,Pe(477),Se(ce(421)))),gO=Ne(Sw),Ew=Et(ke(om,Pe(478),Se(ce(421))),ke(om,Pe(448),Se(ce(449)),Pe(477),Se(ce(421)))),bO=Ne(Ew),_w=ke(cc,Pe(280),Se(ce(466)),Se(ce(466)),Se(ce(421))),Cw=Ne(_w),Bw=ke(Zl,Pe(465),Se(ce(466)),Se(ce(466)),Se(ce(421))),wO=Ne(Bw),ql=Et(Sw,Ew,ke(am,Se(ce(421))),ke(y2,Se(ce(421))),ke(zo,Se(ce(421))),_w,Bw,ce(421)),Iw=Ne(ql),g2=ke(Se(ql),Pe(290),xw(Pe(281)),Se(ce(421))),xO=Ne(g2),b2=Et(ke(ql,Pe(290),Pe(281),Se(ce(421))),ke(ql,Pe(281),Se(ce(421))),ke(Pe(281),Se(ce(421)))),Tw=Ne(b2),w2=Et(ke(zo,ce(6),Pe(480),Se(ce(421))),ke(zo,Pe(480),Se(ce(421)))),vO=Ne(w2),x2=ke(zo,Et(ke(ce(6,"443"),Pe(480)),ke(ce(6),Pe(443)),ke(ce(6),Pe(448),Pe(480)),ke(Pe(448),Pe(480)),Pe(448),Pe(443)),Se(ce(421))),AO=Ne(x2),v2=Et(ke(ce(777),Se(ce(421)))),SO=Ne(v2),A2=Et(ke(ce(400),Se(ce(421)))),EO=Ne(A2);var _t;(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=()=>Fo(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Sr((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 f=o.uint32();switch(f>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ar(o,r.codec()),r.decode=(o,i)=>vr(o,r.codec(),i)})(_t||(_t={}));var kw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],um=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ow="libp2p+webrtc+v1/",Pw=2*1024*1024,Ss=16*1024;function S2(r=Ss){let e=Ue(r-Ue(r)),t=1+Ue(Object.keys(_t.Flag).length-1),n=1,o=r-e-t-n,i=Ue(o);return e+t+n+i}var Nw=S2();var Dw=1e4,lm="/webrtc",uc="/webrtc-signaling/0.0.1",Rw="/libp2p/webrtc-direct/certificate",Lw="webrtc-direct-certificate-private-key";var Uw=12096e5,fm=864e5;function hm(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new xe(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}function Yl(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Jl=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}},Es=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Jl(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 Jl(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 pm=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 E2(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 E2(r,e){e=e??{};let t=e.onEnd,n=new Es,o,i,s,a=Yl(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((m,S)=>{i=N=>{i=null,n.push(N);try{m(r(n))}catch(I){S(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Yl()})}},f=m=>i!=null?i(m):(n.push(m),o),p=m=>(n=new Es,i!=null?i({error:m}):(n.push({error:m}),o)),h=m=>{if(s)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},y=m=>s?o:(s=!0,m!=null?p(m):f({done:!0})),b=()=>(n=new Es,y(),{done:!0}),g=m=>(y(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:b,throw:g,push:h,end:y,get readableLength(){return n.size},onEmpty:async m=>{let S=m?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let N,I;S!=null&&(N=new Promise((K,Z)=>{I=()=>{Z(new pm)},S.addEventListener("abort",I)}));try{await Promise.race([a.promise,N])}finally{I!=null&&S!=null&&S?.removeEventListener("abort",I)}}},t==null)return o;let C=o;return o={[Symbol.asyncIterator](){return this},next(){return C.next()},throw(m){return C.throw(m),t!=null&&(t(m),t=void 0),{done:!0}},return(){return C.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(m){return C.end(m),t!=null&&(t(m),t=void 0),o},get readableLength(){return C.readableLength},onEmpty:m=>C.onEmpty(m)},o}var dm=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},mm=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Mw=r=>globalThis.DOMException===void 0?new mm(r):new DOMException(r),jw=r=>{let e=r.reason===void 0?Mw("This operation was aborted."):r.reason;return e instanceof Error?e:Mw(e)};function ym(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,f=new Promise((p,h)=>{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:b}=e;b.aborted&&h(jw(b)),a=()=>{h(jw(b))},b.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let y=new dm;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(b){h(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(y.message=o??`Promise timed out after ${t} milliseconds`,h(y))},t),(async()=>{try{p(await r)}catch(b){h(b)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var _2=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function C2(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:p}=_2(r),h=async(...b)=>{let g=t.multiArgs?b:b[0];if(t.filter)try{if(!await t.filter(g))return}catch(C){n(),s(C);return}c.push(g),t.count===c.length&&(n(),i(c))},y=(...b)=>{n(),s(t.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)p(b,h);for(let b of t.rejectionEvents)a.includes(b)||p(b,y)};for(let b of a)f(b,h);for(let b of t.rejectionEvents)a.includes(b)||f(b,y);t.signal&&t.signal.addEventListener("abort",()=>{y(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=ym(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Ot(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=C2(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var Xo=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Ql=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function B2(r){return r.reason}async function Cs(r,e,t){if(e==null)return r;let n=t?.translateError??B2;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var I2=Math.pow(2,20)*4,Qn=class extends er{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??I2,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new me,this.writeBuffer=new me,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=_s(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new nn(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new ll(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Xi;this.dispatchEvent(new fl(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Zi))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new me(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new ul(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new _a(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new _a(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ef=class extends Qn{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ot(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ot(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Kw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var tf=class extends er{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await Cs(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new nl;let t=this.onCreateStream({...this.streamOptions,...e});return Kw(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new Ql(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var rf=class extends Qn{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ot(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Ot(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var T2=4194304,nf=class extends Error{static name="UnwrappedError";name="UnwrappedError"},lc=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},bm=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},wm=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function k2(r){return typeof r?.closeRead=="function"}function O2(r){return typeof r?.close=="function"}function gm(r){return k2(r)?r.readStatus==="closing"||r.readStatus==="closed":O2(r)?r.status!=="open":!1}function P2(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function N2(r,e){let t=e?.maxBufferSize??T2,n=new me,o,i=!1;if(!P2(r))throw new xe("Argument should be a Stream or a Multiaddr");let s=p=>{if(n.append(p.data),n.byteLength>t){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=p=>{p.error!=null?o?.reject(p.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(p){if(i===!0)throw new nf("Stream was unwrapped");if(gm(r)){if(p?.bytes==null)return null;if(n.byteLength<p.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,p.bytes),new Xo(`Unexpected EOF - stream closed after reading ${n.byteLength}/${p.bytes} bytes`)}let h=p?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Cs(o.promise,p?.signal),gm(r)){if(n.byteLength===0&&p?.bytes==null)return null;break}o=Promise.withResolvers()}let y=p?.bytes??n.byteLength;if(n.byteLength<y){if(gm(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,y),new Xo(`Unexpected EOF - stream closed while reading ${n.byteLength}/${y} bytes`);return f.read(p)}let b=n.sublist(0,y);return n.consume(y),b},async write(p,h){if(i===!0)throw new nf("Stream was unwrapped");r.send(p)||await Ot(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return f}function of(r,e={}){let t=N2(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ue(e.maxDataLength));let n=e?.lengthDecoder??hn,o=e?.lengthEncoder??Tl;return{async read(s){let a=-1,c=new me;for(;;){let p=await t.read({...s,bytes:1});if(p==null)break;c.append(p);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new lc("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new wm(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new bm(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await t.read({...s,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Xo(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Xo(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(s,a){await t.write(new me(o(s.byteLength),s),a)},async writeV(s,a){let c=new me(...s.flatMap(f=>[o(f.byteLength),f]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function sf(r,e){let t=of(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 D2=1024*1024*4,R2=1024*1024*4,af=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new me,this.maxBufferSize=e.maxBufferSize??D2,this.maxDataLength=e.maxDataLength??R2,this.lengthDecoder=e.lengthDecoder??hn,this.encodingLength=e.encodingLength??Ue}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new xe(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new lc("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var cf=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Bs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},uf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},fc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function lf(r){return r[Symbol.asyncIterator]!=null}function Hw(r,e){if(r.byteLength>e)throw new Bs("Message length too long")}var hf=r=>{let e=Ue(r),t=ot(e);return Tl(r,t),hf.bytes=e,t};hf.bytes=0;function hc(r,e){e=e??{};let t=e.lengthEncoder??hf,n=e?.maxDataLength??4194304;function*o(i){Hw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return lf(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}hc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??hf,n=e?.maxDataLength??4194304;return Hw(r,n),new me(t(r.byteLength),r)};var Zo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Zo||(Zo={}));var xm=r=>{let e=hn(r);return xm.bytes=Ue(e),e};xm.bytes=0;function pc(r,e){let t=new me,n=Zo.LENGTH,o=-1,i=e?.lengthDecoder??xm,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Zo.LENGTH)try{if(o=i(t),o<0)throw new cf("Invalid message length");if(o>a)throw new Bs("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(o),n=Zo.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>s)throw new uf("Message length length too long");break}throw f}if(n===Zo.DATA){if(t.byteLength<o)break;let f=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(f),yield f,n=Zo.LENGTH}}}return lf(r)?(async function*(){for await(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new fc("Unexpected end of input")})():(function*(){for(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new fc("Unexpected end of input")})()}pc.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 pc(n,{...e??{},onLength:i=>{t=i}})};var Vw=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))},M2=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var j2=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var K2=(function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r})();var H2=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var V2=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var $2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,F2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,$w=3,W2=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",$2]],Fw=[["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 qw(r){return r?Ww(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new V2:typeof navigator<"u"?Ww(navigator.userAgent):z2()}function q2(r){return r!==""&&W2.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function Ww(r){var e=q2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new H2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<$w&&(o=Vw(Vw([],o,!0),X2($w-o.length),!0)):o=[];var i=o.join("."),s=G2(r),a=F2.exec(r);return a&&a[1]?new K2(t,i,s,a[1]):new M2(t,i,s)}function G2(r){for(var e=0,t=Fw.length;e<t;e++){var n=Fw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function z2(){var r=typeof process<"u"&&process.version;return r?new j2(process.version.slice(1)):null}function X2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}var Gw=qw(),pf=Gw!=null&&Gw.name==="firefox";async function vm(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??kw.map(e=>({urls:[e]})),r}var zw=(r=32)=>Ow+[...Array(r)].map(()=>um.at(Math.floor(Math.random()*um.length))).join("");var Am=class extends rf{channel;incomingData;maxBufferedAmount;receivedFinAck;finAckTimeout;constructor(e){super({...e,maxMessageSize:(e.maxMessageSize??Ss)-Nw}),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=_s(),this.maxBufferedAmount=e.maxBufferedAmount??Pw,this.finAckTimeout=e.finAckTimeout??Dw,this.channel.onclose=()=>{this.log.trace("received datachannel close event"),this.onRemoteCloseWrite(),this.onTransportClosed()},this.channel.onerror=n=>{let o=n.error;this.log.trace("received datachannel error event - %e",o),this.abort(o)},this.channel.onmessage=async n=>{this.log("incoming message %d bytes",n.data.byteLength);let{data:o}=n;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))},this.channel.bufferedAmountLowThreshold=0,this.channel.onbufferedamountlow=()=>{this.writableNeedsDrain&&this.safeDispatchEvent("drain")},this.channel.readyState!=="open"&&(this.log('channel ready state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),Ot(this.channel,"open",{rejectionEvents:["close","error"]}).then(()=>{this.log('channel ready state is now "%s", dispatching drain',this.channel.readyState),this.safeDispatchEvent("drain")}).catch(n=>{this.abort(n.error??n)})),Promise.resolve().then(async()=>{for await(let n of pc(this.incomingData))this.processIncomingProtobuf(n)}).catch(n=>{this.log.error("error processing incoming data channel messages",n)});let t=()=>{this.channel.readyState==="open"&&(this.log.trace("stream closed, closing underlying datachannel"),this.channel.close())};this.addEventListener("close",t)}sendNewStream(){}_sendMessage(e){if(this.channel.readyState!=="open")throw new nn(`Invalid datachannel state - ${this.channel.readyState}`);if(this.log.trace('sending message, channel state "%s"',this.channel.readyState),pf){this.channel.send(e.subarray());return}for(let t of e)this.channel.send(t)}sendData(e){return this.channel.readyState!=="open"?{sentBytes:0,canSendMore:!1}:(this._sendMessage(hc.single(_t.encode({message:e.subarray()}))),{sentBytes:e.byteLength,canSendMore:this.channel.bufferedAmount<this.maxBufferedAmount})}sendReset(e){try{this.log.error("sending reset - %e",e),this._sendFlag(_t.Flag.RESET),this.receivedFinAck?.reject(e)}catch(t){this.log.error("failed to send reset - %e",t)}}async sendCloseWrite(e){this._sendFlag(_t.Flag.FIN),e?.signal?.throwIfAborted(),this.receivedFinAck=Promise.withResolvers(),await Promise.any([Cs(this.receivedFinAck.promise,e?.signal),new Promise(t=>{AbortSignal.timeout(this.finAckTimeout).addEventListener("abort",()=>{t()})})])}async sendCloseRead(e){this._sendFlag(_t.Flag.STOP_SENDING),e?.signal?.throwIfAborted()}processIncomingProtobuf(e){let t=_t.decode(e);t.message!=null&&(this.readStatus==="readable"||this.readStatus==="paused")&&this.onData(new me(t.message)),t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===_t.Flag.FIN&&(this._sendFlag(_t.Flag.FIN_ACK),this.onRemoteCloseWrite()),t.flag===_t.Flag.RESET&&(this.receivedFinAck?.reject(new Xi("The stream was reset")),this.onRemoteReset()),t.flag===_t.Flag.STOP_SENDING&&this.onRemoteCloseRead(),t.flag===_t.Flag.FIN_ACK&&this.receivedFinAck?.resolve())}_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=_t.encode({flag:e}),n=hc.single(t);try{return this._sendMessage(n),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}sendPause(){}sendResume(){}};function dc(r){let{channel:e,direction:t,isHandshake:n}=r;return new Am({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`),protocol:""})}var eo=class{protocol;peerConnection;metrics;dataChannelOptions;constructor(e){this.peerConnection=e.peerConnection,this.metrics=e.metrics,this.protocol=e.protocol??lm,this.dataChannelOptions=e.dataChannelOptions??{}}createStreamMuxer(e){return new Sm(e,{peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,protocol:this.protocol})}},Sm=class extends tf{peerConnection;dataChannelOptions;constructor(e,t){super(e,{...t,name:"muxer"}),this.peerConnection=t.peerConnection,this.protocol=t.protocol??lm,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming %s datachannel with channel id %d, protocol %s and status %s",n.protocol,n.id,n.protocol,n.readyState),n.label==="init"){this.log.trace("closing init channel %d",n.id),n.close();return}let o=dc({...this.streamOptions,...this.dataChannelOptions,channel:n,direction:"inbound",log:this.log});this.onRemoteStream(o)}}async onCreateStream(e){let t=this.peerConnection.createDataChannel("",{});return this.log("open channel %d for protocol %s",t.id,e?.protocol),dc({...e,...this.dataChannelOptions,channel:t,direction:"outbound",log:this.log})}onData(){}};var Em=class extends ef{peerConnection;constructor(e){super(e),this.peerConnection=e.peerConnection;let t=e.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change %s initial state %s",this.peerConnection.connectionState,t),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.onTransportClosed(),this.peerConnection.close())}}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.peerConnection.close(),e?.signal?.throwIfAborted()}sendReset(){this.peerConnection.close()}sendPause(){}sendResume(){}},mc=r=>new Em(r);var df=globalThis.RTCPeerConnection,mf=globalThis.RTCSessionDescription,Xw=globalThis.RTCIceCandidate;var Xt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var to=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},nr=class extends to{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var yf=class extends to{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var gf=class extends to{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},bf=class extends to{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 Mt;(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=()=>Fo(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Sr((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 f=o.uint32();switch(f>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ar(o,r.codec()),r.decode=(o,i)=>vr(o,r.codec(),i)})(Mt||(Mt={}));var wf=async(r,e,t)=>{try{let n=Promise.withResolvers();for(Z2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Mt.Type.ICE_CANDIDATE)throw new al("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Xt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Xw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Xt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received %o - %e",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate - %e",t.direction,n),t.signal?.aborted===!0&&r.connectionState!=="connected")throw n}};function Z2(r,e){if(r.connectionState==="connected"){e.resolve();return}r.onconnectionstatechange=t=>{switch(r.connectionState){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new rl(`RTCPeerConnection connection state became "${r.connectionState}"`));break;default:break}}}function xf(r){let e;for(let t of r.getComponents())t.name==="p2p"&&(e=gs(t.value??""));if(e==null)throw new ol("Remote peerId must be present in multiaddr");return e}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:f}){let{circuitAddress:p,targetPeer:h}=Yw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",p);let y=i.getConnections(h),b;y.length===0?(f?.(new Xt("webrtc:dial-relay")),b=await s.dial(p,{signal:t,onProgress:f})):(f?.(new Xt("webrtc:reuse-relay-connection")),b=y[0]),f?.(new Xt("webrtc:open-signaling-stream"));let g=await b.newStream(uc,{signal:t,runOnLimitedConnection:!0}),C=sf(g).pb(Mt),m=new df(r);m.addEventListener("connectionstatechange",()=>{switch(m.connectionState){case"closed":m.close();break;default:break}});let S=new eo({peerConnection:m,dataChannelOptions:e});try{let N=m.createDataChannel("init");m.onicecandidate=({candidate:q})=>{if(m.connectionState==="connected"){a.trace("ignore new ice candidate as peer connection is already connected");return}if(q==null||q?.candidate===""){a.trace("initiator detected end of ICE candidates");return}let re=JSON.stringify(q?.toJSON()??null);a.trace("initiator sending ICE candidate %o",q),C.write({type:Mt.Type.ICE_CANDIDATE,data:re},{signal:t}).catch(R=>{a.error("error sending ICE candidate - %e",R)})},m.onicecandidateerror=q=>{a.error("initiator ICE candidate error",q)};let I=await m.createOffer().catch(q=>{throw a.error("could not execute createOffer",q),new nr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",I.sdp),f?.(new Xt("webrtc:send-sdp-offer")),await C.write({type:Mt.Type.SDP_OFFER,data:I.sdp},{signal:t}),await m.setLocalDescription(I).catch(q=>{throw a.error("could not execute setLocalDescription",q),new nr("Failed to set localDescription")}),f?.(new Xt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let K=await C.read({signal:t});if(K.type!==Mt.Type.SDP_ANSWER)throw new nr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",K.data);let Z=new mf({type:"answer",sdp:K.data});return await m.setRemoteDescription(Z).catch(q=>{throw a.error("could not execute setRemoteDescription",q),new nr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),f?.(new Xt("webrtc:read-ice-candidates")),await wf(m,C,{direction:"initiator",signal:t,log:a,onProgress:f}),a.trace("initiator connected"),N.readyState!=="open"&&(a.trace("wait for init channel to open"),await Ot(N,"open",{signal:t})),a.trace("closing init channel"),N.close(),a.trace("waiting for init channel to close"),await Ot(N,"close",{signal:t}),f?.(new Xt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await g.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:m,muxerFactory:S}}catch(N){throw a.error("outgoing signaling error",N),m.close(),g.abort(N),N}finally{m.onicecandidate=null,m.onicecandidateerror=null}}var Jw=Ne(Iw.matchers[0],Pe(290)),vf=class r extends er{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=>Jw.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=>Jw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function Qw(r,e,{peerConnection:t,signal:n,log:o}){o.trace("new inbound signaling stream");let i=sf(r).pb(Mt);try{t.onicecandidate=({candidate:h})=>{if(t.connectionState==="connected"){o.trace("ignore new ice candidate as peer connection is already connected");return}if(h==null||h?.candidate===""){o.trace("recipient detected end of ICE candidates");return}let y=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",y),i.write({type:Mt.Type.ICE_CANDIDATE,data:y},{signal:n}).catch(b=>{o.error("error sending ICE candidate - %e",b)})},o.trace("recipient read SDP offer");let c=await i.read({signal:n});if(c.type!==Mt.Type.SDP_OFFER)throw new nr(`expected message type SDP_OFFER, received: ${c.type??"undefined"} `);o.trace("recipient received SDP offer %s",c.data);let f=new mf({type:"offer",sdp:c.data});await t.setRemoteDescription(f).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new nr("Failed to set remoteDescription")});let p=await t.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new nr("Failed to create answer")});o.trace("recipient send SDP answer %s",p.sdp),await i.write({type:Mt.Type.SDP_ANSWER,data:p.sdp},{signal:n}),await t.setLocalDescription(p).catch(h=>{throw o.error("could not execute setLocalDescription",h),new nr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await wf(t,i,{direction:"recipient",signal:n,log:o})}catch(c){if(t.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",e.remoteAddr,c),t.close(),c;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",e.remoteAddr,c)}let s=xf(e.remoteAddr),a=As(`/webrtc/p2p/${s}`);return o.trace("recipient connected to remote address %s",a),{remoteAddress:a,remotePeer:s}}var Af=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"})})}[hl]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Yi]=["@libp2p/transport"];[Zg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(uc,(e,t)=>{let n=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t,n).catch(o=>{this.log.error("failed to handle incoming connect from %p",t.remotePeer,o)}).finally(()=>{n.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(uc),this._started=!1}createListener(e){return new vf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Tw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await vm(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=mc({peerConnection:o,remoteAddr:n,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,remotePeer:xf(e),muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol(e,t,n){let o=new df(await vm(this.init.rtcConfiguration));o.addEventListener("connectionstatechange",()=>{switch(o.connectionState){case"closed":o.close();break;default:break}});let i=new eo({peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s,remotePeer:a}=await Qw(e,t,{peerConnection:o,signal:n,log:this.log});await e.close({signal:n});let c=mc({peerConnection:o,remoteAddr:s,metrics:this.metrics?.listenerEvents,direction:"inbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")});await this.components.upgrader.upgradeInbound(c,{skipEncryption:!0,skipProtection:!0,remotePeer:a,muxerFactory:i,signal:n}),this._closeOnShutdown(o,c)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),e.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 Yw(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new xe("Destination peer id was missing");return{circuitAddress:As(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:gs(e)}}var ez=Rr(tx());var Fr={};vt(Fr,{Any:()=>Vr,BaseBlock:()=>Je,BaseStringBlock:()=>wc,BitString:()=>Br,BmpString:()=>ti,Boolean:()=>Jo,CharacterString:()=>li,Choice:()=>ks,Constructed:()=>Qe,DATE:()=>_c,DateTime:()=>Bc,Duration:()=>Ic,EndOfContent:()=>xc,Enumerated:()=>Qo,GeneralString:()=>ui,GeneralizedTime:()=>fi,GraphicString:()=>ci,HexBlock:()=>$r,IA5String:()=>ai,Integer:()=>vn,Null:()=>_r,NumericString:()=>ni,ObjectIdentifier:()=>ei,OctetString:()=>Cr,Primitive:()=>xn,PrintableString:()=>oi,RawData:()=>Im,RelativeObjectIdentifier:()=>Ec,Repeated:()=>hi,Sequence:()=>Ct,Set:()=>Pt,TIME:()=>Tc,TeletexString:()=>ii,TimeOfDay:()=>Cc,UTCTime:()=>oo,UniversalString:()=>ri,Utf8String:()=>ir,ValueBlock:()=>pt,VideotexString:()=>si,ViewWriter:()=>Ts,VisibleString:()=>no,compareSchema:()=>bn,fromBER:()=>Sn,verifySchema:()=>gC});var ye=Rr(gn());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 ro(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 f=new Uint8Array(c);for(let p=a-1;p>=0;p--){let h=Math.pow(2,p*e);f[i-p-1]=Math.floor(o/h),o-=f[i-p-1]*h}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function _f(...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 Cm(){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 rx(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=ro(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ro(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 nx(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function jt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var hN=Math.log(2);function Cf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Tm(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 An(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 Tm(this.items)}},yc=[new Uint8Array([1])],ox="0123456789",Bm="name",ix="valueHexView",iC="isHexOnly",sC="idBlock",aC="tagClass",cC="tagNumber",uC="isConstructed",lC="fromBER",fC="toBER",hC="local",Kt="",Ir=new ArrayBuffer(0),Hf=new Uint8Array(0),bc="EndOfContent",ax="OCTET STRING",cx="BIT STRING";function $r(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?ye.BufferSourceConverter.toUint8Array(i.valueHex):Hf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!An(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",Ir)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ye.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wn=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=Hf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ye.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ye.Convert.ToHex(this.valueBeforeDecodeView)}}};wn.NAME="baseBlock";var pt=class extends wn{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 Bf=class extends $r(wn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?ye.BufferSourceConverter.toUint8Array(e.valueHex):Hf,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",Ir}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=ro(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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,f=this.valueHexView=new Uint8Array(255),p=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===p){p+=255;let y=new Uint8Array(p);for(let b=0;b<f.length;b++)y[b]=f[b];f=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,f[c-1]=i[c]&127;let h=new Uint8Array(c);for(let y=0;y<c;y++)h[y]=f[y];f=this.valueHexView=new Uint8Array(c),f.set(h),this.blockLength<=9?this.tagNumber=Yo(f,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}}};Bf.NAME="identificationBlock";var If=class extends wn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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=ro(this.length,8);if(o.byteLength>127)return this.error="Too big length",Ir;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}}};If.NAME="lengthBlock";var X={},Je=class extends wn{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 Bf(o),this.lenBlock=new If(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||ux(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?Ir:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():ye.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ye.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return nx(t,n)}};Je.NAME="BaseBlock";function ux(r){var e;if(r instanceof X.Constructed)for(let t of r.valueBlock.value)ux(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var wc=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}'`}};wc.NAME="BaseStringBlock";var Tf=class extends $r(pt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Tf.NAME="PrimitiveValueBlock";var lx,xn=class extends Je{constructor(e={}){super(e,Tf),this.idBlock.isConstructed=!1}};lx=xn;X.Primitive=lx;xn.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 wn;if(!An(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=X.EndOfContent;break;case 1:c=X.Boolean;break;case 2:c=X.Integer;break;case 3:c=X.BitString;break;case 4:c=X.OctetString;break;case 5:c=X.Null;break;case 6:c=X.ObjectIdentifier;break;case 10:c=X.Enumerated;break;case 12:c=X.Utf8String;break;case 13:c=X.RelativeObjectIdentifier;break;case 14:c=X.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=X.Sequence;break;case 17:c=X.Set;break;case 18:c=X.NumericString;break;case 19:c=X.PrintableString;break;case 20:c=X.TeletexString;break;case 21:c=X.VideotexString;break;case 22:c=X.IA5String;break;case 23:c=X.UTCTime;break;case 24:c=X.GeneralizedTime;break;case 25:c=X.GraphicString;break;case 26:c=X.VisibleString;break;case 27:c=X.GeneralString;break;case 28:c=X.UniversalString;break;case 29:c=X.CharacterString;break;case 30:c=X.BmpString;break;case 31:c=X.DATE;break;case 32:c=X.TimeOfDay;break;case 33:c=X.DateTime;break;case 34:c=X.Duration;break;default:{let f=o.idBlock.isConstructed?new X.Constructed:new X.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?X.Constructed:X.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 Sn(r){if(!r.byteLength){let e=new Je({},pt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Os(ye.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function dC(r,e){return r?1:e}var Hr=class extends pt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;dC(this.isIndefiniteForm,n)>0;){let s=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===bc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===bc?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?Ir:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Hr.NAME="ConstructedValueBlock";var fx,Qe=class extends Je{constructor(e={}){super(e,Hr),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 oS=Object.create;var Qu=Object.defineProperty;var iS=Object.getOwnPropertyDescriptor;var sS=Object.getOwnPropertyNames;var aS=Object.getPrototypeOf,cS=Object.prototype.hasOwnProperty;var np=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),vt=(r,e)=>{for(var t in e)Qu(r,t,{get:e[t],enumerable:!0})},zg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of sS(e))!cS.call(r,o)&&o!==t&&Qu(r,o,{get:()=>e[o],enumerable:!(n=iS(e,o))||n.enumerable});return r};var Rr=(r,e,t)=>(t=r!=null?oS(aS(r)):{},zg(e||!r||!r.__esModule?Qu(t,"default",{value:r,enumerable:!0}):t,r)),uS=r=>zg(Qu({},"__esModule",{value:!0}),r);var tx=np(()=>{var ex;(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,f){return function(p,h){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:h}),f&&f(p,h)}}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,f=!a&&!c,p={create:a?function(){return rp(Object.create(null))}:c?function(){return rp({__proto__:null})}:function(){return rp({})},has:f?function(w,E){return n.call(w,E)}:function(w,E){return E in w},get:f?function(w,E){return n.call(w,E)?w[E]:void 0}:function(w,E){return w[E]}},h=Object.getPrototypeOf(Function),y=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:QA(),b=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:eS(),g=typeof WeakMap=="function"?WeakMap:tS(),C=o?Symbol.for("@reflect-metadata:registry"):void 0,m=ZA(),S=YA(m);function N(w,E,P,$){if(O(P)){if(!rn(w))throw new TypeError;if(!jn(E))throw new TypeError;return V(w,E)}else{if(!rn(w))throw new TypeError;if(!ee(E))throw new TypeError;if(!ee($)&&!O($)&&!pe($))throw new TypeError;return pe($)&&($=void 0),P=Ie(P),B(w,E,P,$)}}e("decorate",N);function I(w,E){function P($,se){if(!ee($))throw new TypeError;if(!O(se)&&!Ju(se))throw new TypeError;L(w,E,$,se)}return P}e("metadata",I);function K(w,E,P,$){if(!ee(P))throw new TypeError;return O($)||($=Ie($)),L(w,E,P,$)}e("defineMetadata",K);function Z(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),A(w,E,P)}e("hasMetadata",Z);function q(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),v(w,E,P)}e("hasOwnMetadata",q);function re(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),D(w,E,P)}e("getMetadata",re);function R(w,E,P){if(!ee(E))throw new TypeError;return O(P)||(P=Ie(P)),U(w,E,P)}e("getOwnMetadata",R);function k(w,E){if(!ee(w))throw new TypeError;return O(E)||(E=Ie(E)),T(w,E)}e("getMetadataKeys",k);function G(w,E){if(!ee(w))throw new TypeError;return O(E)||(E=Ie(E)),M(w,E)}e("getOwnMetadataKeys",G);function Y(w,E,P){if(!ee(E))throw new TypeError;if(O(P)||(P=Ie(P)),!ee(E))throw new TypeError;O(P)||(P=Ie(P));var $=Sa(E,P,!1);return O($)?!1:$.OrdinaryDeleteMetadata(w,E,P)}e("deleteMetadata",Y);function V(w,E){for(var P=w.length-1;P>=0;--P){var $=w[P],se=$(E);if(!O(se)&&!pe(se)){if(!jn(se))throw new TypeError;E=se}}return E}function B(w,E,P,$){for(var se=w.length-1;se>=0;--se){var Xe=w[se],tt=Xe(E,P,$);if(!O(tt)&&!pe(tt)){if(!ee(tt))throw new TypeError;$=tt}}return $}function A(w,E,P){var $=v(w,E,P);if($)return!0;var se=tp(E);return pe(se)?!1:A(w,se,P)}function v(w,E,P){var $=Sa(E,P,!1);return O($)?!1:Ke($.OrdinaryHasOwnMetadata(w,E,P))}function D(w,E,P){var $=v(w,E,P);if($)return U(w,E,P);var se=tp(E);if(!pe(se))return D(w,se,P)}function U(w,E,P){var $=Sa(E,P,!1);if(!O($))return $.OrdinaryGetOwnMetadata(w,E,P)}function L(w,E,P,$){var se=Sa(P,$,!0);se.OrdinaryDefineOwnMetadata(w,E,P,$)}function T(w,E){var P=M(w,E),$=tp(w);if($===null)return P;var se=T($,E);if(se.length<=0)return P;if(P.length<=0)return se;for(var Xe=new b,tt=[],we=0,z=P;we<z.length;we++){var J=z[we],te=Xe.has(J);te||(Xe.add(J),tt.push(J))}for(var ne=0,ve=se;ne<ve.length;ne++){var J=ve[ne],te=Xe.has(J);te||(Xe.add(J),tt.push(J))}return tt}function M(w,E){var P=Sa(w,E,!1);return P?P.OrdinaryOwnMetadataKeys(w,E):[]}function W(w){if(w===null)return 1;switch(typeof w){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return w===null?1:6;default:return 6}}function O(w){return w===void 0}function pe(w){return w===null}function be(w){return typeof w=="symbol"}function ee(w){return typeof w=="object"?w!==null:typeof w=="function"}function Ae(w,E){switch(W(w)){case 0:return w;case 1:return w;case 2:return w;case 3:return w;case 4:return w;case 5:return w}var P=E===3?"string":E===5?"number":"default",$=Aa(w,i);if($!==void 0){var se=$.call(w,P);if(ee(se))throw new TypeError;return se}return Be(w,P==="default"?"number":P)}function Be(w,E){if(E==="string"){var P=w.toString;if(pr(P)){var $=P.call(w);if(!ee($))return $}var se=w.valueOf;if(pr(se)){var $=se.call(w);if(!ee($))return $}}else{var se=w.valueOf;if(pr(se)){var $=se.call(w);if(!ee($))return $}var Xe=w.toString;if(pr(Xe)){var $=Xe.call(w);if(!ee($))return $}}throw new TypeError}function Ke(w){return!!w}function Ee(w){return""+w}function Ie(w){var E=Ae(w,3);return be(E)?E:Ee(E)}function rn(w){return Array.isArray?Array.isArray(w):w instanceof Object?w instanceof Array:Object.prototype.toString.call(w)==="[object Array]"}function pr(w){return typeof w=="function"}function jn(w){return typeof w=="function"}function Ju(w){switch(W(w)){case 3:return!0;case 4:return!0;default:return!1}}function Gi(w,E){return w===E||w!==w&&E!==E}function Aa(w,E){var P=w[E];if(P!=null){if(!pr(P))throw new TypeError;return P}}function $g(w){var E=Aa(w,s);if(!pr(E))throw new TypeError;var P=E.call(w);if(!ee(P))throw new TypeError;return P}function Fg(w){return w.value}function Wg(w){var E=w.next();return E.done?!1:E}function qg(w){var E=w.return;E&&E.call(w)}function tp(w){var E=Object.getPrototypeOf(w);if(typeof w!="function"||w===h||E!==h)return E;var P=w.prototype,$=P&&Object.getPrototypeOf(P);if($==null||$===Object.prototype)return E;var se=$.constructor;return typeof se!="function"||se===w?E:se}function XA(){var w;!O(C)&&typeof t.Reflect<"u"&&!(C in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(w=JA(t.Reflect));var E,P,$,se=new g,Xe={registerProvider:tt,getProvider:z,setProvider:te};return Xe;function tt(ne){if(!Object.isExtensible(Xe))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case w===ne:break;case O(E):E=ne;break;case E===ne:break;case O(P):P=ne;break;case P===ne:break;default:$===void 0&&($=new b),$.add(ne);break}}function we(ne,ve){if(!O(E)){if(E.isProviderFor(ne,ve))return E;if(!O(P)){if(P.isProviderFor(ne,ve))return E;if(!O($))for(var Re=$g($);;){var Ze=Wg(Re);if(!Ze)return;var dr=Fg(Ze);if(dr.isProviderFor(ne,ve))return qg(Re),dr}}}if(!O(w)&&w.isProviderFor(ne,ve))return w}function z(ne,ve){var Re=se.get(ne),Ze;return O(Re)||(Ze=Re.get(ve)),O(Ze)&&(Ze=we(ne,ve),O(Ze)||(O(Re)&&(Re=new y,se.set(ne,Re)),Re.set(ve,Ze))),Ze}function J(ne){if(O(ne))throw new TypeError;return E===ne||P===ne||!O($)&&$.has(ne)}function te(ne,ve,Re){if(!J(Re))throw new Error("Metadata provider not registered.");var Ze=z(ne,ve);if(Ze!==Re){if(!O(Ze))return!1;var dr=se.get(ne);O(dr)&&(dr=new y,se.set(ne,dr)),dr.set(ve,Re)}return!0}}function ZA(){var w;return!O(C)&&ee(t.Reflect)&&Object.isExtensible(t.Reflect)&&(w=t.Reflect[C]),O(w)&&(w=XA()),!O(C)&&ee(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,C,{enumerable:!1,configurable:!1,writable:!1,value:w}),w}function YA(w){var E=new g,P={isProviderFor:function(J,te){var ne=E.get(J);return O(ne)?!1:ne.has(te)},OrdinaryDefineOwnMetadata:tt,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Xe,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:z};return m.registerProvider(P),P;function $(J,te,ne){var ve=E.get(J),Re=!1;if(O(ve)){if(!ne)return;ve=new y,E.set(J,ve),Re=!0}var Ze=ve.get(te);if(O(Ze)){if(!ne)return;if(Ze=new y,ve.set(te,Ze),!w.setProvider(J,te,P))throw ve.delete(te),Re&&E.delete(J),new Error("Wrong provider for target.")}return Ze}function se(J,te,ne){var ve=$(te,ne,!1);return O(ve)?!1:Ke(ve.has(J))}function Xe(J,te,ne){var ve=$(te,ne,!1);if(!O(ve))return ve.get(J)}function tt(J,te,ne,ve){var Re=$(ne,ve,!0);Re.set(J,te)}function we(J,te){var ne=[],ve=$(J,te,!1);if(O(ve))return ne;for(var Re=ve.keys(),Ze=$g(Re),dr=0;;){var Gg=Wg(Ze);if(!Gg)return ne.length=dr,ne;var rS=Fg(Gg);try{ne[dr]=rS}catch(nS){try{qg(Ze)}finally{throw nS}}dr++}}function z(J,te,ne){var ve=$(te,ne,!1);if(O(ve)||!ve.delete(J))return!1;if(ve.size===0){var Re=E.get(te);O(Re)||(Re.delete(ne),Re.size===0&&E.delete(Re))}return!0}}function JA(w){var E=w.defineMetadata,P=w.hasOwnMetadata,$=w.getOwnMetadata,se=w.getOwnMetadataKeys,Xe=w.deleteMetadata,tt=new g,we={isProviderFor:function(z,J){var te=tt.get(z);return!O(te)&&te.has(J)?!0:se(z,J).length?(O(te)&&(te=new b,tt.set(z,te)),te.add(J),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:P,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Xe};return we}function Sa(w,E,P){var $=m.getProvider(w,E);if(!O($))return $;if(P){if(m.setProvider(w,E,S))return S;throw new Error("Illegal state.")}}function QA(){var w={},E=[],P=(function(){function we(z,J,te){this._index=0,this._keys=z,this._values=J,this._selector=te}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var z=this._index;if(z>=0&&z<this._keys.length){var J=this._selector(this._keys[z],this._values[z]);return z+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(z){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),z},we.prototype.return=function(z){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:z,done:!0}},we})(),$=(function(){function we(){this._keys=[],this._values=[],this._cacheKey=w,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(z){return this._find(z,!1)>=0},we.prototype.get=function(z){var J=this._find(z,!1);return J>=0?this._values[J]:void 0},we.prototype.set=function(z,J){var te=this._find(z,!0);return this._values[te]=J,this},we.prototype.delete=function(z){var J=this._find(z,!1);if(J>=0){for(var te=this._keys.length,ne=J+1;ne<te;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Gi(z,this._cacheKey)&&(this._cacheKey=w,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=w,this._cacheIndex=-2},we.prototype.keys=function(){return new P(this._keys,this._values,se)},we.prototype.values=function(){return new P(this._keys,this._values,Xe)},we.prototype.entries=function(){return new P(this._keys,this._values,tt)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(z,J){if(!Gi(this._cacheKey,z)){this._cacheIndex=-1;for(var te=0;te<this._keys.length;te++)if(Gi(this._keys[te],z)){this._cacheIndex=te;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(z),this._values.push(void 0)),this._cacheIndex},we})();return $;function se(we,z){return we}function Xe(we,z){return z}function tt(we,z){return[we,z]}}function eS(){var w=(function(){function E(){this._map=new y}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(P){return this._map.has(P)},E.prototype.add=function(P){return this._map.set(P,P),this},E.prototype.delete=function(P){return this._map.delete(P)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E})();return w}function tS(){var w=16,E=p.create(),P=$();return(function(){function z(){this._key=$()}return z.prototype.has=function(J){var te=se(J,!1);return te!==void 0?p.has(te,this._key):!1},z.prototype.get=function(J){var te=se(J,!1);return te!==void 0?p.get(te,this._key):void 0},z.prototype.set=function(J,te){var ne=se(J,!0);return ne[this._key]=te,this},z.prototype.delete=function(J){var te=se(J,!1);return te!==void 0?delete te[this._key]:!1},z.prototype.clear=function(){this._key=$()},z})();function $(){var z;do z="@@WeakMap@@"+we();while(p.has(E,z));return E[z]=!0,z}function se(z,J){if(!n.call(z,P)){if(!J)return;Object.defineProperty(z,P,{value:p.create()})}return z[P]}function Xe(z,J){for(var te=0;te<J;++te)z[te]=Math.random()*255|0;return z}function tt(z){if(typeof Uint8Array=="function"){var J=new Uint8Array(z);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Xe(J,z),J}return Xe(new Array(z),z)}function we(){var z=tt(w);z[6]=z[6]&79|64,z[8]=z[8]&191|128;for(var J="",te=0;te<w;++te){var ne=z[te];(te===4||te===6||te===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function rp(w){return w.__=void 0,delete w.__,w}})})(ex||(ex={}))});var gn=np(Is=>{"use strict";var Y2="[object ArrayBuffer]",yn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Y2}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}},_m="string",J2=/^[0-9a-f\s]+$/i,Q2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,eC=/^[a-zA-Z0-9-_]+$/,Sf=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=yn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},or=class{static toString(e,t=!1){let n=yn.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}},Ef=class r{static isHex(e){return typeof e===_m&&J2.test(e)}static isBase64(e){return typeof e===_m&&Q2.test(e)}static isBase64Url(e){return typeof e===_m&&eC.test(e)}static ToString(e,t="utf8"){let n=yn.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 or.toString(n,!0);case"utf16":case"utf16be":return or.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 or.fromString(e,!0);case"utf16":case"utf16be":return or.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=yn.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 Sf.fromString(e);case"utf16":case"utf16be":return or.fromString(e);case"utf16le":case"usc2":return or.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 Sf.toString(e);case"utf16":case"utf16be":return or.toString(e);case"utf16le":case"usc2":return or.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=yn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=yn.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 or.toString(e,t)}static FromUtf16String(e,t=!1){return or.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,"")||""}};Ef.DEFAULT_UTF8_ENCODING="utf8";function tC(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 rC(...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 nC(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}Is.BufferSourceConverter=yn;Is.Convert=Ef;Is.assign=tC;Is.combine=rC;Is.isEqual=nC});var Xv=np((D7,bh)=>{var Tv,kv,Ov,Pv,Nv,Dv,Rv,Lv,Uv,gh,Ny,Mv,jv,na,Kv,Hv,Vv,$v,Fv,Wv,qv,Gv,zv;(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 bh=="object"&&typeof bh.exports=="object"?r(t(e,t(bh.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])};Tv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},kv=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},Ov=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},Pv=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 f=t.length-1;f>=0;f--)(c=t[f])&&(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},Nv=function(t,n){return function(o,i){n(o,i,t)}},Dv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Rv=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 f(y){try{h(i.next(y))}catch(b){c(b)}}function p(y){try{h(i.throw(y))}catch(b){c(b)}}function h(y){y.done?a(y.value):s(y.value).then(f,p)}h((i=i.apply(t,n||[])).next())})},Lv=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:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function f(h){return function(y){return p([h,y])}}function p(h){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=h[0]&2?s.return:h[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,h[1])).done)return a;switch(s=0,a&&(h=[h[0]&2,a.value]),h[0]){case 0:case 1:a=h;break;case 4:return o.label++,{value:h[1],done:!1};case 5:o.label++,s=h[1],h=[0];continue;case 7:h=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(h[0]===6||h[0]===2)){o=0;continue}if(h[0]===3&&(!a||h[1]>a[0]&&h[1]<a[3])){o.label=h[1];break}if(h[0]===6&&o.label<a[1]){o.label=a[1],a=h;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(h);break}a[2]&&o.ops.pop(),o.trys.pop();continue}h=n.call(t,o)}catch(y){h=[6,y],s=0}finally{i=a=0}if(h[0]&5)throw h[1];return{value:h[0]?h[1]:void 0,done:!0}}},zv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Uv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},gh=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.")},Ny=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(f){c={error:f}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mv=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Ny(arguments[n]));return t},jv=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,f=a.length;c<f;c++,s++)i[s]=a[c];return i},na=function(t){return this instanceof na?(this.v=t,this):new na(t)},Kv=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(C){return new Promise(function(m,S){a.push([g,C,m,S])>1||f(g,C)})})}function f(g,C){try{p(i[g](C))}catch(m){b(a[0][3],m)}}function p(g){g.value instanceof na?Promise.resolve(g.value.v).then(h,y):b(a[0][2],g)}function h(g){f("next",g)}function y(g){f("throw",g)}function b(g,C){g(C),a.shift(),a.length&&f(a[0][0],a[0][1])}},Hv=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:na(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Vv=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 gh=="function"?gh(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(f,p){c=t[a](c),s(f,p,c.done,c.value)})}}function s(a,c,f,p){Promise.resolve(p).then(function(h){a({value:h,done:f})},c)}},$v=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Fv=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},Wv=function(t){return t&&t.__esModule?t:{default:t}},qv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Gv=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",Tv),r("__assign",kv),r("__rest",Ov),r("__decorate",Pv),r("__param",Nv),r("__metadata",Dv),r("__awaiter",Rv),r("__generator",Lv),r("__exportStar",Uv),r("__createBinding",zv),r("__values",gh),r("__read",Ny),r("__spread",Mv),r("__spreadArrays",jv),r("__await",na),r("__asyncGenerator",Kv),r("__asyncDelegator",Hv),r("__asyncValues",Vv),r("__makeTemplateObject",$v),r("__importStar",Fv),r("__importDefault",Wv),r("__classPrivateFieldGet",qv),r("__classPrivateFieldSet",Gv)})});var pI={};vt(pI,{webRTC:()=>hI,webRTCDirect:()=>fI});var el=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},tl=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},xe=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ea=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var rl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},nl=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},Xi=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var nn=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},_a=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},To=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var ol=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},il=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},sl=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var al=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var cl=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Kn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var ul=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},Zi=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},ll=class extends Zi{constructor(e,t){super(!0,e,t)}},fl=class extends Zi{constructor(e,t){super(!1,e,t)}};var op=Symbol.for("@libp2p/peer-id");var hl=Symbol.for("@libp2p/transport");var Xg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Xg||(Xg={}));var er=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 Yi=Symbol.for("@libp2p/service-capabilities"),Zg=Symbol.for("@libp2p/service-dependencies");var up={};vt(up,{base58btc:()=>Fe,base58flickr:()=>yS});var WI=new Uint8Array(0);function Yg(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function on(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Jg(r){return new TextEncoder().encode(r)}function Qg(r){return new TextDecoder().decode(r)}function lS(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),f=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function h(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var C=0,m=0,S=0,N=g.length;S!==N&&g[S]===0;)S++,C++;for(var I=(N-S)*p+1>>>0,K=new Uint8Array(I);S!==N;){for(var Z=g[S],q=0,re=I-1;(Z!==0||q<m)&&re!==-1;re--,q++)Z+=256*K[re]>>>0,K[re]=Z%a>>>0,Z=Z/a>>>0;if(Z!==0)throw new Error("Non-zero carry");m=q,S++}for(var R=I-m;R!==I&&K[R]===0;)R++;for(var k=c.repeat(C);R<I;++R)k+=r.charAt(K[R]);return k}function y(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var C=0;if(g[C]!==" "){for(var m=0,S=0;g[C]===c;)m++,C++;for(var N=(g.length-C)*f+1>>>0,I=new Uint8Array(N);g[C];){var K=t[g.charCodeAt(C)];if(K===255)return;for(var Z=0,q=N-1;(K!==0||Z<S)&&q!==-1;q--,Z++)K+=a*I[q]>>>0,I[q]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");S=Z,C++}if(g[C]!==" "){for(var re=N-S;re!==N&&I[re]===0;)re++;for(var R=new Uint8Array(m+(N-re)),k=m;re!==N;)R[k++]=I[re++];return R}}}function b(g){var C=y(g);if(C)return C;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:y,decode:b}}var fS=lS,hS=fS,t0=hS;var ip=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")}},sp=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 r0(this,e)}},ap=class{decoders;constructor(e){this.decoders=e}or(e){return r0(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 r0(r,e){return new ap({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var cp=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ip(e,t,n),this.decoder=new sp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ji({name:r,prefix:e,encode:t,decode:n}){return new cp(r,e,t,n)}function Hn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=t0(t,r);return Ji({prefix:e,name:r,encode:n,decode:i=>on(o(i))})}function pS(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 f=0;f<o;++f){let p=e[r[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|p,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function dS(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 mS(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=mS(n);return Ji({prefix:e,name:r,encode(i){return dS(i,n,t)},decode(i){return pS(i,o,t,r)}})}var Fe=Hn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yS=Hn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lp={};vt(lp,{base32:()=>Vn,base32hex:()=>xS,base32hexpad:()=>AS,base32hexpadupper:()=>SS,base32hexupper:()=>vS,base32pad:()=>bS,base32padupper:()=>wS,base32upper:()=>gS,base32z:()=>ES});var Vn=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),gS=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),bS=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),wS=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xS=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vS=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),AS=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),SS=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ES=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fp={};vt(fp,{base36:()=>Ca,base36upper:()=>_S});var Ca=Hn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_S=Hn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mr={};vt(mr,{Digest:()=>ko,create:()=>It,decode:()=>ts,equals:()=>pp,hasCode:()=>FS});var CS=i0,n0=128,BS=127,IS=~BS,TS=Math.pow(2,31);function i0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=TS;)e[t++]=r&255|n0,r/=128;for(;r&IS;)e[t++]=r&255|n0,r>>>=7;return e[t]=r|0,i0.bytes=t-n+1,e}var kS=hp,OS=128,o0=127;function hp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw hp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&o0)<<o:(s&o0)*Math.pow(2,o),o+=7}while(s>=OS);return hp.bytes=i-n,t}var PS=Math.pow(2,7),NS=Math.pow(2,14),DS=Math.pow(2,21),RS=Math.pow(2,28),LS=Math.pow(2,35),US=Math.pow(2,42),MS=Math.pow(2,49),jS=Math.pow(2,56),KS=Math.pow(2,63),HS=function(r){return r<PS?1:r<NS?2:r<DS?3:r<RS?4:r<LS?5:r<US?6:r<MS?7:r<jS?8:r<KS?9:10},VS={encode:CS,decode:kS,encodingLength:HS},$S=VS,Ba=$S;function Ia(r,e=0){return[Ba.decode(r,e),Ba.decode.bytes]}function Qi(r,e,t=0){return Ba.encode(r,e,t),e}function es(r){return Ba.encodingLength(r)}function It(r,e){let t=e.byteLength,n=es(r),o=n+es(t),i=new Uint8Array(o+t);return Qi(r,i,0),Qi(t,i,n),i.set(e,o),new ko(r,t,e,i)}function ts(r){let e=on(r),[t,n]=Ia(e),[o,i]=Ia(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ko(t,o,s,e)}function pp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Yg(r.bytes,t.bytes)}}var ko=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function FS(r,e){return r.code===e}function s0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return qS(t,dp(r),e??Fe.encoder);default:return GS(t,dp(r),e??Vn.encoder)}}var a0=new WeakMap;function dp(r){let e=a0.get(r);if(e==null){let t=new Map;return a0.set(r,t),t}return e}var rt=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!==Ta)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zS)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=It(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&pp(e.multihash,n.multihash)}toString(e){return s0(this,e)}toJSON(){return{"/":s0(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??c0(n,o,i.bytes))}else if(t[XS]===!0){let{version:n,multihash:o,code:i}=t,s=ts(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!==Ta)throw new Error(`Version 0 CID must use dag-pb (code: ${Ta}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=c0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ta,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=on(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new ko(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,y]=Ia(e.subarray(t));return t+=y,h},o=n(),i=Ta;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(),f=t+c,p=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:f}}static parse(e,t){let[n,o]=WS(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 dp(i).set(n,e),i}};function WS(r,e){switch(r[0]){case"Q":{let t=e??Fe;return[Fe.prefix,t.decode(`${Fe.prefix}${r}`)]}case Fe.prefix:{let t=e??Fe;return[Fe.prefix,t.decode(r)]}case Vn.prefix:{let t=e??Vn;return[Vn.prefix,t.decode(r)]}case Ca.prefix:{let t=e??Ca;return[Ca.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 qS(r,e,t){let{prefix:n}=t;if(n!==Fe.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 GS(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 Ta=112,zS=18;function c0(r,e,t){let n=es(r),o=n+es(e),i=new Uint8Array(o+t.byteLength);return Qi(r,i,0),Qi(e,i,n),i.set(t,o),i}var XS=Symbol.for("@ipld/js-cid/CID");var mp={};vt(mp,{identity:()=>yr});var u0=0,ZS="identity",l0=on;function YS(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return It(u0,l0(r))}var yr={code:u0,name:ZS,encode:l0,digest:YS};function We(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function nt(r=0){return new Uint8Array(r)}function ot(r=0){return new Uint8Array(r)}function Tt(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 h0=Symbol.for("@achingbrain/uint8arraylist");function f0(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 dl(r){return!!r?.[h0]}var me=class r{bufs;length;[h0]=!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(dl(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(dl(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=f0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=f0(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(dl(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 Tt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Tt(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 f=e>=a&&e<c,p=t>a&&t<=c;if(f&&p){if(e===a&&t===c){n.push(s);break}let h=e-a;n.push(s.subarray(h,h+(t-e)));break}if(f){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(p){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!dl(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 h=0;h<i;h++)s[h]=-1;for(let h=0;h<o;h++)s[n[h]]=h;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let h=t;h<=c;h+=p){p=0;for(let y=f;y>=0;y--){let b=this.get(h+y);if(n[y]!==b){p=Math.max(1,y-a[b]);break}}if(p===0)return h}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(!We(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var yp={};vt(yp,{base10:()=>QS});var QS=Hn({prefix:"9",name:"base10",alphabet:"0123456789"});var gp={};vt(gp,{base16:()=>eE,base16upper:()=>tE});var eE=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tE=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bp={};vt(bp,{base2:()=>rE});var rE=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wp={};vt(wp,{base256emoji:()=>aE});var p0=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}"),nE=p0.reduce((r,e,t)=>(r[t]=e,r),[]),oE=p0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function iE(r){return r.reduce((e,t)=>(e+=nE[t],e),"")}function sE(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=oE[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var aE=Ji({prefix:"\u{1F680}",name:"base256emoji",encode:iE,decode:sE});var xp={};vt(xp,{base64:()=>cE,base64pad:()=>uE,base64url:()=>Oo,base64urlpad:()=>lE});var cE=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uE=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Oo=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lE=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vp={};vt(vp,{base8:()=>fE});var fE=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ap={};vt(Ap,{identity:()=>hE});var hE=Ji({prefix:"\0",name:"identity",encode:r=>Qg(r),decode:r=>Jg(r)});var BT=new TextEncoder,IT=new TextDecoder;var _p={};vt(_p,{sha256:()=>tr,sha512:()=>yE});var mE=20;function Ep({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Sp(r,e,t,n,o)}var Sp=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??mE,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?d0(n,this.code,t?.truncate):n.then(o=>d0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function d0(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return It(e,r)}function y0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Ep({name:"sha2-256",code:18,encode:y0("SHA-256")}),yE=Ep({name:"sha2-512",code:19,encode:y0("SHA-512")});var Po={...Ap,...bp,...vp,...yp,...gp,...lp,...fp,...up,...xp,...wp},KT={..._p,...mp};function b0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var g0=b0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Cp=b0("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}),gE={utf8:g0,"utf-8":g0,hex:Po.base16,latin1:Cp,ascii:Cp,binary:Cp,...Po},ml=gE;function de(r,e="utf8"){let t=ml[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=ml[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var bE=parseInt("11111",2),Bp=parseInt("10000000",2),wE=parseInt("01111111",2),w0={0:ka,1:ka,2:xE,3:SE,4:EE,5:AE,6:vE,16:ka,22:ka,48:ka};function sn(r,e={offset:0}){let t=r[e.offset]&bE;if(e.offset++,w0[t]!=null)return w0[t](r,e);throw new Error("No decoder for tag "+t)}function Oa(r,e){let t=0;if((r[e.offset]&Bp)===Bp){let n=r[e.offset]&wE,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 ka(r,e){Oa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=sn(r,e);if(n===null)break;t.push(n)}return t}function xE(r,e){let t=Oa(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 vE(r,e){let t=Oa(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 f=r[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let p=0;for(let h=0;h<c.length;h++)p+=c[h]<<h*7;a+=`.${p}`,c=[]}}return a}function AE(r,e){return e.offset++,null}function SE(r,e){let t=Oa(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 EE(r,e){let t=Oa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function _E(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new me;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function yl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=_E(r.byteLength);return new me(Uint8Array.from([e.byteLength|Bp]),e)}function kt(r){let e=new me,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new me(Uint8Array.from([2]),yl(e),e)}function Pa(r){let e=Uint8Array.from([0]),t=new me(e,r);return new me(Uint8Array.from([3]),yl(t),t)}function x0(r){return new me(Uint8Array.from([4]),yl(r),r)}function gr(r,e=48){let t=new me;for(let n of r)t.append(n);return new me(Uint8Array.from([e]),yl(t),t)}async function v0(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 A0(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 S0(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 CE=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),BE=Uint8Array.from([6,5,43,129,4,0,34]),IE=Uint8Array.from([6,5,43,129,4,0,35]),TE={ext:!0,kty:"EC",crv:"P-256"},kE={ext:!0,kty:"EC",crv:"P-384"},OE={ext:!0,kty:"EC",crv:"P-521"},Ip=32,Tp=48,kp=66;function Op(r){let e=sn(r);return E0(e)}function E0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Ip*2+1)return n=ue(e.subarray(t,t+Ip),"base64url"),o=ue(e.subarray(t+Ip),"base64url"),new No({...TE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Tp*2+1)return n=ue(e.subarray(t,t+Tp),"base64url"),o=ue(e.subarray(t+Tp),"base64url"),new No({...kE,key_ops:["verify"],x:n,y:o});if(e.byteLength===kp*2+1)return n=ue(e.subarray(t,t+kp),"base64url"),o=ue(e.subarray(t+kp),"base64url"),new No({...OE,key_ops:["verify"],x:n,y:o});throw new xe(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function _0(r){return gr([kt(Uint8Array.from([1])),x0(de(r.d??"","base64url")),gr([B0(r.crv)],160),gr([Pa(new me(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function C0(r){return gr([kt(Uint8Array.from([1])),gr([B0(r.crv)],160),gr([Pa(new me(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function B0(r){if(r==="P-256")return CE;if(r==="P-384")return BE;if(r==="P-521")return IE;throw new xe(`Invalid curve ${r}`)}async function I0(r="P-256"){let e=await v0(r);return new gl(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=C0(this.jwk)),this._raw}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async verify(e,t,n){return S0(this.jwk,t,e,n)}},gl=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=_0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async sign(e,t){return A0(this.jwk,e,t)}};function Do(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function rr(r,e=""){if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new Error(`${t}expected integer >= 0, got ${r}`)}}function fe(r,e,t=""){let n=Do(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function Ro(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");rr(r.outputLen),rr(r.blockLen)}function rs(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 k0(r,e){fe(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new Error('"digestInto() output" expected to be of length >='+t)}function br(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function bl(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function wr(r,e){return r<<32-e|r>>>e}var O0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",PE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function cn(r){if(fe(r),O0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=PE[r[t]];return e}var an={_0:48,_9:57,A:65,F:70,a:97,f:102};function T0(r){if(r>=an._0&&r<=an._9)return r-an._0;if(r>=an.A&&r<=an.F)return r-(an.A-10);if(r>=an.a&&r<=an.f)return r-(an.a-10)}function un(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(O0)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=T0(r.charCodeAt(i)),a=T0(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 Lt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];fe(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}function Pp(r,e={}){let t=(o,i)=>r(i).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function Fn(r=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(r))}var Np=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function P0(r,e,t){return r&e^~r&t}function N0(r,e,t){return r&e^r&t^e&t}var Na=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=bl(this.buffer)}update(e){rs(this),fe(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=bl(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){rs(this),k0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,br(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let h=s;h<o;h++)t[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=bl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,p[h],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(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()}},ln=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var wl=BigInt(4294967295),D0=BigInt(32);function NE(r,e=!1){return e?{h:Number(r&wl),l:Number(r>>D0&wl)}:{h:Number(r>>D0&wl)|0,l:Number(r&wl)|0}}function R0(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}=NE(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Dp=(r,e,t)=>r>>>t,Rp=(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,Da=(r,e,t)=>r<<64-t|e>>>t-32,Ra=(r,e,t)=>r>>>t-32|e<<64-t;function Lr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var L0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),U0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,M0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),j0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,K0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),H0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var RE=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]),Wn=new Uint32Array(64),Lp=class extends Na{constructor(e){super(64,e,8,!1)}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 h=0;h<16;h++,t+=4)Wn[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let y=Wn[h-15],b=Wn[h-2],g=wr(y,7)^wr(y,18)^y>>>3,C=wr(b,17)^wr(b,19)^b>>>10;Wn[h]=C+Wn[h-7]+g+Wn[h-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:p}=this;for(let h=0;h<64;h++){let y=wr(a,6)^wr(a,11)^wr(a,25),b=p+y+P0(a,c,f)+RE[h]+Wn[h]|0,C=(wr(n,2)^wr(n,13)^wr(n,22))+N0(n,o,i)|0;p=f,f=c,c=a,a=s+b|0,s=i,i=o,o=n,n=b+C|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,f=f+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,f,p)}roundClean(){br(Wn)}destroy(){this.set(0,0,0,0,0,0,0,0),br(this.buffer)}},Up=class extends Lp{A=ln[0]|0;B=ln[1]|0;C=ln[2]|0;D=ln[3]|0;E=ln[4]|0;F=ln[5]|0;G=ln[6]|0;H=ln[7]|0;constructor(){super(32)}};var V0=R0(["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))),LE=V0[0],UE=V0[1],qn=new Uint32Array(80),Gn=new Uint32Array(80),Mp=class extends Na{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:p,Fh:h,Fl:y,Gh:b,Gl:g,Hh:C,Hl:m}=this;return[e,t,n,o,i,s,a,c,f,p,h,y,b,g,C,m]}set(e,t,n,o,i,s,a,c,f,p,h,y,b,g,C,m){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=p|0,this.Fh=h|0,this.Fl=y|0,this.Gh=b|0,this.Gl=g|0,this.Hh=C|0,this.Hl=m|0}process(e,t){for(let I=0;I<16;I++,t+=4)qn[I]=e.getUint32(t),Gn[I]=e.getUint32(t+=4);for(let I=16;I<80;I++){let K=qn[I-15]|0,Z=Gn[I-15]|0,q=Lo(K,Z,1)^Lo(K,Z,8)^Dp(K,Z,7),re=Uo(K,Z,1)^Uo(K,Z,8)^Rp(K,Z,7),R=qn[I-2]|0,k=Gn[I-2]|0,G=Lo(R,k,19)^Da(R,k,61)^Dp(R,k,6),Y=Uo(R,k,19)^Ra(R,k,61)^Rp(R,k,6),V=M0(re,Y,Gn[I-7],Gn[I-16]),B=j0(V,q,G,qn[I-7],qn[I-16]);qn[I]=B|0,Gn[I]=V|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:p,Eh:h,El:y,Fh:b,Fl:g,Gh:C,Gl:m,Hh:S,Hl:N}=this;for(let I=0;I<80;I++){let K=Lo(h,y,14)^Lo(h,y,18)^Da(h,y,41),Z=Uo(h,y,14)^Uo(h,y,18)^Ra(h,y,41),q=h&b^~h&C,re=y&g^~y&m,R=K0(N,Z,re,UE[I],Gn[I]),k=H0(R,S,K,q,LE[I],qn[I]),G=R|0,Y=Lo(n,o,28)^Da(n,o,34)^Da(n,o,39),V=Uo(n,o,28)^Ra(n,o,34)^Ra(n,o,39),B=n&i^n&a^i&a,A=o&s^o&c^s&c;S=C|0,N=m|0,C=b|0,m=g|0,b=h|0,g=y|0,{h,l:y}=Lr(f|0,p|0,k|0,G|0),f=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let v=L0(G,V,A);n=U0(v,k,Y,B),o=v|0}({h:n,l:o}=Lr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Lr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Lr(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:p}=Lr(this.Dh|0,this.Dl|0,f|0,p|0),{h,l:y}=Lr(this.Eh|0,this.El|0,h|0,y|0),{h:b,l:g}=Lr(this.Fh|0,this.Fl|0,b|0,g|0),{h:C,l:m}=Lr(this.Gh|0,this.Gl|0,C|0,m|0),{h:S,l:N}=Lr(this.Hh|0,this.Hl|0,S|0,N|0),this.set(n,o,i,s,a,c,f,p,h,y,b,g,C,m,S,N)}roundClean(){br(qn,Gn)}destroy(){br(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jp=class extends Mp{Ah=ft[0]|0;Al=ft[1]|0;Bh=ft[2]|0;Bl=ft[3]|0;Ch=ft[4]|0;Cl=ft[5]|0;Dh=ft[6]|0;Dl=ft[7]|0;Eh=ft[8]|0;El=ft[9]|0;Fh=ft[10]|0;Fl=ft[11]|0;Gh=ft[12]|0;Gl=ft[13]|0;Hh=ft[14]|0;Hl=ft[15]|0;constructor(){super(64)}};var Ur=Pp(()=>new Up,Np(1));var $0=Pp(()=>new jp,Np(3));var Hp=BigInt(0),Kp=BigInt(1);function fn(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}" `;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function F0(r){if(typeof r=="bigint"){if(!xl(r))throw new Error("positive bigint expected, got "+r)}else rr(r);return r}function La(r){let e=F0(r).toString(16);return e.length&1?"0"+e:e}function W0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Hp:BigInt("0x"+r)}function ns(r){return W0(cn(r))}function Mr(r){return W0(cn(Mo(fe(r)).reverse()))}function vl(r,e){rr(e),r=F0(r);let t=un(r.toString(16).padStart(e*2,"0"));if(t.length!==e)throw new Error("number too large");return t}function Ua(r,e){return vl(r,e).reverse()}function Mo(r){return Uint8Array.from(r)}var xl=r=>typeof r=="bigint"&&Hp<=r;function ME(r,e,t){return xl(r)&&xl(e)&&xl(t)&&e<=r&&r<t}function zn(r,e,t,n){if(!ME(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Vp(r){let e;for(e=0;r>Hp;r>>=Kp,e+=1);return e}var Ma=r=>(Kp<<BigInt(r))-Kp;function q0(r,e,t){if(rr(r,"hashLen"),rr(e,"qByteLen"),typeof t!="function")throw new Error("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),p=0,h=()=>{c.fill(1),f.fill(0),p=0},y=(...m)=>t(f,Lt(c,...m)),b=(m=o)=>{f=y(i,m),c=y(),m.length!==0&&(f=y(s,m),c=y())},g=()=>{if(p++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,S=[];for(;m<e;){c=y();let N=c.slice();S.push(N),m+=c.length}return Lt(...S)};return(m,S)=>{h(),b(m);let N;for(;!(N=S(g()));)b();return h(),N}}function jr(r,e={},t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(i,s,a){let c=r[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(e,!1),o(t,!0)}function os(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 Ot=BigInt(0),st=BigInt(1),jo=BigInt(2),X0=BigInt(3),Z0=BigInt(4),Y0=BigInt(5),jE=BigInt(7),J0=BigInt(8),KE=BigInt(9),Q0=BigInt(16);function He(r,e){let t=r%e;return t>=Ot?t:e+t}function Le(r,e,t){let n=r;for(;e-- >Ot;)n*=n,n%=t;return n}function G0(r,e){if(r===Ot)throw new Error("invert: expected non-zero number");if(e<=Ot)throw new Error("invert: expected positive modulus, got "+e);let t=He(r,e),n=e,o=Ot,i=st,s=st,a=Ot;for(;t!==Ot;){let f=n/t,p=n%t,h=o-s*f,y=i-a*f;n=t,t=p,o=s,i=a,s=h,a=y}if(n!==st)throw new Error("invert: does not exist");return He(o,e)}function Fp(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function eb(r,e){let t=(r.ORDER+st)/Z0,n=r.pow(e,t);return Fp(r,n,e),n}function HE(r,e){let t=(r.ORDER-Y0)/J0,n=r.mul(e,jo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,jo),o),a=r.mul(i,r.sub(s,r.ONE));return Fp(r,a,e),a}function VE(r){let e=is(r),t=tb(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+jE)/Q0;return(a,c)=>{let f=a.pow(c,s),p=a.mul(f,n),h=a.mul(f,o),y=a.mul(f,i),b=a.eql(a.sqr(p),c),g=a.eql(a.sqr(h),c);f=a.cmov(f,p,b),p=a.cmov(y,h,g);let C=a.eql(a.sqr(p),c),m=a.cmov(f,p,C);return Fp(a,m,c),m}}function tb(r){if(r<X0)throw new Error("sqrt is not defined for small field");let e=r-st,t=0;for(;e%jo===Ot;)e/=jo,t++;let n=jo,o=is(r);for(;z0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return eb;let i=o.pow(n,e),s=(e+st)/jo;return function(c,f){if(c.is0(f))return f;if(z0(c,f)!==1)throw new Error("Cannot find square root");let p=t,h=c.mul(c.ONE,i),y=c.pow(f,e),b=c.pow(f,s);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let g=1,C=c.sqr(y);for(;!c.eql(C,c.ONE);)if(g++,C=c.sqr(C),g===p)throw new Error("Cannot find square root");let m=st<<BigInt(p-g-1),S=c.pow(h,m);p=g,h=c.sqr(S),y=c.mul(y,h),b=c.mul(b,S)}return b}}function $E(r){return r%Z0===X0?eb:r%J0===Y0?HE:r%Q0===KE?VE(r):tb(r)}var rb=(r,e)=>(He(r,e)&st)===st,FE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wp(r){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},t=FE.reduce((n,o)=>(n[o]="function",n),e);return jr(r,t),r}function WE(r,e,t){if(t<Ot)throw new Error("invalid exponent, negatives unsupported");if(t===Ot)return r.ONE;if(t===st)return e;let n=r.ONE,o=e;for(;t>Ot;)t&st&&(n=r.mul(n,o)),o=r.sqr(o),t>>=st;return n}function ja(r,e,t=!1){let n=new Array(e.length).fill(t?r.ZERO:void 0),o=e.reduce((s,a,c)=>r.is0(a)?s:(n[c]=s,r.mul(s,a)),r.ONE),i=r.inv(o);return e.reduceRight((s,a,c)=>r.is0(a)?s:(n[c]=r.mul(s,n[c]),r.mul(s,a)),i),n}function z0(r,e){let t=(r.ORDER-st)/jo,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 qE(r,e){e!==void 0&&rr(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}var $p=class{ORDER;BITS;BYTES;isLE;ZERO=Ot;ONE=st;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=Ot)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&(this.sqrt=t.sqrt),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:i}=qE(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return He(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return Ot<=e&&e<this.ORDER}is0(e){return e===Ot}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&st)===st}neg(e){return He(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return He(e*e,this.ORDER)}add(e,t){return He(e+t,this.ORDER)}sub(e,t){return He(e-t,this.ORDER)}mul(e,t){return He(e*t,this.ORDER)}pow(e,t){return WE(this,e,t)}div(e,t){return He(e*G0(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return G0(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=$E(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Ua(e,this.BYTES):vl(e,this.BYTES)}fromBytes(e,t=!1){fe(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Mr(e):ns(e);if(a&&(c=He(c,s)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return ja(this,e)}cmov(e,t,n){return n?t:e}};function is(r,e={}){return new $p(r,e)}function nb(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 qp(r){let e=nb(r);return e+Math.ceil(e/2)}function Gp(r,e,t=!1){fe(r);let n=r.length,o=nb(e),i=qp(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Mr(r):ns(r),a=He(s,e-st)+st;return t?Ua(a,o):vl(a,o)}var ss=BigInt(0),Ko=BigInt(1);function Ka(r,e){let t=e.negate();return r?t:e}function Ho(r,e){let t=ja(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function ab(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function zp(r,e){ab(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Ma(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function ob(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+=Ko);let f=e*n,p=f+Math.abs(a)-1,h=a===0,y=a<0,b=e%2!==0;return{nextN:c,offset:p,isZero:h,isNeg:y,isNegF:b,offsetF:f}}var Xp=new WeakMap,cb=new WeakMap;function Zp(r){return cb.get(r)||1}function ib(r){if(r!==ss)throw new Error("invalid wNAF")}var as=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>ss;)t&Ko&&(n=n.add(o)),o=o.double(),t>>=Ko;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=zp(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=zp(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:p,isNeg:h,isNegF:y,offsetF:b}=ob(n,a,s);n=c,p?i=i.add(Ka(y,t[b])):o=o.add(Ka(h,t[f]))}return ib(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=zp(e,this.bits);for(let s=0;s<i.windows&&n!==ss;s++){let{nextN:a,offset:c,isZero:f,isNeg:p}=ob(n,s,i);if(n=a,!f){let h=t[c];o=o.add(p?h.negate():h)}}return ib(n),o}getPrecomputes(e,t,n){let o=Xp.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),Xp.set(t,o))),o}cached(e,t,n){let o=Zp(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=Zp(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){ab(t,this.bits),cb.set(e,t),Xp.delete(e)}hasCache(e){return Zp(e)!==1}};function ub(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>ss||n>ss;)t&Ko&&(i=i.add(o)),n&Ko&&(s=s.add(o)),o=o.double(),t>>=Ko,n>>=Ko;return{p1:i,p2:s}}function sb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wp(e),e}else return is(r,{isLE:t})}function Al(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=e[c];if(!(typeof f=="bigint"&&f>ss))throw new Error(`CURVE.${c} must be positive bigint`)}let o=sb(e.p,t.Fp,n),i=sb(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function cs(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var Xn=BigInt(0),at=BigInt(1),Yp=BigInt(2),GE=BigInt(8);function zE(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 lb(r,e={}){let t=Al("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;jr(e,{},{uvRatio:"function"});let a=Yp<<BigInt(o.BYTES*8)-at,c=m=>n.create(m),f=e.uvRatio||((m,S)=>{try{return{isValid:!0,value:n.sqrt(n.div(m,S))}}catch{return{isValid:!1,value:Xn}}});if(!zE(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(m,S,N=!1){let I=N?at:Xn;return zn("coordinate "+m,S,I,a),S}function h(m){if(!(m instanceof g))throw new Error("EdwardsPoint expected")}let y=os((m,S)=>{let{X:N,Y:I,Z:K}=m,Z=m.is0();S==null&&(S=Z?GE:n.inv(K));let q=c(N*S),re=c(I*S),R=n.mul(K,S);if(Z)return{x:Xn,y:at};if(R!==at)throw new Error("invZ was invalid");return{x:q,y:re}}),b=os(m=>{let{a:S,d:N}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:I,Y:K,Z,T:q}=m,re=c(I*I),R=c(K*K),k=c(Z*Z),G=c(k*k),Y=c(re*S),V=c(k*c(Y+R)),B=c(G+c(N*c(re*R)));if(V!==B)throw new Error("bad point: equation left != right (1)");let A=c(I*K),v=c(Z*q);if(A!==v)throw new Error("bad point: equation left != right (2)");return!0});class g{static BASE=new g(i.Gx,i.Gy,at,c(i.Gx*i.Gy));static ZERO=new g(Xn,at,at,Xn);static Fp=n;static Fn=o;X;Y;Z;T;constructor(S,N,I,K){this.X=p("x",S),this.Y=p("y",N),this.Z=p("z",I,!0),this.T=p("t",K),Object.freeze(this)}static CURVE(){return i}static fromAffine(S){if(S instanceof g)throw new Error("extended point not allowed");let{x:N,y:I}=S||{};return p("x",N),p("y",I),new g(N,I,at,c(N*I))}static fromBytes(S,N=!1){let I=n.BYTES,{a:K,d:Z}=i;S=Mo(fe(S,I,"point")),fn(N,"zip215");let q=Mo(S),re=S[I-1];q[I-1]=re&-129;let R=Mr(q),k=N?a:n.ORDER;zn("point.y",R,Xn,k);let G=c(R*R),Y=c(G-at),V=c(Z*G-K),{isValid:B,value:A}=f(Y,V);if(!B)throw new Error("bad point: invalid y coordinate");let v=(A&at)===at,D=(re&128)!==0;if(!N&&A===Xn&&D)throw new Error("bad point: x=0 and x_0=1");return D!==v&&(A=c(-A)),g.fromAffine({x:A,y:R})}static fromHex(S,N=!1){return g.fromBytes(un(S),N)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(S=8,N=!0){return C.createCache(this,S),N||this.multiply(Yp),this}assertValidity(){b(this)}equals(S){h(S);let{X:N,Y:I,Z:K}=this,{X:Z,Y:q,Z:re}=S,R=c(N*re),k=c(Z*K),G=c(I*re),Y=c(q*K);return R===k&&G===Y}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:S}=i,{X:N,Y:I,Z:K}=this,Z=c(N*N),q=c(I*I),re=c(Yp*c(K*K)),R=c(S*Z),k=N+I,G=c(c(k*k)-Z-q),Y=R+q,V=Y-re,B=R-q,A=c(G*V),v=c(Y*B),D=c(G*B),U=c(V*Y);return new g(A,v,U,D)}add(S){h(S);let{a:N,d:I}=i,{X:K,Y:Z,Z:q,T:re}=this,{X:R,Y:k,Z:G,T:Y}=S,V=c(K*R),B=c(Z*k),A=c(re*I*Y),v=c(q*G),D=c((K+Z)*(R+k)-V-B),U=v-A,L=v+A,T=c(B-N*V),M=c(D*U),W=c(L*T),O=c(D*T),pe=c(U*L);return new g(M,W,pe,O)}subtract(S){return this.add(S.negate())}multiply(S){if(!o.isValidNot0(S))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:N,f:I}=C.cached(this,S,K=>Ho(g,K));return Ho(g,[N,I])[0]}multiplyUnsafe(S,N=g.ZERO){if(!o.isValid(S))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return S===Xn?g.ZERO:this.is0()||S===at?this:C.unsafe(this,S,I=>Ho(g,I),N)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return C.unsafe(this,i.n).is0()}toAffine(S){return y(this,S)}clearCofactor(){return s===at?this:this.multiplyUnsafe(s)}toBytes(){let{x:S,y:N}=this.toAffine(),I=n.toBytes(N);return I[I.length-1]|=S&at?128:0,I}toHex(){return cn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let C=new as(g,o.BITS);return g.BASE.precompute(8),g}function fb(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');jr(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||Fn,c=t.adjustScalarBytes||(R=>R),f=t.domain||((R,k,G)=>{if(fn(G,"phflag"),k.length||G)throw new Error("Contexts/pre-hash are not supported");return R});function p(R){return s.create(Mr(R))}function h(R){let k=I.secretKey;fe(R,I.secretKey,"secretKey");let G=fe(e(R),2*k,"hashedSecretKey"),Y=c(G.slice(0,k)),V=G.slice(k,2*k),B=p(Y);return{head:Y,prefix:V,scalar:B}}function y(R){let{head:k,prefix:G,scalar:Y}=h(R),V=o.multiply(Y),B=V.toBytes();return{head:k,prefix:G,scalar:Y,point:V,pointBytes:B}}function b(R){return y(R).pointBytes}function g(R=Uint8Array.of(),...k){let G=Lt(...k);return p(e(f(G,fe(R,void 0,"context"),!!n)))}function C(R,k,G={}){R=fe(R,void 0,"message"),n&&(R=n(R));let{prefix:Y,scalar:V,pointBytes:B}=y(k),A=g(G.context,Y,R),v=o.multiply(A).toBytes(),D=g(G.context,v,B,R),U=s.create(A+D*V);if(!s.isValid(U))throw new Error("sign failed: invalid s");let L=Lt(v,s.toBytes(U));return fe(L,I.signature,"result")}let m={zip215:!0};function S(R,k,G,Y=m){let{context:V,zip215:B}=Y,A=I.signature;R=fe(R,A,"signature"),k=fe(k,void 0,"message"),G=fe(G,I.publicKey,"publicKey"),B!==void 0&&fn(B,"zip215"),n&&(k=n(k));let v=A/2,D=R.subarray(0,v),U=Mr(R.subarray(v,A)),L,T,M;try{L=r.fromBytes(G,B),T=r.fromBytes(D,B),M=o.multiplyUnsafe(U)}catch{return!1}if(!B&&L.isSmallOrder())return!1;let W=g(V,T.toBytes(),L.toBytes(),k);return T.add(L.multiplyUnsafe(W)).subtract(M).clearCofactor().is0()}let N=i.BYTES,I={secretKey:N,publicKey:N,signature:2*N,seed:N};function K(R=a(I.seed)){return fe(R,I.seed,"seed")}function Z(R){return Do(R)&&R.length===s.BYTES}function q(R,k){try{return!!r.fromBytes(R,k)}catch{return!1}}let re={getExtendedPublicKey:y,randomSecretKey:K,isValidSecretKey:Z,isValidPublicKey:q,toMontgomery(R){let{y:k}=r.fromBytes(R),G=I.publicKey,Y=G===32;if(!Y&&G!==57)throw new Error("only defined for 25519 and 448");let V=Y?i.div(at+k,at-k):i.div(k-at,k+at);return i.toBytes(V)},toMontgomerySecret(R){let k=I.secretKey;fe(R,k);let G=e(R.subarray(0,k));return c(G).subarray(0,k)}};return Object.freeze({keygen:cs(K,b),getPublicKey:b,sign:C,verify:S,utils:re,Point:r,lengths:I})}var Ha=BigInt(0),us=BigInt(1),Sl=BigInt(2);function XE(r){return jr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function hb(r){let e=XE(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||Fn,f=a?255:448,p=a?32:56,h=BigInt(a?9:5),y=BigInt(a?121665:39081),b=a?Sl**BigInt(254):Sl**BigInt(447),g=a?BigInt(8)*Sl**BigInt(251)-us:BigInt(4)*Sl**BigInt(445)-us,C=b+g+us,m=A=>He(A,t),S=N(h);function N(A){return Ua(m(A),p)}function I(A){let v=Mo(fe(A,p,"uCoordinate"));return a&&(v[31]&=127),m(Mr(v))}function K(A){return Mr(o(Mo(fe(A,p,"scalar"))))}function Z(A,v){let D=G(I(v),K(A));if(D===Ha)throw new Error("invalid private or public key received");return N(D)}function q(A){return Z(A,S)}let re=q,R=Z;function k(A,v,D){let U=m(A*(v-D));return v=m(v-U),D=m(D+U),{x_2:v,x_3:D}}function G(A,v){zn("u",A,Ha,t),zn("scalar",v,b,C);let D=v,U=A,L=us,T=Ha,M=A,W=us,O=Ha;for(let be=BigInt(f-1);be>=Ha;be--){let ee=D>>be&us;O^=ee,{x_2:L,x_3:M}=k(O,L,M),{x_2:T,x_3:W}=k(O,T,W),O=ee;let Ae=L+T,Be=m(Ae*Ae),Ke=L-T,Ee=m(Ke*Ke),Ie=Be-Ee,rn=M+W,pr=M-W,jn=m(pr*Ae),Ju=m(rn*Ke),Gi=jn+Ju,Aa=jn-Ju;M=m(Gi*Gi),W=m(U*m(Aa*Aa)),L=m(Be*Ee),T=m(Ie*(Be+m(y*Ie)))}({x_2:L,x_3:M}=k(O,L,M)),{x_2:T,x_3:W}=k(O,T,W);let pe=i(T);return m(L*pe)}let Y={secretKey:p,publicKey:p,seed:p},V=(A=c(p))=>(fe(A,Y.seed,"seed"),A),B={randomSecretKey:V};return Object.freeze({keygen:cs(V,re),getSharedSecret:R,getPublicKey:re,scalarMult:Z,scalarMultBase:q,utils:B,GuBytes:S.slice(),lengths:Y})}var ZE=BigInt(1),pb=BigInt(2),YE=BigInt(3),JE=BigInt(5),QE=BigInt(8),El=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),e_={p:El,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:QE,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function mb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=El,a=r*r%i*r%i,c=Le(a,pb,i)*a%i,f=Le(c,ZE,i)*r%i,p=Le(f,JE,i)*f%i,h=Le(p,e,i)*p%i,y=Le(h,t,i)*h%i,b=Le(y,n,i)*y%i,g=Le(b,o,i)*b%i,C=Le(g,o,i)*b%i,m=Le(C,e,i)*p%i;return{pow_p_5_8:Le(m,pb,i)*r%i,b2:a}}function yb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var db=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function t_(r,e){let t=El,n=He(e*e*e,t),o=He(n*n*e,t),i=mb(r*o).pow_p_5_8,s=He(r*n*i,t),a=He(e*s*s,t),c=s,f=He(s*db,t),p=a===r,h=a===He(-r,t),y=a===He(-r*db,t);return p&&(s=c),(h||y)&&(s=f),rb(s,t)&&(s=He(-s,t)),{isValid:p||h,value:s}}var r_=lb(e_,{uvRatio:t_});function n_(r){return fb(r_,$0,Object.assign({adjustScalarBytes:yb},r))}var Va=n_({});var $a=(()=>{let r=El;return hb({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=mb(e);return He(Le(t,YE,r)*n,r)},adjustScalarBytes:yb})})();var Fa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Wa=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},_l=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var gb={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new _l("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ut=gb;var Cl=32,qa=64,Jp=32;var ls,bb=(async()=>{try{return await Ut.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function wb(){let r=Va.utils.randomSecretKey(),e=Va.getPublicKey(r);return{privateKey:c_(r,e),publicKey:e}}async function o_(r,e){let t;r.length===qa?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:ue(r.subarray(32),"base64url"),d:ue(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Ut.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ut.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function i_(r,e){let t=r.subarray(0,Jp);return Va.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function xb(r,e){return ls==null&&(ls=await bb),ls?o_(r,e):i_(r,e)}async function s_(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Ut.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ut.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 a_(r,e,t){return Va.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function vb(r,e,t){return ls==null&&(ls=await bb),ls?s_(r,e,t):a_(r,e,t)}function c_(r,e){let t=new Uint8Array(qa);for(let n=0;n<Jp;n++)t[n]=r[n],t[Jp+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 Ga=class{type="Ed25519";raw;constructor(e){this.raw=Il(e,Cl)}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=vb(this.raw,t,e);return fs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},Bl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Il(e,qa),this.publicKey=new Ga(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=xb(this.raw,e);return fs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Qp(r){return r=Il(r,Cl),new Ga(r)}async function Sb(){let{privateKey:r,publicKey:e}=wb();return new Bl(r,e)}function Il(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new xe(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var u_=Math.pow(2,7),l_=Math.pow(2,14),f_=Math.pow(2,21),ed=Math.pow(2,28),td=Math.pow(2,35),rd=Math.pow(2,42),nd=Math.pow(2,49),Te=128,At=127;function Ue(r){if(r<u_)return 1;if(r<l_)return 2;if(r<f_)return 3;if(r<ed)return 4;if(r<td)return 5;if(r<rd)return 6;if(r<nd)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function hs(r,e,t=0){switch(Ue(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 h_(r,e,t=0){switch(Ue(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 od(r,e){let t=r[e],n=0;if(n+=t&At,t<Te||(t=r[e+1],n+=(t&At)<<7,t<Te)||(t=r[e+2],n+=(t&At)<<14,t<Te)||(t=r[e+3],n+=(t&At)<<21,t<Te)||(t=r[e+4],n+=(t&At)*ed,t<Te)||(t=r[e+5],n+=(t&At)*td,t<Te)||(t=r[e+6],n+=(t&At)*rd,t<Te)||(t=r[e+7],n+=(t&At)*nd,t<Te))return n;throw new RangeError("Could not decode varint")}function p_(r,e){let t=r.get(e),n=0;if(n+=t&At,t<Te||(t=r.get(e+1),n+=(t&At)<<7,t<Te)||(t=r.get(e+2),n+=(t&At)<<14,t<Te)||(t=r.get(e+3),n+=(t&At)<<21,t<Te)||(t=r.get(e+4),n+=(t&At)*ed,t<Te)||(t=r.get(e+5),n+=(t&At)*td,t<Te)||(t=r.get(e+6),n+=(t&At)*rd,t<Te)||(t=r.get(e+7),n+=(t&At)*nd,t<Te))return n;throw new RangeError("Could not decode varint")}function Tl(r,e,t=0){return e==null&&(e=ot(Ue(r))),e instanceof Uint8Array?hs(r,e,t):h_(r,e,t)}function hn(r,e=0){return r instanceof Uint8Array?od(r,e):p_(r,e)}var id=new Float32Array([-0]),Zn=new Uint8Array(id.buffer);function Eb(r,e,t){id[0]=r,e[t]=Zn[0],e[t+1]=Zn[1],e[t+2]=Zn[2],e[t+3]=Zn[3]}function _b(r,e){return Zn[0]=r[e],Zn[1]=r[e+1],Zn[2]=r[e+2],Zn[3]=r[e+3],id[0]}var sd=new Float64Array([-0]),St=new Uint8Array(sd.buffer);function Cb(r,e,t){sd[0]=r,e[t]=St[0],e[t+1]=St[1],e[t+2]=St[2],e[t+3]=St[3],e[t+4]=St[4],e[t+5]=St[5],e[t+6]=St[6],e[t+7]=St[7]}function Bb(r,e){return St[0]=r[e],St[1]=r[e+1],St[2]=r[e+2],St[3]=r[e+3],St[4]=r[e+4],St[5]=r[e+5],St[6]=r[e+6],St[7]=r[e+7],sd[0]}var d_=BigInt(Number.MAX_SAFE_INTEGER),m_=BigInt(Number.MIN_SAFE_INTEGER),zt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Vo;if(e<d_&&e>m_)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>Ib&&(o=0n,++n>Ib&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Vo;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):Vo}},Vo=new zt(0,0);Vo.toBigInt=function(){return 0n};Vo.zzEncode=Vo.zzDecode=function(){return this};Vo.length=function(){return 1};var Ib=4294967296n;function Tb(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 kb(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 ad(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 xr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function kl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var cd=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,xr(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 xr(this,4);return kl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw xr(this,4);return kl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw xr(this,4);let e=_b(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw xr(this,4);let e=Bb(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 xr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return kb(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw xr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw xr(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new zt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw xr(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 xr(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 xr(this,8);let e=kl(this.buf,this.pos+=4),t=kl(this.buf,this.pos+=4);return new zt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=od(this.buf,this.pos);return this.pos+=Ue(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 ud(r){return new cd(r instanceof Uint8Array?r:r.subarray())}function vr(r,e,t){let n=ud(r);return e.decode(n,void 0,t)}function ld(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 $o=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function fd(){}var pd=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},y_=ld();function g_(r){return globalThis.Buffer!=null?ot(r):y_(r)}var Za=class{len;head;tail;states;constructor(){this.len=0,this.head=new $o(fd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new $o(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new dd((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ol,10,zt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=zt.fromBigInt(e);return this._push(Ol,t.length(),t)}uint64Number(e){return this._push(hs,Ue(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=zt.fromBigInt(e).zzEncode();return this._push(Ol,t.length(),t)}sint64Number(e){let t=zt.fromNumber(e).zzEncode();return this._push(Ol,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(hd,1,e?1:0)}fixed32(e){return this._push(Xa,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=zt.fromBigInt(e);return this._push(Xa,4,t.lo)._push(Xa,4,t.hi)}fixed64Number(e){let t=zt.fromNumber(e);return this._push(Xa,4,t.lo)._push(Xa,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Eb,4,e)}double(e){return this._push(Cb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(hd,1,0):this.uint32(t)._push(w_,t,e)}string(e){let t=Tb(e);return t!==0?this.uint32(t)._push(ad,t,e):this._push(hd,1,0)}fork(){return this.states=new pd(this),this.head=this.tail=new $o(fd,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 $o(fd,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=g_(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function hd(r,e,t){e[t]=r&255}function b_(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var dd=class extends $o{next;constructor(e,t){super(b_,e,t),this.next=void 0}};function Ol(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Xa(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function w_(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Za.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(x_,e,r),this},Za.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(v_,e,r),this});function x_(r,e,t){e.set(r,t)}function v_(r,e,t){r.length<40?ad(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function md(){return new Za}function Ar(r,e){let t=md();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ps;(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"})(ps||(ps={}));function Pl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Fo(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",ps.VARINT,t,n)}function Sr(r,e){return Pl("message",ps.LENGTH_DELIMITED,r,e)}var Ya=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var yd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(yd||(yd={}));(function(r){r.codec=()=>Fo(yd)})(Ye||(Ye={}));var Kr;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Kr||(Kr={}));var gd;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(gd||(gd={}));var Qa={};vt(Qa,{MAX_RSA_KEY_SIZE:()=>bd,generateRSAKeyPair:()=>Bd,jwkToJWKKeyPair:()=>Lb,jwkToPkcs1:()=>__,jwkToPkix:()=>Ad,jwkToRSAPrivateKey:()=>Cd,pkcs1MessageToJwk:()=>xd,pkcs1MessageToRSAPrivateKey:()=>Sd,pkcs1ToJwk:()=>E_,pkcs1ToRSAPrivateKey:()=>Rb,pkixMessageToJwk:()=>vd,pkixMessageToRSAPublicKey:()=>_d,pkixToJwk:()=>C_,pkixToRSAPublicKey:()=>Ed});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=Qa.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return Db(this.jwk,t,e,n)}},Ja=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Qa.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return Nb(this.jwk,e,t)}};var bd=8192,wd=18,A_=1062,S_=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function E_(r){let e=sn(r);return xd(e)}function xd(r){return{n:ue(r[1],"base64url"),e:ue(r[2],"base64url"),d:ue(r[3],"base64url"),p:ue(r[4],"base64url"),q:ue(r[5],"base64url"),dp:ue(r[6],"base64url"),dq:ue(r[7],"base64url"),qi:ue(r[8],"base64url"),kty:"RSA"}}function __(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 xe("JWK was missing components");return gr([kt(Uint8Array.from([0])),kt(de(r.n,"base64url")),kt(de(r.e,"base64url")),kt(de(r.d,"base64url")),kt(de(r.p,"base64url")),kt(de(r.q,"base64url")),kt(de(r.dp,"base64url")),kt(de(r.dq,"base64url")),kt(de(r.qi,"base64url"))]).subarray()}function C_(r){let e=sn(r,{offset:0});return vd(e)}function vd(r){let e=sn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Ad(r){if(r.n==null||r.e==null)throw new xe("JWK was missing components");return gr([S_,Pa(gr([kt(de(r.n,"base64url")),kt(de(r.e,"base64url"))]))]).subarray()}function Rb(r){let e=sn(r);return Sd(e)}function Sd(r){let e=xd(r);return Cd(e)}function Ed(r,e){if(r.byteLength>=A_)throw new zi("Key size is too large");let t=sn(r,{offset:0});return _d(t,r,e)}function _d(r,e,t){let n=vd(r);if(t==null){let o=Ur(Kr.encode({Type:Ye.RSA,Data:e}));t=It(wd,o)}return new ds(n,t)}function Cd(r){if(Mb(r)>bd)throw new xe("Key size is too large");let e=Lb(r),t=Ur(Kr.encode({Type:Ye.RSA,Data:Ad(e.publicKey)})),n=It(wd,t);return new Ja(e.privateKey,new ds(e.publicKey,n))}async function Bd(r){if(r>bd)throw new xe("Key size is too large");let e=await Ub(r),t=Ur(Kr.encode({Type:Ye.RSA,Data:Ad(e.publicKey)})),n=It(wd,t);return new Ja(e.privateKey,new ds(e.publicKey,n))}function Lb(r){if(r==null)throw new xe("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ub(r,e){let t=await Ut.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 B_(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Nb(r,e,t){let n=await Ut.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Ut.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 Db(r,e,t,n){let o=await Ut.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ut.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function B_(r,e){if(r.privateKey==null||r.publicKey==null)throw new xe("Private and public key are required");let t=await Promise.all([Ut.get().subtle.exportKey("jwk",r.privateKey),Ut.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function Mb(r){if(r.kty!=="RSA")throw new xe("invalid key type");if(r.n==null)throw new xe("invalid key modulus");return de(r.n,"base64url").length*8}var Nl=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Ro(e),fe(t,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),br(o)}update(e){return rs(this),this.iHash.update(e),this}digestInto(e){rs(this),fe(e,this.outputLen,"output"),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||=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()}},ms=(r,e,t)=>new Nl(r,e).update(t).digest();ms.create=(r,e)=>new Nl(r,e);var jb=(r,e)=>(r+(r>=0?e:-e)/Kb)/e;function I_(r,e,t){let[[n,o],[i,s]]=e,a=jb(s*r,t),c=jb(-o*r,t),f=r-a*n-c*i,p=-a*o-c*s,h=f<pn,y=p<pn;h&&(f=-f),y&&(p=-p);let b=Ma(Math.ceil(Vp(t)/2))+ys;if(f<pn||f>=b||p<pn||p>=b)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:h,k1:f,k2neg:y,k2:p}}function Td(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Id(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return fn(t.lowS,"lowS"),fn(t.prehash,"prehash"),t.format!==void 0&&Td(t.format),t}var kd=class extends Error{constructor(e=""){super(e)}},Yn={Err:kd,_tlv:{encode:(r,e)=>{let{Err:t}=Yn;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=La(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?La(o.length/2|128):"";return La(r)+i+o+e},decode(r,e){let{Err:t}=Yn,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 f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let p of f)s=s<<8|p;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=Yn;if(r<pn)throw new e("integer: negative integers are not allowed");let t=La(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}=Yn;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 ns(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Yn,o=fe(r,void 0,"signature"),{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:f,l:p}=n.decode(2,c);if(p.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=Yn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},pn=BigInt(0),ys=BigInt(1),Kb=BigInt(2),Dl=BigInt(3),T_=BigInt(4);function Hb(r,e={}){let t=Al("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;jr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=$b(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(V,B,A){let{x:v,y:D}=B.toAffine(),U=n.toBytes(v);if(fn(A,"isCompressed"),A){p();let L=!n.isOdd(D);return Lt(Vb(L),U)}else return Lt(Uint8Array.of(4),U,n.toBytes(D))}function y(V){fe(V,void 0,"Point");let{publicKey:B,publicKeyUncompressed:A}=f,v=V.length,D=V[0],U=V.subarray(1);if(v===B&&(D===2||D===3)){let L=n.fromBytes(U);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let T=C(L),M;try{M=n.sqrt(T)}catch(pe){let be=pe instanceof Error?": "+pe.message:"";throw new Error("bad point: is not on curve, sqrt error"+be)}p();let W=n.isOdd(M);return(D&1)===1!==W&&(M=n.neg(M)),{x:L,y:M}}else if(v===A&&D===4){let L=n.BYTES,T=n.fromBytes(U.subarray(0,L)),M=n.fromBytes(U.subarray(L,L*2));if(!m(T,M))throw new Error("bad point: is not on curve");return{x:T,y:M}}else throw new Error(`bad point: got length ${v}, expected compressed=${B} or uncompressed=${A}`)}let b=e.toBytes||h,g=e.fromBytes||y;function C(V){let B=n.sqr(V),A=n.mul(B,V);return n.add(n.add(A,n.mul(V,i.a)),i.b)}function m(V,B){let A=n.sqr(B),v=C(V);return n.eql(A,v)}if(!m(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(i.a,Dl),T_),N=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(S,N)))throw new Error("bad curve params: a or b");function I(V,B,A=!1){if(!n.isValid(B)||A&&n.is0(B))throw new Error(`bad point coordinate ${V}`);return B}function K(V){if(!(V instanceof k))throw new Error("Weierstrass Point expected")}function Z(V){if(!c||!c.basises)throw new Error("no endo");return I_(V,c.basises,o.ORDER)}let q=os((V,B)=>{let{X:A,Y:v,Z:D}=V;if(n.eql(D,n.ONE))return{x:A,y:v};let U=V.is0();B==null&&(B=U?n.ONE:n.inv(D));let L=n.mul(A,B),T=n.mul(v,B),M=n.mul(D,B);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(M,n.ONE))throw new Error("invZ was invalid");return{x:L,y:T}}),re=os(V=>{if(V.is0()){if(e.allowInfinityPoint&&!n.is0(V.Y))return;throw new Error("bad point: ZERO")}let{x:B,y:A}=V.toAffine();if(!n.isValid(B)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!m(B,A))throw new Error("bad point: equation left != right");if(!V.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(V,B,A,v,D){return A=new k(n.mul(A.X,V),A.Y,A.Z),B=Ka(v,B),A=Ka(D,A),B.add(A)}class k{static BASE=new k(i.Gx,i.Gy,n.ONE);static ZERO=new k(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(B,A,v){this.X=I("x",B),this.Y=I("y",A,!0),this.Z=I("z",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(B){let{x:A,y:v}=B||{};if(!B||!n.isValid(A)||!n.isValid(v))throw new Error("invalid affine point");if(B instanceof k)throw new Error("projective point not allowed");return n.is0(A)&&n.is0(v)?k.ZERO:new k(A,v,n.ONE)}static fromBytes(B){let A=k.fromAffine(g(fe(B,void 0,"point")));return A.assertValidity(),A}static fromHex(B){return k.fromBytes(un(B))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(B=8,A=!0){return Y.createCache(this,B),A||this.multiply(Dl),this}assertValidity(){re(this)}hasEvenY(){let{y:B}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(B)}equals(B){K(B);let{X:A,Y:v,Z:D}=this,{X:U,Y:L,Z:T}=B,M=n.eql(n.mul(A,T),n.mul(U,D)),W=n.eql(n.mul(v,T),n.mul(L,D));return M&&W}negate(){return new k(this.X,n.neg(this.Y),this.Z)}double(){let{a:B,b:A}=i,v=n.mul(A,Dl),{X:D,Y:U,Z:L}=this,T=n.ZERO,M=n.ZERO,W=n.ZERO,O=n.mul(D,D),pe=n.mul(U,U),be=n.mul(L,L),ee=n.mul(D,U);return ee=n.add(ee,ee),W=n.mul(D,L),W=n.add(W,W),T=n.mul(B,W),M=n.mul(v,be),M=n.add(T,M),T=n.sub(pe,M),M=n.add(pe,M),M=n.mul(T,M),T=n.mul(ee,T),W=n.mul(v,W),be=n.mul(B,be),ee=n.sub(O,be),ee=n.mul(B,ee),ee=n.add(ee,W),W=n.add(O,O),O=n.add(W,O),O=n.add(O,be),O=n.mul(O,ee),M=n.add(M,O),be=n.mul(U,L),be=n.add(be,be),O=n.mul(be,ee),T=n.sub(T,O),W=n.mul(be,pe),W=n.add(W,W),W=n.add(W,W),new k(T,M,W)}add(B){K(B);let{X:A,Y:v,Z:D}=this,{X:U,Y:L,Z:T}=B,M=n.ZERO,W=n.ZERO,O=n.ZERO,pe=i.a,be=n.mul(i.b,Dl),ee=n.mul(A,U),Ae=n.mul(v,L),Be=n.mul(D,T),Ke=n.add(A,v),Ee=n.add(U,L);Ke=n.mul(Ke,Ee),Ee=n.add(ee,Ae),Ke=n.sub(Ke,Ee),Ee=n.add(A,D);let Ie=n.add(U,T);return Ee=n.mul(Ee,Ie),Ie=n.add(ee,Be),Ee=n.sub(Ee,Ie),Ie=n.add(v,D),M=n.add(L,T),Ie=n.mul(Ie,M),M=n.add(Ae,Be),Ie=n.sub(Ie,M),O=n.mul(pe,Ee),M=n.mul(be,Be),O=n.add(M,O),M=n.sub(Ae,O),O=n.add(Ae,O),W=n.mul(M,O),Ae=n.add(ee,ee),Ae=n.add(Ae,ee),Be=n.mul(pe,Be),Ee=n.mul(be,Ee),Ae=n.add(Ae,Be),Be=n.sub(ee,Be),Be=n.mul(pe,Be),Ee=n.add(Ee,Be),ee=n.mul(Ae,Ee),W=n.add(W,ee),ee=n.mul(Ie,Ee),M=n.mul(Ke,M),M=n.sub(M,ee),ee=n.mul(Ke,Ae),O=n.mul(Ie,O),O=n.add(O,ee),new k(M,W,O)}subtract(B){return this.add(B.negate())}is0(){return this.equals(k.ZERO)}multiply(B){let{endo:A}=e;if(!o.isValidNot0(B))throw new Error("invalid scalar: out of range");let v,D,U=L=>Y.cached(this,L,T=>Ho(k,T));if(A){let{k1neg:L,k1:T,k2neg:M,k2:W}=Z(B),{p:O,f:pe}=U(T),{p:be,f:ee}=U(W);D=pe.add(ee),v=R(A.beta,O,be,L,M)}else{let{p:L,f:T}=U(B);v=L,D=T}return Ho(k,[v,D])[0]}multiplyUnsafe(B){let{endo:A}=e,v=this;if(!o.isValid(B))throw new Error("invalid scalar: out of range");if(B===pn||v.is0())return k.ZERO;if(B===ys)return v;if(Y.hasCache(this))return this.multiply(B);if(A){let{k1neg:D,k1:U,k2neg:L,k2:T}=Z(B),{p1:M,p2:W}=ub(k,v,U,T);return R(A.beta,M,W,D,L)}else return Y.unsafe(v,B)}toAffine(B){return q(this,B)}isTorsionFree(){let{isTorsionFree:B}=e;return s===ys?!0:B?B(k,this):Y.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:B}=e;return s===ys?this:B?B(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(B=!0){return fn(B,"isCompressed"),this.assertValidity(),b(k,this,B)}toHex(B=!0){return cn(this.toBytes(B))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=o.BITS,Y=new as(k,e.endo?Math.ceil(G/2):G);return k.BASE.precompute(8),k}function Vb(r){return Uint8Array.of(r?2:3)}function $b(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function k_(r,e={}){let{Fn:t}=r,n=e.randomBytes||Fn,o=Object.assign($b(r.Fp,t),{seed:qp(t.ORDER)});function i(b){try{let g=t.fromBytes(b);return t.isValidNot0(g)}catch{return!1}}function s(b,g){let{publicKey:C,publicKeyUncompressed:m}=o;try{let S=b.length;return g===!0&&S!==C||g===!1&&S!==m?!1:!!r.fromBytes(b)}catch{return!1}}function a(b=n(o.seed)){return Gp(fe(b,o.seed,"seed"),t.ORDER)}function c(b,g=!0){return r.BASE.multiply(t.fromBytes(b)).toBytes(g)}function f(b){let{secretKey:g,publicKey:C,publicKeyUncompressed:m}=o;if(!Do(b)||"_lengths"in t&&t._lengths||g===C)return;let S=fe(b,void 0,"key").length;return S===C||S===m}function p(b,g,C=!0){if(f(b)===!0)throw new Error("first arg must be private key");if(f(g)===!1)throw new Error("second arg must be public key");let m=t.fromBytes(b);return r.fromBytes(g).multiply(m).toBytes(C)}let h={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},y=cs(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:p,keygen:y,Point:r,utils:h,lengths:o})}function Fb(r,e,t={}){Ro(e),jr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),t=Object.assign({},t);let n=t.randomBytes||Fn,o=t.hmac||((A,v)=>ms(e,A,v)),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:p,getSharedSecret:h,utils:y,lengths:b}=k_(r,t),g={prehash:!0,lowS:typeof t.lowS=="boolean"?t.lowS:!0,format:"compact",extraEntropy:!1},C=a*Kb<i.ORDER;function m(A){let v=a>>ys;return A>v}function S(A,v){if(!s.isValidNot0(v))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return v}function N(){if(C)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function I(A,v){Td(v);let D=b.signature,U=v==="compact"?D:v==="recovered"?D+1:void 0;return fe(A,U)}class K{r;s;recovery;constructor(v,D,U){if(this.r=S("r",v),this.s=S("s",D),U!=null){if(N(),![0,1,2,3].includes(U))throw new Error("invalid recovery id");this.recovery=U}Object.freeze(this)}static fromBytes(v,D=g.format){I(v,D);let U;if(D==="der"){let{r:W,s:O}=Yn.toSig(fe(v));return new K(W,O)}D==="recovered"&&(U=v[0],D="compact",v=v.subarray(1));let L=b.signature/2,T=v.subarray(0,L),M=v.subarray(L,L*2);return new K(s.fromBytes(T),s.fromBytes(M),U)}static fromHex(v,D){return this.fromBytes(un(v),D)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new K(this.r,this.s,v)}recoverPublicKey(v){let{r:D,s:U}=this,L=this.assertRecovery(),T=L===2||L===3?D+a:D;if(!i.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=i.toBytes(T),W=r.fromBytes(Lt(Vb((L&1)===0),M)),O=s.inv(T),pe=q(fe(v,void 0,"msgHash")),be=s.create(-pe*O),ee=s.create(U*O),Ae=r.BASE.multiplyUnsafe(be).add(W.multiplyUnsafe(ee));if(Ae.is0())throw new Error("invalid recovery: point at infinify");return Ae.assertValidity(),Ae}hasHighS(){return m(this.s)}toBytes(v=g.format){if(Td(v),v==="der")return un(Yn.hexFromSig(this));let{r:D,s:U}=this,L=s.toBytes(D),T=s.toBytes(U);return v==="recovered"?(N(),Lt(Uint8Array.of(this.assertRecovery()),L,T)):Lt(L,T)}toHex(v){return cn(this.toBytes(v))}}let Z=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let D=ns(v),U=v.length*8-c;return U>0?D>>BigInt(U):D},q=t.bits2int_modN||function(v){return s.create(Z(v))},re=Ma(c);function R(A){return zn("num < 2^"+c,A,pn,re),s.toBytes(A)}function k(A,v){return fe(A,void 0,"message"),v?fe(e(A),void 0,"prehashed message"):A}function G(A,v,D){let{lowS:U,prehash:L,extraEntropy:T}=Id(D,g);A=k(A,L);let M=q(A),W=s.fromBytes(v);if(!s.isValidNot0(W))throw new Error("invalid private key");let O=[R(W),R(M)];if(T!=null&&T!==!1){let Ae=T===!0?n(b.secretKey):T;O.push(fe(Ae,void 0,"extraEntropy"))}let pe=Lt(...O),be=M;function ee(Ae){let Be=Z(Ae);if(!s.isValidNot0(Be))return;let Ke=s.inv(Be),Ee=r.BASE.multiply(Be).toAffine(),Ie=s.create(Ee.x);if(Ie===pn)return;let rn=s.create(Ke*s.create(be+Ie*W));if(rn===pn)return;let pr=(Ee.x===Ie?0:2)|Number(Ee.y&ys),jn=rn;return U&&m(rn)&&(jn=s.neg(rn),pr^=1),new K(Ie,jn,C?void 0:pr)}return{seed:pe,k2sig:ee}}function Y(A,v,D={}){let{seed:U,k2sig:L}=G(A,v,D);return q0(e.outputLen,s.BYTES,o)(U,L).toBytes(D.format)}function V(A,v,D,U={}){let{lowS:L,prehash:T,format:M}=Id(U,g);if(D=fe(D,void 0,"publicKey"),v=k(v,T),!Do(A)){let W=A instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+W)}I(A,M);try{let W=K.fromBytes(A,M),O=r.fromBytes(D);if(L&&W.hasHighS())return!1;let{r:pe,s:be}=W,ee=q(v),Ae=s.inv(be),Be=s.create(ee*Ae),Ke=s.create(pe*Ae),Ee=r.BASE.multiplyUnsafe(Be).add(O.multiplyUnsafe(Ke));return Ee.is0()?!1:s.create(Ee.x)===pe}catch{return!1}}function B(A,v,D={}){let{prehash:U}=Id(D,g);return v=k(v,U),K.fromBytes(A,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:h,utils:y,lengths:b,Point:r,sign:Y,verify:V,recoverPublicKey:B,Signature:K,hash:e})}var Pd={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},O_={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Wb=BigInt(2);function P_(r){let e=Pd.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,p=f*f*r%e,h=Le(p,t,e)*p%e,y=Le(h,t,e)*p%e,b=Le(y,Wb,e)*f%e,g=Le(b,o,e)*b%e,C=Le(g,i,e)*g%e,m=Le(C,a,e)*C%e,S=Le(m,c,e)*m%e,N=Le(S,a,e)*C%e,I=Le(N,t,e)*p%e,K=Le(I,s,e)*g%e,Z=Le(K,n,e)*f%e,q=Le(Z,Wb,e);if(!Od.eql(Od.sqr(q),r))throw new Error("Cannot find square root");return q}var Od=is(Pd.p,{sqrt:P_}),N_=Hb(Pd,{Fp:Od,endo:O_}),Er=Fb(N_,Ur);function qb(r,e,t){let n=tr.digest(e instanceof Uint8Array?e:e.subarray());if(fs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Er.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Fa(String(o))});try{return Er.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Fa(String(o))}}function Gb(r,e,t,n){let o=tr.digest(t instanceof Uint8Array?t:t.subarray());if(fs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Er.verify(e,i,r,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Wa(String(i))});try{return n?.signal?.throwIfAborted(),Er.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(i){throw new Wa(String(i))}}var ec=class{type="secp256k1";raw;_key;constructor(e){this._key=Zb(e),this.raw=zb(this._key)}toMultihash(){return yr.digest($n(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return Fe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return Gb(this._key,t,e,n)}},Rl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=Xb(e),this.publicKey=new ec(t??Yb(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return qb(this.raw,e,t)}};function Nd(r){return new ec(r)}async function Jb(){let r=D_();return new Rl(r)}function zb(r){return Er.Point.fromBytes(r).toBytes()}function Xb(r){try{return Er.getPublicKey(r,!0),r}catch(e){throw new Ea(String(e))}}function Zb(r){try{return Er.Point.fromBytes(r),r}catch(e){throw new zi(String(e))}}function Yb(r){try{return Er.getPublicKey(r,!0)}catch(e){throw new Ea(String(e))}}function D_(){return Er.utils.randomSecretKey()}async function Qb(r,e){if(r==="Ed25519")return Sb();if(r==="secp256k1")return Jb();if(r==="RSA")return Bd(R_(e));if(r==="ECDSA")return I0(L_(e));throw new Kn}function tc(r,e){let{Type:t,Data:n}=Kr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return Ed(o,e);case Ye.Ed25519:return Qp(o);case Ye.secp256k1:return Nd(o);case Ye.ECDSA:return Op(o);default:throw new Kn}}function ew(r){let{Type:e,Data:t}=Kr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return Qp(n);case Ye.secp256k1:return Nd(n);case Ye.ECDSA:return Op(n);default:throw new Kn}}function $n(r){return Kr.encode({Type:Ye[r.type],Data:r.raw})}function R_(r){return r==null?2048:parseInt(r,10)}function L_(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 xe("Unsupported curve, should be P-256, P-384 or P-521")}async function Ll(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 xe("Only RSA and ECDSA keys are supported")}var tw=Symbol.for("nodejs.util.inspect.custom"),U_=114,rc=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()})`}[op]=!0;toString(){return this.string==null&&(this.string=Fe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1(U_,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return We(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return We(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[tw](){return`PeerId(${this.toString()})`}},nc=class extends rc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},oc=class extends rc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},ic=class extends rc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},M_=2336,sc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=yr.digest(de(this.url))}[tw](){return`PeerId(${this.url})`}[op]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(M_,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var j_=114,rw=2336;function gs(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ts(Fe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return K_(rt.parse(r));if(e==null)throw new xe('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ts(e.decode(r))}return nw(t)}function Dd(r){if(r.type==="Ed25519")return new oc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ic({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nc({multihash:r.toCID().multihash,publicKey:r});throw new Kn}function nw(r){if(V_(r))return new nc({multihash:r});if(H_(r))try{let e=ew(r);if(e.type==="Ed25519")return new oc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new ic({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new sc(new URL(t))}throw new sl("Supplied PeerID Multihash is invalid")}function K_(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==j_&&r.code!==rw)throw new il("Supplied PeerID CID is invalid");if(r.code===rw){let e=ue(r.multihash.digest);return new sc(new URL(e))}return nw(r.multihash)}function H_(r){return r.code===yr.code}function V_(r){return r.code===tr.code}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},dn=class extends Error{static name="ValidationError";name="ValidationError"},Ul=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ml=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var jl=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",f=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let y=Number.parseInt(h,e);if(!Number.isNaN(y))return y});if(p===void 0)break;if(i*=e,i+=p,i>f||(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 $_=45,F_=15,Kl=new jl;function ow(r){if(!(r.length>F_))return Kl.new(r).parseWith(()=>Kl.readIPv4Addr())}function iw(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>$_))return Kl.new(r).parseWith(()=>Kl.readIPv6Addr())}function Hl(r){return!!ow(r)}function sw(r){return!!iw(r)}function Ld(r){return e=>ue(e,r)}function Ud(r){return e=>de(e,r)}function bs(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Wo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function aw(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=de(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Wo(n);return Tt([t,o],t.length+o.length)}function cw(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=Vn.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=Wo(n);return Tt([t,o],t.length+o.length)}function Md(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ue(e,"base32"),o=bs(t);return`${n}:${o}`}var jd=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 ht("Invalid byte value in IP address");e[n]=o}),e},uw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Hl(t[n]),s;i&&(s=jd(t[n]),t[n]=ue(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new ht("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},lw=function(r){if(r.byteLength!==4)throw new ht("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},fw=function(r){if(r.byteLength!==16)throw new ht("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 ht(`Invalid IPv6 address "${t}"`)}};function hw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${r}"`)}}var Rd=Object.values(Po).map(r=>r.decoder),W_=(function(){let r=Rd[0].or(Rd[1]);return Rd.slice(2).forEach(e=>r=r.or(e)),r})();function pw(r){return W_.decode(r)}function dw(r){return e=>r.encoder.encode(e)}function q_(r){if(parseInt(r).toString()!==r)throw new dn("Value must be an integer")}function G_(r){if(r<0)throw new dn("Value must be a positive integer, or zero")}function z_(r){return e=>{if(e>r)throw new dn(`Value must be smaller than or equal to ${r}`)}}function X_(...r){return e=>{for(let t of r)t(e)}}var ac=X_(q_,G_,z_(65535));var ct=-1,Kd=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 Ml(`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)}))}},mn=new Kd,l2=[{code:4,name:"ip4",size:32,valueToBytes:jd,bytesToValue:lw,validate:r=>{if(!Hl(r))throw new dn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:273,name:"udp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:33,name:"dccp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:41,name:"ip6",size:128,valueToBytes:uw,bytesToValue:fw,stringToValue:hw,validate:r=>{if(!sw(r))throw new dn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:Ld("base10"),valueToBytes:Ud("base10")},{code:53,name:"dns",size:ct},{code:54,name:"dns4",size:ct},{code:55,name:"dns6",size:ct},{code:56,name:"dnsaddr",size:ct},{code:132,name:"sctp",size:16,valueToBytes:Wo,bytesToValue:bs,validate:ac},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:Ld("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Ud("base58btc")(r):rt.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Md,valueToBytes:aw},{code:445,name:"onion3",size:296,bytesToValue:Md,valueToBytes:cw},{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:dw(Oo),valueToBytes:pw},{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}];l2.forEach(r=>{mn.addProtocol(r)});function mw(r){let e=[],t=0;for(;t<r.length;){let n=hn(r,t),o=mn.getProtocol(n),i=Ue(n),s=f2(o,r,t+i),a=0;s>0&&o.size===ct&&(a=Ue(s));let c=i+a+s,f={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let p=t+i+a,h=r.subarray(p,p+s);f.value=o.bytesToValue?.(h)??ue(h)}e.push(f),t+=c}return e}function yw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=mn.getProtocol(n.code),i=Ue(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??de(n.value),a=s.byteLength,o.size===ct&&(c=Ue(a)));let f=new Uint8Array(i+c+a),p=0;hs(n.code,f,p),p+=i,s!=null&&(o.size===ct&&(hs(a,f,p),p+=c),f.set(s,p)),n.bytes=f}t.push(n.bytes),e+=n.bytes.byteLength}return Tt(t,e)}function gw(r){if(r.charAt(0)!=="/")throw new ht('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=mn.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 ht(`Component ${o} was missing value`);t="value"}else if(t==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ht(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return e}function bw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=mn.getProtocol(e.code);if(t==null)throw new ht(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function f2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:hn(e,t)}var h2=Symbol.for("nodejs.util.inspect.custom"),nm=Symbol.for("@multiformats/multiaddr");function p2(r){if(r==null&&(r="/"),ww(r))return r.getComponents();if(r instanceof Uint8Array)return mw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),gw(r);if(Array.isArray(r))return r;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wl=class r{[nm]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=p2(e),t.validate!==!1&&d2(this)}get bytes(){return this.#r==null&&(this.#r=yw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=bw(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}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 Ul(`Address ${this.toString()} does not contain subaddress: ${t}`);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})}equals(e){return We(this.bytes,e.bytes)}[h2](){return`Multiaddr(${this.toString()})`}};function d2(r){r.getComponents().forEach(e=>{let t=mn.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function ww(r){return!!r?.[nm]}function As(r){return new Wl(r)}var Pe=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),ce=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),xw=r=>({match:e=>r.match(e)===!1?e:!1}),Se=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),Et=(...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}}),ke=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function Ne(...r){function e(o){if(o==null)return!1;let i=o.getComponents();for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var m2=ce(421),iO=Ne(m2),Gl=ce(54),zl=ce(55),Xl=ce(56),im=ce(53),sO=Ne(Gl,Se(ce(421))),aO=Ne(zl,Se(ce(421))),cO=Ne(Xl,Se(ce(421))),uO=Ne(Et(im,Xl,Gl,zl),Se(ce(421))),vw=ke(ce(4),Se(ce(43))),Aw=ke(Se(ce(42)),ce(41),Se(ce(43))),sm=Et(vw,Aw),zo=Et(sm,im,Gl,zl,Xl),lO=Ne(Et(sm,ke(Et(im,Xl,Gl,zl),Se(ce(421))))),fO=Ne(vw),hO=Ne(Aw),pO=Ne(sm),am=ke(zo,ce(6)),cc=ke(zo,ce(273)),dO=Ne(ke(am,Se(ce(421)))),mO=Ne(cc),cm=ke(cc,Pe(460),Se(ce(421))),Zl=ke(cc,Pe(461),Se(ce(421))),y2=Et(cm,Zl),yO=Ne(cm),gO=Ne(Zl),om=Et(zo,am,cc,cm,Zl),Sw=Et(ke(om,Pe(477),Se(ce(421)))),bO=Ne(Sw),Ew=Et(ke(om,Pe(478),Se(ce(421))),ke(om,Pe(448),Se(ce(449)),Pe(477),Se(ce(421)))),wO=Ne(Ew),_w=ke(cc,Pe(280),Se(ce(466)),Se(ce(466)),Se(ce(421))),Cw=Ne(_w),Bw=ke(Zl,Pe(465),Se(ce(466)),Se(ce(466)),Se(ce(421))),xO=Ne(Bw),ql=Et(Sw,Ew,ke(am,Se(ce(421))),ke(y2,Se(ce(421))),ke(zo,Se(ce(421))),_w,Bw,ce(421)),Iw=Ne(ql),g2=ke(Se(ql),Pe(290),xw(Pe(281)),Se(ce(421))),vO=Ne(g2),b2=Et(ke(ql,Pe(290),Pe(281),Se(ce(421))),ke(ql,Pe(281),Se(ce(421))),ke(Pe(281),Se(ce(421)))),Tw=Ne(b2),w2=Et(ke(zo,ce(6),Pe(480),Se(ce(421))),ke(zo,Pe(480),Se(ce(421)))),AO=Ne(w2),x2=ke(zo,Et(ke(ce(6,"443"),Pe(480)),ke(ce(6),Pe(443)),ke(ce(6),Pe(448),Pe(480)),ke(Pe(448),Pe(480)),Pe(448),Pe(443)),Se(ce(421))),SO=Ne(x2),v2=Et(ke(ce(777),Se(ce(421)))),EO=Ne(v2),A2=Et(ke(ce(400),Se(ce(421)))),_O=Ne(A2);var _t;(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=()=>Fo(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Sr((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 f=o.uint32();switch(f>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ar(o,r.codec()),r.decode=(o,i)=>vr(o,r.codec(),i)})(_t||(_t={}));var kw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],um=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ow="libp2p+webrtc+v1/",Pw=2*1024*1024,Ss=16*1024;function S2(r=Ss){let e=Ue(r-Ue(r)),t=1+Ue(Object.keys(_t.Flag).length-1),n=1,o=r-e-t-n,i=Ue(o);return e+t+n+i}var Nw=S2();var Dw=1e4,lm="/webrtc",uc="/webrtc-signaling/0.0.1",Rw="/libp2p/webrtc-direct/certificate",Lw="webrtc-direct-certificate-private-key";var Uw=12096e5,fm=864e5;function hm(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new xe(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}function Yl(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Jl=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}},Es=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Jl(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 Jl(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 pm=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 E2(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 E2(r,e){e=e??{};let t=e.onEnd,n=new Es,o,i,s,a=Yl(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((m,S)=>{i=N=>{i=null,n.push(N);try{m(r(n))}catch(I){S(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Yl()})}},f=m=>i!=null?i(m):(n.push(m),o),p=m=>(n=new Es,i!=null?i({error:m}):(n.push({error:m}),o)),h=m=>{if(s)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:m})},y=m=>s?o:(s=!0,m!=null?p(m):f({done:!0})),b=()=>(n=new Es,y(),{done:!0}),g=m=>(y(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:b,throw:g,push:h,end:y,get readableLength(){return n.size},onEmpty:async m=>{let S=m?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let N,I;S!=null&&(N=new Promise((K,Z)=>{I=()=>{Z(new pm)},S.addEventListener("abort",I)}));try{await Promise.race([a.promise,N])}finally{I!=null&&S!=null&&S?.removeEventListener("abort",I)}}},t==null)return o;let C=o;return o={[Symbol.asyncIterator](){return this},next(){return C.next()},throw(m){return C.throw(m),t!=null&&(t(m),t=void 0),{done:!0}},return(){return C.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(m){return C.end(m),t!=null&&(t(m),t=void 0),o},get readableLength(){return C.readableLength},onEmpty:m=>C.onEmpty(m)},o}var dm=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},mm=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Mw=r=>globalThis.DOMException===void 0?new mm(r):new DOMException(r),jw=r=>{let e=r.reason===void 0?Mw("This operation was aborted."):r.reason;return e instanceof Error?e:Mw(e)};function ym(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,f=new Promise((p,h)=>{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:b}=e;b.aborted&&h(jw(b)),a=()=>{h(jw(b))},b.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,h);return}let y=new dm;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(b){h(b)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?h(o):(y.message=o??`Promise timed out after ${t} milliseconds`,h(y))},t),(async()=>{try{p(await r)}catch(b){h(b)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var _2=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function C2(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:p}=_2(r),h=async(...b)=>{let g=t.multiArgs?b:b[0];if(t.filter)try{if(!await t.filter(g))return}catch(C){n(),s(C);return}c.push(g),t.count===c.length&&(n(),i(c))},y=(...b)=>{n(),s(t.rejectionMultiArgs?b:b[0])};n=()=>{for(let b of a)p(b,h);for(let b of t.rejectionEvents)a.includes(b)||p(b,y)};for(let b of a)f(b,h);for(let b of t.rejectionEvents)a.includes(b)||f(b,y);t.signal&&t.signal.addEventListener("abort",()=>{y(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=ym(o,{milliseconds:t.timeout});return i.cancel=()=>{n(),i.clear()},i}return o}function Ct(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=C2(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var Xo=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},Ql=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function B2(r){return r.reason}async function Cs(r,e,t){if(e==null)return r;let n=t?.translateError??B2;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var I2=Math.pow(2,20)*4,Qn=class extends er{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??I2,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new me,this.writeBuffer=new me,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=_s(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new nn(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new ll(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new nn(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Xi;this.dispatchEvent(new fl(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new Zi))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new me(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new ul(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new _a(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new _a(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var ef=class extends Qn{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ct(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ct(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Kw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var tf=class extends er{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await Cs(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new nl;let t=this.onCreateStream({...this.streamOptions,...e});return Kw(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new Ql(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var rf=class extends Qn{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Ct(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Ct(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var T2=4194304,nf=class extends Error{static name="UnwrappedError";name="UnwrappedError"},lc=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},bm=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},wm=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function k2(r){return typeof r?.closeRead=="function"}function O2(r){return typeof r?.close=="function"}function gm(r){return k2(r)?r.readStatus==="closing"||r.readStatus==="closed":O2(r)?r.status!=="open":!1}function P2(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function N2(r,e){let t=e?.maxBufferSize??T2,n=new me,o,i=!1;if(!P2(r))throw new xe("Argument should be a Stream or a Multiaddr");let s=p=>{if(n.append(p.data),n.byteLength>t){let h=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${h} > ${t}`))}o?.resolve()};r.addEventListener("message",s);let a=p=>{p.error!=null?o?.reject(p.error):o?.resolve()};r.addEventListener("close",a);let c=()=>{o?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(p){if(i===!0)throw new nf("Stream was unwrapped");if(gm(r)){if(p?.bytes==null)return null;if(n.byteLength<p.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,p.bytes),new Xo(`Unexpected EOF - stream closed after reading ${n.byteLength}/${p.bytes} bytes`)}let h=p?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Cs(o.promise,p?.signal),gm(r)){if(n.byteLength===0&&p?.bytes==null)return null;break}o=Promise.withResolvers()}let y=p?.bytes??n.byteLength;if(n.byteLength<y){if(gm(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,y),new Xo(`Unexpected EOF - stream closed while reading ${n.byteLength}/${y} bytes`);return f.read(p)}let b=n.sublist(0,y);return n.consume(y),b},async write(p,h){if(i===!0)throw new nf("Stream was unwrapped");r.send(p)||await Ct(r,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return f}function of(r,e={}){let t=N2(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ue(e.maxDataLength));let n=e?.lengthDecoder??hn,o=e?.lengthEncoder??Tl;return{async read(s){let a=-1,c=new me;for(;;){let p=await t.read({...s,bytes:1});if(p==null)break;c.append(p);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new lc("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new wm(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new bm(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await t.read({...s,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new Xo(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Xo(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(s,a){await t.write(new me(o(s.byteLength),s),a)},async writeV(s,a){let c=new me(...s.flatMap(f=>[o(f.byteLength),f]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function sf(r,e){let t=of(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 D2=1024*1024*4,R2=1024*1024*4,af=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new me,this.maxBufferSize=e.maxBufferSize??D2,this.maxDataLength=e.maxDataLength??R2,this.lengthDecoder=e.lengthDecoder??hn,this.encodingLength=e.encodingLength??Ue}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new xe(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new lc("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var cf=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Bs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},uf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},fc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function lf(r){return r[Symbol.asyncIterator]!=null}function Hw(r,e){if(r.byteLength>e)throw new Bs("Message length too long")}var hf=r=>{let e=Ue(r),t=ot(e);return Tl(r,t),hf.bytes=e,t};hf.bytes=0;function hc(r,e){e=e??{};let t=e.lengthEncoder??hf,n=e?.maxDataLength??4194304;function*o(i){Hw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return lf(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}hc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??hf,n=e?.maxDataLength??4194304;return Hw(r,n),new me(t(r.byteLength),r)};var Zo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Zo||(Zo={}));var xm=r=>{let e=hn(r);return xm.bytes=Ue(e),e};xm.bytes=0;function pc(r,e){let t=new me,n=Zo.LENGTH,o=-1,i=e?.lengthDecoder??xm,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Zo.LENGTH)try{if(o=i(t),o<0)throw new cf("Invalid message length");if(o>a)throw new Bs("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(o),n=Zo.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>s)throw new uf("Message length length too long");break}throw f}if(n===Zo.DATA){if(t.byteLength<o)break;let f=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(f),yield f,n=Zo.LENGTH}}}return lf(r)?(async function*(){for await(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new fc("Unexpected end of input")})():(function*(){for(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new fc("Unexpected end of input")})()}pc.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 pc(n,{...e??{},onLength:i=>{t=i}})};var Vw=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))},M2=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var j2=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var K2=(function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r})();var H2=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var V2=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var $2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,F2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,$w=3,W2=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",$2]],Fw=[["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 qw(r){return r?Ww(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new V2:typeof navigator<"u"?Ww(navigator.userAgent):z2()}function q2(r){return r!==""&&W2.reduce(function(e,t){var n=t[0],o=t[1];if(e)return e;var i=o.exec(r);return!!i&&[n,i]},!1)}function Ww(r){var e=q2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new H2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<$w&&(o=Vw(Vw([],o,!0),X2($w-o.length),!0)):o=[];var i=o.join("."),s=G2(r),a=F2.exec(r);return a&&a[1]?new K2(t,i,s,a[1]):new M2(t,i,s)}function G2(r){for(var e=0,t=Fw.length;e<t;e++){var n=Fw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function z2(){var r=typeof process<"u"&&process.version;return r?new j2(process.version.slice(1)):null}function X2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}var Gw=qw(),pf=Gw!=null&&Gw.name==="firefox";async function vm(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??kw.map(e=>({urls:[e]})),r}var zw=(r=32)=>Ow+[...Array(r)].map(()=>um.at(Math.floor(Math.random()*um.length))).join("");var Am=class extends rf{channel;incomingData;maxBufferedAmount;receivedFinAck;finAckTimeout;constructor(e){super({...e,maxMessageSize:(e.maxMessageSize??Ss)-Nw}),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=_s(),this.maxBufferedAmount=e.maxBufferedAmount??Pw,this.finAckTimeout=e.finAckTimeout??Dw,this.channel.onclose=()=>{this.log.trace("received datachannel close event"),this.onRemoteCloseWrite(),this.onTransportClosed()},this.channel.onerror=n=>{let o=n.error;this.log.trace("received datachannel error event - %e",o),this.abort(o)},this.channel.onmessage=async n=>{this.log("incoming message %d bytes",n.data.byteLength);let{data:o}=n;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))},this.channel.bufferedAmountLowThreshold=0,this.channel.onbufferedamountlow=()=>{this.writableNeedsDrain&&this.safeDispatchEvent("drain")},Promise.resolve().then(async()=>{for await(let n of pc(this.incomingData))this.processIncomingProtobuf(n)}).catch(n=>{this.log.error("error processing incoming data channel messages - %e",n)});let t=()=>{this.channel.readyState==="open"&&(this.log.trace("stream closed, closing underlying datachannel"),this.channel.close())};this.addEventListener("close",t),this.channel.readyState!=="open"&&(this.log('channel ready state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),Ct(this.channel,"open",{rejectionEvents:["close","error"]}).then(()=>{this.log('channel ready state is now "%s", dispatching drain',this.channel.readyState),this.safeDispatchEvent("drain")}).catch(n=>{this.abort(n.error??n)}))}sendNewStream(){}_sendMessage(e){if(this.channel.readyState!=="open")throw new nn(`Invalid datachannel state - ${this.channel.readyState}`);if(this.log.trace('sending message, channel state "%s"',this.channel.readyState),pf){this.channel.send(e.subarray());return}for(let t of e)this.channel.send(t)}sendData(e){return this.channel.readyState!=="open"?{sentBytes:0,canSendMore:!1}:(this._sendMessage(hc.single(_t.encode({message:e.subarray()}))),{sentBytes:e.byteLength,canSendMore:this.channel.bufferedAmount<this.maxBufferedAmount})}sendReset(e){try{this.log.error("sending reset - %e",e),this._sendFlag(_t.Flag.RESET),this.receivedFinAck?.reject(e)}catch(t){this.log.error("failed to send reset - %e",t)}}async sendCloseWrite(e){this._sendFlag(_t.Flag.FIN),e?.signal?.throwIfAborted(),this.receivedFinAck=Promise.withResolvers(),await Promise.any([Cs(this.receivedFinAck.promise,e?.signal),Ct(this.channel,"close"),new Promise(t=>{AbortSignal.timeout(this.finAckTimeout).addEventListener("abort",()=>{t()})})])}async sendCloseRead(e){this._sendFlag(_t.Flag.STOP_SENDING),e?.signal?.throwIfAborted()}processIncomingProtobuf(e){let t=_t.decode(e);t.message!=null&&(this.readStatus==="readable"||this.readStatus==="paused")&&this.onData(new me(t.message)),t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===_t.Flag.FIN&&(this._sendFlag(_t.Flag.FIN_ACK),this.onRemoteCloseWrite()),t.flag===_t.Flag.RESET&&(this.receivedFinAck?.reject(new Xi("The stream was reset")),this.onRemoteReset()),t.flag===_t.Flag.STOP_SENDING&&this.onRemoteCloseRead(),t.flag===_t.Flag.FIN_ACK&&this.receivedFinAck?.resolve())}_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=_t.encode({flag:e}),n=hc.single(t);try{return this._sendMessage(n),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}sendPause(){}sendResume(){}};function dc(r){let{channel:e,direction:t,isHandshake:n}=r;return new Am({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`),protocol:""})}var eo=class{protocol;peerConnection;metrics;dataChannelOptions;earlyDataChannels;constructor(e){this.onEarlyDataChannel=this.onEarlyDataChannel.bind(this),this.peerConnection=e.peerConnection,this.metrics=e.metrics,this.protocol=e.protocol??lm,this.dataChannelOptions=e.dataChannelOptions??{},this.peerConnection.addEventListener("datachannel",this.onEarlyDataChannel),this.earlyDataChannels=[]}onEarlyDataChannel(e){this.earlyDataChannels.push(e.channel)}createStreamMuxer(e){return this.peerConnection.removeEventListener("datachannel",this.onEarlyDataChannel),new Sm(e,{peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,protocol:this.protocol,earlyDataChannels:this.earlyDataChannels})}},Sm=class extends tf{peerConnection;dataChannelOptions;constructor(e,t){super(e,{...t,name:"muxer"}),this.peerConnection=t.peerConnection,this.protocol=t.protocol??lm,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{this.onDataChannel(n)},queueMicrotask(()=>{if(this.status!=="open"){t.earlyDataChannels.forEach(n=>{n.close()});return}t.earlyDataChannels.forEach(n=>{this.onDataChannel(n)})})}onDataChannel(e){if(this.log("incoming datachannel with channel id %d, protocol %s and status %s",e.id,e.protocol,e.readyState),e.label==="init"){this.log.trace("closing init channel %d",e.id),e.close();return}let t=dc({...this.streamOptions,...this.dataChannelOptions,channel:e,direction:"inbound",log:this.log});this.onRemoteStream(t)}async onCreateStream(e){let t=this.peerConnection.createDataChannel("",{});return this.log("open channel %d for protocol %s",t.id,e?.protocol),dc({...e,...this.dataChannelOptions,channel:t,direction:"outbound",log:this.log})}onData(){}};var Em=class extends ef{peerConnection;constructor(e){super(e),this.peerConnection=e.peerConnection;let t=e.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change %s initial state %s",this.peerConnection.connectionState,t),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.onTransportClosed(),this.peerConnection.close())}}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.peerConnection.close(),e?.signal?.throwIfAborted()}sendReset(){this.peerConnection.close()}sendPause(){}sendResume(){}},mc=r=>new Em(r);var df=globalThis.RTCPeerConnection,mf=globalThis.RTCSessionDescription,Xw=globalThis.RTCIceCandidate;var Xt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var to=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},nr=class extends to{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var yf=class extends to{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var gf=class extends to{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},bf=class extends to{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 Mt;(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=()=>Fo(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Sr((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 f=o.uint32();switch(f>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ar(o,r.codec()),r.decode=(o,i)=>vr(o,r.codec(),i)})(Mt||(Mt={}));var wf=async(r,e,t)=>{try{let n=Promise.withResolvers();for(Z2(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Mt.Type.ICE_CANDIDATE)throw new al("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Xt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Xw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Xt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received %o - %e",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate - %e",t.direction,n),t.signal?.aborted===!0&&r.connectionState!=="connected")throw n}};function Z2(r,e){if(r.connectionState==="connected"){e.resolve();return}r.onconnectionstatechange=t=>{switch(r.connectionState){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new rl(`RTCPeerConnection connection state became "${r.connectionState}"`));break;default:break}}}function xf(r){let e;for(let t of r.getComponents())t.name==="p2p"&&(e=gs(t.value??""));if(e==null)throw new ol("Remote peerId must be present in multiaddr");return e}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:f}){let{circuitAddress:p,targetPeer:h}=Yw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",p);let y=i.getConnections(h),b;y.length===0?(f?.(new Xt("webrtc:dial-relay")),b=await s.dial(p,{signal:t,onProgress:f})):(f?.(new Xt("webrtc:reuse-relay-connection")),b=y[0]),f?.(new Xt("webrtc:open-signaling-stream"));let g=await b.newStream(uc,{signal:t,runOnLimitedConnection:!0}),C=sf(g).pb(Mt),m=new df(r);m.addEventListener("connectionstatechange",()=>{switch(m.connectionState){case"closed":m.close();break;default:break}});let S=new eo({peerConnection:m,dataChannelOptions:e});try{let N=m.createDataChannel("init");m.onicecandidate=({candidate:q})=>{if(m.connectionState==="connected"){a.trace("ignore new ice candidate as peer connection is already connected");return}if(q==null||q?.candidate===""){a.trace("initiator detected end of ICE candidates");return}let re=JSON.stringify(q?.toJSON()??null);a.trace("initiator sending ICE candidate %o",q),C.write({type:Mt.Type.ICE_CANDIDATE,data:re},{signal:t}).catch(R=>{a.error("error sending ICE candidate - %e",R)})},m.onicecandidateerror=q=>{a.error("initiator ICE candidate error",q)};let I=await m.createOffer().catch(q=>{throw a.error("could not execute createOffer - %e",q),new nr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",I.sdp),f?.(new Xt("webrtc:send-sdp-offer")),await C.write({type:Mt.Type.SDP_OFFER,data:I.sdp},{signal:t}),await m.setLocalDescription(I).catch(q=>{throw a.error("could not execute setLocalDescription - %e",q),new nr("Failed to set localDescription")}),f?.(new Xt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let K=await C.read({signal:t});if(K.type!==Mt.Type.SDP_ANSWER)throw new nr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",K.data);let Z=new mf({type:"answer",sdp:K.data});return await m.setRemoteDescription(Z).catch(q=>{throw a.error("could not execute setRemoteDescription - %e",q),new nr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),f?.(new Xt("webrtc:read-ice-candidates")),await wf(m,C,{direction:"initiator",signal:t,log:a,onProgress:f}),a.trace("initiator connected"),N.readyState!=="open"&&(a.trace("wait for init channel to open"),await Ct(N,"open",{signal:t})),a.trace("closing init channel"),N.close(),a.trace("waiting for init channel to close"),await Ct(N,"close",{signal:t}),f?.(new Xt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await g.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:m,muxerFactory:S}}catch(N){throw a.error("outgoing signaling error - %e",N),m.close(),g.abort(N),N}finally{m.onicecandidate=null,m.onicecandidateerror=null}}var Jw=Ne(Iw.matchers[0],Pe(290)),vf=class r extends er{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=>Jw.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=>Jw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function Qw(r,e,{peerConnection:t,signal:n,log:o}){o.trace("new inbound signaling stream");let i=sf(r).pb(Mt);try{t.onicecandidate=({candidate:h})=>{if(t.connectionState==="connected"){o.trace("ignore new ice candidate as peer connection is already connected");return}if(h==null||h?.candidate===""){o.trace("recipient detected end of ICE candidates");return}let y=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",y),i.write({type:Mt.Type.ICE_CANDIDATE,data:y},{signal:n}).catch(b=>{o.error("error sending ICE candidate - %e",b)})},o.trace("recipient read SDP offer");let c=await i.read({signal:n});if(c.type!==Mt.Type.SDP_OFFER)throw new nr(`expected message type SDP_OFFER, received: ${c.type??"undefined"} `);o.trace("recipient received SDP offer %s",c.data);let f=new mf({type:"offer",sdp:c.data});await t.setRemoteDescription(f).catch(h=>{throw o.error("could not execute setRemoteDescription - %e",h),new nr("Failed to set remoteDescription")});let p=await t.createAnswer().catch(h=>{throw o.error("could not execute createAnswer - %e",h),new nr("Failed to create answer")});o.trace("recipient send SDP answer %s",p.sdp),await i.write({type:Mt.Type.SDP_ANSWER,data:p.sdp},{signal:n}),await t.setLocalDescription(p).catch(h=>{throw o.error("could not execute setLocalDescription - %e",h),new nr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await wf(t,i,{direction:"recipient",signal:n,log:o})}catch(c){if(t.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a - %e",e.remoteAddr,c),t.close(),c;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",e.remoteAddr,c)}let s=xf(e.remoteAddr),a=As(`/webrtc/p2p/${s}`);return o.trace("recipient connected to remote address %s",a),{remoteAddress:a,remotePeer:s}}var Af=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"})})}[hl]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Yi]=["@libp2p/transport"];[Zg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(uc,(e,t)=>{let n=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t,n).catch(o=>{this.log.error("failed to handle incoming connect from %p - %e",t.remotePeer,o)}).finally(()=>{n.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(uc),this._started=!1}createListener(e){return new vf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Tw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await vm(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=mc({peerConnection:o,remoteAddr:n,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,remotePeer:xf(e),muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol(e,t,n){let o=new df(await vm(this.init.rtcConfiguration));o.addEventListener("connectionstatechange",()=>{switch(o.connectionState){case"closed":o.close();break;default:break}});let i=new eo({peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s,remotePeer:a}=await Qw(e,t,{peerConnection:o,signal:n,log:this.log});await e.close({signal:n});let c=mc({peerConnection:o,remoteAddr:s,metrics:this.metrics?.listenerEvents,direction:"inbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")});await this.components.upgrader.upgradeInbound(c,{skipEncryption:!0,skipProtection:!0,remotePeer:a,muxerFactory:i,signal:n}),this._closeOnShutdown(o,c)}catch(s){throw this.log.error("incoming signaling error - %e",s),o.close(),e.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection - %e",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Yw(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new xe("Destination peer id was missing");return{circuitAddress:As(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:gs(e)}}var tz=Rr(tx());var Fr={};vt(Fr,{Any:()=>Vr,BaseBlock:()=>Je,BaseStringBlock:()=>wc,BitString:()=>Br,BmpString:()=>ti,Boolean:()=>Jo,CharacterString:()=>li,Choice:()=>ks,Constructed:()=>Qe,DATE:()=>_c,DateTime:()=>Bc,Duration:()=>Ic,EndOfContent:()=>xc,Enumerated:()=>Qo,GeneralString:()=>ui,GeneralizedTime:()=>fi,GraphicString:()=>ci,HexBlock:()=>$r,IA5String:()=>ai,Integer:()=>vn,Null:()=>_r,NumericString:()=>ni,ObjectIdentifier:()=>ei,OctetString:()=>Cr,Primitive:()=>xn,PrintableString:()=>oi,RawData:()=>Im,RelativeObjectIdentifier:()=>Ec,Repeated:()=>hi,Sequence:()=>Bt,Set:()=>Pt,TIME:()=>Tc,TeletexString:()=>ii,TimeOfDay:()=>Cc,UTCTime:()=>oo,UniversalString:()=>ri,Utf8String:()=>ir,ValueBlock:()=>pt,VideotexString:()=>si,ViewWriter:()=>Ts,VisibleString:()=>no,compareSchema:()=>bn,fromBER:()=>Sn,verifySchema:()=>gC});var ye=Rr(gn());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 ro(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 f=new Uint8Array(c);for(let p=a-1;p>=0;p--){let h=Math.pow(2,p*e);f[i-p-1]=Math.floor(o/h),o-=f[i-p-1]*h}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function _f(...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 Cm(){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 rx(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=ro(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ro(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 nx(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function jt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var pN=Math.log(2);function Cf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Tm(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 An(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 Tm(this.items)}},yc=[new Uint8Array([1])],ox="0123456789",Bm="name",ix="valueHexView",iC="isHexOnly",sC="idBlock",aC="tagClass",cC="tagNumber",uC="isConstructed",lC="fromBER",fC="toBER",hC="local",Kt="",Ir=new ArrayBuffer(0),Hf=new Uint8Array(0),bc="EndOfContent",ax="OCTET STRING",cx="BIT STRING";function $r(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?ye.BufferSourceConverter.toUint8Array(i.valueHex):Hf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!An(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",Ir)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ye.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wn=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=Hf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ye.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ye.Convert.ToHex(this.valueBeforeDecodeView)}}};wn.NAME="baseBlock";var pt=class extends wn{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 Bf=class extends $r(wn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?ye.BufferSourceConverter.toUint8Array(e.valueHex):Hf,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",Ir}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=ro(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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,f=this.valueHexView=new Uint8Array(255),p=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===p){p+=255;let y=new Uint8Array(p);for(let b=0;b<f.length;b++)y[b]=f[b];f=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,f[c-1]=i[c]&127;let h=new Uint8Array(c);for(let y=0;y<c;y++)h[y]=f[y];f=this.valueHexView=new Uint8Array(c),f.set(h),this.blockLength<=9?this.tagNumber=Yo(f,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}}};Bf.NAME="identificationBlock";var If=class extends wn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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=ro(this.length,8);if(o.byteLength>127)return this.error="Too big length",Ir;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}}};If.NAME="lengthBlock";var X={},Je=class extends wn{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 Bf(o),this.lenBlock=new If(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||ux(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?Ir:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():ye.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ye.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return nx(t,n)}};Je.NAME="BaseBlock";function ux(r){var e;if(r instanceof X.Constructed)for(let t of r.valueBlock.value)ux(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var wc=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}'`}};wc.NAME="BaseStringBlock";var Tf=class extends $r(pt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Tf.NAME="PrimitiveValueBlock";var lx,xn=class extends Je{constructor(e={}){super(e,Tf),this.idBlock.isConstructed=!1}};lx=xn;X.Primitive=lx;xn.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 wn;if(!An(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=X.EndOfContent;break;case 1:c=X.Boolean;break;case 2:c=X.Integer;break;case 3:c=X.BitString;break;case 4:c=X.OctetString;break;case 5:c=X.Null;break;case 6:c=X.ObjectIdentifier;break;case 10:c=X.Enumerated;break;case 12:c=X.Utf8String;break;case 13:c=X.RelativeObjectIdentifier;break;case 14:c=X.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=X.Sequence;break;case 17:c=X.Set;break;case 18:c=X.NumericString;break;case 19:c=X.PrintableString;break;case 20:c=X.TeletexString;break;case 21:c=X.VideotexString;break;case 22:c=X.IA5String;break;case 23:c=X.UTCTime;break;case 24:c=X.GeneralizedTime;break;case 25:c=X.GraphicString;break;case 26:c=X.VisibleString;break;case 27:c=X.GeneralString;break;case 28:c=X.UniversalString;break;case 29:c=X.CharacterString;break;case 30:c=X.BmpString;break;case 31:c=X.DATE;break;case 32:c=X.TimeOfDay;break;case 33:c=X.DateTime;break;case 34:c=X.Duration;break;default:{let f=o.idBlock.isConstructed?new X.Constructed:new X.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?X.Constructed:X.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 Sn(r){if(!r.byteLength){let e=new Je({},pt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Os(ye.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function dC(r,e){return r?1:e}var Hr=class extends pt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;dC(this.isIndefiniteForm,n)>0;){let s=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===bc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===bc?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?Ir:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Hr.NAME="ConstructedValueBlock";var fx,Qe=class extends Je{constructor(e={}){super(e,Hr),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} :`}};fx=Qe;X.Constructed=fx;Qe.NAME="CONSTRUCTED";var kf=class extends pt{fromBER(e,t,n){return t}toBER(e){return Ir}};kf.override="EndOfContentValueBlock";var hx,xc=class extends Je{constructor(e={}){super(e,kf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};hx=xc;X.EndOfContent=hx;xc.NAME=bc;var px,_r=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}`}};px=_r;X.Null=px;_r.NAME="NULL";var Of=class extends $r(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=ye.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);return An(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,Cm.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Of.NAME="BooleanValueBlock";var dx,Jo=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Of),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};dx=Jo;X.Boolean=dx;Jo.NAME="BOOLEAN";var Pf=class extends $r(Hr){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=Hr.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===bc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==ax)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?Hr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Pf.NAME="OctetStringValueBlock";var km,Cr=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},Pf),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=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 Qe.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ye.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof km&&e.push(t.valueBlock.valueHexView);return ye.BufferSourceConverter.concat(e)}};km=Cr;X.OctetString=km;Cr.NAME=ax;var Nf=class extends $r(Hr){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=Hr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===bc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==cx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=ye.BufferSourceConverter.toUint8Array(e);if(!An(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 Hr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Ir;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}}};Nf.NAME="BitStringValueBlock";var mx,Br=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},Nf),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 Qe.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}`}}};mx=Br;X.BitString=mx;Br.NAME=cx;var yx;function mC(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,f=0,p=c<s?s:c,h=0;for(let y=p;y>=0;y--,h++){switch(!0){case h<a.length:f=i[s-h]+a[c-h]+t[0];break;default:f=i[s-h]+t[0]}switch(t[0]=f/10,!0){case h>=i.length:i=_f(new Uint8Array([f%10]),i);break;default:i[s-h]=f%10}}return t[0]>0&&(i=_f(t,i)),i}function sx(r){if(r>=yc.length)for(let e=yc.length;e<=r;e++){let t=new Uint8Array([0]),n=yc[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=_f(t,n)),yc.push(n)}return yc[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,f,p=0;for(let h=c;h>=0;h--,p++)switch(f=i[s-p]-a[c-p]-t,!0){case f<0:t=1,i[s-p]=f+10;break;default:t=0,i[s-p]=f}if(t>0)for(let h=s-c+1;h>=0;h--,p++)if(f=i[s-p]-t,f<0)t=1,i[s-p]=f+10;else{t=0,i[s-p]=f;break}return i.slice()}var vc=class extends $r(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=Cm.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(rx(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 f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=yC(sx(n),t),s="-";break;default:t=mC(t,sx(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=ox.charAt(t[c]));return a===!1&&(s+=ox.charAt(0)),s}};yx=vc;vc.NAME="IntegerValueBlock";Object.defineProperty(yx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var gc,vn=class extends Je{constructor(e={}){super(e,vc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Cf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Cf();let t=BigInt(e),n=new Ts,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ye.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${ye.Convert.ToHex(a)}`)+t,p=ye.BufferSourceConverter.toUint8Array(ye.Convert.FromHex(f.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new gc({valueHex:n.final()})}convertToDER(){let e=new gc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new gc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};gc=vn;X.Integer=gc;vn.NAME="INTEGER";var gx,Qo=class extends vn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};gx=Qo;X.Enumerated=gx;Qo.NAME="ENUMERATED";var Ac=class extends $r(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=ye.BufferSourceConverter.toUint8Array(e);if(!An(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){Cf();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=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Ir;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=ye.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Ac.NAME="sidBlock";var Df=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 Ac;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,Ir;t.push(o)}return Tm(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 Ac;if(o>Number.MAX_SAFE_INTEGER){Cf();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}};Df.NAME="ObjectIdentifierValueBlock";var bx,ei=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Df),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};bx=ei;X.ObjectIdentifier=bx;ei.NAME="OBJECT IDENTIFIER";var Sc=class extends $r(wn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Ir;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ye.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Sc.NAME="relativeSidBlock";var Rf=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 Sc;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,Ir;n.push(i)}return Tm(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 Sc;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}};Rf.NAME="RelativeObjectIdentifierValueBlock";var wx,Ec=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Rf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};wx=Ec;X.RelativeObjectIdentifier=wx;Ec.NAME="RelativeObjectIdentifier";var xx,Ct=class extends Qe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};xx=Ct;X.Sequence=xx;Ct.NAME="SEQUENCE";var vx,Pt=class extends Qe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};vx=Pt;X.Set=vx;Pt.NAME="SET";var Lf=class extends $r(pt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Kt}toJSON(){return{...super.toJSON(),value:this.value}}};Lf.NAME="StringValueBlock";var Uf=class extends Lf{};Uf.NAME="SimpleStringValueBlock";var Nt=class extends wc{constructor({...e}={}){super(e,Uf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ye.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Nt.NAME="SIMPLE STRING";var Mf=class extends Nt{fromBuffer(e){this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ye.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ye.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Mf.NAME="Utf8StringValueBlock";var Ax,ir=class extends Mf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ax=ir;X.Utf8String=Ax;ir.NAME="UTF8String";var jf=class extends Nt{fromBuffer(e){this.valueBlock.value=ye.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf16String(e))}};jf.NAME="BmpStringValueBlock";var Sx,ti=class extends jf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Sx=ti;X.BmpString=Sx;ti.NAME="BMPString";var Kf=class extends Nt{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=ro(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}};Kf.NAME="UniversalStringValueBlock";var Ex,ri=class extends Kf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ex=ri;X.UniversalString=Ex;ri.NAME="UniversalString";var _x,ni=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};_x=ni;X.NumericString=_x;ni.NAME="NumericString";var Cx,oi=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Cx=oi;X.PrintableString=Cx;oi.NAME="PrintableString";var Bx,ii=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Bx=ii;X.TeletexString=Bx;ii.NAME="TeletexString";var Ix,si=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ix=si;X.VideotexString=Ix;si.NAME="VideotexString";var Tx,ai=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Tx=ai;X.IA5String=Tx;ai.NAME="IA5String";var kx,ci=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};kx=ci;X.GraphicString=kx;ci.NAME="GraphicString";var Ox,no=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ox=no;X.VisibleString=Ox;no.NAME="VisibleString";var Px,ui=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Px=ui;X.GeneralString=Px;ui.NAME="GeneralString";var Nx,li=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Nx=li;X.CharacterString=Nx;li.NAME="CharacterString";var Dx,oo=class extends no{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ye.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=jt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=jt(this.month,2),t[2]=jt(this.day,2),t[3]=jt(this.hour,2),t[4]=jt(this.minute,2),t[5]=jt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Dx=oo;X.UTCTime=Dx;oo.NAME="UTCTime";var Rx,fi=class extends oo{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 h=new Number(e[e.length-1]);if(isNaN(h.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 h=1,y=n.indexOf("+"),b="";if(y===-1&&(y=n.indexOf("-"),h=-1),y!==-1){if(b=n.substring(y+1),n=n.substring(0,y),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(b.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*g,b.length===4){if(g=parseInt(b.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=h*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let h=new Number(`0${n.substring(f)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-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,f!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}let p=s.exec(o);if(p===null)throw new Error("Wrong input string for conversion");for(let h=1;h<p.length;h++)switch(h){case 1:this.year=parseInt(p[h],10);break;case 2:this.month=parseInt(p[h],10);break;case 3:this.day=parseInt(p[h],10);break;case 4:this.hour=parseInt(p[h],10)+a;break;case 5:this.minute=parseInt(p[h],10)+c;break;case 6:this.second=parseInt(p[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(jt(this.year,4)),t.push(jt(this.month,2)),t.push(jt(this.day,2)),t.push(jt(this.hour,2)),t.push(jt(this.minute,2)),t.push(jt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(jt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Rx=fi;X.GeneralizedTime=Rx;fi.NAME="GeneralizedTime";var Lx,_c=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Lx=_c;X.DATE=Lx;_c.NAME="DATE";var Ux,Cc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Ux=Cc;X.TimeOfDay=Ux;Cc.NAME="TimeOfDay";var Mx,Bc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Mx=Bc;X.DateTime=Mx;Bc.NAME="DateTime";var jx,Ic=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};jx=Ic;X.Duration=jx;Ic.NAME="Duration";var Kx,Tc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Kx=Tc;X.TIME=Kx;Tc.NAME="TIME";var Vr=class{constructor({name:e=Kt,optional:t=!1}={}){this.name=e,this.optional=t}},ks=class extends Vr{constructor({value:e=[],...t}={}){super(t),this.value=e}},hi=class extends Vr{constructor({value:e=new Vr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Im=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Hf}={}){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ye.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function bn(r,e,t){if(t instanceof ks){for(let i of t.value)if(bn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Bm)&&(i.name=t.name),i}}if(t instanceof Vr)return t.hasOwnProperty(Bm)&&(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(!(sC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(lC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(fC 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(aC)===!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(cC)===!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(uC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(iC 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(!(ix 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 X.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof hi&&(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 f=0;f<t.valueBlock.value.length;f++)c=c&&(t.valueBlock.value[f].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 f={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],f.name=t.name)),f}}else if(t.valueBlock.value[0]instanceof hi){if(s=bn(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(Bm in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let f={};hC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?f=e:f=r,typeof f[t.valueBlock.value[0].name]>"u"&&(f[t.valueBlock.value[0].name]=[]),f[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=bn(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&&ix 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 bn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function gC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Os(ye.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:bn(t.result,t.result,e)}var x;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(x||(x={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var Om=Rr(gn()),Wr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Om.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Om.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Br))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Br({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Br({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Pm=Rr(gn()),ie=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Pm.BufferSourceConverter.isBufferSource(e)?this.buffer=Pm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Cr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Cr({valueHex:this.buffer})}toSchema(e){return new Cr({name:e})}};var bC={fromASN:r=>r instanceof _r?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new _r;let e=Sn(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 vn({value:+r})},xC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Qo({value:r})},ge={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new vn({valueHex:r})};var vC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Br({valueHex:r})},AC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ei({value:r})},SC={fromASN:r=>r.valueBlock.value,toASN:r=>new Jo({value:r})},Ps={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Cr({valueHex:r})},Hx={fromASN:r=>new ie(r.getValue()),toASN:r=>r.toASN()};function sr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Nm=sr(ir),EC=sr(ti),_C=sr(ri),CC=sr(ni),BC=sr(oi),IC=sr(ii),TC=sr(si),kC=sr(ai),OC=sr(ci),PC=sr(no),NC=sr(ui),DC=sr(li),RC={fromASN:r=>r.toDate(),toASN:r=>new oo({valueDate:r})},LC={fromASN:r=>r.toDate(),toASN:r=>new fi({valueDate:r})},UC={fromASN:()=>null,toASN:()=>new _r};function io(r){switch(r){case d.Any:return bC;case d.BitString:return vC;case d.BmpString:return EC;case d.Boolean:return SC;case d.CharacterString:return DC;case d.Enumerated:return xC;case d.GeneralString:return NC;case d.GeneralizedTime:return LC;case d.GraphicString:return OC;case d.IA5String:return kC;case d.Integer:return wC;case d.Null:return UC;case d.NumericString:return CC;case d.ObjectIdentifier:return AC;case d.OctetString:return Ps;case d.PrintableString:return BC;case d.TeletexString:return IC;case d.UTCTime:return RC;case d.UniversalString:return _C;case d.Utf8String:return Nm;case d.VideotexString:return TC;case d.VisibleString:return PC;default:return null}}function ar(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:ar(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Rm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Rm(t)}return!1}function Vx(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 Vf=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:x.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let p=d[s.type],h=Fr[p];if(!h)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new h({name:a})}else ar(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===x.Choice?c=new Vr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Vr({name:a});let f=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Pt:Ct;c=new p({name:"",value:[new hi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||ar(s.type)){let p=s.repeated?Qe:xn;o.push(new p({name:a,optional:f,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,h=p?c:this.get(s.type,!0).schema;h="valueBlock"in h?h.valueBlock.value:h.value,o.push(new Qe({name:p?"":a,optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:h}))}else o.push(new Qe({optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=f,o.push(c)}switch(n.type){case x.Sequence:return new Ct({value:o,name:""});case x.Set:return new Pt({value:o,name:""});case x.Choice:return new ks({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var qe=new Vf;var _=r=>e=>{let t;qe.has(e)?t=qe.get(e):(t=qe.createDefault(e),qe.set(e,t)),Object.assign(t,r)};var l=r=>(e,t)=>{let n;qe.has(e.constructor)?n=qe.get(e.constructor):(n=qe.createDefault(e.constructor),qe.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=io(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}o.raw=r.raw,n.items[t]=o};var so=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var kc=class{static parse(e,t){let n=Sn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(ar(t))return new t().fromASN(e);let n=qe.get(t);qe.cache(t);let o=n.schema,i=this.handleChoiceTypes(e,n,t,o);if(i?.result)return i.result;i?.targetSchema&&(o=i.targetSchema);let s=this.handleSequenceTypes(e,n,t,o);if(s&&"isManualMapping"in s)return s.result;let a=s,c=new t;return Rm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof so&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===Qe&&t.type===x.Choice&&e.idBlock.tagClass===3)for(let i in t.items){let s=t.items[i];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&qe.has(s.type)){let a=qe.get(s.type);if(a&&a.type===x.Sequence){let c=new Ct;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let f=this.fromASN(c,s.type),p=new n;return p[i]=f,{result:p}}}}}else if(e.constructor===Qe&&t.type!==x.Choice){let i=new Qe({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(let s in t.items)delete e[s];return{targetSchema:i}}return null}static handleSequenceTypes(e,t,n,o){if(t.type===x.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&qe.has(c.type)&&qe.get(c.type).type===x.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=bn({},e,o);if(!s.verified)throw new so(`Data does not match to ${n.name} ASN1 schema.${s.result.error?` ${s.result.error}`:""}`);return s}else{let i=bn({},e,o);if(!i.verified)throw new so(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let f=s[c],p=t.items[f];if(a>=i.length)break;if(p.repeated){o[f]=this.processRepeatedField(i,a,p);break}else if(typeof p.type=="number")o[f]=this.processPrimitiveField(i[a],p),a++;else if(this.isOptionalChoiceField(p)){let h=this.processOptionalChoiceField(i[a],p);h.processed&&(o[f]=h.value,a++)}else o[f]=this.fromASN(i[a],p.type),a++}return{result:o,verified:!0,isManualMapping:!0}}static processRepeatedField(e,t,n){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){let i=o[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(o=i.valueBlock.value)}if(typeof n.type=="number"){let i=io(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return i.fromASN(s)}catch{return}}).filter(s=>s!==void 0)}else return o.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,t){let n=io(t.type);if(!n)throw new Error(`No converter for ASN.1 type ${t.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&qe.has(e.type)&&qe.get(e.type).type===x.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof so&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,t,n){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let o=t.itemType;if(typeof o=="number"){let i=io(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type,c;typeof a=="number"||ar(a)?c=this.processPrimitiveSchemaItem(i,s,a):c=this.processComplexSchemaItem(i,s,a),c&&typeof c=="object"&&"value"in c&&"raw"in c?(n[o]=c.value,n[`${o}Raw`]=c.raw):n[o]=c}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:ar(n)?new n:null;if(!i)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,i):this.processSinglePrimitiveItem(e,t,n,i)}static processRepeatedPrimitiveItem(e,t,n){if(t.implicit){let o=t.repeated==="sequence"?Ct:Pt,i=new o;i.valueBlock=e.valueBlock;let s=Sn(i.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let a=s.result.valueBlock.value;return Array.from(a,c=>n.fromASN(c))}else return Array.from(e,o=>n.fromASN(o))}static processSinglePrimitiveItem(e,t,n,o){let i=e;if(t.implicit){let s;if(ar(n))s=new n().toSchema("");else{let a=d[n],c=Fr[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Sn(s.toBER(!1)).result}return o.fromASN(i)}static processComplexSchemaItem(e,t,n){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,n))}else{let o=this.handleImplicitTagging(e,t,n);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,n)}catch(i){if(i instanceof so&&/Wrong values for Choice type/.test(i.message))return;throw i}else{let i=this.fromASN(o,n);return t.raw?{value:i,raw:e.valueBeforeDecodeView}:i}}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=qe.get(n);if(o.type===x.Sequence){let i=new Ct;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(o.type===x.Set){let i=new Pt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var Oc=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"&&ar(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=qe.get(t);qe.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=io(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"&&Vx(this.serialize(a.defaultValue),this.serialize(c)))continue;let f=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||ar(a.type))){let p={};p.valueHex=f instanceof _r?f.valueBeforeDecodeView:f.valueBlock.toBER(),o.push(new xn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new Qe({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:f.valueBlock.value}));else o.push(new Qe({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[f]}));else a.repeated?o=o.concat(f):o.push(f)}let i;switch(n.type){case x.Sequence:i=new Ct({value:o});break;case x.Set:i=new Pt({value:o});break;case x.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,f=>s.toASN(f)),c=e.repeated==="sequence"?Ct:Pt;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"?Ct:Pt;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 Lm=Rr(gn());var F=class r{static serialize(e){return Oc.serialize(e)}static parse(e,t){return kc.parse(e,t)}static toString(e){let t=Lm.BufferSourceConverter.isBufferSource(e)?Lm.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Sn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function u(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 he(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)}function Me(r,e,t,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!o:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(r,t):o?o.value=t:e.set(r,t),t}var $x=Rr(gn()),Pc=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,f)=>c+(f.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP($x.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 Fx=Rr(gn()),Um,Mm,jm,et=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};u([l({type:d.TeletexString})],et.prototype,"teletexString",void 0);u([l({type:d.PrintableString})],et.prototype,"printableString",void 0);u([l({type:d.UniversalString})],et.prototype,"universalString",void 0);u([l({type:d.Utf8String})],et.prototype,"utf8String",void 0);u([l({type:d.BmpString})],et.prototype,"bmpString",void 0);et=u([_({type:x.Choice})],et);var Ns=class extends et{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Fx.Convert.ToHex(this.anyValue):super.toString())}};u([l({type:d.IA5String})],Ns.prototype,"ia5String",void 0);u([l({type:d.Any})],Ns.prototype,"anyValue",void 0);Ns=u([_({type:x.Choice})],Ns);var pi=class{constructor(e={}){this.type="",this.value=new Ns,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],pi.prototype,"type",void 0);u([l({type:Ns})],pi.prototype,"value",void 0);var ao=Um=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Um.prototype)}};ao=Um=u([_({type:x.Set,itemType:pi})],ao);var Km=Mm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};Km=Mm=u([_({type:x.Sequence,itemType:ao})],Km);var Oe=jm=class extends Km{constructor(e){super(e),Object.setPrototypeOf(this,jm.prototype)}};Oe=jm=u([_({type:x.Sequence})],Oe);var MC={fromASN:r=>Pc.toString(Ps.fromASN(r)),toASN:r=>Ps.toASN(Pc.fromString(r))},co=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],co.prototype,"typeId",void 0);u([l({type:d.Any,context:0})],co.prototype,"value",void 0);var Nc=class{constructor(e={}){this.partyName=new et,Object.assign(this,e)}};u([l({type:et,optional:!0,context:0,implicit:!0})],Nc.prototype,"nameAssigner",void 0);u([l({type:et,context:1,implicit:!0})],Nc.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};u([l({type:co,context:0,implicit:!0})],ae.prototype,"otherName",void 0);u([l({type:d.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);u([l({type:d.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);u([l({type:d.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);u([l({type:Oe,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);u([l({type:Nc,context:5})],ae.prototype,"ediPartyName",void 0);u([l({type:d.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);u([l({type:d.OctetString,context:7,implicit:!0,converter:MC})],ae.prototype,"iPAddress",void 0);u([l({type:d.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=u([_({type:x.Choice})],ae);var uo="1.3.6.1.5.5.7",lo=`${uo}.1`,Wx=`${uo}.2`,di=`${uo}.3`,$f=`${uo}.48`,A3=`${Wx}.1`,S3=`${Wx}.2`,Hm=`${$f}.1`,Vm=`${$f}.2`,$m=`${$f}.3`,Fm=`${$f}.5`,le="2.5.29";var Wm,Ff=`${lo}.1`,En=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],En.prototype,"accessMethod",void 0);u([l({type:ae})],En.prototype,"accessLocation",void 0);var mi=Wm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Wm.prototype)}};mi=Wm=u([_({type:x.Sequence,itemType:En})],mi);var Wf=`${le}.35`,yi=class extends ie{},qr=class{constructor(e={}){e&&Object.assign(this,e)}};u([l({type:yi,context:0,optional:!0,implicit:!0})],qr.prototype,"keyIdentifier",void 0);u([l({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],qr.prototype,"authorityCertIssuer",void 0);u([l({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ge})],qr.prototype,"authorityCertSerialNumber",void 0);var qf=`${le}.19`,gi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};u([l({type:d.Boolean,defaultValue:!1})],gi.prototype,"cA",void 0);u([l({type:d.Integer,optional:!0})],gi.prototype,"pathLenConstraint",void 0);var qm,je=qm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qm.prototype)}};je=qm=u([_({type:x.Sequence,itemType:ae})],je);var Gm,jC=`${le}.29`,qx=Gm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};qx=Gm=u([_({type:x.Sequence})],qx);var zm,zf=`${le}.32`,tD=`${zf}.0`,_n=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};u([l({type:d.IA5String})],_n.prototype,"ia5String",void 0);u([l({type:d.VisibleString})],_n.prototype,"visibleString",void 0);u([l({type:d.BmpString})],_n.prototype,"bmpString",void 0);u([l({type:d.Utf8String})],_n.prototype,"utf8String",void 0);_n=u([_({type:x.Choice})],_n);var Dc=class{constructor(e={}){this.organization=new _n,this.noticeNumbers=[],Object.assign(this,e)}};u([l({type:_n})],Dc.prototype,"organization",void 0);u([l({type:d.Integer,repeated:"sequence"})],Dc.prototype,"noticeNumbers",void 0);var Rc=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Dc,optional:!0})],Rc.prototype,"noticeRef",void 0);u([l({type:_n,optional:!0})],Rc.prototype,"explicitText",void 0);var Gf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.IA5String})],Gf.prototype,"cPSuri",void 0);u([l({type:Rc})],Gf.prototype,"userNotice",void 0);Gf=u([_({type:x.Choice})],Gf);var Lc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Lc.prototype,"policyQualifierId",void 0);u([l({type:d.Any})],Lc.prototype,"qualifier",void 0);var bi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],bi.prototype,"policyIdentifier",void 0);u([l({type:Lc,repeated:"sequence",optional:!0})],bi.prototype,"policyQualifiers",void 0);var Uc=zm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,zm.prototype)}};Uc=zm=u([_({type:x.Sequence,itemType:bi})],Uc);var uD=`${le}.20`,Mc=class{constructor(e=0){this.value=e}};u([l({type:d.Integer})],Mc.prototype,"value",void 0);Mc=u([_({type:x.Choice})],Mc);var yD=`${le}.27`,Gx=class extends Mc{};Gx=u([_({type:x.Choice})],Gx);var Xm,Xf=`${le}.31`,Tr;(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"})(Tr||(Tr={}));var jc=class extends Wr{toJSON(){let e=[],t=this.toNumber();return t&Tr.aACompromise&&e.push("aACompromise"),t&Tr.affiliationChanged&&e.push("affiliationChanged"),t&Tr.cACompromise&&e.push("cACompromise"),t&Tr.certificateHold&&e.push("certificateHold"),t&Tr.cessationOfOperation&&e.push("cessationOfOperation"),t&Tr.keyCompromise&&e.push("keyCompromise"),t&Tr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Tr.superseded&&e.push("superseded"),t&Tr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Cn=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,context:0,repeated:"sequence",implicit:!0})],Cn.prototype,"fullName",void 0);u([l({type:ao,context:1,implicit:!0})],Cn.prototype,"nameRelativeToCRLIssuer",void 0);Cn=u([_({type:x.Choice})],Cn);var Gr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Cn,context:0,optional:!0})],Gr.prototype,"distributionPoint",void 0);u([l({type:jc,context:1,optional:!0,implicit:!0})],Gr.prototype,"reasons",void 0);u([l({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],Gr.prototype,"cRLIssuer",void 0);var fo=Xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};fo=Xm=u([_({type:x.Sequence,itemType:Gr})],fo);var Zm,OD=`${le}.46`,zx=Zm=class extends fo{constructor(e){super(e),Object.setPrototypeOf(this,Zm.prototype)}};zx=Zm=u([_({type:x.Sequence,itemType:Gr})],zx);var jD=`${le}.28`,Zt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Zt.ONLY=!1;u([l({type:Cn,context:0,optional:!0})],Zt.prototype,"distributionPoint",void 0);u([l({type:d.Boolean,context:1,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsUserCerts",void 0);u([l({type:d.Boolean,context:2,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsCACerts",void 0);u([l({type:jc,context:3,optional:!0,implicit:!0})],Zt.prototype,"onlySomeReasons",void 0);u([l({type:d.Boolean,context:4,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"indirectCRL",void 0);u([l({type:d.Boolean,context:5,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsAttributeCerts",void 0);var Xx=`${le}.21`,Kc;(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"})(Kc||(Kc={}));var Hc=class{constructor(e=Kc.unspecified){this.reason=Kc.unspecified,this.reason=e}toJSON(){return Kc[this.reason]}toString(){return this.toJSON()}};u([l({type:d.Enumerated})],Hc.prototype,"reason",void 0);Hc=u([_({type:x.Choice})],Hc);var Ym,Zf=`${le}.37`,Vc=Ym=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ym.prototype)}};Vc=Ym=u([_({type:x.Sequence,itemType:d.ObjectIdentifier})],Vc);var ZD=`${Zf}.0`,Zx=`${di}.1`,Yx=`${di}.2`,Jx=`${di}.3`,Qx=`${di}.4`,ev=`${di}.8`,tv=`${di}.9`;var tR=`${le}.54`,Jm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};u([l({type:d.Integer,converter:ge})],Jm.prototype,"value",void 0);Jm=u([_({type:x.Choice})],Jm);var rv=`${le}.24`,$c=class{constructor(e){this.value=new Date,e&&(this.value=e)}};u([l({type:d.GeneralizedTime})],$c.prototype,"value",void 0);$c=u([_({type:x.Choice})],$c);var Qm,ey=`${le}.18`,nv=Qm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};nv=Qm=u([_({type:x.Sequence})],nv);var Yf=`${le}.15`,kr;(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"})(kr||(kr={}));var Ds=class extends Wr{toJSON(){let e=this.toNumber(),t=[];return e&kr.cRLSign&&t.push("crlSign"),e&kr.dataEncipherment&&t.push("dataEncipherment"),e&kr.decipherOnly&&t.push("decipherOnly"),e&kr.digitalSignature&&t.push("digitalSignature"),e&kr.encipherOnly&&t.push("encipherOnly"),e&kr.keyAgreement&&t.push("keyAgreement"),e&kr.keyCertSign&&t.push("keyCertSign"),e&kr.keyEncipherment&&t.push("keyEncipherment"),e&kr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var ty,AR=`${le}.30`,Rs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};u([l({type:ae})],Rs.prototype,"base",void 0);u([l({type:d.Integer,context:0,defaultValue:0,implicit:!0})],Rs.prototype,"minimum",void 0);u([l({type:d.Integer,context:1,optional:!0,implicit:!0})],Rs.prototype,"maximum",void 0);var Jf=ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};Jf=ty=u([_({type:x.Sequence,itemType:Rs})],Jf);var Qf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Jf,context:0,optional:!0,implicit:!0})],Qf.prototype,"permittedSubtrees",void 0);u([l({type:Jf,context:1,optional:!0,implicit:!0})],Qf.prototype,"excludedSubtrees",void 0);var IR=`${le}.36`,eh=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ge})],eh.prototype,"requireExplicitPolicy",void 0);u([l({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ge})],eh.prototype,"inhibitPolicyMapping",void 0);var ry,NR=`${le}.33`,Fc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Fc.prototype,"issuerDomainPolicy",void 0);u([l({type:d.ObjectIdentifier})],Fc.prototype,"subjectDomainPolicy",void 0);var ov=ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};ov=ry=u([_({type:x.Sequence,itemType:Fc})],ov);var ny,oy=`${le}.17`,th=ny=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};th=ny=u([_({type:x.Sequence})],th);var dt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],dt.prototype,"type",void 0);u([l({type:d.Any,repeated:"set"})],dt.prototype,"values",void 0);var iy,XR=`${le}.9`,iv=iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,iy.prototype)}};iv=iy=u([_({type:x.Sequence,itemType:dt})],iv);var sy=`${le}.14`,Ht=class extends yi{};var oL=`${le}.16`,rh=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],rh.prototype,"notBefore",void 0);u([l({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],rh.prototype,"notAfter",void 0);var Wc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Wc||(Wc={}));var nh=class extends Wr{toJSON(){let e=[],t=this.toNumber();return t&Wc.pKIXCertificate&&e.push("pKIXCertificate"),t&Wc.newExtensions&&e.push("newExtensions"),t&Wc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},oh=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new nh,Object.assign(this,e)}};u([l({type:d.GeneralString})],oh.prototype,"entrustVers",void 0);u([l({type:nh})],oh.prototype,"entrustInfoFlags",void 0);var ay,pL=`${lo}.11`,sv=ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ay.prototype)}};sv=ay=u([_({type:x.Sequence,itemType:En})],sv);var av=Rr(gn()),j=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&av.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};u([l({type:d.ObjectIdentifier})],j.prototype,"algorithm",void 0);u([l({type:d.Any,optional:!0})],j.prototype,"parameters",void 0);var mt=class{constructor(e={}){this.algorithm=new j,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],mt.prototype,"algorithm",void 0);u([l({type:d.BitString})],mt.prototype,"subjectPublicKey",void 0);var Ge=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};u([l({type:d.UTCTime})],Ge.prototype,"utcTime",void 0);u([l({type:d.GeneralizedTime})],Ge.prototype,"generalTime",void 0);Ge=u([_({type:x.Choice})],Ge);var Bn=class{constructor(e){this.notBefore=new Ge(new Date),this.notAfter=new Ge(new Date),e&&(this.notBefore=new Ge(e.notBefore),this.notAfter=new Ge(e.notAfter))}};u([l({type:Ge})],Bn.prototype,"notBefore",void 0);u([l({type:Ge})],Bn.prototype,"notAfter",void 0);var cy,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ie,Object.assign(this,e)}};yt.CRITICAL=!1;u([l({type:d.ObjectIdentifier})],yt.prototype,"extnID",void 0);u([l({type:d.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);u([l({type:ie})],yt.prototype,"extnValue",void 0);var Yt=cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cy.prototype)}};Yt=cy=u([_({type:x.Sequence,itemType:yt})],Yt);var zr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(zr||(zr={}));var gt=class{constructor(e={}){this.version=zr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new j,this.issuer=new Oe,this.validity=new Bn,this.subject=new Oe,this.subjectPublicKeyInfo=new mt,Object.assign(this,e)}};u([l({type:d.Integer,context:0,defaultValue:zr.v1})],gt.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],gt.prototype,"serialNumber",void 0);u([l({type:j})],gt.prototype,"signature",void 0);u([l({type:Oe})],gt.prototype,"issuer",void 0);u([l({type:Bn})],gt.prototype,"validity",void 0);u([l({type:Oe})],gt.prototype,"subject",void 0);u([l({type:mt})],gt.prototype,"subjectPublicKeyInfo",void 0);u([l({type:d.BitString,context:1,implicit:!0,optional:!0})],gt.prototype,"issuerUniqueID",void 0);u([l({type:d.BitString,context:2,implicit:!0,optional:!0})],gt.prototype,"subjectUniqueID",void 0);u([l({type:Yt,context:3,optional:!0})],gt.prototype,"extensions",void 0);var cr=class{constructor(e={}){this.tbsCertificate=new gt,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:gt,raw:!0})],cr.prototype,"tbsCertificate",void 0);u([l({type:j})],cr.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],cr.prototype,"signatureValue",void 0);var wi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ge,Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],wi.prototype,"userCertificate",void 0);u([l({type:Ge})],wi.prototype,"revocationDate",void 0);u([l({type:yt,optional:!0,repeated:"sequence"})],wi.prototype,"crlEntryExtensions",void 0);var Jt=class{constructor(e={}){this.signature=new j,this.issuer=new Oe,this.thisUpdate=new Ge,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Jt.prototype,"version",void 0);u([l({type:j})],Jt.prototype,"signature",void 0);u([l({type:Oe})],Jt.prototype,"issuer",void 0);u([l({type:Ge})],Jt.prototype,"thisUpdate",void 0);u([l({type:Ge,optional:!0})],Jt.prototype,"nextUpdate",void 0);u([l({type:wi,repeated:"sequence",optional:!0})],Jt.prototype,"revokedCertificates",void 0);u([l({type:yt,optional:!0,context:0,repeated:"sequence"})],Jt.prototype,"crlExtensions",void 0);var xi=class{constructor(e={}){this.tbsCertList=new Jt,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Jt,raw:!0})],xi.prototype,"tbsCertList",void 0);u([l({type:j})],xi.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],xi.prototype,"signature",void 0);var H=Rr(gn());var Or=class{constructor(e={}){this.issuer=new Oe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Oe})],Or.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],Or.prototype,"serialNumber",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],vi.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],vi.prototype,"issuerAndSerialNumber",void 0);vi=u([_({type:x.Choice})],vi);var bt;(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"})(bt||(bt={}));var Ai=class extends j{};Ai=u([_({type:x.Sequence})],Ai);var qc=class extends j{};qc=u([_({type:x.Sequence})],qc);var Vt=class extends j{};Vt=u([_({type:x.Sequence})],Vt);var Gc=class extends j{};Gc=u([_({type:x.Sequence})],Gc);var uv=class extends j{};uv=u([_({type:x.Sequence})],uv);var ih=class extends j{};ih=u([_({type:x.Sequence})],ih);var Pr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Pr.prototype,"attrType",void 0);u([l({type:d.Any,repeated:"set"})],Pr.prototype,"attrValues",void 0);var uy,$t=class{constructor(e={}){this.version=bt.v0,this.sid=new vi,this.digestAlgorithm=new Ai,this.signatureAlgorithm=new qc,this.signature=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],$t.prototype,"version",void 0);u([l({type:vi})],$t.prototype,"sid",void 0);u([l({type:Ai})],$t.prototype,"digestAlgorithm",void 0);u([l({type:Pr,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],$t.prototype,"signedAttrs",void 0);u([l({type:qc})],$t.prototype,"signatureAlgorithm",void 0);u([l({type:ie})],$t.prototype,"signature",void 0);u([l({type:Pr,repeated:"set",context:1,implicit:!0,optional:!0})],$t.prototype,"unsignedAttrs",void 0);var zc=uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};zc=uy=u([_({type:x.Set,itemType:$t})],zc);var lv=class extends Ge{};lv=u([_({type:x.Choice})],lv);var fv=class extends $t{};fv=u([_({type:x.Sequence})],fv);var Xc=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};u([l({type:ae})],Xc.prototype,"acIssuer",void 0);u([l({type:d.Integer})],Xc.prototype,"acSerial",void 0);u([l({type:dt,repeated:"sequence"})],Xc.prototype,"attrs",void 0);var ly,Zc=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};Zc=ly=u([_({type:x.Sequence,itemType:d.ObjectIdentifier})],Zc);var Ls=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Ls.prototype,"pathLenConstraint",void 0);u([l({type:Zc,implicit:!0,context:0,optional:!0})],Ls.prototype,"permittedAttrs",void 0);u([l({type:Zc,implicit:!0,context:1,optional:!0})],Ls.prototype,"excludedAttrs",void 0);u([l({type:d.Boolean,defaultValue:!0})],Ls.prototype,"permitUnSpecified",void 0);var ur=class{constructor(e={}){this.issuer=new je,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:je})],ur.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],ur.prototype,"serial",void 0);u([l({type:d.BitString,optional:!0})],ur.prototype,"issuerUID",void 0);var fy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(fy||(fy={}));var lr=class{constructor(e={}){this.digestedObjectType=fy.publicKey,this.digestAlgorithm=new j,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Enumerated})],lr.prototype,"digestedObjectType",void 0);u([l({type:d.ObjectIdentifier,optional:!0})],lr.prototype,"otherObjectTypeID",void 0);u([l({type:j})],lr.prototype,"digestAlgorithm",void 0);u([l({type:d.BitString})],lr.prototype,"objectDigest",void 0);var Si=class{constructor(e={}){Object.assign(this,e)}};u([l({type:je,optional:!0})],Si.prototype,"issuerName",void 0);u([l({type:ur,context:0,implicit:!0,optional:!0})],Si.prototype,"baseCertificateID",void 0);u([l({type:lr,context:1,implicit:!0,optional:!0})],Si.prototype,"objectDigestInfo",void 0);var Ei=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,repeated:"sequence"})],Ei.prototype,"v1Form",void 0);u([l({type:Si,context:0,implicit:!0})],Ei.prototype,"v2Form",void 0);Ei=u([_({type:x.Choice})],Ei);var _i=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};u([l({type:d.GeneralizedTime})],_i.prototype,"notBeforeTime",void 0);u([l({type:d.GeneralizedTime})],_i.prototype,"notAfterTime",void 0);var ho=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ur,implicit:!0,context:0,optional:!0})],ho.prototype,"baseCertificateID",void 0);u([l({type:je,implicit:!0,context:1,optional:!0})],ho.prototype,"entityName",void 0);u([l({type:lr,implicit:!0,context:2,optional:!0})],ho.prototype,"objectDigestInfo",void 0);var hy;(function(r){r[r.v2=1]="v2"})(hy||(hy={}));var Ft=class{constructor(e={}){this.version=hy.v2,this.holder=new ho,this.issuer=new Ei,this.signature=new j,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new _i,this.attributes=[],Object.assign(this,e)}};u([l({type:d.Integer})],Ft.prototype,"version",void 0);u([l({type:ho})],Ft.prototype,"holder",void 0);u([l({type:Ei})],Ft.prototype,"issuer",void 0);u([l({type:j})],Ft.prototype,"signature",void 0);u([l({type:d.Integer,converter:ge})],Ft.prototype,"serialNumber",void 0);u([l({type:_i})],Ft.prototype,"attrCertValidityPeriod",void 0);u([l({type:dt,repeated:"sequence"})],Ft.prototype,"attributes",void 0);u([l({type:d.BitString,optional:!0})],Ft.prototype,"issuerUniqueID",void 0);u([l({type:Yt,optional:!0})],Ft.prototype,"extensions",void 0);var Ci=class{constructor(e={}){this.acinfo=new Ft,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Ft})],Ci.prototype,"acinfo",void 0);u([l({type:j})],Ci.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Ci.prototype,"signatureValue",void 0);var Yc;(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"})(Yc||(Yc={}));var Us=class extends Wr{};var Ms=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier,implicit:!0,context:0})],Ms.prototype,"type",void 0);u([l({type:d.Any,implicit:!0,context:1})],Ms.prototype,"value",void 0);var Jc=class{constructor(e={}){this.policyId="",this.classList=new Us(Yc.unclassified),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Jc.prototype,"policyId",void 0);u([l({type:Us,defaultValue:new Us(Yc.unclassified)})],Jc.prototype,"classList",void 0);u([l({type:Ms,repeated:"set"})],Jc.prototype,"securityCategories",void 0);var js=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie})],js.prototype,"cotets",void 0);u([l({type:d.ObjectIdentifier})],js.prototype,"oid",void 0);u([l({type:d.Utf8String})],js.prototype,"string",void 0);var sh=class{constructor(e={}){this.values=[],Object.assign(this,e)}};u([l({type:je,implicit:!0,context:0,optional:!0})],sh.prototype,"policyAuthority",void 0);u([l({type:js,repeated:"sequence"})],sh.prototype,"values",void 0);var Gj=`${lo}.4`,zj=`${lo}.6`,Xj=`${lo}.10`,Zj=`${le}.55`,Qc=`${uo}.10`,Yj=`${Qc}.1`,Jj=`${Qc}.2`,Qj=`${Qc}.3`,e9=`${Qc}.4`,t9=`${Qc}.6`,py="2.5.4",r9=`${py}.72`;var dy,Ks=class{constructor(e={}){this.targetCertificate=new ur,Object.assign(this,e)}};u([l({type:ur})],Ks.prototype,"targetCertificate",void 0);u([l({type:ae,optional:!0})],Ks.prototype,"targetName",void 0);u([l({type:lr,optional:!0})],Ks.prototype,"certDigestInfo",void 0);var Hs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,context:0,implicit:!0})],Hs.prototype,"targetName",void 0);u([l({type:ae,context:1,implicit:!0})],Hs.prototype,"targetGroup",void 0);u([l({type:Ks,context:2,implicit:!0})],Hs.prototype,"targetCert",void 0);Hs=u([_({type:x.Choice})],Hs);var ah=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};ah=dy=u([_({type:x.Sequence,itemType:Hs})],ah);var my,hv=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};hv=my=u([_({type:x.Sequence,itemType:ah})],hv);var ch=class{constructor(e={}){Object.assign(this,e)}};u([l({type:je,implicit:!0,context:0,optional:!0})],ch.prototype,"roleAuthority",void 0);u([l({type:ae,implicit:!0,context:1})],ch.prototype,"roleName",void 0);var eu=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};u([l({type:ae})],eu.prototype,"service",void 0);u([l({type:ae})],eu.prototype,"ident",void 0);u([l({type:ie,optional:!0})],eu.prototype,"authInfo",void 0);var yy,tu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],tu.prototype,"otherCertFormat",void 0);u([l({type:d.Any})],tu.prototype,"otherCert",void 0);var Bi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:cr})],Bi.prototype,"certificate",void 0);u([l({type:Ci,context:2,implicit:!0})],Bi.prototype,"v2AttrCert",void 0);u([l({type:tu,context:3,implicit:!0})],Bi.prototype,"other",void 0);Bi=u([_({type:x.Choice})],Bi);var Ii=yy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};Ii=yy=u([_({type:x.Set,itemType:Bi})],Ii);var fr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],fr.prototype,"contentType",void 0);u([l({type:d.Any,context:0})],fr.prototype,"content",void 0);var Vs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie})],Vs.prototype,"single",void 0);u([l({type:d.Any})],Vs.prototype,"any",void 0);Vs=u([_({type:x.Choice})],Vs);var Ti=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ti.prototype,"eContentType",void 0);u([l({type:Vs,context:0,optional:!0})],Ti.prototype,"eContent",void 0);var ru=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie,context:0,implicit:!0,optional:!0})],ru.prototype,"value",void 0);u([l({type:ie,converter:Hx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],ru.prototype,"constructedValue",void 0);ru=u([_({type:x.Choice})],ru);var po=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Gc,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],po.prototype,"contentType",void 0);u([l({type:Gc})],po.prototype,"contentEncryptionAlgorithm",void 0);u([l({type:ru,optional:!0})],po.prototype,"encryptedContent",void 0);var mo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],mo.prototype,"keyAttrId",void 0);u([l({type:d.Any,optional:!0})],mo.prototype,"keyAttr",void 0);var gy,$s=class{constructor(e={}){this.subjectKeyIdentifier=new Ht,Object.assign(this,e)}};u([l({type:Ht})],$s.prototype,"subjectKeyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],$s.prototype,"date",void 0);u([l({type:mo,optional:!0})],$s.prototype,"other",void 0);var Fs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:$s,context:0,implicit:!0,optional:!0})],Fs.prototype,"rKeyId",void 0);u([l({type:Or,optional:!0})],Fs.prototype,"issuerAndSerialNumber",void 0);Fs=u([_({type:x.Choice})],Fs);var nu=class{constructor(e={}){this.rid=new Fs,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:Fs})],nu.prototype,"rid",void 0);u([l({type:ie})],nu.prototype,"encryptedKey",void 0);var uh=gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,gy.prototype)}};uh=gy=u([_({type:x.Sequence,itemType:nu})],uh);var ou=class{constructor(e={}){this.algorithm=new j,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],ou.prototype,"algorithm",void 0);u([l({type:d.BitString})],ou.prototype,"publicKey",void 0);var ki=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0,optional:!0})],ki.prototype,"subjectKeyIdentifier",void 0);u([l({type:ou,context:1,implicit:!0,optional:!0})],ki.prototype,"originatorKey",void 0);u([l({type:Or,optional:!0})],ki.prototype,"issuerAndSerialNumber",void 0);ki=u([_({type:x.Choice})],ki);var In=class{constructor(e={}){this.version=bt.v3,this.originator=new ki,this.keyEncryptionAlgorithm=new Vt,this.recipientEncryptedKeys=new uh,Object.assign(this,e)}};u([l({type:d.Integer})],In.prototype,"version",void 0);u([l({type:ki,context:0})],In.prototype,"originator",void 0);u([l({type:ie,context:1,optional:!0})],In.prototype,"ukm",void 0);u([l({type:Vt})],In.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:uh})],In.prototype,"recipientEncryptedKeys",void 0);var Ws=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],Ws.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],Ws.prototype,"issuerAndSerialNumber",void 0);Ws=u([_({type:x.Choice})],Ws);var yo=class{constructor(e={}){this.version=bt.v0,this.rid=new Ws,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],yo.prototype,"version",void 0);u([l({type:Ws})],yo.prototype,"rid",void 0);u([l({type:Vt})],yo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],yo.prototype,"encryptedKey",void 0);var Oi=class{constructor(e={}){this.keyIdentifier=new ie,Object.assign(this,e)}};u([l({type:ie})],Oi.prototype,"keyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],Oi.prototype,"date",void 0);u([l({type:mo,optional:!0})],Oi.prototype,"other",void 0);var go=class{constructor(e={}){this.version=bt.v4,this.kekid=new Oi,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],go.prototype,"version",void 0);u([l({type:Oi})],go.prototype,"kekid",void 0);u([l({type:Vt})],go.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],go.prototype,"encryptedKey",void 0);var bo=class{constructor(e={}){this.version=bt.v0,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],bo.prototype,"version",void 0);u([l({type:ih,context:0,optional:!0})],bo.prototype,"keyDerivationAlgorithm",void 0);u([l({type:Vt})],bo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],bo.prototype,"encryptedKey",void 0);var iu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],iu.prototype,"oriType",void 0);u([l({type:d.Any})],iu.prototype,"oriValue",void 0);var Tn=class{constructor(e={}){Object.assign(this,e)}};u([l({type:yo,optional:!0})],Tn.prototype,"ktri",void 0);u([l({type:In,context:1,implicit:!0,optional:!0})],Tn.prototype,"kari",void 0);u([l({type:go,context:2,implicit:!0,optional:!0})],Tn.prototype,"kekri",void 0);u([l({type:bo,context:3,implicit:!0,optional:!0})],Tn.prototype,"pwri",void 0);u([l({type:iu,context:4,implicit:!0,optional:!0})],Tn.prototype,"ori",void 0);Tn=u([_({type:x.Choice})],Tn);var by,su=by=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};su=by=u([_({type:x.Set,itemType:Tn})],su);var wy,pv=`${uo}.16`,tH=`${pv}.2`,rH=`${pv}.4`,qs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],qs.prototype,"otherRevInfoFormat",void 0);u([l({type:d.Any})],qs.prototype,"otherRevInfo",void 0);var lh=class{constructor(e={}){this.other=new qs,Object.assign(this,e)}};u([l({type:qs,context:1,implicit:!0})],lh.prototype,"other",void 0);lh=u([_({type:x.Choice})],lh);var Gs=wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Gs=wy=u([_({type:x.Set,itemType:lh})],Gs);var zs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ii,context:0,implicit:!0,optional:!0})],zs.prototype,"certs",void 0);u([l({type:Gs,context:1,implicit:!0,optional:!0})],zs.prototype,"crls",void 0);var xy,vy=xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};vy=xy=u([_({type:x.Set,itemType:Pr})],vy);var Pi=class{constructor(e={}){this.version=bt.v0,this.recipientInfos=new su,this.encryptedContentInfo=new po,Object.assign(this,e)}};u([l({type:d.Integer})],Pi.prototype,"version",void 0);u([l({type:zs,context:0,implicit:!0,optional:!0})],Pi.prototype,"originatorInfo",void 0);u([l({type:su})],Pi.prototype,"recipientInfos",void 0);u([l({type:po})],Pi.prototype,"encryptedContentInfo",void 0);u([l({type:vy,context:1,implicit:!0,optional:!0})],Pi.prototype,"unprotectedAttrs",void 0);var dv="1.2.840.113549.1.7.2";var Ay,fh=Ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};fh=Ay=u([_({type:x.Set,itemType:Ai})],fh);var kn=class{constructor(e={}){this.version=bt.v0,this.digestAlgorithms=new fh,this.encapContentInfo=new Ti,this.signerInfos=new zc,Object.assign(this,e)}};u([l({type:d.Integer})],kn.prototype,"version",void 0);u([l({type:fh})],kn.prototype,"digestAlgorithms",void 0);u([l({type:Ti})],kn.prototype,"encapContentInfo",void 0);u([l({type:Ii,context:0,implicit:!0,optional:!0})],kn.prototype,"certificates",void 0);u([l({type:Gs,context:1,implicit:!0,optional:!0})],kn.prototype,"crls",void 0);u([l({type:zc})],kn.prototype,"signerInfos",void 0);var Ni="1.2.840.10045.2.1";var au="1.2.840.10045.4.1",hh="1.2.840.10045.4.3.1",cu="1.2.840.10045.4.3.2",uu="1.2.840.10045.4.3.3",lu="1.2.840.10045.4.3.4";var Sy="1.2.840.10045.3.1.7";var Ey="1.3.132.0.34";var _y="1.3.132.0.35";function fu(r){return new j({algorithm:r})}var yv=fu(au),JH=fu(hh),gv=fu(cu),bv=fu(uu),wv=fu(lu);var hu=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],hu.prototype,"fieldType",void 0);u([l({type:d.Any})],hu.prototype,"parameters",void 0);hu=u([_({type:x.Sequence})],hu);var Cy=class extends ie{};var Xs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.OctetString})],Xs.prototype,"a",void 0);u([l({type:d.OctetString})],Xs.prototype,"b",void 0);u([l({type:d.BitString,optional:!0})],Xs.prototype,"seed",void 0);Xs=u([_({type:x.Sequence})],Xs);var By;(function(r){r[r.ecpVer1=1]="ecpVer1"})(By||(By={}));var Xr=class{constructor(e={}){this.version=By.ecpVer1,Object.assign(this,e)}};u([l({type:d.Integer})],Xr.prototype,"version",void 0);u([l({type:hu})],Xr.prototype,"fieldID",void 0);u([l({type:Xs})],Xr.prototype,"curve",void 0);u([l({type:Cy})],Xr.prototype,"base",void 0);u([l({type:d.Integer,converter:ge})],Xr.prototype,"order",void 0);u([l({type:d.Integer,optional:!0})],Xr.prototype,"cofactor",void 0);Xr=u([_({type:x.Sequence})],Xr);var Zr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Zr.prototype,"namedCurve",void 0);u([l({type:d.Null})],Zr.prototype,"implicitCurve",void 0);u([l({type:Xr})],Zr.prototype,"specifiedCurve",void 0);Zr=u([_({type:x.Choice})],Zr);var Zs=class{constructor(e={}){this.version=1,this.privateKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],Zs.prototype,"version",void 0);u([l({type:ie})],Zs.prototype,"privateKey",void 0);u([l({type:Zr,context:0,optional:!0})],Zs.prototype,"parameters",void 0);u([l({type:d.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)}};u([l({type:d.Integer,converter:ge})],Di.prototype,"r",void 0);u([l({type:d.Integer,converter:ge})],Di.prototype,"s",void 0);var Wt="1.2.840.113549.1.1",Yr=`${Wt}.1`,xv=`${Wt}.7`,vv=`${Wt}.9`,wo=`${Wt}.10`,Av=`${Wt}.2`,Sv=`${Wt}.4`,Ys=`${Wt}.5`,Ev=`${Wt}.14`;var ph=`${Wt}.11`,Js=`${Wt}.12`,Qs=`${Wt}.13`,Iy=`${Wt}.15`,Ty=`${Wt}.16`,Ri="1.3.14.3.2.26",dh="2.16.840.1.101.3.4.2.4",Li="2.16.840.1.101.3.4.2.1",Ui="2.16.840.1.101.3.4.2.2",Mi="2.16.840.1.101.3.4.2.3",_v="2.16.840.1.101.3.4.2.5",Cv="2.16.840.1.101.3.4.2.6",Bv="1.2.840.113549.2.2",Iv="1.2.840.113549.2.5",xo=`${Wt}.8`;function it(r){return new j({algorithm:r,parameters:null})}var CV=it(Bv),BV=it(Iv),On=it(Ri),IV=it(dh),TV=it(Li),kV=it(Ui),OV=it(Mi),PV=it(_v),NV=it(Cv),mh=new j({algorithm:xo,parameters:F.serialize(On)}),ky=new j({algorithm:vv,parameters:F.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))}),DV=it(Yr),RV=it(Av),LV=it(Sv),UV=it(Ys),MV=it(Iy),jV=it(Ty),KV=it(Js),HV=it(Qs),VV=it(Iy),$V=it(Ty);var ea=class{constructor(e={}){this.hashAlgorithm=new j(On),this.maskGenAlgorithm=new j({algorithm:xo,parameters:F.serialize(On)}),this.pSourceAlgorithm=new j(ky),Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:On})],ea.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:mh})],ea.prototype,"maskGenAlgorithm",void 0);u([l({type:j,context:2,defaultValue:ky})],ea.prototype,"pSourceAlgorithm",void 0);var ZV=new j({algorithm:xv,parameters:F.serialize(new ea)});var Jr=class{constructor(e={}){this.hashAlgorithm=new j(On),this.maskGenAlgorithm=new j({algorithm:xo,parameters:F.serialize(On)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:On})],Jr.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:mh})],Jr.prototype,"maskGenAlgorithm",void 0);u([l({type:d.Integer,context:2,defaultValue:20})],Jr.prototype,"saltLength",void 0);u([l({type:d.Integer,context:3,defaultValue:1})],Jr.prototype,"trailerField",void 0);var n7=new j({algorithm:wo,parameters:F.serialize(new Jr)});var ji=class{constructor(e={}){this.digestAlgorithm=new j,this.digest=new ie,Object.assign(this,e)}};u([l({type:j})],ji.prototype,"digestAlgorithm",void 0);u([l({type:ie})],ji.prototype,"digest",void 0);var Oy,ta=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],ta.prototype,"prime",void 0);u([l({type:d.Integer,converter:ge})],ta.prototype,"exponent",void 0);u([l({type:d.Integer,converter:ge})],ta.prototype,"coefficient",void 0);var yh=Oy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Oy.prototype)}};yh=Oy=u([_({type:x.Sequence,itemType:ta})],yh);var hr=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)}};u([l({type:d.Integer})],hr.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"publicExponent",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"privateExponent",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"prime1",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"prime2",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"exponent1",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"exponent2",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"coefficient",void 0);u([l({type:yh,optional:!0})],hr.prototype,"otherPrimeInfos",void 0);var ra=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],ra.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],ra.prototype,"publicExponent",void 0);var Py;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Py||(Py={}));var wt=Py;var Zv=Rr(Xv(),1),{__extends:oa,__assign:D7,__rest:WC,__decorate:R7,__param:L7,__metadata:U7,__awaiter:Yv,__generator:Jv,__exportStar:M7,__createBinding:j7,__values:pu,__read:du,__spread:Nr,__spreadArrays:K7,__await:H7,__asyncGenerator:V7,__asyncDelegator:$7,__asyncValues:F7,__makeTemplateObject:W7,__importStar:q7,__importDefault:G7,__classPrivateFieldGet:z7,__classPrivateFieldSet:X7}=Zv.default;var qC="injectionTokens";function Dy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(qC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function mu(r){return!!r.useClass}function ia(r){return!!r.useFactory}var wh=(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,Nr(i))}};return this.reflectMethods.forEach(n),t},r})();function vo(r){return typeof r=="string"||typeof r=="symbol"}function Ry(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function xh(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Qv(r){return typeof r=="function"||r instanceof wh}function Ki(r){return!!r.useToken}function Hi(r){return r.useValue!=null}function e1(r){return mu(r)||Hi(r)||Ki(r)||ia(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})(),yu=GC;var zC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu),t1=zC;var XC=(function(){function r(){this.scopedResolutions=new Map}return r})(),gu=XC;function ZC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function YC(r,e,t){return t===void 0&&(t=" "),Nr([r],e.message.split(`
|
6
|
+
`)}`:`${t} :`}};fx=Qe;X.Constructed=fx;Qe.NAME="CONSTRUCTED";var kf=class extends pt{fromBER(e,t,n){return t}toBER(e){return Ir}};kf.override="EndOfContentValueBlock";var hx,xc=class extends Je{constructor(e={}){super(e,kf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};hx=xc;X.EndOfContent=hx;xc.NAME=bc;var px,_r=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}`}};px=_r;X.Null=px;_r.NAME="NULL";var Of=class extends $r(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=ye.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ye.BufferSourceConverter.toUint8Array(e);return An(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,Cm.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Of.NAME="BooleanValueBlock";var dx,Jo=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Of),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};dx=Jo;X.Boolean=dx;Jo.NAME="BOOLEAN";var Pf=class extends $r(Hr){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=Hr.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===bc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==ax)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?Hr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Pf.NAME="OctetStringValueBlock";var km,Cr=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},Pf),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=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 Qe.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ye.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof km&&e.push(t.valueBlock.valueHexView);return ye.BufferSourceConverter.concat(e)}};km=Cr;X.OctetString=km;Cr.NAME=ax;var Nf=class extends $r(Hr){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=Hr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===bc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==cx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=ye.BufferSourceConverter.toUint8Array(e);if(!An(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 Hr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Ir;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}}};Nf.NAME="BitStringValueBlock";var mx,Br=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},Nf),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 Qe.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}`}}};mx=Br;X.BitString=mx;Br.NAME=cx;var yx;function mC(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,f=0,p=c<s?s:c,h=0;for(let y=p;y>=0;y--,h++){switch(!0){case h<a.length:f=i[s-h]+a[c-h]+t[0];break;default:f=i[s-h]+t[0]}switch(t[0]=f/10,!0){case h>=i.length:i=_f(new Uint8Array([f%10]),i);break;default:i[s-h]=f%10}}return t[0]>0&&(i=_f(t,i)),i}function sx(r){if(r>=yc.length)for(let e=yc.length;e<=r;e++){let t=new Uint8Array([0]),n=yc[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=_f(t,n)),yc.push(n)}return yc[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,f,p=0;for(let h=c;h>=0;h--,p++)switch(f=i[s-p]-a[c-p]-t,!0){case f<0:t=1,i[s-p]=f+10;break;default:t=0,i[s-p]=f}if(t>0)for(let h=s-c+1;h>=0;h--,p++)if(f=i[s-p]-t,f<0)t=1,i[s-p]=f+10;else{t=0,i[s-p]=f;break}return i.slice()}var vc=class extends $r(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=Cm.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(rx(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 f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=yC(sx(n),t),s="-";break;default:t=mC(t,sx(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=ox.charAt(t[c]));return a===!1&&(s+=ox.charAt(0)),s}};yx=vc;vc.NAME="IntegerValueBlock";Object.defineProperty(yx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var gc,vn=class extends Je{constructor(e={}){super(e,vc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Cf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Cf();let t=BigInt(e),n=new Ts,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ye.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${ye.Convert.ToHex(a)}`)+t,p=ye.BufferSourceConverter.toUint8Array(ye.Convert.FromHex(f.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new gc({valueHex:n.final()})}convertToDER(){let e=new gc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new gc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};gc=vn;X.Integer=gc;vn.NAME="INTEGER";var gx,Qo=class extends vn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};gx=Qo;X.Enumerated=gx;Qo.NAME="ENUMERATED";var Ac=class extends $r(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=ye.BufferSourceConverter.toUint8Array(e);if(!An(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){Cf();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=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Ir;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=ye.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Ac.NAME="sidBlock";var Df=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 Ac;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,Ir;t.push(o)}return Tm(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 Ac;if(o>Number.MAX_SAFE_INTEGER){Cf();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}};Df.NAME="ObjectIdentifierValueBlock";var bx,ei=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Df),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};bx=ei;X.ObjectIdentifier=bx;ei.NAME="OBJECT IDENTIFIER";var Sc=class extends $r(wn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ye.BufferSourceConverter.toUint8Array(e);if(!An(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=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Ir;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ye.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Sc.NAME="relativeSidBlock";var Rf=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 Sc;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,Ir;n.push(i)}return Tm(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 Sc;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}};Rf.NAME="RelativeObjectIdentifierValueBlock";var wx,Ec=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Rf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};wx=Ec;X.RelativeObjectIdentifier=wx;Ec.NAME="RelativeObjectIdentifier";var xx,Bt=class extends Qe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};xx=Bt;X.Sequence=xx;Bt.NAME="SEQUENCE";var vx,Pt=class extends Qe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};vx=Pt;X.Set=vx;Pt.NAME="SET";var Lf=class extends $r(pt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Kt}toJSON(){return{...super.toJSON(),value:this.value}}};Lf.NAME="StringValueBlock";var Uf=class extends Lf{};Uf.NAME="SimpleStringValueBlock";var Nt=class extends wc{constructor({...e}={}){super(e,Uf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ye.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Nt.NAME="SIMPLE STRING";var Mf=class extends Nt{fromBuffer(e){this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ye.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ye.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Mf.NAME="Utf8StringValueBlock";var Ax,ir=class extends Mf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ax=ir;X.Utf8String=Ax;ir.NAME="UTF8String";var jf=class extends Nt{fromBuffer(e){this.valueBlock.value=ye.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ye.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ye.Convert.FromUtf16String(e))}};jf.NAME="BmpStringValueBlock";var Sx,ti=class extends jf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Sx=ti;X.BmpString=Sx;ti.NAME="BMPString";var Kf=class extends Nt{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=ro(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}};Kf.NAME="UniversalStringValueBlock";var Ex,ri=class extends Kf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Ex=ri;X.UniversalString=Ex;ri.NAME="UniversalString";var _x,ni=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};_x=ni;X.NumericString=_x;ni.NAME="NumericString";var Cx,oi=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Cx=oi;X.PrintableString=Cx;oi.NAME="PrintableString";var Bx,ii=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Bx=ii;X.TeletexString=Bx;ii.NAME="TeletexString";var Ix,si=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ix=si;X.VideotexString=Ix;si.NAME="VideotexString";var Tx,ai=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Tx=ai;X.IA5String=Tx;ai.NAME="IA5String";var kx,ci=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};kx=ci;X.GraphicString=kx;ci.NAME="GraphicString";var Ox,no=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ox=no;X.VisibleString=Ox;no.NAME="VisibleString";var Px,ui=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Px=ui;X.GeneralString=Px;ui.NAME="GeneralString";var Nx,li=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Nx=li;X.CharacterString=Nx;li.NAME="CharacterString";var Dx,oo=class extends no{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ye.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=jt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=jt(this.month,2),t[2]=jt(this.day,2),t[3]=jt(this.hour,2),t[4]=jt(this.minute,2),t[5]=jt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Dx=oo;X.UTCTime=Dx;oo.NAME="UTCTime";var Rx,fi=class extends oo{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 h=new Number(e[e.length-1]);if(isNaN(h.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 h=1,y=n.indexOf("+"),b="";if(y===-1&&(y=n.indexOf("-"),h=-1),y!==-1){if(b=n.substring(y+1),n=n.substring(0,y),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(b.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*g,b.length===4){if(g=parseInt(b.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=h*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let h=new Number(`0${n.substring(f)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-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,f!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}let p=s.exec(o);if(p===null)throw new Error("Wrong input string for conversion");for(let h=1;h<p.length;h++)switch(h){case 1:this.year=parseInt(p[h],10);break;case 2:this.month=parseInt(p[h],10);break;case 3:this.day=parseInt(p[h],10);break;case 4:this.hour=parseInt(p[h],10)+a;break;case 5:this.minute=parseInt(p[h],10)+c;break;case 6:this.second=parseInt(p[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(jt(this.year,4)),t.push(jt(this.month,2)),t.push(jt(this.day,2)),t.push(jt(this.hour,2)),t.push(jt(this.minute,2)),t.push(jt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(jt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Rx=fi;X.GeneralizedTime=Rx;fi.NAME="GeneralizedTime";var Lx,_c=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Lx=_c;X.DATE=Lx;_c.NAME="DATE";var Ux,Cc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Ux=Cc;X.TimeOfDay=Ux;Cc.NAME="TimeOfDay";var Mx,Bc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Mx=Bc;X.DateTime=Mx;Bc.NAME="DateTime";var jx,Ic=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};jx=Ic;X.Duration=jx;Ic.NAME="Duration";var Kx,Tc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Kx=Tc;X.TIME=Kx;Tc.NAME="TIME";var Vr=class{constructor({name:e=Kt,optional:t=!1}={}){this.name=e,this.optional=t}},ks=class extends Vr{constructor({value:e=[],...t}={}){super(t),this.value=e}},hi=class extends Vr{constructor({value:e=new Vr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Im=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Hf}={}){this.dataView=ye.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ye.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function bn(r,e,t){if(t instanceof ks){for(let i of t.value)if(bn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Bm)&&(i.name=t.name),i}}if(t instanceof Vr)return t.hasOwnProperty(Bm)&&(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(!(sC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(lC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(fC 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(aC)===!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(cC)===!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(uC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(iC 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(!(ix 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 X.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof hi&&(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 f=0;f<t.valueBlock.value.length;f++)c=c&&(t.valueBlock.value[f].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 f={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],f.name=t.name)),f}}else if(t.valueBlock.value[0]instanceof hi){if(s=bn(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(Bm in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let f={};hC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?f=e:f=r,typeof f[t.valueBlock.value[0].name]>"u"&&(f[t.valueBlock.value[0].name]=[]),f[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=bn(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&&ix 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 bn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function gC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Os(ye.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:bn(t.result,t.result,e)}var x;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(x||(x={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var Om=Rr(gn()),Wr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Om.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Om.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Br))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Br({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Br({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Pm=Rr(gn()),ie=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Pm.BufferSourceConverter.isBufferSource(e)?this.buffer=Pm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Cr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Cr({valueHex:this.buffer})}toSchema(e){return new Cr({name:e})}};var bC={fromASN:r=>r instanceof _r?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new _r;let e=Sn(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 vn({value:+r})},xC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Qo({value:r})},ge={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new vn({valueHex:r})};var vC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Br({valueHex:r})},AC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ei({value:r})},SC={fromASN:r=>r.valueBlock.value,toASN:r=>new Jo({value:r})},Ps={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Cr({valueHex:r})},Hx={fromASN:r=>new ie(r.getValue()),toASN:r=>r.toASN()};function sr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Nm=sr(ir),EC=sr(ti),_C=sr(ri),CC=sr(ni),BC=sr(oi),IC=sr(ii),TC=sr(si),kC=sr(ai),OC=sr(ci),PC=sr(no),NC=sr(ui),DC=sr(li),RC={fromASN:r=>r.toDate(),toASN:r=>new oo({valueDate:r})},LC={fromASN:r=>r.toDate(),toASN:r=>new fi({valueDate:r})},UC={fromASN:()=>null,toASN:()=>new _r};function io(r){switch(r){case d.Any:return bC;case d.BitString:return vC;case d.BmpString:return EC;case d.Boolean:return SC;case d.CharacterString:return DC;case d.Enumerated:return xC;case d.GeneralString:return NC;case d.GeneralizedTime:return LC;case d.GraphicString:return OC;case d.IA5String:return kC;case d.Integer:return wC;case d.Null:return UC;case d.NumericString:return CC;case d.ObjectIdentifier:return AC;case d.OctetString:return Ps;case d.PrintableString:return BC;case d.TeletexString:return IC;case d.UTCTime:return RC;case d.UniversalString:return _C;case d.Utf8String:return Nm;case d.VideotexString:return TC;case d.VisibleString:return PC;default:return null}}function ar(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:ar(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Rm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Rm(t)}return!1}function Vx(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 Vf=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:x.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let p=d[s.type],h=Fr[p];if(!h)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new h({name:a})}else ar(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===x.Choice?c=new Vr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Vr({name:a});let f=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Pt:Bt;c=new p({name:"",value:[new hi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||ar(s.type)){let p=s.repeated?Qe:xn;o.push(new p({name:a,optional:f,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,h=p?c:this.get(s.type,!0).schema;h="valueBlock"in h?h.valueBlock.value:h.value,o.push(new Qe({name:p?"":a,optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:h}))}else o.push(new Qe({optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=f,o.push(c)}switch(n.type){case x.Sequence:return new Bt({value:o,name:""});case x.Set:return new Pt({value:o,name:""});case x.Choice:return new ks({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var qe=new Vf;var _=r=>e=>{let t;qe.has(e)?t=qe.get(e):(t=qe.createDefault(e),qe.set(e,t)),Object.assign(t,r)};var l=r=>(e,t)=>{let n;qe.has(e.constructor)?n=qe.get(e.constructor):(n=qe.createDefault(e.constructor),qe.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=io(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}o.raw=r.raw,n.items[t]=o};var so=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var kc=class{static parse(e,t){let n=Sn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(ar(t))return new t().fromASN(e);let n=qe.get(t);qe.cache(t);let o=n.schema,i=this.handleChoiceTypes(e,n,t,o);if(i?.result)return i.result;i?.targetSchema&&(o=i.targetSchema);let s=this.handleSequenceTypes(e,n,t,o);if(s&&"isManualMapping"in s)return s.result;let a=s,c=new t;return Rm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof so&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===Qe&&t.type===x.Choice&&e.idBlock.tagClass===3)for(let i in t.items){let s=t.items[i];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&qe.has(s.type)){let a=qe.get(s.type);if(a&&a.type===x.Sequence){let c=new Bt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let f=this.fromASN(c,s.type),p=new n;return p[i]=f,{result:p}}}}}else if(e.constructor===Qe&&t.type!==x.Choice){let i=new Qe({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(let s in t.items)delete e[s];return{targetSchema:i}}return null}static handleSequenceTypes(e,t,n,o){if(t.type===x.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&qe.has(c.type)&&qe.get(c.type).type===x.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=bn({},e,o);if(!s.verified)throw new so(`Data does not match to ${n.name} ASN1 schema.${s.result.error?` ${s.result.error}`:""}`);return s}else{let i=bn({},e,o);if(!i.verified)throw new so(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let f=s[c],p=t.items[f];if(a>=i.length)break;if(p.repeated){o[f]=this.processRepeatedField(i,a,p);break}else if(typeof p.type=="number")o[f]=this.processPrimitiveField(i[a],p),a++;else if(this.isOptionalChoiceField(p)){let h=this.processOptionalChoiceField(i[a],p);h.processed&&(o[f]=h.value,a++)}else o[f]=this.fromASN(i[a],p.type),a++}return{result:o,verified:!0,isManualMapping:!0}}static processRepeatedField(e,t,n){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){let i=o[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(o=i.valueBlock.value)}if(typeof n.type=="number"){let i=io(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return i.fromASN(s)}catch{return}}).filter(s=>s!==void 0)}else return o.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,t){let n=io(t.type);if(!n)throw new Error(`No converter for ASN.1 type ${t.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&qe.has(e.type)&&qe.get(e.type).type===x.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof so&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,t,n){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let o=t.itemType;if(typeof o=="number"){let i=io(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type,c;typeof a=="number"||ar(a)?c=this.processPrimitiveSchemaItem(i,s,a):c=this.processComplexSchemaItem(i,s,a),c&&typeof c=="object"&&"value"in c&&"raw"in c?(n[o]=c.value,n[`${o}Raw`]=c.raw):n[o]=c}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:ar(n)?new n:null;if(!i)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,i):this.processSinglePrimitiveItem(e,t,n,i)}static processRepeatedPrimitiveItem(e,t,n){if(t.implicit){let o=t.repeated==="sequence"?Bt:Pt,i=new o;i.valueBlock=e.valueBlock;let s=Sn(i.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let a=s.result.valueBlock.value;return Array.from(a,c=>n.fromASN(c))}else return Array.from(e,o=>n.fromASN(o))}static processSinglePrimitiveItem(e,t,n,o){let i=e;if(t.implicit){let s;if(ar(n))s=new n().toSchema("");else{let a=d[n],c=Fr[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Sn(s.toBER(!1)).result}return o.fromASN(i)}static processComplexSchemaItem(e,t,n){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,n))}else{let o=this.handleImplicitTagging(e,t,n);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,n)}catch(i){if(i instanceof so&&/Wrong values for Choice type/.test(i.message))return;throw i}else{let i=this.fromASN(o,n);return t.raw?{value:i,raw:e.valueBeforeDecodeView}:i}}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=qe.get(n);if(o.type===x.Sequence){let i=new Bt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(o.type===x.Set){let i=new Pt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var Oc=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"&&ar(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=qe.get(t);qe.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=io(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"&&Vx(this.serialize(a.defaultValue),this.serialize(c)))continue;let f=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||ar(a.type))){let p={};p.valueHex=f instanceof _r?f.valueBeforeDecodeView:f.valueBlock.toBER(),o.push(new xn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new Qe({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:f.valueBlock.value}));else o.push(new Qe({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[f]}));else a.repeated?o=o.concat(f):o.push(f)}let i;switch(n.type){case x.Sequence:i=new Bt({value:o});break;case x.Set:i=new Pt({value:o});break;case x.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,f=>s.toASN(f)),c=e.repeated==="sequence"?Bt:Pt;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"?Bt:Pt;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 Lm=Rr(gn());var F=class r{static serialize(e){return Oc.serialize(e)}static parse(e,t){return kc.parse(e,t)}static toString(e){let t=Lm.BufferSourceConverter.isBufferSource(e)?Lm.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Sn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function u(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 he(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)}function Me(r,e,t,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!o:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(r,t):o?o.value=t:e.set(r,t),t}var $x=Rr(gn()),Pc=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,f)=>c+(f.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP($x.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 Fx=Rr(gn()),Um,Mm,jm,et=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};u([l({type:d.TeletexString})],et.prototype,"teletexString",void 0);u([l({type:d.PrintableString})],et.prototype,"printableString",void 0);u([l({type:d.UniversalString})],et.prototype,"universalString",void 0);u([l({type:d.Utf8String})],et.prototype,"utf8String",void 0);u([l({type:d.BmpString})],et.prototype,"bmpString",void 0);et=u([_({type:x.Choice})],et);var Ns=class extends et{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Fx.Convert.ToHex(this.anyValue):super.toString())}};u([l({type:d.IA5String})],Ns.prototype,"ia5String",void 0);u([l({type:d.Any})],Ns.prototype,"anyValue",void 0);Ns=u([_({type:x.Choice})],Ns);var pi=class{constructor(e={}){this.type="",this.value=new Ns,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],pi.prototype,"type",void 0);u([l({type:Ns})],pi.prototype,"value",void 0);var ao=Um=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Um.prototype)}};ao=Um=u([_({type:x.Set,itemType:pi})],ao);var Km=Mm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};Km=Mm=u([_({type:x.Sequence,itemType:ao})],Km);var Oe=jm=class extends Km{constructor(e){super(e),Object.setPrototypeOf(this,jm.prototype)}};Oe=jm=u([_({type:x.Sequence})],Oe);var MC={fromASN:r=>Pc.toString(Ps.fromASN(r)),toASN:r=>Ps.toASN(Pc.fromString(r))},co=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],co.prototype,"typeId",void 0);u([l({type:d.Any,context:0})],co.prototype,"value",void 0);var Nc=class{constructor(e={}){this.partyName=new et,Object.assign(this,e)}};u([l({type:et,optional:!0,context:0,implicit:!0})],Nc.prototype,"nameAssigner",void 0);u([l({type:et,context:1,implicit:!0})],Nc.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};u([l({type:co,context:0,implicit:!0})],ae.prototype,"otherName",void 0);u([l({type:d.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);u([l({type:d.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);u([l({type:d.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);u([l({type:Oe,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);u([l({type:Nc,context:5})],ae.prototype,"ediPartyName",void 0);u([l({type:d.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);u([l({type:d.OctetString,context:7,implicit:!0,converter:MC})],ae.prototype,"iPAddress",void 0);u([l({type:d.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=u([_({type:x.Choice})],ae);var uo="1.3.6.1.5.5.7",lo=`${uo}.1`,Wx=`${uo}.2`,di=`${uo}.3`,$f=`${uo}.48`,S3=`${Wx}.1`,E3=`${Wx}.2`,Hm=`${$f}.1`,Vm=`${$f}.2`,$m=`${$f}.3`,Fm=`${$f}.5`,le="2.5.29";var Wm,Ff=`${lo}.1`,En=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],En.prototype,"accessMethod",void 0);u([l({type:ae})],En.prototype,"accessLocation",void 0);var mi=Wm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Wm.prototype)}};mi=Wm=u([_({type:x.Sequence,itemType:En})],mi);var Wf=`${le}.35`,yi=class extends ie{},qr=class{constructor(e={}){e&&Object.assign(this,e)}};u([l({type:yi,context:0,optional:!0,implicit:!0})],qr.prototype,"keyIdentifier",void 0);u([l({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],qr.prototype,"authorityCertIssuer",void 0);u([l({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ge})],qr.prototype,"authorityCertSerialNumber",void 0);var qf=`${le}.19`,gi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};u([l({type:d.Boolean,defaultValue:!1})],gi.prototype,"cA",void 0);u([l({type:d.Integer,optional:!0})],gi.prototype,"pathLenConstraint",void 0);var qm,je=qm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qm.prototype)}};je=qm=u([_({type:x.Sequence,itemType:ae})],je);var Gm,jC=`${le}.29`,qx=Gm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};qx=Gm=u([_({type:x.Sequence})],qx);var zm,zf=`${le}.32`,rD=`${zf}.0`,_n=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};u([l({type:d.IA5String})],_n.prototype,"ia5String",void 0);u([l({type:d.VisibleString})],_n.prototype,"visibleString",void 0);u([l({type:d.BmpString})],_n.prototype,"bmpString",void 0);u([l({type:d.Utf8String})],_n.prototype,"utf8String",void 0);_n=u([_({type:x.Choice})],_n);var Dc=class{constructor(e={}){this.organization=new _n,this.noticeNumbers=[],Object.assign(this,e)}};u([l({type:_n})],Dc.prototype,"organization",void 0);u([l({type:d.Integer,repeated:"sequence"})],Dc.prototype,"noticeNumbers",void 0);var Rc=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Dc,optional:!0})],Rc.prototype,"noticeRef",void 0);u([l({type:_n,optional:!0})],Rc.prototype,"explicitText",void 0);var Gf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.IA5String})],Gf.prototype,"cPSuri",void 0);u([l({type:Rc})],Gf.prototype,"userNotice",void 0);Gf=u([_({type:x.Choice})],Gf);var Lc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Lc.prototype,"policyQualifierId",void 0);u([l({type:d.Any})],Lc.prototype,"qualifier",void 0);var bi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],bi.prototype,"policyIdentifier",void 0);u([l({type:Lc,repeated:"sequence",optional:!0})],bi.prototype,"policyQualifiers",void 0);var Uc=zm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,zm.prototype)}};Uc=zm=u([_({type:x.Sequence,itemType:bi})],Uc);var lD=`${le}.20`,Mc=class{constructor(e=0){this.value=e}};u([l({type:d.Integer})],Mc.prototype,"value",void 0);Mc=u([_({type:x.Choice})],Mc);var gD=`${le}.27`,Gx=class extends Mc{};Gx=u([_({type:x.Choice})],Gx);var Xm,Xf=`${le}.31`,Tr;(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"})(Tr||(Tr={}));var jc=class extends Wr{toJSON(){let e=[],t=this.toNumber();return t&Tr.aACompromise&&e.push("aACompromise"),t&Tr.affiliationChanged&&e.push("affiliationChanged"),t&Tr.cACompromise&&e.push("cACompromise"),t&Tr.certificateHold&&e.push("certificateHold"),t&Tr.cessationOfOperation&&e.push("cessationOfOperation"),t&Tr.keyCompromise&&e.push("keyCompromise"),t&Tr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Tr.superseded&&e.push("superseded"),t&Tr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Cn=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,context:0,repeated:"sequence",implicit:!0})],Cn.prototype,"fullName",void 0);u([l({type:ao,context:1,implicit:!0})],Cn.prototype,"nameRelativeToCRLIssuer",void 0);Cn=u([_({type:x.Choice})],Cn);var Gr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Cn,context:0,optional:!0})],Gr.prototype,"distributionPoint",void 0);u([l({type:jc,context:1,optional:!0,implicit:!0})],Gr.prototype,"reasons",void 0);u([l({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],Gr.prototype,"cRLIssuer",void 0);var fo=Xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};fo=Xm=u([_({type:x.Sequence,itemType:Gr})],fo);var Zm,PD=`${le}.46`,zx=Zm=class extends fo{constructor(e){super(e),Object.setPrototypeOf(this,Zm.prototype)}};zx=Zm=u([_({type:x.Sequence,itemType:Gr})],zx);var KD=`${le}.28`,Zt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Zt.ONLY=!1;u([l({type:Cn,context:0,optional:!0})],Zt.prototype,"distributionPoint",void 0);u([l({type:d.Boolean,context:1,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsUserCerts",void 0);u([l({type:d.Boolean,context:2,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsCACerts",void 0);u([l({type:jc,context:3,optional:!0,implicit:!0})],Zt.prototype,"onlySomeReasons",void 0);u([l({type:d.Boolean,context:4,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"indirectCRL",void 0);u([l({type:d.Boolean,context:5,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsAttributeCerts",void 0);var Xx=`${le}.21`,Kc;(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"})(Kc||(Kc={}));var Hc=class{constructor(e=Kc.unspecified){this.reason=Kc.unspecified,this.reason=e}toJSON(){return Kc[this.reason]}toString(){return this.toJSON()}};u([l({type:d.Enumerated})],Hc.prototype,"reason",void 0);Hc=u([_({type:x.Choice})],Hc);var Ym,Zf=`${le}.37`,Vc=Ym=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ym.prototype)}};Vc=Ym=u([_({type:x.Sequence,itemType:d.ObjectIdentifier})],Vc);var YD=`${Zf}.0`,Zx=`${di}.1`,Yx=`${di}.2`,Jx=`${di}.3`,Qx=`${di}.4`,ev=`${di}.8`,tv=`${di}.9`;var rR=`${le}.54`,Jm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};u([l({type:d.Integer,converter:ge})],Jm.prototype,"value",void 0);Jm=u([_({type:x.Choice})],Jm);var rv=`${le}.24`,$c=class{constructor(e){this.value=new Date,e&&(this.value=e)}};u([l({type:d.GeneralizedTime})],$c.prototype,"value",void 0);$c=u([_({type:x.Choice})],$c);var Qm,ey=`${le}.18`,nv=Qm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};nv=Qm=u([_({type:x.Sequence})],nv);var Yf=`${le}.15`,kr;(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"})(kr||(kr={}));var Ds=class extends Wr{toJSON(){let e=this.toNumber(),t=[];return e&kr.cRLSign&&t.push("crlSign"),e&kr.dataEncipherment&&t.push("dataEncipherment"),e&kr.decipherOnly&&t.push("decipherOnly"),e&kr.digitalSignature&&t.push("digitalSignature"),e&kr.encipherOnly&&t.push("encipherOnly"),e&kr.keyAgreement&&t.push("keyAgreement"),e&kr.keyCertSign&&t.push("keyCertSign"),e&kr.keyEncipherment&&t.push("keyEncipherment"),e&kr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var ty,SR=`${le}.30`,Rs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};u([l({type:ae})],Rs.prototype,"base",void 0);u([l({type:d.Integer,context:0,defaultValue:0,implicit:!0})],Rs.prototype,"minimum",void 0);u([l({type:d.Integer,context:1,optional:!0,implicit:!0})],Rs.prototype,"maximum",void 0);var Jf=ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};Jf=ty=u([_({type:x.Sequence,itemType:Rs})],Jf);var Qf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Jf,context:0,optional:!0,implicit:!0})],Qf.prototype,"permittedSubtrees",void 0);u([l({type:Jf,context:1,optional:!0,implicit:!0})],Qf.prototype,"excludedSubtrees",void 0);var TR=`${le}.36`,eh=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ge})],eh.prototype,"requireExplicitPolicy",void 0);u([l({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ge})],eh.prototype,"inhibitPolicyMapping",void 0);var ry,DR=`${le}.33`,Fc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Fc.prototype,"issuerDomainPolicy",void 0);u([l({type:d.ObjectIdentifier})],Fc.prototype,"subjectDomainPolicy",void 0);var ov=ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};ov=ry=u([_({type:x.Sequence,itemType:Fc})],ov);var ny,oy=`${le}.17`,th=ny=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};th=ny=u([_({type:x.Sequence})],th);var dt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],dt.prototype,"type",void 0);u([l({type:d.Any,repeated:"set"})],dt.prototype,"values",void 0);var iy,ZR=`${le}.9`,iv=iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,iy.prototype)}};iv=iy=u([_({type:x.Sequence,itemType:dt})],iv);var sy=`${le}.14`,Ht=class extends yi{};var iL=`${le}.16`,rh=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],rh.prototype,"notBefore",void 0);u([l({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],rh.prototype,"notAfter",void 0);var Wc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Wc||(Wc={}));var nh=class extends Wr{toJSON(){let e=[],t=this.toNumber();return t&Wc.pKIXCertificate&&e.push("pKIXCertificate"),t&Wc.newExtensions&&e.push("newExtensions"),t&Wc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},oh=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new nh,Object.assign(this,e)}};u([l({type:d.GeneralString})],oh.prototype,"entrustVers",void 0);u([l({type:nh})],oh.prototype,"entrustInfoFlags",void 0);var ay,dL=`${lo}.11`,sv=ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ay.prototype)}};sv=ay=u([_({type:x.Sequence,itemType:En})],sv);var av=Rr(gn()),j=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&av.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};u([l({type:d.ObjectIdentifier})],j.prototype,"algorithm",void 0);u([l({type:d.Any,optional:!0})],j.prototype,"parameters",void 0);var mt=class{constructor(e={}){this.algorithm=new j,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],mt.prototype,"algorithm",void 0);u([l({type:d.BitString})],mt.prototype,"subjectPublicKey",void 0);var Ge=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};u([l({type:d.UTCTime})],Ge.prototype,"utcTime",void 0);u([l({type:d.GeneralizedTime})],Ge.prototype,"generalTime",void 0);Ge=u([_({type:x.Choice})],Ge);var Bn=class{constructor(e){this.notBefore=new Ge(new Date),this.notAfter=new Ge(new Date),e&&(this.notBefore=new Ge(e.notBefore),this.notAfter=new Ge(e.notAfter))}};u([l({type:Ge})],Bn.prototype,"notBefore",void 0);u([l({type:Ge})],Bn.prototype,"notAfter",void 0);var cy,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ie,Object.assign(this,e)}};yt.CRITICAL=!1;u([l({type:d.ObjectIdentifier})],yt.prototype,"extnID",void 0);u([l({type:d.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);u([l({type:ie})],yt.prototype,"extnValue",void 0);var Yt=cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cy.prototype)}};Yt=cy=u([_({type:x.Sequence,itemType:yt})],Yt);var zr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(zr||(zr={}));var gt=class{constructor(e={}){this.version=zr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new j,this.issuer=new Oe,this.validity=new Bn,this.subject=new Oe,this.subjectPublicKeyInfo=new mt,Object.assign(this,e)}};u([l({type:d.Integer,context:0,defaultValue:zr.v1})],gt.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],gt.prototype,"serialNumber",void 0);u([l({type:j})],gt.prototype,"signature",void 0);u([l({type:Oe})],gt.prototype,"issuer",void 0);u([l({type:Bn})],gt.prototype,"validity",void 0);u([l({type:Oe})],gt.prototype,"subject",void 0);u([l({type:mt})],gt.prototype,"subjectPublicKeyInfo",void 0);u([l({type:d.BitString,context:1,implicit:!0,optional:!0})],gt.prototype,"issuerUniqueID",void 0);u([l({type:d.BitString,context:2,implicit:!0,optional:!0})],gt.prototype,"subjectUniqueID",void 0);u([l({type:Yt,context:3,optional:!0})],gt.prototype,"extensions",void 0);var cr=class{constructor(e={}){this.tbsCertificate=new gt,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:gt,raw:!0})],cr.prototype,"tbsCertificate",void 0);u([l({type:j})],cr.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],cr.prototype,"signatureValue",void 0);var wi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ge,Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],wi.prototype,"userCertificate",void 0);u([l({type:Ge})],wi.prototype,"revocationDate",void 0);u([l({type:yt,optional:!0,repeated:"sequence"})],wi.prototype,"crlEntryExtensions",void 0);var Jt=class{constructor(e={}){this.signature=new j,this.issuer=new Oe,this.thisUpdate=new Ge,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Jt.prototype,"version",void 0);u([l({type:j})],Jt.prototype,"signature",void 0);u([l({type:Oe})],Jt.prototype,"issuer",void 0);u([l({type:Ge})],Jt.prototype,"thisUpdate",void 0);u([l({type:Ge,optional:!0})],Jt.prototype,"nextUpdate",void 0);u([l({type:wi,repeated:"sequence",optional:!0})],Jt.prototype,"revokedCertificates",void 0);u([l({type:yt,optional:!0,context:0,repeated:"sequence"})],Jt.prototype,"crlExtensions",void 0);var xi=class{constructor(e={}){this.tbsCertList=new Jt,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Jt,raw:!0})],xi.prototype,"tbsCertList",void 0);u([l({type:j})],xi.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],xi.prototype,"signature",void 0);var H=Rr(gn());var Or=class{constructor(e={}){this.issuer=new Oe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Oe})],Or.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],Or.prototype,"serialNumber",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],vi.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],vi.prototype,"issuerAndSerialNumber",void 0);vi=u([_({type:x.Choice})],vi);var bt;(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"})(bt||(bt={}));var Ai=class extends j{};Ai=u([_({type:x.Sequence})],Ai);var qc=class extends j{};qc=u([_({type:x.Sequence})],qc);var Vt=class extends j{};Vt=u([_({type:x.Sequence})],Vt);var Gc=class extends j{};Gc=u([_({type:x.Sequence})],Gc);var uv=class extends j{};uv=u([_({type:x.Sequence})],uv);var ih=class extends j{};ih=u([_({type:x.Sequence})],ih);var Pr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Pr.prototype,"attrType",void 0);u([l({type:d.Any,repeated:"set"})],Pr.prototype,"attrValues",void 0);var uy,$t=class{constructor(e={}){this.version=bt.v0,this.sid=new vi,this.digestAlgorithm=new Ai,this.signatureAlgorithm=new qc,this.signature=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],$t.prototype,"version",void 0);u([l({type:vi})],$t.prototype,"sid",void 0);u([l({type:Ai})],$t.prototype,"digestAlgorithm",void 0);u([l({type:Pr,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],$t.prototype,"signedAttrs",void 0);u([l({type:qc})],$t.prototype,"signatureAlgorithm",void 0);u([l({type:ie})],$t.prototype,"signature",void 0);u([l({type:Pr,repeated:"set",context:1,implicit:!0,optional:!0})],$t.prototype,"unsignedAttrs",void 0);var zc=uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};zc=uy=u([_({type:x.Set,itemType:$t})],zc);var lv=class extends Ge{};lv=u([_({type:x.Choice})],lv);var fv=class extends $t{};fv=u([_({type:x.Sequence})],fv);var Xc=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};u([l({type:ae})],Xc.prototype,"acIssuer",void 0);u([l({type:d.Integer})],Xc.prototype,"acSerial",void 0);u([l({type:dt,repeated:"sequence"})],Xc.prototype,"attrs",void 0);var ly,Zc=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};Zc=ly=u([_({type:x.Sequence,itemType:d.ObjectIdentifier})],Zc);var Ls=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Ls.prototype,"pathLenConstraint",void 0);u([l({type:Zc,implicit:!0,context:0,optional:!0})],Ls.prototype,"permittedAttrs",void 0);u([l({type:Zc,implicit:!0,context:1,optional:!0})],Ls.prototype,"excludedAttrs",void 0);u([l({type:d.Boolean,defaultValue:!0})],Ls.prototype,"permitUnSpecified",void 0);var ur=class{constructor(e={}){this.issuer=new je,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:je})],ur.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],ur.prototype,"serial",void 0);u([l({type:d.BitString,optional:!0})],ur.prototype,"issuerUID",void 0);var fy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(fy||(fy={}));var lr=class{constructor(e={}){this.digestedObjectType=fy.publicKey,this.digestAlgorithm=new j,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Enumerated})],lr.prototype,"digestedObjectType",void 0);u([l({type:d.ObjectIdentifier,optional:!0})],lr.prototype,"otherObjectTypeID",void 0);u([l({type:j})],lr.prototype,"digestAlgorithm",void 0);u([l({type:d.BitString})],lr.prototype,"objectDigest",void 0);var Si=class{constructor(e={}){Object.assign(this,e)}};u([l({type:je,optional:!0})],Si.prototype,"issuerName",void 0);u([l({type:ur,context:0,implicit:!0,optional:!0})],Si.prototype,"baseCertificateID",void 0);u([l({type:lr,context:1,implicit:!0,optional:!0})],Si.prototype,"objectDigestInfo",void 0);var Ei=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,repeated:"sequence"})],Ei.prototype,"v1Form",void 0);u([l({type:Si,context:0,implicit:!0})],Ei.prototype,"v2Form",void 0);Ei=u([_({type:x.Choice})],Ei);var _i=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};u([l({type:d.GeneralizedTime})],_i.prototype,"notBeforeTime",void 0);u([l({type:d.GeneralizedTime})],_i.prototype,"notAfterTime",void 0);var ho=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ur,implicit:!0,context:0,optional:!0})],ho.prototype,"baseCertificateID",void 0);u([l({type:je,implicit:!0,context:1,optional:!0})],ho.prototype,"entityName",void 0);u([l({type:lr,implicit:!0,context:2,optional:!0})],ho.prototype,"objectDigestInfo",void 0);var hy;(function(r){r[r.v2=1]="v2"})(hy||(hy={}));var Ft=class{constructor(e={}){this.version=hy.v2,this.holder=new ho,this.issuer=new Ei,this.signature=new j,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new _i,this.attributes=[],Object.assign(this,e)}};u([l({type:d.Integer})],Ft.prototype,"version",void 0);u([l({type:ho})],Ft.prototype,"holder",void 0);u([l({type:Ei})],Ft.prototype,"issuer",void 0);u([l({type:j})],Ft.prototype,"signature",void 0);u([l({type:d.Integer,converter:ge})],Ft.prototype,"serialNumber",void 0);u([l({type:_i})],Ft.prototype,"attrCertValidityPeriod",void 0);u([l({type:dt,repeated:"sequence"})],Ft.prototype,"attributes",void 0);u([l({type:d.BitString,optional:!0})],Ft.prototype,"issuerUniqueID",void 0);u([l({type:Yt,optional:!0})],Ft.prototype,"extensions",void 0);var Ci=class{constructor(e={}){this.acinfo=new Ft,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Ft})],Ci.prototype,"acinfo",void 0);u([l({type:j})],Ci.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Ci.prototype,"signatureValue",void 0);var Yc;(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"})(Yc||(Yc={}));var Us=class extends Wr{};var Ms=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier,implicit:!0,context:0})],Ms.prototype,"type",void 0);u([l({type:d.Any,implicit:!0,context:1})],Ms.prototype,"value",void 0);var Jc=class{constructor(e={}){this.policyId="",this.classList=new Us(Yc.unclassified),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Jc.prototype,"policyId",void 0);u([l({type:Us,defaultValue:new Us(Yc.unclassified)})],Jc.prototype,"classList",void 0);u([l({type:Ms,repeated:"set"})],Jc.prototype,"securityCategories",void 0);var js=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie})],js.prototype,"cotets",void 0);u([l({type:d.ObjectIdentifier})],js.prototype,"oid",void 0);u([l({type:d.Utf8String})],js.prototype,"string",void 0);var sh=class{constructor(e={}){this.values=[],Object.assign(this,e)}};u([l({type:je,implicit:!0,context:0,optional:!0})],sh.prototype,"policyAuthority",void 0);u([l({type:js,repeated:"sequence"})],sh.prototype,"values",void 0);var zj=`${lo}.4`,Xj=`${lo}.6`,Zj=`${lo}.10`,Yj=`${le}.55`,Qc=`${uo}.10`,Jj=`${Qc}.1`,Qj=`${Qc}.2`,e9=`${Qc}.3`,t9=`${Qc}.4`,r9=`${Qc}.6`,py="2.5.4",n9=`${py}.72`;var dy,Ks=class{constructor(e={}){this.targetCertificate=new ur,Object.assign(this,e)}};u([l({type:ur})],Ks.prototype,"targetCertificate",void 0);u([l({type:ae,optional:!0})],Ks.prototype,"targetName",void 0);u([l({type:lr,optional:!0})],Ks.prototype,"certDigestInfo",void 0);var Hs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ae,context:0,implicit:!0})],Hs.prototype,"targetName",void 0);u([l({type:ae,context:1,implicit:!0})],Hs.prototype,"targetGroup",void 0);u([l({type:Ks,context:2,implicit:!0})],Hs.prototype,"targetCert",void 0);Hs=u([_({type:x.Choice})],Hs);var ah=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};ah=dy=u([_({type:x.Sequence,itemType:Hs})],ah);var my,hv=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};hv=my=u([_({type:x.Sequence,itemType:ah})],hv);var ch=class{constructor(e={}){Object.assign(this,e)}};u([l({type:je,implicit:!0,context:0,optional:!0})],ch.prototype,"roleAuthority",void 0);u([l({type:ae,implicit:!0,context:1})],ch.prototype,"roleName",void 0);var eu=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};u([l({type:ae})],eu.prototype,"service",void 0);u([l({type:ae})],eu.prototype,"ident",void 0);u([l({type:ie,optional:!0})],eu.prototype,"authInfo",void 0);var yy,tu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],tu.prototype,"otherCertFormat",void 0);u([l({type:d.Any})],tu.prototype,"otherCert",void 0);var Bi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:cr})],Bi.prototype,"certificate",void 0);u([l({type:Ci,context:2,implicit:!0})],Bi.prototype,"v2AttrCert",void 0);u([l({type:tu,context:3,implicit:!0})],Bi.prototype,"other",void 0);Bi=u([_({type:x.Choice})],Bi);var Ii=yy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};Ii=yy=u([_({type:x.Set,itemType:Bi})],Ii);var fr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],fr.prototype,"contentType",void 0);u([l({type:d.Any,context:0})],fr.prototype,"content",void 0);var Vs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie})],Vs.prototype,"single",void 0);u([l({type:d.Any})],Vs.prototype,"any",void 0);Vs=u([_({type:x.Choice})],Vs);var Ti=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ti.prototype,"eContentType",void 0);u([l({type:Vs,context:0,optional:!0})],Ti.prototype,"eContent",void 0);var ru=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ie,context:0,implicit:!0,optional:!0})],ru.prototype,"value",void 0);u([l({type:ie,converter:Hx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],ru.prototype,"constructedValue",void 0);ru=u([_({type:x.Choice})],ru);var po=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Gc,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],po.prototype,"contentType",void 0);u([l({type:Gc})],po.prototype,"contentEncryptionAlgorithm",void 0);u([l({type:ru,optional:!0})],po.prototype,"encryptedContent",void 0);var mo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],mo.prototype,"keyAttrId",void 0);u([l({type:d.Any,optional:!0})],mo.prototype,"keyAttr",void 0);var gy,$s=class{constructor(e={}){this.subjectKeyIdentifier=new Ht,Object.assign(this,e)}};u([l({type:Ht})],$s.prototype,"subjectKeyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],$s.prototype,"date",void 0);u([l({type:mo,optional:!0})],$s.prototype,"other",void 0);var Fs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:$s,context:0,implicit:!0,optional:!0})],Fs.prototype,"rKeyId",void 0);u([l({type:Or,optional:!0})],Fs.prototype,"issuerAndSerialNumber",void 0);Fs=u([_({type:x.Choice})],Fs);var nu=class{constructor(e={}){this.rid=new Fs,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:Fs})],nu.prototype,"rid",void 0);u([l({type:ie})],nu.prototype,"encryptedKey",void 0);var uh=gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,gy.prototype)}};uh=gy=u([_({type:x.Sequence,itemType:nu})],uh);var ou=class{constructor(e={}){this.algorithm=new j,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],ou.prototype,"algorithm",void 0);u([l({type:d.BitString})],ou.prototype,"publicKey",void 0);var ki=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0,optional:!0})],ki.prototype,"subjectKeyIdentifier",void 0);u([l({type:ou,context:1,implicit:!0,optional:!0})],ki.prototype,"originatorKey",void 0);u([l({type:Or,optional:!0})],ki.prototype,"issuerAndSerialNumber",void 0);ki=u([_({type:x.Choice})],ki);var In=class{constructor(e={}){this.version=bt.v3,this.originator=new ki,this.keyEncryptionAlgorithm=new Vt,this.recipientEncryptedKeys=new uh,Object.assign(this,e)}};u([l({type:d.Integer})],In.prototype,"version",void 0);u([l({type:ki,context:0})],In.prototype,"originator",void 0);u([l({type:ie,context:1,optional:!0})],In.prototype,"ukm",void 0);u([l({type:Vt})],In.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:uh})],In.prototype,"recipientEncryptedKeys",void 0);var Ws=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],Ws.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],Ws.prototype,"issuerAndSerialNumber",void 0);Ws=u([_({type:x.Choice})],Ws);var yo=class{constructor(e={}){this.version=bt.v0,this.rid=new Ws,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],yo.prototype,"version",void 0);u([l({type:Ws})],yo.prototype,"rid",void 0);u([l({type:Vt})],yo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],yo.prototype,"encryptedKey",void 0);var Oi=class{constructor(e={}){this.keyIdentifier=new ie,Object.assign(this,e)}};u([l({type:ie})],Oi.prototype,"keyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],Oi.prototype,"date",void 0);u([l({type:mo,optional:!0})],Oi.prototype,"other",void 0);var go=class{constructor(e={}){this.version=bt.v4,this.kekid=new Oi,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],go.prototype,"version",void 0);u([l({type:Oi})],go.prototype,"kekid",void 0);u([l({type:Vt})],go.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],go.prototype,"encryptedKey",void 0);var bo=class{constructor(e={}){this.version=bt.v0,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],bo.prototype,"version",void 0);u([l({type:ih,context:0,optional:!0})],bo.prototype,"keyDerivationAlgorithm",void 0);u([l({type:Vt})],bo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:ie})],bo.prototype,"encryptedKey",void 0);var iu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],iu.prototype,"oriType",void 0);u([l({type:d.Any})],iu.prototype,"oriValue",void 0);var Tn=class{constructor(e={}){Object.assign(this,e)}};u([l({type:yo,optional:!0})],Tn.prototype,"ktri",void 0);u([l({type:In,context:1,implicit:!0,optional:!0})],Tn.prototype,"kari",void 0);u([l({type:go,context:2,implicit:!0,optional:!0})],Tn.prototype,"kekri",void 0);u([l({type:bo,context:3,implicit:!0,optional:!0})],Tn.prototype,"pwri",void 0);u([l({type:iu,context:4,implicit:!0,optional:!0})],Tn.prototype,"ori",void 0);Tn=u([_({type:x.Choice})],Tn);var by,su=by=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};su=by=u([_({type:x.Set,itemType:Tn})],su);var wy,pv=`${uo}.16`,rH=`${pv}.2`,nH=`${pv}.4`,qs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],qs.prototype,"otherRevInfoFormat",void 0);u([l({type:d.Any})],qs.prototype,"otherRevInfo",void 0);var lh=class{constructor(e={}){this.other=new qs,Object.assign(this,e)}};u([l({type:qs,context:1,implicit:!0})],lh.prototype,"other",void 0);lh=u([_({type:x.Choice})],lh);var Gs=wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Gs=wy=u([_({type:x.Set,itemType:lh})],Gs);var zs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ii,context:0,implicit:!0,optional:!0})],zs.prototype,"certs",void 0);u([l({type:Gs,context:1,implicit:!0,optional:!0})],zs.prototype,"crls",void 0);var xy,vy=xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};vy=xy=u([_({type:x.Set,itemType:Pr})],vy);var Pi=class{constructor(e={}){this.version=bt.v0,this.recipientInfos=new su,this.encryptedContentInfo=new po,Object.assign(this,e)}};u([l({type:d.Integer})],Pi.prototype,"version",void 0);u([l({type:zs,context:0,implicit:!0,optional:!0})],Pi.prototype,"originatorInfo",void 0);u([l({type:su})],Pi.prototype,"recipientInfos",void 0);u([l({type:po})],Pi.prototype,"encryptedContentInfo",void 0);u([l({type:vy,context:1,implicit:!0,optional:!0})],Pi.prototype,"unprotectedAttrs",void 0);var dv="1.2.840.113549.1.7.2";var Ay,fh=Ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};fh=Ay=u([_({type:x.Set,itemType:Ai})],fh);var kn=class{constructor(e={}){this.version=bt.v0,this.digestAlgorithms=new fh,this.encapContentInfo=new Ti,this.signerInfos=new zc,Object.assign(this,e)}};u([l({type:d.Integer})],kn.prototype,"version",void 0);u([l({type:fh})],kn.prototype,"digestAlgorithms",void 0);u([l({type:Ti})],kn.prototype,"encapContentInfo",void 0);u([l({type:Ii,context:0,implicit:!0,optional:!0})],kn.prototype,"certificates",void 0);u([l({type:Gs,context:1,implicit:!0,optional:!0})],kn.prototype,"crls",void 0);u([l({type:zc})],kn.prototype,"signerInfos",void 0);var Ni="1.2.840.10045.2.1";var au="1.2.840.10045.4.1",hh="1.2.840.10045.4.3.1",cu="1.2.840.10045.4.3.2",uu="1.2.840.10045.4.3.3",lu="1.2.840.10045.4.3.4";var Sy="1.2.840.10045.3.1.7";var Ey="1.3.132.0.34";var _y="1.3.132.0.35";function fu(r){return new j({algorithm:r})}var yv=fu(au),QH=fu(hh),gv=fu(cu),bv=fu(uu),wv=fu(lu);var hu=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],hu.prototype,"fieldType",void 0);u([l({type:d.Any})],hu.prototype,"parameters",void 0);hu=u([_({type:x.Sequence})],hu);var Cy=class extends ie{};var Xs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.OctetString})],Xs.prototype,"a",void 0);u([l({type:d.OctetString})],Xs.prototype,"b",void 0);u([l({type:d.BitString,optional:!0})],Xs.prototype,"seed",void 0);Xs=u([_({type:x.Sequence})],Xs);var By;(function(r){r[r.ecpVer1=1]="ecpVer1"})(By||(By={}));var Xr=class{constructor(e={}){this.version=By.ecpVer1,Object.assign(this,e)}};u([l({type:d.Integer})],Xr.prototype,"version",void 0);u([l({type:hu})],Xr.prototype,"fieldID",void 0);u([l({type:Xs})],Xr.prototype,"curve",void 0);u([l({type:Cy})],Xr.prototype,"base",void 0);u([l({type:d.Integer,converter:ge})],Xr.prototype,"order",void 0);u([l({type:d.Integer,optional:!0})],Xr.prototype,"cofactor",void 0);Xr=u([_({type:x.Sequence})],Xr);var Zr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Zr.prototype,"namedCurve",void 0);u([l({type:d.Null})],Zr.prototype,"implicitCurve",void 0);u([l({type:Xr})],Zr.prototype,"specifiedCurve",void 0);Zr=u([_({type:x.Choice})],Zr);var Zs=class{constructor(e={}){this.version=1,this.privateKey=new ie,Object.assign(this,e)}};u([l({type:d.Integer})],Zs.prototype,"version",void 0);u([l({type:ie})],Zs.prototype,"privateKey",void 0);u([l({type:Zr,context:0,optional:!0})],Zs.prototype,"parameters",void 0);u([l({type:d.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)}};u([l({type:d.Integer,converter:ge})],Di.prototype,"r",void 0);u([l({type:d.Integer,converter:ge})],Di.prototype,"s",void 0);var Wt="1.2.840.113549.1.1",Yr=`${Wt}.1`,xv=`${Wt}.7`,vv=`${Wt}.9`,wo=`${Wt}.10`,Av=`${Wt}.2`,Sv=`${Wt}.4`,Ys=`${Wt}.5`,Ev=`${Wt}.14`;var ph=`${Wt}.11`,Js=`${Wt}.12`,Qs=`${Wt}.13`,Iy=`${Wt}.15`,Ty=`${Wt}.16`,Ri="1.3.14.3.2.26",dh="2.16.840.1.101.3.4.2.4",Li="2.16.840.1.101.3.4.2.1",Ui="2.16.840.1.101.3.4.2.2",Mi="2.16.840.1.101.3.4.2.3",_v="2.16.840.1.101.3.4.2.5",Cv="2.16.840.1.101.3.4.2.6",Bv="1.2.840.113549.2.2",Iv="1.2.840.113549.2.5",xo=`${Wt}.8`;function it(r){return new j({algorithm:r,parameters:null})}var BV=it(Bv),IV=it(Iv),On=it(Ri),TV=it(dh),kV=it(Li),OV=it(Ui),PV=it(Mi),NV=it(_v),DV=it(Cv),mh=new j({algorithm:xo,parameters:F.serialize(On)}),ky=new j({algorithm:vv,parameters:F.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))}),RV=it(Yr),LV=it(Av),UV=it(Sv),MV=it(Ys),jV=it(Iy),KV=it(Ty),HV=it(Js),VV=it(Qs),$V=it(Iy),FV=it(Ty);var ea=class{constructor(e={}){this.hashAlgorithm=new j(On),this.maskGenAlgorithm=new j({algorithm:xo,parameters:F.serialize(On)}),this.pSourceAlgorithm=new j(ky),Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:On})],ea.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:mh})],ea.prototype,"maskGenAlgorithm",void 0);u([l({type:j,context:2,defaultValue:ky})],ea.prototype,"pSourceAlgorithm",void 0);var YV=new j({algorithm:xv,parameters:F.serialize(new ea)});var Jr=class{constructor(e={}){this.hashAlgorithm=new j(On),this.maskGenAlgorithm=new j({algorithm:xo,parameters:F.serialize(On)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:On})],Jr.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:mh})],Jr.prototype,"maskGenAlgorithm",void 0);u([l({type:d.Integer,context:2,defaultValue:20})],Jr.prototype,"saltLength",void 0);u([l({type:d.Integer,context:3,defaultValue:1})],Jr.prototype,"trailerField",void 0);var o7=new j({algorithm:wo,parameters:F.serialize(new Jr)});var ji=class{constructor(e={}){this.digestAlgorithm=new j,this.digest=new ie,Object.assign(this,e)}};u([l({type:j})],ji.prototype,"digestAlgorithm",void 0);u([l({type:ie})],ji.prototype,"digest",void 0);var Oy,ta=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],ta.prototype,"prime",void 0);u([l({type:d.Integer,converter:ge})],ta.prototype,"exponent",void 0);u([l({type:d.Integer,converter:ge})],ta.prototype,"coefficient",void 0);var yh=Oy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Oy.prototype)}};yh=Oy=u([_({type:x.Sequence,itemType:ta})],yh);var hr=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)}};u([l({type:d.Integer})],hr.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"publicExponent",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"privateExponent",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"prime1",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"prime2",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"exponent1",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"exponent2",void 0);u([l({type:d.Integer,converter:ge})],hr.prototype,"coefficient",void 0);u([l({type:yh,optional:!0})],hr.prototype,"otherPrimeInfos",void 0);var ra=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],ra.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],ra.prototype,"publicExponent",void 0);var Py;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Py||(Py={}));var wt=Py;var Zv=Rr(Xv(),1),{__extends:oa,__assign:R7,__rest:WC,__decorate:L7,__param:U7,__metadata:M7,__awaiter:Yv,__generator:Jv,__exportStar:j7,__createBinding:K7,__values:pu,__read:du,__spread:Nr,__spreadArrays:H7,__await:V7,__asyncGenerator:$7,__asyncDelegator:F7,__asyncValues:W7,__makeTemplateObject:q7,__importStar:G7,__importDefault:z7,__classPrivateFieldGet:X7,__classPrivateFieldSet:Z7}=Zv.default;var qC="injectionTokens";function Dy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(qC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function mu(r){return!!r.useClass}function ia(r){return!!r.useFactory}var wh=(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,Nr(i))}};return this.reflectMethods.forEach(n),t},r})();function vo(r){return typeof r=="string"||typeof r=="symbol"}function Ry(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function xh(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Qv(r){return typeof r=="function"||r instanceof wh}function Ki(r){return!!r.useToken}function Hi(r){return r.useValue!=null}function e1(r){return mu(r)||Hi(r)||Ki(r)||ia(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})(),yu=GC;var zC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu),t1=zC;var XC=(function(){function r(){this.scopedResolutions=new Map}return r})(),gu=XC;function ZC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function YC(r,e,t){return t===void 0&&(t=" "),Nr([r],e.message.split(`
|
7
7
|
`).map(function(n){return t+n})).join(`
|
8
|
-
`)}function Ly(r,e,t){var n=du(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=ZC(i,e);return YC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function r1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var JC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu);var QC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu);var eB=(function(){function r(){this.preResolution=new JC,this.postResolution=new QC}return r})(),n1=eB;var Uy=new Map,tB=(function(){function r(e){this.parent=e,this._registry=new t1,this.interceptors=new n1,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(e1(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! "+Nr(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)||ia(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 gu),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(Qv(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=pu(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(f){n={error:f}}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=pu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var f=c.value;f.options.frequency!="Once"&&s.push(f),f.callback(e,t,n)}}catch(p){o={error:p}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===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):mu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ia(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 gu),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=pu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=du(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=pu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=du(i.value,2),a=s[0],c=s[1];c.some(function(f){var p=f.options;return p.lifecycle===wt.ContainerScoped})&&n._registry.setAll(a,c.map(function(f){return f.options.lifecycle===wt.ContainerScoped?{provider:f.provider,options:f.options}:f}))}}catch(f){e={error:f}}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 Yv(this,void 0,void 0,function(){var e;return Jv(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 wh)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=Uy.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,Nr([void 0],s)))})();return r1(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 Ry(o)?xh(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Nr([n.resolveAll(o.token,new gu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Nr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new gu,o.isOptional):n.resolve(o.token,e,o.isOptional):xh(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Nr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(f){throw new Error(Ly(t,i,f))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),De=new tB;function rB(r){return function(e){Uy.set(e,Dy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){De.register(t,e)}):De.register(r.token,e))}}var Ao=rB;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var jy,Vi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};u([l({type:d.ObjectIdentifier})],Vi.prototype,"attrId",void 0);u([l({type:d.Any,repeated:"set"})],Vi.prototype,"attrValues",void 0);var o1=jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};o1=jy=u([_({type:x.Sequence,itemType:Vi})],o1);var Ky,i1=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};i1=Ky=u([_({type:x.Sequence,itemType:fr})],i1);var nB="1.2.840.113549",oB=`${nB}.1`,s1=`${oB}.12`,sa=`${s1}.1`,sW=`${sa}.1`,aW=`${sa}.2`,cW=`${sa}.3`,uW=`${sa}.4`,lW=`${sa}.5`,fW=`${sa}.6`,$i=`${s1}.10.1`;var dW=`${$i}.1`,mW=`${$i}.2`,yW=`${$i}.3`,gW=`${$i}.4`,bW=`${$i}.5`,wW=`${$i}.6`,vh="1.2.840.113549.1.9";var Ah=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ah.prototype,"certId",void 0);u([l({type:d.Any,context:0})],Ah.prototype,"certValue",void 0);var a1=`${vh}.22`,EW=`${a1}.1`,_W=`${a1}.2`;var Sh=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Sh.prototype,"crlId",void 0);u([l({type:d.Any,context:0})],Sh.prototype,"crltValue",void 0);var iB=`${vh}.23`,kW=`${iB}.1`;var Eh=class extends ie{},So=class{constructor(e={}){this.encryptionAlgorithm=new j,this.encryptedData=new Eh,Object.assign(this,e)}};u([l({type:j})],So.prototype,"encryptionAlgorithm",void 0);u([l({type:Eh})],So.prototype,"encryptedData",void 0);var Hy,Vy;(function(r){r[r.v1=0]="v1"})(Vy||(Vy={}));var _h=class extends ie{},$y=Hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Hy.prototype)}};$y=Hy=u([_({type:x.Sequence,itemType:dt})],$y);var Eo=class{constructor(e={}){this.version=Vy.v1,this.privateKeyAlgorithm=new j,this.privateKey=new _h,Object.assign(this,e)}};u([l({type:d.Integer})],Eo.prototype,"version",void 0);u([l({type:j})],Eo.prototype,"privateKeyAlgorithm",void 0);u([l({type:_h})],Eo.prototype,"privateKey",void 0);u([l({type:$y,implicit:!0,context:0,optional:!0})],Eo.prototype,"attributes",void 0);var c1=class extends Eo{};c1=u([_({type:x.Sequence})],c1);var u1=class extends So{};u1=u([_({type:x.Sequence})],u1);var Ch=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ch.prototype,"secretTypeId",void 0);u([l({type:d.Any,context:0})],Ch.prototype,"secretValue",void 0);var _o=class{constructor(e={}){this.mac=new ji,this.macSalt=new ie,this.iterations=1,Object.assign(this,e)}};u([l({type:ji})],_o.prototype,"mac",void 0);u([l({type:ie})],_o.prototype,"macSalt",void 0);u([l({type:d.Integer,defaultValue:1})],_o.prototype,"iterations",void 0);var Fi=class{constructor(e={}){this.version=3,this.authSafe=new fr,this.macData=new _o,Object.assign(this,e)}};u([l({type:d.Integer})],Fi.prototype,"version",void 0);u([l({type:fr})],Fi.prototype,"authSafe",void 0);u([l({type:_o,optional:!0})],Fi.prototype,"macData",void 0);var Fy,aa=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],aa.prototype,"bagId",void 0);u([l({type:d.Any,context:0})],aa.prototype,"bagValue",void 0);u([l({type:Vi,repeated:"set",optional:!0})],aa.prototype,"bagAttributes",void 0);var l1=Fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Fy.prototype)}};l1=Fy=u([_({type:x.Sequence,itemType:aa})],l1);var Wy,qy,Gy,ze="1.2.840.113549.1.9",Pq=`${ze}.0`,E1=`${ze}.24`,wu=`${ze}.25`,_1=`${ze}.26`,C1=`${ze}.27`,Nq=`${E1}.1`,Dq=`${E1}.2`,Rq=`${ze}.1`,Lq=`${ze}.2`,Uq=`${ze}.3`,Mq=`${ze}.4`,jq=`${ze}.5`,Kq=`${ze}.6`,tg=`${ze}.7`,Hq=`${ze}.8`,Vq=`${ze}.9`,$q=`${ze}.13`,xu=`${ze}.14`,Fq=`${ze}.15`,Wq=`${ze}.20`,qq=`${ze}.21`;var Gq=`${wu}.1`,zq=`${wu}.2`,Xq=`${wu}.3`,Zq=`${wu}.4`,Yq=`${wu}.5`,vu="1.3.6.1.5.5.7.9",Jq=`${vu}.1`,Qq=`${vu}.2`,eG=`${vu}.3`,tG=`${vu}.4`,rG=`${vu}.5`,nG=`${_1}.1`,oG=`${_1}.2`,iG=`${C1}.1`,sG=`${C1}.2`,aG=`${ze}.16`,cG=`${ze}.22`,uG=`${ze}.23`,lG=`${py}.65`,Bh=class extends et{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};u([l({type:d.IA5String})],Bh.prototype,"ia5String",void 0);Bh=u([_({type:x.Choice})],Bh);var f1=class extends fr{};f1=u([_({type:x.Sequence})],f1);var h1=class extends Fi{};h1=u([_({type:x.Sequence})],h1);var p1=class extends So{};p1=u([_({type:x.Sequence})],p1);var zy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.IA5String})],zy.prototype,"value",void 0);zy=u([_({type:x.Choice})],zy);var d1=class extends Bh{};d1=u([_({type:x.Choice})],d1);var m1=class extends et{};m1=u([_({type:x.Choice})],m1);var Xy=class{constructor(e=new Date){this.value=e}};u([l({type:d.GeneralizedTime})],Xy.prototype,"value",void 0);Xy=u([_({type:x.Choice})],Xy);var y1=class extends et{};y1=u([_({type:x.Choice})],y1);var Zy=class{constructor(e="M"){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],Zy.prototype,"value",void 0);Zy=u([_({type:x.Choice})],Zy);var Ih=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],Ih.prototype,"value",void 0);Ih=u([_({type:x.Choice})],Ih);var g1=class extends Ih{};g1=u([_({type:x.Choice})],g1);var b1=class extends et{};b1=u([_({type:x.Choice})],b1);var Yy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.ObjectIdentifier})],Yy.prototype,"value",void 0);Yy=u([_({type:x.Choice})],Yy);var w1=class extends Ge{};w1=u([_({type:x.Choice})],w1);var Jy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};u([l({type:d.Integer})],Jy.prototype,"value",void 0);Jy=u([_({type:x.Choice})],Jy);var x1=class extends $t{};x1=u([_({type:x.Sequence})],x1);var bu=class extends et{};bu=u([_({type:x.Choice})],bu);var v1=Wy=class extends Yt{constructor(e){super(e),Object.setPrototypeOf(this,Wy.prototype)}};v1=Wy=u([_({type:x.Sequence})],v1);var A1=qy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qy.prototype)}};A1=qy=u([_({type:x.Set,itemType:Pr})],A1);var Qy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.BmpString})],Qy.prototype,"value",void 0);Qy=u([_({type:x.Choice})],Qy);var eg=class extends j{};eg=u([_({type:x.Sequence})],eg);var S1=Gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gy.prototype)}};S1=Gy=u([_({type:x.Sequence,itemType:eg})],S1);var rg,Au=rg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,rg.prototype)}};Au=rg=u([_({type:x.Sequence,itemType:dt})],Au);var Qr=class{constructor(e={}){this.version=0,this.subject=new Oe,this.subjectPKInfo=new mt,this.attributes=new Au,Object.assign(this,e)}};u([l({type:d.Integer})],Qr.prototype,"version",void 0);u([l({type:Oe})],Qr.prototype,"subject",void 0);u([l({type:mt})],Qr.prototype,"subjectPKInfo",void 0);u([l({type:Au,implicit:!0,context:0})],Qr.prototype,"attributes",void 0);var Co=class{constructor(e={}){this.certificationRequestInfo=new Qr,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Qr,raw:!0})],Co.prototype,"certificationRequestInfo",void 0);u([l({type:j})],Co.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Co.prototype,"signature",void 0);var qu="crypto.algorithm",hg=class{getAlgorithms(){return De.resolveAll(qu)}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 j({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";De.registerSingleton(Wi,hg);var Ph,Gt="1.3.36.3.3.2.8.1.1",B1=`${Gt}.1`,I1=`${Gt}.2`,T1=`${Gt}.3`,k1=`${Gt}.4`,O1=`${Gt}.5`,P1=`${Gt}.6`,N1=`${Gt}.7`,D1=`${Gt}.8`,R1=`${Gt}.9`,L1=`${Gt}.10`,U1=`${Gt}.11`,M1=`${Gt}.12`,j1=`${Gt}.13`,K1=`${Gt}.14`,H1="brainpoolP160r1",V1="brainpoolP160t1",$1="brainpoolP192r1",F1="brainpoolP192t1",W1="brainpoolP224r1",q1="brainpoolP224t1",G1="brainpoolP256r1",z1="brainpoolP256t1",X1="brainpoolP320r1",Z1="brainpoolP320t1",Y1="brainpoolP384r1",J1="brainpoolP384t1",Q1="brainpoolP512r1",eA="brainpoolP512t1",Ve="ECDSA",Vu=Ph=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 yv;case"sha-256":return gv;case"sha-384":return bv;case"sha-512":return wv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Sy;break;case"K-256":t=Ph.SECP256K1;break;case"P-384":t=Ey;break;case"P-521":t=_y;break;case H1:t=B1;break;case V1:t=I1;break;case $1:t=T1;break;case F1:t=k1;break;case W1:t=O1;break;case q1:t=P1;break;case G1:t=N1;break;case z1:t=D1;break;case X1:t=R1;break;case Z1:t=L1;break;case Y1:t=U1;break;case J1:t=M1;break;case Q1:t=j1;break;case eA:t=K1;break}if(t)return new j({algorithm:Ni,parameters:F.serialize(new Zr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case au:return{name:Ve,hash:{name:"SHA-1"}};case cu:return{name:Ve,hash:{name:"SHA-256"}};case uu:return{name:Ve,hash:{name:"SHA-384"}};case lu:return{name:Ve,hash:{name:"SHA-512"}};case Ni:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,Zr).namedCurve){case Sy:return{name:Ve,namedCurve:"P-256"};case Ph.SECP256K1:return{name:Ve,namedCurve:"K-256"};case Ey:return{name:Ve,namedCurve:"P-384"};case _y:return{name:Ve,namedCurve:"P-521"};case B1:return{name:Ve,namedCurve:H1};case I1:return{name:Ve,namedCurve:V1};case T1:return{name:Ve,namedCurve:$1};case k1:return{name:Ve,namedCurve:F1};case O1:return{name:Ve,namedCurve:W1};case P1:return{name:Ve,namedCurve:q1};case N1:return{name:Ve,namedCurve:G1};case D1:return{name:Ve,namedCurve:z1};case R1:return{name:Ve,namedCurve:X1};case L1:return{name:Ve,namedCurve:Z1};case U1:return{name:Ve,namedCurve:Y1};case M1:return{name:Ve,namedCurve:J1};case j1:return{name:Ve,namedCurve:Q1};case K1:return{name:Ve,namedCurve:eA}}}}return null}};Vu.SECP256K1="1.3.132.0.10";Vu=Ph=u([Ao()],Vu);De.registerSingleton(qu,Vu);var fA=Symbol("name"),hA=Symbol("value"),_e=class{constructor(e,t={},n=""){this[fA]=e,this[hA]=n;for(let o in t)this[o]=t[o]}};_e.NAME=fA;_e.VALUE=hA;var pg=class{static toTextObject(e){let t=new _e("Algorithm Identifier",{},tn.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}},tn=class{static toString(e){let t=this.items[e];return t||e}};tn.items={[Ri]:"sha1",[dh]:"sha224",[Li]:"sha256",[Ui]:"sha384",[Mi]:"sha512",[Yr]:"rsaEncryption",[Ys]:"sha1WithRSAEncryption",[Ev]:"sha224WithRSAEncryption",[ph]:"sha256WithRSAEncryption",[Js]:"sha384WithRSAEncryption",[Qs]:"sha512WithRSAEncryption",[Ni]:"ecPublicKey",[au]:"ecdsaWithSHA1",[hh]:"ecdsaWithSHA224",[cu]:"ecdsaWithSHA256",[uu]:"ecdsaWithSHA384",[lu]:"ecdsaWithSHA512",[Zx]:"TLS WWW server authentication",[Yx]:"TLS WWW client authentication",[Jx]:"Code Signing",[Qx]:"E-mail Protection",[ev]:"Time Stamping",[tv]:"OCSP Signing",[dv]:"Signed Data"};var Nn=class{static serialize(e){return this.serializeObj(e).join(`
|
8
|
+
`)}function Ly(r,e,t){var n=du(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=ZC(i,e);return YC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function r1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var JC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu);var QC=(function(r){oa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(yu);var eB=(function(){function r(){this.preResolution=new JC,this.postResolution=new QC}return r})(),n1=eB;var Uy=new Map,tB=(function(){function r(e){this.parent=e,this._registry=new t1,this.interceptors=new n1,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(e1(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! "+Nr(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)||ia(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 gu),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(Qv(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=pu(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(f){n={error:f}}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=pu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var f=c.value;f.options.frequency!="Once"&&s.push(f),f.callback(e,t,n)}}catch(p){o={error:p}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===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):mu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ia(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 gu),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=pu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=du(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=pu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=du(i.value,2),a=s[0],c=s[1];c.some(function(f){var p=f.options;return p.lifecycle===wt.ContainerScoped})&&n._registry.setAll(a,c.map(function(f){return f.options.lifecycle===wt.ContainerScoped?{provider:f.provider,options:f.options}:f}))}}catch(f){e={error:f}}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 Yv(this,void 0,void 0,function(){var e;return Jv(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 wh)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=Uy.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,Nr([void 0],s)))})();return r1(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 Ry(o)?xh(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Nr([n.resolveAll(o.token,new gu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Nr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new gu,o.isOptional):n.resolve(o.token,e,o.isOptional):xh(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Nr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(f){throw new Error(Ly(t,i,f))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),De=new tB;function rB(r){return function(e){Uy.set(e,Dy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){De.register(t,e)}):De.register(r.token,e))}}var Ao=rB;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);var jy,Vi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};u([l({type:d.ObjectIdentifier})],Vi.prototype,"attrId",void 0);u([l({type:d.Any,repeated:"set"})],Vi.prototype,"attrValues",void 0);var o1=jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};o1=jy=u([_({type:x.Sequence,itemType:Vi})],o1);var Ky,i1=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};i1=Ky=u([_({type:x.Sequence,itemType:fr})],i1);var nB="1.2.840.113549",oB=`${nB}.1`,s1=`${oB}.12`,sa=`${s1}.1`,aW=`${sa}.1`,cW=`${sa}.2`,uW=`${sa}.3`,lW=`${sa}.4`,fW=`${sa}.5`,hW=`${sa}.6`,$i=`${s1}.10.1`;var mW=`${$i}.1`,yW=`${$i}.2`,gW=`${$i}.3`,bW=`${$i}.4`,wW=`${$i}.5`,xW=`${$i}.6`,vh="1.2.840.113549.1.9";var Ah=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ah.prototype,"certId",void 0);u([l({type:d.Any,context:0})],Ah.prototype,"certValue",void 0);var a1=`${vh}.22`,_W=`${a1}.1`,CW=`${a1}.2`;var Sh=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Sh.prototype,"crlId",void 0);u([l({type:d.Any,context:0})],Sh.prototype,"crltValue",void 0);var iB=`${vh}.23`,OW=`${iB}.1`;var Eh=class extends ie{},So=class{constructor(e={}){this.encryptionAlgorithm=new j,this.encryptedData=new Eh,Object.assign(this,e)}};u([l({type:j})],So.prototype,"encryptionAlgorithm",void 0);u([l({type:Eh})],So.prototype,"encryptedData",void 0);var Hy,Vy;(function(r){r[r.v1=0]="v1"})(Vy||(Vy={}));var _h=class extends ie{},$y=Hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Hy.prototype)}};$y=Hy=u([_({type:x.Sequence,itemType:dt})],$y);var Eo=class{constructor(e={}){this.version=Vy.v1,this.privateKeyAlgorithm=new j,this.privateKey=new _h,Object.assign(this,e)}};u([l({type:d.Integer})],Eo.prototype,"version",void 0);u([l({type:j})],Eo.prototype,"privateKeyAlgorithm",void 0);u([l({type:_h})],Eo.prototype,"privateKey",void 0);u([l({type:$y,implicit:!0,context:0,optional:!0})],Eo.prototype,"attributes",void 0);var c1=class extends Eo{};c1=u([_({type:x.Sequence})],c1);var u1=class extends So{};u1=u([_({type:x.Sequence})],u1);var Ch=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Ch.prototype,"secretTypeId",void 0);u([l({type:d.Any,context:0})],Ch.prototype,"secretValue",void 0);var _o=class{constructor(e={}){this.mac=new ji,this.macSalt=new ie,this.iterations=1,Object.assign(this,e)}};u([l({type:ji})],_o.prototype,"mac",void 0);u([l({type:ie})],_o.prototype,"macSalt",void 0);u([l({type:d.Integer,defaultValue:1})],_o.prototype,"iterations",void 0);var Fi=class{constructor(e={}){this.version=3,this.authSafe=new fr,this.macData=new _o,Object.assign(this,e)}};u([l({type:d.Integer})],Fi.prototype,"version",void 0);u([l({type:fr})],Fi.prototype,"authSafe",void 0);u([l({type:_o,optional:!0})],Fi.prototype,"macData",void 0);var Fy,aa=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],aa.prototype,"bagId",void 0);u([l({type:d.Any,context:0})],aa.prototype,"bagValue",void 0);u([l({type:Vi,repeated:"set",optional:!0})],aa.prototype,"bagAttributes",void 0);var l1=Fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Fy.prototype)}};l1=Fy=u([_({type:x.Sequence,itemType:aa})],l1);var Wy,qy,Gy,ze="1.2.840.113549.1.9",Nq=`${ze}.0`,E1=`${ze}.24`,wu=`${ze}.25`,_1=`${ze}.26`,C1=`${ze}.27`,Dq=`${E1}.1`,Rq=`${E1}.2`,Lq=`${ze}.1`,Uq=`${ze}.2`,Mq=`${ze}.3`,jq=`${ze}.4`,Kq=`${ze}.5`,Hq=`${ze}.6`,tg=`${ze}.7`,Vq=`${ze}.8`,$q=`${ze}.9`,Fq=`${ze}.13`,xu=`${ze}.14`,Wq=`${ze}.15`,qq=`${ze}.20`,Gq=`${ze}.21`;var zq=`${wu}.1`,Xq=`${wu}.2`,Zq=`${wu}.3`,Yq=`${wu}.4`,Jq=`${wu}.5`,vu="1.3.6.1.5.5.7.9",Qq=`${vu}.1`,eG=`${vu}.2`,tG=`${vu}.3`,rG=`${vu}.4`,nG=`${vu}.5`,oG=`${_1}.1`,iG=`${_1}.2`,sG=`${C1}.1`,aG=`${C1}.2`,cG=`${ze}.16`,uG=`${ze}.22`,lG=`${ze}.23`,fG=`${py}.65`,Bh=class extends et{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};u([l({type:d.IA5String})],Bh.prototype,"ia5String",void 0);Bh=u([_({type:x.Choice})],Bh);var f1=class extends fr{};f1=u([_({type:x.Sequence})],f1);var h1=class extends Fi{};h1=u([_({type:x.Sequence})],h1);var p1=class extends So{};p1=u([_({type:x.Sequence})],p1);var zy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.IA5String})],zy.prototype,"value",void 0);zy=u([_({type:x.Choice})],zy);var d1=class extends Bh{};d1=u([_({type:x.Choice})],d1);var m1=class extends et{};m1=u([_({type:x.Choice})],m1);var Xy=class{constructor(e=new Date){this.value=e}};u([l({type:d.GeneralizedTime})],Xy.prototype,"value",void 0);Xy=u([_({type:x.Choice})],Xy);var y1=class extends et{};y1=u([_({type:x.Choice})],y1);var Zy=class{constructor(e="M"){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],Zy.prototype,"value",void 0);Zy=u([_({type:x.Choice})],Zy);var Ih=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],Ih.prototype,"value",void 0);Ih=u([_({type:x.Choice})],Ih);var g1=class extends Ih{};g1=u([_({type:x.Choice})],g1);var b1=class extends et{};b1=u([_({type:x.Choice})],b1);var Yy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.ObjectIdentifier})],Yy.prototype,"value",void 0);Yy=u([_({type:x.Choice})],Yy);var w1=class extends Ge{};w1=u([_({type:x.Choice})],w1);var Jy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};u([l({type:d.Integer})],Jy.prototype,"value",void 0);Jy=u([_({type:x.Choice})],Jy);var x1=class extends $t{};x1=u([_({type:x.Sequence})],x1);var bu=class extends et{};bu=u([_({type:x.Choice})],bu);var v1=Wy=class extends Yt{constructor(e){super(e),Object.setPrototypeOf(this,Wy.prototype)}};v1=Wy=u([_({type:x.Sequence})],v1);var A1=qy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qy.prototype)}};A1=qy=u([_({type:x.Set,itemType:Pr})],A1);var Qy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.BmpString})],Qy.prototype,"value",void 0);Qy=u([_({type:x.Choice})],Qy);var eg=class extends j{};eg=u([_({type:x.Sequence})],eg);var S1=Gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gy.prototype)}};S1=Gy=u([_({type:x.Sequence,itemType:eg})],S1);var rg,Au=rg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,rg.prototype)}};Au=rg=u([_({type:x.Sequence,itemType:dt})],Au);var Qr=class{constructor(e={}){this.version=0,this.subject=new Oe,this.subjectPKInfo=new mt,this.attributes=new Au,Object.assign(this,e)}};u([l({type:d.Integer})],Qr.prototype,"version",void 0);u([l({type:Oe})],Qr.prototype,"subject",void 0);u([l({type:mt})],Qr.prototype,"subjectPKInfo",void 0);u([l({type:Au,implicit:!0,context:0})],Qr.prototype,"attributes",void 0);var Co=class{constructor(e={}){this.certificationRequestInfo=new Qr,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Qr,raw:!0})],Co.prototype,"certificationRequestInfo",void 0);u([l({type:j})],Co.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Co.prototype,"signature",void 0);var qu="crypto.algorithm",hg=class{getAlgorithms(){return De.resolveAll(qu)}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 j({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";De.registerSingleton(Wi,hg);var Ph,Gt="1.3.36.3.3.2.8.1.1",B1=`${Gt}.1`,I1=`${Gt}.2`,T1=`${Gt}.3`,k1=`${Gt}.4`,O1=`${Gt}.5`,P1=`${Gt}.6`,N1=`${Gt}.7`,D1=`${Gt}.8`,R1=`${Gt}.9`,L1=`${Gt}.10`,U1=`${Gt}.11`,M1=`${Gt}.12`,j1=`${Gt}.13`,K1=`${Gt}.14`,H1="brainpoolP160r1",V1="brainpoolP160t1",$1="brainpoolP192r1",F1="brainpoolP192t1",W1="brainpoolP224r1",q1="brainpoolP224t1",G1="brainpoolP256r1",z1="brainpoolP256t1",X1="brainpoolP320r1",Z1="brainpoolP320t1",Y1="brainpoolP384r1",J1="brainpoolP384t1",Q1="brainpoolP512r1",eA="brainpoolP512t1",Ve="ECDSA",Vu=Ph=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 yv;case"sha-256":return gv;case"sha-384":return bv;case"sha-512":return wv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Sy;break;case"K-256":t=Ph.SECP256K1;break;case"P-384":t=Ey;break;case"P-521":t=_y;break;case H1:t=B1;break;case V1:t=I1;break;case $1:t=T1;break;case F1:t=k1;break;case W1:t=O1;break;case q1:t=P1;break;case G1:t=N1;break;case z1:t=D1;break;case X1:t=R1;break;case Z1:t=L1;break;case Y1:t=U1;break;case J1:t=M1;break;case Q1:t=j1;break;case eA:t=K1;break}if(t)return new j({algorithm:Ni,parameters:F.serialize(new Zr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case au:return{name:Ve,hash:{name:"SHA-1"}};case cu:return{name:Ve,hash:{name:"SHA-256"}};case uu:return{name:Ve,hash:{name:"SHA-384"}};case lu:return{name:Ve,hash:{name:"SHA-512"}};case Ni:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,Zr).namedCurve){case Sy:return{name:Ve,namedCurve:"P-256"};case Ph.SECP256K1:return{name:Ve,namedCurve:"K-256"};case Ey:return{name:Ve,namedCurve:"P-384"};case _y:return{name:Ve,namedCurve:"P-521"};case B1:return{name:Ve,namedCurve:H1};case I1:return{name:Ve,namedCurve:V1};case T1:return{name:Ve,namedCurve:$1};case k1:return{name:Ve,namedCurve:F1};case O1:return{name:Ve,namedCurve:W1};case P1:return{name:Ve,namedCurve:q1};case N1:return{name:Ve,namedCurve:G1};case D1:return{name:Ve,namedCurve:z1};case R1:return{name:Ve,namedCurve:X1};case L1:return{name:Ve,namedCurve:Z1};case U1:return{name:Ve,namedCurve:Y1};case M1:return{name:Ve,namedCurve:J1};case j1:return{name:Ve,namedCurve:Q1};case K1:return{name:Ve,namedCurve:eA}}}}return null}};Vu.SECP256K1="1.3.132.0.10";Vu=Ph=u([Ao()],Vu);De.registerSingleton(qu,Vu);var fA=Symbol("name"),hA=Symbol("value"),_e=class{constructor(e,t={},n=""){this[fA]=e,this[hA]=n;for(let o in t)this[o]=t[o]}};_e.NAME=fA;_e.VALUE=hA;var pg=class{static toTextObject(e){let t=new _e("Algorithm Identifier",{},tn.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}},tn=class{static toString(e){let t=this.items[e];return t||e}};tn.items={[Ri]:"sha1",[dh]:"sha224",[Li]:"sha256",[Ui]:"sha384",[Mi]:"sha512",[Yr]:"rsaEncryption",[Ys]:"sha1WithRSAEncryption",[Ev]:"sha224WithRSAEncryption",[ph]:"sha256WithRSAEncryption",[Js]:"sha384WithRSAEncryption",[Qs]:"sha512WithRSAEncryption",[Ni]:"ecPublicKey",[au]:"ecdsaWithSHA1",[hh]:"ecdsaWithSHA224",[cu]:"ecdsaWithSHA256",[uu]:"ecdsaWithSHA384",[lu]:"ecdsaWithSHA512",[Zx]:"TLS WWW server authentication",[Yx]:"TLS WWW client authentication",[Jx]:"Code Signing",[Qx]:"E-mail Protection",[ev]:"Time Stamping",[tv]:"OCSP Signing",[dv]:"Signed Data"};var Nn=class{static serialize(e){return this.serializeObj(e).join(`
|
9
9
|
`)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[_e.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[_e.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],f=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${f}${c}`);else if(c instanceof Date)n.push(`${o}${f}${c.toUTCString()}`);else if(Array.isArray(c))for(let p of c)p[_e.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof _e)c[_e.NAME]=a,n.push(...this.serializeObj(c,t));else if(H.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${f}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let p=c.toTextObject();p[_e.NAME]=a,n.push(...this.serializeObj(p,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=H.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 f=o[s++].toString(16).padStart(2,"0");a.push(f)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Nn.oidSerializer=tn;Nn.algorithmSerializer=pg;var ca,Bo=class r{get rawData(){return he(this,ca,"f")||Me(this,ca,F.serialize(this.asn),"f"),he(this,ca,"f")}constructor(...e){ca.set(this,void 0),H.BufferSourceConverter.isBufferSource(e[0])?(this.asn=F.parse(e[0],e[1]),Me(this,ca,H.BufferSourceConverter.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof r?(0,H.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return F.toString(this.rawData);case"text":return Nn.serialize(this.toTextObject());case"hex":return H.Convert.ToHex(this.rawData);case"base64":return H.Convert.ToBase64(this.rawData);case"base64url":return H.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new _e(this.getTextName(),{},e)}};ca=new WeakMap;Bo.NAME="ASN";var Qt=class r extends Bo{constructor(...e){let t;H.BufferSourceConverter.isBufferSource(e[0])?t=H.BufferSourceConverter.toArrayBuffer(e[0]):t=F.serialize(new yt({extnID:e[0],critical:e[1],extnValue:new ie(H.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[_e.NAME]===r.NAME&&(e[_e.NAME]=tn.toString(this.type)),e}},pA,$u=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[pA]="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}};pA=Symbol.toStringTag;$u.DEFAULT="default";var ut=new $u,uB=/^[0-2](?:\.[1-9][0-9]*)+$/;function lB(r){return new RegExp(uB).test(r)}var Dh=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 lB(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},qt=new Dh;qt.register("CN","2.5.4.3");qt.register("L","2.5.4.7");qt.register("ST","2.5.4.8");qt.register("O","2.5.4.10");qt.register("OU","2.5.4.11");qt.register("C","2.5.4.6");qt.register("DC","0.9.2342.19200300.100.1.25");qt.register("E","1.2.840.113549.1.9.1");qt.register("G","2.5.4.42");qt.register("I","2.5.4.43");qt.register("SN","2.5.4.4");qt.register("T","2.5.4.12");function fB(r,e){return`\\${H.Convert.ToHex(H.Convert.FromUtf8String(e)).toUpperCase()}`}function hB(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,fB)}var Dr=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 Dh,this.asn=new Oe;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 Oe?this.asn=e:H.BufferSourceConverter.isBufferSource(e)?this.asn=F.parse(e,Oe):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||qt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||qt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${H.Convert.ToHex(t.value.anyValue)}`:hB(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?`#${H.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Oe,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 f=o[3];s=this.getTypeOid(s);let p=this.createAttribute(s,a);i==="+"?t[t.length-1].push(p):t.push(new ao([p])),i=f}return t}fromJSON(e){let t=new Oe;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 f=this.createAttribute(s,c);o.push(f)}}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 pi({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=H.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
10
|
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return F.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||ut.get()):n=e[0]||ut.get(),await n.subtle.digest(o,this.toArrayBuffer())}},dA="Cannot initialize GeneralName from ASN.1 data.",tA=`${dA} Unsupported string format in use.`,pB=`${dA} Value doesn't match to GUID regular expression.`,rA=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,nA="1.3.6.1.4.1.311.25.1",oA="1.3.6.1.4.1.311.20.2.3",ng="dns",og="dn",ig="email",sg="ip",ag="url",cg="guid",ug="upn",Th="id",en=class extends Bo{constructor(...e){let t;if(e.length===2)switch(e[0]){case og:{let n=new Dr(e[1]).toArrayBuffer(),o=F.parse(n,Oe);t=new ae({directoryName:o});break}case ng:t=new ae({dNSName:e[1]});break;case ig:t=new ae({rfc822Name:e[1]});break;case cg:{let n=new RegExp(rA,"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?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(i)).reverse()):i).join("");t=new ae({otherName:new co({typeId:nA,value:F.serialize(new ie(H.Convert.FromHex(o)))})});break}case sg:t=new ae({iPAddress:e[1]});break;case Th:t=new ae({registeredID:e[1]});break;case ug:{t=new ae({otherName:new co({typeId:oA,value:F.serialize(Nm.toASN(e[1]))})});break}case ag:t=new ae({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else H.BufferSourceConverter.isBufferSource(e[0])?t=F.parse(e[0],ae):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=ng,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=ig,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=sg,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=ag,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Th,this.value=e.registeredID;else if(e.directoryName!=null)this.type=og,this.value=new Dr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===nA){this.type=cg;let t=F.parse(e.otherName.value,ie),n=new RegExp(rA,"i").exec(H.Convert.ToHex(t));if(!n)throw new Error(pB);this.value=n.slice(1).map((o,i)=>i<3?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===oA)this.type=ug,this.value=F.parse(e.otherName.value,et).toString();else throw new Error(tA);else throw new Error(tA)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case og:case ng:case cg:case sg:case Th:case ug:case ag:e=this.type.toUpperCase();break;case ig:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Th&&(t=tn.toString(t)),new _e(e,void 0,t)}},Dn=class extends Bo{constructor(e){let t;if(e instanceof je)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ae)n.push(o);else{let i=F.parse(new en(o.type,o.value).rawData,ae);n.push(i)}t=new je(n)}else if(H.BufferSourceConverter.isBufferSource(e))t=F.parse(e,je);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 en(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[_e.NAME]];Array.isArray(o)||(o=[],e[n[_e.NAME]]=o),o.push(n)}return e}};Dn.NAME="GeneralNames";var Hu="-{5}",Fu="\\n",dB=`[^${Fu}]+`,mB=`${Hu}BEGIN (${dB}(?=${Hu}))${Hu}`,yB=`${Hu}END \\1${Hu}`,fa="\\n",gB=`[^:${Fu}]+`,bB=`(?:[^${Fu}]+${fa}(?: +[^${Fu}]+${fa})*)`,wB="[a-zA-Z0-9=+/]+",xB=`(?:${wB}${fa})+`,iA=`${mB}${fa}(?:((?:${gB}: ${bB})+))?${fa}?(${xB})${yB}`,Dt=class{static isPem(e){return typeof e=="string"&&new RegExp(iA,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(iA,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${Fu}]+`,"g"),""),s={type:o[1],headers:[],rawData:H.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(fa,"g")),f=null;for(let p of c){let[h,y]=p.split(/:(.*)/);if(y===void 0){if(!f)throw new Error("Cannot parse PEM string. Incorrect header value");f.value+=h.trim()}else f&&s.headers.push(f),f={key:h,value:y.trim()}}f&&s.headers.push(f)}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(!H.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:H.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
|
11
11
|
`)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:H.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 f of e.headers)o.push(`${f.key}: ${f.value}`);o.push("")}let i=H.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
|
-
`)}};Dt.CertificateTag="CERTIFICATE";Dt.CrlTag="CRL";Dt.CertificateRequestTag="CERTIFICATE REQUEST";Dt.PublicKeyTag="PUBLIC KEY";Dt.PrivateKeyTag="PRIVATE KEY";var Io=class r extends Bo{static isAsnEncoded(e){return H.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Dt.isPem(e))return Dt.decode(e)[0];if(H.Convert.isHex(e))return H.Convert.FromHex(e);if(H.Convert.isBase64(e))return H.Convert.FromBase64(e);if(H.Convert.isBase64Url(e))return H.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=H.BufferSourceConverter.toUint8Array(e);if(t.length>0&&t[0]===48)return H.BufferSourceConverter.toArrayBuffer(e);let n=H.Convert.ToBinary(e);if(Dt.isPem(n))return Dt.decode(n)[0];if(H.Convert.isHex(n))return H.Convert.FromHex(n);if(H.Convert.isBase64(n))return H.Convert.FromBase64(n);if(H.Convert.isBase64Url(n))return H.Convert.FromBase64Url(n);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Dt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Pn=class r extends Io{static async create(e,t=ut.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(H.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Io.isAsnEncoded(e)?super(e,mt):super(e),this.tag=Dt.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]||ut.get()):t=e[0]||ut.get();let i=this.rawData,s=F.parse(this.rawData,mt);return s.algorithm.algorithm===wo&&(i=vB(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=De.resolve(Wi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Yr:{let o=F.parse(e.subjectPublicKey,ra),i=H.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=H.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]||ut.get()):n=e[0]||ut.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=ut.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=ut.get();let o=F.parse(this.rawData,mt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,mt);switch(e.Algorithm=Nn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ni:e["EC Point"]=t.subjectPublicKey;break;case Yr:default:e["Raw Data"]=t.subjectPublicKey}return e}};function vB(r,e){return r.algorithm=new j({algorithm:Yr,parameters:null}),e=F.serialize(r),e}var Rh=class r extends Qt{static async create(e,t=!1,n=ut.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new qr({keyIdentifier:new yi(H.Convert.FromHex(e[0]))});super(Wf,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Dn?F.parse(t.name.rawData,je):t.name,o=new qr({authorityCertIssuer:n,authorityCertSerialNumber:H.Convert.FromHex(t.serialNumber)});super(Wf,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,qr);t.keyIdentifier&&(this.keyId=H.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?H.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,qr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Dn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Rh.NAME="Authority Key Identifier";var ha=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,gi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new gi({cA:e[0],pathLenConstraint:e[1]});super(qf,e[2],F.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};ha.NAME="Basic Constraints";var sA;(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"})(sA||(sA={}));var Lh=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Vc);this.usages=t.map(n=>n)}else{let t=new Vc(e[0]);super(Zf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>tn.toString(t)).join(", "),e}};Lh.NAME="Extended Key Usages";var aA;(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"})(aA||(aA={}));var Uh=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Ds);this.usages=t.toNumber()}else{let t=new Ds(e[0]);super(Yf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Ds);return e[""]=t.toJSON().join(", "),e}};Uh.NAME="Key Usages";var Mh=class r extends Qt{static async create(e,t=!1,n=ut.get()){let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Ht);this.keyId=H.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?H.Convert.FromHex(e[0]):e[0],n=new Ht(t);super(sy,e[1],F.serialize(n)),this.keyId=H.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Ht);return e[""]=t,e}};Mh.NAME="Subject Key Identifier";var jh=class extends Qt{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(oy,e[1],new Dn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,th);this.names=new Dn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};jh.NAME="Subject Alternative Name";var Rt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new Qt(e),n=this.items.get(t.type);return n?new n(e):t}};Rt.items=new Map;var Kh=class extends Qt{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,Uc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Uc(n.map(s=>new bi({policyIdentifier:s})));super(zf,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new _e("",{},tn.toString(t))),e}};Kh.NAME="Certificate Policies";Rt.register(zf,Kh);var Hh=class extends Qt{constructor(...e){var t;if(H.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 Gr({distributionPoint:new Cn({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new fo(o);super(Xf,e[1],F.serialize(i))}else{let n=new fo(e[0]);super(Xf,e[1],F.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,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 en(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Hh.NAME="CRL Distribution Points";var Vh=class extends Qt{constructor(...e){var t,n,o,i;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof mi){let s=new mi(e[0]);super(Ff,e[1],F.serialize(s))}else{let s=e[0],a=new mi;Oh(a,s,Hm,"ocsp"),Oh(a,s,Vm,"caIssuers"),Oh(a,s,$m,"timeStamping"),Oh(a,s,Fm,"caRepository"),super(Ff,e[1],F.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],F.parse(e.extnValue,mi).forEach(n=>{switch(n.accessMethod){case Hm:this.ocsp.push(new en(n.accessLocation));break;case Vm:this.caIssuers.push(new en(n.accessLocation));break;case $m:this.timeStamping.push(new en(n.accessLocation));break;case Fm:this.caRepository.push(new en(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&kh(e,"OCSP",this.ocsp),this.caIssuers.length&&kh(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&kh(e,"Time Stamping",this.timeStamping),this.caRepository.length&&kh(e,"CA Repository",this.caRepository),e}};Vh.NAME="Authority Info Access";function kh(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 Oh(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new en("url",s)),r.push(new En({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var $h=class extends Qt{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(ey,e[1],new Dn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,je);this.names=new Dn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};$h.NAME="Issuer Alternative Name";var pa=class r extends Bo{constructor(...e){let t;if(H.BufferSourceConverter.isBufferSource(e[0]))t=H.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>H.BufferSourceConverter.toArrayBuffer(i)):[];t=F.serialize(new dt({type:n,values:o}))}super(t,dt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new _e("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[_e.NAME]===r.NAME&&(e[_e.NAME]=tn.toString(this.type)),e}};pa.NAME="Attribute";var Fh=class extends pa{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new bu({printableString:e[0]});super(tg,[F.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],bu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[_e.VALUE]=this.password,e}};Fh.NAME="Challenge Password";var Wu=class extends pa{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new Yt;for(let i of n)o.push(F.parse(i.rawData,yt));super(xu,[F.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],Yt);this.items=t.map(n=>Rt.create(F.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}};Wu.NAME="Extensions";var da=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new pa(e),n=this.items.get(t.type);return n?new n(e):t}};da.items=new Map;var Gu="crypto.signatureFormatter",dg=class{toAsnSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}},Nh,mg=Nh=class{static createPssParams(e,t){let n=Nh.getHashAlgorithm(e);return n?new Jr({hashAlgorithm:n,maskGenAlgorithm:new j({algorithm:xo,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=De.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 j({algorithm:Ys,parameters:null});case"sha-256":return new j({algorithm:ph,parameters:null});case"sha-384":return new j({algorithm:Js,parameters:null});case"sha-512":return new j({algorithm:Qs,parameters:null})}}else return new j({algorithm:Yr,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=Nh.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new j({algorithm:wo,parameters:F.serialize(t)})}else return new j({algorithm:wo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Yr:return{name:"RSASSA-PKCS1-v1_5"};case Ys:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case ph:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Js:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Qs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case wo:if(e.parameters){let t=F.parse(e.parameters,Jr);return{name:"RSA-PSS",hash:De.resolve(Wi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};mg=Nh=u([Ao()],mg);De.registerSingleton(qu,mg);var yg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new j({algorithm:Ri});case"sha-256":return new j({algorithm:Li});case"sha-384":return new j({algorithm:Ui});case"sha-512":return new j({algorithm:Mi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ri:return{name:"SHA-1"};case Li:return{name:"SHA-256"};case Ui:return{name:"SHA-384"};case Mi:return{name:"SHA-512"}}return null}};yg=u([Ao()],yg);De.registerSingleton(qu,yg);var Rn=class r{addPadding(e,t){let n=H.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o.buffer}removePadding(e,t=!1){let n=H.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=H.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),F.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=F.parse(t,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,H.combine)(s,a)}return null}};Rn.namedCurveSize=new Map;Rn.defaultNamedCurveSize=32;var lg="1.3.101.110",cA="1.3.101.111",fg="1.3.101.112",uA="1.3.101.113",gg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=fg;break;case"x25519":t=lg;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=fg;break;case"ed448":t=uA;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=lg;break;case"x448":t=cA;break}}return t?new j({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case fg:return{name:"Ed25519"};case uA:return{name:"EdDSA",namedCurve:"Ed448"};case lg:return{name:"X25519"};case cA:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};gg=u([Ao()],gg);De.registerSingleton(qu,gg);var Su,Eu,_u,Cu,Bu,Iu,Tu,ua,bg=class extends Io{get subjectName(){return he(this,Eu,"f")||Me(this,Eu,new Dr(this.asn.certificationRequestInfo.subject),"f"),he(this,Eu,"f")}get subject(){return he(this,_u,"f")||Me(this,_u,this.subjectName.toString(),"f"),he(this,_u,"f")}get signatureAlgorithm(){if(!he(this,Cu,"f")){let e=De.resolve(Wi);Me(this,Cu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,Cu,"f")}get signature(){return he(this,Bu,"f")||Me(this,Bu,this.asn.signature,"f"),he(this,Bu,"f")}get publicKey(){return he(this,Iu,"f")||Me(this,Iu,new Pn(this.asn.certificationRequestInfo.subjectPKInfo),"f"),he(this,Iu,"f")}get attributes(){return he(this,Tu,"f")||Me(this,Tu,this.asn.certificationRequestInfo.attributes.map(e=>da.create(F.serialize(e))),"f"),he(this,Tu,"f")}get extensions(){if(!he(this,ua,"f")){Me(this,ua,[],"f");let e=this.getAttribute(xu);e instanceof Wu&&Me(this,ua,e.items,"f")}return he(this,ua,"f")}get tbs(){return he(this,Su,"f")||Me(this,Su,this.asn.certificationRequestInfoRaw||F.serialize(this.asn.certificationRequestInfo),"f"),he(this,Su,"f")}constructor(e){let t=Io.isAsnEncoded(e)?[e,Co]:[e];super(t[0],t[1]),Su.set(this,void 0),Eu.set(this,void 0),_u.set(this,void 0),Cu.set(this,void 0),Bu.set(this,void 0),Iu.set(this,void 0),Tu.set(this,void 0),ua.set(this,void 0),this.tag=Dt.CertificateRequestTag}onInit(e){}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=ut.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=De.resolveAll(Gu).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,Co),n=t.certificationRequestInfo,o=new _e("",{Version:`${zr[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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Su=new WeakMap,Eu=new WeakMap,_u=new WeakMap,Cu=new WeakMap,Bu=new WeakMap,Iu=new WeakMap,Tu=new WeakMap,ua=new WeakMap;bg.NAME="PKCS#10 Certificate Request";var ku,Ou,Pu,Nu,Du,Ru,Lu,Uu,Mu,ju,la,Ku,ma=class extends Io{get publicKey(){return he(this,Ku,"f")||Me(this,Ku,new Pn(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),he(this,Ku,"f")}get serialNumber(){if(!he(this,Ou,"f")){let e=this.asn.tbsCertificate,t=new Uint8Array(e.serialNumber);t.length>1&&t[0]===0&&t[1]>127&&(t=t.slice(1)),Me(this,Ou,H.Convert.ToHex(t),"f")}return he(this,Ou,"f")}get subjectName(){return he(this,Pu,"f")||Me(this,Pu,new Dr(this.asn.tbsCertificate.subject),"f"),he(this,Pu,"f")}get subject(){return he(this,Nu,"f")||Me(this,Nu,this.subjectName.toString(),"f"),he(this,Nu,"f")}get issuerName(){return he(this,Du,"f")||Me(this,Du,new Dr(this.asn.tbsCertificate.issuer),"f"),he(this,Du,"f")}get issuer(){return he(this,Ru,"f")||Me(this,Ru,this.issuerName.toString(),"f"),he(this,Ru,"f")}get notBefore(){if(!he(this,Lu,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Me(this,Lu,e,"f")}return he(this,Lu,"f")}get notAfter(){if(!he(this,Uu,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Me(this,Uu,e,"f")}return he(this,Uu,"f")}get signatureAlgorithm(){if(!he(this,Mu,"f")){let e=De.resolve(Wi);Me(this,Mu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,Mu,"f")}get signature(){return he(this,ju,"f")||Me(this,ju,this.asn.signatureValue,"f"),he(this,ju,"f")}get extensions(){return he(this,la,"f")||(Me(this,la,[],"f"),this.asn.tbsCertificate.extensions&&Me(this,la,this.asn.tbsCertificate.extensions.map(e=>Rt.create(F.serialize(e))),"f")),he(this,la,"f")}get tbs(){return he(this,ku,"f")||Me(this,ku,this.asn.tbsCertificateRaw||F.serialize(this.asn.tbsCertificate),"f"),he(this,ku,"f")}constructor(e){let t=Io.isAsnEncoded(e)?[e,cr]:[e];super(t[0],t[1]),ku.set(this,void 0),Ou.set(this,void 0),Pu.set(this,void 0),Nu.set(this,void 0),Du.set(this,void 0),Ru.set(this,void 0),Lu.set(this,void 0),Uu.set(this,void 0),Mu.set(this,void 0),ju.set(this,void 0),la.set(this,void 0),Ku.set(this,void 0),this.tag=Dt.CertificateTag}onInit(e){}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=ut.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 Pn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(H.BufferSourceConverter.isBufferSource(i)){let f=new Pn(i);n={...f.algorithm,...this.signatureAlgorithm},o=await f.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=De.resolveAll(Gu).reverse(),a=null;for(let f of s)if(a=f.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let p=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<p&&p<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=ut.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=ut.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,cr),n=t.tbsCertificate,o=new _e("",{Version:`${zr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Nn.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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ku=new WeakMap,Ou=new WeakMap,Pu=new WeakMap,Nu=new WeakMap,Du=new WeakMap,Ru=new WeakMap,Lu=new WeakMap,Uu=new WeakMap,Mu=new WeakMap,ju=new WeakMap,la=new WeakMap,Ku=new WeakMap;ma.NAME="Certificate";function AB(r,e=ut.get()){let t=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(r||"")),n=t&&t.length&&t.some(i=>i>0)?new Uint8Array(t):void 0;n||(n=e.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n.buffer}var Wh=class{static async createSelfSigned(e,t=ut.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=ut.get()){var n;let o;e.publicKey instanceof Pn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:H.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=AB(e.serialNumber),s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new cr({tbsCertificate:new gt({version:zr.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new Yt(((n=e.extensions)===null||n===void 0?void 0:n.map(m=>F.parse(m.rawData,yt)))||[]),subjectPublicKeyInfo:F.parse(o,mt)})});if(e.subject){let m=e.subject instanceof Dr?e.subject:new Dr(e.subject);c.tbsCertificate.subject=F.parse(m.toArrayBuffer(),Oe)}if(e.issuer){let m=e.issuer instanceof Dr?e.issuer:new Dr(e.issuer);c.tbsCertificate.issuer=F.parse(m.toArrayBuffer(),Oe)}let f={hash:"SHA-256"},p="signingKey"in e?{...f,...e.signingAlgorithm,...e.signingKey.algorithm}:{...f,...e.signingAlgorithm},h=De.resolve(Wi);c.tbsCertificate.signature=c.signatureAlgorithm=h.toAsnAlgorithm(p);let y=F.serialize(c.tbsCertificate),b="signingKey"in e?await t.subtle.sign(p,e.signingKey,y):e.signature,g=De.resolveAll(Gu).reverse(),C=null;for(let m of g)if(C=m.toAsnSignature(p,b),C)break;if(!C)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=C,new ma(F.serialize(c))}},SB,EB,_B,CB,BB,lA;(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"})(lA||(lA={}));SB=new WeakMap,EB=new WeakMap,_B=new WeakMap,CB=new WeakMap,BB=new WeakMap;var IB,TB,kB,OB,PB,NB,DB;IB=new WeakMap,TB=new WeakMap,kB=new WeakMap,OB=new WeakMap,PB=new WeakMap,NB=new WeakMap,DB=new WeakMap;Rt.register(qf,ha);Rt.register(Zf,Lh);Rt.register(Yf,Uh);Rt.register(sy,Mh);Rt.register(Wf,Rh);Rt.register(oy,jh);Rt.register(Xf,Hh);Rt.register(Ff,Vh);Rt.register(ey,$h);da.register(tg,Fh);da.register(xu,Wu);De.registerSingleton(Gu,dg);De.registerSingleton(Gu,Rn);Rn.namedCurveSize.set("P-256",32);Rn.namedCurveSize.set("K-256",32);Rn.namedCurveSize.set("P-384",48);Rn.namedCurveSize.set("P-521",66);var Ln="/",mA=new TextEncoder().encode(Ln),qh=mA[0],zu=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=de(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==qh)throw new Error("Invalid key")}toString(e="utf8"){return ue(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Ln))}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=mA),this._buf[0]!==qh){let e=new Uint8Array(this._buf.byteLength+1);e.fill(qh,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===qh;)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(Ln).slice(1)}type(){return RB(this.baseNamespace())}name(){return LB(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Ln)||(e+=Ln),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Ln):new r(e.slice(0,-1).join(Ln))}child(e){return this.toString()===Ln?e:e.toString()===Ln?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(),...UB(e.map(t=>t.namespaces()))])}};function RB(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function LB(r){let e=r.split(":");return e[e.length-1]}function UB(r){return[].concat(...r)}var Gh=class extends er{async listen(){throw new gf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var ya=!!globalThis.process?.env?.DUMP_SESSION_KEYS,wg=16;function MB(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function zh(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Xh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function lt(r,e,t=""){let n=MB(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function xg(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 yA(r,e){lt(r,void 0,"output");let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Un(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Mn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function jB(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var KB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function gA(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function bA(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 vg=(r,e)=>{function t(n,...o){if(lt(n,void 0,"key"),!KB)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let p=o[0];lt(p,r.varSizeNonce?void 0:r.nonceLength,"nonce")}let i=r.tagLength;i&&o[1]!==void 0&<(o[1],void 0,"AAD");let s=e(n,...o),a=(p,h)=>{if(h!==void 0){if(p!==2)throw new Error("cipher output not supported");lt(h,void 0,"output")}},c=!1;return{encrypt(p,h){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,lt(p),a(s.encrypt.length,h),s.encrypt(p,h)},decrypt(p,h){if(lt(p),i&&p.length<i)throw new Error('"ciphertext" expected length bigger than tagLength='+i);return a(s.decrypt.length,h),s.decrypt(p,h)}}}return Object.assign(t,r),t};function Ag(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error('"output" expected Uint8Array of length '+r+", got: "+e.length);if(t&&!HB(e))throw new Error("invalid output, must be aligned");return e}function wA(r,e,t){zh(t);let n=new Uint8Array(16),o=jB(n);return o.setBigUint64(0,BigInt(e),t),o.setBigUint64(8,BigInt(r),t),n}function HB(r){return r.byteOffset%4===0}function ga(r){return Uint8Array.from(r)}var vA=r=>Uint8Array.from(r.split(""),e=>e.charCodeAt(0)),VB=vA("expand 16-byte k"),$B=vA("expand 32-byte k"),FB=Un(VB),WB=Un($B);function Q(r,e){return r<<e|r>>>32-e}function Sg(r){return r.byteOffset%4===0}var Zh=64,qB=16,AA=2**32-1,xA=Uint32Array.of();function GB(r,e,t,n,o,i,s,a){let c=o.length,f=new Uint8Array(Zh),p=Un(f),h=Sg(o)&&Sg(i),y=h?Un(o):xA,b=h?Un(i):xA;for(let g=0;g<c;s++){if(r(e,t,n,p,s,a),s>=AA)throw new Error("arx: counter overflow");let C=Math.min(Zh,c-g);if(h&&C===Zh){let m=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let S=0,N;S<qB;S++)N=m+S,b[N]=y[N]^p[S];g+=Zh;continue}for(let m=0,S;m<C;m++)S=g+m,i[S]=o[S]^f[m];g+=C}}function Eg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=gA({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Xh(o),Xh(s),zh(i),zh(t),(a,c,f,p,h=0)=>{lt(a,void 0,"key"),lt(c,void 0,"nonce"),lt(f,void 0,"data");let y=f.length;if(p===void 0&&(p=new Uint8Array(y)),lt(p,void 0,"output"),Xh(h),h<0||h>=AA)throw new Error("arx: counter overflow");if(p.length<y)throw new Error(`arx: output (${p.length}) is shorter than data (${y})`);let b=[],g=a.length,C,m;if(g===32)b.push(C=ga(a)),m=WB;else if(g===16&&t)C=new Uint8Array(32),C.set(a),C.set(a,16),m=FB,b.push(C);else throw lt(a,32,"arx key"),new Error("invalid key size");Sg(c)||b.push(c=ga(c));let S=Un(C);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(m,S,Un(c.subarray(0,16)),S),c=c.subarray(16)}let N=16-o;if(N!==c.length)throw new Error(`arx: nonce must be ${N} or 16 bytes`);if(N!==12){let K=new Uint8Array(12);K.set(c,i?0:12-c.length),c=K,b.push(c)}let I=Un(c);return GB(r,m,S,I,f,p,h,s),Mn(...b),p}}function xt(r,e){return r[e++]&255|(r[e++]&255)<<8}var _g=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;constructor(e){e=ga(lt(e,32,"key"));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),f=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|f<<8)&8191,this.r[9]=f>>>5&127;for(let p=0;p<8;p++)this.pad[p]=xt(e,16+2*p)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],f=s[2],p=s[3],h=s[4],y=s[5],b=s[6],g=s[7],C=s[8],m=s[9],S=xt(e,t+0),N=xt(e,t+2),I=xt(e,t+4),K=xt(e,t+6),Z=xt(e,t+8),q=xt(e,t+10),re=xt(e,t+12),R=xt(e,t+14),k=i[0]+(S&8191),G=i[1]+((S>>>13|N<<3)&8191),Y=i[2]+((N>>>10|I<<6)&8191),V=i[3]+((I>>>7|K<<9)&8191),B=i[4]+((K>>>4|Z<<12)&8191),A=i[5]+(Z>>>1&8191),v=i[6]+((Z>>>14|q<<2)&8191),D=i[7]+((q>>>11|re<<5)&8191),U=i[8]+((re>>>8|R<<8)&8191),L=i[9]+(R>>>5|o),T=0,M=T+k*a+G*(5*m)+Y*(5*C)+V*(5*g)+B*(5*b);T=M>>>13,M&=8191,M+=A*(5*y)+v*(5*h)+D*(5*p)+U*(5*f)+L*(5*c),T+=M>>>13,M&=8191;let W=T+k*c+G*a+Y*(5*m)+V*(5*C)+B*(5*g);T=W>>>13,W&=8191,W+=A*(5*b)+v*(5*y)+D*(5*h)+U*(5*p)+L*(5*f),T+=W>>>13,W&=8191;let O=T+k*f+G*c+Y*a+V*(5*m)+B*(5*C);T=O>>>13,O&=8191,O+=A*(5*g)+v*(5*b)+D*(5*y)+U*(5*h)+L*(5*p),T+=O>>>13,O&=8191;let pe=T+k*p+G*f+Y*c+V*a+B*(5*m);T=pe>>>13,pe&=8191,pe+=A*(5*C)+v*(5*g)+D*(5*b)+U*(5*y)+L*(5*h),T+=pe>>>13,pe&=8191;let be=T+k*h+G*p+Y*f+V*c+B*a;T=be>>>13,be&=8191,be+=A*(5*m)+v*(5*C)+D*(5*g)+U*(5*b)+L*(5*y),T+=be>>>13,be&=8191;let ee=T+k*y+G*h+Y*p+V*f+B*c;T=ee>>>13,ee&=8191,ee+=A*a+v*(5*m)+D*(5*C)+U*(5*g)+L*(5*b),T+=ee>>>13,ee&=8191;let Ae=T+k*b+G*y+Y*h+V*p+B*f;T=Ae>>>13,Ae&=8191,Ae+=A*c+v*a+D*(5*m)+U*(5*C)+L*(5*g),T+=Ae>>>13,Ae&=8191;let Be=T+k*g+G*b+Y*y+V*h+B*p;T=Be>>>13,Be&=8191,Be+=A*f+v*c+D*a+U*(5*m)+L*(5*C),T+=Be>>>13,Be&=8191;let Ke=T+k*C+G*g+Y*b+V*y+B*h;T=Ke>>>13,Ke&=8191,Ke+=A*p+v*f+D*c+U*a+L*(5*m),T+=Ke>>>13,Ke&=8191;let Ee=T+k*m+G*C+Y*g+V*b+B*y;T=Ee>>>13,Ee&=8191,Ee+=A*h+v*p+D*f+U*c+L*a,T+=Ee>>>13,Ee&=8191,T=(T<<2)+T|0,T=T+M|0,M=T&8191,T=T>>>13,W+=T,i[0]=M,i[1]=W,i[2]=O,i[3]=pe,i[4]=be,i[5]=ee,i[6]=Ae,i[7]=Be,i[8]=Ke,i[9]=Ee}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;Mn(n)}update(e){xg(this),lt(e),e=ga(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(){Mn(this.h,this.r,this.buffer,this.pad)}digestInto(e){xg(this),yA(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 zB(r){let e=(n,o)=>r(o).update(n).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var SA=zB(r=>new _g(r));function CA(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],f=r[3],p=e[0],h=e[1],y=e[2],b=e[3],g=e[4],C=e[5],m=e[6],S=e[7],N=o,I=t[0],K=t[1],Z=t[2],q=s,re=a,R=c,k=f,G=p,Y=h,V=y,B=b,A=g,v=C,D=m,U=S,L=N,T=I,M=K,W=Z;for(let pe=0;pe<i;pe+=2)q=q+G|0,L=Q(L^q,16),A=A+L|0,G=Q(G^A,12),q=q+G|0,L=Q(L^q,8),A=A+L|0,G=Q(G^A,7),re=re+Y|0,T=Q(T^re,16),v=v+T|0,Y=Q(Y^v,12),re=re+Y|0,T=Q(T^re,8),v=v+T|0,Y=Q(Y^v,7),R=R+V|0,M=Q(M^R,16),D=D+M|0,V=Q(V^D,12),R=R+V|0,M=Q(M^R,8),D=D+M|0,V=Q(V^D,7),k=k+B|0,W=Q(W^k,16),U=U+W|0,B=Q(B^U,12),k=k+B|0,W=Q(W^k,8),U=U+W|0,B=Q(B^U,7),q=q+Y|0,W=Q(W^q,16),D=D+W|0,Y=Q(Y^D,12),q=q+Y|0,W=Q(W^q,8),D=D+W|0,Y=Q(Y^D,7),re=re+V|0,L=Q(L^re,16),U=U+L|0,V=Q(V^U,12),re=re+V|0,L=Q(L^re,8),U=U+L|0,V=Q(V^U,7),R=R+B|0,T=Q(T^R,16),A=A+T|0,B=Q(B^A,12),R=R+B|0,T=Q(T^R,8),A=A+T|0,B=Q(B^A,7),k=k+G|0,M=Q(M^k,16),v=v+M|0,G=Q(G^v,12),k=k+G|0,M=Q(M^k,8),v=v+M|0,G=Q(G^v,7);let O=0;n[O++]=s+q|0,n[O++]=a+re|0,n[O++]=c+R|0,n[O++]=f+k|0,n[O++]=p+G|0,n[O++]=h+Y|0,n[O++]=y+V|0,n[O++]=b+B|0,n[O++]=g+A|0,n[O++]=C+v|0,n[O++]=m+D|0,n[O++]=S+U|0,n[O++]=N+L|0,n[O++]=I+T|0,n[O++]=K+M|0,n[O++]=Z+W|0}function XB(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],f=e[1],p=e[2],h=e[3],y=e[4],b=e[5],g=e[6],C=e[7],m=t[0],S=t[1],N=t[2],I=t[3];for(let Z=0;Z<20;Z+=2)o=o+c|0,m=Q(m^o,16),y=y+m|0,c=Q(c^y,12),o=o+c|0,m=Q(m^o,8),y=y+m|0,c=Q(c^y,7),i=i+f|0,S=Q(S^i,16),b=b+S|0,f=Q(f^b,12),i=i+f|0,S=Q(S^i,8),b=b+S|0,f=Q(f^b,7),s=s+p|0,N=Q(N^s,16),g=g+N|0,p=Q(p^g,12),s=s+p|0,N=Q(N^s,8),g=g+N|0,p=Q(p^g,7),a=a+h|0,I=Q(I^a,16),C=C+I|0,h=Q(h^C,12),a=a+h|0,I=Q(I^a,8),C=C+I|0,h=Q(h^C,7),o=o+f|0,I=Q(I^o,16),g=g+I|0,f=Q(f^g,12),o=o+f|0,I=Q(I^o,8),g=g+I|0,f=Q(f^g,7),i=i+p|0,m=Q(m^i,16),C=C+m|0,p=Q(p^C,12),i=i+p|0,m=Q(m^i,8),C=C+m|0,p=Q(p^C,7),s=s+h|0,S=Q(S^s,16),y=y+S|0,h=Q(h^y,12),s=s+h|0,S=Q(S^s,8),y=y+S|0,h=Q(h^y,7),a=a+c|0,N=Q(N^a,16),b=b+N|0,c=Q(c^b,12),a=a+c|0,N=Q(N^a,8),b=b+N|0,c=Q(c^b,7);let K=0;n[K++]=o,n[K++]=i,n[K++]=s,n[K++]=a,n[K++]=m,n[K++]=S,n[K++]=N,n[K++]=I}var ZB=Eg(CA,{counterRight:!1,counterLength:4,allowShortKeys:!1}),YB=Eg(CA,{counterRight:!1,counterLength:8,extendNonceFn:XB,allowShortKeys:!1});var JB=new Uint8Array(16),EA=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(JB.subarray(t))},QB=new Uint8Array(32);function _A(r,e,t,n,o){o!==void 0&<(o,void 0,"AAD");let i=r(e,t,QB),s=wA(n.length,o?o.length:0,!0),a=SA.create(i);o&&EA(a,o),EA(a,n),a.update(s);let c=a.digest();return Mn(i,s),c}var BA=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Ag(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let f=_A(r,e,t,c,n);return s.set(f,a),Mn(f),s},decrypt(i,s){s=Ag(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),f=_A(r,e,t,a,n);if(!bA(c,f))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Mn(f),s}}),Cg=vg({blockSize:64,nonceLength:12,tagLength:16},BA(ZB)),Uz=vg({blockSize:64,nonceLength:24,tagLength:16},BA(YB));function TA(r,e,t){return Ro(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ms(r,t,e)}var Bg=Uint8Array.of(0),IA=Uint8Array.of();function kA(r,e,t,n=32){Ro(r),rr(n,"length");let o=r.outputLen;if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0?t=IA:fe(t,void 0,"info");let s=new Uint8Array(i*o),a=ms.create(r,e),c=a._cloneInto(),f=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Bg[0]=p+1,c.update(p===0?IA:f).update(t).update(Bg).digestInto(f),s.set(f,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),br(f,Bg),s.slice(0,n)}var Ig={hashSHA256(r){return Ur(r.subarray())},getHKDF(r,e){let t=TA(Ur,e,r),o=kA(Ur,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=$a.utils.randomSecretKey();return{publicKey:$a.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:$a.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return $a.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Cg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Cg(n,e,t).decrypt(r.subarray(),o)}};var OA=Ig;function PA(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 ba=r=>{let e=ot(2);return e[0]=r>>8,e[1]=r,e};ba.bytes=2;var wa=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)};wa.bytes=2;function NA(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 Tg(r,e){!e.enabled||!ya||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local static keys."))}function kg(r,e){!e.enabled||!ya||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function DA(r,e){!e.enabled||!ya||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function Og(r,e){!e.enabled||!ya||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Pg(r,e,t){!t.enabled||!ya||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ue(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ue(e.k,"hex")}`))}var xa=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var eI=0,tI=4294967295,rI="Cipherstate has reached maximum n, a new handshake must be performed",Yh=class{n;bytes;view;constructor(e=eI){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>tI)throw new Error(rI)}};var qi=nt(0),va=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Yh(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}},Ng=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=nI(e,n),this.ck=this.h,this.cs=new va(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new va(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new me(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 va(this.crypto,e),new va(this.crypto,t)]}},Dg=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:f}=e;this.crypto=t,this.ss=new Ng(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=f}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()}},Xu=class extends Dg{writeMessageA(e){return new me(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new me(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new me(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new xa(`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 xa(`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 xa(`handshake stage 2 validation fail: ${t.message}`)}}};function nI(r,e){if(e.length<=32){let t=nt(32);return t.set(e),t}else return r.hash(e)}var Jh;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((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 Ya('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 Ya('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=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Jh||(Jh={}));var Zu;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((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),Jh.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=Jh.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Zu||(Zu={}));async function Lg(r,e,t){let n=await r.sign(LA(e));return Zu.encode({identityKey:$n(r.publicKey),identitySig:n,extensions:t})}async function Ug(r,e,t){try{let n=Zu.decode(r),o=tc(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=LA(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new el(n.message)}}function LA(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?It([e,r],e.length+r.length):(r.prepend(e),r)}var Rg=class extends Qn{stream;handshake;metrics;decoder;constructor(e,t,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=t,this.metrics=n,this.decoder=new af({lengthDecoder:wa,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};this.stream.addEventListener("message",o);let i=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",i);let s=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",s);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65519){let o=n+65519;o>e.byteLength&&(o=e.byteLength);let i;e instanceof Uint8Array?i=this.handshake.encrypt(e.subarray(n,o)):i=this.handshake.encrypt(e.sublist(n,o)),this.metrics?.encryptedPackets.increment(),t.append(ba(i.byteLength)),t.append(i)}return t}decrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65535){let o=n+65535;if(o>e.byteLength&&(o=e.byteLength),o-wg<n)throw new Error("Invalid chunk");let i;e instanceof Uint8Array?i=e.subarray(n,o):i=e.sublist(n,o);let s=e.subarray(n,o-wg);try{let a=this.handshake.decrypt(i,s);this.metrics?.decryptedPackets.increment(),t.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return t}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Mg(r,e,t){return new Rg(r,e,t)}async function UA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,p=await Lg(i,a.publicKey,f),h=new Xu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Tg(h.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(qi),e),t.trace("Stage 0 - Initiator finished sending first message."),kg(h.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let y=h.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Og(h.re,t),DA(h.rs,t),t.trace("Initiator going to check remote's signature...");let b=await Ug(y,h.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,C]=h.ss.split();return Pg(g,C,t),{payload:b,encrypt:m=>g.encryptWithAd(qi,m),decrypt:(m,S)=>C.decryptWithAd(qi,m,S)}}async function MA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,p=await Lg(i,a.publicKey,f),h=new Xu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Tg(h.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),Og(h.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),kg(h.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let y=h.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let b=await Ug(y,h.rs,c),[g,C]=h.ss.split();return Pg(g,C,t),{payload:b,encrypt:m=>C.encryptWithAd(qi,m),decrypt:(m,S)=>g.decryptWithAd(qi,m,S)}}var Qh=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=i??OA;this.crypto=PA(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?NA(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??nt(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Yi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=e.log?.newScope("noise")??this.log,o=of(e,{lengthEncoder:ba,lengthDecoder:wa,maxDataLength:65535}),i=await this.performHandshakeInitiator(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=tc(i.payload.identityKey);return{connection:Mg(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Dd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.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 tl("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=e.log?.newScope("noise")??this.log,o=of(e,{lengthEncoder:ba,lengthDecoder:wa,maxDataLength:65535}),i=await this.performHandshakeResponder(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=tc(i.payload.identityKey);return{connection:Mg(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Dd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await UA({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}async performHandshakeResponder(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await MA({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}};function jA(r={}){return e=>new Qh(e,r)}var jg=Object.values(Po).map(r=>r.decoder).reduce((r,e)=>r.or(e)),oI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function KA(r){return r?.match(oI)?.groups?.fingerprint}function Kg(r){let t=r.getComponents().find(n=>n.code===466)?.value;if(t===void 0||t==="")throw new xe(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function iI(r){return mr.decode(jg.decode(r))}function sI(r){let e=iI(Kg(r)),t=aI(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new yf(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function HA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Bt(tr.code,t);return As(`/certhash/${Oo.encode(n.bytes)}`)}function aI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new bf(r)}}function VA(r,e){let{host:t,port:n,type:o}=hm(r);if(o!=="ip4"&&o!=="ip6")throw new xe(`Multiaddr ${r} was not an IPv4 or IPv6 address`);let i=sI(r);return{type:"answer",sdp:`v=0
|
12
|
+
`)}};Dt.CertificateTag="CERTIFICATE";Dt.CrlTag="CRL";Dt.CertificateRequestTag="CERTIFICATE REQUEST";Dt.PublicKeyTag="PUBLIC KEY";Dt.PrivateKeyTag="PRIVATE KEY";var Io=class r extends Bo{static isAsnEncoded(e){return H.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Dt.isPem(e))return Dt.decode(e)[0];if(H.Convert.isHex(e))return H.Convert.FromHex(e);if(H.Convert.isBase64(e))return H.Convert.FromBase64(e);if(H.Convert.isBase64Url(e))return H.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=H.BufferSourceConverter.toUint8Array(e);if(t.length>0&&t[0]===48)return H.BufferSourceConverter.toArrayBuffer(e);let n=H.Convert.ToBinary(e);if(Dt.isPem(n))return Dt.decode(n)[0];if(H.Convert.isHex(n))return H.Convert.FromHex(n);if(H.Convert.isBase64(n))return H.Convert.FromBase64(n);if(H.Convert.isBase64Url(n))return H.Convert.FromBase64Url(n);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Dt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Pn=class r extends Io{static async create(e,t=ut.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(H.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Io.isAsnEncoded(e)?super(e,mt):super(e),this.tag=Dt.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]||ut.get()):t=e[0]||ut.get();let i=this.rawData,s=F.parse(this.rawData,mt);return s.algorithm.algorithm===wo&&(i=vB(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=De.resolve(Wi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Yr:{let o=F.parse(e.subjectPublicKey,ra),i=H.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=H.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]||ut.get()):n=e[0]||ut.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=ut.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=ut.get();let o=F.parse(this.rawData,mt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,mt);switch(e.Algorithm=Nn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Ni:e["EC Point"]=t.subjectPublicKey;break;case Yr:default:e["Raw Data"]=t.subjectPublicKey}return e}};function vB(r,e){return r.algorithm=new j({algorithm:Yr,parameters:null}),e=F.serialize(r),e}var Rh=class r extends Qt{static async create(e,t=!1,n=ut.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new qr({keyIdentifier:new yi(H.Convert.FromHex(e[0]))});super(Wf,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Dn?F.parse(t.name.rawData,je):t.name,o=new qr({authorityCertIssuer:n,authorityCertSerialNumber:H.Convert.FromHex(t.serialNumber)});super(Wf,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,qr);t.keyIdentifier&&(this.keyId=H.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?H.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,qr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Dn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Rh.NAME="Authority Key Identifier";var ha=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,gi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new gi({cA:e[0],pathLenConstraint:e[1]});super(qf,e[2],F.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};ha.NAME="Basic Constraints";var sA;(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"})(sA||(sA={}));var Lh=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Vc);this.usages=t.map(n=>n)}else{let t=new Vc(e[0]);super(Zf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>tn.toString(t)).join(", "),e}};Lh.NAME="Extended Key Usages";var aA;(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"})(aA||(aA={}));var Uh=class extends Qt{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Ds);this.usages=t.toNumber()}else{let t=new Ds(e[0]);super(Yf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Ds);return e[""]=t.toJSON().join(", "),e}};Uh.NAME="Key Usages";var Mh=class r extends Qt{static async create(e,t=!1,n=ut.get()){let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Ht);this.keyId=H.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?H.Convert.FromHex(e[0]):e[0],n=new Ht(t);super(sy,e[1],F.serialize(n)),this.keyId=H.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Ht);return e[""]=t,e}};Mh.NAME="Subject Key Identifier";var jh=class extends Qt{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(oy,e[1],new Dn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,th);this.names=new Dn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};jh.NAME="Subject Alternative Name";var Rt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new Qt(e),n=this.items.get(t.type);return n?new n(e):t}};Rt.items=new Map;var Kh=class extends Qt{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,Uc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Uc(n.map(s=>new bi({policyIdentifier:s})));super(zf,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new _e("",{},tn.toString(t))),e}};Kh.NAME="Certificate Policies";Rt.register(zf,Kh);var Hh=class extends Qt{constructor(...e){var t;if(H.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 Gr({distributionPoint:new Cn({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new fo(o);super(Xf,e[1],F.serialize(i))}else{let n=new fo(e[0]);super(Xf,e[1],F.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,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 en(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Hh.NAME="CRL Distribution Points";var Vh=class extends Qt{constructor(...e){var t,n,o,i;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof mi){let s=new mi(e[0]);super(Ff,e[1],F.serialize(s))}else{let s=e[0],a=new mi;Oh(a,s,Hm,"ocsp"),Oh(a,s,Vm,"caIssuers"),Oh(a,s,$m,"timeStamping"),Oh(a,s,Fm,"caRepository"),super(Ff,e[1],F.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],F.parse(e.extnValue,mi).forEach(n=>{switch(n.accessMethod){case Hm:this.ocsp.push(new en(n.accessLocation));break;case Vm:this.caIssuers.push(new en(n.accessLocation));break;case $m:this.timeStamping.push(new en(n.accessLocation));break;case Fm:this.caRepository.push(new en(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&kh(e,"OCSP",this.ocsp),this.caIssuers.length&&kh(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&kh(e,"Time Stamping",this.timeStamping),this.caRepository.length&&kh(e,"CA Repository",this.caRepository),e}};Vh.NAME="Authority Info Access";function kh(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 Oh(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new en("url",s)),r.push(new En({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var $h=class extends Qt{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(ey,e[1],new Dn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,je);this.names=new Dn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};$h.NAME="Issuer Alternative Name";var pa=class r extends Bo{constructor(...e){let t;if(H.BufferSourceConverter.isBufferSource(e[0]))t=H.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>H.BufferSourceConverter.toArrayBuffer(i)):[];t=F.serialize(new dt({type:n,values:o}))}super(t,dt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new _e("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[_e.NAME]===r.NAME&&(e[_e.NAME]=tn.toString(this.type)),e}};pa.NAME="Attribute";var Fh=class extends pa{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new bu({printableString:e[0]});super(tg,[F.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],bu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[_e.VALUE]=this.password,e}};Fh.NAME="Challenge Password";var Wu=class extends pa{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new Yt;for(let i of n)o.push(F.parse(i.rawData,yt));super(xu,[F.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],Yt);this.items=t.map(n=>Rt.create(F.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}};Wu.NAME="Extensions";var da=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new pa(e),n=this.items.get(t.type);return n?new n(e):t}};da.items=new Map;var Gu="crypto.signatureFormatter",dg=class{toAsnSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}},Nh,mg=Nh=class{static createPssParams(e,t){let n=Nh.getHashAlgorithm(e);return n?new Jr({hashAlgorithm:n,maskGenAlgorithm:new j({algorithm:xo,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=De.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 j({algorithm:Ys,parameters:null});case"sha-256":return new j({algorithm:ph,parameters:null});case"sha-384":return new j({algorithm:Js,parameters:null});case"sha-512":return new j({algorithm:Qs,parameters:null})}}else return new j({algorithm:Yr,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=Nh.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new j({algorithm:wo,parameters:F.serialize(t)})}else return new j({algorithm:wo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Yr:return{name:"RSASSA-PKCS1-v1_5"};case Ys:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case ph:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Js:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Qs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case wo:if(e.parameters){let t=F.parse(e.parameters,Jr);return{name:"RSA-PSS",hash:De.resolve(Wi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};mg=Nh=u([Ao()],mg);De.registerSingleton(qu,mg);var yg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new j({algorithm:Ri});case"sha-256":return new j({algorithm:Li});case"sha-384":return new j({algorithm:Ui});case"sha-512":return new j({algorithm:Mi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ri:return{name:"SHA-1"};case Li:return{name:"SHA-256"};case Ui:return{name:"SHA-384"};case Mi:return{name:"SHA-512"}}return null}};yg=u([Ao()],yg);De.registerSingleton(qu,yg);var Rn=class r{addPadding(e,t){let n=H.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o.buffer}removePadding(e,t=!1){let n=H.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=H.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),F.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=F.parse(t,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,H.combine)(s,a)}return null}};Rn.namedCurveSize=new Map;Rn.defaultNamedCurveSize=32;var lg="1.3.101.110",cA="1.3.101.111",fg="1.3.101.112",uA="1.3.101.113",gg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=fg;break;case"x25519":t=lg;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=fg;break;case"ed448":t=uA;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=lg;break;case"x448":t=cA;break}}return t?new j({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case fg:return{name:"Ed25519"};case uA:return{name:"EdDSA",namedCurve:"Ed448"};case lg:return{name:"X25519"};case cA:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};gg=u([Ao()],gg);De.registerSingleton(qu,gg);var Su,Eu,_u,Cu,Bu,Iu,Tu,ua,bg=class extends Io{get subjectName(){return he(this,Eu,"f")||Me(this,Eu,new Dr(this.asn.certificationRequestInfo.subject),"f"),he(this,Eu,"f")}get subject(){return he(this,_u,"f")||Me(this,_u,this.subjectName.toString(),"f"),he(this,_u,"f")}get signatureAlgorithm(){if(!he(this,Cu,"f")){let e=De.resolve(Wi);Me(this,Cu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,Cu,"f")}get signature(){return he(this,Bu,"f")||Me(this,Bu,this.asn.signature,"f"),he(this,Bu,"f")}get publicKey(){return he(this,Iu,"f")||Me(this,Iu,new Pn(this.asn.certificationRequestInfo.subjectPKInfo),"f"),he(this,Iu,"f")}get attributes(){return he(this,Tu,"f")||Me(this,Tu,this.asn.certificationRequestInfo.attributes.map(e=>da.create(F.serialize(e))),"f"),he(this,Tu,"f")}get extensions(){if(!he(this,ua,"f")){Me(this,ua,[],"f");let e=this.getAttribute(xu);e instanceof Wu&&Me(this,ua,e.items,"f")}return he(this,ua,"f")}get tbs(){return he(this,Su,"f")||Me(this,Su,this.asn.certificationRequestInfoRaw||F.serialize(this.asn.certificationRequestInfo),"f"),he(this,Su,"f")}constructor(e){let t=Io.isAsnEncoded(e)?[e,Co]:[e];super(t[0],t[1]),Su.set(this,void 0),Eu.set(this,void 0),_u.set(this,void 0),Cu.set(this,void 0),Bu.set(this,void 0),Iu.set(this,void 0),Tu.set(this,void 0),ua.set(this,void 0),this.tag=Dt.CertificateRequestTag}onInit(e){}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=ut.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=De.resolveAll(Gu).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,Co),n=t.certificationRequestInfo,o=new _e("",{Version:`${zr[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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Su=new WeakMap,Eu=new WeakMap,_u=new WeakMap,Cu=new WeakMap,Bu=new WeakMap,Iu=new WeakMap,Tu=new WeakMap,ua=new WeakMap;bg.NAME="PKCS#10 Certificate Request";var ku,Ou,Pu,Nu,Du,Ru,Lu,Uu,Mu,ju,la,Ku,ma=class extends Io{get publicKey(){return he(this,Ku,"f")||Me(this,Ku,new Pn(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),he(this,Ku,"f")}get serialNumber(){if(!he(this,Ou,"f")){let e=this.asn.tbsCertificate,t=new Uint8Array(e.serialNumber);t.length>1&&t[0]===0&&t[1]>127&&(t=t.slice(1)),Me(this,Ou,H.Convert.ToHex(t),"f")}return he(this,Ou,"f")}get subjectName(){return he(this,Pu,"f")||Me(this,Pu,new Dr(this.asn.tbsCertificate.subject),"f"),he(this,Pu,"f")}get subject(){return he(this,Nu,"f")||Me(this,Nu,this.subjectName.toString(),"f"),he(this,Nu,"f")}get issuerName(){return he(this,Du,"f")||Me(this,Du,new Dr(this.asn.tbsCertificate.issuer),"f"),he(this,Du,"f")}get issuer(){return he(this,Ru,"f")||Me(this,Ru,this.issuerName.toString(),"f"),he(this,Ru,"f")}get notBefore(){if(!he(this,Lu,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Me(this,Lu,e,"f")}return he(this,Lu,"f")}get notAfter(){if(!he(this,Uu,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Me(this,Uu,e,"f")}return he(this,Uu,"f")}get signatureAlgorithm(){if(!he(this,Mu,"f")){let e=De.resolve(Wi);Me(this,Mu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,Mu,"f")}get signature(){return he(this,ju,"f")||Me(this,ju,this.asn.signatureValue,"f"),he(this,ju,"f")}get extensions(){return he(this,la,"f")||(Me(this,la,[],"f"),this.asn.tbsCertificate.extensions&&Me(this,la,this.asn.tbsCertificate.extensions.map(e=>Rt.create(F.serialize(e))),"f")),he(this,la,"f")}get tbs(){return he(this,ku,"f")||Me(this,ku,this.asn.tbsCertificateRaw||F.serialize(this.asn.tbsCertificate),"f"),he(this,ku,"f")}constructor(e){let t=Io.isAsnEncoded(e)?[e,cr]:[e];super(t[0],t[1]),ku.set(this,void 0),Ou.set(this,void 0),Pu.set(this,void 0),Nu.set(this,void 0),Du.set(this,void 0),Ru.set(this,void 0),Lu.set(this,void 0),Uu.set(this,void 0),Mu.set(this,void 0),ju.set(this,void 0),la.set(this,void 0),Ku.set(this,void 0),this.tag=Dt.CertificateTag}onInit(e){}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=ut.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 Pn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(H.BufferSourceConverter.isBufferSource(i)){let f=new Pn(i);n={...f.algorithm,...this.signatureAlgorithm},o=await f.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=De.resolveAll(Gu).reverse(),a=null;for(let f of s)if(a=f.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let p=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<p&&p<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=ut.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=ut.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,cr),n=t.tbsCertificate,o=new _e("",{Version:`${zr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Nn.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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ku=new WeakMap,Ou=new WeakMap,Pu=new WeakMap,Nu=new WeakMap,Du=new WeakMap,Ru=new WeakMap,Lu=new WeakMap,Uu=new WeakMap,Mu=new WeakMap,ju=new WeakMap,la=new WeakMap,Ku=new WeakMap;ma.NAME="Certificate";function AB(r,e=ut.get()){let t=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(r||"")),n=t&&t.length&&t.some(i=>i>0)?new Uint8Array(t):void 0;n||(n=e.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n.buffer}var Wh=class{static async createSelfSigned(e,t=ut.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=ut.get()){var n;let o;e.publicKey instanceof Pn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:H.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=AB(e.serialNumber),s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new cr({tbsCertificate:new gt({version:zr.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new Yt(((n=e.extensions)===null||n===void 0?void 0:n.map(m=>F.parse(m.rawData,yt)))||[]),subjectPublicKeyInfo:F.parse(o,mt)})});if(e.subject){let m=e.subject instanceof Dr?e.subject:new Dr(e.subject);c.tbsCertificate.subject=F.parse(m.toArrayBuffer(),Oe)}if(e.issuer){let m=e.issuer instanceof Dr?e.issuer:new Dr(e.issuer);c.tbsCertificate.issuer=F.parse(m.toArrayBuffer(),Oe)}let f={hash:"SHA-256"},p="signingKey"in e?{...f,...e.signingAlgorithm,...e.signingKey.algorithm}:{...f,...e.signingAlgorithm},h=De.resolve(Wi);c.tbsCertificate.signature=c.signatureAlgorithm=h.toAsnAlgorithm(p);let y=F.serialize(c.tbsCertificate),b="signingKey"in e?await t.subtle.sign(p,e.signingKey,y):e.signature,g=De.resolveAll(Gu).reverse(),C=null;for(let m of g)if(C=m.toAsnSignature(p,b),C)break;if(!C)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=C,new ma(F.serialize(c))}},SB,EB,_B,CB,BB,lA;(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"})(lA||(lA={}));SB=new WeakMap,EB=new WeakMap,_B=new WeakMap,CB=new WeakMap,BB=new WeakMap;var IB,TB,kB,OB,PB,NB,DB;IB=new WeakMap,TB=new WeakMap,kB=new WeakMap,OB=new WeakMap,PB=new WeakMap,NB=new WeakMap,DB=new WeakMap;Rt.register(qf,ha);Rt.register(Zf,Lh);Rt.register(Yf,Uh);Rt.register(sy,Mh);Rt.register(Wf,Rh);Rt.register(oy,jh);Rt.register(Xf,Hh);Rt.register(Ff,Vh);Rt.register(ey,$h);da.register(tg,Fh);da.register(xu,Wu);De.registerSingleton(Gu,dg);De.registerSingleton(Gu,Rn);Rn.namedCurveSize.set("P-256",32);Rn.namedCurveSize.set("K-256",32);Rn.namedCurveSize.set("P-384",48);Rn.namedCurveSize.set("P-521",66);var Ln="/",mA=new TextEncoder().encode(Ln),qh=mA[0],zu=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=de(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==qh)throw new Error("Invalid key")}toString(e="utf8"){return ue(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Ln))}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=mA),this._buf[0]!==qh){let e=new Uint8Array(this._buf.byteLength+1);e.fill(qh,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===qh;)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(Ln).slice(1)}type(){return RB(this.baseNamespace())}name(){return LB(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Ln)||(e+=Ln),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Ln):new r(e.slice(0,-1).join(Ln))}child(e){return this.toString()===Ln?e:e.toString()===Ln?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(),...UB(e.map(t=>t.namespaces()))])}};function RB(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function LB(r){let e=r.split(":");return e[e.length-1]}function UB(r){return[].concat(...r)}var Gh=class extends er{async listen(){throw new gf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var ya=!!globalThis.process?.env?.DUMP_SESSION_KEYS,wg=16;function MB(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function zh(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Xh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function lt(r,e,t=""){let n=MB(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function xg(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 yA(r,e){lt(r,void 0,"output");let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Un(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Mn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function jB(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var KB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function gA(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function bA(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 vg=(r,e)=>{function t(n,...o){if(lt(n,void 0,"key"),!KB)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let p=o[0];lt(p,r.varSizeNonce?void 0:r.nonceLength,"nonce")}let i=r.tagLength;i&&o[1]!==void 0&<(o[1],void 0,"AAD");let s=e(n,...o),a=(p,h)=>{if(h!==void 0){if(p!==2)throw new Error("cipher output not supported");lt(h,void 0,"output")}},c=!1;return{encrypt(p,h){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,lt(p),a(s.encrypt.length,h),s.encrypt(p,h)},decrypt(p,h){if(lt(p),i&&p.length<i)throw new Error('"ciphertext" expected length bigger than tagLength='+i);return a(s.decrypt.length,h),s.decrypt(p,h)}}}return Object.assign(t,r),t};function Ag(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error('"output" expected Uint8Array of length '+r+", got: "+e.length);if(t&&!HB(e))throw new Error("invalid output, must be aligned");return e}function wA(r,e,t){zh(t);let n=new Uint8Array(16),o=jB(n);return o.setBigUint64(0,BigInt(e),t),o.setBigUint64(8,BigInt(r),t),n}function HB(r){return r.byteOffset%4===0}function ga(r){return Uint8Array.from(r)}var vA=r=>Uint8Array.from(r.split(""),e=>e.charCodeAt(0)),VB=vA("expand 16-byte k"),$B=vA("expand 32-byte k"),FB=Un(VB),WB=Un($B);function Q(r,e){return r<<e|r>>>32-e}function Sg(r){return r.byteOffset%4===0}var Zh=64,qB=16,AA=2**32-1,xA=Uint32Array.of();function GB(r,e,t,n,o,i,s,a){let c=o.length,f=new Uint8Array(Zh),p=Un(f),h=Sg(o)&&Sg(i),y=h?Un(o):xA,b=h?Un(i):xA;for(let g=0;g<c;s++){if(r(e,t,n,p,s,a),s>=AA)throw new Error("arx: counter overflow");let C=Math.min(Zh,c-g);if(h&&C===Zh){let m=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let S=0,N;S<qB;S++)N=m+S,b[N]=y[N]^p[S];g+=Zh;continue}for(let m=0,S;m<C;m++)S=g+m,i[S]=o[S]^f[m];g+=C}}function Eg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=gA({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Xh(o),Xh(s),zh(i),zh(t),(a,c,f,p,h=0)=>{lt(a,void 0,"key"),lt(c,void 0,"nonce"),lt(f,void 0,"data");let y=f.length;if(p===void 0&&(p=new Uint8Array(y)),lt(p,void 0,"output"),Xh(h),h<0||h>=AA)throw new Error("arx: counter overflow");if(p.length<y)throw new Error(`arx: output (${p.length}) is shorter than data (${y})`);let b=[],g=a.length,C,m;if(g===32)b.push(C=ga(a)),m=WB;else if(g===16&&t)C=new Uint8Array(32),C.set(a),C.set(a,16),m=FB,b.push(C);else throw lt(a,32,"arx key"),new Error("invalid key size");Sg(c)||b.push(c=ga(c));let S=Un(C);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(m,S,Un(c.subarray(0,16)),S),c=c.subarray(16)}let N=16-o;if(N!==c.length)throw new Error(`arx: nonce must be ${N} or 16 bytes`);if(N!==12){let K=new Uint8Array(12);K.set(c,i?0:12-c.length),c=K,b.push(c)}let I=Un(c);return GB(r,m,S,I,f,p,h,s),Mn(...b),p}}function xt(r,e){return r[e++]&255|(r[e++]&255)<<8}var _g=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;constructor(e){e=ga(lt(e,32,"key"));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),f=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|f<<8)&8191,this.r[9]=f>>>5&127;for(let p=0;p<8;p++)this.pad[p]=xt(e,16+2*p)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],f=s[2],p=s[3],h=s[4],y=s[5],b=s[6],g=s[7],C=s[8],m=s[9],S=xt(e,t+0),N=xt(e,t+2),I=xt(e,t+4),K=xt(e,t+6),Z=xt(e,t+8),q=xt(e,t+10),re=xt(e,t+12),R=xt(e,t+14),k=i[0]+(S&8191),G=i[1]+((S>>>13|N<<3)&8191),Y=i[2]+((N>>>10|I<<6)&8191),V=i[3]+((I>>>7|K<<9)&8191),B=i[4]+((K>>>4|Z<<12)&8191),A=i[5]+(Z>>>1&8191),v=i[6]+((Z>>>14|q<<2)&8191),D=i[7]+((q>>>11|re<<5)&8191),U=i[8]+((re>>>8|R<<8)&8191),L=i[9]+(R>>>5|o),T=0,M=T+k*a+G*(5*m)+Y*(5*C)+V*(5*g)+B*(5*b);T=M>>>13,M&=8191,M+=A*(5*y)+v*(5*h)+D*(5*p)+U*(5*f)+L*(5*c),T+=M>>>13,M&=8191;let W=T+k*c+G*a+Y*(5*m)+V*(5*C)+B*(5*g);T=W>>>13,W&=8191,W+=A*(5*b)+v*(5*y)+D*(5*h)+U*(5*p)+L*(5*f),T+=W>>>13,W&=8191;let O=T+k*f+G*c+Y*a+V*(5*m)+B*(5*C);T=O>>>13,O&=8191,O+=A*(5*g)+v*(5*b)+D*(5*y)+U*(5*h)+L*(5*p),T+=O>>>13,O&=8191;let pe=T+k*p+G*f+Y*c+V*a+B*(5*m);T=pe>>>13,pe&=8191,pe+=A*(5*C)+v*(5*g)+D*(5*b)+U*(5*y)+L*(5*h),T+=pe>>>13,pe&=8191;let be=T+k*h+G*p+Y*f+V*c+B*a;T=be>>>13,be&=8191,be+=A*(5*m)+v*(5*C)+D*(5*g)+U*(5*b)+L*(5*y),T+=be>>>13,be&=8191;let ee=T+k*y+G*h+Y*p+V*f+B*c;T=ee>>>13,ee&=8191,ee+=A*a+v*(5*m)+D*(5*C)+U*(5*g)+L*(5*b),T+=ee>>>13,ee&=8191;let Ae=T+k*b+G*y+Y*h+V*p+B*f;T=Ae>>>13,Ae&=8191,Ae+=A*c+v*a+D*(5*m)+U*(5*C)+L*(5*g),T+=Ae>>>13,Ae&=8191;let Be=T+k*g+G*b+Y*y+V*h+B*p;T=Be>>>13,Be&=8191,Be+=A*f+v*c+D*a+U*(5*m)+L*(5*C),T+=Be>>>13,Be&=8191;let Ke=T+k*C+G*g+Y*b+V*y+B*h;T=Ke>>>13,Ke&=8191,Ke+=A*p+v*f+D*c+U*a+L*(5*m),T+=Ke>>>13,Ke&=8191;let Ee=T+k*m+G*C+Y*g+V*b+B*y;T=Ee>>>13,Ee&=8191,Ee+=A*h+v*p+D*f+U*c+L*a,T+=Ee>>>13,Ee&=8191,T=(T<<2)+T|0,T=T+M|0,M=T&8191,T=T>>>13,W+=T,i[0]=M,i[1]=W,i[2]=O,i[3]=pe,i[4]=be,i[5]=ee,i[6]=Ae,i[7]=Be,i[8]=Ke,i[9]=Ee}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;Mn(n)}update(e){xg(this),lt(e),e=ga(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(){Mn(this.h,this.r,this.buffer,this.pad)}digestInto(e){xg(this),yA(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 zB(r){let e=(n,o)=>r(o).update(n).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var SA=zB(r=>new _g(r));function CA(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],f=r[3],p=e[0],h=e[1],y=e[2],b=e[3],g=e[4],C=e[5],m=e[6],S=e[7],N=o,I=t[0],K=t[1],Z=t[2],q=s,re=a,R=c,k=f,G=p,Y=h,V=y,B=b,A=g,v=C,D=m,U=S,L=N,T=I,M=K,W=Z;for(let pe=0;pe<i;pe+=2)q=q+G|0,L=Q(L^q,16),A=A+L|0,G=Q(G^A,12),q=q+G|0,L=Q(L^q,8),A=A+L|0,G=Q(G^A,7),re=re+Y|0,T=Q(T^re,16),v=v+T|0,Y=Q(Y^v,12),re=re+Y|0,T=Q(T^re,8),v=v+T|0,Y=Q(Y^v,7),R=R+V|0,M=Q(M^R,16),D=D+M|0,V=Q(V^D,12),R=R+V|0,M=Q(M^R,8),D=D+M|0,V=Q(V^D,7),k=k+B|0,W=Q(W^k,16),U=U+W|0,B=Q(B^U,12),k=k+B|0,W=Q(W^k,8),U=U+W|0,B=Q(B^U,7),q=q+Y|0,W=Q(W^q,16),D=D+W|0,Y=Q(Y^D,12),q=q+Y|0,W=Q(W^q,8),D=D+W|0,Y=Q(Y^D,7),re=re+V|0,L=Q(L^re,16),U=U+L|0,V=Q(V^U,12),re=re+V|0,L=Q(L^re,8),U=U+L|0,V=Q(V^U,7),R=R+B|0,T=Q(T^R,16),A=A+T|0,B=Q(B^A,12),R=R+B|0,T=Q(T^R,8),A=A+T|0,B=Q(B^A,7),k=k+G|0,M=Q(M^k,16),v=v+M|0,G=Q(G^v,12),k=k+G|0,M=Q(M^k,8),v=v+M|0,G=Q(G^v,7);let O=0;n[O++]=s+q|0,n[O++]=a+re|0,n[O++]=c+R|0,n[O++]=f+k|0,n[O++]=p+G|0,n[O++]=h+Y|0,n[O++]=y+V|0,n[O++]=b+B|0,n[O++]=g+A|0,n[O++]=C+v|0,n[O++]=m+D|0,n[O++]=S+U|0,n[O++]=N+L|0,n[O++]=I+T|0,n[O++]=K+M|0,n[O++]=Z+W|0}function XB(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],f=e[1],p=e[2],h=e[3],y=e[4],b=e[5],g=e[6],C=e[7],m=t[0],S=t[1],N=t[2],I=t[3];for(let Z=0;Z<20;Z+=2)o=o+c|0,m=Q(m^o,16),y=y+m|0,c=Q(c^y,12),o=o+c|0,m=Q(m^o,8),y=y+m|0,c=Q(c^y,7),i=i+f|0,S=Q(S^i,16),b=b+S|0,f=Q(f^b,12),i=i+f|0,S=Q(S^i,8),b=b+S|0,f=Q(f^b,7),s=s+p|0,N=Q(N^s,16),g=g+N|0,p=Q(p^g,12),s=s+p|0,N=Q(N^s,8),g=g+N|0,p=Q(p^g,7),a=a+h|0,I=Q(I^a,16),C=C+I|0,h=Q(h^C,12),a=a+h|0,I=Q(I^a,8),C=C+I|0,h=Q(h^C,7),o=o+f|0,I=Q(I^o,16),g=g+I|0,f=Q(f^g,12),o=o+f|0,I=Q(I^o,8),g=g+I|0,f=Q(f^g,7),i=i+p|0,m=Q(m^i,16),C=C+m|0,p=Q(p^C,12),i=i+p|0,m=Q(m^i,8),C=C+m|0,p=Q(p^C,7),s=s+h|0,S=Q(S^s,16),y=y+S|0,h=Q(h^y,12),s=s+h|0,S=Q(S^s,8),y=y+S|0,h=Q(h^y,7),a=a+c|0,N=Q(N^a,16),b=b+N|0,c=Q(c^b,12),a=a+c|0,N=Q(N^a,8),b=b+N|0,c=Q(c^b,7);let K=0;n[K++]=o,n[K++]=i,n[K++]=s,n[K++]=a,n[K++]=m,n[K++]=S,n[K++]=N,n[K++]=I}var ZB=Eg(CA,{counterRight:!1,counterLength:4,allowShortKeys:!1}),YB=Eg(CA,{counterRight:!1,counterLength:8,extendNonceFn:XB,allowShortKeys:!1});var JB=new Uint8Array(16),EA=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(JB.subarray(t))},QB=new Uint8Array(32);function _A(r,e,t,n,o){o!==void 0&<(o,void 0,"AAD");let i=r(e,t,QB),s=wA(n.length,o?o.length:0,!0),a=SA.create(i);o&&EA(a,o),EA(a,n),a.update(s);let c=a.digest();return Mn(i,s),c}var BA=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Ag(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let f=_A(r,e,t,c,n);return s.set(f,a),Mn(f),s},decrypt(i,s){s=Ag(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),f=_A(r,e,t,a,n);if(!bA(c,f))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Mn(f),s}}),Cg=vg({blockSize:64,nonceLength:12,tagLength:16},BA(ZB)),Mz=vg({blockSize:64,nonceLength:24,tagLength:16},BA(YB));function TA(r,e,t){return Ro(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ms(r,t,e)}var Bg=Uint8Array.of(0),IA=Uint8Array.of();function kA(r,e,t,n=32){Ro(r),rr(n,"length");let o=r.outputLen;if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0?t=IA:fe(t,void 0,"info");let s=new Uint8Array(i*o),a=ms.create(r,e),c=a._cloneInto(),f=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Bg[0]=p+1,c.update(p===0?IA:f).update(t).update(Bg).digestInto(f),s.set(f,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),br(f,Bg),s.slice(0,n)}var Ig={hashSHA256(r){return Ur(r.subarray())},getHKDF(r,e){let t=TA(Ur,e,r),o=kA(Ur,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=$a.utils.randomSecretKey();return{publicKey:$a.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:$a.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return $a.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Cg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Cg(n,e,t).decrypt(r.subarray(),o)}};var OA=Ig;function PA(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 ba=r=>{let e=ot(2);return e[0]=r>>8,e[1]=r,e};ba.bytes=2;var wa=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)};wa.bytes=2;function NA(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 Tg(r,e){!e.enabled||!ya||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local static keys."))}function kg(r,e){!e.enabled||!ya||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function DA(r,e){!e.enabled||!ya||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function Og(r,e){!e.enabled||!ya||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Pg(r,e,t){!t.enabled||!ya||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ue(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ue(e.k,"hex")}`))}var xa=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var eI=0,tI=4294967295,rI="Cipherstate has reached maximum n, a new handshake must be performed",Yh=class{n;bytes;view;constructor(e=eI){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>tI)throw new Error(rI)}};var qi=nt(0),va=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Yh(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}},Ng=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=nI(e,n),this.ck=this.h,this.cs=new va(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new va(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new me(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 va(this.crypto,e),new va(this.crypto,t)]}},Dg=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:f}=e;this.crypto=t,this.ss=new Ng(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=f}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()}},Xu=class extends Dg{writeMessageA(e){return new me(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new me(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new me(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new xa(`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 xa(`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 xa(`handshake stage 2 validation fail: ${t.message}`)}}};function nI(r,e){if(e.length<=32){let t=nt(32);return t.set(e),t}else return r.hash(e)}var Jh;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((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 Ya('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 Ya('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=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Jh||(Jh={}));var Zu;(function(r){let e;r.codec=()=>(e==null&&(e=Sr((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),Jh.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=Jh.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ar(t,r.codec()),r.decode=(t,n)=>vr(t,r.codec(),n)})(Zu||(Zu={}));async function Lg(r,e,t){let n=await r.sign(LA(e));return Zu.encode({identityKey:$n(r.publicKey),identitySig:n,extensions:t})}async function Ug(r,e,t){try{let n=Zu.decode(r),o=tc(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=LA(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new el(n.message)}}function LA(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?Tt([e,r],e.length+r.length):(r.prepend(e),r)}var Rg=class extends Qn{stream;handshake;metrics;decoder;constructor(e,t,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=t,this.metrics=n,this.decoder=new af({lengthDecoder:wa,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=c=>{try{for(let f of this.decoder.decode(c.data))this.onData(this.decrypt(f))}catch(f){this.abort(f)}};this.stream.addEventListener("message",o);let i=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",i);let s=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",s);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65519){let o=n+65519;o>e.byteLength&&(o=e.byteLength);let i;e instanceof Uint8Array?i=this.handshake.encrypt(e.subarray(n,o)):i=this.handshake.encrypt(e.sublist(n,o)),this.metrics?.encryptedPackets.increment(),t.append(ba(i.byteLength)),t.append(i)}return t}decrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65535){let o=n+65535;if(o>e.byteLength&&(o=e.byteLength),o-wg<n)throw new Error("Invalid chunk");let i;e instanceof Uint8Array?i=e.subarray(n,o):i=e.sublist(n,o);let s=e.subarray(n,o-wg);try{let a=this.handshake.decrypt(i,s);this.metrics?.decryptedPackets.increment(),t.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return t}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function Mg(r,e,t){return new Rg(r,e,t)}async function UA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,p=await Lg(i,a.publicKey,f),h=new Xu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Tg(h.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(h.writeMessageA(qi),e),t.trace("Stage 0 - Initiator finished sending first message."),kg(h.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let y=h.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Og(h.re,t),DA(h.rs,t),t.trace("Initiator going to check remote's signature...");let b=await Ug(y,h.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(h.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,C]=h.ss.split();return Pg(g,C,t),{payload:b,encrypt:m=>g.encryptWithAd(qi,m),decrypt:(m,S)=>C.decryptWithAd(qi,m,S)}}async function MA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,p=await Lg(i,a.publicKey,f),h=new Xu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Tg(h.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),h.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),Og(h.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(h.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),kg(h.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let y=h.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let b=await Ug(y,h.rs,c),[g,C]=h.ss.split();return Pg(g,C,t),{payload:b,encrypt:m=>C.encryptWithAd(qi,m),decrypt:(m,S)=>g.decryptWithAd(qi,m,S)}}var Qh=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=i??OA;this.crypto=PA(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?NA(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??nt(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Yi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=e.log?.newScope("noise")??this.log,o=of(e,{lengthEncoder:ba,lengthDecoder:wa,maxDataLength:65535}),i=await this.performHandshakeInitiator(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=tc(i.payload.identityKey);return{connection:Mg(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Dd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.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 tl("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=e.log?.newScope("noise")??this.log,o=of(e,{lengthEncoder:ba,lengthDecoder:wa,maxDataLength:65535}),i=await this.performHandshakeResponder(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=tc(i.payload.identityKey);return{connection:Mg(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Dd(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await UA({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}async performHandshakeResponder(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await MA({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}};function jA(r={}){return e=>new Qh(e,r)}var jg=Object.values(Po).map(r=>r.decoder).reduce((r,e)=>r.or(e)),oI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function KA(r){return r?.match(oI)?.groups?.fingerprint}function Kg(r){let t=r.getComponents().find(n=>n.code===466)?.value;if(t===void 0||t==="")throw new xe(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function iI(r){return mr.decode(jg.decode(r))}function sI(r){let e=iI(Kg(r)),t=aI(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new yf(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function HA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=It(tr.code,t);return As(`/certhash/${Oo.encode(n.bytes)}`)}function aI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new bf(r)}}function VA(r,e){let{host:t,port:n,type:o}=hm(r);if(o!=="ip4"&&o!=="ip6")throw new xe(`Multiaddr ${r} was not an IPv4 or IPv6 address`);let i=sI(r);return{type:"answer",sdp:`v=0
|
13
13
|
o=- 0 0 IN IP${o==="ip4"?4:6} ${t}
|
14
14
|
s=-
|
15
15
|
t=0 0
|
@@ -47,8 +47,8 @@ a=end-of-candidates
|
|
47
47
|
`:`
|
48
48
|
`;try{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)}catch{}return r}var Vg=de("libp2p-webrtc-noise:");function WA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=
|
51
|
-
`)}var ep=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 er,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new xe("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"})})}[hl]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Yi]=["@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.getComponents().findLast(
|
50
|
+
a=ice-pwd:`+e+t)}catch{}return r}var Vg=de("libp2p-webrtc-noise:");function WA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=It(tr.code,o),s=jg.decode(Kg(e)),a=Vg.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?Tt([Vg,s,i.bytes],a):Tt([Vg,i.bytes,s],a)}var cI=pf?"iceconnectionstatechange":"connectionstatechange";function uI(r,e){return r.role==="server"}async function qA(r,e,t,n){let o=r.createDataChannel("",{negotiated:!0,id:0});try{if(n.role==="client"){n.log.trace("client creating local offer");let h=await r.createOffer();n.log.trace("client created local offer %s",h.sdp);let y=Hg(h,t);n.log.trace("client setting local offer %s",y.sdp),await r.setLocalDescription(y);let b=VA(n.remoteAddr,t);n.log.trace("client setting server description %s",b.sdp),await r.setRemoteDescription(b)}else{let h=$A(n.remoteAddr,t);n.log.trace("server setting client %s %s",h.type,h.sdp),await r.setRemoteDescription(h),n.log.trace("server creating local answer");let y=await r.createAnswer();n.log.trace("server created local answer");let b=Hg(y,t);n.log.trace("server setting local description %s",y.sdp),await r.setLocalDescription(b)}if(o.readyState!=="open"&&(n.log.trace("%s wait for handshake channel to open, starting status %s",n.role,o.readyState),await Ct(o,"open",n)),n.log.trace("%s handshake channel opened",n.role),uI(n,r)){let h=r.remoteFingerprint()?.value??"";n.remoteAddr=n.remoteAddr.encapsulate(HA(h))}let i=KA(r.localDescription?.sdp);if(i==null)throw new to("Could not get fingerprint from local description sdp");n.log.trace("%s performing noise handshake",n.role);let s=WA(i,n.remoteAddr,n.role),a=jA({prologueBytes:s})(n),c=dc({channel:o,direction:"outbound",isHandshake:!0,log:n.log,...n.dataChannel??{}}),f=mc({peerConnection:r,remoteAddr:n.remoteAddr,metrics:n.events,direction:n.role==="client"?"outbound":"inbound",log:n.logger.forComponent("libp2p:webrtc-direct:connection")});if(r.addEventListener(cI,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":f.close().catch(h=>{n.log.error("error closing connection - %e",h),f.abort(h)});break;default:break}}),n.events?.increment({peer_connection:!0}),n.role==="client"){n.log.trace("%s secure inbound",n.role);let h=await a.secureInbound(c,{remotePeer:n.remotePeer,signal:n.signal,skipStreamMuxerNegotiation:!0});return n.log.trace("%s upgrade outbound",n.role),await n.upgrader.upgradeOutbound(f,{skipProtection:!0,skipEncryption:!0,remotePeer:h.remotePeer,muxerFactory:e,signal:n.signal})}n.log.trace("%s secure outbound",n.role);let p=await a.secureOutbound(c,{remotePeer:n.remotePeer,signal:n.signal,skipStreamMuxerNegotiation:!0});f.remoteAddr=f.remoteAddr.encapsulate(`/p2p/${p.remotePeer}`),n.log.trace("%s upgrade inbound",n.role),await n.upgrader.upgradeInbound(f,{skipProtection:!0,skipEncryption:!0,remotePeer:p.remotePeer,muxerFactory:e,signal:n.signal})}catch(i){throw o.close(),r.close(),i}}async function GA(r,e,t={}){let n=t.certificate;n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t.rtcConfiguration=="function"?await t.rtcConfiguration():t.rtcConfiguration,i=new RTCPeerConnection({...o??{},certificates:[n]}),s=new eo({peerConnection:i,metrics:t.events,dataChannelOptions:t.dataChannel});return{peerConnection:i,muxerFactory:s}}async function zA(r){let e=await Ll(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ue(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
|
51
|
+
`)}var ep=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 er,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new xe("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"})})}[hl]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Yi]=["@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.getComponents().findLast(c=>c.code===421)?.value;o!=null&&(n=gs(o));let i=zw(),{peerConnection:s,muxerFactory:a}=await GA("client",i,{rtcConfiguration:typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{},dataChannel:this.init.dataChannel});try{return await qA(s,a,i,{role:"client",log:this.log,logger:this.components.logger,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeer:n,privateKey:this.components.privateKey})}catch(c){throw s.close(),c}}createListener(e){if(this.certificate==null)throw new cl;return new Gh(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(Cw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(lI(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 zA(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Lw,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new To;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await Qb("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new zu(this.init.certificateDatastoreKey??Rw),i=await Ll(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new To;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??fm)-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:Oo.encode((await tr.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ma(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??fm);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new To;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!We(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new To;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??Uw));n.setMilliseconds(0),o.setMilliseconds(0);let i=await Wh.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new ha(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,de(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function lI(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function fI(r){return e=>new ep(e,r)}function hI(r){return e=>new Af(e,r)}return uS(pI);})();
|
52
52
|
/*! Bundled license information:
|
53
53
|
|
54
54
|
reflect-metadata/Reflect.js:
|