@libp2p/webrtc 5.2.15 → 5.2.16-ae595d8db

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.
Files changed (28) hide show
  1. package/dist/index.min.js +14 -14
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/private-to-private/listener.d.ts +3 -2
  4. package/dist/src/private-to-private/listener.d.ts.map +1 -1
  5. package/dist/src/private-to-private/listener.js +1 -1
  6. package/dist/src/private-to-private/listener.js.map +1 -1
  7. package/dist/src/private-to-private/transport.d.ts +2 -1
  8. package/dist/src/private-to-private/transport.d.ts.map +1 -1
  9. package/dist/src/private-to-private/transport.js +2 -1
  10. package/dist/src/private-to-private/transport.js.map +1 -1
  11. package/dist/src/private-to-public/listener.browser.d.ts +1 -1
  12. package/dist/src/private-to-public/listener.browser.d.ts.map +1 -1
  13. package/dist/src/private-to-public/listener.browser.js +1 -1
  14. package/dist/src/private-to-public/listener.browser.js.map +1 -1
  15. package/dist/src/private-to-public/listener.d.ts +3 -2
  16. package/dist/src/private-to-public/listener.d.ts.map +1 -1
  17. package/dist/src/private-to-public/listener.js +2 -1
  18. package/dist/src/private-to-public/listener.js.map +1 -1
  19. package/dist/src/private-to-public/transport.d.ts.map +1 -1
  20. package/dist/src/private-to-public/transport.js +2 -1
  21. package/dist/src/private-to-public/transport.js.map +1 -1
  22. package/package.json +13 -12
  23. package/src/private-to-private/listener.ts +3 -2
  24. package/src/private-to-private/transport.ts +4 -2
  25. package/src/private-to-public/listener.browser.ts +1 -1
  26. package/src/private-to-public/listener.ts +4 -2
  27. package/src/private-to-public/transport.ts +4 -2
  28. package/dist/typedoc-urls.json +0 -14
package/dist/index.min.js CHANGED
@@ -1,15 +1,15 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PWebrtc = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PWebrtc=(()=>{var mA=Object.create;var Au=Object.defineProperty;var yA=Object.getOwnPropertyDescriptor;var gA=Object.getOwnPropertyNames;var wA=Object.getPrototypeOf,xA=Object.prototype.hasOwnProperty;var Sp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),bt=(r,e)=>{for(var t in e)Au(r,t,{get:e[t],enumerable:!0})},Zy=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of gA(e))!xA.call(r,o)&&o!==t&&Au(r,o,{get:()=>e[o],enumerable:!(n=yA(e,o))||n.enumerable});return r};var Lr=(r,e,t)=>(t=r!=null?mA(wA(r)):{},Zy(e||!r||!r.__esModule?Au(t,"default",{value:r,enumerable:!0}):t,r)),bA=r=>Zy(Au({},"__esModule",{value:!0}),r);var rx=Sp(()=>{var tx;(function(r){(function(e){var t=typeof globalThis=="object"||typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:a(),n=o(r);typeof t.Reflect<"u"&&(n=o(t.Reflect,n)),e(n,t),typeof t.Reflect>"u"&&(t.Reflect=r);function o(c,f){return function(h,p){Object.defineProperty(c,h,{configurable:!0,writable:!0,value:p}),f&&f(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,f=!a&&!c,h={create:a?function(){return Ap(Object.create(null))}:c?function(){return Ap({__proto__:null})}:function(){return Ap({})},has:f?function(x,E){return n.call(x,E)}:function(x,E){return E in x},get:f?function(x,E){return n.call(x,E)?x[E]:void 0}:function(x,E){return x[E]}},p=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:lA(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:fA(),g=typeof WeakMap=="function"?WeakMap:pA(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,S=aA(),O=cA(S);function Y(x,E,B,W){if(I(B)){if(!ut(x))throw new TypeError;if(!et(E))throw new TypeError;return G(x,E)}else{if(!ut(x))throw new TypeError;if(!Q(E))throw new TypeError;if(!Q(W)&&!I(W)&&!re(W))throw new TypeError;return re(W)&&(W=void 0),B=ke(B),F(x,E,B,W)}}e("decorate",Y);function T(x,E){function B(W,ae){if(!Q(W))throw new TypeError;if(!I(ae)&&!Tt(ae))throw new TypeError;P(x,E,W,ae)}return B}e("metadata",T);function b(x,E,B,W){if(!Q(B))throw new TypeError;return I(W)||(W=ke(W)),P(x,E,B,W)}e("defineMetadata",b);function D(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),ie(x,E,B)}e("hasMetadata",D);function V(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),k(x,E,B)}e("hasOwnMetadata",V);function N(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),R(x,E,B)}e("getMetadata",N);function U(x,E,B){if(!Q(E))throw new TypeError;return I(B)||(B=ke(B)),K(x,E,B)}e("getOwnMetadata",U);function $(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),y(x,E)}e("getMetadataKeys",$);function X(x,E){if(!Q(x))throw new TypeError;return I(E)||(E=ke(E)),C(x,E)}e("getOwnMetadataKeys",X);function M(x,E,B){if(!Q(E))throw new TypeError;if(I(B)||(B=ke(B)),!Q(E))throw new TypeError;I(B)||(B=ke(B));var W=aa(E,B,!1);return I(W)?!1:W.OrdinaryDeleteMetadata(x,E,B)}e("deleteMetadata",M);function G(x,E){for(var B=x.length-1;B>=0;--B){var W=x[B],ae=W(E);if(!I(ae)&&!re(ae)){if(!et(ae))throw new TypeError;E=ae}}return E}function F(x,E,B,W){for(var ae=x.length-1;ae>=0;--ae){var Ge=x[ae],tt=Ge(E,B,W);if(!I(tt)&&!re(tt)){if(!Q(tt))throw new TypeError;W=tt}}return W}function ie(x,E,B){var W=k(x,E,B);if(W)return!0;var ae=sa(E);return re(ae)?!1:ie(x,ae,B)}function k(x,E,B){var W=aa(E,B,!1);return I(W)?!1:Ee(W.OrdinaryHasOwnMetadata(x,E,B))}function R(x,E,B){var W=k(x,E,B);if(W)return K(x,E,B);var ae=sa(E);if(!re(ae))return R(x,ae,B)}function K(x,E,B){var W=aa(E,B,!1);if(!I(W))return W.OrdinaryGetOwnMetadata(x,E,B)}function P(x,E,B,W){var ae=aa(B,W,!0);ae.OrdinaryDefineOwnMetadata(x,E,B,W)}function y(x,E){var B=C(x,E),W=sa(x);if(W===null)return B;var ae=y(W,E);if(ae.length<=0)return B;if(B.length<=0)return ae;for(var Ge=new v,tt=[],we=0,z=B;we<z.length;we++){var J=z[we],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}for(var ne=0,xe=ae;ne<xe.length;ne++){var J=xe[ne],te=Ge.has(J);te||(Ge.add(J),tt.push(J))}return tt}function C(x,E){var B=aa(x,E,!1);return B?B.OrdinaryOwnMetadataKeys(x,E):[]}function L(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function I(x){return x===void 0}function re(x){return x===null}function le(x){return typeof x=="symbol"}function Q(x){return typeof x=="object"?x!==null:typeof x=="function"}function pe(x,E){switch(L(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var B=E===3?"string":E===5?"number":"default",W=Un(x,i);if(W!==void 0){var ae=W.call(x,B);if(Q(ae))throw new TypeError;return ae}return he(x,B==="default"?"number":B)}function he(x,E){if(E==="string"){var B=x.toString;if(Ue(B)){var W=B.call(x);if(!Q(W))return W}var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}}else{var ae=x.valueOf;if(Ue(ae)){var W=ae.call(x);if(!Q(W))return W}var Ge=x.toString;if(Ue(Ge)){var W=Ge.call(x);if(!Q(W))return W}}throw new TypeError}function Ee(x){return!!x}function _e(x){return""+x}function ke(x){var E=pe(x,3);return le(E)?E:_e(E)}function ut(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function Ue(x){return typeof x=="function"}function et(x){return typeof x=="function"}function Tt(x){switch(L(x)){case 3:return!0;case 4:return!0;default:return!1}}function Bt(x,E){return x===E||x!==x&&E!==E}function Un(x,E){var B=x[E];if(B!=null){if(!Ue(B))throw new TypeError;return B}}function ia(x){var E=Un(x,s);if(!Ue(E))throw new TypeError;var B=E.call(x);if(!Q(B))throw new TypeError;return B}function xu(x){return x.value}function bu(x){var E=x.next();return E.done?!1:E}function vu(x){var E=x.return;E&&E.call(x)}function sa(x){var E=Object.getPrototypeOf(x);if(typeof x!="function"||x===p||E!==p)return E;var B=x.prototype,W=B&&Object.getPrototypeOf(B);if(W==null||W===Object.prototype)return E;var ae=W.constructor;return typeof ae!="function"||ae===x?E:ae}function sA(){var x;!I(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=uA(t.Reflect));var E,B,W,ae=new g,Ge={registerProvider:tt,getProvider:z,setProvider:te};return Ge;function tt(ne){if(!Object.isExtensible(Ge))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===ne:break;case I(E):E=ne;break;case E===ne:break;case I(B):B=ne;break;case B===ne:break;default:W===void 0&&(W=new v),W.add(ne);break}}function we(ne,xe){if(!I(E)){if(E.isProviderFor(ne,xe))return E;if(!I(B)){if(B.isProviderFor(ne,xe))return E;if(!I(W))for(var je=ia(W);;){var ze=bu(je);if(!ze)return;var mr=xu(ze);if(mr.isProviderFor(ne,xe))return vu(je),mr}}}if(!I(x)&&x.isProviderFor(ne,xe))return x}function z(ne,xe){var je=ae.get(ne),ze;return I(je)||(ze=je.get(xe)),I(ze)&&(ze=we(ne,xe),I(ze)||(I(je)&&(je=new m,ae.set(ne,je)),je.set(xe,ze))),ze}function J(ne){if(I(ne))throw new TypeError;return E===ne||B===ne||!I(W)&&W.has(ne)}function te(ne,xe,je){if(!J(je))throw new Error("Metadata provider not registered.");var ze=z(ne,xe);if(ze!==je){if(!I(ze))return!1;var mr=ae.get(ne);I(mr)&&(mr=new m,ae.set(ne,mr)),mr.set(xe,je)}return!0}}function aA(){var x;return!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[w]),I(x)&&(x=sA()),!I(w)&&Q(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function cA(x){var E=new g,B={isProviderFor:function(J,te){var ne=E.get(J);return I(ne)?!1:ne.has(te)},OrdinaryDefineOwnMetadata:tt,OrdinaryHasOwnMetadata:ae,OrdinaryGetOwnMetadata:Ge,OrdinaryOwnMetadataKeys:we,OrdinaryDeleteMetadata:z};return S.registerProvider(B),B;function W(J,te,ne){var xe=E.get(J),je=!1;if(I(xe)){if(!ne)return;xe=new m,E.set(J,xe),je=!0}var ze=xe.get(te);if(I(ze)){if(!ne)return;if(ze=new m,xe.set(te,ze),!x.setProvider(J,te,B))throw xe.delete(te),je&&E.delete(J),new Error("Wrong provider for target.")}return ze}function ae(J,te,ne){var xe=W(te,ne,!1);return I(xe)?!1:Ee(xe.has(J))}function Ge(J,te,ne){var xe=W(te,ne,!1);if(!I(xe))return xe.get(J)}function tt(J,te,ne,xe){var je=W(ne,xe,!0);je.set(J,te)}function we(J,te){var ne=[],xe=W(J,te,!1);if(I(xe))return ne;for(var je=xe.keys(),ze=ia(je),mr=0;;){var Yy=bu(ze);if(!Yy)return ne.length=mr,ne;var hA=xu(Yy);try{ne[mr]=hA}catch(dA){try{vu(ze)}finally{throw dA}}mr++}}function z(J,te,ne){var xe=W(te,ne,!1);if(I(xe)||!xe.delete(J))return!1;if(xe.size===0){var je=E.get(te);I(je)||(je.delete(ne),je.size===0&&E.delete(je))}return!0}}function uA(x){var E=x.defineMetadata,B=x.hasOwnMetadata,W=x.getOwnMetadata,ae=x.getOwnMetadataKeys,Ge=x.deleteMetadata,tt=new g,we={isProviderFor:function(z,J){var te=tt.get(z);return!I(te)&&te.has(J)?!0:ae(z,J).length?(I(te)&&(te=new v,tt.set(z,te)),te.add(J),!0):!1},OrdinaryDefineOwnMetadata:E,OrdinaryHasOwnMetadata:B,OrdinaryGetOwnMetadata:W,OrdinaryOwnMetadataKeys:ae,OrdinaryDeleteMetadata:Ge};return we}function aa(x,E,B){var W=S.getProvider(x,E);if(!I(W))return W;if(B){if(S.setProvider(x,E,O))return O;throw new Error("Illegal state.")}}function lA(){var x={},E=[],B=function(){function we(z,J,te){this._index=0,this._keys=z,this._values=J,this._selector=te}return we.prototype["@@iterator"]=function(){return this},we.prototype[s]=function(){return this},we.prototype.next=function(){var z=this._index;if(z>=0&&z<this._keys.length){var J=this._selector(this._keys[z],this._values[z]);return z+1>=this._keys.length?(this._index=-1,this._keys=E,this._values=E):this._index++,{value:J,done:!1}}return{value:void 0,done:!0}},we.prototype.throw=function(z){throw this._index>=0&&(this._index=-1,this._keys=E,this._values=E),z},we.prototype.return=function(z){return this._index>=0&&(this._index=-1,this._keys=E,this._values=E),{value:z,done:!0}},we}(),W=function(){function we(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(we.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),we.prototype.has=function(z){return this._find(z,!1)>=0},we.prototype.get=function(z){var J=this._find(z,!1);return J>=0?this._values[J]:void 0},we.prototype.set=function(z,J){var te=this._find(z,!0);return this._values[te]=J,this},we.prototype.delete=function(z){var J=this._find(z,!1);if(J>=0){for(var te=this._keys.length,ne=J+1;ne<te;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Bt(z,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},we.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},we.prototype.keys=function(){return new B(this._keys,this._values,ae)},we.prototype.values=function(){return new B(this._keys,this._values,Ge)},we.prototype.entries=function(){return new B(this._keys,this._values,tt)},we.prototype["@@iterator"]=function(){return this.entries()},we.prototype[s]=function(){return this.entries()},we.prototype._find=function(z,J){if(!Bt(this._cacheKey,z)){this._cacheIndex=-1;for(var te=0;te<this._keys.length;te++)if(Bt(this._keys[te],z)){this._cacheIndex=te;break}}return this._cacheIndex<0&&J&&(this._cacheIndex=this._keys.length,this._keys.push(z),this._values.push(void 0)),this._cacheIndex},we}();return W;function ae(we,z){return we}function Ge(we,z){return z}function tt(we,z){return[we,z]}}function fA(){var x=function(){function E(){this._map=new m}return Object.defineProperty(E.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),E.prototype.has=function(B){return this._map.has(B)},E.prototype.add=function(B){return this._map.set(B,B),this},E.prototype.delete=function(B){return this._map.delete(B)},E.prototype.clear=function(){this._map.clear()},E.prototype.keys=function(){return this._map.keys()},E.prototype.values=function(){return this._map.keys()},E.prototype.entries=function(){return this._map.entries()},E.prototype["@@iterator"]=function(){return this.keys()},E.prototype[s]=function(){return this.keys()},E}();return x}function pA(){var x=16,E=h.create(),B=W();return function(){function z(){this._key=W()}return z.prototype.has=function(J){var te=ae(J,!1);return te!==void 0?h.has(te,this._key):!1},z.prototype.get=function(J){var te=ae(J,!1);return te!==void 0?h.get(te,this._key):void 0},z.prototype.set=function(J,te){var ne=ae(J,!0);return ne[this._key]=te,this},z.prototype.delete=function(J){var te=ae(J,!1);return te!==void 0?delete te[this._key]:!1},z.prototype.clear=function(){this._key=W()},z}();function W(){var z;do z="@@WeakMap@@"+we();while(h.has(E,z));return E[z]=!0,z}function ae(z,J){if(!n.call(z,B)){if(!J)return;Object.defineProperty(z,B,{value:h.create()})}return z[B]}function Ge(z,J){for(var te=0;te<J;++te)z[te]=Math.random()*255|0;return z}function tt(z){if(typeof Uint8Array=="function"){var J=new Uint8Array(z);return typeof crypto<"u"?crypto.getRandomValues(J):typeof msCrypto<"u"?msCrypto.getRandomValues(J):Ge(J,z),J}return Ge(new Array(z),z)}function we(){var z=tt(x);z[6]=z[6]&79|64,z[8]=z[8]&191|128;for(var J="",te=0;te<x;++te){var ne=z[te];(te===4||te===6||te===8)&&(J+="-"),ne<16&&(J+="0"),J+=ne.toString(16).toLowerCase()}return J}}function Ap(x){return x.__=void 0,delete x.__,x}})})(tx||(tx={}))});var gn=Sp(ms=>{"use strict";var F2="[object ArrayBuffer]",yn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===F2}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}},Rd="string",W2=/^[0-9a-f\s]+$/i,q2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,G2=/^[a-zA-Z0-9-_]+$/,Vl=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n.buffer}static toString(e){let t=yn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},or=class{static toString(e,t=!1){let n=yn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},$l=class r{static isHex(e){return typeof e===Rd&&W2.test(e)}static isBase64(e){return typeof e===Rd&&q2.test(e)}static isBase64Url(e){return typeof e===Rd&&G2.test(e)}static ToString(e,t="utf8"){let n=yn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return or.toString(n,!0);case"utf16":case"utf16be":return or.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return or.fromString(e,!0);case"utf16":case"utf16be":return or.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=yn.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Vl.fromString(e);case"utf16":case"utf16be":return or.fromString(e);case"utf16le":case"usc2":return or.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Vl.toString(e);case"utf16":case"utf16be":return or.toString(e);case"utf16le":case"usc2":return or.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=yn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=yn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return or.toString(e,t)}static FromUtf16String(e,t=!1){return or.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};$l.DEFAULT_UTF8_ENCODING="utf8";function z2(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 X2(...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 Y2(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}ms.BufferSourceConverter=yn;ms.Convert=$l;ms.assign=z2;ms.combine=X2;ms.isEqual=Y2});var Yb=Sp((H7,jf)=>{var kb,Pb,Nb,Ob,Rb,Db,Lb,Ub,jb,Uf,Hm,Mb,Kb,Ws,Hb,Vb,$b,Fb,Wb,qb,Gb,zb,Xb;(function(r){var e=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(n){r(t(e,t(n)))}):typeof jf=="object"&&typeof jf.exports=="object"?r(t(e,t(jf.exports))):r(t(e));function t(n,o){return n!==e&&(typeof Object.create=="function"?Object.defineProperty(n,"__esModule",{value:!0}):n.__esModule=!0),function(i,s){return n[i]=o?o(i,s):s}}})(function(r){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])};kb=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Pb=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},Nb=function(t,n){var o={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)n.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(o[i[s]]=t[i[s]]);return o},Ob=function(t,n,o,i){var s=arguments.length,a=s<3?n:i===null?i=Object.getOwnPropertyDescriptor(n,o):i,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,n,o,i);else for(var f=t.length-1;f>=0;f--)(c=t[f])&&(a=(s<3?c(a):s>3?c(n,o,a):c(n,o))||a);return s>3&&a&&Object.defineProperty(n,o,a),a},Rb=function(t,n){return function(o,i){n(o,i,t)}},Db=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Lb=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function f(m){try{p(i.next(m))}catch(v){c(v)}}function h(m){try{p(i.throw(m))}catch(v){c(v)}}function p(m){m.done?a(m.value):s(m.value).then(f,h)}p((i=i.apply(t,n||[])).next())})},Ub=function(t,n){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,s,a,c;return c={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function f(p){return function(m){return h([p,m])}}function h(p){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=p[0]&2?s.return:p[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,p[1])).done)return a;switch(s=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return o.label++,{value:p[1],done:!1};case 5:o.label++,s=p[1],p=[0];continue;case 7:p=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){o=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]<a[3])){o.label=p[1];break}if(p[0]===6&&o.label<a[1]){o.label=a[1],a=p;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(p);break}a[2]&&o.ops.pop(),o.trys.pop();continue}p=n.call(t,o)}catch(m){p=[6,m],s=0}finally{i=a=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},Xb=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},jb=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Uf=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.")},Hm=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(f){c={error:f}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},Mb=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Hm(arguments[n]));return t},Kb=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,f=a.length;c<f;c++,s++)i[s]=a[c];return i},Ws=function(t){return this instanceof Ws?(this.v=t,this):new Ws(t)},Hb=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(g){i[g]&&(s[g]=function(w){return new Promise(function(S,O){a.push([g,w,S,O])>1||f(g,w)})})}function f(g,w){try{h(i[g](w))}catch(S){v(a[0][3],S)}}function h(g){g.value instanceof Ws?Promise.resolve(g.value.v).then(p,m):v(a[0][2],g)}function p(g){f("next",g)}function m(g){f("throw",g)}function v(g,w){g(w),a.shift(),a.length&&f(a[0][0],a[0][1])}},Vb=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:Ws(t[s](c)),done:s==="return"}:a?a(c):c}:a}},$b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],o;return n?n.call(t):(t=typeof Uf=="function"?Uf(t):t[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(a){o[a]=t[a]&&function(c){return new Promise(function(f,h){c=t[a](c),s(f,h,c.done,c.value)})}}function s(a,c,f,h){Promise.resolve(h).then(function(p){a({value:p,done:f})},c)}},Fb=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},Wb=function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var o in t)Object.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n.default=t,n},qb=function(t){return t&&t.__esModule?t:{default:t}},Gb=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},zb=function(t,n,o){if(!n.has(t))throw new TypeError("attempted to set private field on non-instance");return n.set(t,o),o},r("__extends",kb),r("__assign",Pb),r("__rest",Nb),r("__decorate",Ob),r("__param",Rb),r("__metadata",Db),r("__awaiter",Lb),r("__generator",Ub),r("__exportStar",jb),r("__createBinding",Xb),r("__values",Uf),r("__read",Hm),r("__spread",Mb),r("__spreadArrays",Kb),r("__await",Ws),r("__asyncGenerator",Hb),r("__asyncDelegator",Vb),r("__asyncValues",$b),r("__makeTemplateObject",Fb),r("__importStar",Wb),r("__importDefault",qb),r("__classPrivateFieldGet",Gb),r("__classPrivateFieldSet",zb)})});var QC={};bt(QC,{webRTC:()=>JC,webRTCDirect:()=>ZC});var Ep=Symbol.for("@libp2p/peer-id");var Su=Symbol.for("@libp2p/transport");var Jy;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Jy||(Jy={}));var Eu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},_u=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Fi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ca=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Cu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Iu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Io=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},To=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Tu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Bu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ku=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Pu=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Nu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var jn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Mn=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 Wi=Symbol.for("@libp2p/service-capabilities"),Qy=Symbol.for("@libp2p/service-dependencies");var Bp={};bt(Bp,{base58btc:()=>Pe,base58flickr:()=>IA});var II=new Uint8Array(0);function eg(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 tg(r){return new TextEncoder().encode(r)}function rg(r){return new TextDecoder().decode(r)}function vA(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),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,S=0,O=0,Y=g.length;O!==Y&&g[O]===0;)O++,w++;for(var T=(Y-O)*h+1>>>0,b=new Uint8Array(T);O!==Y;){for(var D=g[O],V=0,N=T-1;(D!==0||V<S)&&N!==-1;N--,V++)D+=256*b[N]>>>0,b[N]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");S=V,O++}for(var U=T-S;U!==T&&b[U]===0;)U++;for(var $=c.repeat(w);U<T;++U)$+=r.charAt(b[U]);return $}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 S=0,O=0;g[w]===c;)S++,w++;for(var Y=(g.length-w)*f+1>>>0,T=new Uint8Array(Y);g[w];){var b=t[g.charCodeAt(w)];if(b===255)return;for(var D=0,V=Y-1;(b!==0||D<O)&&V!==-1;V--,D++)b+=a*T[V]>>>0,T[V]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");O=D,w++}if(g[w]!==" "){for(var N=Y-O;N!==Y&&T[N]===0;)N++;for(var U=new Uint8Array(S+(Y-N)),$=S;N!==Y;)U[$++]=T[N++];return U}}}function v(g){var w=m(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:m,decode:v}}var AA=vA,SA=AA,og=SA;var _p=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")}},Cp=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 ig(this,e)}},Ip=class{decoders;constructor(e){this.decoders=e}or(e){return ig(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 ig(r,e){return new Ip({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Tp=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 _p(e,t,n),this.decoder=new Cp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function qi({name:r,prefix:e,encode:t,decode:n}){return new Tp(r,e,t,n)}function Kn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=og(t,r);return qi({prefix:e,name:r,encode:n,decode:i=>sn(o(i))})}function EA(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let h=e[r[f]];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 _A(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 CA(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function $e({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=CA(n);return qi({prefix:e,name:r,encode(i){return _A(i,n,t)},decode(i){return EA(i,o,t,r)}})}var Pe=Kn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),IA=Kn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kp={};bt(kp,{base32:()=>an,base32hex:()=>PA,base32hexpad:()=>OA,base32hexpadupper:()=>RA,base32hexupper:()=>NA,base32pad:()=>BA,base32padupper:()=>kA,base32upper:()=>TA,base32z:()=>DA});var an=$e({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),TA=$e({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),BA=$e({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kA=$e({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),PA=$e({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),NA=$e({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),OA=$e({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),RA=$e({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),DA=$e({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pp={};bt(Pp,{base36:()=>ua,base36upper:()=>LA});var ua=Kn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),LA=Kn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var er={};bt(er,{Digest:()=>Bo,create:()=>vt,decode:()=>Hn,equals:()=>Op,hasCode:()=>tS});var UA=cg,sg=128,jA=127,MA=~jA,KA=Math.pow(2,31);function cg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=KA;)e[t++]=r&255|sg,r/=128;for(;r&MA;)e[t++]=r&255|sg,r>>>=7;return e[t]=r|0,cg.bytes=t-n+1,e}var HA=Np,VA=128,ag=127;function Np(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Np.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&ag)<<o:(s&ag)*Math.pow(2,o),o+=7}while(s>=VA);return Np.bytes=i-n,t}var $A=Math.pow(2,7),FA=Math.pow(2,14),WA=Math.pow(2,21),qA=Math.pow(2,28),GA=Math.pow(2,35),zA=Math.pow(2,42),XA=Math.pow(2,49),YA=Math.pow(2,56),ZA=Math.pow(2,63),JA=function(r){return r<$A?1:r<FA?2:r<WA?3:r<qA?4:r<GA?5:r<zA?6:r<XA?7:r<YA?8:r<ZA?9:10},QA={encode:UA,decode:HA,encodingLength:JA},eS=QA,la=eS;function fa(r,e=0){return[la.decode(r,e),la.decode.bytes]}function Gi(r,e,t=0){return la.encode(r,e,t),e}function zi(r){return la.encodingLength(r)}function vt(r,e){let t=e.byteLength,n=zi(r),o=n+zi(t),i=new Uint8Array(o+t);return Gi(r,i,0),Gi(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function Hn(r){let e=sn(r),[t,n]=fa(e),[o,i]=fa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Op(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&eg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function tS(r,e){return r.code===e}function ug(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return nS(t,Rp(r),e??Pe.encoder);default:return oS(t,Rp(r),e??an.encoder)}}var lg=new WeakMap;function Rp(r){let e=lg.get(r);if(e==null){let t=new Map;return lg.set(r,t),t}return e}var Xe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==pa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==iS)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=vt(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&&Op(e.multihash,n.multihash)}toString(e){return ug(this,e)}toJSON(){return{"/":ug(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??fg(n,o,i.bytes))}else if(t[sS]===!0){let{version:n,multihash:o,code:i}=t,s=Hn(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!==pa)throw new Error(`Version 0 CID must use dag-pb (code: ${pa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=fg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,pa,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 Bo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[p,m]=fa(e.subarray(t));return t+=m,p},o=n(),i=pa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),f=t+c,h=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:h,size:f}}static parse(e,t){let[n,o]=rS(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 Rp(i).set(n,e),i}};function rS(r,e){switch(r[0]){case"Q":{let t=e??Pe;return[Pe.prefix,t.decode(`${Pe.prefix}${r}`)]}case Pe.prefix:{let t=e??Pe;return[Pe.prefix,t.decode(r)]}case an.prefix:{let t=e??an;return[an.prefix,t.decode(r)]}case ua.prefix:{let t=e??ua;return[ua.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 nS(r,e,t){let{prefix:n}=t;if(n!==Pe.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function oS(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var pa=112,iS=18;function fg(r,e,t){let n=zi(r),o=n+zi(e),i=new Uint8Array(o+t.byteLength);return Gi(r,i,0),Gi(e,i,n),i.set(t,o),i}var sS=Symbol.for("@ipld/js-cid/CID");var Dp={};bt(Dp,{identity:()=>yr});var pg=0,aS="identity",hg=sn;function cS(r){return vt(pg,hg(r))}var yr={code:pg,name:aS,encode:hg,digest:cS};function Fe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function rt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function ot(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=nt(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var mg=Symbol.for("@achingbrain/uint8arraylist");function dg(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 Ru(r){return!!r?.[mg]}var be=class r{bufs;length;[mg]=!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(Ru(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(Ru(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=dg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=dg(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(Ru(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 ot(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:ot(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let f=e>=a&&e<c,h=t>a&&t<=c;if(f&&h){if(e===a&&t===c){n.push(s);break}let p=e-a;n.push(s.subarray(p,p+(t-e)));break}if(f){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(!Ru(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,f=n.byteLength-1,h;for(let p=t;p<=c;p+=h){h=0;for(let m=f;m>=0;m--){let v=this.get(p+m);if(n[m]!==v){h=Math.max(1,m-a[v]);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=nt(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=rt(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=rt(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=rt(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=nt(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=rt(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=rt(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=rt(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=rt(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=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Fe(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,i)=>o+i.byteLength,0)),n.length=t,n}};var Lp={};bt(Lp,{base10:()=>lS});var lS=Kn({prefix:"9",name:"base10",alphabet:"0123456789"});var Up={};bt(Up,{base16:()=>fS,base16upper:()=>pS});var fS=$e({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pS=$e({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jp={};bt(jp,{base2:()=>hS});var hS=$e({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mp={};bt(Mp,{base256emoji:()=>wS});var yg=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}"),dS=yg.reduce((r,e,t)=>(r[t]=e,r),[]),mS=yg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function yS(r){return r.reduce((e,t)=>(e+=dS[t],e),"")}function gS(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=mS[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var wS=qi({prefix:"\u{1F680}",name:"base256emoji",encode:yS,decode:gS});var Kp={};bt(Kp,{base64:()=>xS,base64pad:()=>bS,base64url:()=>ko,base64urlpad:()=>vS});var xS=$e({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),bS=$e({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ko=$e({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vS=$e({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hp={};bt(Hp,{base8:()=>AS});var AS=$e({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vp={};bt(Vp,{identity:()=>SS});var SS=qi({prefix:"\0",name:"identity",encode:r=>rg(r),decode:r=>tg(r)});var uT=new TextEncoder,lT=new TextDecoder;var Wp={};bt(Wp,{sha256:()=>tr,sha512:()=>CS});function Fp({name:r,code:e,encode:t}){return new $p(r,e,t)}var $p=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?vt(this.code,t):t.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var tr=Fp({name:"sha2-256",code:18,encode:wg("SHA-256")}),CS=Fp({name:"sha2-512",code:19,encode:wg("SHA-512")});var Po={...Vp,...jp,...Hp,...Lp,...Up,...kp,...Pp,...Bp,...Kp,...Mp},AT={...Wp,...Dp};function bg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var xg=bg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),qp=bg("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=nt(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),IS={utf8:xg,"utf-8":xg,hex:Po.base16,latin1:qp,ascii:qp,binary:qp,...Po},Du=IS;function de(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=Du[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var TS=parseInt("11111",2),Gp=parseInt("10000000",2),BS=parseInt("01111111",2),vg={0:ha,1:ha,2:kS,3:OS,4:RS,5:NS,6:PS,16:ha,22:ha,48:ha};function cn(r,e={offset:0}){let t=r[e.offset]&TS;if(e.offset++,vg[t]!=null)return vg[t](r,e);throw new Error("No decoder for tag "+t)}function da(r,e){let t=0;if((r[e.offset]&Gp)===Gp){let n=r[e.offset]&BS,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function ha(r,e){da(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=cn(r,e);if(n===null)break;t.push(n)}return t}function kS(r,e){let t=da(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function PS(r,e){let t=da(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let f=r[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let h=0;for(let p=0;p<c.length;p++)h+=c[p]<<p*7;a+=`.${h}`,c=[]}}return a}function NS(r,e){return e.offset++,null}function OS(r,e){let t=da(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 RS(r,e){let t=da(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function DS(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new be;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Lu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=DS(r.byteLength);return new be(Uint8Array.from([e.byteLength|Gp]),e)}function kt(r){let e=new be,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new be(Uint8Array.from([2]),Lu(e),e)}function ma(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Lu(t),t)}function Ag(r){return new be(Uint8Array.from([4]),Lu(r),r)}function gr(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Lu(t),t)}async function Sg(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 Eg(r,e){let t=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,e.subarray());return new Uint8Array(n,0,n.byteLength)}async function _g(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,e,t.subarray())}var LS=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),US=Uint8Array.from([6,5,43,129,4,0,34]),jS=Uint8Array.from([6,5,43,129,4,0,35]),MS={ext:!0,kty:"EC",crv:"P-256"},KS={ext:!0,kty:"EC",crv:"P-384"},HS={ext:!0,kty:"EC",crv:"P-521"},zp=32,Xp=48,Yp=66;function Zp(r){let e=cn(r);return Cg(e)}function Cg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===zp*2+1)return n=ue(e.subarray(t,t+zp),"base64url"),o=ue(e.subarray(t+zp),"base64url"),new No({...MS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Xp*2+1)return n=ue(e.subarray(t,t+Xp),"base64url"),o=ue(e.subarray(t+Xp),"base64url"),new No({...KS,key_ops:["verify"],x:n,y:o});if(e.byteLength===Yp*2+1)return n=ue(e.subarray(t,t+Yp),"base64url"),o=ue(e.subarray(t+Yp),"base64url"),new No({...HS,key_ops:["verify"],x:n,y:o});throw new Ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ig(r){return gr([kt(Uint8Array.from([1])),Ag(de(r.d??"","base64url")),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Tg(r){return gr([kt(Uint8Array.from([1])),gr([Bg(r.crv)],160),gr([ma(new be(Uint8Array.from([4]),de(r.x??"","base64url"),de(r.y??"","base64url")))],161)]).subarray()}function Bg(r){if(r==="P-256")return LS;if(r==="P-384")return US;if(r==="P-521")return jS;throw new Ae(`Invalid curve ${r}`)}async function kg(r="P-256"){let e=await Sg(r);return new Uu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Tg(this.jwk)),this._raw}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async verify(e,t){return _g(this.jwk,t,e)}},Uu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Ig(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}async sign(e){return Eg(this.jwk,e)}};var Oo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function VS(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ro(r,...e){if(!VS(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 ya(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Xi(r.outputLen),Xi(r.blockLen)}function Zi(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 Pg(r,e){Ro(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function wr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function ju(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xr(r,e){return r<<32-e|r>>>e}function Ng(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function $n(r){return typeof r=="string"&&(r=Ng(r)),Ro(r),r}function Jp(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Ro(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 Yi=class{};function Qp(r){let e=n=>r().update($n(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ga(r=32){if(Oo&&typeof Oo.getRandomValues=="function")return Oo.getRandomValues(new Uint8Array(r));if(Oo&&typeof Oo.randomBytes=="function")return Uint8Array.from(Oo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function $S(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,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}function Og(r,e,t){return r&e^~r&t}function Rg(r,e,t){return r&e^r&t^e&t}var wa=class extends Yi{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=ju(this.buffer)}update(e){Zi(this),e=$n(e),Ro(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=ju(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){Zi(this),Pg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,wr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let p=s;p<o;p++)t[p]=0;$S(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=ju(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<f;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()}},un=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mu=BigInt(4294967295),Dg=BigInt(32);function FS(r,e=!1){return e?{h:Number(r&Mu),l:Number(r>>Dg&Mu)}:{h:Number(r>>Dg&Mu)|0,l:Number(r&Mu)|0}}function Lg(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}=FS(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var eh=(r,e,t)=>r>>>t,th=(r,e,t)=>r<<32-t|e>>>t,Do=(r,e,t)=>r>>>t|e<<32-t,Lo=(r,e,t)=>r<<32-t|e>>>t,xa=(r,e,t)=>r<<64-t|e>>>t-32,ba=(r,e,t)=>r>>>t-32|e<<64-t;function Ur(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Ug=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),jg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Mg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Kg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Hg=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Vg=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var qS=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]),Fn=new Uint32Array(64),Ku=class extends wa{constructor(e=32){super(64,e,8,!1),this.A=un[0]|0,this.B=un[1]|0,this.C=un[2]|0,this.D=un[3]|0,this.E=un[4]|0,this.F=un[5]|0,this.G=un[6]|0,this.H=un[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)Fn[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let m=Fn[p-15],v=Fn[p-2],g=xr(m,7)^xr(m,18)^m>>>3,w=xr(v,17)^xr(v,19)^v>>>10;Fn[p]=w+Fn[p-7]+g+Fn[p-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let p=0;p<64;p++){let m=xr(a,6)^xr(a,11)^xr(a,25),v=h+m+Og(a,c,f)+qS[p]+Fn[p]|0,w=(xr(n,2)^xr(n,13)^xr(n,22))+Rg(n,o,i)|0;h=f,f=c,c=a,a=s+v|0,s=i,i=o,o=n,n=v+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,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){wr(Fn)}destroy(){this.set(0,0,0,0,0,0,0,0),wr(this.buffer)}};var $g=Lg(["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))),GS=$g[0],zS=$g[1],Wn=new Uint32Array(80),qn=new Uint32Array(80),rh=class extends wa{constructor(e=64){super(128,e,16,!1),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:h,Fh:p,Fl:m,Gh:v,Gl:g,Hh:w,Hl:S}=this;return[e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S]}set(e,t,n,o,i,s,a,c,f,h,p,m,v,g,w,S){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=p|0,this.Fl=m|0,this.Gh=v|0,this.Gl=g|0,this.Hh=w|0,this.Hl=S|0}process(e,t){for(let T=0;T<16;T++,t+=4)Wn[T]=e.getUint32(t),qn[T]=e.getUint32(t+=4);for(let T=16;T<80;T++){let b=Wn[T-15]|0,D=qn[T-15]|0,V=Do(b,D,1)^Do(b,D,8)^eh(b,D,7),N=Lo(b,D,1)^Lo(b,D,8)^th(b,D,7),U=Wn[T-2]|0,$=qn[T-2]|0,X=Do(U,$,19)^xa(U,$,61)^eh(U,$,6),M=Lo(U,$,19)^ba(U,$,61)^th(U,$,6),G=Mg(N,M,qn[T-7],qn[T-16]),F=Kg(G,V,X,Wn[T-7],Wn[T-16]);Wn[T]=F|0,qn[T]=G|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:h,Eh:p,El:m,Fh:v,Fl:g,Gh:w,Gl:S,Hh:O,Hl:Y}=this;for(let T=0;T<80;T++){let b=Do(p,m,14)^Do(p,m,18)^xa(p,m,41),D=Lo(p,m,14)^Lo(p,m,18)^ba(p,m,41),V=p&v^~p&w,N=m&g^~m&S,U=Hg(Y,D,N,zS[T],qn[T]),$=Vg(U,O,b,V,GS[T],Wn[T]),X=U|0,M=Do(n,o,28)^xa(n,o,34)^xa(n,o,39),G=Lo(n,o,28)^ba(n,o,34)^ba(n,o,39),F=n&i^n&a^i&a,ie=o&s^o&c^s&c;O=w|0,Y=S|0,w=v|0,S=g|0,v=p|0,g=m|0,{h:p,l:m}=Ur(f|0,h|0,$|0,X|0),f=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let k=Ug(X,G,ie);n=jg(k,$,M,F),o=k|0}({h:n,l:o}=Ur(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ur(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ur(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=Ur(this.Dh|0,this.Dl|0,f|0,h|0),{h:p,l:m}=Ur(this.Eh|0,this.El|0,p|0,m|0),{h:v,l:g}=Ur(this.Fh|0,this.Fl|0,v|0,g|0),{h:w,l:S}=Ur(this.Gh|0,this.Gl|0,w|0,S|0),{h:O,l:Y}=Ur(this.Hh|0,this.Hl|0,O|0,Y|0),this.set(n,o,i,s,a,c,f,h,p,m,v,g,w,S,O,Y)}roundClean(){wr(Wn,qn)}destroy(){wr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Hu=Qp(()=>new Ku);var Fg=Qp(()=>new rh);var sh=BigInt(0),ih=BigInt(1);function Ji(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ah(r){if(!Ji(r))throw new Error("Uint8Array expected")}function jr(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function va(r){let e=r.toString(16);return e.length&1?"0"+e:e}function Gg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?sh:BigInt("0x"+r)}var zg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",XS=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Gn(r){if(ah(r),zg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=XS[r[t]];return e}var ln={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wg(r){if(r>=ln._0&&r<=ln._9)return r-ln._0;if(r>=ln.A&&r<=ln.F)return r-(ln.A-10);if(r>=ln.a&&r<=ln.f)return r-(ln.a-10)}function Aa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(zg)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=Wg(r.charCodeAt(i)),a=Wg(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 fn(r){return Gg(Gn(r))}function Mr(r){return ah(r),Gg(Gn(Uint8Array.from(r).reverse()))}function Uo(r,e){return Aa(r.toString(16).padStart(e*2,"0"))}function zn(r,e){return Uo(r,e).reverse()}function Oe(r,e,t){let n;if(typeof e=="string")try{n=Aa(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Ji(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 Xn(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];ah(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 nh=r=>typeof r=="bigint"&&sh<=r;function Vu(r,e,t){return nh(r)&&nh(e)&&nh(t)&&e<=r&&r<t}function At(r,e,t,n){if(!Vu(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Xg(r){let e;for(e=0;r>sh;r>>=ih,e+=1);return e}var jo=r=>(ih<<BigInt(r))-ih,oh=r=>new Uint8Array(r),qg=r=>Uint8Array.from(r);function Yg(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=oh(r),o=oh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...p)=>t(o,n,...p),c=(p=oh(0))=>{o=a(qg([0]),p),n=a(),p.length!==0&&(o=a(qg([1]),p),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,m=[];for(;p<e;){n=a();let v=n.slice();m.push(v),p+=n.length}return Xn(...m)};return(p,m)=>{s(),c(p);let v;for(;!(v=m(f()));)c();return s(),v}}var YS={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ji(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function br(r,e,t={}){let n=(o,i,s)=>{let a=YS[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(t))n(o,i,!0);return r}function Qi(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 Pt=BigInt(0),at=BigInt(1),Mo=BigInt(2),ZS=BigInt(3),Jg=BigInt(4),Qg=BigInt(5),e0=BigInt(8);function Ce(r,e){let t=r%e;return t>=Pt?t:e+t}function Me(r,e,t){let n=r;for(;e-- >Pt;)n*=n,n%=t;return n}function $u(r,e){if(r===Pt)throw new Error("invert: expected non-zero number");if(e<=Pt)throw new Error("invert: expected positive modulus, got "+e);let t=Ce(r,e),n=e,o=Pt,i=at,s=at,a=Pt;for(;t!==Pt;){let f=n/t,h=n%t,p=o-s*f,m=i-a*f;n=t,t=h,o=s,i=a,s=p,a=m}if(n!==at)throw new Error("invert: does not exist");return Ce(o,e)}function t0(r,e){let t=(r.ORDER+at)/Jg,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function JS(r,e){let t=(r.ORDER-Qg)/e0,n=r.mul(e,Mo),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Mo),o),a=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(a),e))throw new Error("Cannot find square root");return a}function QS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-at,t=0;for(;e%Mo===Pt;)e/=Mo,t++;let n=Mo,o=pn(r);for(;Zg(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return t0;let i=o.pow(n,e),s=(e+at)/Mo;return function(c,f){if(c.is0(f))return f;if(Zg(c,f)!==1)throw new Error("Cannot find square root");let h=t,p=c.mul(c.ONE,i),m=c.pow(f,e),v=c.pow(f,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 S=at<<BigInt(h-g-1),O=c.pow(p,S);h=g,p=c.sqr(O),m=c.mul(m,p),v=c.mul(v,O)}return v}}function eE(r){return r%Jg===ZS?t0:r%e0===Qg?JS:QS(r)}var r0=(r,e)=>(Ce(r,e)&at)===at,tE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ch(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=tE.reduce((n,o)=>(n[o]="function",n),e);return br(r,t)}function rE(r,e,t){if(t<Pt)throw new Error("invalid exponent, negatives unsupported");if(t===Pt)return r.ONE;if(t===at)return e;let n=r.ONE,o=e;for(;t>Pt;)t&at&&(n=r.mul(n,o)),o=r.sqr(o),t>>=at;return n}function es(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 Zg(r,e){let t=(r.ORDER-at)/Mo,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 uh(r,e){e!==void 0&&Xi(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function pn(r,e,t=!1,n={}){if(r<=Pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=uh(r,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:t,BITS:o,BYTES:i,MASK:jo(o),ZERO:Pt,ONE:at,create:c=>Ce(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Pt<=c&&c<r},is0:c=>c===Pt,isOdd:c=>(c&at)===at,neg:c=>Ce(-c,r),eql:(c,f)=>c===f,sqr:c=>Ce(c*c,r),add:(c,f)=>Ce(c+f,r),sub:(c,f)=>Ce(c-f,r),mul:(c,f)=>Ce(c*f,r),pow:(c,f)=>rE(a,c,f),div:(c,f)=>Ce(c*$u(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>$u(c,r),sqrt:n.sqrt||(c=>(s||(s=eE(r)),s(a,c))),toBytes:c=>t?zn(c,i):Uo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Mr(c):fn(c)},invertBatch:c=>es(a,c),cmov:(c,f,h)=>h?f:c});return Object.freeze(a)}function n0(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=n0(r);return e+Math.ceil(e/2)}function o0(r,e,t=!1){let n=r.length,o=n0(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?Mr(r):fn(r),a=Ce(s,e-at)+at;return t?zn(a,o):Uo(a,o)}var i0=BigInt(0),mh=BigInt(1);function fh(r,e){let t=e.negate();return r?t:e}function a0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function ph(r,e){a0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=jo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function s0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=mh);let f=e*n,h=f+Math.abs(a)-1,p=a===0,m=a<0,v=e%2!==0;return{nextN:c,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:f}}function nE(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 oE(r,e){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}var hh=new WeakMap,c0=new WeakMap;function dh(r){return c0.get(r)||1}function Fu(r,e){return{constTimeNegate:fh,hasPrecomputes(t){return dh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>i0;)n&mh&&(o=o.add(i)),i=i.double(),n>>=mh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=ph(n,e),s=[],a=t,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=ph(t,e);for(let c=0;c<a.windows;c++){let{nextN:f,offset:h,isZero:p,isNeg:m,isNegF:v,offsetF:g}=s0(o,c,a);o=f,p?s=s.add(fh(v,n[g])):i=i.add(fh(m,n[h]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=ph(t,e);for(let a=0;a<s.windows&&o!==i0;a++){let{nextN:c,offset:f,isZero:h,isNeg:p}=s0(o,a,s);if(o=c,!h){let m=n[f];i=i.add(p?m.negate():m)}}return i},getPrecomputes(t,n,o){let i=hh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&hh.set(n,o(i))),i},wNAFCached(t,n,o){let i=dh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=dh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){a0(n,e),c0.set(t,n),hh.delete(t)}}}function Wu(r,e,t,n){nE(t,r),oE(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=Xg(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=jo(c),h=new Array(Number(f)+1).fill(s),p=Math.floor((e.BITS-1)/c)*c,m=s;for(let v=p;v>=0;v-=c){h.fill(s);for(let w=0;w<i;w++){let S=n[w],O=Number(S>>BigInt(v)&f);h[O]=h[O].add(t[w])}let g=s;for(let w=h.length-1,S=s;w>0;w--)S=S.add(h[w]),g=g.add(S);if(m=m.add(g),v!==0)for(let w=0;w<c;w++)m=m.double()}return m}function Sa(r){return ch(r.Fp),br(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...uh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Kr=BigInt(0),Nt=BigInt(1),u0=BigInt(2),iE=BigInt(8),sE={zip215:!0};function aE(r){let e=Sa(r);return br(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function l0(r){let e=aE(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,f=u0<<BigInt(a*8)-Nt,h=t.create,p=pn(e.n,e.nBitLength);function m(P,y){let C=t.sqr(P),L=t.sqr(y),I=t.add(t.mul(e.a,C),L),re=t.add(t.ONE,t.mul(e.d,t.mul(C,L)));return t.eql(I,re)}if(!m(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let v=e.uvRatio||((P,y)=>{try{return{isValid:!0,value:t.sqrt(P*t.inv(y))}}catch{return{isValid:!1,value:Kr}}}),g=e.adjustScalarBytes||(P=>P),w=e.domain||((P,y,C)=>{if(jr("phflag",C),y.length||C)throw new Error("Contexts/pre-hash are not supported");return P});function S(P,y,C=!1){let L=C?Nt:Kr;At("coordinate "+P,y,L,f)}function O(P){if(!(P instanceof b))throw new Error("ExtendedPoint expected")}let Y=Qi((P,y)=>{let{ex:C,ey:L,ez:I}=P,re=P.is0();y==null&&(y=re?iE:t.inv(I));let le=h(C*y),Q=h(L*y),pe=h(I*y);if(re)return{x:Kr,y:Nt};if(pe!==Nt)throw new Error("invZ was invalid");return{x:le,y:Q}}),T=Qi(P=>{let{a:y,d:C}=e;if(P.is0())throw new Error("bad point: ZERO");let{ex:L,ey:I,ez:re,et:le}=P,Q=h(L*L),pe=h(I*I),he=h(re*re),Ee=h(he*he),_e=h(Q*y),ke=h(he*h(_e+pe)),ut=h(Ee+h(C*h(Q*pe)));if(ke!==ut)throw new Error("bad point: equation left != right (1)");let Ue=h(L*I),et=h(re*le);if(Ue!==et)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(y,C,L,I){S("x",y),S("y",C),S("z",L,!0),S("t",I),this.ex=y,this.ey=C,this.ez=L,this.et=I,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:C,y:L}=y||{};return S("x",C),S("y",L),new b(C,L,Nt,h(C*L))}static normalizeZ(y){let C=es(t,y.map(L=>L.ez));return y.map((L,I)=>L.toAffine(C[I])).map(b.fromAffine)}static msm(y,C){return Wu(b,p,y,C)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){T(this)}equals(y){O(y);let{ex:C,ey:L,ez:I}=this,{ex:re,ey:le,ez:Q}=y,pe=h(C*Q),he=h(re*I),Ee=h(L*Q),_e=h(le*I);return pe===he&&Ee===_e}is0(){return this.equals(b.ZERO)}negate(){return new b(h(-this.ex),this.ey,this.ez,h(-this.et))}double(){let{a:y}=e,{ex:C,ey:L,ez:I}=this,re=h(C*C),le=h(L*L),Q=h(u0*h(I*I)),pe=h(y*re),he=C+L,Ee=h(h(he*he)-re-le),_e=pe+le,ke=_e-Q,ut=pe-le,Ue=h(Ee*ke),et=h(_e*ut),Tt=h(Ee*ut),Bt=h(ke*_e);return new b(Ue,et,Bt,Tt)}add(y){O(y);let{a:C,d:L}=e,{ex:I,ey:re,ez:le,et:Q}=this,{ex:pe,ey:he,ez:Ee,et:_e}=y,ke=h(I*pe),ut=h(re*he),Ue=h(Q*L*_e),et=h(le*Ee),Tt=h((I+re)*(pe+he)-ke-ut),Bt=et-Ue,Un=et+Ue,ia=h(ut-C*ke),xu=h(Tt*Bt),bu=h(Un*ia),vu=h(Tt*ia),sa=h(Bt*Un);return new b(xu,bu,sa,vu)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,b.normalizeZ)}multiply(y){let C=y;At("scalar",C,Nt,n);let{p:L,f:I}=this.wNAF(C);return b.normalizeZ([L,I])[0]}multiplyUnsafe(y,C=b.ZERO){let L=y;return At("scalar",L,Kr,n),L===Kr?V:this.is0()||L===Nt?this:N.wNAFCachedUnsafe(this,L,b.normalizeZ,C)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return Y(this,y)}clearCofactor(){let{h:y}=e;return y===Nt?this:this.multiplyUnsafe(y)}static fromHex(y,C=!1){let{d:L,a:I}=e,re=t.BYTES;y=Oe("pointHex",y,re),jr("zip215",C);let le=y.slice(),Q=y[re-1];le[re-1]=Q&-129;let pe=Mr(le),he=C?f:t.ORDER;At("pointHex.y",pe,Kr,he);let Ee=h(pe*pe),_e=h(Ee-Nt),ke=h(L*Ee-I),{isValid:ut,value:Ue}=v(_e,ke);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let et=(Ue&Nt)===Nt,Tt=(Q&128)!==0;if(!C&&Ue===Kr&&Tt)throw new Error("Point.fromHex: x=0 and x_0=1");return Tt!==et&&(Ue=h(-Ue)),b.fromAffine({x:Ue,y:pe})}static fromPrivateKey(y){let{scalar:C}=X(y);return D.multiply(C)}toRawBytes(){let{x:y,y:C}=this.toAffine(),L=zn(C,t.BYTES);return L[L.length-1]|=y&Nt?128:0,L}toHex(){return Gn(this.toRawBytes())}}b.BASE=new b(e.Gx,e.Gy,Nt,h(e.Gx*e.Gy)),b.ZERO=new b(Kr,Nt,Nt,Kr);let{BASE:D,ZERO:V}=b,N=Fu(b,a*8);function U(P){return Ce(P,n)}function $(P){return U(Mr(P))}function X(P){let y=t.BYTES;P=Oe("private key",P,y);let C=Oe("hashed private key",i(P),2*y),L=g(C.slice(0,y)),I=C.slice(y,2*y),re=$(L);return{head:L,prefix:I,scalar:re}}function M(P){let{head:y,prefix:C,scalar:L}=X(P),I=D.multiply(L),re=I.toRawBytes();return{head:y,prefix:C,scalar:L,point:I,pointBytes:re}}function G(P){return M(P).pointBytes}function F(P=Uint8Array.of(),...y){let C=Xn(...y);return $(i(w(C,Oe("context",P),!!o)))}function ie(P,y,C={}){P=Oe("message",P),o&&(P=o(P));let{prefix:L,scalar:I,pointBytes:re}=M(y),le=F(C.context,L,P),Q=D.multiply(le).toRawBytes(),pe=F(C.context,Q,re,P),he=U(le+pe*I);At("signature.s",he,Kr,n);let Ee=Xn(Q,zn(he,t.BYTES));return Oe("result",Ee,t.BYTES*2)}let k=sE;function R(P,y,C,L=k){let{context:I,zip215:re}=L,le=t.BYTES;P=Oe("signature",P,2*le),y=Oe("message",y),C=Oe("publicKey",C,le),re!==void 0&&jr("zip215",re),o&&(y=o(y));let Q=Mr(P.slice(le,2*le)),pe,he,Ee;try{pe=b.fromHex(C,re),he=b.fromHex(P.slice(0,le),re),Ee=D.multiplyUnsafe(Q)}catch{return!1}if(!re&&pe.isSmallOrder())return!1;let _e=F(I,he.toRawBytes(),pe.toRawBytes(),y);return he.add(pe.multiplyUnsafe(_e)).subtract(Ee).clearCofactor().equals(b.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:G,sign:ie,verify:R,ExtendedPoint:b,utils:{getExtendedPublicKey:M,randomPrivateKey:()=>s(t.BYTES),precompute(P=8,y=b.BASE){return y._setWindowSize(P),y.multiply(BigInt(3)),y}}}}var Ea=BigInt(0),ts=BigInt(1),qu=BigInt(2);function cE(r){return br(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function f0(r){let e=cE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i}=e,s=n==="x25519";if(!s&&n!=="x448")throw new Error("invalid type");let a=s?255:448,c=s?32:56,f=BigInt(s?9:5),h=BigInt(s?121665:39081),p=s?qu**BigInt(254):qu**BigInt(447),m=s?BigInt(8)*qu**BigInt(251)-ts:BigInt(4)*qu**BigInt(445)-ts,v=p+m+ts,g=N=>Ce(N,t),w=S(f);function S(N){return zn(g(N),c)}function O(N){let U=Oe("u coordinate",N,c);return s&&(U[31]&=127),g(Mr(U))}function Y(N){return Mr(o(Oe("scalar",N,c)))}function T(N,U){let $=V(O(U),Y(N));if($===Ea)throw new Error("invalid private or public key received");return S($)}function b(N){return T(N,w)}function D(N,U,$){let X=g(N*(U-$));return U=g(U-X),$=g($+X),{x_2:U,x_3:$}}function V(N,U){At("u",N,Ea,t),At("scalar",U,p,v);let $=U,X=N,M=ts,G=Ea,F=N,ie=ts,k=Ea;for(let K=BigInt(a-1);K>=Ea;K--){let P=$>>K&ts;k^=P,{x_2:M,x_3:F}=D(k,M,F),{x_2:G,x_3:ie}=D(k,G,ie),k=P;let y=M+G,C=g(y*y),L=M-G,I=g(L*L),re=C-I,le=F+ie,Q=F-ie,pe=g(Q*y),he=g(le*L),Ee=pe+he,_e=pe-he;F=g(Ee*Ee),ie=g(X*g(_e*_e)),M=g(C*I),G=g(re*(C+g(h*re)))}({x_2:M,x_3:F}=D(k,M,F)),{x_2:G,x_3:ie}=D(k,G,ie);let R=i(G);return g(M*R)}return{scalarMult:T,scalarMultBase:b,getSharedSecret:(N,U)=>T(N,U),getPublicKey:N=>b(N),utils:{randomPrivateKey:()=>e.randomBytes(c)},GuBytes:w.slice()}}var _a=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),p0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),CB=BigInt(0),uE=BigInt(1),h0=BigInt(2),lE=BigInt(3),fE=BigInt(5),pE=BigInt(8);function m0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=_a,a=r*r%i*r%i,c=Me(a,h0,i)*a%i,f=Me(c,uE,i)*r%i,h=Me(f,fE,i)*f%i,p=Me(h,e,i)*h%i,m=Me(p,t,i)*p%i,v=Me(m,n,i)*m%i,g=Me(v,o,i)*v%i,w=Me(g,o,i)*v%i,S=Me(w,e,i)*h%i;return{pow_p_5_8:Me(S,h0,i)*r%i,b2:a}}function y0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function hE(r,e){let t=_a,n=Ce(e*e*e,t),o=Ce(n*n*e,t),i=m0(r*o).pow_p_5_8,s=Ce(r*n*i,t),a=Ce(e*s*s,t),c=s,f=Ce(s*p0,t),h=a===r,p=a===Ce(-r,t),m=a===Ce(-r*p0,t);return h&&(s=c),(p||m)&&(s=f),r0(s,t)&&(s=Ce(-s,t)),{isValid:h||p,value:s}}var d0=pn(_a,void 0,!0),dE={a:d0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:d0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:pE,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Fg,randomBytes:ga,adjustScalarBytes:y0,uvRatio:hE},Ca=l0(dE);var Ia=f0({P:_a,type:"x25519",powPminus2:r=>{let e=_a,{pow_p_5_8:t,b2:n}=m0(r);return Ce(Me(t,lE,e)*n,e)},adjustScalarBytes:y0,randomBytes:ga});var Gu=32,zu=64,yh=32;function g0(){let r=Ca.utils.randomPrivateKey(),e=Ca.getPublicKey(r);return{privateKey:mE(r,e),publicKey:e}}function w0(r,e){let t=r.subarray(0,yh);return Ca.sign(e instanceof Uint8Array?e:e.subarray(),t)}function x0(r,e,t){return Ca.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function mE(r,e){let t=new Uint8Array(zu);for(let n=0;n<yh;n++)t[n]=r[n],t[yh+n]=e[n];return t}var Ta=class{type="Ed25519";raw;constructor(e){this.raw=Yu(e,Gu)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return x0(this.raw,t,e)}},Xu=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Yu(e,zu),this.publicKey=new Ta(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return w0(this.raw,e)}};function gh(r){return r=Yu(r,Gu),new Ta(r)}async function v0(){let{privateKey:r,publicKey:e}=g0();return new Xu(r,e)}function Yu(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Ae(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var yE=Math.pow(2,7),gE=Math.pow(2,14),wE=Math.pow(2,21),wh=Math.pow(2,28),xh=Math.pow(2,35),bh=Math.pow(2,42),vh=Math.pow(2,49),Te=128,St=127;function Ke(r){if(r<yE)return 1;if(r<gE)return 2;if(r<wE)return 3;if(r<wh)return 4;if(r<xh)return 5;if(r<bh)return 6;if(r<vh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ah(r,e,t=0){switch(Ke(r)){case 8:e[t++]=r&255|Te,r/=128;case 7:e[t++]=r&255|Te,r/=128;case 6:e[t++]=r&255|Te,r/=128;case 5:e[t++]=r&255|Te,r/=128;case 4:e[t++]=r&255|Te,r>>>=7;case 3:e[t++]=r&255|Te,r>>>=7;case 2:e[t++]=r&255|Te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function xE(r,e,t=0){switch(Ke(r)){case 8:e.set(t++,r&255|Te),r/=128;case 7:e.set(t++,r&255|Te),r/=128;case 6:e.set(t++,r&255|Te),r/=128;case 5:e.set(t++,r&255|Te),r/=128;case 4:e.set(t++,r&255|Te),r>>>=7;case 3:e.set(t++,r&255|Te),r>>>=7;case 2:e.set(t++,r&255|Te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Sh(r,e){let t=r[e],n=0;if(n+=t&St,t<Te||(t=r[e+1],n+=(t&St)<<7,t<Te)||(t=r[e+2],n+=(t&St)<<14,t<Te)||(t=r[e+3],n+=(t&St)<<21,t<Te)||(t=r[e+4],n+=(t&St)*wh,t<Te)||(t=r[e+5],n+=(t&St)*xh,t<Te)||(t=r[e+6],n+=(t&St)*bh,t<Te)||(t=r[e+7],n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function bE(r,e){let t=r.get(e),n=0;if(n+=t&St,t<Te||(t=r.get(e+1),n+=(t&St)<<7,t<Te)||(t=r.get(e+2),n+=(t&St)<<14,t<Te)||(t=r.get(e+3),n+=(t&St)<<21,t<Te)||(t=r.get(e+4),n+=(t&St)*wh,t<Te)||(t=r.get(e+5),n+=(t&St)*xh,t<Te)||(t=r.get(e+6),n+=(t&St)*bh,t<Te)||(t=r.get(e+7),n+=(t&St)*vh,t<Te))return n;throw new RangeError("Could not decode varint")}function Hr(r,e,t=0){return e==null&&(e=nt(Ke(r))),e instanceof Uint8Array?Ah(r,e,t):xE(r,e,t)}function vr(r,e=0){return r instanceof Uint8Array?Sh(r,e):bE(r,e)}var Eh=new Float32Array([-0]),Yn=new Uint8Array(Eh.buffer);function A0(r,e,t){Eh[0]=r,e[t]=Yn[0],e[t+1]=Yn[1],e[t+2]=Yn[2],e[t+3]=Yn[3]}function S0(r,e){return Yn[0]=r[e],Yn[1]=r[e+1],Yn[2]=r[e+2],Yn[3]=r[e+3],Eh[0]}var _h=new Float64Array([-0]),Et=new Uint8Array(_h.buffer);function E0(r,e,t){_h[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 _0(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],_h[0]}var vE=BigInt(Number.MAX_SAFE_INTEGER),AE=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 Ko;if(e<vE&&e>AE)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>C0&&(o=0n,++n>C0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ko;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):Ko}},Ko=new Xt(0,0);Ko.toBigInt=function(){return 0n};Ko.zzEncode=Ko.zzDecode=function(){return this};Ko.length=function(){return 1};var C0=4294967296n;function I0(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 T0(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 Ch(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 Ar(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Zu(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Ih=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,Ar(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 Ar(this,4);return Zu(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ar(this,4);return Zu(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ar(this,4);let e=S0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ar(this,4);let e=_0(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 Ar(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return T0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ar(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ar(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 Ar(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 Ar(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 Ar(this,8);let e=Zu(this.buf,this.pos+=4),t=Zu(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=Sh(this.buf,this.pos);return this.pos+=Ke(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 Th(r){return new Ih(r instanceof Uint8Array?r:r.subarray())}function Sr(r,e,t){let n=Th(r);return e.decode(n,void 0,t)}function Bh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return nt(s);o+s>e&&(n=nt(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Ho=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function kh(){}var Nh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},SE=Bh();function EE(r){return globalThis.Buffer!=null?nt(r):SE(r)}var Pa=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ho(kh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Ho(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oh((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(Ju,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(Ju,t.length(),t)}uint64Number(e){return this._push(Ah,Ke(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(Ju,t.length(),t)}sint64Number(e){let t=Xt.fromNumber(e).zzEncode();return this._push(Ju,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ph,1,e?1:0)}fixed32(e){return this._push(ka,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Xt.fromBigInt(e);return this._push(ka,4,t.lo)._push(ka,4,t.hi)}fixed64Number(e){let t=Xt.fromNumber(e);return this._push(ka,4,t.lo)._push(ka,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(A0,4,e)}double(e){return this._push(E0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ph,1,0):this.uint32(t)._push(CE,t,e)}string(e){let t=I0(e);return t!==0?this.uint32(t)._push(Ch,t,e):this._push(Ph,1,0)}fork(){return this.states=new Nh(this),this.head=this.tail=new Ho(kh,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 Ho(kh,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=EE(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ph(r,e,t){e[t]=r&255}function _E(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Oh=class extends Ho{next;constructor(e,t){super(_E,e,t),this.next=void 0}};function Ju(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 ka(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 CE(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Pa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(IE,e,r),this},Pa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(TE,e,r),this});function IE(r,e,t){e.set(r,t)}function TE(r,e,t){r.length<40?Ch(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(de(r),t)}function Rh(){return new Pa}function Er(r,e){let t=Rh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var rs;(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"})(rs||(rs={}));function Qu(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Vo(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 Qu("enum",rs.VARINT,t,n)}function _r(r,e){return Qu("message",rs.LENGTH_DELIMITED,r,e)}var Na=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var Dh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Dh||(Dh={}));(function(r){r.codec=()=>Vo(Dh)})(Ye||(Ye={}));var Vr;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Vr||(Vr={}));var Lh;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(Lh||(Lh={}));var Oa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ra=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},el=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var P0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new el("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 Zn=P0;var La={};bt(La,{MAX_RSA_KEY_SIZE:()=>Uh,generateRSAKeyPair:()=>qh,jwkToJWKKeyPair:()=>D0,jwkToPkcs1:()=>NE,jwkToPkix:()=>Hh,jwkToRSAPrivateKey:()=>Wh,pkcs1MessageToJwk:()=>Mh,pkcs1MessageToRSAPrivateKey:()=>Vh,pkcs1ToJwk:()=>PE,pkcs1ToRSAPrivateKey:()=>R0,pkixMessageToJwk:()=>Kh,pkixMessageToRSAPublicKey:()=>Fh,pkixToJwk:()=>OE,pkixToRSAPublicKey:()=>$h});var Jn=Hu;var ns=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Xe.createV1(114,this._multihash)}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return O0(this.jwk,t,e)}},Da=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=La.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return N0(this.jwk,e)}};var Uh=8192,jh=18,BE=1062,kE=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function PE(r){let e=cn(r);return Mh(e)}function Mh(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 NE(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 Ae("JWK was missing components");return gr([kt(Uint8Array.from([0])),kt(de(r.n,"base64url")),kt(de(r.e,"base64url")),kt(de(r.d,"base64url")),kt(de(r.p,"base64url")),kt(de(r.q,"base64url")),kt(de(r.dp,"base64url")),kt(de(r.dq,"base64url")),kt(de(r.qi,"base64url"))]).subarray()}function OE(r){let e=cn(r,{offset:0});return Kh(e)}function Kh(r){let e=cn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Hh(r){if(r.n==null||r.e==null)throw new Ae("JWK was missing components");return gr([kE,ma(gr([kt(de(r.n,"base64url")),kt(de(r.e,"base64url"))]))]).subarray()}function R0(r){let e=cn(r);return Vh(e)}function Vh(r){let e=Mh(r);return Wh(e)}function $h(r,e){if(r.byteLength>=BE)throw new Fi("Key size is too large");let t=cn(r,{offset:0});return Fh(t,r,e)}function Fh(r,e,t){let n=Kh(r);if(t==null){let o=Jn(Vr.encode({Type:Ye.RSA,Data:e}));t=vt(jh,o)}return new ns(n,t)}function Wh(r){if(U0(r)>Uh)throw new Ae("Key size is too large");let e=D0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}async function qh(r){if(r>Uh)throw new Ae("Key size is too large");let e=await L0(r),t=Jn(Vr.encode({Type:Ye.RSA,Data:Hh(e.publicKey)})),n=vt(jh,t);return new Da(e.privateKey,new ns(e.publicKey,n))}function D0(r){if(r==null)throw new Ae("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function L0(r){let e=await Zn.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await RE(e);return{privateKey:t[0],publicKey:t[1]}}async function N0(r,e){let t=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Zn.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function O0(r,e,t){let n=await Zn.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Zn.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function RE(r){if(r.privateKey==null||r.publicKey==null)throw new Ae("Private and public key are required");return Promise.all([Zn.get().subtle.exportKey("jwk",r.privateKey),Zn.get().subtle.exportKey("jwk",r.publicKey)])}function U0(r){if(r.kty!=="RSA")throw new Ae("invalid key type");if(r.n==null)throw new Ae("invalid key modulus");return de(r.n,"base64url").length*8}var tl=class extends Yi{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ya(e);let n=$n(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),wr(i)}update(e){return Zi(this),this.iHash.update(e),this}digestInto(e){Zi(this),Ro(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()}},os=(r,e,t)=>new tl(r,e).update(t).digest();os.create=(r,e)=>new tl(r,e);function j0(r){r.lowS!==void 0&&jr("lowS",r.lowS),r.prehash!==void 0&&jr("prehash",r.prehash)}function DE(r){let e=Sa(r);br(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}var Xh=class extends Error{constructor(e=""){super(e)}},hn={Err:Xh,_tlv:{encode:(r,e)=>{let{Err:t}=hn;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=va(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?va(o.length/2|128):"";return va(r)+i+o+e},decode(r,e){let{Err:t}=hn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let h of f)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}=hn;if(r<dn)throw new e("integer: negative integers are not allowed");let t=va(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}=hn;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 fn(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=hn,o=Oe("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:f,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(f)}},hexFromSig(r){let{_tlv:e,_int:t}=hn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}};function Gh(r,e){return Gn(Uo(r,e))}var dn=BigInt(0),ct=BigInt(1),Y8=BigInt(2),zh=BigInt(3),LE=BigInt(4);function UE(r){let e=DE(r),{Fp:t}=e,n=pn(e.n,e.nBitLength),o=e.toBytes||((T,b,D)=>{let V=b.toAffine();return Xn(Uint8Array.from([4]),t.toBytes(V.x),t.toBytes(V.y))}),i=e.fromBytes||(T=>{let b=T.subarray(1),D=t.fromBytes(b.subarray(0,t.BYTES)),V=t.fromBytes(b.subarray(t.BYTES,2*t.BYTES));return{x:D,y:V}});function s(T){let{a:b,b:D}=e,V=t.sqr(T),N=t.mul(V,T);return t.add(t.add(N,t.mul(T,b)),D)}function a(T,b){let D=t.sqr(b),V=s(T);return t.eql(D,V)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=t.mul(t.pow(e.a,zh),LE),f=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(c,f)))throw new Error("bad curve params: a or b");function h(T){return Vu(T,ct,e.n)}function p(T){let{allowedPrivateKeyLengths:b,nByteLength:D,wrapPrivateKey:V,n:N}=e;if(b&&typeof T!="bigint"){if(Ji(T)&&(T=Gn(T)),typeof T!="string"||!b.includes(T.length))throw new Error("invalid private key");T=T.padStart(D*2,"0")}let U;try{U=typeof T=="bigint"?T:fn(Oe("private key",T,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof T)}return V&&(U=Ce(U,N)),At("private key",U,ct,N),U}function m(T){if(!(T instanceof w))throw new Error("ProjectivePoint expected")}let v=Qi((T,b)=>{let{px:D,py:V,pz:N}=T;if(t.eql(N,t.ONE))return{x:D,y:V};let U=T.is0();b==null&&(b=U?t.ONE:t.inv(N));let $=t.mul(D,b),X=t.mul(V,b),M=t.mul(N,b);if(U)return{x:t.ZERO,y:t.ZERO};if(!t.eql(M,t.ONE))throw new Error("invZ was invalid");return{x:$,y:X}}),g=Qi(T=>{if(T.is0()){if(e.allowInfinityPoint&&!t.is0(T.py))return;throw new Error("bad point: ZERO")}let{x:b,y:D}=T.toAffine();if(!t.isValid(b)||!t.isValid(D))throw new Error("bad point: x or y not FE");if(!a(b,D))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(b,D,V){if(b==null||!t.isValid(b))throw new Error("x required");if(D==null||!t.isValid(D)||t.is0(D))throw new Error("y required");if(V==null||!t.isValid(V))throw new Error("z required");this.px=b,this.py=D,this.pz=V,Object.freeze(this)}static fromAffine(b){let{x:D,y:V}=b||{};if(!b||!t.isValid(D)||!t.isValid(V))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");let N=U=>t.eql(U,t.ZERO);return N(D)&&N(V)?w.ZERO:new w(D,V,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(b){let D=es(t,b.map(V=>V.pz));return b.map((V,N)=>V.toAffine(D[N])).map(w.fromAffine)}static fromHex(b){let D=w.fromAffine(i(Oe("pointHex",b)));return D.assertValidity(),D}static fromPrivateKey(b){return w.BASE.multiply(p(b))}static msm(b,D){return Wu(w,n,b,D)}_setWindowSize(b){Y.setWindowSize(this,b)}assertValidity(){g(this)}hasEvenY(){let{y:b}=this.toAffine();if(t.isOdd)return!t.isOdd(b);throw new Error("Field doesn't support isOdd")}equals(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.eql(t.mul(D,X),t.mul(U,N)),G=t.eql(t.mul(V,X),t.mul($,N));return M&&G}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){let{a:b,b:D}=e,V=t.mul(D,zh),{px:N,py:U,pz:$}=this,X=t.ZERO,M=t.ZERO,G=t.ZERO,F=t.mul(N,N),ie=t.mul(U,U),k=t.mul($,$),R=t.mul(N,U);return R=t.add(R,R),G=t.mul(N,$),G=t.add(G,G),X=t.mul(b,G),M=t.mul(V,k),M=t.add(X,M),X=t.sub(ie,M),M=t.add(ie,M),M=t.mul(X,M),X=t.mul(R,X),G=t.mul(V,G),k=t.mul(b,k),R=t.sub(F,k),R=t.mul(b,R),R=t.add(R,G),G=t.add(F,F),F=t.add(G,F),F=t.add(F,k),F=t.mul(F,R),M=t.add(M,F),k=t.mul(U,$),k=t.add(k,k),F=t.mul(k,R),X=t.sub(X,F),G=t.mul(k,ie),G=t.add(G,G),G=t.add(G,G),new w(X,M,G)}add(b){m(b);let{px:D,py:V,pz:N}=this,{px:U,py:$,pz:X}=b,M=t.ZERO,G=t.ZERO,F=t.ZERO,ie=e.a,k=t.mul(e.b,zh),R=t.mul(D,U),K=t.mul(V,$),P=t.mul(N,X),y=t.add(D,V),C=t.add(U,$);y=t.mul(y,C),C=t.add(R,K),y=t.sub(y,C),C=t.add(D,N);let L=t.add(U,X);return C=t.mul(C,L),L=t.add(R,P),C=t.sub(C,L),L=t.add(V,N),M=t.add($,X),L=t.mul(L,M),M=t.add(K,P),L=t.sub(L,M),F=t.mul(ie,C),M=t.mul(k,P),F=t.add(M,F),M=t.sub(K,F),F=t.add(K,F),G=t.mul(M,F),K=t.add(R,R),K=t.add(K,R),P=t.mul(ie,P),C=t.mul(k,C),K=t.add(K,P),P=t.sub(R,P),P=t.mul(ie,P),C=t.add(C,P),R=t.mul(K,C),G=t.add(G,R),R=t.mul(L,C),M=t.mul(y,M),M=t.sub(M,R),R=t.mul(y,K),F=t.mul(L,F),F=t.add(F,R),new w(M,G,F)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}wNAF(b){return Y.wNAFCached(this,b,w.normalizeZ)}multiplyUnsafe(b){let{endo:D,n:V}=e;At("scalar",b,dn,V);let N=w.ZERO;if(b===dn)return N;if(this.is0()||b===ct)return this;if(!D||Y.hasPrecomputes(this))return Y.wNAFCachedUnsafe(this,b,w.normalizeZ);let{k1neg:U,k1:$,k2neg:X,k2:M}=D.splitScalar(b),G=N,F=N,ie=this;for(;$>dn||M>dn;)$&ct&&(G=G.add(ie)),M&ct&&(F=F.add(ie)),ie=ie.double(),$>>=ct,M>>=ct;return U&&(G=G.negate()),X&&(F=F.negate()),F=new w(t.mul(F.px,D.beta),F.py,F.pz),G.add(F)}multiply(b){let{endo:D,n:V}=e;At("scalar",b,ct,V);let N,U;if(D){let{k1neg:$,k1:X,k2neg:M,k2:G}=D.splitScalar(b),{p:F,f:ie}=this.wNAF(X),{p:k,f:R}=this.wNAF(G);F=Y.constTimeNegate($,F),k=Y.constTimeNegate(M,k),k=new w(t.mul(k.px,D.beta),k.py,k.pz),N=F.add(k),U=ie.add(R)}else{let{p:$,f:X}=this.wNAF(b);N=$,U=X}return w.normalizeZ([N,U])[0]}multiplyAndAddUnsafe(b,D,V){let N=w.BASE,U=(X,M)=>M===dn||M===ct||!X.equals(N)?X.multiplyUnsafe(M):X.multiply(M),$=U(this,D).add(U(b,V));return $.is0()?void 0:$}toAffine(b){return v(this,b)}isTorsionFree(){let{h:b,isTorsionFree:D}=e;if(b===ct)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:b,clearCofactor:D}=e;return b===ct?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(b=!0){return jr("isCompressed",b),this.assertValidity(),o(w,this,b)}toHex(b=!0){return jr("isCompressed",b),Gn(this.toRawBytes(b))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);let{endo:S,nBitLength:O}=e,Y=Fu(w,S?Math.ceil(O/2):O);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:p,weierstrassEquation:s,isWithinCurveOrder:h}}function jE(r){let e=Sa(r);return br(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function M0(r){let e=jE(r),{Fp:t,n,nByteLength:o,nBitLength:i}=e,s=t.BYTES+1,a=2*t.BYTES+1;function c(k){return Ce(k,n)}function f(k){return $u(k,n)}let{ProjectivePoint:h,normPrivateKeyToScalar:p,weierstrassEquation:m,isWithinCurveOrder:v}=UE({...e,toBytes(k,R,K){let P=R.toAffine(),y=t.toBytes(P.x),C=Xn;return jr("isCompressed",K),K?C(Uint8Array.from([R.hasEvenY()?2:3]),y):C(Uint8Array.from([4]),y,t.toBytes(P.y))},fromBytes(k){let R=k.length,K=k[0],P=k.subarray(1);if(R===s&&(K===2||K===3)){let y=fn(P);if(!Vu(y,ct,t.ORDER))throw new Error("Point is not on curve");let C=m(y),L;try{L=t.sqrt(C)}catch(le){let Q=le instanceof Error?": "+le.message:"";throw new Error("Point is not on curve"+Q)}let I=(L&ct)===ct;return(K&1)===1!==I&&(L=t.neg(L)),{x:y,y:L}}else if(R===a&&K===4){let y=t.fromBytes(P.subarray(0,t.BYTES)),C=t.fromBytes(P.subarray(t.BYTES,2*t.BYTES));return{x:y,y:C}}else{let y=s,C=a;throw new Error("invalid Point, expected length of "+y+", or uncompressed "+C+", got "+R)}}});function g(k){let R=n>>ct;return k>R}function w(k){return g(k)?c(-k):k}let S=(k,R,K)=>fn(k.slice(R,K));class O{constructor(R,K,P){At("r",R,ct,n),At("s",K,ct,n),this.r=R,this.s=K,P!=null&&(this.recovery=P),Object.freeze(this)}static fromCompact(R){let K=o;return R=Oe("compactSignature",R,K*2),new O(S(R,0,K),S(R,K,2*K))}static fromDER(R){let{r:K,s:P}=hn.toSig(Oe("DER",R));return new O(K,P)}assertValidity(){}addRecoveryBit(R){return new O(this.r,this.s,R)}recoverPublicKey(R){let{r:K,s:P,recovery:y}=this,C=N(Oe("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let L=y===2||y===3?K+e.n:K;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let I=(y&1)===0?"02":"03",re=h.fromHex(I+Gh(L,t.BYTES)),le=f(L),Q=c(-C*le),pe=c(P*le),he=h.BASE.multiplyAndAddUnsafe(re,Q,pe);if(!he)throw new Error("point at infinify");return he.assertValidity(),he}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new O(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Aa(this.toDERHex())}toDERHex(){return hn.hexFromSig(this)}toCompactRawBytes(){return Aa(this.toCompactHex())}toCompactHex(){let R=o;return Gh(this.r,R)+Gh(this.s,R)}}let Y={isValidPrivateKey(k){try{return p(k),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let k=lh(e.n);return o0(e.randomBytes(k),e.n)},precompute(k=8,R=h.BASE){return R._setWindowSize(k),R.multiply(BigInt(3)),R}};function T(k,R=!0){return h.fromPrivateKey(k).toRawBytes(R)}function b(k){if(typeof k=="bigint")return!1;if(k instanceof h)return!0;let K=Oe("key",k).length,P=t.BYTES,y=P+1,C=2*P+1;if(!(e.allowedPrivateKeyLengths||o===y))return K===y||K===C}function D(k,R,K=!0){if(b(k)===!0)throw new Error("first arg must be private key");if(b(R)===!1)throw new Error("second arg must be public key");return h.fromHex(R).multiply(p(k)).toRawBytes(K)}let V=e.bits2int||function(k){if(k.length>8192)throw new Error("input is too large");let R=fn(k),K=k.length*8-i;return K>0?R>>BigInt(K):R},N=e.bits2int_modN||function(k){return c(V(k))},U=jo(i);function $(k){return At("num < 2^"+i,k,dn,U),Uo(k,o)}function X(k,R,K=M){if(["recovered","canonical"].some(_e=>_e in K))throw new Error("sign() legacy options not supported");let{hash:P,randomBytes:y}=e,{lowS:C,prehash:L,extraEntropy:I}=K;C==null&&(C=!0),k=Oe("msgHash",k),j0(K),L&&(k=Oe("prehashed msgHash",P(k)));let re=N(k),le=p(R),Q=[$(le),$(re)];if(I!=null&&I!==!1){let _e=I===!0?y(t.BYTES):I;Q.push(Oe("extraEntropy",_e))}let pe=Xn(...Q),he=re;function Ee(_e){let ke=V(_e);if(!v(ke))return;let ut=f(ke),Ue=h.BASE.multiply(ke).toAffine(),et=c(Ue.x);if(et===dn)return;let Tt=c(ut*c(he+et*le));if(Tt===dn)return;let Bt=(Ue.x===et?0:2)|Number(Ue.y&ct),Un=Tt;return C&&g(Tt)&&(Un=w(Tt),Bt^=1),new O(et,Un,Bt)}return{seed:pe,k2sig:Ee}}let M={lowS:e.lowS,prehash:!1},G={lowS:e.lowS,prehash:!1};function F(k,R,K=M){let{seed:P,k2sig:y}=X(k,R,K),C=e;return Yg(C.hash.outputLen,C.nByteLength,C.hmac)(P,y)}h.BASE._setWindowSize(8);function ie(k,R,K,P=G){let y=k;R=Oe("msgHash",R),K=Oe("publicKey",K);let{lowS:C,prehash:L,format:I}=P;if(j0(P),"strict"in P)throw new Error("options.strict was renamed to lowS");if(I!==void 0&&I!=="compact"&&I!=="der")throw new Error("format must be compact or der");let re=typeof y=="string"||Ji(y),le=!re&&!I&&typeof y=="object"&&y!==null&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!re&&!le)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Q,pe;try{if(le&&(Q=new O(y.r,y.s)),re){try{I!=="compact"&&(Q=O.fromDER(y))}catch(Bt){if(!(Bt instanceof hn.Err))throw Bt}!Q&&I!=="der"&&(Q=O.fromCompact(y))}pe=h.fromHex(K)}catch{return!1}if(!Q||C&&Q.hasHighS())return!1;L&&(R=e.hash(R));let{r:he,s:Ee}=Q,_e=N(R),ke=f(Ee),ut=c(_e*ke),Ue=c(he*ke),et=h.BASE.multiplyAndAddUnsafe(pe,ut,Ue)?.toAffine();return et?c(et.x)===he:!1}return{CURVE:e,getPublicKey:T,getSharedSecret:D,sign:F,verify:ie,ProjectivePoint:h,Signature:O,utils:Y}}function ME(r){return{hash:r,hmac:(e,...t)=>os(r,e,Jp(...t)),randomBytes:ga}}function K0(r,e){let t=n=>M0({...r,...ME(n)});return{...t(e),create:t}}var $0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),H0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),KE=BigInt(0),HE=BigInt(1),Yh=BigInt(2),V0=(r,e)=>(r+e/Yh)/e;function VE(r){let e=$0,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,h=f*f*r%e,p=Me(h,t,e)*h%e,m=Me(p,t,e)*h%e,v=Me(m,Yh,e)*f%e,g=Me(v,o,e)*v%e,w=Me(g,i,e)*g%e,S=Me(w,a,e)*w%e,O=Me(S,c,e)*S%e,Y=Me(O,a,e)*w%e,T=Me(Y,t,e)*h%e,b=Me(T,s,e)*g%e,D=Me(b,n,e)*f%e,V=Me(D,Yh,e);if(!Zh.eql(Zh.sqr(V),r))throw new Error("Cannot find square root");return V}var Zh=pn($0,void 0,void 0,{sqrt:VE}),Cr=K0({a:KE,b:BigInt(7),Fp:Zh,n:H0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=H0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-HE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=V0(i*r,e),c=V0(-n*r,e),f=Ce(r-a*t-c*o,e),h=Ce(-a*n-c*i,e),p=f>s,m=h>s;if(p&&(f=e-f),m&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:p,k1:f,k2neg:m,k2:h}}}},Hu);function Jh(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function F0(r,e){let t=tr.digest(e instanceof Uint8Array?e:e.subarray());if(Jh(t))return t.then(({digest:n})=>Cr.sign(n,r).toDERRawBytes()).catch(n=>{throw new Oa(String(n))});try{return Cr.sign(t.digest,r).toDERRawBytes()}catch(n){throw new Oa(String(n))}}function W0(r,e,t){let n=tr.digest(t instanceof Uint8Array?t:t.subarray());if(Jh(n))return n.then(({digest:o})=>Cr.verify(e,o,r)).catch(o=>{throw new Ra(String(o))});try{return Cr.verify(e,n.digest,r)}catch(o){throw new Ra(String(o))}}var Ua=class{type="secp256k1";raw;_key;constructor(e){this._key=z0(e),this.raw=q0(this._key)}toMultihash(){return yr.digest(Vn(this))}toCID(){return Xe.createV1(114,this.toMultihash())}toString(){return Pe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}verify(e,t){return W0(this._key,t,e)}},rl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=G0(e),this.publicKey=new Ua(t??X0(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Fe(this.raw,e.raw)}sign(e){return F0(this.raw,e)}};function Qh(r){return new Ua(r)}async function Y0(){let r=$E();return new rl(r)}function q0(r){return Cr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function G0(r){try{return Cr.getPublicKey(r,!0),r}catch(e){throw new ca(String(e))}}function z0(r){try{return Cr.ProjectivePoint.fromHex(r),r}catch(e){throw new Fi(String(e))}}function X0(r){try{return Cr.getPublicKey(r,!0)}catch(e){throw new ca(String(e))}}function $E(){return Cr.utils.randomPrivateKey()}async function Z0(r,e){if(r==="Ed25519")return v0();if(r==="secp256k1")return Y0();if(r==="RSA")return qh(FE(e));if(r==="ECDSA")return kg(WE(e));throw new jn}function ja(r,e){let{Type:t,Data:n}=Vr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return $h(o,e);case Ye.Ed25519:return gh(o);case Ye.secp256k1:return Qh(o);case Ye.ECDSA:return Zp(o);default:throw new jn}}function J0(r){let{Type:e,Data:t}=Vr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return gh(n);case Ye.secp256k1:return Qh(n);case Ye.ECDSA:return Zp(n);default:throw new jn}}function Vn(r){return Vr.encode({Type:Ye[r.type],Data:r.raw})}function FE(r){return r==null?2048:parseInt(r,10)}function WE(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 Ae("Unsupported curve, should be P-256, P-384 or P-521")}async function nl(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 Ae("Only RSA and ECDSA keys are supported")}var Q0=Symbol.for("nodejs.util.inspect.custom"),qE=114,Ma=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()})`}[Ep]=!0;toString(){return this.string==null&&(this.string=Pe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Xe.createV1(qE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Q0](){return`PeerId(${this.toString()})`}},Ka=class extends Ma{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ha=class extends Ma{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Va=class extends Ma{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},GE=2336,$a=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=yr.digest(de(this.url))}[Q0](){return`PeerId(${this.url})`}[Ep]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Xe.createV1(GE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var zE=114,ew=2336;function is(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Hn(Pe.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return XE(Xe.parse(r));if(e==null)throw new Ae('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Hn(e.decode(r))}return tw(t)}function ed(r){if(r.type==="Ed25519")return new Ha({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Va({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Ka({multihash:r.toCID().multihash,publicKey:r});throw new jn}function tw(r){if(ZE(r))return new Ka({multihash:r});if(YE(r))try{let e=J0(r);if(e.type==="Ed25519")return new Ha({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Va({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new $a(new URL(t))}throw new Bu("Supplied PeerID Multihash is invalid")}function XE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==zE&&r.code!==ew)throw new Tu("Supplied PeerID CID is invalid");if(r.code===ew){let e=ue(r.multihash.digest);return new $a(new URL(e))}return tw(r.multihash)}function YE(r){return r.code===yr.code}function ZE(r){return r.code===tr.code}var ol=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let 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>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var rw=45,JE=15,ss=new ol;function td(r){if(!(r.length>JE))return ss.new(r).parseWith(()=>ss.readIPv4Addr())}function rd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>rw))return ss.new(r).parseWith(()=>ss.readIPv6Addr())}function il(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>rw)return;let t=ss.new(r).parseWith(()=>ss.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var u4=parseInt("0xFFFF",16),l4=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sl(r){return!!td(r)}function al(r){return!!rd(r)}function cl(r){return!!il(r)}var iw=sl,n2=al,nd=function(r){let e=0;if(r=r.toString().trim(),iw(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(n2(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=iw(t[n]),s;i&&(s=nd(t[n]),t[n]=ue(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ue(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},sw=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var as={},od={},i2=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];i2.forEach(r=>{let e=s2(...r);od[e.code]=e,as[e.name]=e});function s2(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Re(r){if(typeof r=="number"){if(od[r]!=null)return od[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(as[r]!=null)return as[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var G4=Re("ip4"),z4=Re("ip6"),X4=Re("ipcidr");function cd(r,e){switch(Re(r).code){case 4:case 41:return c2(e);case 42:return ad(e);case 43:return ue(e,"base10");case 6:case 273:case 33:case 132:return uw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ad(e);case 421:return p2(e);case 444:return cw(e);case 445:return cw(e);case 466:return f2(e);case 481:return globalThis.encodeURIComponent(ad(e));default:return ue(e,"base16")}}function ud(r,e){switch(Re(r).code){case 4:return aw(e);case 41:return aw(e);case 42:return sd(e);case 43:return de(e,"base10");case 6:case 273:case 33:case 132:return ld(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sd(e);case 421:return u2(e);case 444:return h2(e);case 445:return d2(e);case 466:return l2(e);case 481:return sd(globalThis.decodeURIComponent(e));default:return de(e,"base16")}}var id=Object.values(Po).map(r=>r.decoder),a2=function(){let r=id[0].or(id[1]);return id.slice(2).forEach(e=>r=r.or(e)),r}();function aw(r){if(!cl(r))throw new Error("invalid ip address");return nd(r)}function c2(r){let e=sw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!cl(e))throw new Error("invalid ip address");return e}function ld(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function uw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sd(r){let e=de(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function ad(r){let e=vr(r);if(r=r.slice(Ke(e)),r.length!==e)throw new Error("inconsistent lengths");return ue(r)}function u2(r){let e;r[0]==="Q"||r[0]==="1"?e=Hn(Pe.decode(`z${r}`)).bytes:e=Xe.parse(r).multihash.bytes;let t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function l2(r){let e=a2.decode(r),t=Uint8Array.from(Hr(e.length));return ot([t,e],t.length+e.length)}function f2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ue(t,"base64url")}function p2(r){let e=vr(r),t=r.slice(Ke(e));if(t.length!==e)throw new Error("inconsistent lengths");return ue(t,"base58btc")}function h2(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=an.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function d2(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=an.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return ot([t,o],t.length+o.length)}function cw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ue(e,"base32"),o=uw(t);return`${n}:${o}`}function lw(r){r=fd(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=Re(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new ul("invalid address: "+r);if(a.path===!0){n=fd(o.slice(i).join("/")),e.push([a.code,ud(a.code,n)]),t.push([a.code,n]);break}let c=ud(a.code,o[i]);e.push([a.code,c]),t.push([a.code,cd(a.code,c)])}return{string:fw(t),bytes:ll(e),tuples:e,stringTuples:t,path:n}}function pd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=vr(r,o),s=Ke(i),a=Re(i),c=m2(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new ul("Invalid address Uint8Array: "+ue(r,"base16"));e.push([i,f]);let h=cd(i,f);if(t.push([i,h]),a.path===!0){n=h;break}}return{bytes:Uint8Array.from(r),string:fw(t),tuples:e,stringTuples:t,path:n}}function fw(r){let e=[];return r.map(t=>{let n=Re(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),fd(e.join("/"))}function ll(r){return ot(r.map(e=>{let t=Re(e[0]),n=Uint8Array.from(Hr(t.code));return e.length>1&&e[1]!=null&&(n=ot([n,e[1]])),n}))}function m2(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=vr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Ke(t)}}function fd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var ul=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var y2=Symbol.for("nodejs.util.inspect.custom"),dd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),g2=[Re("dns").code,Re("dns4").code,Re("dns6").code,Re("dnsaddr").code],hd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},fl=class r{bytes;#e;#t;#r;#n;[dd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=pd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=lw(e)}else if(hw(e))t=pd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=Re("tcp"),a=Re("udp"),c=Re("ip4"),f=Re("ip6"),h=Re("dns6"),p=Re("ip6zone");for(let[v,g]of this.stringTuples())v===p.code&&(i=`%${g??""}`),g2.includes(v)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${i}`,e=v===h.code?6:4),(v===s.code||v===a.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(v===c.code||v===f.code)&&(t=Re(v).name==="tcp"?"tcp":"udp",n=`${g??""}${i}`,e=v===f.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},Re(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Re(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ll(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===as.p2p.code&&e.push([n,o]),n===as["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ue(Pe.decode(`z${n}`),"base58btc"):ue(Xe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Fe(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=pw.get(t.name);if(n==null)throw new hd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>$r(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[y2](){return`Multiaddr(${this.#e})`}};var pw=new Map;function hw(r){return!!r?.[dd]}function $r(r){return new fl(r)}var w2=r=>r.toString().split("/").slice(1),cs=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>cs(t=>t===r).match(e),pattern:r}),$o=()=>({match:r=>cs(e=>typeof e=="string").match(r),pattern:"{string}"}),us=()=>({match:r=>cs(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Be=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Pe.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Fa=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ko.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ie=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),_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},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),ve=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function De(...r){function e(o){let i=w2(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var x2=Be(),C5=De(x2),hl=ve(ye("dns4"),$o()),dl=ve(ye("dns6"),$o()),ml=ve(ye("dnsaddr"),$o()),yd=ve(ye("dns"),$o()),I5=De(hl,Ie(Be())),T5=De(dl,Ie(Be())),B5=De(ml,Ie(Be())),k5=De(_t(yd,ml,hl,dl),Ie(Be())),dw=ve(ye("ip4"),cs(sl)),mw=ve(ye("ip6"),cs(al)),gd=_t(dw,mw),mn=_t(gd,yd,hl,dl,ml),P5=De(_t(gd,ve(_t(yd,ml,hl,dl),Ie(Be())))),N5=De(dw),O5=De(mw),R5=De(gd),wd=ve(mn,ye("tcp"),us()),Wa=ve(mn,ye("udp"),us()),D5=De(ve(wd,Ie(Be()))),L5=De(Wa),xd=ve(Wa,ye("quic"),Ie(Be())),yl=ve(Wa,ye("quic-v1"),Ie(Be())),b2=_t(xd,yl),U5=De(xd),j5=De(yl),md=_t(mn,wd,Wa,xd,yl),yw=_t(ve(md,ye("ws"),Ie(Be()))),M5=De(yw),gw=_t(ve(md,ye("wss"),Ie(Be())),ve(md,ye("tls"),Ie(ve(ye("sni"),$o())),ye("ws"),Ie(Be()))),K5=De(gw),ww=ve(Wa,ye("webrtc-direct"),Ie(Fa()),Ie(Fa()),Ie(Be())),xw=De(ww),bw=ve(yl,ye("webtransport"),Ie(Fa()),Ie(Fa()),Ie(Be())),H5=De(bw),pl=_t(yw,gw,ve(wd,Ie(Be())),ve(b2,Ie(Be())),ve(mn,Ie(Be())),ww,bw,Be()),vw=De(pl),v2=ve(pl,ye("p2p-circuit"),Be()),V5=De(v2),A2=_t(ve(pl,ye("p2p-circuit"),ye("webrtc"),Ie(Be())),ve(pl,ye("webrtc"),Ie(Be())),ve(ye("webrtc"),Ie(Be()))),Aw=De(A2),S2=_t(ve(mn,ye("tcp"),us(),ye("http"),Ie(Be())),ve(mn,ye("http"),Ie(Be()))),$5=De(S2),E2=_t(ve(mn,ye("tcp"),_t(ve(ye("443"),ye("http")),ve(us(),ye("https")),ve(us(),ye("tls"),ye("http"))),Ie(Be())),ve(mn,ye("tls"),ye("http"),Ie(Be())),ve(mn,ye("https"),Ie(Be()))),F5=De(E2),_2=_t(ve(ye("memory"),$o(),Ie(Be()))),W5=De(_2);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=()=>Vo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Ct||(Ct={}));var Sw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],bd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Ew="libp2p+webrtc+v1/";var _w=466,Cw=2*1024*1024,Iw=30*1e3,ls=16*1024;function C2(r=ls){let e=Ke(r-Ke(r)),t=1+Ke(Object.keys(Ct.Flag).length-1),n=1,o=r-e-t-n,i=Ke(o);return e+t+n+i}var Tw=C2(),Bw=5e3,kw=5e3,Pw=3e4,vd="/webrtc",qa="/webrtc-signaling/0.0.1",Nw="/libp2p/webrtc-direct/certificate",Ow="webrtc-direct-certificate-private-key";var Rw=12096e5,Ad=864e5;var Dw=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))},I2=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var T2=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var B2=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 k2=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var P2=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var N2=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,O2=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Lw=3,R2=[["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",N2]],Uw=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Mw(r){return r?jw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new P2:typeof navigator<"u"?jw(navigator.userAgent):U2()}function D2(r){return r!==""&&R2.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 jw(r){var e=D2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new k2;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Lw&&(o=Dw(Dw([],o,!0),j2(Lw-o.length),!0)):o=[];var i=o.join("."),s=L2(r),a=O2.exec(r);return a&&a[1]?new B2(t,i,s,a[1]):new I2(t,i,s)}function L2(r){for(var e=0,t=Uw.length;e<t;e++){var n=Uw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function U2(){var r=typeof process<"u"&&process.version;return r?new T2(process.version.slice(1)):null}function j2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Ze(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Sd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ed=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Kw=r=>globalThis.DOMException===void 0?new Ed(r):new DOMException(r),Hw=r=>{let e=r.reason===void 0?Kw("This operation was aborted."):r.reason;return e instanceof Error?e:Kw(e)};function Ga(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,f=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:v}=e;v.aborted&&p(Hw(v)),a=()=>{p(Hw(v))},v.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let m=new Sd;s=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(v){p(v)}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(v){p(v)}})()}).finally(()=>{f.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return f.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},f}var Vw=Mw(),za=Vw!=null&&Vw.name==="firefox",gl=async function*(){},wl=async r=>{};function $w(r,e,t=Pw,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=Ze(),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 Ga(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function _d(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??Sw.map(e=>({urls:[e]})),r}var Fw=(r=32)=>Ew+[...Array(r)].map(()=>bd.at(Math.floor(Math.random()*bd.length))).join("");var Fo=class{log;peerConnection;remoteAddr;timeline;metrics;source=gl();sink=wl;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 xl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xl(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 xl(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 Cd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function ps(r={}){return M2(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 M2(r,e){e=e??{};let t=e.onEnd,n=new fs,o,i,s,a=Ze(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((S,O)=>{i=Y=>{i=null,n.push(Y);try{S(r(n))}catch(T){O(T)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ze()})}},f=S=>i!=null?i(S):(n.push(S),o),h=S=>(n=new fs,i!=null?i({error:S}):(n.push({error:S}),o)),p=S=>{if(s)return o;if(e?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},m=S=>s?o:(s=!0,S!=null?h(S):f({done:!0})),v=()=>(n=new fs,m(),{done:!0}),g=S=>(m(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:g,push:p,end:m,get readableLength(){return n.size},onEmpty:async S=>{let O=S?.signal;if(O?.throwIfAborted(),n.isEmpty())return;let Y,T;O!=null&&(Y=new Promise((b,D)=>{T=()=>{D(new Cd)},O.addEventListener("abort",T)}));try{await Promise.race([a.promise,Y])}finally{T!=null&&O!=null&&O?.removeEventListener("abort",T)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(S){return w.throw(S),t!=null&&(t(S),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:p,end(S){return w.end(S),t!=null&&(t(S),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:S=>w.onEmpty(S)},o}var bl=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 rr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new bl(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new bl(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 Ww(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 qw(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gw(r,e){let t=Ww(r).return?.();qw(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var K2=5e3;function Id(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var vl=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=Ze(),this.closed=Ze(),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??K2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=ps({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 Io(`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);Id(o)&&await o}let n=()=>{Gw(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new be(o):o;let i=this.sendData(o,t);Id(i)&&(this.sendingData=Ze(),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 rr(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 rr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await rr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await rr(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();Id(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 Iu("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 Td(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 Al=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},hs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Sl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Xa=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function El(r){return r[Symbol.asyncIterator]!=null}function zw(r,e){if(r.byteLength>e)throw new hs("Message length too long")}var Cl=r=>{let e=Ke(r),t=nt(e);return Hr(r,t),Cl.bytes=e,t};Cl.bytes=0;function Ya(r,e){e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;function*o(i){zw(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return El(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}Ya.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Cl,n=e?.maxDataLength??4194304;return zw(r,n),new be(t(r.byteLength),r)};var Wo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Wo||(Wo={}));var Bd=r=>{let e=vr(r);return Bd.bytes=Ke(e),e};Bd.bytes=0;function qo(r,e){let t=new be,n=Wo.LENGTH,o=-1,i=e?.lengthDecoder??Bd,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Wo.LENGTH)try{if(o=i(t),o<0)throw new Al("Invalid message length");if(o>a)throw new hs("Message length too long");let f=i.bytes;t.consume(f),e?.onLength!=null&&e.onLength(o),n=Wo.DATA}catch(f){if(f instanceof RangeError){if(t.byteLength>s)throw new Sl("Message length length too long");break}throw f}if(n===Wo.DATA){if(t.byteLength<o)break;let f=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(f),yield f,n=Wo.LENGTH}}}return El(r)?async function*(){for await(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}():function*(){for(let f of r)t.append(f),yield*c();if(t.byteLength>0)throw new Xa("Unexpected end of input")}()}qo.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 qo(n,{...e??{},onLength:i=>{t=i}})};var kd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Za(r,e,t,n){let o=new kd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",h),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,f)}let c=p=>{try{if(n?.filter?.(p)===!1)return}catch(m){a(),s(m);return}a(),i(p)},f=p=>{a(),s(p.detail)},h=()=>{a(),s(o)};t?.addEventListener("abort",h),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,f)})}var Pd=class extends vl{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 Ga(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=ps(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Iw,this.maxBufferedAmount=e.maxBufferedAmount??Cw,this.maxMessageSize=(e.maxMessageSize??ls)-Tw,this.receiveFinAck=Ze(),this.finAckTimeout=e.closeTimeout??Bw,this.openTimeout=e.openTimeout??kw,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 Io("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 qo(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new be(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new Io(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Td([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 Za(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=Td([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await Za(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Pu(`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=Ya.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 rr(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=Ya.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 ds(r){let{channel:e,direction:t,handshake:n}=r;return new Pd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var Qn=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??vd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=ds({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Nd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Nd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??vd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=ds({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),$w(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=gl();sink=wl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=ds({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Il=globalThis.RTCPeerConnection,Tl=globalThis.RTCSessionDescription,Xw=globalThis.RTCIceCandidate;var Od=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ze(),this.haveNext=Ze()}[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=Ze(),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=Ze(),await rr(this.readNext.promise,t?.signal,t)}};function Bl(){return new Od}var kl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Yw(r,e){let t=Bl();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new be;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:f}=await rr(n.next(),s?.signal);return c===!0?null:f}for(;o.byteLength<s.bytes;){let{value:c,done:f}=await rr(n.next(),s?.signal);if(f===!0)throw new kl("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 Pl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Nl=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ja(r,e={}){let t=Yw(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ke(e.maxDataLength));let n=e?.lengthDecoder??vr,o=e?.lengthEncoder??Hr;return{read:async s=>{let a=-1,c=new be;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(f){if(f instanceof RangeError)continue;throw f}if(a<0)throw new Pl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ol("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Nl("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new be(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new be(...s.flatMap(f=>[o(f.byteLength),f]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Rl(r,e){let t=Ja(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Yt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var eo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},nr=class extends eo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Dl=class extends eo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Ll=class extends eo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Ul=class extends eo{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 Lt;(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=()=>Vo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=_r((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Er(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(Lt||(Lt={}));var jl=async(r,e,t)=>{try{let n=Ze();for($2(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!==Lt.Type.ICE_CANDIDATE)throw new ku("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Yt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new Xw(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Yt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Ml(r)!=="connected")throw n}};function Ml(r){return za?r.iceConnectionState:r.connectionState}function $2(r,e){r[za?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Ml(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Cu("RTCPeerConnection was closed"));break;default:break}}}async function Zw({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:f}){let{baseAddr:h}=Jw(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",h);let p=h.getPeerId();if(p==null)throw new Ae("Relay peer was missing");let m=i.getConnections(is(p)),v,g=!1;m.length===0?(f?.(new Yt("webrtc:dial-relay")),v=await s.dial(h,{signal:t,onProgress:f}),g=!0):(f?.(new Yt("webrtc:reuse-relay-connection")),v=m[0]);try{f?.(new Yt("webrtc:open-signaling-stream"));let w=await v.newStream(qa,{signal:t,runOnLimitedConnection:!0}),S=Rl(w).pb(Lt),O=new Il(r),Y=new Qn({logger:c},{peerConnection:O,dataChannelOptions:e});try{let T=O.createDataChannel("init");O.onicecandidate=({candidate:N})=>{let U=JSON.stringify(N?.toJSON()??null);a.trace("initiator sending ICE candidate %o",N),S.write({type:Lt.Type.ICE_CANDIDATE,data:U},{signal:t}).catch($=>{a.error("error sending ICE candidate",$)})},O.onicecandidateerror=N=>{a.error("initiator ICE candidate error",N)};let b=await O.createOffer().catch(N=>{throw a.error("could not execute createOffer",N),new nr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",b.sdp),f?.(new Yt("webrtc:send-sdp-offer")),await S.write({type:Lt.Type.SDP_OFFER,data:b.sdp},{signal:t}),await O.setLocalDescription(b).catch(N=>{throw a.error("could not execute setLocalDescription",N),new nr("Failed to set localDescription")}),f?.(new Yt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let D=await S.read({signal:t});if(D.type!==Lt.Type.SDP_ANSWER)throw new nr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",D.data);let V=new Tl({type:"answer",sdp:D.data});return await O.setRemoteDescription(V).catch(N=>{throw a.error("could not execute setRemoteDescription",N),new nr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),f?.(new Yt("webrtc:read-ice-candidates")),await jl(O,S,{direction:"initiator",signal:t,log:a,onProgress:f}),a.trace("initiator connected, closing init channel"),T.close(),f?.(new Yt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await w.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:O,muxerFactory:Y}}catch(T){throw a.error("outgoing signaling error",T),O.close(),w.abort(T),T}finally{O.onicecandidate=null,O.onicecandidateerror=null}}finally{if(g)try{await v.close({signal:t})}catch(w){v.abort(w)}}}var Qw=De(vw.matchers[0],ye("p2p-circuit")),Kl=class r extends Mn{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Qw.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Qw.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function ex({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Rl(e).pb(Lt);try{r.onicecandidate=({candidate:h})=>{let p=JSON.stringify(h?.toJSON()??null);o.trace("recipient sending ICE candidate %s",p),i.write({type:Lt.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!==Lt.Type.SDP_OFFER)throw new nr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Tl({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(h=>{throw o.error("could not execute setRemoteDescription",h),new nr("Failed to set remoteDescription")});let f=await r.createAnswer().catch(h=>{throw o.error("could not execute createAnswer",h),new nr("Failed to create answer")});o.trace("recipient send SDP answer %s",f.sdp),await i.write({type:Lt.Type.SDP_ANSWER,data:f.sdp},{signal:t}),await r.setLocalDescription(f).catch(h=>{throw o.error("could not execute setLocalDescription",h),new nr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await jl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Ml(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=$r(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Hl=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"})})}[Su]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Wi]=["@libp2p/transport"];[Qy]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(qa,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(qa),this._started=!1}createListener(e){return new Kl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Aw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async dial(e,t){this.log.trace("dialing address: %a",e);let{remoteAddress:n,peerConnection:o,muxerFactory:i}=await Zw({rtcConfiguration:await _d(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 Fo(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 Il(await _d(this.init.rtcConfiguration)),i=new Qn(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await ex({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Fo(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Jw(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new Ae("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new Ae("p2p-circuit protocol was not present in multiaddr");let t=$r(e[0]),o=$r("/"+e[1]).getPeerId();if(o==null)throw new Ae("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new Ae("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:is(o)}}var cG=Lr(rx());var Gr={};bt(Gr,{Any:()=>Wr,BaseBlock:()=>Je,BaseStringBlock:()=>rc,BitString:()=>Br,BmpString:()=>Zo,Boolean:()=>zo,CharacterString:()=>si,Choice:()=>gs,Constructed:()=>it,DATE:()=>cc,DateTime:()=>lc,Duration:()=>fc,EndOfContent:()=>nc,Enumerated:()=>Xo,GeneralString:()=>ii,GeneralizedTime:()=>ai,GraphicString:()=>oi,HexBlock:()=>qr,IA5String:()=>ni,Integer:()=>bn,Null:()=>Ir,NumericString:()=>Qo,ObjectIdentifier:()=>Yo,OctetString:()=>Tr,Primitive:()=>xn,PrintableString:()=>ei,RawData:()=>Ud,RelativeObjectIdentifier:()=>ac,Repeated:()=>ci,Sequence:()=>Mt,Set:()=>Kt,TIME:()=>pc,TeletexString:()=>ti,TimeOfDay:()=>uc,UTCTime:()=>oo,UniversalString:()=>Jo,Utf8String:()=>ir,ValueBlock:()=>ft,VideotexString:()=>ri,ViewWriter:()=>ys,VisibleString:()=>no,compareSchema:()=>ro,fromBER:()=>An,verifySchema:()=>l_});var me=Lr(gn());function Go(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 to(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let h=a-1;h>=0;h--){let p=Math.pow(2,h*e);f[i-h-1]=Math.floor(o/p),o-=f[i-h-1]*p}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Fl(...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 Dd(){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=Go(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,Go(i,8)-n}function nx(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=to(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=to(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function ox(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Ut(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 xP=Math.log(2);function Wl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function jd(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 vn(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 ys=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return jd(this.items)}},Qa=[new Uint8Array([1])],ix="0123456789",Ld="name",sx="valueHexView",J2="isHexOnly",Q2="idBlock",e_="tagClass",t_="tagNumber",r_="isConstructed",n_="fromBER",o_="toBER",i_="local",jt="",kr=new ArrayBuffer(0),af=new Uint8Array(0),tc="EndOfContent",cx="OCTET STRING",ux="BIT STRING";function qr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?me.BufferSourceConverter.toUint8Array(i.valueHex):af}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!vn(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",kr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:me.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var wn=class{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=jt,warnings:n=[],valueBeforeDecode:o=af}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=me.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:me.Convert.ToHex(this.valueBeforeDecodeView)}}};wn.NAME="baseBlock";var ft=class extends wn{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};ft.NAME="valueBlock";var ql=class extends qr(wn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?me.BufferSourceConverter.toUint8Array(e.valueHex):af,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",kr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=to(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),h=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;let m=new Uint8Array(h);for(let v=0;v<f.length;v++)m[v]=f[v];f=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,f[c-1]=i[c]&127;let p=new Uint8Array(c);for(let m=0;m<c;m++)p[m]=f[m];f=this.valueHexView=new Uint8Array(c),f.set(p),this.blockLength<=9?this.tagNumber=Go(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};ql.NAME="identificationBlock";var Gl=class extends wn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(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=Go(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=to(this.length,8);if(o.byteLength>127)return this.error="Too big length",kr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Gl.NAME="lengthBlock";var Z={},Je=class extends wn{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 ql(o),this.lenBlock=new Gl(o),this.valueBlock=i?new i(o):new ft(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new ys;t||lx(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?kr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():me.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return ox(t,n)}};Je.NAME="BaseBlock";function lx(r){var e;if(r instanceof Z.Constructed)for(let t of r.valueBlock.value)lx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var rc=class extends Je{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}'`}};rc.NAME="BaseStringBlock";var zl=class extends qr(ft){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};zl.NAME="PrimitiveValueBlock";var fx,xn=class extends Je{constructor(e={}){super(e,zl),this.idBlock.isConstructed=!1}};fx=xn;Z.Primitive=fx;xn.NAME="PRIMITIVE";function s_(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 ws(r,e=0,t=r.length){let n=e,o=new Je({},ft),i=new wn;if(!vn(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Je;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=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 f=o.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Z.Constructed:Z.Primitive}return o=s_(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 An(r){if(!r.byteLength){let e=new Je({},ft);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ws(me.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function a_(r,e){return r?1:e}var Fr=class extends ft{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(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(;a_(this.isIndefiniteForm,n)>0;){let s=ws(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===tc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===tc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new ys;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?kr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Fr.NAME="ConstructedValueBlock";var px,it=class extends Je{constructor(e={}){super(e,Fr),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 E_=Object.create;var Tu=Object.defineProperty;var T_=Object.getOwnPropertyDescriptor;var C_=Object.getOwnPropertyNames;var I_=Object.getPrototypeOf,O_=Object.prototype.hasOwnProperty;var Pp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_t=(r,e)=>{for(var t in e)Tu(r,t,{get:e[t],enumerable:!0})},ng=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C_(e))!O_.call(r,o)&&o!==t&&Tu(r,o,{get:()=>e[o],enumerable:!(n=T_(e,o))||n.enumerable});return r};var Hr=(r,e,t)=>(t=r!=null?E_(I_(r)):{},ng(e||!r||!r.__esModule?Tu(t,"default",{value:r,enumerable:!0}):t,r)),B_=r=>ng(Tu({},"__esModule",{value:!0}),r);var fb=Pp(()=>{var lb;(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(p,f){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:f}),l&&l(p,f)}}function i(){try{return Function("return this;")()}catch{}}function s(){try{return(0,eval)("(function() { return this; })()")}catch{}}function a(){return i()||s()}})(function(e,t){var n=Object.prototype.hasOwnProperty,o=typeof Symbol=="function",i=o&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",s=o&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",c={__proto__:[]}instanceof Array,l=!a&&!c,p={create:a?function(){return Bp(Object.create(null))}:c?function(){return Bp({__proto__:null})}:function(){return Bp({})},has:l?function(x,A){return n.call(x,A)}:function(x,A){return A in x},get:l?function(x,A){return n.call(x,A)?x[A]:void 0}:function(x,A){return x[A]}},f=Object.getPrototypeOf(Function),m=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:x_(),y=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:v_(),b=typeof WeakMap=="function"?WeakMap:__(),v=o?Symbol.for("@reflect-metadata:registry"):void 0,d=g_(),T=w_(d);function D(x,A,k,$){if(U(k)){if(!rr(x))throw new TypeError;if(!Zm(A))throw new TypeError;return O(x,A)}else{if(!rr(x))throw new TypeError;if(!se(A))throw new TypeError;if(!se($)&&!U($)&&!he($))throw new TypeError;return he($)&&($=void 0),k=lt(k),P(x,A,k,$)}}e("decorate",D);function j(x,A){function k($,ue){if(!se($))throw new TypeError;if(!U(ue)&&!y_(ue))throw new TypeError;X(x,A,$,ue)}return k}e("metadata",j);function Z(x,A,k,$){if(!se(k))throw new TypeError;return U($)||($=lt($)),X(x,A,k,$)}e("defineMetadata",Z);function B(x,A,k){if(!se(A))throw new TypeError;return U(k)||(k=lt(k)),R(x,A,k)}e("hasMetadata",B);function G(x,A,k){if(!se(A))throw new TypeError;return U(k)||(k=lt(k)),N(x,A,k)}e("hasOwnMetadata",G);function M(x,A,k){if(!se(A))throw new TypeError;return U(k)||(k=lt(k)),L(x,A,k)}e("getMetadata",M);function K(x,A,k){if(!se(A))throw new TypeError;return U(k)||(k=lt(k)),F(x,A,k)}e("getOwnMetadata",K);function g(x,A){if(!se(x))throw new TypeError;return U(A)||(A=lt(A)),W(x,A)}e("getMetadataKeys",g);function I(x,A){if(!se(x))throw new TypeError;return U(A)||(A=lt(A)),ie(x,A)}e("getOwnMetadataKeys",I);function E(x,A,k){if(!se(A))throw new TypeError;if(U(k)||(k=lt(k)),!se(A))throw new TypeError;U(k)||(k=lt(k));var $=pa(A,k,!1);return U($)?!1:$.OrdinaryDeleteMetadata(x,A,k)}e("deleteMetadata",E);function O(x,A){for(var k=x.length-1;k>=0;--k){var $=x[k],ue=$(A);if(!U(ue)&&!he(ue)){if(!Zm(ue))throw new TypeError;A=ue}}return A}function P(x,A,k,$){for(var ue=x.length-1;ue>=0;--ue){var ze=x[ue],nt=ze(A,k,$);if(!U(nt)&&!he(nt)){if(!se(nt))throw new TypeError;$=nt}}return $}function R(x,A,k){var $=N(x,A,k);if($)return!0;var ue=Op(A);return he(ue)?!1:R(x,ue,k)}function N(x,A,k){var $=pa(A,k,!1);return U($)?!1:tt($.OrdinaryHasOwnMetadata(x,A,k))}function L(x,A,k){var $=N(x,A,k);if($)return F(x,A,k);var ue=Op(A);if(!he(ue))return L(x,ue,k)}function F(x,A,k){var $=pa(A,k,!1);if(!U($))return $.OrdinaryGetOwnMetadata(x,A,k)}function X(x,A,k,$){var ue=pa(k,$,!0);ue.OrdinaryDefineOwnMetadata(x,A,k,$)}function W(x,A){var k=ie(x,A),$=Op(x);if($===null)return k;var ue=W($,A);if(ue.length<=0)return k;if(k.length<=0)return ue;for(var ze=new y,nt=[],ge=0,J=k;ge<J.length;ge++){var ee=J[ge],re=ze.has(ee);re||(ze.add(ee),nt.push(ee))}for(var ne=0,we=ue;ne<we.length;ne++){var ee=we[ne],re=ze.has(ee);re||(ze.add(ee),nt.push(ee))}return nt}function ie(x,A){var k=pa(x,A,!1);return k?k.OrdinaryOwnMetadataKeys(x,A):[]}function Y(x){if(x===null)return 1;switch(typeof x){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return x===null?1:6;default:return 6}}function U(x){return x===void 0}function he(x){return x===null}function Oe(x){return typeof x=="symbol"}function se(x){return typeof x=="object"?x!==null:typeof x=="function"}function Re(x,A){switch(Y(x)){case 0:return x;case 1:return x;case 2:return x;case 3:return x;case 4:return x;case 5:return x}var k=A===3?"string":A===5?"number":"default",$=Ym(x,i);if($!==void 0){var ue=$.call(x,k);if(se(ue))throw new TypeError;return ue}return vt(x,k==="default"?"number":k)}function vt(x,A){if(A==="string"){var k=x.toString;if(qi(k)){var $=k.call(x);if(!se($))return $}var ue=x.valueOf;if(qi(ue)){var $=ue.call(x);if(!se($))return $}}else{var ue=x.valueOf;if(qi(ue)){var $=ue.call(x);if(!se($))return $}var ze=x.toString;if(qi(ze)){var $=ze.call(x);if(!se($))return $}}throw new TypeError}function tt(x){return!!x}function rt(x){return""+x}function lt(x){var A=Re(x,3);return Oe(A)?A:rt(A)}function rr(x){return Array.isArray?Array.isArray(x):x instanceof Object?x instanceof Array:Object.prototype.toString.call(x)==="[object Array]"}function qi(x){return typeof x=="function"}function Zm(x){return typeof x=="function"}function y_(x){switch(Y(x)){case 3:return!0;case 4:return!0;default:return!1}}function Ip(x,A){return x===A||x!==x&&A!==A}function Ym(x,A){var k=x[A];if(k!=null){if(!qi(k))throw new TypeError;return k}}function Jm(x){var A=Ym(x,s);if(!qi(A))throw new TypeError;var k=A.call(x);if(!se(k))throw new TypeError;return k}function Qm(x){return x.value}function eg(x){var A=x.next();return A.done?!1:A}function tg(x){var A=x.return;A&&A.call(x)}function Op(x){var A=Object.getPrototypeOf(x);if(typeof x!="function"||x===f||A!==f)return A;var k=x.prototype,$=k&&Object.getPrototypeOf(k);if($==null||$===Object.prototype)return A;var ue=$.constructor;return typeof ue!="function"||ue===x?A:ue}function m_(){var x;!U(v)&&typeof t.Reflect<"u"&&!(v in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(x=b_(t.Reflect));var A,k,$,ue=new b,ze={registerProvider:nt,getProvider:J,setProvider:re};return ze;function nt(ne){if(!Object.isExtensible(ze))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case x===ne:break;case U(A):A=ne;break;case A===ne:break;case U(k):k=ne;break;case k===ne:break;default:$===void 0&&($=new y),$.add(ne);break}}function ge(ne,we){if(!U(A)){if(A.isProviderFor(ne,we))return A;if(!U(k)){if(k.isProviderFor(ne,we))return A;if(!U($))for(var Me=Jm($);;){var Xe=eg(Me);if(!Xe)return;var wr=Qm(Xe);if(wr.isProviderFor(ne,we))return tg(Me),wr}}}if(!U(x)&&x.isProviderFor(ne,we))return x}function J(ne,we){var Me=ue.get(ne),Xe;return U(Me)||(Xe=Me.get(we)),U(Xe)&&(Xe=ge(ne,we),U(Xe)||(U(Me)&&(Me=new m,ue.set(ne,Me)),Me.set(we,Xe))),Xe}function ee(ne){if(U(ne))throw new TypeError;return A===ne||k===ne||!U($)&&$.has(ne)}function re(ne,we,Me){if(!ee(Me))throw new Error("Metadata provider not registered.");var Xe=J(ne,we);if(Xe!==Me){if(!U(Xe))return!1;var wr=ue.get(ne);U(wr)&&(wr=new m,ue.set(ne,wr)),wr.set(we,Me)}return!0}}function g_(){var x;return!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&(x=t.Reflect[v]),U(x)&&(x=m_()),!U(v)&&se(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,v,{enumerable:!1,configurable:!1,writable:!1,value:x}),x}function w_(x){var A=new b,k={isProviderFor:function(ee,re){var ne=A.get(ee);return U(ne)?!1:ne.has(re)},OrdinaryDefineOwnMetadata:nt,OrdinaryHasOwnMetadata:ue,OrdinaryGetOwnMetadata:ze,OrdinaryOwnMetadataKeys:ge,OrdinaryDeleteMetadata:J};return d.registerProvider(k),k;function $(ee,re,ne){var we=A.get(ee),Me=!1;if(U(we)){if(!ne)return;we=new m,A.set(ee,we),Me=!0}var Xe=we.get(re);if(U(Xe)){if(!ne)return;if(Xe=new m,we.set(re,Xe),!x.setProvider(ee,re,k))throw we.delete(re),Me&&A.delete(ee),new Error("Wrong provider for target.")}return Xe}function ue(ee,re,ne){var we=$(re,ne,!1);return U(we)?!1:tt(we.has(ee))}function ze(ee,re,ne){var we=$(re,ne,!1);if(!U(we))return we.get(ee)}function nt(ee,re,ne,we){var Me=$(ne,we,!0);Me.set(ee,re)}function ge(ee,re){var ne=[],we=$(ee,re,!1);if(U(we))return ne;for(var Me=we.keys(),Xe=Jm(Me),wr=0;;){var rg=eg(Xe);if(!rg)return ne.length=wr,ne;var A_=Qm(rg);try{ne[wr]=A_}catch(S_){try{tg(Xe)}finally{throw S_}}wr++}}function J(ee,re,ne){var we=$(re,ne,!1);if(U(we)||!we.delete(ee))return!1;if(we.size===0){var Me=A.get(re);U(Me)||(Me.delete(ne),Me.size===0&&A.delete(Me))}return!0}}function b_(x){var A=x.defineMetadata,k=x.hasOwnMetadata,$=x.getOwnMetadata,ue=x.getOwnMetadataKeys,ze=x.deleteMetadata,nt=new b,ge={isProviderFor:function(J,ee){var re=nt.get(J);return!U(re)&&re.has(ee)?!0:ue(J,ee).length?(U(re)&&(re=new y,nt.set(J,re)),re.add(ee),!0):!1},OrdinaryDefineOwnMetadata:A,OrdinaryHasOwnMetadata:k,OrdinaryGetOwnMetadata:$,OrdinaryOwnMetadataKeys:ue,OrdinaryDeleteMetadata:ze};return ge}function pa(x,A,k){var $=d.getProvider(x,A);if(!U($))return $;if(k){if(d.setProvider(x,A,T))return T;throw new Error("Illegal state.")}}function x_(){var x={},A=[],k=function(){function ge(J,ee,re){this._index=0,this._keys=J,this._values=ee,this._selector=re}return ge.prototype["@@iterator"]=function(){return this},ge.prototype[s]=function(){return this},ge.prototype.next=function(){var J=this._index;if(J>=0&&J<this._keys.length){var ee=this._selector(this._keys[J],this._values[J]);return J+1>=this._keys.length?(this._index=-1,this._keys=A,this._values=A):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},ge.prototype.throw=function(J){throw this._index>=0&&(this._index=-1,this._keys=A,this._values=A),J},ge.prototype.return=function(J){return this._index>=0&&(this._index=-1,this._keys=A,this._values=A),{value:J,done:!0}},ge}(),$=function(){function ge(){this._keys=[],this._values=[],this._cacheKey=x,this._cacheIndex=-2}return Object.defineProperty(ge.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),ge.prototype.has=function(J){return this._find(J,!1)>=0},ge.prototype.get=function(J){var ee=this._find(J,!1);return ee>=0?this._values[ee]:void 0},ge.prototype.set=function(J,ee){var re=this._find(J,!0);return this._values[re]=ee,this},ge.prototype.delete=function(J){var ee=this._find(J,!1);if(ee>=0){for(var re=this._keys.length,ne=ee+1;ne<re;ne++)this._keys[ne-1]=this._keys[ne],this._values[ne-1]=this._values[ne];return this._keys.length--,this._values.length--,Ip(J,this._cacheKey)&&(this._cacheKey=x,this._cacheIndex=-2),!0}return!1},ge.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=x,this._cacheIndex=-2},ge.prototype.keys=function(){return new k(this._keys,this._values,ue)},ge.prototype.values=function(){return new k(this._keys,this._values,ze)},ge.prototype.entries=function(){return new k(this._keys,this._values,nt)},ge.prototype["@@iterator"]=function(){return this.entries()},ge.prototype[s]=function(){return this.entries()},ge.prototype._find=function(J,ee){if(!Ip(this._cacheKey,J)){this._cacheIndex=-1;for(var re=0;re<this._keys.length;re++)if(Ip(this._keys[re],J)){this._cacheIndex=re;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(J),this._values.push(void 0)),this._cacheIndex},ge}();return $;function ue(ge,J){return ge}function ze(ge,J){return J}function nt(ge,J){return[ge,J]}}function v_(){var x=function(){function A(){this._map=new m}return Object.defineProperty(A.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),A.prototype.has=function(k){return this._map.has(k)},A.prototype.add=function(k){return this._map.set(k,k),this},A.prototype.delete=function(k){return this._map.delete(k)},A.prototype.clear=function(){this._map.clear()},A.prototype.keys=function(){return this._map.keys()},A.prototype.values=function(){return this._map.keys()},A.prototype.entries=function(){return this._map.entries()},A.prototype["@@iterator"]=function(){return this.keys()},A.prototype[s]=function(){return this.keys()},A}();return x}function __(){var x=16,A=p.create(),k=$();return function(){function J(){this._key=$()}return J.prototype.has=function(ee){var re=ue(ee,!1);return re!==void 0?p.has(re,this._key):!1},J.prototype.get=function(ee){var re=ue(ee,!1);return re!==void 0?p.get(re,this._key):void 0},J.prototype.set=function(ee,re){var ne=ue(ee,!0);return ne[this._key]=re,this},J.prototype.delete=function(ee){var re=ue(ee,!1);return re!==void 0?delete re[this._key]:!1},J.prototype.clear=function(){this._key=$()},J}();function $(){var J;do J="@@WeakMap@@"+ge();while(p.has(A,J));return A[J]=!0,J}function ue(J,ee){if(!n.call(J,k)){if(!ee)return;Object.defineProperty(J,k,{value:p.create()})}return J[k]}function ze(J,ee){for(var re=0;re<ee;++re)J[re]=Math.random()*255|0;return J}function nt(J){if(typeof Uint8Array=="function"){var ee=new Uint8Array(J);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):ze(ee,J),ee}return ze(new Array(J),J)}function ge(){var J=nt(x);J[6]=J[6]&79|64,J[8]=J[8]&191|128;for(var ee="",re=0;re<x;++re){var ne=J[re];(re===4||re===6||re===8)&&(ee+="-"),ne<16&&(ee+="0"),ee+=ne.toString(16).toLowerCase()}return ee}}function Bp(x){return x.__=void 0,delete x.__,x}})})(lb||(lb={}))});var vn=Pp(_s=>{"use strict";var u2="[object ArrayBuffer]",xn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===u2}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}},jd="string",l2=/^[0-9a-f\s]+$/i,f2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,p2=/^[a-zA-Z0-9-_]+$/,zl=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=xn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},ar=class{static toString(e,t=!1){let n=xn.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}},Xl=class r{static isHex(e){return typeof e===jd&&l2.test(e)}static isBase64(e){return typeof e===jd&&f2.test(e)}static isBase64Url(e){return typeof e===jd&&p2.test(e)}static ToString(e,t="utf8"){let n=xn.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 ar.toString(n,!0);case"utf16":case"utf16be":return ar.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 ar.fromString(e,!0);case"utf16":case"utf16be":return ar.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=xn.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 zl.fromString(e);case"utf16":case"utf16be":return ar.fromString(e);case"utf16le":case"usc2":return ar.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 zl.toString(e);case"utf16":case"utf16be":return ar.toString(e);case"utf16le":case"usc2":return ar.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=xn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=xn.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 ar.toString(e,t)}static FromUtf16String(e,t=!1){return ar.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,"")||""}};Xl.DEFAULT_UTF8_ENCODING="utf8";function h2(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 d2(...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 y2(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}_s.BufferSourceConverter=xn;_s.Convert=Xl;_s.assign=h2;_s.combine=d2;_s.isEqual=y2});var iv=Pp((hV,Ff)=>{var Mx,Kx,Hx,Vx,$x,Fx,Wx,qx,Gx,$f,Hy,zx,Xx,Js,Zx,Yx,Jx,Qx,ev,tv,rv,nv,ov;(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 Ff=="object"&&typeof Ff.exports=="object"?r(t(e,t(Ff.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])};Mx=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Kx=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},Hx=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},Vx=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},$x=function(t,n){return function(o,i){n(o,i,t)}},Fx=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Wx=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{f(i.next(m))}catch(y){c(y)}}function p(m){try{f(i.throw(m))}catch(y){c(y)}}function f(m){m.done?a(m.value):s(m.value).then(l,p)}f((i=i.apply(t,n||[])).next())})},qx=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(f){return function(m){return p([f,m])}}function p(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(m){f=[6,m],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},ov=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Gx=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},$f=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.")},Hy=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},zx=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Hy(arguments[n]));return t},Xx=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},Js=function(t){return this instanceof Js?(this.v=t,this):new Js(t)},Zx=function(t,n,o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=o.apply(t,n||[]),s,a=[];return s={},c("next"),c("throw"),c("return"),s[Symbol.asyncIterator]=function(){return this},s;function c(b){i[b]&&(s[b]=function(v){return new Promise(function(d,T){a.push([b,v,d,T])>1||l(b,v)})})}function l(b,v){try{p(i[b](v))}catch(d){y(a[0][3],d)}}function p(b){b.value instanceof Js?Promise.resolve(b.value.v).then(f,m):y(a[0][2],b)}function f(b){l("next",b)}function m(b){l("throw",b)}function y(b,v){b(v),a.shift(),a.length&&l(a[0][0],a[0][1])}},Yx=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:Js(t[s](c)),done:s==="return"}:a?a(c):c}:a}},Jx=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 $f=="function"?$f(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,p){c=t[a](c),s(l,p,c.done,c.value)})}}function s(a,c,l,p){Promise.resolve(p).then(function(f){a({value:f,done:l})},c)}},Qx=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},ev=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},tv=function(t){return t&&t.__esModule?t:{default:t}},rv=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},nv=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",Mx),r("__assign",Kx),r("__rest",Hx),r("__decorate",Vx),r("__param",$x),r("__metadata",Fx),r("__awaiter",Wx),r("__generator",qx),r("__exportStar",Gx),r("__createBinding",ov),r("__values",$f),r("__read",Hy),r("__spread",zx),r("__spreadArrays",Xx),r("__await",Js),r("__asyncGenerator",Zx),r("__asyncDelegator",Yx),r("__asyncValues",Jx),r("__makeTemplateObject",Qx),r("__importStar",ev),r("__importDefault",tv),r("__classPrivateFieldGet",rv),r("__classPrivateFieldSet",nv)})});var wC={};_t(wC,{webRTC:()=>gC,webRTCDirect:()=>mC});var kp=Symbol.for("@libp2p/peer-id");var Cu=Symbol.for("@libp2p/transport");var og;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(og||(og={}));var Iu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},Ou=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Gi=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ha=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Bu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Pu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Io=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Oo=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var ku=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Nu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ju=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Ru=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Du=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Vn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $n=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:i})=>i!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var zi=Symbol.for("@libp2p/service-capabilities"),ig=Symbol.for("@libp2p/service-dependencies");var Lp={};_t(Lp,{base58btc:()=>Be,base58flickr:()=>L_});var WC=new Uint8Array(0);function sg(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function pn(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ag(r){return new TextEncoder().encode(r)}function cg(r){return new TextDecoder().decode(r)}function P_(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),p=Math.log(256)/Math.log(a);function f(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var v=0,d=0,T=0,D=b.length;T!==D&&b[T]===0;)T++,v++;for(var j=(D-T)*p+1>>>0,Z=new Uint8Array(j);T!==D;){for(var B=b[T],G=0,M=j-1;(B!==0||G<d)&&M!==-1;M--,G++)B+=256*Z[M]>>>0,Z[M]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");d=G,T++}for(var K=j-d;K!==j&&Z[K]===0;)K++;for(var g=c.repeat(v);K<j;++K)g+=r.charAt(Z[K]);return g}function m(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var v=0;if(b[v]!==" "){for(var d=0,T=0;b[v]===c;)d++,v++;for(var D=(b.length-v)*l+1>>>0,j=new Uint8Array(D);b[v];){var Z=t[b.charCodeAt(v)];if(Z===255)return;for(var B=0,G=D-1;(Z!==0||B<T)&&G!==-1;G--,B++)Z+=a*j[G]>>>0,j[G]=Z%256>>>0,Z=Z/256>>>0;if(Z!==0)throw new Error("Non-zero carry");T=B,v++}if(b[v]!==" "){for(var M=D-T;M!==D&&j[M]===0;)M++;for(var K=new Uint8Array(d+(D-M)),g=d;M!==D;)K[g++]=j[M++];return K}}}function y(b){var v=m(b);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:m,decode:y}}var k_=P_,N_=k_,lg=N_;var Np=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 fg(this,e)}},Rp=class{decoders;constructor(e){this.decoders=e}or(e){return fg(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 fg(r,e){return new Rp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Dp=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 Np(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 Xi({name:r,prefix:e,encode:t,decode:n}){return new Dp(r,e,t,n)}function Fn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=lg(t,r);return Xi({prefix:e,name:r,encode:n,decode:i=>pn(o(i))})}function j_(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 p=e[r[l]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|p,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function R_(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 D_(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=D_(n);return Xi({prefix:e,name:r,encode(i){return R_(i,n,t)},decode(i){return j_(i,o,t,r)}})}var Be=Fn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),L_=Fn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Up={};_t(Up,{base32:()=>hn,base32hex:()=>H_,base32hexpad:()=>$_,base32hexpadupper:()=>F_,base32hexupper:()=>V_,base32pad:()=>M_,base32padupper:()=>K_,base32upper:()=>U_,base32z:()=>W_});var hn=Fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),U_=Fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),M_=Fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),K_=Fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),H_=Fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),V_=Fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$_=Fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),F_=Fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),W_=Fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mp={};_t(Mp,{base36:()=>da,base36upper:()=>q_});var da=Fn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),q_=Fn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nr={};_t(nr,{Digest:()=>Bo,create:()=>At,decode:()=>Wn,equals:()=>Hp,hasCode:()=>fA});var G_=dg,pg=128,z_=127,X_=~z_,Z_=Math.pow(2,31);function dg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=Z_;)e[t++]=r&255|pg,r/=128;for(;r&X_;)e[t++]=r&255|pg,r>>>=7;return e[t]=r|0,dg.bytes=t-n+1,e}var Y_=Kp,J_=128,hg=127;function Kp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Kp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&hg)<<o:(s&hg)*Math.pow(2,o),o+=7}while(s>=J_);return Kp.bytes=i-n,t}var Q_=Math.pow(2,7),eA=Math.pow(2,14),tA=Math.pow(2,21),rA=Math.pow(2,28),nA=Math.pow(2,35),oA=Math.pow(2,42),iA=Math.pow(2,49),sA=Math.pow(2,56),aA=Math.pow(2,63),cA=function(r){return r<Q_?1:r<eA?2:r<tA?3:r<rA?4:r<nA?5:r<oA?6:r<iA?7:r<sA?8:r<aA?9:10},uA={encode:G_,decode:Y_,encodingLength:cA},lA=uA,ya=lA;function ma(r,e=0){return[ya.decode(r,e),ya.decode.bytes]}function Zi(r,e,t=0){return ya.encode(r,e,t),e}function Yi(r){return ya.encodingLength(r)}function At(r,e){let t=e.byteLength,n=Yi(r),o=n+Yi(t),i=new Uint8Array(o+t);return Zi(r,i,0),Zi(t,i,n),i.set(e,o),new Bo(r,t,e,i)}function Wn(r){let e=pn(r),[t,n]=ma(e),[o,i]=ma(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Bo(t,o,s,e)}function Hp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&sg(r.bytes,t.bytes)}}var Bo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function fA(r,e){return r.code===e}function yg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return hA(t,Vp(r),e??Be.encoder);default:return dA(t,Vp(r),e??hn.encoder)}}var mg=new WeakMap;function Vp(r){let e=mg.get(r);if(e==null){let t=new Map;return mg.set(r,t),t}return e}var Ze=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==ga)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==yA)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=At(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Hp(e.multihash,n.multihash)}toString(e){return yg(this,e)}toJSON(){return{"/":yg(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??gg(n,o,i.bytes))}else if(t[mA]===!0){let{version:n,multihash:o,code:i}=t,s=Wn(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!==ga)throw new Error(`Version 0 CID must use dag-pb (code: ${ga}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=gg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ga,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=pn(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Bo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,m]=ma(e.subarray(t));return t+=m,f},o=n(),i=ga;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,p=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:l}}static parse(e,t){let[n,o]=pA(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 Vp(i).set(n,e),i}};function pA(r,e){switch(r[0]){case"Q":{let t=e??Be;return[Be.prefix,t.decode(`${Be.prefix}${r}`)]}case Be.prefix:{let t=e??Be;return[Be.prefix,t.decode(r)]}case hn.prefix:{let t=e??hn;return[hn.prefix,t.decode(r)]}case da.prefix:{let t=e??da;return[da.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 hA(r,e,t){let{prefix:n}=t;if(n!==Be.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 dA(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 ga=112,yA=18;function gg(r,e,t){let n=Yi(r),o=n+Yi(e),i=new Uint8Array(o+t.byteLength);return Zi(r,i,0),Zi(e,i,n),i.set(t,o),i}var mA=Symbol.for("@ipld/js-cid/CID");var $p={};_t($p,{identity:()=>br});var wg=0,gA="identity",bg=pn;function wA(r){return At(wg,bg(r))}var br={code:wg,name:gA,encode:bg,digest:wA};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 st(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 vg=Symbol.for("@achingbrain/uint8arraylist");function xg(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 Uu(r){return!!r?.[vg]}var be=class r{bufs;length;[vg]=!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(Uu(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(Uu(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=xg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=xg(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(Uu(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return st(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:st(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),i=new r;return i.length=o,i.bufs=[...n],i}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let l=e>=a&&e<c,p=t>a&&t<=c;if(l&&p){if(e===a&&t===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(t-e)));break}if(l){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(p){if(t===c){n.push(s);break}n.push(s.subarray(0,t-a));break}n.push(s)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Uu(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let f=0;f<i;f++)s[f]=-1;for(let f=0;f<o;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,p;for(let f=t;f<=c;f+=p){p=0;for(let m=l;m>=0;m--){let y=this.get(f+m);if(n[m]!==y){p=Math.max(1,m-a[y]);break}}if(p===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=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 Fp={};_t(Fp,{base10:()=>xA});var xA=Fn({prefix:"9",name:"base10",alphabet:"0123456789"});var Wp={};_t(Wp,{base16:()=>vA,base16upper:()=>_A});var vA=Fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_A=Fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qp={};_t(qp,{base2:()=>AA});var AA=Fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gp={};_t(Gp,{base256emoji:()=>IA});var _g=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}"),SA=_g.reduce((r,e,t)=>(r[t]=e,r),[]),EA=_g.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function TA(r){return r.reduce((e,t)=>(e+=SA[t],e),"")}function CA(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=EA[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var IA=Xi({prefix:"\u{1F680}",name:"base256emoji",encode:TA,decode:CA});var zp={};_t(zp,{base64:()=>OA,base64pad:()=>BA,base64url:()=>Po,base64urlpad:()=>PA});var OA=Fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),BA=Fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Po=Fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),PA=Fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Xp={};_t(Xp,{base8:()=>kA});var kA=Fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zp={};_t(Zp,{identity:()=>NA});var NA=Xi({prefix:"\0",name:"identity",encode:r=>cg(r),decode:r=>ag(r)});var CI=new TextEncoder,II=new TextDecoder;var Qp={};_t(Qp,{sha256:()=>or,sha512:()=>DA});function Jp({name:r,code:e,encode:t}){return new Yp(r,e,t)}var Yp=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?At(this.code,t):t.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Sg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var or=Jp({name:"sha2-256",code:18,encode:Sg("SHA-256")}),DA=Jp({name:"sha2-512",code:19,encode:Sg("SHA-512")});var ko={...Zp,...qp,...Xp,...Fp,...Wp,...Up,...Mp,...Lp,...zp,...Gp},KI={...Qp,...$p};function Tg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Eg=Tg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),eh=Tg("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}),LA={utf8:Eg,"utf-8":Eg,hex:ko.base16,latin1:eh,ascii:eh,binary:eh,...ko},Mu=LA;function pe(r,e="utf8"){let t=Mu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ce(r,e="utf8"){let t=Mu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var UA=parseInt("11111",2),th=parseInt("10000000",2),MA=parseInt("01111111",2),Cg={0:wa,1:wa,2:KA,3:$A,4:FA,5:VA,6:HA,16:wa,22:wa,48:wa};function dn(r,e={offset:0}){let t=r[e.offset]&UA;if(e.offset++,Cg[t]!=null)return Cg[t](r,e);throw new Error("No decoder for tag "+t)}function ba(r,e){let t=0;if((r[e.offset]&th)===th){let n=r[e.offset]&MA,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 wa(r,e){ba(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=dn(r,e);if(n===null)break;t.push(n)}return t}function KA(r,e){let t=ba(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 HA(r,e){let t=ba(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 p=0;for(let f=0;f<c.length;f++)p+=c[f]<<f*7;a+=`.${p}`,c=[]}}return a}function VA(r,e){return e.offset++,null}function $A(r,e){let t=ba(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 FA(r,e){let t=ba(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function WA(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new be;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Ku(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=WA(r.byteLength);return new be(Uint8Array.from([e.byteLength|th]),e)}function Bt(r){let e=new be,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new be(Uint8Array.from([2]),Ku(e),e)}function xa(r){let e=Uint8Array.from([0]),t=new be(e,r);return new be(Uint8Array.from([3]),Ku(t),t)}function Ig(r){return new be(Uint8Array.from([4]),Ku(r),r)}function xr(r,e=48){let t=new be;for(let n of r)t.append(n);return new be(Uint8Array.from([e]),Ku(t),t)}async function Og(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Bg(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 Pg(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 qA=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),GA=Uint8Array.from([6,5,43,129,4,0,34]),zA=Uint8Array.from([6,5,43,129,4,0,35]),XA={ext:!0,kty:"EC",crv:"P-256"},ZA={ext:!0,kty:"EC",crv:"P-384"},YA={ext:!0,kty:"EC",crv:"P-521"},rh=32,nh=48,oh=66;function ih(r){let e=dn(r);return kg(e)}function kg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===rh*2+1)return n=ce(e.subarray(t,t+rh),"base64url"),o=ce(e.subarray(t+rh),"base64url"),new No({...XA,key_ops:["verify"],x:n,y:o});if(e.byteLength===nh*2+1)return n=ce(e.subarray(t,t+nh),"base64url"),o=ce(e.subarray(t+nh),"base64url"),new No({...ZA,key_ops:["verify"],x:n,y:o});if(e.byteLength===oh*2+1)return n=ce(e.subarray(t,t+oh),"base64url"),o=ce(e.subarray(t+oh),"base64url"),new No({...YA,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ng(r){return xr([Bt(Uint8Array.from([1])),Ig(pe(r.d??"","base64url")),xr([Rg(r.crv)],160),xr([xa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function jg(r){return xr([Bt(Uint8Array.from([1])),xr([Rg(r.crv)],160),xr([xa(new be(Uint8Array.from([4]),pe(r.x??"","base64url"),pe(r.y??"","base64url")))],161)]).subarray()}function Rg(r){if(r==="P-256")return qA;if(r==="P-384")return GA;if(r==="P-521")return zA;throw new ve(`Invalid curve ${r}`)}async function Dg(r="P-256"){let e=await Og(r);return new Hu(e.privateKey)}var No=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=jg(this.jwk)),this._raw}toMultihash(){return br.digest(qn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return Be.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 Pg(this.jwk,t,e,n)}},Hu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new No({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Ng(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}async sign(e,t){return Bg(this.jwk,e,t)}};var jo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Qi(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ro(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function St(r,...e){if(!Qi(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 va(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ro(r.outputLen),Ro(r.blockLen)}function es(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 Ug(r,e){St(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function vr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Vu(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _r(r,e){return r<<32-e|r>>>e}var Mg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",JA=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Vr(r){if(St(r),Mg)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=JA[r[t]];return e}var yn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Lg(r){if(r>=yn._0&&r<=yn._9)return r-yn._0;if(r>=yn.A&&r<=yn.F)return r-(yn.A-10);if(r>=yn.a&&r<=yn.f)return r-(yn.a-10)}function ts(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Mg)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=Lg(r.charCodeAt(i)),a=Lg(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 Kg(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Gn(r){return typeof r=="string"&&(r=Kg(r)),St(r),r}function Zt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];St(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 Ji=class{};function sh(r){let e=n=>r().update(Gn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Do(r=32){if(jo&&typeof jo.getRandomValues=="function")return jo.getRandomValues(new Uint8Array(r));if(jo&&typeof jo.randomBytes=="function")return Uint8Array.from(jo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function QA(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 Hg(r,e,t){return r&e^~r&t}function Vg(r,e,t){return r&e^r&t^e&t}var _a=class extends Ji{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=Vu(this.buffer)}update(e){es(this),e=Gn(e),St(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=Vu(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){es(this),Ug(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,vr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;QA(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Vu(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,p=this.get();if(l>p.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,p[f],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},mn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var $u=BigInt(4294967295),$g=BigInt(32);function eS(r,e=!1){return e?{h:Number(r&$u),l:Number(r>>$g&$u)}:{h:Number(r>>$g&$u)|0,l:Number(r&$u)|0}}function Fg(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}=eS(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var ah=(r,e,t)=>r>>>t,ch=(r,e,t)=>r<<32-t|e>>>t,Lo=(r,e,t)=>r>>>t|e<<32-t,Uo=(r,e,t)=>r<<32-t|e>>>t,Aa=(r,e,t)=>r<<64-t|e>>>t-32,Sa=(r,e,t)=>r>>>t-32|e<<64-t;function $r(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Wg=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),qg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Gg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),zg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Xg=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Zg=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var rS=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),zn=new Uint32Array(64),Fu=class extends _a{constructor(e=32){super(64,e,8,!1),this.A=mn[0]|0,this.B=mn[1]|0,this.C=mn[2]|0,this.D=mn[3]|0,this.E=mn[4]|0,this.F=mn[5]|0,this.G=mn[6]|0,this.H=mn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)zn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let m=zn[f-15],y=zn[f-2],b=_r(m,7)^_r(m,18)^m>>>3,v=_r(y,17)^_r(y,19)^y>>>10;zn[f]=v+zn[f-7]+b+zn[f-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:p}=this;for(let f=0;f<64;f++){let m=_r(a,6)^_r(a,11)^_r(a,25),y=p+m+Hg(a,c,l)+rS[f]+zn[f]|0,v=(_r(n,2)^_r(n,13)^_r(n,22))+Vg(n,o,i)|0;p=l,l=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+v|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,l,p)}roundClean(){vr(zn)}destroy(){this.set(0,0,0,0,0,0,0,0),vr(this.buffer)}};var Yg=Fg(["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))),nS=Yg[0],oS=Yg[1],Xn=new Uint32Array(80),Zn=new Uint32Array(80),uh=class extends _a{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:p,Fh:f,Fl:m,Gh:y,Gl:b,Hh:v,Hl:d}=this;return[e,t,n,o,i,s,a,c,l,p,f,m,y,b,v,d]}set(e,t,n,o,i,s,a,c,l,p,f,m,y,b,v,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=p|0,this.Fh=f|0,this.Fl=m|0,this.Gh=y|0,this.Gl=b|0,this.Hh=v|0,this.Hl=d|0}process(e,t){for(let j=0;j<16;j++,t+=4)Xn[j]=e.getUint32(t),Zn[j]=e.getUint32(t+=4);for(let j=16;j<80;j++){let Z=Xn[j-15]|0,B=Zn[j-15]|0,G=Lo(Z,B,1)^Lo(Z,B,8)^ah(Z,B,7),M=Uo(Z,B,1)^Uo(Z,B,8)^ch(Z,B,7),K=Xn[j-2]|0,g=Zn[j-2]|0,I=Lo(K,g,19)^Aa(K,g,61)^ah(K,g,6),E=Uo(K,g,19)^Sa(K,g,61)^ch(K,g,6),O=Gg(M,E,Zn[j-7],Zn[j-16]),P=zg(O,G,I,Xn[j-7],Xn[j-16]);Xn[j]=P|0,Zn[j]=O|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:p,Eh:f,El:m,Fh:y,Fl:b,Gh:v,Gl:d,Hh:T,Hl:D}=this;for(let j=0;j<80;j++){let Z=Lo(f,m,14)^Lo(f,m,18)^Aa(f,m,41),B=Uo(f,m,14)^Uo(f,m,18)^Sa(f,m,41),G=f&y^~f&v,M=m&b^~m&d,K=Xg(D,B,M,oS[j],Zn[j]),g=Zg(K,T,Z,G,nS[j],Xn[j]),I=K|0,E=Lo(n,o,28)^Aa(n,o,34)^Aa(n,o,39),O=Uo(n,o,28)^Sa(n,o,34)^Sa(n,o,39),P=n&i^n&a^i&a,R=o&s^o&c^s&c;T=v|0,D=d|0,v=y|0,d=b|0,y=f|0,b=m|0,{h:f,l:m}=$r(l|0,p|0,g|0,I|0),l=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let N=Wg(I,O,R);n=qg(N,g,E,P),o=N|0}({h:n,l:o}=$r(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=$r(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=$r(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:p}=$r(this.Dh|0,this.Dl|0,l|0,p|0),{h:f,l:m}=$r(this.Eh|0,this.El|0,f|0,m|0),{h:y,l:b}=$r(this.Fh|0,this.Fl|0,y|0,b|0),{h:v,l:d}=$r(this.Gh|0,this.Gl|0,v|0,d|0),{h:T,l:D}=$r(this.Hh|0,this.Hl|0,T|0,D|0),this.set(n,o,i,s,a,c,l,p,f,m,y,b,v,d,T,D)}roundClean(){vr(Xn,Zn)}destroy(){vr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Wu=sh(()=>new Fu);var Jg=sh(()=>new uh);var ph=BigInt(0),fh=BigInt(1);function gn(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Ea(r){let e=r.toString(16);return e.length&1?"0"+e:e}function Qg(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ph:BigInt("0x"+r)}function rs(r){return Qg(Vr(r))}function Fr(r){return St(r),Qg(Vr(Uint8Array.from(r).reverse()))}function qu(r,e){return ts(r.toString(16).padStart(e*2,"0"))}function Yn(r,e){return qu(r,e).reverse()}function Ne(r,e,t){let n;if(typeof e=="string")try{n=ts(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(Qi(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}var lh=r=>typeof r=="bigint"&&ph<=r;function e0(r,e,t){return lh(r)&&lh(e)&&lh(t)&&e<=r&&r<t}function Ar(r,e,t,n){if(!e0(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function t0(r){let e;for(e=0;r>ph;r>>=fh,e+=1);return e}var Mo=r=>(fh<<BigInt(r))-fh;function r0(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),p=(y=n(0))=>{s=l(o(0),y),i=l(),y.length!==0&&(s=l(o(1),y),i=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,b=[];for(;y<e;){i=l();let v=i.slice();b.push(v),y+=i.length}return Zt(...b)};return(y,b)=>{c(),p(y);let v;for(;!(v=b(f()));)p();return c(),v}}function Wr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}function ns(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 Pt=BigInt(0),ut=BigInt(1),Ko=BigInt(2),iS=BigInt(3),i0=BigInt(4),s0=BigInt(5),a0=BigInt(8);function De(r,e){let t=r%e;return t>=Pt?t:e+t}function Ke(r,e,t){let n=r;for(;e-- >Pt;)n*=n,n%=t;return n}function n0(r,e){if(r===Pt)throw new Error("invert: expected non-zero number");if(e<=Pt)throw new Error("invert: expected positive modulus, got "+e);let t=De(r,e),n=e,o=Pt,i=ut,s=ut,a=Pt;for(;t!==Pt;){let l=n/t,p=n%t,f=o-s*l,m=i-a*l;n=t,t=p,o=s,i=a,s=f,a=m}if(n!==ut)throw new Error("invert: does not exist");return De(o,e)}function c0(r,e){let t=(r.ORDER+ut)/i0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function sS(r,e){let t=(r.ORDER-s0)/a0,n=r.mul(e,Ko),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Ko),o),a=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(a),e))throw new Error("Cannot find square root");return a}function aS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-ut,t=0;for(;e%Ko===Pt;)e/=Ko,t++;let n=Ko,o=Sr(r);for(;o0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return c0;let i=o.pow(n,e),s=(e+ut)/Ko;return function(c,l){if(c.is0(l))return l;if(o0(c,l)!==1)throw new Error("Cannot find square root");let p=t,f=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 b=1,v=c.sqr(m);for(;!c.eql(v,c.ONE);)if(b++,v=c.sqr(v),b===p)throw new Error("Cannot find square root");let d=ut<<BigInt(p-b-1),T=c.pow(f,d);p=b,f=c.sqr(T),m=c.mul(m,f),y=c.mul(y,T)}return y}}function cS(r){return r%i0===iS?c0:r%a0===s0?sS:aS(r)}var u0=(r,e)=>(De(r,e)&ut)===ut,uS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=uS.reduce((n,o)=>(n[o]="function",n),e);return Wr(r,t),r}function lS(r,e,t){if(t<Pt)throw new Error("invalid exponent, negatives unsupported");if(t===Pt)return r.ONE;if(t===ut)return e;let n=r.ONE,o=e;for(;t>Pt;)t&ut&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ut;return n}function Ta(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 o0(r,e){let t=(r.ORDER-ut)/Ko,n=r.pow(e,t),o=r.eql(n,r.ONE),i=r.eql(n,r.ZERO),s=r.eql(n,r.neg(r.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function l0(r,e){e!==void 0&&Ro(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Sr(r,e,t=!1,n={}){if(r<=Pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let p=e;p.BITS&&(o=p.BITS),p.sqrt&&(i=p.sqrt),typeof p.isLE=="boolean"&&(t=p.isLE)}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:s,nByteLength:a}=l0(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:t,BITS:s,BYTES:a,MASK:Mo(s),ZERO:Pt,ONE:ut,create:p=>De(p,r),isValid:p=>{if(typeof p!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof p);return Pt<=p&&p<r},is0:p=>p===Pt,isValidNot0:p=>!l.is0(p)&&l.isValid(p),isOdd:p=>(p&ut)===ut,neg:p=>De(-p,r),eql:(p,f)=>p===f,sqr:p=>De(p*p,r),add:(p,f)=>De(p+f,r),sub:(p,f)=>De(p-f,r),mul:(p,f)=>De(p*f,r),pow:(p,f)=>lS(l,p,f),div:(p,f)=>De(p*n0(f,r),r),sqrN:p=>p*p,addN:(p,f)=>p+f,subN:(p,f)=>p-f,mulN:(p,f)=>p*f,inv:p=>n0(p,r),sqrt:i||(p=>(c||(c=cS(r)),c(l,p))),toBytes:p=>t?Yn(p,a):qu(p,a),fromBytes:p=>{if(p.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+p.length);return t?Fr(p):rs(p)},invertBatch:p=>Ta(l,p),cmov:(p,f,m)=>m?f:p});return Object.freeze(l)}function f0(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 dh(r){let e=f0(r);return e+Math.ceil(e/2)}function p0(r,e,t=!1){let n=r.length,o=f0(e),i=dh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Fr(r):rs(r),a=De(s,e-ut)+ut;return t?Yn(a,o):qu(a,o)}var is=BigInt(0),Ho=BigInt(1);function os(r,e){let t=e.negate();return r?t:e}function Gu(r,e,t){let n=e==="pz"?s=>s.pz:s=>s.ez,o=Ta(r.Fp,t.map(n));return t.map((s,a)=>s.toAffine(o[a])).map(r.fromAffine)}function m0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function yh(r,e){m0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=Mo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function h0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=Ho);let l=e*n,p=l+Math.abs(a)-1,f=a===0,m=a<0,y=e%2!==0;return{nextN:c,offset:p,isZero:f,isNeg:m,isNegF:y,offsetF:l}}function fS(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 pS(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 mh=new WeakMap,g0=new WeakMap;function gh(r){return g0.get(r)||1}function d0(r){if(r!==is)throw new Error("invalid wNAF")}function zu(r,e){return{constTimeNegate:os,hasPrecomputes(t){return gh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>is;)n&Ho&&(o=o.add(i)),i=i.double(),n>>=Ho;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=yh(n,e),s=[],a=t,c=a;for(let l=0;l<o;l++){c=a,s.push(c);for(let p=1;p<i;p++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(t,n,o){let i=r.ZERO,s=r.BASE,a=yh(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:p,isZero:f,isNeg:m,isNegF:y,offsetF:b}=h0(o,c,a);o=l,f?s=s.add(os(y,n[b])):i=i.add(os(m,n[p]))}return d0(o),{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=yh(t,e);for(let a=0;a<s.windows&&o!==is;a++){let{nextN:c,offset:l,isZero:p,isNeg:f}=h0(o,a,s);if(o=c,!p){let m=n[l];i=i.add(f?m.negate():m)}}return d0(o),i},getPrecomputes(t,n,o){let i=mh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&(typeof o=="function"&&(i=o(i)),mh.set(n,i))),i},wNAFCached(t,n,o){let i=gh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=gh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){m0(n,e),g0.set(t,n),mh.delete(t)}}}function w0(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>is||n>is;)t&Ho&&(i=i.add(o)),n&Ho&&(s=s.add(o)),o=o.double(),t>>=Ho,n>>=Ho;return{p1:i,p2:s}}function Xu(r,e,t,n){fS(t,r),pS(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=t0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Mo(c),p=new Array(Number(l)+1).fill(s),f=Math.floor((e.BITS-1)/c)*c,m=s;for(let y=f;y>=0;y-=c){p.fill(s);for(let v=0;v<i;v++){let d=n[v],T=Number(d>>BigInt(y)&l);p[T]=p[T].add(t[v])}let b=s;for(let v=p.length-1,d=s;v>0;v--)d=d.add(p[v]),b=b.add(d);if(m=m.add(b),y!==0)for(let v=0;v<c;v++)m=m.double()}return m}function y0(r,e){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hh(e),e}else return Sr(r)}function Zu(r,e,t={}){if(!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=e[a];if(!(typeof c=="bigint"&&c>is))throw new Error(`CURVE.${a} must be positive bigint`)}let n=y0(e.p,t.Fp),o=y0(e.n,t.Fn),s=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of s)if(!n.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var qr=BigInt(0),kt=BigInt(1),wh=BigInt(2),hS=BigInt(8),dS={zip215:!0};function yS(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 mS(r,e={}){let{Fp:t,Fn:n}=Zu("edwards",r,e),{h:o,n:i}=r;Wr(e,{},{uvRatio:"function"});let s=wh<<BigInt(n.BYTES*8)-kt,a=v=>t.create(v),c=e.uvRatio||((v,d)=>{try{return{isValid:!0,value:t.sqrt(t.div(v,d))}}catch{return{isValid:!1,value:qr}}});if(!yS(t,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(v,d,T=!1){let D=T?kt:qr;return Ar("coordinate "+v,d,D,s),d}function p(v){if(!(v instanceof y))throw new Error("ExtendedPoint expected")}let f=ns((v,d)=>{let{ex:T,ey:D,ez:j}=v,Z=v.is0();d==null&&(d=Z?hS:t.inv(j));let B=a(T*d),G=a(D*d),M=a(j*d);if(Z)return{x:qr,y:kt};if(M!==kt)throw new Error("invZ was invalid");return{x:B,y:G}}),m=ns(v=>{let{a:d,d:T}=r;if(v.is0())throw new Error("bad point: ZERO");let{ex:D,ey:j,ez:Z,et:B}=v,G=a(D*D),M=a(j*j),K=a(Z*Z),g=a(K*K),I=a(G*d),E=a(K*a(I+M)),O=a(g+a(T*a(G*M)));if(E!==O)throw new Error("bad point: equation left != right (1)");let P=a(D*j),R=a(Z*B);if(P!==R)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(d,T,D,j){this.ex=l("x",d),this.ey=l("y",T),this.ez=l("z",D,!0),this.et=l("t",j),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof y)throw new Error("extended point not allowed");let{x:T,y:D}=d||{};return l("x",T),l("y",D),new y(T,D,kt,a(T*D))}static normalizeZ(d){return Gu(y,"ez",d)}static msm(d,T){return Xu(y,n,d,T)}_setWindowSize(d){this.precompute(d)}precompute(d=8,T=!0){return b.setWindowSize(this,d),T||this.multiply(wh),this}assertValidity(){m(this)}equals(d){p(d);let{ex:T,ey:D,ez:j}=this,{ex:Z,ey:B,ez:G}=d,M=a(T*G),K=a(Z*j),g=a(D*G),I=a(B*j);return M===K&&g===I}is0(){return this.equals(y.ZERO)}negate(){return new y(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:T,ey:D,ez:j}=this,Z=a(T*T),B=a(D*D),G=a(wh*a(j*j)),M=a(d*Z),K=T+D,g=a(a(K*K)-Z-B),I=M+B,E=I-G,O=M-B,P=a(g*E),R=a(I*O),N=a(g*O),L=a(E*I);return new y(P,R,L,N)}add(d){p(d);let{a:T,d:D}=r,{ex:j,ey:Z,ez:B,et:G}=this,{ex:M,ey:K,ez:g,et:I}=d,E=a(j*M),O=a(Z*K),P=a(G*D*I),R=a(B*g),N=a((j+Z)*(M+K)-E-O),L=R-P,F=R+P,X=a(O-T*E),W=a(N*L),ie=a(F*X),Y=a(N*X),U=a(L*F);return new y(W,ie,U,Y)}subtract(d){return this.add(d.negate())}multiply(d){let T=d;Ar("scalar",T,kt,i);let{p:D,f:j}=b.wNAFCached(this,T,y.normalizeZ);return y.normalizeZ([D,j])[0]}multiplyUnsafe(d,T=y.ZERO){let D=d;return Ar("scalar",D,qr,i),D===qr?y.ZERO:this.is0()||D===kt?this:b.wNAFCachedUnsafe(this,D,y.normalizeZ,T)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return b.wNAFCachedUnsafe(this,i).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===kt?this:this.multiplyUnsafe(o)}static fromBytes(d,T=!1){return St(d),this.fromHex(d,T)}static fromHex(d,T=!1){let{d:D,a:j}=r,Z=t.BYTES;d=Ne("pointHex",d,Z),gn("zip215",T);let B=d.slice(),G=d[Z-1];B[Z-1]=G&-129;let M=Fr(B),K=T?s:t.ORDER;Ar("pointHex.y",M,qr,K);let g=a(M*M),I=a(g-kt),E=a(D*g-j),{isValid:O,value:P}=c(I,E);if(!O)throw new Error("Point.fromHex: invalid y coordinate");let R=(P&kt)===kt,N=(G&128)!==0;if(!T&&P===qr&&N)throw new Error("Point.fromHex: x=0 and x_0=1");return N!==R&&(P=a(-P)),y.fromAffine({x:P,y:M})}static fromPrivateScalar(d){return y.BASE.multiply(d)}toBytes(){let{x:d,y:T}=this.toAffine(),D=Yn(T,t.BYTES);return D[D.length-1]|=d&kt?128:0,D}toRawBytes(){return this.toBytes()}toHex(){return Vr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,kt,a(r.Gx*r.Gy)),y.ZERO=new y(qr,kt,kt,qr),y.Fp=t,y.Fn=n;let b=zu(y,n.BYTES*8);return y}function gS(r,e){Wr(e,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:t,hash:n}=e,{BASE:o,Fp:i,Fn:s}=r,a=s.ORDER,c=e.randomBytes||Do,l=e.adjustScalarBytes||(B=>B),p=e.domain||((B,G,M)=>{if(gn("phflag",M),G.length||M)throw new Error("Contexts/pre-hash are not supported");return B});function f(B){return s.create(B)}function m(B){return f(Fr(B))}function y(B){let G=i.BYTES;B=Ne("private key",B,G);let M=Ne("hashed private key",n(B),2*G),K=l(M.slice(0,G)),g=M.slice(G,2*G),I=m(K);return{head:K,prefix:g,scalar:I}}function b(B){let{head:G,prefix:M,scalar:K}=y(B),g=o.multiply(K),I=g.toBytes();return{head:G,prefix:M,scalar:K,point:g,pointBytes:I}}function v(B){return b(B).pointBytes}function d(B=Uint8Array.of(),...G){let M=Zt(...G);return m(n(p(M,Ne("context",B),!!t)))}function T(B,G,M={}){B=Ne("message",B),t&&(B=t(B));let{prefix:K,scalar:g,pointBytes:I}=b(G),E=d(M.context,K,B),O=o.multiply(E).toBytes(),P=d(M.context,O,I,B),R=f(E+P*g);Ar("signature.s",R,qr,a);let N=i.BYTES,L=Zt(O,Yn(R,N));return Ne("result",L,N*2)}let D=dS;function j(B,G,M,K=D){let{context:g,zip215:I}=K,E=i.BYTES;B=Ne("signature",B,2*E),G=Ne("message",G),M=Ne("publicKey",M,E),I!==void 0&&gn("zip215",I),t&&(G=t(G));let O=Fr(B.slice(E,2*E)),P,R,N;try{P=r.fromHex(M,I),R=r.fromHex(B.slice(0,E),I),N=o.multiplyUnsafe(O)}catch{return!1}if(!I&&P.isSmallOrder())return!1;let L=d(g,R.toBytes(),P.toBytes(),G);return R.add(P.multiplyUnsafe(L)).subtract(N).clearCofactor().is0()}return o.precompute(8),{getPublicKey:v,sign:T,verify:j,utils:{getExtendedPublicKey:b,randomPrivateKey:()=>c(i.BYTES),precompute(B=8,G=r.BASE){return G.precompute(B,!1)}},Point:r}}function wS(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=Sr(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,eddsaOpts:i}}function bS(r,e){return Object.assign({},e,{ExtendedPoint:e.Point,CURVE:r})}function b0(r){let{CURVE:e,curveOpts:t,eddsaOpts:n}=wS(r),o=mS(e,t),i=gS(o,n);return bS(r,i)}var Ca=BigInt(0),ss=BigInt(1),Yu=BigInt(2);function xS(r){return Wr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function x0(r){let e=xS(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||Do,l=a?255:448,p=a?32:56,f=BigInt(a?9:5),m=BigInt(a?121665:39081),y=a?Yu**BigInt(254):Yu**BigInt(447),b=a?BigInt(8)*Yu**BigInt(251)-ss:BigInt(4)*Yu**BigInt(445)-ss,v=y+b+ss,d=g=>De(g,t),T=D(f);function D(g){return Yn(d(g),p)}function j(g){let I=Ne("u coordinate",g,p);return a&&(I[31]&=127),d(Fr(I))}function Z(g){return Fr(o(Ne("scalar",g,p)))}function B(g,I){let E=K(j(I),Z(g));if(E===Ca)throw new Error("invalid private or public key received");return D(E)}function G(g){return B(g,T)}function M(g,I,E){let O=d(g*(I-E));return I=d(I-O),E=d(E+O),{x_2:I,x_3:E}}function K(g,I){Ar("u",g,Ca,t),Ar("scalar",I,y,v);let E=I,O=g,P=ss,R=Ca,N=g,L=ss,F=Ca;for(let W=BigInt(l-1);W>=Ca;W--){let ie=E>>W&ss;F^=ie,{x_2:P,x_3:N}=M(F,P,N),{x_2:R,x_3:L}=M(F,R,L),F=ie;let Y=P+R,U=d(Y*Y),he=P-R,Oe=d(he*he),se=U-Oe,Re=N+L,vt=N-L,tt=d(vt*Y),rt=d(Re*he),lt=tt+rt,rr=tt-rt;N=d(lt*lt),L=d(O*d(rr*rr)),P=d(U*Oe),R=d(se*(U+d(m*se)))}({x_2:P,x_3:N}=M(F,P,N)),{x_2:R,x_3:L}=M(F,R,L);let X=i(R);return d(P*X)}return{scalarMult:B,scalarMultBase:G,getSharedSecret:(g,I)=>B(g,I),getPublicKey:g=>G(g),utils:{randomPrivateKey:()=>c(p)},GuBytes:T.slice()}}var qO=BigInt(0),vS=BigInt(1),v0=BigInt(2),_S=BigInt(3),AS=BigInt(5),SS=BigInt(8),Ia={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:SS,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function A0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Ia.p,a=r*r%i*r%i,c=Ke(a,v0,i)*a%i,l=Ke(c,vS,i)*r%i,p=Ke(l,AS,i)*l%i,f=Ke(p,e,i)*p%i,m=Ke(f,t,i)*f%i,y=Ke(m,n,i)*m%i,b=Ke(y,o,i)*y%i,v=Ke(b,o,i)*y%i,d=Ke(v,e,i)*p%i;return{pow_p_5_8:Ke(d,v0,i)*r%i,b2:a}}function S0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var _0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ES(r,e){let t=Ia.p,n=De(e*e*e,t),o=De(n*n*e,t),i=A0(r*o).pow_p_5_8,s=De(r*n*i,t),a=De(e*s*s,t),c=s,l=De(s*_0,t),p=a===r,f=a===De(-r,t),m=a===De(-r*_0,t);return p&&(s=c),(f||m)&&(s=l),u0(s,t)&&(s=De(-s,t)),{isValid:p||f,value:s}}var TS=Sr(Ia.p,void 0,!0),CS={...Ia,Fp:TS,hash:Jg,adjustScalarBytes:S0,uvRatio:ES},Oa=b0(CS);var Ba=(()=>{let r=Ia.p;return x0({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=A0(e);return De(Ke(t,_S,r)*n,r)},adjustScalarBytes:S0})})();var Pa=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},ka=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Ju=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var E0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new Ju("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 Dt=E0;var Qu=32,Na=64,bh=32;var as,T0=(async()=>{try{return await Dt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function C0(){let r=Oa.utils.randomPrivateKey(),e=Oa.getPublicKey(r);return{privateKey:kS(r,e),publicKey:e}}async function IS(r,e){let t;r.length===Na?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 Dt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Dt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function OS(r,e){let t=r.subarray(0,bh);return Oa.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function I0(r,e){return as==null&&(as=await T0),as?IS(r,e):OS(r,e)}async function BS(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Dt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Dt.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 PS(r,e,t){return Oa.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function O0(r,e,t){return as==null&&(as=await T0),as?BS(r,e,t):PS(r,e,t)}function kS(r,e){let t=new Uint8Array(Na);for(let n=0;n<bh;n++)t[n]=r[n],t[bh+n]=e[n];return t}function cs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var ja=class{type="Ed25519";raw;constructor(e){this.raw=tl(e,Qu)}toMultihash(){return br.digest(qn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return Be.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=O0(this.raw,t,e);return cs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},el=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=tl(e,Na),this.publicKey=new ja(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=I0(this.raw,e);return cs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function xh(r){return r=tl(r,Qu),new ja(r)}async function P0(){let{privateKey:r,publicKey:e}=C0();return new el(r,e)}function tl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var NS=Math.pow(2,7),jS=Math.pow(2,14),RS=Math.pow(2,21),vh=Math.pow(2,28),_h=Math.pow(2,35),Ah=Math.pow(2,42),Sh=Math.pow(2,49),Ce=128,Et=127;function He(r){if(r<NS)return 1;if(r<jS)return 2;if(r<RS)return 3;if(r<vh)return 4;if(r<_h)return 5;if(r<Ah)return 6;if(r<Sh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Eh(r,e,t=0){switch(He(r)){case 8:e[t++]=r&255|Ce,r/=128;case 7:e[t++]=r&255|Ce,r/=128;case 6:e[t++]=r&255|Ce,r/=128;case 5:e[t++]=r&255|Ce,r/=128;case 4:e[t++]=r&255|Ce,r>>>=7;case 3:e[t++]=r&255|Ce,r>>>=7;case 2:e[t++]=r&255|Ce,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function DS(r,e,t=0){switch(He(r)){case 8:e.set(t++,r&255|Ce),r/=128;case 7:e.set(t++,r&255|Ce),r/=128;case 6:e.set(t++,r&255|Ce),r/=128;case 5:e.set(t++,r&255|Ce),r/=128;case 4:e.set(t++,r&255|Ce),r>>>=7;case 3:e.set(t++,r&255|Ce),r>>>=7;case 2:e.set(t++,r&255|Ce),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Th(r,e){let t=r[e],n=0;if(n+=t&Et,t<Ce||(t=r[e+1],n+=(t&Et)<<7,t<Ce)||(t=r[e+2],n+=(t&Et)<<14,t<Ce)||(t=r[e+3],n+=(t&Et)<<21,t<Ce)||(t=r[e+4],n+=(t&Et)*vh,t<Ce)||(t=r[e+5],n+=(t&Et)*_h,t<Ce)||(t=r[e+6],n+=(t&Et)*Ah,t<Ce)||(t=r[e+7],n+=(t&Et)*Sh,t<Ce))return n;throw new RangeError("Could not decode varint")}function LS(r,e){let t=r.get(e),n=0;if(n+=t&Et,t<Ce||(t=r.get(e+1),n+=(t&Et)<<7,t<Ce)||(t=r.get(e+2),n+=(t&Et)<<14,t<Ce)||(t=r.get(e+3),n+=(t&Et)<<21,t<Ce)||(t=r.get(e+4),n+=(t&Et)*vh,t<Ce)||(t=r.get(e+5),n+=(t&Et)*_h,t<Ce)||(t=r.get(e+6),n+=(t&Et)*Ah,t<Ce)||(t=r.get(e+7),n+=(t&Et)*Sh,t<Ce))return n;throw new RangeError("Could not decode varint")}function Gr(r,e,t=0){return e==null&&(e=it(He(r))),e instanceof Uint8Array?Eh(r,e,t):DS(r,e,t)}function Er(r,e=0){return r instanceof Uint8Array?Th(r,e):LS(r,e)}var Ch=new Float32Array([-0]),Jn=new Uint8Array(Ch.buffer);function k0(r,e,t){Ch[0]=r,e[t]=Jn[0],e[t+1]=Jn[1],e[t+2]=Jn[2],e[t+3]=Jn[3]}function N0(r,e){return Jn[0]=r[e],Jn[1]=r[e+1],Jn[2]=r[e+2],Jn[3]=r[e+3],Ch[0]}var Ih=new Float64Array([-0]),Tt=new Uint8Array(Ih.buffer);function j0(r,e,t){Ih[0]=r,e[t]=Tt[0],e[t+1]=Tt[1],e[t+2]=Tt[2],e[t+3]=Tt[3],e[t+4]=Tt[4],e[t+5]=Tt[5],e[t+6]=Tt[6],e[t+7]=Tt[7]}function R0(r,e){return Tt[0]=r[e],Tt[1]=r[e+1],Tt[2]=r[e+2],Tt[3]=r[e+3],Tt[4]=r[e+4],Tt[5]=r[e+5],Tt[6]=r[e+6],Tt[7]=r[e+7],Ih[0]}var US=BigInt(Number.MAX_SAFE_INTEGER),MS=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 Vo;if(e<US&&e>MS)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>D0&&(o=0n,++n>D0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return Vo;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):Vo}},Vo=new Yt(0,0);Vo.toBigInt=function(){return 0n};Vo.zzEncode=Vo.zzDecode=function(){return this};Vo.length=function(){return 1};var D0=4294967296n;function L0(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 U0(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 Oh(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Tr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function rl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Bh=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Tr(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tr(this,4);return rl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tr(this,4);return rl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tr(this,4);let e=N0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Tr(this,4);let e=R0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Tr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return U0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Tr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Tr(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new 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 Tr(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Tr(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tr(this,8);let e=rl(this.buf,this.pos+=4),t=rl(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=Th(this.buf,this.pos);return this.pos+=He(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ph(r){return new Bh(r instanceof Uint8Array?r:r.subarray())}function Cr(r,e,t){let n=Ph(r);return e.decode(n,void 0,t)}function kh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return 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 $o=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Nh(){}var Rh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},KS=kh();function HS(r){return globalThis.Buffer!=null?it(r):KS(r)}var La=class{len;head;tail;states;constructor(){this.len=0,this.head=new $o(Nh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new $o(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Dh((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(nl,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(nl,t.length(),t)}uint64Number(e){return this._push(Eh,He(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Yt.fromBigInt(e).zzEncode();return this._push(nl,t.length(),t)}sint64Number(e){let t=Yt.fromNumber(e).zzEncode();return this._push(nl,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(jh,1,e?1:0)}fixed32(e){return this._push(Da,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Yt.fromBigInt(e);return this._push(Da,4,t.lo)._push(Da,4,t.hi)}fixed64Number(e){let t=Yt.fromNumber(e);return this._push(Da,4,t.lo)._push(Da,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(k0,4,e)}double(e){return this._push(j0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(jh,1,0):this.uint32(t)._push($S,t,e)}string(e){let t=L0(e);return t!==0?this.uint32(t)._push(Oh,t,e):this._push(jh,1,0)}fork(){return this.states=new Rh(this),this.head=this.tail=new $o(Nh,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new $o(Nh,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=HS(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function jh(r,e,t){e[t]=r&255}function VS(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Dh=class extends $o{next;constructor(e,t){super(VS,e,t),this.next=void 0}};function nl(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 Da(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 $S(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(La.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(FS,e,r),this},La.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(WS,e,r),this});function FS(r,e,t){e.set(r,t)}function WS(r,e,t){r.length<40?Oh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(pe(r),t)}function Lh(){return new La}function Ir(r,e){let t=Lh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var us;(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"})(us||(us={}));function ol(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Fo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return ol("enum",us.VARINT,t,n)}function Or(r,e){return ol("message",us.LENGTH_DELIMITED,r,e)}var Ua=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Ye;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Ye||(Ye={}));var Uh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Uh||(Uh={}));(function(r){r.codec=()=>Fo(Uh)})(Ye||(Ye={}));var zr;(function(r){let e;r.codec=()=>(e==null&&(e=Or((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ir(t,r.codec()),r.decode=(t,n)=>Cr(t,r.codec(),n)})(zr||(zr={}));var Mh;(function(r){let e;r.codec=()=>(e==null&&(e=Or((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),Ye.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.Type=Ye.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ir(t,r.codec()),r.decode=(t,n)=>Cr(t,r.codec(),n)})(Mh||(Mh={}));var Ka={};_t(Ka,{MAX_RSA_KEY_SIZE:()=>Kh,generateRSAKeyPair:()=>Xh,jwkToJWKKeyPair:()=>F0,jwkToPkcs1:()=>XS,jwkToPkix:()=>Fh,jwkToRSAPrivateKey:()=>zh,pkcs1MessageToJwk:()=>Vh,pkcs1MessageToRSAPrivateKey:()=>Wh,pkcs1ToJwk:()=>zS,pkcs1ToRSAPrivateKey:()=>$0,pkixMessageToJwk:()=>$h,pkixMessageToRSAPublicKey:()=>Gh,pkixToJwk:()=>ZS,pkixToRSAPublicKey:()=>qh});var Qn=Wu;var ls=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=Ka.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Ze.createV1(114,this._multihash)}toString(){return Be.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 V0(this.jwk,t,e,n)}},Ma=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Ka.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return H0(this.jwk,e,t)}};var Kh=8192,Hh=18,qS=1062,GS=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function zS(r){let e=dn(r);return Vh(e)}function Vh(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 XS(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return xr([Bt(Uint8Array.from([0])),Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url")),Bt(pe(r.d,"base64url")),Bt(pe(r.p,"base64url")),Bt(pe(r.q,"base64url")),Bt(pe(r.dp,"base64url")),Bt(pe(r.dq,"base64url")),Bt(pe(r.qi,"base64url"))]).subarray()}function ZS(r){let e=dn(r,{offset:0});return $h(e)}function $h(r){let e=dn(r[1],{offset:0});return{kty:"RSA",n:ce(e[0],"base64url"),e:ce(e[1],"base64url")}}function Fh(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return xr([GS,xa(xr([Bt(pe(r.n,"base64url")),Bt(pe(r.e,"base64url"))]))]).subarray()}function $0(r){let e=dn(r);return Wh(e)}function Wh(r){let e=Vh(r);return zh(e)}function qh(r,e){if(r.byteLength>=qS)throw new Gi("Key size is too large");let t=dn(r,{offset:0});return Gh(t,r,e)}function Gh(r,e,t){let n=$h(r);if(t==null){let o=Qn(zr.encode({Type:Ye.RSA,Data:e}));t=At(Hh,o)}return new ls(n,t)}function zh(r){if(q0(r)>Kh)throw new ve("Key size is too large");let e=F0(r),t=Qn(zr.encode({Type:Ye.RSA,Data:Fh(e.publicKey)})),n=At(Hh,t);return new Ma(e.privateKey,new ls(e.publicKey,n))}async function Xh(r){if(r>Kh)throw new ve("Key size is too large");let e=await W0(r),t=Qn(zr.encode({Type:Ye.RSA,Data:Fh(e.publicKey)})),n=At(Hh,t);return new Ma(e.privateKey,new ls(e.publicKey,n))}function F0(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function W0(r,e){let t=await Dt.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 YS(t,e);return{privateKey:n[0],publicKey:n[1]}}async function H0(r,e,t){let n=await Dt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Dt.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 V0(r,e,t,n){let o=await Dt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Dt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function YS(r,e){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");let t=await Promise.all([Dt.get().subtle.exportKey("jwk",r.privateKey),Dt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function q0(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return pe(r.n,"base64url").length*8}var il=class extends Ji{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,va(e);let n=Gn(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),vr(i)}update(e){return es(this),this.iHash.update(e),this}digestInto(e){es(this),St(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()}},fs=(r,e,t)=>new il(r,e).update(t).digest();fs.create=(r,e)=>new il(r,e);function G0(r){r.lowS!==void 0&&gn("lowS",r.lowS),r.prehash!==void 0&&gn("prehash",r.prehash)}var Zh=class extends Error{constructor(e=""){super(e)}},wn={Err:Zh,_tlv:{encode:(r,e)=>{let{Err:t}=wn;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=Ea(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Ea(o.length/2|128):"";return Ea(r)+i+o+e},decode(r,e){let{Err:t}=wn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let p of l)s=s<<8|p;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=wn;if(r<Ha)throw new e("integer: negative integers are not allowed");let t=Ea(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=wn;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return rs(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=wn,o=Ne("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:p}=n.decode(2,c);if(p.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=wn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},Ha=BigInt(0),Va=BigInt(1),JS=BigInt(2),sl=BigInt(3),QS=BigInt(4);function eE(r,e,t){function n(o){let i=r.sqr(o),s=r.mul(i,o);return r.add(r.add(s,r.mul(o,e)),t)}return n}function z0(r,e,t){let{BYTES:n}=r;function o(i){let s;if(typeof i=="bigint")s=i;else{let a=Ne("private key",i);if(e){if(!e.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{s=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof i}`)}}if(t&&(s=r.create(s)),!r.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}return o}function tE(r,e={}){let{Fp:t,Fn:n}=Zu("weierstrass",r,e),{h:o,n:i}=r;Wr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:s}=e;if(s&&(!t.is0(r.a)||typeof s.beta!="bigint"||typeof s.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(K,g,I){let{x:E,y:O}=g.toAffine(),P=t.toBytes(E);if(gn("isCompressed",I),I){a();let R=!t.isOdd(O);return Zt(X0(R),P)}else return Zt(Uint8Array.of(4),P,t.toBytes(O))}function l(K){St(K);let g=t.BYTES,I=g+1,E=2*g+1,O=K.length,P=K[0],R=K.subarray(1);if(O===I&&(P===2||P===3)){let N=t.fromBytes(R);if(!t.isValid(N))throw new Error("bad point: is not on curve, wrong x");let L=m(N),F;try{F=t.sqrt(L)}catch(ie){let Y=ie instanceof Error?": "+ie.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}a();let X=t.isOdd(F);return(P&1)===1!==X&&(F=t.neg(F)),{x:N,y:F}}else if(O===E&&P===4){let N=t.fromBytes(R.subarray(g*0,g*1)),L=t.fromBytes(R.subarray(g*1,g*2));if(!y(N,L))throw new Error("bad point: is not on curve");return{x:N,y:L}}else throw new Error(`bad point: got length ${O}, expected compressed=${I} or uncompressed=${E}`)}let p=e.toBytes||c,f=e.fromBytes||l,m=eE(t,r.a,r.b);function y(K,g){let I=t.sqr(g),E=m(K);return t.eql(I,E)}if(!y(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let b=t.mul(t.pow(r.a,sl),QS),v=t.mul(t.sqr(r.b),BigInt(27));if(t.is0(t.add(b,v)))throw new Error("bad curve params: a or b");function d(K,g,I=!1){if(!t.isValid(g)||I&&t.is0(g))throw new Error(`bad point coordinate ${K}`);return g}function T(K){if(!(K instanceof B))throw new Error("ProjectivePoint expected")}let D=ns((K,g)=>{let{px:I,py:E,pz:O}=K;if(t.eql(O,t.ONE))return{x:I,y:E};let P=K.is0();g==null&&(g=P?t.ONE:t.inv(O));let R=t.mul(I,g),N=t.mul(E,g),L=t.mul(O,g);if(P)return{x:t.ZERO,y:t.ZERO};if(!t.eql(L,t.ONE))throw new Error("invZ was invalid");return{x:R,y:N}}),j=ns(K=>{if(K.is0()){if(e.allowInfinityPoint&&!t.is0(K.py))return;throw new Error("bad point: ZERO")}let{x:g,y:I}=K.toAffine();if(!t.isValid(g)||!t.isValid(I))throw new Error("bad point: x or y not field elements");if(!y(g,I))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Z(K,g,I,E,O){return I=new B(t.mul(I.px,K),I.py,I.pz),g=os(E,g),I=os(O,I),g.add(I)}class B{constructor(g,I,E){this.px=d("x",g),this.py=d("y",I,!0),this.pz=d("z",E),Object.freeze(this)}static fromAffine(g){let{x:I,y:E}=g||{};if(!g||!t.isValid(I)||!t.isValid(E))throw new Error("invalid affine point");if(g instanceof B)throw new Error("projective point not allowed");return t.is0(I)&&t.is0(E)?B.ZERO:new B(I,E,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){return Gu(B,"pz",g)}static fromBytes(g){return St(g),B.fromHex(g)}static fromHex(g){let I=B.fromAffine(f(Ne("pointHex",g)));return I.assertValidity(),I}static fromPrivateKey(g){let I=z0(n,e.allowedPrivateKeyLengths,e.wrapPrivateKey);return B.BASE.multiply(I(g))}static msm(g,I){return Xu(B,n,g,I)}precompute(g=8,I=!0){return M.setWindowSize(this,g),I||this.multiply(sl),this}_setWindowSize(g){this.precompute(g)}assertValidity(){j(this)}hasEvenY(){let{y:g}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(g)}equals(g){T(g);let{px:I,py:E,pz:O}=this,{px:P,py:R,pz:N}=g,L=t.eql(t.mul(I,N),t.mul(P,O)),F=t.eql(t.mul(E,N),t.mul(R,O));return L&&F}negate(){return new B(this.px,t.neg(this.py),this.pz)}double(){let{a:g,b:I}=r,E=t.mul(I,sl),{px:O,py:P,pz:R}=this,N=t.ZERO,L=t.ZERO,F=t.ZERO,X=t.mul(O,O),W=t.mul(P,P),ie=t.mul(R,R),Y=t.mul(O,P);return Y=t.add(Y,Y),F=t.mul(O,R),F=t.add(F,F),N=t.mul(g,F),L=t.mul(E,ie),L=t.add(N,L),N=t.sub(W,L),L=t.add(W,L),L=t.mul(N,L),N=t.mul(Y,N),F=t.mul(E,F),ie=t.mul(g,ie),Y=t.sub(X,ie),Y=t.mul(g,Y),Y=t.add(Y,F),F=t.add(X,X),X=t.add(F,X),X=t.add(X,ie),X=t.mul(X,Y),L=t.add(L,X),ie=t.mul(P,R),ie=t.add(ie,ie),X=t.mul(ie,Y),N=t.sub(N,X),F=t.mul(ie,W),F=t.add(F,F),F=t.add(F,F),new B(N,L,F)}add(g){T(g);let{px:I,py:E,pz:O}=this,{px:P,py:R,pz:N}=g,L=t.ZERO,F=t.ZERO,X=t.ZERO,W=r.a,ie=t.mul(r.b,sl),Y=t.mul(I,P),U=t.mul(E,R),he=t.mul(O,N),Oe=t.add(I,E),se=t.add(P,R);Oe=t.mul(Oe,se),se=t.add(Y,U),Oe=t.sub(Oe,se),se=t.add(I,O);let Re=t.add(P,N);return se=t.mul(se,Re),Re=t.add(Y,he),se=t.sub(se,Re),Re=t.add(E,O),L=t.add(R,N),Re=t.mul(Re,L),L=t.add(U,he),Re=t.sub(Re,L),X=t.mul(W,se),L=t.mul(ie,he),X=t.add(L,X),L=t.sub(U,X),X=t.add(U,X),F=t.mul(L,X),U=t.add(Y,Y),U=t.add(U,Y),he=t.mul(W,he),se=t.mul(ie,se),U=t.add(U,he),he=t.sub(Y,he),he=t.mul(W,he),se=t.add(se,he),Y=t.mul(U,se),F=t.add(F,Y),Y=t.mul(Re,se),L=t.mul(Oe,L),L=t.sub(L,Y),Y=t.mul(Oe,U),X=t.mul(Re,X),X=t.add(X,Y),new B(L,F,X)}subtract(g){return this.add(g.negate())}is0(){return this.equals(B.ZERO)}multiply(g){let{endo:I}=e;if(!n.isValidNot0(g))throw new Error("invalid scalar: out of range");let E,O,P=R=>M.wNAFCached(this,R,B.normalizeZ);if(I){let{k1neg:R,k1:N,k2neg:L,k2:F}=I.splitScalar(g),{p:X,f:W}=P(N),{p:ie,f:Y}=P(F);O=W.add(Y),E=Z(I.beta,X,ie,R,L)}else{let{p:R,f:N}=P(g);E=R,O=N}return B.normalizeZ([E,O])[0]}multiplyUnsafe(g){let{endo:I}=e,E=this;if(!n.isValid(g))throw new Error("invalid scalar: out of range");if(g===Ha||E.is0())return B.ZERO;if(g===Va)return E;if(M.hasPrecomputes(this))return this.multiply(g);if(I){let{k1neg:O,k1:P,k2neg:R,k2:N}=I.splitScalar(g),{p1:L,p2:F}=w0(B,E,P,N);return Z(I.beta,L,F,O,R)}else return M.wNAFCachedUnsafe(E,g)}multiplyAndAddUnsafe(g,I,E){let O=this.multiplyUnsafe(I).add(g.multiplyUnsafe(E));return O.is0()?void 0:O}toAffine(g){return D(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return o===Va?!0:g?g(B,this):M.wNAFCachedUnsafe(this,i).is0()}clearCofactor(){let{clearCofactor:g}=e;return o===Va?this:g?g(B,this):this.multiplyUnsafe(o)}toBytes(g=!0){return gn("isCompressed",g),this.assertValidity(),p(B,this,g)}toRawBytes(g=!0){return this.toBytes(g)}toHex(g=!0){return Vr(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}B.BASE=new B(r.Gx,r.Gy,t.ONE),B.ZERO=new B(t.ZERO,t.ONE,t.ZERO),B.Fp=t,B.Fn=n;let G=n.BITS,M=zu(B,e.endo?Math.ceil(G/2):G);return B}function X0(r){return Uint8Array.of(r?2:3)}function rE(r,e,t={}){Wr(e,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||Do,o=e.hmac||((E,...O)=>fs(e.hash,E,Zt(...O))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s;function l(E){let O=a>>Va;return E>O}function p(E){return l(E)?s.neg(E):E}function f(E,O){if(!s.isValidNot0(O))throw new Error(`invalid signature ${E}: out of range 1..CURVE.n`)}class m{constructor(O,P,R){f("r",O),f("s",P),this.r=O,this.s=P,R!=null&&(this.recovery=R),Object.freeze(this)}static fromCompact(O){let P=s.BYTES,R=Ne("compactSignature",O,P*2);return new m(s.fromBytes(R.subarray(0,P)),s.fromBytes(R.subarray(P,P*2)))}static fromDER(O){let{r:P,s:R}=wn.toSig(Ne("DER",O));return new m(P,R)}assertValidity(){}addRecoveryBit(O){return new m(this.r,this.s,O)}recoverPublicKey(O){let P=i.ORDER,{r:R,s:N,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*JS<P&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let X=L===2||L===3?R+a:R;if(!i.isValid(X))throw new Error("recovery id 2 or 3 invalid");let W=i.toBytes(X),ie=r.fromHex(Zt(X0((L&1)===0),W)),Y=s.inv(X),U=j(Ne("msgHash",O)),he=s.create(-U*Y),Oe=s.create(N*Y),se=r.BASE.multiplyUnsafe(he).add(ie.multiplyUnsafe(Oe));if(se.is0())throw new Error("point at infinify");return se.assertValidity(),se}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,s.neg(this.s),this.recovery):this}toBytes(O){if(O==="compact")return Zt(s.toBytes(this.r),s.toBytes(this.s));if(O==="der")return ts(wn.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Vr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Vr(this.toBytes("compact"))}}let y=z0(s,t.allowedPrivateKeyLengths,t.wrapPrivateKey),b={isValidPrivateKey(E){try{return y(E),!0}catch{return!1}},normPrivateKeyToScalar:y,randomPrivateKey:()=>{let E=a;return p0(n(dh(E)),E)},precompute(E=8,O=r.BASE){return O.precompute(E,!1)}};function v(E,O=!0){return r.fromPrivateKey(E).toBytes(O)}function d(E){if(typeof E=="bigint")return!1;if(E instanceof r)return!0;let P=Ne("key",E).length,R=i.BYTES,N=R+1,L=2*R+1;if(!(t.allowedPrivateKeyLengths||s.BYTES===N))return P===N||P===L}function T(E,O,P=!0){if(d(E)===!0)throw new Error("first arg must be private key");if(d(O)===!1)throw new Error("second arg must be public key");return r.fromHex(O).multiply(y(E)).toBytes(P)}let D=e.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let O=rs(E),P=E.length*8-c;return P>0?O>>BigInt(P):O},j=e.bits2int_modN||function(E){return s.create(D(E))},Z=Mo(c);function B(E){return Ar("num < 2^"+c,E,Ha,Z),s.toBytes(E)}function G(E,O,P=M){if(["recovered","canonical"].some(Oe=>Oe in P))throw new Error("sign() legacy options not supported");let{hash:R}=e,{lowS:N,prehash:L,extraEntropy:F}=P;N==null&&(N=!0),E=Ne("msgHash",E),G0(P),L&&(E=Ne("prehashed msgHash",R(E)));let X=j(E),W=y(O),ie=[B(W),B(X)];if(F!=null&&F!==!1){let Oe=F===!0?n(i.BYTES):F;ie.push(Ne("extraEntropy",Oe))}let Y=Zt(...ie),U=X;function he(Oe){let se=D(Oe);if(!s.isValidNot0(se))return;let Re=s.inv(se),vt=r.BASE.multiply(se).toAffine(),tt=s.create(vt.x);if(tt===Ha)return;let rt=s.create(Re*s.create(U+tt*W));if(rt===Ha)return;let lt=(vt.x===tt?0:2)|Number(vt.y&Va),rr=rt;return N&&l(rt)&&(rr=p(rt),lt^=1),new m(tt,rr,lt)}return{seed:Y,k2sig:he}}let M={lowS:e.lowS,prehash:!1},K={lowS:e.lowS,prehash:!1};function g(E,O,P=M){let{seed:R,k2sig:N}=G(E,O,P);return r0(e.hash.outputLen,s.BYTES,o)(R,N)}r.BASE.precompute(8);function I(E,O,P,R=K){let N=E;O=Ne("msgHash",O),P=Ne("publicKey",P),G0(R);let{lowS:L,prehash:F,format:X}=R;if("strict"in R)throw new Error("options.strict was renamed to lowS");if(X!==void 0&&!["compact","der","js"].includes(X))throw new Error('format must be "compact", "der" or "js"');let W=typeof N=="string"||Qi(N),ie=!W&&!X&&typeof N=="object"&&N!==null&&typeof N.r=="bigint"&&typeof N.s=="bigint";if(!W&&!ie)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let Y,U;try{if(ie)if(X===void 0||X==="js")Y=new m(N.r,N.s);else throw new Error("invalid format");if(W){try{X!=="compact"&&(Y=m.fromDER(N))}catch(rr){if(!(rr instanceof wn.Err))throw rr}!Y&&X!=="der"&&(Y=m.fromCompact(N))}U=r.fromHex(P)}catch{return!1}if(!Y||L&&Y.hasHighS())return!1;F&&(O=e.hash(O));let{r:he,s:Oe}=Y,se=j(O),Re=s.inv(Oe),vt=s.create(se*Re),tt=s.create(he*Re),rt=r.BASE.multiplyUnsafe(vt).add(U.multiplyUnsafe(tt));return rt.is0()?!1:s.create(rt.x)===he}return Object.freeze({getPublicKey:v,getSharedSecret:T,sign:g,verify:I,utils:b,Point:r,Signature:m})}function nE(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=Sr(e.n,r.nBitLength),o={Fp:t,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:o}}function oE(r){let{CURVE:e,curveOpts:t}=nE(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,ecdsaOpts:n}}function iE(r,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:r})}function Z0(r){let{CURVE:e,curveOpts:t,ecdsaOpts:n}=oE(r),o=tE(e,t),i=rE(o,n,t);return iE(r,i)}function Y0(r,e){let t=n=>Z0({...r,hash:n});return{...t(e),create:t}}var al={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},OP=BigInt(0),sE=BigInt(1),Yh=BigInt(2),J0=(r,e)=>(r+e/Yh)/e;function aE(r){let e=al.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,p=l*l*r%e,f=Ke(p,t,e)*p%e,m=Ke(f,t,e)*p%e,y=Ke(m,Yh,e)*l%e,b=Ke(y,o,e)*y%e,v=Ke(b,i,e)*b%e,d=Ke(v,a,e)*v%e,T=Ke(d,c,e)*d%e,D=Ke(T,a,e)*v%e,j=Ke(D,t,e)*p%e,Z=Ke(j,s,e)*b%e,B=Ke(Z,n,e)*l%e,G=Ke(B,Yh,e);if(!Jh.eql(Jh.sqr(G),r))throw new Error("Cannot find square root");return G}var Jh=Sr(al.p,void 0,void 0,{sqrt:aE}),Br=Y0({...al,Fp:Jh,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=al.n,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-sE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=J0(i*r,e),c=J0(-n*r,e),l=De(r-a*t-c*o,e),p=De(-a*n-c*i,e),f=l>s,m=p>s;if(f&&(l=e-l),m&&(p=e-p),l>s||p>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:m,k2:p}}}},Wu);function Q0(r,e,t){let n=or.digest(e instanceof Uint8Array?e:e.subarray());if(cs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Br.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Pa(String(o))});try{return Br.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Pa(String(o))}}function ew(r,e,t,n){let o=or.digest(t instanceof Uint8Array?t:t.subarray());if(cs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Br.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new ka(String(i))});try{return n?.signal?.throwIfAborted(),Br.verify(e,o.digest,r)}catch(i){throw new ka(String(i))}}var $a=class{type="secp256k1";raw;_key;constructor(e){this._key=nw(e),this.raw=tw(this._key)}toMultihash(){return br.digest(qn(this))}toCID(){return Ze.createV1(114,this.toMultihash())}toString(){return Be.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 ew(this._key,t,e,n)}},cl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=rw(e),this.publicKey=new $a(t??ow(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:We(this.raw,e.raw)}sign(e,t){return Q0(this.raw,e,t)}};function Qh(r){return new $a(r)}async function iw(){let r=cE();return new cl(r)}function tw(r){return Br.ProjectivePoint.fromHex(r).toRawBytes(!0)}function rw(r){try{return Br.getPublicKey(r,!0),r}catch(e){throw new ha(String(e))}}function nw(r){try{return Br.ProjectivePoint.fromHex(r),r}catch(e){throw new Gi(String(e))}}function ow(r){try{return Br.getPublicKey(r,!0)}catch(e){throw new ha(String(e))}}function cE(){return Br.utils.randomPrivateKey()}async function sw(r,e){if(r==="Ed25519")return P0();if(r==="secp256k1")return iw();if(r==="RSA")return Xh(uE(e));if(r==="ECDSA")return Dg(lE(e));throw new Vn}function Fa(r,e){let{Type:t,Data:n}=zr.decode(r),o=n??new Uint8Array;switch(t){case Ye.RSA:return qh(o,e);case Ye.Ed25519:return xh(o);case Ye.secp256k1:return Qh(o);case Ye.ECDSA:return ih(o);default:throw new Vn}}function aw(r){let{Type:e,Data:t}=zr.decode(r.digest),n=t??new Uint8Array;switch(e){case Ye.Ed25519:return xh(n);case Ye.secp256k1:return Qh(n);case Ye.ECDSA:return ih(n);default:throw new Vn}}function qn(r){return zr.encode({Type:Ye[r.type],Data:r.raw})}function uE(r){return r==null?2048:parseInt(r,10)}function lE(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function ul(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var cw=Symbol.for("nodejs.util.inspect.custom"),fE=114,Wa=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()})`}[kp]=!0;toString(){return this.string==null&&(this.string=Be.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Ze.createV1(fE,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")}[cw](){return`PeerId(${this.toString()})`}},qa=class extends Wa{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ga=class extends Wa{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},za=class extends Wa{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},pE=2336,Xa=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=br.digest(pe(this.url))}[cw](){return`PeerId(${this.url})`}[kp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Ze.createV1(pE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ce(e)),e.toString()===this.toString())}};var hE=114,uw=2336;function ps(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Wn(Be.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return dE(Ze.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Wn(e.decode(r))}return lw(t)}function ed(r){if(r.type==="Ed25519")return new Ga({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new za({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new qa({multihash:r.toCID().multihash,publicKey:r});throw new Vn}function lw(r){if(mE(r))return new qa({multihash:r});if(yE(r))try{let e=aw(r);if(e.type==="Ed25519")return new Ga({multihash:r,publicKey:e});if(e.type==="secp256k1")return new za({multihash:r,publicKey:e})}catch{let t=ce(r.digest);return new Xa(new URL(t))}throw new Nu("Supplied PeerID Multihash is invalid")}function dE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==hE&&r.code!==uw)throw new ku("Supplied PeerID CID is invalid");if(r.code===uw){let e=ce(r.multihash.digest);return new Xa(new URL(e))}return lw(r.multihash)}function yE(r){return r.code===br.code}function mE(r){return r.code===or.code}var ll=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let m=Number.parseInt(f,e);if(!Number.isNaN(m))return m});if(p===void 0)break;if(i*=e,i+=p,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 fw=45,gE=15,hs=new ll;function td(r){if(!(r.length>gE))return hs.new(r).parseWith(()=>hs.readIPv4Addr())}function rd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fw))return hs.new(r).parseWith(()=>hs.readIPv6Addr())}function fl(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>fw)return;let t=hs.new(r).parseWith(()=>hs.readIPAddr());if(t)return e&&t.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,t[0],t[1],t[2],t[3]]):t}var P8=parseInt("0xFFFF",16),k8=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function pl(r){return!!td(r)}function hl(r){return!!rd(r)}function dl(r){return!!fl(r)}var dw=pl,_E=hl,nd=function(r){let e=0;if(r=r.toString().trim(),dw(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(_E(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=dw(t[n]),s;i&&(s=nd(t[n]),t[n]=ce(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ce(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},yw=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ds={},od={},SE=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];SE.forEach(r=>{let e=EE(...r);od[e.code]=e,ds[e.name]=e});function EE(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function je(r){if(typeof r=="number"){if(od[r]!=null)return od[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ds[r]!=null)return ds[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var y6=je("ip4"),m6=je("ip6"),g6=je("ipcidr");function cd(r,e){switch(je(r).code){case 4:case 41:return CE(e);case 42:return ad(e);case 43:return ce(e,"base10");case 6:case 273:case 33:case 132:return ww(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ad(e);case 421:return PE(e);case 444:return gw(e);case 445:return gw(e);case 466:return BE(e);case 481:return globalThis.encodeURIComponent(ad(e));default:return ce(e,"base16")}}function ud(r,e){switch(je(r).code){case 4:return mw(e);case 41:return mw(e);case 42:return sd(e);case 43:return pe(e,"base10");case 6:case 273:case 33:case 132:return ld(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return sd(e);case 421:return IE(e);case 444:return kE(e);case 445:return NE(e);case 466:return OE(e);case 481:return sd(globalThis.decodeURIComponent(e));default:return pe(e,"base16")}}var id=Object.values(ko).map(r=>r.decoder),TE=function(){let r=id[0].or(id[1]);return id.slice(2).forEach(e=>r=r.or(e)),r}();function mw(r){if(!dl(r))throw new Error("invalid ip address");return nd(r)}function CE(r){let e=yw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!dl(e))throw new Error("invalid ip address");return e}function ld(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function ww(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function sd(r){let e=pe(r),t=Uint8Array.from(Gr(e.length));return st([t,e],t.length+e.length)}function ad(r){let e=Er(r);if(r=r.slice(He(e)),r.length!==e)throw new Error("inconsistent lengths");return ce(r)}function IE(r){let e;r[0]==="Q"||r[0]==="1"?e=Wn(Be.decode(`z${r}`)).bytes:e=Ze.parse(r).multihash.bytes;let t=Uint8Array.from(Gr(e.length));return st([t,e],t.length+e.length)}function OE(r){let e=TE.decode(r),t=Uint8Array.from(Gr(e.length));return st([t,e],t.length+e.length)}function BE(r){let e=Er(r),t=r.slice(He(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ce(t,"base64url")}function PE(r){let e=Er(r),t=r.slice(He(e));if(t.length!==e)throw new Error("inconsistent lengths");return ce(t,"base58btc")}function kE(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=hn.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return st([t,o],t.length+o.length)}function NE(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=hn.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ld(n);return st([t,o],t.length+o.length)}function gw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ce(e,"base32"),o=ww(t);return`${n}:${o}`}function bw(r){r=fd(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=je(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new yl("invalid address: "+r);if(a.path===!0){n=fd(o.slice(i).join("/")),e.push([a.code,ud(a.code,n)]),t.push([a.code,n]);break}let c=ud(a.code,o[i]);e.push([a.code,c]),t.push([a.code,cd(a.code,c)])}return{string:xw(t),bytes:ml(e),tuples:e,stringTuples:t,path:n}}function pd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=Er(r,o),s=He(i),a=je(i),c=jE(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let l=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw new yl("Invalid address Uint8Array: "+ce(r,"base16"));e.push([i,l]);let p=cd(i,l);if(t.push([i,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:xw(t),tuples:e,stringTuples:t,path:n}}function xw(r){let e=[];return r.map(t=>{let n=je(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),fd(e.join("/"))}function ml(r){return st(r.map(e=>{let t=je(e[0]),n=Uint8Array.from(Gr(t.code));return e.length>1&&e[1]!=null&&(n=st([n,e[1]])),n}))}function jE(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Er(e instanceof Uint8Array?e:Uint8Array.from(e));return t+He(t)}}function fd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var yl=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var RE=Symbol.for("nodejs.util.inspect.custom"),dd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),DE=[je("dns").code,je("dns4").code,je("dns6").code,je("dnsaddr").code],hd=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},gl=class r{bytes;#e;#t;#r;#n;[dd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=pd(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=bw(e)}else if(_w(e))t=pd(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=je("tcp"),a=je("udp"),c=je("ip4"),l=je("ip6"),p=je("dns6"),f=je("ip6zone");for(let[y,b]of this.stringTuples())y===f.code&&(i=`%${b??""}`),DE.includes(y)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${b??""}${i}`,e=y===p.code?6:4),(y===s.code||y===a.code)&&(t=je(y).name==="tcp"?"tcp":"udp",o=parseInt(b??"")),(y===c.code||y===l.code)&&(t=je(y).name==="tcp"?"tcp":"udp",n=`${b??""}${i}`,e=y===l.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},je(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>je(e).name)}tuples(){return this.#t.map(([e,t])=>t==null?[e]:[e,t])}stringTuples(){return this.#r.map(([e,t])=>t==null?[e]:[e,t])}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(ml(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ds.p2p.code&&e.push([n,o]),n===ds["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ce(Be.decode(`z${n}`),"base58btc"):ce(Ze.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}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=vw.get(t.name);if(n==null)throw new hd(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Xr(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[RE](){return`Multiaddr(${this.#e})`}};var vw=new Map;function _w(r){return!!r?.[dd]}function Xr(r){return new gl(r)}var LE=r=>r.toString().split("/").slice(1),ys=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),ye=r=>({match:e=>ys(t=>t===r).match(e),pattern:r}),Wo=()=>({match:r=>ys(e=>typeof e=="string").match(r),pattern:"{string}"}),ms=()=>({match:r=>ys(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),Ie=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Be.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Za=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Po.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Ee=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Ct=(...r)=>({match:e=>{let t;for(let n of r){let o=n.match(e);o!==!1&&(t==null||o.length<t.length)&&(t=o)}return t??!1},pattern:`or(${r.map(e=>e.pattern).join(", ")})`}),xe=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${r.map(e=>e.pattern).join(", ")})`});function Le(...r){function e(o){let i=LE(o);for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var UE=Ie(),z6=Le(UE),bl=xe(ye("dns4"),Wo()),xl=xe(ye("dns6"),Wo()),vl=xe(ye("dnsaddr"),Wo()),md=xe(ye("dns"),Wo()),X6=Le(bl,Ee(Ie())),Z6=Le(xl,Ee(Ie())),Y6=Le(vl,Ee(Ie())),J6=Le(Ct(md,vl,bl,xl),Ee(Ie())),Aw=xe(ye("ip4"),ys(pl)),Sw=xe(ye("ip6"),ys(hl)),gd=Ct(Aw,Sw),bn=Ct(gd,md,bl,xl,vl),Q6=Le(Ct(gd,xe(Ct(md,vl,bl,xl),Ee(Ie())))),e5=Le(Aw),t5=Le(Sw),r5=Le(gd),wd=xe(bn,ye("tcp"),ms()),Ya=xe(bn,ye("udp"),ms()),n5=Le(xe(wd,Ee(Ie()))),o5=Le(Ya),bd=xe(Ya,ye("quic"),Ee(Ie())),_l=xe(Ya,ye("quic-v1"),Ee(Ie())),ME=Ct(bd,_l),i5=Le(bd),s5=Le(_l),yd=Ct(bn,wd,Ya,bd,_l),Ew=Ct(xe(yd,ye("ws"),Ee(Ie()))),a5=Le(Ew),Tw=Ct(xe(yd,ye("wss"),Ee(Ie())),xe(yd,ye("tls"),Ee(xe(ye("sni"),Wo())),ye("ws"),Ee(Ie()))),c5=Le(Tw),Cw=xe(Ya,ye("webrtc-direct"),Ee(Za()),Ee(Za()),Ee(Ie())),Iw=Le(Cw),Ow=xe(_l,ye("webtransport"),Ee(Za()),Ee(Za()),Ee(Ie())),u5=Le(Ow),wl=Ct(Ew,Tw,xe(wd,Ee(Ie())),xe(ME,Ee(Ie())),xe(bn,Ee(Ie())),Cw,Ow,Ie()),Bw=Le(wl),KE=xe(wl,ye("p2p-circuit"),Ie()),l5=Le(KE),HE=Ct(xe(wl,ye("p2p-circuit"),ye("webrtc"),Ee(Ie())),xe(wl,ye("webrtc"),Ee(Ie())),xe(ye("webrtc"),Ee(Ie()))),Pw=Le(HE),VE=Ct(xe(bn,ye("tcp"),ms(),ye("http"),Ee(Ie())),xe(bn,ye("http"),Ee(Ie()))),f5=Le(VE),$E=Ct(xe(bn,ye("tcp"),Ct(xe(ye("443"),ye("http")),xe(ms(),ye("https")),xe(ms(),ye("tls"),ye("http"))),Ee(Ie())),xe(bn,ye("tls"),ye("http"),Ee(Ie())),xe(bn,ye("https"),Ee(Ie()))),p5=Le($E),FE=Ct(xe(ye("memory"),Wo(),Ee(Ie()))),h5=Le(FE);var It;(function(r){let e;(function(o){o.FIN="FIN",o.STOP_SENDING="STOP_SENDING",o.RESET="RESET",o.FIN_ACK="FIN_ACK"})(e=r.Flag||(r.Flag={}));let t;(function(o){o[o.FIN=0]="FIN",o[o.STOP_SENDING=1]="STOP_SENDING",o[o.RESET=2]="RESET",o[o.FIN_ACK=3]="FIN_ACK"})(t||(t={})),function(o){o.codec=()=>Fo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Or((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=>Ir(o,r.codec()),r.decode=(o,i)=>Cr(o,r.codec(),i)})(It||(It={}));var kw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],xd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Nw="libp2p+webrtc+v1/";var jw=466,Rw=2*1024*1024,Dw=30*1e3,gs=16*1024;function WE(r=gs){let e=He(r-He(r)),t=1+He(Object.keys(It.Flag).length-1),n=1,o=r-e-t-n,i=He(o);return e+t+n+i}var Lw=WE(),Uw=5e3,Mw=5e3,Kw=3e4,vd="/webrtc",Ja="/webrtc-signaling/0.0.1",Hw="/libp2p/webrtc-direct/certificate",Vw="webrtc-direct-certificate-private-key";var $w=12096e5,_d=864e5;var Fw=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))},qE=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var GE=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var zE=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 XE=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var ZE=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var YE=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,JE=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Ww=3,QE=[["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",YE]],qw=[["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 zw(r){return r?Gw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new ZE:typeof navigator<"u"?Gw(navigator.userAgent):r2()}function e2(r){return r!==""&&QE.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 Gw(r){var e=e2(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new XE;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Ww&&(o=Fw(Fw([],o,!0),n2(Ww-o.length),!0)):o=[];var i=o.join("."),s=t2(r),a=JE.exec(r);return a&&a[1]?new zE(t,i,s,a[1]):new qE(t,i,s)}function t2(r){for(var e=0,t=qw.length;e<t;e++){var n=qw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function r2(){var r=typeof process<"u"&&process.version;return r?new GE(process.version.slice(1)):null}function n2(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function Je(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Ad=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Sd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Xw=r=>globalThis.DOMException===void 0?new Sd(r):new DOMException(r),Zw=r=>{let e=r.reason===void 0?Xw("This operation was aborted."):r.reason;return e instanceof Error?e:Xw(e)};function Qa(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,l=new Promise((p,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&f(Zw(y)),a=()=>{f(Zw(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,f);return}let m=new Ad;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(y){f(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?f(o):(m.message=o??`Promise timed out after ${t} milliseconds`,f(m))},t),(async()=>{try{p(await r)}catch(y){f(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 Yw=zw(),ec=Yw!=null&&Yw.name==="firefox",Al=async function*(){},Sl=async r=>{};function Jw(r,e,t=Kw,n){r.readyState==="open"&&Promise.resolve().then(async()=>{if(r.bufferedAmount>0){n.log("%s drain channel with %d buffered bytes",e,r.bufferedAmount);let o=Je(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await Qa(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Ed(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??kw.map(e=>({urls:[e]})),r}var Qw=(r=32)=>Nw+[...Array(r)].map(()=>xd.at(Math.floor(Math.random()*xd.length))).join("");var qo=class{log;peerConnection;remoteAddr;timeline;metrics;source=Al();sink=Sl;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 El=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}},ws=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new El(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 El(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Td=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function bs(r={}){return o2(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 o2(r,e){e=e??{};let t=e.onEnd,n=new ws,o,i,s,a=Je(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((d,T)=>{i=D=>{i=null,n.push(D);try{d(r(n))}catch(j){T(j)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Je()})}},l=d=>i!=null?i(d):(n.push(d),o),p=d=>(n=new ws,i!=null?i({error:d}):(n.push({error:d}),o)),f=d=>{if(s)return o;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},m=d=>s?o:(s=!0,d!=null?p(d):l({done:!0})),y=()=>(n=new ws,m(),{done:!0}),b=d=>(m(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:y,throw:b,push:f,end:m,get readableLength(){return n.size},onEmpty:async d=>{let T=d?.signal;if(T?.throwIfAborted(),n.isEmpty())return;let D,j;T!=null&&(D=new Promise((Z,B)=>{j=()=>{B(new Td)},T.addEventListener("abort",j)}));try{await Promise.race([a.promise,D])}finally{j!=null&&T!=null&&T?.removeEventListener("abort",j)}}},t==null)return o;let v=o;return o={[Symbol.asyncIterator](){return this},next(){return v.next()},throw(d){return v.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return v.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return v.end(d),t!=null&&(t(d),t=void 0),o},get readableLength(){return v.readableLength},onEmpty:d=>v.onEmpty(d)},o}var Tl=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 ir(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new Tl(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new Tl(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 eb(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 tb(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function rb(r,e){let t=eb(r).return?.();tb(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var i2=5e3;function Cd(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Cl=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=Je(),this.closed=Je(),this.log=e.log,this.status="open",this.readStatus="ready",this.writeStatus="ready",this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??i2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=bs({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 Io(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Cd(o)&&await o}let n=()=>{rb(e,this.log)};try{this.sinkController.signal.addEventListener("abort",n),this.log.trace("sink reading from source");for await(let o of e){o=o instanceof Uint8Array?new be(o):o;let i=this.sendData(o,t);Cd(i)&&(this.sendingData=Je(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await ir(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 ir(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await ir(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await ir(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Cd(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new Pu("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Id(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Il=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},xs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},tc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Bl(r){return r[Symbol.asyncIterator]!=null}function nb(r,e){if(r.byteLength>e)throw new xs("Message length too long")}var kl=r=>{let e=He(r),t=it(e);return Gr(r,t),kl.bytes=e,t};kl.bytes=0;function rc(r,e){e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;function*o(i){nb(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Bl(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}rc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;return nb(r,n),new be(t(r.byteLength),r)};var Go;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Go||(Go={}));var Od=r=>{let e=Er(r);return Od.bytes=He(e),e};Od.bytes=0;function zo(r,e){let t=new be,n=Go.LENGTH,o=-1,i=e?.lengthDecoder??Od,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Go.LENGTH)try{if(o=i(t),o<0)throw new Il("Invalid message length");if(o>a)throw new xs("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Go.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new Ol("Message length length too long");break}throw l}if(n===Go.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Go.LENGTH}}}return Bl(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new tc("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new tc("Unexpected end of input")}()}zo.fromReader=(r,e)=>{let t=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(t);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{t=1}}();return zo(n,{...e??{},onLength:i=>{t=i}})};var Bd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function nc(r,e,t,n){let o=new Bd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(m){a(),s(m);return}a(),i(f)},l=f=>{a(),s(f.detail)},p=()=>{a(),s(o)};t?.addEventListener("abort",p),r.addEventListener(e,c),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,l)})}var Pd=class extends Cl{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 Qa(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=bs(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Dw,this.maxBufferedAmount=e.maxBufferedAmount??Rw,this.maxMessageSize=(e.maxMessageSize??gs)-Lw,this.receiveFinAck=Je(),this.finAckTimeout=e.closeTimeout??Uw,this.openTimeout=e.openTimeout??Mw,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 Io("Unknown datachannel state")}this.channel.onopen=o=>{this.timeline.open=new Date().getTime()},this.channel.onclose=o=>{this.log.trace("received onclose event"),this.closeController.abort(),this.receiveFinAck.resolve(),this.close().catch(i=>{this.log.error("error closing stream after channel closed",i)})},this.channel.onerror=o=>{this.log.trace("received onerror event"),this.closeController.abort();let i=o.error;this.abort(i)},this.channel.onmessage=async o=>{let{data:i}=o;i===null||i.byteLength===0||this.incomingData.push(new Uint8Array(i,0,i.byteLength))};let n=this;Promise.resolve().then(async()=>{for await(let o of zo(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new be(i))}}).catch(o=>{this.log.error("error processing incoming data channel messages",o)})}sendNewStream(){}async _sendMessage(e,t=!0){if(this.channel.readyState==="closed"||this.channel.readyState==="closing")throw new Io(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Id([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await nc(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Id([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await nc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Ru(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=It.encode({message:o}),s=rc.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(It.Flag.RESET)}catch(e){this.log.error("failed to send reset - %e",e)}finally{this.channel.close()}}async sendCloseWrite(e){if(this.channel.readyState!=="open"){this.receiveFinAck.resolve();return}if(await this._sendFlag(It.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await ir(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(It.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=It.decode(e);if(t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===It.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(It.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===It.Flag.RESET&&this.reset(),t.flag===It.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===It.Flag.FIN_ACK&&(this.log.trace("received FIN_ACK"),this.receiveFinAck.resolve())),this.readStatus==="ready")return t.message}async _sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=It.encode({flag:e}),n=rc.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 vs(r){let{channel:e,direction:t,handshake:n}=r;return new Pd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var eo=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??vd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=vs({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new kd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},kd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??vd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=vs({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),Jw(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=Al();sink=Sl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=vs({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Nl=globalThis.RTCPeerConnection,jl=globalThis.RTCSessionDescription,ob=globalThis.RTCIceCandidate;var Nd=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Je(),this.haveNext=Je()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Je(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e!=null?await this.throw(e):await this._push(void 0,t)}async _push(e,t){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Je(),await ir(this.readNext.promise,t?.signal,t)}};function Rl(){return new Nd}var Dl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ib(r,e){let t=Rl();r.sink(t).catch(async s=>{await t.end(s)}),r.sink=async s=>{for await(let a of s)await t.push(a);await t.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new be;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:l}=await ir(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await ir(n.next(),s?.signal);if(l===!0)throw new Dl("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 Ll=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ul=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ml=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function oc(r,e={}){let t=ib(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=He(e.maxDataLength));let n=e?.lengthDecoder??Er,o=e?.lengthEncoder??Gr;return{read:async s=>{let a=-1,c=new be;for(;;){c.append(await t.read({...s,bytes:1}));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ll("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ml("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ul("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new be(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new be(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Kl(r,e){let t=oc(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var Jt=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var to=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},sr=class extends to{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Hl=class extends to{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Vl=class extends to{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},$l=class extends to{constructor(e){super(`unsupported hash algorithm code: ${e} please see the codes at https://github.com/multiformats/multicodec/blob/master/table.csv `),this.name="WebRTC/UnsupportedHashAlgorithmError"}};var Lt;(function(r){let e;(function(o){o.SDP_OFFER="SDP_OFFER",o.SDP_ANSWER="SDP_ANSWER",o.ICE_CANDIDATE="ICE_CANDIDATE"})(e=r.Type||(r.Type={}));let t;(function(o){o[o.SDP_OFFER=0]="SDP_OFFER",o[o.SDP_ANSWER=1]="SDP_ANSWER",o[o.ICE_CANDIDATE=2]="ICE_CANDIDATE"})(t||(t={})),function(o){o.codec=()=>Fo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Or((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=>Ir(o,r.codec()),r.decode=(o,i)=>Cr(o,r.codec(),i)})(Lt||(Lt={}));var Fl=async(r,e,t)=>{try{let n=Je();for(c2(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!==Lt.Type.ICE_CANDIDATE)throw new ju("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new Jt("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new ob(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new Jt("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate",t.direction,n),t.signal?.aborted===!0&&Wl(r)!=="connected")throw n}};function Wl(r){return ec?r.iceConnectionState:r.connectionState}function c2(r,e){r[ec?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Wl(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Bu("RTCPeerConnection was closed"));break;default:break}}}async function sb({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{baseAddr:p}=ab(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",p);let f=p.getPeerId();if(f==null)throw new ve("Relay peer was missing");let m=i.getConnections(ps(f)),y,b=!1;m.length===0?(l?.(new Jt("webrtc:dial-relay")),y=await s.dial(p,{signal:t,onProgress:l}),b=!0):(l?.(new Jt("webrtc:reuse-relay-connection")),y=m[0]);try{l?.(new Jt("webrtc:open-signaling-stream"));let v=await y.newStream(Ja,{signal:t,runOnLimitedConnection:!0}),d=Kl(v).pb(Lt),T=new Nl(r),D=new eo({logger:c},{peerConnection:T,dataChannelOptions:e});try{let j=T.createDataChannel("init");T.onicecandidate=({candidate:M})=>{let K=JSON.stringify(M?.toJSON()??null);a.trace("initiator sending ICE candidate %o",M),d.write({type:Lt.Type.ICE_CANDIDATE,data:K},{signal:t}).catch(g=>{a.error("error sending ICE candidate",g)})},T.onicecandidateerror=M=>{a.error("initiator ICE candidate error",M)};let Z=await T.createOffer().catch(M=>{throw a.error("could not execute createOffer",M),new sr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",Z.sdp),l?.(new Jt("webrtc:send-sdp-offer")),await d.write({type:Lt.Type.SDP_OFFER,data:Z.sdp},{signal:t}),await T.setLocalDescription(Z).catch(M=>{throw a.error("could not execute setLocalDescription",M),new sr("Failed to set localDescription")}),l?.(new Jt("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let B=await d.read({signal:t});if(B.type!==Lt.Type.SDP_ANSWER)throw new sr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",B.data);let G=new jl({type:"answer",sdp:B.data});return await T.setRemoteDescription(G).catch(M=>{throw a.error("could not execute setRemoteDescription",M),new sr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new Jt("webrtc:read-ice-candidates")),await Fl(T,d,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),j.close(),l?.(new Jt("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await v.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:T,muxerFactory:D}}catch(j){throw a.error("outgoing signaling error",j),T.close(),v.abort(j),j}finally{T.onicecandidate=null,T.onicecandidateerror=null}}finally{if(b)try{await y.close({signal:t})}catch(v){y.abort(v)}}}var cb=Le(Bw.matchers[0],ye("p2p-circuit")),ql=class r extends $n{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=>cb.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=>cb.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 ub({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Kl(e).pb(Lt);try{r.onicecandidate=({candidate:p})=>{let f=JSON.stringify(p?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),i.write({type:Lt.Type.ICE_CANDIDATE,data:f},{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!==Lt.Type.SDP_OFFER)throw new sr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new jl({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(p=>{throw o.error("could not execute setRemoteDescription",p),new sr("Failed to set remoteDescription")});let l=await r.createAnswer().catch(p=>{throw o.error("could not execute createAnswer",p),new sr("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:Lt.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(p=>{throw o.error("could not execute setLocalDescription",p),new sr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Fl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Wl(r)!=="connected")throw o.error("error while handling signaling stream from peer %a",n.remoteAddr,a),r.close(),a;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",n.remoteAddr,a)}let s=Xr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Gl=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"})})}[Cu]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[zi]=["@libp2p/transport"];[ig]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Ja,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(Ja),this._started=!1}createListener(e){return new ql(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Pw.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 sb({rtcConfiguration:await Ed(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new qo(this.components,{peerConnection:o,timeline:{open:Date.now()},remoteAddr:n,metrics:this.metrics?.dialerEvents}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol({connection:e,stream:t},n){let o=new Nl(await Ed(this.init.rtcConfiguration)),i=new eo(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await ub({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new qo(this.components,{peerConnection:o,timeline:{open:new Date().getTime()},remoteAddr:s,metrics:this.metrics?.listenerEvents});await this.components.upgrader.upgradeInbound(a,{skipEncryption:!0,skipProtection:!0,muxerFactory:i,signal:n}),this._closeOnShutdown(o,a)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),t.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function ab(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new ve("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new ve("p2p-circuit protocol was not present in multiaddr");let t=Xr(e[0]),o=Xr("/"+e[1]).getPeerId();if(o==null)throw new ve("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new ve("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:ps(o)}}var UG=Hr(fb());var Qr={};_t(Qr,{Any:()=>Yr,BaseBlock:()=>Qe,BaseStringBlock:()=>cc,BitString:()=>Nr,BmpString:()=>Qo,Boolean:()=>Zo,CharacterString:()=>ci,Choice:()=>Ss,Constructed:()=>at,DATE:()=>dc,DateTime:()=>mc,Duration:()=>gc,EndOfContent:()=>uc,Enumerated:()=>Yo,GeneralString:()=>ai,GeneralizedTime:()=>ui,GraphicString:()=>si,HexBlock:()=>Jr,IA5String:()=>ii,Integer:()=>Sn,Null:()=>Pr,NumericString:()=>ti,ObjectIdentifier:()=>Jo,OctetString:()=>kr,Primitive:()=>An,PrintableString:()=>ri,RawData:()=>Ld,RelativeObjectIdentifier:()=>hc,Repeated:()=>li,Sequence:()=>Kt,Set:()=>Ht,TIME:()=>wc,TeletexString:()=>ni,TimeOfDay:()=>yc,UTCTime:()=>io,UniversalString:()=>ei,Utf8String:()=>cr,ValueBlock:()=>pt,VideotexString:()=>oi,ViewWriter:()=>As,VisibleString:()=>oo,compareSchema:()=>no,fromBER:()=>Tn,verifySchema:()=>O2});var de=Hr(vn());function Xo(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function ro(r,e,t=-1){let n=t,o=r,i=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(r<s){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let l=new Uint8Array(c);for(let p=a-1;p>=0;p--){let f=Math.pow(2,p*e);l[i-p-1]=Math.floor(o/f),o-=l[i-p-1]*f}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Zl(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Rd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=Xo(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,Xo(i,8)-n}function pb(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let s=t-e,a=ro(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=ro(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function hb(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function Ut(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 Kk=Math.log(2);function Yl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Ud(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function En(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 As=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Ud(this.items)}},ic=[new Uint8Array([1])],db="0123456789",Dd="name",yb="valueHexView",g2="isHexOnly",w2="idBlock",b2="tagClass",x2="tagNumber",v2="isConstructed",_2="fromBER",A2="toBER",S2="local",Mt="",jr=new ArrayBuffer(0),hf=new Uint8Array(0),ac="EndOfContent",gb="OCTET STRING",wb="BIT STRING";function Jr(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?de.BufferSourceConverter.toUint8Array(i.valueHex):hf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!En(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",jr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:de.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var _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=Mt,warnings:n=[],valueBeforeDecode:o=hf}={}){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 pt=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'")}};pt.NAME="valueBlock";var Jl=class extends Jr(_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):hf,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",jr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=ro(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!En(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),p=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===p){p+=255;let m=new Uint8Array(p);for(let y=0;y<l.length;y++)m[y]=l[y];l=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,l[c-1]=i[c]&127;let f=new Uint8Array(c);for(let m=0;m<c;m++)f[m]=l[m];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=Xo(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}}};Jl.NAME="identificationBlock";var Ql=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(!En(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=Xo(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let o=ro(this.length,8);if(o.byteLength>127)return this.error="Too big length",jr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Ql.NAME="lengthBlock";var Q={},Qe=class extends _n{constructor({name:e=Mt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new Jl(o),this.lenBlock=new Ql(o),this.valueBlock=i?new i(o):new pt(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new As;t||bb(this);let o=this.idBlock.toBER(e);if(n.write(o),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(i)}return t?jr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():de.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=de.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return hb(t,n)}};Qe.NAME="BaseBlock";function bb(r){var e;if(r instanceof Q.Constructed)for(let t of r.valueBlock.value)bb(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var cc=class extends Qe{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Mt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};cc.NAME="BaseStringBlock";var ef=class extends Jr(pt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};ef.NAME="PrimitiveValueBlock";var xb,An=class extends Qe{constructor(e={}){super(e,ef),this.idBlock.isConstructed=!1}};xb=An;Q.Primitive=xb;An.NAME="PRIMITIVE";function E2(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 Es(r,e=0,t=r.length){let n=e,o=new Qe({},pt),i=new _n;if(!En(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=Qe;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};c=Q.EndOfContent;break;case 1:c=Q.Boolean;break;case 2:c=Q.Integer;break;case 3:c=Q.BitString;break;case 4:c=Q.OctetString;break;case 5:c=Q.Null;break;case 6:c=Q.ObjectIdentifier;break;case 10:c=Q.Enumerated;break;case 12:c=Q.Utf8String;break;case 13:c=Q.RelativeObjectIdentifier;break;case 14:c=Q.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=Q.Sequence;break;case 17:c=Q.Set;break;case 18:c=Q.NumericString;break;case 19:c=Q.PrintableString;break;case 20:c=Q.TeletexString;break;case 21:c=Q.VideotexString;break;case 22:c=Q.IA5String;break;case 23:c=Q.UTCTime;break;case 24:c=Q.GeneralizedTime;break;case 25:c=Q.GraphicString;break;case 26:c=Q.VisibleString;break;case 27:c=Q.GeneralString;break;case 28:c=Q.UniversalString;break;case 29:c=Q.CharacterString;break;case 30:c=Q.BmpString;break;case 31:c=Q.DATE;break;case 32:c=Q.TimeOfDay;break;case 33:c=Q.DateTime;break;case 34:c=Q.Duration;break;default:{let l=o.idBlock.isConstructed?new Q.Constructed:new Q.Primitive;l.idBlock=o.idBlock,l.lenBlock=o.lenBlock,l.warnings=o.warnings,o=l}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?Q.Constructed:Q.Primitive}return o=E2(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Tn(r){if(!r.byteLength){let e=new Qe({},pt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Es(de.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function T2(r,e){return r?1:e}var Zr=class extends pt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);if(!En(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(;T2(this.isIndefiniteForm,n)>0;){let s=Es(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 As;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?jr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Zr.NAME="ConstructedValueBlock";var vb,at=class extends Qe{constructor(e={}){super(e,Zr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
3
3
  `).map(o=>` ${o}`).join(`
4
4
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
5
5
  ${e.join(`
6
- `)}`:`${t} :`}};px=it;Z.Constructed=px;it.NAME="CONSTRUCTED";var Xl=class extends ft{fromBER(e,t,n){return t}toBER(e){return kr}};Xl.override="EndOfContentValueBlock";var hx,nc=class extends Je{constructor(e={}){super(e,Xl),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};hx=nc;Z.EndOfContent=hx;nc.NAME=tc;var dx,Ir=class extends Je{constructor(e={}){super(e,ft),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};dx=Ir;Z.Null=dx;Ir.NAME="NULL";var Yl=class extends qr(ft){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=me.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=me.BufferSourceConverter.toUint8Array(e);return vn(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,Dd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Yl.NAME="BooleanValueBlock";var mx,zo=class extends Je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Yl),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};mx=zo;Z.Boolean=mx;zo.NAME="BOOLEAN";var Zl=class extends qr(Fr){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=Fr.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===tc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==cx)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?Fr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Zl.NAME="OctetStringValueBlock";var Md,Tr=class extends Je{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Zl),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=ws(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=me.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof Md&&e.push(t.valueBlock.valueHexView);return me.BufferSourceConverter.concat(e)}};Md=Tr;Z.OctetString=Md;Tr.NAME=cx;var Jl=class extends qr(Fr){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=Fr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===tc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==ux)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=me.BufferSourceConverter.toUint8Array(e);if(!vn(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=ws(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 Fr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return kr;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Jl.NAME="BitStringValueBlock";var yx,Br=class extends Je{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},Jl),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join(""),o=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${o} : ${i}`}}};yx=Br;Z.BitString=yx;Br.NAME=ux;var gx;function c_(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,h=c<s?s:c,p=0;for(let m=h;m>=0;m--,p++){switch(!0){case p<a.length:f=i[s-p]+a[c-p]+t[0];break;default:f=i[s-p]+t[0]}switch(t[0]=f/10,!0){case p>=i.length:i=Fl(new Uint8Array([f%10]),i);break;default:i[s-p]=f%10}}return t[0]>0&&(i=Fl(t,i)),i}function ax(r){if(r>=Qa.length)for(let e=Qa.length;e<=r;e++){let t=new Uint8Array([0]),n=Qa[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=Fl(t,n)),Qa.push(n)}return Qa[r]}function u_(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,h=0;for(let p=c;p>=0;p--,h++)switch(f=i[s-h]-a[c-h]-t,!0){case f<0:t=1,i[s-h]=f+10;break;default:t=0,i[s-h]=f}if(t>0)for(let p=s-c+1;p>=0;p--,h++)if(f=i[s-h]-t,f<0)t=1,i[s-h]=f+10;else{t=0,i[s-h]=f;break}return i.slice()}var oc=class extends qr(ft){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Dd.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(nx(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=u_(ax(n),t),s="-";break;default:t=c_(t,ax(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=ix.charAt(t[c]));return a===!1&&(s+=ix.charAt(0)),s}};gx=oc;oc.NAME="IntegerValueBlock";Object.defineProperty(gx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var ec,bn=class extends Je{constructor(e={}){super(e,oc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Wl(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Wl();let t=BigInt(e),n=new ys,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(me.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${me.Convert.ToHex(a)}`)+t,h=me.BufferSourceConverter.toUint8Array(me.Convert.FromHex(f.toString(16)));h[0]|=128,n.write(h)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new ec({valueHex:n.final()})}convertToDER(){let e=new ec({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new ec({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};ec=bn;Z.Integer=ec;bn.NAME="INTEGER";var wx,Xo=class extends bn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};wx=Xo;Z.Enumerated=wx;Xo.NAME="ENUMERATED";var ic=class extends qr(ft){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(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=Go(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Wl();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=to(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=me.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};ic.NAME="sidBlock";var Ql=class extends ft{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 ic;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,kr;t.push(o)}return jd(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 ic;if(o>Number.MAX_SAFE_INTEGER){Wl();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}};Ql.NAME="ObjectIdentifierValueBlock";var xx,Yo=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Ql),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};xx=Yo;Z.ObjectIdentifier=xx;Yo.NAME="OBJECT IDENTIFIER";var sc=class extends qr(wn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=me.BufferSourceConverter.toUint8Array(e);if(!vn(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=Go(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=to(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",kr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=me.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};sc.NAME="relativeSidBlock";var ef=class extends ft{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 sc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,kr;n.push(i)}return jd(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new sc;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};ef.NAME="RelativeObjectIdentifierValueBlock";var bx,ac=class extends Je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,ef),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};bx=ac;Z.RelativeObjectIdentifier=bx;ac.NAME="RelativeObjectIdentifier";var vx,Mt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};vx=Mt;Z.Sequence=vx;Mt.NAME="SEQUENCE";var Ax,Kt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ax=Kt;Z.Set=Ax;Kt.NAME="SET";var tf=class extends qr(ft){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=jt}toJSON(){return{...super.toJSON(),value:this.value}}};tf.NAME="StringValueBlock";var rf=class extends tf{};rf.NAME="SimpleStringValueBlock";var Ot=class extends rc{constructor({...e}={}){super(e,rf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Ot.NAME="SIMPLE STRING";var nf=class extends Ot{fromBuffer(e){this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=me.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=me.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf8String(e)),this.valueBlock.value=e}};nf.NAME="Utf8StringValueBlock";var Sx,ir=class extends nf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Sx=ir;Z.Utf8String=Sx;ir.NAME="UTF8String";var of=class extends Ot{fromBuffer(e){this.valueBlock.value=me.Convert.ToUtf16String(e),this.valueBlock.valueHexView=me.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(me.Convert.FromUtf16String(e))}};of.NAME="BmpStringValueBlock";var Ex,Zo=class extends of{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Ex=Zo;Z.BmpString=Ex;Zo.NAME="BMPString";var sf=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=to(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}};sf.NAME="UniversalStringValueBlock";var _x,Jo=class extends sf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};_x=Jo;Z.UniversalString=_x;Jo.NAME="UniversalString";var Cx,Qo=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Cx=Qo;Z.NumericString=Cx;Qo.NAME="NumericString";var Ix,ei=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ix=ei;Z.PrintableString=Ix;ei.NAME="PrintableString";var Tx,ti=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Tx=ti;Z.TeletexString=Tx;ti.NAME="TeletexString";var Bx,ri=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Bx=ri;Z.VideotexString=Bx;ri.NAME="VideotexString";var kx,ni=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};kx=ni;Z.IA5String=kx;ni.NAME="IA5String";var Px,oi=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Px=oi;Z.GraphicString=Px;oi.NAME="GraphicString";var Nx,no=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Nx=no;Z.VisibleString=Nx;no.NAME="VisibleString";var Ox,ii=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Ox=ii;Z.GeneralString=Ox;ii.NAME="GeneralString";var Rx,si=class extends Ot{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Rx=si;Z.CharacterString=Rx;si.NAME="CharacterString";var Dx,oo=class extends no{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,me.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ut(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ut(this.month,2),t[2]=Ut(this.day,2),t[3]=Ut(this.hour,2),t[4]=Ut(this.minute,2),t[5]=Ut(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Dx=oo;Z.UTCTime=Dx;oo.NAME="UTCTime";var Lx,ai=class extends oo{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let 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("+"),v="";if(m===-1&&(m=n.indexOf("-"),p=-1),m!==-1){if(v=n.substring(m+1),n=n.substring(0,m),v.length!==2&&v.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(v.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(a=p*g,v.length===4){if(g=parseInt(v.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=p*g}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let p=new Number(`0${n.substring(f)}`);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");i=p.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let 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,f!==-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,f!==-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(Ut(this.year,4)),t.push(Ut(this.month,2)),t.push(Ut(this.day,2)),t.push(Ut(this.hour,2)),t.push(Ut(this.minute,2)),t.push(Ut(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ut(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Lx=ai;Z.GeneralizedTime=Lx;ai.NAME="GeneralizedTime";var Ux,cc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Ux=cc;Z.DATE=Ux;cc.NAME="DATE";var jx,uc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};jx=uc;Z.TimeOfDay=jx;uc.NAME="TimeOfDay";var Mx,lc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Mx=lc;Z.DateTime=Mx;lc.NAME="DateTime";var Kx,fc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Kx=fc;Z.Duration=Kx;fc.NAME="Duration";var Hx,pc=class extends ir{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Hx=pc;Z.TIME=Hx;pc.NAME="TIME";var Wr=class{constructor({name:e=jt,optional:t=!1}={}){this.name=e,this.optional=t}},gs=class extends Wr{constructor({value:e=[],...t}={}){super(t),this.value=e}},ci=class extends Wr{constructor({value:e=new Wr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Ud=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=me.BufferSourceConverter.toUint8Array(e)}constructor({data:e=af}={}){this.dataView=me.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=me.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function ro(r,e,t){if(t instanceof gs){for(let i of t.value)if(ro(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Ld)&&(i.name=t.name),i}}if(t instanceof Wr)return t.hasOwnProperty(Ld)&&(r[t.name]=e),{verified:!0,result:r};if(!(r instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Q2 in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(n_ in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(o_ 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(e_)===!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(t_)===!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(r_)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(J2 in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:r};if(t.idBlock.isHexOnly){if(!(sx in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let i=t.idBlock.valueHexView,s=e.idBlock.valueHexView;if(i.length!==s.length)return{verified:!1,result:r};for(let a=0;a<i.length;a++)if(i[a]!==s[1])return{verified:!1,result:r}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,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 ci&&(a=e.valueBlock.value.length),a===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let f=0;f<t.valueBlock.value.length;f++)c=c&&(t.valueBlock.value[f].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,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 f={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,jt),t.name&&(delete r[t.name],f.name=t.name)),f}}else if(t.valueBlock.value[0]instanceof ci){if(s=ro(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(Ld in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let f={};i_ in t.valueBlock.value[0]&&t.valueBlock.value[0].local?f=e:f=r,typeof f[t.valueBlock.value[0].name]>"u"&&(f[t.valueBlock.value[0].name]=[]),f[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=ro(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&&sx in e.valueBlock){let i=ws(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 ro(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function l_(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=ws(me.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:ro(t.result,t.result,e)}var A;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(A||(A={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var Kd=Lr(gn()),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(Kd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Kd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Br))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Br({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Br({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Hd=Lr(gn()),se=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Hd.BufferSourceConverter.isBufferSource(e)?this.buffer=Hd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Tr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Tr({valueHex:this.buffer})}toSchema(e){return new Tr({name:e})}};var f_={fromASN:r=>r instanceof Ir?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Ir;let e=An(r);if(e.result.error)throw new Error(e.result.error);return e.result}},p_={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new bn({value:+r})},h_={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Xo({value:r})},ge={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new bn({valueHex:r})};var d_={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Br({valueHex:r})},m_={fromASN:r=>r.valueBlock.toString(),toASN:r=>new Yo({value:r})},y_={fromASN:r=>r.valueBlock.value,toASN:r=>new zo({value:r})},xs={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Tr({valueHex:r})},Vx={fromASN:r=>new se(r.getValue()),toASN:r=>r.toASN()};function sr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Vd=sr(ir),g_=sr(Zo),w_=sr(Jo),x_=sr(Qo),b_=sr(ei),v_=sr(ti),A_=sr(ri),S_=sr(ni),E_=sr(oi),__=sr(no),C_=sr(ii),I_=sr(si),T_={fromASN:r=>r.toDate(),toASN:r=>new oo({valueDate:r})},B_={fromASN:r=>r.toDate(),toASN:r=>new ai({valueDate:r})},k_={fromASN:()=>null,toASN:()=>new Ir};function bs(r){switch(r){case d.Any:return f_;case d.BitString:return d_;case d.BmpString:return g_;case d.Boolean:return y_;case d.CharacterString:return I_;case d.Enumerated:return h_;case d.GeneralString:return C_;case d.GeneralizedTime:return B_;case d.GraphicString:return E_;case d.IA5String:return S_;case d.Integer:return p_;case d.Null:return k_;case d.NumericString:return x_;case d.ObjectIdentifier:return m_;case d.OctetString:return xs;case d.PrintableString:return b_;case d.TeletexString:return v_;case d.UTCTime:return T_;case d.UniversalString:return w_;case d.Utf8String:return Vd;case d.VideotexString:return A_;case d.VisibleString:return __;default:return null}}function ar(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:ar(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Fd(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Fd(t)}return!1}function $x(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}var cf=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:A.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let h=d[s.type],p=Gr[h];if(!p)throw new Error(`Cannot get ASN1 class by name '${h}'`);c=new p({name:a})}else ar(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===A.Choice?c=new Wr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Wr({name:a});let f=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let h=s.repeated==="set"?Kt:Mt;c=new h({name:"",value:[new ci({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||ar(s.type)){let h=s.repeated?it:xn;o.push(new h({name:a,optional:f,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 it({name:h?"":a,optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:p}))}else o.push(new it({optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=f,o.push(c)}switch(n.type){case A.Sequence:return new Mt({value:o,name:""});case A.Set:return new Kt({value:o,name:""});case A.Choice:return new gs({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var Rt=new cf;var _=r=>e=>{let t;Rt.has(e)?t=Rt.get(e):(t=Rt.createDefault(e),Rt.set(e,t)),Object.assign(t,r)};var l=r=>(e,t)=>{let n;Rt.has(e.constructor)?n=Rt.get(e.constructor):(n=Rt.createDefault(e.constructor),Rt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=bs(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}n.items[t]=o};var hc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var dc=class{static parse(e,t){let n=An(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(ar(t))return new t().fromASN(e);let o=Rt.get(t);Rt.cache(t);let i=o.schema;if(e.constructor===it&&o.type!==A.Choice){i=new it({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=ro({},e,i);if(!s.verified)throw new hc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(Fd(t)){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=o.itemType;if(typeof c=="number"){let f=bs(c);if(!f)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,h=>f.fromASN(h))}else return t.from(e.valueBlock.value,f=>this.fromASN(f,c))}for(let c in o.items){let f=s.result[c];if(!f)continue;let h=o.items[c],p=h.type;if(typeof p=="number"||ar(p)){let m=(n=h.converter)!==null&&n!==void 0?n:ar(p)?new p:null;if(!m)throw new Error("Converter is empty");if(h.repeated)if(h.implicit){let v=h.repeated==="sequence"?Mt:Kt,g=new v;g.valueBlock=f.valueBlock;let w=An(g.toBER(!1));if(w.offset===-1)throw new Error(`Cannot parse the child item. ${w.result.error}`);if(!("value"in w.result.valueBlock&&Array.isArray(w.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let S=w.result.valueBlock.value;a[c]=Array.from(S,O=>m.fromASN(O))}else a[c]=Array.from(f,v=>m.fromASN(v));else{let v=f;if(h.implicit){let g;if(ar(p))g=new p().toSchema("");else{let w=d[p],S=Gr[w];if(!S)throw new Error(`Cannot get '${w}' class from asn1js module`);g=new S}g.valueBlock=v.valueBlock,v=An(g.toBER(!1)).result}a[c]=m.fromASN(v)}}else if(h.repeated){if(!Array.isArray(f))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");a[c]=Array.from(f,m=>this.fromASN(m,p))}else a[c]=this.fromASN(f,p)}return a}catch(o){throw o instanceof hc&&o.schemas.push(t.name),o}}};var mc=class r{static serialize(e){return e instanceof Je?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&ar(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Rt.get(t);Rt.cache(t);let o=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let s=bs(n.itemType);if(!s)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);o=e.map(a=>s.toASN(a))}else o=e.map(s=>this.toAsnItem({type:n.itemType},"[]",t,s))}else for(let s in n.items){let a=n.items[s],c=e[s];if(c===void 0||a.defaultValue===c||typeof a.defaultValue=="object"&&typeof c=="object"&&$x(this.serialize(a.defaultValue),this.serialize(c)))continue;let f=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||ar(a.type))){let h={};h.valueHex=f instanceof Ir?f.valueBeforeDecodeView:f.valueBlock.toBER(),o.push(new xn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...h}))}else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:f.valueBlock.value}));else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[f]}));else a.repeated?o=o.concat(f):o.push(f)}let i;switch(n.type){case A.Sequence:i=new Mt({value:o});break;case A.Set:i=new Kt({value:o});break;case A.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,f=>s.toASN(f)),c=e.repeated==="sequence"?Mt:Kt;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"?Mt:Kt;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 Wd=Lr(gn());var q=class r{static serialize(e){return mc.serialize(e)}static parse(e,t){return dc.parse(e,t)}static toString(e){let t=Wd.BufferSourceConverter.isBufferSource(e)?Wd.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=An(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 Fx=Lr(gn()),yc=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,f)=>c+(f.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(Fx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var Wx=Lr(gn()),qd,Gd,zd,Qe=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};u([l({type:d.TeletexString})],Qe.prototype,"teletexString",void 0);u([l({type:d.PrintableString})],Qe.prototype,"printableString",void 0);u([l({type:d.UniversalString})],Qe.prototype,"universalString",void 0);u([l({type:d.Utf8String})],Qe.prototype,"utf8String",void 0);u([l({type:d.BmpString})],Qe.prototype,"bmpString",void 0);Qe=u([_({type:A.Choice})],Qe);var vs=class extends Qe{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Wx.Convert.ToHex(this.anyValue):super.toString())}};u([l({type:d.IA5String})],vs.prototype,"ia5String",void 0);u([l({type:d.Any})],vs.prototype,"anyValue",void 0);vs=u([_({type:A.Choice})],vs);var ui=class{constructor(e={}){this.type="",this.value=new vs,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],ui.prototype,"type",void 0);u([l({type:vs})],ui.prototype,"value",void 0);var io=qd=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qd.prototype)}};io=qd=u([_({type:A.Set,itemType:ui})],io);var Xd=Gd=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gd.prototype)}};Xd=Gd=u([_({type:A.Sequence,itemType:io})],Xd);var Ne=zd=class extends Xd{constructor(e){super(e),Object.setPrototypeOf(this,zd.prototype)}};Ne=zd=u([_({type:A.Sequence})],Ne);var P_={fromASN:r=>yc.toString(xs.fromASN(r)),toASN:r=>xs.toASN(yc.fromString(r))},so=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],so.prototype,"typeId",void 0);u([l({type:d.Any,context:0})],so.prototype,"value",void 0);var gc=class{constructor(e={}){this.partyName=new Qe,Object.assign(this,e)}};u([l({type:Qe,optional:!0,context:0,implicit:!0})],gc.prototype,"nameAssigner",void 0);u([l({type:Qe,context:1,implicit:!0})],gc.prototype,"partyName",void 0);var ce=class{constructor(e={}){Object.assign(this,e)}};u([l({type:so,context:0,implicit:!0})],ce.prototype,"otherName",void 0);u([l({type:d.IA5String,context:1,implicit:!0})],ce.prototype,"rfc822Name",void 0);u([l({type:d.IA5String,context:2,implicit:!0})],ce.prototype,"dNSName",void 0);u([l({type:d.Any,context:3,implicit:!0})],ce.prototype,"x400Address",void 0);u([l({type:Ne,context:4,implicit:!1})],ce.prototype,"directoryName",void 0);u([l({type:gc,context:5})],ce.prototype,"ediPartyName",void 0);u([l({type:d.IA5String,context:6,implicit:!0})],ce.prototype,"uniformResourceIdentifier",void 0);u([l({type:d.OctetString,context:7,implicit:!0,converter:P_})],ce.prototype,"iPAddress",void 0);u([l({type:d.ObjectIdentifier,context:8,implicit:!0})],ce.prototype,"registeredID",void 0);ce=u([_({type:A.Choice})],ce);var ao="1.3.6.1.5.5.7",co=`${ao}.1`,qx=`${ao}.2`,li=`${ao}.3`,uf=`${ao}.48`,BN=`${qx}.1`,kN=`${qx}.2`,Yd=`${uf}.1`,Zd=`${uf}.2`,Jd=`${uf}.3`,Qd=`${uf}.5`,fe="2.5.29";var em,lf=`${co}.1`,Sn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ce,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Sn.prototype,"accessMethod",void 0);u([l({type:ce})],Sn.prototype,"accessLocation",void 0);var fi=em=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,em.prototype)}};fi=em=u([_({type:A.Sequence,itemType:Sn})],fi);var ff=`${fe}.35`,pi=class extends se{},Xr=class{constructor(e={}){e&&Object.assign(this,e)}};u([l({type:pi,context:0,optional:!0,implicit:!0})],Xr.prototype,"keyIdentifier",void 0);u([l({type:ce,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Xr.prototype,"authorityCertIssuer",void 0);u([l({type:d.Integer,context:2,optional:!0,implicit:!0,converter:ge})],Xr.prototype,"authorityCertSerialNumber",void 0);var pf=`${fe}.19`,hi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};u([l({type:d.Boolean,defaultValue:!1})],hi.prototype,"cA",void 0);u([l({type:d.Integer,optional:!0})],hi.prototype,"pathLenConstraint",void 0);var tm,He=tm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,tm.prototype)}};He=tm=u([_({type:A.Sequence,itemType:ce})],He);var rm,N_=`${fe}.29`,Gx=rm=class extends He{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};Gx=rm=u([_({type:A.Sequence})],Gx);var nm,df=`${fe}.32`,cO=`${df}.0`,En=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};u([l({type:d.IA5String})],En.prototype,"ia5String",void 0);u([l({type:d.VisibleString})],En.prototype,"visibleString",void 0);u([l({type:d.BmpString})],En.prototype,"bmpString",void 0);u([l({type:d.Utf8String})],En.prototype,"utf8String",void 0);En=u([_({type:A.Choice})],En);var wc=class{constructor(e={}){this.organization=new En,this.noticeNumbers=[],Object.assign(this,e)}};u([l({type:En})],wc.prototype,"organization",void 0);u([l({type:d.Integer,repeated:"sequence"})],wc.prototype,"noticeNumbers",void 0);var xc=class{constructor(e={}){Object.assign(this,e)}};u([l({type:wc,optional:!0})],xc.prototype,"noticeRef",void 0);u([l({type:En,optional:!0})],xc.prototype,"explicitText",void 0);var hf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.IA5String})],hf.prototype,"cPSuri",void 0);u([l({type:xc})],hf.prototype,"userNotice",void 0);hf=u([_({type:A.Choice})],hf);var bc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],bc.prototype,"policyQualifierId",void 0);u([l({type:d.Any})],bc.prototype,"qualifier",void 0);var di=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],di.prototype,"policyIdentifier",void 0);u([l({type:bc,repeated:"sequence",optional:!0})],di.prototype,"policyQualifiers",void 0);var vc=nm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};vc=nm=u([_({type:A.Sequence,itemType:di})],vc);var yO=`${fe}.20`,Ac=class{constructor(e=0){this.value=e}};u([l({type:d.Integer})],Ac.prototype,"value",void 0);Ac=u([_({type:A.Choice})],Ac);var SO=`${fe}.27`,zx=class extends Ac{};zx=u([_({type:A.Choice})],zx);var om,mf=`${fe}.31`,Pr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Pr||(Pr={}));var Sc=class extends zr{toJSON(){let e=[],t=this.toNumber();return t&Pr.aACompromise&&e.push("aACompromise"),t&Pr.affiliationChanged&&e.push("affiliationChanged"),t&Pr.cACompromise&&e.push("cACompromise"),t&Pr.certificateHold&&e.push("certificateHold"),t&Pr.cessationOfOperation&&e.push("cessationOfOperation"),t&Pr.keyCompromise&&e.push("keyCompromise"),t&Pr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Pr.superseded&&e.push("superseded"),t&Pr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},_n=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ce,context:0,repeated:"sequence",implicit:!0})],_n.prototype,"fullName",void 0);u([l({type:io,context:1,implicit:!0})],_n.prototype,"nameRelativeToCRLIssuer",void 0);_n=u([_({type:A.Choice})],_n);var Yr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:_n,context:0,optional:!0})],Yr.prototype,"distributionPoint",void 0);u([l({type:Sc,context:1,optional:!0,implicit:!0})],Yr.prototype,"reasons",void 0);u([l({type:ce,context:2,optional:!0,repeated:"sequence",implicit:!0})],Yr.prototype,"cRLIssuer",void 0);var uo=om=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};uo=om=u([_({type:A.Sequence,itemType:Yr})],uo);var im,jO=`${fe}.46`,Xx=im=class extends uo{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};Xx=im=u([_({type:A.Sequence,itemType:Yr})],Xx);var qO=`${fe}.28`,Zt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Zt.ONLY=!1;u([l({type:_n,context:0,optional:!0})],Zt.prototype,"distributionPoint",void 0);u([l({type:d.Boolean,context:1,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsUserCerts",void 0);u([l({type:d.Boolean,context:2,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsCACerts",void 0);u([l({type:Sc,context:3,optional:!0,implicit:!0})],Zt.prototype,"onlySomeReasons",void 0);u([l({type:d.Boolean,context:4,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"indirectCRL",void 0);u([l({type:d.Boolean,context:5,defaultValue:Zt.ONLY,implicit:!0})],Zt.prototype,"onlyContainsAttributeCerts",void 0);var Yx=`${fe}.21`,Ec;(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"})(Ec||(Ec={}));var _c=class{constructor(e=Ec.unspecified){this.reason=Ec.unspecified,this.reason=e}toJSON(){return Ec[this.reason]}toString(){return this.toJSON()}};u([l({type:d.Enumerated})],_c.prototype,"reason",void 0);_c=u([_({type:A.Choice})],_c);var sm,yf=`${fe}.37`,Cc=sm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,sm.prototype)}};Cc=sm=u([_({type:A.Sequence,itemType:d.ObjectIdentifier})],Cc);var nR=`${yf}.0`,Zx=`${li}.1`,Jx=`${li}.2`,Qx=`${li}.3`,eb=`${li}.4`,tb=`${li}.8`,rb=`${li}.9`;var cR=`${fe}.54`,am=class{constructor(e=new ArrayBuffer(0)){this.value=e}};u([l({type:d.Integer,converter:ge})],am.prototype,"value",void 0);am=u([_({type:A.Choice})],am);var nb=`${fe}.24`,Ic=class{constructor(e){this.value=new Date,e&&(this.value=e)}};u([l({type:d.GeneralizedTime})],Ic.prototype,"value",void 0);Ic=u([_({type:A.Choice})],Ic);var cm,bR=`${fe}.18`,ob=cm=class extends He{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};ob=cm=u([_({type:A.Sequence})],ob);var gf=`${fe}.15`,Nr;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(Nr||(Nr={}));var As=class extends zr{toJSON(){let e=this.toNumber(),t=[];return e&Nr.cRLSign&&t.push("crlSign"),e&Nr.dataEncipherment&&t.push("dataEncipherment"),e&Nr.decipherOnly&&t.push("decipherOnly"),e&Nr.digitalSignature&&t.push("digitalSignature"),e&Nr.encipherOnly&&t.push("encipherOnly"),e&Nr.keyAgreement&&t.push("keyAgreement"),e&Nr.keyCertSign&&t.push("keyCertSign"),e&Nr.keyEncipherment&&t.push("keyEncipherment"),e&Nr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var um,kR=`${fe}.30`,Ss=class{constructor(e={}){this.base=new ce,this.minimum=0,Object.assign(this,e)}};u([l({type:ce})],Ss.prototype,"base",void 0);u([l({type:d.Integer,context:0,defaultValue:0,implicit:!0})],Ss.prototype,"minimum",void 0);u([l({type:d.Integer,context:1,optional:!0,implicit:!0})],Ss.prototype,"maximum",void 0);var wf=um=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};wf=um=u([_({type:A.Sequence,itemType:Ss})],wf);var xf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:wf,context:0,optional:!0,implicit:!0})],xf.prototype,"permittedSubtrees",void 0);u([l({type:wf,context:1,optional:!0,implicit:!0})],xf.prototype,"excludedSubtrees",void 0);var LR=`${fe}.36`,bf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.Integer,context:0,implicit:!0,optional:!0,converter:ge})],bf.prototype,"requireExplicitPolicy",void 0);u([l({type:d.Integer,context:1,implicit:!0,optional:!0,converter:ge})],bf.prototype,"inhibitPolicyMapping",void 0);var lm,HR=`${fe}.33`,Tc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Tc.prototype,"issuerDomainPolicy",void 0);u([l({type:d.ObjectIdentifier})],Tc.prototype,"subjectDomainPolicy",void 0);var ib=lm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};ib=lm=u([_({type:A.Sequence,itemType:Tc})],ib);var fm,pm=`${fe}.17`,vf=fm=class extends He{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};vf=fm=u([_({type:A.Sequence})],vf);var pt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],pt.prototype,"type",void 0);u([l({type:d.Any,repeated:"set"})],pt.prototype,"values",void 0);var hm,nD=`${fe}.9`,sb=hm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hm.prototype)}};sb=hm=u([_({type:A.Sequence,itemType:pt})],sb);var dm=`${fe}.14`,Ht=class extends pi{};var pD=`${fe}.16`,Af=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],Af.prototype,"notBefore",void 0);u([l({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],Af.prototype,"notAfter",void 0);var Bc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Bc||(Bc={}));var Sf=class extends zr{toJSON(){let e=[],t=this.toNumber();return t&Bc.pKIXCertificate&&e.push("pKIXCertificate"),t&Bc.newExtensions&&e.push("newExtensions"),t&Bc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Ef=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Sf,Object.assign(this,e)}};u([l({type:d.GeneralString})],Ef.prototype,"entrustVers",void 0);u([l({type:Sf})],Ef.prototype,"entrustInfoFlags",void 0);var mm,vD=`${co}.11`,ab=mm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};ab=mm=u([_({type:A.Sequence,itemType:Sn})],ab);var cb=Lr(gn()),j=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&cb.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};u([l({type:d.ObjectIdentifier})],j.prototype,"algorithm",void 0);u([l({type:d.Any,optional:!0})],j.prototype,"parameters",void 0);var ht=class{constructor(e={}){this.algorithm=new j,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],ht.prototype,"algorithm",void 0);u([l({type:d.BitString})],ht.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([l({type:d.UTCTime})],We.prototype,"utcTime",void 0);u([l({type:d.GeneralizedTime})],We.prototype,"generalTime",void 0);We=u([_({type:A.Choice})],We);var Cn=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([l({type:We})],Cn.prototype,"notBefore",void 0);u([l({type:We})],Cn.prototype,"notAfter",void 0);var ym,dt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new se,Object.assign(this,e)}};dt.CRITICAL=!1;u([l({type:d.ObjectIdentifier})],dt.prototype,"extnID",void 0);u([l({type:d.Boolean,defaultValue:dt.CRITICAL})],dt.prototype,"critical",void 0);u([l({type:se})],dt.prototype,"extnValue",void 0);var Jt=ym=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ym.prototype)}};Jt=ym=u([_({type:A.Sequence,itemType:dt})],Jt);var Zr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(Zr||(Zr={}));var mt=class{constructor(e={}){this.version=Zr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new j,this.issuer=new Ne,this.validity=new Cn,this.subject=new Ne,this.subjectPublicKeyInfo=new ht,Object.assign(this,e)}};u([l({type:d.Integer,context:0,defaultValue:Zr.v1})],mt.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],mt.prototype,"serialNumber",void 0);u([l({type:j})],mt.prototype,"signature",void 0);u([l({type:Ne})],mt.prototype,"issuer",void 0);u([l({type:Cn})],mt.prototype,"validity",void 0);u([l({type:Ne})],mt.prototype,"subject",void 0);u([l({type:ht})],mt.prototype,"subjectPublicKeyInfo",void 0);u([l({type:d.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);u([l({type:d.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);u([l({type:Jt,context:3,optional:!0})],mt.prototype,"extensions",void 0);var cr=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:mt})],cr.prototype,"tbsCertificate",void 0);u([l({type:j})],cr.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],cr.prototype,"signatureValue",void 0);var mi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new We,Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],mi.prototype,"userCertificate",void 0);u([l({type:We})],mi.prototype,"revocationDate",void 0);u([l({type:dt,optional:!0,repeated:"sequence"})],mi.prototype,"crlEntryExtensions",void 0);var Qt=class{constructor(e={}){this.signature=new j,this.issuer=new Ne,this.thisUpdate=new We,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Qt.prototype,"version",void 0);u([l({type:j})],Qt.prototype,"signature",void 0);u([l({type:Ne})],Qt.prototype,"issuer",void 0);u([l({type:We})],Qt.prototype,"thisUpdate",void 0);u([l({type:We,optional:!0})],Qt.prototype,"nextUpdate",void 0);u([l({type:mi,repeated:"sequence",optional:!0})],Qt.prototype,"revokedCertificates",void 0);u([l({type:dt,optional:!0,context:0,repeated:"sequence"})],Qt.prototype,"crlExtensions",void 0);var yi=class{constructor(e={}){this.tbsCertList=new Qt,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Qt})],yi.prototype,"tbsCertList",void 0);u([l({type:j})],yi.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],yi.prototype,"signature",void 0);var H=Lr(gn());var Or=class{constructor(e={}){this.issuer=new Ne,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Ne})],Or.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],Or.prototype,"serialNumber",void 0);var gi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],gi.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],gi.prototype,"issuerAndSerialNumber",void 0);gi=u([_({type:A.Choice})],gi);var yt;(function(r){r[r.v0=0]="v0",r[r.v1=1]="v1",r[r.v2=2]="v2",r[r.v3=3]="v3",r[r.v4=4]="v4",r[r.v5=5]="v5"})(yt||(yt={}));var wi=class extends j{};wi=u([_({type:A.Sequence})],wi);var kc=class extends j{};kc=u([_({type:A.Sequence})],kc);var Vt=class extends j{};Vt=u([_({type:A.Sequence})],Vt);var Pc=class extends j{};Pc=u([_({type:A.Sequence})],Pc);var lb=class extends j{};lb=u([_({type:A.Sequence})],lb);var _f=class extends j{};_f=u([_({type:A.Sequence})],_f);var Rr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Rr.prototype,"attrType",void 0);u([l({type:d.Any,repeated:"set"})],Rr.prototype,"attrValues",void 0);var gm,$t=class{constructor(e={}){this.version=yt.v0,this.sid=new gi,this.digestAlgorithm=new wi,this.signatureAlgorithm=new kc,this.signature=new se,Object.assign(this,e)}};u([l({type:d.Integer})],$t.prototype,"version",void 0);u([l({type:gi})],$t.prototype,"sid",void 0);u([l({type:wi})],$t.prototype,"digestAlgorithm",void 0);u([l({type:Rr,repeated:"set",context:0,implicit:!0,optional:!0})],$t.prototype,"signedAttrs",void 0);u([l({type:kc})],$t.prototype,"signatureAlgorithm",void 0);u([l({type:se})],$t.prototype,"signature",void 0);u([l({type:Rr,repeated:"set",context:1,implicit:!0,optional:!0})],$t.prototype,"unsignedAttrs",void 0);var Nc=gm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};Nc=gm=u([_({type:A.Set,itemType:$t})],Nc);var fb=class extends We{};fb=u([_({type:A.Choice})],fb);var pb=class extends $t{};pb=u([_({type:A.Sequence})],pb);var Oc=class{constructor(e={}){this.acIssuer=new ce,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};u([l({type:ce})],Oc.prototype,"acIssuer",void 0);u([l({type:d.Integer})],Oc.prototype,"acSerial",void 0);u([l({type:pt,repeated:"sequence"})],Oc.prototype,"attrs",void 0);var wm,Rc=wm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,wm.prototype)}};Rc=wm=u([_({type:A.Sequence,itemType:d.ObjectIdentifier})],Rc);var Es=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};u([l({type:d.Integer,optional:!0})],Es.prototype,"pathLenConstraint",void 0);u([l({type:Rc,implicit:!0,context:0,optional:!0})],Es.prototype,"permittedAttrs",void 0);u([l({type:Rc,implicit:!0,context:1,optional:!0})],Es.prototype,"excludedAttrs",void 0);u([l({type:d.Boolean,defaultValue:!0})],Es.prototype,"permitUnSpecified",void 0);var ur=class{constructor(e={}){this.issuer=new He,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:He})],ur.prototype,"issuer",void 0);u([l({type:d.Integer,converter:ge})],ur.prototype,"serial",void 0);u([l({type:d.BitString,optional:!0})],ur.prototype,"issuerUID",void 0);var xm;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(xm||(xm={}));var lr=class{constructor(e={}){this.digestedObjectType=xm.publicKey,this.digestAlgorithm=new j,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Enumerated})],lr.prototype,"digestedObjectType",void 0);u([l({type:d.ObjectIdentifier,optional:!0})],lr.prototype,"otherObjectTypeID",void 0);u([l({type:j})],lr.prototype,"digestAlgorithm",void 0);u([l({type:d.BitString})],lr.prototype,"objectDigest",void 0);var xi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:He,optional:!0})],xi.prototype,"issuerName",void 0);u([l({type:ur,context:0,implicit:!0,optional:!0})],xi.prototype,"baseCertificateID",void 0);u([l({type:lr,context:1,implicit:!0,optional:!0})],xi.prototype,"objectDigestInfo",void 0);var bi=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ce,repeated:"sequence"})],bi.prototype,"v1Form",void 0);u([l({type:xi,context:0,implicit:!0})],bi.prototype,"v2Form",void 0);bi=u([_({type:A.Choice})],bi);var vi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};u([l({type:d.GeneralizedTime})],vi.prototype,"notBeforeTime",void 0);u([l({type:d.GeneralizedTime})],vi.prototype,"notAfterTime",void 0);var lo=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ur,implicit:!0,context:0,optional:!0})],lo.prototype,"baseCertificateID",void 0);u([l({type:He,implicit:!0,context:1,optional:!0})],lo.prototype,"entityName",void 0);u([l({type:lr,implicit:!0,context:2,optional:!0})],lo.prototype,"objectDigestInfo",void 0);var bm;(function(r){r[r.v2=1]="v2"})(bm||(bm={}));var Ft=class{constructor(e={}){this.version=bm.v2,this.holder=new lo,this.issuer=new bi,this.signature=new j,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new vi,this.attributes=[],Object.assign(this,e)}};u([l({type:d.Integer})],Ft.prototype,"version",void 0);u([l({type:lo})],Ft.prototype,"holder",void 0);u([l({type:bi})],Ft.prototype,"issuer",void 0);u([l({type:j})],Ft.prototype,"signature",void 0);u([l({type:d.Integer,converter:ge})],Ft.prototype,"serialNumber",void 0);u([l({type:vi})],Ft.prototype,"attrCertValidityPeriod",void 0);u([l({type:pt,repeated:"sequence"})],Ft.prototype,"attributes",void 0);u([l({type:d.BitString,optional:!0})],Ft.prototype,"issuerUniqueID",void 0);u([l({type:Jt,optional:!0})],Ft.prototype,"extensions",void 0);var Ai=class{constructor(e={}){this.acinfo=new Ft,this.signatureAlgorithm=new j,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:Ft})],Ai.prototype,"acinfo",void 0);u([l({type:j})],Ai.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Ai.prototype,"signatureValue",void 0);var Dc;(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"})(Dc||(Dc={}));var _s=class extends zr{};var Cs=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier,implicit:!0,context:0})],Cs.prototype,"type",void 0);u([l({type:d.Any,implicit:!0,context:1})],Cs.prototype,"value",void 0);var Lc=class{constructor(e={}){this.policyId="",this.classList=new _s(Dc.unclassified),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Lc.prototype,"policyId",void 0);u([l({type:_s,defaultValue:new _s(Dc.unclassified)})],Lc.prototype,"classList",void 0);u([l({type:Cs,repeated:"set"})],Lc.prototype,"securityCategories",void 0);var Is=class{constructor(e={}){Object.assign(this,e)}};u([l({type:se})],Is.prototype,"cotets",void 0);u([l({type:d.ObjectIdentifier})],Is.prototype,"oid",void 0);u([l({type:d.Utf8String})],Is.prototype,"string",void 0);var Cf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};u([l({type:He,implicit:!0,context:0,optional:!0})],Cf.prototype,"policyAuthority",void 0);u([l({type:Is,repeated:"sequence"})],Cf.prototype,"values",void 0);var tj=`${co}.4`,rj=`${co}.6`,nj=`${co}.10`,oj=`${fe}.55`,Uc=`${ao}.10`,ij=`${Uc}.1`,sj=`${Uc}.2`,aj=`${Uc}.3`,cj=`${Uc}.4`,uj=`${Uc}.6`,vm="2.5.4",lj=`${vm}.72`;var Am,Ts=class{constructor(e={}){this.targetCertificate=new ur,Object.assign(this,e)}};u([l({type:ur})],Ts.prototype,"targetCertificate",void 0);u([l({type:ce,optional:!0})],Ts.prototype,"targetName",void 0);u([l({type:lr,optional:!0})],Ts.prototype,"certDigestInfo",void 0);var Bs=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ce,context:0,implicit:!0})],Bs.prototype,"targetName",void 0);u([l({type:ce,context:1,implicit:!0})],Bs.prototype,"targetGroup",void 0);u([l({type:Ts,context:2,implicit:!0})],Bs.prototype,"targetCert",void 0);Bs=u([_({type:A.Choice})],Bs);var If=Am=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Am.prototype)}};If=Am=u([_({type:A.Sequence,itemType:Bs})],If);var Sm,hb=Sm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sm.prototype)}};hb=Sm=u([_({type:A.Sequence,itemType:If})],hb);var Tf=class{constructor(e={}){Object.assign(this,e)}};u([l({type:He,implicit:!0,context:0,optional:!0})],Tf.prototype,"roleAuthority",void 0);u([l({type:ce,implicit:!0,context:1})],Tf.prototype,"roleName",void 0);var jc=class{constructor(e={}){this.service=new ce,this.ident=new ce,Object.assign(this,e)}};u([l({type:ce})],jc.prototype,"service",void 0);u([l({type:ce})],jc.prototype,"ident",void 0);u([l({type:se,optional:!0})],jc.prototype,"authInfo",void 0);var Em,Mc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Mc.prototype,"otherCertFormat",void 0);u([l({type:d.Any})],Mc.prototype,"otherCert",void 0);var Si=class{constructor(e={}){Object.assign(this,e)}};u([l({type:cr})],Si.prototype,"certificate",void 0);u([l({type:Ai,context:2,implicit:!0})],Si.prototype,"v2AttrCert",void 0);u([l({type:Mc,context:3,implicit:!0})],Si.prototype,"other",void 0);Si=u([_({type:A.Choice})],Si);var Ei=Em=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Em.prototype)}};Ei=Em=u([_({type:A.Set,itemType:Si})],Ei);var fr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],fr.prototype,"contentType",void 0);u([l({type:d.Any,context:0})],fr.prototype,"content",void 0);var ks=class{constructor(e={}){Object.assign(this,e)}};u([l({type:se})],ks.prototype,"single",void 0);u([l({type:d.Any})],ks.prototype,"any",void 0);ks=u([_({type:A.Choice})],ks);var _i=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],_i.prototype,"eContentType",void 0);u([l({type:ks,context:0,optional:!0})],_i.prototype,"eContent",void 0);var Kc=class{constructor(e={}){Object.assign(this,e)}};u([l({type:se,context:0,implicit:!0,optional:!0})],Kc.prototype,"value",void 0);u([l({type:se,converter:Vx,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Kc.prototype,"constructedValue",void 0);Kc=u([_({type:A.Choice})],Kc);var fo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Pc,Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],fo.prototype,"contentType",void 0);u([l({type:Pc})],fo.prototype,"contentEncryptionAlgorithm",void 0);u([l({type:Kc,optional:!0})],fo.prototype,"encryptedContent",void 0);var po=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],po.prototype,"keyAttrId",void 0);u([l({type:d.Any,optional:!0})],po.prototype,"keyAttr",void 0);var _m,Ps=class{constructor(e={}){this.subjectKeyIdentifier=new Ht,Object.assign(this,e)}};u([l({type:Ht})],Ps.prototype,"subjectKeyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],Ps.prototype,"date",void 0);u([l({type:po,optional:!0})],Ps.prototype,"other",void 0);var Ns=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ps,context:0,implicit:!0,optional:!0})],Ns.prototype,"rKeyId",void 0);u([l({type:Or,optional:!0})],Ns.prototype,"issuerAndSerialNumber",void 0);Ns=u([_({type:A.Choice})],Ns);var Hc=class{constructor(e={}){this.rid=new Ns,this.encryptedKey=new se,Object.assign(this,e)}};u([l({type:Ns})],Hc.prototype,"rid",void 0);u([l({type:se})],Hc.prototype,"encryptedKey",void 0);var Bf=_m=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};Bf=_m=u([_({type:A.Sequence,itemType:Hc})],Bf);var Vc=class{constructor(e={}){this.algorithm=new j,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:j})],Vc.prototype,"algorithm",void 0);u([l({type:d.BitString})],Vc.prototype,"publicKey",void 0);var Ci=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0,optional:!0})],Ci.prototype,"subjectKeyIdentifier",void 0);u([l({type:Vc,context:1,implicit:!0,optional:!0})],Ci.prototype,"originatorKey",void 0);u([l({type:Or,optional:!0})],Ci.prototype,"issuerAndSerialNumber",void 0);Ci=u([_({type:A.Choice})],Ci);var In=class{constructor(e={}){this.version=yt.v3,this.originator=new Ci,this.keyEncryptionAlgorithm=new Vt,this.recipientEncryptedKeys=new Bf,Object.assign(this,e)}};u([l({type:d.Integer})],In.prototype,"version",void 0);u([l({type:Ci,context:0})],In.prototype,"originator",void 0);u([l({type:se,context:1,optional:!0})],In.prototype,"ukm",void 0);u([l({type:Vt})],In.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:Bf})],In.prototype,"recipientEncryptedKeys",void 0);var Os=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ht,context:0,implicit:!0})],Os.prototype,"subjectKeyIdentifier",void 0);u([l({type:Or})],Os.prototype,"issuerAndSerialNumber",void 0);Os=u([_({type:A.Choice})],Os);var ho=class{constructor(e={}){this.version=yt.v0,this.rid=new Os,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new se,Object.assign(this,e)}};u([l({type:d.Integer})],ho.prototype,"version",void 0);u([l({type:Os})],ho.prototype,"rid",void 0);u([l({type:Vt})],ho.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:se})],ho.prototype,"encryptedKey",void 0);var Ii=class{constructor(e={}){this.keyIdentifier=new se,Object.assign(this,e)}};u([l({type:se})],Ii.prototype,"keyIdentifier",void 0);u([l({type:d.GeneralizedTime,optional:!0})],Ii.prototype,"date",void 0);u([l({type:po,optional:!0})],Ii.prototype,"other",void 0);var mo=class{constructor(e={}){this.version=yt.v4,this.kekid=new Ii,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new se,Object.assign(this,e)}};u([l({type:d.Integer})],mo.prototype,"version",void 0);u([l({type:Ii})],mo.prototype,"kekid",void 0);u([l({type:Vt})],mo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:se})],mo.prototype,"encryptedKey",void 0);var yo=class{constructor(e={}){this.version=yt.v0,this.keyEncryptionAlgorithm=new Vt,this.encryptedKey=new se,Object.assign(this,e)}};u([l({type:d.Integer})],yo.prototype,"version",void 0);u([l({type:_f,context:0,optional:!0})],yo.prototype,"keyDerivationAlgorithm",void 0);u([l({type:Vt})],yo.prototype,"keyEncryptionAlgorithm",void 0);u([l({type:se})],yo.prototype,"encryptedKey",void 0);var $c=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],$c.prototype,"oriType",void 0);u([l({type:d.Any})],$c.prototype,"oriValue",void 0);var Tn=class{constructor(e={}){Object.assign(this,e)}};u([l({type:ho,optional:!0})],Tn.prototype,"ktri",void 0);u([l({type:In,context:1,implicit:!0,optional:!0})],Tn.prototype,"kari",void 0);u([l({type:mo,context:2,implicit:!0,optional:!0})],Tn.prototype,"kekri",void 0);u([l({type:yo,context:3,implicit:!0,optional:!0})],Tn.prototype,"pwri",void 0);u([l({type:$c,context:4,implicit:!0,optional:!0})],Tn.prototype,"ori",void 0);Tn=u([_({type:A.Choice})],Tn);var Cm,Fc=Cm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Cm.prototype)}};Fc=Cm=u([_({type:A.Set,itemType:Tn})],Fc);var Im,db=`${ao}.16`,uK=`${db}.2`,lK=`${db}.4`,Rs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Rs.prototype,"otherRevInfoFormat",void 0);u([l({type:d.Any})],Rs.prototype,"otherRevInfo",void 0);var kf=class{constructor(e={}){this.other=new Rs,Object.assign(this,e)}};u([l({type:Rs,context:1,implicit:!0})],kf.prototype,"other",void 0);kf=u([_({type:A.Choice})],kf);var Ds=Im=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Im.prototype)}};Ds=Im=u([_({type:A.Set,itemType:kf})],Ds);var Ls=class{constructor(e={}){Object.assign(this,e)}};u([l({type:Ei,context:0,implicit:!0,optional:!0})],Ls.prototype,"certs",void 0);u([l({type:Ds,context:1,implicit:!0,optional:!0})],Ls.prototype,"crls",void 0);var Tm,Bm=Tm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Tm.prototype)}};Bm=Tm=u([_({type:A.Set,itemType:Rr})],Bm);var Ti=class{constructor(e={}){this.version=yt.v0,this.recipientInfos=new Fc,this.encryptedContentInfo=new fo,Object.assign(this,e)}};u([l({type:d.Integer})],Ti.prototype,"version",void 0);u([l({type:Ls,context:0,implicit:!0,optional:!0})],Ti.prototype,"originatorInfo",void 0);u([l({type:Fc})],Ti.prototype,"recipientInfos",void 0);u([l({type:fo})],Ti.prototype,"encryptedContentInfo",void 0);u([l({type:Bm,context:1,implicit:!0,optional:!0})],Ti.prototype,"unprotectedAttrs",void 0);var mb="1.2.840.113549.1.7.2";var km,Pf=km=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,km.prototype)}};Pf=km=u([_({type:A.Set,itemType:wi})],Pf);var Bn=class{constructor(e={}){this.version=yt.v0,this.digestAlgorithms=new Pf,this.encapContentInfo=new _i,this.signerInfos=new Nc,Object.assign(this,e)}};u([l({type:d.Integer})],Bn.prototype,"version",void 0);u([l({type:Pf})],Bn.prototype,"digestAlgorithms",void 0);u([l({type:_i})],Bn.prototype,"encapContentInfo",void 0);u([l({type:Ei,context:0,implicit:!0,optional:!0})],Bn.prototype,"certificates",void 0);u([l({type:Ds,context:1,implicit:!0,optional:!0})],Bn.prototype,"crls",void 0);u([l({type:Nc})],Bn.prototype,"signerInfos",void 0);var Bi="1.2.840.10045.2.1";var Wc="1.2.840.10045.4.1",Nf="1.2.840.10045.4.3.1",qc="1.2.840.10045.4.3.2",Gc="1.2.840.10045.4.3.3",zc="1.2.840.10045.4.3.4";var Pm="1.2.840.10045.3.1.7";var Nm="1.3.132.0.34";var Om="1.3.132.0.35";function Xc(r){return new j({algorithm:r})}var gb=Xc(Wc),sH=Xc(Nf),wb=Xc(qc),xb=Xc(Gc),bb=Xc(zc);var Yc=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Yc.prototype,"fieldType",void 0);u([l({type:d.Any})],Yc.prototype,"parameters",void 0);Yc=u([_({type:A.Sequence})],Yc);var Rm=class extends se{};var Us=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.OctetString})],Us.prototype,"a",void 0);u([l({type:d.OctetString})],Us.prototype,"b",void 0);u([l({type:d.BitString,optional:!0})],Us.prototype,"seed",void 0);Us=u([_({type:A.Sequence})],Us);var Dm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Dm||(Dm={}));var Jr=class{constructor(e={}){this.version=Dm.ecpVer1,Object.assign(this,e)}};u([l({type:d.Integer})],Jr.prototype,"version",void 0);u([l({type:Yc})],Jr.prototype,"fieldID",void 0);u([l({type:Us})],Jr.prototype,"curve",void 0);u([l({type:Rm})],Jr.prototype,"base",void 0);u([l({type:d.Integer,converter:ge})],Jr.prototype,"order",void 0);u([l({type:d.Integer,optional:!0})],Jr.prototype,"cofactor",void 0);Jr=u([_({type:A.Sequence})],Jr);var Qr=class{constructor(e={}){Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Qr.prototype,"namedCurve",void 0);u([l({type:d.Null})],Qr.prototype,"implicitCurve",void 0);u([l({type:Jr})],Qr.prototype,"specifiedCurve",void 0);Qr=u([_({type:A.Choice})],Qr);var js=class{constructor(e={}){this.version=1,this.privateKey=new se,Object.assign(this,e)}};u([l({type:d.Integer})],js.prototype,"version",void 0);u([l({type:se})],js.prototype,"privateKey",void 0);u([l({type:Qr,context:0,optional:!0})],js.prototype,"parameters",void 0);u([l({type:d.BitString,context:1,optional:!0})],js.prototype,"publicKey",void 0);var ki=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],ki.prototype,"r",void 0);u([l({type:d.Integer,converter:ge})],ki.prototype,"s",void 0);var Wt="1.2.840.113549.1.1",en=`${Wt}.1`,vb=`${Wt}.7`,Ab=`${Wt}.9`,go=`${Wt}.10`,Sb=`${Wt}.2`,Eb=`${Wt}.4`,Ms=`${Wt}.5`,_b=`${Wt}.14`;var Of=`${Wt}.11`,Ks=`${Wt}.12`,Hs=`${Wt}.13`,Lm=`${Wt}.15`,Um=`${Wt}.16`,Pi="1.3.14.3.2.26",Rf="2.16.840.1.101.3.4.2.4",Ni="2.16.840.1.101.3.4.2.1",Oi="2.16.840.1.101.3.4.2.2",Ri="2.16.840.1.101.3.4.2.3",Cb="2.16.840.1.101.3.4.2.5",Ib="2.16.840.1.101.3.4.2.6",Tb="1.2.840.113549.2.2",Bb="1.2.840.113549.2.5",wo=`${Wt}.8`;function st(r){return new j({algorithm:r,parameters:null})}var RH=st(Tb),DH=st(Bb),kn=st(Pi),LH=st(Rf),UH=st(Ni),jH=st(Oi),MH=st(Ri),KH=st(Cb),HH=st(Ib),Df=new j({algorithm:wo,parameters:q.serialize(kn)}),jm=new j({algorithm:Ab,parameters:q.serialize(xs.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),VH=st(en),$H=st(Sb),FH=st(Eb),WH=st(Ms),qH=st(Lm),GH=st(Um),zH=st(Ks),XH=st(Hs),YH=st(Lm),ZH=st(Um);var Vs=class{constructor(e={}){this.hashAlgorithm=new j(kn),this.maskGenAlgorithm=new j({algorithm:wo,parameters:q.serialize(kn)}),this.pSourceAlgorithm=new j(jm),Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:kn})],Vs.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:Df})],Vs.prototype,"maskGenAlgorithm",void 0);u([l({type:j,context:2,defaultValue:jm})],Vs.prototype,"pSourceAlgorithm",void 0);var o7=new j({algorithm:vb,parameters:q.serialize(new Vs)});var tn=class{constructor(e={}){this.hashAlgorithm=new j(kn),this.maskGenAlgorithm=new j({algorithm:wo,parameters:q.serialize(kn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};u([l({type:j,context:0,defaultValue:kn})],tn.prototype,"hashAlgorithm",void 0);u([l({type:j,context:1,defaultValue:Df})],tn.prototype,"maskGenAlgorithm",void 0);u([l({type:d.Integer,context:2,defaultValue:20})],tn.prototype,"saltLength",void 0);u([l({type:d.Integer,context:3,defaultValue:1})],tn.prototype,"trailerField",void 0);var f7=new j({algorithm:go,parameters:q.serialize(new tn)});var Di=class{constructor(e={}){this.digestAlgorithm=new j,this.digest=new se,Object.assign(this,e)}};u([l({type:j})],Di.prototype,"digestAlgorithm",void 0);u([l({type:se})],Di.prototype,"digest",void 0);var Mm,$s=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],$s.prototype,"prime",void 0);u([l({type:d.Integer,converter:ge})],$s.prototype,"exponent",void 0);u([l({type:d.Integer,converter:ge})],$s.prototype,"coefficient",void 0);var Lf=Mm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};Lf=Mm=u([_({type:A.Sequence,itemType:$s})],Lf);var pr=class{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer})],pr.prototype,"version",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"publicExponent",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"privateExponent",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"prime1",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"prime2",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"exponent1",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"exponent2",void 0);u([l({type:d.Integer,converter:ge})],pr.prototype,"coefficient",void 0);u([l({type:Lf,optional:!0})],pr.prototype,"otherPrimeInfos",void 0);var Fs=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.Integer,converter:ge})],Fs.prototype,"modulus",void 0);u([l({type:d.Integer,converter:ge})],Fs.prototype,"publicExponent",void 0);var Km;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Km||(Km={}));var gt=Km;var Zb=Lr(Yb(),1),{__extends:qs,__assign:V7,__rest:j_,__decorate:$7,__param:F7,__metadata:W7,__awaiter:Jb,__generator:Qb,__exportStar:q7,__createBinding:G7,__values:Zc,__read:Jc,__spread:Dr,__spreadArrays:z7,__await:X7,__asyncGenerator:Y7,__asyncDelegator:Z7,__asyncValues:J7,__makeTemplateObject:Q7,__importStar:eV,__importDefault:tV,__classPrivateFieldGet:rV,__classPrivateFieldSet:nV}=Zb.default;var M_="injectionTokens";function Vm(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(M_,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function Qc(r){return!!r.useClass}function Gs(r){return!!r.useFactory}var Mf=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,Dr(i))}};return this.reflectMethods.forEach(n),t},r}();function xo(r){return typeof r=="string"||typeof r=="symbol"}function $m(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Kf(r){return typeof r=="object"&&"token"in r&&"transform"in r}function ev(r){return typeof r=="function"||r instanceof Mf}function Li(r){return!!r.useToken}function Ui(r){return r.useValue!=null}function tv(r){return Qc(r)||Ui(r)||Li(r)||Gs(r)}var K_=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}(),eu=K_;var H_=function(r){qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(eu),rv=H_;var V_=function(){function r(){this.scopedResolutions=new Map}return r}(),tu=V_;function $_(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function F_(r,e,t){return t===void 0&&(t=" "),Dr([r],e.message.split(`
6
+ `)}`:`${t} :`}};vb=at;Q.Constructed=vb;at.NAME="CONSTRUCTED";var tf=class extends pt{fromBER(e,t,n){return t}toBER(e){return jr}};tf.override="EndOfContentValueBlock";var _b,uc=class extends Qe{constructor(e={}){super(e,tf),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};_b=uc;Q.EndOfContent=_b;uc.NAME=ac;var Ab,Pr=class extends Qe{constructor(e={}){super(e,pt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};Ab=Pr;Q.Null=Ab;Pr.NAME="NULL";var rf=class extends Jr(pt){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=de.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=de.BufferSourceConverter.toUint8Array(e);return En(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Rd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};rf.NAME="BooleanValueBlock";var Sb,Zo=class extends Qe{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,rf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Sb=Zo;Q.Boolean=Sb;Zo.NAME="BOOLEAN";var nf=class extends Jr(Zr){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=Zr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===ac){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==gb)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?Zr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};nf.NAME="OctetStringValueBlock";var Md,kr=class extends Qe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},nf),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=Es(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 at.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 Md&&e.push(t.valueBlock.valueHexView);return de.BufferSourceConverter.concat(e)}};Md=kr;Q.OctetString=Md;kr.NAME=gb;var of=class extends Jr(Zr){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=Zr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===ac){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==wb)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(!En(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=Es(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return Zr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return jr;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};of.NAME="BitStringValueBlock";var Eb,Nr=class extends Qe{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},of),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 at.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}`}}};Eb=Nr;Q.BitString=Eb;Nr.NAME=wb;var Tb;function C2(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,p=c<s?s:c,f=0;for(let m=p;m>=0;m--,f++){switch(!0){case f<a.length:l=i[s-f]+a[c-f]+t[0];break;default:l=i[s-f]+t[0]}switch(t[0]=l/10,!0){case f>=i.length:i=Zl(new Uint8Array([l%10]),i);break;default:i[s-f]=l%10}}return t[0]>0&&(i=Zl(t,i)),i}function mb(r){if(r>=ic.length)for(let e=ic.length;e<=r;e++){let t=new Uint8Array([0]),n=ic[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=Zl(t,n)),ic.push(n)}return ic[r]}function I2(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,p=0;for(let f=c;f>=0;f--,p++)switch(l=i[s-p]-a[c-p]-t,!0){case l<0:t=1,i[s-p]=l+10;break;default:t=0,i[s-p]=l}if(t>0)for(let f=s-c+1;f>=0;f--,p++)if(l=i[s-p]-t,l<0)t=1,i[s-p]=l+10;else{t=0,i[s-p]=l;break}return i.slice()}var lc=class extends Jr(pt){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Rd.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(pb(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=I2(mb(n),t),s="-";break;default:t=C2(t,mb(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=db.charAt(t[c]));return a===!1&&(s+=db.charAt(0)),s}};Tb=lc;lc.NAME="IntegerValueBlock";Object.defineProperty(Tb.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var sc,Sn=class extends Qe{constructor(e={}){super(e,lc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Yl(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Yl();let t=BigInt(e),n=new As,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,p=de.BufferSourceConverter.toUint8Array(de.Convert.FromHex(l.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new sc({valueHex:n.final()})}convertToDER(){let e=new sc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new sc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};sc=Sn;Q.Integer=sc;Sn.NAME="INTEGER";var Cb,Yo=class extends Sn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Cb=Yo;Q.Enumerated=Cb;Yo.NAME="ENUMERATED";var fc=class extends Jr(pt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=de.BufferSourceConverter.toUint8Array(e);if(!En(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=Xo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Yl();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=de.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};fc.NAME="sidBlock";var sf=class extends pt{constructor({value:e=Mt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new fc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,jr;t.push(o)}return Ud(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new fc;if(o>Number.MAX_SAFE_INTEGER){Yl();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};sf.NAME="ObjectIdentifierValueBlock";var Ib,Jo=class extends Qe{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,sf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Ib=Jo;Q.ObjectIdentifier=Ib;Jo.NAME="OBJECT IDENTIFIER";var pc=class extends Jr(_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(!En(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=Xo(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=ro(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",jr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=de.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};pc.NAME="relativeSidBlock";var af=class extends pt{constructor({value:e=Mt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new pc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,jr;n.push(i)}return Ud(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new pc;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};af.NAME="RelativeObjectIdentifierValueBlock";var Ob,hc=class extends Qe{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,af),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Ob=hc;Q.RelativeObjectIdentifier=Ob;hc.NAME="RelativeObjectIdentifier";var Bb,Kt=class extends at{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Bb=Kt;Q.Sequence=Bb;Kt.NAME="SEQUENCE";var Pb,Ht=class extends at{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Pb=Ht;Q.Set=Pb;Ht.NAME="SET";var cf=class extends Jr(pt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Mt}toJSON(){return{...super.toJSON(),value:this.value}}};cf.NAME="StringValueBlock";var uf=class extends cf{};uf.NAME="SimpleStringValueBlock";var Nt=class extends cc{constructor({...e}={}){super(e,uf)}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}};Nt.NAME="SIMPLE STRING";var lf=class extends Nt{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}};lf.NAME="Utf8StringValueBlock";var kb,cr=class extends lf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};kb=cr;Q.Utf8String=kb;cr.NAME="UTF8String";var ff=class extends Nt{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))}};ff.NAME="BmpStringValueBlock";var Nb,Qo=class extends ff{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nb=Qo;Q.BmpString=Nb;Qo.NAME="BMPString";var pf=class extends Nt{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=ro(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};pf.NAME="UniversalStringValueBlock";var jb,ei=class extends pf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};jb=ei;Q.UniversalString=jb;ei.NAME="UniversalString";var Rb,ti=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Rb=ti;Q.NumericString=Rb;ti.NAME="NumericString";var Db,ri=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Db=ri;Q.PrintableString=Db;ri.NAME="PrintableString";var Lb,ni=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Lb=ni;Q.TeletexString=Lb;ni.NAME="TeletexString";var Ub,oi=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ub=oi;Q.VideotexString=Ub;oi.NAME="VideotexString";var Mb,ii=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Mb=ii;Q.IA5String=Mb;ii.NAME="IA5String";var Kb,si=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Kb=si;Q.GraphicString=Kb;si.NAME="GraphicString";var Hb,oo=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Hb=oo;Q.VisibleString=Hb;oo.NAME="VisibleString";var Vb,ai=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Vb=ai;Q.GeneralString=Vb;ai.NAME="GeneralString";var $b,ci=class extends Nt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};$b=ci;Q.CharacterString=$b;ci.NAME="CharacterString";var Fb,io=class extends oo{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]=Ut(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ut(this.month,2),t[2]=Ut(this.day,2),t[3]=Ut(this.hour,2),t[4]=Ut(this.minute,2),t[5]=Ut(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}}};Fb=io;Q.UTCTime=Fb;io.NAME="UTCTime";var Wb,ui=class extends io{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,m=n.indexOf("+"),y="";if(m===-1&&(m=n.indexOf("-"),f=-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 b=parseInt(y.substring(0,2),10);if(isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*b,y.length===4){if(b=parseInt(y.substring(2,4),10),isNaN(b.valueOf()))throw new Error("Wrong input string for conversion");c=f*b}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");i=f.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 f=60*i;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*i;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*i;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let p=s.exec(o);if(p===null)throw new Error("Wrong input string for conversion");for(let f=1;f<p.length;f++)switch(f){case 1:this.year=parseInt(p[f],10);break;case 2:this.month=parseInt(p[f],10);break;case 3:this.day=parseInt(p[f],10);break;case 4:this.hour=parseInt(p[f],10)+a;break;case 5:this.minute=parseInt(p[f],10)+c;break;case 6:this.second=parseInt(p[f],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Ut(this.year,4)),t.push(Ut(this.month,2)),t.push(Ut(this.day,2)),t.push(Ut(this.hour,2)),t.push(Ut(this.minute,2)),t.push(Ut(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ut(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Wb=ui;Q.GeneralizedTime=Wb;ui.NAME="GeneralizedTime";var qb,dc=class extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};qb=dc;Q.DATE=qb;dc.NAME="DATE";var Gb,yc=class extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Gb=yc;Q.TimeOfDay=Gb;yc.NAME="TimeOfDay";var zb,mc=class extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};zb=mc;Q.DateTime=zb;mc.NAME="DateTime";var Xb,gc=class extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Xb=gc;Q.Duration=Xb;gc.NAME="Duration";var Zb,wc=class extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Zb=wc;Q.TIME=Zb;wc.NAME="TIME";var Yr=class{constructor({name:e=Mt,optional:t=!1}={}){this.name=e,this.optional=t}},Ss=class extends Yr{constructor({value:e=[],...t}={}){super(t),this.value=e}},li=class extends Yr{constructor({value:e=new Yr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Ld=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=de.BufferSourceConverter.toUint8Array(e)}constructor({data:e=hf}={}){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 no(r,e,t){if(t instanceof Ss){for(let i of t.value)if(no(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Dd)&&(i.name=t.name),i}}if(t instanceof Yr)return t.hasOwnProperty(Dd)&&(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(!(w2 in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(_2 in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(A2 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(b2)===!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(x2)===!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(v2)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(g2 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(!(yb in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};let i=t.idBlock.valueHexView,s=e.idBlock.valueHexView;if(i.length!==s.length)return{verified:!1,result:r};for(let a=0;a<i.length;a++)if(i[a]!==s[1])return{verified:!1,result:r}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(r[t.name]=e)),t instanceof Q.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof li&&(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,Mt),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let c=0;c<a;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){let 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,Mt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof li){if(s=no(r,e.valueBlock.value[c],t.valueBlock.value[0].value),s.verified===!1)if(t.valueBlock.value[0].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&delete r[t.name]),s;if(Dd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};S2 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=no(r,e.valueBlock.value[c-i],t.valueBlock.value[c]),s.verified===!1)if(t.valueBlock.value[c].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&delete r[t.name]),s;if(s.verified===!1){let c={verified:!1,result:r};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&yb in e.valueBlock){let i=Es(e.valueBlock.valueHexView);if(i.offset===-1){let s={verified:!1,result:i.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Mt),t.name&&(delete r[t.name],s.name=t.name)),s}return no(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function O2(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Es(de.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:no(t.result,t.result,e)}var _;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(_||(_={}));var h;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(h||(h={}));var Kd=Hr(vn()),en=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Kd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Kd.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 Hd=Hr(vn()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Hd.BufferSourceConverter.isBufferSource(e)?this.buffer=Hd.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 B2={fromASN:r=>r instanceof Pr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Pr;let e=Tn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},P2={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Sn({value:+r})},k2={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Yo({value:r})},me={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Sn({valueHex:r})};var N2={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Nr({valueHex:r})},j2={fromASN:r=>r.valueBlock.toString(),toASN:r=>new Jo({value:r})},R2={fromASN:r=>r.valueBlock.value,toASN:r=>new Zo({value:r})},Ts={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new kr({valueHex:r})},Yb={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function ur(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Vd=ur(cr),D2=ur(Qo),L2=ur(ei),U2=ur(ti),M2=ur(ri),K2=ur(ni),H2=ur(oi),V2=ur(ii),$2=ur(si),F2=ur(oo),W2=ur(ai),q2=ur(ci),G2={fromASN:r=>r.toDate(),toASN:r=>new io({valueDate:r})},z2={fromASN:r=>r.toDate(),toASN:r=>new ui({valueDate:r})},X2={fromASN:()=>null,toASN:()=>new Pr};function Cs(r){switch(r){case h.Any:return B2;case h.BitString:return N2;case h.BmpString:return D2;case h.Boolean:return R2;case h.CharacterString:return q2;case h.Enumerated:return k2;case h.GeneralString:return W2;case h.GeneralizedTime:return z2;case h.GraphicString:return $2;case h.IA5String:return V2;case h.Integer:return P2;case h.Null:return X2;case h.NumericString:return U2;case h.ObjectIdentifier:return j2;case h.OctetString:return Ts;case h.PrintableString:return M2;case h.TeletexString:return K2;case h.UTCTime:return G2;case h.UniversalString:return L2;case h.Utf8String:return Vd;case h.VideotexString:return H2;case h.VisibleString:return F2;default:return null}}function lr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:lr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Fd(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Fd(t)}return!1}function Jb(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 df=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:_.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let p=h[s.type],f=Qr[p];if(!f)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new f({name:a})}else lr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===_.Choice?c=new Yr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Yr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Ht:Kt;c=new p({name:"",value:[new li({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||lr(s.type)){let p=s.repeated?at:An;o.push(new p({name:a,optional:l,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,f=p?c:this.get(s.type,!0).schema;f="valueBlock"in f?f.valueBlock.value:f.value,o.push(new at({name:p?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:f}))}else o.push(new at({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case _.Sequence:return new Kt({value:o,name:""});case _.Set:return new Ht({value:o,name:""});case _.Choice:return new Ss({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var jt=new df;var S=r=>e=>{let t;jt.has(e)?t=jt.get(e):(t=jt.createDefault(e),jt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;jt.has(e.constructor)?n=jt.get(e.constructor):(n=jt.createDefault(e.constructor),jt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Cs(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 bc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var xc=class{static parse(e,t){let n=Tn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(lr(t))return new t().fromASN(e);let o=jt.get(t);jt.cache(t);let i=o.schema;if(e.constructor===at&&o.type!==_.Choice){i=new at({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=no({},e,i);if(!s.verified)throw new bc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(Fd(t)){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=o.itemType;if(typeof c=="number"){let l=Cs(c);if(!l)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,p=>l.fromASN(p))}else return t.from(e.valueBlock.value,l=>this.fromASN(l,c))}for(let c in o.items){let l=s.result[c];if(!l)continue;let p=o.items[c],f=p.type;if(typeof f=="number"||lr(f)){let m=(n=p.converter)!==null&&n!==void 0?n:lr(f)?new f:null;if(!m)throw new Error("Converter is empty");if(p.repeated)if(p.implicit){let y=p.repeated==="sequence"?Kt:Ht,b=new y;b.valueBlock=l.valueBlock;let v=Tn(b.toBER(!1));if(v.offset===-1)throw new Error(`Cannot parse the child item. ${v.result.error}`);if(!("value"in v.result.valueBlock&&Array.isArray(v.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let d=v.result.valueBlock.value;a[c]=Array.from(d,T=>m.fromASN(T))}else a[c]=Array.from(l,y=>m.fromASN(y));else{let y=l;if(p.implicit){let b;if(lr(f))b=new f().toSchema("");else{let v=h[f],d=Qr[v];if(!d)throw new Error(`Cannot get '${v}' class from asn1js module`);b=new d}b.valueBlock=y.valueBlock,y=Tn(b.toBER(!1)).result}a[c]=m.fromASN(y)}}else if(p.repeated){if(!Array.isArray(l))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");a[c]=Array.from(l,m=>this.fromASN(m,f))}else a[c]=this.fromASN(l,f)}return a}catch(o){throw o instanceof bc&&o.schemas.push(t.name),o}}};var vc=class r{static serialize(e){return e instanceof Qe?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&lr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=jt.get(t);jt.cache(t);let o=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let s=Cs(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"&&Jb(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"||lr(a.type))){let p={};p.valueHex=l instanceof Pr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new An({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new at({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new at({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[l]}));else a.repeated?o=o.concat(l):o.push(l)}let i;switch(n.type){case _.Sequence:i=new Kt({value:o});break;case _.Set:i=new Ht({value:o});break;case _.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${h[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,l=>s.toASN(l)),c=e.repeated==="sequence"?Kt:Ht;i=new c({value:a})}else i=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let s=Array.from(o,c=>this.toASN(c)),a=e.repeated==="sequence"?Kt:Ht;i=new a({value:s})}else i=this.toASN(o);return i}};var oe=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var Wd=Hr(vn());var q=class r{static serialize(e){return vc.serialize(e)}static parse(e,t){return xc.parse(e,t)}static toString(e){let t=Wd.BufferSourceConverter.isBufferSource(e)?Wd.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Tn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function w(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Qb=Hr(vn()),_c=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(Qb.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 ex=Hr(vn()),qd,Gd,zd,et=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};w([u({type:h.TeletexString})],et.prototype,"teletexString",void 0);w([u({type:h.PrintableString})],et.prototype,"printableString",void 0);w([u({type:h.UniversalString})],et.prototype,"universalString",void 0);w([u({type:h.Utf8String})],et.prototype,"utf8String",void 0);w([u({type:h.BmpString})],et.prototype,"bmpString",void 0);et=w([S({type:_.Choice})],et);var Is=class extends et{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?ex.Convert.ToHex(this.anyValue):super.toString())}};w([u({type:h.IA5String})],Is.prototype,"ia5String",void 0);w([u({type:h.Any})],Is.prototype,"anyValue",void 0);Is=w([S({type:_.Choice})],Is);var fi=class{constructor(e={}){this.type="",this.value=new Is,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],fi.prototype,"type",void 0);w([u({type:Is})],fi.prototype,"value",void 0);var so=qd=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,qd.prototype)}};so=qd=w([S({type:_.Set,itemType:fi})],so);var Xd=Gd=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gd.prototype)}};Xd=Gd=w([S({type:_.Sequence,itemType:so})],Xd);var Pe=zd=class extends Xd{constructor(e){super(e),Object.setPrototypeOf(this,zd.prototype)}};Pe=zd=w([S({type:_.Sequence})],Pe);var Z2={fromASN:r=>_c.toString(Ts.fromASN(r)),toASN:r=>Ts.toASN(_c.fromString(r))},ao=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],ao.prototype,"typeId",void 0);w([u({type:h.Any,context:0})],ao.prototype,"value",void 0);var Ac=class{constructor(e={}){this.partyName=new et,Object.assign(this,e)}};w([u({type:et,optional:!0,context:0,implicit:!0})],Ac.prototype,"nameAssigner",void 0);w([u({type:et,context:1,implicit:!0})],Ac.prototype,"partyName",void 0);var le=class{constructor(e={}){Object.assign(this,e)}};w([u({type:ao,context:0,implicit:!0})],le.prototype,"otherName",void 0);w([u({type:h.IA5String,context:1,implicit:!0})],le.prototype,"rfc822Name",void 0);w([u({type:h.IA5String,context:2,implicit:!0})],le.prototype,"dNSName",void 0);w([u({type:h.Any,context:3,implicit:!0})],le.prototype,"x400Address",void 0);w([u({type:Pe,context:4,implicit:!1})],le.prototype,"directoryName",void 0);w([u({type:Ac,context:5})],le.prototype,"ediPartyName",void 0);w([u({type:h.IA5String,context:6,implicit:!0})],le.prototype,"uniformResourceIdentifier",void 0);w([u({type:h.OctetString,context:7,implicit:!0,converter:Z2})],le.prototype,"iPAddress",void 0);w([u({type:h.ObjectIdentifier,context:8,implicit:!0})],le.prototype,"registeredID",void 0);le=w([S({type:_.Choice})],le);var co="1.3.6.1.5.5.7",uo=`${co}.1`,tx=`${co}.2`,pi=`${co}.3`,yf=`${co}.48`,Z3=`${tx}.1`,Y3=`${tx}.2`,Zd=`${yf}.1`,Yd=`${yf}.2`,Jd=`${yf}.3`,Qd=`${yf}.5`,fe="2.5.29";var ey,mf=`${uo}.1`,Cn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new le,Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Cn.prototype,"accessMethod",void 0);w([u({type:le})],Cn.prototype,"accessLocation",void 0);var hi=ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ey.prototype)}};hi=ey=w([S({type:_.Sequence,itemType:Cn})],hi);var gf=`${fe}.35`,di=class extends ae{},tn=class{constructor(e={}){e&&Object.assign(this,e)}};w([u({type:di,context:0,optional:!0,implicit:!0})],tn.prototype,"keyIdentifier",void 0);w([u({type:le,context:1,optional:!0,implicit:!0,repeated:"sequence"})],tn.prototype,"authorityCertIssuer",void 0);w([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:me})],tn.prototype,"authorityCertSerialNumber",void 0);var wf=`${fe}.19`,yi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};w([u({type:h.Boolean,defaultValue:!1})],yi.prototype,"cA",void 0);w([u({type:h.Integer,optional:!0})],yi.prototype,"pathLenConstraint",void 0);var ty,Ve=ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};Ve=ty=w([S({type:_.Sequence,itemType:le})],Ve);var ry,Y2=`${fe}.29`,rx=ry=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};rx=ry=w([S({type:_.Sequence})],rx);var ny,xf=`${fe}.32`,ON=`${xf}.0`,In=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};w([u({type:h.IA5String})],In.prototype,"ia5String",void 0);w([u({type:h.VisibleString})],In.prototype,"visibleString",void 0);w([u({type:h.BmpString})],In.prototype,"bmpString",void 0);w([u({type:h.Utf8String})],In.prototype,"utf8String",void 0);In=w([S({type:_.Choice})],In);var Sc=class{constructor(e={}){this.organization=new In,this.noticeNumbers=[],Object.assign(this,e)}};w([u({type:In})],Sc.prototype,"organization",void 0);w([u({type:h.Integer,repeated:"sequence"})],Sc.prototype,"noticeNumbers",void 0);var Ec=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Sc,optional:!0})],Ec.prototype,"noticeRef",void 0);w([u({type:In,optional:!0})],Ec.prototype,"explicitText",void 0);var bf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.IA5String})],bf.prototype,"cPSuri",void 0);w([u({type:Ec})],bf.prototype,"userNotice",void 0);bf=w([S({type:_.Choice})],bf);var Tc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],Tc.prototype,"policyQualifierId",void 0);w([u({type:h.Any})],Tc.prototype,"qualifier",void 0);var mi=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],mi.prototype,"policyIdentifier",void 0);w([u({type:Tc,repeated:"sequence",optional:!0})],mi.prototype,"policyQualifiers",void 0);var Cc=ny=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};Cc=ny=w([S({type:_.Sequence,itemType:mi})],Cc);var LN=`${fe}.20`,Ic=class{constructor(e=0){this.value=e}};w([u({type:h.Integer})],Ic.prototype,"value",void 0);Ic=w([S({type:_.Choice})],Ic);var FN=`${fe}.27`,nx=class extends Ic{};nx=w([S({type:_.Choice})],nx);var oy,vf=`${fe}.31`,Rr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Rr||(Rr={}));var Oc=class extends en{toJSON(){let e=[],t=this.toNumber();return t&Rr.aACompromise&&e.push("aACompromise"),t&Rr.affiliationChanged&&e.push("affiliationChanged"),t&Rr.cACompromise&&e.push("cACompromise"),t&Rr.certificateHold&&e.push("certificateHold"),t&Rr.cessationOfOperation&&e.push("cessationOfOperation"),t&Rr.keyCompromise&&e.push("keyCompromise"),t&Rr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Rr.superseded&&e.push("superseded"),t&Rr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},On=class{constructor(e={}){Object.assign(this,e)}};w([u({type:le,context:0,repeated:"sequence",implicit:!0})],On.prototype,"fullName",void 0);w([u({type:so,context:1,implicit:!0})],On.prototype,"nameRelativeToCRLIssuer",void 0);On=w([S({type:_.Choice})],On);var rn=class{constructor(e={}){Object.assign(this,e)}};w([u({type:On,context:0,optional:!0})],rn.prototype,"distributionPoint",void 0);w([u({type:Oc,context:1,optional:!0,implicit:!0})],rn.prototype,"reasons",void 0);w([u({type:le,context:2,optional:!0,repeated:"sequence",implicit:!0})],rn.prototype,"cRLIssuer",void 0);var lo=oy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,oy.prototype)}};lo=oy=w([S({type:_.Sequence,itemType:rn})],lo);var iy,ij=`${fe}.46`,ox=iy=class extends lo{constructor(e){super(e),Object.setPrototypeOf(this,iy.prototype)}};ox=iy=w([S({type:_.Sequence,itemType:rn})],ox);var hj=`${fe}.28`,Qt=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};Qt.ONLY=!1;w([u({type:On,context:0,optional:!0})],Qt.prototype,"distributionPoint",void 0);w([u({type:h.Boolean,context:1,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsUserCerts",void 0);w([u({type:h.Boolean,context:2,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsCACerts",void 0);w([u({type:Oc,context:3,optional:!0,implicit:!0})],Qt.prototype,"onlySomeReasons",void 0);w([u({type:h.Boolean,context:4,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"indirectCRL",void 0);w([u({type:h.Boolean,context:5,defaultValue:Qt.ONLY,implicit:!0})],Qt.prototype,"onlyContainsAttributeCerts",void 0);var ix=`${fe}.21`,Bc;(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"})(Bc||(Bc={}));var Pc=class{constructor(e=Bc.unspecified){this.reason=Bc.unspecified,this.reason=e}toJSON(){return Bc[this.reason]}toString(){return this.toJSON()}};w([u({type:h.Enumerated})],Pc.prototype,"reason",void 0);Pc=w([S({type:_.Choice})],Pc);var sy,_f=`${fe}.37`,kc=sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,sy.prototype)}};kc=sy=w([S({type:_.Sequence,itemType:h.ObjectIdentifier})],kc);var Sj=`${_f}.0`,sx=`${pi}.1`,ax=`${pi}.2`,cx=`${pi}.3`,ux=`${pi}.4`,lx=`${pi}.8`,fx=`${pi}.9`;var Oj=`${fe}.54`,ay=class{constructor(e=new ArrayBuffer(0)){this.value=e}};w([u({type:h.Integer,converter:me})],ay.prototype,"value",void 0);ay=w([S({type:_.Choice})],ay);var px=`${fe}.24`,Nc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};w([u({type:h.GeneralizedTime})],Nc.prototype,"value",void 0);Nc=w([S({type:_.Choice})],Nc);var cy,Hj=`${fe}.18`,hx=cy=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,cy.prototype)}};hx=cy=w([S({type:_.Sequence})],hx);var Af=`${fe}.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 Os=class extends en{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 uy,Yj=`${fe}.30`,Bs=class{constructor(e={}){this.base=new le,this.minimum=0,Object.assign(this,e)}};w([u({type:le})],Bs.prototype,"base",void 0);w([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Bs.prototype,"minimum",void 0);w([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Bs.prototype,"maximum",void 0);var Sf=uy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};Sf=uy=w([S({type:_.Sequence,itemType:Bs})],Sf);var Ef=class{constructor(e={}){Object.assign(this,e)}};w([u({type:Sf,context:0,optional:!0,implicit:!0})],Ef.prototype,"permittedSubtrees",void 0);w([u({type:Sf,context:1,optional:!0,implicit:!0})],Ef.prototype,"excludedSubtrees",void 0);var nR=`${fe}.36`,Tf=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:me})],Tf.prototype,"requireExplicitPolicy",void 0);w([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:me})],Tf.prototype,"inhibitPolicyMapping",void 0);var ly,cR=`${fe}.33`,jc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],jc.prototype,"issuerDomainPolicy",void 0);w([u({type:h.ObjectIdentifier})],jc.prototype,"subjectDomainPolicy",void 0);var dx=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};dx=ly=w([S({type:_.Sequence,itemType:jc})],dx);var fy,py=`${fe}.17`,Cf=fy=class extends Ve{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};Cf=fy=w([S({type:_.Sequence})],Cf);var ht=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};w([u({type:h.ObjectIdentifier})],ht.prototype,"type",void 0);w([u({type:h.Any,repeated:"set"})],ht.prototype,"values",void 0);var hy,SR=`${fe}.9`,yx=hy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};yx=hy=w([S({type:_.Sequence,itemType:ht})],yx);var dy=`${fe}.14`,Vt=class extends di{};var NR=`${fe}.16`,If=class{constructor(e={}){Object.assign(this,e)}};w([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],If.prototype,"notBefore",void 0);w([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],If.prototype,"notAfter",void 0);var Rc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Rc||(Rc={}));var Of=class extends en{toJSON(){let e=[],t=this.toNumber();return t&Rc.pKIXCertificate&&e.push("pKIXCertificate"),t&Rc.newExtensions&&e.push("newExtensions"),t&Rc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Bf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Of,Object.assign(this,e)}};w([u({type:h.GeneralString})],Bf.prototype,"entrustVers",void 0);w([u({type:Of})],Bf.prototype,"entrustInfoFlags",void 0);var yy,VR=`${uo}.11`,mx=yy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};mx=yy=w([S({type:_.Sequence,itemType:Cn})],mx);var gx=Hr(vn()),H=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&gx.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};w([u({type:h.ObjectIdentifier})],H.prototype,"algorithm",void 0);w([u({type:h.Any,optional:!0})],H.prototype,"parameters",void 0);var dt=class{constructor(e={}){this.algorithm=new H,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:H})],dt.prototype,"algorithm",void 0);w([u({type:h.BitString})],dt.prototype,"subjectPublicKey",void 0);var qe=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};w([u({type:h.UTCTime})],qe.prototype,"utcTime",void 0);w([u({type:h.GeneralizedTime})],qe.prototype,"generalTime",void 0);qe=w([S({type:_.Choice})],qe);var Bn=class{constructor(e){this.notBefore=new qe(new Date),this.notAfter=new qe(new Date),e&&(this.notBefore=new qe(e.notBefore),this.notAfter=new qe(e.notAfter))}};w([u({type:qe})],Bn.prototype,"notBefore",void 0);w([u({type:qe})],Bn.prototype,"notAfter",void 0);var my,yt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};yt.CRITICAL=!1;w([u({type:h.ObjectIdentifier})],yt.prototype,"extnID",void 0);w([u({type:h.Boolean,defaultValue:yt.CRITICAL})],yt.prototype,"critical",void 0);w([u({type:ae})],yt.prototype,"extnValue",void 0);var er=my=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};er=my=w([S({type:_.Sequence,itemType:yt})],er);var nn;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(nn||(nn={}));var mt=class{constructor(e={}){this.version=nn.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new H,this.issuer=new Pe,this.validity=new Bn,this.subject=new Pe,this.subjectPublicKeyInfo=new dt,Object.assign(this,e)}};w([u({type:h.Integer,context:0,defaultValue:nn.v1})],mt.prototype,"version",void 0);w([u({type:h.Integer,converter:me})],mt.prototype,"serialNumber",void 0);w([u({type:H})],mt.prototype,"signature",void 0);w([u({type:Pe})],mt.prototype,"issuer",void 0);w([u({type:Bn})],mt.prototype,"validity",void 0);w([u({type:Pe})],mt.prototype,"subject",void 0);w([u({type:dt})],mt.prototype,"subjectPublicKeyInfo",void 0);w([u({type:h.BitString,context:1,implicit:!0,optional:!0})],mt.prototype,"issuerUniqueID",void 0);w([u({type:h.BitString,context:2,implicit:!0,optional:!0})],mt.prototype,"subjectUniqueID",void 0);w([u({type:er,context:3,optional:!0})],mt.prototype,"extensions",void 0);var fr=class{constructor(e={}){this.tbsCertificate=new mt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:mt})],fr.prototype,"tbsCertificate",void 0);w([u({type:H})],fr.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],fr.prototype,"signatureValue",void 0);var gi=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new qe,Object.assign(this,e)}};w([u({type:h.Integer,converter:me})],gi.prototype,"userCertificate",void 0);w([u({type:qe})],gi.prototype,"revocationDate",void 0);w([u({type:yt,optional:!0,repeated:"sequence"})],gi.prototype,"crlEntryExtensions",void 0);var tr=class{constructor(e={}){this.signature=new H,this.issuer=new Pe,this.thisUpdate=new qe,Object.assign(this,e)}};w([u({type:h.Integer,optional:!0})],tr.prototype,"version",void 0);w([u({type:H})],tr.prototype,"signature",void 0);w([u({type:Pe})],tr.prototype,"issuer",void 0);w([u({type:qe})],tr.prototype,"thisUpdate",void 0);w([u({type:qe,optional:!0})],tr.prototype,"nextUpdate",void 0);w([u({type:gi,repeated:"sequence",optional:!0})],tr.prototype,"revokedCertificates",void 0);w([u({type:yt,optional:!0,context:0,repeated:"sequence"})],tr.prototype,"crlExtensions",void 0);var wi=class{constructor(e={}){this.tbsCertList=new tr,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};w([u({type:tr})],wi.prototype,"tbsCertList",void 0);w([u({type:H})],wi.prototype,"signatureAlgorithm",void 0);w([u({type:h.BitString})],wi.prototype,"signature",void 0);var V=Hr(vn());function C(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Lr=class{constructor(e={}){this.issuer=new Pe,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:Pe})],Lr.prototype,"issuer",void 0);C([u({type:h.Integer,converter:me})],Lr.prototype,"serialNumber",void 0);var bi=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Vt,context:0,implicit:!0})],bi.prototype,"subjectKeyIdentifier",void 0);C([u({type:Lr})],bi.prototype,"issuerAndSerialNumber",void 0);bi=C([S({type:_.Choice})],bi);var gt;(function(r){r[r.v0=0]="v0",r[r.v1=1]="v1",r[r.v2=2]="v2",r[r.v3=3]="v3",r[r.v4=4]="v4",r[r.v5=5]="v5"})(gt||(gt={}));var xi=class extends H{};xi=C([S({type:_.Sequence})],xi);var Dc=class extends H{};Dc=C([S({type:_.Sequence})],Dc);var $t=class extends H{};$t=C([S({type:_.Sequence})],$t);var Lc=class extends H{};Lc=C([S({type:_.Sequence})],Lc);var bx=class extends H{};bx=C([S({type:_.Sequence})],bx);var Pf=class extends H{};Pf=C([S({type:_.Sequence})],Pf);var Ur=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Ur.prototype,"attrType",void 0);C([u({type:h.Any,repeated:"set"})],Ur.prototype,"attrValues",void 0);var gy,Ft=class{constructor(e={}){this.version=gt.v0,this.sid=new bi,this.digestAlgorithm=new xi,this.signatureAlgorithm=new Dc,this.signature=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],Ft.prototype,"version",void 0);C([u({type:bi})],Ft.prototype,"sid",void 0);C([u({type:xi})],Ft.prototype,"digestAlgorithm",void 0);C([u({type:Ur,repeated:"set",context:0,implicit:!0,optional:!0})],Ft.prototype,"signedAttrs",void 0);C([u({type:Dc})],Ft.prototype,"signatureAlgorithm",void 0);C([u({type:ae})],Ft.prototype,"signature",void 0);C([u({type:Ur,repeated:"set",context:1,implicit:!0,optional:!0})],Ft.prototype,"unsignedAttrs",void 0);var Uc=gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,gy.prototype)}};Uc=gy=C([S({type:_.Set,itemType:Ft})],Uc);var xx=class extends qe{};xx=C([S({type:_.Choice})],xx);var vx=class extends Ft{};vx=C([S({type:_.Sequence})],vx);function z(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Mc=class{constructor(e={}){this.acIssuer=new le,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:le})],Mc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Mc.prototype,"acSerial",void 0);z([u({type:ht,repeated:"sequence"})],Mc.prototype,"attrs",void 0);var wy,Kc=wy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Kc=wy=z([S({type:_.Sequence,itemType:h.ObjectIdentifier})],Kc);var Ps=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],Ps.prototype,"pathLenConstraint",void 0);z([u({type:Kc,implicit:!0,context:0,optional:!0})],Ps.prototype,"permittedAttrs",void 0);z([u({type:Kc,implicit:!0,context:1,optional:!0})],Ps.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],Ps.prototype,"permitUnSpecified",void 0);var pr=class{constructor(e={}){this.issuer=new Ve,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Ve})],pr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:me})],pr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],pr.prototype,"issuerUID",void 0);var by;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(by||(by={}));var hr=class{constructor(e={}){this.digestedObjectType=by.publicKey,this.digestAlgorithm=new H,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],hr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],hr.prototype,"otherObjectTypeID",void 0);z([u({type:H})],hr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],hr.prototype,"objectDigest",void 0);var vi=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ve,optional:!0})],vi.prototype,"issuerName",void 0);z([u({type:pr,context:0,implicit:!0,optional:!0})],vi.prototype,"baseCertificateID",void 0);z([u({type:hr,context:1,implicit:!0,optional:!0})],vi.prototype,"objectDigestInfo",void 0);var _i=class{constructor(e={}){Object.assign(this,e)}};z([u({type:le,repeated:"sequence"})],_i.prototype,"v1Form",void 0);z([u({type:vi,context:0,implicit:!0})],_i.prototype,"v2Form",void 0);_i=z([S({type:_.Choice})],_i);var Ai=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Ai.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Ai.prototype,"notAfterTime",void 0);var fo=class{constructor(e={}){Object.assign(this,e)}};z([u({type:pr,implicit:!0,context:0,optional:!0})],fo.prototype,"baseCertificateID",void 0);z([u({type:Ve,implicit:!0,context:1,optional:!0})],fo.prototype,"entityName",void 0);z([u({type:hr,implicit:!0,context:2,optional:!0})],fo.prototype,"objectDigestInfo",void 0);var xy;(function(r){r[r.v2=1]="v2"})(xy||(xy={}));var Wt=class{constructor(e={}){this.version=xy.v2,this.holder=new fo,this.issuer=new _i,this.signature=new H,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Ai,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],Wt.prototype,"version",void 0);z([u({type:fo})],Wt.prototype,"holder",void 0);z([u({type:_i})],Wt.prototype,"issuer",void 0);z([u({type:H})],Wt.prototype,"signature",void 0);z([u({type:h.Integer,converter:me})],Wt.prototype,"serialNumber",void 0);z([u({type:Ai})],Wt.prototype,"attrCertValidityPeriod",void 0);z([u({type:ht,repeated:"sequence"})],Wt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],Wt.prototype,"issuerUniqueID",void 0);z([u({type:er,optional:!0})],Wt.prototype,"extensions",void 0);var Si=class{constructor(e={}){this.acinfo=new Wt,this.signatureAlgorithm=new H,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Wt})],Si.prototype,"acinfo",void 0);z([u({type:H})],Si.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Si.prototype,"signatureValue",void 0);var Hc;(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"})(Hc||(Hc={}));var ks=class extends en{};var Ns=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],Ns.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],Ns.prototype,"value",void 0);var Vc=class{constructor(e={}){this.policyId="",this.classList=new ks(Hc.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],Vc.prototype,"policyId",void 0);z([u({type:ks,defaultValue:new ks(Hc.unclassified)})],Vc.prototype,"classList",void 0);z([u({type:Ns,repeated:"set"})],Vc.prototype,"securityCategories",void 0);var js=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ae})],js.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],js.prototype,"oid",void 0);z([u({type:h.Utf8String})],js.prototype,"string",void 0);var kf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ve,implicit:!0,context:0,optional:!0})],kf.prototype,"policyAuthority",void 0);z([u({type:js,repeated:"sequence"})],kf.prototype,"values",void 0);var SM=`${uo}.4`,EM=`${uo}.6`,TM=`${uo}.10`,CM=`${fe}.55`,$c=`${co}.10`,IM=`${$c}.1`,OM=`${$c}.2`,BM=`${$c}.3`,PM=`${$c}.4`,kM=`${$c}.6`,vy="2.5.4",NM=`${vy}.72`;var _y,Rs=class{constructor(e={}){this.targetCertificate=new pr,Object.assign(this,e)}};z([u({type:pr})],Rs.prototype,"targetCertificate",void 0);z([u({type:le,optional:!0})],Rs.prototype,"targetName",void 0);z([u({type:hr,optional:!0})],Rs.prototype,"certDigestInfo",void 0);var Ds=class{constructor(e={}){Object.assign(this,e)}};z([u({type:le,context:0,implicit:!0})],Ds.prototype,"targetName",void 0);z([u({type:le,context:1,implicit:!0})],Ds.prototype,"targetGroup",void 0);z([u({type:Rs,context:2,implicit:!0})],Ds.prototype,"targetCert",void 0);Ds=z([S({type:_.Choice})],Ds);var Nf=_y=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,_y.prototype)}};Nf=_y=z([S({type:_.Sequence,itemType:Ds})],Nf);var Ay,_x=Ay=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};_x=Ay=z([S({type:_.Sequence,itemType:Nf})],_x);var jf=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ve,implicit:!0,context:0,optional:!0})],jf.prototype,"roleAuthority",void 0);z([u({type:le,implicit:!0,context:1})],jf.prototype,"roleName",void 0);var Fc=class{constructor(e={}){this.service=new le,this.ident=new le,Object.assign(this,e)}};z([u({type:le})],Fc.prototype,"service",void 0);z([u({type:le})],Fc.prototype,"ident",void 0);z([u({type:ae,optional:!0})],Fc.prototype,"authInfo",void 0);var Sy,Wc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Wc.prototype,"otherCertFormat",void 0);C([u({type:h.Any})],Wc.prototype,"otherCert",void 0);var Ei=class{constructor(e={}){Object.assign(this,e)}};C([u({type:fr})],Ei.prototype,"certificate",void 0);C([u({type:Si,context:2,implicit:!0})],Ei.prototype,"v2AttrCert",void 0);C([u({type:Wc,context:3,implicit:!0})],Ei.prototype,"other",void 0);Ei=C([S({type:_.Choice})],Ei);var Ti=Sy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};Ti=Sy=C([S({type:_.Set,itemType:Ei})],Ti);var dr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],dr.prototype,"contentType",void 0);C([u({type:h.Any,context:0})],dr.prototype,"content",void 0);var Ls=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae})],Ls.prototype,"single",void 0);C([u({type:h.Any})],Ls.prototype,"any",void 0);Ls=C([S({type:_.Choice})],Ls);var Ci=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Ci.prototype,"eContentType",void 0);C([u({type:Ls,context:0,optional:!0})],Ci.prototype,"eContent",void 0);var qc=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ae,context:0,implicit:!0,optional:!0})],qc.prototype,"value",void 0);C([u({type:ae,converter:Yb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],qc.prototype,"constructedValue",void 0);qc=C([S({type:_.Choice})],qc);var po=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Lc,Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],po.prototype,"contentType",void 0);C([u({type:Lc})],po.prototype,"contentEncryptionAlgorithm",void 0);C([u({type:qc,optional:!0})],po.prototype,"encryptedContent",void 0);var ho=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],ho.prototype,"keyAttrId",void 0);C([u({type:h.Any,optional:!0})],ho.prototype,"keyAttr",void 0);var Ey,Us=class{constructor(e={}){this.subjectKeyIdentifier=new Vt,Object.assign(this,e)}};C([u({type:Vt})],Us.prototype,"subjectKeyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Us.prototype,"date",void 0);C([u({type:ho,optional:!0})],Us.prototype,"other",void 0);var Ms=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Us,context:0,implicit:!0,optional:!0})],Ms.prototype,"rKeyId",void 0);C([u({type:Lr,optional:!0})],Ms.prototype,"issuerAndSerialNumber",void 0);Ms=C([S({type:_.Choice})],Ms);var Gc=class{constructor(e={}){this.rid=new Ms,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:Ms})],Gc.prototype,"rid",void 0);C([u({type:ae})],Gc.prototype,"encryptedKey",void 0);var Rf=Ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};Rf=Ey=C([S({type:_.Sequence,itemType:Gc})],Rf);var zc=class{constructor(e={}){this.algorithm=new H,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:H})],zc.prototype,"algorithm",void 0);C([u({type:h.BitString})],zc.prototype,"publicKey",void 0);var Ii=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Vt,context:0,implicit:!0,optional:!0})],Ii.prototype,"subjectKeyIdentifier",void 0);C([u({type:zc,context:1,implicit:!0,optional:!0})],Ii.prototype,"originatorKey",void 0);C([u({type:Lr,optional:!0})],Ii.prototype,"issuerAndSerialNumber",void 0);Ii=C([S({type:_.Choice})],Ii);var Pn=class{constructor(e={}){this.version=gt.v3,this.originator=new Ii,this.keyEncryptionAlgorithm=new $t,this.recipientEncryptedKeys=new Rf,Object.assign(this,e)}};C([u({type:h.Integer})],Pn.prototype,"version",void 0);C([u({type:Ii,context:0})],Pn.prototype,"originator",void 0);C([u({type:ae,context:1,optional:!0})],Pn.prototype,"ukm",void 0);C([u({type:$t})],Pn.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:Rf})],Pn.prototype,"recipientEncryptedKeys",void 0);var Ks=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Vt,context:0,implicit:!0})],Ks.prototype,"subjectKeyIdentifier",void 0);C([u({type:Lr})],Ks.prototype,"issuerAndSerialNumber",void 0);Ks=C([S({type:_.Choice})],Ks);var yo=class{constructor(e={}){this.version=gt.v0,this.rid=new Ks,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],yo.prototype,"version",void 0);C([u({type:Ks})],yo.prototype,"rid",void 0);C([u({type:$t})],yo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],yo.prototype,"encryptedKey",void 0);var Oi=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};C([u({type:ae})],Oi.prototype,"keyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Oi.prototype,"date",void 0);C([u({type:ho,optional:!0})],Oi.prototype,"other",void 0);var mo=class{constructor(e={}){this.version=gt.v4,this.kekid=new Oi,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],mo.prototype,"version",void 0);C([u({type:Oi})],mo.prototype,"kekid",void 0);C([u({type:$t})],mo.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],mo.prototype,"encryptedKey",void 0);var go=class{constructor(e={}){this.version=gt.v0,this.keyEncryptionAlgorithm=new $t,this.encryptedKey=new ae,Object.assign(this,e)}};C([u({type:h.Integer})],go.prototype,"version",void 0);C([u({type:Pf,context:0,optional:!0})],go.prototype,"keyDerivationAlgorithm",void 0);C([u({type:$t})],go.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ae})],go.prototype,"encryptedKey",void 0);var Xc=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Xc.prototype,"oriType",void 0);C([u({type:h.Any})],Xc.prototype,"oriValue",void 0);var kn=class{constructor(e={}){Object.assign(this,e)}};C([u({type:yo,optional:!0})],kn.prototype,"ktri",void 0);C([u({type:Pn,context:1,implicit:!0,optional:!0})],kn.prototype,"kari",void 0);C([u({type:mo,context:2,implicit:!0,optional:!0})],kn.prototype,"kekri",void 0);C([u({type:go,context:3,implicit:!0,optional:!0})],kn.prototype,"pwri",void 0);C([u({type:Xc,context:4,implicit:!0,optional:!0})],kn.prototype,"ori",void 0);kn=C([S({type:_.Choice})],kn);var Ty,Zc=Ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};Zc=Ty=C([S({type:_.Set,itemType:kn})],Zc);var Cy,Ax=`${co}.16`,kK=`${Ax}.2`,NK=`${Ax}.4`,Hs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Hs.prototype,"otherRevInfoFormat",void 0);C([u({type:h.Any})],Hs.prototype,"otherRevInfo",void 0);var Df=class{constructor(e={}){this.other=new Hs,Object.assign(this,e)}};C([u({type:Hs,context:1,implicit:!0})],Df.prototype,"other",void 0);Df=C([S({type:_.Choice})],Df);var Vs=Cy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};Vs=Cy=C([S({type:_.Set,itemType:Df})],Vs);var $s=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Ti,context:0,implicit:!0,optional:!0})],$s.prototype,"certs",void 0);C([u({type:Vs,context:1,implicit:!0,optional:!0})],$s.prototype,"crls",void 0);var Iy,Oy=Iy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Iy.prototype)}};Oy=Iy=C([S({type:_.Set,itemType:Ur})],Oy);var Bi=class{constructor(e={}){this.version=gt.v0,this.recipientInfos=new Zc,this.encryptedContentInfo=new po,Object.assign(this,e)}};C([u({type:h.Integer})],Bi.prototype,"version",void 0);C([u({type:$s,context:0,implicit:!0,optional:!0})],Bi.prototype,"originatorInfo",void 0);C([u({type:Zc})],Bi.prototype,"recipientInfos",void 0);C([u({type:po})],Bi.prototype,"encryptedContentInfo",void 0);C([u({type:Oy,context:1,implicit:!0,optional:!0})],Bi.prototype,"unprotectedAttrs",void 0);var Sx="1.2.840.113549.1.7.2";var By,Lf=By=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,By.prototype)}};Lf=By=C([S({type:_.Set,itemType:xi})],Lf);var Nn=class{constructor(e={}){this.version=gt.v0,this.digestAlgorithms=new Lf,this.encapContentInfo=new Ci,this.signerInfos=new Uc,Object.assign(this,e)}};C([u({type:h.Integer})],Nn.prototype,"version",void 0);C([u({type:Lf})],Nn.prototype,"digestAlgorithms",void 0);C([u({type:Ci})],Nn.prototype,"encapContentInfo",void 0);C([u({type:Ti,context:0,implicit:!0,optional:!0})],Nn.prototype,"certificates",void 0);C([u({type:Vs,context:1,implicit:!0,optional:!0})],Nn.prototype,"crls",void 0);C([u({type:Uc})],Nn.prototype,"signerInfos",void 0);var Pi="1.2.840.10045.2.1";var Yc="1.2.840.10045.4.1",Uf="1.2.840.10045.4.3.1",Jc="1.2.840.10045.4.3.2",Qc="1.2.840.10045.4.3.3",eu="1.2.840.10045.4.3.4";var Py="1.2.840.10045.3.1.7";var ky="1.3.132.0.34";var Ny="1.3.132.0.35";function tu(r){return new H({algorithm:r})}var Tx=tu(Yc),OH=tu(Uf),Cx=tu(Jc),Ix=tu(Qc),Ox=tu(eu);function ke(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 ru=class{constructor(e={}){Object.assign(this,e)}};ke([u({type:h.ObjectIdentifier})],ru.prototype,"fieldType",void 0);ke([u({type:h.Any})],ru.prototype,"parameters",void 0);ru=ke([S({type:_.Sequence})],ru);var jy=class extends ae{};var Fs=class{constructor(e={}){Object.assign(this,e)}};ke([u({type:h.OctetString})],Fs.prototype,"a",void 0);ke([u({type:h.OctetString})],Fs.prototype,"b",void 0);ke([u({type:h.BitString,optional:!0})],Fs.prototype,"seed",void 0);Fs=ke([S({type:_.Sequence})],Fs);var Ry;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Ry||(Ry={}));var on=class{constructor(e={}){this.version=Ry.ecpVer1,Object.assign(this,e)}};ke([u({type:h.Integer})],on.prototype,"version",void 0);ke([u({type:ru})],on.prototype,"fieldID",void 0);ke([u({type:Fs})],on.prototype,"curve",void 0);ke([u({type:jy})],on.prototype,"base",void 0);ke([u({type:h.Integer,converter:me})],on.prototype,"order",void 0);ke([u({type:h.Integer,optional:!0})],on.prototype,"cofactor",void 0);on=ke([S({type:_.Sequence})],on);var sn=class{constructor(e={}){Object.assign(this,e)}};ke([u({type:h.ObjectIdentifier})],sn.prototype,"namedCurve",void 0);ke([u({type:h.Null})],sn.prototype,"implicitCurve",void 0);ke([u({type:on})],sn.prototype,"specifiedCurve",void 0);sn=ke([S({type:_.Choice})],sn);var Ws=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};ke([u({type:h.Integer})],Ws.prototype,"version",void 0);ke([u({type:ae})],Ws.prototype,"privateKey",void 0);ke([u({type:sn,context:0,optional:!0})],Ws.prototype,"parameters",void 0);ke([u({type:h.BitString,context:1,optional:!0})],Ws.prototype,"publicKey",void 0);var ki=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer,converter:me})],ki.prototype,"r",void 0);ke([u({type:h.Integer,converter:me})],ki.prototype,"s",void 0);function Te(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var qt="1.2.840.113549.1.1",an=`${qt}.1`,Bx=`${qt}.7`,Px=`${qt}.9`,wo=`${qt}.10`,kx=`${qt}.2`,Nx=`${qt}.4`,qs=`${qt}.5`,jx=`${qt}.14`;var Mf=`${qt}.11`,Gs=`${qt}.12`,zs=`${qt}.13`,Dy=`${qt}.15`,Ly=`${qt}.16`,Ni="1.3.14.3.2.26",Kf="2.16.840.1.101.3.4.2.4",ji="2.16.840.1.101.3.4.2.1",Ri="2.16.840.1.101.3.4.2.2",Di="2.16.840.1.101.3.4.2.3",Rx="2.16.840.1.101.3.4.2.5",Dx="2.16.840.1.101.3.4.2.6",Lx="1.2.840.113549.2.2",Ux="1.2.840.113549.2.5",bo=`${qt}.8`;function ct(r){return new H({algorithm:r,parameters:null})}var i7=ct(Lx),s7=ct(Ux),jn=ct(Ni),a7=ct(Kf),c7=ct(ji),u7=ct(Ri),l7=ct(Di),f7=ct(Rx),p7=ct(Dx),Hf=new H({algorithm:bo,parameters:q.serialize(jn)}),Uy=new H({algorithm:Px,parameters:q.serialize(Ts.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),h7=ct(an),d7=ct(kx),y7=ct(Nx),m7=ct(qs),g7=ct(Dy),w7=ct(Ly),b7=ct(Gs),x7=ct(zs),v7=ct(Dy),_7=ct(Ly);var Xs=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:bo,parameters:q.serialize(jn)}),this.pSourceAlgorithm=new H(Uy),Object.assign(this,e)}};Te([u({type:H,context:0,defaultValue:jn})],Xs.prototype,"hashAlgorithm",void 0);Te([u({type:H,context:1,defaultValue:Hf})],Xs.prototype,"maskGenAlgorithm",void 0);Te([u({type:H,context:2,defaultValue:Uy})],Xs.prototype,"pSourceAlgorithm",void 0);var O7=new H({algorithm:Bx,parameters:q.serialize(new Xs)});var cn=class{constructor(e={}){this.hashAlgorithm=new H(jn),this.maskGenAlgorithm=new H({algorithm:bo,parameters:q.serialize(jn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Te([u({type:H,context:0,defaultValue:jn})],cn.prototype,"hashAlgorithm",void 0);Te([u({type:H,context:1,defaultValue:Hf})],cn.prototype,"maskGenAlgorithm",void 0);Te([u({type:h.Integer,context:2,defaultValue:20})],cn.prototype,"saltLength",void 0);Te([u({type:h.Integer,context:3,defaultValue:1})],cn.prototype,"trailerField",void 0);var D7=new H({algorithm:wo,parameters:q.serialize(new cn)});var Li=class{constructor(e={}){this.digestAlgorithm=new H,this.digest=new ae,Object.assign(this,e)}};Te([u({type:H})],Li.prototype,"digestAlgorithm",void 0);Te([u({type:ae})],Li.prototype,"digest",void 0);var My,Zs=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Te([u({type:h.Integer,converter:me})],Zs.prototype,"prime",void 0);Te([u({type:h.Integer,converter:me})],Zs.prototype,"exponent",void 0);Te([u({type:h.Integer,converter:me})],Zs.prototype,"coefficient",void 0);var Vf=My=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,My.prototype)}};Vf=My=Te([S({type:_.Sequence,itemType:Zs})],Vf);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)}};Te([u({type:h.Integer})],yr.prototype,"version",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"modulus",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"publicExponent",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"privateExponent",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"prime1",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"prime2",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"exponent1",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"exponent2",void 0);Te([u({type:h.Integer,converter:me})],yr.prototype,"coefficient",void 0);Te([u({type:Vf,optional:!0})],yr.prototype,"otherPrimeInfos",void 0);var Ys=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Te([u({type:h.Integer,converter:me})],Ys.prototype,"modulus",void 0);Te([u({type:h.Integer,converter:me})],Ys.prototype,"publicExponent",void 0);function nu(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 Ky;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Ky||(Ky={}));var wt=Ky;var sv=Hr(iv(),1),{__extends:Qs,__assign:dV,__rest:nT,__decorate:yV,__param:mV,__metadata:gV,__awaiter:av,__generator:cv,__exportStar:wV,__createBinding:bV,__values:ou,__read:iu,__spread:Mr,__spreadArrays:xV,__await:vV,__asyncGenerator:_V,__asyncDelegator:AV,__asyncValues:SV,__makeTemplateObject:EV,__importStar:TV,__importDefault:CV,__classPrivateFieldGet:IV,__classPrivateFieldSet:OV}=sv.default;var oT="injectionTokens";function Vy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(oT,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function su(r){return!!r.useClass}function ea(r){return!!r.useFactory}var Wf=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,Mr(i))}};return this.reflectMethods.forEach(n),t},r}();function xo(r){return typeof r=="string"||typeof r=="symbol"}function $y(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function qf(r){return typeof r=="object"&&"token"in r&&"transform"in r}function uv(r){return typeof r=="function"||r instanceof Wf}function Ui(r){return!!r.useToken}function Mi(r){return r.useValue!=null}function lv(r){return su(r)||Mi(r)||Ui(r)||ea(r)}var iT=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}(),au=iT;var sT=function(r){Qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(au),fv=sT;var aT=function(){function r(){this.scopedResolutions=new Map}return r}(),cu=aT;function cT(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function uT(r,e,t){return t===void 0&&(t=" "),Mr([r],e.message.split(`
7
7
  `).map(function(n){return t+n})).join(`
8
- `)}function Fm(r,e,t){var n=Jc(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=$_(i,e);return F_("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function nv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var W_=function(r){qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(eu);var q_=function(r){qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(eu);var G_=function(){function r(){this.preResolution=new W_,this.postResolution=new q_}return r}(),ov=G_;var Wm=new Map,z_=function(){function r(e){this.parent=e,this._registry=new rv,this.interceptors=new ov,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:gt.Transient}),this.ensureNotDisposed();var o;if(tv(t)?o=t:o={useClass:t},Li(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Dr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Li(c.provider)?s=c.provider:s=null}if((n.lifecycle===gt.Singleton||n.lifecycle==gt.ContainerScoped||n.lifecycle==gt.ResolutionScoped)&&(Ui(o)||Gs(o)))throw new Error('Cannot use lifecycle "'+gt[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:o,options:n}),this},r.prototype.registerType=function(e,t){return this.ensureNotDisposed(),xo(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(),xo(e)){if(xo(t))return this.register(e,{useToken:t},{lifecycle:gt.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:gt.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!xo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:gt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new tu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&xo(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),o){var i=this.resolveRegistration(o,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(ev(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=Zc(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(f){n={error:f}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Zc(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var f=c.value;f.options.frequency!="Once"&&s.push(f),f.callback(e,t,n)}}catch(h){o={error:h}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===gt.Singleton,o=e.options.lifecycle===gt.ContainerScoped,i=n||o,s;return Ui(e.provider)?s=e.provider.useValue:Li(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):Qc(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Gs(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===gt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new tu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&xo(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=Zc(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Jc(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Ui(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=Zc(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Jc(i.value,2),a=s[0],c=s[1];c.some(function(f){var h=f.options;return h.lifecycle===gt.ContainerScoped})&&n._registry.setAll(a,c.map(function(f){return f.options.lifecycle===gt.ContainerScoped?{provider:f.provider,options:f.options}:f}))}}catch(f){e={error:f}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},r.prototype.beforeResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:n})},r.prototype.afterResolution=function(e,t,n){n===void 0&&(n={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:n})},r.prototype.dispose=function(){return Jb(this,void 0,void 0,function(){var e;return Qb(this,function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var o=n.dispose();o&&e.push(o)}),[4,Promise.all(e)];case 1:return t.sent(),[2]}})})},r.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},r.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},r.prototype.construct=function(e,t){var n=this;if(e instanceof Mf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=Wm.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,Dr([void 0],s)))}();return nv(o)&&this.disposables.add(o),o},r.prototype.resolveParams=function(e,t){var n=this;return function(o,i){var s,a,c;try{return $m(o)?Kf(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Dr([n.resolveAll(o.token,new tu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Dr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new tu,o.isOptional):n.resolve(o.token,e,o.isOptional):Kf(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Dr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(f){throw new Error(Fm(t,i,f))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r}(),Le=new z_;function X_(r){return function(e){Wm.set(e,Vm(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Le.register(t,e)}):Le.register(r.token,e))}}var bo=X_;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 Gm,ji=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};u([l({type:d.ObjectIdentifier})],ji.prototype,"attrId",void 0);u([l({type:d.Any,repeated:"set"})],ji.prototype,"attrValues",void 0);var iv=Gm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};iv=Gm=u([_({type:A.Sequence,itemType:ji})],iv);var zm,sv=zm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,zm.prototype)}};sv=zm=u([_({type:A.Sequence,itemType:fr})],sv);var Y_="1.2.840.113549",Z_=`${Y_}.1`,av=`${Z_}.12`,zs=`${av}.1`,dF=`${zs}.1`,mF=`${zs}.2`,yF=`${zs}.3`,gF=`${zs}.4`,wF=`${zs}.5`,xF=`${zs}.6`,Mi=`${av}.10.1`;var AF=`${Mi}.1`,SF=`${Mi}.2`,EF=`${Mi}.3`,_F=`${Mi}.4`,CF=`${Mi}.5`,IF=`${Mi}.6`,Hf="1.2.840.113549.1.9";var Vf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Vf.prototype,"certId",void 0);u([l({type:d.Any,context:0})],Vf.prototype,"certValue",void 0);var cv=`${Hf}.22`,NF=`${cv}.1`,OF=`${cv}.2`;var $f=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],$f.prototype,"crlId",void 0);u([l({type:d.Any,context:0})],$f.prototype,"crltValue",void 0);var J_=`${Hf}.23`,jF=`${J_}.1`;var Ff=class extends se{},vo=class{constructor(e={}){this.encryptionAlgorithm=new j,this.encryptedData=new Ff,Object.assign(this,e)}};u([l({type:j})],vo.prototype,"encryptionAlgorithm",void 0);u([l({type:Ff})],vo.prototype,"encryptedData",void 0);var Xm,Ym;(function(r){r[r.v1=0]="v1"})(Ym||(Ym={}));var Wf=class extends se{},Zm=Xm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xm.prototype)}};Zm=Xm=u([_({type:A.Sequence,itemType:pt})],Zm);var Ao=class{constructor(e={}){this.version=Ym.v1,this.privateKeyAlgorithm=new j,this.privateKey=new Wf,Object.assign(this,e)}};u([l({type:d.Integer})],Ao.prototype,"version",void 0);u([l({type:j})],Ao.prototype,"privateKeyAlgorithm",void 0);u([l({type:Wf})],Ao.prototype,"privateKey",void 0);u([l({type:Zm,implicit:!0,context:0,optional:!0})],Ao.prototype,"attributes",void 0);var uv=class extends Ao{};uv=u([_({type:A.Sequence})],uv);var lv=class extends vo{};lv=u([_({type:A.Sequence})],lv);var qf=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],qf.prototype,"secretTypeId",void 0);u([l({type:d.Any,context:0})],qf.prototype,"secretValue",void 0);var So=class{constructor(e={}){this.mac=new Di,this.macSalt=new se,this.iterations=1,Object.assign(this,e)}};u([l({type:Di})],So.prototype,"mac",void 0);u([l({type:se})],So.prototype,"macSalt",void 0);u([l({type:d.Integer,defaultValue:1})],So.prototype,"iterations",void 0);var Ki=class{constructor(e={}){this.version=3,this.authSafe=new fr,this.macData=new So,Object.assign(this,e)}};u([l({type:d.Integer})],Ki.prototype,"version",void 0);u([l({type:fr})],Ki.prototype,"authSafe",void 0);u([l({type:So,optional:!0})],Ki.prototype,"macData",void 0);var Jm,Xs=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:d.ObjectIdentifier})],Xs.prototype,"bagId",void 0);u([l({type:d.Any,context:0})],Xs.prototype,"bagValue",void 0);u([l({type:ji,repeated:"set",optional:!0})],Xs.prototype,"bagAttributes",void 0);var fv=Jm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Jm.prototype)}};fv=Jm=u([_({type:A.Sequence,itemType:Xs})],fv);var Qm,ey,ty,qe="1.2.840.113549.1.9",KW=`${qe}.0`,_v=`${qe}.24`,nu=`${qe}.25`,Cv=`${qe}.26`,Iv=`${qe}.27`,HW=`${_v}.1`,VW=`${_v}.2`,$W=`${qe}.1`,FW=`${qe}.2`,WW=`${qe}.3`,qW=`${qe}.4`,GW=`${qe}.5`,zW=`${qe}.6`,uy=`${qe}.7`,XW=`${qe}.8`,YW=`${qe}.9`,ZW=`${qe}.13`,ou=`${qe}.14`,JW=`${qe}.15`,QW=`${qe}.20`,eq=`${qe}.21`;var tq=`${nu}.1`,rq=`${nu}.2`,nq=`${nu}.3`,oq=`${nu}.4`,iq=`${nu}.5`,iu="1.3.6.1.5.5.7.9",sq=`${iu}.1`,aq=`${iu}.2`,cq=`${iu}.3`,uq=`${iu}.4`,lq=`${iu}.5`,fq=`${Cv}.1`,pq=`${Cv}.2`,hq=`${Iv}.1`,dq=`${Iv}.2`,mq=`${qe}.16`,yq=`${qe}.22`,gq=`${qe}.23`,wq=`${vm}.65`,Gf=class extends Qe{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};u([l({type:d.IA5String})],Gf.prototype,"ia5String",void 0);Gf=u([_({type:A.Choice})],Gf);var pv=class extends fr{};pv=u([_({type:A.Sequence})],pv);var hv=class extends Ki{};hv=u([_({type:A.Sequence})],hv);var dv=class extends vo{};dv=u([_({type:A.Sequence})],dv);var ry=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.IA5String})],ry.prototype,"value",void 0);ry=u([_({type:A.Choice})],ry);var mv=class extends Gf{};mv=u([_({type:A.Choice})],mv);var yv=class extends Qe{};yv=u([_({type:A.Choice})],yv);var ny=class{constructor(e=new Date){this.value=e}};u([l({type:d.GeneralizedTime})],ny.prototype,"value",void 0);ny=u([_({type:A.Choice})],ny);var gv=class extends Qe{};gv=u([_({type:A.Choice})],gv);var oy=class{constructor(e="M"){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],oy.prototype,"value",void 0);oy=u([_({type:A.Choice})],oy);var zf=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.PrintableString})],zf.prototype,"value",void 0);zf=u([_({type:A.Choice})],zf);var wv=class extends zf{};wv=u([_({type:A.Choice})],wv);var xv=class extends Qe{};xv=u([_({type:A.Choice})],xv);var iy=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.ObjectIdentifier})],iy.prototype,"value",void 0);iy=u([_({type:A.Choice})],iy);var bv=class extends We{};bv=u([_({type:A.Choice})],bv);var sy=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};u([l({type:d.Integer})],sy.prototype,"value",void 0);sy=u([_({type:A.Choice})],sy);var vv=class extends $t{};vv=u([_({type:A.Sequence})],vv);var ru=class extends Qe{};ru=u([_({type:A.Choice})],ru);var Av=Qm=class extends Jt{constructor(e){super(e),Object.setPrototypeOf(this,Qm.prototype)}};Av=Qm=u([_({type:A.Sequence})],Av);var Sv=ey=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ey.prototype)}};Sv=ey=u([_({type:A.Set,itemType:Rr})],Sv);var ay=class{constructor(e=""){this.value=e}toString(){return this.value}};u([l({type:d.BmpString})],ay.prototype,"value",void 0);ay=u([_({type:A.Choice})],ay);var cy=class extends j{};cy=u([_({type:A.Sequence})],cy);var Ev=ty=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};Ev=ty=u([_({type:A.Sequence,itemType:cy})],Ev);var ly,su=ly=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};su=ly=u([_({type:A.Sequence,itemType:pt})],su);var rn=class{constructor(e={}){this.version=0,this.subject=new Ne,this.subjectPKInfo=new ht,this.attributes=new su,Object.assign(this,e)}};u([l({type:d.Integer})],rn.prototype,"version",void 0);u([l({type:Ne})],rn.prototype,"subject",void 0);u([l({type:ht})],rn.prototype,"subjectPKInfo",void 0);u([l({type:su,implicit:!0,context:0})],rn.prototype,"attributes",void 0);var Eo=class{constructor(e={}){this.certificationRequestInfo=new rn,this.signatureAlgorithm=new j,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};u([l({type:rn})],Eo.prototype,"certificationRequestInfo",void 0);u([l({type:j})],Eo.prototype,"signatureAlgorithm",void 0);u([l({type:d.BitString})],Eo.prototype,"signature",void 0);var pu="crypto.algorithm",by=class{getAlgorithms(){return Le.resolveAll(pu)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new j({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Hi="crypto.algorithmProvider";Le.registerSingleton(Hi,by);var Jf,zt="1.3.36.3.3.2.8.1.1",Tv=`${zt}.1`,Bv=`${zt}.2`,kv=`${zt}.3`,Pv=`${zt}.4`,Nv=`${zt}.5`,Ov=`${zt}.6`,Rv=`${zt}.7`,Dv=`${zt}.8`,Lv=`${zt}.9`,Uv=`${zt}.10`,jv=`${zt}.11`,Mv=`${zt}.12`,Kv=`${zt}.13`,Hv=`${zt}.14`,Vv="brainpoolP160r1",$v="brainpoolP160t1",Fv="brainpoolP192r1",Wv="brainpoolP192t1",qv="brainpoolP224r1",Gv="brainpoolP224t1",zv="brainpoolP256r1",Xv="brainpoolP256t1",Yv="brainpoolP320r1",Zv="brainpoolP320t1",Jv="brainpoolP384r1",Qv="brainpoolP384t1",e1="brainpoolP512r1",t1="brainpoolP512t1",Ve="ECDSA",cu=Jf=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case Ve.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return gb;case"sha-256":return wb;case"sha-384":return xb;case"sha-512":return bb}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Pm;break;case"K-256":t=Jf.SECP256K1;break;case"P-384":t=Nm;break;case"P-521":t=Om;break;case Vv:t=Tv;break;case $v:t=Bv;break;case Fv:t=kv;break;case Wv:t=Pv;break;case qv:t=Nv;break;case Gv:t=Ov;break;case zv:t=Rv;break;case Xv:t=Dv;break;case Yv:t=Lv;break;case Zv:t=Uv;break;case Jv:t=jv;break;case Qv:t=Mv;break;case e1:t=Kv;break;case t1:t=Hv;break}if(t)return new j({algorithm:Bi,parameters:q.serialize(new Qr({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Wc:return{name:Ve,hash:{name:"SHA-1"}};case qc:return{name:Ve,hash:{name:"SHA-256"}};case Gc:return{name:Ve,hash:{name:"SHA-384"}};case zc:return{name:Ve,hash:{name:"SHA-512"}};case Bi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(q.parse(e.parameters,Qr).namedCurve){case Pm:return{name:Ve,namedCurve:"P-256"};case Jf.SECP256K1:return{name:Ve,namedCurve:"K-256"};case Nm:return{name:Ve,namedCurve:"P-384"};case Om:return{name:Ve,namedCurve:"P-521"};case Tv:return{name:Ve,namedCurve:Vv};case Bv:return{name:Ve,namedCurve:$v};case kv:return{name:Ve,namedCurve:Fv};case Pv:return{name:Ve,namedCurve:Wv};case Nv:return{name:Ve,namedCurve:qv};case Ov:return{name:Ve,namedCurve:Gv};case Rv:return{name:Ve,namedCurve:zv};case Dv:return{name:Ve,namedCurve:Xv};case Lv:return{name:Ve,namedCurve:Yv};case Uv:return{name:Ve,namedCurve:Zv};case jv:return{name:Ve,namedCurve:Jv};case Mv:return{name:Ve,namedCurve:Qv};case Kv:return{name:Ve,namedCurve:e1};case Hv:return{name:Ve,namedCurve:t1}}}}return null}};cu.SECP256K1="1.3.132.0.10";cu=Jf=u([bo()],cu);Le.registerSingleton(pu,cu);var p1=Symbol("name"),h1=Symbol("value"),Se=class{constructor(e,t={},n=""){this[p1]=e,this[h1]=n;for(let o in t)this[o]=t[o]}};Se.NAME=p1;Se.VALUE=h1;var vy=class{static toTextObject(e){let t=new Se("Algorithm Identifier",{},on.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Bi:{let n=new cu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},on=class{static toString(e){let t=this.items[e];return t||e}};on.items={[Pi]:"sha1",[Rf]:"sha224",[Ni]:"sha256",[Oi]:"sha384",[Ri]:"sha512",[en]:"rsaEncryption",[Ms]:"sha1WithRSAEncryption",[_b]:"sha224WithRSAEncryption",[Of]:"sha256WithRSAEncryption",[Ks]:"sha384WithRSAEncryption",[Hs]:"sha512WithRSAEncryption",[Bi]:"ecPublicKey",[Wc]:"ecdsaWithSHA1",[Nf]:"ecdsaWithSHA224",[qc]:"ecdsaWithSHA256",[Gc]:"ecdsaWithSHA384",[zc]:"ecdsaWithSHA512",[Zx]:"TLS WWW server authentication",[Jx]:"TLS WWW client authentication",[Qx]:"Code Signing",[eb]:"E-mail Protection",[tb]:"Time Stamping",[rb]:"OCSP Signing",[mb]:"Signed Data"};var Nn=class{static serialize(e){return this.serializeObj(e).join(`
9
- `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Se.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Se.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],f=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${f}${c}`);else if(c instanceof Date)n.push(`${o}${f}${c.toUTCString()}`);else if(Array.isArray(c))for(let h of c)h[Se.NAME]=a,n.push(...this.serializeObj(h,t));else if(c instanceof Se)c[Se.NAME]=a,n.push(...this.serializeObj(c,t));else if(H.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${f}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let h=c.toTextObject();h[Se.NAME]=a,n.push(...this.serializeObj(h,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=H.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let f=o[s++].toString(16).padStart(2,"0");a.push(f)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Nn.oidSerializer=on;Nn.algorithmSerializer=vy;var _o=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=q.serialize(t),this.onInit(t)}else{let t=q.parse(e[0],e[1]);this.rawData=H.BufferSourceConverter.toArrayBuffer(e[0]),this.onInit(t)}}equal(e){return e instanceof r?(0,H.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return q.toString(this.rawData);case"text":return Nn.serialize(this.toTextObject());case"hex":return H.Convert.ToHex(this.rawData);case"base64":return H.Convert.ToBase64(this.rawData);case"base64url":return H.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new Se(this.getTextName(),{},e)}};_o.NAME="ASN";var dr=class r extends _o{constructor(...e){let t;H.BufferSourceConverter.isBufferSource(e[0])?t=H.BufferSourceConverter.toArrayBuffer(e[0]):t=q.serialize(new dt({extnID:e[0],critical:e[1],extnValue:new se(H.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,dt)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[Se.NAME]===r.NAME&&(e[Se.NAME]=on.toString(this.type)),e}},d1,uu=class r{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[d1]="CryptoProvider",typeof self<"u"&&typeof crypto<"u"?this.set(r.DEFAULT,crypto):typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle&&this.set(r.DEFAULT,globalThis.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,t){return this.items.forEach(e,t)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=r.DEFAULT){let t=this.items.get(e.toLowerCase());if(!t)throw new Error(`Cannot get Crypto by name '${e}'`);return t}set(e,t){if(typeof e=="string"){if(!t)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),t)}else this.items.set(r.DEFAULT,e);return this}};d1=Symbol.toStringTag;uu.DEFAULT="default";var wt=new uu,rC=/^[0-2](?:\.[1-9][0-9]*)+$/;function nC(r){return new RegExp(rC).test(r)}var ep=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 nC(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},qt=new ep;qt.register("CN","2.5.4.3");qt.register("L","2.5.4.7");qt.register("ST","2.5.4.8");qt.register("O","2.5.4.10");qt.register("OU","2.5.4.11");qt.register("C","2.5.4.6");qt.register("DC","0.9.2342.19200300.100.1.25");qt.register("E","1.2.840.113549.1.9.1");qt.register("G","2.5.4.42");qt.register("I","2.5.4.43");qt.register("SN","2.5.4.4");qt.register("T","2.5.4.12");function oC(r,e){return`\\${H.Convert.ToHex(H.Convert.FromUtf8String(e)).toUpperCase()}`}function iC(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,oC)}var hr=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 ep,this.asn=new Ne;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let o=t[n];this.extraNames.register(n,o)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Ne?this.asn=e:H.BufferSourceConverter.isBufferSource(e)?this.asn=q.parse(e,Ne):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||qt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||qt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${H.Convert.ToHex(t.value.anyValue)}`:iC(t.value.toString());return`${n}=${o}`}).join("+")).join(", ")}toJSON(){var e;let t=[];for(let n of this.asn){let o={};for(let i of n){let s=this.getName(i.type)||i.type;(e=o[s])!==null&&e!==void 0||(o[s]=[]),o[s].push(i.value.anyValue?`#${H.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Ne,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,o=null,i=",";for(;o=n.exec(`${e},`);){let[,s,a]=o,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),o[3]=c);let f=o[3];s=this.getTypeOid(s);let h=this.createAttribute(s,a);i==="+"?t[t.length-1].push(h):t.push(new io([h])),i=f}return t}fromJSON(e){let t=new Ne;for(let n of e){let o=new io;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let f=this.createAttribute(s,c);o.push(f)}}t.push(o)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){let n=new ui({type:e});if(typeof t=="object")for(let o in t)switch(o){case"ia5String":n.value.ia5String=t[o];break;case"utf8String":n.value.utf8String=t[o];break;case"universalString":n.value.universalString=t[o];break;case"bmpString":n.value.bmpString=t[o];break;case"printableString":n.value.printableString=t[o];break}else if(t[0]==="#")n.value.anyValue=H.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
10
- `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return q.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},m1="Cannot initialize GeneralName from ASN.1 data.",r1=`${m1} Unsupported string format in use.`,sC=`${m1} Value doesn't match to GUID regular expression.`,n1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,o1="1.3.6.1.4.1.311.25.1",i1="1.3.6.1.4.1.311.20.2.3",fy="dns",py="dn",hy="email",dy="ip",my="url",yy="guid",gy="upn",Xf="id",nn=class extends _o{constructor(...e){let t;if(e.length===2)switch(e[0]){case py:{let n=new hr(e[1]).toArrayBuffer(),o=q.parse(n,Ne);t=new ce({directoryName:o});break}case fy:t=new ce({dNSName:e[1]});break;case hy:t=new ce({rfc822Name:e[1]});break;case yy:{let n=new RegExp(n1,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let o=n.slice(1).map((i,s)=>s<3?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(i)).reverse()):i).join("");t=new ce({otherName:new so({typeId:o1,value:q.serialize(new se(H.Convert.FromHex(o)))})});break}case dy:t=new ce({iPAddress:e[1]});break;case Xf:t=new ce({registeredID:e[1]});break;case gy:{t=new ce({otherName:new so({typeId:i1,value:q.serialize(Vd.toASN(e[1]))})});break}case my:t=new ce({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else H.BufferSourceConverter.isBufferSource(e[0])?t=q.parse(e[0],ce):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=fy,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=hy,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=dy,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=my,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Xf,this.value=e.registeredID;else if(e.directoryName!=null)this.type=py,this.value=new hr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===o1){this.type=yy;let t=q.parse(e.otherName.value,se),n=new RegExp(n1,"i").exec(H.Convert.ToHex(t));if(!n)throw new Error(sC);this.value=n.slice(1).map((o,i)=>i<3?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===i1)this.type=gy,this.value=q.parse(e.otherName.value,Qe).toString();else throw new Error(r1);else throw new Error(r1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case py:case fy:case yy:case dy:case Xf:case gy:case my:e=this.type.toUpperCase();break;case hy:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Xf&&(t=on.toString(t)),new Se(e,void 0,t)}},Vi=class extends _o{constructor(e){let t;if(e instanceof He)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ce)n.push(o);else{let i=q.parse(new nn(o.type,o.value).rawData,ce);n.push(i)}t=new He(n)}else if(H.BufferSourceConverter.isBufferSource(e))t=q.parse(e,He);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 nn(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[Se.NAME]];Array.isArray(o)||(o=[],e[n[Se.NAME]]=o),o.push(n)}return e}};Vi.NAME="GeneralNames";var au="-{5}",lu="\\n",aC=`[^${lu}]+`,cC=`${au}BEGIN (${aC}(?=${au}))${au}`,uC=`${au}END \\1${au}`,Ys="\\n",lC=`[^:${lu}]+`,fC=`(?:[^${lu}]+${Ys}(?: +[^${lu}]+${Ys})*)`,pC="[a-zA-Z0-9=+/]+",hC=`(?:${pC}${Ys})+`,s1=`${cC}${Ys}(?:((?:${lC}: ${fC})+))?${Ys}?(${hC})${uC}`,Dt=class{static isPem(e){return typeof e=="string"&&new RegExp(s1,"g").test(e)}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(s1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${lu}]+`,"g"),""),s={type:o[1],headers:[],rawData:H.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Ys,"g")),f=null;for(let h of c){let[p,m]=h.split(/:(.*)/);if(m===void 0){if(!f)throw new Error("Cannot parse PEM string. Incorrect header value");f.value+=p.trim()}else f&&s.headers.push(f),f={key:p,value:m.trim()}}f&&s.headers.push(f)}n.push(s)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){let n=new Array;return t?e.forEach(o=>{if(!H.BufferSourceConverter.isBufferSource(o))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:t,rawData:H.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
11
- `)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:H.BufferSourceConverter.toArrayBuffer(e)})}}static encodeStruct(e){var t;let n=e.type.toLocaleUpperCase(),o=[];if(o.push(`-----BEGIN ${n}-----`),!((t=e.headers)===null||t===void 0)&&t.length){for(let f of e.headers)o.push(`${f.key}: ${f.value}`);o.push("")}let i=H.Convert.ToBase64(e.rawData),s,a=0,c=Array();for(;a<i.length&&(i.length-a<64?s=i.substring(a):(s=i.substring(a,a+64),a+=64),s.length!==0);)if(c.push(s),s.length<64)break;return o.push(...c),o.push(`-----END ${n}-----`),o.join(`
12
- `)}};Dt.CertificateTag="CERTIFICATE";Dt.CrlTag="CRL";Dt.CertificateRequestTag="CERTIFICATE REQUEST";Dt.PublicKeyTag="PUBLIC KEY";Dt.PrivateKeyTag="PRIVATE KEY";var Co=class r extends _o{static isAsnEncoded(e){return H.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Dt.isPem(e))return Dt.decode(e)[0];if(H.Convert.isHex(e))return H.Convert.FromHex(e);if(H.Convert.isBase64(e))return H.Convert.FromBase64(e);if(H.Convert.isBase64Url(e))return H.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=H.Convert.ToBinary(e);return Dt.isPem(t)?Dt.decode(t)[0]:H.Convert.isHex(t)?H.Convert.FromHex(t):H.Convert.isBase64(t)?H.Convert.FromBase64(t):H.Convert.isBase64Url(t)?H.Convert.FromBase64Url(t):H.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 Dt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Pn=class r extends Co{static async create(e,t=wt.get()){if(e instanceof r)return e;if(uu.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(H.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Co.isAsnEncoded(e)?super(e,ht):super(e),this.tag=Dt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||wt.get()):t=e[0]||wt.get();let i=this.rawData,s=q.parse(this.rawData,ht);return s.algorithm.algorithm===go&&(i=dC(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Le.resolve(Hi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case en:{let o=q.parse(e.subjectPublicKey,Fs),i=H.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=H.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||wt.get()):n=e[0]||wt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=wt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=wt.get();let o=q.parse(this.rawData,ht);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,ht);switch(e.Algorithm=Nn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Bi:e["EC Point"]=t.subjectPublicKey;break;case en:default:e["Raw Data"]=t.subjectPublicKey}return e}};function dC(r,e){return r.algorithm=new j({algorithm:en,parameters:null}),e=q.serialize(r),e}var tp=class r extends dr{static async create(e,t=!1,n=wt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new Xr({keyIdentifier:new pi(H.Convert.FromHex(e[0]))});super(ff,e[1],q.serialize(t))}else{let t=e[0],n=t.name instanceof Vi?q.parse(t.name.rawData,He):t.name,o=new Xr({authorityCertIssuer:n,authorityCertSerialNumber:H.Convert.FromHex(t.serialNumber)});super(ff,e[1],q.serialize(o))}}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,Xr);t.keyIdentifier&&(this.keyId=H.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?H.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,Xr);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Vi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};tp.NAME="Authority Key Identifier";var Zs=class extends dr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,hi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new hi({cA:e[0],pathLenConstraint:e[1]});super(pf,e[2],q.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};Zs.NAME="Basic Constraints";var a1;(function(r){r.serverAuth="1.3.6.1.5.5.7.3.1",r.clientAuth="1.3.6.1.5.5.7.3.2",r.codeSigning="1.3.6.1.5.5.7.3.3",r.emailProtection="1.3.6.1.5.5.7.3.4",r.timeStamping="1.3.6.1.5.5.7.3.8",r.ocspSigning="1.3.6.1.5.5.7.3.9"})(a1||(a1={}));var rp=class extends dr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Cc);this.usages=t.map(n=>n)}else{let t=new Cc(e[0]);super(yf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>on.toString(t)).join(", "),e}};rp.NAME="Extended Key Usages";var c1;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(c1||(c1={}));var np=class extends dr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,As);this.usages=t.toNumber()}else{let t=new As(e[0]);super(gf,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,As);return e[""]=t.toJSON().join(", "),e}};np.NAME="Key Usages";var op=class r extends dr{static async create(e,t=!1,n=wt.get()){let i=await(await Pn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Ht);this.keyId=H.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?H.Convert.FromHex(e[0]):e[0],n=new Ht(t);super(dm,e[1],q.serialize(n)),this.keyId=H.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,Ht);return e[""]=t,e}};op.NAME="Subject Key Identifier";var ip=class extends dr{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(pm,e[1],new Vi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,vf);this.names=new Vi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};ip.NAME="Subject Alternative Name";var Gt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new dr(e),n=this.items.get(t.type);return n?new n(e):t}};Gt.items=new Map;var sp=class extends dr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=q.parse(this.value,vc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new vc(n.map(s=>new di({policyIdentifier:s})));super(df,o,q.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Se("",{},on.toString(t))),e}};sp.NAME="Certificate Policies";Gt.register(df,sp);var ap=class extends dr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new Yr({distributionPoint:new _n({fullName:[new ce({uniformResourceIdentifier:s})]})})),i=new uo(o);super(mf,e[1],q.serialize(i))}else{let n=new uo(e[0]);super(mf,e[1],q.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,uo);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 nn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};ap.NAME="CRL Distribution Points";var cp=class extends dr{constructor(...e){var t,n,o,i;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof fi){let s=new fi(e[0]);super(lf,e[1],q.serialize(s))}else{let s=e[0],a=new fi;Zf(a,s,Yd,"ocsp"),Zf(a,s,Zd,"caIssuers"),Zf(a,s,Jd,"timeStamping"),Zf(a,s,Qd,"caRepository"),super(lf,e[1],q.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],q.parse(e.extnValue,fi).forEach(n=>{switch(n.accessMethod){case Yd:this.ocsp.push(new nn(n.accessLocation));break;case Zd:this.caIssuers.push(new nn(n.accessLocation));break;case Jd:this.timeStamping.push(new nn(n.accessLocation));break;case Qd:this.caRepository.push(new nn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&Yf(e,"OCSP",this.ocsp),this.caIssuers.length&&Yf(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Yf(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Yf(e,"CA Repository",this.caRepository),e}};cp.NAME="Authority Info Access";function Yf(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 Zf(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new nn("url",s)),r.push(new Sn({accessMethod:t,accessLocation:q.parse(s.rawData,ce)}))})}var Js=class r extends _o{constructor(...e){let t;if(H.BufferSourceConverter.isBufferSource(e[0]))t=H.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>H.BufferSourceConverter.toArrayBuffer(i)):[];t=q.serialize(new pt({type:n,values:o}))}super(t,pt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Se("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Se.NAME]===r.NAME&&(e[Se.NAME]=on.toString(this.type)),e}};Js.NAME="Attribute";var up=class extends Js{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new ru({printableString:e[0]});super(uy,[q.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],ru);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Se.VALUE]=this.password,e}};up.NAME="Challenge Password";var fu=class extends Js{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new Jt;for(let i of n)o.push(q.parse(i.rawData,dt));super(ou,[q.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],Jt);this.items=t.map(n=>Gt.create(q.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}};fu.NAME="Extensions";var Qs=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new Js(e),n=this.items.get(t.type);return n?new n(e):t}};Qs.items=new Map;var hu="crypto.signatureFormatter",Ay=class{toAsnSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}},Qf,Sy=Qf=class{static createPssParams(e,t){let n=Qf.getHashAlgorithm(e);return n?new tn({hashAlgorithm:n,maskGenAlgorithm:new j({algorithm:wo,parameters:q.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Le.resolve(Hi);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new j({algorithm:Ms,parameters:null});case"sha-256":return new j({algorithm:Of,parameters:null});case"sha-384":return new j({algorithm:Ks,parameters:null});case"sha-512":return new j({algorithm:Hs,parameters:null})}}else return new j({algorithm:en,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let t=Qf.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new j({algorithm:go,parameters:q.serialize(t)})}else return new j({algorithm:go,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case en:return{name:"RSASSA-PKCS1-v1_5"};case Ms:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Of:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Ks:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Hs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case go:if(e.parameters){let t=q.parse(e.parameters,tn);return{name:"RSA-PSS",hash:Le.resolve(Hi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Sy=Qf=u([bo()],Sy);Le.registerSingleton(pu,Sy);var Ey=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new j({algorithm:Pi});case"sha-256":return new j({algorithm:Ni});case"sha-384":return new j({algorithm:Oi});case"sha-512":return new j({algorithm:Ri})}return null}toWebAlgorithm(e){switch(e.algorithm){case Pi:return{name:"SHA-1"};case Ni:return{name:"SHA-256"};case Oi:return{name:"SHA-384"};case Ri:return{name:"SHA-512"}}return null}};Ey=u([bo()],Ey);Le.registerSingleton(pu,Ey);var On=class r{addPadding(e,t){let n=H.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=H.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new ki,s=H.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),q.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=q.parse(t,ki),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,H.combine)(s,a)}return null}};On.namedCurveSize=new Map;On.defaultNamedCurveSize=32;var wy="1.3.101.110",u1="1.3.101.111",xy="1.3.101.112",l1="1.3.101.113",_y=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=xy;break;case"x25519":t=wy;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=xy;break;case"ed448":t=l1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=wy;break;case"x448":t=u1;break}}return t?new j({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case xy:return{name:"Ed25519"};case l1:return{name:"EdDSA",namedCurve:"Ed448"};case wy:return{name:"X25519"};case u1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};_y=u([bo()],_y);Le.registerSingleton(pu,_y);var Cy=class extends Co{constructor(e){Co.isAsnEncoded(e)?super(e,Eo):super(e),this.tag=Dt.CertificateRequestTag}onInit(e){this.tbs=q.serialize(e.certificationRequestInfo),this.publicKey=new Pn(e.certificationRequestInfo.subjectPKInfo);let t=Le.resolve(Hi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>Qs.create(q.serialize(o)));let n=this.getAttribute(ou);this.extensions=[],n instanceof fu&&(this.extensions=n.items),this.subjectName=new hr(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=wt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Le.resolveAll(hu).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,Eo),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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Cy.NAME="PKCS#10 Certificate Request";var ea=class extends Co{constructor(e){Co.isAsnEncoded(e)?super(e,cr):super(e),this.tag=Dt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=q.serialize(t),this.serialNumber=H.Convert.ToHex(t.serialNumber),this.subjectName=new hr(t.subject),this.subject=new hr(t.subject).toString(),this.issuerName=new hr(t.issuer),this.issuer=this.issuerName.toString();let n=Le.resolve(Hi);this.signatureAlgorithm=n.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signatureValue;let o=t.validity.notBefore.utcTime||t.validity.notBefore.generalTime;if(!o)throw new Error("Cannot get 'notBefore' value");this.notBefore=o;let i=t.validity.notAfter.utcTime||t.validity.notAfter.generalTime;if(!i)throw new Error("Cannot get 'notAfter' value");this.notAfter=i,this.extensions=[],t.extensions&&(this.extensions=t.extensions.map(s=>Gt.create(q.serialize(s)))),this.publicKey=new Pn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=wt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Pn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(H.BufferSourceConverter.isBufferSource(i)){let f=new Pn(i);n={...f.algorithm,...this.signatureAlgorithm},o=await f.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Le.resolveAll(hu).reverse(),a=null;for(let f of s)if(a=f.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let h=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<h&&h<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=wt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=wt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,cr),n=t.tbsCertificate,o=new Se("",{Version:`${Zr[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Nn.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:Nn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ea.NAME="Certificate";var lp=class{static async createSelfSigned(e,t=wt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=wt.get()){var n;let o;e.publicKey instanceof Pn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:H.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(e.serialNumber)):t.getRandomValues(new Uint8Array(16));i[0]>127&&(i[0]&=127),i.length>1&&i[0]===0&&(i[1]|=128);let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new cr({tbsCertificate:new mt({version:Zr.v3,serialNumber:i,validity:new Cn({notBefore:s,notAfter:a}),extensions:new Jt(((n=e.extensions)===null||n===void 0?void 0:n.map(S=>q.parse(S.rawData,dt)))||[]),subjectPublicKeyInfo:q.parse(o,ht)})});if(e.subject){let S=e.subject instanceof hr?e.subject:new hr(e.subject);c.tbsCertificate.subject=q.parse(S.toArrayBuffer(),Ne)}if(e.issuer){let S=e.issuer instanceof hr?e.issuer:new hr(e.issuer);c.tbsCertificate.issuer=q.parse(S.toArrayBuffer(),Ne)}let f={hash:"SHA-256"},h="signingKey"in e?{...f,...e.signingAlgorithm,...e.signingKey.algorithm}:{...f,...e.signingAlgorithm},p=Le.resolve(Hi);c.tbsCertificate.signature=c.signatureAlgorithm=p.toAsnAlgorithm(h);let m=q.serialize(c.tbsCertificate),v="signingKey"in e?await t.subtle.sign(h,e.signingKey,m):e.signature,g=Le.resolveAll(hu).reverse(),w=null;for(let S of g)if(w=S.toAsnSignature(h,v),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new ea(q.serialize(c))}},f1;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(f1||(f1={}));Gt.register(pf,Zs);Gt.register(yf,rp);Gt.register(gf,np);Gt.register(dm,op);Gt.register(ff,tp);Gt.register(pm,ip);Gt.register(mf,ap);Gt.register(lf,cp);Qs.register(uy,up);Qs.register(ou,fu);Le.registerSingleton(hu,Ay);Le.registerSingleton(hu,On);On.namedCurveSize.set("P-256",32);On.namedCurveSize.set("K-256",32);On.namedCurveSize.set("P-384",48);On.namedCurveSize.set("P-521",66);var Rn="/",y1=new TextEncoder().encode(Rn),fp=y1[0],du=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=de(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(t==null&&(t=!0),t&&this.clean(),this._buf.byteLength===0||this._buf[0]!==fp)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(Rn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=y1),this._buf[0]!==fp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(fp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===fp;)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(Rn).slice(1)}type(){return mC(this.baseNamespace())}name(){return yC(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Rn)||(e+=Rn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Rn):new r(e.slice(0,-1).join(Rn))}child(e){return this.toString()===Rn?e:e.toString()===Rn?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(),...gC(e.map(t=>t.namespaces()))])}};function mC(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function yC(r){let e=r.split(":");return e[e.length-1]}function gC(r){return[].concat(...r)}var pp=class extends Mn{async listen(){throw new Ll("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Iy(){let r=Ze(),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 g1(){let r=Iy(),e=Iy();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function wC(r){return r[Symbol.asyncIterator]!=null}async function xC(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*bC(r){let e=new AbortController,t=Bl();xC(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*vC(r){for(let e of r)yield*e}function AC(...r){let e=[];for(let t of r)wC(t)||e.push(t);return e.length===r.length?vC(e):bC(r)}var w1=AC;function x1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Ty(r)){let n=r;r=()=>n.source}else if(v1(r)||b1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Ty(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Ty(t[n])&&(t[n]=EC(t[n]));return SC(...t)}var SC=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},b1=r=>r?.[Symbol.asyncIterator]!=null,v1=r=>r?.[Symbol.iterator]!=null,Ty=r=>r==null?!1:r.sink!=null&&r.source!=null,EC=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=ps({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(b1(i))o=async function*(){yield*i,n.end()};else if(v1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return w1(n,o())}return r.source};var ta=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function S1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function hp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function dp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function It(r,...e){if(!S1(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 By(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 E1(r,e){It(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Dn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Ln(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function _C(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var CC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function IC(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function mp(r){if(typeof r=="string")r=IC(r);else if(S1(r))r=yp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function _1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function C1(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 ky=(r,e)=>{function t(n,...o){if(It(n),!CC)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?It(h):It(h,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&It(o[1]);let s=e(n,...o),a=(h,p)=>{if(p!==void 0){if(h!==2)throw new Error("cipher output not supported");It(p)}},c=!1;return{encrypt(h,p){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,It(h),a(s.encrypt.length,p),s.encrypt(h,p)},decrypt(h,p){if(It(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 Py(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&&!TC(e))throw new Error("invalid output, must be aligned");return e}function A1(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,f=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+f,a,n)}function I1(r,e,t){hp(t);let n=new Uint8Array(16),o=_C(n);return A1(o,0,BigInt(e),t),A1(o,8,BigInt(r),t),n}function TC(r){return r.byteOffset%4===0}function yp(r){return Uint8Array.from(r)}var B1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),BC=B1("expand 16-byte k"),kC=B1("expand 32-byte k"),PC=Dn(BC),NC=Dn(kC);function ee(r,e){return r<<e|r>>>32-e}function Ny(r){return r.byteOffset%4===0}var gp=64,OC=16,k1=2**32-1,T1=new Uint32Array;function RC(r,e,t,n,o,i,s,a){let c=o.length,f=new Uint8Array(gp),h=Dn(f),p=Ny(o)&&Ny(i),m=p?Dn(o):T1,v=p?Dn(i):T1;for(let g=0;g<c;s++){if(r(e,t,n,h,s,a),s>=k1)throw new Error("arx: counter overflow");let w=Math.min(gp,c-g);if(p&&w===gp){let S=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let O=0,Y;O<OC;O++)Y=S+O,v[Y]=m[Y]^h[O];g+=gp;continue}for(let S=0,O;S<w;S++)O=g+S,i[O]=o[O]^f[S];g+=w}}function Oy(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=_1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return dp(o),dp(s),hp(i),hp(t),(a,c,f,h,p=0)=>{It(a),It(c),It(f);let m=f.length;if(h===void 0&&(h=new Uint8Array(m)),It(h),dp(p),p<0||p>=k1)throw new Error("arx: counter overflow");if(h.length<m)throw new Error(`arx: output (${h.length}) is shorter than data (${m})`);let v=[],g=a.length,w,S;if(g===32)v.push(w=yp(a)),S=NC;else if(g===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),S=PC,v.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Ny(c)||v.push(c=yp(c));let O=Dn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(S,O,Dn(c.subarray(0,16)),O),c=c.subarray(16)}let Y=16-o;if(Y!==c.length)throw new Error(`arx: nonce must be ${Y} or 16 bytes`);if(Y!==12){let b=new Uint8Array(12);b.set(c,i?0:12-c.length),c=b,v.push(c)}let T=Dn(c);return RC(r,S,O,T,f,h,p,s),Ln(...v),h}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Ry=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=mp(e),It(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),f=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let 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],f=s[2],h=s[3],p=s[4],m=s[5],v=s[6],g=s[7],w=s[8],S=s[9],O=xt(e,t+0),Y=xt(e,t+2),T=xt(e,t+4),b=xt(e,t+6),D=xt(e,t+8),V=xt(e,t+10),N=xt(e,t+12),U=xt(e,t+14),$=i[0]+(O&8191),X=i[1]+((O>>>13|Y<<3)&8191),M=i[2]+((Y>>>10|T<<6)&8191),G=i[3]+((T>>>7|b<<9)&8191),F=i[4]+((b>>>4|D<<12)&8191),ie=i[5]+(D>>>1&8191),k=i[6]+((D>>>14|V<<2)&8191),R=i[7]+((V>>>11|N<<5)&8191),K=i[8]+((N>>>8|U<<8)&8191),P=i[9]+(U>>>5|o),y=0,C=y+$*a+X*(5*S)+M*(5*w)+G*(5*g)+F*(5*v);y=C>>>13,C&=8191,C+=ie*(5*m)+k*(5*p)+R*(5*h)+K*(5*f)+P*(5*c),y+=C>>>13,C&=8191;let L=y+$*c+X*a+M*(5*S)+G*(5*w)+F*(5*g);y=L>>>13,L&=8191,L+=ie*(5*v)+k*(5*m)+R*(5*p)+K*(5*h)+P*(5*f),y+=L>>>13,L&=8191;let I=y+$*f+X*c+M*a+G*(5*S)+F*(5*w);y=I>>>13,I&=8191,I+=ie*(5*g)+k*(5*v)+R*(5*m)+K*(5*p)+P*(5*h),y+=I>>>13,I&=8191;let re=y+$*h+X*f+M*c+G*a+F*(5*S);y=re>>>13,re&=8191,re+=ie*(5*w)+k*(5*g)+R*(5*v)+K*(5*m)+P*(5*p),y+=re>>>13,re&=8191;let le=y+$*p+X*h+M*f+G*c+F*a;y=le>>>13,le&=8191,le+=ie*(5*S)+k*(5*w)+R*(5*g)+K*(5*v)+P*(5*m),y+=le>>>13,le&=8191;let Q=y+$*m+X*p+M*h+G*f+F*c;y=Q>>>13,Q&=8191,Q+=ie*a+k*(5*S)+R*(5*w)+K*(5*g)+P*(5*v),y+=Q>>>13,Q&=8191;let pe=y+$*v+X*m+M*p+G*h+F*f;y=pe>>>13,pe&=8191,pe+=ie*c+k*a+R*(5*S)+K*(5*w)+P*(5*g),y+=pe>>>13,pe&=8191;let he=y+$*g+X*v+M*m+G*p+F*h;y=he>>>13,he&=8191,he+=ie*f+k*c+R*a+K*(5*S)+P*(5*w),y+=he>>>13,he&=8191;let Ee=y+$*w+X*g+M*v+G*m+F*p;y=Ee>>>13,Ee&=8191,Ee+=ie*h+k*f+R*c+K*a+P*(5*S),y+=Ee>>>13,Ee&=8191;let _e=y+$*S+X*w+M*g+G*v+F*m;y=_e>>>13,_e&=8191,_e+=ie*p+k*h+R*f+K*c+P*a,y+=_e>>>13,_e&=8191,y=(y<<2)+y|0,y=y+C|0,C=y&8191,y=y>>>13,L+=y,i[0]=C,i[1]=L,i[2]=I,i[3]=re,i[4]=le,i[5]=Q,i[6]=pe,i[7]=he,i[8]=Ee,i[9]=_e}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;Ln(n)}update(e){By(this),e=mp(e),It(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(){Ln(this.h,this.r,this.buffer,this.pad)}digestInto(e){By(this),E1(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 DC(r){let e=(n,o)=>r(o).update(mp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var P1=DC(r=>new Ry(r));function R1(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],f=r[3],h=e[0],p=e[1],m=e[2],v=e[3],g=e[4],w=e[5],S=e[6],O=e[7],Y=o,T=t[0],b=t[1],D=t[2],V=s,N=a,U=c,$=f,X=h,M=p,G=m,F=v,ie=g,k=w,R=S,K=O,P=Y,y=T,C=b,L=D;for(let re=0;re<i;re+=2)V=V+X|0,P=ee(P^V,16),ie=ie+P|0,X=ee(X^ie,12),V=V+X|0,P=ee(P^V,8),ie=ie+P|0,X=ee(X^ie,7),N=N+M|0,y=ee(y^N,16),k=k+y|0,M=ee(M^k,12),N=N+M|0,y=ee(y^N,8),k=k+y|0,M=ee(M^k,7),U=U+G|0,C=ee(C^U,16),R=R+C|0,G=ee(G^R,12),U=U+G|0,C=ee(C^U,8),R=R+C|0,G=ee(G^R,7),$=$+F|0,L=ee(L^$,16),K=K+L|0,F=ee(F^K,12),$=$+F|0,L=ee(L^$,8),K=K+L|0,F=ee(F^K,7),V=V+M|0,L=ee(L^V,16),R=R+L|0,M=ee(M^R,12),V=V+M|0,L=ee(L^V,8),R=R+L|0,M=ee(M^R,7),N=N+G|0,P=ee(P^N,16),K=K+P|0,G=ee(G^K,12),N=N+G|0,P=ee(P^N,8),K=K+P|0,G=ee(G^K,7),U=U+F|0,y=ee(y^U,16),ie=ie+y|0,F=ee(F^ie,12),U=U+F|0,y=ee(y^U,8),ie=ie+y|0,F=ee(F^ie,7),$=$+X|0,C=ee(C^$,16),k=k+C|0,X=ee(X^k,12),$=$+X|0,C=ee(C^$,8),k=k+C|0,X=ee(X^k,7);let I=0;n[I++]=s+V|0,n[I++]=a+N|0,n[I++]=c+U|0,n[I++]=f+$|0,n[I++]=h+X|0,n[I++]=p+M|0,n[I++]=m+G|0,n[I++]=v+F|0,n[I++]=g+ie|0,n[I++]=w+k|0,n[I++]=S+R|0,n[I++]=O+K|0,n[I++]=Y+P|0,n[I++]=T+y|0,n[I++]=b+C|0,n[I++]=D+L|0}function LC(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],f=e[1],h=e[2],p=e[3],m=e[4],v=e[5],g=e[6],w=e[7],S=t[0],O=t[1],Y=t[2],T=t[3];for(let D=0;D<20;D+=2)o=o+c|0,S=ee(S^o,16),m=m+S|0,c=ee(c^m,12),o=o+c|0,S=ee(S^o,8),m=m+S|0,c=ee(c^m,7),i=i+f|0,O=ee(O^i,16),v=v+O|0,f=ee(f^v,12),i=i+f|0,O=ee(O^i,8),v=v+O|0,f=ee(f^v,7),s=s+h|0,Y=ee(Y^s,16),g=g+Y|0,h=ee(h^g,12),s=s+h|0,Y=ee(Y^s,8),g=g+Y|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+f|0,T=ee(T^o,16),g=g+T|0,f=ee(f^g,12),o=o+f|0,T=ee(T^o,8),g=g+T|0,f=ee(f^g,7),i=i+h|0,S=ee(S^i,16),w=w+S|0,h=ee(h^w,12),i=i+h|0,S=ee(S^i,8),w=w+S|0,h=ee(h^w,7),s=s+p|0,O=ee(O^s,16),m=m+O|0,p=ee(p^m,12),s=s+p|0,O=ee(O^s,8),m=m+O|0,p=ee(p^m,7),a=a+c|0,Y=ee(Y^a,16),v=v+Y|0,c=ee(c^v,12),a=a+c|0,Y=ee(Y^a,8),v=v+Y|0,c=ee(c^v,7);let b=0;n[b++]=o,n[b++]=i,n[b++]=s,n[b++]=a,n[b++]=S,n[b++]=O,n[b++]=Y,n[b++]=T}var UC=Oy(R1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),jC=Oy(R1,{counterRight:!1,counterLength:8,extendNonceFn:LC,allowShortKeys:!1});var MC=new Uint8Array(16),N1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(MC.subarray(t))},KC=new Uint8Array(32);function O1(r,e,t,n,o){let i=r(e,t,KC),s=P1.create(i);o&&N1(s,o),N1(s,n);let a=I1(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Ln(i,a),c}var D1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Py(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let f=O1(r,e,t,c,n);return s.set(f,a),Ln(f),s},decrypt(i,s){s=Py(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),f=O1(r,e,t,a,n);if(!C1(c,f))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Ln(f),s}}),Dy=ky({blockSize:64,nonceLength:12,tagLength:16},D1(UC)),XG=ky({blockSize:64,nonceLength:24,tagLength:16},D1(jC));function U1(r,e,t){return ya(r),t===void 0&&(t=new Uint8Array(r.outputLen)),os(r,$n(t),$n(e))}var Ly=Uint8Array.from([0]),L1=Uint8Array.of();function j1(r,e,t,n=32){ya(r),Xi(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=L1);let s=new Uint8Array(i*o),a=os.create(r,e),c=a._cloneInto(),f=new Uint8Array(a.outputLen);for(let h=0;h<i;h++)Ly[0]=h+1,c.update(h===0?L1:f).update(t).update(Ly).digestInto(f),s.set(f,o*h),a._cloneInto(c);return a.destroy(),c.destroy(),wr(f,Ly),s.slice(0,n)}var Uy={hashSHA256(r){return Jn(r.subarray())},getHKDF(r,e){let t=U1(Jn,e,r),o=j1(Jn,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=Ia.utils.randomPrivateKey();return{publicKey:Ia.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Ia.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Ia.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Dy(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Dy(n,e,t).decrypt(r.subarray(),o)}};var M1=Uy;function K1(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 ra=r=>{let e=nt(2);return e[0]=r>>8,e[1]=r,e};ra.bytes=2;var mu=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)};mu.bytes=2;function H1(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 jy(r,e){!e.enabled||!ta||(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 My(r,e){!e.enabled||!ta||(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 V1(r,e){!e.enabled||!ta||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function Ky(r,e){!e.enabled||!ta||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Hy(r,e,t){!t.enabled||!ta||(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 na=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var HC=0,VC=4294967295,$C="Cipherstate has reached maximum n, a new handshake must be performed",wp=class{n;bytes;view;constructor(e=HC){this.n=e,this.bytes=rt(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>VC)throw new Error($C)}};var $i=rt(0),oa=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new wp(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},Vy=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=de(t,"utf-8");this.h=FC(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 be(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,$i);return[new oa(this.crypto,e),new oa(this.crypto,t)]}},$y=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:f}=e;this.crypto=t,this.ss=new Vy(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=f}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},yu=class extends $y{writeMessageA(e){return new be(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new be(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new be(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new na(`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 na(`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 na(`handshake stage 2 validation fail: ${t.message}`)}}};function FC(r,e){if(e.length<=32){let t=rt(32);return t.set(e),t}else return r.hash(e)}var xp;(function(r){let e;r.codec=()=>(e==null&&(e=_r((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 Na('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 Na('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=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(xp||(xp={}));var gu;(function(r){let e;r.codec=()=>(e==null&&(e=_r((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),xp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:rt(0),identitySig:rt(0)},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{i.identityKey=t.bytes();break}case 2:{i.identitySig=t.bytes();break}case 4:{i.extensions=xp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Er(t,r.codec()),r.decode=(t,n)=>Sr(t,r.codec(),n)})(gu||(gu={}));async function Fy(r,e,t){let n=await r.sign($1(e));return gu.encode({identityKey:Vn(r.publicKey),identitySig:n,extensions:t})}async function Wy(r,e,t){try{let n=gu.decode(r),o=ja(n.identityKey);if(t?.equals(o)===!1)throw new Error(`Payload identity key ${o} does not match expected remote identity key ${t}`);if(!e)throw new Error("Remote static does not exist");let i=$1(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Eu(n.message)}}function $1(r){let e=de("noise-libp2p-static-key:");return r instanceof Uint8Array?ot([e,r],e.length+r.length):(r.prepend(e),r)}async function F1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,h=await Fy(i,a.publicKey,f),p=new yu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});jy(p.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(p.writeMessageA($i),e),t.trace("Stage 0 - Initiator finished sending first message."),My(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."),Ky(p.re,t),V1(p.rs,t),t.trace("Initiator going to check remote's signature...");let v=await Wy(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 Hy(g,w,t),{payload:v,encrypt:S=>g.encryptWithAd($i,S),decrypt:(S,O)=>w.decryptWithAd($i,S,O)}}async function W1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:f}=r,h=await Fy(i,a.publicKey,f),p=new yu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});jy(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."),Ky(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."),My(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 v=await Wy(m,p.rs,c),[g,w]=p.ss.split();return Hy(g,w,t),{payload:v,encrypt:S=>w.encryptWithAd($i,S),decrypt:(S,O)=>g.decryptWithAd($i,S,O)}}var G1=16;function z1(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let i=o+65519;i>n.length&&(i=n.length);let s;n instanceof Uint8Array?s=r.encrypt(n.subarray(o,i)):s=r.encrypt(n.sublist(o,i)),e?.encryptedPackets.increment(),yield new be(ra(s.byteLength),s)}}}function X1(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-G1<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-G1);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var bp=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e;let c=i??M1;this.crypto=K1(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?H1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??rt(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Wi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=Ja(e,{lengthEncoder:ra,lengthDecoder:mu,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=ja(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ed(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new _u("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=Ja(e,{lengthEncoder:ra,lengthDecoder:mu,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=ja(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ed(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 F1({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 W1({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]=g1(),i=e.unwrap();return await x1(n,z1(t,this.metrics),i,s=>qo(s,{lengthDecoder:mu}),X1(t,this.metrics),n),o}};function Y1(r={}){return e=>new bp(e,r)}var qy=Object.values(Po).map(r=>r.decoder).reduce((r,e)=>r.or(e)),WC=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function Z1(r){return r?.match(WC)?.groups?.fingerprint}function Gy(r){let t=r.stringTuples().filter(n=>n[0]===_w).map(n=>n[1])[0];if(t===void 0||t==="")throw new Ae(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function qC(r){return er.decode(qy.decode(r))}function GC(r){let e=qC(Gy(r)),t=zC(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 Dl(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function J1(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=vt(tr.code,t);return $r(`/certhash/${ko.encode(n.bytes)}`)}function zC(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Ul(r)}}function Q1(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=GC(r);return{type:"answer",sdp:`v=0
8
+ `)}function Fy(r,e,t){var n=iu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=cT(i,e);return uT("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function pv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var lT=function(r){Qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(au);var fT=function(r){Qs(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(au);var pT=function(){function r(){this.preResolution=new lT,this.postResolution=new fT}return r}(),hv=pT;var Wy=new Map,hT=function(){function r(e){this.parent=e,this._registry=new fv,this.interceptors=new hv,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(lv(t)?o=t:o={useClass:t},Ui(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Mr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Ui(c.provider)?s=c.provider:s=null}if((n.lifecycle===wt.Singleton||n.lifecycle==wt.ContainerScoped||n.lifecycle==wt.ResolutionScoped)&&(Mi(o)||ea(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(),xo(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(),xo(e)){if(xo(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&&!xo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:wt.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new cu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&xo(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(uv(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=ou(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(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=ou(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(p){o={error:p}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}this.interceptors.postResolution.setAll(e,s)}},r.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===wt.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===wt.Singleton,o=e.options.lifecycle===wt.ContainerScoped,i=n||o,s;return Mi(e.provider)?s=e.provider.useValue:Ui(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):su(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ea(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===wt.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new cu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&xo(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=ou(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=iu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Mi(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=ou(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=iu(i.value,2),a=s[0],c=s[1];c.some(function(l){var p=l.options;return p.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 av(this,void 0,void 0,function(){var e;return cv(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 Wf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=Wy.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,Mr([void 0],s)))}();return pv(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 $y(o)?qf(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Mr([n.resolveAll(o.token,new cu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Mr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new cu,o.isOptional):n.resolve(o.token,e,o.isOptional):qf(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Mr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(Fy(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}(),Ue=new hT;function dT(r){return function(e){Wy.set(e,Vy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Ue.register(t,e)}):Ue.register(r.token,e))}}var vo=dT;if(typeof Reflect>"u"||!Reflect.getMetadata)throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);function Ae(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}function Se(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Gy,Ki=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Se([u({type:h.ObjectIdentifier})],Ki.prototype,"attrId",void 0);Se([u({type:h.Any,repeated:"set"})],Ki.prototype,"attrValues",void 0);var dv=Gy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Gy.prototype)}};dv=Gy=Se([S({type:_.Sequence,itemType:Ki})],dv);var zy,yv=zy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,zy.prototype)}};yv=zy=Se([S({type:_.Sequence,itemType:dr})],yv);var yT="1.2.840.113549",mT=`${yT}.1`,mv=`${mT}.12`,ta=`${mv}.1`,VF=`${ta}.1`,$F=`${ta}.2`,FF=`${ta}.3`,WF=`${ta}.4`,qF=`${ta}.5`,GF=`${ta}.6`,Hi=`${mv}.10.1`;var ZF=`${Hi}.1`,YF=`${Hi}.2`,JF=`${Hi}.3`,QF=`${Hi}.4`,eW=`${Hi}.5`,tW=`${Hi}.6`,Gf="1.2.840.113549.1.9";var zf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],zf.prototype,"certId",void 0);Se([u({type:h.Any,context:0})],zf.prototype,"certValue",void 0);var gv=`${Gf}.22`,sW=`${gv}.1`,aW=`${gv}.2`;var Xf=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],Xf.prototype,"crlId",void 0);Se([u({type:h.Any,context:0})],Xf.prototype,"crltValue",void 0);var gT=`${Gf}.23`,pW=`${gT}.1`;function Rn(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Zf=class extends ae{},_o=class{constructor(e={}){this.encryptionAlgorithm=new H,this.encryptedData=new Zf,Object.assign(this,e)}};Rn([u({type:H})],_o.prototype,"encryptionAlgorithm",void 0);Rn([u({type:Zf})],_o.prototype,"encryptedData",void 0);var Xy,Zy;(function(r){r[r.v1=0]="v1"})(Zy||(Zy={}));var Yf=class extends ae{},Yy=Xy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};Yy=Xy=Rn([S({type:_.Sequence,itemType:ht})],Yy);var Ao=class{constructor(e={}){this.version=Zy.v1,this.privateKeyAlgorithm=new H,this.privateKey=new Yf,Object.assign(this,e)}};Rn([u({type:h.Integer})],Ao.prototype,"version",void 0);Rn([u({type:H})],Ao.prototype,"privateKeyAlgorithm",void 0);Rn([u({type:Yf})],Ao.prototype,"privateKey",void 0);Rn([u({type:Yy,implicit:!0,context:0,optional:!0})],Ao.prototype,"attributes",void 0);var wv=class extends Ao{};wv=Se([S({type:_.Sequence})],wv);var bv=class extends _o{};bv=Se([S({type:_.Sequence})],bv);var Jf=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],Jf.prototype,"secretTypeId",void 0);Se([u({type:h.Any,context:0})],Jf.prototype,"secretValue",void 0);var So=class{constructor(e={}){this.mac=new Li,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Se([u({type:Li})],So.prototype,"mac",void 0);Se([u({type:ae})],So.prototype,"macSalt",void 0);Se([u({type:h.Integer,defaultValue:1})],So.prototype,"iterations",void 0);var Vi=class{constructor(e={}){this.version=3,this.authSafe=new dr,this.macData=new So,Object.assign(this,e)}};Se([u({type:h.Integer})],Vi.prototype,"version",void 0);Se([u({type:dr})],Vi.prototype,"authSafe",void 0);Se([u({type:So,optional:!0})],Vi.prototype,"macData",void 0);var Jy,ra=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Se([u({type:h.ObjectIdentifier})],ra.prototype,"bagId",void 0);Se([u({type:h.Any,context:0})],ra.prototype,"bagValue",void 0);Se([u({type:Ki,repeated:"set",optional:!0})],ra.prototype,"bagAttributes",void 0);var xv=Jy=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,Jy.prototype)}};xv=Jy=Se([S({type:_.Sequence,itemType:ra})],xv);var Qy,em,tm,Ge="1.2.840.113549.1.9",yq=`${Ge}.0`,jv=`${Ge}.24`,lu=`${Ge}.25`,Rv=`${Ge}.26`,Dv=`${Ge}.27`,mq=`${jv}.1`,gq=`${jv}.2`,wq=`${Ge}.1`,bq=`${Ge}.2`,xq=`${Ge}.3`,vq=`${Ge}.4`,_q=`${Ge}.5`,Aq=`${Ge}.6`,um=`${Ge}.7`,Sq=`${Ge}.8`,Eq=`${Ge}.9`,Tq=`${Ge}.13`,fu=`${Ge}.14`,Cq=`${Ge}.15`,Iq=`${Ge}.20`,Oq=`${Ge}.21`;var Bq=`${lu}.1`,Pq=`${lu}.2`,kq=`${lu}.3`,Nq=`${lu}.4`,jq=`${lu}.5`,pu="1.3.6.1.5.5.7.9",Rq=`${pu}.1`,Dq=`${pu}.2`,Lq=`${pu}.3`,Uq=`${pu}.4`,Mq=`${pu}.5`,Kq=`${Rv}.1`,Hq=`${Rv}.2`,Vq=`${Dv}.1`,$q=`${Dv}.2`,Fq=`${Ge}.16`,Wq=`${Ge}.22`,qq=`${Ge}.23`,Gq=`${vy}.65`,Qf=class extends et{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Ae([u({type:h.IA5String})],Qf.prototype,"ia5String",void 0);Qf=Ae([S({type:_.Choice})],Qf);var vv=class extends dr{};vv=Ae([S({type:_.Sequence})],vv);var _v=class extends Vi{};_v=Ae([S({type:_.Sequence})],_v);var Av=class extends _o{};Av=Ae([S({type:_.Sequence})],Av);var rm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ae([u({type:h.IA5String})],rm.prototype,"value",void 0);rm=Ae([S({type:_.Choice})],rm);var Sv=class extends Qf{};Sv=Ae([S({type:_.Choice})],Sv);var Ev=class extends et{};Ev=Ae([S({type:_.Choice})],Ev);var nm=class{constructor(e=new Date){this.value=e}};Ae([u({type:h.GeneralizedTime})],nm.prototype,"value",void 0);nm=Ae([S({type:_.Choice})],nm);var Tv=class extends et{};Tv=Ae([S({type:_.Choice})],Tv);var om=class{constructor(e="M"){this.value=e}toString(){return this.value}};Ae([u({type:h.PrintableString})],om.prototype,"value",void 0);om=Ae([S({type:_.Choice})],om);var ep=class{constructor(e=""){this.value=e}toString(){return this.value}};Ae([u({type:h.PrintableString})],ep.prototype,"value",void 0);ep=Ae([S({type:_.Choice})],ep);var Cv=class extends ep{};Cv=Ae([S({type:_.Choice})],Cv);var Iv=class extends et{};Iv=Ae([S({type:_.Choice})],Iv);var im=class{constructor(e=""){this.value=e}toString(){return this.value}};Ae([u({type:h.ObjectIdentifier})],im.prototype,"value",void 0);im=Ae([S({type:_.Choice})],im);var Ov=class extends qe{};Ov=Ae([S({type:_.Choice})],Ov);var sm=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Ae([u({type:h.Integer})],sm.prototype,"value",void 0);sm=Ae([S({type:_.Choice})],sm);var Bv=class extends Ft{};Bv=Ae([S({type:_.Sequence})],Bv);var uu=class extends et{};uu=Ae([S({type:_.Choice})],uu);var Pv=Qy=class extends er{constructor(e){super(e),Object.setPrototypeOf(this,Qy.prototype)}};Pv=Qy=Ae([S({type:_.Sequence})],Pv);var kv=em=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,em.prototype)}};kv=em=Ae([S({type:_.Set,itemType:Ur})],kv);var am=class{constructor(e=""){this.value=e}toString(){return this.value}};Ae([u({type:h.BmpString})],am.prototype,"value",void 0);am=Ae([S({type:_.Choice})],am);var cm=class extends H{};cm=Ae([S({type:_.Sequence})],cm);var Nv=tm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,tm.prototype)}};Nv=tm=Ae([S({type:_.Sequence,itemType:cm})],Nv);function Kr(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 lm,hu=lm=class extends oe{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};hu=lm=Kr([S({type:_.Sequence,itemType:ht})],hu);var un=class{constructor(e={}){this.version=0,this.subject=new Pe,this.subjectPKInfo=new dt,this.attributes=new hu,Object.assign(this,e)}};Kr([u({type:h.Integer})],un.prototype,"version",void 0);Kr([u({type:Pe})],un.prototype,"subject",void 0);Kr([u({type:dt})],un.prototype,"subjectPKInfo",void 0);Kr([u({type:hu,implicit:!0,context:0})],un.prototype,"attributes",void 0);var Eo=class{constructor(e={}){this.certificationRequestInfo=new un,this.signatureAlgorithm=new H,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Kr([u({type:un})],Eo.prototype,"certificationRequestInfo",void 0);Kr([u({type:H})],Eo.prototype,"signatureAlgorithm",void 0);Kr([u({type:h.BitString})],Eo.prototype,"signature",void 0);var bu="crypto.algorithm",xm=class{getAlgorithms(){return Ue.resolveAll(bu)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new H({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},$i="crypto.algorithmProvider";Ue.registerSingleton($i,xm);var op,Xt="1.3.36.3.3.2.8.1.1",Lv=`${Xt}.1`,Uv=`${Xt}.2`,Mv=`${Xt}.3`,Kv=`${Xt}.4`,Hv=`${Xt}.5`,Vv=`${Xt}.6`,$v=`${Xt}.7`,Fv=`${Xt}.8`,Wv=`${Xt}.9`,qv=`${Xt}.10`,Gv=`${Xt}.11`,zv=`${Xt}.12`,Xv=`${Xt}.13`,Zv=`${Xt}.14`,Yv="brainpoolP160r1",Jv="brainpoolP160t1",Qv="brainpoolP192r1",e1="brainpoolP192t1",t1="brainpoolP224r1",r1="brainpoolP224t1",n1="brainpoolP256r1",o1="brainpoolP256t1",i1="brainpoolP320r1",s1="brainpoolP320t1",a1="brainpoolP384r1",c1="brainpoolP384t1",u1="brainpoolP512r1",l1="brainpoolP512t1",$e="ECDSA",yu=op=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 Tx;case"sha-256":return Cx;case"sha-384":return Ix;case"sha-512":return Ox}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Py;break;case"K-256":t=op.SECP256K1;break;case"P-384":t=ky;break;case"P-521":t=Ny;break;case Yv:t=Lv;break;case Jv:t=Uv;break;case Qv:t=Mv;break;case e1:t=Kv;break;case t1:t=Hv;break;case r1:t=Vv;break;case n1:t=$v;break;case o1:t=Fv;break;case i1:t=Wv;break;case s1:t=qv;break;case a1:t=Gv;break;case c1:t=zv;break;case u1:t=Xv;break;case l1:t=Zv;break}if(t)return new H({algorithm:Pi,parameters:q.serialize(new sn({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Yc:return{name:$e,hash:{name:"SHA-1"}};case Jc:return{name:$e,hash:{name:"SHA-256"}};case Qc:return{name:$e,hash:{name:"SHA-384"}};case eu:return{name:$e,hash:{name:"SHA-512"}};case Pi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(q.parse(e.parameters,sn).namedCurve){case Py:return{name:$e,namedCurve:"P-256"};case op.SECP256K1:return{name:$e,namedCurve:"K-256"};case ky:return{name:$e,namedCurve:"P-384"};case Ny:return{name:$e,namedCurve:"P-521"};case Lv:return{name:$e,namedCurve:Yv};case Uv:return{name:$e,namedCurve:Jv};case Mv:return{name:$e,namedCurve:Qv};case Kv:return{name:$e,namedCurve:e1};case Hv:return{name:$e,namedCurve:t1};case Vv:return{name:$e,namedCurve:r1};case $v:return{name:$e,namedCurve:n1};case Fv:return{name:$e,namedCurve:o1};case Wv:return{name:$e,namedCurve:i1};case qv:return{name:$e,namedCurve:s1};case Gv:return{name:$e,namedCurve:a1};case zv:return{name:$e,namedCurve:c1};case Xv:return{name:$e,namedCurve:u1};case Zv:return{name:$e,namedCurve:l1}}}}return null}};yu.SECP256K1="1.3.132.0.10";yu=op=nu([vo()],yu);Ue.registerSingleton(bu,yu);var v1=Symbol("name"),_1=Symbol("value"),_e=class{constructor(e,t={},n=""){this[v1]=e,this[_1]=n;for(let o in t)this[o]=t[o]}};_e.NAME=v1;_e.VALUE=_1;var vm=class{static toTextObject(e){let t=new _e("Algorithm Identifier",{},fn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Pi:{let n=new yu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},fn=class{static toString(e){let t=this.items[e];return t||e}};fn.items={[Ni]:"sha1",[Kf]:"sha224",[ji]:"sha256",[Ri]:"sha384",[Di]:"sha512",[an]:"rsaEncryption",[qs]:"sha1WithRSAEncryption",[jx]:"sha224WithRSAEncryption",[Mf]:"sha256WithRSAEncryption",[Gs]:"sha384WithRSAEncryption",[zs]:"sha512WithRSAEncryption",[Pi]:"ecPublicKey",[Yc]:"ecdsaWithSHA1",[Uf]:"ecdsaWithSHA224",[Jc]:"ecdsaWithSHA256",[Qc]:"ecdsaWithSHA384",[eu]:"ecdsaWithSHA512",[sx]:"TLS WWW server authentication",[ax]:"TLS WWW client authentication",[cx]:"Code Signing",[ux]:"E-mail Protection",[lx]:"Time Stamping",[fx]:"OCSP Signing",[Sx]:"Signed Data"};var Ln=class{static serialize(e){return this.serializeObj(e).join(`
9
+ `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[_e.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[_e.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],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 p of c)p[_e.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof _e)c[_e.NAME]=a,n.push(...this.serializeObj(c,t));else if(V.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${l}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let p=c.toTextObject();p[_e.NAME]=a,n.push(...this.serializeObj(p,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=V.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let l=o[s++].toString(16).padStart(2,"0");a.push(l)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Ln.oidSerializer=fn;Ln.algorithmSerializer=vm;var To=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=q.serialize(t),this.onInit(t)}else{let t=q.parse(e[0],e[1]);this.rawData=V.BufferSourceConverter.toArrayBuffer(e[0]),this.onInit(t)}}equal(e){return e instanceof r?(0,V.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return q.toString(this.rawData);case"text":return Ln.serialize(this.toTextObject());case"hex":return V.Convert.ToHex(this.rawData);case"base64":return V.Convert.ToBase64(this.rawData);case"base64url":return V.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new _e(this.getTextName(),{},e)}};To.NAME="ASN";var gr=class r extends To{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=q.serialize(new yt({extnID:e[0],critical:e[1],extnValue:new ae(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,yt)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[_e.NAME]===r.NAME&&(e[_e.NAME]=fn.toString(this.type)),e}},A1,mu=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[A1]="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}};A1=Symbol.toStringTag;mu.DEFAULT="default";var bt=new mu,vT=/^[0-2](?:\.[1-9][0-9]*)+$/;function _T(r){return new RegExp(vT).test(r)}var sp=class{constructor(e={}){this.items={};for(let t in e)this.register(t,e[t])}get(e){return this.items[e]||null}findId(e){return _T(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Gt=new sp;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 AT(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function ST(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,AT)}var mr=class r{static isASCII(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new sp,this.asn=new Pe;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let o=t[n];this.extraNames.register(n,o)}typeof e=="string"?this.asn=this.fromString(e):e instanceof Pe?this.asn=e:V.BufferSourceConverter.isBufferSource(e)?this.asn=q.parse(e,Pe):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Gt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||Gt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${V.Convert.ToHex(t.value.anyValue)}`:ST(t.value.toString());return`${n}=${o}`}).join("+")).join(", ")}toJSON(){var e;let t=[];for(let n of this.asn){let o={};for(let i of n){let s=this.getName(i.type)||i.type;(e=o[s])!==null&&e!==void 0||(o[s]=[]),o[s].push(i.value.anyValue?`#${V.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new Pe,n=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g,o=null,i=",";for(;o=n.exec(`${e},`);){let[,s,a]=o,c=a[a.length-1];(c===","||c==="+")&&(a=a.slice(0,a.length-1),o[3]=c);let l=o[3];s=this.getTypeOid(s);let p=this.createAttribute(s,a);i==="+"?t[t.length-1].push(p):t.push(new so([p])),i=l}return t}fromJSON(e){let t=new Pe;for(let n of e){let o=new so;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 fi({type:e});if(typeof t=="object")for(let o in t)switch(o){case"ia5String":n.value.ia5String=t[o];break;case"utf8String":n.value.utf8String=t[o];break;case"universalString":n.value.universalString=t[o];break;case"bmpString":n.value.bmpString=t[o];break;case"printableString":n.value.printableString=t[o];break}else if(t[0]==="#")n.value.anyValue=V.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
10
+ `).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return q.serialize(this.asn)}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||bt.get()):n=e[0]||bt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},S1="Cannot initialize GeneralName from ASN.1 data.",f1=`${S1} Unsupported string format in use.`,ET=`${S1} Value doesn't match to GUID regular expression.`,p1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,h1="1.3.6.1.4.1.311.25.1",d1="1.3.6.1.4.1.311.20.2.3",fm="dns",pm="dn",hm="email",dm="ip",ym="url",mm="guid",gm="upn",tp="id",ln=class extends To{constructor(...e){let t;if(e.length===2)switch(e[0]){case pm:{let n=new mr(e[1]).toArrayBuffer(),o=q.parse(n,Pe);t=new le({directoryName:o});break}case fm:t=new le({dNSName:e[1]});break;case hm:t=new le({rfc822Name:e[1]});break;case mm:{let n=new RegExp(p1,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let o=n.slice(1).map((i,s)=>s<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(i)).reverse()):i).join("");t=new le({otherName:new ao({typeId:h1,value:q.serialize(new ae(V.Convert.FromHex(o)))})});break}case dm:t=new le({iPAddress:e[1]});break;case tp:t=new le({registeredID:e[1]});break;case gm:{t=new le({otherName:new ao({typeId:d1,value:q.serialize(Vd.toASN(e[1]))})});break}case ym:t=new le({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else V.BufferSourceConverter.isBufferSource(e[0])?t=q.parse(e[0],le):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=fm,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=hm,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=dm,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=ym,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=tp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=pm,this.value=new mr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===h1){this.type=mm;let t=q.parse(e.otherName.value,ae),n=new RegExp(p1,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(ET);this.value=n.slice(1).map((o,i)=>i<3?V.Convert.ToHex(new Uint8Array(V.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===d1)this.type=gm,this.value=q.parse(e.otherName.value,et).toString();else throw new Error(f1);else throw new Error(f1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case pm:case fm:case mm:case dm:case tp:case gm:case ym:e=this.type.toUpperCase();break;case hm:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===tp&&(t=fn.toString(t)),new _e(e,void 0,t)}},Fi=class extends To{constructor(e){let t;if(e instanceof Ve)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof le)n.push(o);else{let i=q.parse(new ln(o.type,o.value).rawData,le);n.push(i)}t=new Ve(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=q.parse(e,Ve);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new ln(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[_e.NAME]];Array.isArray(o)||(o=[],e[n[_e.NAME]]=o),o.push(n)}return e}};Fi.NAME="GeneralNames";var du="-{5}",gu="\\n",TT=`[^${gu}]+`,CT=`${du}BEGIN (${TT}(?=${du}))${du}`,IT=`${du}END \\1${du}`,na="\\n",OT=`[^:${gu}]+`,BT=`(?:[^${gu}]+${na}(?: +[^${gu}]+${na})*)`,PT="[a-zA-Z0-9=+/]+",kT=`(?:${PT}${na})+`,y1=`${CT}${na}(?:((?:${OT}: ${BT})+))?${na}?(${kT})${IT}`,Rt=class{static isPem(e){return typeof e=="string"&&new RegExp(y1,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(y1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${gu}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(na,"g")),l=null;for(let p of c){let[f,m]=p.split(/:(.*)/);if(m===void 0){if(!l)throw new Error("Cannot parse PEM string. Incorrect header value");l.value+=f.trim()}else l&&s.headers.push(l),l={key:f,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(!V.BufferSourceConverter.isBufferSource(o))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:t,rawData:V.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
11
+ `)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:V.BufferSourceConverter.toArrayBuffer(e)})}}static encodeStruct(e){var t;let n=e.type.toLocaleUpperCase(),o=[];if(o.push(`-----BEGIN ${n}-----`),!((t=e.headers)===null||t===void 0)&&t.length){for(let l of e.headers)o.push(`${l.key}: ${l.value}`);o.push("")}let i=V.Convert.ToBase64(e.rawData),s,a=0,c=Array();for(;a<i.length&&(i.length-a<64?s=i.substring(a):(s=i.substring(a,a+64),a+=64),s.length!==0);)if(c.push(s),s.length<64)break;return o.push(...c),o.push(`-----END ${n}-----`),o.join(`
12
+ `)}};Rt.CertificateTag="CERTIFICATE";Rt.CrlTag="CRL";Rt.CertificateRequestTag="CERTIFICATE REQUEST";Rt.PublicKeyTag="PUBLIC KEY";Rt.PrivateKeyTag="PRIVATE KEY";var Co=class r extends To{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Rt.isPem(e))return Rt.decode(e)[0];if(V.Convert.isHex(e))return V.Convert.FromHex(e);if(V.Convert.isBase64(e))return V.Convert.FromBase64(e);if(V.Convert.isBase64Url(e))return V.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=V.Convert.ToBinary(e);return Rt.isPem(t)?Rt.decode(t)[0]:V.Convert.isHex(t)?V.Convert.FromHex(t):V.Convert.isBase64(t)?V.Convert.FromBase64(t):V.Convert.isBase64Url(t)?V.Convert.FromBase64Url(t):V.BufferSourceConverter.toArrayBuffer(e)}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Rt.encode(this.rawData,this.tag);default:return super.toString(e)}}},Dn=class r extends Co{static async create(e,t=bt.get()){if(e instanceof r)return e;if(mu.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(V.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){Co.isAsnEncoded(e)?super(e,dt):super(e),this.tag=Rt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||bt.get()):t=e[0]||bt.get();let i=this.rawData,s=q.parse(this.rawData,dt);return s.algorithm.algorithm===wo&&(i=NT(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Ue.resolve($i),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case an:{let o=q.parse(e.subjectPublicKey,Ys),i=V.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=V.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||bt.get()):n=e[0]||bt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=bt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=bt.get();let o=q.parse(this.rawData,dt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,dt);switch(e.Algorithm=Ln.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Pi:e["EC Point"]=t.subjectPublicKey;break;case an:default:e["Raw Data"]=t.subjectPublicKey}return e}};function NT(r,e){return r.algorithm=new H({algorithm:an,parameters:null}),e=q.serialize(r),e}var ap=class r extends gr{static async create(e,t=!1,n=bt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Dn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new tn({keyIdentifier:new di(V.Convert.FromHex(e[0]))});super(gf,e[1],q.serialize(t))}else{let t=e[0],n=t.name instanceof Fi?q.parse(t.name.rawData,Ve):t.name,o=new tn({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(gf,e[1],q.serialize(o))}}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,tn);t.keyIdentifier&&(this.keyId=V.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?V.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,tn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Fi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};ap.NAME="Authority Key Identifier";var oa=class extends gr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,yi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new yi({cA:e[0],pathLenConstraint:e[1]});super(wf,e[2],q.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};oa.NAME="Basic Constraints";var m1;(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"})(m1||(m1={}));var cp=class extends gr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,kc);this.usages=t.map(n=>n)}else{let t=new kc(e[0]);super(_f,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>fn.toString(t)).join(", "),e}};cp.NAME="Extended Key Usages";var g1;(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"})(g1||(g1={}));var up=class extends gr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Os);this.usages=t.toNumber()}else{let t=new Os(e[0]);super(Af,e[1],q.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,Os);return e[""]=t.toJSON().join(", "),e}};up.NAME="Key Usages";var lp=class r extends gr{static async create(e,t=!1,n=bt.get()){let i=await(await Dn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=q.parse(this.value,Vt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new Vt(t);super(dy,e[1],q.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=q.parse(this.value,Vt);return e[""]=t,e}};lp.NAME="Subject Key Identifier";var fp=class extends gr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(py,e[1],new Fi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,Cf);this.names=new Fi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};fp.NAME="Subject Alternative Name";var zt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new gr(e),n=this.items.get(t.type);return n?new n(e):t}};zt.items=new Map;var pp=class extends gr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=q.parse(this.value,Cc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Cc(n.map(s=>new mi({policyIdentifier:s})));super(xf,o,q.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new _e("",{},fn.toString(t))),e}};pp.NAME="Certificate Policies";zt.register(xf,pp);var hp=class extends gr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new rn({distributionPoint:new On({fullName:[new le({uniformResourceIdentifier:s})]})})),i=new lo(o);super(vf,e[1],q.serialize(i))}else{let n=new lo(e[0]);super(vf,e[1],q.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=q.parse(e.extnValue,lo);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new ln(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};hp.NAME="CRL Distribution Points";var dp=class extends gr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof hi){let s=new hi(e[0]);super(mf,e[1],q.serialize(s))}else{let s=e[0],a=new hi;np(a,s,Zd,"ocsp"),np(a,s,Yd,"caIssuers"),np(a,s,Jd,"timeStamping"),np(a,s,Qd,"caRepository"),super(mf,e[1],q.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],q.parse(e.extnValue,hi).forEach(n=>{switch(n.accessMethod){case Zd:this.ocsp.push(new ln(n.accessLocation));break;case Yd:this.caIssuers.push(new ln(n.accessLocation));break;case Jd:this.timeStamping.push(new ln(n.accessLocation));break;case Qd:this.caRepository.push(new ln(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&rp(e,"OCSP",this.ocsp),this.caIssuers.length&&rp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&rp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&rp(e,"CA Repository",this.caRepository),e}};dp.NAME="Authority Info Access";function rp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new _e("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[_e.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function np(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new ln("url",s)),r.push(new Cn({accessMethod:t,accessLocation:q.parse(s.rawData,le)}))})}var ia=class r extends To{constructor(...e){let t;if(V.BufferSourceConverter.isBufferSource(e[0]))t=V.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>V.BufferSourceConverter.toArrayBuffer(i)):[];t=q.serialize(new ht({type:n,values:o}))}super(t,ht)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new _e("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[_e.NAME]===r.NAME&&(e[_e.NAME]=fn.toString(this.type)),e}};ia.NAME="Attribute";var yp=class extends ia{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new uu({printableString:e[0]});super(um,[q.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],uu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[_e.VALUE]=this.password,e}};yp.NAME="Challenge Password";var wu=class extends ia{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new er;for(let i of n)o.push(q.parse(i.rawData,yt));super(fu,[q.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=q.parse(this.values[0],er);this.items=t.map(n=>zt.create(q.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[_e.NAME]]=n;return e}};wu.NAME="Extensions";var sa=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ia(e),n=this.items.get(t.type);return n?new n(e):t}};sa.items=new Map;var xu="crypto.signatureFormatter",_m=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},ip,Am=ip=class{static createPssParams(e,t){let n=ip.getHashAlgorithm(e);return n?new cn({hashAlgorithm:n,maskGenAlgorithm:new H({algorithm:bo,parameters:q.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Ue.resolve($i);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new H({algorithm:qs,parameters:null});case"sha-256":return new H({algorithm:Mf,parameters:null});case"sha-384":return new H({algorithm:Gs,parameters:null});case"sha-512":return new H({algorithm:zs,parameters:null})}}else return new H({algorithm:an,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let t=ip.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new H({algorithm:wo,parameters:q.serialize(t)})}else return new H({algorithm:wo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case an:return{name:"RSASSA-PKCS1-v1_5"};case qs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Mf:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Gs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case zs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case wo:if(e.parameters){let t=q.parse(e.parameters,cn);return{name:"RSA-PSS",hash:Ue.resolve($i).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Am=ip=nu([vo()],Am);Ue.registerSingleton(bu,Am);var Sm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new H({algorithm:Ni});case"sha-256":return new H({algorithm:ji});case"sha-384":return new H({algorithm:Ri});case"sha-512":return new H({algorithm:Di})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ni:return{name:"SHA-1"};case ji:return{name:"SHA-256"};case Ri:return{name:"SHA-384"};case Di:return{name:"SHA-512"}}return null}};Sm=nu([vo()],Sm);Ue.registerSingleton(bu,Sm);var Un=class r{addPadding(e,t){let n=V.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o}removePadding(e,t=!1){let n=V.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new ki,s=V.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),q.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=q.parse(t,ki),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,V.combine)(s,a)}return null}};Un.namedCurveSize=new Map;Un.defaultNamedCurveSize=32;var wm="1.3.101.110",w1="1.3.101.111",bm="1.3.101.112",b1="1.3.101.113",Em=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=bm;break;case"x25519":t=wm;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=bm;break;case"ed448":t=b1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=wm;break;case"x448":t=w1;break}}return t?new H({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case bm:return{name:"Ed25519"};case b1:return{name:"EdDSA",namedCurve:"Ed448"};case wm:return{name:"X25519"};case w1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Em=nu([vo()],Em);Ue.registerSingleton(bu,Em);var Tm=class extends Co{constructor(e){Co.isAsnEncoded(e)?super(e,Eo):super(e),this.tag=Rt.CertificateRequestTag}onInit(e){this.tbs=q.serialize(e.certificationRequestInfo),this.publicKey=new Dn(e.certificationRequestInfo.subjectPKInfo);let t=Ue.resolve($i);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>sa.create(q.serialize(o)));let n=this.getAttribute(fu);this.extensions=[],n instanceof wu&&(this.extensions=n.items),this.subjectName=new mr(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=bt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Ue.resolveAll(xu).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,Eo),n=t.certificationRequestInfo,o=new _e("",{Version:`${nn[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new _e("");for(let s of this.attributes){let a=s.toTextObject();i[a[_e.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new _e("",{Algorithm:Ln.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Tm.NAME="PKCS#10 Certificate Request";var aa=class extends Co{constructor(e){Co.isAsnEncoded(e)?super(e,fr):super(e),this.tag=Rt.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=q.serialize(t);let n=new Uint8Array(t.serialNumber);n.length>1&&n[0]===0&&n[1]>127&&(n=n.slice(1)),this.serialNumber=V.Convert.ToHex(n),this.subjectName=new mr(t.subject),this.subject=new mr(t.subject).toString(),this.issuerName=new mr(t.issuer),this.issuer=this.issuerName.toString();let o=Ue.resolve($i);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=>zt.create(q.serialize(a)))),this.publicKey=new Dn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=bt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Dn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let l=new Dn(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=Ue.resolveAll(xu).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 p=(e.date||new Date).getTime();return c&&this.notBefore.getTime()<p&&p<this.notAfter.getTime()}}async getThumbprint(...e){let t,n="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(n=e[0]||n,t=e[1])),t??(t=bt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=bt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=q.parse(this.rawData,fr),n=t.tbsCertificate,o=new _e("",{Version:`${nn[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Ln.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new _e("",{"Not Before":n.validity.notBefore.getTime(),"Not After":n.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(n.issuerUniqueID&&(o["Issuer Unique ID"]=n.issuerUniqueID),n.subjectUniqueID&&(o["Subject Unique ID"]=n.subjectUniqueID),this.extensions.length){let i=new _e("");for(let s of this.extensions){let a=s.toTextObject();i[a[_e.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new _e("",{Algorithm:Ln.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};aa.NAME="Certificate";var mp=class{static async createSelfSigned(e,t=bt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=bt.get()){var n;let o;e.publicKey instanceof Dn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:V.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=e.serialNumber?V.BufferSourceConverter.toUint8Array(V.Convert.FromHex(e.serialNumber)):t.getRandomValues(new Uint8Array(16));if(i[0]>127){let d=new Uint8Array(i.length+1);d[0]=0,d.set(i,1),i=d}let s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new fr({tbsCertificate:new mt({version:nn.v3,serialNumber:i,validity:new Bn({notBefore:s,notAfter:a}),extensions:new er(((n=e.extensions)===null||n===void 0?void 0:n.map(d=>q.parse(d.rawData,yt)))||[]),subjectPublicKeyInfo:q.parse(o,dt)})});if(e.subject){let d=e.subject instanceof mr?e.subject:new mr(e.subject);c.tbsCertificate.subject=q.parse(d.toArrayBuffer(),Pe)}if(e.issuer){let d=e.issuer instanceof mr?e.issuer:new mr(e.issuer);c.tbsCertificate.issuer=q.parse(d.toArrayBuffer(),Pe)}let l={hash:"SHA-256"},p="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},f=Ue.resolve($i);c.tbsCertificate.signature=c.signatureAlgorithm=f.toAsnAlgorithm(p);let m=q.serialize(c.tbsCertificate),y="signingKey"in e?await t.subtle.sign(p,e.signingKey,m):e.signature,b=Ue.resolveAll(xu).reverse(),v=null;for(let d of b)if(v=d.toAsnSignature(p,y),v)break;if(!v)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=v,new aa(q.serialize(c))}},x1;(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"})(x1||(x1={}));zt.register(wf,oa);zt.register(_f,cp);zt.register(Af,up);zt.register(dy,lp);zt.register(gf,ap);zt.register(py,fp);zt.register(vf,hp);zt.register(mf,dp);sa.register(um,yp);sa.register(fu,wu);Ue.registerSingleton(xu,_m);Ue.registerSingleton(xu,Un);Un.namedCurveSize.set("P-256",32);Un.namedCurveSize.set("K-256",32);Un.namedCurveSize.set("P-384",48);Un.namedCurveSize.set("P-521",66);var Mn="/",E1=new TextEncoder().encode(Mn),gp=E1[0],vu=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]!==gp)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(Mn))}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=E1),this._buf[0]!==gp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(gp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===gp;)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(Mn).slice(1)}type(){return jT(this.baseNamespace())}name(){return RT(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Mn)||(e+=Mn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Mn):new r(e.slice(0,-1).join(Mn))}child(e){return this.toString()===Mn?e:e.toString()===Mn?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(),...DT(e.map(t=>t.namespaces()))])}};function jT(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function RT(r){let e=r.split(":");return e[e.length-1]}function DT(r){return[].concat(...r)}var wp=class extends $n{async listen(){throw new Vl("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Cm(){let r=Je(),e=!1;return{sink:async t=>{if(e)throw new Error("already piped");e=!0,r.resolve(t)},source:async function*(){yield*await r.promise}()}}function T1(){let r=Cm(),e=Cm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function LT(r){return r[Symbol.asyncIterator]!=null}async function UT(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*MT(r){let e=new AbortController,t=Rl();UT(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*KT(r){for(let e of r)yield*e}function HT(...r){let e=[];for(let t of r)LT(t)||e.push(t);return e.length===r.length?KT(e):MT(r)}var C1=HT;function I1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Im(r)){let n=r;r=()=>n.source}else if(B1(r)||O1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Im(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++)Im(t[n])&&(t[n]=$T(t[n]));return VT(...t)}var VT=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},O1=r=>r?.[Symbol.asyncIterator]!=null,B1=r=>r?.[Symbol.iterator]!=null,Im=r=>r==null?!1:r.sink!=null&&r.source!=null,$T=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=bs({objectMode:!0});t.then(()=>{n.end()},s=>{n.end(s)});let o,i=r.source;if(O1(i))o=async function*(){yield*i,n.end()};else if(B1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return C1(n,o())}return r.source};var ca=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function k1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function bp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function xp(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ot(r,...e){if(!k1(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 Om(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 N1(r,e){Ot(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Kn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Hn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function FT(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var WT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function qT(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function vp(r){if(typeof r=="string")r=qT(r);else if(k1(r))r=_p(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function j1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function R1(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 Bm=(r,e)=>{function t(n,...o){if(Ot(n),!WT)throw new Error("Non little-endian hardware is not yet supported");if(r.nonceLength!==void 0){let p=o[0];if(!p)throw new Error("nonce / iv required");r.varSizeNonce?Ot(p):Ot(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Ot(o[1]);let s=e(n,...o),a=(p,f)=>{if(f!==void 0){if(p!==2)throw new Error("cipher output not supported");Ot(f)}},c=!1;return{encrypt(p,f){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Ot(p),a(s.encrypt.length,f),s.encrypt(p,f)},decrypt(p,f){if(Ot(p),i&&p.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,f),s.decrypt(p,f)}}}return Object.assign(t,r),t};function Pm(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&&!GT(e))throw new Error("invalid output, must be aligned");return e}function P1(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 D1(r,e,t){bp(t);let n=new Uint8Array(16),o=FT(n);return P1(o,0,BigInt(e),t),P1(o,8,BigInt(r),t),n}function GT(r){return r.byteOffset%4===0}function _p(r){return Uint8Array.from(r)}var U1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),zT=U1("expand 16-byte k"),XT=U1("expand 32-byte k"),ZT=Kn(zT),YT=Kn(XT);function te(r,e){return r<<e|r>>>32-e}function km(r){return r.byteOffset%4===0}var Ap=64,JT=16,M1=2**32-1,L1=new Uint32Array;function QT(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(Ap),p=Kn(l),f=km(o)&&km(i),m=f?Kn(o):L1,y=f?Kn(i):L1;for(let b=0;b<c;s++){if(r(e,t,n,p,s,a),s>=M1)throw new Error("arx: counter overflow");let v=Math.min(Ap,c-b);if(f&&v===Ap){let d=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let T=0,D;T<JT;T++)D=d+T,y[D]=m[D]^p[T];b+=Ap;continue}for(let d=0,T;d<v;d++)T=b+d,i[T]=o[T]^l[d];b+=v}}function Nm(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=j1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return xp(o),xp(s),bp(i),bp(t),(a,c,l,p,f=0)=>{Ot(a),Ot(c),Ot(l);let m=l.length;if(p===void 0&&(p=new Uint8Array(m)),Ot(p),xp(f),f<0||f>=M1)throw new Error("arx: counter overflow");if(p.length<m)throw new Error(`arx: output (${p.length}) is shorter than data (${m})`);let y=[],b=a.length,v,d;if(b===32)y.push(v=_p(a)),d=YT;else if(b===16&&t)v=new Uint8Array(32),v.set(a),v.set(a,16),d=ZT,y.push(v);else throw new Error(`arx: invalid 32-byte key, got length=${b}`);km(c)||y.push(c=_p(c));let T=Kn(v);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(d,T,Kn(c.subarray(0,16)),T),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let Z=new Uint8Array(12);Z.set(c,i?0:12-c.length),c=Z,y.push(c)}let j=Kn(c);return QT(r,d,T,j,l,p,f,s),Hn(...y),p}}var xt=(r,e)=>r[e++]&255|(r[e++]&255)<<8,jm=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=vp(e),Ot(e,32);let t=xt(e,0),n=xt(e,2),o=xt(e,4),i=xt(e,6),s=xt(e,8),a=xt(e,10),c=xt(e,12),l=xt(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let p=0;p<8;p++)this.pad[p]=xt(e,16+2*p)}process(e,t,n=!1){let o=n?0:2048,{h:i,r:s}=this,a=s[0],c=s[1],l=s[2],p=s[3],f=s[4],m=s[5],y=s[6],b=s[7],v=s[8],d=s[9],T=xt(e,t+0),D=xt(e,t+2),j=xt(e,t+4),Z=xt(e,t+6),B=xt(e,t+8),G=xt(e,t+10),M=xt(e,t+12),K=xt(e,t+14),g=i[0]+(T&8191),I=i[1]+((T>>>13|D<<3)&8191),E=i[2]+((D>>>10|j<<6)&8191),O=i[3]+((j>>>7|Z<<9)&8191),P=i[4]+((Z>>>4|B<<12)&8191),R=i[5]+(B>>>1&8191),N=i[6]+((B>>>14|G<<2)&8191),L=i[7]+((G>>>11|M<<5)&8191),F=i[8]+((M>>>8|K<<8)&8191),X=i[9]+(K>>>5|o),W=0,ie=W+g*a+I*(5*d)+E*(5*v)+O*(5*b)+P*(5*y);W=ie>>>13,ie&=8191,ie+=R*(5*m)+N*(5*f)+L*(5*p)+F*(5*l)+X*(5*c),W+=ie>>>13,ie&=8191;let Y=W+g*c+I*a+E*(5*d)+O*(5*v)+P*(5*b);W=Y>>>13,Y&=8191,Y+=R*(5*y)+N*(5*m)+L*(5*f)+F*(5*p)+X*(5*l),W+=Y>>>13,Y&=8191;let U=W+g*l+I*c+E*a+O*(5*d)+P*(5*v);W=U>>>13,U&=8191,U+=R*(5*b)+N*(5*y)+L*(5*m)+F*(5*f)+X*(5*p),W+=U>>>13,U&=8191;let he=W+g*p+I*l+E*c+O*a+P*(5*d);W=he>>>13,he&=8191,he+=R*(5*v)+N*(5*b)+L*(5*y)+F*(5*m)+X*(5*f),W+=he>>>13,he&=8191;let Oe=W+g*f+I*p+E*l+O*c+P*a;W=Oe>>>13,Oe&=8191,Oe+=R*(5*d)+N*(5*v)+L*(5*b)+F*(5*y)+X*(5*m),W+=Oe>>>13,Oe&=8191;let se=W+g*m+I*f+E*p+O*l+P*c;W=se>>>13,se&=8191,se+=R*a+N*(5*d)+L*(5*v)+F*(5*b)+X*(5*y),W+=se>>>13,se&=8191;let Re=W+g*y+I*m+E*f+O*p+P*l;W=Re>>>13,Re&=8191,Re+=R*c+N*a+L*(5*d)+F*(5*v)+X*(5*b),W+=Re>>>13,Re&=8191;let vt=W+g*b+I*y+E*m+O*f+P*p;W=vt>>>13,vt&=8191,vt+=R*l+N*c+L*a+F*(5*d)+X*(5*v),W+=vt>>>13,vt&=8191;let tt=W+g*v+I*b+E*y+O*m+P*f;W=tt>>>13,tt&=8191,tt+=R*p+N*l+L*c+F*a+X*(5*d),W+=tt>>>13,tt&=8191;let rt=W+g*d+I*v+E*b+O*y+P*m;W=rt>>>13,rt&=8191,rt+=R*f+N*p+L*l+F*c+X*a,W+=rt>>>13,rt&=8191,W=(W<<2)+W|0,W=W+ie|0,ie=W&8191,W=W>>>13,Y+=W,i[0]=ie,i[1]=Y,i[2]=U,i[3]=he,i[4]=Oe,i[5]=se,i[6]=Re,i[7]=vt,i[8]=tt,i[9]=rt}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;Hn(n)}update(e){Om(this),e=vp(e),Ot(e);let{buffer:t,blockLen:n}=this,o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){Hn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Om(this),N1(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 eC(r){let e=(n,o)=>r(o).update(vp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var K1=eC(r=>new jm(r));function $1(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],l=r[3],p=e[0],f=e[1],m=e[2],y=e[3],b=e[4],v=e[5],d=e[6],T=e[7],D=o,j=t[0],Z=t[1],B=t[2],G=s,M=a,K=c,g=l,I=p,E=f,O=m,P=y,R=b,N=v,L=d,F=T,X=D,W=j,ie=Z,Y=B;for(let he=0;he<i;he+=2)G=G+I|0,X=te(X^G,16),R=R+X|0,I=te(I^R,12),G=G+I|0,X=te(X^G,8),R=R+X|0,I=te(I^R,7),M=M+E|0,W=te(W^M,16),N=N+W|0,E=te(E^N,12),M=M+E|0,W=te(W^M,8),N=N+W|0,E=te(E^N,7),K=K+O|0,ie=te(ie^K,16),L=L+ie|0,O=te(O^L,12),K=K+O|0,ie=te(ie^K,8),L=L+ie|0,O=te(O^L,7),g=g+P|0,Y=te(Y^g,16),F=F+Y|0,P=te(P^F,12),g=g+P|0,Y=te(Y^g,8),F=F+Y|0,P=te(P^F,7),G=G+E|0,Y=te(Y^G,16),L=L+Y|0,E=te(E^L,12),G=G+E|0,Y=te(Y^G,8),L=L+Y|0,E=te(E^L,7),M=M+O|0,X=te(X^M,16),F=F+X|0,O=te(O^F,12),M=M+O|0,X=te(X^M,8),F=F+X|0,O=te(O^F,7),K=K+P|0,W=te(W^K,16),R=R+W|0,P=te(P^R,12),K=K+P|0,W=te(W^K,8),R=R+W|0,P=te(P^R,7),g=g+I|0,ie=te(ie^g,16),N=N+ie|0,I=te(I^N,12),g=g+I|0,ie=te(ie^g,8),N=N+ie|0,I=te(I^N,7);let U=0;n[U++]=s+G|0,n[U++]=a+M|0,n[U++]=c+K|0,n[U++]=l+g|0,n[U++]=p+I|0,n[U++]=f+E|0,n[U++]=m+O|0,n[U++]=y+P|0,n[U++]=b+R|0,n[U++]=v+N|0,n[U++]=d+L|0,n[U++]=T+F|0,n[U++]=D+X|0,n[U++]=j+W|0,n[U++]=Z+ie|0,n[U++]=B+Y|0}function tC(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],l=e[1],p=e[2],f=e[3],m=e[4],y=e[5],b=e[6],v=e[7],d=t[0],T=t[1],D=t[2],j=t[3];for(let B=0;B<20;B+=2)o=o+c|0,d=te(d^o,16),m=m+d|0,c=te(c^m,12),o=o+c|0,d=te(d^o,8),m=m+d|0,c=te(c^m,7),i=i+l|0,T=te(T^i,16),y=y+T|0,l=te(l^y,12),i=i+l|0,T=te(T^i,8),y=y+T|0,l=te(l^y,7),s=s+p|0,D=te(D^s,16),b=b+D|0,p=te(p^b,12),s=s+p|0,D=te(D^s,8),b=b+D|0,p=te(p^b,7),a=a+f|0,j=te(j^a,16),v=v+j|0,f=te(f^v,12),a=a+f|0,j=te(j^a,8),v=v+j|0,f=te(f^v,7),o=o+l|0,j=te(j^o,16),b=b+j|0,l=te(l^b,12),o=o+l|0,j=te(j^o,8),b=b+j|0,l=te(l^b,7),i=i+p|0,d=te(d^i,16),v=v+d|0,p=te(p^v,12),i=i+p|0,d=te(d^i,8),v=v+d|0,p=te(p^v,7),s=s+f|0,T=te(T^s,16),m=m+T|0,f=te(f^m,12),s=s+f|0,T=te(T^s,8),m=m+T|0,f=te(f^m,7),a=a+c|0,D=te(D^a,16),y=y+D|0,c=te(c^y,12),a=a+c|0,D=te(D^a,8),y=y+D|0,c=te(c^y,7);let Z=0;n[Z++]=o,n[Z++]=i,n[Z++]=s,n[Z++]=a,n[Z++]=d,n[Z++]=T,n[Z++]=D,n[Z++]=j}var rC=Nm($1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),nC=Nm($1,{counterRight:!1,counterLength:8,extendNonceFn:tC,allowShortKeys:!1});var oC=new Uint8Array(16),H1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(oC.subarray(t))},iC=new Uint8Array(32);function V1(r,e,t,n,o){let i=r(e,t,iC),s=K1.create(i);o&&H1(s,o),H1(s,n);let a=D1(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Hn(i,a),c}var F1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Pm(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=V1(r,e,t,c,n);return s.set(l,a),Hn(l),s},decrypt(i,s){s=Pm(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=V1(r,e,t,a,n);if(!R1(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Hn(l),s}}),Rm=Bm({blockSize:64,nonceLength:12,tagLength:16},F1(rC)),Ez=Bm({blockSize:64,nonceLength:24,tagLength:16},F1(nC));function q1(r,e,t){return va(r),t===void 0&&(t=new Uint8Array(r.outputLen)),fs(r,Gn(t),Gn(e))}var Dm=Uint8Array.from([0]),W1=Uint8Array.of();function G1(r,e,t,n=32){va(r),Ro(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=W1);let s=new Uint8Array(i*o),a=fs.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Dm[0]=p+1,c.update(p===0?W1:l).update(t).update(Dm).digestInto(l),s.set(l,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),vr(l,Dm),s.slice(0,n)}var Lm={hashSHA256(r){return Qn(r.subarray())},getHKDF(r,e){let t=q1(Qn,e,r),o=G1(Qn,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=Ba.utils.randomPrivateKey();return{publicKey:Ba.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Ba.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Ba.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Rm(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Rm(n,e,t).decrypt(r.subarray(),o)}};var z1=Lm;function X1(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 ua=r=>{let e=it(2);return e[0]=r>>8,e[1]=r,e};ua.bytes=2;var _u=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)};_u.bytes=2;function Z1(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 Um(r,e){!e.enabled||!ca||(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 Mm(r,e){!e.enabled||!ca||(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 Y1(r,e){!e.enabled||!ca||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote static public key.")}function Km(r,e){!e.enabled||!ca||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ce(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Hm(r,e,t){!t.enabled||!ca||(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 la=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var sC=0,aC=4294967295,cC="Cipherstate has reached maximum n, a new handshake must be performed",Sp=class{n;bytes;view;constructor(e=sC){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>aC)throw new Error(cC)}};var Wi=ot(0),fa=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Sp(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}},Vm=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=pe(t,"utf-8");this.h=uC(e,n),this.ck=this.h,this.cs=new fa(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new fa(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new be(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,Wi);return[new fa(this.crypto,e),new fa(this.crypto,t)]}},$m=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 Vm(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()}},Au=class extends $m{writeMessageA(e){return new be(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new be(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new be(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new la(`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 la(`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 la(`handshake stage 2 validation fail: ${t.message}`)}}};function uC(r,e){if(e.length<=32){let t=ot(32);return t.set(e),t}else return r.hash(e)}var Ep;(function(r){let e;r.codec=()=>(e==null&&(e=Or((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 Ua('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 Ua('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=>Ir(t,r.codec()),r.decode=(t,n)=>Cr(t,r.codec(),n)})(Ep||(Ep={}));var Su;(function(r){let e;r.codec=()=>(e==null&&(e=Or((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),Ep.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=Ep.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Ir(t,r.codec()),r.decode=(t,n)=>Cr(t,r.codec(),n)})(Su||(Su={}));async function Fm(r,e,t){let n=await r.sign(J1(e));return Su.encode({identityKey:qn(r.publicKey),identitySig:n,extensions:t})}async function Wm(r,e,t){try{let n=Su.decode(r),o=Fa(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=J1(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Iu(n.message)}}function J1(r){let e=pe("noise-libp2p-static-key:");return r instanceof Uint8Array?st([e,r],e.length+r.length):(r.prepend(e),r)}async function Q1(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,p=await Fm(i,a.publicKey,l),f=new Au({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Um(f.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(f.writeMessageA(Wi),e),t.trace("Stage 0 - Initiator finished sending first message."),Mm(f.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let m=f.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Km(f.re,t),Y1(f.rs,t),t.trace("Initiator going to check remote's signature...");let y=await Wm(m,f.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(f.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[b,v]=f.ss.split();return Hm(b,v,t),{payload:y,encrypt:d=>b.encryptWithAd(Wi,d),decrypt:(d,T)=>v.decryptWithAd(Wi,d,T)}}async function e_(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,p=await Fm(i,a.publicKey,l),f=new Au({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Um(f.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),f.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),Km(f.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(f.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Mm(f.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let m=f.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let y=await Wm(m,f.rs,c),[b,v]=f.ss.split();return Hm(b,v,t),{payload:y,encrypt:d=>v.encryptWithAd(Wi,d),decrypt:(d,T)=>b.decryptWithAd(Wi,d,T)}}var r_=16;function n_(r,e){return async function*(t){for await(let n of t)for(let o=0;o<n.length;o+=65519){let i=o+65519;i>n.length&&(i=n.length);let s;n instanceof Uint8Array?s=r.encrypt(n.subarray(o,i)):s=r.encrypt(n.sublist(o,i)),e?.encryptedPackets.increment(),yield new be(ua(s.byteLength),s)}}}function o_(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-r_<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-r_);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var Tp=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??z1;this.crypto=X1(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?Z1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ot(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[zi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=oc(e,{lengthEncoder:ua,lengthDecoder:_u,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=Fa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ed(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 Ou("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=oc(e,{lengthEncoder:ua,lengthDecoder:_u,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=Fa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ed(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 Q1({connection:e,privateKey:t,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers: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 e_({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]=T1(),i=e.unwrap();return await I1(n,n_(t,this.metrics),i,s=>zo(s,{lengthDecoder:_u}),o_(t,this.metrics),n),o}};function i_(r={}){return e=>new Tp(e,r)}var qm=Object.values(ko).map(r=>r.decoder).reduce((r,e)=>r.or(e)),lC=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function s_(r){return r?.match(lC)?.groups?.fingerprint}function Gm(r){let t=r.stringTuples().filter(n=>n[0]===jw).map(n=>n[1])[0];if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function fC(r){return nr.decode(qm.decode(r))}function pC(r){let e=fC(Gm(r)),t=hC(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 Hl(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function a_(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=At(or.code,t);return Xr(`/certhash/${Po.encode(n.bytes)}`)}function hC(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new $l(r)}}function c_(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=pC(r);return{type:"answer",sdp:`v=0
13
13
  o=- 0 0 IN IP${o} ${t}
14
14
  s=-
15
15
  t=0 0
@@ -23,10 +23,10 @@ a=ice-pwd:${e}
23
23
  a=fingerprint:${i}
24
24
  a=setup:passive
25
25
  a=sctp-port:5000
26
- a=max-message-size:${ls}
26
+ a=max-message-size:${gs}
27
27
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
28
28
  a=end-of-candidates
29
- `}}function eA(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
29
+ `}}function u_(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
30
30
  o=- 0 0 IN IP${o} ${t}
31
31
  s=-
32
32
  c=IN IP${o} ${t}
@@ -39,16 +39,16 @@ a=ice-ufrag:${e}
39
39
  a=ice-pwd:${e}
40
40
  a=fingerprint:sha-256 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
41
41
  a=sctp-port:5000
42
- a=max-message-size:${ls}
42
+ a=max-message-size:${gs}
43
43
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
44
44
  a=end-of-candidates
45
- `}}function zy(r,e){if(r.sdp===void 0)throw new Ae("Can't munge a missing SDP");let t=r.sdp.includes(`\r
45
+ `}}function zm(r,e){if(r.sdp===void 0)throw new ve("Can't munge a missing SDP");let t=r.sdp.includes(`\r
46
46
  `)?`\r
47
47
  `:`
48
48
  `;return r.sdp=r.sdp.replace(/\na=ice-ufrag:[^\n]*\n/,`
49
49
  a=ice-ufrag:`+e+t).replace(/\na=ice-pwd:[^\n]*\n/,`
50
- a=ice-pwd:`+e+t),r}var Xy=de("libp2p-webrtc-noise:");function rA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=de(n,"hex"),i=vt(tr.code,o),s=qy.decode(Gy(e)),a=Xy.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?ot([Xy,s,i.bytes],a):ot([Xy,i.bytes,s],a)}var XC=za?"iceconnectionstatechange":"connectionstatechange";async function nA(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=zy(p,e);t.log.trace("client setting local offer %s",m.sdp),await r.setLocalDescription(m);let v=Q1(t.remoteAddr,e);t.log.trace("client setting server description %s",v.sdp),await r.setRemoteDescription(v)}else{let p=eA(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 v=zy(m,e);t.log.trace("server setting local description %s",m.sdp),await r.setLocalDescription(v)}if(n.readyState!=="open"&&(t.log.trace("%s wait for handshake channel to open, starting status %s",t.role,n.readyState),await Za(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(J1(p))}let o=Z1(r.localDescription?.sdp);if(o==null)throw new eo("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=rA(o,t.remoteAddr,t.role),s=Y1({prologueBytes:i})(t),a=ds({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new Fo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(XC,()=>{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 f=new Qn(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:f,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:f,signal:t.signal})}catch(o){throw n.close(),o}}async function oA(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 iA(r){let e=await nl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ue(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
- `)}var vp=class{log;metrics;components;init;certificate;privateKey;emitter;renewCertificateTask;constructor(e,t={}){if(this.log=e.logger.forComponent("libp2p:webrtc-direct"),this.components=e,this.init=t,this.emitter=new Mn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new Ae("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"})})}[Su]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Wi]=["@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=is(o));let i=Fw(),s=await oA("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await nA(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 Nu;return new pp(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(xw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(YC(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 iA(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Ow,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new To;this.log.trace("checking for stored private key"),this.privateKey=await t.exportKey(e)}catch(n){if(n.name!=="NotFoundError")throw n;this.log.trace("generating private key"),this.privateKey=await Z0("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 du(this.init.certificateDatastoreKey??Nw),i=await nl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new To;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??Ad)-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:ko.encode((await tr.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ea(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??Ad);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new To;this.log("loaded certificate, expires in %d ms",i);let s=await o.publicKey.export(crypto),a=await crypto.subtle.exportKey("raw",s),c=await crypto.subtle.exportKey("raw",t.publicKey);if(!Fe(new Uint8Array(a,0,a.byteLength),new Uint8Array(c,0,c.byteLength)))throw this.log("stored TLS certificate public key did not match public key from private key"),new To;return this.log("loaded certificate, expiry time is %o",i),o}async createCertificate(e,t){let n=new Date,o=new Date(Date.now()+(this.init.certificateLifespan??Rw));n.setMilliseconds(0),o.setMilliseconds(0);let i=await lp.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 Zs(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,de(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function YC(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function ZC(r){return e=>new vp(e,r)}function JC(r){return e=>new Hl(e,r)}return bA(QC);})();
50
+ a=ice-pwd:`+e+t),r}var Xm=pe("libp2p-webrtc-noise:");function f_(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=pe(n,"hex"),i=At(or.code,o),s=qm.decode(Gm(e)),a=Xm.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?st([Xm,s,i.bytes],a):st([Xm,i.bytes,s],a)}var dC=ec?"iceconnectionstatechange":"connectionstatechange";async function p_(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let f=await r.createOffer();t.log.trace("client created local offer %s",f.sdp);let m=zm(f,e);t.log.trace("client setting local offer %s",m.sdp),await r.setLocalDescription(m);let y=c_(t.remoteAddr,e);t.log.trace("client setting server description %s",y.sdp),await r.setRemoteDescription(y)}else{let f=u_(t.remoteAddr,e);t.log.trace("server setting client %s %s",f.type,f.sdp),await r.setRemoteDescription(f),t.log.trace("server creating local answer");let m=await r.createAnswer();t.log.trace("server created local answer");let y=zm(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 nc(n,"open",t.signal)),t.log.trace("%s handshake channel opened",t.role),t.role==="server"){let f=r.remoteFingerprint()?.value??"";t.remoteAddr=t.remoteAddr.encapsulate(a_(f))}let o=s_(r.localDescription?.sdp);if(o==null)throw new to("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=f_(o,t.remoteAddr,t.role),s=i_({prologueBytes:i})(t),a=vs({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new qo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(dC,()=>{switch(r.connectionState){case"failed":case"disconnected":case"closed":c.close().catch(f=>{t.log.error("error closing connection",f),c.abort(f)});break;default:break}}),t.events?.increment({peer_connection:!0});let l=new eo(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 p=await s.secureOutbound(a,{remotePeer:t.remotePeerId,signal:t.signal,skipStreamMuxerNegotiation:!0});c.remoteAddr=c.remoteAddr.encapsulate(`/p2p/${p.remotePeer}`),t.log.trace("%s upgrade inbound",t.role),await t.upgrader.upgradeInbound(c,{skipProtection:!0,skipEncryption:!0,muxerFactory:l,signal:t.signal})}catch(o){throw n.close(),o}}async function h_(r,e,t,n){n==null&&(n=await RTCPeerConnection.generateCertificate({name:"ECDSA",namedCurve:"P-256"}));let o=typeof t=="function"?await t():t;return new RTCPeerConnection({...o??{},certificates:[n]})}async function d_(r){let e=await ul(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 Cp=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 $n,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new ve("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[Cu]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[zi]=["@libp2p/transport"];async start(){this.certificate=await this.getCertificate()}async stop(){this.renewCertificateTask!=null&&clearTimeout(this.renewCertificateTask),this.certificate=void 0}async dial(e,t){this.log("dial %a",e),t.signal.throwIfAborted();let n,o=e.getPeerId();o!=null&&(n=ps(o));let i=Qw(),s=await h_("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await p_(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 Du;return new wp(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(Iw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(yC(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 d_(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Vw,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Oo;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 sw("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 vu(this.init.certificateDatastoreKey??Hw),i=await ul(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Oo;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??_d)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:Po.encode((await or.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new aa(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??_d);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Oo;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 Oo;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??$w));n.setMilliseconds(0),o.setMilliseconds(0);let i=await mp.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new oa(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,pe(i.toString("pem")))):this.log("no keychain is configured so not storing TLS certificate since the private key will not be reused"),i}getKeychain(){try{return this.components.keychain}catch{}}};function yC(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function mC(r){return e=>new Cp(e,r)}function gC(r){return e=>new Gl(e,r)}return B_(wC);})();
52
52
  /*! Bundled license information:
53
53
 
54
54
  reflect-metadata/Reflect.js:
@@ -112,7 +112,7 @@ tslib/tslib.js:
112
112
  @noble/hashes/esm/utils.js:
113
113
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
114
114
 
115
- @noble/curves/esm/abstract/utils.js:
115
+ @noble/curves/esm/utils.js:
116
116
  @noble/curves/esm/abstract/modular.js:
117
117
  @noble/curves/esm/abstract/curve.js:
118
118
  @noble/curves/esm/abstract/edwards.js: