@libp2p/webrtc 5.2.24-8484de8a2 → 5.2.24-87bc8d4fb
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/README.md +20 -10
- package/dist/index.min.js +17 -17
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +23 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +23 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +22 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +22 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/maconn.d.ts +58 -0
- package/dist/src/maconn.d.ts.map +1 -0
- package/dist/src/maconn.js +56 -0
- package/dist/src/maconn.js.map +1 -0
- package/dist/src/muxer.d.ts +46 -14
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +135 -32
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/private-to-private/initiate-connection.d.ts +3 -2
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +5 -23
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/signaling-stream-handler.d.ts +4 -4
- package/dist/src/private-to-private/signaling-stream-handler.d.ts.map +1 -1
- package/dist/src/private-to-private/signaling-stream-handler.js +6 -10
- package/dist/src/private-to-private/signaling-stream-handler.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +2 -2
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +15 -30
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-private/util.d.ts +1 -3
- package/dist/src/private-to-private/util.d.ts.map +1 -1
- package/dist/src/private-to-private/util.js +3 -15
- package/dist/src/private-to-private/util.js.map +1 -1
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +15 -21
- 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 +2 -3
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/private-to-public/utils/connect.d.ts +1 -1
- package/dist/src/private-to-public/utils/connect.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/connect.js +14 -17
- package/dist/src/private-to-public/utils/connect.js.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts +4 -4
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js +2 -13
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js.map +1 -1
- package/dist/src/private-to-public/utils/sdp.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/sdp.js +13 -25
- package/dist/src/private-to-public/utils/sdp.js.map +1 -1
- package/dist/src/private-to-public/utils/stun-listener.js +1 -1
- package/dist/src/private-to-public/utils/stun-listener.js.map +1 -1
- package/dist/src/stream.d.ts +26 -13
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +166 -64
- package/dist/src/stream.js.map +1 -1
- package/dist/src/util.d.ts +1 -3
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +0 -19
- package/dist/src/util.js.map +1 -1
- package/dist/src/webrtc/index.d.ts +1 -1
- package/dist/src/webrtc/index.d.ts.map +1 -1
- package/dist/src/webrtc/index.js +1 -1
- package/dist/src/webrtc/index.js.map +1 -1
- package/package.json +29 -26
- package/src/constants.ts +28 -0
- package/src/index.ts +22 -12
- package/src/maconn.ts +101 -0
- package/src/muxer.ts +166 -43
- package/src/private-to-private/initiate-connection.ts +8 -30
- package/src/private-to-private/signaling-stream-handler.ts +9 -12
- package/src/private-to-private/transport.ts +17 -33
- package/src/private-to-private/util.ts +4 -21
- package/src/private-to-public/listener.ts +15 -22
- package/src/private-to-public/transport.ts +2 -3
- package/src/private-to-public/utils/connect.ts +15 -18
- package/src/private-to-public/utils/get-rtcpeerconnection.ts +4 -16
- package/src/private-to-public/utils/sdp.ts +13 -29
- package/src/private-to-public/utils/stun-listener.ts +1 -1
- package/src/stream.ts +194 -74
- package/src/util.ts +1 -22
- package/src/webrtc/index.ts +1 -1
- package/dist/src/rtcpeerconnection-to-conn.d.ts +0 -12
- package/dist/src/rtcpeerconnection-to-conn.d.ts.map +0 -1
- package/dist/src/rtcpeerconnection-to-conn.js +0 -43
- package/dist/src/rtcpeerconnection-to-conn.js.map +0 -1
- package/src/rtcpeerconnection-to-conn.ts +0 -62
package/dist/index.min.js
CHANGED
@@ -1,21 +1,21 @@
|
|
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 eS=Object.create;var ju=Object.defineProperty;var tS=Object.getOwnPropertyDescriptor;var rS=Object.getOwnPropertyNames;var nS=Object.getPrototypeOf,oS=Object.prototype.hasOwnProperty;var Xp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),bt=(r,e)=>{for(var t in e)ju(r,t,{get:e[t],enumerable:!0})},$g=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of rS(e))!oS.call(r,o)&&o!==t&&ju(r,o,{get:()=>e[o],enumerable:!(n=tS(e,o))||n.enumerable});return r};var Mr=(r,e,t)=>(t=r!=null?eS(nS(r)):{},$g(e||!r||!r.__esModule?ju(t,"default",{value:r,enumerable:!0}):t,r)),iS=r=>$g(ju({},"__esModule",{value:!0}),r);var Xx=Xp(()=>{var zx;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,l){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),l&&l(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,l=!a&&!c,h={create:a?function(){return zp(Object.create(null))}:c?function(){return zp({__proto__:null})}:function(){return zp({})},has:l?function(A,C){return n.call(A,C)}:function(A,C){return C in A},get:l?function(A,C){return n.call(A,C)?A[C]:void 0}:function(A,C){return A[C]}},p=Object.getPrototypeOf(Function),d=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:XA(),y=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:ZA(),g=typeof WeakMap=="function"?WeakMap:YA(),x=o?Symbol.for("@reflect-metadata:registry"):void 0,b=qA(),E=GA(b);function D(A,C,O,$){if(N(O)){if(!on(A))throw new TypeError;if(!Wn(C))throw new TypeError;return H(A,C)}else{if(!on(A))throw new TypeError;if(!Q(C))throw new TypeError;if(!Q($)&&!N($)&&!fe($))throw new TypeError;return fe($)&&($=void 0),O=Te(O),w(A,C,O,$)}}e("decorate",D);function I(A,C){function O($,se){if(!Q($))throw new TypeError;if(!N(se)&&!Mu(se))throw new TypeError;U(A,C,$,se)}return O}e("metadata",I);function V(A,C,O,$){if(!Q(O))throw new TypeError;return N($)||($=Te($)),U(A,C,O,$)}e("defineMetadata",V);function Y(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Te(O)),v(A,C,O)}e("hasMetadata",Y);function z(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Te(O)),_(A,C,O)}e("hasOwnMetadata",z);function te(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Te(O)),P(A,C,O)}e("getMetadata",te);function X(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Te(O)),R(A,C,O)}e("getOwnMetadata",X);function T(A,C){if(!Q(A))throw new TypeError;return N(C)||(C=Te(C)),k(A,C)}e("getMetadataKeys",T);function j(A,C){if(!Q(A))throw new TypeError;return N(C)||(C=Te(C)),L(A,C)}e("getOwnMetadataKeys",j);function q(A,C,O){if(!Q(C))throw new TypeError;if(N(O)||(O=Te(O)),!Q(C))throw new TypeError;N(O)||(O=Te(O));var $=Ba(C,O,!1);return N($)?!1:$.OrdinaryDeleteMetadata(A,C,O)}e("deleteMetadata",q);function H(A,C){for(var O=A.length-1;O>=0;--O){var $=A[O],se=$(C);if(!N(se)&&!fe(se)){if(!Wn(se))throw new TypeError;C=se}}return C}function w(A,C,O,$){for(var se=A.length-1;se>=0;--se){var Ge=A[se],Qe=Ge(C,O,$);if(!N(Qe)&&!fe(Qe)){if(!Q(Qe))throw new TypeError;$=Qe}}return $}function v(A,C,O){var $=_(A,C,O);if($)return!0;var se=Gp(C);return fe(se)?!1:v(A,se,O)}function _(A,C,O){var $=Ba(C,O,!1);return N($)?!1:Pe($.OrdinaryHasOwnMetadata(A,C,O))}function P(A,C,O){var $=_(A,C,O);if($)return R(A,C,O);var se=Gp(C);if(!fe(se))return P(A,se,O)}function R(A,C,O){var $=Ba(C,O,!1);if(!N($))return $.OrdinaryGetOwnMetadata(A,C,O)}function U(A,C,O,$){var se=Ba(O,$,!0);se.OrdinaryDefineOwnMetadata(A,C,O,$)}function k(A,C){var O=L(A,C),$=Gp(A);if($===null)return O;var se=k($,C);if(se.length<=0)return O;if(O.length<=0)return se;for(var Ge=new y,Qe=[],ge=0,G=O;ge<G.length;ge++){var J=G[ge],re=Ge.has(J);re||(Ge.add(J),Qe.push(J))}for(var ne=0,xe=se;ne<xe.length;ne++){var J=xe[ne],re=Ge.has(J);re||(Ge.add(J),Qe.push(J))}return Qe}function L(A,C){var O=Ba(A,C,!1);return O?O.OrdinaryOwnMetadataKeys(A,C):[]}function W(A){if(A===null)return 1;switch(typeof A){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return A===null?1:6;default:return 6}}function N(A){return A===void 0}function fe(A){return A===null}function me(A){return typeof A=="symbol"}function Q(A){return typeof A=="object"?A!==null:typeof A=="function"}function we(A,C){switch(W(A)){case 0:return A;case 1:return A;case 2:return A;case 3:return A;case 4:return A;case 5:return A}var O=C===3?"string":C===5?"number":"default",$=Ug(A,i);if($!==void 0){var se=$.call(A,O);if(Q(se))throw new TypeError;return se}return Ee(A,O==="default"?"number":O)}function Ee(A,C){if(C==="string"){var O=A.toString;if(tr(O)){var $=O.call(A);if(!Q($))return $}var se=A.valueOf;if(tr(se)){var $=se.call(A);if(!Q($))return $}}else{var se=A.valueOf;if(tr(se)){var $=se.call(A);if(!Q($))return $}var Ge=A.toString;if(tr(Ge)){var $=Ge.call(A);if(!Q($))return $}}throw new TypeError}function Pe(A){return!!A}function Ae(A){return""+A}function Te(A){var C=we(A,3);return me(C)?C:Ae(C)}function on(A){return Array.isArray?Array.isArray(A):A instanceof Object?A instanceof Array:Object.prototype.toString.call(A)==="[object Array]"}function tr(A){return typeof A=="function"}function Wn(A){return typeof A=="function"}function Mu(A){switch(W(A)){case 3:return!0;case 4:return!0;default:return!1}}function ts(A,C){return A===C||A!==A&&C!==C}function Ug(A,C){var O=A[C];if(O!=null){if(!tr(O))throw new TypeError;return O}}function Mg(A){var C=Ug(A,s);if(!tr(C))throw new TypeError;var O=C.call(A);if(!Q(O))throw new TypeError;return O}function jg(A){return A.value}function Kg(A){var C=A.next();return C.done?!1:C}function Hg(A){var C=A.return;C&&C.call(A)}function Gp(A){var C=Object.getPrototypeOf(A);if(typeof A!="function"||A===p||C!==p)return C;var O=A.prototype,$=O&&Object.getPrototypeOf(O);if($==null||$===Object.prototype)return C;var se=$.constructor;return typeof se!="function"||se===A?C:se}function WA(){var A;!N(x)&&typeof t.Reflect<"u"&&!(x in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(A=zA(t.Reflect));var C,O,$,se=new g,Ge={registerProvider:Qe,getProvider:G,setProvider:re};return Ge;function Qe(ne){if(!Object.isExtensible(Ge))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case A===ne:break;case N(C):C=ne;break;case C===ne:break;case N(O):O=ne;break;case O===ne:break;default:$===void 0&&($=new y),$.add(ne);break}}function ge(ne,xe){if(!N(C)){if(C.isProviderFor(ne,xe))return C;if(!N(O)){if(O.isProviderFor(ne,xe))return C;if(!N($))for(var Re=Mg($);;){var ze=Kg(Re);if(!ze)return;var br=jg(ze);if(br.isProviderFor(ne,xe))return Hg(Re),br}}}if(!N(A)&&A.isProviderFor(ne,xe))return A}function G(ne,xe){var Re=se.get(ne),ze;return N(Re)||(ze=Re.get(xe)),N(ze)&&(ze=ge(ne,xe),N(ze)||(N(Re)&&(Re=new d,se.set(ne,Re)),Re.set(xe,ze))),ze}function J(ne){if(N(ne))throw new TypeError;return C===ne||O===ne||!N($)&&$.has(ne)}function re(ne,xe,Re){if(!J(Re))throw new Error("Metadata provider not registered.");var ze=G(ne,xe);if(ze!==Re){if(!N(ze))return!1;var br=se.get(ne);N(br)&&(br=new d,se.set(ne,br)),br.set(xe,Re)}return!0}}function qA(){var A;return!N(x)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(A=t.Reflect[x]),N(A)&&(A=WA()),!N(x)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,x,{enumerable:!1,configurable:!1,writable:!1,value:A}),A}function GA(A){var C=new g,O={isProviderFor:function(J,re){var ne=C.get(J);return N(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:Qe,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Ge,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:G};return b.registerProvider(O),O;function $(J,re,ne){var xe=C.get(J),Re=!1;if(N(xe)){if(!ne)return;xe=new d,C.set(J,xe),Re=!0}var ze=xe.get(re);if(N(ze)){if(!ne)return;if(ze=new d,xe.set(re,ze),!A.setProvider(J,re,O))throw xe.delete(re),Re&&C.delete(J),new Error("Wrong provider for target.")}return ze}function se(J,re,ne){var xe=$(re,ne,!1);return N(xe)?!1:Pe(xe.has(J))}function Ge(J,re,ne){var xe=$(re,ne,!1);if(!N(xe))return xe.get(J)}function Qe(J,re,ne,xe){var Re=$(ne,xe,!0);Re.set(J,re)}function ge(J,re){var ne=[],xe=$(J,re,!1);if(N(xe))return ne;for(var Re=xe.keys(),ze=Mg(Re),br=0;;){var Vg=Kg(ze);if(!Vg)return ne.length=br,ne;var JA=jg(Vg);try{ne[br]=JA}catch(QA){try{Hg(ze)}finally{throw QA}}br++}}function G(J,re,ne){var xe=$(re,ne,!1);if(N(xe)||!xe.delete(J))return!1;if(xe.size===0){var Re=C.get(re);N(Re)||(Re.delete(ne),Re.size===0&&C.delete(Re))}return!0}}function zA(A){var C=A.defineMetadata,O=A.hasOwnMetadata,$=A.getOwnMetadata,se=A.getOwnMetadataKeys,Ge=A.deleteMetadata,Qe=new g,ge={isProviderFor:function(G,J){var re=Qe.get(G);return!N(re)&&re.has(J)?!0:se(G,J).length?(N(re)&&(re=new y,Qe.set(G,re)),re.add(J),!0):!1},OrdinaryDefineOwnMetadata:C,OrdinaryHasOwnMetadata:O,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Ge};return ge}function Ba(A,C,O){var $=b.getProvider(A,C);if(!N($))return $;if(O){if(b.setProvider(A,C,E))return E;throw new Error("Illegal state.")}}function XA(){var A={},C=[],O=(function(){function ge(G,J,re){this._index=0,this._keys=G,this._values=J,this._selector=re}return ge.prototype["@@iterator"]=function(){return this},ge.prototype[s]=function(){return this},ge.prototype.next=function(){var G=this._index;if(G>=0&&G<this._keys.length){var J=this._selector(this._keys[G],this._values[G]);return G+1>=this._keys.length?(this._index=-1,this._keys=C,this._values=C):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},ge.prototype.throw=function(G){throw this._index>=0&&(this._index=-1,this._keys=C,this._values=C),G},ge.prototype.return=function(G){return this._index>=0&&(this._index=-1,this._keys=C,this._values=C),{value:G,done:!0}},ge})(),$=(function(){function ge(){this._keys=[],this._values=[],this._cacheKey=A,this._cacheIndex=-2}return Object.defineProperty(ge.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),ge.prototype.has=function(G){return this._find(G,!1)>=0},ge.prototype.get=function(G){var J=this._find(G,!1);return J>=0?this._values[J]:void 0},ge.prototype.set=function(G,J){var re=this._find(G,!0);return this._values[re]=J,this},ge.prototype.delete=function(G){var J=this._find(G,!1);if(J>=0){for(var re=this._keys.length,ne=J+1;ne<re;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,ts(G,this._cacheKey)&&(this._cacheKey=A,this._cacheIndex=-2),!0}return!1},ge.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=A,this._cacheIndex=-2},ge.prototype.keys=function(){return new O(this._keys,this._values,se)},ge.prototype.values=function(){return new O(this._keys,this._values,Ge)},ge.prototype.entries=function(){return new O(this._keys,this._values,Qe)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(G,J){if(!ts(this._cacheKey,G)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(ts(this._keys[re],G)){this._cacheIndex=re;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(G),this._values.push(void 0)),this._cacheIndex},ge})();return $;function se(ge,G){return ge}function Ge(ge,G){return G}function Qe(ge,G){return[ge,G]}}function ZA(){var A=(function(){function C(){this._map=new d}return Object.defineProperty(C.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),C.prototype.has=function(O){return this._map.has(O)},C.prototype.add=function(O){return this._map.set(O,O),this},C.prototype.delete=function(O){return this._map.delete(O)},C.prototype.clear=function(){this._map.clear()},C.prototype.keys=function(){return this._map.keys()},C.prototype.values=function(){return this._map.keys()},C.prototype.entries=function(){return this._map.entries()},C.prototype["@@iterator"]=function(){return this.keys()},C.prototype[s]=function(){return this.keys()},C})();return A}function YA(){var A=16,C=h.create(),O=$();return(function(){function G(){this._key=$()}return G.prototype.has=function(J){var re=se(J,!1);return re!==void 0?h.has(re,this._key):!1},G.prototype.get=function(J){var re=se(J,!1);return re!==void 0?h.get(re,this._key):void 0},G.prototype.set=function(J,re){var ne=se(J,!0);return ne[this._key]=re,this},G.prototype.delete=function(J){var re=se(J,!1);return re!==void 0?delete re[this._key]:!1},G.prototype.clear=function(){this._key=$()},G})();function $(){var G;do G="@@WeakMap@@"+ge();while(h.has(C,G));return C[G]=!0,G}function se(G,J){if(!n.call(G,O)){if(!J)return;Object.defineProperty(G,O,{value:h.create()})}return G[O]}function Ge(G,J){for(var re=0;re<J;++re)G[re]=Math.random()*255|0;return G}function Qe(G){if(typeof Uint8Array=="function"){var J=new Uint8Array(G);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Ge(J,G),J}return Ge(new Array(G),G)}function ge(){var G=Qe(A);G[6]=G[6]&79|64,G[8]=G[8]&191|128;for(var J="",re=0;re<A;++re){var ne=G[re];(re===4||re===6||re===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function zp(A){return A.__=void 0,delete A.__,A}})})(zx||(zx={}))});var Sn=Xp(Us=>{"use strict";var sC="[object ArrayBuffer]",An=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===sC}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}},xm="string",aC=/^[0-9a-f\s]+$/i,cC=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,uC=/^[a-zA-Z0-9-_]+$/,hf=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=An.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},cr=class{static toString(e,t=!1){let n=An.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}},df=class r{static isHex(e){return typeof e===xm&&aC.test(e)}static isBase64(e){return typeof e===xm&&cC.test(e)}static isBase64Url(e){return typeof e===xm&&uC.test(e)}static ToString(e,t="utf8"){let n=An.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return cr.toString(n,!0);case"utf16":case"utf16be":return cr.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return cr.fromString(e,!0);case"utf16":case"utf16be":return cr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=An.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 hf.fromString(e);case"utf16":case"utf16be":return cr.fromString(e);case"utf16le":case"usc2":return cr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return hf.toString(e);case"utf16":case"utf16be":return cr.toString(e);case"utf16le":case"usc2":return cr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=An.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=An.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return cr.toString(e,t)}static FromUtf16String(e,t=!1){return cr.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};df.DEFAULT_UTF8_ENCODING="utf8";function lC(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 fC(...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 pC(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}Us.BufferSourceConverter=An;Us.Convert=df;Us.assign=lC;Us.combine=fC;Us.isEqual=pC});var $v=Xp((K7,cp)=>{var Sv,Ev,_v,Cv,Bv,Iv,Tv,kv,Pv,ap,By,Ov,Nv,pa,Dv,Rv,Lv,Uv,Mv,jv,Kv,Hv,Vv;(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 cp=="object"&&typeof cp.exports=="object"?r(t(e,t(cp.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])};Sv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Ev=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},_v=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},Cv=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Bv=function(t,n){return function(o,i){n(o,i,t)}},Iv=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Tv=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function l(d){try{p(i.next(d))}catch(y){c(y)}}function h(d){try{p(i.throw(d))}catch(y){c(y)}}function p(d){d.done?a(d.value):s(d.value).then(l,h)}p((i=i.apply(t,n||[])).next())})},kv=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(p){return function(d){return h([p,d])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(d){p=[6,d],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Vv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Pv=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},ap=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.")},By=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Ov=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(By(arguments[n]));return t},Nv=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,l=a.length;c<l;c++,s++)i[s]=a[c];return i},pa=function(t){return this instanceof pa?(this.v=t,this):new pa(t)},Dv=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(x){return new Promise(function(b,E){a.push([g,x,b,E])>1||l(g,x)})})}function l(g,x){try{h(i[g](x))}catch(b){y(a[0][3],b)}}function h(g){g.value instanceof pa?Promise.resolve(g.value.v).then(p,d):y(a[0][2],g)}function p(g){l("next",g)}function d(g){l("throw",g)}function y(g,x){g(x),a.shift(),a.length&&l(a[0][0],a[0][1])}},Rv=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:pa(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Lv=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 ap=="function"?ap(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(l,h){c=t[a](c),s(l,h,c.done,c.value)})}}function s(a,c,l,h){Promise.resolve(h).then(function(p){a({value:p,done:l})},c)}},Uv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Mv=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},jv=function(t){return t&&t.__esModule?t:{default:t}},Kv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},Hv=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",Sv),r("__assign",Ev),r("__rest",_v),r("__decorate",Cv),r("__param",Bv),r("__metadata",Iv),r("__awaiter",Tv),r("__generator",kv),r("__exportStar",Pv),r("__createBinding",Vv),r("__values",ap),r("__read",By),r("__spread",Ov),r("__spreadArrays",Nv),r("__await",pa),r("__asyncGenerator",Dv),r("__asyncDelegator",Rv),r("__asyncValues",Lv),r("__makeTemplateObject",Uv),r("__importStar",Mv),r("__importDefault",jv),r("__classPrivateFieldGet",Kv),r("__classPrivateFieldSet",Hv)})});var cI={};bt(cI,{webRTC:()=>aI,webRTCDirect:()=>sI});var Ku=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},Hu=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},be=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},rs=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Ia=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Vu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},$u=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}};var Fu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var jr=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ta=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},Uo=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Wu=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},qu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Gu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var zu=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Xu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var qn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Zu=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ns=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},Yu=class extends ns{constructor(e,t){super(!0,e,t)}},Ju=class extends ns{constructor(e,t){super(!1,e,t)}};var Zp=Symbol.for("@libp2p/peer-id");var Qu=Symbol.for("@libp2p/transport");var Fg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Fg||(Fg={}));var rr=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 os=Symbol.for("@libp2p/service-capabilities"),Wg=Symbol.for("@libp2p/service-dependencies");var th={};bt(th,{base58btc:()=>Ve,base58flickr:()=>pS});var HI=new Uint8Array(0);function qg(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 sn(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Gg(r){return new TextEncoder().encode(r)}function zg(r){return new TextDecoder().decode(r)}function sS(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(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 x=0,b=0,E=0,D=g.length;E!==D&&g[E]===0;)E++,x++;for(var I=(D-E)*h+1>>>0,V=new Uint8Array(I);E!==D;){for(var Y=g[E],z=0,te=I-1;(Y!==0||z<b)&&te!==-1;te--,z++)Y+=256*V[te]>>>0,V[te]=Y%a>>>0,Y=Y/a>>>0;if(Y!==0)throw new Error("Non-zero carry");b=z,E++}for(var X=I-b;X!==I&&V[X]===0;)X++;for(var T=c.repeat(x);X<I;++X)T+=r.charAt(V[X]);return T}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var b=0,E=0;g[x]===c;)b++,x++;for(var D=(g.length-x)*l+1>>>0,I=new Uint8Array(D);g[x];){var V=t[g.charCodeAt(x)];if(V===255)return;for(var Y=0,z=D-1;(V!==0||Y<E)&&z!==-1;z--,Y++)V+=a*I[z]>>>0,I[z]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");E=Y,x++}if(g[x]!==" "){for(var te=D-E;te!==D&&I[te]===0;)te++;for(var X=new Uint8Array(b+(D-te)),T=b;te!==D;)X[T++]=I[te++];return X}}}function y(g){var x=d(g);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:d,decode:y}}var aS=sS,cS=aS,Zg=cS;var Yp=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Jp=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Yg(this,e)}},Qp=class{decoders;constructor(e){this.decoders=e}or(e){return Yg(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 Yg(r,e){return new Qp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var eh=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Yp(e,t,n),this.decoder=new Jp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function is({name:r,prefix:e,encode:t,decode:n}){return new eh(r,e,t,n)}function Gn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Zg(t,r);return is({prefix:e,name:r,encode:n,decode:i=>sn(o(i))})}function uS(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,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 lS(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 fS(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function He({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=fS(n);return is({prefix:e,name:r,encode(i){return lS(i,n,t)},decode(i){return uS(i,o,t,r)}})}var Ve=Gn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pS=Gn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rh={};bt(rh,{base32:()=>zn,base32hex:()=>yS,base32hexpad:()=>bS,base32hexpadupper:()=>xS,base32hexupper:()=>gS,base32pad:()=>dS,base32padupper:()=>mS,base32upper:()=>hS,base32z:()=>wS});var zn=He({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hS=He({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),dS=He({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),mS=He({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yS=He({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gS=He({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bS=He({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xS=He({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wS=He({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nh={};bt(nh,{base36:()=>ka,base36upper:()=>vS});var ka=Gn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vS=Gn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xr={};bt(xr,{Digest:()=>Mo,create:()=>Ct,decode:()=>cs,equals:()=>ih,hasCode:()=>KS});var AS=e0,Jg=128,SS=127,ES=~SS,_S=Math.pow(2,31);function e0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=_S;)e[t++]=r&255|Jg,r/=128;for(;r&ES;)e[t++]=r&255|Jg,r>>>=7;return e[t]=r|0,e0.bytes=t-n+1,e}var CS=oh,BS=128,Qg=127;function oh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw oh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Qg)<<o:(s&Qg)*Math.pow(2,o),o+=7}while(s>=BS);return oh.bytes=i-n,t}var IS=Math.pow(2,7),TS=Math.pow(2,14),kS=Math.pow(2,21),PS=Math.pow(2,28),OS=Math.pow(2,35),NS=Math.pow(2,42),DS=Math.pow(2,49),RS=Math.pow(2,56),LS=Math.pow(2,63),US=function(r){return r<IS?1:r<TS?2:r<kS?3:r<PS?4:r<OS?5:r<NS?6:r<DS?7:r<RS?8:r<LS?9:10},MS={encode:AS,decode:CS,encodingLength:US},jS=MS,Pa=jS;function Oa(r,e=0){return[Pa.decode(r,e),Pa.decode.bytes]}function ss(r,e,t=0){return Pa.encode(r,e,t),e}function as(r){return Pa.encodingLength(r)}function Ct(r,e){let t=e.byteLength,n=as(r),o=n+as(t),i=new Uint8Array(o+t);return ss(r,i,0),ss(t,i,n),i.set(e,o),new Mo(r,t,e,i)}function cs(r){let e=sn(r),[t,n]=Oa(e),[o,i]=Oa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Mo(t,o,s,e)}function ih(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&qg(r.bytes,t.bytes)}}var Mo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function KS(r,e){return r.code===e}function t0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return VS(t,sh(r),e??Ve.encoder);default:return $S(t,sh(r),e??zn.encoder)}}var r0=new WeakMap;function sh(r){let e=r0.get(r);if(e==null){let t=new Map;return r0.set(r,t),t}return e}var et=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Na)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==FS)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=Ct(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ih(e.multihash,n.multihash)}toString(e){return t0(this,e)}toJSON(){return{"/":t0(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??n0(n,o,i.bytes))}else if(t[WS]===!0){let{version:n,multihash:o,code:i}=t,s=cs(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!==Na)throw new Error(`Version 0 CID must use dag-pb (code: ${Na}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=n0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Na,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=sn(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 Mo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,d]=Oa(e.subarray(t));return t+=d,p},o=n(),i=Na;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),l=t+c,h=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=HS(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return sh(i).set(n,e),i}};function HS(r,e){switch(r[0]){case"Q":{let t=e??Ve;return[Ve.prefix,t.decode(`${Ve.prefix}${r}`)]}case Ve.prefix:{let t=e??Ve;return[Ve.prefix,t.decode(r)]}case zn.prefix:{let t=e??zn;return[zn.prefix,t.decode(r)]}case ka.prefix:{let t=e??ka;return[ka.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 VS(r,e,t){let{prefix:n}=t;if(n!==Ve.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 $S(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 Na=112,FS=18;function n0(r,e,t){let n=as(r),o=n+as(e),i=new Uint8Array(o+t.byteLength);return ss(r,i,0),ss(e,i,n),i.set(t,o),i}var WS=Symbol.for("@ipld/js-cid/CID");var ah={};bt(ah,{identity:()=>wr});var o0=0,qS="identity",i0=sn;function GS(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 Ct(o0,i0(r))}var wr={code:o0,name:qS,encode:i0,digest:GS};function $e(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 tt(r=0){return new Uint8Array(r)}function rt(r=0){return new Uint8Array(r)}function Bt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=rt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var a0=Symbol.for("@achingbrain/uint8arraylist");function s0(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function tl(r){return!!r?.[a0]}var he=class r{bufs;length;[a0]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(tl(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(tl(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=s0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=s0(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(tl(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Bt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Bt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!tl(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let d=l;d>=0;d--){let y=this.get(p+d);if(n[d]!==y){h=Math.max(1,d-a[y]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=rt(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=tt(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=tt(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=tt(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=rt(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=tt(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=tt(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=tt(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=tt(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=tt(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(!$e(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var ch={};bt(ch,{base10:()=>XS});var XS=Gn({prefix:"9",name:"base10",alphabet:"0123456789"});var uh={};bt(uh,{base16:()=>ZS,base16upper:()=>YS});var ZS=He({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),YS=He({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var lh={};bt(lh,{base2:()=>JS});var JS=He({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fh={};bt(fh,{base256emoji:()=>nE});var c0=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}"),QS=c0.reduce((r,e,t)=>(r[t]=e,r),[]),eE=c0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function tE(r){return r.reduce((e,t)=>(e+=QS[t],e),"")}function rE(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=eE[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var nE=is({prefix:"\u{1F680}",name:"base256emoji",encode:tE,decode:rE});var ph={};bt(ph,{base64:()=>oE,base64pad:()=>iE,base64url:()=>jo,base64urlpad:()=>sE});var oE=He({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),iE=He({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jo=He({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sE=He({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hh={};bt(hh,{base8:()=>aE});var aE=He({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dh={};bt(dh,{identity:()=>cE});var cE=is({prefix:"\0",name:"identity",encode:r=>zg(r),decode:r=>Gg(r)});var ST=new TextEncoder,ET=new TextDecoder;var gh={};bt(gh,{sha256:()=>nr,sha512:()=>pE});var fE=20;function yh({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new mh(r,e,t,n,o)}var mh=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??fE,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?u0(n,this.code,t?.truncate):n.then(o=>u0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function u0(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 Ct(e,r)}function f0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var nr=yh({name:"sha2-256",code:18,encode:f0("SHA-256")}),pE=yh({name:"sha2-512",code:19,encode:f0("SHA-512")});var Ko={...dh,...lh,...hh,...ch,...uh,...rh,...nh,...th,...ph,...fh},LT={...gh,...ah};function h0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var p0=h0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),bh=h0("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=rt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),hE={utf8:p0,"utf-8":p0,hex:Ko.base16,latin1:bh,ascii:bh,binary:bh,...Ko},rl=hE;function pe(r,e="utf8"){let t=rl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=rl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var dE=parseInt("11111",2),xh=parseInt("10000000",2),mE=parseInt("01111111",2),d0={0:Da,1:Da,2:yE,3:xE,4:wE,5:bE,6:gE,16:Da,22:Da,48:Da};function an(r,e={offset:0}){let t=r[e.offset]&dE;if(e.offset++,d0[t]!=null)return d0[t](r,e);throw new Error("No decoder for tag "+t)}function Ra(r,e){let t=0;if((r[e.offset]&xh)===xh){let n=r[e.offset]&mE,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 Da(r,e){Ra(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=an(r,e);if(n===null)break;t.push(n)}return t}function yE(r,e){let t=Ra(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 gE(r,e){let t=Ra(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function bE(r,e){return e.offset++,null}function xE(r,e){let t=Ra(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 wE(r,e){let t=Ra(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function vE(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new he;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function nl(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=vE(r.byteLength);return new he(Uint8Array.from([e.byteLength|xh]),e)}function It(r){let e=new he,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new he(Uint8Array.from([2]),nl(e),e)}function La(r){let e=Uint8Array.from([0]),t=new he(e,r);return new he(Uint8Array.from([3]),nl(t),t)}function m0(r){return new he(Uint8Array.from([4]),nl(r),r)}function vr(r,e=48){let t=new he;for(let n of r)t.append(n);return new he(Uint8Array.from([e]),nl(t),t)}async function y0(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 g0(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 b0(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 AE=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),SE=Uint8Array.from([6,5,43,129,4,0,34]),EE=Uint8Array.from([6,5,43,129,4,0,35]),_E={ext:!0,kty:"EC",crv:"P-256"},CE={ext:!0,kty:"EC",crv:"P-384"},BE={ext:!0,kty:"EC",crv:"P-521"},wh=32,vh=48,Ah=66;function Sh(r){let e=an(r);return x0(e)}function x0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===wh*2+1)return n=ue(e.subarray(t,t+wh),"base64url"),o=ue(e.subarray(t+wh),"base64url"),new Ho({..._E,key_ops:["verify"],x:n,y:o});if(e.byteLength===vh*2+1)return n=ue(e.subarray(t,t+vh),"base64url"),o=ue(e.subarray(t+vh),"base64url"),new Ho({...CE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ah*2+1)return n=ue(e.subarray(t,t+Ah),"base64url"),o=ue(e.subarray(t+Ah),"base64url"),new Ho({...BE,key_ops:["verify"],x:n,y:o});throw new be(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function w0(r){return vr([It(Uint8Array.from([1])),m0(pe(r.d??"","base64url")),vr([A0(r.crv)],160),vr([La(new he(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function v0(r){return vr([It(Uint8Array.from([1])),vr([A0(r.crv)],160),vr([La(new he(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function A0(r){if(r==="P-256")return AE;if(r==="P-384")return SE;if(r==="P-521")return EE;throw new be(`Invalid curve ${r}`)}async function S0(r="P-256"){let e=await y0(r);return new ol(e.privateKey)}var Ho=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=v0(this.jwk)),this._raw}toMultihash(){return wr.digest(Xn(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Ve.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}async verify(e,t,n){return b0(this.jwk,t,e,n)}},ol=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Ho({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=w0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}async sign(e,t){return g0(this.jwk,e,t)}};var Vo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function un(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function $o(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function xt(r,...e){if(!un(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Fo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");$o(r.outputLen),$o(r.blockLen)}function ls(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function _0(r,e){xt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Ar(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function il(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Sr(r,e){return r<<32-e|r>>>e}var C0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",IE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function or(r){if(xt(r),C0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=IE[r[t]];return e}var cn={_0:48,_9:57,A:65,F:70,a:97,f:102};function E0(r){if(r>=cn._0&&r<=cn._9)return r-cn._0;if(r>=cn.A&&r<=cn.F)return r-(cn.A-10);if(r>=cn.a&&r<=cn.f)return r-(cn.a-10)}function Wo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(C0)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=E0(r.charCodeAt(i)),a=E0(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 Eh(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Zn(r){return typeof r=="string"&&(r=Eh(r)),xt(r),r}function Tt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];xt(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var us=class{};function _h(r){let e=n=>r().update(Zn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Yn(r=32){if(Vo&&typeof Vo.getRandomValues=="function")return Vo.getRandomValues(new Uint8Array(r));if(Vo&&typeof Vo.randomBytes=="function")return Uint8Array.from(Vo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function TE(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function B0(r,e,t){return r&e^~r&t}function I0(r,e,t){return r&e^r&t^e&t}var Ua=class extends us{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=il(this.buffer)}update(e){ls(this),e=Zn(e),xt(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=il(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){ls(this),_0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Ar(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;TE(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=il(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.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 at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var sl=BigInt(4294967295),T0=BigInt(32);function kE(r,e=!1){return e?{h:Number(r&sl),l:Number(r>>T0&sl)}:{h:Number(r>>T0&sl)|0,l:Number(r&sl)|0}}function k0(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}=kE(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Ch=(r,e,t)=>r>>>t,Bh=(r,e,t)=>r<<32-t|e>>>t,qo=(r,e,t)=>r>>>t|e<<32-t,Go=(r,e,t)=>r<<32-t|e>>>t,Ma=(r,e,t)=>r<<64-t|e>>>t-32,ja=(r,e,t)=>r>>>t-32|e<<64-t;function Kr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var P0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),O0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,N0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),D0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,R0=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),L0=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var OE=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]),Jn=new Uint32Array(64),al=class extends Ua{constructor(e=32){super(64,e,8,!1),this.A=ln[0]|0,this.B=ln[1]|0,this.C=ln[2]|0,this.D=ln[3]|0,this.E=ln[4]|0,this.F=ln[5]|0,this.G=ln[6]|0,this.H=ln[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)Jn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let d=Jn[p-15],y=Jn[p-2],g=Sr(d,7)^Sr(d,18)^d>>>3,x=Sr(y,17)^Sr(y,19)^y>>>10;Jn[p]=x+Jn[p-7]+g+Jn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:h}=this;for(let p=0;p<64;p++){let d=Sr(a,6)^Sr(a,11)^Sr(a,25),y=h+d+B0(a,c,l)+OE[p]+Jn[p]|0,x=(Sr(n,2)^Sr(n,13)^Sr(n,22))+I0(n,o,i)|0;h=l,l=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+x|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,l,h)}roundClean(){Ar(Jn)}destroy(){this.set(0,0,0,0,0,0,0,0),Ar(this.buffer)}};var U0=k0(["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))),NE=U0[0],DE=U0[1],Qn=new Uint32Array(80),eo=new Uint32Array(80),Ih=class extends Ua{constructor(e=64){super(128,e,16,!1),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:h,Fh:p,Fl:d,Gh:y,Gl:g,Hh:x,Hl:b}=this;return[e,t,n,o,i,s,a,c,l,h,p,d,y,g,x,b]}set(e,t,n,o,i,s,a,c,l,h,p,d,y,g,x,b){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=h|0,this.Fh=p|0,this.Fl=d|0,this.Gh=y|0,this.Gl=g|0,this.Hh=x|0,this.Hl=b|0}process(e,t){for(let I=0;I<16;I++,t+=4)Qn[I]=e.getUint32(t),eo[I]=e.getUint32(t+=4);for(let I=16;I<80;I++){let V=Qn[I-15]|0,Y=eo[I-15]|0,z=qo(V,Y,1)^qo(V,Y,8)^Ch(V,Y,7),te=Go(V,Y,1)^Go(V,Y,8)^Bh(V,Y,7),X=Qn[I-2]|0,T=eo[I-2]|0,j=qo(X,T,19)^Ma(X,T,61)^Ch(X,T,6),q=Go(X,T,19)^ja(X,T,61)^Bh(X,T,6),H=N0(te,q,eo[I-7],eo[I-16]),w=D0(H,z,j,Qn[I-7],Qn[I-16]);Qn[I]=w|0,eo[I]=H|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:h,Eh:p,El:d,Fh:y,Fl:g,Gh:x,Gl:b,Hh:E,Hl:D}=this;for(let I=0;I<80;I++){let V=qo(p,d,14)^qo(p,d,18)^Ma(p,d,41),Y=Go(p,d,14)^Go(p,d,18)^ja(p,d,41),z=p&y^~p&x,te=d&g^~d&b,X=R0(D,Y,te,DE[I],eo[I]),T=L0(X,E,V,z,NE[I],Qn[I]),j=X|0,q=qo(n,o,28)^Ma(n,o,34)^Ma(n,o,39),H=Go(n,o,28)^ja(n,o,34)^ja(n,o,39),w=n&i^n&a^i&a,v=o&s^o&c^s&c;E=x|0,D=b|0,x=y|0,b=g|0,y=p|0,g=d|0,{h:p,l:d}=Kr(l|0,h|0,T|0,j|0),l=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let _=P0(j,H,v);n=O0(_,T,q,w),o=_|0}({h:n,l:o}=Kr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Kr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Kr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=Kr(this.Dh|0,this.Dl|0,l|0,h|0),{h:p,l:d}=Kr(this.Eh|0,this.El|0,p|0,d|0),{h:y,l:g}=Kr(this.Fh|0,this.Fl|0,y|0,g|0),{h:x,l:b}=Kr(this.Gh|0,this.Gl|0,x|0,b|0),{h:E,l:D}=Kr(this.Hh|0,this.Hl|0,E|0,D|0),this.set(n,o,i,s,a,c,l,h,p,d,y,g,x,b,E,D)}roundClean(){Ar(Qn,eo)}destroy(){Ar(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var to=_h(()=>new al);var M0=_h(()=>new Ih);var Ph=BigInt(0),kh=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 Gt(r,e,t=""){let n=un(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 Ka(r){let e=r.toString(16);return e.length&1?"0"+e:e}function j0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ph:BigInt("0x"+r)}function fs(r){return j0(or(r))}function ir(r){return xt(r),j0(or(Uint8Array.from(r).reverse()))}function cl(r,e){return Wo(r.toString(16).padStart(e*2,"0"))}function Ha(r,e){return cl(r,e).reverse()}function _e(r,e,t){let n;if(typeof e=="string")try{n=Wo(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(un(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function K0(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}function Oh(r){return Uint8Array.from(r)}var Th=r=>typeof r=="bigint"&&Ph<=r;function H0(r,e,t){return Th(r)&&Th(e)&&Th(t)&&e<=r&&r<t}function ro(r,e,t,n){if(!H0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function ul(r){let e;for(e=0;r>Ph;r>>=kh,e+=1);return e}var no=r=>(kh<<BigInt(r))-kh;function V0(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},l=(...y)=>t(s,i,...y),h=(y=n(0))=>{s=l(o(0),y),i=l(),y.length!==0&&(s=l(o(1),y),i=l())},p=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,g=[];for(;y<e;){i=l();let x=i.slice();g.push(x),y+=i.length}return Tt(...g)};return(y,g)=>{c(),h(y);let x;for(;!(x=g(p()));)h();return c(),x}}function Hr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}var Nh=()=>{throw new Error("not implemented")};function ps(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),ot=BigInt(1),zo=BigInt(2),W0=BigInt(3),q0=BigInt(4),G0=BigInt(5),RE=BigInt(7),z0=BigInt(8),LE=BigInt(9),X0=BigInt(16);function Le(r,e){let t=r%e;return t>=kt?t:e+t}function Ue(r,e,t){let n=r;for(;e-- >kt;)n*=n,n%=t;return n}function $0(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=Le(r,e),n=e,o=kt,i=ot,s=ot,a=kt;for(;t!==kt;){let l=n/t,h=n%t,p=o-s*l,d=i-a*l;n=t,t=h,o=s,i=a,s=p,a=d}if(n!==ot)throw new Error("invert: does not exist");return Le(o,e)}function Dh(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function Z0(r,e){let t=(r.ORDER+ot)/q0,n=r.pow(e,t);return Dh(r,n,e),n}function UE(r,e){let t=(r.ORDER-G0)/z0,n=r.mul(e,zo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,zo),o),a=r.mul(i,r.sub(s,r.ONE));return Dh(r,a,e),a}function ME(r){let e=zt(r),t=Y0(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+RE)/X0;return(a,c)=>{let l=a.pow(c,s),h=a.mul(l,n),p=a.mul(l,o),d=a.mul(l,i),y=a.eql(a.sqr(h),c),g=a.eql(a.sqr(p),c);l=a.cmov(l,h,y),h=a.cmov(d,p,g);let x=a.eql(a.sqr(h),c),b=a.cmov(l,h,x);return Dh(a,b,c),b}}function Y0(r){if(r<W0)throw new Error("sqrt is not defined for small field");let e=r-ot,t=0;for(;e%zo===kt;)e/=zo,t++;let n=zo,o=zt(r);for(;F0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Z0;let i=o.pow(n,e),s=(e+ot)/zo;return function(c,l){if(c.is0(l))return l;if(F0(c,l)!==1)throw new Error("Cannot find square root");let h=t,p=c.mul(c.ONE,i),d=c.pow(l,e),y=c.pow(l,s);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let g=1,x=c.sqr(d);for(;!c.eql(x,c.ONE);)if(g++,x=c.sqr(x),g===h)throw new Error("Cannot find square root");let b=ot<<BigInt(h-g-1),E=c.pow(p,b);h=g,p=c.sqr(E),d=c.mul(d,p),y=c.mul(y,E)}return y}}function jE(r){return r%q0===W0?Z0:r%z0===G0?UE:r%X0===LE?ME(r):Y0(r)}var pn=(r,e)=>(Le(r,e)&ot)===ot,KE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Rh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=KE.reduce((n,o)=>(n[o]="function",n),e);return Hr(r,t),r}function HE(r,e,t){if(t<kt)throw new Error("invalid exponent, negatives unsupported");if(t===kt)return r.ONE;if(t===ot)return e;let n=r.ONE,o=e;for(;t>kt;)t&ot&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ot;return n}function Va(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 F0(r,e){let t=(r.ORDER-ot)/zo,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 ll(r,e){e!==void 0&&$o(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function zt(r,e,t=!1,n={}){if(r<=kt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i,s=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let d=e;d.BITS&&(o=d.BITS),d.sqrt&&(i=d.sqrt),typeof d.isLE=="boolean"&&(t=d.isLE),typeof d.modFromBytes=="boolean"&&(s=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:l}=ll(r,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,p=Object.freeze({ORDER:r,isLE:t,BITS:c,BYTES:l,MASK:no(c),ZERO:kt,ONE:ot,allowedLengths:a,create:d=>Le(d,r),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return kt<=d&&d<r},is0:d=>d===kt,isValidNot0:d=>!p.is0(d)&&p.isValid(d),isOdd:d=>(d&ot)===ot,neg:d=>Le(-d,r),eql:(d,y)=>d===y,sqr:d=>Le(d*d,r),add:(d,y)=>Le(d+y,r),sub:(d,y)=>Le(d-y,r),mul:(d,y)=>Le(d*y,r),pow:(d,y)=>HE(p,d,y),div:(d,y)=>Le(d*$0(y,r),r),sqrN:d=>d*d,addN:(d,y)=>d+y,subN:(d,y)=>d-y,mulN:(d,y)=>d*y,inv:d=>$0(d,r),sqrt:i||(d=>(h||(h=jE(r)),h(p,d))),toBytes:d=>t?Ha(d,l):cl(d,l),fromBytes:(d,y=!0)=>{if(a){if(!a.includes(d.length)||d.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);let x=new Uint8Array(l);x.set(d,t?0:x.length-d.length),d=x}if(d.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+d.length);let g=t?ir(d):fs(d);if(s&&(g=Le(g,r)),!y&&!p.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:d=>Va(p,d),cmov:(d,y,g)=>g?y:d});return Object.freeze(p)}function J0(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 Lh(r){let e=J0(r);return e+Math.ceil(e/2)}function Uh(r,e,t=!1){let n=r.length,o=J0(e),i=Lh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?ir(r):fs(r),a=Le(s,e-ot)+ot;return t?Ha(a,o):cl(a,o)}var hs=BigInt(0),Xo=BigInt(1);function $a(r,e){let t=e.negate();return r?t:e}function hn(r,e){let t=Va(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function rb(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function Mh(r,e){rb(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=no(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Q0(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+=Xo);let l=e*n,h=l+Math.abs(a)-1,p=a===0,d=a<0,y=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:d,isNegF:y,offsetF:l}}function VE(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function $E(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var jh=new WeakMap,nb=new WeakMap;function Kh(r){return nb.get(r)||1}function eb(r){if(r!==hs)throw new Error("invalid wNAF")}var ds=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>hs;)t&Xo&&(n=n.add(o)),o=o.double(),t>>=Xo;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=Mh(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let l=1;l<o;l++)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=Mh(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:l,isZero:h,isNeg:p,isNegF:d,offsetF:y}=Q0(n,a,s);n=c,h?i=i.add($a(d,t[y])):o=o.add($a(p,t[l]))}return eb(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=Mh(e,this.bits);for(let s=0;s<i.windows&&n!==hs;s++){let{nextN:a,offset:c,isZero:l,isNeg:h}=Q0(n,s,i);if(n=a,!l){let p=t[c];o=o.add(h?p.negate():p)}}return eb(n),o}getPrecomputes(e,t,n){let o=jh.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),jh.set(t,o))),o}cached(e,t,n){let o=Kh(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=Kh(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){rb(t,this.bits),nb.set(e,t),jh.delete(e)}hasCache(e){return Kh(e)!==1}};function ob(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>hs||n>hs;)t&Xo&&(i=i.add(o)),n&Xo&&(s=s.add(o)),o=o.double(),t>>=Xo,n>>=Xo;return{p1:i,p2:s}}function ms(r,e,t,n){VE(t,r),$E(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=ul(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=no(c),h=new Array(Number(l)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,d=s;for(let y=p;y>=0;y-=c){h.fill(s);for(let x=0;x<i;x++){let b=n[x],E=Number(b>>BigInt(y)&l);h[E]=h[E].add(t[x])}let g=s;for(let x=h.length-1,b=s;x>0;x--)b=b.add(h[x]),g=g.add(b);if(d=d.add(g),y!==0)for(let x=0;x<c;x++)d=d.double()}return d}function tb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Rh(e),e}else return zt(r,{isLE:t})}function fl(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 l=e[c];if(!(typeof l=="bigint"&&l>hs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=tb(e.p,t.Fp,n),i=tb(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}}var oo=BigInt(0),it=BigInt(1),Hh=BigInt(2),FE=BigInt(8);function WE(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 qE(r,e={}){let t=fl("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;Hr(e,{},{uvRatio:"function"});let a=Hh<<BigInt(o.BYTES*8)-it,c=b=>n.create(b),l=e.uvRatio||((b,E)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,E))}}catch{return{isValid:!1,value:oo}}});if(!WE(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(b,E,D=!1){let I=D?it:oo;return ro("coordinate "+b,E,I,a),E}function p(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let d=ps((b,E)=>{let{X:D,Y:I,Z:V}=b,Y=b.is0();E==null&&(E=Y?FE:n.inv(V));let z=c(D*E),te=c(I*E),X=n.mul(V,E);if(Y)return{x:oo,y:it};if(X!==it)throw new Error("invZ was invalid");return{x:z,y:te}}),y=ps(b=>{let{a:E,d:D}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:I,Y:V,Z:Y,T:z}=b,te=c(I*I),X=c(V*V),T=c(Y*Y),j=c(T*T),q=c(te*E),H=c(T*c(q+X)),w=c(j+c(D*c(te*X)));if(H!==w)throw new Error("bad point: equation left != right (1)");let v=c(I*V),_=c(Y*z);if(v!==_)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(E,D,I,V){this.X=h("x",E),this.Y=h("y",D),this.Z=h("z",I,!0),this.T=h("t",V),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){if(E instanceof g)throw new Error("extended point not allowed");let{x:D,y:I}=E||{};return h("x",D),h("y",I),new g(D,I,it,c(D*I))}static fromBytes(E,D=!1){let I=n.BYTES,{a:V,d:Y}=i;E=Oh(Gt(E,I,"point")),fn(D,"zip215");let z=Oh(E),te=E[I-1];z[I-1]=te&-129;let X=ir(z),T=D?a:n.ORDER;ro("point.y",X,oo,T);let j=c(X*X),q=c(j-it),H=c(Y*j-V),{isValid:w,value:v}=l(q,H);if(!w)throw new Error("bad point: invalid y coordinate");let _=(v&it)===it,P=(te&128)!==0;if(!D&&v===oo&&P)throw new Error("bad point: x=0 and x_0=1");return P!==_&&(v=c(-v)),g.fromAffine({x:v,y:X})}static fromHex(E,D=!1){return g.fromBytes(_e("point",E),D)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,D=!0){return x.createCache(this,E),D||this.multiply(Hh),this}assertValidity(){y(this)}equals(E){p(E);let{X:D,Y:I,Z:V}=this,{X:Y,Y:z,Z:te}=E,X=c(D*te),T=c(Y*V),j=c(I*te),q=c(z*V);return X===T&&j===q}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:E}=i,{X:D,Y:I,Z:V}=this,Y=c(D*D),z=c(I*I),te=c(Hh*c(V*V)),X=c(E*Y),T=D+I,j=c(c(T*T)-Y-z),q=X+z,H=q-te,w=X-z,v=c(j*H),_=c(q*w),P=c(j*w),R=c(H*q);return new g(v,_,R,P)}add(E){p(E);let{a:D,d:I}=i,{X:V,Y,Z:z,T:te}=this,{X,Y:T,Z:j,T:q}=E,H=c(V*X),w=c(Y*T),v=c(te*I*q),_=c(z*j),P=c((V+Y)*(X+T)-H-w),R=_-v,U=_+v,k=c(w-D*H),L=c(P*R),W=c(U*k),N=c(P*k),fe=c(R*U);return new g(L,W,fe,N)}subtract(E){return this.add(E.negate())}multiply(E){if(!o.isValidNot0(E))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:D,f:I}=x.cached(this,E,V=>hn(g,V));return hn(g,[D,I])[0]}multiplyUnsafe(E,D=g.ZERO){if(!o.isValid(E))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return E===oo?g.ZERO:this.is0()||E===it?this:x.unsafe(this,E,I=>hn(g,I),D)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return x.unsafe(this,i.n).is0()}toAffine(E){return d(this,E)}clearCofactor(){return s===it?this:this.multiplyUnsafe(s)}toBytes(){let{x:E,y:D}=this.toAffine(),I=n.toBytes(D);return I[I.length-1]|=E&it?128:0,I}toHex(){return or(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(E){return hn(g,E)}static msm(E,D){return ms(g,o,E,D)}_setWindowSize(E){this.precompute(E)}toRawBytes(){return this.toBytes()}}g.BASE=new g(i.Gx,i.Gy,it,c(i.Gx*i.Gy)),g.ZERO=new g(oo,it,it,oo),g.Fp=n,g.Fn=o;let x=new ds(g,o.BITS);return g.BASE.precompute(8),g}var pl=class{constructor(e){this.ep=e}static fromBytes(e){Nh()}static fromHex(e){Nh()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return or(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}toRawBytes(){return this.toBytes()}};function GE(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');Hr(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||Yn,c=t.adjustScalarBytes||(T=>T),l=t.domain||((T,j,q)=>{if(fn(q,"phflag"),j.length||q)throw new Error("Contexts/pre-hash are not supported");return T});function h(T){return s.create(ir(T))}function p(T){let j=I.secretKey;T=_e("private key",T,j);let q=_e("hashed private key",e(T),2*j),H=c(q.slice(0,j)),w=q.slice(j,2*j),v=h(H);return{head:H,prefix:w,scalar:v}}function d(T){let{head:j,prefix:q,scalar:H}=p(T),w=o.multiply(H),v=w.toBytes();return{head:j,prefix:q,scalar:H,point:w,pointBytes:v}}function y(T){return d(T).pointBytes}function g(T=Uint8Array.of(),...j){let q=Tt(...j);return h(e(l(q,_e("context",T),!!n)))}function x(T,j,q={}){T=_e("message",T),n&&(T=n(T));let{prefix:H,scalar:w,pointBytes:v}=d(j),_=g(q.context,H,T),P=o.multiply(_).toBytes(),R=g(q.context,P,v,T),U=s.create(_+R*w);if(!s.isValid(U))throw new Error("sign failed: invalid s");let k=Tt(P,s.toBytes(U));return Gt(k,I.signature,"result")}let b={zip215:!0};function E(T,j,q,H=b){let{context:w,zip215:v}=H,_=I.signature;T=_e("signature",T,_),j=_e("message",j),q=_e("publicKey",q,I.publicKey),v!==void 0&&fn(v,"zip215"),n&&(j=n(j));let P=_/2,R=T.subarray(0,P),U=ir(T.subarray(P,_)),k,L,W;try{k=r.fromBytes(q,v),L=r.fromBytes(R,v),W=o.multiplyUnsafe(U)}catch{return!1}if(!v&&k.isSmallOrder())return!1;let N=g(w,L.toBytes(),k.toBytes(),j);return L.add(k.multiplyUnsafe(N)).subtract(W).clearCofactor().is0()}let D=i.BYTES,I={secretKey:D,publicKey:D,signature:2*D,seed:D};function V(T=a(I.seed)){return Gt(T,I.seed,"seed")}function Y(T){let j=X.randomSecretKey(T);return{secretKey:j,publicKey:y(j)}}function z(T){return un(T)&&T.length===s.BYTES}function te(T,j){try{return!!r.fromBytes(T,j)}catch{return!1}}let X={getExtendedPublicKey:d,randomSecretKey:V,isValidSecretKey:z,isValidPublicKey:te,toMontgomery(T){let{y:j}=r.fromBytes(T),q=I.publicKey,H=q===32;if(!H&&q!==57)throw new Error("only defined for 25519 and 448");let w=H?i.div(it+j,it-j):i.div(j-it,j+it);return i.toBytes(w)},toMontgomerySecret(T){let j=I.secretKey;Gt(T,j);let q=e(T.subarray(0,j));return c(q).subarray(0,j)},randomPrivateKey:V,precompute(T=8,j=r.BASE){return j.precompute(T,!1)}};return Object.freeze({keygen:Y,getPublicKey:y,sign:x,verify:E,utils:X,Point:r,lengths:I})}function zE(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=zt(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,hash:r.hash,eddsaOpts:i}}function XE(r,e){let t=e.Point;return Object.assign({},e,{ExtendedPoint:t,CURVE:r,nBitLength:t.Fn.BITS,nByteLength:t.Fn.BYTES})}function ib(r){let{CURVE:e,curveOpts:t,hash:n,eddsaOpts:o}=zE(r),i=qE(e,t),s=GE(i,n,o);return XE(r,s)}var Fa=BigInt(0),ys=BigInt(1),hl=BigInt(2);function ZE(r){return Hr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function sb(r){let e=ZE(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||Yn,l=a?255:448,h=a?32:56,p=BigInt(a?9:5),d=BigInt(a?121665:39081),y=a?hl**BigInt(254):hl**BigInt(447),g=a?BigInt(8)*hl**BigInt(251)-ys:BigInt(4)*hl**BigInt(445)-ys,x=y+g+ys,b=w=>Le(w,t),E=D(p);function D(w){return Ha(b(w),h)}function I(w){let v=_e("u coordinate",w,h);return a&&(v[31]&=127),b(ir(v))}function V(w){return ir(o(_e("scalar",w,h)))}function Y(w,v){let _=X(I(v),V(w));if(_===Fa)throw new Error("invalid private or public key received");return D(_)}function z(w){return Y(w,E)}function te(w,v,_){let P=b(w*(v-_));return v=b(v-P),_=b(_+P),{x_2:v,x_3:_}}function X(w,v){ro("u",w,Fa,t),ro("scalar",v,y,x);let _=v,P=w,R=ys,U=Fa,k=w,L=ys,W=Fa;for(let fe=BigInt(l-1);fe>=Fa;fe--){let me=_>>fe&ys;W^=me,{x_2:R,x_3:k}=te(W,R,k),{x_2:U,x_3:L}=te(W,U,L),W=me;let Q=R+U,we=b(Q*Q),Ee=R-U,Pe=b(Ee*Ee),Ae=we-Pe,Te=k+L,on=k-L,tr=b(on*Q),Wn=b(Te*Ee),Mu=tr+Wn,ts=tr-Wn;k=b(Mu*Mu),L=b(P*b(ts*ts)),R=b(we*Pe),U=b(Ae*(we+b(d*Ae)))}({x_2:R,x_3:k}=te(W,R,k)),{x_2:U,x_3:L}=te(W,U,L);let N=i(U);return b(R*N)}let T={secretKey:h,publicKey:h,seed:h},j=(w=c(h))=>(xt(w,T.seed),w);function q(w){let v=j(w);return{secretKey:v,publicKey:z(v)}}return{keygen:q,getSharedSecret:(w,v)=>Y(w,v),getPublicKey:w=>z(w),scalarMult:Y,scalarMultBase:z,utils:{randomSecretKey:j,randomPrivateKey:j},GuBytes:E.slice(),lengths:T}}var YE=BigInt(0),mn=BigInt(1),ab=BigInt(2),JE=BigInt(3),QE=BigInt(5),e_=BigInt(8),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wa={p:gs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:e_,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function lb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=gs,a=r*r%i*r%i,c=Ue(a,ab,i)*a%i,l=Ue(c,mn,i)*r%i,h=Ue(l,QE,i)*l%i,p=Ue(h,e,i)*h%i,d=Ue(p,t,i)*p%i,y=Ue(d,n,i)*d%i,g=Ue(y,o,i)*y%i,x=Ue(g,o,i)*y%i,b=Ue(x,e,i)*h%i;return{pow_p_5_8:Ue(b,ab,i)*r%i,b2:a}}function fb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Vh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Wh(r,e){let t=gs,n=Le(e*e*e,t),o=Le(n*n*e,t),i=lb(r*o).pow_p_5_8,s=Le(r*n*i,t),a=Le(e*s*s,t),c=s,l=Le(s*Vh,t),h=a===r,p=a===Le(-r,t),d=a===Le(-r*Vh,t);return h&&(s=c),(p||d)&&(s=l),pn(s,t)&&(s=Le(-s,t)),{isValid:h||p,value:s}}var dn=zt(Wa.p,{isLE:!0}),t_=zt(Wa.n,{isLE:!0}),r_={...Wa,Fp:dn,hash:M0,adjustScalarBytes:fb,uvRatio:Wh},sr=ib(r_);var qa=(()=>{let r=dn.ORDER;return sb({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=lb(e);return Le(Ue(t,JE,r)*n,r)},adjustScalarBytes:fb})})();var $h=Vh,n_=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),o_=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),i_=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),s_=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),cb=r=>Wh(mn,r),a_=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fh=r=>sr.Point.Fp.create(ir(r)&a_);function ub(r){let{d:e}=Wa,t=gs,n=E=>dn.create(E),o=n($h*r*r),i=n((o+mn)*i_),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:l}=Wh(i,a),h=n(l*r);pn(h,t)||(h=n(-h)),c||(l=h),c||(s=o);let p=n(s*(o-mn)*s_-a),d=l*l,y=n((l+l)*a),g=n(p*n_),x=n(mn-d),b=n(mn+d);return new sr.Point(n(y*b),n(x*g),n(g*b),n(y*x))}function c_(r){xt(r,64);let e=Fh(r.subarray(0,32)),t=ub(e),n=Fh(r.subarray(32,64)),o=ub(n);return new yn(t.add(o))}var yn=class r extends pl{constructor(e){super(e)}static fromAffine(e){return new r(sr.Point.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static hashToCurve(e){return c_(_e("ristrettoHash",e,64))}static fromBytes(e){xt(e,32);let{a:t,d:n}=Wa,o=gs,i=V=>dn.create(V),s=Fh(e);if(!K0(dn.toBytes(s),e)||pn(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(mn+t*a),l=i(mn-t*a),h=i(c*c),p=i(l*l),d=i(t*n*h-p),{isValid:y,value:g}=cb(i(d*p)),x=i(g*l),b=i(g*x*d),E=i((s+s)*x);pn(E,o)&&(E=i(-E));let D=i(c*b),I=i(E*D);if(!y||pn(I,o)||D===YE)throw new Error("invalid ristretto255 encoding 2");return new r(new sr.Point(E,D,mn,I))}static fromHex(e){return r.fromBytes(_e("ristrettoHex",e,32))}static msm(e,t){return ms(r,sr.Point.Fn,e,t)}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,i=gs,s=b=>dn.create(b),a=s(s(n+t)*s(n-t)),c=s(e*t),l=s(c*c),{value:h}=cb(s(a*l)),p=s(h*a),d=s(h*c),y=s(p*d*o),g;if(pn(o*y,i)){let b=s(t*$h),E=s(e*$h);e=b,t=E,g=s(p*o_)}else g=d;pn(e*y,i)&&(t=s(-t));let x=s((n-t)*g);return pn(x,i)&&(x=s(-x)),dn.toBytes(x)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=l=>dn.create(l),a=s(t*i)===s(n*o),c=s(n*i)===s(t*o);return a||c}is0(){return this.equals(r.ZERO)}};yn.BASE=new yn(sr.Point.BASE);yn.ZERO=new yn(sr.Point.ZERO);yn.Fp=dn;yn.Fn=t_;var Ga=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},za=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},dl=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var pb={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new dl("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 Rt=pb;var ml=32,Xa=64,qh=32;var bs,hb=(async()=>{try{return await Rt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function db(){let r=sr.utils.randomPrivateKey(),e=sr.getPublicKey(r);return{privateKey:h_(r,e),publicKey:e}}async function u_(r,e){let t;r.length===Xa?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 Rt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Rt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function l_(r,e){let t=r.subarray(0,qh);return sr.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function mb(r,e){return bs==null&&(bs=await hb),bs?u_(r,e):l_(r,e)}async function f_(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Rt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Rt.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 p_(r,e,t){return sr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function yb(r,e,t){return bs==null&&(bs=await hb),bs?f_(r,e,t):p_(r,e,t)}function h_(r,e){let t=new Uint8Array(Xa);for(let n=0;n<qh;n++)t[n]=r[n],t[qh+n]=e[n];return t}function xs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Za=class{type="Ed25519";raw;constructor(e){this.raw=gl(e,ml)}toMultihash(){return wr.digest(Xn(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Ve.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=yb(this.raw,t,e);return xs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},yl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=gl(e,Xa),this.publicKey=new Za(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=mb(this.raw,e);return xs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Gh(r){return r=gl(r,ml),new Za(r)}async function bb(){let{privateKey:r,publicKey:e}=db();return new yl(r,e)}function gl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new be(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var d_=Math.pow(2,7),m_=Math.pow(2,14),y_=Math.pow(2,21),zh=Math.pow(2,28),Xh=Math.pow(2,35),Zh=Math.pow(2,42),Yh=Math.pow(2,49),Be=128,wt=127;function Me(r){if(r<d_)return 1;if(r<m_)return 2;if(r<y_)return 3;if(r<zh)return 4;if(r<Xh)return 5;if(r<Zh)return 6;if(r<Yh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ws(r,e,t=0){switch(Me(r)){case 8:e[t++]=r&255|Be,r/=128;case 7:e[t++]=r&255|Be,r/=128;case 6:e[t++]=r&255|Be,r/=128;case 5:e[t++]=r&255|Be,r/=128;case 4:e[t++]=r&255|Be,r>>>=7;case 3:e[t++]=r&255|Be,r>>>=7;case 2:e[t++]=r&255|Be,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function g_(r,e,t=0){switch(Me(r)){case 8:e.set(t++,r&255|Be),r/=128;case 7:e.set(t++,r&255|Be),r/=128;case 6:e.set(t++,r&255|Be),r/=128;case 5:e.set(t++,r&255|Be),r/=128;case 4:e.set(t++,r&255|Be),r>>>=7;case 3:e.set(t++,r&255|Be),r>>>=7;case 2:e.set(t++,r&255|Be),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Jh(r,e){let t=r[e],n=0;if(n+=t&wt,t<Be||(t=r[e+1],n+=(t&wt)<<7,t<Be)||(t=r[e+2],n+=(t&wt)<<14,t<Be)||(t=r[e+3],n+=(t&wt)<<21,t<Be)||(t=r[e+4],n+=(t&wt)*zh,t<Be)||(t=r[e+5],n+=(t&wt)*Xh,t<Be)||(t=r[e+6],n+=(t&wt)*Zh,t<Be)||(t=r[e+7],n+=(t&wt)*Yh,t<Be))return n;throw new RangeError("Could not decode varint")}function b_(r,e){let t=r.get(e),n=0;if(n+=t&wt,t<Be||(t=r.get(e+1),n+=(t&wt)<<7,t<Be)||(t=r.get(e+2),n+=(t&wt)<<14,t<Be)||(t=r.get(e+3),n+=(t&wt)<<21,t<Be)||(t=r.get(e+4),n+=(t&wt)*zh,t<Be)||(t=r.get(e+5),n+=(t&wt)*Xh,t<Be)||(t=r.get(e+6),n+=(t&wt)*Zh,t<Be)||(t=r.get(e+7),n+=(t&wt)*Yh,t<Be))return n;throw new RangeError("Could not decode varint")}function bl(r,e,t=0){return e==null&&(e=rt(Me(r))),e instanceof Uint8Array?ws(r,e,t):g_(r,e,t)}function gn(r,e=0){return r instanceof Uint8Array?Jh(r,e):b_(r,e)}var Qh=new Float32Array([-0]),io=new Uint8Array(Qh.buffer);function xb(r,e,t){Qh[0]=r,e[t]=io[0],e[t+1]=io[1],e[t+2]=io[2],e[t+3]=io[3]}function wb(r,e){return io[0]=r[e],io[1]=r[e+1],io[2]=r[e+2],io[3]=r[e+3],Qh[0]}var ed=new Float64Array([-0]),vt=new Uint8Array(ed.buffer);function vb(r,e,t){ed[0]=r,e[t]=vt[0],e[t+1]=vt[1],e[t+2]=vt[2],e[t+3]=vt[3],e[t+4]=vt[4],e[t+5]=vt[5],e[t+6]=vt[6],e[t+7]=vt[7]}function Ab(r,e){return vt[0]=r[e],vt[1]=r[e+1],vt[2]=r[e+2],vt[3]=r[e+3],vt[4]=r[e+4],vt[5]=r[e+5],vt[6]=r[e+6],vt[7]=r[e+7],ed[0]}var x_=BigInt(Number.MAX_SAFE_INTEGER),w_=BigInt(Number.MIN_SAFE_INTEGER),Xt=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Zo;if(e<x_&&e>w_)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>Sb&&(o=0n,++n>Sb&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Zo;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):Zo}},Zo=new Xt(0,0);Zo.toBigInt=function(){return 0n};Zo.zzEncode=Zo.zzDecode=function(){return this};Zo.length=function(){return 1};var Sb=4294967296n;function Eb(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 _b(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 td(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 Er(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function xl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var rd=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,Er(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 Er(this,4);return xl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Er(this,4);return xl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Er(this,4);let e=wb(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Er(this,4);let e=Ab(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 Er(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return _b(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Er(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Er(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Xt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Er(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 Er(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 Er(this,8);let e=xl(this.buf,this.pos+=4),t=xl(this.buf,this.pos+=4);return new Xt(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Jh(this.buf,this.pos);return this.pos+=Me(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 nd(r){return new rd(r instanceof Uint8Array?r:r.subarray())}function _r(r,e,t){let n=nd(r);return e.decode(n,void 0,t)}function od(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return rt(s);o+s>e&&(n=rt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Yo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function id(){}var ad=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},v_=od();function A_(r){return globalThis.Buffer!=null?rt(r):v_(r)}var Qa=class{len;head;tail;states;constructor(){this.len=0,this.head=new Yo(id,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Yo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new cd((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(wl,10,Xt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Xt.fromBigInt(e);return this._push(wl,t.length(),t)}uint64Number(e){return this._push(ws,Me(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Xt.fromBigInt(e).zzEncode();return this._push(wl,t.length(),t)}sint64Number(e){let t=Xt.fromNumber(e).zzEncode();return this._push(wl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(sd,1,e?1:0)}fixed32(e){return this._push(Ja,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Xt.fromBigInt(e);return this._push(Ja,4,t.lo)._push(Ja,4,t.hi)}fixed64Number(e){let t=Xt.fromNumber(e);return this._push(Ja,4,t.lo)._push(Ja,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(xb,4,e)}double(e){return this._push(vb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(sd,1,0):this.uint32(t)._push(E_,t,e)}string(e){let t=Eb(e);return t!==0?this.uint32(t)._push(td,t,e):this._push(sd,1,0)}fork(){return this.states=new ad(this),this.head=this.tail=new Yo(id,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 Yo(id,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=A_(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function sd(r,e,t){e[t]=r&255}function S_(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var cd=class extends Yo{next;constructor(e,t){super(S_,e,t),this.next=void 0}};function wl(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Ja(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 E_(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Qa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(__,e,r),this},Qa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(C_,e,r),this});function __(r,e,t){e.set(r,t)}function C_(r,e,t){r.length<40?td(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(pe(r),t)}function ud(){return new Qa}function Cr(r,e){let t=ud();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var vs;(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"})(vs||(vs={}));function vl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Jo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return vl("enum",vs.VARINT,t,n)}function Br(r,e){return vl("message",vs.LENGTH_DELIMITED,r,e)}var ec=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Xe;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Xe||(Xe={}));var ld;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ld||(ld={}));(function(r){r.codec=()=>Jo(ld)})(Xe||(Xe={}));var Vr;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Xe.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=Xe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Cr(t,r.codec()),r.decode=(t,n)=>_r(t,r.codec(),n)})(Vr||(Vr={}));var fd;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Xe.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=Xe.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Cr(t,r.codec()),r.decode=(t,n)=>_r(t,r.codec(),n)})(fd||(fd={}));var rc={};bt(rc,{MAX_RSA_KEY_SIZE:()=>pd,generateRSAKeyPair:()=>vd,jwkToJWKKeyPair:()=>Pb,jwkToPkcs1:()=>k_,jwkToPkix:()=>yd,jwkToRSAPrivateKey:()=>wd,pkcs1MessageToJwk:()=>dd,pkcs1MessageToRSAPrivateKey:()=>gd,pkcs1ToJwk:()=>T_,pkcs1ToRSAPrivateKey:()=>kb,pkixMessageToJwk:()=>md,pkixMessageToRSAPublicKey:()=>xd,pkixToJwk:()=>P_,pkixToRSAPublicKey:()=>bd});var Al=to;var As=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=rc.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return Ve.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}verify(e,t,n){return Tb(this.jwk,t,e,n)}},tc=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=rc.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}sign(e,t){return Ib(this.jwk,e,t)}};var pd=8192,hd=18,B_=1062,I_=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function T_(r){let e=an(r);return dd(e)}function dd(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 k_(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 be("JWK was missing components");return vr([It(Uint8Array.from([0])),It(pe(r.n,"base64url")),It(pe(r.e,"base64url")),It(pe(r.d,"base64url")),It(pe(r.p,"base64url")),It(pe(r.q,"base64url")),It(pe(r.dp,"base64url")),It(pe(r.dq,"base64url")),It(pe(r.qi,"base64url"))]).subarray()}function P_(r){let e=an(r,{offset:0});return md(e)}function md(r){let e=an(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function yd(r){if(r.n==null||r.e==null)throw new be("JWK was missing components");return vr([I_,La(vr([It(pe(r.n,"base64url")),It(pe(r.e,"base64url"))]))]).subarray()}function kb(r){let e=an(r);return gd(e)}function gd(r){let e=dd(r);return wd(e)}function bd(r,e){if(r.byteLength>=B_)throw new rs("Key size is too large");let t=an(r,{offset:0});return xd(t,r,e)}function xd(r,e,t){let n=md(r);if(t==null){let o=Al(Vr.encode({Type:Xe.RSA,Data:e}));t=Ct(hd,o)}return new As(n,t)}function wd(r){if(Nb(r)>pd)throw new be("Key size is too large");let e=Pb(r),t=Al(Vr.encode({Type:Xe.RSA,Data:yd(e.publicKey)})),n=Ct(hd,t);return new tc(e.privateKey,new As(e.publicKey,n))}async function vd(r){if(r>pd)throw new be("Key size is too large");let e=await Ob(r),t=Al(Vr.encode({Type:Xe.RSA,Data:yd(e.publicKey)})),n=Ct(hd,t);return new tc(e.privateKey,new As(e.publicKey,n))}function Pb(r){if(r==null)throw new be("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ob(r,e){let t=await Rt.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 O_(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Ib(r,e,t){let n=await Rt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Rt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Tb(r,e,t,n){let o=await Rt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Rt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function O_(r,e){if(r.privateKey==null||r.publicKey==null)throw new be("Private and public key are required");let t=await Promise.all([Rt.get().subtle.exportKey("jwk",r.privateKey),Rt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function Nb(r){if(r.kty!=="RSA")throw new be("invalid key type");if(r.n==null)throw new be("invalid key modulus");return pe(r.n,"base64url").length*8}var Sl=class extends us{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Fo(e);let n=Zn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Ar(i)}update(e){return ls(this),this.iHash.update(e),this}digestInto(e){ls(this),xt(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ss=(r,e,t)=>new Sl(r,e).update(t).digest();Ss.create=(r,e)=>new Sl(r,e);var Db=(r,e)=>(r+(r>=0?e:-e)/Rb)/e;function N_(r,e,t){let[[n,o],[i,s]]=e,a=Db(s*r,t),c=Db(-o*r,t),l=r-a*n-c*i,h=-a*o-c*s,p=l<xn,d=h<xn;p&&(l=-l),d&&(h=-h);let y=no(Math.ceil(ul(t)/2))+_s;if(l<xn||l>=y||h<xn||h>=y)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:p,k1:l,k2neg:d,k2:h}}function Sd(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Ad(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&&Sd(t.format),t}var Ed=class extends Error{constructor(e=""){super(e)}},bn={Err:Ed,_tlv:{encode:(r,e)=>{let{Err:t}=bn;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=Ka(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Ka(o.length/2|128):"";return Ka(r)+i+o+e},decode(r,e){let{Err:t}=bn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of l)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=bn;if(r<xn)throw new e("integer: negative integers are not allowed");let t=Ka(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}=bn;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 fs(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=bn,o=_e("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=bn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},xn=BigInt(0),_s=BigInt(1),Rb=BigInt(2),El=BigInt(3),D_=BigInt(4);function Es(r,e){let{BYTES:t}=r,n;if(typeof e=="bigint")n=e;else{let o=_e("private key",e);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function R_(r,e={}){let t=fl("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;Hr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});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 l=Ub(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(H,w,v){let{x:_,y:P}=w.toAffine(),R=n.toBytes(_);if(fn(v,"isCompressed"),v){h();let U=!n.isOdd(P);return Tt(Lb(U),R)}else return Tt(Uint8Array.of(4),R,n.toBytes(P))}function d(H){Gt(H,void 0,"Point");let{publicKey:w,publicKeyUncompressed:v}=l,_=H.length,P=H[0],R=H.subarray(1);if(_===w&&(P===2||P===3)){let U=n.fromBytes(R);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let k=x(U),L;try{L=n.sqrt(k)}catch(fe){let me=fe instanceof Error?": "+fe.message:"";throw new Error("bad point: is not on curve, sqrt error"+me)}h();let W=n.isOdd(L);return(P&1)===1!==W&&(L=n.neg(L)),{x:U,y:L}}else if(_===v&&P===4){let U=n.BYTES,k=n.fromBytes(R.subarray(0,U)),L=n.fromBytes(R.subarray(U,U*2));if(!b(k,L))throw new Error("bad point: is not on curve");return{x:k,y:L}}else throw new Error(`bad point: got length ${_}, expected compressed=${w} or uncompressed=${v}`)}let y=e.toBytes||p,g=e.fromBytes||d;function x(H){let w=n.sqr(H),v=n.mul(w,H);return n.add(n.add(v,n.mul(H,i.a)),i.b)}function b(H,w){let v=n.sqr(w),_=x(H);return n.eql(v,_)}if(!b(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(i.a,El),D_),D=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(E,D)))throw new Error("bad curve params: a or b");function I(H,w,v=!1){if(!n.isValid(w)||v&&n.is0(w))throw new Error(`bad point coordinate ${H}`);return w}function V(H){if(!(H instanceof T))throw new Error("ProjectivePoint expected")}function Y(H){if(!c||!c.basises)throw new Error("no endo");return N_(H,c.basises,o.ORDER)}let z=ps((H,w)=>{let{X:v,Y:_,Z:P}=H;if(n.eql(P,n.ONE))return{x:v,y:_};let R=H.is0();w==null&&(w=R?n.ONE:n.inv(P));let U=n.mul(v,w),k=n.mul(_,w),L=n.mul(P,w);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:U,y:k}}),te=ps(H=>{if(H.is0()){if(e.allowInfinityPoint&&!n.is0(H.Y))return;throw new Error("bad point: ZERO")}let{x:w,y:v}=H.toAffine();if(!n.isValid(w)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!b(w,v))throw new Error("bad point: equation left != right");if(!H.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function X(H,w,v,_,P){return v=new T(n.mul(v.X,H),v.Y,v.Z),w=$a(_,w),v=$a(P,v),w.add(v)}class T{constructor(w,v,_){this.X=I("x",w),this.Y=I("y",v,!0),this.Z=I("z",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){let{x:v,y:_}=w||{};if(!w||!n.isValid(v)||!n.isValid(_))throw new Error("invalid affine point");if(w instanceof T)throw new Error("projective point not allowed");return n.is0(v)&&n.is0(_)?T.ZERO:new T(v,_,n.ONE)}static fromBytes(w){let v=T.fromAffine(g(Gt(w,void 0,"point")));return v.assertValidity(),v}static fromHex(w){return T.fromBytes(_e("pointHex",w))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,v=!0){return q.createCache(this,w),v||this.multiply(El),this}assertValidity(){te(this)}hasEvenY(){let{y:w}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(w)}equals(w){V(w);let{X:v,Y:_,Z:P}=this,{X:R,Y:U,Z:k}=w,L=n.eql(n.mul(v,k),n.mul(R,P)),W=n.eql(n.mul(_,k),n.mul(U,P));return L&&W}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:w,b:v}=i,_=n.mul(v,El),{X:P,Y:R,Z:U}=this,k=n.ZERO,L=n.ZERO,W=n.ZERO,N=n.mul(P,P),fe=n.mul(R,R),me=n.mul(U,U),Q=n.mul(P,R);return Q=n.add(Q,Q),W=n.mul(P,U),W=n.add(W,W),k=n.mul(w,W),L=n.mul(_,me),L=n.add(k,L),k=n.sub(fe,L),L=n.add(fe,L),L=n.mul(k,L),k=n.mul(Q,k),W=n.mul(_,W),me=n.mul(w,me),Q=n.sub(N,me),Q=n.mul(w,Q),Q=n.add(Q,W),W=n.add(N,N),N=n.add(W,N),N=n.add(N,me),N=n.mul(N,Q),L=n.add(L,N),me=n.mul(R,U),me=n.add(me,me),N=n.mul(me,Q),k=n.sub(k,N),W=n.mul(me,fe),W=n.add(W,W),W=n.add(W,W),new T(k,L,W)}add(w){V(w);let{X:v,Y:_,Z:P}=this,{X:R,Y:U,Z:k}=w,L=n.ZERO,W=n.ZERO,N=n.ZERO,fe=i.a,me=n.mul(i.b,El),Q=n.mul(v,R),we=n.mul(_,U),Ee=n.mul(P,k),Pe=n.add(v,_),Ae=n.add(R,U);Pe=n.mul(Pe,Ae),Ae=n.add(Q,we),Pe=n.sub(Pe,Ae),Ae=n.add(v,P);let Te=n.add(R,k);return Ae=n.mul(Ae,Te),Te=n.add(Q,Ee),Ae=n.sub(Ae,Te),Te=n.add(_,P),L=n.add(U,k),Te=n.mul(Te,L),L=n.add(we,Ee),Te=n.sub(Te,L),N=n.mul(fe,Ae),L=n.mul(me,Ee),N=n.add(L,N),L=n.sub(we,N),N=n.add(we,N),W=n.mul(L,N),we=n.add(Q,Q),we=n.add(we,Q),Ee=n.mul(fe,Ee),Ae=n.mul(me,Ae),we=n.add(we,Ee),Ee=n.sub(Q,Ee),Ee=n.mul(fe,Ee),Ae=n.add(Ae,Ee),Q=n.mul(we,Ae),W=n.add(W,Q),Q=n.mul(Te,Ae),L=n.mul(Pe,L),L=n.sub(L,Q),Q=n.mul(Pe,we),N=n.mul(Te,N),N=n.add(N,Q),new T(L,W,N)}subtract(w){return this.add(w.negate())}is0(){return this.equals(T.ZERO)}multiply(w){let{endo:v}=e;if(!o.isValidNot0(w))throw new Error("invalid scalar: out of range");let _,P,R=U=>q.cached(this,U,k=>hn(T,k));if(v){let{k1neg:U,k1:k,k2neg:L,k2:W}=Y(w),{p:N,f:fe}=R(k),{p:me,f:Q}=R(W);P=fe.add(Q),_=X(v.beta,N,me,U,L)}else{let{p:U,f:k}=R(w);_=U,P=k}return hn(T,[_,P])[0]}multiplyUnsafe(w){let{endo:v}=e,_=this;if(!o.isValid(w))throw new Error("invalid scalar: out of range");if(w===xn||_.is0())return T.ZERO;if(w===_s)return _;if(q.hasCache(this))return this.multiply(w);if(v){let{k1neg:P,k1:R,k2neg:U,k2:k}=Y(w),{p1:L,p2:W}=ob(T,_,R,k);return X(v.beta,L,W,P,U)}else return q.unsafe(_,w)}multiplyAndAddUnsafe(w,v,_){let P=this.multiplyUnsafe(v).add(w.multiplyUnsafe(_));return P.is0()?void 0:P}toAffine(w){return z(this,w)}isTorsionFree(){let{isTorsionFree:w}=e;return s===_s?!0:w?w(T,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:w}=e;return s===_s?this:w?w(T,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(w=!0){return fn(w,"isCompressed"),this.assertValidity(),y(T,this,w)}toHex(w=!0){return or(this.toBytes(w))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(w=!0){return this.toBytes(w)}_setWindowSize(w){this.precompute(w)}static normalizeZ(w){return hn(T,w)}static msm(w,v){return ms(T,o,w,v)}static fromPrivateKey(w){return T.BASE.multiply(Es(o,w))}}T.BASE=new T(i.Gx,i.Gy,n.ONE),T.ZERO=new T(n.ZERO,n.ONE,n.ZERO),T.Fp=n,T.Fn=o;let j=o.BITS,q=new ds(T,e.endo?Math.ceil(j/2):j);return T.BASE.precompute(8),T}function Lb(r){return Uint8Array.of(r?2:3)}function Ub(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function L_(r,e={}){let{Fn:t}=r,n=e.randomBytes||Yn,o=Object.assign(Ub(r.Fp,t),{seed:Lh(t.ORDER)});function i(y){try{return!!Es(t,y)}catch{return!1}}function s(y,g){let{publicKey:x,publicKeyUncompressed:b}=o;try{let E=y.length;return g===!0&&E!==x||g===!1&&E!==b?!1:!!r.fromBytes(y)}catch{return!1}}function a(y=n(o.seed)){return Uh(Gt(y,o.seed,"seed"),t.ORDER)}function c(y,g=!0){return r.BASE.multiply(Es(t,y)).toBytes(g)}function l(y){let g=a(y);return{secretKey:g,publicKey:c(g)}}function h(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let{secretKey:g,publicKey:x,publicKeyUncompressed:b}=o;if(t.allowedLengths||g===x)return;let E=_e("key",y).length;return E===x||E===b}function p(y,g,x=!0){if(h(y)===!0)throw new Error("first arg must be private key");if(h(g)===!1)throw new Error("second arg must be public key");let b=Es(t,y);return r.fromHex(g).multiply(b).toBytes(x)}return Object.freeze({getPublicKey:c,getSharedSecret:p,keygen:l,Point:r,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:y=>Es(t,y),precompute(y=8,g=r.BASE){return g.precompute(y,!1)}},lengths:o})}function U_(r,e,t={}){Fo(e),Hr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Yn,o=t.hmac||((v,..._)=>Ss(e,v,Tt(..._))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:l,getPublicKey:h,getSharedSecret:p,utils:d,lengths:y}=L_(r,t),g={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},x="compact";function b(v){let _=a>>_s;return v>_}function E(v,_){if(!s.isValidNot0(_))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return _}function D(v,_){Sd(_);let P=y.signature,R=_==="compact"?P:_==="recovered"?P+1:void 0;return Gt(v,R,`${_} signature`)}class I{constructor(_,P,R){this.r=E("r",_),this.s=E("s",P),R!=null&&(this.recovery=R),Object.freeze(this)}static fromBytes(_,P=x){D(_,P);let R;if(P==="der"){let{r:W,s:N}=bn.toSig(Gt(_));return new I(W,N)}P==="recovered"&&(R=_[0],P="compact",_=_.subarray(1));let U=s.BYTES,k=_.subarray(0,U),L=_.subarray(U,U*2);return new I(s.fromBytes(k),s.fromBytes(L),R)}static fromHex(_,P){return this.fromBytes(Wo(_),P)}addRecoveryBit(_){return new I(this.r,this.s,_)}recoverPublicKey(_){let P=i.ORDER,{r:R,s:U,recovery:k}=this;if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");if(a*Rb<P&&k>1)throw new Error("recovery id is ambiguous for h>1 curve");let W=k===2||k===3?R+a:R;if(!i.isValid(W))throw new Error("recovery id 2 or 3 invalid");let N=i.toBytes(W),fe=r.fromBytes(Tt(Lb((k&1)===0),N)),me=s.inv(W),Q=Y(_e("msgHash",_)),we=s.create(-Q*me),Ee=s.create(U*me),Pe=r.BASE.multiplyUnsafe(we).add(fe.multiplyUnsafe(Ee));if(Pe.is0())throw new Error("point at infinify");return Pe.assertValidity(),Pe}hasHighS(){return b(this.s)}toBytes(_=x){if(Sd(_),_==="der")return Wo(bn.hexFromSig(this));let P=s.toBytes(this.r),R=s.toBytes(this.s);if(_==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Tt(Uint8Array.of(this.recovery),P,R)}return Tt(P,R)}toHex(_){return or(this.toBytes(_))}assertValidity(){}static fromCompact(_){return I.fromBytes(_e("sig",_),"compact")}static fromDER(_){return I.fromBytes(_e("sig",_),"der")}normalizeS(){return this.hasHighS()?new I(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return or(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return or(this.toBytes("compact"))}}let V=t.bits2int||function(_){if(_.length>8192)throw new Error("input is too large");let P=fs(_),R=_.length*8-c;return R>0?P>>BigInt(R):P},Y=t.bits2int_modN||function(_){return s.create(V(_))},z=no(c);function te(v){return ro("num < 2^"+c,v,xn,z),s.toBytes(v)}function X(v,_){return Gt(v,void 0,"message"),_?Gt(e(v),void 0,"prehashed message"):v}function T(v,_,P){if(["recovered","canonical"].some(we=>we in P))throw new Error("sign() legacy options not supported");let{lowS:R,prehash:U,extraEntropy:k}=Ad(P,g);v=X(v,U);let L=Y(v),W=Es(s,_),N=[te(W),te(L)];if(k!=null&&k!==!1){let we=k===!0?n(y.secretKey):k;N.push(_e("extraEntropy",we))}let fe=Tt(...N),me=L;function Q(we){let Ee=V(we);if(!s.isValidNot0(Ee))return;let Pe=s.inv(Ee),Ae=r.BASE.multiply(Ee).toAffine(),Te=s.create(Ae.x);if(Te===xn)return;let on=s.create(Pe*s.create(me+Te*W));if(on===xn)return;let tr=(Ae.x===Te?0:2)|Number(Ae.y&_s),Wn=on;return R&&b(on)&&(Wn=s.neg(on),tr^=1),new I(Te,Wn,tr)}return{seed:fe,k2sig:Q}}function j(v,_,P={}){v=_e("message",v);let{seed:R,k2sig:U}=T(v,_,P);return V0(e.outputLen,s.BYTES,o)(R,U)}function q(v){let _,P=typeof v=="string"||un(v),R=!P&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!P&&!R)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(R)_=new I(v.r,v.s);else if(P){try{_=I.fromBytes(_e("sig",v),"der")}catch(U){if(!(U instanceof bn.Err))throw U}if(!_)try{_=I.fromBytes(_e("sig",v),"compact")}catch{return!1}}return _||!1}function H(v,_,P,R={}){let{lowS:U,prehash:k,format:L}=Ad(R,g);if(P=_e("publicKey",P),_=X(_e("message",_),k),"strict"in R)throw new Error("options.strict was renamed to lowS");let W=L===void 0?q(v):I.fromBytes(_e("sig",v),L);if(W===!1)return!1;try{let N=r.fromBytes(P);if(U&&W.hasHighS())return!1;let{r:fe,s:me}=W,Q=Y(_),we=s.inv(me),Ee=s.create(Q*we),Pe=s.create(fe*we),Ae=r.BASE.multiplyUnsafe(Ee).add(N.multiplyUnsafe(Pe));return Ae.is0()?!1:s.create(Ae.x)===fe}catch{return!1}}function w(v,_,P={}){let{prehash:R}=Ad(P,g);return _=X(_,R),I.fromBytes(v,"recovered").recoverPublicKey(_).toBytes()}return Object.freeze({keygen:l,getPublicKey:h,getSharedSecret:p,utils:d,lengths:y,Point:r,sign:j,verify:H,recoverPublicKey:w,Signature:I,hash:e})}function M_(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=zt(e.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes:r.wrapPrivateKey}),i={Fp:t,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:i}}function j_(r){let{CURVE:e,curveOpts:t}=M_(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,hash:r.hash,ecdsaOpts:n}}function K_(r,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},r,ll(t.Fn.ORDER,t.Fn.BITS))})}function Mb(r){let{CURVE:e,curveOpts:t,hash:n,ecdsaOpts:o}=j_(r),i=R_(e,t),s=U_(i,n,o);return K_(r,s)}function jb(r,e){let t=n=>Mb({...r,hash:n});return{...t(e),create:t}}var Cd={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},H_={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Kb=BigInt(2);function V_(r){let e=Cd.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,h=l*l*r%e,p=Ue(h,t,e)*h%e,d=Ue(p,t,e)*h%e,y=Ue(d,Kb,e)*l%e,g=Ue(y,o,e)*y%e,x=Ue(g,i,e)*g%e,b=Ue(x,a,e)*x%e,E=Ue(b,c,e)*b%e,D=Ue(E,a,e)*x%e,I=Ue(D,t,e)*h%e,V=Ue(I,s,e)*g%e,Y=Ue(V,n,e)*l%e,z=Ue(Y,Kb,e);if(!_d.eql(_d.sqr(z),r))throw new Error("Cannot find square root");return z}var _d=zt(Cd.p,{sqrt:V_}),Ir=jb({...Cd,Fp:_d,lowS:!0,endo:H_},to);function Hb(r,e,t){let n=nr.digest(e instanceof Uint8Array?e:e.subarray());if(xs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Ir.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ga(String(o))});try{return Ir.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Ga(String(o))}}function Vb(r,e,t,n){let o=nr.digest(t instanceof Uint8Array?t:t.subarray());if(xs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ir.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new za(String(i))});try{return n?.signal?.throwIfAborted(),Ir.verify(e,o.digest,r)}catch(i){throw new za(String(i))}}var nc=class{type="secp256k1";raw;_key;constructor(e){this._key=Wb(e),this.raw=$b(this._key)}toMultihash(){return wr.digest(Xn(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Ve.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}verify(e,t,n){return Vb(this._key,t,e,n)}},_l=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=Fb(e),this.publicKey=new nc(t??qb(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:$e(this.raw,e.raw)}sign(e,t){return Hb(this.raw,e,t)}};function Bd(r){return new nc(r)}async function Gb(){let r=$_();return new _l(r)}function $b(r){return Ir.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Fb(r){try{return Ir.getPublicKey(r,!0),r}catch(e){throw new Ia(String(e))}}function Wb(r){try{return Ir.ProjectivePoint.fromHex(r),r}catch(e){throw new rs(String(e))}}function qb(r){try{return Ir.getPublicKey(r,!0)}catch(e){throw new Ia(String(e))}}function $_(){return Ir.utils.randomPrivateKey()}async function zb(r,e){if(r==="Ed25519")return bb();if(r==="secp256k1")return Gb();if(r==="RSA")return vd(F_(e));if(r==="ECDSA")return S0(W_(e));throw new qn}function oc(r,e){let{Type:t,Data:n}=Vr.decode(r),o=n??new Uint8Array;switch(t){case Xe.RSA:return bd(o,e);case Xe.Ed25519:return Gh(o);case Xe.secp256k1:return Bd(o);case Xe.ECDSA:return Sh(o);default:throw new qn}}function Xb(r){let{Type:e,Data:t}=Vr.decode(r.digest),n=t??new Uint8Array;switch(e){case Xe.Ed25519:return Gh(n);case Xe.secp256k1:return Bd(n);case Xe.ECDSA:return Sh(n);default:throw new qn}}function Xn(r){return Vr.encode({Type:Xe[r.type],Data:r.raw})}function F_(r){return r==null?2048:parseInt(r,10)}function W_(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 be("Unsupported curve, should be P-256, P-384 or P-521")}async function Cl(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 be("Only RSA and ECDSA keys are supported")}var Zb=Symbol.for("nodejs.util.inspect.custom"),q_=114,ic=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zp]=!0;toString(){return this.string==null&&(this.string=Ve.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(q_,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return $e(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return $e(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Zb](){return`PeerId(${this.toString()})`}},sc=class extends ic{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},ac=class extends ic{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},cc=class extends ic{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},G_=2336,uc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=wr.digest(pe(this.url))}[Zb](){return`PeerId(${this.url})`}[Zp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(G_,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var z_=114,Yb=2336;function Cs(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=cs(Ve.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return X_(et.parse(r));if(e==null)throw new be('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=cs(e.decode(r))}return Jb(t)}function Id(r){if(r.type==="Ed25519")return new ac({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new cc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sc({multihash:r.toCID().multihash,publicKey:r});throw new qn}function Jb(r){if(Y_(r))return new sc({multihash:r});if(Z_(r))try{let e=Xb(r);if(e.type==="Ed25519")return new ac({multihash:r,publicKey:e});if(e.type==="secp256k1")return new cc({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new uc(new URL(t))}throw new Gu("Supplied PeerID Multihash is invalid")}function X_(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==z_&&r.code!==Yb)throw new qu("Supplied PeerID CID is invalid");if(r.code===Yb){let e=ue(r.multihash.digest);return new uc(new URL(e))}return Jb(r.multihash)}function Z_(r){return r.code===wr.code}function Y_(r){return r.code===nr.code}var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},wn=class extends Error{static name="ValidationError";name="ValidationError"},Bl=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Il=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Tl=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let d=Number.parseInt(p,e);if(!Number.isNaN(d))return d});if(h===void 0)break;if(i*=e,i+=h,i>l||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var J_=45,Q_=15,kl=new Tl;function Qb(r){if(!(r.length>Q_))return kl.new(r).parseWith(()=>kl.readIPv4Addr())}function ex(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>J_))return kl.new(r).parseWith(()=>kl.readIPv6Addr())}function Pl(r){return!!Qb(r)}function tx(r){return!!ex(r)}function kd(r){return e=>ue(e,r)}function Pd(r){return e=>pe(e,r)}function Bs(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function Qo(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function rx(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=pe(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Qo(n);return Bt([t,o],t.length+o.length)}function nx(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=zn.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=Qo(n);return Bt([t,o],t.length+o.length)}function Od(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 Nd=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 ct("Invalid byte value in IP address");e[n]=o}),e},ox=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=Pl(t[n]),s;i&&(s=Nd(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 ct("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},ix=function(r){if(r.byteLength!==4)throw new ct("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},sx=function(r){if(r.byteLength!==16)throw new ct("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 ct(`Invalid IPv6 address "${t}"`)}};function ax(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}}var Td=Object.values(Ko).map(r=>r.decoder),e2=(function(){let r=Td[0].or(Td[1]);return Td.slice(2).forEach(e=>r=r.or(e)),r})();function cx(r){return e2.decode(r)}function ux(r){return e=>r.encoder.encode(e)}function t2(r){if(parseInt(r).toString()!==r)throw new wn("Value must be an integer")}function r2(r){if(r<0)throw new wn("Value must be a positive integer, or zero")}function n2(r){return e=>{if(e>r)throw new wn(`Value must be smaller than or equal to ${r}`)}}function o2(...r){return e=>{for(let t of r)t(e)}}var lc=o2(t2,r2,n2(65535));var st=-1,Dd=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 Il(`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)}))}},vn=new Dd,x2=[{code:4,name:"ip4",size:32,valueToBytes:Nd,bytesToValue:ix,validate:r=>{if(!Pl(r))throw new wn(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Qo,bytesToValue:Bs,validate:lc},{code:273,name:"udp",size:16,valueToBytes:Qo,bytesToValue:Bs,validate:lc},{code:33,name:"dccp",size:16,valueToBytes:Qo,bytesToValue:Bs,validate:lc},{code:41,name:"ip6",size:128,valueToBytes:ox,bytesToValue:sx,stringToValue:ax,validate:r=>{if(!tx(r))throw new wn(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:kd("base10"),valueToBytes:Pd("base10")},{code:53,name:"dns",size:st},{code:54,name:"dns4",size:st},{code:55,name:"dns6",size:st},{code:56,name:"dnsaddr",size:st},{code:132,name:"sctp",size:16,valueToBytes:Qo,bytesToValue:Bs,validate:lc},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:kd("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Pd("base58btc")(r):et.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Od,valueToBytes:rx},{code:445,name:"onion3",size:296,bytesToValue:Od,valueToBytes:nx},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:ux(jo),valueToBytes:cx},{code:480,name:"http"},{code:481,name:"http-path",size:st,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:st}];x2.forEach(r=>{vn.addProtocol(r)});function lx(r){let e=[],t=0;for(;t<r.length;){let n=gn(r,t),o=vn.getProtocol(n),i=Me(n),s=w2(o,r,t+i),a=0;s>0&&o.size===st&&(a=Me(s));let c=i+a+s,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let h=t+i+a,p=r.subarray(h,h+s);l.value=o.bytesToValue?.(p)??ue(p)}e.push(l),t+=c}return e}function fx(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=vn.getProtocol(n.code),i=Me(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??pe(n.value),a=s.byteLength,o.size===st&&(c=Me(a)));let l=new Uint8Array(i+c+a),h=0;ws(n.code,l,h),h+=i,s!=null&&(o.size===st&&(ws(a,l,h),h+=c),l.set(s,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return Bt(t,e)}function px(r){if(r.charAt(0)!=="/")throw new ct('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=vn.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 ct(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return e}function hx(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=vn.getProtocol(e.code);if(t==null)throw new ct(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function w2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:gn(e,t)}var v2=Symbol.for("nodejs.util.inspect.custom"),Yd=Symbol.for("@multiformats/multiaddr");function A2(r){if(r==null&&(r="/"),dx(r))return r.getComponents();if(r instanceof Uint8Array)return lx(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),px(r);if(Array.isArray(r))return r;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Rl=class r{[Yd]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=A2(e),t.validate!==!1&&S2(this)}get bytes(){return this.#r==null&&(this.#r=fx(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=hx(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 Bl(`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 $e(this.bytes,e.bytes)}[v2](){return`Multiaddr(${this.toString()})`}};function S2(r){r.getComponents().forEach(e=>{let t=vn.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function dx(r){return!!r?.[Yd]}function Ps(r){return new Rl(r)}var Oe=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)}}),mx=r=>({match:e=>r.match(e)===!1?e:!1}),ve=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),At=(...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}}),Ie=(...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 E2=ce(421),f5=Ne(E2),Ul=ce(54),Ml=ce(55),jl=ce(56),Qd=ce(53),p5=Ne(Ul,ve(ce(421))),h5=Ne(Ml,ve(ce(421))),d5=Ne(jl,ve(ce(421))),m5=Ne(At(Qd,jl,Ul,Ml),ve(ce(421))),yx=Ie(ce(4),ve(ce(43))),gx=Ie(ve(ce(42)),ce(41),ve(ce(43))),em=At(yx,gx),ri=At(em,Qd,Ul,Ml,jl),y5=Ne(At(em,Ie(At(Qd,jl,Ul,Ml),ve(ce(421))))),g5=Ne(yx),b5=Ne(gx),x5=Ne(em),tm=Ie(ri,ce(6)),fc=Ie(ri,ce(273)),w5=Ne(Ie(tm,ve(ce(421)))),v5=Ne(fc),rm=Ie(fc,Oe(460),ve(ce(421))),Kl=Ie(fc,Oe(461),ve(ce(421))),_2=At(rm,Kl),A5=Ne(rm),S5=Ne(Kl),Jd=At(ri,tm,fc,rm,Kl),bx=At(Ie(Jd,Oe(477),ve(ce(421)))),E5=Ne(bx),xx=At(Ie(Jd,Oe(478),ve(ce(421))),Ie(Jd,Oe(448),ve(ce(449)),Oe(477),ve(ce(421)))),_5=Ne(xx),wx=Ie(fc,Oe(280),ve(ce(466)),ve(ce(466)),ve(ce(421))),vx=Ne(wx),Ax=Ie(Kl,Oe(465),ve(ce(466)),ve(ce(466)),ve(ce(421))),C5=Ne(Ax),Ll=At(bx,xx,Ie(tm,ve(ce(421))),Ie(_2,ve(ce(421))),Ie(ri,ve(ce(421))),wx,Ax,ce(421)),Sx=Ne(Ll),C2=Ie(ve(Ll),Oe(290),mx(Oe(281)),ve(ce(421))),B5=Ne(C2),B2=At(Ie(Ll,Oe(290),Oe(281),ve(ce(421))),Ie(Ll,Oe(281),ve(ce(421))),Ie(Oe(281),ve(ce(421)))),Ex=Ne(B2),I2=At(Ie(ri,ce(6),Oe(480),ve(ce(421))),Ie(ri,Oe(480),ve(ce(421)))),I5=Ne(I2),T2=Ie(ri,At(Ie(ce(6,"443"),Oe(480)),Ie(ce(6),Oe(443)),Ie(ce(6),Oe(448),Oe(480)),Ie(Oe(448),Oe(480)),Oe(448),Oe(443)),ve(ce(421))),T5=Ne(T2),k2=At(Ie(ce(777),ve(ce(421)))),k5=Ne(k2),P2=At(Ie(ce(400),ve(ce(421)))),P5=Ne(P2);var St;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),(function(o){o.codec=()=>Jo(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Cr(o,r.codec()),r.decode=(o,i)=>_r(o,r.codec(),i)})(St||(St={}));var _x=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],nm=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Cx="libp2p+webrtc+v1/",Bx=2*1024*1024,Os=16*1024;function O2(r=Os){let e=Me(r-Me(r)),t=1+Me(Object.keys(St.Flag).length-1),n=1,o=r-e-t-n,i=Me(o);return e+t+n+i}var Ix=O2();var om="/webrtc",pc="/webrtc-signaling/0.0.1",Tx="/libp2p/webrtc-direct/certificate",kx="webrtc-direct-certificate-private-key";var Px=12096e5,im=864e5;function sm(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 be(`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 Hl(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Vl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ns=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Vl(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new Vl(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var am=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ds(r={}){return N2(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 N2(r,e){e=e??{};let t=e.onEnd,n=new Ns,o,i,s,a=Hl(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((b,E)=>{i=D=>{i=null,n.push(D);try{b(r(n))}catch(I){E(I)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Hl()})}},l=b=>i!=null?i(b):(n.push(b),o),h=b=>(n=new Ns,i!=null?i({error:b}):(n.push({error:b}),o)),p=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},d=b=>s?o:(s=!0,b!=null?h(b):l({done:!0})),y=()=>(n=new Ns,d(),{done:!0}),g=b=>(d(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:y,throw:g,push:p,end:d,get readableLength(){return n.size},onEmpty:async b=>{let E=b?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let D,I;E!=null&&(D=new Promise((V,Y)=>{I=()=>{Y(new am)},E.addEventListener("abort",I)}));try{await Promise.race([a.promise,D])}finally{I!=null&&E!=null&&E?.removeEventListener("abort",I)}}},t==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(b){return x.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return x.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(b){return x.end(b),t!=null&&(t(b),t=void 0),o},get readableLength(){return x.readableLength},onEmpty:b=>x.onEmpty(b)},o}var cm=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},um=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ox=r=>globalThis.DOMException===void 0?new um(r):new DOMException(r),Nx=r=>{let e=r.reason===void 0?Ox("This operation was aborted."):r.reason;return e instanceof Error?e:Ox(e)};function lm(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&p(Nx(y)),a=()=>{p(Nx(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let d=new cm;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(y){p(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(d.message=o??`Promise timed out after ${t} milliseconds`,p(d))},t),(async()=>{try{h(await r)}catch(y){p(y)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var D2=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 R2(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!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:l,removeListener:h}=D2(r),p=(...y)=>{let g=t.multiArgs?y:y[0];t.filter&&!t.filter(g)||(c.push(g),t.count===c.length&&(n(),i(c)))},d=y=>{n(),s(y)};n=()=>{for(let y of a)h(y,p);for(let y of t.rejectionEvents)h(y,d)};for(let y of a)l(y,p);for(let y of t.rejectionEvents)l(y,d);t.signal&&t.signal.addEventListener("abort",()=>{d(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=lm(o,{milliseconds:t.timeout});return i.cancel=n,i}return o}function Lt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=R2(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var ni=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},$l=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function L2(r){return r.reason}async function Rs(r,e,t){if(e==null)return r;let n=t?.translateError??L2;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 U2=Math.pow(2,20)*4,ao=class extends rr{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??U2,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new he,this.writeBuffer=new he,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.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=Ds(),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 jr(`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 Yu(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new jr("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 jr("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 jr(`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 Fu;this.dispatchEvent(new Ju(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(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 ns))}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 he(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 Zu(e))}finally{this.remoteWriteStatus==="closed"&&(this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Ta(`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 Ta(`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 Fl=class extends ao{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 Lt(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 Lt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function Dx(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Wl=class extends rr{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 Rs(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 $u;let t=this.onCreateStream({...this.streamOptions,...e});return Dx(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 $l(`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 ql=class extends ao{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 Lt(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 Lt(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 M2=4194304,Gl=class extends Error{static name="UnwrappedError";name="UnwrappedError"},hc=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},pm=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hm=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function j2(r){return typeof r?.closeRead=="function"}function K2(r){return typeof r?.close=="function"}function fm(r){return j2(r)?r.readStatus==="closing"||r.readStatus==="closed":K2(r)?r.status!=="open":!1}function H2(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function V2(r,e){let t=e?.maxBufferSize??M2,n=new he,o=Promise.withResolvers(),i=!1;if(!H2(r))throw new be("Argument should be a Stream or a Multiaddr");let s=h=>{if(e?.stopPropagation,n.append(h.data),n.byteLength>t){let p=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${p} > ${t}`))}o.resolve()};r.addEventListener("message",s);let a=h=>{h.error!=null?o.reject(h.error):o.resolve()};r.addEventListener("close",a);let c=()=>{o.resolve()};r.addEventListener("remoteCloseWrite",c);let l={readBuffer:n,async read(h){if(i===!0)throw new Gl("Stream was unwrapped");if(fm(r)){if(h?.bytes==null)return null;if(n.byteLength<h.bytes)throw new ni(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let p=h?.bytes??1;for(;;){if(n.byteLength>=p){o.resolve();break}if(await Rs(o.promise,h?.signal),fm(r)){if(n.byteLength===0&&h?.bytes==null)return null;break}o=Promise.withResolvers()}let d=h?.bytes??n.byteLength;if(n.byteLength<d){if(fm(r))throw new ni(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return l.read(h)}let y=n.sublist(0,d);return n.consume(d),y},async write(h,p){if(i===!0)throw new Gl("Stream was unwrapped");r.send(h)||await Lt(r,"drain",{signal:p?.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 l}function zl(r,e={}){let t=V2(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Me(e.maxDataLength));let n=e?.lengthDecoder??gn,o=e?.lengthEncoder??bl;return{async read(s){let a=-1,c=new he;for(;;){let h=await t.read({...s,bytes:1});if(h==null)break;c.append(h);try{a=n(c)}catch(p){if(p instanceof RangeError)continue;throw p}if(a<0)throw new hc("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new hm(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new pm(`Message length too long - ${a} > ${e.maxDataLength}`);let l=await t.read({...s,bytes:a});if(l==null)throw new ni(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(l.byteLength!==a)throw new ni(`Unexpected EOF - read ${l.byteLength}/${a} bytes before the stream closed`);return l},async write(s,a){await t.write(new he(o(s.byteLength),s),a)},async writeV(s,a){let c=new he(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function Xl(r,e){let t=zl(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 $2=1024*1024*4,F2=1024*1024*4,Zl=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new he,this.maxBufferSize=e.maxBufferSize??$2,this.maxDataLength=e.maxDataLength??F2,this.lengthDecoder=e.lengthDecoder??gn,this.encodingLength=e.encodingLength??Me}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new be(`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 hc("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 Yl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ls=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Jl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},dc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Ql(r){return r[Symbol.asyncIterator]!=null}function Rx(r,e){if(r.byteLength>e)throw new Ls("Message length too long")}var tf=r=>{let e=Me(r),t=rt(e);return bl(r,t),tf.bytes=e,t};tf.bytes=0;function mc(r,e){e=e??{};let t=e.lengthEncoder??tf,n=e?.maxDataLength??4194304;function*o(i){Rx(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Ql(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}mc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??tf,n=e?.maxDataLength??4194304;return Rx(r,n),new he(t(r.byteLength),r)};var oi;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(oi||(oi={}));var dm=r=>{let e=gn(r);return dm.bytes=Me(e),e};dm.bytes=0;function yc(r,e){let t=new he,n=oi.LENGTH,o=-1,i=e?.lengthDecoder??dm,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===oi.LENGTH)try{if(o=i(t),o<0)throw new Yl("Invalid message length");if(o>a)throw new Ls("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=oi.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new Jl("Message length length too long");break}throw l}if(n===oi.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=oi.LENGTH}}}return Ql(r)?(async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new dc("Unexpected end of input")})():(function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new dc("Unexpected end of input")})()}yc.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 yc(n,{...e??{},onLength:i=>{t=i}})};var mm=class extends ql{channel;incomingData;maxBufferedAmount;receivedFinAck;constructor(e){switch(super({...e,maxMessageSize:(e.maxMessageSize??Os)-Ix}),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Ds(),this.maxBufferedAmount=e.maxBufferedAmount??Bx,this.receivedFinAck=Promise.withResolvers(),this.channel.readyState){case"open":break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new jr("Unknown datachannel state")}this.channel.onclose=o=>{this.log.trace("received onclose event"),this.onRemoteCloseWrite(),this.onTransportClosed()},this.channel.onerror=o=>{this.log.trace("received onerror event");let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))},this.channel.bufferedAmountLowThreshold=0,this.channel.onbufferedamountlow=()=>{this.safeDispatchEvent("drain")};let t=this;Promise.resolve().then(async()=>{for await(let o of yc(this.incomingData)){let i=t.processIncomingProtobuf(o);i!=null&&t.onData(new he(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)});let n=()=>{this.channel.close()};this.addEventListener("close",n)}sendNewStream(){}_sendMessage(e){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new jr(`Invalid datachannel state - ${this.channel.readyState}`);try{this.log.trace('sending message, channel state "%s"',this.channel.readyState);for(let t of e)this.channel.send(t)}catch(t){this.log.error("error while sending message",t)}}sendData(e){let t=St.encode({message:e.subarray()}),n=mc.single(t);return this._sendMessage(n),{sentBytes:e.byteLength,canSendMore:this.channel.bufferedAmount<this.maxBufferedAmount}}sendReset(){this.receivedFinAck.resolve();try{this._sendFlag(St.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){this.channel.readyState==="open"&&this._sendFlag(St.Flag.FIN),await Rs(this.receivedFinAck.promise,e?.signal)}async sendCloseRead(e){this.channel.readyState==="open"&&this._sendFlag(St.Flag.STOP_SENDING),e?.signal?.throwIfAborted()}processIncomingProtobuf(e){let t=St.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===St.Flag.FIN&&(this.onRemoteCloseWrite(),this._sendFlag(St.Flag.FIN_ACK)),t.flag===St.Flag.RESET&&(this.receivedFinAck.resolve(),this.onRemoteReset()),t.flag===St.Flag.STOP_SENDING&&this.onRemoteCloseRead(),t.flag===St.Flag.FIN_ACK&&this.receivedFinAck.resolve()),this.readStatus==="readable"||this.readStatus==="paused")return t.message}_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=St.encode({flag:e}),n=mc.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 gc(r){let{channel:e,direction:t,isHandshake:n}=r;return new mm({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`),protocol:""})}var co=class{protocol;peerConnection;metrics;dataChannelOptions;constructor(e){this.peerConnection=e.peerConnection,this.metrics=e.metrics,this.protocol=e.protocol??om,this.dataChannelOptions=e.dataChannelOptions??{}}createStreamMuxer(e){return new ym(e,{peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,protocol:this.protocol})}},ym=class extends Wl{peerConnection;dataChannelOptions;constructor(e,t){super(e,{...t,name:"muxer"}),this.peerConnection=t.peerConnection,this.protocol=t.protocol??om,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming %s datachannel with channel id %d and status",n.protocol,n.id,n.readyState),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=gc({...this.streamOptions,...this.dataChannelOptions,channel:n,direction:"inbound",log:this.log});this.onRemoteStream(o)}}async onCreateStream(e){let t=this.peerConnection.createDataChannel("wtf",{protocol:e?.protocol});return this.log("open channel %d for protocol %s",t.id,e?.protocol),t.readyState!=="open"&&(this.log('channel %d state is "%s" and not "open", waiting for "open" event before sending data',t.id,t.readyState),await Lt(t,"open",e),this.log('channel %d state is now "%s", sending data',t.id,t.readyState)),gc({...e,...this.dataChannelOptions,channel:t,direction:"outbound",log:this.log})}onData(){}};var gm=class extends Fl{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()}}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.peerConnection.close(),e?.signal?.throwIfAborted()}sendReset(){this.peerConnection.close()}sendPause(){}sendResume(){}},bc=r=>new gm(r);var Lx=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))},G2=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var z2=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var X2=(function(){function r(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"}return r})();var Z2=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var Y2=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var J2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Q2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Ux=3,eC=[["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",J2]],Mx=[["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 Kx(r){return r?jx(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Y2:typeof navigator<"u"?jx(navigator.userAgent):nC()}function tC(r){return r!==""&&eC.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 jx(r){var e=tC(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new Z2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Ux&&(o=Lx(Lx([],o,!0),oC(Ux-o.length),!0)):o=[];var i=o.join("."),s=rC(r),a=Q2.exec(r);return a&&a[1]?new X2(t,i,s,a[1]):new G2(t,i,s)}function rC(r){for(var e=0,t=Mx.length;e<t;e++){var n=Mx[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function nC(){var r=typeof process<"u"&&process.version;return r?new z2(process.version.slice(1)):null}function oC(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}var Hx=Kx(),xc=Hx!=null&&Hx.name==="firefox";async function bm(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??_x.map(e=>({urls:[e]})),r}var Vx=(r=32)=>Cx+[...Array(r)].map(()=>nm.at(Math.floor(Math.random()*nm.length))).join("");var rf=globalThis.RTCPeerConnection,nf=globalThis.RTCSessionDescription,$x=globalThis.RTCIceCandidate;var Zt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var uo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ar=class extends uo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var of=class extends uo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var sf=class extends uo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},af=class extends uo{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Ut;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),(function(o){o.codec=()=>Jo(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Cr(o,r.codec()),r.decode=(o,i)=>_r(o,r.codec(),i)})(Ut||(Ut={}));var cf=async(r,e,t)=>{try{let n=Promise.withResolvers();for(iC(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Ut.Type.ICE_CANDIDATE)throw new zu("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Zt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new $x(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Zt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&uf(r)!=="connected")throw n}};function uf(r){return xc?r.iceConnectionState:r.connectionState}function iC(r,e){r[xc?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(uf(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Vu("RTCPeerConnection was closed"));break;default:break}}}function lf(r){let e;for(let t of r.getComponents())t.name==="p2p"&&(e=Cs(t.value??""));if(e==null)throw new Wu("Remote peerId must be present in multiaddr");return e}async function Fx({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{circuitAddress:h,targetPeer:p}=Wx(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",h);let d=i.getConnections(p),y;d.length===0?(l?.(new Zt("webrtc:dial-relay")),y=await s.dial(h,{signal:t,onProgress:l})):(l?.(new Zt("webrtc:reuse-relay-connection")),y=d[0]),l?.(new Zt("webrtc:open-signaling-stream"));let g=await y.newStream(pc,{signal:t,runOnLimitedConnection:!0}),x=Xl(g).pb(Ut),b=new rf(r);b.addEventListener("connectionstatechange",()=>{switch(b.connectionState){case"closed":b.close();break;default:break}});let E=new co({peerConnection:b,dataChannelOptions:e});try{let D=b.createDataChannel("init");b.onicecandidate=({candidate:z})=>{let te=JSON.stringify(z?.toJSON()??null);a.trace("initiator sending ICE candidate %o",z),x.write({type:Ut.Type.ICE_CANDIDATE,data:te},{signal:t}).catch(X=>{a.error("error sending ICE candidate - %e",X)})},b.onicecandidateerror=z=>{a.error("initiator ICE candidate error",z)};let I=await b.createOffer().catch(z=>{throw a.error("could not execute createOffer",z),new ar("Failed to set createOffer")});a.trace("initiator send SDP offer %s",I.sdp),l?.(new Zt("webrtc:send-sdp-offer")),await x.write({type:Ut.Type.SDP_OFFER,data:I.sdp},{signal:t}),await b.setLocalDescription(I).catch(z=>{throw a.error("could not execute setLocalDescription",z),new ar("Failed to set localDescription")}),l?.(new Zt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let V=await x.read({signal:t});if(V.type!==Ut.Type.SDP_ANSWER)throw new ar("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",V.data);let Y=new nf({type:"answer",sdp:V.data});return await b.setRemoteDescription(Y).catch(z=>{throw a.error("could not execute setRemoteDescription",z),new ar("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new Zt("webrtc:read-ice-candidates")),await cf(b,x,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected"),D.readyState!=="open"&&(a.trace("wait for init channel to open"),await Lt(D,"open",{signal:t})),a.trace("closing init channel, starting status"),D.close(),l?.(new Zt("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:b,muxerFactory:E}}catch(D){throw a.error("outgoing signaling error",D),b.close(),g.abort(D),D}finally{b.onicecandidate=null,b.onicecandidateerror=null}}var qx=Ne(Sx.matchers[0],Oe(290)),ff=class r extends rr{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=>qx.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=>qx.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 Gx(r,e,{peerConnection:t,signal:n,log:o}){o.trace("new inbound signaling stream");let i=Xl(r).pb(Ut);try{t.onicecandidate=({candidate:p})=>{let d=JSON.stringify(p?.toJSON()??null);o.trace("recipient sending ICE candidate %s",d),i.write({type:Ut.Type.ICE_CANDIDATE,data:d},{signal:n}).catch(y=>{o.error("error sending ICE candidate - %e",y)})},o.trace("recipient read SDP offer");let c=await i.read({signal:n});if(c.type!==Ut.Type.SDP_OFFER)throw new ar(`expected message type SDP_OFFER, received: ${c.type??"undefined"} `);o.trace("recipient received SDP offer %s",c.data);let l=new nf({type:"offer",sdp:c.data});await t.setRemoteDescription(l).catch(p=>{throw o.error("could not execute setRemoteDescription",p),new ar("Failed to set remoteDescription")});let h=await t.createAnswer().catch(p=>{throw o.error("could not execute createAnswer",p),new ar("Failed to create answer")});o.trace("recipient send SDP answer %s",h.sdp),await i.write({type:Ut.Type.SDP_ANSWER,data:h.sdp},{signal:n}),await t.setLocalDescription(h).catch(p=>{throw o.error("could not execute setLocalDescription",p),new ar("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await cf(t,i,{direction:"recipient",signal:n,log:o})}catch(c){if(uf(t)!=="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=lf(e.remoteAddr),a=Ps(`/webrtc/p2p/${s}`);return o.trace("recipient connected to remote address %s",a),{remoteAddress:a,remotePeer:s}}var pf=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"})})}[Qu]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[os]=["@libp2p/transport"];[Wg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(pc,(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(pc),this._started=!1}createListener(e){return new ff(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Ex.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 Fx({rtcConfiguration:await bm(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=bc({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:lf(e),muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol(e,t,n){let o=new rf(await bm(this.init.rtcConfiguration));o.addEventListener("connectionstatechange",()=>{switch(o.connectionState){case"closed":o.close();break;default:break}});let i=new co({peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s,remotePeer:a}=await Gx(e,t,{peerConnection:o,signal:n,log:this.log});await e.close({signal:n});let c=bc({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 Wx(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new be("Destination peer id was missing");return{circuitAddress:Ps(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:Cs(e)}}var az=Mr(Xx());var qr={};bt(qr,{Any:()=>Fr,BaseBlock:()=>Ze,BaseStringBlock:()=>Sc,BitString:()=>Pr,BmpString:()=>ui,Boolean:()=>si,CharacterString:()=>bi,Choice:()=>js,Constructed:()=>Ye,DATE:()=>Tc,DateTime:()=>Pc,Duration:()=>Oc,EndOfContent:()=>Ec,Enumerated:()=>ai,GeneralString:()=>gi,GeneralizedTime:()=>xi,GraphicString:()=>yi,HexBlock:()=>Wr,IA5String:()=>mi,Integer:()=>Bn,Null:()=>Tr,NumericString:()=>fi,ObjectIdentifier:()=>ci,OctetString:()=>kr,Primitive:()=>Cn,PrintableString:()=>pi,RawData:()=>Am,RelativeObjectIdentifier:()=>Ic,Repeated:()=>wi,Sequence:()=>Et,Set:()=>Pt,TIME:()=>Nc,TeletexString:()=>hi,TimeOfDay:()=>kc,UTCTime:()=>po,UniversalString:()=>li,Utf8String:()=>ur,ValueBlock:()=>ut,VideotexString:()=>di,ViewWriter:()=>Ms,VisibleString:()=>fo,compareSchema:()=>En,fromBER:()=>Tn,verifySchema:()=>CC});var de=Mr(Sn());function ii(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 lo(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let l=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);l[i-h-1]=Math.floor(o/p),o-=l[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function mf(...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 wm(){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=ii(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,ii(i,8)-n}function Zx(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=lo(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=lo(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 Yx(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Mt(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,o=new Array(n);for(let s=0;s<n;s++)o[s]="0";return o.join("").concat(t)}var xN=Math.log(2);function yf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Sm(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 In(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 Ms=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Sm(this.items)}},wc=[new Uint8Array([1])],Jx="0123456789",vm="name",Qx="valueHexView",dC="isHexOnly",mC="idBlock",yC="tagClass",gC="tagNumber",bC="isConstructed",xC="fromBER",wC="toBER",vC="local",jt="",Or=new ArrayBuffer(0),Pf=new Uint8Array(0),Ac="EndOfContent",tw="OCTET STRING",rw="BIT STRING";function Wr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?de.BufferSourceConverter.toUint8Array(i.valueHex):Pf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!In(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",Or)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:de.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var _n=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=jt,warnings:n=[],valueBeforeDecode:o=Pf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=de.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:de.Convert.ToHex(this.valueBeforeDecodeView)}}};_n.NAME="baseBlock";var ut=class extends _n{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'")}};ut.NAME="valueBlock";var gf=class extends Wr(_n){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?de.BufferSourceConverter.toUint8Array(e.valueHex):Pf,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Or}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=lo(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(l[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let d=new Uint8Array(h);for(let y=0;y<l.length;y++)d[y]=l[y];l=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,l[c-1]=i[c]&127;let p=new Uint8Array(c);for(let d=0;d<c;d++)p[d]=l[d];l=this.valueHexView=new Uint8Array(c),l.set(p),this.blockLength<=9?this.tagNumber=ii(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};gf.NAME="identificationBlock";var bf=class extends _n{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!In(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=ii(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=lo(this.length,8);if(o.byteLength>127)return this.error="Too big length",Or;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}}};bf.NAME="lengthBlock";var Z={},Ze=class extends _n{constructor({name:e=jt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new gf(o),this.lenBlock=new bf(o),this.valueBlock=i?new i(o):new ut(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 Ms;t||nw(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?Or:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():de.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=de.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Yx(t,n)}};Ze.NAME="BaseBlock";function nw(r){var e;if(r instanceof Z.Constructed)for(let t of r.valueBlock.value)nw(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var Sc=class extends Ze{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=jt,...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}'`}};Sc.NAME="BaseStringBlock";var xf=class extends Wr(ut){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};xf.NAME="PrimitiveValueBlock";var ow,Cn=class extends Ze{constructor(e={}){super(e,xf),this.idBlock.isConstructed=!1}};ow=Cn;Z.Primitive=ow;Cn.NAME="PRIMITIVE";function AC(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 Ks(r,e=0,t=r.length){let n=e,o=new Ze({},ut),i=new _n;if(!In(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=Ze;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=Z.EndOfContent;break;case 1:c=Z.Boolean;break;case 2:c=Z.Integer;break;case 3:c=Z.BitString;break;case 4:c=Z.OctetString;break;case 5:c=Z.Null;break;case 6:c=Z.ObjectIdentifier;break;case 10:c=Z.Enumerated;break;case 12:c=Z.Utf8String;break;case 13:c=Z.RelativeObjectIdentifier;break;case 14:c=Z.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Z.Sequence;break;case 17:c=Z.Set;break;case 18:c=Z.NumericString;break;case 19:c=Z.PrintableString;break;case 20:c=Z.TeletexString;break;case 21:c=Z.VideotexString;break;case 22:c=Z.IA5String;break;case 23:c=Z.UTCTime;break;case 24:c=Z.GeneralizedTime;break;case 25:c=Z.GraphicString;break;case 26:c=Z.VisibleString;break;case 27:c=Z.GeneralString;break;case 28:c=Z.UniversalString;break;case 29:c=Z.CharacterString;break;case 30:c=Z.BmpString;break;case 31:c=Z.DATE;break;case 32:c=Z.TimeOfDay;break;case 33:c=Z.DateTime;break;case 34:c=Z.Duration;break;default:{let l=o.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Z.Constructed:Z.Primitive}return o=AC(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Tn(r){if(!r.byteLength){let e=new Ze({},ut);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ks(de.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function SC(r,e){return r?1:e}var $r=class extends ut{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!In(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(;SC(this.isIndefiniteForm,n)>0;){let s=Ks(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===Ac)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Ac?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Ms;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Or:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};$r.NAME="ConstructedValueBlock";var iw,Ye=class extends Ze{constructor(e={}){super(e,$r),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 MS=Object.create;var hl=Object.defineProperty;var jS=Object.getOwnPropertyDescriptor;var KS=Object.getOwnPropertyNames;var HS=Object.getPrototypeOf,VS=Object.prototype.hasOwnProperty;var vh=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),vt=(r,e)=>{for(var t in e)hl(r,t,{get:e[t],enumerable:!0})},c0=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of KS(e))!VS.call(r,o)&&o!==t&&hl(r,o,{get:()=>e[o],enumerable:!(n=jS(e,o))||n.enumerable});return r};var Hr=(r,e,t)=>(t=r!=null?MS(HS(r)):{},c0(e||!r||!r.__esModule?hl(t,"default",{value:r,enumerable:!0}):t,r)),$S=r=>c0(hl({},"__esModule",{value:!0}),r);var _x=vh(()=>{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,l){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),l&&l(h,p)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,l=!a&&!c,h={create:a?function(){return xh(Object.create(null))}:c?function(){return xh({__proto__:null})}:function(){return xh({})},has:l?function(A,C){return n.call(A,C)}:function(A,C){return C in A},get:l?function(A,C){return n.call(A,C)?A[C]:void 0}:function(A,C){return A[C]}},p=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:NS(),y=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:DS(),g=typeof WeakMap=="function"?WeakMap:RS(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,b=kS(),E=PS(b);function D(A,C,O,$){if(N(O)){if(!cn(A))throw new TypeError;if(!Gn(C))throw new TypeError;return H(A,C)}else{if(!cn(A))throw new TypeError;if(!Q(C))throw new TypeError;if(!Q($)&&!N($)&&!pe($))throw new TypeError;return pe($)&&($=void 0),O=Be(O),x(A,C,O,$)}}e("decorate",D);function T(A,C){function O($,se){if(!Q($))throw new TypeError;if(!N(se)&&!pl(se))throw new TypeError;U(A,C,$,se)}return O}e("metadata",T);function V(A,C,O,$){if(!Q(O))throw new TypeError;return N($)||($=Be($)),U(A,C,O,$)}e("defineMetadata",V);function Y(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Be(O)),v(A,C,O)}e("hasMetadata",Y);function z(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Be(O)),_(A,C,O)}e("hasOwnMetadata",z);function te(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Be(O)),P(A,C,O)}e("getMetadata",te);function X(A,C,O){if(!Q(C))throw new TypeError;return N(O)||(O=Be(O)),R(A,C,O)}e("getOwnMetadata",X);function B(A,C){if(!Q(A))throw new TypeError;return N(C)||(C=Be(C)),k(A,C)}e("getMetadataKeys",B);function j(A,C){if(!Q(A))throw new TypeError;return N(C)||(C=Be(C)),L(A,C)}e("getOwnMetadataKeys",j);function q(A,C,O){if(!Q(C))throw new TypeError;if(N(O)||(O=Be(O)),!Q(C))throw new TypeError;N(O)||(O=Be(O));var $=Na(C,O,!1);return N($)?!1:$.OrdinaryDeleteMetadata(A,C,O)}e("deleteMetadata",q);function H(A,C){for(var O=A.length-1;O>=0;--O){var $=A[O],se=$(C);if(!N(se)&&!pe(se)){if(!Gn(se))throw new TypeError;C=se}}return C}function x(A,C,O,$){for(var se=A.length-1;se>=0;--se){var Xe=A[se],nt=Xe(C,O,$);if(!N(nt)&&!pe(nt)){if(!Q(nt))throw new TypeError;$=nt}}return $}function v(A,C,O){var $=_(A,C,O);if($)return!0;var se=wh(C);return pe(se)?!1:v(A,se,O)}function _(A,C,O){var $=Na(C,O,!1);return N($)?!1:Oe($.OrdinaryHasOwnMetadata(A,C,O))}function P(A,C,O){var $=_(A,C,O);if($)return R(A,C,O);var se=wh(C);if(!pe(se))return P(A,se,O)}function R(A,C,O){var $=Na(C,O,!1);if(!N($))return $.OrdinaryGetOwnMetadata(A,C,O)}function U(A,C,O,$){var se=Na(O,$,!0);se.OrdinaryDefineOwnMetadata(A,C,O,$)}function k(A,C){var O=L(A,C),$=wh(A);if($===null)return O;var se=k($,C);if(se.length<=0)return O;if(O.length<=0)return se;for(var Xe=new y,nt=[],ge=0,G=O;ge<G.length;ge++){var J=G[ge],re=Xe.has(J);re||(Xe.add(J),nt.push(J))}for(var ne=0,be=se;ne<be.length;ne++){var J=be[ne],re=Xe.has(J);re||(Xe.add(J),nt.push(J))}return nt}function L(A,C){var O=Na(A,C,!1);return O?O.OrdinaryOwnMetadataKeys(A,C):[]}function W(A){if(A===null)return 1;switch(typeof A){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return A===null?1:6;default:return 6}}function N(A){return A===void 0}function pe(A){return A===null}function me(A){return typeof A=="symbol"}function Q(A){return typeof A=="object"?A!==null:typeof A=="function"}function xe(A,C){switch(W(A)){case 0:return A;case 1:return A;case 2:return A;case 3:return A;case 4:return A;case 5:return A}var O=C===3?"string":C===5?"number":"default",$=r0(A,i);if($!==void 0){var se=$.call(A,O);if(Q(se))throw new TypeError;return se}return Ee(A,O==="default"?"number":O)}function Ee(A,C){if(C==="string"){var O=A.toString;if(or(O)){var $=O.call(A);if(!Q($))return $}var se=A.valueOf;if(or(se)){var $=se.call(A);if(!Q($))return $}}else{var se=A.valueOf;if(or(se)){var $=se.call(A);if(!Q($))return $}var Xe=A.toString;if(or(Xe)){var $=Xe.call(A);if(!Q($))return $}}throw new TypeError}function Oe(A){return!!A}function ve(A){return""+A}function Be(A){var C=xe(A,3);return me(C)?C:ve(C)}function cn(A){return Array.isArray?Array.isArray(A):A instanceof Object?A instanceof Array:Object.prototype.toString.call(A)==="[object Array]"}function or(A){return typeof A=="function"}function Gn(A){return typeof A=="function"}function pl(A){switch(W(A)){case 3:return!0;case 4:return!0;default:return!1}}function ss(A,C){return A===C||A!==A&&C!==C}function r0(A,C){var O=A[C];if(O!=null){if(!or(O))throw new TypeError;return O}}function n0(A){var C=r0(A,s);if(!or(C))throw new TypeError;var O=C.call(A);if(!Q(O))throw new TypeError;return O}function o0(A){return A.value}function i0(A){var C=A.next();return C.done?!1:C}function s0(A){var C=A.return;C&&C.call(A)}function wh(A){var C=Object.getPrototypeOf(A);if(typeof A!="function"||A===p||C!==p)return C;var O=A.prototype,$=O&&Object.getPrototypeOf(O);if($==null||$===Object.prototype)return C;var se=$.constructor;return typeof se!="function"||se===A?C:se}function BS(){var A;!N(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(A=OS(t.Reflect));var C,O,$,se=new g,Xe={registerProvider:nt,getProvider:G,setProvider:re};return Xe;function nt(ne){if(!Object.isExtensible(Xe))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case A===ne:break;case N(C):C=ne;break;case C===ne:break;case N(O):O=ne;break;case O===ne:break;default:$===void 0&&($=new y),$.add(ne);break}}function ge(ne,be){if(!N(C)){if(C.isProviderFor(ne,be))return C;if(!N(O)){if(O.isProviderFor(ne,be))return C;if(!N($))for(var Le=n0($);;){var Ze=i0(Le);if(!Ze)return;var xr=o0(Ze);if(xr.isProviderFor(ne,be))return s0(Le),xr}}}if(!N(A)&&A.isProviderFor(ne,be))return A}function G(ne,be){var Le=se.get(ne),Ze;return N(Le)||(Ze=Le.get(be)),N(Ze)&&(Ze=ge(ne,be),N(Ze)||(N(Le)&&(Le=new m,se.set(ne,Le)),Le.set(be,Ze))),Ze}function J(ne){if(N(ne))throw new TypeError;return C===ne||O===ne||!N($)&&$.has(ne)}function re(ne,be,Le){if(!J(Le))throw new Error("Metadata provider not registered.");var Ze=G(ne,be);if(Ze!==Le){if(!N(Ze))return!1;var xr=se.get(ne);N(xr)&&(xr=new m,se.set(ne,xr)),xr.set(be,Le)}return!0}}function kS(){var A;return!N(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(A=t.Reflect[w]),N(A)&&(A=BS()),!N(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:A}),A}function PS(A){var C=new g,O={isProviderFor:function(J,re){var ne=C.get(J);return N(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:nt,OrdinaryHasOwnMetadata:se,OrdinaryGetOwnMetadata:Xe,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:G};return b.registerProvider(O),O;function $(J,re,ne){var be=C.get(J),Le=!1;if(N(be)){if(!ne)return;be=new m,C.set(J,be),Le=!0}var Ze=be.get(re);if(N(Ze)){if(!ne)return;if(Ze=new m,be.set(re,Ze),!A.setProvider(J,re,O))throw be.delete(re),Le&&C.delete(J),new Error("Wrong provider for target.")}return Ze}function se(J,re,ne){var be=$(re,ne,!1);return N(be)?!1:Oe(be.has(J))}function Xe(J,re,ne){var be=$(re,ne,!1);if(!N(be))return be.get(J)}function nt(J,re,ne,be){var Le=$(ne,be,!0);Le.set(J,re)}function ge(J,re){var ne=[],be=$(J,re,!1);if(N(be))return ne;for(var Le=be.keys(),Ze=n0(Le),xr=0;;){var a0=i0(Ze);if(!a0)return ne.length=xr,ne;var LS=o0(a0);try{ne[xr]=LS}catch(US){try{s0(Ze)}finally{throw US}}xr++}}function G(J,re,ne){var be=$(re,ne,!1);if(N(be)||!be.delete(J))return!1;if(be.size===0){var Le=C.get(re);N(Le)||(Le.delete(ne),Le.size===0&&C.delete(Le))}return!0}}function OS(A){var C=A.defineMetadata,O=A.hasOwnMetadata,$=A.getOwnMetadata,se=A.getOwnMetadataKeys,Xe=A.deleteMetadata,nt=new g,ge={isProviderFor:function(G,J){var re=nt.get(G);return!N(re)&&re.has(J)?!0:se(G,J).length?(N(re)&&(re=new y,nt.set(G,re)),re.add(J),!0):!1},OrdinaryDefineOwnMetadata:C,OrdinaryHasOwnMetadata:O,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:se,OrdinaryDeleteMetadata:Xe};return ge}function Na(A,C,O){var $=b.getProvider(A,C);if(!N($))return $;if(O){if(b.setProvider(A,C,E))return E;throw new Error("Illegal state.")}}function NS(){var A={},C=[],O=(function(){function ge(G,J,re){this._index=0,this._keys=G,this._values=J,this._selector=re}return ge.prototype["@@iterator"]=function(){return this},ge.prototype[s]=function(){return this},ge.prototype.next=function(){var G=this._index;if(G>=0&&G<this._keys.length){var J=this._selector(this._keys[G],this._values[G]);return G+1>=this._keys.length?(this._index=-1,this._keys=C,this._values=C):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},ge.prototype.throw=function(G){throw this._index>=0&&(this._index=-1,this._keys=C,this._values=C),G},ge.prototype.return=function(G){return this._index>=0&&(this._index=-1,this._keys=C,this._values=C),{value:G,done:!0}},ge})(),$=(function(){function ge(){this._keys=[],this._values=[],this._cacheKey=A,this._cacheIndex=-2}return Object.defineProperty(ge.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),ge.prototype.has=function(G){return this._find(G,!1)>=0},ge.prototype.get=function(G){var J=this._find(G,!1);return J>=0?this._values[J]:void 0},ge.prototype.set=function(G,J){var re=this._find(G,!0);return this._values[re]=J,this},ge.prototype.delete=function(G){var J=this._find(G,!1);if(J>=0){for(var re=this._keys.length,ne=J+1;ne<re;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,ss(G,this._cacheKey)&&(this._cacheKey=A,this._cacheIndex=-2),!0}return!1},ge.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=A,this._cacheIndex=-2},ge.prototype.keys=function(){return new O(this._keys,this._values,se)},ge.prototype.values=function(){return new O(this._keys,this._values,Xe)},ge.prototype.entries=function(){return new O(this._keys,this._values,nt)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(G,J){if(!ss(this._cacheKey,G)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(ss(this._keys[re],G)){this._cacheIndex=re;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(G),this._values.push(void 0)),this._cacheIndex},ge})();return $;function se(ge,G){return ge}function Xe(ge,G){return G}function nt(ge,G){return[ge,G]}}function DS(){var A=(function(){function C(){this._map=new m}return Object.defineProperty(C.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),C.prototype.has=function(O){return this._map.has(O)},C.prototype.add=function(O){return this._map.set(O,O),this},C.prototype.delete=function(O){return this._map.delete(O)},C.prototype.clear=function(){this._map.clear()},C.prototype.keys=function(){return this._map.keys()},C.prototype.values=function(){return this._map.keys()},C.prototype.entries=function(){return this._map.entries()},C.prototype["@@iterator"]=function(){return this.keys()},C.prototype[s]=function(){return this.keys()},C})();return A}function RS(){var A=16,C=h.create(),O=$();return(function(){function G(){this._key=$()}return G.prototype.has=function(J){var re=se(J,!1);return re!==void 0?h.has(re,this._key):!1},G.prototype.get=function(J){var re=se(J,!1);return re!==void 0?h.get(re,this._key):void 0},G.prototype.set=function(J,re){var ne=se(J,!0);return ne[this._key]=re,this},G.prototype.delete=function(J){var re=se(J,!1);return re!==void 0?delete re[this._key]:!1},G.prototype.clear=function(){this._key=$()},G})();function $(){var G;do G="@@WeakMap@@"+ge();while(h.has(C,G));return C[G]=!0,G}function se(G,J){if(!n.call(G,O)){if(!J)return;Object.defineProperty(G,O,{value:h.create()})}return G[O]}function Xe(G,J){for(var re=0;re<J;++re)G[re]=Math.random()*255|0;return G}function nt(G){if(typeof Uint8Array=="function"){var J=new Uint8Array(G);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Xe(J,G),J}return Xe(new Array(G),G)}function ge(){var G=nt(A);G[6]=G[6]&79|64,G[8]=G[8]&191|128;for(var J="",re=0;re<A;++re){var ne=G[re];(re===4||re===6||re===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function xh(A){return A.__=void 0,delete A.__,A}})})(Ex||(Ex={}))});var _n=vh(Hs=>{"use strict";var jC="[object ArrayBuffer]",En=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===jC}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}},jm="string",KC=/^[0-9a-f\s]+$/i,HC=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,VC=/^[a-zA-Z0-9-_]+$/,jf=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=En.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},fr=class{static toString(e,t=!1){let n=En.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}},Kf=class r{static isHex(e){return typeof e===jm&&KC.test(e)}static isBase64(e){return typeof e===jm&&HC.test(e)}static isBase64Url(e){return typeof e===jm&&VC.test(e)}static ToString(e,t="utf8"){let n=En.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 fr.toString(n,!0);case"utf16":case"utf16be":return fr.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 fr.fromString(e,!0);case"utf16":case"utf16be":return fr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=En.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 jf.fromString(e);case"utf16":case"utf16be":return fr.fromString(e);case"utf16le":case"usc2":return fr.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 jf.toString(e);case"utf16":case"utf16be":return fr.toString(e);case"utf16le":case"usc2":return fr.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=En.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=En.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 fr.toString(e,t)}static FromUtf16String(e,t=!1){return fr.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,"")||""}};Kf.DEFAULT_UTF8_ENCODING="utf8";function $C(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 FC(...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 WC(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}Hs.BufferSourceConverter=En;Hs.Convert=Kf;Hs.assign=$C;Hs.combine=FC;Hs.isEqual=WC});var w1=vh((fF,Dp)=>{var Qv,e1,t1,r1,n1,o1,i1,s1,a1,Np,Gy,c1,u1,ya,l1,f1,p1,h1,d1,m1,y1,g1,b1;(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 Dp=="object"&&typeof Dp.exports=="object"?r(t(e,t(Dp.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])};Qv=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},e1=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},t1=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},r1=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var l=t.length-1;l>=0;l--)(c=t[l])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},n1=function(t,n){return function(o,i){n(o,i,t)}},o1=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},i1=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function l(m){try{p(i.next(m))}catch(y){c(y)}}function h(m){try{p(i.throw(m))}catch(y){c(y)}}function p(m){m.done?a(m.value):s(m.value).then(l,h)}p((i=i.apply(t,n||[])).next())})},s1=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function l(p){return function(m){return h([p,m])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(m){p=[6,m],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},b1=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},a1=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Np=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.")},Gy=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},c1=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Gy(arguments[n]));return t},u1=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,l=a.length;c<l;c++,s++)i[s]=a[c];return i},ya=function(t){return this instanceof ya?(this.v=t,this):new ya(t)},l1=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(w){return new Promise(function(b,E){a.push([g,w,b,E])>1||l(g,w)})})}function l(g,w){try{h(i[g](w))}catch(b){y(a[0][3],b)}}function h(g){g.value instanceof ya?Promise.resolve(g.value.v).then(p,m):y(a[0][2],g)}function p(g){l("next",g)}function m(g){l("throw",g)}function y(g,w){g(w),a.shift(),a.length&&l(a[0][0],a[0][1])}},f1=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:ya(t[s](c)),done:s==="return"}:a?a(c):c}:a}},p1=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 Np=="function"?Np(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(l,h){c=t[a](c),s(l,h,c.done,c.value)})}}function s(a,c,l,h){Promise.resolve(h).then(function(p){a({value:p,done:l})},c)}},h1=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},d1=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},m1=function(t){return t&&t.__esModule?t:{default:t}},y1=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},g1=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",Qv),r("__assign",e1),r("__rest",t1),r("__decorate",r1),r("__param",n1),r("__metadata",o1),r("__awaiter",i1),r("__generator",s1),r("__exportStar",a1),r("__createBinding",b1),r("__values",Np),r("__read",Gy),r("__spread",c1),r("__spreadArrays",u1),r("__await",ya),r("__asyncGenerator",l1),r("__asyncDelegator",f1),r("__asyncValues",p1),r("__makeTemplateObject",h1),r("__importStar",d1),r("__importDefault",m1),r("__classPrivateFieldGet",y1),r("__classPrivateFieldSet",g1)})});var aB={};vt(aB,{webRTC:()=>sB,webRTCDirect:()=>iB});var Ah=Symbol.for("@libp2p/peer-id");var dl=Symbol.for("@libp2p/transport");var u0;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(u0||(u0={}));var ml=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},yl=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ke=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},as=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Da=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var gl=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var bl=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},jo=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Ko=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var wl=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},xl=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var vl=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Al=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Sl=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var zn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Xn=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 cs=Symbol.for("@libp2p/service-capabilities"),l0=Symbol.for("@libp2p/service-dependencies");var Ih={};vt(Ih,{base58btc:()=>He,base58flickr:()=>ZS});var DB=new Uint8Array(0);function f0(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 un(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 p0(r){return new TextEncoder().encode(r)}function h0(r){return new TextDecoder().decode(r)}function FS(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function p(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var w=0,b=0,E=0,D=g.length;E!==D&&g[E]===0;)E++,w++;for(var T=(D-E)*h+1>>>0,V=new Uint8Array(T);E!==D;){for(var Y=g[E],z=0,te=T-1;(Y!==0||z<b)&&te!==-1;te--,z++)Y+=256*V[te]>>>0,V[te]=Y%a>>>0,Y=Y/a>>>0;if(Y!==0)throw new Error("Non-zero carry");b=z,E++}for(var X=T-b;X!==T&&V[X]===0;)X++;for(var B=c.repeat(w);X<T;++X)B+=r.charAt(V[X]);return B}function m(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var b=0,E=0;g[w]===c;)b++,w++;for(var D=(g.length-w)*l+1>>>0,T=new Uint8Array(D);g[w];){var V=t[g.charCodeAt(w)];if(V===255)return;for(var Y=0,z=D-1;(V!==0||Y<E)&&z!==-1;z--,Y++)V+=a*T[z]>>>0,T[z]=V%256>>>0,V=V/256>>>0;if(V!==0)throw new Error("Non-zero carry");E=Y,w++}if(g[w]!==" "){for(var te=D-E;te!==D&&T[te]===0;)te++;for(var X=new Uint8Array(b+(D-te)),B=b;te!==D;)X[B++]=T[te++];return X}}}function y(g){var w=m(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:y}}var WS=FS,qS=WS,m0=qS;var Sh=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Eh=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 y0(this,e)}},_h=class{decoders;constructor(e){this.decoders=e}or(e){return y0(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 y0(r,e){return new _h({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ch=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sh(e,t,n),this.decoder=new Eh(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function us({name:r,prefix:e,encode:t,decode:n}){return new Ch(r,e,t,n)}function Zn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=m0(t,r);return us({prefix:e,name:r,encode:n,decode:i=>un(o(i))})}function GS(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let h=e[r[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|h,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 zS(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 XS(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Fe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=XS(n);return us({prefix:e,name:r,encode(i){return zS(i,n,t)},decode(i){return GS(i,o,t,r)}})}var He=Zn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ZS=Zn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Th={};vt(Th,{base32:()=>Yn,base32hex:()=>eE,base32hexpad:()=>rE,base32hexpadupper:()=>nE,base32hexupper:()=>tE,base32pad:()=>JS,base32padupper:()=>QS,base32upper:()=>YS,base32z:()=>oE});var Yn=Fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),YS=Fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),JS=Fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),QS=Fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),eE=Fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),tE=Fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),rE=Fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nE=Fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),oE=Fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bh={};vt(Bh,{base36:()=>Ra,base36upper:()=>iE});var Ra=Zn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),iE=Zn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vr={};vt(vr,{Digest:()=>Ho,create:()=>Bt,decode:()=>ps,equals:()=>Ph,hasCode:()=>EE});var sE=w0,g0=128,aE=127,cE=~aE,uE=Math.pow(2,31);function w0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=uE;)e[t++]=r&255|g0,r/=128;for(;r&cE;)e[t++]=r&255|g0,r>>>=7;return e[t]=r|0,w0.bytes=t-n+1,e}var lE=kh,fE=128,b0=127;function kh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw kh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&b0)<<o:(s&b0)*Math.pow(2,o),o+=7}while(s>=fE);return kh.bytes=i-n,t}var pE=Math.pow(2,7),hE=Math.pow(2,14),dE=Math.pow(2,21),mE=Math.pow(2,28),yE=Math.pow(2,35),gE=Math.pow(2,42),bE=Math.pow(2,49),wE=Math.pow(2,56),xE=Math.pow(2,63),vE=function(r){return r<pE?1:r<hE?2:r<dE?3:r<mE?4:r<yE?5:r<gE?6:r<bE?7:r<wE?8:r<xE?9:10},AE={encode:sE,decode:lE,encodingLength:vE},SE=AE,La=SE;function Ua(r,e=0){return[La.decode(r,e),La.decode.bytes]}function ls(r,e,t=0){return La.encode(r,e,t),e}function fs(r){return La.encodingLength(r)}function Bt(r,e){let t=e.byteLength,n=fs(r),o=n+fs(t),i=new Uint8Array(o+t);return ls(r,i,0),ls(t,i,n),i.set(e,o),new Ho(r,t,e,i)}function ps(r){let e=un(r),[t,n]=Ua(e),[o,i]=Ua(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ho(t,o,s,e)}function Ph(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&f0(r.bytes,t.bytes)}}var Ho=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function EE(r,e){return r.code===e}function x0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return CE(t,Oh(r),e??He.encoder);default:return IE(t,Oh(r),e??Yn.encoder)}}var v0=new WeakMap;function Oh(r){let e=v0.get(r);if(e==null){let t=new Map;return v0.set(r,t),t}return e}var Ye=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!==Ma)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==TE)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&&Ph(e.multihash,n.multihash)}toString(e){return x0(this,e)}toJSON(){return{"/":x0(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??A0(n,o,i.bytes))}else if(t[BE]===!0){let{version:n,multihash:o,code:i}=t,s=ps(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!==Ma)throw new Error(`Version 0 CID must use dag-pb (code: ${Ma}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=A0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ma,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=un(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 Ho(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,m]=Ua(e.subarray(t));return t+=m,p},o=n(),i=Ma;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),l=t+c,h=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:l}}static parse(e,t){let[n,o]=_E(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 Oh(i).set(n,e),i}};function _E(r,e){switch(r[0]){case"Q":{let t=e??He;return[He.prefix,t.decode(`${He.prefix}${r}`)]}case He.prefix:{let t=e??He;return[He.prefix,t.decode(r)]}case Yn.prefix:{let t=e??Yn;return[Yn.prefix,t.decode(r)]}case Ra.prefix:{let t=e??Ra;return[Ra.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 CE(r,e,t){let{prefix:n}=t;if(n!==He.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function IE(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 Ma=112,TE=18;function A0(r,e,t){let n=fs(r),o=n+fs(e),i=new Uint8Array(o+t.byteLength);return ls(r,i,0),ls(e,i,n),i.set(t,o),i}var BE=Symbol.for("@ipld/js-cid/CID");var Nh={};vt(Nh,{identity:()=>Ar});var S0=0,kE="identity",E0=un;function PE(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(S0,E0(r))}var Ar={code:S0,name:kE,encode:E0,digest:PE};function We(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function ot(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function kt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=it(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var C0=Symbol.for("@achingbrain/uint8arraylist");function _0(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 _l(r){return!!r?.[C0]}var we=class r{bufs;length;[C0]=!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(_l(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(_l(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=_0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=_0(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(_l(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 kt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:kt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,h=t>a&&t<=c;if(l&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(h){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!_l(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let p=0;p<i;p++)s[p]=-1;for(let p=0;p<o;p++)s[n[p]]=p;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let m=l;m>=0;m--){let y=this.get(p+m);if(n[m]!==y){h=Math.max(1,m-a[y]);break}}if(h===0)return p}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!We(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Dh={};vt(Dh,{base10:()=>NE});var NE=Zn({prefix:"9",name:"base10",alphabet:"0123456789"});var Rh={};vt(Rh,{base16:()=>DE,base16upper:()=>RE});var DE=Fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),RE=Fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Lh={};vt(Lh,{base2:()=>LE});var LE=Fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Uh={};vt(Uh,{base256emoji:()=>HE});var I0=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}"),UE=I0.reduce((r,e,t)=>(r[t]=e,r),[]),ME=I0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function jE(r){return r.reduce((e,t)=>(e+=UE[t],e),"")}function KE(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=ME[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var HE=us({prefix:"\u{1F680}",name:"base256emoji",encode:jE,decode:KE});var Mh={};vt(Mh,{base64:()=>VE,base64pad:()=>$E,base64url:()=>Vo,base64urlpad:()=>FE});var VE=Fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$E=Fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vo=Fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),FE=Fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jh={};vt(jh,{base8:()=>WE});var WE=Fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kh={};vt(Kh,{identity:()=>qE});var qE=us({prefix:"\0",name:"identity",encode:r=>h0(r),decode:r=>p0(r)});var yk=new TextEncoder,gk=new TextDecoder;var $h={};vt($h,{sha256:()=>ir,sha512:()=>ZE});var XE=20;function Vh({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Hh(r,e,t,n,o)}var Hh=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??XE,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?T0(n,this.code,t?.truncate):n.then(o=>T0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function T0(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 k0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ir=Vh({name:"sha2-256",code:18,encode:k0("SHA-256")}),ZE=Vh({name:"sha2-512",code:19,encode:k0("SHA-512")});var $o={...Kh,...Lh,...jh,...Dh,...Rh,...Th,...Bh,...Ih,...Mh,...Uh},Bk={...$h,...Nh};function O0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var P0=O0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fh=O0("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=it(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),YE={utf8:P0,"utf-8":P0,hex:$o.base16,latin1:Fh,ascii:Fh,binary:Fh,...$o},Cl=YE;function fe(r,e="utf8"){let t=Cl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ce(r,e="utf8"){let t=Cl[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var JE=parseInt("11111",2),Wh=parseInt("10000000",2),QE=parseInt("01111111",2),N0={0:ja,1:ja,2:e_,3:n_,4:o_,5:r_,6:t_,16:ja,22:ja,48:ja};function ln(r,e={offset:0}){let t=r[e.offset]&JE;if(e.offset++,N0[t]!=null)return N0[t](r,e);throw new Error("No decoder for tag "+t)}function Ka(r,e){let t=0;if((r[e.offset]&Wh)===Wh){let n=r[e.offset]&QE,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 ja(r,e){Ka(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=ln(r,e);if(n===null)break;t.push(n)}return t}function e_(r,e){let t=Ka(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 t_(r,e){let t=Ka(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function r_(r,e){return e.offset++,null}function n_(r,e){let t=Ka(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 o_(r,e){let t=Ka(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function i_(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new we;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Il(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=i_(r.byteLength);return new we(Uint8Array.from([e.byteLength|Wh]),e)}function Pt(r){let e=new we,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new we(Uint8Array.from([2]),Il(e),e)}function Ha(r){let e=Uint8Array.from([0]),t=new we(e,r);return new we(Uint8Array.from([3]),Il(t),t)}function D0(r){return new we(Uint8Array.from([4]),Il(r),r)}function Sr(r,e=48){let t=new we;for(let n of r)t.append(n);return new we(Uint8Array.from([e]),Il(t),t)}async function R0(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 L0(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 U0(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 s_=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),a_=Uint8Array.from([6,5,43,129,4,0,34]),c_=Uint8Array.from([6,5,43,129,4,0,35]),u_={ext:!0,kty:"EC",crv:"P-256"},l_={ext:!0,kty:"EC",crv:"P-384"},f_={ext:!0,kty:"EC",crv:"P-521"},qh=32,Gh=48,zh=66;function Xh(r){let e=ln(r);return M0(e)}function M0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===qh*2+1)return n=ce(e.subarray(t,t+qh),"base64url"),o=ce(e.subarray(t+qh),"base64url"),new Fo({...u_,key_ops:["verify"],x:n,y:o});if(e.byteLength===Gh*2+1)return n=ce(e.subarray(t,t+Gh),"base64url"),o=ce(e.subarray(t+Gh),"base64url"),new Fo({...l_,key_ops:["verify"],x:n,y:o});if(e.byteLength===zh*2+1)return n=ce(e.subarray(t,t+zh),"base64url"),o=ce(e.subarray(t+zh),"base64url"),new Fo({...f_,key_ops:["verify"],x:n,y:o});throw new ke(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function j0(r){return Sr([Pt(Uint8Array.from([1])),D0(fe(r.d??"","base64url")),Sr([H0(r.crv)],160),Sr([Ha(new we(Uint8Array.from([4]),fe(r.x??"","base64url"),fe(r.y??"","base64url")))],161)]).subarray()}function K0(r){return Sr([Pt(Uint8Array.from([1])),Sr([H0(r.crv)],160),Sr([Ha(new we(Uint8Array.from([4]),fe(r.x??"","base64url"),fe(r.y??"","base64url")))],161)]).subarray()}function H0(r){if(r==="P-256")return s_;if(r==="P-384")return a_;if(r==="P-521")return c_;throw new ke(`Invalid curve ${r}`)}async function V0(r="P-256"){let e=await R0(r);return new Tl(e.privateKey)}var Fo=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=K0(this.jwk)),this._raw}toMultihash(){return Ar.digest(Jn(this))}toCID(){return Ye.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async verify(e,t,n){return U0(this.jwk,t,e,n)}},Tl=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Fo({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=j0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async sign(e,t){return L0(this.jwk,e,t)}};var Wo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function pn(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function qo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function At(r,...e){if(!pn(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Go(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");qo(r.outputLen),qo(r.blockLen)}function ds(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 F0(r,e){At(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Er(...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 _r(r,e){return r<<32-e|r>>>e}var W0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",p_=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function sr(r){if(At(r),W0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=p_[r[t]];return e}var fn={_0:48,_9:57,A:65,F:70,a:97,f:102};function $0(r){if(r>=fn._0&&r<=fn._9)return r-fn._0;if(r>=fn.A&&r<=fn.F)return r-(fn.A-10);if(r>=fn.a&&r<=fn.f)return r-(fn.a-10)}function zo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(W0)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=$0(r.charCodeAt(i)),a=$0(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 Zh(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Qn(r){return typeof r=="string"&&(r=Zh(r)),At(r),r}function Ot(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];At(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let i=r[n];t.set(i,o),o+=i.length}return t}var hs=class{};function Yh(r){let e=n=>r().update(Qn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function eo(r=32){if(Wo&&typeof Wo.getRandomValues=="function")return Wo.getRandomValues(new Uint8Array(r));if(Wo&&typeof Wo.randomBytes=="function")return Uint8Array.from(Wo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function h_(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function q0(r,e,t){return r&e^~r&t}function G0(r,e,t){return r&e^r&t^e&t}var Va=class extends hs{constructor(e,t,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Bl(this.buffer)}update(e){ds(this),e=Qn(e),At(e);let{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=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){ds(this),F0(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Er(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;h_(n,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 should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<l;p++)a.setUint32(4*p,h[p],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},hn=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 kl=BigInt(4294967295),z0=BigInt(32);function d_(r,e=!1){return e?{h:Number(r&kl),l:Number(r>>z0&kl)}:{h:Number(r>>z0&kl)|0,l:Number(r&kl)|0}}function X0(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}=d_(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var Jh=(r,e,t)=>r>>>t,Qh=(r,e,t)=>r<<32-t|e>>>t,Xo=(r,e,t)=>r>>>t|e<<32-t,Zo=(r,e,t)=>r<<32-t|e>>>t,$a=(r,e,t)=>r<<64-t|e>>>t-32,Fa=(r,e,t)=>r>>>t-32|e<<64-t;function Vr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Z0=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Y0=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,J0=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Q0=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,eb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),tb=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var y_=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]),to=new Uint32Array(64),Pl=class extends Va{constructor(e=32){super(64,e,8,!1),this.A=hn[0]|0,this.B=hn[1]|0,this.C=hn[2]|0,this.D=hn[3]|0,this.E=hn[4]|0,this.F=hn[5]|0,this.G=hn[6]|0,this.H=hn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)to[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let m=to[p-15],y=to[p-2],g=_r(m,7)^_r(m,18)^m>>>3,w=_r(y,17)^_r(y,19)^y>>>10;to[p]=w+to[p-7]+g+to[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:h}=this;for(let p=0;p<64;p++){let m=_r(a,6)^_r(a,11)^_r(a,25),y=h+m+q0(a,c,l)+y_[p]+to[p]|0,w=(_r(n,2)^_r(n,13)^_r(n,22))+G0(n,o,i)|0;h=l,l=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,l,h)}roundClean(){Er(to)}destroy(){this.set(0,0,0,0,0,0,0,0),Er(this.buffer)}};var rb=X0(["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))),g_=rb[0],b_=rb[1],ro=new Uint32Array(80),no=new Uint32Array(80),ed=class extends Va{constructor(e=64){super(128,e,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:h,Fh:p,Fl:m,Gh:y,Gl:g,Hh:w,Hl:b}=this;return[e,t,n,o,i,s,a,c,l,h,p,m,y,g,w,b]}set(e,t,n,o,i,s,a,c,l,h,p,m,y,g,w,b){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=h|0,this.Fh=p|0,this.Fl=m|0,this.Gh=y|0,this.Gl=g|0,this.Hh=w|0,this.Hl=b|0}process(e,t){for(let T=0;T<16;T++,t+=4)ro[T]=e.getUint32(t),no[T]=e.getUint32(t+=4);for(let T=16;T<80;T++){let V=ro[T-15]|0,Y=no[T-15]|0,z=Xo(V,Y,1)^Xo(V,Y,8)^Jh(V,Y,7),te=Zo(V,Y,1)^Zo(V,Y,8)^Qh(V,Y,7),X=ro[T-2]|0,B=no[T-2]|0,j=Xo(X,B,19)^$a(X,B,61)^Jh(X,B,6),q=Zo(X,B,19)^Fa(X,B,61)^Qh(X,B,6),H=J0(te,q,no[T-7],no[T-16]),x=Q0(H,z,j,ro[T-7],ro[T-16]);ro[T]=x|0,no[T]=H|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:h,Eh:p,El:m,Fh:y,Fl:g,Gh:w,Gl:b,Hh:E,Hl:D}=this;for(let T=0;T<80;T++){let V=Xo(p,m,14)^Xo(p,m,18)^$a(p,m,41),Y=Zo(p,m,14)^Zo(p,m,18)^Fa(p,m,41),z=p&y^~p&w,te=m&g^~m&b,X=eb(D,Y,te,b_[T],no[T]),B=tb(X,E,V,z,g_[T],ro[T]),j=X|0,q=Xo(n,o,28)^$a(n,o,34)^$a(n,o,39),H=Zo(n,o,28)^Fa(n,o,34)^Fa(n,o,39),x=n&i^n&a^i&a,v=o&s^o&c^s&c;E=w|0,D=b|0,w=y|0,b=g|0,y=p|0,g=m|0,{h:p,l:m}=Vr(l|0,h|0,B|0,j|0),l=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let _=Z0(j,H,v);n=Y0(_,B,q,x),o=_|0}({h:n,l:o}=Vr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Vr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Vr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=Vr(this.Dh|0,this.Dl|0,l|0,h|0),{h:p,l:m}=Vr(this.Eh|0,this.El|0,p|0,m|0),{h:y,l:g}=Vr(this.Fh|0,this.Fl|0,y|0,g|0),{h:w,l:b}=Vr(this.Gh|0,this.Gl|0,w|0,b|0),{h:E,l:D}=Vr(this.Hh|0,this.Hl|0,E|0,D|0),this.set(n,o,i,s,a,c,l,h,p,m,y,g,w,b,E,D)}roundClean(){Er(ro,no)}destroy(){Er(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ol=Yh(()=>new Pl);var nb=Yh(()=>new ed);var nd=BigInt(0),rd=BigInt(1);function dn(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}"`;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function Xt(r,e,t=""){let n=pn(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 Wa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function ob(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?nd:BigInt("0x"+r)}function ms(r){return ob(sr(r))}function ar(r){return At(r),ob(sr(Uint8Array.from(r).reverse()))}function Nl(r,e){return zo(r.toString(16).padStart(e*2,"0"))}function qa(r,e){return Nl(r,e).reverse()}function _e(r,e,t){let n;if(typeof e=="string")try{n=zo(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(pn(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function ib(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}function od(r){return Uint8Array.from(r)}var td=r=>typeof r=="bigint"&&nd<=r;function sb(r,e,t){return td(r)&&td(e)&&td(t)&&e<=r&&r<t}function oo(r,e,t,n){if(!sb(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Dl(r){let e;for(e=0;r>nd;r>>=rd,e+=1);return e}var io=r=>(rd<<BigInt(r))-rd;function ab(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},l=(...y)=>t(s,i,...y),h=(y=n(0))=>{s=l(o(0),y),i=l(),y.length!==0&&(s=l(o(1),y),i=l())},p=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,g=[];for(;y<e;){i=l();let w=i.slice();g.push(w),y+=i.length}return Ot(...g)};return(y,g)=>{c(),h(y);let w;for(;!(w=g(p()));)h();return c(),w}}function $r(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}var id=()=>{throw new Error("not implemented")};function ys(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 Nt=BigInt(0),at=BigInt(1),Yo=BigInt(2),lb=BigInt(3),fb=BigInt(4),pb=BigInt(5),w_=BigInt(7),hb=BigInt(8),x_=BigInt(9),db=BigInt(16);function Ue(r,e){let t=r%e;return t>=Nt?t:e+t}function Me(r,e,t){let n=r;for(;e-- >Nt;)n*=n,n%=t;return n}function cb(r,e){if(r===Nt)throw new Error("invert: expected non-zero number");if(e<=Nt)throw new Error("invert: expected positive modulus, got "+e);let t=Ue(r,e),n=e,o=Nt,i=at,s=at,a=Nt;for(;t!==Nt;){let l=n/t,h=n%t,p=o-s*l,m=i-a*l;n=t,t=h,o=s,i=a,s=p,a=m}if(n!==at)throw new Error("invert: does not exist");return Ue(o,e)}function sd(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function mb(r,e){let t=(r.ORDER+at)/fb,n=r.pow(e,t);return sd(r,n,e),n}function v_(r,e){let t=(r.ORDER-pb)/hb,n=r.mul(e,Yo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Yo),o),a=r.mul(i,r.sub(s,r.ONE));return sd(r,a,e),a}function A_(r){let e=Zt(r),t=yb(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+w_)/db;return(a,c)=>{let l=a.pow(c,s),h=a.mul(l,n),p=a.mul(l,o),m=a.mul(l,i),y=a.eql(a.sqr(h),c),g=a.eql(a.sqr(p),c);l=a.cmov(l,h,y),h=a.cmov(m,p,g);let w=a.eql(a.sqr(h),c),b=a.cmov(l,h,w);return sd(a,b,c),b}}function yb(r){if(r<lb)throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Yo===Nt;)e/=Yo,t++;let n=Yo,o=Zt(r);for(;ub(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return mb;let i=o.pow(n,e),s=(e+at)/Yo;return function(c,l){if(c.is0(l))return l;if(ub(c,l)!==1)throw new Error("Cannot find square root");let h=t,p=c.mul(c.ONE,i),m=c.pow(l,e),y=c.pow(l,s);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let g=1,w=c.sqr(m);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===h)throw new Error("Cannot find square root");let b=at<<BigInt(h-g-1),E=c.pow(p,b);h=g,p=c.sqr(E),m=c.mul(m,p),y=c.mul(y,E)}return y}}function S_(r){return r%fb===lb?mb:r%hb===pb?v_:r%db===x_?A_(r):yb(r)}var mn=(r,e)=>(Ue(r,e)&at)===at,E_=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ad(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=E_.reduce((n,o)=>(n[o]="function",n),e);return $r(r,t),r}function __(r,e,t){if(t<Nt)throw new Error("invalid exponent, negatives unsupported");if(t===Nt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>Nt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function Ga(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 ub(r,e){let t=(r.ORDER-at)/Yo,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 Rl(r,e){e!==void 0&&qo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Zt(r,e,t=!1,n={}){if(r<=Nt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i,s=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let m=e;m.BITS&&(o=m.BITS),m.sqrt&&(i=m.sqrt),typeof m.isLE=="boolean"&&(t=m.isLE),typeof m.modFromBytes=="boolean"&&(s=m.modFromBytes),a=m.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:l}=Rl(r,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,p=Object.freeze({ORDER:r,isLE:t,BITS:c,BYTES:l,MASK:io(c),ZERO:Nt,ONE:at,allowedLengths:a,create:m=>Ue(m,r),isValid:m=>{if(typeof m!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof m);return Nt<=m&&m<r},is0:m=>m===Nt,isValidNot0:m=>!p.is0(m)&&p.isValid(m),isOdd:m=>(m&at)===at,neg:m=>Ue(-m,r),eql:(m,y)=>m===y,sqr:m=>Ue(m*m,r),add:(m,y)=>Ue(m+y,r),sub:(m,y)=>Ue(m-y,r),mul:(m,y)=>Ue(m*y,r),pow:(m,y)=>__(p,m,y),div:(m,y)=>Ue(m*cb(y,r),r),sqrN:m=>m*m,addN:(m,y)=>m+y,subN:(m,y)=>m-y,mulN:(m,y)=>m*y,inv:m=>cb(m,r),sqrt:i||(m=>(h||(h=S_(r)),h(p,m))),toBytes:m=>t?qa(m,l):Nl(m,l),fromBytes:(m,y=!0)=>{if(a){if(!a.includes(m.length)||m.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+m.length);let w=new Uint8Array(l);w.set(m,t?0:w.length-m.length),m=w}if(m.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+m.length);let g=t?ar(m):ms(m);if(s&&(g=Ue(g,r)),!y&&!p.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:m=>Ga(p,m),cmov:(m,y,g)=>g?y:m});return Object.freeze(p)}function gb(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 cd(r){let e=gb(r);return e+Math.ceil(e/2)}function ud(r,e,t=!1){let n=r.length,o=gb(e),i=cd(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?ar(r):ms(r),a=Ue(s,e-at)+at;return t?qa(a,o):Nl(a,o)}var gs=BigInt(0),Jo=BigInt(1);function za(r,e){let t=e.negate();return r?t:e}function yn(r,e){let t=Ga(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function vb(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function ld(r,e){vb(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=io(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function bb(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+=Jo);let l=e*n,h=l+Math.abs(a)-1,p=a===0,m=a<0,y=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:m,isNegF:y,offsetF:l}}function C_(r,e){if(!Array.isArray(r))throw new Error("array expected");r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function I_(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var fd=new WeakMap,Ab=new WeakMap;function pd(r){return Ab.get(r)||1}function wb(r){if(r!==gs)throw new Error("invalid wNAF")}var bs=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>gs;)t&Jo&&(n=n.add(o)),o=o.double(),t>>=Jo;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=ld(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let l=1;l<o;l++)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=ld(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:l,isZero:h,isNeg:p,isNegF:m,offsetF:y}=bb(n,a,s);n=c,h?i=i.add(za(m,t[y])):o=o.add(za(p,t[l]))}return wb(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=ld(e,this.bits);for(let s=0;s<i.windows&&n!==gs;s++){let{nextN:a,offset:c,isZero:l,isNeg:h}=bb(n,s,i);if(n=a,!l){let p=t[c];o=o.add(h?p.negate():p)}}return wb(n),o}getPrecomputes(e,t,n){let o=fd.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),fd.set(t,o))),o}cached(e,t,n){let o=pd(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=pd(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){vb(t,this.bits),Ab.set(e,t),fd.delete(e)}hasCache(e){return pd(e)!==1}};function Sb(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>gs||n>gs;)t&Jo&&(i=i.add(o)),n&Jo&&(s=s.add(o)),o=o.double(),t>>=Jo,n>>=Jo;return{p1:i,p2:s}}function ws(r,e,t,n){C_(t,r),I_(n,e);let o=t.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,a=Dl(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=io(c),h=new Array(Number(l)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,m=s;for(let y=p;y>=0;y-=c){h.fill(s);for(let w=0;w<i;w++){let b=n[w],E=Number(b>>BigInt(y)&l);h[E]=h[E].add(t[w])}let g=s;for(let w=h.length-1,b=s;w>0;w--)b=b.add(h[w]),g=g.add(b);if(m=m.add(g),y!==0)for(let w=0;w<c;w++)m=m.double()}return m}function xb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ad(e),e}else return Zt(r,{isLE:t})}function Ll(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 l=e[c];if(!(typeof l=="bigint"&&l>gs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=xb(e.p,t.Fp,n),i=xb(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}}var so=BigInt(0),ct=BigInt(1),hd=BigInt(2),T_=BigInt(8);function B_(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 k_(r,e={}){let t=Ll("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;$r(e,{},{uvRatio:"function"});let a=hd<<BigInt(o.BYTES*8)-ct,c=b=>n.create(b),l=e.uvRatio||((b,E)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,E))}}catch{return{isValid:!1,value:so}}});if(!B_(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(b,E,D=!1){let T=D?ct:so;return oo("coordinate "+b,E,T,a),E}function p(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let m=ys((b,E)=>{let{X:D,Y:T,Z:V}=b,Y=b.is0();E==null&&(E=Y?T_:n.inv(V));let z=c(D*E),te=c(T*E),X=n.mul(V,E);if(Y)return{x:so,y:ct};if(X!==ct)throw new Error("invZ was invalid");return{x:z,y:te}}),y=ys(b=>{let{a:E,d:D}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:T,Y:V,Z:Y,T:z}=b,te=c(T*T),X=c(V*V),B=c(Y*Y),j=c(B*B),q=c(te*E),H=c(B*c(q+X)),x=c(j+c(D*c(te*X)));if(H!==x)throw new Error("bad point: equation left != right (1)");let v=c(T*V),_=c(Y*z);if(v!==_)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(E,D,T,V){this.X=h("x",E),this.Y=h("y",D),this.Z=h("z",T,!0),this.T=h("t",V),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){if(E instanceof g)throw new Error("extended point not allowed");let{x:D,y:T}=E||{};return h("x",D),h("y",T),new g(D,T,ct,c(D*T))}static fromBytes(E,D=!1){let T=n.BYTES,{a:V,d:Y}=i;E=od(Xt(E,T,"point")),dn(D,"zip215");let z=od(E),te=E[T-1];z[T-1]=te&-129;let X=ar(z),B=D?a:n.ORDER;oo("point.y",X,so,B);let j=c(X*X),q=c(j-ct),H=c(Y*j-V),{isValid:x,value:v}=l(q,H);if(!x)throw new Error("bad point: invalid y coordinate");let _=(v&ct)===ct,P=(te&128)!==0;if(!D&&v===so&&P)throw new Error("bad point: x=0 and x_0=1");return P!==_&&(v=c(-v)),g.fromAffine({x:v,y:X})}static fromHex(E,D=!1){return g.fromBytes(_e("point",E),D)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,D=!0){return w.createCache(this,E),D||this.multiply(hd),this}assertValidity(){y(this)}equals(E){p(E);let{X:D,Y:T,Z:V}=this,{X:Y,Y:z,Z:te}=E,X=c(D*te),B=c(Y*V),j=c(T*te),q=c(z*V);return X===B&&j===q}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:E}=i,{X:D,Y:T,Z:V}=this,Y=c(D*D),z=c(T*T),te=c(hd*c(V*V)),X=c(E*Y),B=D+T,j=c(c(B*B)-Y-z),q=X+z,H=q-te,x=X-z,v=c(j*H),_=c(q*x),P=c(j*x),R=c(H*q);return new g(v,_,R,P)}add(E){p(E);let{a:D,d:T}=i,{X:V,Y,Z:z,T:te}=this,{X,Y:B,Z:j,T:q}=E,H=c(V*X),x=c(Y*B),v=c(te*T*q),_=c(z*j),P=c((V+Y)*(X+B)-H-x),R=_-v,U=_+v,k=c(x-D*H),L=c(P*R),W=c(U*k),N=c(P*k),pe=c(R*U);return new g(L,W,pe,N)}subtract(E){return this.add(E.negate())}multiply(E){if(!o.isValidNot0(E))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:D,f:T}=w.cached(this,E,V=>yn(g,V));return yn(g,[D,T])[0]}multiplyUnsafe(E,D=g.ZERO){if(!o.isValid(E))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return E===so?g.ZERO:this.is0()||E===ct?this:w.unsafe(this,E,T=>yn(g,T),D)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return w.unsafe(this,i.n).is0()}toAffine(E){return m(this,E)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:E,y:D}=this.toAffine(),T=n.toBytes(D);return T[T.length-1]|=E&ct?128:0,T}toHex(){return sr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(E){return yn(g,E)}static msm(E,D){return ws(g,o,E,D)}_setWindowSize(E){this.precompute(E)}toRawBytes(){return this.toBytes()}}g.BASE=new g(i.Gx,i.Gy,ct,c(i.Gx*i.Gy)),g.ZERO=new g(so,ct,ct,so),g.Fp=n,g.Fn=o;let w=new bs(g,o.BITS);return g.BASE.precompute(8),g}var Ul=class{constructor(e){this.ep=e}static fromBytes(e){id()}static fromHex(e){id()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return sr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}toRawBytes(){return this.toBytes()}};function P_(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');$r(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||eo,c=t.adjustScalarBytes||(B=>B),l=t.domain||((B,j,q)=>{if(dn(q,"phflag"),j.length||q)throw new Error("Contexts/pre-hash are not supported");return B});function h(B){return s.create(ar(B))}function p(B){let j=T.secretKey;B=_e("private key",B,j);let q=_e("hashed private key",e(B),2*j),H=c(q.slice(0,j)),x=q.slice(j,2*j),v=h(H);return{head:H,prefix:x,scalar:v}}function m(B){let{head:j,prefix:q,scalar:H}=p(B),x=o.multiply(H),v=x.toBytes();return{head:j,prefix:q,scalar:H,point:x,pointBytes:v}}function y(B){return m(B).pointBytes}function g(B=Uint8Array.of(),...j){let q=Ot(...j);return h(e(l(q,_e("context",B),!!n)))}function w(B,j,q={}){B=_e("message",B),n&&(B=n(B));let{prefix:H,scalar:x,pointBytes:v}=m(j),_=g(q.context,H,B),P=o.multiply(_).toBytes(),R=g(q.context,P,v,B),U=s.create(_+R*x);if(!s.isValid(U))throw new Error("sign failed: invalid s");let k=Ot(P,s.toBytes(U));return Xt(k,T.signature,"result")}let b={zip215:!0};function E(B,j,q,H=b){let{context:x,zip215:v}=H,_=T.signature;B=_e("signature",B,_),j=_e("message",j),q=_e("publicKey",q,T.publicKey),v!==void 0&&dn(v,"zip215"),n&&(j=n(j));let P=_/2,R=B.subarray(0,P),U=ar(B.subarray(P,_)),k,L,W;try{k=r.fromBytes(q,v),L=r.fromBytes(R,v),W=o.multiplyUnsafe(U)}catch{return!1}if(!v&&k.isSmallOrder())return!1;let N=g(x,L.toBytes(),k.toBytes(),j);return L.add(k.multiplyUnsafe(N)).subtract(W).clearCofactor().is0()}let D=i.BYTES,T={secretKey:D,publicKey:D,signature:2*D,seed:D};function V(B=a(T.seed)){return Xt(B,T.seed,"seed")}function Y(B){let j=X.randomSecretKey(B);return{secretKey:j,publicKey:y(j)}}function z(B){return pn(B)&&B.length===s.BYTES}function te(B,j){try{return!!r.fromBytes(B,j)}catch{return!1}}let X={getExtendedPublicKey:m,randomSecretKey:V,isValidSecretKey:z,isValidPublicKey:te,toMontgomery(B){let{y:j}=r.fromBytes(B),q=T.publicKey,H=q===32;if(!H&&q!==57)throw new Error("only defined for 25519 and 448");let x=H?i.div(ct+j,ct-j):i.div(j-ct,j+ct);return i.toBytes(x)},toMontgomerySecret(B){let j=T.secretKey;Xt(B,j);let q=e(B.subarray(0,j));return c(q).subarray(0,j)},randomPrivateKey:V,precompute(B=8,j=r.BASE){return j.precompute(B,!1)}};return Object.freeze({keygen:Y,getPublicKey:y,sign:w,verify:E,utils:X,Point:r,lengths:T})}function O_(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=Zt(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,hash:r.hash,eddsaOpts:i}}function N_(r,e){let t=e.Point;return Object.assign({},e,{ExtendedPoint:t,CURVE:r,nBitLength:t.Fn.BITS,nByteLength:t.Fn.BYTES})}function Eb(r){let{CURVE:e,curveOpts:t,hash:n,eddsaOpts:o}=O_(r),i=k_(e,t),s=P_(i,n,o);return N_(r,s)}var Xa=BigInt(0),xs=BigInt(1),Ml=BigInt(2);function D_(r){return $r(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function _b(r){let e=D_(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||eo,l=a?255:448,h=a?32:56,p=BigInt(a?9:5),m=BigInt(a?121665:39081),y=a?Ml**BigInt(254):Ml**BigInt(447),g=a?BigInt(8)*Ml**BigInt(251)-xs:BigInt(4)*Ml**BigInt(445)-xs,w=y+g+xs,b=x=>Ue(x,t),E=D(p);function D(x){return qa(b(x),h)}function T(x){let v=_e("u coordinate",x,h);return a&&(v[31]&=127),b(ar(v))}function V(x){return ar(o(_e("scalar",x,h)))}function Y(x,v){let _=X(T(v),V(x));if(_===Xa)throw new Error("invalid private or public key received");return D(_)}function z(x){return Y(x,E)}function te(x,v,_){let P=b(x*(v-_));return v=b(v-P),_=b(_+P),{x_2:v,x_3:_}}function X(x,v){oo("u",x,Xa,t),oo("scalar",v,y,w);let _=v,P=x,R=xs,U=Xa,k=x,L=xs,W=Xa;for(let pe=BigInt(l-1);pe>=Xa;pe--){let me=_>>pe&xs;W^=me,{x_2:R,x_3:k}=te(W,R,k),{x_2:U,x_3:L}=te(W,U,L),W=me;let Q=R+U,xe=b(Q*Q),Ee=R-U,Oe=b(Ee*Ee),ve=xe-Oe,Be=k+L,cn=k-L,or=b(cn*Q),Gn=b(Be*Ee),pl=or+Gn,ss=or-Gn;k=b(pl*pl),L=b(P*b(ss*ss)),R=b(xe*Oe),U=b(ve*(xe+b(m*ve)))}({x_2:R,x_3:k}=te(W,R,k)),{x_2:U,x_3:L}=te(W,U,L);let N=i(U);return b(R*N)}let B={secretKey:h,publicKey:h,seed:h},j=(x=c(h))=>(At(x,B.seed),x);function q(x){let v=j(x);return{secretKey:v,publicKey:z(v)}}return{keygen:q,getSharedSecret:(x,v)=>Y(x,v),getPublicKey:x=>z(x),scalarMult:Y,scalarMultBase:z,utils:{randomSecretKey:j,randomPrivateKey:j},GuBytes:E.slice(),lengths:B}}var R_=BigInt(0),bn=BigInt(1),Cb=BigInt(2),L_=BigInt(3),U_=BigInt(5),M_=BigInt(8),vs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Za={p:vs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:M_,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Bb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=vs,a=r*r%i*r%i,c=Me(a,Cb,i)*a%i,l=Me(c,bn,i)*r%i,h=Me(l,U_,i)*l%i,p=Me(h,e,i)*h%i,m=Me(p,t,i)*p%i,y=Me(m,n,i)*m%i,g=Me(y,o,i)*y%i,w=Me(g,o,i)*y%i,b=Me(w,e,i)*h%i;return{pow_p_5_8:Me(b,Cb,i)*r%i,b2:a}}function kb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var dd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gd(r,e){let t=vs,n=Ue(e*e*e,t),o=Ue(n*n*e,t),i=Bb(r*o).pow_p_5_8,s=Ue(r*n*i,t),a=Ue(e*s*s,t),c=s,l=Ue(s*dd,t),h=a===r,p=a===Ue(-r,t),m=a===Ue(-r*dd,t);return h&&(s=c),(p||m)&&(s=l),mn(s,t)&&(s=Ue(-s,t)),{isValid:h||p,value:s}}var gn=Zt(Za.p,{isLE:!0}),j_=Zt(Za.n,{isLE:!0}),K_={...Za,Fp:gn,hash:nb,adjustScalarBytes:kb,uvRatio:gd},cr=Eb(K_);var Ya=(()=>{let r=gn.ORDER;return _b({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=Bb(e);return Ue(Me(t,L_,r)*n,r)},adjustScalarBytes:kb})})();var md=dd,H_=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),V_=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$_=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),F_=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ib=r=>gd(bn,r),W_=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),yd=r=>cr.Point.Fp.create(ar(r)&W_);function Tb(r){let{d:e}=Za,t=vs,n=E=>gn.create(E),o=n(md*r*r),i=n((o+bn)*$_),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:l}=gd(i,a),h=n(l*r);mn(h,t)||(h=n(-h)),c||(l=h),c||(s=o);let p=n(s*(o-bn)*F_-a),m=l*l,y=n((l+l)*a),g=n(p*H_),w=n(bn-m),b=n(bn+m);return new cr.Point(n(y*b),n(w*g),n(g*b),n(y*w))}function q_(r){At(r,64);let e=yd(r.subarray(0,32)),t=Tb(e),n=yd(r.subarray(32,64)),o=Tb(n);return new wn(t.add(o))}var wn=class r extends Ul{constructor(e){super(e)}static fromAffine(e){return new r(cr.Point.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static hashToCurve(e){return q_(_e("ristrettoHash",e,64))}static fromBytes(e){At(e,32);let{a:t,d:n}=Za,o=vs,i=V=>gn.create(V),s=yd(e);if(!ib(gn.toBytes(s),e)||mn(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(bn+t*a),l=i(bn-t*a),h=i(c*c),p=i(l*l),m=i(t*n*h-p),{isValid:y,value:g}=Ib(i(m*p)),w=i(g*l),b=i(g*w*m),E=i((s+s)*w);mn(E,o)&&(E=i(-E));let D=i(c*b),T=i(E*D);if(!y||mn(T,o)||D===R_)throw new Error("invalid ristretto255 encoding 2");return new r(new cr.Point(E,D,bn,T))}static fromHex(e){return r.fromBytes(_e("ristrettoHex",e,32))}static msm(e,t){return ws(r,cr.Point.Fn,e,t)}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,i=vs,s=b=>gn.create(b),a=s(s(n+t)*s(n-t)),c=s(e*t),l=s(c*c),{value:h}=Ib(s(a*l)),p=s(h*a),m=s(h*c),y=s(p*m*o),g;if(mn(o*y,i)){let b=s(t*md),E=s(e*md);e=b,t=E,g=s(p*V_)}else g=m;mn(e*y,i)&&(t=s(-t));let w=s((n-t)*g);return mn(w,i)&&(w=s(-w)),gn.toBytes(w)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=l=>gn.create(l),a=s(t*i)===s(n*o),c=s(n*i)===s(t*o);return a||c}is0(){return this.equals(r.ZERO)}};wn.BASE=new wn(cr.Point.BASE);wn.ZERO=new wn(cr.Point.ZERO);wn.Fp=gn;wn.Fn=j_;var Ja=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Qa=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},jl=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Pb={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new jl("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Mt=Pb;var Kl=32,ec=64,bd=32;var As,Ob=(async()=>{try{return await Mt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Nb(){let r=cr.utils.randomPrivateKey(),e=cr.getPublicKey(r);return{privateKey:Y_(r,e),publicKey:e}}async function G_(r,e){let t;r.length===ec?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:ce(r.subarray(32),"base64url"),d:ce(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Mt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Mt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function z_(r,e){let t=r.subarray(0,bd);return cr.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function Db(r,e){return As==null&&(As=await Ob),As?G_(r,e):z_(r,e)}async function X_(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Mt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Mt.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Z_(r,e,t){return cr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Rb(r,e,t){return As==null&&(As=await Ob),As?X_(r,e,t):Z_(r,e,t)}function Y_(r,e){let t=new Uint8Array(ec);for(let n=0;n<bd;n++)t[n]=r[n],t[bd+n]=e[n];return t}function Ss(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var tc=class{type="Ed25519";raw;constructor(e){this.raw=Vl(e,Kl)}toMultihash(){return Ar.digest(Jn(this))}toCID(){return Ye.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=Rb(this.raw,t,e);return Ss(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},Hl=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Vl(e,ec),this.publicKey=new tc(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=Db(this.raw,e);return Ss(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function wd(r){return r=Vl(r,Kl),new tc(r)}async function Ub(){let{privateKey:r,publicKey:e}=Nb();return new Hl(r,e)}function Vl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ke(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var J_=Math.pow(2,7),Q_=Math.pow(2,14),e2=Math.pow(2,21),xd=Math.pow(2,28),vd=Math.pow(2,35),Ad=Math.pow(2,42),Sd=Math.pow(2,49),Ie=128,St=127;function Ve(r){if(r<J_)return 1;if(r<Q_)return 2;if(r<e2)return 3;if(r<xd)return 4;if(r<vd)return 5;if(r<Ad)return 6;if(r<Sd)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Es(r,e,t=0){switch(Ve(r)){case 8:e[t++]=r&255|Ie,r/=128;case 7:e[t++]=r&255|Ie,r/=128;case 6:e[t++]=r&255|Ie,r/=128;case 5:e[t++]=r&255|Ie,r/=128;case 4:e[t++]=r&255|Ie,r>>>=7;case 3:e[t++]=r&255|Ie,r>>>=7;case 2:e[t++]=r&255|Ie,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function t2(r,e,t=0){switch(Ve(r)){case 8:e.set(t++,r&255|Ie),r/=128;case 7:e.set(t++,r&255|Ie),r/=128;case 6:e.set(t++,r&255|Ie),r/=128;case 5:e.set(t++,r&255|Ie),r/=128;case 4:e.set(t++,r&255|Ie),r>>>=7;case 3:e.set(t++,r&255|Ie),r>>>=7;case 2:e.set(t++,r&255|Ie),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Ed(r,e){let t=r[e],n=0;if(n+=t&St,t<Ie||(t=r[e+1],n+=(t&St)<<7,t<Ie)||(t=r[e+2],n+=(t&St)<<14,t<Ie)||(t=r[e+3],n+=(t&St)<<21,t<Ie)||(t=r[e+4],n+=(t&St)*xd,t<Ie)||(t=r[e+5],n+=(t&St)*vd,t<Ie)||(t=r[e+6],n+=(t&St)*Ad,t<Ie)||(t=r[e+7],n+=(t&St)*Sd,t<Ie))return n;throw new RangeError("Could not decode varint")}function r2(r,e){let t=r.get(e),n=0;if(n+=t&St,t<Ie||(t=r.get(e+1),n+=(t&St)<<7,t<Ie)||(t=r.get(e+2),n+=(t&St)<<14,t<Ie)||(t=r.get(e+3),n+=(t&St)<<21,t<Ie)||(t=r.get(e+4),n+=(t&St)*xd,t<Ie)||(t=r.get(e+5),n+=(t&St)*vd,t<Ie)||(t=r.get(e+6),n+=(t&St)*Ad,t<Ie)||(t=r.get(e+7),n+=(t&St)*Sd,t<Ie))return n;throw new RangeError("Could not decode varint")}function $l(r,e,t=0){return e==null&&(e=it(Ve(r))),e instanceof Uint8Array?Es(r,e,t):t2(r,e,t)}function Qo(r,e=0){return r instanceof Uint8Array?Ed(r,e):r2(r,e)}var _d=new Float32Array([-0]),ao=new Uint8Array(_d.buffer);function Mb(r,e,t){_d[0]=r,e[t]=ao[0],e[t+1]=ao[1],e[t+2]=ao[2],e[t+3]=ao[3]}function jb(r,e){return ao[0]=r[e],ao[1]=r[e+1],ao[2]=r[e+2],ao[3]=r[e+3],_d[0]}var Cd=new Float64Array([-0]),Et=new Uint8Array(Cd.buffer);function Kb(r,e,t){Cd[0]=r,e[t]=Et[0],e[t+1]=Et[1],e[t+2]=Et[2],e[t+3]=Et[3],e[t+4]=Et[4],e[t+5]=Et[5],e[t+6]=Et[6],e[t+7]=Et[7]}function Hb(r,e){return Et[0]=r[e],Et[1]=r[e+1],Et[2]=r[e+2],Et[3]=r[e+3],Et[4]=r[e+4],Et[5]=r[e+5],Et[6]=r[e+6],Et[7]=r[e+7],Cd[0]}var n2=BigInt(Number.MAX_SAFE_INTEGER),o2=BigInt(Number.MIN_SAFE_INTEGER),Yt=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 ei;if(e<n2&&e>o2)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Vb&&(o=0n,++n>Vb&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return ei;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):ei}},ei=new Yt(0,0);ei.toBigInt=function(){return 0n};ei.zzEncode=ei.zzDecode=function(){return this};ei.length=function(){return 1};var Vb=4294967296n;function $b(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Fb(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 Id(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 Cr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Wl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Td=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,Cr(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 Cr(this,4);return Wl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Cr(this,4);return Wl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Cr(this,4);let e=jb(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Cr(this,4);let e=Hb(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 Cr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Fb(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Cr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Cr(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 Yt(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 Cr(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 Cr(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 Cr(this,8);let e=Wl(this.buf,this.pos+=4),t=Wl(this.buf,this.pos+=4);return new Yt(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=Ed(this.buf,this.pos);return this.pos+=Ve(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Bd(r){return new Td(r instanceof Uint8Array?r:r.subarray())}function Ir(r,e,t){let n=Bd(r);return e.decode(n,void 0,t)}function kd(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return it(s);o+s>e&&(n=it(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ti=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Pd(){}var Nd=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},i2=kd();function s2(r){return globalThis.Buffer!=null?it(r):i2(r)}var nc=class{len;head;tail;states;constructor(){this.len=0,this.head=new ti(Pd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ti(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(ql,10,Yt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Yt.fromBigInt(e);return this._push(ql,t.length(),t)}uint64Number(e){return this._push(Es,Ve(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Yt.fromBigInt(e).zzEncode();return this._push(ql,t.length(),t)}sint64Number(e){let t=Yt.fromNumber(e).zzEncode();return this._push(ql,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Od,1,e?1:0)}fixed32(e){return this._push(rc,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Yt.fromBigInt(e);return this._push(rc,4,t.lo)._push(rc,4,t.hi)}fixed64Number(e){let t=Yt.fromNumber(e);return this._push(rc,4,t.lo)._push(rc,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(Mb,4,e)}double(e){return this._push(Kb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Od,1,0):this.uint32(t)._push(c2,t,e)}string(e){let t=$b(e);return t!==0?this.uint32(t)._push(Id,t,e):this._push(Od,1,0)}fork(){return this.states=new Nd(this),this.head=this.tail=new ti(Pd,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ti(Pd,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=s2(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Od(r,e,t){e[t]=r&255}function a2(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Dd=class extends ti{next;constructor(e,t){super(a2,e,t),this.next=void 0}};function ql(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 rc(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 c2(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(nc.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(u2,e,r),this},nc.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(l2,e,r),this});function u2(r,e,t){e.set(r,t)}function l2(r,e,t){r.length<40?Id(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(fe(r),t)}function Rd(){return new nc}function Tr(r,e){let t=Rd();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var _s;(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"})(_s||(_s={}));function Gl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function ri(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 Gl("enum",_s.VARINT,t,n)}function Br(r,e){return Gl("message",_s.LENGTH_DELIMITED,r,e)}var oc=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Je;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Je||(Je={}));var Ld;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Ld||(Ld={}));(function(r){r.codec=()=>ri(Ld)})(Je||(Je={}));var Fr;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Je.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=Je.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Tr(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Fr||(Fr={}));var Ud;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Je.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=Je.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Tr(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(Ud||(Ud={}));var sc={};vt(sc,{MAX_RSA_KEY_SIZE:()=>Md,generateRSAKeyPair:()=>Gd,jwkToJWKKeyPair:()=>Zb,jwkToPkcs1:()=>d2,jwkToPkix:()=>Vd,jwkToRSAPrivateKey:()=>qd,pkcs1MessageToJwk:()=>Kd,pkcs1MessageToRSAPrivateKey:()=>$d,pkcs1ToJwk:()=>h2,pkcs1ToRSAPrivateKey:()=>Xb,pkixMessageToJwk:()=>Hd,pkixMessageToRSAPublicKey:()=>Wd,pkixToJwk:()=>m2,pkixToRSAPublicKey:()=>Fd});var co=Ol;var Cs=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=sc.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Ye.createV1(114,this._multihash)}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return zb(this.jwk,t,e,n)}},ic=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=sc.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return Gb(this.jwk,e,t)}};var Md=8192,jd=18,f2=1062,p2=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function h2(r){let e=ln(r);return Kd(e)}function Kd(r){return{n:ce(r[1],"base64url"),e:ce(r[2],"base64url"),d:ce(r[3],"base64url"),p:ce(r[4],"base64url"),q:ce(r[5],"base64url"),dp:ce(r[6],"base64url"),dq:ce(r[7],"base64url"),qi:ce(r[8],"base64url"),kty:"RSA"}}function d2(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ke("JWK was missing components");return Sr([Pt(Uint8Array.from([0])),Pt(fe(r.n,"base64url")),Pt(fe(r.e,"base64url")),Pt(fe(r.d,"base64url")),Pt(fe(r.p,"base64url")),Pt(fe(r.q,"base64url")),Pt(fe(r.dp,"base64url")),Pt(fe(r.dq,"base64url")),Pt(fe(r.qi,"base64url"))]).subarray()}function m2(r){let e=ln(r,{offset:0});return Hd(e)}function Hd(r){let e=ln(r[1],{offset:0});return{kty:"RSA",n:ce(e[0],"base64url"),e:ce(e[1],"base64url")}}function Vd(r){if(r.n==null||r.e==null)throw new ke("JWK was missing components");return Sr([p2,Ha(Sr([Pt(fe(r.n,"base64url")),Pt(fe(r.e,"base64url"))]))]).subarray()}function Xb(r){let e=ln(r);return $d(e)}function $d(r){let e=Kd(r);return qd(e)}function Fd(r,e){if(r.byteLength>=f2)throw new as("Key size is too large");let t=ln(r,{offset:0});return Wd(t,r,e)}function Wd(r,e,t){let n=Hd(r);if(t==null){let o=co(Fr.encode({Type:Je.RSA,Data:e}));t=Bt(jd,o)}return new Cs(n,t)}function qd(r){if(Jb(r)>Md)throw new ke("Key size is too large");let e=Zb(r),t=co(Fr.encode({Type:Je.RSA,Data:Vd(e.publicKey)})),n=Bt(jd,t);return new ic(e.privateKey,new Cs(e.publicKey,n))}async function Gd(r){if(r>Md)throw new ke("Key size is too large");let e=await Yb(r),t=co(Fr.encode({Type:Je.RSA,Data:Vd(e.publicKey)})),n=Bt(jd,t);return new ic(e.privateKey,new Cs(e.publicKey,n))}function Zb(r){if(r==null)throw new ke("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Yb(r,e){let t=await Mt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await y2(t,e);return{privateKey:n[0],publicKey:n[1]}}async function Gb(r,e,t){let n=await Mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Mt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function zb(r,e,t,n){let o=await Mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function y2(r,e){if(r.privateKey==null||r.publicKey==null)throw new ke("Private and public key are required");let t=await Promise.all([Mt.get().subtle.exportKey("jwk",r.privateKey),Mt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function Jb(r){if(r.kty!=="RSA")throw new ke("invalid key type");if(r.n==null)throw new ke("invalid key modulus");return fe(r.n,"base64url").length*8}var zl=class extends hs{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Go(e);let n=Qn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Er(i)}update(e){return ds(this),this.iHash.update(e),this}digestInto(e){ds(this),At(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Is=(r,e,t)=>new zl(r,e).update(t).digest();Is.create=(r,e)=>new zl(r,e);var Qb=(r,e)=>(r+(r>=0?e:-e)/ew)/e;function g2(r,e,t){let[[n,o],[i,s]]=e,a=Qb(s*r,t),c=Qb(-o*r,t),l=r-a*n-c*i,h=-a*o-c*s,p=l<vn,m=h<vn;p&&(l=-l),m&&(h=-h);let y=io(Math.ceil(Dl(t)/2))+Bs;if(l<vn||l>=y||h<vn||h>=y)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:p,k1:l,k2neg:m,k2:h}}function Xd(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function zd(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return dn(t.lowS,"lowS"),dn(t.prehash,"prehash"),t.format!==void 0&&Xd(t.format),t}var Zd=class extends Error{constructor(e=""){super(e)}},xn={Err:Zd,_tlv:{encode:(r,e)=>{let{Err:t}=xn;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=Wa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Wa(o.length/2|128):"";return Wa(r)+i+o+e},decode(r,e){let{Err:t}=xn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of l)s=s<<8|h;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=xn;if(r<vn)throw new e("integer: negative integers are not allowed");let t=Wa(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}=xn;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 ms(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=xn,o=_e("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=xn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},vn=BigInt(0),Bs=BigInt(1),ew=BigInt(2),Xl=BigInt(3),b2=BigInt(4);function Ts(r,e){let{BYTES:t}=r,n;if(typeof e=="bigint")n=e;else{let o=_e("private key",e);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function w2(r,e={}){let t=Ll("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;$r(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});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 l=rw(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(H,x,v){let{x:_,y:P}=x.toAffine(),R=n.toBytes(_);if(dn(v,"isCompressed"),v){h();let U=!n.isOdd(P);return Ot(tw(U),R)}else return Ot(Uint8Array.of(4),R,n.toBytes(P))}function m(H){Xt(H,void 0,"Point");let{publicKey:x,publicKeyUncompressed:v}=l,_=H.length,P=H[0],R=H.subarray(1);if(_===x&&(P===2||P===3)){let U=n.fromBytes(R);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let k=w(U),L;try{L=n.sqrt(k)}catch(pe){let me=pe instanceof Error?": "+pe.message:"";throw new Error("bad point: is not on curve, sqrt error"+me)}h();let W=n.isOdd(L);return(P&1)===1!==W&&(L=n.neg(L)),{x:U,y:L}}else if(_===v&&P===4){let U=n.BYTES,k=n.fromBytes(R.subarray(0,U)),L=n.fromBytes(R.subarray(U,U*2));if(!b(k,L))throw new Error("bad point: is not on curve");return{x:k,y:L}}else throw new Error(`bad point: got length ${_}, expected compressed=${x} or uncompressed=${v}`)}let y=e.toBytes||p,g=e.fromBytes||m;function w(H){let x=n.sqr(H),v=n.mul(x,H);return n.add(n.add(v,n.mul(H,i.a)),i.b)}function b(H,x){let v=n.sqr(x),_=w(H);return n.eql(v,_)}if(!b(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(i.a,Xl),b2),D=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(E,D)))throw new Error("bad curve params: a or b");function T(H,x,v=!1){if(!n.isValid(x)||v&&n.is0(x))throw new Error(`bad point coordinate ${H}`);return x}function V(H){if(!(H instanceof B))throw new Error("ProjectivePoint expected")}function Y(H){if(!c||!c.basises)throw new Error("no endo");return g2(H,c.basises,o.ORDER)}let z=ys((H,x)=>{let{X:v,Y:_,Z:P}=H;if(n.eql(P,n.ONE))return{x:v,y:_};let R=H.is0();x==null&&(x=R?n.ONE:n.inv(P));let U=n.mul(v,x),k=n.mul(_,x),L=n.mul(P,x);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:U,y:k}}),te=ys(H=>{if(H.is0()){if(e.allowInfinityPoint&&!n.is0(H.Y))return;throw new Error("bad point: ZERO")}let{x,y:v}=H.toAffine();if(!n.isValid(x)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!b(x,v))throw new Error("bad point: equation left != right");if(!H.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function X(H,x,v,_,P){return v=new B(n.mul(v.X,H),v.Y,v.Z),x=za(_,x),v=za(P,v),x.add(v)}class B{constructor(x,v,_){this.X=T("x",x),this.Y=T("y",v,!0),this.Z=T("z",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){let{x:v,y:_}=x||{};if(!x||!n.isValid(v)||!n.isValid(_))throw new Error("invalid affine point");if(x instanceof B)throw new Error("projective point not allowed");return n.is0(v)&&n.is0(_)?B.ZERO:new B(v,_,n.ONE)}static fromBytes(x){let v=B.fromAffine(g(Xt(x,void 0,"point")));return v.assertValidity(),v}static fromHex(x){return B.fromBytes(_e("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,v=!0){return q.createCache(this,x),v||this.multiply(Xl),this}assertValidity(){te(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){V(x);let{X:v,Y:_,Z:P}=this,{X:R,Y:U,Z:k}=x,L=n.eql(n.mul(v,k),n.mul(R,P)),W=n.eql(n.mul(_,k),n.mul(U,P));return L&&W}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:v}=i,_=n.mul(v,Xl),{X:P,Y:R,Z:U}=this,k=n.ZERO,L=n.ZERO,W=n.ZERO,N=n.mul(P,P),pe=n.mul(R,R),me=n.mul(U,U),Q=n.mul(P,R);return Q=n.add(Q,Q),W=n.mul(P,U),W=n.add(W,W),k=n.mul(x,W),L=n.mul(_,me),L=n.add(k,L),k=n.sub(pe,L),L=n.add(pe,L),L=n.mul(k,L),k=n.mul(Q,k),W=n.mul(_,W),me=n.mul(x,me),Q=n.sub(N,me),Q=n.mul(x,Q),Q=n.add(Q,W),W=n.add(N,N),N=n.add(W,N),N=n.add(N,me),N=n.mul(N,Q),L=n.add(L,N),me=n.mul(R,U),me=n.add(me,me),N=n.mul(me,Q),k=n.sub(k,N),W=n.mul(me,pe),W=n.add(W,W),W=n.add(W,W),new B(k,L,W)}add(x){V(x);let{X:v,Y:_,Z:P}=this,{X:R,Y:U,Z:k}=x,L=n.ZERO,W=n.ZERO,N=n.ZERO,pe=i.a,me=n.mul(i.b,Xl),Q=n.mul(v,R),xe=n.mul(_,U),Ee=n.mul(P,k),Oe=n.add(v,_),ve=n.add(R,U);Oe=n.mul(Oe,ve),ve=n.add(Q,xe),Oe=n.sub(Oe,ve),ve=n.add(v,P);let Be=n.add(R,k);return ve=n.mul(ve,Be),Be=n.add(Q,Ee),ve=n.sub(ve,Be),Be=n.add(_,P),L=n.add(U,k),Be=n.mul(Be,L),L=n.add(xe,Ee),Be=n.sub(Be,L),N=n.mul(pe,ve),L=n.mul(me,Ee),N=n.add(L,N),L=n.sub(xe,N),N=n.add(xe,N),W=n.mul(L,N),xe=n.add(Q,Q),xe=n.add(xe,Q),Ee=n.mul(pe,Ee),ve=n.mul(me,ve),xe=n.add(xe,Ee),Ee=n.sub(Q,Ee),Ee=n.mul(pe,Ee),ve=n.add(ve,Ee),Q=n.mul(xe,ve),W=n.add(W,Q),Q=n.mul(Be,ve),L=n.mul(Oe,L),L=n.sub(L,Q),Q=n.mul(Oe,xe),N=n.mul(Be,N),N=n.add(N,Q),new B(L,W,N)}subtract(x){return this.add(x.negate())}is0(){return this.equals(B.ZERO)}multiply(x){let{endo:v}=e;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let _,P,R=U=>q.cached(this,U,k=>yn(B,k));if(v){let{k1neg:U,k1:k,k2neg:L,k2:W}=Y(x),{p:N,f:pe}=R(k),{p:me,f:Q}=R(W);P=pe.add(Q),_=X(v.beta,N,me,U,L)}else{let{p:U,f:k}=R(x);_=U,P=k}return yn(B,[_,P])[0]}multiplyUnsafe(x){let{endo:v}=e,_=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===vn||_.is0())return B.ZERO;if(x===Bs)return _;if(q.hasCache(this))return this.multiply(x);if(v){let{k1neg:P,k1:R,k2neg:U,k2:k}=Y(x),{p1:L,p2:W}=Sb(B,_,R,k);return X(v.beta,L,W,P,U)}else return q.unsafe(_,x)}multiplyAndAddUnsafe(x,v,_){let P=this.multiplyUnsafe(v).add(x.multiplyUnsafe(_));return P.is0()?void 0:P}toAffine(x){return z(this,x)}isTorsionFree(){let{isTorsionFree:x}=e;return s===Bs?!0:x?x(B,this):q.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:x}=e;return s===Bs?this:x?x(B,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(x=!0){return dn(x,"isCompressed"),this.assertValidity(),y(B,this,x)}toHex(x=!0){return sr(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return yn(B,x)}static msm(x,v){return ws(B,o,x,v)}static fromPrivateKey(x){return B.BASE.multiply(Ts(o,x))}}B.BASE=new B(i.Gx,i.Gy,n.ONE),B.ZERO=new B(n.ZERO,n.ONE,n.ZERO),B.Fp=n,B.Fn=o;let j=o.BITS,q=new bs(B,e.endo?Math.ceil(j/2):j);return B.BASE.precompute(8),B}function tw(r){return Uint8Array.of(r?2:3)}function rw(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function x2(r,e={}){let{Fn:t}=r,n=e.randomBytes||eo,o=Object.assign(rw(r.Fp,t),{seed:cd(t.ORDER)});function i(y){try{return!!Ts(t,y)}catch{return!1}}function s(y,g){let{publicKey:w,publicKeyUncompressed:b}=o;try{let E=y.length;return g===!0&&E!==w||g===!1&&E!==b?!1:!!r.fromBytes(y)}catch{return!1}}function a(y=n(o.seed)){return ud(Xt(y,o.seed,"seed"),t.ORDER)}function c(y,g=!0){return r.BASE.multiply(Ts(t,y)).toBytes(g)}function l(y){let g=a(y);return{secretKey:g,publicKey:c(g)}}function h(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let{secretKey:g,publicKey:w,publicKeyUncompressed:b}=o;if(t.allowedLengths||g===w)return;let E=_e("key",y).length;return E===w||E===b}function p(y,g,w=!0){if(h(y)===!0)throw new Error("first arg must be private key");if(h(g)===!1)throw new Error("second arg must be public key");let b=Ts(t,y);return r.fromHex(g).multiply(b).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:p,keygen:l,Point:r,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:y=>Ts(t,y),precompute(y=8,g=r.BASE){return g.precompute(y,!1)}},lengths:o})}function v2(r,e,t={}){Go(e),$r(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||eo,o=t.hmac||((v,..._)=>Is(e,v,Ot(..._))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:l,getPublicKey:h,getSharedSecret:p,utils:m,lengths:y}=x2(r,t),g={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function b(v){let _=a>>Bs;return v>_}function E(v,_){if(!s.isValidNot0(_))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return _}function D(v,_){Xd(_);let P=y.signature,R=_==="compact"?P:_==="recovered"?P+1:void 0;return Xt(v,R,`${_} signature`)}class T{constructor(_,P,R){this.r=E("r",_),this.s=E("s",P),R!=null&&(this.recovery=R),Object.freeze(this)}static fromBytes(_,P=w){D(_,P);let R;if(P==="der"){let{r:W,s:N}=xn.toSig(Xt(_));return new T(W,N)}P==="recovered"&&(R=_[0],P="compact",_=_.subarray(1));let U=s.BYTES,k=_.subarray(0,U),L=_.subarray(U,U*2);return new T(s.fromBytes(k),s.fromBytes(L),R)}static fromHex(_,P){return this.fromBytes(zo(_),P)}addRecoveryBit(_){return new T(this.r,this.s,_)}recoverPublicKey(_){let P=i.ORDER,{r:R,s:U,recovery:k}=this;if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");if(a*ew<P&&k>1)throw new Error("recovery id is ambiguous for h>1 curve");let W=k===2||k===3?R+a:R;if(!i.isValid(W))throw new Error("recovery id 2 or 3 invalid");let N=i.toBytes(W),pe=r.fromBytes(Ot(tw((k&1)===0),N)),me=s.inv(W),Q=Y(_e("msgHash",_)),xe=s.create(-Q*me),Ee=s.create(U*me),Oe=r.BASE.multiplyUnsafe(xe).add(pe.multiplyUnsafe(Ee));if(Oe.is0())throw new Error("point at infinify");return Oe.assertValidity(),Oe}hasHighS(){return b(this.s)}toBytes(_=w){if(Xd(_),_==="der")return zo(xn.hexFromSig(this));let P=s.toBytes(this.r),R=s.toBytes(this.s);if(_==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Ot(Uint8Array.of(this.recovery),P,R)}return Ot(P,R)}toHex(_){return sr(this.toBytes(_))}assertValidity(){}static fromCompact(_){return T.fromBytes(_e("sig",_),"compact")}static fromDER(_){return T.fromBytes(_e("sig",_),"der")}normalizeS(){return this.hasHighS()?new T(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return sr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return sr(this.toBytes("compact"))}}let V=t.bits2int||function(_){if(_.length>8192)throw new Error("input is too large");let P=ms(_),R=_.length*8-c;return R>0?P>>BigInt(R):P},Y=t.bits2int_modN||function(_){return s.create(V(_))},z=io(c);function te(v){return oo("num < 2^"+c,v,vn,z),s.toBytes(v)}function X(v,_){return Xt(v,void 0,"message"),_?Xt(e(v),void 0,"prehashed message"):v}function B(v,_,P){if(["recovered","canonical"].some(xe=>xe in P))throw new Error("sign() legacy options not supported");let{lowS:R,prehash:U,extraEntropy:k}=zd(P,g);v=X(v,U);let L=Y(v),W=Ts(s,_),N=[te(W),te(L)];if(k!=null&&k!==!1){let xe=k===!0?n(y.secretKey):k;N.push(_e("extraEntropy",xe))}let pe=Ot(...N),me=L;function Q(xe){let Ee=V(xe);if(!s.isValidNot0(Ee))return;let Oe=s.inv(Ee),ve=r.BASE.multiply(Ee).toAffine(),Be=s.create(ve.x);if(Be===vn)return;let cn=s.create(Oe*s.create(me+Be*W));if(cn===vn)return;let or=(ve.x===Be?0:2)|Number(ve.y&Bs),Gn=cn;return R&&b(cn)&&(Gn=s.neg(cn),or^=1),new T(Be,Gn,or)}return{seed:pe,k2sig:Q}}function j(v,_,P={}){v=_e("message",v);let{seed:R,k2sig:U}=B(v,_,P);return ab(e.outputLen,s.BYTES,o)(R,U)}function q(v){let _,P=typeof v=="string"||pn(v),R=!P&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!P&&!R)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(R)_=new T(v.r,v.s);else if(P){try{_=T.fromBytes(_e("sig",v),"der")}catch(U){if(!(U instanceof xn.Err))throw U}if(!_)try{_=T.fromBytes(_e("sig",v),"compact")}catch{return!1}}return _||!1}function H(v,_,P,R={}){let{lowS:U,prehash:k,format:L}=zd(R,g);if(P=_e("publicKey",P),_=X(_e("message",_),k),"strict"in R)throw new Error("options.strict was renamed to lowS");let W=L===void 0?q(v):T.fromBytes(_e("sig",v),L);if(W===!1)return!1;try{let N=r.fromBytes(P);if(U&&W.hasHighS())return!1;let{r:pe,s:me}=W,Q=Y(_),xe=s.inv(me),Ee=s.create(Q*xe),Oe=s.create(pe*xe),ve=r.BASE.multiplyUnsafe(Ee).add(N.multiplyUnsafe(Oe));return ve.is0()?!1:s.create(ve.x)===pe}catch{return!1}}function x(v,_,P={}){let{prehash:R}=zd(P,g);return _=X(_,R),T.fromBytes(v,"recovered").recoverPublicKey(_).toBytes()}return Object.freeze({keygen:l,getPublicKey:h,getSharedSecret:p,utils:m,lengths:y,Point:r,sign:j,verify:H,recoverPublicKey:x,Signature:T,hash:e})}function A2(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=Zt(e.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes:r.wrapPrivateKey}),i={Fp:t,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:i}}function S2(r){let{CURVE:e,curveOpts:t}=A2(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,hash:r.hash,ecdsaOpts:n}}function E2(r,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},r,Rl(t.Fn.ORDER,t.Fn.BITS))})}function nw(r){let{CURVE:e,curveOpts:t,hash:n,ecdsaOpts:o}=S2(r),i=w2(e,t),s=v2(i,n,o);return E2(r,s)}function ow(r,e){let t=n=>nw({...r,hash:n});return{...t(e),create:t}}var Jd={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var iw=BigInt(2);function C2(r){let e=Jd.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%e,h=l*l*r%e,p=Me(h,t,e)*h%e,m=Me(p,t,e)*h%e,y=Me(m,iw,e)*l%e,g=Me(y,o,e)*y%e,w=Me(g,i,e)*g%e,b=Me(w,a,e)*w%e,E=Me(b,c,e)*b%e,D=Me(E,a,e)*w%e,T=Me(D,t,e)*h%e,V=Me(T,s,e)*g%e,Y=Me(V,n,e)*l%e,z=Me(Y,iw,e);if(!Yd.eql(Yd.sqr(z),r))throw new Error("Cannot find square root");return z}var Yd=Zt(Jd.p,{sqrt:C2}),kr=ow({...Jd,Fp:Yd,lowS:!0,endo:_2},Ol);function sw(r,e,t){let n=ir.digest(e instanceof Uint8Array?e:e.subarray());if(Ss(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),kr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ja(String(o))});try{return kr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Ja(String(o))}}function aw(r,e,t,n){let o=ir.digest(t instanceof Uint8Array?t:t.subarray());if(Ss(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),kr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Qa(String(i))});try{return n?.signal?.throwIfAborted(),kr.verify(e,o.digest,r)}catch(i){throw new Qa(String(i))}}var ac=class{type="secp256k1";raw;_key;constructor(e){this._key=lw(e),this.raw=cw(this._key)}toMultihash(){return Ar.digest(Jn(this))}toCID(){return Ye.createV1(114,this.toMultihash())}toString(){return He.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}verify(e,t,n){return aw(this._key,t,e,n)}},Zl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=uw(e),this.publicKey=new ac(t??fw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return sw(this.raw,e,t)}};function Qd(r){return new ac(r)}async function pw(){let r=I2();return new Zl(r)}function cw(r){return kr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function uw(r){try{return kr.getPublicKey(r,!0),r}catch(e){throw new Da(String(e))}}function lw(r){try{return kr.ProjectivePoint.fromHex(r),r}catch(e){throw new as(String(e))}}function fw(r){try{return kr.getPublicKey(r,!0)}catch(e){throw new Da(String(e))}}function I2(){return kr.utils.randomPrivateKey()}async function hw(r,e){if(r==="Ed25519")return Ub();if(r==="secp256k1")return pw();if(r==="RSA")return Gd(T2(e));if(r==="ECDSA")return V0(B2(e));throw new zn}function cc(r,e){let{Type:t,Data:n}=Fr.decode(r),o=n??new Uint8Array;switch(t){case Je.RSA:return Fd(o,e);case Je.Ed25519:return wd(o);case Je.secp256k1:return Qd(o);case Je.ECDSA:return Xh(o);default:throw new zn}}function dw(r){let{Type:e,Data:t}=Fr.decode(r.digest),n=t??new Uint8Array;switch(e){case Je.Ed25519:return wd(n);case Je.secp256k1:return Qd(n);case Je.ECDSA:return Xh(n);default:throw new zn}}function Jn(r){return Fr.encode({Type:Je[r.type],Data:r.raw})}function T2(r){return r==null?2048:parseInt(r,10)}function B2(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ke("Unsupported curve, should be P-256, P-384 or P-521")}async function Yl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ke("Only RSA and ECDSA keys are supported")}var mw=Symbol.for("nodejs.util.inspect.custom"),k2=114,uc=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()})`}[Ah]=!0;toString(){return this.string==null&&(this.string=He.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Ye.createV1(k2,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")}[mw](){return`PeerId(${this.toString()})`}},lc=class extends uc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},fc=class extends uc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},pc=class extends uc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},P2=2336,hc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ar.digest(fe(this.url))}[mw](){return`PeerId(${this.url})`}[Ah]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Ye.createV1(P2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ce(e)),e.toString()===this.toString())}};var O2=114,yw=2336;function Jl(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ps(He.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return N2(Ye.parse(r));if(e==null)throw new ke('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ps(e.decode(r))}return gw(t)}function em(r){if(r.type==="Ed25519")return new fc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new pc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new lc({multihash:r.toCID().multihash,publicKey:r});throw new zn}function gw(r){if(R2(r))return new lc({multihash:r});if(D2(r))try{let e=dw(r);if(e.type==="Ed25519")return new fc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new pc({multihash:r,publicKey:e})}catch{let t=ce(r.digest);return new hc(new URL(t))}throw new xl("Supplied PeerID Multihash is invalid")}function N2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==O2&&r.code!==yw)throw new wl("Supplied PeerID CID is invalid");if(r.code===yw){let e=ce(r.multihash.digest);return new hc(new URL(e))}return gw(r.multihash)}function D2(r){return r.code===Ar.code}function R2(r){return r.code===ir.code}var pt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},An=class extends Error{static name="ValidationError";name="ValidationError"},dc=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ql=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ef=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let h=this.readAtomically(()=>{let p=this.readChar();if(p===void 0)return;let m=Number.parseInt(p,e);if(!Number.isNaN(m))return m});if(h===void 0)break;if(i*=e,i+=h,i>l||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var L2=45,U2=15,tf=new ef;function tm(r){if(!(r.length>U2))return tf.new(r).parseWith(()=>tf.readIPv4Addr())}function rm(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>L2))return tf.new(r).parseWith(()=>tf.readIPv6Addr())}function rf(r){return!!tm(r)}function ww(r){return!!rm(r)}function om(r){return e=>ce(e,r)}function im(r){return e=>fe(e,r)}function ks(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ni(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function xw(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=fe(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=ni(n);return kt([t,o],t.length+o.length)}function vw(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=Yn.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=ni(n);return kt([t,o],t.length+o.length)}function sm(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=ce(e,"base32"),o=ks(t);return`${n}:${o}`}var am=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new pt("Invalid byte value in IP address");e[n]=o}),e},Aw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=rf(t[n]),s;i&&(s=am(t[n]),t[n]=ce(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ce(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new pt("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Sw=function(r){if(r.byteLength!==4)throw new pt("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Ew=function(r){if(r.byteLength!==16)throw new pt("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${t}"`)}};function _w(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new pt(`Invalid IPv6 address "${r}"`)}}var nm=Object.values($o).map(r=>r.decoder),M2=(function(){let r=nm[0].or(nm[1]);return nm.slice(2).forEach(e=>r=r.or(e)),r})();function Cw(r){return M2.decode(r)}function Iw(r){return e=>r.encoder.encode(e)}function j2(r){if(parseInt(r).toString()!==r)throw new An("Value must be an integer")}function K2(r){if(r<0)throw new An("Value must be a positive integer, or zero")}function H2(r){return e=>{if(e>r)throw new An(`Value must be smaller than or equal to ${r}`)}}function V2(...r){return e=>{for(let t of r)t(e)}}var mc=V2(j2,K2,H2(65535));var ut=-1,cm=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 Ql(`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)}))}},Jt=new cm,nC=[{code:4,name:"ip4",size:32,valueToBytes:am,bytesToValue:Sw,validate:r=>{if(!rf(r))throw new An(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ni,bytesToValue:ks,validate:mc},{code:273,name:"udp",size:16,valueToBytes:ni,bytesToValue:ks,validate:mc},{code:33,name:"dccp",size:16,valueToBytes:ni,bytesToValue:ks,validate:mc},{code:41,name:"ip6",size:128,valueToBytes:Aw,bytesToValue:Ew,stringToValue:_w,validate:r=>{if(!ww(r))throw new An(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:ut},{code:43,name:"ipcidr",size:8,bytesToValue:om("base10"),valueToBytes:im("base10")},{code:53,name:"dns",size:ut,resolvable:!0},{code:54,name:"dns4",size:ut,resolvable:!0},{code:55,name:"dns6",size:ut,resolvable:!0},{code:56,name:"dnsaddr",size:ut,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:ni,bytesToValue:ks,validate:mc},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ut,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:ut,bytesToValue:om("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?im("base58btc")(r):Ye.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:sm,valueToBytes:xw},{code:445,name:"onion3",size:296,bytesToValue:sm,valueToBytes:vw},{code:446,name:"garlic64",size:ut},{code:447,name:"garlic32",size:ut},{code:448,name:"tls"},{code:449,name:"sni",size:ut},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ut,bytesToValue:Iw(Vo),valueToBytes:Cw},{code:480,name:"http"},{code:481,name:"http-path",size:ut,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ut}];nC.forEach(r=>{Jt.addProtocol(r)});function Tw(r){let e=[],t=0;for(;t<r.length;){let n=Qo(r,t),o=Jt.getProtocol(n),i=Ve(n),s=oC(o,r,t+i),a=0;s>0&&o.size===ut&&(a=Ve(s));let c=i+a+s,l={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let h=t+i+a,p=r.subarray(h,h+s);l.value=o.bytesToValue?.(p)??ce(p)}e.push(l),t+=c}return e}function Bw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=Jt.getProtocol(n.code),i=Ve(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??fe(n.value),a=s.byteLength,o.size===ut&&(c=Ve(a)));let l=new Uint8Array(i+c+a),h=0;Es(n.code,l,h),h+=i,s!=null&&(o.size===ut&&(Es(a,l,h),h+=c),l.set(s,h)),n.bytes=l}t.push(n.bytes),e+=n.bytes.byteLength}return kt(t,e)}function kw(r){if(r.charAt(0)!=="/")throw new pt('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=Jt.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new pt(`Component ${o} was missing value`);t="value"}else if(t==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new pt(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}e.push(l),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new pt("Incomplete multiaddr");return e}function Pw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=Jt.getProtocol(e.code);if(t==null)throw new pt(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function oC(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Qo(e,t)}var iC=Symbol.for("nodejs.util.inspect.custom"),bm=Symbol.for("@multiformats/multiaddr"),sC=[53,54,55,56],gm=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function aC(r){if(r==null&&(r="/"),Nw(r))return r.getComponents();if(r instanceof Uint8Array)return Tw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),kw(r);if(Array.isArray(r))return r;throw new pt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var af=class r{[bm]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=aC(e),t.validate!==!1&&cC(this)}get bytes(){return this.#r==null&&(this.#r=Bw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Pw(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="";for(let{code:a,name:c,value:l}of this.#e)a===42&&(i=`%${l??""}`),sC.includes(a)&&(t="tcp",o=443,n=`${l??""}${i}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(t="tcp",n=`${l??""}${i}`,e=a===41?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=Jt.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:t})=>{if(t==null)return[e];let n=Jt.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??fe(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new dc(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ce(He.decode(`z${n}`),"base58btc"):ce(Ye.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(Jt.getProtocol(e.code).path)return e.value??null;return null}equals(e){return We(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Ow.get(t.name);if(n==null)throw new gm(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Sn(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[iC](){return`Multiaddr(${this.toString()})`}};function cC(r){r.getComponents().forEach(e=>{let t=Jt.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var aO=parseInt("0xFFFF",16),cO=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Ow=new Map;function Nw(r){return!!r?.[bm]}function Sn(r){return new af(r)}var De=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),ue=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),Se=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),_t=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1}}),Te=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function 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 hC=ue(421),ZO=Ne(hC),uf=ue(54),lf=ue(55),ff=ue(56),xm=ue(53),YO=Ne(uf,Se(ue(421))),JO=Ne(lf,Se(ue(421))),QO=Ne(ff,Se(ue(421))),e4=Ne(_t(xm,ff,uf,lf),Se(ue(421))),Lw=Te(ue(4),Se(ue(43))),Uw=Te(Se(ue(42)),ue(41),Se(ue(43))),vm=_t(Lw,Uw),si=_t(vm,xm,uf,lf,ff),t4=Ne(_t(vm,Te(_t(xm,ff,uf,lf),Se(ue(421))))),r4=Ne(Lw),n4=Ne(Uw),o4=Ne(vm),Am=Te(si,ue(6)),vc=Te(si,ue(273)),i4=Ne(Te(Am,Se(ue(421)))),s4=Ne(vc),Sm=Te(vc,De(460),Se(ue(421))),pf=Te(vc,De(461),Se(ue(421))),dC=_t(Sm,pf),a4=Ne(Sm),c4=Ne(pf),wm=_t(si,Am,vc,Sm,pf),Mw=_t(Te(wm,De(477),Se(ue(421)))),u4=Ne(Mw),jw=_t(Te(wm,De(478),Se(ue(421))),Te(wm,De(448),Se(ue(449)),De(477),Se(ue(421)))),l4=Ne(jw),Kw=Te(vc,De(280),Se(ue(466)),Se(ue(466)),Se(ue(421))),Hw=Ne(Kw),Vw=Te(pf,De(465),Se(ue(466)),Se(ue(466)),Se(ue(421))),f4=Ne(Vw),cf=_t(Mw,jw,Te(Am,Se(ue(421))),Te(dC,Se(ue(421))),Te(si,Se(ue(421))),Kw,Vw,ue(421)),$w=Ne(cf),mC=Te(cf,De(290),ue(421)),p4=Ne(mC),yC=_t(Te(cf,De(290),De(281),Se(ue(421))),Te(cf,De(281),Se(ue(421))),Te(De(281),Se(ue(421)))),Fw=Ne(yC),gC=_t(Te(si,ue(6),De(480),Se(ue(421))),Te(si,De(480),Se(ue(421)))),h4=Ne(gC),bC=Te(si,_t(Te(ue(6,"443"),De(480)),Te(ue(6),De(443)),Te(ue(6),De(448),De(480)),Te(De(448),De(480)),De(448),De(443)),Se(ue(421))),d4=Ne(bC),wC=_t(Te(ue(777),Se(ue(421)))),m4=Ne(wC),xC=_t(Te(ue(400),Se(ue(421)))),y4=Ne(xC);var Ct;(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=()=>ri(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Tr(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(Ct||(Ct={}));var Ww=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Em=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),qw="libp2p+webrtc+v1/";var Gw=466,zw=2*1024*1024,Xw=30*1e3,Ls=16*1024;function vC(r=Ls){let e=Ve(r-Ve(r)),t=1+Ve(Object.keys(Ct.Flag).length-1),n=1,o=r-e-t-n,i=Ve(o);return e+t+n+i}var Zw=vC(),Yw=5e3,Jw=5e3,Qw=3e4,_m="/webrtc",Ac="/webrtc-signaling/0.0.1",ex="/libp2p/webrtc-direct/certificate",tx="webrtc-direct-certificate-private-key";var rx=12096e5,Cm=864e5;var nx=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))},AC=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var SC=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var EC=(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 _C=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var CC=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var IC=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,TC=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,ox=3,BC=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",IC]],ix=[["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 ax(r){return r?sx(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new CC:typeof navigator<"u"?sx(navigator.userAgent):OC()}function kC(r){return r!==""&&BC.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 sx(r){var e=kC(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new _C;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<ox&&(o=nx(nx([],o,!0),NC(ox-o.length),!0)):o=[];var i=o.join("."),s=PC(r),a=TC.exec(r);return a&&a[1]?new EC(t,i,s,a[1]):new AC(t,i,s)}function PC(r){for(var e=0,t=ix.length;e<t;e++){var n=ix[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function OC(){var r=typeof process<"u"&&process.version;return r?new SC(process.version.slice(1)):null}function NC(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Qe(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Im=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Tm=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},cx=r=>globalThis.DOMException===void 0?new Tm(r):new DOMException(r),ux=r=>{let e=r.reason===void 0?cx("This operation was aborted."):r.reason;return e instanceof Error?e:cx(e)};function Sc(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&p(ux(y)),a=()=>{p(ux(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let m=new Im;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(y){p(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(m.message=o??`Promise timed out after ${t} milliseconds`,p(m))},t),(async()=>{try{h(await r)}catch(y){p(y)}})()}).finally(()=>{l.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return l.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},l}var lx=ax(),Ec=lx!=null&&lx.name==="firefox",hf=async function*(){},df=async r=>{};function fx(r,e,t=Qw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Qe(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Sc(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Bm(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Ww.map(e=>({urls:[e]})),r}var px=(r=32)=>qw+[...Array(r)].map(()=>Em.at(Math.floor(Math.random()*Em.length))).join("");var ai=class{log;peerConnection;remoteAddr;timeline;metrics;source=hf();sink=df;constructor(e,t){this.log=e.logger.forComponent("libp2p:webrtc:maconn"),this.remoteAddr=t.remoteAddr,this.timeline=t.timeline,this.peerConnection=t.peerConnection;let n=this.peerConnection,o=n.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change",n.connectionState,"initial state",o),(n.connectionState==="disconnected"||n.connectionState==="failed"||n.connectionState==="closed")&&(this.timeline.close=Date.now())}}async close(e){this.log.trace("closing connection"),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({close:!0})}abort(e){this.log.error("closing connection due to error",e),this.peerConnection.close(),this.timeline.close=Date.now(),this.metrics?.increment({abort:!0})}};var mf=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}},Us=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new mf(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 mf(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 km=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ms(r={}){return DC(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 DC(r,e){e=e??{};let t=e.onEnd,n=new Us,o,i,s,a=Qe(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((b,E)=>{i=D=>{i=null,n.push(D);try{b(r(n))}catch(T){E(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Qe()})}},l=b=>i!=null?i(b):(n.push(b),o),h=b=>(n=new Us,i!=null?i({error:b}):(n.push({error:b}),o)),p=b=>{if(s)return o;if(e?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:b})},m=b=>s?o:(s=!0,b!=null?h(b):l({done:!0})),y=()=>(n=new Us,m(),{done:!0}),g=b=>(m(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:y,throw:g,push:p,end:m,get readableLength(){return n.size},onEmpty:async b=>{let E=b?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let D,T;E!=null&&(D=new Promise((V,Y)=>{T=()=>{Y(new km)},E.addEventListener("abort",T)}));try{await Promise.race([a.promise,D])}finally{T!=null&&E!=null&&E?.removeEventListener("abort",T)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(b){return w.throw(b),t!=null&&(t(b),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(b){return w.end(b),t!=null&&(t(b),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:b=>w.onEmpty(b)},o}var yf=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function ur(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new yf(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new yf(t?.errorMessage,t?.errorCode,t?.errorName);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}function hx(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function dx(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function mx(r,e){let t=hx(r).return?.();dx(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var RC=5e3;function Pm(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var gf=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Qe(),this.closed=Qe(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??RC,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=Ms({onEnd:t=>{t!=null?this.log.trace("source ended with error",t):this.log.trace("source ended"),this.onSourceEnd(t)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!=="ready")throw new jo(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Pm(o)&&await o}let n=()=>{mx(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new we(o):o;let i=this.sendData(o,t);Pm(i)&&(this.sendingData=Qe(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await ur(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await ur(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await ur(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await ur(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Pm(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new bl("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Om(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var bf=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},js=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},wf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},_c=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function xf(r){return r[Symbol.asyncIterator]!=null}function yx(r,e){if(r.byteLength>e)throw new js("Message length too long")}var Af=r=>{let e=Ve(r),t=it(e);return $l(r,t),Af.bytes=e,t};Af.bytes=0;function Cc(r,e){e=e??{};let t=e.lengthEncoder??Af,n=e?.maxDataLength??4194304;function*o(i){yx(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return xf(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}Cc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Af,n=e?.maxDataLength??4194304;return yx(r,n),new we(t(r.byteLength),r)};var ci;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ci||(ci={}));var Nm=r=>{let e=Qo(r);return Nm.bytes=Ve(e),e};Nm.bytes=0;function ui(r,e){let t=new we,n=ci.LENGTH,o=-1,i=e?.lengthDecoder??Nm,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===ci.LENGTH)try{if(o=i(t),o<0)throw new bf("Invalid message length");if(o>a)throw new js("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=ci.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new wf("Message length length too long");break}throw l}if(n===ci.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=ci.LENGTH}}}return xf(r)?(async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new _c("Unexpected end of input")})():(function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new _c("Unexpected end of input")})()}ui.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 ui(n,{...e??{},onLength:i=>{t=i}})};var Sf=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...t){super(e,...t)}};async function Ic(r,e,t,n){let o=new Sf(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let i=n?.errorEvent??"error";return t?.aborted===!0?Promise.reject(o):new Promise((s,a)=>{function c(){Rm(t,"abort",p),Rm(r,e,l),Rm(r,i,h)}let l=m=>{try{if(n?.filter?.(m)===!1)return}catch(y){c(),a(y);return}c(),s(m)},h=m=>{if(c(),m instanceof Error){a(m);return}a(m.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},p=()=>{c(),a(o)};Dm(t,"abort",p),Dm(r,e,l),Dm(r,i,h)})}function Dm(r,e,t){r!=null&&(gx(r)?r.addEventListener(e,t):r.addListener(e,t))}function Rm(r,e,t){r!=null&&(gx(r)?r.removeEventListener(e,t):r.removeListener(e,t))}function gx(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var Lm=class extends gf{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await Sc(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Ms(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Xw,this.maxBufferedAmount=e.maxBufferedAmount??zw,this.maxMessageSize=(e.maxMessageSize??Ls)-Zw,this.receiveFinAck=Qe(),this.finAckTimeout=e.closeTimeout??Yw,this.openTimeout=e.openTimeout??Jw,this.closeController=new AbortController,this.channel.readyState){case"open":this.timeline.open=new Date().getTime();break;case"closed":case"closing":(this.timeline.close===void 0||this.timeline.close===0)&&(this.timeline.close=Date.now());break;case"connecting":break;default:throw this.log.error("unknown datachannel state %s",this.channel.readyState),new jo("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of ui(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new we(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new jo(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Om([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await Ic(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Om([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Ic(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Al(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=Ct.encode({message:o}),s=Cc.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(Ct.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(Ct.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await ur(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(Ct.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=Ct.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===Ct.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(Ct.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===Ct.Flag.RESET&&this.reset(),t.flag===Ct.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===Ct.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=Ct.encode({flag:e}),n=Cc.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function Ks(r){let{channel:e,direction:t,handshake:n}=r;return new Lm({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`)})}var lo=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??_m,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=Ks({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},log:this.log,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Um(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Um=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=t.log?.newScope("muxer")??e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??_m,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=Ks({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},log:this.log,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),fx(t,`${e.direction} ${e.id} ${e.protocol}`,this.dataChannelOptions.drainTimeout,{log:this.log}),this.streams=this.streams.filter(n=>n.id!==e.id),this.metrics?.increment({stream_end:!0}),this.init?.onStreamEnd?.(e)}async close(e){try{await Promise.all(this.streams.map(async t=>t.close(e)))}catch(t){this.abort(t)}}abort(e){for(let t of this.streams)t.abort(e)}source=hf();sink=df;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=Ks({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},log:this.log,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Ef=globalThis.RTCPeerConnection,_f=globalThis.RTCSessionDescription,bx=globalThis.RTCIceCandidate;var Mm=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Qe(),this.haveNext=Qe()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Qe(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Qe(),await ur(this.readNext.promise,t?.signal,t)}};function Cf(){return new Mm}var If=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function wx(r,e){let t=Cf();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new we;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:l}=await ur(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await ur(n.next(),s?.signal);if(l===!0)throw new If("unexpected end of input");o.append(c)}let a=o.sublist(0,s.bytes);return o.consume(s.bytes),a},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await t.push(s,a):await t.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=(async function*(){e?.yieldBytes===!1?yield o:yield*o,yield*s})()}return r}}}var Tf=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Bf=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},kf=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Tc(r,e={}){let t=wx(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ve(e.maxDataLength));let n=e?.lengthDecoder??Qo,o=e?.lengthEncoder??$l;return{read:async s=>{let a=-1,c=new we;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Tf("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new kf("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Bf("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new we(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new we(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Pf(r,e){let t=Tc(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 Qt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var fo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},lr=class extends fo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Of=class extends fo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Nf=class extends fo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Df=class extends fo{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 jt;(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=()=>ri(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Tr(o,r.codec()),r.decode=(o,i)=>Ir(o,r.codec(),i)})(jt||(jt={}));var Rf=async(r,e,t)=>{try{let n=Qe();for(MC(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal}).catch(()=>{})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==jt.Type.ICE_CANDIDATE)throw new vl("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Qt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new bx(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Qt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Lf(r)!=="connected")throw n}};function Lf(r){return Ec?r.iceConnectionState:r.connectionState}function MC(r,e){r[Ec?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Lf(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new gl("RTCPeerConnection was closed"));break;default:break}}}async function xx({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{circuitAddress:h,targetPeer:p}=vx(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",h);let m=i.getConnections(p),y;m.length===0?(l?.(new Qt("webrtc:dial-relay")),y=await s.dial(h,{signal:t,onProgress:l})):(l?.(new Qt("webrtc:reuse-relay-connection")),y=m[0]),l?.(new Qt("webrtc:open-signaling-stream"));let g=await y.newStream(Ac,{signal:t,runOnLimitedConnection:!0}),w=Pf(g).pb(jt),b=new Ef(r),E=new lo({logger:c},{peerConnection:b,dataChannelOptions:e});try{let D=b.createDataChannel("init");b.onicecandidate=({candidate:z})=>{let te=JSON.stringify(z?.toJSON()??null);a.trace("initiator sending ICE candidate %o",z),w.write({type:jt.Type.ICE_CANDIDATE,data:te},{signal:t}).catch(X=>{a.error("error sending ICE candidate",X)})},b.onicecandidateerror=z=>{a.error("initiator ICE candidate error",z)};let T=await b.createOffer().catch(z=>{throw a.error("could not execute createOffer",z),new lr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",T.sdp),l?.(new Qt("webrtc:send-sdp-offer")),await w.write({type:jt.Type.SDP_OFFER,data:T.sdp},{signal:t}),await b.setLocalDescription(T).catch(z=>{throw a.error("could not execute setLocalDescription",z),new lr("Failed to set localDescription")}),l?.(new Qt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let V=await w.read({signal:t});if(V.type!==jt.Type.SDP_ANSWER)throw new lr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",V.data);let Y=new _f({type:"answer",sdp:V.data});return await b.setRemoteDescription(Y).catch(z=>{throw a.error("could not execute setRemoteDescription",z),new lr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new Qt("webrtc:read-ice-candidates")),await Rf(b,w,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),D.close(),l?.(new Qt("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:b,muxerFactory:E}}catch(D){throw a.error("outgoing signaling error",D),b.close(),g.abort(D),D}finally{b.onicecandidate=null,b.onicecandidateerror=null}}var Ax=Ne($w.matchers[0],De(290)),Uf=class r extends Xn{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=>Ax.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=>Ax.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 Sx({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Pf(e).pb(jt);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:jt.Type.ICE_CANDIDATE,data:p},{signal:t}).catch(m=>{o.error("error sending ICE candidate",m)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==jt.Type.SDP_OFFER)throw new lr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new _f({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new lr("Failed to set remoteDescription")});let l=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new lr("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:jt.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(h=>{throw o.error("could not execute setLocalDescription",h),new lr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Rf(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Lf(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=Sn(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Mf=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"})})}[dl]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[cs]=["@libp2p/transport"];[l0]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Ac,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Ac),this._started=!1}createListener(e){return new Uf(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Fw.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 xx({rtcConfiguration:await Bm(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new ai(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new Ef(await Bm(this.init.rtcConfiguration)),i=new lo(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await Sx({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new ai(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function vx(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new ke("Destination peer id was missing");return{circuitAddress:Sn(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:Jl(e)}}var OX=Hr(_x());var Xr={};vt(Xr,{Any:()=>Gr,BaseBlock:()=>et,BaseStringBlock:()=>Oc,BitString:()=>Nr,BmpString:()=>di,Boolean:()=>fi,CharacterString:()=>Si,Choice:()=>$s,Constructed:()=>tt,DATE:()=>Mc,DateTime:()=>Kc,Duration:()=>Hc,EndOfContent:()=>Nc,Enumerated:()=>pi,GeneralString:()=>Ai,GeneralizedTime:()=>Ei,GraphicString:()=>vi,HexBlock:()=>zr,IA5String:()=>xi,Integer:()=>Bn,Null:()=>Pr,NumericString:()=>yi,ObjectIdentifier:()=>hi,OctetString:()=>Or,Primitive:()=>Tn,PrintableString:()=>gi,RawData:()=>Vm,RelativeObjectIdentifier:()=>Uc,Repeated:()=>_i,Sequence:()=>It,Set:()=>Dt,TIME:()=>Vc,TeletexString:()=>bi,TimeOfDay:()=>jc,UTCTime:()=>mo,UniversalString:()=>mi,Utf8String:()=>pr,ValueBlock:()=>ht,VideotexString:()=>wi,ViewWriter:()=>Vs,VisibleString:()=>ho,compareSchema:()=>Cn,fromBER:()=>Pn,verifySchema:()=>iI});var de=Hr(_n());function li(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 po(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let l=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);l[i-h-1]=Math.floor(o/p),o-=l[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Hf(...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 Km(){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=li(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,li(i,8)-n}function Cx(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=po(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=po(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 Ix(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 Kt(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 F3=Math.log(2);function Vf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function $m(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 kn(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 Vs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return $m(this.items)}},Bc=[new Uint8Array([1])],Tx="0123456789",Hm="name",Bx="valueHexView",GC="isHexOnly",zC="idBlock",XC="tagClass",ZC="tagNumber",YC="isConstructed",JC="fromBER",QC="toBER",eI="local",Ht="",Dr=new ArrayBuffer(0),np=new Uint8Array(0),Pc="EndOfContent",Px="OCTET STRING",Ox="BIT STRING";function zr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?de.BufferSourceConverter.toUint8Array(i.valueHex):np}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!kn(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",Dr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:de.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var In=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=Ht,warnings:n=[],valueBeforeDecode:o=np}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=de.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:de.Convert.ToHex(this.valueBeforeDecodeView)}}};In.NAME="baseBlock";var ht=class extends In{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ht.NAME="valueBlock";var $f=class extends zr(In){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?de.BufferSourceConverter.toUint8Array(e.valueHex):np,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",Dr}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=po(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!kn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(l[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let m=new Uint8Array(h);for(let y=0;y<l.length;y++)m[y]=l[y];l=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,l[c-1]=i[c]&127;let p=new Uint8Array(c);for(let m=0;m<c;m++)p[m]=l[m];l=this.valueHexView=new Uint8Array(c),l.set(p),this.blockLength<=9?this.tagNumber=li(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};$f.NAME="identificationBlock";var Ff=class extends In{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!kn(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=li(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=po(this.length,8);if(o.byteLength>127)return this.error="Too big length",Dr;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}}};Ff.NAME="lengthBlock";var Z={},et=class extends In{constructor({name:e=Ht,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new $f(o),this.lenBlock=new Ff(o),this.valueBlock=i?new i(o):new ht(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new Vs;t||Nx(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?Dr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():de.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=de.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return Ix(t,n)}};et.NAME="BaseBlock";function Nx(r){var e;if(r instanceof Z.Constructed)for(let t of r.valueBlock.value)Nx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var Oc=class extends et{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Ht,...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}'`}};Oc.NAME="BaseStringBlock";var Wf=class extends zr(ht){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Wf.NAME="PrimitiveValueBlock";var Dx,Tn=class extends et{constructor(e={}){super(e,Wf),this.idBlock.isConstructed=!1}};Dx=Tn;Z.Primitive=Dx;Tn.NAME="PRIMITIVE";function tI(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 Fs(r,e=0,t=r.length){let n=e,o=new et({},ht),i=new In;if(!kn(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=et;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=Z.EndOfContent;break;case 1:c=Z.Boolean;break;case 2:c=Z.Integer;break;case 3:c=Z.BitString;break;case 4:c=Z.OctetString;break;case 5:c=Z.Null;break;case 6:c=Z.ObjectIdentifier;break;case 10:c=Z.Enumerated;break;case 12:c=Z.Utf8String;break;case 13:c=Z.RelativeObjectIdentifier;break;case 14:c=Z.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Z.Sequence;break;case 17:c=Z.Set;break;case 18:c=Z.NumericString;break;case 19:c=Z.PrintableString;break;case 20:c=Z.TeletexString;break;case 21:c=Z.VideotexString;break;case 22:c=Z.IA5String;break;case 23:c=Z.UTCTime;break;case 24:c=Z.GeneralizedTime;break;case 25:c=Z.GraphicString;break;case 26:c=Z.VisibleString;break;case 27:c=Z.GeneralString;break;case 28:c=Z.UniversalString;break;case 29:c=Z.CharacterString;break;case 30:c=Z.BmpString;break;case 31:c=Z.DATE;break;case 32:c=Z.TimeOfDay;break;case 33:c=Z.DateTime;break;case 34:c=Z.Duration;break;default:{let l=o.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Z.Constructed:Z.Primitive}return o=tI(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 Pn(r){if(!r.byteLength){let e=new et({},ht);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Fs(de.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function rI(r,e){return r?1:e}var qr=class extends ht{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!kn(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(;rI(this.isIndefiniteForm,n)>0;){let s=Fs(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===Pc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Pc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Vs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Dr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};qr.NAME="ConstructedValueBlock";var Rx,tt=class extends et{constructor(e={}){super(e,qr),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} :`}};iw=Ye;Z.Constructed=iw;Ye.NAME="CONSTRUCTED";var wf=class extends ut{fromBER(e,t,n){return t}toBER(e){return Or}};wf.override="EndOfContentValueBlock";var sw,Ec=class extends Ze{constructor(e={}){super(e,wf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};sw=Ec;Z.EndOfContent=sw;Ec.NAME=Ac;var aw,Tr=class extends Ze{constructor(e={}){super(e,ut),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}`}};aw=Tr;Z.Null=aw;Tr.NAME="NULL";var vf=class extends Wr(ut){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=de.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);return In(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,wm.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};vf.NAME="BooleanValueBlock";var cw,si=class extends Ze{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,vf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};cw=si;Z.Boolean=cw;si.NAME="BOOLEAN";var Af=class extends Wr($r){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=$r.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===Ac){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==tw)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?$r.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Af.NAME="OctetStringValueBlock";var Em,kr=class extends Ze{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},Af),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=Ks(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 Ye.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=de.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof Em&&e.push(t.valueBlock.valueHexView);return de.BufferSourceConverter.concat(e)}};Em=kr;Z.OctetString=Em;kr.NAME=tw;var Sf=class extends Wr($r){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=$r.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Ac){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==rw)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return o}let i=de.BufferSourceConverter.toUint8Array(e);if(!In(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=Ks(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 $r.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Or;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}}};Sf.NAME="BitStringValueBlock";var uw,Pr=class extends Ze{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},Sf),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 Ye.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}`}}};uw=Pr;Z.BitString=uw;Pr.NAME=rw;var lw;function EC(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,l=0,h=c<s?s:c,p=0;for(let d=h;d>=0;d--,p++){switch(!0){case p<a.length:l=i[s-p]+a[c-p]+t[0];break;default:l=i[s-p]+t[0]}switch(t[0]=l/10,!0){case p>=i.length:i=mf(new Uint8Array([l%10]),i);break;default:i[s-p]=l%10}}return t[0]>0&&(i=mf(t,i)),i}function ew(r){if(r>=wc.length)for(let e=wc.length;e<=r;e++){let t=new Uint8Array([0]),n=wc[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=mf(t,n)),wc.push(n)}return wc[r]}function _C(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,l,h=0;for(let p=c;p>=0;p--,h++)switch(l=i[s-h]-a[c-h]-t,!0){case l<0:t=1,i[s-h]=l+10;break;default:t=0,i[s-h]=l}if(t>0)for(let p=s-c+1;p>=0;p--,h++)if(l=i[s-h]-t,l<0)t=1,i[s-h]=l+10;else{t=0,i[s-h]=l;break}return i.slice()}var _c=class extends Wr(ut){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=wm.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(Zx(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let l=0;l<8;l++){if((o&1)===1)switch(n){case e:t=_C(ew(n),t),s="-";break;default:t=EC(t,ew(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Jx.charAt(t[c]));return a===!1&&(s+=Jx.charAt(0)),s}};lw=_c;_c.NAME="IntegerValueBlock";Object.defineProperty(lw.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var vc,Bn=class extends Ze{constructor(e={}){super(e,_c),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return yf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){yf();let t=BigInt(e),n=new Ms,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(de.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${de.Convert.ToHex(a)}`)+t,h=de.BufferSourceConverter.toUint8Array(de.Convert.FromHex(l.toString(16)));h[0]|=128,n.write(h)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new vc({valueHex:n.final()})}convertToDER(){let e=new vc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new vc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};vc=Bn;Z.Integer=vc;Bn.NAME="INTEGER";var fw,ai=class extends Bn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};fw=ai;Z.Enumerated=fw;ai.NAME="ENUMERATED";var Cc=class extends Wr(ut){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=de.BufferSourceConverter.toUint8Array(e);if(!In(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=ii(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){yf();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=lo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Or;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=de.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Cc.NAME="sidBlock";var Ef=class extends ut{constructor({value:e=jt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Cc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.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,Or;t.push(o)}return Sm(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 Cc;if(o>Number.MAX_SAFE_INTEGER){yf();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};Ef.NAME="ObjectIdentifierValueBlock";var pw,ci=class extends Ze{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Ef),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};pw=ci;Z.ObjectIdentifier=pw;ci.NAME="OBJECT IDENTIFIER";var Bc=class extends Wr(_n){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=de.BufferSourceConverter.toUint8Array(e);if(!In(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=ii(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=lo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Or;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=de.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Bc.NAME="relativeSidBlock";var _f=class extends ut{constructor({value:e=jt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Bc;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,Or;n.push(i)}return Sm(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 Bc;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}};_f.NAME="RelativeObjectIdentifierValueBlock";var hw,Ic=class extends Ze{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,_f),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};hw=Ic;Z.RelativeObjectIdentifier=hw;Ic.NAME="RelativeObjectIdentifier";var dw,Et=class extends Ye{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};dw=Et;Z.Sequence=dw;Et.NAME="SEQUENCE";var mw,Pt=class extends Ye{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};mw=Pt;Z.Set=mw;Pt.NAME="SET";var Cf=class extends Wr(ut){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=jt}toJSON(){return{...super.toJSON(),value:this.value}}};Cf.NAME="StringValueBlock";var Bf=class extends Cf{};Bf.NAME="SimpleStringValueBlock";var Ot=class extends Sc{constructor({...e}={}){super(e,Bf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,de.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Ot.NAME="SIMPLE STRING";var If=class extends Ot{fromBuffer(e){this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=de.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=de.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf8String(e)),this.valueBlock.value=e}};If.NAME="Utf8StringValueBlock";var yw,ur=class extends If{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};yw=ur;Z.Utf8String=yw;ur.NAME="UTF8String";var Tf=class extends Ot{fromBuffer(e){this.valueBlock.value=de.Convert.ToUtf16String(e),this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf16String(e))}};Tf.NAME="BmpStringValueBlock";var gw,ui=class extends Tf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};gw=ui;Z.BmpString=gw;ui.NAME="BMPString";var kf=class extends Ot{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=lo(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 bw,li=class extends kf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};bw=li;Z.UniversalString=bw;li.NAME="UniversalString";var xw,fi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};xw=fi;Z.NumericString=xw;fi.NAME="NumericString";var ww,pi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};ww=pi;Z.PrintableString=ww;pi.NAME="PrintableString";var vw,hi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};vw=hi;Z.TeletexString=vw;hi.NAME="TeletexString";var Aw,di=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Aw=di;Z.VideotexString=Aw;di.NAME="VideotexString";var Sw,mi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Sw=mi;Z.IA5String=Sw;mi.NAME="IA5String";var Ew,yi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Ew=yi;Z.GraphicString=Ew;yi.NAME="GraphicString";var _w,fo=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};_w=fo;Z.VisibleString=_w;fo.NAME="VisibleString";var Cw,gi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Cw=gi;Z.GeneralString=Cw;gi.NAME="GeneralString";var Bw,bi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Bw=bi;Z.CharacterString=Bw;bi.NAME="CharacterString";var Iw,po=class extends fo{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,de.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Mt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Mt(this.month,2),t[2]=Mt(this.day,2),t[3]=Mt(this.hour,2),t[4]=Mt(this.minute,2),t[5]=Mt(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Iw=po;Z.UTCTime=Iw;po.NAME="UTCTime";var Tw,xi=class extends po{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let p=new Number(e[e.length-1]);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let p=1,d=n.indexOf("+"),y="";if(d===-1&&(d=n.indexOf("-"),p=-1),d!==-1){if(y=n.substring(d+1),n=n.substring(0,d),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(y.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*g,y.length===4){if(g=parseInt(y.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=p*g}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let p=new Number(`0${n.substring(l)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,l)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=60*i;this.minute=Math.floor(p),p=60*(p-this.minute),this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=60*i;this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let h=s.exec(o);if(h===null)throw new Error("Wrong input string for conversion");for(let p=1;p<h.length;p++)switch(p){case 1:this.year=parseInt(h[p],10);break;case 2:this.month=parseInt(h[p],10);break;case 3:this.day=parseInt(h[p],10);break;case 4:this.hour=parseInt(h[p],10)+a;break;case 5:this.minute=parseInt(h[p],10)+c;break;case 6:this.second=parseInt(h[p],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let p=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=p.getUTCFullYear(),this.month=p.getUTCMonth(),this.day=p.getUTCDay(),this.hour=p.getUTCHours(),this.minute=p.getUTCMinutes(),this.second=p.getUTCSeconds(),this.millisecond=p.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Mt(this.year,4)),t.push(Mt(this.month,2)),t.push(Mt(this.day,2)),t.push(Mt(this.hour,2)),t.push(Mt(this.minute,2)),t.push(Mt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Mt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Tw=xi;Z.GeneralizedTime=Tw;xi.NAME="GeneralizedTime";var kw,Tc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};kw=Tc;Z.DATE=kw;Tc.NAME="DATE";var Pw,kc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Pw=kc;Z.TimeOfDay=Pw;kc.NAME="TimeOfDay";var Ow,Pc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Ow=Pc;Z.DateTime=Ow;Pc.NAME="DateTime";var Nw,Oc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Nw=Oc;Z.Duration=Nw;Oc.NAME="Duration";var Dw,Nc=class extends ur{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Dw=Nc;Z.TIME=Dw;Nc.NAME="TIME";var Fr=class{constructor({name:e=jt,optional:t=!1}={}){this.name=e,this.optional=t}},js=class extends Fr{constructor({value:e=[],...t}={}){super(t),this.value=e}},wi=class extends Fr{constructor({value:e=new Fr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Am=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=de.BufferSourceConverter.toUint8Array(e)}constructor({data:e=Pf}={}){this.dataView=de.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=de.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function En(r,e,t){if(t instanceof js){for(let i of t.value)if(En(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(vm)&&(i.name=t.name),i}}if(t instanceof Fr)return t.hasOwnProperty(vm)&&(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(!(mC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(xC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(wC 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(yC)===!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(gC)===!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(bC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(dC 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(!(Qx 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,jt),t.name&&(r[t.name]=e)),t instanceof Z.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof wi&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let l=0;l<t.valueBlock.value.length;l++)c=c&&(t.valueBlock.value[l].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,jt),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){let l={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,jt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof wi){if(s=En(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,jt),t.name&&delete r[t.name]),s;if(vm in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};vC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?l=e:l=r,typeof l[t.valueBlock.value[0].name]>"u"&&(l[t.valueBlock.value[0].name]=[]),l[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=En(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,jt),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,jt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Qx in e.valueBlock){let i=Ks(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,jt),t.name&&(delete r[t.name],s.name=t.name)),s}return En(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function CC(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Ks(de.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:En(t.result,t.result,e)}var S;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(S||(S={}));var m;(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"})(m||(m={}));var _m=Mr(Sn()),Gr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(_m.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=_m.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Pr))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 Pr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Pr({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 Cm=Mr(Sn()),ie=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Cm.BufferSourceConverter.isBufferSource(e)?this.buffer=Cm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof kr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new kr({valueHex:this.buffer})}toSchema(e){return new kr({name:e})}};var BC={fromASN:r=>r instanceof Tr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Tr;let e=Tn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},IC={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Bn({value:+r})},TC={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new ai({value:r})},ye={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Bn({valueHex:r})};var kC={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Pr({valueHex:r})},PC={fromASN:r=>r.valueBlock.toString(),toASN:r=>new ci({value:r})},OC={fromASN:r=>r.valueBlock.value,toASN:r=>new si({value:r})},Hs={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new kr({valueHex:r})},Rw={fromASN:r=>new ie(r.getValue()),toASN:r=>r.toASN()};function lr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Bm=lr(ur),NC=lr(ui),DC=lr(li),RC=lr(fi),LC=lr(pi),UC=lr(hi),MC=lr(di),jC=lr(mi),KC=lr(yi),HC=lr(fo),VC=lr(gi),$C=lr(bi),FC={fromASN:r=>r.toDate(),toASN:r=>new po({valueDate:r})},WC={fromASN:r=>r.toDate(),toASN:r=>new xi({valueDate:r})},qC={fromASN:()=>null,toASN:()=>new Tr};function ho(r){switch(r){case m.Any:return BC;case m.BitString:return kC;case m.BmpString:return NC;case m.Boolean:return OC;case m.CharacterString:return $C;case m.Enumerated:return TC;case m.GeneralString:return VC;case m.GeneralizedTime:return WC;case m.GraphicString:return KC;case m.IA5String:return jC;case m.Integer:return IC;case m.Null:return qC;case m.NumericString:return RC;case m.ObjectIdentifier:return PC;case m.OctetString:return Hs;case m.PrintableString:return LC;case m.TeletexString:return UC;case m.UTCTime:return FC;case m.UniversalString:return DC;case m.Utf8String:return Bm;case m.VideotexString:return MC;case m.VisibleString:return HC;default:return null}}function fr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:fr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Tm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Tm(t)}return!1}function Lw(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 Of=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:S.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let h=m[s.type],p=qr[h];if(!p)throw new Error(`Cannot get ASN1 class by name '${h}'`);c=new p({name:a})}else fr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===S.Choice?c=new Fr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Fr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let h=s.repeated==="set"?Pt:Et;c=new h({name:"",value:[new wi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||fr(s.type)){let h=s.repeated?Ye:Cn;o.push(new h({name:a,optional:l,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let h=!!s.repeated,p=h?c:this.get(s.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,o.push(new Ye({name:h?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new Ye({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case S.Sequence:return new Et({value:o,name:""});case S.Set:return new Pt({value:o,name:""});case S.Choice:return new js({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 Fe=new Of;var B=r=>e=>{let t;Fe.has(e)?t=Fe.get(e):(t=Fe.createDefault(e),Fe.set(e,t)),Object.assign(t,r)};var f=r=>(e,t)=>{let n;Fe.has(e.constructor)?n=Fe.get(e.constructor):(n=Fe.createDefault(e.constructor),Fe.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=ho(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}n.items[t]=o};var mo=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Dc=class{static parse(e,t){let n=Tn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(fr(t))return new t().fromASN(e);let n=Fe.get(t);Fe.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 Tm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof mo&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===Ye&&t.type===S.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"&&Fe.has(s.type)){let a=Fe.get(s.type);if(a&&a.type===S.Sequence){let c=new Et;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let l=this.fromASN(c,s.type),h=new n;return h[i]=l,{result:h}}}}}else if(e.constructor===Ye&&t.type!==S.Choice){let i=new Ye({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===S.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&Fe.has(c.type)&&Fe.get(c.type).type===S.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=En({},e,o);if(!s.verified)throw new mo(`Data does not match to ${n.name} ASN1 schema. ${s.result.error}`);return s}else{let i=En({},e,o);if(!i.verified)throw new mo(`Data does not match to ${n.name} ASN1 schema. ${i.result.error}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let l=s[c],h=t.items[l];if(a>=i.length)break;if(h.repeated){o[l]=this.processRepeatedField(i,a,h);break}else if(typeof h.type=="number")o[l]=this.processPrimitiveField(i[a],h),a++;else if(this.isOptionalChoiceField(h)){let p=this.processOptionalChoiceField(i[a],h);p.processed&&(o[l]=p.value,a++)}else o[l]=this.fromASN(i[a],h.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=ho(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=ho(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"&&Fe.has(e.type)&&Fe.get(e.type).type===S.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof mo&&/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=ho(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type;typeof a=="number"||fr(a)?n[o]=this.processPrimitiveSchemaItem(i,s,a):n[o]=this.processComplexSchemaItem(i,s,a)}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:fr(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"?Et:Pt,i=new o;i.valueBlock=e.valueBlock;let s=Tn(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(fr(n))s=new n().toSchema("");else{let a=m[n],c=qr[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Tn(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 mo&&/Wrong values for Choice type/.test(i.message))return;throw i}else return this.fromASN(o,n)}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=Fe.get(n);if(o.type===S.Sequence){let i=new Et;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===S.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 Rc=class r{static serialize(e){return e instanceof Ze?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&fr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Fe.get(t);Fe.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=ho(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"&&Lw(this.serialize(a.defaultValue),this.serialize(c)))continue;let l=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||fr(a.type))){let h={};h.valueHex=l instanceof Tr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new Cn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...h}))}else o.push(new Ye({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new Ye({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else a.repeated?o=o.concat(l):o.push(l)}let i;switch(n.type){case S.Sequence:i=new Et({value:o});break;case S.Set:i=new Pt({value:o});break;case S.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 ${m[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,l=>s.toASN(l)),c=e.repeated==="sequence"?Et: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"?Et: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 km=Mr(Sn());var F=class r{static serialize(e){return Rc.serialize(e)}static parse(e,t){return Dc.parse(e,t)}static toString(e){let t=km.BufferSourceConverter.isBufferSource(e)?km.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Tn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function 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}var Uw=Mr(Sn()),Lc=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,l)=>c+(l.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(Uw.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 Mw=Mr(Sn()),Pm,Om,Nm,Je=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};u([f({type:m.TeletexString})],Je.prototype,"teletexString",void 0);u([f({type:m.PrintableString})],Je.prototype,"printableString",void 0);u([f({type:m.UniversalString})],Je.prototype,"universalString",void 0);u([f({type:m.Utf8String})],Je.prototype,"utf8String",void 0);u([f({type:m.BmpString})],Je.prototype,"bmpString",void 0);Je=u([B({type:S.Choice})],Je);var Vs=class extends Je{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Mw.Convert.ToHex(this.anyValue):super.toString())}};u([f({type:m.IA5String})],Vs.prototype,"ia5String",void 0);u([f({type:m.Any})],Vs.prototype,"anyValue",void 0);Vs=u([B({type:S.Choice})],Vs);var vi=class{constructor(e={}){this.type="",this.value=new Vs,Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],vi.prototype,"type",void 0);u([f({type:Vs})],vi.prototype,"value",void 0);var yo=Pm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Pm.prototype)}};yo=Pm=u([B({type:S.Set,itemType:vi})],yo);var Dm=Om=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Om.prototype)}};Dm=Om=u([B({type:S.Sequence,itemType:yo})],Dm);var ke=Nm=class extends Dm{constructor(e){super(e),Object.setPrototypeOf(this,Nm.prototype)}};ke=Nm=u([B({type:S.Sequence})],ke);var GC={fromASN:r=>Lc.toString(Hs.fromASN(r)),toASN:r=>Hs.toASN(Lc.fromString(r))},go=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],go.prototype,"typeId",void 0);u([f({type:m.Any,context:0})],go.prototype,"value",void 0);var Uc=class{constructor(e={}){this.partyName=new Je,Object.assign(this,e)}};u([f({type:Je,optional:!0,context:0,implicit:!0})],Uc.prototype,"nameAssigner",void 0);u([f({type:Je,context:1,implicit:!0})],Uc.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};u([f({type:go,context:0,implicit:!0})],ae.prototype,"otherName",void 0);u([f({type:m.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);u([f({type:m.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);u([f({type:m.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);u([f({type:ke,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);u([f({type:Uc,context:5})],ae.prototype,"ediPartyName",void 0);u([f({type:m.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);u([f({type:m.OctetString,context:7,implicit:!0,converter:GC})],ae.prototype,"iPAddress",void 0);u([f({type:m.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=u([B({type:S.Choice})],ae);var bo="1.3.6.1.5.5.7",xo=`${bo}.1`,jw=`${bo}.2`,Ai=`${bo}.3`,Nf=`${bo}.48`,T3=`${jw}.1`,k3=`${jw}.2`,Rm=`${Nf}.1`,Lm=`${Nf}.2`,Um=`${Nf}.3`,Mm=`${Nf}.5`,le="2.5.29";var jm,Df=`${xo}.1`,kn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],kn.prototype,"accessMethod",void 0);u([f({type:ae})],kn.prototype,"accessLocation",void 0);var Si=jm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,jm.prototype)}};Si=jm=u([B({type:S.Sequence,itemType:kn})],Si);var Rf=`${le}.35`,Ei=class extends ie{},zr=class{constructor(e={}){e&&Object.assign(this,e)}};u([f({type:Ei,context:0,optional:!0,implicit:!0})],zr.prototype,"keyIdentifier",void 0);u([f({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],zr.prototype,"authorityCertIssuer",void 0);u([f({type:m.Integer,context:2,optional:!0,implicit:!0,converter:ye})],zr.prototype,"authorityCertSerialNumber",void 0);var Lf=`${le}.19`,_i=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};u([f({type:m.Boolean,defaultValue:!1})],_i.prototype,"cA",void 0);u([f({type:m.Integer,optional:!0})],_i.prototype,"pathLenConstraint",void 0);var Km,je=Km=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Km.prototype)}};je=Km=u([B({type:S.Sequence,itemType:ae})],je);var Hm,zC=`${le}.29`,Kw=Hm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Hm.prototype)}};Kw=Hm=u([B({type:S.Sequence})],Kw);var Vm,Mf=`${le}.32`,cD=`${Mf}.0`,Pn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};u([f({type:m.IA5String})],Pn.prototype,"ia5String",void 0);u([f({type:m.VisibleString})],Pn.prototype,"visibleString",void 0);u([f({type:m.BmpString})],Pn.prototype,"bmpString",void 0);u([f({type:m.Utf8String})],Pn.prototype,"utf8String",void 0);Pn=u([B({type:S.Choice})],Pn);var Mc=class{constructor(e={}){this.organization=new Pn,this.noticeNumbers=[],Object.assign(this,e)}};u([f({type:Pn})],Mc.prototype,"organization",void 0);u([f({type:m.Integer,repeated:"sequence"})],Mc.prototype,"noticeNumbers",void 0);var jc=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Mc,optional:!0})],jc.prototype,"noticeRef",void 0);u([f({type:Pn,optional:!0})],jc.prototype,"explicitText",void 0);var Uf=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.IA5String})],Uf.prototype,"cPSuri",void 0);u([f({type:jc})],Uf.prototype,"userNotice",void 0);Uf=u([B({type:S.Choice})],Uf);var Kc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Kc.prototype,"policyQualifierId",void 0);u([f({type:m.Any})],Kc.prototype,"qualifier",void 0);var Ci=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Ci.prototype,"policyIdentifier",void 0);u([f({type:Kc,repeated:"sequence",optional:!0})],Ci.prototype,"policyQualifiers",void 0);var Hc=Vm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Vm.prototype)}};Hc=Vm=u([B({type:S.Sequence,itemType:Ci})],Hc);var yD=`${le}.20`,Vc=class{constructor(e=0){this.value=e}};u([f({type:m.Integer})],Vc.prototype,"value",void 0);Vc=u([B({type:S.Choice})],Vc);var SD=`${le}.27`,Hw=class extends Vc{};Hw=u([B({type:S.Choice})],Hw);var $m,jf=`${le}.31`,Nr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Nr||(Nr={}));var $c=class extends Gr{toJSON(){let e=[],t=this.toNumber();return t&Nr.aACompromise&&e.push("aACompromise"),t&Nr.affiliationChanged&&e.push("affiliationChanged"),t&Nr.cACompromise&&e.push("cACompromise"),t&Nr.certificateHold&&e.push("certificateHold"),t&Nr.cessationOfOperation&&e.push("cessationOfOperation"),t&Nr.keyCompromise&&e.push("keyCompromise"),t&Nr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Nr.superseded&&e.push("superseded"),t&Nr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},On=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,context:0,repeated:"sequence",implicit:!0})],On.prototype,"fullName",void 0);u([f({type:yo,context:1,implicit:!0})],On.prototype,"nameRelativeToCRLIssuer",void 0);On=u([B({type:S.Choice})],On);var Xr=class{constructor(e={}){Object.assign(this,e)}};u([f({type:On,context:0,optional:!0})],Xr.prototype,"distributionPoint",void 0);u([f({type:$c,context:1,optional:!0,implicit:!0})],Xr.prototype,"reasons",void 0);u([f({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],Xr.prototype,"cRLIssuer",void 0);var wo=$m=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,$m.prototype)}};wo=$m=u([B({type:S.Sequence,itemType:Xr})],wo);var Fm,MD=`${le}.46`,Vw=Fm=class extends wo{constructor(e){super(e),Object.setPrototypeOf(this,Fm.prototype)}};Vw=Fm=u([B({type:S.Sequence,itemType:Xr})],Vw);var qD=`${le}.28`,Yt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Yt.ONLY=!1;u([f({type:On,context:0,optional:!0})],Yt.prototype,"distributionPoint",void 0);u([f({type:m.Boolean,context:1,defaultValue:Yt.ONLY,implicit:!0})],Yt.prototype,"onlyContainsUserCerts",void 0);u([f({type:m.Boolean,context:2,defaultValue:Yt.ONLY,implicit:!0})],Yt.prototype,"onlyContainsCACerts",void 0);u([f({type:$c,context:3,optional:!0,implicit:!0})],Yt.prototype,"onlySomeReasons",void 0);u([f({type:m.Boolean,context:4,defaultValue:Yt.ONLY,implicit:!0})],Yt.prototype,"indirectCRL",void 0);u([f({type:m.Boolean,context:5,defaultValue:Yt.ONLY,implicit:!0})],Yt.prototype,"onlyContainsAttributeCerts",void 0);var $w=`${le}.21`,Fc;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(Fc||(Fc={}));var Wc=class{constructor(e=Fc.unspecified){this.reason=Fc.unspecified,this.reason=e}toJSON(){return Fc[this.reason]}toString(){return this.toJSON()}};u([f({type:m.Enumerated})],Wc.prototype,"reason",void 0);Wc=u([B({type:S.Choice})],Wc);var Wm,Kf=`${le}.37`,qc=Wm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Wm.prototype)}};qc=Wm=u([B({type:S.Sequence,itemType:m.ObjectIdentifier})],qc);var nR=`${Kf}.0`,Fw=`${Ai}.1`,Ww=`${Ai}.2`,qw=`${Ai}.3`,Gw=`${Ai}.4`,zw=`${Ai}.8`,Xw=`${Ai}.9`;var cR=`${le}.54`,qm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};u([f({type:m.Integer,converter:ye})],qm.prototype,"value",void 0);qm=u([B({type:S.Choice})],qm);var Zw=`${le}.24`,Gc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};u([f({type:m.GeneralizedTime})],Gc.prototype,"value",void 0);Gc=u([B({type:S.Choice})],Gc);var Gm,zm=`${le}.18`,Yw=Gm=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};Yw=Gm=u([B({type:S.Sequence})],Yw);var Hf=`${le}.15`,Dr;(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"})(Dr||(Dr={}));var $s=class extends Gr{toJSON(){let e=this.toNumber(),t=[];return e&Dr.cRLSign&&t.push("crlSign"),e&Dr.dataEncipherment&&t.push("dataEncipherment"),e&Dr.decipherOnly&&t.push("decipherOnly"),e&Dr.digitalSignature&&t.push("digitalSignature"),e&Dr.encipherOnly&&t.push("encipherOnly"),e&Dr.keyAgreement&&t.push("keyAgreement"),e&Dr.keyCertSign&&t.push("keyCertSign"),e&Dr.keyEncipherment&&t.push("keyEncipherment"),e&Dr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var Xm,TR=`${le}.30`,Fs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};u([f({type:ae})],Fs.prototype,"base",void 0);u([f({type:m.Integer,context:0,defaultValue:0,implicit:!0})],Fs.prototype,"minimum",void 0);u([f({type:m.Integer,context:1,optional:!0,implicit:!0})],Fs.prototype,"maximum",void 0);var Vf=Xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};Vf=Xm=u([B({type:S.Sequence,itemType:Fs})],Vf);var $f=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Vf,context:0,optional:!0,implicit:!0})],$f.prototype,"permittedSubtrees",void 0);u([f({type:Vf,context:1,optional:!0,implicit:!0})],$f.prototype,"excludedSubtrees",void 0);var RR=`${le}.36`,Ff=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.Integer,context:0,implicit:!0,optional:!0,converter:ye})],Ff.prototype,"requireExplicitPolicy",void 0);u([f({type:m.Integer,context:1,implicit:!0,optional:!0,converter:ye})],Ff.prototype,"inhibitPolicyMapping",void 0);var Zm,KR=`${le}.33`,zc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],zc.prototype,"issuerDomainPolicy",void 0);u([f({type:m.ObjectIdentifier})],zc.prototype,"subjectDomainPolicy",void 0);var Jw=Zm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Zm.prototype)}};Jw=Zm=u([B({type:S.Sequence,itemType:zc})],Jw);var Ym,Jm=`${le}.17`,Wf=Ym=class extends je{constructor(e){super(e),Object.setPrototypeOf(this,Ym.prototype)}};Wf=Ym=u([B({type:S.Sequence})],Wf);var lt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],lt.prototype,"type",void 0);u([f({type:m.Any,repeated:"set"})],lt.prototype,"values",void 0);var Qm,rL=`${le}.9`,Qw=Qm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};Qw=Qm=u([B({type:S.Sequence,itemType:lt})],Qw);var ey=`${le}.14`,Kt=class extends Ei{};var fL=`${le}.16`,qf=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.GeneralizedTime,context:0,implicit:!0,optional:!0})],qf.prototype,"notBefore",void 0);u([f({type:m.GeneralizedTime,context:1,implicit:!0,optional:!0})],qf.prototype,"notAfter",void 0);var Xc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Xc||(Xc={}));var Gf=class extends Gr{toJSON(){let e=[],t=this.toNumber();return t&Xc.pKIXCertificate&&e.push("pKIXCertificate"),t&Xc.newExtensions&&e.push("newExtensions"),t&Xc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},zf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Gf,Object.assign(this,e)}};u([f({type:m.GeneralString})],zf.prototype,"entrustVers",void 0);u([f({type:Gf})],zf.prototype,"entrustInfoFlags",void 0);var ty,wL=`${xo}.11`,ev=ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};ev=ty=u([B({type:S.Sequence,itemType:kn})],ev);var tv=Mr(Sn()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&tv.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};u([f({type:m.ObjectIdentifier})],M.prototype,"algorithm",void 0);u([f({type:m.Any,optional:!0})],M.prototype,"parameters",void 0);var ft=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:M})],ft.prototype,"algorithm",void 0);u([f({type:m.BitString})],ft.prototype,"subjectPublicKey",void 0);var We=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};u([f({type:m.UTCTime})],We.prototype,"utcTime",void 0);u([f({type:m.GeneralizedTime})],We.prototype,"generalTime",void 0);We=u([B({type:S.Choice})],We);var Nn=class{constructor(e){this.notBefore=new We(new Date),this.notAfter=new We(new Date),e&&(this.notBefore=new We(e.notBefore),this.notAfter=new We(e.notAfter))}};u([f({type:We})],Nn.prototype,"notBefore",void 0);u([f({type:We})],Nn.prototype,"notAfter",void 0);var ry,pt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ie,Object.assign(this,e)}};pt.CRITICAL=!1;u([f({type:m.ObjectIdentifier})],pt.prototype,"extnID",void 0);u([f({type:m.Boolean,defaultValue:pt.CRITICAL})],pt.prototype,"critical",void 0);u([f({type:ie})],pt.prototype,"extnValue",void 0);var Jt=ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};Jt=ry=u([B({type:S.Sequence,itemType:pt})],Jt);var Zr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(Zr||(Zr={}));var ht=class{constructor(e={}){this.version=Zr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new ke,this.validity=new Nn,this.subject=new ke,this.subjectPublicKeyInfo=new ft,Object.assign(this,e)}};u([f({type:m.Integer,context:0,defaultValue:Zr.v1})],ht.prototype,"version",void 0);u([f({type:m.Integer,converter:ye})],ht.prototype,"serialNumber",void 0);u([f({type:M})],ht.prototype,"signature",void 0);u([f({type:ke})],ht.prototype,"issuer",void 0);u([f({type:Nn})],ht.prototype,"validity",void 0);u([f({type:ke})],ht.prototype,"subject",void 0);u([f({type:ft})],ht.prototype,"subjectPublicKeyInfo",void 0);u([f({type:m.BitString,context:1,implicit:!0,optional:!0})],ht.prototype,"issuerUniqueID",void 0);u([f({type:m.BitString,context:2,implicit:!0,optional:!0})],ht.prototype,"subjectUniqueID",void 0);u([f({type:Jt,context:3,optional:!0})],ht.prototype,"extensions",void 0);var pr=class{constructor(e={}){this.tbsCertificate=new ht,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:ht})],pr.prototype,"tbsCertificate",void 0);u([f({type:M})],pr.prototype,"signatureAlgorithm",void 0);u([f({type:m.BitString})],pr.prototype,"signatureValue",void 0);var Bi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new We,Object.assign(this,e)}};u([f({type:m.Integer,converter:ye})],Bi.prototype,"userCertificate",void 0);u([f({type:We})],Bi.prototype,"revocationDate",void 0);u([f({type:pt,optional:!0,repeated:"sequence"})],Bi.prototype,"crlEntryExtensions",void 0);var Qt=class{constructor(e={}){this.signature=new M,this.issuer=new ke,this.thisUpdate=new We,Object.assign(this,e)}};u([f({type:m.Integer,optional:!0})],Qt.prototype,"version",void 0);u([f({type:M})],Qt.prototype,"signature",void 0);u([f({type:ke})],Qt.prototype,"issuer",void 0);u([f({type:We})],Qt.prototype,"thisUpdate",void 0);u([f({type:We,optional:!0})],Qt.prototype,"nextUpdate",void 0);u([f({type:Bi,repeated:"sequence",optional:!0})],Qt.prototype,"revokedCertificates",void 0);u([f({type:pt,optional:!0,context:0,repeated:"sequence"})],Qt.prototype,"crlExtensions",void 0);var Ii=class{constructor(e={}){this.tbsCertList=new Qt,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:Qt})],Ii.prototype,"tbsCertList",void 0);u([f({type:M})],Ii.prototype,"signatureAlgorithm",void 0);u([f({type:m.BitString})],Ii.prototype,"signature",void 0);var K=Mr(Sn());var Rr=class{constructor(e={}){this.issuer=new ke,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:ke})],Rr.prototype,"issuer",void 0);u([f({type:m.Integer,converter:ye})],Rr.prototype,"serialNumber",void 0);var Ti=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Kt,context:0,implicit:!0})],Ti.prototype,"subjectKeyIdentifier",void 0);u([f({type:Rr})],Ti.prototype,"issuerAndSerialNumber",void 0);Ti=u([B({type:S.Choice})],Ti);var dt;(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"})(dt||(dt={}));var ki=class extends M{};ki=u([B({type:S.Sequence})],ki);var Zc=class extends M{};Zc=u([B({type:S.Sequence})],Zc);var Ht=class extends M{};Ht=u([B({type:S.Sequence})],Ht);var Yc=class extends M{};Yc=u([B({type:S.Sequence})],Yc);var nv=class extends M{};nv=u([B({type:S.Sequence})],nv);var Xf=class extends M{};Xf=u([B({type:S.Sequence})],Xf);var Lr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Lr.prototype,"attrType",void 0);u([f({type:m.Any,repeated:"set"})],Lr.prototype,"attrValues",void 0);var ny,Vt=class{constructor(e={}){this.version=dt.v0,this.sid=new Ti,this.digestAlgorithm=new ki,this.signatureAlgorithm=new Zc,this.signature=new ie,Object.assign(this,e)}};u([f({type:m.Integer})],Vt.prototype,"version",void 0);u([f({type:Ti})],Vt.prototype,"sid",void 0);u([f({type:ki})],Vt.prototype,"digestAlgorithm",void 0);u([f({type:Lr,repeated:"set",context:0,implicit:!0,optional:!0})],Vt.prototype,"signedAttrs",void 0);u([f({type:Zc})],Vt.prototype,"signatureAlgorithm",void 0);u([f({type:ie})],Vt.prototype,"signature",void 0);u([f({type:Lr,repeated:"set",context:1,implicit:!0,optional:!0})],Vt.prototype,"unsignedAttrs",void 0);var Jc=ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};Jc=ny=u([B({type:S.Set,itemType:Vt})],Jc);var ov=class extends We{};ov=u([B({type:S.Choice})],ov);var iv=class extends Vt{};iv=u([B({type:S.Sequence})],iv);var Qc=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};u([f({type:ae})],Qc.prototype,"acIssuer",void 0);u([f({type:m.Integer})],Qc.prototype,"acSerial",void 0);u([f({type:lt,repeated:"sequence"})],Qc.prototype,"attrs",void 0);var oy,eu=oy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,oy.prototype)}};eu=oy=u([B({type:S.Sequence,itemType:m.ObjectIdentifier})],eu);var Ws=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};u([f({type:m.Integer,optional:!0})],Ws.prototype,"pathLenConstraint",void 0);u([f({type:eu,implicit:!0,context:0,optional:!0})],Ws.prototype,"permittedAttrs",void 0);u([f({type:eu,implicit:!0,context:1,optional:!0})],Ws.prototype,"excludedAttrs",void 0);u([f({type:m.Boolean,defaultValue:!0})],Ws.prototype,"permitUnSpecified",void 0);var hr=class{constructor(e={}){this.issuer=new je,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:je})],hr.prototype,"issuer",void 0);u([f({type:m.Integer,converter:ye})],hr.prototype,"serial",void 0);u([f({type:m.BitString,optional:!0})],hr.prototype,"issuerUID",void 0);var iy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(iy||(iy={}));var dr=class{constructor(e={}){this.digestedObjectType=iy.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.Enumerated})],dr.prototype,"digestedObjectType",void 0);u([f({type:m.ObjectIdentifier,optional:!0})],dr.prototype,"otherObjectTypeID",void 0);u([f({type:M})],dr.prototype,"digestAlgorithm",void 0);u([f({type:m.BitString})],dr.prototype,"objectDigest",void 0);var Pi=class{constructor(e={}){Object.assign(this,e)}};u([f({type:je,optional:!0})],Pi.prototype,"issuerName",void 0);u([f({type:hr,context:0,implicit:!0,optional:!0})],Pi.prototype,"baseCertificateID",void 0);u([f({type:dr,context:1,implicit:!0,optional:!0})],Pi.prototype,"objectDigestInfo",void 0);var Oi=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,repeated:"sequence"})],Oi.prototype,"v1Form",void 0);u([f({type:Pi,context:0,implicit:!0})],Oi.prototype,"v2Form",void 0);Oi=u([B({type:S.Choice})],Oi);var Ni=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};u([f({type:m.GeneralizedTime})],Ni.prototype,"notBeforeTime",void 0);u([f({type:m.GeneralizedTime})],Ni.prototype,"notAfterTime",void 0);var vo=class{constructor(e={}){Object.assign(this,e)}};u([f({type:hr,implicit:!0,context:0,optional:!0})],vo.prototype,"baseCertificateID",void 0);u([f({type:je,implicit:!0,context:1,optional:!0})],vo.prototype,"entityName",void 0);u([f({type:dr,implicit:!0,context:2,optional:!0})],vo.prototype,"objectDigestInfo",void 0);var sy;(function(r){r[r.v2=1]="v2"})(sy||(sy={}));var $t=class{constructor(e={}){this.version=sy.v2,this.holder=new vo,this.issuer=new Oi,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Ni,this.attributes=[],Object.assign(this,e)}};u([f({type:m.Integer})],$t.prototype,"version",void 0);u([f({type:vo})],$t.prototype,"holder",void 0);u([f({type:Oi})],$t.prototype,"issuer",void 0);u([f({type:M})],$t.prototype,"signature",void 0);u([f({type:m.Integer,converter:ye})],$t.prototype,"serialNumber",void 0);u([f({type:Ni})],$t.prototype,"attrCertValidityPeriod",void 0);u([f({type:lt,repeated:"sequence"})],$t.prototype,"attributes",void 0);u([f({type:m.BitString,optional:!0})],$t.prototype,"issuerUniqueID",void 0);u([f({type:Jt,optional:!0})],$t.prototype,"extensions",void 0);var Di=class{constructor(e={}){this.acinfo=new $t,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:$t})],Di.prototype,"acinfo",void 0);u([f({type:M})],Di.prototype,"signatureAlgorithm",void 0);u([f({type:m.BitString})],Di.prototype,"signatureValue",void 0);var tu;(function(r){r[r.unmarked=1]="unmarked",r[r.unclassified=2]="unclassified",r[r.restricted=4]="restricted",r[r.confidential=8]="confidential",r[r.secret=16]="secret",r[r.topSecret=32]="topSecret"})(tu||(tu={}));var qs=class extends Gr{};var Gs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier,implicit:!0,context:0})],Gs.prototype,"type",void 0);u([f({type:m.Any,implicit:!0,context:1})],Gs.prototype,"value",void 0);var ru=class{constructor(e={}){this.policyId="",this.classList=new qs(tu.unclassified),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],ru.prototype,"policyId",void 0);u([f({type:qs,defaultValue:new qs(tu.unclassified)})],ru.prototype,"classList",void 0);u([f({type:Gs,repeated:"set"})],ru.prototype,"securityCategories",void 0);var zs=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie})],zs.prototype,"cotets",void 0);u([f({type:m.ObjectIdentifier})],zs.prototype,"oid",void 0);u([f({type:m.Utf8String})],zs.prototype,"string",void 0);var Zf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};u([f({type:je,implicit:!0,context:0,optional:!0})],Zf.prototype,"policyAuthority",void 0);u([f({type:zs,repeated:"sequence"})],Zf.prototype,"values",void 0);var e9=`${xo}.4`,t9=`${xo}.6`,r9=`${xo}.10`,n9=`${le}.55`,nu=`${bo}.10`,o9=`${nu}.1`,i9=`${nu}.2`,s9=`${nu}.3`,a9=`${nu}.4`,c9=`${nu}.6`,ay="2.5.4",u9=`${ay}.72`;var cy,Xs=class{constructor(e={}){this.targetCertificate=new hr,Object.assign(this,e)}};u([f({type:hr})],Xs.prototype,"targetCertificate",void 0);u([f({type:ae,optional:!0})],Xs.prototype,"targetName",void 0);u([f({type:dr,optional:!0})],Xs.prototype,"certDigestInfo",void 0);var Zs=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,context:0,implicit:!0})],Zs.prototype,"targetName",void 0);u([f({type:ae,context:1,implicit:!0})],Zs.prototype,"targetGroup",void 0);u([f({type:Xs,context:2,implicit:!0})],Zs.prototype,"targetCert",void 0);Zs=u([B({type:S.Choice})],Zs);var Yf=cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cy.prototype)}};Yf=cy=u([B({type:S.Sequence,itemType:Zs})],Yf);var uy,sv=uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};sv=uy=u([B({type:S.Sequence,itemType:Yf})],sv);var Jf=class{constructor(e={}){Object.assign(this,e)}};u([f({type:je,implicit:!0,context:0,optional:!0})],Jf.prototype,"roleAuthority",void 0);u([f({type:ae,implicit:!0,context:1})],Jf.prototype,"roleName",void 0);var ou=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};u([f({type:ae})],ou.prototype,"service",void 0);u([f({type:ae})],ou.prototype,"ident",void 0);u([f({type:ie,optional:!0})],ou.prototype,"authInfo",void 0);var ly,iu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],iu.prototype,"otherCertFormat",void 0);u([f({type:m.Any})],iu.prototype,"otherCert",void 0);var Ri=class{constructor(e={}){Object.assign(this,e)}};u([f({type:pr})],Ri.prototype,"certificate",void 0);u([f({type:Di,context:2,implicit:!0})],Ri.prototype,"v2AttrCert",void 0);u([f({type:iu,context:3,implicit:!0})],Ri.prototype,"other",void 0);Ri=u([B({type:S.Choice})],Ri);var Li=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};Li=ly=u([B({type:S.Set,itemType:Ri})],Li);var mr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],mr.prototype,"contentType",void 0);u([f({type:m.Any,context:0})],mr.prototype,"content",void 0);var Ys=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie})],Ys.prototype,"single",void 0);u([f({type:m.Any})],Ys.prototype,"any",void 0);Ys=u([B({type:S.Choice})],Ys);var Ui=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Ui.prototype,"eContentType",void 0);u([f({type:Ys,context:0,optional:!0})],Ui.prototype,"eContent",void 0);var su=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie,context:0,implicit:!0,optional:!0})],su.prototype,"value",void 0);u([f({type:ie,converter:Rw,context:0,implicit:!0,optional:!0,repeated:"sequence"})],su.prototype,"constructedValue",void 0);su=u([B({type:S.Choice})],su);var Ao=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Yc,Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Ao.prototype,"contentType",void 0);u([f({type:Yc})],Ao.prototype,"contentEncryptionAlgorithm",void 0);u([f({type:su,optional:!0})],Ao.prototype,"encryptedContent",void 0);var So=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],So.prototype,"keyAttrId",void 0);u([f({type:m.Any,optional:!0})],So.prototype,"keyAttr",void 0);var fy,Js=class{constructor(e={}){this.subjectKeyIdentifier=new Kt,Object.assign(this,e)}};u([f({type:Kt})],Js.prototype,"subjectKeyIdentifier",void 0);u([f({type:m.GeneralizedTime,optional:!0})],Js.prototype,"date",void 0);u([f({type:So,optional:!0})],Js.prototype,"other",void 0);var Qs=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Js,context:0,implicit:!0,optional:!0})],Qs.prototype,"rKeyId",void 0);u([f({type:Rr,optional:!0})],Qs.prototype,"issuerAndSerialNumber",void 0);Qs=u([B({type:S.Choice})],Qs);var au=class{constructor(e={}){this.rid=new Qs,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:Qs})],au.prototype,"rid",void 0);u([f({type:ie})],au.prototype,"encryptedKey",void 0);var Qf=fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};Qf=fy=u([B({type:S.Sequence,itemType:au})],Qf);var cu=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:M})],cu.prototype,"algorithm",void 0);u([f({type:m.BitString})],cu.prototype,"publicKey",void 0);var Mi=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Kt,context:0,implicit:!0,optional:!0})],Mi.prototype,"subjectKeyIdentifier",void 0);u([f({type:cu,context:1,implicit:!0,optional:!0})],Mi.prototype,"originatorKey",void 0);u([f({type:Rr,optional:!0})],Mi.prototype,"issuerAndSerialNumber",void 0);Mi=u([B({type:S.Choice})],Mi);var Dn=class{constructor(e={}){this.version=dt.v3,this.originator=new Mi,this.keyEncryptionAlgorithm=new Ht,this.recipientEncryptedKeys=new Qf,Object.assign(this,e)}};u([f({type:m.Integer})],Dn.prototype,"version",void 0);u([f({type:Mi,context:0})],Dn.prototype,"originator",void 0);u([f({type:ie,context:1,optional:!0})],Dn.prototype,"ukm",void 0);u([f({type:Ht})],Dn.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:Qf})],Dn.prototype,"recipientEncryptedKeys",void 0);var ea=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Kt,context:0,implicit:!0})],ea.prototype,"subjectKeyIdentifier",void 0);u([f({type:Rr})],ea.prototype,"issuerAndSerialNumber",void 0);ea=u([B({type:S.Choice})],ea);var Eo=class{constructor(e={}){this.version=dt.v0,this.rid=new ea,this.keyEncryptionAlgorithm=new Ht,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:m.Integer})],Eo.prototype,"version",void 0);u([f({type:ea})],Eo.prototype,"rid",void 0);u([f({type:Ht})],Eo.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],Eo.prototype,"encryptedKey",void 0);var ji=class{constructor(e={}){this.keyIdentifier=new ie,Object.assign(this,e)}};u([f({type:ie})],ji.prototype,"keyIdentifier",void 0);u([f({type:m.GeneralizedTime,optional:!0})],ji.prototype,"date",void 0);u([f({type:So,optional:!0})],ji.prototype,"other",void 0);var _o=class{constructor(e={}){this.version=dt.v4,this.kekid=new ji,this.keyEncryptionAlgorithm=new Ht,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:m.Integer})],_o.prototype,"version",void 0);u([f({type:ji})],_o.prototype,"kekid",void 0);u([f({type:Ht})],_o.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],_o.prototype,"encryptedKey",void 0);var Co=class{constructor(e={}){this.version=dt.v0,this.keyEncryptionAlgorithm=new Ht,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:m.Integer})],Co.prototype,"version",void 0);u([f({type:Xf,context:0,optional:!0})],Co.prototype,"keyDerivationAlgorithm",void 0);u([f({type:Ht})],Co.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],Co.prototype,"encryptedKey",void 0);var uu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],uu.prototype,"oriType",void 0);u([f({type:m.Any})],uu.prototype,"oriValue",void 0);var Rn=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Eo,optional:!0})],Rn.prototype,"ktri",void 0);u([f({type:Dn,context:1,implicit:!0,optional:!0})],Rn.prototype,"kari",void 0);u([f({type:_o,context:2,implicit:!0,optional:!0})],Rn.prototype,"kekri",void 0);u([f({type:Co,context:3,implicit:!0,optional:!0})],Rn.prototype,"pwri",void 0);u([f({type:uu,context:4,implicit:!0,optional:!0})],Rn.prototype,"ori",void 0);Rn=u([B({type:S.Choice})],Rn);var py,lu=py=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};lu=py=u([B({type:S.Set,itemType:Rn})],lu);var hy,av=`${bo}.16`,cH=`${av}.2`,uH=`${av}.4`,ta=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],ta.prototype,"otherRevInfoFormat",void 0);u([f({type:m.Any})],ta.prototype,"otherRevInfo",void 0);var ep=class{constructor(e={}){this.other=new ta,Object.assign(this,e)}};u([f({type:ta,context:1,implicit:!0})],ep.prototype,"other",void 0);ep=u([B({type:S.Choice})],ep);var ra=hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};ra=hy=u([B({type:S.Set,itemType:ep})],ra);var na=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Li,context:0,implicit:!0,optional:!0})],na.prototype,"certs",void 0);u([f({type:ra,context:1,implicit:!0,optional:!0})],na.prototype,"crls",void 0);var dy,my=dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};my=dy=u([B({type:S.Set,itemType:Lr})],my);var Ki=class{constructor(e={}){this.version=dt.v0,this.recipientInfos=new lu,this.encryptedContentInfo=new Ao,Object.assign(this,e)}};u([f({type:m.Integer})],Ki.prototype,"version",void 0);u([f({type:na,context:0,implicit:!0,optional:!0})],Ki.prototype,"originatorInfo",void 0);u([f({type:lu})],Ki.prototype,"recipientInfos",void 0);u([f({type:Ao})],Ki.prototype,"encryptedContentInfo",void 0);u([f({type:my,context:1,implicit:!0,optional:!0})],Ki.prototype,"unprotectedAttrs",void 0);var cv="1.2.840.113549.1.7.2";var yy,tp=yy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};tp=yy=u([B({type:S.Set,itemType:ki})],tp);var Ln=class{constructor(e={}){this.version=dt.v0,this.digestAlgorithms=new tp,this.encapContentInfo=new Ui,this.signerInfos=new Jc,Object.assign(this,e)}};u([f({type:m.Integer})],Ln.prototype,"version",void 0);u([f({type:tp})],Ln.prototype,"digestAlgorithms",void 0);u([f({type:Ui})],Ln.prototype,"encapContentInfo",void 0);u([f({type:Li,context:0,implicit:!0,optional:!0})],Ln.prototype,"certificates",void 0);u([f({type:ra,context:1,implicit:!0,optional:!0})],Ln.prototype,"crls",void 0);u([f({type:Jc})],Ln.prototype,"signerInfos",void 0);var Hi="1.2.840.10045.2.1";var fu="1.2.840.10045.4.1",rp="1.2.840.10045.4.3.1",pu="1.2.840.10045.4.3.2",hu="1.2.840.10045.4.3.3",du="1.2.840.10045.4.3.4";var gy="1.2.840.10045.3.1.7";var by="1.3.132.0.34";var xy="1.3.132.0.35";function mu(r){return new M({algorithm:r})}var lv=mu(fu),iV=mu(rp),fv=mu(pu),pv=mu(hu),hv=mu(du);var yu=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],yu.prototype,"fieldType",void 0);u([f({type:m.Any})],yu.prototype,"parameters",void 0);yu=u([B({type:S.Sequence})],yu);var wy=class extends ie{};var oa=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.OctetString})],oa.prototype,"a",void 0);u([f({type:m.OctetString})],oa.prototype,"b",void 0);u([f({type:m.BitString,optional:!0})],oa.prototype,"seed",void 0);oa=u([B({type:S.Sequence})],oa);var vy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(vy||(vy={}));var Yr=class{constructor(e={}){this.version=vy.ecpVer1,Object.assign(this,e)}};u([f({type:m.Integer})],Yr.prototype,"version",void 0);u([f({type:yu})],Yr.prototype,"fieldID",void 0);u([f({type:oa})],Yr.prototype,"curve",void 0);u([f({type:wy})],Yr.prototype,"base",void 0);u([f({type:m.Integer,converter:ye})],Yr.prototype,"order",void 0);u([f({type:m.Integer,optional:!0})],Yr.prototype,"cofactor",void 0);Yr=u([B({type:S.Sequence})],Yr);var Jr=class{constructor(e={}){Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],Jr.prototype,"namedCurve",void 0);u([f({type:m.Null})],Jr.prototype,"implicitCurve",void 0);u([f({type:Yr})],Jr.prototype,"specifiedCurve",void 0);Jr=u([B({type:S.Choice})],Jr);var ia=class{constructor(e={}){this.version=1,this.privateKey=new ie,Object.assign(this,e)}};u([f({type:m.Integer})],ia.prototype,"version",void 0);u([f({type:ie})],ia.prototype,"privateKey",void 0);u([f({type:Jr,context:0,optional:!0})],ia.prototype,"parameters",void 0);u([f({type:m.BitString,context:1,optional:!0})],ia.prototype,"publicKey",void 0);var Vi=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.Integer,converter:ye})],Vi.prototype,"r",void 0);u([f({type:m.Integer,converter:ye})],Vi.prototype,"s",void 0);var Ft="1.2.840.113549.1.1",Qr=`${Ft}.1`,dv=`${Ft}.7`,mv=`${Ft}.9`,Bo=`${Ft}.10`,yv=`${Ft}.2`,gv=`${Ft}.4`,sa=`${Ft}.5`,bv=`${Ft}.14`;var np=`${Ft}.11`,aa=`${Ft}.12`,ca=`${Ft}.13`,Ay=`${Ft}.15`,Sy=`${Ft}.16`,$i="1.3.14.3.2.26",op="2.16.840.1.101.3.4.2.4",Fi="2.16.840.1.101.3.4.2.1",Wi="2.16.840.1.101.3.4.2.2",qi="2.16.840.1.101.3.4.2.3",xv="2.16.840.1.101.3.4.2.5",wv="2.16.840.1.101.3.4.2.6",vv="1.2.840.113549.2.2",Av="1.2.840.113549.2.5",Io=`${Ft}.8`;function nt(r){return new M({algorithm:r,parameters:null})}var NV=nt(vv),DV=nt(Av),Un=nt($i),RV=nt(op),LV=nt(Fi),UV=nt(Wi),MV=nt(qi),jV=nt(xv),KV=nt(wv),ip=new M({algorithm:Io,parameters:F.serialize(Un)}),Ey=new M({algorithm:mv,parameters:F.serialize(Hs.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),HV=nt(Qr),VV=nt(yv),$V=nt(gv),FV=nt(sa),WV=nt(Ay),qV=nt(Sy),GV=nt(aa),zV=nt(ca),XV=nt(Ay),ZV=nt(Sy);var ua=class{constructor(e={}){this.hashAlgorithm=new M(Un),this.maskGenAlgorithm=new M({algorithm:Io,parameters:F.serialize(Un)}),this.pSourceAlgorithm=new M(Ey),Object.assign(this,e)}};u([f({type:M,context:0,defaultValue:Un})],ua.prototype,"hashAlgorithm",void 0);u([f({type:M,context:1,defaultValue:ip})],ua.prototype,"maskGenAlgorithm",void 0);u([f({type:M,context:2,defaultValue:Ey})],ua.prototype,"pSourceAlgorithm",void 0);var n7=new M({algorithm:dv,parameters:F.serialize(new ua)});var en=class{constructor(e={}){this.hashAlgorithm=new M(Un),this.maskGenAlgorithm=new M({algorithm:Io,parameters:F.serialize(Un)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};u([f({type:M,context:0,defaultValue:Un})],en.prototype,"hashAlgorithm",void 0);u([f({type:M,context:1,defaultValue:ip})],en.prototype,"maskGenAlgorithm",void 0);u([f({type:m.Integer,context:2,defaultValue:20})],en.prototype,"saltLength",void 0);u([f({type:m.Integer,context:3,defaultValue:1})],en.prototype,"trailerField",void 0);var l7=new M({algorithm:Bo,parameters:F.serialize(new en)});var Gi=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ie,Object.assign(this,e)}};u([f({type:M})],Gi.prototype,"digestAlgorithm",void 0);u([f({type:ie})],Gi.prototype,"digest",void 0);var _y,la=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.Integer,converter:ye})],la.prototype,"prime",void 0);u([f({type:m.Integer,converter:ye})],la.prototype,"exponent",void 0);u([f({type:m.Integer,converter:ye})],la.prototype,"coefficient",void 0);var sp=_y=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,_y.prototype)}};sp=_y=u([B({type:S.Sequence,itemType:la})],sp);var yr=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([f({type:m.Integer})],yr.prototype,"version",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"modulus",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"publicExponent",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"privateExponent",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"prime1",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"prime2",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"exponent1",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"exponent2",void 0);u([f({type:m.Integer,converter:ye})],yr.prototype,"coefficient",void 0);u([f({type:sp,optional:!0})],yr.prototype,"otherPrimeInfos",void 0);var fa=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.Integer,converter:ye})],fa.prototype,"modulus",void 0);u([f({type:m.Integer,converter:ye})],fa.prototype,"publicExponent",void 0);var Cy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Cy||(Cy={}));var mt=Cy;var Fv=Mr($v(),1),{__extends:ha,__assign:H7,__rest:eB,__decorate:V7,__param:$7,__metadata:F7,__awaiter:Wv,__generator:qv,__exportStar:W7,__createBinding:q7,__values:gu,__read:bu,__spread:Ur,__spreadArrays:G7,__await:z7,__asyncGenerator:X7,__asyncDelegator:Z7,__asyncValues:Y7,__makeTemplateObject:J7,__importStar:Q7,__importDefault:e$,__classPrivateFieldGet:t$,__classPrivateFieldSet:r$}=Fv.default;var tB="injectionTokens";function Iy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(tB,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function xu(r){return!!r.useClass}function da(r){return!!r.useFactory}var up=(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,Ur(i))}};return this.reflectMethods.forEach(n),t},r})();function To(r){return typeof r=="string"||typeof r=="symbol"}function Ty(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function lp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function Gv(r){return typeof r=="function"||r instanceof up}function zi(r){return!!r.useToken}function Xi(r){return r.useValue!=null}function zv(r){return xu(r)||Xi(r)||zi(r)||da(r)}var rB=(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})(),wu=rB;var nB=(function(r){ha(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(wu),Xv=nB;var oB=(function(){function r(){this.scopedResolutions=new Map}return r})(),vu=oB;function iB(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function sB(r,e,t){return t===void 0&&(t=" "),Ur([r],e.message.split(`
|
6
|
+
`)}`:`${t} :`}};Rx=tt;Z.Constructed=Rx;tt.NAME="CONSTRUCTED";var qf=class extends ht{fromBER(e,t,n){return t}toBER(e){return Dr}};qf.override="EndOfContentValueBlock";var Lx,Nc=class extends et{constructor(e={}){super(e,qf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Lx=Nc;Z.EndOfContent=Lx;Nc.NAME=Pc;var Ux,Pr=class extends et{constructor(e={}){super(e,ht),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ux=Pr;Z.Null=Ux;Pr.NAME="NULL";var Gf=class extends zr(ht){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=de.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);return kn(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,Km.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Gf.NAME="BooleanValueBlock";var Mx,fi=class extends et{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Gf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Mx=fi;Z.Boolean=Mx;fi.NAME="BOOLEAN";var zf=class extends zr(qr){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=qr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===Pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Px)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?qr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};zf.NAME="OctetStringValueBlock";var Fm,Or=class extends et{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},zf),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=Fs(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 tt.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=de.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof Fm&&e.push(t.valueBlock.valueHexView);return de.BufferSourceConverter.concat(e)}};Fm=Or;Z.OctetString=Fm;Or.NAME=Px;var Xf=class extends zr(qr){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=qr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Ox)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return o}let i=de.BufferSourceConverter.toUint8Array(e);if(!kn(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=Fs(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 qr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Dr;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}}};Xf.NAME="BitStringValueBlock";var jx,Nr=class extends et{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},Xf),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 tt.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}`}}};jx=Nr;Z.BitString=jx;Nr.NAME=Ox;var Kx;function nI(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,l=0,h=c<s?s:c,p=0;for(let m=h;m>=0;m--,p++){switch(!0){case p<a.length:l=i[s-p]+a[c-p]+t[0];break;default:l=i[s-p]+t[0]}switch(t[0]=l/10,!0){case p>=i.length:i=Hf(new Uint8Array([l%10]),i);break;default:i[s-p]=l%10}}return t[0]>0&&(i=Hf(t,i)),i}function kx(r){if(r>=Bc.length)for(let e=Bc.length;e<=r;e++){let t=new Uint8Array([0]),n=Bc[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=Hf(t,n)),Bc.push(n)}return Bc[r]}function oI(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,l,h=0;for(let p=c;p>=0;p--,h++)switch(l=i[s-h]-a[c-h]-t,!0){case l<0:t=1,i[s-h]=l+10;break;default:t=0,i[s-h]=l}if(t>0)for(let p=s-c+1;p>=0;p--,h++)if(l=i[s-h]-t,l<0)t=1,i[s-h]=l+10;else{t=0,i[s-h]=l;break}return i.slice()}var Dc=class extends zr(ht){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Km.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(Cx(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let l=0;l<8;l++){if((o&1)===1)switch(n){case e:t=oI(kx(n),t),s="-";break;default:t=nI(t,kx(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Tx.charAt(t[c]));return a===!1&&(s+=Tx.charAt(0)),s}};Kx=Dc;Dc.NAME="IntegerValueBlock";Object.defineProperty(Kx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var kc,Bn=class extends et{constructor(e={}){super(e,Dc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Vf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Vf();let t=BigInt(e),n=new Vs,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(de.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${de.Convert.ToHex(a)}`)+t,h=de.BufferSourceConverter.toUint8Array(de.Convert.FromHex(l.toString(16)));h[0]|=128,n.write(h)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new kc({valueHex:n.final()})}convertToDER(){let e=new kc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new kc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};kc=Bn;Z.Integer=kc;Bn.NAME="INTEGER";var Hx,pi=class extends Bn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Hx=pi;Z.Enumerated=Hx;pi.NAME="ENUMERATED";var Rc=class extends zr(ht){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=de.BufferSourceConverter.toUint8Array(e);if(!kn(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=li(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Vf();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=po(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Dr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=de.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Rc.NAME="sidBlock";var Zf=class extends ht{constructor({value:e=Ht,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Rc;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,Dr;t.push(o)}return $m(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 Rc;if(o>Number.MAX_SAFE_INTEGER){Vf();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}};Zf.NAME="ObjectIdentifierValueBlock";var Vx,hi=class extends et{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Zf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Vx=hi;Z.ObjectIdentifier=Vx;hi.NAME="OBJECT IDENTIFIER";var Lc=class extends zr(In){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=de.BufferSourceConverter.toUint8Array(e);if(!kn(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=li(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=po(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Dr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=de.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Lc.NAME="relativeSidBlock";var Yf=class extends ht{constructor({value:e=Ht,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Lc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.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,Dr;n.push(i)}return $m(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 Lc;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}};Yf.NAME="RelativeObjectIdentifierValueBlock";var $x,Uc=class extends et{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Yf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};$x=Uc;Z.RelativeObjectIdentifier=$x;Uc.NAME="RelativeObjectIdentifier";var Fx,It=class extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Fx=It;Z.Sequence=Fx;It.NAME="SEQUENCE";var Wx,Dt=class extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Wx=Dt;Z.Set=Wx;Dt.NAME="SET";var Jf=class extends zr(ht){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Ht}toJSON(){return{...super.toJSON(),value:this.value}}};Jf.NAME="StringValueBlock";var Qf=class extends Jf{};Qf.NAME="SimpleStringValueBlock";var Rt=class extends Oc{constructor({...e}={}){super(e,Qf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,de.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Rt.NAME="SIMPLE STRING";var ep=class extends Rt{fromBuffer(e){this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=de.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=de.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf8String(e)),this.valueBlock.value=e}};ep.NAME="Utf8StringValueBlock";var qx,pr=class extends ep{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};qx=pr;Z.Utf8String=qx;pr.NAME="UTF8String";var tp=class extends Rt{fromBuffer(e){this.valueBlock.value=de.Convert.ToUtf16String(e),this.valueBlock.valueHexView=de.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(de.Convert.FromUtf16String(e))}};tp.NAME="BmpStringValueBlock";var Gx,di=class extends tp{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Gx=di;Z.BmpString=Gx;di.NAME="BMPString";var rp=class extends Rt{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=po(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}};rp.NAME="UniversalStringValueBlock";var zx,mi=class extends rp{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};zx=mi;Z.UniversalString=zx;mi.NAME="UniversalString";var Xx,yi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Xx=yi;Z.NumericString=Xx;yi.NAME="NumericString";var Zx,gi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Zx=gi;Z.PrintableString=Zx;gi.NAME="PrintableString";var Yx,bi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Yx=bi;Z.TeletexString=Yx;bi.NAME="TeletexString";var Jx,wi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Jx=wi;Z.VideotexString=Jx;wi.NAME="VideotexString";var Qx,xi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Qx=xi;Z.IA5String=Qx;xi.NAME="IA5String";var ev,vi=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};ev=vi;Z.GraphicString=ev;vi.NAME="GraphicString";var tv,ho=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};tv=ho;Z.VisibleString=tv;ho.NAME="VisibleString";var rv,Ai=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};rv=Ai;Z.GeneralString=rv;Ai.NAME="GeneralString";var nv,Si=class extends Rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};nv=Si;Z.CharacterString=nv;Si.NAME="CharacterString";var ov,mo=class extends ho{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,de.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Kt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Kt(this.month,2),t[2]=Kt(this.day,2),t[3]=Kt(this.hour,2),t[4]=Kt(this.minute,2),t[5]=Kt(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}}};ov=mo;Z.UTCTime=ov;mo.NAME="UTCTime";var iv,Ei=class extends mo{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let p=new Number(e[e.length-1]);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let p=1,m=n.indexOf("+"),y="";if(m===-1&&(m=n.indexOf("-"),p=-1),m!==-1){if(y=n.substring(m+1),n=n.substring(0,m),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(y.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*g,y.length===4){if(g=parseInt(y.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=p*g}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let p=new Number(`0${n.substring(l)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,l)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=60*i;this.minute=Math.floor(p),p=60*(p-this.minute),this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=60*i;this.second=Math.floor(p),p=1e3*(p-this.second),this.millisecond=Math.floor(p)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let p=1e3*i;this.millisecond=Math.floor(p)}break;default:throw new Error("Wrong input string for conversion")}let h=s.exec(o);if(h===null)throw new Error("Wrong input string for conversion");for(let p=1;p<h.length;p++)switch(p){case 1:this.year=parseInt(h[p],10);break;case 2:this.month=parseInt(h[p],10);break;case 3:this.day=parseInt(h[p],10);break;case 4:this.hour=parseInt(h[p],10)+a;break;case 5:this.minute=parseInt(h[p],10)+c;break;case 6:this.second=parseInt(h[p],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let p=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=p.getUTCFullYear(),this.month=p.getUTCMonth(),this.day=p.getUTCDay(),this.hour=p.getUTCHours(),this.minute=p.getUTCMinutes(),this.second=p.getUTCSeconds(),this.millisecond=p.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Kt(this.year,4)),t.push(Kt(this.month,2)),t.push(Kt(this.day,2)),t.push(Kt(this.hour,2)),t.push(Kt(this.minute,2)),t.push(Kt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Kt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};iv=Ei;Z.GeneralizedTime=iv;Ei.NAME="GeneralizedTime";var sv,Mc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};sv=Mc;Z.DATE=sv;Mc.NAME="DATE";var av,jc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};av=jc;Z.TimeOfDay=av;jc.NAME="TimeOfDay";var cv,Kc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};cv=Kc;Z.DateTime=cv;Kc.NAME="DateTime";var uv,Hc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};uv=Hc;Z.Duration=uv;Hc.NAME="Duration";var lv,Vc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};lv=Vc;Z.TIME=lv;Vc.NAME="TIME";var Gr=class{constructor({name:e=Ht,optional:t=!1}={}){this.name=e,this.optional=t}},$s=class extends Gr{constructor({value:e=[],...t}={}){super(t),this.value=e}},_i=class extends Gr{constructor({value:e=new Gr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Vm=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=de.BufferSourceConverter.toUint8Array(e)}constructor({data:e=np}={}){this.dataView=de.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=de.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function Cn(r,e,t){if(t instanceof $s){for(let i of t.value)if(Cn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Hm)&&(i.name=t.name),i}}if(t instanceof Gr)return t.hasOwnProperty(Hm)&&(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(!(zC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(JC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(QC 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(XC)===!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(ZC)===!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(YC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(GC 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(!(Bx 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,Ht),t.name&&(r[t.name]=e)),t instanceof Z.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof _i&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let l=0;l<t.valueBlock.value.length;l++)c=c&&(t.valueBlock.value[l].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Ht),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){let l={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Ht),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof _i){if(s=Cn(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,Ht),t.name&&delete r[t.name]),s;if(Hm in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};eI in t.valueBlock.value[0]&&t.valueBlock.value[0].local?l=e:l=r,typeof l[t.valueBlock.value[0].name]>"u"&&(l[t.valueBlock.value[0].name]=[]),l[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=Cn(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,Ht),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,Ht),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Bx in e.valueBlock){let i=Fs(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,Ht),t.name&&(delete r[t.name],s.name=t.name)),s}return Cn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function iI(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Fs(de.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:Cn(t.result,t.result,e)}var S;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(S||(S={}));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 Wm=Hr(_n()),Zr=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Wm.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Wm.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Nr))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 Nr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Nr({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 qm=Hr(_n()),ie=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):qm.BufferSourceConverter.isBufferSource(e)?this.buffer=qm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Or))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Or({valueHex:this.buffer})}toSchema(e){return new Or({name:e})}};var sI={fromASN:r=>r instanceof Pr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Pr;let e=Pn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},aI={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Bn({value:+r})},cI={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new pi({value:r})},ye={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Bn({valueHex:r})};var uI={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Nr({valueHex:r})},lI={fromASN:r=>r.valueBlock.toString(),toASN:r=>new hi({value:r})},fI={fromASN:r=>r.valueBlock.value,toASN:r=>new fi({value:r})},Ws={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Or({valueHex:r})},fv={fromASN:r=>new ie(r.getValue()),toASN:r=>r.toASN()};function hr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Gm=hr(pr),pI=hr(di),hI=hr(mi),dI=hr(yi),mI=hr(gi),yI=hr(bi),gI=hr(wi),bI=hr(xi),wI=hr(vi),xI=hr(ho),vI=hr(Ai),AI=hr(Si),SI={fromASN:r=>r.toDate(),toASN:r=>new mo({valueDate:r})},EI={fromASN:r=>r.toDate(),toASN:r=>new Ei({valueDate:r})},_I={fromASN:()=>null,toASN:()=>new Pr};function yo(r){switch(r){case d.Any:return sI;case d.BitString:return uI;case d.BmpString:return pI;case d.Boolean:return fI;case d.CharacterString:return AI;case d.Enumerated:return cI;case d.GeneralString:return vI;case d.GeneralizedTime:return EI;case d.GraphicString:return wI;case d.IA5String:return bI;case d.Integer:return aI;case d.Null:return _I;case d.NumericString:return dI;case d.ObjectIdentifier:return lI;case d.OctetString:return Ws;case d.PrintableString:return mI;case d.TeletexString:return yI;case d.UTCTime:return SI;case d.UniversalString:return hI;case d.Utf8String:return Gm;case d.VideotexString:return gI;case d.VisibleString:return xI;default:return null}}function dr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:dr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Xm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Xm(t)}return!1}function pv(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 op=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:S.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let h=d[s.type],p=Xr[h];if(!p)throw new Error(`Cannot get ASN1 class by name '${h}'`);c=new p({name:a})}else dr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===S.Choice?c=new Gr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Gr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let h=s.repeated==="set"?Dt:It;c=new h({name:"",value:[new _i({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||dr(s.type)){let h=s.repeated?tt:Tn;o.push(new h({name:a,optional:l,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let h=!!s.repeated,p=h?c:this.get(s.type,!0).schema;p="valueBlock"in p?p.valueBlock.value:p.value,o.push(new tt({name:h?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new tt({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case S.Sequence:return new It({value:o,name:""});case S.Set:return new Dt({value:o,name:""});case S.Choice:return new $s({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 op;var I=r=>e=>{let t;qe.has(e)?t=qe.get(e):(t=qe.createDefault(e),qe.set(e,t)),Object.assign(t,r)};var f=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=yo(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 go=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var $c=class{static parse(e,t){let n=Pn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(dr(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 Xm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof go&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===tt&&t.type===S.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===S.Sequence){let c=new It;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let l=this.fromASN(c,s.type),h=new n;return h[i]=l,{result:h}}}}}else if(e.constructor===tt&&t.type!==S.Choice){let i=new tt({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===S.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===S.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=Cn({},e,o);if(!s.verified)throw new go(`Data does not match to ${n.name} ASN1 schema.${s.result.error?` ${s.result.error}`:""}`);return s}else{let i=Cn({},e,o);if(!i.verified)throw new go(`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 l=s[c],h=t.items[l];if(a>=i.length)break;if(h.repeated){o[l]=this.processRepeatedField(i,a,h);break}else if(typeof h.type=="number")o[l]=this.processPrimitiveField(i[a],h),a++;else if(this.isOptionalChoiceField(h)){let p=this.processOptionalChoiceField(i[a],h);p.processed&&(o[l]=p.value,a++)}else o[l]=this.fromASN(i[a],h.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=yo(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=yo(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===S.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof go&&/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=yo(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"||dr(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:dr(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"?It:Dt,i=new o;i.valueBlock=e.valueBlock;let s=Pn(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(dr(n))s=new n().toSchema("");else{let a=d[n],c=Xr[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Pn(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 go&&/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===S.Sequence){let i=new It;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===S.Set){let i=new Dt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var Fc=class r{static serialize(e){return e instanceof et?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&dr(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=yo(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"&&pv(this.serialize(a.defaultValue),this.serialize(c)))continue;let l=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||dr(a.type))){let h={};h.valueHex=l instanceof Pr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new Tn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...h}))}else o.push(new tt({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new tt({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else a.repeated?o=o.concat(l):o.push(l)}let i;switch(n.type){case S.Sequence:i=new It({value:o});break;case S.Set:i=new Dt({value:o});break;case S.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,l=>s.toASN(l)),c=e.repeated==="sequence"?It:Dt;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"?It:Dt;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 Zm=Hr(_n());var F=class r{static serialize(e){return Fc.serialize(e)}static parse(e,t){return $c.parse(e,t)}static toString(e){let t=Zm.BufferSourceConverter.isBufferSource(e)?Zm.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Pn(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 je(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 hv=Hr(_n()),Wc=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,l)=>c+(l.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(hv.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 dv=Hr(_n()),Ym,Jm,Qm,rt=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};u([f({type:d.TeletexString})],rt.prototype,"teletexString",void 0);u([f({type:d.PrintableString})],rt.prototype,"printableString",void 0);u([f({type:d.UniversalString})],rt.prototype,"universalString",void 0);u([f({type:d.Utf8String})],rt.prototype,"utf8String",void 0);u([f({type:d.BmpString})],rt.prototype,"bmpString",void 0);rt=u([I({type:S.Choice})],rt);var qs=class extends rt{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?dv.Convert.ToHex(this.anyValue):super.toString())}};u([f({type:d.IA5String})],qs.prototype,"ia5String",void 0);u([f({type:d.Any})],qs.prototype,"anyValue",void 0);qs=u([I({type:S.Choice})],qs);var Ci=class{constructor(e={}){this.type="",this.value=new qs,Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Ci.prototype,"type",void 0);u([f({type:qs})],Ci.prototype,"value",void 0);var bo=Ym=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ym.prototype)}};bo=Ym=u([I({type:S.Set,itemType:Ci})],bo);var ey=Jm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Jm.prototype)}};ey=Jm=u([I({type:S.Sequence,itemType:bo})],ey);var Pe=Qm=class extends ey{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};Pe=Qm=u([I({type:S.Sequence})],Pe);var CI={fromASN:r=>Wc.toString(Ws.fromASN(r)),toASN:r=>Ws.toASN(Wc.fromString(r))},wo=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],wo.prototype,"typeId",void 0);u([f({type:d.Any,context:0})],wo.prototype,"value",void 0);var qc=class{constructor(e={}){this.partyName=new rt,Object.assign(this,e)}};u([f({type:rt,optional:!0,context:0,implicit:!0})],qc.prototype,"nameAssigner",void 0);u([f({type:rt,context:1,implicit:!0})],qc.prototype,"partyName",void 0);var ae=class{constructor(e={}){Object.assign(this,e)}};u([f({type:wo,context:0,implicit:!0})],ae.prototype,"otherName",void 0);u([f({type:d.IA5String,context:1,implicit:!0})],ae.prototype,"rfc822Name",void 0);u([f({type:d.IA5String,context:2,implicit:!0})],ae.prototype,"dNSName",void 0);u([f({type:d.Any,context:3,implicit:!0})],ae.prototype,"x400Address",void 0);u([f({type:Pe,context:4,implicit:!1})],ae.prototype,"directoryName",void 0);u([f({type:qc,context:5})],ae.prototype,"ediPartyName",void 0);u([f({type:d.IA5String,context:6,implicit:!0})],ae.prototype,"uniformResourceIdentifier",void 0);u([f({type:d.OctetString,context:7,implicit:!0,converter:CI})],ae.prototype,"iPAddress",void 0);u([f({type:d.ObjectIdentifier,context:8,implicit:!0})],ae.prototype,"registeredID",void 0);ae=u([I({type:S.Choice})],ae);var xo="1.3.6.1.5.5.7",vo=`${xo}.1`,mv=`${xo}.2`,Ii=`${xo}.3`,ip=`${xo}.48`,eR=`${mv}.1`,tR=`${mv}.2`,ty=`${ip}.1`,ry=`${ip}.2`,ny=`${ip}.3`,oy=`${ip}.5`,le="2.5.29";var iy,sp=`${vo}.1`,On=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ae,Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],On.prototype,"accessMethod",void 0);u([f({type:ae})],On.prototype,"accessLocation",void 0);var Ti=iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,iy.prototype)}};Ti=iy=u([I({type:S.Sequence,itemType:On})],Ti);var ap=`${le}.35`,Bi=class extends ie{},Yr=class{constructor(e={}){e&&Object.assign(this,e)}};u([f({type:Bi,context:0,optional:!0,implicit:!0})],Yr.prototype,"keyIdentifier",void 0);u([f({type:ae,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Yr.prototype,"authorityCertIssuer",void 0);u([f({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ye})],Yr.prototype,"authorityCertSerialNumber",void 0);var cp=`${le}.19`,ki=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};u([f({type:d.Boolean,defaultValue:!1})],ki.prototype,"cA",void 0);u([f({type:d.Integer,optional:!0})],ki.prototype,"pathLenConstraint",void 0);var sy,Ke=sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,sy.prototype)}};Ke=sy=u([I({type:S.Sequence,itemType:ae})],Ke);var ay,II=`${le}.29`,yv=ay=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,ay.prototype)}};yv=ay=u([I({type:S.Sequence})],yv);var cy,lp=`${le}.32`,NR=`${lp}.0`,Nn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};u([f({type:d.IA5String})],Nn.prototype,"ia5String",void 0);u([f({type:d.VisibleString})],Nn.prototype,"visibleString",void 0);u([f({type:d.BmpString})],Nn.prototype,"bmpString",void 0);u([f({type:d.Utf8String})],Nn.prototype,"utf8String",void 0);Nn=u([I({type:S.Choice})],Nn);var Gc=class{constructor(e={}){this.organization=new Nn,this.noticeNumbers=[],Object.assign(this,e)}};u([f({type:Nn})],Gc.prototype,"organization",void 0);u([f({type:d.Integer,repeated:"sequence"})],Gc.prototype,"noticeNumbers",void 0);var zc=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Gc,optional:!0})],zc.prototype,"noticeRef",void 0);u([f({type:Nn,optional:!0})],zc.prototype,"explicitText",void 0);var up=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.IA5String})],up.prototype,"cPSuri",void 0);u([f({type:zc})],up.prototype,"userNotice",void 0);up=u([I({type:S.Choice})],up);var Xc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Xc.prototype,"policyQualifierId",void 0);u([f({type:d.Any})],Xc.prototype,"qualifier",void 0);var Pi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Pi.prototype,"policyIdentifier",void 0);u([f({type:Xc,repeated:"sequence",optional:!0})],Pi.prototype,"policyQualifiers",void 0);var Zc=cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,cy.prototype)}};Zc=cy=u([I({type:S.Sequence,itemType:Pi})],Zc);var HR=`${le}.20`,Yc=class{constructor(e=0){this.value=e}};u([f({type:d.Integer})],Yc.prototype,"value",void 0);Yc=u([I({type:S.Choice})],Yc);var zR=`${le}.27`,gv=class extends Yc{};gv=u([I({type:S.Choice})],gv);var uy,fp=`${le}.31`,Rr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Rr||(Rr={}));var Jc=class extends Zr{toJSON(){let e=[],t=this.toNumber();return t&Rr.aACompromise&&e.push("aACompromise"),t&Rr.affiliationChanged&&e.push("affiliationChanged"),t&Rr.cACompromise&&e.push("cACompromise"),t&Rr.certificateHold&&e.push("certificateHold"),t&Rr.cessationOfOperation&&e.push("cessationOfOperation"),t&Rr.keyCompromise&&e.push("keyCompromise"),t&Rr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Rr.superseded&&e.push("superseded"),t&Rr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Dn=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,context:0,repeated:"sequence",implicit:!0})],Dn.prototype,"fullName",void 0);u([f({type:bo,context:1,implicit:!0})],Dn.prototype,"nameRelativeToCRLIssuer",void 0);Dn=u([I({type:S.Choice})],Dn);var Jr=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Dn,context:0,optional:!0})],Jr.prototype,"distributionPoint",void 0);u([f({type:Jc,context:1,optional:!0,implicit:!0})],Jr.prototype,"reasons",void 0);u([f({type:ae,context:2,optional:!0,repeated:"sequence",implicit:!0})],Jr.prototype,"cRLIssuer",void 0);var Ao=uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};Ao=uy=u([I({type:S.Sequence,itemType:Jr})],Ao);var ly,uL=`${le}.46`,bv=ly=class extends Ao{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};bv=ly=u([I({type:S.Sequence,itemType:Jr})],bv);var gL=`${le}.28`,er=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};er.ONLY=!1;u([f({type:Dn,context:0,optional:!0})],er.prototype,"distributionPoint",void 0);u([f({type:d.Boolean,context:1,defaultValue:er.ONLY,implicit:!0})],er.prototype,"onlyContainsUserCerts",void 0);u([f({type:d.Boolean,context:2,defaultValue:er.ONLY,implicit:!0})],er.prototype,"onlyContainsCACerts",void 0);u([f({type:Jc,context:3,optional:!0,implicit:!0})],er.prototype,"onlySomeReasons",void 0);u([f({type:d.Boolean,context:4,defaultValue:er.ONLY,implicit:!0})],er.prototype,"indirectCRL",void 0);u([f({type:d.Boolean,context:5,defaultValue:er.ONLY,implicit:!0})],er.prototype,"onlyContainsAttributeCerts",void 0);var wv=`${le}.21`,Qc;(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"})(Qc||(Qc={}));var eu=class{constructor(e=Qc.unspecified){this.reason=Qc.unspecified,this.reason=e}toJSON(){return Qc[this.reason]}toString(){return this.toJSON()}};u([f({type:d.Enumerated})],eu.prototype,"reason",void 0);eu=u([I({type:S.Choice})],eu);var fy,pp=`${le}.37`,tu=fy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};tu=fy=u([I({type:S.Sequence,itemType:d.ObjectIdentifier})],tu);var TL=`${pp}.0`,xv=`${Ii}.1`,vv=`${Ii}.2`,Av=`${Ii}.3`,Sv=`${Ii}.4`,Ev=`${Ii}.8`,_v=`${Ii}.9`;var NL=`${le}.54`,py=class{constructor(e=new ArrayBuffer(0)){this.value=e}};u([f({type:d.Integer,converter:ye})],py.prototype,"value",void 0);py=u([I({type:S.Choice})],py);var Cv=`${le}.24`,ru=class{constructor(e){this.value=new Date,e&&(this.value=e)}};u([f({type:d.GeneralizedTime})],ru.prototype,"value",void 0);ru=u([I({type:S.Choice})],ru);var hy,dy=`${le}.18`,Iv=hy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};Iv=hy=u([I({type:S.Sequence})],Iv);var hp=`${le}.15`,Lr;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(Lr||(Lr={}));var Gs=class extends Zr{toJSON(){let e=this.toNumber(),t=[];return e&Lr.cRLSign&&t.push("crlSign"),e&Lr.dataEncipherment&&t.push("dataEncipherment"),e&Lr.decipherOnly&&t.push("decipherOnly"),e&Lr.digitalSignature&&t.push("digitalSignature"),e&Lr.encipherOnly&&t.push("encipherOnly"),e&Lr.keyAgreement&&t.push("keyAgreement"),e&Lr.keyCertSign&&t.push("keyCertSign"),e&Lr.keyEncipherment&&t.push("keyEncipherment"),e&Lr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var my,eU=`${le}.30`,zs=class{constructor(e={}){this.base=new ae,this.minimum=0,Object.assign(this,e)}};u([f({type:ae})],zs.prototype,"base",void 0);u([f({type:d.Integer,context:0,defaultValue:0,implicit:!0})],zs.prototype,"minimum",void 0);u([f({type:d.Integer,context:1,optional:!0,implicit:!0})],zs.prototype,"maximum",void 0);var dp=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};dp=my=u([I({type:S.Sequence,itemType:zs})],dp);var mp=class{constructor(e={}){Object.assign(this,e)}};u([f({type:dp,context:0,optional:!0,implicit:!0})],mp.prototype,"permittedSubtrees",void 0);u([f({type:dp,context:1,optional:!0,implicit:!0})],mp.prototype,"excludedSubtrees",void 0);var sU=`${le}.36`,yp=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ye})],yp.prototype,"requireExplicitPolicy",void 0);u([f({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ye})],yp.prototype,"inhibitPolicyMapping",void 0);var yy,fU=`${le}.33`,nu=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],nu.prototype,"issuerDomainPolicy",void 0);u([f({type:d.ObjectIdentifier})],nu.prototype,"subjectDomainPolicy",void 0);var Tv=yy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};Tv=yy=u([I({type:S.Sequence,itemType:nu})],Tv);var gy,by=`${le}.17`,gp=gy=class extends Ke{constructor(e){super(e),Object.setPrototypeOf(this,gy.prototype)}};gp=gy=u([I({type:S.Sequence})],gp);var dt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],dt.prototype,"type",void 0);u([f({type:d.Any,repeated:"set"})],dt.prototype,"values",void 0);var wy,IU=`${le}.9`,Bv=wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Bv=wy=u([I({type:S.Sequence,itemType:dt})],Bv);var xy=`${le}.14`,Vt=class extends Bi{};var LU=`${le}.16`,bp=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],bp.prototype,"notBefore",void 0);u([f({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],bp.prototype,"notAfter",void 0);var ou;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(ou||(ou={}));var wp=class extends Zr{toJSON(){let e=[],t=this.toNumber();return t&ou.pKIXCertificate&&e.push("pKIXCertificate"),t&ou.newExtensions&&e.push("newExtensions"),t&ou.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},xp=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new wp,Object.assign(this,e)}};u([f({type:d.GeneralString})],xp.prototype,"entrustVers",void 0);u([f({type:wp})],xp.prototype,"entrustInfoFlags",void 0);var vy,WU=`${vo}.11`,kv=vy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,vy.prototype)}};kv=vy=u([I({type:S.Sequence,itemType:On})],kv);var Pv=Hr(_n()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&Pv.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};u([f({type:d.ObjectIdentifier})],M.prototype,"algorithm",void 0);u([f({type:d.Any,optional:!0})],M.prototype,"parameters",void 0);var mt=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:M})],mt.prototype,"algorithm",void 0);u([f({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([f({type:d.UTCTime})],Ge.prototype,"utcTime",void 0);u([f({type:d.GeneralizedTime})],Ge.prototype,"generalTime",void 0);Ge=u([I({type:S.Choice})],Ge);var Rn=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([f({type:Ge})],Rn.prototype,"notBefore",void 0);u([f({type:Ge})],Rn.prototype,"notAfter",void 0);var Ay,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ie,Object.assign(this,e)}};yt.CRITICAL=!1;u([f({type:d.ObjectIdentifier})],yt.prototype,"extnID",void 0);u([f({type:d.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);u([f({type:ie})],yt.prototype,"extnValue",void 0);var tr=Ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};tr=Ay=u([I({type:S.Sequence,itemType:yt})],tr);var Qr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(Qr||(Qr={}));var gt=class{constructor(e={}){this.version=Qr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new Pe,this.validity=new Rn,this.subject=new Pe,this.subjectPublicKeyInfo=new mt,Object.assign(this,e)}};u([f({type:d.Integer,context:0,defaultValue:Qr.v1})],gt.prototype,"version",void 0);u([f({type:d.Integer,converter:ye})],gt.prototype,"serialNumber",void 0);u([f({type:M})],gt.prototype,"signature",void 0);u([f({type:Pe})],gt.prototype,"issuer",void 0);u([f({type:Rn})],gt.prototype,"validity",void 0);u([f({type:Pe})],gt.prototype,"subject",void 0);u([f({type:mt})],gt.prototype,"subjectPublicKeyInfo",void 0);u([f({type:d.BitString,context:1,implicit:!0,optional:!0})],gt.prototype,"issuerUniqueID",void 0);u([f({type:d.BitString,context:2,implicit:!0,optional:!0})],gt.prototype,"subjectUniqueID",void 0);u([f({type:tr,context:3,optional:!0})],gt.prototype,"extensions",void 0);var mr=class{constructor(e={}){this.tbsCertificate=new gt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:gt,raw:!0})],mr.prototype,"tbsCertificate",void 0);u([f({type:M})],mr.prototype,"signatureAlgorithm",void 0);u([f({type:d.BitString})],mr.prototype,"signatureValue",void 0);var Oi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ge,Object.assign(this,e)}};u([f({type:d.Integer,converter:ye})],Oi.prototype,"userCertificate",void 0);u([f({type:Ge})],Oi.prototype,"revocationDate",void 0);u([f({type:yt,optional:!0,repeated:"sequence"})],Oi.prototype,"crlEntryExtensions",void 0);var rr=class{constructor(e={}){this.signature=new M,this.issuer=new Pe,this.thisUpdate=new Ge,Object.assign(this,e)}};u([f({type:d.Integer,optional:!0})],rr.prototype,"version",void 0);u([f({type:M})],rr.prototype,"signature",void 0);u([f({type:Pe})],rr.prototype,"issuer",void 0);u([f({type:Ge})],rr.prototype,"thisUpdate",void 0);u([f({type:Ge,optional:!0})],rr.prototype,"nextUpdate",void 0);u([f({type:Oi,repeated:"sequence",optional:!0})],rr.prototype,"revokedCertificates",void 0);u([f({type:yt,optional:!0,context:0,repeated:"sequence"})],rr.prototype,"crlExtensions",void 0);var Ni=class{constructor(e={}){this.tbsCertList=new rr,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:rr,raw:!0})],Ni.prototype,"tbsCertList",void 0);u([f({type:M})],Ni.prototype,"signatureAlgorithm",void 0);u([f({type:d.BitString})],Ni.prototype,"signature",void 0);var K=Hr(_n());var Ur=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:Pe})],Ur.prototype,"issuer",void 0);u([f({type:d.Integer,converter:ye})],Ur.prototype,"serialNumber",void 0);var Di=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Vt,context:0,implicit:!0})],Di.prototype,"subjectKeyIdentifier",void 0);u([f({type:Ur})],Di.prototype,"issuerAndSerialNumber",void 0);Di=u([I({type:S.Choice})],Di);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 Ri=class extends M{};Ri=u([I({type:S.Sequence})],Ri);var iu=class extends M{};iu=u([I({type:S.Sequence})],iu);var $t=class extends M{};$t=u([I({type:S.Sequence})],$t);var su=class extends M{};su=u([I({type:S.Sequence})],su);var Nv=class extends M{};Nv=u([I({type:S.Sequence})],Nv);var vp=class extends M{};vp=u([I({type:S.Sequence})],vp);var Mr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Mr.prototype,"attrType",void 0);u([f({type:d.Any,repeated:"set"})],Mr.prototype,"attrValues",void 0);var Sy,Ft=class{constructor(e={}){this.version=bt.v0,this.sid=new Di,this.digestAlgorithm=new Ri,this.signatureAlgorithm=new iu,this.signature=new ie,Object.assign(this,e)}};u([f({type:d.Integer})],Ft.prototype,"version",void 0);u([f({type:Di})],Ft.prototype,"sid",void 0);u([f({type:Ri})],Ft.prototype,"digestAlgorithm",void 0);u([f({type:Mr,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],Ft.prototype,"signedAttrs",void 0);u([f({type:iu})],Ft.prototype,"signatureAlgorithm",void 0);u([f({type:ie})],Ft.prototype,"signature",void 0);u([f({type:Mr,repeated:"set",context:1,implicit:!0,optional:!0})],Ft.prototype,"unsignedAttrs",void 0);var au=Sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};au=Sy=u([I({type:S.Set,itemType:Ft})],au);var Dv=class extends Ge{};Dv=u([I({type:S.Choice})],Dv);var Rv=class extends Ft{};Rv=u([I({type:S.Sequence})],Rv);var cu=class{constructor(e={}){this.acIssuer=new ae,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};u([f({type:ae})],cu.prototype,"acIssuer",void 0);u([f({type:d.Integer})],cu.prototype,"acSerial",void 0);u([f({type:dt,repeated:"sequence"})],cu.prototype,"attrs",void 0);var Ey,uu=Ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};uu=Ey=u([I({type:S.Sequence,itemType:d.ObjectIdentifier})],uu);var Xs=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};u([f({type:d.Integer,optional:!0})],Xs.prototype,"pathLenConstraint",void 0);u([f({type:uu,implicit:!0,context:0,optional:!0})],Xs.prototype,"permittedAttrs",void 0);u([f({type:uu,implicit:!0,context:1,optional:!0})],Xs.prototype,"excludedAttrs",void 0);u([f({type:d.Boolean,defaultValue:!0})],Xs.prototype,"permitUnSpecified",void 0);var yr=class{constructor(e={}){this.issuer=new Ke,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:Ke})],yr.prototype,"issuer",void 0);u([f({type:d.Integer,converter:ye})],yr.prototype,"serial",void 0);u([f({type:d.BitString,optional:!0})],yr.prototype,"issuerUID",void 0);var _y;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(_y||(_y={}));var gr=class{constructor(e={}){this.digestedObjectType=_y.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.Enumerated})],gr.prototype,"digestedObjectType",void 0);u([f({type:d.ObjectIdentifier,optional:!0})],gr.prototype,"otherObjectTypeID",void 0);u([f({type:M})],gr.prototype,"digestAlgorithm",void 0);u([f({type:d.BitString})],gr.prototype,"objectDigest",void 0);var Li=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Ke,optional:!0})],Li.prototype,"issuerName",void 0);u([f({type:yr,context:0,implicit:!0,optional:!0})],Li.prototype,"baseCertificateID",void 0);u([f({type:gr,context:1,implicit:!0,optional:!0})],Li.prototype,"objectDigestInfo",void 0);var Ui=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,repeated:"sequence"})],Ui.prototype,"v1Form",void 0);u([f({type:Li,context:0,implicit:!0})],Ui.prototype,"v2Form",void 0);Ui=u([I({type:S.Choice})],Ui);var Mi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};u([f({type:d.GeneralizedTime})],Mi.prototype,"notBeforeTime",void 0);u([f({type:d.GeneralizedTime})],Mi.prototype,"notAfterTime",void 0);var So=class{constructor(e={}){Object.assign(this,e)}};u([f({type:yr,implicit:!0,context:0,optional:!0})],So.prototype,"baseCertificateID",void 0);u([f({type:Ke,implicit:!0,context:1,optional:!0})],So.prototype,"entityName",void 0);u([f({type:gr,implicit:!0,context:2,optional:!0})],So.prototype,"objectDigestInfo",void 0);var Cy;(function(r){r[r.v2=1]="v2"})(Cy||(Cy={}));var Wt=class{constructor(e={}){this.version=Cy.v2,this.holder=new So,this.issuer=new Ui,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Mi,this.attributes=[],Object.assign(this,e)}};u([f({type:d.Integer})],Wt.prototype,"version",void 0);u([f({type:So})],Wt.prototype,"holder",void 0);u([f({type:Ui})],Wt.prototype,"issuer",void 0);u([f({type:M})],Wt.prototype,"signature",void 0);u([f({type:d.Integer,converter:ye})],Wt.prototype,"serialNumber",void 0);u([f({type:Mi})],Wt.prototype,"attrCertValidityPeriod",void 0);u([f({type:dt,repeated:"sequence"})],Wt.prototype,"attributes",void 0);u([f({type:d.BitString,optional:!0})],Wt.prototype,"issuerUniqueID",void 0);u([f({type:tr,optional:!0})],Wt.prototype,"extensions",void 0);var ji=class{constructor(e={}){this.acinfo=new Wt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:Wt})],ji.prototype,"acinfo",void 0);u([f({type:M})],ji.prototype,"signatureAlgorithm",void 0);u([f({type:d.BitString})],ji.prototype,"signatureValue",void 0);var lu;(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"})(lu||(lu={}));var Zs=class extends Zr{};var Ys=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier,implicit:!0,context:0})],Ys.prototype,"type",void 0);u([f({type:d.Any,implicit:!0,context:1})],Ys.prototype,"value",void 0);var fu=class{constructor(e={}){this.policyId="",this.classList=new Zs(lu.unclassified),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],fu.prototype,"policyId",void 0);u([f({type:Zs,defaultValue:new Zs(lu.unclassified)})],fu.prototype,"classList",void 0);u([f({type:Ys,repeated:"set"})],fu.prototype,"securityCategories",void 0);var Js=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie})],Js.prototype,"cotets",void 0);u([f({type:d.ObjectIdentifier})],Js.prototype,"oid",void 0);u([f({type:d.Utf8String})],Js.prototype,"string",void 0);var Ap=class{constructor(e={}){this.values=[],Object.assign(this,e)}};u([f({type:Ke,implicit:!0,context:0,optional:!0})],Ap.prototype,"policyAuthority",void 0);u([f({type:Js,repeated:"sequence"})],Ap.prototype,"values",void 0);var _K=`${vo}.4`,CK=`${vo}.6`,IK=`${vo}.10`,TK=`${le}.55`,pu=`${xo}.10`,BK=`${pu}.1`,kK=`${pu}.2`,PK=`${pu}.3`,OK=`${pu}.4`,NK=`${pu}.6`,Iy="2.5.4",DK=`${Iy}.72`;var Ty,Qs=class{constructor(e={}){this.targetCertificate=new yr,Object.assign(this,e)}};u([f({type:yr})],Qs.prototype,"targetCertificate",void 0);u([f({type:ae,optional:!0})],Qs.prototype,"targetName",void 0);u([f({type:gr,optional:!0})],Qs.prototype,"certDigestInfo",void 0);var ea=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ae,context:0,implicit:!0})],ea.prototype,"targetName",void 0);u([f({type:ae,context:1,implicit:!0})],ea.prototype,"targetGroup",void 0);u([f({type:Qs,context:2,implicit:!0})],ea.prototype,"targetCert",void 0);ea=u([I({type:S.Choice})],ea);var Sp=Ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};Sp=Ty=u([I({type:S.Sequence,itemType:ea})],Sp);var By,Lv=By=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,By.prototype)}};Lv=By=u([I({type:S.Sequence,itemType:Sp})],Lv);var Ep=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Ke,implicit:!0,context:0,optional:!0})],Ep.prototype,"roleAuthority",void 0);u([f({type:ae,implicit:!0,context:1})],Ep.prototype,"roleName",void 0);var hu=class{constructor(e={}){this.service=new ae,this.ident=new ae,Object.assign(this,e)}};u([f({type:ae})],hu.prototype,"service",void 0);u([f({type:ae})],hu.prototype,"ident",void 0);u([f({type:ie,optional:!0})],hu.prototype,"authInfo",void 0);var ky,du=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],du.prototype,"otherCertFormat",void 0);u([f({type:d.Any})],du.prototype,"otherCert",void 0);var Ki=class{constructor(e={}){Object.assign(this,e)}};u([f({type:mr})],Ki.prototype,"certificate",void 0);u([f({type:ji,context:2,implicit:!0})],Ki.prototype,"v2AttrCert",void 0);u([f({type:du,context:3,implicit:!0})],Ki.prototype,"other",void 0);Ki=u([I({type:S.Choice})],Ki);var Hi=ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Hi=ky=u([I({type:S.Set,itemType:Ki})],Hi);var br=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],br.prototype,"contentType",void 0);u([f({type:d.Any,context:0})],br.prototype,"content",void 0);var ta=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie})],ta.prototype,"single",void 0);u([f({type:d.Any})],ta.prototype,"any",void 0);ta=u([I({type:S.Choice})],ta);var Vi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Vi.prototype,"eContentType",void 0);u([f({type:ta,context:0,optional:!0})],Vi.prototype,"eContent",void 0);var mu=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ie,context:0,implicit:!0,optional:!0})],mu.prototype,"value",void 0);u([f({type:ie,converter:fv,context:0,implicit:!0,optional:!0,repeated:"sequence"})],mu.prototype,"constructedValue",void 0);mu=u([I({type:S.Choice})],mu);var Eo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new su,Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Eo.prototype,"contentType",void 0);u([f({type:su})],Eo.prototype,"contentEncryptionAlgorithm",void 0);u([f({type:mu,optional:!0})],Eo.prototype,"encryptedContent",void 0);var _o=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],_o.prototype,"keyAttrId",void 0);u([f({type:d.Any,optional:!0})],_o.prototype,"keyAttr",void 0);var Py,ra=class{constructor(e={}){this.subjectKeyIdentifier=new Vt,Object.assign(this,e)}};u([f({type:Vt})],ra.prototype,"subjectKeyIdentifier",void 0);u([f({type:d.GeneralizedTime,optional:!0})],ra.prototype,"date",void 0);u([f({type:_o,optional:!0})],ra.prototype,"other",void 0);var na=class{constructor(e={}){Object.assign(this,e)}};u([f({type:ra,context:0,implicit:!0,optional:!0})],na.prototype,"rKeyId",void 0);u([f({type:Ur,optional:!0})],na.prototype,"issuerAndSerialNumber",void 0);na=u([I({type:S.Choice})],na);var yu=class{constructor(e={}){this.rid=new na,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:na})],yu.prototype,"rid",void 0);u([f({type:ie})],yu.prototype,"encryptedKey",void 0);var _p=Py=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Py.prototype)}};_p=Py=u([I({type:S.Sequence,itemType:yu})],_p);var gu=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:M})],gu.prototype,"algorithm",void 0);u([f({type:d.BitString})],gu.prototype,"publicKey",void 0);var $i=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Vt,context:0,implicit:!0,optional:!0})],$i.prototype,"subjectKeyIdentifier",void 0);u([f({type:gu,context:1,implicit:!0,optional:!0})],$i.prototype,"originatorKey",void 0);u([f({type:Ur,optional:!0})],$i.prototype,"issuerAndSerialNumber",void 0);$i=u([I({type:S.Choice})],$i);var Ln=class{constructor(e={}){this.version=bt.v3,this.originator=new $i,this.keyEncryptionAlgorithm=new $t,this.recipientEncryptedKeys=new _p,Object.assign(this,e)}};u([f({type:d.Integer})],Ln.prototype,"version",void 0);u([f({type:$i,context:0})],Ln.prototype,"originator",void 0);u([f({type:ie,context:1,optional:!0})],Ln.prototype,"ukm",void 0);u([f({type:$t})],Ln.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:_p})],Ln.prototype,"recipientEncryptedKeys",void 0);var oa=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Vt,context:0,implicit:!0})],oa.prototype,"subjectKeyIdentifier",void 0);u([f({type:Ur})],oa.prototype,"issuerAndSerialNumber",void 0);oa=u([I({type:S.Choice})],oa);var Co=class{constructor(e={}){this.version=bt.v0,this.rid=new oa,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:d.Integer})],Co.prototype,"version",void 0);u([f({type:oa})],Co.prototype,"rid",void 0);u([f({type:$t})],Co.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],Co.prototype,"encryptedKey",void 0);var Fi=class{constructor(e={}){this.keyIdentifier=new ie,Object.assign(this,e)}};u([f({type:ie})],Fi.prototype,"keyIdentifier",void 0);u([f({type:d.GeneralizedTime,optional:!0})],Fi.prototype,"date",void 0);u([f({type:_o,optional:!0})],Fi.prototype,"other",void 0);var Io=class{constructor(e={}){this.version=bt.v4,this.kekid=new Fi,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:d.Integer})],Io.prototype,"version",void 0);u([f({type:Fi})],Io.prototype,"kekid",void 0);u([f({type:$t})],Io.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],Io.prototype,"encryptedKey",void 0);var To=class{constructor(e={}){this.version=bt.v0,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ie,Object.assign(this,e)}};u([f({type:d.Integer})],To.prototype,"version",void 0);u([f({type:vp,context:0,optional:!0})],To.prototype,"keyDerivationAlgorithm",void 0);u([f({type:$t})],To.prototype,"keyEncryptionAlgorithm",void 0);u([f({type:ie})],To.prototype,"encryptedKey",void 0);var bu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],bu.prototype,"oriType",void 0);u([f({type:d.Any})],bu.prototype,"oriValue",void 0);var Un=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Co,optional:!0})],Un.prototype,"ktri",void 0);u([f({type:Ln,context:1,implicit:!0,optional:!0})],Un.prototype,"kari",void 0);u([f({type:Io,context:2,implicit:!0,optional:!0})],Un.prototype,"kekri",void 0);u([f({type:To,context:3,implicit:!0,optional:!0})],Un.prototype,"pwri",void 0);u([f({type:bu,context:4,implicit:!0,optional:!0})],Un.prototype,"ori",void 0);Un=u([I({type:S.Choice})],Un);var Oy,wu=Oy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Oy.prototype)}};wu=Oy=u([I({type:S.Set,itemType:Un})],wu);var Ny,Uv=`${xo}.16`,NV=`${Uv}.2`,DV=`${Uv}.4`,ia=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],ia.prototype,"otherRevInfoFormat",void 0);u([f({type:d.Any})],ia.prototype,"otherRevInfo",void 0);var Cp=class{constructor(e={}){this.other=new ia,Object.assign(this,e)}};u([f({type:ia,context:1,implicit:!0})],Cp.prototype,"other",void 0);Cp=u([I({type:S.Choice})],Cp);var sa=Ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};sa=Ny=u([I({type:S.Set,itemType:Cp})],sa);var aa=class{constructor(e={}){Object.assign(this,e)}};u([f({type:Hi,context:0,implicit:!0,optional:!0})],aa.prototype,"certs",void 0);u([f({type:sa,context:1,implicit:!0,optional:!0})],aa.prototype,"crls",void 0);var Dy,Ry=Dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};Ry=Dy=u([I({type:S.Set,itemType:Mr})],Ry);var Wi=class{constructor(e={}){this.version=bt.v0,this.recipientInfos=new wu,this.encryptedContentInfo=new Eo,Object.assign(this,e)}};u([f({type:d.Integer})],Wi.prototype,"version",void 0);u([f({type:aa,context:0,implicit:!0,optional:!0})],Wi.prototype,"originatorInfo",void 0);u([f({type:wu})],Wi.prototype,"recipientInfos",void 0);u([f({type:Eo})],Wi.prototype,"encryptedContentInfo",void 0);u([f({type:Ry,context:1,implicit:!0,optional:!0})],Wi.prototype,"unprotectedAttrs",void 0);var Mv="1.2.840.113549.1.7.2";var Ly,Ip=Ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Ip=Ly=u([I({type:S.Set,itemType:Ri})],Ip);var Mn=class{constructor(e={}){this.version=bt.v0,this.digestAlgorithms=new Ip,this.encapContentInfo=new Vi,this.signerInfos=new au,Object.assign(this,e)}};u([f({type:d.Integer})],Mn.prototype,"version",void 0);u([f({type:Ip})],Mn.prototype,"digestAlgorithms",void 0);u([f({type:Vi})],Mn.prototype,"encapContentInfo",void 0);u([f({type:Hi,context:0,implicit:!0,optional:!0})],Mn.prototype,"certificates",void 0);u([f({type:sa,context:1,implicit:!0,optional:!0})],Mn.prototype,"crls",void 0);u([f({type:au})],Mn.prototype,"signerInfos",void 0);var qi="1.2.840.10045.2.1";var xu="1.2.840.10045.4.1",Tp="1.2.840.10045.4.3.1",vu="1.2.840.10045.4.3.2",Au="1.2.840.10045.4.3.3",Su="1.2.840.10045.4.3.4";var Uy="1.2.840.10045.3.1.7";var My="1.3.132.0.34";var jy="1.3.132.0.35";function Eu(r){return new M({algorithm:r})}var Kv=Eu(xu),k7=Eu(Tp),Hv=Eu(vu),Vv=Eu(Au),$v=Eu(Su);var _u=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],_u.prototype,"fieldType",void 0);u([f({type:d.Any})],_u.prototype,"parameters",void 0);_u=u([I({type:S.Sequence})],_u);var Ky=class extends ie{};var ca=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.OctetString})],ca.prototype,"a",void 0);u([f({type:d.OctetString})],ca.prototype,"b",void 0);u([f({type:d.BitString,optional:!0})],ca.prototype,"seed",void 0);ca=u([I({type:S.Sequence})],ca);var Hy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Hy||(Hy={}));var en=class{constructor(e={}){this.version=Hy.ecpVer1,Object.assign(this,e)}};u([f({type:d.Integer})],en.prototype,"version",void 0);u([f({type:_u})],en.prototype,"fieldID",void 0);u([f({type:ca})],en.prototype,"curve",void 0);u([f({type:Ky})],en.prototype,"base",void 0);u([f({type:d.Integer,converter:ye})],en.prototype,"order",void 0);u([f({type:d.Integer,optional:!0})],en.prototype,"cofactor",void 0);en=u([I({type:S.Sequence})],en);var tn=class{constructor(e={}){Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],tn.prototype,"namedCurve",void 0);u([f({type:d.Null})],tn.prototype,"implicitCurve",void 0);u([f({type:en})],tn.prototype,"specifiedCurve",void 0);tn=u([I({type:S.Choice})],tn);var ua=class{constructor(e={}){this.version=1,this.privateKey=new ie,Object.assign(this,e)}};u([f({type:d.Integer})],ua.prototype,"version",void 0);u([f({type:ie})],ua.prototype,"privateKey",void 0);u([f({type:tn,context:0,optional:!0})],ua.prototype,"parameters",void 0);u([f({type:d.BitString,context:1,optional:!0})],ua.prototype,"publicKey",void 0);var Gi=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.Integer,converter:ye})],Gi.prototype,"r",void 0);u([f({type:d.Integer,converter:ye})],Gi.prototype,"s",void 0);var qt="1.2.840.113549.1.1",rn=`${qt}.1`,Fv=`${qt}.7`,Wv=`${qt}.9`,Bo=`${qt}.10`,qv=`${qt}.2`,Gv=`${qt}.4`,la=`${qt}.5`,zv=`${qt}.14`;var Bp=`${qt}.11`,fa=`${qt}.12`,pa=`${qt}.13`,Vy=`${qt}.15`,$y=`${qt}.16`,zi="1.3.14.3.2.26",kp="2.16.840.1.101.3.4.2.4",Xi="2.16.840.1.101.3.4.2.1",Zi="2.16.840.1.101.3.4.2.2",Yi="2.16.840.1.101.3.4.2.3",Xv="2.16.840.1.101.3.4.2.5",Zv="2.16.840.1.101.3.4.2.6",Yv="1.2.840.113549.2.2",Jv="1.2.840.113549.2.5",ko=`${qt}.8`;function st(r){return new M({algorithm:r,parameters:null})}var o$=st(Yv),i$=st(Jv),jn=st(zi),s$=st(kp),a$=st(Xi),c$=st(Zi),u$=st(Yi),l$=st(Xv),f$=st(Zv),Pp=new M({algorithm:ko,parameters:F.serialize(jn)}),Fy=new M({algorithm:Wv,parameters:F.serialize(Ws.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),p$=st(rn),h$=st(qv),d$=st(Gv),m$=st(la),y$=st(Vy),g$=st($y),b$=st(fa),w$=st(pa),x$=st(Vy),v$=st($y);var ha=class{constructor(e={}){this.hashAlgorithm=new M(jn),this.maskGenAlgorithm=new M({algorithm:ko,parameters:F.serialize(jn)}),this.pSourceAlgorithm=new M(Fy),Object.assign(this,e)}};u([f({type:M,context:0,defaultValue:jn})],ha.prototype,"hashAlgorithm",void 0);u([f({type:M,context:1,defaultValue:Pp})],ha.prototype,"maskGenAlgorithm",void 0);u([f({type:M,context:2,defaultValue:Fy})],ha.prototype,"pSourceAlgorithm",void 0);var T$=new M({algorithm:Fv,parameters:F.serialize(new ha)});var nn=class{constructor(e={}){this.hashAlgorithm=new M(jn),this.maskGenAlgorithm=new M({algorithm:ko,parameters:F.serialize(jn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};u([f({type:M,context:0,defaultValue:jn})],nn.prototype,"hashAlgorithm",void 0);u([f({type:M,context:1,defaultValue:Pp})],nn.prototype,"maskGenAlgorithm",void 0);u([f({type:d.Integer,context:2,defaultValue:20})],nn.prototype,"saltLength",void 0);u([f({type:d.Integer,context:3,defaultValue:1})],nn.prototype,"trailerField",void 0);var R$=new M({algorithm:Bo,parameters:F.serialize(new nn)});var Ji=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ie,Object.assign(this,e)}};u([f({type:M})],Ji.prototype,"digestAlgorithm",void 0);u([f({type:ie})],Ji.prototype,"digest",void 0);var Wy,da=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.Integer,converter:ye})],da.prototype,"prime",void 0);u([f({type:d.Integer,converter:ye})],da.prototype,"exponent",void 0);u([f({type:d.Integer,converter:ye})],da.prototype,"coefficient",void 0);var Op=Wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Wy.prototype)}};Op=Wy=u([I({type:S.Sequence,itemType:da})],Op);var wr=class{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.Integer})],wr.prototype,"version",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"modulus",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"publicExponent",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"privateExponent",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"prime1",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"prime2",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"exponent1",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"exponent2",void 0);u([f({type:d.Integer,converter:ye})],wr.prototype,"coefficient",void 0);u([f({type:Op,optional:!0})],wr.prototype,"otherPrimeInfos",void 0);var ma=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.Integer,converter:ye})],ma.prototype,"modulus",void 0);u([f({type:d.Integer,converter:ye})],ma.prototype,"publicExponent",void 0);var qy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(qy||(qy={}));var wt=qy;var x1=Hr(w1(),1),{__extends:ga,__assign:pF,__rest:NI,__decorate:hF,__param:dF,__metadata:mF,__awaiter:v1,__generator:A1,__exportStar:yF,__createBinding:gF,__values:Cu,__read:Iu,__spread:jr,__spreadArrays:bF,__await:wF,__asyncGenerator:xF,__asyncDelegator:vF,__asyncValues:AF,__makeTemplateObject:SF,__importStar:EF,__importDefault:_F,__classPrivateFieldGet:CF,__classPrivateFieldSet:IF}=x1.default;var DI="injectionTokens";function zy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(DI,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function Tu(r){return!!r.useClass}function ba(r){return!!r.useFactory}var Rp=(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,jr(i))}};return this.reflectMethods.forEach(n),t},r})();function Po(r){return typeof r=="string"||typeof r=="symbol"}function Xy(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Lp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function S1(r){return typeof r=="function"||r instanceof Rp}function Qi(r){return!!r.useToken}function es(r){return r.useValue!=null}function E1(r){return Tu(r)||es(r)||Qi(r)||ba(r)}var RI=(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})(),Bu=RI;var LI=(function(r){ga(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Bu),_1=LI;var UI=(function(){function r(){this.scopedResolutions=new Map}return r})(),ku=UI;function MI(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function jI(r,e,t){return t===void 0&&(t=" "),jr([r],e.message.split(`
|
7
7
|
`).map(function(n){return t+n})).join(`
|
8
|
-
`)}function ky(r,e,t){var n=bu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=iB(i,e);return sB("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function Zv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var aB=(function(r){ha(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(wu);var cB=(function(r){ha(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(wu);var uB=(function(){function r(){this.preResolution=new aB,this.postResolution=new cB}return r})(),Yv=uB;var Py=new Map,lB=(function(){function r(e){this.parent=e,this._registry=new Xv,this.interceptors=new Yv,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:mt.Transient}),this.ensureNotDisposed();var o;if(zv(t)?o=t:o={useClass:t},zi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Ur(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&zi(c.provider)?s=c.provider:s=null}if((n.lifecycle===mt.Singleton||n.lifecycle==mt.ContainerScoped||n.lifecycle==mt.ResolutionScoped)&&(Xi(o)||da(o)))throw new Error('Cannot use lifecycle "'+mt[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(),To(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(),To(e)){if(To(t))return this.register(e,{useToken:t},{lifecycle:mt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:mt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!To(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:mt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new vu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&To(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(Gv(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=gu(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(l){n={error:l}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=gu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var l=c.value;l.options.frequency!="Once"&&s.push(l),l.callback(e,t,n)}}catch(h){o={error:h}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===mt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===mt.Singleton,o=e.options.lifecycle===mt.ContainerScoped,i=n||o,s;return Xi(e.provider)?s=e.provider.useValue:zi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):xu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):da(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===mt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new vu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&To(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=gu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=bu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Xi(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=gu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=bu(i.value,2),a=s[0],c=s[1];c.some(function(l){var h=l.options;return h.lifecycle===mt.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===mt.ContainerScoped?{provider:l.provider,options:l.options}:l}))}}catch(l){e={error:l}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},r.prototype.beforeResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:n})},r.prototype.afterResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:n})},r.prototype.dispose=function(){return Wv(this,void 0,void 0,function(){var e;return qv(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 up)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=Py.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,Ur([void 0],s)))})();return Zv(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 Ty(o)?lp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Ur([n.resolveAll(o.token,new vu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Ur([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new vu,o.isOptional):n.resolve(o.token,e,o.isOptional):lp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Ur([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(ky(t,i,l))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),De=new lB;function fB(r){return function(e){Py.set(e,Iy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){De.register(t,e)}):De.register(r.token,e))}}var ko=fB;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 Ny,Zi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};u([f({type:m.ObjectIdentifier})],Zi.prototype,"attrId",void 0);u([f({type:m.Any,repeated:"set"})],Zi.prototype,"attrValues",void 0);var Jv=Ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};Jv=Ny=u([B({type:S.Sequence,itemType:Zi})],Jv);var Dy,Qv=Dy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};Qv=Dy=u([B({type:S.Sequence,itemType:mr})],Qv);var pB="1.2.840.113549",hB=`${pB}.1`,e1=`${hB}.12`,ma=`${e1}.1`,hW=`${ma}.1`,dW=`${ma}.2`,mW=`${ma}.3`,yW=`${ma}.4`,gW=`${ma}.5`,bW=`${ma}.6`,Yi=`${e1}.10.1`;var vW=`${Yi}.1`,AW=`${Yi}.2`,SW=`${Yi}.3`,EW=`${Yi}.4`,_W=`${Yi}.5`,CW=`${Yi}.6`,fp="1.2.840.113549.1.9";var pp=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],pp.prototype,"certId",void 0);u([f({type:m.Any,context:0})],pp.prototype,"certValue",void 0);var t1=`${fp}.22`,PW=`${t1}.1`,OW=`${t1}.2`;var hp=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],hp.prototype,"crlId",void 0);u([f({type:m.Any,context:0})],hp.prototype,"crltValue",void 0);var dB=`${fp}.23`,UW=`${dB}.1`;var dp=class extends ie{},Po=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new dp,Object.assign(this,e)}};u([f({type:M})],Po.prototype,"encryptionAlgorithm",void 0);u([f({type:dp})],Po.prototype,"encryptedData",void 0);var Ry,Ly;(function(r){r[r.v1=0]="v1"})(Ly||(Ly={}));var mp=class extends ie{},Uy=Ry=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ry.prototype)}};Uy=Ry=u([B({type:S.Sequence,itemType:lt})],Uy);var Oo=class{constructor(e={}){this.version=Ly.v1,this.privateKeyAlgorithm=new M,this.privateKey=new mp,Object.assign(this,e)}};u([f({type:m.Integer})],Oo.prototype,"version",void 0);u([f({type:M})],Oo.prototype,"privateKeyAlgorithm",void 0);u([f({type:mp})],Oo.prototype,"privateKey",void 0);u([f({type:Uy,implicit:!0,context:0,optional:!0})],Oo.prototype,"attributes",void 0);var r1=class extends Oo{};r1=u([B({type:S.Sequence})],r1);var n1=class extends Po{};n1=u([B({type:S.Sequence})],n1);var yp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],yp.prototype,"secretTypeId",void 0);u([f({type:m.Any,context:0})],yp.prototype,"secretValue",void 0);var No=class{constructor(e={}){this.mac=new Gi,this.macSalt=new ie,this.iterations=1,Object.assign(this,e)}};u([f({type:Gi})],No.prototype,"mac",void 0);u([f({type:ie})],No.prototype,"macSalt",void 0);u([f({type:m.Integer,defaultValue:1})],No.prototype,"iterations",void 0);var Ji=class{constructor(e={}){this.version=3,this.authSafe=new mr,this.macData=new No,Object.assign(this,e)}};u([f({type:m.Integer})],Ji.prototype,"version",void 0);u([f({type:mr})],Ji.prototype,"authSafe",void 0);u([f({type:No,optional:!0})],Ji.prototype,"macData",void 0);var My,ya=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:m.ObjectIdentifier})],ya.prototype,"bagId",void 0);u([f({type:m.Any,context:0})],ya.prototype,"bagValue",void 0);u([f({type:Zi,repeated:"set",optional:!0})],ya.prototype,"bagAttributes",void 0);var o1=My=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,My.prototype)}};o1=My=u([B({type:S.Sequence,itemType:ya})],o1);var jy,Ky,Hy,qe="1.2.840.113549.1.9",jq=`${qe}.0`,b1=`${qe}.24`,Su=`${qe}.25`,x1=`${qe}.26`,w1=`${qe}.27`,Kq=`${b1}.1`,Hq=`${b1}.2`,Vq=`${qe}.1`,$q=`${qe}.2`,Fq=`${qe}.3`,Wq=`${qe}.4`,qq=`${qe}.5`,Gq=`${qe}.6`,Xy=`${qe}.7`,zq=`${qe}.8`,Xq=`${qe}.9`,Zq=`${qe}.13`,Eu=`${qe}.14`,Yq=`${qe}.15`,Jq=`${qe}.20`,Qq=`${qe}.21`;var eG=`${Su}.1`,tG=`${Su}.2`,rG=`${Su}.3`,nG=`${Su}.4`,oG=`${Su}.5`,_u="1.3.6.1.5.5.7.9",iG=`${_u}.1`,sG=`${_u}.2`,aG=`${_u}.3`,cG=`${_u}.4`,uG=`${_u}.5`,lG=`${x1}.1`,fG=`${x1}.2`,pG=`${w1}.1`,hG=`${w1}.2`,dG=`${qe}.16`,mG=`${qe}.22`,yG=`${qe}.23`,gG=`${ay}.65`,gp=class extends Je{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};u([f({type:m.IA5String})],gp.prototype,"ia5String",void 0);gp=u([B({type:S.Choice})],gp);var i1=class extends mr{};i1=u([B({type:S.Sequence})],i1);var s1=class extends Ji{};s1=u([B({type:S.Sequence})],s1);var a1=class extends Po{};a1=u([B({type:S.Sequence})],a1);var Vy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:m.IA5String})],Vy.prototype,"value",void 0);Vy=u([B({type:S.Choice})],Vy);var c1=class extends gp{};c1=u([B({type:S.Choice})],c1);var u1=class extends Je{};u1=u([B({type:S.Choice})],u1);var $y=class{constructor(e=new Date){this.value=e}};u([f({type:m.GeneralizedTime})],$y.prototype,"value",void 0);$y=u([B({type:S.Choice})],$y);var l1=class extends Je{};l1=u([B({type:S.Choice})],l1);var Fy=class{constructor(e="M"){this.value=e}toString(){return this.value}};u([f({type:m.PrintableString})],Fy.prototype,"value",void 0);Fy=u([B({type:S.Choice})],Fy);var bp=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:m.PrintableString})],bp.prototype,"value",void 0);bp=u([B({type:S.Choice})],bp);var f1=class extends bp{};f1=u([B({type:S.Choice})],f1);var p1=class extends Je{};p1=u([B({type:S.Choice})],p1);var Wy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:m.ObjectIdentifier})],Wy.prototype,"value",void 0);Wy=u([B({type:S.Choice})],Wy);var h1=class extends We{};h1=u([B({type:S.Choice})],h1);var qy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};u([f({type:m.Integer})],qy.prototype,"value",void 0);qy=u([B({type:S.Choice})],qy);var d1=class extends Vt{};d1=u([B({type:S.Sequence})],d1);var Au=class extends Je{};Au=u([B({type:S.Choice})],Au);var m1=jy=class extends Jt{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};m1=jy=u([B({type:S.Sequence})],m1);var y1=Ky=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};y1=Ky=u([B({type:S.Set,itemType:Lr})],y1);var Gy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:m.BmpString})],Gy.prototype,"value",void 0);Gy=u([B({type:S.Choice})],Gy);var zy=class extends M{};zy=u([B({type:S.Sequence})],zy);var g1=Hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Hy.prototype)}};g1=Hy=u([B({type:S.Sequence,itemType:zy})],g1);var Zy,Cu=Zy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Zy.prototype)}};Cu=Zy=u([B({type:S.Sequence,itemType:lt})],Cu);var tn=class{constructor(e={}){this.version=0,this.subject=new ke,this.subjectPKInfo=new ft,this.attributes=new Cu,Object.assign(this,e)}};u([f({type:m.Integer})],tn.prototype,"version",void 0);u([f({type:ke})],tn.prototype,"subject",void 0);u([f({type:ft})],tn.prototype,"subjectPKInfo",void 0);u([f({type:Cu,implicit:!0,context:0})],tn.prototype,"attributes",void 0);var Do=class{constructor(e={}){this.certificationRequestInfo=new tn,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:tn})],Do.prototype,"certificationRequestInfo",void 0);u([f({type:M})],Do.prototype,"signatureAlgorithm",void 0);u([f({type:m.BitString})],Do.prototype,"signature",void 0);var Ou="crypto.algorithm",sg=class{getAlgorithms(){return De.resolveAll(Ou)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Qi="crypto.algorithmProvider";De.registerSingleton(Qi,sg);var Ap,qt="1.3.36.3.3.2.8.1.1",v1=`${qt}.1`,A1=`${qt}.2`,S1=`${qt}.3`,E1=`${qt}.4`,_1=`${qt}.5`,C1=`${qt}.6`,B1=`${qt}.7`,I1=`${qt}.8`,T1=`${qt}.9`,k1=`${qt}.10`,P1=`${qt}.11`,O1=`${qt}.12`,N1=`${qt}.13`,D1=`${qt}.14`,R1="brainpoolP160r1",L1="brainpoolP160t1",U1="brainpoolP192r1",M1="brainpoolP192t1",j1="brainpoolP224r1",K1="brainpoolP224t1",H1="brainpoolP256r1",V1="brainpoolP256t1",$1="brainpoolP320r1",F1="brainpoolP320t1",W1="brainpoolP384r1",q1="brainpoolP384t1",G1="brainpoolP512r1",z1="brainpoolP512t1",Ke="ECDSA",Iu=Ap=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Ke.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return lv;case"sha-256":return fv;case"sha-384":return pv;case"sha-512":return hv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=gy;break;case"K-256":t=Ap.SECP256K1;break;case"P-384":t=by;break;case"P-521":t=xy;break;case R1:t=v1;break;case L1:t=A1;break;case U1:t=S1;break;case M1:t=E1;break;case j1:t=_1;break;case K1:t=C1;break;case H1:t=B1;break;case V1:t=I1;break;case $1:t=T1;break;case F1:t=k1;break;case W1:t=P1;break;case q1:t=O1;break;case G1:t=N1;break;case z1:t=D1;break}if(t)return new M({algorithm:Hi,parameters:F.serialize(new Jr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case fu:return{name:Ke,hash:{name:"SHA-1"}};case pu:return{name:Ke,hash:{name:"SHA-256"}};case hu:return{name:Ke,hash:{name:"SHA-384"}};case du:return{name:Ke,hash:{name:"SHA-512"}};case Hi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,Jr).namedCurve){case gy:return{name:Ke,namedCurve:"P-256"};case Ap.SECP256K1:return{name:Ke,namedCurve:"K-256"};case by:return{name:Ke,namedCurve:"P-384"};case xy:return{name:Ke,namedCurve:"P-521"};case v1:return{name:Ke,namedCurve:R1};case A1:return{name:Ke,namedCurve:L1};case S1:return{name:Ke,namedCurve:U1};case E1:return{name:Ke,namedCurve:M1};case _1:return{name:Ke,namedCurve:j1};case C1:return{name:Ke,namedCurve:K1};case B1:return{name:Ke,namedCurve:H1};case I1:return{name:Ke,namedCurve:V1};case T1:return{name:Ke,namedCurve:$1};case k1:return{name:Ke,namedCurve:F1};case P1:return{name:Ke,namedCurve:W1};case O1:return{name:Ke,namedCurve:q1};case N1:return{name:Ke,namedCurve:G1};case D1:return{name:Ke,namedCurve:z1}}}}return null}};Iu.SECP256K1="1.3.132.0.10";Iu=Ap=u([ko()],Iu);De.registerSingleton(Ou,Iu);var iA=Symbol("name"),sA=Symbol("value"),Se=class{constructor(e,t={},n=""){this[iA]=e,this[sA]=n;for(let o in t)this[o]=t[o]}};Se.NAME=iA;Se.VALUE=sA;var ag=class{static toTextObject(e){let t=new Se("Algorithm Identifier",{},nn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Hi:{let n=new Iu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},nn=class{static toString(e){let t=this.items[e];return t||e}};nn.items={[$i]:"sha1",[op]:"sha224",[Fi]:"sha256",[Wi]:"sha384",[qi]:"sha512",[Qr]:"rsaEncryption",[sa]:"sha1WithRSAEncryption",[bv]:"sha224WithRSAEncryption",[np]:"sha256WithRSAEncryption",[aa]:"sha384WithRSAEncryption",[ca]:"sha512WithRSAEncryption",[Hi]:"ecPublicKey",[fu]:"ecdsaWithSHA1",[rp]:"ecdsaWithSHA224",[pu]:"ecdsaWithSHA256",[hu]:"ecdsaWithSHA384",[du]:"ecdsaWithSHA512",[Fw]:"TLS WWW server authentication",[Ww]:"TLS WWW client authentication",[qw]:"Code Signing",[Gw]:"E-mail Protection",[zw]:"Time Stamping",[Xw]:"OCSP Signing",[cv]:"Signed Data"};var jn=class{static serialize(e){return this.serializeObj(e).join(`
|
9
|
-
`)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[
|
10
|
-
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return 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]||
|
8
|
+
`)}function Zy(r,e,t){var n=Iu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=MI(i,e);return jI("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function C1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var KI=(function(r){ga(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Bu);var HI=(function(r){ga(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Bu);var VI=(function(){function r(){this.preResolution=new KI,this.postResolution=new HI}return r})(),I1=VI;var Yy=new Map,$I=(function(){function r(e){this.parent=e,this._registry=new _1,this.interceptors=new I1,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},Qi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+jr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Qi(c.provider)?s=c.provider:s=null}if((n.lifecycle===wt.Singleton||n.lifecycle==wt.ContainerScoped||n.lifecycle==wt.ResolutionScoped)&&(es(o)||ba(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(),Po(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(),Po(e)){if(Po(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&&!Po(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:wt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new ku),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&Po(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(S1(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=Cu(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(l){n={error:l}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Cu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var l=c.value;l.options.frequency!="Once"&&s.push(l),l.callback(e,t,n)}}catch(h){o={error:h}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===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 es(e.provider)?s=e.provider.useValue:Qi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):Tu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ba(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 ku),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&Po(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=Cu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Iu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!es(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=Cu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Iu(i.value,2),a=s[0],c=s[1];c.some(function(l){var h=l.options;return h.lifecycle===wt.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===wt.ContainerScoped?{provider:l.provider,options:l.options}:l}))}}catch(l){e={error:l}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},r.prototype.beforeResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:n})},r.prototype.afterResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:n})},r.prototype.dispose=function(){return v1(this,void 0,void 0,function(){var e;return A1(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 Rp)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=Yy.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,jr([void 0],s)))})();return C1(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 Xy(o)?Lp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,jr([n.resolveAll(o.token,new ku,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,jr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new ku,o.isOptional):n.resolve(o.token,e,o.isOptional):Lp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,jr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(Zy(t,i,l))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),Re=new $I;function FI(r){return function(e){Yy.set(e,zy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Re.register(t,e)}):Re.register(r.token,e))}}var Oo=FI;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 Qy,ts=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};u([f({type:d.ObjectIdentifier})],ts.prototype,"attrId",void 0);u([f({type:d.Any,repeated:"set"})],ts.prototype,"attrValues",void 0);var T1=Qy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Qy.prototype)}};T1=Qy=u([I({type:S.Sequence,itemType:ts})],T1);var eg,B1=eg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,eg.prototype)}};B1=eg=u([I({type:S.Sequence,itemType:br})],B1);var WI="1.2.840.113549",qI=`${WI}.1`,k1=`${qI}.12`,wa=`${k1}.1`,Mq=`${wa}.1`,jq=`${wa}.2`,Kq=`${wa}.3`,Hq=`${wa}.4`,Vq=`${wa}.5`,$q=`${wa}.6`,rs=`${k1}.10.1`;var qq=`${rs}.1`,Gq=`${rs}.2`,zq=`${rs}.3`,Xq=`${rs}.4`,Zq=`${rs}.5`,Yq=`${rs}.6`,Up="1.2.840.113549.1.9";var Mp=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Mp.prototype,"certId",void 0);u([f({type:d.Any,context:0})],Mp.prototype,"certValue",void 0);var P1=`${Up}.22`,rG=`${P1}.1`,nG=`${P1}.2`;var jp=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],jp.prototype,"crlId",void 0);u([f({type:d.Any,context:0})],jp.prototype,"crltValue",void 0);var GI=`${Up}.23`,cG=`${GI}.1`;var Kp=class extends ie{},No=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Kp,Object.assign(this,e)}};u([f({type:M})],No.prototype,"encryptionAlgorithm",void 0);u([f({type:Kp})],No.prototype,"encryptedData",void 0);var tg,rg;(function(r){r[r.v1=0]="v1"})(rg||(rg={}));var Hp=class extends ie{},ng=tg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,tg.prototype)}};ng=tg=u([I({type:S.Sequence,itemType:dt})],ng);var Do=class{constructor(e={}){this.version=rg.v1,this.privateKeyAlgorithm=new M,this.privateKey=new Hp,Object.assign(this,e)}};u([f({type:d.Integer})],Do.prototype,"version",void 0);u([f({type:M})],Do.prototype,"privateKeyAlgorithm",void 0);u([f({type:Hp})],Do.prototype,"privateKey",void 0);u([f({type:ng,implicit:!0,context:0,optional:!0})],Do.prototype,"attributes",void 0);var O1=class extends Do{};O1=u([I({type:S.Sequence})],O1);var N1=class extends No{};N1=u([I({type:S.Sequence})],N1);var Vp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],Vp.prototype,"secretTypeId",void 0);u([f({type:d.Any,context:0})],Vp.prototype,"secretValue",void 0);var Ro=class{constructor(e={}){this.mac=new Ji,this.macSalt=new ie,this.iterations=1,Object.assign(this,e)}};u([f({type:Ji})],Ro.prototype,"mac",void 0);u([f({type:ie})],Ro.prototype,"macSalt",void 0);u([f({type:d.Integer,defaultValue:1})],Ro.prototype,"iterations",void 0);var ns=class{constructor(e={}){this.version=3,this.authSafe=new br,this.macData=new Ro,Object.assign(this,e)}};u([f({type:d.Integer})],ns.prototype,"version",void 0);u([f({type:br})],ns.prototype,"authSafe",void 0);u([f({type:Ro,optional:!0})],ns.prototype,"macData",void 0);var og,xa=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:d.ObjectIdentifier})],xa.prototype,"bagId",void 0);u([f({type:d.Any,context:0})],xa.prototype,"bagValue",void 0);u([f({type:ts,repeated:"set",optional:!0})],xa.prototype,"bagAttributes",void 0);var D1=og=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,og.prototype)}};D1=og=u([I({type:S.Sequence,itemType:xa})],D1);var ig,sg,ag,ze="1.2.840.113549.1.9",lz=`${ze}.0`,z1=`${ze}.24`,Ou=`${ze}.25`,X1=`${ze}.26`,Z1=`${ze}.27`,fz=`${z1}.1`,pz=`${z1}.2`,hz=`${ze}.1`,dz=`${ze}.2`,mz=`${ze}.3`,yz=`${ze}.4`,gz=`${ze}.5`,bz=`${ze}.6`,mg=`${ze}.7`,wz=`${ze}.8`,xz=`${ze}.9`,vz=`${ze}.13`,Nu=`${ze}.14`,Az=`${ze}.15`,Sz=`${ze}.20`,Ez=`${ze}.21`;var _z=`${Ou}.1`,Cz=`${Ou}.2`,Iz=`${Ou}.3`,Tz=`${Ou}.4`,Bz=`${Ou}.5`,Du="1.3.6.1.5.5.7.9",kz=`${Du}.1`,Pz=`${Du}.2`,Oz=`${Du}.3`,Nz=`${Du}.4`,Dz=`${Du}.5`,Rz=`${X1}.1`,Lz=`${X1}.2`,Uz=`${Z1}.1`,Mz=`${Z1}.2`,jz=`${ze}.16`,Kz=`${ze}.22`,Hz=`${ze}.23`,Vz=`${Iy}.65`,$p=class extends rt{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};u([f({type:d.IA5String})],$p.prototype,"ia5String",void 0);$p=u([I({type:S.Choice})],$p);var R1=class extends br{};R1=u([I({type:S.Sequence})],R1);var L1=class extends ns{};L1=u([I({type:S.Sequence})],L1);var U1=class extends No{};U1=u([I({type:S.Sequence})],U1);var cg=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:d.IA5String})],cg.prototype,"value",void 0);cg=u([I({type:S.Choice})],cg);var M1=class extends $p{};M1=u([I({type:S.Choice})],M1);var j1=class extends rt{};j1=u([I({type:S.Choice})],j1);var ug=class{constructor(e=new Date){this.value=e}};u([f({type:d.GeneralizedTime})],ug.prototype,"value",void 0);ug=u([I({type:S.Choice})],ug);var K1=class extends rt{};K1=u([I({type:S.Choice})],K1);var lg=class{constructor(e="M"){this.value=e}toString(){return this.value}};u([f({type:d.PrintableString})],lg.prototype,"value",void 0);lg=u([I({type:S.Choice})],lg);var Fp=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:d.PrintableString})],Fp.prototype,"value",void 0);Fp=u([I({type:S.Choice})],Fp);var H1=class extends Fp{};H1=u([I({type:S.Choice})],H1);var V1=class extends rt{};V1=u([I({type:S.Choice})],V1);var fg=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:d.ObjectIdentifier})],fg.prototype,"value",void 0);fg=u([I({type:S.Choice})],fg);var $1=class extends Ge{};$1=u([I({type:S.Choice})],$1);var pg=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};u([f({type:d.Integer})],pg.prototype,"value",void 0);pg=u([I({type:S.Choice})],pg);var F1=class extends Ft{};F1=u([I({type:S.Sequence})],F1);var Pu=class extends rt{};Pu=u([I({type:S.Choice})],Pu);var W1=ig=class extends tr{constructor(e){super(e),Object.setPrototypeOf(this,ig.prototype)}};W1=ig=u([I({type:S.Sequence})],W1);var q1=sg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,sg.prototype)}};q1=sg=u([I({type:S.Set,itemType:Mr})],q1);var hg=class{constructor(e=""){this.value=e}toString(){return this.value}};u([f({type:d.BmpString})],hg.prototype,"value",void 0);hg=u([I({type:S.Choice})],hg);var dg=class extends M{};dg=u([I({type:S.Sequence})],dg);var G1=ag=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ag.prototype)}};G1=ag=u([I({type:S.Sequence,itemType:dg})],G1);var yg,Ru=yg=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yg.prototype)}};Ru=yg=u([I({type:S.Sequence,itemType:dt})],Ru);var on=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new mt,this.attributes=new Ru,Object.assign(this,e)}};u([f({type:d.Integer})],on.prototype,"version",void 0);u([f({type:Pe})],on.prototype,"subject",void 0);u([f({type:mt})],on.prototype,"subjectPKInfo",void 0);u([f({type:Ru,implicit:!0,context:0})],on.prototype,"attributes",void 0);var Lo=class{constructor(e={}){this.certificationRequestInfo=new on,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([f({type:on,raw:!0})],Lo.prototype,"certificationRequestInfo",void 0);u([f({type:M})],Lo.prototype,"signatureAlgorithm",void 0);u([f({type:d.BitString})],Lo.prototype,"signature",void 0);var il="crypto.algorithm",Cg=class{getAlgorithms(){return Re.resolveAll(il)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},os="crypto.algorithmProvider";Re.registerSingleton(os,Cg);var zp,zt="1.3.36.3.3.2.8.1.1",Y1=`${zt}.1`,J1=`${zt}.2`,Q1=`${zt}.3`,eA=`${zt}.4`,tA=`${zt}.5`,rA=`${zt}.6`,nA=`${zt}.7`,oA=`${zt}.8`,iA=`${zt}.9`,sA=`${zt}.10`,aA=`${zt}.11`,cA=`${zt}.12`,uA=`${zt}.13`,lA=`${zt}.14`,fA="brainpoolP160r1",pA="brainpoolP160t1",hA="brainpoolP192r1",dA="brainpoolP192t1",mA="brainpoolP224r1",yA="brainpoolP224t1",gA="brainpoolP256r1",bA="brainpoolP256t1",wA="brainpoolP320r1",xA="brainpoolP320t1",vA="brainpoolP384r1",AA="brainpoolP384t1",SA="brainpoolP512r1",EA="brainpoolP512t1",$e="ECDSA",tl=zp=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case $e.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Kv;case"sha-256":return Hv;case"sha-384":return Vv;case"sha-512":return $v}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Uy;break;case"K-256":t=zp.SECP256K1;break;case"P-384":t=My;break;case"P-521":t=jy;break;case fA:t=Y1;break;case pA:t=J1;break;case hA:t=Q1;break;case dA:t=eA;break;case mA:t=tA;break;case yA:t=rA;break;case gA:t=nA;break;case bA:t=oA;break;case wA:t=iA;break;case xA:t=sA;break;case vA:t=aA;break;case AA:t=cA;break;case SA:t=uA;break;case EA:t=lA;break}if(t)return new M({algorithm:qi,parameters:F.serialize(new tn({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case xu:return{name:$e,hash:{name:"SHA-1"}};case vu:return{name:$e,hash:{name:"SHA-256"}};case Au:return{name:$e,hash:{name:"SHA-384"}};case Su:return{name:$e,hash:{name:"SHA-512"}};case qi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(F.parse(e.parameters,tn).namedCurve){case Uy:return{name:$e,namedCurve:"P-256"};case zp.SECP256K1:return{name:$e,namedCurve:"K-256"};case My:return{name:$e,namedCurve:"P-384"};case jy:return{name:$e,namedCurve:"P-521"};case Y1:return{name:$e,namedCurve:fA};case J1:return{name:$e,namedCurve:pA};case Q1:return{name:$e,namedCurve:hA};case eA:return{name:$e,namedCurve:dA};case tA:return{name:$e,namedCurve:mA};case rA:return{name:$e,namedCurve:yA};case nA:return{name:$e,namedCurve:gA};case oA:return{name:$e,namedCurve:bA};case iA:return{name:$e,namedCurve:wA};case sA:return{name:$e,namedCurve:xA};case aA:return{name:$e,namedCurve:vA};case cA:return{name:$e,namedCurve:AA};case uA:return{name:$e,namedCurve:SA};case lA:return{name:$e,namedCurve:EA}}}}return null}};tl.SECP256K1="1.3.132.0.10";tl=zp=u([Oo()],tl);Re.registerSingleton(il,tl);var RA=Symbol("name"),LA=Symbol("value"),Ae=class{constructor(e,t={},n=""){this[RA]=e,this[LA]=n;for(let o in t)this[o]=t[o]}};Ae.NAME=RA;Ae.VALUE=LA;var Ig=class{static toTextObject(e){let t=new Ae("Algorithm Identifier",{},an.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case qi:{let n=new tl().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},an=class{static toString(e){let t=this.items[e];return t||e}};an.items={[zi]:"sha1",[kp]:"sha224",[Xi]:"sha256",[Zi]:"sha384",[Yi]:"sha512",[rn]:"rsaEncryption",[la]:"sha1WithRSAEncryption",[zv]:"sha224WithRSAEncryption",[Bp]:"sha256WithRSAEncryption",[fa]:"sha384WithRSAEncryption",[pa]:"sha512WithRSAEncryption",[qi]:"ecPublicKey",[xu]:"ecdsaWithSHA1",[Tp]:"ecdsaWithSHA224",[vu]:"ecdsaWithSHA256",[Au]:"ecdsaWithSHA384",[Su]:"ecdsaWithSHA512",[xv]:"TLS WWW server authentication",[vv]:"TLS WWW client authentication",[Av]:"Code Signing",[Sv]:"E-mail Protection",[Ev]:"Time Stamping",[_v]:"OCSP Signing",[Mv]:"Signed Data"};var Hn=class{static serialize(e){return this.serializeObj(e).join(`
|
9
|
+
`)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Ae.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Ae.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],l=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${l}${c}`);else if(c instanceof Date)n.push(`${o}${l}${c.toUTCString()}`);else if(Array.isArray(c))for(let h of c)h[Ae.NAME]=a,n.push(...this.serializeObj(h,t));else if(c instanceof Ae)c[Ae.NAME]=a,n.push(...this.serializeObj(c,t));else if(K.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${l}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let h=c.toTextObject();h[Ae.NAME]=a,n.push(...this.serializeObj(h,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=K.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let l=o[s++].toString(16).padStart(2,"0");a.push(l)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Hn.oidSerializer=an;Hn.algorithmSerializer=Ig;var va,Uo=class r{get rawData(){return he(this,va,"f")||je(this,va,F.serialize(this.asn),"f"),he(this,va,"f")}constructor(...e){va.set(this,void 0),K.BufferSourceConverter.isBufferSource(e[0])?(this.asn=F.parse(e[0],e[1]),je(this,va,K.BufferSourceConverter.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof r?(0,K.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return F.toString(this.rawData);case"text":return Hn.serialize(this.toTextObject());case"hex":return K.Convert.ToHex(this.rawData);case"base64":return K.Convert.ToBase64(this.rawData);case"base64url":return K.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 Ae(this.getTextName(),{},e)}};va=new WeakMap;Uo.NAME="ASN";var nr=class r extends Uo{constructor(...e){let t;K.BufferSourceConverter.isBufferSource(e[0])?t=K.BufferSourceConverter.toArrayBuffer(e[0]):t=F.serialize(new yt({extnID:e[0],critical:e[1],extnValue:new ie(K.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[Ae.NAME]===r.NAME&&(e[Ae.NAME]=an.toString(this.type)),e}},UA,rl=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[UA]="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}};UA=Symbol.toStringTag;rl.DEFAULT="default";var lt=new rl,YI=/^[0-2](?:\.[1-9][0-9]*)+$/;function JI(r){return new RegExp(YI).test(r)}var Zp=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 JI(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Gt=new Zp;Gt.register("CN","2.5.4.3");Gt.register("L","2.5.4.7");Gt.register("ST","2.5.4.8");Gt.register("O","2.5.4.10");Gt.register("OU","2.5.4.11");Gt.register("C","2.5.4.6");Gt.register("DC","0.9.2342.19200300.100.1.25");Gt.register("E","1.2.840.113549.1.9.1");Gt.register("G","2.5.4.42");Gt.register("I","2.5.4.43");Gt.register("SN","2.5.4.4");Gt.register("T","2.5.4.12");function QI(r,e){return`\\${K.Convert.ToHex(K.Convert.FromUtf8String(e)).toUpperCase()}`}function eT(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,QI)}var Kr=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 Zp,this.asn=new Pe;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let o=t[n];this.extraNames.register(n,o)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Pe?this.asn=e:K.BufferSourceConverter.isBufferSource(e)?this.asn=F.parse(e,Pe):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Gt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||Gt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${K.Convert.ToHex(t.value.anyValue)}`:eT(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?`#${K.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Pe,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,o=null,i=",";for(;o=n.exec(`${e},`);){let[,s,a]=o,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),o[3]=c);let l=o[3];s=this.getTypeOid(s);let h=this.createAttribute(s,a);i==="+"?t[t.length-1].push(h):t.push(new bo([h])),i=l}return t}fromJSON(e){let t=new Pe;for(let n of e){let o=new bo;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let l=this.createAttribute(s,c);o.push(l)}}t.push(o)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){let n=new Ci({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=K.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
|
10
|
+
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return F.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||lt.get()):n=e[0]||lt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},MA="Cannot initialize GeneralName from ASN.1 data.",_A=`${MA} Unsupported string format in use.`,tT=`${MA} Value doesn't match to GUID regular expression.`,CA=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,IA="1.3.6.1.4.1.311.25.1",TA="1.3.6.1.4.1.311.20.2.3",gg="dns",bg="dn",wg="email",xg="ip",vg="url",Ag="guid",Sg="upn",Wp="id",sn=class extends Uo{constructor(...e){let t;if(e.length===2)switch(e[0]){case bg:{let n=new Kr(e[1]).toArrayBuffer(),o=F.parse(n,Pe);t=new ae({directoryName:o});break}case gg:t=new ae({dNSName:e[1]});break;case wg:t=new ae({rfc822Name:e[1]});break;case Ag:{let n=new RegExp(CA,"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?K.Convert.ToHex(new Uint8Array(K.Convert.FromHex(i)).reverse()):i).join("");t=new ae({otherName:new wo({typeId:IA,value:F.serialize(new ie(K.Convert.FromHex(o)))})});break}case xg:t=new ae({iPAddress:e[1]});break;case Wp:t=new ae({registeredID:e[1]});break;case Sg:{t=new ae({otherName:new wo({typeId:TA,value:F.serialize(Gm.toASN(e[1]))})});break}case vg:t=new ae({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else K.BufferSourceConverter.isBufferSource(e[0])?t=F.parse(e[0],ae):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=gg,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=wg,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=xg,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=vg,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Wp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=bg,this.value=new Kr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===IA){this.type=Ag;let t=F.parse(e.otherName.value,ie),n=new RegExp(CA,"i").exec(K.Convert.ToHex(t));if(!n)throw new Error(tT);this.value=n.slice(1).map((o,i)=>i<3?K.Convert.ToHex(new Uint8Array(K.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===TA)this.type=Sg,this.value=F.parse(e.otherName.value,rt).toString();else throw new Error(_A);else throw new Error(_A)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case bg:case gg:case Ag:case xg:case Wp:case Sg:case vg:e=this.type.toUpperCase();break;case wg:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Wp&&(t=an.toString(t)),new Ae(e,void 0,t)}},Vn=class extends Uo{constructor(e){let t;if(e instanceof Ke)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ae)n.push(o);else{let i=F.parse(new sn(o.type,o.value).rawData,ae);n.push(i)}t=new Ke(n)}else if(K.BufferSourceConverter.isBufferSource(e))t=F.parse(e,Ke);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new sn(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[Ae.NAME]];Array.isArray(o)||(o=[],e[n[Ae.NAME]]=o),o.push(n)}return e}};Vn.NAME="GeneralNames";var el="-{5}",nl="\\n",rT=`[^${nl}]+`,nT=`${el}BEGIN (${rT}(?=${el}))${el}`,oT=`${el}END \\1${el}`,Ea="\\n",iT=`[^:${nl}]+`,sT=`(?:[^${nl}]+${Ea}(?: +[^${nl}]+${Ea})*)`,aT="[a-zA-Z0-9=+/]+",cT=`(?:${aT}${Ea})+`,BA=`${nT}${Ea}(?:((?:${iT}: ${sT})+))?${Ea}?(${cT})${oT}`,Lt=class{static isPem(e){return typeof e=="string"&&new RegExp(BA,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(BA,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${nl}]+`,"g"),""),s={type:o[1],headers:[],rawData:K.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Ea,"g")),l=null;for(let h of c){let[p,m]=h.split(/:(.*)/);if(m===void 0){if(!l)throw new Error("Cannot parse PEM string. Incorrect header value");l.value+=p.trim()}else l&&s.headers.push(l),l={key:p,value:m.trim()}}l&&s.headers.push(l)}n.push(s)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){let n=new Array;return t?e.forEach(o=>{if(!K.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:K.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:K.BufferSourceConverter.toArrayBuffer(e)})}}static encodeStruct(e){var t;let n=e.type.toLocaleUpperCase(),o=[];if(o.push(`-----BEGIN ${n}-----`),!((t=e.headers)===null||t===void 0)&&t.length){for(let l of e.headers)o.push(`${l.key}: ${l.value}`);o.push("")}let i=K.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
|
-
`)}};Nt.CertificateTag="CERTIFICATE";Nt.CrlTag="CRL";Nt.CertificateRequestTag="CERTIFICATE REQUEST";Nt.PublicKeyTag="PUBLIC KEY";Nt.PrivateKeyTag="PRIVATE KEY";var Lo=class r extends Ro{static isAsnEncoded(e){return K.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Nt.isPem(e))return Nt.decode(e)[0];if(K.Convert.isHex(e))return K.Convert.FromHex(e);if(K.Convert.isBase64(e))return K.Convert.FromBase64(e);if(K.Convert.isBase64Url(e))return K.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=K.Convert.ToBinary(e);return Nt.isPem(t)?Nt.decode(t)[0]:K.Convert.isHex(t)?K.Convert.FromHex(t):K.Convert.isBase64(t)?K.Convert.FromBase64(t):K.Convert.isBase64Url(t)?K.Convert.FromBase64Url(t):K.BufferSourceConverter.toArrayBuffer(e)}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Nt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Mn=class r extends Lo{static async create(e,t=yt.get()){if(e instanceof r)return e;if(Tu.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(K.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Lo.isAsnEncoded(e)?super(e,ft):super(e),this.tag=Nt.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]||yt.get()):t=e[0]||yt.get();let i=this.rawData,s=F.parse(this.rawData,ft);return s.algorithm.algorithm===Bo&&(i=kB(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=De.resolve(Qi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case Qr:{let o=F.parse(e.subjectPublicKey,fa),i=K.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=K.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]||yt.get()):n=e[0]||yt.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=yt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=yt.get();let o=F.parse(this.rawData,ft);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,ft);switch(e.Algorithm=jn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Hi:e["EC Point"]=t.subjectPublicKey;break;case Qr:default:e["Raw Data"]=t.subjectPublicKey}return e}};function kB(r,e){return r.algorithm=new M({algorithm:Qr,parameters:null}),e=F.serialize(r),e}var _p=class r extends er{static async create(e,t=!1,n=yt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Mn.create(e,n)).getKeyIdentifier(n);return new r(K.Convert.ToHex(i),t)}constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new zr({keyIdentifier:new Ei(K.Convert.FromHex(e[0]))});super(Rf,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Kn?F.parse(t.name.rawData,je):t.name,o=new zr({authorityCertIssuer:n,authorityCertSerialNumber:K.Convert.FromHex(t.serialNumber)});super(Rf,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,zr);t.keyIdentifier&&(this.keyId=K.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?K.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,zr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Kn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};_p.NAME="Authority Key Identifier";var ba=class extends er{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,_i);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new _i({cA:e[0],pathLenConstraint:e[1]});super(Lf,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}};ba.NAME="Basic Constraints";var eA;(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"})(eA||(eA={}));var Cp=class extends er{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,qc);this.usages=t.map(n=>n)}else{let t=new qc(e[0]);super(Kf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>nn.toString(t)).join(", "),e}};Cp.NAME="Extended Key Usages";var tA;(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"})(tA||(tA={}));var Bp=class extends er{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,$s);this.usages=t.toNumber()}else{let t=new $s(e[0]);super(Hf,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,$s);return e[""]=t.toJSON().join(", "),e}};Bp.NAME="Key Usages";var Ip=class r extends er{static async create(e,t=!1,n=yt.get()){let i=await(await Mn.create(e,n)).getKeyIdentifier(n);return new r(K.Convert.ToHex(i),t)}constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Kt);this.keyId=K.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?K.Convert.FromHex(e[0]):e[0],n=new Kt(t);super(ey,e[1],F.serialize(n)),this.keyId=K.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Kt);return e[""]=t,e}};Ip.NAME="Subject Key Identifier";var Tp=class extends er{constructor(...e){K.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Jm,e[1],new Kn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Wf);this.names=new Kn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Tp.NAME="Subject Alternative Name";var Dt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new er(e),n=this.items.get(t.type);return n?new n(e):t}};Dt.items=new Map;var kp=class extends er{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,Hc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Hc(n.map(s=>new Ci({policyIdentifier:s})));super(Mf,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Se("",{},nn.toString(t))),e}};kp.NAME="Certificate Policies";Dt.register(Mf,kp);var Pp=class extends er{constructor(...e){var t;if(K.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 Xr({distributionPoint:new On({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new wo(o);super(jf,e[1],F.serialize(i))}else{let n=new wo(e[0]);super(jf,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,wo);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 rn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};Pp.NAME="CRL Distribution Points";var Op=class extends er{constructor(...e){var t,n,o,i;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Si){let s=new Si(e[0]);super(Df,e[1],F.serialize(s))}else{let s=e[0],a=new Si;vp(a,s,Rm,"ocsp"),vp(a,s,Lm,"caIssuers"),vp(a,s,Um,"timeStamping"),vp(a,s,Mm,"caRepository"),super(Df,e[1],F.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],F.parse(e.extnValue,Si).forEach(n=>{switch(n.accessMethod){case Rm:this.ocsp.push(new rn(n.accessLocation));break;case Lm:this.caIssuers.push(new rn(n.accessLocation));break;case Um:this.timeStamping.push(new rn(n.accessLocation));break;case Mm:this.caRepository.push(new rn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&wp(e,"OCSP",this.ocsp),this.caIssuers.length&&wp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&wp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&wp(e,"CA Repository",this.caRepository),e}};Op.NAME="Authority Info Access";function wp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Se("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Se.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function vp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new rn("url",s)),r.push(new kn({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var Np=class extends er{constructor(...e){K.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(zm,e[1],new Kn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,je);this.names=new Kn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};Np.NAME="Issuer Alternative Name";var xa=class r extends Ro{constructor(...e){let t;if(K.BufferSourceConverter.isBufferSource(e[0]))t=K.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>K.BufferSourceConverter.toArrayBuffer(i)):[];t=F.serialize(new lt({type:n,values:o}))}super(t,lt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Se("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Se.NAME]===r.NAME&&(e[Se.NAME]=nn.toString(this.type)),e}};xa.NAME="Attribute";var Dp=class extends xa{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new Au({printableString:e[0]});super(Xy,[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],Au);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Se.VALUE]=this.password,e}};Dp.NAME="Challenge Password";var Pu=class extends xa{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new Jt;for(let i of n)o.push(F.parse(i.rawData,pt));super(Eu,[F.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=F.parse(this.values[0],Jt);this.items=t.map(n=>Dt.create(F.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Se.NAME]]=n;return e}};Pu.NAME="Extensions";var wa=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new xa(e),n=this.items.get(t.type);return n?new n(e):t}};wa.items=new Map;var Nu="crypto.signatureFormatter",cg=class{toAsnSignature(e,t){return K.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return K.BufferSourceConverter.toArrayBuffer(t)}},Sp,ug=Sp=class{static createPssParams(e,t){let n=Sp.getHashAlgorithm(e);return n?new en({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:Io,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=De.resolve(Qi);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:sa,parameters:null});case"sha-256":return new M({algorithm:np,parameters:null});case"sha-384":return new M({algorithm:aa,parameters:null});case"sha-512":return new M({algorithm:ca,parameters:null})}}else return new M({algorithm:Qr,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=Sp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Bo,parameters:F.serialize(t)})}else return new M({algorithm:Bo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case Qr:return{name:"RSASSA-PKCS1-v1_5"};case sa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case np:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case aa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ca:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Bo:if(e.parameters){let t=F.parse(e.parameters,en);return{name:"RSA-PSS",hash:De.resolve(Qi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};ug=Sp=u([ko()],ug);De.registerSingleton(Ou,ug);var lg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:$i});case"sha-256":return new M({algorithm:Fi});case"sha-384":return new M({algorithm:Wi});case"sha-512":return new M({algorithm:qi})}return null}toWebAlgorithm(e){switch(e.algorithm){case $i:return{name:"SHA-1"};case Fi:return{name:"SHA-256"};case Wi:return{name:"SHA-384"};case qi:return{name:"SHA-512"}}return null}};lg=u([ko()],lg);De.registerSingleton(Ou,lg);var Hn=class r{addPadding(e,t){let n=K.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=K.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 Vi,s=K.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,Vi),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,K.combine)(s,a)}return null}};Hn.namedCurveSize=new Map;Hn.defaultNamedCurveSize=32;var og="1.3.101.110",rA="1.3.101.111",ig="1.3.101.112",nA="1.3.101.113",fg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=ig;break;case"x25519":t=og;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=ig;break;case"ed448":t=nA;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=og;break;case"x448":t=rA;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case ig:return{name:"Ed25519"};case nA:return{name:"EdDSA",namedCurve:"Ed448"};case og:return{name:"X25519"};case rA:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};fg=u([ko()],fg);De.registerSingleton(Ou,fg);var pg=class extends Lo{constructor(e){Lo.isAsnEncoded(e)?super(e,Do):super(e),this.tag=Nt.CertificateRequestTag}onInit(e){this.tbs=F.serialize(e.certificationRequestInfo),this.publicKey=new Mn(e.certificationRequestInfo.subjectPKInfo);let t=De.resolve(Qi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>wa.create(F.serialize(o)));let n=this.getAttribute(Eu);this.extensions=[],n instanceof Pu&&(this.extensions=n.items),this.subjectName=new gr(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=yt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=De.resolveAll(Nu).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,Do),n=t.certificationRequestInfo,o=new Se("",{Version:`${Zr[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Se("");for(let s of this.attributes){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Se("",{Algorithm:jn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};pg.NAME="PKCS#10 Certificate Request";var va=class extends Lo{constructor(e){Lo.isAsnEncoded(e)?super(e,pr):super(e),this.tag=Nt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=F.serialize(t);let n=new Uint8Array(t.serialNumber);n.length>1&&n[0]===0&&n[1]>127&&(n=n.slice(1)),this.serialNumber=K.Convert.ToHex(n),this.subjectName=new gr(t.subject),this.subject=new gr(t.subject).toString(),this.issuerName=new gr(t.issuer),this.issuer=this.issuerName.toString();let o=De.resolve(Qi);this.signatureAlgorithm=o.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let i=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!i)throw new Error("Cannot get 'notBefore' value");this.notBefore=i;let s=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!s)throw new Error("Cannot get 'notAfter' value");this.notAfter=s,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(a=>Dt.create(F.serialize(a)))),this.publicKey=new Mn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=yt.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 Mn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(K.BufferSourceConverter.isBufferSource(i)){let l=new Mn(i);n={...l.algorithm,...this.signatureAlgorithm},o=await l.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=De.resolveAll(Nu).reverse(),a=null;for(let l of s)if(a=l.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let h=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<h&&h<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=yt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=yt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,pr),n=t.tbsCertificate,o=new Se("",{Version:`${Zr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":jn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Se("",{"Not Before":n.validity.notBefore.getTime(),"Not After":n.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(n.issuerUniqueID&&(o["Issuer Unique ID"]=n.issuerUniqueID),n.subjectUniqueID&&(o["Subject Unique ID"]=n.subjectUniqueID),this.extensions.length){let i=new Se("");for(let s of this.extensions){let a=s.toTextObject();i[a[Se.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Se("",{Algorithm:jn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};va.NAME="Certificate";var Rp=class{static async createSelfSigned(e,t=yt.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=yt.get()){var n;let o;e.publicKey instanceof Mn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:K.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?K.BufferSourceConverter.toUint8Array(K.Convert.FromHex(e.serialNumber)):void 0;i=this.generateSerialNumber(i,t);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new pr({tbsCertificate:new ht({version:Zr.v3,serialNumber:i,validity:new Nn({notBefore:s,notAfter:a}),extensions:new Jt(((n=e.extensions)===null||n===void 0?void 0:n.map(b=>F.parse(b.rawData,pt)))||[]),subjectPublicKeyInfo:F.parse(o,ft)})});if(e.subject){let b=e.subject instanceof gr?e.subject:new gr(e.subject);c.tbsCertificate.subject=F.parse(b.toArrayBuffer(),ke)}if(e.issuer){let b=e.issuer instanceof gr?e.issuer:new gr(e.issuer);c.tbsCertificate.issuer=F.parse(b.toArrayBuffer(),ke)}let l={hash:"SHA-256"},h="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},p=De.resolve(Qi);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(h);let d=F.serialize(c.tbsCertificate),y="signingKey"in e?await t.subtle.sign(h,e.signingKey,d):e.signature,g=De.resolveAll(Nu).reverse(),x=null;for(let b of g)if(x=b.toAsnSignature(h,y),x)break;if(!x)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=x,new va(F.serialize(c))}static generateSerialNumber(e,t){let n=e&&e.length&&e.some(i=>i>0)?new Uint8Array(e):void 0;n||(n=t.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n}},oA;(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"})(oA||(oA={}));Dt.register(Lf,ba);Dt.register(Kf,Cp);Dt.register(Hf,Bp);Dt.register(ey,Ip);Dt.register(Rf,_p);Dt.register(Jm,Tp);Dt.register(jf,Pp);Dt.register(Df,Op);Dt.register(zm,Np);wa.register(Xy,Dp);wa.register(Eu,Pu);De.registerSingleton(Nu,cg);De.registerSingleton(Nu,Hn);Hn.namedCurveSize.set("P-256",32);Hn.namedCurveSize.set("K-256",32);Hn.namedCurveSize.set("P-384",48);Hn.namedCurveSize.set("P-521",66);var Vn="/",uA=new TextEncoder().encode(Vn),Lp=uA[0],Du=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=pe(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Lp)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(Vn))}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=uA),this._buf[0]!==Lp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Lp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Lp;)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(Vn).slice(1)}type(){return PB(this.baseNamespace())}name(){return OB(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Vn)||(e+=Vn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Vn):new r(e.slice(0,-1).join(Vn))}child(e){return this.toString()===Vn?e:e.toString()===Vn?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(),...NB(e.map(t=>t.namespaces()))])}};function PB(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function OB(r){let e=r.split(":");return e[e.length-1]}function NB(r){return[].concat(...r)}var Up=class extends rr{async listen(){throw new sf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var Aa=!!globalThis.process?.env?.DUMP_SESSION_KEYS,hg=16;function fA(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Mp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function jp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function _t(r,...e){if(!fA(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function dg(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function pA(r,e){_t(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function $n(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Fn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function DB(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var RB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function LB(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Kp(r){if(typeof r=="string")r=LB(r);else if(fA(r))r=Hp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function hA(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function dA(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 mg=(r,e)=>{function t(n,...o){if(_t(n),!RB)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let h=o[0];if(!h)throw new Error("nonce / iv required");r.varSizeNonce?_t(h):_t(h,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&_t(o[1]);let s=e(n,...o),a=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");_t(p)}},c=!1;return{encrypt(h,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,_t(h),a(s.encrypt.length,p),s.encrypt(h,p)},decrypt(h,p){if(_t(h),i&&h.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,p),s.decrypt(h,p)}}}return Object.assign(t,r),t};function yg(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error("invalid output length, expected "+r+", got: "+e.length);if(t&&!UB(e))throw new Error("invalid output, must be aligned");return e}function lA(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function mA(r,e,t){Mp(t);let n=new Uint8Array(16),o=DB(n);return lA(o,0,BigInt(e),t),lA(o,8,BigInt(r),t),n}function UB(r){return r.byteOffset%4===0}function Hp(r){return Uint8Array.from(r)}var gA=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),MB=gA("expand 16-byte k"),jB=gA("expand 32-byte k"),KB=$n(MB),HB=$n(jB);function ee(r,e){return r<<e|r>>>32-e}function gg(r){return r.byteOffset%4===0}var Vp=64,VB=16,bA=2**32-1,yA=new Uint32Array;function $B(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(Vp),h=$n(l),p=gg(o)&&gg(i),d=p?$n(o):yA,y=p?$n(i):yA;for(let g=0;g<c;s++){if(r(e,t,n,h,s,a),s>=bA)throw new Error("arx: counter overflow");let x=Math.min(Vp,c-g);if(p&&x===Vp){let b=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let E=0,D;E<VB;E++)D=b+E,y[D]=d[D]^h[E];g+=Vp;continue}for(let b=0,E;b<x;b++)E=g+b,i[E]=o[E]^l[b];g+=x}}function bg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=hA({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return jp(o),jp(s),Mp(i),Mp(t),(a,c,l,h,p=0)=>{_t(a),_t(c),_t(l);let d=l.length;if(h===void 0&&(h=new Uint8Array(d)),_t(h),jp(p),p<0||p>=bA)throw new Error("arx: counter overflow");if(h.length<d)throw new Error(`arx: output (${h.length}) is shorter than data (${d})`);let y=[],g=a.length,x,b;if(g===32)y.push(x=Hp(a)),b=HB;else if(g===16&&t)x=new Uint8Array(32),x.set(a),x.set(a,16),b=KB,y.push(x);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);gg(c)||y.push(c=Hp(c));let E=$n(x);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(b,E,$n(c.subarray(0,16)),E),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let V=new Uint8Array(12);V.set(c,i?0:12-c.length),c=V,y.push(c)}let I=$n(c);return $B(r,b,E,I,l,h,p,s),Fn(...y),h}}var gt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,xg=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Kp(e),_t(e,32);let t=gt(e,0),n=gt(e,2),o=gt(e,4),i=gt(e,6),s=gt(e,8),a=gt(e,10),c=gt(e,12),l=gt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let h=0;h<8;h++)this.pad[h]=gt(e,16+2*h)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],l=s[2],h=s[3],p=s[4],d=s[5],y=s[6],g=s[7],x=s[8],b=s[9],E=gt(e,t+0),D=gt(e,t+2),I=gt(e,t+4),V=gt(e,t+6),Y=gt(e,t+8),z=gt(e,t+10),te=gt(e,t+12),X=gt(e,t+14),T=i[0]+(E&8191),j=i[1]+((E>>>13|D<<3)&8191),q=i[2]+((D>>>10|I<<6)&8191),H=i[3]+((I>>>7|V<<9)&8191),w=i[4]+((V>>>4|Y<<12)&8191),v=i[5]+(Y>>>1&8191),_=i[6]+((Y>>>14|z<<2)&8191),P=i[7]+((z>>>11|te<<5)&8191),R=i[8]+((te>>>8|X<<8)&8191),U=i[9]+(X>>>5|o),k=0,L=k+T*a+j*(5*b)+q*(5*x)+H*(5*g)+w*(5*y);k=L>>>13,L&=8191,L+=v*(5*d)+_*(5*p)+P*(5*h)+R*(5*l)+U*(5*c),k+=L>>>13,L&=8191;let W=k+T*c+j*a+q*(5*b)+H*(5*x)+w*(5*g);k=W>>>13,W&=8191,W+=v*(5*y)+_*(5*d)+P*(5*p)+R*(5*h)+U*(5*l),k+=W>>>13,W&=8191;let N=k+T*l+j*c+q*a+H*(5*b)+w*(5*x);k=N>>>13,N&=8191,N+=v*(5*g)+_*(5*y)+P*(5*d)+R*(5*p)+U*(5*h),k+=N>>>13,N&=8191;let fe=k+T*h+j*l+q*c+H*a+w*(5*b);k=fe>>>13,fe&=8191,fe+=v*(5*x)+_*(5*g)+P*(5*y)+R*(5*d)+U*(5*p),k+=fe>>>13,fe&=8191;let me=k+T*p+j*h+q*l+H*c+w*a;k=me>>>13,me&=8191,me+=v*(5*b)+_*(5*x)+P*(5*g)+R*(5*y)+U*(5*d),k+=me>>>13,me&=8191;let Q=k+T*d+j*p+q*h+H*l+w*c;k=Q>>>13,Q&=8191,Q+=v*a+_*(5*b)+P*(5*x)+R*(5*g)+U*(5*y),k+=Q>>>13,Q&=8191;let we=k+T*y+j*d+q*p+H*h+w*l;k=we>>>13,we&=8191,we+=v*c+_*a+P*(5*b)+R*(5*x)+U*(5*g),k+=we>>>13,we&=8191;let Ee=k+T*g+j*y+q*d+H*p+w*h;k=Ee>>>13,Ee&=8191,Ee+=v*l+_*c+P*a+R*(5*b)+U*(5*x),k+=Ee>>>13,Ee&=8191;let Pe=k+T*x+j*g+q*y+H*d+w*p;k=Pe>>>13,Pe&=8191,Pe+=v*h+_*l+P*c+R*a+U*(5*b),k+=Pe>>>13,Pe&=8191;let Ae=k+T*b+j*x+q*g+H*y+w*d;k=Ae>>>13,Ae&=8191,Ae+=v*p+_*h+P*l+R*c+U*a,k+=Ae>>>13,Ae&=8191,k=(k<<2)+k|0,k=k+L|0,L=k&8191,k=k>>>13,W+=k,i[0]=L,i[1]=W,i[2]=N,i[3]=fe,i[4]=me,i[5]=Q,i[6]=we,i[7]=Ee,i[8]=Pe,i[9]=Ae}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;Fn(n)}update(e){dg(this),e=Kp(e),_t(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(){Fn(this.h,this.r,this.buffer,this.pad)}digestInto(e){dg(this),pA(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 FB(r){let e=(n,o)=>r(o).update(Kp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var xA=FB(r=>new xg(r));function AA(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],l=r[3],h=e[0],p=e[1],d=e[2],y=e[3],g=e[4],x=e[5],b=e[6],E=e[7],D=o,I=t[0],V=t[1],Y=t[2],z=s,te=a,X=c,T=l,j=h,q=p,H=d,w=y,v=g,_=x,P=b,R=E,U=D,k=I,L=V,W=Y;for(let fe=0;fe<i;fe+=2)z=z+j|0,U=ee(U^z,16),v=v+U|0,j=ee(j^v,12),z=z+j|0,U=ee(U^z,8),v=v+U|0,j=ee(j^v,7),te=te+q|0,k=ee(k^te,16),_=_+k|0,q=ee(q^_,12),te=te+q|0,k=ee(k^te,8),_=_+k|0,q=ee(q^_,7),X=X+H|0,L=ee(L^X,16),P=P+L|0,H=ee(H^P,12),X=X+H|0,L=ee(L^X,8),P=P+L|0,H=ee(H^P,7),T=T+w|0,W=ee(W^T,16),R=R+W|0,w=ee(w^R,12),T=T+w|0,W=ee(W^T,8),R=R+W|0,w=ee(w^R,7),z=z+q|0,W=ee(W^z,16),P=P+W|0,q=ee(q^P,12),z=z+q|0,W=ee(W^z,8),P=P+W|0,q=ee(q^P,7),te=te+H|0,U=ee(U^te,16),R=R+U|0,H=ee(H^R,12),te=te+H|0,U=ee(U^te,8),R=R+U|0,H=ee(H^R,7),X=X+w|0,k=ee(k^X,16),v=v+k|0,w=ee(w^v,12),X=X+w|0,k=ee(k^X,8),v=v+k|0,w=ee(w^v,7),T=T+j|0,L=ee(L^T,16),_=_+L|0,j=ee(j^_,12),T=T+j|0,L=ee(L^T,8),_=_+L|0,j=ee(j^_,7);let N=0;n[N++]=s+z|0,n[N++]=a+te|0,n[N++]=c+X|0,n[N++]=l+T|0,n[N++]=h+j|0,n[N++]=p+q|0,n[N++]=d+H|0,n[N++]=y+w|0,n[N++]=g+v|0,n[N++]=x+_|0,n[N++]=b+P|0,n[N++]=E+R|0,n[N++]=D+U|0,n[N++]=I+k|0,n[N++]=V+L|0,n[N++]=Y+W|0}function WB(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],l=e[1],h=e[2],p=e[3],d=e[4],y=e[5],g=e[6],x=e[7],b=t[0],E=t[1],D=t[2],I=t[3];for(let Y=0;Y<20;Y+=2)o=o+c|0,b=ee(b^o,16),d=d+b|0,c=ee(c^d,12),o=o+c|0,b=ee(b^o,8),d=d+b|0,c=ee(c^d,7),i=i+l|0,E=ee(E^i,16),y=y+E|0,l=ee(l^y,12),i=i+l|0,E=ee(E^i,8),y=y+E|0,l=ee(l^y,7),s=s+h|0,D=ee(D^s,16),g=g+D|0,h=ee(h^g,12),s=s+h|0,D=ee(D^s,8),g=g+D|0,h=ee(h^g,7),a=a+p|0,I=ee(I^a,16),x=x+I|0,p=ee(p^x,12),a=a+p|0,I=ee(I^a,8),x=x+I|0,p=ee(p^x,7),o=o+l|0,I=ee(I^o,16),g=g+I|0,l=ee(l^g,12),o=o+l|0,I=ee(I^o,8),g=g+I|0,l=ee(l^g,7),i=i+h|0,b=ee(b^i,16),x=x+b|0,h=ee(h^x,12),i=i+h|0,b=ee(b^i,8),x=x+b|0,h=ee(h^x,7),s=s+p|0,E=ee(E^s,16),d=d+E|0,p=ee(p^d,12),s=s+p|0,E=ee(E^s,8),d=d+E|0,p=ee(p^d,7),a=a+c|0,D=ee(D^a,16),y=y+D|0,c=ee(c^y,12),a=a+c|0,D=ee(D^a,8),y=y+D|0,c=ee(c^y,7);let V=0;n[V++]=o,n[V++]=i,n[V++]=s,n[V++]=a,n[V++]=b,n[V++]=E,n[V++]=D,n[V++]=I}var qB=bg(AA,{counterRight:!1,counterLength:4,allowShortKeys:!1}),GB=bg(AA,{counterRight:!1,counterLength:8,extendNonceFn:WB,allowShortKeys:!1});var zB=new Uint8Array(16),wA=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(zB.subarray(t))},XB=new Uint8Array(32);function vA(r,e,t,n,o){let i=r(e,t,XB),s=xA.create(i);o&&wA(s,o),wA(s,n);let a=mA(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Fn(i,a),c}var SA=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=yg(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=vA(r,e,t,c,n);return s.set(l,a),Fn(l),s},decrypt(i,s){s=yg(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=vA(r,e,t,a,n);if(!dA(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Fn(l),s}}),wg=mg({blockSize:64,nonceLength:12,tagLength:16},SA(qB)),jz=mg({blockSize:64,nonceLength:24,tagLength:16},SA(GB));function _A(r,e,t){return Fo(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Ss(r,Zn(t),Zn(e))}var vg=Uint8Array.from([0]),EA=Uint8Array.of();function CA(r,e,t,n=32){Fo(r),$o(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=EA);let s=new Uint8Array(i*o),a=Ss.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let h=0;h<i;h++)vg[0]=h+1,c.update(h===0?EA:l).update(t).update(vg).digestInto(l),s.set(l,o*h),a._cloneInto(c);return a.destroy(),c.destroy(),Ar(l,vg),s.slice(0,n)}var Ag={hashSHA256(r){return to(r.subarray())},getHKDF(r,e){let t=_A(to,e,r),o=CA(to,t,void 0,96),i=o.subarray(0,32),s=o.subarray(32,64),a=o.subarray(64,96);return[i,s,a]},generateX25519KeyPair(){let r=qa.utils.randomSecretKey();return{publicKey:qa.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:qa.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return qa.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return wg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return wg(n,e,t).decrypt(r.subarray(),o)}};var BA=Ag;function IA(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 Sa=r=>{let e=rt(2);return e[0]=r>>8,e[1]=r,e};Sa.bytes=2;var Ea=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)};Ea.bytes=2;function TA(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Sg(r,e){!e.enabled||!Aa||(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 Eg(r,e){!e.enabled||!Aa||(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 kA(r,e){!e.enabled||!Aa||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function _g(r,e){!e.enabled||!Aa||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Cg(r,e,t){!t.enabled||!Aa||(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 _a=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var ZB=0,YB=4294967295,JB="Cipher state has reached maximum n, a new handshake must be performed",$p=class{n;bytes;view;constructor(e=ZB){this.n=e,this.bytes=tt(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>YB)throw new Error(JB)}};var es=tt(0),Ca=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new $p(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}},Bg=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=pe(t,"utf-8");this.h=QB(e,n),this.ck=this.h,this.cs=new Ca(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Ca(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new he(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,es);return[new Ca(this.crypto,e),new Ca(this.crypto,t)]}},Ig=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:l}=e;this.crypto=t,this.ss=new Bg(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Ru=class extends Ig{writeMessageA(e){return new he(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new he(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new he(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new _a(`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 _a(`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 _a(`handshake stage 2 validation fail: ${t.message}`)}}};function QB(r,e){if(e.length<=32){let t=tt(32);return t.set(e),t}else return r.hash(e)}var Fp;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let i of t.webtransportCerthashes)n.uint32(10),n.bytes(i);if(t.streamMuxers!=null)for(let i of t.streamMuxers)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={webtransportCerthashes:[],streamMuxers:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&i.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new ec('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 ec('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=>Cr(t,r.codec()),r.decode=(t,n)=>_r(t,r.codec(),n)})(Fp||(Fp={}));var Lu;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),Fp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:tt(0),identitySig:tt(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=Fp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Cr(t,r.codec()),r.decode=(t,n)=>_r(t,r.codec(),n)})(Lu||(Lu={}));async function kg(r,e,t){let n=await r.sign(OA(e));return Lu.encode({identityKey:Xn(r.publicKey),identitySig:n,extensions:t})}async function Pg(r,e,t){try{let n=Lu.decode(r),o=oc(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=OA(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Ku(n.message)}}function OA(r){let e=pe("noise-libp2p-static-key:");return r instanceof Uint8Array?Bt([e,r],e.length+r.length):(r.prepend(e),r)}var Tg=class extends ao{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 Zl({lengthDecoder:Ea,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=c=>{try{for(let l of this.decoder.decode(c.data))this.onData(this.decrypt(l))}catch(l){this.abort(l)}};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 he;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(Sa(i.byteLength)),t.append(i)}return t}decrypt(e){let t=new he;for(let n=0;n<e.byteLength;n+=65535){let o=n+65535;if(o>e.byteLength&&(o=e.byteLength),o-hg<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-hg);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 Og(r,e,t){return new Tg(r,e,t)}async function NA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,h=await kg(i,a.publicKey,l),p=new Ru({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Sg(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(es),e),t.trace("Stage 0 - Initiator finished sending first message."),Eg(p.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=p.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),_g(p.re,t),kA(p.rs,t),t.trace("Initiator going to check remote's signature...");let y=await Pg(d,p.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(p.writeMessageC(h),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,x]=p.ss.split();return Cg(g,x,t),{payload:y,encrypt:b=>g.encryptWithAd(es,b),decrypt:(b,E)=>x.decryptWithAd(es,b,E)}}async function DA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,h=await kg(i,a.publicKey,l),p=new Ru({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Sg(p.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),p.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),_g(p.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(p.writeMessageB(h),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Eg(p.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let d=p.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let y=await Pg(d,p.rs,c),[g,x]=p.ss.split();return Cg(g,x,t),{payload:y,encrypt:b=>x.encryptWithAd(es,b),decrypt:(b,E)=>g.decryptWithAd(es,b,E)}}var Wp=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??BA;this.crypto=IA(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?TA(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??tt(0)}[Symbol.toStringTag]="@libp2p/noise";[os]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,t){let n=e.log?.newScope("noise")??this.log,o=zl(e,{lengthEncoder:Sa,lengthDecoder:Ea,maxDataLength:65535}),i=await this.performHandshakeInitiator(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=oc(i.payload.identityKey);return{connection:Og(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Id(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 Hu("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=zl(e,{lengthEncoder:Sa,lengthDecoder:Ea,maxDataLength:65535}),i=await this.performHandshakeResponder(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=oc(i.payload.identityKey);return{connection:Og(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:Id(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 NA({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 DA({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 RA(r={}){return e=>new Wp(e,r)}var Ng=Object.values(Ko).map(r=>r.decoder).reduce((r,e)=>r.or(e)),eI=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function LA(r){return r?.match(eI)?.groups?.fingerprint}function Dg(r){let t=r.getComponents().find(n=>n.code===466)?.value;if(t===void 0||t==="")throw new be(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function tI(r){return xr.decode(Ng.decode(r))}function rI(r){let e=tI(Dg(r)),t=nI(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new of(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function UA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Ct(nr.code,t);return Ps(`/certhash/${jo.encode(n.bytes)}`)}function nI(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new af(r)}}function MA(r,e){let{host:t,port:n,type:o}=sm(r);if(o!=="ip4"&&o!=="ip6")throw new be(`Multiaddr ${r} was not an IPv4 or IPv6 address`);let i=rI(r);return{type:"answer",sdp:`v=0
|
13
|
-
o=- 0 0 IN IP${o
|
12
|
+
`)}};Lt.CertificateTag="CERTIFICATE";Lt.CrlTag="CRL";Lt.CertificateRequestTag="CERTIFICATE REQUEST";Lt.PublicKeyTag="PUBLIC KEY";Lt.PrivateKeyTag="PRIVATE KEY";var Mo=class r extends Uo{static isAsnEncoded(e){return K.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Lt.isPem(e))return Lt.decode(e)[0];if(K.Convert.isHex(e))return K.Convert.FromHex(e);if(K.Convert.isBase64(e))return K.Convert.FromBase64(e);if(K.Convert.isBase64Url(e))return K.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=K.BufferSourceConverter.toUint8Array(e);if(t.length>0&&t[0]===48)return K.BufferSourceConverter.toArrayBuffer(e);let n=K.Convert.ToBinary(e);if(Lt.isPem(n))return Lt.decode(n)[0];if(K.Convert.isHex(n))return K.Convert.FromHex(n);if(K.Convert.isBase64(n))return K.Convert.FromBase64(n);if(K.Convert.isBase64Url(n))return K.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 Lt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Kn=class r extends Mo{static async create(e,t=lt.get()){if(e instanceof r)return e;if(rl.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(K.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Mo.isAsnEncoded(e)?super(e,mt):super(e),this.tag=Lt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||lt.get()):t=e[0]||lt.get();let i=this.rawData,s=F.parse(this.rawData,mt);return s.algorithm.algorithm===Bo&&(i=uT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Re.resolve(os),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case rn:{let o=F.parse(e.subjectPublicKey,ma),i=K.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=K.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]||lt.get()):n=e[0]||lt.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=lt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=lt.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=Hn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case qi:e["EC Point"]=t.subjectPublicKey;break;case rn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function uT(r,e){return r.algorithm=new M({algorithm:rn,parameters:null}),e=F.serialize(r),e}var Yp=class r extends nr{static async create(e,t=!1,n=lt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Kn.create(e,n)).getKeyIdentifier(n);return new r(K.Convert.ToHex(i),t)}constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new Yr({keyIdentifier:new Bi(K.Convert.FromHex(e[0]))});super(ap,e[1],F.serialize(t))}else{let t=e[0],n=t.name instanceof Vn?F.parse(t.name.rawData,Ke):t.name,o=new Yr({authorityCertIssuer:n,authorityCertSerialNumber:K.Convert.FromHex(t.serialNumber)});super(ap,e[1],F.serialize(o))}}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Yr);t.keyIdentifier&&(this.keyId=K.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?K.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Yr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Vn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};Yp.NAME="Authority Key Identifier";var _a=class extends nr{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,ki);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new ki({cA:e[0],pathLenConstraint:e[1]});super(cp,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}};_a.NAME="Basic Constraints";var kA;(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"})(kA||(kA={}));var Jp=class extends nr{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,tu);this.usages=t.map(n=>n)}else{let t=new tu(e[0]);super(pp,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>an.toString(t)).join(", "),e}};Jp.NAME="Extended Key Usages";var PA;(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"})(PA||(PA={}));var Qp=class extends nr{constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Gs);this.usages=t.toNumber()}else{let t=new Gs(e[0]);super(hp,e[1],F.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Gs);return e[""]=t.toJSON().join(", "),e}};Qp.NAME="Key Usages";var eh=class r extends nr{static async create(e,t=!1,n=lt.get()){let i=await(await Kn.create(e,n)).getKeyIdentifier(n);return new r(K.Convert.ToHex(i),t)}constructor(...e){if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=F.parse(this.value,Vt);this.keyId=K.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?K.Convert.FromHex(e[0]):e[0],n=new Vt(t);super(xy,e[1],F.serialize(n)),this.keyId=K.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=F.parse(this.value,Vt);return e[""]=t,e}};eh.NAME="Subject Key Identifier";var th=class extends nr{constructor(...e){K.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(by,e[1],new Vn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,gp);this.names=new Vn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};th.NAME="Subject Alternative Name";var Ut=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new nr(e),n=this.items.get(t.type);return n?new n(e):t}};Ut.items=new Map;var rh=class extends nr{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=F.parse(this.value,Zc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Zc(n.map(s=>new Pi({policyIdentifier:s})));super(lp,o,F.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Ae("",{},an.toString(t))),e}};rh.NAME="Certificate Policies";Ut.register(lp,rh);var nh=class extends nr{constructor(...e){var t;if(K.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 Jr({distributionPoint:new Dn({fullName:[new ae({uniformResourceIdentifier:s})]})})),i=new Ao(o);super(fp,e[1],F.serialize(i))}else{let n=new Ao(e[0]);super(fp,e[1],F.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Ao);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new sn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};nh.NAME="CRL Distribution Points";var oh=class extends nr{constructor(...e){var t,n,o,i;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Ti){let s=new Ti(e[0]);super(sp,e[1],F.serialize(s))}else{let s=e[0],a=new Ti;Gp(a,s,ty,"ocsp"),Gp(a,s,ry,"caIssuers"),Gp(a,s,ny,"timeStamping"),Gp(a,s,oy,"caRepository"),super(sp,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,Ti).forEach(n=>{switch(n.accessMethod){case ty:this.ocsp.push(new sn(n.accessLocation));break;case ry:this.caIssuers.push(new sn(n.accessLocation));break;case ny:this.timeStamping.push(new sn(n.accessLocation));break;case oy:this.caRepository.push(new sn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&qp(e,"OCSP",this.ocsp),this.caIssuers.length&&qp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&qp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&qp(e,"CA Repository",this.caRepository),e}};oh.NAME="Authority Info Access";function qp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Ae("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Ae.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function Gp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new sn("url",s)),r.push(new On({accessMethod:t,accessLocation:F.parse(s.rawData,ae)}))})}var ih=class extends nr{constructor(...e){K.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(dy,e[1],new Vn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=F.parse(e.extnValue,Ke);this.names=new Vn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};ih.NAME="Issuer Alternative Name";var Ca=class r extends Uo{constructor(...e){let t;if(K.BufferSourceConverter.isBufferSource(e[0]))t=K.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>K.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 Ae("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Ae.NAME]===r.NAME&&(e[Ae.NAME]=an.toString(this.type)),e}};Ca.NAME="Attribute";var sh=class extends Ca{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new Pu({printableString:e[0]});super(mg,[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],Pu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Ae.VALUE]=this.password,e}};sh.NAME="Challenge Password";var ol=class extends Ca{constructor(...e){var t;if(K.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new tr;for(let i of n)o.push(F.parse(i.rawData,yt));super(Nu,[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],tr);this.items=t.map(n=>Ut.create(F.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Ae.NAME]]=n;return e}};ol.NAME="Extensions";var Ia=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new Ca(e),n=this.items.get(t.type);return n?new n(e):t}};Ia.items=new Map;var sl="crypto.signatureFormatter",Tg=class{toAsnSignature(e,t){return K.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return K.BufferSourceConverter.toArrayBuffer(t)}},Xp,Bg=Xp=class{static createPssParams(e,t){let n=Xp.getHashAlgorithm(e);return n?new nn({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:ko,parameters:F.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Re.resolve(os);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:la,parameters:null});case"sha-256":return new M({algorithm:Bp,parameters:null});case"sha-384":return new M({algorithm:fa,parameters:null});case"sha-512":return new M({algorithm:pa,parameters:null})}}else return new M({algorithm:rn,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=Xp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Bo,parameters:F.serialize(t)})}else return new M({algorithm:Bo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case rn:return{name:"RSASSA-PKCS1-v1_5"};case la:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Bp:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case fa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case pa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Bo:if(e.parameters){let t=F.parse(e.parameters,nn);return{name:"RSA-PSS",hash:Re.resolve(os).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Bg=Xp=u([Oo()],Bg);Re.registerSingleton(il,Bg);var kg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:zi});case"sha-256":return new M({algorithm:Xi});case"sha-384":return new M({algorithm:Zi});case"sha-512":return new M({algorithm:Yi})}return null}toWebAlgorithm(e){switch(e.algorithm){case zi:return{name:"SHA-1"};case Xi:return{name:"SHA-256"};case Zi:return{name:"SHA-384"};case Yi:return{name:"SHA-512"}}return null}};kg=u([Oo()],kg);Re.registerSingleton(il,kg);var $n=class r{addPadding(e,t){let n=K.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o.buffer}removePadding(e,t=!1){let n=K.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 Gi,s=K.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,Gi),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,K.combine)(s,a)}return null}};$n.namedCurveSize=new Map;$n.defaultNamedCurveSize=32;var Eg="1.3.101.110",OA="1.3.101.111",_g="1.3.101.112",NA="1.3.101.113",Pg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=_g;break;case"x25519":t=Eg;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=_g;break;case"ed448":t=NA;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Eg;break;case"x448":t=OA;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case _g:return{name:"Ed25519"};case NA:return{name:"EdDSA",namedCurve:"Ed448"};case Eg:return{name:"X25519"};case OA:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Pg=u([Oo()],Pg);Re.registerSingleton(il,Pg);var Lu,Uu,Mu,ju,Ku,Hu,Vu,Aa,Og=class extends Mo{get subjectName(){return he(this,Uu,"f")||je(this,Uu,new Kr(this.asn.certificationRequestInfo.subject),"f"),he(this,Uu,"f")}get subject(){return he(this,Mu,"f")||je(this,Mu,this.subjectName.toString(),"f"),he(this,Mu,"f")}get signatureAlgorithm(){if(!he(this,ju,"f")){let e=Re.resolve(os);je(this,ju,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,ju,"f")}get signature(){return he(this,Ku,"f")||je(this,Ku,this.asn.signature,"f"),he(this,Ku,"f")}get publicKey(){return he(this,Hu,"f")||je(this,Hu,new Kn(this.asn.certificationRequestInfo.subjectPKInfo),"f"),he(this,Hu,"f")}get attributes(){return he(this,Vu,"f")||je(this,Vu,this.asn.certificationRequestInfo.attributes.map(e=>Ia.create(F.serialize(e))),"f"),he(this,Vu,"f")}get extensions(){if(!he(this,Aa,"f")){je(this,Aa,[],"f");let e=this.getAttribute(Nu);e instanceof ol&&je(this,Aa,e.items,"f")}return he(this,Aa,"f")}get tbs(){return he(this,Lu,"f")||je(this,Lu,this.asn.certificationRequestInfoRaw||F.serialize(this.asn.certificationRequestInfo),"f"),he(this,Lu,"f")}constructor(e){let t=Mo.isAsnEncoded(e)?[e,Lo]:[e];super(t[0],t[1]),Lu.set(this,void 0),Uu.set(this,void 0),Mu.set(this,void 0),ju.set(this,void 0),Ku.set(this,void 0),Hu.set(this,void 0),Vu.set(this,void 0),Aa.set(this,void 0),this.tag=Lt.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=lt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Re.resolveAll(sl).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,Lo),n=t.certificationRequestInfo,o=new Ae("",{Version:`${Qr[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Ae("");for(let s of this.attributes){let a=s.toTextObject();i[a[Ae.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Ae("",{Algorithm:Hn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Lu=new WeakMap,Uu=new WeakMap,Mu=new WeakMap,ju=new WeakMap,Ku=new WeakMap,Hu=new WeakMap,Vu=new WeakMap,Aa=new WeakMap;Og.NAME="PKCS#10 Certificate Request";var $u,Fu,Wu,qu,Gu,zu,Xu,Zu,Yu,Ju,Sa,Qu,Ta=class extends Mo{get publicKey(){return he(this,Qu,"f")||je(this,Qu,new Kn(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),he(this,Qu,"f")}get serialNumber(){if(!he(this,Fu,"f")){let e=this.asn.tbsCertificate,t=new Uint8Array(e.serialNumber);t.length>1&&t[0]===0&&t[1]>127&&(t=t.slice(1)),je(this,Fu,K.Convert.ToHex(t),"f")}return he(this,Fu,"f")}get subjectName(){return he(this,Wu,"f")||je(this,Wu,new Kr(this.asn.tbsCertificate.subject),"f"),he(this,Wu,"f")}get subject(){return he(this,qu,"f")||je(this,qu,this.subjectName.toString(),"f"),he(this,qu,"f")}get issuerName(){return he(this,Gu,"f")||je(this,Gu,new Kr(this.asn.tbsCertificate.issuer),"f"),he(this,Gu,"f")}get issuer(){return he(this,zu,"f")||je(this,zu,this.issuerName.toString(),"f"),he(this,zu,"f")}get notBefore(){if(!he(this,Xu,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");je(this,Xu,e,"f")}return he(this,Xu,"f")}get notAfter(){if(!he(this,Zu,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");je(this,Zu,e,"f")}return he(this,Zu,"f")}get signatureAlgorithm(){if(!he(this,Yu,"f")){let e=Re.resolve(os);je(this,Yu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return he(this,Yu,"f")}get signature(){return he(this,Ju,"f")||je(this,Ju,this.asn.signatureValue,"f"),he(this,Ju,"f")}get extensions(){return he(this,Sa,"f")||(je(this,Sa,[],"f"),this.asn.tbsCertificate.extensions&&je(this,Sa,this.asn.tbsCertificate.extensions.map(e=>Ut.create(F.serialize(e))),"f")),he(this,Sa,"f")}get tbs(){return he(this,$u,"f")||je(this,$u,this.asn.tbsCertificateRaw||F.serialize(this.asn.tbsCertificate),"f"),he(this,$u,"f")}constructor(e){let t=Mo.isAsnEncoded(e)?[e,mr]:[e];super(t[0],t[1]),$u.set(this,void 0),Fu.set(this,void 0),Wu.set(this,void 0),qu.set(this,void 0),Gu.set(this,void 0),zu.set(this,void 0),Xu.set(this,void 0),Zu.set(this,void 0),Yu.set(this,void 0),Ju.set(this,void 0),Sa.set(this,void 0),Qu.set(this,void 0),this.tag=Lt.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=lt.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 Kn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(K.BufferSourceConverter.isBufferSource(i)){let l=new Kn(i);n={...l.algorithm,...this.signatureAlgorithm},o=await l.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Re.resolveAll(sl).reverse(),a=null;for(let l of s)if(a=l.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let h=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<h&&h<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=lt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=lt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=F.parse(this.rawData,mr),n=t.tbsCertificate,o=new Ae("",{Version:`${Qr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Hn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Ae("",{"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 Ae("");for(let s of this.extensions){let a=s.toTextObject();i[a[Ae.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Ae("",{Algorithm:Hn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};$u=new WeakMap,Fu=new WeakMap,Wu=new WeakMap,qu=new WeakMap,Gu=new WeakMap,zu=new WeakMap,Xu=new WeakMap,Zu=new WeakMap,Yu=new WeakMap,Ju=new WeakMap,Sa=new WeakMap,Qu=new WeakMap;Ta.NAME="Certificate";function lT(r,e=lt.get()){let t=K.BufferSourceConverter.toUint8Array(K.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 ah=class{static async createSelfSigned(e,t=lt.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=lt.get()){var n;let o;e.publicKey instanceof Kn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:K.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=lT(e.serialNumber),s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new mr({tbsCertificate:new gt({version:Qr.v3,serialNumber:i,validity:new Rn({notBefore:s,notAfter:a}),extensions:new tr(((n=e.extensions)===null||n===void 0?void 0:n.map(b=>F.parse(b.rawData,yt)))||[]),subjectPublicKeyInfo:F.parse(o,mt)})});if(e.subject){let b=e.subject instanceof Kr?e.subject:new Kr(e.subject);c.tbsCertificate.subject=F.parse(b.toArrayBuffer(),Pe)}if(e.issuer){let b=e.issuer instanceof Kr?e.issuer:new Kr(e.issuer);c.tbsCertificate.issuer=F.parse(b.toArrayBuffer(),Pe)}let l={hash:"SHA-256"},h="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},p=Re.resolve(os);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(h);let m=F.serialize(c.tbsCertificate),y="signingKey"in e?await t.subtle.sign(h,e.signingKey,m):e.signature,g=Re.resolveAll(sl).reverse(),w=null;for(let b of g)if(w=b.toAsnSignature(h,y),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new Ta(F.serialize(c))}},fT,pT,hT,dT,mT,DA;(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"})(DA||(DA={}));fT=new WeakMap,pT=new WeakMap,hT=new WeakMap,dT=new WeakMap,mT=new WeakMap;var yT,gT,bT,wT,xT,vT,AT;yT=new WeakMap,gT=new WeakMap,bT=new WeakMap,wT=new WeakMap,xT=new WeakMap,vT=new WeakMap,AT=new WeakMap;Ut.register(cp,_a);Ut.register(pp,Jp);Ut.register(hp,Qp);Ut.register(xy,eh);Ut.register(ap,Yp);Ut.register(by,th);Ut.register(fp,nh);Ut.register(sp,oh);Ut.register(dy,ih);Ia.register(mg,sh);Ia.register(Nu,ol);Re.registerSingleton(sl,Tg);Re.registerSingleton(sl,$n);$n.namedCurveSize.set("P-256",32);$n.namedCurveSize.set("K-256",32);$n.namedCurveSize.set("P-384",48);$n.namedCurveSize.set("P-521",66);var Fn="/",jA=new TextEncoder().encode(Fn),ch=jA[0],al=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=fe(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]!==ch)throw new Error("Invalid key")}toString(e="utf8"){return ce(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Fn))}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=jA),this._buf[0]!==ch){let e=new Uint8Array(this._buf.byteLength+1);e.fill(ch,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ch;)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(Fn).slice(1)}type(){return ST(this.baseNamespace())}name(){return ET(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Fn)||(e+=Fn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Fn):new r(e.slice(0,-1).join(Fn))}child(e){return this.toString()===Fn?e:e.toString()===Fn?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(),..._T(e.map(t=>t.namespaces()))])}};function ST(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function ET(r){let e=r.split(":");return e[e.length-1]}function _T(r){return[].concat(...r)}var uh=class extends Xn{async listen(){throw new Nf("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Ng(){let r=Qe(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:(async function*(){yield*await r.promise})()}}function KA(){let r=Ng(),e=Ng();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function CT(r){return r[Symbol.asyncIterator]!=null}async function IT(r,e,t){try{await Promise.all(r.map(async n=>{for await(let o of n)await e.push(o,{signal:t}),t.throwIfAborted()})),await e.end(void 0,{signal:t})}catch(n){await e.end(n,{signal:t}).catch(()=>{})}}async function*TT(r){let e=new AbortController,t=Cf();IT(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*BT(r){for(let e of r)yield*e}function kT(...r){let e=[];for(let t of r)CT(t)||e.push(t);return e.length===r.length?BT(e):TT(r)}var HA=kT;function VA(r,...e){if(r==null)throw new Error("Empty pipeline");if(Dg(r)){let n=r;r=()=>n.source}else if(FA(r)||$A(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Dg(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Dg(t[n])&&(t[n]=OT(t[n]));return PT(...t)}var PT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},$A=r=>r?.[Symbol.asyncIterator]!=null,FA=r=>r?.[Symbol.iterator]!=null,Dg=r=>r==null?!1:r.sink!=null&&r.source!=null,OT=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Ms({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if($A(i))o=async function*(){yield*i,n.end()};else if(FA(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return HA(n,o())}return r.source};var Ba=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function qA(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function lh(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function fh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Tt(r,...e){if(!qA(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Rg(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 GA(r,e){Tt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Wn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function qn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function NT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var DT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function RT(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function ph(r){if(typeof r=="string")r=RT(r);else if(qA(r))r=hh(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function zA(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function XA(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 Lg=(r,e)=>{function t(n,...o){if(Tt(n),!DT)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let h=o[0];if(!h)throw new Error("nonce / iv required");r.varSizeNonce?Tt(h):Tt(h,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Tt(o[1]);let s=e(n,...o),a=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");Tt(p)}},c=!1;return{encrypt(h,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Tt(h),a(s.encrypt.length,p),s.encrypt(h,p)},decrypt(h,p){if(Tt(h),i&&h.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,p),s.decrypt(h,p)}}}return Object.assign(t,r),t};function Ug(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error("invalid output length, expected "+r+", got: "+e.length);if(t&&!LT(e))throw new Error("invalid output, must be aligned");return e}function WA(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(t>>o&i),a=Number(t&i),c=n?4:0,l=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+l,a,n)}function ZA(r,e,t){lh(t);let n=new Uint8Array(16),o=NT(n);return WA(o,0,BigInt(e),t),WA(o,8,BigInt(r),t),n}function LT(r){return r.byteOffset%4===0}function hh(r){return Uint8Array.from(r)}var JA=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),UT=JA("expand 16-byte k"),MT=JA("expand 32-byte k"),jT=Wn(UT),KT=Wn(MT);function ee(r,e){return r<<e|r>>>32-e}function Mg(r){return r.byteOffset%4===0}var dh=64,HT=16,QA=2**32-1,YA=new Uint32Array;function VT(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(dh),h=Wn(l),p=Mg(o)&&Mg(i),m=p?Wn(o):YA,y=p?Wn(i):YA;for(let g=0;g<c;s++){if(r(e,t,n,h,s,a),s>=QA)throw new Error("arx: counter overflow");let w=Math.min(dh,c-g);if(p&&w===dh){let b=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let E=0,D;E<HT;E++)D=b+E,y[D]=m[D]^h[E];g+=dh;continue}for(let b=0,E;b<w;b++)E=g+b,i[E]=o[E]^l[b];g+=w}}function jg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=zA({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return fh(o),fh(s),lh(i),lh(t),(a,c,l,h,p=0)=>{Tt(a),Tt(c),Tt(l);let m=l.length;if(h===void 0&&(h=new Uint8Array(m)),Tt(h),fh(p),p<0||p>=QA)throw new Error("arx: counter overflow");if(h.length<m)throw new Error(`arx: output (${h.length}) is shorter than data (${m})`);let y=[],g=a.length,w,b;if(g===32)y.push(w=hh(a)),b=KT;else if(g===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),b=jT,y.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Mg(c)||y.push(c=hh(c));let E=Wn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(b,E,Wn(c.subarray(0,16)),E),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let V=new Uint8Array(12);V.set(c,i?0:12-c.length),c=V,y.push(c)}let T=Wn(c);return VT(r,b,E,T,l,h,p,s),qn(...y),h}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Kg=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=ph(e),Tt(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),l=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let h=0;h<8;h++)this.pad[h]=xt(e,16+2*h)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],l=s[2],h=s[3],p=s[4],m=s[5],y=s[6],g=s[7],w=s[8],b=s[9],E=xt(e,t+0),D=xt(e,t+2),T=xt(e,t+4),V=xt(e,t+6),Y=xt(e,t+8),z=xt(e,t+10),te=xt(e,t+12),X=xt(e,t+14),B=i[0]+(E&8191),j=i[1]+((E>>>13|D<<3)&8191),q=i[2]+((D>>>10|T<<6)&8191),H=i[3]+((T>>>7|V<<9)&8191),x=i[4]+((V>>>4|Y<<12)&8191),v=i[5]+(Y>>>1&8191),_=i[6]+((Y>>>14|z<<2)&8191),P=i[7]+((z>>>11|te<<5)&8191),R=i[8]+((te>>>8|X<<8)&8191),U=i[9]+(X>>>5|o),k=0,L=k+B*a+j*(5*b)+q*(5*w)+H*(5*g)+x*(5*y);k=L>>>13,L&=8191,L+=v*(5*m)+_*(5*p)+P*(5*h)+R*(5*l)+U*(5*c),k+=L>>>13,L&=8191;let W=k+B*c+j*a+q*(5*b)+H*(5*w)+x*(5*g);k=W>>>13,W&=8191,W+=v*(5*y)+_*(5*m)+P*(5*p)+R*(5*h)+U*(5*l),k+=W>>>13,W&=8191;let N=k+B*l+j*c+q*a+H*(5*b)+x*(5*w);k=N>>>13,N&=8191,N+=v*(5*g)+_*(5*y)+P*(5*m)+R*(5*p)+U*(5*h),k+=N>>>13,N&=8191;let pe=k+B*h+j*l+q*c+H*a+x*(5*b);k=pe>>>13,pe&=8191,pe+=v*(5*w)+_*(5*g)+P*(5*y)+R*(5*m)+U*(5*p),k+=pe>>>13,pe&=8191;let me=k+B*p+j*h+q*l+H*c+x*a;k=me>>>13,me&=8191,me+=v*(5*b)+_*(5*w)+P*(5*g)+R*(5*y)+U*(5*m),k+=me>>>13,me&=8191;let Q=k+B*m+j*p+q*h+H*l+x*c;k=Q>>>13,Q&=8191,Q+=v*a+_*(5*b)+P*(5*w)+R*(5*g)+U*(5*y),k+=Q>>>13,Q&=8191;let xe=k+B*y+j*m+q*p+H*h+x*l;k=xe>>>13,xe&=8191,xe+=v*c+_*a+P*(5*b)+R*(5*w)+U*(5*g),k+=xe>>>13,xe&=8191;let Ee=k+B*g+j*y+q*m+H*p+x*h;k=Ee>>>13,Ee&=8191,Ee+=v*l+_*c+P*a+R*(5*b)+U*(5*w),k+=Ee>>>13,Ee&=8191;let Oe=k+B*w+j*g+q*y+H*m+x*p;k=Oe>>>13,Oe&=8191,Oe+=v*h+_*l+P*c+R*a+U*(5*b),k+=Oe>>>13,Oe&=8191;let ve=k+B*b+j*w+q*g+H*y+x*m;k=ve>>>13,ve&=8191,ve+=v*p+_*h+P*l+R*c+U*a,k+=ve>>>13,ve&=8191,k=(k<<2)+k|0,k=k+L|0,L=k&8191,k=k>>>13,W+=k,i[0]=L,i[1]=W,i[2]=N,i[3]=pe,i[4]=me,i[5]=Q,i[6]=xe,i[7]=Ee,i[8]=Oe,i[9]=ve}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;qn(n)}update(e){Rg(this),e=ph(e),Tt(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(){qn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Rg(this),GA(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 $T(r){let e=(n,o)=>r(o).update(ph(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var eS=$T(r=>new Kg(r));function nS(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],l=r[3],h=e[0],p=e[1],m=e[2],y=e[3],g=e[4],w=e[5],b=e[6],E=e[7],D=o,T=t[0],V=t[1],Y=t[2],z=s,te=a,X=c,B=l,j=h,q=p,H=m,x=y,v=g,_=w,P=b,R=E,U=D,k=T,L=V,W=Y;for(let pe=0;pe<i;pe+=2)z=z+j|0,U=ee(U^z,16),v=v+U|0,j=ee(j^v,12),z=z+j|0,U=ee(U^z,8),v=v+U|0,j=ee(j^v,7),te=te+q|0,k=ee(k^te,16),_=_+k|0,q=ee(q^_,12),te=te+q|0,k=ee(k^te,8),_=_+k|0,q=ee(q^_,7),X=X+H|0,L=ee(L^X,16),P=P+L|0,H=ee(H^P,12),X=X+H|0,L=ee(L^X,8),P=P+L|0,H=ee(H^P,7),B=B+x|0,W=ee(W^B,16),R=R+W|0,x=ee(x^R,12),B=B+x|0,W=ee(W^B,8),R=R+W|0,x=ee(x^R,7),z=z+q|0,W=ee(W^z,16),P=P+W|0,q=ee(q^P,12),z=z+q|0,W=ee(W^z,8),P=P+W|0,q=ee(q^P,7),te=te+H|0,U=ee(U^te,16),R=R+U|0,H=ee(H^R,12),te=te+H|0,U=ee(U^te,8),R=R+U|0,H=ee(H^R,7),X=X+x|0,k=ee(k^X,16),v=v+k|0,x=ee(x^v,12),X=X+x|0,k=ee(k^X,8),v=v+k|0,x=ee(x^v,7),B=B+j|0,L=ee(L^B,16),_=_+L|0,j=ee(j^_,12),B=B+j|0,L=ee(L^B,8),_=_+L|0,j=ee(j^_,7);let N=0;n[N++]=s+z|0,n[N++]=a+te|0,n[N++]=c+X|0,n[N++]=l+B|0,n[N++]=h+j|0,n[N++]=p+q|0,n[N++]=m+H|0,n[N++]=y+x|0,n[N++]=g+v|0,n[N++]=w+_|0,n[N++]=b+P|0,n[N++]=E+R|0,n[N++]=D+U|0,n[N++]=T+k|0,n[N++]=V+L|0,n[N++]=Y+W|0}function FT(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],l=e[1],h=e[2],p=e[3],m=e[4],y=e[5],g=e[6],w=e[7],b=t[0],E=t[1],D=t[2],T=t[3];for(let Y=0;Y<20;Y+=2)o=o+c|0,b=ee(b^o,16),m=m+b|0,c=ee(c^m,12),o=o+c|0,b=ee(b^o,8),m=m+b|0,c=ee(c^m,7),i=i+l|0,E=ee(E^i,16),y=y+E|0,l=ee(l^y,12),i=i+l|0,E=ee(E^i,8),y=y+E|0,l=ee(l^y,7),s=s+h|0,D=ee(D^s,16),g=g+D|0,h=ee(h^g,12),s=s+h|0,D=ee(D^s,8),g=g+D|0,h=ee(h^g,7),a=a+p|0,T=ee(T^a,16),w=w+T|0,p=ee(p^w,12),a=a+p|0,T=ee(T^a,8),w=w+T|0,p=ee(p^w,7),o=o+l|0,T=ee(T^o,16),g=g+T|0,l=ee(l^g,12),o=o+l|0,T=ee(T^o,8),g=g+T|0,l=ee(l^g,7),i=i+h|0,b=ee(b^i,16),w=w+b|0,h=ee(h^w,12),i=i+h|0,b=ee(b^i,8),w=w+b|0,h=ee(h^w,7),s=s+p|0,E=ee(E^s,16),m=m+E|0,p=ee(p^m,12),s=s+p|0,E=ee(E^s,8),m=m+E|0,p=ee(p^m,7),a=a+c|0,D=ee(D^a,16),y=y+D|0,c=ee(c^y,12),a=a+c|0,D=ee(D^a,8),y=y+D|0,c=ee(c^y,7);let V=0;n[V++]=o,n[V++]=i,n[V++]=s,n[V++]=a,n[V++]=b,n[V++]=E,n[V++]=D,n[V++]=T}var WT=jg(nS,{counterRight:!1,counterLength:4,allowShortKeys:!1}),qT=jg(nS,{counterRight:!1,counterLength:8,extendNonceFn:FT,allowShortKeys:!1});var GT=new Uint8Array(16),tS=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(GT.subarray(t))},zT=new Uint8Array(32);function rS(r,e,t,n,o){let i=r(e,t,zT),s=eS.create(i);o&&tS(s,o),tS(s,n);let a=ZA(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return qn(i,a),c}var oS=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Ug(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=rS(r,e,t,c,n);return s.set(l,a),qn(l),s},decrypt(i,s){s=Ug(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=rS(r,e,t,a,n);if(!XA(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),qn(l),s}}),Hg=Lg({blockSize:64,nonceLength:12,tagLength:16},oS(WT)),wZ=Lg({blockSize:64,nonceLength:24,tagLength:16},oS(qT));function sS(r,e,t){return Go(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Is(r,Qn(t),Qn(e))}var Vg=Uint8Array.from([0]),iS=Uint8Array.of();function aS(r,e,t,n=32){Go(r),qo(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=iS);let s=new Uint8Array(i*o),a=Is.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let h=0;h<i;h++)Vg[0]=h+1,c.update(h===0?iS:l).update(t).update(Vg).digestInto(l),s.set(l,o*h),a._cloneInto(c);return a.destroy(),c.destroy(),Er(l,Vg),s.slice(0,n)}var $g={hashSHA256(r){return co(r.subarray())},getHKDF(r,e){let t=sS(co,e,r),o=aS(co,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=Ya.utils.randomPrivateKey();return{publicKey:Ya.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Ya.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Ya.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Hg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Hg(n,e,t).decrypt(r.subarray(),o)}};var cS=$g;function uS(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 ka=r=>{let e=it(2);return e[0]=r>>8,e[1]=r,e};ka.bytes=2;var cl=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};cl.bytes=2;function lS(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 Fg(r,e){!e.enabled||!Ba||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local static keys."))}function Wg(r,e){!e.enabled||!Ba||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${ce(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${ce(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function fS(r,e){!e.enabled||!Ba||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote static public key.")}function qg(r,e){!e.enabled||!Ba||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Gg(r,e,t){!t.enabled||!Ba||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&ce(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&ce(e.k,"hex")}`))}var Pa=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var XT=0,ZT=4294967295,YT="Cipherstate has reached maximum n, a new handshake must be performed",mh=class{n;bytes;view;constructor(e=XT){this.n=e,this.bytes=ot(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,e,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>ZT)throw new Error(YT)}};var is=ot(0),Oa=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new mh(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}},zg=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=fe(t,"utf-8");this.h=JT(e,n),this.ck=this.h,this.cs=new Oa(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Oa(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new we(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,is);return[new Oa(this.crypto,e),new Oa(this.crypto,t)]}},Xg=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:l}=e;this.crypto=t,this.ss=new zg(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},ul=class extends Xg{writeMessageA(e){return new we(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new we(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new we(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new Pa(`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 Pa(`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 Pa(`handshake stage 2 validation fail: ${t.message}`)}}};function JT(r,e){if(e.length<=32){let t=ot(32);return t.set(e),t}else return r.hash(e)}var yh;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let i of t.webtransportCerthashes)n.uint32(10),n.bytes(i);if(t.streamMuxers!=null)for(let i of t.streamMuxers)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={webtransportCerthashes:[],streamMuxers:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&i.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new oc('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 oc('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=>Tr(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(yh||(yh={}));var ll;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),yh.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ot(0),identitySig:ot(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.identityKey=t.bytes();break}case 2:{i.identitySig=t.bytes();break}case 4:{i.extensions=yh.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Tr(t,r.codec()),r.decode=(t,n)=>Ir(t,r.codec(),n)})(ll||(ll={}));async function Zg(r,e,t){let n=await r.sign(pS(e));return ll.encode({identityKey:Jn(r.publicKey),identitySig:n,extensions:t})}async function Yg(r,e,t){try{let n=ll.decode(r),o=cc(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=pS(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new ml(n.message)}}function pS(r){let e=fe("noise-libp2p-static-key:");return r instanceof Uint8Array?kt([e,r],e.length+r.length):(r.prepend(e),r)}async function hS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,h=await Zg(i,a.publicKey,l),p=new ul({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Fg(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA(is),e),t.trace("Stage 0 - Initiator finished sending first message."),Wg(p.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let m=p.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),qg(p.re,t),fS(p.rs,t),t.trace("Initiator going to check remote's signature...");let y=await Yg(m,p.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(p.writeMessageC(h),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,w]=p.ss.split();return Gg(g,w,t),{payload:y,encrypt:b=>g.encryptWithAd(is,b),decrypt:(b,E)=>w.decryptWithAd(is,b,E)}}async function dS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,h=await Zg(i,a.publicKey,l),p=new ul({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Fg(p.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),p.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),qg(p.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(p.writeMessageB(h),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Wg(p.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let m=p.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let y=await Yg(m,p.rs,c),[g,w]=p.ss.split();return Gg(g,w,t),{payload:y,encrypt:b=>w.encryptWithAd(is,b),decrypt:(b,E)=>g.decryptWithAd(is,b,E)}}var yS=16;function gS(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let i=o+65519;i>n.length&&(i=n.length);let s;n instanceof Uint8Array?s=r.encrypt(n.subarray(o,i)):s=r.encrypt(n.sublist(o,i)),e?.encryptedPackets.increment(),yield new we(ka(s.byteLength),s)}}}function bS(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65535){let i=o+65535;if(i>n.length&&(i=n.length),i-yS<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-yS);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var gh=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e;let c=i??cS;this.crypto=uS(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?lS(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ot(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[cs]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=Tc(e,{lengthEncoder:ka,lengthDecoder:cl,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=cc(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:em(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new yl("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=Tc(e,{lengthEncoder:ka,lengthDecoder:cl,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=cc(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:em(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await hS({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async performHandshakeResponder(e,t,n,o){let i,s=o?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{i=await dS({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:s,webtransportCerthashes:[],...this.extensions}},o),this.metrics?.xxHandshakeSuccesses.increment()}catch(a){throw this.metrics?.xxHandshakeErrors.increment(),a}return i}async createSecureConnection(e,t){let[n,o]=KA(),i=e.unwrap();return await VA(n,gS(t,this.metrics),i,s=>ui(s,{lengthDecoder:cl}),bS(t,this.metrics),n),o}};function wS(r={}){return e=>new gh(e,r)}var Jg=Object.values($o).map(r=>r.decoder).reduce((r,e)=>r.or(e)),QT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function xS(r){return r?.match(QT)?.groups?.fingerprint}function Qg(r){let t=r.stringTuples().filter(n=>n[0]===Gw).map(n=>n[1])[0];if(t===void 0||t==="")throw new ke(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function eB(r){return vr.decode(Jg.decode(r))}function tB(r){let e=eB(Qg(r)),t=rB(e.code),n=e.digest.reduce((i,s)=>i+s.toString(16).padStart(2,"0"),""),o=n.match(/.{1,2}/g);if(o==null)throw new Of(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function vS(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Bt(ir.code,t);return Sn(`/certhash/${Vo.encode(n.bytes)}`)}function rB(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Df(r)}}function AS(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=tB(r);return{type:"answer",sdp:`v=0
|
13
|
+
o=- 0 0 IN IP${o} ${t}
|
14
14
|
s=-
|
15
15
|
t=0 0
|
16
16
|
a=ice-lite
|
17
17
|
m=application ${n} UDP/DTLS/SCTP webrtc-datachannel
|
18
|
-
c=IN IP${o
|
18
|
+
c=IN IP${o} ${t}
|
19
19
|
a=mid:0
|
20
20
|
a=ice-options:ice2
|
21
21
|
a=ice-ufrag:${e}
|
@@ -23,13 +23,13 @@ a=ice-pwd:${e}
|
|
23
23
|
a=fingerprint:${i}
|
24
24
|
a=setup:passive
|
25
25
|
a=sctp-port:5000
|
26
|
-
a=max-message-size:${
|
26
|
+
a=max-message-size:${Ls}
|
27
27
|
a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
|
28
28
|
a=end-of-candidates
|
29
|
-
`}}function
|
30
|
-
o=- 0 0 IN IP${o
|
29
|
+
`}}function SS(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
|
30
|
+
o=- 0 0 IN IP${o} ${t}
|
31
31
|
s=-
|
32
|
-
c=IN IP${o
|
32
|
+
c=IN IP${o} ${t}
|
33
33
|
t=0 0
|
34
34
|
a=ice-options:ice2,trickle
|
35
35
|
m=application ${n} UDP/DTLS/SCTP webrtc-datachannel
|
@@ -39,16 +39,16 @@ a=ice-ufrag:${e}
|
|
39
39
|
a=ice-pwd:${e}
|
40
40
|
a=fingerprint:sha-256 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
|
41
41
|
a=sctp-port:5000
|
42
|
-
a=max-message-size:${
|
42
|
+
a=max-message-size:${Ls}
|
43
43
|
a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
|
44
44
|
a=end-of-candidates
|
45
|
-
`}}function
|
45
|
+
`}}function e0(r,e){if(r.sdp===void 0)throw new ke("Can't munge a missing SDP");let t=r.sdp.includes(`\r
|
46
46
|
`)?`\r
|
47
47
|
`:`
|
48
|
-
`;
|
48
|
+
`;return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
|
49
49
|
a=ice-ufrag:`+e+t).replace(/\na=ice-pwd:[^\n]*\n/,`
|
50
|
-
a=ice-pwd:`+e+t)
|
51
|
-
`)}var
|
50
|
+
a=ice-pwd:`+e+t),r}var t0=fe("libp2p-webrtc-noise:");function _S(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=fe(n,"hex"),i=Bt(ir.code,o),s=Jg.decode(Qg(e)),a=t0.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?kt([t0,s,i.bytes],a):kt([t0,i.bytes,s],a)}var nB=Ec?"iceconnectionstatechange":"connectionstatechange";async function CS(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let p=await r.createOffer();t.log.trace("client created local offer %s",p.sdp);let m=e0(p,e);t.log.trace("client setting local offer %s",m.sdp),await r.setLocalDescription(m);let y=AS(t.remoteAddr,e);t.log.trace("client setting server description %s",y.sdp),await r.setRemoteDescription(y)}else{let p=SS(t.remoteAddr,e);t.log.trace("server setting client %s %s",p.type,p.sdp),await r.setRemoteDescription(p),t.log.trace("server creating local answer");let m=await r.createAnswer();t.log.trace("server created local answer");let y=e0(m,e);t.log.trace("server setting local description %s",m.sdp),await r.setLocalDescription(y)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await Ic(n,"open",t.signal)),t.log.trace("%s handshake channel opened",t.role),t.role==="server"){let p=r.remoteFingerprint()?.value??"";t.remoteAddr=t.remoteAddr.encapsulate(vS(p))}let o=xS(r.localDescription?.sdp);if(o==null)throw new fo("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=_S(o,t.remoteAddr,t.role),s=wS({prologueBytes:i})(t),a=Ks({channel:n,direction:"outbound",handshake:!0,log:t.log,...t.dataChannel??{}}),c=new ai(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(nB,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":c.close().catch(p=>{t.log.error("error closing connection",p),c.abort(p)});break;default:break}}),t.events?.increment({peer_connection:!0});let l=new lo(t,{peerConnection:r,metrics:t.events,dataChannelOptions:t.dataChannel});if(t.role==="client")return t.log.trace("%s secure inbound",t.role),await s.secureInbound(a,{remotePeer:t.remotePeerId,signal:t.signal,skipStreamMuxerNegotiation:!0}),t.log.trace("%s upgrade outbound",t.role),await t.upgrader.upgradeOutbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:l,signal:t.signal});t.log.trace("%s secure outbound",t.role);let h=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal,skipStreamMuxerNegotiation:!0});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${h.remotePeer}`),t.log.trace("%s upgrade inbound",t.role),await t.upgrader.upgradeInbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:l,signal:t.signal})}catch(o){throw n.close(),o}}async function IS(r,e,t,n){n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t=="function"?await t():t;return new RTCPeerConnection({...o??{},certificates:[n]})}async function TS(r){let e=await Yl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ce(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
|
51
|
+
`)}var bh=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 Xn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new ke("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[dl]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[cs]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getPeerId();o!=null&&(n=Jl(o));let i=px(),s=await IS("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await CS(s,i,{role:"client",log:this.log,logger:this.components.logger,metrics:this.components.metrics,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeerId:n,privateKey:this.components.privateKey})}catch(a){throw s.close(),a}}createListener(e){if(this.certificate==null)throw new Sl;return new uh(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(Hw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(oB(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 TS(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??tx,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Ko;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 hw("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 al(this.init.certificateDatastoreKey??ex),i=await Yl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Ko;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??Cm)-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:Vo.encode((await ir.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new Ta(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??Cm);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Ko;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 Ko;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??rx));n.setMilliseconds(0),o.setMilliseconds(0);let i=await ah.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 _a(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,fe(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 oB(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function iB(r){return e=>new bh(e,r)}function sB(r){return e=>new Mf(e,r)}return $S(aB);})();
|
52
52
|
/*! Bundled license information:
|
53
53
|
|
54
54
|
reflect-metadata/Reflect.js:
|