@libp2p/webrtc 5.2.15-ec73d59a6 → 5.2.16

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 +12 -12
  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/dist/typedoc-urls.json +14 -0
  23. package/package.json +10 -9
  24. package/src/private-to-private/listener.ts +3 -2
  25. package/src/private-to-private/transport.ts +4 -2
  26. package/src/private-to-public/listener.browser.ts +1 -1
  27. package/src/private-to-public/listener.ts +4 -2
  28. package/src/private-to-public/transport.ts +4 -2
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 SA=Object.create;var Bu=Object.defineProperty;var EA=Object.getOwnPropertyDescriptor;var CA=Object.getOwnPropertyNames;var TA=Object.getPrototypeOf,IA=Object.prototype.hasOwnProperty;var kp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ct=(r,e)=>{for(var t in e)Bu(r,t,{get:e[t],enumerable:!0})},sg=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of CA(e))!IA.call(r,o)&&o!==t&&Bu(r,o,{get:()=>e[o],enumerable:!(n=EA(e,o))||n.enumerable});return r};var $r=(r,e,t)=>(t=r!=null?SA(TA(r)):{},sg(e||!r||!r.__esModule?Bu(t,"default",{value:r,enumerable:!0}):t,r)),OA=r=>sg(Bu({},"__esModule",{value:!0}),r);var fb=kp(()=>{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(b,S){return n.call(b,S)}:function(b,S){return S in b},get:l?function(b,S){return n.call(b,S)?b[S]:void 0}:function(b,S){return b[S]}},f=Object.getPrototypeOf(Function),d=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:bA(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:xA(),g=typeof WeakMap=="function"?WeakMap:vA(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,_=mA(),j=gA(_);function J(b,S,P,q){if(I(P)){if(!yt(b))throw new TypeError;if(!st(S))throw new TypeError;return X(b,S)}else{if(!yt(b))throw new TypeError;if(!te(S))throw new TypeError;if(!te(q)&&!I(q)&&!oe(q))throw new TypeError;return oe(q)&&(q=void 0),P=Re(P),W(b,S,P,q)}}e("decorate",J);function O(b,S){function P(q,ue){if(!te(q))throw new TypeError;if(!I(ue)&&!jt(ue))throw new TypeError;k(b,S,q,ue)}return P}e("metadata",O);function x(b,S,P,q){if(!te(P))throw new TypeError;return I(q)||(q=Re(q)),k(b,S,P,q)}e("defineMetadata",x);function D(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),ae(b,S,P)}e("hasMetadata",D);function $(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),B(b,S,P)}e("hasOwnMetadata",$);function N(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),R(b,S,P)}e("getMetadata",N);function U(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),H(b,S,P)}e("getOwnMetadata",U);function F(b,S){if(!te(b))throw new TypeError;return I(S)||(S=Re(S)),y(b,S)}e("getMetadataKeys",F);function Z(b,S){if(!te(b))throw new TypeError;return I(S)||(S=Re(S)),T(b,S)}e("getOwnMetadataKeys",Z);function K(b,S,P){if(!te(S))throw new TypeError;if(I(P)||(P=Re(P)),!te(S))throw new TypeError;I(P)||(P=Re(P));var q=ya(S,P,!1);return I(q)?!1:q.OrdinaryDeleteMetadata(b,S,P)}e("deleteMetadata",K);function X(b,S){for(var P=b.length-1;P>=0;--P){var q=b[P],ue=q(S);if(!I(ue)&&!oe(ue)){if(!st(ue))throw new TypeError;S=ue}}return S}function W(b,S,P,q){for(var ue=b.length-1;ue>=0;--ue){var Qe=b[ue],at=Qe(S,P,q);if(!I(at)&&!oe(at)){if(!te(at))throw new TypeError;q=at}}return q}function ae(b,S,P){var q=B(b,S,P);if(q)return!0;var ue=da(S);return oe(ue)?!1:ae(b,ue,P)}function B(b,S,P){var q=ya(S,P,!1);return I(q)?!1:Ce(q.OrdinaryHasOwnMetadata(b,S,P))}function R(b,S,P){var q=B(b,S,P);if(q)return H(b,S,P);var ue=da(S);if(!oe(ue))return R(b,ue,P)}function H(b,S,P){var q=ya(S,P,!1);if(!I(q))return q.OrdinaryGetOwnMetadata(b,S,P)}function k(b,S,P,q){var ue=ya(P,q,!0);ue.OrdinaryDefineOwnMetadata(b,S,P,q)}function y(b,S){var P=T(b,S),q=da(b);if(q===null)return P;var ue=y(q,S);if(ue.length<=0)return P;if(P.length<=0)return ue;for(var Qe=new v,at=[],xe=0,Y=P;xe<Y.length;xe++){var ee=Y[xe],ne=Qe.has(ee);ne||(Qe.add(ee),at.push(ee))}for(var ie=0,ve=ue;ie<ve.length;ie++){var ee=ve[ie],ne=Qe.has(ee);ne||(Qe.add(ee),at.push(ee))}return at}function T(b,S){var P=ya(b,S,!1);return P?P.OrdinaryOwnMetadataKeys(b,S):[]}function L(b){if(b===null)return 1;switch(typeof b){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return b===null?1:6;default:return 6}}function I(b){return b===void 0}function oe(b){return b===null}function pe(b){return typeof b=="symbol"}function te(b){return typeof b=="object"?b!==null:typeof b=="function"}function de(b,S){switch(L(b)){case 0:return b;case 1:return b;case 2:return b;case 3:return b;case 4:return b;case 5:return b}var P=S===3?"string":S===5?"number":"default",q=Wn(b,i);if(q!==void 0){var ue=q.call(b,P);if(te(ue))throw new TypeError;return ue}return ye(b,P==="default"?"number":P)}function ye(b,S){if(S==="string"){var P=b.toString;if($e(P)){var q=P.call(b);if(!te(q))return q}var ue=b.valueOf;if($e(ue)){var q=ue.call(b);if(!te(q))return q}}else{var ue=b.valueOf;if($e(ue)){var q=ue.call(b);if(!te(q))return q}var Qe=b.toString;if($e(Qe)){var q=Qe.call(b);if(!te(q))return q}}throw new TypeError}function Ce(b){return!!b}function Te(b){return""+b}function Re(b){var S=de(b,3);return pe(S)?S:Te(S)}function yt(b){return Array.isArray?Array.isArray(b):b instanceof Object?b instanceof Array:Object.prototype.toString.call(b)==="[object Array]"}function $e(b){return typeof b=="function"}function st(b){return typeof b=="function"}function jt(b){switch(L(b)){case 3:return!0;case 4:return!0;default:return!1}}function Rt(b,S){return b===S||b!==b&&S!==S}function Wn(b,S){var P=b[S];if(P!=null){if(!$e(P))throw new TypeError;return P}}function ha(b){var S=Wn(b,s);if(!$e(S))throw new TypeError;var P=S.call(b);if(!te(P))throw new TypeError;return P}function Iu(b){return b.value}function Ou(b){var S=b.next();return S.done?!1:S}function Pu(b){var S=b.return;S&&S.call(b)}function da(b){var S=Object.getPrototypeOf(b);if(typeof b!="function"||b===f||S!==f)return S;var P=b.prototype,q=P&&Object.getPrototypeOf(P);if(q==null||q===Object.prototype)return S;var ue=q.constructor;return typeof ue!="function"||ue===b?S:ue}function yA(){var b;!I(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(b=wA(t.Reflect));var S,P,q,ue=new g,Qe={registerProvider:at,getProvider:Y,setProvider:ne};return Qe;function at(ie){if(!Object.isExtensible(Qe))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case b===ie:break;case I(S):S=ie;break;case S===ie:break;case I(P):P=ie;break;case P===ie:break;default:q===void 0&&(q=new v),q.add(ie);break}}function xe(ie,ve){if(!I(S)){if(S.isProviderFor(ie,ve))return S;if(!I(P)){if(P.isProviderFor(ie,ve))return S;if(!I(q))for(var Fe=ha(q);;){var et=Ou(Fe);if(!et)return;var vr=Iu(et);if(vr.isProviderFor(ie,ve))return Pu(Fe),vr}}}if(!I(b)&&b.isProviderFor(ie,ve))return b}function Y(ie,ve){var Fe=ue.get(ie),et;return I(Fe)||(et=Fe.get(ve)),I(et)&&(et=xe(ie,ve),I(et)||(I(Fe)&&(Fe=new d,ue.set(ie,Fe)),Fe.set(ve,et))),et}function ee(ie){if(I(ie))throw new TypeError;return S===ie||P===ie||!I(q)&&q.has(ie)}function ne(ie,ve,Fe){if(!ee(Fe))throw new Error("Metadata provider not registered.");var et=Y(ie,ve);if(et!==Fe){if(!I(et))return!1;var vr=ue.get(ie);I(vr)&&(vr=new d,ue.set(ie,vr)),vr.set(ve,Fe)}return!0}}function mA(){var b;return!I(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&(b=t.Reflect[w]),I(b)&&(b=yA()),!I(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:b}),b}function gA(b){var S=new g,P={isProviderFor:function(ee,ne){var ie=S.get(ee);return I(ie)?!1:ie.has(ne)},OrdinaryDefineOwnMetadata:at,OrdinaryHasOwnMetadata:ue,OrdinaryGetOwnMetadata:Qe,OrdinaryOwnMetadataKeys:xe,OrdinaryDeleteMetadata:Y};return _.registerProvider(P),P;function q(ee,ne,ie){var ve=S.get(ee),Fe=!1;if(I(ve)){if(!ie)return;ve=new d,S.set(ee,ve),Fe=!0}var et=ve.get(ne);if(I(et)){if(!ie)return;if(et=new d,ve.set(ne,et),!b.setProvider(ee,ne,P))throw ve.delete(ne),Fe&&S.delete(ee),new Error("Wrong provider for target.")}return et}function ue(ee,ne,ie){var ve=q(ne,ie,!1);return I(ve)?!1:Ce(ve.has(ee))}function Qe(ee,ne,ie){var ve=q(ne,ie,!1);if(!I(ve))return ve.get(ee)}function at(ee,ne,ie,ve){var Fe=q(ie,ve,!0);Fe.set(ee,ne)}function xe(ee,ne){var ie=[],ve=q(ee,ne,!1);if(I(ve))return ie;for(var Fe=ve.keys(),et=ha(Fe),vr=0;;){var ig=Ou(et);if(!ig)return ie.length=vr,ie;var AA=Iu(ig);try{ie[vr]=AA}catch(_A){try{Pu(et)}finally{throw _A}}vr++}}function Y(ee,ne,ie){var ve=q(ne,ie,!1);if(I(ve)||!ve.delete(ee))return!1;if(ve.size===0){var Fe=S.get(ne);I(Fe)||(Fe.delete(ie),Fe.size===0&&S.delete(Fe))}return!0}}function wA(b){var S=b.defineMetadata,P=b.hasOwnMetadata,q=b.getOwnMetadata,ue=b.getOwnMetadataKeys,Qe=b.deleteMetadata,at=new g,xe={isProviderFor:function(Y,ee){var ne=at.get(Y);return!I(ne)&&ne.has(ee)?!0:ue(Y,ee).length?(I(ne)&&(ne=new v,at.set(Y,ne)),ne.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:P,OrdinaryGetOwnMetadata:q,OrdinaryOwnMetadataKeys:ue,OrdinaryDeleteMetadata:Qe};return xe}function ya(b,S,P){var q=_.getProvider(b,S);if(!I(q))return q;if(P){if(_.setProvider(b,S,j))return j;throw new Error("Illegal state.")}}function bA(){var b={},S=[],P=function(){function xe(Y,ee,ne){this._index=0,this._keys=Y,this._values=ee,this._selector=ne}return xe.prototype["@@iterator"]=function(){return this},xe.prototype[s]=function(){return this},xe.prototype.next=function(){var Y=this._index;if(Y>=0&&Y<this._keys.length){var ee=this._selector(this._keys[Y],this._values[Y]);return Y+1>=this._keys.length?(this._index=-1,this._keys=S,this._values=S):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},xe.prototype.throw=function(Y){throw this._index>=0&&(this._index=-1,this._keys=S,this._values=S),Y},xe.prototype.return=function(Y){return this._index>=0&&(this._index=-1,this._keys=S,this._values=S),{value:Y,done:!0}},xe}(),q=function(){function xe(){this._keys=[],this._values=[],this._cacheKey=b,this._cacheIndex=-2}return Object.defineProperty(xe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),xe.prototype.has=function(Y){return this._find(Y,!1)>=0},xe.prototype.get=function(Y){var ee=this._find(Y,!1);return ee>=0?this._values[ee]:void 0},xe.prototype.set=function(Y,ee){var ne=this._find(Y,!0);return this._values[ne]=ee,this},xe.prototype.delete=function(Y){var ee=this._find(Y,!1);if(ee>=0){for(var ne=this._keys.length,ie=ee+1;ie<ne;ie++)this._keys[ie-1]=this._keys[ie],this._values[ie-1]=this._values[ie];return this._keys.length--,this._values.length--,Rt(Y,this._cacheKey)&&(this._cacheKey=b,this._cacheIndex=-2),!0}return!1},xe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=b,this._cacheIndex=-2},xe.prototype.keys=function(){return new P(this._keys,this._values,ue)},xe.prototype.values=function(){return new P(this._keys,this._values,Qe)},xe.prototype.entries=function(){return new P(this._keys,this._values,at)},xe.prototype["@@iterator"]=function(){return this.entries()},xe.prototype[s]=function(){return this.entries()},xe.prototype._find=function(Y,ee){if(!Rt(this._cacheKey,Y)){this._cacheIndex=-1;for(var ne=0;ne<this._keys.length;ne++)if(Rt(this._keys[ne],Y)){this._cacheIndex=ne;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(Y),this._values.push(void 0)),this._cacheIndex},xe}();return q;function ue(xe,Y){return xe}function Qe(xe,Y){return Y}function at(xe,Y){return[xe,Y]}}function xA(){var b=function(){function S(){this._map=new d}return Object.defineProperty(S.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),S.prototype.has=function(P){return this._map.has(P)},S.prototype.add=function(P){return this._map.set(P,P),this},S.prototype.delete=function(P){return this._map.delete(P)},S.prototype.clear=function(){this._map.clear()},S.prototype.keys=function(){return this._map.keys()},S.prototype.values=function(){return this._map.keys()},S.prototype.entries=function(){return this._map.entries()},S.prototype["@@iterator"]=function(){return this.keys()},S.prototype[s]=function(){return this.keys()},S}();return b}function vA(){var b=16,S=p.create(),P=q();return function(){function Y(){this._key=q()}return Y.prototype.has=function(ee){var ne=ue(ee,!1);return ne!==void 0?p.has(ne,this._key):!1},Y.prototype.get=function(ee){var ne=ue(ee,!1);return ne!==void 0?p.get(ne,this._key):void 0},Y.prototype.set=function(ee,ne){var ie=ue(ee,!0);return ie[this._key]=ne,this},Y.prototype.delete=function(ee){var ne=ue(ee,!1);return ne!==void 0?delete ne[this._key]:!1},Y.prototype.clear=function(){this._key=q()},Y}();function q(){var Y;do Y="@@WeakMap@@"+xe();while(p.has(S,Y));return S[Y]=!0,Y}function ue(Y,ee){if(!n.call(Y,P)){if(!ee)return;Object.defineProperty(Y,P,{value:p.create()})}return Y[P]}function Qe(Y,ee){for(var ne=0;ne<ee;++ne)Y[ne]=Math.random()*255|0;return Y}function at(Y){if(typeof Uint8Array=="function"){var ee=new Uint8Array(Y);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):Qe(ee,Y),ee}return Qe(new Array(Y),Y)}function xe(){var Y=at(b);Y[6]=Y[6]&79|64,Y[8]=Y[8]&191|128;for(var ee="",ne=0;ne<b;++ne){var ie=Y[ne];(ne===4||ne===6||ne===8)&&(ee+="-"),ie<16&&(ee+="0"),ee+=ie.toString(16).toLowerCase()}return ee}}function Bp(b){return b.__=void 0,delete b.__,b}})})(lb||(lb={}))});var Sn=kp(_s=>{"use strict";var QE="[object ArrayBuffer]",_n=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===QE}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}},$d="string",e2=/^[0-9a-f\s]+$/i,t2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,r2=/^[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=_n.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},lr=class{static toString(e,t=!1){let n=_n.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}},Jl=class r{static isHex(e){return typeof e===$d&&e2.test(e)}static isBase64(e){return typeof e===$d&&t2.test(e)}static isBase64Url(e){return typeof e===$d&&r2.test(e)}static ToString(e,t="utf8"){let n=_n.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return lr.toString(n,!0);case"utf16":case"utf16be":return lr.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return lr.fromString(e,!0);case"utf16":case"utf16be":return lr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=_n.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 lr.fromString(e);case"utf16le":case"usc2":return lr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Zl.toString(e);case"utf16":case"utf16be":return lr.toString(e);case"utf16le":case"usc2":return lr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=_n.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=_n.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return lr.toString(e,t)}static FromUtf16String(e,t=!1){return lr.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Jl.DEFAULT_UTF8_ENCODING="utf8";function n2(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 o2(...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 i2(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=_n;_s.Convert=Jl;_s.assign=n2;_s.combine=o2;_s.isEqual=i2});var iv=kp((tV,Gf)=>{var Mx,Kx,Hx,Vx,$x,Fx,Wx,qx,Gx,qf,Yy,zx,Xx,Qs,Yx,Zx,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 Gf=="object"&&typeof Gf.exports=="object"?r(t(e,t(Gf.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(d){try{f(i.next(d))}catch(v){c(v)}}function p(d){try{f(i.throw(d))}catch(v){c(v)}}function f(d){d.done?a(d.value):s(d.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(d){return p([f,d])}}function p(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(d){f=[6,d],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},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])},qf=function(t){var n=typeof Symbol=="function"&&Symbol.iterator,o=n&&t[n],i=0;if(o)return o.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},Yy=function(t,n){var o=typeof Symbol=="function"&&t[Symbol.iterator];if(!o)return t;var i=o.call(t),s,a=[],c;try{for(;(n===void 0||n-- >0)&&!(s=i.next()).done;)a.push(s.value)}catch(l){c={error:l}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},zx=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Yy(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},Qs=function(t){return this instanceof Qs?(this.v=t,this):new Qs(t)},Yx=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(_,j){a.push([g,w,_,j])>1||l(g,w)})})}function l(g,w){try{p(i[g](w))}catch(_){v(a[0][3],_)}}function p(g){g.value instanceof Qs?Promise.resolve(g.value.v).then(f,d):v(a[0][2],g)}function f(g){l("next",g)}function d(g){l("throw",g)}function v(g,w){g(w),a.shift(),a.length&&l(a[0][0],a[0][1])}},Zx=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:Qs(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 qf=="function"?qf(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",qf),r("__read",Yy),r("__spread",zx),r("__spreadArrays",Xx),r("__await",Qs),r("__asyncGenerator",Yx),r("__asyncDelegator",Zx),r("__asyncValues",Jx),r("__makeTemplateObject",Qx),r("__importStar",ev),r("__importDefault",tv),r("__classPrivateFieldGet",rv),r("__classPrivateFieldSet",nv)})});var cT={};Ct(cT,{webRTC:()=>aT,webRTCDirect:()=>sT});var Np=Symbol.for("@libp2p/peer-id");var ku=Symbol.for("@libp2p/transport");var ag;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(ag||(ag={}));var Nu=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},ju=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ji=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},ma=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Ru=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Du=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Ro=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Do=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Lu=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Uu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Mu=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Ku=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Hu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var qn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Gn=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 Qi=Symbol.for("@libp2p/service-capabilities"),cg=Symbol.for("@libp2p/service-dependencies");var Up={};Ct(Up,{base58btc:()=>De,base58flickr:()=>DA});var DT=new Uint8Array(0);function ug(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function hn(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function lg(r){return new TextEncoder().encode(r)}function fg(r){return new TextDecoder().decode(r)}function PA(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(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,_=0,j=0,J=g.length;j!==J&&g[j]===0;)j++,w++;for(var O=(J-j)*p+1>>>0,x=new Uint8Array(O);j!==J;){for(var D=g[j],$=0,N=O-1;(D!==0||$<_)&&N!==-1;N--,$++)D+=256*x[N]>>>0,x[N]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");_=$,j++}for(var U=O-_;U!==O&&x[U]===0;)U++;for(var F=c.repeat(w);U<O;++U)F+=r.charAt(x[U]);return F}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var _=0,j=0;g[w]===c;)_++,w++;for(var J=(g.length-w)*l+1>>>0,O=new Uint8Array(J);g[w];){var x=t[g.charCodeAt(w)];if(x===255)return;for(var D=0,$=J-1;(x!==0||D<j)&&$!==-1;$--,D++)x+=a*O[$]>>>0,O[$]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");j=D,w++}if(g[w]!==" "){for(var N=J-j;N!==J&&O[N]===0;)N++;for(var U=new Uint8Array(_+(J-N)),F=_;N!==J;)U[F++]=O[N++];return U}}}function v(g){var w=d(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:v}}var BA=PA,kA=BA,hg=kA;var jp=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")}},Rp=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 dg(this,e)}},Dp=class{decoders;constructor(e){this.decoders=e}or(e){return dg(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 dg(r,e){return new Dp({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Lp=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 jp(e,t,n),this.decoder=new Rp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function es({name:r,prefix:e,encode:t,decode:n}){return new Lp(r,e,t,n)}function zn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=hg(t,r);return es({prefix:e,name:r,encode:n,decode:i=>hn(o(i))})}function NA(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 jA(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 RA(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Xe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=RA(n);return es({prefix:e,name:r,encode(i){return jA(i,n,t)},decode(i){return NA(i,o,t,r)}})}var De=zn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),DA=zn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Mp={};Ct(Mp,{base32:()=>dn,base32hex:()=>KA,base32hexpad:()=>VA,base32hexpadupper:()=>$A,base32hexupper:()=>HA,base32pad:()=>UA,base32padupper:()=>MA,base32upper:()=>LA,base32z:()=>FA});var dn=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),LA=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),UA=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),MA=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),KA=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),HA=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),VA=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$A=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),FA=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kp={};Ct(Kp,{base36:()=>ga,base36upper:()=>WA});var ga=zn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),WA=zn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sr={};Ct(sr,{Digest:()=>Lo,create:()=>Tt,decode:()=>Xn,equals:()=>Vp,hasCode:()=>l_});var qA=gg,yg=128,GA=127,zA=~GA,XA=Math.pow(2,31);function gg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=XA;)e[t++]=r&255|yg,r/=128;for(;r&zA;)e[t++]=r&255|yg,r>>>=7;return e[t]=r|0,gg.bytes=t-n+1,e}var YA=Hp,ZA=128,mg=127;function Hp(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Hp.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&mg)<<o:(s&mg)*Math.pow(2,o),o+=7}while(s>=ZA);return Hp.bytes=i-n,t}var JA=Math.pow(2,7),QA=Math.pow(2,14),e_=Math.pow(2,21),t_=Math.pow(2,28),r_=Math.pow(2,35),n_=Math.pow(2,42),o_=Math.pow(2,49),i_=Math.pow(2,56),s_=Math.pow(2,63),a_=function(r){return r<JA?1:r<QA?2:r<e_?3:r<t_?4:r<r_?5:r<n_?6:r<o_?7:r<i_?8:r<s_?9:10},c_={encode:qA,decode:YA,encodingLength:a_},u_=c_,wa=u_;function ba(r,e=0){return[wa.decode(r,e),wa.decode.bytes]}function ts(r,e,t=0){return wa.encode(r,e,t),e}function rs(r){return wa.encodingLength(r)}function Tt(r,e){let t=e.byteLength,n=rs(r),o=n+rs(t),i=new Uint8Array(o+t);return ts(r,i,0),ts(t,i,n),i.set(e,o),new Lo(r,t,e,i)}function Xn(r){let e=hn(r),[t,n]=ba(e),[o,i]=ba(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Lo(t,o,s,e)}function Vp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ug(r.bytes,t.bytes)}}var Lo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function l_(r,e){return r.code===e}function wg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return p_(t,$p(r),e??De.encoder);default:return h_(t,$p(r),e??dn.encoder)}}var bg=new WeakMap;function $p(r){let e=bg.get(r);if(e==null){let t=new Map;return bg.set(r,t),t}return e}var tt=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==xa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==d_)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=Tt(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&&Vp(e.multihash,n.multihash)}toString(e){return wg(this,e)}toJSON(){return{"/":wg(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??xg(n,o,i.bytes))}else if(t[y_]===!0){let{version:n,multihash:o,code:i}=t,s=Xn(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==xa)throw new Error(`Version 0 CID must use dag-pb (code: ${xa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=xg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,xa,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=hn(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new Lo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=ba(e.subarray(t));return t+=d,f},o=n(),i=xa;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),l=t+c,p=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:l}}static parse(e,t){let[n,o]=f_(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 $p(i).set(n,e),i}};function f_(r,e){switch(r[0]){case"Q":{let t=e??De;return[De.prefix,t.decode(`${De.prefix}${r}`)]}case De.prefix:{let t=e??De;return[De.prefix,t.decode(r)]}case dn.prefix:{let t=e??dn;return[dn.prefix,t.decode(r)]}case ga.prefix:{let t=e??ga;return[ga.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function p_(r,e,t){let{prefix:n}=t;if(n!==De.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function h_(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var xa=112,d_=18;function xg(r,e,t){let n=rs(r),o=n+rs(e),i=new Uint8Array(o+t.byteLength);return ts(r,i,0),ts(e,i,n),i.set(t,o),i}var y_=Symbol.for("@ipld/js-cid/CID");var Fp={};Ct(Fp,{identity:()=>Ar});var vg=0,m_="identity",Ag=hn;function g_(r){return Tt(vg,Ag(r))}var Ar={code:vg,name:m_,encode:Ag,digest:g_};function Ye(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 ct(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}function lt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ut(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Sg=Symbol.for("@achingbrain/uint8arraylist");function _g(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function $u(r){return!!r?.[Sg]}var Ae=class r{bufs;length;[Sg]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if($u(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if($u(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=_g(this.bufs,e);return t.buf[t.index]}set(e,t){let n=_g(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if($u(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return lt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:lt(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(!$u(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let 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 d=l;d>=0;d--){let v=this.get(f+d);if(n[d]!==v){p=Math.max(1,d-a[v]);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=ut(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=ct(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=ct(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=ct(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=ut(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=ct(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=ct(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=ct(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=ct(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=ct(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(!Ye(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 Wp={};Ct(Wp,{base10:()=>b_});var b_=zn({prefix:"9",name:"base10",alphabet:"0123456789"});var qp={};Ct(qp,{base16:()=>x_,base16upper:()=>v_});var x_=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),v_=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Gp={};Ct(Gp,{base2:()=>A_});var A_=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zp={};Ct(zp,{base256emoji:()=>T_});var Eg=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}"),__=Eg.reduce((r,e,t)=>(r[t]=e,r),[]),S_=Eg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function E_(r){return r.reduce((e,t)=>(e+=__[t],e),"")}function C_(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=S_[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var T_=es({prefix:"\u{1F680}",name:"base256emoji",encode:E_,decode:C_});var Xp={};Ct(Xp,{base64:()=>I_,base64pad:()=>O_,base64url:()=>Uo,base64urlpad:()=>P_});var I_=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),O_=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),P_=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yp={};Ct(Yp,{base8:()=>B_});var B_=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zp={};Ct(Zp,{identity:()=>k_});var k_=es({prefix:"\0",name:"identity",encode:r=>fg(r),decode:r=>lg(r)});var wI=new TextEncoder,bI=new TextDecoder;var eh={};Ct(eh,{sha256:()=>ar,sha512:()=>R_});function Qp({name:r,code:e,encode:t}){return new Jp(r,e,t)}var Jp=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?Tt(this.code,t):t.then(n=>Tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Tg(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var ar=Qp({name:"sha2-256",code:18,encode:Tg("SHA-256")}),R_=Qp({name:"sha2-512",code:19,encode:Tg("SHA-512")});var Mo={...Zp,...Gp,...Yp,...Wp,...qp,...Mp,...Kp,...Up,...Xp,...zp},BI={...eh,...Fp};function Og(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ig=Og("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),th=Og("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=ut(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),D_={utf8:Ig,"utf-8":Ig,hex:Mo.base16,latin1:th,ascii:th,binary:th,...Mo},Fu=D_;function me(r,e="utf8"){let t=Fu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function fe(r,e="utf8"){let t=Fu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var L_=parseInt("11111",2),rh=parseInt("10000000",2),U_=parseInt("01111111",2),Pg={0:va,1:va,2:M_,3:V_,4:$_,5:H_,6:K_,16:va,22:va,48:va};function yn(r,e={offset:0}){let t=r[e.offset]&L_;if(e.offset++,Pg[t]!=null)return Pg[t](r,e);throw new Error("No decoder for tag "+t)}function Aa(r,e){let t=0;if((r[e.offset]&rh)===rh){let n=r[e.offset]&U_,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function va(r,e){Aa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=yn(r,e);if(n===null)break;t.push(n)}return t}function M_(r,e){let t=Aa(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 K_(r,e){let t=Aa(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 H_(r,e){return e.offset++,null}function V_(r,e){let t=Aa(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 $_(r,e){let t=Aa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function F_(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new Ae;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Wu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=F_(r.byteLength);return new Ae(Uint8Array.from([e.byteLength|rh]),e)}function Dt(r){let e=new Ae,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new Ae(Uint8Array.from([2]),Wu(e),e)}function _a(r){let e=Uint8Array.from([0]),t=new Ae(e,r);return new Ae(Uint8Array.from([3]),Wu(t),t)}function Bg(r){return new Ae(Uint8Array.from([4]),Wu(r),r)}function _r(r,e=48){let t=new Ae;for(let n of r)t.append(n);return new Ae(Uint8Array.from([e]),Wu(t),t)}async function kg(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 Ng(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 jg(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 W_=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),q_=Uint8Array.from([6,5,43,129,4,0,34]),G_=Uint8Array.from([6,5,43,129,4,0,35]),z_={ext:!0,kty:"EC",crv:"P-256"},X_={ext:!0,kty:"EC",crv:"P-384"},Y_={ext:!0,kty:"EC",crv:"P-521"},nh=32,oh=48,ih=66;function sh(r){let e=yn(r);return Rg(e)}function Rg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===nh*2+1)return n=fe(e.subarray(t,t+nh),"base64url"),o=fe(e.subarray(t+nh),"base64url"),new Ko({...z_,key_ops:["verify"],x:n,y:o});if(e.byteLength===oh*2+1)return n=fe(e.subarray(t,t+oh),"base64url"),o=fe(e.subarray(t+oh),"base64url"),new Ko({...X_,key_ops:["verify"],x:n,y:o});if(e.byteLength===ih*2+1)return n=fe(e.subarray(t,t+ih),"base64url"),o=fe(e.subarray(t+ih),"base64url"),new Ko({...Y_,key_ops:["verify"],x:n,y:o});throw new Se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Dg(r){return _r([Dt(Uint8Array.from([1])),Bg(me(r.d??"","base64url")),_r([Ug(r.crv)],160),_r([_a(new Ae(Uint8Array.from([4]),me(r.x??"","base64url"),me(r.y??"","base64url")))],161)]).subarray()}function Lg(r){return _r([Dt(Uint8Array.from([1])),_r([Ug(r.crv)],160),_r([_a(new Ae(Uint8Array.from([4]),me(r.x??"","base64url"),me(r.y??"","base64url")))],161)]).subarray()}function Ug(r){if(r==="P-256")return W_;if(r==="P-384")return q_;if(r==="P-521")return G_;throw new Se(`Invalid curve ${r}`)}async function Mg(r="P-256"){let e=await kg(r);return new qu(e.privateKey)}var Ko=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Lg(this.jwk)),this._raw}toMultihash(){return Ar.digest(Yn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async verify(e,t,n){return jg(this.jwk,t,e,n)}},qu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Ko({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=Dg(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async sign(e,t){return Ng(this.jwk,e,t)}};var Ho=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Z_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ns(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Vo(r,...e){if(!Z_(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 Sa(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ns(r.outputLen),ns(r.blockLen)}function is(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 Kg(r,e){Vo(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Sr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Gu(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Er(r,e){return r<<32-e|r>>>e}function Hg(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Zn(r){return typeof r=="string"&&(r=Hg(r)),Vo(r),r}function ah(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Vo(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 os=class{};function ch(r){let e=n=>r().update(Zn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ea(r=32){if(Ho&&typeof Ho.getRandomValues=="function")return Ho.getRandomValues(new Uint8Array(r));if(Ho&&typeof Ho.randomBytes=="function")return Uint8Array.from(Ho.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function J_(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 Vg(r,e,t){return r&e^~r&t}function $g(r,e,t){return r&e^r&t^e&t}var Ca=class extends os{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=Gu(this.buffer)}update(e){is(this),e=Zn(e),Vo(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=Gu(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){is(this),Kg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Sr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;J_(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Gu(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 mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var zu=BigInt(4294967295),Fg=BigInt(32);function Q_(r,e=!1){return e?{h:Number(r&zu),l:Number(r>>Fg&zu)}:{h:Number(r>>Fg&zu)|0,l:Number(r&zu)|0}}function Wg(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}=Q_(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var uh=(r,e,t)=>r>>>t,lh=(r,e,t)=>r<<32-t|e>>>t,$o=(r,e,t)=>r>>>t|e<<32-t,Fo=(r,e,t)=>r<<32-t|e>>>t,Ta=(r,e,t)=>r<<64-t|e>>>t-32,Ia=(r,e,t)=>r>>>t-32|e<<64-t;function Fr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var qg=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Gg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,zg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Xg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Yg=(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 tS=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jn=new Uint32Array(64),Xu=class extends Ca{constructor(e=32){super(64,e,8,!1),this.A=mn[0]|0,this.B=mn[1]|0,this.C=mn[2]|0,this.D=mn[3]|0,this.E=mn[4]|0,this.F=mn[5]|0,this.G=mn[6]|0,this.H=mn[7]|0}get(){let{A:e,B:t,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,t,n,o,i,s,a,c]}set(e,t,n,o,i,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)Jn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let d=Jn[f-15],v=Jn[f-2],g=Er(d,7)^Er(d,18)^d>>>3,w=Er(v,17)^Er(v,19)^v>>>10;Jn[f]=w+Jn[f-7]+g+Jn[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 d=Er(a,6)^Er(a,11)^Er(a,25),v=p+d+Vg(a,c,l)+tS[f]+Jn[f]|0,w=(Er(n,2)^Er(n,13)^Er(n,22))+$g(n,o,i)|0;p=l,l=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,l=l+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,l,p)}roundClean(){Sr(Jn)}destroy(){this.set(0,0,0,0,0,0,0,0),Sr(this.buffer)}};var Jg=Wg(["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))),rS=Jg[0],nS=Jg[1],Qn=new Uint32Array(80),eo=new Uint32Array(80),fh=class extends Ca{constructor(e=64){super(128,e,16,!1),this.Ah=mt[0]|0,this.Al=mt[1]|0,this.Bh=mt[2]|0,this.Bl=mt[3]|0,this.Ch=mt[4]|0,this.Cl=mt[5]|0,this.Dh=mt[6]|0,this.Dl=mt[7]|0,this.Eh=mt[8]|0,this.El=mt[9]|0,this.Fh=mt[10]|0,this.Fl=mt[11]|0,this.Gh=mt[12]|0,this.Gl=mt[13]|0,this.Hh=mt[14]|0,this.Hl=mt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:p,Fh:f,Fl:d,Gh:v,Gl:g,Hh:w,Hl:_}=this;return[e,t,n,o,i,s,a,c,l,p,f,d,v,g,w,_]}set(e,t,n,o,i,s,a,c,l,p,f,d,v,g,w,_){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=d|0,this.Gh=v|0,this.Gl=g|0,this.Hh=w|0,this.Hl=_|0}process(e,t){for(let O=0;O<16;O++,t+=4)Qn[O]=e.getUint32(t),eo[O]=e.getUint32(t+=4);for(let O=16;O<80;O++){let x=Qn[O-15]|0,D=eo[O-15]|0,$=$o(x,D,1)^$o(x,D,8)^uh(x,D,7),N=Fo(x,D,1)^Fo(x,D,8)^lh(x,D,7),U=Qn[O-2]|0,F=eo[O-2]|0,Z=$o(U,F,19)^Ta(U,F,61)^uh(U,F,6),K=Fo(U,F,19)^Ia(U,F,61)^lh(U,F,6),X=zg(N,K,eo[O-7],eo[O-16]),W=Xg(X,$,Z,Qn[O-7],Qn[O-16]);Qn[O]=W|0,eo[O]=X|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:p,Eh:f,El:d,Fh:v,Fl:g,Gh:w,Gl:_,Hh:j,Hl:J}=this;for(let O=0;O<80;O++){let x=$o(f,d,14)^$o(f,d,18)^Ta(f,d,41),D=Fo(f,d,14)^Fo(f,d,18)^Ia(f,d,41),$=f&v^~f&w,N=d&g^~d&_,U=Yg(J,D,N,nS[O],eo[O]),F=Zg(U,j,x,$,rS[O],Qn[O]),Z=U|0,K=$o(n,o,28)^Ta(n,o,34)^Ta(n,o,39),X=Fo(n,o,28)^Ia(n,o,34)^Ia(n,o,39),W=n&i^n&a^i&a,ae=o&s^o&c^s&c;j=w|0,J=_|0,w=v|0,_=g|0,v=f|0,g=d|0,{h:f,l:d}=Fr(l|0,p|0,F|0,Z|0),l=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let B=qg(Z,X,ae);n=Gg(B,F,K,W),o=B|0}({h:n,l:o}=Fr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Fr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Fr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:p}=Fr(this.Dh|0,this.Dl|0,l|0,p|0),{h:f,l:d}=Fr(this.Eh|0,this.El|0,f|0,d|0),{h:v,l:g}=Fr(this.Fh|0,this.Fl|0,v|0,g|0),{h:w,l:_}=Fr(this.Gh|0,this.Gl|0,w|0,_|0),{h:j,l:J}=Fr(this.Hh|0,this.Hl|0,j|0,J|0),this.set(n,o,i,s,a,c,l,p,f,d,v,g,w,_,j,J)}roundClean(){Sr(Qn,eo)}destroy(){Sr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Yu=ch(()=>new Xu);var Qg=ch(()=>new fh);var yh=BigInt(0),dh=BigInt(1);function ss(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function mh(r){if(!ss(r))throw new Error("Uint8Array expected")}function Wr(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Oa(r){let e=r.toString(16);return e.length&1?"0"+e:e}function r0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?yh:BigInt("0x"+r)}var n0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",oS=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function to(r){if(mh(r),n0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=oS[r[t]];return e}var gn={_0:48,_9:57,A:65,F:70,a:97,f:102};function e0(r){if(r>=gn._0&&r<=gn._9)return r-gn._0;if(r>=gn.A&&r<=gn.F)return r-(gn.A-10);if(r>=gn.a&&r<=gn.f)return r-(gn.a-10)}function Pa(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(n0)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=e0(r.charCodeAt(i)),a=e0(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function wn(r){return r0(to(r))}function qr(r){return mh(r),r0(to(Uint8Array.from(r).reverse()))}function Wo(r,e){return Pa(r.toString(16).padStart(e*2,"0"))}function ro(r,e){return Wo(r,e).reverse()}function Me(r,e,t){let n;if(typeof e=="string")try{n=Pa(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(ss(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function no(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];mh(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 ph=r=>typeof r=="bigint"&&yh<=r;function Zu(r,e,t){return ph(r)&&ph(e)&&ph(t)&&e<=r&&r<t}function It(r,e,t,n){if(!Zu(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function o0(r){let e;for(e=0;r>yh;r>>=dh,e+=1);return e}var qo=r=>(dh<<BigInt(r))-dh,hh=r=>new Uint8Array(r),t0=r=>Uint8Array.from(r);function i0(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=hh(r),o=hh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...f)=>t(o,n,...f),c=(f=hh(0))=>{o=a(t0([0]),f),n=a(),f.length!==0&&(o=a(t0([1]),f),n=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<e;){n=a();let v=n.slice();d.push(v),f+=n.length}return no(...d)};return(f,d)=>{s(),c(f);let v;for(;!(v=d(l()));)c();return s(),v}}var iS={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"||ss(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 Cr(r,e,t={}){let n=(o,i,s)=>{let a=iS[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 as(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 Lt=BigInt(0),ht=BigInt(1),Go=BigInt(2),sS=BigInt(3),a0=BigInt(4),c0=BigInt(5),u0=BigInt(8);function Pe(r,e){let t=r%e;return t>=Lt?t:e+t}function We(r,e,t){let n=r;for(;e-- >Lt;)n*=n,n%=t;return n}function Ju(r,e){if(r===Lt)throw new Error("invert: expected non-zero number");if(e<=Lt)throw new Error("invert: expected positive modulus, got "+e);let t=Pe(r,e),n=e,o=Lt,i=ht,s=ht,a=Lt;for(;t!==Lt;){let l=n/t,p=n%t,f=o-s*l,d=i-a*l;n=t,t=p,o=s,i=a,s=f,a=d}if(n!==ht)throw new Error("invert: does not exist");return Pe(o,e)}function l0(r,e){let t=(r.ORDER+ht)/a0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function aS(r,e){let t=(r.ORDER-c0)/u0,n=r.mul(e,Go),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Go),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 cS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-ht,t=0;for(;e%Go===Lt;)e/=Go,t++;let n=Go,o=bn(r);for(;s0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return l0;let i=o.pow(n,e),s=(e+ht)/Go;return function(c,l){if(c.is0(l))return l;if(s0(c,l)!==1)throw new Error("Cannot find square root");let p=t,f=c.mul(c.ONE,i),d=c.pow(l,e),v=c.pow(l,s);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let g=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===p)throw new Error("Cannot find square root");let _=ht<<BigInt(p-g-1),j=c.pow(f,_);p=g,f=c.sqr(j),d=c.mul(d,f),v=c.mul(v,j)}return v}}function uS(r){return r%a0===sS?l0:r%u0===c0?aS:cS(r)}var f0=(r,e)=>(Pe(r,e)&ht)===ht,lS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=lS.reduce((n,o)=>(n[o]="function",n),e);return Cr(r,t)}function fS(r,e,t){if(t<Lt)throw new Error("invalid exponent, negatives unsupported");if(t===Lt)return r.ONE;if(t===ht)return e;let n=r.ONE,o=e;for(;t>Lt;)t&ht&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ht;return n}function cs(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 s0(r,e){let t=(r.ORDER-ht)/Go,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 wh(r,e){e!==void 0&&ns(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function bn(r,e,t=!1,n={}){if(r<=Lt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=wh(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:qo(o),ZERO:Lt,ONE:ht,create:c=>Pe(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Lt<=c&&c<r},is0:c=>c===Lt,isOdd:c=>(c&ht)===ht,neg:c=>Pe(-c,r),eql:(c,l)=>c===l,sqr:c=>Pe(c*c,r),add:(c,l)=>Pe(c+l,r),sub:(c,l)=>Pe(c-l,r),mul:(c,l)=>Pe(c*l,r),pow:(c,l)=>fS(a,c,l),div:(c,l)=>Pe(c*Ju(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Ju(c,r),sqrt:n.sqrt||(c=>(s||(s=uS(r)),s(a,c))),toBytes:c=>t?ro(c,i):Wo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?qr(c):wn(c)},invertBatch:c=>cs(a,c),cmov:(c,l,p)=>p?l:c});return Object.freeze(a)}function p0(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 bh(r){let e=p0(r);return e+Math.ceil(e/2)}function h0(r,e,t=!1){let n=r.length,o=p0(e),i=bh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?qr(r):wn(r),a=Pe(s,e-ht)+ht;return t?ro(a,o):Wo(a,o)}var d0=BigInt(0),Sh=BigInt(1);function xh(r,e){let t=e.negate();return r?t:e}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 vh(r,e){m0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=qo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function y0(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=Sh);let l=e*n,p=l+Math.abs(a)-1,f=a===0,d=a<0,v=e%2!==0;return{nextN:c,offset:p,isZero:f,isNeg:d,isNegF:v,offsetF:l}}function pS(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 hS(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 Ah=new WeakMap,g0=new WeakMap;function _h(r){return g0.get(r)||1}function Qu(r,e){return{constTimeNegate:xh,hasPrecomputes(t){return _h(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>d0;)n&Sh&&(o=o.add(i)),i=i.double(),n>>=Sh;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=vh(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=vh(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:p,isZero:f,isNeg:d,isNegF:v,offsetF:g}=y0(o,c,a);o=l,f?s=s.add(xh(v,n[g])):i=i.add(xh(d,n[p]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=vh(t,e);for(let a=0;a<s.windows&&o!==d0;a++){let{nextN:c,offset:l,isZero:p,isNeg:f}=y0(o,a,s);if(o=c,!p){let d=n[l];i=i.add(f?d.negate():d)}}return i},getPrecomputes(t,n,o){let i=Ah.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&Ah.set(n,o(i))),i},wNAFCached(t,n,o){let i=_h(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=_h(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),Ah.delete(t)}}}function el(r,e,t,n){pS(t,r),hS(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=o0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=qo(c),p=new Array(Number(l)+1).fill(s),f=Math.floor((e.BITS-1)/c)*c,d=s;for(let v=f;v>=0;v-=c){p.fill(s);for(let w=0;w<i;w++){let _=n[w],j=Number(_>>BigInt(v)&l);p[j]=p[j].add(t[w])}let g=s;for(let w=p.length-1,_=s;w>0;w--)_=_.add(p[w]),g=g.add(_);if(d=d.add(g),v!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Ba(r){return gh(r.Fp),Cr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...wh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Gr=BigInt(0),Ut=BigInt(1),w0=BigInt(2),dS=BigInt(8),yS={zip215:!0};function mS(r){let e=Ba(r);return Cr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function b0(r){let e=mS(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,l=w0<<BigInt(a*8)-Ut,p=t.create,f=bn(e.n,e.nBitLength);function d(k,y){let T=t.sqr(k),L=t.sqr(y),I=t.add(t.mul(e.a,T),L),oe=t.add(t.ONE,t.mul(e.d,t.mul(T,L)));return t.eql(I,oe)}if(!d(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let v=e.uvRatio||((k,y)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(y))}}catch{return{isValid:!1,value:Gr}}}),g=e.adjustScalarBytes||(k=>k),w=e.domain||((k,y,T)=>{if(Wr("phflag",T),y.length||T)throw new Error("Contexts/pre-hash are not supported");return k});function _(k,y,T=!1){let L=T?Ut:Gr;It("coordinate "+k,y,L,l)}function j(k){if(!(k instanceof x))throw new Error("ExtendedPoint expected")}let J=as((k,y)=>{let{ex:T,ey:L,ez:I}=k,oe=k.is0();y==null&&(y=oe?dS:t.inv(I));let pe=p(T*y),te=p(L*y),de=p(I*y);if(oe)return{x:Gr,y:Ut};if(de!==Ut)throw new Error("invZ was invalid");return{x:pe,y:te}}),O=as(k=>{let{a:y,d:T}=e;if(k.is0())throw new Error("bad point: ZERO");let{ex:L,ey:I,ez:oe,et:pe}=k,te=p(L*L),de=p(I*I),ye=p(oe*oe),Ce=p(ye*ye),Te=p(te*y),Re=p(ye*p(Te+de)),yt=p(Ce+p(T*p(te*de)));if(Re!==yt)throw new Error("bad point: equation left != right (1)");let $e=p(L*I),st=p(oe*pe);if($e!==st)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(y,T,L,I){_("x",y),_("y",T),_("z",L,!0),_("t",I),this.ex=y,this.ey=T,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 x)throw new Error("extended point not allowed");let{x:T,y:L}=y||{};return _("x",T),_("y",L),new x(T,L,Ut,p(T*L))}static normalizeZ(y){let T=cs(t,y.map(L=>L.ez));return y.map((L,I)=>L.toAffine(T[I])).map(x.fromAffine)}static msm(y,T){return el(x,f,y,T)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){O(this)}equals(y){j(y);let{ex:T,ey:L,ez:I}=this,{ex:oe,ey:pe,ez:te}=y,de=p(T*te),ye=p(oe*I),Ce=p(L*te),Te=p(pe*I);return de===ye&&Ce===Te}is0(){return this.equals(x.ZERO)}negate(){return new x(p(-this.ex),this.ey,this.ez,p(-this.et))}double(){let{a:y}=e,{ex:T,ey:L,ez:I}=this,oe=p(T*T),pe=p(L*L),te=p(w0*p(I*I)),de=p(y*oe),ye=T+L,Ce=p(p(ye*ye)-oe-pe),Te=de+pe,Re=Te-te,yt=de-pe,$e=p(Ce*Re),st=p(Te*yt),jt=p(Ce*yt),Rt=p(Re*Te);return new x($e,st,Rt,jt)}add(y){j(y);let{a:T,d:L}=e,{ex:I,ey:oe,ez:pe,et:te}=this,{ex:de,ey:ye,ez:Ce,et:Te}=y,Re=p(I*de),yt=p(oe*ye),$e=p(te*L*Te),st=p(pe*Ce),jt=p((I+oe)*(de+ye)-Re-yt),Rt=st-$e,Wn=st+$e,ha=p(yt-T*Re),Iu=p(jt*Rt),Ou=p(Wn*ha),Pu=p(jt*ha),da=p(Rt*Wn);return new x(Iu,Ou,da,Pu)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,x.normalizeZ)}multiply(y){let T=y;It("scalar",T,Ut,n);let{p:L,f:I}=this.wNAF(T);return x.normalizeZ([L,I])[0]}multiplyUnsafe(y,T=x.ZERO){let L=y;return It("scalar",L,Gr,n),L===Gr?$:this.is0()||L===Ut?this:N.wNAFCachedUnsafe(this,L,x.normalizeZ,T)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return J(this,y)}clearCofactor(){let{h:y}=e;return y===Ut?this:this.multiplyUnsafe(y)}static fromHex(y,T=!1){let{d:L,a:I}=e,oe=t.BYTES;y=Me("pointHex",y,oe),Wr("zip215",T);let pe=y.slice(),te=y[oe-1];pe[oe-1]=te&-129;let de=qr(pe),ye=T?l:t.ORDER;It("pointHex.y",de,Gr,ye);let Ce=p(de*de),Te=p(Ce-Ut),Re=p(L*Ce-I),{isValid:yt,value:$e}=v(Te,Re);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let st=($e&Ut)===Ut,jt=(te&128)!==0;if(!T&&$e===Gr&&jt)throw new Error("Point.fromHex: x=0 and x_0=1");return jt!==st&&($e=p(-$e)),x.fromAffine({x:$e,y:de})}static fromPrivateKey(y){let{scalar:T}=Z(y);return D.multiply(T)}toRawBytes(){let{x:y,y:T}=this.toAffine(),L=ro(T,t.BYTES);return L[L.length-1]|=y&Ut?128:0,L}toHex(){return to(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,Ut,p(e.Gx*e.Gy)),x.ZERO=new x(Gr,Ut,Ut,Gr);let{BASE:D,ZERO:$}=x,N=Qu(x,a*8);function U(k){return Pe(k,n)}function F(k){return U(qr(k))}function Z(k){let y=t.BYTES;k=Me("private key",k,y);let T=Me("hashed private key",i(k),2*y),L=g(T.slice(0,y)),I=T.slice(y,2*y),oe=F(L);return{head:L,prefix:I,scalar:oe}}function K(k){let{head:y,prefix:T,scalar:L}=Z(k),I=D.multiply(L),oe=I.toRawBytes();return{head:y,prefix:T,scalar:L,point:I,pointBytes:oe}}function X(k){return K(k).pointBytes}function W(k=Uint8Array.of(),...y){let T=no(...y);return F(i(w(T,Me("context",k),!!o)))}function ae(k,y,T={}){k=Me("message",k),o&&(k=o(k));let{prefix:L,scalar:I,pointBytes:oe}=K(y),pe=W(T.context,L,k),te=D.multiply(pe).toRawBytes(),de=W(T.context,te,oe,k),ye=U(pe+de*I);It("signature.s",ye,Gr,n);let Ce=no(te,ro(ye,t.BYTES));return Me("result",Ce,t.BYTES*2)}let B=yS;function R(k,y,T,L=B){let{context:I,zip215:oe}=L,pe=t.BYTES;k=Me("signature",k,2*pe),y=Me("message",y),T=Me("publicKey",T,pe),oe!==void 0&&Wr("zip215",oe),o&&(y=o(y));let te=qr(k.slice(pe,2*pe)),de,ye,Ce;try{de=x.fromHex(T,oe),ye=x.fromHex(k.slice(0,pe),oe),Ce=D.multiplyUnsafe(te)}catch{return!1}if(!oe&&de.isSmallOrder())return!1;let Te=W(I,ye.toRawBytes(),de.toRawBytes(),y);return ye.add(de.multiplyUnsafe(Te)).subtract(Ce).clearCofactor().equals(x.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:X,sign:ae,verify:R,ExtendedPoint:x,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>s(t.BYTES),precompute(k=8,y=x.BASE){return y._setWindowSize(k),y.multiply(BigInt(3)),y}}}}var ka=BigInt(0),us=BigInt(1),tl=BigInt(2);function gS(r){return Cr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function x0(r){let e=gS(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,l=BigInt(s?9:5),p=BigInt(s?121665:39081),f=s?tl**BigInt(254):tl**BigInt(447),d=s?BigInt(8)*tl**BigInt(251)-us:BigInt(4)*tl**BigInt(445)-us,v=f+d+us,g=N=>Pe(N,t),w=_(l);function _(N){return ro(g(N),c)}function j(N){let U=Me("u coordinate",N,c);return s&&(U[31]&=127),g(qr(U))}function J(N){return qr(o(Me("scalar",N,c)))}function O(N,U){let F=$(j(U),J(N));if(F===ka)throw new Error("invalid private or public key received");return _(F)}function x(N){return O(N,w)}function D(N,U,F){let Z=g(N*(U-F));return U=g(U-Z),F=g(F+Z),{x_2:U,x_3:F}}function $(N,U){It("u",N,ka,t),It("scalar",U,f,v);let F=U,Z=N,K=us,X=ka,W=N,ae=us,B=ka;for(let H=BigInt(a-1);H>=ka;H--){let k=F>>H&us;B^=k,{x_2:K,x_3:W}=D(B,K,W),{x_2:X,x_3:ae}=D(B,X,ae),B=k;let y=K+X,T=g(y*y),L=K-X,I=g(L*L),oe=T-I,pe=W+ae,te=W-ae,de=g(te*y),ye=g(pe*L),Ce=de+ye,Te=de-ye;W=g(Ce*Ce),ae=g(Z*g(Te*Te)),K=g(T*I),X=g(oe*(T+g(p*oe)))}({x_2:K,x_3:W}=D(B,K,W)),{x_2:X,x_3:ae}=D(B,X,ae);let R=i(X);return g(K*R)}return{scalarMult:O,scalarMultBase:x,getSharedSecret:(N,U)=>O(N,U),getPublicKey:N=>x(N),utils:{randomPrivateKey:()=>e.randomBytes(c)},GuBytes:w.slice()}}var Na=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),v0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),RO=BigInt(0),wS=BigInt(1),A0=BigInt(2),bS=BigInt(3),xS=BigInt(5),vS=BigInt(8);function S0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Na,a=r*r%i*r%i,c=We(a,A0,i)*a%i,l=We(c,wS,i)*r%i,p=We(l,xS,i)*l%i,f=We(p,e,i)*p%i,d=We(f,t,i)*f%i,v=We(d,n,i)*d%i,g=We(v,o,i)*v%i,w=We(g,o,i)*v%i,_=We(w,e,i)*p%i;return{pow_p_5_8:We(_,A0,i)*r%i,b2:a}}function E0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function AS(r,e){let t=Na,n=Pe(e*e*e,t),o=Pe(n*n*e,t),i=S0(r*o).pow_p_5_8,s=Pe(r*n*i,t),a=Pe(e*s*s,t),c=s,l=Pe(s*v0,t),p=a===r,f=a===Pe(-r,t),d=a===Pe(-r*v0,t);return p&&(s=c),(f||d)&&(s=l),f0(s,t)&&(s=Pe(-s,t)),{isValid:p||f,value:s}}var _0=bn(Na,void 0,!0),_S={a:_0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:_0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:vS,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Qg,randomBytes:Ea,adjustScalarBytes:E0,uvRatio:AS},ja=b0(_S);var Ra=x0({P:Na,type:"x25519",powPminus2:r=>{let e=Na,{pow_p_5_8:t,b2:n}=S0(r);return Pe(We(t,bS,e)*n,e)},adjustScalarBytes:E0,randomBytes:Ea});var rl=32,nl=64,Eh=32;function C0(){let r=ja.utils.randomPrivateKey(),e=ja.getPublicKey(r);return{privateKey:SS(r,e),publicKey:e}}function T0(r,e){let t=r.subarray(0,Eh);return ja.sign(e instanceof Uint8Array?e:e.subarray(),t)}function I0(r,e,t){return ja.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}function SS(r,e){let t=new Uint8Array(nl);for(let n=0;n<Eh;n++)t[n]=r[n],t[Eh+n]=e[n];return t}var Da=class{type="Ed25519";raw;constructor(e){this.raw=il(e,rl)}toMultihash(){return Ar.digest(Yn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){return n?.signal?.throwIfAborted(),I0(this.raw,t,e)}},ol=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=il(e,nl),this.publicKey=new Da(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return t?.signal?.throwIfAborted(),T0(this.raw,e)}};function Ch(r){return r=il(r,rl),new Da(r)}async function P0(){let{privateKey:r,publicKey:e}=C0();return new ol(r,e)}function il(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Se(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var ES=Math.pow(2,7),CS=Math.pow(2,14),TS=Math.pow(2,21),Th=Math.pow(2,28),Ih=Math.pow(2,35),Oh=Math.pow(2,42),Ph=Math.pow(2,49),Ne=128,Ot=127;function qe(r){if(r<ES)return 1;if(r<CS)return 2;if(r<TS)return 3;if(r<Th)return 4;if(r<Ih)return 5;if(r<Oh)return 6;if(r<Ph)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Bh(r,e,t=0){switch(qe(r)){case 8:e[t++]=r&255|Ne,r/=128;case 7:e[t++]=r&255|Ne,r/=128;case 6:e[t++]=r&255|Ne,r/=128;case 5:e[t++]=r&255|Ne,r/=128;case 4:e[t++]=r&255|Ne,r>>>=7;case 3:e[t++]=r&255|Ne,r>>>=7;case 2:e[t++]=r&255|Ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function IS(r,e,t=0){switch(qe(r)){case 8:e.set(t++,r&255|Ne),r/=128;case 7:e.set(t++,r&255|Ne),r/=128;case 6:e.set(t++,r&255|Ne),r/=128;case 5:e.set(t++,r&255|Ne),r/=128;case 4:e.set(t++,r&255|Ne),r>>>=7;case 3:e.set(t++,r&255|Ne),r>>>=7;case 2:e.set(t++,r&255|Ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function kh(r,e){let t=r[e],n=0;if(n+=t&Ot,t<Ne||(t=r[e+1],n+=(t&Ot)<<7,t<Ne)||(t=r[e+2],n+=(t&Ot)<<14,t<Ne)||(t=r[e+3],n+=(t&Ot)<<21,t<Ne)||(t=r[e+4],n+=(t&Ot)*Th,t<Ne)||(t=r[e+5],n+=(t&Ot)*Ih,t<Ne)||(t=r[e+6],n+=(t&Ot)*Oh,t<Ne)||(t=r[e+7],n+=(t&Ot)*Ph,t<Ne))return n;throw new RangeError("Could not decode varint")}function OS(r,e){let t=r.get(e),n=0;if(n+=t&Ot,t<Ne||(t=r.get(e+1),n+=(t&Ot)<<7,t<Ne)||(t=r.get(e+2),n+=(t&Ot)<<14,t<Ne)||(t=r.get(e+3),n+=(t&Ot)<<21,t<Ne)||(t=r.get(e+4),n+=(t&Ot)*Th,t<Ne)||(t=r.get(e+5),n+=(t&Ot)*Ih,t<Ne)||(t=r.get(e+6),n+=(t&Ot)*Oh,t<Ne)||(t=r.get(e+7),n+=(t&Ot)*Ph,t<Ne))return n;throw new RangeError("Could not decode varint")}function zr(r,e,t=0){return e==null&&(e=ut(qe(r))),e instanceof Uint8Array?Bh(r,e,t):IS(r,e,t)}function Tr(r,e=0){return r instanceof Uint8Array?kh(r,e):OS(r,e)}var Nh=new Float32Array([-0]),oo=new Uint8Array(Nh.buffer);function B0(r,e,t){Nh[0]=r,e[t]=oo[0],e[t+1]=oo[1],e[t+2]=oo[2],e[t+3]=oo[3]}function k0(r,e){return oo[0]=r[e],oo[1]=r[e+1],oo[2]=r[e+2],oo[3]=r[e+3],Nh[0]}var jh=new Float64Array([-0]),Pt=new Uint8Array(jh.buffer);function N0(r,e,t){jh[0]=r,e[t]=Pt[0],e[t+1]=Pt[1],e[t+2]=Pt[2],e[t+3]=Pt[3],e[t+4]=Pt[4],e[t+5]=Pt[5],e[t+6]=Pt[6],e[t+7]=Pt[7]}function j0(r,e){return Pt[0]=r[e],Pt[1]=r[e+1],Pt[2]=r[e+2],Pt[3]=r[e+3],Pt[4]=r[e+4],Pt[5]=r[e+5],Pt[6]=r[e+6],Pt[7]=r[e+7],jh[0]}var PS=BigInt(Number.MAX_SAFE_INTEGER),BS=BigInt(Number.MIN_SAFE_INTEGER),tr=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return zo;if(e<PS&&e>BS)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>R0&&(o=0n,++n>R0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return zo;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):zo}},zo=new tr(0,0);zo.toBigInt=function(){return 0n};zo.zzEncode=zo.zzDecode=function(){return this};zo.length=function(){return 1};var R0=4294967296n;function D0(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 L0(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 Rh(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Ir(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function sl(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Dh=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ir(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ir(this,4);return sl(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ir(this,4);return sl(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ir(this,4);let e=k0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ir(this,4);let e=j0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Ir(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return L0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ir(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ir(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new tr(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ir(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ir(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ir(this,8);let e=sl(this.buf,this.pos+=4),t=sl(this.buf,this.pos+=4);return new tr(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=kh(this.buf,this.pos);return this.pos+=qe(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 Lh(r){return new Dh(r instanceof Uint8Array?r:r.subarray())}function Or(r,e,t){let n=Lh(r);return e.decode(n,void 0,t)}function Uh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ut(s);o+s>e&&(n=ut(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Xo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Mh(){}var Hh=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},kS=Uh();function NS(r){return globalThis.Buffer!=null?ut(r):kS(r)}var Ma=class{len;head;tail;states;constructor(){this.len=0,this.head=new Xo(Mh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Xo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Vh((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(al,10,tr.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=tr.fromBigInt(e);return this._push(al,t.length(),t)}uint64Number(e){return this._push(Bh,qe(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=tr.fromBigInt(e).zzEncode();return this._push(al,t.length(),t)}sint64Number(e){let t=tr.fromNumber(e).zzEncode();return this._push(al,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Kh,1,e?1:0)}fixed32(e){return this._push(Ua,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=tr.fromBigInt(e);return this._push(Ua,4,t.lo)._push(Ua,4,t.hi)}fixed64Number(e){let t=tr.fromNumber(e);return this._push(Ua,4,t.lo)._push(Ua,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(B0,4,e)}double(e){return this._push(N0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Kh,1,0):this.uint32(t)._push(RS,t,e)}string(e){let t=D0(e);return t!==0?this.uint32(t)._push(Rh,t,e):this._push(Kh,1,0)}fork(){return this.states=new Hh(this),this.head=this.tail=new Xo(Mh,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 Xo(Mh,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=NS(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Kh(r,e,t){e[t]=r&255}function jS(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Vh=class extends Xo{next;constructor(e,t){super(jS,e,t),this.next=void 0}};function al(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Ua(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function RS(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Ma.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(DS,e,r),this},Ma.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(LS,e,r),this});function DS(r,e,t){e.set(r,t)}function LS(r,e,t){r.length<40?Rh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(me(r),t)}function $h(){return new Ma}function Pr(r,e){let t=$h();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ls;(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"})(ls||(ls={}));function cl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Yo(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 cl("enum",ls.VARINT,t,n)}function Br(r,e){return cl("message",ls.LENGTH_DELIMITED,r,e)}var Ka=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(rt||(rt={}));var Fh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Fh||(Fh={}));(function(r){r.codec=()=>Yo(Fh)})(rt||(rt={}));var Xr;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Xr||(Xr={}));var Wh;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Wh||(Wh={}));var Ha=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Va=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},ul=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var K0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new ul("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 io=K0;var Fa={};Ct(Fa,{MAX_RSA_KEY_SIZE:()=>qh,generateRSAKeyPair:()=>td,jwkToJWKKeyPair:()=>F0,jwkToPkcs1:()=>HS,jwkToPkix:()=>Yh,jwkToRSAPrivateKey:()=>ed,pkcs1MessageToJwk:()=>zh,pkcs1MessageToRSAPrivateKey:()=>Zh,pkcs1ToJwk:()=>KS,pkcs1ToRSAPrivateKey:()=>$0,pkixMessageToJwk:()=>Xh,pkixMessageToRSAPublicKey:()=>Qh,pkixToJwk:()=>VS,pkixToRSAPublicKey:()=>Jh});var so=Yu;var fs=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=Fa.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){return V0(this.jwk,t,e,n)}},$a=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Fa.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return H0(this.jwk,e,t)}};var qh=8192,Gh=18,US=1062,MS=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function KS(r){let e=yn(r);return zh(e)}function zh(r){return{n:fe(r[1],"base64url"),e:fe(r[2],"base64url"),d:fe(r[3],"base64url"),p:fe(r[4],"base64url"),q:fe(r[5],"base64url"),dp:fe(r[6],"base64url"),dq:fe(r[7],"base64url"),qi:fe(r[8],"base64url"),kty:"RSA"}}function HS(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 Se("JWK was missing components");return _r([Dt(Uint8Array.from([0])),Dt(me(r.n,"base64url")),Dt(me(r.e,"base64url")),Dt(me(r.d,"base64url")),Dt(me(r.p,"base64url")),Dt(me(r.q,"base64url")),Dt(me(r.dp,"base64url")),Dt(me(r.dq,"base64url")),Dt(me(r.qi,"base64url"))]).subarray()}function VS(r){let e=yn(r,{offset:0});return Xh(e)}function Xh(r){let e=yn(r[1],{offset:0});return{kty:"RSA",n:fe(e[0],"base64url"),e:fe(e[1],"base64url")}}function Yh(r){if(r.n==null||r.e==null)throw new Se("JWK was missing components");return _r([MS,_a(_r([Dt(me(r.n,"base64url")),Dt(me(r.e,"base64url"))]))]).subarray()}function $0(r){let e=yn(r);return Zh(e)}function Zh(r){let e=zh(r);return ed(e)}function Jh(r,e){if(r.byteLength>=US)throw new Ji("Key size is too large");let t=yn(r,{offset:0});return Qh(t,r,e)}function Qh(r,e,t){let n=Xh(r);if(t==null){let o=so(Xr.encode({Type:rt.RSA,Data:e}));t=Tt(Gh,o)}return new fs(n,t)}function ed(r){if(q0(r)>qh)throw new Se("Key size is too large");let e=F0(r),t=so(Xr.encode({Type:rt.RSA,Data:Yh(e.publicKey)})),n=Tt(Gh,t);return new $a(e.privateKey,new fs(e.publicKey,n))}async function td(r){if(r>qh)throw new Se("Key size is too large");let e=await W0(r),t=so(Xr.encode({Type:rt.RSA,Data:Yh(e.publicKey)})),n=Tt(Gh,t);return new $a(e.privateKey,new fs(e.publicKey,n))}function F0(r){if(r==null)throw new Se("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function W0(r,e){let t=await io.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 $S(t,e);return{privateKey:n[0],publicKey:n[1]}}async function H0(r,e,t){let n=await io.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await io.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 io.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await io.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function $S(r,e){if(r.privateKey==null||r.publicKey==null)throw new Se("Private and public key are required");let t=await Promise.all([io.get().subtle.exportKey("jwk",r.privateKey),io.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function q0(r){if(r.kty!=="RSA")throw new Se("invalid key type");if(r.n==null)throw new Se("invalid key modulus");return me(r.n,"base64url").length*8}var ll=class extends os{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Sa(e);let n=Zn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Sr(i)}update(e){return is(this),this.iHash.update(e),this}digestInto(e){is(this),Vo(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()}},ps=(r,e,t)=>new ll(r,e).update(t).digest();ps.create=(r,e)=>new ll(r,e);function G0(r){r.lowS!==void 0&&Wr("lowS",r.lowS),r.prehash!==void 0&&Wr("prehash",r.prehash)}function FS(r){let e=Ba(r);Cr(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 od=class extends Error{constructor(e=""){super(e)}},xn={Err:od,_tlv:{encode:(r,e)=>{let{Err:t}=xn;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=Oa(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Oa(o.length/2|128):"";return Oa(r)+i+o+e},decode(r,e){let{Err:t}=xn,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let l=e.subarray(n,n+c);if(l.length!==c)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let 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}=xn;if(r<vn)throw new e("integer: negative integers are not allowed");let t=Oa(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=xn;if(r[0]&128)throw new e("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return wn(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=xn,o=Me("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}=xn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}};function rd(r,e){return to(Wo(r,e))}var vn=BigInt(0),dt=BigInt(1),iB=BigInt(2),nd=BigInt(3),WS=BigInt(4);function qS(r){let e=FS(r),{Fp:t}=e,n=bn(e.n,e.nBitLength),o=e.toBytes||((O,x,D)=>{let $=x.toAffine();return no(Uint8Array.from([4]),t.toBytes($.x),t.toBytes($.y))}),i=e.fromBytes||(O=>{let x=O.subarray(1),D=t.fromBytes(x.subarray(0,t.BYTES)),$=t.fromBytes(x.subarray(t.BYTES,2*t.BYTES));return{x:D,y:$}});function s(O){let{a:x,b:D}=e,$=t.sqr(O),N=t.mul($,O);return t.add(t.add(N,t.mul(O,x)),D)}function a(O,x){let D=t.sqr(x),$=s(O);return t.eql(D,$)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=t.mul(t.pow(e.a,nd),WS),l=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(c,l)))throw new Error("bad curve params: a or b");function p(O){return Zu(O,dt,e.n)}function f(O){let{allowedPrivateKeyLengths:x,nByteLength:D,wrapPrivateKey:$,n:N}=e;if(x&&typeof O!="bigint"){if(ss(O)&&(O=to(O)),typeof O!="string"||!x.includes(O.length))throw new Error("invalid private key");O=O.padStart(D*2,"0")}let U;try{U=typeof O=="bigint"?O:wn(Me("private key",O,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof O)}return $&&(U=Pe(U,N)),It("private key",U,dt,N),U}function d(O){if(!(O instanceof w))throw new Error("ProjectivePoint expected")}let v=as((O,x)=>{let{px:D,py:$,pz:N}=O;if(t.eql(N,t.ONE))return{x:D,y:$};let U=O.is0();x==null&&(x=U?t.ONE:t.inv(N));let F=t.mul(D,x),Z=t.mul($,x),K=t.mul(N,x);if(U)return{x:t.ZERO,y:t.ZERO};if(!t.eql(K,t.ONE))throw new Error("invZ was invalid");return{x:F,y:Z}}),g=as(O=>{if(O.is0()){if(e.allowInfinityPoint&&!t.is0(O.py))return;throw new Error("bad point: ZERO")}let{x,y:D}=O.toAffine();if(!t.isValid(x)||!t.isValid(D))throw new Error("bad point: x or y not FE");if(!a(x,D))throw new Error("bad point: equation left != right");if(!O.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(x,D,$){if(x==null||!t.isValid(x))throw new Error("x required");if(D==null||!t.isValid(D)||t.is0(D))throw new Error("y required");if($==null||!t.isValid($))throw new Error("z required");this.px=x,this.py=D,this.pz=$,Object.freeze(this)}static fromAffine(x){let{x:D,y:$}=x||{};if(!x||!t.isValid(D)||!t.isValid($))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");let N=U=>t.eql(U,t.ZERO);return N(D)&&N($)?w.ZERO:new w(D,$,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){let D=cs(t,x.map($=>$.pz));return x.map(($,N)=>$.toAffine(D[N])).map(w.fromAffine)}static fromHex(x){let D=w.fromAffine(i(Me("pointHex",x)));return D.assertValidity(),D}static fromPrivateKey(x){return w.BASE.multiply(f(x))}static msm(x,D){return el(w,n,x,D)}_setWindowSize(x){J.setWindowSize(this,x)}assertValidity(){g(this)}hasEvenY(){let{y:x}=this.toAffine();if(t.isOdd)return!t.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){d(x);let{px:D,py:$,pz:N}=this,{px:U,py:F,pz:Z}=x,K=t.eql(t.mul(D,Z),t.mul(U,N)),X=t.eql(t.mul($,Z),t.mul(F,N));return K&&X}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){let{a:x,b:D}=e,$=t.mul(D,nd),{px:N,py:U,pz:F}=this,Z=t.ZERO,K=t.ZERO,X=t.ZERO,W=t.mul(N,N),ae=t.mul(U,U),B=t.mul(F,F),R=t.mul(N,U);return R=t.add(R,R),X=t.mul(N,F),X=t.add(X,X),Z=t.mul(x,X),K=t.mul($,B),K=t.add(Z,K),Z=t.sub(ae,K),K=t.add(ae,K),K=t.mul(Z,K),Z=t.mul(R,Z),X=t.mul($,X),B=t.mul(x,B),R=t.sub(W,B),R=t.mul(x,R),R=t.add(R,X),X=t.add(W,W),W=t.add(X,W),W=t.add(W,B),W=t.mul(W,R),K=t.add(K,W),B=t.mul(U,F),B=t.add(B,B),W=t.mul(B,R),Z=t.sub(Z,W),X=t.mul(B,ae),X=t.add(X,X),X=t.add(X,X),new w(Z,K,X)}add(x){d(x);let{px:D,py:$,pz:N}=this,{px:U,py:F,pz:Z}=x,K=t.ZERO,X=t.ZERO,W=t.ZERO,ae=e.a,B=t.mul(e.b,nd),R=t.mul(D,U),H=t.mul($,F),k=t.mul(N,Z),y=t.add(D,$),T=t.add(U,F);y=t.mul(y,T),T=t.add(R,H),y=t.sub(y,T),T=t.add(D,N);let L=t.add(U,Z);return T=t.mul(T,L),L=t.add(R,k),T=t.sub(T,L),L=t.add($,N),K=t.add(F,Z),L=t.mul(L,K),K=t.add(H,k),L=t.sub(L,K),W=t.mul(ae,T),K=t.mul(B,k),W=t.add(K,W),K=t.sub(H,W),W=t.add(H,W),X=t.mul(K,W),H=t.add(R,R),H=t.add(H,R),k=t.mul(ae,k),T=t.mul(B,T),H=t.add(H,k),k=t.sub(R,k),k=t.mul(ae,k),T=t.add(T,k),R=t.mul(H,T),X=t.add(X,R),R=t.mul(L,T),K=t.mul(y,K),K=t.sub(K,R),R=t.mul(y,H),W=t.mul(L,W),W=t.add(W,R),new w(K,X,W)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}wNAF(x){return J.wNAFCached(this,x,w.normalizeZ)}multiplyUnsafe(x){let{endo:D,n:$}=e;It("scalar",x,vn,$);let N=w.ZERO;if(x===vn)return N;if(this.is0()||x===dt)return this;if(!D||J.hasPrecomputes(this))return J.wNAFCachedUnsafe(this,x,w.normalizeZ);let{k1neg:U,k1:F,k2neg:Z,k2:K}=D.splitScalar(x),X=N,W=N,ae=this;for(;F>vn||K>vn;)F&dt&&(X=X.add(ae)),K&dt&&(W=W.add(ae)),ae=ae.double(),F>>=dt,K>>=dt;return U&&(X=X.negate()),Z&&(W=W.negate()),W=new w(t.mul(W.px,D.beta),W.py,W.pz),X.add(W)}multiply(x){let{endo:D,n:$}=e;It("scalar",x,dt,$);let N,U;if(D){let{k1neg:F,k1:Z,k2neg:K,k2:X}=D.splitScalar(x),{p:W,f:ae}=this.wNAF(Z),{p:B,f:R}=this.wNAF(X);W=J.constTimeNegate(F,W),B=J.constTimeNegate(K,B),B=new w(t.mul(B.px,D.beta),B.py,B.pz),N=W.add(B),U=ae.add(R)}else{let{p:F,f:Z}=this.wNAF(x);N=F,U=Z}return w.normalizeZ([N,U])[0]}multiplyAndAddUnsafe(x,D,$){let N=w.BASE,U=(Z,K)=>K===vn||K===dt||!Z.equals(N)?Z.multiplyUnsafe(K):Z.multiply(K),F=U(this,D).add(U(x,$));return F.is0()?void 0:F}toAffine(x){return v(this,x)}isTorsionFree(){let{h:x,isTorsionFree:D}=e;if(x===dt)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:x,clearCofactor:D}=e;return x===dt?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return Wr("isCompressed",x),this.assertValidity(),o(w,this,x)}toHex(x=!0){return Wr("isCompressed",x),to(this.toRawBytes(x))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);let{endo:_,nBitLength:j}=e,J=Qu(w,_?Math.ceil(j/2):j);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:f,weierstrassEquation:s,isWithinCurveOrder:p}}function GS(r){let e=Ba(r);return Cr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function z0(r){let e=GS(r),{Fp:t,n,nByteLength:o,nBitLength:i}=e,s=t.BYTES+1,a=2*t.BYTES+1;function c(B){return Pe(B,n)}function l(B){return Ju(B,n)}let{ProjectivePoint:p,normPrivateKeyToScalar:f,weierstrassEquation:d,isWithinCurveOrder:v}=qS({...e,toBytes(B,R,H){let k=R.toAffine(),y=t.toBytes(k.x),T=no;return Wr("isCompressed",H),H?T(Uint8Array.from([R.hasEvenY()?2:3]),y):T(Uint8Array.from([4]),y,t.toBytes(k.y))},fromBytes(B){let R=B.length,H=B[0],k=B.subarray(1);if(R===s&&(H===2||H===3)){let y=wn(k);if(!Zu(y,dt,t.ORDER))throw new Error("Point is not on curve");let T=d(y),L;try{L=t.sqrt(T)}catch(pe){let te=pe instanceof Error?": "+pe.message:"";throw new Error("Point is not on curve"+te)}let I=(L&dt)===dt;return(H&1)===1!==I&&(L=t.neg(L)),{x:y,y:L}}else if(R===a&&H===4){let y=t.fromBytes(k.subarray(0,t.BYTES)),T=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:y,y:T}}else{let y=s,T=a;throw new Error("invalid Point, expected length of "+y+", or uncompressed "+T+", got "+R)}}});function g(B){let R=n>>dt;return B>R}function w(B){return g(B)?c(-B):B}let _=(B,R,H)=>wn(B.slice(R,H));class j{constructor(R,H,k){It("r",R,dt,n),It("s",H,dt,n),this.r=R,this.s=H,k!=null&&(this.recovery=k),Object.freeze(this)}static fromCompact(R){let H=o;return R=Me("compactSignature",R,H*2),new j(_(R,0,H),_(R,H,2*H))}static fromDER(R){let{r:H,s:k}=xn.toSig(Me("DER",R));return new j(H,k)}assertValidity(){}addRecoveryBit(R){return new j(this.r,this.s,R)}recoverPublicKey(R){let{r:H,s:k,recovery:y}=this,T=N(Me("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let L=y===2||y===3?H+e.n:H;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let I=(y&1)===0?"02":"03",oe=p.fromHex(I+rd(L,t.BYTES)),pe=l(L),te=c(-T*pe),de=c(k*pe),ye=p.BASE.multiplyAndAddUnsafe(oe,te,de);if(!ye)throw new Error("point at infinify");return ye.assertValidity(),ye}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new j(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pa(this.toDERHex())}toDERHex(){return xn.hexFromSig(this)}toCompactRawBytes(){return Pa(this.toCompactHex())}toCompactHex(){let R=o;return rd(this.r,R)+rd(this.s,R)}}let J={isValidPrivateKey(B){try{return f(B),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let B=bh(e.n);return h0(e.randomBytes(B),e.n)},precompute(B=8,R=p.BASE){return R._setWindowSize(B),R.multiply(BigInt(3)),R}};function O(B,R=!0){return p.fromPrivateKey(B).toRawBytes(R)}function x(B){if(typeof B=="bigint")return!1;if(B instanceof p)return!0;let H=Me("key",B).length,k=t.BYTES,y=k+1,T=2*k+1;if(!(e.allowedPrivateKeyLengths||o===y))return H===y||H===T}function D(B,R,H=!0){if(x(B)===!0)throw new Error("first arg must be private key");if(x(R)===!1)throw new Error("second arg must be public key");return p.fromHex(R).multiply(f(B)).toRawBytes(H)}let $=e.bits2int||function(B){if(B.length>8192)throw new Error("input is too large");let R=wn(B),H=B.length*8-i;return H>0?R>>BigInt(H):R},N=e.bits2int_modN||function(B){return c($(B))},U=qo(i);function F(B){return It("num < 2^"+i,B,vn,U),Wo(B,o)}function Z(B,R,H=K){if(["recovered","canonical"].some(Te=>Te in H))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:y}=e,{lowS:T,prehash:L,extraEntropy:I}=H;T==null&&(T=!0),B=Me("msgHash",B),G0(H),L&&(B=Me("prehashed msgHash",k(B)));let oe=N(B),pe=f(R),te=[F(pe),F(oe)];if(I!=null&&I!==!1){let Te=I===!0?y(t.BYTES):I;te.push(Me("extraEntropy",Te))}let de=no(...te),ye=oe;function Ce(Te){let Re=$(Te);if(!v(Re))return;let yt=l(Re),$e=p.BASE.multiply(Re).toAffine(),st=c($e.x);if(st===vn)return;let jt=c(yt*c(ye+st*pe));if(jt===vn)return;let Rt=($e.x===st?0:2)|Number($e.y&dt),Wn=jt;return T&&g(jt)&&(Wn=w(jt),Rt^=1),new j(st,Wn,Rt)}return{seed:de,k2sig:Ce}}let K={lowS:e.lowS,prehash:!1},X={lowS:e.lowS,prehash:!1};function W(B,R,H=K){let{seed:k,k2sig:y}=Z(B,R,H),T=e;return i0(T.hash.outputLen,T.nByteLength,T.hmac)(k,y)}p.BASE._setWindowSize(8);function ae(B,R,H,k=X){let y=B;R=Me("msgHash",R),H=Me("publicKey",H);let{lowS:T,prehash:L,format:I}=k;if(G0(k),"strict"in k)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 oe=typeof y=="string"||ss(y),pe=!oe&&!I&&typeof y=="object"&&y!==null&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!oe&&!pe)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let te,de;try{if(pe&&(te=new j(y.r,y.s)),oe){try{I!=="compact"&&(te=j.fromDER(y))}catch(Rt){if(!(Rt instanceof xn.Err))throw Rt}!te&&I!=="der"&&(te=j.fromCompact(y))}de=p.fromHex(H)}catch{return!1}if(!te||T&&te.hasHighS())return!1;L&&(R=e.hash(R));let{r:ye,s:Ce}=te,Te=N(R),Re=l(Ce),yt=c(Te*Re),$e=c(ye*Re),st=p.BASE.multiplyAndAddUnsafe(de,yt,$e)?.toAffine();return st?c(st.x)===ye:!1}return{CURVE:e,getPublicKey:O,getSharedSecret:D,sign:W,verify:ae,ProjectivePoint:p,Signature:j,utils:J}}function zS(r){return{hash:r,hmac:(e,...t)=>ps(r,e,ah(...t)),randomBytes:Ea}}function X0(r,e){let t=n=>z0({...r,...zS(n)});return{...t(e),create:t}}var J0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Y0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),XS=BigInt(0),YS=BigInt(1),id=BigInt(2),Z0=(r,e)=>(r+e/id)/e;function ZS(r){let e=J0,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=We(p,t,e)*p%e,d=We(f,t,e)*p%e,v=We(d,id,e)*l%e,g=We(v,o,e)*v%e,w=We(g,i,e)*g%e,_=We(w,a,e)*w%e,j=We(_,c,e)*_%e,J=We(j,a,e)*w%e,O=We(J,t,e)*p%e,x=We(O,s,e)*g%e,D=We(x,n,e)*l%e,$=We(D,id,e);if(!sd.eql(sd.sqr($),r))throw new Error("Cannot find square root");return $}var sd=bn(J0,void 0,void 0,{sqrt:ZS}),kr=X0({a:XS,b:BigInt(7),Fp:sd,n:Y0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Y0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-YS*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=Z0(i*r,e),c=Z0(-n*r,e),l=Pe(r-a*t-c*o,e),p=Pe(-a*n-c*i,e),f=l>s,d=p>s;if(f&&(l=e-l),d&&(p=e-p),l>s||p>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:p}}}},Yu);function ad(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Q0(r,e,t){let n=ar.digest(e instanceof Uint8Array?e:e.subarray());if(ad(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),kr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ha(String(o))});try{return kr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Ha(String(o))}}function ew(r,e,t,n){let o=ar.digest(t instanceof Uint8Array?t:t.subarray());if(ad(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),kr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Va(String(i))});try{return n?.signal?.throwIfAborted(),kr.verify(e,o.digest,r)}catch(i){throw new Va(String(i))}}var Wa=class{type="secp256k1";raw;_key;constructor(e){this._key=nw(e),this.raw=tw(this._key)}toMultihash(){return Ar.digest(Yn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){return ew(this._key,t,e,n)}},fl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=rw(e),this.publicKey=new Wa(t??ow(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return Q0(this.raw,e,t)}};function cd(r){return new Wa(r)}async function iw(){let r=JS();return new fl(r)}function tw(r){return kr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function rw(r){try{return kr.getPublicKey(r,!0),r}catch(e){throw new ma(String(e))}}function nw(r){try{return kr.ProjectivePoint.fromHex(r),r}catch(e){throw new Ji(String(e))}}function ow(r){try{return kr.getPublicKey(r,!0)}catch(e){throw new ma(String(e))}}function JS(){return kr.utils.randomPrivateKey()}async function sw(r,e){if(r==="Ed25519")return P0();if(r==="secp256k1")return iw();if(r==="RSA")return td(QS(e));if(r==="ECDSA")return Mg(eE(e));throw new qn}function qa(r,e){let{Type:t,Data:n}=Xr.decode(r),o=n??new Uint8Array;switch(t){case rt.RSA:return Jh(o,e);case rt.Ed25519:return Ch(o);case rt.secp256k1:return cd(o);case rt.ECDSA:return sh(o);default:throw new qn}}function aw(r){let{Type:e,Data:t}=Xr.decode(r.digest),n=t??new Uint8Array;switch(e){case rt.Ed25519:return Ch(n);case rt.secp256k1:return cd(n);case rt.ECDSA:return sh(n);default:throw new qn}}function Yn(r){return Xr.encode({Type:rt[r.type],Data:r.raw})}function QS(r){return r==null?2048:parseInt(r,10)}function eE(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new Se("Unsupported curve, should be P-256, P-384 or P-521")}async function pl(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 Se("Only RSA and ECDSA keys are supported")}var cw=Symbol.for("nodejs.util.inspect.custom"),tE=114,Ga=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()})`}[Np]=!0;toString(){return this.string==null&&(this.string=De.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(tE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ye(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ye(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[cw](){return`PeerId(${this.toString()})`}},za=class extends Ga{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xa=class extends Ga{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Ya=class extends Ga{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},rE=2336,Za=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ar.digest(me(this.url))}[cw](){return`PeerId(${this.url})`}[Np]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(rE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=fe(e)),e.toString()===this.toString())}};var nE=114,uw=2336;function hs(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Xn(De.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return oE(tt.parse(r));if(e==null)throw new Se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Xn(e.decode(r))}return lw(t)}function ud(r){if(r.type==="Ed25519")return new Xa({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Ya({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new za({multihash:r.toCID().multihash,publicKey:r});throw new qn}function lw(r){if(sE(r))return new za({multihash:r});if(iE(r))try{let e=aw(r);if(e.type==="Ed25519")return new Xa({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Ya({multihash:r,publicKey:e})}catch{let t=fe(r.digest);return new Za(new URL(t))}throw new Uu("Supplied PeerID Multihash is invalid")}function oE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==nE&&r.code!==uw)throw new Lu("Supplied PeerID CID is invalid");if(r.code===uw){let e=fe(r.multihash.digest);return new Za(new URL(e))}return lw(r.multihash)}function iE(r){return r.code===Ar.code}function sE(r){return r.code===ar.code}var hl=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 d=Number.parseInt(f,e);if(!Number.isNaN(d))return d});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,aE=15,ds=new hl;function ld(r){if(!(r.length>aE))return ds.new(r).parseWith(()=>ds.readIPv4Addr())}function fd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fw))return ds.new(r).parseWith(()=>ds.readIPv6Addr())}function dl(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>fw)return;let t=ds.new(r).parseWith(()=>ds.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 w8=parseInt("0xFFFF",16),b8=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function yl(r){return!!ld(r)}function ml(r){return!!fd(r)}function gl(r){return!!dl(r)}var dw=yl,pE=ml,pd=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(pE(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=dw(t[n]),s;i&&(s=pd(t[n]),t[n]=fe(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,fe(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 ys={},hd={},dE=[[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"]];dE.forEach(r=>{let e=yE(...r);hd[e.code]=e,ys[e.name]=e});function yE(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Ke(r){if(typeof r=="number"){if(hd[r]!=null)return hd[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ys[r]!=null)return ys[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var r4=Ke("ip4"),n4=Ke("ip6"),o4=Ke("ipcidr");function gd(r,e){switch(Ke(r).code){case 4:case 41:return gE(e);case 42:return md(e);case 43:return fe(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 md(e);case 421:return vE(e);case 444:return gw(e);case 445:return gw(e);case 466:return xE(e);case 481:return globalThis.encodeURIComponent(md(e));default:return fe(e,"base16")}}function wd(r,e){switch(Ke(r).code){case 4:return mw(e);case 41:return mw(e);case 42:return yd(e);case 43:return me(e,"base10");case 6:case 273:case 33:case 132:return bd(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return yd(e);case 421:return wE(e);case 444:return AE(e);case 445:return _E(e);case 466:return bE(e);case 481:return yd(globalThis.decodeURIComponent(e));default:return me(e,"base16")}}var dd=Object.values(Mo).map(r=>r.decoder),mE=function(){let r=dd[0].or(dd[1]);return dd.slice(2).forEach(e=>r=r.or(e)),r}();function mw(r){if(!gl(r))throw new Error("invalid ip address");return pd(r)}function gE(r){let e=yw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!gl(e))throw new Error("invalid ip address");return e}function bd(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 yd(r){let e=me(r),t=Uint8Array.from(zr(e.length));return lt([t,e],t.length+e.length)}function md(r){let e=Tr(r);if(r=r.slice(qe(e)),r.length!==e)throw new Error("inconsistent lengths");return fe(r)}function wE(r){let e;r[0]==="Q"||r[0]==="1"?e=Xn(De.decode(`z${r}`)).bytes:e=tt.parse(r).multihash.bytes;let t=Uint8Array.from(zr(e.length));return lt([t,e],t.length+e.length)}function bE(r){let e=mE.decode(r),t=Uint8Array.from(zr(e.length));return lt([t,e],t.length+e.length)}function xE(r){let e=Tr(r),t=r.slice(qe(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+fe(t,"base64url")}function vE(r){let e=Tr(r),t=r.slice(qe(e));if(t.length!==e)throw new Error("inconsistent lengths");return fe(t,"base58btc")}function AE(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=dn.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=bd(n);return lt([t,o],t.length+o.length)}function _E(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=dn.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=bd(n);return lt([t,o],t.length+o.length)}function gw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=fe(e,"base32"),o=ww(t);return`${n}:${o}`}function bw(r){r=xd(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=Ke(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new wl("invalid address: "+r);if(a.path===!0){n=xd(o.slice(i).join("/")),e.push([a.code,wd(a.code,n)]),t.push([a.code,n]);break}let c=wd(a.code,o[i]);e.push([a.code,c]),t.push([a.code,gd(a.code,c)])}return{string:xw(t),bytes:bl(e),tuples:e,stringTuples:t,path:n}}function vd(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=Tr(r,o),s=qe(i),a=Ke(i),c=SE(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 wl("Invalid address Uint8Array: "+fe(r,"base16"));e.push([i,l]);let p=gd(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=Ke(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),xd(e.join("/"))}function bl(r){return lt(r.map(e=>{let t=Ke(e[0]),n=Uint8Array.from(zr(t.code));return e.length>1&&e[1]!=null&&(n=lt([n,e[1]])),n}))}function SE(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Tr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+qe(t)}}function xd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var wl=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var EE=Symbol.for("nodejs.util.inspect.custom"),_d=Symbol.for("@multiformats/js-multiaddr/multiaddr"),CE=[Ke("dns").code,Ke("dns4").code,Ke("dns6").code,Ke("dnsaddr").code],Ad=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},xl=class r{bytes;#e;#t;#r;#n;[_d]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=vd(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(Aw(e))t=vd(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=Ke("tcp"),a=Ke("udp"),c=Ke("ip4"),l=Ke("ip6"),p=Ke("dns6"),f=Ke("ip6zone");for(let[v,g]of this.stringTuples())v===f.code&&(i=`%${g??""}`),CE.includes(v)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${i}`,e=v===p.code?6:4),(v===s.code||v===a.code)&&(t=Ke(v).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(v===c.code||v===l.code)&&(t=Ke(v).name==="tcp"?"tcp":"udp",n=`${g??""}${i}`,e=v===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({},Ke(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Ke(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(bl(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ys.p2p.code&&e.push([n,o]),n===ys["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?fe(De.decode(`z${n}`),"base58btc"):fe(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ye(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 Ad(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Yr(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)}[EE](){return`Multiaddr(${this.#e})`}};var vw=new Map;function Aw(r){return!!r?.[_d]}function Yr(r){return new xl(r)}var TE=r=>r.toString().split("/").slice(1),ms=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),we=r=>({match:e=>ms(t=>t===r).match(e),pattern:r}),Zo=()=>({match:r=>ms(e=>typeof e=="string").match(r),pattern:"{string}"}),gs=()=>({match:r=>ms(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),je=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{De.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Ja=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Uo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Bt=(...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(", ")})`}),_e=(...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 He(...r){function e(o){let i=TE(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 IE=je(),R4=He(IE),Al=_e(we("dns4"),Zo()),_l=_e(we("dns6"),Zo()),Sl=_e(we("dnsaddr"),Zo()),Ed=_e(we("dns"),Zo()),D4=He(Al,Be(je())),L4=He(_l,Be(je())),U4=He(Sl,Be(je())),M4=He(Bt(Ed,Sl,Al,_l),Be(je())),_w=_e(we("ip4"),ms(yl)),Sw=_e(we("ip6"),ms(ml)),Cd=Bt(_w,Sw),An=Bt(Cd,Ed,Al,_l,Sl),K4=He(Bt(Cd,_e(Bt(Ed,Sl,Al,_l),Be(je())))),H4=He(_w),V4=He(Sw),$4=He(Cd),Td=_e(An,we("tcp"),gs()),Qa=_e(An,we("udp"),gs()),F4=He(_e(Td,Be(je()))),W4=He(Qa),Id=_e(Qa,we("quic"),Be(je())),El=_e(Qa,we("quic-v1"),Be(je())),OE=Bt(Id,El),q4=He(Id),G4=He(El),Sd=Bt(An,Td,Qa,Id,El),Ew=Bt(_e(Sd,we("ws"),Be(je()))),z4=He(Ew),Cw=Bt(_e(Sd,we("wss"),Be(je())),_e(Sd,we("tls"),Be(_e(we("sni"),Zo())),we("ws"),Be(je()))),X4=He(Cw),Tw=_e(Qa,we("webrtc-direct"),Be(Ja()),Be(Ja()),Be(je())),Iw=He(Tw),Ow=_e(El,we("webtransport"),Be(Ja()),Be(Ja()),Be(je())),Y4=He(Ow),vl=Bt(Ew,Cw,_e(Td,Be(je())),_e(OE,Be(je())),_e(An,Be(je())),Tw,Ow,je()),Pw=He(vl),PE=_e(vl,we("p2p-circuit"),je()),Z4=He(PE),BE=Bt(_e(vl,we("p2p-circuit"),we("webrtc"),Be(je())),_e(vl,we("webrtc"),Be(je())),_e(we("webrtc"),Be(je()))),Bw=He(BE),kE=Bt(_e(An,we("tcp"),gs(),we("http"),Be(je())),_e(An,we("http"),Be(je()))),J4=He(kE),NE=Bt(_e(An,we("tcp"),Bt(_e(we("443"),we("http")),_e(gs(),we("https")),_e(gs(),we("tls"),we("http"))),Be(je())),_e(An,we("tls"),we("http"),Be(je())),_e(An,we("https"),Be(je()))),Q4=He(NE),jE=Bt(_e(we("memory"),Zo(),Be(je()))),e5=He(jE);var kt;(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=()=>Yo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.flag!=null&&(i.uint32(8),r.Flag.codec().encode(o.flag,i)),o.message!=null&&(i.uint32(18),i.bytes(o.message)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Pr(o,r.codec()),r.decode=(o,i)=>Or(o,r.codec(),i)})(kt||(kt={}));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"],Od=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Nw="libp2p+webrtc+v1/";var jw=466,Rw=2*1024*1024,Dw=30*1e3,ws=16*1024;function RE(r=ws){let e=qe(r-qe(r)),t=1+qe(Object.keys(kt.Flag).length-1),n=1,o=r-e-t-n,i=qe(o);return e+t+n+i}var Lw=RE(),Uw=5e3,Mw=5e3,Kw=3e4,Pd="/webrtc",ec="/webrtc-signaling/0.0.1",Hw="/libp2p/webrtc-direct/certificate",Vw="webrtc-direct-certificate-private-key";var $w=12096e5,Bd=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))},DE=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var LE=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var UE=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 ME=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var KE=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var HE=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,VE=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Ww=3,$E=[["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",HE]],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 KE:typeof navigator<"u"?Gw(navigator.userAgent):qE()}function FE(r){return r!==""&&$E.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=FE(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new ME;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Ww&&(o=Fw(Fw([],o,!0),GE(Ww-o.length),!0)):o=[];var i=o.join("."),s=WE(r),a=VE.exec(r);return a&&a[1]?new UE(t,i,s,a[1]):new DE(t,i,s)}function WE(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 qE(){var r=typeof process<"u"&&process.version;return r?new LE(process.version.slice(1)):null}function GE(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function nt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var kd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Nd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Xw=r=>globalThis.DOMException===void 0?new Nd(r):new DOMException(r),Yw=r=>{let e=r.reason===void 0?Xw("This operation was aborted."):r.reason;return e instanceof Error?e:Xw(e)};function tc(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:v}=e;v.aborted&&f(Yw(v)),a=()=>{f(Yw(v))},v.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,f);return}let d=new kd;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(v){f(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{p(await r)}catch(v){f(v)}})()}).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 Zw=zw(),rc=Zw!=null&&Zw.name==="firefox",Cl=async function*(){},Tl=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=nt(),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 tc(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function jd(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??kw.map(e=>({urls:[e]})),r}var Qw=(r=32)=>Nw+[...Array(r)].map(()=>Od.at(Math.floor(Math.random()*Od.length))).join("");var Jo=class{log;peerConnection;remoteAddr;timeline;metrics;source=Cl();sink=Tl;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 Il=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}},bs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Il(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 Il(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Rd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function xs(r={}){return zE(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 zE(r,e){e=e??{};let t=e.onEnd,n=new bs,o,i,s,a=nt(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((_,j)=>{i=J=>{i=null,n.push(J);try{_(r(n))}catch(O){j(O)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=nt()})}},l=_=>i!=null?i(_):(n.push(_),o),p=_=>(n=new bs,i!=null?i({error:_}):(n.push({error:_}),o)),f=_=>{if(s)return o;if(e?.objectMode!==!0&&_?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:_})},d=_=>s?o:(s=!0,_!=null?p(_):l({done:!0})),v=()=>(n=new bs,d(),{done:!0}),g=_=>(d(_),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:g,push:f,end:d,get readableLength(){return n.size},onEmpty:async _=>{let j=_?.signal;if(j?.throwIfAborted(),n.isEmpty())return;let J,O;j!=null&&(J=new Promise((x,D)=>{O=()=>{D(new Rd)},j.addEventListener("abort",O)}));try{await Promise.race([a.promise,J])}finally{O!=null&&j!=null&&j?.removeEventListener("abort",O)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(_){return w.throw(_),t!=null&&(t(_),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(_){return w.end(_),t!=null&&(t(_),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:_=>w.onEmpty(_)},o}var Ol=class extends Error{type;code;constructor(e,t,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=t??"ABORT_ERR"}};async function cr(r,e,t){if(e==null)return r;if(e.aborted)return r.catch(()=>{}),Promise.reject(new Ol(t?.errorMessage,t?.errorCode,t?.errorName));let n,o=new Ol(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 XE=5e3;function Dd(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Pl=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=nt(),this.closed=nt(),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??XE,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=xs({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 Ro(`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);Dd(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 Ae(o):o;let i=this.sendData(o,t);Dd(i)&&(this.sendingData=nt(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await cr(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await cr(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await cr(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await cr(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Dd(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 Du("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 Ld(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 Bl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},kl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},nc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Nl(r){return r[Symbol.asyncIterator]!=null}function nb(r,e){if(r.byteLength>e)throw new vs("Message length too long")}var Rl=r=>{let e=qe(r),t=ut(e);return zr(r,t),Rl.bytes=e,t};Rl.bytes=0;function oc(r,e){e=e??{};let t=e.lengthEncoder??Rl,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 Nl(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}oc.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Rl,n=e?.maxDataLength??4194304;return nb(r,n),new Ae(t(r.byteLength),r)};var Qo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Qo||(Qo={}));var Ud=r=>{let e=Tr(r);return Ud.bytes=qe(e),e};Ud.bytes=0;function ei(r,e){let t=new Ae,n=Qo.LENGTH,o=-1,i=e?.lengthDecoder??Ud,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Qo.LENGTH)try{if(o=i(t),o<0)throw new Bl("Invalid message length");if(o>a)throw new vs("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Qo.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new kl("Message length length too long");break}throw l}if(n===Qo.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Qo.LENGTH}}}return Nl(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new nc("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new nc("Unexpected end of input")}()}ei.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 ei(n,{...e??{},onLength:i=>{t=i}})};var Md=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 ic(r,e,t,n){let o=new Md(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(d){a(),s(d);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 Kd=class extends Pl{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 tc(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=xs(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Dw,this.maxBufferedAmount=e.maxBufferedAmount??Rw,this.maxMessageSize=(e.maxMessageSize??ws)-Lw,this.receiveFinAck=nt(),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 Ro("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 ei(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new Ae(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 Ro(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Ld([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await ic(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Ld([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await ic(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new Ku(`Timed out waiting for DataChannel buffer to clear after ${this.bufferedAmountLowEventTimeout}ms`):i}finally{o.clear()}}try{this.log.trace('sending message, channel state "%s"',this.channel.readyState),this.channel.send(e.subarray())}catch(n){this.log.error("error while sending message",n)}}async sendData(e){let t=e.byteLength;for(e=e.sublist();e.byteLength>0;){let n=Math.min(e.byteLength,this.maxMessageSize),o=e.subarray(0,n),i=kt.encode({message:o}),s=oc.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(kt.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(kt.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await cr(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(kt.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=kt.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===kt.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(kt.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===kt.Flag.RESET&&this.reset(),t.flag===kt.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===kt.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=kt.encode({flag:e}),n=oc.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function As(r){let{channel:e,direction:t,handshake:n}=r;return new Kd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var ao=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??Pd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=As({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Hd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Hd=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??Pd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=As({channel:n,direction:"inbound",onEnd:()=>{this.#e(i,n),this.log("incoming channel %s ended",o)},logger:this.logger,...this.dataChannelOptions});this.streams.push(i),this.metrics?.increment({incoming_stream:!0}),t?.onIncomingStream?.(i)},this.init.streams.length>0&&queueMicrotask(()=>{this.init.streams.forEach(n=>{n.onEnd=()=>{this.log("incoming early channel %s ended with state %s",n.channel.id,n.channel.readyState),this.#e(n.stream,n.channel)},this.metrics?.increment({incoming_stream:!0}),this.init?.onIncomingStream?.(n.stream)})})}#e(e,t){this.log.trace("stream %s %s %s onEnd",e.direction,e.id,e.protocol),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=Cl();sink=Tl;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=As({channel:e,direction:"outbound",onEnd:()=>{this.#e(n,e),this.log("outgoing channel %s ended",t)},logger:this.logger,...this.dataChannelOptions});return this.streams.push(n),this.metrics?.increment({outgoing_stream:!0}),n}};var Dl=globalThis.RTCPeerConnection,Ll=globalThis.RTCSessionDescription,ob=globalThis.RTCIceCandidate;var Vd=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=nt(),this.haveNext=nt()}[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=nt(),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=nt(),await cr(this.readNext.promise,t?.signal,t)}};function Ul(){return new Vd}var Ml=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ib(r,e){let t=Ul();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 Ae;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:l}=await cr(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await cr(n.next(),s?.signal);if(l===!0)throw new Ml("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 Kl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Hl=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Vl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function sc(r,e={}){let t=ib(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=qe(e.maxDataLength));let n=e?.lengthDecoder??Tr,o=e?.lengthEncoder??zr;return{read:async s=>{let a=-1,c=new Ae;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 Kl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Vl("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Hl("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new Ae(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new Ae(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function $l(r,e){let t=sc(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 rr=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var co=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},ur=class extends co{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Fl=class extends co{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Wl=class extends co{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},ql=class extends co{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 Vt;(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=()=>Yo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Br((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.type!=null&&(i.uint32(8),r.Type.codec().encode(o.type,i)),o.data!=null&&(i.uint32(18),i.string(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>Pr(o,r.codec()),r.decode=(o,i)=>Or(o,r.codec(),i)})(Vt||(Vt={}));var Gl=async(r,e,t)=>{try{let n=nt();for(JE(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!==Vt.Type.ICE_CANDIDATE)throw new Mu("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new rr("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 rr("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&&zl(r)!=="connected")throw n}};function zl(r){return rc?r.iceConnectionState:r.connectionState}function JE(r,e){r[rc?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(zl(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Ru("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 Se("Relay peer was missing");let d=i.getConnections(hs(f)),v,g=!1;d.length===0?(l?.(new rr("webrtc:dial-relay")),v=await s.dial(p,{signal:t,onProgress:l}),g=!0):(l?.(new rr("webrtc:reuse-relay-connection")),v=d[0]);try{l?.(new rr("webrtc:open-signaling-stream"));let w=await v.newStream(ec,{signal:t,runOnLimitedConnection:!0}),_=$l(w).pb(Vt),j=new Dl(r),J=new ao({logger:c},{peerConnection:j,dataChannelOptions:e});try{let O=j.createDataChannel("init");j.onicecandidate=({candidate:N})=>{let U=JSON.stringify(N?.toJSON()??null);a.trace("initiator sending ICE candidate %o",N),_.write({type:Vt.Type.ICE_CANDIDATE,data:U},{signal:t}).catch(F=>{a.error("error sending ICE candidate",F)})},j.onicecandidateerror=N=>{a.error("initiator ICE candidate error",N)};let x=await j.createOffer().catch(N=>{throw a.error("could not execute createOffer",N),new ur("Failed to set createOffer")});a.trace("initiator send SDP offer %s",x.sdp),l?.(new rr("webrtc:send-sdp-offer")),await _.write({type:Vt.Type.SDP_OFFER,data:x.sdp},{signal:t}),await j.setLocalDescription(x).catch(N=>{throw a.error("could not execute setLocalDescription",N),new ur("Failed to set localDescription")}),l?.(new rr("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let D=await _.read({signal:t});if(D.type!==Vt.Type.SDP_ANSWER)throw new ur("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",D.data);let $=new Ll({type:"answer",sdp:D.data});return await j.setRemoteDescription($).catch(N=>{throw a.error("could not execute setRemoteDescription",N),new ur("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new rr("webrtc:read-ice-candidates")),await Gl(j,_,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),O.close(),l?.(new rr("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:j,muxerFactory:J}}catch(O){throw a.error("outgoing signaling error",O),j.close(),w.abort(O),O}finally{j.onicecandidate=null,j.onicecandidateerror=null}}finally{if(g)try{await v.close({signal:t})}catch(w){v.abort(w)}}}var cb=He(Pw.matchers[0],we("p2p-circuit")),Xl=class r extends Gn{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=$l(e).pb(Vt);try{r.onicecandidate=({candidate:p})=>{let f=JSON.stringify(p?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),i.write({type:Vt.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(d=>{o.error("error sending ICE candidate",d)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==Vt.Type.SDP_OFFER)throw new ur(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Ll({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(p=>{throw o.error("could not execute setRemoteDescription",p),new ur("Failed to set remoteDescription")});let l=await r.createAnswer().catch(p=>{throw o.error("could not execute createAnswer",p),new ur("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:Vt.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(p=>{throw o.error("could not execute setLocalDescription",p),new ur("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Gl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(zl(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=Yr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Yl=class{components;init;log;_started=!1;metrics;shutdownController;constructor(e,t={}){this.components=e,this.init=t,this.log=e.logger.forComponent("libp2p:webrtc"),this.shutdownController=new AbortController,this.shutdownController.signal,e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_dialer_events_total",{label:"event",help:"Total count of WebRTC dialer events by type"}),listenerEvents:e.metrics.registerCounterGroup("libp2p_webrtc_listener_events_total",{label:"event",help:"Total count of WebRTC listener events by type"})})}[ku]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Qi]=["@libp2p/transport"];[cg]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(ec,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(ec),this._started=!1}createListener(e){return new Xl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Bw.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 jd(this.init.rtcConfiguration),dataChannel:this.init.dataChannel,multiaddr:e,dataChannelOptions:this.init.dataChannel,signal:t.signal,connectionManager:this.components.connectionManager,transportManager:this.components.transportManager,log:this.log,logger:this.components.logger,onProgress:t.onProgress}),s=new Jo(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 Dl(await jd(this.init.rtcConfiguration)),i=new ao(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 Jo(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 Se("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new Se("p2p-circuit protocol was not present in multiaddr");let t=Yr(e[0]),o=Yr("/"+e[1]).getPeerId();if(o==null)throw new Se("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new Se("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:hs(o)}}var CG=$r(fb());var en={};Ct(en,{Any:()=>Jr,BaseBlock:()=>ot,BaseStringBlock:()=>lc,BitString:()=>Rr,BmpString:()=>ii,Boolean:()=>ri,CharacterString:()=>di,Choice:()=>Es,Constructed:()=>ft,DATE:()=>mc,DateTime:()=>wc,Duration:()=>bc,EndOfContent:()=>fc,Enumerated:()=>ni,GeneralString:()=>hi,GeneralizedTime:()=>yi,GraphicString:()=>pi,HexBlock:()=>Qr,IA5String:()=>fi,Integer:()=>Tn,Null:()=>Nr,NumericString:()=>ai,ObjectIdentifier:()=>oi,OctetString:()=>jr,Primitive:()=>Cn,PrintableString:()=>ci,RawData:()=>qd,RelativeObjectIdentifier:()=>yc,Repeated:()=>mi,Sequence:()=>Wt,Set:()=>qt,TIME:()=>xc,TeletexString:()=>ui,TimeOfDay:()=>gc,UTCTime:()=>po,UniversalString:()=>si,Utf8String:()=>fr,ValueBlock:()=>gt,VideotexString:()=>li,ViewWriter:()=>Ss,VisibleString:()=>fo,compareSchema:()=>lo,fromBER:()=>On,verifySchema:()=>b2});var ge=$r(Sn());function ti(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 uo(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 Ql(...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 Fd(){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=ti(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,ti(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=uo(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=uo(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 $t(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 I3=Math.log(2);function ef(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Gd(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function In(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Ss=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Gd(this.items)}},ac=[new Uint8Array([1])],db="0123456789",Wd="name",yb="valueHexView",a2="isHexOnly",c2="idBlock",u2="tagClass",l2="tagNumber",f2="isConstructed",p2="fromBER",h2="toBER",d2="local",Ft="",Dr=new ArrayBuffer(0),mf=new Uint8Array(0),uc="EndOfContent",gb="OCTET STRING",wb="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?ge.BufferSourceConverter.toUint8Array(i.valueHex):mf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!In(this,s,o,i))return-1;let a=o+i;return this.valueHexView=s.subarray(o,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),o)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Dr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ge.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var En=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=Ft,warnings:n=[],valueBeforeDecode:o=mf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ge.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ge.Convert.ToHex(this.valueBeforeDecodeView)}}};En.NAME="baseBlock";var gt=class extends En{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'")}};gt.NAME="valueBlock";var tf=class extends Qr(En){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?ge.BufferSourceConverter.toUint8Array(e.valueHex):mf,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Dr}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let o=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,o[0]=t}return o.buffer}if(!this.isHexOnly){let o=uo(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),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 d=new Uint8Array(p);for(let v=0;v<l.length;v++)d[v]=l[v];l=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,l[c-1]=i[c]&127;let f=new Uint8Array(c);for(let d=0;d<c;d++)f[d]=l[d];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=ti(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}}};tf.NAME="identificationBlock";var rf=class extends En{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;let i=o.subarray(t,t+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;let s=i[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=o.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=ti(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=uo(this.length,8);if(o.byteLength>127)return this.error="Too big length",Dr;if(t=new ArrayBuffer(o.byteLength+1),e)return t;let i=new Uint8Array(o);n=new Uint8Array(t),n[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)n[s+1]=i[s];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};rf.NAME="lengthBlock";var Q={},ot=class extends En{constructor({name:e=Ft,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new tf(o),this.lenBlock=new rf(o),this.valueBlock=i?new i(o):new gt(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 Ss;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?Dr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():ge.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ge.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return hb(t,n)}};ot.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 lc=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Ft,...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}'`}};lc.NAME="BaseStringBlock";var nf=class extends Qr(gt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};nf.NAME="PrimitiveValueBlock";var xb,Cn=class extends ot{constructor(e={}){super(e,nf),this.idBlock.isConstructed=!1}};xb=Cn;Q.Primitive=xb;Cn.NAME="PRIMITIVE";function y2(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 Cs(r,e=0,t=r.length){let n=e,o=new ot({},gt),i=new En;if(!In(i,r,e,t))return o.error=i.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let a=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),a===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=a,t-=o.idBlock.blockLength,a=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),a===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=a,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let c=ot;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=y2(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 On(r){if(!r.byteLength){let e=new ot({},gt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Cs(ge.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function m2(r,e){return r?1:e}var Zr=class extends gt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;m2(this.isIndefiniteForm,n)>0;){let s=Cs(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===uc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===uc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Ss;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Dr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Zr.NAME="ConstructedValueBlock";var vb,ft=class extends ot{constructor(e={}){super(e,Zr),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PWebrtc=(()=>{var CA=Object.create;var ju=Object.defineProperty;var TA=Object.getOwnPropertyDescriptor;var IA=Object.getOwnPropertyNames;var OA=Object.getPrototypeOf,PA=Object.prototype.hasOwnProperty;var jp=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ct=(r,e)=>{for(var t in e)ju(r,t,{get:e[t],enumerable:!0})},ag=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of IA(e))!PA.call(r,o)&&o!==t&&ju(r,o,{get:()=>e[o],enumerable:!(n=TA(e,o))||n.enumerable});return r};var Fr=(r,e,t)=>(t=r!=null?CA(OA(r)):{},ag(e||!r||!r.__esModule?ju(t,"default",{value:r,enumerable:!0}):t,r)),BA=r=>ag(ju({},"__esModule",{value:!0}),r);var hb=jp(()=>{var pb;(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 Np(Object.create(null))}:c?function(){return Np({__proto__:null})}:function(){return Np({})},has:l?function(b,S){return n.call(b,S)}:function(b,S){return S in b},get:l?function(b,S){return n.call(b,S)?b[S]:void 0}:function(b,S){return b[S]}},f=Object.getPrototypeOf(Function),d=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:vA(),v=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:AA(),g=typeof WeakMap=="function"?WeakMap:_A(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,_=wA(),j=bA(_);function J(b,S,P,q){if(I(P)){if(!yt(b))throw new TypeError;if(!st(S))throw new TypeError;return X(b,S)}else{if(!yt(b))throw new TypeError;if(!te(S))throw new TypeError;if(!te(q)&&!I(q)&&!oe(q))throw new TypeError;return oe(q)&&(q=void 0),P=Re(P),W(b,S,P,q)}}e("decorate",J);function O(b,S){function P(q,le){if(!te(q))throw new TypeError;if(!I(le)&&!jt(le))throw new TypeError;k(b,S,q,le)}return P}e("metadata",O);function x(b,S,P,q){if(!te(P))throw new TypeError;return I(q)||(q=Re(q)),k(b,S,P,q)}e("defineMetadata",x);function D(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),ae(b,S,P)}e("hasMetadata",D);function $(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),B(b,S,P)}e("hasOwnMetadata",$);function N(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),R(b,S,P)}e("getMetadata",N);function U(b,S,P){if(!te(S))throw new TypeError;return I(P)||(P=Re(P)),H(b,S,P)}e("getOwnMetadata",U);function F(b,S){if(!te(b))throw new TypeError;return I(S)||(S=Re(S)),y(b,S)}e("getMetadataKeys",F);function Z(b,S){if(!te(b))throw new TypeError;return I(S)||(S=Re(S)),T(b,S)}e("getOwnMetadataKeys",Z);function K(b,S,P){if(!te(S))throw new TypeError;if(I(P)||(P=Re(P)),!te(S))throw new TypeError;I(P)||(P=Re(P));var q=ga(S,P,!1);return I(q)?!1:q.OrdinaryDeleteMetadata(b,S,P)}e("deleteMetadata",K);function X(b,S){for(var P=b.length-1;P>=0;--P){var q=b[P],le=q(S);if(!I(le)&&!oe(le)){if(!st(le))throw new TypeError;S=le}}return S}function W(b,S,P,q){for(var le=b.length-1;le>=0;--le){var Qe=b[le],at=Qe(S,P,q);if(!I(at)&&!oe(at)){if(!te(at))throw new TypeError;q=at}}return q}function ae(b,S,P){var q=B(b,S,P);if(q)return!0;var le=ma(S);return oe(le)?!1:ae(b,le,P)}function B(b,S,P){var q=ga(S,P,!1);return I(q)?!1:Ce(q.OrdinaryHasOwnMetadata(b,S,P))}function R(b,S,P){var q=B(b,S,P);if(q)return H(b,S,P);var le=ma(S);if(!oe(le))return R(b,le,P)}function H(b,S,P){var q=ga(S,P,!1);if(!I(q))return q.OrdinaryGetOwnMetadata(b,S,P)}function k(b,S,P,q){var le=ga(P,q,!0);le.OrdinaryDefineOwnMetadata(b,S,P,q)}function y(b,S){var P=T(b,S),q=ma(b);if(q===null)return P;var le=y(q,S);if(le.length<=0)return P;if(P.length<=0)return le;for(var Qe=new v,at=[],xe=0,Y=P;xe<Y.length;xe++){var ee=Y[xe],ne=Qe.has(ee);ne||(Qe.add(ee),at.push(ee))}for(var ie=0,ve=le;ie<ve.length;ie++){var ee=ve[ie],ne=Qe.has(ee);ne||(Qe.add(ee),at.push(ee))}return at}function T(b,S){var P=ga(b,S,!1);return P?P.OrdinaryOwnMetadataKeys(b,S):[]}function L(b){if(b===null)return 1;switch(typeof b){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return b===null?1:6;default:return 6}}function I(b){return b===void 0}function oe(b){return b===null}function pe(b){return typeof b=="symbol"}function te(b){return typeof b=="object"?b!==null:typeof b=="function"}function de(b,S){switch(L(b)){case 0:return b;case 1:return b;case 2:return b;case 3:return b;case 4:return b;case 5:return b}var P=S===3?"string":S===5?"number":"default",q=qn(b,i);if(q!==void 0){var le=q.call(b,P);if(te(le))throw new TypeError;return le}return ye(b,P==="default"?"number":P)}function ye(b,S){if(S==="string"){var P=b.toString;if($e(P)){var q=P.call(b);if(!te(q))return q}var le=b.valueOf;if($e(le)){var q=le.call(b);if(!te(q))return q}}else{var le=b.valueOf;if($e(le)){var q=le.call(b);if(!te(q))return q}var Qe=b.toString;if($e(Qe)){var q=Qe.call(b);if(!te(q))return q}}throw new TypeError}function Ce(b){return!!b}function Te(b){return""+b}function Re(b){var S=de(b,3);return pe(S)?S:Te(S)}function yt(b){return Array.isArray?Array.isArray(b):b instanceof Object?b instanceof Array:Object.prototype.toString.call(b)==="[object Array]"}function $e(b){return typeof b=="function"}function st(b){return typeof b=="function"}function jt(b){switch(L(b)){case 3:return!0;case 4:return!0;default:return!1}}function Rt(b,S){return b===S||b!==b&&S!==S}function qn(b,S){var P=b[S];if(P!=null){if(!$e(P))throw new TypeError;return P}}function ya(b){var S=qn(b,s);if(!$e(S))throw new TypeError;var P=S.call(b);if(!te(P))throw new TypeError;return P}function Bu(b){return b.value}function ku(b){var S=b.next();return S.done?!1:S}function Nu(b){var S=b.return;S&&S.call(b)}function ma(b){var S=Object.getPrototypeOf(b);if(typeof b!="function"||b===f||S!==f)return S;var P=b.prototype,q=P&&Object.getPrototypeOf(P);if(q==null||q===Object.prototype)return S;var le=q.constructor;return typeof le!="function"||le===b?S:le}function gA(){var b;!I(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(b=xA(t.Reflect));var S,P,q,le=new g,Qe={registerProvider:at,getProvider:Y,setProvider:ne};return Qe;function at(ie){if(!Object.isExtensible(Qe))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case b===ie:break;case I(S):S=ie;break;case S===ie:break;case I(P):P=ie;break;case P===ie:break;default:q===void 0&&(q=new v),q.add(ie);break}}function xe(ie,ve){if(!I(S)){if(S.isProviderFor(ie,ve))return S;if(!I(P)){if(P.isProviderFor(ie,ve))return S;if(!I(q))for(var Fe=ya(q);;){var et=ku(Fe);if(!et)return;var Ar=Bu(et);if(Ar.isProviderFor(ie,ve))return Nu(Fe),Ar}}}if(!I(b)&&b.isProviderFor(ie,ve))return b}function Y(ie,ve){var Fe=le.get(ie),et;return I(Fe)||(et=Fe.get(ve)),I(et)&&(et=xe(ie,ve),I(et)||(I(Fe)&&(Fe=new d,le.set(ie,Fe)),Fe.set(ve,et))),et}function ee(ie){if(I(ie))throw new TypeError;return S===ie||P===ie||!I(q)&&q.has(ie)}function ne(ie,ve,Fe){if(!ee(Fe))throw new Error("Metadata provider not registered.");var et=Y(ie,ve);if(et!==Fe){if(!I(et))return!1;var Ar=le.get(ie);I(Ar)&&(Ar=new d,le.set(ie,Ar)),Ar.set(ve,Fe)}return!0}}function wA(){var b;return!I(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&(b=t.Reflect[w]),I(b)&&(b=gA()),!I(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:b}),b}function bA(b){var S=new g,P={isProviderFor:function(ee,ne){var ie=S.get(ee);return I(ie)?!1:ie.has(ne)},OrdinaryDefineOwnMetadata:at,OrdinaryHasOwnMetadata:le,OrdinaryGetOwnMetadata:Qe,OrdinaryOwnMetadataKeys:xe,OrdinaryDeleteMetadata:Y};return _.registerProvider(P),P;function q(ee,ne,ie){var ve=S.get(ee),Fe=!1;if(I(ve)){if(!ie)return;ve=new d,S.set(ee,ve),Fe=!0}var et=ve.get(ne);if(I(et)){if(!ie)return;if(et=new d,ve.set(ne,et),!b.setProvider(ee,ne,P))throw ve.delete(ne),Fe&&S.delete(ee),new Error("Wrong provider for target.")}return et}function le(ee,ne,ie){var ve=q(ne,ie,!1);return I(ve)?!1:Ce(ve.has(ee))}function Qe(ee,ne,ie){var ve=q(ne,ie,!1);if(!I(ve))return ve.get(ee)}function at(ee,ne,ie,ve){var Fe=q(ie,ve,!0);Fe.set(ee,ne)}function xe(ee,ne){var ie=[],ve=q(ee,ne,!1);if(I(ve))return ie;for(var Fe=ve.keys(),et=ya(Fe),Ar=0;;){var sg=ku(et);if(!sg)return ie.length=Ar,ie;var SA=Bu(sg);try{ie[Ar]=SA}catch(EA){try{Nu(et)}finally{throw EA}}Ar++}}function Y(ee,ne,ie){var ve=q(ne,ie,!1);if(I(ve)||!ve.delete(ee))return!1;if(ve.size===0){var Fe=S.get(ne);I(Fe)||(Fe.delete(ie),Fe.size===0&&S.delete(Fe))}return!0}}function xA(b){var S=b.defineMetadata,P=b.hasOwnMetadata,q=b.getOwnMetadata,le=b.getOwnMetadataKeys,Qe=b.deleteMetadata,at=new g,xe={isProviderFor:function(Y,ee){var ne=at.get(Y);return!I(ne)&&ne.has(ee)?!0:le(Y,ee).length?(I(ne)&&(ne=new v,at.set(Y,ne)),ne.add(ee),!0):!1},OrdinaryDefineOwnMetadata:S,OrdinaryHasOwnMetadata:P,OrdinaryGetOwnMetadata:q,OrdinaryOwnMetadataKeys:le,OrdinaryDeleteMetadata:Qe};return xe}function ga(b,S,P){var q=_.getProvider(b,S);if(!I(q))return q;if(P){if(_.setProvider(b,S,j))return j;throw new Error("Illegal state.")}}function vA(){var b={},S=[],P=function(){function xe(Y,ee,ne){this._index=0,this._keys=Y,this._values=ee,this._selector=ne}return xe.prototype["@@iterator"]=function(){return this},xe.prototype[s]=function(){return this},xe.prototype.next=function(){var Y=this._index;if(Y>=0&&Y<this._keys.length){var ee=this._selector(this._keys[Y],this._values[Y]);return Y+1>=this._keys.length?(this._index=-1,this._keys=S,this._values=S):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},xe.prototype.throw=function(Y){throw this._index>=0&&(this._index=-1,this._keys=S,this._values=S),Y},xe.prototype.return=function(Y){return this._index>=0&&(this._index=-1,this._keys=S,this._values=S),{value:Y,done:!0}},xe}(),q=function(){function xe(){this._keys=[],this._values=[],this._cacheKey=b,this._cacheIndex=-2}return Object.defineProperty(xe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),xe.prototype.has=function(Y){return this._find(Y,!1)>=0},xe.prototype.get=function(Y){var ee=this._find(Y,!1);return ee>=0?this._values[ee]:void 0},xe.prototype.set=function(Y,ee){var ne=this._find(Y,!0);return this._values[ne]=ee,this},xe.prototype.delete=function(Y){var ee=this._find(Y,!1);if(ee>=0){for(var ne=this._keys.length,ie=ee+1;ie<ne;ie++)this._keys[ie-1]=this._keys[ie],this._values[ie-1]=this._values[ie];return this._keys.length--,this._values.length--,Rt(Y,this._cacheKey)&&(this._cacheKey=b,this._cacheIndex=-2),!0}return!1},xe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=b,this._cacheIndex=-2},xe.prototype.keys=function(){return new P(this._keys,this._values,le)},xe.prototype.values=function(){return new P(this._keys,this._values,Qe)},xe.prototype.entries=function(){return new P(this._keys,this._values,at)},xe.prototype["@@iterator"]=function(){return this.entries()},xe.prototype[s]=function(){return this.entries()},xe.prototype._find=function(Y,ee){if(!Rt(this._cacheKey,Y)){this._cacheIndex=-1;for(var ne=0;ne<this._keys.length;ne++)if(Rt(this._keys[ne],Y)){this._cacheIndex=ne;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(Y),this._values.push(void 0)),this._cacheIndex},xe}();return q;function le(xe,Y){return xe}function Qe(xe,Y){return Y}function at(xe,Y){return[xe,Y]}}function AA(){var b=function(){function S(){this._map=new d}return Object.defineProperty(S.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),S.prototype.has=function(P){return this._map.has(P)},S.prototype.add=function(P){return this._map.set(P,P),this},S.prototype.delete=function(P){return this._map.delete(P)},S.prototype.clear=function(){this._map.clear()},S.prototype.keys=function(){return this._map.keys()},S.prototype.values=function(){return this._map.keys()},S.prototype.entries=function(){return this._map.entries()},S.prototype["@@iterator"]=function(){return this.keys()},S.prototype[s]=function(){return this.keys()},S}();return b}function _A(){var b=16,S=p.create(),P=q();return function(){function Y(){this._key=q()}return Y.prototype.has=function(ee){var ne=le(ee,!1);return ne!==void 0?p.has(ne,this._key):!1},Y.prototype.get=function(ee){var ne=le(ee,!1);return ne!==void 0?p.get(ne,this._key):void 0},Y.prototype.set=function(ee,ne){var ie=le(ee,!0);return ie[this._key]=ne,this},Y.prototype.delete=function(ee){var ne=le(ee,!1);return ne!==void 0?delete ne[this._key]:!1},Y.prototype.clear=function(){this._key=q()},Y}();function q(){var Y;do Y="@@WeakMap@@"+xe();while(p.has(S,Y));return S[Y]=!0,Y}function le(Y,ee){if(!n.call(Y,P)){if(!ee)return;Object.defineProperty(Y,P,{value:p.create()})}return Y[P]}function Qe(Y,ee){for(var ne=0;ne<ee;++ne)Y[ne]=Math.random()*255|0;return Y}function at(Y){if(typeof Uint8Array=="function"){var ee=new Uint8Array(Y);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):Qe(ee,Y),ee}return Qe(new Array(Y),Y)}function xe(){var Y=at(b);Y[6]=Y[6]&79|64,Y[8]=Y[8]&191|128;for(var ee="",ne=0;ne<b;++ne){var ie=Y[ne];(ne===4||ne===6||ne===8)&&(ee+="-"),ie<16&&(ee+="0"),ee+=ie.toString(16).toLowerCase()}return ee}}function Np(b){return b.__=void 0,delete b.__,b}})})(pb||(pb={}))});var En=jp(Es=>{"use strict";var i2="[object ArrayBuffer]",Sn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===i2}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),o=r.toUint8Array(t);if(n.length!==o.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==o[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let s of t)n+=s.byteLength;let o=new Uint8Array(n),i=0;for(let s of t){let a=this.toUint8Array(s);o.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}},Fd="string",s2=/^[0-9a-f\s]+$/i,a2=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,c2=/^[a-zA-Z0-9-_]+$/,Ql=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=Sn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},fr=class{static toString(e,t=!1){let n=Sn.toArrayBuffer(e),o=new DataView(n),i="";for(let s=0;s<n.byteLength;s+=2){let a=o.getUint16(s,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),o=new DataView(n);for(let i=0;i<e.length;i++)o.setUint16(i*2,e.charCodeAt(i),t);return n}},ef=class r{static isHex(e){return typeof e===Fd&&s2.test(e)}static isBase64(e){return typeof e===Fd&&a2.test(e)}static isBase64Url(e){return typeof e===Fd&&c2.test(e)}static ToString(e,t="utf8"){let n=Sn.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return fr.toString(n,!0);case"utf16":case"utf16be":return fr.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return fr.fromString(e,!0);case"utf16":case"utf16be":return fr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Sn.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 Ql.fromString(e);case"utf16":case"utf16be":return fr.fromString(e);case"utf16le":case"usc2":return fr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Ql.toString(e);case"utf16":case"utf16be":return fr.toString(e);case"utf16le":case"usc2":return fr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return n.buffer}static ToBinary(e){let t=Sn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Sn.toUint8Array(e),n="",o=t.length;for(let i=0;i<o;i++){let s=t[i];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){let i=t.slice(o,o+2);n[o/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(e,t=!1){return fr.toString(e,t)}static FromUtf16String(e,t=!1){return fr.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ef.DEFAULT_UTF8_ENCODING="utf8";function u2(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 l2(...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 f2(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}Es.BufferSourceConverter=Sn;Es.Convert=ef;Es.assign=u2;Es.combine=l2;Es.isEqual=f2});var av=jp((cV,Xf)=>{var Hx,Vx,$x,Fx,Wx,qx,Gx,zx,Xx,zf,Zy,Yx,Zx,ta,Jx,Qx,ev,tv,rv,nv,ov,iv,sv;(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 Xf=="object"&&typeof Xf.exports=="object"?r(t(e,t(Xf.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])};Hx=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},Vx=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},$x=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},Fx=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},Wx=function(t,n){return function(o,i){n(o,i,t)}},qx=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},Gx=function(t,n,o,i){function s(a){return a instanceof o?a:new o(function(c){c(a)})}return new(o||(o=Promise))(function(a,c){function l(d){try{f(i.next(d))}catch(v){c(v)}}function p(d){try{f(i.throw(d))}catch(v){c(v)}}function f(d){d.done?a(d.value):s(d.value).then(l,p)}f((i=i.apply(t,n||[])).next())})},zx=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(d){return p([f,d])}}function p(f){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=f[0]&2?s.return:f[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,f[1])).done)return a;switch(s=0,a&&(f=[f[0]&2,a.value]),f[0]){case 0:case 1:a=f;break;case 4:return o.label++,{value:f[1],done:!1};case 5:o.label++,s=f[1],f=[0];continue;case 7:f=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(f[0]===6||f[0]===2)){o=0;continue}if(f[0]===3&&(!a||f[1]>a[0]&&f[1]<a[3])){o.label=f[1];break}if(f[0]===6&&o.label<a[1]){o.label=a[1],a=f;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(f);break}a[2]&&o.ops.pop(),o.trys.pop();continue}f=n.call(t,o)}catch(d){f=[6,d],s=0}finally{i=a=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},sv=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},Xx=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},zf=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.")},Zy=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},Yx=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(Zy(arguments[n]));return t},Zx=function(){for(var t=0,n=0,o=arguments.length;n<o;n++)t+=arguments[n].length;for(var i=Array(t),s=0,n=0;n<o;n++)for(var a=arguments[n],c=0,l=a.length;c<l;c++,s++)i[s]=a[c];return i},ta=function(t){return this instanceof ta?(this.v=t,this):new ta(t)},Jx=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(_,j){a.push([g,w,_,j])>1||l(g,w)})})}function l(g,w){try{p(i[g](w))}catch(_){v(a[0][3],_)}}function p(g){g.value instanceof ta?Promise.resolve(g.value.v).then(f,d):v(a[0][2],g)}function f(g){l("next",g)}function d(g){l("throw",g)}function v(g,w){g(w),a.shift(),a.length&&l(a[0][0],a[0][1])}},Qx=function(t){var n,o;return n={},i("next"),i("throw",function(s){throw s}),i("return"),n[Symbol.iterator]=function(){return this},n;function i(s,a){n[s]=t[s]?function(c){return(o=!o)?{value:ta(t[s](c)),done:s==="return"}:a?a(c):c}:a}},ev=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 zf=="function"?zf(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)}},tv=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},rv=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},nv=function(t){return t&&t.__esModule?t:{default:t}},ov=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},iv=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",Hx),r("__assign",Vx),r("__rest",$x),r("__decorate",Fx),r("__param",Wx),r("__metadata",qx),r("__awaiter",Gx),r("__generator",zx),r("__exportStar",Xx),r("__createBinding",sv),r("__values",zf),r("__read",Zy),r("__spread",Yx),r("__spreadArrays",Zx),r("__await",ta),r("__asyncGenerator",Jx),r("__asyncDelegator",Qx),r("__asyncValues",ev),r("__makeTemplateObject",tv),r("__importStar",rv),r("__importDefault",nv),r("__classPrivateFieldGet",ov),r("__classPrivateFieldSet",iv)})});var dT={};Ct(dT,{webRTC:()=>hT,webRTCDirect:()=>pT});var Rp=Symbol.for("@libp2p/peer-id");var Ru=Symbol.for("@libp2p/transport");var cg;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(cg||(cg={}));var Du=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},Lu=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},Se=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ji=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},wa=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var Uu=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}};var Mu=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}},Ro=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Do=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"}},Hu=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Vu=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var $u=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},Fu=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Gn=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var zn=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 Qi=Symbol.for("@libp2p/service-capabilities"),ug=Symbol.for("@libp2p/service-dependencies");var Kp={};Ct(Kp,{base58btc:()=>De,base58flickr:()=>UA});var HT=new Uint8Array(0);function lg(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 dn(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 fg(r){return new TextEncoder().encode(r)}function pg(r){return new TextDecoder().decode(r)}function kA(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(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,_=0,j=0,J=g.length;j!==J&&g[j]===0;)j++,w++;for(var O=(J-j)*p+1>>>0,x=new Uint8Array(O);j!==J;){for(var D=g[j],$=0,N=O-1;(D!==0||$<_)&&N!==-1;N--,$++)D+=256*x[N]>>>0,x[N]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");_=$,j++}for(var U=O-_;U!==O&&x[U]===0;)U++;for(var F=c.repeat(w);U<O;++U)F+=r.charAt(x[U]);return F}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var w=0;if(g[w]!==" "){for(var _=0,j=0;g[w]===c;)_++,w++;for(var J=(g.length-w)*l+1>>>0,O=new Uint8Array(J);g[w];){var x=t[g.charCodeAt(w)];if(x===255)return;for(var D=0,$=J-1;(x!==0||D<j)&&$!==-1;$--,D++)x+=a*O[$]>>>0,O[$]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");j=D,w++}if(g[w]!==" "){for(var N=J-j;N!==J&&O[N]===0;)N++;for(var U=new Uint8Array(_+(J-N)),F=_;N!==J;)U[F++]=O[N++];return U}}}function v(g){var w=d(g);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:v}}var NA=kA,jA=NA,dg=jA;var Dp=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")}},Lp=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return yg(this,e)}},Up=class{decoders;constructor(e){this.decoders=e}or(e){return yg(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function yg(r,e){return new Up({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Mp=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 Dp(e,t,n),this.decoder=new Lp(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function es({name:r,prefix:e,encode:t,decode:n}){return new Mp(r,e,t,n)}function Xn({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=dg(t,r);return es({prefix:e,name:r,encode:n,decode:i=>dn(o(i))})}function RA(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 DA(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 LA(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Xe({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=LA(n);return es({prefix:e,name:r,encode(i){return DA(i,n,t)},decode(i){return RA(i,o,t,r)}})}var De=Xn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),UA=Xn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hp={};Ct(Hp,{base32:()=>yn,base32hex:()=>VA,base32hexpad:()=>FA,base32hexpadupper:()=>WA,base32hexupper:()=>$A,base32pad:()=>KA,base32padupper:()=>HA,base32upper:()=>MA,base32z:()=>qA});var yn=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),MA=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),KA=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),HA=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),VA=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),$A=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),FA=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),WA=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),qA=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vp={};Ct(Vp,{base36:()=>ba,base36upper:()=>GA});var ba=Xn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),GA=Xn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ar={};Ct(ar,{Digest:()=>Lo,create:()=>Tt,decode:()=>Yn,equals:()=>Fp,hasCode:()=>p_});var zA=wg,mg=128,XA=127,YA=~XA,ZA=Math.pow(2,31);function wg(r,e,t){e=e||[],t=t||0;for(var n=t;r>=ZA;)e[t++]=r&255|mg,r/=128;for(;r&YA;)e[t++]=r&255|mg,r>>>=7;return e[t]=r|0,wg.bytes=t-n+1,e}var JA=$p,QA=128,gg=127;function $p(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw $p.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&gg)<<o:(s&gg)*Math.pow(2,o),o+=7}while(s>=QA);return $p.bytes=i-n,t}var e_=Math.pow(2,7),t_=Math.pow(2,14),r_=Math.pow(2,21),n_=Math.pow(2,28),o_=Math.pow(2,35),i_=Math.pow(2,42),s_=Math.pow(2,49),a_=Math.pow(2,56),c_=Math.pow(2,63),u_=function(r){return r<e_?1:r<t_?2:r<r_?3:r<n_?4:r<o_?5:r<i_?6:r<s_?7:r<a_?8:r<c_?9:10},l_={encode:zA,decode:JA,encodingLength:u_},f_=l_,xa=f_;function va(r,e=0){return[xa.decode(r,e),xa.decode.bytes]}function ts(r,e,t=0){return xa.encode(r,e,t),e}function rs(r){return xa.encodingLength(r)}function Tt(r,e){let t=e.byteLength,n=rs(r),o=n+rs(t),i=new Uint8Array(o+t);return ts(r,i,0),ts(t,i,n),i.set(e,o),new Lo(r,t,e,i)}function Yn(r){let e=dn(r),[t,n]=va(e),[o,i]=va(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Lo(t,o,s,e)}function Fp(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&lg(r.bytes,t.bytes)}}var Lo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function p_(r,e){return r.code===e}function bg(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return d_(t,Wp(r),e??De.encoder);default:return y_(t,Wp(r),e??yn.encoder)}}var xg=new WeakMap;function Wp(r){let e=xg.get(r);if(e==null){let t=new Map;return xg.set(r,t),t}return e}var tt=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!==Aa)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==m_)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=Tt(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&&Fp(e.multihash,n.multihash)}toString(e){return bg(this,e)}toJSON(){return{"/":bg(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??vg(n,o,i.bytes))}else if(t[g_]===!0){let{version:n,multihash:o,code:i}=t,s=Yn(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!==Aa)throw new Error(`Version 0 CID must use dag-pb (code: ${Aa}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=vg(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Aa,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=dn(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 Lo(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=va(e.subarray(t));return t+=d,f},o=n(),i=Aa;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]=h_(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 Wp(i).set(n,e),i}};function h_(r,e){switch(r[0]){case"Q":{let t=e??De;return[De.prefix,t.decode(`${De.prefix}${r}`)]}case De.prefix:{let t=e??De;return[De.prefix,t.decode(r)]}case yn.prefix:{let t=e??yn;return[yn.prefix,t.decode(r)]}case ba.prefix:{let t=e??ba;return[ba.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 d_(r,e,t){let{prefix:n}=t;if(n!==De.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function y_(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 Aa=112,m_=18;function vg(r,e,t){let n=rs(r),o=n+rs(e),i=new Uint8Array(o+t.byteLength);return ts(r,i,0),ts(e,i,n),i.set(t,o),i}var g_=Symbol.for("@ipld/js-cid/CID");var qp={};Ct(qp,{identity:()=>_r});var Ag=0,w_="identity",_g=dn;function b_(r){return Tt(Ag,_g(r))}var _r={code:Ag,name:w_,encode:_g,digest:b_};function Ye(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 ct(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}function lt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ut(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Eg=Symbol.for("@achingbrain/uint8arraylist");function Sg(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 qu(r){return!!r?.[Eg]}var Ae=class r{bufs;length;[Eg]=!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(qu(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(qu(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=Sg(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Sg(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(qu(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 lt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:lt(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(!qu(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 d=l;d>=0;d--){let v=this.get(f+d);if(n[d]!==v){p=Math.max(1,d-a[v]);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=ut(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=ct(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=ct(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=ct(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=ut(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=ct(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=ct(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=ct(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=ct(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=ct(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(!Ye(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 Gp={};Ct(Gp,{base10:()=>v_});var v_=Xn({prefix:"9",name:"base10",alphabet:"0123456789"});var zp={};Ct(zp,{base16:()=>A_,base16upper:()=>__});var A_=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),__=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xp={};Ct(Xp,{base2:()=>S_});var S_=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Yp={};Ct(Yp,{base256emoji:()=>O_});var Cg=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}"),E_=Cg.reduce((r,e,t)=>(r[t]=e,r),[]),C_=Cg.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function T_(r){return r.reduce((e,t)=>(e+=E_[t],e),"")}function I_(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=C_[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var O_=es({prefix:"\u{1F680}",name:"base256emoji",encode:T_,decode:I_});var Zp={};Ct(Zp,{base64:()=>P_,base64pad:()=>B_,base64url:()=>Uo,base64urlpad:()=>k_});var P_=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),B_=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),k_=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Jp={};Ct(Jp,{base8:()=>N_});var N_=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qp={};Ct(Qp,{identity:()=>j_});var j_=es({prefix:"\0",name:"identity",encode:r=>pg(r),decode:r=>fg(r)});var _I=new TextEncoder,SI=new TextDecoder;var rh={};Ct(rh,{sha256:()=>cr,sha512:()=>L_});function th({name:r,code:e,encode:t}){return new eh(r,e,t)}var eh=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?Tt(this.code,t):t.then(n=>Tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ig(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var cr=th({name:"sha2-256",code:18,encode:Ig("SHA-256")}),L_=th({name:"sha2-512",code:19,encode:Ig("SHA-512")});var Mo={...Qp,...Xp,...Jp,...Gp,...zp,...Hp,...Vp,...Kp,...Zp,...Yp},DI={...rh,...qp};function Pg(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Og=Pg("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),nh=Pg("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=ut(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),U_={utf8:Og,"utf-8":Og,hex:Mo.base16,latin1:nh,ascii:nh,binary:nh,...Mo},Gu=U_;function me(r,e="utf8"){let t=Gu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ue(r,e="utf8"){let t=Gu[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var M_=parseInt("11111",2),oh=parseInt("10000000",2),K_=parseInt("01111111",2),Bg={0:_a,1:_a,2:H_,3:F_,4:W_,5:$_,6:V_,16:_a,22:_a,48:_a};function mn(r,e={offset:0}){let t=r[e.offset]&M_;if(e.offset++,Bg[t]!=null)return Bg[t](r,e);throw new Error("No decoder for tag "+t)}function Sa(r,e){let t=0;if((r[e.offset]&oh)===oh){let n=r[e.offset]&K_,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function _a(r,e){Sa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=mn(r,e);if(n===null)break;t.push(n)}return t}function H_(r,e){let t=Sa(r,e),n=e.offset,o=e.offset+t,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return e.offset+=t,Uint8Array.from(i)}function V_(r,e){let t=Sa(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let p=0;for(let f=0;f<c.length;f++)p+=c[f]<<f*7;a+=`.${p}`,c=[]}}return a}function $_(r,e){return e.offset++,null}function F_(r,e){let t=Sa(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function W_(r,e){let t=Sa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function q_(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new Ae;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function zu(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=q_(r.byteLength);return new Ae(Uint8Array.from([e.byteLength|oh]),e)}function Dt(r){let e=new Ae,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new Ae(Uint8Array.from([2]),zu(e),e)}function Ea(r){let e=Uint8Array.from([0]),t=new Ae(e,r);return new Ae(Uint8Array.from([3]),zu(t),t)}function kg(r){return new Ae(Uint8Array.from([4]),zu(r),r)}function Sr(r,e=48){let t=new Ae;for(let n of r)t.append(n);return new Ae(Uint8Array.from([e]),zu(t),t)}async function Ng(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function jg(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Rg(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 G_=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),z_=Uint8Array.from([6,5,43,129,4,0,34]),X_=Uint8Array.from([6,5,43,129,4,0,35]),Y_={ext:!0,kty:"EC",crv:"P-256"},Z_={ext:!0,kty:"EC",crv:"P-384"},J_={ext:!0,kty:"EC",crv:"P-521"},ih=32,sh=48,ah=66;function ch(r){let e=mn(r);return Dg(e)}function Dg(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===ih*2+1)return n=ue(e.subarray(t,t+ih),"base64url"),o=ue(e.subarray(t+ih),"base64url"),new Ko({...Y_,key_ops:["verify"],x:n,y:o});if(e.byteLength===sh*2+1)return n=ue(e.subarray(t,t+sh),"base64url"),o=ue(e.subarray(t+sh),"base64url"),new Ko({...Z_,key_ops:["verify"],x:n,y:o});if(e.byteLength===ah*2+1)return n=ue(e.subarray(t,t+ah),"base64url"),o=ue(e.subarray(t+ah),"base64url"),new Ko({...J_,key_ops:["verify"],x:n,y:o});throw new Se(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Lg(r){return Sr([Dt(Uint8Array.from([1])),kg(me(r.d??"","base64url")),Sr([Mg(r.crv)],160),Sr([Ea(new Ae(Uint8Array.from([4]),me(r.x??"","base64url"),me(r.y??"","base64url")))],161)]).subarray()}function Ug(r){return Sr([Dt(Uint8Array.from([1])),Sr([Mg(r.crv)],160),Sr([Ea(new Ae(Uint8Array.from([4]),me(r.x??"","base64url"),me(r.y??"","base64url")))],161)]).subarray()}function Mg(r){if(r==="P-256")return G_;if(r==="P-384")return z_;if(r==="P-521")return X_;throw new Se(`Invalid curve ${r}`)}async function Kg(r="P-256"){let e=await Ng(r);return new Xu(e.privateKey)}var Ko=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ug(this.jwk)),this._raw}toMultihash(){return _r.digest(Zn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async verify(e,t,n){return Rg(this.jwk,t,e,n)}},Xu=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Ko({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=Lg(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async sign(e,t){return jg(this.jwk,e,t)}};var Ho=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Q_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ns(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Vo(r,...e){if(!Q_(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 Ca(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ns(r.outputLen),ns(r.blockLen)}function is(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 Hg(r,e){Vo(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Er(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Yu(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Cr(r,e){return r<<32-e|r>>>e}function Vg(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Jn(r){return typeof r=="string"&&(r=Vg(r)),Vo(r),r}function uh(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Vo(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 os=class{};function lh(r){let e=n=>r().update(Jn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Ta(r=32){if(Ho&&typeof Ho.getRandomValues=="function")return Ho.getRandomValues(new Uint8Array(r));if(Ho&&typeof Ho.randomBytes=="function")return Uint8Array.from(Ho.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function eS(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 $g(r,e,t){return r&e^~r&t}function Fg(r,e,t){return r&e^r&t^e&t}var Ia=class extends os{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=Yu(this.buffer)}update(e){is(this),e=Jn(e),Vo(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=Yu(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){is(this),Hg(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Er(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let f=s;f<o;f++)t[f]=0;eS(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Yu(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()}},gn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Zu=BigInt(4294967295),Wg=BigInt(32);function tS(r,e=!1){return e?{h:Number(r&Zu),l:Number(r>>Wg&Zu)}:{h:Number(r>>Wg&Zu)|0,l:Number(r&Zu)|0}}function qg(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}=tS(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var fh=(r,e,t)=>r>>>t,ph=(r,e,t)=>r<<32-t|e>>>t,$o=(r,e,t)=>r>>>t|e<<32-t,Fo=(r,e,t)=>r<<32-t|e>>>t,Oa=(r,e,t)=>r<<64-t|e>>>t-32,Pa=(r,e,t)=>r>>>t-32|e<<64-t;function Wr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Gg=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),zg=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Xg=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Yg=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Zg=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Jg=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var nS=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]),Qn=new Uint32Array(64),Ju=class extends Ia{constructor(e=32){super(64,e,8,!1),this.A=gn[0]|0,this.B=gn[1]|0,this.C=gn[2]|0,this.D=gn[3]|0,this.E=gn[4]|0,this.F=gn[5]|0,this.G=gn[6]|0,this.H=gn[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)Qn[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let d=Qn[f-15],v=Qn[f-2],g=Cr(d,7)^Cr(d,18)^d>>>3,w=Cr(v,17)^Cr(v,19)^v>>>10;Qn[f]=w+Qn[f-7]+g+Qn[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 d=Cr(a,6)^Cr(a,11)^Cr(a,25),v=p+d+$g(a,c,l)+nS[f]+Qn[f]|0,w=(Cr(n,2)^Cr(n,13)^Cr(n,22))+Fg(n,o,i)|0;p=l,l=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,l=l+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,l,p)}roundClean(){Er(Qn)}destroy(){this.set(0,0,0,0,0,0,0,0),Er(this.buffer)}};var Qg=qg(["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))),oS=Qg[0],iS=Qg[1],eo=new Uint32Array(80),to=new Uint32Array(80),hh=class extends Ia{constructor(e=64){super(128,e,16,!1),this.Ah=mt[0]|0,this.Al=mt[1]|0,this.Bh=mt[2]|0,this.Bl=mt[3]|0,this.Ch=mt[4]|0,this.Cl=mt[5]|0,this.Dh=mt[6]|0,this.Dl=mt[7]|0,this.Eh=mt[8]|0,this.El=mt[9]|0,this.Fh=mt[10]|0,this.Fl=mt[11]|0,this.Gh=mt[12]|0,this.Gl=mt[13]|0,this.Hh=mt[14]|0,this.Hl=mt[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:p,Fh:f,Fl:d,Gh:v,Gl:g,Hh:w,Hl:_}=this;return[e,t,n,o,i,s,a,c,l,p,f,d,v,g,w,_]}set(e,t,n,o,i,s,a,c,l,p,f,d,v,g,w,_){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=d|0,this.Gh=v|0,this.Gl=g|0,this.Hh=w|0,this.Hl=_|0}process(e,t){for(let O=0;O<16;O++,t+=4)eo[O]=e.getUint32(t),to[O]=e.getUint32(t+=4);for(let O=16;O<80;O++){let x=eo[O-15]|0,D=to[O-15]|0,$=$o(x,D,1)^$o(x,D,8)^fh(x,D,7),N=Fo(x,D,1)^Fo(x,D,8)^ph(x,D,7),U=eo[O-2]|0,F=to[O-2]|0,Z=$o(U,F,19)^Oa(U,F,61)^fh(U,F,6),K=Fo(U,F,19)^Pa(U,F,61)^ph(U,F,6),X=Xg(N,K,to[O-7],to[O-16]),W=Yg(X,$,Z,eo[O-7],eo[O-16]);eo[O]=W|0,to[O]=X|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:p,Eh:f,El:d,Fh:v,Fl:g,Gh:w,Gl:_,Hh:j,Hl:J}=this;for(let O=0;O<80;O++){let x=$o(f,d,14)^$o(f,d,18)^Oa(f,d,41),D=Fo(f,d,14)^Fo(f,d,18)^Pa(f,d,41),$=f&v^~f&w,N=d&g^~d&_,U=Zg(J,D,N,iS[O],to[O]),F=Jg(U,j,x,$,oS[O],eo[O]),Z=U|0,K=$o(n,o,28)^Oa(n,o,34)^Oa(n,o,39),X=Fo(n,o,28)^Pa(n,o,34)^Pa(n,o,39),W=n&i^n&a^i&a,ae=o&s^o&c^s&c;j=w|0,J=_|0,w=v|0,_=g|0,v=f|0,g=d|0,{h:f,l:d}=Wr(l|0,p|0,F|0,Z|0),l=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let B=Gg(Z,X,ae);n=zg(B,F,K,W),o=B|0}({h:n,l:o}=Wr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Wr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Wr(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:p}=Wr(this.Dh|0,this.Dl|0,l|0,p|0),{h:f,l:d}=Wr(this.Eh|0,this.El|0,f|0,d|0),{h:v,l:g}=Wr(this.Fh|0,this.Fl|0,v|0,g|0),{h:w,l:_}=Wr(this.Gh|0,this.Gl|0,w|0,_|0),{h:j,l:J}=Wr(this.Hh|0,this.Hl|0,j|0,J|0),this.set(n,o,i,s,a,c,l,p,f,d,v,g,w,_,j,J)}roundClean(){Er(eo,to)}destroy(){Er(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Qu=lh(()=>new Ju);var e0=lh(()=>new hh);var gh=BigInt(0),mh=BigInt(1);function ss(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function wh(r){if(!ss(r))throw new Error("Uint8Array expected")}function qr(r,e){if(typeof e!="boolean")throw new Error(r+" boolean expected, got "+e)}function Ba(r){let e=r.toString(16);return e.length&1?"0"+e:e}function n0(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?gh:BigInt("0x"+r)}var o0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",sS=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ro(r){if(wh(r),o0)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=sS[r[t]];return e}var wn={_0:48,_9:57,A:65,F:70,a:97,f:102};function t0(r){if(r>=wn._0&&r<=wn._9)return r-wn._0;if(r>=wn.A&&r<=wn.F)return r-(wn.A-10);if(r>=wn.a&&r<=wn.f)return r-(wn.a-10)}function ka(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(o0)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,i=0;o<t;o++,i+=2){let s=t0(r.charCodeAt(i)),a=t0(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function bn(r){return n0(ro(r))}function Gr(r){return wh(r),n0(ro(Uint8Array.from(r).reverse()))}function Wo(r,e){return ka(r.toString(16).padStart(e*2,"0"))}function no(r,e){return Wo(r,e).reverse()}function Me(r,e,t){let n;if(typeof e=="string")try{n=ka(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(ss(e))n=Uint8Array.from(e);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof t=="number"&&o!==t)throw new Error(r+" of length "+t+" expected, got "+o);return n}function oo(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];wh(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 dh=r=>typeof r=="bigint"&&gh<=r;function el(r,e,t){return dh(r)&&dh(e)&&dh(t)&&e<=r&&r<t}function It(r,e,t,n){if(!el(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function i0(r){let e;for(e=0;r>gh;r>>=mh,e+=1);return e}var qo=r=>(mh<<BigInt(r))-mh,yh=r=>new Uint8Array(r),r0=r=>Uint8Array.from(r);function s0(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=yh(r),o=yh(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...f)=>t(o,n,...f),c=(f=yh(0))=>{o=a(r0([0]),f),n=a(),f.length!==0&&(o=a(r0([1]),f),n=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<e;){n=a();let v=n.slice();d.push(v),f+=n.length}return oo(...d)};return(f,d)=>{s(),c(f);let v;for(;!(v=d(l()));)c();return s(),v}}var aS={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"||ss(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 Tr(r,e,t={}){let n=(o,i,s)=>{let a=aS[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 as(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 Lt=BigInt(0),ht=BigInt(1),Go=BigInt(2),cS=BigInt(3),c0=BigInt(4),u0=BigInt(5),l0=BigInt(8);function Pe(r,e){let t=r%e;return t>=Lt?t:e+t}function We(r,e,t){let n=r;for(;e-- >Lt;)n*=n,n%=t;return n}function tl(r,e){if(r===Lt)throw new Error("invert: expected non-zero number");if(e<=Lt)throw new Error("invert: expected positive modulus, got "+e);let t=Pe(r,e),n=e,o=Lt,i=ht,s=ht,a=Lt;for(;t!==Lt;){let l=n/t,p=n%t,f=o-s*l,d=i-a*l;n=t,t=p,o=s,i=a,s=f,a=d}if(n!==ht)throw new Error("invert: does not exist");return Pe(o,e)}function f0(r,e){let t=(r.ORDER+ht)/c0,n=r.pow(e,t);if(!r.eql(r.sqr(n),e))throw new Error("Cannot find square root");return n}function uS(r,e){let t=(r.ORDER-u0)/l0,n=r.mul(e,Go),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,Go),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 lS(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let e=r-ht,t=0;for(;e%Go===Lt;)e/=Go,t++;let n=Go,o=xn(r);for(;a0(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return f0;let i=o.pow(n,e),s=(e+ht)/Go;return function(c,l){if(c.is0(l))return l;if(a0(c,l)!==1)throw new Error("Cannot find square root");let p=t,f=c.mul(c.ONE,i),d=c.pow(l,e),v=c.pow(l,s);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let g=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(g++,w=c.sqr(w),g===p)throw new Error("Cannot find square root");let _=ht<<BigInt(p-g-1),j=c.pow(f,_);p=g,f=c.sqr(j),d=c.mul(d,f),v=c.mul(v,j)}return v}}function fS(r){return r%c0===cS?f0:r%l0===u0?uS:lS(r)}var p0=(r,e)=>(Pe(r,e)&ht)===ht,pS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function bh(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=pS.reduce((n,o)=>(n[o]="function",n),e);return Tr(r,t)}function hS(r,e,t){if(t<Lt)throw new Error("invalid exponent, negatives unsupported");if(t===Lt)return r.ONE;if(t===ht)return e;let n=r.ONE,o=e;for(;t>Lt;)t&ht&&(n=r.mul(n,o)),o=r.sqr(o),t>>=ht;return n}function cs(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 a0(r,e){let t=(r.ORDER-ht)/Go,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 xh(r,e){e!==void 0&&ns(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function xn(r,e,t=!1,n={}){if(r<=Lt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=xh(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:qo(o),ZERO:Lt,ONE:ht,create:c=>Pe(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Lt<=c&&c<r},is0:c=>c===Lt,isOdd:c=>(c&ht)===ht,neg:c=>Pe(-c,r),eql:(c,l)=>c===l,sqr:c=>Pe(c*c,r),add:(c,l)=>Pe(c+l,r),sub:(c,l)=>Pe(c-l,r),mul:(c,l)=>Pe(c*l,r),pow:(c,l)=>hS(a,c,l),div:(c,l)=>Pe(c*tl(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>tl(c,r),sqrt:n.sqrt||(c=>(s||(s=fS(r)),s(a,c))),toBytes:c=>t?no(c,i):Wo(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return t?Gr(c):bn(c)},invertBatch:c=>cs(a,c),cmov:(c,l,p)=>p?l:c});return Object.freeze(a)}function h0(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 vh(r){let e=h0(r);return e+Math.ceil(e/2)}function d0(r,e,t=!1){let n=r.length,o=h0(e),i=vh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?Gr(r):bn(r),a=Pe(s,e-ht)+ht;return t?no(a,o):Wo(a,o)}var y0=BigInt(0),Ch=BigInt(1);function Ah(r,e){let t=e.negate();return r?t:e}function g0(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function _h(r,e){g0(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=qo(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function m0(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+=Ch);let l=e*n,p=l+Math.abs(a)-1,f=a===0,d=a<0,v=e%2!==0;return{nextN:c,offset:p,isZero:f,isNeg:d,isNegF:v,offsetF:l}}function dS(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 yS(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 Sh=new WeakMap,w0=new WeakMap;function Eh(r){return w0.get(r)||1}function rl(r,e){return{constTimeNegate:Ah,hasPrecomputes(t){return Eh(t)!==1},unsafeLadder(t,n,o=r.ZERO){let i=t;for(;n>y0;)n&Ch&&(o=o.add(i)),i=i.double(),n>>=Ch;return o},precomputeWindow(t,n){let{windows:o,windowSize:i}=_h(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=_h(t,e);for(let c=0;c<a.windows;c++){let{nextN:l,offset:p,isZero:f,isNeg:d,isNegF:v,offsetF:g}=m0(o,c,a);o=l,f?s=s.add(Ah(v,n[g])):i=i.add(Ah(d,n[p]))}return{p:i,f:s}},wNAFUnsafe(t,n,o,i=r.ZERO){let s=_h(t,e);for(let a=0;a<s.windows&&o!==y0;a++){let{nextN:c,offset:l,isZero:p,isNeg:f}=m0(o,a,s);if(o=c,!p){let d=n[l];i=i.add(f?d.negate():d)}}return i},getPrecomputes(t,n,o){let i=Sh.get(n);return i||(i=this.precomputeWindow(n,t),t!==1&&Sh.set(n,o(i))),i},wNAFCached(t,n,o){let i=Eh(t);return this.wNAF(i,this.getPrecomputes(i,t,o),n)},wNAFCachedUnsafe(t,n,o,i){let s=Eh(t);return s===1?this.unsafeLadder(t,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,t,o),n,i)},setWindowSize(t,n){g0(n,e),w0.set(t,n),Sh.delete(t)}}}function nl(r,e,t,n){dS(t,r),yS(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=i0(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=qo(c),p=new Array(Number(l)+1).fill(s),f=Math.floor((e.BITS-1)/c)*c,d=s;for(let v=f;v>=0;v-=c){p.fill(s);for(let w=0;w<i;w++){let _=n[w],j=Number(_>>BigInt(v)&l);p[j]=p[j].add(t[w])}let g=s;for(let w=p.length-1,_=s;w>0;w--)_=_.add(p[w]),g=g.add(_);if(d=d.add(g),v!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Na(r){return bh(r.Fp),Tr(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...xh(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var zr=BigInt(0),Ut=BigInt(1),b0=BigInt(2),mS=BigInt(8),gS={zip215:!0};function wS(r){let e=Na(r);return Tr(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function x0(r){let e=wS(r),{Fp:t,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=e,l=b0<<BigInt(a*8)-Ut,p=t.create,f=xn(e.n,e.nBitLength);function d(k,y){let T=t.sqr(k),L=t.sqr(y),I=t.add(t.mul(e.a,T),L),oe=t.add(t.ONE,t.mul(e.d,t.mul(T,L)));return t.eql(I,oe)}if(!d(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let v=e.uvRatio||((k,y)=>{try{return{isValid:!0,value:t.sqrt(k*t.inv(y))}}catch{return{isValid:!1,value:zr}}}),g=e.adjustScalarBytes||(k=>k),w=e.domain||((k,y,T)=>{if(qr("phflag",T),y.length||T)throw new Error("Contexts/pre-hash are not supported");return k});function _(k,y,T=!1){let L=T?Ut:zr;It("coordinate "+k,y,L,l)}function j(k){if(!(k instanceof x))throw new Error("ExtendedPoint expected")}let J=as((k,y)=>{let{ex:T,ey:L,ez:I}=k,oe=k.is0();y==null&&(y=oe?mS:t.inv(I));let pe=p(T*y),te=p(L*y),de=p(I*y);if(oe)return{x:zr,y:Ut};if(de!==Ut)throw new Error("invZ was invalid");return{x:pe,y:te}}),O=as(k=>{let{a:y,d:T}=e;if(k.is0())throw new Error("bad point: ZERO");let{ex:L,ey:I,ez:oe,et:pe}=k,te=p(L*L),de=p(I*I),ye=p(oe*oe),Ce=p(ye*ye),Te=p(te*y),Re=p(ye*p(Te+de)),yt=p(Ce+p(T*p(te*de)));if(Re!==yt)throw new Error("bad point: equation left != right (1)");let $e=p(L*I),st=p(oe*pe);if($e!==st)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(y,T,L,I){_("x",y),_("y",T),_("z",L,!0),_("t",I),this.ex=y,this.ey=T,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 x)throw new Error("extended point not allowed");let{x:T,y:L}=y||{};return _("x",T),_("y",L),new x(T,L,Ut,p(T*L))}static normalizeZ(y){let T=cs(t,y.map(L=>L.ez));return y.map((L,I)=>L.toAffine(T[I])).map(x.fromAffine)}static msm(y,T){return nl(x,f,y,T)}_setWindowSize(y){N.setWindowSize(this,y)}assertValidity(){O(this)}equals(y){j(y);let{ex:T,ey:L,ez:I}=this,{ex:oe,ey:pe,ez:te}=y,de=p(T*te),ye=p(oe*I),Ce=p(L*te),Te=p(pe*I);return de===ye&&Ce===Te}is0(){return this.equals(x.ZERO)}negate(){return new x(p(-this.ex),this.ey,this.ez,p(-this.et))}double(){let{a:y}=e,{ex:T,ey:L,ez:I}=this,oe=p(T*T),pe=p(L*L),te=p(b0*p(I*I)),de=p(y*oe),ye=T+L,Ce=p(p(ye*ye)-oe-pe),Te=de+pe,Re=Te-te,yt=de-pe,$e=p(Ce*Re),st=p(Te*yt),jt=p(Ce*yt),Rt=p(Re*Te);return new x($e,st,Rt,jt)}add(y){j(y);let{a:T,d:L}=e,{ex:I,ey:oe,ez:pe,et:te}=this,{ex:de,ey:ye,ez:Ce,et:Te}=y,Re=p(I*de),yt=p(oe*ye),$e=p(te*L*Te),st=p(pe*Ce),jt=p((I+oe)*(de+ye)-Re-yt),Rt=st-$e,qn=st+$e,ya=p(yt-T*Re),Bu=p(jt*Rt),ku=p(qn*ya),Nu=p(jt*ya),ma=p(Rt*qn);return new x(Bu,ku,ma,Nu)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,y,x.normalizeZ)}multiply(y){let T=y;It("scalar",T,Ut,n);let{p:L,f:I}=this.wNAF(T);return x.normalizeZ([L,I])[0]}multiplyUnsafe(y,T=x.ZERO){let L=y;return It("scalar",L,zr,n),L===zr?$:this.is0()||L===Ut?this:N.wNAFCachedUnsafe(this,L,x.normalizeZ,T)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){return J(this,y)}clearCofactor(){let{h:y}=e;return y===Ut?this:this.multiplyUnsafe(y)}static fromHex(y,T=!1){let{d:L,a:I}=e,oe=t.BYTES;y=Me("pointHex",y,oe),qr("zip215",T);let pe=y.slice(),te=y[oe-1];pe[oe-1]=te&-129;let de=Gr(pe),ye=T?l:t.ORDER;It("pointHex.y",de,zr,ye);let Ce=p(de*de),Te=p(Ce-Ut),Re=p(L*Ce-I),{isValid:yt,value:$e}=v(Te,Re);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let st=($e&Ut)===Ut,jt=(te&128)!==0;if(!T&&$e===zr&&jt)throw new Error("Point.fromHex: x=0 and x_0=1");return jt!==st&&($e=p(-$e)),x.fromAffine({x:$e,y:de})}static fromPrivateKey(y){let{scalar:T}=Z(y);return D.multiply(T)}toRawBytes(){let{x:y,y:T}=this.toAffine(),L=no(T,t.BYTES);return L[L.length-1]|=y&Ut?128:0,L}toHex(){return ro(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,Ut,p(e.Gx*e.Gy)),x.ZERO=new x(zr,Ut,Ut,zr);let{BASE:D,ZERO:$}=x,N=rl(x,a*8);function U(k){return Pe(k,n)}function F(k){return U(Gr(k))}function Z(k){let y=t.BYTES;k=Me("private key",k,y);let T=Me("hashed private key",i(k),2*y),L=g(T.slice(0,y)),I=T.slice(y,2*y),oe=F(L);return{head:L,prefix:I,scalar:oe}}function K(k){let{head:y,prefix:T,scalar:L}=Z(k),I=D.multiply(L),oe=I.toRawBytes();return{head:y,prefix:T,scalar:L,point:I,pointBytes:oe}}function X(k){return K(k).pointBytes}function W(k=Uint8Array.of(),...y){let T=oo(...y);return F(i(w(T,Me("context",k),!!o)))}function ae(k,y,T={}){k=Me("message",k),o&&(k=o(k));let{prefix:L,scalar:I,pointBytes:oe}=K(y),pe=W(T.context,L,k),te=D.multiply(pe).toRawBytes(),de=W(T.context,te,oe,k),ye=U(pe+de*I);It("signature.s",ye,zr,n);let Ce=oo(te,no(ye,t.BYTES));return Me("result",Ce,t.BYTES*2)}let B=gS;function R(k,y,T,L=B){let{context:I,zip215:oe}=L,pe=t.BYTES;k=Me("signature",k,2*pe),y=Me("message",y),T=Me("publicKey",T,pe),oe!==void 0&&qr("zip215",oe),o&&(y=o(y));let te=Gr(k.slice(pe,2*pe)),de,ye,Ce;try{de=x.fromHex(T,oe),ye=x.fromHex(k.slice(0,pe),oe),Ce=D.multiplyUnsafe(te)}catch{return!1}if(!oe&&de.isSmallOrder())return!1;let Te=W(I,ye.toRawBytes(),de.toRawBytes(),y);return ye.add(de.multiplyUnsafe(Te)).subtract(Ce).clearCofactor().equals(x.ZERO)}return D._setWindowSize(8),{CURVE:e,getPublicKey:X,sign:ae,verify:R,ExtendedPoint:x,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>s(t.BYTES),precompute(k=8,y=x.BASE){return y._setWindowSize(k),y.multiply(BigInt(3)),y}}}}var ja=BigInt(0),us=BigInt(1),ol=BigInt(2);function bS(r){return Tr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function v0(r){let e=bS(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,l=BigInt(s?9:5),p=BigInt(s?121665:39081),f=s?ol**BigInt(254):ol**BigInt(447),d=s?BigInt(8)*ol**BigInt(251)-us:BigInt(4)*ol**BigInt(445)-us,v=f+d+us,g=N=>Pe(N,t),w=_(l);function _(N){return no(g(N),c)}function j(N){let U=Me("u coordinate",N,c);return s&&(U[31]&=127),g(Gr(U))}function J(N){return Gr(o(Me("scalar",N,c)))}function O(N,U){let F=$(j(U),J(N));if(F===ja)throw new Error("invalid private or public key received");return _(F)}function x(N){return O(N,w)}function D(N,U,F){let Z=g(N*(U-F));return U=g(U-Z),F=g(F+Z),{x_2:U,x_3:F}}function $(N,U){It("u",N,ja,t),It("scalar",U,f,v);let F=U,Z=N,K=us,X=ja,W=N,ae=us,B=ja;for(let H=BigInt(a-1);H>=ja;H--){let k=F>>H&us;B^=k,{x_2:K,x_3:W}=D(B,K,W),{x_2:X,x_3:ae}=D(B,X,ae),B=k;let y=K+X,T=g(y*y),L=K-X,I=g(L*L),oe=T-I,pe=W+ae,te=W-ae,de=g(te*y),ye=g(pe*L),Ce=de+ye,Te=de-ye;W=g(Ce*Ce),ae=g(Z*g(Te*Te)),K=g(T*I),X=g(oe*(T+g(p*oe)))}({x_2:K,x_3:W}=D(B,K,W)),{x_2:X,x_3:ae}=D(B,X,ae);let R=i(X);return g(K*R)}return{scalarMult:O,scalarMultBase:x,getSharedSecret:(N,U)=>O(N,U),getPublicKey:N=>x(N),utils:{randomPrivateKey:()=>e.randomBytes(c)},GuBytes:w.slice()}}var Ra=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),A0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),KO=BigInt(0),xS=BigInt(1),_0=BigInt(2),vS=BigInt(3),AS=BigInt(5),_S=BigInt(8);function E0(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Ra,a=r*r%i*r%i,c=We(a,_0,i)*a%i,l=We(c,xS,i)*r%i,p=We(l,AS,i)*l%i,f=We(p,e,i)*p%i,d=We(f,t,i)*f%i,v=We(d,n,i)*d%i,g=We(v,o,i)*v%i,w=We(g,o,i)*v%i,_=We(w,e,i)*p%i;return{pow_p_5_8:We(_,_0,i)*r%i,b2:a}}function C0(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function SS(r,e){let t=Ra,n=Pe(e*e*e,t),o=Pe(n*n*e,t),i=E0(r*o).pow_p_5_8,s=Pe(r*n*i,t),a=Pe(e*s*s,t),c=s,l=Pe(s*A0,t),p=a===r,f=a===Pe(-r,t),d=a===Pe(-r*A0,t);return p&&(s=c),(f||d)&&(s=l),p0(s,t)&&(s=Pe(-s,t)),{isValid:p||f,value:s}}var S0=xn(Ra,void 0,!0),ES={a:S0.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:S0,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:_S,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:e0,randomBytes:Ta,adjustScalarBytes:C0,uvRatio:SS},Da=x0(ES);var La=v0({P:Ra,type:"x25519",powPminus2:r=>{let e=Ra,{pow_p_5_8:t,b2:n}=E0(r);return Pe(We(t,vS,e)*n,e)},adjustScalarBytes:C0,randomBytes:Ta});var Ua=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Ma=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},il=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var T0={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new il("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 Vt=T0;var sl=32,Ka=64,Th=32;var ls,I0=(async()=>{try{return await Vt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function O0(){let r=Da.utils.randomPrivateKey(),e=Da.getPublicKey(r);return{privateKey:PS(r,e),publicKey:e}}async function CS(r,e){let t;r.length===Ka?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:ue(r.subarray(32),"base64url"),d:ue(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Vt.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Vt.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function TS(r,e){let t=r.subarray(0,Th);return Da.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function P0(r,e){return ls==null&&(ls=await I0),ls?CS(r,e):TS(r,e)}async function IS(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Vt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Vt.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 OS(r,e,t){return Da.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function B0(r,e,t){return ls==null&&(ls=await I0),ls?IS(r,e,t):OS(r,e,t)}function PS(r,e){let t=new Uint8Array(Ka);for(let n=0;n<Th;n++)t[n]=r[n],t[Th+n]=e[n];return t}function fs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Ha=class{type="Ed25519";raw;constructor(e){this.raw=cl(e,sl)}toMultihash(){return _r.digest(Zn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=B0(this.raw,t,e);return fs(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},al=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=cl(e,Ka),this.publicKey=new Ha(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=P0(this.raw,e);return fs(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Ih(r){return r=cl(r,sl),new Ha(r)}async function N0(){let{privateKey:r,publicKey:e}=O0();return new al(r,e)}function cl(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Se(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var BS=Math.pow(2,7),kS=Math.pow(2,14),NS=Math.pow(2,21),Oh=Math.pow(2,28),Ph=Math.pow(2,35),Bh=Math.pow(2,42),kh=Math.pow(2,49),Ne=128,Ot=127;function qe(r){if(r<BS)return 1;if(r<kS)return 2;if(r<NS)return 3;if(r<Oh)return 4;if(r<Ph)return 5;if(r<Bh)return 6;if(r<kh)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Nh(r,e,t=0){switch(qe(r)){case 8:e[t++]=r&255|Ne,r/=128;case 7:e[t++]=r&255|Ne,r/=128;case 6:e[t++]=r&255|Ne,r/=128;case 5:e[t++]=r&255|Ne,r/=128;case 4:e[t++]=r&255|Ne,r>>>=7;case 3:e[t++]=r&255|Ne,r>>>=7;case 2:e[t++]=r&255|Ne,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function jS(r,e,t=0){switch(qe(r)){case 8:e.set(t++,r&255|Ne),r/=128;case 7:e.set(t++,r&255|Ne),r/=128;case 6:e.set(t++,r&255|Ne),r/=128;case 5:e.set(t++,r&255|Ne),r/=128;case 4:e.set(t++,r&255|Ne),r>>>=7;case 3:e.set(t++,r&255|Ne),r>>>=7;case 2:e.set(t++,r&255|Ne),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function jh(r,e){let t=r[e],n=0;if(n+=t&Ot,t<Ne||(t=r[e+1],n+=(t&Ot)<<7,t<Ne)||(t=r[e+2],n+=(t&Ot)<<14,t<Ne)||(t=r[e+3],n+=(t&Ot)<<21,t<Ne)||(t=r[e+4],n+=(t&Ot)*Oh,t<Ne)||(t=r[e+5],n+=(t&Ot)*Ph,t<Ne)||(t=r[e+6],n+=(t&Ot)*Bh,t<Ne)||(t=r[e+7],n+=(t&Ot)*kh,t<Ne))return n;throw new RangeError("Could not decode varint")}function RS(r,e){let t=r.get(e),n=0;if(n+=t&Ot,t<Ne||(t=r.get(e+1),n+=(t&Ot)<<7,t<Ne)||(t=r.get(e+2),n+=(t&Ot)<<14,t<Ne)||(t=r.get(e+3),n+=(t&Ot)<<21,t<Ne)||(t=r.get(e+4),n+=(t&Ot)*Oh,t<Ne)||(t=r.get(e+5),n+=(t&Ot)*Ph,t<Ne)||(t=r.get(e+6),n+=(t&Ot)*Bh,t<Ne)||(t=r.get(e+7),n+=(t&Ot)*kh,t<Ne))return n;throw new RangeError("Could not decode varint")}function Xr(r,e,t=0){return e==null&&(e=ut(qe(r))),e instanceof Uint8Array?Nh(r,e,t):jS(r,e,t)}function Ir(r,e=0){return r instanceof Uint8Array?jh(r,e):RS(r,e)}var Rh=new Float32Array([-0]),io=new Uint8Array(Rh.buffer);function j0(r,e,t){Rh[0]=r,e[t]=io[0],e[t+1]=io[1],e[t+2]=io[2],e[t+3]=io[3]}function R0(r,e){return io[0]=r[e],io[1]=r[e+1],io[2]=r[e+2],io[3]=r[e+3],Rh[0]}var Dh=new Float64Array([-0]),Pt=new Uint8Array(Dh.buffer);function D0(r,e,t){Dh[0]=r,e[t]=Pt[0],e[t+1]=Pt[1],e[t+2]=Pt[2],e[t+3]=Pt[3],e[t+4]=Pt[4],e[t+5]=Pt[5],e[t+6]=Pt[6],e[t+7]=Pt[7]}function L0(r,e){return Pt[0]=r[e],Pt[1]=r[e+1],Pt[2]=r[e+2],Pt[3]=r[e+3],Pt[4]=r[e+4],Pt[5]=r[e+5],Pt[6]=r[e+6],Pt[7]=r[e+7],Dh[0]}var DS=BigInt(Number.MAX_SAFE_INTEGER),LS=BigInt(Number.MIN_SAFE_INTEGER),rr=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return zo;if(e<DS&&e>LS)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>U0&&(o=0n,++n>U0&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return zo;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):zo}},zo=new rr(0,0);zo.toBigInt=function(){return 0n};zo.zzEncode=zo.zzDecode=function(){return this};zo.length=function(){return 1};var U0=4294967296n;function M0(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 K0(r,e,t){if(t-e<1)return"";let o,i=[],s=0,a;for(;e<t;)a=r[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Lh(r,e,t){let n=t,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function Or(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function ul(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Uh=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Or(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 Or(this,4);return ul(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Or(this,4);return ul(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Or(this,4);let e=R0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Or(this,4);let e=L0(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 Or(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return K0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Or(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Or(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new rr(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Or(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 Or(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 Or(this,8);let e=ul(this.buf,this.pos+=4),t=ul(this.buf,this.pos+=4);return new rr(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=jh(this.buf,this.pos);return this.pos+=qe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Mh(r){return new Uh(r instanceof Uint8Array?r:r.subarray())}function Pr(r,e,t){let n=Mh(r);return e.decode(n,void 0,t)}function Kh(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ut(s);o+s>e&&(n=ut(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Xo=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Hh(){}var $h=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},US=Kh();function MS(r){return globalThis.Buffer!=null?ut(r):US(r)}var Fa=class{len;head;tail;states;constructor(){this.len=0,this.head=new Xo(Hh,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new Xo(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fh((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(ll,10,rr.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=rr.fromBigInt(e);return this._push(ll,t.length(),t)}uint64Number(e){return this._push(Nh,qe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=rr.fromBigInt(e).zzEncode();return this._push(ll,t.length(),t)}sint64Number(e){let t=rr.fromNumber(e).zzEncode();return this._push(ll,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vh,1,e?1:0)}fixed32(e){return this._push($a,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=rr.fromBigInt(e);return this._push($a,4,t.lo)._push($a,4,t.hi)}fixed64Number(e){let t=rr.fromNumber(e);return this._push($a,4,t.lo)._push($a,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(j0,4,e)}double(e){return this._push(D0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Vh,1,0):this.uint32(t)._push(HS,t,e)}string(e){let t=M0(e);return t!==0?this.uint32(t)._push(Lh,t,e):this._push(Vh,1,0)}fork(){return this.states=new $h(this),this.head=this.tail=new Xo(Hh,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Xo(Hh,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=MS(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Vh(r,e,t){e[t]=r&255}function KS(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Fh=class extends Xo{next;constructor(e,t){super(KS,e,t),this.next=void 0}};function ll(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function $a(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 HS(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Fa.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(VS,e,r),this},Fa.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push($S,e,r),this});function VS(r,e,t){e.set(r,t)}function $S(r,e,t){r.length<40?Lh(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(me(r),t)}function Wh(){return new Fa}function Br(r,e){let t=Wh();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var ps;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ps||(ps={}));function fl(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Yo(r){function e(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let t=function(i,s){let a=e(i);s.int32(a)},n=function(i){let s=i.int32();return e(s)};return fl("enum",ps.VARINT,t,n)}function kr(r,e){return fl("message",ps.LENGTH_DELIMITED,r,e)}var Wa=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(rt||(rt={}));var qh;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(qh||(qh={}));(function(r){r.codec=()=>Yo(qh)})(rt||(rt={}));var Yr;(function(r){let e;r.codec=()=>(e==null&&(e=kr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Br(t,r.codec()),r.decode=(t,n)=>Pr(t,r.codec(),n)})(Yr||(Yr={}));var Gh;(function(r){let e;r.codec=()=>(e==null&&(e=kr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),rt.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=rt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Br(t,r.codec()),r.decode=(t,n)=>Pr(t,r.codec(),n)})(Gh||(Gh={}));var Ga={};Ct(Ga,{MAX_RSA_KEY_SIZE:()=>zh,generateRSAKeyPair:()=>nd,jwkToJWKKeyPair:()=>q0,jwkToPkcs1:()=>GS,jwkToPkix:()=>Jh,jwkToRSAPrivateKey:()=>rd,pkcs1MessageToJwk:()=>Yh,pkcs1MessageToRSAPrivateKey:()=>Qh,pkcs1ToJwk:()=>qS,pkcs1ToRSAPrivateKey:()=>W0,pkixMessageToJwk:()=>Zh,pkixMessageToRSAPublicKey:()=>td,pkixToJwk:()=>zS,pkixToRSAPublicKey:()=>ed});var so=Qu;var hs=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=Ga.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){return F0(this.jwk,t,e,n)}},qa=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=Ga.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return $0(this.jwk,e,t)}};var zh=8192,Xh=18,FS=1062,WS=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function qS(r){let e=mn(r);return Yh(e)}function Yh(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 GS(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 Se("JWK was missing components");return Sr([Dt(Uint8Array.from([0])),Dt(me(r.n,"base64url")),Dt(me(r.e,"base64url")),Dt(me(r.d,"base64url")),Dt(me(r.p,"base64url")),Dt(me(r.q,"base64url")),Dt(me(r.dp,"base64url")),Dt(me(r.dq,"base64url")),Dt(me(r.qi,"base64url"))]).subarray()}function zS(r){let e=mn(r,{offset:0});return Zh(e)}function Zh(r){let e=mn(r[1],{offset:0});return{kty:"RSA",n:ue(e[0],"base64url"),e:ue(e[1],"base64url")}}function Jh(r){if(r.n==null||r.e==null)throw new Se("JWK was missing components");return Sr([WS,Ea(Sr([Dt(me(r.n,"base64url")),Dt(me(r.e,"base64url"))]))]).subarray()}function W0(r){let e=mn(r);return Qh(e)}function Qh(r){let e=Yh(r);return rd(e)}function ed(r,e){if(r.byteLength>=FS)throw new Ji("Key size is too large");let t=mn(r,{offset:0});return td(t,r,e)}function td(r,e,t){let n=Zh(r);if(t==null){let o=so(Yr.encode({Type:rt.RSA,Data:e}));t=Tt(Xh,o)}return new hs(n,t)}function rd(r){if(z0(r)>zh)throw new Se("Key size is too large");let e=q0(r),t=so(Yr.encode({Type:rt.RSA,Data:Jh(e.publicKey)})),n=Tt(Xh,t);return new qa(e.privateKey,new hs(e.publicKey,n))}async function nd(r){if(r>zh)throw new Se("Key size is too large");let e=await G0(r),t=so(Yr.encode({Type:rt.RSA,Data:Jh(e.publicKey)})),n=Tt(Xh,t);return new qa(e.privateKey,new hs(e.publicKey,n))}function q0(r){if(r==null)throw new Se("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function G0(r,e){let t=await Vt.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 XS(t,e);return{privateKey:n[0],publicKey:n[1]}}async function $0(r,e,t){let n=await Vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Vt.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 F0(r,e,t,n){let o=await Vt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Vt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function XS(r,e){if(r.privateKey==null||r.publicKey==null)throw new Se("Private and public key are required");let t=await Promise.all([Vt.get().subtle.exportKey("jwk",r.privateKey),Vt.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function z0(r){if(r.kty!=="RSA")throw new Se("invalid key type");if(r.n==null)throw new Se("invalid key modulus");return me(r.n,"base64url").length*8}var pl=class extends os{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ca(e);let n=Jn(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),Er(i)}update(e){return is(this),this.iHash.update(e),this}digestInto(e){is(this),Vo(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ds=(r,e,t)=>new pl(r,e).update(t).digest();ds.create=(r,e)=>new pl(r,e);function X0(r){r.lowS!==void 0&&qr("lowS",r.lowS),r.prehash!==void 0&&qr("prehash",r.prehash)}function YS(r){let e=Na(r);Tr(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 sd=class extends Error{constructor(e=""){super(e)}},vn={Err:sd,_tlv:{encode:(r,e)=>{let{Err:t}=vn;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=Ba(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Ba(o.length/2|128):"";return Ba(r)+i+o+e},decode(r,e){let{Err:t}=vn,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}=vn;if(r<An)throw new e("integer: negative integers are not allowed");let t=Ba(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}=vn;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 bn(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=vn,o=Me("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}=vn,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 od(r,e){return ro(Wo(r,e))}var An=BigInt(0),dt=BigInt(1),mB=BigInt(2),id=BigInt(3),ZS=BigInt(4);function JS(r){let e=YS(r),{Fp:t}=e,n=xn(e.n,e.nBitLength),o=e.toBytes||((O,x,D)=>{let $=x.toAffine();return oo(Uint8Array.from([4]),t.toBytes($.x),t.toBytes($.y))}),i=e.fromBytes||(O=>{let x=O.subarray(1),D=t.fromBytes(x.subarray(0,t.BYTES)),$=t.fromBytes(x.subarray(t.BYTES,2*t.BYTES));return{x:D,y:$}});function s(O){let{a:x,b:D}=e,$=t.sqr(O),N=t.mul($,O);return t.add(t.add(N,t.mul(O,x)),D)}function a(O,x){let D=t.sqr(x),$=s(O);return t.eql(D,$)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=t.mul(t.pow(e.a,id),ZS),l=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(c,l)))throw new Error("bad curve params: a or b");function p(O){return el(O,dt,e.n)}function f(O){let{allowedPrivateKeyLengths:x,nByteLength:D,wrapPrivateKey:$,n:N}=e;if(x&&typeof O!="bigint"){if(ss(O)&&(O=ro(O)),typeof O!="string"||!x.includes(O.length))throw new Error("invalid private key");O=O.padStart(D*2,"0")}let U;try{U=typeof O=="bigint"?O:bn(Me("private key",O,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof O)}return $&&(U=Pe(U,N)),It("private key",U,dt,N),U}function d(O){if(!(O instanceof w))throw new Error("ProjectivePoint expected")}let v=as((O,x)=>{let{px:D,py:$,pz:N}=O;if(t.eql(N,t.ONE))return{x:D,y:$};let U=O.is0();x==null&&(x=U?t.ONE:t.inv(N));let F=t.mul(D,x),Z=t.mul($,x),K=t.mul(N,x);if(U)return{x:t.ZERO,y:t.ZERO};if(!t.eql(K,t.ONE))throw new Error("invZ was invalid");return{x:F,y:Z}}),g=as(O=>{if(O.is0()){if(e.allowInfinityPoint&&!t.is0(O.py))return;throw new Error("bad point: ZERO")}let{x,y:D}=O.toAffine();if(!t.isValid(x)||!t.isValid(D))throw new Error("bad point: x or y not FE");if(!a(x,D))throw new Error("bad point: equation left != right");if(!O.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(x,D,$){if(x==null||!t.isValid(x))throw new Error("x required");if(D==null||!t.isValid(D)||t.is0(D))throw new Error("y required");if($==null||!t.isValid($))throw new Error("z required");this.px=x,this.py=D,this.pz=$,Object.freeze(this)}static fromAffine(x){let{x:D,y:$}=x||{};if(!x||!t.isValid(D)||!t.isValid($))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");let N=U=>t.eql(U,t.ZERO);return N(D)&&N($)?w.ZERO:new w(D,$,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){let D=cs(t,x.map($=>$.pz));return x.map(($,N)=>$.toAffine(D[N])).map(w.fromAffine)}static fromHex(x){let D=w.fromAffine(i(Me("pointHex",x)));return D.assertValidity(),D}static fromPrivateKey(x){return w.BASE.multiply(f(x))}static msm(x,D){return nl(w,n,x,D)}_setWindowSize(x){J.setWindowSize(this,x)}assertValidity(){g(this)}hasEvenY(){let{y:x}=this.toAffine();if(t.isOdd)return!t.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){d(x);let{px:D,py:$,pz:N}=this,{px:U,py:F,pz:Z}=x,K=t.eql(t.mul(D,Z),t.mul(U,N)),X=t.eql(t.mul($,Z),t.mul(F,N));return K&&X}negate(){return new w(this.px,t.neg(this.py),this.pz)}double(){let{a:x,b:D}=e,$=t.mul(D,id),{px:N,py:U,pz:F}=this,Z=t.ZERO,K=t.ZERO,X=t.ZERO,W=t.mul(N,N),ae=t.mul(U,U),B=t.mul(F,F),R=t.mul(N,U);return R=t.add(R,R),X=t.mul(N,F),X=t.add(X,X),Z=t.mul(x,X),K=t.mul($,B),K=t.add(Z,K),Z=t.sub(ae,K),K=t.add(ae,K),K=t.mul(Z,K),Z=t.mul(R,Z),X=t.mul($,X),B=t.mul(x,B),R=t.sub(W,B),R=t.mul(x,R),R=t.add(R,X),X=t.add(W,W),W=t.add(X,W),W=t.add(W,B),W=t.mul(W,R),K=t.add(K,W),B=t.mul(U,F),B=t.add(B,B),W=t.mul(B,R),Z=t.sub(Z,W),X=t.mul(B,ae),X=t.add(X,X),X=t.add(X,X),new w(Z,K,X)}add(x){d(x);let{px:D,py:$,pz:N}=this,{px:U,py:F,pz:Z}=x,K=t.ZERO,X=t.ZERO,W=t.ZERO,ae=e.a,B=t.mul(e.b,id),R=t.mul(D,U),H=t.mul($,F),k=t.mul(N,Z),y=t.add(D,$),T=t.add(U,F);y=t.mul(y,T),T=t.add(R,H),y=t.sub(y,T),T=t.add(D,N);let L=t.add(U,Z);return T=t.mul(T,L),L=t.add(R,k),T=t.sub(T,L),L=t.add($,N),K=t.add(F,Z),L=t.mul(L,K),K=t.add(H,k),L=t.sub(L,K),W=t.mul(ae,T),K=t.mul(B,k),W=t.add(K,W),K=t.sub(H,W),W=t.add(H,W),X=t.mul(K,W),H=t.add(R,R),H=t.add(H,R),k=t.mul(ae,k),T=t.mul(B,T),H=t.add(H,k),k=t.sub(R,k),k=t.mul(ae,k),T=t.add(T,k),R=t.mul(H,T),X=t.add(X,R),R=t.mul(L,T),K=t.mul(y,K),K=t.sub(K,R),R=t.mul(y,H),W=t.mul(L,W),W=t.add(W,R),new w(K,X,W)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}wNAF(x){return J.wNAFCached(this,x,w.normalizeZ)}multiplyUnsafe(x){let{endo:D,n:$}=e;It("scalar",x,An,$);let N=w.ZERO;if(x===An)return N;if(this.is0()||x===dt)return this;if(!D||J.hasPrecomputes(this))return J.wNAFCachedUnsafe(this,x,w.normalizeZ);let{k1neg:U,k1:F,k2neg:Z,k2:K}=D.splitScalar(x),X=N,W=N,ae=this;for(;F>An||K>An;)F&dt&&(X=X.add(ae)),K&dt&&(W=W.add(ae)),ae=ae.double(),F>>=dt,K>>=dt;return U&&(X=X.negate()),Z&&(W=W.negate()),W=new w(t.mul(W.px,D.beta),W.py,W.pz),X.add(W)}multiply(x){let{endo:D,n:$}=e;It("scalar",x,dt,$);let N,U;if(D){let{k1neg:F,k1:Z,k2neg:K,k2:X}=D.splitScalar(x),{p:W,f:ae}=this.wNAF(Z),{p:B,f:R}=this.wNAF(X);W=J.constTimeNegate(F,W),B=J.constTimeNegate(K,B),B=new w(t.mul(B.px,D.beta),B.py,B.pz),N=W.add(B),U=ae.add(R)}else{let{p:F,f:Z}=this.wNAF(x);N=F,U=Z}return w.normalizeZ([N,U])[0]}multiplyAndAddUnsafe(x,D,$){let N=w.BASE,U=(Z,K)=>K===An||K===dt||!Z.equals(N)?Z.multiplyUnsafe(K):Z.multiply(K),F=U(this,D).add(U(x,$));return F.is0()?void 0:F}toAffine(x){return v(this,x)}isTorsionFree(){let{h:x,isTorsionFree:D}=e;if(x===dt)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:x,clearCofactor:D}=e;return x===dt?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return qr("isCompressed",x),this.assertValidity(),o(w,this,x)}toHex(x=!0){return qr("isCompressed",x),ro(this.toRawBytes(x))}}w.BASE=new w(e.Gx,e.Gy,t.ONE),w.ZERO=new w(t.ZERO,t.ONE,t.ZERO);let{endo:_,nBitLength:j}=e,J=rl(w,_?Math.ceil(j/2):j);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:f,weierstrassEquation:s,isWithinCurveOrder:p}}function QS(r){let e=Na(r);return Tr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Y0(r){let e=QS(r),{Fp:t,n,nByteLength:o,nBitLength:i}=e,s=t.BYTES+1,a=2*t.BYTES+1;function c(B){return Pe(B,n)}function l(B){return tl(B,n)}let{ProjectivePoint:p,normPrivateKeyToScalar:f,weierstrassEquation:d,isWithinCurveOrder:v}=JS({...e,toBytes(B,R,H){let k=R.toAffine(),y=t.toBytes(k.x),T=oo;return qr("isCompressed",H),H?T(Uint8Array.from([R.hasEvenY()?2:3]),y):T(Uint8Array.from([4]),y,t.toBytes(k.y))},fromBytes(B){let R=B.length,H=B[0],k=B.subarray(1);if(R===s&&(H===2||H===3)){let y=bn(k);if(!el(y,dt,t.ORDER))throw new Error("Point is not on curve");let T=d(y),L;try{L=t.sqrt(T)}catch(pe){let te=pe instanceof Error?": "+pe.message:"";throw new Error("Point is not on curve"+te)}let I=(L&dt)===dt;return(H&1)===1!==I&&(L=t.neg(L)),{x:y,y:L}}else if(R===a&&H===4){let y=t.fromBytes(k.subarray(0,t.BYTES)),T=t.fromBytes(k.subarray(t.BYTES,2*t.BYTES));return{x:y,y:T}}else{let y=s,T=a;throw new Error("invalid Point, expected length of "+y+", or uncompressed "+T+", got "+R)}}});function g(B){let R=n>>dt;return B>R}function w(B){return g(B)?c(-B):B}let _=(B,R,H)=>bn(B.slice(R,H));class j{constructor(R,H,k){It("r",R,dt,n),It("s",H,dt,n),this.r=R,this.s=H,k!=null&&(this.recovery=k),Object.freeze(this)}static fromCompact(R){let H=o;return R=Me("compactSignature",R,H*2),new j(_(R,0,H),_(R,H,2*H))}static fromDER(R){let{r:H,s:k}=vn.toSig(Me("DER",R));return new j(H,k)}assertValidity(){}addRecoveryBit(R){return new j(this.r,this.s,R)}recoverPublicKey(R){let{r:H,s:k,recovery:y}=this,T=N(Me("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let L=y===2||y===3?H+e.n:H;if(L>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let I=(y&1)===0?"02":"03",oe=p.fromHex(I+od(L,t.BYTES)),pe=l(L),te=c(-T*pe),de=c(k*pe),ye=p.BASE.multiplyAndAddUnsafe(oe,te,de);if(!ye)throw new Error("point at infinify");return ye.assertValidity(),ye}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new j(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return ka(this.toDERHex())}toDERHex(){return vn.hexFromSig(this)}toCompactRawBytes(){return ka(this.toCompactHex())}toCompactHex(){let R=o;return od(this.r,R)+od(this.s,R)}}let J={isValidPrivateKey(B){try{return f(B),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let B=vh(e.n);return d0(e.randomBytes(B),e.n)},precompute(B=8,R=p.BASE){return R._setWindowSize(B),R.multiply(BigInt(3)),R}};function O(B,R=!0){return p.fromPrivateKey(B).toRawBytes(R)}function x(B){if(typeof B=="bigint")return!1;if(B instanceof p)return!0;let H=Me("key",B).length,k=t.BYTES,y=k+1,T=2*k+1;if(!(e.allowedPrivateKeyLengths||o===y))return H===y||H===T}function D(B,R,H=!0){if(x(B)===!0)throw new Error("first arg must be private key");if(x(R)===!1)throw new Error("second arg must be public key");return p.fromHex(R).multiply(f(B)).toRawBytes(H)}let $=e.bits2int||function(B){if(B.length>8192)throw new Error("input is too large");let R=bn(B),H=B.length*8-i;return H>0?R>>BigInt(H):R},N=e.bits2int_modN||function(B){return c($(B))},U=qo(i);function F(B){return It("num < 2^"+i,B,An,U),Wo(B,o)}function Z(B,R,H=K){if(["recovered","canonical"].some(Te=>Te in H))throw new Error("sign() legacy options not supported");let{hash:k,randomBytes:y}=e,{lowS:T,prehash:L,extraEntropy:I}=H;T==null&&(T=!0),B=Me("msgHash",B),X0(H),L&&(B=Me("prehashed msgHash",k(B)));let oe=N(B),pe=f(R),te=[F(pe),F(oe)];if(I!=null&&I!==!1){let Te=I===!0?y(t.BYTES):I;te.push(Me("extraEntropy",Te))}let de=oo(...te),ye=oe;function Ce(Te){let Re=$(Te);if(!v(Re))return;let yt=l(Re),$e=p.BASE.multiply(Re).toAffine(),st=c($e.x);if(st===An)return;let jt=c(yt*c(ye+st*pe));if(jt===An)return;let Rt=($e.x===st?0:2)|Number($e.y&dt),qn=jt;return T&&g(jt)&&(qn=w(jt),Rt^=1),new j(st,qn,Rt)}return{seed:de,k2sig:Ce}}let K={lowS:e.lowS,prehash:!1},X={lowS:e.lowS,prehash:!1};function W(B,R,H=K){let{seed:k,k2sig:y}=Z(B,R,H),T=e;return s0(T.hash.outputLen,T.nByteLength,T.hmac)(k,y)}p.BASE._setWindowSize(8);function ae(B,R,H,k=X){let y=B;R=Me("msgHash",R),H=Me("publicKey",H);let{lowS:T,prehash:L,format:I}=k;if(X0(k),"strict"in k)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 oe=typeof y=="string"||ss(y),pe=!oe&&!I&&typeof y=="object"&&y!==null&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!oe&&!pe)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let te,de;try{if(pe&&(te=new j(y.r,y.s)),oe){try{I!=="compact"&&(te=j.fromDER(y))}catch(Rt){if(!(Rt instanceof vn.Err))throw Rt}!te&&I!=="der"&&(te=j.fromCompact(y))}de=p.fromHex(H)}catch{return!1}if(!te||T&&te.hasHighS())return!1;L&&(R=e.hash(R));let{r:ye,s:Ce}=te,Te=N(R),Re=l(Ce),yt=c(Te*Re),$e=c(ye*Re),st=p.BASE.multiplyAndAddUnsafe(de,yt,$e)?.toAffine();return st?c(st.x)===ye:!1}return{CURVE:e,getPublicKey:O,getSharedSecret:D,sign:W,verify:ae,ProjectivePoint:p,Signature:j,utils:J}}function eE(r){return{hash:r,hmac:(e,...t)=>ds(r,e,uh(...t)),randomBytes:Ta}}function Z0(r,e){let t=n=>Y0({...r,...eE(n)});return{...t(e),create:t}}var ew=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),J0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),tE=BigInt(0),rE=BigInt(1),ad=BigInt(2),Q0=(r,e)=>(r+e/ad)/e;function nE(r){let e=ew,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=We(p,t,e)*p%e,d=We(f,t,e)*p%e,v=We(d,ad,e)*l%e,g=We(v,o,e)*v%e,w=We(g,i,e)*g%e,_=We(w,a,e)*w%e,j=We(_,c,e)*_%e,J=We(j,a,e)*w%e,O=We(J,t,e)*p%e,x=We(O,s,e)*g%e,D=We(x,n,e)*l%e,$=We(D,ad,e);if(!cd.eql(cd.sqr($),r))throw new Error("Cannot find square root");return $}var cd=xn(ew,void 0,void 0,{sqrt:nE}),Nr=Z0({a:tE,b:BigInt(7),Fp:cd,n:J0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=J0,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-rE*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=Q0(i*r,e),c=Q0(-n*r,e),l=Pe(r-a*t-c*o,e),p=Pe(-a*n-c*i,e),f=l>s,d=p>s;if(f&&(l=e-l),d&&(p=e-p),l>s||p>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:p}}}},Qu);function tw(r,e,t){let n=cr.digest(e instanceof Uint8Array?e:e.subarray());if(fs(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Nr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ua(String(o))});try{return Nr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new Ua(String(o))}}function rw(r,e,t,n){let o=cr.digest(t instanceof Uint8Array?t:t.subarray());if(fs(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Nr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new Ma(String(i))});try{return n?.signal?.throwIfAborted(),Nr.verify(e,o.digest,r)}catch(i){throw new Ma(String(i))}}var za=class{type="secp256k1";raw;_key;constructor(e){this._key=iw(e),this.raw=nw(this._key)}toMultihash(){return _r.digest(Zn(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return De.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}verify(e,t,n){return rw(this._key,t,e,n)}},hl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=ow(e),this.publicKey=new za(t??sw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return tw(this.raw,e,t)}};function ud(r){return new za(r)}async function aw(){let r=oE();return new hl(r)}function nw(r){return Nr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ow(r){try{return Nr.getPublicKey(r,!0),r}catch(e){throw new wa(String(e))}}function iw(r){try{return Nr.ProjectivePoint.fromHex(r),r}catch(e){throw new Ji(String(e))}}function sw(r){try{return Nr.getPublicKey(r,!0)}catch(e){throw new wa(String(e))}}function oE(){return Nr.utils.randomPrivateKey()}async function cw(r,e){if(r==="Ed25519")return N0();if(r==="secp256k1")return aw();if(r==="RSA")return nd(iE(e));if(r==="ECDSA")return Kg(sE(e));throw new Gn}function Xa(r,e){let{Type:t,Data:n}=Yr.decode(r),o=n??new Uint8Array;switch(t){case rt.RSA:return ed(o,e);case rt.Ed25519:return Ih(o);case rt.secp256k1:return ud(o);case rt.ECDSA:return ch(o);default:throw new Gn}}function uw(r){let{Type:e,Data:t}=Yr.decode(r.digest),n=t??new Uint8Array;switch(e){case rt.Ed25519:return Ih(n);case rt.secp256k1:return ud(n);case rt.ECDSA:return ch(n);default:throw new Gn}}function Zn(r){return Yr.encode({Type:rt[r.type],Data:r.raw})}function iE(r){return r==null?2048:parseInt(r,10)}function sE(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 Se("Unsupported curve, should be P-256, P-384 or P-521")}async function dl(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new Se("Only RSA and ECDSA keys are supported")}var lw=Symbol.for("nodejs.util.inspect.custom"),aE=114,Ya=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()})`}[Rp]=!0;toString(){return this.string==null&&(this.string=De.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(aE,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ye(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ye(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[lw](){return`PeerId(${this.toString()})`}},Za=class extends Ya{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ja=class extends Ya{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qa=class extends Ya{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},cE=2336,ec=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=_r.digest(me(this.url))}[lw](){return`PeerId(${this.url})`}[Rp]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(cE,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ue(e)),e.toString()===this.toString())}};var uE=114,fw=2336;function ys(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Yn(De.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return lE(tt.parse(r));if(e==null)throw new Se('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Yn(e.decode(r))}return pw(t)}function ld(r){if(r.type==="Ed25519")return new Ja({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Qa({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Za({multihash:r.toCID().multihash,publicKey:r});throw new Gn}function pw(r){if(pE(r))return new Za({multihash:r});if(fE(r))try{let e=uw(r);if(e.type==="Ed25519")return new Ja({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Qa({multihash:r,publicKey:e})}catch{let t=ue(r.digest);return new ec(new URL(t))}throw new Hu("Supplied PeerID Multihash is invalid")}function lE(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==uE&&r.code!==fw)throw new Ku("Supplied PeerID CID is invalid");if(r.code===fw){let e=ue(r.multihash.digest);return new ec(new URL(e))}return pw(r.multihash)}function fE(r){return r.code===_r.code}function pE(r){return r.code===cr.code}var yl=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 d=Number.parseInt(f,e);if(!Number.isNaN(d))return d});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 hw=45,hE=15,ms=new yl;function fd(r){if(!(r.length>hE))return ms.new(r).parseWith(()=>ms.readIPv4Addr())}function pd(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>hw))return ms.new(r).parseWith(()=>ms.readIPv6Addr())}function ml(r,e=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>hw)return;let t=ms.new(r).parseWith(()=>ms.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 C8=parseInt("0xFFFF",16),T8=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function gl(r){return!!fd(r)}function wl(r){return!!pd(r)}function bl(r){return!!ml(r)}var mw=gl,wE=wl,hd=function(r){let e=0;if(r=r.toString().trim(),mw(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(wE(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=mw(t[n]),s;i&&(s=hd(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")},gw=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 gs={},dd={},xE=[[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"]];xE.forEach(r=>{let e=vE(...r);dd[e.code]=e,gs[e.name]=e});function vE(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function Ke(r){if(typeof r=="number"){if(dd[r]!=null)return dd[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(gs[r]!=null)return gs[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var l5=Ke("ip4"),f5=Ke("ip6"),p5=Ke("ipcidr");function wd(r,e){switch(Ke(r).code){case 4:case 41:return _E(e);case 42:return gd(e);case 43:return ue(e,"base10");case 6:case 273:case 33:case 132:return xw(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return gd(e);case 421:return TE(e);case 444:return bw(e);case 445:return bw(e);case 466:return CE(e);case 481:return globalThis.encodeURIComponent(gd(e));default:return ue(e,"base16")}}function bd(r,e){switch(Ke(r).code){case 4:return ww(e);case 41:return ww(e);case 42:return md(e);case 43:return me(e,"base10");case 6:case 273:case 33:case 132:return xd(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return md(e);case 421:return SE(e);case 444:return IE(e);case 445:return OE(e);case 466:return EE(e);case 481:return md(globalThis.decodeURIComponent(e));default:return me(e,"base16")}}var yd=Object.values(Mo).map(r=>r.decoder),AE=function(){let r=yd[0].or(yd[1]);return yd.slice(2).forEach(e=>r=r.or(e)),r}();function ww(r){if(!bl(r))throw new Error("invalid ip address");return hd(r)}function _E(r){let e=gw(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!bl(e))throw new Error("invalid ip address");return e}function xd(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function xw(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function md(r){let e=me(r),t=Uint8Array.from(Xr(e.length));return lt([t,e],t.length+e.length)}function gd(r){let e=Ir(r);if(r=r.slice(qe(e)),r.length!==e)throw new Error("inconsistent lengths");return ue(r)}function SE(r){let e;r[0]==="Q"||r[0]==="1"?e=Yn(De.decode(`z${r}`)).bytes:e=tt.parse(r).multihash.bytes;let t=Uint8Array.from(Xr(e.length));return lt([t,e],t.length+e.length)}function EE(r){let e=AE.decode(r),t=Uint8Array.from(Xr(e.length));return lt([t,e],t.length+e.length)}function CE(r){let e=Ir(r),t=r.slice(qe(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ue(t,"base64url")}function TE(r){let e=Ir(r),t=r.slice(qe(e));if(t.length!==e)throw new Error("inconsistent lengths");return ue(t,"base58btc")}function IE(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=yn.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=xd(n);return lt([t,o],t.length+o.length)}function OE(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=yn.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=xd(n);return lt([t,o],t.length+o.length)}function bw(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ue(e,"base32"),o=xw(t);return`${n}:${o}`}function vw(r){r=vd(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=Ke(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw new xl("invalid address: "+r);if(a.path===!0){n=vd(o.slice(i).join("/")),e.push([a.code,bd(a.code,n)]),t.push([a.code,n]);break}let c=bd(a.code,o[i]);e.push([a.code,c]),t.push([a.code,wd(a.code,c)])}return{string:Aw(t),bytes:vl(e),tuples:e,stringTuples:t,path:n}}function Ad(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=Ir(r,o),s=qe(i),a=Ke(i),c=PE(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 xl("Invalid address Uint8Array: "+ue(r,"base16"));e.push([i,l]);let p=wd(i,l);if(t.push([i,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:Aw(t),tuples:e,stringTuples:t,path:n}}function Aw(r){let e=[];return r.map(t=>{let n=Ke(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),vd(e.join("/"))}function vl(r){return lt(r.map(e=>{let t=Ke(e[0]),n=Uint8Array.from(Xr(t.code));return e.length>1&&e[1]!=null&&(n=lt([n,e[1]])),n}))}function PE(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Ir(e instanceof Uint8Array?e:Uint8Array.from(e));return t+qe(t)}}function vd(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}var xl=class extends Error{static name="ParseError";name="ParseError";constructor(e){super(`Error parsing address: ${e}`)}};var BE=Symbol.for("nodejs.util.inspect.custom"),Sd=Symbol.for("@multiformats/js-multiaddr/multiaddr"),kE=[Ke("dns").code,Ke("dns4").code,Ke("dns6").code,Ke("dnsaddr").code],_d=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Al=class r{bytes;#e;#t;#r;#n;[Sd]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Ad(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vw(e)}else if(Sw(e))t=Ad(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=Ke("tcp"),a=Ke("udp"),c=Ke("ip4"),l=Ke("ip6"),p=Ke("dns6"),f=Ke("ip6zone");for(let[v,g]of this.stringTuples())v===f.code&&(i=`%${g??""}`),kE.includes(v)&&(t=s.name==="tcp"?"tcp":"udp",o=443,n=`${g??""}${i}`,e=v===p.code?6:4),(v===s.code||v===a.code)&&(t=Ke(v).name==="tcp"?"tcp":"udp",o=parseInt(g??"")),(v===c.code||v===l.code)&&(t=Ke(v).name==="tcp"?"tcp":"udp",n=`${g??""}${i}`,e=v===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({},Ke(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Ke(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(vl(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===gs.p2p.code&&e.push([n,o]),n===gs["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ue(De.decode(`z${n}`),"base58btc"):ue(tt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Ye(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=_w.get(t.name);if(n==null)throw new _d(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>Zr(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)}[BE](){return`Multiaddr(${this.#e})`}};var _w=new Map;function Sw(r){return!!r?.[Sd]}function Zr(r){return new Al(r)}var NE=r=>r.toString().split("/").slice(1),ws=r=>({match:e=>e.length<1?!1:r(e[0])?e.slice(1):!1,pattern:"fn"}),we=r=>({match:e=>ws(t=>t===r).match(e),pattern:r}),Zo=()=>({match:r=>ws(e=>typeof e=="string").match(r),pattern:"{string}"}),bs=()=>({match:r=>ws(e=>!isNaN(parseInt(e))).match(r),pattern:"{number}"}),je=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{De.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),tc=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Uo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),Be=r=>({match:e=>{let t=r.match(e);return t===!1?e:t},pattern:`optional(${r.pattern})`}),Bt=(...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(", ")})`}),_e=(...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 He(...r){function e(o){let i=NE(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 jE=je(),$5=He(jE),Sl=_e(we("dns4"),Zo()),El=_e(we("dns6"),Zo()),Cl=_e(we("dnsaddr"),Zo()),Cd=_e(we("dns"),Zo()),F5=He(Sl,Be(je())),W5=He(El,Be(je())),q5=He(Cl,Be(je())),G5=He(Bt(Cd,Cl,Sl,El),Be(je())),Ew=_e(we("ip4"),ws(gl)),Cw=_e(we("ip6"),ws(wl)),Td=Bt(Ew,Cw),_n=Bt(Td,Cd,Sl,El,Cl),z5=He(Bt(Td,_e(Bt(Cd,Cl,Sl,El),Be(je())))),X5=He(Ew),Y5=He(Cw),Z5=He(Td),Id=_e(_n,we("tcp"),bs()),rc=_e(_n,we("udp"),bs()),J5=He(_e(Id,Be(je()))),Q5=He(rc),Od=_e(rc,we("quic"),Be(je())),Tl=_e(rc,we("quic-v1"),Be(je())),RE=Bt(Od,Tl),e4=He(Od),t4=He(Tl),Ed=Bt(_n,Id,rc,Od,Tl),Tw=Bt(_e(Ed,we("ws"),Be(je()))),r4=He(Tw),Iw=Bt(_e(Ed,we("wss"),Be(je())),_e(Ed,we("tls"),Be(_e(we("sni"),Zo())),we("ws"),Be(je()))),n4=He(Iw),Ow=_e(rc,we("webrtc-direct"),Be(tc()),Be(tc()),Be(je())),Pw=He(Ow),Bw=_e(Tl,we("webtransport"),Be(tc()),Be(tc()),Be(je())),o4=He(Bw),_l=Bt(Tw,Iw,_e(Id,Be(je())),_e(RE,Be(je())),_e(_n,Be(je())),Ow,Bw,je()),kw=He(_l),DE=_e(_l,we("p2p-circuit"),je()),i4=He(DE),LE=Bt(_e(_l,we("p2p-circuit"),we("webrtc"),Be(je())),_e(_l,we("webrtc"),Be(je())),_e(we("webrtc"),Be(je()))),Nw=He(LE),UE=Bt(_e(_n,we("tcp"),bs(),we("http"),Be(je())),_e(_n,we("http"),Be(je()))),s4=He(UE),ME=Bt(_e(_n,we("tcp"),Bt(_e(we("443"),we("http")),_e(bs(),we("https")),_e(bs(),we("tls"),we("http"))),Be(je())),_e(_n,we("tls"),we("http"),Be(je())),_e(_n,we("https"),Be(je()))),a4=He(ME),KE=Bt(_e(we("memory"),Zo(),Be(je()))),c4=He(KE);var kt;(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=()=>Yo(t)}(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=kr((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=>Br(o,r.codec()),r.decode=(o,i)=>Pr(o,r.codec(),i)})(kt||(kt={}));var jw=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Pd=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),Rw="libp2p+webrtc+v1/";var Dw=466,Lw=2*1024*1024,Uw=30*1e3,xs=16*1024;function HE(r=xs){let e=qe(r-qe(r)),t=1+qe(Object.keys(kt.Flag).length-1),n=1,o=r-e-t-n,i=qe(o);return e+t+n+i}var Mw=HE(),Kw=5e3,Hw=5e3,Vw=3e4,Bd="/webrtc",nc="/webrtc-signaling/0.0.1",$w="/libp2p/webrtc-direct/certificate",Fw="webrtc-direct-certificate-private-key";var Ww=12096e5,kd=864e5;var qw=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))},VE=function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r}();var $E=function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r}();var FE=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 WE=function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r}();var qE=function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r}();var GE=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,zE=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Gw=3,XE=[["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",GE]],zw=[["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 Yw(r){return r?Xw(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new qE:typeof navigator<"u"?Xw(navigator.userAgent):JE()}function YE(r){return r!==""&&XE.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 Xw(r){var e=YE(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new WE;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<Gw&&(o=qw(qw([],o,!0),QE(Gw-o.length),!0)):o=[];var i=o.join("."),s=ZE(r),a=zE.exec(r);return a&&a[1]?new FE(t,i,s,a[1]):new VE(t,i,s)}function ZE(r){for(var e=0,t=zw.length;e<t;e++){var n=zw[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function JE(){var r=typeof process<"u"&&process.version;return r?new $E(process.version.slice(1)):null}function QE(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}function nt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Nd=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},jd=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Zw=r=>globalThis.DOMException===void 0?new jd(r):new DOMException(r),Jw=r=>{let e=r.reason===void 0?Zw("This operation was aborted."):r.reason;return e instanceof Error?e:Zw(e)};function oc(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:v}=e;v.aborted&&f(Jw(v)),a=()=>{f(Jw(v))},v.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,f);return}let d=new Nd;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(v){f(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${t} milliseconds`,f(d))},t),(async()=>{try{p(await r)}catch(v){f(v)}})()}).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 Qw=Yw(),ic=Qw!=null&&Qw.name==="firefox",Il=async function*(){},Ol=async r=>{};function eb(r,e,t=Vw,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=nt(),i=!1;r.bufferedAmountLowThreshold=0;let s=()=>{i||(n.log("%s drain channel closed before drain",e),o.resolve())};r.addEventListener("close",s,{once:!0}),r.addEventListener("bufferedamountlow",()=>{i=!0,r.removeEventListener("close",s),o.resolve()}),await oc(o.promise,{milliseconds:t})}}).then(async()=>{r.readyState==="open"&&r.close()}).catch(o=>{n.log.error("error closing outbound stream",o)})}async function Rd(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??jw.map(e=>({urls:[e]})),r}var tb=(r=32)=>Rw+[...Array(r)].map(()=>Pd.at(Math.floor(Math.random()*Pd.length))).join("");var Jo=class{log;peerConnection;remoteAddr;timeline;metrics;source=Il();sink=Ol;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 Pl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},vs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Pl(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 Pl(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 Dd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function As(r={}){return e2(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function e2(r,e){e=e??{};let t=e.onEnd,n=new vs,o,i,s,a=nt(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((_,j)=>{i=J=>{i=null,n.push(J);try{_(r(n))}catch(O){j(O)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=nt()})}},l=_=>i!=null?i(_):(n.push(_),o),p=_=>(n=new vs,i!=null?i({error:_}):(n.push({error:_}),o)),f=_=>{if(s)return o;if(e?.objectMode!==!0&&_?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:_})},d=_=>s?o:(s=!0,_!=null?p(_):l({done:!0})),v=()=>(n=new vs,d(),{done:!0}),g=_=>(d(_),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:v,throw:g,push:f,end:d,get readableLength(){return n.size},onEmpty:async _=>{let j=_?.signal;if(j?.throwIfAborted(),n.isEmpty())return;let J,O;j!=null&&(J=new Promise((x,D)=>{O=()=>{D(new Dd)},j.addEventListener("abort",O)}));try{await Promise.race([a.promise,J])}finally{O!=null&&j!=null&&j?.removeEventListener("abort",O)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(_){return w.throw(_),t!=null&&(t(_),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(_){return w.end(_),t!=null&&(t(_),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:_=>w.onEmpty(_)},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 ur(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 rb(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 nb(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ob(r,e){let t=rb(r).return?.();nb(t)&&t.catch(n=>{e.error("could not cause iterator to return",n)})}var t2=5e3;function Ld(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var kl=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=nt(),this.closed=nt(),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??t2,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=As({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 Ro(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus="writing";let t={signal:this.sinkController.signal};if(this.direction==="outbound"){let o=this.sendNewStream(t);Ld(o)&&await o}let n=()=>{ob(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 Ae(o):o;let i=this.sendData(o,t);Ld(i)&&(this.sendingData=nt(),await i,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener("abort",n)}this.log.trace('sink finished reading from source, write status is "%s"',this.writeStatus),this.writeStatus==="writing"&&(this.writeStatus="closing",this.log.trace("send close write to remote"),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus="closed"),this.onSinkEnd()}catch(t){throw this.log.trace("sink ended with error, calling abort with error",t),this.abort(t),t}finally{this.log.trace("resolve sink end"),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead==null&&(this.timeline.closeRead=Date.now(),this.readStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite!=null?(this.log.trace("source and sink ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("source ended, waiting for sink to end"))}onSinkEnd(e){this.timeline.closeWrite==null&&(this.timeline.closeWrite=Date.now(),this.writeStatus="closed",e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead!=null?(this.log.trace("sink and source ended"),this.timeline.close=Date.now(),this.status!=="aborted"&&this.status!=="reset"&&(this.status="closed"),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()):this.log.trace("sink ended, waiting for source to end"))}async close(e){this.status==="open"&&(this.log.trace("closing gracefully"),this.status="closing",await ur(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status="closed",this.log.trace("closed gracefully"))}async closeRead(e={}){if(this.readStatus==="closing"||this.readStatus==="closed")return;this.log.trace('closing readable end of stream with starting read status "%s"',this.readStatus);let t=this.readStatus;this.readStatus="closing",this.status!=="reset"&&this.status!=="aborted"&&this.timeline.closeRead==null&&(this.log.trace("send close read to remote"),await this.sendCloseRead(e)),t==="ready"&&(this.log.trace("ending internal source queue with %d queued bytes",this.streamSource.readableLength),this.streamSource.end()),this.log.trace("closed readable end of stream")}async closeWrite(e={}){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.log.trace('closing writable end of stream with starting write status "%s"',this.writeStatus),this.writeStatus==="ready"&&(this.log.trace("sink was never sunk, sink an empty array"),await ur(this.sink([]),e.signal)),this.writeStatus==="writing"&&(this.sendingData!=null&&await ur(this.sendingData.promise,e.signal),this.log.trace("aborting source passed to .sink"),this.sinkController.abort(),await ur(this.sinkEnd.promise,e.signal)),this.writeStatus="closed",this.log.trace("closed writable end of stream"))}abort(e){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;this.log("abort with error",e),this.log("try to send reset to remote");let t=this.sendReset();Ld(t)&&t.catch(n=>{this.log.error("error sending reset message",n)}),this.status="aborted",this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset")return;let e=new Mu("stream reset");this.status="reset",this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus==="writing"&&(this.log.trace("end sink source"),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!=="closing"&&this.readStatus!=="closed"&&(this.log.trace("ending source with %d bytes to be read by consumer",this.streamSource.readableLength),this.readStatus="closing",this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("received remote close write but local source is already closed");return}this.log.trace("remote close write"),this._closeSource()}remoteCloseRead(){if(this.writeStatus==="closing"||this.writeStatus==="closed"){this.log("received remote close read but local sink is already closed");return}this.log.trace("remote close read"),this._closeSink()}destroy(){if(this.status==="closed"||this.status==="aborted"||this.status==="reset"){this.log("received destroy but we are already closed");return}this.log.trace("stream destroyed"),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Ud(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}var Nl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},_s=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},jl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},sc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Rl(r){return r[Symbol.asyncIterator]!=null}function ib(r,e){if(r.byteLength>e)throw new _s("Message length too long")}var Ll=r=>{let e=qe(r),t=ut(e);return Xr(r,t),Ll.bytes=e,t};Ll.bytes=0;function ac(r,e){e=e??{};let t=e.lengthEncoder??Ll,n=e?.maxDataLength??4194304;function*o(i){ib(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Rl(r)?async function*(){for await(let i of r)yield*o(i)}():function*(){for(let i of r)yield*o(i)}()}ac.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??Ll,n=e?.maxDataLength??4194304;return ib(r,n),new Ae(t(r.byteLength),r)};var Qo;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Qo||(Qo={}));var Md=r=>{let e=Ir(r);return Md.bytes=qe(e),e};Md.bytes=0;function ei(r,e){let t=new Ae,n=Qo.LENGTH,o=-1,i=e?.lengthDecoder??Md,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===Qo.LENGTH)try{if(o=i(t),o<0)throw new Nl("Invalid message length");if(o>a)throw new _s("Message length too long");let l=i.bytes;t.consume(l),e?.onLength!=null&&e.onLength(o),n=Qo.DATA}catch(l){if(l instanceof RangeError){if(t.byteLength>s)throw new jl("Message length length too long");break}throw l}if(n===Qo.DATA){if(t.byteLength<o)break;let l=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(l),yield l,n=Qo.LENGTH}}}return Rl(r)?async function*(){for await(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new sc("Unexpected end of input")}():function*(){for(let l of r)t.append(l),yield*c();if(t.byteLength>0)throw new sc("Unexpected end of input")}()}ei.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 ei(n,{...e??{},onLength:i=>{t=i}})};var Kd=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function cc(r,e,t,n){let o=new Kd(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((i,s)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,c),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,l)}let c=f=>{try{if(n?.filter?.(f)===!1)return}catch(d){a(),s(d);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 Hd=class extends kl{channel;incomingData;maxBufferedAmount;bufferedAmountLowEventTimeout;maxMessageSize;receiveFinAck;finAckTimeout;openTimeout;closeController;constructor(e){let t=e.onEnd;switch(e.onEnd=o=>{this.log.trace('readable and writeable ends closed with status "%s"',this.status),Promise.resolve(async()=>{if(!(this.timeline.abort!=null||this.timeline.reset!==null))try{await oc(this.receiveFinAck.promise,{milliseconds:this.finAckTimeout})}catch(i){this.log.error("error receiving FIN_ACK",i)}}).then(()=>{this.incomingData.end(),t?.(o)}).catch(i=>{this.log.error("error ending stream",i)}).finally(()=>{this.channel.close()})},super(e),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=As(),this.bufferedAmountLowEventTimeout=e.bufferedAmountLowEventTimeout??Uw,this.maxBufferedAmount=e.maxBufferedAmount??Lw,this.maxMessageSize=(e.maxMessageSize??xs)-Mw,this.receiveFinAck=nt(),this.finAckTimeout=e.closeTimeout??Kw,this.openTimeout=e.openTimeout??Hw,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 Ro("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 ei(this.incomingData)){let i=n.processIncomingProtobuf(o);i!=null&&n.sourcePush(new Ae(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 Ro(`Invalid datachannel state - ${this.channel.readyState}`);if(this.channel.readyState!=="open"){let n=AbortSignal.timeout(this.openTimeout),o=Ud([this.closeController.signal,n]);try{this.log('channel state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),await cc(this.channel,"open",o)}finally{o.clear()}this.log('channel state is now "%s", sending data',this.channel.readyState)}if(t&&this.channel.bufferedAmount>this.maxBufferedAmount){let n=AbortSignal.timeout(this.bufferedAmountLowEventTimeout),o=Ud([this.closeController.signal,n]);try{this.log('channel buffer is %d, wait for "bufferedamountlow" event',this.channel.bufferedAmount),await cc(this.channel,"bufferedamountlow",o)}catch(i){throw n.aborted?new $u(`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=kt.encode({message:o}),s=ac.single(i);this.log.trace("sending %d/%d bytes on channel",o.byteLength,t),await this._sendMessage(s),e.consume(n)}this.log.trace('finished sending data, channel state "%s"',this.channel.readyState)}async sendReset(){try{await this._sendFlag(kt.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(kt.Flag.FIN)){this.log.trace("awaiting FIN_ACK");try{await ur(this.receiveFinAck.promise,e?.signal,{errorMessage:"sending close-write was aborted before FIN_ACK was received",errorName:"FinAckNotReceivedError"})}catch(n){this.log.error("failed to await FIN_ACK",n)}}else this.log.trace("sending FIN failed, not awaiting FIN_ACK");this.receiveFinAck.resolve()}async sendCloseRead(){this.channel.readyState==="open"&&await this._sendFlag(kt.Flag.STOP_SENDING)}processIncomingProtobuf(e){let t=kt.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===kt.Flag.FIN&&(this.remoteCloseWrite(),this.log.trace("sending FIN_ACK"),this._sendFlag(kt.Flag.FIN_ACK).catch(n=>{this.log.error("error sending FIN_ACK immediately",n)})),t.flag===kt.Flag.RESET&&this.reset(),t.flag===kt.Flag.STOP_SENDING&&this.remoteCloseRead(),t.flag===kt.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=kt.encode({flag:e}),n=ac.single(t);try{return await this._sendMessage(n,!1),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}};function Ss(r){let{channel:e,direction:t,handshake:n}=r;return new Hd({id:`${e.id}`,log:r.logger.forComponent(`libp2p:webrtc:stream:${n===!0?"handshake":t}:${e.id}`),...r})}var ao=class{protocol;peerConnection;bufferedStreams=[];metrics;dataChannelOptions;components;log;constructor(e,t){this.components=e,this.peerConnection=t.peerConnection,this.metrics=t.metrics,this.protocol=t.protocol??Bd,this.dataChannelOptions=t.dataChannelOptions??{},this.log=e.logger.forComponent("libp2p:webrtc:muxerfactory"),this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace('incoming early datachannel with channel id %d and label "%s"',n.id),n.label==="init"){this.log.trace("closing early init channel"),n.close();return}let o={},i=Ss({channel:n,direction:"inbound",onEnd:s=>{o.onEnd(s)},logger:e.logger,...this.dataChannelOptions});o.stream=i,o.channel=n,o.onEnd=()=>{this.bufferedStreams=this.bufferedStreams.filter(s=>s.stream.id!==i.id)},this.bufferedStreams.push(o)}}createStreamMuxer(e){return new Vd(this.components,{...e,peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,streams:this.bufferedStreams,protocol:this.protocol})}},Vd=class{init;streams;protocol;log;peerConnection;dataChannelOptions;metrics;logger;constructor(e,t){this.init=t,this.log=e.logger.forComponent("libp2p:webrtc:muxer"),this.logger=e.logger,this.streams=t.streams.map(n=>n.stream),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Bd,this.metrics=t.metrics,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming datachannel with channel id %d",n.id),n.label==="init"){this.log.trace("closing init channel"),n.close();return}let o=n.id,i=Ss({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),eb(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=Il();sink=Ol;newStream(){let e=this.peerConnection.createDataChannel(""),t=e.id;this.log.trace("opened outgoing datachannel with channel id %s",t);let n=Ss({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 Ul=globalThis.RTCPeerConnection,Ml=globalThis.RTCSessionDescription,sb=globalThis.RTCIceCandidate;var $d=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=nt(),this.haveNext=nt()}[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=nt(),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=nt(),await ur(this.readNext.promise,t?.signal,t)}};function Kl(){return new $d}var Hl=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function ab(r,e){let t=Kl();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 Ae;return{read:async s=>{if(s?.signal?.throwIfAborted(),s?.bytes==null){let{done:c,value:l}=await ur(n.next(),s?.signal);return c===!0?null:l}for(;o.byteLength<s.bytes;){let{value:c,done:l}=await ur(n.next(),s?.signal);if(l===!0)throw new Hl("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 Vl=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$l=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Fl=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function uc(r,e={}){let t=ab(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=qe(e.maxDataLength));let n=e?.lengthDecoder??Ir,o=e?.lengthEncoder??Xr;return{read:async s=>{let a=-1,c=new Ae;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 Vl("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Fl("message length length too long");if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new $l("message length too long");return t.read({...s,bytes:a})},write:async(s,a)=>{await t.write(new Ae(o(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new Ae(...s.flatMap(l=>[o(l.byteLength),l]));await t.write(c,a)},unwrap:()=>t.unwrap()}}function Wl(r,e){let t=uc(r,e),n={read:async(o,i)=>{let s=await t.read(i);return o.decode(s)},write:async(o,i,s)=>{await t.write(i.encode(o),s)},writeV:async(o,i,s)=>{await t.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>t.unwrap()};return n}var nr=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var co=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},lr=class extends co{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var ql=class extends co{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Gl=class extends co{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},zl=class extends co{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 $t;(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=()=>Yo(t)}(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=kr((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=>Br(o,r.codec()),r.decode=(o,i)=>Pr(o,r.codec(),i)})($t||($t={}));var Xl=async(r,e,t)=>{try{let n=nt();for(o2(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!==$t.Type.ICE_CANDIDATE)throw new Vu("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new nr("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new sb(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new nr("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&&Yl(r)!=="connected")throw n}};function Yl(r){return ic?r.iceConnectionState:r.connectionState}function o2(r,e){r[ic?"oniceconnectionstatechange":"onconnectionstatechange"]=t=>{switch(Yl(r)){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new Uu("RTCPeerConnection was closed"));break;default:break}}}async function cb({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:l}){let{baseAddr:p}=ub(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing base address: %a",p);let f=p.getPeerId();if(f==null)throw new Se("Relay peer was missing");let d=i.getConnections(ys(f)),v,g=!1;d.length===0?(l?.(new nr("webrtc:dial-relay")),v=await s.dial(p,{signal:t,onProgress:l}),g=!0):(l?.(new nr("webrtc:reuse-relay-connection")),v=d[0]);try{l?.(new nr("webrtc:open-signaling-stream"));let w=await v.newStream(nc,{signal:t,runOnLimitedConnection:!0}),_=Wl(w).pb($t),j=new Ul(r),J=new ao({logger:c},{peerConnection:j,dataChannelOptions:e});try{let O=j.createDataChannel("init");j.onicecandidate=({candidate:N})=>{let U=JSON.stringify(N?.toJSON()??null);a.trace("initiator sending ICE candidate %o",N),_.write({type:$t.Type.ICE_CANDIDATE,data:U},{signal:t}).catch(F=>{a.error("error sending ICE candidate",F)})},j.onicecandidateerror=N=>{a.error("initiator ICE candidate error",N)};let x=await j.createOffer().catch(N=>{throw a.error("could not execute createOffer",N),new lr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",x.sdp),l?.(new nr("webrtc:send-sdp-offer")),await _.write({type:$t.Type.SDP_OFFER,data:x.sdp},{signal:t}),await j.setLocalDescription(x).catch(N=>{throw a.error("could not execute setLocalDescription",N),new lr("Failed to set localDescription")}),l?.(new nr("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let D=await _.read({signal:t});if(D.type!==$t.Type.SDP_ANSWER)throw new lr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",D.data);let $=new Ml({type:"answer",sdp:D.data});return await j.setRemoteDescription($).catch(N=>{throw a.error("could not execute setRemoteDescription",N),new lr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),l?.(new nr("webrtc:read-ice-candidates")),await Xl(j,_,{direction:"initiator",signal:t,log:a,onProgress:l}),a.trace("initiator connected, closing init channel"),O.close(),l?.(new nr("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:j,muxerFactory:J}}catch(O){throw a.error("outgoing signaling error",O),j.close(),w.abort(O),O}finally{j.onicecandidate=null,j.onicecandidateerror=null}}finally{if(g)try{await v.close({signal:t})}catch(w){v.abort(w)}}}var lb=He(kw.matchers[0],we("p2p-circuit")),Zl=class r extends zn{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=>lb.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=>lb.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 fb({peerConnection:r,stream:e,signal:t,connection:n,log:o}){o.trace("new inbound signaling stream");let i=Wl(e).pb($t);try{r.onicecandidate=({candidate:p})=>{let f=JSON.stringify(p?.toJSON()??null);o.trace("recipient sending ICE candidate %s",f),i.write({type:$t.Type.ICE_CANDIDATE,data:f},{signal:t}).catch(d=>{o.error("error sending ICE candidate",d)})},o.trace("recipient read SDP offer");let a=await i.read({signal:t});if(a.type!==$t.Type.SDP_OFFER)throw new lr(`expected message type SDP_OFFER, received: ${a.type??"undefined"} `);o.trace("recipient received SDP offer %s",a.data);let c=new Ml({type:"offer",sdp:a.data});await r.setRemoteDescription(c).catch(p=>{throw o.error("could not execute setRemoteDescription",p),new lr("Failed to set remoteDescription")});let l=await r.createAnswer().catch(p=>{throw o.error("could not execute createAnswer",p),new lr("Failed to create answer")});o.trace("recipient send SDP answer %s",l.sdp),await i.write({type:$t.Type.SDP_ANSWER,data:l.sdp},{signal:t}),await r.setLocalDescription(l).catch(p=>{throw o.error("could not execute setLocalDescription",p),new lr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Xl(r,i,{direction:"recipient",signal:t,log:o})}catch(a){if(Yl(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=Zr(`/webrtc/p2p/${n.remoteAddr.getPeerId()}`);return o.trace("recipient connected to remote address %s",s),{remoteAddress:s}}var Jl=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"})})}[Ru]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[Qi]=["@libp2p/transport"];[ug]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(nc,e=>{let t=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t).catch(n=>{this.log.error("failed to handle incoming connect from %p",e.connection.remotePeer,n)}).finally(()=>{t.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(nc),this._started=!1}createListener(e){return new Zl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(Nw.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 cb({rtcConfiguration:await Rd(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 Jo(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 Ul(await Rd(this.init.rtcConfiguration)),i=new ao(this.components,{peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s}=await fb({peerConnection:o,connection:e,stream:t,signal:n,log:this.log});await t.close({signal:n});let a=new Jo(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 ub(r){let e=r.toString().split("/webrtc/");if(e.length!==2)throw new Se("webrtc protocol was not present in multiaddr");if(!e[0].includes("/p2p-circuit"))throw new Se("p2p-circuit protocol was not present in multiaddr");let t=Zr(e[0]),o=Zr("/"+e[1]).getPeerId();if(o==null)throw new Se("destination peer id was missing");let i=t.protos().pop();if(i===void 0)throw new Se("invalid multiaddr");return i.name!=="p2p"&&(t=t.encapsulate(`/p2p/${o}`)),{baseAddr:t,peerId:ys(o)}}var NG=Fr(hb());var tn={};Ct(tn,{Any:()=>Qr,BaseBlock:()=>ot,BaseStringBlock:()=>hc,BitString:()=>Dr,BmpString:()=>ii,Boolean:()=>ri,CharacterString:()=>di,Choice:()=>Ts,Constructed:()=>ft,DATE:()=>bc,DateTime:()=>vc,Duration:()=>Ac,EndOfContent:()=>dc,Enumerated:()=>ni,GeneralString:()=>hi,GeneralizedTime:()=>yi,GraphicString:()=>pi,HexBlock:()=>en,IA5String:()=>fi,Integer:()=>In,Null:()=>jr,NumericString:()=>ai,ObjectIdentifier:()=>oi,OctetString:()=>Rr,Primitive:()=>Tn,PrintableString:()=>ci,RawData:()=>Gd,RelativeObjectIdentifier:()=>wc,Repeated:()=>mi,Sequence:()=>qt,Set:()=>Gt,TIME:()=>_c,TeletexString:()=>ui,TimeOfDay:()=>xc,UTCTime:()=>po,UniversalString:()=>si,Utf8String:()=>pr,ValueBlock:()=>gt,VideotexString:()=>li,ViewWriter:()=>Cs,VisibleString:()=>fo,compareSchema:()=>lo,fromBER:()=>Pn,verifySchema:()=>E2});var ge=Fr(En());function ti(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 uo(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 tf(...r){let e=0,t=0;for(let i of r)e+=i.length;let n=new ArrayBuffer(e),o=new Uint8Array(n);for(let i of r)o.set(i,t),t+=i.length;return o}function Wd(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=ti(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,ti(i,8)-n}function db(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=uo(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=uo(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 yb(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 Ft(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 R3=Math.log(2);function rf(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function zd(r){let e=0,t=0;for(let o=0;o<r.length;o++){let i=r[o];e+=i.byteLength}let n=new Uint8Array(e);for(let o=0;o<r.length;o++){let i=r[o];n.set(new Uint8Array(i),t),t+=i.byteLength}return n.buffer}function On(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Cs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return zd(this.items)}},lc=[new Uint8Array([1])],mb="0123456789",qd="name",gb="valueHexView",h2="isHexOnly",d2="idBlock",y2="tagClass",m2="tagNumber",g2="isConstructed",w2="fromBER",b2="toBER",x2="local",Wt="",Lr=new ArrayBuffer(0),wf=new Uint8Array(0),pc="EndOfContent",bb="OCTET STRING",xb="BIT STRING";function en(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}constructor(...n){var o;super(...n);let i=n[0]||{};this.isHexOnly=(o=i.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=i.valueHex?ge.BufferSourceConverter.toUint8Array(i.valueHex):wf}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!On(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",Lr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ge.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Cn=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=Wt,warnings:n=[],valueBeforeDecode:o=wf}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=ge.BufferSourceConverter.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ge.Convert.ToHex(this.valueBeforeDecodeView)}}};Cn.NAME="baseBlock";var gt=class extends Cn{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'")}};gt.NAME="valueBlock";var nf=class extends en(Cn){constructor({idBlock:e={}}={}){var t,n,o,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?ge.BufferSourceConverter.toUint8Array(e.valueHex):wf,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",Lr}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=uo(this.tagNumber,7),i=new Uint8Array(o),s=o.byteLength,a=new Uint8Array(s+1);if(a[0]=t|31,!e){for(let c=0;c<s-1;c++)a[c+1]=i[c]|128;a[s]=i[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let o=this.valueHexView;for(let i=0;i<o.length-1;i++)n[i+1]=o[i]|128;n[this.valueHexView.byteLength]=o[o.length-1]}return n.buffer}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!On(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 d=new Uint8Array(p);for(let v=0;v<l.length;v++)d[v]=l[v];l=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,l[c-1]=i[c]&127;let f=new Uint8Array(c);for(let d=0;d<c;d++)f[d]=l[d];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=ti(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}}};nf.NAME="identificationBlock";var of=class extends Cn{constructor({lenBlock:e={}}={}){var t,n,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!On(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=ti(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=uo(this.length,8);if(o.byteLength>127)return this.error="Too big length",Lr;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}}};of.NAME="lengthBlock";var Q={},ot=class extends Cn{constructor({name:e=Wt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new nf(o),this.lenBlock=new of(o),this.valueBlock=i?new i(o):new gt(o)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}toBER(e,t){let n=t||new Cs;t||vb(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?Lr:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():ge.Convert.ToHex(this.toBER())}onAsciiEncoding(){let e=this.constructor.NAME,t=ge.Convert.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return yb(t,n)}};ot.NAME="BaseBlock";function vb(r){var e;if(r instanceof Q.Constructed)for(let t of r.valueBlock.value)vb(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var hc=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Wt,...t}={},n){super(t,n),e&&this.fromString(e)}fromBER(e,t,n){let o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};hc.NAME="BaseStringBlock";var sf=class extends en(gt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};sf.NAME="PrimitiveValueBlock";var Ab,Tn=class extends ot{constructor(e={}){super(e,sf),this.idBlock.isConstructed=!1}};Ab=Tn;Q.Primitive=Ab;Tn.NAME="PRIMITIVE";function v2(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function Is(r,e=0,t=r.length){let n=e,o=new ot({},gt),i=new Cn;if(!On(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=ot;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=v2(o,c),a=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(n,n+o.blockLength),{offset:a,result:o}}function Pn(r){if(!r.byteLength){let e=new ot({},gt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Is(ge.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function A2(r,e){return r?1:e}var Jr=class extends gt{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);if(!On(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(;A2(this.isIndefiniteForm,n)>0;){let s=Is(o,i,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(i=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===pc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===pc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Cs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Lr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Jr.NAME="ConstructedValueBlock";var _b,ft=class extends ot{constructor(e={}){super(e,Jr),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} :`}};vb=ft;Q.Constructed=vb;ft.NAME="CONSTRUCTED";var of=class extends gt{fromBER(e,t,n){return t}toBER(e){return Dr}};of.override="EndOfContentValueBlock";var Ab,fc=class extends ot{constructor(e={}){super(e,of),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ab=fc;Q.EndOfContent=Ab;fc.NAME=uc;var _b,Nr=class extends ot{constructor(e={}){super(e,gt),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}`}};_b=Nr;Q.Null=_b;Nr.NAME="NULL";var sf=class extends Qr(gt){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=ge.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);return In(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Fd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};sf.NAME="BooleanValueBlock";var Sb,ri=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,sf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Sb=ri;Q.Boolean=Sb;ri.NAME="BOOLEAN";var af=class extends Qr(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===uc){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}}};af.NAME="OctetStringValueBlock";var zd,jr=class extends ot{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},af),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=Cs(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 ft.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ge.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof zd&&e.push(t.valueBlock.valueHexView);return ge.BufferSourceConverter.concat(e)}};zd=jr;Q.OctetString=zd;jr.NAME=gb;var cf=class extends Qr(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===uc){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=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Cs(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 Dr;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};cf.NAME="BitStringValueBlock";var Eb,Rr=class extends ot{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},cf),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 ft.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=Rr;Q.BitString=Eb;Rr.NAME=wb;var Cb;function g2(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 d=p;d>=0;d--,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=Ql(new Uint8Array([l%10]),i);break;default:i[s-f]=l%10}}return t[0]>0&&(i=Ql(t,i)),i}function mb(r){if(r>=ac.length)for(let e=ac.length;e<=r;e++){let t=new Uint8Array([0]),n=ac[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=Ql(t,n)),ac.push(n)}return ac[r]}function w2(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 pc=class extends Qr(gt){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=Fd.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=w2(mb(n),t),s="-";break;default:t=g2(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}};Cb=pc;pc.NAME="IntegerValueBlock";Object.defineProperty(Cb.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var cc,Tn=class extends ot{constructor(e={}){super(e,pc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return ef(),BigInt(this.valueBlock.toString())}static fromBigInt(e){ef();let t=BigInt(e),n=new Ss,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ge.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${ge.Convert.ToHex(a)}`)+t,p=ge.BufferSourceConverter.toUint8Array(ge.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 cc({valueHex:n.final()})}convertToDER(){let e=new cc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new cc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};cc=Tn;Q.Integer=cc;Tn.NAME="INTEGER";var Tb,ni=class extends Tn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Tb=ni;Q.Enumerated=Tb;ni.NAME="ENUMERATED";var hc=class extends Qr(gt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ti(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){ef();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=uo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Dr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=ge.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};hc.NAME="sidBlock";var uf=class extends gt{constructor({value:e=Ft,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new hc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,Dr;t.push(o)}return Gd(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 hc;if(o>Number.MAX_SAFE_INTEGER){ef();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};uf.NAME="ObjectIdentifierValueBlock";var Ib,oi=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,uf),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=oi;Q.ObjectIdentifier=Ib;oi.NAME="OBJECT IDENTIFIER";var dc=class extends Qr(En){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ge.BufferSourceConverter.toUint8Array(e);if(!In(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,(i[a]&128)!==0);a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=ti(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=uo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Dr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ge.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};dc.NAME="relativeSidBlock";var lf=class extends gt{constructor({value:e=Ft,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new dc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,Dr;n.push(i)}return Gd(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 dc;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}};lf.NAME="RelativeObjectIdentifierValueBlock";var Ob,yc=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,lf),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=yc;Q.RelativeObjectIdentifier=Ob;yc.NAME="RelativeObjectIdentifier";var Pb,Wt=class extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Pb=Wt;Q.Sequence=Pb;Wt.NAME="SEQUENCE";var Bb,qt=class extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Bb=qt;Q.Set=Bb;qt.NAME="SET";var ff=class extends Qr(gt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Ft}toJSON(){return{...super.toJSON(),value:this.value}}};ff.NAME="StringValueBlock";var pf=class extends ff{};pf.NAME="SimpleStringValueBlock";var Mt=class extends lc{constructor({...e}={}){super(e,pf)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ge.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Mt.NAME="SIMPLE STRING";var hf=class extends Mt{fromBuffer(e){this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ge.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ge.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf8String(e)),this.valueBlock.value=e}};hf.NAME="Utf8StringValueBlock";var kb,fr=class extends hf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};kb=fr;Q.Utf8String=kb;fr.NAME="UTF8String";var df=class extends Mt{fromBuffer(e){this.valueBlock.value=ge.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf16String(e))}};df.NAME="BmpStringValueBlock";var Nb,ii=class extends df{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nb=ii;Q.BmpString=Nb;ii.NAME="BMPString";var yf=class extends Mt{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=uo(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}};yf.NAME="UniversalStringValueBlock";var jb,si=class extends yf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};jb=si;Q.UniversalString=jb;si.NAME="UniversalString";var Rb,ai=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Rb=ai;Q.NumericString=Rb;ai.NAME="NumericString";var Db,ci=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Db=ci;Q.PrintableString=Db;ci.NAME="PrintableString";var Lb,ui=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Lb=ui;Q.TeletexString=Lb;ui.NAME="TeletexString";var Ub,li=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Ub=li;Q.VideotexString=Ub;li.NAME="VideotexString";var Mb,fi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Mb=fi;Q.IA5String=Mb;fi.NAME="IA5String";var Kb,pi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Kb=pi;Q.GraphicString=Kb;pi.NAME="GraphicString";var Hb,fo=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Hb=fo;Q.VisibleString=Hb;fo.NAME="VisibleString";var Vb,hi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Vb=hi;Q.GeneralString=Vb;hi.NAME="GeneralString";var $b,di=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};$b=di;Q.CharacterString=$b;di.NAME="CharacterString";var Fb,po=class extends fo{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ge.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=$t(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=$t(this.month,2),t[2]=$t(this.day,2),t[3]=$t(this.hour,2),t[4]=$t(this.minute,2),t[5]=$t(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=po;Q.UTCTime=Fb;po.NAME="UTCTime";var Wb,yi=class extends po{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,d=n.indexOf("+"),v="";if(d===-1&&(d=n.indexOf("-"),f=-1),d!==-1){if(v=n.substring(d+1),n=n.substring(0,d),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=f*g,v.length===4){if(g=parseInt(v.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=f*g}}}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($t(this.year,4)),t.push($t(this.month,2)),t.push($t(this.day,2)),t.push($t(this.hour,2)),t.push($t(this.minute,2)),t.push($t(this.second,2)),this.millisecond!==0&&(t.push("."),t.push($t(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Wb=yi;Q.GeneralizedTime=Wb;yi.NAME="GeneralizedTime";var qb,mc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};qb=mc;Q.DATE=qb;mc.NAME="DATE";var Gb,gc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Gb=gc;Q.TimeOfDay=Gb;gc.NAME="TimeOfDay";var zb,wc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};zb=wc;Q.DateTime=zb;wc.NAME="DateTime";var Xb,bc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Xb=bc;Q.Duration=Xb;bc.NAME="Duration";var Yb,xc=class extends fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Yb=xc;Q.TIME=Yb;xc.NAME="TIME";var Jr=class{constructor({name:e=Ft,optional:t=!1}={}){this.name=e,this.optional=t}},Es=class extends Jr{constructor({value:e=[],...t}={}){super(t),this.value=e}},mi=class extends Jr{constructor({value:e=new Jr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},qd=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}constructor({data:e=mf}={}){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ge.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function lo(r,e,t){if(t instanceof Es){for(let i of t.value)if(lo(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Wd)&&(i.name=t.name),i}}if(t instanceof Jr)return t.hasOwnProperty(Wd)&&(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(!(c2 in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(p2 in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(h2 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(u2)===!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(l2)===!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(f2)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(a2 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,Ft),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 mi&&(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,Ft),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,Ft),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof mi){if(s=lo(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,Ft),t.name&&delete r[t.name]),s;if(Wd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};d2 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=lo(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,Ft),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,Ft),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=Cs(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,Ft),t.name&&(delete r[t.name],s.name=t.name)),s}return lo(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function b2(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Cs(ge.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:lo(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 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 Xd=$r(Sn()),tn=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Xd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Xd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Rr))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 Rr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Rr({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Yd=$r(Sn()),ce=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Yd.BufferSourceConverter.isBufferSource(e)?this.buffer=Yd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof jr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new jr({valueHex:this.buffer})}toSchema(e){return new jr({name:e})}};var x2={fromASN:r=>r instanceof Nr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Nr;let e=On(r);if(e.result.error)throw new Error(e.result.error);return e.result}},v2={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Tn({value:+r})},A2={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new ni({value:r})},be={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Tn({valueHex:r})};var _2={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Rr({valueHex:r})},S2={fromASN:r=>r.valueBlock.toString(),toASN:r=>new oi({value:r})},E2={fromASN:r=>r.valueBlock.value,toASN:r=>new ri({value:r})},Ts={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new jr({valueHex:r})},Zb={fromASN:r=>new ce(r.getValue()),toASN:r=>r.toASN()};function pr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Zd=pr(fr),C2=pr(ii),T2=pr(si),I2=pr(ai),O2=pr(ci),P2=pr(ui),B2=pr(li),k2=pr(fi),N2=pr(pi),j2=pr(fo),R2=pr(hi),D2=pr(di),L2={fromASN:r=>r.toDate(),toASN:r=>new po({valueDate:r})},U2={fromASN:r=>r.toDate(),toASN:r=>new yi({valueDate:r})},M2={fromASN:()=>null,toASN:()=>new Nr};function Is(r){switch(r){case h.Any:return x2;case h.BitString:return _2;case h.BmpString:return C2;case h.Boolean:return E2;case h.CharacterString:return D2;case h.Enumerated:return A2;case h.GeneralString:return R2;case h.GeneralizedTime:return U2;case h.GraphicString:return N2;case h.IA5String:return k2;case h.Integer:return v2;case h.Null:return M2;case h.NumericString:return I2;case h.ObjectIdentifier:return S2;case h.OctetString:return Ts;case h.PrintableString:return O2;case h.TeletexString:return P2;case h.UTCTime:return L2;case h.UniversalString:return T2;case h.Utf8String:return Zd;case h.VideotexString:return B2;case h.VisibleString:return j2;default:return null}}function hr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:hr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function Qd(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:Qd(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 gf=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 p=h[s.type],f=en[p];if(!f)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new f({name:a})}else hr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===A.Choice?c=new Jr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Jr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?qt:Wt;c=new p({name:"",value:[new mi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||hr(s.type)){let p=s.repeated?ft:Cn;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 ft({name:p?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:f}))}else o.push(new ft({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case A.Sequence:return new Wt({value:o,name:""});case A.Set:return new qt({value:o,name:""});case A.Choice:return new Es({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 Kt=new gf;var E=r=>e=>{let t;Kt.has(e)?t=Kt.get(e):(t=Kt.createDefault(e),Kt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;Kt.has(e.constructor)?n=Kt.get(e.constructor):(n=Kt.createDefault(e.constructor),Kt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Is(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 vc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Ac=class{static parse(e,t){let n=On(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(hr(t))return new t().fromASN(e);let o=Kt.get(t);Kt.cache(t);let i=o.schema;if(e.constructor===ft&&o.type!==A.Choice){i=new ft({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=lo({},e,i);if(!s.verified)throw new vc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(Qd(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=Is(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"||hr(f)){let d=(n=p.converter)!==null&&n!==void 0?n:hr(f)?new f:null;if(!d)throw new Error("Converter is empty");if(p.repeated)if(p.implicit){let v=p.repeated==="sequence"?Wt:qt,g=new v;g.valueBlock=l.valueBlock;let w=On(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 _=w.result.valueBlock.value;a[c]=Array.from(_,j=>d.fromASN(j))}else a[c]=Array.from(l,v=>d.fromASN(v));else{let v=l;if(p.implicit){let g;if(hr(f))g=new f().toSchema("");else{let w=h[f],_=en[w];if(!_)throw new Error(`Cannot get '${w}' class from asn1js module`);g=new _}g.valueBlock=v.valueBlock,v=On(g.toBER(!1)).result}a[c]=d.fromASN(v)}}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,d=>this.fromASN(d,f))}else a[c]=this.fromASN(l,f)}return a}catch(o){throw o instanceof vc&&o.schemas.push(t.name),o}}};var _c=class r{static serialize(e){return e instanceof ot?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&hr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Kt.get(t);Kt.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=Is(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"||hr(a.type))){let p={};p.valueHex=l instanceof Nr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new Cn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new ft({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new ft({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 A.Sequence:i=new Wt({value:o});break;case A.Set:i=new qt({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 ${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"?Wt:qt;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"?Wt:qt;i=new a({value:s})}else i=this.toASN(o);return i}};var se=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var ey=$r(Sn());var G=class r{static serialize(e){return _c.serialize(e)}static parse(e,t){return Ac.parse(e,t)}static toString(e){let t=ey.BufferSourceConverter.isBufferSource(e)?ey.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=On(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function m(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=$r(Sn()),Sc=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=$r(Sn()),ty,ry,ny,it=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};m([u({type:h.TeletexString})],it.prototype,"teletexString",void 0);m([u({type:h.PrintableString})],it.prototype,"printableString",void 0);m([u({type:h.UniversalString})],it.prototype,"universalString",void 0);m([u({type:h.Utf8String})],it.prototype,"utf8String",void 0);m([u({type:h.BmpString})],it.prototype,"bmpString",void 0);it=m([E({type:A.Choice})],it);var Os=class extends it{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?ex.Convert.ToHex(this.anyValue):super.toString())}};m([u({type:h.IA5String})],Os.prototype,"ia5String",void 0);m([u({type:h.Any})],Os.prototype,"anyValue",void 0);Os=m([E({type:A.Choice})],Os);var gi=class{constructor(e={}){this.type="",this.value=new Os,Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],gi.prototype,"type",void 0);m([u({type:Os})],gi.prototype,"value",void 0);var ho=ty=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ty.prototype)}};ho=ty=m([E({type:A.Set,itemType:gi})],ho);var oy=ry=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};oy=ry=m([E({type:A.Sequence,itemType:ho})],oy);var Le=ny=class extends oy{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};Le=ny=m([E({type:A.Sequence})],Le);var K2={fromASN:r=>Sc.toString(Ts.fromASN(r)),toASN:r=>Ts.toASN(Sc.fromString(r))},yo=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],yo.prototype,"typeId",void 0);m([u({type:h.Any,context:0})],yo.prototype,"value",void 0);var Ec=class{constructor(e={}){this.partyName=new it,Object.assign(this,e)}};m([u({type:it,optional:!0,context:0,implicit:!0})],Ec.prototype,"nameAssigner",void 0);m([u({type:it,context:1,implicit:!0})],Ec.prototype,"partyName",void 0);var le=class{constructor(e={}){Object.assign(this,e)}};m([u({type:yo,context:0,implicit:!0})],le.prototype,"otherName",void 0);m([u({type:h.IA5String,context:1,implicit:!0})],le.prototype,"rfc822Name",void 0);m([u({type:h.IA5String,context:2,implicit:!0})],le.prototype,"dNSName",void 0);m([u({type:h.Any,context:3,implicit:!0})],le.prototype,"x400Address",void 0);m([u({type:Le,context:4,implicit:!1})],le.prototype,"directoryName",void 0);m([u({type:Ec,context:5})],le.prototype,"ediPartyName",void 0);m([u({type:h.IA5String,context:6,implicit:!0})],le.prototype,"uniformResourceIdentifier",void 0);m([u({type:h.OctetString,context:7,implicit:!0,converter:K2})],le.prototype,"iPAddress",void 0);m([u({type:h.ObjectIdentifier,context:8,implicit:!0})],le.prototype,"registeredID",void 0);le=m([E({type:A.Choice})],le);var mo="1.3.6.1.5.5.7",go=`${mo}.1`,tx=`${mo}.2`,wi=`${mo}.3`,wf=`${mo}.48`,Uk=`${tx}.1`,Mk=`${tx}.2`,iy=`${wf}.1`,sy=`${wf}.2`,ay=`${wf}.3`,cy=`${wf}.5`,he="2.5.29";var uy,bf=`${go}.1`,Pn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new le,Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Pn.prototype,"accessMethod",void 0);m([u({type:le})],Pn.prototype,"accessLocation",void 0);var bi=uy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,uy.prototype)}};bi=uy=m([E({type:A.Sequence,itemType:Pn})],bi);var xf=`${he}.35`,xi=class extends ce{},rn=class{constructor(e={}){e&&Object.assign(this,e)}};m([u({type:xi,context:0,optional:!0,implicit:!0})],rn.prototype,"keyIdentifier",void 0);m([u({type:le,context:1,optional:!0,implicit:!0,repeated:"sequence"})],rn.prototype,"authorityCertIssuer",void 0);m([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:be})],rn.prototype,"authorityCertSerialNumber",void 0);var vf=`${he}.19`,vi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};m([u({type:h.Boolean,defaultValue:!1})],vi.prototype,"cA",void 0);m([u({type:h.Integer,optional:!0})],vi.prototype,"pathLenConstraint",void 0);var ly,Ge=ly=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};Ge=ly=m([E({type:A.Sequence,itemType:le})],Ge);var fy,H2=`${he}.29`,rx=fy=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};rx=fy=m([E({type:A.Sequence})],rx);var py,_f=`${he}.32`,gN=`${_f}.0`,Bn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};m([u({type:h.IA5String})],Bn.prototype,"ia5String",void 0);m([u({type:h.VisibleString})],Bn.prototype,"visibleString",void 0);m([u({type:h.BmpString})],Bn.prototype,"bmpString",void 0);m([u({type:h.Utf8String})],Bn.prototype,"utf8String",void 0);Bn=m([E({type:A.Choice})],Bn);var Cc=class{constructor(e={}){this.organization=new Bn,this.noticeNumbers=[],Object.assign(this,e)}};m([u({type:Bn})],Cc.prototype,"organization",void 0);m([u({type:h.Integer,repeated:"sequence"})],Cc.prototype,"noticeNumbers",void 0);var Tc=class{constructor(e={}){Object.assign(this,e)}};m([u({type:Cc,optional:!0})],Tc.prototype,"noticeRef",void 0);m([u({type:Bn,optional:!0})],Tc.prototype,"explicitText",void 0);var Af=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.IA5String})],Af.prototype,"cPSuri",void 0);m([u({type:Tc})],Af.prototype,"userNotice",void 0);Af=m([E({type:A.Choice})],Af);var Ic=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Ic.prototype,"policyQualifierId",void 0);m([u({type:h.Any})],Ic.prototype,"qualifier",void 0);var Ai=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Ai.prototype,"policyIdentifier",void 0);m([u({type:Ic,repeated:"sequence",optional:!0})],Ai.prototype,"policyQualifiers",void 0);var Oc=py=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};Oc=py=m([E({type:A.Sequence,itemType:Ai})],Oc);var EN=`${he}.20`,Pc=class{constructor(e=0){this.value=e}};m([u({type:h.Integer})],Pc.prototype,"value",void 0);Pc=m([E({type:A.Choice})],Pc);var kN=`${he}.27`,nx=class extends Pc{};nx=m([E({type:A.Choice})],nx);var hy,Sf=`${he}.31`,Lr;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(Lr||(Lr={}));var Bc=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&Lr.aACompromise&&e.push("aACompromise"),t&Lr.affiliationChanged&&e.push("affiliationChanged"),t&Lr.cACompromise&&e.push("cACompromise"),t&Lr.certificateHold&&e.push("certificateHold"),t&Lr.cessationOfOperation&&e.push("cessationOfOperation"),t&Lr.keyCompromise&&e.push("keyCompromise"),t&Lr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Lr.superseded&&e.push("superseded"),t&Lr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},kn=class{constructor(e={}){Object.assign(this,e)}};m([u({type:le,context:0,repeated:"sequence",implicit:!0})],kn.prototype,"fullName",void 0);m([u({type:ho,context:1,implicit:!0})],kn.prototype,"nameRelativeToCRLIssuer",void 0);kn=m([E({type:A.Choice})],kn);var nn=class{constructor(e={}){Object.assign(this,e)}};m([u({type:kn,context:0,optional:!0})],nn.prototype,"distributionPoint",void 0);m([u({type:Bc,context:1,optional:!0,implicit:!0})],nn.prototype,"reasons",void 0);m([u({type:le,context:2,optional:!0,repeated:"sequence",implicit:!0})],nn.prototype,"cRLIssuer",void 0);var wo=hy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};wo=hy=m([E({type:A.Sequence,itemType:nn})],wo);var dy,GN=`${he}.46`,ox=dy=class extends wo{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};ox=dy=m([E({type:A.Sequence,itemType:nn})],ox);var tj=`${he}.28`,nr=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};nr.ONLY=!1;m([u({type:kn,context:0,optional:!0})],nr.prototype,"distributionPoint",void 0);m([u({type:h.Boolean,context:1,defaultValue:nr.ONLY,implicit:!0})],nr.prototype,"onlyContainsUserCerts",void 0);m([u({type:h.Boolean,context:2,defaultValue:nr.ONLY,implicit:!0})],nr.prototype,"onlyContainsCACerts",void 0);m([u({type:Bc,context:3,optional:!0,implicit:!0})],nr.prototype,"onlySomeReasons",void 0);m([u({type:h.Boolean,context:4,defaultValue:nr.ONLY,implicit:!0})],nr.prototype,"indirectCRL",void 0);m([u({type:h.Boolean,context:5,defaultValue:nr.ONLY,implicit:!0})],nr.prototype,"onlyContainsAttributeCerts",void 0);var ix=`${he}.21`,kc;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(kc||(kc={}));var Nc=class{constructor(e=kc.unspecified){this.reason=kc.unspecified,this.reason=e}toJSON(){return kc[this.reason]}toString(){return this.toJSON()}};m([u({type:h.Enumerated})],Nc.prototype,"reason",void 0);Nc=m([E({type:A.Choice})],Nc);var yy,Ef=`${he}.37`,jc=yy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};jc=yy=m([E({type:A.Sequence,itemType:h.ObjectIdentifier})],jc);var pj=`${Ef}.0`,sx=`${wi}.1`,ax=`${wi}.2`,cx=`${wi}.3`,ux=`${wi}.4`,lx=`${wi}.8`,fx=`${wi}.9`;var gj=`${he}.54`,my=class{constructor(e=new ArrayBuffer(0)){this.value=e}};m([u({type:h.Integer,converter:be})],my.prototype,"value",void 0);my=m([E({type:A.Choice})],my);var px=`${he}.24`,Rc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};m([u({type:h.GeneralizedTime})],Rc.prototype,"value",void 0);Rc=m([E({type:A.Choice})],Rc);var gy,Oj=`${he}.18`,hx=gy=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,gy.prototype)}};hx=gy=m([E({type:A.Sequence})],hx);var Cf=`${he}.15`,Ur;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(Ur||(Ur={}));var Ps=class extends tn{toJSON(){let e=this.toNumber(),t=[];return e&Ur.cRLSign&&t.push("crlSign"),e&Ur.dataEncipherment&&t.push("dataEncipherment"),e&Ur.decipherOnly&&t.push("decipherOnly"),e&Ur.digitalSignature&&t.push("digitalSignature"),e&Ur.encipherOnly&&t.push("encipherOnly"),e&Ur.keyAgreement&&t.push("keyAgreement"),e&Ur.keyCertSign&&t.push("keyCertSign"),e&Ur.keyEncipherment&&t.push("keyEncipherment"),e&Ur.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var wy,Mj=`${he}.30`,Bs=class{constructor(e={}){this.base=new le,this.minimum=0,Object.assign(this,e)}};m([u({type:le})],Bs.prototype,"base",void 0);m([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Bs.prototype,"minimum",void 0);m([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Bs.prototype,"maximum",void 0);var Tf=wy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};Tf=wy=m([E({type:A.Sequence,itemType:Bs})],Tf);var If=class{constructor(e={}){Object.assign(this,e)}};m([u({type:Tf,context:0,optional:!0,implicit:!0})],If.prototype,"permittedSubtrees",void 0);m([u({type:Tf,context:1,optional:!0,implicit:!0})],If.prototype,"excludedSubtrees",void 0);var Wj=`${he}.36`,Of=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:be})],Of.prototype,"requireExplicitPolicy",void 0);m([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:be})],Of.prototype,"inhibitPolicyMapping",void 0);var by,Yj=`${he}.33`,Dc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Dc.prototype,"issuerDomainPolicy",void 0);m([u({type:h.ObjectIdentifier})],Dc.prototype,"subjectDomainPolicy",void 0);var dx=by=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};dx=by=m([E({type:A.Sequence,itemType:Dc})],dx);var xy,vy=`${he}.17`,Pf=xy=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};Pf=xy=m([E({type:A.Sequence})],Pf);var wt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],wt.prototype,"type",void 0);m([u({type:h.Any,repeated:"set"})],wt.prototype,"values",void 0);var Ay,pR=`${he}.9`,yx=Ay=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ay.prototype)}};yx=Ay=m([E({type:A.Sequence,itemType:wt})],yx);var _y=`${he}.14`,Gt=class extends xi{};var vR=`${he}.16`,Bf=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],Bf.prototype,"notBefore",void 0);m([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],Bf.prototype,"notAfter",void 0);var Lc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Lc||(Lc={}));var kf=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&Lc.pKIXCertificate&&e.push("pKIXCertificate"),t&Lc.newExtensions&&e.push("newExtensions"),t&Lc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Nf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new kf,Object.assign(this,e)}};m([u({type:h.GeneralString})],Nf.prototype,"entrustVers",void 0);m([u({type:kf})],Nf.prototype,"entrustInfoFlags",void 0);var Sy,PR=`${go}.11`,mx=Sy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Sy.prototype)}};mx=Sy=m([E({type:A.Sequence,itemType:Pn})],mx);var gx=$r(Sn()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&gx.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};m([u({type:h.ObjectIdentifier})],M.prototype,"algorithm",void 0);m([u({type:h.Any,optional:!0})],M.prototype,"parameters",void 0);var bt=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:M})],bt.prototype,"algorithm",void 0);m([u({type:h.BitString})],bt.prototype,"subjectPublicKey",void 0);var Ze=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};m([u({type:h.UTCTime})],Ze.prototype,"utcTime",void 0);m([u({type:h.GeneralizedTime})],Ze.prototype,"generalTime",void 0);Ze=m([E({type:A.Choice})],Ze);var Nn=class{constructor(e){this.notBefore=new Ze(new Date),this.notAfter=new Ze(new Date),e&&(this.notBefore=new Ze(e.notBefore),this.notAfter=new Ze(e.notAfter))}};m([u({type:Ze})],Nn.prototype,"notBefore",void 0);m([u({type:Ze})],Nn.prototype,"notAfter",void 0);var Ey,xt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ce,Object.assign(this,e)}};xt.CRITICAL=!1;m([u({type:h.ObjectIdentifier})],xt.prototype,"extnID",void 0);m([u({type:h.Boolean,defaultValue:xt.CRITICAL})],xt.prototype,"critical",void 0);m([u({type:ce})],xt.prototype,"extnValue",void 0);var or=Ey=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};or=Ey=m([E({type:A.Sequence,itemType:xt})],or);var on;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(on||(on={}));var vt=class{constructor(e={}){this.version=on.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new Le,this.validity=new Nn,this.subject=new Le,this.subjectPublicKeyInfo=new bt,Object.assign(this,e)}};m([u({type:h.Integer,context:0,defaultValue:on.v1})],vt.prototype,"version",void 0);m([u({type:h.Integer,converter:be})],vt.prototype,"serialNumber",void 0);m([u({type:M})],vt.prototype,"signature",void 0);m([u({type:Le})],vt.prototype,"issuer",void 0);m([u({type:Nn})],vt.prototype,"validity",void 0);m([u({type:Le})],vt.prototype,"subject",void 0);m([u({type:bt})],vt.prototype,"subjectPublicKeyInfo",void 0);m([u({type:h.BitString,context:1,implicit:!0,optional:!0})],vt.prototype,"issuerUniqueID",void 0);m([u({type:h.BitString,context:2,implicit:!0,optional:!0})],vt.prototype,"subjectUniqueID",void 0);m([u({type:or,context:3,optional:!0})],vt.prototype,"extensions",void 0);var dr=class{constructor(e={}){this.tbsCertificate=new vt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:vt})],dr.prototype,"tbsCertificate",void 0);m([u({type:M})],dr.prototype,"signatureAlgorithm",void 0);m([u({type:h.BitString})],dr.prototype,"signatureValue",void 0);var _i=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ze,Object.assign(this,e)}};m([u({type:h.Integer,converter:be})],_i.prototype,"userCertificate",void 0);m([u({type:Ze})],_i.prototype,"revocationDate",void 0);m([u({type:xt,optional:!0,repeated:"sequence"})],_i.prototype,"crlEntryExtensions",void 0);var ir=class{constructor(e={}){this.signature=new M,this.issuer=new Le,this.thisUpdate=new Ze,Object.assign(this,e)}};m([u({type:h.Integer,optional:!0})],ir.prototype,"version",void 0);m([u({type:M})],ir.prototype,"signature",void 0);m([u({type:Le})],ir.prototype,"issuer",void 0);m([u({type:Ze})],ir.prototype,"thisUpdate",void 0);m([u({type:Ze,optional:!0})],ir.prototype,"nextUpdate",void 0);m([u({type:_i,repeated:"sequence",optional:!0})],ir.prototype,"revokedCertificates",void 0);m([u({type:xt,optional:!0,context:0,repeated:"sequence"})],ir.prototype,"crlExtensions",void 0);var Si=class{constructor(e={}){this.tbsCertList=new ir,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:ir})],Si.prototype,"tbsCertList",void 0);m([u({type:M})],Si.prototype,"signatureAlgorithm",void 0);m([u({type:h.BitString})],Si.prototype,"signature",void 0);var V=$r(Sn());function C(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Mr=class{constructor(e={}){this.issuer=new Le,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:Le})],Mr.prototype,"issuer",void 0);C([u({type:h.Integer,converter:be})],Mr.prototype,"serialNumber",void 0);var Ei=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Gt,context:0,implicit:!0})],Ei.prototype,"subjectKeyIdentifier",void 0);C([u({type:Mr})],Ei.prototype,"issuerAndSerialNumber",void 0);Ei=C([E({type:A.Choice})],Ei);var At;(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"})(At||(At={}));var Ci=class extends M{};Ci=C([E({type:A.Sequence})],Ci);var Uc=class extends M{};Uc=C([E({type:A.Sequence})],Uc);var zt=class extends M{};zt=C([E({type:A.Sequence})],zt);var Mc=class extends M{};Mc=C([E({type:A.Sequence})],Mc);var bx=class extends M{};bx=C([E({type:A.Sequence})],bx);var jf=class extends M{};jf=C([E({type:A.Sequence})],jf);var Kr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Kr.prototype,"attrType",void 0);C([u({type:h.Any,repeated:"set"})],Kr.prototype,"attrValues",void 0);var Cy,Xt=class{constructor(e={}){this.version=At.v0,this.sid=new Ei,this.digestAlgorithm=new Ci,this.signatureAlgorithm=new Uc,this.signature=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],Xt.prototype,"version",void 0);C([u({type:Ei})],Xt.prototype,"sid",void 0);C([u({type:Ci})],Xt.prototype,"digestAlgorithm",void 0);C([u({type:Kr,repeated:"set",context:0,implicit:!0,optional:!0})],Xt.prototype,"signedAttrs",void 0);C([u({type:Uc})],Xt.prototype,"signatureAlgorithm",void 0);C([u({type:ce})],Xt.prototype,"signature",void 0);C([u({type:Kr,repeated:"set",context:1,implicit:!0,optional:!0})],Xt.prototype,"unsignedAttrs",void 0);var Kc=Cy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};Kc=Cy=C([E({type:A.Set,itemType:Xt})],Kc);var xx=class extends Ze{};xx=C([E({type:A.Choice})],xx);var vx=class extends Xt{};vx=C([E({type:A.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 Hc=class{constructor(e={}){this.acIssuer=new le,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:le})],Hc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Hc.prototype,"acSerial",void 0);z([u({type:wt,repeated:"sequence"})],Hc.prototype,"attrs",void 0);var Ty,Vc=Ty=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};Vc=Ty=z([E({type:A.Sequence,itemType:h.ObjectIdentifier})],Vc);var ks=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],ks.prototype,"pathLenConstraint",void 0);z([u({type:Vc,implicit:!0,context:0,optional:!0})],ks.prototype,"permittedAttrs",void 0);z([u({type:Vc,implicit:!0,context:1,optional:!0})],ks.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],ks.prototype,"permitUnSpecified",void 0);var yr=class{constructor(e={}){this.issuer=new Ge,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Ge})],yr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:be})],yr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],yr.prototype,"issuerUID",void 0);var Iy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(Iy||(Iy={}));var mr=class{constructor(e={}){this.digestedObjectType=Iy.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],mr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],mr.prototype,"otherObjectTypeID",void 0);z([u({type:M})],mr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],mr.prototype,"objectDigest",void 0);var Ti=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ge,optional:!0})],Ti.prototype,"issuerName",void 0);z([u({type:yr,context:0,implicit:!0,optional:!0})],Ti.prototype,"baseCertificateID",void 0);z([u({type:mr,context:1,implicit:!0,optional:!0})],Ti.prototype,"objectDigestInfo",void 0);var Ii=class{constructor(e={}){Object.assign(this,e)}};z([u({type:le,repeated:"sequence"})],Ii.prototype,"v1Form",void 0);z([u({type:Ti,context:0,implicit:!0})],Ii.prototype,"v2Form",void 0);Ii=z([E({type:A.Choice})],Ii);var Oi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Oi.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Oi.prototype,"notAfterTime",void 0);var bo=class{constructor(e={}){Object.assign(this,e)}};z([u({type:yr,implicit:!0,context:0,optional:!0})],bo.prototype,"baseCertificateID",void 0);z([u({type:Ge,implicit:!0,context:1,optional:!0})],bo.prototype,"entityName",void 0);z([u({type:mr,implicit:!0,context:2,optional:!0})],bo.prototype,"objectDigestInfo",void 0);var Oy;(function(r){r[r.v2=1]="v2"})(Oy||(Oy={}));var Yt=class{constructor(e={}){this.version=Oy.v2,this.holder=new bo,this.issuer=new Ii,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Oi,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],Yt.prototype,"version",void 0);z([u({type:bo})],Yt.prototype,"holder",void 0);z([u({type:Ii})],Yt.prototype,"issuer",void 0);z([u({type:M})],Yt.prototype,"signature",void 0);z([u({type:h.Integer,converter:be})],Yt.prototype,"serialNumber",void 0);z([u({type:Oi})],Yt.prototype,"attrCertValidityPeriod",void 0);z([u({type:wt,repeated:"sequence"})],Yt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],Yt.prototype,"issuerUniqueID",void 0);z([u({type:or,optional:!0})],Yt.prototype,"extensions",void 0);var Pi=class{constructor(e={}){this.acinfo=new Yt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Yt})],Pi.prototype,"acinfo",void 0);z([u({type:M})],Pi.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Pi.prototype,"signatureValue",void 0);var $c;(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"})($c||($c={}));var Ns=class extends tn{};var js=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],js.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],js.prototype,"value",void 0);var Fc=class{constructor(e={}){this.policyId="",this.classList=new Ns($c.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],Fc.prototype,"policyId",void 0);z([u({type:Ns,defaultValue:new Ns($c.unclassified)})],Fc.prototype,"classList",void 0);z([u({type:js,repeated:"set"})],Fc.prototype,"securityCategories",void 0);var Rs=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ce})],Rs.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],Rs.prototype,"oid",void 0);z([u({type:h.Utf8String})],Rs.prototype,"string",void 0);var Rf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ge,implicit:!0,context:0,optional:!0})],Rf.prototype,"policyAuthority",void 0);z([u({type:Rs,repeated:"sequence"})],Rf.prototype,"values",void 0);var pM=`${go}.4`,hM=`${go}.6`,dM=`${go}.10`,yM=`${he}.55`,Wc=`${mo}.10`,mM=`${Wc}.1`,gM=`${Wc}.2`,wM=`${Wc}.3`,bM=`${Wc}.4`,xM=`${Wc}.6`,Py="2.5.4",vM=`${Py}.72`;var By,Ds=class{constructor(e={}){this.targetCertificate=new yr,Object.assign(this,e)}};z([u({type:yr})],Ds.prototype,"targetCertificate",void 0);z([u({type:le,optional:!0})],Ds.prototype,"targetName",void 0);z([u({type:mr,optional:!0})],Ds.prototype,"certDigestInfo",void 0);var Ls=class{constructor(e={}){Object.assign(this,e)}};z([u({type:le,context:0,implicit:!0})],Ls.prototype,"targetName",void 0);z([u({type:le,context:1,implicit:!0})],Ls.prototype,"targetGroup",void 0);z([u({type:Ds,context:2,implicit:!0})],Ls.prototype,"targetCert",void 0);Ls=z([E({type:A.Choice})],Ls);var Df=By=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,By.prototype)}};Df=By=z([E({type:A.Sequence,itemType:Ls})],Df);var ky,Ax=ky=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Ax=ky=z([E({type:A.Sequence,itemType:Df})],Ax);var Lf=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ge,implicit:!0,context:0,optional:!0})],Lf.prototype,"roleAuthority",void 0);z([u({type:le,implicit:!0,context:1})],Lf.prototype,"roleName",void 0);var qc=class{constructor(e={}){this.service=new le,this.ident=new le,Object.assign(this,e)}};z([u({type:le})],qc.prototype,"service",void 0);z([u({type:le})],qc.prototype,"ident",void 0);z([u({type:ce,optional:!0})],qc.prototype,"authInfo",void 0);var Ny,Gc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Gc.prototype,"otherCertFormat",void 0);C([u({type:h.Any})],Gc.prototype,"otherCert",void 0);var Bi=class{constructor(e={}){Object.assign(this,e)}};C([u({type:dr})],Bi.prototype,"certificate",void 0);C([u({type:Pi,context:2,implicit:!0})],Bi.prototype,"v2AttrCert",void 0);C([u({type:Gc,context:3,implicit:!0})],Bi.prototype,"other",void 0);Bi=C([E({type:A.Choice})],Bi);var ki=Ny=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};ki=Ny=C([E({type:A.Set,itemType:Bi})],ki);var gr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],gr.prototype,"contentType",void 0);C([u({type:h.Any,context:0})],gr.prototype,"content",void 0);var Us=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ce})],Us.prototype,"single",void 0);C([u({type:h.Any})],Us.prototype,"any",void 0);Us=C([E({type:A.Choice})],Us);var Ni=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Ni.prototype,"eContentType",void 0);C([u({type:Us,context:0,optional:!0})],Ni.prototype,"eContent",void 0);var zc=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ce,context:0,implicit:!0,optional:!0})],zc.prototype,"value",void 0);C([u({type:ce,converter:Zb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],zc.prototype,"constructedValue",void 0);zc=C([E({type:A.Choice})],zc);var xo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Mc,Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],xo.prototype,"contentType",void 0);C([u({type:Mc})],xo.prototype,"contentEncryptionAlgorithm",void 0);C([u({type:zc,optional:!0})],xo.prototype,"encryptedContent",void 0);var vo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],vo.prototype,"keyAttrId",void 0);C([u({type:h.Any,optional:!0})],vo.prototype,"keyAttr",void 0);var jy,Ms=class{constructor(e={}){this.subjectKeyIdentifier=new Gt,Object.assign(this,e)}};C([u({type:Gt})],Ms.prototype,"subjectKeyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Ms.prototype,"date",void 0);C([u({type:vo,optional:!0})],Ms.prototype,"other",void 0);var Ks=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Ms,context:0,implicit:!0,optional:!0})],Ks.prototype,"rKeyId",void 0);C([u({type:Mr,optional:!0})],Ks.prototype,"issuerAndSerialNumber",void 0);Ks=C([E({type:A.Choice})],Ks);var Xc=class{constructor(e={}){this.rid=new Ks,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:Ks})],Xc.prototype,"rid",void 0);C([u({type:ce})],Xc.prototype,"encryptedKey",void 0);var Uf=jy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};Uf=jy=C([E({type:A.Sequence,itemType:Xc})],Uf);var Yc=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:M})],Yc.prototype,"algorithm",void 0);C([u({type:h.BitString})],Yc.prototype,"publicKey",void 0);var ji=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Gt,context:0,implicit:!0,optional:!0})],ji.prototype,"subjectKeyIdentifier",void 0);C([u({type:Yc,context:1,implicit:!0,optional:!0})],ji.prototype,"originatorKey",void 0);C([u({type:Mr,optional:!0})],ji.prototype,"issuerAndSerialNumber",void 0);ji=C([E({type:A.Choice})],ji);var jn=class{constructor(e={}){this.version=At.v3,this.originator=new ji,this.keyEncryptionAlgorithm=new zt,this.recipientEncryptedKeys=new Uf,Object.assign(this,e)}};C([u({type:h.Integer})],jn.prototype,"version",void 0);C([u({type:ji,context:0})],jn.prototype,"originator",void 0);C([u({type:ce,context:1,optional:!0})],jn.prototype,"ukm",void 0);C([u({type:zt})],jn.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:Uf})],jn.prototype,"recipientEncryptedKeys",void 0);var Hs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Gt,context:0,implicit:!0})],Hs.prototype,"subjectKeyIdentifier",void 0);C([u({type:Mr})],Hs.prototype,"issuerAndSerialNumber",void 0);Hs=C([E({type:A.Choice})],Hs);var Ao=class{constructor(e={}){this.version=At.v0,this.rid=new Hs,this.keyEncryptionAlgorithm=new zt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],Ao.prototype,"version",void 0);C([u({type:Hs})],Ao.prototype,"rid",void 0);C([u({type:zt})],Ao.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],Ao.prototype,"encryptedKey",void 0);var Ri=class{constructor(e={}){this.keyIdentifier=new ce,Object.assign(this,e)}};C([u({type:ce})],Ri.prototype,"keyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Ri.prototype,"date",void 0);C([u({type:vo,optional:!0})],Ri.prototype,"other",void 0);var _o=class{constructor(e={}){this.version=At.v4,this.kekid=new Ri,this.keyEncryptionAlgorithm=new zt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],_o.prototype,"version",void 0);C([u({type:Ri})],_o.prototype,"kekid",void 0);C([u({type:zt})],_o.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],_o.prototype,"encryptedKey",void 0);var So=class{constructor(e={}){this.version=At.v0,this.keyEncryptionAlgorithm=new zt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],So.prototype,"version",void 0);C([u({type:jf,context:0,optional:!0})],So.prototype,"keyDerivationAlgorithm",void 0);C([u({type:zt})],So.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],So.prototype,"encryptedKey",void 0);var Zc=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Zc.prototype,"oriType",void 0);C([u({type:h.Any})],Zc.prototype,"oriValue",void 0);var Rn=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Ao,optional:!0})],Rn.prototype,"ktri",void 0);C([u({type:jn,context:1,implicit:!0,optional:!0})],Rn.prototype,"kari",void 0);C([u({type:_o,context:2,implicit:!0,optional:!0})],Rn.prototype,"kekri",void 0);C([u({type:So,context:3,implicit:!0,optional:!0})],Rn.prototype,"pwri",void 0);C([u({type:Zc,context:4,implicit:!0,optional:!0})],Rn.prototype,"ori",void 0);Rn=C([E({type:A.Choice})],Rn);var Ry,Jc=Ry=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ry.prototype)}};Jc=Ry=C([E({type:A.Set,itemType:Rn})],Jc);var Dy,_x=`${mo}.16`,xK=`${_x}.2`,vK=`${_x}.4`,Vs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Vs.prototype,"otherRevInfoFormat",void 0);C([u({type:h.Any})],Vs.prototype,"otherRevInfo",void 0);var Mf=class{constructor(e={}){this.other=new Vs,Object.assign(this,e)}};C([u({type:Vs,context:1,implicit:!0})],Mf.prototype,"other",void 0);Mf=C([E({type:A.Choice})],Mf);var $s=Dy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};$s=Dy=C([E({type:A.Set,itemType:Mf})],$s);var Fs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ki,context:0,implicit:!0,optional:!0})],Fs.prototype,"certs",void 0);C([u({type:$s,context:1,implicit:!0,optional:!0})],Fs.prototype,"crls",void 0);var Ly,Uy=Ly=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Uy=Ly=C([E({type:A.Set,itemType:Kr})],Uy);var Di=class{constructor(e={}){this.version=At.v0,this.recipientInfos=new Jc,this.encryptedContentInfo=new xo,Object.assign(this,e)}};C([u({type:h.Integer})],Di.prototype,"version",void 0);C([u({type:Fs,context:0,implicit:!0,optional:!0})],Di.prototype,"originatorInfo",void 0);C([u({type:Jc})],Di.prototype,"recipientInfos",void 0);C([u({type:xo})],Di.prototype,"encryptedContentInfo",void 0);C([u({type:Uy,context:1,implicit:!0,optional:!0})],Di.prototype,"unprotectedAttrs",void 0);var Sx="1.2.840.113549.1.7.2";var My,Kf=My=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,My.prototype)}};Kf=My=C([E({type:A.Set,itemType:Ci})],Kf);var Dn=class{constructor(e={}){this.version=At.v0,this.digestAlgorithms=new Kf,this.encapContentInfo=new Ni,this.signerInfos=new Kc,Object.assign(this,e)}};C([u({type:h.Integer})],Dn.prototype,"version",void 0);C([u({type:Kf})],Dn.prototype,"digestAlgorithms",void 0);C([u({type:Ni})],Dn.prototype,"encapContentInfo",void 0);C([u({type:ki,context:0,implicit:!0,optional:!0})],Dn.prototype,"certificates",void 0);C([u({type:$s,context:1,implicit:!0,optional:!0})],Dn.prototype,"crls",void 0);C([u({type:Kc})],Dn.prototype,"signerInfos",void 0);var Li="1.2.840.10045.2.1";var Qc="1.2.840.10045.4.1",Hf="1.2.840.10045.4.3.1",eu="1.2.840.10045.4.3.2",tu="1.2.840.10045.4.3.3",ru="1.2.840.10045.4.3.4";var Ky="1.2.840.10045.3.1.7";var Hy="1.3.132.0.34";var Vy="1.3.132.0.35";function nu(r){return new M({algorithm:r})}var Cx=nu(Qc),gH=nu(Hf),Tx=nu(eu),Ix=nu(tu),Ox=nu(ru);function Ue(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 ou=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.ObjectIdentifier})],ou.prototype,"fieldType",void 0);Ue([u({type:h.Any})],ou.prototype,"parameters",void 0);ou=Ue([E({type:A.Sequence})],ou);var $y=class extends ce{};var Ws=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.OctetString})],Ws.prototype,"a",void 0);Ue([u({type:h.OctetString})],Ws.prototype,"b",void 0);Ue([u({type:h.BitString,optional:!0})],Ws.prototype,"seed",void 0);Ws=Ue([E({type:A.Sequence})],Ws);var Fy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Fy||(Fy={}));var sn=class{constructor(e={}){this.version=Fy.ecpVer1,Object.assign(this,e)}};Ue([u({type:h.Integer})],sn.prototype,"version",void 0);Ue([u({type:ou})],sn.prototype,"fieldID",void 0);Ue([u({type:Ws})],sn.prototype,"curve",void 0);Ue([u({type:$y})],sn.prototype,"base",void 0);Ue([u({type:h.Integer,converter:be})],sn.prototype,"order",void 0);Ue([u({type:h.Integer,optional:!0})],sn.prototype,"cofactor",void 0);sn=Ue([E({type:A.Sequence})],sn);var an=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.ObjectIdentifier})],an.prototype,"namedCurve",void 0);Ue([u({type:h.Null})],an.prototype,"implicitCurve",void 0);Ue([u({type:sn})],an.prototype,"specifiedCurve",void 0);an=Ue([E({type:A.Choice})],an);var qs=class{constructor(e={}){this.version=1,this.privateKey=new ce,Object.assign(this,e)}};Ue([u({type:h.Integer})],qs.prototype,"version",void 0);Ue([u({type:ce})],qs.prototype,"privateKey",void 0);Ue([u({type:an,context:0,optional:!0})],qs.prototype,"parameters",void 0);Ue([u({type:h.BitString,context:1,optional:!0})],qs.prototype,"publicKey",void 0);var Ui=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Ue([u({type:h.Integer,converter:be})],Ui.prototype,"r",void 0);Ue([u({type:h.Integer,converter:be})],Ui.prototype,"s",void 0);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 Zt="1.2.840.113549.1.1",cn=`${Zt}.1`,Px=`${Zt}.7`,Bx=`${Zt}.9`,Eo=`${Zt}.10`,kx=`${Zt}.2`,Nx=`${Zt}.4`,Gs=`${Zt}.5`,jx=`${Zt}.14`;var Vf=`${Zt}.11`,zs=`${Zt}.12`,Xs=`${Zt}.13`,Wy=`${Zt}.15`,qy=`${Zt}.16`,Mi="1.3.14.3.2.26",$f="2.16.840.1.101.3.4.2.4",Ki="2.16.840.1.101.3.4.2.1",Hi="2.16.840.1.101.3.4.2.2",Vi="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",Co=`${Zt}.8`;function pt(r){return new M({algorithm:r,parameters:null})}var GH=pt(Lx),zH=pt(Ux),Ln=pt(Mi),XH=pt($f),YH=pt(Ki),ZH=pt(Hi),JH=pt(Vi),QH=pt(Rx),e7=pt(Dx),Ff=new M({algorithm:Co,parameters:G.serialize(Ln)}),Gy=new M({algorithm:Bx,parameters:G.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))}),t7=pt(cn),r7=pt(kx),n7=pt(Nx),o7=pt(Gs),i7=pt(Wy),s7=pt(qy),a7=pt(zs),c7=pt(Xs),u7=pt(Wy),l7=pt(qy);var Ys=class{constructor(e={}){this.hashAlgorithm=new M(Ln),this.maskGenAlgorithm=new M({algorithm:Co,parameters:G.serialize(Ln)}),this.pSourceAlgorithm=new M(Gy),Object.assign(this,e)}};ke([u({type:M,context:0,defaultValue:Ln})],Ys.prototype,"hashAlgorithm",void 0);ke([u({type:M,context:1,defaultValue:Ff})],Ys.prototype,"maskGenAlgorithm",void 0);ke([u({type:M,context:2,defaultValue:Gy})],Ys.prototype,"pSourceAlgorithm",void 0);var g7=new M({algorithm:Px,parameters:G.serialize(new Ys)});var un=class{constructor(e={}){this.hashAlgorithm=new M(Ln),this.maskGenAlgorithm=new M({algorithm:Co,parameters:G.serialize(Ln)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};ke([u({type:M,context:0,defaultValue:Ln})],un.prototype,"hashAlgorithm",void 0);ke([u({type:M,context:1,defaultValue:Ff})],un.prototype,"maskGenAlgorithm",void 0);ke([u({type:h.Integer,context:2,defaultValue:20})],un.prototype,"saltLength",void 0);ke([u({type:h.Integer,context:3,defaultValue:1})],un.prototype,"trailerField",void 0);var S7=new M({algorithm:Eo,parameters:G.serialize(new un)});var $i=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ce,Object.assign(this,e)}};ke([u({type:M})],$i.prototype,"digestAlgorithm",void 0);ke([u({type:ce})],$i.prototype,"digest",void 0);var zy,Zs=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer,converter:be})],Zs.prototype,"prime",void 0);ke([u({type:h.Integer,converter:be})],Zs.prototype,"exponent",void 0);ke([u({type:h.Integer,converter:be})],Zs.prototype,"coefficient",void 0);var Wf=zy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,zy.prototype)}};Wf=zy=ke([E({type:A.Sequence,itemType:Zs})],Wf);var wr=class{constructor(e={}){this.version=0,this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),this.privateExponent=new ArrayBuffer(0),this.prime1=new ArrayBuffer(0),this.prime2=new ArrayBuffer(0),this.exponent1=new ArrayBuffer(0),this.exponent2=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer})],wr.prototype,"version",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"modulus",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"publicExponent",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"privateExponent",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"prime1",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"prime2",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"exponent1",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"exponent2",void 0);ke([u({type:h.Integer,converter:be})],wr.prototype,"coefficient",void 0);ke([u({type:Wf,optional:!0})],wr.prototype,"otherPrimeInfos",void 0);var Js=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer,converter:be})],Js.prototype,"modulus",void 0);ke([u({type:h.Integer,converter:be})],Js.prototype,"publicExponent",void 0);function iu(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Xy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Xy||(Xy={}));var _t=Xy;var sv=$r(iv(),1),{__extends:ea,__assign:rV,__rest:G2,__decorate:nV,__param:oV,__metadata:iV,__awaiter:av,__generator:cv,__exportStar:sV,__createBinding:aV,__values:su,__read:au,__spread:Hr,__spreadArrays:cV,__await:uV,__asyncGenerator:lV,__asyncDelegator:fV,__asyncValues:pV,__makeTemplateObject:hV,__importStar:dV,__importDefault:yV,__classPrivateFieldGet:mV,__classPrivateFieldSet:gV}=sv.default;var z2="injectionTokens";function Zy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(z2,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function cu(r){return!!r.useClass}function ta(r){return!!r.useFactory}var zf=function(){function r(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return r.prototype.createProxy=function(e){var t=this,n={},o=!1,i,s=function(){return o||(i=e(t.wrap()),o=!0),i};return new Proxy(n,this.createHandler(s))},r.prototype.createHandler=function(e){var t={},n=function(o){t[o]=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];i[0]=e();var a=Reflect[o];return a.apply(void 0,Hr(i))}};return this.reflectMethods.forEach(n),t},r}();function To(r){return typeof r=="string"||typeof r=="symbol"}function Jy(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Xf(r){return typeof r=="object"&&"token"in r&&"transform"in r}function uv(r){return typeof r=="function"||r instanceof zf}function Fi(r){return!!r.useToken}function Wi(r){return r.useValue!=null}function lv(r){return cu(r)||Wi(r)||Fi(r)||ta(r)}var X2=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}(),uu=X2;var Y2=function(r){ea(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(uu),fv=Y2;var Z2=function(){function r(){this.scopedResolutions=new Map}return r}(),lu=Z2;function J2(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function Q2(r,e,t){return t===void 0&&(t=" "),Hr([r],e.message.split(`
6
+ `)}`:`${t} :`}};_b=ft;Q.Constructed=_b;ft.NAME="CONSTRUCTED";var af=class extends gt{fromBER(e,t,n){return t}toBER(e){return Lr}};af.override="EndOfContentValueBlock";var Sb,dc=class extends ot{constructor(e={}){super(e,af),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Sb=dc;Q.EndOfContent=Sb;dc.NAME=pc;var Eb,jr=class extends ot{constructor(e={}){super(e,gt),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}`}};Eb=jr;Q.Null=Eb;jr.NAME="NULL";var cf=class extends en(gt){get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=ge.BufferSourceConverter.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,n){let o=ge.BufferSourceConverter.toUint8Array(e);return On(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Wd.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};cf.NAME="BooleanValueBlock";var Cb,ri=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,cf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Cb=ri;Q.Boolean=Cb;ri.NAME="BOOLEAN";var uf=class extends en(Jr){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=Jr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==bb)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?Jr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};uf.NAME="OctetStringValueBlock";var Xd,Rr=class extends ot{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},uf),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=Is(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return ft.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=ge.Convert.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof Xd&&e.push(t.valueBlock.valueHexView);return ge.BufferSourceConverter.concat(e)}};Xd=Rr;Q.OctetString=Xd;Rr.NAME=bb;var lf=class extends en(Jr){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=Jr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==xb)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=ge.BufferSourceConverter.toUint8Array(e);if(!On(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Is(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+n}toBER(e,t){if(this.isConstructed)return Jr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Lr;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}}};lf.NAME="BitStringValueBlock";var Tb,Dr=class extends ot{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},lf),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 ft.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}`}}};Tb=Dr;Q.BitString=Tb;Dr.NAME=xb;var Ib;function _2(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 d=p;d>=0;d--,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=tf(new Uint8Array([l%10]),i);break;default:i[s-f]=l%10}}return t[0]>0&&(i=tf(t,i)),i}function wb(r){if(r>=lc.length)for(let e=lc.length;e<=r;e++){let t=new Uint8Array([0]),n=lc[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=tf(t,n)),lc.push(n)}return lc[r]}function S2(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 yc=class extends en(gt){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Wd.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(db(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=S2(wb(n),t),s="-";break;default:t=_2(t,wb(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=mb.charAt(t[c]));return a===!1&&(s+=mb.charAt(0)),s}};Ib=yc;yc.NAME="IntegerValueBlock";Object.defineProperty(Ib.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var fc,In=class extends ot{constructor(e={}){super(e,yc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return rf(),BigInt(this.valueBlock.toString())}static fromBigInt(e){rf();let t=BigInt(e),n=new Cs,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(ge.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${ge.Convert.ToHex(a)}`)+t,p=ge.BufferSourceConverter.toUint8Array(ge.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 fc({valueHex:n.final()})}convertToDER(){let e=new fc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new fc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};fc=In;Q.Integer=fc;In.NAME="INTEGER";var Ob,ni=class extends In{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Ob=ni;Q.Enumerated=Ob;ni.NAME="ENUMERATED";var mc=class extends en(gt){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=ge.BufferSourceConverter.toUint8Array(e);if(!On(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=ti(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){rf();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=uo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Lr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=ge.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};mc.NAME="sidBlock";var ff=class extends gt{constructor({value:e=Wt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new mc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,Lr;t.push(o)}return zd(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new mc;if(o>Number.MAX_SAFE_INTEGER){rf();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}};ff.NAME="ObjectIdentifierValueBlock";var Pb,oi=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,ff),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Pb=oi;Q.ObjectIdentifier=Pb;oi.NAME="OBJECT IDENTIFIER";var gc=class extends en(Cn){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=ge.BufferSourceConverter.toUint8Array(e);if(!On(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=ti(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=uo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Lr;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=ge.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};gc.NAME="relativeSidBlock";var pf=class extends gt{constructor({value:e=Wt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new gc;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,Lr;n.push(i)}return zd(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new gc;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};pf.NAME="RelativeObjectIdentifierValueBlock";var Bb,wc=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,pf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Bb=wc;Q.RelativeObjectIdentifier=Bb;wc.NAME="RelativeObjectIdentifier";var kb,qt=class extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};kb=qt;Q.Sequence=kb;qt.NAME="SEQUENCE";var Nb,Gt=class extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Nb=Gt;Q.Set=Nb;Gt.NAME="SET";var hf=class extends en(gt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Wt}toJSON(){return{...super.toJSON(),value:this.value}}};hf.NAME="StringValueBlock";var df=class extends hf{};df.NAME="SimpleStringValueBlock";var Mt=class extends hc{constructor({...e}={}){super(e,df)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,ge.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Mt.NAME="SIMPLE STRING";var yf=class extends Mt{fromBuffer(e){this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=ge.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=ge.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf8String(e)),this.valueBlock.value=e}};yf.NAME="Utf8StringValueBlock";var jb,pr=class extends yf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};jb=pr;Q.Utf8String=jb;pr.NAME="UTF8String";var mf=class extends Mt{fromBuffer(e){this.valueBlock.value=ge.Convert.ToUtf16String(e),this.valueBlock.valueHexView=ge.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(ge.Convert.FromUtf16String(e))}};mf.NAME="BmpStringValueBlock";var Rb,ii=class extends mf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Rb=ii;Q.BmpString=Rb;ii.NAME="BMPString";var gf=class extends Mt{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=uo(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}};gf.NAME="UniversalStringValueBlock";var Db,si=class extends gf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Db=si;Q.UniversalString=Db;si.NAME="UniversalString";var Lb,ai=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Lb=ai;Q.NumericString=Lb;ai.NAME="NumericString";var Ub,ci=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ub=ci;Q.PrintableString=Ub;ci.NAME="PrintableString";var Mb,ui=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Mb=ui;Q.TeletexString=Mb;ui.NAME="TeletexString";var Kb,li=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Kb=li;Q.VideotexString=Kb;li.NAME="VideotexString";var Hb,fi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Hb=fi;Q.IA5String=Hb;fi.NAME="IA5String";var Vb,pi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Vb=pi;Q.GraphicString=Vb;pi.NAME="GraphicString";var $b,fo=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};$b=fo;Q.VisibleString=$b;fo.NAME="VisibleString";var Fb,hi=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Fb=hi;Q.GeneralString=Fb;hi.NAME="GeneralString";var Wb,di=class extends Mt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Wb=di;Q.CharacterString=Wb;di.NAME="CharacterString";var qb,po=class extends fo{constructor({value:e,valueDate:t,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,ge.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let t=new Array(7);return t[0]=Ft(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Ft(this.month,2),t[2]=Ft(this.day,2),t[3]=Ft(this.hour,2),t[4]=Ft(this.minute,2),t[5]=Ft(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}}};qb=po;Q.UTCTime=qb;po.NAME="UTCTime";var Gb,yi=class extends po{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,d=n.indexOf("+"),v="";if(d===-1&&(d=n.indexOf("-"),f=-1),d!==-1){if(v=n.substring(d+1),n=n.substring(0,d),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=f*g,v.length===4){if(g=parseInt(v.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");c=f*g}}}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(Ft(this.year,4)),t.push(Ft(this.month,2)),t.push(Ft(this.day,2)),t.push(Ft(this.hour,2)),t.push(Ft(this.minute,2)),t.push(Ft(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Ft(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Gb=yi;Q.GeneralizedTime=Gb;yi.NAME="GeneralizedTime";var zb,bc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};zb=bc;Q.DATE=zb;bc.NAME="DATE";var Xb,xc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Xb=xc;Q.TimeOfDay=Xb;xc.NAME="TimeOfDay";var Yb,vc=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Yb=vc;Q.DateTime=Yb;vc.NAME="DateTime";var Zb,Ac=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Zb=Ac;Q.Duration=Zb;Ac.NAME="Duration";var Jb,_c=class extends pr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Jb=_c;Q.TIME=Jb;_c.NAME="TIME";var Qr=class{constructor({name:e=Wt,optional:t=!1}={}){this.name=e,this.optional=t}},Ts=class extends Qr{constructor({value:e=[],...t}={}){super(t),this.value=e}},mi=class extends Qr{constructor({value:e=new Qr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Gd=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}constructor({data:e=wf}={}){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}fromBER(e,t,n){let o=t+n;return this.dataView=ge.BufferSourceConverter.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}};function lo(r,e,t){if(t instanceof Ts){for(let i of t.value)if(lo(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(qd)&&(i.name=t.name),i}}if(t instanceof Qr)return t.hasOwnProperty(qd)&&(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(!(d2 in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(w2 in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(b2 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(y2)===!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(m2)===!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(g2)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(h2 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(!(gb 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,Wt),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 mi&&(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,Wt),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,Wt),t.name&&(delete r[t.name],l.name=t.name)),l}}else if(t.valueBlock.value[0]instanceof mi){if(s=lo(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,Wt),t.name&&delete r[t.name]),s;if(qd in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let l={};x2 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=lo(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,Wt),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,Wt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&gb in e.valueBlock){let i=Is(e.valueBlock.valueHexView);if(i.offset===-1){let s={verified:!1,result:i.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Wt),t.name&&(delete r[t.name],s.name=t.name)),s}return lo(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function E2(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Is(ge.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:lo(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 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 Yd=Fr(En()),rn=class{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(Yd.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=Yd.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Dr))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new Dr({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Dr({name:e})}toNumber(){let e="",t=new Uint8Array(this.value);for(let n of t)e+=n.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2),n=t.length+7>>3;this.unusedBits=(n<<3)-t.length;let o=new Uint8Array(n);t=t.padStart(n<<3,"0").split("").reverse().join("");let i=0;for(;i<n;)o[i]=parseInt(t.slice(i<<3,(i<<3)+8),2),i++;this.value=o.buffer}};var Zd=Fr(En()),ce=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):Zd.BufferSourceConverter.isBufferSource(e)?this.buffer=Zd.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Rr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Rr({valueHex:this.buffer})}toSchema(e){return new Rr({name:e})}};var C2={fromASN:r=>r instanceof jr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new jr;let e=Pn(r);if(e.result.error)throw new Error(e.result.error);return e.result}},T2={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new In({value:+r})},I2={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new ni({value:r})},be={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new In({valueHex:r})};var O2={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Dr({valueHex:r})},P2={fromASN:r=>r.valueBlock.toString(),toASN:r=>new oi({value:r})},B2={fromASN:r=>r.valueBlock.value,toASN:r=>new ri({value:r})},Os={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Rr({valueHex:r})},Qb={fromASN:r=>new ce(r.getValue()),toASN:r=>r.toASN()};function hr(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var Jd=hr(pr),k2=hr(ii),N2=hr(si),j2=hr(ai),R2=hr(ci),D2=hr(ui),L2=hr(li),U2=hr(fi),M2=hr(pi),K2=hr(fo),H2=hr(hi),V2=hr(di),$2={fromASN:r=>r.toDate(),toASN:r=>new po({valueDate:r})},F2={fromASN:r=>r.toDate(),toASN:r=>new yi({valueDate:r})},W2={fromASN:()=>null,toASN:()=>new jr};function Ps(r){switch(r){case h.Any:return C2;case h.BitString:return O2;case h.BmpString:return k2;case h.Boolean:return B2;case h.CharacterString:return V2;case h.Enumerated:return I2;case h.GeneralString:return H2;case h.GeneralizedTime:return F2;case h.GraphicString:return M2;case h.IA5String:return U2;case h.Integer:return T2;case h.Null:return W2;case h.NumericString:return j2;case h.ObjectIdentifier:return P2;case h.OctetString:return Os;case h.PrintableString:return R2;case h.TeletexString:return D2;case h.UTCTime:return $2;case h.UniversalString:return N2;case h.Utf8String:return Jd;case h.VideotexString:return L2;case h.VisibleString:return K2;default:return null}}function dr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:dr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function ey(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:ey(t)}return!1}function ex(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==n[o])return!1;return!0}var bf=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type: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 p=h[s.type],f=tn[p];if(!f)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new f({name:a})}else dr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===A.Choice?c=new Qr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Qr({name:a});let l=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Gt:qt;c=new p({name:"",value:[new mi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||dr(s.type)){let p=s.repeated?ft:Tn;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 ft({name:p?"":a,optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:f}))}else o.push(new ft({optional:l,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=l,o.push(c)}switch(n.type){case A.Sequence:return new qt({value:o,name:""});case A.Set:return new Gt({value:o,name:""});case A.Choice:return new Ts({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){let t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}};var Kt=new bf;var E=r=>e=>{let t;Kt.has(e)?t=Kt.get(e):(t=Kt.createDefault(e),Kt.set(e,t)),Object.assign(t,r)};var u=r=>(e,t)=>{let n;Kt.has(e.constructor)?n=Kt.get(e.constructor):(n=Kt.createDefault(e.constructor),Kt.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Ps(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}n.items[t]=o};var Sc=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Ec=class{static parse(e,t){let n=Pn(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){var n;try{if(dr(t))return new t().fromASN(e);let o=Kt.get(t);Kt.cache(t);let i=o.schema;if(e.constructor===ft&&o.type!==A.Choice){i=new ft({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:o.schema.valueBlock.value});for(let c in o.items)delete e[c]}let s=lo({},e,i);if(!s.verified)throw new Sc(`Data does not match to ${t.name} ASN1 schema. ${s.result.error}`);let a=new t;if(ey(t)){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let c=o.itemType;if(typeof c=="number"){let l=Ps(c);if(!l)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);return t.from(e.valueBlock.value,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"||dr(f)){let d=(n=p.converter)!==null&&n!==void 0?n:dr(f)?new f:null;if(!d)throw new Error("Converter is empty");if(p.repeated)if(p.implicit){let v=p.repeated==="sequence"?qt:Gt,g=new v;g.valueBlock=l.valueBlock;let w=Pn(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 _=w.result.valueBlock.value;a[c]=Array.from(_,j=>d.fromASN(j))}else a[c]=Array.from(l,v=>d.fromASN(v));else{let v=l;if(p.implicit){let g;if(dr(f))g=new f().toSchema("");else{let w=h[f],_=tn[w];if(!_)throw new Error(`Cannot get '${w}' class from asn1js module`);g=new _}g.valueBlock=v.valueBlock,v=Pn(g.toBER(!1)).result}a[c]=d.fromASN(v)}}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,d=>this.fromASN(d,f))}else a[c]=this.fromASN(l,f)}return a}catch(o){throw o instanceof Sc&&o.schemas.push(t.name),o}}};var Cc=class r{static serialize(e){return e instanceof ot?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&dr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Kt.get(t);Kt.cache(t);let o=[];if(n.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof n.itemType=="number"){let s=Ps(n.itemType);if(!s)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);o=e.map(a=>s.toASN(a))}else o=e.map(s=>this.toAsnItem({type:n.itemType},"[]",t,s))}else for(let s in n.items){let a=n.items[s],c=e[s];if(c===void 0||a.defaultValue===c||typeof a.defaultValue=="object"&&typeof c=="object"&&ex(this.serialize(a.defaultValue),this.serialize(c)))continue;let l=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||dr(a.type))){let p={};p.valueHex=l instanceof jr?l.valueBeforeDecodeView:l.valueBlock.toBER(),o.push(new Tn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new ft({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:l.valueBlock.value}));else o.push(new ft({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 A.Sequence:i=new qt({value:o});break;case A.Set:i=new Gt({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 ${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"?qt:Gt;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"?qt:Gt;i=new a({value:s})}else i=this.toASN(o);return i}};var se=class extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(let t of e)this.push(t)}}};var ty=Fr(En());var G=class r{static serialize(e){return Cc.serialize(e)}static parse(e,t){return Ec.parse(e,t)}static toString(e){let t=ty.BufferSourceConverter.isBufferSource(e)?ty.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Pn(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function m(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var tx=Fr(En()),Tc=class{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){let t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(n=>{let o=parseInt(n,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){let n=this.expandIPv6(e).split(":");if(n.length!==8)throw new Error("Invalid IPv6 address");return n.reduce((o,i)=>{let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;let t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");let n=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],i=8-(n.length+o.length);if(i<0)throw new Error("Invalid IPv6 address");return[...n,...Array(i).fill("0"),...o].join(":")}static formatIPv6(e){let t=[];for(let n=0;n<16;n+=2)t.push((e[n]<<8|e[n+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){let t=e.split(":"),n=-1,o=0,i=-1,s=0;for(let a=0;a<t.length;a++)t[a]==="0"?(i===-1&&(i=a),s++):(s>o&&(n=i,o=s),i=-1,s=0);if(s>o&&(n=i,o=s),o>1){let a=t.slice(0,n).join(":"),c=t.slice(n+o).join(":");return`${a}::${c}`}return e}static parseCIDR(e){let[t,n]=e.split("/"),o=parseInt(n,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;let t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,i)=>o+ +i,0),n=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return n=n.slice(0,-1),`${n}/${t}`}static toString(e){let t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){let n=t.length/2,o=t.slice(0,n),i=t.slice(n);if(t.every(c=>c===0))return t.length===8?"0.0.0.0/0":"::/0";let a=i.reduce((c,l)=>c+(l.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(tx.Convert.ToHex(e))}static fromString(e){if(e.includes("/")){let[n,o]=this.parseCIDR(e),i=new Uint8Array(n.length),s=o;for(let c=0;c<i.length;c++)s>=8?(i[c]=255,s-=8):s>0&&(i[c]=255<<8-s,s=0);let a=new Uint8Array(n.length*2);return a.set(n,0),a.set(i,n.length),a.buffer}let t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}};var rx=Fr(En()),ry,ny,oy,it=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};m([u({type:h.TeletexString})],it.prototype,"teletexString",void 0);m([u({type:h.PrintableString})],it.prototype,"printableString",void 0);m([u({type:h.UniversalString})],it.prototype,"universalString",void 0);m([u({type:h.Utf8String})],it.prototype,"utf8String",void 0);m([u({type:h.BmpString})],it.prototype,"bmpString",void 0);it=m([E({type:A.Choice})],it);var Bs=class extends it{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?rx.Convert.ToHex(this.anyValue):super.toString())}};m([u({type:h.IA5String})],Bs.prototype,"ia5String",void 0);m([u({type:h.Any})],Bs.prototype,"anyValue",void 0);Bs=m([E({type:A.Choice})],Bs);var gi=class{constructor(e={}){this.type="",this.value=new Bs,Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],gi.prototype,"type",void 0);m([u({type:Bs})],gi.prototype,"value",void 0);var ho=ry=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ry.prototype)}};ho=ry=m([E({type:A.Set,itemType:gi})],ho);var iy=ny=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ny.prototype)}};iy=ny=m([E({type:A.Sequence,itemType:ho})],iy);var Le=oy=class extends iy{constructor(e){super(e),Object.setPrototypeOf(this,oy.prototype)}};Le=oy=m([E({type:A.Sequence})],Le);var q2={fromASN:r=>Tc.toString(Os.fromASN(r)),toASN:r=>Os.toASN(Tc.fromString(r))},yo=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],yo.prototype,"typeId",void 0);m([u({type:h.Any,context:0})],yo.prototype,"value",void 0);var Ic=class{constructor(e={}){this.partyName=new it,Object.assign(this,e)}};m([u({type:it,optional:!0,context:0,implicit:!0})],Ic.prototype,"nameAssigner",void 0);m([u({type:it,context:1,implicit:!0})],Ic.prototype,"partyName",void 0);var fe=class{constructor(e={}){Object.assign(this,e)}};m([u({type:yo,context:0,implicit:!0})],fe.prototype,"otherName",void 0);m([u({type:h.IA5String,context:1,implicit:!0})],fe.prototype,"rfc822Name",void 0);m([u({type:h.IA5String,context:2,implicit:!0})],fe.prototype,"dNSName",void 0);m([u({type:h.Any,context:3,implicit:!0})],fe.prototype,"x400Address",void 0);m([u({type:Le,context:4,implicit:!1})],fe.prototype,"directoryName",void 0);m([u({type:Ic,context:5})],fe.prototype,"ediPartyName",void 0);m([u({type:h.IA5String,context:6,implicit:!0})],fe.prototype,"uniformResourceIdentifier",void 0);m([u({type:h.OctetString,context:7,implicit:!0,converter:q2})],fe.prototype,"iPAddress",void 0);m([u({type:h.ObjectIdentifier,context:8,implicit:!0})],fe.prototype,"registeredID",void 0);fe=m([E({type:A.Choice})],fe);var mo="1.3.6.1.5.5.7",go=`${mo}.1`,nx=`${mo}.2`,wi=`${mo}.3`,xf=`${mo}.48`,Wk=`${nx}.1`,qk=`${nx}.2`,sy=`${xf}.1`,ay=`${xf}.2`,cy=`${xf}.3`,uy=`${xf}.5`,he="2.5.29";var ly,vf=`${go}.1`,Bn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new fe,Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Bn.prototype,"accessMethod",void 0);m([u({type:fe})],Bn.prototype,"accessLocation",void 0);var bi=ly=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ly.prototype)}};bi=ly=m([E({type:A.Sequence,itemType:Bn})],bi);var Af=`${he}.35`,xi=class extends ce{},nn=class{constructor(e={}){e&&Object.assign(this,e)}};m([u({type:xi,context:0,optional:!0,implicit:!0})],nn.prototype,"keyIdentifier",void 0);m([u({type:fe,context:1,optional:!0,implicit:!0,repeated:"sequence"})],nn.prototype,"authorityCertIssuer",void 0);m([u({type:h.Integer,context:2,optional:!0,implicit:!0,converter:be})],nn.prototype,"authorityCertSerialNumber",void 0);var _f=`${he}.19`,vi=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};m([u({type:h.Boolean,defaultValue:!1})],vi.prototype,"cA",void 0);m([u({type:h.Integer,optional:!0})],vi.prototype,"pathLenConstraint",void 0);var fy,Ge=fy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,fy.prototype)}};Ge=fy=m([E({type:A.Sequence,itemType:fe})],Ge);var py,G2=`${he}.29`,ox=py=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,py.prototype)}};ox=py=m([E({type:A.Sequence})],ox);var hy,Ef=`${he}.32`,SN=`${Ef}.0`,kn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};m([u({type:h.IA5String})],kn.prototype,"ia5String",void 0);m([u({type:h.VisibleString})],kn.prototype,"visibleString",void 0);m([u({type:h.BmpString})],kn.prototype,"bmpString",void 0);m([u({type:h.Utf8String})],kn.prototype,"utf8String",void 0);kn=m([E({type:A.Choice})],kn);var Oc=class{constructor(e={}){this.organization=new kn,this.noticeNumbers=[],Object.assign(this,e)}};m([u({type:kn})],Oc.prototype,"organization",void 0);m([u({type:h.Integer,repeated:"sequence"})],Oc.prototype,"noticeNumbers",void 0);var Pc=class{constructor(e={}){Object.assign(this,e)}};m([u({type:Oc,optional:!0})],Pc.prototype,"noticeRef",void 0);m([u({type:kn,optional:!0})],Pc.prototype,"explicitText",void 0);var Sf=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.IA5String})],Sf.prototype,"cPSuri",void 0);m([u({type:Pc})],Sf.prototype,"userNotice",void 0);Sf=m([E({type:A.Choice})],Sf);var Bc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Bc.prototype,"policyQualifierId",void 0);m([u({type:h.Any})],Bc.prototype,"qualifier",void 0);var Ai=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Ai.prototype,"policyIdentifier",void 0);m([u({type:Bc,repeated:"sequence",optional:!0})],Ai.prototype,"policyQualifiers",void 0);var kc=hy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,hy.prototype)}};kc=hy=m([E({type:A.Sequence,itemType:Ai})],kc);var kN=`${he}.20`,Nc=class{constructor(e=0){this.value=e}};m([u({type:h.Integer})],Nc.prototype,"value",void 0);Nc=m([E({type:A.Choice})],Nc);var MN=`${he}.27`,ix=class extends Nc{};ix=m([E({type:A.Choice})],ix);var dy,Cf=`${he}.31`,Ur;(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"})(Ur||(Ur={}));var jc=class extends rn{toJSON(){let e=[],t=this.toNumber();return t&Ur.aACompromise&&e.push("aACompromise"),t&Ur.affiliationChanged&&e.push("affiliationChanged"),t&Ur.cACompromise&&e.push("cACompromise"),t&Ur.certificateHold&&e.push("certificateHold"),t&Ur.cessationOfOperation&&e.push("cessationOfOperation"),t&Ur.keyCompromise&&e.push("keyCompromise"),t&Ur.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Ur.superseded&&e.push("superseded"),t&Ur.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Nn=class{constructor(e={}){Object.assign(this,e)}};m([u({type:fe,context:0,repeated:"sequence",implicit:!0})],Nn.prototype,"fullName",void 0);m([u({type:ho,context:1,implicit:!0})],Nn.prototype,"nameRelativeToCRLIssuer",void 0);Nn=m([E({type:A.Choice})],Nn);var on=class{constructor(e={}){Object.assign(this,e)}};m([u({type:Nn,context:0,optional:!0})],on.prototype,"distributionPoint",void 0);m([u({type:jc,context:1,optional:!0,implicit:!0})],on.prototype,"reasons",void 0);m([u({type:fe,context:2,optional:!0,repeated:"sequence",implicit:!0})],on.prototype,"cRLIssuer",void 0);var wo=dy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,dy.prototype)}};wo=dy=m([E({type:A.Sequence,itemType:on})],wo);var yy,ej=`${he}.46`,sx=yy=class extends wo{constructor(e){super(e),Object.setPrototypeOf(this,yy.prototype)}};sx=yy=m([E({type:A.Sequence,itemType:on})],sx);var cj=`${he}.28`,or=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};or.ONLY=!1;m([u({type:Nn,context:0,optional:!0})],or.prototype,"distributionPoint",void 0);m([u({type:h.Boolean,context:1,defaultValue:or.ONLY,implicit:!0})],or.prototype,"onlyContainsUserCerts",void 0);m([u({type:h.Boolean,context:2,defaultValue:or.ONLY,implicit:!0})],or.prototype,"onlyContainsCACerts",void 0);m([u({type:jc,context:3,optional:!0,implicit:!0})],or.prototype,"onlySomeReasons",void 0);m([u({type:h.Boolean,context:4,defaultValue:or.ONLY,implicit:!0})],or.prototype,"indirectCRL",void 0);m([u({type:h.Boolean,context:5,defaultValue:or.ONLY,implicit:!0})],or.prototype,"onlyContainsAttributeCerts",void 0);var ax=`${he}.21`,Rc;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(Rc||(Rc={}));var Dc=class{constructor(e=Rc.unspecified){this.reason=Rc.unspecified,this.reason=e}toJSON(){return Rc[this.reason]}toString(){return this.toJSON()}};m([u({type:h.Enumerated})],Dc.prototype,"reason",void 0);Dc=m([E({type:A.Choice})],Dc);var my,Tf=`${he}.37`,Lc=my=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,my.prototype)}};Lc=my=m([E({type:A.Sequence,itemType:h.ObjectIdentifier})],Lc);var bj=`${Tf}.0`,cx=`${wi}.1`,ux=`${wi}.2`,lx=`${wi}.3`,fx=`${wi}.4`,px=`${wi}.8`,hx=`${wi}.9`;var Sj=`${he}.54`,gy=class{constructor(e=new ArrayBuffer(0)){this.value=e}};m([u({type:h.Integer,converter:be})],gy.prototype,"value",void 0);gy=m([E({type:A.Choice})],gy);var dx=`${he}.24`,Uc=class{constructor(e){this.value=new Date,e&&(this.value=e)}};m([u({type:h.GeneralizedTime})],Uc.prototype,"value",void 0);Uc=m([E({type:A.Choice})],Uc);var wy,Dj=`${he}.18`,yx=wy=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,wy.prototype)}};yx=wy=m([E({type:A.Sequence})],yx);var If=`${he}.15`,Mr;(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"})(Mr||(Mr={}));var ks=class extends rn{toJSON(){let e=this.toNumber(),t=[];return e&Mr.cRLSign&&t.push("crlSign"),e&Mr.dataEncipherment&&t.push("dataEncipherment"),e&Mr.decipherOnly&&t.push("decipherOnly"),e&Mr.digitalSignature&&t.push("digitalSignature"),e&Mr.encipherOnly&&t.push("encipherOnly"),e&Mr.keyAgreement&&t.push("keyAgreement"),e&Mr.keyCertSign&&t.push("keyCertSign"),e&Mr.keyEncipherment&&t.push("keyEncipherment"),e&Mr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var by,qj=`${he}.30`,Ns=class{constructor(e={}){this.base=new fe,this.minimum=0,Object.assign(this,e)}};m([u({type:fe})],Ns.prototype,"base",void 0);m([u({type:h.Integer,context:0,defaultValue:0,implicit:!0})],Ns.prototype,"minimum",void 0);m([u({type:h.Integer,context:1,optional:!0,implicit:!0})],Ns.prototype,"maximum",void 0);var Of=by=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,by.prototype)}};Of=by=m([E({type:A.Sequence,itemType:Ns})],Of);var Pf=class{constructor(e={}){Object.assign(this,e)}};m([u({type:Of,context:0,optional:!0,implicit:!0})],Pf.prototype,"permittedSubtrees",void 0);m([u({type:Of,context:1,optional:!0,implicit:!0})],Pf.prototype,"excludedSubtrees",void 0);var Jj=`${he}.36`,Bf=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.Integer,context:0,implicit:!0,optional:!0,converter:be})],Bf.prototype,"requireExplicitPolicy",void 0);m([u({type:h.Integer,context:1,implicit:!0,optional:!0,converter:be})],Bf.prototype,"inhibitPolicyMapping",void 0);var xy,nR=`${he}.33`,Mc=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],Mc.prototype,"issuerDomainPolicy",void 0);m([u({type:h.ObjectIdentifier})],Mc.prototype,"subjectDomainPolicy",void 0);var mx=xy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,xy.prototype)}};mx=xy=m([E({type:A.Sequence,itemType:Mc})],mx);var vy,Ay=`${he}.17`,kf=vy=class extends Ge{constructor(e){super(e),Object.setPrototypeOf(this,vy.prototype)}};kf=vy=m([E({type:A.Sequence})],kf);var wt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};m([u({type:h.ObjectIdentifier})],wt.prototype,"type",void 0);m([u({type:h.Any,repeated:"set"})],wt.prototype,"values",void 0);var _y,bR=`${he}.9`,gx=_y=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,_y.prototype)}};gx=_y=m([E({type:A.Sequence,itemType:wt})],gx);var Sy=`${he}.14`,zt=class extends xi{};var IR=`${he}.16`,Nf=class{constructor(e={}){Object.assign(this,e)}};m([u({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],Nf.prototype,"notBefore",void 0);m([u({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],Nf.prototype,"notAfter",void 0);var Kc;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Kc||(Kc={}));var jf=class extends rn{toJSON(){let e=[],t=this.toNumber();return t&Kc.pKIXCertificate&&e.push("pKIXCertificate"),t&Kc.newExtensions&&e.push("newExtensions"),t&Kc.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Rf=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new jf,Object.assign(this,e)}};m([u({type:h.GeneralString})],Rf.prototype,"entrustVers",void 0);m([u({type:jf})],Rf.prototype,"entrustInfoFlags",void 0);var Ey,LR=`${go}.11`,wx=Ey=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ey.prototype)}};wx=Ey=m([E({type:A.Sequence,itemType:Bn})],wx);var bx=Fr(En()),M=class r{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof r&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&bx.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};m([u({type:h.ObjectIdentifier})],M.prototype,"algorithm",void 0);m([u({type:h.Any,optional:!0})],M.prototype,"parameters",void 0);var bt=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:M})],bt.prototype,"algorithm",void 0);m([u({type:h.BitString})],bt.prototype,"subjectPublicKey",void 0);var Ze=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};m([u({type:h.UTCTime})],Ze.prototype,"utcTime",void 0);m([u({type:h.GeneralizedTime})],Ze.prototype,"generalTime",void 0);Ze=m([E({type:A.Choice})],Ze);var jn=class{constructor(e){this.notBefore=new Ze(new Date),this.notAfter=new Ze(new Date),e&&(this.notBefore=new Ze(e.notBefore),this.notAfter=new Ze(e.notAfter))}};m([u({type:Ze})],jn.prototype,"notBefore",void 0);m([u({type:Ze})],jn.prototype,"notAfter",void 0);var Cy,xt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ce,Object.assign(this,e)}};xt.CRITICAL=!1;m([u({type:h.ObjectIdentifier})],xt.prototype,"extnID",void 0);m([u({type:h.Boolean,defaultValue:xt.CRITICAL})],xt.prototype,"critical",void 0);m([u({type:ce})],xt.prototype,"extnValue",void 0);var ir=Cy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Cy.prototype)}};ir=Cy=m([E({type:A.Sequence,itemType:xt})],ir);var sn;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(sn||(sn={}));var vt=class{constructor(e={}){this.version=sn.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new Le,this.validity=new jn,this.subject=new Le,this.subjectPublicKeyInfo=new bt,Object.assign(this,e)}};m([u({type:h.Integer,context:0,defaultValue:sn.v1})],vt.prototype,"version",void 0);m([u({type:h.Integer,converter:be})],vt.prototype,"serialNumber",void 0);m([u({type:M})],vt.prototype,"signature",void 0);m([u({type:Le})],vt.prototype,"issuer",void 0);m([u({type:jn})],vt.prototype,"validity",void 0);m([u({type:Le})],vt.prototype,"subject",void 0);m([u({type:bt})],vt.prototype,"subjectPublicKeyInfo",void 0);m([u({type:h.BitString,context:1,implicit:!0,optional:!0})],vt.prototype,"issuerUniqueID",void 0);m([u({type:h.BitString,context:2,implicit:!0,optional:!0})],vt.prototype,"subjectUniqueID",void 0);m([u({type:ir,context:3,optional:!0})],vt.prototype,"extensions",void 0);var yr=class{constructor(e={}){this.tbsCertificate=new vt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:vt})],yr.prototype,"tbsCertificate",void 0);m([u({type:M})],yr.prototype,"signatureAlgorithm",void 0);m([u({type:h.BitString})],yr.prototype,"signatureValue",void 0);var _i=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Ze,Object.assign(this,e)}};m([u({type:h.Integer,converter:be})],_i.prototype,"userCertificate",void 0);m([u({type:Ze})],_i.prototype,"revocationDate",void 0);m([u({type:xt,optional:!0,repeated:"sequence"})],_i.prototype,"crlEntryExtensions",void 0);var sr=class{constructor(e={}){this.signature=new M,this.issuer=new Le,this.thisUpdate=new Ze,Object.assign(this,e)}};m([u({type:h.Integer,optional:!0})],sr.prototype,"version",void 0);m([u({type:M})],sr.prototype,"signature",void 0);m([u({type:Le})],sr.prototype,"issuer",void 0);m([u({type:Ze})],sr.prototype,"thisUpdate",void 0);m([u({type:Ze,optional:!0})],sr.prototype,"nextUpdate",void 0);m([u({type:_i,repeated:"sequence",optional:!0})],sr.prototype,"revokedCertificates",void 0);m([u({type:xt,optional:!0,context:0,repeated:"sequence"})],sr.prototype,"crlExtensions",void 0);var Si=class{constructor(e={}){this.tbsCertList=new sr,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};m([u({type:sr})],Si.prototype,"tbsCertList",void 0);m([u({type:M})],Si.prototype,"signatureAlgorithm",void 0);m([u({type:h.BitString})],Si.prototype,"signature",void 0);var V=Fr(En());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 Kr=class{constructor(e={}){this.issuer=new Le,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:Le})],Kr.prototype,"issuer",void 0);C([u({type:h.Integer,converter:be})],Kr.prototype,"serialNumber",void 0);var Ei=class{constructor(e={}){Object.assign(this,e)}};C([u({type:zt,context:0,implicit:!0})],Ei.prototype,"subjectKeyIdentifier",void 0);C([u({type:Kr})],Ei.prototype,"issuerAndSerialNumber",void 0);Ei=C([E({type:A.Choice})],Ei);var At;(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"})(At||(At={}));var Ci=class extends M{};Ci=C([E({type:A.Sequence})],Ci);var Hc=class extends M{};Hc=C([E({type:A.Sequence})],Hc);var Xt=class extends M{};Xt=C([E({type:A.Sequence})],Xt);var Vc=class extends M{};Vc=C([E({type:A.Sequence})],Vc);var vx=class extends M{};vx=C([E({type:A.Sequence})],vx);var Df=class extends M{};Df=C([E({type:A.Sequence})],Df);var Hr=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Hr.prototype,"attrType",void 0);C([u({type:h.Any,repeated:"set"})],Hr.prototype,"attrValues",void 0);var Ty,Yt=class{constructor(e={}){this.version=At.v0,this.sid=new Ei,this.digestAlgorithm=new Ci,this.signatureAlgorithm=new Hc,this.signature=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],Yt.prototype,"version",void 0);C([u({type:Ei})],Yt.prototype,"sid",void 0);C([u({type:Ci})],Yt.prototype,"digestAlgorithm",void 0);C([u({type:Hr,repeated:"set",context:0,implicit:!0,optional:!0})],Yt.prototype,"signedAttrs",void 0);C([u({type:Hc})],Yt.prototype,"signatureAlgorithm",void 0);C([u({type:ce})],Yt.prototype,"signature",void 0);C([u({type:Hr,repeated:"set",context:1,implicit:!0,optional:!0})],Yt.prototype,"unsignedAttrs",void 0);var $c=Ty=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ty.prototype)}};$c=Ty=C([E({type:A.Set,itemType:Yt})],$c);var Ax=class extends Ze{};Ax=C([E({type:A.Choice})],Ax);var _x=class extends Yt{};_x=C([E({type:A.Sequence})],_x);function z(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Fc=class{constructor(e={}){this.acIssuer=new fe,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};z([u({type:fe})],Fc.prototype,"acIssuer",void 0);z([u({type:h.Integer})],Fc.prototype,"acSerial",void 0);z([u({type:wt,repeated:"sequence"})],Fc.prototype,"attrs",void 0);var Iy,Wc=Iy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Iy.prototype)}};Wc=Iy=z([E({type:A.Sequence,itemType:h.ObjectIdentifier})],Wc);var js=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};z([u({type:h.Integer,optional:!0})],js.prototype,"pathLenConstraint",void 0);z([u({type:Wc,implicit:!0,context:0,optional:!0})],js.prototype,"permittedAttrs",void 0);z([u({type:Wc,implicit:!0,context:1,optional:!0})],js.prototype,"excludedAttrs",void 0);z([u({type:h.Boolean,defaultValue:!0})],js.prototype,"permitUnSpecified",void 0);var mr=class{constructor(e={}){this.issuer=new Ge,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Ge})],mr.prototype,"issuer",void 0);z([u({type:h.Integer,converter:be})],mr.prototype,"serial",void 0);z([u({type:h.BitString,optional:!0})],mr.prototype,"issuerUID",void 0);var Oy;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(Oy||(Oy={}));var gr=class{constructor(e={}){this.digestedObjectType=Oy.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.Enumerated})],gr.prototype,"digestedObjectType",void 0);z([u({type:h.ObjectIdentifier,optional:!0})],gr.prototype,"otherObjectTypeID",void 0);z([u({type:M})],gr.prototype,"digestAlgorithm",void 0);z([u({type:h.BitString})],gr.prototype,"objectDigest",void 0);var Ti=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ge,optional:!0})],Ti.prototype,"issuerName",void 0);z([u({type:mr,context:0,implicit:!0,optional:!0})],Ti.prototype,"baseCertificateID",void 0);z([u({type:gr,context:1,implicit:!0,optional:!0})],Ti.prototype,"objectDigestInfo",void 0);var Ii=class{constructor(e={}){Object.assign(this,e)}};z([u({type:fe,repeated:"sequence"})],Ii.prototype,"v1Form",void 0);z([u({type:Ti,context:0,implicit:!0})],Ii.prototype,"v2Form",void 0);Ii=z([E({type:A.Choice})],Ii);var Oi=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};z([u({type:h.GeneralizedTime})],Oi.prototype,"notBeforeTime",void 0);z([u({type:h.GeneralizedTime})],Oi.prototype,"notAfterTime",void 0);var bo=class{constructor(e={}){Object.assign(this,e)}};z([u({type:mr,implicit:!0,context:0,optional:!0})],bo.prototype,"baseCertificateID",void 0);z([u({type:Ge,implicit:!0,context:1,optional:!0})],bo.prototype,"entityName",void 0);z([u({type:gr,implicit:!0,context:2,optional:!0})],bo.prototype,"objectDigestInfo",void 0);var Py;(function(r){r[r.v2=1]="v2"})(Py||(Py={}));var Zt=class{constructor(e={}){this.version=Py.v2,this.holder=new bo,this.issuer=new Ii,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Oi,this.attributes=[],Object.assign(this,e)}};z([u({type:h.Integer})],Zt.prototype,"version",void 0);z([u({type:bo})],Zt.prototype,"holder",void 0);z([u({type:Ii})],Zt.prototype,"issuer",void 0);z([u({type:M})],Zt.prototype,"signature",void 0);z([u({type:h.Integer,converter:be})],Zt.prototype,"serialNumber",void 0);z([u({type:Oi})],Zt.prototype,"attrCertValidityPeriod",void 0);z([u({type:wt,repeated:"sequence"})],Zt.prototype,"attributes",void 0);z([u({type:h.BitString,optional:!0})],Zt.prototype,"issuerUniqueID",void 0);z([u({type:ir,optional:!0})],Zt.prototype,"extensions",void 0);var Pi=class{constructor(e={}){this.acinfo=new Zt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:Zt})],Pi.prototype,"acinfo",void 0);z([u({type:M})],Pi.prototype,"signatureAlgorithm",void 0);z([u({type:h.BitString})],Pi.prototype,"signatureValue",void 0);var qc;(function(r){r[r.unmarked=1]="unmarked",r[r.unclassified=2]="unclassified",r[r.restricted=4]="restricted",r[r.confidential=8]="confidential",r[r.secret=16]="secret",r[r.topSecret=32]="topSecret"})(qc||(qc={}));var Rs=class extends rn{};var Ds=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier,implicit:!0,context:0})],Ds.prototype,"type",void 0);z([u({type:h.Any,implicit:!0,context:1})],Ds.prototype,"value",void 0);var Gc=class{constructor(e={}){this.policyId="",this.classList=new Rs(qc.unclassified),Object.assign(this,e)}};z([u({type:h.ObjectIdentifier})],Gc.prototype,"policyId",void 0);z([u({type:Rs,defaultValue:new Rs(qc.unclassified)})],Gc.prototype,"classList",void 0);z([u({type:Ds,repeated:"set"})],Gc.prototype,"securityCategories",void 0);var Ls=class{constructor(e={}){Object.assign(this,e)}};z([u({type:ce})],Ls.prototype,"cotets",void 0);z([u({type:h.ObjectIdentifier})],Ls.prototype,"oid",void 0);z([u({type:h.Utf8String})],Ls.prototype,"string",void 0);var Lf=class{constructor(e={}){this.values=[],Object.assign(this,e)}};z([u({type:Ge,implicit:!0,context:0,optional:!0})],Lf.prototype,"policyAuthority",void 0);z([u({type:Ls,repeated:"sequence"})],Lf.prototype,"values",void 0);var bM=`${go}.4`,xM=`${go}.6`,vM=`${go}.10`,AM=`${he}.55`,zc=`${mo}.10`,_M=`${zc}.1`,SM=`${zc}.2`,EM=`${zc}.3`,CM=`${zc}.4`,TM=`${zc}.6`,By="2.5.4",IM=`${By}.72`;var ky,Us=class{constructor(e={}){this.targetCertificate=new mr,Object.assign(this,e)}};z([u({type:mr})],Us.prototype,"targetCertificate",void 0);z([u({type:fe,optional:!0})],Us.prototype,"targetName",void 0);z([u({type:gr,optional:!0})],Us.prototype,"certDigestInfo",void 0);var Ms=class{constructor(e={}){Object.assign(this,e)}};z([u({type:fe,context:0,implicit:!0})],Ms.prototype,"targetName",void 0);z([u({type:fe,context:1,implicit:!0})],Ms.prototype,"targetGroup",void 0);z([u({type:Us,context:2,implicit:!0})],Ms.prototype,"targetCert",void 0);Ms=z([E({type:A.Choice})],Ms);var Uf=ky=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,ky.prototype)}};Uf=ky=z([E({type:A.Sequence,itemType:Ms})],Uf);var Ny,Sx=Ny=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ny.prototype)}};Sx=Ny=z([E({type:A.Sequence,itemType:Uf})],Sx);var Mf=class{constructor(e={}){Object.assign(this,e)}};z([u({type:Ge,implicit:!0,context:0,optional:!0})],Mf.prototype,"roleAuthority",void 0);z([u({type:fe,implicit:!0,context:1})],Mf.prototype,"roleName",void 0);var Xc=class{constructor(e={}){this.service=new fe,this.ident=new fe,Object.assign(this,e)}};z([u({type:fe})],Xc.prototype,"service",void 0);z([u({type:fe})],Xc.prototype,"ident",void 0);z([u({type:ce,optional:!0})],Xc.prototype,"authInfo",void 0);var jy,Yc=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Yc.prototype,"otherCertFormat",void 0);C([u({type:h.Any})],Yc.prototype,"otherCert",void 0);var Bi=class{constructor(e={}){Object.assign(this,e)}};C([u({type:yr})],Bi.prototype,"certificate",void 0);C([u({type:Pi,context:2,implicit:!0})],Bi.prototype,"v2AttrCert",void 0);C([u({type:Yc,context:3,implicit:!0})],Bi.prototype,"other",void 0);Bi=C([E({type:A.Choice})],Bi);var ki=jy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,jy.prototype)}};ki=jy=C([E({type:A.Set,itemType:Bi})],ki);var wr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],wr.prototype,"contentType",void 0);C([u({type:h.Any,context:0})],wr.prototype,"content",void 0);var Ks=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ce})],Ks.prototype,"single",void 0);C([u({type:h.Any})],Ks.prototype,"any",void 0);Ks=C([E({type:A.Choice})],Ks);var Ni=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Ni.prototype,"eContentType",void 0);C([u({type:Ks,context:0,optional:!0})],Ni.prototype,"eContent",void 0);var Zc=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ce,context:0,implicit:!0,optional:!0})],Zc.prototype,"value",void 0);C([u({type:ce,converter:Qb,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Zc.prototype,"constructedValue",void 0);Zc=C([E({type:A.Choice})],Zc);var xo=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Vc,Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],xo.prototype,"contentType",void 0);C([u({type:Vc})],xo.prototype,"contentEncryptionAlgorithm",void 0);C([u({type:Zc,optional:!0})],xo.prototype,"encryptedContent",void 0);var vo=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],vo.prototype,"keyAttrId",void 0);C([u({type:h.Any,optional:!0})],vo.prototype,"keyAttr",void 0);var Ry,Hs=class{constructor(e={}){this.subjectKeyIdentifier=new zt,Object.assign(this,e)}};C([u({type:zt})],Hs.prototype,"subjectKeyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Hs.prototype,"date",void 0);C([u({type:vo,optional:!0})],Hs.prototype,"other",void 0);var Vs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Hs,context:0,implicit:!0,optional:!0})],Vs.prototype,"rKeyId",void 0);C([u({type:Kr,optional:!0})],Vs.prototype,"issuerAndSerialNumber",void 0);Vs=C([E({type:A.Choice})],Vs);var Jc=class{constructor(e={}){this.rid=new Vs,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:Vs})],Jc.prototype,"rid",void 0);C([u({type:ce})],Jc.prototype,"encryptedKey",void 0);var Kf=Ry=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ry.prototype)}};Kf=Ry=C([E({type:A.Sequence,itemType:Jc})],Kf);var Qc=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:M})],Qc.prototype,"algorithm",void 0);C([u({type:h.BitString})],Qc.prototype,"publicKey",void 0);var ji=class{constructor(e={}){Object.assign(this,e)}};C([u({type:zt,context:0,implicit:!0,optional:!0})],ji.prototype,"subjectKeyIdentifier",void 0);C([u({type:Qc,context:1,implicit:!0,optional:!0})],ji.prototype,"originatorKey",void 0);C([u({type:Kr,optional:!0})],ji.prototype,"issuerAndSerialNumber",void 0);ji=C([E({type:A.Choice})],ji);var Rn=class{constructor(e={}){this.version=At.v3,this.originator=new ji,this.keyEncryptionAlgorithm=new Xt,this.recipientEncryptedKeys=new Kf,Object.assign(this,e)}};C([u({type:h.Integer})],Rn.prototype,"version",void 0);C([u({type:ji,context:0})],Rn.prototype,"originator",void 0);C([u({type:ce,context:1,optional:!0})],Rn.prototype,"ukm",void 0);C([u({type:Xt})],Rn.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:Kf})],Rn.prototype,"recipientEncryptedKeys",void 0);var $s=class{constructor(e={}){Object.assign(this,e)}};C([u({type:zt,context:0,implicit:!0})],$s.prototype,"subjectKeyIdentifier",void 0);C([u({type:Kr})],$s.prototype,"issuerAndSerialNumber",void 0);$s=C([E({type:A.Choice})],$s);var Ao=class{constructor(e={}){this.version=At.v0,this.rid=new $s,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],Ao.prototype,"version",void 0);C([u({type:$s})],Ao.prototype,"rid",void 0);C([u({type:Xt})],Ao.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],Ao.prototype,"encryptedKey",void 0);var Ri=class{constructor(e={}){this.keyIdentifier=new ce,Object.assign(this,e)}};C([u({type:ce})],Ri.prototype,"keyIdentifier",void 0);C([u({type:h.GeneralizedTime,optional:!0})],Ri.prototype,"date",void 0);C([u({type:vo,optional:!0})],Ri.prototype,"other",void 0);var _o=class{constructor(e={}){this.version=At.v4,this.kekid=new Ri,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],_o.prototype,"version",void 0);C([u({type:Ri})],_o.prototype,"kekid",void 0);C([u({type:Xt})],_o.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],_o.prototype,"encryptedKey",void 0);var So=class{constructor(e={}){this.version=At.v0,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ce,Object.assign(this,e)}};C([u({type:h.Integer})],So.prototype,"version",void 0);C([u({type:Df,context:0,optional:!0})],So.prototype,"keyDerivationAlgorithm",void 0);C([u({type:Xt})],So.prototype,"keyEncryptionAlgorithm",void 0);C([u({type:ce})],So.prototype,"encryptedKey",void 0);var eu=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],eu.prototype,"oriType",void 0);C([u({type:h.Any})],eu.prototype,"oriValue",void 0);var Dn=class{constructor(e={}){Object.assign(this,e)}};C([u({type:Ao,optional:!0})],Dn.prototype,"ktri",void 0);C([u({type:Rn,context:1,implicit:!0,optional:!0})],Dn.prototype,"kari",void 0);C([u({type:_o,context:2,implicit:!0,optional:!0})],Dn.prototype,"kekri",void 0);C([u({type:So,context:3,implicit:!0,optional:!0})],Dn.prototype,"pwri",void 0);C([u({type:eu,context:4,implicit:!0,optional:!0})],Dn.prototype,"ori",void 0);Dn=C([E({type:A.Choice})],Dn);var Dy,tu=Dy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Dy.prototype)}};tu=Dy=C([E({type:A.Set,itemType:Dn})],tu);var Ly,Ex=`${mo}.16`,TK=`${Ex}.2`,IK=`${Ex}.4`,Fs=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};C([u({type:h.ObjectIdentifier})],Fs.prototype,"otherRevInfoFormat",void 0);C([u({type:h.Any})],Fs.prototype,"otherRevInfo",void 0);var Hf=class{constructor(e={}){this.other=new Fs,Object.assign(this,e)}};C([u({type:Fs,context:1,implicit:!0})],Hf.prototype,"other",void 0);Hf=C([E({type:A.Choice})],Hf);var Ws=Ly=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ly.prototype)}};Ws=Ly=C([E({type:A.Set,itemType:Hf})],Ws);var qs=class{constructor(e={}){Object.assign(this,e)}};C([u({type:ki,context:0,implicit:!0,optional:!0})],qs.prototype,"certs",void 0);C([u({type:Ws,context:1,implicit:!0,optional:!0})],qs.prototype,"crls",void 0);var Uy,My=Uy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Uy.prototype)}};My=Uy=C([E({type:A.Set,itemType:Hr})],My);var Di=class{constructor(e={}){this.version=At.v0,this.recipientInfos=new tu,this.encryptedContentInfo=new xo,Object.assign(this,e)}};C([u({type:h.Integer})],Di.prototype,"version",void 0);C([u({type:qs,context:0,implicit:!0,optional:!0})],Di.prototype,"originatorInfo",void 0);C([u({type:tu})],Di.prototype,"recipientInfos",void 0);C([u({type:xo})],Di.prototype,"encryptedContentInfo",void 0);C([u({type:My,context:1,implicit:!0,optional:!0})],Di.prototype,"unprotectedAttrs",void 0);var Cx="1.2.840.113549.1.7.2";var Ky,Vf=Ky=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Ky.prototype)}};Vf=Ky=C([E({type:A.Set,itemType:Ci})],Vf);var Ln=class{constructor(e={}){this.version=At.v0,this.digestAlgorithms=new Vf,this.encapContentInfo=new Ni,this.signerInfos=new $c,Object.assign(this,e)}};C([u({type:h.Integer})],Ln.prototype,"version",void 0);C([u({type:Vf})],Ln.prototype,"digestAlgorithms",void 0);C([u({type:Ni})],Ln.prototype,"encapContentInfo",void 0);C([u({type:ki,context:0,implicit:!0,optional:!0})],Ln.prototype,"certificates",void 0);C([u({type:Ws,context:1,implicit:!0,optional:!0})],Ln.prototype,"crls",void 0);C([u({type:$c})],Ln.prototype,"signerInfos",void 0);var Li="1.2.840.10045.2.1";var ru="1.2.840.10045.4.1",$f="1.2.840.10045.4.3.1",nu="1.2.840.10045.4.3.2",ou="1.2.840.10045.4.3.3",iu="1.2.840.10045.4.3.4";var Hy="1.2.840.10045.3.1.7";var Vy="1.3.132.0.34";var $y="1.3.132.0.35";function su(r){return new M({algorithm:r})}var Ix=su(ru),SH=su($f),Ox=su(nu),Px=su(ou),Bx=su(iu);function Ue(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var au=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.ObjectIdentifier})],au.prototype,"fieldType",void 0);Ue([u({type:h.Any})],au.prototype,"parameters",void 0);au=Ue([E({type:A.Sequence})],au);var Fy=class extends ce{};var Gs=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.OctetString})],Gs.prototype,"a",void 0);Ue([u({type:h.OctetString})],Gs.prototype,"b",void 0);Ue([u({type:h.BitString,optional:!0})],Gs.prototype,"seed",void 0);Gs=Ue([E({type:A.Sequence})],Gs);var Wy;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Wy||(Wy={}));var an=class{constructor(e={}){this.version=Wy.ecpVer1,Object.assign(this,e)}};Ue([u({type:h.Integer})],an.prototype,"version",void 0);Ue([u({type:au})],an.prototype,"fieldID",void 0);Ue([u({type:Gs})],an.prototype,"curve",void 0);Ue([u({type:Fy})],an.prototype,"base",void 0);Ue([u({type:h.Integer,converter:be})],an.prototype,"order",void 0);Ue([u({type:h.Integer,optional:!0})],an.prototype,"cofactor",void 0);an=Ue([E({type:A.Sequence})],an);var cn=class{constructor(e={}){Object.assign(this,e)}};Ue([u({type:h.ObjectIdentifier})],cn.prototype,"namedCurve",void 0);Ue([u({type:h.Null})],cn.prototype,"implicitCurve",void 0);Ue([u({type:an})],cn.prototype,"specifiedCurve",void 0);cn=Ue([E({type:A.Choice})],cn);var zs=class{constructor(e={}){this.version=1,this.privateKey=new ce,Object.assign(this,e)}};Ue([u({type:h.Integer})],zs.prototype,"version",void 0);Ue([u({type:ce})],zs.prototype,"privateKey",void 0);Ue([u({type:cn,context:0,optional:!0})],zs.prototype,"parameters",void 0);Ue([u({type:h.BitString,context:1,optional:!0})],zs.prototype,"publicKey",void 0);var Ui=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Ue([u({type:h.Integer,converter:be})],Ui.prototype,"r",void 0);Ue([u({type:h.Integer,converter:be})],Ui.prototype,"s",void 0);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 Jt="1.2.840.113549.1.1",un=`${Jt}.1`,kx=`${Jt}.7`,Nx=`${Jt}.9`,Eo=`${Jt}.10`,jx=`${Jt}.2`,Rx=`${Jt}.4`,Xs=`${Jt}.5`,Dx=`${Jt}.14`;var Ff=`${Jt}.11`,Ys=`${Jt}.12`,Zs=`${Jt}.13`,qy=`${Jt}.15`,Gy=`${Jt}.16`,Mi="1.3.14.3.2.26",Wf="2.16.840.1.101.3.4.2.4",Ki="2.16.840.1.101.3.4.2.1",Hi="2.16.840.1.101.3.4.2.2",Vi="2.16.840.1.101.3.4.2.3",Lx="2.16.840.1.101.3.4.2.5",Ux="2.16.840.1.101.3.4.2.6",Mx="1.2.840.113549.2.2",Kx="1.2.840.113549.2.5",Co=`${Jt}.8`;function pt(r){return new M({algorithm:r,parameters:null})}var e7=pt(Mx),t7=pt(Kx),Un=pt(Mi),r7=pt(Wf),n7=pt(Ki),o7=pt(Hi),i7=pt(Vi),s7=pt(Lx),a7=pt(Ux),qf=new M({algorithm:Co,parameters:G.serialize(Un)}),zy=new M({algorithm:Nx,parameters:G.serialize(Os.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),c7=pt(un),u7=pt(jx),l7=pt(Rx),f7=pt(Xs),p7=pt(qy),h7=pt(Gy),d7=pt(Ys),y7=pt(Zs),m7=pt(qy),g7=pt(Gy);var Js=class{constructor(e={}){this.hashAlgorithm=new M(Un),this.maskGenAlgorithm=new M({algorithm:Co,parameters:G.serialize(Un)}),this.pSourceAlgorithm=new M(zy),Object.assign(this,e)}};ke([u({type:M,context:0,defaultValue:Un})],Js.prototype,"hashAlgorithm",void 0);ke([u({type:M,context:1,defaultValue:qf})],Js.prototype,"maskGenAlgorithm",void 0);ke([u({type:M,context:2,defaultValue:zy})],Js.prototype,"pSourceAlgorithm",void 0);var S7=new M({algorithm:kx,parameters:G.serialize(new Js)});var ln=class{constructor(e={}){this.hashAlgorithm=new M(Un),this.maskGenAlgorithm=new M({algorithm:Co,parameters:G.serialize(Un)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};ke([u({type:M,context:0,defaultValue:Un})],ln.prototype,"hashAlgorithm",void 0);ke([u({type:M,context:1,defaultValue:qf})],ln.prototype,"maskGenAlgorithm",void 0);ke([u({type:h.Integer,context:2,defaultValue:20})],ln.prototype,"saltLength",void 0);ke([u({type:h.Integer,context:3,defaultValue:1})],ln.prototype,"trailerField",void 0);var B7=new M({algorithm:Eo,parameters:G.serialize(new ln)});var $i=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ce,Object.assign(this,e)}};ke([u({type:M})],$i.prototype,"digestAlgorithm",void 0);ke([u({type:ce})],$i.prototype,"digest",void 0);var Xy,Qs=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer,converter:be})],Qs.prototype,"prime",void 0);ke([u({type:h.Integer,converter:be})],Qs.prototype,"exponent",void 0);ke([u({type:h.Integer,converter:be})],Qs.prototype,"coefficient",void 0);var Gf=Xy=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Xy.prototype)}};Gf=Xy=ke([E({type:A.Sequence,itemType:Qs})],Gf);var br=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)}};ke([u({type:h.Integer})],br.prototype,"version",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"modulus",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"publicExponent",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"privateExponent",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"prime1",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"prime2",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"exponent1",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"exponent2",void 0);ke([u({type:h.Integer,converter:be})],br.prototype,"coefficient",void 0);ke([u({type:Gf,optional:!0})],br.prototype,"otherPrimeInfos",void 0);var ea=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};ke([u({type:h.Integer,converter:be})],ea.prototype,"modulus",void 0);ke([u({type:h.Integer,converter:be})],ea.prototype,"publicExponent",void 0);function cu(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var Yy;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(Yy||(Yy={}));var _t=Yy;var cv=Fr(av(),1),{__extends:ra,__assign:uV,__rest:Q2,__decorate:lV,__param:fV,__metadata:pV,__awaiter:uv,__generator:lv,__exportStar:hV,__createBinding:dV,__values:uu,__read:lu,__spread:Vr,__spreadArrays:yV,__await:mV,__asyncGenerator:gV,__asyncDelegator:wV,__asyncValues:bV,__makeTemplateObject:xV,__importStar:vV,__importDefault:AV,__classPrivateFieldGet:_V,__classPrivateFieldSet:SV}=cv.default;var eC="injectionTokens";function Jy(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(eC,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function fu(r){return!!r.useClass}function na(r){return!!r.useFactory}var Yf=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,Vr(i))}};return this.reflectMethods.forEach(n),t},r}();function To(r){return typeof r=="string"||typeof r=="symbol"}function Qy(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Zf(r){return typeof r=="object"&&"token"in r&&"transform"in r}function fv(r){return typeof r=="function"||r instanceof Yf}function Fi(r){return!!r.useToken}function Wi(r){return r.useValue!=null}function pv(r){return fu(r)||Wi(r)||Fi(r)||na(r)}var tC=function(){function r(){this._registryMap=new Map}return r.prototype.entries=function(){return this._registryMap.entries()},r.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},r.prototype.get=function(e){this.ensure(e);var t=this._registryMap.get(e);return t[t.length-1]||null},r.prototype.set=function(e,t){this.ensure(e),this._registryMap.get(e).push(t)},r.prototype.setAll=function(e,t){this._registryMap.set(e,t)},r.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},r.prototype.clear=function(){this._registryMap.clear()},r.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},r}(),pu=tC;var rC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu),hv=rC;var nC=function(){function r(){this.scopedResolutions=new Map}return r}(),hu=nC;function oC(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function iC(r,e,t){return t===void 0&&(t=" "),Vr([r],e.message.split(`
7
7
  `).map(function(n){return t+n})).join(`
8
- `)}function Qy(r,e,t){var n=au(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=J2(i,e);return Q2("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 eC=function(r){ea(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(uu);var tC=function(r){ea(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(uu);var rC=function(){function r(){this.preResolution=new eC,this.postResolution=new tC}return r}(),hv=rC;var em=new Map,nC=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:_t.Transient}),this.ensureNotDisposed();var o;if(lv(t)?o=t:o={useClass:t},Fi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Hr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Fi(c.provider)?s=c.provider:s=null}if((n.lifecycle===_t.Singleton||n.lifecycle==_t.ContainerScoped||n.lifecycle==_t.ResolutionScoped)&&(Wi(o)||ta(o)))throw new Error('Cannot use lifecycle "'+_t[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:o,options:n}),this},r.prototype.registerType=function(e,t){return this.ensureNotDisposed(),To(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},r.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},r.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),To(e)){if(To(t))return this.register(e,{useToken:t},{lifecycle:_t.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:_t.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!To(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:_t.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new lu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&To(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),o){var i=this.resolveRegistration(o,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(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=su(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=su(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===_t.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===_t.Singleton,o=e.options.lifecycle===_t.ContainerScoped,i=n||o,s;return Wi(e.provider)?s=e.provider.useValue:Fi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):cu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):ta(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===_t.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new lu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&To(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=su(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=au(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Wi(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=su(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=au(i.value,2),a=s[0],c=s[1];c.some(function(l){var p=l.options;return p.lifecycle===_t.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===_t.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 zf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=em.get(e);if(!i||i.length===0){if(e.length===0)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var s=i.map(n.resolveParams(t,e));return new(e.bind.apply(e,Hr([void 0],s)))}();return 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 Jy(o)?Xf(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Hr([n.resolveAll(o.token,new lu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Hr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new lu,o.isOptional):n.resolve(o.token,e,o.isOptional):Xf(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Hr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(Qy(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}(),Ve=new nC;function oC(r){return function(e){em.set(e,Zy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Ve.register(t,e)}):Ve.register(r.token,e))}}var Io=oC;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 Ie(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 Oe(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var rm,qi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Oe([u({type:h.ObjectIdentifier})],qi.prototype,"attrId",void 0);Oe([u({type:h.Any,repeated:"set"})],qi.prototype,"attrValues",void 0);var dv=rm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,rm.prototype)}};dv=rm=Oe([E({type:A.Sequence,itemType:qi})],dv);var nm,yv=nm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};yv=nm=Oe([E({type:A.Sequence,itemType:gr})],yv);var iC="1.2.840.113549",sC=`${iC}.1`,mv=`${sC}.12`,ra=`${mv}.1`,PF=`${ra}.1`,BF=`${ra}.2`,kF=`${ra}.3`,NF=`${ra}.4`,jF=`${ra}.5`,RF=`${ra}.6`,Gi=`${mv}.10.1`;var UF=`${Gi}.1`,MF=`${Gi}.2`,KF=`${Gi}.3`,HF=`${Gi}.4`,VF=`${Gi}.5`,$F=`${Gi}.6`,Yf="1.2.840.113549.1.9";var Zf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],Zf.prototype,"certId",void 0);Oe([u({type:h.Any,context:0})],Zf.prototype,"certValue",void 0);var gv=`${Yf}.22`,zF=`${gv}.1`,XF=`${gv}.2`;var Jf=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],Jf.prototype,"crlId",void 0);Oe([u({type:h.Any,context:0})],Jf.prototype,"crltValue",void 0);var aC=`${Yf}.23`,eW=`${aC}.1`;function Un(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 Qf=class extends ce{},Oo=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Qf,Object.assign(this,e)}};Un([u({type:M})],Oo.prototype,"encryptionAlgorithm",void 0);Un([u({type:Qf})],Oo.prototype,"encryptedData",void 0);var om,im;(function(r){r[r.v1=0]="v1"})(im||(im={}));var ep=class extends ce{},sm=om=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};sm=om=Un([E({type:A.Sequence,itemType:wt})],sm);var Po=class{constructor(e={}){this.version=im.v1,this.privateKeyAlgorithm=new M,this.privateKey=new ep,Object.assign(this,e)}};Un([u({type:h.Integer})],Po.prototype,"version",void 0);Un([u({type:M})],Po.prototype,"privateKeyAlgorithm",void 0);Un([u({type:ep})],Po.prototype,"privateKey",void 0);Un([u({type:sm,implicit:!0,context:0,optional:!0})],Po.prototype,"attributes",void 0);var wv=class extends Po{};wv=Oe([E({type:A.Sequence})],wv);var bv=class extends Oo{};bv=Oe([E({type:A.Sequence})],bv);var tp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],tp.prototype,"secretTypeId",void 0);Oe([u({type:h.Any,context:0})],tp.prototype,"secretValue",void 0);var Bo=class{constructor(e={}){this.mac=new $i,this.macSalt=new ce,this.iterations=1,Object.assign(this,e)}};Oe([u({type:$i})],Bo.prototype,"mac",void 0);Oe([u({type:ce})],Bo.prototype,"macSalt",void 0);Oe([u({type:h.Integer,defaultValue:1})],Bo.prototype,"iterations",void 0);var zi=class{constructor(e={}){this.version=3,this.authSafe=new gr,this.macData=new Bo,Object.assign(this,e)}};Oe([u({type:h.Integer})],zi.prototype,"version",void 0);Oe([u({type:gr})],zi.prototype,"authSafe",void 0);Oe([u({type:Bo,optional:!0})],zi.prototype,"macData",void 0);var am,na=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],na.prototype,"bagId",void 0);Oe([u({type:h.Any,context:0})],na.prototype,"bagValue",void 0);Oe([u({type:qi,repeated:"set",optional:!0})],na.prototype,"bagAttributes",void 0);var xv=am=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,am.prototype)}};xv=am=Oe([E({type:A.Sequence,itemType:na})],xv);var cm,um,lm,Je="1.2.840.113549.1.9",nq=`${Je}.0`,jv=`${Je}.24`,pu=`${Je}.25`,Rv=`${Je}.26`,Dv=`${Je}.27`,oq=`${jv}.1`,iq=`${jv}.2`,sq=`${Je}.1`,aq=`${Je}.2`,cq=`${Je}.3`,uq=`${Je}.4`,lq=`${Je}.5`,fq=`${Je}.6`,wm=`${Je}.7`,pq=`${Je}.8`,hq=`${Je}.9`,dq=`${Je}.13`,hu=`${Je}.14`,yq=`${Je}.15`,mq=`${Je}.20`,gq=`${Je}.21`;var wq=`${pu}.1`,bq=`${pu}.2`,xq=`${pu}.3`,vq=`${pu}.4`,Aq=`${pu}.5`,du="1.3.6.1.5.5.7.9",_q=`${du}.1`,Sq=`${du}.2`,Eq=`${du}.3`,Cq=`${du}.4`,Tq=`${du}.5`,Iq=`${Rv}.1`,Oq=`${Rv}.2`,Pq=`${Dv}.1`,Bq=`${Dv}.2`,kq=`${Je}.16`,Nq=`${Je}.22`,jq=`${Je}.23`,Rq=`${Py}.65`,rp=class extends it{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Ie([u({type:h.IA5String})],rp.prototype,"ia5String",void 0);rp=Ie([E({type:A.Choice})],rp);var vv=class extends gr{};vv=Ie([E({type:A.Sequence})],vv);var Av=class extends zi{};Av=Ie([E({type:A.Sequence})],Av);var _v=class extends Oo{};_v=Ie([E({type:A.Sequence})],_v);var fm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.IA5String})],fm.prototype,"value",void 0);fm=Ie([E({type:A.Choice})],fm);var Sv=class extends rp{};Sv=Ie([E({type:A.Choice})],Sv);var Ev=class extends it{};Ev=Ie([E({type:A.Choice})],Ev);var pm=class{constructor(e=new Date){this.value=e}};Ie([u({type:h.GeneralizedTime})],pm.prototype,"value",void 0);pm=Ie([E({type:A.Choice})],pm);var Cv=class extends it{};Cv=Ie([E({type:A.Choice})],Cv);var hm=class{constructor(e="M"){this.value=e}toString(){return this.value}};Ie([u({type:h.PrintableString})],hm.prototype,"value",void 0);hm=Ie([E({type:A.Choice})],hm);var np=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.PrintableString})],np.prototype,"value",void 0);np=Ie([E({type:A.Choice})],np);var Tv=class extends np{};Tv=Ie([E({type:A.Choice})],Tv);var Iv=class extends it{};Iv=Ie([E({type:A.Choice})],Iv);var dm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.ObjectIdentifier})],dm.prototype,"value",void 0);dm=Ie([E({type:A.Choice})],dm);var Ov=class extends Ze{};Ov=Ie([E({type:A.Choice})],Ov);var ym=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Ie([u({type:h.Integer})],ym.prototype,"value",void 0);ym=Ie([E({type:A.Choice})],ym);var Pv=class extends Xt{};Pv=Ie([E({type:A.Sequence})],Pv);var fu=class extends it{};fu=Ie([E({type:A.Choice})],fu);var Bv=cm=class extends or{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};Bv=cm=Ie([E({type:A.Sequence})],Bv);var kv=um=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};kv=um=Ie([E({type:A.Set,itemType:Kr})],kv);var mm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.BmpString})],mm.prototype,"value",void 0);mm=Ie([E({type:A.Choice})],mm);var gm=class extends M{};gm=Ie([E({type:A.Sequence})],gm);var Nv=lm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};Nv=lm=Ie([E({type:A.Sequence,itemType:gm})],Nv);function Vr(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var bm,yu=bm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,bm.prototype)}};yu=bm=Vr([E({type:A.Sequence,itemType:wt})],yu);var ln=class{constructor(e={}){this.version=0,this.subject=new Le,this.subjectPKInfo=new bt,this.attributes=new yu,Object.assign(this,e)}};Vr([u({type:h.Integer})],ln.prototype,"version",void 0);Vr([u({type:Le})],ln.prototype,"subject",void 0);Vr([u({type:bt})],ln.prototype,"subjectPKInfo",void 0);Vr([u({type:yu,implicit:!0,context:0})],ln.prototype,"attributes",void 0);var ko=class{constructor(e={}){this.certificationRequestInfo=new ln,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Vr([u({type:ln})],ko.prototype,"certificationRequestInfo",void 0);Vr([u({type:M})],ko.prototype,"signatureAlgorithm",void 0);Vr([u({type:h.BitString})],ko.prototype,"signature",void 0);var vu="crypto.algorithm",Om=class{getAlgorithms(){return Ve.resolveAll(vu)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Xi="crypto.algorithmProvider";Ve.registerSingleton(Xi,Om);var ap,er="1.3.36.3.3.2.8.1.1",Lv=`${er}.1`,Uv=`${er}.2`,Mv=`${er}.3`,Kv=`${er}.4`,Hv=`${er}.5`,Vv=`${er}.6`,$v=`${er}.7`,Fv=`${er}.8`,Wv=`${er}.9`,qv=`${er}.10`,Gv=`${er}.11`,zv=`${er}.12`,Xv=`${er}.13`,Yv=`${er}.14`,Zv="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",ze="ECDSA",gu=ap=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case ze.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Cx;case"sha-256":return Tx;case"sha-384":return Ix;case"sha-512":return Ox}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Ky;break;case"K-256":t=ap.SECP256K1;break;case"P-384":t=Hy;break;case"P-521":t=Vy;break;case Zv: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=Yv;break}if(t)return new M({algorithm:Li,parameters:G.serialize(new an({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Qc:return{name:ze,hash:{name:"SHA-1"}};case eu:return{name:ze,hash:{name:"SHA-256"}};case tu:return{name:ze,hash:{name:"SHA-384"}};case ru:return{name:ze,hash:{name:"SHA-512"}};case Li:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(G.parse(e.parameters,an).namedCurve){case Ky:return{name:ze,namedCurve:"P-256"};case ap.SECP256K1:return{name:ze,namedCurve:"K-256"};case Hy:return{name:ze,namedCurve:"P-384"};case Vy:return{name:ze,namedCurve:"P-521"};case Lv:return{name:ze,namedCurve:Zv};case Uv:return{name:ze,namedCurve:Jv};case Mv:return{name:ze,namedCurve:Qv};case Kv:return{name:ze,namedCurve:e1};case Hv:return{name:ze,namedCurve:t1};case Vv:return{name:ze,namedCurve:r1};case $v:return{name:ze,namedCurve:n1};case Fv:return{name:ze,namedCurve:o1};case Wv:return{name:ze,namedCurve:i1};case qv:return{name:ze,namedCurve:s1};case Gv:return{name:ze,namedCurve:a1};case zv:return{name:ze,namedCurve:c1};case Xv:return{name:ze,namedCurve:u1};case Yv:return{name:ze,namedCurve:l1}}}}return null}};gu.SECP256K1="1.3.132.0.10";gu=ap=iu([Io()],gu);Ve.registerSingleton(vu,gu);var v1=Symbol("name"),A1=Symbol("value"),Ee=class{constructor(e,t={},n=""){this[v1]=e,this[A1]=n;for(let o in t)this[o]=t[o]}};Ee.NAME=v1;Ee.VALUE=A1;var Pm=class{static toTextObject(e){let t=new Ee("Algorithm Identifier",{},pn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Li:{let n=new gu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},pn=class{static toString(e){let t=this.items[e];return t||e}};pn.items={[Mi]:"sha1",[$f]:"sha224",[Ki]:"sha256",[Hi]:"sha384",[Vi]:"sha512",[cn]:"rsaEncryption",[Gs]:"sha1WithRSAEncryption",[jx]:"sha224WithRSAEncryption",[Vf]:"sha256WithRSAEncryption",[zs]:"sha384WithRSAEncryption",[Xs]:"sha512WithRSAEncryption",[Li]:"ecPublicKey",[Qc]:"ecdsaWithSHA1",[Hf]:"ecdsaWithSHA224",[eu]:"ecdsaWithSHA256",[tu]:"ecdsaWithSHA384",[ru]:"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 Kn=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[Ee.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Ee.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[Ee.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof Ee)c[Ee.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[Ee.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)}};Kn.oidSerializer=pn;Kn.algorithmSerializer=Pm;var No=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=G.serialize(t),this.onInit(t)}else{let t=G.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 G.toString(this.rawData);case"text":return Kn.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 Ee(this.getTextName(),{},e)}};No.NAME="ASN";var xr=class r extends No{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=G.serialize(new xt({extnID:e[0],critical:e[1],extnValue:new ce(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,xt)}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[Ee.NAME]===r.NAME&&(e[Ee.NAME]=pn.toString(this.type)),e}},_1,wu=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[_1]="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}};_1=Symbol.toStringTag;wu.DEFAULT="default";var St=new wu,fC=/^[0-2](?:\.[1-9][0-9]*)+$/;function pC(r){return new RegExp(fC).test(r)}var up=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 pC(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Jt=new up;Jt.register("CN","2.5.4.3");Jt.register("L","2.5.4.7");Jt.register("ST","2.5.4.8");Jt.register("O","2.5.4.10");Jt.register("OU","2.5.4.11");Jt.register("C","2.5.4.6");Jt.register("DC","0.9.2342.19200300.100.1.25");Jt.register("E","1.2.840.113549.1.9.1");Jt.register("G","2.5.4.42");Jt.register("I","2.5.4.43");Jt.register("SN","2.5.4.4");Jt.register("T","2.5.4.12");function hC(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function dC(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,hC)}var br=class r{static isASCII(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new up,this.asn=new Le;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 Le?this.asn=e:V.BufferSourceConverter.isBufferSource(e)?this.asn=G.parse(e,Le):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Jt.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)||Jt.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)}`:dC(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 Le,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 ho([p])),i=l}return t}fromJSON(e){let t=new Le;for(let n of e){let o=new ho;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 gi({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 G.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]||St.get()):n=e[0]||St.get(),await n.subtle.digest(o,this.toArrayBuffer())}},S1="Cannot initialize GeneralName from ASN.1 data.",f1=`${S1} Unsupported string format in use.`,yC=`${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",xm="dns",vm="dn",Am="email",_m="ip",Sm="url",Em="guid",Cm="upn",op="id",fn=class extends No{constructor(...e){let t;if(e.length===2)switch(e[0]){case vm:{let n=new br(e[1]).toArrayBuffer(),o=G.parse(n,Le);t=new le({directoryName:o});break}case xm:t=new le({dNSName:e[1]});break;case Am:t=new le({rfc822Name:e[1]});break;case Em:{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 yo({typeId:h1,value:G.serialize(new ce(V.Convert.FromHex(o)))})});break}case _m:t=new le({iPAddress:e[1]});break;case op:t=new le({registeredID:e[1]});break;case Cm:{t=new le({otherName:new yo({typeId:d1,value:G.serialize(Zd.toASN(e[1]))})});break}case Sm: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=G.parse(e[0],le):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=xm,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=Am,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=_m,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Sm,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=op,this.value=e.registeredID;else if(e.directoryName!=null)this.type=vm,this.value=new br(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===h1){this.type=Em;let t=G.parse(e.otherName.value,ce),n=new RegExp(p1,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(yC);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=Cm,this.value=G.parse(e.otherName.value,it).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 vm:case xm:case Em:case _m:case op:case Cm:case Sm:e=this.type.toUpperCase();break;case Am:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===op&&(t=pn.toString(t)),new Ee(e,void 0,t)}},Yi=class extends No{constructor(e){let t;if(e instanceof Ge)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof le)n.push(o);else{let i=G.parse(new fn(o.type,o.value).rawData,le);n.push(i)}t=new Ge(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=G.parse(e,Ge);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new fn(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[Ee.NAME]];Array.isArray(o)||(o=[],e[n[Ee.NAME]]=o),o.push(n)}return e}};Yi.NAME="GeneralNames";var mu="-{5}",bu="\\n",mC=`[^${bu}]+`,gC=`${mu}BEGIN (${mC}(?=${mu}))${mu}`,wC=`${mu}END \\1${mu}`,oa="\\n",bC=`[^:${bu}]+`,xC=`(?:[^${bu}]+${oa}(?: +[^${bu}]+${oa})*)`,vC="[a-zA-Z0-9=+/]+",AC=`(?:${vC}${oa})+`,y1=`${gC}${oa}(?:((?:${bC}: ${xC})+))?${oa}?(${AC})${wC}`,Ht=class{static isPem(e){return typeof e=="string"&&new RegExp(y1,"g").test(e)}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(`[${bu}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(oa,"g")),l=null;for(let p of c){let[f,d]=p.split(/:(.*)/);if(d===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:d.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(`
8
+ `)}function em(r,e,t){var n=lu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=oC(i,e);return iC("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function dv(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var sC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu);var aC=function(r){ra(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e}(pu);var cC=function(){function r(){this.preResolution=new sC,this.postResolution=new aC}return r}(),yv=cC;var tm=new Map,uC=function(){function r(e){this.parent=e,this._registry=new hv,this.interceptors=new yv,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:_t.Transient}),this.ensureNotDisposed();var o;if(pv(t)?o=t:o={useClass:t},Fi(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Vr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&Fi(c.provider)?s=c.provider:s=null}if((n.lifecycle===_t.Singleton||n.lifecycle==_t.ContainerScoped||n.lifecycle==_t.ResolutionScoped)&&(Wi(o)||na(o)))throw new Error('Cannot use lifecycle "'+_t[n.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:o,options:n}),this},r.prototype.registerType=function(e,t){return this.ensureNotDisposed(),To(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},r.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},r.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),To(e)){if(To(t))return this.register(e,{useToken:t},{lifecycle:_t.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:_t.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!To(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:_t.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new hu),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&To(e)){if(n)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),o){var i=this.resolveRegistration(o,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}if(fv(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=uu(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(l){n={error:l}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=uu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var l=c.value;l.options.frequency!="Once"&&s.push(l),l.callback(e,t,n)}}catch(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===_t.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===_t.Singleton,o=e.options.lifecycle===_t.ContainerScoped,i=n||o,s;return Wi(e.provider)?s=e.provider.useValue:Fi(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):fu(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):na(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===_t.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new hu),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&To(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=uu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=lu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!Wi(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=uu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=lu(i.value,2),a=s[0],c=s[1];c.some(function(l){var p=l.options;return p.lifecycle===_t.ContainerScoped})&&n._registry.setAll(a,c.map(function(l){return l.options.lifecycle===_t.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 uv(this,void 0,void 0,function(){var e;return lv(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 Yf)return e.createProxy(function(i){return n.resolve(i,t)});var o=function(){var i=tm.get(e);if(!i||i.length===0){if(e.length===0)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var s=i.map(n.resolveParams(t,e));return new(e.bind.apply(e,Vr([void 0],s)))}();return dv(o)&&this.disposables.add(o),o},r.prototype.resolveParams=function(e,t){var n=this;return function(o,i){var s,a,c;try{return Qy(o)?Zf(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Vr([n.resolveAll(o.token,new hu,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Vr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new hu,o.isOptional):n.resolve(o.token,e,o.isOptional):Zf(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Vr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(l){throw new Error(em(t,i,l))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r}(),Ve=new uC;function lC(r){return function(e){tm.set(e,Jy(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){Ve.register(t,e)}):Ve.register(r.token,e))}}var Io=lC;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 Ie(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 Oe(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var nm,qi=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Oe([u({type:h.ObjectIdentifier})],qi.prototype,"attrId",void 0);Oe([u({type:h.Any,repeated:"set"})],qi.prototype,"attrValues",void 0);var mv=nm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,nm.prototype)}};mv=nm=Oe([E({type:A.Sequence,itemType:qi})],mv);var om,gv=om=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,om.prototype)}};gv=om=Oe([E({type:A.Sequence,itemType:wr})],gv);var fC="1.2.840.113549",pC=`${fC}.1`,wv=`${pC}.12`,oa=`${wv}.1`,LF=`${oa}.1`,UF=`${oa}.2`,MF=`${oa}.3`,KF=`${oa}.4`,HF=`${oa}.5`,VF=`${oa}.6`,Gi=`${wv}.10.1`;var WF=`${Gi}.1`,qF=`${Gi}.2`,GF=`${Gi}.3`,zF=`${Gi}.4`,XF=`${Gi}.5`,YF=`${Gi}.6`,Jf="1.2.840.113549.1.9";var Qf=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],Qf.prototype,"certId",void 0);Oe([u({type:h.Any,context:0})],Qf.prototype,"certValue",void 0);var bv=`${Jf}.22`,tW=`${bv}.1`,rW=`${bv}.2`;var ep=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],ep.prototype,"crlId",void 0);Oe([u({type:h.Any,context:0})],ep.prototype,"crltValue",void 0);var hC=`${Jf}.23`,aW=`${hC}.1`;function Mn(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 tp=class extends ce{},Oo=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new tp,Object.assign(this,e)}};Mn([u({type:M})],Oo.prototype,"encryptionAlgorithm",void 0);Mn([u({type:tp})],Oo.prototype,"encryptedData",void 0);var im,sm;(function(r){r[r.v1=0]="v1"})(sm||(sm={}));var rp=class extends ce{},am=im=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,im.prototype)}};am=im=Mn([E({type:A.Sequence,itemType:wt})],am);var Po=class{constructor(e={}){this.version=sm.v1,this.privateKeyAlgorithm=new M,this.privateKey=new rp,Object.assign(this,e)}};Mn([u({type:h.Integer})],Po.prototype,"version",void 0);Mn([u({type:M})],Po.prototype,"privateKeyAlgorithm",void 0);Mn([u({type:rp})],Po.prototype,"privateKey",void 0);Mn([u({type:am,implicit:!0,context:0,optional:!0})],Po.prototype,"attributes",void 0);var xv=class extends Po{};xv=Oe([E({type:A.Sequence})],xv);var vv=class extends Oo{};vv=Oe([E({type:A.Sequence})],vv);var np=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],np.prototype,"secretTypeId",void 0);Oe([u({type:h.Any,context:0})],np.prototype,"secretValue",void 0);var Bo=class{constructor(e={}){this.mac=new $i,this.macSalt=new ce,this.iterations=1,Object.assign(this,e)}};Oe([u({type:$i})],Bo.prototype,"mac",void 0);Oe([u({type:ce})],Bo.prototype,"macSalt",void 0);Oe([u({type:h.Integer,defaultValue:1})],Bo.prototype,"iterations",void 0);var zi=class{constructor(e={}){this.version=3,this.authSafe=new wr,this.macData=new Bo,Object.assign(this,e)}};Oe([u({type:h.Integer})],zi.prototype,"version",void 0);Oe([u({type:wr})],zi.prototype,"authSafe",void 0);Oe([u({type:Bo,optional:!0})],zi.prototype,"macData",void 0);var cm,ia=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Oe([u({type:h.ObjectIdentifier})],ia.prototype,"bagId",void 0);Oe([u({type:h.Any,context:0})],ia.prototype,"bagValue",void 0);Oe([u({type:qi,repeated:"set",optional:!0})],ia.prototype,"bagAttributes",void 0);var Av=cm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};Av=cm=Oe([E({type:A.Sequence,itemType:ia})],Av);var um,lm,fm,Je="1.2.840.113549.1.9",lq=`${Je}.0`,Dv=`${Je}.24`,yu=`${Je}.25`,Lv=`${Je}.26`,Uv=`${Je}.27`,fq=`${Dv}.1`,pq=`${Dv}.2`,hq=`${Je}.1`,dq=`${Je}.2`,yq=`${Je}.3`,mq=`${Je}.4`,gq=`${Je}.5`,wq=`${Je}.6`,bm=`${Je}.7`,bq=`${Je}.8`,xq=`${Je}.9`,vq=`${Je}.13`,mu=`${Je}.14`,Aq=`${Je}.15`,_q=`${Je}.20`,Sq=`${Je}.21`;var Eq=`${yu}.1`,Cq=`${yu}.2`,Tq=`${yu}.3`,Iq=`${yu}.4`,Oq=`${yu}.5`,gu="1.3.6.1.5.5.7.9",Pq=`${gu}.1`,Bq=`${gu}.2`,kq=`${gu}.3`,Nq=`${gu}.4`,jq=`${gu}.5`,Rq=`${Lv}.1`,Dq=`${Lv}.2`,Lq=`${Uv}.1`,Uq=`${Uv}.2`,Mq=`${Je}.16`,Kq=`${Je}.22`,Hq=`${Je}.23`,Vq=`${By}.65`,op=class extends it{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Ie([u({type:h.IA5String})],op.prototype,"ia5String",void 0);op=Ie([E({type:A.Choice})],op);var _v=class extends wr{};_v=Ie([E({type:A.Sequence})],_v);var Sv=class extends zi{};Sv=Ie([E({type:A.Sequence})],Sv);var Ev=class extends Oo{};Ev=Ie([E({type:A.Sequence})],Ev);var pm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.IA5String})],pm.prototype,"value",void 0);pm=Ie([E({type:A.Choice})],pm);var Cv=class extends op{};Cv=Ie([E({type:A.Choice})],Cv);var Tv=class extends it{};Tv=Ie([E({type:A.Choice})],Tv);var hm=class{constructor(e=new Date){this.value=e}};Ie([u({type:h.GeneralizedTime})],hm.prototype,"value",void 0);hm=Ie([E({type:A.Choice})],hm);var Iv=class extends it{};Iv=Ie([E({type:A.Choice})],Iv);var dm=class{constructor(e="M"){this.value=e}toString(){return this.value}};Ie([u({type:h.PrintableString})],dm.prototype,"value",void 0);dm=Ie([E({type:A.Choice})],dm);var ip=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.PrintableString})],ip.prototype,"value",void 0);ip=Ie([E({type:A.Choice})],ip);var Ov=class extends ip{};Ov=Ie([E({type:A.Choice})],Ov);var Pv=class extends it{};Pv=Ie([E({type:A.Choice})],Pv);var ym=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.ObjectIdentifier})],ym.prototype,"value",void 0);ym=Ie([E({type:A.Choice})],ym);var Bv=class extends Ze{};Bv=Ie([E({type:A.Choice})],Bv);var mm=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Ie([u({type:h.Integer})],mm.prototype,"value",void 0);mm=Ie([E({type:A.Choice})],mm);var kv=class extends Yt{};kv=Ie([E({type:A.Sequence})],kv);var du=class extends it{};du=Ie([E({type:A.Choice})],du);var Nv=um=class extends ir{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};Nv=um=Ie([E({type:A.Sequence})],Nv);var jv=lm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,lm.prototype)}};jv=lm=Ie([E({type:A.Set,itemType:Hr})],jv);var gm=class{constructor(e=""){this.value=e}toString(){return this.value}};Ie([u({type:h.BmpString})],gm.prototype,"value",void 0);gm=Ie([E({type:A.Choice})],gm);var wm=class extends M{};wm=Ie([E({type:A.Sequence})],wm);var Rv=fm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};Rv=fm=Ie([E({type:A.Sequence,itemType:wm})],Rv);function $r(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}var xm,wu=xm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};wu=xm=$r([E({type:A.Sequence,itemType:wt})],wu);var fn=class{constructor(e={}){this.version=0,this.subject=new Le,this.subjectPKInfo=new bt,this.attributes=new wu,Object.assign(this,e)}};$r([u({type:h.Integer})],fn.prototype,"version",void 0);$r([u({type:Le})],fn.prototype,"subject",void 0);$r([u({type:bt})],fn.prototype,"subjectPKInfo",void 0);$r([u({type:wu,implicit:!0,context:0})],fn.prototype,"attributes",void 0);var ko=class{constructor(e={}){this.certificationRequestInfo=new fn,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};$r([u({type:fn})],ko.prototype,"certificationRequestInfo",void 0);$r([u({type:M})],ko.prototype,"signatureAlgorithm",void 0);$r([u({type:h.BitString})],ko.prototype,"signature",void 0);var Su="crypto.algorithm",Pm=class{getAlgorithms(){return Ve.resolveAll(Su)}toAsnAlgorithm(e){({...e});for(let t of this.getAlgorithms()){let n=t.toAsnAlgorithm(e);if(n)return n}if(/^[0-9.]+$/.test(e.name)){let t=new M({algorithm:e.name});if("parameters"in e){let n=e;t.parameters=n.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(let n of this.getAlgorithms()){let o=n.toWebAlgorithm(e);if(o)return o}return{name:e.algorithm,parameters:e.parameters}}},Xi="crypto.algorithmProvider";Ve.registerSingleton(Xi,Pm);var up,tr="1.3.36.3.3.2.8.1.1",Mv=`${tr}.1`,Kv=`${tr}.2`,Hv=`${tr}.3`,Vv=`${tr}.4`,$v=`${tr}.5`,Fv=`${tr}.6`,Wv=`${tr}.7`,qv=`${tr}.8`,Gv=`${tr}.9`,zv=`${tr}.10`,Xv=`${tr}.11`,Yv=`${tr}.12`,Zv=`${tr}.13`,Jv=`${tr}.14`,Qv="brainpoolP160r1",e1="brainpoolP160t1",t1="brainpoolP192r1",r1="brainpoolP192t1",n1="brainpoolP224r1",o1="brainpoolP224t1",i1="brainpoolP256r1",s1="brainpoolP256t1",a1="brainpoolP320r1",c1="brainpoolP320t1",u1="brainpoolP384r1",l1="brainpoolP384t1",f1="brainpoolP512r1",p1="brainpoolP512t1",ze="ECDSA",xu=up=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case ze.toLowerCase():if("hash"in e)switch((typeof e.hash=="string"?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Ix;case"sha-256":return Ox;case"sha-384":return Px;case"sha-512":return Bx}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Hy;break;case"K-256":t=up.SECP256K1;break;case"P-384":t=Vy;break;case"P-521":t=$y;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=Yv;break;case f1:t=Zv;break;case p1:t=Jv;break}if(t)return new M({algorithm:Li,parameters:G.serialize(new cn({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case ru:return{name:ze,hash:{name:"SHA-1"}};case nu:return{name:ze,hash:{name:"SHA-256"}};case ou:return{name:ze,hash:{name:"SHA-384"}};case iu:return{name:ze,hash:{name:"SHA-512"}};case Li:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(G.parse(e.parameters,cn).namedCurve){case Hy:return{name:ze,namedCurve:"P-256"};case up.SECP256K1:return{name:ze,namedCurve:"K-256"};case Vy:return{name:ze,namedCurve:"P-384"};case $y:return{name:ze,namedCurve:"P-521"};case Mv:return{name:ze,namedCurve:Qv};case Kv:return{name:ze,namedCurve:e1};case Hv:return{name:ze,namedCurve:t1};case Vv:return{name:ze,namedCurve:r1};case $v:return{name:ze,namedCurve:n1};case Fv:return{name:ze,namedCurve:o1};case Wv:return{name:ze,namedCurve:i1};case qv:return{name:ze,namedCurve:s1};case Gv:return{name:ze,namedCurve:a1};case zv:return{name:ze,namedCurve:c1};case Xv:return{name:ze,namedCurve:u1};case Yv:return{name:ze,namedCurve:l1};case Zv:return{name:ze,namedCurve:f1};case Jv:return{name:ze,namedCurve:p1}}}}return null}};xu.SECP256K1="1.3.132.0.10";xu=up=cu([Io()],xu);Ve.registerSingleton(Su,xu);var _1=Symbol("name"),S1=Symbol("value"),Ee=class{constructor(e,t={},n=""){this[_1]=e,this[S1]=n;for(let o in t)this[o]=t[o]}};Ee.NAME=_1;Ee.VALUE=S1;var Bm=class{static toTextObject(e){let t=new Ee("Algorithm Identifier",{},hn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Li:{let n=new xu().toWebAlgorithm(e);n&&"namedCurve"in n?t["Named Curve"]=n.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}},hn=class{static toString(e){let t=this.items[e];return t||e}};hn.items={[Mi]:"sha1",[Wf]:"sha224",[Ki]:"sha256",[Hi]:"sha384",[Vi]:"sha512",[un]:"rsaEncryption",[Xs]:"sha1WithRSAEncryption",[Dx]:"sha224WithRSAEncryption",[Ff]:"sha256WithRSAEncryption",[Ys]:"sha384WithRSAEncryption",[Zs]:"sha512WithRSAEncryption",[Li]:"ecPublicKey",[ru]:"ecdsaWithSHA1",[$f]:"ecdsaWithSHA224",[nu]:"ecdsaWithSHA256",[ou]:"ecdsaWithSHA384",[iu]:"ecdsaWithSHA512",[cx]:"TLS WWW server authentication",[ux]:"TLS WWW client authentication",[lx]:"Code Signing",[fx]:"E-mail Protection",[px]:"Time Stamping",[hx]:"OCSP Signing",[Cx]:"Signed Data"};var Hn=class{static serialize(e){return this.serializeObj(e).join(`
9
+ `)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Ee.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Ee.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[Ee.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof Ee)c[Ee.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[Ee.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)}};Hn.oidSerializer=hn;Hn.algorithmSerializer=Bm;var No=class r{constructor(...e){if(e.length===1){let t=e[0];this.rawData=G.serialize(t),this.onInit(t)}else{let t=G.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 G.toString(this.rawData);case"text":return Hn.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 Ee(this.getTextName(),{},e)}};No.NAME="ASN";var vr=class r extends No{constructor(...e){let t;V.BufferSourceConverter.isBufferSource(e[0])?t=V.BufferSourceConverter.toArrayBuffer(e[0]):t=G.serialize(new xt({extnID:e[0],critical:e[1],extnValue:new ce(V.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,xt)}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[Ee.NAME]===r.NAME&&(e[Ee.NAME]=hn.toString(this.type)),e}},E1,vu=class r{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&e.extractable!==void 0}constructor(){this.items=new Map,this[E1]="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}};E1=Symbol.toStringTag;vu.DEFAULT="default";var St=new vu,gC=/^[0-2](?:\.[1-9][0-9]*)+$/;function wC(r){return new RegExp(gC).test(r)}var fp=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 wC(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Qt=new fp;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 bC(r,e){return`\\${V.Convert.ToHex(V.Convert.FromUtf8String(e)).toUpperCase()}`}function xC(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,bC)}var xr=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 fp,this.asn=new Le;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 Le?this.asn=e:V.BufferSourceConverter.isBufferSource(e)?this.asn=G.parse(e,Le):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?`#${V.Convert.ToHex(t.value.anyValue)}`:xC(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 Le,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 ho([p])),i=l}return t}fromJSON(e){let t=new Le;for(let n of e){let o=new ho;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 gi({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 G.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]||St.get()):n=e[0]||St.get(),await n.subtle.digest(o,this.toArrayBuffer())}},C1="Cannot initialize GeneralName from ASN.1 data.",h1=`${C1} Unsupported string format in use.`,vC=`${C1} Value doesn't match to GUID regular expression.`,d1=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,y1="1.3.6.1.4.1.311.25.1",m1="1.3.6.1.4.1.311.20.2.3",vm="dns",Am="dn",_m="email",Sm="ip",Em="url",Cm="guid",Tm="upn",sp="id",pn=class extends No{constructor(...e){let t;if(e.length===2)switch(e[0]){case Am:{let n=new xr(e[1]).toArrayBuffer(),o=G.parse(n,Le);t=new fe({directoryName:o});break}case vm:t=new fe({dNSName:e[1]});break;case _m:t=new fe({rfc822Name:e[1]});break;case Cm:{let n=new RegExp(d1,"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 fe({otherName:new yo({typeId:y1,value:G.serialize(new ce(V.Convert.FromHex(o)))})});break}case Sm:t=new fe({iPAddress:e[1]});break;case sp:t=new fe({registeredID:e[1]});break;case Tm:{t=new fe({otherName:new yo({typeId:m1,value:G.serialize(Jd.toASN(e[1]))})});break}case Em:t=new fe({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else V.BufferSourceConverter.isBufferSource(e[0])?t=G.parse(e[0],fe):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=vm,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=_m,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=Sm,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Em,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=sp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Am,this.value=new xr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===y1){this.type=Cm;let t=G.parse(e.otherName.value,ce),n=new RegExp(d1,"i").exec(V.Convert.ToHex(t));if(!n)throw new Error(vC);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===m1)this.type=Tm,this.value=G.parse(e.otherName.value,it).toString();else throw new Error(h1);else throw new Error(h1)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Am:case vm:case Cm:case Sm:case sp:case Tm:case Em:e=this.type.toUpperCase();break;case _m:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===sp&&(t=hn.toString(t)),new Ee(e,void 0,t)}},Yi=class extends No{constructor(e){let t;if(e instanceof Ge)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof fe)n.push(o);else{let i=G.parse(new pn(o.type,o.value).rawData,fe);n.push(i)}t=new Ge(n)}else if(V.BufferSourceConverter.isBufferSource(e))t=G.parse(e,Ge);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 pn(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[Ee.NAME]];Array.isArray(o)||(o=[],e[n[Ee.NAME]]=o),o.push(n)}return e}};Yi.NAME="GeneralNames";var bu="-{5}",Au="\\n",AC=`[^${Au}]+`,_C=`${bu}BEGIN (${AC}(?=${bu}))${bu}`,SC=`${bu}END \\1${bu}`,sa="\\n",EC=`[^:${Au}]+`,CC=`(?:[^${Au}]+${sa}(?: +[^${Au}]+${sa})*)`,TC="[a-zA-Z0-9=+/]+",IC=`(?:${TC}${sa})+`,g1=`${_C}${sa}(?:((?:${EC}: ${CC})+))?${sa}?(${IC})${SC}`,Ht=class{static isPem(e){return typeof e=="string"&&new RegExp(g1,"g").test(e)}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(g1,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${Au}]+`,"g"),""),s={type:o[1],headers:[],rawData:V.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(sa,"g")),l=null;for(let p of c){let[f,d]=p.split(/:(.*)/);if(d===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:d.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
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
- `)}};Ht.CertificateTag="CERTIFICATE";Ht.CrlTag="CRL";Ht.CertificateRequestTag="CERTIFICATE REQUEST";Ht.PublicKeyTag="PUBLIC KEY";Ht.PrivateKeyTag="PRIVATE KEY";var jo=class r extends No{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ht.isPem(e))return Ht.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 Ht.isPem(t)?Ht.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 Ht.encode(this.rawData,this.tag);default:return super.toString(e)}}},Mn=class r extends jo{static async create(e,t=St.get()){if(e instanceof r)return e;if(wu.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){jo.isAsnEncoded(e)?super(e,bt):super(e),this.tag=Ht.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||St.get()):t=e[0]||St.get();let i=this.rawData,s=G.parse(this.rawData,bt);return s.algorithm.algorithm===Eo&&(i=_C(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Ve.resolve(Xi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case cn:{let o=G.parse(e.subjectPublicKey,Js),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]||St.get()):n=e[0]||St.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=St.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=St.get();let o=G.parse(this.rawData,bt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,bt);switch(e.Algorithm=Kn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Li:e["EC Point"]=t.subjectPublicKey;break;case cn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function _C(r,e){return r.algorithm=new M({algorithm:cn,parameters:null}),e=G.serialize(r),e}var lp=class r extends xr{static async create(e,t=!1,n=St.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Mn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new rn({keyIdentifier:new xi(V.Convert.FromHex(e[0]))});super(xf,e[1],G.serialize(t))}else{let t=e[0],n=t.name instanceof Yi?G.parse(t.name.rawData,Ge):t.name,o=new rn({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(xf,e[1],G.serialize(o))}}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,rn);t.keyIdentifier&&(this.keyId=V.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?V.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,rn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Yi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};lp.NAME="Authority Key Identifier";var ia=class extends xr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,vi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new vi({cA:e[0],pathLenConstraint:e[1]});super(vf,e[2],G.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};ia.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 fp=class extends xr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,jc);this.usages=t.map(n=>n)}else{let t=new jc(e[0]);super(Ef,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>pn.toString(t)).join(", "),e}};fp.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 pp=class extends xr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,Ps);this.usages=t.toNumber()}else{let t=new Ps(e[0]);super(Cf,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,Ps);return e[""]=t.toJSON().join(", "),e}};pp.NAME="Key Usages";var hp=class r extends xr{static async create(e,t=!1,n=St.get()){let i=await(await Mn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,Gt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new Gt(t);super(_y,e[1],G.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,Gt);return e[""]=t,e}};hp.NAME="Subject Key Identifier";var dp=class extends xr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(vy,e[1],new Yi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,Pf);this.names=new Yi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};dp.NAME="Subject Alternative Name";var Qt=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new xr(e),n=this.items.get(t.type);return n?new n(e):t}};Qt.items=new Map;var yp=class extends xr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=G.parse(this.value,Oc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new Oc(n.map(s=>new Ai({policyIdentifier:s})));super(_f,o,G.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Ee("",{},pn.toString(t))),e}};yp.NAME="Certificate Policies";Qt.register(_f,yp);var mp=class extends xr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new nn({distributionPoint:new kn({fullName:[new le({uniformResourceIdentifier:s})]})})),i=new wo(o);super(Sf,e[1],G.serialize(i))}else{let n=new wo(e[0]);super(Sf,e[1],G.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,wo);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new fn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};mp.NAME="CRL Distribution Points";var gp=class extends xr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof bi){let s=new bi(e[0]);super(bf,e[1],G.serialize(s))}else{let s=e[0],a=new bi;sp(a,s,iy,"ocsp"),sp(a,s,sy,"caIssuers"),sp(a,s,ay,"timeStamping"),sp(a,s,cy,"caRepository"),super(bf,e[1],G.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],G.parse(e.extnValue,bi).forEach(n=>{switch(n.accessMethod){case iy:this.ocsp.push(new fn(n.accessLocation));break;case sy:this.caIssuers.push(new fn(n.accessLocation));break;case ay:this.timeStamping.push(new fn(n.accessLocation));break;case cy:this.caRepository.push(new fn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&ip(e,"OCSP",this.ocsp),this.caIssuers.length&&ip(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&ip(e,"Time Stamping",this.timeStamping),this.caRepository.length&&ip(e,"CA Repository",this.caRepository),e}};gp.NAME="Authority Info Access";function ip(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Ee("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Ee.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function sp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new fn("url",s)),r.push(new Pn({accessMethod:t,accessLocation:G.parse(s.rawData,le)}))})}var sa=class r extends No{constructor(...e){let t;if(V.BufferSourceConverter.isBufferSource(e[0]))t=V.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>V.BufferSourceConverter.toArrayBuffer(i)):[];t=G.serialize(new wt({type:n,values:o}))}super(t,wt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Ee("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Ee.NAME]===r.NAME&&(e[Ee.NAME]=pn.toString(this.type)),e}};sa.NAME="Attribute";var wp=class extends sa{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new fu({printableString:e[0]});super(wm,[G.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],fu);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Ee.VALUE]=this.password,e}};wp.NAME="Challenge Password";var xu=class extends sa{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new or;for(let i of n)o.push(G.parse(i.rawData,xt));super(hu,[G.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],or);this.items=t.map(n=>Qt.create(G.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Ee.NAME]]=n;return e}};xu.NAME="Extensions";var aa=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new sa(e),n=this.items.get(t.type);return n?new n(e):t}};aa.items=new Map;var Au="crypto.signatureFormatter",Bm=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},cp,km=cp=class{static createPssParams(e,t){let n=cp.getHashAlgorithm(e);return n?new un({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:Co,parameters:G.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Ve.resolve(Xi);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:Gs,parameters:null});case"sha-256":return new M({algorithm:Vf,parameters:null});case"sha-384":return new M({algorithm:zs,parameters:null});case"sha-512":return new M({algorithm:Xs,parameters:null})}}else return new M({algorithm:cn,parameters:null});break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e&&typeof e.saltLength=="number"))throw new Error("Cannot get 'saltLength' from 'alg' argument");let t=cp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Eo,parameters:G.serialize(t)})}else return new M({algorithm:Eo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case cn:return{name:"RSASSA-PKCS1-v1_5"};case Gs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Vf:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case zs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Xs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Eo:if(e.parameters){let t=G.parse(e.parameters,un);return{name:"RSA-PSS",hash:Ve.resolve(Xi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};km=cp=iu([Io()],km);Ve.registerSingleton(vu,km);var Nm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Mi});case"sha-256":return new M({algorithm:Ki});case"sha-384":return new M({algorithm:Hi});case"sha-512":return new M({algorithm:Vi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Mi:return{name:"SHA-1"};case Ki:return{name:"SHA-256"};case Hi:return{name:"SHA-384"};case Vi:return{name:"SHA-512"}}return null}};Nm=iu([Io()],Nm);Ve.registerSingleton(vu,Nm);var Hn=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 Ui,s=V.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),G.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=G.parse(t,Ui),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}};Hn.namedCurveSize=new Map;Hn.defaultNamedCurveSize=32;var Tm="1.3.101.110",w1="1.3.101.111",Im="1.3.101.112",b1="1.3.101.113",jm=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=Im;break;case"x25519":t=Tm;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=Im;break;case"ed448":t=b1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Tm;break;case"x448":t=w1;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case Im:return{name:"Ed25519"};case b1:return{name:"EdDSA",namedCurve:"Ed448"};case Tm:return{name:"X25519"};case w1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};jm=iu([Io()],jm);Ve.registerSingleton(vu,jm);var Rm=class extends jo{constructor(e){jo.isAsnEncoded(e)?super(e,ko):super(e),this.tag=Ht.CertificateRequestTag}onInit(e){this.tbs=G.serialize(e.certificationRequestInfo),this.publicKey=new Mn(e.certificationRequestInfo.subjectPKInfo);let t=Ve.resolve(Xi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>aa.create(G.serialize(o)));let n=this.getAttribute(hu);this.extensions=[],n instanceof xu&&(this.extensions=n.items),this.subjectName=new br(e.certificationRequestInfo.subject),this.subject=this.subjectName.toString()}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=St.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Ve.resolveAll(Au).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,ko),n=t.certificationRequestInfo,o=new Ee("",{Version:`${on[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Ee("");for(let s of this.attributes){let a=s.toTextObject();i[a[Ee.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Ee("",{Algorithm:Kn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Rm.NAME="PKCS#10 Certificate Request";var ca=class extends jo{constructor(e){jo.isAsnEncoded(e)?super(e,dr):super(e),this.tag=Ht.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=G.serialize(t),this.serialNumber=V.Convert.ToHex(t.serialNumber),this.subjectName=new br(t.subject),this.subject=new br(t.subject).toString(),this.issuerName=new br(t.issuer),this.issuer=this.issuerName.toString();let n=Ve.resolve(Xi);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=>Qt.create(G.serialize(s)))),this.publicKey=new Mn(t.subjectPublicKeyInfo)}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=St.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Mn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let l=new Mn(i);n={...l.algorithm,...this.signatureAlgorithm},o=await l.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Ve.resolveAll(Au).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=St.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=St.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,dr),n=t.tbsCertificate,o=new Ee("",{Version:`${on[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Kn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Ee("",{"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 Ee("");for(let s of this.extensions){let a=s.toTextObject();i[a[Ee.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Ee("",{Algorithm:Kn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};ca.NAME="Certificate";var bp=class{static async createSelfSigned(e,t=St.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=St.get()){var n;let o;e.publicKey instanceof Mn?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));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 dr({tbsCertificate:new vt({version:on.v3,serialNumber:i,validity:new Nn({notBefore:s,notAfter:a}),extensions:new or(((n=e.extensions)===null||n===void 0?void 0:n.map(_=>G.parse(_.rawData,xt)))||[]),subjectPublicKeyInfo:G.parse(o,bt)})});if(e.subject){let _=e.subject instanceof br?e.subject:new br(e.subject);c.tbsCertificate.subject=G.parse(_.toArrayBuffer(),Le)}if(e.issuer){let _=e.issuer instanceof br?e.issuer:new br(e.issuer);c.tbsCertificate.issuer=G.parse(_.toArrayBuffer(),Le)}let l={hash:"SHA-256"},p="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},f=Ve.resolve(Xi);c.tbsCertificate.signature=c.signatureAlgorithm=f.toAsnAlgorithm(p);let d=G.serialize(c.tbsCertificate),v="signingKey"in e?await t.subtle.sign(p,e.signingKey,d):e.signature,g=Ve.resolveAll(Au).reverse(),w=null;for(let _ of g)if(w=_.toAsnSignature(p,v),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new ca(G.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={}));Qt.register(vf,ia);Qt.register(Ef,fp);Qt.register(Cf,pp);Qt.register(_y,hp);Qt.register(xf,lp);Qt.register(vy,dp);Qt.register(Sf,mp);Qt.register(bf,gp);aa.register(wm,wp);aa.register(hu,xu);Ve.registerSingleton(Au,Bm);Ve.registerSingleton(Au,Hn);Hn.namedCurveSize.set("P-256",32);Hn.namedCurveSize.set("K-256",32);Hn.namedCurveSize.set("P-384",48);Hn.namedCurveSize.set("P-521",66);var Vn="/",E1=new TextEncoder().encode(Vn),xp=E1[0],_u=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=me(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]!==xp)throw new Error("Invalid key")}toString(e="utf8"){return fe(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Vn))}static random(){return new r(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new r(e):typeof e.uint8Array=="function"?new r(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=E1),this._buf[0]!==xp){let e=new Uint8Array(this._buf.byteLength+1);e.fill(xp,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===xp;)this._buf=this._buf.subarray(0,-1)}less(e){let t=this.list(),n=e.list();for(let o=0;o<t.length;o++){if(n.length<o+1)return!1;let i=t[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return t.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Vn).slice(1)}type(){return SC(this.baseNamespace())}name(){return EC(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Vn)||(e+=Vn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Vn):new r(e.slice(0,-1).join(Vn))}child(e){return this.toString()===Vn?e:e.toString()===Vn?this:new r(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return r.withNamespaces([...this.namespaces(),...CC(e.map(t=>t.namespaces()))])}};function SC(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function EC(r){let e=r.split(":");return e[e.length-1]}function CC(r){return[].concat(...r)}var vp=class extends Gn{async listen(){throw new Wl("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Dm(){let r=nt(),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 C1(){let r=Dm(),e=Dm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function TC(r){return r[Symbol.asyncIterator]!=null}async function IC(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*OC(r){let e=new AbortController,t=Ul();IC(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*PC(r){for(let e of r)yield*e}function BC(...r){let e=[];for(let t of r)TC(t)||e.push(t);return e.length===r.length?PC(e):OC(r)}var T1=BC;function I1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Lm(r)){let n=r;r=()=>n.source}else if(P1(r)||O1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Lm(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++)Lm(t[n])&&(t[n]=NC(t[n]));return kC(...t)}var kC=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},O1=r=>r?.[Symbol.asyncIterator]!=null,P1=r=>r?.[Symbol.iterator]!=null,Lm=r=>r==null?!1:r.sink!=null&&r.source!=null,NC=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=xs({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(P1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return T1(n,o())}return r.source};var ua=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function k1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ap(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function _p(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Nt(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 Um(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){Nt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function $n(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Fn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function jC(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var RC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function DC(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Sp(r){if(typeof r=="string")r=DC(r);else if(k1(r))r=Ep(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 Mm=(r,e)=>{function t(n,...o){if(Nt(n),!RC)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?Nt(p):Nt(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Nt(o[1]);let s=e(n,...o),a=(p,f)=>{if(f!==void 0){if(p!==2)throw new Error("cipher output not supported");Nt(f)}},c=!1;return{encrypt(p,f){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Nt(p),a(s.encrypt.length,f),s.encrypt(p,f)},decrypt(p,f){if(Nt(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 Km(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&&!LC(e))throw new Error("invalid output, must be aligned");return e}function B1(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){Ap(t);let n=new Uint8Array(16),o=jC(n);return B1(o,0,BigInt(e),t),B1(o,8,BigInt(r),t),n}function LC(r){return r.byteOffset%4===0}function Ep(r){return Uint8Array.from(r)}var U1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),UC=U1("expand 16-byte k"),MC=U1("expand 32-byte k"),KC=$n(UC),HC=$n(MC);function re(r,e){return r<<e|r>>>32-e}function Hm(r){return r.byteOffset%4===0}var Cp=64,VC=16,M1=2**32-1,L1=new Uint32Array;function $C(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(Cp),p=$n(l),f=Hm(o)&&Hm(i),d=f?$n(o):L1,v=f?$n(i):L1;for(let g=0;g<c;s++){if(r(e,t,n,p,s,a),s>=M1)throw new Error("arx: counter overflow");let w=Math.min(Cp,c-g);if(f&&w===Cp){let _=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let j=0,J;j<VC;j++)J=_+j,v[J]=d[J]^p[j];g+=Cp;continue}for(let _=0,j;_<w;_++)j=g+_,i[j]=o[j]^l[_];g+=w}}function Vm(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 _p(o),_p(s),Ap(i),Ap(t),(a,c,l,p,f=0)=>{Nt(a),Nt(c),Nt(l);let d=l.length;if(p===void 0&&(p=new Uint8Array(d)),Nt(p),_p(f),f<0||f>=M1)throw new Error("arx: counter overflow");if(p.length<d)throw new Error(`arx: output (${p.length}) is shorter than data (${d})`);let v=[],g=a.length,w,_;if(g===32)v.push(w=Ep(a)),_=HC;else if(g===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),_=KC,v.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Hm(c)||v.push(c=Ep(c));let j=$n(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(_,j,$n(c.subarray(0,16)),j),c=c.subarray(16)}let J=16-o;if(J!==c.length)throw new Error(`arx: nonce must be ${J} or 16 bytes`);if(J!==12){let x=new Uint8Array(12);x.set(c,i?0:12-c.length),c=x,v.push(c)}let O=$n(c);return $C(r,_,j,O,l,p,f,s),Fn(...v),p}}var Et=(r,e)=>r[e++]&255|(r[e++]&255)<<8,$m=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=Sp(e),Nt(e,32);let t=Et(e,0),n=Et(e,2),o=Et(e,4),i=Et(e,6),s=Et(e,8),a=Et(e,10),c=Et(e,12),l=Et(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]=Et(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],d=s[5],v=s[6],g=s[7],w=s[8],_=s[9],j=Et(e,t+0),J=Et(e,t+2),O=Et(e,t+4),x=Et(e,t+6),D=Et(e,t+8),$=Et(e,t+10),N=Et(e,t+12),U=Et(e,t+14),F=i[0]+(j&8191),Z=i[1]+((j>>>13|J<<3)&8191),K=i[2]+((J>>>10|O<<6)&8191),X=i[3]+((O>>>7|x<<9)&8191),W=i[4]+((x>>>4|D<<12)&8191),ae=i[5]+(D>>>1&8191),B=i[6]+((D>>>14|$<<2)&8191),R=i[7]+(($>>>11|N<<5)&8191),H=i[8]+((N>>>8|U<<8)&8191),k=i[9]+(U>>>5|o),y=0,T=y+F*a+Z*(5*_)+K*(5*w)+X*(5*g)+W*(5*v);y=T>>>13,T&=8191,T+=ae*(5*d)+B*(5*f)+R*(5*p)+H*(5*l)+k*(5*c),y+=T>>>13,T&=8191;let L=y+F*c+Z*a+K*(5*_)+X*(5*w)+W*(5*g);y=L>>>13,L&=8191,L+=ae*(5*v)+B*(5*d)+R*(5*f)+H*(5*p)+k*(5*l),y+=L>>>13,L&=8191;let I=y+F*l+Z*c+K*a+X*(5*_)+W*(5*w);y=I>>>13,I&=8191,I+=ae*(5*g)+B*(5*v)+R*(5*d)+H*(5*f)+k*(5*p),y+=I>>>13,I&=8191;let oe=y+F*p+Z*l+K*c+X*a+W*(5*_);y=oe>>>13,oe&=8191,oe+=ae*(5*w)+B*(5*g)+R*(5*v)+H*(5*d)+k*(5*f),y+=oe>>>13,oe&=8191;let pe=y+F*f+Z*p+K*l+X*c+W*a;y=pe>>>13,pe&=8191,pe+=ae*(5*_)+B*(5*w)+R*(5*g)+H*(5*v)+k*(5*d),y+=pe>>>13,pe&=8191;let te=y+F*d+Z*f+K*p+X*l+W*c;y=te>>>13,te&=8191,te+=ae*a+B*(5*_)+R*(5*w)+H*(5*g)+k*(5*v),y+=te>>>13,te&=8191;let de=y+F*v+Z*d+K*f+X*p+W*l;y=de>>>13,de&=8191,de+=ae*c+B*a+R*(5*_)+H*(5*w)+k*(5*g),y+=de>>>13,de&=8191;let ye=y+F*g+Z*v+K*d+X*f+W*p;y=ye>>>13,ye&=8191,ye+=ae*l+B*c+R*a+H*(5*_)+k*(5*w),y+=ye>>>13,ye&=8191;let Ce=y+F*w+Z*g+K*v+X*d+W*f;y=Ce>>>13,Ce&=8191,Ce+=ae*p+B*l+R*c+H*a+k*(5*_),y+=Ce>>>13,Ce&=8191;let Te=y+F*_+Z*w+K*g+X*v+W*d;y=Te>>>13,Te&=8191,Te+=ae*f+B*p+R*l+H*c+k*a,y+=Te>>>13,Te&=8191,y=(y<<2)+y|0,y=y+T|0,T=y&8191,y=y>>>13,L+=y,i[0]=T,i[1]=L,i[2]=I,i[3]=oe,i[4]=pe,i[5]=te,i[6]=de,i[7]=ye,i[8]=Ce,i[9]=Te}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;Fn(n)}update(e){Um(this),e=Sp(e),Nt(e);let{buffer:t,blockLen:n}=this,o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){Fn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Um(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 FC(r){let e=(n,o)=>r(o).update(Sp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var K1=FC(r=>new $m(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],d=e[2],v=e[3],g=e[4],w=e[5],_=e[6],j=e[7],J=o,O=t[0],x=t[1],D=t[2],$=s,N=a,U=c,F=l,Z=p,K=f,X=d,W=v,ae=g,B=w,R=_,H=j,k=J,y=O,T=x,L=D;for(let oe=0;oe<i;oe+=2)$=$+Z|0,k=re(k^$,16),ae=ae+k|0,Z=re(Z^ae,12),$=$+Z|0,k=re(k^$,8),ae=ae+k|0,Z=re(Z^ae,7),N=N+K|0,y=re(y^N,16),B=B+y|0,K=re(K^B,12),N=N+K|0,y=re(y^N,8),B=B+y|0,K=re(K^B,7),U=U+X|0,T=re(T^U,16),R=R+T|0,X=re(X^R,12),U=U+X|0,T=re(T^U,8),R=R+T|0,X=re(X^R,7),F=F+W|0,L=re(L^F,16),H=H+L|0,W=re(W^H,12),F=F+W|0,L=re(L^F,8),H=H+L|0,W=re(W^H,7),$=$+K|0,L=re(L^$,16),R=R+L|0,K=re(K^R,12),$=$+K|0,L=re(L^$,8),R=R+L|0,K=re(K^R,7),N=N+X|0,k=re(k^N,16),H=H+k|0,X=re(X^H,12),N=N+X|0,k=re(k^N,8),H=H+k|0,X=re(X^H,7),U=U+W|0,y=re(y^U,16),ae=ae+y|0,W=re(W^ae,12),U=U+W|0,y=re(y^U,8),ae=ae+y|0,W=re(W^ae,7),F=F+Z|0,T=re(T^F,16),B=B+T|0,Z=re(Z^B,12),F=F+Z|0,T=re(T^F,8),B=B+T|0,Z=re(Z^B,7);let I=0;n[I++]=s+$|0,n[I++]=a+N|0,n[I++]=c+U|0,n[I++]=l+F|0,n[I++]=p+Z|0,n[I++]=f+K|0,n[I++]=d+X|0,n[I++]=v+W|0,n[I++]=g+ae|0,n[I++]=w+B|0,n[I++]=_+R|0,n[I++]=j+H|0,n[I++]=J+k|0,n[I++]=O+y|0,n[I++]=x+T|0,n[I++]=D+L|0}function WC(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],d=e[4],v=e[5],g=e[6],w=e[7],_=t[0],j=t[1],J=t[2],O=t[3];for(let D=0;D<20;D+=2)o=o+c|0,_=re(_^o,16),d=d+_|0,c=re(c^d,12),o=o+c|0,_=re(_^o,8),d=d+_|0,c=re(c^d,7),i=i+l|0,j=re(j^i,16),v=v+j|0,l=re(l^v,12),i=i+l|0,j=re(j^i,8),v=v+j|0,l=re(l^v,7),s=s+p|0,J=re(J^s,16),g=g+J|0,p=re(p^g,12),s=s+p|0,J=re(J^s,8),g=g+J|0,p=re(p^g,7),a=a+f|0,O=re(O^a,16),w=w+O|0,f=re(f^w,12),a=a+f|0,O=re(O^a,8),w=w+O|0,f=re(f^w,7),o=o+l|0,O=re(O^o,16),g=g+O|0,l=re(l^g,12),o=o+l|0,O=re(O^o,8),g=g+O|0,l=re(l^g,7),i=i+p|0,_=re(_^i,16),w=w+_|0,p=re(p^w,12),i=i+p|0,_=re(_^i,8),w=w+_|0,p=re(p^w,7),s=s+f|0,j=re(j^s,16),d=d+j|0,f=re(f^d,12),s=s+f|0,j=re(j^s,8),d=d+j|0,f=re(f^d,7),a=a+c|0,J=re(J^a,16),v=v+J|0,c=re(c^v,12),a=a+c|0,J=re(J^a,8),v=v+J|0,c=re(c^v,7);let x=0;n[x++]=o,n[x++]=i,n[x++]=s,n[x++]=a,n[x++]=_,n[x++]=j,n[x++]=J,n[x++]=O}var qC=Vm($1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),GC=Vm($1,{counterRight:!1,counterLength:8,extendNonceFn:WC,allowShortKeys:!1});var zC=new Uint8Array(16),H1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(zC.subarray(t))},XC=new Uint8Array(32);function V1(r,e,t,n,o){let i=r(e,t,XC),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 Fn(i,a),c}var F1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Km(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),Fn(l),s},decrypt(i,s){s=Km(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),Fn(l),s}}),Fm=Mm({blockSize:64,nonceLength:12,tagLength:16},F1(qC)),hz=Mm({blockSize:64,nonceLength:24,tagLength:16},F1(GC));function q1(r,e,t){return Sa(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ps(r,Zn(t),Zn(e))}var Wm=Uint8Array.from([0]),W1=Uint8Array.of();function G1(r,e,t,n=32){Sa(r),ns(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=ps.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Wm[0]=p+1,c.update(p===0?W1:l).update(t).update(Wm).digestInto(l),s.set(l,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),Sr(l,Wm),s.slice(0,n)}var qm={hashSHA256(r){return so(r.subarray())},getHKDF(r,e){let t=q1(so,e,r),o=G1(so,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=Ra.utils.randomPrivateKey();return{publicKey:Ra.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Ra.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return Ra.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Fm(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Fm(n,e,t).decrypt(r.subarray(),o)}};var z1=qm;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 la=r=>{let e=ut(2);return e[0]=r>>8,e[1]=r,e};la.bytes=2;var Su=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)};Su.bytes=2;function Y1(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 Gm(r,e){!e.enabled||!ua||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${fe(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${fe(r.privateKey,"hex")}`)):e("Missing local static keys."))}function zm(r,e){!e.enabled||!ua||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${fe(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${fe(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function Z1(r,e){!e.enabled||!ua||e(r?`REMOTE_STATIC_PUBLIC_KEY ${fe(r.subarray(),"hex")}`:"Missing remote static public key.")}function Xm(r,e){!e.enabled||!ua||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${fe(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Ym(r,e,t){!t.enabled||!ua||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&fe(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&fe(e.k,"hex")}`))}var fa=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var YC=0,ZC=4294967295,JC="Cipherstate has reached maximum n, a new handshake must be performed",Tp=class{n;bytes;view;constructor(e=YC){this.n=e,this.bytes=ct(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>ZC)throw new Error(JC)}};var Zi=ct(0),pa=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Tp(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}},Zm=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=me(t,"utf-8");this.h=QC(e,n),this.ck=this.h,this.cs=new pa(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new pa(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Ae(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,Zi);return[new pa(this.crypto,e),new pa(this.crypto,t)]}},Jm=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 Zm(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()}},Eu=class extends Jm{writeMessageA(e){return new Ae(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Ae(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new Ae(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new fa(`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 fa(`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 fa(`handshake stage 2 validation fail: ${t.message}`)}}};function QC(r,e){if(e.length<=32){let t=ct(32);return t.set(e),t}else return r.hash(e)}var Ip;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),t.webtransportCerthashes!=null)for(let i of t.webtransportCerthashes)n.uint32(10),n.bytes(i);if(t.streamMuxers!=null)for(let i of t.streamMuxers)n.uint32(18),n.string(i);o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={webtransportCerthashes:[],streamMuxers:[]},s=n==null?t.len:t.pos+n;for(;t.pos<s;){let a=t.uint32();switch(a>>>3){case 1:{if(o.limits?.webtransportCerthashes!=null&&i.webtransportCerthashes.length===o.limits.webtransportCerthashes)throw new Ka('Decode error - map field "webtransportCerthashes" had too many elements');i.webtransportCerthashes.push(t.bytes());break}case 2:{if(o.limits?.streamMuxers!=null&&i.streamMuxers.length===o.limits.streamMuxers)throw new Ka('Decode error - map field "streamMuxers" had too many elements');i.streamMuxers.push(t.string());break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Ip||(Ip={}));var Cu;(function(r){let e;r.codec=()=>(e==null&&(e=Br((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.identityKey!=null&&t.identityKey.byteLength>0&&(n.uint32(10),n.bytes(t.identityKey)),t.identitySig!=null&&t.identitySig.byteLength>0&&(n.uint32(18),n.bytes(t.identitySig)),t.extensions!=null&&(n.uint32(34),Ip.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ct(0),identitySig:ct(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=Ip.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Pr(t,r.codec()),r.decode=(t,n)=>Or(t,r.codec(),n)})(Cu||(Cu={}));async function Qm(r,e,t){let n=await r.sign(J1(e));return Cu.encode({identityKey:Yn(r.publicKey),identitySig:n,extensions:t})}async function eg(r,e,t){try{let n=Cu.decode(r),o=qa(n.identityKey);if(t?.equals(o)===!1)throw new Error(`Payload identity key ${o} does not match expected remote identity key ${t}`);if(!e)throw new Error("Remote static does not exist");let i=J1(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Nu(n.message)}}function J1(r){let e=me("noise-libp2p-static-key:");return r instanceof Uint8Array?lt([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 Qm(i,a.publicKey,l),f=new Eu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});Gm(f.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(f.writeMessageA(Zi),e),t.trace("Stage 0 - Initiator finished sending first message."),zm(f.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=f.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Xm(f.re,t),Z1(f.rs,t),t.trace("Initiator going to check remote's signature...");let v=await eg(d,f.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(f.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,w]=f.ss.split();return Ym(g,w,t),{payload:v,encrypt:_=>g.encryptWithAd(Zi,_),decrypt:(_,j)=>w.decryptWithAd(Zi,_,j)}}async function eA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,p=await Qm(i,a.publicKey,l),f=new Eu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});Gm(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."),Xm(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."),zm(f.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let d=f.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let v=await eg(d,f.rs,c),[g,w]=f.ss.split();return Ym(g,w,t),{payload:v,encrypt:_=>w.encryptWithAd(Zi,_),decrypt:(_,j)=>g.decryptWithAd(Zi,_,j)}}var rA=16;function nA(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 Ae(la(s.byteLength),s)}}}function oA(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-rA<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-rA);try{let c=r.decrypt(s,a);e?.decryptedPackets.increment(),yield c}catch(c){throw e?.decryptErrors.increment(),c}}}}var Op=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?Y1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ct(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Qi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=sc(e,{lengthEncoder:la,lengthDecoder:Su,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=qa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ud(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(o.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new ju("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=sc(e,{lengthEncoder:la,lengthDecoder:Su,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=qa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ud(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 eA({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]=C1(),i=e.unwrap();return await I1(n,nA(t,this.metrics),i,s=>ei(s,{lengthDecoder:Su}),oA(t,this.metrics),n),o}};function iA(r={}){return e=>new Op(e,r)}var tg=Object.values(Mo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),eT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function sA(r){return r?.match(eT)?.groups?.fingerprint}function rg(r){let t=r.stringTuples().filter(n=>n[0]===jw).map(n=>n[1])[0];if(t===void 0||t==="")throw new Se(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function tT(r){return sr.decode(tg.decode(r))}function rT(r){let e=tT(rg(r)),t=nT(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 Fl(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function aA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Tt(ar.code,t);return Yr(`/certhash/${Uo.encode(n.bytes)}`)}function nT(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new ql(r)}}function cA(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=rT(r);return{type:"answer",sdp:`v=0
12
+ `)}};Ht.CertificateTag="CERTIFICATE";Ht.CrlTag="CRL";Ht.CertificateRequestTag="CERTIFICATE REQUEST";Ht.PublicKeyTag="PUBLIC KEY";Ht.PrivateKeyTag="PRIVATE KEY";var jo=class r extends No{static isAsnEncoded(e){return V.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Ht.isPem(e))return Ht.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 Ht.isPem(t)?Ht.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 Ht.encode(this.rawData,this.tag);default:return super.toString(e)}}},Kn=class r extends jo{static async create(e,t=St.get()){if(e instanceof r)return e;if(vu.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(V.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){jo.isAsnEncoded(e)?super(e,bt):super(e),this.tag=Ht.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||St.get()):t=e[0]||St.get();let i=this.rawData,s=G.parse(this.rawData,bt);return s.algorithm.algorithm===Eo&&(i=OC(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=Ve.resolve(Xi),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case un:{let o=G.parse(e.subjectPublicKey,ea),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]||St.get()):n=e[0]||St.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=St.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=St.get();let o=G.parse(this.rawData,bt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,bt);switch(e.Algorithm=Hn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Li:e["EC Point"]=t.subjectPublicKey;break;case un:default:e["Raw Data"]=t.subjectPublicKey}return e}};function OC(r,e){return r.algorithm=new M({algorithm:un,parameters:null}),e=G.serialize(r),e}var pp=class r extends vr{static async create(e,t=!1,n=St.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await Kn.create(e,n)).getKeyIdentifier(n);return new r(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 nn({keyIdentifier:new xi(V.Convert.FromHex(e[0]))});super(Af,e[1],G.serialize(t))}else{let t=e[0],n=t.name instanceof Yi?G.parse(t.name.rawData,Ge):t.name,o=new nn({authorityCertIssuer:n,authorityCertSerialNumber:V.Convert.FromHex(t.serialNumber)});super(Af,e[1],G.serialize(o))}}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,nn);t.keyIdentifier&&(this.keyId=V.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?V.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,nn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Yi(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};pp.NAME="Authority Key Identifier";var aa=class extends vr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,vi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new vi({cA:e[0],pathLenConstraint:e[1]});super(_f,e[2],G.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),this.pathLength!==void 0&&(e["Path Length"]=this.pathLength),e}};aa.NAME="Basic Constraints";var w1;(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"})(w1||(w1={}));var hp=class extends vr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,Lc);this.usages=t.map(n=>n)}else{let t=new Lc(e[0]);super(Tf,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>hn.toString(t)).join(", "),e}};hp.NAME="Extended Key Usages";var b1;(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"})(b1||(b1={}));var dp=class extends vr{constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,ks);this.usages=t.toNumber()}else{let t=new ks(e[0]);super(If,e[1],G.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,ks);return e[""]=t.toJSON().join(", "),e}};dp.NAME="Key Usages";var yp=class r extends vr{static async create(e,t=!1,n=St.get()){let i=await(await Kn.create(e,n)).getKeyIdentifier(n);return new r(V.Convert.ToHex(i),t)}constructor(...e){if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=G.parse(this.value,zt);this.keyId=V.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?V.Convert.FromHex(e[0]):e[0],n=new zt(t);super(Sy,e[1],G.serialize(n)),this.keyId=V.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=G.parse(this.value,zt);return e[""]=t,e}};yp.NAME="Subject Key Identifier";var mp=class extends vr{constructor(...e){V.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Ay,e[1],new Yi(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,kf);this.names=new Yi(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};mp.NAME="Subject Alternative Name";var er=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new vr(e),n=this.items.get(t.type);return n?new n(e):t}};er.items=new Map;var gp=class extends vr{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=G.parse(this.value,kc);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new kc(n.map(s=>new Ai({policyIdentifier:s})));super(Ef,o,G.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Ee("",{},hn.toString(t))),e}};gp.NAME="Certificate Policies";er.register(Ef,gp);var wp=class extends vr{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 on({distributionPoint:new Nn({fullName:[new fe({uniformResourceIdentifier:s})]})})),i=new wo(o);super(Cf,e[1],G.serialize(i))}else{let n=new wo(e[0]);super(Cf,e[1],G.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=G.parse(e.extnValue,wo);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new pn(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};wp.NAME="CRL Distribution Points";var bp=class extends vr{constructor(...e){var t,n,o,i;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof bi){let s=new bi(e[0]);super(vf,e[1],G.serialize(s))}else{let s=e[0],a=new bi;cp(a,s,sy,"ocsp"),cp(a,s,ay,"caIssuers"),cp(a,s,cy,"timeStamping"),cp(a,s,uy,"caRepository"),super(vf,e[1],G.serialize(a))}(t=this.ocsp)!==null&&t!==void 0||(this.ocsp=[]),(n=this.caIssuers)!==null&&n!==void 0||(this.caIssuers=[]),(o=this.timeStamping)!==null&&o!==void 0||(this.timeStamping=[]),(i=this.caRepository)!==null&&i!==void 0||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[],G.parse(e.extnValue,bi).forEach(n=>{switch(n.accessMethod){case sy:this.ocsp.push(new pn(n.accessLocation));break;case ay:this.caIssuers.push(new pn(n.accessLocation));break;case cy:this.timeStamping.push(new pn(n.accessLocation));break;case uy:this.caRepository.push(new pn(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&ap(e,"OCSP",this.ocsp),this.caIssuers.length&&ap(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&ap(e,"Time Stamping",this.timeStamping),this.caRepository.length&&ap(e,"CA Repository",this.caRepository),e}};bp.NAME="Authority Info Access";function ap(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Ee("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Ee.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function cp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new pn("url",s)),r.push(new Bn({accessMethod:t,accessLocation:G.parse(s.rawData,fe)}))})}var ca=class r extends No{constructor(...e){let t;if(V.BufferSourceConverter.isBufferSource(e[0]))t=V.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>V.BufferSourceConverter.toArrayBuffer(i)):[];t=G.serialize(new wt({type:n,values:o}))}super(t,wt)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Value=this.values.map(t=>new Ee("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Ee.NAME]===r.NAME&&(e[Ee.NAME]=hn.toString(this.type)),e}};ca.NAME="Attribute";var xp=class extends ca{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new du({printableString:e[0]});super(bm,[G.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],du);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Ee.VALUE]=this.password,e}};xp.NAME="Challenge Password";var _u=class extends ca{constructor(...e){var t;if(V.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new ir;for(let i of n)o.push(G.parse(i.rawData,xt));super(mu,[G.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=G.parse(this.values[0],ir);this.items=t.map(n=>er.create(G.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Ee.NAME]]=n;return e}};_u.NAME="Extensions";var ua=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ca(e),n=this.items.get(t.type);return n?new n(e):t}};ua.items=new Map;var Eu="crypto.signatureFormatter",km=class{toAsnSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return V.BufferSourceConverter.toArrayBuffer(t)}},lp,Nm=lp=class{static createPssParams(e,t){let n=lp.getHashAlgorithm(e);return n?new ln({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:Co,parameters:G.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=Ve.resolve(Xi);return typeof e=="string"?t.toAsnAlgorithm({name:e}):typeof e=="object"&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if("hash"in e){let t;if(typeof e.hash=="string")t=e.hash;else if(e.hash&&typeof e.hash=="object"&&"name"in e.hash&&typeof e.hash.name=="string")t=e.hash.name.toUpperCase();else throw new Error("Cannot get hash algorithm name");switch(t.toLowerCase()){case"sha-1":return new M({algorithm:Xs,parameters:null});case"sha-256":return new M({algorithm:Ff,parameters:null});case"sha-384":return new M({algorithm:Ys,parameters:null});case"sha-512":return new M({algorithm:Zs,parameters:null})}}else return new M({algorithm:un,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=lp.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Eo,parameters:G.serialize(t)})}else return new M({algorithm:Eo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case un:return{name:"RSASSA-PKCS1-v1_5"};case Xs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Ff:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case Ys:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case Zs:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Eo:if(e.parameters){let t=G.parse(e.parameters,ln);return{name:"RSA-PSS",hash:Ve.resolve(Xi).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Nm=lp=cu([Io()],Nm);Ve.registerSingleton(Su,Nm);var jm=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Mi});case"sha-256":return new M({algorithm:Ki});case"sha-384":return new M({algorithm:Hi});case"sha-512":return new M({algorithm:Vi})}return null}toWebAlgorithm(e){switch(e.algorithm){case Mi:return{name:"SHA-1"};case Ki:return{name:"SHA-256"};case Hi:return{name:"SHA-384"};case Vi:return{name:"SHA-512"}}return null}};jm=cu([Io()],jm);Ve.registerSingleton(Su,jm);var Vn=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 Ui,s=V.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),G.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=G.parse(t,Ui),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}};Vn.namedCurveSize=new Map;Vn.defaultNamedCurveSize=32;var Im="1.3.101.110",x1="1.3.101.111",Om="1.3.101.112",v1="1.3.101.113",Rm=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=Om;break;case"x25519":t=Im;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=Om;break;case"ed448":t=v1;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Im;break;case"x448":t=x1;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case Om:return{name:"Ed25519"};case v1:return{name:"EdDSA",namedCurve:"Ed448"};case Im:return{name:"X25519"};case x1:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Rm=cu([Io()],Rm);Ve.registerSingleton(Su,Rm);var Dm=class extends jo{constructor(e){jo.isAsnEncoded(e)?super(e,ko):super(e),this.tag=Ht.CertificateRequestTag}onInit(e){this.tbs=G.serialize(e.certificationRequestInfo),this.publicKey=new Kn(e.certificationRequestInfo.subjectPKInfo);let t=Ve.resolve(Xi);this.signatureAlgorithm=t.toWebAlgorithm(e.signatureAlgorithm),this.signature=e.signature,this.attributes=e.certificationRequestInfo.attributes.map(o=>ua.create(G.serialize(o)));let n=this.getAttribute(mu);this.extensions=[],n instanceof _u&&(this.extensions=n.items),this.subjectName=new xr(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=St.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=Ve.resolveAll(Eu).reverse(),i=null;for(let a of o)if(i=a.toWebSignature(t,this.signature),i)break;if(!i)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,n,i,this.tbs)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,ko),n=t.certificationRequestInfo,o=new Ee("",{Version:`${sn[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Ee("");for(let s of this.attributes){let a=s.toTextObject();i[a[Ee.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Ee("",{Algorithm:Hn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Dm.NAME="PKCS#10 Certificate Request";var la=class extends jo{constructor(e){jo.isAsnEncoded(e)?super(e,yr):super(e),this.tag=Ht.CertificateTag}onInit(e){let t=e.tbsCertificate;this.tbs=G.serialize(t),this.serialNumber=V.Convert.ToHex(t.serialNumber),this.subjectName=new xr(t.subject),this.subject=new xr(t.subject).toString(),this.issuerName=new xr(t.issuer),this.issuer=this.issuerName.toString();let n=Ve.resolve(Xi);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=>er.create(G.serialize(s)))),this.publicKey=new Kn(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=St.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof Kn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(V.BufferSourceConverter.isBufferSource(i)){let l=new Kn(i);n={...l.algorithm,...this.signatureAlgorithm},o=await l.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=Ve.resolveAll(Eu).reverse(),a=null;for(let l of s)if(a=l.toWebSignature(n,this.signature),a)break;if(!a)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");let c=await t.subtle.verify(this.signatureAlgorithm,o,a,this.tbs);if(e.signatureOnly)return c;{let 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=St.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=St.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=G.parse(this.rawData,yr),n=t.tbsCertificate,o=new Ee("",{Version:`${sn[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Hn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Ee("",{"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 Ee("");for(let s of this.extensions){let a=s.toTextObject();i[a[Ee.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Ee("",{Algorithm:Hn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};la.NAME="Certificate";var vp=class{static async createSelfSigned(e,t=St.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=St.get()){var n;let o;e.publicKey instanceof Kn?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));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 yr({tbsCertificate:new vt({version:sn.v3,serialNumber:i,validity:new jn({notBefore:s,notAfter:a}),extensions:new ir(((n=e.extensions)===null||n===void 0?void 0:n.map(_=>G.parse(_.rawData,xt)))||[]),subjectPublicKeyInfo:G.parse(o,bt)})});if(e.subject){let _=e.subject instanceof xr?e.subject:new xr(e.subject);c.tbsCertificate.subject=G.parse(_.toArrayBuffer(),Le)}if(e.issuer){let _=e.issuer instanceof xr?e.issuer:new xr(e.issuer);c.tbsCertificate.issuer=G.parse(_.toArrayBuffer(),Le)}let l={hash:"SHA-256"},p="signingKey"in e?{...l,...e.signingAlgorithm,...e.signingKey.algorithm}:{...l,...e.signingAlgorithm},f=Ve.resolve(Xi);c.tbsCertificate.signature=c.signatureAlgorithm=f.toAsnAlgorithm(p);let d=G.serialize(c.tbsCertificate),v="signingKey"in e?await t.subtle.sign(p,e.signingKey,d):e.signature,g=Ve.resolveAll(Eu).reverse(),w=null;for(let _ of g)if(w=_.toAsnSignature(p,v),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new la(G.serialize(c))}},A1;(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"})(A1||(A1={}));er.register(_f,aa);er.register(Tf,hp);er.register(If,dp);er.register(Sy,yp);er.register(Af,pp);er.register(Ay,mp);er.register(Cf,wp);er.register(vf,bp);ua.register(bm,xp);ua.register(mu,_u);Ve.registerSingleton(Eu,km);Ve.registerSingleton(Eu,Vn);Vn.namedCurveSize.set("P-256",32);Vn.namedCurveSize.set("K-256",32);Vn.namedCurveSize.set("P-384",48);Vn.namedCurveSize.set("P-521",66);var $n="/",T1=new TextEncoder().encode($n),Ap=T1[0],Cu=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=me(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]!==Ap)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($n))}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=T1),this._buf[0]!==Ap){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ap,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ap;)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($n).slice(1)}type(){return PC(this.baseNamespace())}name(){return BC(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith($n)||(e+=$n),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r($n):new r(e.slice(0,-1).join($n))}child(e){return this.toString()===$n?e:e.toString()===$n?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(),...kC(e.map(t=>t.namespaces()))])}};function PC(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function BC(r){let e=r.split(":");return e[e.length-1]}function kC(r){return[].concat(...r)}var _p=class extends zn{async listen(){throw new Gl("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};function Lm(){let r=nt(),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 I1(){let r=Lm(),e=Lm();return[{source:r.source,sink:e.sink},{source:e.source,sink:r.sink}]}function NC(r){return r[Symbol.asyncIterator]!=null}async function jC(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*RC(r){let e=new AbortController,t=Kl();jC(r,t,e.signal).catch(()=>{});try{yield*t}finally{e.abort()}}function*DC(r){for(let e of r)yield*e}function LC(...r){let e=[];for(let t of r)NC(t)||e.push(t);return e.length===r.length?DC(e):RC(r)}var O1=LC;function P1(r,...e){if(r==null)throw new Error("Empty pipeline");if(Um(r)){let n=r;r=()=>n.source}else if(k1(r)||B1(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Um(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Um(t[n])&&(t[n]=MC(t[n]));return UC(...t)}var UC=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},B1=r=>r?.[Symbol.asyncIterator]!=null,k1=r=>r?.[Symbol.iterator]!=null,Um=r=>r==null?!1:r.sink!=null&&r.source!=null,MC=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=As({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(k1(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return O1(n,o())}return r.source};var fa=!!globalThis.process?.env?.DUMP_SESSION_KEYS;function j1(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Sp(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function Ep(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Nt(r,...e){if(!j1(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Mm(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function R1(r,e){Nt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Fn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function Wn(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function KC(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var HC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function VC(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Cp(r){if(typeof r=="string")r=VC(r);else if(j1(r))r=Tp(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function D1(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function L1(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var Km=(r,e)=>{function t(n,...o){if(Nt(n),!HC)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?Nt(p):Nt(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&Nt(o[1]);let s=e(n,...o),a=(p,f)=>{if(f!==void 0){if(p!==2)throw new Error("cipher output not supported");Nt(f)}},c=!1;return{encrypt(p,f){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Nt(p),a(s.encrypt.length,f),s.encrypt(p,f)},decrypt(p,f){if(Nt(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 Hm(r,e,t=!0){if(e===void 0)return new Uint8Array(r);if(e.length!==r)throw new Error("invalid output length, expected "+r+", got: "+e.length);if(t&&!$C(e))throw new Error("invalid output, must be aligned");return e}function N1(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 U1(r,e,t){Sp(t);let n=new Uint8Array(16),o=KC(n);return N1(o,0,BigInt(e),t),N1(o,8,BigInt(r),t),n}function $C(r){return r.byteOffset%4===0}function Tp(r){return Uint8Array.from(r)}var K1=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),FC=K1("expand 16-byte k"),WC=K1("expand 32-byte k"),qC=Fn(FC),GC=Fn(WC);function re(r,e){return r<<e|r>>>32-e}function Vm(r){return r.byteOffset%4===0}var Ip=64,zC=16,H1=2**32-1,M1=new Uint32Array;function XC(r,e,t,n,o,i,s,a){let c=o.length,l=new Uint8Array(Ip),p=Fn(l),f=Vm(o)&&Vm(i),d=f?Fn(o):M1,v=f?Fn(i):M1;for(let g=0;g<c;s++){if(r(e,t,n,p,s,a),s>=H1)throw new Error("arx: counter overflow");let w=Math.min(Ip,c-g);if(f&&w===Ip){let _=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let j=0,J;j<zC;j++)J=_+j,v[J]=d[J]^p[j];g+=Ip;continue}for(let _=0,j;_<w;_++)j=g+_,i[j]=o[j]^l[_];g+=w}}function $m(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=D1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return Ep(o),Ep(s),Sp(i),Sp(t),(a,c,l,p,f=0)=>{Nt(a),Nt(c),Nt(l);let d=l.length;if(p===void 0&&(p=new Uint8Array(d)),Nt(p),Ep(f),f<0||f>=H1)throw new Error("arx: counter overflow");if(p.length<d)throw new Error(`arx: output (${p.length}) is shorter than data (${d})`);let v=[],g=a.length,w,_;if(g===32)v.push(w=Tp(a)),_=GC;else if(g===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),_=qC,v.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Vm(c)||v.push(c=Tp(c));let j=Fn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(_,j,Fn(c.subarray(0,16)),j),c=c.subarray(16)}let J=16-o;if(J!==c.length)throw new Error(`arx: nonce must be ${J} or 16 bytes`);if(J!==12){let x=new Uint8Array(12);x.set(c,i?0:12-c.length),c=x,v.push(c)}let O=Fn(c);return XC(r,_,j,O,l,p,f,s),Wn(...v),p}}var Et=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Fm=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Cp(e),Nt(e,32);let t=Et(e,0),n=Et(e,2),o=Et(e,4),i=Et(e,6),s=Et(e,8),a=Et(e,10),c=Et(e,12),l=Et(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]=Et(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],d=s[5],v=s[6],g=s[7],w=s[8],_=s[9],j=Et(e,t+0),J=Et(e,t+2),O=Et(e,t+4),x=Et(e,t+6),D=Et(e,t+8),$=Et(e,t+10),N=Et(e,t+12),U=Et(e,t+14),F=i[0]+(j&8191),Z=i[1]+((j>>>13|J<<3)&8191),K=i[2]+((J>>>10|O<<6)&8191),X=i[3]+((O>>>7|x<<9)&8191),W=i[4]+((x>>>4|D<<12)&8191),ae=i[5]+(D>>>1&8191),B=i[6]+((D>>>14|$<<2)&8191),R=i[7]+(($>>>11|N<<5)&8191),H=i[8]+((N>>>8|U<<8)&8191),k=i[9]+(U>>>5|o),y=0,T=y+F*a+Z*(5*_)+K*(5*w)+X*(5*g)+W*(5*v);y=T>>>13,T&=8191,T+=ae*(5*d)+B*(5*f)+R*(5*p)+H*(5*l)+k*(5*c),y+=T>>>13,T&=8191;let L=y+F*c+Z*a+K*(5*_)+X*(5*w)+W*(5*g);y=L>>>13,L&=8191,L+=ae*(5*v)+B*(5*d)+R*(5*f)+H*(5*p)+k*(5*l),y+=L>>>13,L&=8191;let I=y+F*l+Z*c+K*a+X*(5*_)+W*(5*w);y=I>>>13,I&=8191,I+=ae*(5*g)+B*(5*v)+R*(5*d)+H*(5*f)+k*(5*p),y+=I>>>13,I&=8191;let oe=y+F*p+Z*l+K*c+X*a+W*(5*_);y=oe>>>13,oe&=8191,oe+=ae*(5*w)+B*(5*g)+R*(5*v)+H*(5*d)+k*(5*f),y+=oe>>>13,oe&=8191;let pe=y+F*f+Z*p+K*l+X*c+W*a;y=pe>>>13,pe&=8191,pe+=ae*(5*_)+B*(5*w)+R*(5*g)+H*(5*v)+k*(5*d),y+=pe>>>13,pe&=8191;let te=y+F*d+Z*f+K*p+X*l+W*c;y=te>>>13,te&=8191,te+=ae*a+B*(5*_)+R*(5*w)+H*(5*g)+k*(5*v),y+=te>>>13,te&=8191;let de=y+F*v+Z*d+K*f+X*p+W*l;y=de>>>13,de&=8191,de+=ae*c+B*a+R*(5*_)+H*(5*w)+k*(5*g),y+=de>>>13,de&=8191;let ye=y+F*g+Z*v+K*d+X*f+W*p;y=ye>>>13,ye&=8191,ye+=ae*l+B*c+R*a+H*(5*_)+k*(5*w),y+=ye>>>13,ye&=8191;let Ce=y+F*w+Z*g+K*v+X*d+W*f;y=Ce>>>13,Ce&=8191,Ce+=ae*p+B*l+R*c+H*a+k*(5*_),y+=Ce>>>13,Ce&=8191;let Te=y+F*_+Z*w+K*g+X*v+W*d;y=Te>>>13,Te&=8191,Te+=ae*f+B*p+R*l+H*c+k*a,y+=Te>>>13,Te&=8191,y=(y<<2)+y|0,y=y+T|0,T=y&8191,y=y>>>13,L+=y,i[0]=T,i[1]=L,i[2]=I,i[3]=oe,i[4]=pe,i[5]=te,i[6]=de,i[7]=ye,i[8]=Ce,i[9]=Te}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;Wn(n)}update(e){Mm(this),e=Cp(e),Nt(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(){Wn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Mm(this),R1(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 YC(r){let e=(n,o)=>r(o).update(Cp(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var V1=YC(r=>new Fm(r));function W1(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],d=e[2],v=e[3],g=e[4],w=e[5],_=e[6],j=e[7],J=o,O=t[0],x=t[1],D=t[2],$=s,N=a,U=c,F=l,Z=p,K=f,X=d,W=v,ae=g,B=w,R=_,H=j,k=J,y=O,T=x,L=D;for(let oe=0;oe<i;oe+=2)$=$+Z|0,k=re(k^$,16),ae=ae+k|0,Z=re(Z^ae,12),$=$+Z|0,k=re(k^$,8),ae=ae+k|0,Z=re(Z^ae,7),N=N+K|0,y=re(y^N,16),B=B+y|0,K=re(K^B,12),N=N+K|0,y=re(y^N,8),B=B+y|0,K=re(K^B,7),U=U+X|0,T=re(T^U,16),R=R+T|0,X=re(X^R,12),U=U+X|0,T=re(T^U,8),R=R+T|0,X=re(X^R,7),F=F+W|0,L=re(L^F,16),H=H+L|0,W=re(W^H,12),F=F+W|0,L=re(L^F,8),H=H+L|0,W=re(W^H,7),$=$+K|0,L=re(L^$,16),R=R+L|0,K=re(K^R,12),$=$+K|0,L=re(L^$,8),R=R+L|0,K=re(K^R,7),N=N+X|0,k=re(k^N,16),H=H+k|0,X=re(X^H,12),N=N+X|0,k=re(k^N,8),H=H+k|0,X=re(X^H,7),U=U+W|0,y=re(y^U,16),ae=ae+y|0,W=re(W^ae,12),U=U+W|0,y=re(y^U,8),ae=ae+y|0,W=re(W^ae,7),F=F+Z|0,T=re(T^F,16),B=B+T|0,Z=re(Z^B,12),F=F+Z|0,T=re(T^F,8),B=B+T|0,Z=re(Z^B,7);let I=0;n[I++]=s+$|0,n[I++]=a+N|0,n[I++]=c+U|0,n[I++]=l+F|0,n[I++]=p+Z|0,n[I++]=f+K|0,n[I++]=d+X|0,n[I++]=v+W|0,n[I++]=g+ae|0,n[I++]=w+B|0,n[I++]=_+R|0,n[I++]=j+H|0,n[I++]=J+k|0,n[I++]=O+y|0,n[I++]=x+T|0,n[I++]=D+L|0}function ZC(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],d=e[4],v=e[5],g=e[6],w=e[7],_=t[0],j=t[1],J=t[2],O=t[3];for(let D=0;D<20;D+=2)o=o+c|0,_=re(_^o,16),d=d+_|0,c=re(c^d,12),o=o+c|0,_=re(_^o,8),d=d+_|0,c=re(c^d,7),i=i+l|0,j=re(j^i,16),v=v+j|0,l=re(l^v,12),i=i+l|0,j=re(j^i,8),v=v+j|0,l=re(l^v,7),s=s+p|0,J=re(J^s,16),g=g+J|0,p=re(p^g,12),s=s+p|0,J=re(J^s,8),g=g+J|0,p=re(p^g,7),a=a+f|0,O=re(O^a,16),w=w+O|0,f=re(f^w,12),a=a+f|0,O=re(O^a,8),w=w+O|0,f=re(f^w,7),o=o+l|0,O=re(O^o,16),g=g+O|0,l=re(l^g,12),o=o+l|0,O=re(O^o,8),g=g+O|0,l=re(l^g,7),i=i+p|0,_=re(_^i,16),w=w+_|0,p=re(p^w,12),i=i+p|0,_=re(_^i,8),w=w+_|0,p=re(p^w,7),s=s+f|0,j=re(j^s,16),d=d+j|0,f=re(f^d,12),s=s+f|0,j=re(j^s,8),d=d+j|0,f=re(f^d,7),a=a+c|0,J=re(J^a,16),v=v+J|0,c=re(c^v,12),a=a+c|0,J=re(J^a,8),v=v+J|0,c=re(c^v,7);let x=0;n[x++]=o,n[x++]=i,n[x++]=s,n[x++]=a,n[x++]=_,n[x++]=j,n[x++]=J,n[x++]=O}var JC=$m(W1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),QC=$m(W1,{counterRight:!1,counterLength:8,extendNonceFn:ZC,allowShortKeys:!1});var eT=new Uint8Array(16),$1=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(eT.subarray(t))},tT=new Uint8Array(32);function F1(r,e,t,n,o){let i=r(e,t,tT),s=V1.create(i);o&&$1(s,o),$1(s,n);let a=U1(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return Wn(i,a),c}var q1=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Hm(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let l=F1(r,e,t,c,n);return s.set(l,a),Wn(l),s},decrypt(i,s){s=Hm(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),l=F1(r,e,t,a,n);if(!L1(c,l))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),Wn(l),s}}),Wm=Km({blockSize:64,nonceLength:12,tagLength:16},q1(JC)),xz=Km({blockSize:64,nonceLength:24,tagLength:16},q1(QC));function z1(r,e,t){return Ca(r),t===void 0&&(t=new Uint8Array(r.outputLen)),ds(r,Jn(t),Jn(e))}var qm=Uint8Array.from([0]),G1=Uint8Array.of();function X1(r,e,t,n=32){Ca(r),ns(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=G1);let s=new Uint8Array(i*o),a=ds.create(r,e),c=a._cloneInto(),l=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)qm[0]=p+1,c.update(p===0?G1:l).update(t).update(qm).digestInto(l),s.set(l,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),Er(l,qm),s.slice(0,n)}var Gm={hashSHA256(r){return so(r.subarray())},getHKDF(r,e){let t=z1(so,e,r),o=X1(so,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=La.utils.randomPrivateKey();return{publicKey:La.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:La.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return La.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Wm(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Wm(n,e,t).decrypt(r.subarray(),o)}};var Y1=Gm;function Z1(r){return{generateKeypair:r.generateX25519KeyPair,dh:(e,t)=>r.generateX25519SharedKey(e.privateKey,t).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var pa=r=>{let e=ut(2);return e[0]=r>>8,e[1]=r,e};pa.bytes=2;var Tu=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let e=0;return e+=r[0]<<8,e+=r[1],e}return r.getUint16(0)};Tu.bytes=2;function J1(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function zm(r,e){!e.enabled||!fa||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${ue(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${ue(r.privateKey,"hex")}`)):e("Missing local static keys."))}function Xm(r,e){!e.enabled||!fa||(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 Q1(r,e){!e.enabled||!fa||e(r?`REMOTE_STATIC_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote static public key.")}function Ym(r,e){!e.enabled||!fa||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${ue(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Zm(r,e,t){!t.enabled||!fa||(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 ha=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var rT=0,nT=4294967295,oT="Cipherstate has reached maximum n, a new handshake must be performed",Op=class{n;bytes;view;constructor(e=rT){this.n=e,this.bytes=ct(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>nT)throw new Error(oT)}};var Zi=ct(0),da=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new Op(n)}hasKey(){return!!this.k}encryptWithAd(e,t){if(!this.hasKey())return t;this.n.assertValue();let n=this.crypto.encrypt(t,this.n.getBytes(),e,this.k);return this.n.increment(),n}decryptWithAd(e,t,n){if(!this.hasKey())return t;this.n.assertValue();let o=this.crypto.decrypt(t,this.n.getBytes(),e,this.k,n);return this.n.increment(),o}},Jm=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=me(t,"utf-8");this.h=iT(e,n),this.ck=this.h,this.cs=new da(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new da(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new Ae(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,Zi);return[new da(this.crypto,e),new da(this.crypto,t)]}},Qm=class{ss;s;e;rs;re;initiator;crypto;constructor(e){let{crypto:t,protocolName:n,prologue:o,initiator:i,s,e:a,rs:c,re:l}=e;this.crypto=t,this.ss=new Jm(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let e=this.crypto.generateKeypair();return this.ss.mixHash(e.publicKey),this.e=e,e.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(e,t=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(e.byteLength<t+32)throw new Error("message is not long enough");this.re=e.sublist(t,t+32),this.ss.mixHash(this.re)}readS(e,t=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(e.byteLength<t+n)throw new Error("message is not long enough");let o=e.sublist(t,t+n);return this.rs=this.ss.decryptAndHash(o),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},Iu=class extends Qm{writeMessageA(e){return new Ae(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new Ae(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new Ae(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new ha(`handshake stage 0 validation fail: ${t.message}`)}}readMessageB(e){try{this.readE(e),this.readEE();let t=this.readS(e,32);return this.readES(),this.ss.decryptAndHash(e.sublist(32+t))}catch(t){throw new ha(`handshake stage 1 validation fail: ${t.message}`)}}readMessageC(e){try{let t=this.readS(e);return this.readSE(),this.ss.decryptAndHash(e.sublist(t))}catch(t){throw new ha(`handshake stage 2 validation fail: ${t.message}`)}}};function iT(r,e){if(e.length<=32){let t=ct(32);return t.set(e),t}else return r.hash(e)}var Pp;(function(r){let e;r.codec=()=>(e==null&&(e=kr((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 Wa('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 Wa('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=>Br(t,r.codec()),r.decode=(t,n)=>Pr(t,r.codec(),n)})(Pp||(Pp={}));var Ou;(function(r){let e;r.codec=()=>(e==null&&(e=kr((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),Pp.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ct(0),identitySig:ct(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=Pp.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>Br(t,r.codec()),r.decode=(t,n)=>Pr(t,r.codec(),n)})(Ou||(Ou={}));async function eg(r,e,t){let n=await r.sign(eA(e));return Ou.encode({identityKey:Zn(r.publicKey),identitySig:n,extensions:t})}async function tg(r,e,t){try{let n=Ou.decode(r),o=Xa(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=eA(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new Du(n.message)}}function eA(r){let e=me("noise-libp2p-static-key:");return r instanceof Uint8Array?lt([e,r],e.length+r.length):(r.prepend(e),r)}async function tA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,p=await eg(i,a.publicKey,l),f=new Iu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});zm(f.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(f.writeMessageA(Zi),e),t.trace("Stage 0 - Initiator finished sending first message."),Xm(f.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let d=f.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),Ym(f.re,t),Q1(f.rs,t),t.trace("Initiator going to check remote's signature...");let v=await tg(d,f.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(f.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[g,w]=f.ss.split();return Zm(g,w,t),{payload:v,encrypt:_=>g.encryptWithAd(Zi,_),decrypt:(_,j)=>w.decryptWithAd(Zi,_,j)}}async function rA(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:l}=r,p=await eg(i,a.publicKey,l),f=new Iu({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});zm(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."),Ym(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."),Xm(f.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let d=f.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let v=await tg(d,f.rs,c),[g,w]=f.ss.split();return Zm(g,w,t),{payload:v,encrypt:_=>w.encryptWithAd(Zi,_),decrypt:(_,j)=>g.decryptWithAd(Zi,_,j)}}var oA=16;function iA(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 Ae(pa(s.byteLength),s)}}}function sA(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-oA<o)throw new Error("Invalid chunk");let s=n.sublist(o,i),a=n.subarray(o,i-oA);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??Y1;this.crypto=Z1(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?J1(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ct(0)}[Symbol.toStringTag]="@chainsafe/libp2p-noise";[Qi]=["@libp2p/connection-encryption","@chainsafe/libp2p-noise"];async secureOutbound(e,t){let n=uc(e,{lengthEncoder:pa,lengthDecoder:Tu,maxDataLength:65535}),o=await this.performHandshakeInitiator(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Xa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ld(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 Lu("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=uc(e,{lengthEncoder:pa,lengthDecoder:Tu,maxDataLength:65535}),o=await this.performHandshakeResponder(n,this.components.privateKey,t?.remotePeer?.publicKey,t),i=await this.createSecureConnection(n,o);e.source=i.source,e.sink=i.sink;let s=Xa(o.payload.identityKey);return{conn:e,remoteExtensions:o.payload.extensions,remotePeer:ld(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 tA({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 rA({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]=I1(),i=e.unwrap();return await P1(n,iA(t,this.metrics),i,s=>ei(s,{lengthDecoder:Tu}),sA(t,this.metrics),n),o}};function aA(r={}){return e=>new Bp(e,r)}var rg=Object.values(Mo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),sT=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function cA(r){return r?.match(sT)?.groups?.fingerprint}function ng(r){let t=r.stringTuples().filter(n=>n[0]===Dw).map(n=>n[1])[0];if(t===void 0||t==="")throw new Se(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function aT(r){return ar.decode(rg.decode(r))}function cT(r){let e=aT(ng(r)),t=uT(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 ql(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function uA(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Tt(cr.code,t);return Zr(`/certhash/${Uo.encode(n.bytes)}`)}function uT(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new zl(r)}}function lA(r,e){let{host:t,port:n,family:o}=r.toOptions(),i=cT(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:${ws}
26
+ a=max-message-size:${xs}
27
27
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
28
28
  a=end-of-candidates
29
- `}}function uA(r,e){let{host:t,port:n,family:o}=r.toOptions();return{type:"offer",sdp:`v=0
29
+ `}}function fA(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:${ws}
42
+ a=max-message-size:${xs}
43
43
  a=candidate:1467250027 1 UDP 1467250027 ${t} ${n} typ host
44
44
  a=end-of-candidates
45
- `}}function ng(r,e){if(r.sdp===void 0)throw new Se("Can't munge a missing SDP");let t=r.sdp.includes(`\r
45
+ `}}function og(r,e){if(r.sdp===void 0)throw new Se("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 og=me("libp2p-webrtc-noise:");function fA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=me(n,"hex"),i=Tt(ar.code,o),s=tg.decode(rg(e)),a=og.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?lt([og,s,i.bytes],a):lt([og,i.bytes,s],a)}var oT=rc?"iceconnectionstatechange":"connectionstatechange";async function pA(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let f=await r.createOffer();t.log.trace("client created local offer %s",f.sdp);let d=ng(f,e);t.log.trace("client setting local offer %s",d.sdp),await r.setLocalDescription(d);let v=cA(t.remoteAddr,e);t.log.trace("client setting server description %s",v.sdp),await r.setRemoteDescription(v)}else{let f=uA(t.remoteAddr,e);t.log.trace("server setting client %s %s",f.type,f.sdp),await r.setRemoteDescription(f),t.log.trace("server creating local answer");let d=await r.createAnswer();t.log.trace("server created local answer");let v=ng(d,e);t.log.trace("server setting local description %s",d.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 ic(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(aA(f))}let o=sA(r.localDescription?.sdp);if(o==null)throw new co("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=fA(o,t.remoteAddr,t.role),s=iA({prologueBytes:i})(t),a=As({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new Jo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(oT,()=>{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 ao(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 hA(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 dA(r){let e=await pl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...fe(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
- `)}var Pp=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 Gn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new Se("Certificate renewal threshold must be less than certificate lifespan");e.metrics!=null&&(this.metrics={dialerEvents:e.metrics.registerCounterGroup("libp2p_webrtc-direct_dialer_events_total",{label:"event",help:"Total count of WebRTC-direct dial events by type"})})}[ku]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Qi]=["@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=hs(o));let i=Qw(),s=await hA("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await pA(s,i,{role:"client",log:this.log,logger:this.components.logger,metrics:this.components.metrics,events:this.metrics?.dialerEvents,signal:t.signal,remoteAddr:e,dataChannel:this.init.dataChannel,upgrader:t.upgrader,peerId:this.components.peerId,remotePeerId:n,privateKey:this.components.privateKey})}catch(a){throw s.close(),a}}createListener(e){if(this.certificate==null)throw new Hu;return new vp(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(iT(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 dA(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 Do;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 _u(this.init.certificateDatastoreKey??Hw),i=await pl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Do;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??Bd)-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:Uo.encode((await ar.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new ca(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??Bd);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Do;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(!Ye(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 Do;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 bp.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 ia(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,me(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 iT(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function sT(r){return e=>new Pp(e,r)}function aT(r){return e=>new Yl(e,r)}return OA(cT);})();
50
+ a=ice-pwd:`+e+t),r}var ig=me("libp2p-webrtc-noise:");function hA(r,e,t){let n=r.trim().toLowerCase().replaceAll(":",""),o=me(n,"hex"),i=Tt(cr.code,o),s=rg.decode(ng(e)),a=ig.byteLength+i.bytes.byteLength+s.byteLength;return t==="server"?lt([ig,s,i.bytes],a):lt([ig,i.bytes,s],a)}var lT=ic?"iceconnectionstatechange":"connectionstatechange";async function dA(r,e,t){let n=r.createDataChannel("",{negotiated:!0,id:0});try{if(t.role==="client"){t.log.trace("client creating local offer");let f=await r.createOffer();t.log.trace("client created local offer %s",f.sdp);let d=og(f,e);t.log.trace("client setting local offer %s",d.sdp),await r.setLocalDescription(d);let v=lA(t.remoteAddr,e);t.log.trace("client setting server description %s",v.sdp),await r.setRemoteDescription(v)}else{let f=fA(t.remoteAddr,e);t.log.trace("server setting client %s %s",f.type,f.sdp),await r.setRemoteDescription(f),t.log.trace("server creating local answer");let d=await r.createAnswer();t.log.trace("server created local answer");let v=og(d,e);t.log.trace("server setting local description %s",d.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 cc(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(uA(f))}let o=cA(r.localDescription?.sdp);if(o==null)throw new co("Could not get fingerprint from local description sdp");t.log.trace("%s performing noise handshake",t.role);let i=hA(o,t.remoteAddr,t.role),s=aA({prologueBytes:i})(t),a=Ss({channel:n,direction:"outbound",handshake:!0,logger:t.logger,...t.dataChannel??{}}),c=new Jo(t,{peerConnection:r,remoteAddr:t.remoteAddr,timeline:{open:Date.now()},metrics:t.events});r.addEventListener(lT,()=>{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 ao(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 yA(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 mA(r){let e=await dl(r),t=await crypto.subtle.exportKey("pkcs8",e.privateKey);return["-----BEGIN PRIVATE KEY-----",...ue(new Uint8Array(t),"base64pad").split(/(.{64})/).filter(Boolean),"-----END PRIVATE KEY-----"].join(`
51
+ `)}var kp=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 zn,t.certificateLifespan!=null&&t.certificateRenewalThreshold!=null&&t.certificateRenewalThreshold>=t.certificateLifespan)throw new Se("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"})})}[Ru]=!0;[Symbol.toStringTag]="@libp2p/webrtc-direct";[Qi]=["@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=ys(o));let i=tb(),s=await yA("client",i,typeof this.init.rtcConfiguration=="function"?await this.init.rtcConfiguration():this.init.rtcConfiguration??{});try{return await dA(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 Fu;return new _p(this.components,{...this.init,...e,certificate:this.certificate,emitter:this.emitter})}listenFilter(e){return e.filter(Pw.exactMatch)}dialFilter(e){return this.listenFilter(e)}async getCertificate(e){if(fT(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 mA(t),pem:n,certhash:o}}async loadOrCreatePrivateKey(){if(this.privateKey!=null)return this.privateKey;let e=this.init.certificateKeychainName??Fw,t=this.getKeychain();try{if(t==null)throw this.log("no keychain configured - not checking for stored private key"),new Do;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 cw("ECDSA","P-256"),t!=null?(this.log.trace("storing private key"),await t.importKey(e,this.privateKey)):this.log("no keychain configured - not storing private key")}return this.privateKey}async loadOrCreateCertificate(e,t){if(this.certificate!=null&&t!==!0)return this.certificate;let n,o=new Cu(this.init.certificateDatastoreKey??$w),i=await dl(e);try{if(t===!0)throw this.log.trace("forcing renewal of TLS certificate"),new Do;this.log.trace("checking for stored TLS certificate"),n=await this.loadCertificate(o,i)}catch(a){if(a.name!=="NotFoundError")throw a;this.log.trace("generating new TLS certificate"),n=await this.createCertificate(o,i)}let s=n.notAfter.getTime()-(this.init.certificateRenewalThreshold??kd)-Date.now();return s<0&&(s=100),this.log("will renew TLS certificate after %d ms",s),this.renewCertificateTask=setTimeout(()=>{this.log("renewing TLS certificate"),this.getCertificate(!0).then(a=>{this.certificate=a,this.emitter.safeDispatchEvent("certificate:renew",{detail:a})}).catch(a=>{this.log.error("could not renew certificate - %e",a)})},s),{pem:n.toString("pem"),certhash:Uo.encode((await cr.digest(new Uint8Array(n.rawData))).bytes)}}async loadCertificate(e,t){let n=await this.components.datastore.get(e),o=new la(n),i=o.notAfter.getTime()-(this.init.certificateRenewalThreshold??kd);if(Date.now()>i)throw this.log("stored TLS certificate has expired"),new Do;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(!Ye(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 Do;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??Ww));n.setMilliseconds(0),o.setMilliseconds(0);let i=await vp.createSelfSigned({serialNumber:(BigInt(Math.random().toString().replace(".",""))*100000n).toString(16),name:"CN=example.com, C=US, L=CA, O=example, ST=CA",notBefore:n,notAfter:o,keys:t,extensions:[new aa(!1,void 0,!0)]},crypto);return this.getKeychain()!=null?(this.log.trace("storing TLS certificate"),await this.components.datastore.put(e,me(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 fT(r){return r==null?!1:typeof r.privateKey=="string"&&typeof r.pem=="string"&&typeof r.certhash=="string"}function pT(r){return e=>new kp(e,r)}function hT(r){return e=>new Jl(e,r)}return BA(dT);})();
52
52
  /*! Bundled license information:
53
53
 
54
54
  reflect-metadata/Reflect.js: