@libp2p/webrtc 5.2.24-da78fa851 → 5.2.24-e8398d97e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +4 -4
- package/dist/index.min.js.map +3 -3
- package/dist/src/private-to-private/transport.d.ts +0 -7
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +0 -8
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/package.json +9 -9
- package/src/private-to-private/transport.ts +0 -8
- package/src/private-to-public/transport.ts +0 -10
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 NS=Object.create;var bf=Object.defineProperty;var kS=Object.getOwnPropertyDescriptor;var DS=Object.getOwnPropertyNames;var RS=Object.getPrototypeOf,jS=Object.prototype.hasOwnProperty;var Ch=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ct=(r,e)=>{for(var t in e)bf(r,t,{get:e[t],enumerable:!0})},x0=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of DS(e))!jS.call(r,o)&&o!==t&&bf(r,o,{get:()=>e[o],enumerable:!(n=kS(e,o))||n.enumerable});return r};var Gr=(r,e,t)=>(t=r!=null?NS(RS(r)):{},x0(e||!r||!r.__esModule?bf(t,"default",{value:r,enumerable:!0}):t,r)),LS=r=>x0(bf({},"__esModule",{value:!0}),r);var Tx=Ch(()=>{var Cx;(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,u){return function(p,l){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:l}),u&&u(p,l)}}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,u=!a&&!c,p={create:a?function(){return Eh(Object.create(null))}:c?function(){return Eh({__proto__:null})}:function(){return Eh({})},has:u?function(_,C){return n.call(_,C)}:function(_,C){return C in _},get:u?function(_,C){return n.call(_,C)?_[C]:void 0}:function(_,C){return _[C]}},l=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:TS(),y=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:BS(),m=typeof WeakMap=="function"?WeakMap:IS(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,g=AS(),A=ES(g);function D(_,C,k,F){if(R(k)){if(!hn(_))throw new TypeError;if(!to(C))throw new TypeError;return V(_,C)}else{if(!hn(_))throw new TypeError;if(!te(C))throw new TypeError;if(!te(F)&&!R(F)&&!he(F))throw new TypeError;return he(F)&&(F=void 0),k=Re(k),x(_,C,k,F)}}e("decorate",D);function B(_,C){function k(F,ce){if(!te(F))throw new TypeError;if(!R(ce)&&!gf(ce))throw new TypeError;U(_,C,F,ce)}return k}e("metadata",B);function $(_,C,k,F){if(!te(k))throw new TypeError;return R(F)||(F=Re(F)),U(_,C,k,F)}e("defineMetadata",$);function Q(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),v(_,C,k)}e("hasMetadata",Q);function X(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),E(_,C,k)}e("hasOwnMetadata",X);function ne(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),N(_,C,k)}e("getMetadata",ne);function Y(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),j(_,C,k)}e("getOwnMetadata",Y);function I(_,C){if(!te(_))throw new TypeError;return R(C)||(C=Re(C)),P(_,C)}e("getMetadataKeys",I);function K(_,C){if(!te(_))throw new TypeError;return R(C)||(C=Re(C)),L(_,C)}e("getOwnMetadataKeys",K);function z(_,C,k){if(!te(C))throw new TypeError;if(R(k)||(k=Re(k)),!te(C))throw new TypeError;R(k)||(k=Re(k));var F=Ha(C,k,!1);return R(F)?!1:F.OrdinaryDeleteMetadata(_,C,k)}e("deleteMetadata",z);function V(_,C){for(var k=_.length-1;k>=0;--k){var F=_[k],ce=F(C);if(!R(ce)&&!he(ce)){if(!to(ce))throw new TypeError;C=ce}}return C}function x(_,C,k,F){for(var ce=_.length-1;ce>=0;--ce){var tt=_[ce],at=tt(C,k,F);if(!R(at)&&!he(at)){if(!te(at))throw new TypeError;F=at}}return F}function v(_,C,k){var F=E(_,C,k);if(F)return!0;var ce=Ah(C);return he(ce)?!1:v(_,ce,k)}function E(_,C,k){var F=Ha(C,k,!1);return R(F)?!1:Ue(F.OrdinaryHasOwnMetadata(_,C,k))}function N(_,C,k){var F=E(_,C,k);if(F)return j(_,C,k);var ce=Ah(C);if(!he(ce))return N(_,ce,k)}function j(_,C,k){var F=Ha(C,k,!1);if(!R(F))return F.OrdinaryGetOwnMetadata(_,C,k)}function U(_,C,k,F){var ce=Ha(k,F,!0);ce.OrdinaryDefineOwnMetadata(_,C,k,F)}function P(_,C){var k=L(_,C),F=Ah(_);if(F===null)return k;var ce=P(F,C);if(ce.length<=0)return k;if(k.length<=0)return ce;for(var tt=new y,at=[],xe=0,Z=k;xe<Z.length;xe++){var ee=Z[xe],oe=tt.has(ee);oe||(tt.add(ee),at.push(ee))}for(var ie=0,_e=ce;ie<_e.length;ie++){var ee=_e[ie],oe=tt.has(ee);oe||(tt.add(ee),at.push(ee))}return at}function L(_,C){var k=Ha(_,C,!1);return k?k.OrdinaryOwnMetadataKeys(_,C):[]}function q(_){if(_===null)return 1;switch(typeof _){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return _===null?1:6;default:return 6}}function R(_){return _===void 0}function he(_){return _===null}function be(_){return typeof _=="symbol"}function te(_){return typeof _=="object"?_!==null:typeof _=="function"}function Se(_,C){switch(q(_)){case 0:return _;case 1:return _;case 2:return _;case 3:return _;case 4:return _;case 5:return _}var k=C===3?"string":C===5?"number":"default",F=d0(_,i);if(F!==void 0){var ce=F.call(_,k);if(te(ce))throw new TypeError;return ce}return Te(_,k==="default"?"number":k)}function Te(_,C){if(C==="string"){var k=_.toString;if(ur(k)){var F=k.call(_);if(!te(F))return F}var ce=_.valueOf;if(ur(ce)){var F=ce.call(_);if(!te(F))return F}}else{var ce=_.valueOf;if(ur(ce)){var F=ce.call(_);if(!te(F))return F}var tt=_.toString;if(ur(tt)){var F=tt.call(_);if(!te(F))return F}}throw new TypeError}function Ue(_){return!!_}function Ee(_){return""+_}function Re(_){var C=Se(_,3);return be(C)?C:Ee(C)}function hn(_){return Array.isArray?Array.isArray(_):_ instanceof Object?_ instanceof Array:Object.prototype.toString.call(_)==="[object Array]"}function ur(_){return typeof _=="function"}function to(_){return typeof _=="function"}function gf(_){switch(q(_)){case 3:return!0;case 4:return!0;default:return!1}}function ls(_,C){return _===C||_!==_&&C!==C}function d0(_,C){var k=_[C];if(k!=null){if(!ur(k))throw new TypeError;return k}}function y0(_){var C=d0(_,s);if(!ur(C))throw new TypeError;var k=C.call(_);if(!te(k))throw new TypeError;return k}function m0(_){return _.value}function g0(_){var C=_.next();return C.done?!1:C}function b0(_){var C=_.return;C&&C.call(_)}function Ah(_){var C=Object.getPrototypeOf(_);if(typeof _!="function"||_===l||C!==l)return C;var k=_.prototype,F=k&&Object.getPrototypeOf(k);if(F==null||F===Object.prototype)return C;var ce=F.constructor;return typeof ce!="function"||ce===_?C:ce}function SS(){var _;!R(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(_=CS(t.Reflect));var C,k,F,ce=new m,tt={registerProvider:at,getProvider:Z,setProvider:oe};return tt;function at(ie){if(!Object.isExtensible(tt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case _===ie:break;case R(C):C=ie;break;case C===ie:break;case R(k):k=ie;break;case k===ie:break;default:F===void 0&&(F=new y),F.add(ie);break}}function xe(ie,_e){if(!R(C)){if(C.isProviderFor(ie,_e))return C;if(!R(k)){if(k.isProviderFor(ie,_e))return C;if(!R(F))for(var Ve=y0(F);;){var rt=g0(Ve);if(!rt)return;var Er=m0(rt);if(Er.isProviderFor(ie,_e))return b0(Ve),Er}}}if(!R(_)&&_.isProviderFor(ie,_e))return _}function Z(ie,_e){var Ve=ce.get(ie),rt;return R(Ve)||(rt=Ve.get(_e)),R(rt)&&(rt=xe(ie,_e),R(rt)||(R(Ve)&&(Ve=new h,ce.set(ie,Ve)),Ve.set(_e,rt))),rt}function ee(ie){if(R(ie))throw new TypeError;return C===ie||k===ie||!R(F)&&F.has(ie)}function oe(ie,_e,Ve){if(!ee(Ve))throw new Error("Metadata provider not registered.");var rt=Z(ie,_e);if(rt!==Ve){if(!R(rt))return!1;var Er=ce.get(ie);R(Er)&&(Er=new h,ce.set(ie,Er)),Er.set(_e,Ve)}return!0}}function AS(){var _;return!R(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&(_=t.Reflect[w]),R(_)&&(_=SS()),!R(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:_}),_}function ES(_){var C=new m,k={isProviderFor:function(ee,oe){var ie=C.get(ee);return R(ie)?!1:ie.has(oe)},OrdinaryDefineOwnMetadata:at,OrdinaryHasOwnMetadata:ce,OrdinaryGetOwnMetadata:tt,OrdinaryOwnMetadataKeys:xe,OrdinaryDeleteMetadata:Z};return g.registerProvider(k),k;function F(ee,oe,ie){var _e=C.get(ee),Ve=!1;if(R(_e)){if(!ie)return;_e=new h,C.set(ee,_e),Ve=!0}var rt=_e.get(oe);if(R(rt)){if(!ie)return;if(rt=new h,_e.set(oe,rt),!_.setProvider(ee,oe,k))throw _e.delete(oe),Ve&&C.delete(ee),new Error("Wrong provider for target.")}return rt}function ce(ee,oe,ie){var _e=F(oe,ie,!1);return R(_e)?!1:Ue(_e.has(ee))}function tt(ee,oe,ie){var _e=F(oe,ie,!1);if(!R(_e))return _e.get(ee)}function at(ee,oe,ie,_e){var Ve=F(ie,_e,!0);Ve.set(ee,oe)}function xe(ee,oe){var ie=[],_e=F(ee,oe,!1);if(R(_e))return ie;for(var Ve=_e.keys(),rt=y0(Ve),Er=0;;){var w0=g0(rt);if(!w0)return ie.length=Er,ie;var OS=m0(w0);try{ie[Er]=OS}catch(PS){try{b0(rt)}finally{throw PS}}Er++}}function Z(ee,oe,ie){var _e=F(oe,ie,!1);if(R(_e)||!_e.delete(ee))return!1;if(_e.size===0){var Ve=C.get(oe);R(Ve)||(Ve.delete(ie),Ve.size===0&&C.delete(Ve))}return!0}}function CS(_){var C=_.defineMetadata,k=_.hasOwnMetadata,F=_.getOwnMetadata,ce=_.getOwnMetadataKeys,tt=_.deleteMetadata,at=new m,xe={isProviderFor:function(Z,ee){var oe=at.get(Z);return!R(oe)&&oe.has(ee)?!0:ce(Z,ee).length?(R(oe)&&(oe=new y,at.set(Z,oe)),oe.add(ee),!0):!1},OrdinaryDefineOwnMetadata:C,OrdinaryHasOwnMetadata:k,OrdinaryGetOwnMetadata:F,OrdinaryOwnMetadataKeys:ce,OrdinaryDeleteMetadata:tt};return xe}function Ha(_,C,k){var F=g.getProvider(_,C);if(!R(F))return F;if(k){if(g.setProvider(_,C,A))return A;throw new Error("Illegal state.")}}function TS(){var _={},C=[],k=(function(){function xe(Z,ee,oe){this._index=0,this._keys=Z,this._values=ee,this._selector=oe}return xe.prototype["@@iterator"]=function(){return this},xe.prototype[s]=function(){return this},xe.prototype.next=function(){var Z=this._index;if(Z>=0&&Z<this._keys.length){var ee=this._selector(this._keys[Z],this._values[Z]);return Z+1>=this._keys.length?(this._index=-1,this._keys=C,this._values=C):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},xe.prototype.throw=function(Z){throw this._index>=0&&(this._index=-1,this._keys=C,this._values=C),Z},xe.prototype.return=function(Z){return this._index>=0&&(this._index=-1,this._keys=C,this._values=C),{value:Z,done:!0}},xe})(),F=(function(){function xe(){this._keys=[],this._values=[],this._cacheKey=_,this._cacheIndex=-2}return Object.defineProperty(xe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),xe.prototype.has=function(Z){return this._find(Z,!1)>=0},xe.prototype.get=function(Z){var ee=this._find(Z,!1);return ee>=0?this._values[ee]:void 0},xe.prototype.set=function(Z,ee){var oe=this._find(Z,!0);return this._values[oe]=ee,this},xe.prototype.delete=function(Z){var ee=this._find(Z,!1);if(ee>=0){for(var oe=this._keys.length,ie=ee+1;ie<oe;ie++)this._keys[ie-1]=this._keys[ie],this._values[ie-1]=this._values[ie];return this._keys.length--,this._values.length--,ls(Z,this._cacheKey)&&(this._cacheKey=_,this._cacheIndex=-2),!0}return!1},xe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=_,this._cacheIndex=-2},xe.prototype.keys=function(){return new k(this._keys,this._values,ce)},xe.prototype.values=function(){return new k(this._keys,this._values,tt)},xe.prototype.entries=function(){return new k(this._keys,this._values,at)},xe.prototype["@@iterator"]=function(){return this.entries()},xe.prototype[s]=function(){return this.entries()},xe.prototype._find=function(Z,ee){if(!ls(this._cacheKey,Z)){this._cacheIndex=-1;for(var oe=0;oe<this._keys.length;oe++)if(ls(this._keys[oe],Z)){this._cacheIndex=oe;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(Z),this._values.push(void 0)),this._cacheIndex},xe})();return F;function ce(xe,Z){return xe}function tt(xe,Z){return Z}function at(xe,Z){return[xe,Z]}}function BS(){var _=(function(){function C(){this._map=new h}return Object.defineProperty(C.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),C.prototype.has=function(k){return this._map.has(k)},C.prototype.add=function(k){return this._map.set(k,k),this},C.prototype.delete=function(k){return this._map.delete(k)},C.prototype.clear=function(){this._map.clear()},C.prototype.keys=function(){return this._map.keys()},C.prototype.values=function(){return this._map.keys()},C.prototype.entries=function(){return this._map.entries()},C.prototype["@@iterator"]=function(){return this.keys()},C.prototype[s]=function(){return this.keys()},C})();return _}function IS(){var _=16,C=p.create(),k=F();return(function(){function Z(){this._key=F()}return Z.prototype.has=function(ee){var oe=ce(ee,!1);return oe!==void 0?p.has(oe,this._key):!1},Z.prototype.get=function(ee){var oe=ce(ee,!1);return oe!==void 0?p.get(oe,this._key):void 0},Z.prototype.set=function(ee,oe){var ie=ce(ee,!0);return ie[this._key]=oe,this},Z.prototype.delete=function(ee){var oe=ce(ee,!1);return oe!==void 0?delete oe[this._key]:!1},Z.prototype.clear=function(){this._key=F()},Z})();function F(){var Z;do Z="@@WeakMap@@"+xe();while(p.has(C,Z));return C[Z]=!0,Z}function ce(Z,ee){if(!n.call(Z,k)){if(!ee)return;Object.defineProperty(Z,k,{value:p.create()})}return Z[k]}function tt(Z,ee){for(var oe=0;oe<ee;++oe)Z[oe]=Math.random()*255|0;return Z}function at(Z){if(typeof Uint8Array=="function"){var ee=new Uint8Array(Z);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):tt(ee,Z),ee}return tt(new Array(Z),Z)}function xe(){var Z=at(_);Z[6]=Z[6]&79|64,Z[8]=Z[8]&191|128;for(var ee="",oe=0;oe<_;++oe){var ie=Z[oe];(oe===4||oe===6||oe===8)&&(ee+="-"),ie<16&&(ee+="0"),ee+=ie.toString(16).toLowerCase()}return ee}}function Eh(_){return _.__=void 0,delete _.__,_}})})(Cx||(Cx={}))});var Nn=Ch(zs=>{"use strict";var UC="[object ArrayBuffer]",Pn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===UC}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}},Zy="string",MC=/^[0-9a-f\s]+$/i,KC=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,HC=/^[a-zA-Z0-9-_]+$/,Fl=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=Pn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},mr=class{static toString(e,t=!1){let n=Pn.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}},Wl=class r{static isHex(e){return typeof e===Zy&&MC.test(e)}static isBase64(e){return typeof e===Zy&&KC.test(e)}static isBase64Url(e){return typeof e===Zy&&HC.test(e)}static ToString(e,t="utf8"){let n=Pn.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 mr.toString(n,!0);case"utf16":case"utf16be":return mr.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 mr.fromString(e,!0);case"utf16":case"utf16be":return mr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pn.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 Fl.fromString(e);case"utf16":case"utf16be":return mr.fromString(e);case"utf16le":case"usc2":return mr.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 Fl.toString(e);case"utf16":case"utf16be":return mr.toString(e);case"utf16le":case"usc2":return mr.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=Pn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Pn.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 mr.toString(e,t)}static FromUtf16String(e,t=!1){return mr.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,"")||""}};Wl.DEFAULT_UTF8_ENCODING="utf8";function VC(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 $C(...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 FC(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}zs.BufferSourceConverter=Pn;zs.Convert=Wl;zs.assign=VC;zs.combine=$C;zs.isEqual=FC});var v1=Ch((j7,Mp)=>{var t1,r1,n1,o1,i1,s1,a1,c1,u1,Up,og,f1,l1,Sa,p1,h1,d1,y1,m1,g1,b1,w1,x1;(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 Mp=="object"&&typeof Mp.exports=="object"?r(t(e,t(Mp.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])};t1=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},r1=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},n1=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},o1=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 u=t.length-1;u>=0;u--)(c=t[u])&&(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},i1=function(t,n){return function(o,i){n(o,i,t)}},s1=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},a1=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 u(h){try{l(i.next(h))}catch(y){c(y)}}function p(h){try{l(i.throw(h))}catch(y){c(y)}}function l(h){h.done?a(h.value):s(h.value).then(u,p)}l((i=i.apply(t,n||[])).next())})},c1=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:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function u(l){return function(h){return p([l,h])}}function p(l){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=l[0]&2?s.return:l[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,l[1])).done)return a;switch(s=0,a&&(l=[l[0]&2,a.value]),l[0]){case 0:case 1:a=l;break;case 4:return o.label++,{value:l[1],done:!1};case 5:o.label++,s=l[1],l=[0];continue;case 7:l=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(l[0]===6||l[0]===2)){o=0;continue}if(l[0]===3&&(!a||l[1]>a[0]&&l[1]<a[3])){o.label=l[1];break}if(l[0]===6&&o.label<a[1]){o.label=a[1],a=l;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(l);break}a[2]&&o.ops.pop(),o.trys.pop();continue}l=n.call(t,o)}catch(h){l=[6,h],s=0}finally{i=a=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},x1=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},u1=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Up=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.")},og=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(u){c={error:u}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},f1=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(og(arguments[n]));return t},l1=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,u=a.length;c<u;c++,s++)i[s]=a[c];return i},Sa=function(t){return this instanceof Sa?(this.v=t,this):new Sa(t)},p1=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(m){i[m]&&(s[m]=function(w){return new Promise(function(g,A){a.push([m,w,g,A])>1||u(m,w)})})}function u(m,w){try{p(i[m](w))}catch(g){y(a[0][3],g)}}function p(m){m.value instanceof Sa?Promise.resolve(m.value.v).then(l,h):y(a[0][2],m)}function l(m){u("next",m)}function h(m){u("throw",m)}function y(m,w){m(w),a.shift(),a.length&&u(a[0][0],a[0][1])}},h1=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:Sa(t[s](c)),done:s==="return"}:a?a(c):c}:a}},d1=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 Up=="function"?Up(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(u,p){c=t[a](c),s(u,p,c.done,c.value)})}}function s(a,c,u,p){Promise.resolve(p).then(function(l){a({value:l,done:u})},c)}},y1=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},m1=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},g1=function(t){return t&&t.__esModule?t:{default:t}},b1=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},w1=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",t1),r("__assign",r1),r("__rest",n1),r("__decorate",o1),r("__param",i1),r("__metadata",s1),r("__awaiter",a1),r("__generator",c1),r("__exportStar",u1),r("__createBinding",x1),r("__values",Up),r("__read",og),r("__spread",f1),r("__spreadArrays",l1),r("__await",Sa),r("__asyncGenerator",p1),r("__asyncDelegator",h1),r("__asyncValues",d1),r("__makeTemplateObject",y1),r("__importStar",m1),r("__importDefault",g1),r("__classPrivateFieldGet",b1),r("__classPrivateFieldSet",w1)})});var QB={};Ct(QB,{webRTC:()=>JB,webRTCDirect:()=>YB});var wf=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},xf=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ps=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Va=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var vf=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},_f=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}};var hs=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var dn=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},$a=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},Go=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Sf=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Af=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Ef=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Cf=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Tf=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ro=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bf=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ds=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},If=class extends ds{constructor(e,t){super(!0,e,t)}},Of=class extends ds{constructor(e,t){super(!1,e,t)}};var Th=Symbol.for("@libp2p/peer-id");var Pf=Symbol.for("@libp2p/transport");var v0;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(v0||(v0={}));var fr=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 ys=Symbol.for("@libp2p/service-capabilities"),_0=Symbol.for("@libp2p/service-dependencies");var Nh={};Ct(Nh,{base58btc:()=>Ze,base58flickr:()=>FS});var NI=new Uint8Array(0);function S0(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 yn(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 A0(r){return new TextEncoder().encode(r)}function E0(r){return new TextDecoder().decode(r)}function US(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),u=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var w=0,g=0,A=0,D=m.length;A!==D&&m[A]===0;)A++,w++;for(var B=(D-A)*p+1>>>0,$=new Uint8Array(B);A!==D;){for(var Q=m[A],X=0,ne=B-1;(Q!==0||X<g)&&ne!==-1;ne--,X++)Q+=256*$[ne]>>>0,$[ne]=Q%a>>>0,Q=Q/a>>>0;if(Q!==0)throw new Error("Non-zero carry");g=X,A++}for(var Y=B-g;Y!==B&&$[Y]===0;)Y++;for(var I=c.repeat(w);Y<B;++Y)I+=r.charAt($[Y]);return I}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var w=0;if(m[w]!==" "){for(var g=0,A=0;m[w]===c;)g++,w++;for(var D=(m.length-w)*u+1>>>0,B=new Uint8Array(D);m[w];){var $=t[m.charCodeAt(w)];if($===255)return;for(var Q=0,X=D-1;($!==0||Q<A)&&X!==-1;X--,Q++)$+=a*B[X]>>>0,B[X]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");A=Q,w++}if(m[w]!==" "){for(var ne=D-A;ne!==D&&B[ne]===0;)ne++;for(var Y=new Uint8Array(g+(D-ne)),I=g;ne!==D;)Y[I++]=B[ne++];return Y}}}function y(m){var w=h(m);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:y}}var MS=US,KS=MS,T0=KS;var Bh=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")}},Ih=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 B0(this,e)}},Oh=class{decoders;constructor(e){this.decoders=e}or(e){return B0(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 B0(r,e){return new Oh({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ph=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 Bh(e,t,n),this.decoder=new Ih(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ms({name:r,prefix:e,encode:t,decode:n}){return new Ph(r,e,t,n)}function no({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=T0(t,r);return ms({prefix:e,name:r,encode:n,decode:i=>yn(o(i))})}function HS(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 u=0;u<o;++u){let p=e[r[u]];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 VS(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 $S(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=$S(n);return ms({prefix:e,name:r,encode(i){return VS(i,n,t)},decode(i){return HS(i,o,t,r)}})}var Ze=no({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),FS=no({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kh={};Ct(kh,{base32:()=>oo,base32hex:()=>zS,base32hexpad:()=>ZS,base32hexpadupper:()=>YS,base32hexupper:()=>XS,base32pad:()=>qS,base32padupper:()=>GS,base32upper:()=>WS,base32z:()=>JS});var oo=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),WS=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qS=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),GS=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zS=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),XS=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ZS=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),YS=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),JS=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dh={};Ct(Dh,{base36:()=>Fa,base36upper:()=>QS});var Fa=no({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),QS=no({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cr={};Ct(Cr,{Digest:()=>zo,create:()=>Dt,decode:()=>ws,equals:()=>jh,hasCode:()=>bA});var eA=P0,I0=128,tA=127,rA=~tA,nA=Math.pow(2,31);function P0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=nA;)e[t++]=r&255|I0,r/=128;for(;r&rA;)e[t++]=r&255|I0,r>>>=7;return e[t]=r|0,P0.bytes=t-n+1,e}var oA=Rh,iA=128,O0=127;function Rh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Rh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&O0)<<o:(s&O0)*Math.pow(2,o),o+=7}while(s>=iA);return Rh.bytes=i-n,t}var sA=Math.pow(2,7),aA=Math.pow(2,14),cA=Math.pow(2,21),uA=Math.pow(2,28),fA=Math.pow(2,35),lA=Math.pow(2,42),pA=Math.pow(2,49),hA=Math.pow(2,56),dA=Math.pow(2,63),yA=function(r){return r<sA?1:r<aA?2:r<cA?3:r<uA?4:r<fA?5:r<lA?6:r<pA?7:r<hA?8:r<dA?9:10},mA={encode:eA,decode:oA,encodingLength:yA},gA=mA,Wa=gA;function qa(r,e=0){return[Wa.decode(r,e),Wa.decode.bytes]}function gs(r,e,t=0){return Wa.encode(r,e,t),e}function bs(r){return Wa.encodingLength(r)}function Dt(r,e){let t=e.byteLength,n=bs(r),o=n+bs(t),i=new Uint8Array(o+t);return gs(r,i,0),gs(t,i,n),i.set(e,o),new zo(r,t,e,i)}function ws(r){let e=yn(r),[t,n]=qa(e),[o,i]=qa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new zo(t,o,s,e)}function jh(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&S0(r.bytes,t.bytes)}}var zo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function bA(r,e){return r.code===e}function N0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return xA(t,Lh(r),e??Ze.encoder);default:return vA(t,Lh(r),e??oo.encoder)}}var k0=new WeakMap;function Lh(r){let e=k0.get(r);if(e==null){let t=new Map;return k0.set(r,t),t}return e}var ct=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Ga)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==_A)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=Dt(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&&jh(e.multihash,n.multihash)}toString(e){return N0(this,e)}toJSON(){return{"/":N0(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??D0(n,o,i.bytes))}else if(t[SA]===!0){let{version:n,multihash:o,code:i}=t,s=ws(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ga)throw new Error(`Version 0 CID must use dag-pb (code: ${Ga}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=D0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ga,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=yn(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 zo(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[l,h]=qa(e.subarray(t));return t+=h,l},o=n(),i=Ga;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,p=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:u}}static parse(e,t){let[n,o]=wA(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 Lh(i).set(n,e),i}};function wA(r,e){switch(r[0]){case"Q":{let t=e??Ze;return[Ze.prefix,t.decode(`${Ze.prefix}${r}`)]}case Ze.prefix:{let t=e??Ze;return[Ze.prefix,t.decode(r)]}case oo.prefix:{let t=e??oo;return[oo.prefix,t.decode(r)]}case Fa.prefix:{let t=e??Fa;return[Fa.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 xA(r,e,t){let{prefix:n}=t;if(n!==Ze.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 vA(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Ga=112,_A=18;function D0(r,e,t){let n=bs(r),o=n+bs(e),i=new Uint8Array(o+t.byteLength);return gs(r,i,0),gs(e,i,n),i.set(t,o),i}var SA=Symbol.for("@ipld/js-cid/CID");var Uh={};Ct(Uh,{identity:()=>Tr});var R0=0,AA="identity",j0=yn;function EA(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Dt(R0,j0(r))}var Tr={code:R0,name:AA,encode:j0,digest:EA};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 ut(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function Rt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ft(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var U0=Symbol.for("@achingbrain/uint8arraylist");function L0(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 kf(r){return!!r?.[U0]}var me=class r{bufs;length;[U0]=!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(kf(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(kf(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=L0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=L0(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(kf(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 Rt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Rt(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 u=e>=a&&e<c,p=t>a&&t<=c;if(u&&p){if(e===a&&t===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(t-e)));break}if(u){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(!kf(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 l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,p;for(let l=t;l<=c;l+=p){p=0;for(let h=u;h>=0;h--){let y=this.get(l+h);if(n[h]!==y){p=Math.max(1,h-a[y]);break}}if(p===0)return l}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=ft(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=ut(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=ut(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=ut(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=ft(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=ut(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=ut(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=ut(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=ut(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=ut(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 Mh={};Ct(Mh,{base10:()=>TA});var TA=no({prefix:"9",name:"base10",alphabet:"0123456789"});var Kh={};Ct(Kh,{base16:()=>BA,base16upper:()=>IA});var BA=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),IA=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hh={};Ct(Hh,{base2:()=>OA});var OA=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vh={};Ct(Vh,{base256emoji:()=>RA});var M0=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}"),PA=M0.reduce((r,e,t)=>(r[t]=e,r),[]),NA=M0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function kA(r){return r.reduce((e,t)=>(e+=PA[t],e),"")}function DA(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=NA[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var RA=ms({prefix:"\u{1F680}",name:"base256emoji",encode:kA,decode:DA});var $h={};Ct($h,{base64:()=>jA,base64pad:()=>LA,base64url:()=>Xo,base64urlpad:()=>UA});var jA=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),LA=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xo=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),UA=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fh={};Ct(Fh,{base8:()=>MA});var MA=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Wh={};Ct(Wh,{identity:()=>KA});var KA=ms({prefix:"\0",name:"identity",encode:r=>E0(r),decode:r=>A0(r)});var dO=new TextEncoder,yO=new TextDecoder;var zh={};Ct(zh,{sha256:()=>lr,sha512:()=>FA});var $A=20;function Gh({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new qh(r,e,t,n,o)}var qh=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??$A,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?K0(n,this.code,t?.truncate):n.then(o=>K0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function K0(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Dt(e,r)}function V0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var lr=Gh({name:"sha2-256",code:18,encode:V0("SHA-256")}),FA=Gh({name:"sha2-512",code:19,encode:V0("SHA-512")});var Zo={...Wh,...Hh,...Fh,...Mh,...Kh,...kh,...Dh,...Nh,...$h,...Vh},TO={...zh,...Uh};function F0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var $0=F0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Xh=F0("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=ft(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),WA={utf8:$0,"utf-8":$0,hex:Zo.base16,latin1:Xh,ascii:Xh,binary:Xh,...Zo},Df=WA;function ye(r,e="utf8"){let t=Df[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function le(r,e="utf8"){let t=Df[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var qA=parseInt("11111",2),Zh=parseInt("10000000",2),GA=parseInt("01111111",2),W0={0:za,1:za,2:zA,3:YA,4:JA,5:ZA,6:XA,16:za,22:za,48:za};function mn(r,e={offset:0}){let t=r[e.offset]&qA;if(e.offset++,W0[t]!=null)return W0[t](r,e);throw new Error("No decoder for tag "+t)}function Xa(r,e){let t=0;if((r[e.offset]&Zh)===Zh){let n=r[e.offset]&GA,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 za(r,e){Xa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=mn(r,e);if(n===null)break;t.push(n)}return t}function zA(r,e){let t=Xa(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 XA(r,e){let t=Xa(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 u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let p=0;for(let l=0;l<c.length;l++)p+=c[l]<<l*7;a+=`.${p}`,c=[]}}return a}function ZA(r,e){return e.offset++,null}function YA(r,e){let t=Xa(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 JA(r,e){let t=Xa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function QA(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new me;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Rf(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=QA(r.byteLength);return new me(Uint8Array.from([e.byteLength|Zh]),e)}function jt(r){let e=new me,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new me(Uint8Array.from([2]),Rf(e),e)}function Za(r){let e=Uint8Array.from([0]),t=new me(e,r);return new me(Uint8Array.from([3]),Rf(t),t)}function q0(r){return new me(Uint8Array.from([4]),Rf(r),r)}function Br(r,e=48){let t=new me;for(let n of r)t.append(n);return new me(Uint8Array.from([e]),Rf(t),t)}async function G0(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 z0(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 X0(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 eE=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),tE=Uint8Array.from([6,5,43,129,4,0,34]),rE=Uint8Array.from([6,5,43,129,4,0,35]),nE={ext:!0,kty:"EC",crv:"P-256"},oE={ext:!0,kty:"EC",crv:"P-384"},iE={ext:!0,kty:"EC",crv:"P-521"},Yh=32,Jh=48,Qh=66;function ed(r){let e=mn(r);return Z0(e)}function Z0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Yh*2+1)return n=le(e.subarray(t,t+Yh),"base64url"),o=le(e.subarray(t+Yh),"base64url"),new Yo({...nE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Jh*2+1)return n=le(e.subarray(t,t+Jh),"base64url"),o=le(e.subarray(t+Jh),"base64url"),new Yo({...oE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Qh*2+1)return n=le(e.subarray(t,t+Qh),"base64url"),o=le(e.subarray(t+Qh),"base64url"),new Yo({...iE,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Y0(r){return Br([jt(Uint8Array.from([1])),q0(ye(r.d??"","base64url")),Br([Q0(r.crv)],160),Br([Za(new me(Uint8Array.from([4]),ye(r.x??"","base64url"),ye(r.y??"","base64url")))],161)]).subarray()}function J0(r){return Br([jt(Uint8Array.from([1])),Br([Q0(r.crv)],160),Br([Za(new me(Uint8Array.from([4]),ye(r.x??"","base64url"),ye(r.y??"","base64url")))],161)]).subarray()}function Q0(r){if(r==="P-256")return eE;if(r==="P-384")return tE;if(r==="P-521")return rE;throw new ve(`Invalid curve ${r}`)}async function eb(r="P-256"){let e=await G0(r);return new jf(e.privateKey)}var Yo=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=J0(this.jwk)),this._raw}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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 X0(this.jwk,t,e,n)}},jf=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Yo({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=Y0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async sign(e,t){return z0(this.jwk,e,t)}};var Jo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bn(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Qo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Tt(r,...e){if(!bn(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 ei(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Qo(r.outputLen),Qo(r.blockLen)}function vs(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 rb(r,e){Tt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Ir(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Lf(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Or(r,e){return r<<32-e|r>>>e}var nb=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",sE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function pr(r){if(Tt(r),nb)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=sE[r[t]];return e}var gn={_0:48,_9:57,A:65,F:70,a:97,f:102};function tb(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 ti(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(nb)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=tb(r.charCodeAt(i)),a=tb(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 td(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function so(r){return typeof r=="string"&&(r=td(r)),Tt(r),r}function Lt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Tt(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 xs=class{};function rd(r){let e=n=>r().update(so(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ao(r=32){if(Jo&&typeof Jo.getRandomValues=="function")return Jo.getRandomValues(new Uint8Array(r));if(Jo&&typeof Jo.randomBytes=="function")return Uint8Array.from(Jo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function aE(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,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function ob(r,e,t){return r&e^~r&t}function ib(r,e,t){return r&e^r&t^e&t}var Ya=class extends xs{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=Lf(this.buffer)}update(e){vs(this),e=so(e),Tt(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=Lf(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){vs(this),rb(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Ir(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;aE(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Lf(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,p=this.get();if(u>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,p[l],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()}},wn=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 Uf=BigInt(4294967295),sb=BigInt(32);function cE(r,e=!1){return e?{h:Number(r&Uf),l:Number(r>>sb&Uf)}:{h:Number(r>>sb&Uf)|0,l:Number(r&Uf)|0}}function ab(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}=cE(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var nd=(r,e,t)=>r>>>t,od=(r,e,t)=>r<<32-t|e>>>t,ri=(r,e,t)=>r>>>t|e<<32-t,ni=(r,e,t)=>r<<32-t|e>>>t,Ja=(r,e,t)=>r<<64-t|e>>>t-32,Qa=(r,e,t)=>r>>>t-32|e<<64-t;function zr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var cb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ub=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,fb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),lb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,pb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),hb=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var fE=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]),co=new Uint32Array(64),Mf=class extends Ya{constructor(e=32){super(64,e,8,!1),this.A=wn[0]|0,this.B=wn[1]|0,this.C=wn[2]|0,this.D=wn[3]|0,this.E=wn[4]|0,this.F=wn[5]|0,this.G=wn[6]|0,this.H=wn[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 l=0;l<16;l++,t+=4)co[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=co[l-15],y=co[l-2],m=Or(h,7)^Or(h,18)^h>>>3,w=Or(y,17)^Or(y,19)^y>>>10;co[l]=w+co[l-7]+m+co[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:p}=this;for(let l=0;l<64;l++){let h=Or(a,6)^Or(a,11)^Or(a,25),y=p+h+ob(a,c,u)+fE[l]+co[l]|0,w=(Or(n,2)^Or(n,13)^Or(n,22))+ib(n,o,i)|0;p=u,u=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,u,p)}roundClean(){Ir(co)}destroy(){this.set(0,0,0,0,0,0,0,0),Ir(this.buffer)}};var db=ab(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),lE=db[0],pE=db[1],uo=new Uint32Array(80),fo=new Uint32Array(80),id=class extends Ya{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:u,El:p,Fh:l,Fl:h,Gh:y,Gl:m,Hh:w,Hl:g}=this;return[e,t,n,o,i,s,a,c,u,p,l,h,y,m,w,g]}set(e,t,n,o,i,s,a,c,u,p,l,h,y,m,w,g){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=u|0,this.El=p|0,this.Fh=l|0,this.Fl=h|0,this.Gh=y|0,this.Gl=m|0,this.Hh=w|0,this.Hl=g|0}process(e,t){for(let B=0;B<16;B++,t+=4)uo[B]=e.getUint32(t),fo[B]=e.getUint32(t+=4);for(let B=16;B<80;B++){let $=uo[B-15]|0,Q=fo[B-15]|0,X=ri($,Q,1)^ri($,Q,8)^nd($,Q,7),ne=ni($,Q,1)^ni($,Q,8)^od($,Q,7),Y=uo[B-2]|0,I=fo[B-2]|0,K=ri(Y,I,19)^Ja(Y,I,61)^nd(Y,I,6),z=ni(Y,I,19)^Qa(Y,I,61)^od(Y,I,6),V=fb(ne,z,fo[B-7],fo[B-16]),x=lb(V,X,K,uo[B-7],uo[B-16]);uo[B]=x|0,fo[B]=V|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:p,Eh:l,El:h,Fh:y,Fl:m,Gh:w,Gl:g,Hh:A,Hl:D}=this;for(let B=0;B<80;B++){let $=ri(l,h,14)^ri(l,h,18)^Ja(l,h,41),Q=ni(l,h,14)^ni(l,h,18)^Qa(l,h,41),X=l&y^~l&w,ne=h&m^~h&g,Y=pb(D,Q,ne,pE[B],fo[B]),I=hb(Y,A,$,X,lE[B],uo[B]),K=Y|0,z=ri(n,o,28)^Ja(n,o,34)^Ja(n,o,39),V=ni(n,o,28)^Qa(n,o,34)^Qa(n,o,39),x=n&i^n&a^i&a,v=o&s^o&c^s&c;A=w|0,D=g|0,w=y|0,g=m|0,y=l|0,m=h|0,{h:l,l:h}=zr(u|0,p|0,I|0,K|0),u=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let E=cb(K,V,v);n=ub(E,I,z,x),o=E|0}({h:n,l:o}=zr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=zr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=zr(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:p}=zr(this.Dh|0,this.Dl|0,u|0,p|0),{h:l,l:h}=zr(this.Eh|0,this.El|0,l|0,h|0),{h:y,l:m}=zr(this.Fh|0,this.Fl|0,y|0,m|0),{h:w,l:g}=zr(this.Gh|0,this.Gl|0,w|0,g|0),{h:A,l:D}=zr(this.Hh|0,this.Hl|0,A|0,D|0),this.set(n,o,i,s,a,c,u,p,l,h,y,m,w,g,A,D)}roundClean(){Ir(uo,fo)}destroy(){Ir(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var lo=rd(()=>new Mf);var yb=rd(()=>new id);var cd=BigInt(0),ad=BigInt(1);function xn(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}"`;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function tr(r,e,t=""){let n=bn(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function ec(r){let e=r.toString(16);return e.length&1?"0"+e:e}function mb(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?cd:BigInt("0x"+r)}function _s(r){return mb(pr(r))}function hr(r){return Tt(r),mb(pr(Uint8Array.from(r).reverse()))}function Kf(r,e){return ti(r.toString(16).padStart(e*2,"0"))}function tc(r,e){return Kf(r,e).reverse()}function Oe(r,e,t){let n;if(typeof e=="string")try{n=ti(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(bn(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 gb(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function ud(r){return Uint8Array.from(r)}var sd=r=>typeof r=="bigint"&&cd<=r;function bb(r,e,t){return sd(r)&&sd(e)&&sd(t)&&e<=r&&r<t}function po(r,e,t,n){if(!bb(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Hf(r){let e;for(e=0;r>cd;r>>=ad,e+=1);return e}var ho=r=>(ad<<BigInt(r))-ad;function wb(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},u=(...y)=>t(s,i,...y),p=(y=n(0))=>{s=u(o(0),y),i=u(),y.length!==0&&(s=u(o(1),y),i=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,m=[];for(;y<e;){i=u();let w=i.slice();m.push(w),y+=i.length}return Lt(...m)};return(y,m)=>{c(),p(y);let w;for(;!(w=m(l()));)p();return c(),w}}function Xr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}var fd=()=>{throw new Error("not implemented")};function Ss(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var Ut=BigInt(0),pt=BigInt(1),oi=BigInt(2),_b=BigInt(3),Sb=BigInt(4),Ab=BigInt(5),hE=BigInt(7),Eb=BigInt(8),dE=BigInt(9),Cb=BigInt(16);function $e(r,e){let t=r%e;return t>=Ut?t:e+t}function Fe(r,e,t){let n=r;for(;e-- >Ut;)n*=n,n%=t;return n}function xb(r,e){if(r===Ut)throw new Error("invert: expected non-zero number");if(e<=Ut)throw new Error("invert: expected positive modulus, got "+e);let t=$e(r,e),n=e,o=Ut,i=pt,s=pt,a=Ut;for(;t!==Ut;){let u=n/t,p=n%t,l=o-s*u,h=i-a*u;n=t,t=p,o=s,i=a,s=l,a=h}if(n!==pt)throw new Error("invert: does not exist");return $e(o,e)}function ld(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function Tb(r,e){let t=(r.ORDER+pt)/Sb,n=r.pow(e,t);return ld(r,n,e),n}function yE(r,e){let t=(r.ORDER-Ab)/Eb,n=r.mul(e,oi),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,oi),o),a=r.mul(i,r.sub(s,r.ONE));return ld(r,a,e),a}function mE(r){let e=rr(r),t=Bb(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+hE)/Cb;return(a,c)=>{let u=a.pow(c,s),p=a.mul(u,n),l=a.mul(u,o),h=a.mul(u,i),y=a.eql(a.sqr(p),c),m=a.eql(a.sqr(l),c);u=a.cmov(u,p,y),p=a.cmov(h,l,m);let w=a.eql(a.sqr(p),c),g=a.cmov(u,p,w);return ld(a,g,c),g}}function Bb(r){if(r<_b)throw new Error("sqrt is not defined for small field");let e=r-pt,t=0;for(;e%oi===Ut;)e/=oi,t++;let n=oi,o=rr(r);for(;vb(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Tb;let i=o.pow(n,e),s=(e+pt)/oi;return function(c,u){if(c.is0(u))return u;if(vb(c,u)!==1)throw new Error("Cannot find square root");let p=t,l=c.mul(c.ONE,i),h=c.pow(u,e),y=c.pow(u,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,w=c.sqr(h);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===p)throw new Error("Cannot find square root");let g=pt<<BigInt(p-m-1),A=c.pow(l,g);p=m,l=c.sqr(A),h=c.mul(h,l),y=c.mul(y,A)}return y}}function gE(r){return r%Sb===_b?Tb:r%Eb===Ab?yE:r%Cb===dE?mE(r):Bb(r)}var vn=(r,e)=>($e(r,e)&pt)===pt,bE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function pd(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=bE.reduce((n,o)=>(n[o]="function",n),e);return Xr(r,t),r}function wE(r,e,t){if(t<Ut)throw new Error("invalid exponent, negatives unsupported");if(t===Ut)return r.ONE;if(t===pt)return e;let n=r.ONE,o=e;for(;t>Ut;)t&pt&&(n=r.mul(n,o)),o=r.sqr(o),t>>=pt;return n}function rc(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 vb(r,e){let t=(r.ORDER-pt)/oi,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 Vf(r,e){e!==void 0&&Qo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function rr(r,e,t=!1,n={}){if(r<=Ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i,s=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(o=h.BITS),h.sqrt&&(i=h.sqrt),typeof h.isLE=="boolean"&&(t=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),a=h.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=Vf(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:r,isLE:t,BITS:c,BYTES:u,MASK:ho(c),ZERO:Ut,ONE:pt,allowedLengths:a,create:h=>$e(h,r),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return Ut<=h&&h<r},is0:h=>h===Ut,isValidNot0:h=>!l.is0(h)&&l.isValid(h),isOdd:h=>(h&pt)===pt,neg:h=>$e(-h,r),eql:(h,y)=>h===y,sqr:h=>$e(h*h,r),add:(h,y)=>$e(h+y,r),sub:(h,y)=>$e(h-y,r),mul:(h,y)=>$e(h*y,r),pow:(h,y)=>wE(l,h,y),div:(h,y)=>$e(h*xb(y,r),r),sqrN:h=>h*h,addN:(h,y)=>h+y,subN:(h,y)=>h-y,mulN:(h,y)=>h*y,inv:h=>xb(h,r),sqrt:i||(h=>(p||(p=gE(r)),p(l,h))),toBytes:h=>t?tc(h,u):Kf(h,u),fromBytes:(h,y=!0)=>{if(a){if(!a.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+h.length);let w=new Uint8Array(u);w.set(h,t?0:w.length-h.length),h=w}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let m=t?hr(h):_s(h);if(s&&(m=$e(m,r)),!y&&!l.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>rc(l,h),cmov:(h,y,m)=>m?y:h});return Object.freeze(l)}function Ib(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 hd(r){let e=Ib(r);return e+Math.ceil(e/2)}function dd(r,e,t=!1){let n=r.length,o=Ib(e),i=hd(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?hr(r):_s(r),a=$e(s,e-pt)+pt;return t?tc(a,o):Kf(a,o)}var As=BigInt(0),ii=BigInt(1);function nc(r,e){let t=e.negate();return r?t:e}function _n(r,e){let t=rc(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function kb(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function yd(r,e){kb(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=ho(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Ob(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=ii);let u=e*n,p=u+Math.abs(a)-1,l=a===0,h=a<0,y=e%2!==0;return{nextN:c,offset:p,isZero:l,isNeg:h,isNegF:y,offsetF:u}}function xE(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 vE(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 md=new WeakMap,Db=new WeakMap;function gd(r){return Db.get(r)||1}function Pb(r){if(r!==As)throw new Error("invalid wNAF")}var Es=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>As;)t&ii&&(n=n.add(o)),o=o.double(),t>>=ii;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=yd(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=yd(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:p,isNeg:l,isNegF:h,offsetF:y}=Ob(n,a,s);n=c,p?i=i.add(nc(h,t[y])):o=o.add(nc(l,t[u]))}return Pb(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=yd(e,this.bits);for(let s=0;s<i.windows&&n!==As;s++){let{nextN:a,offset:c,isZero:u,isNeg:p}=Ob(n,s,i);if(n=a,!u){let l=t[c];o=o.add(p?l.negate():l)}}return Pb(n),o}getPrecomputes(e,t,n){let o=md.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),md.set(t,o))),o}cached(e,t,n){let o=gd(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=gd(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){kb(t,this.bits),Db.set(e,t),md.delete(e)}hasCache(e){return gd(e)!==1}};function Rb(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>As||n>As;)t&ii&&(i=i.add(o)),n&ii&&(s=s.add(o)),o=o.double(),t>>=ii,n>>=ii;return{p1:i,p2:s}}function Cs(r,e,t,n){xE(t,r),vE(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=Hf(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ho(c),p=new Array(Number(u)+1).fill(s),l=Math.floor((e.BITS-1)/c)*c,h=s;for(let y=l;y>=0;y-=c){p.fill(s);for(let w=0;w<i;w++){let g=n[w],A=Number(g>>BigInt(y)&u);p[A]=p[A].add(t[w])}let m=s;for(let w=p.length-1,g=s;w>0;w--)g=g.add(p[w]),m=m.add(g);if(h=h.add(m),y!==0)for(let w=0;w<c;w++)h=h.double()}return h}function Nb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return pd(e),e}else return rr(r,{isLE:t})}function $f(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>As))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Nb(e.p,t.Fp,n),i=Nb(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}var yo=BigInt(0),ht=BigInt(1),bd=BigInt(2),_E=BigInt(8);function SE(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function AE(r,e={}){let t=$f("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;Xr(e,{},{uvRatio:"function"});let a=bd<<BigInt(o.BYTES*8)-ht,c=g=>n.create(g),u=e.uvRatio||((g,A)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,A))}}catch{return{isValid:!1,value:yo}}});if(!SE(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(g,A,D=!1){let B=D?ht:yo;return po("coordinate "+g,A,B,a),A}function l(g){if(!(g instanceof m))throw new Error("ExtendedPoint expected")}let h=Ss((g,A)=>{let{X:D,Y:B,Z:$}=g,Q=g.is0();A==null&&(A=Q?_E:n.inv($));let X=c(D*A),ne=c(B*A),Y=n.mul($,A);if(Q)return{x:yo,y:ht};if(Y!==ht)throw new Error("invZ was invalid");return{x:X,y:ne}}),y=Ss(g=>{let{a:A,d:D}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:B,Y:$,Z:Q,T:X}=g,ne=c(B*B),Y=c($*$),I=c(Q*Q),K=c(I*I),z=c(ne*A),V=c(I*c(z+Y)),x=c(K+c(D*c(ne*Y)));if(V!==x)throw new Error("bad point: equation left != right (1)");let v=c(B*$),E=c(Q*X);if(v!==E)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(A,D,B,$){this.X=p("x",A),this.Y=p("y",D),this.Z=p("z",B,!0),this.T=p("t",$),Object.freeze(this)}static CURVE(){return i}static fromAffine(A){if(A instanceof m)throw new Error("extended point not allowed");let{x:D,y:B}=A||{};return p("x",D),p("y",B),new m(D,B,ht,c(D*B))}static fromBytes(A,D=!1){let B=n.BYTES,{a:$,d:Q}=i;A=ud(tr(A,B,"point")),xn(D,"zip215");let X=ud(A),ne=A[B-1];X[B-1]=ne&-129;let Y=hr(X),I=D?a:n.ORDER;po("point.y",Y,yo,I);let K=c(Y*Y),z=c(K-ht),V=c(Q*K-$),{isValid:x,value:v}=u(z,V);if(!x)throw new Error("bad point: invalid y coordinate");let E=(v&ht)===ht,N=(ne&128)!==0;if(!D&&v===yo&&N)throw new Error("bad point: x=0 and x_0=1");return N!==E&&(v=c(-v)),m.fromAffine({x:v,y:Y})}static fromHex(A,D=!1){return m.fromBytes(Oe("point",A),D)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(A=8,D=!0){return w.createCache(this,A),D||this.multiply(bd),this}assertValidity(){y(this)}equals(A){l(A);let{X:D,Y:B,Z:$}=this,{X:Q,Y:X,Z:ne}=A,Y=c(D*ne),I=c(Q*$),K=c(B*ne),z=c(X*$);return Y===I&&K===z}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:A}=i,{X:D,Y:B,Z:$}=this,Q=c(D*D),X=c(B*B),ne=c(bd*c($*$)),Y=c(A*Q),I=D+B,K=c(c(I*I)-Q-X),z=Y+X,V=z-ne,x=Y-X,v=c(K*V),E=c(z*x),N=c(K*x),j=c(V*z);return new m(v,E,j,N)}add(A){l(A);let{a:D,d:B}=i,{X:$,Y:Q,Z:X,T:ne}=this,{X:Y,Y:I,Z:K,T:z}=A,V=c($*Y),x=c(Q*I),v=c(ne*B*z),E=c(X*K),N=c(($+Q)*(Y+I)-V-x),j=E-v,U=E+v,P=c(x-D*V),L=c(N*j),q=c(U*P),R=c(N*P),he=c(j*U);return new m(L,q,he,R)}subtract(A){return this.add(A.negate())}multiply(A){if(!o.isValidNot0(A))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:D,f:B}=w.cached(this,A,$=>_n(m,$));return _n(m,[D,B])[0]}multiplyUnsafe(A,D=m.ZERO){if(!o.isValid(A))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return A===yo?m.ZERO:this.is0()||A===ht?this:w.unsafe(this,A,B=>_n(m,B),D)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return w.unsafe(this,i.n).is0()}toAffine(A){return h(this,A)}clearCofactor(){return s===ht?this:this.multiplyUnsafe(s)}toBytes(){let{x:A,y:D}=this.toAffine(),B=n.toBytes(D);return B[B.length-1]|=A&ht?128:0,B}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(A){return _n(m,A)}static msm(A,D){return Cs(m,o,A,D)}_setWindowSize(A){this.precompute(A)}toRawBytes(){return this.toBytes()}}m.BASE=new m(i.Gx,i.Gy,ht,c(i.Gx*i.Gy)),m.ZERO=new m(yo,ht,ht,yo),m.Fp=n,m.Fn=o;let w=new Es(m,o.BITS);return m.BASE.precompute(8),m}var Ff=class{constructor(e){this.ep=e}static fromBytes(e){fd()}static fromHex(e){fd()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return pr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}toRawBytes(){return this.toBytes()}};function EE(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');Xr(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||ao,c=t.adjustScalarBytes||(I=>I),u=t.domain||((I,K,z)=>{if(xn(z,"phflag"),K.length||z)throw new Error("Contexts/pre-hash are not supported");return I});function p(I){return s.create(hr(I))}function l(I){let K=B.secretKey;I=Oe("private key",I,K);let z=Oe("hashed private key",e(I),2*K),V=c(z.slice(0,K)),x=z.slice(K,2*K),v=p(V);return{head:V,prefix:x,scalar:v}}function h(I){let{head:K,prefix:z,scalar:V}=l(I),x=o.multiply(V),v=x.toBytes();return{head:K,prefix:z,scalar:V,point:x,pointBytes:v}}function y(I){return h(I).pointBytes}function m(I=Uint8Array.of(),...K){let z=Lt(...K);return p(e(u(z,Oe("context",I),!!n)))}function w(I,K,z={}){I=Oe("message",I),n&&(I=n(I));let{prefix:V,scalar:x,pointBytes:v}=h(K),E=m(z.context,V,I),N=o.multiply(E).toBytes(),j=m(z.context,N,v,I),U=s.create(E+j*x);if(!s.isValid(U))throw new Error("sign failed: invalid s");let P=Lt(N,s.toBytes(U));return tr(P,B.signature,"result")}let g={zip215:!0};function A(I,K,z,V=g){let{context:x,zip215:v}=V,E=B.signature;I=Oe("signature",I,E),K=Oe("message",K),z=Oe("publicKey",z,B.publicKey),v!==void 0&&xn(v,"zip215"),n&&(K=n(K));let N=E/2,j=I.subarray(0,N),U=hr(I.subarray(N,E)),P,L,q;try{P=r.fromBytes(z,v),L=r.fromBytes(j,v),q=o.multiplyUnsafe(U)}catch{return!1}if(!v&&P.isSmallOrder())return!1;let R=m(x,L.toBytes(),P.toBytes(),K);return L.add(P.multiplyUnsafe(R)).subtract(q).clearCofactor().is0()}let D=i.BYTES,B={secretKey:D,publicKey:D,signature:2*D,seed:D};function $(I=a(B.seed)){return tr(I,B.seed,"seed")}function Q(I){let K=Y.randomSecretKey(I);return{secretKey:K,publicKey:y(K)}}function X(I){return bn(I)&&I.length===s.BYTES}function ne(I,K){try{return!!r.fromBytes(I,K)}catch{return!1}}let Y={getExtendedPublicKey:h,randomSecretKey:$,isValidSecretKey:X,isValidPublicKey:ne,toMontgomery(I){let{y:K}=r.fromBytes(I),z=B.publicKey,V=z===32;if(!V&&z!==57)throw new Error("only defined for 25519 and 448");let x=V?i.div(ht+K,ht-K):i.div(K-ht,K+ht);return i.toBytes(x)},toMontgomerySecret(I){let K=B.secretKey;tr(I,K);let z=e(I.subarray(0,K));return c(z).subarray(0,K)},randomPrivateKey:$,precompute(I=8,K=r.BASE){return K.precompute(I,!1)}};return Object.freeze({keygen:Q,getPublicKey:y,sign:w,verify:A,utils:Y,Point:r,lengths:B})}function CE(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=rr(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,hash:r.hash,eddsaOpts:i}}function TE(r,e){let t=e.Point;return Object.assign({},e,{ExtendedPoint:t,CURVE:r,nBitLength:t.Fn.BITS,nByteLength:t.Fn.BYTES})}function jb(r){let{CURVE:e,curveOpts:t,hash:n,eddsaOpts:o}=CE(r),i=AE(e,t),s=EE(i,n,o);return TE(r,s)}var oc=BigInt(0),Ts=BigInt(1),Wf=BigInt(2);function BE(r){return Xr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function Lb(r){let e=BE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||ao,u=a?255:448,p=a?32:56,l=BigInt(a?9:5),h=BigInt(a?121665:39081),y=a?Wf**BigInt(254):Wf**BigInt(447),m=a?BigInt(8)*Wf**BigInt(251)-Ts:BigInt(4)*Wf**BigInt(445)-Ts,w=y+m+Ts,g=x=>$e(x,t),A=D(l);function D(x){return tc(g(x),p)}function B(x){let v=Oe("u coordinate",x,p);return a&&(v[31]&=127),g(hr(v))}function $(x){return hr(o(Oe("scalar",x,p)))}function Q(x,v){let E=Y(B(v),$(x));if(E===oc)throw new Error("invalid private or public key received");return D(E)}function X(x){return Q(x,A)}function ne(x,v,E){let N=g(x*(v-E));return v=g(v-N),E=g(E+N),{x_2:v,x_3:E}}function Y(x,v){po("u",x,oc,t),po("scalar",v,y,w);let E=v,N=x,j=Ts,U=oc,P=x,L=Ts,q=oc;for(let he=BigInt(u-1);he>=oc;he--){let be=E>>he&Ts;q^=be,{x_2:j,x_3:P}=ne(q,j,P),{x_2:U,x_3:L}=ne(q,U,L),q=be;let te=j+U,Se=g(te*te),Te=j-U,Ue=g(Te*Te),Ee=Se-Ue,Re=P+L,hn=P-L,ur=g(hn*te),to=g(Re*Te),gf=ur+to,ls=ur-to;P=g(gf*gf),L=g(N*g(ls*ls)),j=g(Se*Ue),U=g(Ee*(Se+g(h*Ee)))}({x_2:j,x_3:P}=ne(q,j,P)),{x_2:U,x_3:L}=ne(q,U,L);let R=i(U);return g(j*R)}let I={secretKey:p,publicKey:p,seed:p},K=(x=c(p))=>(Tt(x,I.seed),x);function z(x){let v=K(x);return{secretKey:v,publicKey:X(v)}}return{keygen:z,getSharedSecret:(x,v)=>Q(x,v),getPublicKey:x=>X(x),scalarMult:Q,scalarMultBase:X,utils:{randomSecretKey:K,randomPrivateKey:K},GuBytes:A.slice(),lengths:I}}var IE=BigInt(0),An=BigInt(1),Ub=BigInt(2),OE=BigInt(3),PE=BigInt(5),NE=BigInt(8),Bs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ic={p:Bs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:NE,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Hb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Bs,a=r*r%i*r%i,c=Fe(a,Ub,i)*a%i,u=Fe(c,An,i)*r%i,p=Fe(u,PE,i)*u%i,l=Fe(p,e,i)*p%i,h=Fe(l,t,i)*l%i,y=Fe(h,n,i)*h%i,m=Fe(y,o,i)*y%i,w=Fe(m,o,i)*y%i,g=Fe(w,e,i)*p%i;return{pow_p_5_8:Fe(g,Ub,i)*r%i,b2:a}}function Vb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var wd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function _d(r,e){let t=Bs,n=$e(e*e*e,t),o=$e(n*n*e,t),i=Hb(r*o).pow_p_5_8,s=$e(r*n*i,t),a=$e(e*s*s,t),c=s,u=$e(s*wd,t),p=a===r,l=a===$e(-r,t),h=a===$e(-r*wd,t);return p&&(s=c),(l||h)&&(s=u),vn(s,t)&&(s=$e(-s,t)),{isValid:p||l,value:s}}var Sn=rr(ic.p,{isLE:!0}),kE=rr(ic.n,{isLE:!0}),DE={...ic,Fp:Sn,hash:yb,adjustScalarBytes:Vb,uvRatio:_d},dr=jb(DE);var sc=(()=>{let r=Sn.ORDER;return Lb({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=Hb(e);return $e(Fe(t,OE,r)*n,r)},adjustScalarBytes:Vb})})();var xd=wd,RE=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jE=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),LE=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),UE=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Mb=r=>_d(An,r),ME=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),vd=r=>dr.Point.Fp.create(hr(r)&ME);function Kb(r){let{d:e}=ic,t=Bs,n=A=>Sn.create(A),o=n(xd*r*r),i=n((o+An)*LE),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=_d(i,a),p=n(u*r);vn(p,t)||(p=n(-p)),c||(u=p),c||(s=o);let l=n(s*(o-An)*UE-a),h=u*u,y=n((u+u)*a),m=n(l*RE),w=n(An-h),g=n(An+h);return new dr.Point(n(y*g),n(w*m),n(m*g),n(y*w))}function KE(r){Tt(r,64);let e=vd(r.subarray(0,32)),t=Kb(e),n=vd(r.subarray(32,64)),o=Kb(n);return new En(t.add(o))}var En=class r extends Ff{constructor(e){super(e)}static fromAffine(e){return new r(dr.Point.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static hashToCurve(e){return KE(Oe("ristrettoHash",e,64))}static fromBytes(e){Tt(e,32);let{a:t,d:n}=ic,o=Bs,i=$=>Sn.create($),s=vd(e);if(!gb(Sn.toBytes(s),e)||vn(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(An+t*a),u=i(An-t*a),p=i(c*c),l=i(u*u),h=i(t*n*p-l),{isValid:y,value:m}=Mb(i(h*l)),w=i(m*u),g=i(m*w*h),A=i((s+s)*w);vn(A,o)&&(A=i(-A));let D=i(c*g),B=i(A*D);if(!y||vn(B,o)||D===IE)throw new Error("invalid ristretto255 encoding 2");return new r(new dr.Point(A,D,An,B))}static fromHex(e){return r.fromBytes(Oe("ristrettoHex",e,32))}static msm(e,t){return Cs(r,dr.Point.Fn,e,t)}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,i=Bs,s=g=>Sn.create(g),a=s(s(n+t)*s(n-t)),c=s(e*t),u=s(c*c),{value:p}=Mb(s(a*u)),l=s(p*a),h=s(p*c),y=s(l*h*o),m;if(vn(o*y,i)){let g=s(t*xd),A=s(e*xd);e=g,t=A,m=s(l*jE)}else m=h;vn(e*y,i)&&(t=s(-t));let w=s((n-t)*m);return vn(w,i)&&(w=s(-w)),Sn.toBytes(w)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>Sn.create(u),a=s(t*i)===s(n*o),c=s(n*i)===s(t*o);return a||c}is0(){return this.equals(r.ZERO)}};En.BASE=new En(dr.Point.BASE);En.ZERO=new En(dr.Point.ZERO);En.Fp=Sn;En.Fn=kE;var ac=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},cc=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},qf=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var $b={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new qf("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 Ft=$b;var Gf=32,uc=64,Sd=32;var Is,Fb=(async()=>{try{return await Ft.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Wb(){let r=dr.utils.randomPrivateKey(),e=dr.getPublicKey(r);return{privateKey:WE(r,e),publicKey:e}}async function HE(r,e){let t;r.length===uc?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:le(r.subarray(32),"base64url"),d:le(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Ft.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ft.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function VE(r,e){let t=r.subarray(0,Sd);return dr.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function qb(r,e){return Is==null&&(Is=await Fb),Is?HE(r,e):VE(r,e)}async function $E(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Ft.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ft.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 FE(r,e,t){return dr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Gb(r,e,t){return Is==null&&(Is=await Fb),Is?$E(r,e,t):FE(r,e,t)}function WE(r,e){let t=new Uint8Array(uc);for(let n=0;n<Sd;n++)t[n]=r[n],t[Sd+n]=e[n];return t}function Os(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var fc=class{type="Ed25519";raw;constructor(e){this.raw=Xf(e,Gf)}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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=Gb(this.raw,t,e);return Os(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},zf=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Xf(e,uc),this.publicKey=new fc(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=qb(this.raw,e);return Os(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Ad(r){return r=Xf(r,Gf),new fc(r)}async function Xb(){let{privateKey:r,publicKey:e}=Wb();return new zf(r,e)}function Xf(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var qE=Math.pow(2,7),GE=Math.pow(2,14),zE=Math.pow(2,21),Ed=Math.pow(2,28),Cd=Math.pow(2,35),Td=Math.pow(2,42),Bd=Math.pow(2,49),ke=128,Bt=127;function We(r){if(r<qE)return 1;if(r<GE)return 2;if(r<zE)return 3;if(r<Ed)return 4;if(r<Cd)return 5;if(r<Td)return 6;if(r<Bd)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ps(r,e,t=0){switch(We(r)){case 8:e[t++]=r&255|ke,r/=128;case 7:e[t++]=r&255|ke,r/=128;case 6:e[t++]=r&255|ke,r/=128;case 5:e[t++]=r&255|ke,r/=128;case 4:e[t++]=r&255|ke,r>>>=7;case 3:e[t++]=r&255|ke,r>>>=7;case 2:e[t++]=r&255|ke,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function XE(r,e,t=0){switch(We(r)){case 8:e.set(t++,r&255|ke),r/=128;case 7:e.set(t++,r&255|ke),r/=128;case 6:e.set(t++,r&255|ke),r/=128;case 5:e.set(t++,r&255|ke),r/=128;case 4:e.set(t++,r&255|ke),r>>>=7;case 3:e.set(t++,r&255|ke),r>>>=7;case 2:e.set(t++,r&255|ke),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Id(r,e){let t=r[e],n=0;if(n+=t&Bt,t<ke||(t=r[e+1],n+=(t&Bt)<<7,t<ke)||(t=r[e+2],n+=(t&Bt)<<14,t<ke)||(t=r[e+3],n+=(t&Bt)<<21,t<ke)||(t=r[e+4],n+=(t&Bt)*Ed,t<ke)||(t=r[e+5],n+=(t&Bt)*Cd,t<ke)||(t=r[e+6],n+=(t&Bt)*Td,t<ke)||(t=r[e+7],n+=(t&Bt)*Bd,t<ke))return n;throw new RangeError("Could not decode varint")}function ZE(r,e){let t=r.get(e),n=0;if(n+=t&Bt,t<ke||(t=r.get(e+1),n+=(t&Bt)<<7,t<ke)||(t=r.get(e+2),n+=(t&Bt)<<14,t<ke)||(t=r.get(e+3),n+=(t&Bt)<<21,t<ke)||(t=r.get(e+4),n+=(t&Bt)*Ed,t<ke)||(t=r.get(e+5),n+=(t&Bt)*Cd,t<ke)||(t=r.get(e+6),n+=(t&Bt)*Td,t<ke)||(t=r.get(e+7),n+=(t&Bt)*Bd,t<ke))return n;throw new RangeError("Could not decode varint")}function Zf(r,e,t=0){return e==null&&(e=ft(We(r))),e instanceof Uint8Array?Ps(r,e,t):XE(r,e,t)}function Cn(r,e=0){return r instanceof Uint8Array?Id(r,e):ZE(r,e)}var Od=new Float32Array([-0]),mo=new Uint8Array(Od.buffer);function Zb(r,e,t){Od[0]=r,e[t]=mo[0],e[t+1]=mo[1],e[t+2]=mo[2],e[t+3]=mo[3]}function Yb(r,e){return mo[0]=r[e],mo[1]=r[e+1],mo[2]=r[e+2],mo[3]=r[e+3],Od[0]}var Pd=new Float64Array([-0]),It=new Uint8Array(Pd.buffer);function Jb(r,e,t){Pd[0]=r,e[t]=It[0],e[t+1]=It[1],e[t+2]=It[2],e[t+3]=It[3],e[t+4]=It[4],e[t+5]=It[5],e[t+6]=It[6],e[t+7]=It[7]}function Qb(r,e){return It[0]=r[e],It[1]=r[e+1],It[2]=r[e+2],It[3]=r[e+3],It[4]=r[e+4],It[5]=r[e+5],It[6]=r[e+6],It[7]=r[e+7],Pd[0]}var YE=BigInt(Number.MAX_SAFE_INTEGER),JE=BigInt(Number.MIN_SAFE_INTEGER),nr=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 si;if(e<YE&&e>JE)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>ew&&(o=0n,++n>ew&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return si;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):si}},si=new nr(0,0);si.toBigInt=function(){return 0n};si.zzEncode=si.zzDecode=function(){return this};si.length=function(){return 1};var ew=4294967296n;function tw(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 rw(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 Nd(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 Pr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Yf(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var kd=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,Pr(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 Pr(this,4);return Yf(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pr(this,4);return Yf(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pr(this,4);let e=Yb(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Pr(this,4);let e=Qb(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 Pr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return rw(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Pr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Pr(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 nr(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 Pr(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 Pr(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 Pr(this,8);let e=Yf(this.buf,this.pos+=4),t=Yf(this.buf,this.pos+=4);return new nr(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=Id(this.buf,this.pos);return this.pos+=We(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 Dd(r){return new kd(r instanceof Uint8Array?r:r.subarray())}function Nr(r,e,t){let n=Dd(r);return e.decode(n,void 0,t)}function Rd(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ft(s);o+s>e&&(n=ft(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ai=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function jd(){}var Ud=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},QE=Rd();function e2(r){return globalThis.Buffer!=null?ft(r):QE(r)}var hc=class{len;head;tail;states;constructor(){this.len=0,this.head=new ai(jd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ai(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Md((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(Jf,10,nr.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=nr.fromBigInt(e);return this._push(Jf,t.length(),t)}uint64Number(e){return this._push(Ps,We(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=nr.fromBigInt(e).zzEncode();return this._push(Jf,t.length(),t)}sint64Number(e){let t=nr.fromNumber(e).zzEncode();return this._push(Jf,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ld,1,e?1:0)}fixed32(e){return this._push(pc,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=nr.fromBigInt(e);return this._push(pc,4,t.lo)._push(pc,4,t.hi)}fixed64Number(e){let t=nr.fromNumber(e);return this._push(pc,4,t.lo)._push(pc,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(Zb,4,e)}double(e){return this._push(Jb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ld,1,0):this.uint32(t)._push(r2,t,e)}string(e){let t=tw(e);return t!==0?this.uint32(t)._push(Nd,t,e):this._push(Ld,1,0)}fork(){return this.states=new Ud(this),this.head=this.tail=new ai(jd,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 ai(jd,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=e2(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ld(r,e,t){e[t]=r&255}function t2(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Md=class extends ai{next;constructor(e,t){super(t2,e,t),this.next=void 0}};function Jf(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 pc(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 r2(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(hc.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(n2,e,r),this},hc.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(o2,e,r),this});function n2(r,e,t){e.set(r,t)}function o2(r,e,t){r.length<40?Nd(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(ye(r),t)}function Kd(){return new hc}function kr(r,e){let t=Kd();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Ns;(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"})(Ns||(Ns={}));function Qf(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function ci(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 Qf("enum",Ns.VARINT,t,n)}function Dr(r,e){return Qf("message",Ns.LENGTH_DELIMITED,r,e)}var dc=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var nt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(nt||(nt={}));var Hd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Hd||(Hd={}));(function(r){r.codec=()=>ci(Hd)})(nt||(nt={}));var Zr;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),nt.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=nt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(Zr||(Zr={}));var Vd;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),nt.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=nt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(Vd||(Vd={}));var mc={};Ct(mc,{MAX_RSA_KEY_SIZE:()=>$d,generateRSAKeyPair:()=>Jd,jwkToJWKKeyPair:()=>cw,jwkToPkcs1:()=>c2,jwkToPkix:()=>Gd,jwkToRSAPrivateKey:()=>Yd,pkcs1MessageToJwk:()=>Wd,pkcs1MessageToRSAPrivateKey:()=>zd,pkcs1ToJwk:()=>a2,pkcs1ToRSAPrivateKey:()=>aw,pkixMessageToJwk:()=>qd,pkixMessageToRSAPublicKey:()=>Zd,pkixToJwk:()=>u2,pkixToRSAPublicKey:()=>Xd});var el=lo;var ks=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=mc.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return Ze.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 sw(this.jwk,t,e,n)}},yc=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=mc.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return iw(this.jwk,e,t)}};var $d=8192,Fd=18,i2=1062,s2=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function a2(r){let e=mn(r);return Wd(e)}function Wd(r){return{n:le(r[1],"base64url"),e:le(r[2],"base64url"),d:le(r[3],"base64url"),p:le(r[4],"base64url"),q:le(r[5],"base64url"),dp:le(r[6],"base64url"),dq:le(r[7],"base64url"),qi:le(r[8],"base64url"),kty:"RSA"}}function c2(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return Br([jt(Uint8Array.from([0])),jt(ye(r.n,"base64url")),jt(ye(r.e,"base64url")),jt(ye(r.d,"base64url")),jt(ye(r.p,"base64url")),jt(ye(r.q,"base64url")),jt(ye(r.dp,"base64url")),jt(ye(r.dq,"base64url")),jt(ye(r.qi,"base64url"))]).subarray()}function u2(r){let e=mn(r,{offset:0});return qd(e)}function qd(r){let e=mn(r[1],{offset:0});return{kty:"RSA",n:le(e[0],"base64url"),e:le(e[1],"base64url")}}function Gd(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return Br([s2,Za(Br([jt(ye(r.n,"base64url")),jt(ye(r.e,"base64url"))]))]).subarray()}function aw(r){let e=mn(r);return zd(e)}function zd(r){let e=Wd(r);return Yd(e)}function Xd(r,e){if(r.byteLength>=i2)throw new ps("Key size is too large");let t=mn(r,{offset:0});return Zd(t,r,e)}function Zd(r,e,t){let n=qd(r);if(t==null){let o=el(Zr.encode({Type:nt.RSA,Data:e}));t=Dt(Fd,o)}return new ks(n,t)}function Yd(r){if(fw(r)>$d)throw new ve("Key size is too large");let e=cw(r),t=el(Zr.encode({Type:nt.RSA,Data:Gd(e.publicKey)})),n=Dt(Fd,t);return new yc(e.privateKey,new ks(e.publicKey,n))}async function Jd(r){if(r>$d)throw new ve("Key size is too large");let e=await uw(r),t=el(Zr.encode({Type:nt.RSA,Data:Gd(e.publicKey)})),n=Dt(Fd,t);return new yc(e.privateKey,new ks(e.publicKey,n))}function cw(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function uw(r,e){let t=await Ft.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 f2(t,e);return{privateKey:n[0],publicKey:n[1]}}async function iw(r,e,t){let n=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Ft.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 sw(r,e,t,n){let o=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function f2(r,e){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");let t=await Promise.all([Ft.get().subtle.exportKey("jwk",r.privateKey),Ft.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function fw(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return ye(r.n,"base64url").length*8}var tl=class extends xs{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ei(e);let n=so(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),Ir(i)}update(e){return vs(this),this.iHash.update(e),this}digestInto(e){vs(this),Tt(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 tl(r,e).update(t).digest();Ds.create=(r,e)=>new tl(r,e);var lw=(r,e)=>(r+(r>=0?e:-e)/pw)/e;function l2(r,e,t){let[[n,o],[i,s]]=e,a=lw(s*r,t),c=lw(-o*r,t),u=r-a*n-c*i,p=-a*o-c*s,l=u<Bn,h=p<Bn;l&&(u=-u),h&&(p=-p);let y=ho(Math.ceil(Hf(t)/2))+js;if(u<Bn||u>=y||p<Bn||p>=y)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:h,k2:p}}function ey(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Qd(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return xn(t.lowS,"lowS"),xn(t.prehash,"prehash"),t.format!==void 0&&ey(t.format),t}var ty=class extends Error{constructor(e=""){super(e)}},Tn={Err:ty,_tlv:{encode:(r,e)=>{let{Err:t}=Tn;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=ec(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?ec(o.length/2|128):"";return ec(r)+i+o+e},decode(r,e){let{Err:t}=Tn,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 u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let p of u)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}=Tn;if(r<Bn)throw new e("integer: negative integers are not allowed");let t=ec(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}=Tn;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 _s(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Tn,o=Oe("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,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(u)}},hexFromSig(r){let{_tlv:e,_int:t}=Tn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},Bn=BigInt(0),js=BigInt(1),pw=BigInt(2),rl=BigInt(3),p2=BigInt(4);function Rs(r,e){let{BYTES:t}=r,n;if(typeof e=="bigint")n=e;else{let o=Oe("private key",e);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function h2(r,e={}){let t=$f("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;Xr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=dw(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(V,x,v){let{x:E,y:N}=x.toAffine(),j=n.toBytes(E);if(xn(v,"isCompressed"),v){p();let U=!n.isOdd(N);return Lt(hw(U),j)}else return Lt(Uint8Array.of(4),j,n.toBytes(N))}function h(V){tr(V,void 0,"Point");let{publicKey:x,publicKeyUncompressed:v}=u,E=V.length,N=V[0],j=V.subarray(1);if(E===x&&(N===2||N===3)){let U=n.fromBytes(j);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let P=w(U),L;try{L=n.sqrt(P)}catch(he){let be=he instanceof Error?": "+he.message:"";throw new Error("bad point: is not on curve, sqrt error"+be)}p();let q=n.isOdd(L);return(N&1)===1!==q&&(L=n.neg(L)),{x:U,y:L}}else if(E===v&&N===4){let U=n.BYTES,P=n.fromBytes(j.subarray(0,U)),L=n.fromBytes(j.subarray(U,U*2));if(!g(P,L))throw new Error("bad point: is not on curve");return{x:P,y:L}}else throw new Error(`bad point: got length ${E}, expected compressed=${x} or uncompressed=${v}`)}let y=e.toBytes||l,m=e.fromBytes||h;function w(V){let x=n.sqr(V),v=n.mul(x,V);return n.add(n.add(v,n.mul(V,i.a)),i.b)}function g(V,x){let v=n.sqr(x),E=w(V);return n.eql(v,E)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,rl),p2),D=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,D)))throw new Error("bad curve params: a or b");function B(V,x,v=!1){if(!n.isValid(x)||v&&n.is0(x))throw new Error(`bad point coordinate ${V}`);return x}function $(V){if(!(V instanceof I))throw new Error("ProjectivePoint expected")}function Q(V){if(!c||!c.basises)throw new Error("no endo");return l2(V,c.basises,o.ORDER)}let X=Ss((V,x)=>{let{X:v,Y:E,Z:N}=V;if(n.eql(N,n.ONE))return{x:v,y:E};let j=V.is0();x==null&&(x=j?n.ONE:n.inv(N));let U=n.mul(v,x),P=n.mul(E,x),L=n.mul(N,x);if(j)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:U,y:P}}),ne=Ss(V=>{if(V.is0()){if(e.allowInfinityPoint&&!n.is0(V.Y))return;throw new Error("bad point: ZERO")}let{x,y:v}=V.toAffine();if(!n.isValid(x)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!g(x,v))throw new Error("bad point: equation left != right");if(!V.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Y(V,x,v,E,N){return v=new I(n.mul(v.X,V),v.Y,v.Z),x=nc(E,x),v=nc(N,v),x.add(v)}class I{constructor(x,v,E){this.X=B("x",x),this.Y=B("y",v,!0),this.Z=B("z",E),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){let{x:v,y:E}=x||{};if(!x||!n.isValid(v)||!n.isValid(E))throw new Error("invalid affine point");if(x instanceof I)throw new Error("projective point not allowed");return n.is0(v)&&n.is0(E)?I.ZERO:new I(v,E,n.ONE)}static fromBytes(x){let v=I.fromAffine(m(tr(x,void 0,"point")));return v.assertValidity(),v}static fromHex(x){return I.fromBytes(Oe("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,v=!0){return z.createCache(this,x),v||this.multiply(rl),this}assertValidity(){ne(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){$(x);let{X:v,Y:E,Z:N}=this,{X:j,Y:U,Z:P}=x,L=n.eql(n.mul(v,P),n.mul(j,N)),q=n.eql(n.mul(E,P),n.mul(U,N));return L&&q}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:v}=i,E=n.mul(v,rl),{X:N,Y:j,Z:U}=this,P=n.ZERO,L=n.ZERO,q=n.ZERO,R=n.mul(N,N),he=n.mul(j,j),be=n.mul(U,U),te=n.mul(N,j);return te=n.add(te,te),q=n.mul(N,U),q=n.add(q,q),P=n.mul(x,q),L=n.mul(E,be),L=n.add(P,L),P=n.sub(he,L),L=n.add(he,L),L=n.mul(P,L),P=n.mul(te,P),q=n.mul(E,q),be=n.mul(x,be),te=n.sub(R,be),te=n.mul(x,te),te=n.add(te,q),q=n.add(R,R),R=n.add(q,R),R=n.add(R,be),R=n.mul(R,te),L=n.add(L,R),be=n.mul(j,U),be=n.add(be,be),R=n.mul(be,te),P=n.sub(P,R),q=n.mul(be,he),q=n.add(q,q),q=n.add(q,q),new I(P,L,q)}add(x){$(x);let{X:v,Y:E,Z:N}=this,{X:j,Y:U,Z:P}=x,L=n.ZERO,q=n.ZERO,R=n.ZERO,he=i.a,be=n.mul(i.b,rl),te=n.mul(v,j),Se=n.mul(E,U),Te=n.mul(N,P),Ue=n.add(v,E),Ee=n.add(j,U);Ue=n.mul(Ue,Ee),Ee=n.add(te,Se),Ue=n.sub(Ue,Ee),Ee=n.add(v,N);let Re=n.add(j,P);return Ee=n.mul(Ee,Re),Re=n.add(te,Te),Ee=n.sub(Ee,Re),Re=n.add(E,N),L=n.add(U,P),Re=n.mul(Re,L),L=n.add(Se,Te),Re=n.sub(Re,L),R=n.mul(he,Ee),L=n.mul(be,Te),R=n.add(L,R),L=n.sub(Se,R),R=n.add(Se,R),q=n.mul(L,R),Se=n.add(te,te),Se=n.add(Se,te),Te=n.mul(he,Te),Ee=n.mul(be,Ee),Se=n.add(Se,Te),Te=n.sub(te,Te),Te=n.mul(he,Te),Ee=n.add(Ee,Te),te=n.mul(Se,Ee),q=n.add(q,te),te=n.mul(Re,Ee),L=n.mul(Ue,L),L=n.sub(L,te),te=n.mul(Ue,Se),R=n.mul(Re,R),R=n.add(R,te),new I(L,q,R)}subtract(x){return this.add(x.negate())}is0(){return this.equals(I.ZERO)}multiply(x){let{endo:v}=e;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let E,N,j=U=>z.cached(this,U,P=>_n(I,P));if(v){let{k1neg:U,k1:P,k2neg:L,k2:q}=Q(x),{p:R,f:he}=j(P),{p:be,f:te}=j(q);N=he.add(te),E=Y(v.beta,R,be,U,L)}else{let{p:U,f:P}=j(x);E=U,N=P}return _n(I,[E,N])[0]}multiplyUnsafe(x){let{endo:v}=e,E=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===Bn||E.is0())return I.ZERO;if(x===js)return E;if(z.hasCache(this))return this.multiply(x);if(v){let{k1neg:N,k1:j,k2neg:U,k2:P}=Q(x),{p1:L,p2:q}=Rb(I,E,j,P);return Y(v.beta,L,q,N,U)}else return z.unsafe(E,x)}multiplyAndAddUnsafe(x,v,E){let N=this.multiplyUnsafe(v).add(x.multiplyUnsafe(E));return N.is0()?void 0:N}toAffine(x){return X(this,x)}isTorsionFree(){let{isTorsionFree:x}=e;return s===js?!0:x?x(I,this):z.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:x}=e;return s===js?this:x?x(I,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(x=!0){return xn(x,"isCompressed"),this.assertValidity(),y(I,this,x)}toHex(x=!0){return pr(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return _n(I,x)}static msm(x,v){return Cs(I,o,x,v)}static fromPrivateKey(x){return I.BASE.multiply(Rs(o,x))}}I.BASE=new I(i.Gx,i.Gy,n.ONE),I.ZERO=new I(n.ZERO,n.ONE,n.ZERO),I.Fp=n,I.Fn=o;let K=o.BITS,z=new Es(I,e.endo?Math.ceil(K/2):K);return I.BASE.precompute(8),I}function hw(r){return Uint8Array.of(r?2:3)}function dw(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function d2(r,e={}){let{Fn:t}=r,n=e.randomBytes||ao,o=Object.assign(dw(r.Fp,t),{seed:hd(t.ORDER)});function i(y){try{return!!Rs(t,y)}catch{return!1}}function s(y,m){let{publicKey:w,publicKeyUncompressed:g}=o;try{let A=y.length;return m===!0&&A!==w||m===!1&&A!==g?!1:!!r.fromBytes(y)}catch{return!1}}function a(y=n(o.seed)){return dd(tr(y,o.seed,"seed"),t.ORDER)}function c(y,m=!0){return r.BASE.multiply(Rs(t,y)).toBytes(m)}function u(y){let m=a(y);return{secretKey:m,publicKey:c(m)}}function p(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let{secretKey:m,publicKey:w,publicKeyUncompressed:g}=o;if(t.allowedLengths||m===w)return;let A=Oe("key",y).length;return A===w||A===g}function l(y,m,w=!0){if(p(y)===!0)throw new Error("first arg must be private key");if(p(m)===!1)throw new Error("second arg must be public key");let g=Rs(t,y);return r.fromHex(m).multiply(g).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:r,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:y=>Rs(t,y),precompute(y=8,m=r.BASE){return m.precompute(y,!1)}},lengths:o})}function y2(r,e,t={}){ei(e),Xr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||ao,o=t.hmac||((v,...E)=>Ds(e,v,Lt(...E))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:p,getSharedSecret:l,utils:h,lengths:y}=d2(r,t),m={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function g(v){let E=a>>js;return v>E}function A(v,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return E}function D(v,E){ey(E);let N=y.signature,j=E==="compact"?N:E==="recovered"?N+1:void 0;return tr(v,j,`${E} signature`)}class B{constructor(E,N,j){this.r=A("r",E),this.s=A("s",N),j!=null&&(this.recovery=j),Object.freeze(this)}static fromBytes(E,N=w){D(E,N);let j;if(N==="der"){let{r:q,s:R}=Tn.toSig(tr(E));return new B(q,R)}N==="recovered"&&(j=E[0],N="compact",E=E.subarray(1));let U=s.BYTES,P=E.subarray(0,U),L=E.subarray(U,U*2);return new B(s.fromBytes(P),s.fromBytes(L),j)}static fromHex(E,N){return this.fromBytes(ti(E),N)}addRecoveryBit(E){return new B(this.r,this.s,E)}recoverPublicKey(E){let N=i.ORDER,{r:j,s:U,recovery:P}=this;if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");if(a*pw<N&&P>1)throw new Error("recovery id is ambiguous for h>1 curve");let q=P===2||P===3?j+a:j;if(!i.isValid(q))throw new Error("recovery id 2 or 3 invalid");let R=i.toBytes(q),he=r.fromBytes(Lt(hw((P&1)===0),R)),be=s.inv(q),te=Q(Oe("msgHash",E)),Se=s.create(-te*be),Te=s.create(U*be),Ue=r.BASE.multiplyUnsafe(Se).add(he.multiplyUnsafe(Te));if(Ue.is0())throw new Error("point at infinify");return Ue.assertValidity(),Ue}hasHighS(){return g(this.s)}toBytes(E=w){if(ey(E),E==="der")return ti(Tn.hexFromSig(this));let N=s.toBytes(this.r),j=s.toBytes(this.s);if(E==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Lt(Uint8Array.of(this.recovery),N,j)}return Lt(N,j)}toHex(E){return pr(this.toBytes(E))}assertValidity(){}static fromCompact(E){return B.fromBytes(Oe("sig",E),"compact")}static fromDER(E){return B.fromBytes(Oe("sig",E),"der")}normalizeS(){return this.hasHighS()?new B(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return pr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return pr(this.toBytes("compact"))}}let $=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=_s(E),j=E.length*8-c;return j>0?N>>BigInt(j):N},Q=t.bits2int_modN||function(E){return s.create($(E))},X=ho(c);function ne(v){return po("num < 2^"+c,v,Bn,X),s.toBytes(v)}function Y(v,E){return tr(v,void 0,"message"),E?tr(e(v),void 0,"prehashed message"):v}function I(v,E,N){if(["recovered","canonical"].some(Se=>Se in N))throw new Error("sign() legacy options not supported");let{lowS:j,prehash:U,extraEntropy:P}=Qd(N,m);v=Y(v,U);let L=Q(v),q=Rs(s,E),R=[ne(q),ne(L)];if(P!=null&&P!==!1){let Se=P===!0?n(y.secretKey):P;R.push(Oe("extraEntropy",Se))}let he=Lt(...R),be=L;function te(Se){let Te=$(Se);if(!s.isValidNot0(Te))return;let Ue=s.inv(Te),Ee=r.BASE.multiply(Te).toAffine(),Re=s.create(Ee.x);if(Re===Bn)return;let hn=s.create(Ue*s.create(be+Re*q));if(hn===Bn)return;let ur=(Ee.x===Re?0:2)|Number(Ee.y&js),to=hn;return j&&g(hn)&&(to=s.neg(hn),ur^=1),new B(Re,to,ur)}return{seed:he,k2sig:te}}function K(v,E,N={}){v=Oe("message",v);let{seed:j,k2sig:U}=I(v,E,N);return wb(e.outputLen,s.BYTES,o)(j,U)}function z(v){let E,N=typeof v=="string"||bn(v),j=!N&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!N&&!j)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(j)E=new B(v.r,v.s);else if(N){try{E=B.fromBytes(Oe("sig",v),"der")}catch(U){if(!(U instanceof Tn.Err))throw U}if(!E)try{E=B.fromBytes(Oe("sig",v),"compact")}catch{return!1}}return E||!1}function V(v,E,N,j={}){let{lowS:U,prehash:P,format:L}=Qd(j,m);if(N=Oe("publicKey",N),E=Y(Oe("message",E),P),"strict"in j)throw new Error("options.strict was renamed to lowS");let q=L===void 0?z(v):B.fromBytes(Oe("sig",v),L);if(q===!1)return!1;try{let R=r.fromBytes(N);if(U&&q.hasHighS())return!1;let{r:he,s:be}=q,te=Q(E),Se=s.inv(be),Te=s.create(te*Se),Ue=s.create(he*Se),Ee=r.BASE.multiplyUnsafe(Te).add(R.multiplyUnsafe(Ue));return Ee.is0()?!1:s.create(Ee.x)===he}catch{return!1}}function x(v,E,N={}){let{prehash:j}=Qd(N,m);return E=Y(E,j),B.fromBytes(v,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:p,getSharedSecret:l,utils:h,lengths:y,Point:r,sign:K,verify:V,recoverPublicKey:x,Signature:B,hash:e})}function m2(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=rr(e.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes:r.wrapPrivateKey}),i={Fp:t,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:i}}function g2(r){let{CURVE:e,curveOpts:t}=m2(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,hash:r.hash,ecdsaOpts:n}}function b2(r,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},r,Vf(t.Fn.ORDER,t.Fn.BITS))})}function yw(r){let{CURVE:e,curveOpts:t,hash:n,ecdsaOpts:o}=g2(r),i=h2(e,t),s=y2(i,n,o);return b2(r,s)}function mw(r,e){let t=n=>yw({...r,hash:n});return{...t(e),create:t}}var ny={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},w2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gw=BigInt(2);function x2(r){let e=ny.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,p=u*u*r%e,l=Fe(p,t,e)*p%e,h=Fe(l,t,e)*p%e,y=Fe(h,gw,e)*u%e,m=Fe(y,o,e)*y%e,w=Fe(m,i,e)*m%e,g=Fe(w,a,e)*w%e,A=Fe(g,c,e)*g%e,D=Fe(A,a,e)*w%e,B=Fe(D,t,e)*p%e,$=Fe(B,s,e)*m%e,Q=Fe($,n,e)*u%e,X=Fe(Q,gw,e);if(!ry.eql(ry.sqr(X),r))throw new Error("Cannot find square root");return X}var ry=rr(ny.p,{sqrt:x2}),Rr=mw({...ny,Fp:ry,lowS:!0,endo:w2},lo);function bw(r,e,t){let n=lr.digest(e instanceof Uint8Array?e:e.subarray());if(Os(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Rr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new ac(String(o))});try{return Rr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new ac(String(o))}}function ww(r,e,t,n){let o=lr.digest(t instanceof Uint8Array?t:t.subarray());if(Os(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Rr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new cc(String(i))});try{return n?.signal?.throwIfAborted(),Rr.verify(e,o.digest,r)}catch(i){throw new cc(String(i))}}var gc=class{type="secp256k1";raw;_key;constructor(e){this._key=_w(e),this.raw=xw(this._key)}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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 ww(this._key,t,e,n)}},nl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=vw(e),this.publicKey=new gc(t??Sw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return bw(this.raw,e,t)}};function oy(r){return new gc(r)}async function Aw(){let r=v2();return new nl(r)}function xw(r){return Rr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function vw(r){try{return Rr.getPublicKey(r,!0),r}catch(e){throw new Va(String(e))}}function _w(r){try{return Rr.ProjectivePoint.fromHex(r),r}catch(e){throw new ps(String(e))}}function Sw(r){try{return Rr.getPublicKey(r,!0)}catch(e){throw new Va(String(e))}}function v2(){return Rr.utils.randomPrivateKey()}async function Ew(r,e){if(r==="Ed25519")return Xb();if(r==="secp256k1")return Aw();if(r==="RSA")return Jd(_2(e));if(r==="ECDSA")return eb(S2(e));throw new ro}function bc(r,e){let{Type:t,Data:n}=Zr.decode(r),o=n??new Uint8Array;switch(t){case nt.RSA:return Xd(o,e);case nt.Ed25519:return Ad(o);case nt.secp256k1:return oy(o);case nt.ECDSA:return ed(o);default:throw new ro}}function Cw(r){let{Type:e,Data:t}=Zr.decode(r.digest),n=t??new Uint8Array;switch(e){case nt.Ed25519:return Ad(n);case nt.secp256k1:return oy(n);case nt.ECDSA:return ed(n);default:throw new ro}}function io(r){return Zr.encode({Type:nt[r.type],Data:r.raw})}function _2(r){return r==null?2048:parseInt(r,10)}function S2(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function ol(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var Tw=Symbol.for("nodejs.util.inspect.custom"),A2=114,wc=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()})`}[Th]=!0;toString(){return this.string==null&&(this.string=Ze.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(A2,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")}[Tw](){return`PeerId(${this.toString()})`}},xc=class extends wc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},vc=class extends wc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},_c=class extends wc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},E2=2336,Sc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Tr.digest(ye(this.url))}[Tw](){return`PeerId(${this.url})`}[Th]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(E2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=le(e)),e.toString()===this.toString())}};var C2=114,Bw=2336;function Ls(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ws(Ze.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return T2(ct.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ws(e.decode(r))}return Iw(t)}function iy(r){if(r.type==="Ed25519")return new vc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new _c({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new xc({multihash:r.toCID().multihash,publicKey:r});throw new ro}function Iw(r){if(I2(r))return new xc({multihash:r});if(B2(r))try{let e=Cw(r);if(e.type==="Ed25519")return new vc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new _c({multihash:r,publicKey:e})}catch{let t=le(r.digest);return new Sc(new URL(t))}throw new Ef("Supplied PeerID Multihash is invalid")}function T2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==C2&&r.code!==Bw)throw new Af("Supplied PeerID CID is invalid");if(r.code===Bw){let e=le(r.multihash.digest);return new Sc(new URL(e))}return Iw(r.multihash)}function B2(r){return r.code===Tr.code}function I2(r){return r.code===lr.code}var gt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},In=class extends Error{static name="ValidationError";name="ValidationError"},il=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},sl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var al=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",u=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(p===void 0)break;if(i*=e,i+=p,i>u||(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 O2=45,P2=15,cl=new al;function Ow(r){if(!(r.length>P2))return cl.new(r).parseWith(()=>cl.readIPv4Addr())}function Pw(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>O2))return cl.new(r).parseWith(()=>cl.readIPv6Addr())}function ul(r){return!!Ow(r)}function Nw(r){return!!Pw(r)}function ay(r){return e=>le(e,r)}function cy(r){return e=>ye(e,r)}function Us(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ui(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function kw(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=ye(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ui(n);return Rt([t,o],t.length+o.length)}function Dw(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=oo.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=ui(n);return Rt([t,o],t.length+o.length)}function uy(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=le(e,"base32"),o=Us(t);return`${n}:${o}`}var fy=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new gt("Invalid byte value in IP address");e[n]=o}),e},Rw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=ul(t[n]),s;i&&(s=fy(t[n]),t[n]=le(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,le(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new gt("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},jw=function(r){if(r.byteLength!==4)throw new gt("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Lw=function(r){if(r.byteLength!==16)throw new gt("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${t}"`)}};function Uw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${r}"`)}}var sy=Object.values(Zo).map(r=>r.decoder),N2=(function(){let r=sy[0].or(sy[1]);return sy.slice(2).forEach(e=>r=r.or(e)),r})();function Mw(r){return N2.decode(r)}function Kw(r){return e=>r.encoder.encode(e)}function k2(r){if(parseInt(r).toString()!==r)throw new In("Value must be an integer")}function D2(r){if(r<0)throw new In("Value must be a positive integer, or zero")}function R2(r){return e=>{if(e>r)throw new In(`Value must be smaller than or equal to ${r}`)}}function j2(...r){return e=>{for(let t of r)t(e)}}var Ac=j2(k2,D2,R2(65535));var dt=-1,ly=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new sl(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},On=new ly,Y2=[{code:4,name:"ip4",size:32,valueToBytes:fy,bytesToValue:jw,validate:r=>{if(!ul(r))throw new In(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:273,name:"udp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:33,name:"dccp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:41,name:"ip6",size:128,valueToBytes:Rw,bytesToValue:Lw,stringToValue:Uw,validate:r=>{if(!Nw(r))throw new In(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:ay("base10"),valueToBytes:cy("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:ay("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?cy("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:uy,valueToBytes:kw},{code:445,name:"onion3",size:296,bytesToValue:uy,valueToBytes:Dw},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Kw(Xo),valueToBytes:Mw},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];Y2.forEach(r=>{On.addProtocol(r)});function Hw(r){let e=[],t=0;for(;t<r.length;){let n=Cn(r,t),o=On.getProtocol(n),i=We(n),s=J2(o,r,t+i),a=0;s>0&&o.size===dt&&(a=We(s));let c=i+a+s,u={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let p=t+i+a,l=r.subarray(p,p+s);u.value=o.bytesToValue?.(l)??le(l)}e.push(u),t+=c}return e}function Vw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=On.getProtocol(n.code),i=We(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??ye(n.value),a=s.byteLength,o.size===dt&&(c=We(a)));let u=new Uint8Array(i+c+a),p=0;Ps(n.code,u,p),p+=i,s!=null&&(o.size===dt&&(Ps(a,u,p),p+=c),u.set(s,p)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return Rt(t,e)}function $w(r){if(r.charAt(0)!=="/")throw new gt('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=On.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new gt(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new gt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new gt("Incomplete multiaddr");return e}function Fw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=On.getProtocol(e.code);if(t==null)throw new gt(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function J2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Cn(e,t)}var Q2=Symbol.for("nodejs.util.inspect.custom"),By=Symbol.for("@multiformats/multiaddr");function eC(r){if(r==null&&(r="/"),Ww(r))return r.getComponents();if(r instanceof Uint8Array)return Hw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),$w(r);if(Array.isArray(r))return r;throw new gt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var hl=class r{[By]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=eC(e),t.validate!==!1&&tC(this)}get bytes(){return this.#r==null&&(this.#r=Vw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Fw(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new il(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return Ye(this.bytes,e.bytes)}[Q2](){return`Multiaddr(${this.toString()})`}};function tC(r){r.getComponents().forEach(e=>{let t=On.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Ww(r){return!!r?.[By]}function Vs(r){return new hl(r)}var Me=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),fe=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),qw=r=>({match:e=>r.match(e)===!1?e:!1}),Ae=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),Ot=(...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}}),De=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function Ke(...r){function e(o){if(o==null)return!1;let i=o.getComponents();for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var rC=fe(421),r4=Ke(rC),yl=fe(54),ml=fe(55),gl=fe(56),Oy=fe(53),n4=Ke(yl,Ae(fe(421))),o4=Ke(ml,Ae(fe(421))),i4=Ke(gl,Ae(fe(421))),s4=Ke(Ot(Oy,gl,yl,ml),Ae(fe(421))),Gw=De(fe(4),Ae(fe(43))),zw=De(Ae(fe(42)),fe(41),Ae(fe(43))),Py=Ot(Gw,zw),pi=Ot(Py,Oy,yl,ml,gl),a4=Ke(Ot(Py,De(Ot(Oy,gl,yl,ml),Ae(fe(421))))),c4=Ke(Gw),u4=Ke(zw),f4=Ke(Py),Ny=De(pi,fe(6)),Ec=De(pi,fe(273)),l4=Ke(De(Ny,Ae(fe(421)))),p4=Ke(Ec),ky=De(Ec,Me(460),Ae(fe(421))),bl=De(Ec,Me(461),Ae(fe(421))),nC=Ot(ky,bl),h4=Ke(ky),d4=Ke(bl),Iy=Ot(pi,Ny,Ec,ky,bl),Xw=Ot(De(Iy,Me(477),Ae(fe(421)))),y4=Ke(Xw),Zw=Ot(De(Iy,Me(478),Ae(fe(421))),De(Iy,Me(448),Ae(fe(449)),Me(477),Ae(fe(421)))),m4=Ke(Zw),Yw=De(Ec,Me(280),Ae(fe(466)),Ae(fe(466)),Ae(fe(421))),Jw=Ke(Yw),Qw=De(bl,Me(465),Ae(fe(466)),Ae(fe(466)),Ae(fe(421))),g4=Ke(Qw),dl=Ot(Xw,Zw,De(Ny,Ae(fe(421))),De(nC,Ae(fe(421))),De(pi,Ae(fe(421))),Yw,Qw,fe(421)),ex=Ke(dl),oC=De(Ae(dl),Me(290),qw(Me(281)),Ae(fe(421))),b4=Ke(oC),iC=Ot(De(dl,Me(290),Me(281),Ae(fe(421))),De(dl,Me(281),Ae(fe(421))),De(Me(281),Ae(fe(421)))),tx=Ke(iC),sC=Ot(De(pi,fe(6),Me(480),Ae(fe(421))),De(pi,Me(480),Ae(fe(421)))),w4=Ke(sC),aC=De(pi,Ot(De(fe(6,"443"),Me(480)),De(fe(6),Me(443)),De(fe(6),Me(448),Me(480)),De(Me(448),Me(480)),Me(448),Me(443)),Ae(fe(421))),x4=Ke(aC),cC=Ot(De(fe(777),Ae(fe(421)))),v4=Ke(cC),uC=Ot(De(fe(400),Ae(fe(421)))),_4=Ke(uC);var Pt;(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=()=>ci(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Dr((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 u=o.uint32();switch(u>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>kr(o,r.codec()),r.decode=(o,i)=>Nr(o,r.codec(),i)})(Pt||(Pt={}));var rx=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Dy=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),nx="libp2p+webrtc+v1/",ox=2*1024*1024,$s=16*1024;function fC(r=$s){let e=We(r-We(r)),t=1+We(Object.keys(Pt.Flag).length-1),n=1,o=r-e-t-n,i=We(o);return e+t+n+i}var ix=fC();var sx=1e4,Ry="/webrtc",Cc="/webrtc-signaling/0.0.1",ax="/libp2p/webrtc-direct/certificate",cx="webrtc-direct-certificate-private-key";var ux=12096e5,jy=864e5;function Ly(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new ve(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}function wl(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var xl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xl(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new xl(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Uy=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ws(r={}){return lC(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 lC(r,e){e=e??{};let t=e.onEnd,n=new Fs,o,i,s,a=wl(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,A)=>{i=D=>{i=null,n.push(D);try{g(r(n))}catch(B){A(B)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=wl()})}},u=g=>i!=null?i(g):(n.push(g),o),p=g=>(n=new Fs,i!=null?i({error:g}):(n.push({error:g}),o)),l=g=>{if(s)return o;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},h=g=>s?o:(s=!0,g!=null?p(g):u({done:!0})),y=()=>(n=new Fs,h(),{done:!0}),m=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:y,throw:m,push:l,end:h,get readableLength(){return n.size},onEmpty:async g=>{let A=g?.signal;if(A?.throwIfAborted(),n.isEmpty())return;let D,B;A!=null&&(D=new Promise(($,Q)=>{B=()=>{Q(new Uy)},A.addEventListener("abort",B)}));try{await Promise.race([a.promise,D])}finally{B!=null&&A!=null&&A?.removeEventListener("abort",B)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),t!=null&&(t(g),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(g){return w.end(g),t!=null&&(t(g),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},o}var My=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ky=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fx=r=>globalThis.DOMException===void 0?new Ky(r):new DOMException(r),lx=r=>{let e=r.reason===void 0?fx("This operation was aborted."):r.reason;return e instanceof Error?e:fx(e)};function Hy(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,u=new Promise((p,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&l(lx(y)),a=()=>{l(lx(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,l);return}let h=new My;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(y){l(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?l(o):(h.message=o??`Promise timed out after ${t} milliseconds`,l(h))},t),(async()=>{try{p(await r)}catch(y){l(y)}})()}).finally(()=>{u.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}var pC=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function hC(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:p}=pC(r),l=(...y)=>{let m=t.multiArgs?y:y[0];t.filter&&!t.filter(m)||(c.push(m),t.count===c.length&&(n(),i(c)))},h=y=>{n(),s(y)};n=()=>{for(let y of a)p(y,l);for(let y of t.rejectionEvents)p(y,h)};for(let y of a)u(y,l);for(let y of t.rejectionEvents)u(y,h);t.signal&&t.signal.addEventListener("abort",()=>{h(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=Hy(o,{milliseconds:t.timeout});return i.cancel=n,i}return o}function Mt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=hC(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var hi=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},vl=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function dC(r){return r.reason}async function qs(r,e,t){if(e==null)return r;let n=t?.translateError??dC;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var yC=Math.pow(2,20)*4,bo=class extends fr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??yC,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new me,this.writeBuffer=new me,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Ws(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new dn(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new If(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new hs;this.dispatchEvent(new Of(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ds))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new me(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Bf(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new $a(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new $a(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var _l=class extends bo{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function px(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Sl=class extends fr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await qs(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new _f;let t=this.onCreateStream({...this.streamOptions,...e});return px(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new vl(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var Al=class extends bo{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Mt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var mC=4194304,El=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Tc=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$y=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Fy=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function gC(r){return typeof r?.closeRead=="function"}function bC(r){return typeof r?.close=="function"}function Vy(r){return gC(r)?r.readStatus==="closing"||r.readStatus==="closed":bC(r)?r.status!=="open":!1}function wC(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function xC(r,e){let t=e?.maxBufferSize??mC,n=new me,o=Promise.withResolvers(),i=!1;if(!wC(r))throw new ve("Argument should be a Stream or a Multiaddr");let s=p=>{if(n.append(p.data),n.byteLength>t){let l=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${l} > ${t}`))}o.resolve()};r.addEventListener("message",s);let a=p=>{p.error!=null?o.reject(p.error):o.resolve()};r.addEventListener("close",a);let c=()=>{o.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(p){if(i===!0)throw new El("Stream was unwrapped");if(Vy(r)){if(p?.bytes==null)return null;if(n.byteLength<p.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,p.bytes),new hi(`Unexpected EOF - stream closed after reading ${n.byteLength}/${p.bytes} bytes`)}let l=p?.bytes??1;for(;;){if(n.byteLength>=l){o.resolve();break}if(await qs(o.promise,p?.signal),Vy(r)){if(n.byteLength===0&&p?.bytes==null)return null;break}o=Promise.withResolvers()}let h=p?.bytes??n.byteLength;if(n.byteLength<h){if(Vy(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,h),new hi(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(p)}let y=n.sublist(0,h);return n.consume(h),y},async write(p,l){if(i===!0)throw new El("Stream was unwrapped");r.send(p)||await Mt(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Cl(r,e={}){let t=xC(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=We(e.maxDataLength));let n=e?.lengthDecoder??Cn,o=e?.lengthEncoder??Zf;return{async read(s){let a=-1,c=new me;for(;;){let p=await t.read({...s,bytes:1});if(p==null)break;c.append(p);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Tc("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Fy(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new $y(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await t.read({...s,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new hi(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new hi(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(s,a){await t.write(new me(o(s.byteLength),s),a)},async writeV(s,a){let c=new me(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function Tl(r,e){let t=Cl(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 vC=1024*1024*4,_C=1024*1024*4,Bl=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new me,this.maxBufferSize=e.maxBufferSize??vC,this.maxDataLength=e.maxDataLength??_C,this.lengthDecoder=e.lengthDecoder??Cn,this.encodingLength=e.encodingLength??We}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ve(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new Tc("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var Il=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Gs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Bc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Pl(r){return r[Symbol.asyncIterator]!=null}function hx(r,e){if(r.byteLength>e)throw new Gs("Message length too long")}var kl=r=>{let e=We(r),t=ft(e);return Zf(r,t),kl.bytes=e,t};kl.bytes=0;function Ic(r,e){e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;function*o(i){hx(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Pl(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}Ic.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;return hx(r,n),new me(t(r.byteLength),r)};var di;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(di||(di={}));var Wy=r=>{let e=Cn(r);return Wy.bytes=We(e),e};Wy.bytes=0;function Oc(r,e){let t=new me,n=di.LENGTH,o=-1,i=e?.lengthDecoder??Wy,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===di.LENGTH)try{if(o=i(t),o<0)throw new Il("Invalid message length");if(o>a)throw new Gs("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=di.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new Ol("Message length length too long");break}throw u}if(n===di.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=di.LENGTH}}}return Pl(r)?(async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Bc("Unexpected end of input")})():(function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Bc("Unexpected end of input")})()}Oc.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 Oc(n,{...e??{},onLength:i=>{t=i}})};var dx=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))},EC=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var CC=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var TC=(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 BC=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var IC=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var OC=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,PC=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,yx=3,NC=[["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",OC]],mx=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function bx(r){return r?gx(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new IC:typeof navigator<"u"?gx(navigator.userAgent):RC()}function kC(r){return r!==""&&NC.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 gx(r){var e=kC(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new BC;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<yx&&(o=dx(dx([],o,!0),jC(yx-o.length),!0)):o=[];var i=o.join("."),s=DC(r),a=PC.exec(r);return a&&a[1]?new TC(t,i,s,a[1]):new EC(t,i,s)}function DC(r){for(var e=0,t=mx.length;e<t;e++){var n=mx[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function RC(){var r=typeof process<"u"&&process.version;return r?new CC(process.version.slice(1)):null}function jC(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}var wx=bx(),Dl=wx!=null&&wx.name==="firefox";async function qy(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??rx.map(e=>({urls:[e]})),r}var xx=(r=32)=>nx+[...Array(r)].map(()=>Dy.at(Math.floor(Math.random()*Dy.length))).join("");var Gy=class extends Al{channel;incomingData;maxBufferedAmount;receivedFinAck;finAckTimeout;constructor(e){super({...e,maxMessageSize:(e.maxMessageSize??$s)-ix}),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Ws(),this.maxBufferedAmount=e.maxBufferedAmount??ox,this.finAckTimeout=e.finAckTimeout??sx,this.channel.onclose=()=>{this.log.trace("received datachannel close event"),this.onRemoteCloseWrite(),this.onTransportClosed()},this.channel.onerror=n=>{let o=n.error;this.log.trace("received datachannel error event - %e",o),this.abort(o)},this.channel.onmessage=async n=>{this.log("incoming message %d bytes",n.data.byteLength);let{data:o}=n;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))},this.channel.bufferedAmountLowThreshold=0,this.channel.onbufferedamountlow=()=>{this.writableNeedsDrain&&this.safeDispatchEvent("drain")},this.channel.readyState!=="open"&&(this.log('channel ready state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),Mt(this.channel,"open",{rejectionEvents:["close","error"]}).then(()=>{this.log('channel ready state is now "%s", dispatching drain',this.channel.readyState),this.safeDispatchEvent("drain")}).catch(n=>{this.abort(n.error??n)})),Promise.resolve().then(async()=>{for await(let n of Oc(this.incomingData))this.processIncomingProtobuf(n)}).catch(n=>{this.log.error("error processing incoming data channel messages",n)});let t=()=>{this.channel.readyState==="open"&&(this.log.trace("stream closed, closing underlying datachannel"),this.channel.close())};this.addEventListener("close",t)}sendNewStream(){}_sendMessage(e){if(this.channel.readyState!=="open")throw new dn(`Invalid datachannel state - ${this.channel.readyState}`);if(this.log.trace('sending message, channel state "%s"',this.channel.readyState),Dl){this.channel.send(e.subarray());return}for(let t of e)this.channel.send(t)}sendData(e){return this.channel.readyState!=="open"?{sentBytes:0,canSendMore:!1}:(this._sendMessage(Ic.single(Pt.encode({message:e.subarray()}))),{sentBytes:e.byteLength,canSendMore:this.channel.bufferedAmount<this.maxBufferedAmount})}sendReset(e){try{this.log.error("sending reset - %e",e),this._sendFlag(Pt.Flag.RESET),this.receivedFinAck?.reject(e)}catch(t){this.log.error("failed to send reset - %e",t)}}async sendCloseWrite(e){this._sendFlag(Pt.Flag.FIN),e?.signal?.throwIfAborted(),this.receivedFinAck=Promise.withResolvers(),await Promise.any([qs(this.receivedFinAck.promise,e?.signal),new Promise(t=>{AbortSignal.timeout(this.finAckTimeout).addEventListener("abort",()=>{t()})})])}async sendCloseRead(e){this._sendFlag(Pt.Flag.STOP_SENDING),e?.signal?.throwIfAborted()}processIncomingProtobuf(e){let t=Pt.decode(e);t.message!=null&&(this.readStatus==="readable"||this.readStatus==="paused")&&this.onData(new me(t.message)),t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===Pt.Flag.FIN&&(this._sendFlag(Pt.Flag.FIN_ACK),this.onRemoteCloseWrite()),t.flag===Pt.Flag.RESET&&(this.receivedFinAck?.reject(new hs("The stream was reset")),this.onRemoteReset()),t.flag===Pt.Flag.STOP_SENDING&&this.onRemoteCloseRead(),t.flag===Pt.Flag.FIN_ACK&&this.receivedFinAck?.resolve())}_sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=Pt.encode({flag:e}),n=Ic.single(t);try{return this._sendMessage(n),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}sendPause(){}sendResume(){}};function Pc(r){let{channel:e,direction:t,isHandshake:n}=r;return new Gy({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`),protocol:""})}var wo=class{protocol;peerConnection;metrics;dataChannelOptions;constructor(e){this.peerConnection=e.peerConnection,this.metrics=e.metrics,this.protocol=e.protocol??Ry,this.dataChannelOptions=e.dataChannelOptions??{}}createStreamMuxer(e){return new zy(e,{peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,protocol:this.protocol})}},zy=class extends Sl{peerConnection;dataChannelOptions;constructor(e,t){super(e,{...t,name:"muxer"}),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Ry,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming %s datachannel with channel id %d, protocol %s and status %s",n.protocol,n.id,n.protocol,n.readyState),n.label==="init"){this.log.trace("closing init channel %d",n.id),n.close();return}let o=Pc({...this.streamOptions,...this.dataChannelOptions,channel:n,direction:"inbound",log:this.log});this.onRemoteStream(o)}}async onCreateStream(e){let t=this.peerConnection.createDataChannel("",{});return this.log("open channel %d for protocol %s",t.id,e?.protocol),Pc({...e,...this.dataChannelOptions,channel:t,direction:"outbound",log:this.log})}onData(){}};var Xy=class extends _l{peerConnection;constructor(e){super(e),this.peerConnection=e.peerConnection;let t=e.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change %s initial state %s",this.peerConnection.connectionState,t),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.onTransportClosed(),this.peerConnection.close())}}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.peerConnection.close(),e?.signal?.throwIfAborted()}sendReset(){this.peerConnection.close()}sendPause(){}sendResume(){}},Nc=r=>new Xy(r);var Rl=globalThis.RTCPeerConnection,jl=globalThis.RTCSessionDescription,vx=globalThis.RTCIceCandidate;var or=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var xo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},yr=class extends xo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Ll=class extends xo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Ul=class extends xo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Ml=class extends xo{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 Wt;(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=()=>ci(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Dr((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 u=o.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>kr(o,r.codec()),r.decode=(o,i)=>Nr(o,r.codec(),i)})(Wt||(Wt={}));var Kl=async(r,e,t)=>{try{let n=Promise.withResolvers();for(LC(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Wt.Type.ICE_CANDIDATE)throw new Cf("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new or("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new vx(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new or("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received %o - %e",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate - %e",t.direction,n),t.signal?.aborted===!0&&r.connectionState!=="connected")throw n}};function LC(r,e){if(r.connectionState==="connected"){e.resolve();return}r.onconnectionstatechange=t=>{switch(r.connectionState){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new vf(`RTCPeerConnection connection state became "${r.connectionState}"`));break;default:break}}}function Hl(r){let e;for(let t of r.getComponents())t.name==="p2p"&&(e=Ls(t.value??""));if(e==null)throw new Sf("Remote peerId must be present in multiaddr");return e}async function _x({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:u}){let{circuitAddress:p,targetPeer:l}=Sx(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",p);let h=i.getConnections(l),y;h.length===0?(u?.(new or("webrtc:dial-relay")),y=await s.dial(p,{signal:t,onProgress:u})):(u?.(new or("webrtc:reuse-relay-connection")),y=h[0]),u?.(new or("webrtc:open-signaling-stream"));let m=await y.newStream(Cc,{signal:t,runOnLimitedConnection:!0}),w=Tl(m).pb(Wt),g=new Rl(r);g.addEventListener("connectionstatechange",()=>{switch(g.connectionState){case"closed":g.close();break;default:break}});let A=new wo({peerConnection:g,dataChannelOptions:e});try{let D=g.createDataChannel("init");g.onicecandidate=({candidate:X})=>{if(g.connectionState==="connected"){a.trace("ignore new ice candidate as peer connection is already connected");return}if(X==null||X?.candidate===""){a.trace("initiator detected end of ICE candidates");return}let ne=JSON.stringify(X?.toJSON()??null);a.trace("initiator sending ICE candidate %o",X),w.write({type:Wt.Type.ICE_CANDIDATE,data:ne},{signal:t}).catch(Y=>{a.error("error sending ICE candidate - %e",Y)})},g.onicecandidateerror=X=>{a.error("initiator ICE candidate error",X)};let B=await g.createOffer().catch(X=>{throw a.error("could not execute createOffer",X),new yr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",B.sdp),u?.(new or("webrtc:send-sdp-offer")),await w.write({type:Wt.Type.SDP_OFFER,data:B.sdp},{signal:t}),await g.setLocalDescription(B).catch(X=>{throw a.error("could not execute setLocalDescription",X),new yr("Failed to set localDescription")}),u?.(new or("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let $=await w.read({signal:t});if($.type!==Wt.Type.SDP_ANSWER)throw new yr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",$.data);let Q=new jl({type:"answer",sdp:$.data});return await g.setRemoteDescription(Q).catch(X=>{throw a.error("could not execute setRemoteDescription",X),new yr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),u?.(new or("webrtc:read-ice-candidates")),await Kl(g,w,{direction:"initiator",signal:t,log:a,onProgress:u}),a.trace("initiator connected"),D.readyState!=="open"&&(a.trace("wait for init channel to open"),await Mt(D,"open",{signal:t})),a.trace("closing init channel"),D.close(),a.trace("waiting for init channel to close"),await Mt(D,"close",{signal:t}),u?.(new or("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await m.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:g,muxerFactory:A}}catch(D){throw a.error("outgoing signaling error",D),g.close(),m.abort(D),D}finally{g.onicecandidate=null,g.onicecandidateerror=null}}var Ax=Ke(ex.matchers[0],Me(290)),Vl=class r extends fr{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Ax.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Ax.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function Ex(r,e,{peerConnection:t,signal:n,log:o}){o.trace("new inbound signaling stream");let i=Tl(r).pb(Wt);try{t.onicecandidate=({candidate:l})=>{if(t.connectionState==="connected"){o.trace("ignore new ice candidate as peer connection is already connected");return}if(l==null||l?.candidate===""){o.trace("recipient detected end of ICE candidates");return}let h=JSON.stringify(l?.toJSON()??null);o.trace("recipient sending ICE candidate %s",h),i.write({type:Wt.Type.ICE_CANDIDATE,data:h},{signal:n}).catch(y=>{o.error("error sending ICE candidate - %e",y)})},o.trace("recipient read SDP offer");let c=await i.read({signal:n});if(c.type!==Wt.Type.SDP_OFFER)throw new yr(`expected message type SDP_OFFER, received: ${c.type??"undefined"} `);o.trace("recipient received SDP offer %s",c.data);let u=new jl({type:"offer",sdp:c.data});await t.setRemoteDescription(u).catch(l=>{throw o.error("could not execute setRemoteDescription",l),new yr("Failed to set remoteDescription")});let p=await t.createAnswer().catch(l=>{throw o.error("could not execute createAnswer",l),new yr("Failed to create answer")});o.trace("recipient send SDP answer %s",p.sdp),await i.write({type:Wt.Type.SDP_ANSWER,data:p.sdp},{signal:n}),await t.setLocalDescription(p).catch(l=>{throw o.error("could not execute setLocalDescription",l),new yr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Kl(t,i,{direction:"recipient",signal:n,log:o})}catch(c){if(t.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",e.remoteAddr,c),t.close(),c;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",e.remoteAddr,c)}let s=Hl(e.remoteAddr),a=Vs(`/webrtc/p2p/${s}`);return o.trace("recipient connected to remote address %s",a),{remoteAddress:a,remotePeer:s}}var $l=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"})})}[Pf]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[ys]=["@libp2p/transport"];[_0]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Cc,(e,t)=>{let n=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t,n).catch(o=>{this.log.error("failed to handle incoming connect from %p",t.remotePeer,o)}).finally(()=>{n.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Cc),this._started=!1}createListener(e){return new Vl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(tx.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 _x({rtcConfiguration:await qy(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=Nc({peerConnection:o,remoteAddr:n,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,remotePeer:Hl(e),muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol(e,t,n){let o=new Rl(await qy(this.init.rtcConfiguration));o.addEventListener("connectionstatechange",()=>{switch(o.connectionState){case"closed":o.close();break;default:break}});let i=new wo({peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s,remotePeer:a}=await Ex(e,t,{peerConnection:o,signal:n,log:this.log});await e.close({signal:n});let c=Nc({peerConnection:o,remoteAddr:s,metrics:this.metrics?.listenerEvents,direction:"inbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")});await this.components.upgrader.upgradeInbound(c,{skipEncryption:!0,skipProtection:!0,remotePeer:a,muxerFactory:i,signal:n}),this._closeOnShutdown(o,c)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),e.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Sx(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new ve("Destination peer id was missing");return{circuitAddress:Vs(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:Ls(e)}}var aX=Gr(Tx());var en={};Ct(en,{Any:()=>Jr,BaseBlock:()=>ot,BaseStringBlock:()=>jc,BitString:()=>Ur,BmpString:()=>wi,Boolean:()=>mi,CharacterString:()=>Bi,Choice:()=>Zs,Constructed:()=>it,DATE:()=>Vc,DateTime:()=>Fc,Duration:()=>Wc,EndOfContent:()=>Lc,Enumerated:()=>gi,GeneralString:()=>Ti,GeneralizedTime:()=>Ii,GraphicString:()=>Ci,HexBlock:()=>Qr,IA5String:()=>Ei,Integer:()=>jn,Null:()=>jr,NumericString:()=>vi,ObjectIdentifier:()=>bi,OctetString:()=>Lr,Primitive:()=>Rn,PrintableString:()=>_i,RawData:()=>Qy,RelativeObjectIdentifier:()=>Hc,Repeated:()=>Oi,Sequence:()=>Nt,Set:()=>Kt,TIME:()=>qc,TeletexString:()=>Si,TimeOfDay:()=>$c,UTCTime:()=>So,UniversalString:()=>xi,Utf8String:()=>gr,ValueBlock:()=>bt,VideotexString:()=>Ai,ViewWriter:()=>Xs,VisibleString:()=>_o,compareSchema:()=>kn,fromBER:()=>Un,verifySchema:()=>oT});var ge=Gr(Nn());function yi(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 vo(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 u=new Uint8Array(c);for(let p=a-1;p>=0;p--){let l=Math.pow(2,p*e);u[i-p-1]=Math.floor(o/l),o-=u[i-p-1]*l}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 Yy(){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=yi(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,yi(i,8)-n}function Bx(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=vo(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=vo(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ix(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function qt(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 fD=Math.log(2);function Gl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function em(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 Ln(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 Xs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return em(this.items)}},kc=[new Uint8Array([1])],Ox="0123456789",Jy="name",Px="valueHexView",qC="isHexOnly",GC="idBlock",zC="tagClass",XC="tagNumber",ZC="isConstructed",YC="fromBER",JC="toBER",QC="local",Gt="",Mr=new ArrayBuffer(0),cp=new Uint8Array(0),Rc="EndOfContent",kx="OCTET STRING",Dx="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):cp}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ln(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",Mr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ge.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Dn=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=Gt,warnings:n=[],valueBeforeDecode:o=cp}={}){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)}}};Dn.NAME="baseBlock";var bt=class extends Dn{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'")}};bt.NAME="valueBlock";var zl=class extends Qr(Dn){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):cp,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",Mr}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=vo(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(!Ln(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,u=this.valueHexView=new Uint8Array(255),p=255;for(;i[c]&128;){if(u[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 h=new Uint8Array(p);for(let y=0;y<u.length;y++)h[y]=u[y];u=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,u[c-1]=i[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(l),this.blockLength<=9?this.tagNumber=yi(u,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}}};zl.NAME="identificationBlock";var Xl=class extends Dn{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(!Ln(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=yi(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=vo(this.length,8);if(o.byteLength>127)return this.error="Too big length",Mr;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}}};Xl.NAME="lengthBlock";var J={},ot=class extends Dn{constructor({name:e=Gt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new zl(o),this.lenBlock=new Xl(o),this.valueBlock=i?new i(o):new bt(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 Xs;t||Rx(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?Mr: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 Ix(t,n)}};ot.NAME="BaseBlock";function Rx(r){var e;if(r instanceof J.Constructed)for(let t of r.valueBlock.value)Rx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var jc=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Gt,...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}'`}};jc.NAME="BaseStringBlock";var Zl=class extends Qr(bt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Zl.NAME="PrimitiveValueBlock";var jx,Rn=class extends ot{constructor(e={}){super(e,Zl),this.idBlock.isConstructed=!1}};jx=Rn;J.Primitive=jx;Rn.NAME="PRIMITIVE";function eT(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 Ys(r,e=0,t=r.length){let n=e,o=new ot({},bt),i=new Dn;if(!Ln(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=J.EndOfContent;break;case 1:c=J.Boolean;break;case 2:c=J.Integer;break;case 3:c=J.BitString;break;case 4:c=J.OctetString;break;case 5:c=J.Null;break;case 6:c=J.ObjectIdentifier;break;case 10:c=J.Enumerated;break;case 12:c=J.Utf8String;break;case 13:c=J.RelativeObjectIdentifier;break;case 14:c=J.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=J.Sequence;break;case 17:c=J.Set;break;case 18:c=J.NumericString;break;case 19:c=J.PrintableString;break;case 20:c=J.TeletexString;break;case 21:c=J.VideotexString;break;case 22:c=J.IA5String;break;case 23:c=J.UTCTime;break;case 24:c=J.GeneralizedTime;break;case 25:c=J.GraphicString;break;case 26:c=J.VisibleString;break;case 27:c=J.GeneralString;break;case 28:c=J.UniversalString;break;case 29:c=J.CharacterString;break;case 30:c=J.BmpString;break;case 31:c=J.DATE;break;case 32:c=J.TimeOfDay;break;case 33:c=J.DateTime;break;case 34:c=J.Duration;break;default:{let u=o.idBlock.isConstructed?new J.Constructed:new J.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?J.Constructed:J.Primitive}return o=eT(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 Un(r){if(!r.byteLength){let e=new ot({},bt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ys(ge.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function tT(r,e){return r?1:e}var Yr=class extends bt{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(!Ln(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(;tT(this.isIndefiniteForm,n)>0;){let s=Ys(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===Rc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Rc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Xs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Mr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Yr.NAME="ConstructedValueBlock";var Lx,it=class extends ot{constructor(e={}){super(e,Yr),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 NS=Object.create;var bf=Object.defineProperty;var kS=Object.getOwnPropertyDescriptor;var DS=Object.getOwnPropertyNames;var RS=Object.getPrototypeOf,jS=Object.prototype.hasOwnProperty;var Ch=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ct=(r,e)=>{for(var t in e)bf(r,t,{get:e[t],enumerable:!0})},x0=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of DS(e))!jS.call(r,o)&&o!==t&&bf(r,o,{get:()=>e[o],enumerable:!(n=kS(e,o))||n.enumerable});return r};var Gr=(r,e,t)=>(t=r!=null?NS(RS(r)):{},x0(e||!r||!r.__esModule?bf(t,"default",{value:r,enumerable:!0}):t,r)),LS=r=>x0(bf({},"__esModule",{value:!0}),r);var Tx=Ch(()=>{var Cx;(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,u){return function(p,l){Object.defineProperty(c,p,{configurable:!0,writable:!0,value:l}),u&&u(p,l)}}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,u=!a&&!c,p={create:a?function(){return Eh(Object.create(null))}:c?function(){return Eh({__proto__:null})}:function(){return Eh({})},has:u?function(_,C){return n.call(_,C)}:function(_,C){return C in _},get:u?function(_,C){return n.call(_,C)?_[C]:void 0}:function(_,C){return _[C]}},l=Object.getPrototypeOf(Function),h=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:TS(),y=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:BS(),m=typeof WeakMap=="function"?WeakMap:IS(),w=o?Symbol.for("@reflect-metadata:registry"):void 0,g=AS(),A=ES(g);function D(_,C,k,F){if(R(k)){if(!hn(_))throw new TypeError;if(!to(C))throw new TypeError;return V(_,C)}else{if(!hn(_))throw new TypeError;if(!te(C))throw new TypeError;if(!te(F)&&!R(F)&&!he(F))throw new TypeError;return he(F)&&(F=void 0),k=Re(k),x(_,C,k,F)}}e("decorate",D);function B(_,C){function k(F,ce){if(!te(F))throw new TypeError;if(!R(ce)&&!gf(ce))throw new TypeError;U(_,C,F,ce)}return k}e("metadata",B);function $(_,C,k,F){if(!te(k))throw new TypeError;return R(F)||(F=Re(F)),U(_,C,k,F)}e("defineMetadata",$);function Q(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),v(_,C,k)}e("hasMetadata",Q);function X(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),E(_,C,k)}e("hasOwnMetadata",X);function ne(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),N(_,C,k)}e("getMetadata",ne);function Y(_,C,k){if(!te(C))throw new TypeError;return R(k)||(k=Re(k)),j(_,C,k)}e("getOwnMetadata",Y);function I(_,C){if(!te(_))throw new TypeError;return R(C)||(C=Re(C)),P(_,C)}e("getMetadataKeys",I);function K(_,C){if(!te(_))throw new TypeError;return R(C)||(C=Re(C)),L(_,C)}e("getOwnMetadataKeys",K);function z(_,C,k){if(!te(C))throw new TypeError;if(R(k)||(k=Re(k)),!te(C))throw new TypeError;R(k)||(k=Re(k));var F=Ha(C,k,!1);return R(F)?!1:F.OrdinaryDeleteMetadata(_,C,k)}e("deleteMetadata",z);function V(_,C){for(var k=_.length-1;k>=0;--k){var F=_[k],ce=F(C);if(!R(ce)&&!he(ce)){if(!to(ce))throw new TypeError;C=ce}}return C}function x(_,C,k,F){for(var ce=_.length-1;ce>=0;--ce){var tt=_[ce],at=tt(C,k,F);if(!R(at)&&!he(at)){if(!te(at))throw new TypeError;F=at}}return F}function v(_,C,k){var F=E(_,C,k);if(F)return!0;var ce=Ah(C);return he(ce)?!1:v(_,ce,k)}function E(_,C,k){var F=Ha(C,k,!1);return R(F)?!1:Ue(F.OrdinaryHasOwnMetadata(_,C,k))}function N(_,C,k){var F=E(_,C,k);if(F)return j(_,C,k);var ce=Ah(C);if(!he(ce))return N(_,ce,k)}function j(_,C,k){var F=Ha(C,k,!1);if(!R(F))return F.OrdinaryGetOwnMetadata(_,C,k)}function U(_,C,k,F){var ce=Ha(k,F,!0);ce.OrdinaryDefineOwnMetadata(_,C,k,F)}function P(_,C){var k=L(_,C),F=Ah(_);if(F===null)return k;var ce=P(F,C);if(ce.length<=0)return k;if(k.length<=0)return ce;for(var tt=new y,at=[],xe=0,Z=k;xe<Z.length;xe++){var ee=Z[xe],oe=tt.has(ee);oe||(tt.add(ee),at.push(ee))}for(var ie=0,_e=ce;ie<_e.length;ie++){var ee=_e[ie],oe=tt.has(ee);oe||(tt.add(ee),at.push(ee))}return at}function L(_,C){var k=Ha(_,C,!1);return k?k.OrdinaryOwnMetadataKeys(_,C):[]}function q(_){if(_===null)return 1;switch(typeof _){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return _===null?1:6;default:return 6}}function R(_){return _===void 0}function he(_){return _===null}function be(_){return typeof _=="symbol"}function te(_){return typeof _=="object"?_!==null:typeof _=="function"}function Se(_,C){switch(q(_)){case 0:return _;case 1:return _;case 2:return _;case 3:return _;case 4:return _;case 5:return _}var k=C===3?"string":C===5?"number":"default",F=d0(_,i);if(F!==void 0){var ce=F.call(_,k);if(te(ce))throw new TypeError;return ce}return Te(_,k==="default"?"number":k)}function Te(_,C){if(C==="string"){var k=_.toString;if(ur(k)){var F=k.call(_);if(!te(F))return F}var ce=_.valueOf;if(ur(ce)){var F=ce.call(_);if(!te(F))return F}}else{var ce=_.valueOf;if(ur(ce)){var F=ce.call(_);if(!te(F))return F}var tt=_.toString;if(ur(tt)){var F=tt.call(_);if(!te(F))return F}}throw new TypeError}function Ue(_){return!!_}function Ee(_){return""+_}function Re(_){var C=Se(_,3);return be(C)?C:Ee(C)}function hn(_){return Array.isArray?Array.isArray(_):_ instanceof Object?_ instanceof Array:Object.prototype.toString.call(_)==="[object Array]"}function ur(_){return typeof _=="function"}function to(_){return typeof _=="function"}function gf(_){switch(q(_)){case 3:return!0;case 4:return!0;default:return!1}}function ls(_,C){return _===C||_!==_&&C!==C}function d0(_,C){var k=_[C];if(k!=null){if(!ur(k))throw new TypeError;return k}}function y0(_){var C=d0(_,s);if(!ur(C))throw new TypeError;var k=C.call(_);if(!te(k))throw new TypeError;return k}function m0(_){return _.value}function g0(_){var C=_.next();return C.done?!1:C}function b0(_){var C=_.return;C&&C.call(_)}function Ah(_){var C=Object.getPrototypeOf(_);if(typeof _!="function"||_===l||C!==l)return C;var k=_.prototype,F=k&&Object.getPrototypeOf(k);if(F==null||F===Object.prototype)return C;var ce=F.constructor;return typeof ce!="function"||ce===_?C:ce}function SS(){var _;!R(w)&&typeof t.Reflect<"u"&&!(w in t.Reflect)&&typeof t.Reflect.defineMetadata=="function"&&(_=CS(t.Reflect));var C,k,F,ce=new m,tt={registerProvider:at,getProvider:Z,setProvider:oe};return tt;function at(ie){if(!Object.isExtensible(tt))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case _===ie:break;case R(C):C=ie;break;case C===ie:break;case R(k):k=ie;break;case k===ie:break;default:F===void 0&&(F=new y),F.add(ie);break}}function xe(ie,_e){if(!R(C)){if(C.isProviderFor(ie,_e))return C;if(!R(k)){if(k.isProviderFor(ie,_e))return C;if(!R(F))for(var Ve=y0(F);;){var rt=g0(Ve);if(!rt)return;var Er=m0(rt);if(Er.isProviderFor(ie,_e))return b0(Ve),Er}}}if(!R(_)&&_.isProviderFor(ie,_e))return _}function Z(ie,_e){var Ve=ce.get(ie),rt;return R(Ve)||(rt=Ve.get(_e)),R(rt)&&(rt=xe(ie,_e),R(rt)||(R(Ve)&&(Ve=new h,ce.set(ie,Ve)),Ve.set(_e,rt))),rt}function ee(ie){if(R(ie))throw new TypeError;return C===ie||k===ie||!R(F)&&F.has(ie)}function oe(ie,_e,Ve){if(!ee(Ve))throw new Error("Metadata provider not registered.");var rt=Z(ie,_e);if(rt!==Ve){if(!R(rt))return!1;var Er=ce.get(ie);R(Er)&&(Er=new h,ce.set(ie,Er)),Er.set(_e,Ve)}return!0}}function AS(){var _;return!R(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&(_=t.Reflect[w]),R(_)&&(_=SS()),!R(w)&&te(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,w,{enumerable:!1,configurable:!1,writable:!1,value:_}),_}function ES(_){var C=new m,k={isProviderFor:function(ee,oe){var ie=C.get(ee);return R(ie)?!1:ie.has(oe)},OrdinaryDefineOwnMetadata:at,OrdinaryHasOwnMetadata:ce,OrdinaryGetOwnMetadata:tt,OrdinaryOwnMetadataKeys:xe,OrdinaryDeleteMetadata:Z};return g.registerProvider(k),k;function F(ee,oe,ie){var _e=C.get(ee),Ve=!1;if(R(_e)){if(!ie)return;_e=new h,C.set(ee,_e),Ve=!0}var rt=_e.get(oe);if(R(rt)){if(!ie)return;if(rt=new h,_e.set(oe,rt),!_.setProvider(ee,oe,k))throw _e.delete(oe),Ve&&C.delete(ee),new Error("Wrong provider for target.")}return rt}function ce(ee,oe,ie){var _e=F(oe,ie,!1);return R(_e)?!1:Ue(_e.has(ee))}function tt(ee,oe,ie){var _e=F(oe,ie,!1);if(!R(_e))return _e.get(ee)}function at(ee,oe,ie,_e){var Ve=F(ie,_e,!0);Ve.set(ee,oe)}function xe(ee,oe){var ie=[],_e=F(ee,oe,!1);if(R(_e))return ie;for(var Ve=_e.keys(),rt=y0(Ve),Er=0;;){var w0=g0(rt);if(!w0)return ie.length=Er,ie;var OS=m0(w0);try{ie[Er]=OS}catch(PS){try{b0(rt)}finally{throw PS}}Er++}}function Z(ee,oe,ie){var _e=F(oe,ie,!1);if(R(_e)||!_e.delete(ee))return!1;if(_e.size===0){var Ve=C.get(oe);R(Ve)||(Ve.delete(ie),Ve.size===0&&C.delete(Ve))}return!0}}function CS(_){var C=_.defineMetadata,k=_.hasOwnMetadata,F=_.getOwnMetadata,ce=_.getOwnMetadataKeys,tt=_.deleteMetadata,at=new m,xe={isProviderFor:function(Z,ee){var oe=at.get(Z);return!R(oe)&&oe.has(ee)?!0:ce(Z,ee).length?(R(oe)&&(oe=new y,at.set(Z,oe)),oe.add(ee),!0):!1},OrdinaryDefineOwnMetadata:C,OrdinaryHasOwnMetadata:k,OrdinaryGetOwnMetadata:F,OrdinaryOwnMetadataKeys:ce,OrdinaryDeleteMetadata:tt};return xe}function Ha(_,C,k){var F=g.getProvider(_,C);if(!R(F))return F;if(k){if(g.setProvider(_,C,A))return A;throw new Error("Illegal state.")}}function TS(){var _={},C=[],k=(function(){function xe(Z,ee,oe){this._index=0,this._keys=Z,this._values=ee,this._selector=oe}return xe.prototype["@@iterator"]=function(){return this},xe.prototype[s]=function(){return this},xe.prototype.next=function(){var Z=this._index;if(Z>=0&&Z<this._keys.length){var ee=this._selector(this._keys[Z],this._values[Z]);return Z+1>=this._keys.length?(this._index=-1,this._keys=C,this._values=C):this._index++,{value:ee,done:!1}}return{value:void 0,done:!0}},xe.prototype.throw=function(Z){throw this._index>=0&&(this._index=-1,this._keys=C,this._values=C),Z},xe.prototype.return=function(Z){return this._index>=0&&(this._index=-1,this._keys=C,this._values=C),{value:Z,done:!0}},xe})(),F=(function(){function xe(){this._keys=[],this._values=[],this._cacheKey=_,this._cacheIndex=-2}return Object.defineProperty(xe.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),xe.prototype.has=function(Z){return this._find(Z,!1)>=0},xe.prototype.get=function(Z){var ee=this._find(Z,!1);return ee>=0?this._values[ee]:void 0},xe.prototype.set=function(Z,ee){var oe=this._find(Z,!0);return this._values[oe]=ee,this},xe.prototype.delete=function(Z){var ee=this._find(Z,!1);if(ee>=0){for(var oe=this._keys.length,ie=ee+1;ie<oe;ie++)this._keys[ie-1]=this._keys[ie],this._values[ie-1]=this._values[ie];return this._keys.length--,this._values.length--,ls(Z,this._cacheKey)&&(this._cacheKey=_,this._cacheIndex=-2),!0}return!1},xe.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=_,this._cacheIndex=-2},xe.prototype.keys=function(){return new k(this._keys,this._values,ce)},xe.prototype.values=function(){return new k(this._keys,this._values,tt)},xe.prototype.entries=function(){return new k(this._keys,this._values,at)},xe.prototype["@@iterator"]=function(){return this.entries()},xe.prototype[s]=function(){return this.entries()},xe.prototype._find=function(Z,ee){if(!ls(this._cacheKey,Z)){this._cacheIndex=-1;for(var oe=0;oe<this._keys.length;oe++)if(ls(this._keys[oe],Z)){this._cacheIndex=oe;break}}return this._cacheIndex<0&&ee&&(this._cacheIndex=this._keys.length,this._keys.push(Z),this._values.push(void 0)),this._cacheIndex},xe})();return F;function ce(xe,Z){return xe}function tt(xe,Z){return Z}function at(xe,Z){return[xe,Z]}}function BS(){var _=(function(){function C(){this._map=new h}return Object.defineProperty(C.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),C.prototype.has=function(k){return this._map.has(k)},C.prototype.add=function(k){return this._map.set(k,k),this},C.prototype.delete=function(k){return this._map.delete(k)},C.prototype.clear=function(){this._map.clear()},C.prototype.keys=function(){return this._map.keys()},C.prototype.values=function(){return this._map.keys()},C.prototype.entries=function(){return this._map.entries()},C.prototype["@@iterator"]=function(){return this.keys()},C.prototype[s]=function(){return this.keys()},C})();return _}function IS(){var _=16,C=p.create(),k=F();return(function(){function Z(){this._key=F()}return Z.prototype.has=function(ee){var oe=ce(ee,!1);return oe!==void 0?p.has(oe,this._key):!1},Z.prototype.get=function(ee){var oe=ce(ee,!1);return oe!==void 0?p.get(oe,this._key):void 0},Z.prototype.set=function(ee,oe){var ie=ce(ee,!0);return ie[this._key]=oe,this},Z.prototype.delete=function(ee){var oe=ce(ee,!1);return oe!==void 0?delete oe[this._key]:!1},Z.prototype.clear=function(){this._key=F()},Z})();function F(){var Z;do Z="@@WeakMap@@"+xe();while(p.has(C,Z));return C[Z]=!0,Z}function ce(Z,ee){if(!n.call(Z,k)){if(!ee)return;Object.defineProperty(Z,k,{value:p.create()})}return Z[k]}function tt(Z,ee){for(var oe=0;oe<ee;++oe)Z[oe]=Math.random()*255|0;return Z}function at(Z){if(typeof Uint8Array=="function"){var ee=new Uint8Array(Z);return typeof crypto<"u"?crypto.getRandomValues(ee):typeof msCrypto<"u"?msCrypto.getRandomValues(ee):tt(ee,Z),ee}return tt(new Array(Z),Z)}function xe(){var Z=at(_);Z[6]=Z[6]&79|64,Z[8]=Z[8]&191|128;for(var ee="",oe=0;oe<_;++oe){var ie=Z[oe];(oe===4||oe===6||oe===8)&&(ee+="-"),ie<16&&(ee+="0"),ee+=ie.toString(16).toLowerCase()}return ee}}function Eh(_){return _.__=void 0,delete _.__,_}})})(Cx||(Cx={}))});var Nn=Ch(zs=>{"use strict";var UC="[object ArrayBuffer]",Pn=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===UC}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}},Zy="string",MC=/^[0-9a-f\s]+$/i,KC=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,HC=/^[a-zA-Z0-9-_]+$/,Fl=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=Pn.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return decodeURIComponent(escape(n))}},mr=class{static toString(e,t=!1){let n=Pn.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}},Wl=class r{static isHex(e){return typeof e===Zy&&MC.test(e)}static isBase64(e){return typeof e===Zy&&KC.test(e)}static isBase64Url(e){return typeof e===Zy&&HC.test(e)}static ToString(e,t="utf8"){let n=Pn.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 mr.toString(n,!0);case"utf16":case"utf16be":return mr.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 mr.fromString(e,!0);case"utf16":case"utf16be":return mr.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Pn.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 Fl.fromString(e);case"utf16":case"utf16be":return mr.fromString(e);case"utf16le":case"usc2":return mr.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 Fl.toString(e);case"utf16":case"utf16be":return mr.toString(e);case"utf16le":case"usc2":return mr.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=Pn.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return n}static ToHex(e){let t=Pn.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 mr.toString(e,t)}static FromUtf16String(e,t=!1){return mr.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,"")||""}};Wl.DEFAULT_UTF8_ENCODING="utf8";function VC(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 $C(...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 FC(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}zs.BufferSourceConverter=Pn;zs.Convert=Wl;zs.assign=VC;zs.combine=$C;zs.isEqual=FC});var v1=Ch((R7,Mp)=>{var t1,r1,n1,o1,i1,s1,a1,c1,u1,Up,og,f1,l1,Sa,p1,h1,d1,y1,m1,g1,b1,w1,x1;(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 Mp=="object"&&typeof Mp.exports=="object"?r(t(e,t(Mp.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])};t1=function(t,n){e(t,n);function o(){this.constructor=t}t.prototype=n===null?Object.create(n):(o.prototype=n.prototype,new o)},r1=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},n1=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},o1=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 u=t.length-1;u>=0;u--)(c=t[u])&&(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},i1=function(t,n){return function(o,i){n(o,i,t)}},s1=function(t,n){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,n)},a1=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 u(h){try{l(i.next(h))}catch(y){c(y)}}function p(h){try{l(i.throw(h))}catch(y){c(y)}}function l(h){h.done?a(h.value):s(h.value).then(u,p)}l((i=i.apply(t,n||[])).next())})},c1=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:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function u(l){return function(h){return p([l,h])}}function p(l){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,s&&(a=l[0]&2?s.return:l[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,l[1])).done)return a;switch(s=0,a&&(l=[l[0]&2,a.value]),l[0]){case 0:case 1:a=l;break;case 4:return o.label++,{value:l[1],done:!1};case 5:o.label++,s=l[1],l=[0];continue;case 7:l=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(l[0]===6||l[0]===2)){o=0;continue}if(l[0]===3&&(!a||l[1]>a[0]&&l[1]<a[3])){o.label=l[1];break}if(l[0]===6&&o.label<a[1]){o.label=a[1],a=l;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(l);break}a[2]&&o.ops.pop(),o.trys.pop();continue}l=n.call(t,o)}catch(h){l=[6,h],s=0}finally{i=a=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},x1=function(t,n,o,i){i===void 0&&(i=o),t[i]=n[o]},u1=function(t,n){for(var o in t)o!=="default"&&!n.hasOwnProperty(o)&&(n[o]=t[o])},Up=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.")},og=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(u){c={error:u}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(c)throw c.error}}return a},f1=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(og(arguments[n]));return t},l1=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,u=a.length;c<u;c++,s++)i[s]=a[c];return i},Sa=function(t){return this instanceof Sa?(this.v=t,this):new Sa(t)},p1=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(m){i[m]&&(s[m]=function(w){return new Promise(function(g,A){a.push([m,w,g,A])>1||u(m,w)})})}function u(m,w){try{p(i[m](w))}catch(g){y(a[0][3],g)}}function p(m){m.value instanceof Sa?Promise.resolve(m.value.v).then(l,h):y(a[0][2],m)}function l(m){u("next",m)}function h(m){u("throw",m)}function y(m,w){m(w),a.shift(),a.length&&u(a[0][0],a[0][1])}},h1=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:Sa(t[s](c)),done:s==="return"}:a?a(c):c}:a}},d1=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 Up=="function"?Up(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(u,p){c=t[a](c),s(u,p,c.done,c.value)})}}function s(a,c,u,p){Promise.resolve(p).then(function(l){a({value:l,done:u})},c)}},y1=function(t,n){return Object.defineProperty?Object.defineProperty(t,"raw",{value:n}):t.raw=n,t},m1=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},g1=function(t){return t&&t.__esModule?t:{default:t}},b1=function(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");return n.get(t)},w1=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",t1),r("__assign",r1),r("__rest",n1),r("__decorate",o1),r("__param",i1),r("__metadata",s1),r("__awaiter",a1),r("__generator",c1),r("__exportStar",u1),r("__createBinding",x1),r("__values",Up),r("__read",og),r("__spread",f1),r("__spreadArrays",l1),r("__await",Sa),r("__asyncGenerator",p1),r("__asyncDelegator",h1),r("__asyncValues",d1),r("__makeTemplateObject",y1),r("__importStar",m1),r("__importDefault",g1),r("__classPrivateFieldGet",b1),r("__classPrivateFieldSet",w1)})});var QB={};Ct(QB,{webRTC:()=>JB,webRTCDirect:()=>YB});var wf=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}},xf=class extends Error{static name="InvalidCryptoExchangeError";constructor(e="Invalid crypto exchange"){super(e),this.name="InvalidCryptoExchangeError"}},ve=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ps=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Va=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var vf=class extends Error{static name="ConnectionFailedError";constructor(e="Connection failed"){super(e),this.name="ConnectionFailedError"}},_f=class extends Error{static name="MuxerClosedError";constructor(e="The muxer is closed"){super(e),this.name="MuxerClosedError"}},hs=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var dn=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},$a=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},Go=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Sf=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Af=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Ef=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Cf=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Tf=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ro=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bf=class extends Event{data;constructor(e,t){super("message",t),this.data=e}},ds=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}},If=class extends ds{constructor(e,t){super(!0,e,t)}},Of=class extends ds{constructor(e,t){super(!1,e,t)}};var Th=Symbol.for("@libp2p/peer-id");var Pf=Symbol.for("@libp2p/transport");var v0;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(v0||(v0={}));var fr=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 ys=Symbol.for("@libp2p/service-capabilities"),_0=Symbol.for("@libp2p/service-dependencies");var Nh={};Ct(Nh,{base58btc:()=>Ze,base58flickr:()=>FS});var PI=new Uint8Array(0);function S0(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 yn(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 A0(r){return new TextEncoder().encode(r)}function E0(r){return new TextDecoder().decode(r)}function US(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),u=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var w=0,g=0,A=0,D=m.length;A!==D&&m[A]===0;)A++,w++;for(var B=(D-A)*p+1>>>0,$=new Uint8Array(B);A!==D;){for(var Q=m[A],X=0,ne=B-1;(Q!==0||X<g)&&ne!==-1;ne--,X++)Q+=256*$[ne]>>>0,$[ne]=Q%a>>>0,Q=Q/a>>>0;if(Q!==0)throw new Error("Non-zero carry");g=X,A++}for(var Y=B-g;Y!==B&&$[Y]===0;)Y++;for(var I=c.repeat(w);Y<B;++Y)I+=r.charAt($[Y]);return I}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var w=0;if(m[w]!==" "){for(var g=0,A=0;m[w]===c;)g++,w++;for(var D=(m.length-w)*u+1>>>0,B=new Uint8Array(D);m[w];){var $=t[m.charCodeAt(w)];if($===255)return;for(var Q=0,X=D-1;($!==0||Q<A)&&X!==-1;X--,Q++)$+=a*B[X]>>>0,B[X]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");A=Q,w++}if(m[w]!==" "){for(var ne=D-A;ne!==D&&B[ne]===0;)ne++;for(var Y=new Uint8Array(g+(D-ne)),I=g;ne!==D;)Y[I++]=B[ne++];return Y}}}function y(m){var w=h(m);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:y}}var MS=US,KS=MS,T0=KS;var Bh=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")}},Ih=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 B0(this,e)}},Oh=class{decoders;constructor(e){this.decoders=e}or(e){return B0(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 B0(r,e){return new Oh({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ph=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 Bh(e,t,n),this.decoder=new Ih(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ms({name:r,prefix:e,encode:t,decode:n}){return new Ph(r,e,t,n)}function no({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=T0(t,r);return ms({prefix:e,name:r,encode:n,decode:i=>yn(o(i))})}function HS(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 u=0;u<o;++u){let p=e[r[u]];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 VS(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 $S(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=$S(n);return ms({prefix:e,name:r,encode(i){return VS(i,n,t)},decode(i){return HS(i,o,t,r)}})}var Ze=no({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),FS=no({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kh={};Ct(kh,{base32:()=>oo,base32hex:()=>zS,base32hexpad:()=>ZS,base32hexpadupper:()=>YS,base32hexupper:()=>XS,base32pad:()=>qS,base32padupper:()=>GS,base32upper:()=>WS,base32z:()=>JS});var oo=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),WS=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qS=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),GS=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zS=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),XS=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ZS=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),YS=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),JS=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Dh={};Ct(Dh,{base36:()=>Fa,base36upper:()=>QS});var Fa=no({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),QS=no({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cr={};Ct(Cr,{Digest:()=>zo,create:()=>Dt,decode:()=>ws,equals:()=>jh,hasCode:()=>bA});var eA=P0,I0=128,tA=127,rA=~tA,nA=Math.pow(2,31);function P0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=nA;)e[t++]=r&255|I0,r/=128;for(;r&rA;)e[t++]=r&255|I0,r>>>=7;return e[t]=r|0,P0.bytes=t-n+1,e}var oA=Rh,iA=128,O0=127;function Rh(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Rh.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&O0)<<o:(s&O0)*Math.pow(2,o),o+=7}while(s>=iA);return Rh.bytes=i-n,t}var sA=Math.pow(2,7),aA=Math.pow(2,14),cA=Math.pow(2,21),uA=Math.pow(2,28),fA=Math.pow(2,35),lA=Math.pow(2,42),pA=Math.pow(2,49),hA=Math.pow(2,56),dA=Math.pow(2,63),yA=function(r){return r<sA?1:r<aA?2:r<cA?3:r<uA?4:r<fA?5:r<lA?6:r<pA?7:r<hA?8:r<dA?9:10},mA={encode:eA,decode:oA,encodingLength:yA},gA=mA,Wa=gA;function qa(r,e=0){return[Wa.decode(r,e),Wa.decode.bytes]}function gs(r,e,t=0){return Wa.encode(r,e,t),e}function bs(r){return Wa.encodingLength(r)}function Dt(r,e){let t=e.byteLength,n=bs(r),o=n+bs(t),i=new Uint8Array(o+t);return gs(r,i,0),gs(t,i,n),i.set(e,o),new zo(r,t,e,i)}function ws(r){let e=yn(r),[t,n]=qa(e),[o,i]=qa(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new zo(t,o,s,e)}function jh(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&S0(r.bytes,t.bytes)}}var zo=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function bA(r,e){return r.code===e}function N0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return xA(t,Lh(r),e??Ze.encoder);default:return vA(t,Lh(r),e??oo.encoder)}}var k0=new WeakMap;function Lh(r){let e=k0.get(r);if(e==null){let t=new Map;return k0.set(r,t),t}return e}var ct=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Ga)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==_A)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=Dt(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&&jh(e.multihash,n.multihash)}toString(e){return N0(this,e)}toJSON(){return{"/":N0(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??D0(n,o,i.bytes))}else if(t[SA]===!0){let{version:n,multihash:o,code:i}=t,s=ws(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Ga)throw new Error(`Version 0 CID must use dag-pb (code: ${Ga}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=D0(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Ga,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=yn(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 zo(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[l,h]=qa(e.subarray(t));return t+=h,l},o=n(),i=Ga;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),u=t+c,p=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:p,size:u}}static parse(e,t){let[n,o]=wA(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 Lh(i).set(n,e),i}};function wA(r,e){switch(r[0]){case"Q":{let t=e??Ze;return[Ze.prefix,t.decode(`${Ze.prefix}${r}`)]}case Ze.prefix:{let t=e??Ze;return[Ze.prefix,t.decode(r)]}case oo.prefix:{let t=e??oo;return[oo.prefix,t.decode(r)]}case Fa.prefix:{let t=e??Fa;return[Fa.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 xA(r,e,t){let{prefix:n}=t;if(n!==Ze.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 vA(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var Ga=112,_A=18;function D0(r,e,t){let n=bs(r),o=n+bs(e),i=new Uint8Array(o+t.byteLength);return gs(r,i,0),gs(e,i,n),i.set(t,o),i}var SA=Symbol.for("@ipld/js-cid/CID");var Uh={};Ct(Uh,{identity:()=>Tr});var R0=0,AA="identity",j0=yn;function EA(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Dt(R0,j0(r))}var Tr={code:R0,name:AA,encode:j0,digest:EA};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 ut(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function Rt(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ft(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var U0=Symbol.for("@achingbrain/uint8arraylist");function L0(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 kf(r){return!!r?.[U0]}var me=class r{bufs;length;[U0]=!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(kf(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(kf(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=L0(this.bufs,e);return t.buf[t.index]}set(e,t){let n=L0(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(kf(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 Rt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Rt(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 u=e>=a&&e<c,p=t>a&&t<=c;if(u&&p){if(e===a&&t===c){n.push(s);break}let l=e-a;n.push(s.subarray(l,l+(t-e)));break}if(u){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(!kf(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 l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,p;for(let l=t;l<=c;l+=p){p=0;for(let h=u;h>=0;h--){let y=this.get(l+h);if(n[h]!==y){p=Math.max(1,h-a[y]);break}}if(p===0)return l}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=ft(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=ut(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=ut(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=ut(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=ft(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=ut(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=ut(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=ut(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=ut(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=ut(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 Mh={};Ct(Mh,{base10:()=>TA});var TA=no({prefix:"9",name:"base10",alphabet:"0123456789"});var Kh={};Ct(Kh,{base16:()=>BA,base16upper:()=>IA});var BA=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),IA=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hh={};Ct(Hh,{base2:()=>OA});var OA=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vh={};Ct(Vh,{base256emoji:()=>RA});var M0=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}"),PA=M0.reduce((r,e,t)=>(r[t]=e,r),[]),NA=M0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function kA(r){return r.reduce((e,t)=>(e+=PA[t],e),"")}function DA(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=NA[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var RA=ms({prefix:"\u{1F680}",name:"base256emoji",encode:kA,decode:DA});var $h={};Ct($h,{base64:()=>jA,base64pad:()=>LA,base64url:()=>Xo,base64urlpad:()=>UA});var jA=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),LA=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xo=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),UA=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fh={};Ct(Fh,{base8:()=>MA});var MA=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Wh={};Ct(Wh,{identity:()=>KA});var KA=ms({prefix:"\0",name:"identity",encode:r=>E0(r),decode:r=>A0(r)});var hO=new TextEncoder,dO=new TextDecoder;var zh={};Ct(zh,{sha256:()=>lr,sha512:()=>FA});var $A=20;function Gh({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new qh(r,e,t,n,o)}var qh=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??$A,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?K0(n,this.code,t?.truncate):n.then(o=>K0(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function K0(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Dt(e,r)}function V0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var lr=Gh({name:"sha2-256",code:18,encode:V0("SHA-256")}),FA=Gh({name:"sha2-512",code:19,encode:V0("SHA-512")});var Zo={...Wh,...Hh,...Fh,...Mh,...Kh,...kh,...Dh,...Nh,...$h,...Vh},CO={...zh,...Uh};function F0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var $0=F0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Xh=F0("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=ft(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),WA={utf8:$0,"utf-8":$0,hex:Zo.base16,latin1:Xh,ascii:Xh,binary:Xh,...Zo},Df=WA;function ye(r,e="utf8"){let t=Df[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function le(r,e="utf8"){let t=Df[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var qA=parseInt("11111",2),Zh=parseInt("10000000",2),GA=parseInt("01111111",2),W0={0:za,1:za,2:zA,3:YA,4:JA,5:ZA,6:XA,16:za,22:za,48:za};function mn(r,e={offset:0}){let t=r[e.offset]&qA;if(e.offset++,W0[t]!=null)return W0[t](r,e);throw new Error("No decoder for tag "+t)}function Xa(r,e){let t=0;if((r[e.offset]&Zh)===Zh){let n=r[e.offset]&GA,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 za(r,e){Xa(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=mn(r,e);if(n===null)break;t.push(n)}return t}function zA(r,e){let t=Xa(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 XA(r,e){let t=Xa(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 u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let p=0;for(let l=0;l<c.length;l++)p+=c[l]<<l*7;a+=`.${p}`,c=[]}}return a}function ZA(r,e){return e.offset++,null}function YA(r,e){let t=Xa(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 JA(r,e){let t=Xa(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function QA(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new me;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function Rf(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=QA(r.byteLength);return new me(Uint8Array.from([e.byteLength|Zh]),e)}function jt(r){let e=new me,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new me(Uint8Array.from([2]),Rf(e),e)}function Za(r){let e=Uint8Array.from([0]),t=new me(e,r);return new me(Uint8Array.from([3]),Rf(t),t)}function q0(r){return new me(Uint8Array.from([4]),Rf(r),r)}function Br(r,e=48){let t=new me;for(let n of r)t.append(n);return new me(Uint8Array.from([e]),Rf(t),t)}async function G0(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 z0(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 X0(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 eE=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),tE=Uint8Array.from([6,5,43,129,4,0,34]),rE=Uint8Array.from([6,5,43,129,4,0,35]),nE={ext:!0,kty:"EC",crv:"P-256"},oE={ext:!0,kty:"EC",crv:"P-384"},iE={ext:!0,kty:"EC",crv:"P-521"},Yh=32,Jh=48,Qh=66;function ed(r){let e=mn(r);return Z0(e)}function Z0(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Yh*2+1)return n=le(e.subarray(t,t+Yh),"base64url"),o=le(e.subarray(t+Yh),"base64url"),new Yo({...nE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Jh*2+1)return n=le(e.subarray(t,t+Jh),"base64url"),o=le(e.subarray(t+Jh),"base64url"),new Yo({...oE,key_ops:["verify"],x:n,y:o});if(e.byteLength===Qh*2+1)return n=le(e.subarray(t,t+Qh),"base64url"),o=le(e.subarray(t+Qh),"base64url"),new Yo({...iE,key_ops:["verify"],x:n,y:o});throw new ve(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Y0(r){return Br([jt(Uint8Array.from([1])),q0(ye(r.d??"","base64url")),Br([Q0(r.crv)],160),Br([Za(new me(Uint8Array.from([4]),ye(r.x??"","base64url"),ye(r.y??"","base64url")))],161)]).subarray()}function J0(r){return Br([jt(Uint8Array.from([1])),Br([Q0(r.crv)],160),Br([Za(new me(Uint8Array.from([4]),ye(r.x??"","base64url"),ye(r.y??"","base64url")))],161)]).subarray()}function Q0(r){if(r==="P-256")return eE;if(r==="P-384")return tE;if(r==="P-521")return rE;throw new ve(`Invalid curve ${r}`)}async function eb(r="P-256"){let e=await G0(r);return new jf(e.privateKey)}var Yo=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=J0(this.jwk)),this._raw}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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 X0(this.jwk,t,e,n)}},jf=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Yo({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=Y0(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}async sign(e,t){return z0(this.jwk,e,t)}};var Jo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bn(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Qo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Tt(r,...e){if(!bn(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 ei(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Qo(r.outputLen),Qo(r.blockLen)}function vs(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 rb(r,e){Tt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Ir(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Lf(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Or(r,e){return r<<32-e|r>>>e}var nb=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",sE=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function pr(r){if(Tt(r),nb)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=sE[r[t]];return e}var gn={_0:48,_9:57,A:65,F:70,a:97,f:102};function tb(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 ti(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(nb)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=tb(r.charCodeAt(i)),a=tb(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 td(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function so(r){return typeof r=="string"&&(r=td(r)),Tt(r),r}function Lt(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];Tt(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 xs=class{};function rd(r){let e=n=>r().update(so(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function ao(r=32){if(Jo&&typeof Jo.getRandomValues=="function")return Jo.getRandomValues(new Uint8Array(r));if(Jo&&typeof Jo.randomBytes=="function")return Uint8Array.from(Jo.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function aE(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,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function ob(r,e,t){return r&e^~r&t}function ib(r,e,t){return r&e^r&t^e&t}var Ya=class extends xs{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=Lf(this.buffer)}update(e){vs(this),e=so(e),Tt(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=Lf(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){vs(this),rb(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;t[s++]=128,Ir(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)t[l]=0;aE(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Lf(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,p=this.get();if(u>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,p[l],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()}},wn=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 Uf=BigInt(4294967295),sb=BigInt(32);function cE(r,e=!1){return e?{h:Number(r&Uf),l:Number(r>>sb&Uf)}:{h:Number(r>>sb&Uf)|0,l:Number(r&Uf)|0}}function ab(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}=cE(r[i],e);[n[i],o[i]]=[s,a]}return[n,o]}var nd=(r,e,t)=>r>>>t,od=(r,e,t)=>r<<32-t|e>>>t,ri=(r,e,t)=>r>>>t|e<<32-t,ni=(r,e,t)=>r<<32-t|e>>>t,Ja=(r,e,t)=>r<<64-t|e>>>t-32,Qa=(r,e,t)=>r>>>t-32|e<<64-t;function zr(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var cb=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ub=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,fb=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),lb=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,pb=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),hb=(r,e,t,n,o,i)=>e+t+n+o+i+(r/2**32|0)|0;var fE=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]),co=new Uint32Array(64),Mf=class extends Ya{constructor(e=32){super(64,e,8,!1),this.A=wn[0]|0,this.B=wn[1]|0,this.C=wn[2]|0,this.D=wn[3]|0,this.E=wn[4]|0,this.F=wn[5]|0,this.G=wn[6]|0,this.H=wn[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 l=0;l<16;l++,t+=4)co[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let h=co[l-15],y=co[l-2],m=Or(h,7)^Or(h,18)^h>>>3,w=Or(y,17)^Or(y,19)^y>>>10;co[l]=w+co[l-7]+m+co[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:p}=this;for(let l=0;l<64;l++){let h=Or(a,6)^Or(a,11)^Or(a,25),y=p+h+ob(a,c,u)+fE[l]+co[l]|0,w=(Or(n,2)^Or(n,13)^Or(n,22))+ib(n,o,i)|0;p=u,u=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,u,p)}roundClean(){Ir(co)}destroy(){this.set(0,0,0,0,0,0,0,0),Ir(this.buffer)}};var db=ab(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),lE=db[0],pE=db[1],uo=new Uint32Array(80),fo=new Uint32Array(80),id=class extends Ya{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:u,El:p,Fh:l,Fl:h,Gh:y,Gl:m,Hh:w,Hl:g}=this;return[e,t,n,o,i,s,a,c,u,p,l,h,y,m,w,g]}set(e,t,n,o,i,s,a,c,u,p,l,h,y,m,w,g){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=u|0,this.El=p|0,this.Fh=l|0,this.Fl=h|0,this.Gh=y|0,this.Gl=m|0,this.Hh=w|0,this.Hl=g|0}process(e,t){for(let B=0;B<16;B++,t+=4)uo[B]=e.getUint32(t),fo[B]=e.getUint32(t+=4);for(let B=16;B<80;B++){let $=uo[B-15]|0,Q=fo[B-15]|0,X=ri($,Q,1)^ri($,Q,8)^nd($,Q,7),ne=ni($,Q,1)^ni($,Q,8)^od($,Q,7),Y=uo[B-2]|0,I=fo[B-2]|0,K=ri(Y,I,19)^Ja(Y,I,61)^nd(Y,I,6),z=ni(Y,I,19)^Qa(Y,I,61)^od(Y,I,6),V=fb(ne,z,fo[B-7],fo[B-16]),x=lb(V,X,K,uo[B-7],uo[B-16]);uo[B]=x|0,fo[B]=V|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:p,Eh:l,El:h,Fh:y,Fl:m,Gh:w,Gl:g,Hh:A,Hl:D}=this;for(let B=0;B<80;B++){let $=ri(l,h,14)^ri(l,h,18)^Ja(l,h,41),Q=ni(l,h,14)^ni(l,h,18)^Qa(l,h,41),X=l&y^~l&w,ne=h&m^~h&g,Y=pb(D,Q,ne,pE[B],fo[B]),I=hb(Y,A,$,X,lE[B],uo[B]),K=Y|0,z=ri(n,o,28)^Ja(n,o,34)^Ja(n,o,39),V=ni(n,o,28)^Qa(n,o,34)^Qa(n,o,39),x=n&i^n&a^i&a,v=o&s^o&c^s&c;A=w|0,D=g|0,w=y|0,g=m|0,y=l|0,m=h|0,{h:l,l:h}=zr(u|0,p|0,I|0,K|0),u=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let E=cb(K,V,v);n=ub(E,I,z,x),o=E|0}({h:n,l:o}=zr(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=zr(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=zr(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:p}=zr(this.Dh|0,this.Dl|0,u|0,p|0),{h:l,l:h}=zr(this.Eh|0,this.El|0,l|0,h|0),{h:y,l:m}=zr(this.Fh|0,this.Fl|0,y|0,m|0),{h:w,l:g}=zr(this.Gh|0,this.Gl|0,w|0,g|0),{h:A,l:D}=zr(this.Hh|0,this.Hl|0,A|0,D|0),this.set(n,o,i,s,a,c,u,p,l,h,y,m,w,g,A,D)}roundClean(){Ir(uo,fo)}destroy(){Ir(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var lo=rd(()=>new Mf);var yb=rd(()=>new id);var cd=BigInt(0),ad=BigInt(1);function xn(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}"`;throw new Error(t+"expected boolean, got type="+typeof r)}return r}function tr(r,e,t=""){let n=bn(r),o=r?.length,i=e!==void 0;if(!n||i&&o!==e){let s=t&&`"${t}" `,a=i?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return r}function ec(r){let e=r.toString(16);return e.length&1?"0"+e:e}function mb(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?cd:BigInt("0x"+r)}function _s(r){return mb(pr(r))}function hr(r){return Tt(r),mb(pr(Uint8Array.from(r).reverse()))}function Kf(r,e){return ti(r.toString(16).padStart(e*2,"0"))}function tc(r,e){return Kf(r,e).reverse()}function Oe(r,e,t){let n;if(typeof e=="string")try{n=ti(e)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(bn(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 gb(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function ud(r){return Uint8Array.from(r)}var sd=r=>typeof r=="bigint"&&cd<=r;function bb(r,e,t){return sd(r)&&sd(e)&&sd(t)&&e<=r&&r<t}function po(r,e,t,n){if(!bb(e,t,n))throw new Error("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Hf(r){let e;for(e=0;r>cd;r>>=ad,e+=1);return e}var ho=r=>(ad<<BigInt(r))-ad;function wb(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),i=n(r),s=n(r),a=0,c=()=>{i.fill(1),s.fill(0),a=0},u=(...y)=>t(s,i,...y),p=(y=n(0))=>{s=u(o(0),y),i=u(),y.length!==0&&(s=u(o(1),y),i=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,m=[];for(;y<e;){i=u();let w=i.slice();m.push(w),y+=i.length}return Lt(...m)};return(y,m)=>{c(),p(y);let w;for(;!(w=m(l()));)p();return c(),w}}function Xr(r,e,t={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,s){let a=r[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([o,i])=>n(o,i,!1)),Object.entries(t).forEach(([o,i])=>n(o,i,!0))}var fd=()=>{throw new Error("not implemented")};function Ss(r){let e=new WeakMap;return(t,...n)=>{let o=e.get(t);if(o!==void 0)return o;let i=r(t,...n);return e.set(t,i),i}}var Ut=BigInt(0),pt=BigInt(1),oi=BigInt(2),_b=BigInt(3),Sb=BigInt(4),Ab=BigInt(5),hE=BigInt(7),Eb=BigInt(8),dE=BigInt(9),Cb=BigInt(16);function $e(r,e){let t=r%e;return t>=Ut?t:e+t}function Fe(r,e,t){let n=r;for(;e-- >Ut;)n*=n,n%=t;return n}function xb(r,e){if(r===Ut)throw new Error("invert: expected non-zero number");if(e<=Ut)throw new Error("invert: expected positive modulus, got "+e);let t=$e(r,e),n=e,o=Ut,i=pt,s=pt,a=Ut;for(;t!==Ut;){let u=n/t,p=n%t,l=o-s*u,h=i-a*u;n=t,t=p,o=s,i=a,s=l,a=h}if(n!==pt)throw new Error("invert: does not exist");return $e(o,e)}function ld(r,e,t){if(!r.eql(r.sqr(e),t))throw new Error("Cannot find square root")}function Tb(r,e){let t=(r.ORDER+pt)/Sb,n=r.pow(e,t);return ld(r,n,e),n}function yE(r,e){let t=(r.ORDER-Ab)/Eb,n=r.mul(e,oi),o=r.pow(n,t),i=r.mul(e,o),s=r.mul(r.mul(i,oi),o),a=r.mul(i,r.sub(s,r.ONE));return ld(r,a,e),a}function mE(r){let e=rr(r),t=Bb(r),n=t(e,e.neg(e.ONE)),o=t(e,n),i=t(e,e.neg(n)),s=(r+hE)/Cb;return(a,c)=>{let u=a.pow(c,s),p=a.mul(u,n),l=a.mul(u,o),h=a.mul(u,i),y=a.eql(a.sqr(p),c),m=a.eql(a.sqr(l),c);u=a.cmov(u,p,y),p=a.cmov(h,l,m);let w=a.eql(a.sqr(p),c),g=a.cmov(u,p,w);return ld(a,g,c),g}}function Bb(r){if(r<_b)throw new Error("sqrt is not defined for small field");let e=r-pt,t=0;for(;e%oi===Ut;)e/=oi,t++;let n=oi,o=rr(r);for(;vb(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Tb;let i=o.pow(n,e),s=(e+pt)/oi;return function(c,u){if(c.is0(u))return u;if(vb(c,u)!==1)throw new Error("Cannot find square root");let p=t,l=c.mul(c.ONE,i),h=c.pow(u,e),y=c.pow(u,s);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let m=1,w=c.sqr(h);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===p)throw new Error("Cannot find square root");let g=pt<<BigInt(p-m-1),A=c.pow(l,g);p=m,l=c.sqr(A),h=c.mul(h,l),y=c.mul(y,A)}return y}}function gE(r){return r%Sb===_b?Tb:r%Eb===Ab?yE:r%Cb===dE?mE(r):Bb(r)}var vn=(r,e)=>($e(r,e)&pt)===pt,bE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function pd(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},t=bE.reduce((n,o)=>(n[o]="function",n),e);return Xr(r,t),r}function wE(r,e,t){if(t<Ut)throw new Error("invalid exponent, negatives unsupported");if(t===Ut)return r.ONE;if(t===pt)return e;let n=r.ONE,o=e;for(;t>Ut;)t&pt&&(n=r.mul(n,o)),o=r.sqr(o),t>>=pt;return n}function rc(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 vb(r,e){let t=(r.ORDER-pt)/oi,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 Vf(r,e){e!==void 0&&Qo(e);let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function rr(r,e,t=!1,n={}){if(r<=Ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,i,s=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||t)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(o=h.BITS),h.sqrt&&(i=h.sqrt),typeof h.isLE=="boolean"&&(t=h.isLE),typeof h.modFromBytes=="boolean"&&(s=h.modFromBytes),a=h.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=Vf(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:r,isLE:t,BITS:c,BYTES:u,MASK:ho(c),ZERO:Ut,ONE:pt,allowedLengths:a,create:h=>$e(h,r),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return Ut<=h&&h<r},is0:h=>h===Ut,isValidNot0:h=>!l.is0(h)&&l.isValid(h),isOdd:h=>(h&pt)===pt,neg:h=>$e(-h,r),eql:(h,y)=>h===y,sqr:h=>$e(h*h,r),add:(h,y)=>$e(h+y,r),sub:(h,y)=>$e(h-y,r),mul:(h,y)=>$e(h*y,r),pow:(h,y)=>wE(l,h,y),div:(h,y)=>$e(h*xb(y,r),r),sqrN:h=>h*h,addN:(h,y)=>h+y,subN:(h,y)=>h-y,mulN:(h,y)=>h*y,inv:h=>xb(h,r),sqrt:i||(h=>(p||(p=gE(r)),p(l,h))),toBytes:h=>t?tc(h,u):Kf(h,u),fromBytes:(h,y=!0)=>{if(a){if(!a.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+h.length);let w=new Uint8Array(u);w.set(h,t?0:w.length-h.length),h=w}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let m=t?hr(h):_s(h);if(s&&(m=$e(m,r)),!y&&!l.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>rc(l,h),cmov:(h,y,m)=>m?y:h});return Object.freeze(l)}function Ib(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 hd(r){let e=Ib(r);return e+Math.ceil(e/2)}function dd(r,e,t=!1){let n=r.length,o=Ib(e),i=hd(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=t?hr(r):_s(r),a=$e(s,e-pt)+pt;return t?tc(a,o):Kf(a,o)}var As=BigInt(0),ii=BigInt(1);function nc(r,e){let t=e.negate();return r?t:e}function _n(r,e){let t=rc(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function kb(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function yd(r,e){kb(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,i=ho(r),s=BigInt(r);return{windows:t,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Ob(r,e,t){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=t,a=Number(r&o),c=r>>s;a>n&&(a-=i,c+=ii);let u=e*n,p=u+Math.abs(a)-1,l=a===0,h=a<0,y=e%2!==0;return{nextN:c,offset:p,isZero:l,isNeg:h,isNegF:y,offsetF:u}}function xE(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 vE(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 md=new WeakMap,Db=new WeakMap;function gd(r){return Db.get(r)||1}function Pb(r){if(r!==As)throw new Error("invalid wNAF")}var Es=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>As;)t&ii&&(n=n.add(o)),o=o.double(),t>>=ii;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=yd(t,this.bits),i=[],s=e,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=yd(e,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:p,isNeg:l,isNegF:h,offsetF:y}=Ob(n,a,s);n=c,p?i=i.add(nc(h,t[y])):o=o.add(nc(l,t[u]))}return Pb(n),{p:o,f:i}}wNAFUnsafe(e,t,n,o=this.ZERO){let i=yd(e,this.bits);for(let s=0;s<i.windows&&n!==As;s++){let{nextN:a,offset:c,isZero:u,isNeg:p}=Ob(n,s,i);if(n=a,!u){let l=t[c];o=o.add(p?l.negate():l)}}return Pb(n),o}getPrecomputes(e,t,n){let o=md.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),md.set(t,o))),o}cached(e,t,n){let o=gd(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let i=gd(e);return i===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,o)}createCache(e,t){kb(t,this.bits),Db.set(e,t),md.delete(e)}hasCache(e){return gd(e)!==1}};function Rb(r,e,t,n){let o=e,i=r.ZERO,s=r.ZERO;for(;t>As||n>As;)t&ii&&(i=i.add(o)),n&ii&&(s=s.add(o)),o=o.double(),t>>=ii,n>>=ii;return{p1:i,p2:s}}function Cs(r,e,t,n){xE(t,r),vE(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=Hf(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ho(c),p=new Array(Number(u)+1).fill(s),l=Math.floor((e.BITS-1)/c)*c,h=s;for(let y=l;y>=0;y-=c){p.fill(s);for(let w=0;w<i;w++){let g=n[w],A=Number(g>>BigInt(y)&u);p[A]=p[A].add(t[w])}let m=s;for(let w=p.length-1,g=s;w>0;w--)g=g.add(p[w]),m=m.add(g);if(h=h.add(m),y!==0)for(let w=0;w<c;w++)h=h.double()}return h}function Nb(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return pd(e),e}else return rr(r,{isLE:t})}function $f(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>As))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Nb(e.p,t.Fp,n),i=Nb(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}var yo=BigInt(0),ht=BigInt(1),bd=BigInt(2),_E=BigInt(8);function SE(r,e,t,n){let o=r.sqr(t),i=r.sqr(n),s=r.add(r.mul(e.a,o),i),a=r.add(r.ONE,r.mul(e.d,r.mul(o,i)));return r.eql(s,a)}function AE(r,e={}){let t=$f("edwards",r,e,e.FpFnLE),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s}=i;Xr(e,{},{uvRatio:"function"});let a=bd<<BigInt(o.BYTES*8)-ht,c=g=>n.create(g),u=e.uvRatio||((g,A)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,A))}}catch{return{isValid:!1,value:yo}}});if(!SE(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(g,A,D=!1){let B=D?ht:yo;return po("coordinate "+g,A,B,a),A}function l(g){if(!(g instanceof m))throw new Error("ExtendedPoint expected")}let h=Ss((g,A)=>{let{X:D,Y:B,Z:$}=g,Q=g.is0();A==null&&(A=Q?_E:n.inv($));let X=c(D*A),ne=c(B*A),Y=n.mul($,A);if(Q)return{x:yo,y:ht};if(Y!==ht)throw new Error("invZ was invalid");return{x:X,y:ne}}),y=Ss(g=>{let{a:A,d:D}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:B,Y:$,Z:Q,T:X}=g,ne=c(B*B),Y=c($*$),I=c(Q*Q),K=c(I*I),z=c(ne*A),V=c(I*c(z+Y)),x=c(K+c(D*c(ne*Y)));if(V!==x)throw new Error("bad point: equation left != right (1)");let v=c(B*$),E=c(Q*X);if(v!==E)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(A,D,B,$){this.X=p("x",A),this.Y=p("y",D),this.Z=p("z",B,!0),this.T=p("t",$),Object.freeze(this)}static CURVE(){return i}static fromAffine(A){if(A instanceof m)throw new Error("extended point not allowed");let{x:D,y:B}=A||{};return p("x",D),p("y",B),new m(D,B,ht,c(D*B))}static fromBytes(A,D=!1){let B=n.BYTES,{a:$,d:Q}=i;A=ud(tr(A,B,"point")),xn(D,"zip215");let X=ud(A),ne=A[B-1];X[B-1]=ne&-129;let Y=hr(X),I=D?a:n.ORDER;po("point.y",Y,yo,I);let K=c(Y*Y),z=c(K-ht),V=c(Q*K-$),{isValid:x,value:v}=u(z,V);if(!x)throw new Error("bad point: invalid y coordinate");let E=(v&ht)===ht,N=(ne&128)!==0;if(!D&&v===yo&&N)throw new Error("bad point: x=0 and x_0=1");return N!==E&&(v=c(-v)),m.fromAffine({x:v,y:Y})}static fromHex(A,D=!1){return m.fromBytes(Oe("point",A),D)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(A=8,D=!0){return w.createCache(this,A),D||this.multiply(bd),this}assertValidity(){y(this)}equals(A){l(A);let{X:D,Y:B,Z:$}=this,{X:Q,Y:X,Z:ne}=A,Y=c(D*ne),I=c(Q*$),K=c(B*ne),z=c(X*$);return Y===I&&K===z}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:A}=i,{X:D,Y:B,Z:$}=this,Q=c(D*D),X=c(B*B),ne=c(bd*c($*$)),Y=c(A*Q),I=D+B,K=c(c(I*I)-Q-X),z=Y+X,V=z-ne,x=Y-X,v=c(K*V),E=c(z*x),N=c(K*x),j=c(V*z);return new m(v,E,j,N)}add(A){l(A);let{a:D,d:B}=i,{X:$,Y:Q,Z:X,T:ne}=this,{X:Y,Y:I,Z:K,T:z}=A,V=c($*Y),x=c(Q*I),v=c(ne*B*z),E=c(X*K),N=c(($+Q)*(Y+I)-V-x),j=E-v,U=E+v,P=c(x-D*V),L=c(N*j),q=c(U*P),R=c(N*P),he=c(j*U);return new m(L,q,he,R)}subtract(A){return this.add(A.negate())}multiply(A){if(!o.isValidNot0(A))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:D,f:B}=w.cached(this,A,$=>_n(m,$));return _n(m,[D,B])[0]}multiplyUnsafe(A,D=m.ZERO){if(!o.isValid(A))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return A===yo?m.ZERO:this.is0()||A===ht?this:w.unsafe(this,A,B=>_n(m,B),D)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return w.unsafe(this,i.n).is0()}toAffine(A){return h(this,A)}clearCofactor(){return s===ht?this:this.multiplyUnsafe(s)}toBytes(){let{x:A,y:D}=this.toAffine(),B=n.toBytes(D);return B[B.length-1]|=A&ht?128:0,B}toHex(){return pr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(A){return _n(m,A)}static msm(A,D){return Cs(m,o,A,D)}_setWindowSize(A){this.precompute(A)}toRawBytes(){return this.toBytes()}}m.BASE=new m(i.Gx,i.Gy,ht,c(i.Gx*i.Gy)),m.ZERO=new m(yo,ht,ht,yo),m.Fp=n,m.Fn=o;let w=new Es(m,o.BITS);return m.BASE.precompute(8),m}var Ff=class{constructor(e){this.ep=e}static fromBytes(e){fd()}static fromHex(e){fd()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return pr(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}toRawBytes(){return this.toBytes()}};function EE(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');Xr(t,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=t,{BASE:o,Fp:i,Fn:s}=r,a=t.randomBytes||ao,c=t.adjustScalarBytes||(I=>I),u=t.domain||((I,K,z)=>{if(xn(z,"phflag"),K.length||z)throw new Error("Contexts/pre-hash are not supported");return I});function p(I){return s.create(hr(I))}function l(I){let K=B.secretKey;I=Oe("private key",I,K);let z=Oe("hashed private key",e(I),2*K),V=c(z.slice(0,K)),x=z.slice(K,2*K),v=p(V);return{head:V,prefix:x,scalar:v}}function h(I){let{head:K,prefix:z,scalar:V}=l(I),x=o.multiply(V),v=x.toBytes();return{head:K,prefix:z,scalar:V,point:x,pointBytes:v}}function y(I){return h(I).pointBytes}function m(I=Uint8Array.of(),...K){let z=Lt(...K);return p(e(u(z,Oe("context",I),!!n)))}function w(I,K,z={}){I=Oe("message",I),n&&(I=n(I));let{prefix:V,scalar:x,pointBytes:v}=h(K),E=m(z.context,V,I),N=o.multiply(E).toBytes(),j=m(z.context,N,v,I),U=s.create(E+j*x);if(!s.isValid(U))throw new Error("sign failed: invalid s");let P=Lt(N,s.toBytes(U));return tr(P,B.signature,"result")}let g={zip215:!0};function A(I,K,z,V=g){let{context:x,zip215:v}=V,E=B.signature;I=Oe("signature",I,E),K=Oe("message",K),z=Oe("publicKey",z,B.publicKey),v!==void 0&&xn(v,"zip215"),n&&(K=n(K));let N=E/2,j=I.subarray(0,N),U=hr(I.subarray(N,E)),P,L,q;try{P=r.fromBytes(z,v),L=r.fromBytes(j,v),q=o.multiplyUnsafe(U)}catch{return!1}if(!v&&P.isSmallOrder())return!1;let R=m(x,L.toBytes(),P.toBytes(),K);return L.add(P.multiplyUnsafe(R)).subtract(q).clearCofactor().is0()}let D=i.BYTES,B={secretKey:D,publicKey:D,signature:2*D,seed:D};function $(I=a(B.seed)){return tr(I,B.seed,"seed")}function Q(I){let K=Y.randomSecretKey(I);return{secretKey:K,publicKey:y(K)}}function X(I){return bn(I)&&I.length===s.BYTES}function ne(I,K){try{return!!r.fromBytes(I,K)}catch{return!1}}let Y={getExtendedPublicKey:h,randomSecretKey:$,isValidSecretKey:X,isValidPublicKey:ne,toMontgomery(I){let{y:K}=r.fromBytes(I),z=B.publicKey,V=z===32;if(!V&&z!==57)throw new Error("only defined for 25519 and 448");let x=V?i.div(ht+K,ht-K):i.div(K-ht,K+ht);return i.toBytes(x)},toMontgomerySecret(I){let K=B.secretKey;tr(I,K);let z=e(I.subarray(0,K));return c(z).subarray(0,K)},randomPrivateKey:$,precompute(I=8,K=r.BASE){return K.precompute(I,!1)}};return Object.freeze({keygen:Q,getPublicKey:y,sign:w,verify:A,utils:Y,Point:r,lengths:B})}function CE(r){let e={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=rr(e.n,r.nBitLength,!0),o={Fp:t,Fn:n,uvRatio:r.uvRatio},i={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:e,curveOpts:o,hash:r.hash,eddsaOpts:i}}function TE(r,e){let t=e.Point;return Object.assign({},e,{ExtendedPoint:t,CURVE:r,nBitLength:t.Fn.BITS,nByteLength:t.Fn.BYTES})}function jb(r){let{CURVE:e,curveOpts:t,hash:n,eddsaOpts:o}=CE(r),i=AE(e,t),s=EE(i,n,o);return TE(r,s)}var oc=BigInt(0),Ts=BigInt(1),Wf=BigInt(2);function BE(r){return Xr(r,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r})}function Lb(r){let e=BE(r),{P:t,type:n,adjustScalarBytes:o,powPminus2:i,randomBytes:s}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=s||ao,u=a?255:448,p=a?32:56,l=BigInt(a?9:5),h=BigInt(a?121665:39081),y=a?Wf**BigInt(254):Wf**BigInt(447),m=a?BigInt(8)*Wf**BigInt(251)-Ts:BigInt(4)*Wf**BigInt(445)-Ts,w=y+m+Ts,g=x=>$e(x,t),A=D(l);function D(x){return tc(g(x),p)}function B(x){let v=Oe("u coordinate",x,p);return a&&(v[31]&=127),g(hr(v))}function $(x){return hr(o(Oe("scalar",x,p)))}function Q(x,v){let E=Y(B(v),$(x));if(E===oc)throw new Error("invalid private or public key received");return D(E)}function X(x){return Q(x,A)}function ne(x,v,E){let N=g(x*(v-E));return v=g(v-N),E=g(E+N),{x_2:v,x_3:E}}function Y(x,v){po("u",x,oc,t),po("scalar",v,y,w);let E=v,N=x,j=Ts,U=oc,P=x,L=Ts,q=oc;for(let he=BigInt(u-1);he>=oc;he--){let be=E>>he&Ts;q^=be,{x_2:j,x_3:P}=ne(q,j,P),{x_2:U,x_3:L}=ne(q,U,L),q=be;let te=j+U,Se=g(te*te),Te=j-U,Ue=g(Te*Te),Ee=Se-Ue,Re=P+L,hn=P-L,ur=g(hn*te),to=g(Re*Te),gf=ur+to,ls=ur-to;P=g(gf*gf),L=g(N*g(ls*ls)),j=g(Se*Ue),U=g(Ee*(Se+g(h*Ee)))}({x_2:j,x_3:P}=ne(q,j,P)),{x_2:U,x_3:L}=ne(q,U,L);let R=i(U);return g(j*R)}let I={secretKey:p,publicKey:p,seed:p},K=(x=c(p))=>(Tt(x,I.seed),x);function z(x){let v=K(x);return{secretKey:v,publicKey:X(v)}}return{keygen:z,getSharedSecret:(x,v)=>Q(x,v),getPublicKey:x=>X(x),scalarMult:Q,scalarMultBase:X,utils:{randomSecretKey:K,randomPrivateKey:K},GuBytes:A.slice(),lengths:I}}var IE=BigInt(0),An=BigInt(1),Ub=BigInt(2),OE=BigInt(3),PE=BigInt(5),NE=BigInt(8),Bs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ic={p:Bs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:NE,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Hb(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),i=Bs,a=r*r%i*r%i,c=Fe(a,Ub,i)*a%i,u=Fe(c,An,i)*r%i,p=Fe(u,PE,i)*u%i,l=Fe(p,e,i)*p%i,h=Fe(l,t,i)*l%i,y=Fe(h,n,i)*h%i,m=Fe(y,o,i)*y%i,w=Fe(m,o,i)*y%i,g=Fe(w,e,i)*p%i;return{pow_p_5_8:Fe(g,Ub,i)*r%i,b2:a}}function Vb(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var wd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function _d(r,e){let t=Bs,n=$e(e*e*e,t),o=$e(n*n*e,t),i=Hb(r*o).pow_p_5_8,s=$e(r*n*i,t),a=$e(e*s*s,t),c=s,u=$e(s*wd,t),p=a===r,l=a===$e(-r,t),h=a===$e(-r*wd,t);return p&&(s=c),(l||h)&&(s=u),vn(s,t)&&(s=$e(-s,t)),{isValid:p||l,value:s}}var Sn=rr(ic.p,{isLE:!0}),kE=rr(ic.n,{isLE:!0}),DE={...ic,Fp:Sn,hash:yb,adjustScalarBytes:Vb,uvRatio:_d},dr=jb(DE);var sc=(()=>{let r=Sn.ORDER;return Lb({P:r,type:"x25519",powPminus2:e=>{let{pow_p_5_8:t,b2:n}=Hb(e);return $e(Fe(t,OE,r)*n,r)},adjustScalarBytes:Vb})})();var xd=wd,RE=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jE=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),LE=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),UE=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Mb=r=>_d(An,r),ME=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),vd=r=>dr.Point.Fp.create(hr(r)&ME);function Kb(r){let{d:e}=ic,t=Bs,n=A=>Sn.create(A),o=n(xd*r*r),i=n((o+An)*LE),s=BigInt(-1),a=n((s-e*o)*n(o+e)),{isValid:c,value:u}=_d(i,a),p=n(u*r);vn(p,t)||(p=n(-p)),c||(u=p),c||(s=o);let l=n(s*(o-An)*UE-a),h=u*u,y=n((u+u)*a),m=n(l*RE),w=n(An-h),g=n(An+h);return new dr.Point(n(y*g),n(w*m),n(m*g),n(y*w))}function KE(r){Tt(r,64);let e=vd(r.subarray(0,32)),t=Kb(e),n=vd(r.subarray(32,64)),o=Kb(n);return new En(t.add(o))}var En=class r extends Ff{constructor(e){super(e)}static fromAffine(e){return new r(dr.Point.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static hashToCurve(e){return KE(Oe("ristrettoHash",e,64))}static fromBytes(e){Tt(e,32);let{a:t,d:n}=ic,o=Bs,i=$=>Sn.create($),s=vd(e);if(!gb(Sn.toBytes(s),e)||vn(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(An+t*a),u=i(An-t*a),p=i(c*c),l=i(u*u),h=i(t*n*p-l),{isValid:y,value:m}=Mb(i(h*l)),w=i(m*u),g=i(m*w*h),A=i((s+s)*w);vn(A,o)&&(A=i(-A));let D=i(c*g),B=i(A*D);if(!y||vn(B,o)||D===IE)throw new Error("invalid ristretto255 encoding 2");return new r(new dr.Point(A,D,An,B))}static fromHex(e){return r.fromBytes(Oe("ristrettoHex",e,32))}static msm(e,t){return Cs(r,dr.Point.Fn,e,t)}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,i=Bs,s=g=>Sn.create(g),a=s(s(n+t)*s(n-t)),c=s(e*t),u=s(c*c),{value:p}=Mb(s(a*u)),l=s(p*a),h=s(p*c),y=s(l*h*o),m;if(vn(o*y,i)){let g=s(t*xd),A=s(e*xd);e=g,t=A,m=s(l*jE)}else m=h;vn(e*y,i)&&(t=s(-t));let w=s((n-t)*m);return vn(w,i)&&(w=s(-w)),Sn.toBytes(w)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:i}=e.ep,s=u=>Sn.create(u),a=s(t*i)===s(n*o),c=s(n*i)===s(t*o);return a||c}is0(){return this.equals(r.ZERO)}};En.BASE=new En(dr.Point.BASE);En.ZERO=new En(dr.Point.ZERO);En.Fp=Sn;En.Fn=kE;var ac=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},cc=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},qf=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var $b={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new qf("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 Ft=$b;var Gf=32,uc=64,Sd=32;var Is,Fb=(async()=>{try{return await Ft.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Wb(){let r=dr.utils.randomPrivateKey(),e=dr.getPublicKey(r);return{privateKey:WE(r,e),publicKey:e}}async function HE(r,e){let t;r.length===uc?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:le(r.subarray(32),"base64url"),d:le(t,"base64url"),ext:!0,key_ops:["sign"]},o=await Ft.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),i=await Ft.get().subtle.sign({name:"Ed25519"},o,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(i,0,i.byteLength)}function VE(r,e){let t=r.subarray(0,Sd);return dr.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function qb(r,e){return Is==null&&(Is=await Fb),Is?HE(r,e):VE(r,e)}async function $E(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await Ft.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ft.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 FE(r,e,t){return dr.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Gb(r,e,t){return Is==null&&(Is=await Fb),Is?$E(r,e,t):FE(r,e,t)}function WE(r,e){let t=new Uint8Array(uc);for(let n=0;n<Sd;n++)t[n]=r[n],t[Sd+n]=e[n];return t}function Os(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var fc=class{type="Ed25519";raw;constructor(e){this.raw=Xf(e,Gf)}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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=Gb(this.raw,t,e);return Os(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}},zf=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Xf(e,uc),this.publicKey=new fc(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=qb(this.raw,e);return Os(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function Ad(r){return r=Xf(r,Gf),new fc(r)}async function Xb(){let{privateKey:r,publicKey:e}=Wb();return new zf(r,e)}function Xf(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new ve(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var qE=Math.pow(2,7),GE=Math.pow(2,14),zE=Math.pow(2,21),Ed=Math.pow(2,28),Cd=Math.pow(2,35),Td=Math.pow(2,42),Bd=Math.pow(2,49),ke=128,Bt=127;function We(r){if(r<qE)return 1;if(r<GE)return 2;if(r<zE)return 3;if(r<Ed)return 4;if(r<Cd)return 5;if(r<Td)return 6;if(r<Bd)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ps(r,e,t=0){switch(We(r)){case 8:e[t++]=r&255|ke,r/=128;case 7:e[t++]=r&255|ke,r/=128;case 6:e[t++]=r&255|ke,r/=128;case 5:e[t++]=r&255|ke,r/=128;case 4:e[t++]=r&255|ke,r>>>=7;case 3:e[t++]=r&255|ke,r>>>=7;case 2:e[t++]=r&255|ke,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function XE(r,e,t=0){switch(We(r)){case 8:e.set(t++,r&255|ke),r/=128;case 7:e.set(t++,r&255|ke),r/=128;case 6:e.set(t++,r&255|ke),r/=128;case 5:e.set(t++,r&255|ke),r/=128;case 4:e.set(t++,r&255|ke),r>>>=7;case 3:e.set(t++,r&255|ke),r>>>=7;case 2:e.set(t++,r&255|ke),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Id(r,e){let t=r[e],n=0;if(n+=t&Bt,t<ke||(t=r[e+1],n+=(t&Bt)<<7,t<ke)||(t=r[e+2],n+=(t&Bt)<<14,t<ke)||(t=r[e+3],n+=(t&Bt)<<21,t<ke)||(t=r[e+4],n+=(t&Bt)*Ed,t<ke)||(t=r[e+5],n+=(t&Bt)*Cd,t<ke)||(t=r[e+6],n+=(t&Bt)*Td,t<ke)||(t=r[e+7],n+=(t&Bt)*Bd,t<ke))return n;throw new RangeError("Could not decode varint")}function ZE(r,e){let t=r.get(e),n=0;if(n+=t&Bt,t<ke||(t=r.get(e+1),n+=(t&Bt)<<7,t<ke)||(t=r.get(e+2),n+=(t&Bt)<<14,t<ke)||(t=r.get(e+3),n+=(t&Bt)<<21,t<ke)||(t=r.get(e+4),n+=(t&Bt)*Ed,t<ke)||(t=r.get(e+5),n+=(t&Bt)*Cd,t<ke)||(t=r.get(e+6),n+=(t&Bt)*Td,t<ke)||(t=r.get(e+7),n+=(t&Bt)*Bd,t<ke))return n;throw new RangeError("Could not decode varint")}function Zf(r,e,t=0){return e==null&&(e=ft(We(r))),e instanceof Uint8Array?Ps(r,e,t):XE(r,e,t)}function Cn(r,e=0){return r instanceof Uint8Array?Id(r,e):ZE(r,e)}var Od=new Float32Array([-0]),mo=new Uint8Array(Od.buffer);function Zb(r,e,t){Od[0]=r,e[t]=mo[0],e[t+1]=mo[1],e[t+2]=mo[2],e[t+3]=mo[3]}function Yb(r,e){return mo[0]=r[e],mo[1]=r[e+1],mo[2]=r[e+2],mo[3]=r[e+3],Od[0]}var Pd=new Float64Array([-0]),It=new Uint8Array(Pd.buffer);function Jb(r,e,t){Pd[0]=r,e[t]=It[0],e[t+1]=It[1],e[t+2]=It[2],e[t+3]=It[3],e[t+4]=It[4],e[t+5]=It[5],e[t+6]=It[6],e[t+7]=It[7]}function Qb(r,e){return It[0]=r[e],It[1]=r[e+1],It[2]=r[e+2],It[3]=r[e+3],It[4]=r[e+4],It[5]=r[e+5],It[6]=r[e+6],It[7]=r[e+7],Pd[0]}var YE=BigInt(Number.MAX_SAFE_INTEGER),JE=BigInt(Number.MIN_SAFE_INTEGER),nr=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 si;if(e<YE&&e>JE)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>ew&&(o=0n,++n>ew&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return si;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):si}},si=new nr(0,0);si.toBigInt=function(){return 0n};si.zzEncode=si.zzDecode=function(){return this};si.length=function(){return 1};var ew=4294967296n;function tw(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 rw(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 Nd(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 Pr(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Yf(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var kd=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,Pr(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 Pr(this,4);return Yf(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pr(this,4);return Yf(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pr(this,4);let e=Yb(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Pr(this,4);let e=Qb(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 Pr(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return rw(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Pr(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Pr(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 nr(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 Pr(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 Pr(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 Pr(this,8);let e=Yf(this.buf,this.pos+=4),t=Yf(this.buf,this.pos+=4);return new nr(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=Id(this.buf,this.pos);return this.pos+=We(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 Dd(r){return new kd(r instanceof Uint8Array?r:r.subarray())}function Nr(r,e,t){let n=Dd(r);return e.decode(n,void 0,t)}function Rd(r){let e=r??8192,t=e>>>1,n,o=e;return function(s){if(s<1||s>t)return ft(s);o+s>e&&(n=ft(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ai=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function jd(){}var Ud=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},QE=Rd();function e2(r){return globalThis.Buffer!=null?ft(r):QE(r)}var hc=class{len;head;tail;states;constructor(){this.len=0,this.head=new ai(jd,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ai(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Md((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(Jf,10,nr.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=nr.fromBigInt(e);return this._push(Jf,t.length(),t)}uint64Number(e){return this._push(Ps,We(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=nr.fromBigInt(e).zzEncode();return this._push(Jf,t.length(),t)}sint64Number(e){let t=nr.fromNumber(e).zzEncode();return this._push(Jf,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ld,1,e?1:0)}fixed32(e){return this._push(pc,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=nr.fromBigInt(e);return this._push(pc,4,t.lo)._push(pc,4,t.hi)}fixed64Number(e){let t=nr.fromNumber(e);return this._push(pc,4,t.lo)._push(pc,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(Zb,4,e)}double(e){return this._push(Jb,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ld,1,0):this.uint32(t)._push(r2,t,e)}string(e){let t=tw(e);return t!==0?this.uint32(t)._push(Nd,t,e):this._push(Ld,1,0)}fork(){return this.states=new Ud(this),this.head=this.tail=new ai(jd,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 ai(jd,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=e2(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ld(r,e,t){e[t]=r&255}function t2(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Md=class extends ai{next;constructor(e,t){super(t2,e,t),this.next=void 0}};function Jf(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 pc(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 r2(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(hc.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(n2,e,r),this},hc.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(o2,e,r),this});function n2(r,e,t){e.set(r,t)}function o2(r,e,t){r.length<40?Nd(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(ye(r),t)}function Kd(){return new hc}function kr(r,e){let t=Kd();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var Ns;(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"})(Ns||(Ns={}));function Qf(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function ci(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 Qf("enum",Ns.VARINT,t,n)}function Dr(r,e){return Qf("message",Ns.LENGTH_DELIMITED,r,e)}var dc=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var nt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(nt||(nt={}));var Hd;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Hd||(Hd={}));(function(r){r.codec=()=>ci(Hd)})(nt||(nt={}));var Zr;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),nt.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=nt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(Zr||(Zr={}));var Vd;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((t,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),nt.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=nt.codec().decode(t);break}case 2:{i.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(Vd||(Vd={}));var mc={};Ct(mc,{MAX_RSA_KEY_SIZE:()=>$d,generateRSAKeyPair:()=>Jd,jwkToJWKKeyPair:()=>cw,jwkToPkcs1:()=>c2,jwkToPkix:()=>Gd,jwkToRSAPrivateKey:()=>Yd,pkcs1MessageToJwk:()=>Wd,pkcs1MessageToRSAPrivateKey:()=>zd,pkcs1ToJwk:()=>a2,pkcs1ToRSAPrivateKey:()=>aw,pkixMessageToJwk:()=>qd,pkixMessageToRSAPublicKey:()=>Zd,pkixToJwk:()=>u2,pkixToRSAPublicKey:()=>Xd});var el=lo;var ks=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=mc.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return Ze.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 sw(this.jwk,t,e,n)}},yc=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=mc.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return iw(this.jwk,e,t)}};var $d=8192,Fd=18,i2=1062,s2=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function a2(r){let e=mn(r);return Wd(e)}function Wd(r){return{n:le(r[1],"base64url"),e:le(r[2],"base64url"),d:le(r[3],"base64url"),p:le(r[4],"base64url"),q:le(r[5],"base64url"),dp:le(r[6],"base64url"),dq:le(r[7],"base64url"),qi:le(r[8],"base64url"),kty:"RSA"}}function c2(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");return Br([jt(Uint8Array.from([0])),jt(ye(r.n,"base64url")),jt(ye(r.e,"base64url")),jt(ye(r.d,"base64url")),jt(ye(r.p,"base64url")),jt(ye(r.q,"base64url")),jt(ye(r.dp,"base64url")),jt(ye(r.dq,"base64url")),jt(ye(r.qi,"base64url"))]).subarray()}function u2(r){let e=mn(r,{offset:0});return qd(e)}function qd(r){let e=mn(r[1],{offset:0});return{kty:"RSA",n:le(e[0],"base64url"),e:le(e[1],"base64url")}}function Gd(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");return Br([s2,Za(Br([jt(ye(r.n,"base64url")),jt(ye(r.e,"base64url"))]))]).subarray()}function aw(r){let e=mn(r);return zd(e)}function zd(r){let e=Wd(r);return Yd(e)}function Xd(r,e){if(r.byteLength>=i2)throw new ps("Key size is too large");let t=mn(r,{offset:0});return Zd(t,r,e)}function Zd(r,e,t){let n=qd(r);if(t==null){let o=el(Zr.encode({Type:nt.RSA,Data:e}));t=Dt(Fd,o)}return new ks(n,t)}function Yd(r){if(fw(r)>$d)throw new ve("Key size is too large");let e=cw(r),t=el(Zr.encode({Type:nt.RSA,Data:Gd(e.publicKey)})),n=Dt(Fd,t);return new yc(e.privateKey,new ks(e.publicKey,n))}async function Jd(r){if(r>$d)throw new ve("Key size is too large");let e=await uw(r),t=el(Zr.encode({Type:nt.RSA,Data:Gd(e.publicKey)})),n=Dt(Fd,t);return new yc(e.privateKey,new ks(e.publicKey,n))}function cw(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function uw(r,e){let t=await Ft.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 f2(t,e);return{privateKey:n[0],publicKey:n[1]}}async function iw(r,e,t){let n=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await Ft.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 sw(r,e,t,n){let o=await Ft.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ft.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,t instanceof Uint8Array?t:t.subarray());return n?.signal?.throwIfAborted(),i}async function f2(r,e){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");let t=await Promise.all([Ft.get().subtle.exportKey("jwk",r.privateKey),Ft.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function fw(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return ye(r.n,"base64url").length*8}var tl=class extends xs{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ei(e);let n=so(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),Ir(i)}update(e){return vs(this),this.iHash.update(e),this}digestInto(e){vs(this),Tt(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 tl(r,e).update(t).digest();Ds.create=(r,e)=>new tl(r,e);var lw=(r,e)=>(r+(r>=0?e:-e)/pw)/e;function l2(r,e,t){let[[n,o],[i,s]]=e,a=lw(s*r,t),c=lw(-o*r,t),u=r-a*n-c*i,p=-a*o-c*s,l=u<Bn,h=p<Bn;l&&(u=-u),h&&(p=-p);let y=ho(Math.ceil(Hf(t)/2))+js;if(u<Bn||u>=y||p<Bn||p>=y)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:h,k2:p}}function ey(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Qd(r,e){let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return xn(t.lowS,"lowS"),xn(t.prehash,"prehash"),t.format!==void 0&&ey(t.format),t}var ty=class extends Error{constructor(e=""){super(e)}},Tn={Err:ty,_tlv:{encode:(r,e)=>{let{Err:t}=Tn;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=ec(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?ec(o.length/2|128):"";return ec(r)+i+o+e},decode(r,e){let{Err:t}=Tn,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 u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let p of u)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}=Tn;if(r<Bn)throw new e("integer: negative integers are not allowed");let t=ec(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}=Tn;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 _s(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=Tn,o=Oe("signature",r),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,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(u)}},hexFromSig(r){let{_tlv:e,_int:t}=Tn,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),i=n+o;return e.encode(48,i)}},Bn=BigInt(0),js=BigInt(1),pw=BigInt(2),rl=BigInt(3),p2=BigInt(4);function Rs(r,e){let{BYTES:t}=r,n;if(typeof e=="bigint")n=e;else{let o=Oe("private key",e);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function h2(r,e={}){let t=$f("weierstrass",r,e),{Fp:n,Fn:o}=t,i=t.CURVE,{h:s,n:a}=i;Xr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=dw(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(V,x,v){let{x:E,y:N}=x.toAffine(),j=n.toBytes(E);if(xn(v,"isCompressed"),v){p();let U=!n.isOdd(N);return Lt(hw(U),j)}else return Lt(Uint8Array.of(4),j,n.toBytes(N))}function h(V){tr(V,void 0,"Point");let{publicKey:x,publicKeyUncompressed:v}=u,E=V.length,N=V[0],j=V.subarray(1);if(E===x&&(N===2||N===3)){let U=n.fromBytes(j);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let P=w(U),L;try{L=n.sqrt(P)}catch(he){let be=he instanceof Error?": "+he.message:"";throw new Error("bad point: is not on curve, sqrt error"+be)}p();let q=n.isOdd(L);return(N&1)===1!==q&&(L=n.neg(L)),{x:U,y:L}}else if(E===v&&N===4){let U=n.BYTES,P=n.fromBytes(j.subarray(0,U)),L=n.fromBytes(j.subarray(U,U*2));if(!g(P,L))throw new Error("bad point: is not on curve");return{x:P,y:L}}else throw new Error(`bad point: got length ${E}, expected compressed=${x} or uncompressed=${v}`)}let y=e.toBytes||l,m=e.fromBytes||h;function w(V){let x=n.sqr(V),v=n.mul(x,V);return n.add(n.add(v,n.mul(V,i.a)),i.b)}function g(V,x){let v=n.sqr(x),E=w(V);return n.eql(v,E)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,rl),p2),D=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,D)))throw new Error("bad curve params: a or b");function B(V,x,v=!1){if(!n.isValid(x)||v&&n.is0(x))throw new Error(`bad point coordinate ${V}`);return x}function $(V){if(!(V instanceof I))throw new Error("ProjectivePoint expected")}function Q(V){if(!c||!c.basises)throw new Error("no endo");return l2(V,c.basises,o.ORDER)}let X=Ss((V,x)=>{let{X:v,Y:E,Z:N}=V;if(n.eql(N,n.ONE))return{x:v,y:E};let j=V.is0();x==null&&(x=j?n.ONE:n.inv(N));let U=n.mul(v,x),P=n.mul(E,x),L=n.mul(N,x);if(j)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:U,y:P}}),ne=Ss(V=>{if(V.is0()){if(e.allowInfinityPoint&&!n.is0(V.Y))return;throw new Error("bad point: ZERO")}let{x,y:v}=V.toAffine();if(!n.isValid(x)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!g(x,v))throw new Error("bad point: equation left != right");if(!V.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Y(V,x,v,E,N){return v=new I(n.mul(v.X,V),v.Y,v.Z),x=nc(E,x),v=nc(N,v),x.add(v)}class I{constructor(x,v,E){this.X=B("x",x),this.Y=B("y",v,!0),this.Z=B("z",E),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){let{x:v,y:E}=x||{};if(!x||!n.isValid(v)||!n.isValid(E))throw new Error("invalid affine point");if(x instanceof I)throw new Error("projective point not allowed");return n.is0(v)&&n.is0(E)?I.ZERO:new I(v,E,n.ONE)}static fromBytes(x){let v=I.fromAffine(m(tr(x,void 0,"point")));return v.assertValidity(),v}static fromHex(x){return I.fromBytes(Oe("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,v=!0){return z.createCache(this,x),v||this.multiply(rl),this}assertValidity(){ne(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){$(x);let{X:v,Y:E,Z:N}=this,{X:j,Y:U,Z:P}=x,L=n.eql(n.mul(v,P),n.mul(j,N)),q=n.eql(n.mul(E,P),n.mul(U,N));return L&&q}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:v}=i,E=n.mul(v,rl),{X:N,Y:j,Z:U}=this,P=n.ZERO,L=n.ZERO,q=n.ZERO,R=n.mul(N,N),he=n.mul(j,j),be=n.mul(U,U),te=n.mul(N,j);return te=n.add(te,te),q=n.mul(N,U),q=n.add(q,q),P=n.mul(x,q),L=n.mul(E,be),L=n.add(P,L),P=n.sub(he,L),L=n.add(he,L),L=n.mul(P,L),P=n.mul(te,P),q=n.mul(E,q),be=n.mul(x,be),te=n.sub(R,be),te=n.mul(x,te),te=n.add(te,q),q=n.add(R,R),R=n.add(q,R),R=n.add(R,be),R=n.mul(R,te),L=n.add(L,R),be=n.mul(j,U),be=n.add(be,be),R=n.mul(be,te),P=n.sub(P,R),q=n.mul(be,he),q=n.add(q,q),q=n.add(q,q),new I(P,L,q)}add(x){$(x);let{X:v,Y:E,Z:N}=this,{X:j,Y:U,Z:P}=x,L=n.ZERO,q=n.ZERO,R=n.ZERO,he=i.a,be=n.mul(i.b,rl),te=n.mul(v,j),Se=n.mul(E,U),Te=n.mul(N,P),Ue=n.add(v,E),Ee=n.add(j,U);Ue=n.mul(Ue,Ee),Ee=n.add(te,Se),Ue=n.sub(Ue,Ee),Ee=n.add(v,N);let Re=n.add(j,P);return Ee=n.mul(Ee,Re),Re=n.add(te,Te),Ee=n.sub(Ee,Re),Re=n.add(E,N),L=n.add(U,P),Re=n.mul(Re,L),L=n.add(Se,Te),Re=n.sub(Re,L),R=n.mul(he,Ee),L=n.mul(be,Te),R=n.add(L,R),L=n.sub(Se,R),R=n.add(Se,R),q=n.mul(L,R),Se=n.add(te,te),Se=n.add(Se,te),Te=n.mul(he,Te),Ee=n.mul(be,Ee),Se=n.add(Se,Te),Te=n.sub(te,Te),Te=n.mul(he,Te),Ee=n.add(Ee,Te),te=n.mul(Se,Ee),q=n.add(q,te),te=n.mul(Re,Ee),L=n.mul(Ue,L),L=n.sub(L,te),te=n.mul(Ue,Se),R=n.mul(Re,R),R=n.add(R,te),new I(L,q,R)}subtract(x){return this.add(x.negate())}is0(){return this.equals(I.ZERO)}multiply(x){let{endo:v}=e;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let E,N,j=U=>z.cached(this,U,P=>_n(I,P));if(v){let{k1neg:U,k1:P,k2neg:L,k2:q}=Q(x),{p:R,f:he}=j(P),{p:be,f:te}=j(q);N=he.add(te),E=Y(v.beta,R,be,U,L)}else{let{p:U,f:P}=j(x);E=U,N=P}return _n(I,[E,N])[0]}multiplyUnsafe(x){let{endo:v}=e,E=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===Bn||E.is0())return I.ZERO;if(x===js)return E;if(z.hasCache(this))return this.multiply(x);if(v){let{k1neg:N,k1:j,k2neg:U,k2:P}=Q(x),{p1:L,p2:q}=Rb(I,E,j,P);return Y(v.beta,L,q,N,U)}else return z.unsafe(E,x)}multiplyAndAddUnsafe(x,v,E){let N=this.multiplyUnsafe(v).add(x.multiplyUnsafe(E));return N.is0()?void 0:N}toAffine(x){return X(this,x)}isTorsionFree(){let{isTorsionFree:x}=e;return s===js?!0:x?x(I,this):z.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:x}=e;return s===js?this:x?x(I,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(x=!0){return xn(x,"isCompressed"),this.assertValidity(),y(I,this,x)}toHex(x=!0){return pr(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return _n(I,x)}static msm(x,v){return Cs(I,o,x,v)}static fromPrivateKey(x){return I.BASE.multiply(Rs(o,x))}}I.BASE=new I(i.Gx,i.Gy,n.ONE),I.ZERO=new I(n.ZERO,n.ONE,n.ZERO),I.Fp=n,I.Fn=o;let K=o.BITS,z=new Es(I,e.endo?Math.ceil(K/2):K);return I.BASE.precompute(8),I}function hw(r){return Uint8Array.of(r?2:3)}function dw(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function d2(r,e={}){let{Fn:t}=r,n=e.randomBytes||ao,o=Object.assign(dw(r.Fp,t),{seed:hd(t.ORDER)});function i(y){try{return!!Rs(t,y)}catch{return!1}}function s(y,m){let{publicKey:w,publicKeyUncompressed:g}=o;try{let A=y.length;return m===!0&&A!==w||m===!1&&A!==g?!1:!!r.fromBytes(y)}catch{return!1}}function a(y=n(o.seed)){return dd(tr(y,o.seed,"seed"),t.ORDER)}function c(y,m=!0){return r.BASE.multiply(Rs(t,y)).toBytes(m)}function u(y){let m=a(y);return{secretKey:m,publicKey:c(m)}}function p(y){if(typeof y=="bigint")return!1;if(y instanceof r)return!0;let{secretKey:m,publicKey:w,publicKeyUncompressed:g}=o;if(t.allowedLengths||m===w)return;let A=Oe("key",y).length;return A===w||A===g}function l(y,m,w=!0){if(p(y)===!0)throw new Error("first arg must be private key");if(p(m)===!1)throw new Error("second arg must be public key");let g=Rs(t,y);return r.fromHex(m).multiply(g).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:r,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:y=>Rs(t,y),precompute(y=8,m=r.BASE){return m.precompute(y,!1)}},lengths:o})}function y2(r,e,t={}){ei(e),Xr(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||ao,o=t.hmac||((v,...E)=>Ds(e,v,Lt(...E))),{Fp:i,Fn:s}=r,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:p,getSharedSecret:l,utils:h,lengths:y}=d2(r,t),m={prehash:!1,lowS:typeof t.lowS=="boolean"?t.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function g(v){let E=a>>js;return v>E}function A(v,E){if(!s.isValidNot0(E))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return E}function D(v,E){ey(E);let N=y.signature,j=E==="compact"?N:E==="recovered"?N+1:void 0;return tr(v,j,`${E} signature`)}class B{constructor(E,N,j){this.r=A("r",E),this.s=A("s",N),j!=null&&(this.recovery=j),Object.freeze(this)}static fromBytes(E,N=w){D(E,N);let j;if(N==="der"){let{r:q,s:R}=Tn.toSig(tr(E));return new B(q,R)}N==="recovered"&&(j=E[0],N="compact",E=E.subarray(1));let U=s.BYTES,P=E.subarray(0,U),L=E.subarray(U,U*2);return new B(s.fromBytes(P),s.fromBytes(L),j)}static fromHex(E,N){return this.fromBytes(ti(E),N)}addRecoveryBit(E){return new B(this.r,this.s,E)}recoverPublicKey(E){let N=i.ORDER,{r:j,s:U,recovery:P}=this;if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");if(a*pw<N&&P>1)throw new Error("recovery id is ambiguous for h>1 curve");let q=P===2||P===3?j+a:j;if(!i.isValid(q))throw new Error("recovery id 2 or 3 invalid");let R=i.toBytes(q),he=r.fromBytes(Lt(hw((P&1)===0),R)),be=s.inv(q),te=Q(Oe("msgHash",E)),Se=s.create(-te*be),Te=s.create(U*be),Ue=r.BASE.multiplyUnsafe(Se).add(he.multiplyUnsafe(Te));if(Ue.is0())throw new Error("point at infinify");return Ue.assertValidity(),Ue}hasHighS(){return g(this.s)}toBytes(E=w){if(ey(E),E==="der")return ti(Tn.hexFromSig(this));let N=s.toBytes(this.r),j=s.toBytes(this.s);if(E==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Lt(Uint8Array.of(this.recovery),N,j)}return Lt(N,j)}toHex(E){return pr(this.toBytes(E))}assertValidity(){}static fromCompact(E){return B.fromBytes(Oe("sig",E),"compact")}static fromDER(E){return B.fromBytes(Oe("sig",E),"der")}normalizeS(){return this.hasHighS()?new B(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return pr(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return pr(this.toBytes("compact"))}}let $=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=_s(E),j=E.length*8-c;return j>0?N>>BigInt(j):N},Q=t.bits2int_modN||function(E){return s.create($(E))},X=ho(c);function ne(v){return po("num < 2^"+c,v,Bn,X),s.toBytes(v)}function Y(v,E){return tr(v,void 0,"message"),E?tr(e(v),void 0,"prehashed message"):v}function I(v,E,N){if(["recovered","canonical"].some(Se=>Se in N))throw new Error("sign() legacy options not supported");let{lowS:j,prehash:U,extraEntropy:P}=Qd(N,m);v=Y(v,U);let L=Q(v),q=Rs(s,E),R=[ne(q),ne(L)];if(P!=null&&P!==!1){let Se=P===!0?n(y.secretKey):P;R.push(Oe("extraEntropy",Se))}let he=Lt(...R),be=L;function te(Se){let Te=$(Se);if(!s.isValidNot0(Te))return;let Ue=s.inv(Te),Ee=r.BASE.multiply(Te).toAffine(),Re=s.create(Ee.x);if(Re===Bn)return;let hn=s.create(Ue*s.create(be+Re*q));if(hn===Bn)return;let ur=(Ee.x===Re?0:2)|Number(Ee.y&js),to=hn;return j&&g(hn)&&(to=s.neg(hn),ur^=1),new B(Re,to,ur)}return{seed:he,k2sig:te}}function K(v,E,N={}){v=Oe("message",v);let{seed:j,k2sig:U}=I(v,E,N);return wb(e.outputLen,s.BYTES,o)(j,U)}function z(v){let E,N=typeof v=="string"||bn(v),j=!N&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!N&&!j)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(j)E=new B(v.r,v.s);else if(N){try{E=B.fromBytes(Oe("sig",v),"der")}catch(U){if(!(U instanceof Tn.Err))throw U}if(!E)try{E=B.fromBytes(Oe("sig",v),"compact")}catch{return!1}}return E||!1}function V(v,E,N,j={}){let{lowS:U,prehash:P,format:L}=Qd(j,m);if(N=Oe("publicKey",N),E=Y(Oe("message",E),P),"strict"in j)throw new Error("options.strict was renamed to lowS");let q=L===void 0?z(v):B.fromBytes(Oe("sig",v),L);if(q===!1)return!1;try{let R=r.fromBytes(N);if(U&&q.hasHighS())return!1;let{r:he,s:be}=q,te=Q(E),Se=s.inv(be),Te=s.create(te*Se),Ue=s.create(he*Se),Ee=r.BASE.multiplyUnsafe(Te).add(R.multiplyUnsafe(Ue));return Ee.is0()?!1:s.create(Ee.x)===he}catch{return!1}}function x(v,E,N={}){let{prehash:j}=Qd(N,m);return E=Y(E,j),B.fromBytes(v,"recovered").recoverPublicKey(E).toBytes()}return Object.freeze({keygen:u,getPublicKey:p,getSharedSecret:l,utils:h,lengths:y,Point:r,sign:K,verify:V,recoverPublicKey:x,Signature:B,hash:e})}function m2(r){let e={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},t=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=rr(e.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes:r.wrapPrivateKey}),i={Fp:t,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:e,curveOpts:i}}function g2(r){let{CURVE:e,curveOpts:t}=m2(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:e,curveOpts:t,hash:r.hash,ecdsaOpts:n}}function b2(r,e){let t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},r,Vf(t.Fn.ORDER,t.Fn.BITS))})}function yw(r){let{CURVE:e,curveOpts:t,hash:n,ecdsaOpts:o}=g2(r),i=h2(e,t),s=y2(i,n,o);return b2(r,s)}function mw(r,e){let t=n=>yw({...r,hash:n});return{...t(e),create:t}}var ny={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},w2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gw=BigInt(2);function x2(r){let e=ny.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,p=u*u*r%e,l=Fe(p,t,e)*p%e,h=Fe(l,t,e)*p%e,y=Fe(h,gw,e)*u%e,m=Fe(y,o,e)*y%e,w=Fe(m,i,e)*m%e,g=Fe(w,a,e)*w%e,A=Fe(g,c,e)*g%e,D=Fe(A,a,e)*w%e,B=Fe(D,t,e)*p%e,$=Fe(B,s,e)*m%e,Q=Fe($,n,e)*u%e,X=Fe(Q,gw,e);if(!ry.eql(ry.sqr(X),r))throw new Error("Cannot find square root");return X}var ry=rr(ny.p,{sqrt:x2}),Rr=mw({...ny,Fp:ry,lowS:!0,endo:w2},lo);function bw(r,e,t){let n=lr.digest(e instanceof Uint8Array?e:e.subarray());if(Os(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),Rr.sign(o,r).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new ac(String(o))});try{return Rr.sign(n.digest,r).toDERRawBytes()}catch(o){throw new ac(String(o))}}function ww(r,e,t,n){let o=lr.digest(t instanceof Uint8Array?t:t.subarray());if(Os(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),Rr.verify(e,i,r))).catch(i=>{throw i.name==="AbortError"?i:new cc(String(i))});try{return n?.signal?.throwIfAborted(),Rr.verify(e,o.digest,r)}catch(i){throw new cc(String(i))}}var gc=class{type="secp256k1";raw;_key;constructor(e){this._key=_w(e),this.raw=xw(this._key)}toMultihash(){return Tr.digest(io(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return Ze.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 ww(this._key,t,e,n)}},nl=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=vw(e),this.publicKey=new gc(t??Sw(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ye(this.raw,e.raw)}sign(e,t){return bw(this.raw,e,t)}};function oy(r){return new gc(r)}async function Aw(){let r=v2();return new nl(r)}function xw(r){return Rr.ProjectivePoint.fromHex(r).toRawBytes(!0)}function vw(r){try{return Rr.getPublicKey(r,!0),r}catch(e){throw new Va(String(e))}}function _w(r){try{return Rr.ProjectivePoint.fromHex(r),r}catch(e){throw new ps(String(e))}}function Sw(r){try{return Rr.getPublicKey(r,!0)}catch(e){throw new Va(String(e))}}function v2(){return Rr.utils.randomPrivateKey()}async function Ew(r,e){if(r==="Ed25519")return Xb();if(r==="secp256k1")return Aw();if(r==="RSA")return Jd(_2(e));if(r==="ECDSA")return eb(S2(e));throw new ro}function bc(r,e){let{Type:t,Data:n}=Zr.decode(r),o=n??new Uint8Array;switch(t){case nt.RSA:return Xd(o,e);case nt.Ed25519:return Ad(o);case nt.secp256k1:return oy(o);case nt.ECDSA:return ed(o);default:throw new ro}}function Cw(r){let{Type:e,Data:t}=Zr.decode(r.digest),n=t??new Uint8Array;switch(e){case nt.Ed25519:return Ad(n);case nt.secp256k1:return oy(n);case nt.ECDSA:return ed(n);default:throw new ro}}function io(r){return Zr.encode({Type:nt[r.type],Data:r.raw})}function _2(r){return r==null?2048:parseInt(r,10)}function S2(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new ve("Unsupported curve, should be P-256, P-384 or P-521")}async function ol(r){if(r.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(r.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",r.jwk,{name:"ECDSA",namedCurve:r.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",r.publicKey.jwk,{name:"ECDSA",namedCurve:r.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new ve("Only RSA and ECDSA keys are supported")}var Tw=Symbol.for("nodejs.util.inspect.custom"),A2=114,wc=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()})`}[Th]=!0;toString(){return this.string==null&&(this.string=Ze.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(A2,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")}[Tw](){return`PeerId(${this.toString()})`}},xc=class extends wc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},vc=class extends wc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},_c=class extends wc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},E2=2336,Sc=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Tr.digest(ye(this.url))}[Tw](){return`PeerId(${this.url})`}[Th]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(E2,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=le(e)),e.toString()===this.toString())}};var C2=114,Bw=2336;function Ls(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=ws(Ze.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return T2(ct.parse(r));if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=ws(e.decode(r))}return Iw(t)}function iy(r){if(r.type==="Ed25519")return new vc({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new _c({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new xc({multihash:r.toCID().multihash,publicKey:r});throw new ro}function Iw(r){if(I2(r))return new xc({multihash:r});if(B2(r))try{let e=Cw(r);if(e.type==="Ed25519")return new vc({multihash:r,publicKey:e});if(e.type==="secp256k1")return new _c({multihash:r,publicKey:e})}catch{let t=le(r.digest);return new Sc(new URL(t))}throw new Ef("Supplied PeerID Multihash is invalid")}function T2(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==C2&&r.code!==Bw)throw new Af("Supplied PeerID CID is invalid");if(r.code===Bw){let e=le(r.multihash.digest);return new Sc(new URL(e))}return Iw(r.multihash)}function B2(r){return r.code===Tr.code}function I2(r){return r.code===lr.code}var gt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},In=class extends Error{static name="ValidationError";name="ValidationError"},il=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},sl=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var al=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",u=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(p===void 0)break;if(i*=e,i+=p,i>u||(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 O2=45,P2=15,cl=new al;function Ow(r){if(!(r.length>P2))return cl.new(r).parseWith(()=>cl.readIPv4Addr())}function Pw(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>O2))return cl.new(r).parseWith(()=>cl.readIPv6Addr())}function ul(r){return!!Ow(r)}function Nw(r){return!!Pw(r)}function ay(r){return e=>le(e,r)}function cy(r){return e=>ye(e,r)}function Us(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ui(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function kw(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=ye(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ui(n);return Rt([t,o],t.length+o.length)}function Dw(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=oo.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=ui(n);return Rt([t,o],t.length+o.length)}function uy(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=le(e,"base32"),o=Us(t);return`${n}:${o}`}var fy=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new gt("Invalid byte value in IP address");e[n]=o}),e},Rw=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=ul(t[n]),s;i&&(s=fy(t[n]),t[n]=le(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,le(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new gt("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},jw=function(r){if(r.byteLength!==4)throw new gt("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Lw=function(r){if(r.byteLength!==16)throw new gt("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${t}"`)}};function Uw(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new gt(`Invalid IPv6 address "${r}"`)}}var sy=Object.values(Zo).map(r=>r.decoder),N2=(function(){let r=sy[0].or(sy[1]);return sy.slice(2).forEach(e=>r=r.or(e)),r})();function Mw(r){return N2.decode(r)}function Kw(r){return e=>r.encoder.encode(e)}function k2(r){if(parseInt(r).toString()!==r)throw new In("Value must be an integer")}function D2(r){if(r<0)throw new In("Value must be a positive integer, or zero")}function R2(r){return e=>{if(e>r)throw new In(`Value must be smaller than or equal to ${r}`)}}function j2(...r){return e=>{for(let t of r)t(e)}}var Ac=j2(k2,D2,R2(65535));var dt=-1,ly=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new sl(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},On=new ly,Y2=[{code:4,name:"ip4",size:32,valueToBytes:fy,bytesToValue:jw,validate:r=>{if(!ul(r))throw new In(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:273,name:"udp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:33,name:"dccp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:41,name:"ip6",size:128,valueToBytes:Rw,bytesToValue:Lw,stringToValue:Uw,validate:r=>{if(!Nw(r))throw new In(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:ay("base10"),valueToBytes:cy("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:ui,bytesToValue:Us,validate:Ac},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:ay("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?cy("base58btc")(r):ct.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:uy,valueToBytes:kw},{code:445,name:"onion3",size:296,bytesToValue:uy,valueToBytes:Dw},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Kw(Xo),valueToBytes:Mw},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];Y2.forEach(r=>{On.addProtocol(r)});function Hw(r){let e=[],t=0;for(;t<r.length;){let n=Cn(r,t),o=On.getProtocol(n),i=We(n),s=J2(o,r,t+i),a=0;s>0&&o.size===dt&&(a=We(s));let c=i+a+s,u={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let p=t+i+a,l=r.subarray(p,p+s);u.value=o.bytesToValue?.(l)??le(l)}e.push(u),t+=c}return e}function Vw(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=On.getProtocol(n.code),i=We(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??ye(n.value),a=s.byteLength,o.size===dt&&(c=We(a)));let u=new Uint8Array(i+c+a),p=0;Ps(n.code,u,p),p+=i,s!=null&&(o.size===dt&&(Ps(a,u,p),p+=c),u.set(s,p)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return Rt(t,e)}function $w(r){if(r.charAt(0)!=="/")throw new gt('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=On.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new gt(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new gt(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new gt("Incomplete multiaddr");return e}function Fw(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=On.getProtocol(e.code);if(t==null)throw new gt(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function J2(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Cn(e,t)}var Q2=Symbol.for("nodejs.util.inspect.custom"),By=Symbol.for("@multiformats/multiaddr");function eC(r){if(r==null&&(r="/"),Ww(r))return r.getComponents();if(r instanceof Uint8Array)return Hw(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),$w(r);if(Array.isArray(r))return r;throw new gt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var hl=class r{[By]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=eC(e),t.validate!==!1&&tC(this)}get bytes(){return this.#r==null&&(this.#r=Vw(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Fw(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new il(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return Ye(this.bytes,e.bytes)}[Q2](){return`Multiaddr(${this.toString()})`}};function tC(r){r.getComponents().forEach(e=>{let t=On.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function Ww(r){return!!r?.[By]}function Vs(r){return new hl(r)}var Me=r=>({match:e=>{let t=e[0];return t==null||t.code!==r||t.value!=null?!1:e.slice(1)}}),fe=(r,e)=>({match:t=>{let n=t[0];return n?.code!==r||n.value==null||e!=null&&n.value!==e?!1:t.slice(1)}}),qw=r=>({match:e=>r.match(e)===!1?e:!1}),Ae=r=>({match:e=>{let t=r.match(e);return t===!1?e:t}}),Ot=(...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}}),De=(...r)=>({match:e=>{for(let t of r){let n=t.match(e);if(n===!1)return!1;e=n}return e}});function Ke(...r){function e(o){if(o==null)return!1;let i=o.getComponents();for(let s of r){let a=s.match(i);if(a===!1)return!1;i=a}return i}function t(o){return e(o)!==!1}function n(o){let i=e(o);return i===!1?!1:i.length===0}return{matchers:r,matches:t,exactMatch:n}}var rC=fe(421),t4=Ke(rC),yl=fe(54),ml=fe(55),gl=fe(56),Oy=fe(53),r4=Ke(yl,Ae(fe(421))),n4=Ke(ml,Ae(fe(421))),o4=Ke(gl,Ae(fe(421))),i4=Ke(Ot(Oy,gl,yl,ml),Ae(fe(421))),Gw=De(fe(4),Ae(fe(43))),zw=De(Ae(fe(42)),fe(41),Ae(fe(43))),Py=Ot(Gw,zw),pi=Ot(Py,Oy,yl,ml,gl),s4=Ke(Ot(Py,De(Ot(Oy,gl,yl,ml),Ae(fe(421))))),a4=Ke(Gw),c4=Ke(zw),u4=Ke(Py),Ny=De(pi,fe(6)),Ec=De(pi,fe(273)),f4=Ke(De(Ny,Ae(fe(421)))),l4=Ke(Ec),ky=De(Ec,Me(460),Ae(fe(421))),bl=De(Ec,Me(461),Ae(fe(421))),nC=Ot(ky,bl),p4=Ke(ky),h4=Ke(bl),Iy=Ot(pi,Ny,Ec,ky,bl),Xw=Ot(De(Iy,Me(477),Ae(fe(421)))),d4=Ke(Xw),Zw=Ot(De(Iy,Me(478),Ae(fe(421))),De(Iy,Me(448),Ae(fe(449)),Me(477),Ae(fe(421)))),y4=Ke(Zw),Yw=De(Ec,Me(280),Ae(fe(466)),Ae(fe(466)),Ae(fe(421))),Jw=Ke(Yw),Qw=De(bl,Me(465),Ae(fe(466)),Ae(fe(466)),Ae(fe(421))),m4=Ke(Qw),dl=Ot(Xw,Zw,De(Ny,Ae(fe(421))),De(nC,Ae(fe(421))),De(pi,Ae(fe(421))),Yw,Qw,fe(421)),ex=Ke(dl),oC=De(Ae(dl),Me(290),qw(Me(281)),Ae(fe(421))),g4=Ke(oC),iC=Ot(De(dl,Me(290),Me(281),Ae(fe(421))),De(dl,Me(281),Ae(fe(421))),De(Me(281),Ae(fe(421)))),tx=Ke(iC),sC=Ot(De(pi,fe(6),Me(480),Ae(fe(421))),De(pi,Me(480),Ae(fe(421)))),b4=Ke(sC),aC=De(pi,Ot(De(fe(6,"443"),Me(480)),De(fe(6),Me(443)),De(fe(6),Me(448),Me(480)),De(Me(448),Me(480)),Me(448),Me(443)),Ae(fe(421))),w4=Ke(aC),cC=Ot(De(fe(777),Ae(fe(421)))),x4=Ke(cC),uC=Ot(De(fe(400),Ae(fe(421)))),v4=Ke(uC);var Pt;(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=()=>ci(t)})(e=r.Flag||(r.Flag={}));let n;r.codec=()=>(n==null&&(n=Dr((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 u=o.uint32();switch(u>>>3){case 1:{a.flag=r.Flag.codec().decode(o);break}case 2:{a.message=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>kr(o,r.codec()),r.decode=(o,i)=>Nr(o,r.codec(),i)})(Pt||(Pt={}));var rx=["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478","stun:stun.cloudflare.com:3478","stun:stun.services.mozilla.com:3478"],Dy=Array.from("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"),nx="libp2p+webrtc+v1/",ox=2*1024*1024,$s=16*1024;function fC(r=$s){let e=We(r-We(r)),t=1+We(Object.keys(Pt.Flag).length-1),n=1,o=r-e-t-n,i=We(o);return e+t+n+i}var ix=fC();var sx=1e4,Ry="/webrtc",Cc="/webrtc-signaling/0.0.1",ax="/libp2p/webrtc-direct/certificate",cx="webrtc-direct-certificate-private-key";var ux=12096e5,jy=864e5;function Ly(r){let e=r.getComponents(),t={},n=0;if(e[n]?.name==="ip6zone"&&(t.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(t.type=e[n].name,t.host=e[n].value,n++):e[n].name==="dnsaddr"&&(t.type=e[n].name,t.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(t.protocol=e[n].name==="tcp"?"tcp":"udp",t.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(t.type==="ip4"?t.cidr=parseInt(`${e[n].value}`):t.type==="ip6"&&(t.cidr=`${e[n].value}`),n++),t.type==null||t.host==null)throw new ve(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(t.sni=e[n+1].value,n+=2),t}function wl(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var xl=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Fs=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new xl(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new xl(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Uy=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Ws(r={}){return lC(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 lC(r,e){e=e??{};let t=e.onEnd,n=new Fs,o,i,s,a=wl(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,A)=>{i=D=>{i=null,n.push(D);try{g(r(n))}catch(B){A(B)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=wl()})}},u=g=>i!=null?i(g):(n.push(g),o),p=g=>(n=new Fs,i!=null?i({error:g}):(n.push({error:g}),o)),l=g=>{if(s)return o;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},h=g=>s?o:(s=!0,g!=null?p(g):u({done:!0})),y=()=>(n=new Fs,h(),{done:!0}),m=g=>(h(g),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:y,throw:m,push:l,end:h,get readableLength(){return n.size},onEmpty:async g=>{let A=g?.signal;if(A?.throwIfAborted(),n.isEmpty())return;let D,B;A!=null&&(D=new Promise(($,Q)=>{B=()=>{Q(new Uy)},A.addEventListener("abort",B)}));try{await Promise.race([a.promise,D])}finally{B!=null&&A!=null&&A?.removeEventListener("abort",B)}}},t==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(g){return w.throw(g),t!=null&&(t(g),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:l,end(g){return w.end(g),t!=null&&(t(g),t=void 0),o},get readableLength(){return w.readableLength},onEmpty:g=>w.onEmpty(g)},o}var My=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ky=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fx=r=>globalThis.DOMException===void 0?new Ky(r):new DOMException(r),lx=r=>{let e=r.reason===void 0?fx("This operation was aborted."):r.reason;return e instanceof Error?e:fx(e)};function Hy(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,a,u=new Promise((p,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:y}=e;y.aborted&&l(lx(y)),a=()=>{l(lx(y))},y.addEventListener("abort",a,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(p,l);return}let h=new My;s=i.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(y){l(y)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?p():o instanceof Error?l(o):(h.message=o??`Promise timed out after ${t} milliseconds`,l(h))},t),(async()=>{try{p(await r)}catch(y){l(y)}})()}).finally(()=>{u.clear(),a&&e.signal&&e.signal.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}var pC=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function hC(r,e,t){let n,o=new Promise((i,s)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:p}=pC(r),l=(...y)=>{let m=t.multiArgs?y:y[0];t.filter&&!t.filter(m)||(c.push(m),t.count===c.length&&(n(),i(c)))},h=y=>{n(),s(y)};n=()=>{for(let y of a)p(y,l);for(let y of t.rejectionEvents)p(y,h)};for(let y of a)u(y,l);for(let y of t.rejectionEvents)u(y,h);t.signal&&t.signal.addEventListener("abort",()=>{h(t.signal.reason)},{once:!0}),t.resolveImmediately&&i(c)});if(o.cancel=n,typeof t.timeout=="number"){let i=Hy(o,{milliseconds:t.timeout});return i.cancel=n,i}return o}function Mt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=hC(r,e,t),o=n.then(i=>i[0]);return o.cancel=n.cancel,o}var hi=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"},vl=class extends Error{static name="MaxEarlyStreamsError";name="MaxEarlyStreamsError"};function dC(r){return r.reason}async function qs(r,e,t){if(e==null)return r;let n=t?.translateError??dC;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((i,s)=>{o=()=>{s(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var yC=Math.pow(2,20)*4,bo=class extends fr{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??yC,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new me,this.writeBuffer=new me,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let t=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue())};this.addEventListener("drain",t)}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Ws(),t=i=>{e.push(i.data)};this.addEventListener("message",t);let n=i=>{e.end(i.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",t),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new dn(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(t){this.log("failed to send reset to remote - %e",t)}this.dispatchEvent(new If(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new dn(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new hs;this.dispatchEvent(new Of(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new ds))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,t=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let i=this.writeBuffer.sublist(0,o),s=new me(i);this.writeBuffer.consume(i.byteLength);let a=this.sendData(i);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==s.byteLength&&(s.consume(a.sentBytes),this.writeBuffer.prepend(s)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,t,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Bf(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new $a(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new $a(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var _l=class extends bo{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",t=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),t.error!=null?t.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):t.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};function px(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Sl=class extends fr{streams;protocol;status;log;maConn;streamOptions;earlyStreams;maxEarlyStreams;metrics;constructor(e,t){super(),this.maConn=e,this.protocol=t.protocol,this.streams=[],this.earlyStreams=[],this.status="open",this.log=e.log.newScope(t.name),this.streamOptions=t.streamOptions,this.maxEarlyStreams=t.maxEarlyStreams??10,this.metrics=t.metrics;let n=s=>{try{this.onData(s.data)}catch(a){this.abort(a),this.maConn.abort(a)}};this.maConn.addEventListener("message",n);let o=()=>{this.log("underlying stream drained, signal %d streams to continue writing",this.streams.length),this.streams.forEach(s=>{s.onMuxerDrain()})};this.maConn.addEventListener("drain",o);let i=()=>{this.log("underlying stream closed with status %s and %d streams",this.status,this.streams.length),this.onTransportClosed()};this.maConn.addEventListener("close",i)}send(e){let t=this.maConn.send(e);return t===!1&&(this.log("underlying stream saturated, signal %d streams to pause writing",this.streams.length),this.streams.forEach(n=>{n.onMuxerNeedsDrain()})),t}async close(e){this.status==="closed"||this.status==="closing"||(this.status="closing",await qs(Promise.all([...this.streams].map(async t=>{await t.close(e)})),e?.signal),this.status="closed")}abort(e){this.status!=="closed"&&(this.status="closing",[...this.streams].forEach(t=>{t.abort(e)}),this.status="closed")}onTransportClosed(e){this.status="closing";try{[...this.streams].forEach(t=>{t.onTransportClosed(e)})}catch(t){this.abort(t)}this.status="closed"}async createStream(e){if(this.status!=="open")throw new _f;let t=this.onCreateStream({...this.streamOptions,...e});return px(t)&&(t=await t),this.streams.push(t),this.cleanUpStream(t),t}onRemoteStream(e){if(this.streams.push(e),this.cleanUpStream(e),this.listenerCount("stream")===0){this.earlyStreams.push(e),this.earlyStreams.length>this.maxEarlyStreams&&this.abort(new vl(`Too many early streams were opened - ${this.earlyStreams.length}/${this.maxEarlyStreams}`));return}this.safeDispatchEvent("stream",{detail:e})}cleanUpStream(e){let t=n=>{let o=this.streams.findIndex(i=>i===e);o!==-1&&this.streams.splice(o,1),n.error!=null?n.local?this.metrics?.increment({[`${e.direction}_stream_reset`]:!0}):this.metrics?.increment({[`${e.direction}_stream_abort`]:!0}):this.metrics?.increment({[`${e.direction}_stream_end`]:!0})};e.addEventListener("close",t),this.metrics?.increment({[`${e.direction}_stream`]:!0})}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="stream"&&this.earlyStreams.length>0&&queueMicrotask(()=>{this.earlyStreams.forEach(t=>{this.safeDispatchEvent("stream",{detail:t})}),this.earlyStreams=[]})}};var Al=class extends bo{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Mt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Mt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var mC=4194304,El=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Tc=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$y=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Fy=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function gC(r){return typeof r?.closeRead=="function"}function bC(r){return typeof r?.close=="function"}function Vy(r){return gC(r)?r.readStatus==="closing"||r.readStatus==="closed":bC(r)?r.status!=="open":!1}function wC(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function xC(r,e){let t=e?.maxBufferSize??mC,n=new me,o=Promise.withResolvers(),i=!1;if(!wC(r))throw new ve("Argument should be a Stream or a Multiaddr");let s=p=>{if(n.append(p.data),n.byteLength>t){let l=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${l} > ${t}`))}o.resolve()};r.addEventListener("message",s);let a=p=>{p.error!=null?o.reject(p.error):o.resolve()};r.addEventListener("close",a);let c=()=>{o.resolve()};r.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(p){if(i===!0)throw new El("Stream was unwrapped");if(Vy(r)){if(p?.bytes==null)return null;if(n.byteLength<p.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,p.bytes),new hi(`Unexpected EOF - stream closed after reading ${n.byteLength}/${p.bytes} bytes`)}let l=p?.bytes??1;for(;;){if(n.byteLength>=l){o.resolve();break}if(await qs(o.promise,p?.signal),Vy(r)){if(n.byteLength===0&&p?.bytes==null)return null;break}o=Promise.withResolvers()}let h=p?.bytes??n.byteLength;if(n.byteLength<h){if(Vy(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,h),new hi(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(p)}let y=n.sublist(0,h);return n.consume(h),y},async write(p,l){if(i===!0)throw new El("Stream was unwrapped");r.send(p)||await Mt(r,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,r.removeEventListener("message",s),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return u}function Cl(r,e={}){let t=xC(r,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=We(e.maxDataLength));let n=e?.lengthDecoder??Cn,o=e?.lengthEncoder??Zf;return{async read(s){let a=-1,c=new me;for(;;){let p=await t.read({...s,bytes:1});if(p==null)break;c.append(p);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Tc("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Fy(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new $y(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await t.read({...s,bytes:a});if(u==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new hi(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new hi(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(s,a){await t.write(new me(o(s.byteLength),s),a)},async writeV(s,a){let c=new me(...s.flatMap(u=>[o(u.byteLength),u]));await t.write(c,a)},unwrap(){return t.unwrap()}}}function Tl(r,e){let t=Cl(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 vC=1024*1024*4,_C=1024*1024*4,Bl=class{buffer;maxBufferSize;lengthDecoder;maxDataLength;encodingLength;constructor(e={}){this.buffer=new me,this.maxBufferSize=e.maxBufferSize??vC,this.maxDataLength=e.maxDataLength??_C,this.lengthDecoder=e.lengthDecoder??Cn,this.encodingLength=e.encodingLength??We}*decode(e){if(this.buffer.append(e),this.buffer.byteLength>this.maxBufferSize)throw new ve(`Buffer length limit exceeded - ${this.buffer.byteLength}/${this.maxBufferSize}`);for(;;){let t;try{t=this.lengthDecoder(this.buffer)}catch(i){if(i instanceof RangeError)break;throw i}if(t<0||t>this.maxDataLength)throw new Tc("Invalid message length");let n=this.encodingLength(t),o=n+t;if(this.buffer.byteLength>=o){let i=this.buffer.sublist(n,o);this.buffer.consume(o),i.byteLength>0&&(yield i)}else break}}};var Il=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Gs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ol=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Bc=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Pl(r){return r[Symbol.asyncIterator]!=null}function hx(r,e){if(r.byteLength>e)throw new Gs("Message length too long")}var kl=r=>{let e=We(r),t=ft(e);return Zf(r,t),kl.bytes=e,t};kl.bytes=0;function Ic(r,e){e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;function*o(i){hx(i,n);let s=t(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Pl(r)?(async function*(){for await(let i of r)yield*o(i)})():(function*(){for(let i of r)yield*o(i)})()}Ic.single=(r,e)=>{e=e??{};let t=e.lengthEncoder??kl,n=e?.maxDataLength??4194304;return hx(r,n),new me(t(r.byteLength),r)};var di;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(di||(di={}));var Wy=r=>{let e=Cn(r);return Wy.bytes=We(e),e};Wy.bytes=0;function Oc(r,e){let t=new me,n=di.LENGTH,o=-1,i=e?.lengthDecoder??Wy,s=e?.maxLengthLength??8,a=e?.maxDataLength??4194304;function*c(){for(;t.byteLength>0;){if(n===di.LENGTH)try{if(o=i(t),o<0)throw new Il("Invalid message length");if(o>a)throw new Gs("Message length too long");let u=i.bytes;t.consume(u),e?.onLength!=null&&e.onLength(o),n=di.DATA}catch(u){if(u instanceof RangeError){if(t.byteLength>s)throw new Ol("Message length length too long");break}throw u}if(n===di.DATA){if(t.byteLength<o)break;let u=t.sublist(0,o);t.consume(o),e?.onData!=null&&e.onData(u),yield u,n=di.LENGTH}}}return Pl(r)?(async function*(){for await(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Bc("Unexpected end of input")})():(function*(){for(let u of r)t.append(u),yield*c();if(t.byteLength>0)throw new Bc("Unexpected end of input")})()}Oc.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 Oc(n,{...e??{},onLength:i=>{t=i}})};var dx=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))},EC=(function(){function r(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"}return r})();var CC=(function(){function r(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return r})();var TC=(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 BC=(function(){function r(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return r})();var IC=(function(){function r(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return r})();var OC=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,PC=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,yx=3,NC=[["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",OC]],mx=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function bx(r){return r?gx(r):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new IC:typeof navigator<"u"?gx(navigator.userAgent):RC()}function kC(r){return r!==""&&NC.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 gx(r){var e=kC(r);if(!e)return null;var t=e[0],n=e[1];if(t==="searchbot")return new BC;var o=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);o?o.length<yx&&(o=dx(dx([],o,!0),jC(yx-o.length),!0)):o=[];var i=o.join("."),s=DC(r),a=PC.exec(r);return a&&a[1]?new TC(t,i,s,a[1]):new EC(t,i,s)}function DC(r){for(var e=0,t=mx.length;e<t;e++){var n=mx[e],o=n[0],i=n[1],s=i.exec(r);if(s)return o}return null}function RC(){var r=typeof process<"u"&&process.version;return r?new CC(process.version.slice(1)):null}function jC(r){for(var e=[],t=0;t<r;t++)e.push("0");return e}var wx=bx(),Dl=wx!=null&&wx.name==="firefox";async function qy(r){return r=r??{},typeof r=="function"&&(r=await r()),r.iceServers=r.iceServers??rx.map(e=>({urls:[e]})),r}var xx=(r=32)=>nx+[...Array(r)].map(()=>Dy.at(Math.floor(Math.random()*Dy.length))).join("");var Gy=class extends Al{channel;incomingData;maxBufferedAmount;receivedFinAck;finAckTimeout;constructor(e){super({...e,maxMessageSize:(e.maxMessageSize??$s)-ix}),this.channel=e.channel,this.channel.binaryType="arraybuffer",this.incomingData=Ws(),this.maxBufferedAmount=e.maxBufferedAmount??ox,this.finAckTimeout=e.finAckTimeout??sx,this.channel.onclose=()=>{this.log.trace("received datachannel close event"),this.onRemoteCloseWrite(),this.onTransportClosed()},this.channel.onerror=n=>{let o=n.error;this.log.trace("received datachannel error event - %e",o),this.abort(o)},this.channel.onmessage=async n=>{this.log("incoming message %d bytes",n.data.byteLength);let{data:o}=n;o===null||o.byteLength===0||this.incomingData.push(new Uint8Array(o,0,o.byteLength))},this.channel.bufferedAmountLowThreshold=0,this.channel.onbufferedamountlow=()=>{this.writableNeedsDrain&&this.safeDispatchEvent("drain")},this.channel.readyState!=="open"&&(this.log('channel ready state is "%s" and not "open", waiting for "open" event before sending data',this.channel.readyState),Mt(this.channel,"open",{rejectionEvents:["close","error"]}).then(()=>{this.log('channel ready state is now "%s", dispatching drain',this.channel.readyState),this.safeDispatchEvent("drain")}).catch(n=>{this.abort(n.error??n)})),Promise.resolve().then(async()=>{for await(let n of Oc(this.incomingData))this.processIncomingProtobuf(n)}).catch(n=>{this.log.error("error processing incoming data channel messages",n)});let t=()=>{this.channel.readyState==="open"&&(this.log.trace("stream closed, closing underlying datachannel"),this.channel.close())};this.addEventListener("close",t)}sendNewStream(){}_sendMessage(e){if(this.channel.readyState!=="open")throw new dn(`Invalid datachannel state - ${this.channel.readyState}`);if(this.log.trace('sending message, channel state "%s"',this.channel.readyState),Dl){this.channel.send(e.subarray());return}for(let t of e)this.channel.send(t)}sendData(e){return this.channel.readyState!=="open"?{sentBytes:0,canSendMore:!1}:(this._sendMessage(Ic.single(Pt.encode({message:e.subarray()}))),{sentBytes:e.byteLength,canSendMore:this.channel.bufferedAmount<this.maxBufferedAmount})}sendReset(e){try{this.log.error("sending reset - %e",e),this._sendFlag(Pt.Flag.RESET),this.receivedFinAck?.reject(e)}catch(t){this.log.error("failed to send reset - %e",t)}}async sendCloseWrite(e){this._sendFlag(Pt.Flag.FIN),e?.signal?.throwIfAborted(),this.receivedFinAck=Promise.withResolvers(),await Promise.any([qs(this.receivedFinAck.promise,e?.signal),new Promise(t=>{AbortSignal.timeout(this.finAckTimeout).addEventListener("abort",()=>{t()})})])}async sendCloseRead(e){this._sendFlag(Pt.Flag.STOP_SENDING),e?.signal?.throwIfAborted()}processIncomingProtobuf(e){let t=Pt.decode(e);t.message!=null&&(this.readStatus==="readable"||this.readStatus==="paused")&&this.onData(new me(t.message)),t.flag!==void 0&&(this.log.trace('incoming flag %s, write status "%s", read status "%s"',t.flag,this.writeStatus,this.readStatus),t.flag===Pt.Flag.FIN&&(this._sendFlag(Pt.Flag.FIN_ACK),this.onRemoteCloseWrite()),t.flag===Pt.Flag.RESET&&(this.receivedFinAck?.reject(new hs("The stream was reset")),this.onRemoteReset()),t.flag===Pt.Flag.STOP_SENDING&&this.onRemoteCloseRead(),t.flag===Pt.Flag.FIN_ACK&&this.receivedFinAck?.resolve())}_sendFlag(e){if(this.channel.readyState!=="open")return this.log.trace('not sending flag %s because channel is "%s" and not "open"',e.toString(),this.channel.readyState),!1;this.log.trace("sending flag %s",e.toString());let t=Pt.encode({flag:e}),n=Ic.single(t);try{return this._sendMessage(n),!0}catch(o){this.log.error("could not send flag %s - %e",e.toString(),o)}return!1}sendPause(){}sendResume(){}};function Pc(r){let{channel:e,direction:t,isHandshake:n}=r;return new Gy({...r,id:`${e.id}`,log:r.log.newScope(`${n===!0?"handshake":t}:${e.id}`),protocol:""})}var wo=class{protocol;peerConnection;metrics;dataChannelOptions;constructor(e){this.peerConnection=e.peerConnection,this.metrics=e.metrics,this.protocol=e.protocol??Ry,this.dataChannelOptions=e.dataChannelOptions??{}}createStreamMuxer(e){return new zy(e,{peerConnection:this.peerConnection,dataChannelOptions:this.dataChannelOptions,metrics:this.metrics,protocol:this.protocol})}},zy=class extends Sl{peerConnection;dataChannelOptions;constructor(e,t){super(e,{...t,name:"muxer"}),this.peerConnection=t.peerConnection,this.protocol=t.protocol??Ry,this.dataChannelOptions=t.dataChannelOptions??{},this.peerConnection.ondatachannel=({channel:n})=>{if(this.log.trace("incoming %s datachannel with channel id %d, protocol %s and status %s",n.protocol,n.id,n.protocol,n.readyState),n.label==="init"){this.log.trace("closing init channel %d",n.id),n.close();return}let o=Pc({...this.streamOptions,...this.dataChannelOptions,channel:n,direction:"inbound",log:this.log});this.onRemoteStream(o)}}async onCreateStream(e){let t=this.peerConnection.createDataChannel("",{});return this.log("open channel %d for protocol %s",t.id,e?.protocol),Pc({...e,...this.dataChannelOptions,channel:t,direction:"outbound",log:this.log})}onData(){}};var Xy=class extends _l{peerConnection;constructor(e){super(e),this.peerConnection=e.peerConnection;let t=e.peerConnection.connectionState;this.peerConnection.onconnectionstatechange=()=>{this.log.trace("peer connection state change %s initial state %s",this.peerConnection.connectionState,t),(this.peerConnection.connectionState==="disconnected"||this.peerConnection.connectionState==="failed"||this.peerConnection.connectionState==="closed")&&(this.onTransportClosed(),this.peerConnection.close())}}sendData(e){return{sentBytes:e.byteLength,canSendMore:!0}}async sendClose(e){this.peerConnection.close(),e?.signal?.throwIfAborted()}sendReset(){this.peerConnection.close()}sendPause(){}sendResume(){}},Nc=r=>new Xy(r);var Rl=globalThis.RTCPeerConnection,jl=globalThis.RTCSessionDescription,vx=globalThis.RTCIceCandidate;var or=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var xo=class extends Error{constructor(e){super(`WebRTC transport error: ${e}`),this.name="WebRTCTransportError"}},yr=class extends xo{constructor(e="SDP handshake failed"){super(e),this.name="SDPHandshakeFailedError"}};var Ll=class extends xo{constructor(e,t){super(`Invalid fingerprint "${e}" within ${t}`),this.name="WebRTC/InvalidFingerprintError"}};var Ul=class extends xo{constructor(e){super(`A method (${e}) was called though it has been intentionally left unimplemented.`),this.name="WebRTC/UnimplementedError"}},Ml=class extends xo{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 Wt;(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=()=>ci(t)})(e=r.Type||(r.Type={}));let n;r.codec=()=>(n==null&&(n=Dr((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 u=o.uint32();switch(u>>>3){case 1:{a.type=r.Type.codec().decode(o);break}case 2:{a.data=o.string();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>kr(o,r.codec()),r.decode=(o,i)=>Nr(o,r.codec(),i)})(Wt||(Wt={}));var Kl=async(r,e,t)=>{try{let n=Promise.withResolvers();for(LC(r,n);;){let o=await Promise.race([n.promise,e.read({signal:t.signal})]);if(o==null){t.signal?.throwIfAborted();break}if(o.type!==Wt.Type.ICE_CANDIDATE)throw new Cf("ICE candidate message expected");let i=JSON.parse(o.data??"null");if(i===""||i===null){t.onProgress?.(new or("webrtc:end-of-ice-candidates")),t.log.trace("end-of-candidates received");continue}let s=new vx(i);t.log.trace("%s received new ICE candidate %o",t.direction,i);try{t.onProgress?.(new or("webrtc:add-ice-candidate",s.candidate)),await r.addIceCandidate(s)}catch(a){t.log.error("%s bad candidate received %o - %e",t.direction,i,a)}}}catch(n){if(t.log.error("%s error parsing ICE candidate - %e",t.direction,n),t.signal?.aborted===!0&&r.connectionState!=="connected")throw n}};function LC(r,e){if(r.connectionState==="connected"){e.resolve();return}r.onconnectionstatechange=t=>{switch(r.connectionState){case"connected":e.resolve();break;case"failed":case"disconnected":case"closed":e.reject(new vf(`RTCPeerConnection connection state became "${r.connectionState}"`));break;default:break}}}function Hl(r){let e;for(let t of r.getComponents())t.name==="p2p"&&(e=Ls(t.value??""));if(e==null)throw new Sf("Remote peerId must be present in multiaddr");return e}async function _x({rtcConfiguration:r,dataChannel:e,signal:t,metrics:n,multiaddr:o,connectionManager:i,transportManager:s,log:a,logger:c,onProgress:u}){let{circuitAddress:p,targetPeer:l}=Sx(o);n?.dialerEvents.increment({open:!0}),a.trace("dialing circuit address: %a",p);let h=i.getConnections(l),y;h.length===0?(u?.(new or("webrtc:dial-relay")),y=await s.dial(p,{signal:t,onProgress:u})):(u?.(new or("webrtc:reuse-relay-connection")),y=h[0]),u?.(new or("webrtc:open-signaling-stream"));let m=await y.newStream(Cc,{signal:t,runOnLimitedConnection:!0}),w=Tl(m).pb(Wt),g=new Rl(r);g.addEventListener("connectionstatechange",()=>{switch(g.connectionState){case"closed":g.close();break;default:break}});let A=new wo({peerConnection:g,dataChannelOptions:e});try{let D=g.createDataChannel("init");g.onicecandidate=({candidate:X})=>{if(g.connectionState==="connected"){a.trace("ignore new ice candidate as peer connection is already connected");return}if(X==null||X?.candidate===""){a.trace("initiator detected end of ICE candidates");return}let ne=JSON.stringify(X?.toJSON()??null);a.trace("initiator sending ICE candidate %o",X),w.write({type:Wt.Type.ICE_CANDIDATE,data:ne},{signal:t}).catch(Y=>{a.error("error sending ICE candidate - %e",Y)})},g.onicecandidateerror=X=>{a.error("initiator ICE candidate error",X)};let B=await g.createOffer().catch(X=>{throw a.error("could not execute createOffer",X),new yr("Failed to set createOffer")});a.trace("initiator send SDP offer %s",B.sdp),u?.(new or("webrtc:send-sdp-offer")),await w.write({type:Wt.Type.SDP_OFFER,data:B.sdp},{signal:t}),await g.setLocalDescription(B).catch(X=>{throw a.error("could not execute setLocalDescription",X),new yr("Failed to set localDescription")}),u?.(new or("webrtc:read-sdp-answer")),a.trace("initiator read SDP answer");let $=await w.read({signal:t});if($.type!==Wt.Type.SDP_ANSWER)throw new yr("Remote should send an SDP answer");a.trace("initiator received SDP answer %s",$.data);let Q=new jl({type:"answer",sdp:$.data});return await g.setRemoteDescription(Q).catch(X=>{throw a.error("could not execute setRemoteDescription",X),new yr("Failed to set remoteDescription")}),a.trace("initiator read candidates until connected"),u?.(new or("webrtc:read-ice-candidates")),await Kl(g,w,{direction:"initiator",signal:t,log:a,onProgress:u}),a.trace("initiator connected"),D.readyState!=="open"&&(a.trace("wait for init channel to open"),await Mt(D,"open",{signal:t})),a.trace("closing init channel"),D.close(),a.trace("waiting for init channel to close"),await Mt(D,"close",{signal:t}),u?.(new or("webrtc:close-signaling-stream")),a.trace("closing signaling channel"),await m.close({signal:t}),a.trace("initiator connected to remote address %s",o),{remoteAddress:o,peerConnection:g,muxerFactory:A}}catch(D){throw a.error("outgoing signaling error",D),g.close(),m.abort(D),D}finally{g.onicecandidate=null,g.onicecandidateerror=null}}var Ax=Ke(ex.matchers[0],Me(290)),Vl=class r extends fr{transportManager;shutdownController;events;constructor(e,t){super(),this.transportManager=e.transportManager,this.events=e.events,this.shutdownController=t.shutdownController,this.onTransportListening=this.onTransportListening.bind(this)}async listen(){this.events.addEventListener("transport:listening",this.onTransportListening)}onTransportListening(e){e.detail.getAddrs().filter(n=>Ax.exactMatch(n)).map(n=>n.encapsulate("/webrtc")).length>0&&this.safeDispatchEvent("listening")}getAddrs(){return this.transportManager.getListeners().filter(e=>!(e instanceof r)).map(e=>e.getAddrs().filter(t=>Ax.exactMatch(t)).map(t=>t.encapsulate("/webrtc"))).flat()}updateAnnounceAddrs(){}async close(){this.events.removeEventListener("transport:listening",this.onTransportListening),this.shutdownController.abort(),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};async function Ex(r,e,{peerConnection:t,signal:n,log:o}){o.trace("new inbound signaling stream");let i=Tl(r).pb(Wt);try{t.onicecandidate=({candidate:l})=>{if(t.connectionState==="connected"){o.trace("ignore new ice candidate as peer connection is already connected");return}if(l==null||l?.candidate===""){o.trace("recipient detected end of ICE candidates");return}let h=JSON.stringify(l?.toJSON()??null);o.trace("recipient sending ICE candidate %s",h),i.write({type:Wt.Type.ICE_CANDIDATE,data:h},{signal:n}).catch(y=>{o.error("error sending ICE candidate - %e",y)})},o.trace("recipient read SDP offer");let c=await i.read({signal:n});if(c.type!==Wt.Type.SDP_OFFER)throw new yr(`expected message type SDP_OFFER, received: ${c.type??"undefined"} `);o.trace("recipient received SDP offer %s",c.data);let u=new jl({type:"offer",sdp:c.data});await t.setRemoteDescription(u).catch(l=>{throw o.error("could not execute setRemoteDescription",l),new yr("Failed to set remoteDescription")});let p=await t.createAnswer().catch(l=>{throw o.error("could not execute createAnswer",l),new yr("Failed to create answer")});o.trace("recipient send SDP answer %s",p.sdp),await i.write({type:Wt.Type.SDP_ANSWER,data:p.sdp},{signal:n}),await t.setLocalDescription(p).catch(l=>{throw o.error("could not execute setLocalDescription",l),new yr("Failed to set localDescription")}),o.trace("recipient read candidates until connected"),await Kl(t,i,{direction:"recipient",signal:n,log:o})}catch(c){if(t.connectionState!=="connected")throw o.error("error while handling signaling stream from peer %a",e.remoteAddr,c),t.close(),c;o("error while handling signaling stream from peer %a, ignoring as the RTCPeerConnection is already connected",e.remoteAddr,c)}let s=Hl(e.remoteAddr),a=Vs(`/webrtc/p2p/${s}`);return o.trace("recipient connected to remote address %s",a),{remoteAddress:a,remotePeer:s}}var $l=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"})})}[Pf]=!0;[Symbol.toStringTag]="@libp2p/webrtc";[ys]=["@libp2p/transport"];[_0]=["@libp2p/identify","@libp2p/circuit-relay-v2-transport"];isStarted(){return this._started}async start(){await this.components.registrar.handle(Cc,(e,t)=>{let n=this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);this._onProtocol(e,t,n).catch(o=>{this.log.error("failed to handle incoming connect from %p",t.remotePeer,o)}).finally(()=>{n.clear()})},{runOnLimitedConnection:!0}),this._started=!0}async stop(){await this.components.registrar.unhandle(Cc),this._started=!1}createListener(e){return new Vl(this.components,{shutdownController:this.shutdownController})}listenFilter(e){return e.filter(tx.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 _x({rtcConfiguration:await qy(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=Nc({peerConnection:o,remoteAddr:n,metrics:this.metrics?.dialerEvents,direction:"outbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")}),a=await t.upgrader.upgradeOutbound(s,{skipProtection:!0,skipEncryption:!0,remotePeer:Hl(e),muxerFactory:i,onProgress:t.onProgress,signal:t.signal});return this._closeOnShutdown(o,s),a}async _onProtocol(e,t,n){let o=new Rl(await qy(this.init.rtcConfiguration));o.addEventListener("connectionstatechange",()=>{switch(o.connectionState){case"closed":o.close();break;default:break}});let i=new wo({peerConnection:o,dataChannelOptions:this.init.dataChannel});try{let{remoteAddress:s,remotePeer:a}=await Ex(e,t,{peerConnection:o,signal:n,log:this.log});await e.close({signal:n});let c=Nc({peerConnection:o,remoteAddr:s,metrics:this.metrics?.listenerEvents,direction:"inbound",log:this.components.logger.forComponent("libp2p:webrtc:connection")});await this.components.upgrader.upgradeInbound(c,{skipEncryption:!0,skipProtection:!0,remotePeer:a,muxerFactory:i,signal:n}),this._closeOnShutdown(o,c)}catch(s){throw this.log.error("incoming signaling error",s),o.close(),e.abort(s),s}}_closeOnShutdown(e,t){let n=()=>{t.close().catch(o=>{this.log.error("could not close WebRTCMultiaddrConnection",o)})};this.shutdownController.signal.addEventListener("abort",n),e.addEventListener("close",()=>{this.shutdownController.signal.removeEventListener("abort",n)})}};function Sx(r){let e=r.getComponents().filter(({name:n})=>n==="p2p").map(({value:n})=>n).pop();if(e==null)throw new ve("Destination peer id was missing");return{circuitAddress:Vs(r.getComponents().filter(({name:n})=>n!=="webrtc")),targetPeer:Ls(e)}}var sX=Gr(Tx());var en={};Ct(en,{Any:()=>Jr,BaseBlock:()=>ot,BaseStringBlock:()=>jc,BitString:()=>Ur,BmpString:()=>wi,Boolean:()=>mi,CharacterString:()=>Bi,Choice:()=>Zs,Constructed:()=>it,DATE:()=>Vc,DateTime:()=>Fc,Duration:()=>Wc,EndOfContent:()=>Lc,Enumerated:()=>gi,GeneralString:()=>Ti,GeneralizedTime:()=>Ii,GraphicString:()=>Ci,HexBlock:()=>Qr,IA5String:()=>Ei,Integer:()=>jn,Null:()=>jr,NumericString:()=>vi,ObjectIdentifier:()=>bi,OctetString:()=>Lr,Primitive:()=>Rn,PrintableString:()=>_i,RawData:()=>Qy,RelativeObjectIdentifier:()=>Hc,Repeated:()=>Oi,Sequence:()=>Nt,Set:()=>Kt,TIME:()=>qc,TeletexString:()=>Si,TimeOfDay:()=>$c,UTCTime:()=>So,UniversalString:()=>xi,Utf8String:()=>gr,ValueBlock:()=>bt,VideotexString:()=>Ai,ViewWriter:()=>Xs,VisibleString:()=>_o,compareSchema:()=>kn,fromBER:()=>Un,verifySchema:()=>oT});var ge=Gr(Nn());function yi(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 vo(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 u=new Uint8Array(c);for(let p=a-1;p>=0;p--){let l=Math.pow(2,p*e);u[i-p-1]=Math.floor(o/l),o-=u[i-p-1]*l}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 Yy(){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=yi(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,yi(i,8)-n}function Bx(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=vo(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let o=vo(e,8,n),i=new Uint8Array(o);if(i[0]&128){let s=o.slice(0),a=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),i=new Uint8Array(o);for(let c=0;c<s.byteLength;c++)i[c+1]=a[c];i[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ix(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==n[o])return!1;return!0}function qt(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 uD=Math.log(2);function Gl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function em(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 Ln(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 Xs=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return em(this.items)}},kc=[new Uint8Array([1])],Ox="0123456789",Jy="name",Px="valueHexView",qC="isHexOnly",GC="idBlock",zC="tagClass",XC="tagNumber",ZC="isConstructed",YC="fromBER",JC="toBER",QC="local",Gt="",Mr=new ArrayBuffer(0),cp=new Uint8Array(0),Rc="EndOfContent",kx="OCTET STRING",Dx="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):cp}fromBER(n,o,i){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Ln(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",Mr)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ge.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var Dn=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=Gt,warnings:n=[],valueBeforeDecode:o=cp}={}){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)}}};Dn.NAME="baseBlock";var bt=class extends Dn{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'")}};bt.NAME="valueBlock";var zl=class extends Qr(Dn){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):cp,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",Mr}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=vo(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(!Ln(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,u=this.valueHexView=new Uint8Array(255),p=255;for(;i[c]&128;){if(u[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 h=new Uint8Array(p);for(let y=0;y<u.length;y++)h[y]=u[y];u=this.valueHexView=new Uint8Array(p)}}this.blockLength=c+1,u[c-1]=i[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(l),this.blockLength<=9?this.tagNumber=yi(u,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}}};zl.NAME="identificationBlock";var Xl=class extends Dn{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(!Ln(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=yi(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=vo(this.length,8);if(o.byteLength>127)return this.error="Too big length",Mr;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}}};Xl.NAME="lengthBlock";var J={},ot=class extends Dn{constructor({name:e=Gt,optional:t=!1,primitiveSchema:n,...o}={},i){super(o),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new zl(o),this.lenBlock=new Xl(o),this.valueBlock=i?new i(o):new bt(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 Xs;t||Rx(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?Mr: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 Ix(t,n)}};ot.NAME="BaseBlock";function Rx(r){var e;if(r instanceof J.Constructed)for(let t of r.valueBlock.value)Rx(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}var jc=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Gt,...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}'`}};jc.NAME="BaseStringBlock";var Zl=class extends Qr(bt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};Zl.NAME="PrimitiveValueBlock";var jx,Rn=class extends ot{constructor(e={}){super(e,Zl),this.idBlock.isConstructed=!1}};jx=Rn;J.Primitive=jx;Rn.NAME="PRIMITIVE";function eT(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 Ys(r,e=0,t=r.length){let n=e,o=new ot({},bt),i=new Dn;if(!Ln(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=J.EndOfContent;break;case 1:c=J.Boolean;break;case 2:c=J.Integer;break;case 3:c=J.BitString;break;case 4:c=J.OctetString;break;case 5:c=J.Null;break;case 6:c=J.ObjectIdentifier;break;case 10:c=J.Enumerated;break;case 12:c=J.Utf8String;break;case 13:c=J.RelativeObjectIdentifier;break;case 14:c=J.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:c=J.Sequence;break;case 17:c=J.Set;break;case 18:c=J.NumericString;break;case 19:c=J.PrintableString;break;case 20:c=J.TeletexString;break;case 21:c=J.VideotexString;break;case 22:c=J.IA5String;break;case 23:c=J.UTCTime;break;case 24:c=J.GeneralizedTime;break;case 25:c=J.GraphicString;break;case 26:c=J.VisibleString;break;case 27:c=J.GeneralString;break;case 28:c=J.UniversalString;break;case 29:c=J.CharacterString;break;case 30:c=J.BmpString;break;case 31:c=J.DATE;break;case 32:c=J.TimeOfDay;break;case 33:c=J.DateTime;break;case 34:c=J.Duration;break;default:{let u=o.idBlock.isConstructed?new J.Constructed:new J.Primitive;u.idBlock=o.idBlock,u.lenBlock=o.lenBlock,u.warnings=o.warnings,o=u}}break;case 2:case 3:case 4:default:c=o.idBlock.isConstructed?J.Constructed:J.Primitive}return o=eT(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 Un(r){if(!r.byteLength){let e=new ot({},bt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ys(ge.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function tT(r,e){return r?1:e}var Yr=class extends bt{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(!Ln(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(;tT(this.isIndefiniteForm,n)>0;){let s=Ys(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===Rc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Rc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){let n=t||new Xs;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,n);return t?Mr:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};Yr.NAME="ConstructedValueBlock";var Lx,it=class extends ot{constructor(e={}){super(e,Yr),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} :`}};Lx=it;J.Constructed=Lx;it.NAME="CONSTRUCTED";var Yl=class extends bt{fromBER(e,t,n){return t}toBER(e){return Mr}};Yl.override="EndOfContentValueBlock";var Ux,Lc=class extends ot{constructor(e={}){super(e,Yl),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ux=Lc;J.EndOfContent=Ux;Lc.NAME=Rc;var Mx,jr=class extends ot{constructor(e={}){super(e,bt),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}`}};Mx=jr;J.Null=Mx;jr.NAME="NULL";var Jl=class extends Qr(bt){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 Ln(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,Yy.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Jl.NAME="BooleanValueBlock";var Kx,mi=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Jl),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Kx=mi;J.Boolean=Kx;mi.NAME="BOOLEAN";var Ql=class extends Qr(Yr){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=Yr.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===Rc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==kx)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?Yr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ql.NAME="OctetStringValueBlock";var tm,Lr=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},Ql),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=Ys(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=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 tm&&e.push(t.valueBlock.valueHexView);return ge.BufferSourceConverter.concat(e)}};tm=Lr;J.OctetString=tm;Lr.NAME=kx;var ep=class extends Qr(Yr){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=Yr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Rc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Dx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let i=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=Ys(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 Yr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Mr;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}}};ep.NAME="BitStringValueBlock";var Hx,Ur=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},ep),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join(""),o=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${o} : ${i}`}}};Hx=Ur;J.BitString=Hx;Ur.NAME=Dx;var Vx;function rT(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,u=0,p=c<s?s:c,l=0;for(let h=p;h>=0;h--,l++){switch(!0){case l<a.length:u=i[s-l]+a[c-l]+t[0];break;default:u=i[s-l]+t[0]}switch(t[0]=u/10,!0){case l>=i.length:i=ql(new Uint8Array([u%10]),i);break;default:i[s-l]=u%10}}return t[0]>0&&(i=ql(t,i)),i}function Nx(r){if(r>=kc.length)for(let e=kc.length;e<=r;e++){let t=new Uint8Array([0]),n=kc[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)),kc.push(n)}return kc[r]}function nT(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,u,p=0;for(let l=c;l>=0;l--,p++)switch(u=i[s-p]-a[c-p]-t,!0){case u<0:t=1,i[s-p]=u+10;break;default:t=0,i[s-p]=u}if(t>0)for(let l=s-c+1;l>=0;l--,p++)if(u=i[s-p]-t,u<0)t=1,i[s-p]=u+10;else{t=0,i[s-p]=u;break}return i.slice()}var Uc=class extends Qr(bt){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=Yy.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(Bx(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 u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=nT(Nx(n),t),s="-";break;default:t=rT(t,Nx(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Ox.charAt(t[c]));return a===!1&&(s+=Ox.charAt(0)),s}};Vx=Uc;Uc.NAME="IntegerValueBlock";Object.defineProperty(Vx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Dc,jn=class extends ot{constructor(e={}){super(e,Uc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Gl(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Gl();let t=BigInt(e),n=new Xs,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 u=BigInt(`0x${ge.Convert.ToHex(a)}`)+t,p=ge.BufferSourceConverter.toUint8Array(ge.Convert.FromHex(u.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new Dc({valueHex:n.final()})}convertToDER(){let e=new Dc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Dc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Dc=jn;J.Integer=Dc;jn.NAME="INTEGER";var $x,gi=class extends jn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};$x=gi;J.Enumerated=$x;gi.NAME="ENUMERATED";var Mc=class extends Qr(bt){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(!Ln(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=yi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Gl();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=vo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Mr;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 tp=class extends bt{constructor({value:e=Gt,...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,Mr;t.push(o)}return em(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){Gl();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}};tp.NAME="ObjectIdentifierValueBlock";var Fx,bi=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,tp),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Fx=bi;J.ObjectIdentifier=Fx;bi.NAME="OBJECT IDENTIFIER";var Kc=class extends Qr(Dn){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(!Ln(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=yi(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=vo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Mr;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}}};Kc.NAME="relativeSidBlock";var rp=class extends bt{constructor({value:e=Gt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Kc;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,Mr;n.push(i)}return em(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 Kc;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}};rp.NAME="RelativeObjectIdentifierValueBlock";var Wx,Hc=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,rp),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Wx=Hc;J.RelativeObjectIdentifier=Wx;Hc.NAME="RelativeObjectIdentifier";var qx,Nt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};qx=Nt;J.Sequence=qx;Nt.NAME="SEQUENCE";var Gx,Kt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Gx=Kt;J.Set=Gx;Kt.NAME="SET";var np=class extends Qr(bt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Gt}toJSON(){return{...super.toJSON(),value:this.value}}};np.NAME="StringValueBlock";var op=class extends np{};op.NAME="SimpleStringValueBlock";var Ht=class extends jc{constructor({...e}={}){super(e,op)}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}};Ht.NAME="SIMPLE STRING";var ip=class extends Ht{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}};ip.NAME="Utf8StringValueBlock";var zx,gr=class extends ip{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};zx=gr;J.Utf8String=zx;gr.NAME="UTF8String";var sp=class extends Ht{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))}};sp.NAME="BmpStringValueBlock";var Xx,wi=class extends sp{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Xx=wi;J.BmpString=Xx;wi.NAME="BMPString";var ap=class extends Ht{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=vo(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}};ap.NAME="UniversalStringValueBlock";var Zx,xi=class extends ap{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Zx=xi;J.UniversalString=Zx;xi.NAME="UniversalString";var Yx,vi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Yx=vi;J.NumericString=Yx;vi.NAME="NumericString";var Jx,_i=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Jx=_i;J.PrintableString=Jx;_i.NAME="PrintableString";var Qx,Si=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Qx=Si;J.TeletexString=Qx;Si.NAME="TeletexString";var ev,Ai=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};ev=Ai;J.VideotexString=ev;Ai.NAME="VideotexString";var tv,Ei=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};tv=Ei;J.IA5String=tv;Ei.NAME="IA5String";var rv,Ci=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};rv=Ci;J.GraphicString=rv;Ci.NAME="GraphicString";var nv,_o=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};nv=_o;J.VisibleString=nv;_o.NAME="VisibleString";var ov,Ti=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ov=Ti;J.GeneralString=ov;Ti.NAME="GeneralString";var iv,Bi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};iv=Bi;J.CharacterString=iv;Bi.NAME="CharacterString";var sv,So=class extends _o{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]=qt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=qt(this.month,2),t[2]=qt(this.day,2),t[3]=qt(this.hour,2),t[4]=qt(this.minute,2),t[5]=qt(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}}};sv=So;J.UTCTime=sv;So.NAME="UTCTime";var av,Ii=class extends So{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.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 l=1,h=n.indexOf("+"),y="";if(h===-1&&(h=n.indexOf("-"),l=-1),h!==-1){if(y=n.substring(h+1),n=n.substring(0,h),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let m=parseInt(y.substring(0,2),10);if(isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*m,y.length===4){if(m=parseInt(y.substring(2,4),10),isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");c=l*m}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let l=new Number(`0${n.substring(u)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-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,u!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}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 l=1;l<p.length;l++)switch(l){case 1:this.year=parseInt(p[l],10);break;case 2:this.month=parseInt(p[l],10);break;case 3:this.day=parseInt(p[l],10);break;case 4:this.hour=parseInt(p[l],10)+a;break;case 5:this.minute=parseInt(p[l],10)+c;break;case 6:this.second=parseInt(p[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(qt(this.year,4)),t.push(qt(this.month,2)),t.push(qt(this.day,2)),t.push(qt(this.hour,2)),t.push(qt(this.minute,2)),t.push(qt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(qt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};av=Ii;J.GeneralizedTime=av;Ii.NAME="GeneralizedTime";var cv,Vc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};cv=Vc;J.DATE=cv;Vc.NAME="DATE";var uv,$c=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};uv=$c;J.TimeOfDay=uv;$c.NAME="TimeOfDay";var fv,Fc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};fv=Fc;J.DateTime=fv;Fc.NAME="DateTime";var lv,Wc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};lv=Wc;J.Duration=lv;Wc.NAME="Duration";var pv,qc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};pv=qc;J.TIME=pv;qc.NAME="TIME";var Jr=class{constructor({name:e=Gt,optional:t=!1}={}){this.name=e,this.optional=t}},Zs=class extends Jr{constructor({value:e=[],...t}={}){super(t),this.value=e}},Oi=class extends Jr{constructor({value:e=new Jr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Qy=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}constructor({data:e=cp}={}){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 kn(r,e,t){if(t instanceof Zs){for(let i of t.value)if(kn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Jy)&&(i.name=t.name),i}}if(t instanceof Jr)return t.hasOwnProperty(Jy)&&(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(!(GC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(YC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(JC 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(zC)===!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(XC)===!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(ZC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(qC 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(!(Px 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,Gt),t.name&&(r[t.name]=e)),t instanceof J.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof Oi&&(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 u=0;u<t.valueBlock.value.length;u++)c=c&&(t.valueBlock.value[u].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Gt),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 u={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,Gt),t.name&&(delete r[t.name],u.name=t.name)),u}}else if(t.valueBlock.value[0]instanceof Oi){if(s=kn(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,Gt),t.name&&delete r[t.name]),s;if(Jy in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let u={};QC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?u=e:u=r,typeof u[t.valueBlock.value[0].name]>"u"&&(u[t.valueBlock.value[0].name]=[]),u[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=kn(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,Gt),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,Gt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Px in e.valueBlock){let i=Ys(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,Gt),t.name&&(delete r[t.name],s.name=t.name)),s}return kn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function oT(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Ys(ge.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:kn(t.result,t.result,e)}var S;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(S||(S={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var rm=Gr(Nn()),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(rm.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=rm.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Ur))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 Ur({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Ur({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 nm=Gr(Nn()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):nm.BufferSourceConverter.isBufferSource(e)?this.buffer=nm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Lr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Lr({valueHex:this.buffer})}toSchema(e){return new Lr({name:e})}};var iT={fromASN:r=>r instanceof jr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new jr;let e=Un(r);if(e.result.error)throw new Error(e.result.error);return e.result}},sT={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new jn({value:+r})},aT={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new gi({value:r})},we={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new jn({valueHex:r})};var cT={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Ur({valueHex:r})},uT={fromASN:r=>r.valueBlock.toString(),toASN:r=>new bi({value:r})},fT={fromASN:r=>r.valueBlock.value,toASN:r=>new mi({value:r})},Js={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Lr({valueHex:r})},hv={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function br(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var om=br(gr),lT=br(wi),pT=br(xi),hT=br(vi),dT=br(_i),yT=br(Si),mT=br(Ai),gT=br(Ei),bT=br(Ci),wT=br(_o),xT=br(Ti),vT=br(Bi),_T={fromASN:r=>r.toDate(),toASN:r=>new So({valueDate:r})},ST={fromASN:r=>r.toDate(),toASN:r=>new Ii({valueDate:r})},AT={fromASN:()=>null,toASN:()=>new jr};function Ao(r){switch(r){case d.Any:return iT;case d.BitString:return cT;case d.BmpString:return lT;case d.Boolean:return fT;case d.CharacterString:return vT;case d.Enumerated:return aT;case d.GeneralString:return xT;case d.GeneralizedTime:return ST;case d.GraphicString:return bT;case d.IA5String:return gT;case d.Integer:return sT;case d.Null:return AT;case d.NumericString:return hT;case d.ObjectIdentifier:return uT;case d.OctetString:return Js;case d.PrintableString:return dT;case d.TeletexString:return yT;case d.UTCTime:return _T;case d.UniversalString:return pT;case d.Utf8String:return om;case d.VideotexString:return mT;case d.VisibleString:return wT;default:return null}}function wr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:wr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function sm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:sm(t)}return!1}function dv(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 up=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:S.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let p=d[s.type],l=en[p];if(!l)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new l({name:a})}else wr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===S.Choice?c=new Jr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Jr({name:a});let u=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Kt:Nt;c=new p({name:"",value:[new Oi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||wr(s.type)){let p=s.repeated?it:Rn;o.push(new p({name:a,optional:u,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,l=p?c:this.get(s.type,!0).schema;l="valueBlock"in l?l.valueBlock.value:l.value,o.push(new it({name:p?"":a,optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:l}))}else o.push(new it({optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=u,o.push(c)}switch(n.type){case S.Sequence:return new Nt({value:o,name:""});case S.Set:return new Kt({value:o,name:""});case S.Choice:return new Zs({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 Je=new up;var T=r=>e=>{let t;Je.has(e)?t=Je.get(e):(t=Je.createDefault(e),Je.set(e,t)),Object.assign(t,r)};var f=r=>(e,t)=>{let n;Je.has(e.constructor)?n=Je.get(e.constructor):(n=Je.createDefault(e.constructor),Je.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Ao(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}o.raw=r.raw,n.items[t]=o};var Eo=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Gc=class{static parse(e,t){let n=Un(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(wr(t))return new t().fromASN(e);let n=Je.get(t);Je.cache(t);let o=n.schema,i=this.handleChoiceTypes(e,n,t,o);if(i?.result)return i.result;i?.targetSchema&&(o=i.targetSchema);let s=this.handleSequenceTypes(e,n,t,o);if(s&&"isManualMapping"in s)return s.result;let a=s,c=new t;return sm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof Eo&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===it&&t.type===S.Choice&&e.idBlock.tagClass===3)for(let i in t.items){let s=t.items[i];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&Je.has(s.type)){let a=Je.get(s.type);if(a&&a.type===S.Sequence){let c=new Nt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let u=this.fromASN(c,s.type),p=new n;return p[i]=u,{result:p}}}}}else if(e.constructor===it&&t.type!==S.Choice){let i=new it({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(let s in t.items)delete e[s];return{targetSchema:i}}return null}static handleSequenceTypes(e,t,n,o){if(t.type===S.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&Je.has(c.type)&&Je.get(c.type).type===S.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=kn({},e,o);if(!s.verified)throw new Eo(`Data does not match to ${n.name} ASN1 schema.${s.result.error?` ${s.result.error}`:""}`);return s}else{let i=kn({},e,o);if(!i.verified)throw new Eo(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let u=s[c],p=t.items[u];if(a>=i.length)break;if(p.repeated){o[u]=this.processRepeatedField(i,a,p);break}else if(typeof p.type=="number")o[u]=this.processPrimitiveField(i[a],p),a++;else if(this.isOptionalChoiceField(p)){let l=this.processOptionalChoiceField(i[a],p);l.processed&&(o[u]=l.value,a++)}else o[u]=this.fromASN(i[a],p.type),a++}return{result:o,verified:!0,isManualMapping:!0}}static processRepeatedField(e,t,n){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){let i=o[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(o=i.valueBlock.value)}if(typeof n.type=="number"){let i=Ao(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return i.fromASN(s)}catch{return}}).filter(s=>s!==void 0)}else return o.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,t){let n=Ao(t.type);if(!n)throw new Error(`No converter for ASN.1 type ${t.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Je.has(e.type)&&Je.get(e.type).type===S.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof Eo&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,t,n){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let o=t.itemType;if(typeof o=="number"){let i=Ao(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type,c;typeof a=="number"||wr(a)?c=this.processPrimitiveSchemaItem(i,s,a):c=this.processComplexSchemaItem(i,s,a),c&&typeof c=="object"&&"value"in c&&"raw"in c?(n[o]=c.value,n[`${o}Raw`]=c.raw):n[o]=c}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:wr(n)?new n:null;if(!i)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,i):this.processSinglePrimitiveItem(e,t,n,i)}static processRepeatedPrimitiveItem(e,t,n){if(t.implicit){let o=t.repeated==="sequence"?Nt:Kt,i=new o;i.valueBlock=e.valueBlock;let s=Un(i.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let a=s.result.valueBlock.value;return Array.from(a,c=>n.fromASN(c))}else return Array.from(e,o=>n.fromASN(o))}static processSinglePrimitiveItem(e,t,n,o){let i=e;if(t.implicit){let s;if(wr(n))s=new n().toSchema("");else{let a=d[n],c=en[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Un(s.toBER(!1)).result}return o.fromASN(i)}static processComplexSchemaItem(e,t,n){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,n))}else{let o=this.handleImplicitTagging(e,t,n);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,n)}catch(i){if(i instanceof Eo&&/Wrong values for Choice type/.test(i.message))return;throw i}else{let i=this.fromASN(o,n);return t.raw?{value:i,raw:e.valueBeforeDecodeView}:i}}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=Je.get(n);if(o.type===S.Sequence){let i=new Nt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(o.type===S.Set){let i=new Kt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var zc=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"&&wr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Je.get(t);Je.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=Ao(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"&&dv(this.serialize(a.defaultValue),this.serialize(c)))continue;let u=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||wr(a.type))){let p={};p.valueHex=u instanceof jr?u.valueBeforeDecodeView:u.valueBlock.toBER(),o.push(new Rn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:u.valueBlock.value}));else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[u]}));else a.repeated?o=o.concat(u):o.push(u)}let i;switch(n.type){case S.Sequence:i=new Nt({value:o});break;case S.Set:i=new Kt({value:o});break;case S.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,u=>s.toASN(u)),c=e.repeated==="sequence"?Nt:Kt;i=new c({value:a})}else i=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let s=Array.from(o,c=>this.toASN(c)),a=e.repeated==="sequence"?Nt:Kt;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 am=Gr(Nn());var W=class r{static serialize(e){return zc.serialize(e)}static parse(e,t){return Gc.parse(e,t)}static toString(e){let t=am.BufferSourceConverter.isBufferSource(e)?am.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Un(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function b(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 yv=Gr(Nn()),Xc=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,u)=>c+(u.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(yv.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 mv=Gr(Nn()),cm,um,fm,st=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};b([f({type:d.TeletexString})],st.prototype,"teletexString",void 0);b([f({type:d.PrintableString})],st.prototype,"printableString",void 0);b([f({type:d.UniversalString})],st.prototype,"universalString",void 0);b([f({type:d.Utf8String})],st.prototype,"utf8String",void 0);b([f({type:d.BmpString})],st.prototype,"bmpString",void 0);st=b([T({type:S.Choice})],st);var Qs=class extends st{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?mv.Convert.ToHex(this.anyValue):super.toString())}};b([f({type:d.IA5String})],Qs.prototype,"ia5String",void 0);b([f({type:d.Any})],Qs.prototype,"anyValue",void 0);Qs=b([T({type:S.Choice})],Qs);var Pi=class{constructor(e={}){this.type="",this.value=new Qs,Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Pi.prototype,"type",void 0);b([f({type:Qs})],Pi.prototype,"value",void 0);var Co=cm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};Co=cm=b([T({type:S.Set,itemType:Pi})],Co);var lm=um=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};lm=um=b([T({type:S.Sequence,itemType:Co})],lm);var je=fm=class extends lm{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};je=fm=b([T({type:S.Sequence})],je);var ET={fromASN:r=>Xc.toString(Js.fromASN(r)),toASN:r=>Js.toASN(Xc.fromString(r))},To=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],To.prototype,"typeId",void 0);b([f({type:d.Any,context:0})],To.prototype,"value",void 0);var Zc=class{constructor(e={}){this.partyName=new st,Object.assign(this,e)}};b([f({type:st,optional:!0,context:0,implicit:!0})],Zc.prototype,"nameAssigner",void 0);b([f({type:st,context:1,implicit:!0})],Zc.prototype,"partyName",void 0);var ue=class{constructor(e={}){Object.assign(this,e)}};b([f({type:To,context:0,implicit:!0})],ue.prototype,"otherName",void 0);b([f({type:d.IA5String,context:1,implicit:!0})],ue.prototype,"rfc822Name",void 0);b([f({type:d.IA5String,context:2,implicit:!0})],ue.prototype,"dNSName",void 0);b([f({type:d.Any,context:3,implicit:!0})],ue.prototype,"x400Address",void 0);b([f({type:je,context:4,implicit:!1})],ue.prototype,"directoryName",void 0);b([f({type:Zc,context:5})],ue.prototype,"ediPartyName",void 0);b([f({type:d.IA5String,context:6,implicit:!0})],ue.prototype,"uniformResourceIdentifier",void 0);b([f({type:d.OctetString,context:7,implicit:!0,converter:ET})],ue.prototype,"iPAddress",void 0);b([f({type:d.ObjectIdentifier,context:8,implicit:!0})],ue.prototype,"registeredID",void 0);ue=b([T({type:S.Choice})],ue);var Bo="1.3.6.1.5.5.7",Io=`${Bo}.1`,gv=`${Bo}.2`,Ni=`${Bo}.3`,fp=`${Bo}.48`,x3=`${gv}.1`,v3=`${gv}.2`,pm=`${fp}.1`,hm=`${fp}.2`,dm=`${fp}.3`,ym=`${fp}.5`,pe="2.5.29";var mm,lp=`${Io}.1`,Mn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ue,Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Mn.prototype,"accessMethod",void 0);b([f({type:ue})],Mn.prototype,"accessLocation",void 0);var ki=mm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};ki=mm=b([T({type:S.Sequence,itemType:Mn})],ki);var pp=`${pe}.35`,Di=class extends ae{},rn=class{constructor(e={}){e&&Object.assign(this,e)}};b([f({type:Di,context:0,optional:!0,implicit:!0})],rn.prototype,"keyIdentifier",void 0);b([f({type:ue,context:1,optional:!0,implicit:!0,repeated:"sequence"})],rn.prototype,"authorityCertIssuer",void 0);b([f({type:d.Integer,context:2,optional:!0,implicit:!0,converter:we})],rn.prototype,"authorityCertSerialNumber",void 0);var hp=`${pe}.19`,Ri=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};b([f({type:d.Boolean,defaultValue:!1})],Ri.prototype,"cA",void 0);b([f({type:d.Integer,optional:!0})],Ri.prototype,"pathLenConstraint",void 0);var gm,qe=gm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};qe=gm=b([T({type:S.Sequence,itemType:ue})],qe);var bm,CT=`${pe}.29`,bv=bm=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,bm.prototype)}};bv=bm=b([T({type:S.Sequence})],bv);var wm,yp=`${pe}.32`,Q3=`${yp}.0`,Kn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};b([f({type:d.IA5String})],Kn.prototype,"ia5String",void 0);b([f({type:d.VisibleString})],Kn.prototype,"visibleString",void 0);b([f({type:d.BmpString})],Kn.prototype,"bmpString",void 0);b([f({type:d.Utf8String})],Kn.prototype,"utf8String",void 0);Kn=b([T({type:S.Choice})],Kn);var Yc=class{constructor(e={}){this.organization=new Kn,this.noticeNumbers=[],Object.assign(this,e)}};b([f({type:Kn})],Yc.prototype,"organization",void 0);b([f({type:d.Integer,repeated:"sequence"})],Yc.prototype,"noticeNumbers",void 0);var Jc=class{constructor(e={}){Object.assign(this,e)}};b([f({type:Yc,optional:!0})],Jc.prototype,"noticeRef",void 0);b([f({type:Kn,optional:!0})],Jc.prototype,"explicitText",void 0);var dp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.IA5String})],dp.prototype,"cPSuri",void 0);b([f({type:Jc})],dp.prototype,"userNotice",void 0);dp=b([T({type:S.Choice})],dp);var Qc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Qc.prototype,"policyQualifierId",void 0);b([f({type:d.Any})],Qc.prototype,"qualifier",void 0);var ji=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],ji.prototype,"policyIdentifier",void 0);b([f({type:Qc,repeated:"sequence",optional:!0})],ji.prototype,"policyQualifiers",void 0);var eu=wm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,wm.prototype)}};eu=wm=b([T({type:S.Sequence,itemType:ji})],eu);var aR=`${pe}.20`,tu=class{constructor(e=0){this.value=e}};b([f({type:d.Integer})],tu.prototype,"value",void 0);tu=b([T({type:S.Choice})],tu);var dR=`${pe}.27`,wv=class extends tu{};wv=b([T({type:S.Choice})],wv);var xm,mp=`${pe}.31`,Kr;(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"})(Kr||(Kr={}));var ru=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&Kr.aACompromise&&e.push("aACompromise"),t&Kr.affiliationChanged&&e.push("affiliationChanged"),t&Kr.cACompromise&&e.push("cACompromise"),t&Kr.certificateHold&&e.push("certificateHold"),t&Kr.cessationOfOperation&&e.push("cessationOfOperation"),t&Kr.keyCompromise&&e.push("keyCompromise"),t&Kr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Kr.superseded&&e.push("superseded"),t&Kr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Hn=class{constructor(e={}){Object.assign(this,e)}};b([f({type:ue,context:0,repeated:"sequence",implicit:!0})],Hn.prototype,"fullName",void 0);b([f({type:Co,context:1,implicit:!0})],Hn.prototype,"nameRelativeToCRLIssuer",void 0);Hn=b([T({type:S.Choice})],Hn);var nn=class{constructor(e={}){Object.assign(this,e)}};b([f({type:Hn,context:0,optional:!0})],nn.prototype,"distributionPoint",void 0);b([f({type:ru,context:1,optional:!0,implicit:!0})],nn.prototype,"reasons",void 0);b([f({type:ue,context:2,optional:!0,repeated:"sequence",implicit:!0})],nn.prototype,"cRLIssuer",void 0);var Oo=xm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};Oo=xm=b([T({type:S.Sequence,itemType:nn})],Oo);var vm,IR=`${pe}.46`,xv=vm=class extends Oo{constructor(e){super(e),Object.setPrototypeOf(this,vm.prototype)}};xv=vm=b([T({type:S.Sequence,itemType:nn})],xv);var LR=`${pe}.28`,ir=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};ir.ONLY=!1;b([f({type:Hn,context:0,optional:!0})],ir.prototype,"distributionPoint",void 0);b([f({type:d.Boolean,context:1,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsUserCerts",void 0);b([f({type:d.Boolean,context:2,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsCACerts",void 0);b([f({type:ru,context:3,optional:!0,implicit:!0})],ir.prototype,"onlySomeReasons",void 0);b([f({type:d.Boolean,context:4,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"indirectCRL",void 0);b([f({type:d.Boolean,context:5,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsAttributeCerts",void 0);var vv=`${pe}.21`,nu;(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"})(nu||(nu={}));var ou=class{constructor(e=nu.unspecified){this.reason=nu.unspecified,this.reason=e}toJSON(){return nu[this.reason]}toString(){return this.toJSON()}};b([f({type:d.Enumerated})],ou.prototype,"reason",void 0);ou=b([T({type:S.Choice})],ou);var _m,gp=`${pe}.37`,iu=_m=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};iu=_m=b([T({type:S.Sequence,itemType:d.ObjectIdentifier})],iu);var zR=`${gp}.0`,_v=`${Ni}.1`,Sv=`${Ni}.2`,Av=`${Ni}.3`,Ev=`${Ni}.4`,Cv=`${Ni}.8`,Tv=`${Ni}.9`;var QR=`${pe}.54`,Sm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};b([f({type:d.Integer,converter:we})],Sm.prototype,"value",void 0);Sm=b([T({type:S.Choice})],Sm);var Bv=`${pe}.24`,su=class{constructor(e){this.value=new Date,e&&(this.value=e)}};b([f({type:d.GeneralizedTime})],su.prototype,"value",void 0);su=b([T({type:S.Choice})],su);var Am,Em=`${pe}.18`,Iv=Am=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,Am.prototype)}};Iv=Am=b([T({type:S.Sequence})],Iv);var bp=`${pe}.15`,Hr;(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"})(Hr||(Hr={}));var ea=class extends tn{toJSON(){let e=this.toNumber(),t=[];return e&Hr.cRLSign&&t.push("crlSign"),e&Hr.dataEncipherment&&t.push("dataEncipherment"),e&Hr.decipherOnly&&t.push("decipherOnly"),e&Hr.digitalSignature&&t.push("digitalSignature"),e&Hr.encipherOnly&&t.push("encipherOnly"),e&Hr.keyAgreement&&t.push("keyAgreement"),e&Hr.keyCertSign&&t.push("keyCertSign"),e&Hr.keyEncipherment&&t.push("keyEncipherment"),e&Hr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var Cm,xj=`${pe}.30`,ta=class{constructor(e={}){this.base=new ue,this.minimum=0,Object.assign(this,e)}};b([f({type:ue})],ta.prototype,"base",void 0);b([f({type:d.Integer,context:0,defaultValue:0,implicit:!0})],ta.prototype,"minimum",void 0);b([f({type:d.Integer,context:1,optional:!0,implicit:!0})],ta.prototype,"maximum",void 0);var wp=Cm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Cm.prototype)}};wp=Cm=b([T({type:S.Sequence,itemType:ta})],wp);var xp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:wp,context:0,optional:!0,implicit:!0})],xp.prototype,"permittedSubtrees",void 0);b([f({type:wp,context:1,optional:!0,implicit:!0})],xp.prototype,"excludedSubtrees",void 0);var Cj=`${pe}.36`,vp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.Integer,context:0,implicit:!0,optional:!0,converter:we})],vp.prototype,"requireExplicitPolicy",void 0);b([f({type:d.Integer,context:1,implicit:!0,optional:!0,converter:we})],vp.prototype,"inhibitPolicyMapping",void 0);var Tm,Pj=`${pe}.33`,au=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],au.prototype,"issuerDomainPolicy",void 0);b([f({type:d.ObjectIdentifier})],au.prototype,"subjectDomainPolicy",void 0);var Ov=Tm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Tm.prototype)}};Ov=Tm=b([T({type:S.Sequence,itemType:au})],Ov);var Bm,Im=`${pe}.17`,_p=Bm=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,Bm.prototype)}};_p=Bm=b([T({type:S.Sequence})],_p);var wt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],wt.prototype,"type",void 0);b([f({type:d.Any,repeated:"set"})],wt.prototype,"values",void 0);var Om,Gj=`${pe}.9`,Pv=Om=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Om.prototype)}};Pv=Om=b([T({type:S.Sequence,itemType:wt})],Pv);var Pm=`${pe}.14`,zt=class extends Di{};var rL=`${pe}.16`,Sp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],Sp.prototype,"notBefore",void 0);b([f({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],Sp.prototype,"notAfter",void 0);var cu;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(cu||(cu={}));var Ap=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&cu.pKIXCertificate&&e.push("pKIXCertificate"),t&cu.newExtensions&&e.push("newExtensions"),t&cu.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Ep=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Ap,Object.assign(this,e)}};b([f({type:d.GeneralString})],Ep.prototype,"entrustVers",void 0);b([f({type:Ap})],Ep.prototype,"entrustInfoFlags",void 0);var Nm,lL=`${Io}.11`,Nv=Nm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Nm.prototype)}};Nv=Nm=b([T({type:S.Sequence,itemType:Mn})],Nv);var kv=Gr(Nn()),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&&kv.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};b([f({type:d.ObjectIdentifier})],M.prototype,"algorithm",void 0);b([f({type:d.Any,optional:!0})],M.prototype,"parameters",void 0);var xt=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:M})],xt.prototype,"algorithm",void 0);b([f({type:d.BitString})],xt.prototype,"subjectPublicKey",void 0);var Qe=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};b([f({type:d.UTCTime})],Qe.prototype,"utcTime",void 0);b([f({type:d.GeneralizedTime})],Qe.prototype,"generalTime",void 0);Qe=b([T({type:S.Choice})],Qe);var Vn=class{constructor(e){this.notBefore=new Qe(new Date),this.notAfter=new Qe(new Date),e&&(this.notBefore=new Qe(e.notBefore),this.notAfter=new Qe(e.notAfter))}};b([f({type:Qe})],Vn.prototype,"notBefore",void 0);b([f({type:Qe})],Vn.prototype,"notAfter",void 0);var km,vt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};vt.CRITICAL=!1;b([f({type:d.ObjectIdentifier})],vt.prototype,"extnID",void 0);b([f({type:d.Boolean,defaultValue:vt.CRITICAL})],vt.prototype,"critical",void 0);b([f({type:ae})],vt.prototype,"extnValue",void 0);var sr=km=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,km.prototype)}};sr=km=b([T({type:S.Sequence,itemType:vt})],sr);var on;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(on||(on={}));var _t=class{constructor(e={}){this.version=on.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new je,this.validity=new Vn,this.subject=new je,this.subjectPublicKeyInfo=new xt,Object.assign(this,e)}};b([f({type:d.Integer,context:0,defaultValue:on.v1})],_t.prototype,"version",void 0);b([f({type:d.Integer,converter:we})],_t.prototype,"serialNumber",void 0);b([f({type:M})],_t.prototype,"signature",void 0);b([f({type:je})],_t.prototype,"issuer",void 0);b([f({type:Vn})],_t.prototype,"validity",void 0);b([f({type:je})],_t.prototype,"subject",void 0);b([f({type:xt})],_t.prototype,"subjectPublicKeyInfo",void 0);b([f({type:d.BitString,context:1,implicit:!0,optional:!0})],_t.prototype,"issuerUniqueID",void 0);b([f({type:d.BitString,context:2,implicit:!0,optional:!0})],_t.prototype,"subjectUniqueID",void 0);b([f({type:sr,context:3,optional:!0})],_t.prototype,"extensions",void 0);var xr=class{constructor(e={}){this.tbsCertificate=new _t,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:_t,raw:!0})],xr.prototype,"tbsCertificate",void 0);b([f({type:M})],xr.prototype,"signatureAlgorithm",void 0);b([f({type:d.BitString})],xr.prototype,"signatureValue",void 0);var Li=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Qe,Object.assign(this,e)}};b([f({type:d.Integer,converter:we})],Li.prototype,"userCertificate",void 0);b([f({type:Qe})],Li.prototype,"revocationDate",void 0);b([f({type:vt,optional:!0,repeated:"sequence"})],Li.prototype,"crlEntryExtensions",void 0);var ar=class{constructor(e={}){this.signature=new M,this.issuer=new je,this.thisUpdate=new Qe,Object.assign(this,e)}};b([f({type:d.Integer,optional:!0})],ar.prototype,"version",void 0);b([f({type:M})],ar.prototype,"signature",void 0);b([f({type:je})],ar.prototype,"issuer",void 0);b([f({type:Qe})],ar.prototype,"thisUpdate",void 0);b([f({type:Qe,optional:!0})],ar.prototype,"nextUpdate",void 0);b([f({type:Li,repeated:"sequence",optional:!0})],ar.prototype,"revokedCertificates",void 0);b([f({type:vt,optional:!0,context:0,repeated:"sequence"})],ar.prototype,"crlExtensions",void 0);var Ui=class{constructor(e={}){this.tbsCertList=new ar,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:ar,raw:!0})],Ui.prototype,"tbsCertList",void 0);b([f({type:M})],Ui.prototype,"signatureAlgorithm",void 0);b([f({type:d.BitString})],Ui.prototype,"signature",void 0);var H=Gr(Nn());function uu(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}function de(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)}function Ge(r,e,t,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!o:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(r,t):o?o.value=t:e.set(r,t),t}function O(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 Vr=class{constructor(e={}){this.issuer=new je,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:je})],Vr.prototype,"issuer",void 0);O([f({type:d.Integer,converter:we})],Vr.prototype,"serialNumber",void 0);var Mi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0})],Mi.prototype,"subjectKeyIdentifier",void 0);O([f({type:Vr})],Mi.prototype,"issuerAndSerialNumber",void 0);Mi=O([T({type:S.Choice})],Mi);var St;(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"})(St||(St={}));var Ki=class extends M{};Ki=O([T({type:S.Sequence})],Ki);var fu=class extends M{};fu=O([T({type:S.Sequence})],fu);var Xt=class extends M{};Xt=O([T({type:S.Sequence})],Xt);var lu=class extends M{};lu=O([T({type:S.Sequence})],lu);var Rv=class extends M{};Rv=O([T({type:S.Sequence})],Rv);var Cp=class extends M{};Cp=O([T({type:S.Sequence})],Cp);var $r=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],$r.prototype,"attrType",void 0);O([f({type:d.Any,repeated:"set"})],$r.prototype,"attrValues",void 0);var Dm,Zt=class{constructor(e={}){this.version=St.v0,this.sid=new Mi,this.digestAlgorithm=new Ki,this.signatureAlgorithm=new fu,this.signature=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Zt.prototype,"version",void 0);O([f({type:Mi})],Zt.prototype,"sid",void 0);O([f({type:Ki})],Zt.prototype,"digestAlgorithm",void 0);O([f({type:$r,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],Zt.prototype,"signedAttrs",void 0);O([f({type:fu})],Zt.prototype,"signatureAlgorithm",void 0);O([f({type:ae})],Zt.prototype,"signature",void 0);O([f({type:$r,repeated:"set",context:1,implicit:!0,optional:!0})],Zt.prototype,"unsignedAttrs",void 0);var pu=Dm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Dm.prototype)}};pu=Dm=O([T({type:S.Set,itemType:Zt})],pu);var jv=class extends Qe{};jv=O([T({type:S.Choice})],jv);var Lv=class extends Zt{};Lv=O([T({type:S.Sequence})],Lv);function G(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 hu=class{constructor(e={}){this.acIssuer=new ue,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};G([f({type:ue})],hu.prototype,"acIssuer",void 0);G([f({type:d.Integer})],hu.prototype,"acSerial",void 0);G([f({type:wt,repeated:"sequence"})],hu.prototype,"attrs",void 0);var Rm,du=Rm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Rm.prototype)}};du=Rm=G([T({type:S.Sequence,itemType:d.ObjectIdentifier})],du);var ra=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};G([f({type:d.Integer,optional:!0})],ra.prototype,"pathLenConstraint",void 0);G([f({type:du,implicit:!0,context:0,optional:!0})],ra.prototype,"permittedAttrs",void 0);G([f({type:du,implicit:!0,context:1,optional:!0})],ra.prototype,"excludedAttrs",void 0);G([f({type:d.Boolean,defaultValue:!0})],ra.prototype,"permitUnSpecified",void 0);var vr=class{constructor(e={}){this.issuer=new qe,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:qe})],vr.prototype,"issuer",void 0);G([f({type:d.Integer,converter:we})],vr.prototype,"serial",void 0);G([f({type:d.BitString,optional:!0})],vr.prototype,"issuerUID",void 0);var jm;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(jm||(jm={}));var _r=class{constructor(e={}){this.digestedObjectType=jm.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:d.Enumerated})],_r.prototype,"digestedObjectType",void 0);G([f({type:d.ObjectIdentifier,optional:!0})],_r.prototype,"otherObjectTypeID",void 0);G([f({type:M})],_r.prototype,"digestAlgorithm",void 0);G([f({type:d.BitString})],_r.prototype,"objectDigest",void 0);var Hi=class{constructor(e={}){Object.assign(this,e)}};G([f({type:qe,optional:!0})],Hi.prototype,"issuerName",void 0);G([f({type:vr,context:0,implicit:!0,optional:!0})],Hi.prototype,"baseCertificateID",void 0);G([f({type:_r,context:1,implicit:!0,optional:!0})],Hi.prototype,"objectDigestInfo",void 0);var Vi=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ue,repeated:"sequence"})],Vi.prototype,"v1Form",void 0);G([f({type:Hi,context:0,implicit:!0})],Vi.prototype,"v2Form",void 0);Vi=G([T({type:S.Choice})],Vi);var $i=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};G([f({type:d.GeneralizedTime})],$i.prototype,"notBeforeTime",void 0);G([f({type:d.GeneralizedTime})],$i.prototype,"notAfterTime",void 0);var Po=class{constructor(e={}){Object.assign(this,e)}};G([f({type:vr,implicit:!0,context:0,optional:!0})],Po.prototype,"baseCertificateID",void 0);G([f({type:qe,implicit:!0,context:1,optional:!0})],Po.prototype,"entityName",void 0);G([f({type:_r,implicit:!0,context:2,optional:!0})],Po.prototype,"objectDigestInfo",void 0);var Lm;(function(r){r[r.v2=1]="v2"})(Lm||(Lm={}));var Yt=class{constructor(e={}){this.version=Lm.v2,this.holder=new Po,this.issuer=new Vi,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new $i,this.attributes=[],Object.assign(this,e)}};G([f({type:d.Integer})],Yt.prototype,"version",void 0);G([f({type:Po})],Yt.prototype,"holder",void 0);G([f({type:Vi})],Yt.prototype,"issuer",void 0);G([f({type:M})],Yt.prototype,"signature",void 0);G([f({type:d.Integer,converter:we})],Yt.prototype,"serialNumber",void 0);G([f({type:$i})],Yt.prototype,"attrCertValidityPeriod",void 0);G([f({type:wt,repeated:"sequence"})],Yt.prototype,"attributes",void 0);G([f({type:d.BitString,optional:!0})],Yt.prototype,"issuerUniqueID",void 0);G([f({type:sr,optional:!0})],Yt.prototype,"extensions",void 0);var Fi=class{constructor(e={}){this.acinfo=new Yt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:Yt})],Fi.prototype,"acinfo",void 0);G([f({type:M})],Fi.prototype,"signatureAlgorithm",void 0);G([f({type:d.BitString})],Fi.prototype,"signatureValue",void 0);var yu;(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"})(yu||(yu={}));var na=class extends tn{};var oa=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:d.ObjectIdentifier,implicit:!0,context:0})],oa.prototype,"type",void 0);G([f({type:d.Any,implicit:!0,context:1})],oa.prototype,"value",void 0);var mu=class{constructor(e={}){this.policyId="",this.classList=new na(yu.unclassified),Object.assign(this,e)}};G([f({type:d.ObjectIdentifier})],mu.prototype,"policyId",void 0);G([f({type:na,defaultValue:new na(yu.unclassified)})],mu.prototype,"classList",void 0);G([f({type:oa,repeated:"set"})],mu.prototype,"securityCategories",void 0);var ia=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ae})],ia.prototype,"cotets",void 0);G([f({type:d.ObjectIdentifier})],ia.prototype,"oid",void 0);G([f({type:d.Utf8String})],ia.prototype,"string",void 0);var Tp=class{constructor(e={}){this.values=[],Object.assign(this,e)}};G([f({type:qe,implicit:!0,context:0,optional:!0})],Tp.prototype,"policyAuthority",void 0);G([f({type:ia,repeated:"sequence"})],Tp.prototype,"values",void 0);var z9=`${Io}.4`,X9=`${Io}.6`,Z9=`${Io}.10`,Y9=`${pe}.55`,gu=`${Bo}.10`,J9=`${gu}.1`,Q9=`${gu}.2`,eK=`${gu}.3`,tK=`${gu}.4`,rK=`${gu}.6`,Um="2.5.4",nK=`${Um}.72`;var Mm,sa=class{constructor(e={}){this.targetCertificate=new vr,Object.assign(this,e)}};G([f({type:vr})],sa.prototype,"targetCertificate",void 0);G([f({type:ue,optional:!0})],sa.prototype,"targetName",void 0);G([f({type:_r,optional:!0})],sa.prototype,"certDigestInfo",void 0);var aa=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ue,context:0,implicit:!0})],aa.prototype,"targetName",void 0);G([f({type:ue,context:1,implicit:!0})],aa.prototype,"targetGroup",void 0);G([f({type:sa,context:2,implicit:!0})],aa.prototype,"targetCert",void 0);aa=G([T({type:S.Choice})],aa);var Bp=Mm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};Bp=Mm=G([T({type:S.Sequence,itemType:aa})],Bp);var Km,Uv=Km=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Km.prototype)}};Uv=Km=G([T({type:S.Sequence,itemType:Bp})],Uv);var Ip=class{constructor(e={}){Object.assign(this,e)}};G([f({type:qe,implicit:!0,context:0,optional:!0})],Ip.prototype,"roleAuthority",void 0);G([f({type:ue,implicit:!0,context:1})],Ip.prototype,"roleName",void 0);var bu=class{constructor(e={}){this.service=new ue,this.ident=new ue,Object.assign(this,e)}};G([f({type:ue})],bu.prototype,"service",void 0);G([f({type:ue})],bu.prototype,"ident",void 0);G([f({type:ae,optional:!0})],bu.prototype,"authInfo",void 0);var Hm,wu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],wu.prototype,"otherCertFormat",void 0);O([f({type:d.Any})],wu.prototype,"otherCert",void 0);var Wi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:xr})],Wi.prototype,"certificate",void 0);O([f({type:Fi,context:2,implicit:!0})],Wi.prototype,"v2AttrCert",void 0);O([f({type:wu,context:3,implicit:!0})],Wi.prototype,"other",void 0);Wi=O([T({type:S.Choice})],Wi);var qi=Hm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Hm.prototype)}};qi=Hm=O([T({type:S.Set,itemType:Wi})],qi);var Sr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Sr.prototype,"contentType",void 0);O([f({type:d.Any,context:0})],Sr.prototype,"content",void 0);var ca=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ae})],ca.prototype,"single",void 0);O([f({type:d.Any})],ca.prototype,"any",void 0);ca=O([T({type:S.Choice})],ca);var Gi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Gi.prototype,"eContentType",void 0);O([f({type:ca,context:0,optional:!0})],Gi.prototype,"eContent",void 0);var xu=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ae,context:0,implicit:!0,optional:!0})],xu.prototype,"value",void 0);O([f({type:ae,converter:hv,context:0,implicit:!0,optional:!0,repeated:"sequence"})],xu.prototype,"constructedValue",void 0);xu=O([T({type:S.Choice})],xu);var No=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new lu,Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],No.prototype,"contentType",void 0);O([f({type:lu})],No.prototype,"contentEncryptionAlgorithm",void 0);O([f({type:xu,optional:!0})],No.prototype,"encryptedContent",void 0);var ko=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],ko.prototype,"keyAttrId",void 0);O([f({type:d.Any,optional:!0})],ko.prototype,"keyAttr",void 0);var Vm,ua=class{constructor(e={}){this.subjectKeyIdentifier=new zt,Object.assign(this,e)}};O([f({type:zt})],ua.prototype,"subjectKeyIdentifier",void 0);O([f({type:d.GeneralizedTime,optional:!0})],ua.prototype,"date",void 0);O([f({type:ko,optional:!0})],ua.prototype,"other",void 0);var fa=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ua,context:0,implicit:!0,optional:!0})],fa.prototype,"rKeyId",void 0);O([f({type:Vr,optional:!0})],fa.prototype,"issuerAndSerialNumber",void 0);fa=O([T({type:S.Choice})],fa);var vu=class{constructor(e={}){this.rid=new fa,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:fa})],vu.prototype,"rid",void 0);O([f({type:ae})],vu.prototype,"encryptedKey",void 0);var Op=Vm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Vm.prototype)}};Op=Vm=O([T({type:S.Sequence,itemType:vu})],Op);var _u=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:M})],_u.prototype,"algorithm",void 0);O([f({type:d.BitString})],_u.prototype,"publicKey",void 0);var zi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0,optional:!0})],zi.prototype,"subjectKeyIdentifier",void 0);O([f({type:_u,context:1,implicit:!0,optional:!0})],zi.prototype,"originatorKey",void 0);O([f({type:Vr,optional:!0})],zi.prototype,"issuerAndSerialNumber",void 0);zi=O([T({type:S.Choice})],zi);var $n=class{constructor(e={}){this.version=St.v3,this.originator=new zi,this.keyEncryptionAlgorithm=new Xt,this.recipientEncryptedKeys=new Op,Object.assign(this,e)}};O([f({type:d.Integer})],$n.prototype,"version",void 0);O([f({type:zi,context:0})],$n.prototype,"originator",void 0);O([f({type:ae,context:1,optional:!0})],$n.prototype,"ukm",void 0);O([f({type:Xt})],$n.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:Op})],$n.prototype,"recipientEncryptedKeys",void 0);var la=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0})],la.prototype,"subjectKeyIdentifier",void 0);O([f({type:Vr})],la.prototype,"issuerAndSerialNumber",void 0);la=O([T({type:S.Choice})],la);var Do=class{constructor(e={}){this.version=St.v0,this.rid=new la,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Do.prototype,"version",void 0);O([f({type:la})],Do.prototype,"rid",void 0);O([f({type:Xt})],Do.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],Do.prototype,"encryptedKey",void 0);var Xi=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};O([f({type:ae})],Xi.prototype,"keyIdentifier",void 0);O([f({type:d.GeneralizedTime,optional:!0})],Xi.prototype,"date",void 0);O([f({type:ko,optional:!0})],Xi.prototype,"other",void 0);var Ro=class{constructor(e={}){this.version=St.v4,this.kekid=new Xi,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Ro.prototype,"version",void 0);O([f({type:Xi})],Ro.prototype,"kekid",void 0);O([f({type:Xt})],Ro.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],Ro.prototype,"encryptedKey",void 0);var jo=class{constructor(e={}){this.version=St.v0,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],jo.prototype,"version",void 0);O([f({type:Cp,context:0,optional:!0})],jo.prototype,"keyDerivationAlgorithm",void 0);O([f({type:Xt})],jo.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],jo.prototype,"encryptedKey",void 0);var Su=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Su.prototype,"oriType",void 0);O([f({type:d.Any})],Su.prototype,"oriValue",void 0);var Fn=class{constructor(e={}){Object.assign(this,e)}};O([f({type:Do,optional:!0})],Fn.prototype,"ktri",void 0);O([f({type:$n,context:1,implicit:!0,optional:!0})],Fn.prototype,"kari",void 0);O([f({type:Ro,context:2,implicit:!0,optional:!0})],Fn.prototype,"kekri",void 0);O([f({type:jo,context:3,implicit:!0,optional:!0})],Fn.prototype,"pwri",void 0);O([f({type:Su,context:4,implicit:!0,optional:!0})],Fn.prototype,"ori",void 0);Fn=O([T({type:S.Choice})],Fn);var $m,Au=$m=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,$m.prototype)}};Au=$m=O([T({type:S.Set,itemType:Fn})],Au);var Fm,Mv=`${Bo}.16`,rV=`${Mv}.2`,nV=`${Mv}.4`,pa=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],pa.prototype,"otherRevInfoFormat",void 0);O([f({type:d.Any})],pa.prototype,"otherRevInfo",void 0);var Pp=class{constructor(e={}){this.other=new pa,Object.assign(this,e)}};O([f({type:pa,context:1,implicit:!0})],Pp.prototype,"other",void 0);Pp=O([T({type:S.Choice})],Pp);var ha=Fm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Fm.prototype)}};ha=Fm=O([T({type:S.Set,itemType:Pp})],ha);var da=class{constructor(e={}){Object.assign(this,e)}};O([f({type:qi,context:0,implicit:!0,optional:!0})],da.prototype,"certs",void 0);O([f({type:ha,context:1,implicit:!0,optional:!0})],da.prototype,"crls",void 0);var Wm,qm=Wm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Wm.prototype)}};qm=Wm=O([T({type:S.Set,itemType:$r})],qm);var Zi=class{constructor(e={}){this.version=St.v0,this.recipientInfos=new Au,this.encryptedContentInfo=new No,Object.assign(this,e)}};O([f({type:d.Integer})],Zi.prototype,"version",void 0);O([f({type:da,context:0,implicit:!0,optional:!0})],Zi.prototype,"originatorInfo",void 0);O([f({type:Au})],Zi.prototype,"recipientInfos",void 0);O([f({type:No})],Zi.prototype,"encryptedContentInfo",void 0);O([f({type:qm,context:1,implicit:!0,optional:!0})],Zi.prototype,"unprotectedAttrs",void 0);var Kv="1.2.840.113549.1.7.2";var Gm,Np=Gm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};Np=Gm=O([T({type:S.Set,itemType:Ki})],Np);var Wn=class{constructor(e={}){this.version=St.v0,this.digestAlgorithms=new Np,this.encapContentInfo=new Gi,this.signerInfos=new pu,Object.assign(this,e)}};O([f({type:d.Integer})],Wn.prototype,"version",void 0);O([f({type:Np})],Wn.prototype,"digestAlgorithms",void 0);O([f({type:Gi})],Wn.prototype,"encapContentInfo",void 0);O([f({type:qi,context:0,implicit:!0,optional:!0})],Wn.prototype,"certificates",void 0);O([f({type:ha,context:1,implicit:!0,optional:!0})],Wn.prototype,"crls",void 0);O([f({type:pu})],Wn.prototype,"signerInfos",void 0);var Yi="1.2.840.10045.2.1";var Eu="1.2.840.10045.4.1",kp="1.2.840.10045.4.3.1",Cu="1.2.840.10045.4.3.2",Tu="1.2.840.10045.4.3.3",Bu="1.2.840.10045.4.3.4";var zm="1.2.840.10045.3.1.7";var Xm="1.3.132.0.34";var Zm="1.3.132.0.35";function Iu(r){return new M({algorithm:r})}var Vv=Iu(Eu),QV=Iu(kp),$v=Iu(Cu),Fv=Iu(Tu),Wv=Iu(Bu);function Le(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)}};Le([f({type:d.ObjectIdentifier})],Ou.prototype,"fieldType",void 0);Le([f({type:d.Any})],Ou.prototype,"parameters",void 0);Ou=Le([T({type:S.Sequence})],Ou);var Ym=class extends ae{};var ya=class{constructor(e={}){Object.assign(this,e)}};Le([f({type:d.OctetString})],ya.prototype,"a",void 0);Le([f({type:d.OctetString})],ya.prototype,"b",void 0);Le([f({type:d.BitString,optional:!0})],ya.prototype,"seed",void 0);ya=Le([T({type:S.Sequence})],ya);var Jm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Jm||(Jm={}));var sn=class{constructor(e={}){this.version=Jm.ecpVer1,Object.assign(this,e)}};Le([f({type:d.Integer})],sn.prototype,"version",void 0);Le([f({type:Ou})],sn.prototype,"fieldID",void 0);Le([f({type:ya})],sn.prototype,"curve",void 0);Le([f({type:Ym})],sn.prototype,"base",void 0);Le([f({type:d.Integer,converter:we})],sn.prototype,"order",void 0);Le([f({type:d.Integer,optional:!0})],sn.prototype,"cofactor",void 0);sn=Le([T({type:S.Sequence})],sn);var an=class{constructor(e={}){Object.assign(this,e)}};Le([f({type:d.ObjectIdentifier})],an.prototype,"namedCurve",void 0);Le([f({type:d.Null})],an.prototype,"implicitCurve",void 0);Le([f({type:sn})],an.prototype,"specifiedCurve",void 0);an=Le([T({type:S.Choice})],an);var ma=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};Le([f({type:d.Integer})],ma.prototype,"version",void 0);Le([f({type:ae})],ma.prototype,"privateKey",void 0);Le([f({type:an,context:0,optional:!0})],ma.prototype,"parameters",void 0);Le([f({type:d.BitString,context:1,optional:!0})],ma.prototype,"publicKey",void 0);var Ji=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Le([f({type:d.Integer,converter:we})],Ji.prototype,"r",void 0);Le([f({type:d.Integer,converter:we})],Ji.prototype,"s",void 0);function Ne(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",cn=`${Jt}.1`,qv=`${Jt}.7`,Gv=`${Jt}.9`,Lo=`${Jt}.10`,zv=`${Jt}.2`,Xv=`${Jt}.4`,ga=`${Jt}.5`,Zv=`${Jt}.14`;var Dp=`${Jt}.11`,ba=`${Jt}.12`,wa=`${Jt}.13`,Qm=`${Jt}.15`,eg=`${Jt}.16`,Qi="1.3.14.3.2.26",Rp="2.16.840.1.101.3.4.2.4",es="2.16.840.1.101.3.4.2.1",ts="2.16.840.1.101.3.4.2.2",rs="2.16.840.1.101.3.4.2.3",Yv="2.16.840.1.101.3.4.2.5",Jv="2.16.840.1.101.3.4.2.6",Qv="1.2.840.113549.2.2",e1="1.2.840.113549.2.5",Uo=`${Jt}.8`;function lt(r){return new M({algorithm:r,parameters:null})}var I$=lt(Qv),O$=lt(e1),qn=lt(Qi),P$=lt(Rp),N$=lt(es),k$=lt(ts),D$=lt(rs),R$=lt(Yv),j$=lt(Jv),jp=new M({algorithm:Uo,parameters:W.serialize(qn)}),tg=new M({algorithm:Gv,parameters:W.serialize(Js.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),L$=lt(cn),U$=lt(zv),M$=lt(Xv),K$=lt(ga),H$=lt(Qm),V$=lt(eg),$$=lt(ba),F$=lt(wa),W$=lt(Qm),q$=lt(eg);var xa=class{constructor(e={}){this.hashAlgorithm=new M(qn),this.maskGenAlgorithm=new M({algorithm:Uo,parameters:W.serialize(qn)}),this.pSourceAlgorithm=new M(tg),Object.assign(this,e)}};Ne([f({type:M,context:0,defaultValue:qn})],xa.prototype,"hashAlgorithm",void 0);Ne([f({type:M,context:1,defaultValue:jp})],xa.prototype,"maskGenAlgorithm",void 0);Ne([f({type:M,context:2,defaultValue:tg})],xa.prototype,"pSourceAlgorithm",void 0);var Q$=new M({algorithm:qv,parameters:W.serialize(new xa)});var un=class{constructor(e={}){this.hashAlgorithm=new M(qn),this.maskGenAlgorithm=new M({algorithm:Uo,parameters:W.serialize(qn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Ne([f({type:M,context:0,defaultValue:qn})],un.prototype,"hashAlgorithm",void 0);Ne([f({type:M,context:1,defaultValue:jp})],un.prototype,"maskGenAlgorithm",void 0);Ne([f({type:d.Integer,context:2,defaultValue:20})],un.prototype,"saltLength",void 0);Ne([f({type:d.Integer,context:3,defaultValue:1})],un.prototype,"trailerField",void 0);var s7=new M({algorithm:Lo,parameters:W.serialize(new un)});var ns=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ae,Object.assign(this,e)}};Ne([f({type:M})],ns.prototype,"digestAlgorithm",void 0);Ne([f({type:ae})],ns.prototype,"digest",void 0);var rg,va=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Ne([f({type:d.Integer,converter:we})],va.prototype,"prime",void 0);Ne([f({type:d.Integer,converter:we})],va.prototype,"exponent",void 0);Ne([f({type:d.Integer,converter:we})],va.prototype,"coefficient",void 0);var Lp=rg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,rg.prototype)}};Lp=rg=Ne([T({type:S.Sequence,itemType:va})],Lp);var Ar=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)}};Ne([f({type:d.Integer})],Ar.prototype,"version",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"modulus",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"publicExponent",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"privateExponent",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"prime1",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"prime2",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"exponent1",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"exponent2",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"coefficient",void 0);Ne([f({type:Lp,optional:!0})],Ar.prototype,"otherPrimeInfos",void 0);var _a=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Ne([f({type:d.Integer,converter:we})],_a.prototype,"modulus",void 0);Ne([f({type:d.Integer,converter:we})],_a.prototype,"publicExponent",void 0);var ng;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(ng||(ng={}));var At=ng;var _1=Gr(v1(),1),{__extends:Aa,__assign:L7,__rest:NT,__decorate:U7,__param:M7,__metadata:K7,__awaiter:S1,__generator:A1,__exportStar:H7,__createBinding:V7,__values:Pu,__read:Nu,__spread:Fr,__spreadArrays:$7,__await:F7,__asyncGenerator:W7,__asyncDelegator:q7,__asyncValues:G7,__makeTemplateObject:z7,__importStar:X7,__importDefault:Z7,__classPrivateFieldGet:Y7,__classPrivateFieldSet:J7}=_1.default;var kT="injectionTokens";function ig(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(kT,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function ku(r){return!!r.useClass}function Ea(r){return!!r.useFactory}var Kp=(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,Fr(i))}};return this.reflectMethods.forEach(n),t},r})();function Mo(r){return typeof r=="string"||typeof r=="symbol"}function sg(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Hp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function E1(r){return typeof r=="function"||r instanceof Kp}function os(r){return!!r.useToken}function is(r){return r.useValue!=null}function C1(r){return ku(r)||is(r)||os(r)||Ea(r)}var DT=(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})(),Du=DT;var RT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du),T1=RT;var jT=(function(){function r(){this.scopedResolutions=new Map}return r})(),Ru=jT;function LT(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function UT(r,e,t){return t===void 0&&(t=" "),Fr([r],e.message.split(`
|
6
|
+
`)}`:`${t} :`}};Lx=it;J.Constructed=Lx;it.NAME="CONSTRUCTED";var Yl=class extends bt{fromBER(e,t,n){return t}toBER(e){return Mr}};Yl.override="EndOfContentValueBlock";var Ux,Lc=class extends ot{constructor(e={}){super(e,Yl),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ux=Lc;J.EndOfContent=Ux;Lc.NAME=Rc;var Mx,jr=class extends ot{constructor(e={}){super(e,bt),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}`}};Mx=jr;J.Null=Mx;jr.NAME="NULL";var Jl=class extends Qr(bt){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 Ln(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,Yy.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Jl.NAME="BooleanValueBlock";var Kx,mi=class extends ot{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Jl),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Kx=mi;J.Boolean=Kx;mi.NAME="BOOLEAN";var Ql=class extends Qr(Yr){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=Yr.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===Rc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==kx)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?Yr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ql.NAME="OctetStringValueBlock";var tm,Lr=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},Ql),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=Ys(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);let e=this.constructor.NAME,t=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 tm&&e.push(t.valueBlock.valueHexView);return ge.BufferSourceConverter.concat(e)}};tm=Lr;J.OctetString=tm;Lr.NAME=kx;var ep=class extends Qr(Yr){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=Yr.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===Rc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Dx)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return o}let i=ge.BufferSourceConverter.toUint8Array(e);if(!Ln(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=Ys(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 Yr.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Mr;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}}};ep.NAME="BitStringValueBlock";var Hx,Ur=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},ep),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return it.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let s of t)e.push(s.toString(2).padStart(8,"0"));let n=e.join(""),o=this.constructor.NAME,i=n.substring(0,n.length-this.valueBlock.unusedBits);return`${o} : ${i}`}}};Hx=Ur;J.BitString=Hx;Ur.NAME=Dx;var Vx;function rT(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,u=0,p=c<s?s:c,l=0;for(let h=p;h>=0;h--,l++){switch(!0){case l<a.length:u=i[s-l]+a[c-l]+t[0];break;default:u=i[s-l]+t[0]}switch(t[0]=u/10,!0){case l>=i.length:i=ql(new Uint8Array([u%10]),i);break;default:i[s-l]=u%10}}return t[0]>0&&(i=ql(t,i)),i}function Nx(r){if(r>=kc.length)for(let e=kc.length;e<=r;e++){let t=new Uint8Array([0]),n=kc[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)),kc.push(n)}return kc[r]}function nT(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,u,p=0;for(let l=c;l>=0;l--,p++)switch(u=i[s-p]-a[c-p]-t,!0){case u<0:t=1,i[s-p]=u+10;break;default:t=0,i[s-p]=u}if(t>0)for(let l=s-c+1;l>=0;l--,p++)if(u=i[s-p]-t,u<0)t=1,i[s-p]=u+10;else{t=0,i[s-p]=u;break}return i.slice()}var Uc=class extends Qr(bt){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=Yy.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(Bx(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 u=0;u<8;u++){if((o&1)===1)switch(n){case e:t=nT(Nx(n),t),s="-";break;default:t=rT(t,Nx(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Ox.charAt(t[c]));return a===!1&&(s+=Ox.charAt(0)),s}};Vx=Uc;Uc.NAME="IntegerValueBlock";Object.defineProperty(Vx.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Dc,jn=class extends ot{constructor(e={}){super(e,Uc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Gl(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Gl();let t=BigInt(e),n=new Xs,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 u=BigInt(`0x${ge.Convert.ToHex(a)}`)+t,p=ge.BufferSourceConverter.toUint8Array(ge.Convert.FromHex(u.toString(16)));p[0]|=128,n.write(p)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new Dc({valueHex:n.final()})}convertToDER(){let e=new Dc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Dc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};Dc=jn;J.Integer=Dc;jn.NAME="INTEGER";var $x,gi=class extends jn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};$x=gi;J.Enumerated=$x;gi.NAME="ENUMERATED";var Mc=class extends Qr(bt){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(!Ln(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=yi(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Gl();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=vo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Mr;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 tp=class extends bt{constructor({value:e=Gt,...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,Mr;t.push(o)}return em(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){Gl();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}};tp.NAME="ObjectIdentifierValueBlock";var Fx,bi=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,tp),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Fx=bi;J.ObjectIdentifier=Fx;bi.NAME="OBJECT IDENTIFIER";var Kc=class extends Qr(Dn){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(!Ln(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=yi(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=vo(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Mr;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}}};Kc.NAME="relativeSidBlock";var rp=class extends bt{constructor({value:e=Gt,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new Kc;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,Mr;n.push(i)}return em(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 Kc;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}};rp.NAME="RelativeObjectIdentifierValueBlock";var Wx,Hc=class extends ot{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,rp),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Wx=Hc;J.RelativeObjectIdentifier=Wx;Hc.NAME="RelativeObjectIdentifier";var qx,Nt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};qx=Nt;J.Sequence=qx;Nt.NAME="SEQUENCE";var Gx,Kt=class extends it{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Gx=Kt;J.Set=Gx;Kt.NAME="SET";var np=class extends Qr(bt){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Gt}toJSON(){return{...super.toJSON(),value:this.value}}};np.NAME="StringValueBlock";var op=class extends np{};op.NAME="SimpleStringValueBlock";var Ht=class extends jc{constructor({...e}={}){super(e,op)}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}};Ht.NAME="SIMPLE STRING";var ip=class extends Ht{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}};ip.NAME="Utf8StringValueBlock";var zx,gr=class extends ip{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};zx=gr;J.Utf8String=zx;gr.NAME="UTF8String";var sp=class extends Ht{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))}};sp.NAME="BmpStringValueBlock";var Xx,wi=class extends sp{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Xx=wi;J.BmpString=Xx;wi.NAME="BMPString";var ap=class extends Ht{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=vo(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}};ap.NAME="UniversalStringValueBlock";var Zx,xi=class extends ap{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Zx=xi;J.UniversalString=Zx;xi.NAME="UniversalString";var Yx,vi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Yx=vi;J.NumericString=Yx;vi.NAME="NumericString";var Jx,_i=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Jx=_i;J.PrintableString=Jx;_i.NAME="PrintableString";var Qx,Si=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Qx=Si;J.TeletexString=Qx;Si.NAME="TeletexString";var ev,Ai=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};ev=Ai;J.VideotexString=ev;Ai.NAME="VideotexString";var tv,Ei=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};tv=Ei;J.IA5String=tv;Ei.NAME="IA5String";var rv,Ci=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};rv=Ci;J.GraphicString=rv;Ci.NAME="GraphicString";var nv,_o=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};nv=_o;J.VisibleString=nv;_o.NAME="VisibleString";var ov,Ti=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ov=Ti;J.GeneralString=ov;Ti.NAME="GeneralString";var iv,Bi=class extends Ht{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};iv=Bi;J.CharacterString=iv;Bi.NAME="CharacterString";var sv,So=class extends _o{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]=qt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=qt(this.month,2),t[2]=qt(this.day,2),t[3]=qt(this.hour,2),t[4]=qt(this.minute,2),t[5]=qt(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}}};sv=So;J.UTCTime=sv;So.NAME="UTCTime";var av,Ii=class extends So{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){let e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.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 l=1,h=n.indexOf("+"),y="";if(h===-1&&(h=n.indexOf("-"),l=-1),h!==-1){if(y=n.substring(h+1),n=n.substring(0,h),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let m=parseInt(y.substring(0,2),10);if(isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*m,y.length===4){if(m=parseInt(y.substring(2,4),10),isNaN(m.valueOf()))throw new Error("Wrong input string for conversion");c=l*m}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let l=new Number(`0${n.substring(u)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,u)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-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,u!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}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 l=1;l<p.length;l++)switch(l){case 1:this.year=parseInt(p[l],10);break;case 2:this.month=parseInt(p[l],10);break;case 3:this.day=parseInt(p[l],10);break;case 4:this.hour=parseInt(p[l],10)+a;break;case 5:this.minute=parseInt(p[l],10)+c;break;case 6:this.second=parseInt(p[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(qt(this.year,4)),t.push(qt(this.month,2)),t.push(qt(this.day,2)),t.push(qt(this.hour,2)),t.push(qt(this.minute,2)),t.push(qt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(qt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};av=Ii;J.GeneralizedTime=av;Ii.NAME="GeneralizedTime";var cv,Vc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};cv=Vc;J.DATE=cv;Vc.NAME="DATE";var uv,$c=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};uv=$c;J.TimeOfDay=uv;$c.NAME="TimeOfDay";var fv,Fc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};fv=Fc;J.DateTime=fv;Fc.NAME="DateTime";var lv,Wc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};lv=Wc;J.Duration=lv;Wc.NAME="Duration";var pv,qc=class extends gr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};pv=qc;J.TIME=pv;qc.NAME="TIME";var Jr=class{constructor({name:e=Gt,optional:t=!1}={}){this.name=e,this.optional=t}},Zs=class extends Jr{constructor({value:e=[],...t}={}){super(t),this.value=e}},Oi=class extends Jr{constructor({value:e=new Jr,local:t=!1,...n}={}){super(n),this.value=e,this.local=t}},Qy=class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=ge.BufferSourceConverter.toUint8Array(e)}constructor({data:e=cp}={}){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 kn(r,e,t){if(t instanceof Zs){for(let i of t.value)if(kn(r,e,i).verified)return{verified:!0,result:r};{let i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Jy)&&(i.name=t.name),i}}if(t instanceof Jr)return t.hasOwnProperty(Jy)&&(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(!(GC in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(YC in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(JC 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(zC)===!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(XC)===!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(ZC)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(qC 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(!(Px 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,Gt),t.name&&(r[t.name]=e)),t instanceof J.Constructed){let i=0,s={verified:!1,result:{error:"Unknown error"}},a=t.valueBlock.value.length;if(a>0&&t.valueBlock.value[0]instanceof Oi&&(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 u=0;u<t.valueBlock.value.length;u++)c=c&&(t.valueBlock.value[u].optional||!1);return c?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Gt),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 u={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,Gt),t.name&&(delete r[t.name],u.name=t.name)),u}}else if(t.valueBlock.value[0]instanceof Oi){if(s=kn(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,Gt),t.name&&delete r[t.name]),s;if(Jy in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let u={};QC in t.valueBlock.value[0]&&t.valueBlock.value[0].local?u=e:u=r,typeof u[t.valueBlock.value[0].name]>"u"&&(u[t.valueBlock.value[0].name]=[]),u[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(s=kn(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,Gt),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,Gt),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&Px in e.valueBlock){let i=Ys(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,Gt),t.name&&(delete r[t.name],s.name=t.name)),s}return kn(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}function oT(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};let t=Ys(ge.BufferSourceConverter.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:kn(t.result,t.result,e)}var S;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(S||(S={}));var d;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(d||(d={}));var rm=Gr(Nn()),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(rm.BufferSourceConverter.isBufferSource(e))this.unusedBits=t,this.value=rm.BufferSourceConverter.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof Ur))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 Ur({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Ur({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 nm=Gr(Nn()),ae=class{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):nm.BufferSourceConverter.isBufferSource(e)?this.buffer=nm.BufferSourceConverter.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof Lr))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new Lr({valueHex:this.buffer})}toSchema(e){return new Lr({name:e})}};var iT={fromASN:r=>r instanceof jr?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new jr;let e=Un(r);if(e.result.error)throw new Error(e.result.error);return e.result}},sT={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new jn({value:+r})},aT={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new gi({value:r})},we={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new jn({valueHex:r})};var cT={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Ur({valueHex:r})},uT={fromASN:r=>r.valueBlock.toString(),toASN:r=>new bi({value:r})},fT={fromASN:r=>r.valueBlock.value,toASN:r=>new mi({value:r})},Js={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Lr({valueHex:r})},hv={fromASN:r=>new ae(r.getValue()),toASN:r=>r.toASN()};function br(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}var om=br(gr),lT=br(wi),pT=br(xi),hT=br(vi),dT=br(_i),yT=br(Si),mT=br(Ai),gT=br(Ei),bT=br(Ci),wT=br(_o),xT=br(Ti),vT=br(Bi),_T={fromASN:r=>r.toDate(),toASN:r=>new So({valueDate:r})},ST={fromASN:r=>r.toDate(),toASN:r=>new Ii({valueDate:r})},AT={fromASN:()=>null,toASN:()=>new jr};function Ao(r){switch(r){case d.Any:return iT;case d.BitString:return cT;case d.BmpString:return lT;case d.Boolean:return fT;case d.CharacterString:return vT;case d.Enumerated:return aT;case d.GeneralString:return xT;case d.GeneralizedTime:return ST;case d.GraphicString:return bT;case d.IA5String:return gT;case d.Integer:return sT;case d.Null:return AT;case d.NumericString:return hT;case d.ObjectIdentifier:return uT;case d.OctetString:return Js;case d.PrintableString:return dT;case d.TeletexString:return yT;case d.UTCTime:return _T;case d.UniversalString:return pT;case d.Utf8String:return om;case d.VideotexString:return mT;case d.VisibleString:return wT;default:return null}}function wr(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:wr(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function sm(r){var e;if(r){let t=Object.getPrototypeOf(r);return((e=t?.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:sm(t)}return!1}function dv(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 up=class{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){let n=this.items.get(e);if(!n)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!n.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return n}cache(e){let t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){let t={type:S.Sequence,items:{}},n=this.findParentSchema(e);return n&&(Object.assign(t,n),t.items=Object.assign({},t.items,n.items)),t}create(e,t){let n=this.items.get(e)||this.createDefault(e),o=[];for(let i in n.items){let s=n.items[i],a=t?i:"",c;if(typeof s.type=="number"){let p=d[s.type],l=en[p];if(!l)throw new Error(`Cannot get ASN1 class by name '${p}'`);c=new l({name:a})}else wr(s.type)?c=new s.type().toSchema(a):s.optional?this.get(s.type).type===S.Choice?c=new Jr({name:a}):(c=this.create(s.type,!1),c.name=a):c=new Jr({name:a});let u=!!s.optional||s.defaultValue!==void 0;if(s.repeated){c.name="";let p=s.repeated==="set"?Kt:Nt;c=new p({name:"",value:[new Oi({name:a,value:c})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||wr(s.type)){let p=s.repeated?it:Rn;o.push(new p({name:a,optional:u,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);let p=!!s.repeated,l=p?c:this.get(s.type,!0).schema;l="valueBlock"in l?l.valueBlock.value:l.value,o.push(new it({name:p?"":a,optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:l}))}else o.push(new it({optional:u,idBlock:{tagClass:3,tagNumber:s.context},value:[c]}));else c.optional=u,o.push(c)}switch(n.type){case S.Sequence:return new Nt({value:o,name:""});case S.Set:return new Kt({value:o,name:""});case S.Choice:return new Zs({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 Je=new up;var T=r=>e=>{let t;Je.has(e)?t=Je.get(e):(t=Je.createDefault(e),Je.set(e,t)),Object.assign(t,r)};var f=r=>(e,t)=>{let n;Je.has(e.constructor)?n=Je.get(e.constructor):(n=Je.createDefault(e.constructor),Je.set(e.constructor,n));let o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){let i=Ao(r.type);if(!i)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=i}o.raw=r.raw,n.items[t]=o};var Eo=class extends Error{constructor(){super(...arguments),this.schemas=[]}};var Gc=class{static parse(e,t){let n=Un(e);if(n.result.error)throw new Error(n.result.error);return this.fromASN(n.result,t)}static fromASN(e,t){try{if(wr(t))return new t().fromASN(e);let n=Je.get(t);Je.cache(t);let o=n.schema,i=this.handleChoiceTypes(e,n,t,o);if(i?.result)return i.result;i?.targetSchema&&(o=i.targetSchema);let s=this.handleSequenceTypes(e,n,t,o);if(s&&"isManualMapping"in s)return s.result;let a=s,c=new t;return sm(t)?this.handleArrayTypes(e,n,t):(this.processSchemaItems(n,a,c),c)}catch(n){throw n instanceof Eo&&n.schemas.push(t.name),n}}static handleChoiceTypes(e,t,n,o){if(e.constructor===it&&t.type===S.Choice&&e.idBlock.tagClass===3)for(let i in t.items){let s=t.items[i];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&Je.has(s.type)){let a=Je.get(s.type);if(a&&a.type===S.Sequence){let c=new Nt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in c.valueBlock){c.valueBlock.value=e.valueBlock.value;let u=this.fromASN(c,s.type),p=new n;return p[i]=u,{result:p}}}}}else if(e.constructor===it&&t.type!==S.Choice){let i=new it({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(let s in t.items)delete e[s];return{targetSchema:i}}return null}static handleSequenceTypes(e,t,n,o){if(t.type===S.Sequence){if(Object.keys(t.items).filter(a=>{let c=t.items[a];return c.optional&&typeof c.type=="function"&&Je.has(c.type)&&Je.get(c.type).type===S.Choice}).length>0&&"value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&n.name==="CertReqMsg")return this.handleManualMapping(e,t,n);let s=kn({},e,o);if(!s.verified)throw new Eo(`Data does not match to ${n.name} ASN1 schema.${s.result.error?` ${s.result.error}`:""}`);return s}else{let i=kn({},e,o);if(!i.verified)throw new Eo(`Data does not match to ${n.name} ASN1 schema.${i.result.error?` ${i.result.error}`:""}`);return i}}static handleManualMapping(e,t,n){let o=new n,i=e.valueBlock.value,s=Object.keys(t.items),a=0;for(let c=0;c<s.length;c++){let u=s[c],p=t.items[u];if(a>=i.length)break;if(p.repeated){o[u]=this.processRepeatedField(i,a,p);break}else if(typeof p.type=="number")o[u]=this.processPrimitiveField(i[a],p),a++;else if(this.isOptionalChoiceField(p)){let l=this.processOptionalChoiceField(i[a],p);l.processed&&(o[u]=l.value,a++)}else o[u]=this.fromASN(i[a],p.type),a++}return{result:o,verified:!0,isManualMapping:!0}}static processRepeatedField(e,t,n){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){let i=o[0];i.valueBlock&&i.valueBlock.value&&Array.isArray(i.valueBlock.value)&&(o=i.valueBlock.value)}if(typeof n.type=="number"){let i=Ao(n.type);if(!i)throw new Error(`No converter for ASN.1 type ${n.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return i.fromASN(s)}catch{return}}).filter(s=>s!==void 0)}else return o.filter(i=>i&&i.valueBlock).map(i=>{try{return this.fromASN(i,n.type)}catch{return}}).filter(i=>i!==void 0)}static processPrimitiveField(e,t){let n=Ao(t.type);if(!n)throw new Error(`No converter for ASN.1 type ${t.type}`);return n.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&Je.has(e.type)&&Je.get(e.type).type===S.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(n){if(n instanceof Eo&&/Wrong values for Choice type/.test(n.message))return{processed:!1};throw n}}static handleArrayTypes(e,t,n){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let o=t.itemType;if(typeof o=="number"){let i=Ao(o);if(!i)throw new Error(`Cannot get default converter for array item of ${n.name} ASN1 schema`);return n.from(e.valueBlock.value,s=>i.fromASN(s))}else return n.from(e.valueBlock.value,i=>this.fromASN(i,o))}static processSchemaItems(e,t,n){for(let o in e.items){let i=t.result[o];if(!i)continue;let s=e.items[o],a=s.type,c;typeof a=="number"||wr(a)?c=this.processPrimitiveSchemaItem(i,s,a):c=this.processComplexSchemaItem(i,s,a),c&&typeof c=="object"&&"value"in c&&"raw"in c?(n[o]=c.value,n[`${o}Raw`]=c.raw):n[o]=c}}static processPrimitiveSchemaItem(e,t,n){var o;let i=(o=t.converter)!==null&&o!==void 0?o:wr(n)?new n:null;if(!i)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,i):this.processSinglePrimitiveItem(e,t,n,i)}static processRepeatedPrimitiveItem(e,t,n){if(t.implicit){let o=t.repeated==="sequence"?Nt:Kt,i=new o;i.valueBlock=e.valueBlock;let s=Un(i.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");let a=s.result.valueBlock.value;return Array.from(a,c=>n.fromASN(c))}else return Array.from(e,o=>n.fromASN(o))}static processSinglePrimitiveItem(e,t,n,o){let i=e;if(t.implicit){let s;if(wr(n))s=new n().toSchema("");else{let a=d[n],c=en[a];if(!c)throw new Error(`Cannot get '${a}' class from asn1js module`);s=new c}s.valueBlock=i.valueBlock,i=Un(s.toBER(!1)).result}return o.fromASN(i)}static processComplexSchemaItem(e,t,n){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,n))}else{let o=this.handleImplicitTagging(e,t,n);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,n)}catch(i){if(i instanceof Eo&&/Wrong values for Choice type/.test(i.message))return;throw i}else{let i=this.fromASN(o,n);return t.raw?{value:i,raw:e.valueBeforeDecodeView}:i}}}static handleImplicitTagging(e,t,n){if(t.implicit&&typeof t.context=="number"){let o=Je.get(n);if(o.type===S.Sequence){let i=new Nt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}else if(o.type===S.Set){let i=new Kt;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in i.valueBlock)return i.valueBlock.value=e.valueBlock.value,i}}return e}};var zc=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"&&wr(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");let t=e.constructor,n=Je.get(t);Je.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=Ao(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"&&dv(this.serialize(a.defaultValue),this.serialize(c)))continue;let u=r.toAsnItem(a,s,t,c);if(typeof a.context=="number")if(a.implicit)if(!a.repeated&&(typeof a.type=="number"||wr(a.type))){let p={};p.valueHex=u instanceof jr?u.valueBeforeDecodeView:u.valueBlock.toBER(),o.push(new Rn({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},...p}))}else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:u.valueBlock.value}));else o.push(new it({optional:a.optional,idBlock:{tagClass:3,tagNumber:a.context},value:[u]}));else a.repeated?o=o.concat(u):o.push(u)}let i;switch(n.type){case S.Sequence:i=new Nt({value:o});break;case S.Set:i=new Kt({value:o});break;case S.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=o[0];break}return i}static toAsnItem(e,t,n,o){let i;if(typeof e.type=="number"){let s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${d[e.type]} in schema '${n.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let a=Array.from(o,u=>s.toASN(u)),c=e.repeated==="sequence"?Nt:Kt;i=new c({value:a})}else i=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");let s=Array.from(o,c=>this.toASN(c)),a=e.repeated==="sequence"?Nt:Kt;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 am=Gr(Nn());var W=class r{static serialize(e){return zc.serialize(e)}static parse(e,t){return Gc.parse(e,t)}static toString(e){let t=am.BufferSourceConverter.isBufferSource(e)?am.BufferSourceConverter.toArrayBuffer(e):r.serialize(e),n=Un(t);if(n.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${n.result.error}`);return n.result.toString()}};function b(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 yv=Gr(Nn()),Xc=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,u)=>c+(u.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${a}`:`${this.formatIPv6(o)}/${a}`}return this.decodeIP(yv.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 mv=Gr(Nn()),cm,um,fm,st=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};b([f({type:d.TeletexString})],st.prototype,"teletexString",void 0);b([f({type:d.PrintableString})],st.prototype,"printableString",void 0);b([f({type:d.UniversalString})],st.prototype,"universalString",void 0);b([f({type:d.Utf8String})],st.prototype,"utf8String",void 0);b([f({type:d.BmpString})],st.prototype,"bmpString",void 0);st=b([T({type:S.Choice})],st);var Qs=class extends st{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?mv.Convert.ToHex(this.anyValue):super.toString())}};b([f({type:d.IA5String})],Qs.prototype,"ia5String",void 0);b([f({type:d.Any})],Qs.prototype,"anyValue",void 0);Qs=b([T({type:S.Choice})],Qs);var Pi=class{constructor(e={}){this.type="",this.value=new Qs,Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Pi.prototype,"type",void 0);b([f({type:Qs})],Pi.prototype,"value",void 0);var Co=cm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,cm.prototype)}};Co=cm=b([T({type:S.Set,itemType:Pi})],Co);var lm=um=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,um.prototype)}};lm=um=b([T({type:S.Sequence,itemType:Co})],lm);var je=fm=class extends lm{constructor(e){super(e),Object.setPrototypeOf(this,fm.prototype)}};je=fm=b([T({type:S.Sequence})],je);var ET={fromASN:r=>Xc.toString(Js.fromASN(r)),toASN:r=>Js.toASN(Xc.fromString(r))},To=class{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],To.prototype,"typeId",void 0);b([f({type:d.Any,context:0})],To.prototype,"value",void 0);var Zc=class{constructor(e={}){this.partyName=new st,Object.assign(this,e)}};b([f({type:st,optional:!0,context:0,implicit:!0})],Zc.prototype,"nameAssigner",void 0);b([f({type:st,context:1,implicit:!0})],Zc.prototype,"partyName",void 0);var ue=class{constructor(e={}){Object.assign(this,e)}};b([f({type:To,context:0,implicit:!0})],ue.prototype,"otherName",void 0);b([f({type:d.IA5String,context:1,implicit:!0})],ue.prototype,"rfc822Name",void 0);b([f({type:d.IA5String,context:2,implicit:!0})],ue.prototype,"dNSName",void 0);b([f({type:d.Any,context:3,implicit:!0})],ue.prototype,"x400Address",void 0);b([f({type:je,context:4,implicit:!1})],ue.prototype,"directoryName",void 0);b([f({type:Zc,context:5})],ue.prototype,"ediPartyName",void 0);b([f({type:d.IA5String,context:6,implicit:!0})],ue.prototype,"uniformResourceIdentifier",void 0);b([f({type:d.OctetString,context:7,implicit:!0,converter:ET})],ue.prototype,"iPAddress",void 0);b([f({type:d.ObjectIdentifier,context:8,implicit:!0})],ue.prototype,"registeredID",void 0);ue=b([T({type:S.Choice})],ue);var Bo="1.3.6.1.5.5.7",Io=`${Bo}.1`,gv=`${Bo}.2`,Ni=`${Bo}.3`,fp=`${Bo}.48`,w3=`${gv}.1`,x3=`${gv}.2`,pm=`${fp}.1`,hm=`${fp}.2`,dm=`${fp}.3`,ym=`${fp}.5`,pe="2.5.29";var mm,lp=`${Io}.1`,Mn=class{constructor(e={}){this.accessMethod="",this.accessLocation=new ue,Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Mn.prototype,"accessMethod",void 0);b([f({type:ue})],Mn.prototype,"accessLocation",void 0);var ki=mm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,mm.prototype)}};ki=mm=b([T({type:S.Sequence,itemType:Mn})],ki);var pp=`${pe}.35`,Di=class extends ae{},rn=class{constructor(e={}){e&&Object.assign(this,e)}};b([f({type:Di,context:0,optional:!0,implicit:!0})],rn.prototype,"keyIdentifier",void 0);b([f({type:ue,context:1,optional:!0,implicit:!0,repeated:"sequence"})],rn.prototype,"authorityCertIssuer",void 0);b([f({type:d.Integer,context:2,optional:!0,implicit:!0,converter:we})],rn.prototype,"authorityCertSerialNumber",void 0);var hp=`${pe}.19`,Ri=class{constructor(e={}){this.cA=!1,Object.assign(this,e)}};b([f({type:d.Boolean,defaultValue:!1})],Ri.prototype,"cA",void 0);b([f({type:d.Integer,optional:!0})],Ri.prototype,"pathLenConstraint",void 0);var gm,qe=gm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,gm.prototype)}};qe=gm=b([T({type:S.Sequence,itemType:ue})],qe);var bm,CT=`${pe}.29`,bv=bm=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,bm.prototype)}};bv=bm=b([T({type:S.Sequence})],bv);var wm,yp=`${pe}.32`,J3=`${yp}.0`,Kn=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};b([f({type:d.IA5String})],Kn.prototype,"ia5String",void 0);b([f({type:d.VisibleString})],Kn.prototype,"visibleString",void 0);b([f({type:d.BmpString})],Kn.prototype,"bmpString",void 0);b([f({type:d.Utf8String})],Kn.prototype,"utf8String",void 0);Kn=b([T({type:S.Choice})],Kn);var Yc=class{constructor(e={}){this.organization=new Kn,this.noticeNumbers=[],Object.assign(this,e)}};b([f({type:Kn})],Yc.prototype,"organization",void 0);b([f({type:d.Integer,repeated:"sequence"})],Yc.prototype,"noticeNumbers",void 0);var Jc=class{constructor(e={}){Object.assign(this,e)}};b([f({type:Yc,optional:!0})],Jc.prototype,"noticeRef",void 0);b([f({type:Kn,optional:!0})],Jc.prototype,"explicitText",void 0);var dp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.IA5String})],dp.prototype,"cPSuri",void 0);b([f({type:Jc})],dp.prototype,"userNotice",void 0);dp=b([T({type:S.Choice})],dp);var Qc=class{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],Qc.prototype,"policyQualifierId",void 0);b([f({type:d.Any})],Qc.prototype,"qualifier",void 0);var ji=class{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],ji.prototype,"policyIdentifier",void 0);b([f({type:Qc,repeated:"sequence",optional:!0})],ji.prototype,"policyQualifiers",void 0);var eu=wm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,wm.prototype)}};eu=wm=b([T({type:S.Sequence,itemType:ji})],eu);var sR=`${pe}.20`,tu=class{constructor(e=0){this.value=e}};b([f({type:d.Integer})],tu.prototype,"value",void 0);tu=b([T({type:S.Choice})],tu);var hR=`${pe}.27`,wv=class extends tu{};wv=b([T({type:S.Choice})],wv);var xm,mp=`${pe}.31`,Kr;(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"})(Kr||(Kr={}));var ru=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&Kr.aACompromise&&e.push("aACompromise"),t&Kr.affiliationChanged&&e.push("affiliationChanged"),t&Kr.cACompromise&&e.push("cACompromise"),t&Kr.certificateHold&&e.push("certificateHold"),t&Kr.cessationOfOperation&&e.push("cessationOfOperation"),t&Kr.keyCompromise&&e.push("keyCompromise"),t&Kr.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Kr.superseded&&e.push("superseded"),t&Kr.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Hn=class{constructor(e={}){Object.assign(this,e)}};b([f({type:ue,context:0,repeated:"sequence",implicit:!0})],Hn.prototype,"fullName",void 0);b([f({type:Co,context:1,implicit:!0})],Hn.prototype,"nameRelativeToCRLIssuer",void 0);Hn=b([T({type:S.Choice})],Hn);var nn=class{constructor(e={}){Object.assign(this,e)}};b([f({type:Hn,context:0,optional:!0})],nn.prototype,"distributionPoint",void 0);b([f({type:ru,context:1,optional:!0,implicit:!0})],nn.prototype,"reasons",void 0);b([f({type:ue,context:2,optional:!0,repeated:"sequence",implicit:!0})],nn.prototype,"cRLIssuer",void 0);var Oo=xm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,xm.prototype)}};Oo=xm=b([T({type:S.Sequence,itemType:nn})],Oo);var vm,BR=`${pe}.46`,xv=vm=class extends Oo{constructor(e){super(e),Object.setPrototypeOf(this,vm.prototype)}};xv=vm=b([T({type:S.Sequence,itemType:nn})],xv);var jR=`${pe}.28`,ir=class r{constructor(e={}){this.onlyContainsUserCerts=r.ONLY,this.onlyContainsCACerts=r.ONLY,this.indirectCRL=r.ONLY,this.onlyContainsAttributeCerts=r.ONLY,Object.assign(this,e)}};ir.ONLY=!1;b([f({type:Hn,context:0,optional:!0})],ir.prototype,"distributionPoint",void 0);b([f({type:d.Boolean,context:1,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsUserCerts",void 0);b([f({type:d.Boolean,context:2,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsCACerts",void 0);b([f({type:ru,context:3,optional:!0,implicit:!0})],ir.prototype,"onlySomeReasons",void 0);b([f({type:d.Boolean,context:4,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"indirectCRL",void 0);b([f({type:d.Boolean,context:5,defaultValue:ir.ONLY,implicit:!0})],ir.prototype,"onlyContainsAttributeCerts",void 0);var vv=`${pe}.21`,nu;(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"})(nu||(nu={}));var ou=class{constructor(e=nu.unspecified){this.reason=nu.unspecified,this.reason=e}toJSON(){return nu[this.reason]}toString(){return this.toJSON()}};b([f({type:d.Enumerated})],ou.prototype,"reason",void 0);ou=b([T({type:S.Choice})],ou);var _m,gp=`${pe}.37`,iu=_m=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,_m.prototype)}};iu=_m=b([T({type:S.Sequence,itemType:d.ObjectIdentifier})],iu);var GR=`${gp}.0`,_v=`${Ni}.1`,Sv=`${Ni}.2`,Av=`${Ni}.3`,Ev=`${Ni}.4`,Cv=`${Ni}.8`,Tv=`${Ni}.9`;var JR=`${pe}.54`,Sm=class{constructor(e=new ArrayBuffer(0)){this.value=e}};b([f({type:d.Integer,converter:we})],Sm.prototype,"value",void 0);Sm=b([T({type:S.Choice})],Sm);var Bv=`${pe}.24`,su=class{constructor(e){this.value=new Date,e&&(this.value=e)}};b([f({type:d.GeneralizedTime})],su.prototype,"value",void 0);su=b([T({type:S.Choice})],su);var Am,Em=`${pe}.18`,Iv=Am=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,Am.prototype)}};Iv=Am=b([T({type:S.Sequence})],Iv);var bp=`${pe}.15`,Hr;(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"})(Hr||(Hr={}));var ea=class extends tn{toJSON(){let e=this.toNumber(),t=[];return e&Hr.cRLSign&&t.push("crlSign"),e&Hr.dataEncipherment&&t.push("dataEncipherment"),e&Hr.decipherOnly&&t.push("decipherOnly"),e&Hr.digitalSignature&&t.push("digitalSignature"),e&Hr.encipherOnly&&t.push("encipherOnly"),e&Hr.keyAgreement&&t.push("keyAgreement"),e&Hr.keyCertSign&&t.push("keyCertSign"),e&Hr.keyEncipherment&&t.push("keyEncipherment"),e&Hr.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}};var Cm,wj=`${pe}.30`,ta=class{constructor(e={}){this.base=new ue,this.minimum=0,Object.assign(this,e)}};b([f({type:ue})],ta.prototype,"base",void 0);b([f({type:d.Integer,context:0,defaultValue:0,implicit:!0})],ta.prototype,"minimum",void 0);b([f({type:d.Integer,context:1,optional:!0,implicit:!0})],ta.prototype,"maximum",void 0);var wp=Cm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Cm.prototype)}};wp=Cm=b([T({type:S.Sequence,itemType:ta})],wp);var xp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:wp,context:0,optional:!0,implicit:!0})],xp.prototype,"permittedSubtrees",void 0);b([f({type:wp,context:1,optional:!0,implicit:!0})],xp.prototype,"excludedSubtrees",void 0);var Ej=`${pe}.36`,vp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.Integer,context:0,implicit:!0,optional:!0,converter:we})],vp.prototype,"requireExplicitPolicy",void 0);b([f({type:d.Integer,context:1,implicit:!0,optional:!0,converter:we})],vp.prototype,"inhibitPolicyMapping",void 0);var Tm,Oj=`${pe}.33`,au=class{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],au.prototype,"issuerDomainPolicy",void 0);b([f({type:d.ObjectIdentifier})],au.prototype,"subjectDomainPolicy",void 0);var Ov=Tm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Tm.prototype)}};Ov=Tm=b([T({type:S.Sequence,itemType:au})],Ov);var Bm,Im=`${pe}.17`,_p=Bm=class extends qe{constructor(e){super(e),Object.setPrototypeOf(this,Bm.prototype)}};_p=Bm=b([T({type:S.Sequence})],_p);var wt=class{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}};b([f({type:d.ObjectIdentifier})],wt.prototype,"type",void 0);b([f({type:d.Any,repeated:"set"})],wt.prototype,"values",void 0);var Om,qj=`${pe}.9`,Pv=Om=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Om.prototype)}};Pv=Om=b([T({type:S.Sequence,itemType:wt})],Pv);var Pm=`${pe}.14`,zt=class extends Di{};var tL=`${pe}.16`,Sp=class{constructor(e={}){Object.assign(this,e)}};b([f({type:d.GeneralizedTime,context:0,implicit:!0,optional:!0})],Sp.prototype,"notBefore",void 0);b([f({type:d.GeneralizedTime,context:1,implicit:!0,optional:!0})],Sp.prototype,"notAfter",void 0);var cu;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(cu||(cu={}));var Ap=class extends tn{toJSON(){let e=[],t=this.toNumber();return t&cu.pKIXCertificate&&e.push("pKIXCertificate"),t&cu.newExtensions&&e.push("newExtensions"),t&cu.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}},Ep=class{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new Ap,Object.assign(this,e)}};b([f({type:d.GeneralString})],Ep.prototype,"entrustVers",void 0);b([f({type:Ap})],Ep.prototype,"entrustInfoFlags",void 0);var Nm,fL=`${Io}.11`,Nv=Nm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Nm.prototype)}};Nv=Nm=b([T({type:S.Sequence,itemType:Mn})],Nv);var kv=Gr(Nn()),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&&kv.isEqual(e.parameters,this.parameters)||e.parameters===this.parameters)}};b([f({type:d.ObjectIdentifier})],M.prototype,"algorithm",void 0);b([f({type:d.Any,optional:!0})],M.prototype,"parameters",void 0);var xt=class{constructor(e={}){this.algorithm=new M,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:M})],xt.prototype,"algorithm",void 0);b([f({type:d.BitString})],xt.prototype,"subjectPublicKey",void 0);var Qe=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){let t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){let e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};b([f({type:d.UTCTime})],Qe.prototype,"utcTime",void 0);b([f({type:d.GeneralizedTime})],Qe.prototype,"generalTime",void 0);Qe=b([T({type:S.Choice})],Qe);var Vn=class{constructor(e){this.notBefore=new Qe(new Date),this.notAfter=new Qe(new Date),e&&(this.notBefore=new Qe(e.notBefore),this.notAfter=new Qe(e.notAfter))}};b([f({type:Qe})],Vn.prototype,"notBefore",void 0);b([f({type:Qe})],Vn.prototype,"notAfter",void 0);var km,vt=class r{constructor(e={}){this.extnID="",this.critical=r.CRITICAL,this.extnValue=new ae,Object.assign(this,e)}};vt.CRITICAL=!1;b([f({type:d.ObjectIdentifier})],vt.prototype,"extnID",void 0);b([f({type:d.Boolean,defaultValue:vt.CRITICAL})],vt.prototype,"critical",void 0);b([f({type:ae})],vt.prototype,"extnValue",void 0);var sr=km=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,km.prototype)}};sr=km=b([T({type:S.Sequence,itemType:vt})],sr);var on;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(on||(on={}));var _t=class{constructor(e={}){this.version=on.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new M,this.issuer=new je,this.validity=new Vn,this.subject=new je,this.subjectPublicKeyInfo=new xt,Object.assign(this,e)}};b([f({type:d.Integer,context:0,defaultValue:on.v1})],_t.prototype,"version",void 0);b([f({type:d.Integer,converter:we})],_t.prototype,"serialNumber",void 0);b([f({type:M})],_t.prototype,"signature",void 0);b([f({type:je})],_t.prototype,"issuer",void 0);b([f({type:Vn})],_t.prototype,"validity",void 0);b([f({type:je})],_t.prototype,"subject",void 0);b([f({type:xt})],_t.prototype,"subjectPublicKeyInfo",void 0);b([f({type:d.BitString,context:1,implicit:!0,optional:!0})],_t.prototype,"issuerUniqueID",void 0);b([f({type:d.BitString,context:2,implicit:!0,optional:!0})],_t.prototype,"subjectUniqueID",void 0);b([f({type:sr,context:3,optional:!0})],_t.prototype,"extensions",void 0);var xr=class{constructor(e={}){this.tbsCertificate=new _t,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:_t,raw:!0})],xr.prototype,"tbsCertificate",void 0);b([f({type:M})],xr.prototype,"signatureAlgorithm",void 0);b([f({type:d.BitString})],xr.prototype,"signatureValue",void 0);var Li=class{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new Qe,Object.assign(this,e)}};b([f({type:d.Integer,converter:we})],Li.prototype,"userCertificate",void 0);b([f({type:Qe})],Li.prototype,"revocationDate",void 0);b([f({type:vt,optional:!0,repeated:"sequence"})],Li.prototype,"crlEntryExtensions",void 0);var ar=class{constructor(e={}){this.signature=new M,this.issuer=new je,this.thisUpdate=new Qe,Object.assign(this,e)}};b([f({type:d.Integer,optional:!0})],ar.prototype,"version",void 0);b([f({type:M})],ar.prototype,"signature",void 0);b([f({type:je})],ar.prototype,"issuer",void 0);b([f({type:Qe})],ar.prototype,"thisUpdate",void 0);b([f({type:Qe,optional:!0})],ar.prototype,"nextUpdate",void 0);b([f({type:Li,repeated:"sequence",optional:!0})],ar.prototype,"revokedCertificates",void 0);b([f({type:vt,optional:!0,context:0,repeated:"sequence"})],ar.prototype,"crlExtensions",void 0);var Ui=class{constructor(e={}){this.tbsCertList=new ar,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};b([f({type:ar,raw:!0})],Ui.prototype,"tbsCertList",void 0);b([f({type:M})],Ui.prototype,"signatureAlgorithm",void 0);b([f({type:d.BitString})],Ui.prototype,"signature",void 0);var H=Gr(Nn());function uu(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}function de(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)}function Ge(r,e,t,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!o:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(r,t):o?o.value=t:e.set(r,t),t}function O(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 Vr=class{constructor(e={}){this.issuer=new je,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:je})],Vr.prototype,"issuer",void 0);O([f({type:d.Integer,converter:we})],Vr.prototype,"serialNumber",void 0);var Mi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0})],Mi.prototype,"subjectKeyIdentifier",void 0);O([f({type:Vr})],Mi.prototype,"issuerAndSerialNumber",void 0);Mi=O([T({type:S.Choice})],Mi);var St;(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"})(St||(St={}));var Ki=class extends M{};Ki=O([T({type:S.Sequence})],Ki);var fu=class extends M{};fu=O([T({type:S.Sequence})],fu);var Xt=class extends M{};Xt=O([T({type:S.Sequence})],Xt);var lu=class extends M{};lu=O([T({type:S.Sequence})],lu);var Rv=class extends M{};Rv=O([T({type:S.Sequence})],Rv);var Cp=class extends M{};Cp=O([T({type:S.Sequence})],Cp);var $r=class{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],$r.prototype,"attrType",void 0);O([f({type:d.Any,repeated:"set"})],$r.prototype,"attrValues",void 0);var Dm,Zt=class{constructor(e={}){this.version=St.v0,this.sid=new Mi,this.digestAlgorithm=new Ki,this.signatureAlgorithm=new fu,this.signature=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Zt.prototype,"version",void 0);O([f({type:Mi})],Zt.prototype,"sid",void 0);O([f({type:Ki})],Zt.prototype,"digestAlgorithm",void 0);O([f({type:$r,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],Zt.prototype,"signedAttrs",void 0);O([f({type:fu})],Zt.prototype,"signatureAlgorithm",void 0);O([f({type:ae})],Zt.prototype,"signature",void 0);O([f({type:$r,repeated:"set",context:1,implicit:!0,optional:!0})],Zt.prototype,"unsignedAttrs",void 0);var pu=Dm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Dm.prototype)}};pu=Dm=O([T({type:S.Set,itemType:Zt})],pu);var jv=class extends Qe{};jv=O([T({type:S.Choice})],jv);var Lv=class extends Zt{};Lv=O([T({type:S.Sequence})],Lv);function G(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 hu=class{constructor(e={}){this.acIssuer=new ue,this.acSerial=0,this.attrs=[],Object.assign(this,e)}};G([f({type:ue})],hu.prototype,"acIssuer",void 0);G([f({type:d.Integer})],hu.prototype,"acSerial",void 0);G([f({type:wt,repeated:"sequence"})],hu.prototype,"attrs",void 0);var Rm,du=Rm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Rm.prototype)}};du=Rm=G([T({type:S.Sequence,itemType:d.ObjectIdentifier})],du);var ra=class{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}};G([f({type:d.Integer,optional:!0})],ra.prototype,"pathLenConstraint",void 0);G([f({type:du,implicit:!0,context:0,optional:!0})],ra.prototype,"permittedAttrs",void 0);G([f({type:du,implicit:!0,context:1,optional:!0})],ra.prototype,"excludedAttrs",void 0);G([f({type:d.Boolean,defaultValue:!0})],ra.prototype,"permitUnSpecified",void 0);var vr=class{constructor(e={}){this.issuer=new qe,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:qe})],vr.prototype,"issuer",void 0);G([f({type:d.Integer,converter:we})],vr.prototype,"serial",void 0);G([f({type:d.BitString,optional:!0})],vr.prototype,"issuerUID",void 0);var jm;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(jm||(jm={}));var _r=class{constructor(e={}){this.digestedObjectType=jm.publicKey,this.digestAlgorithm=new M,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:d.Enumerated})],_r.prototype,"digestedObjectType",void 0);G([f({type:d.ObjectIdentifier,optional:!0})],_r.prototype,"otherObjectTypeID",void 0);G([f({type:M})],_r.prototype,"digestAlgorithm",void 0);G([f({type:d.BitString})],_r.prototype,"objectDigest",void 0);var Hi=class{constructor(e={}){Object.assign(this,e)}};G([f({type:qe,optional:!0})],Hi.prototype,"issuerName",void 0);G([f({type:vr,context:0,implicit:!0,optional:!0})],Hi.prototype,"baseCertificateID",void 0);G([f({type:_r,context:1,implicit:!0,optional:!0})],Hi.prototype,"objectDigestInfo",void 0);var Vi=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ue,repeated:"sequence"})],Vi.prototype,"v1Form",void 0);G([f({type:Hi,context:0,implicit:!0})],Vi.prototype,"v2Form",void 0);Vi=G([T({type:S.Choice})],Vi);var $i=class{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}};G([f({type:d.GeneralizedTime})],$i.prototype,"notBeforeTime",void 0);G([f({type:d.GeneralizedTime})],$i.prototype,"notAfterTime",void 0);var Po=class{constructor(e={}){Object.assign(this,e)}};G([f({type:vr,implicit:!0,context:0,optional:!0})],Po.prototype,"baseCertificateID",void 0);G([f({type:qe,implicit:!0,context:1,optional:!0})],Po.prototype,"entityName",void 0);G([f({type:_r,implicit:!0,context:2,optional:!0})],Po.prototype,"objectDigestInfo",void 0);var Lm;(function(r){r[r.v2=1]="v2"})(Lm||(Lm={}));var Yt=class{constructor(e={}){this.version=Lm.v2,this.holder=new Po,this.issuer=new Vi,this.signature=new M,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new $i,this.attributes=[],Object.assign(this,e)}};G([f({type:d.Integer})],Yt.prototype,"version",void 0);G([f({type:Po})],Yt.prototype,"holder",void 0);G([f({type:Vi})],Yt.prototype,"issuer",void 0);G([f({type:M})],Yt.prototype,"signature",void 0);G([f({type:d.Integer,converter:we})],Yt.prototype,"serialNumber",void 0);G([f({type:$i})],Yt.prototype,"attrCertValidityPeriod",void 0);G([f({type:wt,repeated:"sequence"})],Yt.prototype,"attributes",void 0);G([f({type:d.BitString,optional:!0})],Yt.prototype,"issuerUniqueID",void 0);G([f({type:sr,optional:!0})],Yt.prototype,"extensions",void 0);var Fi=class{constructor(e={}){this.acinfo=new Yt,this.signatureAlgorithm=new M,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:Yt})],Fi.prototype,"acinfo",void 0);G([f({type:M})],Fi.prototype,"signatureAlgorithm",void 0);G([f({type:d.BitString})],Fi.prototype,"signatureValue",void 0);var yu;(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"})(yu||(yu={}));var na=class extends tn{};var oa=class{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}};G([f({type:d.ObjectIdentifier,implicit:!0,context:0})],oa.prototype,"type",void 0);G([f({type:d.Any,implicit:!0,context:1})],oa.prototype,"value",void 0);var mu=class{constructor(e={}){this.policyId="",this.classList=new na(yu.unclassified),Object.assign(this,e)}};G([f({type:d.ObjectIdentifier})],mu.prototype,"policyId",void 0);G([f({type:na,defaultValue:new na(yu.unclassified)})],mu.prototype,"classList",void 0);G([f({type:oa,repeated:"set"})],mu.prototype,"securityCategories",void 0);var ia=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ae})],ia.prototype,"cotets",void 0);G([f({type:d.ObjectIdentifier})],ia.prototype,"oid",void 0);G([f({type:d.Utf8String})],ia.prototype,"string",void 0);var Tp=class{constructor(e={}){this.values=[],Object.assign(this,e)}};G([f({type:qe,implicit:!0,context:0,optional:!0})],Tp.prototype,"policyAuthority",void 0);G([f({type:ia,repeated:"sequence"})],Tp.prototype,"values",void 0);var G9=`${Io}.4`,z9=`${Io}.6`,X9=`${Io}.10`,Z9=`${pe}.55`,gu=`${Bo}.10`,Y9=`${gu}.1`,J9=`${gu}.2`,Q9=`${gu}.3`,eK=`${gu}.4`,tK=`${gu}.6`,Um="2.5.4",rK=`${Um}.72`;var Mm,sa=class{constructor(e={}){this.targetCertificate=new vr,Object.assign(this,e)}};G([f({type:vr})],sa.prototype,"targetCertificate",void 0);G([f({type:ue,optional:!0})],sa.prototype,"targetName",void 0);G([f({type:_r,optional:!0})],sa.prototype,"certDigestInfo",void 0);var aa=class{constructor(e={}){Object.assign(this,e)}};G([f({type:ue,context:0,implicit:!0})],aa.prototype,"targetName",void 0);G([f({type:ue,context:1,implicit:!0})],aa.prototype,"targetGroup",void 0);G([f({type:sa,context:2,implicit:!0})],aa.prototype,"targetCert",void 0);aa=G([T({type:S.Choice})],aa);var Bp=Mm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Mm.prototype)}};Bp=Mm=G([T({type:S.Sequence,itemType:aa})],Bp);var Km,Uv=Km=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Km.prototype)}};Uv=Km=G([T({type:S.Sequence,itemType:Bp})],Uv);var Ip=class{constructor(e={}){Object.assign(this,e)}};G([f({type:qe,implicit:!0,context:0,optional:!0})],Ip.prototype,"roleAuthority",void 0);G([f({type:ue,implicit:!0,context:1})],Ip.prototype,"roleName",void 0);var bu=class{constructor(e={}){this.service=new ue,this.ident=new ue,Object.assign(this,e)}};G([f({type:ue})],bu.prototype,"service",void 0);G([f({type:ue})],bu.prototype,"ident",void 0);G([f({type:ae,optional:!0})],bu.prototype,"authInfo",void 0);var Hm,wu=class{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],wu.prototype,"otherCertFormat",void 0);O([f({type:d.Any})],wu.prototype,"otherCert",void 0);var Wi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:xr})],Wi.prototype,"certificate",void 0);O([f({type:Fi,context:2,implicit:!0})],Wi.prototype,"v2AttrCert",void 0);O([f({type:wu,context:3,implicit:!0})],Wi.prototype,"other",void 0);Wi=O([T({type:S.Choice})],Wi);var qi=Hm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Hm.prototype)}};qi=Hm=O([T({type:S.Set,itemType:Wi})],qi);var Sr=class{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Sr.prototype,"contentType",void 0);O([f({type:d.Any,context:0})],Sr.prototype,"content",void 0);var ca=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ae})],ca.prototype,"single",void 0);O([f({type:d.Any})],ca.prototype,"any",void 0);ca=O([T({type:S.Choice})],ca);var Gi=class{constructor(e={}){this.eContentType="",Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Gi.prototype,"eContentType",void 0);O([f({type:ca,context:0,optional:!0})],Gi.prototype,"eContent",void 0);var xu=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ae,context:0,implicit:!0,optional:!0})],xu.prototype,"value",void 0);O([f({type:ae,converter:hv,context:0,implicit:!0,optional:!0,repeated:"sequence"})],xu.prototype,"constructedValue",void 0);xu=O([T({type:S.Choice})],xu);var No=class{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new lu,Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],No.prototype,"contentType",void 0);O([f({type:lu})],No.prototype,"contentEncryptionAlgorithm",void 0);O([f({type:xu,optional:!0})],No.prototype,"encryptedContent",void 0);var ko=class{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],ko.prototype,"keyAttrId",void 0);O([f({type:d.Any,optional:!0})],ko.prototype,"keyAttr",void 0);var Vm,ua=class{constructor(e={}){this.subjectKeyIdentifier=new zt,Object.assign(this,e)}};O([f({type:zt})],ua.prototype,"subjectKeyIdentifier",void 0);O([f({type:d.GeneralizedTime,optional:!0})],ua.prototype,"date",void 0);O([f({type:ko,optional:!0})],ua.prototype,"other",void 0);var fa=class{constructor(e={}){Object.assign(this,e)}};O([f({type:ua,context:0,implicit:!0,optional:!0})],fa.prototype,"rKeyId",void 0);O([f({type:Vr,optional:!0})],fa.prototype,"issuerAndSerialNumber",void 0);fa=O([T({type:S.Choice})],fa);var vu=class{constructor(e={}){this.rid=new fa,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:fa})],vu.prototype,"rid",void 0);O([f({type:ae})],vu.prototype,"encryptedKey",void 0);var Op=Vm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Vm.prototype)}};Op=Vm=O([T({type:S.Sequence,itemType:vu})],Op);var _u=class{constructor(e={}){this.algorithm=new M,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:M})],_u.prototype,"algorithm",void 0);O([f({type:d.BitString})],_u.prototype,"publicKey",void 0);var zi=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0,optional:!0})],zi.prototype,"subjectKeyIdentifier",void 0);O([f({type:_u,context:1,implicit:!0,optional:!0})],zi.prototype,"originatorKey",void 0);O([f({type:Vr,optional:!0})],zi.prototype,"issuerAndSerialNumber",void 0);zi=O([T({type:S.Choice})],zi);var $n=class{constructor(e={}){this.version=St.v3,this.originator=new zi,this.keyEncryptionAlgorithm=new Xt,this.recipientEncryptedKeys=new Op,Object.assign(this,e)}};O([f({type:d.Integer})],$n.prototype,"version",void 0);O([f({type:zi,context:0})],$n.prototype,"originator",void 0);O([f({type:ae,context:1,optional:!0})],$n.prototype,"ukm",void 0);O([f({type:Xt})],$n.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:Op})],$n.prototype,"recipientEncryptedKeys",void 0);var la=class{constructor(e={}){Object.assign(this,e)}};O([f({type:zt,context:0,implicit:!0})],la.prototype,"subjectKeyIdentifier",void 0);O([f({type:Vr})],la.prototype,"issuerAndSerialNumber",void 0);la=O([T({type:S.Choice})],la);var Do=class{constructor(e={}){this.version=St.v0,this.rid=new la,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Do.prototype,"version",void 0);O([f({type:la})],Do.prototype,"rid",void 0);O([f({type:Xt})],Do.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],Do.prototype,"encryptedKey",void 0);var Xi=class{constructor(e={}){this.keyIdentifier=new ae,Object.assign(this,e)}};O([f({type:ae})],Xi.prototype,"keyIdentifier",void 0);O([f({type:d.GeneralizedTime,optional:!0})],Xi.prototype,"date",void 0);O([f({type:ko,optional:!0})],Xi.prototype,"other",void 0);var Ro=class{constructor(e={}){this.version=St.v4,this.kekid=new Xi,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],Ro.prototype,"version",void 0);O([f({type:Xi})],Ro.prototype,"kekid",void 0);O([f({type:Xt})],Ro.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],Ro.prototype,"encryptedKey",void 0);var jo=class{constructor(e={}){this.version=St.v0,this.keyEncryptionAlgorithm=new Xt,this.encryptedKey=new ae,Object.assign(this,e)}};O([f({type:d.Integer})],jo.prototype,"version",void 0);O([f({type:Cp,context:0,optional:!0})],jo.prototype,"keyDerivationAlgorithm",void 0);O([f({type:Xt})],jo.prototype,"keyEncryptionAlgorithm",void 0);O([f({type:ae})],jo.prototype,"encryptedKey",void 0);var Su=class{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],Su.prototype,"oriType",void 0);O([f({type:d.Any})],Su.prototype,"oriValue",void 0);var Fn=class{constructor(e={}){Object.assign(this,e)}};O([f({type:Do,optional:!0})],Fn.prototype,"ktri",void 0);O([f({type:$n,context:1,implicit:!0,optional:!0})],Fn.prototype,"kari",void 0);O([f({type:Ro,context:2,implicit:!0,optional:!0})],Fn.prototype,"kekri",void 0);O([f({type:jo,context:3,implicit:!0,optional:!0})],Fn.prototype,"pwri",void 0);O([f({type:Su,context:4,implicit:!0,optional:!0})],Fn.prototype,"ori",void 0);Fn=O([T({type:S.Choice})],Fn);var $m,Au=$m=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,$m.prototype)}};Au=$m=O([T({type:S.Set,itemType:Fn})],Au);var Fm,Mv=`${Bo}.16`,tV=`${Mv}.2`,rV=`${Mv}.4`,pa=class{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}};O([f({type:d.ObjectIdentifier})],pa.prototype,"otherRevInfoFormat",void 0);O([f({type:d.Any})],pa.prototype,"otherRevInfo",void 0);var Pp=class{constructor(e={}){this.other=new pa,Object.assign(this,e)}};O([f({type:pa,context:1,implicit:!0})],Pp.prototype,"other",void 0);Pp=O([T({type:S.Choice})],Pp);var ha=Fm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Fm.prototype)}};ha=Fm=O([T({type:S.Set,itemType:Pp})],ha);var da=class{constructor(e={}){Object.assign(this,e)}};O([f({type:qi,context:0,implicit:!0,optional:!0})],da.prototype,"certs",void 0);O([f({type:ha,context:1,implicit:!0,optional:!0})],da.prototype,"crls",void 0);var Wm,qm=Wm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Wm.prototype)}};qm=Wm=O([T({type:S.Set,itemType:$r})],qm);var Zi=class{constructor(e={}){this.version=St.v0,this.recipientInfos=new Au,this.encryptedContentInfo=new No,Object.assign(this,e)}};O([f({type:d.Integer})],Zi.prototype,"version",void 0);O([f({type:da,context:0,implicit:!0,optional:!0})],Zi.prototype,"originatorInfo",void 0);O([f({type:Au})],Zi.prototype,"recipientInfos",void 0);O([f({type:No})],Zi.prototype,"encryptedContentInfo",void 0);O([f({type:qm,context:1,implicit:!0,optional:!0})],Zi.prototype,"unprotectedAttrs",void 0);var Kv="1.2.840.113549.1.7.2";var Gm,Np=Gm=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Gm.prototype)}};Np=Gm=O([T({type:S.Set,itemType:Ki})],Np);var Wn=class{constructor(e={}){this.version=St.v0,this.digestAlgorithms=new Np,this.encapContentInfo=new Gi,this.signerInfos=new pu,Object.assign(this,e)}};O([f({type:d.Integer})],Wn.prototype,"version",void 0);O([f({type:Np})],Wn.prototype,"digestAlgorithms",void 0);O([f({type:Gi})],Wn.prototype,"encapContentInfo",void 0);O([f({type:qi,context:0,implicit:!0,optional:!0})],Wn.prototype,"certificates",void 0);O([f({type:ha,context:1,implicit:!0,optional:!0})],Wn.prototype,"crls",void 0);O([f({type:pu})],Wn.prototype,"signerInfos",void 0);var Yi="1.2.840.10045.2.1";var Eu="1.2.840.10045.4.1",kp="1.2.840.10045.4.3.1",Cu="1.2.840.10045.4.3.2",Tu="1.2.840.10045.4.3.3",Bu="1.2.840.10045.4.3.4";var zm="1.2.840.10045.3.1.7";var Xm="1.3.132.0.34";var Zm="1.3.132.0.35";function Iu(r){return new M({algorithm:r})}var Vv=Iu(Eu),JV=Iu(kp),$v=Iu(Cu),Fv=Iu(Tu),Wv=Iu(Bu);function Le(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)}};Le([f({type:d.ObjectIdentifier})],Ou.prototype,"fieldType",void 0);Le([f({type:d.Any})],Ou.prototype,"parameters",void 0);Ou=Le([T({type:S.Sequence})],Ou);var Ym=class extends ae{};var ya=class{constructor(e={}){Object.assign(this,e)}};Le([f({type:d.OctetString})],ya.prototype,"a",void 0);Le([f({type:d.OctetString})],ya.prototype,"b",void 0);Le([f({type:d.BitString,optional:!0})],ya.prototype,"seed",void 0);ya=Le([T({type:S.Sequence})],ya);var Jm;(function(r){r[r.ecpVer1=1]="ecpVer1"})(Jm||(Jm={}));var sn=class{constructor(e={}){this.version=Jm.ecpVer1,Object.assign(this,e)}};Le([f({type:d.Integer})],sn.prototype,"version",void 0);Le([f({type:Ou})],sn.prototype,"fieldID",void 0);Le([f({type:ya})],sn.prototype,"curve",void 0);Le([f({type:Ym})],sn.prototype,"base",void 0);Le([f({type:d.Integer,converter:we})],sn.prototype,"order",void 0);Le([f({type:d.Integer,optional:!0})],sn.prototype,"cofactor",void 0);sn=Le([T({type:S.Sequence})],sn);var an=class{constructor(e={}){Object.assign(this,e)}};Le([f({type:d.ObjectIdentifier})],an.prototype,"namedCurve",void 0);Le([f({type:d.Null})],an.prototype,"implicitCurve",void 0);Le([f({type:sn})],an.prototype,"specifiedCurve",void 0);an=Le([T({type:S.Choice})],an);var ma=class{constructor(e={}){this.version=1,this.privateKey=new ae,Object.assign(this,e)}};Le([f({type:d.Integer})],ma.prototype,"version",void 0);Le([f({type:ae})],ma.prototype,"privateKey",void 0);Le([f({type:an,context:0,optional:!0})],ma.prototype,"parameters",void 0);Le([f({type:d.BitString,context:1,optional:!0})],ma.prototype,"publicKey",void 0);var Ji=class{constructor(e={}){this.r=new ArrayBuffer(0),this.s=new ArrayBuffer(0),Object.assign(this,e)}};Le([f({type:d.Integer,converter:we})],Ji.prototype,"r",void 0);Le([f({type:d.Integer,converter:we})],Ji.prototype,"s",void 0);function Ne(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",cn=`${Jt}.1`,qv=`${Jt}.7`,Gv=`${Jt}.9`,Lo=`${Jt}.10`,zv=`${Jt}.2`,Xv=`${Jt}.4`,ga=`${Jt}.5`,Zv=`${Jt}.14`;var Dp=`${Jt}.11`,ba=`${Jt}.12`,wa=`${Jt}.13`,Qm=`${Jt}.15`,eg=`${Jt}.16`,Qi="1.3.14.3.2.26",Rp="2.16.840.1.101.3.4.2.4",es="2.16.840.1.101.3.4.2.1",ts="2.16.840.1.101.3.4.2.2",rs="2.16.840.1.101.3.4.2.3",Yv="2.16.840.1.101.3.4.2.5",Jv="2.16.840.1.101.3.4.2.6",Qv="1.2.840.113549.2.2",e1="1.2.840.113549.2.5",Uo=`${Jt}.8`;function lt(r){return new M({algorithm:r,parameters:null})}var B$=lt(Qv),I$=lt(e1),qn=lt(Qi),O$=lt(Rp),P$=lt(es),N$=lt(ts),k$=lt(rs),D$=lt(Yv),R$=lt(Jv),jp=new M({algorithm:Uo,parameters:W.serialize(qn)}),tg=new M({algorithm:Gv,parameters:W.serialize(Js.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))}),j$=lt(cn),L$=lt(zv),U$=lt(Xv),M$=lt(ga),K$=lt(Qm),H$=lt(eg),V$=lt(ba),$$=lt(wa),F$=lt(Qm),W$=lt(eg);var xa=class{constructor(e={}){this.hashAlgorithm=new M(qn),this.maskGenAlgorithm=new M({algorithm:Uo,parameters:W.serialize(qn)}),this.pSourceAlgorithm=new M(tg),Object.assign(this,e)}};Ne([f({type:M,context:0,defaultValue:qn})],xa.prototype,"hashAlgorithm",void 0);Ne([f({type:M,context:1,defaultValue:jp})],xa.prototype,"maskGenAlgorithm",void 0);Ne([f({type:M,context:2,defaultValue:tg})],xa.prototype,"pSourceAlgorithm",void 0);var J$=new M({algorithm:qv,parameters:W.serialize(new xa)});var un=class{constructor(e={}){this.hashAlgorithm=new M(qn),this.maskGenAlgorithm=new M({algorithm:Uo,parameters:W.serialize(qn)}),this.saltLength=20,this.trailerField=1,Object.assign(this,e)}};Ne([f({type:M,context:0,defaultValue:qn})],un.prototype,"hashAlgorithm",void 0);Ne([f({type:M,context:1,defaultValue:jp})],un.prototype,"maskGenAlgorithm",void 0);Ne([f({type:d.Integer,context:2,defaultValue:20})],un.prototype,"saltLength",void 0);Ne([f({type:d.Integer,context:3,defaultValue:1})],un.prototype,"trailerField",void 0);var i7=new M({algorithm:Lo,parameters:W.serialize(new un)});var ns=class{constructor(e={}){this.digestAlgorithm=new M,this.digest=new ae,Object.assign(this,e)}};Ne([f({type:M})],ns.prototype,"digestAlgorithm",void 0);Ne([f({type:ae})],ns.prototype,"digest",void 0);var rg,va=class{constructor(e={}){this.prime=new ArrayBuffer(0),this.exponent=new ArrayBuffer(0),this.coefficient=new ArrayBuffer(0),Object.assign(this,e)}};Ne([f({type:d.Integer,converter:we})],va.prototype,"prime",void 0);Ne([f({type:d.Integer,converter:we})],va.prototype,"exponent",void 0);Ne([f({type:d.Integer,converter:we})],va.prototype,"coefficient",void 0);var Lp=rg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,rg.prototype)}};Lp=rg=Ne([T({type:S.Sequence,itemType:va})],Lp);var Ar=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)}};Ne([f({type:d.Integer})],Ar.prototype,"version",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"modulus",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"publicExponent",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"privateExponent",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"prime1",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"prime2",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"exponent1",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"exponent2",void 0);Ne([f({type:d.Integer,converter:we})],Ar.prototype,"coefficient",void 0);Ne([f({type:Lp,optional:!0})],Ar.prototype,"otherPrimeInfos",void 0);var _a=class{constructor(e={}){this.modulus=new ArrayBuffer(0),this.publicExponent=new ArrayBuffer(0),Object.assign(this,e)}};Ne([f({type:d.Integer,converter:we})],_a.prototype,"modulus",void 0);Ne([f({type:d.Integer,converter:we})],_a.prototype,"publicExponent",void 0);var ng;(function(r){r[r.Transient=0]="Transient",r[r.Singleton=1]="Singleton",r[r.ResolutionScoped=2]="ResolutionScoped",r[r.ContainerScoped=3]="ContainerScoped"})(ng||(ng={}));var At=ng;var _1=Gr(v1(),1),{__extends:Aa,__assign:j7,__rest:NT,__decorate:L7,__param:U7,__metadata:M7,__awaiter:S1,__generator:A1,__exportStar:K7,__createBinding:H7,__values:Pu,__read:Nu,__spread:Fr,__spreadArrays:V7,__await:$7,__asyncGenerator:F7,__asyncDelegator:W7,__asyncValues:q7,__makeTemplateObject:G7,__importStar:z7,__importDefault:X7,__classPrivateFieldGet:Z7,__classPrivateFieldSet:Y7}=_1.default;var kT="injectionTokens";function ig(r){var e=Reflect.getMetadata("design:paramtypes",r)||[],t=Reflect.getOwnMetadata(kT,r)||{};return Object.keys(t).forEach(function(n){e[+n]=t[n]}),e}function ku(r){return!!r.useClass}function Ea(r){return!!r.useFactory}var Kp=(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,Fr(i))}};return this.reflectMethods.forEach(n),t},r})();function Mo(r){return typeof r=="string"||typeof r=="symbol"}function sg(r){return typeof r=="object"&&"token"in r&&"multiple"in r}function Hp(r){return typeof r=="object"&&"token"in r&&"transform"in r}function E1(r){return typeof r=="function"||r instanceof Kp}function os(r){return!!r.useToken}function is(r){return r.useValue!=null}function C1(r){return ku(r)||is(r)||os(r)||Ea(r)}var DT=(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})(),Du=DT;var RT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du),T1=RT;var jT=(function(){function r(){this.scopedResolutions=new Map}return r})(),Ru=jT;function LT(r,e){if(r===null)return"at position #"+e;var t=r.split(",")[e].trim();return'"'+t+'" at position #'+e}function UT(r,e,t){return t===void 0&&(t=" "),Fr([r],e.message.split(`
|
7
7
|
`).map(function(n){return t+n})).join(`
|
8
|
-
`)}function ag(r,e,t){var n=Nu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=LT(i,e);return UT("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function B1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var MT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du);var KT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du);var HT=(function(){function r(){this.preResolution=new MT,this.postResolution=new KT}return r})(),I1=HT;var cg=new Map,VT=(function(){function r(e){this.parent=e,this._registry=new T1,this.interceptors=new I1,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:At.Transient}),this.ensureNotDisposed();var o;if(C1(t)?o=t:o={useClass:t},os(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Fr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&os(c.provider)?s=c.provider:s=null}if((n.lifecycle===At.Singleton||n.lifecycle==At.ContainerScoped||n.lifecycle==At.ResolutionScoped)&&(is(o)||Ea(o)))throw new Error('Cannot use lifecycle "'+At[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(),Mo(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(),Mo(e)){if(Mo(t))return this.register(e,{useToken:t},{lifecycle:At.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:At.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!Mo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:At.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new Ru),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&Mo(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(E1(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=Pu(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Pu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var u=c.value;u.options.frequency!="Once"&&s.push(u),u.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===At.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===At.Singleton,o=e.options.lifecycle===At.ContainerScoped,i=n||o,s;return is(e.provider)?s=e.provider.useValue:os(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):ku(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Ea(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===At.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new Ru),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&Mo(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=Pu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Nu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!is(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=Pu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Nu(i.value,2),a=s[0],c=s[1];c.some(function(u){var p=u.options;return p.lifecycle===At.ContainerScoped})&&n._registry.setAll(a,c.map(function(u){return u.options.lifecycle===At.ContainerScoped?{provider:u.provider,options:u.options}:u}))}}catch(u){e={error:u}}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 S1(this,void 0,void 0,function(){var e;return A1(this,function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var o=n.dispose();o&&e.push(o)}),[4,Promise.all(e)];case 1:return t.sent(),[2]}})})},r.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},r.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},r.prototype.construct=function(e,t){var n=this;if(e instanceof Kp)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=cg.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,Fr([void 0],s)))})();return B1(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 sg(o)?Hp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Fr([n.resolveAll(o.token,new Ru,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Fr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new Ru,o.isOptional):n.resolve(o.token,e,o.isOptional):Hp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Fr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(u){throw new Error(ag(t,i,u))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),He=new VT;function $T(r){return function(e){cg.set(e,ig(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){He.register(t,e)}):He.register(r.token,e))}}var Ko=$T;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 Be(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}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}var fg,ss=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Ie([f({type:d.ObjectIdentifier})],ss.prototype,"attrId",void 0);Ie([f({type:d.Any,repeated:"set"})],ss.prototype,"attrValues",void 0);var O1=fg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,fg.prototype)}};O1=fg=Ie([T({type:S.Sequence,itemType:ss})],O1);var lg,P1=lg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,lg.prototype)}};P1=lg=Ie([T({type:S.Sequence,itemType:Sr})],P1);var FT="1.2.840.113549",WT=`${FT}.1`,N1=`${WT}.12`,Ca=`${N1}.1`,lq=`${Ca}.1`,pq=`${Ca}.2`,hq=`${Ca}.3`,dq=`${Ca}.4`,yq=`${Ca}.5`,mq=`${Ca}.6`,as=`${N1}.10.1`;var wq=`${as}.1`,xq=`${as}.2`,vq=`${as}.3`,_q=`${as}.4`,Sq=`${as}.5`,Aq=`${as}.6`,Vp="1.2.840.113549.1.9";var $p=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],$p.prototype,"certId",void 0);Ie([f({type:d.Any,context:0})],$p.prototype,"certValue",void 0);var k1=`${Vp}.22`,Iq=`${k1}.1`,Oq=`${k1}.2`;var Fp=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Fp.prototype,"crlId",void 0);Ie([f({type:d.Any,context:0})],Fp.prototype,"crltValue",void 0);var qT=`${Vp}.23`,Rq=`${qT}.1`;function Gn(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 Wp=class extends ae{},Ho=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Wp,Object.assign(this,e)}};Gn([f({type:M})],Ho.prototype,"encryptionAlgorithm",void 0);Gn([f({type:Wp})],Ho.prototype,"encryptedData",void 0);var pg,hg;(function(r){r[r.v1=0]="v1"})(hg||(hg={}));var qp=class extends ae{},dg=pg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,pg.prototype)}};dg=pg=Gn([T({type:S.Sequence,itemType:wt})],dg);var Vo=class{constructor(e={}){this.version=hg.v1,this.privateKeyAlgorithm=new M,this.privateKey=new qp,Object.assign(this,e)}};Gn([f({type:d.Integer})],Vo.prototype,"version",void 0);Gn([f({type:M})],Vo.prototype,"privateKeyAlgorithm",void 0);Gn([f({type:qp})],Vo.prototype,"privateKey",void 0);Gn([f({type:dg,implicit:!0,context:0,optional:!0})],Vo.prototype,"attributes",void 0);var D1=class extends Vo{};D1=Ie([T({type:S.Sequence})],D1);var R1=class extends Ho{};R1=Ie([T({type:S.Sequence})],R1);var Gp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Gp.prototype,"secretTypeId",void 0);Ie([f({type:d.Any,context:0})],Gp.prototype,"secretValue",void 0);var $o=class{constructor(e={}){this.mac=new ns,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Ie([f({type:ns})],$o.prototype,"mac",void 0);Ie([f({type:ae})],$o.prototype,"macSalt",void 0);Ie([f({type:d.Integer,defaultValue:1})],$o.prototype,"iterations",void 0);var cs=class{constructor(e={}){this.version=3,this.authSafe=new Sr,this.macData=new $o,Object.assign(this,e)}};Ie([f({type:d.Integer})],cs.prototype,"version",void 0);Ie([f({type:Sr})],cs.prototype,"authSafe",void 0);Ie([f({type:$o,optional:!0})],cs.prototype,"macData",void 0);var yg,Ta=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Ta.prototype,"bagId",void 0);Ie([f({type:d.Any,context:0})],Ta.prototype,"bagValue",void 0);Ie([f({type:ss,repeated:"set",optional:!0})],Ta.prototype,"bagAttributes",void 0);var j1=yg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,yg.prototype)}};j1=yg=Ie([T({type:S.Sequence,itemType:Ta})],j1);var mg,gg,bg,et="1.2.840.113549.1.9",UG=`${et}.0`,Z1=`${et}.24`,Lu=`${et}.25`,Y1=`${et}.26`,J1=`${et}.27`,MG=`${Z1}.1`,KG=`${Z1}.2`,HG=`${et}.1`,VG=`${et}.2`,$G=`${et}.3`,FG=`${et}.4`,WG=`${et}.5`,qG=`${et}.6`,Cg=`${et}.7`,GG=`${et}.8`,zG=`${et}.9`,XG=`${et}.13`,Uu=`${et}.14`,ZG=`${et}.15`,YG=`${et}.20`,JG=`${et}.21`;var QG=`${Lu}.1`,ez=`${Lu}.2`,tz=`${Lu}.3`,rz=`${Lu}.4`,nz=`${Lu}.5`,Mu="1.3.6.1.5.5.7.9",oz=`${Mu}.1`,iz=`${Mu}.2`,sz=`${Mu}.3`,az=`${Mu}.4`,cz=`${Mu}.5`,uz=`${Y1}.1`,fz=`${Y1}.2`,lz=`${J1}.1`,pz=`${J1}.2`,hz=`${et}.16`,dz=`${et}.22`,yz=`${et}.23`,mz=`${Um}.65`,zp=class extends st{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Be([f({type:d.IA5String})],zp.prototype,"ia5String",void 0);zp=Be([T({type:S.Choice})],zp);var L1=class extends Sr{};L1=Be([T({type:S.Sequence})],L1);var U1=class extends cs{};U1=Be([T({type:S.Sequence})],U1);var M1=class extends Ho{};M1=Be([T({type:S.Sequence})],M1);var wg=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.IA5String})],wg.prototype,"value",void 0);wg=Be([T({type:S.Choice})],wg);var K1=class extends zp{};K1=Be([T({type:S.Choice})],K1);var H1=class extends st{};H1=Be([T({type:S.Choice})],H1);var xg=class{constructor(e=new Date){this.value=e}};Be([f({type:d.GeneralizedTime})],xg.prototype,"value",void 0);xg=Be([T({type:S.Choice})],xg);var V1=class extends st{};V1=Be([T({type:S.Choice})],V1);var vg=class{constructor(e="M"){this.value=e}toString(){return this.value}};Be([f({type:d.PrintableString})],vg.prototype,"value",void 0);vg=Be([T({type:S.Choice})],vg);var Xp=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.PrintableString})],Xp.prototype,"value",void 0);Xp=Be([T({type:S.Choice})],Xp);var $1=class extends Xp{};$1=Be([T({type:S.Choice})],$1);var F1=class extends st{};F1=Be([T({type:S.Choice})],F1);var _g=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.ObjectIdentifier})],_g.prototype,"value",void 0);_g=Be([T({type:S.Choice})],_g);var W1=class extends Qe{};W1=Be([T({type:S.Choice})],W1);var Sg=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Be([f({type:d.Integer})],Sg.prototype,"value",void 0);Sg=Be([T({type:S.Choice})],Sg);var q1=class extends Zt{};q1=Be([T({type:S.Sequence})],q1);var ju=class extends st{};ju=Be([T({type:S.Choice})],ju);var G1=mg=class extends sr{constructor(e){super(e),Object.setPrototypeOf(this,mg.prototype)}};G1=mg=Be([T({type:S.Sequence})],G1);var z1=gg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,gg.prototype)}};z1=gg=Be([T({type:S.Set,itemType:$r})],z1);var Ag=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.BmpString})],Ag.prototype,"value",void 0);Ag=Be([T({type:S.Choice})],Ag);var Eg=class extends M{};Eg=Be([T({type:S.Sequence})],Eg);var X1=bg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,bg.prototype)}};X1=bg=Be([T({type:S.Sequence,itemType:Eg})],X1);function Wr(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 Tg,Ku=Tg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Tg.prototype)}};Ku=Tg=Wr([T({type:S.Sequence,itemType:wt})],Ku);var fn=class{constructor(e={}){this.version=0,this.subject=new je,this.subjectPKInfo=new xt,this.attributes=new Ku,Object.assign(this,e)}};Wr([f({type:d.Integer})],fn.prototype,"version",void 0);Wr([f({type:je})],fn.prototype,"subject",void 0);Wr([f({type:xt})],fn.prototype,"subjectPKInfo",void 0);Wr([f({type:Ku,implicit:!0,context:0})],fn.prototype,"attributes",void 0);var Fo=class{constructor(e={}){this.certificationRequestInfo=new fn,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Wr([f({type:fn,raw:!0})],Fo.prototype,"certificationRequestInfo",void 0);Wr([f({type:M})],Fo.prototype,"signatureAlgorithm",void 0);Wr([f({type:d.BitString})],Fo.prototype,"signature",void 0);var lf="crypto.algorithm",Lg=class{getAlgorithms(){return He.resolveAll(lf)}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}}},us="crypto.algorithmProvider";He.registerSingleton(us,Lg);var Qp,er="1.3.36.3.3.2.8.1.1",Q1=`${er}.1`,e_=`${er}.2`,t_=`${er}.3`,r_=`${er}.4`,n_=`${er}.5`,o_=`${er}.6`,i_=`${er}.7`,s_=`${er}.8`,a_=`${er}.9`,c_=`${er}.10`,u_=`${er}.11`,f_=`${er}.12`,l_=`${er}.13`,p_=`${er}.14`,h_="brainpoolP160r1",d_="brainpoolP160t1",y_="brainpoolP192r1",m_="brainpoolP192t1",g_="brainpoolP224r1",b_="brainpoolP224t1",w_="brainpoolP256r1",x_="brainpoolP256t1",v_="brainpoolP320r1",__="brainpoolP320t1",S_="brainpoolP384r1",A_="brainpoolP384t1",E_="brainpoolP512r1",C_="brainpoolP512t1",ze="ECDSA",af=Qp=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 Vv;case"sha-256":return $v;case"sha-384":return Fv;case"sha-512":return Wv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=zm;break;case"K-256":t=Qp.SECP256K1;break;case"P-384":t=Xm;break;case"P-521":t=Zm;break;case h_:t=Q1;break;case d_:t=e_;break;case y_:t=t_;break;case m_:t=r_;break;case g_:t=n_;break;case b_:t=o_;break;case w_:t=i_;break;case x_:t=s_;break;case v_:t=a_;break;case __:t=c_;break;case S_:t=u_;break;case A_:t=f_;break;case E_:t=l_;break;case C_:t=p_;break}if(t)return new M({algorithm:Yi,parameters:W.serialize(new an({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Eu:return{name:ze,hash:{name:"SHA-1"}};case Cu:return{name:ze,hash:{name:"SHA-256"}};case Tu:return{name:ze,hash:{name:"SHA-384"}};case Bu:return{name:ze,hash:{name:"SHA-512"}};case Yi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(W.parse(e.parameters,an).namedCurve){case zm:return{name:ze,namedCurve:"P-256"};case Qp.SECP256K1:return{name:ze,namedCurve:"K-256"};case Xm:return{name:ze,namedCurve:"P-384"};case Zm:return{name:ze,namedCurve:"P-521"};case Q1:return{name:ze,namedCurve:h_};case e_:return{name:ze,namedCurve:d_};case t_:return{name:ze,namedCurve:y_};case r_:return{name:ze,namedCurve:m_};case n_:return{name:ze,namedCurve:g_};case o_:return{name:ze,namedCurve:b_};case i_:return{name:ze,namedCurve:w_};case s_:return{name:ze,namedCurve:x_};case a_:return{name:ze,namedCurve:v_};case c_:return{name:ze,namedCurve:__};case u_:return{name:ze,namedCurve:S_};case f_:return{name:ze,namedCurve:A_};case l_:return{name:ze,namedCurve:E_};case p_:return{name:ze,namedCurve:C_}}}}return null}};af.SECP256K1="1.3.132.0.10";af=Qp=uu([Ko()],af);He.registerSingleton(lf,af);var L_=Symbol("name"),U_=Symbol("value"),Ce=class{constructor(e,t={},n=""){this[L_]=e,this[U_]=n;for(let o in t)this[o]=t[o]}};Ce.NAME=L_;Ce.VALUE=U_;var Ug=class{static toTextObject(e){let t=new Ce("Algorithm Identifier",{},pn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Yi:{let n=new af().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={[Qi]:"sha1",[Rp]:"sha224",[es]:"sha256",[ts]:"sha384",[rs]:"sha512",[cn]:"rsaEncryption",[ga]:"sha1WithRSAEncryption",[Zv]:"sha224WithRSAEncryption",[Dp]:"sha256WithRSAEncryption",[ba]:"sha384WithRSAEncryption",[wa]:"sha512WithRSAEncryption",[Yi]:"ecPublicKey",[Eu]:"ecdsaWithSHA1",[kp]:"ecdsaWithSHA224",[Cu]:"ecdsaWithSHA256",[Tu]:"ecdsaWithSHA384",[Bu]:"ecdsaWithSHA512",[_v]:"TLS WWW server authentication",[Sv]:"TLS WWW client authentication",[Av]:"Code Signing",[Ev]:"E-mail Protection",[Cv]:"Time Stamping",[Tv]:"OCSP Signing",[Kv]:"Signed Data"};var Xn=class{static serialize(e){return this.serializeObj(e).join(`
|
8
|
+
`)}function ag(r,e,t){var n=Nu(r.toString().match(/constructor\(([\w, ]+)\)/)||[],2),o=n[1],i=o===void 0?null:o,s=LT(i,e);return UT("Cannot inject the dependency "+s+' of "'+r.name+'" constructor. Reason:',t)}function B1(r){if(typeof r.dispose!="function")return!1;var e=r.dispose;return!(e.length>0)}var MT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du);var KT=(function(r){Aa(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e})(Du);var HT=(function(){function r(){this.preResolution=new MT,this.postResolution=new KT}return r})(),I1=HT;var cg=new Map,VT=(function(){function r(e){this.parent=e,this._registry=new T1,this.interceptors=new I1,this.disposed=!1,this.disposables=new Set}return r.prototype.register=function(e,t,n){n===void 0&&(n={lifecycle:At.Transient}),this.ensureNotDisposed();var o;if(C1(t)?o=t:o={useClass:t},os(o))for(var i=[e],s=o;s!=null;){var a=s.useToken;if(i.includes(a))throw new Error("Token registration cycle detected! "+Fr(i,[a]).join(" -> "));i.push(a);var c=this._registry.get(a);c&&os(c.provider)?s=c.provider:s=null}if((n.lifecycle===At.Singleton||n.lifecycle==At.ContainerScoped||n.lifecycle==At.ResolutionScoped)&&(is(o)||Ea(o)))throw new Error('Cannot use lifecycle "'+At[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(),Mo(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(),Mo(e)){if(Mo(t))return this.register(e,{useToken:t},{lifecycle:At.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:At.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var n=e;return t&&!Mo(t)&&(n=t),this.register(e,{useClass:n},{lifecycle:At.Singleton})},r.prototype.resolve=function(e,t,n){t===void 0&&(t=new Ru),n===void 0&&(n=!1),this.ensureNotDisposed();var o=this.getRegistration(e);if(!o&&Mo(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(E1(e)){var i=this.construct(e,t);return this.executePostResolutionInterceptor(e,i,"Single"),i}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},r.prototype.executePreResolutionInterceptor=function(e,t){var n,o;if(this.interceptors.preResolution.has(e)){var i=[];try{for(var s=Pu(this.interceptors.preResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;c.options.frequency!="Once"&&i.push(c),c.callback(e,t)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(n)throw n.error}}this.interceptors.preResolution.setAll(e,i)}},r.prototype.executePostResolutionInterceptor=function(e,t,n){var o,i;if(this.interceptors.postResolution.has(e)){var s=[];try{for(var a=Pu(this.interceptors.postResolution.getAll(e)),c=a.next();!c.done;c=a.next()){var u=c.value;u.options.frequency!="Once"&&s.push(u),u.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===At.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var n=e.options.lifecycle===At.Singleton,o=e.options.lifecycle===At.ContainerScoped,i=n||o,s;return is(e.provider)?s=e.provider.useValue:os(e.provider)?s=i?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):ku(e.provider)?s=i?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Ea(e.provider)?s=e.provider.useFactory(this):s=this.construct(e.provider,t),e.options.lifecycle===At.ResolutionScoped&&t.scopedResolutions.set(e,s),s},r.prototype.resolveAll=function(e,t,n){var o=this;t===void 0&&(t=new Ru),n===void 0&&(n=!1),this.ensureNotDisposed();var i=this.getAllRegistrations(e);if(!i&&Mo(e)){if(n)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),i){var s=i.map(function(c){return o.resolveRegistration(c,t)});return this.executePostResolutionInterceptor(e,s,"All"),s}var a=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,a,"All"),a},r.prototype.isRegistered=function(e,t){return t===void 0&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},r.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},r.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var n=Pu(this._registry.entries()),o=n.next();!o.done;o=n.next()){var i=Nu(o.value,2),s=i[0],a=i[1];this._registry.setAll(s,a.filter(function(c){return!is(c.provider)}).map(function(c){return c.instance=void 0,c}))}}catch(c){e={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},r.prototype.createChildContainer=function(){var e,t;this.ensureNotDisposed();var n=new r(this);try{for(var o=Pu(this._registry.entries()),i=o.next();!i.done;i=o.next()){var s=Nu(i.value,2),a=s[0],c=s[1];c.some(function(u){var p=u.options;return p.lifecycle===At.ContainerScoped})&&n._registry.setAll(a,c.map(function(u){return u.options.lifecycle===At.ContainerScoped?{provider:u.provider,options:u.options}:u}))}}catch(u){e={error:u}}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 S1(this,void 0,void 0,function(){var e;return A1(this,function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach(function(n){var o=n.dispose();o&&e.push(o)}),[4,Promise.all(e)];case 1:return t.sent(),[2]}})})},r.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},r.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},r.prototype.construct=function(e,t){var n=this;if(e instanceof Kp)return e.createProxy(function(i){return n.resolve(i,t)});var o=(function(){var i=cg.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,Fr([void 0],s)))})();return B1(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 sg(o)?Hp(o)?o.multiple?(s=n.resolve(o.transform)).transform.apply(s,Fr([n.resolveAll(o.token,new Ru,o.isOptional)],o.transformArgs)):(a=n.resolve(o.transform)).transform.apply(a,Fr([n.resolve(o.token,e,o.isOptional)],o.transformArgs)):o.multiple?n.resolveAll(o.token,new Ru,o.isOptional):n.resolve(o.token,e,o.isOptional):Hp(o)?(c=n.resolve(o.transform,e)).transform.apply(c,Fr([n.resolve(o.token,e)],o.transformArgs)):n.resolve(o,e)}catch(u){throw new Error(ag(t,i,u))}}},r.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},r})(),He=new VT;function $T(r){return function(e){cg.set(e,ig(e)),r&&r.token&&(Array.isArray(r.token)?r.token.forEach(function(t){He.register(t,e)}):He.register(r.token,e))}}var Ko=$T;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 Be(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var a=r.length-1;a>=0;a--)(s=r[a])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i}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}var fg,ss=class{constructor(e={}){this.attrId="",this.attrValues=[],Object.assign(e)}};Ie([f({type:d.ObjectIdentifier})],ss.prototype,"attrId",void 0);Ie([f({type:d.Any,repeated:"set"})],ss.prototype,"attrValues",void 0);var O1=fg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,fg.prototype)}};O1=fg=Ie([T({type:S.Sequence,itemType:ss})],O1);var lg,P1=lg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,lg.prototype)}};P1=lg=Ie([T({type:S.Sequence,itemType:Sr})],P1);var FT="1.2.840.113549",WT=`${FT}.1`,N1=`${WT}.12`,Ca=`${N1}.1`,fq=`${Ca}.1`,lq=`${Ca}.2`,pq=`${Ca}.3`,hq=`${Ca}.4`,dq=`${Ca}.5`,yq=`${Ca}.6`,as=`${N1}.10.1`;var bq=`${as}.1`,wq=`${as}.2`,xq=`${as}.3`,vq=`${as}.4`,_q=`${as}.5`,Sq=`${as}.6`,Vp="1.2.840.113549.1.9";var $p=class{constructor(e={}){this.certId="",this.certValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],$p.prototype,"certId",void 0);Ie([f({type:d.Any,context:0})],$p.prototype,"certValue",void 0);var k1=`${Vp}.22`,Bq=`${k1}.1`,Iq=`${k1}.2`;var Fp=class{constructor(e={}){this.crlId="",this.crltValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Fp.prototype,"crlId",void 0);Ie([f({type:d.Any,context:0})],Fp.prototype,"crltValue",void 0);var qT=`${Vp}.23`,Dq=`${qT}.1`;function Gn(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 Wp=class extends ae{},Ho=class{constructor(e={}){this.encryptionAlgorithm=new M,this.encryptedData=new Wp,Object.assign(this,e)}};Gn([f({type:M})],Ho.prototype,"encryptionAlgorithm",void 0);Gn([f({type:Wp})],Ho.prototype,"encryptedData",void 0);var pg,hg;(function(r){r[r.v1=0]="v1"})(hg||(hg={}));var qp=class extends ae{},dg=pg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,pg.prototype)}};dg=pg=Gn([T({type:S.Sequence,itemType:wt})],dg);var Vo=class{constructor(e={}){this.version=hg.v1,this.privateKeyAlgorithm=new M,this.privateKey=new qp,Object.assign(this,e)}};Gn([f({type:d.Integer})],Vo.prototype,"version",void 0);Gn([f({type:M})],Vo.prototype,"privateKeyAlgorithm",void 0);Gn([f({type:qp})],Vo.prototype,"privateKey",void 0);Gn([f({type:dg,implicit:!0,context:0,optional:!0})],Vo.prototype,"attributes",void 0);var D1=class extends Vo{};D1=Ie([T({type:S.Sequence})],D1);var R1=class extends Ho{};R1=Ie([T({type:S.Sequence})],R1);var Gp=class{constructor(e={}){this.secretTypeId="",this.secretValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Gp.prototype,"secretTypeId",void 0);Ie([f({type:d.Any,context:0})],Gp.prototype,"secretValue",void 0);var $o=class{constructor(e={}){this.mac=new ns,this.macSalt=new ae,this.iterations=1,Object.assign(this,e)}};Ie([f({type:ns})],$o.prototype,"mac",void 0);Ie([f({type:ae})],$o.prototype,"macSalt",void 0);Ie([f({type:d.Integer,defaultValue:1})],$o.prototype,"iterations",void 0);var cs=class{constructor(e={}){this.version=3,this.authSafe=new Sr,this.macData=new $o,Object.assign(this,e)}};Ie([f({type:d.Integer})],cs.prototype,"version",void 0);Ie([f({type:Sr})],cs.prototype,"authSafe",void 0);Ie([f({type:$o,optional:!0})],cs.prototype,"macData",void 0);var yg,Ta=class{constructor(e={}){this.bagId="",this.bagValue=new ArrayBuffer(0),Object.assign(this,e)}};Ie([f({type:d.ObjectIdentifier})],Ta.prototype,"bagId",void 0);Ie([f({type:d.Any,context:0})],Ta.prototype,"bagValue",void 0);Ie([f({type:ss,repeated:"set",optional:!0})],Ta.prototype,"bagAttributes",void 0);var j1=yg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,yg.prototype)}};j1=yg=Ie([T({type:S.Sequence,itemType:Ta})],j1);var mg,gg,bg,et="1.2.840.113549.1.9",LG=`${et}.0`,Z1=`${et}.24`,Lu=`${et}.25`,Y1=`${et}.26`,J1=`${et}.27`,UG=`${Z1}.1`,MG=`${Z1}.2`,KG=`${et}.1`,HG=`${et}.2`,VG=`${et}.3`,$G=`${et}.4`,FG=`${et}.5`,WG=`${et}.6`,Cg=`${et}.7`,qG=`${et}.8`,GG=`${et}.9`,zG=`${et}.13`,Uu=`${et}.14`,XG=`${et}.15`,ZG=`${et}.20`,YG=`${et}.21`;var JG=`${Lu}.1`,QG=`${Lu}.2`,ez=`${Lu}.3`,tz=`${Lu}.4`,rz=`${Lu}.5`,Mu="1.3.6.1.5.5.7.9",nz=`${Mu}.1`,oz=`${Mu}.2`,iz=`${Mu}.3`,sz=`${Mu}.4`,az=`${Mu}.5`,cz=`${Y1}.1`,uz=`${Y1}.2`,fz=`${J1}.1`,lz=`${J1}.2`,pz=`${et}.16`,hz=`${et}.22`,dz=`${et}.23`,yz=`${Um}.65`,zp=class extends st{constructor(e={}){super(e)}toString(){return{}.toString(),this.ia5String||super.toString()}};Be([f({type:d.IA5String})],zp.prototype,"ia5String",void 0);zp=Be([T({type:S.Choice})],zp);var L1=class extends Sr{};L1=Be([T({type:S.Sequence})],L1);var U1=class extends cs{};U1=Be([T({type:S.Sequence})],U1);var M1=class extends Ho{};M1=Be([T({type:S.Sequence})],M1);var wg=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.IA5String})],wg.prototype,"value",void 0);wg=Be([T({type:S.Choice})],wg);var K1=class extends zp{};K1=Be([T({type:S.Choice})],K1);var H1=class extends st{};H1=Be([T({type:S.Choice})],H1);var xg=class{constructor(e=new Date){this.value=e}};Be([f({type:d.GeneralizedTime})],xg.prototype,"value",void 0);xg=Be([T({type:S.Choice})],xg);var V1=class extends st{};V1=Be([T({type:S.Choice})],V1);var vg=class{constructor(e="M"){this.value=e}toString(){return this.value}};Be([f({type:d.PrintableString})],vg.prototype,"value",void 0);vg=Be([T({type:S.Choice})],vg);var Xp=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.PrintableString})],Xp.prototype,"value",void 0);Xp=Be([T({type:S.Choice})],Xp);var $1=class extends Xp{};$1=Be([T({type:S.Choice})],$1);var F1=class extends st{};F1=Be([T({type:S.Choice})],F1);var _g=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.ObjectIdentifier})],_g.prototype,"value",void 0);_g=Be([T({type:S.Choice})],_g);var W1=class extends Qe{};W1=Be([T({type:S.Choice})],W1);var Sg=class{constructor(e=0){this.value=e}toString(){return this.value.toString()}};Be([f({type:d.Integer})],Sg.prototype,"value",void 0);Sg=Be([T({type:S.Choice})],Sg);var q1=class extends Zt{};q1=Be([T({type:S.Sequence})],q1);var ju=class extends st{};ju=Be([T({type:S.Choice})],ju);var G1=mg=class extends sr{constructor(e){super(e),Object.setPrototypeOf(this,mg.prototype)}};G1=mg=Be([T({type:S.Sequence})],G1);var z1=gg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,gg.prototype)}};z1=gg=Be([T({type:S.Set,itemType:$r})],z1);var Ag=class{constructor(e=""){this.value=e}toString(){return this.value}};Be([f({type:d.BmpString})],Ag.prototype,"value",void 0);Ag=Be([T({type:S.Choice})],Ag);var Eg=class extends M{};Eg=Be([T({type:S.Sequence})],Eg);var X1=bg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,bg.prototype)}};X1=bg=Be([T({type:S.Sequence,itemType:Eg})],X1);function Wr(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 Tg,Ku=Tg=class extends se{constructor(e){super(e),Object.setPrototypeOf(this,Tg.prototype)}};Ku=Tg=Wr([T({type:S.Sequence,itemType:wt})],Ku);var fn=class{constructor(e={}){this.version=0,this.subject=new je,this.subjectPKInfo=new xt,this.attributes=new Ku,Object.assign(this,e)}};Wr([f({type:d.Integer})],fn.prototype,"version",void 0);Wr([f({type:je})],fn.prototype,"subject",void 0);Wr([f({type:xt})],fn.prototype,"subjectPKInfo",void 0);Wr([f({type:Ku,implicit:!0,context:0})],fn.prototype,"attributes",void 0);var Fo=class{constructor(e={}){this.certificationRequestInfo=new fn,this.signatureAlgorithm=new M,this.signature=new ArrayBuffer(0),Object.assign(this,e)}};Wr([f({type:fn,raw:!0})],Fo.prototype,"certificationRequestInfo",void 0);Wr([f({type:M})],Fo.prototype,"signatureAlgorithm",void 0);Wr([f({type:d.BitString})],Fo.prototype,"signature",void 0);var lf="crypto.algorithm",Lg=class{getAlgorithms(){return He.resolveAll(lf)}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}}},us="crypto.algorithmProvider";He.registerSingleton(us,Lg);var Qp,er="1.3.36.3.3.2.8.1.1",Q1=`${er}.1`,e_=`${er}.2`,t_=`${er}.3`,r_=`${er}.4`,n_=`${er}.5`,o_=`${er}.6`,i_=`${er}.7`,s_=`${er}.8`,a_=`${er}.9`,c_=`${er}.10`,u_=`${er}.11`,f_=`${er}.12`,l_=`${er}.13`,p_=`${er}.14`,h_="brainpoolP160r1",d_="brainpoolP160t1",y_="brainpoolP192r1",m_="brainpoolP192t1",g_="brainpoolP224r1",b_="brainpoolP224t1",w_="brainpoolP256r1",x_="brainpoolP256t1",v_="brainpoolP320r1",__="brainpoolP320t1",S_="brainpoolP384r1",A_="brainpoolP384t1",E_="brainpoolP512r1",C_="brainpoolP512t1",ze="ECDSA",af=Qp=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 Vv;case"sha-256":return $v;case"sha-384":return Fv;case"sha-512":return Wv}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=zm;break;case"K-256":t=Qp.SECP256K1;break;case"P-384":t=Xm;break;case"P-521":t=Zm;break;case h_:t=Q1;break;case d_:t=e_;break;case y_:t=t_;break;case m_:t=r_;break;case g_:t=n_;break;case b_:t=o_;break;case w_:t=i_;break;case x_:t=s_;break;case v_:t=a_;break;case __:t=c_;break;case S_:t=u_;break;case A_:t=f_;break;case E_:t=l_;break;case C_:t=p_;break}if(t)return new M({algorithm:Yi,parameters:W.serialize(new an({namedCurve:t}))})}}return null}toWebAlgorithm(e){switch(e.algorithm){case Eu:return{name:ze,hash:{name:"SHA-1"}};case Cu:return{name:ze,hash:{name:"SHA-256"}};case Tu:return{name:ze,hash:{name:"SHA-384"}};case Bu:return{name:ze,hash:{name:"SHA-512"}};case Yi:{if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(W.parse(e.parameters,an).namedCurve){case zm:return{name:ze,namedCurve:"P-256"};case Qp.SECP256K1:return{name:ze,namedCurve:"K-256"};case Xm:return{name:ze,namedCurve:"P-384"};case Zm:return{name:ze,namedCurve:"P-521"};case Q1:return{name:ze,namedCurve:h_};case e_:return{name:ze,namedCurve:d_};case t_:return{name:ze,namedCurve:y_};case r_:return{name:ze,namedCurve:m_};case n_:return{name:ze,namedCurve:g_};case o_:return{name:ze,namedCurve:b_};case i_:return{name:ze,namedCurve:w_};case s_:return{name:ze,namedCurve:x_};case a_:return{name:ze,namedCurve:v_};case c_:return{name:ze,namedCurve:__};case u_:return{name:ze,namedCurve:S_};case f_:return{name:ze,namedCurve:A_};case l_:return{name:ze,namedCurve:E_};case p_:return{name:ze,namedCurve:C_}}}}return null}};af.SECP256K1="1.3.132.0.10";af=Qp=uu([Ko()],af);He.registerSingleton(lf,af);var L_=Symbol("name"),U_=Symbol("value"),Ce=class{constructor(e,t={},n=""){this[L_]=e,this[U_]=n;for(let o in t)this[o]=t[o]}};Ce.NAME=L_;Ce.VALUE=U_;var Ug=class{static toTextObject(e){let t=new Ce("Algorithm Identifier",{},pn.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Yi:{let n=new af().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={[Qi]:"sha1",[Rp]:"sha224",[es]:"sha256",[ts]:"sha384",[rs]:"sha512",[cn]:"rsaEncryption",[ga]:"sha1WithRSAEncryption",[Zv]:"sha224WithRSAEncryption",[Dp]:"sha256WithRSAEncryption",[ba]:"sha384WithRSAEncryption",[wa]:"sha512WithRSAEncryption",[Yi]:"ecPublicKey",[Eu]:"ecdsaWithSHA1",[kp]:"ecdsaWithSHA224",[Cu]:"ecdsaWithSHA256",[Tu]:"ecdsaWithSHA384",[Bu]:"ecdsaWithSHA512",[_v]:"TLS WWW server authentication",[Sv]:"TLS WWW client authentication",[Av]:"Code Signing",[Ev]:"E-mail Protection",[Cv]:"Time Stamping",[Tv]:"OCSP Signing",[Kv]:"Signed Data"};var Xn=class{static serialize(e){return this.serializeObj(e).join(`
|
9
9
|
`)}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){let n=[],o=this.pad(t++),i="",s=e[Ce.VALUE];s&&(i=` ${s}`),n.push(`${o}${e[Ce.NAME]}:${i}`),o=this.pad(t);for(let a in e){if(typeof a=="symbol")continue;let c=e[a],u=a?`${a}: `:"";if(typeof c=="string"||typeof c=="number"||typeof c=="boolean")n.push(`${o}${u}${c}`);else if(c instanceof Date)n.push(`${o}${u}${c.toUTCString()}`);else if(Array.isArray(c))for(let p of c)p[Ce.NAME]=a,n.push(...this.serializeObj(p,t));else if(c instanceof Ce)c[Ce.NAME]=a,n.push(...this.serializeObj(c,t));else if(H.BufferSourceConverter.isBufferSource(c))a?(n.push(`${o}${u}`),n.push(...this.serializeBufferSource(c,t+1))):n.push(...this.serializeBufferSource(c,t));else if("toTextObject"in c){let p=c.toTextObject();p[Ce.NAME]=a,n.push(...this.serializeObj(p,t))}else throw new TypeError("Cannot serialize data in text format. Unsupported type.")}return n}static serializeBufferSource(e,t=0){let n=this.pad(t),o=H.BufferSourceConverter.toUint8Array(e),i=[];for(let s=0;s<o.length;){let a=[];for(let c=0;c<16&&s<o.length;c++){c===8&&a.push("");let u=o[s++].toString(16).padStart(2,"0");a.push(u)}i.push(`${n}${a.join(" ")}`)}return i}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}};Xn.oidSerializer=pn;Xn.algorithmSerializer=Ug;var Ba,Wo=class r{get rawData(){return de(this,Ba,"f")||Ge(this,Ba,W.serialize(this.asn),"f"),de(this,Ba,"f")}constructor(...e){Ba.set(this,void 0),H.BufferSourceConverter.isBufferSource(e[0])?(this.asn=W.parse(e[0],e[1]),Ge(this,Ba,H.BufferSourceConverter.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof r?(0,H.isEqual)(e.rawData,this.rawData):!1}toString(e="text"){switch(e){case"asn":return W.toString(this.rawData);case"text":return Xn.serialize(this.toTextObject());case"hex":return H.Convert.ToHex(this.rawData);case"base64":return H.Convert.ToBase64(this.rawData);case"base64url":return H.Convert.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){let e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new Ce(this.getTextName(),{},e)}};Ba=new WeakMap;Wo.NAME="ASN";var cr=class r extends Wo{constructor(...e){let t;H.BufferSourceConverter.isBufferSource(e[0])?t=H.BufferSourceConverter.toArrayBuffer(e[0]):t=W.serialize(new vt({extnID:e[0],critical:e[1],extnValue:new ae(H.BufferSourceConverter.toArrayBuffer(e[2]))})),super(t,vt)}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[Ce.NAME]===r.NAME&&(e[Ce.NAME]=pn.toString(this.type)),e}},M_,cf=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[M_]="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}};M_=Symbol.toStringTag;cf.DEFAULT="default";var yt=new cf,ZT=/^[0-2](?:\.[1-9][0-9]*)+$/;function YT(r){return new RegExp(ZT).test(r)}var th=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 YT(e)?e:this.get(e)}register(e,t){this.items[e]=t,this.items[t]=e}},Qt=new th;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 JT(r,e){return`\\${H.Convert.ToHex(H.Convert.FromUtf8String(e)).toUpperCase()}`}function QT(r){return r.replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,JT)}var qr=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 th,this.asn=new je;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 je?this.asn=e:H.BufferSourceConverter.isBufferSource(e)?this.asn=W.parse(e,je):this.asn=this.fromJSON(e)}getField(e){let t=this.extraNames.findId(e)||Qt.findId(e),n=[];for(let o of this.asn)for(let i of o)i.type===t&&n.push(i.value.toString());return n}getName(e){return this.extraNames.get(e)||Qt.get(e)}toString(){return this.asn.map(e=>e.map(t=>{let n=this.getName(t.type)||t.type,o=t.value.anyValue?`#${H.Convert.ToHex(t.value.anyValue)}`:QT(t.value.toString());return`${n}=${o}`}).join("+")).join(", ")}toJSON(){var e;let t=[];for(let n of this.asn){let o={};for(let i of n){let s=this.getName(i.type)||i.type;(e=o[s])!==null&&e!==void 0||(o[s]=[]),o[s].push(i.value.anyValue?`#${H.Convert.ToHex(i.value.anyValue)}`:i.value.toString())}t.push(o)}return t}fromString(e){let t=new je,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 u=o[3];s=this.getTypeOid(s);let p=this.createAttribute(s,a);i==="+"?t[t.length-1].push(p):t.push(new Co([p])),i=u}return t}fromJSON(e){let t=new je;for(let n of e){let o=new Co;for(let i in n){let s=this.getTypeOid(i),a=n[i];for(let c of a){let u=this.createAttribute(s,c);o.push(u)}}t.push(o)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){let n=new Pi({type:e});if(typeof t=="object")for(let o in t)switch(o){case"ia5String":n.value.ia5String=t[o];break;case"utf8String":n.value.utf8String=t[o];break;case"universalString":n.value.universalString=t[o];break;case"bmpString":n.value.bmpString=t[o];break;case"printableString":n.value.printableString=t[o];break}else if(t[0]==="#")n.value.anyValue=H.Convert.FromHex(t.slice(1));else{let o=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?n.value.ia5String=o:r.isPrintableString(o)?n.value.printableString=o:n.value.utf8String=o}return n}processStringValue(e){let t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/ig,`
|
10
10
|
`).replace(/\\0d/ig,"\r").replace(/\\0g/ig," ").replace(/\\(.)/g,"$1")}toArrayBuffer(){return W.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]||yt.get()):n=e[0]||yt.get(),await n.subtle.digest(o,this.toArrayBuffer())}},K_="Cannot initialize GeneralName from ASN.1 data.",T_=`${K_} Unsupported string format in use.`,eB=`${K_} Value doesn't match to GUID regular expression.`,B_=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,I_="1.3.6.1.4.1.311.25.1",O_="1.3.6.1.4.1.311.20.2.3",Bg="dns",Ig="dn",Og="email",Pg="ip",Ng="url",kg="guid",Dg="upn",Zp="id",ln=class extends Wo{constructor(...e){let t;if(e.length===2)switch(e[0]){case Ig:{let n=new qr(e[1]).toArrayBuffer(),o=W.parse(n,je);t=new ue({directoryName:o});break}case Bg:t=new ue({dNSName:e[1]});break;case Og:t=new ue({rfc822Name:e[1]});break;case kg:{let n=new RegExp(B_,"i").exec(e[1]);if(!n)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");let o=n.slice(1).map((i,s)=>s<3?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(i)).reverse()):i).join("");t=new ue({otherName:new To({typeId:I_,value:W.serialize(new ae(H.Convert.FromHex(o)))})});break}case Pg:t=new ue({iPAddress:e[1]});break;case Zp:t=new ue({registeredID:e[1]});break;case Dg:{t=new ue({otherName:new To({typeId:O_,value:W.serialize(om.toASN(e[1]))})});break}case Ng:t=new ue({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else H.BufferSourceConverter.isBufferSource(e[0])?t=W.parse(e[0],ue):t=e[0];super(t)}onInit(e){if(e.dNSName!=null)this.type=Bg,this.value=e.dNSName;else if(e.rfc822Name!=null)this.type=Og,this.value=e.rfc822Name;else if(e.iPAddress!=null)this.type=Pg,this.value=e.iPAddress;else if(e.uniformResourceIdentifier!=null)this.type=Ng,this.value=e.uniformResourceIdentifier;else if(e.registeredID!=null)this.type=Zp,this.value=e.registeredID;else if(e.directoryName!=null)this.type=Ig,this.value=new qr(e.directoryName).toString();else if(e.otherName!=null)if(e.otherName.typeId===I_){this.type=kg;let t=W.parse(e.otherName.value,ae),n=new RegExp(B_,"i").exec(H.Convert.ToHex(t));if(!n)throw new Error(eB);this.value=n.slice(1).map((o,i)=>i<3?H.Convert.ToHex(new Uint8Array(H.Convert.FromHex(o)).reverse()):o).join("-")}else if(e.otherName.typeId===O_)this.type=Dg,this.value=W.parse(e.otherName.value,st).toString();else throw new Error(T_);else throw new Error(T_)}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case Ig:case Bg:case kg:case Pg:case Zp:case Dg:case Ng:e=this.type.toUpperCase();break;case Og:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Zp&&(t=pn.toString(t)),new Ce(e,void 0,t)}},Zn=class extends Wo{constructor(e){let t;if(e instanceof qe)t=e;else if(Array.isArray(e)){let n=[];for(let o of e)if(o instanceof ue)n.push(o);else{let i=W.parse(new ln(o.type,o.value).rawData,ue);n.push(i)}t=new qe(n)}else if(H.BufferSourceConverter.isBufferSource(e))t=W.parse(e,qe);else throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");super(t)}onInit(e){let t=[];for(let n of e){let o=null;try{o=new ln(n)}catch{continue}t.push(o)}this.items=t}toJSON(){return this.items.map(e=>e.toJSON())}toTextObject(){let e=super.toTextObjectEmpty();for(let t of this.items){let n=t.toTextObject(),o=e[n[Ce.NAME]];Array.isArray(o)||(o=[],e[n[Ce.NAME]]=o),o.push(n)}return e}};Zn.NAME="GeneralNames";var sf="-{5}",uf="\\n",tB=`[^${uf}]+`,rB=`${sf}BEGIN (${tB}(?=${sf}))${sf}`,nB=`${sf}END \\1${sf}`,Pa="\\n",oB=`[^:${uf}]+`,iB=`(?:[^${uf}]+${Pa}(?: +[^${uf}]+${Pa})*)`,sB="[a-zA-Z0-9=+/]+",aB=`(?:${sB}${Pa})+`,P_=`${rB}${Pa}(?:((?:${oB}: ${iB})+))?${Pa}?(${aB})${nB}`,Vt=class{static isPem(e){return typeof e=="string"&&new RegExp(P_,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");let t=new RegExp(P_,"g"),n=[],o=null;for(;o=t.exec(e);){let i=o[3].replace(new RegExp(`[${uf}]+`,"g"),""),s={type:o[1],headers:[],rawData:H.Convert.FromBase64(i)},a=o[2];if(a){let c=a.split(new RegExp(Pa,"g")),u=null;for(let p of c){let[l,h]=p.split(/:(.*)/);if(h===void 0){if(!u)throw new Error("Cannot parse PEM string. Incorrect header value");u.value+=l.trim()}else u&&s.headers.push(u),u={key:l,value:h.trim()}}u&&s.headers.push(u)}n.push(s)}return n}static decode(e){return this.decodeWithHeaders(e).map(n=>n.rawData)}static decodeFirst(e){let t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){let n=new Array;return t?e.forEach(o=>{if(!H.BufferSourceConverter.isBufferSource(o))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");n.push(this.encodeStruct({type:t,rawData:H.BufferSourceConverter.toArrayBuffer(o)}))}):e.forEach(o=>{if(!("type"in o))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");n.push(this.encodeStruct(o))}),n.join(`
|
11
11
|
`)}else{if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:H.BufferSourceConverter.toArrayBuffer(e)})}}static encodeStruct(e){var t;let n=e.type.toLocaleUpperCase(),o=[];if(o.push(`-----BEGIN ${n}-----`),!((t=e.headers)===null||t===void 0)&&t.length){for(let u of e.headers)o.push(`${u.key}: ${u.value}`);o.push("")}let i=H.Convert.ToBase64(e.rawData),s,a=0,c=Array();for(;a<i.length&&(i.length-a<64?s=i.substring(a):(s=i.substring(a,a+64),a+=64),s.length!==0);)if(c.push(s),s.length<64)break;return o.push(...c),o.push(`-----END ${n}-----`),o.join(`
|
12
|
-
`)}};Vt.CertificateTag="CERTIFICATE";Vt.CrlTag="CRL";Vt.CertificateRequestTag="CERTIFICATE REQUEST";Vt.PublicKeyTag="PUBLIC KEY";Vt.PrivateKeyTag="PRIVATE KEY";var qo=class r extends Wo{static isAsnEncoded(e){return H.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Vt.isPem(e))return Vt.decode(e)[0];if(H.Convert.isHex(e))return H.Convert.FromHex(e);if(H.Convert.isBase64(e))return H.Convert.FromBase64(e);if(H.Convert.isBase64Url(e))return H.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=H.BufferSourceConverter.toUint8Array(e);if(t.length>0&&t[0]===48)return H.BufferSourceConverter.toArrayBuffer(e);let n=H.Convert.ToBinary(e);if(Vt.isPem(n))return Vt.decode(n)[0];if(H.Convert.isHex(n))return H.Convert.FromHex(n);if(H.Convert.isBase64(n))return H.Convert.FromBase64(n);if(H.Convert.isBase64Url(n))return H.Convert.FromBase64Url(n);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Vt.encode(this.rawData,this.tag);default:return super.toString(e)}}},zn=class r extends qo{static async create(e,t=yt.get()){if(e instanceof r)return e;if(cf.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(H.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){qo.isAsnEncoded(e)?super(e,xt):super(e),this.tag=Vt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||yt.get()):t=e[0]||yt.get();let i=this.rawData,s=W.parse(this.rawData,xt);return s.algorithm.algorithm===Lo&&(i=cB(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=He.resolve(us),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case cn:{let o=W.parse(e.subjectPublicKey,_a),i=H.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=H.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||yt.get()):n=e[0]||yt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=yt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=yt.get();let o=W.parse(this.rawData,xt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,xt);switch(e.Algorithm=Xn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Yi:e["EC Point"]=t.subjectPublicKey;break;case cn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function cB(r,e){return r.algorithm=new M({algorithm:cn,parameters:null}),e=W.serialize(r),e}var rh=class r extends cr{static async create(e,t=!1,n=yt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new rn({keyIdentifier:new Di(H.Convert.FromHex(e[0]))});super(pp,e[1],W.serialize(t))}else{let t=e[0],n=t.name instanceof Zn?W.parse(t.name.rawData,qe):t.name,o=new rn({authorityCertIssuer:n,authorityCertSerialNumber:H.Convert.FromHex(t.serialNumber)});super(pp,e[1],W.serialize(o))}}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,rn);t.keyIdentifier&&(this.keyId=H.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?H.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,rn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Zn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};rh.NAME="Authority Key Identifier";var Na=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,Ri);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new Ri({cA:e[0],pathLenConstraint:e[1]});super(hp,e[2],W.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}};Na.NAME="Basic Constraints";var N_;(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"})(N_||(N_={}));var nh=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,iu);this.usages=t.map(n=>n)}else{let t=new iu(e[0]);super(gp,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>pn.toString(t)).join(", "),e}};nh.NAME="Extended Key Usages";var k_;(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"})(k_||(k_={}));var oh=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,ea);this.usages=t.toNumber()}else{let t=new ea(e[0]);super(bp,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,ea);return e[""]=t.toJSON().join(", "),e}};oh.NAME="Key Usages";var ih=class r extends cr{static async create(e,t=!1,n=yt.get()){let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,zt);this.keyId=H.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?H.Convert.FromHex(e[0]):e[0],n=new zt(t);super(Pm,e[1],W.serialize(n)),this.keyId=H.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,zt);return e[""]=t,e}};ih.NAME="Subject Key Identifier";var sh=class extends cr{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Im,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,_p);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};sh.NAME="Subject Alternative Name";var $t=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new cr(e),n=this.items.get(t.type);return n?new n(e):t}};$t.items=new Map;var ah=class extends cr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=W.parse(this.value,eu);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new eu(n.map(s=>new ji({policyIdentifier:s})));super(yp,o,W.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Ce("",{},pn.toString(t))),e}};ah.NAME="Certificate Policies";$t.register(yp,ah);var ch=class extends cr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new nn({distributionPoint:new Hn({fullName:[new ue({uniformResourceIdentifier:s})]})})),i=new Oo(o);super(mp,e[1],W.serialize(i))}else{let n=new Oo(e[0]);super(mp,e[1],W.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,Oo);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new ln(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};ch.NAME="CRL Distribution Points";var uh=class extends cr{constructor(...e){var t,n,o,i;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof ki){let s=new ki(e[0]);super(lp,e[1],W.serialize(s))}else{let s=e[0],a=new ki;Jp(a,s,pm,"ocsp"),Jp(a,s,hm,"caIssuers"),Jp(a,s,dm,"timeStamping"),Jp(a,s,ym,"caRepository"),super(lp,e[1],W.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=[],W.parse(e.extnValue,ki).forEach(n=>{switch(n.accessMethod){case pm:this.ocsp.push(new ln(n.accessLocation));break;case hm:this.caIssuers.push(new ln(n.accessLocation));break;case dm:this.timeStamping.push(new ln(n.accessLocation));break;case ym:this.caRepository.push(new ln(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&Yp(e,"OCSP",this.ocsp),this.caIssuers.length&&Yp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Yp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Yp(e,"CA Repository",this.caRepository),e}};uh.NAME="Authority Info Access";function Yp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Ce("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Ce.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function Jp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new ln("url",s)),r.push(new Mn({accessMethod:t,accessLocation:W.parse(s.rawData,ue)}))})}var fh=class extends cr{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Em,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,qe);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};fh.NAME="Issuer Alternative Name";var ka=class r extends Wo{constructor(...e){let t;if(H.BufferSourceConverter.isBufferSource(e[0]))t=H.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>H.BufferSourceConverter.toArrayBuffer(i)):[];t=W.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 Ce("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Ce.NAME]===r.NAME&&(e[Ce.NAME]=pn.toString(this.type)),e}};ka.NAME="Attribute";var lh=class extends ka{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new ju({printableString:e[0]});super(Cg,[W.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],ju);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Ce.VALUE]=this.password,e}};lh.NAME="Challenge Password";var ff=class extends ka{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new sr;for(let i of n)o.push(W.parse(i.rawData,vt));super(Uu,[W.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],sr);this.items=t.map(n=>$t.create(W.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Ce.NAME]]=n;return e}};ff.NAME="Extensions";var Da=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ka(e),n=this.items.get(t.type);return n?new n(e):t}};Da.items=new Map;var pf="crypto.signatureFormatter",Mg=class{toAsnSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}},eh,Kg=eh=class{static createPssParams(e,t){let n=eh.getHashAlgorithm(e);return n?new un({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:Uo,parameters:W.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=He.resolve(us);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:ga,parameters:null});case"sha-256":return new M({algorithm:Dp,parameters:null});case"sha-384":return new M({algorithm:ba,parameters:null});case"sha-512":return new M({algorithm:wa,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=eh.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Lo,parameters:W.serialize(t)})}else return new M({algorithm:Lo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case cn:return{name:"RSASSA-PKCS1-v1_5"};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Dp:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ba:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case wa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Lo:if(e.parameters){let t=W.parse(e.parameters,un);return{name:"RSA-PSS",hash:He.resolve(us).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Kg=eh=uu([Ko()],Kg);He.registerSingleton(lf,Kg);var Hg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Qi});case"sha-256":return new M({algorithm:es});case"sha-384":return new M({algorithm:ts});case"sha-512":return new M({algorithm:rs})}return null}toWebAlgorithm(e){switch(e.algorithm){case Qi:return{name:"SHA-1"};case es:return{name:"SHA-256"};case ts:return{name:"SHA-384"};case rs:return{name:"SHA-512"}}return null}};Hg=uu([Ko()],Hg);He.registerSingleton(lf,Hg);var Yn=class r{addPadding(e,t){let n=H.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o.buffer}removePadding(e,t=!1){let n=H.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new Ji,s=H.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),W.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=W.parse(t,Ji),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,H.combine)(s,a)}return null}};Yn.namedCurveSize=new Map;Yn.defaultNamedCurveSize=32;var Rg="1.3.101.110",D_="1.3.101.111",jg="1.3.101.112",R_="1.3.101.113",Vg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=jg;break;case"x25519":t=Rg;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=jg;break;case"ed448":t=R_;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Rg;break;case"x448":t=D_;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case jg:return{name:"Ed25519"};case R_:return{name:"EdDSA",namedCurve:"Ed448"};case Rg:return{name:"X25519"};case D_:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Vg=uu([Ko()],Vg);He.registerSingleton(lf,Vg);var Hu,Vu,$u,Fu,Wu,qu,Gu,Ia,$g=class extends qo{get subjectName(){return de(this,Vu,"f")||Ge(this,Vu,new qr(this.asn.certificationRequestInfo.subject),"f"),de(this,Vu,"f")}get subject(){return de(this,$u,"f")||Ge(this,$u,this.subjectName.toString(),"f"),de(this,$u,"f")}get signatureAlgorithm(){if(!de(this,Fu,"f")){let e=He.resolve(us);Ge(this,Fu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return de(this,Fu,"f")}get signature(){return de(this,Wu,"f")||Ge(this,Wu,this.asn.signature,"f"),de(this,Wu,"f")}get publicKey(){return de(this,qu,"f")||Ge(this,qu,new zn(this.asn.certificationRequestInfo.subjectPKInfo),"f"),de(this,qu,"f")}get attributes(){return de(this,Gu,"f")||Ge(this,Gu,this.asn.certificationRequestInfo.attributes.map(e=>Da.create(W.serialize(e))),"f"),de(this,Gu,"f")}get extensions(){if(!de(this,Ia,"f")){Ge(this,Ia,[],"f");let e=this.getAttribute(Uu);e instanceof ff&&Ge(this,Ia,e.items,"f")}return de(this,Ia,"f")}get tbs(){return de(this,Hu,"f")||Ge(this,Hu,this.asn.certificationRequestInfoRaw||W.serialize(this.asn.certificationRequestInfo),"f"),de(this,Hu,"f")}constructor(e){let t=qo.isAsnEncoded(e)?[e,Fo]:[e];super(t[0],t[1]),Hu.set(this,void 0),Vu.set(this,void 0),$u.set(this,void 0),Fu.set(this,void 0),Wu.set(this,void 0),qu.set(this,void 0),Gu.set(this,void 0),Ia.set(this,void 0),this.tag=Vt.CertificateRequestTag}onInit(e){}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=yt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=He.resolveAll(pf).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=W.parse(this.rawData,Fo),n=t.certificationRequestInfo,o=new Ce("",{Version:`${on[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Ce("");for(let s of this.attributes){let a=s.toTextObject();i[a[Ce.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Ce("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Hu=new WeakMap,Vu=new WeakMap,$u=new WeakMap,Fu=new WeakMap,Wu=new WeakMap,qu=new WeakMap,Gu=new WeakMap,Ia=new WeakMap;$g.NAME="PKCS#10 Certificate Request";var zu,Xu,Zu,Yu,Ju,Qu,ef,tf,rf,nf,Oa,of,Ra=class extends qo{get publicKey(){return de(this,of,"f")||Ge(this,of,new zn(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),de(this,of,"f")}get serialNumber(){if(!de(this,Xu,"f")){let e=this.asn.tbsCertificate,t=new Uint8Array(e.serialNumber);t.length>1&&t[0]===0&&t[1]>127&&(t=t.slice(1)),Ge(this,Xu,H.Convert.ToHex(t),"f")}return de(this,Xu,"f")}get subjectName(){return de(this,Zu,"f")||Ge(this,Zu,new qr(this.asn.tbsCertificate.subject),"f"),de(this,Zu,"f")}get subject(){return de(this,Yu,"f")||Ge(this,Yu,this.subjectName.toString(),"f"),de(this,Yu,"f")}get issuerName(){return de(this,Ju,"f")||Ge(this,Ju,new qr(this.asn.tbsCertificate.issuer),"f"),de(this,Ju,"f")}get issuer(){return de(this,Qu,"f")||Ge(this,Qu,this.issuerName.toString(),"f"),de(this,Qu,"f")}get notBefore(){if(!de(this,ef,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Ge(this,ef,e,"f")}return de(this,ef,"f")}get notAfter(){if(!de(this,tf,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Ge(this,tf,e,"f")}return de(this,tf,"f")}get signatureAlgorithm(){if(!de(this,rf,"f")){let e=He.resolve(us);Ge(this,rf,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return de(this,rf,"f")}get signature(){return de(this,nf,"f")||Ge(this,nf,this.asn.signatureValue,"f"),de(this,nf,"f")}get extensions(){return de(this,Oa,"f")||(Ge(this,Oa,[],"f"),this.asn.tbsCertificate.extensions&&Ge(this,Oa,this.asn.tbsCertificate.extensions.map(e=>$t.create(W.serialize(e))),"f")),de(this,Oa,"f")}get tbs(){return de(this,zu,"f")||Ge(this,zu,this.asn.tbsCertificateRaw||W.serialize(this.asn.tbsCertificate),"f"),de(this,zu,"f")}constructor(e){let t=qo.isAsnEncoded(e)?[e,xr]:[e];super(t[0],t[1]),zu.set(this,void 0),Xu.set(this,void 0),Zu.set(this,void 0),Yu.set(this,void 0),Ju.set(this,void 0),Qu.set(this,void 0),ef.set(this,void 0),tf.set(this,void 0),rf.set(this,void 0),nf.set(this,void 0),Oa.set(this,void 0),of.set(this,void 0),this.tag=Vt.CertificateTag}onInit(e){}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=yt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof zn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(H.BufferSourceConverter.isBufferSource(i)){let u=new zn(i);n={...u.algorithm,...this.signatureAlgorithm},o=await u.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=He.resolveAll(pf).reverse(),a=null;for(let u of s)if(a=u.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=yt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=yt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,xr),n=t.tbsCertificate,o=new Ce("",{Version:`${on[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Xn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Ce("",{"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 Ce("");for(let s of this.extensions){let a=s.toTextObject();i[a[Ce.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Ce("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};zu=new WeakMap,Xu=new WeakMap,Zu=new WeakMap,Yu=new WeakMap,Ju=new WeakMap,Qu=new WeakMap,ef=new WeakMap,tf=new WeakMap,rf=new WeakMap,nf=new WeakMap,Oa=new WeakMap,of=new WeakMap;Ra.NAME="Certificate";function uB(r,e=yt.get()){let t=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(r||"")),n=t&&t.length&&t.some(i=>i>0)?new Uint8Array(t):void 0;n||(n=e.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n.buffer}var ph=class{static async createSelfSigned(e,t=yt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=yt.get()){var n;let o;e.publicKey instanceof zn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:H.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=uB(e.serialNumber),s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new xr({tbsCertificate:new _t({version:on.v3,serialNumber:i,validity:new Vn({notBefore:s,notAfter:a}),extensions:new sr(((n=e.extensions)===null||n===void 0?void 0:n.map(g=>W.parse(g.rawData,vt)))||[]),subjectPublicKeyInfo:W.parse(o,xt)})});if(e.subject){let g=e.subject instanceof qr?e.subject:new qr(e.subject);c.tbsCertificate.subject=W.parse(g.toArrayBuffer(),je)}if(e.issuer){let g=e.issuer instanceof qr?e.issuer:new qr(e.issuer);c.tbsCertificate.issuer=W.parse(g.toArrayBuffer(),je)}let u={hash:"SHA-256"},p="signingKey"in e?{...u,...e.signingAlgorithm,...e.signingKey.algorithm}:{...u,...e.signingAlgorithm},l=He.resolve(us);c.tbsCertificate.signature=c.signatureAlgorithm=l.toAsnAlgorithm(p);let h=W.serialize(c.tbsCertificate),y="signingKey"in e?await t.subtle.sign(p,e.signingKey,h):e.signature,m=He.resolveAll(pf).reverse(),w=null;for(let g of m)if(w=g.toAsnSignature(p,y),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new Ra(W.serialize(c))}},fB,lB,pB,hB,dB,j_;(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"})(j_||(j_={}));fB=new WeakMap,lB=new WeakMap,pB=new WeakMap,hB=new WeakMap,dB=new WeakMap;var yB,mB,gB,bB,wB,xB,vB;yB=new WeakMap,mB=new WeakMap,gB=new WeakMap,bB=new WeakMap,wB=new WeakMap,xB=new WeakMap,vB=new WeakMap;$t.register(hp,Na);$t.register(gp,nh);$t.register(bp,oh);$t.register(Pm,ih);$t.register(pp,rh);$t.register(Im,sh);$t.register(mp,ch);$t.register(lp,uh);$t.register(Em,fh);Da.register(Cg,lh);Da.register(Uu,ff);He.registerSingleton(pf,Mg);He.registerSingleton(pf,Yn);Yn.namedCurveSize.set("P-256",32);Yn.namedCurveSize.set("K-256",32);Yn.namedCurveSize.set("P-384",48);Yn.namedCurveSize.set("P-521",66);var Jn="/",H_=new TextEncoder().encode(Jn),hh=H_[0],hf=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=ye(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]!==hh)throw new Error("Invalid key")}toString(e="utf8"){return le(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Jn))}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=H_),this._buf[0]!==hh){let e=new Uint8Array(this._buf.byteLength+1);e.fill(hh,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===hh;)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(Jn).slice(1)}type(){return _B(this.baseNamespace())}name(){return SB(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Jn)||(e+=Jn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Jn):new r(e.slice(0,-1).join(Jn))}child(e){return this.toString()===Jn?e:e.toString()===Jn?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(),...AB(e.map(t=>t.namespaces()))])}};function _B(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function SB(r){let e=r.split(":");return e[e.length-1]}function AB(r){return[].concat(...r)}var dh=class extends fr{async listen(){throw new Ul("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var ja=!!globalThis.process?.env?.DUMP_SESSION_KEYS,Fg=16;function $_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function yh(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function mh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function kt(r,...e){if(!$_(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 Wg(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 F_(r,e){kt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Qn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function eo(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function EB(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var CB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function TB(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function gh(r){if(typeof r=="string")r=TB(r);else if($_(r))r=bh(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function W_(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function q_(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 qg=(r,e)=>{function t(n,...o){if(kt(n),!CB)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?kt(p):kt(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&kt(o[1]);let s=e(n,...o),a=(p,l)=>{if(l!==void 0){if(p!==2)throw new Error("cipher output not supported");kt(l)}},c=!1;return{encrypt(p,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,kt(p),a(s.encrypt.length,l),s.encrypt(p,l)},decrypt(p,l){if(kt(p),i&&p.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,l),s.decrypt(p,l)}}}return Object.assign(t,r),t};function Gg(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&&!BB(e))throw new Error("invalid output, must be aligned");return e}function V_(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,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function G_(r,e,t){yh(t);let n=new Uint8Array(16),o=EB(n);return V_(o,0,BigInt(e),t),V_(o,8,BigInt(r),t),n}function BB(r){return r.byteOffset%4===0}function bh(r){return Uint8Array.from(r)}var X_=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),IB=X_("expand 16-byte k"),OB=X_("expand 32-byte k"),PB=Qn(IB),NB=Qn(OB);function re(r,e){return r<<e|r>>>32-e}function zg(r){return r.byteOffset%4===0}var wh=64,kB=16,Z_=2**32-1,z_=new Uint32Array;function DB(r,e,t,n,o,i,s,a){let c=o.length,u=new Uint8Array(wh),p=Qn(u),l=zg(o)&&zg(i),h=l?Qn(o):z_,y=l?Qn(i):z_;for(let m=0;m<c;s++){if(r(e,t,n,p,s,a),s>=Z_)throw new Error("arx: counter overflow");let w=Math.min(wh,c-m);if(l&&w===wh){let g=m/4;if(m%4!==0)throw new Error("arx: invalid block position");for(let A=0,D;A<kB;A++)D=g+A,y[D]=h[D]^p[A];m+=wh;continue}for(let g=0,A;g<w;g++)A=m+g,i[A]=o[A]^u[g];m+=w}}function Xg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=W_({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return mh(o),mh(s),yh(i),yh(t),(a,c,u,p,l=0)=>{kt(a),kt(c),kt(u);let h=u.length;if(p===void 0&&(p=new Uint8Array(h)),kt(p),mh(l),l<0||l>=Z_)throw new Error("arx: counter overflow");if(p.length<h)throw new Error(`arx: output (${p.length}) is shorter than data (${h})`);let y=[],m=a.length,w,g;if(m===32)y.push(w=bh(a)),g=NB;else if(m===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),g=PB,y.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${m}`);zg(c)||y.push(c=bh(c));let A=Qn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,A,Qn(c.subarray(0,16)),A),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let $=new Uint8Array(12);$.set(c,i?0:12-c.length),c=$,y.push(c)}let B=Qn(c);return DB(r,g,A,B,u,p,l,s),eo(...y),p}}var Et=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Zg=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=gh(e),kt(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),u=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|u<<8)&8191,this.r[9]=u>>>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],u=s[2],p=s[3],l=s[4],h=s[5],y=s[6],m=s[7],w=s[8],g=s[9],A=Et(e,t+0),D=Et(e,t+2),B=Et(e,t+4),$=Et(e,t+6),Q=Et(e,t+8),X=Et(e,t+10),ne=Et(e,t+12),Y=Et(e,t+14),I=i[0]+(A&8191),K=i[1]+((A>>>13|D<<3)&8191),z=i[2]+((D>>>10|B<<6)&8191),V=i[3]+((B>>>7|$<<9)&8191),x=i[4]+(($>>>4|Q<<12)&8191),v=i[5]+(Q>>>1&8191),E=i[6]+((Q>>>14|X<<2)&8191),N=i[7]+((X>>>11|ne<<5)&8191),j=i[8]+((ne>>>8|Y<<8)&8191),U=i[9]+(Y>>>5|o),P=0,L=P+I*a+K*(5*g)+z*(5*w)+V*(5*m)+x*(5*y);P=L>>>13,L&=8191,L+=v*(5*h)+E*(5*l)+N*(5*p)+j*(5*u)+U*(5*c),P+=L>>>13,L&=8191;let q=P+I*c+K*a+z*(5*g)+V*(5*w)+x*(5*m);P=q>>>13,q&=8191,q+=v*(5*y)+E*(5*h)+N*(5*l)+j*(5*p)+U*(5*u),P+=q>>>13,q&=8191;let R=P+I*u+K*c+z*a+V*(5*g)+x*(5*w);P=R>>>13,R&=8191,R+=v*(5*m)+E*(5*y)+N*(5*h)+j*(5*l)+U*(5*p),P+=R>>>13,R&=8191;let he=P+I*p+K*u+z*c+V*a+x*(5*g);P=he>>>13,he&=8191,he+=v*(5*w)+E*(5*m)+N*(5*y)+j*(5*h)+U*(5*l),P+=he>>>13,he&=8191;let be=P+I*l+K*p+z*u+V*c+x*a;P=be>>>13,be&=8191,be+=v*(5*g)+E*(5*w)+N*(5*m)+j*(5*y)+U*(5*h),P+=be>>>13,be&=8191;let te=P+I*h+K*l+z*p+V*u+x*c;P=te>>>13,te&=8191,te+=v*a+E*(5*g)+N*(5*w)+j*(5*m)+U*(5*y),P+=te>>>13,te&=8191;let Se=P+I*y+K*h+z*l+V*p+x*u;P=Se>>>13,Se&=8191,Se+=v*c+E*a+N*(5*g)+j*(5*w)+U*(5*m),P+=Se>>>13,Se&=8191;let Te=P+I*m+K*y+z*h+V*l+x*p;P=Te>>>13,Te&=8191,Te+=v*u+E*c+N*a+j*(5*g)+U*(5*w),P+=Te>>>13,Te&=8191;let Ue=P+I*w+K*m+z*y+V*h+x*l;P=Ue>>>13,Ue&=8191,Ue+=v*p+E*u+N*c+j*a+U*(5*g),P+=Ue>>>13,Ue&=8191;let Ee=P+I*g+K*w+z*m+V*y+x*h;P=Ee>>>13,Ee&=8191,Ee+=v*l+E*p+N*u+j*c+U*a,P+=Ee>>>13,Ee&=8191,P=(P<<2)+P|0,P=P+L|0,L=P&8191,P=P>>>13,q+=P,i[0]=L,i[1]=q,i[2]=R,i[3]=he,i[4]=be,i[5]=te,i[6]=Se,i[7]=Te,i[8]=Ue,i[9]=Ee}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;eo(n)}update(e){Wg(this),e=gh(e),kt(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(){eo(this.h,this.r,this.buffer,this.pad)}digestInto(e){Wg(this),F_(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 RB(r){let e=(n,o)=>r(o).update(gh(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var Y_=RB(r=>new Zg(r));function eS(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],u=r[3],p=e[0],l=e[1],h=e[2],y=e[3],m=e[4],w=e[5],g=e[6],A=e[7],D=o,B=t[0],$=t[1],Q=t[2],X=s,ne=a,Y=c,I=u,K=p,z=l,V=h,x=y,v=m,E=w,N=g,j=A,U=D,P=B,L=$,q=Q;for(let he=0;he<i;he+=2)X=X+K|0,U=re(U^X,16),v=v+U|0,K=re(K^v,12),X=X+K|0,U=re(U^X,8),v=v+U|0,K=re(K^v,7),ne=ne+z|0,P=re(P^ne,16),E=E+P|0,z=re(z^E,12),ne=ne+z|0,P=re(P^ne,8),E=E+P|0,z=re(z^E,7),Y=Y+V|0,L=re(L^Y,16),N=N+L|0,V=re(V^N,12),Y=Y+V|0,L=re(L^Y,8),N=N+L|0,V=re(V^N,7),I=I+x|0,q=re(q^I,16),j=j+q|0,x=re(x^j,12),I=I+x|0,q=re(q^I,8),j=j+q|0,x=re(x^j,7),X=X+z|0,q=re(q^X,16),N=N+q|0,z=re(z^N,12),X=X+z|0,q=re(q^X,8),N=N+q|0,z=re(z^N,7),ne=ne+V|0,U=re(U^ne,16),j=j+U|0,V=re(V^j,12),ne=ne+V|0,U=re(U^ne,8),j=j+U|0,V=re(V^j,7),Y=Y+x|0,P=re(P^Y,16),v=v+P|0,x=re(x^v,12),Y=Y+x|0,P=re(P^Y,8),v=v+P|0,x=re(x^v,7),I=I+K|0,L=re(L^I,16),E=E+L|0,K=re(K^E,12),I=I+K|0,L=re(L^I,8),E=E+L|0,K=re(K^E,7);let R=0;n[R++]=s+X|0,n[R++]=a+ne|0,n[R++]=c+Y|0,n[R++]=u+I|0,n[R++]=p+K|0,n[R++]=l+z|0,n[R++]=h+V|0,n[R++]=y+x|0,n[R++]=m+v|0,n[R++]=w+E|0,n[R++]=g+N|0,n[R++]=A+j|0,n[R++]=D+U|0,n[R++]=B+P|0,n[R++]=$+L|0,n[R++]=Q+q|0}function jB(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],u=e[1],p=e[2],l=e[3],h=e[4],y=e[5],m=e[6],w=e[7],g=t[0],A=t[1],D=t[2],B=t[3];for(let Q=0;Q<20;Q+=2)o=o+c|0,g=re(g^o,16),h=h+g|0,c=re(c^h,12),o=o+c|0,g=re(g^o,8),h=h+g|0,c=re(c^h,7),i=i+u|0,A=re(A^i,16),y=y+A|0,u=re(u^y,12),i=i+u|0,A=re(A^i,8),y=y+A|0,u=re(u^y,7),s=s+p|0,D=re(D^s,16),m=m+D|0,p=re(p^m,12),s=s+p|0,D=re(D^s,8),m=m+D|0,p=re(p^m,7),a=a+l|0,B=re(B^a,16),w=w+B|0,l=re(l^w,12),a=a+l|0,B=re(B^a,8),w=w+B|0,l=re(l^w,7),o=o+u|0,B=re(B^o,16),m=m+B|0,u=re(u^m,12),o=o+u|0,B=re(B^o,8),m=m+B|0,u=re(u^m,7),i=i+p|0,g=re(g^i,16),w=w+g|0,p=re(p^w,12),i=i+p|0,g=re(g^i,8),w=w+g|0,p=re(p^w,7),s=s+l|0,A=re(A^s,16),h=h+A|0,l=re(l^h,12),s=s+l|0,A=re(A^s,8),h=h+A|0,l=re(l^h,7),a=a+c|0,D=re(D^a,16),y=y+D|0,c=re(c^y,12),a=a+c|0,D=re(D^a,8),y=y+D|0,c=re(c^y,7);let $=0;n[$++]=o,n[$++]=i,n[$++]=s,n[$++]=a,n[$++]=g,n[$++]=A,n[$++]=D,n[$++]=B}var LB=Xg(eS,{counterRight:!1,counterLength:4,allowShortKeys:!1}),UB=Xg(eS,{counterRight:!1,counterLength:8,extendNonceFn:jB,allowShortKeys:!1});var MB=new Uint8Array(16),J_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(MB.subarray(t))},KB=new Uint8Array(32);function Q_(r,e,t,n,o){let i=r(e,t,KB),s=Y_.create(i);o&&J_(s,o),J_(s,n);let a=G_(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return eo(i,a),c}var tS=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Gg(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let u=Q_(r,e,t,c,n);return s.set(u,a),eo(u),s},decrypt(i,s){s=Gg(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=Q_(r,e,t,a,n);if(!q_(c,u))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),eo(u),s}}),Yg=qg({blockSize:64,nonceLength:12,tagLength:16},tS(LB)),MX=qg({blockSize:64,nonceLength:24,tagLength:16},tS(UB));function nS(r,e,t){return ei(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Ds(r,so(t),so(e))}var Jg=Uint8Array.from([0]),rS=Uint8Array.of();function oS(r,e,t,n=32){ei(r),Qo(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=rS);let s=new Uint8Array(i*o),a=Ds.create(r,e),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Jg[0]=p+1,c.update(p===0?rS:u).update(t).update(Jg).digestInto(u),s.set(u,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),Ir(u,Jg),s.slice(0,n)}var Qg={hashSHA256(r){return lo(r.subarray())},getHKDF(r,e){let t=nS(lo,e,r),o=oS(lo,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=sc.utils.randomSecretKey();return{publicKey:sc.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:sc.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return sc.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Yg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Yg(n,e,t).decrypt(r.subarray(),o)}};var iS=Qg;function sS(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=ft(2);return e[0]=r>>8,e[1]=r,e};La.bytes=2;var Ua=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)};Ua.bytes=2;function aS(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 e0(r,e){!e.enabled||!ja||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${le(r.privateKey,"hex")}`)):e("Missing local static keys."))}function t0(r,e){!e.enabled||!ja||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${le(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function cS(r,e){!e.enabled||!ja||e(r?`REMOTE_STATIC_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote static public key.")}function r0(r,e){!e.enabled||!ja||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function n0(r,e,t){!t.enabled||!ja||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&le(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&le(e.k,"hex")}`))}var Ma=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var HB=0,VB=4294967295,$B="Cipher state has reached maximum n, a new handshake must be performed",xh=class{n;bytes;view;constructor(e=HB){this.n=e,this.bytes=ut(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>VB)throw new Error($B)}};var fs=ut(0),Ka=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new xh(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}},o0=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=ye(t,"utf-8");this.h=FB(e,n),this.ck=this.h,this.cs=new Ka(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Ka(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new me(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,fs);return[new Ka(this.crypto,e),new Ka(this.crypto,t)]}},i0=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:u}=e;this.crypto=t,this.ss=new o0(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=u}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()}},df=class extends i0{writeMessageA(e){return new me(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new me(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new me(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new Ma(`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 Ma(`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 Ma(`handshake stage 2 validation fail: ${t.message}`)}}};function FB(r,e){if(e.length<=32){let t=ut(32);return t.set(e),t}else return r.hash(e)}var vh;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((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 dc('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 dc('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=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(vh||(vh={}));var yf;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((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),vh.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ut(0),identitySig:ut(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=vh.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(yf||(yf={}));async function a0(r,e,t){let n=await r.sign(fS(e));return yf.encode({identityKey:io(r.publicKey),identitySig:n,extensions:t})}async function c0(r,e,t){try{let n=yf.decode(r),o=bc(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=fS(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new wf(n.message)}}function fS(r){let e=ye("noise-libp2p-static-key:");return r instanceof Uint8Array?Rt([e,r],e.length+r.length):(r.prepend(e),r)}var s0=class extends bo{stream;handshake;metrics;decoder;constructor(e,t,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=t,this.metrics=n,this.decoder=new Bl({lengthDecoder:Ua,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",o);let i=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",i);let s=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",s);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65519){let o=n+65519;o>e.byteLength&&(o=e.byteLength);let i;e instanceof Uint8Array?i=this.handshake.encrypt(e.subarray(n,o)):i=this.handshake.encrypt(e.sublist(n,o)),this.metrics?.encryptedPackets.increment(),t.append(La(i.byteLength)),t.append(i)}return t}decrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65535){let o=n+65535;if(o>e.byteLength&&(o=e.byteLength),o-Fg<n)throw new Error("Invalid chunk");let i;e instanceof Uint8Array?i=e.subarray(n,o):i=e.sublist(n,o);let s=e.subarray(n,o-Fg);try{let a=this.handshake.decrypt(i,s);this.metrics?.decryptedPackets.increment(),t.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return t}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function u0(r,e,t){return new s0(r,e,t)}async function lS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await a0(i,a.publicKey,u),l=new df({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});e0(l.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(fs),e),t.trace("Stage 0 - Initiator finished sending first message."),t0(l.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let h=l.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),r0(l.re,t),cS(l.rs,t),t.trace("Initiator going to check remote's signature...");let y=await c0(h,l.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[m,w]=l.ss.split();return n0(m,w,t),{payload:y,encrypt:g=>m.encryptWithAd(fs,g),decrypt:(g,A)=>w.decryptWithAd(fs,g,A)}}async function pS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await a0(i,a.publicKey,u),l=new df({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});e0(l.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),r0(l.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),t0(l.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let h=l.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let y=await c0(h,l.rs,c),[m,w]=l.ss.split();return n0(m,w,t),{payload:y,encrypt:g=>w.encryptWithAd(fs,g),decrypt:(g,A)=>m.decryptWithAd(fs,g,A)}}var _h=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=i??iS;this.crypto=sS(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?aS(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ut(0)}[Symbol.toStringTag]="@libp2p/noise";[ys]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,t){let n=e.log?.newScope("noise")??this.log,o=Cl(e,{lengthEncoder:La,lengthDecoder:Ua,maxDataLength:65535}),i=await this.performHandshakeInitiator(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=bc(i.payload.identityKey);return{connection:u0(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:iy(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new xf("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=e.log?.newScope("noise")??this.log,o=Cl(e,{lengthEncoder:La,lengthDecoder:Ua,maxDataLength:65535}),i=await this.performHandshakeResponder(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=bc(i.payload.identityKey);return{connection:u0(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:iy(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await lS({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}async performHandshakeResponder(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await pS({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}};function hS(r={}){return e=>new _h(e,r)}var f0=Object.values(Zo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),WB=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function dS(r){return r?.match(WB)?.groups?.fingerprint}function l0(r){let t=r.getComponents().find(n=>n.code===466)?.value;if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function qB(r){return Cr.decode(f0.decode(r))}function GB(r){let e=qB(l0(r)),t=zB(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 Ll(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function yS(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Dt(lr.code,t);return Vs(`/certhash/${Xo.encode(n.bytes)}`)}function zB(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Ml(r)}}function mS(r,e){let{host:t,port:n,type:o}=Ly(r);if(o!=="ip4"&&o!=="ip6")throw new ve(`Multiaddr ${r} was not an IPv4 or IPv6 address`);let i=GB(r);return{type:"answer",sdp:`v=0
|
12
|
+
`)}};Vt.CertificateTag="CERTIFICATE";Vt.CrlTag="CRL";Vt.CertificateRequestTag="CERTIFICATE REQUEST";Vt.PublicKeyTag="PUBLIC KEY";Vt.PrivateKeyTag="PRIVATE KEY";var qo=class r extends Wo{static isAsnEncoded(e){return H.BufferSourceConverter.isBufferSource(e)||typeof e=="string"}static toArrayBuffer(e){if(typeof e=="string"){if(Vt.isPem(e))return Vt.decode(e)[0];if(H.Convert.isHex(e))return H.Convert.FromHex(e);if(H.Convert.isBase64(e))return H.Convert.FromBase64(e);if(H.Convert.isBase64Url(e))return H.Convert.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}else{let t=H.BufferSourceConverter.toUint8Array(e);if(t.length>0&&t[0]===48)return H.BufferSourceConverter.toArrayBuffer(e);let n=H.Convert.ToBinary(e);if(Vt.isPem(n))return Vt.decode(n)[0];if(H.Convert.isHex(n))return H.Convert.FromHex(n);if(H.Convert.isBase64(n))return H.Convert.FromBase64(n);if(H.Convert.isBase64Url(n))return H.Convert.FromBase64Url(n);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){r.isAsnEncoded(e[0])?super(r.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){switch(e){case"pem":return Vt.encode(this.rawData,this.tag);default:return super.toString(e)}}},zn=class r extends qo{static async create(e,t=yt.get()){if(e instanceof r)return e;if(cf.isCryptoKey(e)){if(e.type!=="public")throw new TypeError("Public key is required");let n=await t.subtle.exportKey("spki",e);return new r(n)}else{if(e.publicKey)return e.publicKey;if(H.BufferSourceConverter.isBufferSource(e))return new r(e);throw new TypeError("Unsupported PublicKeyType")}}constructor(e){qo.isAsnEncoded(e)?super(e,xt):super(e),this.tag=Vt.PublicKeyTag}async export(...e){let t,n=["verify"],o={hash:"SHA-256",...this.algorithm};e.length>1?(o=e[0]||o,n=e[1]||n,t=e[2]||yt.get()):t=e[0]||yt.get();let i=this.rawData,s=W.parse(this.rawData,xt);return s.algorithm.algorithm===Lo&&(i=cB(s,i)),t.subtle.importKey("spki",i,o,!0,n)}onInit(e){let t=He.resolve(us),n=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case cn:{let o=W.parse(e.subjectPublicKey,_a),i=H.BufferSourceConverter.toUint8Array(o.modulus);n.publicExponent=H.BufferSourceConverter.toUint8Array(o.publicExponent),n.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let n,o="SHA-1";return e.length>=1&&!(!((t=e[0])===null||t===void 0)&&t.subtle)?(o=e[0]||o,n=e[1]||yt.get()):n=e[0]||yt.get(),await n.subtle.digest(o,this.rawData)}async getKeyIdentifier(...e){let t,n="SHA-1";e.length===1?typeof e[0]=="string"?(n=e[0],t=yt.get()):t=e[0]:e.length===2?(n=e[0],t=e[1]):t=yt.get();let o=W.parse(this.rawData,xt);return await t.subtle.digest(n,o.subjectPublicKey)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,xt);switch(e.Algorithm=Xn.serializeAlgorithm(t.algorithm),t.algorithm.algorithm){case Yi:e["EC Point"]=t.subjectPublicKey;break;case cn:default:e["Raw Data"]=t.subjectPublicKey}return e}};function cB(r,e){return r.algorithm=new M({algorithm:cn,parameters:null}),e=W.serialize(r),e}var rh=class r extends cr{static async create(e,t=!1,n=yt.get()){if("name"in e&&"serialNumber"in e)return new r(e,t);let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(typeof e[0]=="string"){let t=new rn({keyIdentifier:new Di(H.Convert.FromHex(e[0]))});super(pp,e[1],W.serialize(t))}else{let t=e[0],n=t.name instanceof Zn?W.parse(t.name.rawData,qe):t.name,o=new rn({authorityCertIssuer:n,authorityCertSerialNumber:H.Convert.FromHex(t.serialNumber)});super(pp,e[1],W.serialize(o))}}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,rn);t.keyIdentifier&&(this.keyId=H.Convert.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?H.Convert.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,rn);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Zn(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}};rh.NAME="Authority Key Identifier";var Na=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,Ri);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{let t=new Ri({cA:e[0],pathLenConstraint:e[1]});super(hp,e[2],W.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}};Na.NAME="Basic Constraints";var N_;(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"})(N_||(N_={}));var nh=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,iu);this.usages=t.map(n=>n)}else{let t=new iu(e[0]);super(gp,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[""]=this.usages.map(t=>pn.toString(t)).join(", "),e}};nh.NAME="Extended Key Usages";var k_;(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"})(k_||(k_={}));var oh=class extends cr{constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,ea);this.usages=t.toNumber()}else{let t=new ea(e[0]);super(bp,e[1],W.serialize(t)),this.usages=e[0]}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,ea);return e[""]=t.toJSON().join(", "),e}};oh.NAME="Key Usages";var ih=class r extends cr{static async create(e,t=!1,n=yt.get()){let i=await(await zn.create(e,n)).getKeyIdentifier(n);return new r(H.Convert.ToHex(i),t)}constructor(...e){if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let t=W.parse(this.value,zt);this.keyId=H.Convert.ToHex(t)}else{let t=typeof e[0]=="string"?H.Convert.FromHex(e[0]):e[0],n=new zt(t);super(Pm,e[1],W.serialize(n)),this.keyId=H.Convert.ToHex(t)}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=W.parse(this.value,zt);return e[""]=t,e}};ih.NAME="Subject Key Identifier";var sh=class extends cr{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Im,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,_p);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};sh.NAME="Subject Alternative Name";var $t=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new cr(e),n=this.items.get(t.type);return n?new n(e):t}};$t.items=new Map;var ah=class extends cr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0])){super(e[0]);let n=W.parse(this.value,eu);this.policies=n.map(o=>o.policyIdentifier)}else{let n=e[0],o=(t=e[1])!==null&&t!==void 0?t:!1,i=new eu(n.map(s=>new ji({policyIdentifier:s})));super(yp,o,W.serialize(i)),this.policies=n}}toTextObject(){let e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map(t=>new Ce("",{},pn.toString(t))),e}};ah.NAME="Certificate Policies";$t.register(yp,ah);var ch=class extends cr{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&typeof e[0][0]=="string"){let o=e[0].map(s=>new nn({distributionPoint:new Hn({fullName:[new ue({uniformResourceIdentifier:s})]})})),i=new Oo(o);super(mp,e[1],W.serialize(i))}else{let n=new Oo(e[0]);super(mp,e[1],W.serialize(n))}(t=this.distributionPoints)!==null&&t!==void 0||(this.distributionPoints=[])}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,Oo);this.distributionPoints=t}toTextObject(){let e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map(t=>{var n;let o={};return t.distributionPoint&&(o[""]=(n=t.distributionPoint.fullName)===null||n===void 0?void 0:n.map(i=>new ln(i).toString()).join(", ")),t.reasons&&(o.Reasons=t.reasons.toString()),t.cRLIssuer&&(o["CRL Issuer"]=t.cRLIssuer.map(i=>i.toString()).join(", ")),o}),e}};ch.NAME="CRL Distribution Points";var uh=class extends cr{constructor(...e){var t,n,o,i;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof ki){let s=new ki(e[0]);super(lp,e[1],W.serialize(s))}else{let s=e[0],a=new ki;Jp(a,s,pm,"ocsp"),Jp(a,s,hm,"caIssuers"),Jp(a,s,dm,"timeStamping"),Jp(a,s,ym,"caRepository"),super(lp,e[1],W.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=[],W.parse(e.extnValue,ki).forEach(n=>{switch(n.accessMethod){case pm:this.ocsp.push(new ln(n.accessLocation));break;case hm:this.caIssuers.push(new ln(n.accessLocation));break;case dm:this.timeStamping.push(new ln(n.accessLocation));break;case ym:this.caRepository.push(new ln(n.accessLocation));break}})}toTextObject(){let e=this.toTextObjectWithoutValue();return this.ocsp.length&&Yp(e,"OCSP",this.ocsp),this.caIssuers.length&&Yp(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Yp(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Yp(e,"CA Repository",this.caRepository),e}};uh.NAME="Authority Info Access";function Yp(r,e,t){if(t.length===1)r[e]=t[0].toTextObject();else{let n=new Ce("");t.forEach((o,i)=>{let s=o.toTextObject(),a=`${s[Ce.NAME]} ${i+1}`,c=n[a];Array.isArray(c)||(c=[],n[a]=c),c.push(s)}),r[e]=n}}function Jp(r,e,t,n){let o=e[n];o&&(Array.isArray(o)?o:[o]).forEach(s=>{typeof s=="string"&&(s=new ln("url",s)),r.push(new Mn({accessMethod:t,accessLocation:W.parse(s.rawData,ue)}))})}var fh=class extends cr{constructor(...e){H.BufferSourceConverter.isBufferSource(e[0])?super(e[0]):super(Em,e[1],new Zn(e[0]||[]).rawData)}onInit(e){super.onInit(e);let t=W.parse(e.extnValue,qe);this.names=new Zn(t)}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(let n in t)e[n]=t[n];return e}};fh.NAME="Issuer Alternative Name";var ka=class r extends Wo{constructor(...e){let t;if(H.BufferSourceConverter.isBufferSource(e[0]))t=H.BufferSourceConverter.toArrayBuffer(e[0]);else{let n=e[0],o=Array.isArray(e[1])?e[1].map(i=>H.BufferSourceConverter.toArrayBuffer(i)):[];t=W.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 Ce("",{"":t})),e}toTextObjectWithoutValue(){let e=this.toTextObjectEmpty();return e[Ce.NAME]===r.NAME&&(e[Ce.NAME]=pn.toString(this.type)),e}};ka.NAME="Attribute";var lh=class extends ka{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=new ju({printableString:e[0]});super(Cg,[W.serialize(n)])}(t=this.password)!==null&&t!==void 0||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],ju);this.password=t.toString()}}toTextObject(){let e=this.toTextObjectWithoutValue();return e[Ce.VALUE]=this.password,e}};lh.NAME="Challenge Password";var ff=class extends ka{constructor(...e){var t;if(H.BufferSourceConverter.isBufferSource(e[0]))super(e[0]);else{let n=e[0],o=new sr;for(let i of n)o.push(W.parse(i.rawData,vt));super(Uu,[W.serialize(o)])}(t=this.items)!==null&&t!==void 0||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){let t=W.parse(this.values[0],sr);this.items=t.map(n=>$t.create(W.serialize(n)))}}toTextObject(){let e=this.toTextObjectWithoutValue(),t=this.items.map(n=>n.toTextObject());for(let n of t)e[n[Ce.NAME]]=n;return e}};ff.NAME="Extensions";var Da=class{static register(e,t){this.items.set(e,t)}static create(e){let t=new ka(e),n=this.items.get(t.type);return n?new n(e):t}};Da.items=new Map;var pf="crypto.signatureFormatter",Mg=class{toAsnSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}toWebSignature(e,t){return H.BufferSourceConverter.toArrayBuffer(t)}},eh,Kg=eh=class{static createPssParams(e,t){let n=eh.getHashAlgorithm(e);return n?new un({hashAlgorithm:n,maskGenAlgorithm:new M({algorithm:Uo,parameters:W.serialize(n)}),saltLength:t}):null}static getHashAlgorithm(e){let t=He.resolve(us);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:ga,parameters:null});case"sha-256":return new M({algorithm:Dp,parameters:null});case"sha-384":return new M({algorithm:ba,parameters:null});case"sha-512":return new M({algorithm:wa,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=eh.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new M({algorithm:Lo,parameters:W.serialize(t)})}else return new M({algorithm:Lo,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case cn:return{name:"RSASSA-PKCS1-v1_5"};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case Dp:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ba:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case wa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case Lo:if(e.parameters){let t=W.parse(e.parameters,un);return{name:"RSA-PSS",hash:He.resolve(us).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}else return{name:"RSA-PSS"}}return null}};Kg=eh=uu([Ko()],Kg);He.registerSingleton(lf,Kg);var Hg=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new M({algorithm:Qi});case"sha-256":return new M({algorithm:es});case"sha-384":return new M({algorithm:ts});case"sha-512":return new M({algorithm:rs})}return null}toWebAlgorithm(e){switch(e.algorithm){case Qi:return{name:"SHA-1"};case es:return{name:"SHA-256"};case ts:return{name:"SHA-384"};case rs:return{name:"SHA-512"}}return null}};Hg=uu([Ko()],Hg);He.registerSingleton(lf,Hg);var Yn=class r{addPadding(e,t){let n=H.BufferSourceConverter.toUint8Array(t),o=new Uint8Array(e);return o.set(n,e-n.length),o.buffer}removePadding(e,t=!1){let n=H.BufferSourceConverter.toUint8Array(e);for(let o=0;o<n.length;o++)if(n[o]){n=n.slice(o);break}if(t&&n[0]>127){let o=new Uint8Array(n.length+1);return o.set(n,1),o.buffer}return n.buffer}toAsnSignature(e,t){if(e.name==="ECDSA"){let n=e.namedCurve,o=r.namedCurveSize.get(n)||r.defaultNamedCurveSize,i=new Ji,s=H.BufferSourceConverter.toUint8Array(t);return i.r=this.removePadding(s.slice(0,o),!0),i.s=this.removePadding(s.slice(o,o+o),!0),W.serialize(i)}return null}toWebSignature(e,t){if(e.name==="ECDSA"){let n=W.parse(t,Ji),o=e.namedCurve,i=r.namedCurveSize.get(o)||r.defaultNamedCurveSize,s=this.addPadding(i,this.removePadding(n.r)),a=this.addPadding(i,this.removePadding(n.s));return(0,H.combine)(s,a)}return null}};Yn.namedCurveSize=new Map;Yn.defaultNamedCurveSize=32;var Rg="1.3.101.110",D_="1.3.101.111",jg="1.3.101.112",R_="1.3.101.113",Vg=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=jg;break;case"x25519":t=Rg;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=jg;break;case"ed448":t=R_;break}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=Rg;break;case"x448":t=D_;break}}return t?new M({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case jg:return{name:"Ed25519"};case R_:return{name:"EdDSA",namedCurve:"Ed448"};case Rg:return{name:"X25519"};case D_:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};Vg=uu([Ko()],Vg);He.registerSingleton(lf,Vg);var Hu,Vu,$u,Fu,Wu,qu,Gu,Ia,$g=class extends qo{get subjectName(){return de(this,Vu,"f")||Ge(this,Vu,new qr(this.asn.certificationRequestInfo.subject),"f"),de(this,Vu,"f")}get subject(){return de(this,$u,"f")||Ge(this,$u,this.subjectName.toString(),"f"),de(this,$u,"f")}get signatureAlgorithm(){if(!de(this,Fu,"f")){let e=He.resolve(us);Ge(this,Fu,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return de(this,Fu,"f")}get signature(){return de(this,Wu,"f")||Ge(this,Wu,this.asn.signature,"f"),de(this,Wu,"f")}get publicKey(){return de(this,qu,"f")||Ge(this,qu,new zn(this.asn.certificationRequestInfo.subjectPKInfo),"f"),de(this,qu,"f")}get attributes(){return de(this,Gu,"f")||Ge(this,Gu,this.asn.certificationRequestInfo.attributes.map(e=>Da.create(W.serialize(e))),"f"),de(this,Gu,"f")}get extensions(){if(!de(this,Ia,"f")){Ge(this,Ia,[],"f");let e=this.getAttribute(Uu);e instanceof ff&&Ge(this,Ia,e.items,"f")}return de(this,Ia,"f")}get tbs(){return de(this,Hu,"f")||Ge(this,Hu,this.asn.certificationRequestInfoRaw||W.serialize(this.asn.certificationRequestInfo),"f"),de(this,Hu,"f")}constructor(e){let t=qo.isAsnEncoded(e)?[e,Fo]:[e];super(t[0],t[1]),Hu.set(this,void 0),Vu.set(this,void 0),$u.set(this,void 0),Fu.set(this,void 0),Wu.set(this,void 0),qu.set(this,void 0),Gu.set(this,void 0),Ia.set(this,void 0),this.tag=Vt.CertificateRequestTag}onInit(e){}getAttribute(e){for(let t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter(t=>t.type===e)}getExtension(e){for(let t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter(t=>t.type===e)}async verify(e=yt.get()){let t={...this.publicKey.algorithm,...this.signatureAlgorithm},n=await this.publicKey.export(t,["verify"],e),o=He.resolveAll(pf).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=W.parse(this.rawData,Fo),n=t.certificationRequestInfo,o=new Ce("",{Version:`${on[n.version]} (${n.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){let i=new Ce("");for(let s of this.attributes){let a=s.toTextObject();i[a[Ce.NAME]]=a}o.Attributes=i}return e.Data=o,e.Signature=new Ce("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}};Hu=new WeakMap,Vu=new WeakMap,$u=new WeakMap,Fu=new WeakMap,Wu=new WeakMap,qu=new WeakMap,Gu=new WeakMap,Ia=new WeakMap;$g.NAME="PKCS#10 Certificate Request";var zu,Xu,Zu,Yu,Ju,Qu,ef,tf,rf,nf,Oa,of,Ra=class extends qo{get publicKey(){return de(this,of,"f")||Ge(this,of,new zn(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),de(this,of,"f")}get serialNumber(){if(!de(this,Xu,"f")){let e=this.asn.tbsCertificate,t=new Uint8Array(e.serialNumber);t.length>1&&t[0]===0&&t[1]>127&&(t=t.slice(1)),Ge(this,Xu,H.Convert.ToHex(t),"f")}return de(this,Xu,"f")}get subjectName(){return de(this,Zu,"f")||Ge(this,Zu,new qr(this.asn.tbsCertificate.subject),"f"),de(this,Zu,"f")}get subject(){return de(this,Yu,"f")||Ge(this,Yu,this.subjectName.toString(),"f"),de(this,Yu,"f")}get issuerName(){return de(this,Ju,"f")||Ge(this,Ju,new qr(this.asn.tbsCertificate.issuer),"f"),de(this,Ju,"f")}get issuer(){return de(this,Qu,"f")||Ge(this,Qu,this.issuerName.toString(),"f"),de(this,Qu,"f")}get notBefore(){if(!de(this,ef,"f")){let e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Ge(this,ef,e,"f")}return de(this,ef,"f")}get notAfter(){if(!de(this,tf,"f")){let e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Ge(this,tf,e,"f")}return de(this,tf,"f")}get signatureAlgorithm(){if(!de(this,rf,"f")){let e=He.resolve(us);Ge(this,rf,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return de(this,rf,"f")}get signature(){return de(this,nf,"f")||Ge(this,nf,this.asn.signatureValue,"f"),de(this,nf,"f")}get extensions(){return de(this,Oa,"f")||(Ge(this,Oa,[],"f"),this.asn.tbsCertificate.extensions&&Ge(this,Oa,this.asn.tbsCertificate.extensions.map(e=>$t.create(W.serialize(e))),"f")),de(this,Oa,"f")}get tbs(){return de(this,zu,"f")||Ge(this,zu,this.asn.tbsCertificateRaw||W.serialize(this.asn.tbsCertificate),"f"),de(this,zu,"f")}constructor(e){let t=qo.isAsnEncoded(e)?[e,xr]:[e];super(t[0],t[1]),zu.set(this,void 0),Xu.set(this,void 0),Zu.set(this,void 0),Yu.set(this,void 0),Ju.set(this,void 0),Qu.set(this,void 0),ef.set(this,void 0),tf.set(this,void 0),rf.set(this,void 0),nf.set(this,void 0),Oa.set(this,void 0),of.set(this,void 0),this.tag=Vt.CertificateTag}onInit(e){}getExtension(e){for(let t of this.extensions)if(typeof e=="string"){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter(t=>typeof e=="string"?t.type===e:t instanceof e)}async verify(e={},t=yt.get()){let n,o,i=e.publicKey;try{if(!i)n={...this.publicKey.algorithm,...this.signatureAlgorithm},o=await this.publicKey.export(n,["verify"],t);else if("publicKey"in i)n={...i.publicKey.algorithm,...this.signatureAlgorithm},o=await i.publicKey.export(n,["verify"],t);else if(i instanceof zn)n={...i.algorithm,...this.signatureAlgorithm},o=await i.export(n,["verify"],t);else if(H.BufferSourceConverter.isBufferSource(i)){let u=new zn(i);n={...u.algorithm,...this.signatureAlgorithm},o=await u.export(n,["verify"],t)}else n={...i.algorithm,...this.signatureAlgorithm},o=i}catch{return!1}let s=He.resolveAll(pf).reverse(),a=null;for(let u of s)if(a=u.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=yt.get()),await t.subtle.digest(n,this.rawData)}async isSelfSigned(e=yt.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){let e=this.toTextObjectEmpty(),t=W.parse(this.rawData,xr),n=t.tbsCertificate,o=new Ce("",{Version:`${on[n.version]} (${n.version})`,"Serial Number":n.serialNumber,"Signature Algorithm":Xn.serializeAlgorithm(n.signature),Issuer:this.issuer,Validity:new Ce("",{"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 Ce("");for(let s of this.extensions){let a=s.toTextObject();i[a[Ce.NAME]]=a}o.Extensions=i}return e.Data=o,e.Signature=new Ce("",{Algorithm:Xn.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}};zu=new WeakMap,Xu=new WeakMap,Zu=new WeakMap,Yu=new WeakMap,Ju=new WeakMap,Qu=new WeakMap,ef=new WeakMap,tf=new WeakMap,rf=new WeakMap,nf=new WeakMap,Oa=new WeakMap,of=new WeakMap;Ra.NAME="Certificate";function uB(r,e=yt.get()){let t=H.BufferSourceConverter.toUint8Array(H.Convert.FromHex(r||"")),n=t&&t.length&&t.some(i=>i>0)?new Uint8Array(t):void 0;n||(n=e.getRandomValues(new Uint8Array(16)));let o=0;for(;o<n.length-1&&n[o]===0;)o++;if(n=n.slice(o),n[0]>127){let i=new Uint8Array(n.length+1);i[0]=0,i.set(n,1),n=i}return n.buffer}var ph=class{static async createSelfSigned(e,t=yt.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=yt.get()){var n;let o;e.publicKey instanceof zn?o=e.publicKey.rawData:"publicKey"in e.publicKey?o=e.publicKey.publicKey.rawData:H.BufferSourceConverter.isBufferSource(e.publicKey)?o=e.publicKey:o=await t.subtle.exportKey("spki",e.publicKey);let i=uB(e.serialNumber),s=e.notBefore||new Date,a=e.notAfter||new Date(s.getTime()+31536e6),c=new xr({tbsCertificate:new _t({version:on.v3,serialNumber:i,validity:new Vn({notBefore:s,notAfter:a}),extensions:new sr(((n=e.extensions)===null||n===void 0?void 0:n.map(g=>W.parse(g.rawData,vt)))||[]),subjectPublicKeyInfo:W.parse(o,xt)})});if(e.subject){let g=e.subject instanceof qr?e.subject:new qr(e.subject);c.tbsCertificate.subject=W.parse(g.toArrayBuffer(),je)}if(e.issuer){let g=e.issuer instanceof qr?e.issuer:new qr(e.issuer);c.tbsCertificate.issuer=W.parse(g.toArrayBuffer(),je)}let u={hash:"SHA-256"},p="signingKey"in e?{...u,...e.signingAlgorithm,...e.signingKey.algorithm}:{...u,...e.signingAlgorithm},l=He.resolve(us);c.tbsCertificate.signature=c.signatureAlgorithm=l.toAsnAlgorithm(p);let h=W.serialize(c.tbsCertificate),y="signingKey"in e?await t.subtle.sign(p,e.signingKey,h):e.signature,m=He.resolveAll(pf).reverse(),w=null;for(let g of m)if(w=g.toAsnSignature(p,y),w)break;if(!w)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return c.signatureValue=w,new Ra(W.serialize(c))}},fB,lB,pB,hB,dB,j_;(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"})(j_||(j_={}));fB=new WeakMap,lB=new WeakMap,pB=new WeakMap,hB=new WeakMap,dB=new WeakMap;var yB,mB,gB,bB,wB,xB,vB;yB=new WeakMap,mB=new WeakMap,gB=new WeakMap,bB=new WeakMap,wB=new WeakMap,xB=new WeakMap,vB=new WeakMap;$t.register(hp,Na);$t.register(gp,nh);$t.register(bp,oh);$t.register(Pm,ih);$t.register(pp,rh);$t.register(Im,sh);$t.register(mp,ch);$t.register(lp,uh);$t.register(Em,fh);Da.register(Cg,lh);Da.register(Uu,ff);He.registerSingleton(pf,Mg);He.registerSingleton(pf,Yn);Yn.namedCurveSize.set("P-256",32);Yn.namedCurveSize.set("K-256",32);Yn.namedCurveSize.set("P-384",48);Yn.namedCurveSize.set("P-521",66);var Jn="/",H_=new TextEncoder().encode(Jn),hh=H_[0],hf=class r{_buf;constructor(e,t){if(typeof e=="string")this._buf=ye(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]!==hh)throw new Error("Invalid key")}toString(e="utf8"){return le(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new r(e.join(Jn))}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=H_),this._buf[0]!==hh){let e=new Uint8Array(this._buf.byteLength+1);e.fill(hh,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===hh;)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(Jn).slice(1)}type(){return _B(this.baseNamespace())}name(){return SB(this.baseNamespace())}instance(e){return new r(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Jn)||(e+=Jn),e+=this.type(),new r(e)}parent(){let e=this.list();return e.length===1?new r(Jn):new r(e.slice(0,-1).join(Jn))}child(e){return this.toString()===Jn?e:e.toString()===Jn?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(),...AB(e.map(t=>t.namespaces()))])}};function _B(r){let e=r.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function SB(r){let e=r.split(":");return e[e.length-1]}function AB(r){return[].concat(...r)}var dh=class extends fr{async listen(){throw new Ul("WebRTCTransport.createListener")}getAddrs(){return[]}updateAnnounceAddrs(){}async close(){}};var ja=!!globalThis.process?.env?.DUMP_SESSION_KEYS,Fg=16;function $_(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function yh(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function mh(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function kt(r,...e){if(!$_(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 Wg(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 F_(r,e){kt(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function Qn(r){return new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4))}function eo(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function EB(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}var CB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function TB(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function gh(r){if(typeof r=="string")r=TB(r);else if($_(r))r=bh(r);else throw new Error("Uint8Array expected, got "+typeof r);return r}function W_(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function q_(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 qg=(r,e)=>{function t(n,...o){if(kt(n),!CB)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?kt(p):kt(p,r.nonceLength)}let i=r.tagLength;i&&o[1]!==void 0&&kt(o[1]);let s=e(n,...o),a=(p,l)=>{if(l!==void 0){if(p!==2)throw new Error("cipher output not supported");kt(l)}},c=!1;return{encrypt(p,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,kt(p),a(s.encrypt.length,l),s.encrypt(p,l)},decrypt(p,l){if(kt(p),i&&p.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(s.decrypt.length,l),s.decrypt(p,l)}}}return Object.assign(t,r),t};function Gg(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&&!BB(e))throw new Error("invalid output, must be aligned");return e}function V_(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,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function G_(r,e,t){yh(t);let n=new Uint8Array(16),o=EB(n);return V_(o,0,BigInt(e),t),V_(o,8,BigInt(r),t),n}function BB(r){return r.byteOffset%4===0}function bh(r){return Uint8Array.from(r)}var X_=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),IB=X_("expand 16-byte k"),OB=X_("expand 32-byte k"),PB=Qn(IB),NB=Qn(OB);function re(r,e){return r<<e|r>>>32-e}function zg(r){return r.byteOffset%4===0}var wh=64,kB=16,Z_=2**32-1,z_=new Uint32Array;function DB(r,e,t,n,o,i,s,a){let c=o.length,u=new Uint8Array(wh),p=Qn(u),l=zg(o)&&zg(i),h=l?Qn(o):z_,y=l?Qn(i):z_;for(let m=0;m<c;s++){if(r(e,t,n,p,s,a),s>=Z_)throw new Error("arx: counter overflow");let w=Math.min(wh,c-m);if(l&&w===wh){let g=m/4;if(m%4!==0)throw new Error("arx: invalid block position");for(let A=0,D;A<kB;A++)D=g+A,y[D]=h[D]^p[A];m+=wh;continue}for(let g=0,A;g<w;g++)A=m+g,i[A]=o[A]^u[g];m+=w}}function Xg(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=W_({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return mh(o),mh(s),yh(i),yh(t),(a,c,u,p,l=0)=>{kt(a),kt(c),kt(u);let h=u.length;if(p===void 0&&(p=new Uint8Array(h)),kt(p),mh(l),l<0||l>=Z_)throw new Error("arx: counter overflow");if(p.length<h)throw new Error(`arx: output (${p.length}) is shorter than data (${h})`);let y=[],m=a.length,w,g;if(m===32)y.push(w=bh(a)),g=NB;else if(m===16&&t)w=new Uint8Array(32),w.set(a),w.set(a,16),g=PB,y.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${m}`);zg(c)||y.push(c=bh(c));let A=Qn(w);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,A,Qn(c.subarray(0,16)),A),c=c.subarray(16)}let D=16-o;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){let $=new Uint8Array(12);$.set(c,i?0:12-c.length),c=$,y.push(c)}let B=Qn(c);return DB(r,g,A,B,u,p,l,s),eo(...y),p}}var Et=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Zg=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=gh(e),kt(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),u=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|u<<8)&8191,this.r[9]=u>>>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],u=s[2],p=s[3],l=s[4],h=s[5],y=s[6],m=s[7],w=s[8],g=s[9],A=Et(e,t+0),D=Et(e,t+2),B=Et(e,t+4),$=Et(e,t+6),Q=Et(e,t+8),X=Et(e,t+10),ne=Et(e,t+12),Y=Et(e,t+14),I=i[0]+(A&8191),K=i[1]+((A>>>13|D<<3)&8191),z=i[2]+((D>>>10|B<<6)&8191),V=i[3]+((B>>>7|$<<9)&8191),x=i[4]+(($>>>4|Q<<12)&8191),v=i[5]+(Q>>>1&8191),E=i[6]+((Q>>>14|X<<2)&8191),N=i[7]+((X>>>11|ne<<5)&8191),j=i[8]+((ne>>>8|Y<<8)&8191),U=i[9]+(Y>>>5|o),P=0,L=P+I*a+K*(5*g)+z*(5*w)+V*(5*m)+x*(5*y);P=L>>>13,L&=8191,L+=v*(5*h)+E*(5*l)+N*(5*p)+j*(5*u)+U*(5*c),P+=L>>>13,L&=8191;let q=P+I*c+K*a+z*(5*g)+V*(5*w)+x*(5*m);P=q>>>13,q&=8191,q+=v*(5*y)+E*(5*h)+N*(5*l)+j*(5*p)+U*(5*u),P+=q>>>13,q&=8191;let R=P+I*u+K*c+z*a+V*(5*g)+x*(5*w);P=R>>>13,R&=8191,R+=v*(5*m)+E*(5*y)+N*(5*h)+j*(5*l)+U*(5*p),P+=R>>>13,R&=8191;let he=P+I*p+K*u+z*c+V*a+x*(5*g);P=he>>>13,he&=8191,he+=v*(5*w)+E*(5*m)+N*(5*y)+j*(5*h)+U*(5*l),P+=he>>>13,he&=8191;let be=P+I*l+K*p+z*u+V*c+x*a;P=be>>>13,be&=8191,be+=v*(5*g)+E*(5*w)+N*(5*m)+j*(5*y)+U*(5*h),P+=be>>>13,be&=8191;let te=P+I*h+K*l+z*p+V*u+x*c;P=te>>>13,te&=8191,te+=v*a+E*(5*g)+N*(5*w)+j*(5*m)+U*(5*y),P+=te>>>13,te&=8191;let Se=P+I*y+K*h+z*l+V*p+x*u;P=Se>>>13,Se&=8191,Se+=v*c+E*a+N*(5*g)+j*(5*w)+U*(5*m),P+=Se>>>13,Se&=8191;let Te=P+I*m+K*y+z*h+V*l+x*p;P=Te>>>13,Te&=8191,Te+=v*u+E*c+N*a+j*(5*g)+U*(5*w),P+=Te>>>13,Te&=8191;let Ue=P+I*w+K*m+z*y+V*h+x*l;P=Ue>>>13,Ue&=8191,Ue+=v*p+E*u+N*c+j*a+U*(5*g),P+=Ue>>>13,Ue&=8191;let Ee=P+I*g+K*w+z*m+V*y+x*h;P=Ee>>>13,Ee&=8191,Ee+=v*l+E*p+N*u+j*c+U*a,P+=Ee>>>13,Ee&=8191,P=(P<<2)+P|0,P=P+L|0,L=P&8191,P=P>>>13,q+=P,i[0]=L,i[1]=q,i[2]=R,i[3]=he,i[4]=be,i[5]=te,i[6]=Se,i[7]=Te,i[8]=Ue,i[9]=Ee}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=o,o=e[a]>>>13,e[a]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+o,o=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(o^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535;eo(n)}update(e){Wg(this),e=gh(e),kt(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(){eo(this.h,this.r,this.buffer,this.pad)}digestInto(e){Wg(this),F_(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 RB(r){let e=(n,o)=>r(o).update(gh(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var Y_=RB(r=>new Zg(r));function eS(r,e,t,n,o,i=20){let s=r[0],a=r[1],c=r[2],u=r[3],p=e[0],l=e[1],h=e[2],y=e[3],m=e[4],w=e[5],g=e[6],A=e[7],D=o,B=t[0],$=t[1],Q=t[2],X=s,ne=a,Y=c,I=u,K=p,z=l,V=h,x=y,v=m,E=w,N=g,j=A,U=D,P=B,L=$,q=Q;for(let he=0;he<i;he+=2)X=X+K|0,U=re(U^X,16),v=v+U|0,K=re(K^v,12),X=X+K|0,U=re(U^X,8),v=v+U|0,K=re(K^v,7),ne=ne+z|0,P=re(P^ne,16),E=E+P|0,z=re(z^E,12),ne=ne+z|0,P=re(P^ne,8),E=E+P|0,z=re(z^E,7),Y=Y+V|0,L=re(L^Y,16),N=N+L|0,V=re(V^N,12),Y=Y+V|0,L=re(L^Y,8),N=N+L|0,V=re(V^N,7),I=I+x|0,q=re(q^I,16),j=j+q|0,x=re(x^j,12),I=I+x|0,q=re(q^I,8),j=j+q|0,x=re(x^j,7),X=X+z|0,q=re(q^X,16),N=N+q|0,z=re(z^N,12),X=X+z|0,q=re(q^X,8),N=N+q|0,z=re(z^N,7),ne=ne+V|0,U=re(U^ne,16),j=j+U|0,V=re(V^j,12),ne=ne+V|0,U=re(U^ne,8),j=j+U|0,V=re(V^j,7),Y=Y+x|0,P=re(P^Y,16),v=v+P|0,x=re(x^v,12),Y=Y+x|0,P=re(P^Y,8),v=v+P|0,x=re(x^v,7),I=I+K|0,L=re(L^I,16),E=E+L|0,K=re(K^E,12),I=I+K|0,L=re(L^I,8),E=E+L|0,K=re(K^E,7);let R=0;n[R++]=s+X|0,n[R++]=a+ne|0,n[R++]=c+Y|0,n[R++]=u+I|0,n[R++]=p+K|0,n[R++]=l+z|0,n[R++]=h+V|0,n[R++]=y+x|0,n[R++]=m+v|0,n[R++]=w+E|0,n[R++]=g+N|0,n[R++]=A+j|0,n[R++]=D+U|0,n[R++]=B+P|0,n[R++]=$+L|0,n[R++]=Q+q|0}function jB(r,e,t,n){let o=r[0],i=r[1],s=r[2],a=r[3],c=e[0],u=e[1],p=e[2],l=e[3],h=e[4],y=e[5],m=e[6],w=e[7],g=t[0],A=t[1],D=t[2],B=t[3];for(let Q=0;Q<20;Q+=2)o=o+c|0,g=re(g^o,16),h=h+g|0,c=re(c^h,12),o=o+c|0,g=re(g^o,8),h=h+g|0,c=re(c^h,7),i=i+u|0,A=re(A^i,16),y=y+A|0,u=re(u^y,12),i=i+u|0,A=re(A^i,8),y=y+A|0,u=re(u^y,7),s=s+p|0,D=re(D^s,16),m=m+D|0,p=re(p^m,12),s=s+p|0,D=re(D^s,8),m=m+D|0,p=re(p^m,7),a=a+l|0,B=re(B^a,16),w=w+B|0,l=re(l^w,12),a=a+l|0,B=re(B^a,8),w=w+B|0,l=re(l^w,7),o=o+u|0,B=re(B^o,16),m=m+B|0,u=re(u^m,12),o=o+u|0,B=re(B^o,8),m=m+B|0,u=re(u^m,7),i=i+p|0,g=re(g^i,16),w=w+g|0,p=re(p^w,12),i=i+p|0,g=re(g^i,8),w=w+g|0,p=re(p^w,7),s=s+l|0,A=re(A^s,16),h=h+A|0,l=re(l^h,12),s=s+l|0,A=re(A^s,8),h=h+A|0,l=re(l^h,7),a=a+c|0,D=re(D^a,16),y=y+D|0,c=re(c^y,12),a=a+c|0,D=re(D^a,8),y=y+D|0,c=re(c^y,7);let $=0;n[$++]=o,n[$++]=i,n[$++]=s,n[$++]=a,n[$++]=g,n[$++]=A,n[$++]=D,n[$++]=B}var LB=Xg(eS,{counterRight:!1,counterLength:4,allowShortKeys:!1}),UB=Xg(eS,{counterRight:!1,counterLength:8,extendNonceFn:jB,allowShortKeys:!1});var MB=new Uint8Array(16),J_=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(MB.subarray(t))},KB=new Uint8Array(32);function Q_(r,e,t,n,o){let i=r(e,t,KB),s=Y_.create(i);o&&J_(s,o),J_(s,n);let a=G_(n.length,o?o.length:0,!0);s.update(a);let c=s.digest();return eo(i,a),c}var tS=r=>(e,t,n)=>({encrypt(i,s){let a=i.length;s=Gg(a+16,s,!1),s.set(i);let c=s.subarray(0,-16);r(e,t,c,c,1);let u=Q_(r,e,t,c,n);return s.set(u,a),eo(u),s},decrypt(i,s){s=Gg(i.length-16,s,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=Q_(r,e,t,a,n);if(!q_(c,u))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),r(e,t,s,s,1),eo(u),s}}),Yg=qg({blockSize:64,nonceLength:12,tagLength:16},tS(LB)),UX=qg({blockSize:64,nonceLength:24,tagLength:16},tS(UB));function nS(r,e,t){return ei(r),t===void 0&&(t=new Uint8Array(r.outputLen)),Ds(r,so(t),so(e))}var Jg=Uint8Array.from([0]),rS=Uint8Array.of();function oS(r,e,t,n=32){ei(r),Qo(n);let o=r.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);t===void 0&&(t=rS);let s=new Uint8Array(i*o),a=Ds.create(r,e),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let p=0;p<i;p++)Jg[0]=p+1,c.update(p===0?rS:u).update(t).update(Jg).digestInto(u),s.set(u,o*p),a._cloneInto(c);return a.destroy(),c.destroy(),Ir(u,Jg),s.slice(0,n)}var Qg={hashSHA256(r){return lo(r.subarray())},getHKDF(r,e){let t=nS(lo,e,r),o=oS(lo,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=sc.utils.randomSecretKey();return{publicKey:sc.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:sc.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,e){return sc.getSharedSecret(r.subarray(),e.subarray())},chaCha20Poly1305Encrypt(r,e,t,n){return Yg(n,e,t).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,e,t,n,o){return Yg(n,e,t).decrypt(r.subarray(),o)}};var iS=Qg;function sS(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=ft(2);return e[0]=r>>8,e[1]=r,e};La.bytes=2;var Ua=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)};Ua.bytes=2;function aS(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 e0(r,e){!e.enabled||!ja||(r?(e(`LOCAL_STATIC_PUBLIC_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_STATIC_PRIVATE_KEY ${le(r.privateKey,"hex")}`)):e("Missing local static keys."))}function t0(r,e){!e.enabled||!ja||(r?(e(`LOCAL_PUBLIC_EPHEMERAL_KEY ${le(r.publicKey,"hex")}`),e(`LOCAL_PRIVATE_EPHEMERAL_KEY ${le(r.privateKey,"hex")}`)):e("Missing local ephemeral keys."))}function cS(r,e){!e.enabled||!ja||e(r?`REMOTE_STATIC_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote static public key.")}function r0(r,e){!e.enabled||!ja||e(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${le(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function n0(r,e,t){!t.enabled||!ja||(t(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&le(r.k,"hex")}`),t(`CIPHER_STATE_2 ${e.n.getUint64()} ${e.k&&le(e.k,"hex")}`))}var Ma=class r extends Error{code;constructor(e="Invalid crypto exchange"){super(e),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var HB=0,VB=4294967295,$B="Cipher state has reached maximum n, a new handshake must be performed",xh=class{n;bytes;view;constructor(e=HB){this.n=e,this.bytes=ut(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>VB)throw new Error($B)}};var fs=ut(0),Ka=class{k;n;crypto;constructor(e,t=void 0,n=0){this.crypto=e,this.k=t,this.n=new xh(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}},o0=class{cs;ck;h;crypto;constructor(e,t){this.crypto=e;let n=ye(t,"utf-8");this.h=FB(e,n),this.ck=this.h,this.cs=new Ka(e)}mixKey(e){let[t,n]=this.crypto.hkdf(this.ck,e);this.ck=t,this.cs=new Ka(this.crypto,n)}mixHash(e){this.h=this.crypto.hash(new me(this.h,e))}encryptAndHash(e){let t=this.cs.encryptWithAd(this.h,e);return this.mixHash(t),t}decryptAndHash(e){let t=this.cs.decryptWithAd(this.h,e);return this.mixHash(e),t}split(){let[e,t]=this.crypto.hkdf(this.ck,fs);return[new Ka(this.crypto,e),new Ka(this.crypto,t)]}},i0=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:u}=e;this.crypto=t,this.ss=new o0(t,n),this.ss.mixHash(o),this.initiator=i,this.s=s,this.e=a,this.rs=c,this.re=u}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()}},df=class extends i0{writeMessageA(e){return new me(this.writeE(),this.ss.encryptAndHash(e))}writeMessageB(e){let t=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new me(t,n,this.ss.encryptAndHash(e))}writeMessageC(e){let t=this.writeS();return this.writeSE(),new me(t,this.ss.encryptAndHash(e))}readMessageA(e){try{return this.readE(e),this.ss.decryptAndHash(e.sublist(32))}catch(t){throw new Ma(`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 Ma(`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 Ma(`handshake stage 2 validation fail: ${t.message}`)}}};function FB(r,e){if(e.length<=32){let t=ut(32);return t.set(e),t}else return r.hash(e)}var vh;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((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 dc('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 dc('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=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(vh||(vh={}));var yf;(function(r){let e;r.codec=()=>(e==null&&(e=Dr((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),vh.codec().encode(t.extensions,n)),o.lengthDelimited!==!1&&n.ldelim()},(t,n,o={})=>{let i={identityKey:ut(0),identitySig:ut(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=vh.codec().decode(t,t.uint32(),{limits:o.limits?.extensions});break}default:{t.skipType(a&7);break}}}return i})),e),r.encode=t=>kr(t,r.codec()),r.decode=(t,n)=>Nr(t,r.codec(),n)})(yf||(yf={}));async function a0(r,e,t){let n=await r.sign(fS(e));return yf.encode({identityKey:io(r.publicKey),identitySig:n,extensions:t})}async function c0(r,e,t){try{let n=yf.decode(r),o=bc(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=fS(e);if(!await o.verify(i,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new wf(n.message)}}function fS(r){let e=ye("noise-libp2p-static-key:");return r instanceof Uint8Array?Rt([e,r],e.length+r.length):(r.prepend(e),r)}var s0=class extends bo{stream;handshake;metrics;decoder;constructor(e,t,n){super({log:e.log,inactivityTimeout:e.inactivityTimeout,maxReadBufferLength:e.maxReadBufferLength,direction:e.direction}),this.stream=e,this.handshake=t,this.metrics=n,this.decoder=new Bl({lengthDecoder:Ua,maxBufferSize:16*1024*1024,encodingLength:()=>2});let o=c=>{try{for(let u of this.decoder.decode(c.data))this.onData(this.decrypt(u))}catch(u){this.abort(u)}};this.stream.addEventListener("message",o);let i=c=>{c.error!=null?c.local===!0?this.abort(c.error):this.onRemoteReset():this.onTransportClosed()};this.stream.addEventListener("close",i);let s=()=>{this.safeDispatchEvent("drain")};this.stream.addEventListener("drain",s);let a=()=>{this.onRemoteCloseWrite()};this.stream.addEventListener("remoteCloseWrite",a)}encrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65519){let o=n+65519;o>e.byteLength&&(o=e.byteLength);let i;e instanceof Uint8Array?i=this.handshake.encrypt(e.subarray(n,o)):i=this.handshake.encrypt(e.sublist(n,o)),this.metrics?.encryptedPackets.increment(),t.append(La(i.byteLength)),t.append(i)}return t}decrypt(e){let t=new me;for(let n=0;n<e.byteLength;n+=65535){let o=n+65535;if(o>e.byteLength&&(o=e.byteLength),o-Fg<n)throw new Error("Invalid chunk");let i;e instanceof Uint8Array?i=e.subarray(n,o):i=e.sublist(n,o);let s=e.subarray(n,o-Fg);try{let a=this.handshake.decrypt(i,s);this.metrics?.decryptedPackets.increment(),t.append(a)}catch(a){throw this.metrics?.decryptErrors.increment(),a}}return t}close(e){return this.stream.close(e)}sendPause(){this.stream.pause()}sendResume(){this.stream.resume()}sendReset(e){this.stream.abort(e)}sendData(e){return{sentBytes:e.byteLength,canSendMore:this.stream.send(this.encrypt(e))}}};function u0(r,e,t){return new s0(r,e,t)}async function lS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await a0(i,a.publicKey,u),l=new df({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:s,s:a});e0(l.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await n.write(l.writeMessageA(fs),e),t.trace("Stage 0 - Initiator finished sending first message."),t0(l.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let h=l.readMessageB(await n.read(e));t.trace("Stage 1 - Initiator received the message."),r0(l.re,t),cS(l.rs,t),t.trace("Initiator going to check remote's signature...");let y=await c0(h,l.rs,c);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await n.write(l.writeMessageC(p),e),t.trace("Stage 2 - Initiator sent message with signed payload.");let[m,w]=l.ss.split();return n0(m,w,t),{payload:y,encrypt:g=>m.encryptWithAd(fs,g),decrypt:(g,A)=>w.decryptWithAd(fs,g,A)}}async function pS(r,e){let{log:t,connection:n,crypto:o,privateKey:i,prologue:s,s:a,remoteIdentityKey:c,extensions:u}=r,p=await a0(i,a.publicKey,u),l=new df({crypto:o,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:s,s:a});e0(l.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),l.readMessageA(await n.read(e)),t.trace("Stage 0 - Responder received first message."),r0(l.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await n.write(l.writeMessageB(p),e),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),t0(l.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let h=l.readMessageC(await n.read(e));t.trace("Stage 2 - Responder received the message, finished handshake.");let y=await c0(h,l.rs,c),[m,w]=l.ss.split();return n0(m,w,t),{payload:y,encrypt:g=>w.encryptWithAd(fs,g),decrypt:(g,A)=>m.decryptWithAd(fs,g,A)}}var _h=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;log;constructor(e,t={}){let{staticNoiseKey:n,extensions:o,crypto:i,prologueBytes:s}=t,{metrics:a}=e;this.components=e,this.log=e.logger.forComponent("libp2p:noise");let c=i??iS;this.crypto=sS(c),this.extensions={webtransportCerthashes:[],...o},this.metrics=a?aS(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=s??ut(0)}[Symbol.toStringTag]="@libp2p/noise";[ys]=["@libp2p/connection-encryption","@libp2p/noise"];async secureOutbound(e,t){let n=e.log?.newScope("noise")??this.log,o=Cl(e,{lengthEncoder:La,lengthDecoder:Ua,maxDataLength:65535}),i=await this.performHandshakeInitiator(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=bc(i.payload.identityKey);return{connection:u0(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:iy(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}getStreamMuxer(e){if(e==null||e.length===0)return;let t=this.components.upgrader.getStreamMuxers();if(t!=null)for(let n of e){let o=t.get(n);if(o!=null)return o}if(e.length)throw new xf("Early muxer negotiation was requested but the initiator and responder had no common muxers")}async secureInbound(e,t){let n=e.log?.newScope("noise")??this.log,o=Cl(e,{lengthEncoder:La,lengthDecoder:Ua,maxDataLength:65535}),i=await this.performHandshakeResponder(o,this.components.privateKey,n,t?.remotePeer?.publicKey,t),s=bc(i.payload.identityKey);return{connection:u0(o.unwrap(),i,this.metrics),remoteExtensions:i.payload.extensions,remotePeer:iy(s),streamMuxer:t?.skipStreamMuxerNegotiation===!0?void 0:this.getStreamMuxer(i.payload.extensions?.streamMuxers)}}async performHandshakeInitiator(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await lS({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}async performHandshakeResponder(e,t,n,o,i){let s,a=i?.skipStreamMuxerNegotiation===!0?[]:[...this.components.upgrader.getStreamMuxers().keys()];try{s=await pS({connection:e,privateKey:t,remoteIdentityKey:o,log:n.newScope("xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:{streamMuxers:a,webtransportCerthashes:[],...this.extensions}},i),this.metrics?.xxHandshakeSuccesses.increment()}catch(c){throw this.metrics?.xxHandshakeErrors.increment(),c}return s}};function hS(r={}){return e=>new _h(e,r)}var f0=Object.values(Zo).map(r=>r.decoder).reduce((r,e)=>r.or(e)),WB=/^a=fingerprint:(?:\w+-[0-9]+)\s(?<fingerprint>(:?[0-9a-fA-F]{2})+)$/m;function dS(r){return r?.match(WB)?.groups?.fingerprint}function l0(r){let t=r.getComponents().find(n=>n.code===466)?.value;if(t===void 0||t==="")throw new ve(`Couldn't find a certhash component of multiaddr: ${r.toString()}`);return t}function qB(r){return Cr.decode(f0.decode(r))}function GB(r){let e=qB(l0(r)),t=zB(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 Ll(n,r.toString());return`${t} ${o.join(":").toUpperCase()}`}function yS(r){let e=r.split(":").map(o=>parseInt(o,16)),t=Uint8Array.from(e),n=Dt(lr.code,t);return Vs(`/certhash/${Xo.encode(n.bytes)}`)}function zB(r){switch(r){case 17:return"sha-1";case 18:return"sha-256";case 19:return"sha-512";default:throw new Ml(r)}}function mS(r,e){let{host:t,port:n,type:o}=Ly(r);if(o!=="ip4"&&o!=="ip6")throw new ve(`Multiaddr ${r} was not an IPv4 or IPv6 address`);let i=GB(r);return{type:"answer",sdp:`v=0
|
13
13
|
o=- 0 0 IN IP${o==="ip4"?4:6} ${t}
|
14
14
|
s=-
|
15
15
|
t=0 0
|